home *** CD-ROM | disk | FTP | other *** search
/ Internet Publisher's Toolbox 2.0 / Internet Publisher's Toolbox.iso / internet / ntserver / wtsource / ircfiles.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-17  |  98.7 KB  |  3,772 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. /* this file defines a set of helper functions
  12.  * for indexing common types of files.
  13.  * -brewster 7/90
  14.  */
  15.  
  16. /* I encourage adding customizations.
  17.  * (too bad they all have to be hard coded, but
  18.  *  C did not have convenient dynamic linking facilities)
  19.  *
  20.  * Add three functions to this file:
  21.  * boolean foo_separator_function(char *line){}
  22.  * void foo_header_function(char *line){}
  23.  * long foo_date_function(char *line){}
  24.  * void foo_finish_header_function(char *header){}
  25.  *
  26.  * then add the prototypes to ircfiles.h
  27.  * then add the functions to the big case statement in waisindex.c
  28.  *
  29.  *
  30.  * to do:
  31.  *   filter for digests
  32.  *
  33.  *   Tracy pointed out 2 things which we should consider when redesigning the
  34.  *   parser:
  35.  *
  36.  *   - there should be a way for the parser to decide to skip a section of 
  37.  *   input text (ie. not index it).  she does this by having global variable 
  38.  *   which is set by her custom seperator function when it wants to tell 
  39.  *   map_over_words() to not add the words on the current line
  40.  *
  41.  *   - there should be a way to switch lexers depending what section of a
  42.  *   document you are in (since word separators will change).  This is 
  43.  *   needed by the european patent office too.
  44.  *
  45.  */
  46.  
  47.  
  48. /* Change log:
  49.  * 8/90 brewster added the library customizations
  50.  * 6/91 and before - added a bunch of other filters - JG
  51.  * $Log:    ircfiles.c,v $
  52.  * Revision 1.3  93/07/21  18:45:34  warnock
  53.  * Added new functions to handle listserv logs and STELAR-specific types
  54.  * 
  55.  * Revision 1.2  93/07/19  16:31:50  warnock
  56.  * Added document type URL from Nathan.Torkington@vuw.ac.nz
  57.  * 
  58.  * Revision 1.1  1993/02/16  15:05:35  freewais
  59.  * Initial revision
  60.  *
  61.  * Revision 1.34  92/05/06  17:28:23  jonathan
  62.  * Added filename_finish_header_function.  Puts leaf name into header.
  63.  * 
  64.  * Revision 1.33  92/05/05  11:10:50  jonathan
  65.  * Added fix to bibtex indexer to ignore subsequent "booktitles" after title
  66.  * has been set.  Thanks to Lutz Prechelt (prechelt@ira.uka.de).
  67.  * 
  68.  * Revision 1.32  92/04/30  12:31:08  jonathan
  69.  * Fixed syntax errors in OBJ C functions.
  70.  * 
  71.  * Revision 1.31  92/04/29  14:08:57  shen
  72.  * chnage catalaog header string to "Title:"
  73.  * 
  74.  * Revision 1.30  92/04/26  14:45:08  brewster
  75.  * debug ziff
  76.  * 
  77.  * Revision 1.29  92/04/26  14:39:24  brewster
  78.  * tweeked ziff filter
  79.  * 
  80.  * Revision 1.28  92/04/25  21:14:05  brewster
  81.  * added ziff
  82.  * 
  83.  * Revision 1.27  92/04/20  15:21:06  morris
  84.  * added todo's for tracy
  85.  * 
  86.  * Revision 1.26  92/03/22  18:38:29  brewster
  87.  * added objective C filter
  88.  * 
  89.  * Revision 1.25  92/03/13  08:21:37  jonathan
  90.  * Added length limits to scanf's in my_getdate, thanks to
  91.  * sendall@dxpt01.cern.ch (Mike Sendall).
  92.  * 
  93.  * Revision 1.24  92/02/29  20:13:54  jonathan
  94.  * separated =- for some compilers that get confused (ULTRIX).
  95.  * 
  96.  * Revision 1.23  92/02/20  09:50:14  jonathan
  97.  * Added bibtex and nhyp filters from S.P.vandeBurgt@research.ptt.nl.
  98.  * 
  99.  * Revision 1.22  92/02/12  13:11:25  jonathan
  100.  * Changed library catalog functions for new format (from fad).
  101.  * 
  102.  * 
  103.  *
  104.  */
  105.  
  106. #include <string.h>
  107. #include <ctype.h>
  108. #include "cutil.h"
  109. #include "ircfiles.h"
  110.  
  111. extern char *current_filename;
  112. extern int current_filecount;
  113.  
  114. #define MAX_HEADER_LEN 100
  115.  
  116. #define MAX_AUTHOR_LEN 25
  117. #define MAX_DATE_LEN 4
  118.  
  119. static char *months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
  120.             "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", NULL};
  121.  
  122.  
  123. static char* trim_trailing_newline _AP((char* string));
  124. static char* trim_leading_blanks _AP((char* string));
  125.  
  126. static char*
  127. trim_trailing_newline(string)
  128. char* string;
  129. {
  130.   if(string)
  131.     if(strlen(string) > 0)
  132.       if(string[strlen(string) -1] == '\n')
  133.     string[strlen(string) -1] = '\0';
  134.   return(string);
  135. }
  136.  
  137. static char*
  138. trim_leading_blanks(string)
  139. char* string;
  140. {
  141.   if(string)
  142.     if(strlen(string) > 0)
  143.       while(string[0] <= ' ')
  144.     string++;
  145.   return(string);
  146. }
  147.  
  148.  
  149. #ifdef BIO
  150.  
  151. char bio_header1[MAX_HEADER_LEN + 1];
  152. char bio_header2[MAX_HEADER_LEN + 1];
  153.  
  154.  
  155. /* ==========================================
  156.  *
  157.  * ===  Genbank Flat-file Customizations  ===
  158.  *
  159.  * d.g.gilbert, 15feb92, 
  160.  * gilbertd@bio.indiana.edu
  161.  *
  162.  * ==========================================
  163.  */
  164.  
  165. #define genbank_data_tab    12
  166. #define genbank_date_tab    63
  167.  
  168. /* Genbank Flat-file format:
  169. LOCUS       ACAAC01      1571 bp ds-DNA             INV       05-NOV-1991 << start entry
  170. 12345678901234567890123456789012345678901234567890123456789012345678901234567890
  171. .........1.........2.........3.........4.........5.........6.........7.........8
  172. all data starts at tab=13
  173. on locus line, data starts at tab=63
  174. ...
  175. LOCUS       blah    << Start entry, index LOCUS_NAME, includes DATE
  176. DEFINITION  blah    << Index def line == HEADER line
  177. ACCESSION   blah    << Index acc line
  178. KEYWORDS    blah    << index keywords
  179. SOURCE      blah    << index source
  180.   ORGANISM  blah    << index organism
  181.             blah    << index taxonomy
  182.             blah    << "
  183.   AUTHORS   blah    << Index
  184.   TITLE     blah    << Index
  185.             blah    << Index
  186. ANYOTHERS   jazz    << skipit
  187. //                  << end of entry == entry separator
  188. LOCUS       ACAAC01      1571 bp ds-DNA             INV       05-NOV-1991 << start entry
  189. DEFINITION  Acanthamoeba castelani gene encoding actin I.
  190. ACCESSION   V00002 J01016
  191. KEYWORDS    actin.
  192. SOURCE      Acanthamoeba castellanii DNA.
  193.   ORGANISM  Acanthamoeba castellanii
  194.             Eukaryota; Animalia; Protozoa; Sarcomastigophora; Sarcodina;
  195.             Rhizopoda; Lobosa; Gymnamoeba; Amoebida; Acanthopodina;
  196.             Acanthamoebidae.
  197. REFERENCE   1  (bases 1 to 1571)
  198.   AUTHORS   Nellen,W. and Gallwitz,D.
  199.   TITLE     Actin genes and actin messenger RNA in Acanthamoeba castellani.
  200.             Nucleotide sequence of the split actin gene I
  201.   JOURNAL   J. Mol. Biol. 159, 1-18 (1982)
  202. COMMENT     SWISS-PROT; P02578; ACT1$ACACA.
  203.                From EMBL 26   entry ACAC01;  dated 22-JAN-1991.
  204.  
  205. FEATURES             Location/Qualifiers
  206.     >>> ignore all features
  207.     
  208. BASE COUNT      313 a    535 c    389 g    334 t
  209. ORIGIN
  210.         1 ggagaagcgt gcacgcaata accaagcgac agagcaacct ctctggcacc acgccccaca
  211.     >>> ignore all seq data in indexing
  212. //  <<< end of entry
  213. LOCUS       ACAMHCA      5894 bp ds-DNA             INV       30-SEP-1988
  214. ...
  215. *****/
  216.  
  217.  
  218. static  boolean  keepindexing = false;
  219.  
  220. void genbank_filter_for_index(line)
  221. char* line;
  222. {
  223.   /* check whether to index anything in line, 
  224.    * call this from genbank_header_function which is called for
  225.    * each line.  
  226.    * Blank out parts of line not for indexing...
  227.    */
  228.   char *c;
  229.   long  i;
  230.   
  231.   if (strlen(line) <= genbank_data_tab) {
  232.      for (c=line ; *c>=' '; c++) *c=' ';
  233.      keepindexing= false;  
  234.      }
  235.      
  236.   else if (substrcmp(line, "            ")) {  
  237.         /* most lines are like this, including nucleotides */
  238.      if (!keepindexing) for (c=line ; *c>=' '; c++) *c=' ';
  239.      }
  240.      
  241.   /*******
  242.    else if (substrcmp(line, "LOCUS       ")){
  243.         // I think this is bad, locus not in index ... 
  244.      for (c=line, i=0; *c>=' ' && i<genbank_data_tab; i++, c++) *c=' ';
  245.      for ( ; *c>' '; c++) ;  // leave LOCUS ID intact  
  246.      for ( ; *c>=' '; c++) *c=' '; 
  247.      keepindexing= false;
  248.      }
  249.     ******/ 
  250.     
  251.   else if ( 
  252.        substrcmp(line, "DEFINITION  ") 
  253.     || substrcmp(line, "LOCUS       ")
  254.     || substrcmp(line, "ACCESSION   ")
  255.     || substrcmp(line, "KEYWORDS    ")
  256.     || substrcmp(line, "SOURCE      ")
  257.     || substrcmp(line, "  ORGANISM  ")
  258.     || substrcmp(line, "  AUTHORS   ")
  259.     || substrcmp(line, "  TITLE     ")
  260.     ){
  261.      for (c=line, i=0; *c>=' ' && i<genbank_data_tab; i++, c++) *c=' ';
  262.      keepindexing= true;
  263.      }
  264.  
  265.   else {
  266.      for (c=line ; *c>=' '; c++) *c=' ';
  267.      keepindexing= false;
  268.      }
  269. }
  270.  
  271.  
  272.  
  273. boolean genbank_separator_function(line)
  274. char *line;
  275. {
  276. /* !! with // as separator, we get // at top of entry which will
  277.    screw up seqanal software... */
  278. /*  if ((strlen(line) > 1) && (0==strncmp(line, "//", 2))){
  279.      return(true);
  280.      }  
  281. */
  282.   if ((strlen(line) > genbank_data_tab) && substrcmp(line, "LOCUS       ")){
  283.      return(true);
  284.      }
  285.   else{
  286.     return(false);
  287.     }
  288. }
  289.  
  290. long genbank_getdate(line)
  291. char *line;
  292. {
  293.     /* genbank date == 30-SEP-1988*/
  294.   char date[255], *temp;
  295.   int day, month, year;
  296.   char cmonth[25];
  297.  
  298.   strcpy(date, line);
  299.  
  300.   temp = date;
  301.  
  302.   while(!isdigit(*temp)) temp++;
  303.  
  304.   /* sscanf(temp, "%d %s %d", &day, cmonth, &year); */
  305.   sscanf(temp, "%d-%s-%d", &day, cmonth, &year);
  306.  
  307.   for(month = 0; months[month] != NULL; month++)
  308.     /* if(!strcmp(cmonth, months[month])) break; */
  309.     if(!strcasecmp(cmonth, months[month])) break; /* was stricmp !! */
  310.  
  311.   if (year > 99) year = year % 100;
  312.  
  313.   if(day > 0 && 
  314.      month < 12 &&
  315.      year > 0) {
  316.     return (10000 * year + 100 * (month+1) + day);
  317.   }
  318.   return 0;
  319. }
  320.  
  321. long genbank_date_function(line)
  322. char *line;
  323. {
  324.   if ((strlen(line) > genbank_data_tab) && substrcmp(line, "LOCUS       ")){
  325.     return(genbank_getdate(line+genbank_date_tab));
  326.   }
  327.   else 
  328.     return -1;
  329. }
  330.  
  331.   
  332.  
  333. char *genbank_def = bio_header1;
  334. char *genbank_accession= bio_header2;
  335.  
  336. void genbank_header_function(line)
  337. char *line;
  338. {
  339.   if ((strlen(line) > genbank_data_tab) && substrcmp(line, "DEFINITION  ") &&
  340.      (strlen(genbank_def) == 0)){
  341.     strncpy(genbank_def, line + genbank_data_tab, MAX_HEADER_LEN);
  342.     trim_trailing_newline(genbank_def);
  343.     }
  344.     
  345.   else if ((strlen(line) > genbank_data_tab) &&
  346.      substrcmp(line, "ACCESSION   ") &&
  347.      (strlen(genbank_accession) == 0)){
  348.     /* cut extra acc. numbers from this -- we want only 1st */
  349.     char *cp;
  350.     for (cp=line+genbank_data_tab; *cp==' '; cp++) ;
  351.     strncpy(genbank_accession, cp, MAX_HEADER_LEN);
  352.     cp= strchr(genbank_accession, ' ');
  353.     if (cp!=NULL) *cp=0; /* drop after 1st */
  354.     trim_trailing_newline(genbank_accession);
  355.     }
  356.   
  357.   genbank_filter_for_index( line);
  358.   
  359. }
  360.  
  361. void genbank_finish_header_function(header)
  362. char *header;
  363. {
  364.   if(strlen(genbank_def) != 0 && strlen(genbank_accession) != 0){
  365.     strncpy(header, genbank_accession, MAX_HEADER_LEN);
  366.     s_strncat(header, " ", MAX_HEADER_LEN, MAX_HEADER_LEN);
  367.     s_strncat(header, genbank_def, MAX_HEADER_LEN, MAX_HEADER_LEN);
  368.   }
  369.   else if(strlen(genbank_def) != 0){
  370.     strncpy(header, genbank_def, MAX_HEADER_LEN);
  371.   }
  372.   else if(strlen(genbank_accession) != 0){
  373.     strncpy(header, genbank_accession, MAX_HEADER_LEN);
  374.   }
  375.   else{
  376.     strcpy(header, "Unknown Entry");
  377.   }
  378.   genbank_def[0] = '\0';
  379.   genbank_accession[0] = '\0';
  380. }
  381.  
  382.  
  383. /* ==========================================
  384.  *
  385.  * ===  PIR Protein Customizations  ===
  386.  *
  387.  * d.g.gilbert, 11Mar92, 
  388.  * gilbertd@bio.indiana.edu
  389.  *
  390.  * ==========================================
  391.  */
  392.  
  393. #define pir_data_tab    16
  394.  
  395. /* pir Flat-file format:    (lines are prepended with '|' to keep cpp happy)
  396. |ENTRY           CCHU       #Type Protein
  397. 12345678901234567890123456789012345678901234567890123456789012345678901234567890
  398. .........1.........2.........3.........4.........5.........6.........7.........8
  399. all data starts at tab=17 or further
  400.  
  401. |ENTRY       blah       << Start entry, index it
  402. |TITLE      blah        << Index def line == HEADER line
  403. |ACCESSION   blah       << Index acc line
  404. |KEYWORDS    blah       << index keywords
  405. |SOURCE      blah       << index source
  406. |REFERENCE   blah       << Index
  407. |SUPERFAMILY blah       << Index
  408. |            blah       << Index
  409. |ANYOTHERS      jazz    << skipit
  410. |any word starting w/ "#", skipit
  411. |///                            << end of entry == entry separator
  412. |ENTRY           CCHU       #Type Protein
  413. |TITLE           Cytochrome c - Human
  414. |DATE            #Sequence 30-Sep-1991 #Text 30-Sep-1991
  415. |PLACEMENT          1.0    1.0    1.0    1.0    1.0
  416. |SOURCE          Homo sapiens #Common-name man
  417. |ACCESSION       A31764\ A05676\ A00001
  418. |REFERENCE
  419. |   #Authors     Evans M.J., Scarpulla R.C.
  420. |   #Journal     Proc. Natl. Acad. Sci. U.S.A. (1988) 85:9625-9629
  421. |   #Title       The human somatic cytochrome c gene: two classes of
  422. |                  processed pseudogenes demarcate a period of rapid
  423. |                  molecular evolution.
  424. |   #Reference-number A31764
  425. |   #Accession   A31764
  426. |   #Molecule-type DNA
  427. |   #Residues    1-105 <EVA>
  428. |   #Cross-reference GB:M22877
  429. |REFERENCE
  430. |   #Authors     Matsubara H., Smith E.L.
  431. |   #Journal     J. Biol. Chem. (1963) 238:2732-2753
  432. |   #Reference-number A05676
  433. |   #Accession   A05676
  434. |   #Molecule-type protein
  435. |   #Residues    2-28;29-46;47-100;101-105 <MATS>
  436. |REFERENCE
  437. |   #Authors     Matsubara H., Smith E.L.
  438. |   #Journal     J. Biol. Chem. (1962) 237:3575-3576
  439. |   #Reference-number A00001
  440. |   #Comment     66-Leu is found in 10% of the molecules in pooled
  441. |                  protein.
  442. |GENETIC
  443. |   #Introns        57/1
  444. |SUPERFAMILY     #Name cytochrome c
  445. |KEYWORDS        acetylation\ electron transport\ heme\
  446. |                  mitochondrion\ oxidative phosphorylation\
  447. |                  polymorphism\ respiratory chain
  448. |FEATURE
  449. |   2-105                   #Protein cytochrome c (experimental)
  450. |                             <MAT>\
  451. |   2                       #Modified-site acetylated amino end
  452. |                             (experimental)\
  453. |   15,18                   #Binding-site heme (covalent)\
  454. |   19,81                   #Binding-site heme iron (axial ligands)
  455. |SUMMARY       #Molecular-weight 11749  #Length 105  #Checksum  3247
  456. |SEQUENCE
  457. |                5        10        15        20        25        30
  458. |      1 M G D V E K G K K I F I M K C S Q C H T V E K G G K H K T G
  459. |     31 P N L H G L F G R K T G Q A P G Y S Y T A A N K N K G I I W
  460. |     61 G E D T L M E Y L E N P K K Y I P G T K M I F V G I K K K E
  461. |     91 E R A D L I A Y L K K A T N E
  462. |///
  463. |
  464.  
  465. *****/
  466.  
  467.  
  468. void pir_filter_for_index(line)
  469. char* line;
  470. {
  471.   /* check whether to index anything in line, 
  472.    * call this from pir_header_function which is called for
  473.    * each line.  
  474.    * Blank out parts of line not for indexing...
  475.    */
  476.   char *c;
  477.   long  i;
  478.   
  479.   if (strlen(line) <= pir_data_tab) {
  480.      for (c=line ; *c>=' '; c++) *c=' ';
  481.      keepindexing= false;  
  482.      }
  483.  
  484. /* drop some ref junk that is not of much indexing interest... */
  485.   else if (substrcmp(line, "   #Reference-number ") 
  486.     || substrcmp(line, "   #Residues ")
  487.     || substrcmp(line, "   #Accession ")
  488.     || substrcmp(line, "   #Residues ")
  489.         || substrcmp(line, "   #Cross-reference ")
  490.     || substrcmp(line, "   #Molecule-type ")
  491.     || substrcmp(line, "   #Journal ") ) {   
  492.      for (c=line ; *c>=' '; c++) *c=' ';
  493.      /* keepindexing is based on last main keyword (ENTRY, REF...) */
  494.      }
  495.  
  496.   else if (substrcmp(line, "   ")) {  
  497.     /* some good & bad continuation lines start like this */
  498.      if (!keepindexing) for (c=line ; *c>=' '; c++) *c=' ';
  499.      }
  500.         
  501.   else if ( 
  502.        substrcmp(line, "ENTRY           ") 
  503.     || substrcmp(line, "TITLE           ")
  504.     || substrcmp(line, "SOURCE          ")
  505.     || substrcmp(line, "ACCESSION       ")
  506.     || substrcmp(line, "REFERENCE")  
  507. /* REFERENCE line seems to have no data on line, but it follows (keepindexing) */
  508.     || substrcmp(line, "SUPERFAMILY     ")
  509.     || substrcmp(line, "KEYWORDS        ")
  510.     ){
  511.      for (c=line, i=0; *c>=' ' && i<pir_data_tab; i++, c++) *c=' ';
  512.      keepindexing= true;
  513.      }
  514.  
  515.   else {
  516.      for (c=line ; *c>=' '; c++) *c=' ';
  517.      keepindexing= false;
  518.      }
  519.   
  520.   /* pir -- blank out #words */
  521.   for (c=line; *c != 0; ) {
  522.     if (*c=='#') do { *c++=' '; } while (*c > ' ');
  523.     else c++;    
  524.     }
  525.  
  526. }
  527.  
  528.  
  529.  
  530. boolean pir_separator_function(line)
  531. char *line;
  532. {
  533. /* !! with /// as separator, we get /// at top of entry which will
  534.    screw up seqanal software... */
  535. /*  if ((strlen(line) > 1) && (0==strncmp(line, "///", 2))){
  536.      return(true);
  537.      }  
  538. */
  539.   if ((strlen(line) > pir_data_tab) && substrcmp(line, "ENTRY           ")){
  540.      return(true);
  541.      }
  542.   else{
  543.     return(false);
  544.     }
  545. }
  546.  
  547.  
  548. long pir_date_function(line)
  549. char *line;
  550. { /* later maybe */
  551.     return -1;
  552. }
  553.  
  554.   
  555.  
  556. char *pir_def = bio_header1;
  557. char *pir_accession= bio_header2;
  558.  
  559. void pir_header_function(line)
  560. char *line;
  561. {
  562.   if ((strlen(line) > pir_data_tab) &&
  563.      substrcmp(line, "TITLE           ") &&
  564.      (strlen(pir_def) == 0)){
  565.     strncpy(pir_def, line + pir_data_tab, MAX_HEADER_LEN);
  566.     trim_trailing_newline(pir_def);
  567.     }
  568.     
  569.   else if ((strlen(line) > pir_data_tab) &&
  570.      substrcmp(line, "ACCESSION      ") &&
  571.      (strlen(pir_accession) == 0)){
  572.     /* cut extra acc. numbers from this -- we want only 1st */
  573.     char *cp;
  574.     for (cp=line+pir_data_tab; *cp==' '; cp++) ;
  575.             strncpy(pir_accession, cp, MAX_HEADER_LEN);
  576.     cp= strchr(pir_accession, ' ');
  577.     if (cp!=NULL) *cp=0; /* drop after 1st */
  578.         trim_trailing_newline(pir_accession);
  579.         }
  580.   
  581.   pir_filter_for_index( line);
  582.   
  583. }
  584.  
  585. void pir_finish_header_function(header)
  586. char *header;
  587. {
  588.   if(strlen(pir_def) != 0 && strlen(pir_accession) != 0){
  589.     strncpy(header, pir_accession, MAX_HEADER_LEN);
  590.     s_strncat(header, " ", MAX_HEADER_LEN, MAX_HEADER_LEN);
  591.     s_strncat(header, pir_def, MAX_HEADER_LEN, MAX_HEADER_LEN);
  592.   }
  593.   else if(strlen(pir_def) != 0){
  594.     strncpy(header, pir_def, MAX_HEADER_LEN);
  595.   }
  596.   else if(strlen(pir_accession) != 0){
  597.     strncpy(header, pir_accession, MAX_HEADER_LEN);
  598.   }
  599.   else{
  600.     strcpy(header, "Unknown Entry");
  601.   }
  602.   pir_def[0] = '\0';
  603.   pir_accession[0] = '\0';
  604. }
  605.  
  606.  
  607.  
  608. /* ==========================================
  609.  * ===    EMBL Flat-file Customizations  ===
  610.  * d.g.gilbert, 23Feb92, 
  611.  * ==========================================
  612.  */
  613.  
  614. #define embl_data_tab   5
  615.  
  616. /* EMBL Flat-file format:
  617.  
  618. ID   BAAMYLA    standard; DNA; PRO; 7872 BP.
  619. 1234567890
  620. XX
  621. AC   X62835;
  622. XX
  623. DT   12-NOV-1991 (Rel. 29, Last updated, Version 1)
  624. DT   12-NOV-1991 (Rel. 29, Created)
  625. XX
  626. DE   B.acidocaldarius amy gene for amylase
  627. XX
  628. KW   amy gene; amylase.
  629. XX
  630. OS   Bacillus acidocaldarius
  631. OC   Prokaryota; Bacteria; Firmicutes; Endospore-forming rods and cocci;
  632. OC   Bacillaceae; Bacillus.
  633. XX
  634. RN   [1]
  635. RP   1-7872
  636. RA   Hemila H.O.;
  637. RT   ;
  638. RL   Submitted (22-OCT-1991) on tape to the EMBL Data Library by:
  639. RL   H.O. Hemila, Institute of Biotechnology, Valimotie 7, 00380
  640. RL   Helsinki, FINLAND
  641. XX
  642. RN   [2]
  643. RP   1-7872
  644. RA   Koivula T., Hemilae H.;
  645. RT   ;
  646. RL   Unpublished.
  647. XX
  648. CC   *source: strain=ATCC 27009;
  649. CC   *source: clone_library=lambda gt-10;
  650. XX
  651. FH   Key             Location/Qualifiers
  652. FH
  653. FT   -35_signal      3224..3229
  654. FT   -10_signal      3246..3251
  655. FT   RBS             3288..3294
  656. FT                   /note="amy gene"
  657. FT   CDS             3297..7202
  658. FT                   /gene="amy" /product="amylase"
  659. FT   CDS             7332..>7872
  660. FT                   /product="malE protein-homologue"
  661. XX
  662. SQ   Sequence 7872 BP; 1615 A; 2240 C; 2473 G; 1544 T; 0 other;
  663.      cgttcctcgt gccgtccgaa gcgttcccga cgaatctgcg cggcaccgcc gcgggatctc
  664. //
  665. *****/
  666.  
  667.  
  668.  
  669. void embl_filter_for_index(line)
  670. char* line;
  671. {
  672.   /* check whether to index anything in line, 
  673.    * call this from embl_header_function which is called for
  674.    * each line.  
  675.    * Blank out parts of line not for indexing...
  676.    */
  677.   char *c;
  678.   long  i;
  679.   
  680.   if (strlen(line) <= embl_data_tab) {
  681.      for (c=line; *c>=' '; c++) *c=' ';
  682.      }
  683.      
  684.   else if ( 
  685.        substrcmp(line, "DE   ") 
  686.     || substrcmp(line, "ID   ")
  687.     || substrcmp(line, "AC   ")
  688.     || substrcmp(line, "KW   ")
  689.     || substrcmp(line, "OS   ")
  690.     || substrcmp(line, "OC   ")
  691.     || substrcmp(line, "RA   ")
  692.     || substrcmp(line, "RT   ")
  693.     ){
  694.      for (c=line, i=0; *c>=' ' && i<embl_data_tab; i++, c++) *c=' ';
  695.      }
  696.  
  697.   else {
  698.      for (c=line ; *c>=' '; c++) *c=' ';
  699.      }
  700. }
  701.  
  702.  
  703.  
  704. boolean embl_separator_function(line)
  705. char *line;
  706. {
  707. /* !! with // as separator, we get // at top of entry which will
  708.    screw up seqanal software... */
  709. /*  if ((strlen(line) > 1) && (0==strncmp(line, "//", 2))){
  710.      return(true);
  711.      }  
  712. */
  713.   if ((strlen(line) > embl_data_tab) && substrcmp(line, "ID   ")){
  714.      return(true);
  715.      }
  716.   else{
  717.     return(false);
  718.     }
  719. }
  720.  
  721. /* embl date == 30-SEP-1988 == genbank_date*/
  722.  
  723. long embl_date_function(line)
  724. char *line;
  725. {
  726.   if ((strlen(line) > embl_data_tab) && substrcmp(line, "DT   ")){
  727.     return(genbank_getdate(line+embl_data_tab));
  728.   }
  729.   else 
  730.     return -1;
  731. }
  732.  
  733.   
  734.  
  735. char *embl_def = bio_header1;
  736. char *embl_accession= bio_header2;
  737.  
  738. void embl_header_function(line)
  739. char *line;
  740. {
  741.   if ((strlen(line) > embl_data_tab) &&
  742.      substrcmp(line, "DE   ") &&
  743.      (strlen(embl_def) == 0)){
  744.     strncpy(embl_def, line + embl_data_tab, MAX_HEADER_LEN);
  745.     trim_trailing_newline(embl_def);
  746.     }
  747.     
  748.   else if ((strlen(line) > embl_data_tab) &&
  749.      substrcmp(line, "AC   ") &&
  750.      (strlen(embl_accession) == 0)){
  751.     /* cut extra acc. numbers from this -- we want only 1st */
  752.     char *cp;
  753.     for (cp=line+embl_data_tab; *cp==' '; cp++) ;
  754.     strncpy(embl_accession, cp, MAX_HEADER_LEN);
  755.     cp= strchr(embl_accession, ' ');
  756.     if (cp!=NULL) *cp=0; /* drop after 1st */
  757.         trim_trailing_newline(embl_accession);
  758.     }
  759.   
  760.   embl_filter_for_index( line);
  761.   
  762. }
  763.  
  764. void embl_finish_header_function(header)
  765. char *header;
  766. {
  767.   if(strlen(embl_def) != 0 && strlen(embl_accession) != 0){
  768.     strncpy(header, embl_accession, MAX_HEADER_LEN);
  769.     s_strncat(header, " ", MAX_HEADER_LEN, MAX_HEADER_LEN);
  770.     s_strncat(header, embl_def, MAX_HEADER_LEN, MAX_HEADER_LEN);
  771.   }
  772.   else if(strlen(embl_def) != 0){
  773.     strncpy(header, embl_def, MAX_HEADER_LEN);
  774.   }
  775.   else if(strlen(embl_accession) != 0){
  776.     strncpy(header, embl_accession, MAX_HEADER_LEN);
  777.   }
  778.   else{
  779.     strcpy(header, "Unknown Entry");
  780.   }
  781.   embl_def[0] = '\0';
  782.   embl_accession[0] = '\0';
  783. }
  784.  
  785.  
  786.  
  787. /* ==========================================
  788.  *
  789.  * ===  Prosite Dat & Doc Customizations  ===
  790.  *
  791.  * d.g.gilbert, 18feb92, 
  792.  * gilbertd@bio.indiana.edu
  793.  *
  794.  * ==========================================
  795.  */
  796.  
  797. #define prositedat_data_tab 5
  798.  
  799. /* Prosite DOC format:
  800.  
  801. {END}
  802. {PDOC00002}
  803. {PS00002; GLYCOSAMINOGLYCAN}
  804. {BEGIN}
  805. *************************************
  806. * Glycosaminoglycan attachment site *
  807. *************************************
  808.  
  809. Proteoglycans [1] are complex glycoconjugates consisting of a core  protein to
  810. which a variable number of glycosaminoglycan chains  (such as heparin sulfate,
  811. chondroitin sulfate, etc.) are covalently attached. The glycosaminoglycans are
  812. attached to the core proteins through  a xyloside residue which is  in turn is
  813. linked to  a serine   residue of the protein.    A consensus sequence for  the
  814. attachment  site seems  to exist [2].   However,  it must be noted  that  this
  815. consensus is only based on the sequence of three proteoglycans core proteins.
  816.  
  817. -Consensus pattern: S-G-x-G
  818.                     [S is the attachment site]
  819.  Additional rule: There must be at least  two acidic amino acids from -2 to -4
  820.                   relative to the serine.
  821. -Last update: June 1988 / First entry.
  822.  
  823. [ 1] Hassel J.R., Kimura J.H., Hascall V.C.
  824.      Annu. Rev. Biochem. 55:539-567(1986).
  825. [ 2] Bourdon M.A., Krusius T., Campbell S., Schwarz N.B.
  826.      Proc. Natl. Acad. Sci. U.S.A. 84:3194-3198(1987).
  827. {END}
  828. {PDOC00003}
  829. {PS00003; SULFATATION}
  830. {BEGIN}
  831.  
  832. *****/
  833.  
  834. /* Prosite DAT format:
  835. //
  836. ID   ASN_GLYCOSYLATION; PATTERN.
  837. 1234567890
  838. AC   PS00001;
  839. DT   APR-1990 (CREATED); APR-1990 (DATA UPDATE); APR-1990 (INFO UPDATE).
  840. DE   N-glycosylation site.
  841. PA   N-{P}-[ST]-{P}.
  842. CC   /TAXO-RANGE=??E?V;
  843. CC   /SITE=1,carbohydrate;
  844. CC   /SKIP-FLAG=TRUE;
  845. DO   PDOC00001;
  846. //
  847.  
  848. *****/
  849.  
  850. boolean prositedoc_separator_function(line)
  851. char *line;
  852. {
  853.   if ((strlen(line) > strlen("{END}")) && substrcmp(line, "{END}")){
  854.      return(true);
  855.      }
  856.   else{
  857.     return(false);
  858.     }
  859. }
  860.  
  861.  
  862. char *prositedoc_def = bio_header1;
  863. char *prositedoc_accession= bio_header2;
  864.  
  865. void prositedoc_header_function(line)
  866. char *line;
  867. {
  868.   if ((strlen(line)>2) && (line[0]=='*') && (line[1]==' ') && 
  869.      (strlen(prositedoc_def) == 0)){
  870.     strncpy(prositedoc_def, line + 2, MAX_HEADER_LEN);
  871.     trim_trailing_newline(prositedoc_def);
  872.     }
  873.   else if ((strlen(line)>2) && (line[0]=='{') && 
  874.      (!substrcmp(line, "{END}")) &&
  875.      (strlen(prositedoc_accession) == 0)){
  876.     char *cp;
  877.     strncpy(prositedoc_accession, line+1, MAX_HEADER_LEN);
  878.     cp= strchr(prositedoc_accession, '}');
  879.     if (cp!=NULL) *cp=0;  
  880.     trim_trailing_newline(prositedoc_accession);
  881.     }
  882.   
  883. }
  884.  
  885. void prositedoc_finish_header_function(header)
  886. char *header;
  887. {
  888.   if(strlen(prositedoc_def) != 0 && strlen(prositedoc_accession) != 0){
  889.     strncpy(header, prositedoc_accession, MAX_HEADER_LEN);
  890.     s_strncat(header, " ", MAX_HEADER_LEN, MAX_HEADER_LEN);
  891.     s_strncat(header, prositedoc_def, MAX_HEADER_LEN, MAX_HEADER_LEN);
  892.   }
  893.   else if(strlen(prositedoc_def) != 0){
  894.     strncpy(header, prositedoc_def, MAX_HEADER_LEN);
  895.   }
  896.   else if(strlen(prositedoc_accession) != 0){
  897.     strncpy(header, prositedoc_accession, MAX_HEADER_LEN);
  898.   }
  899.   else{
  900.     strcpy(header, "Unknown Entry");
  901.   }
  902.   prositedoc_def[0] = '\0';
  903.   prositedoc_accession[0] = '\0';
  904. }
  905.  
  906.  
  907. boolean prositedat_separator_function(line)
  908. char *line;
  909. {
  910. /* !! with // as separator, we get // at top of entry which will
  911.    screw up seqanal software... */
  912. /*  if ((strlen(line) > 1) && (0==strncmp(line, "//", 2))){
  913.      return(true);
  914.      }  
  915. */
  916.   if ((strlen(line) > prositedat_data_tab) && substrcmp(line, "ID  ")){
  917.      return(true);
  918.      }
  919.   else{
  920.     return(false);
  921.     }
  922. }
  923.  
  924.  
  925. char *prositedat_def = bio_header1;
  926. char *prositedat_accession= bio_header2;
  927.  
  928. void prositedat_header_function(line)
  929. char *line;
  930. {
  931.   int   i;
  932.  
  933.   if ((strlen(line) > prositedat_data_tab) &&
  934.      substrcmp(line, "DE   ") &&
  935.      (strlen(prositedat_def) == 0)){
  936.     strncpy(prositedat_def, line + prositedat_data_tab, MAX_HEADER_LEN);
  937.     trim_trailing_newline(prositedat_def);
  938.     }
  939.     
  940.   else if ((strlen(line) > prositedat_data_tab) &&
  941.      substrcmp(line, "AC   ") &&
  942.      (strlen(prositedat_accession) == 0)){
  943.     /* cut extra acc. numbers from this -- we want only 1st */
  944.     char *cp;
  945.     for (cp=line+prositedat_data_tab; *cp==' '; cp++) ;
  946.     strncpy(prositedat_accession, cp, MAX_HEADER_LEN);
  947.     cp= strchr(prositedat_accession, ' ');
  948.     if (cp!=NULL) *cp=0; /* drop after 1st */
  949.     trim_trailing_newline(prositedat_accession);
  950.     }
  951.    
  952.   if (strlen(line) > prositedat_data_tab)
  953.     for (i=0; i<prositedat_data_tab; i++) line[i]= ' '; 
  954.   
  955. }
  956.  
  957. void prositedat_finish_header_function(header)
  958. char *header;
  959. {
  960.   if(strlen(prositedat_def) != 0 && strlen(prositedat_accession) != 0){
  961.     strncpy(header, prositedat_accession, MAX_HEADER_LEN);
  962.     s_strncat(header, " ", MAX_HEADER_LEN, MAX_HEADER_LEN);
  963.     s_strncat(header, prositedat_def, MAX_HEADER_LEN, MAX_HEADER_LEN);
  964.   }
  965.   else if(strlen(prositedat_def) != 0){
  966.     strncpy(header, prositedat_def, MAX_HEADER_LEN);
  967.   }
  968.   else if(strlen(prositedat_accession) != 0){
  969.     strncpy(header, prositedat_accession, MAX_HEADER_LEN);
  970.   }
  971.   else{
  972.     strcpy(header, "Unknown Entry");
  973.   }
  974.   prositedat_def[0] = '\0';
  975.   prositedat_accession[0] = '\0';
  976. }
  977.  
  978. /* ==================== 
  979.  *      Bio Journals        
  980.  * (modified EMBL format) 
  981.  * dgg
  982.  * ================== 
  983.  */
  984.  
  985. /******
  986. //
  987. RA   Casida L.E. Jr.;
  988. 123456
  989. RT   "Protozoan Response to the Addition of Bacterial Predators and Other
  990. RT   Bacteria to Soil.";
  991. RL   Appl. Environ. Microbiol. 55:1857-1859(1989).
  992. //
  993. RA   Caldwell B.A., Ye C., Griffiths R.P., Moyer C.L., Morita R.Y.;
  994. RT   "Plasmid Expression and Maintenance during Long-Term Starvation-Survival
  995. RT   of Bacteria in Well Water.";
  996. RL   Appl. Environ. Microbiol. 55:1860-1864(1989).
  997. //
  998. *******/
  999.  
  1000. #define biojournal_tab  5
  1001.  
  1002. boolean biojournal_separator_function(line)
  1003. char *line;
  1004. {
  1005.   if ((strlen(line) > 1) && (0==strncmp(line, "//", 2))){
  1006.      return(true);
  1007.      }  
  1008. /*  if ((strlen(line) > biojournal_tab) && substrcmp(line, "RA   ")){
  1009.      return(true);
  1010.      }
  1011. */
  1012.   else{
  1013.     return(false);
  1014.     }
  1015. }
  1016.  
  1017.  
  1018. char *biojournal_title = bio_header1;
  1019. char *biojournal_author= bio_header2;
  1020.  
  1021. void biojournal_header_function(line)
  1022. char *line;
  1023. {
  1024.   int   i;
  1025.  
  1026.   if ((strlen(line) > biojournal_tab) && substrcmp(line, "RT   ") &&
  1027.      (strlen(biojournal_title) == 0)){
  1028.     strncpy(biojournal_title, line + biojournal_tab, MAX_HEADER_LEN);
  1029.     trim_trailing_newline(biojournal_title);
  1030.     }
  1031.     
  1032.   else if ((strlen(line) > biojournal_tab) && substrcmp(line, "RA   ") &&
  1033.      (strlen(biojournal_author) == 0)){
  1034.     char *cp;
  1035.     strncpy(biojournal_author, line+biojournal_tab, MAX_HEADER_LEN);
  1036.     cp= strchr(biojournal_author, ' ');
  1037.     if (cp!=NULL) *cp=0; /* drop after 1st */
  1038.     trim_trailing_newline(biojournal_author);
  1039.     }
  1040.    
  1041.    if (strlen(line) > biojournal_tab)
  1042.     for (i=0; i<biojournal_tab; i++) line[i]= ' '; 
  1043. }
  1044.  
  1045. void biojournal_finish_header_function(header)
  1046. char *header;
  1047. {
  1048.   if(strlen(biojournal_title) != 0 && strlen(biojournal_author) != 0){
  1049.     strncpy(header, biojournal_author, MAX_HEADER_LEN);
  1050.     s_strncat(header, " ", MAX_HEADER_LEN, MAX_HEADER_LEN);
  1051.     s_strncat(header, biojournal_title, MAX_HEADER_LEN, MAX_HEADER_LEN);
  1052.   }
  1053.   else if(strlen(biojournal_title) != 0){
  1054.     strncpy(header, biojournal_title, MAX_HEADER_LEN);
  1055.   }
  1056.   else if(strlen(biojournal_author) != 0){
  1057.     strncpy(header, biojournal_author, MAX_HEADER_LEN);
  1058.   }
  1059.   else{
  1060.     strcpy(header, "Unknown Entry");
  1061.   }
  1062.   biojournal_title[0] = '\0';
  1063.   biojournal_author[0] = '\0';
  1064. }
  1065.  
  1066.  
  1067. /* ==========================================
  1068.  *
  1069.  * ===  Drosophila Redbook Customizations  ===
  1070.  *
  1071.  * d.g.gilbert, 18feb92, 
  1072.  * gilbertd@bio.indiana.edu
  1073.  * ==========================================
  1074.  */
  1075.  
  1076. /*------ example
  1077. |#Abnormal:  see A
  1078. |#abnormal abdomen:  see a( )
  1079. |#Abnormal abdomen:  see A
  1080. |# abnormal eye:  see mit15
  1081. |#abnormal oocytes:  see abo
  1082. |#abnormal tergites:  see abt
  1083. |#abnormal wings:  see abw
  1084. |#abo:  abnormal oocyte
  1085. | location:  2-44.0 (mapped with respect to J, 2-41).
  1086. | origin:  Naturally occurring allele recovered near Rome,
  1087. |   Italy.
  1088. | references:  Sandler, Lindsley, Nicoletti, and Trippa,
  1089. | ...
  1090. ----*/
  1091.  
  1092.  
  1093. boolean redbook_separator_function(line)
  1094. char *line;
  1095. {
  1096.   if(*line=='#'){
  1097.     return(true);
  1098.   }
  1099.   else{
  1100.     return(false);
  1101.   }
  1102. }
  1103.  
  1104. char *redbook_header = bio_header1;
  1105.  
  1106. void redbook_header_function(line)
  1107. char *line;
  1108. {
  1109.   if(redbook_separator_function(line)){
  1110.     strncpy(redbook_header, line + 1, MAX_HEADER_LEN);
  1111.   }
  1112. }
  1113.  
  1114. void redbook_finish_header_function(header)
  1115. char *header;
  1116. {
  1117.   if(strlen(redbook_header) == 0){
  1118.     strncpy(header, "Unknown", MAX_HEADER_LEN);
  1119.   }
  1120.   else{
  1121.     strncpy(header, redbook_header, MAX_HEADER_LEN);
  1122.   }
  1123.   redbook_header[0] = '\0';
  1124. }
  1125.  
  1126.  
  1127. /* ==========================================
  1128.  *
  1129.  * ===  Drosophila flybase Customizations  ===
  1130.  *
  1131.  * d.g.gilbert, 18feb92, 
  1132.  * gilbertd@bio.indiana.edu
  1133.  * ==========================================
  1134.  */
  1135.  
  1136. /*----------------------------------------
  1137. ::::::::::::::
  1138. ABAUTOSY.TEXT
  1139. ::::::::::::::
  1140. LS(2)P6
  1141.      24E-24F        28A-28D             A
  1142. LS(2)P11
  1143.      25E-25F        35D                 A
  1144. ::::::::::::::
  1145. ABDELETE.TEXT
  1146. ::::::::::::::
  1147. Df(1)FM7
  1148.      1A             1B2-1B3             Df   |l(1)1Aa--ac|
  1149. In(1)y3P$+L$-sc8$+R$-
  1150.      1A             1B2-1B3             Df   |y--ac|
  1151. ::::::::::::::
  1152. ABDUPLIC.TEXT
  1153. ::::::::::::::
  1154. In(1)sc8$+L$-EN$+R$-
  1155.      1A             1B2-1B3             Dp   |l(1)1Ac--ac|
  1156. In(1)sc8$+L$-y3P$+R$-
  1157.      1A             1B2-1B3             Dp   |y--ac|
  1158. ::::::::::::::
  1159. ABINSERT.TEXT
  1160. ::::::::::::::
  1161. TE298
  1162.      1E             []                  I
  1163. TE276
  1164.      3A1-3A2        []                  I
  1165. ::::::::::::::
  1166. ABINVERT.TEXT
  1167. ::::::::::::::
  1168. In(1)l-v227
  1169.      1-2            19-20               In
  1170. In(1)y-G
  1171.      1A             1C3-1C4             In   |y--y|;;
  1172. ::::::::::::::
  1173. ABREFS.TEXT
  1174. ::::::::::::::
  1175. 3R3L.3R                                 Novitski, Genetics 98:257
  1176. B$+S$- v$++$- y$++Y$-                   Voelker, Genetics 107:279
  1177. B$+S$-Ybb$+l$-                          Polembo, Molec.Gen.Genet. 195:35
  1178. ::::::::::::::
  1179. ABTRANSL.TEXT
  1180. ::::::::::::::
  1181. T(1;2)gl$++$-
  1182.      1A             21C1                T
  1183. T(1;2)y-v1
  1184.      1A             39                  T    |y--y|;;
  1185. T(1;2)SP55
  1186.      1A             41                  T
  1187. ::::::::::::::
  1188. ABTRANSP.TEXT
  1189. ::::::::::::::
  1190. Tp(3;1)pn36
  1191.      1A             61A                 Tp
  1192. Tp(1;1)Si2
  1193.      1A1-1A8        14D2-14E1           Tp   |r--r|;;
  1194. Tp(1;1)Si2
  1195.      1A1-1A8        18F                 Tp
  1196. ::::::::::::::
  1197. COSMID.TEXT
  1198. ::::::::::::::
  1199. 1A\S\T\U      0          0            0                23E12
  1200. 1A\VS         0          ~50          BH\W             125H10
  1201. 1B\M\U        0          0            0                88B3
  1202. ::::::::::::::
  1203. FUNCTION.TEXT
  1204. ::::::::::::::
  1205. 3-hydroxy-3-methylglutaryl-coenzyme-A-reductase               1.1.1.34  HmG-CoAR
  1206. 6-pyruvoyl-tetrahydropterin-synthase                                     pr
  1207. 14-3-3-protein                                                           D14-3-3
  1208. ::::::::::::::
  1209. LOCI.TEXT
  1210. ::::::::::::::
  1211. 3S18;    3S18-element
  1212.               repetitive-element-3S18
  1213. 4.5SRNA;    4.5SRNA
  1214.           3-[21]     65A
  1215.               RNA-4.5S
  1216. 5HT-R1;    serotonin-receptor-1
  1217.           3-[102]    100A
  1218.               serotonin-receptor
  1219.               transmembrane-protein
  1220.               G-protein-coupled-receptor
  1221. 5HT-R2A;    serotonin-receptor
  1222.           2-[87]     56A-56B
  1223. ::::::::::::::
  1224. LZSYN.TEXT
  1225. ::::::::::::::
  1226.  Acp-g1              AcpG
  1227.  Acr96A              Acr96Aa
  1228.  Aldox-1             Aldox1
  1229. ::::::::::::::
  1230. MAP.TEXT
  1231. ::::::::::::::
  1232. 1-[0]          1A6 ?                            l(1)Ac
  1233. 1-0.0                                           cc
  1234. 1-0.0                                           clv-1
  1235. ::::::::::::::
  1236. REFS.TEXT
  1237. ::::::::::::::
  1238. 4.5SRNA              Steffenson            Genetics 110:s84
  1239. 5HT-R1               Boschert              12th Europ.Dros.Conference
  1240. 5HT-R2A              Boschert              12th Europ.Dros.Conference
  1241. ::::::::::::::
  1242. SYNONYMS.TEXT
  1243. ::::::::::::::
  1244. 1C                                Pk36A
  1245. 1J                                Pk91C
  1246. 2sm$+lab$-                        sm
  1247. 3-2                               Pk45C
  1248. ::::::::::::::
  1249. UID.TEXT
  1250. ::::::::::::::
  1251. 00001;4.5SRNA
  1252. 00002;5SRNA
  1253. 00003;7SLRNA
  1254. 00004;17.6
  1255. -----------------------------*/
  1256.  
  1257. /*  need something like this for some doc formats.... */
  1258.  
  1259.  
  1260.  
  1261. boolean flybase_separator_function(line)
  1262. char *line;
  1263. {
  1264.   if (isgraph(*line)) {
  1265.     return(true);
  1266.   }
  1267.   else{
  1268.     return(false);
  1269.   }
  1270. }
  1271.  
  1272. char *flybase_header = bio_header1;
  1273.  
  1274. void flybase_header_function(line)
  1275. char *line;
  1276. {
  1277.   char *c;
  1278.     int  i;
  1279.     
  1280.   if (flybase_separator_function(line)) {
  1281.       for (c=line, i=0; isgraph(*c) && (i<MAX_HEADER_LEN); )  
  1282.             flybase_header[i++]= *c++; 
  1283.         flybase_header[i]= '\0';
  1284.     }
  1285. }
  1286.  
  1287. void flybase_finish_header_function(header)
  1288. char *header;
  1289. {
  1290.   if(strlen(flybase_header) == 0){
  1291.     strncpy(header, "Unknown", MAX_HEADER_LEN);
  1292.   }
  1293.   else{
  1294.     strncpy(header, flybase_header, MAX_HEADER_LEN);
  1295.   }
  1296.   flybase_header[0] = '\0';
  1297. }
  1298.  
  1299. /* ==========================================
  1300.  * DIN news -- like BIO but "***" separator 
  1301.  * dgg
  1302.  */
  1303.  
  1304. boolean din_hit_head = false;
  1305. char din_header[MAX_HEADER_LEN + 1];
  1306.  
  1307. boolean din_separator_function(line)
  1308. char *line;
  1309. {
  1310.   if ((strlen(line) >= 3) && substrcmp(line, "***")) {
  1311.     return(true);
  1312.   }
  1313.   else{
  1314.     return(false);
  1315.   }
  1316. }
  1317.  
  1318.  
  1319. void din_header_function(line)
  1320. char *line;
  1321. {
  1322.   if(din_hit_head   /* we just hit a seperator previous to this */
  1323.      && strlen(line) > 3        /* line is valid */
  1324.      && isalnum(*line)          /* and is word */
  1325.      && (!din_separator_function(line)) /* we are not on the separator now */
  1326.      && strlen(din_header) == 0){ /* and we have not saved the headline yet */
  1327.     strcpy(din_header, line);
  1328.     waislog(WLOG_MEDIUM, WLOG_INDEX, "storing line: %s", din_header);
  1329.     din_hit_head = false;
  1330.   }
  1331. }
  1332.  
  1333. void din_finish_header_function(header)
  1334. char *header;
  1335. {
  1336.   din_hit_head = true;  /* turn on the flag */
  1337.   if(strlen(din_header) == 0){
  1338.     strcpy(header, "Unknown Title");
  1339.   }
  1340.   else{
  1341.     strcpy(header, din_header);
  1342.   }
  1343.   din_header[0] = '\0';
  1344. }
  1345.  
  1346.  
  1347.  
  1348. #endif /* BIO */
  1349.  
  1350.  
  1351. /* =================================
  1352.  * ===  Groliers Customizations  ===
  1353.  * =================================
  1354.  */
  1355.  
  1356. boolean groliers_separator_function(line)
  1357. char *line;
  1358. {
  1359.   if((strlen(line) > strlen("ARTICLE")) &&
  1360.      substrcmp(line, "ARTICLE")){
  1361.     /* printf("hit %s\n", line); */
  1362.     return(true);
  1363.   }
  1364.   else{
  1365.     return(false);
  1366.   }
  1367. }
  1368.  
  1369. char groliers_header[MAX_HEADER_LEN + 1];
  1370.  
  1371. void groliers_header_function(line)
  1372. char *line;
  1373. {
  1374.   if(groliers_separator_function(line)){
  1375.     s_strncpy(groliers_header, line + strlen("ARTICLE") + 2, MAX_HEADER_LEN);
  1376.   }
  1377. }
  1378.  
  1379. void groliers_finish_header_function(header)
  1380. char *header;
  1381. {
  1382.   if(strlen(groliers_header) == 0){
  1383.     s_strncpy(header, "Unknown Title", MAX_HEADER_LEN);
  1384.   }
  1385.   else{
  1386.     s_strncpy(header, groliers_header, MAX_HEADER_LEN);
  1387.   }
  1388.   groliers_header[0] = '\0';
  1389. }
  1390.  
  1391.  
  1392. /* ==============================
  1393.  * ===  RMail Customizations  ===
  1394.  * ==============================
  1395.  */
  1396.  
  1397. /* this is just a preliminary version. A good version would
  1398.  * produce a headline like gnu emacs RMAIL
  1399.  */
  1400.  
  1401.  
  1402. boolean mail_separator_function(line)
  1403. char *line;
  1404. {
  1405.   /* this should really look for a "<cr><cr>From " rather than "<cr>From " */
  1406.   if((strlen(line) > strlen("From ")) &&
  1407.      substrcmp(line, "From ")){
  1408.     return(true);
  1409.   }
  1410.   else{
  1411.     return(false);
  1412.   }
  1413. }
  1414.  
  1415. boolean rmail_separator_function(line)
  1416. char *line;
  1417. {
  1418.   if(0 == strcmp(line, " \n")){
  1419.     return(true);
  1420.   }
  1421.   else{
  1422.     return(false);
  1423.   }
  1424. }
  1425.  
  1426. /* This one is portable, but might get the wrong answer.
  1427.    I'm open to better code.  - Jonny G
  1428. */
  1429.  
  1430.  
  1431. long my_getdate(line)
  1432. char *line;
  1433. {
  1434.   char date[255], *temp;
  1435.   int day, month, year;
  1436.   char cmonth[25], dow[5], tod[10];
  1437.  
  1438.   strcpy(date, line);
  1439.  
  1440.   temp = date;
  1441.  
  1442.   while(!isdigit(*temp)) temp++;
  1443.  
  1444.   sscanf(temp, "%d %25s %d", &day, cmonth, &year);
  1445.  
  1446.   for(month = 0; months[month] != NULL; month++)
  1447.     if(!strcmp(cmonth, months[month])) break;
  1448.  
  1449.   if (year > 99) year = year % 100;
  1450.  
  1451.   if(day > 0 && 
  1452.      month < 12 &&
  1453.      year > 0) {
  1454.     return (10000 * year + 100 * (month+1) + day);
  1455.   }
  1456.  
  1457.   month = -1; day = -1; year = -1;
  1458.  
  1459.   sscanf(temp, "%d/%d/%d", &month, &day, &year);
  1460.  
  1461.   if (year > 99) year = year % 100;
  1462.  
  1463.   if(day > 0 && 
  1464.      month < 12 &&
  1465.      year > 0) {
  1466.     return (10000 * year + 100 * (month+1) + day);
  1467.   }
  1468.  
  1469.   month = -1; day = -1; year = -1;
  1470.  
  1471.   sscanf(temp, "%d/%d/%d", &year, &month, &day);
  1472.  
  1473.   if (year > 99) year = year % 100;
  1474.  
  1475.   if(day > 0 && 
  1476.      month < 12 &&
  1477.      year > 0) {
  1478.     return (10000 * year + 100 * (month+1) + day);
  1479.   }
  1480.  
  1481.   temp = date;
  1482.  
  1483.   sscanf(temp, "%5s %25s %d %10s %d", dow, cmonth, &day, tod, &year);
  1484.  
  1485.   for(month = 0; months[month] != NULL; month++)
  1486.     if(!strcmp(cmonth, months[month])) break;
  1487.  
  1488.   if (year > 99) year = year % 100;
  1489.  
  1490.   if(day > 0 && 
  1491.      month < 12 &&
  1492.      year > 0) {
  1493.     return (10000 * year + 100 * (month+1) + day);
  1494.   }
  1495.  
  1496.   return 0;
  1497. }
  1498.  
  1499. long mail_date_function(line)
  1500. char *line;
  1501. {
  1502.   if((strlen(line) > strlen("Date: ")) &&
  1503.      substrcmp(line, "Date: ")){
  1504.     return(my_getdate(line+6));
  1505.   }
  1506.   else if((strlen(line) > strlen("From ")) &&
  1507.       substrcmp(line, "From ")){
  1508.     char *p;
  1509. #ifdef WIN32
  1510.     p = (char*)strchr(line+5, ' ');
  1511. #else
  1512.     p = (char*)index(line+5, ' ');
  1513. #endif
  1514.     if(p != NULL)
  1515.       return(my_getdate(p+1));
  1516.   }
  1517.   else return -1;
  1518. }
  1519.  
  1520.   
  1521.  
  1522. char mail_subject[MAX_HEADER_LEN + 1];
  1523. char mail_from[MAX_HEADER_LEN + 1];
  1524.  
  1525. void mail_header_function(line)
  1526. char *line;
  1527. {
  1528.   if((strlen(line) > strlen("Subject: ")) &&
  1529.      substrcmp(line, "Subject: ") &&
  1530.      (strlen(mail_subject) == 0)){
  1531.     strcpy(mail_subject, "Re: ");
  1532.     s_strncat(mail_subject, line + strlen("Subject: "), MAX_HEADER_LEN, MAX_HEADER_LEN);
  1533.     trim_trailing_newline(mail_subject);
  1534.   }
  1535.   else if((strlen(line) > strlen("From: ")) &&
  1536.      substrcmp(line, "From: ") &&
  1537.      (strlen(mail_from) == 0)){
  1538.     /* this should find the <foo@bar> field in the from list */
  1539.     s_strncpy(mail_from, line + strlen("From: "), MAX_HEADER_LEN);
  1540.     trim_trailing_newline(mail_from);
  1541.   }
  1542.   
  1543. }
  1544.  
  1545. void mail_finish_header_function(header)
  1546. char *header;
  1547. {
  1548.   if(strlen(mail_subject) != 0 &&
  1549.      strlen(mail_from) != 0){
  1550.     /* trim the from line if needed */
  1551.     if(strlen(mail_from) > 10){
  1552.       mail_from[10] = '\0';
  1553.     }
  1554.     s_strncpy(header, mail_from, MAX_HEADER_LEN);
  1555.     s_strncat(header, " ", MAX_HEADER_LEN, MAX_HEADER_LEN);
  1556.     s_strncat(header, mail_subject, MAX_HEADER_LEN, MAX_HEADER_LEN);
  1557.     /* printf("%s\n", header); */
  1558.   }
  1559.   else if(strlen(mail_subject) != 0){
  1560.     s_strncpy(header, mail_subject, MAX_HEADER_LEN);
  1561.   }
  1562.   else if(strlen(mail_from) != 0){
  1563.     s_strncpy(header, mail_from, MAX_HEADER_LEN);
  1564.   }
  1565.   else{
  1566.     strcpy(header, "Unknown Subject");
  1567.   }
  1568.   mail_from[0] = '\0';
  1569.   mail_subject[0] = '\0';
  1570. }
  1571.  
  1572.  
  1573.  
  1574.  
  1575. boolean mail_or_rmail_separator(line)
  1576. char *line;
  1577. {
  1578.   static boolean blank_line = false;
  1579.  
  1580.   if((strlen(line) > strlen("From ")) &&
  1581.      substrcmp(line, "From ") &&
  1582.      blank_line == true){
  1583.     blank_line = false;
  1584.     return(true);
  1585.   }
  1586.   
  1587.   if(substrcmp(line, "")){
  1588.     blank_line = true;
  1589.     return(true);
  1590.   }    
  1591.   
  1592.   if(!strcmp(line, "\n")){
  1593.       blank_line = true;
  1594.     }
  1595.     else{
  1596.       blank_line = false;
  1597.     }
  1598.  
  1599.   return(false);
  1600. }
  1601.  
  1602. #ifdef WIN32
  1603. /* ========================================
  1604.  * ===  Microsoft Knowledge Base       ====
  1605.  * ========================================
  1606.  */
  1607.  
  1608. /*
  1609.  
  1610. Format of Each MS Knowledge Base File:
  1611.  
  1612. DOCUMENT:Q100650  01-MAR-1994  [O_LANMAN]
  1613. TITLE   :PRB: Internal Processing Error at 0270:0Bf8 with LMSM
  1614. PRODUCT :Microsoft Lan Manager
  1615. PROD/VER:2.10 2.10a
  1616. OPER/SYS:OS/2
  1617. KEYWORDS:
  1618.  
  1619. ...
  1620.  */
  1621.  
  1622. long mskbase_getdate(line)
  1623. char *line;
  1624. {
  1625.     /* genbank date == 30-SEP-1988*/
  1626.   char date[255], *temp;
  1627.   int day, month, year;
  1628.   char cmonth[25];
  1629.  
  1630.   strcpy(date, line);
  1631.  
  1632.   temp = date;
  1633.   
  1634.   while(!isdigit(*temp)) temp++;
  1635.  
  1636.   /* sscanf(temp, "%d %s %d", &day, cmonth, &year); */
  1637.   sscanf(temp, "%d-%s-%d", &day, cmonth, &year);
  1638.  
  1639.   for(month = 0; months[month] != NULL; month++)
  1640.     /* if(!strcmp(cmonth, months[month])) break; */
  1641.     if(!_stricmp(cmonth, months[month])) break; /* was stricmp !! */
  1642.  
  1643.   if (year > 99) year = year % 100;
  1644.  
  1645.   if(day > 0 && 
  1646.      month < 12 &&
  1647.      year > 0) {
  1648.     return (10000 * year + 100 * (month+1) + day);
  1649.   }
  1650.   return 0;
  1651. }
  1652.  
  1653. #define mskbase_date_tab 18
  1654.  
  1655. long mskbase_date_function(line)
  1656. char *line;
  1657. {
  1658.   if ((strlen(line) > mskbase_date_tab) && substrcmp(line, "DOCUMENT:")){
  1659.     /* mskbase_getdate processes 01-MAR-1994 format date */
  1660.     return(mskbase_getdate(line+mskbase_date_tab));
  1661.   }
  1662.   else 
  1663.     return -1;
  1664. }
  1665.  
  1666. char mskbase_title[MAX_HEADER_LEN + 1];
  1667.  
  1668. void mskbase_header_function(line)
  1669. char *line;
  1670. {
  1671.   if((strlen(line) > strlen("TITLE   :")) &&
  1672.      substrcmp(line, "TITLE   :") &&
  1673.      (strlen(mskbase_title) == 0)){
  1674.     s_strncat(mskbase_title, line + strlen("TITLE   :"), MAX_HEADER_LEN, MAX_HEADER_LEN);
  1675.     trim_trailing_newline(mskbase_title);
  1676.   }
  1677. }
  1678.  
  1679. void mskbase_finish_header_function(header)
  1680. char *header;
  1681. {
  1682.   if(strlen(mskbase_title) == 0){
  1683.     strcpy(header, "Unknown Title");
  1684.   }
  1685.   else{
  1686.     s_strncpy(header, mskbase_title, MAX_HEADER_LEN);
  1687.   }
  1688.   mskbase_title[0] = '\0';
  1689. }
  1690. #endif /* WIN32 */
  1691.  
  1692. /* ========================================
  1693.  * ===  Mail Digest Customizations     ====
  1694.  * ========================================
  1695.  */
  1696.  
  1697. boolean mail_digest_separator_function(line)
  1698. char *line;
  1699. {
  1700.   if((strlen(line) > strlen("-----------------------------")) &&
  1701.      substrcmp(line, "------------------------------")){
  1702.     return(true);
  1703.   }
  1704.   else{
  1705.     return(false);
  1706.   }
  1707. }
  1708.  
  1709. /* ========================================
  1710.  * ===  Listserv Digest Customizations     ====
  1711.  * ========================================
  1712.  */
  1713.  
  1714. char listserv_from[MAX_HEADER_LEN + 1];
  1715. char listserv_subject[MAX_HEADER_LEN + 1];
  1716.  
  1717. boolean listserv_digest_separator_function(line)
  1718. char *line;
  1719. {
  1720.   if((strlen(line) > strlen("========================================")) &&
  1721.      substrcmp(line,"========================================")){
  1722.     return(true);
  1723.   }
  1724.   else{
  1725.     return(false);
  1726.   }
  1727. }  
  1728.  
  1729. long listserv_date_function(line)
  1730. char *line;
  1731. {
  1732.   if((strlen(line) > strlen("Date: ")) && substrcmp(line, "Date: ")){
  1733.     return(my_getdate(line+6));
  1734.   }
  1735.   else if((strlen(line) > strlen("From: ")) &&
  1736.      substrcmp(line, "From: ") && (strlen(listserv_from) == 0)){
  1737.     /* this should find the <foo@bar> field in the from list */
  1738.     s_strncpy(listserv_from, line + strlen("From:          "), MAX_HEADER_LEN);
  1739.     trim_trailing_newline(listserv_from);
  1740.   }
  1741.   else return -1;
  1742. }
  1743.  
  1744. void listserv_header_function(line)
  1745. char *line;
  1746. {
  1747.   if((strlen(line) > strlen("Subject: ")) &&
  1748.      substrcmp(line, "Subject: ") && (strlen(listserv_subject) == 0)){
  1749.     strcpy(listserv_subject, "Re: ");
  1750.     s_strncat(listserv_subject, line + strlen("Subject:      "), MAX_HEADER_LEN, MAX_HEADER_LEN);
  1751.     trim_trailing_newline(listserv_subject);
  1752.   }
  1753.   else if((strlen(line) > strlen("From: ")) &&
  1754.      substrcmp(line, "From: ") && (strlen(listserv_from) == 0)){
  1755. /*    printf("1: ->%s<-\n",line); */
  1756.     /* this should find the <foo@bar> field in the from list */
  1757.     s_strncpy(listserv_from, line + strlen("From:         "), MAX_HEADER_LEN);
  1758.     trim_trailing_newline(listserv_from);
  1759.     trim_leading_blanks(listserv_from);
  1760. /*    printf("2: ->%s<-\n",listserv_from); */
  1761.   }
  1762.   
  1763. }
  1764.  
  1765. void listserv_finish_header_function(header)
  1766. char *header;
  1767. {
  1768.   if(strlen(listserv_subject) != 0 && strlen(listserv_from) != 0){
  1769.     /* trim the from line if needed */
  1770.     if(strlen(listserv_from) > 15){
  1771.       listserv_from[15] = '\0';
  1772.     }
  1773.     trim_leading_blanks(listserv_from);
  1774.     s_strncpy(header, listserv_from, MAX_HEADER_LEN);
  1775.     s_strncat(header, " ", MAX_HEADER_LEN, MAX_HEADER_LEN);
  1776.     s_strncat(header, listserv_subject, MAX_HEADER_LEN, MAX_HEADER_LEN);
  1777.     /* printf("%s\n", header); */ 
  1778.   }
  1779.   else if(strlen(listserv_subject) != 0){
  1780.     s_strncpy(header, listserv_subject, MAX_HEADER_LEN);
  1781.   }
  1782.   else if(strlen(listserv_from) != 0){
  1783.     s_strncpy(header, listserv_from, MAX_HEADER_LEN);
  1784.   }
  1785.   else{
  1786.     strcpy(header, "Unknown Subject");
  1787.   }
  1788.   listserv_from[0] = '\0';
  1789.   listserv_subject[0] = '\0';
  1790. }
  1791.  
  1792. /* ========================================
  1793.  * ===  Library Catalog Customizations  ===
  1794.  * ========================================
  1795.  */
  1796.  
  1797. #define TITLE_MARKER "Title: "
  1798. #define FIRST_LINE_MARKER "Call No...."
  1799.  
  1800. /* just use the title */
  1801.  
  1802. boolean catalog_separator_function(line)
  1803. char *line;
  1804. {
  1805.   if (strstr(line, FIRST_LINE_MARKER)) {
  1806.     return(true);
  1807.   }
  1808.   else{
  1809.     return(false);
  1810.   }
  1811. }
  1812.  
  1813. char catalog_header[MAX_HEADER_LEN + 1];
  1814.  
  1815. void catalog_header_function(line)
  1816. char *line;
  1817. {
  1818.   char * title_start;
  1819.   if (title_start = strstr(line, TITLE_MARKER))
  1820.     {
  1821.       strncpy(catalog_header, title_start + strlen(TITLE_MARKER), MAX_HEADER_LEN);
  1822.     }
  1823. }
  1824.  
  1825. void catalog_finish_header_function(header)
  1826. char *header;
  1827. {
  1828.   if(strlen(catalog_header) == 0){
  1829.     strcpy(header, "Unknown Title");
  1830.   }
  1831.   else{
  1832.     s_strncpy(header, catalog_header, MAX_HEADER_LEN);
  1833.   }
  1834.   catalog_header[0] = '\0';
  1835. }
  1836.  
  1837.  
  1838.  
  1839. /* ============================
  1840.  * ===  Bio Customizations  ===
  1841.  * ============================
  1842.  */
  1843.  
  1844. /* customizations for a DB of genetic abstracts */
  1845.  
  1846. boolean hit_header = false;
  1847.  
  1848. boolean bio_separator_function(line)
  1849. char *line;
  1850. {
  1851.   if((strlen(line) > strlen(">>>")) &&
  1852.      substrcmp(line, ">>>")){
  1853.     return(true);
  1854.   }
  1855.   else{
  1856.     return(false);
  1857.   }
  1858. }
  1859.  
  1860. char bio_header[MAX_HEADER_LEN + 1];
  1861.  
  1862. void bio_header_function(line)
  1863. char *line;
  1864.  
  1865. {
  1866.   if(hit_header         /* we just hit a seperator previous to this */
  1867.      && (!bio_separator_function(line)) /* we are not on the separator now */
  1868.      && strlen(bio_header) == 0){ /* and we have not saved the headline yet */
  1869.     strcpy(bio_header, line);
  1870.     waislog(WLOG_MEDIUM, WLOG_INDEX, "storing line: %s", bio_header);
  1871.     hit_header = false;
  1872.   }
  1873. }
  1874.  
  1875. void bio_finish_header_function(header)
  1876. char *header;
  1877.  
  1878. {
  1879.   hit_header = true; /* turn on the flag */
  1880.   if(strlen(bio_header) == 0){
  1881.     strcpy(header, "Unknown Title");
  1882.   }
  1883.   else{
  1884.     strcpy(header, bio_header);
  1885.   }
  1886.   bio_header[0] = '\0';
  1887. }
  1888.  
  1889. /* =================================
  1890.  * ===  CMApp   Customizations  ===
  1891.  * =================================
  1892.  */
  1893.  
  1894. boolean cmapp_separator_function(line)
  1895. char *line;
  1896. {
  1897.   if((strlen(line) > strlen("@A")) &&
  1898.      substrcmp(line, "@A")){
  1899.     /* printf("hit %s\n", line); */
  1900.     return(true);
  1901.   }
  1902.   else{
  1903.     return(false);
  1904.   }
  1905. }
  1906.  
  1907. char cmapp_header[MAX_HEADER_LEN + 1];
  1908.  
  1909. void cmapp_header_function(line)
  1910. char *line;
  1911. {
  1912.   if((strlen(line) > strlen("APPLICATION:")) &&
  1913.      substrcmp(line, "APPLICATION:")){
  1914.     /* printf("hit %s\n", line); */
  1915.     s_strncpy(cmapp_header, line + strlen("APPLICATION:"), MAX_HEADER_LEN);
  1916.   }
  1917. }
  1918.  
  1919. void cmapp_finish_header_function(header)
  1920. char *header;
  1921. {
  1922.   if(strlen(cmapp_header) == 0){
  1923.     s_strncpy(header, "Unknown Title", MAX_HEADER_LEN);
  1924.   }
  1925.   else{
  1926.     s_strncpy(header, cmapp_header, MAX_HEADER_LEN);
  1927.   }
  1928.   cmapp_header[0] = '\0';
  1929. }
  1930.  
  1931. /* =================================
  1932.  * ===  Jargon   Customizations  ===
  1933.  * =================================
  1934.  *
  1935.  * GW - updated for Jargon File 2.9.8
  1936.  */
  1937.  
  1938. /*
  1939.  
  1940. Format of an entry:
  1941.  
  1942. [blank line]
  1943. :Title of This entry: first line of text of this entry
  1944.    second line of text of this entry
  1945.    third line of text of this entry
  1946. [blank line]
  1947.  
  1948. Any line which starts with a colon is considered to be the beginning
  1949. of an entry.
  1950.  
  1951. -GW
  1952.  
  1953. */
  1954.  
  1955. static int jargon_seen_entry = 0;
  1956.  
  1957. boolean jargon_separator_function(line)
  1958. register char *line;
  1959. {
  1960.   if(!jargon_seen_entry && line[0] == ':')
  1961.     jargon_seen_entry = 1;
  1962.   return line[0] == ':';
  1963. }
  1964.  
  1965. char jargon_header[MAX_HEADER_LEN + 1];
  1966.  
  1967. void jargon_header_function(line)
  1968. char *line;
  1969. {
  1970.   if(line[0] != ':')
  1971.     return;
  1972.  
  1973.   strncpy(jargon_header,line+1,MAX_HEADER_LEN);
  1974.   jargon_header[MAX_HEADER_LEN] = '\0';
  1975.  
  1976.   if(NULL != (line = strchr(jargon_header,':'))){
  1977.     if(line[1] == ':')
  1978.       line++;
  1979.     line++;
  1980.     line[0] = '\0';
  1981.   }
  1982. }   
  1983.  
  1984. void jargon_finish_header_function(header)
  1985. char *header;
  1986. {
  1987.   if(jargon_seen_entry) {
  1988.     strncpy(header, jargon_header, MAX_HEADER_LEN);
  1989.   }
  1990.   jargon_header[0] = '\0';
  1991. }
  1992.  
  1993.  
  1994. /* =================================
  1995.  * ===  Internet Resource Guide  ===
  1996.  * =================================
  1997.  */
  1998.  
  1999.  
  2000. char irg_header[MAX_HEADER_LEN + 1];
  2001. boolean irg_header_set = FALSE;
  2002.  
  2003. boolean irg_separator_function(line)
  2004. char *line;
  2005. {
  2006.   if(line[0] == 12){  /* control L */
  2007.     irg_header_set = FALSE;
  2008.     return(true);
  2009.   }
  2010.   else
  2011.     return(false);
  2012. }
  2013.  
  2014. void irg_header_function(line)
  2015. char *line;
  2016. {
  2017.   if((irg_header_set == FALSE) &&
  2018.      (line[0] == 32 )){ /* space */
  2019.     s_strncpy(irg_header, line + strspn(line, " "), MAX_HEADER_LEN);
  2020.     irg_header_set = TRUE;
  2021.   }
  2022.   
  2023. }
  2024.  
  2025. void irg_finish_header_function(header)
  2026. char *header;
  2027. {
  2028.   if(strlen(irg_header) == 0){
  2029.     s_strncpy(header, "Unknown Title", MAX_HEADER_LEN);
  2030.   }
  2031.   else{
  2032.     s_strncpy(header, irg_header, MAX_HEADER_LEN);
  2033.   }
  2034.   irg_header[0] = '\0';
  2035.   irg_header_set = FALSE;
  2036. }
  2037.  
  2038. /* ========================
  2039.  * ===  Dash Separator  ===
  2040.  * ========================
  2041.  */
  2042.  
  2043.  
  2044. /*
  2045.  * dash-seperate entries
  2046.  * used in Introduction to Algorithms bug.list, suggestions, etc.
  2047.  * --------------------... at least 20 dashes
  2048.  * header
  2049.  * item
  2050.  *  ..
  2051.  * --------------------... at least 20 dashes
  2052.  */
  2053.  
  2054. boolean dash_separator_function(line)
  2055. char *line;
  2056. {
  2057.   if((strlen(line) > 20) && substrcmp(line,"--------------------")){
  2058.     /* printf("hit %s\n", line); */
  2059.     return(true);
  2060.   }
  2061.   else{
  2062.     return(false);
  2063.   }
  2064. }
  2065.  
  2066. char dash_header[MAX_HEADER_LEN + 1];
  2067.  
  2068. void dash_header_function(line)
  2069. char *line;
  2070. {
  2071.   if(!dash_separator_function(line) &&
  2072.      (strlen(dash_header) < (MAX_HEADER_LEN - 1))){
  2073.     s_strncat(dash_header, line, 
  2074.           MAX_HEADER_LEN, MAX_HEADER_LEN);
  2075.     trim_trailing_newline(dash_header);
  2076.     strncat(dash_header, "  ", MAX_HEADER_LEN);
  2077.   }
  2078. }
  2079.  
  2080. void dash_finish_header_function(header)
  2081. char *header;
  2082. {
  2083.   if (strlen(dash_header) == 0) {
  2084.     strcpy(header, "No Title");
  2085.   }
  2086.   else {
  2087.     s_strncpy(header, dash_header, MAX_HEADER_LEN);
  2088.   }
  2089.   dash_header[0] = '\0';
  2090. }
  2091.  
  2092.  
  2093. /* ============================
  2094.  * ===  one_line Separator  ===
  2095.  * ============================
  2096.  */
  2097.  
  2098. /* this is where each line is a document (good for databases) */
  2099.  
  2100. boolean one_line_hit_header = false;
  2101.  
  2102. boolean one_line_separator_function(line)
  2103. char *line;
  2104. {
  2105.     return(true);
  2106. }
  2107.  
  2108. char one_line_header[MAX_HEADER_LEN + 1];
  2109.  
  2110. void one_line_header_function(line)
  2111. char *line;
  2112. {
  2113.     s_strncpy(one_line_header, line, MAX_HEADER_LEN);
  2114. }
  2115.  
  2116. void one_line_finish_header_function(header)
  2117. char *header;
  2118. {
  2119.   if (strlen(one_line_header) == 0) {
  2120.     strcpy(header, "No Title");
  2121.   }
  2122.   else {
  2123.     s_strncpy(header, one_line_header, MAX_HEADER_LEN);
  2124.   }
  2125.   one_line_header[0] = '\0';
  2126. }
  2127.  
  2128. /* =============================
  2129.  * ===  Paragraph Separator  ===
  2130.  * =============================
  2131.  */
  2132.  
  2133. /* paragraph files - seperated by a blank line.  Next line is the header */
  2134.  
  2135. char para_header[MAX_HEADER_LEN +1];
  2136. static boolean para_start = true;
  2137.  
  2138. boolean para_separator_function(line)
  2139. char *line;
  2140. {
  2141.   if (para_start == true) {
  2142.     para_start = false;
  2143.     return true;
  2144.   }
  2145.   if (strlen(line) < 2)
  2146.     para_start = true;
  2147.   return false;
  2148. }
  2149.  
  2150. void para_header_function(line)
  2151. char *line;
  2152. {
  2153.   if (para_header[0] == 0)
  2154.     s_strncpy(para_header, line, MAX_HEADER_LEN);
  2155. }
  2156.  
  2157. void para_finish_header_function(header)
  2158. char *header;
  2159. {
  2160.   if (strlen(para_header) == 0) {
  2161.     strcpy(header, "No Title");
  2162.   }
  2163.   else {
  2164.     s_strncpy(header, para_header, MAX_HEADER_LEN);
  2165.   }
  2166.   para_header[0] = 0;
  2167. }  
  2168. /* ========================================
  2169.  * ===  INRIA DOC   Customizations     ====
  2170.  * a la netnews
  2171.  * ========================================
  2172.  */
  2173.  
  2174. /* ottavj@sophia.inria.fr
  2175. Inria Documents are produced by a texto query, each on a separate file
  2176. */
  2177. char inriadoc_title[MAX_HEADER_LEN + 1];
  2178. char inriadoc_auth[MAX_HEADER_LEN + 1];
  2179.  
  2180. void inriadoc_header_function(line)
  2181. char *line;
  2182. {
  2183.   if((strlen(line) > strlen("Titre         ")) &&
  2184.      substrcmp(line, "Titre         ") &&
  2185.      (strlen(inriadoc_title) == 0)){
  2186.     strcpy(inriadoc_title, " : ");
  2187.     s_strncat(inriadoc_title, line + strlen("Titre           "), MAX_HEADER_LEN,
  2188.  MAX_HEADER_LEN);
  2189.     trim_trailing_newline(inriadoc_title);
  2190.      }
  2191.   else if((strlen(line) > strlen("Auteur(s)     ")) &&
  2192.      substrcmp(line, "Auteur(s)     ") &&
  2193.      (strlen(inriadoc_auth) == 0)){
  2194.     strncpy(inriadoc_auth, line + strlen("Auteur(s)     "), MAX_HEADER_LEN);
  2195.     trim_trailing_newline(inriadoc_auth);
  2196.      }
  2197. }
  2198.  
  2199. void inriadoc_finish_header_function(header)
  2200. char *header;
  2201. {
  2202.   if(strlen(inriadoc_title) != 0 &&
  2203.      strlen(inriadoc_auth) != 0){
  2204.     /* trim the auth line if needed */
  2205.     if(strlen(inriadoc_auth) > 40){
  2206.       inriadoc_auth[40] = '\0';
  2207.     }
  2208.     strncpy(header, inriadoc_auth, MAX_HEADER_LEN);
  2209.     s_strncat(header, " ", MAX_HEADER_LEN, MAX_HEADER_LEN);
  2210.     s_strncat(header, inriadoc_title, MAX_HEADER_LEN, MAX_HEADER_LEN);
  2211.     /* printf("%s\n", header); */
  2212.      }
  2213.   else if(strlen(inriadoc_title) != 0){
  2214.     strncpy(header, inriadoc_title, MAX_HEADER_LEN);
  2215.   }
  2216.   else if(strlen(inriadoc_auth) != 0){
  2217.     strncpy(header, inriadoc_auth, MAX_HEADER_LEN);
  2218.   }
  2219.   else{
  2220.     strcpy(header, "Unknown Title");
  2221.   }
  2222.   inriadoc_auth[0] = '\0';
  2223.   inriadoc_title[0] = '\0';
  2224. }
  2225.  
  2226.  
  2227.  
  2228. /* ==========================
  2229.  * ===  Seeker Separator  ===
  2230.  * ==========================
  2231.  */
  2232.  
  2233. boolean seeker_separator_function(line)
  2234. char *line;
  2235. {
  2236.   return(dash_separator_function(line));
  2237. }
  2238.  
  2239. char seeker_header[MAX_HEADER_LEN + 1];
  2240. boolean in_headline = FALSE;
  2241.  
  2242. void seeker_header_function(line)
  2243. char *line;
  2244. {
  2245.   if(strlen(line) > strlen("Headline:") &&
  2246.      substrcmp(line, "Headline:")){
  2247.     in_headline = TRUE;
  2248.     seeker_header[0] = '\0';
  2249.     /* printf("hit headline!\n"); */
  2250.   }
  2251.   else if(in_headline == TRUE &&
  2252.       (strlen(seeker_header) < (MAX_HEADER_LEN - 1))){
  2253.     s_strncat(seeker_header, line, 
  2254.           MAX_HEADER_LEN, MAX_HEADER_LEN);
  2255.     trim_trailing_newline(seeker_header);
  2256.   }
  2257. }
  2258.  
  2259. void seeker_finish_header_function(header)
  2260. char *header;
  2261. {
  2262.   if (strlen(seeker_header) == 0) {
  2263.     strcpy(header, "No Title");
  2264.   }
  2265.   else {
  2266.     s_strncpy(header, seeker_header, MAX_HEADER_LEN);
  2267.   }
  2268.   seeker_header[0] = '\0';
  2269.   in_headline = TRUE;
  2270. }  
  2271.  
  2272. /* ==========================
  2273.  * ===  RLIN Separator  ===
  2274.  * ==========================
  2275.  */
  2276.  
  2277. boolean rlin_separator_function(line)
  2278. char *line;
  2279. {
  2280.   return(dash_separator_function(line));
  2281. }
  2282.  
  2283. char rlin_header[MAX_HEADER_LEN + 1];
  2284. boolean rlin_in_headline = FALSE;
  2285.  
  2286. void rlin_header_function(line)
  2287. char *line;
  2288. {
  2289.   if(rlin_separator_function(line)){
  2290.     rlin_in_headline = TRUE;
  2291.     rlin_header[0] = '\0';
  2292.     /* printf("hit headline!\n"); */
  2293.   }
  2294.   else if(rlin_in_headline == TRUE &&
  2295.       (strlen(rlin_header) < (MAX_HEADER_LEN - 1))){
  2296.     s_strncat(rlin_header, line, 
  2297.           MAX_HEADER_LEN, MAX_HEADER_LEN);
  2298.     trim_trailing_newline(rlin_header);
  2299.   }
  2300. }
  2301.  
  2302. void rlin_finish_header_function(header)
  2303. char *header;
  2304. {
  2305.   if (strlen(rlin_header) == 0) {
  2306.     strcpy(header, "No Title");
  2307.   }
  2308.   else {
  2309.     s_strncpy(header, rlin_header, MAX_HEADER_LEN);
  2310.   }
  2311.   rlin_header[0] = '\0';
  2312.   in_headline = TRUE;
  2313. }  
  2314.  
  2315. /* ========================================
  2316.  * ===  MH_BBoard  Customizations     ====
  2317.  * ========================================
  2318.  */
  2319.  
  2320. /* gcardwel@uci.edu
  2321. MH bboards use a series of control A's to do a blank line.. yuk!
  2322. */
  2323.  
  2324. boolean mh_bboard_separator_function(line)
  2325. char *line;
  2326. {
  2327.   static boolean blank_line = false;
  2328.  
  2329.   if((strlen(line) > strlen("BBoard-ID: ")) &&
  2330.      substrcmp(line, "BBoard-ID: ") &&
  2331.      blank_line == true){
  2332.     blank_line = false;
  2333.     return(true);
  2334.   }
  2335.   
  2336.   if(!strcmp(line, "\001\001\001\001\n")){
  2337.     blank_line = true;
  2338.   }
  2339.   else{
  2340.     blank_line = false;
  2341.   }
  2342.   return (false);
  2343. }
  2344.  
  2345. /*
  2346.  * Customization for files saved from within the 'rn' newsreader.
  2347.  *
  2348.  * These can either be in 'mail' format, or they can be in a similar
  2349.  * format which starts each article with the pseudo-header
  2350.  * 'Article: 42 of comp.sys.foobar'.  Other than that, we treat this
  2351.  * just like 'mail'.
  2352.  *
  2353.  * wollman@uvm.edu, Sun Sep  8 20:12:21 EDT 1991
  2354.  *
  2355.  * dgg added "Path:" fix for netnews/NNTP fetches (!NOT MAIL, NO "From ")
  2356.  * gilbertd@sunflower.bio.indiana.edu
  2357.  */
  2358. boolean rn_separator_function(line)
  2359. char *line;
  2360. {
  2361.   if(!strncmp(line,"From ",5) ||
  2362.     !strncmp(line,"Path: ",6) ||
  2363.     !strncmp(line,"Article ",7) ||
  2364.     !strncmp(line,"Article: ",9))
  2365.     return true;
  2366.   return false;
  2367. }
  2368.  
  2369. /*
  2370.  * Customization for files saved NNTP netnews fetches (!NOT MAIL FORMAT, NO "From ".
  2371.  *
  2372.  * gilbertd@sunflower.bio.indiana.edu
  2373.  */
  2374. boolean netnews_separator_function(line)
  2375. char *line;
  2376. {
  2377.   if(!strncmp(line,"From ",5) ||
  2378.      !strncmp(line,"Article ",7) ||
  2379.      !strncmp(line,"Article: ",9))
  2380.     return true;
  2381.   return false;
  2382. }
  2383.  
  2384. /*
  2385.  * Customizations for GNU Emacs Info files
  2386.  *
  2387.  * When indexing info files, the user must index the files with real text
  2388.  * in them, rather than the file with the tag and indirect tables; otherwise
  2389.  * you'll end up with lots of garbage in your index.
  2390.  *
  2391.  * G. Wollman
  2392.  */
  2393.  
  2394. static int done_headline = 0;
  2395.  
  2396. boolean emacs_info_separator_function(line) /* hate K&R-style definitions */
  2397. char *line;
  2398. {
  2399.   if(line[0] == (char)31) {
  2400.     done_headline = 0;
  2401.     return true;
  2402.   }
  2403.   return false;
  2404. }
  2405.  
  2406. static char emacs_info_headline[MAX_HEADER_LEN+1];
  2407.  
  2408. void emacs_info_header_function(line)
  2409. register char *line;
  2410. {
  2411.   int i;
  2412.  
  2413.   if(done_headline)
  2414.     return;
  2415.  
  2416.   if(strncmp(line,"File: ",6))
  2417.     return;
  2418.  
  2419.   done_headline = 1;
  2420.   line += 6;            /* skip over "File: " */
  2421.  
  2422.   i = 1;
  2423.   emacs_info_headline[0] = '(';
  2424.   while(*line && *line != ',' && (i < MAX_HEADER_LEN-1))
  2425.     emacs_info_headline[i++] = *line++;
  2426.  
  2427.   emacs_info_headline[i++] = ')';
  2428.  
  2429.   line += 9;            /* skip over ", Node: " */
  2430.  
  2431.   /* copy the name of the info node into the headline */
  2432.   while(*line && (i < MAX_HEADER_LEN) && (*line != ','))
  2433.     emacs_info_headline[i++] = *line++;
  2434.  
  2435.   emacs_info_headline[i++] = '\0';
  2436. }
  2437.  
  2438. void emacs_info_finish_header_function(header)
  2439. char *header;
  2440. {
  2441.   strcpy(header,emacs_info_headline);
  2442. }
  2443.  
  2444. /* ========================================
  2445.  * ===    Medline  Customizations      ====
  2446.  * ========================================
  2447.  */
  2448.  
  2449. /* 
  2450.     Francois Schiettecatte
  2451.     with help from:
  2452.     Tom Emmel
  2453.     Karen Phipps
  2454. */
  2455.  
  2456. char medline_header[MAX_HEADER_LEN +1];
  2457. char medline_title[MAX_HEADER_LEN + 1];
  2458. char medline_date[MAX_HEADER_LEN + 1];
  2459. char medline_author[MAX_HEADER_LEN + 1];
  2460.  
  2461. static boolean medline_start = true;
  2462.  
  2463.  
  2464. boolean medline_separator_function(line)
  2465. char *line;
  2466. {
  2467.   if (medline_start == true) {
  2468.     medline_start = false;
  2469.     return true;
  2470.   }
  2471.   if (strlen(line) < 2)
  2472.     medline_start = true;
  2473.   return false;
  2474. }
  2475.  
  2476.  
  2477. void medline_header_function(line)
  2478. char *line;
  2479. {
  2480.  char *ptr;
  2481.  
  2482.  if((strlen(line) > strlen("TI ")) && 
  2483.      (substrcmp(line, "TI "))){    
  2484.     strncpy(medline_title, line + strlen("TI "), MAX_HEADER_LEN);
  2485.   }
  2486.  
  2487.   if((strlen(line) > strlen("SO ")) &&
  2488.      (substrcmp(line, "SO "))){
  2489.    ptr = strchr(line,'1');
  2490.    strncpy(medline_date, ptr, MAX_DATE_LEN);
  2491.   }
  2492.  
  2493.   if((strlen(line) > strlen("AU ")) &&
  2494.      (substrcmp(line, "AU "))){
  2495.     ptr = strtok(line + strlen("AU "),".,");
  2496.     strcpy(medline_author,ptr);
  2497.     strncat(medline_author, "  ", MAX_AUTHOR_LEN); 
  2498.   } 
  2499. }
  2500.  
  2501. void medline_finish_header_function(header)
  2502. char *header;
  2503. {
  2504.   if(strlen(medline_author) > 0 ){
  2505.    strncat(medline_header,medline_author, MAX_HEADER_LEN);
  2506.   }
  2507.   
  2508.   if(strlen(medline_date) > 0 ){
  2509.     strncat(medline_header,"(", MAX_HEADER_LEN);
  2510.     strncat(medline_header,medline_date, MAX_HEADER_LEN);
  2511.     strncat(medline_header,") ", MAX_HEADER_LEN);
  2512.   }
  2513.  
  2514.   if(strlen(medline_title) > 0 ){
  2515.     strncat(medline_header,medline_title, MAX_HEADER_LEN);
  2516.   }
  2517.   
  2518.   if(strlen(medline_header) == 0){
  2519.     strcpy(header, "No Title");
  2520.   }
  2521.   else{
  2522.     strncpy(header, medline_header, MAX_HEADER_LEN);
  2523.   }
  2524.  
  2525.   medline_header[0] = '\0';
  2526.   medline_title[0] = '\0';
  2527.   medline_date[0] = '\0';
  2528.   medline_author[0] = '\0';
  2529. }
  2530.  
  2531.  
  2532.  
  2533.  
  2534. /* ========================================
  2535.  * ===    Refer  Customizations      ====
  2536.  * ========================================
  2537.  */
  2538.  
  2539.  
  2540. /* 
  2541.     Francois Schiettecatte
  2542.     with help from:
  2543.     Tom Emmel
  2544.     Karen Phipps
  2545. */
  2546.  
  2547. char refer_header[MAX_HEADER_LEN +1];
  2548. char refer_title[MAX_HEADER_LEN + 1];
  2549. char refer_date[MAX_HEADER_LEN + 1];
  2550. char refer_author[MAX_HEADER_LEN + 1];
  2551.  
  2552. static boolean refer_start = true;
  2553.  
  2554.  
  2555. boolean refer_separator_function(line)
  2556. char *line;
  2557. {
  2558.   if (refer_start == true) {
  2559.     refer_start = false;
  2560.     return true;
  2561.   }
  2562.   if (strlen(line) < 2)
  2563.     refer_start = true;
  2564.   return false;
  2565. }
  2566.  
  2567.  
  2568. void refer_header_function(line)
  2569. char *line;
  2570. {
  2571.   if((strlen(line) > strlen("%T ")) && 
  2572.      (substrcmp(line, "%T "))){    
  2573.     strncpy(refer_title, line + strlen("%T "), MAX_HEADER_LEN);
  2574.   }
  2575.   else if((strlen(line) > strlen("%B ")) && 
  2576.      (substrcmp(line, "%B ")) && (strlen(refer_title) == 0)){    
  2577.     strncpy(refer_title, line + strlen("%B "), MAX_HEADER_LEN);
  2578.   }
  2579.   
  2580.   if((strlen(line) > strlen("%D ")) &&
  2581.      (substrcmp(line, "%D "))){
  2582.     strncpy(refer_date, line + strlen("%D "), MAX_DATE_LEN);
  2583.   }
  2584.  
  2585.   if((strlen(line) > strlen("%A ")) &&
  2586.      (substrcmp(line, "%A ")) && (strlen(refer_author) == 0)){
  2587.     strncpy(refer_author, line + strlen("%A "), MAX_AUTHOR_LEN);
  2588.     strncat(refer_author, " ", MAX_AUTHOR_LEN);
  2589.   }
  2590.   else if((strlen(line) > strlen("%E ")) &&
  2591.      (substrcmp(line, "%E ")) && (strlen(refer_author) == 0)){
  2592.     strncpy(refer_author, line + strlen("%E "), MAX_AUTHOR_LEN);
  2593.     strncat(refer_author, " ", MAX_AUTHOR_LEN);
  2594.   }
  2595. }
  2596.  
  2597. void refer_finish_header_function(header)
  2598. char *header;
  2599. {
  2600.   if(strlen(refer_author) > 0 ){
  2601.     strncat(refer_header,refer_author, MAX_HEADER_LEN);
  2602.   }
  2603.   
  2604.   if(strlen(refer_date) > 0 ){
  2605.     strncat(refer_header,"(", MAX_HEADER_LEN);
  2606.     strncat(refer_header,refer_date, MAX_HEADER_LEN);
  2607.     strncat(refer_header,") ", MAX_HEADER_LEN);
  2608.   }
  2609.  
  2610.   if(strlen(refer_title) > 0 ){
  2611.     strncat(refer_header,refer_title, MAX_HEADER_LEN);
  2612.   }
  2613.   
  2614.   if(strlen(refer_header) == 0){
  2615.     strncpy(header, "No Title", MAX_HEADER_LEN);
  2616.   }
  2617.   else{
  2618.     strncpy(header, refer_header, MAX_HEADER_LEN);
  2619.   }
  2620.  
  2621.   refer_header[0] = '\0';
  2622.   refer_author[0] = '\0';
  2623.   refer_date[0] = '\0';
  2624.   refer_title[0] = '\0';
  2625. }
  2626.  
  2627. #if 0 /* HTML, we already have such functions */
  2628. /* ===========================================
  2629.  * ===    HTML - grab the header from <TITLE></TITLE>
  2630.  * Michael Nelson (m.l.nelson@larc.nasa.gov) 10/26/93
  2631.  * ===========================================
  2632.  */
  2633.   
  2634. char html_header[MAX_HEADER_LEN +1];
  2635.   
  2636. boolean html_separator_function(line)
  2637. char *line;
  2638. {
  2639.   return false;
  2640. }
  2641.   
  2642. void html_header_function(line)
  2643. char *line;
  2644. {
  2645.   if((strlen(line) > strlen("<TITLE>")) &&
  2646.      ((substrcmp(line, "<TITLE>")) || (substrcmp(line, "<title>")))){
  2647.     strncpy(html_header, line + strlen("<TITLE>"), MAX_HEADER_LEN);
  2648.   }
  2649. }
  2650.  
  2651. void html_finish_header_function(header)
  2652. char *header;
  2653. {
  2654.   if (strlen(html_header) == 0) {
  2655.     strcpy(header, "No Title");
  2656.   }
  2657.   else {
  2658.     s_strncpy(header, html_header, MAX_HEADER_LEN);
  2659.   }
  2660.   html_header[0] = 0;
  2661. }  
  2662. #endif /* HTML */
  2663.  
  2664. /* ===========================================
  2665.  * ===    First Line  Customizations      ====
  2666.  * ===========================================
  2667.  */
  2668.  
  2669. /* this means the first line of the file is the headline.
  2670.    useful for the lyrics server */
  2671.  
  2672. /* paragraph files - seperated by a blank line.  Next line is the header */
  2673.  
  2674. char first_line_header[MAX_HEADER_LEN +1];
  2675.  
  2676. boolean first_line_separator_function(line)
  2677. char *line;
  2678. {
  2679.   return false;
  2680. }
  2681.  
  2682. void first_line_header_function(line)
  2683. char *line;
  2684. {
  2685.   if (first_line_header[0] == '\0')
  2686.     s_strncpy(first_line_header, line, MAX_HEADER_LEN);
  2687. }
  2688.  
  2689. void first_line_finish_header_function(header)
  2690. char *header;
  2691. {
  2692.   if (strlen(first_line_header) == 0) {
  2693.     strcpy(header, "No Title");
  2694.   }
  2695.   else {
  2696.     s_strncpy(header, first_line_header, MAX_HEADER_LEN);
  2697.   }
  2698.   first_line_header[0] = 0;
  2699. }  
  2700.  
  2701. /* =========================
  2702.  * ===  BIBTEX Separator ===
  2703.  * =========================
  2704.  * S.P.vandeBurgt@research.ptt.nl (Stan)
  2705.  *
  2706.  * BibTeX entries
  2707.  *
  2708.  * @......{
  2709.  * ......
  2710.  * title = header
  2711.  * .......}
  2712.  *
  2713.  */
  2714.  
  2715. static char bibtex_header[MAX_HEADER_LEN + 1];
  2716.  
  2717. boolean bibtex_separator_function(line)
  2718. char *line;
  2719. {
  2720.     char *p = line;
  2721.  
  2722.     while (isspace(*p)) p++; /* skip space */
  2723.     return(*p == '@');
  2724. }
  2725.  
  2726. void bibtex_header_function(line)
  2727. char *line;
  2728. {
  2729.     char *p = line;
  2730.  
  2731.     p = strstr(line, "title");
  2732.     if (p == NULL) p = strstr(line, "Title");
  2733.     if (p == NULL) p = strstr(line, "TITLE");
  2734.     if (p != NULL && (p == line || !isalpha(*(p-1))))
  2735.     {
  2736.       p += 5;
  2737.  
  2738.       while (isspace(*p)) p++; /* skip space */
  2739.       if (*p == '=')          /* should be an '=' now */
  2740.       {
  2741.           p++;
  2742.           /* skip bibtex char's */
  2743.           while (isspace(*p) || *p == '"' || *p == '{') p++;
  2744.           strncpy(bibtex_header, p, MAX_HEADER_LEN);
  2745.           for (p = bibtex_header; *p != '\0'; p++)
  2746.           {
  2747.               /* replace bibtex char's */
  2748.               if (*p == '\n' || *p == '"' || *p == '}' || *p == '{')
  2749.               {
  2750.                   *p = ' ';
  2751.               }
  2752.           }
  2753.       }
  2754.     }
  2755. }
  2756.  
  2757. void bibtex_finish_header_function(header)
  2758. char *header;
  2759. {
  2760.     if (bibtex_header[0] == '\0')
  2761.     {
  2762.       strcpy(header, "Unknown Title");
  2763.     }
  2764.     else{
  2765.       strncpy(header, bibtex_header, MAX_HEADER_LEN);
  2766.     }
  2767.     bibtex_header[0] = '\0';
  2768. }
  2769.  
  2770.  
  2771. /* =========================
  2772.  * ===  NHYP Separator ===
  2773.  * =========================
  2774.  * S.P.vandeBurgt@research.ptt.nl (Stan)
  2775.  * Nhyp entries
  2776.  *
  2777.  * ?:? header
  2778.  * ......
  2779.  * ......
  2780.  *
  2781.  */
  2782.  
  2783. static char nhyp_header[MAX_HEADER_LEN + 1];
  2784.  
  2785. boolean nhyp_separator_function(line)
  2786. char *line;
  2787. {
  2788.     return(strstr(line, "?:?") != NULL);
  2789. }
  2790.  
  2791. void nhyp_header_function(line)
  2792. char *line;
  2793. {
  2794.     char *p = line;
  2795.  
  2796.     p = strstr(line, "?:?");
  2797.     if (p != NULL)
  2798.     {
  2799.       p += 3;
  2800.       while (isspace(*p)) p++; /* skip space */
  2801.       strncpy(nhyp_header, p, MAX_HEADER_LEN);
  2802.       trim_trailing_newline(nhyp_header);
  2803.     }
  2804. }
  2805.  
  2806. void nhyp_finish_header_function(header)
  2807. char *header;
  2808. {
  2809.     if (nhyp_header[0] == '\0')
  2810.     {
  2811.       strcpy(header, "Unknown Title");
  2812.     }
  2813.     else{
  2814.       strncpy(header, nhyp_header, MAX_HEADER_LEN);
  2815.     }
  2816.     nhyp_header[0] = '\0';
  2817. }
  2818.  
  2819.  
  2820.  
  2821. /* ==========================
  2822.  * ===  Objective-C code  ===
  2823.  * ==========================
  2824.  */
  2825.  
  2826.  
  2827.  
  2828. /*----------------------- FSA -------------------*/
  2829. #define fsa_max_edges 4
  2830. #define fsa_error_state (-1)
  2831.  
  2832.  
  2833. typedef struct
  2834. {
  2835.     int if_input;
  2836.     int then_goto;
  2837. }
  2838.     fsa_edge;
  2839.  
  2840.  
  2841. /* action (if non-NULL) is excuted before transfer to next state is made */
  2842. /* action takes as arg the int input that will decide the next state */
  2843. typedef struct
  2844. {
  2845.     int default_goto;
  2846.     int n_edges;
  2847.     fsa_edge edges[fsa_max_edges];
  2848.     int (*action)();
  2849. }
  2850.     fsa_vertex;
  2851.  
  2852.  
  2853. int fsa_step(input, state_p, table)
  2854. int input;
  2855. int *state_p;
  2856. fsa_vertex *table;
  2857. {
  2858.     int next_state, e;
  2859.     int (*this_action)();
  2860.  
  2861.  
  2862.     if(*state_p < 0) return(*state_p = fsa_error_state);
  2863.     this_action = table[*state_p].action;
  2864.     if(this_action) this_action(input);
  2865.     for(e=0; e<table[*state_p].n_edges; e++)
  2866.         if(input == table[*state_p].edges[e].if_input)
  2867.         { next_state = table[*state_p].edges[e].then_goto; break; }
  2868.     if(e >= table[*state_p].n_edges) next_state = table[*state_p].default_goto;
  2869.     if(next_state < 0) next_state = fsa_error_state;
  2870.     return(*state_p = next_state);
  2871. }
  2872.  
  2873.  
  2874. /* sends null char as last input, returns final state */
  2875. int fsa_run(s, state_p, table)
  2876. char *s;
  2877. int *state_p;
  2878. fsa_vertex *table;
  2879. {
  2880.     char *p;
  2881.     
  2882.  
  2883.     for(p=s; *p; p++)
  2884.         fsa_step((int) *p, state_p, table);
  2885.     fsa_step(0, state_p, table);
  2886.     return(*state_p);
  2887. }
  2888.  
  2889.  
  2890. /*----------------------- end FSA -------------------*/
  2891.  
  2892.  
  2893. static int wobjc_brace_level = 0;
  2894. static int wobjc_paren_level = 0;
  2895. static int wobjc_strip_state = 0;
  2896. static int wobjc_context = 0;
  2897. static boolean wobjc_separator = false;
  2898. static char wobjc_class[MAX_HEADER_LEN+1];
  2899. static char *wobjc_class_end = 0;
  2900. static char wobjc_header[MAX_HEADER_LEN+1];
  2901. static char *wobjc_header_end = 0;
  2902.  
  2903.  
  2904. #define WOBJC_BLANK " \t\n\r"
  2905. #define WOBJC_WORD "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM_0123456789"
  2906.  
  2907.  
  2908. /* Flag next line as separator, when context fsa says so. */
  2909. static int wobjc_separate(input)
  2910. int input;
  2911. {
  2912.     return(wobjc_separator = true);
  2913. }
  2914.  
  2915.  
  2916. /* FSA to parse objective-C constructs. */
  2917. static fsa_vertex wobjc_context_fsa[] =
  2918. {
  2919.     { 0, 1, {{ '@', 1 }}},          /* look for objc constructs */
  2920.     { 0, 1, {{ 'i', 20 }}},
  2921.     { 3, 1, {{ ' ', 2 }}},              /* look for @imp class */
  2922.     { 4, 1, {{ 'A', 3 }}},
  2923.     { 4, 3, {{ '+', 6 },{ '-', 8 },{ '@', 10 }}},/* in @imp */
  2924.     { 4, 3, {{ '+', 6 },{ '-', 8 },{ '@', 10 }}, wobjc_separate},
  2925.     { 6, 1, {{ '{', 7 }}},          /* look for -method: */
  2926.     { 5, 1, {{ '{', 7 }}},
  2927.     { 8, 1, {{ '{', 9 }}},          /* look for +method: */
  2928.     { 5, 1, {{ '{', 9 }}},
  2929.     { 4, 1, {{ 'e', 11 }}},         /* look for @end of @imp */
  2930.     { 4, 1, {{ 'n', 12 }}},
  2931.     { 4, 1, {{ 'd', 0 }}},
  2932.     { 14, 1, {{ ' ', 13 }}},            /* look for @intf class */
  2933.     { 15, 1, {{ 'A', 14 }}},
  2934.     { 15, 1, {{ '@', 16 }}},            /* in @intf */
  2935.     { 15, 1, {{ 'e', 17 }}},            /* look for @end of @intf */
  2936.     { 15, 1, {{ 'n', 18 }}},
  2937.     { 15, 1, {{ 'd', 19 }}},
  2938.     { 0, 1, {{ '@', 1 }}, wobjc_separate},
  2939.     { 0, 2, {{ 'm', 21 },{ 'n', 33 }}},     /* look for @impl */
  2940.     { 0, 1, {{ 'p', 22 }}},
  2941.     { 0, 1, {{ 'l', 23 }}},
  2942.     { 0, 1, {{ 'e', 24 }}},
  2943.     { 0, 1, {{ 'm', 25 }}},
  2944.     { 0, 1, {{ 'e', 26 }}},
  2945.     { 0, 1, {{ 'n', 27 }}},
  2946.     { 0, 1, {{ 't', 28 }}},
  2947.     { 0, 1, {{ 'a', 29 }}},
  2948.     { 0, 1, {{ 't', 30 }}},
  2949.     { 0, 1, {{ 'i', 31 }}},
  2950.     { 0, 1, {{ 'o', 32 }}},
  2951.     { 0, 1, {{ 'n', 2 }}},
  2952.     { 0, 1, {{ 't', 34 }}},         /* look for @intf */
  2953.     { 0, 1, {{ 'e', 35 }}},
  2954.     { 0, 1, {{ 'r', 36 }}},
  2955.     { 0, 1, {{ 'f', 37 }}},
  2956.     { 0, 1, {{ 'a', 38 }}},
  2957.     { 0, 1, {{ 'c', 39 }}},
  2958.     { 0, 1, {{ 'e', 13 }}}
  2959. };
  2960.  
  2961.  
  2962. /* Action to be used by stripping fsa in non-commented, non-quoted state. */
  2963. /* This runs context fsa. */
  2964. static int wobjc_process_stripped_code(input)
  2965. int input;
  2966. {
  2967.     int context_input;
  2968.     
  2969.  
  2970.     switch(input)
  2971.     {
  2972.         /* Increment brace/paren levels as appropriate. */
  2973.     case '{': wobjc_brace_level++; break;
  2974.     case '}': if(wobjc_brace_level > 0) wobjc_brace_level--; break;
  2975.     case '(': wobjc_paren_level++; break;
  2976.     case ')': if(wobjc_paren_level > 0) wobjc_paren_level--; break;
  2977.     case '\"': break;
  2978.     case '\'': break;
  2979.     case '/': break;
  2980.         
  2981.     default:
  2982.         /* If in correct context and not in brace/paren/comment/quote, */
  2983.         /* then record header info.  */
  2984.         if(wobjc_brace_level==0 && wobjc_paren_level==0)
  2985.         {
  2986.             /* Recording class or instance method.  Ignore multiple blanks. */
  2987.             if(wobjc_context==6 || wobjc_context==8)
  2988.             {
  2989.                 if(!wobjc_header_end || wobjc_header_end==wobjc_header)
  2990.                 {
  2991.                     strcpy(wobjc_header, (wobjc_context==6 ? "+[" : "-["));
  2992.                     strcat(wobjc_header, wobjc_class);
  2993.                     strcat(wobjc_header, " ");
  2994.                     wobjc_header_end = wobjc_header+strlen(wobjc_header);
  2995.                 }
  2996.                 if((wobjc_header_end - wobjc_header)<(MAX_HEADER_LEN-5)
  2997.                     && !(strchr(WOBJC_BLANK, *(wobjc_header_end-1))
  2998.                         && strchr(WOBJC_BLANK, input)))
  2999.                     { *wobjc_header_end++ = input; *wobjc_header_end = 0; }
  3000.             }
  3001.             
  3002.  
  3003.             /* Recording class name for @implementation or @interface. */
  3004.             if(strchr(WOBJC_WORD, input)
  3005.                 && (wobjc_context==2 || wobjc_context==3
  3006.                     || wobjc_context==13 || wobjc_context==14))
  3007.             {
  3008.                 if(wobjc_context==2 || wobjc_context==13 || !wobjc_class_end)
  3009.                     wobjc_class_end = wobjc_class;
  3010.                 if(wobjc_context==13
  3011.                     || (wobjc_context==14 && !wobjc_header_end))
  3012.                     wobjc_header_end = wobjc_header;
  3013.                 if((wobjc_class_end - wobjc_class_end)<(MAX_HEADER_LEN/2))
  3014.                     { *wobjc_class_end++ = input; *wobjc_class_end = 0; }
  3015.                 if((wobjc_context==13 || wobjc_context==14)
  3016.                     && (wobjc_header_end-wobjc_header_end)<(MAX_HEADER_LEN/2))
  3017.                     { *wobjc_header_end++ = input; *wobjc_header_end = 0; }
  3018.             }
  3019.         }
  3020.         
  3021.         /* Since not in comment/quote, run context fsa. */
  3022.         /* Input is modified like this: */
  3023.         /*      Non-zero brace level => '{'. */
  3024.         /*      Else spaces => ' '. */
  3025.         /*      Else if in correct contexts, word letters => 'A'. */
  3026.         context_input = input;
  3027.         if(wobjc_brace_level>0) context_input = '{';
  3028.         else if(strchr(WOBJC_BLANK, input)) context_input = ' ';
  3029.         else if((wobjc_context==3 || wobjc_context==14)
  3030.             && strchr(WOBJC_WORD, input))
  3031.                 context_input = 'A';
  3032.         fsa_step(context_input, &wobjc_context, wobjc_context_fsa);
  3033.         break;
  3034.     }
  3035.     return(true);
  3036. }
  3037.  
  3038.  
  3039. /* FSA to strip out comments and quotes. */
  3040. static fsa_vertex wobjc_strip_fsa[] =
  3041. {
  3042.     { 0, 3, {{ '/', 1 },{ '\"', 5 },{ '\'', 7 }}, wobjc_process_stripped_code},
  3043.     { 0, 2, {{ '*', 2 },{ '/', 4 }}},       /* look for comment */
  3044.     { 2, 1, {{ '*', 3 }}},          /* in /* comment */
  3045.     { 2, 2, {{ '/', 0 },{ '*', 3 }}},
  3046.     { 4, 1, {{ '\n', 0 }, { '\0', 0 }}},    /* in // comment */
  3047.     { 5, 2, {{ '\\', 6 },{ '\"', 0 }}},     /* in " quote */
  3048.     { 5, 0, },
  3049.     { 7, 2, {{ '\\', 8 },{ '\'', 0 }}},     /* in ' quote */
  3050.     { 7, 0, }
  3051. };
  3052.  
  3053.  
  3054. boolean wobjc_separator_function(line)
  3055. char *line;
  3056. {
  3057.     if(wobjc_separator) { wobjc_separator = false; return true; }
  3058.     else return false;
  3059. }
  3060.  
  3061.  
  3062. void wobjc_header_function(line)
  3063. char *line;
  3064. {
  3065.     /* Run stripping fsa, which will run context fsa. */
  3066.     fsa_run(line, &wobjc_strip_state, wobjc_strip_fsa);
  3067.     return;
  3068. }
  3069.  
  3070.  
  3071. void wobjc_finish_header_function(header)
  3072. char *header;
  3073. {
  3074.     char *p;
  3075.     
  3076.  
  3077.     /* Flush terminal blanks and balance opening '[' if any. */
  3078.     for(p=wobjc_header+strlen(wobjc_header);
  3079.         p>wobjc_header && strchr(WOBJC_BLANK, *(p-1)); p--);
  3080.     if(wobjc_header[0]=='+' || wobjc_header[0]=='-') *p++ = ']';
  3081.     *p = 0;
  3082.     
  3083.  
  3084.     /* Copy out final header. */
  3085.     strcpy(header, wobjc_header);
  3086.     wobjc_header[0] = 0;
  3087.     wobjc_header_end = wobjc_header;
  3088.     return;
  3089. }
  3090.  
  3091.  
  3092. /* ==============================
  3093.  * ===  Ziff computer select  ===
  3094.  * ==============================
  3095.  */
  3096.  
  3097. /* these filters index ziff computer select cd-rom files that
  3098.    have been offloaded from the CDROM.  This is for indexing
  3099.    the CACM files that have been explicitly ok'ed by ACM.
  3100.    All other uses would violate the no lan access restrictions
  3101.    of Ziff */
  3102.  
  3103.  
  3104. #define ZIFF_TITLE_MARKER_1 "Title:     "
  3105. #define ZIFF_TITLE_MARKER_2 "Company:   "
  3106. #define ZIFF_FIRST_LINE_MARKER " *****"
  3107.  
  3108. /* just use the title */
  3109.  
  3110. boolean ziff_separator_function(line)
  3111. char *line;
  3112. {
  3113.   if (strstr(line, ZIFF_FIRST_LINE_MARKER)) {
  3114.     return(true);
  3115.   }
  3116.   else{
  3117.     return(false);
  3118.   }
  3119. }
  3120.  
  3121. char ziff_header[MAX_HEADER_LEN + 1];
  3122.  
  3123. void ziff_header_function(line)
  3124. char *line;
  3125. {
  3126.   if (strstr(line, ZIFF_TITLE_MARKER_1) ||
  3127.       strstr(line, ZIFF_TITLE_MARKER_2))
  3128.     {
  3129.       strncpy(ziff_header, line + strlen(ZIFF_TITLE_MARKER_1), 
  3130.           MAX_HEADER_LEN);
  3131.     }
  3132. }
  3133.  
  3134. void ziff_finish_header_function(header)
  3135. char *header;
  3136. {
  3137.   if(strlen(ziff_header) == 0){
  3138.     strcpy(header, "Unknown Title");
  3139.   }
  3140.   else{
  3141.     s_strncpy(header, ziff_header, MAX_HEADER_LEN);
  3142.   }
  3143.   ziff_header[0] = '\0';
  3144. }
  3145.  
  3146. /* special header function for filename only type */
  3147.  
  3148. void filename_finish_header_function(header)
  3149. char* header;
  3150. {
  3151.   char *p = strrchr(current_filename, '/');
  3152.  
  3153.   if (p != NULL) {
  3154.     p++;
  3155.   } else {
  3156.     p = current_filename;
  3157.   }
  3158.  
  3159.   s_strncpy(header, p, MAX_HEADER_LEN);
  3160. }
  3161.  
  3162. #ifdef BIBDB
  3163. /* ============================
  3164.  * ===  Bibdb Separator  ===
  3165.  * ============================
  3166.  */
  3167.  
  3168.  
  3169. /*
  3170.  * formfedd seperate entries
  3171.  * each page is one entry
  3172.  */
  3173.  
  3174. boolean bibdb_hit_header = 0;
  3175.  
  3176. boolean bibdb_separator_function(line)
  3177. char *line;
  3178. {
  3179.   if((strlen(line) < 3) && substrcmp(line," ")){
  3180.     return(true);
  3181.   }
  3182.   else{
  3183.     return(false);
  3184.   }
  3185. }
  3186.  
  3187. char bibdb_header[MAX_HEADER_LEN + 1];
  3188.  
  3189. void bibdb_header_function(line)
  3190. char *line;
  3191. {
  3192.  
  3193.   /*
  3194.   printf("bibdb_header_function: %s %d %d %d\n", line, bibdb_hit_header,
  3195.          bibdb_separator_function(line), strncmp(line, "CK: ", 4)); 
  3196.          */
  3197.   if((bibdb_hit_header<2)
  3198.      && (!bibdb_separator_function(line)))
  3199.     if (!strncmp(line, "CK: ", 4)) {
  3200.       strncpy(bibdb_header, line+4, MAX_HEADER_LEN);
  3201.       bibdb_hit_header++;
  3202.     } else if (!strncmp(line, "TI: ", 4)) {
  3203.       int i;
  3204.       for (i=0;i<21;i++) if (!bibdb_header[i]) bibdb_header[i]=' ';
  3205.       strncpy(&(bibdb_header[20]), line+4, MAX_HEADER_LEN-21);
  3206.       bibdb_hit_header++;
  3207.     }
  3208. }
  3209.  
  3210. void bibdb_finish_header_function(header)
  3211. char *header;
  3212.  
  3213. {
  3214.   bibdb_hit_header = 0; /* turn on the flag */
  3215.   if (strlen(bibdb_header) == 0) {
  3216.     strcpy(header, "No Title");
  3217.   }
  3218.   else {
  3219.     strncpy(header, bibdb_header, MAX_HEADER_LEN);
  3220.   }
  3221.   bibdb_header[0] = '\0';
  3222. }
  3223.  
  3224. long bgetdate(s)
  3225.      char *s;
  3226. {
  3227.   int year, month, day;
  3228.   sscanf(s,"%2d%2d%2d", &year, &month, &day);
  3229.   return (10000 * year + 100 * month + day);
  3230. }
  3231.  
  3232. long bibdb_date_function(line)
  3233. char *line;
  3234. {
  3235.   if((strlen(line) > strlen("ED: ")) &&
  3236.      substrcmp(line, "ED: ")){
  3237.     return(bgetdate(line+4));
  3238.   }
  3239.   else return -1;
  3240. }
  3241.  
  3242. /* ============================
  3243.  * ===  Formfeed Separator  ===
  3244.  * ============================
  3245.  */
  3246.  
  3247.  
  3248. /*
  3249.  * formfeed-seperate entries
  3250.  * each page is one entry
  3251.  */
  3252.  
  3253. boolean formfeed_hit_header = false;
  3254.  
  3255. boolean formfeed_separator_function(line)
  3256. char *line;
  3257. {
  3258.   if((strlen(line) < 3) && substrcmp(line," ")){
  3259.     /* printf("hit %s\n", line); */
  3260.     return(true);
  3261.   }
  3262.   else{
  3263.     return(false);
  3264.   }
  3265. }
  3266.  
  3267. char formfeed_header[MAX_HEADER_LEN + 1];
  3268.  
  3269. void formfeed_header_function(line)
  3270. char *line;
  3271. {
  3272.   if(formfeed_hit_header
  3273.      && (!formfeed_separator_function(line))
  3274.      && strlen(formfeed_header) == 0) {
  3275.     strncpy(formfeed_header, line, MAX_HEADER_LEN);
  3276.     formfeed_hit_header = false;
  3277.   }
  3278. }
  3279.  
  3280. void formfeed_finish_header_function(header)
  3281. char *header;
  3282.  
  3283. {
  3284.   formfeed_hit_header = true; /* turn on the flag */
  3285.   if (strlen(formfeed_header) == 0) {
  3286.     strcpy(header, "No Title");
  3287.   }
  3288.   else {
  3289.     strncpy(header, formfeed_header, MAX_HEADER_LEN);
  3290.   }
  3291.   formfeed_header[0] = '\0';
  3292. }
  3293.  
  3294.  
  3295.  
  3296. /* ==============================
  3297.  * ===  Bibinf Separator ===
  3298.  * ==============================
  3299.  */
  3300.  
  3301. /* each section is one entry */
  3302.  
  3303. int bibinf_hit_header = 0;
  3304.  
  3305. boolean bibinf_separator_function(line)
  3306. char *line;
  3307. {
  3308.   if((strlen(line) < 3) &&  ((*line == '\n')
  3309.      || (*line == '\0'))) {
  3310.     return(true);
  3311.   }
  3312.   else{
  3313.     return(false);
  3314.   }
  3315. }
  3316.  
  3317. #ifdef SIMPLE_BIBINF
  3318. char bibinf_autor[MAX_HEADER_LEN + 1];
  3319. char bibinf_title[MAX_HEADER_LEN + 1];
  3320.  
  3321. void bibinf_header_function(line)
  3322. char *line;
  3323. {
  3324.  
  3325.   if((bibinf_hit_header<2)
  3326.      && (!bibinf_separator_function(line))) {
  3327.     if (!strncmp(line, "Titel: ", 7)) {
  3328.       strncpy(bibinf_title, line+7, MAX_HEADER_LEN);
  3329.       bibinf_hit_header++;
  3330.     } else if (!strncmp(line, "Autor: ", 7)) {
  3331.       strncpy(bibinf_autor, line+7, MAX_HEADER_LEN);
  3332.       bibinf_hit_header++;
  3333.     }
  3334.   }
  3335. }
  3336. void bibinf_finish_header_function(header)
  3337. char *header;
  3338.  
  3339. {
  3340.   if (bibinf_hit_header == 0) {
  3341.     strcpy(header, "No Title");
  3342.   }
  3343.   else {
  3344.     int i;
  3345.     if (strlen(bibinf_autor)>0) {
  3346.       strncpy(header, bibinf_autor, 25);
  3347.     } else {
  3348.       strncpy(header, "No author given",  25);
  3349.     }
  3350.     for (i=strlen(header);i<MAX_HEADER_LEN;header[i++]=' ');
  3351.     if (strlen(bibinf_title)>0) {
  3352.       strncpy(&(header[26]), bibinf_title, MAX_HEADER_LEN-26);
  3353.     } else {
  3354.       strncpy(&(header[26]), "No title given",  MAX_HEADER_LEN-26);
  3355.     }
  3356.   bibinf_hit_header = 0; /* turn on the flag */
  3357.   }
  3358.   bibinf_autor[0] = '\0';
  3359.   bibinf_title[0] = '\0';
  3360. }
  3361.  
  3362. #else
  3363.  
  3364. char bibinf_header[MAX_HEADER_LEN + 1];
  3365. boolean titel = false;
  3366. boolean autor = false;
  3367. boolean hrsgb = false;
  3368.  
  3369. void bibinf_header_function(line)
  3370. char *line;
  3371. {
  3372.   char *word;
  3373.   char bibinf_header_copy[30];
  3374.   int i;
  3375.  
  3376.   if(bibinf_hit_header            /* begin of Autor-line */
  3377.      && (!bibinf_separator_function(line))
  3378.      && (!strncmp(line, "Autor: ", 7))){
  3379.     s_strncpy(bibinf_header_copy, line+7, 26);
  3380.     word = strtok(bibinf_header_copy," ");
  3381.     while(word){
  3382.       if(isalnum(*word)){
  3383.         trim_trailing_newline(word);
  3384.         s_strncat(bibinf_header,word,26,26);
  3385.         s_strncat(bibinf_header," ",26,26);
  3386.       }
  3387.       else if(word[0] == '|'){
  3388.         bibinf_header[strlen(bibinf_header)-1] = '\0';
  3389.         s_strncat(bibinf_header,"; ",26,26);
  3390.       } 
  3391.       word = strtok(NULL," ");
  3392.     }
  3393.     autor = true;
  3394.   }
  3395.   else if(autor && bibinf_hit_header     /* next words of Autor-line */
  3396.           && (!bibinf_separator_function(line))
  3397.           && (strchr(line, ':') == NULL)){
  3398.     s_strncpy(bibinf_header_copy, line, 26);
  3399.     word = strtok(bibinf_header_copy," ");
  3400.     while(word){
  3401.       if(isalnum(*word)){
  3402.         trim_trailing_newline(word);
  3403.         s_strncat(bibinf_header,word,26,26);
  3404.         s_strncat(bibinf_header," ",26,26);
  3405.       }
  3406.       else if(word[0] == '|'){
  3407.         bibinf_header[strlen(bibinf_header)-1] = '\0';
  3408.         s_strncat(bibinf_header,"; ",26,26);
  3409.       } 
  3410.       word = strtok(NULL," ");
  3411.     }
  3412.   }                            /* end of Autor-line */
  3413.                                /* begin of Herausgeber-line */
  3414.   else if(bibinf_hit_header
  3415.           && (!bibinf_separator_function(line))
  3416.           && (!strncmp(line, "Herausgeber: ", strlen("Herausgeber: ")))){
  3417.     s_strncpy(bibinf_header_copy, line+strlen("Herausgeber: "), 26);
  3418.     word = strtok(bibinf_header_copy," ");
  3419.     while(word){
  3420.       if(isalnum(*word)){
  3421.         trim_trailing_newline(word);
  3422.         s_strncat(bibinf_header,word,26,26);
  3423.         s_strncat(bibinf_header," ",26,26);
  3424.       }
  3425.       else if(word[0] == '|'){
  3426.         bibinf_header[strlen(bibinf_header)-1] = '\0';
  3427.         s_strncat(bibinf_header,"; ",26,26);
  3428.       }
  3429.       word = strtok(NULL," ");
  3430.     }
  3431.     hrsgb = true;
  3432.   }
  3433.   else if(hrsgb && bibinf_hit_header      /* next words of Hrsgb-line */
  3434.           && (!bibinf_separator_function(line))
  3435.           && (strchr(line, ':') == NULL)){
  3436.     s_strncpy(bibinf_header_copy, line, 26);
  3437.     word = strtok(bibinf_header_copy," ");
  3438.     while(word){
  3439.       if(isalnum(*word)){
  3440.         trim_trailing_newline(word);
  3441.         s_strncat(bibinf_header,word,26,26);
  3442.         s_strncat(bibinf_header," ",26,26);
  3443.       }
  3444.       else if(word[0] == '|'){
  3445.         bibinf_header[strlen(bibinf_header)-1] = '\0';
  3446.         s_strncat(bibinf_header,"; ",26,26);
  3447.       } 
  3448.       word = strtok(NULL," ");
  3449.     }
  3450.   }                       /* end of Hrsgb-line */
  3451.  
  3452.   else if(bibinf_hit_header          /* begin of Titel-line */
  3453.           && (!bibinf_separator_function(line))
  3454.           && (!strncmp(line, "Titel: ", 7))) {
  3455.     autor = false;
  3456.     hrsgb = false;
  3457.     for(i=strlen(bibinf_header); i < 25; i++)
  3458.       s_strncat(bibinf_header," ",MAX_HEADER_LEN,MAX_HEADER_LEN);
  3459.     s_strncat(bibinf_header,": ",MAX_HEADER_LEN,MAX_HEADER_LEN);
  3460.     s_strncat(bibinf_header, line+7,MAX_HEADER_LEN,MAX_HEADER_LEN);
  3461.     titel = true;
  3462.   }
  3463.   else if                           /* next words of Titel-line */
  3464.     (titel && bibinf_hit_header
  3465.      && (!bibinf_separator_function(line))
  3466.      && (strchr(line, ':') == NULL)){
  3467.       trim_trailing_newline(bibinf_header);
  3468.       for(i=strlen(bibinf_header) - 1; isspace(bibinf_header[i]); i--)
  3469.         bibinf_header[i] = '\0'; 
  3470.       s_strncat(bibinf_header," ",MAX_HEADER_LEN,MAX_HEADER_LEN);
  3471.       s_strncat(bibinf_header,line,MAX_HEADER_LEN,MAX_HEADER_LEN);
  3472.       if(strlen(bibinf_header) == MAX_HEADER_LEN -1)
  3473.         bibinf_header[MAX_HEADER_LEN-2] = '\n'; 
  3474.     }
  3475.   else if
  3476.     (titel && bibinf_hit_header
  3477.      && (!bibinf_separator_function(line))
  3478.      && (strchr(line, ':') != NULL)){
  3479.       titel = false;
  3480.       bibinf_hit_header = false; 
  3481.     }
  3482.   else if (titel){
  3483.     titel = false;
  3484.     bibinf_hit_header = false;     
  3485.   }
  3486. }
  3487.  
  3488. void bibinf_finish_header_function(header)
  3489. char *header;
  3490.  
  3491. {
  3492.   bibinf_hit_header = true; /* turn on the flag */
  3493.   if (strlen(bibinf_header) == 0) {
  3494.     strcpy(header, "No Title");
  3495.   }
  3496.   else {
  3497.     strncpy(header, bibinf_header, MAX_HEADER_LEN);
  3498. /*    s_strncpy(header, bibinf_header,60);
  3499.     if(header[strlen(header)-1] != '\n')
  3500.       strcat(header,"...\n"); */
  3501.   }
  3502.   bibinf_header[0] = '\0';
  3503. }
  3504.  
  3505.  
  3506. #endif /* SIMPLE_BIBINF */
  3507.  
  3508. long binfgetdate(s)
  3509.      char *s;
  3510. {
  3511.   int year, month, day;
  3512.  
  3513.   sscanf(s, "%4d-%2d-%2d", &year, &month, &day);
  3514.   return (10000 * (year - 1900) + 100 * month + day);
  3515. }
  3516.  
  3517. long bibinf_date_function(line)
  3518. char *line;
  3519. {
  3520.   if((strlen(line) > strlen("Erfasst: ")) &&
  3521.      substrcmp(line, "Erfasst: ")){
  3522.     return(binfgetdate(line+9));
  3523.   }
  3524.   else return -1;
  3525. }
  3526.   
  3527.  
  3528. /* ========================================
  3529.  * ===  Irlist Digest Customizations     ====
  3530.  * ========================================
  3531.  */
  3532.  
  3533. boolean irlist_separator_function(line)
  3534. char *line;
  3535. {
  3536.   if (mail_or_rmail_separator(line)) return(true);
  3537.   
  3538.   if((strlen(line) > strlen("*********")) &&
  3539.      substrcmp(line, "**********")){
  3540.     return(true);
  3541.   }
  3542.   else{
  3543.     return(false);
  3544.   }
  3545. }
  3546.  
  3547. void irlist_header_function(line)
  3548. char *line;
  3549. {
  3550.   if((strlen(line) > strlen("Re: ")) &&
  3551.      substrcmp(line, "Re: ") &&
  3552.      (strlen(mail_subject) == 0)){
  3553.     strcpy(mail_subject, "Re: ");
  3554.     s_strncat(mail_subject, line + strlen("Re: "), MAX_HEADER_LEN, MAX_HEADER_LEN);
  3555.     trim_trailing_newline(mail_subject);
  3556.   }
  3557.   else if((strlen(line) > strlen("Fr: ")) &&
  3558.      substrcmp(line, "Fr: ") &&
  3559.      (strlen(mail_from) == 0)){
  3560.     /* this should find the <foo@bar> field in the from list */
  3561.     strncpy(mail_from, line + strlen("Fr: "), MAX_HEADER_LEN);
  3562.     trim_trailing_newline(mail_from);
  3563.   }
  3564.   else mail_header_function(line);
  3565. }
  3566.  
  3567. long irlist_date_function(line)
  3568. char *line;
  3569. {
  3570.   static long last_date = 0;
  3571.   long this_date;
  3572.   
  3573.   if ((this_date = mail_date_function(line)) > 0)
  3574.     return(last_date = this_date);
  3575.   else
  3576.     return(last_date);
  3577. }
  3578.  
  3579. #endif
  3580.  
  3581. #ifdef STELAR
  3582.  
  3583. /*=================================
  3584.  *
  3585.  *      STELAR Abstracts
  3586.  *
  3587.  *=================================*/
  3588. char stelar_header[MAX_HEADER_LEN+1];
  3589.  
  3590. boolean stelar_separator_function(line)
  3591.      char *line;
  3592. {
  3593.   return(false);
  3594. }
  3595.  
  3596. void stelar_header_function(line)
  3597.      char *line;
  3598. {
  3599.   char *p;
  3600.  
  3601.   if(stelar_header[0]=='\0' && isspace(line[0]) && strlen(line)>3){
  3602.     p=line;
  3603.     while(isspace(*p)) ++p;
  3604.     strncpy(stelar_header,p,MAX_HEADER_LEN);
  3605.   }
  3606. }
  3607.  
  3608. void stelar_finish_header_function(header)
  3609.      char *header;
  3610. {
  3611.   if(strlen(stelar_header)==0){
  3612.     strcpy(header,"No Title");
  3613.   } else {
  3614.     strncpy(header,stelar_header,MAX_HEADER_LEN);
  3615.   }
  3616.   stelar_header[0]='\0';
  3617. }
  3618. #endif /* STELAR */
  3619. /*=================================
  3620.  *
  3621.  *      AAS Meeting Abstracts
  3622.  *      (using AAS abstract LaTeX macros)
  3623.  *
  3624.  *=================================*/
  3625. #ifdef AAS
  3626.  
  3627. #define AASAB_TITLE_MARKER "\\title{"
  3628. #define AASAB_AUTHOR_MARKER "\\author{"
  3629.  
  3630. char aasab_header[MAX_HEADER_LEN+1];
  3631. char aasab_author[MAX_HEADER_LEN+1];
  3632. char aasab_title[MAX_HEADER_LEN+1];
  3633.  
  3634. boolean aasab_separator_function(line)
  3635.      char *line;
  3636. {
  3637.   if ((strlen(line) > strlen("\\documentstyle["))
  3638.       && (substrcmp(line, "aasab"))) {
  3639.     return(true);
  3640.   } else {
  3641.     return(false);
  3642.   }
  3643. }
  3644.  
  3645. void aasab_header_function(line)
  3646.      char *line;
  3647. {
  3648.   char *aas_start;
  3649.   if (aas_start = strstr(line, AASAB_TITLE_MARKER)) {
  3650.     s_strncpy( aasab_title, aas_start+strlen(AASAB_TITLE_MARKER), MAX_HEADER_LEN);
  3651.   } else
  3652.     if (aas_start = strstr(line, AASAB_AUTHOR_MARKER)) {
  3653.       s_strncpy( aasab_author, aas_start+strlen(AASAB_AUTHOR_MARKER), MAX_HEADER_LEN);
  3654.     }
  3655. }
  3656.  
  3657. void aasab_finish_header_function(line)
  3658.      char *line;
  3659. {
  3660.   int nchars;
  3661.   char *p = strrchr(current_filename, '/');
  3662.  
  3663.   if (strlen(aasab_title) == 0) {
  3664.     strcpy( line, "Unknown Title");
  3665.   } else {
  3666.     nchars = 0;
  3667.     while ((nchars < 20) && (aasab_author[nchars] != '}')) {
  3668.       aasab_header[nchars] = aasab_author[nchars];
  3669.       nchars++;
  3670.     }
  3671.     aasab_header[nchars] = '\0';
  3672.  
  3673.     if (p != NULL) {
  3674.       p++;
  3675.     } else {
  3676.       p = current_filename;
  3677.     }
  3678.  
  3679.     s_strncpy( line, p, MAX_HEADER_LEN);
  3680.     s_strncat( line, " ", strlen(" "), MAX_HEADER_LEN);
  3681.     s_strncat( aasab_header, "<> RE: ", strlen("<> RE: "), MAX_HEADER_LEN);
  3682.     s_strncat( aasab_header, aasab_title, MAX_HEADER_LEN, MAX_HEADER_LEN);
  3683.     s_strncat( line, aasab_header, MAX_HEADER_LEN, MAX_HEADER_LEN);
  3684.   }
  3685.   aasab_title[0] = '\0';
  3686. }
  3687.  
  3688. #endif /* AAS */
  3689.  
  3690.  
  3691. char *URL_prefix=NULL;
  3692. char *URL_trim=NULL;
  3693.  
  3694. #ifdef HTML                                                                                  
  3695. /* David J. Bianco <bianco@cs.odu.edu> */
  3696.  
  3697. char html_header[MAX_HEADER_LEN + 1];                                                        
  3698. static int html_title_found = 0;                                                             
  3699. #ifdef WIN32
  3700. #define MAX_LINE_LENGTH 1000
  3701. #endif
  3702.  
  3703. void html_header_function(line)                                                              
  3704. char *line;                                                                                  
  3705. {                                                                                            
  3706. #ifdef WIN32
  3707. char conv_line[MAX_LINE_LENGTH];                                                                      
  3708. #else
  3709. char conv_line[BUFSIZ];                                                                      
  3710. #endif
  3711. int linkflag = 0,i;                                                                          
  3712. char * begin, * end;                                                                         
  3713.                                                                                              
  3714. /* convert entities to lower case to simplify comparisons */                                 
  3715. #ifdef WIN32
  3716.   for(i=0;i <= (int)strlen(line);i++) {                                                           
  3717. #else
  3718.   for(i=0;i <= strlen(line);i++) {                                                           
  3719. #endif
  3720.     if(line[i] == '<') {                                                                     
  3721.   linkflag = 1;                                                                              
  3722.     } else if(line[i] == '>') {                                                              
  3723.   linkflag = 0;                                                                              
  3724.     }                                                                                        
  3725.     if(linkflag == 1) {                                                                      
  3726.   conv_line[i] = tolower(line[i]);                                                           
  3727.     } else conv_line[i] = line[i];                                                           
  3728.   }                                                                                          
  3729.                                                                                              
  3730.   begin = strstr(conv_line, "<title>");                                                      
  3731.   end = strstr(conv_line, "</title>");                                                       
  3732.                                                                                              
  3733.   if(begin != NULL)                                                                          
  3734.   html_title_found = 1;                                                                      
  3735.                                                                                              
  3736.   if((begin == NULL) && (html_title_found == 0)) {                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
  3737.     return;                                                                                  
  3738.   }                                                                                          
  3739.                                                                                              
  3740.   if((begin == NULL) && (html_title_found == 1)) {                                           
  3741.     begin = conv_line;                                                                       
  3742.   }                                                                                          
  3743.                                                                                              
  3744.   if((end != NULL) && (strncmp(end, "</title>", 8) == 0)) {                                  
  3745.     html_title_found = 0;                                                                    
  3746.   }                                                                                          
  3747.   if(strncmp(begin, "<title>", 7) == 0) {                                                    
  3748.     begin += 7;                                                                              
  3749.   }                                                                                          
  3750.   if(end == NULL){                                                                           
  3751.     end = &(conv_line[strlen(conv_line) + 1]);                                               
  3752.   }                                                                                          
  3753.                                                                                              
  3754.   *end = '\0';                                                                               
  3755.   strcat(html_header, begin);                                                                
  3756. }                                                                                            
  3757.                                                                                              
  3758. void html_finish_header_function(header)                                                     
  3759. char *header;                                                                                
  3760. {                                                                                            
  3761.   if(strlen(html_header) == 0){                                                              
  3762.     strcpy(header, "Untitled HTML Document");                                                
  3763.   }                                                                                          
  3764.   else{                                                                                      
  3765.     s_strncpy(header, html_header, MAX_HEADER_LEN);                                          
  3766.   }                                                                                          
  3767.   html_header[0] = '\0';                                                                     
  3768. }                                                                                            
  3769. #endif /* HTML */                                                                            
  3770.  
  3771.                                                                                                                                                                                                                                                                                                                                                                                                                                                 
  3772.