# # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License, Version 1.0 only # (the "License"). You may not use this file except in compliance # with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2005 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # Copyright (c) 2018, Joyent, Inc. include ../Makefile.cmd PROG1 = refer addbib lookbib sortbib PROG2 = roffbib indxbib PROG3 = mkey inv hunt PROG = $(PROG1) $(PROG2) OBJS = addbib.o deliv2.o glue1.o glue2.o glue3.o glue4.o \ glue5.o hunt1.o hunt2.o hunt3.o hunt5.o hunt6.o \ hunt7.o hunt8.o inv1.o inv2.o inv3.o \ inv5.o inv6.o lookbib.o mkey1.o mkey2.o mkey3.o \ refer..o refer0.o refer1.o refer2.o refer3.o refer4.o \ refer5.o refer6.o refer7.o refer8.o shell.o sortbib.o \ tick.o types.o # # for messaging catalog # POFILES= $(OBJS:%.o=%.po) POFILE= refer.po CERRWARN += -Wno-implicit-function-declaration CERRWARN += -Wno-parentheses CERRWARN += -Wno-unused-variable CERRWARN += $(CNOWARN_UNINIT) # Hammerhead: Suppress pointer/int cast warnings in legacy refer code CERRWARN += -Wno-pointer-to-int-cast CERRWARN += -Wno-int-to-pointer-cast CERRWARN += -Wno-cast-function-type # not linted SMATCH=off CLOBBERFILES += $(PROG3) addbib.po : XGETFLAGS += -a -x addbib.xcl OTXTS = tmac.bib REFDIR = $(ROOTLIB)/refer TMACDIR = $(ROOTSHLIB)/tmac #Don't re-install dir already installed by Targetdirs #ROOTDIRS = $(REFDIR) $(TMACDIR) ROOTDIRS = $(REFDIR) SUBDIRS = papers REFDIRPROG = $(PROG3:%=$(REFDIR)/%) IOTXTS = $(OTXTS:%=$(TMACDIR)/%) $(IOTXTS): FILEMODE = 0644 all: TARGET= all install: TARGET= install clean: TARGET= clean clobber: TARGET= clobber mkey: POBJS= mkey1.o mkey2.o mkey3.o deliv2.o inv: POBJS= inv1.o inv2.o inv3.o inv5.o inv6.o deliv2.o hunt: POBJS= hunt1.o hunt2.o hunt3.o hunt5.o hunt6.o \ hunt7.o glue5.o refer3.o shell.o \ deliv2.o hunt8.o glue4.o tick.o refer: POBJS= glue1.o refer1.o refer2.o refer4.o refer5.o \ refer6.o mkey3.o refer7.o refer8.o hunt2.o \ hunt3.o deliv2.o hunt5.o hunt6.o hunt8.o \ glue3.o hunt7.o glue2.o glue4.o \ glue5.o refer0.o shell.o addbib: POBJS= addbib.o lookbib: POBJS= lookbib.o sortbib: POBJS= sortbib.o .KEEP_STATE : .PARALLEL: $(OBJS) all: $(PROG) $(PROG3) $(OTXTS) $(PROG1) $(PROG3): $$(POBJS) $(LINK.c) -o $@ $(POBJS) $(LDFLAGS) $(LDLIBS) $(POST_PROCESS) $(POFILE): $(POFILES) $(RM) $@ cat $(POFILES) > $@ types.po: touch types.po install: all .WAIT $(ROOTDIRS) \ $(ROOTPROG) $(REFDIRPROG) $(IOTXTS) $(SUBDIRS) $(REFDIR)/% : % $(INS.file) $(TMACDIR)/% : % $(INS.file) clean : $(SUBDIRS) $(RM) $(OBJS) clobber : $(SUBDIRS) local_clobber lint: $(LINT.c) mkey1.c mkey2.c mkey3.c deliv2.c $(LDLIBS) $(LINT.c) inv1.c inv2.c inv3.c inv5.c inv6.c deliv2.c $(LDLIBS) $(LINT.c) hunt1.c hunt2.c hunt3.c hunt5.c hunt6.c \ hunt7.c glue5.c refer3.c shell.c \ deliv2.c hunt8.c glue4.c tick.c $(LDLIBS) $(LINT.c) glue1.c refer1.c refer2.c refer4.c refer5.c \ refer6.c mkey3.c refer7.c refer8.c hunt2.c \ hunt3.c deliv2.c hunt5.c hunt6.c hunt8.c \ glue3.c hunt7.c glue2.c glue4.c \ glue5.c refer0.c shell.c $(LDLIBS) $(LINT.c) addbib.c $(LDLIBS) $(LINT.c) lookbib.c $(LDLIBS) $(LINT.c) sortbib.c $(LDLIBS) local_clobber: $(RM) $(PROG) $(OBJS) $(CLOBBERFILES) strip: $(SUBDIRS): FRC @cd $@; pwd; $(MAKE) $(TARGET) $(ROOTDIRS) : $(INS.dir) FRC: include ../Makefile.targ Copyright (c) 1980 Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. All advertising materials mentioning features or use of this software must display the following acknowledgement: This product includes software developed by the University of California, Berkeley and its contributors. 4. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. PORTIONS OF REFER COMMAND FUNCTIONALITY /* * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1980 Regents of the University of California. * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. */ #include #include #include #include #define MAXENT 50 struct skeleton { char prompt[20]; /* prompt user for entry */ char keylet[5]; /* key letter for database */ } bibskel[MAXENT] = { " Author:", "%A", " Title:", "%T", " Journal:", "%J", " Volume:", "%V", " Pages:", "%P", "Publisher:", "%I", " City:", "%C", " Date:", "%D", " Other:", "%O", " Keywords:", "%K", }; int entries = 10; /* total number of entries in bibskel */ int abstract = 1; /* asking for abstracts is the default */ static void addbib(FILE *, char *); void bibedit(FILE *, char *, char *); static void instruct(void); static void rd_skel(char *); static void trim(char []); static void usage(void) /* print proper usage and exit */ { puts(gettext("Usage: addbib [-p promptfile] [-a] database\n\ \t-p: the promptfile defines alternate fields\n\ \t-a: don't include prompting for the abstract\n")); exit(1); } int main(int argc, char *argv[]) /* addbib: bibliography entry program */ { FILE *fp, *fopen(); int i; (void) setlocale(LC_ALL, ""); #if !defined(TEXT_DOMAIN) #define TEXT_DOMAIN "SYS_TEST" #endif (void) textdomain(TEXT_DOMAIN); if (argc == 1) { puts(gettext( "You must specify a bibliography file (database).")); usage(); } for (i = 1; argv[i][0] == '-'; i++) { if (argv[i][1] == 'p') { if (i >= argc - 2) { puts(gettext("Not enough arguments for " "-p option.")); usage(); } rd_skel(argv[++i]); } else if (argv[i][1] == 'a') { if (i >= argc - 1) { puts(gettext( "No bibliofile specified after -a.")); usage(); } abstract = 0; } else { /* neither -p nor -a */ printf(gettext( "Invalid command line flag: %s\n"), argv[i]); usage(); } } if (i < argc - 1) { puts(gettext("Too many arguments with no options.")); usage(); } if ((fp = fopen(argv[i], "a")) == NULL) { perror(argv[i]); exit(1); } addbib(fp, argv[i]); /* loop for input */ return (0); } static void addbib(FILE *fp, char *argv) /* add entries to a bibliographic database */ { char line[BUFSIZ]; int i = 0, firstln, repeat = 0, escape = 0; printf(gettext("Instructions? ")); fgets(line, BUFSIZ, stdin); if (line[0] == 'y' || line[0] == 'Y') instruct(); while (1) { putchar('\n'); putc('\n', fp); for (i = 0; i < entries; i++) { printf("%s\t", gettext(bibskel[i].prompt)); if (fgets(line, BUFSIZ, stdin) == NULL) { clearerr(stdin); break; } if (line[0] == '-' && line[1] == '\n') { i -= 2; if (i < -1) { printf(gettext("Too far back.\n")); i++; } continue; } else if (line[strlen(line)-2] == '\\') { if (line[0] != '\\') { line[strlen(line)-2] = '\n'; line[strlen(line)-1] = '\0'; trim(line); fprintf(fp, "%s %s", bibskel[i].keylet, line); } printf("> "); again: fgets(line, BUFSIZ, stdin); if (line[strlen(line)-2] == '\\') { line[strlen(line)-2] = '\n'; line[strlen(line)-1] = '\0'; trim(line); fputs(line, fp); printf("> "); goto again; } trim(line); fputs(line, fp); } else if (line[0] != '\n') { trim(line); fprintf(fp, "%s %s", bibskel[i].keylet, line); } } if (abstract) { puts(gettext(" Abstract: (ctrl-d to end)")); firstln = 1; while (fgets(line, BUFSIZ, stdin)) { if (firstln && line[0] != '%') { fprintf(fp, "%%X "); firstln = 0; } fputs(line, fp); } clearerr(stdin); } fflush(fp); /* write to file at end of each cycle */ if (ferror(fp)) { perror(argv); exit(1); } editloop: printf(gettext("\nContinue? ")); fgets(line, BUFSIZ, stdin); if (line[0] == 'e' || line[0] == 'v') { bibedit(fp, line, argv); goto editloop; } if (line[0] == 'q' || line[0] == 'n') return; } } static void trim(char line[]) /* trim line of trailing white space */ { int n; n = strlen(line); while (--n >= 0) { if (!isspace(line[n])) break; } line[++n] = '\n'; line[++n] = '\0'; } void bibedit(FILE *fp, char *cmd, char *arg) /* edit database with edit, ex, or vi */ { int i = 0, status; fclose(fp); while (!isspace(cmd[i])) i++; cmd[i] = '\0'; if (fork() == 0) { if (cmd[0] == 'v' && cmd[1] == 'i') execlp(cmd, cmd, "+$", arg, NULL); else /* either ed, ex, or edit */ execlp(cmd, cmd, arg, NULL); } signal(SIGINT, SIG_IGN); signal(SIGQUIT, SIG_IGN); wait(&status); signal(SIGINT, SIG_DFL); signal(SIGQUIT, SIG_DFL); if ((fp = fopen(arg, "a")) == NULL) { perror(arg); exit(1); } } static void instruct(void) /* give user elementary directions */ { putchar('\n'); puts(gettext( "Addbib will prompt you for various bibliographic fields.\n" "If you don't need a particular field, just hit RETURN,\n" "\tand that field will not appear in the output file.\n" "If you want to return to previous fields in the skeleton,\n" "\ta single minus sign will go back a field at a time.\n" "\t(This is the best way to input multiple authors.)\n" "If you have to continue a field or add an unusual field,\n" "\ta trailing backslash will allow a temporary escape.\n" "Finally, (without -a) you will be prompted for an abstract\n" "Type in as many lines as you need, and end with a ctrl-d.\n" "To quit, type `q' or `n' when asked if you want to continue.\n" "To edit the database, type `edit', `vi', or `ex' instead.")); } static void rd_skel(char *arg) /* redo bibskel from user-supplied file */ { FILE *pfp, *fopen(); char str[BUFSIZ]; int entry, i, j; if ((pfp = fopen(arg, "r")) == NULL) { fprintf(stderr, gettext("Promptfile ")); perror(arg); exit(1); } for (entry = 0; fgets(str, BUFSIZ, pfp); entry++) { for (i = 0; str[i] != '\t' && str[i] != '\n'; i++) bibskel[entry].prompt[i] = str[i]; bibskel[entry].prompt[i] = '\0'; if (str[i] == '\n') { fprintf(stderr, gettext( "No tabs between promptfile fields.\n")); fprintf(stderr, gettext( "Format: prompt-string %%key\n")); exit(1); } for (i++, j = 0; str[i] != '\n'; i++, j++) bibskel[entry].keylet[j] = str[i]; bibskel[entry].keylet[j] = '\0'; if (entry >= MAXENT) { fprintf(stderr, gettext( "Too many entries in promptfile.\n")); exit(1); } } entries = entry; fclose(pfp); } # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License, Version 1.0 only # (the "License"). You may not use this file except in compliance # with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # msgid "%A" msgid "%T" msgid "%J" msgid "%V" msgid "%P" msgid "%I" msgid "%C" msgid "%D" msgid "%O" msgid "%K" msgid "" msgid "a" msgid "%s %s" msgid "> " msgid "%%X " msgid "+$" msgid "r" /* * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1980 Regents of the University of California. * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. */ #include #include int hash(char *s) { int c, n; for (n = 0; c = *s; s++) n += (c*n+ c << (n%4)); return (n > 0 ? n : -n); } void err(char *s, int a) { fprintf(stderr, gettext("Error: ")); fprintf(stderr, s, a); putc('\n', stderr); exit(1); } int prefix(char *t, char *s) { int c; while ((c = *t++) == *s++) if (c == 0) return (1); return (c == 0 ? 1 : 0); } char * mindex(char *s, char c) { char *p; for (p = s; *p; p++) if (*p == c) return (p); return (0); } void * zalloc(size_t m, size_t n) { char *calloc(); void *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); } /* * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1980 Regents of the University of California. * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. */ #include #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(); 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; extern int baddrop(); extern int ckexist(); extern int doquery(); extern void err(); extern int getq(); extern void grepcall(); extern int makefgrep(); extern void restodir(); extern void result(); extern void savedir(); extern void *zalloc(); static int setfrom(char); char *todir(char *); void huntmain(int argc, 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; unsigned *masterp; #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 ((int)argv[2] < 16000) { soutlen = (int)argv[2]; argc--; argv++; } break; case 't': /* tag output to string */ argc--; argv++; tagout = argv[1]; if ((int)argv[2] < 16000) { taglen = (int)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 = (long *)zalloc(nhash, sizeof (*hpt)); #if D1 fprintf(stderr, "hpt now %o\n", hpt); #endif if (hpt == NULL) /* * TRANSLATION_NOTE * %d is the size of the hash table - not * very interesting info for the end users. * Hash is a computer science terminology. */ err(gettext("No space for hash list (%d)"), nhash); fread(hpt, sizeof (*hpt), nhash, fa); if (hfreq == 0) hfreq = (int *)zalloc(nhash, sizeof (*hfreq)); if (hfreq == NULL) /* * TRANSLATION_NOTE * %d is the size of the hash table. */ err(gettext( "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 = (long *)zalloc(lmaster, sizeof (long)); else master.a = (unsigned *)zalloc(lmaster, sizeof (int)); if (master.a == NULL) err(gettext("no space for answer list"), 0); } else if (makefgrep(indexname)) typeindex = 2; else { err(gettext("No files %s\n"), indexname); exit(1); } } if (iflong) masterp = (unsigned *)master.b; else masterp = master.a; #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, masterp); #ifdef D1 fprintf(stderr, "return from doquery with nfound %d\n", nfound); #endif if (falseflg == 0) nfound = baddrop(masterp, 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(masterp, 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(char *t) { char *s; usedir[0] = 0; 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); } static int setfrom(char 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); } } /* * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1980 Regents of the University of California. * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. */ char refdir[50]; extern int corout(); extern char *trimnl(); void savedir(void) { if (refdir[0] == 0) corout("", refdir, "/bin/pwd", "", 50); trimnl(refdir); } void restodir(void) { chdir(refdir); } /* * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1980 Regents of the University of California. * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. */ #include "refer..c" #include #define move(x, y) close(y); dup(x); close(x); extern void err(); extern long findline(); extern void huntmain(); extern void restodir(); static int callhunt(char *, char *, char *, int); static int dodeliv(char *, char *, char *, int); int corout(char *in, char *out, char *rprog, char *arg, int outlen) { int pipev[2], fr1, fr2, fw1, fw2, n; #if D1 fprintf(stderr, "in corout, rprog /%s/ in /%s/\n", rprog ? rprog : "", strlen(in) ? in : ""); #endif 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(gettext("Can't run %s"), rprog); } close(fw2); close(fr1); if (strlen(in) > 0) write(fw1, in, strlen(in)); close(fw1); wait(0); n = read(fr2, out, outlen); out[n] = 0; close(fr2); return (0); } #define ALEN 50 static int callhunt(char *in, char *out, char *arg, int outlen) { 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] = (char *)outlen; argv[6] = "-T"; argv[7] = "-F1"; argv[8] = "-o"; argv[9] = one; argv[10] = (char *)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); } static int dodeliv(char *in, char *out, char *arg, int outlen) { char *mout; int mlen; #if D1 fprintf(stderr, "in dodeliv, arg /%s/\n", arg?arg:""); #endif if (arg && arg[0]) chdir(arg); mlen = findline(in, &mout, outlen, 0L); if (mlen > 0) { strncpy(out, mout, outlen); free(mout); } restodir(); return (0); } /* * Copyright 2017 Gary Mills * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1980 Regents of the University of California. * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. */ #include #include extern char gfile[]; void grepcall(char *in, char *out, char *arg) { char line[200], *s, argig[100], *cv[50]; char *inp, inb[500]; FILE *qf, *gf; int c, alph = 0, nv = 0; int sv0, sv1; strcpy(argig, arg); strcat(argig, ".ig"); strcpy(inp = inb, in); if (gfile[0] == 0) sprintf(gfile, "/tmp/rj%dg", getpid()); for (cv[nv++] = "fgrep"; c = *inp; inp++) { if (c == ' ') c = *inp = 0; else if (isupper(c)) *inp = tolower(c); alph = (c == 0) ? 0 : alph+1; if (alph == 1) cv[nv++] = inp; if (alph > 6) *inp = 0; } { sv0 = dup(0); close(0); if (open(argig, 0) != 0) err("Can't read fgrep index %s", argig); sv1 = dup(1); close(1); if (creat(gfile, 0666) != 1) err("Can't write fgrep output %s", gfile); fgrep(nv, cv); close(0); dup(sv0); close(sv0); close(1); dup(sv1); close(sv1); } gf = fopen(gfile, "r"); if (gf == NULL) err("can't read fgrep output %s", gfile); while (fgets(line, 100, gf) == line) { line[100] = 0; for (s = line; *s && (*s != '\t'); s++) ; if (*s == '\t') { *s++ = '\n'; *s++ = 0; } if (line[0]) strcat(out, line); while (*s) s++; if (s[-1] != '\n') while (!feof(gf) && getc(gf) != '\n') ; } fclose(gf); unlink(gfile); } void clfgrep(void) { if (gfile[0]) unlink(gfile); } /* * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1980 Regents of the University of California. * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. */ #include #include /* * 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[2*BUFSIZ]; int nsucc; int need; char *instr; int inct; int rflag; int xargc; char **xargv; int numwords; int nfound; static int flag = 0; extern void err(); extern void *zalloc(); static void cfail(void); static void cgotofn(void); static void execute(void); static char gch(void); static int new(struct words *x); static void overflo(void); int fgrep(int argc, char **argv) { nsucc = need = inct = rflag = numwords = nfound = 0; instr = 0; flag = 0; if (www == 0) www = (struct words *)zalloc(MAXSIZ, sizeof (*www)); if (www == NULL) err(gettext("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 = (int)xargv[1]; xargv++; xargc--; break; case 'i': instr = xargv[1]; inct = (int)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 ? instr[inct-3] : '\0', instr ? instr[inct-2] : '\0', instr ? instr[inct-1] : '\0'); #endif execute(); #if D1 fprintf(stderr, "returning nsucc %d\n", nsucc); fprintf(stderr, "fgrep done www %o\n", www); #endif return (nsucc == 0); } static void execute(void) { char *p; struct words *c; char ch; int 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[2*BUFSIZ]) p = buf; if (p > &buf[BUFSIZ]) { if ((ccount = read(f, p, &buf[2*BUFSIZ] - p)) <= 0) break; } else if ((ccount = read(f, p, BUFSIZ)) <= 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[2*BUFSIZ] %o\n", p, nlp, ccount, buf, buf+2*BUFSIZ); #endif if (instr == 0) while (*p++ != '\n') { #if D3 fprintf(stderr, "down ccount2\n"); #endif if (--ccount <= 0) { if (p == &buf[2*BUFSIZ]) p = buf; if (p > &buf[BUFSIZ]) { if ((ccount = read(f, p, &buf[2*BUFSIZ] - p)) <= 0) break; } else if ((ccount = read(f, p, BUFSIZ)) <= 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[2*BUFSIZ] - 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); } static void cgotofn(void) { char c; 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; } static char gch(void) { static char *s; if (flag == 0) { flag = 1; s = *xargv++; #if D1 fprintf(stderr, "next arg is %s xargc %d\n", xargc > 0 ? s : "", xargc); #endif if (xargc-- <= 0) return (0); } if (*s) return (*s++); for (flag = 0; flag < 2*BUFSIZ; flag++) buf[flag] = 0; flag = 0; return ('\n'); } static void overflo(void) { write(2, "wordlist too large\n", 19); exit(2); } static void cfail(void) { struct words *queue[QSIZE]; struct words **front, **rear; struct words *state; char c; 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 struct words *seen[50]; static int new(struct words *x) { int i; for (i = 0; i < nfound; i++) if (seen[i] == x) return (0); seen[i] = x; return (1); } /* * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1980 Regents of the University of California. * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. */ #include #include #include extern char refdir[]; extern int keepold; extern char *fgnames[]; extern char **fgnamp; FILE *fd = NULL; int lmaster = 500; int *hfreq, hfrflg; int colevel = 0; int measure = 0; int soutlen = 1000; int reached = 0; int iflong = 0; int prfreqs = 0; char usedir[100]; char *calloc(); char *todir(); char gfile[50]; static int full = 1000; static int tags = 0; char *sinput, *soutput, *tagout; long indexdate = 0, gdate(); extern int baddrop(); extern int doquery(); extern void err(); extern long findline(); extern int getq(); extern void grepcall(); extern int makefgrep(); extern void result(); extern void tick(); extern void tock(); static int setfrom(char); int main(int argc, char *argv[]) { /* read query from stdin, expect name of indexes in argv[1] */ static FILE *fa, *fb, *fc; char nma[100], nmb[100], nmc[100], *qitem[100], *rprog = NULL; char nmd[100], grepquery[256]; static char oldname[30]; static int was = 0; /* these pointers are unions of pointer to int and pointer to long */ long *hpt; unsigned *master = 0; int falseflg, nhash, nitem, nfound, frtbl, kk; /* special wart for refpart: default is tags only */ (void) setlocale(LC_ALL, ""); #if !defined(TEXT_DOMAIN) #define TEXT_DOMAIN "SYS_TEST" #endif (void) textdomain(TEXT_DOMAIN); falseflg = 0; while (argc > 1 && argv[1][0] == '-') { 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 ((int)argv[2] < 16000) { soutlen = (int)argv[2]; argc--; argv++; } break; case 't': /* tag output to string */ argc--; argv++; tagout = argv[1]; break; case 'l': /* length of internal lists */ argc--; argv++; lmaster = atoi(argv[1]); break; case 'g': /* suppress fgrep search on old files */ keepold = 0; break; case 'C': /* coordination level */ colevel = atoi(argv[1]+2); #if D1 fprintf(stderr, "colevel set to %d\n", colevel); #endif break; case 'P': /* print term freqs */ prfreqs = 1; break; case 'm': measure = 1; break; } argc--; argv++; } if (argc < 2) exit(1); strcpy(nma, todir(argv[1])); if (was == 0 || strcmp(oldname, nma) != 0) { strcpy(oldname, nma); strcpy(nmb, nma); strcpy(nmc, nmb); strcpy(nmd, nma); strcat(nma, ".ia"); strcat(nmb, ".ib"); strcat(nmc, ".ic"); strcat(nmd, ".id"); if (was) { fclose(fa); fclose(fb); fclose(fc); } fa = fopen(nma, "r"); if (fa == NULL) { strcpy(*fgnamp++ = calloc(strlen(oldname)+2, 1), oldname); fb = NULL; goto search; } fb = fopen(nmb, "r"); fc = fopen(nmc, "r"); was = 1; if (fb == NULL || fc == NULL) { err(gettext("Index incomplete %s"), nmb); exit(1); } indexdate = gdate(fb); fd = fopen(nmd, "r"); } fseek(fa, 0L, 0); fread(&nhash, sizeof (nhash), 1, fa); fread(&iflong, sizeof (iflong), 1, fa); if (master == 0) master = (unsigned *)calloc(lmaster, iflong ? sizeof (long) : sizeof (unsigned)); hpt = (long *)calloc(nhash, sizeof (*hpt)); kk = fread(hpt, sizeof (*hpt), nhash, fa); #if D1 fprintf(stderr, "read %d hashes, iflong %d, nhash %d\n", kk, iflong, nhash); #endif assert(kk == nhash); hfreq = (int *)calloc(nhash, sizeof (*hfreq)); assert(hfreq != NULL); frtbl = fread(hfreq, sizeof (*hfreq), nhash, fa); hfrflg = (frtbl == nhash); #if D1 fprintf(stderr, "read freqs %d\n", frtbl); #endif search: while (1) { nitem = getq(qitem); if (measure) tick(); if (nitem == 0) continue; if (nitem < 0) break; if (tagout) tagout[0] = 0; if (fb != NULL) { nfound = doquery(hpt, nhash, fb, nitem, qitem, master); #if D1 fprintf(stderr, "after doquery nfound %d\n", nfound); #endif fgnamp = fgnames; if (falseflg == 0) nfound = baddrop(master, nfound, fc, nitem, qitem, rprog, full); #if D1 fprintf(stderr, "after baddrop nfound %d\n", nfound); #endif } if (fgnamp > fgnames) { char **fgp, tgbuff[100]; int k; #if D1 fprintf(stderr, "were %d bad files\n", fgnamp-fgnames); #endif (void) memset(tgbuff, 0, sizeof (tgbuff)); grepquery[0] = 0; for (k = 0; k < nitem; k++) { strcat(grepquery, " "); strcat(grepquery, qitem[k]); } #if D1 fprintf(stderr, "grepquery %s\n", grepquery); #endif for (fgp = fgnames; fgp < fgnamp; fgp++) { #if D1 fprintf(stderr, "Now on %s query /%s/\n", *fgp, grepquery); #endif makefgrep(*fgp); #if D1 fprintf(stderr, "grepmade\n"); #endif if (tagout == 0) tagout = tgbuff; grepcall(grepquery, tagout, *fgp); #if D1 fprintf(stderr, "tagout now /%s/\n", tagout); #endif if (full) { int nout; char *bout; char *tagp; char *oldtagp; tagp = tagout; while (*tagp) { oldtagp = tagp; while (*tagp && (*tagp != '\n')) tagp++; if (*tagp) tagp++; nout = findline(oldtagp, &bout, 1000, 0L); if (nout > 0) { fputs(bout, stdout); free(bout); } } } } } if (tags) result(master, nfound > tags ? tags : nfound, fc); if (measure) tock(); } return (0); } char * todir(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); } static int setfrom(char 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); } } /* * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1980 Regents of the University of California. * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. */ #include "refer..c" static int *coord = 0; int hh[50]; extern int *hfreq, hfrflg; extern int prfreqs; union ptr { unsigned *a; long *b; }; extern int hash(); extern void shell(); extern void *zalloc(); static long getl(FILE *); static int hcomp(int, int); static void hexch(int, int); int doquery(long *hpt, int nhash, FILE *fb, int nitem, char *qitem[], unsigned *mptr) { long k; union ptr prevdrop, master; int nf = 0, best = 0, nterm = 0, i, g, j; int *prevcoord; long lp; extern int lmaster, colevel, reached; extern int iflong; if (iflong) { master.b = (long *)mptr; } else { master.a = mptr; } #if D1 fprintf(stderr, "entering doquery nitem %d\n", nitem); fprintf(stderr, "first few hashes are %ld %ld %ld %ld %ld\n", hpt[0], hpt[1], hpt[2], hpt[3], hpt[4]); fprintf(stderr, "and frequencies are %d %d %d %d %d\n", hfreq[0], hfreq[1], hfreq[2], hfreq[3], hfreq[4]); #endif assert(lmaster > 0); if (coord == 0) coord = (int *)zalloc(lmaster, sizeof (lmaster)); if (colevel > 0) { if (iflong) prevdrop.b = (long *)zalloc(lmaster, sizeof (long)); else prevdrop.a = (unsigned *)zalloc(lmaster, sizeof (int)); prevcoord = (int *)zalloc(lmaster, sizeof (lmaster)); } else { prevdrop.a = master.a; prevcoord = coord; } #if D1 fprintf(stderr, "nitem %d\n", nitem); #endif for (i = 0; i < nitem; i++) { hh[i] = hash(qitem[i])%nhash; #if D1 fprintf(stderr, "query wd X%sX has hash %d\n", qitem[i], hh[i]); #endif } #if D1 fprintf(stderr, "past that loop nhash %d hpt is %lo\n", nhash, hpt); #endif if (prfreqs) for (i = 0; i < nitem; i++) fprintf(stderr, "item %s hash %d hfreq %d\n", qitem[i], hh[i], hfreq[hh[i]]); /* if possible, sort query into decreasing frequency of hashes */ if (hfrflg) shell(nitem, hcomp, hexch); #if D1 for (i = 0; i < nitem; i++) fprintf(stderr, "item hash %d frq %d\n", hh[i], hfreq[hh[i]]); #endif lp = hpt [hh[0]]; #if D1 fprintf(stderr, "first item hash %d lp %ld 0%lo\n", hh[0], lp, lp); #endif assert(fb != NULL); assert(fseek(fb, lp, 0) != -1); for (i = 0; i < lmaster; i++) { if (iflong) master.b[i] = getl(fb); else master.a[i] = getw(fb); coord[i] = 1; #if D2 if (iflong) fprintf(stderr, "master has %ld\n", (master.b[i])); else fprintf(stderr, "master has %d\n", (master.a[i])); #endif assert(i < lmaster); if (iflong) { if (master.b[i] == -1L) break; } else { if (master.a[i] == -1) break; } } nf = i; for (nterm = 1; nterm < nitem; nterm++) { #ifdef D1 fprintf(stderr, "item %d, hash %d\n", nterm, hh[nterm]); #endif if (colevel > 0) { for (j = 0; j < nf; j++) { if (iflong) prevdrop.b[j] = master.b[j]; else prevdrop.a[j] = master.a[j]; prevcoord[j] = coord[j]; } } lp = hpt[hh[nterm]]; assert(fseek(fb, lp, 0) != -1); #if D1 fprintf(stderr, "item %d hash %d seek to %ld\n", nterm, hh[nterm], lp); #endif g = j = 0; while (1) { if (iflong) k = getl(fb); else k = getw(fb); if (k == -1) break; #if D2 fprintf(stderr, "next term finds %ld\n", k); #endif #if D3 if (iflong) fprintf(stderr, "bfwh j %d nf %d master %ld k %ld\n", j, nf, prevdrop.b[j], (long)(k)); else fprintf(stderr, "bfwh j %d nf %d master %ld k %ld\n", j, nf, prevdrop.a[j], (long)(k)); #endif while (j < nf && (iflong ? prevdrop.b[j] : prevdrop.a[j]) < k) { #if D3 if (iflong) fprintf(stderr, "j %d nf %d prevdrop " "%ld prevcoord %d colevel %d nterm " "%d k %ld\n", j, nf, prevdrop.b[j], prevcoord[j], colevel, nterm, (long)(k)); else fprintf(stderr, "j %d nf %d prevdrop " "%ld prevcoord %d colevel %d nterm " "%d k %ld\n", j, nf, prevdrop.a[j], prevcoord[j], colevel, nterm, (long)(k)); #endif if (prevcoord[j] + colevel <= nterm) j++; else { assert(g < lmaster); if (iflong) master.b[g] = prevdrop.b[j]; else master.a[g] = prevdrop.a[j]; coord[g++] = prevcoord[j++]; #if D1 if (iflong) fprintf(stderr, " not skip g " "%d doc %d coord %d note " "%d\n", g, master.b[g-1], coord[g-1], master.b[j-1]); else fprintf(stderr, " not skip g " "%d doc %ld coord %d nterm " "%d\n", g, master.a[g-1], coord[g-1], nterm); #endif continue; } } if (colevel == 0 && j >= nf) break; if (j < nf && (iflong ? prevdrop.b[j] : prevdrop.a[j]) == k) { if (iflong) master.b[g] = k; else master.a[g] = k; coord[g++] = prevcoord[j++]+1; #if D1 if (iflong) fprintf(stderr, " at g %d item %ld " "coord %d note %ld\n", g, master.b[g-1], coord[g-1], master.b[j-1]); else fprintf(stderr, " at g %d item %d " "coord %d note %d\n", g, master.a[g-1], coord[g-1], master.a[j-1]); #endif } else if (colevel >= nterm) { if (iflong) master.b[g] = k; else master.a[g] = k; coord[g++] = 1; } } #if D1 fprintf(stderr, "now have %d items\n", g); #endif if (colevel > 0) for (; j < nf; j++) if ((iflong ? prevdrop.b[j] : prevdrop.a[j]) + colevel > nterm) { assert(g < lmaster); if (iflong) master.b[g] = prevdrop.b[j]; else master.a[g] = prevdrop.a[j]; coord[g++] = prevcoord[j]; #if D3 if (iflong) fprintf(stderr, "copied over " "%ld coord %d\n", master.b[g-1], coord[g-1]); else fprintf(stderr, "copied over " "%d coord %d\n", master.a[g-1], coord[g-1]); #endif } nf = g; } if (colevel > 0) { best = 0; for (j = 0; j < nf; j++) if (coord[j] > best) best = coord[j]; #if D1 fprintf(stderr, "colevel %d best %d\n", colevel, best); #endif reached = best; for (g = j = 0; j < nf; j++) if (coord[j] == best) { if (iflong) master.b[g++] = master.b[j]; else master.a[g++] = master.a[j]; } nf = g; #if D1 fprintf(stderr, "yet got %d\n", nf); #endif } #ifdef D1 fprintf(stderr, " returning with %d\n", nf); #endif if (colevel) { free(prevdrop, lmaster, iflong ? sizeof (long): sizeof (int)); free(prevcoord, lmaster, sizeof (lmaster)); } #if D3 for (g = 0; g < nf; g++) if (iflong) fprintf(stderr, ":%ld\n", master.b[g]); else fprintf(stderr, ":%d\n", master.a[g]); #endif return (nf); } static long getl(FILE *fb) { return (getw(fb)); } static int hcomp(int n1, int n2) { return (hfreq[hh[n1]] <= hfreq[hh[n2]]); } static void hexch(int n1, int n2) { int t; t = hh[n1]; hh[n1] = hh[n2]; hh[n2] = t; } /* * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1980 Regents of the University of California. * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. */ #include #include "refer..c" #define BSIZ 250 int getq(char *v[]) { 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; if (p > buff + BSIZ) fprintf(stderr, gettext("query long than %d characters\n"), BSIZ); 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); } /* * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1980 Regents of the University of California. * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. */ #include #include #include extern char *soutput, *tagout, usedir[]; union ptr { unsigned *a; long *b; }; void result(unsigned *mptr, int nf, FILE *fc) { int i, c; char *s; long lp; extern int iflong; char res[100]; union ptr master; if (iflong) { master.b = (long *)mptr; } else { master.a = mptr; } 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); } } } long gdate(f) FILE *f; { struct stat sb; fstat(fileno(f), &sb); return (sb . st_mtime); } /* * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1980 Regents of the University of California. * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. */ #include #include #include #define TXTLEN 1000 char *outbuf = 0; extern char *soutput; extern int soutlen, iflong; extern long indexdate; union ptr { unsigned *a; long *b; }; extern int corout(); extern int fgrep(); extern long findline(); static int auxil(char *, char *); int baddrop(unsigned *mptr, int nf, FILE *fc, int nitem, char *qitem[], char *rprog, int full) { /* checks list of drops for real bad drops; finds items with "deliv" */ int i, g, j, need, got, na, len; long lp; char res[100], *ar[50], output[TXTLEN], *mput; union ptr master; extern int colevel, reached; if (iflong) { master.b = (long *)mptr; } else { master.a = mptr; } #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; } if (rprog) len = corout(res, output, rprog, "", TXTLEN); else { len = findline(res, &mput, TXTLEN, indexdate); if (len > 0) { /* copy and free */ strncpy(output, mput, TXTLEN); free(mput); } else /* insufficient memory or other... */ len = 0; } } #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++] = (char *)need; ar[na++] = "-i"; ar[na++] = output; ar[na++] = (char *)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); } static int auxil(char *res, char *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); } /* * Copyright 2017 Gary Mills * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1980 Regents of the University of California. * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. */ #include #include #include #define SAME 0 #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; extern char *mindex(); long findline(char *in, char **out, int outlen, long indexdate) { static char name[100] = ""; char *p, **ftp; extern long gdate(); static FILE *fa = NULL; long lp, llen; int k, nofil; if (mindex(in, '!')) return (0); 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); if (k < 2) { lp = 0; llen = outlen; } if (nofil) { fa = stdin; } else if (strcmp(name, in) != 0 || 1) { if (fa != NULL) fa = freopen(in, "r", fa); else fa = fopen(in, "r"); 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, gettext( "Warning: index predates file '%s'\n"), name); } } if (fa != NULL) { fseek(fa, lp, 0); *out = (char *)malloc(llen + 1); if (*out == NULL) { return (0); } (void) fread(*out, 1, llen, fa); *(*out + llen) = 0; } return (llen); } /* * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1980 Regents of the University of California. * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. */ #include #include #include #define unopen(fil) {if (fil != NULL) {fclose(fil); fil = NULL; }} extern void err(); extern long indexdate, gdate(); extern FILE *iopen(); int ckexist(char *, char *); static void runbib(char *s) { /* make a file suitable for fgrep */ char tmp[200]; sprintf(tmp, "/usr/lib/refer/mkey '%s' > '%s.ig'", s, s); system(tmp); } int makefgrep(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)) { if (fa != NULL) 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); } else /* failure */ return (0); return (1); /* success */ } int ckexist(char *s, char *t) { char fnam[100]; strcpy(fnam, s); strcat(fnam, t); return (access(fnam, 04) != -1); } FILE * iopen(char *s, char *t) { char fnam[100]; FILE *f; strcpy(fnam, s); strcat(fnam, t); f = fopen(fnam, "r"); if (f == NULL) { err(gettext("Missing expected file %s"), fnam); exit(1); } return (f); } #!/usr/bin/sh # Copyright 1988 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T # All Rights Reserved # Copyright (c) 1980 Regents of the University of California. # All rights reserved. The Berkeley software License Agreement # specifies the terms and conditions for redistribution. # # indxbib sh script # if test $1 then /usr/lib/refer/mkey $* | /usr/lib/refer/inv _$1 mv _$1.ia $1.ia mv _$1.ib $1.ib mv _$1.ic $1.ic else echo 'Usage: indxbib database [ ... ] first argument is the basename for indexes indexes will be called database.{ia,ib,ic}' fi /* * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1980 Regents of the University of California. * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. */ #include #include #include extern void err(); extern int newkeys(); extern int recopy(); extern void whash(); int main(int argc, char *argv[]) { /* * Make inverted file indexes. Reads a stream from mkey which * gives record pointer items and keys. Generates 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; FILE *fd = NULL; 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; (void) setlocale(LC_ALL, ""); #if !defined(TEXT_DOMAIN) #define TEXT_DOMAIN "SYS_TEST" #endif (void) textdomain(TEXT_DOMAIN); sortdir = (access("/crp/tmp", 06) == 0) ? "/crp/tmp" : "/usr/tmp"; while (argc > 1 && 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(gettext("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) { sprintf(com, "/bin/sort -T %s -o %s", sortdir, tmpa); fta = popen(com, "w"); } 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(gettext("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) { pclose(fta); } 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(gettext("%ld key occurrences, %d hashes, %d docs\n"), keys, hashes, docs); return (0); } /* * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1980 Regents of the University of California. * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. */ #include #include #define LINESIZ 1250 extern int hash(); int newkeys(FILE *outf, FILE *inf, FILE *recf, int nhash, FILE *fd, int *iflong) { /* * reads key lines from inf; hashes and writes on outf; * writes orig key on recf, records pointer on outf too. * format of outf is : hash code space record pointer */ long lp, ftell(); long ld = 0; int ll = 0, lt = 0; char line[LINESIZ]; char key[30], bkeys[40]; char *p, *s; char *keyv[500]; int i, nk, ndoc = 0, more = 0, c; lp = ftell(recf); while (fgets(line, LINESIZ, inf)) { p = line; while (*p != '\t') p++; *p++ = 0; fputs(line, recf); if (fd) { sprintf(bkeys, ";%ld", ld); ll = strlen(p); lt = strlen(bkeys); fputs(bkeys, recf); sprintf(bkeys, ",%d", ll); lt += strlen(bkeys); fputs(bkeys, recf); ld += ll; fputs(p, fd); } putc('\n', recf); for (s = p; *s; s++) ; if (*--s == '\n') { more = 0; *s = 0; } else more = 1; assert(fd == 0 || more == 0); nk = getargs(p, keyv); if (more) nk--; for (i = 0; i < nk; i++) fprintf(outf, "%04d %06ld\n", hash(keyv[i])%nhash, lp); #if D1 for (i = 0; i < nk; i++) printf("key %s hash %d\n", keyv[i], hash(keyv[i])%nhash); #endif if (more) { /* allow more than LINESIZ keys */ strcpy(key, keyv[nk]); for (s = key; *s; s++) ; while ((c = getc(inf)) != '\n') { if (c != ' ') { *s++ = c; continue; } *s = 0; if (s > key) fprintf(outf, "%04d %06ld\n", hash(key)%nhash, lp); s = key; } } lp += (strlen(line)+lt+1); ndoc++; } *iflong = (lp >= 65536L); if (sizeof (int) > 2) *iflong = 1; /* force long on VAX */ fclose(recf); return (ndoc); } void trimnl(char *p) { while (*p) p++; p--; if (*p == '\n') *p = 0; } /* * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1980 Regents of the University of California. * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. */ int getargs(char *s, char *arps[]) { int 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); } /* * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1980 Regents of the University of California. * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. */ #include #include extern void err(); int recopy(FILE *ft, FILE *fb, FILE *fa, int nhash) { /* 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(gettext("No old pointers"), 0); return (0); } fread(&n, sizeof (n), 1, fa); fread(&iflong, sizeof (iflong), 1, fa); if (iflong) { hpt_l = (long *)calloc(sizeof (*hpt_l), n+1); n = fread(hpt_l, sizeof (*hpt_l), n, fa); } else { hpt_s = (int *)calloc(sizeof (*hpt_s), n+1); n = fread(hpt_s, sizeof (*hpt_s), n, fa); } if (n != nhash) fprintf(stderr, gettext("Changing hash value to old %d\n"), n); fclose(fa); if (iflong) getfun = (int(*)())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); } /* * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1980 Regents of the University of California. * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. */ #include #include static void putl(long, FILE *); void whash(FILE *ft, FILE *fa, FILE *fb, int nhash, int iflong, long *ptotct, int *phused) { char line[100]; int hash = 0, hused = 0; long totct = 0L; int ct = 0; long point; long opoint = -1; int m; int k; long lp; long *hpt; int *hfreq = NULL; hpt = (long *)calloc(nhash+1, sizeof (*hpt)); assert(hpt != NULL); hfreq = (int *)calloc(nhash, sizeof (*hfreq)); assert(hfreq != NULL); hpt[0] = 0; lp = 0; while (fgets(line, 100, ft)) { totct++; sscanf(line, "%d %ld", &k, &point); if (hash < k) { hused++; if (iflong) putl(-1L, fb); else putw(-1, fb); hfreq[hash] = ct; while (hash < k) { hpt[++hash] = lp; hfreq[hash] = 0; } hpt[hash] = lp += iflong ? sizeof (long) : sizeof (int); opoint = -1; ct = 0; } if (point != opoint) { if (iflong) putl(opoint = point, fb); else putw((int)(opoint = point), fb); lp += iflong ? sizeof (long) : sizeof (int); ct++; } } if (iflong) putl(-1L, fb); else putw(-1, fb); while (hash < nhash) hpt[++hash] = lp; fwrite(&nhash, sizeof (nhash), 1, fa); fwrite(&iflong, sizeof (iflong), 1, fa); fwrite(hpt, sizeof (*hpt), nhash, fa); fwrite(hfreq, sizeof (*hfreq), nhash, fa); *ptotct = totct; *phused = hused; } static void putl(long ll, FILE *f) { putw(ll, f); } long getl(FILE *f) { return (getw(f)); } /* * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1980 Regents of the University of California. * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. */ #include #include #include static void instruct(void); static void map_lower(char *); /* look in biblio for record matching keywords */ int main(int argc, char **argv) { FILE *hfp, *fopen(), *popen(); char s[BUFSIZ], hunt[64]; (void) setlocale(LC_ALL, ""); #if !defined(TEXT_DOMAIN) #define TEXT_DOMAIN "SYS_TEST" #endif (void) textdomain(TEXT_DOMAIN); if (argc == 1 || argc > 2) { fputs(gettext("Usage: lookbib database\n\ \tfinds citations specified on standard input\n"), stderr); exit(1); } sprintf(s, "%s.ia", argv[1]); if (access(s, 0) == -1) { sprintf(s, "%s", argv[1]); if (access(s, 0) == -1) { perror(s); fprintf(stderr, gettext("\tNeither index file %s.ia \ nor reference file %s found\n"), s, s); exit(1); } } sprintf(hunt, "/usr/lib/refer/hunt %s", argv[1]); if (isatty(fileno(stdin))) { fprintf(stderr, gettext("Instructions? ")); fgets(s, BUFSIZ, stdin); if (*s == 'y') instruct(); } again: fprintf(stderr, "> "); if (fgets(s, BUFSIZ, stdin)) { if (*s == '\n') goto again; if (strlen(s) <= 3) goto again; if ((hfp = popen(hunt, "w")) == NULL) { perror(gettext("lookbib: /usr/lib/refer/hunt")); exit(1); } map_lower(s); fputs(s, hfp); pclose(hfp); goto again; } fprintf(stderr, gettext("EOT\n")); return (0); } static void map_lower(char *s) /* map string s to lower case */ { for (; *s; ++s) if (isupper(*s)) *s = tolower(*s); } static void instruct(void) { fputs(gettext( "\nType keywords (such as author and date) after the > prompt.\n\ References with those keywords are printed if they exist;\n\ \tif nothing matches you are given another prompt.\n\ To quit lookbib, press CTRL-d after the > prompt.\n\n"), stderr); } /* * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1980 Regents of the University of California. * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. */ #include #include extern char *comname; /* "/usr/lib/refer/eign" */ int wholefile = 0; int keycount = 100; int labels = 1; int minlen = 3; extern int comcount; char *iglist = "XYZ#"; extern void dofile(); extern void err(); extern char *trimnl(); int main(int argc, 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; (void) setlocale(LC_ALL, ""); #if !defined(TEXT_DOMAIN) #define TEXT_DOMAIN "SYS_TEST" #endif (void) textdomain(TEXT_DOMAIN); 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, gettext("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(gettext("No file %s"), name); else dofile(f, name); } return (0); } /* * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1980 Regents of the University of California. * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. */ #include #include #define MAXLINE 500 static int eof = 0; static long lp, lim; static int alph, used, prevc; static char *p, key[20]; extern int common(); extern char *mindex(); static void chkey(int, char *); static long grec(char *, FILE *); void dofile(FILE *f, char *name) { /* read file f & spit out keys & ptrs */ char line[MAXLINE], *s; extern int minlen, keycount, labels; int c; 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); } static int outkey(char *ky, int lead, int trail) { int n; extern int minlen; 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])) /* Allow years 1000 - 2099 */ if (!(ky[0] == '1' || (ky[0] == '2' && ky[1] == '0')) || n != 4) return (0); if (common(ky)) return (0); return (1); } static long grec(char *s, FILE *f) { char tm[200]; int curtype = 0; long len = 0L, tlen = 0L; extern int wholefile; extern char *iglist; 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(char *ln) { char *p = ln; while (*p) p++; p--; if (*p == '\n') *p = 0; return (ln); } static void chkey(int c, char *name) { extern int labels; extern int wholefile; 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; } } /* * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1980 Regents of the University of California. * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. */ #include #define COMNUM 500 #define COMTSIZE 997 char *comname = "/usr/lib/refer/eign"; static int cgate = 0; extern char *comname; int comcount = 100; static char cbuf[COMNUM*9]; static char *cwds[COMTSIZE]; static char *cbp; extern int hash(); extern char *trimnl(); static void cominit(void); static int c_look(char *, int); int common(char *s) { if (cgate == 0) cominit(); return (c_look(s, 1)); } static void cominit(void) { 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); } static int c_look(char *s, int fl) { 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); } # #ident "%Z%%M% %I% %E% SMI" # # Copyright (c) 1989 by Sun Microsystems, Inc. # # Makefile for cmd/refer/papers # include ../../Makefile.cmd ROOTDIRS = $(ROOT)/usr/lib/refer/papers PAPERS = Rbstjissue runinv Rv7man ROOTPAPERS = $(PAPERS:%=$(ROOTDIRS)/%) FILEMODE = 644 $(ROOTDIRS)/runinv : FILEMODE = 755 # install rule $(ROOTDIRS)/% : % $(INS.file) .KEEP_STATE: all : $(PAPERS) install: all $(ROOTDIRS) $(ROOTPAPERS) $(ROOTDIRS) : $(INS.dir) clean clobber strip: %T U\s-2NIX\s0 Time-Sharing System: Preface %A T. H. Crowley %J Bell Sys. Tech. J. %V 57 %N 6 %P 1897-1898 %D 1978 %K bstj unix %T U\s-2NIX\s0 Time-Sharing System: Foreword %A M. D. McIlroy %A E. N. Pinson %A B. A. Tague %J Bell Sys. Tech. J. %V 57 %N 6 %P 1899-1904 %D 1978 %K unix bstj %T The U\s-2NIX\s0 Time-Sharing System %K unix bstj %A D. M. Ritchie %A K. Thompson %J Bell Sys. Tech. J. %V 57 %N 6 %P 1905-1929 %D 1978 %T U\s-2NIX\s0 Time-Sharing System: U\s-2NIX\s0 Implementation %K unix bstj %A K. Thompson %J Bell Sys. Tech. J. %V 57 %N 6 %P 1931-1946 %D 1978 %T U\s-2NIX\s0 Time-Sharing System: A Retrospective %K unix bstj %A D. M. Ritchie %J Bell Sys. Tech. J. %V 57 %N 6 %P 1947-1969 %D 1978 %O Also in \f1Proc. Hawaii International Conference on Systems Science,\f1 Honolulu, Hawaii, Jan. 1977. %T U\s-2NIX\s0 Time-Sharing System: The U\s-2NIX\s0 Shell %A S. R. Bourne %K unix bstj %J Bell Sys. Tech. J. %V 57 %N 6 %P 1971-1990 %D 1978 %T U\s-2NIX\s0 Time-Sharing System: The C Programming Language %A D. M. Ritchie %A S. C. Johnson %A M. E. Lesk %A B. W. Kernighan %J Bell Sys. Tech. J. %V 57 %N 6 %P 1991-2019 %D 1978 %K bstj %T U\s-2NIX\s0 Time-Sharing System: Portability of C Programs and the U\s-2NIX\s0 System %K unix bstj %A S. C. Johnson %A D. M. Ritchie %J Bell Sys. Tech. J. %V 57 %N 6 %P 2021-2048 %D 1978 %T U\s-2NIX\s0 Time-Sharing System: The M\s-2ERT\s0 Operating System %A H. Lycklama %A D. L. Bayer %J Bell Sys. Tech. J. %V 57 %N 6 %K mert %P 2049-2086 %D 1978 %K bstj %T U\s-2NIX\s0 Time-Sharing System: U\s-2NIX\s0 on a Microprocessor %K unix bstj %A H. Lycklama %J Bell Sys. Tech. J. %V 57 %N 6 %P 2087-2101 %D 1978 %T U\s-2NIX\s0 Time-Sharing System: A Minicomputer Satellite Processor System %A H. Lycklama %A C. Christensen %J Bell Sys. Tech. J. %V 57 %N 6 %P 2103-2113 %D 1978 %K bstj unix %T U\s-2NIX\s0 Time-Sharing System: Document Preparation %K unix bstj %A B. W. Kernighan %A M. E. Lesk %A J. F. Ossanna %J Bell Sys. Tech. J. %V 57 %N 6 %P 2115-2135 %D 1978 %T U\s-2NIX\s0 Time-Sharing System: Statistical Text Processing %K unix bstj %A L. E. McMahon %A L. L. Cherry %A R. Morris %J Bell Sys. Tech. J. %V 57 %N 6 %P 2137-2154 %D 1978 %T U\s-2NIX\s0 Time-Sharing System: Language Development Tools %K unix bstj %A S. C. Johnson %A M. E. Lesk %J Bell Sys. Tech. J. %V 57 %N 6 %P 2155-2175 %D 1978 %T U\s-2NIX\s0 Time-Sharing System: The Programmer's Workbench %A T. A. Dolotta %A R. C. Haight %A J. R. Mashey %J Bell Sys. Tech. J. %V 57 %N 6 %P 2177-2200 %D 1978 %K unix bstj %T U\s-2NIX\s0 Time-Sharing System: The U\s-2NIX\s0 Operating System as a Base for Applications %K unix bstj %A G. W. R. Luderer %A J. F. Maranzano %A B. A. Tague %J Bell Sys. Tech. J. %V 57 %N 6 %P 2201-2207 %D 1978 %T U\s-2NIX\s0 Time-Sharing System: Microcomputer Control of Apparatus, Machinery, and Experiments %K unix bstj %A B. C. Wonsiewicz %A A. R. Storm %A J. D. Sieber %J Bell Sys. Tech. J. %V 57 %N 6 %P 2209-2232 %D 1978 %T U\s-2NIX\s0 Time-Sharing System: Circuit Design Aids %K unix bstj %A A. G. Fraser %J Bell Sys. Tech. J. %V 57 %N 6 %P 2233-2249 %D 1978 %T U\s-2NIX\s0 Time-Sharing System: A Support Environment for M\s-2AC\s0-8 Systems %A H. D. Rovegno %K mac8 unix %J Bell Sys. Tech. J. %V 57 %N 6 %P 2251-2263 %K bstj %D 1978 %T U\s-2NIX\s0 Time-Sharing System: No. 4 ESS Diagnostic Environment %K unix bstj %A S. P. Pekarich %J Bell Sys. Tech. J. %V 57 %N 6 %P 2265-2274 %D 1978 %T U\s-2NIX\s0 Time-Sharing System: R\s-2BCS\s0/R\s-2CMAS\s0 \(em Converting to the M\s-2ERT\s0 Operating System %K unix bstj %A E. R. Nagelberg %A M. A. Pilla %J Bell Sys. Tech. J. %V 57 %N 6 %P 2275-2287 %D 1978 %T U\s-2NIX\s0 Time-Sharing System: The Network Operations Center System %K unix bstj %A H. Cohen %A J. C. Kaufeld, Jr. %J Bell Sys. Tech. J. %V 57 %N 6 %P 2289-2304 %D 1978 %A L. P. Deutsch %A B. W. Lampson %T An online editor %J Comm. Assoc. Comp. Mach. %V 10 %N 12 %D December 1967 %P 793-799, 803 %K qed .[ %r 17 %K cstr %R Comp. Sci. Tech. Rep. No. 17 %I Bell Laboratories %C Murray Hill, New Jersey %A B. W. Kernighan %A L. L. Cherry %T A System for Typesetting Mathematics %d May 1974, revised April 1977 %J Comm. Assoc. Comp. Mach. %K acm cacm %V 18 %P 151-157 %D March 1975 .] %T U\s-2NIX\s0 Time-Sharing System: Document Preparation %K unix bstj %A B. W. Kernighan %A M. E. Lesk %A J. F. Ossanna %J Bell Sys. Tech. J. %V 57 %N 6 %P 2115-2135 %D 1978 %A T. A. Dolotta %A J. R. Mashey %T An Introduction to the Programmer's Workbench %J Proc. 2nd Int. Conf. on Software Engineering %D October 13-15, 1976 %P 164-168 %T U\s-2NIX\s0 Time-Sharing System: The Programmer's Workbench %A T. A. Dolotta %A R. C. Haight %A J. R. Mashey %J Bell Sys. Tech. J. %V 57 %N 6 %P 2177-2200 %D 1978 %K unix bstj %T U\s-2NIX\s0 Time-Sharing System: U\s-2NIX\s0 on a Microprocessor %K unix bstj %A H. Lycklama %J Bell Sys. Tech. J. %V 57 %N 6 %P 2087-2101 %D 1978 %T The C Programming Language %A B. W. Kernighan %A D. M. Ritchie %I Prentice-Hall %C Englewood Cliffs, New Jersey %D 1978 %T Computer Recreations %A Aleph-null %J Software Practice and Experience %V 1 %N 2 %D April-June 1971 %P 201-204 %T U\s-2NIX\s0 Time-Sharing System: The U\s-2NIX\s0 Shell %A S. R. Bourne %K unix bstj %J Bell Sys. Tech. J. %V 57 %N 6 %P 1971-1990 %D 1978 %A L. P. Deutsch %A B. W. Lampson %T \*sSDS\*n 930 time-sharing system preliminary reference manual %R Doc. 30.10.10, Project \*sGENIE\*n %C Univ. Cal. at Berkeley %D April 1965 %A R. J. Feiertag %A E. I. Organick %T The Multics input-output system %J Proc. Third Symposium on Operating Systems Principles %D October 18-20, 1971 %P 35-41 %A D. G. Bobrow %A J. D. Burchfiel %A D. L. Murphy %A R. S. Tomlinson %T \*sTENEX\*n, a Paged Time Sharing System for the \*sPDP\*n-10 %J Comm. Assoc. Comp. Mach. %V 15 %N 3 %D March 1972 %K tenex %P 135-143 %A R. E. Griswold %A D. R. Hanson %T An Overview of SL5 %J SIGPLAN Notices %V 12 %N 4 %D April 1977 %P 40-50 %A E. W. Dijkstra %T Cooperating Sequential Processes %B Programming Languages %E F. Genuys %I Academic Press %C New York %D 1968 %P 43-112 %A J. A. Hawley %A W. B. Meyer %T M\s-2UNIX\s0, A Multiprocessing Version of U\s-2NIX\s0 %K munix unix %R M.S. Thesis %I Naval Postgraduate School %C Monterey, Cal. %D 1975 %T The U\s-2NIX\s0 Time-Sharing System %K unix bstj %A D. M. Ritchie %A K. Thompson %J Bell Sys. Tech. J. %V 57 %N 6 %P 1905-1929 %D 1978 %A E. I. Organick %T The M\s-2ULTICS\s0 System %K multics %I M.I.T. Press %C Cambridge, Mass. %D 1972 %T UNIX for Beginners %A B. W. Kernighan %D 1978 %T U\s-2NIX\s0 Programmer's Man\&ual %A K. Thompson %A D. M. Ritchie %K unix %I Bell Laboratories %O Seventh Edition. %D 1978 %A K. Thompson %T The U\s-2NIX\s0 Command Language %B Structured Programming\(emInfotech State of the Art Report %I Infotech International Ltd. %C Nicholson House, Maidenhead, Berkshire, England %D March 1975 %P 375-384 %K unix %X pwb Brief description of shell syntax and semantics, without much detail on implementation. Much on pipes and convenience of hooking programs together. Includes SERMONETTE: "Many familiar computing `concepts' are missing from UNIX. Files have no records. There are no access methods. There are no file types. These concepts fill a much-needed gap. I sincerely hope that when future systems are designed by manufacturers the value of some of these ingrained notions is re-examined. Like the politician and his `common man', manufacturers have their `average user'. %A J. R. Mashey %T PWB/UNIX Shell Tutorial %D September 30, 1977 %A D. F. Hartley (Ed.) %T The Cambridge Multiple Access System \- Users Reference Manual %I University Mathematical Laboratory %C Cambridge, England %D 1968 %A P. A. Crisman (Ed.) %T The Compatible Time-Sharing System %I M.I.T. Press %K whole ctss book %C Cambridge, Mass. %D 1965 %T LR Parsing %A A. V. Aho %A S. C. Johnson %J Comp. Surveys %V 6 %N 2 %P 99-124 %D June 1974 %T Deterministic Parsing of Ambiguous Grammars %A A. V. Aho %A S. C. Johnson %A J. D. Ullman %J Comm. Assoc. Comp. Mach. %K acm cacm %V 18 %N 8 %P 441-452 %D August 1975 %A A. V. Aho %A J. D. Ullman %T Principles of Compiler Design %I Addison-Wesley %C Reading, Mass. %D 1977 .[ %r 65 %R Comp. Sci. Tech. Rep. No. 65 %K CSTR %A S. C. Johnson %T Lint, a C Program Checker %D December 1977 %O updated version TM 78-1273-3 %D 1978 .] %T A Portable Compiler: Theory and Practice %A S. C. Johnson %J Proc. 5th ACM Symp. on Principles of Programming Languages %P 97-104 %D January 1978 .[ %r 39 %K CSTR %R Comp. Sci. Tech. Rep. No. 39 %I Bell Laboratories %C Murray Hill, New Jersey %A M. E. Lesk %T Lex \(em A Lexical Analyzer Generator %D October 1975 .] .[ %r 32 %K CSTR %R Comp. Sci. Tech. Rep. No. 32 %I Bell Laboratories %C Murray Hill, New Jersey %A S. C. Johnson %T Yacc \(em Yet Another Compiler-Compiler %D July 1975 .] %T U\s-2NIX\s0 Time-Sharing System: Portability of C Programs and the U\s-2NIX\s0 System %K unix bstj %A S. C. Johnson %A D. M. Ritchie %J Bell Sys. Tech. J. %V 57 %N 6 %P 2021-2048 %D 1978 %T Typing Documents on UNIX and GCOS: The -ms Macros for Troff %A M. E. Lesk %D 1977 %A K. Thompson %A D. M. Ritchie %T U\s-2NIX\s0 Programmer's Manual %K unix %I Bell Laboratories %O Sixth Edition %D May 1975 %T The Network U\s-2NIX\s0 System %K unix %A G. L. Chesson %J Operating Systems Review %V 9 %N 5 %P 60-66 %D 1975 %O Also in \f2Proc. 5th Symp. on Operating Systems Principles.\f1 %T Spider \(em An Experimental Data Communications System %Z ctr127 %A A. G. Fraser %J Proc. IEEE Conf. on Communications %P 21F %O IEEE Cat. No. 74CH0859-9-CSCB. %D June 1974 %T A Virtual Channel Network %A A. G. Fraser %J Datamation %P 51-56 %D February 1975 .[ %r 41 %K CSTR %R Comp. Sci. Tech. Rep. No. 41 %I Bell Laboratories %C Murray Hill, New Jersey %A J. W. Hunt %A M. D. McIlroy %T An Algorithm for Differential File Comparison %D June 1976 .] %A F. P. Brooks, Jr. %T The Mythical Man-Month %I Addison-Wesley %C Reading, Mass. %D 1975 %X pwb Readable, classic reference on software engineering and problems of large projects, from someone with experience in them. Required reading for any software engineer, even if conclusions may not always be agreed with. %br "The second is the most dangerous system a man every designs." p.55. %br "Hence plan to throw one away; you will, anyhow." p.116. %br "Cosgrove has perceptively pointed out that the programmer delivers satisfaction of a user need rather than any tangible product. And both the actual need and the user's perception of that need will change as programs are built, tested, and used." p.117. %br "The total cost of maintaining a widely used program is typically 40 percent or more of the cost of developing it." p.121. %br "As shown above, amalgamating prose and program reduces the total number of characters to be stored." p.175. %T A Portable Compiler for the Language C %A A. Snyder %I Master's Thesis, M.I.T. %C Cambridge, Mass. %D 1974 %T The C Language Calling Sequence %A M. E. Lesk %A S. C. Johnson %A D. M. Ritchie %D 1977 %T Optimal Code Generation for Expression Trees %A A. V. Aho %A S. C. Johnson %D 1975 %J J. Assoc. Comp. Mach. %K acm jacm %V 23 %N 3 %P 488-501 %O Also in \f2Proc. ACM Symp. on Theory of Computing,\f1 pp. 207-217, 1975. %A R. Sethi %A J. D. Ullman %T The Generation of Optimal Code for Arithmetic Expressions %J J. Assoc. Comp. Mach. %K acm jacm %V 17 %N 4 %D October 1970 %P 715-728 %O Reprinted as pp. 229-247 in \fICompiler Techniques\fR, ed. B. W. Pollack, Auerbach, Princeton NJ (1972). %X pwb Optimal approach for straight-line, fixed number of regs. %T Code Generation for Machines with Multiregister Operations %A A. V. Aho %A S. C. Johnson %A J. D. Ullman %J Proc. 4th ACM Symp. on Principles of Programming Languages %P 21-28 %D January 1977 # Copyright(c) 1988, Sun Microsystems, Inc. # All Rights Reserved /usr/lib/refer/mkey R* | /usr/lib/refer/inv -v -h997 -n Xind mv Xind.ia Ind.ia mv Xind.ib Ind.ib mv Xind.ic Ind.ic /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1980 Regents of the University of California. * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. */ /* * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc. * All Rights Reserved. */ #include #include #include #define FLAG 003 #define AFLAG 007 #define NRFTXT 10000 #define NRFTBL 500 #define NTFILE 20 #define QLEN 512 #define ANSLEN 4000 #define TAGLEN 400 #define NSERCH 20 #define MXSIG 200 /* max bytes in aggregate signal */ extern FILE *in; extern int endpush, sort, labels, keywant, bare; extern int biblio, science, postpunct; extern char *smallcaps; extern char comname; extern char *keystr; extern char *convert; 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(); extern char *getenv(), *strcpy(), *strcat(); /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1980 Regents of the University of California. * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. */ /* * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc. * All Rights Reserved. */ #include "refer..c" FILE *in = stdin; FILE *fo = stdout; FILE *ftemp = stdout; int endpush = 0; int sort = 0; int labels = 0; int keywant = 0; int bare = 0; int biblio = 0; int science = 0; int postpunct = 0; int authrev = 0; char *smallcaps = ""; char *keystr = "AD"; char *convert = "X.AP"; 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]; char ofile[NTFILE]; char gfile[NTFILE]; char hidenam[NTFILE]; char *Ifile = "standard input"; int Iline = 0; /* * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1980 Regents of the University of California. * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. */ #include #include #include #include "refer..c" extern void clfgrep(); extern void doref(); extern void dumpold(); extern void err(); extern void output(); extern int prefix(); extern void recopy(); void cleanup(void); void signals(void); int main(int argc, char *argv[]) /* process command-line arguments */ { char line[BUFSIZ], *s; int nodeflt = 0; (void) setlocale(LC_ALL, ""); #if !defined(TEXT_DOMAIN) #define TEXT_DOMAIN "SYS_TEST" #endif (void) textdomain(TEXT_DOMAIN); signals(); while (argc > 1 && argv[1][0] == '-') { switch (argv[1][1]) { case 'e': endpush++; break; case 's': sort++; endpush = 1; if (argv[1][2]) keystr = argv[1]+2; break; case 'l': labels++; s = argv[1]+2; nmlen = atoi(s); while (*s) if (*s++ == ',') break; dtlen = atoi(s); break; case 'k': keywant = (argv[1][2] ? argv[1][2] : 'L'); labels++; break; case 'n': nodeflt = 1; break; case 'p': argc--; argv++; *search++ = argv[1]; if (search-rdata > NSERCH) err(gettext( "too many -p options (%d)"), NSERCH); break; case 'a': authrev = atoi(argv[1]+2); if (authrev <= 0) authrev = 1000; break; case 'b': bare = (argv[1][2] == '1') ? 1 : 2; break; case 'c': smallcaps = argv[1]+2; break; case 'f': refnum = atoi(argv[1]+2) - 1; break; case 'B': biblio++; bare = 2; if (argv[1][2]) convert = argv[1]+2; break; case 'S': science++; labels = 1; break; case 'P': postpunct++; break; } argc--; argv++; } if (getenv("REFER") != NULL) *search++ = getenv("REFER"); else if (nodeflt == 0) *search++ = "/usr/lib/refer/papers/Ind"; if (sort && !labels) { sprintf(ofile, "/tmp/rj%db", getpid()); ftemp = fopen(ofile, "w"); if (ftemp == NULL) { fprintf(stderr, gettext("Can't open scratch file\n")); exit(1); } } if (endpush) { sprintf(tfile, "/tmp/rj%da", getpid()); fo = fopen(tfile, "w"); if (fo == NULL) { fo = ftemp; fprintf(stderr, gettext("Can't open scratch file")); } sep = 002; /* separate records without confusing sort.. */ } else fo = ftemp; do { if (argc > 1) { fclose(in); Iline = 0; in = fopen(Ifile = argv[1], "r"); argc--; argv++; if (in == NULL) { err(gettext("Can't read %s"), Ifile); continue; } } while (input(line)) { Iline++; if (biblio && *line == '\n') doref(line); else if (biblio && Iline == 1 && *line == '%') doref(line); else if (!prefix(".[", line)) output(line); else doref(line); } } while (argc > 1); if (endpush && fo != NULL) dumpold(); output(""); if (sort && !labels) recopy(ofile); clfgrep(); cleanup(); return (0); } extern void intr(); void signals(void) { if (signal(SIGINT, SIG_IGN) != SIG_IGN) signal(SIGINT, intr); signal(SIGHUP, intr); signal(SIGPIPE, intr); signal(SIGTERM, intr); } void intr(void) { signal(SIGINT, SIG_IGN); cleanup(); exit(1); } void cleanup(void) { if (tfile[0]) unlink(tfile); if (gfile[0]) unlink(gfile); if (ofile[0]) unlink(ofile); if (hidenam[0]) unlink(hidenam); } /* * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1980 Regents of the University of California. * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. */ #include "refer..c" #include #define NFLD 30 #define TLEN 512 extern FILE *in; char one[ANSLEN]; int onelen = ANSLEN; static char dr [100] = ""; extern int prefix(); extern int common(); extern void dumpold(); extern void putref(); extern void flout(); extern int tabs(); extern int chkdup(); extern void putsig(); extern void putkey(); extern void err(); extern int corout(); void choices(char *); int control(char); static int newline(char *); void doref(char *line1) { char buff[QLEN], dbuff[3*QLEN]; char answer[ANSLEN], temp[TLEN], line[BUFSIZ]; char *p, **sr, *flds[NFLD], *r; int stat, nf, nr, query = 0, alph, digs; again: buff[0] = dbuff[0] = '\0'; if (biblio && Iline == 1 && line1[0] == '%') strcat(dbuff, line1); while (input(line)) { /* get query */ Iline++; if (prefix(".]", line)) break; if (biblio && line[0] == '\n') break; if (biblio && line[0] == '%' && line[1] == *convert) break; if (control(line[0])) query = 1; strcat(query ? dbuff : buff, line); if (strlen(buff) > QLEN) err(gettext("query too long (%d)"), strlen(buff)); if (strlen(dbuff) > 3 * QLEN) err(gettext("record at line %d too long"), Iline-1); } if (biblio && line[0] == '\n' && feof(in)) return; if (strcmp(buff, "$LIST$\n") == 0) { assert(dbuff[0] == 0); dumpold(); return; } answer[0] = 0; for (p = buff; *p; p++) { if (isupper(*p)) *p |= 040; } alph = digs = 0; for (p = buff; *p; p++) { if (isalpha(*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 (digs != 4 || atoi(r)/100 != 19) { while (r < p) *r++ = ' '; } } *p = ' '; alph = digs = 0; } } one[0] = 0; if (buff[0]) { /* do not search if no query */ for (sr = rdata; sr < search; sr++) { temp[0] = 0; corout(buff, temp, "hunt", *sr, TLEN); assert(strlen(temp) < TLEN); if (strlen(temp)+strlen(answer) > BUFSIZ) err(gettext( "Accumulated answers too large"), 0); strcat(answer, temp); if (strlen(answer) > BUFSIZ) err(gettext("answer too long (%d)"), strlen(answer)); if (newline(answer) > 0) break; } } assert(strlen(one) < ANSLEN); assert(strlen(answer) < ANSLEN); if (buff[0]) switch (newline(answer)) { case 0: fprintf(stderr, gettext("No such paper: %s\n"), buff); return; default: fprintf(stderr, gettext( "Too many hits: %s\n"), trimnl(buff)); choices(answer); p = buff; while (*p != '\n') p++; *++p = 0; /* FALLTHROUGH */ case 1: if (endpush) if (nr = chkdup(answer)) { if (bare < 2) { nf = tabs(flds, one); nf += tabs(flds+nf, dbuff); assert(nf < NFLD); putsig(nf, flds, nr, line1, line, 0); } return; } if (one[0] == 0) corout(answer, one, "deliv", dr, QLEN); break; } assert(strlen(buff) < QLEN); assert(strlen(one) < ANSLEN); nf = tabs(flds, one); nf += tabs(flds+nf, dbuff); assert(nf < NFLD); refnum++; if (sort) putkey(nf, flds, refnum, keystr); if (bare < 2) putsig(nf, flds, refnum, line1, line, 1); else flout(); putref(nf, flds); if (biblio && line[0] == '\n') goto again; if (biblio && line[0] == '%' && line[1] == *convert) fprintf(fo, "%s%c%s", convert+1, sep, line+3); } static int newline(char *s) { int k = 0, c; while (c = *s++) if (c == '\n') k++; return (k); } void choices(char *buff) { char ob[BUFSIZ], *p, *r, *q, *t; int nl; for (r = p = buff; *p; p++) { if (*p == '\n') { *p++ = 0; corout(r, ob, "deliv", dr, BUFSIZ); 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, gettext("??? at %s\n"), r); r = p; } } } int control(char c) { if (c == '.') return (1); if (c == '%') return (1); return (0); } /* * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1980 Regents of the University of California. * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. */ #include "refer..c" #define move(x, y) close(y); dup(x); close(x); extern void err(); int corout(char *in, char *out, char *rprog, char *arg, int outlen) { int pipev[2], fr1, fr2, fw1, fw2, n; int status; 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(&status); n = read(fr2, out, outlen); out[n] = 0; close(fr2); return (n); } /* * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1980 Regents of the University of California. * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. */ #include "refer..c" #include #define punctuat(c) (c == '.' || c == '?' || c == '!' || \ c == ',' || c == ';' || c == ':') static int gate = 0; static char buff[BUFSIZ]; extern void err(); char *trimnl(char *); void output(char *s) { if (gate) fputs(buff, ftemp); else gate = 1; strcpy(buff, s); if (strlen(buff) > BUFSIZ) err(gettext("one buff too big (%d)!"), BUFSIZ); } void append(char *s) { char *p; int lch; trimnl(buff); for (p = buff; *p; p++) ; lch = *--p; if (postpunct && punctuat(lch)) *p = '\0'; else /* pre-punctuation */ switch (lch) { case '.': case '?': case '!': case ',': case ';': case ':': *p++ = lch; *p = '\0'; } strcat(buff, s); if (postpunct) switch (lch) { case '.': case '?': case '!': case ',': case ';': case ':': for (p = buff; *p; p++) ; if (*--p == '\n') *p = '\0'; *p++ = lch; *p++ = '\n'; *p = '\0'; } if (strlen(buff) > BUFSIZ) err(gettext("output buff too long (%d)"), BUFSIZ); } void flout(void) { if (gate) fputs(buff, ftemp); gate = 0; } char * trimnl(char *ln) { char *p = ln; while (*p) p++; p--; if (*p == '\n') *p = 0; return (ln); } /* * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1980 Regents of the University of California. * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. */ #include "refer..c" #define SAME 0 #define NFLAB 3000 /* number of bytes to record all labels */ #define NLABC 1000 /* max number of labels */ static char sig[MXSIG]; static char bflab[NFLAB]; static char *labtab[NLABC]; static char *lbp = bflab; static char labc[NLABC]; static char stbuff[50]; static int prevsig; extern void addch(); extern void append(); extern void err(); extern void flout(); extern int prefix(); char keylet(char *, int); static void initadd(char *, char *, char *); static void mycpy(char *, char *); static void mycpy2(char *, char *, int); void tokeytab(char *, int); /* choose signal style */ void putsig(int nf, char *flds[], int nref, char *nstline, char *endline, int toindex) { char t[100], t1[MXSIG], t2[100], format[10], *sd, *stline; int addon, another = 0; static FILE *fhide = 0; int i; char tag; if (labels) { if (nf == 0) /* old */ sprintf(t, "%s%c", labtab[nref], labc[nref]); else { *t = 0; if (keywant) fpar(nf, flds, t, keywant, 1, 0); if (science && t[0] == 0) { if (fpar(nf, flds, t, 'A', 1, 0) != 0) { if (fpar(nf, flds, t2, 'D', 1, 0) != 0) { strcat(t, ", "); strcat(t, t2); } } } else if (t[0] == 0) { sprintf(format, nmlen > 0 ? "%%.%ds%%s" : "%%s%%s", nmlen); /* format is %s%s for default labels */ /* or %.3s%s eg if wanted */ if (fpar(nf, flds, t2, 'D', 1, 0)) { sd = t2; if (dtlen > 0) { int n = strlen(sd) - dtlen; if (n > 0) sd += n; } } else { sd = ""; } t1[0] = 0; fpar(nf, flds, t1, 'A', 1, 0); sprintf(t, format, t1, sd); } if (keywant) { addon = 0; for (sd = t; *sd; sd++) ; if (*--sd == '-') { addon = 1; *sd = 0; } } if ((!keywant || addon) && !science) { addch(t, keylet(t, nref)); } else { tokeytab(t, nref); } } } else { if (sort) sprintf(t, "%c%d%c", FLAG, nref, FLAG); else sprintf(t, "%d", nref); } another = (sd = lookat()) ? prefix(".[", sd) : 0; if (another && (strcmp(".[\n", sd) != SAME)) fprintf(stderr, (char *)gettext( "File %s line %d: punctuation ignored from: %s"), Ifile, Iline, sd); if ((strlen(sig) + strlen(t)) > MXSIG) err(gettext("sig overflow (%d)"), MXSIG); strcat(sig, t); #if EBUG fprintf(stderr, "sig is now %s leng %d\n", sig, strlen(sig)); #endif trimnl(nstline); trimnl(endline); stline = stbuff; if (prevsig == 0) { strcpy(stline, nstline); prevsig = 1; } if (stline[2] || endline[2]) { stline += 2; endline += 2; } else { stline = "\\*([."; endline = "\\*(.]"; } if (science) { stline = " ("; endline = ")"; } if (bare == 0) { if (!another) { sprintf(t1, "%s%s%s\n", stline, sig, endline); if (strlen(t1) > MXSIG) err(gettext("t1 overflow (%d)"), MXSIG); append(t1); flout(); sig[0] = 0; prevsig = 0; if (fo == fhide) { int ch; fclose(fhide); fhide = fopen(hidenam, "r"); fo = ftemp; while ((ch = getc(fhide)) != EOF) putc(ch, fo); fclose(fhide); unlink(hidenam); } } else { if (labels) { strcat(sig, ",\\|"); } else { /* * Seperate reference numbers with AFLAG * for later sorting and condensing. */ t1[0] = AFLAG; t1[1] = '\0'; strcat(sig, t1); } if (fo == ftemp) { /* hide if need be */ sprintf(hidenam, "/tmp/rj%dc", getpid()); #if EBUG fprintf(stderr, "hiding in %s\n", hidenam); #endif fhide = fopen(hidenam, "w"); if (fhide == NULL) err(gettext( "Can't get scratch file %s"), hidenam); fo = fhide; } } } if (bare < 2) if (nf > 0 && toindex) fprintf(fo, ".ds [F %s%c", t, sep); if (bare > 0) flout(); #if EBUG fprintf(stderr, "sig is now %s\n", sig); #endif } char * fpar(int nf, char *flds[], char *out, int c, int seq, int prepend) { char *p, *s; int i, fnd = 0; for (i = 0; i < nf; i++) if (flds[i][1] == c && ++fnd >= seq) { /* for titles use first word otherwise last */ if (c == 'T' || c == 'J') { p = flds[i]+3; if (prefix("A ", p)) p += 2; if (prefix("An ", p)) p += 3; if (prefix("The ", p)) p += 4; mycpy2(out, p, 20); return (out); } /* if its not 'L' then use just the last word */ s = p = flds[i]+2; if (c != 'L') { for (; *p; p++) ; while (p > s && *p != ' ') p--; } /* special wart for authors */ if (c == 'A' && (p[-1] == ',' || p[1] == '(')) { p--; while (p > s && *p != ' ') p--; mycpy(out, p+1); } else strcpy(out, p+1); if (c == 'A' && prepend) initadd(out, flds[i]+2, p); return (out); } return (0); } void putkey(int nf, char *flds[], int nref, char *keystr) { char t1[50], *sf; int ctype, i, count; fprintf(fo, ".\\\""); if (nf <= 0) fprintf(fo, "%s%c%c", labtab[nref], labc[nref], sep); else { while (ctype = *keystr++) { count = atoi(keystr); if (*keystr == '+') count = 999; if (count <= 0) count = 1; for (i = 1; i <= count; i++) { sf = fpar(nf, flds, t1, ctype, i, 1); if (sf == 0) break; sf = artskp(sf); fprintf(fo, "%s%c", sf, '-'); } } fprintf(fo, "%c%d%c%c", FLAG, nref, FLAG, sep); } } void tokeytab(char *t, int nref) { strcpy(labtab[nref] = lbp, t); while (*lbp++) ; } char keylet(char *t, int nref) { int i; int x = 'a' - 1; for (i = 1; i < nref; i++) { if (strcmp(labtab[i], t) == 0) x = labc[i]; } tokeytab(t, nref); if (lbp-bflab > NFLAB) err(gettext("bflab overflow (%d)"), NFLAB); if (nref > NLABC) err(gettext("nref in labc overflow (%d)"), NLABC); #if EBUG fprintf(stderr, "lbp up to %d of %d\n", lbp-bflab, NFLAB); #endif return (labc[nref] = x+1); } static void mycpy(char *s, char *t) { while (*t && *t != ',' && *t != ' ') *s++ = *t++; *s = 0; } static void mycpy2(char *s, char *t, int n) { int c; while (n-- && (c = *t++) > 0) { if (c == ' ') c = '-'; *s++ = c; } *s = 0; } static void initadd(char *to, char *from, char *stop) { int c, nalph = 1; while (*to) to++; while (from < stop) { c = *from++; if (!isalpha(c)) { if (nalph) *to++ = '.'; nalph = 0; continue; } if (nalph++ == 0) *to++ = c; } *to = 0; } static char *articles[] = { "the ", "an ", "a ", 0 }; char * artskp(s) /* skips over initial "a ", "an ", "the " in s */ char *s; { char **p, *r1, *r2; for (p = articles; *p; p++) { r2 = s; for (r1 = *p; ((*r1 ^ *r2) & ~040) == 0; r1++) r2++; if (*r1 == 0 && *r2 != 0) return (r2); } return (s); } /* * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1980 Regents of the University of California. * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. */ #include "refer..c" #define dsde (macro? "de" : "ds") #define ifnl (macro? sep : ' ') extern int control(); extern char *mindex(); int hastype(int, char *[], char); static char last(char *); char *class(int, char *[]); char *caps(char *, char *); char *revauth(char *, char *); void putref(int n, char *tvec[]) { char *s, *tx; char buf1[BUFSIZ], buf2[50]; int nauth = 0, i, lastype = 0, cch, macro = 0, la; int lauth = 0, ltitle = 0, lother = 0; fprintf(fo, ".]-%c", 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 EBUG fprintf(stderr, "smallcaps %s cch %c\n", smallcaps, cch); #endif if (mindex(smallcaps, cch)) tx = caps(tx, buf1); #if EBUG 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 (cch == 'O') lother = (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, ".nr [O %d%c", lother, sep); fprintf(fo, ".][ %s%c", class(n, tvec), '\n'); } int tabs(char *sv[], char *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(int nt, 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"); } int hastype(int nt, char *tv[], char c) { int i; for (i = 0; i < nt; i++) if (control(tv[i][0]) && tv[i][1] == c) return (1); return (0); } char * caps(char *a, char *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(char *s, char *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); } static char last(char *s) { while (*s) s++; return (*--s); } /* * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1980 Regents of the University of California. * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. */ #include "refer..c" #include int newr[250]; extern void err(); extern void flout(); static void condense(int *, int, char *); int chkdup(char *tag) { int i; for (i = 1; i <= refnum; i++) { if (reftable[i] && strcmp(reftable[i], tag) == 0) return (i); } reftable[refnum+1] = rtp; if (refnum >= NRFTBL) err(gettext("too many references (%d) for table"), refnum); strcpy(rtp, tag); while (*rtp++) ; if (rtp > reftext + NRFTXT) err(gettext("reference pointers too long (%d)"), rtp-reftext); return (0); } void dumpold(void) { FILE *fi; int c, g1 = 0, nr = 1; if (!endpush) return; fclose(fo); fo = NULL; if (sort) { char comm[100]; sprintf(comm, "sort -f %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 EBUG 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 TF unlink(tfile); #endif fprintf(ftemp, ".]>\n"); } void recopy(char *fnam) { int c; int *wref = NULL; int wcnt = 0; int wsize = 50; int finalrn; char sig[MXSIG]; extern int *realloc(); wref = (int *)calloc((unsigned)wsize, (unsigned)sizeof (int)); fclose(ftemp); ftemp = fopen(fnam, "r"); if (ftemp == NULL) { fprintf(stderr, gettext("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; /* * If sort was done, permute the reference number * to obtain the final reference number, finalrn. */ if (sort) finalrn = newr[atoi(tb)]; else finalrn = atoi(tb); if ((++wcnt > wsize) && ((wref = realloc(wref, (wsize += 50) * sizeof (int))) == NULL)) { fprintf(stderr, gettext( "Ref condense out of memory.")); exit(1); } wref[wcnt-1] = finalrn; if ((c = getc(ftemp)) == AFLAG) continue; wref[wcnt] = 0; condense(wref, wcnt, sig); wcnt = 0; printf("%s", sig); } putchar(c); } fclose(ftemp); unlink(fnam); } /* * sort and condense reference signals when they are placed in * the text. Viz, the signal 1,2,3,4 is condensed to 1-4 and signals * of the form 5,2,9 are converted to 2,5,9 */ static void condense(int *wref, int wcnt, char *sig) { int i = 0; char wt[4]; extern int wswap(); qsort(wref, wcnt, sizeof (int), wswap); sig[0] = 0; while (i < wcnt) { sprintf(wt, "%d", wref[i]); strcat(sig, wt); if ((i+2 < wcnt) && (wref[i] == (wref[i+2] - 2))) { while (wref[i] == (wref[i+1] - 1)) i++; strcat(sig, "-"); } else if (++i < wcnt) strcat(sig, ",\\|"); } } int wswap(int *iw1, int *iw2) { return (*iw1 - *iw2); } /* * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1980 Regents of the University of California. * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. */ #include "refer..c" static char ahead[1024]; static int peeked = 0; static char *noteof = (char *)1; char * input(char *s) { if (peeked) { peeked = 0; if (noteof == 0) return (0); strcpy(s, ahead); return (s); } return (fgets(s, 1000, in)); } char * lookat(void) { if (peeked) return (ahead); noteof = input(ahead); peeked = 1; return (noteof); } void addch(char *s, char c) { while (*s) s++; *s++ = c; *s = 0; } #!/usr/bin/sh # Copyright 1988 Sun Microsystems, Inc. All Rights Reserved. # Use is subject to license terms. # Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T # All Rights Reserved # Copyright (c) 1980 Regents of the University of California. # All rights reserved. The Berkeley software License Agreement # specifies the terms and conditions for redistribution. # # roffbib sh script # flags= abstr= headr=BIBLIOGRAPHY xroff=/usr/bin/nroff macro=-mbib for i do case $1 in -[onsrT]*|-[qeh]) flags="$flags $1" shift ;; -x) abstr="X.ig ]-" shift ;; -m) shift macro="-m$1" shift ;; -Q) xroff="/usr/bin/troff" shift ;; -H) shift headr="$1" shift ;; -*) echo "roffbib: unknown flag: $1" shift esac done if test $1 then (echo .ds TL $headr; /usr/bin/refer -a1 -B"$abstr" $*) | \ $xroff $flags $macro else (echo .ds TL $headr; /usr/bin/refer -a1 -B"$abstr") | $xroff $flags $macro fi /* * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1980 Regents of the University of California. * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. */ /* * SORTS UP. * IF THERE ARE NO EXCHANGES (IEX=0) ON A SWEEP * THE COMPARISON GAP (IGAP) IS HALVED FOR THE NEXT SWEEP */ void shell(int n, int (*comp)(), int (*exch)()) { 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) ; } } /* * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1980 Regents of the University of California. * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. */ #include #include #include #include #define BUF BUFSIZ #define MXFILES 16 char tempfile[32]; /* temporary file for sorting keys */ int tmpfd = -1; char *keystr = "AD"; /* default sorting on author and date */ int multauth = 0; /* by default sort on senior author only */ int oneauth; /* has there been author in the record? */ static int article(char *); static void deliver(FILE *[], FILE *); static int endcomma(char *); static void error(char *); static void eval(char []); static void parse(char [], char fld[][BUF]); static void sortbib(FILE *, FILE *, int); static void onintr(void); /* sortbib: sort bibliographic database in place */ int main(int argc, char *argv[]) { FILE *fp[MXFILES], *tfp; int i; (void) setlocale(LC_ALL, ""); #if !defined(TEXT_DOMAIN) #define TEXT_DOMAIN "SYS_TEST" #endif (void) textdomain(TEXT_DOMAIN); if (argc == 1) { /* can't use stdin for seeking anyway */ puts(gettext("Usage: sortbib [-sKEYS] database [...]\n\ \t-s: sort by fields in KEYS (default is AD)")); exit(1); } if (argc > 2 && argv[1][0] == '-' && argv[1][1] == 's') { /* if a key is specified use it, otherwise use default key */ if (argv[1][2] != '\0') keystr = argv[1] + 2; eval(keystr); /* evaluate A+ for multiple authors */ argv++; argc--; } if (argc > MXFILES+1) { /* too many open file streams */ fprintf(stderr, gettext("sortbib: More than %d databases specified\n"), MXFILES); exit(1); } for (i = 1; i < argc; i++) /* open files in arg list */ if ((fp[i-1] = fopen(argv[i], "r")) == NULL) error(argv[i]); strcpy(tempfile, "/tmp/SbibXXXXXX"); /* tempfile for sorting keys */ if ((tmpfd = mkstemp(tempfile)) == -1) error(tempfile); (void) close(tmpfd); if (signal(SIGINT, SIG_IGN) != SIG_IGN) /* remove if interrupted */ signal(SIGINT, (void(*)())onintr); if ((tfp = fopen(tempfile, "w")) == NULL) { (void) unlink(tempfile); error(tempfile); } for (i = 0; i < argc-1; i++) /* read keys from bib files */ sortbib(fp[i], tfp, i); fclose(tfp); deliver(fp, tfp); /* do disk seeks and read from biblio files */ (void) unlink(tempfile); return (0); } int rsmode = 0; /* record separator: 1 = null line, 2 = bracket */ /* read records, prepare list for sorting */ static void sortbib(FILE *fp, FILE *tfp, int i) { long offset, lastoffset = 0, ftell(); /* byte offsets in file */ int length, newrec, recno = 0; /* reclen, new rec'd?, number */ char line[BUF], fld[4][BUF]; /* one line, the sort fields */ /* measure byte offset, then get new line */ while (offset = ftell(fp), fgets(line, BUF, fp)) { if (recno == 0) /* accept record w/o initial newline */ newrec = 1; if (line[0] == '\n') { /* accept null line record separator */ if (!rsmode) rsmode = 1; /* null line mode */ if (rsmode == 1) newrec = 1; } if (line[0] == '.' && line[1] == '[') { /* also accept .[ .] */ if (!rsmode) rsmode = 2; /* bracket pair mode */ if (rsmode == 2) newrec = 1; } if (newrec) { /* by whatever means above */ newrec = 0; length = offset - lastoffset; /* measure rec len */ if (length > BUF*8) { fprintf(stderr, gettext("sortbib: record %d longer than %d " "(%d)\n"), recno, BUF*8, length); (void) unlink(tempfile); exit(1); } if (recno++) { /* info for sorting */ fprintf(tfp, "%d %d %d : %s %s %s %s\n", i, lastoffset, length, fld[0], fld[1], fld[2], fld[3]); if (ferror(tfp)) { (void) unlink(tempfile); error(tempfile); } } *fld[0] = *fld[1] = *fld[2] = *fld[3] = '\0'; oneauth = 0; /* reset number of authors */ lastoffset = offset; /* save for next time */ } if (line[0] == '%') /* parse out fields to be sorted */ parse(line, fld); } offset = ftell(fp); /* measure byte offset at EOF */ length = offset - lastoffset; /* measure final record length */ if (length > BUF*8) { fprintf(stderr, gettext("sortbib: record %d longer than %d (%d)\n"), recno, BUF*8, length); (void) unlink(tempfile); exit(1); } if (line[0] != '\n') { /* ignore null line just before EOF */ fprintf(tfp, "%d %d %d : %s %s %s %s\n", i, lastoffset, length, fld[0], fld[1], fld[2], fld[3]); if (ferror(tfp)) { (void) unlink(tempfile); error(tempfile); /* disk error in /tmp */ } } } /* deliver sorted entries out of database(s) */ static void deliver(FILE *fp[], FILE *tfp) { char str[BUF], buff[BUF*8]; /* for tempfile & databases */ char cmd[80]; /* for using system sort command */ long int offset; int i, length; /* when sorting, ignore case distinctions; tab char is ':' */ sprintf(cmd, "sort +4f +0n +1n %s -o %s", tempfile, tempfile); if (system(cmd) == 127) { (void) unlink(tempfile); error("sortbib"); } tfp = fopen(tempfile, "r"); while (fgets(str, sizeof (str), tfp)) { /* get file pointer, record offset, and length */ if (sscanf(str, "%d %d %d :", &i, &offset, &length) != 3) error(gettext("sortbib: sorting error")); /* seek to proper disk location in proper file */ if (fseek(fp[i], offset, 0) == -1) { (void) unlink(tempfile); error("sortbib"); } /* read exactly one record from bibliography */ if (fread(buff, sizeof (*buff), length, fp[i]) == 0) { (void) unlink(tempfile); error("sortbib"); } /* add newline between unseparated records */ if (buff[0] != '\n' && rsmode == 1) putchar('\n'); /* write record buffer to standard output */ if (fwrite(buff, sizeof (*buff), length, stdout) == 0) { (void) unlink(tempfile); error("sortbib"); } } } /* get fields out of line, prepare for sorting */ static void parse(char line[], char fld[][BUF]) { char wd[8][BUF/4], *strcat(); int n, i, j; for (i = 0; i < 8; i++) /* zap out old strings */ *wd[i] = '\0'; n = sscanf(line, "%s %s %s %s %s %s %s %s", wd[0], wd[1], wd[2], wd[3], wd[4], wd[5], wd[6], wd[7]); for (i = 0; i < 4; i++) { if (wd[0][1] == keystr[i]) { if (wd[0][1] == 'A') { if (oneauth && !multauth) /* no repeat */ break; else if (oneauth) /* mult auths */ strcat(fld[i], "~~"); if (!endcomma(wd[n-2])) /* surname */ strcat(fld[i], wd[n-1]); else { /* jr. or ed. */ strcat(fld[i], wd[n-2]); n--; } strcat(fld[i], " "); for (j = 1; j < n-1; j++) strcat(fld[i], wd[j]); oneauth = 1; } else if (wd[0][1] == 'D') { strcat(fld[i], wd[n-1]); /* year */ if (n > 2) strcat(fld[i], wd[1]); /* month */ } else if (wd[0][1] == 'T' || wd[0][1] == 'J') { j = 1; if (article(wd[1])) /* skip article */ j++; for (; j < n; j++) strcat(fld[i], wd[j]); } else /* any other field */ for (j = 1; j < n; j++) strcat(fld[i], wd[j]); } /* %Q quorporate or queer author - unreversed %A */ else if (wd[0][1] == 'Q' && keystr[i] == 'A') for (j = 1; j < n; j++) strcat(fld[i], wd[j]); } } /* see if string contains an article */ static int article(char *str) { if (strcmp("The", str) == 0) /* English */ return (1); if (strcmp("A", str) == 0) return (1); if (strcmp("An", str) == 0) return (1); if (strcmp("Le", str) == 0) /* French */ return (1); if (strcmp("La", str) == 0) return (1); if (strcmp("Der", str) == 0) /* German */ return (1); if (strcmp("Die", str) == 0) return (1); if (strcmp("Das", str) == 0) return (1); if (strcmp("El", str) == 0) /* Spanish */ return (1); if (strcmp("Den", str) == 0) /* Scandinavian */ return (1); return (0); } /* evaluate key string for A+ marking */ static void eval(char keystr[]) { int i, j; for (i = 0, j = 0; keystr[i]; i++, j++) { if (keystr[i] == '+') { multauth = 1; i++; } if (keystr[i] == '\0') break; keystr[j] = keystr[i]; } keystr[j] = '\0'; } /* exit in case of various system errors */ static void error(char *s) { perror(s); exit(1); } /* remove tempfile in case of interrupt */ static void onintr(void) { fprintf(stderr, gettext("\nInterrupt\n")); unlink(tempfile); exit(1); } static int endcomma(char *str) { int n; n = strlen(str) - 1; if (str[n] == ',') { str[n] = '\0'; return (1); } return (0); } /* * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1980 Regents of the University of California. * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. */ /* time programs */ #include #include struct tbuffer { long proc_user_time; long proc_system_time; long child_user_time; long child_system_time; }; static long start, user, systm; void tick(void) { struct tbuffer tx; time_t tp; times(&tx); time(&tp); user = tx.proc_user_time; systm = tx.proc_system_time; start = tp; } void tock(void) { struct tbuffer tx; time_t tp; float lap, use, sys; if (start == 0) return; times(&tx); time(&tp); lap = (tp - start)/60.; use = (tx.proc_user_time - user)/60.; sys = (tx.proc_system_time - systm)/60.; printf("Elapsed %.2f CPU %.2f (user %.2f, sys %.2f)\n", lap, use+sys, use, sys); } '\" Copyright 1990 Sun Microsystems, Inc. All rights reserved. '\" Use is subject to license terms. '\" '\" Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T '\" All rights reserved. '\" '\" Portions of this source code were derived from Berkeley 4.3 BSD '\" under license from the Regents of the University of California. '\" '\"#ident "%Z%%M% %I% %E% SMI" '\" .ds TL BIBLIOGRAPHY . \" HD - header macro .de HD .nr PN \\n% 'sp |.5i-1 .if \\n%>1 .tl ''- \\n(PN -'' 'sp |1i .ps .ft .vs .ns .. . \" FT - footer macro .de FT .ps 10 .ft 1 .vs 12p 'bp .. .so /usr/share/lib/tmac/ms.acc .wh 0 HD .wh -1i FT .if n .na .if n .nr PD 1v .if t .nr PD .5v .nr PI 5n . \" RT - reset everything to normal state .de RT .in 0 .ce 0 .ul 0 .ft 1 .ta 5n 10n 15n 20n 25n 30n 35n 40n 45n 50n 55n 60n 65n 70n 75n 80n .fi .. . \" XP - exdented paragraph .de XP .if \\nV=1 .ls 2 .RT .ne 3.1 .sp \\n(PDu .in +\\n(PIu .ti -\\n(PIu .. . \" AP - annotation paragraph .de AP .if \\nV=1 .ls 1 .RT .ne 1.1 .sp \\n(PDu .in +\\n(PIu .. . \" NP - numbered paragraph .de NP .if \\nV=1 .ls 2 .RT .ne 3.1 .sp \\n(PDu .in +\\n(PIu .ti -\\n(PIu .ta \\n(PIu \\n+#.\t\c .. . \" refer macros for citations .de [] .][ \\$1 .. .de ][ .if \\$1>4 .tm %M (Bell Labs Memorandum) undefined .[\\$1 .. .if n .ds [o \&" .if n .ds [c \&" .if t .ds [o `` .if t .ds [c '' . \" [0 - other type of citation .de [0 .XP .nr [: 0 .if !\\*([Q \{\ .nr [: 1 \\*([Q\c .\} .if !\\*([A \{\ .nr [: 1 \\*([A\c .\} .if !\\*([T \{\ .if \\n([:>0 , .nr [: 1 \f2\\*([T\f1\c .\} .if !\\*([S , \\*([S\c .if !\\*([V , \\*([V\c .if !\\*([P \{\ .ie \\n([P>0 , pp. \\*([P\c .el , p. \\*([P\c .\} .if !\\*([C , \\*([C\c .if !\\*([D , \\*([D\c .if \\n([:>0 \&. .if !\\*([O \\*([O .. . \" [1 - journal article .de [1 .XP .if !\\*([Q \\*([Q, .if !\\*([A \\*([A, .if !\\*([T \\*([o\\*([T,\\*([c \f2\\*([J\f1\c .if !\\*([V , vol. \\*([V\c .if !\\*([N , no. \\*([N\c .if !\\*([P \{\ .ie \\n([P>0 , pp. \\*([P\c .el , p. \\*([P\c .\} .if !\\*([I , \\*([I\c .if !\\*([C , \\*([C\c .if !\\*([D , \\*([D\c \&. .if !\\*([O \\*([O .. . \" [2 - book .de [2 .XP .if !\\*([Q \\*([Q, .if !\\*([A \\*([A, .if !\\*([T \f2\\*([T,\f1 .if !\\*([S \\*([S, .if !\\*([V \\*([V, .if !\\*([P \{\ .ie \\n([P>0 pp. \\*([P, .el p. \\*([P, .\} \\*([I\c .if !\\*([C , \\*([C\c .if !\\*([D , \\*([D\c \&. .if !\\*([O \\*([O .. . \" [3 - article in book .de [3 .XP .if !\\*([Q \\*([Q, .if !\\*([A \\*([A, .if !\\*([T \\*([o\\*([T,\\*([c in \f2\\*([B\f1\c .if !\\*([E , ed. \\*([E\c .if !\\*([S , \\*([S\c .if !\\*([V , vol. \\*([V\c .if !\\*([P \{\ .ie \\n([P>0 , pp. \\*([P\c .el , p. \\*([P\c .\} .if !\\*([I , \\*([I\c .if !\\*([C , \\*([C\c .if !\\*([D , \\*([D\c \&. .if !\\*([O \\*([O .. . \" [4 - report .de [4 .XP .if !\\*([Q \\*([Q, .if !\\*([A \\*([A, .if !\\*([T \\*([o\\*([T,\\*([c .if !\\*([R \\*([R\c .if !\\*([G \& (\\*([G)\c .if !\\*([P \{\ .ie \\n([P>0 , pp. \\*([P\c .el , p. \\*([P\c .\} .if !\\*([I , \\*([I\c .if !\\*([C , \\*([C\c .if !\\*([D , \\*([D\c \&. .if !\\*([O \\*([O .. .de ]< .[< .. .de [< .SH References .LP .rm FS FE .. .de [> .]> .. .de ]> .sp .. .de ]- .[- .. .de [- .if !\\n(TL \{\ . br \" pseudo-page break . ce \f2\\*(TL\f1 . sp 2 . nr TL 1 .\} .rm [Q [A [T [J [B [E [S [V .rm [N [P [I [C [D [O [R [G .. . \" command-line registers .if \nN .nr # \nN-1 1 .if \nN .rn NP XP .if \nV .ls \nV .if \nL .ll \nLu .if \nO .po \nOu