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

  1. /* syn_policy.c: */
  2.  
  3. # ifndef lint
  4. static char Rcsid[] = "@(#)$Header: /xtel/pp/pp-beta/Chans/lists/RCS/syn_policy.c,v 6.0 1991/12/18 20:10:43 jpo Rel $";
  5. # endif
  6.  
  7. /*
  8.  * $Header: /xtel/pp/pp-beta/Chans/lists/RCS/syn_policy.c,v 6.0 1991/12/18 20:10:43 jpo Rel $
  9.  *
  10.  * $Log: syn_policy.c,v $
  11.  * Revision 6.0  1991/12/18  20:10:43  jpo
  12.  * Release 6.0
  13.  *
  14.  */
  15.  
  16.  
  17.  
  18. #include "dlist.h"
  19. #include <isode/cmd_srch.h>
  20.  
  21. static CMD_TABLE expand_table [] = {
  22.     "FALSE",    FALSE,
  23.     "TRUE",        TRUE,
  24.     0,        -1,
  25. };
  26.  
  27. static CMD_TABLE convert_table [] = {
  28.     "ORIGINAL",    DP_ORIGINAL,
  29.     "FALSE",    DP_FALSE,
  30.     "TRUE",        DP_TRUE,
  31.     0,        -1,
  32. };
  33.  
  34. static CMD_TABLE priority_table [] = {
  35.     "ORIGINAL",    DP_ORIGINAL,
  36.     "LOW",        DP_LOW,
  37.     "NORMAL",    DP_NORMAL,
  38.     "HIGH",        DP_HIGH,
  39.     0,        -1,
  40. };
  41.  
  42. static dl_policy_free (ptr)
  43. struct dl_policy * ptr;
  44. {
  45.     free ((char *) ptr);
  46. }
  47.  
  48.  
  49. static struct dl_policy * dl_policy_cpy (a)
  50. struct dl_policy * a;
  51. {
  52. struct dl_policy * result;
  53.  
  54.     result = (struct dl_policy *) smalloc (sizeof (struct dl_policy));
  55.     *result = *a;        /* struct copy */
  56.     return (result);
  57. }
  58.  
  59. static dl_policy_cmp (a,b)
  60. struct dl_policy * a;
  61. struct dl_policy * b;
  62. {
  63.     if (a == (struct dl_policy *) NULL)
  64.         if (b == (struct dl_policy *) NULL)
  65.             return (0);
  66.         else 
  67.             return (-1);
  68.  
  69.     if (b == (struct dl_policy *) NULL)
  70.         return 1;
  71.  
  72.     if (a->dp_expand != b->dp_expand)
  73.         return ( a->dp_expand > b->dp_expand ? 1 : -1);
  74.  
  75.     if (a->dp_priority != b->dp_priority)
  76.         return ( a->dp_priority > b->dp_priority ? 1 : -1);
  77.  
  78.     if (a->dp_convert != b->dp_convert)
  79.         return ( a->dp_convert > b->dp_convert ? 1 : -1);
  80.  
  81.     return (0);
  82. }
  83.  
  84.  
  85. static dl_policy_print (ps,p,format)
  86. register PS ps;
  87. struct   dl_policy* p;
  88. int format;
  89. {
  90.  
  91.     if (format == READOUT)
  92.         ps_print (ps,"Expansion: ");
  93.  
  94.     ps_printf (ps,"%s",rcmd_srch(p->dp_expand,expand_table));
  95.  
  96.     if (format == READOUT)
  97.         ps_print (ps,", Conversion: ");
  98.     else
  99.         ps_print (ps,"$");
  100.  
  101.     ps_printf (ps,"%s",rcmd_srch(p->dp_convert,convert_table));
  102.  
  103.     if (format == READOUT)
  104.         ps_print (ps,", Priority: ");
  105.     else
  106.         ps_print (ps,"$");
  107.  
  108.     ps_printf (ps,"%s",rcmd_srch(p->dp_priority,priority_table));
  109. }
  110.  
  111. static struct dl_policy* str2dl_policy (str)
  112. char * str;
  113. {
  114. struct dl_policy * result;
  115. char * ptr;
  116. char * mark = NULLCP;
  117. char * prtparse ();
  118.  
  119.  
  120.  
  121.     if ( (ptr=index (str,'$')) == NULLCP) {
  122.         parse_error ("seperator missing in dl_policy '%s'",str);
  123.         return ((struct dl_policy *) NULL);
  124.     }
  125.  
  126.     result = (struct dl_policy *) smalloc (sizeof (struct dl_policy));
  127.     *ptr--= 0;
  128.     if (isspace (*ptr)) {
  129.         *ptr = 0;
  130.         mark = ptr;
  131.     }
  132.     ptr++;
  133.  
  134.     if (*str == 0)
  135.         result->dp_expand = TRUE;
  136.     else if ((result->dp_expand = cmd_srch(str,expand_table)) == -1) {
  137.         parse_error ("%s unrecognised",str);
  138.                 return ((struct dl_policy *) NULL);
  139.     }
  140.     *ptr++ = '$';
  141.  
  142.     if (mark != NULLCP)
  143.         *mark = ' ';
  144.  
  145.     str = SkipSpace(ptr);    
  146.  
  147.     if ( (ptr=index (str,'$')) == NULLCP) {
  148.         parse_error ("2nd seperator missing in dl_policy '%s'",str);
  149.         return ((struct dl_policy *) NULL);
  150.     }
  151.  
  152.     *ptr--= 0;
  153.     if (isspace (*ptr)) {
  154.         *ptr = 0;
  155.         mark = ptr;
  156.     } else
  157.         mark = NULLCP;
  158.  
  159.     ptr++;
  160.  
  161.     if (*str == 0)
  162.         result->dp_convert = DP_ORIGINAL;
  163.     else if ((result->dp_convert = cmd_srch(str,convert_table)) == -1) {
  164.         parse_error ("%s unrecognised (2)",str);
  165.                 return ((struct dl_policy *) NULL);
  166.     }
  167.  
  168.     *ptr++ = '$';
  169.  
  170.     if (mark != NULLCP)
  171.         *mark = ' ';
  172.  
  173.     ptr = SkipSpace (ptr);
  174.  
  175.     if (*ptr == 0)
  176.         result->dp_priority = DP_LOW;
  177.     else if ((result->dp_priority = cmd_srch(ptr,priority_table)) == -1) {
  178.         parse_error ("%s unrecognised (3)",ptr);
  179.                 return ((struct dl_policy *) NULL);
  180.     }
  181.  
  182.     return (result);
  183. }
  184.  
  185. static PE dl_policy_enc (m)
  186. struct dl_policy * m;
  187. {
  188. PE ret_pe;
  189.  
  190.         (void) encode_DL_DlPolicy (&ret_pe,0,0,NULLCP,m);
  191.  
  192.     return (ret_pe);
  193. }
  194.  
  195. static struct dl_policy * dl_policy_dec (pe)
  196. PE pe;
  197. {
  198.     struct dl_policy * m;
  199.  
  200.     if (decode_DL_DlPolicy (pe,1,NULLIP,NULLVP,&m) == NOTOK) {
  201.         free ((char *)m);
  202.         return ((struct dl_policy *) NULL);
  203.     }
  204.     return (m);
  205. }
  206.  
  207. policy_syntax ()
  208. {
  209.     (void) add_attribute_syntax ("DlPolicy",
  210.         (IFP) dl_policy_enc,    (IFP) dl_policy_dec,
  211.         (IFP) str2dl_policy,    dl_policy_print,
  212.         (IFP) dl_policy_cpy,    dl_policy_cmp,
  213.         dl_policy_free,        NULLCP,
  214.         NULLIFP,        TRUE);
  215. }
  216.