home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / usr.bin / mail / def.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-04-18  |  9.7 KB  |  324 lines

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