コード例 #1
0
/* Copies and moves binary contents in passed, preopened
 * model .dbd file (f) to new dbd file in target directory.
 * Rename the internal .d00, etc filenames to match dbname.
 */
static void     create_new_dbd (FILE *f)
{
    FILE	*g;	/* target dbd file */
    int		i;
    static char	*nocopy_msg =
		"%s Unable to copy '%s' to '%s':\n  %s\a\n";
		/* (Same as dtsearch.msg: MS_initausd, 214) */
    static char	zeros[] =
		"\0\0\0\0\0\0\0\0\0\0\0\0";

    strcpy (newextp, ".dbd");
    if (debug_mode)
	printf (PROGNAME"507 create_new_dbd '%s'\n", newpath);

    /* If new .dbd file preexists, make sure it is writable */
    confirm_ok_to_overwrite (newpath);
    if (chmod (newpath, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP)) {
	if (errno != ENOENT) {
	    printf (catgets (dtsearch_catd, MS_initausd, 214, nocopy_msg),
		PROGNAME"515", modelpath, newpath, strerror(errno));
	    DtSearchExit (15);
	}
    }

    if ((g = fopen (newpath, "w+b")) == NULL) {
	printf (catgets (dtsearch_catd, MS_initausd, 214, nocopy_msg),
	    PROGNAME"509", modelpath, newpath, strerror(errno));
	DtSearchExit (4);
    }
    errno = 0;
    while ((i = fgetc (f)) != EOF)
	fputc (i, g);
    if (errno) {
	printf (catgets (dtsearch_catd, MS_initausd, 214, nocopy_msg),
	    PROGNAME"531", modelpath, newpath, strerror(errno));
	DtSearchExit (13);
    }

    /* Now reposition the write head in the new dbd file
     * to rename the filenames.  Rename each internal file
     * name to '<newdbname>.xxx'.
     */
    for (i = 0;  exttab[i] != NULL;  i++) {
	fseek (g, START_OF_FT + (i * SIZEOF_FILE_ENTRY), SEEK_SET);	
	fprintf (g, "%s%s", dbname, exttab[i]);
	fwrite (zeros, sizeof(char), sizeof(zeros), g);
    }

    /* The new dbd file only has to be readable */
    fclose (g);
    chmod (newpath, S_IRUSR | S_IRGRP | S_IROTH);
    return;
}  /* create_new_dbd() */
コード例 #2
0
static void     retncode_abort (int location)
{
    fputc ('\n', aa_stderr);
    if (DtSearchHasMessages ())
	fprintf (aa_stderr, "%s\n", DtSearchGetMessages ());
    fprintf (aa_stderr,
	PROGNAME "%d Program abort.  usrblk.retncode = %d.  Exit code = 3.\n",
	location, usrblk.retncode);
    DtSearchExit (3);
}  /* retncode_abort() */
コード例 #3
0
ファイル: dtsrjoint.c プロジェクト: idunham/cdesktop
/* Confirms ausapi_init() was first function called. */
void            aa_check_initialization (void)
{
    if (aa_is_initialized)
	return;
    fprintf (aa_stderr,
	catgets (dtsearch_catd, 2, 37,
	    "%s First API function call must be DtSearchInit().\n"),
	PROGNAME"37");
    DtSearchExit (37);
}  /* aa_check_initialization() */
コード例 #4
0
ファイル: dtsrapi.c プロジェクト: idunham/cdesktop
/* Interrupt handler for all common 'abort' signals.
 * Shuts down gracefully by ensuring database properly closed.
 * The database close and write to the audit log occur in OE.
 */
