home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / sendmail / ease-3.5 / src / emitcf.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-15  |  7.7 KB  |  281 lines

  1. #ifdef FLUKE
  2. # ifndef LINT
  3.     static char RCSid[] = "@(#)FLUKE  $Header: /home/kreskin/u0/barnett/Src/Ease/ease/src/RCS/emitcf.c,v 3.0 1991/02/22 18:50:27 barnett Exp $";
  4. # endif LINT
  5. #endif FLUKE
  6.  
  7. /*
  8.  *    emitcf.c  -- This file contains routines associated with the writing
  9.  *             and formatting of a translated sendmail configuration file.
  10.  *
  11.  *    author      -- James S. Schoner, Purdue University Computing Center,
  12.  *                         West Lafayette, Indiana  47907
  13.  *
  14.  *      date      -- July 9, 1985
  15.  *
  16.  *    Copyright (c) 1985 by Purdue Research Foundation
  17.  *
  18.  *    All rights reserved.
  19.  *
  20.  * $Log: emitcf.c,v $
  21.  * Revision 3.0  1991/02/22  18:50:27  barnett
  22.  * Added support for HP/UX and IDA sendmail.
  23.  *
  24.  * Revision 2.1  1990/01/30  14:09:49  jeff
  25.  * Changes by Bruce Barnett - extensions for SunOS/Ultrix.
  26.  *
  27.  * Revision 2.0  88/06/15  14:40:47  root
  28.  * Baseline release for net posting. ADR.
  29.  */
  30.  
  31. #include <stdio.h>
  32. #include "symtab.h"
  33. #include "fixstrings.h"
  34.  
  35. #define REGLINE 60    /* length of output lines which may be continued */
  36. #define MAXLINE 256    /* liberal maximum line length             */
  37.  
  38. extern short Rformat;            /* read-format flag for a class  */
  39. extern char *MacScan ();
  40. extern char  MakeMac ();
  41. extern void  PrintError (),
  42.          FatalError (),
  43.          PrintWarning (),
  44.          ErrorReport ();
  45.  
  46. void  PrintDef ();
  47.  
  48. static char ClassCH;            /* printable class macro char    */
  49.  
  50. /*
  51.  *    EmitDef () -- Emit a definition line (Ease block definition) in cf 
  52.  *              format.
  53.  *
  54.  */
  55. void
  56. EmitDef (blockdef, targ, defstr1, defstr2)
  57. register enum bdefs blockdef;    /* type of definition        */
  58. register struct he *targ;    /* target to be defined      */
  59. char *defstr1, *defstr2;    /* one or two definition strings */
  60. {
  61.     /*
  62.      *  This routine is about as pretty as a translated ease file...
  63.      *  Each type of line (Ease block) is handled case by case below.
  64.      *
  65.      */
  66.     switch (blockdef) {
  67.         case def_macro:        printf ("D%c", MakeMac (targ, ID_MACRO));
  68.                     PrintDef (def_macro, MacScan (defstr1));
  69.                     if (ISMACRO(targ->idd))
  70.                         PrintWarning ("Redefining macro %s.\n", targ->psb);
  71.                     targ->idd |= ID_MACRO;  /* signal definition */
  72.                     break;
  73.  
  74.         case def_class:        if (Rformat)    /* read format */
  75.                         printf ("F");
  76.                     else
  77.                         printf ("C");
  78.                     printf ("%c", ClassCH = MakeMac (targ, ID_CLASS));
  79.                     if (Rformat) {    /* read format */
  80.                         printf ("%s\n", defstr1);
  81.                         Rformat = FALSE;
  82.                     } else
  83.                         PrintDef (def_class, MacScan(defstr1));
  84.                     if (ISCLASS(targ->idd))
  85.                         PrintWarning ("Appending to previously defined class %s.\n", targ->psb);
  86.                     targ->idd |= ID_CLASS;  /* signal definition */
  87.                     break;
  88.  
  89.         case def_option:    if (defstr1 == NULL)
  90.                         FatalError ("No option passed in EmitDef()", (char *)NULL);
  91.                     printf ("O%c", *defstr1);
  92.                     PrintDef (def_option, defstr2);
  93.                     break;
  94.  
  95.         case def_prec:        printf ("P%s=%d\n", targ->psb, targ->idval.prec);
  96.                     break;
  97.  
  98.         case def_trusted:    printf ("T");
  99.                     PrintDef (def_trusted, defstr1);
  100.                     break;
  101.  
  102.         case def_header:    printf ("H");
  103.                     if (defstr1 != NULL)
  104.                         printf ("?%s?", defstr1);
  105.                     PrintDef (def_header, defstr2);
  106.                     break;
  107.  
  108.         case def_mailer:    if (ISMAILER(targ->idtype)) {
  109.                         if (ISMAILER(targ->idd))
  110.                             PrintWarning ("Redefining mailer %s.\n", targ->psb);
  111.                     } else if (ISTYPED(targ->idtype)) {
  112.                         PrintError ("Redeclaration of identifier as mailer: %s", targ->psb);
  113.                         return;
  114.                     }
  115.                     targ->idd |= ID_MAILER;  /* signal definition */
  116.                     printf ("M%s, ", targ->psb);
  117.                     PrintDef (def_mailer, defstr1);
  118.                     break;
  119.  
  120.         case def_ruleset:    printf ("R");
  121.                     PrintDef (def_ruleset, defstr1);
  122.                     break;
  123.  
  124.         default:        FatalError ("Bad case in EmitDef ()", (char *) NULL);
  125.     }
  126. }
  127.  
  128.  
  129. /*
  130.  *      PrintContinued () -- Print a line definition (buf) by splitting it over
  131.  *                 more than one line.  The two definition types 
  132.  *                 accepted for this method of continuation are class
  133.  *                 and trusted user lists, indicated in the argument 
  134.  *                 btype 
  135.  *
  136.  */
  137. void
  138. PrintContinued (btype, buf)
  139. enum bdefs     btype;    /* block (line) type for definition */
  140. register char *buf;    /* buffer containing the definition */
  141. {
  142.     register char *tmp;    /* breakpoint search pointer   */
  143.     register char  tc;    /* temporary swap byte         */
  144.     int  buflen;        /* length of definition buffer */    
  145.  
  146.     buflen = strlen (buf);
  147.     tmp = buf + REGLINE;
  148.     while ((*--tmp != ' ') && (tmp != buf))     /* look for suitable break */
  149.         /* null */ ;
  150.     if (tmp == buf) {
  151.         for (tmp = buf + REGLINE; (*tmp != ' ') && (tmp - buf != buflen); tmp++)
  152.             /* null */ ;
  153.         if ((tmp - buf) >= MAXLINE)
  154.             PrintWarning ("Member name may be too long.\n", (char *) NULL);
  155.     }
  156.     tc = *tmp;        /* swap break char with null char */
  157.     *tmp = '\0';
  158.     printf ("%s\n", buf);
  159.     if ((*tmp = tc) == '\0')
  160.         return;
  161.     else
  162.         tmp++;
  163.     if (btype == def_class)        /* start next line   */
  164.         printf ("C%c", ClassCH);
  165.     else
  166.         printf ("T");
  167.     if (strlen (tmp) < REGLINE)    /* continue the line */
  168.         printf ("%s\n", tmp);
  169.     else
  170.         PrintContinued (btype, tmp);
  171. }
  172.  
  173.  
  174. /*
  175.  *    PrintDef () -- Handles special cases (like line continuation) when 
  176.  *               printing definitions.
  177.  *
  178.  */
  179. void
  180. PrintDef (btype, dstr)
  181. register enum bdefs btype;    /* block type (output line type) */
  182. register char *dstr;        /* definition string         */
  183. {
  184.     register char *tmp;
  185.  
  186.     if (dstr == (char *)NULL)
  187.         dstr = "";
  188.  
  189.     for (tmp = dstr; *tmp != '\0'; tmp++)     /* search for line continuations */
  190.         if ((*tmp == '\\') && (*++tmp == '\n'))
  191.             if (btype != def_header) {
  192.                 ErrorReport ("Non-header string contains line continuation\n");
  193.                 return;
  194.             } else
  195.                 break;
  196.  
  197.     /*
  198.      *  Perform case by case handling of definition printing.
  199.      *
  200.      */
  201.     switch (btype) {
  202.         case def_header :  if (*tmp-- == '\n') {
  203.                     *tmp = '\0';
  204.                     if (tmp - dstr >= MAXLINE)
  205.                         PrintWarning ("Header may be too long.\n", 
  206.                                   (char *) NULL);
  207.                     printf ("%s\n\t", dstr);
  208.                     tmp += 2;
  209.                         PrintDef (def_header, tmp);
  210.                    } else {
  211.                     if (strlen (dstr) >= MAXLINE)
  212.                         PrintWarning ("Header may be too long.\n", 
  213.                                   (char *) NULL);
  214.                     printf ("%s\n", dstr);
  215.                    }
  216.                    break;
  217.  
  218.         case def_mailer :  if (strlen (dstr) >= MAXLINE)
  219.                     PrintWarning ("Mailer definition may be too long.\n", 
  220.                               (char *) NULL);
  221.                    printf ("%s\n", dstr);
  222.                    break;
  223.  
  224.         case def_ruleset:  if (strlen (dstr) >= MAXLINE)
  225.                     PrintWarning ("Rewriting rule may be too long.\n", 
  226.                               (char *) NULL);
  227.                    printf ("%s\n", dstr);
  228.                    break;
  229.  
  230.         case def_option :  if (strlen (dstr) >= MAXLINE)
  231.                     PrintWarning ("Option assignment may be too long.\n", 
  232.                               (char *) NULL);
  233.                    printf ("%s\n", dstr);
  234.                    break;
  235.  
  236.         case def_macro  :  if (strlen (dstr) >= MAXLINE)
  237.                     PrintWarning ("Macro assignment may be too long.\n", 
  238.                               (char *) NULL);
  239.                    printf ("%s\n", dstr);
  240.                    break;
  241.  
  242.         case def_prec   :  if (strlen (dstr) >= MAXLINE)
  243.                     PrintWarning ("Precedence relation may be too long.\n", 
  244.                               (char *) NULL);
  245.                    printf ("%s\n", dstr);
  246.                    break;
  247.  
  248.         case def_trusted:
  249.         case def_class  :  if (strlen (dstr) < REGLINE)
  250.                     printf ("%s\n", dstr);
  251.                    else        /* use line continuation feature */
  252.                        PrintContinued (btype, dstr);
  253.                    break;
  254.  
  255.         default         :  FatalError ("Invalid case in PrintDef ()", (char *) NULL);
  256.     }
  257. }
  258.  
  259.  
  260. /*
  261.  *    StartRuleset () -- Prints a ruleset heading for the ruleset identifier
  262.  *                   contained in the argument rsid.
  263.  *
  264.  */
  265. void
  266. StartRuleset (rsid)
  267. register struct he *rsid;    /* ruleset identifier */
  268. {
  269.     if (!ISRULESET(rsid->idtype))
  270.         if (ISTYPED(rsid->idtype))
  271.             PrintError ("Identifier not of ruleset type: %s", rsid->psb);
  272.         else
  273.             PrintError ("Ruleset identifier not bound to a number: %s", rsid->psb);
  274.     else {
  275.         if (ISRULESET(rsid->idd))
  276.             PrintWarning ("Redefining ruleset %s.\n", rsid->psb);
  277.         rsid->idd |= ID_RULESET;
  278.         printf ("S%s\n", rsid->idval.rsn);
  279.     }
  280. }
  281.