Annotation of 43BSDTahoe/new/xns/morexnslib/ch/CHstrtoname.c, revision 1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.