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