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

1.1     ! root        1: /* ps2pe.c - presentation stream to presentation element */
        !             2: 
        !             3: #ifndef        lint
        !             4: static char *rcsid = "$Header: /f/osi/psap/RCS/ps2pe.c,v 7.1 90/07/27 08:47:25 mrose Exp $";
        !             5: #endif
        !             6: 
        !             7: /* 
        !             8:  * $Header: /f/osi/psap/RCS/ps2pe.c,v 7.1 90/07/27 08:47:25 mrose Exp $
        !             9:  *
        !            10:  *
        !            11:  * $Log:       ps2pe.c,v $
        !            12:  * Revision 7.1  90/07/27  08:47:25  mrose
        !            13:  * update
        !            14:  * 
        !            15:  * Revision 7.0  89/11/23  22:13:18  mrose
        !            16:  * Release 6.0
        !            17:  * 
        !            18:  */
        !            19: 
        !            20: /*
        !            21:  *                               NOTICE
        !            22:  *
        !            23:  *    Acquisition, use, and distribution of this module and related
        !            24:  *    materials are subject to the restrictions of a license agreement.
        !            25:  *    Consult the Preface in the User's Manual for the full terms of
        !            26:  *    this agreement.
        !            27:  *
        !            28:  */
        !            29: 
        !            30: 
        !            31: /* LINTLIBRARY */
        !            32: 
        !            33: #include <stdio.h>
        !            34: #include "psap.h"
        !            35: #include "tailor.h"
        !            36: 
        !            37: /*  */
        !            38: 
        !            39: PE     ps2pe_aux (ps, top, all)
        !            40: register PS    ps;
        !            41: int    top,
        !            42:        all;
        !            43: {
        !            44:     register PElementLen len;
        !            45:     PElementClass   class;
        !            46:     PElementForm    form;
        !            47:     PElementID     id;
        !            48:     register PE            pe;
        !            49: 
        !            50:     if (top && ps_prime (ps) == NOTOK)
        !            51:        return NULLPE;
        !            52:     
        !            53:     if (ps_read_id (ps, top, &class, &form, &id) == NOTOK)
        !            54:        return NULLPE;
        !            55:     if ((pe = pe_alloc (class, form, id)) == NULLPE)
        !            56:        return ps_seterr (ps, PS_ERR_NMEM, NULLPE);
        !            57:     if (ps_read_len (ps, &pe -> pe_len) == NOTOK)
        !            58:        goto you_lose;
        !            59: 
        !            60:     if (all == 0)
        !            61:        return pe;
        !            62:     len = pe -> pe_len;
        !            63:     switch (pe -> pe_form) {
        !            64:        case PE_FORM_PRIM: 
        !            65:            if (len == PE_LEN_INDF) {
        !            66:                (void) ps_seterr (ps, PS_ERR_INDF, NULLPE);
        !            67:                goto you_lose;
        !            68:            }
        !            69:            if (len > 0) {
        !            70:                if (ps -> ps_inline) {  /* "ultra-efficiency"... */
        !            71:                    if (ps -> ps_base == NULLCP || ps -> ps_cnt < len) {
        !            72:                        (void) ps_seterr (ps, PS_ERR_EOF, NULLPE);
        !            73:                        goto you_lose;
        !            74:                    }
        !            75:                    pe -> pe_inline = 1;
        !            76:                    pe -> pe_prim = (PElementData) ps -> ps_ptr;
        !            77:                    ps -> ps_ptr += len, ps -> ps_cnt -= len;
        !            78:                    ps -> ps_byteno += len;
        !            79:                }
        !            80:                else {
        !            81:                    if ((pe -> pe_prim = PEDalloc (len)) == NULLPED) {
        !            82:                        (void) ps_seterr (ps, PS_ERR_NMEM, NULLPE);
        !            83:                        goto you_lose;
        !            84:                    }
        !            85:                    if (ps_read (ps, pe -> pe_prim, len) == NOTOK) {
        !            86: #ifdef DEBUG
        !            87:                        SLOG (psap_log, LLOG_DEBUG, NULLCP,
        !            88:                              ("error reading primitive, %d bytes: %s",
        !            89:                               len, ps_error (ps -> ps_errno)));
        !            90: #endif
        !            91:                        goto you_lose;
        !            92:                    }
        !            93:                }
        !            94:            }
        !            95:            break;
        !            96: 
        !            97:        case PE_FORM_CONS: 
        !            98:            if (len != 0 && ps_read_cons (ps, &pe -> pe_cons, len) == NOTOK)
        !            99:                goto you_lose;
        !           100:            break;
        !           101:     }
        !           102: 
        !           103:     return pe;
        !           104: 
        !           105: you_lose: ;
        !           106: #ifdef DEBUG
        !           107:     if (psap_log -> ll_events & LLOG_DEBUG) {
        !           108:        LLOG (psap_log, LLOG_PDUS, ("PE read thus far"));
        !           109:        pe2text (psap_log, pe, 1, NOTOK);
        !           110:     }
        !           111: #endif
        !           112: 
        !           113:     pe_free (pe);
        !           114:     return NULLPE;
        !           115: }
        !           116: 
        !           117: /*  */
        !           118: 
        !           119: static int pe_id_overshift = PE_ID_MASK << (PE_ID_BITS - (PE_ID_SHIFT + 1));
        !           120: 
        !           121: 
        !           122: int  ps_read_id (ps, top, class, form, id)
        !           123: register PS    ps;
        !           124: int    top;
        !           125: register PElementClass *class;
        !           126: register PElementForm *form;
        !           127: register PElementID *id;
        !           128: {
        !           129:     byte    c,
        !           130:            d;
        !           131:     register PElementID j;
        !           132: 
        !           133:     if (ps_read (ps, &c, 1) == NOTOK) {
        !           134:        if (top && ps -> ps_errno == PS_ERR_EOF)
        !           135:            ps -> ps_errno = PS_ERR_NONE;
        !           136:        else {
        !           137: #ifdef DEBUG
        !           138:        SLOG (psap_log, LLOG_DEBUG, NULLCP,
        !           139:              ("error reading initial octet: %s", ps_error (ps -> ps_errno)));
        !           140: #endif
        !           141:        }
        !           142:            
        !           143:        return NOTOK;
        !           144:     }
        !           145: 
        !           146:     *class = (c & PE_CLASS_MASK) >> PE_CLASS_SHIFT;
        !           147:     *form = (c & PE_FORM_MASK) >> PE_FORM_SHIFT;
        !           148:     j = (c & PE_CODE_MASK);
        !           149: 
        !           150:     if (j == PE_ID_XTND)
        !           151:        for (j = 0;; j <<= PE_ID_SHIFT) {
        !           152:            if (ps_read (ps, &d, 1) == NOTOK) {
        !           153:                if (ps -> ps_errno == PS_ERR_EOF)
        !           154:                    ps -> ps_errno = PS_ERR_EOFID;
        !           155:                return NOTOK;
        !           156:            }
        !           157: 
        !           158:            j |= d & PE_ID_MASK;
        !           159:            if (!(d & PE_ID_MORE))
        !           160:                break;
        !           161:            if (j & pe_id_overshift)
        !           162:                return ps_seterr (ps, PS_ERR_OVERID, NOTOK);
        !           163:        }
        !           164:     *id = j;
        !           165:     DLOG (psap_log, LLOG_DEBUG, ("class=%d form=%d id=%d",*class, *form, *id));
        !           166: 
        !           167:     return OK;
        !           168: }
        !           169: 
        !           170: /*  */
        !           171: 
        !           172: int  ps_read_len (ps, len)
        !           173: register PS    ps;
        !           174: register PElementLen   *len;
        !           175: {
        !           176:     register int    i;
        !           177:     register PElementLen j;
        !           178:     byte    c;
        !           179: 
        !           180:     if (ps_read (ps, &c, 1) == NOTOK) {
        !           181: #ifdef DEBUG
        !           182:        SLOG (psap_log, LLOG_DEBUG, NULLCP,
        !           183:              ("error reading initial length octet: %s",
        !           184:               ps_error (ps -> ps_errno)));
        !           185: #endif
        !           186: 
        !           187:        return NOTOK;
        !           188:     }
        !           189: 
        !           190:     if ((i = c) & PE_LEN_XTND) {
        !           191:        if ((i &= PE_LEN_MASK) > sizeof (PElementLen))
        !           192:            return ps_seterr (ps, PS_ERR_OVERLEN, NOTOK);
        !           193: 
        !           194:        if (i) {
        !           195:            for (j = 0; i-- > 0;) {
        !           196:                if (ps_read (ps, &c, 1) == NOTOK) {
        !           197:                    if (ps -> ps_errno == PS_ERR_EOF)
        !           198:                        ps -> ps_errno = PS_ERR_EOFLEN;
        !           199:                    return NOTOK;
        !           200:                }
        !           201: 
        !           202:                j = (j << 8) | (c & 0xff);
        !           203:            }
        !           204:            *len = j;
        !           205:        }
        !           206:        else
        !           207:            *len = PE_LEN_INDF;
        !           208:     }
        !           209:     else
        !           210:        *len = i;
        !           211: #ifdef DEBUG
        !           212:     SLOG (psap_log, LLOG_DEBUG, NULLCP, ("len=%d", *len));
        !           213: #endif
        !           214: 
        !           215:     return OK;
        !           216: }
        !           217: 
        !           218: /*  */
        !           219: 
        !           220: int  ps_read_cons (ps, pe, len)
        !           221: register PS    ps;
        !           222: register PE    *pe;
        !           223: register PElementLen len;
        !           224: {
        !           225:     register int    cc;
        !           226:     register PE            p,
        !           227:                    q;
        !           228: 
        !           229:     cc = ps -> ps_byteno + len;
        !           230: 
        !           231:     if ((p = ps2pe_aux (ps, 0, 1)) == NULLPE) {
        !           232: no_cons: ;
        !           233: #ifdef DEBUG
        !           234:        if (len == PE_LEN_INDF)
        !           235:            LLOG (psap_log, LLOG_DEBUG,
        !           236:                  ("error building indefinite constructor, %s",
        !           237:                   ps_error (ps -> ps_errno)));
        !           238:        else
        !           239:            LLOG (psap_log, LLOG_DEBUG,
        !           240:                  ("error building constructor, stream at %d, wanted %d: %s",
        !           241:                   ps -> ps_byteno, cc, ps_error (ps -> ps_errno)));
        !           242: #endif
        !           243: 
        !           244:        return NOTOK;
        !           245:     }
        !           246:     *pe = p;
        !           247: 
        !           248:     if (len == PE_LEN_INDF) {
        !           249:        if (p -> pe_class == PE_CLASS_UNIV && p -> pe_id == PE_UNIV_EOC) {
        !           250:            pe_free (p);
        !           251:            *pe = NULLPE;
        !           252:            return OK;
        !           253:        }
        !           254:        for (q = p; p = ps2pe_aux (ps, 0, 1); q = q -> pe_next = p) {
        !           255:            if (p -> pe_class == PE_CLASS_UNIV && p -> pe_id == PE_UNIV_EOC) {
        !           256:                pe_free (p);
        !           257:                return OK;
        !           258:            }
        !           259:        }
        !           260: 
        !           261:        goto no_cons;
        !           262:     }
        !           263: 
        !           264:     for (q = p;; q = q -> pe_next = p) {
        !           265:        if (cc < ps -> ps_byteno)
        !           266:            return ps_seterr (ps, PS_ERR_LEN, NOTOK);
        !           267:        if (cc == ps -> ps_byteno)
        !           268:            return OK;
        !           269:        if ((p = ps2pe_aux (ps, 0, 1)) == NULLPE)
        !           270:            goto no_cons;
        !           271:     }
        !           272: }

unix.superglobalmegacorp.com

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