Annotation of 43BSDReno/contrib/isode-beta/psap/pe2ps.c, revision 1.1.1.1

1.1       root        1: /* pe2ps.c - presentation element to presentation stream */
                      2: 
                      3: #ifndef        lint
                      4: static char *rcsid = "$Header: /f/osi/psap/RCS/pe2ps.c,v 7.0 89/11/23 22:12:56 mrose Rel $";
                      5: #endif
                      6: 
                      7: /* 
                      8:  * $Header: /f/osi/psap/RCS/pe2ps.c,v 7.0 89/11/23 22:12:56 mrose Rel $
                      9:  *
                     10:  *
                     11:  * $Log:       pe2ps.c,v $
                     12:  * Revision 7.0  89/11/23  22:12:56  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: #include "tailor.h"
                     33: 
                     34: /*    DATA */
                     35: 
                     36: static PElement pe_eoc = { PE_CLASS_UNIV, PE_FORM_PRIM, PE_UNIV_EOC, 0 };
                     37: 
                     38: /*  */
                     39: 
                     40: int    pe2ps_aux (ps, pe, eval)
                     41: register PS    ps;
                     42: register PE    pe;
                     43: int    eval;
                     44: {
                     45:     int     result;
                     46: 
                     47:     if (eval > 0)
                     48:        switch (pe -> pe_form) {
                     49:            case PE_FORM_PRIM: 
                     50:            case PE_FORM_ICONS: 
                     51:                break;
                     52: 
                     53:            case PE_FORM_CONS: 
                     54:                (void) ps_get_abs (pe);
                     55:                break;
                     56:        }
                     57: 
                     58:     if ((result = pe2ps_aux2 (ps, pe, eval)) != NOTOK)
                     59:        result = ps_flush (ps);
                     60: 
                     61:     return result;
                     62: }
                     63: 
                     64: 
                     65: static int  pe2ps_aux2 (ps, pe, eval)
                     66: register PS    ps;
                     67: register PE    pe;
                     68: int    eval;
                     69: {
                     70:     register PE            p;
                     71: 
                     72:     if (pe -> pe_form == PE_FORM_ICONS) {
                     73:        if (ps_write_aux (ps, pe -> pe_prim, pe -> pe_len, 1) == NOTOK)
                     74:            return NOTOK;
                     75: 
                     76:        return OK;
                     77:     }
                     78:     
                     79:     if (ps_write_id (ps, pe) == NOTOK || ps_write_len (ps, pe) == NOTOK)
                     80:        return NOTOK;
                     81: 
                     82:     switch (pe -> pe_form) {
                     83:        case PE_FORM_PRIM: 
                     84:            if (ps_write_aux (ps, pe -> pe_prim, pe -> pe_len, 1) == NOTOK)
                     85:                return NOTOK;
                     86:            break;
                     87: 
                     88:        case PE_FORM_CONS: 
                     89:            if (eval < 0)
                     90:                    break;
                     91:            if (pe -> pe_len) {
                     92:                for (p = pe -> pe_cons; p; p = p -> pe_next)
                     93:                    if (pe2ps_aux2 (ps, p, 0) == NOTOK)
                     94:                        return NOTOK;
                     95: 
                     96:                if (pe -> pe_len == PE_LEN_INDF
                     97:                        && pe2ps_aux2 (ps, &pe_eoc, 0) == NOTOK)
                     98:                    return NOTOK;
                     99:            }
                    100:            break;
                    101:     }
                    102: 
                    103:     return OK;
                    104: }
                    105: 
                    106: /*  */
                    107: 
                    108: static int  ps_write_id (ps, pe)
                    109: register PS    ps;
                    110: register PE    pe;
                    111: {
                    112:     byte    buffer[1 + sizeof (PElementID)];
                    113:     register byte  *bp = buffer;
                    114:     PElementForm    form;
                    115:     register PElementID id;
                    116: 
                    117:     if ((form = pe -> pe_form) == PE_FORM_ICONS)
                    118:        form = PE_FORM_CONS;
                    119:     *bp = ((pe -> pe_class << PE_CLASS_SHIFT) & PE_CLASS_MASK)
                    120:                | ((form << PE_FORM_SHIFT) & PE_FORM_MASK);
                    121: 
                    122:     if ((id = pe -> pe_id) < PE_ID_XTND)
                    123:        *bp++ |= id;
                    124:     else {
                    125:        register byte *ep;
                    126:        register PElementID jd;
                    127: 
                    128:        *bp |= PE_ID_XTND;
                    129: 
                    130:        ep = buffer;
                    131:        for (jd = id; jd != 0; jd >>= PE_ID_SHIFT)
                    132:            ep++;
                    133: 
                    134:        for (bp = ep; id != 0; id >>= PE_ID_SHIFT)
                    135:            *bp-- = id & PE_ID_MASK;
                    136:        for (bp = buffer + 1; bp < ep; bp++)
                    137:            *bp |= PE_ID_MORE;
                    138: 
                    139:        bp = ++ep;
                    140:     }
                    141: 
                    142:     if (ps_write (ps, buffer, bp - buffer) == NOTOK)
                    143:        return NOTOK;
                    144: 
                    145:     return OK;
                    146: }
                    147: 
                    148: /*  */
                    149: 
                    150: /* probably should integrate the non-PE_LEN_SMAX case with the algorithm in
                    151:    num2prim() for a single, unified routine */
                    152: 
                    153: static int  ps_write_len (ps, pe)
                    154: register PS    ps;
                    155: register PE    pe;
                    156: {
                    157:     byte    buffer[1 + sizeof (PElementLen)];
                    158:     register byte  *bp = buffer,
                    159:                   *ep;
                    160:     register PElementLen len;
                    161: 
                    162:     if ((len = pe -> pe_len) == PE_LEN_INDF)
                    163:        *bp++ = PE_LEN_XTND;
                    164:     else
                    165:        if (len <= PE_LEN_SMAX)
                    166:            *bp++ = len & 0xff;
                    167:        else {
                    168:            ep = buffer + sizeof buffer - 1;
                    169:            for (bp = ep; len != 0 && buffer < bp; len >>= 8)
                    170:                *bp-- = len & 0xff;
                    171:            *bp = PE_LEN_XTND | ((ep - bp) & 0xff);
                    172:            if (ps_write (ps, bp, ep - bp + 1) == NOTOK)
                    173:                return NOTOK;
                    174: 
                    175:            return OK;
                    176:        }
                    177: 
                    178:     if (ps_write (ps, buffer, bp - buffer) == NOTOK)
                    179:        return NOTOK;
                    180: 
                    181:     return OK;
                    182: }

unix.superglobalmegacorp.com

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