home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / com / utils / elm / sources / filter.h < prev    next >
C/C++ Source or Header  |  1992-03-22  |  6KB  |  200 lines

  1.  
  2. /* $Id: filter.h,v 4.1 90/04/28 22:42:09 syd Exp $ */
  3.  
  4. /*******************************************************************************
  5.  *  The Elm Mail System  -  $Revision: 4.1 $   $State: Exp $
  6.  *
  7.  *             Copyright (c) 1986, 1987 Dave Taylor
  8.  *             Copyright (c) 1988, 1989, 1990 USENET Community Trust
  9.  *******************************************************************************
  10.  * Bug reports, patches, comments, suggestions should be sent to:
  11.  *
  12.  *    Syd Weinstein, Elm Coordinator
  13.  *    elm@DSI.COM            dsinc!elm
  14.  *
  15.  *******************************************************************************
  16.  * $Log:    filter.h,v $
  17.  * Revision 4.1  90/04/28  22:42:09  syd
  18.  * checkin of Elm 2.3 as of Release PL0
  19.  *
  20.  *
  21.  ******************************************************************************/
  22.  
  23. /** Headers for the filter program.
  24.  
  25. **/
  26.  
  27. #ifdef   BSD
  28. # undef  tolower
  29. #endif
  30.  
  31. /** define a few handy macros for later use... **/
  32.  
  33. #define  the_same(a,b)    (strncmp(a,b,strlen(b)) == 0)
  34.  
  35. #define relationname(x)  (x == 1?"<=":x==2?"<":x==3?">=":x==4?">":x==5?"!=":"=")
  36.  
  37. #define quoteit(x)     (x == LINES? "" : "\"")
  38.  
  39. #define remove_return(s)    { if (s[strlen(s)-1] == '\n') \
  40.                     s[strlen(s)-1] = '\0';    \
  41.                    }
  42.  
  43. /** some of the files we'll be using, where they are, and so on... **/
  44.  
  45. #define  filter_temp    "filter"
  46. #define  filterfile    "elm/filter.rul"
  47. #define  filterlog    "elm/filter.log"
  48. #define  filtersum    "elm/filter.sum"
  49.  
  50. #define  EMERGENCY_MAILBOX      "emergenc.mbx"
  51. #define  EMERG_MBOX             "emerg.mbx"
  52.  
  53. /** and now the hardwired constraint of the program.. **/
  54.  
  55. #define  MAXRULES    25        /* can't have more den dis, boss! */
  56.  
  57. /** some random defines for mnemonic stuff in the program... **/
  58.  
  59. #ifdef SUBJECT
  60. # undef SUBJECT
  61. #endif
  62.  
  63. #define  TO        1
  64. #define  FROM        2
  65. #define  LINES        3
  66. #define  SUBJECT    4
  67. #define  CONTAINS    5
  68. #define  ALWAYS        6
  69.  
  70. #define  DELETE_MSG     7
  71. #define  SAVE        8
  72. #define  SAVECC        9
  73. #define  FORWARD    10
  74. #define  LEAVE        11
  75. #define  EXEC        12
  76.  
  77. #define  FAILED_SAVE    20
  78.  
  79. /** Some conditionals... **/
  80.  
  81. #define LE        1
  82. #define LT        2
  83. #define GE        3
  84. #define GT        4
  85. #define NE        5
  86. #define EQ        6
  87.  
  88. /** A funky way to open a file using open() to avoid file locking hassles **/
  89.  
  90. #define  FOLDERMODE    O_WRONLY | O_APPEND | O_CREAT
  91.  
  92. /** cheap but easy way to have two files share the same #include file **/
  93.  
  94. #ifdef MAIN_ROUTINE
  95.  
  96. char home[SLEN],                /* the users home directory */
  97.      hostname[SLEN],            /* the machine name...      */
  98.      username[SLEN];            /* the users login name...  */
  99.  
  100. char to[VERY_LONG_STRING],
  101.      from[LONG_STRING],
  102.      subject[LONG_STRING];        /* from current message     */
  103.  
  104. FILE *outfd;
  105. char outfname[SLEN];
  106.  
  107. int  total_rules = 0,                /* how many rules to check  */
  108.      show_only = FALSE,                /* just for show?           */
  109.      long_summary = FALSE,            /* what sorta summary??     */
  110.      verbose   = FALSE,                /* spit out lots of stuff   */
  111.      lines     = 0,                /* lines in message..       */
  112.      clear_logs = FALSE,            /* clear files after sum?   */
  113.      already_been_forwarded = FALSE,        /* has this been filtered?  */
  114.      log_actions_only = FALSE,            /* log actions | everything */
  115.      printing_rules = FALSE,            /* are we just using '-r'?  */
  116.      rule_choosen;                /* which one we choose      */
  117.  
  118. #else
  119.  
  120. extern char home[SLEN],                /* the users home directory */
  121.             hostname[SLEN],            /* the machine name...      */
  122.             username[SLEN];            /* the users login name...  */
  123.  
  124. extern char to[VERY_LONG_STRING],
  125.             from[LONG_STRING],
  126.             subject[LONG_STRING];        /* from current message     */
  127.  
  128. extern FILE *outfd;
  129. extern char outfname[SLEN];
  130.  
  131. extern int total_rules,                /* how many rules to check  */
  132.            show_only,                /* just for show?           */
  133.            long_summary,            /* what sorta summary??     */
  134.            verbose,                /* spit out lots of stuff   */
  135.            lines,                /* lines in message..       */
  136.            clear_logs,                    /* clear files after sum?   */
  137.        already_been_forwarded,        /* has this been filtered?  */
  138.            log_actions_only,            /* log actions | everything */
  139.            printing_rules,            /* are we just using '-r'?  */
  140.            rule_choosen;            /* which one we choose      */
  141. #endif
  142.  
  143. /** and our ruleset record structure... **/
  144.  
  145. struct condition_rec {
  146.     int     matchwhat;            /* type of 'if' clause      */
  147.     int     relation;            /* type of match (eq, etc)  */
  148.     char    argument1[SLEN];        /* match against this       */
  149.     struct  condition_rec  *next;        /* next condition...        */
  150.       };
  151.  
  152. struct ruleset_record {
  153.     char      printable[SLEN];        /* straight from file...    */
  154.     struct  condition_rec  *condition;
  155.     int     action;                /* what action to take      */
  156.     char    argument2[SLEN];        /* argument for action      */
  157.       };
  158.  
  159. #ifdef MAIN_ROUTINE
  160.   struct ruleset_record rules[MAXRULES];
  161. #else
  162.   extern struct ruleset_record rules[MAXRULES];
  163. #endif
  164.  
  165. /** finally let's keep LINT happy with the return values of all these pups! ***/
  166.  
  167. char *itoa();
  168.  
  169. #ifdef    _POSIX_SOURCE        /*{_POSIX_SOURCE*/
  170. #include <string.h>
  171. #include <unistd.h>
  172. #include <stdlib.h>
  173. #else                /*}_POSIX_SOURCE{*/
  174. unsigned short getuid();
  175.  
  176. unsigned long sleep();
  177.  
  178. char *malloc(), *strcpy(), *strcat();
  179.  
  180. void    exit();
  181.  
  182. #ifdef BSD
  183.  
  184.   FILE *popen();
  185.  
  186. #ifdef MAIN_ROUTINE
  187.   char  _vbuf[5*BUFSIZ];              /* space for file buffering */
  188. #else
  189.   extern char  _vbuf[5*BUFSIZ];        /* space for file buffering */
  190. #endif
  191.  
  192. #ifndef _IOFBF
  193. # define _IOFBF        0        /* doesn't matter - ignored */
  194. #endif
  195.  
  196. # define setvbuf(fd,a,b,c)    setbuffer(fd, _vbuf, 5*BUFSIZ)
  197.  
  198. #endif
  199. #endif                /*}_POSIX_SOURCE*/
  200.