[3745] | 1 | /**************************************************************************
|
---|
| 2 | *
|
---|
| 3 | * mg_files.h -- Routines for handling files for the auxillary programs
|
---|
| 4 | * Copyright (C) 1994 Neil Sharman
|
---|
| 5 | *
|
---|
| 6 | * This program is free software; you can redistribute it and/or modify
|
---|
| 7 | * it under the terms of the GNU General Public License as published by
|
---|
| 8 | * the Free Software Foundation; either version 2 of the License, or
|
---|
| 9 | * (at your option) any later version.
|
---|
| 10 | *
|
---|
| 11 | * This program is distributed in the hope that it will be useful,
|
---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 14 | * GNU General Public License for more details.
|
---|
| 15 | *
|
---|
| 16 | * You should have received a copy of the GNU General Public License
|
---|
| 17 | * along with this program; if not, write to the Free Software
|
---|
| 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 19 | *
|
---|
| 20 | * $Id: mg_files.h 25147 2012-02-28 00:59:00Z kjdon $
|
---|
| 21 | *
|
---|
| 22 | **************************************************************************/
|
---|
| 23 |
|
---|
| 24 | #ifndef MG_FILES_H
|
---|
| 25 | #define MG_FILES_H
|
---|
| 26 |
|
---|
| 27 | #include "sysfuncs.h"
|
---|
| 28 |
|
---|
| 29 | /* Magic numbers for the different types of files */
|
---|
| 30 |
|
---|
[25147] | 31 | #define GEN_MAGIC(a,b,c,d) ((mg_u_long)(((a)<<24) + ((b)<<16) + \
|
---|
[3745] | 32 | ((c)<<8) + (d)))
|
---|
| 33 |
|
---|
| 34 | #define MAGIC_XXXX GEN_MAGIC('M','G', 0 , 0)
|
---|
| 35 | #define MAGIC_STATS_DICT GEN_MAGIC('M','G','S','D')
|
---|
| 36 | #define MAGIC_AUX_DICT GEN_MAGIC('M','G','A','D')
|
---|
| 37 | #define MAGIC_FAST_DICT GEN_MAGIC('M','G','F','D')
|
---|
| 38 | #define MAGIC_DICT GEN_MAGIC('M','G','D', 0 )
|
---|
| 39 | #define MAGIC_STEM_BUILD GEN_MAGIC('M','G','S', 0 )
|
---|
| 40 | #define MAGIC_HASH GEN_MAGIC('M','G','H', 0 )
|
---|
| 41 | #define MAGIC_STEM GEN_MAGIC('M','G','s', 0 )
|
---|
| 42 | #define MAGIC_CHUNK GEN_MAGIC('M','G','C', 0 )
|
---|
| 43 | #define MAGIC_CHUNK_TRANS GEN_MAGIC('M','G','c', 0 )
|
---|
| 44 | #define MAGIC_TEXT GEN_MAGIC('M','G','T', 0 )
|
---|
| 45 | #define MAGIC_TEXI GEN_MAGIC('M','G','t', 0 )
|
---|
| 46 | #define MAGIC_TEXI_WGT GEN_MAGIC('M','G','t','W')
|
---|
| 47 | #define MAGIC_INVF GEN_MAGIC('M','G','I', 0 )
|
---|
| 48 | #define MAGIC_INVI GEN_MAGIC('M','G','i', 0 )
|
---|
| 49 | #define MAGIC_WGHT GEN_MAGIC('M','G','W', 0 )
|
---|
| 50 | #define MAGIC_WGHT_APPROX GEN_MAGIC('M','G','w', 0 )
|
---|
| 51 | #define MAGIC_PARAGRAPH GEN_MAGIC('M','G','P', 0 )
|
---|
| 52 | /* [RPAP - Jan 97: Stem Index Change] */
|
---|
| 53 | #define MAGIC_STEM_1 GEN_MAGIC('M','G','s','1')
|
---|
| 54 | #define MAGIC_STEM_2 GEN_MAGIC('M','G','s','2')
|
---|
| 55 | #define MAGIC_STEM_3 GEN_MAGIC('M','G','s','3')
|
---|
| 56 |
|
---|
[25147] | 57 | #define IS_MAGIC(a) ((((mg_u_long)(a)) & 0xffff0000) == MAGIC_XXXX)
|
---|
[3745] | 58 |
|
---|
| 59 |
|
---|
| 60 | /* err_mode values for open_file and create_file */
|
---|
| 61 | #define MG_ABORT 0
|
---|
| 62 | #define MG_MESSAGE 1
|
---|
| 63 | #define MG_CONTINUE 2
|
---|
| 64 |
|
---|
| 65 |
|
---|
| 66 |
|
---|
| 67 |
|
---|
| 68 |
|
---|
| 69 | /* File suffixes */
|
---|
| 70 |
|
---|
| 71 |
|
---|
| 72 | /* The compression dictionary built by txt.pass1 */
|
---|
| 73 | #ifdef SHORT_SUFFIX
|
---|
| 74 | # define TEXT_STATS_DICT_SUFFIX ".tsd"
|
---|
| 75 | #else
|
---|
| 76 | # define TEXT_STATS_DICT_SUFFIX ".text.stats"
|
---|
| 77 | #endif
|
---|
| 78 |
|
---|
| 79 | /* The compression dictionary built by text.pass1 and comp_dict.process */
|
---|
| 80 | #ifdef SHORT_SUFFIX
|
---|
| 81 | # define TEXT_DICT_SUFFIX ".td"
|
---|
| 82 | #else
|
---|
| 83 | # define TEXT_DICT_SUFFIX ".text.dict"
|
---|
| 84 | #endif
|
---|
| 85 |
|
---|
| 86 | /* The compression dictionary built by mg_make_fast_dict */
|
---|
| 87 | #ifdef SHORT_SUFFIX
|
---|
| 88 | # define TEXT_DICT_FAST_SUFFIX ".tdf"
|
---|
| 89 | #else
|
---|
| 90 | # define TEXT_DICT_FAST_SUFFIX ".text.dict.fast"
|
---|
| 91 | #endif
|
---|
| 92 |
|
---|
| 93 | /* The auxilary dictionary built by text.pass2 */
|
---|
| 94 | #ifdef SHORT_SUFFIX
|
---|
| 95 | # define TEXT_DICT_AUX_SUFFIX ".tda"
|
---|
| 96 | #else
|
---|
| 97 | # define TEXT_DICT_AUX_SUFFIX ".text.dict.aux"
|
---|
| 98 | #endif
|
---|
| 99 |
|
---|
| 100 | /* The compressed text build by text.pass2 */
|
---|
| 101 | #ifdef SHORT_SUFFIX
|
---|
| 102 | # define TEXT_SUFFIX ".t"
|
---|
| 103 | #else
|
---|
| 104 | # define TEXT_SUFFIX ".text"
|
---|
| 105 | #endif
|
---|
| 106 |
|
---|
| 107 | /* The combined compressed text index and document weight file */
|
---|
| 108 | #ifdef SHORT_SUFFIX
|
---|
| 109 | # define TEXT_IDX_WGT_SUFFIX ".tiw"
|
---|
| 110 | #else
|
---|
| 111 | # define TEXT_IDX_WGT_SUFFIX ".text.idx.wgt"
|
---|
| 112 | #endif
|
---|
| 113 |
|
---|
| 114 | /* The compressed text index file */
|
---|
| 115 | #ifdef SHORT_SUFFIX
|
---|
| 116 | # define TEXT_IDX_SUFFIX ".ti"
|
---|
| 117 | #else
|
---|
| 118 | # define TEXT_IDX_SUFFIX ".text.idx"
|
---|
| 119 | #endif
|
---|
| 120 |
|
---|
| 121 | /* The dictionary of stemmed words build by invf.pass1 and ivf.pass1 */
|
---|
| 122 | #ifdef SHORT_SUFFIX
|
---|
| 123 | # define INVF_DICT_SUFFIX ".id"
|
---|
| 124 | #else
|
---|
| 125 | # define INVF_DICT_SUFFIX ".invf.dict"
|
---|
| 126 | #endif
|
---|
| 127 |
|
---|
| 128 | /* The dictionary of stemmed words build by stem.process */
|
---|
| 129 | #ifdef SHORT_SUFFIX
|
---|
| 130 | # define INVF_DICT_BLOCKED_SUFFIX ".idb"
|
---|
| 131 | #else
|
---|
| 132 | # define INVF_DICT_BLOCKED_SUFFIX ".invf.dict.blocked"
|
---|
| 133 | #endif
|
---|
| 134 |
|
---|
| 135 | /* The exact document weights file build by make.weights, invf.pass2,
|
---|
| 136 | or ivf.pass2 */
|
---|
| 137 | #ifdef SHORT_SUFFIX
|
---|
| 138 | # define WEIGHTS_SUFFIX ".w"
|
---|
| 139 | #else
|
---|
| 140 | # define WEIGHTS_SUFFIX ".weight"
|
---|
| 141 | #endif
|
---|
| 142 |
|
---|
| 143 | /* The approximate weights file built by make.weights */
|
---|
| 144 | #ifdef SHORT_SUFFIX
|
---|
| 145 | # define APPROX_WEIGHTS_SUFFIX ".wa"
|
---|
| 146 | #else
|
---|
| 147 | # define APPROX_WEIGHTS_SUFFIX ".weight.approx"
|
---|
| 148 | #endif
|
---|
| 149 |
|
---|
| 150 | /* The inverted file build by invf.pass2 or ivf.pass2 */
|
---|
| 151 | #ifdef SHORT_SUFFIX
|
---|
| 152 | # define INVF_SUFFIX ".i"
|
---|
| 153 | #else
|
---|
| 154 | # define INVF_SUFFIX ".invf"
|
---|
| 155 | #endif
|
---|
| 156 |
|
---|
| 157 | /* The inverted file index build by invf.pass2 or ivf.pass2 */
|
---|
| 158 | #ifdef SHORT_SUFFIX
|
---|
| 159 | # define INVF_IDX_SUFFIX ".ii"
|
---|
| 160 | #else
|
---|
| 161 | # define INVF_IDX_SUFFIX ".invf.idx"
|
---|
| 162 | #endif
|
---|
| 163 |
|
---|
| 164 | /* The inverted file chunk descriptor built by ivf.pass1 */
|
---|
| 165 | #ifdef SHORT_SUFFIX
|
---|
| 166 | # define INVF_CHUNK_SUFFIX ".ic"
|
---|
| 167 | #else
|
---|
| 168 | # define INVF_CHUNK_SUFFIX ".invf.chunk"
|
---|
| 169 | #endif
|
---|
| 170 |
|
---|
| 171 | /* The word index translation file built by ivf.pass1 */
|
---|
| 172 | #ifdef SHORT_SUFFIX
|
---|
| 173 | # define INVF_CHUNK_TRANS_SUFFIX ".ict"
|
---|
| 174 | #else
|
---|
| 175 | # define INVF_CHUNK_TRANS_SUFFIX ".invf.chunk.trans"
|
---|
| 176 | #endif
|
---|
| 177 |
|
---|
| 178 | /* The hashed stemmed dictionary built by make.perf_hash */
|
---|
| 179 | #ifdef SHORT_SUFFIX
|
---|
| 180 | # define INVF_DICT_HASH_SUFFIX ".idh"
|
---|
| 181 | #else
|
---|
| 182 | # define INVF_DICT_HASH_SUFFIX ".invf.dict.hash"
|
---|
| 183 | #endif
|
---|
| 184 |
|
---|
| 185 | /* The paragraph descriptior file built by invf.pass1 or ivf.pass1 */
|
---|
| 186 | #ifdef SHORT_SUFFIX
|
---|
| 187 | # define INVF_PARAGRAPH_SUFFIX ".ip"
|
---|
| 188 | #else
|
---|
| 189 | # define INVF_PARAGRAPH_SUFFIX ".invf.paragraph"
|
---|
| 190 | #endif
|
---|
| 191 |
|
---|
| 192 | /* The trace file build by mg.builder. */
|
---|
| 193 | #ifdef SHORT_SUFFIX
|
---|
| 194 | # define TRACE_SUFFIX ".trc"
|
---|
| 195 | #else
|
---|
| 196 | # define TRACE_SUFFIX ".trace"
|
---|
| 197 | #endif
|
---|
| 198 |
|
---|
| 199 | /* The compression stats file build by mg.builder. */
|
---|
| 200 | #ifdef SHORT_SUFFIX
|
---|
| 201 | # define COMPRESSION_STATS_SUFFIX ".cs"
|
---|
| 202 | #else
|
---|
| 203 | # define COMPRESSION_STATS_SUFFIX ".compression.stats"
|
---|
| 204 | #endif
|
---|
| 205 |
|
---|
| 206 | /* [RPAP - Jan 97: Stem Index Change] */
|
---|
| 207 | /* The casefolded index into the stemmed dictionary */
|
---|
| 208 | #ifdef SHORT_SUFFIX
|
---|
| 209 | # define INVF_DICT_BLOCKED_1_SUFFIX ".ib1"
|
---|
| 210 | #else
|
---|
| 211 | # define INVF_DICT_BLOCKED_1_SUFFIX ".invf.dict.blocked.1"
|
---|
| 212 | #endif
|
---|
| 213 |
|
---|
| 214 | /* [RPAP - Jan 97: Stem Index Change] */
|
---|
| 215 | /* The stemmed index into the stemmed dictionary */
|
---|
| 216 | #ifdef SHORT_SUFFIX
|
---|
| 217 | # define INVF_DICT_BLOCKED_2_SUFFIX ".ib2"
|
---|
| 218 | #else
|
---|
| 219 | # define INVF_DICT_BLOCKED_2_SUFFIX ".invf.dict.blocked.2"
|
---|
| 220 | #endif
|
---|
| 221 |
|
---|
| 222 | /* [RPAP - Jan 97: Stem Index Change] */
|
---|
| 223 | /* The casefolded and stemmed index into the stemmed dictionary */
|
---|
| 224 | #ifdef SHORT_SUFFIX
|
---|
| 225 | # define INVF_DICT_BLOCKED_3_SUFFIX ".ib3"
|
---|
| 226 | #else
|
---|
| 227 | # define INVF_DICT_BLOCKED_3_SUFFIX ".invf.dict.blocked.3"
|
---|
| 228 | #endif
|
---|
| 229 |
|
---|
| 230 | /* [RPAP - Feb 97: WIN32 Port] */
|
---|
| 231 | #ifdef __WIN32__
|
---|
| 232 | #define FILE_NAME_FORMAT "%s%s%s"
|
---|
| 233 | #else
|
---|
| 234 | #define FILE_NAME_FORMAT "%s/%s%s"
|
---|
| 235 | #endif
|
---|
| 236 |
|
---|
| 237 |
|
---|
| 238 | /* This sets the base path for all file operations */
|
---|
| 239 | void set_basepath (const char *bp);
|
---|
| 240 |
|
---|
| 241 |
|
---|
| 242 | /* return the currently defined basepath */
|
---|
| 243 | char *get_basepath (void);
|
---|
| 244 |
|
---|
| 245 |
|
---|
| 246 |
|
---|
| 247 |
|
---|
| 248 | /* This generates the name of a file. It places the name in the buffer
|
---|
| 249 | specified or if that is NULL it uses a static buffer. */
|
---|
| 250 | char *make_name (const char *name, const char *suffix, char *buffer);
|
---|
| 251 |
|
---|
| 252 |
|
---|
| 253 |
|
---|
| 254 |
|
---|
| 255 |
|
---|
| 256 |
|
---|
| 257 |
|
---|
| 258 | /* This will open the specified file and check its magic number.
|
---|
| 259 | Mode may take on the following values
|
---|
| 260 | MG_ABORT : causes an error message to be generated and the
|
---|
| 261 | program aborted if there is an error.
|
---|
| 262 | MG_MESSAGE : causes a message to be generated and a NULL value to
|
---|
| 263 | be returned if there is an error.
|
---|
| 264 | MG_CONTINUE : causes a NULL value to be returned if there is an error.
|
---|
| 265 |
|
---|
| 266 | On success if returns the FILE *. On failure it will return a NULL value
|
---|
| 267 | and possibly generate an error message, or it will exit the program with
|
---|
| 268 | an error message. */
|
---|
| 269 | FILE *open_named_file (const char *name, const char *mode,
|
---|
[25147] | 270 | mg_u_long magic_num, int err_mode);
|
---|
[3745] | 271 |
|
---|
| 272 |
|
---|
| 273 |
|
---|
| 274 |
|
---|
| 275 | /* This will open the specified file and check its magic number.
|
---|
| 276 |
|
---|
| 277 | err_mode may take on the following values
|
---|
| 278 | MG_ABORT : causes an error message to be generated and the
|
---|
| 279 | program aborted if there is an error.
|
---|
| 280 | MG_MESSAGE : causes a message to be generated and a NULL value to
|
---|
| 281 | be returned if there is an error.
|
---|
| 282 | MG_CONTINUE : causes a NULL value to be returned if there is an error.
|
---|
| 283 |
|
---|
| 284 | On success if returns the FILE *. On failure it will return a NULL value
|
---|
| 285 | and possibly generate an error message, or it will exit the program with
|
---|
| 286 | an error message. */
|
---|
| 287 | FILE *open_file (const char *name, const char *suffix, const char *mode,
|
---|
[25147] | 288 | mg_u_long magic_num, int err_mode);
|
---|
[3745] | 289 |
|
---|
| 290 |
|
---|
| 291 |
|
---|
| 292 |
|
---|
| 293 |
|
---|
| 294 | /* This will create the specified file and set its magic number.
|
---|
| 295 |
|
---|
| 296 | Mode may take on the following values
|
---|
| 297 | MG_ABORT : causes an error message to be generated and the
|
---|
| 298 | program aborted if there is an error.
|
---|
| 299 | MG_MESSAGE : causes a message to be generated and a NULL value to
|
---|
| 300 | be returned if there is an error.
|
---|
| 301 | MG_CONTINUE : causes a NULL value to be returned if there is an error.
|
---|
| 302 |
|
---|
| 303 | On success if returns the FILE *. On failure it will return a NULL value
|
---|
| 304 | and possibly generate an error message, or it will exit the program with
|
---|
| 305 | an error message. */
|
---|
| 306 | FILE *create_named_file (const char *name, const char *mode,
|
---|
[25147] | 307 | mg_u_long magic_num, int err_mode);
|
---|
[3745] | 308 |
|
---|
| 309 |
|
---|
| 310 |
|
---|
| 311 | /* This will create the specified file and set its magic number.
|
---|
| 312 |
|
---|
| 313 | err_mode may take on the following values
|
---|
| 314 | MG_ABORT : causes an error message to be generated and the
|
---|
| 315 | program aborted if there is an error.
|
---|
| 316 | MG_MESSAGE : causes a message to be generated and a NULL value to
|
---|
| 317 | be returned if there is an error.
|
---|
| 318 | MG_CONTINUE : causes a NULL value to be returned if there is an error.
|
---|
| 319 |
|
---|
| 320 | On success if returns the FILE *. On failure it will return a NULL value
|
---|
| 321 | and possibly generate an error message, or it will exit the program with
|
---|
| 322 | an error message. */
|
---|
| 323 | FILE *create_file (const char *name, const char *suffix, const char *mode,
|
---|
[25147] | 324 | mg_u_long magic_num, int err_mode);
|
---|
[3745] | 325 |
|
---|
| 326 |
|
---|
| 327 |
|
---|
| 328 |
|
---|
| 329 | #endif
|
---|