Commit | Line | Data |
---|---|---|
761330fe DF |
1 | /* |
2 | * Copyright (c) 1980 Regents of the University of California. | |
0c5f72fb | 3 | * All rights reserved. |
761330fe | 4 | * |
0c5f72fb | 5 | * Redistribution and use in source and binary forms are permitted |
acfc7e9b KB |
6 | * provided that the above copyright notice and this paragraph are |
7 | * duplicated in all such forms and that any documentation, | |
8 | * advertising materials, and other materials related to such | |
9 | * distribution and use acknowledge that the software was developed | |
10 | * by the University of California, Berkeley. The name of the | |
11 | * University may not be used to endorse or promote products derived | |
12 | * from this software without specific prior written permission. | |
13 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR | |
14 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED | |
15 | * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
0c5f72fb | 16 | * |
d33aa50d | 17 | * @(#)def.h 5.14 (Berkeley) %G% |
761330fe | 18 | */ |
43101bb9 | 19 | |
46053c99 | 20 | #include <sys/param.h> /* includes <sys/types.h> */ |
828615a1 | 21 | #include <sys/signal.h> |
43101bb9 | 22 | #include <stdio.h> |
7400d084 | 23 | #include <sgtty.h> |
828615a1 EW |
24 | #include <ctype.h> |
25 | #include <strings.h> | |
1c265896 | 26 | #include "local.h" |
43101bb9 | 27 | |
43101bb9 KS |
28 | /* |
29 | * Mail -- a mail program | |
30 | * | |
43101bb9 KS |
31 | * Author: Kurt Shoens (UCB) March 25, 1978 |
32 | */ | |
33 | ||
34 | ||
35 | #define ESCAPE '~' /* Default escape for sending */ | |
7e9e94c1 S |
36 | #define NMLSIZE 1024 /* max names in a message list */ |
37 | #define PATHSIZE 1024 /* Size of pathnames throughout */ | |
38 | #define NAMESIZE 32 /* Max size of user name */ | |
39 | #define HSHSIZE 59 /* Hash size for aliases and vars */ | |
43101bb9 | 40 | #define HDRFIELDS 3 /* Number of header fields */ |
74f7ed29 | 41 | #define LINESIZE BUFSIZ /* max readable line width */ |
43101bb9 | 42 | #define STRINGSIZE ((unsigned) 128)/* Dynamic allocation units */ |
7e9e94c1 | 43 | #define MAXARGC 1024 /* Maximum list of raw strings */ |
43101bb9 KS |
44 | #define NOSTR ((char *) 0) /* Null string pointer */ |
45 | #define MAXEXP 25 /* Maximum expansion of aliases */ | |
828615a1 | 46 | |
43101bb9 KS |
47 | #define equal(a, b) (strcmp(a,b)==0)/* A nice function to string compare */ |
48 | ||
49 | struct message { | |
50 | short m_flag; /* flags, see below */ | |
51 | short m_block; /* block number of this message */ | |
52 | short m_offset; /* offset in block of message */ | |
ee0b03d5 | 53 | long m_size; /* Bytes in the message */ |
43101bb9 KS |
54 | short m_lines; /* Lines in the message */ |
55 | }; | |
56 | ||
57 | /* | |
58 | * flag bits. | |
59 | */ | |
60 | ||
8a23b6e3 KS |
61 | #define MUSED (1<<0) /* entry is used, but this bit isn't */ |
62 | #define MDELETED (1<<1) /* entry has been deleted */ | |
63 | #define MSAVED (1<<2) /* entry has been saved */ | |
64 | #define MTOUCH (1<<3) /* entry has been noticed */ | |
65 | #define MPRESERVE (1<<4) /* keep entry in sys mailbox */ | |
66 | #define MMARK (1<<5) /* message is marked! */ | |
67 | #define MODIFY (1<<6) /* message has been modified */ | |
68 | #define MNEW (1<<7) /* message has never been seen */ | |
69 | #define MREAD (1<<8) /* message has been read sometime. */ | |
70 | #define MSTATUS (1<<9) /* message status has changed */ | |
71 | #define MBOX (1<<10) /* Send this to mbox, regardless */ | |
43101bb9 | 72 | |
828615a1 EW |
73 | /* |
74 | * Given a file address, determine the block number it represents. | |
75 | */ | |
76 | #define blockof(off) ((int) ((off) / 4096)) | |
77 | #define offsetof(off) ((int) ((off) % 4096)) | |
78 | #define positionof(block, offset) ((off_t)(block) * 4096 + (offset)) | |
79 | ||
43101bb9 KS |
80 | /* |
81 | * Format of the command description table. | |
82 | * The actual table is declared and initialized | |
83 | * in lex.c | |
84 | */ | |
85 | ||
86 | struct cmd { | |
87 | char *c_name; /* Name of command */ | |
88 | int (*c_func)(); /* Implementor of the command */ | |
89 | short c_argtype; /* Type of arglist (see below) */ | |
90 | short c_msgflag; /* Required flags of messages */ | |
91 | short c_msgmask; /* Relevant flags of messages */ | |
92 | }; | |
93 | ||
94 | /* Yechh, can't initialize unions */ | |
95 | ||
96 | #define c_minargs c_msgflag /* Minimum argcount for RAWLIST */ | |
97 | #define c_maxargs c_msgmask /* Max argcount for RAWLIST */ | |
98 | ||
99 | /* | |
100 | * Argument types. | |
101 | */ | |
102 | ||
103 | #define MSGLIST 0 /* Message list type */ | |
104 | #define STRLIST 1 /* A pure string */ | |
105 | #define RAWLIST 2 /* Shell string list */ | |
106 | #define NOLIST 3 /* Just plain 0 */ | |
107 | #define NDMLIST 4 /* Message list, no defaults */ | |
108 | ||
109 | #define P 040 /* Autoprint dot after command */ | |
110 | #define I 0100 /* Interactive command bit */ | |
7798c88e | 111 | #define M 0200 /* Legal from send mode bit */ |
6fff2fd5 | 112 | #define W 0400 /* Illegal when read only bit */ |
726904d6 | 113 | #define F 01000 /* Is a conditional command */ |
6c0822ea | 114 | #define T 02000 /* Is a transparent command */ |
a642148b | 115 | #define R 04000 /* Cannot be called from collect */ |
43101bb9 KS |
116 | |
117 | /* | |
118 | * Oft-used mask values | |
119 | */ | |
120 | ||
121 | #define MMNORM (MDELETED|MSAVED)/* Look at both save and delete bits */ | |
122 | #define MMNDEL MDELETED /* Look only at deleted bit */ | |
123 | ||
124 | /* | |
125 | * Structure used to return a break down of a head | |
126 | * line (hats off to Bill Joy!) | |
127 | */ | |
128 | ||
129 | struct headline { | |
130 | char *l_from; /* The name of the sender */ | |
131 | char *l_tty; /* His tty string (if any) */ | |
132 | char *l_date; /* The entire date string */ | |
133 | }; | |
134 | ||
135 | #define GTO 1 /* Grab To: line */ | |
136 | #define GSUBJECT 2 /* Likewise, Subject: line */ | |
137 | #define GCC 4 /* And the Cc: line */ | |
138 | #define GBCC 8 /* And also the Bcc: line */ | |
139 | #define GMASK (GTO|GSUBJECT|GCC|GBCC) | |
140 | /* Mask of places from whence */ | |
141 | ||
142 | #define GNL 16 /* Print blank line after */ | |
143 | #define GDEL 32 /* Entity removed from list */ | |
144 | #define GCOMMA 64 /* detract puts in commas */ | |
145 | ||
146 | /* | |
147 | * Structure used to pass about the current | |
148 | * state of the user-typed message header. | |
149 | */ | |
150 | ||
151 | struct header { | |
3d6f01e5 EW |
152 | struct name *h_to; /* Dynamic "To:" string */ |
153 | char *h_subject; /* Subject string */ | |
154 | struct name *h_cc; /* Carbon copies string */ | |
155 | struct name *h_bcc; /* Blind carbon copies */ | |
156 | struct name *h_smopts; /* Sendmail options */ | |
43101bb9 KS |
157 | }; |
158 | ||
159 | /* | |
160 | * Structure of namelist nodes used in processing | |
161 | * the recipients of mail and aliases and all that | |
162 | * kind of stuff. | |
163 | */ | |
164 | ||
165 | struct name { | |
166 | struct name *n_flink; /* Forward link in list. */ | |
167 | struct name *n_blink; /* Backward list link */ | |
168 | short n_type; /* From which list it came */ | |
169 | char *n_name; /* This fella's name */ | |
170 | }; | |
171 | ||
172 | /* | |
173 | * Structure of a variable node. All variables are | |
174 | * kept on a singly-linked list of these, rooted by | |
175 | * "variables" | |
176 | */ | |
177 | ||
178 | struct var { | |
179 | struct var *v_link; /* Forward link to next variable */ | |
180 | char *v_name; /* The variable's name */ | |
181 | char *v_value; /* And it's current value */ | |
182 | }; | |
183 | ||
184 | struct group { | |
185 | struct group *ge_link; /* Next person in this group */ | |
186 | char *ge_name; /* This person's user name */ | |
187 | }; | |
188 | ||
189 | struct grouphead { | |
190 | struct grouphead *g_link; /* Next grouphead in list */ | |
191 | char *g_name; /* Name of this group */ | |
192 | struct group *g_list; /* Users in group. */ | |
193 | }; | |
194 | ||
195 | #define NIL ((struct name *) 0) /* The nil pointer for namelists */ | |
196 | #define NONE ((struct cmd *) 0) /* The nil pointer to command tab */ | |
197 | #define NOVAR ((struct var *) 0) /* The nil pointer to variables */ | |
198 | #define NOGRP ((struct grouphead *) 0)/* The nil grouphead pointer */ | |
199 | #define NOGE ((struct group *) 0) /* The nil group pointer */ | |
200 | ||
b6264a3d KS |
201 | /* |
202 | * Structure of the hash table of ignored header fields | |
203 | */ | |
887efe38 EW |
204 | struct ignoretab { |
205 | int i_count; /* Number of entries */ | |
206 | struct ignore { | |
207 | struct ignore *i_link; /* Next ignored field in bucket */ | |
208 | char *i_field; /* This ignored field */ | |
209 | } *i_head[HSHSIZE]; | |
b6264a3d KS |
210 | }; |
211 | ||
43101bb9 KS |
212 | /* |
213 | * Token values returned by the scanner used for argument lists. | |
214 | * Also, sizes of scanner-related things. | |
215 | */ | |
216 | ||
217 | #define TEOL 0 /* End of the command line */ | |
218 | #define TNUMBER 1 /* A message number */ | |
219 | #define TDASH 2 /* A simple dash */ | |
220 | #define TSTRING 3 /* A string (possibly containing -) */ | |
221 | #define TDOT 4 /* A "." */ | |
222 | #define TUP 5 /* An "^" */ | |
223 | #define TDOLLAR 6 /* A "$" */ | |
224 | #define TSTAR 7 /* A "*" */ | |
225 | #define TOPEN 8 /* An '(' */ | |
226 | #define TCLOSE 9 /* A ')' */ | |
227 | #define TPLUS 10 /* A '+' */ | |
228 | ||
229 | #define REGDEP 2 /* Maximum regret depth. */ | |
7e9e94c1 | 230 | #define STRINGLEN 1024 /* Maximum length of string token */ |
43101bb9 | 231 | |
6c0822ea KS |
232 | /* |
233 | * Constants for conditional commands. These describe whether | |
234 | * we should be executing stuff or not. | |
235 | */ | |
236 | ||
237 | #define CANY 0 /* Execute in send or receive mode */ | |
238 | #define CRCV 1 /* Execute in receive mode only */ | |
239 | #define CSEND 2 /* Execute in send mode only */ | |
240 | ||
43101bb9 KS |
241 | /* |
242 | * Kludges to handle the change from setexit / reset to setjmp / longjmp | |
243 | */ | |
244 | ||
245 | #define setexit() setjmp(srbuf) | |
246 | #define reset(x) longjmp(srbuf, x) | |
247 | ||
28bcd25d SL |
248 | /* |
249 | * Truncate a file to the last character written. This is | |
250 | * useful just before closing an old file that was opened | |
251 | * for read/write. | |
252 | */ | |
253 | #define trunc(stream) ftruncate(fileno(stream), (long) ftell(stream)) | |
254 | ||
43101bb9 KS |
255 | /* |
256 | * Forward declarations of routine types to keep lint and cc happy. | |
257 | */ | |
258 | ||
259 | FILE *Fdopen(); | |
d96977db | 260 | FILE *Popen(); |
43101bb9 KS |
261 | FILE *collect(); |
262 | FILE *infix(); | |
d33aa50d | 263 | FILE *run_editor(); |
43101bb9 KS |
264 | FILE *setinput(); |
265 | char **unpack(); | |
43101bb9 KS |
266 | char *calloc(); |
267 | char *copy(); | |
268 | char *copyin(); | |
269 | char *detract(); | |
270 | char *expand(); | |
271 | char *gets(); | |
272 | char *hfield(); | |
d1cc2242 | 273 | char *name1(); |
43101bb9 KS |
274 | char *nameof(); |
275 | char *nextword(); | |
276 | char *getenv(); | |
d33aa50d | 277 | char *fgets(); |
2a0f6531 | 278 | char *findmail(); |
828615a1 EW |
279 | char *ishfield(); |
280 | char *malloc(); | |
d33aa50d | 281 | char *mktemp(); |
43101bb9 | 282 | char *readtty(); |
5959bcea | 283 | char *reedit(); |
43101bb9 KS |
284 | char *salloc(); |
285 | char *savestr(); | |
d1cc2242 | 286 | char *skin(); |
43101bb9 KS |
287 | char *snarf(); |
288 | char *value(); | |
289 | char *vcopy(); | |
290 | char *yankword(); | |
291 | off_t fsize(); | |
d33aa50d | 292 | uid_t getuid(); |
43101bb9 KS |
293 | struct cmd *lex(); |
294 | struct grouphead *findgroup(); | |
3d6f01e5 | 295 | struct name *nalloc(); |
43101bb9 KS |
296 | struct name *cat(); |
297 | struct name *delname(); | |
298 | struct name *elide(); | |
299 | struct name *extract(); | |
300 | struct name *gexpand(); | |
43101bb9 KS |
301 | struct name *outof(); |
302 | struct name *put(); | |
303 | struct name *usermap(); | |
43101bb9 | 304 | struct var *lookup(); |
ee0b03d5 | 305 | long transmit(); |
69a9c675 | 306 | int icequal(); |