static void     signal_abort (int sig)
{
    fputs (DtSearchGetMessages (), aa_stderr);
    fprintf (aa_stderr, catgets (dtsearch_catd, MS_ausapi, 216,
	"\n%s %s Caught signal %d.\n"),
	PROGNAME"216",
	(aa_argv0) ? aa_argv0 : OE_prodname,
	sig);
    fflush (aa_stderr);
    DtSearchExit (100 + sig);
}  /* signal_abort() */
コード例 #5
0
static void     remove_d9x_file (char *extension)
{
                    strcpy (newextp, extension);
    if (debug_mode)
	printf ("094*** delete '%s'.\n", newpath);
    if (remove (newpath) != 0) {
	/* 'file not found' is not an error */
	if (errno != ENOENT) {
	    printf (catgets (dtsearch_catd, MS_initausd, 244,
		    PROGNAME "244 Unable to remove '%s': %s\n"),
		newpath, strerror (errno));
	    DtSearchExit (5);
	}
    }
    return;
}  /* remove_d9x_file() */
コード例 #6
0
ファイル: dtsrjoint.c プロジェクト: idunham/cdesktop
/* Subroutine of DtSearchSortResults().
 * Sorts a list of DtSrResult structures and returns ptr to sorted list.
 * The basic idea is to sort by recursively splitting a list
 * into two equal halves and sorting each of those.  The recursion
 * ends when there are only two small lists which are either
 * already sorted or are swapped.  This sort rarely runs out
 * of stack space because each recursion cuts the list length in
 * half so there are at most 1 + log-N-to-the-base-2 items on the stack.
 * (e.g. 64,000 nodes = max stack depth of 16:  2**16 = 64K).
 */
static DtSrResult *ditto_sort (DtSrResult * lst)
{
    DtSrResult     *lst2;

    if ((lst == NULL) || (lst->link == NULL))
	return lst;
    lst2 = ditto_split (lst);
    switch (ditsort_type) {
	case DtSrSORT_PROX:
	    return merge_by_prox (ditto_sort (lst), ditto_sort (lst2));
	case DtSrSORT_DATE:
	    return merge_by_date (ditto_sort (lst), ditto_sort (lst2));
	default:
	    fprintf (aa_stderr, PROGNAME "525 Invalid Sort Type %d.\n",
		ditsort_type);
	    DtSearchExit (32);
    }
}  /* ditto_sort() */
コード例 #7
0
/* Called whenever we are about to write a new file.
 * Checks to see if file preexists.  If it does,
 * and user has never said it's ok to overwrite,
 * prompts for permission to overlay all preexisting files.
 * If 'yes', never asks again.  If 'no', exits.
 * Returns if ok to overwrite, else exits.
 */
