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

  1. #ifdef FLUKE
  2. # ifndef LINT
  3.     static char RCSid[] = "@(#)FLUKE  $Header: /home/kreskin/u0/barnett/Src/Ease/ease/src/RCS/idman.c,v 3.2 1991/10/15 17:02:04 barnett Exp $";
  4. # endif LINT
  5. #endif FLUKE
  6.  
  7. /*
  8.  *      idman.c    -- Contains routines for manipulating identifiers and their
  9.  *           symbolic associations.
  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: idman.c,v $
  21.  * Revision 3.2  1991/10/15  17:02:04  barnett
  22.  * Detect if (one_or_more) next ($2) error
  23.  *
  24.  * Revision 3.1  1991/02/25  22:09:52  barnett
  25.  * Fixed some portability problems
  26.  *
  27.  * Revision 3.0  1991/02/22  18:50:27  barnett
  28.  * Added support for HP/UX and IDA sendmail.
  29.  *
  30.  * Revision 2.1  1990/01/30  14:33:52  jeff
  31.  * Bruce Barnett - changed UniqMac.
  32.  *
  33.  * Revision 2.0  88/06/15  14:42:14  root
  34.  * Baseline release for net posting. ADR.
  35.  */
  36.  
  37. #include <stdio.h>
  38. #include <ctype.h>
  39. #include "symtab.h"
  40. #include "fixstrings.h"
  41.  
  42. extern struct he *LookupSymbol ();
  43. extern void      FatalError (),
  44.           ErrorReport (),
  45.           PrintWarning (),
  46.           PrintError ();
  47. extern char *      malloc ();
  48. extern short number_of_fields;    /* number of fields on a ruleset */
  49.  
  50. char    IDused[] = "                          "; /* 26 blanks */
  51. /*
  52.  *    UniqMac () -- Assigns and returns a unique one-character macro
  53.  *              name (upper-case) for an Ease macro name.
  54.  *
  55.  *    Bruce Barnett:
  56.  *    Special enhancement - if idval is a single character,
  57.  *    and the corresponding letter has not been assigned,
  58.  *    Make the idc character the same as the macro name 
  59.  *
  60.  *    This makes it nice to test cfc/ease completeness.
  61.  *    Also makes reading the ease output easier.
  62.  *
  63.  */
  64. char
  65. UniqMac (phe)
  66. struct he *phe;        /* symbol table entry for Ease macro */
  67. {
  68.     short i;
  69.  
  70.     if ((strlen(phe->psb) == 1) && 
  71.     isupper(*(phe->psb)) &&
  72.     IDused[*(phe->psb) - 'A'] == ' ' ) {
  73.     IDused[*(phe->psb) - 'A'] = (phe->idval.idc) = *(phe->psb);
  74.     } else {
  75.     for (i=0;i<26 && IDused[i] != ' ';i++) 
  76.       ;    /* find first unused letter */
  77.     if (i==26) FatalError ("Too many macro names (26 max)", (char *) NULL);
  78.     IDused[i] = 
  79.       (phe->idval.idc) = 
  80.         'A' + i;
  81.     }
  82.     return (phe->idval.idc);
  83. }
  84.  
  85.  
  86. /*
  87.  *    BindID () -- Binds either a ruleset or precedence identifier (phe) to
  88.  *              an integer (vid).  The id type distinction is passed in
  89.  *             the parameter idt.
  90.  *
  91.  */
  92. void
  93. BindID (phe, vid, idt)
  94. register struct he *phe;    /* symbol table entry for an identifier    */
  95. int vid;            /* value of the identifier           */
  96. unsigned idt;            /* identifier type (ruleset or precedence) */
  97. {
  98.     if (ISTYPED(phe->idtype)) {    /* should be undefined */
  99.         PrintWarning ("Redeclaration of %s.\n", phe->psb);
  100.         phe->idtype = ID_UNTYPED;
  101.     }
  102.     phe->idtype |= idt;        /* make defined           */
  103.     if (ISRULESET(phe->idtype)) {
  104.         if (vid > VALRSNMAX) {
  105.             ErrorReport ("Ruleset number too large.\n");
  106.             return;
  107.         } else if (vid < 0) {
  108.             ErrorReport ("Ruleset number must be non-negative.\n");
  109.             return;
  110.         }
  111.         sprintf (phe->idval.rsn, "%d", vid);
  112.     } else 
  113.         phe->idval.prec = vid;
  114. }
  115.  
  116.  
  117. /*
  118.  *    CheckRS () -- Checks validity of a ruleset identifier (phe) and 
  119.  *              returns the ruleset string to which the identifier
  120.  *              is bound.  If the ruleset identifier is invalid, the
  121.  *              null string is returned.
  122.  *
  123.  */
  124. char *
  125. CheckRS (phe)
  126. struct he *phe;        /* symbol table entry for ruleset identifier */
  127. {
  128.     if (!ISRULESET(phe->idtype)) {
  129.         if (!ISTYPED(phe->idtype))
  130.             PrintError ("Ruleset identifier not bound to a number: %s", phe->psb);
  131.         else
  132.             PrintError ("Identifier not of ruleset type: %s", phe->psb);
  133.         return (NULL);
  134.     } else
  135.         return (phe->idval.rsn);
  136. }
  137.  
  138.  
  139. /*
  140.  *    MakeMac () -- Declare a macro name (pmac) as a class and/or macro type 
  141.  *              (targtype) and return the unique cf character assigned 
  142.  *              to it.
  143.  *
  144.  */
  145. char
  146. MakeMac (pmac, targtype)
  147. register struct he *pmac;    /* symbol table entry for macro identifier */
  148. unsigned targtype;        /* target declaration type for the macro   */
  149. {
  150.     /*
  151.      *    An Ease macro may be declared as both a singular macro and
  152.      *    a class macro.
  153.      *
  154.      */
  155.     if (ISMACRO(pmac->idtype) || ISCLASS(pmac->idtype)) {
  156.         pmac->idtype |= targtype;
  157.         return (pmac->idval.idc);
  158.     }
  159.     if (ISTYPED(pmac->idtype)) {    /* not a macro or class id */
  160.         PrintError ("Redeclaring or using as macro or class: %s", pmac->psb);
  161.         return ('\0');
  162.     }
  163.     pmac->idtype |= targtype;    /* previously untyped; declare here */
  164.     return (UniqMac (pmac));
  165. }
  166.     
  167.  
  168. /*
  169.  *    GetField () -- Returns a field type string given a field 
  170.  *               identifier (fid).
  171.  *
  172.  */
  173. char *
  174. GetField (fid)
  175. register struct he *fid;    /* field identifier */
  176. {
  177.     if (!ISFIELD(fid->idtype)) {
  178.         PrintError ("Field type not defined for %s", fid->psb);
  179.         return (NULL);
  180.     } else {
  181.         number_of_fields++;
  182.         return (fid->idval.fstring);
  183.     }
  184. }
  185.  
  186.  
  187. /*
  188.  *    CheckMailer () -- Declares a mailer identifier (mid) as type mailer,
  189.  *              checking that the identifier was not previously 
  190.  *              declared a different type. 
  191.  *
  192.  */
  193. char *
  194. CheckMailer (mid)
  195. register struct he *mid;
  196. {
  197.     if (ISTYPED (mid->idtype) && !ISMAILER (mid->idtype)) {
  198.         PrintError ("Redeclaration as mailer: %s", mid->psb);
  199.         return (NULL);
  200.     }
  201.     mid->idtype |= ID_MAILER;
  202.     return (mid->psb);
  203. }
  204.  
  205.  
  206. /*
  207.  *    AssignType () -- Assigns to each field identifier in fidlist the
  208.  *             type (in string form) fidtype.  This is accomplished
  209.  *             by making each field identifier symbol table entry
  210.  *             "point" to the type found in fidtype.
  211.  *
  212.  */
  213. void
  214. AssignType (fidlist, fidtype)
  215. register char *fidlist;        /* field identifier list, blank separated */
  216. char *fidtype;            /* field identifier type string          */
  217. {
  218.     register struct he *fid;    /* pointer to a field identifier  */
  219.     char *fres;            /* field type result string      */
  220.     register char *srch;        /* fidlist search pointer      */
  221.     char  sep;            /* fidlist separator character    */
  222.  
  223.     fres = (char *) malloc (strlen (fidtype) + 1);
  224.     if (fres == NULL)
  225.         FatalError ("System out of string space in AssignType ()", (char *) NULL);
  226.     strcpy (fres, fidtype);        /* make clean copy of string type */
  227.  
  228.     /*
  229.      *    Search for all field identifiers and make the type assignment. 
  230.       *
  231.      */
  232.     srch = fidlist;
  233.     while (*srch != '\0') {
  234.         while ((*++srch != ' ') && (*srch != '\0'))
  235.             /* null */ ;
  236.         if (*fidlist != '\0') {                /* found a field id       */
  237.             sep = *srch;
  238.             *srch = '\0';
  239.             fid = LookupSymbol (fidlist);    /* get symbol table entry */
  240.             if (ISFIELD(fid->idtype)) {
  241.                 if (strcmp (fid->idval.fstring, fres))
  242.                     PrintWarning ("Redefinition of field type for %s.\n", fid->psb);
  243.             } else if (ISTYPED(fid->idtype)) {
  244.                 PrintError ("Redeclaration of identifier as a field: %s", fid->psb);
  245.                 return;
  246.             }
  247.             fid->idtype |= ID_FIELD;    /* type the identifier    */
  248.             fid->idval.fstring = fres;    /* type the field      */
  249.             if ((*srch = sep) != '\0')
  250.                 fidlist = ++srch;
  251.         }
  252.     }
  253. }
  254.