Annotation of researchv10no/ipc/mgrs/4.3gate/getfields.c, revision 1.1.1.1

1.1       root        1: static char is_sep[256], is_field[256];
                      2: static init = 0;
                      3: 
                      4: void
                      5: setfields(arg)
                      6:        char *arg;
                      7: {
                      8:        register unsigned char *s = (unsigned char *)arg;
                      9: 
                     10:        memset(is_sep, 0, sizeof is_sep);
                     11:        memset(is_field, 1, sizeof is_field);
                     12:        while(*s){
                     13:                is_sep[*s] = 1;
                     14:                is_field[*s++] = 0;
                     15:        }
                     16:        is_field[0] = 0;
                     17:        init = 1;
                     18: }
                     19: 
                     20: getfields(ss, sp, nptrs)
                     21:        char *ss;
                     22:        char **sp;
                     23: {
                     24:        register unsigned char *s = (unsigned char *)ss;
                     25:        register unsigned char **p = (unsigned char **)sp;
                     26:        register unsigned c;
                     27: 
                     28:        if(init == 0)
                     29:                setfields(" \t");
                     30:        for(;;){
                     31:                if(*s == 0) break;
                     32:                if(--nptrs < 0) break;
                     33:                *p++ = s;
                     34:                while(is_field[c = *s++]);
                     35:                if(c == 0) break;
                     36:                s[-1] = 0;
                     37:        }
                     38:        if(nptrs > 0)
                     39:                *p = 0;
                     40:        else if(--s >= (unsigned char *)ss)
                     41:                *s = c;
                     42:        return(p - (unsigned char **)sp);
                     43: }
                     44: 
                     45: getmfields(ss, sp, nptrs)
                     46:        char *ss;
                     47:        char **sp;
                     48: {
                     49:        register unsigned char *s = (unsigned char *)ss;
                     50:        register unsigned char **p = (unsigned char **)sp;
                     51:        register unsigned c;
                     52:        unsigned char *goo;
                     53: 
                     54:        if(init == 0)
                     55:                setfields(" \t");
                     56:        if(*s){
                     57:                while(nptrs-- > 0){
                     58:                        *p++ = s;
                     59:                        while(is_field[*s++]);
                     60:                        goo = s-1;
                     61:                        if((c = *goo) == 0)
                     62:                                break;
                     63:                        *goo = 0;
                     64:                        while(is_sep[*s]) s++;
                     65:                        if(*s == 0) break;
                     66:                }
                     67:        }
                     68:        if(nptrs > 0)   /* plenty of room */
                     69:                *p = 0;
                     70:        else if(*s)     /* no room and we found a trailing non-is_seper */
                     71:                *goo = c;
                     72:        return(p - (unsigned char **)sp);
                     73: }
                     74: 
                     75: #ifdef MAIN
                     76: #include       <fio.h>
                     77: 
                     78: main()
                     79: {
                     80:        char *fields[256];
                     81:        char *s;
                     82:        int n, i;
                     83: 
                     84:        print("go:\n");
                     85:        while(s = Frdline(0)){
                     86:                n = getmfields(s, fields, 3);
                     87:                for(i = 0; i < n; i++)
                     88:                        Fprint(1, ">%s< ", fields[i]);
                     89:                Fputc(1, '\n');
                     90:                Fflush(1);
                     91:        }
                     92:        exit(0);
                     93: }
                     94: #endif

unix.superglobalmegacorp.com

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