add some gcc hint defines
[mmh] / h / mh.h
1 /*
2 ** mh.h -- main header file for all of nmh
3 */
4
5 #include <config.h>
6
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <sys/types.h>
11 #include <stdarg.h>
12
13
14 /*
15 ** Well-used constants
16 */
17 #define NOTOK       (-1)    /* syscall()s return this on error */
18 #define OK             0    /*  ditto on success               */
19 #define DONE           1    /* trinary logic                   */
20 #define ALL           ""
21 #define Nbby           8    /* number of bits/byte */
22
23 #define MAXARGS     1000    /* max arguments to exec                */
24 #define NFOLDERS    1000    /* max folder arguments on command line */
25 #define DMAXFOLDER     4    /* typical number of digits             */
26 #define MAXFOLDER   1000    /* message increment                    */
27
28 #ifndef FALSE
29 # define FALSE 0
30 #endif
31 #ifndef TRUE
32 # define TRUE 1
33 #endif
34 typedef unsigned char  boolean;  /* not int so we can pack in a structure */
35
36 /* If we're using gcc then give it some information about
37 ** functions that abort.
38 */
39 #if __GNUC__ > 2
40 # define NORETURN __attribute__((__noreturn__))
41 # define CONST __attribute__((const))
42 # define MALLOC __attribute__((malloc))
43 # define NONNULL(...) __attribute__((nonnull(__VA_ARGS__)))
44 # define PURE __attribute__((pure))
45 # define ENDNULL __attribute__((sentinel))
46 #else
47 # define NORETURN
48 # define CONST
49 # define MALLOC
50 # define NONNULL(...)
51 # define PURE
52 # define ENDNULL
53 #endif
54
55 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
56 # define ALLOC_SIZE(...) __attribute__((alloc_size(__VA_ARGS__)))
57 # define CHECK_PRINTF(fmt, arg) __attribute__((format(printf, fmt, arg)))
58 #else
59 # define ALLOC_SIZE(...)
60 # define CHECK_PRINTF(fmt, arg)
61 #endif
62
63 /*
64 ** we should be getting this value from pathconf(_PC_PATH_MAX)
65 */
66 #ifndef PATH_MAX
67 # ifdef MAXPATHLEN
68 #  define PATH_MAX MAXPATHLEN
69 # else
70    /* so we will just pick something */
71 #  define PATH_MAX 1024
72 # endif
73 #endif
74
75 /*
76 ** we should be getting this value from sysconf(_SC_OPEN_MAX)
77 */
78 #ifndef OPEN_MAX
79 # ifdef NOFILE
80 #  define OPEN_MAX NOFILE
81 # else
82    /* so we will just pick something */
83 #  define OPEN_MAX 64
84 # endif
85 #endif
86
87 /*
88 ** user context/profile structure
89 */
90 struct node {
91         char *n_name;         /* key                  */
92         char *n_field;        /* value                */
93         char n_context;       /* context, not profile */
94         struct node *n_next;  /* next entry           */
95 };
96
97 /*
98 ** switches structure
99 */
100 #define AMBIGSW  (-2)    /* from smatch() on ambiguous switch */
101 #define UNKWNSW  (-1)    /* from smatch() on unknown switch   */
102
103 struct swit {
104         char *sw;
105         /*
106         ** The minchars field is apparently used like this:
107         **
108         ** -# : Switch can be abbreviated to # chars; switch hidden in -help.
109         ** 0  : Switch can't be abbreviated;          switch shown in -help.
110         ** #  : Switch can be abbreviated to # chars; switch shown in -help.
111         */
112         int minchars;
113 };
114
115 extern struct swit anoyes[];   /* standard yes/no switches */
116
117 /*
118 ** general folder attributes
119 */
120 #define READONLY      (1<<0)    /* No write access to folder    */
121 #define SEQMOD        (1<<1)    /* folder's sequences modifed   */
122 #define ALLOW_BEYOND  (1<<2)    /* allow the beyond sequence    */
123 #define OTHERS        (1<<3)    /* folder has other files       */
124
125 #define FBITS  "\020\01READONLY\02SEQMOD\03ALLOW_BEYOND\04OTHERS"
126
127 /*
128 ** type for holding the sequence set of a message
129 */
130 typedef unsigned int seqset_t;
131
132 /*
133 ** internal messages attributes (sequences)
134 */
135 #define EXISTS        (1<<0)    /* exists            */
136 #define SELECTED      (1<<1)    /* selected for use  */
137 #define SELECT_UNSEEN (1<<2)    /* inc/show "unseen" */
138
139 #define MBITS "\020\01EXISTS\02SELECTED\03UNSEEN"
140
141 /*
142 ** first free slot for user-defined sequences
143 */
144 #define FFATTRSLOT  3
145
146 /*
147 ** Determine the number of user defined sequences we
148 ** can have.  The first few sequence flags are for
149 ** internal nmh message flags.
150 */
151 #define NUMATTRS  ((sizeof(seqset_t) * Nbby) - FFATTRSLOT)
152
153 /*
154 ** Primary structure of folder/message information
155 */
156 struct msgs {
157         int lowmsg;        /* Lowest msg number                 */
158         int hghmsg;        /* Highest msg number                */
159         int nummsg;        /* Actual Number of msgs             */
160
161         int lowsel;        /* Lowest selected msg number        */
162         int hghsel;        /* Highest selected msg number       */
163         int numsel;        /* Number of msgs selected           */
164
165         int curmsg;        /* Number of current msg if any      */
166
167         int msgflags;      /* Folder attributes (READONLY, etc) */
168         char *foldpath;    /* Pathname of folder                */
169
170         /*
171         ** Name of sequences in this folder.  We add an
172         ** extra slot, so we can NULL terminate the list.
173         */
174         char *msgattrs[NUMATTRS + 1];
175
176         /*
177         ** bit flags for whether sequence
178         ** is public (0), or private (1)
179         */
180         seqset_t attrstats;
181
182         /*
183         ** These represent the lowest and highest possible
184         ** message numbers we can put in the message status
185         ** area, without calling folder_realloc().
186         */
187         int    lowoff;
188         int    hghoff;
189
190         /*
191         ** This is an array of seqset_t which we allocate dynamically.
192         ** Each seqset_t is a set of bits flags for a particular message.
193         ** These bit flags represent general attributes such as
194         ** EXISTS, SELECTED, etc. as well as track if message is
195         ** in a particular sequence.
196         */
197         seqset_t *msgstats;        /* msg status */
198 };
199
200 /*
201 ** Amount of space to allocate for msgstats.  Allocate
202 ** the array to have space for messages numbers lo to hi.
203 */
204 #define MSGSTATSIZE(mp,lo,hi) ((size_t) (((hi) - (lo) + 1) * sizeof(*(mp)->msgstats)))
205
206 #define NULLMP  ((struct msgs *) 0)
207
208 /*
209 ** m_getfld() message parsing
210 */
211
212 #define NAMESZ  999        /*
213                            ** Limit on component name size.
214                            ** RFC 2822 limits line lengths to
215                            ** 998 characters, so a header name
216                            ** can be at most that long.
217                            ** m_getfld limits header names to 2
218                            ** less than NAMESZ, which is fine,
219                            ** because header names must be
220                            ** followed by a colon. Add one for
221                            ** terminating NULL.
222                            */
223
224 /* m_getfld2() returned data */
225 struct field {
226         char name[NAMESZ];
227         size_t namelen;
228         char *value;
229         size_t valuelen;
230         size_t alloclen;
231         boolean crlf;
232 };
233
234 /* m_getfld2() states */
235 enum state {
236         LENERR2 = -2,      /* Line too long */
237         FMTERR2 = -3,      /* Format error in message */
238         IOERR2 = -1,       /* Read error */
239         FLD2 = 0,          /* Header field returned */
240         BODY2,             /* Body line returned */
241         FILEEOF2           /* Reached end of input file */
242 };
243
244 #define NOUSE    0        /* draft being re-used */
245
246 #define OUTPUTLINELEN  72    /* default line length for headers */
247
248 /*
249 ** miscellaneous macros
250 */
251
252 #ifndef max
253 # define max(a,b) ((a) > (b) ? (a) : (b))
254 #endif
255
256 #ifndef min
257 # define min(a,b) ((a) < (b) ? (a) : (b))
258 #endif
259
260 /*
261 ** GLOBAL VARIABLES
262 */
263 #define CTXMOD  0x01        /* context information modified */
264 #define DBITS  "\020\01CTXMOD"
265 extern char ctxflags;
266
267 extern char *invo_name;      /* command invocation name         */
268 extern char *mypath;         /* user's $HOME                    */
269 extern char *mmhdir;
270 extern char *mmhpath;
271 extern char *defpath;        /* pathname of user's profile      */
272 extern char *ctxpath;        /* pathname of user's context      */
273 extern struct node *m_defs;  /* list of profile/context entries */
274 extern char *mailstore;      /* name of mail storage directory  */
275
276 /*
277 ** These standard strings are defined in config.c.  They are the
278 ** only system-dependent parameters in nmh, and thus by redefining
279 ** their values and reloading the various modules, nmh will run
280 ** on any system.
281 */
282 extern char *attach_hdr;
283 extern char *sign_hdr;
284 extern char *enc_hdr;
285 extern char *components;
286 extern char *context;
287 extern char *curfolder;
288 extern char *defaulteditor;
289 extern char *defaultpager;
290 extern char *defaultfolder;
291 extern char *digestcomps;
292 extern char *distcomps;
293 extern char *draftfolder;
294 extern char *foldprot;
295 extern char *forwcomps;
296 extern char *inbox;
297 extern char *listproc;
298 extern char *mhetcdir;
299 extern char *mailspool;
300 extern char *mh_seq;
301 extern char *mhlformat;
302 extern char *mhlreply;
303 extern char *mimetypequery;
304 extern char *mimetypequeryproc;
305 extern char *msgprot;
306 extern char *nmhstorage;
307 extern char *nsequence;
308 extern char *profile;
309 extern char *rcvdistcomps;
310 extern char *replcomps;
311 extern char *replgroupcomps;
312 extern char *scanformat;
313 extern char *sendmail;
314 extern char *seq_all;
315 extern char *seq_beyond;
316 extern char *seq_cur;
317 extern char *seq_first;
318 extern char *seq_last;
319 extern char *seq_next;
320 extern char *seq_prev;
321 extern char *seq_unseen;
322 extern char *seq_neg;
323 extern char *trashfolder;
324 extern char *usequence;
325 extern char *version;
326 extern char *lib_version;
327 extern char *whatnowproc;
328
329 #include <h/prototypes.h>