static void close_db(void *db) { if (adb != db) return; if (!tcadbclose(adb)) die("close error: %s", tcadbpath(adb)); tcadbdel(adb); adb = NULL; }
/* perform inform command */ static int procinform(const char *name){ TCADB *adb = tcadbnew(); ADBSKEL skel; if(*name == '@'){ setskeltran(&skel); if(!tcadbsetskel(adb, &skel)){ printerr(adb); skel.del(skel.opq); tcadbdel(adb); return 1; } name++; } else if(*name == '%'){ if(!tcadbsetskelmulti(adb, 8)){ printerr(adb); tcadbdel(adb); return 1; } name++; } if(!tcadbopen(adb, name)){ printerr(adb); tcadbdel(adb); return 1; } bool err = false; const char *path = tcadbpath(adb); if(!path) path = "(unknown)"; printf("path: %s\n", path); const char *type = "(unknown)"; switch(tcadbomode(adb)){ case ADBOVOID: type = "not opened"; break; case ADBOMDB: type = "on-memory hash database"; break; case ADBONDB: type = "on-memory tree database"; break; case ADBOHDB: type = "hash database"; break; case ADBOBDB: type = "B+ tree database"; break; case ADBOFDB: type = "fixed-length database"; break; case ADBOTDB: type = "table database"; break; case ADBOSKEL: type = "skeleton database"; break; } printf("database type: %s\n", type); printf("record number: %llu\n", (unsigned long long)tcadbrnum(adb)); printf("size: %llu\n", (unsigned long long)tcadbsize(adb)); if(!tcadbclose(adb)){ printerr(adb); err = true; } tcadbdel(adb); return err ? 1 : 0; }
/* print error message of abstract database */ static void eprint(TCADB *adb, int line, const char *func){ const char *path = adb ? tcadbpath(adb) : NULL; fprintf(stderr, "%s: %s: %d: %s: error\n", g_progname, path ? path : "-", line, func); }
/* print error information */ static void printerr(TCADB *adb){ const char *path = tcadbpath(adb); fprintf(stderr, "%s: %s: error\n", g_progname, path ? path : "-"); }