]> diplodocus.org Git - nmh/blob - h/mh.h
More cleaned and conversion to the new parameter API.
[nmh] / h / mh.h
1
2 /*
3 * mh.h -- main header file for all of nmh
4 */
5
6 #include <h/nmh.h>
7
8 /*
9 * Well-used constants
10 */
11 #define NOTOK (-1) /* syscall()s return this on error */
12 #define OK 0 /* ditto on success */
13 #define DONE 1 /* trinary logic */
14 #define ALL ""
15 #define Nbby 8 /* number of bits/byte */
16
17 #define MAXARGS 1000 /* max arguments to exec */
18 #define NFOLDERS 1000 /* max folder arguments on command line */
19 #define DMAXFOLDER 4 /* typical number of digits */
20 #define MAXFOLDER 1000 /* message increment */
21
22 #ifndef FALSE
23 #define FALSE 0
24 #endif
25 #ifndef TRUE
26 #define TRUE 1
27 #endif
28 typedef unsigned char boolean; /* not int so we can pack in a structure */
29
30 /* If we're using gcc then give it some information about
31 * functions that abort.
32 */
33 #if __GNUC__ > 2
34 #define NORETURN __attribute__((__noreturn__))
35 #define NMH_UNUSED(i) (void) i
36 #else
37 #define NORETURN
38 #define NMH_UNUSED(i) i
39 #endif
40
41 /*
42 * user context/profile structure
43 */
44 struct node {
45 char *n_name; /* key */
46 char *n_field; /* value */
47 char n_context; /* context, not profile */
48 struct node *n_next; /* next entry */
49 };
50
51 /*
52 * switches structure
53 */
54 #define AMBIGSW (-2) /* from smatch() on ambiguous switch */
55 #define UNKWNSW (-1) /* from smatch() on unknown switch */
56
57 struct swit {
58
59 /*
60 * Switch name
61 */
62
63 char *sw;
64
65 /* The minchars field is apparently used like this:
66
67 -# : Switch can be abbreviated to # characters; switch hidden in -help.
68 0 : Switch can't be abbreviated; switch shown in -help.
69 # : Switch can be abbreviated to # characters; switch shown in -help. */
70 int minchars;
71
72 /*
73 * If we pick this switch, return this value from smatch
74 */
75
76 int swret;
77 };
78
79 /*
80 * Macros to use when declaring struct swit arrays.
81 *
82 * These macros use a technique known as X-Macros. In your source code you
83 * use them like this:
84 *
85 * #define FOO_SWITCHES \
86 * X("switch1", 0, SWITCHSW) \
87 * X("switch2", 0, SWITCH2SW) \
88 * X("thirdswitch", 2, SWITCH3SW) \
89 *
90 * The argument to each entry in FOO_SWITCHES are the switch name (sw),
91 * the minchars field (see above) and the return value for this switch.
92 * Note that the last entry in the above definition must either omit the
93 * continuation backslash, or be followed by a blank line. In the nmh
94 * code the style is to have every line include a backslash and follow
95 * the SWITCHES macro definition by a blank line.
96 *
97 * After you define FOO_SWITCHES, you instantiate it as follows:
98 *
99 * #define X(sw, minchars, id) id,
100 * DEFINE_SWITCH_ENUM(FOO);
101 * #undef X
102 *
103 * #define X(sw, minchars, id) { sw, minchars, id },
104 * DEFINE_SWITCH_ARRAY(FOO);
105 * #undef X
106 *
107 * DEFINE_SWITCH_ENUM defines an extra enum at the end of the list called
108 * LEN_FOO.
109 */
110
111 #define DEFINE_SWITCH_ENUM(name) \
112 enum { \
113 name ## _SWITCHES \
114 LEN_ ## name \
115 }
116
117 #define DEFINE_SWITCH_ARRAY(name, array) \
118 static struct swit array[] = { \
119 name ## _SWITCHES \
120 { NULL, 0, 0 } \
121 }
122
123 extern struct swit anoyes[]; /* standard yes/no switches */
124
125 /*
126 * general folder attributes
127 */
128 #define READONLY (1<<0) /* No write access to folder */
129 #define SEQMOD (1<<1) /* folder's sequences modifed */
130 #define ALLOW_NEW (1<<2) /* allow the "new" sequence */
131 #define OTHERS (1<<3) /* folder has other files */
132 #define MODIFIED (1<<4) /* msh in-core folder modified */
133
134 #define FBITS "\020\01READONLY\02SEQMOD\03ALLOW_NEW\04OTHERS\05MODIFIED"
135
136 /*
137 * first free slot for user defined sequences
138 * and attributes
139 */
140 #define FFATTRSLOT 5
141
142 /*
143 * internal messages attributes (sequences)
144 */
145 #define EXISTS (0) /* exists */
146 #define DELETED (1) /* deleted */
147 #define SELECTED (2) /* selected for use */
148 #define SELECT_EMPTY (3) /* "new" message */
149 #define SELECT_UNSEEN (4) /* inc/show "unseen" */
150
151 #define MBITS "\020\01EXISTS\02DELETED\03SELECTED\04NEW\05UNSEEN"
152
153 /*
154 * type for holding the sequence set of a message
155 */
156 typedef struct bvector *bvector_t;
157
158 bvector_t bvector_create (size_t /* initial size in bits, can be 0 */);
159 void bvector_copy (bvector_t, bvector_t);
160 void bvector_free (bvector_t);
161 void bvector_clear (bvector_t, size_t);
162 void bvector_clear_all (bvector_t);
163 void bvector_set (bvector_t, size_t);
164 unsigned int bvector_at (bvector_t, size_t);
165 const unsigned long *bvector_bits (bvector_t);
166 size_t bvector_maxsize (bvector_t);
167
168 struct svector;
169 typedef struct svector *svector_t;
170
171 svector_t svector_create (size_t);
172 void svector_free (svector_t);
173 char *svector_push_back (svector_t, char *);
174 char *svector_at (svector_t, size_t);
175 char **svector_find(svector_t, const char *);
176 char **svector_strs (svector_t);
177 size_t svector_size (svector_t);
178
179 struct ivector;
180 typedef struct ivector *ivector_t;
181
182 ivector_t ivector_create (size_t);
183 void ivector_free (ivector_t);
184 int ivector_push_back (ivector_t, int);
185 int ivector_at (ivector_t, size_t);
186 int *ivector_atp (ivector_t, size_t);
187 size_t ivector_size (ivector_t);
188
189 /*
190 * Primary structure of folder/message information
191 */
192 struct msgs {
193 int lowmsg; /* Lowest msg number */
194 int hghmsg; /* Highest msg number */
195 int nummsg; /* Actual Number of msgs */
196
197 int lowsel; /* Lowest selected msg number */
198 int hghsel; /* Highest selected msg number */
199 int numsel; /* Number of msgs selected */
200
201 int curmsg; /* Number of current msg if any */
202
203 int msgflags; /* Folder attributes (READONLY, etc) */
204 char *foldpath; /* Pathname of folder */
205
206 /*
207 * Name of sequences in this folder.
208 */
209 svector_t msgattrs;
210
211 /*
212 * bit flags for whether sequence
213 * is public (0), or private (1)
214 */
215 bvector_t attrstats;
216
217 /*
218 * These represent the lowest and highest possible
219 * message numbers we can put in the message status
220 * area, without calling folder_realloc().
221 */
222 int lowoff;
223 int hghoff;
224
225 /*
226 * This is an array of bvector_t which we allocate dynamically.
227 * Each bvector_t is a set of bits flags for a particular message.
228 * These bit flags represent general attributes such as
229 * EXISTS, SELECTED, etc. as well as track if message is
230 * in a particular sequence.
231 */
232 size_t num_msgstats;
233 bvector_t *msgstats; /* msg status */
234
235 /*
236 * A FILE handle containing an open filehandle for the sequence file
237 * for this folder. If non-NULL, use it when the sequence file is
238 * written.
239 */
240 FILE *seqhandle;
241
242 /*
243 * The name of the public sequence file; required by lkfclose()
244 */
245 char *seqname;
246 };
247
248 /*
249 * Amount of space to allocate for msgstats. Allocate
250 * the array to have space for messages numbered lo to hi.
251 * Use MSGSTATNUM to load mp->num_msgstats first.
252 */
253 #define MSGSTATNUM(lo, hi) ((size_t) ((hi) - (lo) + 1))
254 #define MSGSTATSIZE(mp) ((mp)->num_msgstats * sizeof *(mp)->msgstats)
255
256 /*
257 * macros for message and sequence manipulation
258 */
259 #define msgstat(mp,n) (mp)->msgstats[(n) - mp->lowoff]
260 #define clear_msg_flags(mp,msgnum) bvector_clear_all (msgstat(mp, msgnum))
261 #define copy_msg_flags(mp,i,j) bvector_copy (msgstat(mp,i), msgstat(mp,j))
262 #define get_msg_flags(mp,ptr,msgnum) bvector_copy (ptr, msgstat(mp, msgnum))
263 #define set_msg_flags(mp,ptr,msgnum) bvector_copy (msgstat(mp, msgnum), ptr)
264
265 #define does_exist(mp,msgnum) bvector_at (msgstat(mp, msgnum), EXISTS)
266 #define unset_exists(mp,msgnum) bvector_clear (msgstat(mp, msgnum), EXISTS)
267 #define set_exists(mp,msgnum) bvector_set (msgstat(mp, msgnum), EXISTS)
268
269 #define is_selected(mp,msgnum) bvector_at (msgstat(mp, msgnum), SELECTED)
270 #define unset_selected(mp,msgnum) bvector_clear (msgstat(mp, msgnum), SELECTED)
271 #define set_selected(mp,msgnum) bvector_set (msgstat(mp, msgnum), SELECTED)
272
273 #define is_select_empty(mp,msgnum) \
274 bvector_at (msgstat(mp, msgnum), SELECT_EMPTY)
275 #define set_select_empty(mp,msgnum) \
276 bvector_set (msgstat(mp, msgnum), SELECT_EMPTY)
277
278 #define is_unseen(mp,msgnum) \
279 bvector_at (msgstat(mp, msgnum), SELECT_UNSEEN)
280 #define unset_unseen(mp,msgnum) \
281 bvector_clear (msgstat(mp, msgnum), SELECT_UNSEEN)
282 #define set_unseen(mp,msgnum) \
283 bvector_set (msgstat(mp, msgnum), SELECT_UNSEEN)
284
285 /* for msh only */
286 #define set_deleted(mp,msgnum) bvector_set (msgstat(mp, msgnum), DELETED)
287
288 #define in_sequence(mp,seqnum,msgnum) \
289 bvector_at (msgstat(mp, msgnum), FFATTRSLOT + seqnum)
290 #define clear_sequence(mp,seqnum,msgnum) \
291 bvector_clear (msgstat(mp, msgnum), FFATTRSLOT + seqnum)
292 #define add_sequence(mp,seqnum,msgnum) \
293 bvector_set (msgstat(mp, msgnum), FFATTRSLOT + seqnum)
294
295 #define is_seq_private(mp,seqnum) \
296 bvector_at (mp->attrstats, FFATTRSLOT + seqnum)
297 #define make_seq_public(mp,seqnum) \
298 bvector_clear (mp->attrstats, FFATTRSLOT + seqnum)
299 #define make_seq_private(mp,seqnum) \
300 bvector_set (mp->attrstats, FFATTRSLOT + seqnum)
301 #define make_all_public(mp) \
302 mp->attrstats = bvector_create(0); bvector_clear_all (mp->attrstats)
303
304 /*
305 * macros for folder attributes
306 */
307 #define clear_folder_flags(mp) ((mp)->msgflags = 0)
308
309 #define is_readonly(mp) ((mp)->msgflags & READONLY)
310 #define set_readonly(mp) ((mp)->msgflags |= READONLY)
311
312 #define other_files(mp) ((mp)->msgflags & OTHERS)
313 #define set_other_files(mp) ((mp)->msgflags |= OTHERS)
314
315 #define NULLMP ((struct msgs *) 0)
316
317 /*
318 * m_getfld() message parsing
319 */
320
321 #define NAMESZ 999 /* Limit on component name size.
322 RFC 2822 limits line lengths to
323 998 characters, so a header name
324 can be at most that long.
325 m_getfld limits header names to 2
326 less than NAMESZ, which is fine,
327 because header names must be
328 followed by a colon. Add one for
329 terminating NULL. */
330
331 #define LENERR (-2) /* Name too long error from getfld */
332 #define FMTERR (-3) /* Message Format error */
333 #define FLD 0 /* Field returned */
334 #define FLDPLUS 1 /* Field returned with more to come */
335 #define BODY 3 /* Body returned with more to come */
336 #define FILEEOF 5 /* Reached end of input file */
337
338 struct m_getfld_state;
339 typedef struct m_getfld_state *m_getfld_state_t;
340
341 /*
342 * Maildrop styles
343 */
344 #define MS_DEFAULT 0 /* default (one msg per file) */
345 #define MS_UNKNOWN 1 /* type not known yet */
346 #define MS_MBOX 2 /* Unix-style "from" lines */
347 #define MS_MMDF 3 /* string mmdlm2 */
348 #define MS_MSH 4 /* whacko msh */
349
350 #define NOUSE 0 /* draft being re-used */
351
352 #define TFOLDER 0 /* path() given a +folder */
353 #define TFILE 1 /* path() given a file */
354 #define TSUBCWF 2 /* path() given a @folder */
355
356 #define OUTPUTLINELEN 72 /* default line length for headers */
357
358 #define LINK "@" /* Name of link to file to which you are */
359 /* replying. */
360
361 /*
362 * credentials management
363 */
364 struct nmh_creds {
365 char *host;
366 char *user;
367 char *password;
368 };
369
370 typedef struct nmh_creds *nmh_creds_t;
371
372 /*
373 * miscellaneous macros
374 */
375 #define pidXwait(pid,cp) pidstatus (pidwait (pid, NOTOK), stdout, cp)
376
377 #ifndef max
378 # define max(a,b) ((a) > (b) ? (a) : (b))
379 #endif
380
381 #ifndef min
382 # define min(a,b) ((a) < (b) ? (a) : (b))
383 #endif
384
385 #ifndef abs
386 # define abs(a) ((a) > 0 ? (a) : -(a))
387 #endif
388
389 /*
390 * GLOBAL VARIABLES
391 */
392 #define CTXMOD 0x01 /* context information modified */
393 #define DBITS "\020\01CTXMOD"
394 extern char ctxflags;
395
396 extern char *invo_name; /* command invocation name */
397 extern char *mypath; /* user's $HOME */
398 extern char *defpath; /* pathname of user's profile */
399 extern char *ctxpath; /* pathname of user's context */
400 extern struct node *m_defs; /* list of profile/context entries */
401
402 /* What style to use for generated Message-ID and Content-ID header
403 fields. The localname style is pid.time@localname, where time is
404 in seconds. The random style replaces the localname with some
405 (pseudo)random bytes and uses microsecond-resolution time. */
406 int save_message_id_style (const char *);
407 char *message_id (time_t, int);
408
409 /*
410 * These standard strings are defined in config.c. They are the
411 * only system-dependent parameters in nmh, and thus by redefining
412 * their values and reloading the various modules, nmh will run
413 * on any system.
414 */
415 extern char *buildmimeproc;
416 extern char *catproc;
417 extern char *components;
418 extern char *context;
419 extern char *current;
420 extern char *credentials_file;
421 extern char *defaultfolder;
422 extern char *digestcomps;
423 extern char *distcomps;
424 extern char *draft;
425 extern char *fileproc;
426 extern char *foldprot;
427 extern char *formatproc;
428 extern char *forwcomps;
429 extern char *inbox;
430 extern char *incproc;
431 extern char *lproc;
432 extern char *mailproc;
433 extern char *mh_defaults;
434 extern char *mh_profile;
435 extern char *mh_seq;
436 extern char *mhlformat;
437 extern char *mhlforward;
438 extern char *mhlproc;
439 extern char *mhlreply;
440 extern char *moreproc;
441 extern char *msgprot;
442 extern char *mshproc;
443 extern char *nmhaccessftp;
444 extern char *nmhaccessurl;
445 extern char *nmhstorage;
446 extern char *nmhcache;
447 extern char *nmhprivcache;
448 extern char *nsequence;
449 extern char *packproc;
450 extern char *postproc;
451 extern char *pfolder;
452 extern char *psequence;
453 extern char *rcvdistcomps;
454 extern char *rcvstoreproc;
455 extern char *replcomps;
456 extern char *replgroupcomps;
457 extern char *rmmproc;
458 extern char *sendproc;
459 extern char *showmimeproc;
460 extern char *showproc;
461 extern char *usequence;
462 extern char *version_num;
463 extern char *version_str;
464 extern char *vmhproc;
465 extern char *whatnowproc;
466 extern char *whomproc;
467
468 extern void (*done) (int) NORETURN;
469
470 #include <h/prototypes.h>
471