cvsimport
[findutils.git] / locate / locatedb.h
bloba4a7289c6d66340fb38e7749927faabcb6f82b3c
1 /* locatedb.h -- declarations for the locate database
2 Copyright (C) 1994 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #ifndef _LOCATEDB_H
19 #define _LOCATEDB_H 1
21 /* The magic string at the start of a locate database, to make sure
22 it's in the right format. The 02 is the database format version number.
23 This string has the same format as a database entry, but you can't
24 concatenate databases even if you remove it, since the differential count
25 in the first entry of the second database will be wrong. */
26 #define LOCATEDB_MAGIC "\0LOCATE02"
28 /* Common-prefix length differences in the ranges
29 0..127, -127..-1 (0x00..0x7f, 0x81..0xff) fit into one byte.
30 This value (which is -128) indicates that the difference is
31 too large to fit into one byte, and a two-byte integer follows. */
32 #define LOCATEDB_ESCAPE 0x80
33 #define LOCATEDB_ONEBYTE_MAX (127)
34 #define LOCATEDB_ONEBYTE_MIN (-127)
37 /* If it is ever possible to try to encode LOCATEDB_MAGIC as a
38 * single-byte offset, then an unfortunate length of common prefix
39 * will produce a spurious escape character, desynchronising the data
40 * stream. We use a compile-time check in the preprocessor to prevent
41 * this.
43 #if LOCATEDB_ESCAPE <= LOCATEDB_ONEBYTE_MAX
44 #error "You have a bad combination of LOCATEDB_ESCAPE and LOCATEDB_ONEBYTE_MAX, see above"
45 #endif
47 /* These are used for old, bigram-encoded databases: */
49 /* Means the differential count follows in a 2-byte int instead. */
50 #define LOCATEDB_OLD_ESCAPE 30
52 /* Offset added to differential counts to encode them as positive numbers. */
53 #define LOCATEDB_OLD_OFFSET 14
55 # ifndef PARAMS
56 # if defined PROTOTYPES || (defined __STDC__ && __STDC__)
57 # define PARAMS(Args) Args
58 # else
59 # define PARAMS(Args) ()
60 # endif
61 # endif
63 typedef enum
65 GetwordEndianStateInitial = 0,
66 GetwordEndianStateNative = 1,
67 GetwordEndianStateSwab = 2
68 } GetwordEndianState;
70 int getword (FILE *fp, const char *filename,
71 size_t minvalue, size_t maxvalue,
72 GetwordEndianState *endian_state_flag);
74 bool putword (FILE *fp, int word,
75 GetwordEndianState endian_state_flag);
78 #define SLOCATE_DB_MAGIC_LEN 2
80 #endif /* !_LOCATEDB_H */