home *** CD-ROM | disk | FTP | other *** search
- /*
- * PARSE.C
- *
- * (C) Copyright 1989-1990 by Matthew Dillon, All Rights Reserved.
- */
-
- #include "defs.h"
-
- Prototype int ParseAddress (char *, char *, int);
-
- Local char *ParseAddress2 (char *, char *, int);
-
- /*
- * PARSEADDRESS()
- *
- * Takes an address containing ! @ % : and converts it to a level 3 ! path.
- *
- * [path]@mach -> mach[!path]
- * [path]%mach -> mach[!path]
- * patha:pathb -> patha!pathb
- * patha:pathb:pathc -> patha!pathb!pathc
- */
-
- int
- ParseAddress (char *str, char *buf, int len)
- {
- int
- j,
- i;
- char
- *base = buf;
-
- for (i = j = 0; i < len; ++i) {
- if (str [i] == ':') {
- buf = ParseAddress2 (str + j, buf, i - j);
- *buf++ = '!';
- j = i + 1;
- }
- }
-
- buf = ParseAddress2 (str + j, buf, i - j);
- *buf = 0;
-
- for (i = 0; base [i] && base [i] != '!'; ++i)
- ;
-
- return i;
- }
-
- /*
- * deals with !, @, and %
- */
-
- static char *
- ParseAddress2 (char *addr, char *buf, int len)
- {
- int
- i;
-
- for (i = len - 1; i >= 0; --i) {
- if (addr [i] == '@' || addr [i] == '%') {
- int
- j = len - i;
-
- strncpy (buf, addr + i + 1, j - 1);
- buf += j - 1;
- len -= j;
- if (len)
- *buf++ = '!';
- }
- }
-
- strncpy (buf, addr, len);
- buf += len;
-
- return buf;
- }
-