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

1.1       root        1: /* str2pe.c - create an Inline CONStructor PElement */
                      2: 
                      3: #ifndef        lint
                      4: static char *rcsid = "$Header: /f/osi/psap/RCS/str2pe.c,v 7.0 89/11/23 22:13:47 mrose Rel $";
                      5: #endif
                      6: 
                      7: /* 
                      8:  * $Header: /f/osi/psap/RCS/str2pe.c,v 7.0 89/11/23 22:13:47 mrose Rel $
                      9:  *
                     10:  *
                     11:  * $Log:       str2pe.c,v $
                     12:  * Revision 7.0  89/11/23  22:13:47  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: /*  */
                     35: 
                     36: PElementLen    str_get_len ();
                     37: 
                     38: /*  */
                     39: 
                     40: #define        seterr(e,v)             (*result = (e), (v))
                     41: 
                     42: 
                     43: PE     str2pe (s, len, advance, result)
                     44: char   *s;
                     45: int    len,
                     46:        *advance,
                     47:        *result;
                     48: {
                     49: #ifdef DEBUG
                     50:     int            n = len;
                     51: #endif
                     52:     char   *sp;
                     53:     PElementClass   class;
                     54:     PElementForm    form;
                     55:     PElementID    id;
                     56:     PElementLen plen;
                     57:     register PE            pe;
                     58: 
                     59:     *result = PS_ERR_NONE;
                     60: 
                     61:     sp = s;
                     62:     if (str_get_start (&sp, &len, &class, &form, &id, &plen, result) == NOTOK)
                     63:        return NULLPE;
                     64: 
                     65:     if (form == PE_FORM_CONS)
                     66:        form = PE_FORM_ICONS;
                     67: 
                     68:     if (plen == PE_LEN_INDF
                     69:            && (plen = str_get_len (sp, len, result)) == PE_LEN_INDF)
                     70:        return NULLPE;
                     71: 
                     72:     if ((pe = pe_alloc (class, form, id)) == NULLPE)
                     73:        return seterr (PS_ERR_NMEM, NULLPE);
                     74: 
                     75:     pe -> pe_ilen = sp - s;
                     76:     if (form == PE_FORM_ICONS) {
                     77:        pe -> pe_len = pe -> pe_ilen + plen;
                     78:        pe -> pe_prim = (PElementData) s;
                     79:     }
                     80:     else
                     81:        if (pe -> pe_len = plen)
                     82:            pe -> pe_prim = (PElementData) sp;
                     83: 
                     84:     pe -> pe_inline = 1;
                     85: 
                     86:     if (advance)
                     87:        *advance = pe -> pe_ilen + plen;
                     88: 
                     89: #ifdef DEBUG
                     90:     if (psap_log -> ll_events & LLOG_PDUS)
                     91:        pe2text (psap_log, pe, 1, n);
                     92: #endif
                     93: 
                     94:     return pe;
                     95: }
                     96: 
                     97: /*  */
                     98: 
                     99: static int  str_get_start (sp, n, class, form, id, plen, result)
                    100: char  **sp;
                    101: int    *n,
                    102:        *result;
                    103: PElementClass *class;
                    104: PElementForm *form;
                    105: PElementID *id;
                    106: PElementLen *plen;
                    107: {
                    108:     register int i,
                    109:                 len;
                    110:     register char *s;
                    111:     byte    c,
                    112:            d;
                    113:     register PElementID    jd;
                    114:     register PElementLen qlen;
                    115: 
                    116:     s = *sp, len = *n;
                    117:     if (len-- <= 0)
                    118:        return seterr (PS_ERR_EOF, NOTOK);
                    119:     c = *s++;
                    120: 
                    121:     *class = (c & PE_CLASS_MASK) >> PE_CLASS_SHIFT;
                    122:     *form = (c & PE_FORM_MASK) >> PE_FORM_SHIFT;
                    123:     if ((jd = (c & PE_CODE_MASK)) == PE_ID_XTND)
                    124:        for (jd = 0;; jd <<= PE_ID_SHIFT) {
                    125:            if (len-- <= 0)
                    126:                return seterr (PS_ERR_EOFID, NOTOK);
                    127:            d = *s++;
                    128: 
                    129:            jd |= d & PE_ID_MASK;
                    130:            if (!(d & PE_ID_MORE))
                    131:                break;
                    132:            if (jd & (PE_ID_MASK << (PE_ID_SHIFT - 1)))
                    133:                return seterr (PS_ERR_OVERID, NOTOK);
                    134:        }
                    135:     *id = jd;
                    136: #ifdef DEBUG
                    137:     SLOG (psap_log, LLOG_DEBUG, NULLCP,
                    138:          ("class=%d form=%d id=%d", *class, *form, *id));
                    139: #endif
                    140: 
                    141:     if (len-- <= 0)
                    142:        return seterr (PS_ERR_EOFLEN, NOTOK);
                    143:     c = *s++;
                    144: 
                    145:     if ((i = c) & PE_LEN_XTND) {
                    146:        if ((i &= PE_LEN_MASK) > sizeof (PElementLen))
                    147:            return seterr (PS_ERR_OVERLEN, NOTOK);
                    148: 
                    149:        if (i) {
                    150:            for (qlen = 0; i-- > 0;) {
                    151:                if (len-- <= 0)
                    152:                    return seterr (PS_ERR_EOFLEN, NOTOK);
                    153:                c = *s++;
                    154: 
                    155:                qlen = (qlen << 8) | (c & 0xff);
                    156:            }
                    157: 
                    158:            *plen = qlen;
                    159:        }
                    160:        else
                    161:            if (*form == PE_FORM_PRIM)
                    162:                return seterr (PS_ERR_INDF, NOTOK);
                    163:            else
                    164:                *plen = PE_LEN_INDF;
                    165:     }
                    166:     else
                    167:        *plen = i;
                    168: #ifdef DEBUG
                    169:     SLOG (psap_log, LLOG_DEBUG, NULLCP, ("len=%d", *plen));
                    170: #endif
                    171: 
                    172:     *sp = s, *n = len;
                    173: 
                    174:     return OK;
                    175: }
                    176: 
                    177: /*  */
                    178: 
                    179: static PElementLen  str_get_len (s, len, result)
                    180: char   *s;
                    181: int    len,
                    182:        *result;
                    183: {
                    184:     char   *sp;
                    185:     PElementClass class;
                    186:     PElementForm form;
                    187:     PElementID id;
                    188:     PElementLen plen;
                    189: 
                    190:     for (sp = s;;) {
                    191:        if (str_get_start (&sp, &len, &class, &form, &id, &plen, result)
                    192:                == NOTOK)
                    193:            return PE_LEN_INDF;
                    194: 
                    195:        if (class == PE_CLASS_UNIV && id == PE_UNIV_EOC)
                    196:            return ((PElementLen) (sp - s));
                    197: 
                    198:        if (plen == PE_LEN_INDF
                    199:                && (plen = str_get_len (sp, len, result)) == PE_LEN_INDF)
                    200:            return PE_LEN_INDF;
                    201: 
                    202:        sp += plen, len -= plen;
                    203:     }
                    204: }

unix.superglobalmegacorp.com

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