From: Tom London Date: Mon, 6 Nov 1978 04:34:11 +0000 (-0500) Subject: Bell 32V development X-Git-Tag: Bell-32V~698 X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/commitdiff_plain/2b1a705ed970c2e79af7002901532e0048d627a8 Bell 32V development Work on file usr/src/cmd/refer/deliv1.c Work on file usr/src/cmd/refer/glue1.c Work on file usr/src/cmd/refer/deliv2.c Work on file usr/src/cmd/refer/flagger.c Work on file usr/src/cmd/refer/glue2.c Work on file usr/src/cmd/refer/glue3.c Work on file usr/src/cmd/refer/glue5.c Work on file usr/src/cmd/refer/hunt3.c Work on file usr/src/cmd/refer/hunt7.c Work on file usr/src/cmd/refer/hunt5.c Work on file usr/src/cmd/refer/hunt9.c Work on file usr/src/cmd/refer/hunt8.c Work on file usr/src/cmd/refer/inv1.c Work on file usr/src/cmd/refer/hunt6.c Work on file usr/src/cmd/refer/inv3.c Work on file usr/src/cmd/refer/mkey1.c Work on file usr/src/cmd/refer/inv5.c Work on file usr/src/cmd/refer/kaiser.c Work on file usr/src/cmd/refer/mkey3.c Work on file usr/src/cmd/refer/refer0.c Work on file usr/src/cmd/refer/refer..c Work on file usr/src/cmd/refer/mkey2.c Work on file usr/src/cmd/refer/refer3.c Work on file usr/src/cmd/refer/refer2.c Work on file usr/src/cmd/refer/refer8.c Work on file usr/src/cmd/refer/refer7.c Work on file usr/src/cmd/refer/thash.c Work on file usr/src/cmd/refer/refer6.c Work on file usr/src/cmd/refer/shell.c Work on file usr/src/cmd/refer/test Work on file usr/src/cmd/refer/what1.c Work on file usr/src/cmd/refer/what4.c Co-Authored-By: John Reiser Synthesized-from: 32v --- diff --git a/usr/src/cmd/refer/deliv1.c b/usr/src/cmd/refer/deliv1.c new file mode 100644 index 0000000000..ae4a57bf30 --- /dev/null +++ b/usr/src/cmd/refer/deliv1.c @@ -0,0 +1,45 @@ +# include "stdio.h" +main(argc,argv) + char *argv[]; +{ +/* goes from file:begin,l to actual characters */ +char line[750], *p, name[100]; +FILE *fa NULL; +long lp; +int len; + +if (argc>1 && argv[1] && argv[1][0]) + chdir (argv[1]); +name[0]=""; +while (gets(line)) + { + if (line[0]=='$' && line[1]=='$') + { + chdir(line+2); + continue; + } + for(p=line; *p!= ':'; p++) + ; + *p++ = 0; + sscanf(p, "%ld,%d", &lp, &len); + if (p==line) + fa = stdin; + else + if (strcmp (name, line) != 0) + { + if (fa != NULL) + fclose(fa); + fa = fopen(line, "r"); + if (fa == NULL) + err("Can't open %s", line); + strcpy(name, line); + } + if (fa != NULL) + { + fseek (fa, lp, 0); + fread (line, 1, len, fa); + line[len] = 0; + fputs(line, stdout); + } + } +} diff --git a/usr/src/cmd/refer/deliv2.c b/usr/src/cmd/refer/deliv2.c new file mode 100644 index 0000000000..2405991de6 --- /dev/null +++ b/usr/src/cmd/refer/deliv2.c @@ -0,0 +1,47 @@ +# include "stdio.h" +hash (s) + char *s; +{ +int c, n; +for(n=0; c= *s; s++) + n += (c*n+ c << (n%4)); +return(n>0 ? n : -n); +} +err (s, a) + char *s; +{ +fprintf(stderr, "Error: "); +fprintf(stderr, s, a); +putc('\n', stderr); +exit(1); +} +prefix(t, s) + char *t, *s; +{ +int c, d; +while ( (c= *t++) == *s++) + if (c==0) return(1); +return(c==0 ? 1: 0); +} +char * +mindex(s, c) + char *s; +{ +register char *p; +for( p=s; *p; p++) + if (*p ==c) + return(p); +return(0); +} +zalloc(m,n) +{ + int t; +# if D1 +fprintf(stderr, "calling calloc for %d*%d bytes\n",m,n); +# endif +t = calloc(m,n); +# if D1 +fprintf(stderr, "calloc returned %o\n", t); +# endif +return(t); +} diff --git a/usr/src/cmd/refer/flagger.c b/usr/src/cmd/refer/flagger.c new file mode 100644 index 0000000000..435cd5a505 --- /dev/null +++ b/usr/src/cmd/refer/flagger.c @@ -0,0 +1,163 @@ +# include "stdio.h" +char wds[100][40]; +int synwd[100]; +int mark[100]; +int justw 0; +extern int comcount; +int blank[100]; +int wdp, wdf; +int bl; +int sargc; char **sargv; +FILE *inf; +main(argc,argv) + char *argv[]; +{ +int i; +while (--argc && **++argv== '-') + switch(argv[0][1]) + { + case 'w': justw=1; break; + case 'c': comcount=atoi(argv[0]+2); break; + } +wdp=wdf=0; +if (argc>0) + { + argc--; + inf = fopen(argv[0], "r"); + if (inf==NULL) exit(0); + argv++; + } +else + inf=stdin; +sargc=argc; sargv= argv; +while ( gw (wds[wdp = next(wdp)], &bl)) + { + blank[wdp] = bl; + mark[wdp]=0; + synwd[wdp] = common(upcase(wds[wdp])); + if (common(sstrip(upcase(wds[wdp])))) + synwd[wdp]=1; + if (allpunct(wds[wdp])) + synwd[wdp]=1; + if (strlen(wds[wdp])<3) + synwd[wdp]=1; + if (synwd[wdp]==1) + { + for(i=wdp; i!=wdf; i=prev(i)) + { + if (synwd[i]>0) + continue; + mark[i]=1; + break; + } + } + } +if (wdp<0) return(0); +i=wdf -1; +i = next(i); +while (i != wdp) + i= next(i); +} +next(i) +{ +int j; +j = (i+1) % 100; +if (j==wdf) + { + if (justw==0) + { + if (mark[j] ) putchar('*'); + printf("%s",wds[j]); + if (blank[j]) putchar(' '); + } + else + if (mark[j]) printf("%s\n", wds[j]); + wdf = (wdf+1)%100; + } +return(j); +} +prev(i) +{ +i = (i-1)%100; +return(i); +} +allpunct(s) + char *s; +{ +int c; +while (c = *s++) + if (isalpha(c)) + return(0); +return(1); +} +gw(s, b) + char *s; + int *b; +{ +int c, type, nt; +c = getc(inf); +while (c==EOF) + { + fclose(inf); + inf=NULL; + if (sargc-->0) + { + inf = fopen ( *sargv++, "r"); + } + if (inf==NULL) return(0); + c = getc(inf); + } +*s++ = c; +type = isalpha(c) || isdigit(c); +while ( (c = getc(inf)) != EOF ) + { + nt = isalpha(c) || isdigit(c); + if (nt==type) + *s++= c; + else + break; + } +*s=0; +if (c== ' ') + { + *b = 1; + return(1); + } +while (c==EOF) + { + fclose(inf); inf=NULL; + if (sargc-- > 0) + { + inf= fopen( *sargv++, "r"); + } + if (inf==NULL) return(0); + c = getc(inf); + } +ungetc(c, inf); +*b=0; +return(1); +} +trimnl(s) + char *s; +{ +while (*s) s++; +if (*--s=='\n') *s=0; +} +upcase(s) + char *s; +{ +static char buf[100]; +strcpy (buf, s); +for(s=buf; *s; s++) + if (isupper(*s)) + *s = *s-'A'+'a'; +return(buf); +} +sstrip(s) + char *s; +{ +char *p ; p=s; +while (*s) s++; +if (*--s=='s') *s=0; +return(p); +} diff --git a/usr/src/cmd/refer/glue1.c b/usr/src/cmd/refer/glue1.c new file mode 100644 index 0000000000..076fbbe08e --- /dev/null +++ b/usr/src/cmd/refer/glue1.c @@ -0,0 +1,259 @@ +# include "stdio.h" +# define unopen(fil) {if (fil!=NULL) {fclose(fil); fil=NULL;}} +extern char refdir[]; +int lmaster = 1000; +int reached = 0; +FILE *fd = 0; +int *hfreq, hfrflg; +int colevel = 0; +static union firetruck {unsigned *a; long *b;} master; +int iflong; +extern char *fgnames[], **fgnamp; +extern FILE *iopen(); +char *todir(); +int prfreqs = 0; +int typeindex = 0; +char usedir[100]; +static int full = 1000; +static int tags = 0; +char *sinput, *soutput, *tagout; +long indexdate = 0, gdate(); +int soutlen = 1000; +int taglen = 1000; + +huntmain(argc,argv) + char *argv[]; +{ +/* read query from stdin, expect name of indexes in argv[1] */ +static FILE *fa, *fb, *fc; +char indexname[100], *qitem[100], *rprog = 0; +char grepquery[200]; +static char oldname[30] ; +static int nhash = 0; +static int maxhash = 0; +int falseflg = 0, nitem, nfound, frtbl; +static long *hpt = 0; +# if D1 +fprintf(stderr, "in glue1 argc %d argv %o %o\n", argc, argv[0],argv[1]); +# endif +savedir(); +while (argv[1][0] == '-') + { +# if D1 +fprintf(stderr, "argv.1 is %s\n",argv[1]); +# endif + switch(argv[1][1]) + { + case 'a': /* all output, incl. false drops */ + falseflg = 1; break; + case 'r': + argc--; argv++; + rprog = argv[1]; + break; + case 'F': /* put out full text */ + full = setfrom(argv[1][2]); + break; + case 'T': /* put out tags */ + tags = setfrom(argv[1][2]); + break; + case 'i': /* input in argument string */ + argc--; argv++; + sinput = argv[1]; + break; + case 's': /*text output to string */ + case 'o': + argc--; argv++; + soutput = argv[1]; + if (argv[2]<16000) + { + soutlen = argv[2]; + argc--; argv++; + } + break; + case 't': /*tag output to string */ + argc--; argv++; + tagout = argv[1]; + if (argv[2]<16000) + { + taglen = argv[2]; + argc--; argv++; + } + break; + case 'l': /* specify length of lists */ + argc--; argv++; + lmaster = atoi(argv[1]); +# if D1 + fprintf(stderr, "lmaster now %d\n",lmaster); +# endif + break; + case 'C': + argc--; argv++; + colevel = atoi(argv[1]); + break; + } + argc--; argv++; + } +strcpy (indexname, todir(argv[1])); +# if D1 +fprintf(stderr, "in huntmain indexname %s typeindex %d\n", indexname, typeindex); +# endif +if (typeindex == 0 || strcmp (oldname, indexname) !=0) + { + strcpy (oldname, indexname); + unopen(fa); unopen(fb); unopen(fc); + + if (ckexist(indexname, ".ib")) + { +# if D1 + fprintf(stderr, "found old index\n"); +# endif + fa = iopen(indexname, ".ia"); + fb = iopen(indexname, ".ib"); + fc = iopen(indexname, ".ic"); + typeindex =1; +# if D1 + fprintf(stderr, "opened f's as %o %o %o\n",fa,fb,fc); +# endif + indexdate = gdate(fb); + fread (&nhash, sizeof(nhash), 1, fa); + fread (&iflong, sizeof(iflong), 1, fa); + if (nhash > maxhash) + { + if (hpt) + free (hpt, maxhash, sizeof(*hpt)); + hpt=0; + if (hfreq) + free(hfreq, maxhash, sizeof(*hfreq)); + hfreq=0; + maxhash=nhash; +# if D1 + fprintf(stderr, "Freed if needed maxhash %d\n",maxhash); +# endif + } + if (hpt==0) + hpt = zalloc(nhash, sizeof(*hpt)); +# if D1 + fprintf(stderr, "hpt now %o\n",hpt); +# endif + if (hpt == NULL) + err ("No space for hash list (%d)", nhash); + fread( hpt, sizeof(*hpt), nhash, fa); + if (hfreq==0) + hfreq=zalloc(nhash, sizeof(*hfreq)); + if (hfreq==NULL) + err ("No space for hash frequencies (%d)", nhash); + frtbl = fread(hfreq, sizeof(*hfreq), nhash, fa); + hfrflg = (frtbl == nhash); +# if D1 + fprintf(stderr,"Read pointer files\n"); +# endif + if (master.a == NULL) + if (iflong) + master.b = zalloc(lmaster, sizeof(long)); + else + master.a = zalloc(lmaster, sizeof(int)); + if (master.a == NULL) + err ("no space for answer list",0); + } + else + if (makefgrep(indexname)) + typeindex=2; + else + { + err ("No files %s\n",indexname); + exit(1); + } + } + +# if D1 +fprintf(stderr, "typeindex now %d\n",typeindex); +# endif +tagout[0]=0; +if (typeindex==2) + { + grepcall(sinput, tagout, indexname); +# if D1 + fprintf(stderr, " back from grepcall\n"); +# endif + restodir(); + return; + } +nitem = getq(qitem); +# if D1 +fprintf(stderr, "approaching doquery fb %o\n", fb); +# endif +nfound = doquery(hpt, nhash, fb, nitem, qitem, master); +# ifdef D1 + fprintf(stderr, "return from doquery with nfound %d\n", nfound); +# endif +if (falseflg == 0) + nfound = baddrop(master, nfound, fc, nitem, qitem, rprog, full); +# ifdef D1 + fprintf(stderr, "after baddrop with nfound %d\n",nfound); + fprintf(stderr, "tagout is /%s/, sout /%s/\n",tagout, soutput); +# endif +if (tags) + result (master, nfound >tags ? tags : nfound, fc); +# if D1 +fprintf(stderr, "done with huntmain\n"); +fprintf(stderr, "tagout is /%s/\n", tagout); +fprintf(stderr, "string out is /%s/\n", soutput); +# endif +if (fgnamp>fgnames) + { + char **fgp; + int k; +# if D1 + fprintf(stderr, "were %d bad files\n", fgnamp-fgnames); +# endif + grepquery[0]=0; + for(k=0; k=t && *s != '/') s--; + if (s ALEN) + err("abuff not big enough %d", strlen(abuff)); +argc = 6; +huntmain (argc,argv); +return(0); +} +dodeliv(in, out, arg, outlen) + char *in, *out, *arg; +{ +# if D1 +fprintf(stderr, "in dodeliv, arg /%s/\n", arg?arg:""); +# endif +if (arg && arg[0]) + chdir(arg); +findline(in, out, outlen, 0L); +restodir(); +} diff --git a/usr/src/cmd/refer/glue5.c b/usr/src/cmd/refer/glue5.c new file mode 100644 index 0000000000..134da9585a --- /dev/null +++ b/usr/src/cmd/refer/glue5.c @@ -0,0 +1,361 @@ +# include "stdio.h" +# include "ctype.h" +/* + * fgrep -- print all lines containing any of a set of keywords + * + * status returns: + * 0 - ok, and some matches + * 1 - ok, but no matches + * 2 - some error + */ +#define MAXSIZ 700 +#define QSIZE 400 +struct words { + char inp; + char out; + struct words *nst; + struct words *link; + struct words *fail; +} +*www, *smax, *q; + +char buf[1024]; +int nsucc; +int need; +char *instr; +int inct; +int rflag; +int xargc; +char **xargv; +int numwords; +int nfound; +static int flag = 0; + + +fgrep(argc, argv) +char **argv; +{ + instr = nsucc = need = inct = rflag = numwords = nfound = 0; + flag = 0; + if (www==0) + www = zalloc(MAXSIZ, sizeof (*www)); + if (www==NULL) + err("Can't get space for machines", 0); + for (q=www; qinp =0; q->out =0; q->nst =0; q->link =0; q->fail =0; + } + xargc = argc-1; + xargv = argv+1; + while (xargc>0 && xargv[0][0]=='-') + { + switch(xargv[0][1]) + { + case 'r': /* return value only */ + rflag++; + break; + case 'n': /* number of answers needed */ + need = xargv[1]; + xargv++; xargc--; + break; + case 'i': + instr = xargv[1]; + inct = xargv[2]+2; +# if D2 +fprintf(stderr,"inct %d xargv.2. %o %d\n",inct, xargv[2],xargv[2]); +# endif + xargv += 2; xargc -= 2; + break; + } + xargv++; xargc--; + } + if (xargc<=0) + { + write (2, "bad fgrep call\n", 15); + exit(2); + } +# if D1 + fprintf(stderr, "before cgoto\n"); +# endif + cgotofn(); +# if D1 + fprintf(stderr, "before cfail\n"); +# endif + cfail(); +# if D1 + fprintf(stderr, "before execute instr %.20s\n", instr? instr: ""); + fprintf(stderr, "end of string %d %c %c %c\n", inct, instr[inct-3], + instr[inct-2], instr[inct-1]); +# endif + execute(); +# if D1 + fprintf(stderr, "returning nsucc %d\n", nsucc); + fprintf(stderr, "fgrep done www %o\n",www); +# endif + return(nsucc == 0); +} + +execute() +{ + register char *p; + register struct words *c; + register ch; + register ccount; + int f; + char *nlp; + f=0; + ccount = instr ? inct : 0; + nfound=0; + p = instr ? instr : buf; + if (need == 0) need = numwords; + nlp = p; + c = www; +# if D2 +fprintf(stderr, "in execute ccount %d inct %d\n",ccount, inct ); +# endif + for (;;) { +# if D3 +fprintf(stderr, "down ccount\n"); +# endif + if (--ccount <= 0) { +# if D2 +fprintf(stderr, "ex loop ccount %d instr %o\n",ccount, instr); +# endif + if (instr) break; + if (p == &buf[1024]) p = buf; + if (p > &buf[512]) { + if ((ccount = read(f, p, &buf[1024] - p)) <= 0) break; + } + else if ((ccount = read(f, p, 512)) <= 0) break; +# if D2 +fprintf(stderr, " normal read %d bytres\n", ccount); +{char xx[20]; sprintf(xx, "they are %%.%ds\n", ccount); +fprintf(stderr, xx, p); +} +# endif + } +nstate: + ch = *p; +# if D2 +fprintf(stderr, "roaming along in ex ch %c c %o\n",ch,c); +# endif + if (isupper(ch)) ch |= 040; + if (c->inp == ch) { + c = c->nst; + } + else if (c->link != 0) { + c = c->link; + goto nstate; + } + else { + c = c->fail; + if (c==0) { + c = www; +istate: + if (c->inp == ch) { + c = c->nst; + } + else if (c->link != 0) { + c = c->link; + goto istate; + } + } + else goto nstate; + } + if (c->out && new (c)) { +# if D2 +fprintf(stderr, " found: nfound %d need %d\n",nfound,need); +# endif + if (++nfound >= need) + { +# if D1 +fprintf(stderr, "found, p %o nlp %o ccount %d buf %o buf[1024] %o\n",p,nlp,ccount,buf,buf+1024); +# endif + if (instr==0) + while (*p++ != '\n') { +# if D3 +fprintf(stderr, "down ccount2\n"); +# endif + if (--ccount <= 0) { + if (p == &buf[1024]) p = buf; + if (p > &buf[512]) { + if ((ccount = read(f, p, &buf[1024] - p)) <= 0) break; + } + else if ((ccount = read(f, p, 512)) <= 0) break; +# if D2 +fprintf(stderr, " read %d bytes\n",ccount); +{ char xx[20]; sprintf(xx, "they are %%.%ds\n", ccount); +fprintf(stderr, xx, p); +} +# endif + } + } + nsucc = 1; + if (rflag==0) + { +# if D2 +fprintf(stderr, "p %o nlp %o buf %o\n",p,nlp,buf); +if (p>nlp) +{write (2, "XX\n", 3); write (2, nlp, p-nlp); write (2, "XX\n", 3);} +# endif + if (p > nlp) write(1, nlp, p-nlp); + else { + write(1, nlp, &buf[1024] - nlp); + write(1, buf, p-&buf[0]); + } + if (p[-1]!= '\n') write (1, "\n", 1); + } + if (instr==0) + { + nlp = p; + c = www; + nfound=0; + } + } + else + ccount++; + continue; + } +# if D2 +fprintf(stderr, "nr end loop p %o\n",p); +# endif + if (instr) + p++; + else + if (*p++ == '\n') + { + nlp = p; + c = www; + nfound=0; + } + } + if (instr==0) + close(f); +} + +cgotofn() { + register c; + register struct words *s; + s = smax = www; +nword: + for(;;) { +# if D1 + fprintf(stderr, " in for loop c now %o %c\n",c, c>' ' ? c : ' '); +# endif + if ((c = gch())==0) return; + else if (c == '\n') { + s->out = 1; + s = www; + } + else { +loop: + if (s->inp == c) { + s = s->nst; + continue; + } + if (s->inp == 0) goto enter; + if (s->link == 0) { + if (smax >= &www[MAXSIZ - 1]) overflo(); + s->link = ++smax; + s = smax; + goto enter; + } + s = s->link; + goto loop; + } + } + +enter: + do { + s->inp = c; + if (smax >= &www[MAXSIZ - 1]) overflo(); + s->nst = ++smax; + s = smax; + } + while ((c = gch()) != '\n'); + smax->out = 1; + s = www; + numwords++; + goto nword; + +} + +gch() +{ + static char *s; + if (flag==0) + { + flag=1; + s = *xargv++; +# if D1 + fprintf(stderr, "next arg is %s xargc %d\n",s,xargc); +# endif + if (xargc-- <=0) return(0); + } + if (*s) return(*s++); + for(flag=0; flag<1024; flag++) + buf[flag]=0; + flag=0; + return('\n'); +} + +overflo() { + write(2,"wordlist too large\n", 19); + exit(2); +} +cfail() { + struct words *queue[QSIZE]; + struct words **front, **rear; + struct words *state; + register char c; + register struct words *s; + s = www; + front = rear = queue; +init: + if ((s->inp) != 0) { + *rear++ = s->nst; + if (rear >= &queue[QSIZE - 1]) overflo(); + } + if ((s = s->link) != 0) { + goto init; + } + + while (rear!=front) { + s = *front; + if (front == &queue[QSIZE-1]) + front = queue; + else front++; +cloop: + if ((c = s->inp) != 0) { + *rear = (q = s->nst); + if (front < rear) + if (rear >= &queue[QSIZE-1]) + if (front == queue) overflo(); + else rear = queue; + else rear++; + else + if (++rear == front) overflo(); + state = s->fail; +floop: + if (state == 0) state = www; + if (state->inp == c) { + q->fail = state->nst; + if ((state->nst)->out == 1) q->out = 1; + continue; + } + else if ((state = state->link) != 0) + goto floop; + } + if ((s = s->link) != 0) + goto cloop; + } +} +static int seen[50]; +new (x) +{ + int i; + for(i=0; i 0) + { + if (c== '\n') + break; + if (isalpha(c) || isdigit(c)) + { + if (las==0) + { + v[n++] = p; + las=1; + } + if (las++ <= 6) + *p++ = c; + } + else + { + if (las>0) + *p++ = 0; + las=0; + } + } +*p=0; +assert(p_file, &sb); +return (sb . st_mtime); +} diff --git a/usr/src/cmd/refer/hunt6.c b/usr/src/cmd/refer/hunt6.c new file mode 100644 index 0000000000..589f6c39b6 --- /dev/null +++ b/usr/src/cmd/refer/hunt6.c @@ -0,0 +1,110 @@ +# include "stdio.h" +# include "assert.h" +# define TXTLEN 1000 +char *outbuf = 0; +extern char *soutput; +extern int soutlen, iflong; +extern long indexdate; +baddrop(master, nf, fc, nitem, qitem, rprog, full) + union ptr {unsigned *a; long *b; } master; + FILE *fc; + char *qitem[], *rprog; +{ +/* checks list of drops for real bad drops; + uses "deliv" to find items. */ +int i, g, j, need, got, na, len; +long lp; +char res[100], *ar[50], output[TXTLEN]; +extern int colevel, reached; +# if D1 +if (iflong) +fprintf(stderr,"in baddrop, nf %d master %ld %ld %ld\n", nf, master.b[0], master.b[1], master.b[2]); +else +fprintf(stderr,"in baddrop, nf %d master %d %d %d\n", nf, master.a[0], master.a[1], master.a[2]); +# endif +for (i=g=0; i= g) + if (soutput==0) + fputs(output, stdout); + else + strcpy (soutput, output); + } +# ifdef D1 + fprintf(stderr, "after fgrep\n"); +# endif + } +return(g); +} +auxil( res, output) + char *res, *output; +{ +extern FILE *fd; +long lp, c; int len; +if (fd==0)return(0); +while (c = *res++) + { + if (c == ';') + { + sscanf(res, "%ld,%d", &lp, &len); + fseek (fd, lp, 0); + fgets(output, len, fd); + return(1); + } + } +return(0); +} diff --git a/usr/src/cmd/refer/hunt7.c b/usr/src/cmd/refer/hunt7.c new file mode 100644 index 0000000000..6a7430897c --- /dev/null +++ b/usr/src/cmd/refer/hunt7.c @@ -0,0 +1,104 @@ +# include "stdio.h" +# define SAME 0 +# include "assert.h" +# define FGCT 10 +# define FGSIZE 150 +int keepold = 1; /* keep old things for fgrep search */ +char fgspace[FGSIZE]; +char *fgp = fgspace; +char *fgnames[FGCT]; +char **fgnamp = fgnames; +findline(in, out, outlen, indexdate) + long indexdate; + char *in, *out; +{ +static char name[100] = ""; +char *p, **ftp; +extern long gdate(); +static FILE *fa = NULL; +long lp, llen; +int len, k, nofil; + +# if D1 + fprintf(stderr, "findline: %s\n", in); +# endif + if (mindex(in, '!')) + return(remote(in, out)); + nofil = in[0]==0; + for(p=in; *p && *p != ':' && *p != ';'; p++) + ; + if (*p) *p++=0; + else p=in; + k = sscanf(p, "%ld,%ld", &lp, &llen); +# ifdef D1 + fprintf(stderr, "p %s k %d lp %ld llen %ld\n",p,k,lp,llen); +# endif + if (k<2) + { + lp = 0; + llen=outlen; + } +# ifdef D1 + fprintf(stderr, "lp %ld llen %ld\n",lp, llen); +# endif +# ifdef D1 +fprintf(stderr, "fa now %o, p %o in %o %s\n",fa, p,in,in); +# endif + if (nofil) +{ +# if D1 +fprintf(stderr, "set fa to stdin\n"); +# endif + fa = stdin; +} + else + if (strcmp (name, in) != 0 || 1) + { +# if D1 +fprintf(stderr, "old: %s new %s not equal\n",name,in); +# endif + if (fa != NULL) + fa = freopen(in, "r", fa); + else + fa = fopen(in, "r"); +# if D1 + if (fa==NULL) fprintf(stderr, "failed to (re)open *%s*\n",in); +# endif + if (fa == NULL) + return(0); + /* err("Can't open %s", in); */ + strcpy(name, in); + if (gdate(fa) > indexdate && indexdate != 0) + { + if (keepold) + { + for(ftp=fgnames; ftp= outlen) ? outlen-1 : llen; + len = fread (out, 1, len, fa); + out[len] = 0; +# ifdef D1 + fprintf(stderr, "length as read is %d\n",len); +# endif + } + return(len); +} diff --git a/usr/src/cmd/refer/hunt8.c b/usr/src/cmd/refer/hunt8.c new file mode 100644 index 0000000000..c9e9e5180a --- /dev/null +++ b/usr/src/cmd/refer/hunt8.c @@ -0,0 +1,73 @@ +# include "stdio.h" +# include "assert.h" +# define unopen(fil) {if (fil!=NULL) {fclose(fil); fil=NULL;}} +extern long indexdate, gdate(); +extern FILE *iopen(); +runbib (s) + char *s; +{ +/* make a file suitable for fgrep */ +char tmp[200]; +sprintf(tmp, "/usr/lib/refer/mkey %s >%s.ig", s,s); +system(tmp); +} +makefgrep(indexname) + char *indexname; +{ + FILE *fa, *fb; + if (ckexist(indexname, ".ig")) + { + /* existing gfrep -type index */ +# if D1 + fprintf(stderr, "found fgrep\n"); +# endif + fa = iopen(indexname, ".ig"); + fb = iopen(indexname, ""); + if (gdate(fb)>gdate(fa)) + { + fclose(fa); + runbib(indexname); + fa= iopen(indexname, ".ig"); + } + indexdate = gdate(fa); + unopen(fa); unopen(fb); + } + else + if (ckexist(indexname, "")) + { + /* make fgrep */ +# if D1 + fprintf(stderr, "make fgrep\n"); +# endif + runbib(indexname); + time(&indexdate); + unopen(fb); + } + else /* failure */ + return(0); +return(1); /* success */ +} +ckexist(s, t) + char *s, *t; +{ +char fnam[100]; +strcpy (fnam, s); +strcat (fnam, t); +return (access(fnam, 04) != -1); +} +FILE * +iopen (s, t) + char *s, *t; +{ +char fnam[100]; +FILE *f; +strcpy (fnam, s); +strcat (fnam, t); +f = fopen (fnam, "r"); +if (f == NULL) + { + err("Missing expected file %s", fnam); + exit(1); + } +return(f); +} diff --git a/usr/src/cmd/refer/hunt9.c b/usr/src/cmd/refer/hunt9.c new file mode 100644 index 0000000000..73b615f561 --- /dev/null +++ b/usr/src/cmd/refer/hunt9.c @@ -0,0 +1,6 @@ +remote(in, out) + char *in, *out; +{ +/* "in" is a long distance file name: get it */ +; +} diff --git a/usr/src/cmd/refer/inv1.c b/usr/src/cmd/refer/inv1.c new file mode 100644 index 0000000000..a253420177 --- /dev/null +++ b/usr/src/cmd/refer/inv1.c @@ -0,0 +1,157 @@ +# include "stdio.h" +# include "assert.h" + +main(argc, argv) + char *argv[]; +{ +/* make inverted file indexes. Reads a stream from mkey which + gives record pointer items and keys. Generates a set of files + a. NHASH pointers to file b. + b. lists of record numbers. + c. record pointer items. + + these files are named xxx.ia, xxx.ib, xxx.ic; + where xxx is taken from arg1. + If the files exist they are updated. +*/ + +FILE *fa, *fb, *fc, *fta, *ftb, *ftc, *fd; +int nhash = 256; +int appflg = 1; +int keepkey = 0, pipein = 0; +char nma[100], nmb[100], nmc[100], com[100], nmd[100]; +char tmpa[20], tmpb[20], tmpc[20]; +char *remove = NULL; +int chatty = 0, docs, hashes, fp[2], fr, fw, pfork, pwait, status; +int i,j,k; +long keys; +int iflong =0; +char *sortdir; + +sortdir = (access("/crp/tmp", 06)==0) ? "/crp/tmp" : "/usr/tmp"; +while (argv[1][0] == '-') + { + switch(argv[1][1]) + { + case 'h': /* size of hash table */ + nhash = atoi (argv[1]+2); break; + case 'n': /* new, don't append */ + appflg=0; break; + case 'a': /* append to old file */ + appflg=1; break; + case 'v': /* verbose output */ + chatty=1; break; + case 'd': /* keep keys on file .id for check on searching */ + keepkey=1; break; + case 'p': /* pipe into sort (saves space, costs time)*/ + pipein = 1; break; + case 'i': /* input is on file, not stdin */ + close(0); + if (open(argv[2], 0) != 0) + err("Can't read input %s", argv[2]); + if (argv[1][2]=='u') /* unlink */ + remove = argv[2]; + argc--; argv++; + break; + } + argc--; + argv++; + } + +strcpy (nma, argc >= 2 ? argv[1] : "Index"); +strcpy (nmb, nma); +strcpy (nmc, nma); +strcpy (nmd, nma); +strcat (nma, ".ia"); +strcat (nmb, ".ib"); +strcat (nmc, ".ic"); +strcat (nmd, ".id"); + +sprintf(tmpa, "junk%di", getpid()); +if (pipein) + { + pipe(fp); fr=fp[0]; fw=fp[1]; + if ( (pfork=fork()) == 0) + { + close(fw); + close(0); + _assert(dup(fr)==0); + close(fr); + execl("/bin/sort", "sort", "-T", sortdir, "-o", tmpa, 0); + execl("/usr/bin/sort", "sort", "-T", sortdir, "-o", tmpa, 0); + _assert(0); + } + _assert(pfork!= -1); + close(fr); + fta = fopen("/dev/null", "w"); + close(fta->_file); + fta->_file = fw; + } +else /* use tmp file */ + { + fta = fopen(tmpa, "w"); + _assert (fta != NULL); + } +fb = 0; +if (appflg ) + { + if (fb = fopen(nmb, "r")) + { + sprintf(tmpb, "junk%dj", getpid()); + ftb = fopen(tmpb, "w"); + if (ftb==NULL) + err("Can't get scratch file %s",tmpb); + nhash = recopy(ftb, fb, fopen(nma, "r")); + fclose(ftb); + } + else + appflg=0; + } +fc = fopen(nmc, appflg ? "a" : "w"); +if (keepkey) +fd = keepkey ? fopen(nmd, "w") : 0; +docs = newkeys(fta, stdin, fc, nhash, fd, &iflong); +fclose(stdin); +if (remove != NULL) + unlink(remove); +fclose(fta); +if (pipein) + { + pwait = wait(&status); + printf("pfork %o pwait %o status %d\n",pfork,pwait,status); + _assert(pwait==pfork); + _assert(status==0); + } +else + { + sprintf(com, "sort -T %s %s -o %s", sortdir, tmpa, tmpa); + system(com); + } + +if (appflg) + { + sprintf(tmpc, "junk%dk", getpid()); + sprintf(com, "mv %s %s", tmpa, tmpc); + system(com); + sprintf(com, "sort -T %s -m %s %s -o %s", sortdir, + tmpb, tmpc, tmpa); + system(com); + } +fta = fopen(tmpa, "r"); +fa = fopen(nma, "w"); +fb = fopen(nmb, "w"); +whash(fta, fa, fb, nhash, iflong, &keys, &hashes); +fclose(fta); +# ifndef D1 +unlink(tmpa); +# endif +if (appflg) + { + unlink(tmpb); + unlink(tmpc); + } +if (chatty) + + printf ("%ld key occurrences, %d hashes, %d docs\n", + keys, hashes, docs); +} diff --git a/usr/src/cmd/refer/inv3.c b/usr/src/cmd/refer/inv3.c new file mode 100644 index 0000000000..0448f4e486 --- /dev/null +++ b/usr/src/cmd/refer/inv3.c @@ -0,0 +1,16 @@ +getargs(s, arps) + char *s, *arps[]; +{ + int i; +i = 0; +while (1) + { + arps[i++]=s; + while (*s != 0 && *s!=' '&& *s != '\t')s++; + if (*s==0) break; + *s++ =0; + while (*s==' ' || *s=='\t')s++; + if (*s==0)break; + } +return(i); +} diff --git a/usr/src/cmd/refer/inv5.c b/usr/src/cmd/refer/inv5.c new file mode 100644 index 0000000000..7aa5886cd4 --- /dev/null +++ b/usr/src/cmd/refer/inv5.c @@ -0,0 +1,50 @@ +# include "stdio.h" + +recopy (ft, fb, fa, nhash) + FILE *ft, *fb, *fa; +{ +/* copy fb (old hash items/pointers) to ft (new ones) */ +int n, i, iflong; +long getl(); +int getw(); +int *hpt_s; +int (*getfun)(); +long *hpt_l; +long k, lp; +if (fa==NULL) + { + err("No old pointers",0); + return; + } +fread(&n, sizeof(n), 1, fa); +fread(&iflong, sizeof(iflong), 1, fa); +if (iflong) + { + hpt_l = calloc(sizeof(*hpt_l), n+1); + n =fread(hpt_l, sizeof(*hpt_l), n, fa); + } +else + { + hpt_s = calloc(sizeof(*hpt_s), n+1); + n =fread(hpt_s, sizeof(*hpt_s), n, fa); + } +if (n!= nhash) + fprintf(stderr, "Changing hash value to old %d\n",n); +fclose(fa); +if (iflong) + getfun = getl; +else + getfun = getw; +for(i=0; i'9' || line[1]<'0') continue; + switch(line[0]) + { + case 'T': + if (state > 'T') + { + book=0; + report=0; + printf("\n%%T "); + } + printf("%s\n", line+18); + state='T'; + na = getargs(line+18, v); + for(i=0;i0) + { + printf("%%A "); + corp=0; + for(p=vv[1]; *p; p++) + if (islower(*p)) + corp=1; + if (corp==0) + { + for(p=vv[1]; *p; p++) + printf("%c. ", *p); + if (na>2 &&strcmp(vv[2], "+")) + { + printf("%s", vv[0]); + if (strcmp(vv[2], "Jr.")==0) + printf(","); + printf(" %s\n",vv[2]); + vv++;na--; + } + else + printf("%s\n", vv[0]); + } + else + printf("%s %s\n",vv[0],vv[1]); + vv+=2; + na-=2; + if (strcmp(vv[0], "+")==0) + { + vv++;na--; + } + } + continue; + case 'U': + if (state!='U') + ubuff[0]=0; + else + strcat(ubuff, " "); + state = 'U'; + strcat(ubuff, line+18); + if (line[2]=='.') + { /* end of item */ + p=ubuff; /*start*/ + volume=0; + for(s=ubuff; *s; s++) + if (s[-1]==' ' && prefix("Vol", s)) + { + for(q=s-1; q>ubuff; q--) + { + if (*q==' ' || *q==',') *q=0; + else break; + } + volume=1; + break; + } + if (*s==0) + for(s=ubuff; *s && (*s!=',' || sprefix("Inc", s+1)); s++) + ; + else + s++; + if (*s==',')*s++=0; + if (book) + printf("%%I %s\n",ubuff); + else if (volume) + printf("%%J %s\n", ubuff); + else if (substr(ubuff, "Report")!=0) + { + report=1; + printf("%%R %s\n", ubuff); + } + else + printf("%%J %s\n", ubuff); + if (volume) + { + s += 3; /* Vol */ + if (*s=='.') s++; + while (*s==' ')s++; + printf("%%V "); + while (*s && *s != ' ' && *s!=',' && *s!=';' && *s!= ':') + putchar(*s++); + putchar('\n'); + if (*s==':') + { + printf("%%N "); + while (*s==' ')s++; + while (isdigit(*s)) + putchar(*s++); + putchar('\n'); + } + *s++=0; + while (*s==' ')*s++=0; + if (s[0]=='N' && s[1]=='o' && (s[2]==' '||s[2]=='.')) + { + s+=2; + while (*s==' '||*s=='.')s++; + printf("%%N "); + while (isdigit(*s)||*s=='-') + putchar(*s++); + putchar('\n'); + } + if (*s==',') *s++=0; + } + for(rr=months; *rr; rr++) + { + q= substr(s, *rr); + if (q) + { + for(r=q; *r; r++); + r--; + if (*r=='.')*r=0; + printf("%%D %s\n",q); + *(q-1)=0; + break; + } + } + if (*rr==0) + { + for(q=s; *q; q++) + { + if (q[0]=='1' && q[1]=='9' && (q[4]==0 || (q[4]=='.' && q[5]==0))) + { + if (q[4]=='.') q[4]=0; + printf("%%D %s\n",q); + rr=months; + q[-1]=0; + if (q==s) q[0]=0; + break; + } + } + } + if (*rr==0) /* no date */ + printf("%%D 19xx\n"); + /* if book bite off next field for city, if report for issuer */ + if (book) + { + for(q=s; *q && *q != ','; q++) + ; + if (*q==',') + { + r=q; + r++; + while (*r==' ')r++; + if (isupper(r[0]) && isupper(r[1])) + { + r+=2; + *r++=0; + while (*r==' ')r++; + } + else + *q=0; + printf("%%C %s\n", s); + s=r; + } + } + for(q=s; *q; q++) + { + if (q[0]==' ' && q[1]=='p' && (q[2]=='p'||q[2]==0)) + { + for(r=q; r>s; r--) + { + if (*r==' ' || *r==',') + *r=0; + } + *q=0; + q+=2; + if (q[0]=='p')q++; + while (*q==' '||*q=='.')q++; + r=q; + while (isdigit(*q)||*q=='.'||*q=='-'||isalpha(*q))q++; + *q++=0; + while (*q==' ')q++; + printf("%%P %s\n",r); + break; + } + } + s=ispp(s); + while (*s==' ')s++; + while (*q==' ')q++; + if (*s||*q) + printf("%%O %s %s\n", *s?s:"", *q?q:""); + } + continue; + } + } +} +getargs(s, arps) + char *s, *arps[]; +{ + int i; +i = 0; +while (1) + { + arps[i++]=s; + while (*s != 0 && *s!=' '&& *s != '\t')s++; + if (*s==0) break; + *s++ =0; + while (*s==' ' || *s=='\t')s++; + if (*s==0)break; + } +return(i); +} +prefix(small, big) + char *small, *big; +{ +int c; +while ((c= *small++) == *big++) + if (c==0) return(1); +return(c==0); +} +substr(big, small) + char *small, *big; +{ +while (*big) + if (prefix(small, big)) + return(big); + else + big++; +return(0); +} +sprefix(small, big) + char *small, *big; +{ +while (*big==' ') big++; +return(prefix(small,big)); +} +ispp(s) + char *s; +{ +static char buff[50]; +char *p, *t; +p=s; +while (*p==' ') p++; +if (!isdigit(*p)) return(s); +t=p; +while (isdigit(*p))p++; +if (p[0]!='p' || p[1]!='p') return(s); +*p=0; +sprintf(buff, "%spp.", t); +return(buff); +} diff --git a/usr/src/cmd/refer/mkey1.c b/usr/src/cmd/refer/mkey1.c new file mode 100644 index 0000000000..8fd266fe03 --- /dev/null +++ b/usr/src/cmd/refer/mkey1.c @@ -0,0 +1,87 @@ +# include "stdio.h" +extern char *comname; /* "/usr/lib/eign" */ +int wholefile = 0; +int keycount = 100; +int labels = 1; +int minlen = 3; +extern int comcount; +char *iglist = "XYZ"; + +main (argc,argv) + char *argv[]; +{ +/* this program expects as its arguments a list of + files and generates a set of lines of the form + filename:byte-add,length (tab) key1 key2 key3 + where the byte addresses give the position within + the file and the keys are the strings off the lines + which are alphabetic, first six characters only. +*/ + +int i; +char *name, qn[200]; +char *inlist = 0; + +FILE *f, *ff; + +while (argc>1 && argv[1][0] == '-') + { + switch(argv[1][1]) + { + case 'c': + comname = argv[2]; + argv++; argc--; + break; + case 'w': + wholefile = 1; break; + case 'f': + inlist = argv[2]; + argv++; argc--; + break; + case 'i': + iglist = argv[2]; + argv++; argc--; + break; + case 'l': + minlen = atoi(argv[1]+2); + if (minlen<=0) minlen=3; + break; + case 'n': /* number of common words to use */ + comcount = atoi(argv[1]+2); + break; + case 'k': /* number of keys per file max */ + keycount = atoi(argv[1]+2); + break; + case 's': /* suppress labels, search only */ + labels = 0; + break; + } + argc--; argv++; + } +if (inlist) + { + ff = fopen(inlist, "r"); + while (fgets(qn, 200, ff)) + { + trimnl(qn); + f = fopen (qn, "r"); + if (f!=NULL) + dofile(f, qn); + else + fprintf(stderr, "Can't read %s\n",qn); + } + } +else +if (argc<=1) + dofile(stdin, ""); +else +for(i=1; i0 && len >= MAXLINE) + { + fseek (f, 0L, 2); + return(ftell(f)); + } + } + eof=1; + return(s[0] ? len : 0L); +} +char * +trimnl(ln) + char *ln; +{ +register char *p = ln; +while (*p) p++; +p--; +if (*p == '\n') *p=0; +return(ln); +} +chkey (c, name) + { + if (isalpha(c) || isdigit(c)) + { + if (alph++ < 6) + *p++ = c; + } + else + { + *p = 0; + for(p=key; *p; p++) + *p |= 040; + if (outkey(p=key,prevc,c)) + { + if (used==0) + { + if (labels) + { + if (wholefile==0) + printf("%s:%ld,%ld\t", name, lp, lim); + else + printf("%s\t", name); + } + } + else + putchar(' '); + fputs(key, stdout); + used++; + } + prevc=c; + alph=0; + } + } diff --git a/usr/src/cmd/refer/mkey3.c b/usr/src/cmd/refer/mkey3.c new file mode 100644 index 0000000000..0787400eeb --- /dev/null +++ b/usr/src/cmd/refer/mkey3.c @@ -0,0 +1,50 @@ +# include "stdio.h" +char *comname = "/usr/lib/eign"; +static int cgate = 0; +extern char *comname; +# define COMNUM 500 +# define COMTSIZE 997 +int comcount = 100; +static char cbuf[COMNUM*9]; +static char *cwds[COMTSIZE]; +static char *cbp; + +common (s) + char *s; +{ +if (cgate==0) cominit(); +return (c_look(s, 1)); +} +cominit() +{ +int i; +FILE *f; +cgate=1; +f = fopen(comname, "r"); +if (f==NULL) return; +cbp=cbuf; +for(i=0; iQLEN) + err("buff too big (%d)", strlen(buff)); + assert (strlen(dbuff) <3*QLEN); + } +if (strcmp (buff, "$LIST$\n")==0) + { +# if D1 +fprintf(stderr, "dump sorted list\n"); +# endif + assert ( dbuff[0]==0); + dumpold(); + return; + } +answer[0] = 0; +# ifdef D1 + fprintf(stderr, "query is %s\n",buff); +# endif +for( p=buff; *p; p++) + { + if (isupper(*p)) *p |= 040; + } +alph = digs =0; +for(p=buff; *p; p++) + { + if (isalpha(chp = *p)) alph++; + else + if (isdigit(*p)) digs++; + else + { + *p=0; + if ( (alph+digs<3) || common(p-alph)) + { + r = p-alph; + while (r < p) + *r++ = ' '; + } + if ( alph==0 && digs >0) + { + r = p-digs; +# if D1 +fprintf(stderr, "number, %d long, text is %s\n",digs,r); +# endif + if (digs != 4 || (atoi(r)/100 != 19)) + { + while (rLLINE) + err("Accumulated answers too large",0); + strcat (answer, temp); + if (strlen(answer)>LLINE) + err("answer too long (%d)", strlen(answer)); + if (newline(answer) > 0) break; + } +# if D1 +fprintf(stderr, "answer:\n%s****\n", answer); +# endif +assert (strlen(one)1) + { + *b++ = '\\'; + *b++ = 's'; + *b++ = '+'; + *b++ = '2'; + } + if (this) + c &= (~040); + *b++ = c; + alph = this ? alph+1 : 0; + } +if (alph>1) + { + *b++ = '\\'; + *b++ = 's'; + *b++ = '+'; + *b++ = '2'; + } +*b=0; +return (p); +} +char * +revauth(s, b) + char *s, *b; +{ +char *init, *name, *jr, *p, *bcop; +bcop = b; +init=name=s; +while (*name)name++; +jr=name; +while (name>init && *name!= ' ') + name--; +if (name[-1] == ',' || name[-1]== '(' ) + { + jr = --name; + while (name>init && *name != ' ') + name--; + } +p=name; +while (p=NRFTBL) + err("too many references (%d) for table", refnum); +strcpy (rtp, tag); +while (*rtp++); +if (rtp > reftext + NRFTXT) + err("reftext too big (%d)", rtp-reftext); +return(0); +} +dumpold() +{ +FILE *fi; +int c, g1 = 0, nr = 1; +if (!endpush) return; +fclose(fo); +if (sort) + { + char comm[100]; + sprintf(comm, "sort %s -o %s", tfile, tfile); + system(comm); + } +fi = fopen(tfile, "r"); +if (fi==NULL) return; +flout(); +fprintf(ftemp,".]<\n"); +while ( (c = getc(fi)) >0) + { + if (c=='\n') + { + nr++; + g1 = 0; + } + if (c==sep) + c = '\n'; + if (c== FLAG) + { + /* make old-new ref number table */ + char tb[20]; + char *s = tb; + while ( (c=getc(fi)) != FLAG) + *s++ = c; + *s=0; + if (g1++ == 0) + newr[atoi(tb)] = nr; +# if D1 + fprintf(stderr, "nr %d assigned to atoi(tb) %d\n",nr,atoi(tb)); +# endif + fprintf(ftemp,"%d", nr); + continue; + } + putc(c, ftemp); + } +fclose(fi); +# ifndef D1 +unlink(tfile); +# endif +fprintf(ftemp, ".]>\n"); +} + +recopy (fnam) + char *fnam; +{ +int c; +fclose(ftemp); + +ftemp = fopen(fnam, "r"); +if (ftemp==NULL) + { + fprintf(stderr, "Can't reopen %s\n", fnam); + exit(1); + } +while ( (c = getc(ftemp)) != EOF) + { + if (c == FLAG) + { + char tb[10]; + char *s = tb; + while ( (c = getc(ftemp)) != FLAG) + *s++ = c; + *s=0; + printf("%d", newr[atoi(tb)]); + continue; + } + putchar(c); + } +fclose(ftemp); +unlink(fnam); +} diff --git a/usr/src/cmd/refer/refer8.c b/usr/src/cmd/refer/refer8.c new file mode 100644 index 0000000000..6ea018a861 --- /dev/null +++ b/usr/src/cmd/refer/refer8.c @@ -0,0 +1,32 @@ +# include "refer..c" +static char ahead[1000]; +static int peeked = 0; +static int noteof = 1; +char * +input (s) + char *s; +{ +if (peeked) + { + peeked=0; + if (noteof==0) return(0); + strcpy (s, ahead); + return(s); + } +return(fgets(s, 1000, in)); +} +char * +lookat() +{ +if (peeked) return(ahead); +noteof=input(ahead); +peeked=1; +return(noteof); +} +addch(s, c) + char *s; +{ +while (*s) s++; +*s++ = c; +*s = 0; +} diff --git a/usr/src/cmd/refer/shell.c b/usr/src/cmd/refer/shell.c new file mode 100644 index 0000000000..ed180648e1 --- /dev/null +++ b/usr/src/cmd/refer/shell.c @@ -0,0 +1,24 @@ +shell (n, comp, exch) + int (*comp)(), (*exch)(); +/* SORTS UP. IF THERE ARE NO EXCHANGES (IEX=0) ON A SWEEP + THE COMPARISON GAP (IGAP) IS HALVED FOR THE NEXT SWEEP */ +{ + int igap, iplusg, iex, i, imax; + igap=n; +while (igap > 1) + { + igap /= 2; + imax = n-igap; + do + { + iex=0; + for(i=0; i0); + } +} diff --git a/usr/src/cmd/refer/test b/usr/src/cmd/refer/test new file mode 100644 index 0000000000..74a0e118eb --- /dev/null +++ b/usr/src/cmd/refer/test @@ -0,0 +1,60 @@ +.LP +hoboken harrison newark roseville avenue grove street +.[ +Aho Ullman subsequence 1976 +.] +east orange brick church orange highland avenue +mountain station south orange maplewood millburn short hills +.[ +Kernighan software tools 1975 +.] +summit chatham madison convent station morristown +new providence murray hill berkeley heights +gillette stirling millington lyons basking ridge +.[ +Kernighan typesetting guide second +.] +bernardsville far hills peapack gladstone +.LP +Each person to whom this notice is addressed is entitled to submit, +.[ +Kernighan tools 1975 +.] +or request the Department of Labor to submit, to the District Director +described above, a comment on the question of whether the Plan meets the +requirements for qualification under Part I of Subchapter D of Chapter +I of the Internal Revenue Code of 1954. Two or more such persons +.[ +Blue Cubic spline CSTR +.] +may join in a single comment or request. If such a person or persons +request the Department of Labor to submit a comment and that department +declines to do so in respect of one or more matters raised in the request, +the person or persons so requesting may submit a comment to the +.[ +Graham small hexagon +.] +.[ +Blue cubic spline CSTR +.] +District Director in respect of the matters on which the Department +of Labor declines to comment. A comment +submitted to the District Director must be received +by him on or before June 30, 1977. However, if it is +being submitted on a matter on which the Department of +Labor was first requested, but declined to comment, the comment +.[ +Chambers methods linear models +.] +must be received by the District Director on or before the later +of June 30, 1977 or the 15th day after the day on which the +Department of Labor notifies such person +that it declines to comment, but in no event later than July 15, 1977. +A request of the Department of Labor to submit a comment must be received +by that department on or before June 10, 1977, or, if the person or persons +making the request wish to preserve their right to submit a comment to +the District Director in the event the Department of Labor declines to comment, +on or before May 30, 1977. +.[ +$LIST$ +.] diff --git a/usr/src/cmd/refer/thash.c b/usr/src/cmd/refer/thash.c new file mode 100644 index 0000000000..037800c81e --- /dev/null +++ b/usr/src/cmd/refer/thash.c @@ -0,0 +1,140 @@ +# include "stdio.h" +int nh 500; +int saw[6000]; +char *comname "/usr/lib/eign"; + +main (argc,argv) + char *argv[]; +{ + +int i, z; +char *name; + +FILE *f; + +while (argc>1 && argv[1][0] == '-') + { + switch(argv[1][1]) + { + case 'h': + nh = atoi(argv[1]+2); break; + } + argc--; argv++; + } +if (argc<=1) + dofile(stdin, ""); +else +for(i=1; i0 ? n : -n); +} diff --git a/usr/src/cmd/refer/what1.c b/usr/src/cmd/refer/what1.c new file mode 100644 index 0000000000..6fbb4c1cc9 --- /dev/null +++ b/usr/src/cmd/refer/what1.c @@ -0,0 +1,133 @@ +# include "what..c" +struct filans files[NFILES]; +char fnames[NAMES]; +int relfeed 0; +char *rb[NFEED]; +char rbb[200], *rbp rbb;; + +main(argc,argv) + char *argv[]; +{ + char *s, *t, *xargv[50], *wd[50]; + struct filans *af; + int xargc 0, nw, nf, i; +while (argc>1 && argv[1][0]=='-') + { + switch(argv[1][1]) + { + case 'r': relfeed=1; break; + } + argc--; argv++; + } +if (argc<=1) + { + printf("No query.\n"); + return(0); + } +nf = doclook(argc,argv,0); +printf(" %d files\n",nf); +if (relfeed && nf>NFEED) + { + wrdoc(NFEED, argc, argv, 1); + nw = freqwd (rb, wd, argc); + for(i=0; rb[i]; i++) + unlink(rb[i]); + } +for(i=0; ifdate != p2->fdate) + return(p2->fdate > p1->fdate); + return(p2->uid >= p1->uid); +} +wrdoc ( np, argc, argv, relfeed ) +{ + struct filans *af; + char *s, *t, buf[200]; + int eval, k, pid; + FILE *rf NULL; + FILE *ans NULL; + pid=getpid(); + for(af=files; affdate); + getpw(af->uid, s=buf); + while (*s && *s!=':') s++; + *s=0; + printf("%s (%.20s) %s, %ld bytes\n",af->nm,t+4,buf,af->size); + if (relfeed) + { + k=af-files; + _assert (knm, argc,argv, rf); + if (relfeed) + { + printf("You like that one?"); + fflush(stdout); + fgets(buf, 100, stdin); + switch(buf[0]) + { + case 'y': case 'Y': eval=1; break; + case 'n': case 'N': eval = -1; break; + default: eval=0; break; + } + fclose(rf); + if (eval<=0) + { + unlink(rb[k]); + rb[k][0]=0; + } + } + } + if (relfeed) rb[np]=0; +} +lfind( wl, n, wds) + char *wl, *wds[]; +{ + int i; +for(i=0; i0) + word[j].ct++; + } + } while (any>0); +shell ( TSIZE, wcomp, wexch ); +for(nw=0; word[nw].ct >0 && nw=nin*2 && word[nw].ct != word[0].ct) + break; +for(i=0; i0 ? k : -k); +} + +gw (f, t) + char *t; + FILE *f; +{ +int start 1, oldc ' ', c; +if (f==NULL) return (0); +while ( (c=getc(f)) != EOF) + { + if (isupper(c)) c= tolower(c); + if (start==1) + if (!alphanum(c, oldc)) + continue; + else + start=0; + if (start==0) + if (alphanum(c, oldc)) + *t++ = c; + else + { + *t=0; + return(1); + } + oldc=c; + } +return(0); +} + +alphanum( c, oldc ) +{ +if (isalpha(c) || isdigit(c)) return(1); +if (isalpha(oldc)) + if (c== '\'' || c == '-') return(1); +return(0); +} + +wcomp (n1, n2) +{ +return (word[n1].ct >= word[n2].ct); +} + +wexch (n1, n2) +{ +struct wst tt; +tt.tx = word[n1].tx; tt.ct = word[n1].ct; +word[n1].tx = word[n2].tx; word[n1].ct = word[n2].ct; +word[n2].tx = tt.tx; word[n2].ct = tt.ct; +} + +prime(n) +{ +/* only executed once- slow is ok */ +int i; +if (n%2==0) return(0); +for(i=3; i*i<=n; i+= 2) + if (n%i ==0 ) return(0); +return(1); +} +trimnl(s) + char *s; +{ + while (*s)s++; + if (*--s=='\n') *s=0; +} + + +/* this is the test for what4.c as a standalone prog ... +main (argc, argv) + char *argv[]; +{ +char *ff[10], *wd[20], **ffp ff; +int n, i; +while (--argc) + *ffp++ = *++argv; +*ffp=0; +n=freqwd(ff,wd); +for(i=0; i