static void	confirm_ok_to_overwrite (char *fname)
{
    FILE	*fptr;
    int		i;

    if (ok_to_overwrite)
	return;
    if ((fptr = fopen (newpath, "r")) == NULL)
	return;
    fclose (fptr);

    printf ( catgets(dtsearch_catd, MS_initausd, 12,
	"\nFile '%s' already exists.\n"
	"Is it ok to overwrite it and other database files? [y,n] ") ,
	newpath);
    i = tolower (getchar());
    if (i == 'y')
	ok_to_overwrite = TRUE;
    else
	DtSearchExit (2);
    return;
} /* confirm_ok_to_overwrite() */
コード例 #8
0
ファイル: hdecode.c プロジェクト: idunham/cdesktop
void	hc_decode (
		UCHAR	*bitstring,	/* input: compressed data */
		UCHAR	*charbuf,	/* output: uncompressed data */
		int	charcount,	/* input: length uncompressed data */
		time_t	encode_id)
{  /* input: compression table to use */
#ifdef DEBUG_DECODE
    static int      first_time = TRUE;
#endif
    register int    bitreg;
    int             i;
    int             bitcount;
    int             tree_index;
    TREENODE       *tree_addr;

#ifdef EXTERNAL_TREE
    char           *ptr;
    char           *hdecode_filebuf;
    FILE           *hdecode_file;
    _Xstrtokparams  strtok_buf;
#endif

#ifdef EXTERNAL_TREE
    /* Create hctree from external file? */
    if (hctree == NULL) {
	if ((hdecode_filebuf = malloc (HDEC_FBUFSZ)) == NULL) {
	    fprintf (aa_stderr, catgets(dtsearch_catd, MS_huff, 10,
		"%s Out of Memory.\n"),
		PROGNAME"076");
	    DtSearchExit (2);
	}
	if ((hdecode_file = fopen (hctree_name, "r")) == NULL) {
	    fprintf (aa_stderr, catgets(dtsearch_catd, MS_huff, 11,
		"%s Cannot open tree file '%s': %s\n"),
		PROGNAME"082", hctree_name, strerror (errno));
	    DtSearchExit (2);
	}

	/* read first few lines to load global variables */
	for (i = 0; i < 3; i++)
	    fgets (hdecode_filebuf, HDEC_FBUFSZ, hdecode_file);
	ptr = strchr (hdecode_filebuf, '=');
	hctree_id = atol (ptr + 1);

	fgets (hdecode_filebuf, HDEC_FBUFSZ, hdecode_file);
	ptr = strchr (hdecode_filebuf, '=');
	hctree_root = atoi (ptr + 1);

	fgets (hdecode_filebuf, HDEC_FBUFSZ, hdecode_file);	/* throwaway */

	/* allocate space for the hctree and read in the values */
	if ((hctree = (int *) malloc (
		sizeof (int) * 2 * (hctree_root + 2))) == NULL) {
	    fprintf (aa_stderr, "\n" PROGNAME "100 Out of Memory.\7\n");
	    DtSearchExit (2);
	}
	for (i = 0; i <= hctree_root; i++) {
	    if ((fgets (hdecode_filebuf, HDEC_FBUFSZ, hdecode_file)) == NULL) {
		fprintf (aa_stderr, catgets(dtsearch_catd, MS_huff, 12,
		    "%s Invalid format hctree '%s'.\n"),
		    PROGNAME"106", hctree_name);
		DtSearchExit (2);
	    }
	    hctree[2 * i] = atoi (_XStrtok (hdecode_filebuf, " \t,", strtok_buf));
	    hctree[2 * i + 1] = atoi (_XStrtok (NULL, " \t,", strtok_buf));
	}
	free (hdecode_filebuf);
	fclose (hdecode_file);
    }	/* endif where hctree created from external file */
#endif	/* for EXTERNAL_TREE */

#ifdef DEBUG_DECODE
    if (first_time) {
	first_time = FALSE;
	printf ("\n***** created hctree from '%s' ******\n"
	    "hctree_id = %ld\nhctree_root = %d\n",
	    hctree_name, hctree_id, hctree_root);
    }
#endif


    if (encode_id != hctree_id) {
	fprintf (aa_stderr, catgets(dtsearch_catd, MS_huff, 13,
	    "%s Incompatible hctree_ids.\n"),
	    PROGNAME"118");
	DtSearchExit (2);
    }
    tree_addr = (TREENODE *) hctree;
    bitcount = 0;
    while (charcount-- > 0) {	/****** MAIN OUTPUT CHARACTER LOOP ******/
	tree_index = hctree_root;
	while (tree_index >= 0) {	/****** TREE TRAVERSAL LOOP ******/
	    /* retrieve next bit */
	    if (bitcount <= 0) {	/* read next input char? */
		bitcount = 8;
		bitreg = *bitstring++;
	    }
	    bitreg <<= 1;
	    bitcount--;
	    if (bitreg & 0x0100)
		tree_index = tree_addr[tree_index].branch1;
	    else
		tree_index = tree_addr[tree_index].branch0;
	}	/* end tree traversal loop */

	/******** DECODE CHARACTER ********/
	/* if literal code, retrieve next 8 bits as char itself */
	if ((tree_index += 257) == 256) {
	    tree_index = 0;
	    for (i = 8; i > 0; i--) {
		if (bitcount <= 0) {	/* read next input char? */
		    bitcount = 8;
		    bitreg = *bitstring++;
		}
		bitreg <<= 1;
		bitcount--;
		tree_index <<= 1;
		if (bitreg & 0x0100)
		    tree_index |= 1;
	    }	/* end 8-bit for loop */
	}	/* endif to process literal coding */
	*charbuf = tree_index;
	charbuf++;
    }	/* end main output character loop */

    return;
}  /* end of function hc_decode */
コード例 #9
0
int             main (int argc, char *argv[])
{
    char           *arg;
    time_t          mytime;
    char            timebuf[80];

    aa_argv0 = argv[0];
    setlocale (LC_ALL, "");
    dtsearch_catd = catopen (FNAME_DTSRCAT, 0);
    time (&mytime);
    strftime (timebuf, sizeof (timebuf),
        catgets(dtsearch_catd, MS_misc, 22, "%A, %b %d %Y, %I:%M %p"),
	localtime (&mytime));
    printf (catgets(dtsearch_catd, MS_tomita, 29,
	"%s.  Run %s.\n") ,
	aa_argv0, timebuf);
    austext_exit_last = print_exit_code;

    signal (SIGINT, DtSearchExit);
    signal (SIGTERM, DtSearchExit);
/****memset (&usrblk, 0, sizeof(USRBLK));****/

    /* Validate program number argument */
    if (argc < 2) {
BAD_ARGS:
	fprintf (aa_stderr, catgets(dtsearch_catd, MS_tomita, 30,
	    "\nUSAGE: %s [options]\n"
	    "  -i    Input file name.  If not specified, defaults to %s.\n"
	    "  -d[v] Print debug statements.\n"
	    "        -dv turns on verbose (record-by-record) debugging.\n"
	    "  -t<N> Max desired number of seconds of run time.\n"
	    "        Ctrl-C/Break will also stop deletion at next record.\n"
	    "  -n<N> Change number of records in a batch from %d to <N>.\n"
	    "  -y    Automatically answers 'yes' to Delete mode confirm prompt.\n"
	    "  -d    trace deletion operations.\n") ,
	    aa_argv0, FNAME_DISCARD_DATA,
	    FNAME_CONFIRM_LIST, FNAME_CONFIRM_LIST, DBACOUNT);
	DtSearchExit (2);
    }
    prog = toupper (argv[1][0]);
    if (prog != 'B' && prog != 'D')
	goto BAD_ARGS;

    /* Initialize defaults depending on program mode */
    if (prog == 'B') {
	infname = FNAME_DISCARD_DATA;
	outfname = FNAME_CONFIRM_LIST;
    }
    else {
	infname = FNAME_CONFIRM_LIST;
	outfname = PROGNAME "654";
    }
    maxtime = 0L;

    /* Save rest of command line arguments */
    for (argc -= 2, argv += 2; argc > 0; argc--, argv++) {
	arg = *argv;
	switch (tolower (arg[1])) {
	    case 'i':
		infname = arg + 2;
		break;

	    case 'o':
		outfname = arg + 2;
		break;

	    case 'd':
		debug_mode = TRUE;
		usrblk.debug |= USRDBG_DELETE;
		if (arg[2] == 'v')
		    usrblk.debug |= USRDBG_VERBOSE;
		break;

	    case 'y':
		yesarg = TRUE;
		break;

	    case 't':
		maxtime = atol (arg + 2);
		break;

	    case 'n':
		max_dbacount = atol (arg + 2);
		break;

	    default:
		fprintf (aa_stderr, catgets(dtsearch_catd, MS_tomita, 31,
		    "\n%s Unknown argument '%s'.\n") ,
		    PROGNAME"689", arg);
		goto BAD_ARGS;

	}	/* end switch */
    }	/* end arg parsing */

    /* Open input file to test for its existence.
     * For the Browse program, file ptr 'inf' == NULL
     * means the file is not open.
     */
    if ((inf = fopen (infname, "r")) == NULL) {
	if (prog == 'D') {
	    fprintf (aa_stderr, catgets(dtsearch_catd, MS_tomita, 32,
		"%s Unable to open input file '%s'.\n") ,
		PROGNAME"710", infname);
	    goto BAD_ARGS;
	}
    }

    /* If browsing, get output file name and
     * open it to test for write permission.
     */
    if (prog == 'B') {
	if ((outf = fopen (outfname, "a ")) == NULL)
	    /* the blank in "a " works around old aix bug */
	{
	    fprintf (aa_stderr,  catgets(dtsearch_catd, MS_tomita, 33,
		"\n%s Unable to open output file '%s'.\n") ,
		PROGNAME"721", outfname);
	    goto BAD_ARGS;
	}
    }

    /* Initialize the opera engine, i.e. open the database */
    printf ( catgets(dtsearch_catd, MS_tomita, 34,
	"Initializing %s engine...\n"),
	OE_prodname);
    strcpy (usrblk.userid, "ToMiTa");
    usrblk.request = OE_INITIALIZE;
    usrblk.query = AUSAPI_VERSION;
    Opera_Engine ();
    if (usrblk.retncode != OE_OK)
	retncode_abort (733);

    PRINT_MESSAGES
	if (prog == 'B')
	browser ();
    else
	deleter (infname);

    usrblk.request = OE_SHUTDOWN;
    Opera_Engine ();
    printf ( "%s", catgets(dtsearch_catd, MS_tomita, 36,
	"Normal engine shutdown.\n") );
    DtSearchExit (0);
}  /* main() */
コード例 #10
0
ファイル: hencode.c プロジェクト: idunham/cdesktop
void            gen_vec (char *fname_huffcode_tab)
{
    char            temp[40];
    int             i, j;
    char            tab_filebuf[128];
    unsigned char   ch;
    FILE           *tab_stream;
    _Xstrtokparams  strtok_buf;

    if ((tab_stream = fopen (fname_huffcode_tab, "r")) == NULL) {
	printf (catgets(dtsearch_catd, MS_huff, 1,
	    "%s: Cannot open huffman encode file '%s':\n"
	    "  %s\n  Exit Code = 2\n"),
	    PROGNAME"222", fname_huffcode_tab, strerror (errno));
	DtSearchExit (2);
    }
    memset (huff_code, 0, sizeof(huff_code));
    memset (code_length, 0, sizeof(code_length));
    /*
     * First line in the file contains time stamp. We have to read
     * it separately. First token on first line is hufid. Save it
     * in a global for optional use by caller. 
     */
    fgets (tab_filebuf, sizeof (tab_filebuf) - 1, tab_stream);
    gen_vec_hufid = atol (tab_filebuf);

    /*-------------- READ IN HUFFMAN FILE ------------*/
    /*
     * We are only interested in the character itself (index) and
     * its Huffman Code 
     */
    while (fgets (tab_filebuf, sizeof (tab_filebuf) - 1, tab_stream)
	!= NULL) {
	i = atoi (_XStrtok (tab_filebuf, DELIMITERS, strtok_buf)); /* char */
	/* read current huff code */
	strcpy (temp, _XStrtok (NULL, DELIMITERS, strtok_buf));
	if (temp[0] == ' ') {
	    /* Empty huffcode associated with LITERAL CODE.
	     * Either this is literal char itself and literal
	     * encodeing has been turned off, or this char is
	     * so rare that it is coded using the literal char.
	     */
	    if (i == 256)
		continue;

	    /* current character has LITERAL CODE */
	    strcpy (temp, huff_code[LITERAL_NUM]);
	    *(code_length + i) = *(code_length + LITERAL_NUM) + 8;
	    ch = (unsigned char) i;
	    for (j = 0; j < 8; j++) {
		if (ch & 0x80) {
		    temp[*(code_length + LITERAL_NUM) + j] =
			'1';
		}
		else {
		    temp[*(code_length + LITERAL_NUM) + j] =
			'0';
		}
		ch = ch << 1;
	    }
	    temp[*(code_length + LITERAL_NUM) + 8] = '\0';
	    huff_code[i] =
		(char *) malloc (*(code_length + i) + 1);
	    strcpy (huff_code[i], temp);
	}
	else {
	    /* regular HUFFMAN code */
	    *(code_length + i) = strlen (temp);
	    huff_code[i] =
		(char *) malloc (*(code_length + i) + 1);
	    strcpy (huff_code[i], temp);
	}
    }
    fclose (tab_stream);
}  /* end of function gen_vec */
コード例 #11
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() */
コード例 #12
0
/* Handles command line arguments for main().
 * Initializes global variables.
 */
