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