Bell 32V development
authorTom London <tbl@research.uucp>
Mon, 6 Nov 1978 04:34:11 +0000 (23:34 -0500)
committerTom London <tbl@research.uucp>
Mon, 6 Nov 1978 04:34:11 +0000 (23:34 -0500)
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 <jfr@research.uucp>
Synthesized-from: 32v

32 files changed:
usr/src/cmd/refer/deliv1.c [new file with mode: 0644]
usr/src/cmd/refer/deliv2.c [new file with mode: 0644]
usr/src/cmd/refer/flagger.c [new file with mode: 0644]
usr/src/cmd/refer/glue1.c [new file with mode: 0644]
usr/src/cmd/refer/glue2.c [new file with mode: 0644]
usr/src/cmd/refer/glue3.c [new file with mode: 0644]
usr/src/cmd/refer/glue5.c [new file with mode: 0644]
usr/src/cmd/refer/hunt3.c [new file with mode: 0644]
usr/src/cmd/refer/hunt5.c [new file with mode: 0644]
usr/src/cmd/refer/hunt6.c [new file with mode: 0644]
usr/src/cmd/refer/hunt7.c [new file with mode: 0644]
usr/src/cmd/refer/hunt8.c [new file with mode: 0644]
usr/src/cmd/refer/hunt9.c [new file with mode: 0644]
usr/src/cmd/refer/inv1.c [new file with mode: 0644]
usr/src/cmd/refer/inv3.c [new file with mode: 0644]
usr/src/cmd/refer/inv5.c [new file with mode: 0644]
usr/src/cmd/refer/kaiser.c [new file with mode: 0644]
usr/src/cmd/refer/mkey1.c [new file with mode: 0644]
usr/src/cmd/refer/mkey2.c [new file with mode: 0644]
usr/src/cmd/refer/mkey3.c [new file with mode: 0644]
usr/src/cmd/refer/refer..c [new file with mode: 0644]
usr/src/cmd/refer/refer0.c [new file with mode: 0644]
usr/src/cmd/refer/refer2.c [new file with mode: 0644]
usr/src/cmd/refer/refer3.c [new file with mode: 0644]
usr/src/cmd/refer/refer6.c [new file with mode: 0644]
usr/src/cmd/refer/refer7.c [new file with mode: 0644]
usr/src/cmd/refer/refer8.c [new file with mode: 0644]
usr/src/cmd/refer/shell.c [new file with mode: 0644]
usr/src/cmd/refer/test [new file with mode: 0644]
usr/src/cmd/refer/thash.c [new file with mode: 0644]
usr/src/cmd/refer/what1.c [new file with mode: 0644]
usr/src/cmd/refer/what4.c [new file with mode: 0644]

