4.4BSD snapshot (revision 8.1); add 1993 to copyright
[unix-history] / usr / src / usr.bin / mail / def.h
CommitLineData
761330fe 1/*
a12ff486
KB
2 * Copyright (c) 1980, 1993
3 * The Regents of the University of California. All rights reserved.
761330fe 4 *
f15db449 5 * %sccs.include.redist.c%
0c5f72fb 6 *
a12ff486 7 * @(#)def.h 8.1 (Berkeley) %G%
761330fe 8 */
43101bb9 9
43101bb9
KS
10/*
11 * Mail -- a mail program
12 *
43101bb9
KS
13 * Author: Kurt Shoens (UCB) March 25, 1978
14 */
15
a0d23834
KB
16#include <sys/param.h>
17#include <sys/stat.h>
18#include <sys/time.h>
19
20#include <signal.h>
21#include <sgtty.h>
22#include <unistd.h>
23#include <stdlib.h>
24#include <stdio.h>
25#include <ctype.h>
26#include <string.h>
27#include "pathnames.h"
28
435e8dff 29#define APPEND /* New mail goes to end of mailbox */
43101bb9
KS
30
31#define ESCAPE '~' /* Default escape for sending */
7e9e94c1 32#define NMLSIZE 1024 /* max names in a message list */
f674e088 33#define PATHSIZE MAXPATHLEN /* Size of pathnames throughout */
7e9e94c1 34#define HSHSIZE 59 /* Hash size for aliases and vars */
74f7ed29 35#define LINESIZE BUFSIZ /* max readable line width */
43101bb9 36#define STRINGSIZE ((unsigned) 128)/* Dynamic allocation units */
7e9e94c1 37#define MAXARGC 1024 /* Maximum list of raw strings */
43101bb9
KS
38#define NOSTR ((char *) 0) /* Null string pointer */
39#define MAXEXP 25 /* Maximum expansion of aliases */
828615a1 40
43101bb9
KS
41#define equal(a, b) (strcmp(a,b)==0)/* A nice function to string compare */
42
43struct message {
44 short m_flag; /* flags, see below */
45 short m_block; /* block number of this message */
46 short m_offset; /* offset in block of message */
ee0b03d5 47 long m_size; /* Bytes in the message */
43101bb9
KS
48 short m_lines; /* Lines in the message */
49};
50
51/*
52 * flag bits.
53 */
54
8a23b6e3
KS
55#define MUSED (1<<0) /* entry is used, but this bit isn't */
56#define MDELETED (1<<1) /* entry has been deleted */
57#define MSAVED (1<<2) /* entry has been saved */
58#define MTOUCH (1<<3) /* entry has been noticed */
59#define MPRESERVE (1<<4) /* keep entry in sys mailbox */
60#define MMARK (1<<5) /* message is marked! */
61#define MODIFY (1<<6) /* message has been modified */
62#define MNEW (1<<7) /* message has never been seen */
63#define MREAD (1<<8) /* message has been read sometime. */
64#define MSTATUS (1<<9) /* message status has changed */
65#define MBOX (1<<10) /* Send this to mbox, regardless */
43101bb9 66
828615a1
EW
67/*
68 * Given a file address, determine the block number it represents.
69 */
70#define blockof(off) ((int) ((off) / 4096))
71#define offsetof(off) ((int) ((off) % 4096))
72#define positionof(block, offset) ((off_t)(block) * 4096 + (offset))
73
43101bb9
KS
74/*
75 * Format of the command description table.
76 * The actual table is declared and initialized
77 * in lex.c
78 */
43101bb9
KS
79struct cmd {
80 char *c_name; /* Name of command */
81 int (*c_func)(); /* Implementor of the command */
82 short c_argtype; /* Type of arglist (see below) */
83 short c_msgflag; /* Required flags of messages */
84 short c_msgmask; /* Relevant flags of messages */
85};
86
87/* Yechh, can't initialize unions */
88
89#define c_minargs c_msgflag /* Minimum argcount for RAWLIST */
90#define c_maxargs c_msgmask /* Max argcount for RAWLIST */
91
92/*
93 * Argument types.
94 */
95
96#define MSGLIST 0 /* Message list type */
97#define STRLIST 1 /* A pure string */
98#define RAWLIST 2 /* Shell string list */
99#define NOLIST 3 /* Just plain 0 */
100#define NDMLIST 4 /* Message list, no defaults */
101
102#define P 040 /* Autoprint dot after command */
103#define I 0100 /* Interactive command bit */
7798c88e 104#define M 0200 /* Legal from send mode bit */
6fff2fd5 105#define W 0400 /* Illegal when read only bit */
726904d6 106#define F 01000 /* Is a conditional command */
6c0822ea 107#define T 02000 /* Is a transparent command */
a642148b 108#define R 04000 /* Cannot be called from collect */
43101bb9
KS
109
110/*
111 * Oft-used mask values
112 */
113
114#define MMNORM (MDELETED|MSAVED)/* Look at both save and delete bits */
115#define MMNDEL MDELETED /* Look only at deleted bit */
116
117/*
118 * Structure used to return a break down of a head
119 * line (hats off to Bill Joy!)
120 */
121
122struct headline {
123 char *l_from; /* The name of the sender */
124 char *l_tty; /* His tty string (if any) */
125 char *l_date; /* The entire date string */
126};
127
128#define GTO 1 /* Grab To: line */
129#define GSUBJECT 2 /* Likewise, Subject: line */
130#define GCC 4 /* And the Cc: line */
131#define GBCC 8 /* And also the Bcc: line */
132#define GMASK (GTO|GSUBJECT|GCC|GBCC)
133 /* Mask of places from whence */
134
135#define GNL 16 /* Print blank line after */
136#define GDEL 32 /* Entity removed from list */
137#define GCOMMA 64 /* detract puts in commas */
138
139/*
140 * Structure used to pass about the current
141 * state of the user-typed message header.
142 */
143
144struct header {
3d6f01e5
EW
145 struct name *h_to; /* Dynamic "To:" string */
146 char *h_subject; /* Subject string */
147 struct name *h_cc; /* Carbon copies string */
148 struct name *h_bcc; /* Blind carbon copies */
149 struct name *h_smopts; /* Sendmail options */
43101bb9
KS
150};
151
152/*
153 * Structure of namelist nodes used in processing
154 * the recipients of mail and aliases and all that
155 * kind of stuff.
156 */
157
158struct name {
159 struct name *n_flink; /* Forward link in list. */
160 struct name *n_blink; /* Backward list link */
161 short n_type; /* From which list it came */
162 char *n_name; /* This fella's name */
163};
164
165/*
166 * Structure of a variable node. All variables are
167 * kept on a singly-linked list of these, rooted by
168 * "variables"
169 */
170
171struct var {
172 struct var *v_link; /* Forward link to next variable */
173 char *v_name; /* The variable's name */
174 char *v_value; /* And it's current value */
175};
176
177struct group {
178 struct group *ge_link; /* Next person in this group */
179 char *ge_name; /* This person's user name */
180};
181
182struct grouphead {
183 struct grouphead *g_link; /* Next grouphead in list */
184 char *g_name; /* Name of this group */
185 struct group *g_list; /* Users in group. */
186};
187
188#define NIL ((struct name *) 0) /* The nil pointer for namelists */
189#define NONE ((struct cmd *) 0) /* The nil pointer to command tab */
190#define NOVAR ((struct var *) 0) /* The nil pointer to variables */
191#define NOGRP ((struct grouphead *) 0)/* The nil grouphead pointer */
192#define NOGE ((struct group *) 0) /* The nil group pointer */
193
b6264a3d
KS
194/*
195 * Structure of the hash table of ignored header fields
196 */
887efe38
EW
197struct ignoretab {
198 int i_count; /* Number of entries */
199 struct ignore {
200 struct ignore *i_link; /* Next ignored field in bucket */
201 char *i_field; /* This ignored field */
202 } *i_head[HSHSIZE];
b6264a3d
KS
203};
204
43101bb9
KS
205/*
206 * Token values returned by the scanner used for argument lists.
207 * Also, sizes of scanner-related things.
208 */
209
210#define TEOL 0 /* End of the command line */
211#define TNUMBER 1 /* A message number */
212#define TDASH 2 /* A simple dash */
213#define TSTRING 3 /* A string (possibly containing -) */
214#define TDOT 4 /* A "." */
215#define TUP 5 /* An "^" */
216#define TDOLLAR 6 /* A "$" */
217#define TSTAR 7 /* A "*" */
218#define TOPEN 8 /* An '(' */
219#define TCLOSE 9 /* A ')' */
220#define TPLUS 10 /* A '+' */
a8a981d5 221#define TERROR 11 /* A lexical error */
43101bb9
KS
222
223#define REGDEP 2 /* Maximum regret depth. */
7e9e94c1 224#define STRINGLEN 1024 /* Maximum length of string token */
43101bb9 225
6c0822ea
KS
226/*
227 * Constants for conditional commands. These describe whether
228 * we should be executing stuff or not.
229 */
230
231#define CANY 0 /* Execute in send or receive mode */
232#define CRCV 1 /* Execute in receive mode only */
233#define CSEND 2 /* Execute in send mode only */
234
43101bb9
KS
235/*
236 * Kludges to handle the change from setexit / reset to setjmp / longjmp
237 */
238
239#define setexit() setjmp(srbuf)
240#define reset(x) longjmp(srbuf, x)
241
28bcd25d
SL
242/*
243 * Truncate a file to the last character written. This is
244 * useful just before closing an old file that was opened
245 * for read/write.
246 */
247#define trunc(stream) ftruncate(fileno(stream), (long) ftell(stream))