Example #1
0
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() */
Example #2
0
/* dblk.path may be NULL */
int             open_dblk (DBLK ** dblist, int numpages, int debugging)
{
    DBLK           *db, *bad_db, **lastlink;
    int             i;
    size_t          totlen = 0L;
    char           *allnames;
    int             vistano = 0;
    char           *srcptr, *targptr;
    char            temp_file_name[1024];
    char            sprintbuf[1024];
    struct stat     statbuf;
    char	open_mode [8];

    if (debugging)
	fprintf (aa_stderr, PROGNAME"76 "
	    "Entering open_dblks().  db_oflag==%d.\n",
	    db_oflag);
    if (dblist == NULL || numpages < 8) {
BAD_INPUT:
	sprintf (sprintbuf, catgets (dtsearch_catd, MS_oeinit, 99,
		"%s Programming Error: Invalid input to open_dblk()."),
	    PROGNAME "99");
	DtSearchAddMessage (sprintbuf);
	return FALSE;
    }
    if (*dblist == NULL)	/* empty list of dblks */
	goto BAD_INPUT;

    if (debugging) {
	fprintf (aa_stderr, PROGNAME "96 Current list of dblks:\n");
	for (db = *dblist; db != NULL; db = db->link) {
	    targptr = sprintbuf;
	    for (i = 0; i < db->ktcount; i++) {
		*targptr++ = db->keytypes[i].ktchar;
	    }
	    *targptr = 0;
	    fprintf (aa_stderr, "--> DBLK at %p link=%p name='%s' maxhits=%d\n"
		"    keytypes='%s', path='%s'\n",
		(void *) db, (void *) db->link, db->name, db->maxhits,
		sprintbuf, NULLORSTR (db->path));
	}
    }

    /* By doing setpages first, we can trap previously opened databases.
     * Overflow and transaction locking files are not required.
     */
    d_setpages (numpages, 0);
    if (db_status != S_OKAY) {
	DtSearchAddMessage (vista_msg (PROGNAME "389"));
	return FALSE;
    }

    /* ---- PASS #1 ------------------------------------------
     * Open nonvista (d99) files.  If error, unlink dblk from dblist.
     * Add up the total string length of surviving paths and database names.
     * This giant path/file string will be used in the single d_open()
     * below to find the .dbd files.
     * While we're at it, set vistano in each dblk.
     * The open mode depends on the current setting of db_oflag.
     */
    if (db_oflag == O_RDONLY)
	strcpy (open_mode, "rb");
    else
	strcpy (open_mode, "r+b");
    db = *dblist;
    lastlink = dblist;
    while (db != NULL) {
	if (db->path == NULL)
	    db->path = strdup ("");
	strcpy (temp_file_name, db->path);
	strcat (temp_file_name, db->name);
	strcat (temp_file_name, EXT_DTBS);
	if ((db->iifile = fopen (temp_file_name, open_mode)) == NULL) {
	    if (debugging)
		fprintf (aa_stderr, PROGNAME "129 UNLINK: cant open '%s'.\n",
		    temp_file_name);
	    sprintf (sprintbuf, catgets (dtsearch_catd, MS_oeinit, 317,
		    "%s Cannot open database file '%s'.\n"
		    "  Errno %d = %s\n"
		    "  %s is removing '%s' from list of available databases."),
		PROGNAME "317", temp_file_name, errno, strerror (errno),
		OE_prodname, db->name);
	    if (errno == ENOENT)
		strcat (sprintbuf, catgets (dtsearch_catd, MS_oeinit, 318,
		    "\n  This can usually be corrected by specifying a valid\n"
		    "  database PATH in the site configuration file."));
	    DtSearchAddMessage (sprintbuf);
	    goto DELETE_DB;
	}

	/*
	 * Find and save the timestamp for when the d99 file was
	 * last modified. An engine reinit is forced if it changes
	 * while the engine is running. 
	 */
	if (fstat (fileno (db->iifile), &statbuf) == -1) {
	    if (debugging)
		fprintf (aa_stderr,
		    PROGNAME "149 UNLINK: cant get status '%s'.\n",
		    temp_file_name);
	    sprintf (sprintbuf, catgets (dtsearch_catd, MS_oeinit, 1404,
		    "%s Removing database '%s' from list of "
		    "available databases because status is "
		    "unavailable for file %s: %s"),
		PROGNAME "1404", db->name, temp_file_name, strerror (errno));
	    DtSearchAddMessage (sprintbuf);
	    goto DELETE_DB;
	}
	db->iimtime = statbuf.st_mtime;

	/*
	 * This dblk is ok so far.  Increment pointers and
	 * continue. 
	 */
	if (debugging)
	    fprintf (aa_stderr, PROGNAME "163 opened '%s'.\n", temp_file_name);
	db->vistano = vistano++;
	totlen += strlen (db->path) + strlen (db->name) + 16;
	lastlink = &db->link;
	db = db->link;
	continue;

DELETE_DB:
	/*
	 * This dblk failed in one or more ways. Unlink it and
	 * don't increment pointers. If all dblks unlinked, *dblist
	 * will = NULL. 
	 */
	bad_db = db;	/* temp save */
	*lastlink = db->link;
	db = db->link;
	free (bad_db);
    }	/* end PASS #1 */

    /* quit if no dblks remain */
    if (vistano <= 0) {
	sprintf (sprintbuf, catgets (dtsearch_catd, MS_misc, 8,
		"%s No valid databases remain."), PROGNAME "265");
	DtSearchAddMessage (sprintbuf);
	return FALSE;
    }

    allnames = austext_malloc (totlen + 512, PROGNAME "66", NULL);

    /* ---- PASS #2 ------------------------------------------
     * Build string of accumulated path and database names.
     */
    targptr = allnames;
    for (db = *dblist; db != NULL; db = db->link) {
	srcptr = db->path;
	while (*srcptr != 0)
	    *targptr++ = *srcptr++;

	srcptr = db->name;
	while (*srcptr != 0)
	    *targptr++ = *srcptr++;
	*targptr++ = ';';
    }
    *(--targptr) = 0;	/* terminate string */

    if (debugging)
	fprintf (aa_stderr,
	    PROGNAME "150 vista opening databases '%s'\n", allnames);
    d_open (allnames, "o");	/* replaces OPEN() call from dmacros.h */

    if (db_status != S_OKAY) {
	targptr = austext_malloc (totlen + 128, PROGNAME"239", NULL);
	sprintf (targptr, catgets (dtsearch_catd, MS_vista, 378,
	    "%s Could not open following database name string:\n  '%s'"),
	    PROGNAME"378", allnames);
	DtSearchAddMessage (targptr);
	DtSearchAddMessage (vista_msg (PROGNAME"379"));
	free (allnames);
	free (targptr);
	return FALSE;
    }
    else if (debugging)
	fprintf (aa_stderr, " --> vista open successful!\n");

    /* From here on, emergency exits MUST close the databases */
    austext_exit_dbms = (void (*) (int)) d_close;

    free (allnames);
    return TRUE;
}  /* open_dblk() */
Example #3
0
/* 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() */