1: /* $Header: CHstrtoname.c,v 2.0 85/11/21 07:22:34 jqj Exp $ */
   2: 
   3: /* contains:
   4:  * CH_strtoname
   5:  */
   6: 
   7: /* $Log:	CHstrtoname.c,v $
   8:  * Revision 2.0  85/11/21  07:22:34  jqj
   9:  * 4.3BSD standard release
  10:  *
  11:  * Revision 1.1  85/03/26  06:27:02  jqj
  12:  * Initial revision
  13:  *
  14:  * Revision 1.1  85/03/26  06:27:02  jqj
  15:  * Initial revision
  16:  *
  17:  */
  18: 
  19: #include <xnscourier/Clearinghouse2.h>
  20: 
  21: static char *copy();
  22: 
  23: /*
  24:  * Given a string in standard format, return an ObjectName.
  25:  * If the string is incomplete, e.g. "jqj" or "::cornell-univ", fill
  26:  * in default values from defaults.
  27:  */
  28: Clearinghouse2_ObjectName
  29: CH_StringToName(str,defaults)
  30:     char *str;
  31:     Clearinghouse2_ObjectName *defaults;
  32: {
  33:     register char *s1;
  34:     extern char *index();
  35:     register Clearinghouse2_ObjectName result;
  36: 
  37:     s1 = result.object = (str ? copy(str) : "");
  38:     if (s1 = index(s1,':')) {
  39:         *s1 = '\0';
  40:         result.domain = ++s1;
  41:         if (s1 = index(s1,':')) {
  42:             *s1 = '\0';
  43:             result.organization = ++s1;
  44:         }
  45:         else
  46:             result.organization = "";
  47:     }
  48:     else
  49:         result.organization = result.domain = "";
  50:     /* now fill in defaults if any */
  51:     if (defaults == (Clearinghouse2_ObjectName*) NULL)
  52:         return(result);
  53:     if (*result.object == '\0' && defaults->object != NULL)
  54:         result.object = copy(defaults->object);
  55:     if (*result.domain == '\0' && defaults->domain != NULL)
  56:         result.domain = copy(defaults->domain);
  57:     if (*result.organization == '\0' && defaults->organization != NULL)
  58:         result.organization = copy(defaults->organization);
  59:     return(result);
  60: }
  61: 
  62: 
  63: static char *
  64: copy(s)
  65:     char *s;
  66: {
  67:     char *p;
  68:     extern char *malloc();
  69: 
  70:     if ((p = malloc(strlen(s) + 1)) == NULL) {
  71:         exit(1);
  72:     }
  73:     (void) strcpy(p, s);
  74:     return (p);
  75: }

Defined functions

CH_StringToName defined in line 28; used 1 times
copy defined in line 63; used 5 times
Last modified: 1986-03-13
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 819
Valid CSS Valid XHTML 1.0 Strict