41 static int add_db_rec(
void *,
void *);
43 static long nb_ok, nb_ko, nb_t;
53 const char *args =
"h12b:rvdfk:t:m:cw:eC:X";
58 bool dbreverse =
FALSE;
65 char *dbstartkey = NULL;
70 #ifndef USE_BerkeleyDB 71 fprintf(stderr,
" -> ze-filter wasn't compiled with BerkeleyDB...\n");
72 fprintf(stderr,
" -> Can't use dabatases without BerkeleyDB !\n");
78 while ((c = getopt(argc, argv, args)) != -1) {
94 switch (tolower(*optarg)) {
110 int w = atoi(optarg);
117 dbexport = !dbexport;
120 switch (tolower(*optarg)) {
137 if (optarg == NULL || *optarg ==
'\0') {
138 fprintf(stderr,
"Error %s\n", optarg ? optarg :
"");
141 if (dbname != NULL) {
142 fprintf(stderr,
"Error : only one -b option allowed\n");
145 if ((dbname = strdup(optarg)) == NULL) {
146 fprintf(stderr,
"FATAL ERROR - memory allocation dbname\n");
164 if (optarg == NULL || *optarg ==
'\0') {
165 fprintf(stderr,
"Error %s\n", optarg ? optarg :
"");
169 if ((dbstartkey = strdup(optarg)) == NULL) {
170 fprintf(stderr,
"FATAL ERROR - memory allocation dbname\n");
175 if (optarg != NULL) {
178 for (p = optarg; *p !=
'\0'; p++) {
193 fprintf(stderr,
"\nInvalid option\n");
203 fprintf(stderr,
"\n Can't set both SKIP and UPDATE modes\n");
208 if ((db_updt_mode & (MDB_UPDATE | MDB_SKIP)) == 0)
212 dbstartkey =
STRNULL(dbstartkey,
"");
214 nb_t = nb_ok = nb_ko = 0;
221 if (dbname == NULL) {
223 fprintf(stderr,
"Missing -b option\n");
227 if (*dbname ==
'-') {
229 fprintf(stderr,
"dbname not valid : %s\n", dbname);
250 printf(
" ** %7ld records found\n", (
long int ) st->st.btree_st.bt_ndata);
270 char key[256], data[256];
274 memset(key, 0,
sizeof (key));
275 memset(data, 0,
sizeof (data));
277 snprintf(key,
sizeof (key),
"%s", dbstartkey);
281 snprintf(key,
sizeof (key),
"%s", dbstartkey);
290 if (strncmp(key, dbstartkey, strlen(dbstartkey)) != 0)
294 snprintf(format,
sizeof (format),
295 " ** KEY : %%-%ds - DATA : %%s\n", kw);
297 snprintf(format,
sizeof (format),
"%%-%ds %%s\n", kw);
298 printf(format, key, data);
310 if (!dbexport || dbcount)
311 printf(
" ** %7ld records found\n", nb);
331 (void)
zm_RdTextFile(NULL, dbattrnb, dbreverse,
"", add_db_rec);
335 printf(
"* Total : %6ld records read\n", nb_t);
336 printf(
" %6ld records added\n", nb_ok);
337 printf(
" %6ld errors\n", nb_ko);
355 char *k = (
char *) vk;
356 char *v = (
char *) vv;
361 if (k == NULL || strlen(k) == 0)
371 if ((db_updt_mode &
MDB_SKIP) != 0) {
386 return (res ? 1 : 0);
396 printf(
"Usage : ze-makemap options\n" 398 " Compiled on %s %s\n" " -b table : specifies table name\n" 399 " -d : dump instead of update\n" 400 " -c : count records on database\n" 401 " -k key : matching key\n" 402 " -w NN : column width when dumping database\n" 403 " -t : database type\n" 406 " -m mode : how to insert records\n" 407 " e - clear database before update\n" 408 " s - skip existent records\n" 409 " u - new records update existent records\n" 410 " - can be defined multiple times\n" 411 " - default mode : erase and skim\n" 412 " -r : reverse key/value order (value/key)\n" 413 " -1 : single column (key only)\n" 414 " -2 : two columns (key / value) - default\n" 415 " -h : help (print this and exits)\n" 416 " default mode : erase and skim\n"
bool zeDb_Stat(ZEDB_T *h, ZEDB_STAT_T **)
bool zeDb_AddRec(ZEDB_T *h, char *, void *, size_t)
bool zeDb_Empty(ZEDB_T *h)
void zeLog_SetOutput(bool, bool)
#define DB_BTREE_SEQ_START()
bool zeDb_CursorGetFirst(ZEDB_T *h, char *, size_t, void *, size_t)
bool zeDb_Open(ZEDB_T *h, ZEDB_ENV_T *, char *, int, bool, bool, size_t)
bool zeDb_Close(ZEDB_T *h)
#define DB_BTREE_SEQ_END()
int zm_RdTextFile(char *, int, int, char *, int(*)(void *, void *))
#define ZE_MessageInfo(level,...)
bool zeDb_GetRec(ZEDB_T *h, char *, void *, size_t)
bool zeDb_CursorOpen(ZEDB_T *h, bool)
int main(int argc, char **argv)
#define DB_BTREE_SEQ_CHECK(key, dbname)
char * zeStr2Lower(char *)
bool zeDb_CursorClose(ZEDB_T *h)
bool zeDb_CursorGetNext(ZEDB_T *h, char *, size_t, void *, size_t)