int main (int argc, char *argv[]) { struct or_dbrec dbrec; char renamebuf[256]; time_t now; struct tm *time_ptr; _Xltimeparams localtime_buf; aa_argv0 = argv[0]; setlocale (LC_ALL, ""); dtsearch_catd = catopen (FNAME_DTSRCAT, 0); austools_catd = catopen (FNAME_AUSCAT, 0); time (&now); time_ptr = _XLocaltime(&now, localtime_buf); strftime (renamebuf, sizeof (renamebuf), catgets (dtsearch_catd, MS_misc, 22, "%A, %b %d %Y, %I:%M %p"), time_ptr); printf (catgets (dtsearch_catd, MS_misc, 23, "%s: Version %s. Run %s.\n"), aa_argv0, DtSrVERSION, renamebuf); if (argc < 2) { printf (catgets (dtsearch_catd, MS_dbrec, 310, "USAGE: %s <dbname>\n"), aa_argv0); return 2; } sprintf (renamebuf, "%s.d00", argv[1]); db_oflag = O_RDONLY; /* db files may be read-only */ d_open (argv[1], "o"); if (db_status != S_OKAY) { printf (catgets (dtsearch_catd, MS_dbrec, 330, "Could not open '%s' database.\n%s\n"), argv[1], vista_msg(PROGNAME"293")); return 3; } d_recfrst (OR_DBREC, 0); if (db_status != S_OKAY) { printf (catgets (dtsearch_catd, MS_dbrec, 340, "No dbrec record in database '%s'.\n"), argv[1]); return 4; } d_recread (&dbrec, 0); if (db_status != S_OKAY) { printf (catgets (dtsearch_catd, MS_dbrec, 350, "Can't read dbrec record in database '%s'.\n%s\n"), argv[1], vista_msg(PROGNAME"306")); return 5; } swab_dbrec (&dbrec, NTOH); print_dbrec (argv[1], &dbrec); return 0; } /* main() */
/* 1. CREATE or find database dictionary (.dbd file). * 2. CREATE empty 'dtsearch' database files. * 3. OPEN 'dtsearch' database. * 4. INITIALIZE the database. * 5. WRITE dbrec after initializing it. * 6. RENAME each database file. * 7. UNLINK (delete) d9x files. */ int main (int argc, char *argv[]) { int i; char *ptr; FILE *f; struct or_miscrec miscrec; struct or_swordrec swordrec; struct or_lwordrec lwordrec; setlocale (LC_ALL, ""); dtsearch_catd = catopen (FNAME_DTSRCAT, 0); aa_argv0 = argv[0]; max_ormisc_size = sizeof (miscrec.or_misc); maxwidth_sword = sizeof (swordrec.or_swordkey) - 1; maxwidth_lword = sizeof (lwordrec.or_lwordkey) - 1; printf (catgets (dtsearch_catd, MS_misc, 4, "%s Version %s.\n"), aa_argv0, DtSrVERSION ); /* Handle cmd line args. Init global variables. */ user_args_processor (argc, argv); /* ------- copy model .dbd to new .dbd ------- */ /* CASE 1: If user specified -d special alternative * directory for model .dbd, it should be there. */ if (modelpath[0] != 0) { if (debug_mode) printf (PROGNAME"628 Try opening '%s' (-d dir).\n", modelpath); if ((f = fopen (modelpath, "rb")) != NULL) { if (debug_mode) puts (PROGNAME"638 Found it!"); create_new_dbd (f); fclose (f); goto DBD_OKAY; } else { print_usage(); printf (catgets (dtsearch_catd, MS_initausd, 213, default_unable_to_open_msg), "\n"PROGNAME"302", modelpath, strerror(errno)); DtSearchExit (4); } } /* end CASE 1 */ /* CASE 2: If model .dbd is in current directory, use it. * If error is anything other than 'cant find file', quit now. */ if (debug_mode) printf (PROGNAME"649 Try opening '%s' (curr dir).\n", FNAME_MODEL); if ((f = fopen (FNAME_MODEL, "rb")) != NULL) { if (debug_mode) puts (PROGNAME"660 Found it!"); create_new_dbd (f); fclose (f); goto DBD_OKAY; } else if (errno != ENOENT) { print_usage(); printf (catgets (dtsearch_catd, MS_initausd, 213, default_unable_to_open_msg), "\n"PROGNAME"655", FNAME_MODEL, strerror(errno)); DtSearchExit (4); } /* end else CASE 2 */ /* CASE 3: Last chance. Look for model .dbd in target directory. * At this point have to quit on any error. */ strcpy (modelpath, newpath); strcpy (modelpath + path_offset, FNAME_MODEL); if (debug_mode) printf (PROGNAME"672 Try opening '%s' (new dir).\n", modelpath); if ((f = fopen (modelpath, "rb")) != NULL) { if (debug_mode) puts (PROGNAME"675 Found it!"); create_new_dbd (f); fclose (f); goto DBD_OKAY; } if (debug_mode) puts (PROGNAME"682 Never found it!"); print_usage(); printf (catgets (dtsearch_catd, MS_initausd, 213, default_unable_to_open_msg), "\n"PROGNAME"686", FNAME_MODEL, "Not found in either current or target directories. Use -d option\a"); DtSearchExit (4); DBD_OKAY: /* Open a new database */ *newextp = 0; /* use no extension when opening database */ if (debug_mode) printf ("040*** d_open newpath = '%s'.\n", newpath); d_open (newpath, "o"); if (db_status != S_OKAY) { printf (catgets (dtsearch_catd, MS_initausd, 230, PROGNAME "230 Could not open database '%s'.\n"), newpath); puts (vista_msg (PROGNAME "231")); DtSearchExit (3); } austext_exit_dbms = (void (*) (int)) d_close; /* emerg exit func */ /* initialize the 'dtsearch' database */ if (debug_mode) printf ("042*** d_initialize.\n"); d_initialize (0); if (db_status != S_OKAY) { printf (catgets (dtsearch_catd, MS_initausd, 239, PROGNAME "239 Could not initialize database '%s'.\n"), newpath); puts (vista_msg (PROGNAME "240")); DtSearchExit (3); } /* Create and initialize dbrec database header record in first slot. * First fill entire record with binary zeros. * Then set specific values as specified by flavor on command line. * For now most values are hard-coded. */ if (debug_mode) printf ("050*** create dbrec.\n"); memset (&dbrec, 0, sizeof (dbrec)); /* Init fields that are completely independent */ dbrec.or_language = (DtSrINT16) language; dbrec.or_maxwordsz = (DtSrINT16) maxwordsz; dbrec.or_minwordsz = (DtSrINT16) minwordsz; dbrec.or_fzkeysz = (DtSrINT16) fzkeysz; dbrec.or_abstrsz = (DtSrINT16) abstrsz; dbrec.or_dbflags = ORD_NONOTES | ORD_NOMARKDEL | ORD_XWORDS; strncpy (dbrec.or_version, SCHEMA_VERSION, sizeof(dbrec.or_version)); dbrec.or_version [sizeof(dbrec.or_version) - 1] = 0; /* Load dbrec's recslots fields based on correct number * of misc recs required to hold user's abstract. * Round abstrsz upward if there is any space left on last misc rec. */ dbrec.or_recslots = 1; /* start with obj rec itself */ for (i = dbrec.or_fzkeysz + dbrec.or_abstrsz; i > 0; i -= max_ormisc_size) dbrec.or_recslots++; if (i < 0) { /* Add in difference to INCREASE abstrsz */ dbrec.or_abstrsz -= i; printf (catgets (dtsearch_catd, MS_misc, 433, "%1$sAdjusted maximum abstract size upward to %2$hd.\n"), PROGNAME "433 ", dbrec.or_abstrsz); } /* Init fields that are dependent on language */ switch (language) { case DtSrLaENG: case DtSrLaENG2: dbrec.or_dbflags |= ORD_XSTEMS; break; default: break; } /* Init fields that are dependent on flavor */ if (flavor == AUSTEXT_FLAVOR) { dbrec.or_dbaccess = ORA_BLOB; dbrec.or_compflags = ORC_COMPBLOB; dbrec.or_hufid = -1L; /* -1 = use huffman compression, but * hufid not yet known. */ dbrec.or_dbotype = DtSrObjTEXT; } else { /* default flavor == DTSEARCH_FLAVOR */ dbrec.or_dbaccess = ORA_NOTAVAIL; } if (!quiet_mode) { /******putchar ('\n');******/ print_dbrec (newpath, &dbrec); fflush (stdout); } swab_dbrec (&dbrec, HTON); if (debug_mode) printf ("060*** fillnew dbrec.\n"); d_fillnew (OR_DBREC, &dbrec, 0); if (db_status != S_OKAY) { printf (catgets (dtsearch_catd, MS_initausd, 509, PROGNAME "509 Could not initialize database header record.\n")); puts (vista_msg (PROGNAME "510")); DtSearchExit (3); } /* Close the database */ d_close (); austext_exit_dbms = NULL; /* emerg exit no longer required */ /* Delete all nonvista (inverted index) database files (.d9x) */ remove_d9x_file (".d97"); remove_d9x_file (".d98"); remove_d9x_file (".d99"); *newextp = 0; /* no extension suffixes for next msgs */ printf (catgets (dtsearch_catd, MS_initausd, 24, PROGNAME " Successfully initialized database '%s'.\n"), newpath); return 0; } /* main() */