Annotation of src/usr.bin/mail/def.h, Revision 1.4
1.4 ! millert 1: /* $OpenBSD: def.h,v 1.3 1997/02/03 00:25:18 deraadt Exp $ */
1.2 deraadt 2: /* $NetBSD: def.h,v 1.8 1996/06/08 19:48:18 christos Exp $ */
1.1 deraadt 3: /*
4: * Copyright (c) 1980, 1993
5: * The Regents of the University of California. All rights reserved.
6: *
7: * Redistribution and use in source and binary forms, with or without
8: * modification, are permitted provided that the following conditions
9: * are met:
10: * 1. Redistributions of source code must retain the above copyright
11: * notice, this list of conditions and the following disclaimer.
12: * 2. Redistributions in binary form must reproduce the above copyright
13: * notice, this list of conditions and the following disclaimer in the
14: * documentation and/or other materials provided with the distribution.
15: * 3. All advertising materials mentioning features or use of this software
16: * must display the following acknowledgement:
17: * This product includes software developed by the University of
18: * California, Berkeley and its contributors.
19: * 4. Neither the name of the University nor the names of its contributors
20: * may be used to endorse or promote products derived from this software
21: * without specific prior written permission.
22: *
23: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33: * SUCH DAMAGE.
34: *
1.2 deraadt 35: * @(#)def.h 8.2 (Berkeley) 3/21/94
36: * $NetBSD: def.h,v 1.8 1996/06/08 19:48:18 christos Exp $
1.1 deraadt 37: */
38:
39: /*
40: * Mail -- a mail program
41: *
42: * Author: Kurt Shoens (UCB) March 25, 1978
43: */
44:
45: #include <sys/param.h>
46: #include <sys/stat.h>
47: #include <sys/time.h>
48:
49: #include <signal.h>
50: #include <termios.h>
51: #include <unistd.h>
52: #include <stdlib.h>
53: #include <stdio.h>
54: #include <ctype.h>
55: #include <string.h>
56: #include "pathnames.h"
57:
58: #define APPEND /* New mail goes to end of mailbox */
59:
60: #define ESCAPE '~' /* Default escape for sending */
61: #define NMLSIZE 1024 /* max names in a message list */
62: #define PATHSIZE MAXPATHLEN /* Size of pathnames throughout */
63: #define HSHSIZE 59 /* Hash size for aliases and vars */
64: #define LINESIZE BUFSIZ /* max readable line width */
65: #define STRINGSIZE ((unsigned) 128)/* Dynamic allocation units */
66: #define MAXARGC 1024 /* Maximum list of raw strings */
67: #define NOSTR ((char *) 0) /* Null string pointer */
68: #define MAXEXP 25 /* Maximum expansion of aliases */
69:
70: #define equal(a, b) (strcmp(a,b)==0)/* A nice function to string compare */
71:
72: struct message {
73: short m_flag; /* flags, see below */
1.4 ! millert 74: int m_block; /* block number of this message */
! 75: int m_offset; /* offset in block of message */
! 76: int m_size; /* Bytes in the message */
! 77: int m_lines; /* Lines in the message */
1.1 deraadt 78: };
79:
80: /*
81: * flag bits.
82: */
83:
84: #define MUSED (1<<0) /* entry is used, but this bit isn't */
85: #define MDELETED (1<<1) /* entry has been deleted */
86: #define MSAVED (1<<2) /* entry has been saved */
87: #define MTOUCH (1<<3) /* entry has been noticed */
88: #define MPRESERVE (1<<4) /* keep entry in sys mailbox */
89: #define MMARK (1<<5) /* message is marked! */
90: #define MODIFY (1<<6) /* message has been modified */
91: #define MNEW (1<<7) /* message has never been seen */
92: #define MREAD (1<<8) /* message has been read sometime. */
93: #define MSTATUS (1<<9) /* message status has changed */
94: #define MBOX (1<<10) /* Send this to mbox, regardless */
95:
96: /*
97: * Given a file address, determine the block number it represents.
98: */
99: #define blockof(off) ((int) ((off) / 4096))
100: #define offsetof(off) ((int) ((off) % 4096))
101: #define positionof(block, offset) ((off_t)(block) * 4096 + (offset))
102:
103: /*
104: * Format of the command description table.
105: * The actual table is declared and initialized
106: * in lex.c
107: */
108: struct cmd {
109: char *c_name; /* Name of command */
1.2 deraadt 110: int (*c_func) __P((void *));/* Implementor of the command */
1.1 deraadt 111: short c_argtype; /* Type of arglist (see below) */
112: short c_msgflag; /* Required flags of messages */
113: short c_msgmask; /* Relevant flags of messages */
114: };
115:
116: /* Yechh, can't initialize unions */
117:
118: #define c_minargs c_msgflag /* Minimum argcount for RAWLIST */
119: #define c_maxargs c_msgmask /* Max argcount for RAWLIST */
120:
121: /*
122: * Argument types.
123: */
124:
125: #define MSGLIST 0 /* Message list type */
126: #define STRLIST 1 /* A pure string */
127: #define RAWLIST 2 /* Shell string list */
128: #define NOLIST 3 /* Just plain 0 */
129: #define NDMLIST 4 /* Message list, no defaults */
130:
131: #define P 040 /* Autoprint dot after command */
132: #define I 0100 /* Interactive command bit */
133: #define M 0200 /* Legal from send mode bit */
134: #define W 0400 /* Illegal when read only bit */
135: #define F 01000 /* Is a conditional command */
136: #define T 02000 /* Is a transparent command */
137: #define R 04000 /* Cannot be called from collect */
138:
139: /*
140: * Oft-used mask values
141: */
142:
143: #define MMNORM (MDELETED|MSAVED)/* Look at both save and delete bits */
144: #define MMNDEL MDELETED /* Look only at deleted bit */
145:
146: /*
147: * Structure used to return a break down of a head
148: * line (hats off to Bill Joy!)
149: */
150:
151: struct headline {
152: char *l_from; /* The name of the sender */
153: char *l_tty; /* His tty string (if any) */
154: char *l_date; /* The entire date string */
155: };
156:
157: #define GTO 1 /* Grab To: line */
158: #define GSUBJECT 2 /* Likewise, Subject: line */
159: #define GCC 4 /* And the Cc: line */
160: #define GBCC 8 /* And also the Bcc: line */
161: #define GMASK (GTO|GSUBJECT|GCC|GBCC)
162: /* Mask of places from whence */
163:
164: #define GNL 16 /* Print blank line after */
165: #define GDEL 32 /* Entity removed from list */
166: #define GCOMMA 64 /* detract puts in commas */
167:
168: /*
169: * Structure used to pass about the current
170: * state of the user-typed message header.
171: */
172:
173: struct header {
174: struct name *h_to; /* Dynamic "To:" string */
175: char *h_subject; /* Subject string */
176: struct name *h_cc; /* Carbon copies string */
177: struct name *h_bcc; /* Blind carbon copies */
178: struct name *h_smopts; /* Sendmail options */
179: };
180:
181: /*
182: * Structure of namelist nodes used in processing
183: * the recipients of mail and aliases and all that
184: * kind of stuff.
185: */
186:
187: struct name {
188: struct name *n_flink; /* Forward link in list. */
189: struct name *n_blink; /* Backward list link */
190: short n_type; /* From which list it came */
191: char *n_name; /* This fella's name */
192: };
193:
194: /*
195: * Structure of a variable node. All variables are
196: * kept on a singly-linked list of these, rooted by
197: * "variables"
198: */
199:
200: struct var {
201: struct var *v_link; /* Forward link to next variable */
202: char *v_name; /* The variable's name */
203: char *v_value; /* And it's current value */
204: };
205:
206: struct group {
207: struct group *ge_link; /* Next person in this group */
208: char *ge_name; /* This person's user name */
209: };
210:
211: struct grouphead {
212: struct grouphead *g_link; /* Next grouphead in list */
213: char *g_name; /* Name of this group */
214: struct group *g_list; /* Users in group. */
215: };
216:
217: #define NIL ((struct name *) 0) /* The nil pointer for namelists */
218: #define NONE ((struct cmd *) 0) /* The nil pointer to command tab */
219: #define NOVAR ((struct var *) 0) /* The nil pointer to variables */
220: #define NOGRP ((struct grouphead *) 0)/* The nil grouphead pointer */
221: #define NOGE ((struct group *) 0) /* The nil group pointer */
222:
223: /*
224: * Structure of the hash table of ignored header fields
225: */
226: struct ignoretab {
227: int i_count; /* Number of entries */
228: struct ignore {
229: struct ignore *i_link; /* Next ignored field in bucket */
230: char *i_field; /* This ignored field */
231: } *i_head[HSHSIZE];
232: };
233:
234: /*
235: * Token values returned by the scanner used for argument lists.
236: * Also, sizes of scanner-related things.
237: */
238:
239: #define TEOL 0 /* End of the command line */
240: #define TNUMBER 1 /* A message number */
241: #define TDASH 2 /* A simple dash */
242: #define TSTRING 3 /* A string (possibly containing -) */
243: #define TDOT 4 /* A "." */
244: #define TUP 5 /* An "^" */
245: #define TDOLLAR 6 /* A "$" */
246: #define TSTAR 7 /* A "*" */
247: #define TOPEN 8 /* An '(' */
248: #define TCLOSE 9 /* A ')' */
249: #define TPLUS 10 /* A '+' */
250: #define TERROR 11 /* A lexical error */
251:
252: #define REGDEP 2 /* Maximum regret depth. */
253: #define STRINGLEN 1024 /* Maximum length of string token */
254:
255: /*
256: * Constants for conditional commands. These describe whether
257: * we should be executing stuff or not.
258: */
259:
260: #define CANY 0 /* Execute in send or receive mode */
261: #define CRCV 1 /* Execute in receive mode only */
262: #define CSEND 2 /* Execute in send mode only */
263:
264: /*
265: * Kludges to handle the change from setexit / reset to setjmp / longjmp
266: */
267:
268: #define setexit() setjmp(srbuf)
269: #define reset(x) longjmp(srbuf, x)
270:
271: /*
272: * Truncate a file to the last character written. This is
273: * useful just before closing an old file that was opened
274: * for read/write.
275: */
276: #define trunc(stream) { \
277: (void)fflush(stream); \
278: (void)ftruncate(fileno(stream), (off_t)ftell(stream)); \
279: }