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

1.1     ! root        1: /* pe2pl.c - presentation element to presentation list */
        !             2: 
        !             3: #ifndef        lint
        !             4: static char *rcsid = "$Header: /f/osi/psap/RCS/pe2pl.c,v 7.0 89/11/23 22:12:53 mrose Rel $";
        !             5: #endif
        !             6: 
        !             7: /* 
        !             8:  * $Header: /f/osi/psap/RCS/pe2pl.c,v 7.0 89/11/23 22:12:53 mrose Rel $
        !             9:  *
        !            10:  *
        !            11:  * $Log:       pe2pl.c,v $
        !            12:  * Revision 7.0  89/11/23  22:12:53  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: /* Presentation lists are a human-readable, unambiguous way of describing
        !            29:    a presentation element.
        !            30: 
        !            31:     SYNTAX:            list    ::      "(" class code arguments ")"
        !            32: 
        !            33:                        class   ::      "UNIV" / "APPL" / "CONT" / "PRIV"
        !            34: 
        !            35:                        code    ::      name / number
        !            36: 
        !            37:                        name    ::      letter (letter / digit / dash)*
        !            38: 
        !            39:                        number  ::      "0x" [0-f] [0-f]* /
        !            40:                                        "0" [0-7] [0-7]* /
        !            41:                                        [1-9] [0-9]* /
        !            42:                                        "\"" (IA5 subset)* "\""
        !            43: 
        !            44:                        arguments::     primitive / constructor
        !            45: 
        !            46:                        primitive::     number number*
        !            47: 
        !            48:                        constructor::   list*
        !            49: 
        !            50:    NOTE WELL:  A single "number" must be representable in no more than
        !            51:                (sizeof (int)) bytes.
        !            52:  */
        !            53: 
        !            54: 
        !            55: /* LINTLIBRARY */
        !            56: 
        !            57: #include <ctype.h>
        !            58: #include <stdio.h>
        !            59: #include "psap.h"
        !            60: 
        !            61: 
        !            62: #define        bf_write()      \
        !            63:     if (ps_write (ps, (PElementData) buffer, (PElementLen) strlen (buffer)) == NOTOK) \
        !            64:        return NOTOK
        !            65: 
        !            66: /*  */
        !            67: 
        !            68: int    pe2pl (ps, pe)
        !            69: register PS    ps;
        !            70: register PE    pe;
        !            71: {
        !            72:     int     result;
        !            73: 
        !            74:     if ((result = pe2pl_aux (ps, pe, 0)) != NOTOK)
        !            75:        result = ps_flush (ps);
        !            76: 
        !            77:     return result;
        !            78: }
        !            79: 
        !            80: /*  */
        !            81: 
        !            82: static int  pe2pl_aux (ps, pe, level)
        !            83: register PS    ps;
        !            84: register PE    pe;
        !            85: int    level;
        !            86: {
        !            87:     register int    i,
        !            88:                    ia5,
        !            89:                    ia5ok;
        !            90:     register char  *bp;
        !            91:     char    buffer[BUFSIZ];
        !            92:     register PE            p;
        !            93:     register PElementID id;
        !            94:     register PElementData dp,
        !            95:                          ep,
        !            96:                          fp,
        !            97:                          gp;
        !            98: 
        !            99:     (void) sprintf (buffer, "%*s( %s ",
        !           100:            level * 4, "", pe_classlist[pe -> pe_class]);
        !           101:     bf_write ();
        !           102: 
        !           103:     switch (pe -> pe_class) {
        !           104:        case PE_CLASS_UNIV: 
        !           105:            if ((id = pe -> pe_id) < pe_maxuniv && (bp = pe_univlist[id])) {
        !           106:                if (ps_write (ps, (PElementData) bp, (PElementLen) strlen (bp))
        !           107:                        == NOTOK)
        !           108:                    return NOTOK;
        !           109:            }
        !           110:            else
        !           111:                goto no_code;
        !           112:            break;
        !           113: 
        !           114:        case PE_CLASS_APPL: 
        !           115:            if ((id = pe -> pe_id) < pe_maxappl && (bp = pe_applist[id])) {
        !           116:                if (ps_write (ps, (PElementData) bp, (PElementLen) strlen (bp))
        !           117:                        == NOTOK)
        !           118:                    return NOTOK;
        !           119:            }
        !           120:            else
        !           121:                goto no_code;
        !           122: 
        !           123:        case PE_CLASS_PRIV: 
        !           124:            if ((id = pe -> pe_id) < pe_maxpriv && (bp = pe_privlist[id])) {
        !           125:                if (ps_write (ps, (PElementData) bp, (PElementLen) strlen (bp))
        !           126:                        == NOTOK)
        !           127:                    return NOTOK;
        !           128:            }                   /* else fall */
        !           129: 
        !           130:        case PE_CLASS_CONT: 
        !           131:     no_code: ;
        !           132:            (void) sprintf (buffer, "0x%x", pe -> pe_id);
        !           133:            bf_write ();
        !           134:            break;
        !           135:     }
        !           136: 
        !           137:     level++;
        !           138:     switch (pe -> pe_form) {
        !           139:        case PE_FORM_PRIM: 
        !           140:        case PE_FORM_ICONS: 
        !           141:            (void) sprintf (buffer, " 0x%x%c",
        !           142:                        pe -> pe_len, pe -> pe_len ? '\n' : ' ');
        !           143:            bf_write ();
        !           144: 
        !           145:            if (pe -> pe_len) {
        !           146:                ia5ok = 0;
        !           147:                if (pe -> pe_form == PE_FORM_PRIM
        !           148:                        && pe -> pe_class == PE_CLASS_UNIV)
        !           149:                    switch (pe -> pe_id) {
        !           150:                        case PE_PRIM_OCTS:
        !           151:                        case PE_DEFN_IA5S:
        !           152:                        case PE_DEFN_NUMS: 
        !           153:                        case PE_DEFN_PRTS: 
        !           154:                        case PE_DEFN_T61S:
        !           155:                        case PE_DEFN_VTXS:
        !           156:                        case PE_DEFN_VISS:
        !           157:                        case PE_DEFN_GENT:
        !           158:                        case PE_DEFN_UTCT:
        !           159:                        case PE_DEFN_GFXS:
        !           160:                        case PE_PRIM_ODE:
        !           161:                        case PE_DEFN_GENS:
        !           162:                            ia5ok = 1;
        !           163:                            break;
        !           164: 
        !           165:                        default:
        !           166:                            break;
        !           167:                    }
        !           168: 
        !           169:                for (ep = (dp = pe -> pe_prim) + pe -> pe_len; dp < ep;) {
        !           170:                    i = min (ep - dp, sizeof (int));
        !           171:                    if (ia5 = ia5ok) {
        !           172:                        for (gp = (fp = dp) + i; fp < gp; fp++) {
        !           173:                            switch (*fp) {
        !           174:                                case ' ':
        !           175:                                    continue;
        !           176:                                case '"':
        !           177:                                    break;
        !           178:                                default:
        !           179:                                    if (iscntrl (*fp)
        !           180:                                            || isspace (*fp)
        !           181:                                            || (*fp & 0x80))
        !           182:                                        break;
        !           183:                                    continue;
        !           184:                            }
        !           185:                            ia5 = 0;
        !           186:                            break;
        !           187:                        }
        !           188:                    }
        !           189:                    (void) sprintf (buffer, ia5 ? "%*s\"" : "%*s0x",
        !           190:                                level * 4, "");
        !           191:                    bp = buffer + strlen (buffer);
        !           192:                    while (i-- > 0) {
        !           193:                        (void) sprintf (bp, ia5 ? (i ? "%c" : "%c\"\n")
        !           194:                                    : (i ? "%02x" : "%02x\n"), *dp++);
        !           195:                        bp += strlen (bp);
        !           196:                    }
        !           197:                    bf_write ();
        !           198:                }
        !           199:            }
        !           200:            else
        !           201:                level = 1;
        !           202:            break;
        !           203: 
        !           204:        case PE_FORM_CONS: 
        !           205:            if (p = pe -> pe_cons) {
        !           206:                if (ps_write (ps, (PElementData) "\n", (PElementLen) 1)
        !           207:                    == NOTOK)
        !           208:                    return NOTOK;
        !           209:                for (p = pe -> pe_cons; p; p = p -> pe_next)
        !           210:                    if (pe2pl_aux (ps, p, level) == NOTOK)
        !           211:                        return NOTOK;
        !           212:            }
        !           213:            else {
        !           214:                if (ps_write (ps, (PElementData) " ", (PElementLen) 1)
        !           215:                    == NOTOK)
        !           216:                    return NOTOK;
        !           217:                level = 1;
        !           218:            }
        !           219:            break;
        !           220:     }
        !           221:     level--;
        !           222: 
        !           223:     (void) sprintf (buffer, "%*s)\n", level * 4, "");
        !           224:     bf_write ();
        !           225: 
        !           226:     return OK;
        !           227: }

unix.superglobalmegacorp.com

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