]> diplodocus.org Git - nmh/blob - h/mh.h
Document argsplit changes in mh-profile man page.
[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 are what 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 *
93 * After you define FOO_SWITCHES, you instantiate it as follows:
94 *
95 * #define X(sw, minchars, id) id,
96 * DEFINE_SWITCH_ENUM(FOO);
97 * #undef X
98 *
99 * #define X(sw, minchars, id) { sw, minchars, id },
100 * DEFINE_SWITCH_ARRAY(FOO);
101 * #undef X
102 *
103 * DEFINE_SWITCH_ENUM defines an extra enum at the end of the list called
104 * LEN_FOO.
105 */
106
107 #define DEFINE_SWITCH_ENUM(name) \
108 enum { \
109 name ## _SWITCHES \
110 LEN_ ## name \
111 }
112
113 #define DEFINE_SWITCH_ARRAY(name, array) \
114 static struct swit array[] = { \
115 name ## _SWITCHES \
116 { NULL, 0, 0 } \
117 }
118
119 extern struct swit anoyes[]; /* standard yes/no switches */
120
121 #define ATTACHFORMATS 3 /* Number of send attach formats. */
122
123 /*
124 * general folder attributes
125 */
126 #define READONLY (1<<0) /* No write access to folder */
127 #define SEQMOD (1<<1) /* folder's sequences modifed */
128 #define ALLOW_NEW (1<<2) /* allow the "new" sequence */
129 #define OTHERS (1<<3) /* folder has other files */
130 #define MODIFIED (1<<4) /* msh in-core folder modified */
131
132 #define FBITS "\020\01READONLY\02SEQMOD\03ALLOW_NEW\04OTHERS\05MODIFIED"
133
134 /*
135 * type for holding the sequence set of a message
136 */
137 typedef unsigned int seqset_t;
138
139 /*
140 * Determine the number of user defined sequences we
141 * can have. The first 5 sequence flags are for
142 * internal nmh message flags.
143 */
144 #define NUMATTRS ((sizeof(seqset_t) * Nbby) - 5)
145
146 /*
147 * first free slot for user defined sequences
148 * and attributes
149 */
150 #define FFATTRSLOT 5
151
152 /*
153 * internal messages attributes (sequences)
154 */
155 #define EXISTS (1<<0) /* exists */
156 #define DELETED (1<<1) /* deleted */
157 #define SELECTED (1<<2) /* selected for use */
158 #define SELECT_EMPTY (1<<3) /* "new" message */
159 #define SELECT_UNSEEN (1<<4) /* inc/show "unseen" */
160
161 #define MBITS "\020\01EXISTS\02DELETED\03SELECTED\04NEW\05UNSEEN"
162
163 /*
164 * Primary structure of folder/message information
165 */
166 struct msgs {
167 int lowmsg; /* Lowest msg number */
168 int hghmsg; /* Highest msg number */
169 int nummsg; /* Actual Number of msgs */
170
171 int lowsel; /* Lowest selected msg number */
172 int hghsel; /* Highest selected msg number */
173 int numsel; /* Number of msgs selected */
174
175 int curmsg; /* Number of current msg if any */
176
177 int msgflags; /* Folder attributes (READONLY, etc) */
178 char *foldpath; /* Pathname of folder */
179
180 /*
181 * Name of sequences in this folder. We add an
182 * extra slot, so we can NULL terminate the list.
183 */
184 char *msgattrs[NUMATTRS + 1];
185
186 /*
187 * bit flags for whether sequence
188 * is public (0), or private (1)
189 */
190 seqset_t attrstats;
191
192 /*
193 * These represent the lowest and highest possible
194 * message numbers we can put in the message status
195 * area, without calling folder_realloc().
196 */
197 int lowoff;
198 int hghoff;
199
200 /*
201 * This is an array of seqset_t which we allocate dynamically.
202 * Each seqset_t is a set of bits flags for a particular message.
203 * These bit flags represent general attributes such as
204 * EXISTS, SELECTED, etc. as well as track if message is
205 * in a particular sequence.
206 */
207 seqset_t *msgstats; /* msg status */
208 };
209
210 /*
211 * Amount of space to allocate for msgstats. Allocate
212 * the array to have space for messages numbers lo to hi.
213 */
214 #define MSGSTATSIZE(mp,lo,hi) ((size_t) (((hi) - (lo) + 1) * sizeof(*(mp)->msgstats)))
215
216 /*
217 * macros for message and sequence manipulation
218 */
219 #define clear_msg_flags(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] = 0)
220 #define copy_msg_flags(mp,i,j) \
221 ((mp)->msgstats[(i) - mp->lowoff] = (mp)->msgstats[(j) - mp->lowoff])
222 #define get_msg_flags(mp,ptr,msgnum) (*(ptr) = (mp)->msgstats[(msgnum) - mp->lowoff])
223 #define set_msg_flags(mp,ptr,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] = *(ptr))
224
225 #define does_exist(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] & EXISTS)
226 #define unset_exists(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] &= ~EXISTS)
227 #define set_exists(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] |= EXISTS)
228
229 #define is_selected(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] & SELECTED)
230 #define unset_selected(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] &= ~SELECTED)
231 #define set_selected(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] |= SELECTED)
232
233 #define is_select_empty(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] & SELECT_EMPTY)
234 #define set_select_empty(mp,msgnum) \
235 ((mp)->msgstats[(msgnum) - mp->lowoff] |= SELECT_EMPTY)
236
237 #define is_unseen(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] & SELECT_UNSEEN)
238 #define unset_unseen(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] &= ~SELECT_UNSEEN)
239 #define set_unseen(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] |= SELECT_UNSEEN)
240
241 /* for msh only */
242 #define set_deleted(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] |= DELETED)
243
244 #define in_sequence(mp,seqnum,msgnum) \
245 ((mp)->msgstats[(msgnum) - mp->lowoff] & (1 << (FFATTRSLOT + seqnum)))
246 #define clear_sequence(mp,seqnum,msgnum) \
247 ((mp)->msgstats[(msgnum) - mp->lowoff] &= ~(1 << (FFATTRSLOT + seqnum)))
248 #define add_sequence(mp,seqnum,msgnum) \
249 ((mp)->msgstats[(msgnum) - mp->lowoff] |= (1 << (FFATTRSLOT + seqnum)))
250
251 #define is_seq_private(mp,seqnum) \
252 ((mp)->attrstats & (1 << (FFATTRSLOT + seqnum)))
253 #define make_seq_public(mp,seqnum) \
254 ((mp)->attrstats &= ~(1 << (FFATTRSLOT + seqnum)))
255 #define make_seq_private(mp,seqnum) \
256 ((mp)->attrstats |= (1 << (FFATTRSLOT + seqnum)))
257 #define make_all_public(mp) \
258 ((mp)->attrstats = 0)
259
260 /*
261 * macros for folder attributes
262 */
263 #define clear_folder_flags(mp) ((mp)->msgflags = 0)
264
265 #define is_readonly(mp) ((mp)->msgflags & READONLY)
266 #define set_readonly(mp) ((mp)->msgflags |= READONLY)
267
268 #define other_files(mp) ((mp)->msgflags & OTHERS)
269 #define set_other_files(mp) ((mp)->msgflags |= OTHERS)
270
271 #define NULLMP ((struct msgs *) 0)
272
273 /*
274 * m_getfld() message parsing
275 */
276
277 #define NAMESZ 999 /* Limit on component name size.
278 RFC 2822 limits line lengths to
279 998 characters, so a header name
280 can be at most that long.
281 m_getfld limits header names to 2
282 less than NAMESZ, which is fine,
283 because header names must be
284 followed by a colon. Add one for
285 terminating NULL. */
286
287 #define LENERR (-2) /* Name too long error from getfld */
288 #define FMTERR (-3) /* Message Format error */
289 #define FLD 0 /* Field returned */
290 #define FLDPLUS 1 /* Field returned with more to come */
291 #define BODY 3 /* Body returned with more to come */
292 #define FILEEOF 5 /* Reached end of input file */
293
294 struct m_getfld_state;
295 typedef struct m_getfld_state *m_getfld_state_t;
296
297 /*
298 * Maildrop styles
299 */
300 #define MS_DEFAULT 0 /* default (one msg per file) */
301 #define MS_UNKNOWN 1 /* type not known yet */
302 #define MS_MBOX 2 /* Unix-style "from" lines */
303 #define MS_MMDF 3 /* string mmdlm2 */
304 #define MS_MSH 4 /* whacko msh */
305
306 #define NOUSE 0 /* draft being re-used */
307
308 #define TFOLDER 0 /* path() given a +folder */
309 #define TFILE 1 /* path() given a file */
310 #define TSUBCWF 2 /* path() given a @folder */
311
312 #define OUTPUTLINELEN 72 /* default line length for headers */
313
314 #define LINK "@" /* Name of link to file to which you are */
315 /* replying. */
316
317 #define NMH_ATTACH_HEADER "Nmh-Attachment" /* Default header for -attach */
318
319 /*
320 * miscellaneous macros
321 */
322 #define pidXwait(pid,cp) pidstatus (pidwait (pid, NOTOK), stdout, cp)
323
324 #ifndef max
325 # define max(a,b) ((a) > (b) ? (a) : (b))
326 #endif
327
328 #ifndef min
329 # define min(a,b) ((a) < (b) ? (a) : (b))
330 #endif
331
332 #ifndef abs
333 # define abs(a) ((a) > 0 ? (a) : -(a))
334 #endif
335
336 /*
337 * GLOBAL VARIABLES
338 */
339 #define CTXMOD 0x01 /* context information modified */
340 #define DBITS "\020\01CTXMOD"
341 extern char ctxflags;
342
343 extern char *invo_name; /* command invocation name */
344 extern char *mypath; /* user's $HOME */
345 extern char *defpath; /* pathname of user's profile */
346 extern char *ctxpath; /* pathname of user's context */
347 extern struct node *m_defs; /* list of profile/context entries */
348
349 /* What style to use for generated Message-ID and Content-ID header
350 fields. The localname style is pid.time@localname, where time is
351 in seconds. The random style replaces the localname with some
352 (pseudo)random bytes and uses microsecond-resolution time. */
353 int save_message_id_style (const char *);
354 char *message_id (time_t, int);
355
356 /*
357 * These standard strings are defined in config.c. They are the
358 * only system-dependent parameters in nmh, and thus by redefining
359 * their values and reloading the various modules, nmh will run
360 * on any system.
361 */
362 extern char *buildmimeproc;
363 extern char *catproc;
364 extern char *components;
365 extern char *context;
366 extern char *current;
367 extern char *defaultfolder;
368 extern char *digestcomps;
369 extern char *distcomps;
370 extern char *draft;
371 extern char *fileproc;
372 extern char *foldprot;
373 extern char *formatproc;
374 extern char *forwcomps;
375 extern char *inbox;
376 extern char *incproc;
377 extern char *lproc;
378 extern char *mailproc;
379 extern char *mh_defaults;
380 extern char *mh_profile;
381 extern char *mh_seq;
382 extern char *mhlformat;
383 extern char *mhlforward;
384 extern char *mhlproc;
385 extern char *mhlreply;
386 extern char *moreproc;
387 extern char *msgprot;
388 extern char *mshproc;
389 extern char *nmhaccessftp;
390 extern char *nmhstorage;
391 extern char *nmhcache;
392 extern char *nmhprivcache;
393 extern char *nsequence;
394 extern char *packproc;
395 extern char *postproc;
396 extern char *pfolder;
397 extern char *psequence;
398 extern char *rcvdistcomps;
399 extern char *rcvstoreproc;
400 extern char *replcomps;
401 extern char *replgroupcomps;
402 extern char *rmmproc;
403 extern char *sendproc;
404 extern char *showmimeproc;
405 extern char *showproc;
406 extern char *usequence;
407 extern char *version_num;
408 extern char *version_str;
409 extern char *vmhproc;
410 extern char *whatnowproc;
411 extern char *whomproc;
412
413 extern void (*done) (int) NORETURN;
414
415 #include <h/prototypes.h>
416