home *** CD-ROM | disk | FTP | other *** search
/ back2roots/padua / padua.7z / padua / uucp / duucp-1.17 / AU-117b4-src.lha / src / sendmail / parse.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-02  |  1.2 KB  |  78 lines

  1. /*
  2.  *  PARSE.C
  3.  *
  4.  *  (C) Copyright 1989-1990 by Matthew Dillon,    All Rights Reserved.
  5.  */
  6.  
  7. #include "defs.h"
  8.  
  9. Prototype int ParseAddress (char *, char *, int);
  10.  
  11. Local char *ParseAddress2 (char *, char *, int);
  12.  
  13. /*
  14.  *  PARSEADDRESS()
  15.  *
  16.  *  Takes an address containing ! @ % : and converts it to a level 3 ! path.
  17.  *
  18.  *  [path]@mach     ->  mach[!path]
  19.  *  [path]%mach     ->  mach[!path]
  20.  *  patha:pathb     ->  patha!pathb
  21.  *  patha:pathb:pathc    ->  patha!pathb!pathc
  22.  */
  23.  
  24. int
  25. ParseAddress (char *str, char *buf, int len)
  26. {
  27.     int
  28.         j,
  29.         i;
  30.     char
  31.         *base = buf;
  32.  
  33.     for (i = j = 0; i < len; ++i) {
  34.         if (str [i] == ':') {
  35.             buf = ParseAddress2 (str + j, buf, i - j);
  36.             *buf++ = '!';
  37.             j = i + 1;
  38.         }
  39.     }
  40.  
  41.     buf = ParseAddress2 (str + j, buf, i - j);
  42.     *buf = 0;
  43.  
  44.     for (i = 0; base [i] && base [i] != '!'; ++i)
  45.         ;
  46.  
  47.     return i;
  48. }
  49.  
  50. /*
  51.  *  deals with !, @, and %
  52.  */
  53.  
  54. static char *
  55. ParseAddress2 (char *addr, char *buf, int len)
  56. {
  57.     int
  58.         i;
  59.  
  60.     for (i = len - 1; i >= 0; --i) {
  61.         if (addr [i] == '@' || addr [i] == '%') {
  62.             int
  63.                 j = len - i;
  64.  
  65.             strncpy (buf, addr + i + 1, j - 1);
  66.             buf += j - 1;
  67.             len -= j;
  68.             if (len)
  69.                 *buf++ = '!';
  70.         }
  71.     }
  72.  
  73.     strncpy (buf, addr, len);
  74.     buf += len;
  75.  
  76.     return buf;
  77. }
  78.