]>
Commit | Line | Data |
---|---|---|
224c7076 A |
1 | /* $FreeBSD: src/lib/libc/nls/msgcat.h,v 1.8 2000/09/03 21:05:10 ache Exp $ */ |
2 | ||
3 | #ifndef _MSGCAT_H_ | |
4 | #define _MSGCAT_H_ | |
5 | ||
6 | ||
7 | /*********************************************************** | |
8 | Copyright 1990, by Alfalfa Software Incorporated, Cambridge, Massachusetts. | |
9 | ||
10 | All Rights Reserved | |
11 | ||
12 | Permission to use, copy, modify, and distribute this software and its | |
13 | documentation for any purpose and without fee is hereby granted, | |
14 | provided that the above copyright notice appear in all copies and that | |
15 | both that copyright notice and this permission notice appear in | |
16 | supporting documentation, and that Alfalfa's name not be used in | |
17 | advertising or publicity pertaining to distribution of the software | |
18 | without specific, written prior permission. | |
19 | ||
20 | ALPHALPHA DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING | |
21 | ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL | |
22 | ALPHALPHA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR | |
23 | ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, | |
24 | WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, | |
25 | ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS | |
26 | SOFTWARE. | |
27 | ||
28 | If you make any modifications, bugfixes or other changes to this software | |
29 | we'd appreciate it if you could send a copy to us so we can keep things | |
30 | up-to-date. Many thanks. | |
31 | Kee Hinckley | |
32 | Alfalfa Software, Inc. | |
33 | 267 Allston St., #3 | |
34 | Cambridge, MA 02139 USA | |
35 | nazgul@alfalfa.com | |
36 | ||
37 | ******************************************************************/ | |
38 | ||
39 | ||
40 | #include <sys/types.h> | |
41 | ||
42 | /* | |
43 | * On disk data structures | |
44 | */ | |
45 | ||
46 | /* For or'd constants */ | |
47 | #define MCMakeId(s,m) (u_int32_t) ( ((unsigned short)s << (sizeof(short)*8)) \ | |
48 | | (unsigned short)m ) | |
49 | #define MCSetId(id) (unsigned int) ( id >> (sizeof(short) * 8) ) | |
50 | #define MCMsgId(id) (unsigned int) ( (id << (sizeof(short) * 8)) \ | |
51 | >> (sizeof(short) * 8) ) | |
52 | #define MCMagicLen 8 | |
53 | #define MCMagic "*nazgul*" | |
54 | #define MCLastMsg 0 | |
55 | #define MCLastSet 0 | |
56 | ||
57 | #define MCMajorVer 1 | |
58 | #define MCMinorVer 0 | |
59 | ||
60 | /* | |
61 | * Critical note here. Sets and Messages *MUST* be stored in ascending | |
62 | * order. There are stored that way (by specification) in the original | |
63 | * data file, however in the process of merging in new stuff you might | |
64 | * mix that up. Don't! The catget stuff does a binary search and will | |
65 | * totally lose it if these aren't in order (not contiguous mind you, just | |
66 | * in order. If this turns out to be a major problem this could be enhanced | |
67 | * by adding a 'sorted' flag to the db, and sorting msgs and sets at load | |
68 | * time if things aren't sorted, but I'd like not to have to do that. | |
69 | */ | |
70 | ||
71 | /* | |
72 | * I have tried here to define data structures which can be used | |
73 | * while the catalog is on disk, and at runtime. | |
74 | * This is rather dangerous of course, but I think it can be done without | |
75 | * overly increasing the memory usage, and it makes loading and storing | |
76 | * somewhat simpler and less prone to accidents. I have also tried to | |
77 | * define on disk data structures which can be updated in place, so that | |
78 | * with a very large catalog (e.g. all system errors) you don't have to | |
79 | * load everything in memory in order to add or update one set. With | |
80 | * this in mind there are "invalid" flags which allow items to be | |
81 | * invalidated and thus not loaded at runtime. Note however that although | |
82 | * I pay attention to these when I load the DB, I do not currently use | |
83 | * them in gencat (it just reads everything into memory), so there is | |
84 | * no guarantee that this will all work. | |
85 | */ | |
86 | ||
87 | /* These should be publicly available */ | |
88 | ||
89 | #define MCLoadBySet 0 /* Load entire sets as they are used */ | |
90 | #define MCLoadAll 1 /* Load entire DB on catopen */ | |
91 | ||
92 | /* | |
93 | * MCOffsetT - Union to handle both disk and runtime pointers | |
94 | */ | |
95 | typedef union { | |
96 | off_t off; | |
97 | char *str; | |
98 | void *ptr; | |
99 | struct _MCMsgT *msg; | |
100 | struct _MCSetT *set; | |
101 | } MCOffsetT; | |
102 | ||
103 | #ifdef __LP64__ | |
104 | #pragma pack(4) | |
105 | #endif /* __LP64__ */ | |
106 | /* | |
107 | * MCMsgT - Message structure (disk and runtime) | |
108 | */ | |
109 | typedef struct _MCMsgT { | |
110 | int32_t msgId; /* Id of this message */ | |
111 | MCOffsetT msg; /* Relative offset on disk or pointer in memory */ | |
112 | int32_t invalid; /* Valid on disk, loaded in memory */ | |
113 | } MCMsgT; | |
114 | ||
115 | /* | |
116 | * MCSetT - Set structure (disk and runtime) | |
117 | */ | |
118 | typedef struct _MCSetT { | |
119 | int32_t setId; /* Id of this set */ | |
120 | off_t nextSet; /* Offset of next set on disk */ | |
121 | union { | |
122 | off_t firstMsg; /* Offset to first Msg (while on disk) */ | |
123 | MCMsgT *msgs; /* Pointer to array of msgs (in mem, loaded) */ | |
124 | } u; | |
125 | MCOffsetT data; /* Offset to data, or pointer to data */ | |
126 | int32_t dataLen; /* Length of data area on disk */ | |
127 | int32_t numMsgs; /* Number of messages */ | |
128 | int32_t invalid; /* Valid on disk, loaded in memory */ | |
129 | } MCSetT; | |
130 | #ifdef __LP64__ | |
131 | #pragma pack() | |
132 | #endif /* __LP64__ */ | |
133 | ||
134 | /* | |
135 | * MCCatT - Runtime catalog pointer | |
136 | */ | |
137 | typedef struct { | |
138 | int32_t loadType; /* How to load the messages (see MSLoadType) */ | |
139 | FILE *fp; /* File descriptor of catalog (if load-on-demand) */ | |
140 | int32_t numSets; /* Number of sets */ | |
141 | MCSetT *sets; /* Pointer to the sets */ | |
142 | off_t firstSet; /* Offset of first set on disk */ | |
143 | } MCCatT; | |
144 | ||
145 | /* | |
146 | * MCHeaderT - Disk file header | |
147 | */ | |
148 | typedef struct { | |
149 | char magic[MCMagicLen]; /* Magic cookie "*nazgul*" */ | |
150 | int32_t majorVer; /* ++ on incompatible changes */ | |
151 | int32_t minorVer; /* ++ on compatible changes */ | |
152 | int32_t flags; /* Informational flags */ | |
153 | int32_t numSets; /* Number of valid Sets */ | |
154 | off_t firstSet; /* Offset of first set on disk */ | |
155 | } MCHeaderT; | |
156 | ||
157 | /* Some flags */ | |
158 | #define MC68KByteOrder 0x01 | |
159 | #define MCn86ByteOrder 0x02 | |
160 | ||
161 | #endif /* !_MSGCAT_H_ */ |