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