int main(int argc, char *argv[]) { cmdname = ""; arg1 = NULL; arg1len = 0; arg2 = NULL; arg2len = 0; if (argv[1]) { cmdname = "open"; arg1 = argv[1]; do_command(); cmdname = ""; arg1 = NULL; } switch (argc) { case 1: case 2: /* Interactive mode */ while ((cmdname = tdb_getline("tdb> "))) { arg2 = arg1 = NULL; if ((arg1 = strchr((const char *)cmdname,' ')) != NULL) { arg1++; arg2 = arg1; while (*arg2) { if (*arg2 == ' ') { *arg2++ = '\0'; break; } if ((*arg2++ == '\\') && (*arg2 == ' ')) { arg2++; } } } if (arg1) arg1 = tdb_convert_string(arg1,&arg1len); if (arg2) arg2 = tdb_convert_string(arg2,&arg2len); if (do_command()) break; } break; case 5: arg2 = tdb_convert_string(argv[4],&arg2len); case 4: arg1 = tdb_convert_string(argv[3],&arg1len); case 3: cmdname = argv[2]; default: do_command(); break; } if (tdb) tdb_close(tdb); return 0; }
int main(int argc, char *argv[]) { int bIterate = 0, ignore; char *line; char *tok; TDB_DATA iterate_kbuf; if (argv[1]) { static char tmp[1024]; sprintf(tmp, "open %s", argv[1]); tok=strtok(tmp," "); open_tdb(); } while ((line = tdb_getline("tdb> "))) { /* Shell command */ if (line[0] == '!') { ignore = system(line + 1); continue; } if ((tok = strtok(line," "))==NULL) { if (bIterate) next_record(tdb, &iterate_kbuf); continue; } if (strcmp(tok,"create") == 0) { bIterate = 0; create_tdb(); continue; } else if (strcmp(tok,"open") == 0) { open_tdb(); continue; } else if ((strcmp(tok, "q") == 0) || (strcmp(tok, "quit") == 0)) { break; } /* all the rest require a open database */ if (!tdb) { bIterate = 0; terror("database not open"); help(); continue; } if (strcmp(tok,"insert") == 0) { bIterate = 0; insert_tdb(); } else if (strcmp(tok,"store") == 0) { bIterate = 0; store_tdb(); } else if (strcmp(tok,"show") == 0) { bIterate = 0; show_tdb(); } else if (strcmp(tok,"erase") == 0) { bIterate = 0; tdb_traverse(tdb, do_delete_fn, NULL); } else if (strcmp(tok,"delete") == 0) { bIterate = 0; delete_tdb(); } else if (strcmp(tok,"dump") == 0) { bIterate = 0; if(open_dump_file() == 0) { /* open file */ tdb_traverse(tdb, print_rec, NULL); close_dump_file(); /* close file */ } pDumpFile = stdout; } else if (strcmp(tok,"list") == 0) { tdb_dump_all(tdb); } else if (strcmp(tok, "free") == 0) { tdb_printfreelist(tdb); } else if (strcmp(tok,"info") == 0) { info_tdb(); } else if ( (strcmp(tok, "1") == 0) || (strcmp(tok, "first") == 0)) { bIterate = 1; first_record(tdb, &iterate_kbuf); } else if ((strcmp(tok, "n") == 0) || (strcmp(tok, "next") == 0)) { next_record(tdb, &iterate_kbuf); } else if ((strcmp(tok, "keys") == 0)) { bIterate = 0; tdb_traverse(tdb, print_key, NULL); } else { help(); } } if (tdb) tdb_close(tdb); return 0; }