mhl and mhbuild ignore to long lines
[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 #define MAXTEXTPERLN 78
225
226 /* m_getfld2() returned data */
227 struct field {
228         char name[NAMESZ];
229         size_t namelen;
230         char *value;
231         size_t valuelen;
232         size_t alloclen;
233         boolean crlf;
234 };
235
236 /* m_getfld2() states */
237 enum state {
238         LENERR2 = -2,      /* Line too long */
239         FMTERR2 = -3,      /* Format error in message */
240         IOERR2 = -1,       /* Read error */
241         FLD2 = 0,          /* Header field returned */
242         BODY2,             /* Body line returned */
243         FILEEOF2           /* Reached end of input file */
244 };
245
246 #define NOUSE    0        /* draft being re-used */
247
248 #define OUTPUTLINELEN  72    /* default line length for headers */
249
250 /*
251 ** miscellaneous macros
252 */
253
254 #ifndef max
255 # define max(a,b) ((a) > (b) ? (a) : (b))
256 #endif
257
258 #ifndef min
259 # define min(a,b) ((a) < (b) ? (a) : (b))
260 #endif
261
262 /*
263 ** GLOBAL VARIABLES
264 */
265 #define CTXMOD  0x01        /* context information modified */
266 #define DBITS  "\020\01CTXMOD"
267 extern char ctxflags;
268
269 extern char *invo_name;      /* command invocation name         */
270 extern char *mypath;         /* user's $HOME                    */
271 extern char *mmhdir;
272 extern char *mmhpath;
273 extern char *defpath;        /* pathname of user's profile      */
274 extern char *ctxpath;        /* pathname of user's context      */
275 extern struct node *m_defs;  /* list of profile/context entries */
276 extern char *mailstore;      /* name of mail storage directory  */
277
278 /*
279 ** These standard strings are defined in config.c.  They are the
280 ** only system-dependent parameters in nmh, and thus by redefining
281 ** their values and reloading the various modules, nmh will run
282 ** on any system.
283 */
284 extern char *attach_hdr;
285 extern char *sign_hdr;
286 extern char *enc_hdr;
287 extern char *components;
288 extern char *context;
289 extern char *curfolder;
290 extern char *defaulteditor;
291 extern char *defaultpager;
292 extern char *defaultfolder;
293 extern char *digestcomps;
294 extern char *distcomps;
295 extern char *draftfolder;
296 extern char *foldprot;
297 extern char *forwcomps;
298 extern char *inbox;
299 extern char *listproc;
300 extern char *mhetcdir;
301 extern char *mailspool;
302 extern char *mh_seq;
303 extern char *mhlformat;
304 extern char *mhlreply;
305 extern char *mimetypequery;
306 extern char *mimetypequeryproc;
307 extern char *msgprot;
308 extern char *nmhstorage;
309 extern char *nsequence;
310 extern char *profile;
311 extern char *rcvdistcomps;
312 extern char *replcomps;
313 extern char *replgroupcomps;
314 extern char *scanformat;
315 extern char *sendmail;
316 extern char *seq_all;
317 extern char *seq_beyond;
318 extern char *seq_cur;
319 extern char *seq_first;
320 extern char *seq_last;
321 extern char *seq_next;
322 extern char *seq_prev;
323 extern char *seq_unseen;
324 extern char *seq_neg;
325 extern char *trashfolder;
326 extern char *usequence;
327 extern char *version;
328 extern char *lib_version;
329 extern char *whatnowproc;
330
331 #include <h/charstring.h>
332 #include <h/prototypes.h>