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

  1. /* or_buildpn: build a personal name from string */
  2.  
  3. # ifndef lint
  4. static char Rcsid[] = "@(#)$Header: /xtel/pp/pp-beta/Lib/or/RCS/or_buildpn.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_buildpn.c,v 6.0 1991/12/18 20:23:08 jpo Rel $
  9.  *
  10.  * $Log: or_buildpn.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. Takes string and builds a tree
  23. */
  24.  
  25. OR_ptr or_buildpn (str)
  26. char            *str;
  27. {
  28.     OR_ptr      or,
  29.             tor,
  30.         tree;
  31.     char        tbuf[LINESIZE],
  32.         *q,
  33.         *r;
  34.  
  35.     PP_DBG (("or_util.c/or_buildpn (%s)", str));
  36.  
  37.     tree = NULLOR;
  38.  
  39.     if ((q = index (str, '.')) == NULLCP)
  40.     /*
  41.     Only a surname is specified
  42.     */
  43.     q = str;
  44.     else {
  45.     if ((q - str) > 1) {
  46.         /*
  47.         A given name is specified
  48.         */
  49.         *q++ = '\0';
  50.         tree = or_new (OR_G, NULLCP, str);
  51.     }
  52.     else
  53.         q = str;
  54.  
  55.     /*
  56.     Do the initials from q
  57.     */
  58.  
  59.     r = tbuf;
  60.  
  61.     while (TRUE) {
  62.         if (!isalnum (*q) || (*(q + 1) != '.'))
  63.             break;
  64.         *r++ = *q;
  65.         q = q + 2;
  66.     }
  67.  
  68.     *r = '\0';
  69.  
  70.     if (tbuf[0] != '\0') {
  71.         if ((or = or_new (OR_I, NULLCP, tbuf)) == NULLOR)
  72.             return NULLOR;
  73.  
  74.         if ((tor = or_add (tree, or, TRUE)) == NULLOR) {
  75.             or_free (or);
  76.             return NULLOR;
  77.         }
  78.         tree = tor;
  79.     }
  80.     }
  81.  
  82.     /*
  83.     q now points to start of surname
  84.     */
  85.  
  86.     if ((or = or_new (OR_S, NULLCP, q)) == NULLOR)
  87.     return NULLOR;
  88.     tor = or_add (tree, or, TRUE);
  89.     if (tor == NULLOR) {
  90.         or_free (tree);
  91.         return NULLOR;
  92.     }
  93.     tree = tor;
  94.     return tree;
  95. }
  96.