Much more straight-forward handling of the beyond sequence.
[mmh] / h / mh.h
1 /*
2 ** mh.h -- main header file for all of nmh
3 */
4
5 #include <h/nmh.h>
6
7 /*
8 ** Well-used constants
9 */
10 #define NOTOK       (-1)    /* syscall()s return this on error */
11 #define OK             0    /*  ditto on success               */
12 #define DONE           1    /* trinary logic                   */
13 #define ALL           ""
14 #define Nbby           8    /* number of bits/byte */
15
16 #define MAXARGS     1000    /* max arguments to exec                */
17 #define NFOLDERS    1000    /* max folder arguments on command line */
18 #define DMAXFOLDER     4    /* typical number of digits             */
19 #define MAXFOLDER   1000    /* message increment                    */
20
21 #ifndef FALSE
22 # define FALSE 0
23 #endif
24 #ifndef TRUE
25 # define TRUE 1
26 #endif
27 typedef unsigned char  boolean;  /* not int so we can pack in a structure */
28
29 /* If we're using gcc then give it some information about
30 ** functions that abort.
31 */
32 #if __GNUC__ > 2
33 # define NORETURN __attribute__((__noreturn__))
34 #else
35 # define NORETURN
36 #endif
37
38 /*
39 ** user context/profile structure
40 */
41 struct node {
42         char *n_name;         /* key                  */
43         char *n_field;        /* value                */
44         char n_context;       /* context, not profile */
45         struct node *n_next;  /* next entry           */
46 };
47
48 /*
49 ** switches structure
50 */
51 #define AMBIGSW  (-2)    /* from smatch() on ambiguous switch */
52 #define UNKWNSW  (-1)    /* from smatch() on unknown switch   */
53
54 struct swit {
55         char *sw;
56         /*
57         ** The minchars field is apparently used like this:
58         **
59         ** -# : Switch can be abbreviated to # chars; switch hidden in -help.
60         ** 0  : Switch can't be abbreviated;          switch shown in -help.
61         ** #  : Switch can be abbreviated to # chars; switch shown in -help.
62         */
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_BEYOND  (1<<2)    /* allow the beyond sequence    */
76 #define OTHERS        (1<<3)    /* folder has other files       */
77
78 #define FBITS  "\020\01READONLY\02SEQMOD\03ALLOW_BEYOND\04OTHERS"
79
80 /*
81 ** type for holding the sequence set of a message
82 */
83 typedef unsigned int seqset_t;
84
85 /*
86 ** internal messages attributes (sequences)
87 */
88 #define EXISTS        (1<<0)    /* exists            */
89 #define SELECTED      (1<<1)    /* selected for use  */
90 #define SELECT_UNSEEN (1<<2)    /* inc/show "unseen" */
91
92 #define MBITS "\020\01EXISTS\02SELECTED\03UNSEEN"
93
94 /*
95 ** first free slot for user-defined sequences
96 */
97 #define FFATTRSLOT  3
98
99 /*
100 ** Determine the number of user defined sequences we
101 ** can have.  The first few sequence flags are for
102 ** internal nmh message flags.
103 */
104 #define NUMATTRS  ((sizeof(seqset_t) * Nbby) - FFATTRSLOT)
105
106 /*
107 ** Primary structure of folder/message information
108 */
109 struct msgs {
110         int lowmsg;        /* Lowest msg number                 */
111         int hghmsg;        /* Highest msg number                */
112         int nummsg;        /* Actual Number of msgs             */
113
114         int lowsel;        /* Lowest selected msg number        */
115         int hghsel;        /* Highest selected msg number       */
116         int numsel;        /* Number of msgs selected           */
117
118         int curmsg;        /* Number of current msg if any      */
119
120         int msgflags;      /* Folder attributes (READONLY, etc) */
121         char *foldpath;    /* Pathname of folder                */
122
123         /*
124         ** Name of sequences in this folder.  We add an
125         ** extra slot, so we can NULL terminate the list.
126         */
127         char *msgattrs[NUMATTRS + 1];
128
129         /*
130         ** bit flags for whether sequence
131         ** is public (0), or private (1)
132         */
133         seqset_t attrstats;
134
135         /*
136         ** These represent the lowest and highest possible
137         ** message numbers we can put in the message status
138         ** area, without calling folder_realloc().
139         */
140         int    lowoff;
141         int    hghoff;
142
143         /*
144         ** This is an array of seqset_t which we allocate dynamically.
145         ** Each seqset_t is a set of bits flags for a particular message.
146         ** These bit flags represent general attributes such as
147         ** EXISTS, SELECTED, etc. as well as track if message is
148         ** in a particular sequence.
149         */
150         seqset_t *msgstats;        /* msg status */
151 };
152
153 /*
154 ** Amount of space to allocate for msgstats.  Allocate
155 ** the array to have space for messages numbers lo to hi.
156 */
157 #define MSGSTATSIZE(mp,lo,hi) ((size_t) (((hi) - (lo) + 1) * sizeof(*(mp)->msgstats)))
158
159 /*
160 ** macros for message and sequence manipulation
161 */
162 #define clear_msg_flags(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] = 0)
163 #define copy_msg_flags(mp,i,j) \
164     ((mp)->msgstats[(i) - mp->lowoff] = (mp)->msgstats[(j) - mp->lowoff])
165 #define get_msg_flags(mp,ptr,msgnum)  (*(ptr) = (mp)->msgstats[(msgnum) - mp->lowoff])
166 #define set_msg_flags(mp,ptr,msgnum)  ((mp)->msgstats[(msgnum) - mp->lowoff] = *(ptr))
167
168 #define does_exist(mp,msgnum)  ((mp)->msgstats[(msgnum) - mp->lowoff] & EXISTS)
169 #define unset_exists(mp,msgnum)  ((mp)->msgstats[(msgnum) - mp->lowoff] &= ~EXISTS)
170 #define set_exists(mp,msgnum)  ((mp)->msgstats[(msgnum) - mp->lowoff] |= EXISTS)
171
172 #define is_selected(mp,msgnum)  ((mp)->msgstats[(msgnum) - mp->lowoff] & SELECTED)
173 #define unset_selected(mp,msgnum)  ((mp)->msgstats[(msgnum) - mp->lowoff] &= ~SELECTED)
174 #define set_selected(mp,msgnum)  ((mp)->msgstats[(msgnum) - mp->lowoff] |= SELECTED)
175
176 #define is_unseen(mp,msgnum)  ((mp)->msgstats[(msgnum) - mp->lowoff] & SELECT_UNSEEN)
177 #define unset_unseen(mp,msgnum)  ((mp)->msgstats[(msgnum) - mp->lowoff] &= ~SELECT_UNSEEN)
178 #define set_unseen(mp,msgnum)  ((mp)->msgstats[(msgnum) - mp->lowoff] |= SELECT_UNSEEN)
179
180
181 #define in_sequence(mp,seqnum,msgnum) \
182            ((mp)->msgstats[(msgnum) - mp->lowoff] & (1 << (FFATTRSLOT + seqnum)))
183 #define clear_sequence(mp,seqnum,msgnum) \
184            ((mp)->msgstats[(msgnum) - mp->lowoff] &= ~(1 << (FFATTRSLOT + seqnum)))
185 #define add_sequence(mp,seqnum,msgnum) \
186            ((mp)->msgstats[(msgnum) - mp->lowoff] |= (1 << (FFATTRSLOT + seqnum)))
187
188 #define is_seq_private(mp,seqnum) \
189            ((mp)->attrstats & (1 << (FFATTRSLOT + seqnum)))
190 #define make_seq_public(mp,seqnum) \
191            ((mp)->attrstats &= ~(1 << (FFATTRSLOT + seqnum)))
192 #define make_seq_private(mp,seqnum) \
193            ((mp)->attrstats |= (1 << (FFATTRSLOT + seqnum)))
194 #define make_all_public(mp) \
195            ((mp)->attrstats = 0)
196
197 /*
198 ** macros for folder attributes
199 */
200 #define clear_folder_flags(mp) ((mp)->msgflags = 0)
201
202 #define is_readonly(mp)  ((mp)->msgflags & READONLY)
203 #define set_readonly(mp)  ((mp)->msgflags |= READONLY)
204
205 #define other_files(mp)  ((mp)->msgflags & OTHERS)
206 #define set_other_files(mp)  ((mp)->msgflags |= OTHERS)
207
208 #define NULLMP  ((struct msgs *) 0)
209
210 /*
211 ** m_getfld() message parsing
212 */
213
214 #define NAMESZ  999        /*
215                            ** Limit on component name size.
216                            ** RFC 2822 limits line lengths to
217                            ** 998 characters, so a header name
218                            ** can be at most that long.
219                            ** m_getfld limits header names to 2
220                            ** less than NAMESZ, which is fine,
221                            ** because header names must be
222                            ** followed by a colon. Add one for
223                            ** terminating NULL.
224                            */
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
243 extern int msg_count;        /* m_getfld() indicators */
244 extern int msg_style;        /*  .. */
245 extern char *msg_delim;      /*  .. */
246
247 #define NOUSE    0        /* draft being re-used */
248
249 #define OUTPUTLINELEN  72    /* default line length for headers */
250
251 /*
252 ** miscellaneous macros
253 */
254
255 #define pidXwait(pid,cp) pidstatus(pidwait(pid, NOTOK), stdout, cp)
256
257 #ifndef max
258 # define max(a,b) ((a) > (b) ? (a) : (b))
259 #endif
260
261 #ifndef min
262 # define min(a,b) ((a) < (b) ? (a) : (b))
263 #endif
264
265 #ifndef abs
266 # define abs(a) ((a) > 0 ? (a) : -(a))
267 #endif
268
269 /*
270 ** GLOBAL VARIABLES
271 */
272 #define CTXMOD  0x01        /* context information modified */
273 #define DBITS  "\020\01CTXMOD"
274 extern char ctxflags;
275
276 extern char *invo_name;      /* command invocation name         */
277 extern char *mypath;         /* user's $HOME                    */
278 extern char *mmhdir;
279 extern char *mmhpath;
280 extern char *defpath;        /* pathname of user's profile      */
281 extern char *ctxpath;        /* pathname of user's context      */
282 extern struct node *m_defs;  /* list of profile/context entries */
283 extern char *mailstore;      /* name of mail storage directory  */
284
285 /*
286 ** These standard strings are defined in config.c.  They are the
287 ** only system-dependent parameters in nmh, and thus by redefining
288 ** their values and reloading the various modules, nmh will run
289 ** on any system.
290 */
291 extern char *buildmimeproc;
292 extern char *backup_prefix;
293 extern char *altmsglink;
294 extern char *catproc;
295 extern char *components;
296 extern char *context;
297 extern char *curfolder;
298 extern char *defaulteditor;
299 extern char *defaultfolder;
300 extern char *digestcomps;
301 extern char *distcomps;
302 extern char *draftfolder;
303 extern char *fileproc;
304 extern char *foldprot;
305 extern char *forwcomps;
306 extern char *inbox;
307 extern char *incproc;
308 extern char *lproc;
309 extern char *mhetcdir;
310 extern char *mailproc;
311 extern char *mh_seq;
312 extern char *mhlformat;
313 extern char *mhlforward;
314 extern char *mhlproc;
315 extern char *mhlreply;
316 extern char *moreproc;
317 extern char *msgprot;
318 extern char *nmhaccessftp;
319 extern char *nmhstorage;
320 extern char *nmhcache;
321 extern char *nmhprivcache;
322 extern char *nsequence;
323 extern char *postproc;
324 extern char *profile;
325 extern char *psequence;
326 extern char *rcvdistcomps;
327 extern char *rcvstoreproc;
328 extern char *replcomps;
329 extern char *replgroupcomps;
330 extern char *rmmproc;
331 extern char *sendmail;
332 extern char *sendproc;
333 extern char *seq_all;
334 extern char *seq_beyond;
335 extern char *seq_cur;
336 extern char *seq_first;
337 extern char *seq_last;
338 extern char *seq_next;
339 extern char *seq_prev;
340 extern char *seq_unseen;
341 extern char *seq_neg;
342 extern char *showmimeproc;
343 extern char *showproc;
344 extern char *usequence;
345 extern char *version_num;
346 extern char *version_str;
347 extern char *whatnowproc;
348
349 extern void (*done) (int) NORETURN;
350
351 #include <h/prototypes.h>