Annotation of 43BSDReno/contrib/isode-beta/psap/prim2str.c, revision 1.1

1.1     ! root        1: /* prim2str.c - presentation element to octet string */
        !             2: 
        !             3: #ifndef        lint
        !             4: static char *rcsid = "$Header: /f/osi/psap/RCS/prim2str.c,v 7.0 89/11/23 22:13:16 mrose Rel $";
        !             5: #endif
        !             6: 
        !             7: /* 
        !             8:  * $Header: /f/osi/psap/RCS/prim2str.c,v 7.0 89/11/23 22:13:16 mrose Rel $
        !             9:  *
        !            10:  *
        !            11:  * $Log:       prim2str.c,v $
        !            12:  * Revision 7.0  89/11/23  22:13:16  mrose
        !            13:  * Release 6.0
        !            14:  * 
        !            15:  */
        !            16: 
        !            17: /*
        !            18:  *                               NOTICE
        !            19:  *
        !            20:  *    Acquisition, use, and distribution of this module and related
        !            21:  *    materials are subject to the restrictions of a license agreement.
        !            22:  *    Consult the Preface in the User's Manual for the full terms of
        !            23:  *    this agreement.
        !            24:  *
        !            25:  */
        !            26: 
        !            27: 
        !            28: /* LINTLIBRARY */
        !            29: 
        !            30: #include <stdio.h>
        !            31: #include "psap.h"
        !            32: 
        !            33: /*  */
        !            34: 
        !            35: /* Similar to pe_pullup.  Returns a newly allocated string, composed of
        !            36:    of any sub-elements in pe, whereas pe_pullup always reverts "pe" to
        !            37:    a primitive.  The string is null-terminated, though pe_len specifically
        !            38:    does NOT reflect this. */
        !            39: 
        !            40: char   *prim2str (pe, len)
        !            41: register PE    pe;
        !            42: register int   *len;
        !            43: {
        !            44:     register int    i,
        !            45:                     k;
        !            46:     int     j;
        !            47:     register char  *dp,
        !            48:                    *ep,
        !            49:                    *fp;
        !            50:     register PElementClass class;
        !            51:     register PElementID id;
        !            52:     register PE            p;
        !            53: 
        !            54:     *len = 0;
        !            55:     switch (pe -> pe_form) {
        !            56:        case PE_FORM_PRIM: 
        !            57:            if ((dp = malloc ((unsigned) ((i = pe -> pe_len) + 1))) == NULLCP)
        !            58:                return pe_seterr (pe, PE_ERR_NMEM, NULLCP);
        !            59:            bcopy ((char *) pe -> pe_prim, dp, i);
        !            60:            break;
        !            61: 
        !            62:        case PE_FORM_CONS: 
        !            63:            if ((p = pe -> pe_cons) == NULLPE) {
        !            64:                if ((dp = malloc ((unsigned) ((i = 0) + 1))) == NULLCP)
        !            65:                    return pe_seterr (pe, PE_ERR_NMEM, NULLCP);
        !            66:                break;
        !            67:            }
        !            68:            dp = NULLCP, i = 0;
        !            69:            class = p -> pe_class, id = p -> pe_id;
        !            70:            for (p = pe -> pe_cons; p; p = p -> pe_next) {
        !            71:                if ((p -> pe_class != class || p -> pe_id != id)
        !            72:                        && (p -> pe_class != PE_CLASS_UNIV
        !            73:                                || p -> pe_id != PE_PRIM_OCTS)) {
        !            74:                    if (dp)
        !            75:                        free (dp);
        !            76:                    return pe_seterr (pe, PE_ERR_TYPE, NULLCP);
        !            77:                }
        !            78: 
        !            79:                if ((ep = prim2str (p, &j)) == NULLCP) {
        !            80:                    if (dp)
        !            81:                        free (dp);
        !            82:                    return pe_seterr (pe, PE_ERR_NMEM, NULLCP);
        !            83:                }
        !            84:                if (dp) {
        !            85:                    if ((fp = realloc (dp, (unsigned) ((k = i + j) + 1)))
        !            86:                            == NULLCP) {
        !            87:                        free (dp);
        !            88:                        return pe_seterr (pe, PE_ERR_NMEM, NULLCP);
        !            89:                    }
        !            90:                    bcopy (ep, fp + i, j);
        !            91:                    dp = fp, i = k;
        !            92:                }
        !            93:                else
        !            94:                    dp = ep, i += j;
        !            95:            }
        !            96:            break;
        !            97:     }
        !            98: 
        !            99:     if (dp)
        !           100:        dp[*len = i] = NULL;
        !           101: 
        !           102:     return dp;
        !           103: }

unix.superglobalmegacorp.com

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