smbd: Fix a typo
[Samba.git] / lib / tdb / tools / tdbtool.c
blob780782b3c4592895eba5ec7297da8fae8d59f957
1 /*
2 Unix SMB/CIFS implementation.
3 Samba database functions
4 Copyright (C) Andrew Tridgell 1999-2000
5 Copyright (C) Paul `Rusty' Russell 2000
6 Copyright (C) Jeremy Allison 2000
7 Copyright (C) Andrew Esh 2001
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "replace.h"
24 #include "system/locale.h"
25 #include "system/time.h"
26 #include "system/filesys.h"
27 #include "system/wait.h"
28 #include "tdb.h"
30 static int do_command(void);
31 const char *cmdname;
32 char *arg1, *arg2;
33 size_t arg1len, arg2len;
34 int bIterate = 0;
35 char *line;
36 TDB_DATA iterate_kbuf;
37 char cmdline[1024];
38 static int disable_mmap;
39 static int disable_lock;
41 enum commands {
42 CMD_CREATE_TDB,
43 CMD_OPEN_TDB,
44 CMD_TRANSACTION_START,
45 CMD_TRANSACTION_COMMIT,
46 CMD_TRANSACTION_CANCEL,
47 CMD_ERASE,
48 CMD_DUMP,
49 CMD_INSERT,
50 CMD_MOVE,
51 CMD_STORE,
52 CMD_SHOW,
53 CMD_KEYS,
54 CMD_HEXKEYS,
55 CMD_DELETE,
56 CMD_LIST_HASH_FREE,
57 CMD_LIST_FREE,
58 CMD_FREELIST_SIZE,
59 CMD_INFO,
60 CMD_MMAP,
61 CMD_SPEED,
62 CMD_FIRST,
63 CMD_NEXT,
64 CMD_SYSTEM,
65 CMD_CHECK,
66 CMD_REPACK,
67 CMD_QUIT,
68 CMD_HELP
71 typedef struct {
72 const char *name;
73 enum commands cmd;
74 } COMMAND_TABLE;
76 COMMAND_TABLE cmd_table[] = {
77 {"create", CMD_CREATE_TDB},
78 {"open", CMD_OPEN_TDB},
79 {"transaction_start", CMD_TRANSACTION_START},
80 {"transaction_commit", CMD_TRANSACTION_COMMIT},
81 {"transaction_cancel", CMD_TRANSACTION_CANCEL},
82 {"erase", CMD_ERASE},
83 {"dump", CMD_DUMP},
84 {"insert", CMD_INSERT},
85 {"move", CMD_MOVE},
86 {"store", CMD_STORE},
87 {"show", CMD_SHOW},
88 {"keys", CMD_KEYS},
89 {"hexkeys", CMD_HEXKEYS},
90 {"delete", CMD_DELETE},
91 {"list", CMD_LIST_HASH_FREE},
92 {"free", CMD_LIST_FREE},
93 {"freelist_size", CMD_FREELIST_SIZE},
94 {"info", CMD_INFO},
95 {"speed", CMD_SPEED},
96 {"mmap", CMD_MMAP},
97 {"first", CMD_FIRST},
98 {"1", CMD_FIRST},
99 {"next", CMD_NEXT},
100 {"n", CMD_NEXT},
101 {"check", CMD_CHECK},
102 {"quit", CMD_QUIT},
103 {"q", CMD_QUIT},
104 {"!", CMD_SYSTEM},
105 {"repack", CMD_REPACK},
106 {NULL, CMD_HELP}
109 struct timeval tp1,tp2;
111 static void _start_timer(void)
113 gettimeofday(&tp1,NULL);
116 static double _end_timer(void)
118 gettimeofday(&tp2,NULL);
119 return((tp2.tv_sec - tp1.tv_sec) +
120 (tp2.tv_usec - tp1.tv_usec)*1.0e-6);
123 #ifdef PRINTF_ATTRIBUTE
124 static void tdb_log_open(struct tdb_context *tdb, enum tdb_debug_level level,
125 const char *format, ...) PRINTF_ATTRIBUTE(3,4);
126 #endif
127 static void tdb_log_open(struct tdb_context *tdb, enum tdb_debug_level level,
128 const char *format, ...)
130 const char *mutex_msg =
131 "Can use mutexes only with MUTEX_LOCKING or NOLOCK\n";
132 char *p;
133 va_list ap;
135 p = strstr(format, mutex_msg);
136 if (p != NULL) {
138 * Yes, this is a hack, but we don't want to see this
139 * message on first open, but we want to see
140 * everything else.
142 return;
145 va_start(ap, format);
146 vfprintf(stderr, format, ap);
147 va_end(ap);
150 #ifdef PRINTF_ATTRIBUTE
151 static void tdb_log(struct tdb_context *tdb, enum tdb_debug_level level, const char *format, ...) PRINTF_ATTRIBUTE(3,4);
152 #endif
153 static void tdb_log(struct tdb_context *tdb, enum tdb_debug_level level, const char *format, ...)
155 va_list ap;
157 va_start(ap, format);
158 vfprintf(stderr, format, ap);
159 va_end(ap);
162 /* a tdb tool for manipulating a tdb database */
164 static TDB_CONTEXT *tdb;
166 static int print_rec(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state);
167 static int print_key(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state);
168 static int print_hexkey(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state);
170 static void print_asc(const char *buf,int len)
172 int i;
174 /* We're probably printing ASCII strings so don't try to display
175 the trailing NULL character. */
177 if (buf[len - 1] == 0)
178 len--;
180 for (i=0;i<len;i++)
181 printf("%c",isprint(buf[i])?buf[i]:'.');
184 static void print_data(const char *buf,int len)
186 int i=0;
187 if (len<=0) return;
188 printf("[%03X] ",i);
189 for (i=0;i<len;) {
190 printf("%02X ",(int)((unsigned char)buf[i]));
191 i++;
192 if (i%8 == 0) printf(" ");
193 if (i%16 == 0) {
194 print_asc(&buf[i-16],8); printf(" ");
195 print_asc(&buf[i-8],8); printf("\n");
196 if (i<len) printf("[%03X] ",i);
199 if (i%16) {
200 int n;
202 n = 16 - (i%16);
203 printf(" ");
204 if (n>8) printf(" ");
205 while (n--) printf(" ");
207 n = i%16;
208 if (n > 8) n = 8;
209 print_asc(&buf[i-(i%16)],n); printf(" ");
210 n = (i%16) - n;
211 if (n>0) print_asc(&buf[i-n],n);
212 printf("\n");
216 static void help(void)
218 printf("\n"
219 "tdbtool: \n"
220 " create dbname : create a database\n"
221 " open dbname : open an existing database\n"
222 " transaction_start : start a transaction\n"
223 " transaction_commit : commit a transaction\n"
224 " transaction_cancel : cancel a transaction\n"
225 " erase : erase the database\n"
226 " dump : dump the database as strings\n"
227 " keys : dump the database keys as strings\n"
228 " hexkeys : dump the database keys as hex values\n"
229 " info : print summary info about the database\n"
230 " insert key data : insert a record\n"
231 " move key file : move a record to a destination tdb\n"
232 " store key data : store a record (replace)\n"
233 " show key : show a record by key\n"
234 " delete key : delete a record by key\n"
235 " list : print the database hash table and freelist\n"
236 " free : print the database freelist\n"
237 " freelist_size : print the number of records in the freelist\n"
238 " check : check the integrity of an opened database\n"
239 " repack : repack the database\n"
240 " speed : perform speed tests on the database\n"
241 " ! command : execute system command\n"
242 " 1 | first : print the first record\n"
243 " n | next : print the next record\n"
244 " q | quit : terminate\n"
245 " \\n : repeat 'next' command\n"
246 "\n");
249 static void terror(const char *why)
251 printf("%s\n", why);
254 static void create_tdb(const char *tdbname)
256 struct tdb_logging_context log_ctx = { NULL, NULL};
257 log_ctx.log_fn = tdb_log;
259 if (tdb) tdb_close(tdb);
260 tdb = tdb_open_ex(tdbname, 0,
261 TDB_CLEAR_IF_FIRST |
262 (disable_mmap?TDB_NOMMAP:0) |
263 (disable_lock?TDB_NOLOCK:0),
264 O_RDWR | O_CREAT | O_TRUNC, 0600, &log_ctx, NULL);
265 if (!tdb) {
266 printf("Could not create %s: %s\n", tdbname, strerror(errno));
270 static void open_tdb(const char *tdbname)
272 struct tdb_logging_context log_ctx = { NULL, NULL };
273 log_ctx.log_fn = tdb_log_open;
275 if (tdb) tdb_close(tdb);
276 tdb = tdb_open_ex(tdbname, 0,
277 (disable_mmap?TDB_NOMMAP:0) |
278 (disable_lock?TDB_NOLOCK:0),
279 O_RDWR, 0600,
280 &log_ctx, NULL);
282 log_ctx.log_fn = tdb_log;
283 if (tdb != NULL) {
284 tdb_set_logging_function(tdb, &log_ctx);
287 if ((tdb == NULL) && (errno == EINVAL)) {
289 * Retry NOLOCK and readonly. There we want to see all
290 * error messages.
292 tdb = tdb_open_ex(tdbname, 0,
293 (disable_mmap?TDB_NOMMAP:0) |TDB_NOLOCK,
294 O_RDONLY, 0600,
295 &log_ctx, NULL);
298 if (!tdb) {
299 printf("Could not open %s: %s\n", tdbname, strerror(errno));
303 static void insert_tdb(char *keyname, size_t keylen, char* data, size_t datalen)
305 TDB_DATA key, dbuf;
307 if ((keyname == NULL) || (keylen == 0)) {
308 terror("need key");
309 return;
312 key.dptr = (unsigned char *)keyname;
313 key.dsize = keylen;
314 dbuf.dptr = (unsigned char *)data;
315 dbuf.dsize = datalen;
317 if (tdb_store(tdb, key, dbuf, TDB_INSERT) != 0) {
318 terror("insert failed");
322 static void store_tdb(char *keyname, size_t keylen, char* data, size_t datalen)
324 TDB_DATA key, dbuf;
326 if ((keyname == NULL) || (keylen == 0)) {
327 terror("need key");
328 return;
331 if ((data == NULL) || (datalen == 0)) {
332 terror("need data");
333 return;
336 key.dptr = (unsigned char *)keyname;
337 key.dsize = keylen;
338 dbuf.dptr = (unsigned char *)data;
339 dbuf.dsize = datalen;
341 printf("Storing key:\n");
342 print_rec(tdb, key, dbuf, NULL);
344 if (tdb_store(tdb, key, dbuf, TDB_REPLACE) != 0) {
345 terror("store failed");
349 static void show_tdb(char *keyname, size_t keylen)
351 TDB_DATA key, dbuf;
353 if ((keyname == NULL) || (keylen == 0)) {
354 terror("need key");
355 return;
358 key.dptr = (unsigned char *)keyname;
359 key.dsize = keylen;
361 dbuf = tdb_fetch(tdb, key);
362 if (!dbuf.dptr) {
363 terror("fetch failed");
364 return;
367 print_rec(tdb, key, dbuf, NULL);
369 free( dbuf.dptr );
371 return;
374 static void delete_tdb(char *keyname, size_t keylen)
376 TDB_DATA key;
378 if ((keyname == NULL) || (keylen == 0)) {
379 terror("need key");
380 return;
383 key.dptr = (unsigned char *)keyname;
384 key.dsize = keylen;
386 if (tdb_delete(tdb, key) != 0) {
387 terror("delete failed");
391 static void move_rec(char *keyname, size_t keylen, char* tdbname)
393 TDB_DATA key, dbuf;
394 TDB_CONTEXT *dst_tdb;
396 if ((keyname == NULL) || (keylen == 0)) {
397 terror("need key");
398 return;
401 if ( !tdbname ) {
402 terror("need destination tdb name");
403 return;
406 key.dptr = (unsigned char *)keyname;
407 key.dsize = keylen;
409 dbuf = tdb_fetch(tdb, key);
410 if (!dbuf.dptr) {
411 terror("fetch failed");
412 return;
415 print_rec(tdb, key, dbuf, NULL);
417 dst_tdb = tdb_open(tdbname, 0, 0, O_RDWR, 0600);
418 if ( !dst_tdb ) {
419 terror("unable to open destination tdb");
420 return;
423 if (tdb_store( dst_tdb, key, dbuf, TDB_REPLACE ) != 0) {
424 terror("failed to move record");
426 else
427 printf("record moved\n");
429 tdb_close( dst_tdb );
431 return;
434 static int print_rec(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state)
436 printf("\nkey %d bytes\n", (int)key.dsize);
437 print_asc((const char *)key.dptr, key.dsize);
438 printf("\ndata %d bytes\n", (int)dbuf.dsize);
439 print_data((const char *)dbuf.dptr, dbuf.dsize);
440 return 0;
443 static int print_key(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state)
445 printf("key %d bytes: ", (int)key.dsize);
446 print_asc((const char *)key.dptr, key.dsize);
447 printf("\n");
448 return 0;
451 static int print_hexkey(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state)
453 printf("key %d bytes\n", (int)key.dsize);
454 print_data((const char *)key.dptr, key.dsize);
455 printf("\n");
456 return 0;
459 static int total_bytes;
461 static int traverse_fn(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state)
463 total_bytes += dbuf.dsize;
464 return 0;
467 static void info_tdb(void)
469 char *summary = tdb_summary(tdb);
471 if (!summary) {
472 printf("Error = %s\n", tdb_errorstr(tdb));
473 } else {
474 printf("%s", summary);
475 free(summary);
479 static void speed_tdb(const char *tlimit)
481 const char *str = "store test", *str2 = "transaction test";
482 unsigned timelimit = tlimit?atoi(tlimit):0;
483 double t;
484 int ops;
485 if (timelimit == 0) timelimit = 5;
487 ops = 0;
488 printf("Testing store speed for %u seconds\n", timelimit);
489 _start_timer();
490 do {
491 long int r = random();
492 TDB_DATA key, dbuf;
493 key.dptr = discard_const_p(uint8_t, str);
494 key.dsize = strlen((char *)key.dptr);
495 dbuf.dptr = (uint8_t *) &r;
496 dbuf.dsize = sizeof(r);
497 tdb_store(tdb, key, dbuf, TDB_REPLACE);
498 t = _end_timer();
499 ops++;
500 } while (t < timelimit);
501 printf("%10.3f ops/sec\n", ops/t);
503 ops = 0;
504 printf("Testing fetch speed for %u seconds\n", timelimit);
505 _start_timer();
506 do {
507 TDB_DATA key;
508 key.dptr = discard_const_p(uint8_t, str);
509 key.dsize = strlen((char *)key.dptr);
510 tdb_fetch(tdb, key);
511 t = _end_timer();
512 ops++;
513 } while (t < timelimit);
514 printf("%10.3f ops/sec\n", ops/t);
516 ops = 0;
517 printf("Testing transaction speed for %u seconds\n", timelimit);
518 _start_timer();
519 do {
520 long int r = random();
521 TDB_DATA key, dbuf;
522 key.dptr = discard_const_p(uint8_t, str2);
523 key.dsize = strlen((char *)key.dptr);
524 dbuf.dptr = (uint8_t *) &r;
525 dbuf.dsize = sizeof(r);
526 tdb_transaction_start(tdb);
527 tdb_store(tdb, key, dbuf, TDB_REPLACE);
528 tdb_transaction_commit(tdb);
529 t = _end_timer();
530 ops++;
531 } while (t < timelimit);
532 printf("%10.3f ops/sec\n", ops/t);
534 ops = 0;
535 printf("Testing traverse speed for %u seconds\n", timelimit);
536 _start_timer();
537 do {
538 tdb_traverse(tdb, traverse_fn, NULL);
539 t = _end_timer();
540 ops++;
541 } while (t < timelimit);
542 printf("%10.3f ops/sec\n", ops/t);
545 static void toggle_mmap(void)
547 disable_mmap = !disable_mmap;
548 if (disable_mmap) {
549 printf("mmap is disabled\n");
550 } else {
551 printf("mmap is enabled\n");
555 static char *tdb_getline(const char *prompt)
557 static char thisline[1024];
558 char *p;
559 fputs(prompt, stdout);
560 thisline[0] = 0;
561 p = fgets(thisline, sizeof(thisline)-1, stdin);
562 if (p) p = strchr(p, '\n');
563 if (p) *p = 0;
564 return p?thisline:NULL;
567 static int do_delete_fn(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf,
568 void *state)
570 return tdb_delete(the_tdb, key);
573 static void first_record(TDB_CONTEXT *the_tdb, TDB_DATA *pkey)
575 TDB_DATA dbuf;
576 *pkey = tdb_firstkey(the_tdb);
578 dbuf = tdb_fetch(the_tdb, *pkey);
579 if (!dbuf.dptr) terror("fetch failed");
580 else {
581 print_rec(the_tdb, *pkey, dbuf, NULL);
585 static void next_record(TDB_CONTEXT *the_tdb, TDB_DATA *pkey)
587 TDB_DATA dbuf;
588 *pkey = tdb_nextkey(the_tdb, *pkey);
590 dbuf = tdb_fetch(the_tdb, *pkey);
591 if (!dbuf.dptr)
592 terror("fetch failed");
593 else
594 print_rec(the_tdb, *pkey, dbuf, NULL);
597 static int count(TDB_DATA key, TDB_DATA data, void *private_data)
599 (*(unsigned int *)private_data)++;
600 return 0;
603 static void check_db(TDB_CONTEXT *the_tdb)
605 int tdbcount = 0;
606 if (!the_tdb)
607 printf("Error: No database opened!\n");
608 else if (tdb_check(the_tdb, count, &tdbcount) == -1)
609 printf("Integrity check for the opened database failed.\n");
610 else
611 printf("Database integrity is OK and has %d records.\n",
612 tdbcount);
615 static int do_command(void)
617 COMMAND_TABLE *ctp = cmd_table;
618 enum commands mycmd = CMD_HELP;
619 int cmd_len;
621 if (cmdname && strlen(cmdname) == 0) {
622 mycmd = CMD_NEXT;
623 } else {
624 while (ctp->name) {
625 cmd_len = strlen(ctp->name);
626 if (strncmp(ctp->name,cmdname,cmd_len) == 0) {
627 mycmd = ctp->cmd;
628 break;
630 ctp++;
634 switch (mycmd) {
635 case CMD_CREATE_TDB:
636 bIterate = 0;
637 create_tdb(arg1);
638 return 0;
639 case CMD_OPEN_TDB:
640 bIterate = 0;
641 open_tdb(arg1);
642 return 0;
643 case CMD_SYSTEM:
644 /* Shell command */
645 if (system(arg1) == -1) {
646 terror("system() call failed\n");
648 return 0;
649 case CMD_QUIT:
650 return 1;
651 default:
652 /* all the rest require a open database */
653 if (!tdb) {
654 bIterate = 0;
655 terror("database not open");
656 help();
657 return 0;
659 switch (mycmd) {
660 case CMD_TRANSACTION_START:
661 bIterate = 0;
662 tdb_transaction_start(tdb);
663 return 0;
664 case CMD_TRANSACTION_COMMIT:
665 bIterate = 0;
666 tdb_transaction_commit(tdb);
667 return 0;
668 case CMD_REPACK:
669 bIterate = 0;
670 tdb_repack(tdb);
671 return 0;
672 case CMD_TRANSACTION_CANCEL:
673 bIterate = 0;
674 tdb_transaction_cancel(tdb);
675 return 0;
676 case CMD_ERASE:
677 bIterate = 0;
678 tdb_traverse(tdb, do_delete_fn, NULL);
679 return 0;
680 case CMD_DUMP:
681 bIterate = 0;
682 tdb_traverse(tdb, print_rec, NULL);
683 return 0;
684 case CMD_INSERT:
685 bIterate = 0;
686 insert_tdb(arg1, arg1len,arg2,arg2len);
687 return 0;
688 case CMD_MOVE:
689 bIterate = 0;
690 move_rec(arg1,arg1len,arg2);
691 return 0;
692 case CMD_STORE:
693 bIterate = 0;
694 store_tdb(arg1,arg1len,arg2,arg2len);
695 return 0;
696 case CMD_SHOW:
697 bIterate = 0;
698 show_tdb(arg1, arg1len);
699 return 0;
700 case CMD_KEYS:
701 tdb_traverse(tdb, print_key, NULL);
702 return 0;
703 case CMD_HEXKEYS:
704 tdb_traverse(tdb, print_hexkey, NULL);
705 return 0;
706 case CMD_DELETE:
707 bIterate = 0;
708 delete_tdb(arg1,arg1len);
709 return 0;
710 case CMD_LIST_HASH_FREE:
711 tdb_dump_all(tdb);
712 return 0;
713 case CMD_LIST_FREE:
714 tdb_printfreelist(tdb);
715 return 0;
716 case CMD_FREELIST_SIZE: {
717 int count;
719 count = tdb_freelist_size(tdb);
720 if (count < 0) {
721 printf("Error getting freelist size.\n");
722 } else {
723 printf("freelist size: %d\n", count);
726 return 0;
728 case CMD_INFO:
729 info_tdb();
730 return 0;
731 case CMD_SPEED:
732 speed_tdb(arg1);
733 return 0;
734 case CMD_MMAP:
735 toggle_mmap();
736 return 0;
737 case CMD_FIRST:
738 bIterate = 1;
739 first_record(tdb, &iterate_kbuf);
740 return 0;
741 case CMD_NEXT:
742 if (bIterate)
743 next_record(tdb, &iterate_kbuf);
744 return 0;
745 case CMD_CHECK:
746 check_db(tdb);
747 return 0;
748 case CMD_HELP:
749 help();
750 return 0;
751 case CMD_CREATE_TDB:
752 case CMD_OPEN_TDB:
753 case CMD_SYSTEM:
754 case CMD_QUIT:
756 * unhandled commands. cases included here to avoid compiler
757 * warnings.
759 return 0;
763 return 0;
766 static char *tdb_convert_string(char *instring, size_t *sizep)
768 size_t length = 0;
769 char *outp, *inp;
770 char temp[3];
772 outp = inp = instring;
774 while (*inp) {
775 if (*inp == '\\') {
776 inp++;
777 if (*inp && strchr("0123456789abcdefABCDEF",(int)*inp)) {
778 temp[0] = *inp++;
779 temp[1] = '\0';
780 if (*inp && strchr("0123456789abcdefABCDEF",(int)*inp)) {
781 temp[1] = *inp++;
782 temp[2] = '\0';
784 *outp++ = (char)strtol((const char *)temp,NULL,16);
785 } else {
786 *outp++ = *inp++;
788 } else {
789 *outp++ = *inp++;
791 length++;
793 *sizep = length;
794 return instring;
797 int main(int argc, char *argv[])
799 cmdname = "";
800 arg1 = NULL;
801 arg1len = 0;
802 arg2 = NULL;
803 arg2len = 0;
805 if (argv[1] && (strcmp(argv[1], "-l") == 0)) {
806 disable_lock = 1;
807 argv[1] = argv[0];
808 argv += 1;
809 argc -= 1;
812 if (argv[1]) {
813 cmdname = "open";
814 arg1 = argv[1];
815 do_command();
816 cmdname = "";
817 arg1 = NULL;
820 switch (argc) {
821 case 1:
822 case 2:
823 /* Interactive mode */
824 while ((cmdname = tdb_getline("tdb> "))) {
825 arg2 = arg1 = NULL;
826 if ((arg1 = strchr((const char *)cmdname,' ')) != NULL) {
827 arg1++;
828 arg2 = arg1;
829 while (*arg2) {
830 if (*arg2 == ' ') {
831 *arg2++ = '\0';
832 break;
834 if ((*arg2++ == '\\') && (*arg2 == ' ')) {
835 arg2++;
839 if (arg1) arg1 = tdb_convert_string(arg1,&arg1len);
840 if (arg2) arg2 = tdb_convert_string(arg2,&arg2len);
841 if (do_command()) break;
843 break;
844 case 5:
845 arg2 = tdb_convert_string(argv[4],&arg2len);
846 case 4:
847 arg1 = tdb_convert_string(argv[3],&arg1len);
848 case 3:
849 cmdname = argv[2];
850 default:
851 do_command();
852 break;
855 if (tdb) tdb_close(tdb);
857 return 0;