static void     user_args_processor (int argc, char **argv)
{
    int		i;
    int		remaining_slot_space;
    char	*ptr;

    /* Initialize variables prior to parsing command line */
    newpath[0] = 0;
    modelpath[0] = 0;

    if (argc < 2) {
	print_usage();
	DtSearchExit (2);
    }

    /* Each pass grabs new parm of "-xxx" format */
    for (;;) {
	argc--;
	argv++;
	if (argc <= 0)
	    break;
	ptr = argv[0];
	if (ptr[0] != '-')
	    break;

	switch (ptr[1]) {
	    case 'r':	/* unadvertised debug mode */
		if (strcmp (ptr, "-russell") == 0) {
		    debug_mode = TRUE;
		    puts ("001*** debug mode.");
		}
		else {
BAD_ARG:
		    print_usage();
		    printf (catgets (dtsearch_catd, MS_misc, 9,
			    "%sInvalid command line argument '%s'.\a\n"),
			"\n"PROGNAME" ", ptr);
		    DtSearchExit (2);
		}
		break;

	    case 'a':
		/* zero length abstract may be explicity specified */
		abstrsz = atoi (ptr + 2);
		if (abstrsz < 0 || (abstrsz == 0 && ptr[2] != '0'))
		    goto BAD_ARG;
		break;

	    case 'q':
		quiet_mode = TRUE;
		break;

	    case 'o':
		ok_to_overwrite = TRUE;
		break;

	    case 'f':
		switch (ptr[2]) {
		    case AUSTEXT_FLAVOR:
		    case DTSEARCH_FLAVOR:
			flavor = ptr[2];
			break;
		    default:
			goto BAD_ARG;
		}
		break;

	    case 'w':	/* change min (-wn..) or max (-wx..) word size */
		switch (ptr[2]) {
		    case 'x':
			if (!change_max_wordsize (ptr + 3))
			    goto BAD_ARG;
			break;
		    case 'n':
			if (!change_min_wordsize (ptr + 3))
			    goto BAD_ARG;
			break;
		    default:
			goto BAD_ARG;
		}
		break;

	    case 'd':	/* special path name for model .dbd */
		strncpy (modelpath, ptr + 2, sizeof(modelpath));
		modelpath [sizeof(modelpath) - sizeof(FNAME_MODEL) - 4] = 0;
		ensure_end_slash (modelpath);
		strcat (modelpath, FNAME_MODEL);
		break;

	    case 'l':
		/* Note that custom, unsupported languages
		 * greater than DtSrLaLAST are permitted.
		 */
		language = atoi (ptr + 2);
		if (language < 0)
		    goto BAD_ARG;
		if (!quiet_mode  &&  language > DtSrLaLAST)
		    printf ( catgets(dtsearch_catd, MS_initausd, 13,
			"%s Warning! you have specified "
			"an unsupported, custom language.\n"
			"  You will have to provide your own "
			"language loaders at run time\n"
			"  in user function 'load_custom_language' "
			"to access this database.\a\n"),
			PROGNAME"444");
		break;

	    default:
		printf (catgets (dtsearch_catd, MS_misc, 10,
			"%sIgnored unknown command line argument '%s'.\n"),
		    PROGNAME " ", ptr);
		break;
	}	/* end switch */
    }	/* end parse of cmd line options beginning with '-' */

    /* Only required arg is new database name,
     * including optional path prefix.
     * Load newpath and newextp, leaving room
     * for long dbnames and .xxx extensions.
     */
    if (argc <= 0) {
	print_usage();
	printf (catgets (dtsearch_catd, MS_misc, 18,
		"%sDatabase name not specified.\n\a"), "\n"PROGNAME" ");
	DtSearchExit(2);
    }
    strncpy (newpath, argv[0], sizeof (newpath));
    newpath [sizeof(newpath) - 12] = 0;
    newextp = newpath + strlen (newpath);

    /* Get just the 1 - 8 char database name by moving ptr
     * backwards until first non-alphanumeric character
     * (such as a ":" in the dos drive id or a slash between directories),
     * or to the beginning of string.
     * Then test database name for validity.
     */
    for (ptr = newpath + strlen(newpath) - 1;  ptr >= newpath;  ptr--)
	if (!isalnum (*ptr)) {
	    ptr++;
	    break;
	}
    if (ptr < newpath)
	ptr = newpath;
    i = strlen (ptr);
    if (i < 1 || i > 8) {
BAD_DBNAME:
	print_usage();
	printf (catgets (dtsearch_catd, MS_misc, 11,
		"%sInvalid database name '%s'.\a\n"),
	    "\n"PROGNAME"346 ", ptr);
	DtSearchExit(2);
    }
    path_offset = ptr - newpath;
    strcpy (dbname, ptr);	/* save it */
    if (strcmp (dbname, "austext") == 0 || strcmp (dbname, "dtsearch") == 0) {
	goto BAD_DBNAME;
    }

    /* Ensure semantic processing specified only for english language */
    if (fzkeysz != 0  && language != DtSrLaENG  &&  language != DtSrLaENG2) {
	print_usage();
	printf ( catgets(dtsearch_catd, MS_initausd, 14,
	    "\n%s semantic processing is only available "
	    "for English language databases.\n\a") ,
	    PROGNAME"340");
	DtSearchExit(2);
    }

    /* Unless overridden by user args,
     * initialize abstract based on flavor.
     * The abstract size defaults to the remaining 
     * space in the final misc slot after the fzkey.
     * However if the user specified a specific
     * abstract size, it may be adjusted later
     * to fill up the last slot.
     */
    if (abstrsz == -1)
	abstrsz = max_ormisc_size - (fzkeysz % max_ormisc_size);

    /* Default maxword size is 'short', except for German */
    if (maxwordsz == INT_MAX)
	maxwordsz = STANDARD_MAXWORD;

    if (debug_mode)
	printf ("002*** userargs: modelpath='%s' newpath='%s'\n"
	    "  fzkeysz=%d abstrsz=%d\n",
	    modelpath, newpath, fzkeysz, abstrsz);
    return;
}  /* user_args_processor() */