Annotation of 43BSDReno/contrib/isode-beta/compat/str2sel.c, revision 1.1.1.1

1.1       root        1: /* str2sel.c - string to selector */
                      2: 
                      3: #ifndef        lint
                      4: static char *rcsid = "$Header: /f/osi/compat/RCS/str2sel.c,v 7.0 89/11/23 21:23:37 mrose Rel $";
                      5: #endif
                      6: 
                      7: /* 
                      8:  * $Header: /f/osi/compat/RCS/str2sel.c,v 7.0 89/11/23 21:23:37 mrose Rel $
                      9:  *
                     10:  *
                     11:  * $Log:       str2sel.c,v $
                     12:  * Revision 7.0  89/11/23  21:23:37  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 <ctype.h>
                     31: #include <stdio.h>
                     32: #include "general.h"
                     33: #include "manifest.h"
                     34: #include "tailor.h"
                     35: 
                     36: 
                     37: #define        QUOTE   '\\'
                     38: 
                     39: /*    STR2SEL */
                     40: 
                     41: int    str2sel (s, quoted, sel, n)
                     42: char   *s,
                     43:        *sel;
                     44: int    quoted,
                     45:        n;
                     46: {
                     47:     int     i,
                     48:             r;
                     49:     register char  *cp;
                     50: 
                     51:     if (*s == NULL)
                     52:        return 0;
                     53: 
                     54:     if (quoted <= 0) {
                     55:        for (cp = s; *cp; cp++)
                     56:            if (!isxdigit (*cp))
                     57:                break;
                     58: 
                     59:        if (*cp == NULL && (i = (cp - s)) >= 2 && (i & 0x01) == 0) {
                     60:            if (i > (r = n * 2))
                     61:                i = r;
                     62:            i = implode ((u_char *) sel, s, i);
                     63:            if ((r = (n - i)) > 0)
                     64:                bzero (sel + i, r);
                     65:            return i;
                     66:        }
                     67:        if (*s == '#') {        /* gosip style, network byte-order */
                     68:            i = atoi (s + 1);
                     69:            sel[0] = (i >> 8) & 0xff;
                     70:            sel[1] = i & 0xff;
                     71: 
                     72:            return 2;
                     73:        }
                     74: 
                     75:        DLOG (compat_log, LLOG_EXCEPTIONS, ("invalid selector \"%s\"", s));
                     76:     }
                     77: 
                     78:     for (cp = sel; *s && n > 0; cp++, s++, n--)
                     79:        if (*s != QUOTE)
                     80:            *cp = *s;
                     81:        else
                     82:            switch (*++s) {
                     83:                case 'b':
                     84:                    *cp = '\b';
                     85:                    break;
                     86:                case 'f':
                     87:                    *cp = '\f';
                     88:                    break;
                     89:                case 'n':
                     90:                    *cp = '\n';
                     91:                    break;
                     92:                case 'r':
                     93:                    *cp = '\r';
                     94:                    break;
                     95:                case 't':
                     96:                    *cp = '\t';
                     97:                    break;
                     98: 
                     99:                case NULL: 
                    100:                    s--;
                    101:                case QUOTE: 
                    102:                    *cp = QUOTE;
                    103:                    break;
                    104: 
                    105:                default: 
                    106:                    if (!isdigit (*s)) {
                    107:                        *cp++ = QUOTE;
                    108:                        *cp = *s;
                    109:                        break;
                    110:                    }
                    111:                    r = *s != '0' ? 10 : 8;
                    112:                    for (i = 0; isdigit (*s); s++)
                    113:                        i = i * r + *s - '0';
                    114:                    s--;
                    115:                    *cp = toascii (i);
                    116:                    break;
                    117:            }
                    118:     if (n > 0)
                    119:        *cp = NULL;
                    120: 
                    121:     return (cp - sel);
                    122: }

unix.superglobalmegacorp.com

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