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