use fork instead of vfork on Linux
[mmh] / h / mh.h
1
2 /*
3  * mh.h -- main header file for all of nmh
4  *
5  * $Id$
6  */
7
8 #include <h/nmh.h>
9
10 /* A quick fix for Linux systems. According to the vfork manual page, 
11    there is little difference in performance, so we aren't losing much.
12    But this fixes a minor message bug so why not? On NetBSD, this should
13    probably not happen. */
14 #ifdef linux
15 #define vfork fork
16 #endif
17
18
19 /*
20  * Well-used constants
21  */
22 #define NOTOK        (-1)       /* syscall()s return this on error */
23 #define OK             0        /*  ditto on success               */
24 #define DONE           1        /* trinary logic                   */
25 #define ALL           ""
26 #define Nbby           8        /* number of bits/byte */
27
28 #define MAXARGS     1000        /* max arguments to exec                */
29 #define NFOLDERS    1000        /* max folder arguments on command line */
30 #define DMAXFOLDER     4        /* typical number of digits             */
31 #define MAXFOLDER   1000        /* message increment                    */
32
33 #ifndef FALSE
34 #define FALSE 0
35 #endif
36 #ifndef TRUE
37 #define TRUE 1
38 #endif
39 typedef unsigned char  boolean;  /* not int so we can pack in a structure */
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     char *sw;
59
60     /* The minchars field is apparently used like this:
61
62        -# : Switch can be abbreviated to # characters; switch hidden in -help.
63        0  : Switch can't be abbreviated;               switch shown in -help.
64        #  : Switch can be abbreviated to # characters; switch shown in -help. */
65     int minchars;
66 };
67
68 extern struct swit anoyes[];    /* standard yes/no switches */
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  128             /* Limit on component name size     */
225
226 #define LENERR  (-2)            /* Name too long error from getfld  */
227 #define FMTERR  (-3)            /* Message Format error             */
228 #define FLD      0              /* Field returned                   */
229 #define FLDPLUS  1              /* Field returned with more to come */
230 #define FLDEOF   2              /* Field returned ending at eom     */
231 #define BODY     3              /* Body  returned with more to come */
232 #define BODYEOF  4              /* Body  returned ending at eom     */
233 #define FILEEOF  5              /* Reached end of input file        */
234
235 /*
236  * Maildrop styles
237  */
238 #define MS_DEFAULT      0       /* default (one msg per file) */
239 #define MS_UNKNOWN      1       /* type not known yet         */
240 #define MS_MBOX         2       /* Unix-style "from" lines    */
241 #define MS_MMDF         3       /* string mmdlm2              */
242 #define MS_MSH          4       /* whacko msh                 */
243
244 extern int msg_count;           /* m_getfld() indicators */
245 extern int msg_style;           /*  .. */
246 extern char *msg_delim;         /*  .. */
247
248 #define NOUSE   0               /* draft being re-used */
249
250 #define TFOLDER 0               /* path() given a +folder */
251 #define TFILE   1               /* path() given a file    */
252 #define TSUBCWF 2               /* path() given a @folder */
253
254 #define OUTPUTLINELEN   72      /* default line length for headers */
255
256 /*
257  * miscellaneous macros
258  */
259 #define pidXwait(pid,cp) pidstatus (pidwait (pid, NOTOK), stdout, cp)
260
261 #ifndef max
262 # define max(a,b) ((a) > (b) ? (a) : (b))
263 #endif
264
265 #ifndef min
266 # define min(a,b) ((a) < (b) ? (a) : (b))
267 #endif
268
269 #ifndef abs
270 # define abs(a) ((a) > 0 ? (a) : -(a))
271 #endif
272
273 /*
274  * GLOBAL VARIABLES
275  */
276 #define CTXMOD  0x01            /* context information modified */
277 #define DBITS   "\020\01CTXMOD"
278 extern char ctxflags;
279
280 extern char *invo_name;         /* command invocation name         */
281 extern char *mypath;            /* user's $HOME                    */
282 extern char *defpath;           /* pathname of user's profile      */
283 extern char *ctxpath;           /* pathname of user's context      */
284 extern struct node *m_defs;     /* list of profile/context entries */
285
286 /*
287  * These standard strings are defined in config.c.  They are the
288  * only system-dependent parameters in nmh, and thus by redefining
289  * their values and reloading the various modules, nmh will run
290  * on any system.
291  */
292 extern char *buildmimeproc;
293 extern char *catproc;
294 extern char *components;
295 extern char *context;
296 extern char *current;
297 extern char *defaulteditor;
298 extern char *defaultfolder;
299 extern char *digestcomps;
300 extern char *distcomps;
301 extern char *draft;
302 extern char *faceproc;
303 extern char *fileproc;
304 extern char *foldprot;
305 extern char *forwcomps;
306 extern char *inbox;
307 extern char *incproc;
308 extern char *installproc;
309 extern char *lproc;
310 extern char *mailproc;
311 extern char *mh_defaults;
312 extern char *mh_profile;
313 extern char *mh_seq;
314 extern char *mhlformat;
315 extern char *mhlforward;
316 extern char *mhlproc;
317 extern char *mhlreply;
318 extern char *moreproc;
319 extern char *msgprot;
320 extern char *mshproc;
321 extern char *nmhaccessftp;
322 extern char *nmhstorage;
323 extern char *nmhcache;
324 extern char *nmhprivcache;
325 extern char *nsequence;
326 extern char *packproc;
327 extern char *postproc;
328 extern char *pfolder;
329 extern char *psequence;
330 extern char *rcvdistcomps;
331 extern char *rcvstoreproc;
332 extern char *replcomps;
333 extern char *replgroupcomps;
334 extern char *rmfproc;
335 extern char *rmmproc;
336 extern char *sendproc;
337 extern char *showmimeproc;
338 extern char *showproc;
339 extern char *usequence;
340 extern char *version_num;
341 extern char *version_str;
342 extern char *vmhproc;
343 extern char *whatnowproc;
344 extern char *whomproc;
345
346 #include <h/prototypes.h>
347