home *** CD-ROM | disk | FTP | other *** search
/ ftp.uv.es / 2014.11.ftp.uv.es.tar / ftp.uv.es / pub / unix / freeWAIS-0.202.tar.gz / freeWAIS-0.202.tar / freeWAIS-0.202 / ir / iubuild.c < prev    next >
C/C++ Source or Header  |  1993-10-05  |  30KB  |  811 lines

  1. /* WIDE AREA INFORMATION SERVER SOFTWARE:
  2.    No guarantees or restrictions.  See the readme file for the full standard
  3.    disclaimer.
  4.  
  5.    Brewster@think.com
  6. */
  7.  
  8. /* Copyright (c) CNIDR (see ../COPYRIGHT) */
  9.  
  10.  
  11. #ifndef lint
  12. static char *RCSid = "$Header: /usr/users/freewais/FreeWAIS-0.1/ir/iubuild.c,v 1.1 1993/02/16 15:05:35 freewais Exp $";
  13. #endif
  14.  
  15. /*
  16.  * Building an index with a Unix shell interface.
  17.  *
  18.  * -brewster 6/90
  19.  */
  20.  
  21. /* Change log:
  22.  * added -stdio option from jik@athena.mit.edu
  23.  * $Log: iubuild.c,v $
  24.  * Revision 1.1  1993/02/16  15:05:35  freewais
  25.  * Initial revision
  26.  *
  27.  * Revision 1.47  92/05/10  14:48:17  jonathan
  28.  * Updated for release.
  29.  * 
  30.  * Revision 1.46  92/05/08  10:03:17  jonathan
  31.  * Adjusted memory paramters.  It's closer...
  32.  * 
  33.  * Revision 1.45  92/05/06  17:26:46  jonathan
  34.  * Added switch for indexing contents, new user-specified type name, new type:
  35.  * filename, which only puts the name of the file in the header.
  36.  * 
  37.  * Revision 1.44  92/04/25  21:14:35  brewster
  38.  * added ziff
  39.  * 
  40.  * Revision 1.43  92/04/22  15:29:13  jonathan
  41.  * Added jargon to usage message.
  42.  * 
  43.  * Revision 1.42  92/04/01  17:08:50  jonathan
  44.  * Added FTP type.
  45.  * 
  46.  * Revision 1.41  92/03/25  18:49:39  jonathan
  47.  * Added log_level and log_file arguments.
  48.  * 
  49.  * Revision 1.40  92/03/22  18:38:14  brewster
  50.  * added objective C filter
  51.  * 
  52.  * Revision 1.39  92/03/20  11:02:44  jonathan
  53.  * Added code to handle switches for word_pairs and word_postition info.
  54.  * 
  55.  * Revision 1.38  92/03/17  07:34:32  jonathan
  56.  * Fixed spacing in usage message.
  57.  * 
  58.  * Revision 1.37  92/03/10  10:42:51  morris
  59.  * fixed small bug in command line argument handleing.  doesn't die if there
  60.  * are no args.
  61.  * 
  62.  * Revision 1.36  92/03/05  07:05:32  shen
  63.  * add cm grow percent and textsize to command line and init search engine
  64.  * 
  65.  * Revision 1.35  92/03/04  16:34:09  jonathan
  66.  * Set wais_pid from getpid().
  67.  * 
  68.  * Revision 1.34  92/02/20  09:49:37  jonathan
  69.  * Added bibtex and nhyp filters from S.P.vandeBurgt@research.ptt.nl.
  70.  * 
  71.  * Revision 1.33  92/02/17  14:21:08  jonathan
  72.  * Added switch to disable creation of catalog (-nocat).
  73.  * 
  74.  * Revision 1.32  92/02/17  12:41:55  jonathan
  75.  * Added RCSid.
  76.  * 
  77.  * Revision 1.31  92/02/17  12:41:01  jonathan
  78.  * Build catalog after completion of indexing.
  79.  * 
  80.  * Revision 1.30  92/02/12  13:22:53  jonathan
  81.  * Added "$Log" so RCS will put the log message in the header
  82.  * 
  83.  */
  84.  
  85. /* to do:
  86.  *   done: make incremental indexing not index things that are already index
  87.  *   add extra arg -register that will send in description of the server to 
  88.  *           the directory of servers.
  89.  *   done: create a source struct in the .src file
  90.  *   make it continuously index to keep itself uptodate.
  91.  *
  92.  */
  93.  
  94. #include <string.h>
  95. #include <sys/types.h>
  96. #include <sys/param.h>
  97. #include "irdirent.h"
  98. #include "cutil.h"
  99. #include "futil.h"
  100. #include "irfiles.h"
  101. #include "irtfiles.h"
  102. #include "panic.h"
  103. #include "ircfiles.h"
  104. #include "version.h"
  105. #include "irext.h"
  106.  
  107. #define INDEXER_DATE "Sun May 10 1992"
  108.  
  109. /* for reporting errors, in WAIStation it is defined in CRetrievalApp.c */
  110.  
  111. extern boolean indexingForBeta;
  112.  
  113. void usage(command)
  114. char *command;
  115. { /* no args */
  116.   fprintf(stderr,"Usage: %s [-d index_filename]\n", command);
  117.   fprintf(stderr,"          [-a] /* adding to an existing index, otherwise it erases the index */\n");
  118.   fprintf(stderr,"          [-r] /* recursively index subdirectories */\n");
  119.   fprintf(stderr,"          [-mem mbytes] /* number of megabytes to run this in */\n");
  120.   fprintf(stderr,"          [-register] /* registers the database with the directory of servers.\n");
  121.   fprintf(stderr,"                         This should be done with care. */\n");
  122.   fprintf(stderr,"          [-export] /* uses short dbname and port 210 */\n");
  123.   fprintf(stderr,"          [-e [file]] /* set log output to file, or /dev/null if not specified */\n");
  124.   fprintf(stderr,"          [-l log_level] /* set log level.  0 means log nothing,\n");
  125.   fprintf(stderr,"                            10 [the default] means log everything */\n");
  126.   fprintf(stderr,"          [-v] /* print the version of the software */\n");
  127.   fprintf(stderr,"          [-stdin] /* read file names from stdin */\n");
  128.   fprintf(stderr,"          [-pos | -nopos] /* include (don't include - default) word position information /*\n");
  129.   fprintf(stderr,"          [-nopairs | -pairs] /* don't include (or include - default) word pairs /*\n");
  130.   fprintf(stderr,"          [-nocat] /* inhibit creation of catalog /*\n");
  131.   fprintf(stderr,"          [-contents] /* Index the contents: this is good for types that\n");
  132.   fprintf(stderr,"                         inhibit the indexing of the contents (like gif). /*\n");
  133.   fprintf(stderr,"          [-nocontents] /* Index only the filename, not the contents /*\n");
  134.   fprintf(stderr,"          [-cmmem  mem%] /* percent of CM memory (CM code only) */\n");
  135.   fprintf(stderr,"          [-T  type] /* type becomes the \"TYPE\" of the document. */\n");
  136.   fprintf(stderr,"          [-t    /* format of the file. if none then each file is a document */\n");
  137.   fprintf(stderr,"             text /* simple text files, this is the default */\n");
  138.   fprintf(stderr,"           | bibtex /* BibTeX / LaTeX format */\n");
  139.   fprintf(stderr,"           | bio /* biology abstract format */\n");
  140.   fprintf(stderr,"           | cmapp /* CM applications from Hypercard */\n");
  141.   fprintf(stderr,"           | dash /* entries separated by a row of dashes */\n");
  142.   fprintf(stderr,"           | dvi /* dvi format */\n");     
  143.   fprintf(stderr,"           | emacsinfo /* the GNU documentation system */\n");
  144.   fprintf(stderr,"           | first_line /* first line of file is headline */\n");
  145.   fprintf(stderr,"           | filename /* uses only the filename part of the pathname for the title */\n");
  146.   fprintf(stderr,"           | ftp /* special type for FTP files.  First line of file is headline */\n");
  147.   fprintf(stderr,"           | gif /* gif files, only indexes the filename */\n");
  148.   fprintf(stderr,"           | irg /* internet resource guide */\n");
  149.   fprintf(stderr,"           | jargon /* Jargon File 2.9.8 format*/\n");
  150.   fprintf(stderr,"           | mail_digest /* standard internet mail digest format */\n");
  151.   fprintf(stderr,"           | mail_or_rmail /* mail or rmail or both */\n");
  152.   fprintf(stderr,"           | medline /* medline format */\n");
  153.   fprintf(stderr,"           | mh_bboard /* MH bulletin board format */\n");
  154.   fprintf(stderr,"           | netnews /* netnews format */\n");
  155.   fprintf(stderr,"           | nhyp /* ?:? hyper text format, Polytechnic of Central London */\n");
  156.   fprintf(stderr,"           | one_line /* each line is a document */\n");
  157.   fprintf(stderr,"           | para /* paragraphs separated by blank lines */\n");
  158.   fprintf(stderr,"           | pict /* pict files, only indexes the filename */\n");
  159.   fprintf(stderr,"           | ps /* postscript format */\n");
  160.   fprintf(stderr,"           | refer /* refer format */\n");
  161.   fprintf(stderr,"           | rn /* netnews saved by the [rt]?rn newsreader */\n");
  162.   fprintf(stderr,"           | server /* server structures for the dir of servers */\n");
  163. #ifdef NeXT
  164.   fprintf(stderr,"           | objc /* objective-C .h and .m files */\n");
  165. #endif /* def NeXT */
  166.   fprintf(stderr,"           | tiff /* tiff files, only indexes the filename */\n");
  167.      fprintf(stderr,"           | genbank  /* GenBank flatfile format */\n");
  168.      fprintf(stderr,"           | embl     /* EMBL flatfile format */\n");
  169.      fprintf(stderr,"           | pir     /* PIR flatfile format */\n");
  170.      fprintf(stderr,"           | prositedoc /* Prosite protein doc format */\n");
  171.      fprintf(stderr,"           | prositedat /* Prosite protein dat format */\n");
  172.      fprintf(stderr,"           | biojournal /* Bio journal TOC on bionet.journals */\n
  173. ");
  174.      fprintf(stderr,"           | redbook  /* Drosophila redbook text */\n");
  175.  
  176.   fprintf(stderr,"          ] filename filename ...\n");
  177. }
  178.  
  179. char *log_file_name = NULL;
  180. FILE *logfile;
  181.  
  182. extern boolean index_contents;
  183.  
  184. /* This is the MAIN for building an index.
  185.  */
  186. void
  187. main(argc, argv)
  188. int argc;
  189. char *argv[];
  190. {
  191.   database* db = NULL;
  192.   long argc_copy = argc;
  193.   char **argv_copy = argv;
  194.   char *next_argument;
  195.   char index_filename[1000];
  196.   boolean (*separator_function)();
  197.   void (*header_function)();
  198.   void (*finish_header_function)();
  199.   long (*date_function)();
  200.   boolean adding_to_existing_index = false;
  201.   boolean traverse_directory = false;
  202.   boolean word_positions = false;
  203.   boolean word_pairs = true;
  204.   long memory_to_use = -1;
  205.   long cm_mem_percent = 0;  /* default */
  206.   long grow_percent = 0;  /* default */
  207.   long text_size = 0;  /* default */
  208.   boolean check_for_text_file = false;
  209.   boolean register_database = false;
  210.   boolean export_database = false;
  211.   boolean read_files_from_stdin = false;
  212.   boolean make_catalog = true;
  213.   char data_filename[MAXPATHLEN];
  214.   char *typename = NULL;  /* this is what the user said */
  215.   char *type = NULL;      /* this is the type stored with the db */
  216.   long start_of_filenames;
  217.   long hashtable_size = 1L<<16;
  218.   long flush_after_n_words = 300000;
  219.   char *command_name;
  220.   int minwordlen= 2;    /* dgg */
  221.  
  222.   next_argument = next_arg(&argc, &argv);
  223.   separator_function = NULL; /* initailize to nil */
  224.   header_function = NULL;
  225.   date_function = NULL;
  226.   finish_header_function = NULL;
  227.   type = "TEXT"; /* default to text */
  228.   typename = "Text"; 
  229.  
  230.   command_name = next_argument;
  231.  
  232.   logfile = stderr;
  233.   wais_pid = getpid();
  234.  
  235.   if(0 == argc) {
  236.     usage(command_name);
  237.     exit(0);
  238.   }
  239.  
  240. #ifdef THINK_C
  241.   strcpy(index_filename, "wais:System Folder:wais-index:index");
  242. #else
  243.   strcpy(index_filename, "index"); /* in the current directory */
  244. #endif /* THINK_C */
  245.   
  246.   if(NULL == (next_argument = next_arg(&argc, &argv))){
  247.     fprintf(stderr,"No arguments specified\n");
  248.     exit(0);
  249.   }
  250.   while((next_argument != NULL) && '-' == next_argument[0]){
  251.     /* then we have an argument to process */
  252.     if((0 == strcmp("-i", next_argument)) || /* -i is for backcompatibility */
  253.        (0 == strcmp("-d", next_argument))){
  254.       if(NULL == (next_argument = next_arg(&argc, &argv))){
  255.     fprintf(stderr,"Expected filename for the index\n");
  256.     exit(0);
  257.       }
  258.       strcpy(index_filename, next_argument);
  259.       }
  260.     else if(0 == strcmp("-a", next_argument)){
  261.       adding_to_existing_index = true;
  262.     }
  263.     else if(0 == strcmp("-r", next_argument)){
  264.       traverse_directory = true;
  265.     }
  266.     else if(0 == strcmp("-register", next_argument)){
  267.       register_database = true;
  268.     }
  269.     else if(0 == strcmp("-export", next_argument)){
  270.       export_database = true;
  271.     }
  272.     else if(0 == strcmp("-v", next_argument)){
  273.       fprintf(stderr,"%s: %s\n", command_name, VERSION, INDEXER_DATE);
  274.     }
  275.     else if (0 == strcmp("-stdin", next_argument)) {
  276.       read_files_from_stdin = true;
  277.     }
  278.     else if (0 == strcmp("-nopos", next_argument)) {
  279.       word_positions = false;
  280.     }
  281.     else if (0 == strcmp("-pos", next_argument)) {
  282.       word_positions = true;
  283.     }
  284.     else if (0 == strcmp("-nopairs", next_argument)) {
  285.       word_pairs = false;
  286.     }
  287.     else if (0 == strcmp("-pairs", next_argument)) {
  288.       word_pairs = true;
  289.     }
  290.     else if (0 == strcmp("-nocat", next_argument)) {
  291.       make_catalog = false;
  292.     }
  293.     else if(0 == strcmp("-mem", next_argument)){
  294.       if(NULL == (next_argument = next_arg(&argc, &argv)))
  295.     panic("Expected a number for the amount of memory to use");
  296.       memory_to_use = atol(next_argument);
  297.       if(memory_to_use < 1)
  298.     panic("The -mem argument should not be less than 1");
  299.       if(memory_to_use > 200)
  300.     fprintf(stderr,"Warning: The -mem parameter was %ld Mbytes.  That is a large number of mega bytes in current machines\n", memory_to_use);
  301.     }
  302.     else if(0 == strcmp("-cmmem", next_argument)){
  303.       if(NULL == (next_argument = next_arg(&argc, &argv)))
  304.     panic("Expected a number (1-100) for percentage of memory to use");
  305.       cm_mem_percent = atol(next_argument);
  306.       if(cm_mem_percent < 1)
  307.     panic("The -cmmem argument should not be less than 1 and less than 100");
  308.       if(cm_mem_percent > 100)
  309.     panic("Warning: The -cmmem parameter was %ld%%. It should be between 1-100.", cm_mem_percent);
  310.     }
  311.     else if(0 == strcmp("-grow", next_argument)){
  312.       if(NULL == (next_argument = next_arg(&argc, &argv)))
  313.         panic("Expected a number (1-100) for database growing percentage");
  314.       grow_percent = atol(next_argument);
  315.       if(grow_percent < 1)
  316.         panic("The -grow argument should not be less than 1");
  317.     }
  318.     else if(0 == strcmp("-textsize", next_argument)){
  319.       if(NULL == (next_argument = next_arg(&argc, &argv)))
  320.         panic("Expected a number for text size in megabytes");
  321.       text_size = atol(next_argument);
  322.       if(text_size < 1)
  323.         panic("The -textsize argument should not be less than 1");
  324.     }
  325.     else if (0 == strcmp("-e", next_argument)) {
  326.       char *peek_argument = peek_arg(&argc, &argv);
  327.       log_file_name = "/dev/null"; /* default to /dev/null */
  328.       if ((peek_argument != NULL) &&
  329.       ('-' != peek_argument[0])) {
  330.     log_file_name = next_arg(&argc, &argv);
  331.       }                /* end if (explicit log file) */
  332.     }                /* end if (-e) */
  333.     else if (0 == strcmp("-l", next_argument)) {
  334.       wais_log_level = atol(next_arg(&argc, &argv));
  335.     }                /* end if (-l) */
  336.     else if(0 == strcmp("-cm", next_argument)){
  337.       /* this is an undocumented argument to help use this to
  338.      front end the CM application */
  339.       indexingForBeta = true;
  340.     }
  341.     else if(0 == strcmp("-T", next_argument)){
  342.       /* This is a specification for a "Special" type.  The next argument
  343.      is the type name.  This will not index the body of the file. */
  344.       if(NULL == (next_argument = next_arg(&argc, &argv)))
  345.     panic("Expected a file type");
  346.       typename = next_argument;
  347.       type = next_argument;
  348.       finish_header_function = filename_finish_header_function;
  349.     }
  350.     else if(0 == strcmp("-contents", next_argument)){
  351.       index_contents = true;
  352.     }
  353.     else if(0 == strcmp("-nocontents", next_argument)){
  354.       index_contents = false;
  355.     }
  356.     else if(0 == strcmp("-t", next_argument)){
  357.       /* then we have a specialized file */
  358.       index_contents = true;
  359.       if(NULL == (next_argument = next_arg(&argc, &argv)))
  360.     panic("Expected a file type");
  361.       if(0 == strcmp("groliers", next_argument)){
  362.     typename = next_argument;
  363.     type = "TEXT";
  364.     separator_function = groliers_separator_function;
  365.     header_function = groliers_header_function;
  366.     finish_header_function = groliers_finish_header_function;
  367.       }
  368. #ifdef NeXT
  369.       else if(0 == strcmp("objc", next_argument)){
  370.     typename = next_argument;
  371.     type = "TEXT";
  372.     separator_function = wobjc_separator_function;
  373.     header_function = wobjc_header_function;
  374.     finish_header_function = wobjc_finish_header_function;
  375.       }
  376. #endif /* def NeXT */
  377.       else if(0 == strcmp("mail", next_argument)){
  378.     typename = next_argument;
  379.     type = "TEXT";
  380.     separator_function = mail_separator_function;
  381.     header_function = mail_header_function;
  382.     date_function = mail_date_function;
  383.     finish_header_function = mail_finish_header_function;
  384.       }
  385.       else if(0 == strcmp("mail_or_rmail", next_argument)){
  386.     typename = next_argument;
  387.     type = "TEXT";
  388.     separator_function = mail_or_rmail_separator;
  389.     header_function = mail_header_function;
  390.     date_function = mail_date_function;
  391.     finish_header_function = mail_finish_header_function;
  392.       }
  393.       else if(0 == strcmp("mail_digest", next_argument)){
  394.     typename = next_argument;
  395.     type = "TEXT";
  396.     separator_function = mail_digest_separator_function;
  397.      header_function = mail_header_function;
  398.      date_function = mail_date_function;
  399.      finish_header_function = mail_finish_header_function;
  400.       }
  401.       else if(0 == strcmp("mh_bboard", next_argument)){
  402.      typename = next_argument;
  403.      type = "TEXT";
  404.      separator_function = mh_bboard_separator_function;
  405.     header_function = mail_header_function;
  406.     date_function = mail_date_function;
  407.     finish_header_function = mail_finish_header_function;
  408.       }
  409.       else if(0 == strcmp("rmail", next_argument)){
  410.     typename = next_argument;
  411.     type = "TEXT";
  412.     separator_function = rmail_separator_function;
  413.     header_function = mail_header_function;
  414.     date_function = mail_date_function;
  415.     finish_header_function = mail_finish_header_function;
  416.       }
  417.       else if(0 == strcmp("netnews", next_argument)){
  418.     typename = next_argument;
  419.     type = "TEXT";
  420.     separator_function = NULL;
  421.     header_function = mail_header_function;
  422.     date_function = mail_date_function;
  423.     finish_header_function = mail_finish_header_function;
  424.       }
  425.       else if(0 == strcmp("rn", next_argument)){
  426.     typename = next_argument;
  427.     type = "TEXT";
  428.     separator_function = rn_separator_function;
  429.     header_function = mail_header_function;
  430.     date_function = mail_date_function;
  431.     finish_header_function = mail_finish_header_function;
  432.       }
  433.       else if(0 == strcmp("emacsinfo", next_argument)){
  434.     typename = next_argument;
  435.     type = "TEXT";
  436.     separator_function = emacs_info_separator_function;
  437.     header_function = emacs_info_header_function;
  438.     finish_header_function = emacs_info_finish_header_function;
  439.       }
  440.       else if(0 == strcmp("catalog", next_argument)){
  441.     typename = next_argument;
  442.     type = "TEXT";
  443.     separator_function = catalog_separator_function;
  444.     header_function = catalog_header_function;
  445.     finish_header_function = catalog_finish_header_function;
  446.       }
  447.       else if(0 == strcmp("bio", next_argument)){
  448.     typename = next_argument;
  449.     type = "TEXT";
  450.     separator_function = bio_separator_function;
  451.     header_function = bio_header_function;
  452.     finish_header_function = bio_finish_header_function;
  453.       }
  454.  
  455.        else if(0 == strcmp("genbank", next_argument)){/* dgg */
  456.        typename = next_argument;
  457.        type = "TEXT";
  458.        separator_function = genbank_separator_function;
  459.        header_function = genbank_header_function;
  460.        finish_header_function = genbank_finish_header_function;
  461.        date_function = genbank_date_function;
  462.        }
  463.        else if(0 == strcmp("embl", next_argument)){/* dgg */
  464.        typename = next_argument;
  465.        type = "TEXT";
  466.        separator_function = embl_separator_function;
  467.        header_function = embl_header_function;
  468.        finish_header_function = embl_finish_header_function;
  469.        date_function = embl_date_function;
  470.        }
  471.        else if(0 == strcmp("pir", next_argument)){/* dgg */
  472.        typename = next_argument;
  473.        type = "TEXT";
  474.        separator_function = pir_separator_function;
  475.        header_function = pir_header_function;
  476.        finish_header_function = pir_finish_header_function;
  477.        date_function = pir_date_function;
  478.        }
  479.         else if(0 == strcmp("prositedoc", next_argument)){ /* dgg */
  480.          typename = next_argument;
  481.          type = "TEXT";
  482.          separator_function = prositedoc_separator_function;
  483.          header_function = prositedoc_header_function;
  484.          finish_header_function = prositedoc_finish_header_function;
  485.        }
  486.        else if(0 == strcmp("prositedat", next_argument)){ /* dgg */
  487.          typename = next_argument;
  488.          type = "TEXT";
  489.          separator_function = prositedat_separator_function;
  490.          header_function = prositedat_header_function;
  491.          finish_header_function = prositedat_finish_header_function;
  492.        }
  493.        else if(0 == strcmp("biojournal", next_argument)){ /* dgg */
  494.          typename = next_argument;
  495.          type = "TEXT";
  496.          separator_function = biojournal_separator_function;
  497.          header_function = biojournal_header_function;
  498.          finish_header_function = biojournal_finish_header_function;
  499.        }
  500.  
  501.        else if(0 == strcmp("redbook", next_argument)){ /* dgg */
  502.        typename = next_argument;
  503.        type = "TEXT";
  504.        separator_function = redbook_separator_function;
  505.        header_function = redbook_header_function;
  506.        finish_header_function = redbook_finish_header_function;
  507.        }
  508.  
  509.  
  510.       else if(0 == strcmp("cmapp", next_argument)){
  511.     typename = next_argument;
  512.     type = "TEXT";    
  513.     separator_function = cmapp_separator_function;
  514.     header_function = cmapp_header_function;
  515.     finish_header_function = cmapp_finish_header_function;
  516.       }
  517.       else if(0 == strcmp("ftp", next_argument)){
  518.     type = "TEXT-FTP";
  519.     typename = next_argument;
  520.     separator_function = first_line_separator_function;
  521.     header_function = first_line_header_function;
  522.     finish_header_function = first_line_finish_header_function;
  523.       }
  524.       else if(0 == strcmp("jargon", next_argument)){
  525.     typename = next_argument;
  526.     type = "TEXT";
  527.     separator_function = jargon_separator_function;
  528.     header_function = jargon_header_function;
  529.     finish_header_function = jargon_finish_header_function;
  530.       }
  531.       else if(0 == strcmp("server", next_argument)){
  532.     typename = next_argument;
  533.     type = "WSRC";
  534.     finish_header_function = filename_finish_header_function;
  535.       }
  536.       else if(0 == strcmp("text", next_argument)){
  537.     type = "TEXT";
  538.     typename = next_argument;
  539.     check_for_text_file = true;
  540.       }
  541.       else if(0 == strcmp("filename", next_argument)){
  542.     type = "TEXT";
  543.     typename = next_argument;
  544.     finish_header_function = filename_finish_header_function;
  545.       }
  546.       else if(0 == strcmp("irg", next_argument)){
  547.     typename = next_argument;
  548.     type = "TEXT";
  549.     separator_function = irg_separator_function;
  550.     header_function = irg_header_function;
  551.     finish_header_function = irg_finish_header_function;
  552.       }
  553.       /* dash-separated items , Intro to Algorithms buglist, etc */
  554.       else if(0 == strcmp("dash", next_argument)){
  555.     type = "TEXT";
  556.     typename = next_argument;
  557.     separator_function = dash_separator_function;
  558.     header_function = dash_header_function;
  559.     finish_header_function = dash_finish_header_function;
  560.       }
  561.       /* one_line-separated items */
  562.       else if(0 == strcmp("one_line", next_argument)){
  563.     type = "TEXT";
  564.     typename = next_argument;
  565.     separator_function = one_line_separator_function;
  566.     header_function = one_line_header_function;
  567.     finish_header_function = one_line_finish_header_function;
  568.       }
  569.       /* blank line-separated items (paragraphs) */
  570.       else if(0 == strcmp("para", next_argument)){
  571.     type = "TEXT";
  572.     typename = next_argument;
  573.     separator_function = para_separator_function;
  574.     header_function = para_header_function;
  575.     finish_header_function = para_finish_header_function;
  576.       }
  577.       /* seeker items */
  578.       else if(0 == strcmp("seeker", next_argument)){
  579.     type = "TEXT";
  580.     typename = next_argument;
  581.     separator_function = seeker_separator_function;
  582.     header_function = seeker_header_function;
  583.     finish_header_function = seeker_finish_header_function;
  584.       }
  585.       /* medline format */
  586.       else if(0 == strcmp("medline", next_argument)){
  587.     type = "TEXT";
  588.     typename = next_argument;
  589.     separator_function = medline_separator_function;
  590.     header_function = medline_header_function;
  591.     finish_header_function = medline_finish_header_function;
  592.       }
  593.       /* refer format */
  594.       else if(0 == strcmp("refer", next_argument)){
  595.     type = "TEXT";
  596.     typename = next_argument;
  597.     separator_function = refer_separator_function;
  598.     header_function = refer_header_function;
  599.     finish_header_function = refer_finish_header_function;
  600.       }
  601.       /* first_line format */
  602.       else if(0 == strcmp("first_line", next_argument)){
  603.     type = "TEXT";
  604.     typename = next_argument;
  605.     separator_function = first_line_separator_function;
  606.     header_function = first_line_header_function;
  607.     finish_header_function = first_line_finish_header_function;
  608.       }
  609.       /* rlin items */
  610.       else if(0 == strcmp("rlin", next_argument)){
  611.     type = "TEXT";
  612.     typename = next_argument;
  613.     separator_function = rlin_separator_function;
  614.     header_function = rlin_header_function;
  615.     finish_header_function = rlin_finish_header_function;
  616.       }
  617.       else if(0 == strcmp("dvi", next_argument)){
  618.     typename = next_argument;
  619.     type = "DVI";
  620.     finish_header_function = filename_finish_header_function;
  621.       }
  622.       else if(0 == strcmp("ps", next_argument)){
  623.     typename = next_argument;
  624.     type = "PS";
  625.     finish_header_function = filename_finish_header_function;
  626.       }
  627.       else if(0 == strcmp("pict", next_argument)){
  628.     typename = next_argument;
  629.     type = "PICT";    
  630.     finish_header_function = filename_finish_header_function;
  631.     index_contents = false;
  632.       }
  633.       else if(0 == strcmp("gif", next_argument)){
  634.     typename = next_argument;
  635.     type = "GIF";    
  636.     finish_header_function = filename_finish_header_function;
  637.     index_contents = false;
  638.       }
  639.       else if(0 == strcmp("tiff", next_argument)){
  640.     typename = next_argument;
  641.     type = "TIFF";    
  642.     finish_header_function = filename_finish_header_function;
  643.     index_contents = false;
  644.       }
  645.       /* BibTeX items */
  646.       else if(0 == strcmp("bibtex", next_argument)){
  647.     type = "TEXT";
  648.     typename = next_argument;
  649.     separator_function = bibtex_separator_function;
  650.     header_function = bibtex_header_function;
  651.     finish_header_function = bibtex_finish_header_function;
  652.       }
  653.       /* ?:? seperated hypertext items */
  654.       else if(0 == strcmp("nhyp", next_argument)){
  655.     type = "TEXT";
  656.     typename = next_argument;
  657.     separator_function = nhyp_separator_function;
  658.     header_function = nhyp_header_function;
  659.     finish_header_function = nhyp_finish_header_function;
  660.       }
  661.       else if(0 == strcmp("ziff", next_argument)){
  662.     type = "TEXT";
  663.     typename = next_argument;
  664.     separator_function = ziff_separator_function;
  665.     header_function = ziff_header_function;
  666.     finish_header_function = ziff_finish_header_function;
  667.       }
  668.       else{
  669.     panic("Don't recognize the '%s' type", next_argument);
  670.       }
  671.     }
  672.     else{
  673.       panic("Don't recognize the '%s' option", next_argument);
  674.     }
  675.     next_argument = next_arg(&argc, &argv);
  676.     if (! (read_files_from_stdin || next_argument)) {
  677.       fprintf(stderr,"No files specified\n");
  678.       exit(0);
  679.     }
  680.   }
  681.   start_of_filenames = argc_copy - argc - 1;
  682.  
  683.   /* check index */
  684.   if(0 == strlen(pathname_name(index_filename))){
  685.     waislog(WLOG_HIGH, WLOG_ERROR,
  686.         "The pathname specified for the destination of the index files ('%s') should have a leaf filename without an extention rather than just a directory.",
  687.         index_filename);
  688.     exit(0);     
  689.   }
  690.     
  691.   waislog(WLOG_MEDIUM, WLOG_INDEX, "Starting to build database %s",
  692.       index_filename);
  693.  
  694.   if(0 != init_search_engine(index_filename, false, false, cm_mem_percent,
  695.           text_size, grow_percent))
  696.     panic("unable to initialize search engine");
  697.  
  698.   if(true == adding_to_existing_index){
  699.     db = openDatabase(index_filename, false, false);
  700.     if (db == NULL){ /* does not exist, create one */
  701.       db = openDatabase(index_filename, true, false);
  702.       if (db == NULL)
  703.     panic("unable to open the database");
  704.     }
  705.   }
  706.   else{
  707.     db = openDatabase(index_filename, true, false);
  708.     if (db == NULL)
  709.       panic("unable to open the database");
  710.   }
  711.   { /* set up the memory hashtable */
  712.  
  713.     if(memory_to_use < 0){ /* default */
  714.       /* do nothing */
  715.     }
  716.     else if(memory_to_use <= 2){
  717.       hashtable_size = 1L<<16;
  718.       flush_after_n_words = 50000;
  719.     }
  720.     else if(memory_to_use <= 5){
  721.       hashtable_size = 1L<<16;
  722.       flush_after_n_words = 150000;
  723.     }
  724.     else if(memory_to_use <= 10){
  725.       /* shown to take about 6MB on a sun4, when it is dict limited */
  726.       hashtable_size = 1L<<16;
  727.       flush_after_n_words = 300000;
  728.     }
  729.     else if(memory_to_use <= 20){
  730.       hashtable_size = 1L<<17;
  731.       flush_after_n_words = 600000;
  732.     }
  733.     else{ /* over 20 Mbytes */
  734.       hashtable_size = 1L<<18;
  735.       flush_after_n_words = 1000000;
  736.     }
  737.     init_add_word(db, hashtable_size, flush_after_n_words);
  738.   }
  739.  
  740.   if (read_files_from_stdin) {
  741.     if (0 != (next_argument = fgets(data_filename, MAXPATHLEN, stdin))) {
  742.       int len = strlen(next_argument);
  743.       if (next_argument[len-1] == '\n') {
  744.     next_argument[len-1] = '\0';
  745.       }
  746.     }
  747.   }
  748.  
  749.   while(NULL != next_argument){ /* the first filename is in next_argument already */
  750.     if(directoryp(next_argument)){
  751.        if(traverse_directory){
  752.      index_directory(next_argument,
  753.              separator_function,
  754.              header_function,
  755.              date_function,
  756.              finish_header_function,
  757.              type, db,
  758.              check_for_text_file,
  759.              adding_to_existing_index, 
  760.              word_positions, word_pairs);
  761.        }
  762.      }
  763.     else{            /* not a directory */
  764.       waislog(WLOG_MEDIUM, WLOG_INDEX, 
  765.           "Indexing file: %s", next_argument);
  766.       index_text_file(next_argument,
  767.               separator_function,
  768.               header_function,
  769.               date_function,
  770.               finish_header_function,
  771.               type, db, 
  772.               check_for_text_file, adding_to_existing_index,
  773.               word_positions, word_pairs, minwordlen);
  774.     }
  775.     if (read_files_from_stdin) {
  776.       if (0 != (next_argument = fgets(data_filename, MAXPATHLEN, stdin))) {
  777.     int len = strlen(next_argument);
  778.     if (next_argument[len-1] == '\n') {
  779.       next_argument[len-1] = '\0';
  780.     }
  781.       }
  782.     }
  783.     else {
  784.       next_argument = next_arg(&argc, &argv);
  785.     }
  786.   }
  787.   finished_add_word(db);
  788.   {
  789.     char filename[MAX_FILENAME_LEN + 1];
  790.     if(!probe_file(source_filename(filename, db))){
  791.       char database_name[MAX_FILENAME_LEN];
  792.       write_src_structure(source_filename(filename, db),
  793.               export_database?pathname_name(index_filename):
  794.                       truename(index_filename, database_name),
  795.               typename,
  796.               &argv_copy[start_of_filenames],
  797.               argc_copy - start_of_filenames,
  798.               export_database,
  799.               210L);
  800.     }
  801.     /* write out a description of the server if appropriate */
  802.     if(register_database){
  803.       register_src_structure(source_filename(filename, db));
  804.     }
  805.   }
  806.   if(make_catalog) build_catalog(db);
  807.   closeDatabase(db);
  808.   waislog(WLOG_MEDIUM, WLOG_INDEX, "Finished build");
  809.   exit(0);
  810. }
  811.