abcf445168ac656d015548c624879a28370c8673
[mmh] / 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 #else
36 #define NORETURN
37 #endif
38
39 /*
40  * user context/profile structure
41  */
42 struct node {
43     char *n_name;               /* key                  */
44     char *n_field;              /* value                */
45     char  n_context;            /* context, not profile */
46     struct node *n_next;        /* next entry           */
47 };
48
49 /*
50  * switches structure
51  */
52 #define AMBIGSW  (-2)   /* from smatch() on ambiguous switch */
53 #define UNKWNSW  (-1)   /* from smatch() on unknown switch   */
54
55 struct swit {
56     char *sw;
57
58     /* The minchars field is apparently used like this:
59
60        -# : Switch can be abbreviated to # characters; switch hidden in -help.
61        0  : Switch can't be abbreviated;               switch shown in -help.
62        #  : Switch can be abbreviated to # characters; switch shown in -help. */
63     int minchars;
64 };
65
66 extern struct swit anoyes[];    /* standard yes/no switches */
67
68 #define ATTACHFORMATS 3         /* Number of send attach formats. */
69
70 /*
71  * general folder attributes
72  */
73 #define READONLY   (1<<0)       /* No write access to folder    */
74 #define SEQMOD     (1<<1)       /* folder's sequences modifed   */
75 #define ALLOW_NEW  (1<<2)       /* allow the "new" sequence     */
76 #define OTHERS     (1<<3)       /* folder has other files       */
77 #define MODIFIED   (1<<4)       /* msh in-core folder modified  */
78
79 #define FBITS "\020\01READONLY\02SEQMOD\03ALLOW_NEW\04OTHERS\05MODIFIED"
80
81 /*
82  * type for holding the sequence set of a message
83  */
84 typedef unsigned int seqset_t;
85
86 /*
87  * Determine the number of user defined sequences we
88  * can have.  The first 5 sequence flags are for
89  * internal nmh message flags.
90  */
91 #define NUMATTRS  ((sizeof(seqset_t) * Nbby) - 5)
92
93 /*
94  * first free slot for user defined sequences
95  * and attributes
96  */
97 #define FFATTRSLOT  5
98
99 /*
100  * internal messages attributes (sequences)
101  */
102 #define EXISTS        (1<<0)    /* exists            */
103 #define DELETED       (1<<1)    /* deleted           */
104 #define SELECTED      (1<<2)    /* selected for use  */
105 #define SELECT_EMPTY  (1<<3)    /* "new" message     */
106 #define SELECT_UNSEEN (1<<4)    /* inc/show "unseen" */
107
108 #define MBITS "\020\01EXISTS\02DELETED\03SELECTED\04NEW\05UNSEEN"
109
110 /*
111  * Primary structure of folder/message information
112  */
113 struct msgs {
114     int lowmsg;         /* Lowest msg number                 */
115     int hghmsg;         /* Highest msg number                */
116     int nummsg;         /* Actual Number of msgs             */
117
118     int lowsel;         /* Lowest selected msg number        */
119     int hghsel;         /* Highest selected msg number       */
120     int numsel;         /* Number of msgs selected           */
121
122     int curmsg;         /* Number of current msg if any      */
123
124     int msgflags;       /* Folder attributes (READONLY, etc) */
125     char *foldpath;     /* Pathname of folder                */
126
127     /*
128      * Name of sequences in this folder.  We add an
129      * extra slot, so we can NULL terminate the list.
130      */
131     char *msgattrs[NUMATTRS + 1];
132
133     /*
134      * bit flags for whether sequence
135      * is public (0), or private (1)
136      */
137     seqset_t attrstats;
138
139     /*
140      * These represent the lowest and highest possible
141      * message numbers we can put in the message status
142      * area, without calling folder_realloc().
143      */
144     int lowoff;
145     int hghoff;
146
147     /*
148      * This is an array of seqset_t which we allocate dynamically.
149      * Each seqset_t is a set of bits flags for a particular message.
150      * These bit flags represent general attributes such as
151      * EXISTS, SELECTED, etc. as well as track if message is
152      * in a particular sequence.
153      */
154     seqset_t *msgstats;         /* msg status */
155 };
156
157 /*
158  * Amount of space to allocate for msgstats.  Allocate
159  * the array to have space for messages numbers lo to hi.
160  */
161 #define MSGSTATSIZE(mp,lo,hi) ((size_t) (((hi) - (lo) + 1) * sizeof(*(mp)->msgstats)))
162
163 /*
164  * macros for message and sequence manipulation
165  */
166 #define clear_msg_flags(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] = 0)
167 #define copy_msg_flags(mp,i,j) \
168         ((mp)->msgstats[(i) - mp->lowoff] = (mp)->msgstats[(j) - mp->lowoff])
169 #define get_msg_flags(mp,ptr,msgnum)  (*(ptr) = (mp)->msgstats[(msgnum) - mp->lowoff])
170 #define set_msg_flags(mp,ptr,msgnum)  ((mp)->msgstats[(msgnum) - mp->lowoff] = *(ptr))
171
172 #define does_exist(mp,msgnum)     ((mp)->msgstats[(msgnum) - mp->lowoff] & EXISTS)
173 #define unset_exists(mp,msgnum)   ((mp)->msgstats[(msgnum) - mp->lowoff] &= ~EXISTS)
174 #define set_exists(mp,msgnum)     ((mp)->msgstats[(msgnum) - mp->lowoff] |= EXISTS)
175
176 #define is_selected(mp,msgnum)    ((mp)->msgstats[(msgnum) - mp->lowoff] & SELECTED)
177 #define unset_selected(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] &= ~SELECTED)
178 #define set_selected(mp,msgnum)   ((mp)->msgstats[(msgnum) - mp->lowoff] |= SELECTED)
179
180 #define is_select_empty(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] & SELECT_EMPTY)
181 #define set_select_empty(mp,msgnum) \
182         ((mp)->msgstats[(msgnum) - mp->lowoff] |= SELECT_EMPTY)
183
184 #define is_unseen(mp,msgnum)      ((mp)->msgstats[(msgnum) - mp->lowoff] & SELECT_UNSEEN)
185 #define unset_unseen(mp,msgnum)   ((mp)->msgstats[(msgnum) - mp->lowoff] &= ~SELECT_UNSEEN)
186 #define set_unseen(mp,msgnum)     ((mp)->msgstats[(msgnum) - mp->lowoff] |= SELECT_UNSEEN)
187
188 /* for msh only */
189 #define set_deleted(mp,msgnum)    ((mp)->msgstats[(msgnum) - mp->lowoff] |= DELETED)
190
191 #define in_sequence(mp,seqnum,msgnum) \
192            ((mp)->msgstats[(msgnum) - mp->lowoff] & (1 << (FFATTRSLOT + seqnum)))
193 #define clear_sequence(mp,seqnum,msgnum) \
194            ((mp)->msgstats[(msgnum) - mp->lowoff] &= ~(1 << (FFATTRSLOT + seqnum)))
195 #define add_sequence(mp,seqnum,msgnum) \
196            ((mp)->msgstats[(msgnum) - mp->lowoff] |= (1 << (FFATTRSLOT + seqnum)))
197
198 #define is_seq_private(mp,seqnum) \
199            ((mp)->attrstats & (1 << (FFATTRSLOT + seqnum)))
200 #define make_seq_public(mp,seqnum) \
201            ((mp)->attrstats &= ~(1 << (FFATTRSLOT + seqnum)))
202 #define make_seq_private(mp,seqnum) \
203            ((mp)->attrstats |= (1 << (FFATTRSLOT + seqnum)))
204 #define make_all_public(mp) \
205            ((mp)->attrstats = 0)
206
207 /*
208  * macros for folder attributes
209  */
210 #define clear_folder_flags(mp) ((mp)->msgflags = 0)
211
212 #define is_readonly(mp)     ((mp)->msgflags & READONLY)
213 #define set_readonly(mp)    ((mp)->msgflags |= READONLY)
214
215 #define other_files(mp)     ((mp)->msgflags & OTHERS)
216 #define set_other_files(mp) ((mp)->msgflags |= OTHERS)
217
218 #define NULLMP  ((struct msgs *) 0)
219
220 /*
221  * m_getfld() message parsing
222  */
223
224 #define NAMESZ  999             /* Limit on component name size.
225                                    RFC 2822 limits line lengths to
226                                    998 characters, so a header name
227                                    can be at most that long.
228                                    m_getfld limits header names to 2
229                                    less than NAMESZ, which is fine,
230                                    because header names must be
231                                    followed by a colon.  Add one for
232                                    terminating NULL. */
233
234 #define LENERR  (-2)            /* Name too long error from getfld  */
235 #define FMTERR  (-3)            /* Message Format error             */
236 #define FLD      0              /* Field returned                   */
237 #define FLDPLUS  1              /* Field returned with more to come */
238 #define FLDEOF   2              /* Field returned ending at eom     */
239 #define BODY     3              /* Body  returned with more to come */
240 #define BODYEOF  4              /* Body  returned ending at eom     */
241 #define FILEEOF  5              /* Reached end of input file        */
242
243 /*
244  * Maildrop styles
245  */
246 #define MS_DEFAULT      0       /* default (one msg per file) */
247 #define MS_UNKNOWN      1       /* type not known yet         */
248 #define MS_MBOX         2       /* Unix-style "from" lines    */
249 #define MS_MMDF         3       /* string mmdlm2              */
250 #define MS_MSH          4       /* whacko msh                 */
251
252 extern int msg_count;           /* m_getfld() indicators */
253 extern int msg_style;           /*  .. */
254 extern char *msg_delim;         /*  .. */
255
256 #define NOUSE   0               /* draft being re-used */
257
258 #define TFOLDER 0               /* path() given a +folder */
259 #define TFILE   1               /* path() given a file    */
260 #define TSUBCWF 2               /* path() given a @folder */
261
262 #define OUTPUTLINELEN   72      /* default line length for headers */
263
264 /*
265  * miscellaneous macros
266  */
267 #define pidXwait(pid,cp) pidstatus (pidwait (pid, NOTOK), stdout, cp)
268
269 #ifndef max
270 # define max(a,b) ((a) > (b) ? (a) : (b))
271 #endif
272
273 #ifndef min
274 # define min(a,b) ((a) < (b) ? (a) : (b))
275 #endif
276
277 #ifndef abs
278 # define abs(a) ((a) > 0 ? (a) : -(a))
279 #endif
280
281 /*
282  * GLOBAL VARIABLES
283  */
284 #define CTXMOD  0x01            /* context information modified */
285 #define DBITS   "\020\01CTXMOD"
286 extern char ctxflags;
287
288 extern char *invo_name;         /* command invocation name         */
289 extern char *mypath;            /* user's $HOME                    */
290 extern char *defpath;           /* pathname of user's profile      */
291 extern char *ctxpath;           /* pathname of user's context      */
292 extern struct node *m_defs;     /* list of profile/context entries */
293
294 /*
295  * These standard strings are defined in config.c.  They are the
296  * only system-dependent parameters in nmh, and thus by redefining
297  * their values and reloading the various modules, nmh will run
298  * on any system.
299  */
300 extern char *buildmimeproc;
301 extern char *catproc;
302 extern char *components;
303 extern char *context;
304 extern char *current;
305 extern char *defaulteditor;
306 extern char *defaultfolder;
307 extern char *digestcomps;
308 extern char *distcomps;
309 extern char *draft;
310 extern char *faceproc;
311 extern char *fileproc;
312 extern char *foldprot;
313 extern char *forwcomps;
314 extern char *inbox;
315 extern char *incproc;
316 extern char *installproc;
317 extern char *lproc;
318 extern char *mailproc;
319 extern char *mh_defaults;
320 extern char *mh_profile;
321 extern char *mh_seq;
322 extern char *mhlformat;
323 extern char *mhlforward;
324 extern char *mhlproc;
325 extern char *mhlreply;
326 extern char *moreproc;
327 extern char *msgprot;
328 extern char *mshproc;
329 extern char *nmhaccessftp;
330 extern char *nmhstorage;
331 extern char *nmhcache;
332 extern char *nmhprivcache;
333 extern char *nsequence;
334 extern char *packproc;
335 extern char *postproc;
336 extern char *pfolder;
337 extern char *psequence;
338 extern char *rcvdistcomps;
339 extern char *rcvstoreproc;
340 extern char *replcomps;
341 extern char *replgroupcomps;
342 extern char *rmfproc;
343 extern char *rmmproc;
344 extern char *sendproc;
345 extern char *showmimeproc;
346 extern char *showproc;
347 extern char *usequence;
348 extern char *version_num;
349 extern char *version_str;
350 extern char *vmhproc;
351 extern char *whatnowproc;
352 extern char *whomproc;
353
354 extern void (*done) (int) NORETURN;
355
356 #include <h/prototypes.h>
357