Annotation of 43BSDReno/contrib/isode-beta/compat/sstr2arg.c, revision 1.1

1.1     ! root        1: /* sstr2arg: convert string into argument list */
        !             2: 
        !             3: #ifndef        lint
        !             4: static char *rcsid = "$Header: /f/osi/compat/RCS/sstr2arg.c,v 7.0 89/11/23 21:23:34 mrose Rel $";
        !             5: #endif
        !             6: 
        !             7: /* 
        !             8:  * $Header: /f/osi/compat/RCS/sstr2arg.c,v 7.0 89/11/23 21:23:34 mrose Rel $
        !             9:  *
        !            10:  *
        !            11:  * $Log:       sstr2arg.c,v $
        !            12:  * Revision 7.0  89/11/23  21:23:34  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 "manifest.h"
        !            32: #include <errno.h>
        !            33: 
        !            34: extern int errno;
        !            35: 
        !            36: /*  */
        !            37: 
        !            38: /*
        !            39:    stash a pointer to each field into the passed array. any common seperators
        !            40:    split the words.  extra white-space between fields is ignored.
        !            41: 
        !            42:    specially-interpreted characters:
        !            43:        double-quote, backslash (preceding a special char with a backslash
        !            44:        removes its interpretation.  A backslash not followed by a special is
        !            45:        used to preface an octal specification for one character a string begun
        !            46:        with double-quote has only double-quote and backslash as special
        !            47:        characters.
        !            48: 
        !            49: */
        !            50: 
        !            51: 
        !            52: 
        !            53: 
        !            54: sstr2arg (srcptr, maxpf, argv, dlmstr)
        !            55: register char *srcptr;  /* source data */
        !            56: int maxpf;              /* maximum number of permitted fields */
        !            57: char *argv[];           /* where to put the pointers */
        !            58: char *dlmstr;           /* Delimiting character */
        !            59: {
        !            60:     char gotquote;      /* currently parsing quoted string */
        !            61:     register int ind;
        !            62:     register char *destptr;
        !            63: 
        !            64:     if (srcptr == 0) {
        !            65:        errno = EINVAL;     /* emulate system-call failure */
        !            66:        return (NOTOK);
        !            67:     }
        !            68: 
        !            69:     for (ind = 0, maxpf -= 2;; ind++) {
        !            70:        if (ind >= maxpf) {
        !            71:            errno = E2BIG;      /* emulate system-call failure */
        !            72:            return (NOTOK);
        !            73:        }
        !            74: 
        !            75:        /* Skip leading white space */
        !            76:        for (; *srcptr == '\t' || *srcptr == ' '; srcptr++);
        !            77: 
        !            78:        argv [ind] = srcptr;
        !            79:        destptr = srcptr;
        !            80: 
        !            81:        for (gotquote = 0; ; ) {
        !            82:            register char *cp;
        !            83: 
        !            84:            for (cp = dlmstr; (*cp != '\0') && (*cp != *srcptr); cp++);
        !            85: 
        !            86:            if (*cp != '\0')
        !            87:            {
        !            88:                if (gotquote) {           /* don't interpret the char */
        !            89:                    *destptr++ = *srcptr++;
        !            90:                    continue;
        !            91:                }
        !            92: 
        !            93:                srcptr++;
        !            94:                *destptr = '\0';
        !            95:                goto nextarg;
        !            96:            } else {
        !            97:                switch (*srcptr) {
        !            98:                default:        /* just copy it                     */
        !            99:                        *destptr++ = *srcptr++;
        !           100:                        break;
        !           101: 
        !           102:                case '\"':      /* beginning or end of string       */
        !           103:                        gotquote = (gotquote) ? 0 : 1 ;
        !           104:                        srcptr++;   /* just toggle */
        !           105:                        break;
        !           106: 
        !           107:                case '\\':      /* quote next character             */
        !           108:                        srcptr++;   /* just skip the back-slash         */
        !           109:                        if (*srcptr >= '0' && *srcptr <= '7') {
        !           110:                                *destptr = '\0';
        !           111:                                do
        !           112:                                    *destptr = (*destptr << 3) | (*srcptr++ - '0');
        !           113:                                while (*srcptr >= '0' && *srcptr <= '7');
        !           114:                                destptr++;
        !           115:                                break;
        !           116:                        }
        !           117:                        else
        !           118:                             *destptr++ = *srcptr++;
        !           119:                        break;
        !           120: 
        !           121:                    case '\0':
        !           122:                        *destptr = '\0';
        !           123:                        ind++;
        !           124:                        argv[ind] = (char *) 0;
        !           125:                        return (ind);
        !           126:                }
        !           127:            }
        !           128:        }
        !           129:     nextarg:
        !           130:        continue;
        !           131:     }
        !           132: }

unix.superglobalmegacorp.com

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