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

  1. /* ap_t2p.c: split tree into major address parts */
  2.  
  3. # ifndef lint
  4. static char Rcsid[] = "@(#)$Header: /xtel/pp/pp-beta/Lib/addr/RCS/ap_t2p.c,v 6.0 1991/12/18 20:21:24 jpo Rel $";
  5. # endif
  6.  
  7. /*
  8.  * $Header: /xtel/pp/pp-beta/Lib/addr/RCS/ap_t2p.c,v 6.0 1991/12/18 20:21:24 jpo Rel $
  9.  *
  10.  * $Log: ap_t2p.c,v $
  11.  * Revision 6.0  1991/12/18  20:21:24  jpo
  12.  * Release 6.0
  13.  *
  14.  */
  15.  
  16.  
  17.  
  18. /*
  19. Record beginnings of major sections of an address
  20.  
  21.     Returns:    pointer to next node, after address
  22.          0 if end of tree
  23.         -1 if error
  24.  
  25. if both rroute and nroute are requested, and the tree has routing
  26. in reverse-path form, then these will point to the same node.
  27. */
  28.  
  29.  
  30.  
  31. #include "util.h"
  32. #include "ap.h"
  33.  
  34.  
  35. static int      person_level,
  36.         group_level;
  37.  
  38.  
  39.  
  40. /* ---------------------  Begin  Routines  -------------------------------- */
  41.  
  42.  
  43.  
  44. AP_ptr ap_t2p (tree, group, name, local, domain, route)
  45. register AP_ptr         tree;           /* -- the parse tree -- */
  46. AP_ptr                  *group,         /* -- start of group name -- */
  47.             *name,          /* -- start of person name -- */
  48.             *local,         /* -- start of local-part -- */
  49.             *domain,        /* -- basic domain reference -- */
  50.             *route;         /* -- start of 822 reverse route -- */
  51. {
  52.     AP_ptr          return_ptr,
  53.             start_ptr = tree;
  54.     int             got_local, got_first;
  55.  
  56.     PP_DBG (("Lib/addr/ap_t2p()"));
  57.     
  58.     group_level = 0;
  59.     person_level = 0;
  60.  
  61.     if (group  != (AP_ptr *) 0)             *group   = NULLAP;
  62.     if (name   != (AP_ptr *) 0)             *name    = NULLAP;
  63.     if (local  != (AP_ptr *) 0)             *local   = NULLAP;
  64.     if (domain != (AP_ptr *) 0)             *domain  = NULLAP;
  65.     if (route  != (AP_ptr *) 0)             *route   = NULLAP;
  66.  
  67.     /* -- ignore null stuff -- */
  68.     if (tree == NULLAP || tree -> ap_obtype == AP_NIL)
  69.         return ((AP_ptr) OK);
  70.  
  71.     got_first = FALSE;
  72.  
  73.     for (got_local = FALSE; ; tree = tree -> ap_next) {
  74.         /* -- print munged addr -- */
  75.         switch (tree -> ap_obtype) {
  76.             case AP_NIL:
  77.             return_ptr = NULLAP;
  78.             goto endit;
  79.  
  80.             case AP_PERSON_NAME:
  81.             person_level++;
  82.             if (name != (AP_ptr *) 0 && *name == NULLAP) { 
  83.                 *name = start_ptr;
  84.                 got_first = TRUE;
  85.             }
  86.             start_ptr = tree -> ap_next;
  87.             break;
  88.  
  89.             case AP_PERSON_START:
  90.             start_ptr = tree -> ap_next;
  91.             break;
  92.  
  93.             case AP_PERSON_END:
  94.             person_level--;
  95.             start_ptr = tree -> ap_next;
  96.             break;
  97.  
  98.             case AP_GROUP_NAME:
  99.             group_level++;
  100.             if (group != (AP_ptr *) 0 && *group == NULLAP) {
  101.                 *group = start_ptr;
  102.                 got_first = TRUE;
  103.             }
  104.             start_ptr = tree -> ap_next;
  105.             break;
  106.  
  107.             case AP_GROUP_START:
  108.             start_ptr = tree -> ap_next;
  109.             break;
  110.  
  111.             case AP_GROUP_END:
  112.             group_level--;
  113.             start_ptr = tree -> ap_next;
  114.             break;
  115.  
  116.             case AP_GENERIC_WORD:
  117.             case AP_MAILBOX:
  118.             if (local != (AP_ptr *) 0 && *local == NULLAP) {
  119.                 *local = start_ptr;
  120.                 got_first = TRUE;
  121.             }
  122.             got_local = TRUE;
  123.             start_ptr = tree -> ap_next;
  124.  
  125.             break;
  126.  
  127.             case AP_DOMAIN_LITERAL:
  128.             case AP_DOMAIN:
  129.             if (got_local) {
  130.                 /* -- reference after local -- */
  131.                 if (domain != (AP_ptr *) 0 &&
  132.                     *domain == NULLAP) {
  133.                     *domain = start_ptr;
  134.                     got_first = TRUE;
  135.                 }
  136.             }
  137.             else {
  138.                 /* -- must be 822 route -- */
  139.                 /* -- domain precedes local-part -- */
  140.                 if (route != (AP_ptr *) 0 && *route == NULLAP) {
  141.                     *route = start_ptr;
  142.                     got_first = TRUE;
  143.                 }
  144.             }
  145.             start_ptr = tree -> ap_next;
  146.  
  147.             break;
  148.         
  149.             case AP_COMMENT:
  150.             /* -- output value as comment -- */
  151.             if (got_first == FALSE)
  152.                 /* cannot lose preceding comments */
  153.                 break;
  154.             default:
  155.             start_ptr = tree -> ap_next;
  156.             break;
  157.         }
  158.  
  159.  
  160.  
  161.         switch (tree -> ap_ptrtype) {
  162.         case AP_PTR_NXT:
  163.             if (tree -> ap_next -> ap_obtype != AP_NIL) {
  164.                 return_ptr = (AP_ptr) tree -> ap_next;
  165.                 goto endit;
  166.             }
  167.  
  168.             /* -- else drop on through -- */
  169.  
  170.         case AP_PTR_NIL:
  171.             return_ptr = (AP_ptr) OK;
  172.             goto endit;
  173.         }
  174.     }
  175.  
  176. endit:
  177.  
  178.     return (return_ptr);
  179. }
  180.