Annotation of 3BSD/cmd/refer/glue4.c, revision 1.1

1.1     ! root        1: # include "stdio.h"
        !             2: # include "ctype.h"
        !             3: 
        !             4: grepcall (in, out, arg)
        !             5:        char *in, *out, *arg;
        !             6: {
        !             7: char line[200], *s, argig[100], *cv[50];
        !             8: char *inp, inb[500];
        !             9: extern char gfile[];
        !            10: FILE *qf, *gf;
        !            11: int c, oldc = 0, alph = 0, nv = 0;
        !            12: int sv0, sv1;
        !            13: strcpy (argig, arg); strcat(argig, ".ig");
        !            14: strcpy (inp=inb, in);
        !            15: if (gfile[0]==0)
        !            16:        sprintf(gfile, "/tmp/rj%dg", getpid());
        !            17: # if D1
        !            18: fprintf(stderr, "in grepcall, gfile %s in %o out %o\n", gfile,in,out);
        !            19: # endif
        !            20: for(cv[nv++] = "fgrep"; c = *inp; inp++)
        !            21:        {
        !            22:        if (c== ' ')
        !            23:                c = *inp = 0;
        !            24:        else if (isupper(c))
        !            25:                *inp = tolower(c);
        !            26:        alph = (c==0) ? 0 : alph+1;
        !            27:        if (alph == 1)
        !            28:                cv[nv++] = inp;
        !            29:        if (alph > 6)
        !            30:                *inp = 0;
        !            31:        oldc=c;
        !            32:        }
        !            33: # if D1
        !            34: fprintf(stderr, "%d args set up\n", nv);
        !            35: # endif
        !            36:        {
        !            37:        sv0 = dup(0);
        !            38:        close(0);
        !            39:        if (open (argig, 0) != 0)
        !            40:                err("Can't read fgrep index %s", argig);
        !            41:        sv1 = dup(1);
        !            42:        close(1);
        !            43:        if (creat(gfile, 0666) != 1)
        !            44:                err("Can't write fgrep output %s", gfile);
        !            45:        fgrep(nv, cv);
        !            46: # if D1
        !            47: fprintf(stderr, "fgrep returned, output is..\n");
        !            48: # endif
        !            49:        close (0); dup(sv0); close(sv0);
        !            50:        close (1); dup(sv1); close(sv1);
        !            51:        }
        !            52: 
        !            53: # if D1
        !            54: fprintf(stderr, "back from fgrep\n");
        !            55: # endif
        !            56: gf = fopen(gfile, "r");
        !            57: if (gf==NULL)
        !            58:        err("can't read fgrep output %s", gfile);
        !            59: while (fgets(line, 100, gf) == line)
        !            60:        {
        !            61:        line[100]=0;
        !            62: # if D1
        !            63: fprintf(stderr, "read line as //%s//\n",line);
        !            64: # endif
        !            65:        for(s=line; *s && (*s != '\t'); s++);
        !            66:        if (*s == '\t')
        !            67:                {
        !            68:                *s++ = '\n';
        !            69:                *s++ = 0;
        !            70:                }
        !            71:        if (line[0])
        !            72:                strcat(out, line);
        !            73: # if D1
        !            74: fprintf(stderr, "out now /%s/\n",out);
        !            75: # endif
        !            76:        while (*s) s++;
        !            77: # if D1
        !            78: fprintf(stderr, "line %o s %o s-1 %o\n",line,s,s[-1]);
        !            79: # endif
        !            80:        if (s[-1]!= '\n')
        !            81:                while (!feof(gf) && getc(gf)!= '\n') ;
        !            82:        }
        !            83: fclose(gf);
        !            84: # if D1
        !            85:        fprintf(stderr, "back from reading %, out %s\n",out);
        !            86: # else
        !            87: unlink (gfile);
        !            88: # endif
        !            89: return(0);
        !            90: }
        !            91: 
        !            92: clfgrep()
        !            93: {
        !            94: if (gfile[0])
        !            95:        unlink(gfile);
        !            96: }

unix.superglobalmegacorp.com

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