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

  1. /* or_add.c: add an orname component to the list */
  2.  
  3. # ifndef lint
  4. static char Rcsid[] = "@(#)$Header: /xtel/pp/pp-beta/Lib/or/RCS/or_add.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_add.c,v 6.0 1991/12/18 20:23:08 jpo Rel $
  9.  *
  10.  * $Log: or_add.c,v $
  11.  * Revision 6.0  1991/12/18  20:23:08  jpo
  12.  * Release 6.0
  13.  *
  14.  */
  15.  
  16.  
  17.  
  18. #include "util.h"
  19. #include "or.h"
  20.  
  21. OR_ptr or_add (tree, or, before)
  22. OR_ptr          tree;
  23. OR_ptr          or;
  24. int             before;    /* if true then add equal values at front */
  25. {
  26.     OR_ptr      current;
  27.     char    *name;
  28.     
  29.     /* this routine is horrible */
  30.     /* MUST be able to rewrite more efficiently */
  31.  
  32.     PP_DBG (("or_util.c/or_add ('%d', '%s')",
  33.       or -> or_type, or -> or_value));
  34.  
  35.     if (or == NULLOR)
  36.         return tree;
  37.  
  38.     if (tree == NULLOR) {
  39.     or -> or_next = NULLOR;
  40.     or -> or_prev = NULLOR;
  41.     return (or);
  42.     }
  43.  
  44.     if (or -> or_type == OR_OU) {
  45.         int    ou_count = 1;
  46.         /* check for exceding upper limit */
  47.         for (current = tree; 
  48.          current != NULLOR && current->or_type <= OR_OU; 
  49.          current = current -> or_next) 
  50.             if (current->or_type == OR_OU)
  51.                 ou_count++;
  52.         if (ou_count > MAX_OU) {
  53.             (void) or_lose("Exceeds upperbound on the number of OrganizataionalUnits (%d OUs)",
  54.                 MAX_OU);
  55.             return NULLOR;
  56.         }
  57.     } else if (or -> or_type == OR_DD) {
  58.         int    dda_count = 1;
  59.         /* check for exceding upper limit */
  60.         for (current = tree; 
  61.          current != NULLOR && current->or_type <= OR_DD;
  62.          current = current -> or_next) 
  63.             if (current->or_type == OR_DD)
  64.                 dda_count++;
  65.         if (dda_count > MAX_DDA) {
  66.             (void) or_lose("Exceeds upperbound on the number of Domain Defined Attributes (%d DDAs)",
  67.                 MAX_DDA);
  68.             return NULLOR;
  69.         }
  70.     }
  71.  
  72.  
  73.     if (or -> or_type < tree -> or_type) {
  74.     or -> or_next = tree;
  75.     tree -> or_prev = or;
  76.     or -> or_prev = NULLOR;
  77.     return (or);
  78.     }
  79.  
  80.  
  81.     if (or -> or_type == tree -> or_type) {
  82.  
  83.     if (or -> or_type != OR_OU && or -> or_type != OR_DD) {
  84.         if ((name = or_type2name (or -> or_type)) == NULLCP) 
  85.             (void) or_lose("Illegal duplicate component type '%d' (%s & %s)",
  86.                  or -> or_type,
  87.                  or -> or_value, tree -> or_value);
  88.         else
  89.             (void) or_lose("Illegal duplicate component type '%s' (%s & %s)",
  90.                  name,
  91.                  or -> or_value, tree -> or_value);
  92.  
  93.         return NULLOR;
  94.     }
  95.  
  96.     if (before) {
  97.         or -> or_next = tree;
  98.         tree -> or_prev = or;
  99.         or -> or_prev = NULLOR;
  100.         return (or);
  101.     }
  102.     }
  103.  
  104.  
  105.     for (current = tree; current != NULLOR; current = current -> or_next) {
  106.  
  107.     if (current -> or_next == NULLOR) {
  108.         current -> or_next = or;
  109.         or -> or_prev = current;
  110.         or -> or_next = NULLOR;
  111.         return (tree);
  112.     }
  113.  
  114.     if (or -> or_type < current -> or_next -> or_type) {
  115.         or -> or_next = current -> or_next;
  116.         current -> or_next -> or_prev = or;
  117.         or -> or_prev = current;
  118.         current -> or_next = or;
  119.         return (tree);
  120.     }
  121.  
  122.     if (or -> or_type == current -> or_next -> or_type) {
  123.  
  124.         if (or -> or_type != OR_OU && or -> or_type != OR_DD) {
  125.             if ((name = or_type2name (or -> or_type)) == NULLCP) 
  126.                 (void) or_lose("Illegal duplicate type '%d' (%s & %s)",
  127.                     or->or_type,
  128.                     or->or_value, current->or_value);
  129.             else
  130.                 (void) or_lose ("Illegal duplicate type '%s' (%s & %s)",
  131.                      name,
  132.                      or -> or_value, 
  133.                      current -> or_value);
  134.             return NULLOR;
  135.         }
  136.  
  137.         if (before) {
  138.             or -> or_next = current -> or_next;
  139.             current -> or_next -> or_prev = or;
  140.             or -> or_prev = current;
  141.             current -> or_next = or;
  142.             return (tree);
  143.         }
  144.  
  145.     }            /* end of if */
  146.  
  147.     }  /* end of for */
  148.  
  149.  
  150.    PP_LOG (LLOG_EXCEPTIONS, ("or_util.c/or_add () - serious problem"));
  151.    return NULLOR;
  152. }
  153.  
  154. OR_ptr or_add_t61 (tree, type, value,len, before)
  155. OR_ptr tree;
  156. int    type;
  157. unsigned char    *value;
  158. int before;
  159. {
  160.     OR_ptr or;
  161.     char buf[BUFSIZ];
  162.     char buf2[BUFSIZ];
  163.  
  164.     or_t61encode (buf, value, len);
  165.     if ((or = or_locate (tree, type)) == NULLOR) {
  166.         (void) sprintf (buf2, "*%s", buf);
  167.         or = or_new_aux (type, NULLCP, buf2, OR_ENC_TTX);
  168.         return or_add (tree, or, before);
  169.     }
  170.  
  171.     if (or -> or_encoding != OR_ENC_PS) {
  172.         PP_LOG(LLOG_EXCEPTIONS, ("Encoding not plain PS"));
  173.         return NULLOR;
  174.     }
  175.  
  176.     (void) sprintf (buf2, "%s*%s", or -> or_value, buf);
  177.     or -> or_encoding = OR_ENC_TTX_AND_OR_PS;
  178.     if (or -> or_value)
  179.         free (or -> or_value);
  180.     or -> or_value = strdup (buf2);
  181.     return tree;
  182. }
  183.  
  184. void or_t61encode (buf, str, len)
  185. char    *buf;
  186. unsigned char *str;
  187. int len;
  188. {
  189.     int n;
  190.     int inbracket = 0;
  191.     char *p = buf;
  192.  
  193.     for (n = 0; n < len; n++) {
  194.         if (*str < 128 && or_isps(*str)) {
  195.             if (inbracket) {
  196.                 *p ++ = '}';
  197.                 inbracket = 0;
  198.             }
  199.             *p ++ = *str ++;
  200.         }
  201.         else {
  202.             if (! inbracket) {
  203.                 inbracket = 1;
  204.                 *p++ = '{';
  205.             }
  206.             *p++ = (*str) / 100 + '0';
  207.             *p++ = (unsigned char) ((*str) % 100) / 10 + '0';
  208.             *p++ = (*str++) % 10 + '0';
  209.         }
  210.     }
  211.     if (inbracket)
  212.         *p++ = '}';
  213.     *p = 0;
  214. }
  215.  
  216. struct qbuf *or_t61decode (str)
  217. char    *str;
  218. {
  219.     unsigned char buf[BUFSIZ];
  220.     unsigned char *p;
  221.     int n;
  222.     int inbracket = 0;
  223.  
  224.     for (n = 0, p = buf; *str; n++) {
  225.         if (inbracket) {
  226.             if (*str == '}') {
  227.                 inbracket = 0;
  228.                 str ++;
  229.             }
  230.             else {
  231.                 *p = (*str++ - '0') * 100;
  232.                 *p += (*str++ - '0') * 10;
  233.                 *p++ += (*str++ - '0');
  234.             }
  235.         }
  236.         else {
  237.             if (*str == '{') {
  238.                 inbracket = 1;
  239.                 str ++;
  240.             }
  241.             else
  242.                 *p++ = *str++;
  243.         }
  244.     }
  245.     p = 0;
  246.     return str2qb ((char *)buf, n, 1);
  247. }
  248.