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

  1. /* or2rfc.c: Parses an RFC address using the tables or, or2rfc and rfc2or */
  2.  
  3. # ifndef lint
  4. static char Rcsid[] = "@(#)$Header: /xtel/pp/pp-beta/Tools/ckor/RCS/or2rfc.c,v 6.0 1991/12/18 20:29:26 jpo Rel $";
  5. # endif
  6.  
  7. /*
  8.  * $Header: /xtel/pp/pp-beta/Tools/ckor/RCS/or2rfc.c,v 6.0 1991/12/18 20:29:26 jpo Rel $
  9.  *
  10.  * $Log: or2rfc.c,v $
  11.  * Revision 6.0  1991/12/18  20:29:26  jpo
  12.  * Release 6.0
  13.  *
  14.  */
  15.  
  16.  
  17.  
  18. #include "head.h"
  19. #include "or.h"
  20.  
  21. extern char             or_error[];
  22.  
  23.  
  24.  
  25.  
  26. /* ---------------------  Begin  Routines  -------------------------------- */
  27.  
  28.  
  29.  
  30. main (argc, argv)
  31. int     argc;
  32. char    *argv[];
  33. {
  34.     char    buf[BUFSIZ];
  35.     int     i = 1;
  36.  
  37.     sys_init (argv[0]);
  38.  
  39.     if (or_init() == NOTOK ) {
  40.         printf ("or_init() failed\n");
  41.         exit (1);
  42.     }
  43.  
  44.     if (argc == 1)
  45.         while (gets (buf) != NULL)
  46.             parse_address (buf);
  47.     else
  48.         while (i < argc)
  49.             parse_address (argv[i++]);
  50. }
  51.  
  52.  
  53. /* ---------------------  Static  Routines  ------------------------------- */
  54.  
  55.  
  56.  
  57. static int parse_address (str)
  58. char    *str;
  59. {
  60.     char            rfcbuf [BUFSIZ];
  61.     char            x400buf [BUFSIZ];
  62.     OR_ptr          or = NULLOR;
  63.  
  64.     or_error[0] = x400buf[0] = rfcbuf[0] = '\0';
  65.  
  66.     if ((or = or_std2or (str)) == NULLOR)
  67.         goto error;
  68.  
  69.     if (or_or2rfc (or, rfcbuf) == NOTOK)
  70.         goto error;
  71.  
  72.     if (isstr (or_error))
  73.         goto error;
  74.  
  75.     or_free (or);
  76.     or = NULLOR;
  77.  
  78.     if (or_rfc2or (rfcbuf, &or) == NOTOK)
  79.         goto error;
  80.  
  81.     if (isstr (or_error))
  82.         goto error;
  83.  
  84.     or_or2std (or, x400buf, FALSE);
  85.  
  86.     printf ("\n%s -> (rfc822) %s\n%-*s -> (x400)   %s\n",
  87.         str, rfcbuf, strlen(str), "", x400buf);
  88.  
  89.     goto finish;
  90.  
  91.  
  92. error:  ;
  93.     printf ("\nAddress parsing failed \nReason : %s\n", or_error);
  94.     if (rfcbuf[0] != '\0')
  95.         printf ("%s -> (rfc822) %s\n", str, rfcbuf);
  96.     if (x400buf[0] != '\0')
  97.         printf ("%s -> (x400) %s\n", str, x400buf);
  98.  
  99. finish:   ;
  100.     printf ("\n");
  101.     fflush (stdout);
  102.     if (or)
  103.         or_free (or);
  104.     return;
  105. }
  106.