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

1.1       root        1: /* str2ps.c - string-backed abstraction for PStreams */
                      2: 
                      3: #ifndef        lint
                      4: static char *rcsid = "$Header: /f/osi/psap/RCS/str2ps.c,v 7.0 89/11/23 22:13:48 mrose Rel $";
                      5: #endif
                      6: 
                      7: /* 
                      8:  * $Header: /f/osi/psap/RCS/str2ps.c,v 7.0 89/11/23 22:13:48 mrose Rel $
                      9:  *
                     10:  *
                     11:  * $Log:       str2ps.c,v $
                     12:  * Revision 7.0  89/11/23  22:13:48  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: /* ARGSUSED */
                     36: 
                     37: static int str_read (ps, data, n, in_line)
                     38: register PS    ps;
                     39: PElementData data;
                     40: PElementLen n;
                     41: int    in_line;
                     42: {
                     43:     register int    cc;
                     44: 
                     45:     if (ps -> ps_base == NULLCP || (cc = ps -> ps_cnt) <= 0)
                     46:        return 0;
                     47:     if (cc > n)
                     48:        cc = n;
                     49: 
                     50:     bcopy (ps -> ps_ptr, (char *) data, cc);
                     51:     ps -> ps_ptr += cc, ps -> ps_cnt -= cc;
                     52: 
                     53:     return cc;
                     54: }
                     55: 
                     56: 
                     57: /* ARGSUSED */
                     58: 
                     59: static int str_write (ps, data, n, in_line)
                     60: register PS    ps;
                     61: PElementData data;
                     62: PElementLen n;
                     63: int    in_line;
                     64: {
                     65:     register int    cc;
                     66:     register char  *cp;
                     67: 
                     68:     if (ps -> ps_base == NULLCP) {
                     69:        if ((cp = malloc ((unsigned) (cc = n + BUFSIZ))) == NULLCP)
                     70:            return ps_seterr (ps, PS_ERR_NMEM, NOTOK);
                     71:        ps -> ps_base = ps -> ps_ptr = cp;
                     72:        ps -> ps_bufsiz = ps -> ps_cnt = cc;
                     73:     }
                     74:     else
                     75:        if (ps -> ps_cnt < n) {
                     76:            register int    curlen = ps -> ps_ptr - ps -> ps_base;
                     77: 
                     78:            if (ps -> ps_inline)
                     79:                return 0;
                     80:            if ((cp = realloc (ps -> ps_base,
                     81:                                      (unsigned) (ps -> ps_bufsiz
                     82:                                                  + (cc = n + BUFSIZ))))
                     83:                    == NULLCP)
                     84:                return ps_seterr (ps, PS_ERR_NMEM, NOTOK);
                     85:            ps -> ps_ptr = (ps -> ps_base = cp) + curlen;
                     86:            ps -> ps_bufsiz += cc, ps -> ps_cnt += cc;
                     87:        }
                     88: 
                     89:     bcopy ((char *) data, ps -> ps_ptr, n);
                     90:     ps -> ps_ptr += n, ps -> ps_cnt -= n;
                     91: 
                     92:     return n;
                     93: }
                     94: 
                     95: 
                     96: static int str_close (ps)
                     97: register PS    ps;
                     98: {
                     99:     if (ps -> ps_base && !ps -> ps_inline)
                    100:        free (ps -> ps_base);
                    101: 
                    102:     return OK;
                    103: }
                    104: 
                    105: /*  */
                    106: 
                    107: int    str_open (ps)
                    108: register PS    ps;
                    109: {
                    110:     ps -> ps_readP = str_read;
                    111:     ps -> ps_writeP = str_write;
                    112:     ps -> ps_closeP = str_close;
                    113: 
                    114:     return OK;
                    115: }
                    116: 
                    117: 
                    118: int    str_setup (ps, cp, cc, in_line)
                    119: register PS    ps;
                    120: register char  *cp;
                    121: register int   cc;
                    122: int    in_line;
                    123: {
                    124:     register char  *dp;
                    125: 
                    126:     if (in_line) {
                    127:        ps -> ps_inline = 1;
                    128:        ps -> ps_base = ps -> ps_ptr = cp;
                    129:        ps -> ps_bufsiz = ps -> ps_cnt = cc;
                    130:     }
                    131:     else
                    132:        if (cc > 0) {
                    133:            if ((dp = malloc ((unsigned) (cc))) == NULLCP)
                    134:                return ps_seterr (ps, PS_ERR_NMEM, NOTOK);
                    135:            ps -> ps_base = ps -> ps_ptr = dp;
                    136:            if (cp != NULLCP)
                    137:                bcopy (cp, dp, cc);
                    138:            ps -> ps_bufsiz = ps -> ps_cnt = cc;
                    139:        }
                    140: 
                    141:     return OK;
                    142: }

unix.superglobalmegacorp.com

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