Annotation of researchv10no/cmd/nupas/ipc/util.c, revision 1.1.1.1

1.1       root        1: #include <stdio.h>
                      2: #include <sysexits.h>
                      3: 
                      4: static char is_sep[256], is_field[256];
                      5: static init = 0;
                      6: 
                      7: extern int errno;
                      8: extern char *errstr;
                      9: 
                     10: void
                     11: setfields(arg)
                     12:        char *arg;
                     13: {
                     14:        register unsigned char *s = (unsigned char *)arg;
                     15: 
                     16:        memset(is_sep, 0, sizeof is_sep);
                     17:        memset(is_field, 1, sizeof is_field);
                     18:        while(*s){
                     19:                is_sep[*s] = 1;
                     20:                is_field[*s++] = 0;
                     21:        }
                     22:        is_field[0] = 0;
                     23:        init = 1;
                     24: }
                     25: 
                     26: getfields(ss, sp, nptrs)
                     27:        char *ss;
                     28:        char **sp;
                     29: {
                     30:        register unsigned char *s = (unsigned char *)ss;
                     31:        register unsigned char **p = (unsigned char **)sp;
                     32:        register unsigned c;
                     33: 
                     34:        if(init == 0)
                     35:                setfields(" \t");
                     36:        for(;;){
                     37:                if(--nptrs < 0) break;
                     38:                *p++ = s;
                     39:                while(is_field[c = *s++]);
                     40:                if(c == 0) break;
                     41:                s[-1] = 0;
                     42:        }
                     43:        if(nptrs > 0)
                     44:                *p = 0;
                     45:        else if(--s >= (unsigned char *)ss)
                     46:                *s = c;
                     47:        return(p - (unsigned char **)sp);
                     48: }
                     49: 
                     50: getmfields(ss, sp, nptrs)
                     51:        char *ss;
                     52:        char **sp;
                     53: {
                     54:        register unsigned char *s = (unsigned char *)ss;
                     55:        register unsigned char **p = (unsigned char **)sp;
                     56:        register unsigned c;
                     57:        unsigned char *goo;
                     58: 
                     59:        if(init == 0)
                     60:                setfields(" \t");
                     61:        if(*s){
                     62:                while(nptrs-- > 0){
                     63:                        *p++ = s;
                     64:                        while(is_field[*s++]);
                     65:                        goo = s-1;
                     66:                        if((c = *goo) == 0)
                     67:                                break;
                     68:                        *goo = 0;
                     69:                        while(is_sep[*s]) s++;
                     70:                        if(*s == 0) break;
                     71:                }
                     72:        }
                     73:        if(nptrs > 0)   /* plenty of room */
                     74:                *p = 0;
                     75:        else if(*s)     /* no room and we found a trailing non-is_seper */
                     76:                *goo = c;
                     77:        return(p - (unsigned char **)sp);
                     78: }
                     79: 
                     80: /*
                     81:  * Crude version of BSD socket recv command
                     82:  */
                     83: int
                     84: recv(fd, buf, n, flags)
                     85: int fd;
                     86: char *buf;
                     87: int n, flags;
                     88: {
                     89:        if (flags != 0) {
                     90:                ipcseterror(EX_SOFTWARE, "flags not allowed", "recv");
                     91:                return(-1);
                     92:        }
                     93:        return(read(fd, buf, n));
                     94: }
                     95: 
                     96: /*
                     97:  * Crude version of BSD socket send command
                     98:  */
                     99: int
                    100: send(fd, buf, n, flags)
                    101: int fd;
                    102: char *buf;
                    103: int n, flags;
                    104: {
                    105:        if (flags != 0) {
                    106:                ipcseterror(EX_SOFTWARE, "flags not allowed", "send");
                    107:                return(-1);
                    108:        }
                    109:        return(write(fd, buf, n));
                    110: }

unix.superglobalmegacorp.com

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