diff --git a/usr/src/cmd/refer/deliv1.c b/usr/src/cmd/refer/deliv1.c
new file mode 100644 (file)
index 0000000..ae4a57b
--- /dev/null
@@ -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 (file)
index 0000000..2405991
--- /dev/null
@@ -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 (file)
index 0000000..435cd5a
--- /dev/null
@@ -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 (file)
index 0000000..076fbbe
--- /dev/null
@@ -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<nitem; k++)
+               {
+               strcat(grepquery, " ");
+               strcat(grepquery, qitem[k]);
+               }
+       for(fgp=fgnames; fgp<fgnamp; fgp++)
+               {
+# if D1
+               fprintf(stderr, "Now on %s query /%s/\n", *fgp, grepquery);
+# endif
+               makefgrep(*fgp);
+               grepcall(grepquery, tagout, *fgp);
+# if D1
+               fprintf(stderr, "tagout now /%s/\n", tagout);
+# endif
+               }
+       }
+restodir();
+}
+
+char *
+todir(t)
+       char *t;
+{
+       char *s;
+       s=t;
+       while (*s) s++;
+       while (s>=t && *s != '/') s--;
+       if (s<t) return(t);
+*s++ = 0;
+t = (*t ? t : "/");
+chdir (t);
+strcpy (usedir,t);
+return(s);
+}
+setfrom(c)
+{
+switch(c)
+       {
+       case 'y': case '\0':
+       default:
+               return(1000);
+       case '1':
+       case '2': case '3': case '4': case '5':
+       case '6': case '7': case '8': case '9':
+               return(c-'0');
+       case 'n': case '0':
+               return(0);
+       }
+}
diff --git a/usr/src/cmd/refer/glue2.c b/usr/src/cmd/refer/glue2.c
new file mode 100644 (file)
index 0000000..0225278
--- /dev/null
@@ -0,0 +1,11 @@
+ char refdir[50];
+savedir()
+{
+if (refdir[0]==0)
+       corout ("", refdir, "/bin/pwd", "", 50);
+trimnl(refdir);
+}
+restodir()
+{
+chdir(refdir);
+}
diff --git a/usr/src/cmd/refer/glue3.c b/usr/src/cmd/refer/glue3.c
new file mode 100644 (file)
index 0000000..8f6c171
--- /dev/null
@@ -0,0 +1,69 @@
+# include "refer..c"
+corout(in, out, rprog, arg, outlen)
+       char *in, *out, *rprog;
+{
+# define move(x, y) close(y); dup(x); close(x);
+int pipev[2], fr1, fr2, fw1, fw2, n;
+
+if (strcmp (rprog, "hunt") ==0)
+       return(callhunt(in, out, arg, outlen));
+if (strcmp (rprog, "deliv")==0)
+       return(dodeliv(in, out, arg, outlen));
+pipe (pipev); fr1= pipev[0]; fw1 = pipev[1];
+pipe (pipev); fr2= pipev[0]; fw2 = pipev[1];
+if (fork()==0)
+       {
+       close (fw1); close (fr2);
+       move (fr1, 0);
+       move (fw2, 1);
+       if (rprog[0]!= '/')
+               chdir("/usr/lib/refer");
+       execl(rprog, "deliv", arg, 0);
+       err ("Can't run %s", rprog);
+       }
+close(fw2); close(fr1);
+write (fw1, in , strlen(in));
+close(fw1);
+wait(0);
+n = read (fr2, out, outlen);
+out[n]=0;
+close(fr2);
+}
+callhunt(in, out, arg, outlen)
+       char *in, *out, *arg;
+{
+# define ALEN 50
+char *argv[20], abuff[ALEN];
+extern int typeindex;
+int argc;
+extern char one[];
+extern int onelen;
+argv[0] = "hunt";
+argv[1] = "-i";
+argv[2] = in;
+argv[3] = "-t";
+argv[4] = out;
+argv[5] = outlen;
+argv[6] = "-T";
+argv[7] = "-F1";
+argv[8] = "-o";
+argv[9] = one;
+argv[10] = onelen;
+argv[11] = abuff; strcpy (abuff,arg);
+if (strlen(abuff) > 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 (file)
index 0000000..134da95
--- /dev/null
@@ -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; q<www+MAXSIZ; q++) {
+               q->inp =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<nfound; i++)
+               if (seen[i]==x)
+                       return(0);
+       seen[i]=x;
+       return(1);
+}
diff --git a/usr/src/cmd/refer/hunt3.c b/usr/src/cmd/refer/hunt3.c
new file mode 100644 (file)
index 0000000..e89f4fb
--- /dev/null
@@ -0,0 +1,43 @@
+# include "refer..c"
+getq(v)
+       char *v[];
+{
+# define BSIZ 250
+static char buff[BSIZ];
+static int eof = 0;
+extern char *sinput;
+char *p;
+int c, n = 0, las = 0;
+if (eof) return(-1);
+p = buff;
+while ( (c = (sinput ? *sinput++ : getchar()) ) > 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<buff+BSIZ);
+if (sinput==0 && c<= 0) eof=1;
+# if D1
+fprintf(stderr, "no. keys %d\n",n);
+for(c=0; c<n; c++)
+ fprintf(stderr, "keys X%sX\n", v[c]);
+# endif
+return(n);
+}
diff --git a/usr/src/cmd/refer/hunt5.c b/usr/src/cmd/refer/hunt5.c
new file mode 100644 (file)
index 0000000..19557a5
--- /dev/null
@@ -0,0 +1,50 @@
+# include "stdio.h"
+extern char *soutput, *tagout, usedir[];
+
+result(master, nf, fc)
+       union ptr {unsigned *a; long *b;} *master;
+       FILE *fc;
+{
+int i, c;
+char *s;
+long lp;
+extern int iflong;
+char res[100];
+
+for(i=0; i<nf; i++)
+       {
+       lp = iflong ? master.b[i] : master.a[i];
+       fseek(fc,lp, 0);
+       fgets(res, 100, fc);
+       for(s=res; c = *s; s++)
+               if (c== ';')
+                       {
+                       *s=0;
+                       break;
+                       }
+       if (tagout !=0)
+               {
+               if (res[0]=='/' || usedir[0]==0)
+                       sprintf(tagout, "%s", res);
+               else
+               sprintf(tagout, "%s/%s", usedir, res);
+               while (*tagout) tagout++;
+               }
+       else
+               {
+               if (res[0]!='/' || usedir[0]==0)
+                       printf("%s/", usedir);
+               printf("%s\n", res);
+               }
+       }
+}
+
+# include "sys/types.h"
+# include "sys/stat.h"
+long gdate(f)
+       FILE *f;
+{
+struct stat sb;
+fstat (f->_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 (file)
index 0000000..589f6c3
--- /dev/null
@@ -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<nf; i++)
+       {
+       lp = iflong ? master.b[i] : master.a[i];
+# if D1
+       if (iflong)
+       fprintf(stderr, "i %d master %lo lp %lo\n", i, master.b[i], lp);
+       else
+       fprintf(stderr, "i %d master %o lp %lo\n", i, master.a[i], lp);
+# endif
+       fseek (fc, lp, 0);
+       fgets( res, 100, fc);
+# if D1
+       fprintf(stderr, "tag %s", res);
+# endif
+       if (!auxil(res,output))
+               {
+               char *s; int c;
+# if D1
+               fprintf(stderr, "not auxil try rprog %c\n", rprog? 'y': 'n');
+# endif
+               for(s=res; c= *s; s++)
+                       if (c == ';' || c == '\n')
+                               {*s=0; break;}
+               len = rprog ?
+                       corout (res, output, rprog, 0, TXTLEN) :
+                       findline (res, output, TXTLEN, indexdate);
+               }
+# if D1
+       _assert (len <TXTLEN);
+       fprintf(stderr,"item %d of %d, tag %s len %d output\n%s\n..\n",i,nf,res, len,output);
+# endif
+       if (len==0)
+               continue;
+       need = colevel ? reached : nitem;
+       na=0;
+       ar[na++] = "fgrep";
+       ar[na++] = "-r";
+       ar[na++] = "-n";
+       ar[na++] = need;
+       ar[na++] = "-i";
+       ar[na++] = output;
+       ar[na++] = len;
+       for(j=0; j<nitem; j++)
+               ar[na++] = qitem[j];
+# ifdef D1
+       fprintf(stderr, "calling fgrep len %d ar[4] %s %o %d \n",len,ar[4],ar[5],ar[6]);
+# endif
+       if (fgrep(na, ar)==0)
+               {
+# ifdef D1
+       fprintf(stderr, "fgrep found it\n");
+# endif
+               if (iflong)
+                       master.b[g++] = master.b[i];
+               else
+                       master.a[g++] = master.a[i];
+               if (full >= 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 (file)
index 0000000..6a74308
--- /dev/null
@@ -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<fgnamp; ftp++)
+                                       if (strcmp(*ftp, name)==SAME)
+                                               return(0);
+                               strcpy (*fgnamp++ = fgp, name);
+                               assert(fgnamp<fgnames+FGCT);
+                               while (*fgp && *fgp!=':')
+                                       fgp++;
+                               *fgp++ = 0;
+                               assert (fgp<fgspace+FGSIZE);
+                               return(0);
+                               }
+                       fprintf(stderr, "Warning: index predates file '%s'\n", name);
+                       }
+               }
+# if D1
+       else
+               fprintf(stderr, "old %s new %s same fa %o\n", name,in,fa);
+# endif
+       if (fa != NULL)
+               {
+               fseek (fa, lp, 0);
+               len = (llen >= 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 (file)
index 0000000..c9e9e51
--- /dev/null
@@ -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 (file)
index 0000000..73b615f
--- /dev/null
@@ -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 (file)
index 0000000..a253420
--- /dev/null
@@ -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 (file)
index 0000000..0448f4e
--- /dev/null
@@ -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 (file)
index 0000000..7aa5886
--- /dev/null
@@ -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<n; i++)
+       {
+       if (iflong)
+               lp = hpt_l[i];
+       else
+               lp = hpt_s[i];
+       fseek(fb, lp, 0);
+       while ( (k= (*getfun)(fb) ) != -1)
+               fprintf(ft, "%04d %06ld\n",i,k);
+       }
+fclose(fb);
+return(n);
+}
diff --git a/usr/src/cmd/refer/kaiser.c b/usr/src/cmd/refer/kaiser.c
new file mode 100644 (file)
index 0000000..cd1ddfb
--- /dev/null
@@ -0,0 +1,274 @@
+# include "stdio.h"
+# include "ctype.h"
+char *months[] {"Jan", "Feb", "Mar", "Apr", "May",
+       "Jun", "Jul", "Aug", "Sep","Oct", "Nov", "Dec",0};
+main()
+{
+int state 1000, i, book, volume, corp, report;
+int na;
+char *v[20], **vv, **rr;
+char ubuff[1000], *up;
+char line[100];
+char *p, *s, *r, *q;
+while (gets(line))
+       {
+       if (line[1]>'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;i<na;i++)
+                               if (strcmp(v[i], "(Book)")==0)
+                                       book=1;
+                       continue;
+               case 'A':
+                       state = 'A';
+                       na=getargs(line+18, vv=v);
+                       if (na<=0) continue;
+                       while (na>0)
+                               {
+                               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 (file)
index 0000000..8fd266f
--- /dev/null
@@ -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; i<argc; i++)
+       {
+       f = fopen(name=argv[i], "r");
+       if (f==NULL)
+               err("No file %s",name);
+       else
+               dofile(f, name);
+       }
+exit(0);
+}
diff --git a/usr/src/cmd/refer/mkey2.c b/usr/src/cmd/refer/mkey2.c
new file mode 100644 (file)
index 0000000..94949b1
--- /dev/null
@@ -0,0 +1,137 @@
+# include "stdio.h"
+# include "ctype.h"
+
+       static int eof = 0;
+       static long lp, lim;
+       static int alph, used, prevc;
+       static char *p, key[20];
+
+dofile(f, name)
+       FILE *f;
+       char *name;
+{
+
+/* read file f & spit out keys & ptrs */
+# define MAXLINE 500
+char line[MAXLINE], *s;
+extern int minlen, keycount, labels;
+int c;
+long grec();
+extern int wholefile;
+extern char *iglist;
+alph=used=prevc=eof=0;
+
+lp=0;
+if (wholefile==0)
+while (lim = grec(line,f))
+       {
+# if D1
+fprintf(stderr, "line: /%s",line);
+# endif
+       used=alph=0;
+       p = key;
+       for(s=line; (c= *s) && (used<keycount); s++)
+               chkey(c, name);
+       lp += lim;
+       if (used) putchar('\n');
+       }
+else
+       {
+       p=key;
+       used=alph=0;
+       while ( (c=getc(f)) != EOF && used<keycount)
+               chkey (c, name);
+       if (used) putchar('\n');
+       }
+fclose(f);
+}
+
+outkey( ky, lead, trail)
+       char *ky;
+{
+       int n;
+n = strlen(ky);
+if (n<minlen) return (0);
+if (n<3)
+       {
+       if (trail == '.') return(0);
+       if (mindex(".%,!#$%&'();+:*", lead)!=0) return(0);
+       }
+if (isdigit(ky[0]))
+       if (ky[0] != '1' || ky[1] != '9' || n!= 4) return(0);
+if (common(ky))
+       return(0);
+return(1);
+}
+long grec (s, f)
+       char *s;
+       FILE *f;
+{
+       char tm[200];
+       int curtype = 0;
+       long len = 0L, tlen = 0L;
+       extern int wholefile;
+       if (eof) return(0);
+       *s = 0;
+       while (fgets(tm, 200, f))
+               {
+               tlen += strlen(tm);
+               if (tm[0] == '%' || tm[0] == '.')
+                       curtype = tm[1];
+               if (tlen < MAXLINE && mindex(iglist,curtype)==0)
+                               strcat(s, tm);
+               len = tlen;
+               if (wholefile==0 && tm[0] == '\n')
+                       return(len);
+               if (wholefile>0 && 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 (file)
index 0000000..0787400
--- /dev/null
@@ -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; i<comcount; i++)
+       {
+       if (fgets(cbp, 15, f)==NULL)
+               break;
+       trimnl(cbp);
+       c_look (cbp, 0);
+       while (*cbp++);
+       }
+fclose(f);
+}
+c_look (s, fl)
+       char *s;
+{
+int h;
+h = hash(s) % (COMTSIZE);
+while (cwds[h] != 0)
+       {
+       if (strcmp(s, cwds[h])==0)
+               return(1);
+       h = (h+1) % (COMTSIZE);
+       }
+if (fl==0)
+       cwds[h] = s;
+return(0);
+}
diff --git a/usr/src/cmd/refer/refer..c b/usr/src/cmd/refer/refer..c
new file mode 100644 (file)
index 0000000..d5cd565
--- /dev/null
@@ -0,0 +1,34 @@
+# include "stdio.h"
+# include "ctype.h"
+# include "assert.h"
+extern FILE *in;
+extern int endpush, labels, sort, bare, keywant;
+extern char *smallcaps;
+extern char comname;
+extern char *keystr;
+extern int authrev;
+extern int nmlen, dtlen;
+extern char *rdata[], **search;
+extern int refnum;
+extern char *reftable[];
+extern char *rtp, reftext[];
+extern int sep;
+extern char tfile[];
+extern char gfile[];
+extern char ofile[];
+extern char hidenam[];
+extern char *Ifile; extern int Iline;
+extern FILE *fo, *ftemp;
+extern char *input(),*lookat();
+extern char *class(),*caps(),*revauth();
+extern char *artskp(),*fpar();
+extern char *trimnl();
+# define FLAG 003
+# define NRFTXT 2000
+# define NTFILE 20
+# define NRFTBL 200
+# define LLINE 512
+# define QLEN 300
+# define ANSLEN 1000
+# define TAGLEN 400
+# define NSERCH 20
diff --git a/usr/src/cmd/refer/refer0.c b/usr/src/cmd/refer/refer0.c
new file mode 100644 (file)
index 0000000..caaa6a8
--- /dev/null
@@ -0,0 +1,27 @@
+# include "stdio.h"
+# include "refer..c"
+FILE *in = stdin;
+int endpush = 0;
+int labels = 0;
+int keywant = 0;
+int sort = 0;
+int bare = 0;
+int authrev = 0;
+char *smallcaps = "";
+char *keystr = "AD";
+int nmlen = 0, dtlen = 0;
+char *rdata[NSERCH];
+char **search = rdata;
+int refnum = 0;
+char reftext[NRFTXT];
+char *reftable[NRFTBL];
+char *rtp = reftext;
+int sep = '\n';
+char tfile[NTFILE];
+FILE *fo = stdout;
+FILE *ftemp = stdout;
+char ofile[NTFILE];
+char gfile[NTFILE];
+char hidenam[NTFILE];
+char *Ifile = "standard input";
+int Iline = 0;
diff --git a/usr/src/cmd/refer/refer2.c b/usr/src/cmd/refer/refer2.c
new file mode 100644 (file)
index 0000000..ccec3da
--- /dev/null
@@ -0,0 +1,203 @@
+# include "refer..c"
+extern FILE *in;
+# define NFLD 30
+# define TLEN 400
+char one[ANSLEN];
+int onelen = ANSLEN;
+static char dr [100] = "";
+doref(firline)
+       char *firline;
+{
+char buff[QLEN], dbuff[3*QLEN], answer[ANSLEN], temp[TLEN];
+char line[LLINE];
+char *p, **sr, *flds[NFLD], *r;
+int nf, nr, alph, query = 0, chp, digs;
+
+/* get query */
+buff[0] = dbuff[0] = 0;
+while (input(line))
+       {
+       if (prefix(".]", line))
+               break;
+       if (control(line[0])) query=1;
+       strcat (query  ? dbuff: buff, line);
+       if (strlen(buff)>QLEN)
+               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 (r<p)
+                                       *r++ = ' ';
+                               }
+                       }
+               *p=' ';
+               alph = digs = 0;
+               }
+       }
+# ifdef D1
+       fprintf(stderr, "query translated to %s\n", buff);
+# endif
+one[0]=0;
+if (buff[0]) /* do not search if no query */
+for( sr= rdata; sr < search; sr++)
+       {
+# ifdef D1
+       fprintf(stderr, "now searching %s\n", *sr);
+# endif
+       temp[0]=0;
+       corout (buff, temp, "hunt", *sr, TLEN);
+       assert (strlen(temp)<TLEN);
+       if (strlen(temp)+strlen(answer)>LLINE)
+               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)<ANSLEN);
+assert (strlen(answer)<ANSLEN);
+if (buff[0])
+switch (newline(answer))
+       {
+       case 0:
+               fprintf (stderr, "No such paper %s\n", buff);
+               return;
+       default:
+               fprintf(stderr, "too many hits for '%s'\n", trimnl(buff));
+               choices(answer);
+               p = buff;
+               while (*p != '\n') p++;
+               *++p=0;
+       case 1:
+# ifdef D1
+       fprintf(stderr, "found one\n");
+# endif
+               if (endpush)
+                       if (nr = chkdup(answer))
+                               {
+                               if (bare<2)
+                                       putsig (0, flds, nr, firline, line);
+                               return;
+                               }
+# if D1
+               fprintf(stderr, "one[0] was %o\n",one[0]);
+# endif
+               if (one[0]==0)
+                       corout (answer, one, "deliv", dr, QLEN);
+# if D1
+               fprintf(stderr, "one now %o\n",one[0]);
+# endif
+               break;
+       }
+assert (strlen(buff)<QLEN);
+assert (strlen(one)<ANSLEN);
+nf = tabs(flds, one);
+nf += tabs(flds+nf, dbuff);
+# if D1
+fprintf(stderr, "one %.20s dbuff %.20s nf %d\n",one,dbuff, nf);
+# endif
+assert (nf < NFLD);
+refnum++;
+if (sort) putkey (nf, flds, refnum, keystr);
+if (bare<2)
+       putsig (nf, flds, refnum, firline, line);
+else
+       flout();
+# if D1
+fprintf(stderr, "put signal\n");
+# endif
+putref (nf, flds);
+# if D1
+fprintf(stderr, "put ref\n");
+# endif
+}
+newline(s)
+       char *s;
+{
+int k = 0, c;
+while (c = *s++)
+       if (c == '\n')
+               k++;
+return(k);
+}
+choices( buff )
+       char *buff;
+{
+char ob[LLINE], *p, *r, *q, *t;
+int nl;
+for(r=p= buff; *p; p++)
+       {
+       if (*p == '\n')
+               {
+               *p++ = 0;
+                       {
+                       corout (r, ob, "deliv", dr, LLINE);
+                       nl = 1;
+                       for( q=ob; *q; q++)
+                               {
+                               if (nl && (q[0] == '.' || q[0] == '%') && q[1] == 'T')
+                                       {
+                                       q += 3;
+                                       for (t=q; *t && *t != '\n'; t++);
+                                       *t = 0;
+                                       fprintf(stderr, "%.70s\n", q);
+                                       q=0; break;
+                                       }
+                               nl = *q == '\n';
+                               }
+                       if (q)
+                               fprintf(stderr, "??? at %s\n",r);
+                       }
+               r=p;
+               }
+       }
+}
+
+control(c)
+       {
+       if (c=='.') return(1);
+       if (c=='%') return(1);
+       return(0);
+       }
diff --git a/usr/src/cmd/refer/refer3.c b/usr/src/cmd/refer/refer3.c
new file mode 100644 (file)
index 0000000..ca95793
--- /dev/null
@@ -0,0 +1,26 @@
+# include "refer..c"
+corout(in, out, rprog, arg, outlen)
+       char *in, *out, *rprog;
+{
+# define move(x, y) close(y); dup(x); close(x);
+int pipev[2], fr1, fr2, fw1, fw2, n;
+
+pipe (pipev); fr1= pipev[0]; fw1 = pipev[1];
+pipe (pipev); fr2= pipev[0]; fw2 = pipev[1];
+if (fork()==0)
+       {
+       close (fw1); close (fr2);
+       move (fr1, 0);
+       move (fw2, 1);
+       execl(rprog, "deliv", arg, 0);
+       err ("Can't run %s", rprog);
+       }
+close(fw2); close(fr1);
+write (fw1, in , strlen(in));
+close(fw1);
+wait(0);
+n = read (fr2, out, outlen);
+out[n]=0;
+close(fr2);
+return(n);
+}
diff --git a/usr/src/cmd/refer/refer6.c b/usr/src/cmd/refer/refer6.c
new file mode 100644 (file)
index 0000000..56340ef
--- /dev/null
@@ -0,0 +1,224 @@
+# include "refer..c"
+putref (n, tvec)
+       char *tvec[];
+{
+char *s, *tx;
+char buf1[LLINE], buf2[50];
+int nauth = 0, i, lastype = 0, cch, macro = 0, la;
+int lauth = 0, ltitle = 0;
+
+fprintf(fo, ".]-%c", sep);
+# define dsde (macro? "de" : "ds")
+# define ifnl (macro? sep : ' ')
+for (i=0; i<n; i++)
+       {
+       s = tvec[i];
+       if (*s==0) continue;
+       if (control(s[0]) )
+               {
+               if (lastype && macro)
+                       fprintf(fo, "..%c", sep);
+               if (control(s[1]))
+                       {
+                       cch = s[2];
+                       tx = s+3;
+                       macro=1;
+                       }
+               else
+                       {
+                       cch = s[1];
+                       tx = s+2;
+                       macro=0;
+                       }
+               }
+       else
+               {
+               cch = lastype;
+               tx=s;
+               }
+# if D1
+fprintf(stderr, "smallcaps %s cch %c\n",smallcaps, cch);
+# endif
+       if (mindex (smallcaps, cch))
+               tx = caps(tx, buf1);
+# if D1
+fprintf(stderr, " s %o tx %o %s\n",s,tx,tx);
+# endif
+       if (!control(s[0])) /* append to previous item */
+               {
+               if (lastype!=0)
+                       {
+                       if (macro)
+                               fprintf(fo, "%s%c", tx, sep);
+                       else
+                               fprintf(fo, ".as [%c \" %s%c",lastype,tx,sep);
+                       if (lastype == 'T')
+                               ltitle = (mindex(".;,?", last(tx))!=0);
+                       if (lastype == 'A')
+                               lauth = last(tx) == '.';
+                       }
+               continue;
+               }
+       if (mindex("XYZ[]", cch)) /* skip these */
+               {
+               lastype=0;
+               continue;
+               }
+       else
+       if (cch == 'A')
+               {
+               if (nauth < authrev)
+                       tx = revauth(tx, buf2);
+               if (nauth++ ==0)
+                       if (macro)
+                               fprintf(fo, ".de [%c%c%s%c",cch,sep,tx,sep);
+                       else
+                               fprintf(fo, ".ds [%c%s%c", cch,tx,sep);
+               else
+                       {
+                       la = (tvec[i+1][1]!='A');
+                       fprintf(fo, ".as [A \"");
+                       if (la == 0 || nauth != 2)
+                               fprintf(fo, ",");
+                       if (la)
+                       fprintf(fo,"%s", 
+                               mindex(smallcaps, 'A')? " \\s-2AND\\s+2" : " and");
+                       fprintf(fo, "%s%c", tx, sep);
+                       }
+               lauth = last(tx)=='.';
+               }
+       else
+               if (macro)
+                       fprintf(fo, ".de [%c%c%s%c",cch,sep, tx, sep);
+               else
+                       fprintf(fo, ".ds [%c%s%c",cch,tx, sep);
+       if (cch=='P')
+               fprintf(fo, ".nr [P %d%c", mindex(s, '-')!=0, sep);
+       lastype = cch;
+       if (cch == 'T')
+               ltitle = (mindex(".;,?", last(tx)) != 0);
+       }
+if (lastype && macro)
+       fprintf(fo, "..%c", sep);
+fprintf(fo, ".nr [T %d%c", ltitle, sep);
+fprintf(fo, ".nr [A %d%c", lauth, sep);
+fprintf (fo, ".][ %s%c", class(n, tvec), '\n');
+}
+tabs (sv, line)
+       char *sv[], *line;
+{
+char *p;
+int n = 0;
+sv[n++] = line;
+for( p= line; *p; p++)
+       {
+       if (*p == '\n')
+               {
+               *p=0;
+               sv[n++] = p+1;
+               }
+       }
+return(n-1);
+}
+char *
+class (nt, tv)
+       char *tv[];
+{
+if (hastype (nt, tv, 'J'))
+       return("1 journal-article");
+if (hastype (nt, tv, 'B'))
+       return("3 article-in-book");
+if (hastype (nt, tv, 'R'))
+       return ("4 tech-report");
+if (hastype (nt, tv, 'G'))
+       return ("4 tech-report");
+if (hastype (nt, tv, 'I'))
+       return("2 book");
+if (hastype (nt, tv,'M'))
+       return ("5 bell-tm");
+return("0 other");
+}
+hastype (nt, tv, c)
+       char *tv[];
+{
+int i;
+for(i=0; i<nt; i++)
+       if ( control(tv[i][0]) && tv[i][1]==c )
+               return(1);
+return(0);
+}
+char *
+caps(a, b)
+       char *a, *b;
+{
+char *p;
+int c, alph, this;
+p=b;
+alph = 0;
+while (c = *a++)
+       {
+       this = isalpha(c);
+       if (this && alph==1)
+               {
+               *b++ = '\\';
+               *b++ = 's';
+               *b++ = '-';
+               *b++ = '2';
+               }
+       if (!this && alph>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<jr)
+       *b++ = *p++;
+*b++ = ',';
+while (init<name)
+       *b++ = *init++;
+if (*jr)jr++;
+while(*jr)
+       *b++ = *jr++;
+*b++ = 0;
+return(bcop);
+}
+last(s)
+       char *s;
+{
+while (*s) s++;
+return(*--s);
+}
diff --git a/usr/src/cmd/refer/refer7.c b/usr/src/cmd/refer/refer7.c
new file mode 100644 (file)
index 0000000..af8e05c
--- /dev/null
@@ -0,0 +1,99 @@
+# include "refer..c"
+int newr[250];
+chkdup ( tag )
+       char *tag;
+{
+int i;
+for(i=1; i<=refnum; i++)
+       {
+       if (strcmp(reftable[i], tag)==0)
+               return(i);
+       }
+reftable[refnum+1] = rtp;
+if (refnum>=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 (file)
index 0000000..6ea018a
--- /dev/null
@@ -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 (file)
index 0000000..ed18064
--- /dev/null
@@ -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; i<imax; i++)
+                       {
+                       iplusg = i + igap;
+                       if ((*comp) (i, iplusg) ) continue;
+                       (*exch) (i, iplusg);
+                       iex=1;
+                       }
+               } while (iex>0);
+       }
+}
diff --git a/usr/src/cmd/refer/test b/usr/src/cmd/refer/test
new file mode 100644 (file)
index 0000000..74a0e11
--- /dev/null
@@ -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 (file)
index 0000000..037800c
--- /dev/null
@@ -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; i<argc; i++)
+       {
+       f = fopen(name=argv[i], "r");
+       if (f==NULL)
+               err("No file %s",name);
+       else
+               dofile(f, name);
+       }
+for(z=i=0; i<nh; i++)
+       {
+       if (saw[i]) z++;
+       }
+printf("hashes %d used %d\n",nh,z);
+}
+# include "stdio.h"
+
+dofile(f, name)
+       FILE *f;
+       char *name;
+{
+
+/* read file f & spit out keys & ptrs */
+# define MAXLINE 750
+char line[MAXLINE], *s;
+char key[20], *p;
+int k 0;
+int c, lim;
+int alph 0;
+int used 0;
+long lp 0;
+
+while (fgets(line, MAXLINE, f))
+       {
+       k++;
+       used=alph=0;
+       lim = strlen(line);
+       p = key;
+       for(s=line; c= *s; s++)
+               {
+               if (isalpha(c) || isdigit(c))
+                       {
+                       if (alph++ < 6)
+                               *p++ = c;
+                       }
+               else
+                       {
+                       *p = 0;
+                       if (outkey(p=key))
+                               {
+                               tkey(key,k);
+                               used=1;
+                               }
+                       alph=0;
+                       }
+               }
+       lp += lim;
+       }
+}
+
+outkey( ky)
+       char *ky;
+{
+       int n;
+n = strlen(ky);
+if (n<3) return(0);
+if (isdigit(ky[0]))
+       if (ky[0] != '1' || ky[1] != '9' || n!= 4) return(0);
+return(1);
+}
+# include "stdio.h"
+hash (s)
+       char *s;
+{
+int c, n, q;
+for(q=n=0; c= *s; s++)
+       n += (c*n + c << (n%4));
+return(n);
+}
+err (s, a)
+       char *s;
+{
+fprintf(stderr, "Error: ");
+fprintf(stderr, s, a);
+putc('\n', stderr);
+}
+prefix(t, s)
+       char *t, *s;
+{
+int c, d;
+while ( (c= *t++) == *s++)
+       if (c==0) return(1);
+return(c==0 ? 1: 0);
+}
+mindex(s, c)
+       char *s;
+{
+register char *p;
+for( p=s; *p; p++)
+       if (*p ==c)
+               return(p);
+return(0);
+}
+tkey(s,nw)
+       char *s;
+{
+int x;
+x = abs(hash(s)) % nh;
+/* if (saw[x]) printf("%d %d\n", x, nw); */
+saw[x]= nw;
+}
+abs(n)
+{
+return(n>0 ? n : -n);
+}
diff --git a/usr/src/cmd/refer/what1.c b/usr/src/cmd/refer/what1.c
new file mode 100644 (file)
index 0000000..6fbb4c1
--- /dev/null
@@ -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; i<argc; i++)
+       xargv[xargc++]=argv[i];
+if (relfeed)
+       {
+       printf("Adding: ");
+       for(i=0; i<nw; i++)
+               if (!lfind(wd[i], xargc, xargv))
+                       printf("%s ", xargv[xargc++]=wd[i]);
+       printf("\n");
+       nf = doclook(xargc, xargv, relfeed? xargc/4 : 0);
+       printf("  %d files\n",nf);
+       }
+shell (nf, comp, exch);
+wrdoc(nf, xargc, xargv, 0);
+return(0);
+}
+exch( i1, i2 )
+{
+       struct filans *p1, *p2;
+       struct filans xt;
+       p1=files+i1;
+       p2=files+i2;
+       xt = *p1;
+       *p1 = *p2;
+       *p2 = xt;
+}
+comp(i1, i2)
+{
+       struct filans *p1, *p2;
+       p1 = files+i1;
+       p2= files+i2;
+       if (p1->fdate != 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; af<files+np; af++)
+               {
+               t = ctime(&af->fdate);
+               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 (k<NFEED);
+                       sprintf(rb[k]=rbp, "rf%d.%d",pid, k);
+                       rf = fopen(rb[k], "w");
+                       while (*rbp++);
+                       }
+               describe(af->nm, 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; i<n; i++)
+       if (str6cmp(wl, wds[i])==0)
+               return(1);
+return(0);
+}
+str6cmp(s, t)
+       char *s, *t;
+{
+int i 0, c;
+while ( (c= *s++ ) == ( *t++))
+       if (c==0 || ++i ==6)
+               return(0);
+return(1);
+}
diff --git a/usr/src/cmd/refer/what4.c b/usr/src/cmd/refer/what4.c
new file mode 100644 (file)
index 0000000..e9a2bd3
--- /dev/null
@@ -0,0 +1,163 @@
+# include "what..c"
+struct wst { char *tx; int ct; } ;
+# define NW 5
+# define ZIPF 10
+# define HASHF 3
+# define WLEN 10
+# define SAME 0
+# define TSIZE HASHF*ZIPF*NW
+int HSIZE;
+static struct wst word[TSIZE];
+static char tbuf[NW*ZIPF*WLEN], *tp tbuf;
+# define NF 10
+
+freqwd ( fn, wd, nin )
+       char *fn[], *wd[];
+{
+       FILE *fi[NF];
+       int nw 0, i, any, nf, j, wexch(), wcomp();
+       char tw[20];
+for(HSIZE=TSIZE; !prime(HSIZE); HSIZE--);
+for(nf=0; fn[nf] && nf<NF; nf++)
+       fi[nf] = fn[nf][0] ? fopen(fn[nf], "r") : NULL;
+do {
+       any=0;
+       for(i=0; i<nf; i++)
+               {
+               if (fi[i]==NULL) continue;
+               if (gw(fi[i], tw)==0)
+                       {
+                       fclose(fi[i]);
+                       fi[i]==NULL;
+                       continue;
+                       }
+               any=1;
+               if (common(tw)) continue;
+               if (strlen(tw)<3) continue;
+               j = lookup (tw);
+               if (j<0 && nw < ZIPF*NW)
+                       {
+                       j = -j;
+                       strcpy (tp, tw);
+                       word[j].tx = tp;
+                       while (*tp++);
+                       _assert (tp < tbuf+NW*ZIPF*WLEN);
+                       word[j].ct = 1;
+                       nw++;
+                       }
+               else if (j>0)
+                       word[j].ct++;
+               }
+       } while (any>0);
+shell ( TSIZE, wcomp, wexch );
+for(nw=0; word[nw].ct >0 && nw<TSIZE; nw++)
+       if (nw>=nin*2 && word[nw].ct != word[0].ct)
+               break;
+for(i=0; i<nw; i++)
+       wd[i] = word[i].tx;
+return(nw);
+}
+
+lookup (wt)
+       char *wt;
+{
+int h;
+h = hash(wt);
+for( h = h%HSIZE; word[h].tx; h = (h+1)%HSIZE)
+       {
+       if (h==0) continue;
+       if (strcmp(wt, word[h].tx) == SAME)
+               return (h);
+       }
+return ( -h );
+}
+
+hash (s)
+       char *s;
+{
+int k 0, c 0, i 0;
+while ( c = *s++ )
+       k ^= (c << (i++%5) );
+return (k>0 ? 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<n; i++)
+ printf("%s\n",wd[i]);
+printf("total of %d items\n",n);
+}
+ /* .... */