home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume17 / ease2 / part01 / src / idman.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-02-08  |  5.5 KB  |  219 lines

  1. /*    $Header: idman.c,v 2.0 88/06/15 14:42:14 root Exp $    */
  2.  
  3. /*
  4.  * $Log:    idman.c,v $
  5.  * Revision 2.0  88/06/15  14:42:14  root
  6.  * Baseline release for net posting. ADR.
  7.  * 
  8.  */
  9.  
  10. /*
  11.  *      idman.c    -- Contains routines for manipulating identifiers and their
  12.  *           symbolic associations.
  13.  *
  14.  *      author    -- James S. Schoner, Purdue University Computing Center,
  15.  *                     West Lafayette, Indiana  47907
  16.  *
  17.  *      date    -- July 9, 1985
  18.  *
  19.  *    Copyright (c) 1985 by Purdue Research Foundation
  20.  *
  21.  *    All rights reserved.
  22.  *
  23.  */
  24.  
  25. #include <stdio.h>
  26. #include "symtab.h"
  27. #include "fixstrings.h"
  28.  
  29. extern struct he *LookupSymbol ();
  30. extern void      FatalError (),
  31.           ErrorReport (),
  32.           PrintWarning (),
  33.           PrintError ();
  34.  
  35. short Uchar = 'A';            /* for unique macro names */
  36.  
  37.  
  38. /*
  39.  *    UniqMac () -- Assigns and returns a unique one-character macro
  40.  *              name (upper-case) for an Ease macro name.
  41.  *
  42.  */
  43. char
  44. UniqMac (phe)
  45. struct he *phe;        /* symbol table entry for Ease macro */
  46. {
  47.     if ((phe->idval.idc = Uchar++) > 'Z')
  48.         FatalError ("Too many macro names (26 max)", (char *) NULL);
  49.     return (phe->idval.idc);
  50. }
  51.  
  52.  
  53. /*
  54.  *    BindID () -- Binds either a ruleset or precedence identifier (phe) to
  55.  *              an integer (vid).  The id type distinction is passed in
  56.  *             the parameter idt.
  57.  *
  58.  */
  59. void
  60. BindID (phe, vid, idt)
  61. register struct he *phe;    /* symbol table entry for an identifier    */
  62. int vid;            /* value of the identifier           */
  63. unsigned idt;            /* identifier type (ruleset or precedence) */
  64. {
  65.     if (ISTYPED(phe->idtype)) {    /* should be undefined */
  66.         PrintWarning ("Redeclaration of %s.\n", phe->psb);
  67.         phe->idtype = ID_UNTYPED;
  68.     }
  69.     phe->idtype |= idt;        /* make defined           */
  70.     if (ISRULESET(phe->idtype)) {
  71.         if (vid > VALRSNMAX) {
  72.             ErrorReport ("Ruleset number too large.\n");
  73.             return;
  74.         } else if (vid < 0) {
  75.             ErrorReport ("Ruleset number must be non-negative.\n");
  76.             return;
  77.         }
  78.         sprintf (phe->idval.rsn, "%d", vid);
  79.     } else 
  80.         phe->idval.prec = vid;
  81. }
  82.  
  83.  
  84. /*
  85.  *    CheckRS () -- Checks validity of a ruleset identifier (phe) and 
  86.  *              returns the ruleset string to which the identifier
  87.  *              is bound.  If the ruleset identifier is invalid, the
  88.  *              null string is returned.
  89.  *
  90.  */
  91. char *
  92. CheckRS (phe)
  93. struct he *phe;        /* symbol table entry for ruleset identifier */
  94. {
  95.     if (!ISRULESET(phe->idtype)) {
  96.         if (!ISTYPED(phe->idtype))
  97.             PrintError ("Ruleset identifier not bound to a number:", phe->psb);
  98.         else
  99.             PrintError ("Identifier not of ruleset type:", phe->psb);
  100.         return (NULL);
  101.     } else
  102.         return (phe->idval.rsn);
  103. }
  104.  
  105.  
  106. /*
  107.  *    MakeMac () -- Declare a macro name (pmac) as a class and/or macro type 
  108.  *              (targtype) and return the unique cf character assigned 
  109.  *              to it.
  110.  *
  111.  */
  112. char
  113. MakeMac (pmac, targtype)
  114. register struct he *pmac;    /* symbol table entry for macro identifier */
  115. unsigned targtype;        /* target declaration type for the macro   */
  116. {
  117.     /*
  118.      *    An Ease macro may be declared as both a singular macro and
  119.      *    a class macro.
  120.      *
  121.      */
  122.     if (ISMACRO(pmac->idtype) || ISCLASS(pmac->idtype)) {
  123.         pmac->idtype |= targtype;
  124.         return (pmac->idval.idc);
  125.     }
  126.     if (ISTYPED(pmac->idtype)) {    /* not a macro or class id */
  127.         PrintError ("Redeclaring or using as macro or class:", pmac->psb);
  128.         return ('\0');
  129.     }
  130.     pmac->idtype |= targtype;    /* previously untyped; declare here */
  131.     return (UniqMac (pmac));
  132. }
  133.     
  134.  
  135. /*
  136.  *    GetField () -- Returns a field type string given a field 
  137.  *               identifier (fid).
  138.  *
  139.  */
  140. char *
  141. GetField (fid)
  142. register struct he *fid;    /* field identifier */
  143. {
  144.     if (!ISFIELD(fid->idtype)) {
  145.         PrintError ("Field type not defined for", fid->psb);
  146.         return (NULL);
  147.     } else 
  148.         return (fid->idval.fstring);
  149. }
  150.  
  151.  
  152. /*
  153.  *    CheckMailer () -- Declares a mailer identifier (mid) as type mailer,
  154.  *              checking that the identifier was not previously 
  155.  *              declared a different type. 
  156.  *
  157.  */
  158. char *
  159. CheckMailer (mid)
  160. register struct he *mid;
  161. {
  162.     if (ISTYPED (mid->idtype) && !ISMAILER (mid->idtype)) {
  163.         PrintError ("Redeclaration as mailer:", mid->psb);
  164.         return (NULL);
  165.     }
  166.     mid->idtype |= ID_MAILER;
  167.     return (mid->psb);
  168. }
  169.  
  170.  
  171. /*
  172.  *    AssignType () -- Assigns to each field identifier in fidlist the
  173.  *             type (in string form) fidtype.  This is accomplished
  174.  *             by making each field identifier symbol table entry
  175.  *             "point" to the type found in fidtype.
  176.  *
  177.  */
  178. void
  179. AssignType (fidlist, fidtype)
  180. register char *fidlist;        /* field identifier list, blank separated */
  181. char *fidtype;            /* field identifier type string          */
  182. {
  183.     register struct he *fid;    /* pointer to a field identifier  */
  184.     char *fres;            /* field type result string      */
  185.     register char *srch;        /* fidlist search pointer      */
  186.     char  sep;            /* fidlist separator character    */
  187.  
  188.     fres = (char *) malloc (strlen (fidtype) + 1);
  189.     if (fres == NULL)
  190.         FatalError ("System out of string space in AssignType ()", (char *) NULL);
  191.     strcpy (fres, fidtype);        /* make clean copy of string type */
  192.  
  193.     /*
  194.      *    Search for all field identifiers and make the type assignment. 
  195.       *
  196.      */
  197.     srch = fidlist;
  198.     while (*srch != '\0') {
  199.         while ((*++srch != ' ') && (*srch != '\0'))
  200.             /* null */ ;
  201.         if (*fidlist != '\0') {                /* found a field id       */
  202.             sep = *srch;
  203.             *srch = '\0';
  204.             fid = LookupSymbol (fidlist);    /* get symbol table entry */
  205.             if (ISFIELD(fid->idtype)) {
  206.                 if (strcmp (fid->idval.fstring, fres))
  207.                     PrintWarning ("Redefinition of field type for %s.\n", fid->psb);
  208.             } else if (ISTYPED(fid->idtype)) {
  209.                 PrintError ("Redeclaration of identifier as a field:", fid->psb);
  210.                 return;
  211.             }
  212.             fid->idtype |= ID_FIELD;    /* type the identifier    */
  213.             fid->idval.fstring = fres;    /* type the field      */
  214.             if ((*srch = sep) != '\0')
  215.                 fidlist = ++srch;
  216.         }
  217.     }
  218. }
  219.