home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pp / pp-6.0 / Lib / or / or_basic.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-18  |  3.0 KB  |  153 lines

  1. /* or_basic.c: basic low level or structure manipulation */
  2.  
  3. # ifndef lint
  4. static char Rcsid[] = "@(#)$Header: /xtel/pp/pp-beta/Lib/or/RCS/or_basic.c,v 6.0 1991/12/18 20:23:08 jpo Rel $";
  5. # endif
  6.  
  7. /*
  8.  * $Header: /xtel/pp/pp-beta/Lib/or/RCS/or_basic.c,v 6.0 1991/12/18 20:23:08 jpo Rel $
  9.  *
  10.  * $Log: or_basic.c,v $
  11.  * Revision 6.0  1991/12/18  20:23:08  jpo
  12.  * Release 6.0
  13.  *
  14.  */
  15.  
  16.  
  17.  
  18. #include "or.h"
  19. #include "util.h"
  20.  
  21.  
  22. OR_ptr or_new (type, ddname, value)
  23. int type;
  24. char *ddname;
  25. char *value;
  26. {
  27.     int enc = or_type2charset (type);
  28.     char *cp;
  29.     
  30.     if (strcmp(value, "@") == 0) 
  31.         return or_new_aux(type, ddname, value, OR_ENC_PP);
  32.  
  33.     switch (enc) {
  34.         case OR_ENC_TTX_AND_OR_PS:
  35.         for (cp = value; *cp; cp ++) {
  36.             if (!or_isps (*cp)) {
  37.                 if (*cp == '*') {
  38.                     if(cp == value)
  39.                         enc = OR_ENC_TTX;
  40.                     /* else stay as you were */
  41.                 }
  42.                 (void) or_lose ("Bad string syntax %s",
  43.                         value);
  44.                 return NULLOR;
  45.             }
  46.         }
  47.         if (*cp == '\0')
  48.             enc = OR_ENC_PS;
  49.         break;
  50.         case OR_ENC_PS:
  51.         case OR_ENC_NUM:
  52.         case OR_ENC_TTX:
  53.         case OR_ENC_INT:
  54.         case OR_ENC_PSAP:
  55.         case OR_ENC_PP:
  56.         break;
  57.         default:
  58.         PP_LOG (LLOG_EXCEPTIONS,
  59.             ("Unknown encoding for type %d val %s",
  60.              type, value));
  61.     }
  62.     return or_new_aux (type, ddname, value, enc);
  63. }
  64.             
  65. OR_ptr or_new_aux (type, ddname, value, encoding)
  66. int     type;
  67. char    *ddname;
  68. char    *value;
  69. int     encoding;
  70. {
  71.     OR_ptr      or;
  72.  
  73.     PP_DBG (("or_util.c/or_new ('%d', '%s', '%s')",
  74.          type, ddname ? ddname : "<none>",
  75.          value ? value : "<none>"));
  76.  
  77.     switch (encoding) { /* check the easy ones */
  78.     case OR_ENC_PS:
  79.         if (!or_str_isps (value)) {
  80.             (void) or_lose ("Not a printable string %s", value);
  81.             return NULLOR;
  82.         }
  83.         if (type == OR_DD && !or_str_isps (ddname)) {
  84.             (void) or_lose ("DD type %s not a printable string",
  85.                     ddname);
  86.             return NULLOR;
  87.         }
  88.         break;
  89.     case OR_ENC_NUM:
  90.         if (!or_str_isns (value)) {
  91.             (void) or_lose ("Not a numeric string %s", value);
  92.             return NULLOR;
  93.         }
  94.         break;
  95.     default:
  96.         break;
  97.     }
  98.     or = (OR_ptr) smalloc (sizeof (struct or_part));
  99.     if (or == NULLOR)
  100.     return NULLOR;
  101.  
  102.     or -> or_type = type;
  103.     or -> or_encoding = encoding;
  104.     or -> or_next = NULLOR;
  105.     or -> or_prev = NULLOR;
  106.  
  107.     if (type != OR_DD ) {
  108.     or -> or_ddname = NULLCP;
  109.     or -> or_value = strdup (value);
  110.     }
  111.     else {
  112.     or -> or_ddname = strdup (ddname);
  113.     or -> or_value = strdup (value);
  114.     }
  115.     return (or);
  116. }
  117.  
  118. OR_ptr or_dup (or)
  119. OR_ptr or;
  120. {
  121.     return (or_new_aux (or -> or_type, or -> or_ddname,
  122.             or -> or_value, or -> or_encoding));
  123. }
  124.  
  125. OR_ptr or_tdup (or)
  126. OR_ptr or;
  127. {
  128.     OR_ptr new = NULLOR;
  129.  
  130.     if (or == NULLOR)
  131.     return NULLOR;
  132.     new = or_dup (or);
  133.     new -> or_next = or_tdup (or -> or_next);
  134.     if (new -> or_next)
  135.     new -> or_next -> or_prev = new;
  136.     return new;
  137. }
  138.  
  139. void or_free (tree)
  140. OR_ptr  tree;
  141. {
  142.     if (tree == NULLOR)
  143.         return;
  144.  
  145.     if (tree -> or_next)
  146.         or_free (tree -> or_next);
  147.     if (tree -> or_value)
  148.         free (tree -> or_value);
  149.     if (tree -> or_ddname)
  150.         free (tree -> or_ddname);
  151.     free ((char *)tree);
  152. }
  153.