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