* Copyright (c) 1992 Eric P. Allman.
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
static char sccsid
[] = "@(#)makemap.c 8.1 (Berkeley) 6/7/93";
enum type
{ T_DBM
, T_BTREE
, T_HASH
, T_ERR
, T_UNKNOWN
};
bool allowreplace
= FALSE
;
while ((opt
= getopt(argc
, argv
, "Nforv")) != EOF
)
if (strcmp(typename
, "dbm") == 0)
else if (strcmp(typename
, "btree") == 0)
else if (strcmp(typename
, "hash") == 0)
fprintf(stderr
, "Usage: %s [-N] [-o] [-v] type mapname\n", progname
);
fprintf(stderr
, "%s: Unknown database type %s\n",
fprintf(stderr
, "%s: Type %s not supported in this version\n",
dbp
.dbm
= dbm_open(mapname
, mode
, 0644);
dbp
.db
= dbopen(mapname
, mode
, 0644, DB_HASH
, NULL
);
dbp
.db
= dbopen(mapname
, mode
, 0644, DB_BTREE
, NULL
);
fprintf(stderr
, "%s: internal error: type %d\n", progname
, type
);
fprintf(stderr
, "%s: cannot create type %s map %s\n",
progname
, typename
, mapname
);
while (fgets(ibuf
, sizeof ibuf
, stdin
) != NULL
)
if (ibuf
[0] == '\0' || ibuf
[0] == '#')
fprintf(stderr
, "%s: %s: line %d: syntax error (leading space)\n",
progname
, mapname
, lineno
);
for (p
= ibuf
; *p
!= '\0' && !isspace(*p
); p
++)
if (foldcase
&& isupper(*p
))
key
.xx
.size
= p
- key
.xx
.data
;
fprintf(stderr
, "%s: %s: line %d: no RHS for LHS %s\n",
progname
, mapname
, lineno
, key
.xx
.data
);
** Do the database insert.
printf("key=`%s', val=`%s'\n", key
.xx
.data
, val
.xx
.data
);
st
= dbm_store(dbp
.dbm
, key
.dbm
, val
.dbm
,
allowreplace
? DBM_REPLACE
: DBM_INSERT
);
st
= (*dbp
.db
->put
)(dbp
.db
, &key
.db
, &val
.db
,
allowreplace
? 0 : R_NOOVERWRITE
);
fprintf(stderr
, "%s: %s: line %d: key %s: put error\n",
progname
, mapname
, lineno
, key
.xx
.data
);
fprintf(stderr
, "%s: %s: line %d: key %s: duplicate key\n",
progname
, mapname
, lineno
, key
.xx
.data
);
** Now close the database.
if ((*dbp
.db
->close
)(dbp
.db
) < 0)
fprintf(stderr
, "%s: %s: error on close\n",