home *** CD-ROM | disk | FTP | other *** search
/ ftp.uv.es / 2014.11.ftp.uv.es.tar / ftp.uv.es / pub / unix / freeWAIS-0.202.tar.gz / freeWAIS-0.202.tar / freeWAIS-0.202 / ir / irfiles.h < prev    next >
C/C++ Source or Header  |  1993-10-05  |  9KB  |  285 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.  * $Log: irfiles.h,v $
  8.  * Revision 1.1  1993/02/16  15:05:35  freewais
  9.  * Initial revision
  10.  *
  11.  * Revision 1.19  92/04/16  20:04:44  morris
  12.  * small fix to dictionary_blockword_occurances, lenght read was
  13.  * NEXT_INDEX_BLOCK_SIZE, now its NUMBR_OF_OCCURANCES_SIZE.
  14.  * 
  15.  * Revision 1.18  92/03/19  09:34:08  morris
  16.  * fixed the dictionary header to accurately indicate the number of blocks
  17.  * 
  18.  * Revision 1.17  92/02/17  12:38:00  jonathan
  19.  * Added defines for catalog.
  20.  * 
  21.  */
  22.  
  23. /* Copyright (c) CNIDR (see ../COPYRIGHT) */
  24.  
  25.  
  26. /* include file for irfiles.c */
  27.  
  28. #ifndef IRFILES_H
  29. #define IRFILES_H
  30.  
  31. #include "cdialect.h"
  32. #include "cutil.h"
  33. #include "hash.h"
  34. #include "ustubs.h" /* for time_t */
  35. #include "synonym.h"
  36.  
  37. /* filename extensions for various components */
  38. #define dictionary_ext            ".dct"
  39. #define filename_table_ext        ".fn"
  40. #define headline_table_ext        ".hl"
  41. #define document_table_ext        ".doc"
  42. #define index_ext            ".inv"
  43. #define source_ext             ".src"
  44. #define catalog_ext             ".cat"
  45. #define synonym_ext            ".syn"
  46. #ifdef BIO
  47. #define delimiters_ext    ".dlm"        /* dgg */
  48. #endif
  49.  
  50. /* these dictionary definitions are used in irhash,irverify, and irfiles */
  51. #define DICTIONARY_HEADER_SIZE 4
  52. #define DICTIONARY_BLOCK_SIZE 1000L  /* in entries, not bytes */
  53. #define DICTIONARY_ENTRY_HASH_CODE_SIZE 2
  54. /* #define DICTIONARY_ENTRY_COUNT_SIZE 3  moved to inverted file */
  55. /* #define DICTIONARY_ENTRY_INDEX_BLOCK_SIZE 4 not used and too long a symbol*/
  56. /* #define DICTIONARY_ELEMENT_SIZE 6 was 9 */
  57. #define DICTIONARY_SIZE 524288L
  58. #define DICTIONARY_TOTAL_SIZE_WORD "{}" /* the word that holds the total number of words in the whole dictionary */
  59.  
  60. #define INDEX_HEADER_SIZE 4
  61. #ifdef BIO
  62.  
  63. /* !! Bug in W8B5 -- Increasing this INDEX_BLOCK_SIZE_SIZE above 2 now fails !! */
  64. /* it worked in W8B3 ... both 3 and 4 fail now */
  65. #define INDEX_BLOCK_SIZE_SIZE 2  /* was 2, genbank wants 3, dgg */
  66.  
  67. #else
  68. #define INDEX_BLOCK_SIZE_SIZE 2
  69. #endif
  70.  
  71. #define NEXT_INDEX_BLOCK_SIZE 4
  72. #define INDEX_BLOCK_FLAG_SIZE 1
  73.  
  74. /* dgg -- this is a bug 
  75. #define INDEX_BLOCK_HEADER_SIZE 7
  76. This == 7 only if the component SIZEs don't change
  77. */
  78. #define INDEX_BLOCK_HEADER_SIZE (INDEX_BLOCK_SIZE_SIZE+NEXT_INDEX_BLOCK_SIZE+INDEX_BLOCK_FLAG_SIZE)
  79.  
  80.  
  81. #define NUMBER_OF_OCCURANCES_SIZE 4
  82. #define INDEX_BLOCK_NOT_FULL_FLAG 101
  83. #define INDEX_BLOCK_FULL_FLAG 69
  84. #define INDEX_BLOCK_DICTIONARY_FLAG 123
  85.  
  86. #define DOCUMENT_ID_SIZE 4
  87. #define WORD_POSITION_SIZE 0
  88. #define CHARACTER_POSITION_SIZE 3
  89. #define WEIGHT_SIZE 1
  90. #define INDEX_ELEMENT_SIZE 8
  91. #define WORD_ID_SIZE 4 /* for posting arrays */
  92.  
  93. #ifdef BOOLEANS            /* dgg */
  94. #define BOOLEAN_AND    "and"    /* may prefer "&", but need symbol fix */
  95. #define BOOLEAN_NOT "not"    /* may prefer "!", but need symbol fix */
  96. #define BOOLEAN_NOT_FLAG -91    /* stick in weight param as flag for search_word */
  97. #endif
  98.  
  99. #ifdef PARTIALWORD        /* dgg */
  100. #define PARTWORD_WILDCARD  '*'        
  101. #endif
  102.  
  103. #ifdef LITERAL            /* dgg */
  104. #define LITERAL_KEY1    '"'    
  105. #define LITERAL_KEY2    0x27    /* single quote ' dgg */
  106. #define LITERAL_FLAG    -92    /* stick in weight param as flag for search_word */
  107. #define MAX_PHRASE_LENGTH  200
  108. #endif
  109.  
  110.  
  111. typedef struct database {
  112.     char*    database_file;
  113.     FILE*    dictionary_stream;
  114.     FILE*    filename_table_stream;
  115.     FILE*    headline_table_stream;
  116.     FILE*    document_table_stream;
  117.     FILE*    index_stream;
  118. #ifdef BIO
  119.     FILE*    delimiters_stream;
  120. #endif
  121.   long    doc_table_allocated_entries;
  122.     hashtable* the_word_memory_hashtable;
  123.  
  124.     long     number_of_words_in_hashtable; /* for building.
  125.                          checked on every add_word.
  126.                            set at start of building,
  127.                            and on every flush.*/
  128.     long     flush_after_n_words; /* set at the start of building used
  129.                     to compare with 
  130.                     number_of_words_in_hashtable. */
  131.     long     number_of_words; /* for building.  number of different words.
  132.                     Set from the headers of .inv files
  133.                     as they are merged. 
  134.                     It is used to set the header when a .inv 
  135.                     file is first created (not by merging).
  136.                     */
  137.     long    index_file_number; /* for building. */
  138.     long    total_word_count; /* Total number of word occurances.
  139.                      set during indexing, saved in 
  140.                      dictionary under 'ALL' entry */
  141.     void*   ext_database;
  142.  t_Synonym* syn_Table;       /* synonym index lookup table */
  143.         int     syn_Table_Size;     /* number of entries in synonym table */
  144. } database;
  145.  
  146. typedef struct document_table_entry {
  147.     long    filename_id;
  148.     long    headline_id;
  149.     long    source_id;    /* for signature system */
  150.     long    start_character;
  151.     long    end_character;
  152.     long     document_length; /* in characters */
  153.     long    number_of_lines; /* in lines */
  154.     time_t  date;            /* 0 if unknown */
  155. } document_table_entry;
  156.  
  157. #ifdef __cplusplus
  158. /* declare these as C style functions */
  159. extern "C"
  160.     {
  161. #endif /* def __cplusplus */
  162.  
  163. database*     openDatabase _AP((char* name, boolean initialize,boolean for_search));
  164. void        closeDatabase _AP((database* the_db));
  165. void        disposeDatabase _AP((database* the_db));
  166.  
  167. void initialize_index_files _AP((database* db));
  168.  
  169. char *read_filename_table_entry _AP((long position, 
  170.                   char* filename,
  171.                   char* type, 
  172.                   time_t* file_write_date,
  173.                   database* db));
  174.  
  175. long write_filename_table_entry _AP((char* filename, char *type, database* db));
  176. boolean filename_in_database _AP((char *filename, char *type,
  177.                   time_t *write_file_date, database *db));
  178. boolean filename_in_filename_file _AP ((char *filename, char*type,
  179.                   time_t *file_write_date, 
  180.                   char* filename_file));
  181. char *read_headline_table_entry _AP((long position,database* db));
  182. long write_headline_table_entry _AP((char* headline, database* db));
  183.  
  184. #ifdef BIO
  185. char *read_delimiters _AP((database* db));
  186. long write_delimiters _AP((char* delimiters, database* db));
  187. #endif
  188.  
  189. boolean read_document_table_entry 
  190.   _AP((document_table_entry* doc_entry,long number,database* db));
  191.  
  192. long write_document_table_entry
  193.   _AP((document_table_entry* doc_table_entry, database* db));
  194.  
  195. boolean writeUserValToDocIDTable _AP((unsigned long userVal,long doc,
  196.                       database* db));
  197.  
  198.  
  199. long next_document_id _AP((database* db));
  200.  
  201.  
  202. void close_dictionary_file _AP((database *db));
  203.  
  204. long add_word_to_dictionary
  205.      _AP((char *word, long index_file_block_number, long number_of_occurances,
  206.      database* db));
  207. #ifdef PARTIALWORD
  208. long look_up_partialword_in_dictionary _AP((char *word, long *word_id, database* db));
  209. #endif
  210. long look_up_word_in_dictionary _AP((char *word, long *word_id, database* db));
  211. long init_dict_file_for_writing _AP((database *db));
  212. void init_dict_file_detailed _AP((FILE* dictionary_stream,
  213.                   long number_of_blocks));
  214. void record_num_blocks_in_dict _AP((FILE* dictionary_stream,
  215.                     long number_of_words));
  216.  
  217. long finished_add_word_to_dictionary _AP((database *db));
  218.  
  219. boolean register_src_structure _AP((char *filename));
  220. boolean write_src_structure _AP((char *filename, 
  221.                  char *database_name, 
  222.                  char *typename,
  223.                  char **filenames, 
  224.                  long number_of_filename,
  225.                  boolean export_database,
  226.                  long tcp_port));
  227.  
  228. boolean build_catalog _AP((database* db));
  229.  
  230. long allocate_index_block _AP((long how_large, FILE* stream));
  231.  
  232. unsigned char *read_dictionary_block _AP((unsigned char* block,
  233.                       long position,long length,
  234.                       FILE* stream));
  235.                                       
  236. void print_dictionary _AP((database* db));
  237.  
  238. #define DICTIONARY_ENTRY_SIZE 29 /* sum of MAX_WORD_LENGTH, 1 ('\0'), 
  239.                     NEXT_INDEX_BLOCK_SIZE and
  240.                     NUMBER_OF_OCCURANCES_SIZE */
  241.  
  242.  
  243. #ifdef DICT_FUNC
  244.  
  245. char *dictionary_block_word _AP((long i,unsigned char* block));
  246. long dictionary_block_position _AP((long i,unsigned char* block));
  247. long dictionary_block_word_occurances _AP((long i,unsigned char* block));
  248.  
  249. #else /* macros */
  250.  
  251. #define dictionary_block_word(i,block) \
  252.   ((char *)((block) + ((i) * DICTIONARY_ENTRY_SIZE)))
  253.  
  254. #define dictionary_block_position(i,block) \
  255.   read_bytes_from_memory(NEXT_INDEX_BLOCK_SIZE, \
  256.              (block) + ((i) * DICTIONARY_ENTRY_SIZE) + \
  257.               MAX_WORD_LENGTH + 1)
  258.  
  259. #define dictionary_block_word_occurances(i,block) \
  260.   read_bytes_from_memory(NUMBER_OF_OCCURANCES_SIZE, \
  261.                          (block) + ((i) * DICTIONARY_ENTRY_SIZE) + \
  262.                          MAX_WORD_LENGTH + 1 + NEXT_INDEX_BLOCK_SIZE)
  263. #endif
  264.  
  265. void print_dictionary_block _AP((unsigned char* block,long size));
  266.  
  267. /* database functions */
  268. char* dictionary_filename _AP((char* destination, database* db));
  269. char* filename_table_filename _AP((char* destination, database* db));
  270. char* headline_table_filename _AP((char* destination, database* db));
  271. char* document_table_filename _AP((char* destination, database* db));
  272. char* index_filename _AP((char* destination, database* db));
  273. char* index_filename_with_version _AP((long version, char* destination, 
  274.                   database* db));
  275. char* source_filename _AP((char* destination, database* db));
  276. #ifdef BIO
  277. char* delimiters_filename _AP((char* destination, database* db));
  278. #endif
  279.  
  280. #ifdef __cplusplus
  281.     }
  282. #endif /* def __cplusplus */
  283.  
  284. #endif /* IRFILES_H */
  285.