diff options
Diffstat (limited to 'usr/src')
36 files changed, 1985 insertions, 1974 deletions
diff --git a/usr/src/cmd/refer/Makefile b/usr/src/cmd/refer/Makefile index 68e3a629f5..0a838b040b 100644 --- a/usr/src/cmd/refer/Makefile +++ b/usr/src/cmd/refer/Makefile @@ -20,7 +20,7 @@ # CDDL HEADER END # # -# Copyright 2004 Sun Microsystems, Inc. All rights reserved. +# Copyright 2005 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "%Z%%M% %I% %E% SMI" @@ -37,7 +37,7 @@ 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 hunt9.o inv1.o inv2.o inv3.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 \ @@ -75,12 +75,12 @@ 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 hunt9.o shell.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 hunt9.o glue2.o glue4.o \ + glue3.o hunt7.o glue2.o glue4.o \ glue5.o refer0.o shell.o addbib:= POBJS= addbib.o lookbib:= POBJS= lookbib.o @@ -122,12 +122,12 @@ 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 hunt9.c shell.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 hunt9.c glue2.c glue4.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) diff --git a/usr/src/cmd/refer/addbib.c b/usr/src/cmd/refer/addbib.c index fd4fb959c6..99570efce7 100644 --- a/usr/src/cmd/refer/addbib.c +++ b/usr/src/cmd/refer/addbib.c @@ -1,26 +1,25 @@ +/* + * 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. */ -/* - * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc. - * All Rights Reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" +#pragma ident "%Z%%M% %I% %E% SMI" #include <locale.h> #include <stdio.h> #include <ctype.h> #include <signal.h> -#define MAXENT 50 +#define MAXENT 50 struct skeleton { char prompt[20]; /* prompt user for entry */ @@ -40,7 +39,14 @@ struct skeleton { int entries = 10; /* total number of entries in bibskel */ int abstract = 1; /* asking for abstracts is the default */ -usage() /* print proper usage and exit */ +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\ @@ -48,9 +54,8 @@ usage() /* print proper usage and exit */ exit(1); } -main(argc, argv) /* addbib: bibliography entry program */ -int argc; -char *argv[]; +int +main(int argc, char *argv[]) /* addbib: bibliography entry program */ { FILE *fp, *fopen(); int i; @@ -58,59 +63,50 @@ char *argv[]; (void) setlocale(LC_ALL, ""); #if !defined(TEXT_DOMAIN) -#define TEXT_DOMAIN "SYS_TEST" +#define TEXT_DOMAIN "SYS_TEST" #endif (void) textdomain(TEXT_DOMAIN); - if (argc == 1) - { - puts(gettext("You must specify a bibliography file (database).")); + 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.")); + 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.")); + } 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]); + } else { /* neither -p nor -a */ + printf(gettext( + "Invalid command line flag: %s\n"), argv[i]); usage(); } } - if (i < argc - 1) - { + if (i < argc - 1) { puts(gettext("Too many arguments with no options.")); usage(); } - if ((fp = fopen(argv[i], "a")) == NULL) - { + if ((fp = fopen(argv[i], "a")) == NULL) { perror(argv[i]); exit(1); } addbib(fp, argv[i]); /* loop for input */ - exit(0); - /* NOTREACHED */ + return (0); } -addbib(fp, argv) /* add entries to a bibliographic database */ -FILE *fp; -char *argv; +static void +addbib(FILE *fp, char *argv) /* add entries to a bibliographic database */ { char line[BUFSIZ]; int i = 0, firstln, repeat = 0, escape = 0; @@ -119,43 +115,34 @@ char *argv; fgets(line, BUFSIZ, stdin); if (line[0] == 'y' || line[0] == 'Y') instruct(); - while (1) - { + while (1) { putchar('\n'); putc('\n', fp); - for (i = 0; i < entries; i++) - { + for (i = 0; i < entries; i++) { printf("%s\t", gettext(bibskel[i].prompt)); - if (fgets(line, BUFSIZ, stdin) == NULL) - { + if (fgets(line, BUFSIZ, stdin) == NULL) { clearerr(stdin); break; } - if (line[0] == '-' && line[1] == '\n') - { + if (line[0] == '-' && line[1] == '\n') { i -= 2; - if (i < -1) - { + if (i < -1) { printf(gettext("Too far back.\n")); i++; } continue; - } - else if (line[strlen(line)-2] == '\\') - { - if (line[0] != '\\') - { + } else if (line[strlen(line)-2] == '\\') { + if (line[0] != '\\') { line[strlen(line)-2] = '\n'; line[strlen(line)-1] = NULL; trim(line); fprintf(fp, "%s %s", - bibskel[i].keylet, line); + bibskel[i].keylet, line); } printf("> "); again: fgets(line, BUFSIZ, stdin); - if (line[strlen(line)-2] == '\\') - { + if (line[strlen(line)-2] == '\\') { line[strlen(line)-2] = '\n'; line[strlen(line)-1] = NULL; trim(line); @@ -165,21 +152,16 @@ char *argv; } trim(line); fputs(line, fp); - } - else if (line[0] != '\n') - { + } else if (line[0] != '\n') { trim(line); fprintf(fp, "%s %s", bibskel[i].keylet, line); } } - if (abstract) - { + if (abstract) { puts(gettext(" Abstract: (ctrl-d to end)")); firstln = 1; - while (fgets(line, BUFSIZ, stdin)) - { - if (firstln && line[0] != '%') - { + while (fgets(line, BUFSIZ, stdin)) { + if (firstln && line[0] != '%') { fprintf(fp, "%%X "); firstln = 0; } @@ -188,16 +170,14 @@ char *argv; clearerr(stdin); } fflush(fp); /* write to file at end of each cycle */ - if (ferror(fp)) - { + if (ferror(fp)) { perror(argv); exit(1); } editloop: printf(gettext("\nContinue? ")); fgets(line, BUFSIZ, stdin); - if (line[0] == 'e' || line[0] == 'v') - { + if (line[0] == 'e' || line[0] == 'v') { bibedit(fp, line, argv); goto editloop; } @@ -206,14 +186,13 @@ char *argv; } } -trim(line) /* trim line of trailing white space */ -char line[]; +static void +trim(char line[]) /* trim line of trailing white space */ { int n; n = strlen(line); - while (--n >= 0) - { + while (--n >= 0) { if (!isspace(line[n])) break; } @@ -221,9 +200,8 @@ char line[]; line[++n] = NULL; } -bibedit(fp, cmd, arg) /* edit database with edit, ex, or vi */ -FILE *fp; -char *cmd, *arg; +void +bibedit(FILE *fp, char *cmd, char *arg) /* edit database with edit, ex, or vi */ { int i = 0, status; @@ -231,8 +209,7 @@ char *cmd, *arg; while (!isspace(cmd[i])) i++; cmd[i] = NULL; - if (fork() == 0) - { + if (fork() == 0) { if (cmd[0] == 'v' && cmd[1] == 'i') execlp(cmd, cmd, "+$", arg, NULL); else /* either ed, ex, or edit */ @@ -243,17 +220,18 @@ char *cmd, *arg; wait(&status); signal(SIGINT, SIG_DFL); signal(SIGQUIT, SIG_DFL); - if ((fp = fopen(arg, "a")) == NULL) - { + if ((fp = fopen(arg, "a")) == NULL) { perror(arg); exit(1); } } -instruct() /* give user elementary directions */ +static void +instruct(void) /* give user elementary directions */ { putchar('\n'); - puts(gettext("Addbib will prompt you for various bibliographic fields.\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" @@ -268,37 +246,36 @@ instruct() /* give user elementary directions */ } -rd_skel(arg) /* redo bibskel from user-supplied file */ -char *arg; +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) - { + if ((pfp = fopen(arg, "r")) == NULL) { fprintf(stderr, gettext("Promptfile ")); perror(arg); exit(1); } - for (entry = 0; fgets(str, BUFSIZ, pfp); entry++) - { + 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] = NULL; - if (str[i] == '\n') - { - fprintf(stderr, gettext("No tabs between promptfile fields.\n")); - fprintf(stderr, gettext("Format: prompt-string <TAB> %%key\n")); + if (str[i] == '\n') { + fprintf(stderr, gettext( + "No tabs between promptfile fields.\n")); + fprintf(stderr, gettext( + "Format: prompt-string <TAB> %%key\n")); exit(1); } - for (i++, j = 0; str[i] != '\n'; i++, j++) + for (i++, j = 0; str[i] != '\n'; i++, j++) bibskel[entry].keylet[j] = str[i]; bibskel[entry].keylet[j] = NULL; - if (entry >= MAXENT) - { - fprintf(stderr, gettext("Too many entries in promptfile.\n")); + if (entry >= MAXENT) { + fprintf(stderr, gettext( + "Too many entries in promptfile.\n")); exit(1); } } diff --git a/usr/src/cmd/refer/deliv2.c b/usr/src/cmd/refer/deliv2.c index 538bd8f656..c0b24039cc 100644 --- a/usr/src/cmd/refer/deliv2.c +++ b/usr/src/cmd/refer/deliv2.c @@ -1,35 +1,34 @@ +/* + * 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. */ -/* - * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc. - * All Rights Reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" +#pragma ident "%Z%%M% %I% %E% SMI" #include <stdio.h> #include <locale.h> -hash (s) -char *s; +int +hash(char *s) { int c, n; - for(n=0; c= *s; s++) + for (n = 0; c = *s; s++) n += (c*n+ c << (n%4)); - return(n>0 ? n : -n); + return (n > 0 ? n : -n); } -err (s, a) -char *s; +void +err(char *s, int a) { fprintf(stderr, gettext("Error: ")); fprintf(stderr, s, a); @@ -37,37 +36,38 @@ char *s; exit(1); } -prefix(t, s) -char *t, *s; +int +prefix(char *t, char *s) { int c; - while ((c= *t++) == *s++) - if (c==0) return(1); - return(c==0 ? 1: 0); + while ((c = *t++) == *s++) + if (c == 0) + return (1); + return (c == 0 ? 1 : 0); } char * -mindex(s, c) -char *s; +mindex(char *s, char c) { - register char *p; - for( p=s; *p; p++) - if (*p ==c) - return(p); - return(0); + char *p; + for (p = s; *p; p++) + if (*p == c) + return (p); + return (0); } -zalloc(m,n) +void * +zalloc(size_t m, size_t n) { char *calloc(); - int t; -# if D1 - fprintf(stderr, "calling calloc for %d*%d bytes\n",m,n); -# endif - t = (int) calloc(m,n); -# if D1 + 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); +#endif + return (t); } diff --git a/usr/src/cmd/refer/glue1.c b/usr/src/cmd/refer/glue1.c index 7f662b0cdd..e3f1698508 100644 --- a/usr/src/cmd/refer/glue1.c +++ b/usr/src/cmd/refer/glue1.c @@ -1,23 +1,22 @@ +/* + * 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. */ -/* - * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc. - * All Rights Reserved. - */ - - -#pragma ident "%Z%%M% %I% %E% SMI" +#pragma ident "%Z%%M% %I% %E% SMI" #include <stdio.h> -#define unopen(fil) {if (fil!=NULL) {fclose(fil); fil=NULL;}} + +#define unopen(fil) {if (fil != NULL) {fclose(fil); fil = NULL; }} extern char refdir[]; int lmaster = 1000; @@ -26,13 +25,12 @@ FILE *fd = 0; int *hfreq, hfrflg; int colevel = 0; static union firetruck { - unsigned *a; + unsigned *a; long *b; } master; int iflong; extern char *fgnames[], **fgnamp; extern FILE *iopen(); -char *todir(); int prfreqs = 0; int typeindex = 0; char usedir[100]; @@ -43,36 +41,50 @@ long indexdate = 0, gdate(); int soutlen = 1000; int taglen = 1000; -huntmain(argc,argv) -char *argv[]; +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 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 +#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]) - { + 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; + falseflg = 1; break; case 'r': - argc--; + argc--; argv++; rprog = argv[1]; break; @@ -83,94 +95,91 @@ char *argv[]; tags = setfrom(argv[1][2]); break; case 'i': /* input in argument string */ - argc--; + argc--; argv++; sinput = argv[1]; break; - case 's': /*text output to string */ + case 's': /* text output to string */ case 'o': - argc--; + argc--; argv++; soutput = argv[1]; - if ((int) argv[2]<16000) - { - soutlen = (int) argv[2]; - argc--; + if ((int)argv[2] < 16000) { + soutlen = (int)argv[2]; + argc--; argv++; } break; - case 't': /*tag output to string */ - argc--; + case 't': /* tag output to string */ + argc--; argv++; tagout = argv[1]; - if ((int)argv[2]<16000) - { + if ((int)argv[2] < 16000) { taglen = (int)argv[2]; - argc--; + argc--; argv++; } break; case 'l': /* specify length of lists */ - argc--; + argc--; argv++; lmaster = atoi(argv[1]); -# if D1 - fprintf(stderr, "lmaster now %d\n",lmaster); -# endif +#if D1 + fprintf(stderr, "lmaster now %d\n", lmaster); +#endif break; - case 'C': - argc--; + case 'C': + argc--; argv++; colevel = atoi(argv[1]); break; } - argc--; + 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); + 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 + if (ckexist(indexname, ".ib")) { +#if D1 fprintf(stderr, "found old index\n"); -# endif +#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 + 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) - { + fread(&nhash, sizeof (nhash), 1, fa); + fread(&iflong, sizeof (iflong), 1, fa); + if (nhash > maxhash) { if (hpt) - free (hpt, maxhash, sizeof(*hpt)); - hpt=0; + 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 + 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 == 0) + hpt = (long *)zalloc(nhash, sizeof (*hpt)); +#if D1 + fprintf(stderr, "hpt now %o\n", hpt); +#endif if (hpt == NULL) /* * TRANSLATION_NOTE @@ -179,11 +188,11 @@ char *argv[]; * 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) + 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. @@ -191,134 +200,132 @@ char *argv[]; err(gettext( "No space for hash frequencies (%d)"), nhash); - frtbl = fread(hfreq, sizeof(*hfreq), nhash, fa); + frtbl = fread(hfreq, sizeof (*hfreq), nhash, fa); hfrflg = (frtbl == nhash); -# if D1 - fprintf(stderr,"Read pointer files\n"); -# endif +#if D1 + fprintf(stderr, "Read pointer files\n"); +#endif if (master.a == NULL) if (iflong) - master.b = (long *)zalloc(lmaster, sizeof(long)); + master.b = (long *)zalloc(lmaster, + sizeof (long)); else - master.a = (unsigned *)zalloc(lmaster, sizeof(int)); + master.a = (unsigned *)zalloc(lmaster, + sizeof (int)); if (master.a == NULL) err(gettext("no space for answer list"), 0); - } - else + } else if (makefgrep(indexname)) - typeindex=2; - else - { + typeindex = 2; + else { err(gettext("No files %s\n"), indexname); exit(1); } } - if (iflong) - masterp = (unsigned *) master.b; + 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) - { +#if D1 + fprintf(stderr, "typeindex now %d\n", typeindex); +#endif + tagout[0] = 0; + if (typeindex == 2) { grepcall(sinput, tagout, indexname); -# if D1 +#if D1 fprintf(stderr, " back from grepcall\n"); -# endif +#endif restodir(); return; } nitem = getq(qitem); -# if D1 +#if D1 fprintf(stderr, "approaching doquery fb %o\n", fb); -# endif +#endif nfound = doquery(hpt, nhash, fb, nitem, qitem, masterp); -# ifdef D1 +#ifdef D1 fprintf(stderr, "return from doquery with nfound %d\n", nfound); -# endif +#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 + 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 + 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) - { +#endif + if (fgnamp > fgnames) { char **fgp; int k; -# if D1 +#if D1 fprintf(stderr, "were %d bad files\n", fgnamp-fgnames); -# endif - grepquery[0]=0; - for(k=0; k<nitem; k++) - { +#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 + 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 +#if D1 fprintf(stderr, "tagout now /%s/\n", tagout); -# endif +#endif } } restodir(); } char * -todir(t) -char *t; +todir(char *t) { char *s; usedir[0] = 0; - s=t; + s = t; while (*s) s++; - while (s>=t && *s != '/') s--; - if (s<t) return(t); + while (s >= t && *s != '/') s--; + if (s < t) + return (t); *s++ = 0; t = (*t ? t : "/"); - chdir (t); - strcpy (usedir,t); - return(s); + chdir(t); + strcpy(usedir, t); + return (s); } -setfrom(c) +static int +setfrom(char c) { - switch(c) - { - case 'y': + switch (c) { + case 'y': case '\0': default: - return(1000); + return (1000); case '1': - case '2': - case '3': - case '4': + case '2': + case '3': + case '4': case '5': - case '6': - case '7': - case '8': + case '6': + case '7': + case '8': case '9': - return(c-'0'); - case 'n': + return (c-'0'); + case 'n': case '0': - return(0); + return (0); } } diff --git a/usr/src/cmd/refer/glue2.c b/usr/src/cmd/refer/glue2.c index 2c010df841..5453fcaf64 100644 --- a/usr/src/cmd/refer/glue2.c +++ b/usr/src/cmd/refer/glue2.c @@ -1,31 +1,35 @@ +/* + * 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. */ -/* - * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc. - * All Rights Reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" +#pragma ident "%Z%%M% %I% %E% SMI" char refdir[50]; -savedir() +extern int corout(); +extern char *trimnl(); + +void +savedir(void) { - if (refdir[0]==0) - corout ("", refdir, "/usr/bin/pwd", "", 50); + if (refdir[0] == 0) + corout("", refdir, "/usr/bin/pwd", "", 50); trimnl(refdir); } -restodir() +void +restodir(void) { chdir(refdir); } diff --git a/usr/src/cmd/refer/glue3.c b/usr/src/cmd/refer/glue3.c index f381038a6f..3a4fff1d55 100644 --- a/usr/src/cmd/refer/glue3.c +++ b/usr/src/cmd/refer/glue3.c @@ -1,71 +1,78 @@ +/* + * 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. */ -/* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - #pragma ident "%Z%%M% %I% %E% SMI" #include "refer..c" #include <string.h> -#define move(x, y) close(y); dup(x); close(x); +#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); -corout(in, out, rprog, arg, outlen) -char *in, *out, *rprog; +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 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]; + 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]; + pipe(pipev); + fr2 = pipev[0]; fw2 = pipev[1]; - if (fork()==0) - { - close (fw1); - close (fr2); - move (fr1, 0); - move (fw2, 1); - if (rprog[0]!= '/') + 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(fw2); close(fr1); if (strlen(in) > 0) - write (fw1, in , strlen(in)); + write(fw1, in, strlen(in)); close(fw1); wait(0); - n = read (fr2, out, outlen); - out[n]=0; + n = read(fr2, out, outlen); + out[n] = 0; close(fr2); + return (0); } -# define ALEN 50 +#define ALEN 50 -callhunt(in, out, arg, outlen) -char *in, *out, *arg; +static int +callhunt(char *in, char *out, char *arg, int outlen) { char *argv[20], abuff[ALEN]; extern int typeindex; @@ -83,32 +90,32 @@ char *in, *out, *arg; argv[8] = "-o"; argv[9] = one; argv[10] = (char *)onelen; - argv[11] = abuff; - strcpy (abuff,arg); + 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); + huntmain(argc, argv); + return (0); } -dodeliv(in, out, arg, outlen) -char *in, *out, *arg; +static int +dodeliv(char *in, char *out, char *arg, int outlen) { char *mout; int mlen; -# if D1 +#if D1 fprintf(stderr, "in dodeliv, arg /%s/\n", arg?arg:""); -# endif +#endif if (arg && arg[0]) chdir(arg); - mlen = findline(in, &mout, outlen,0L); + mlen = findline(in, &mout, outlen, 0L); - if (mlen>0) - { + if (mlen > 0) { strncpy(out, mout, outlen); - free (mout); + free(mout); } restodir(); + return (0); } diff --git a/usr/src/cmd/refer/glue4.c b/usr/src/cmd/refer/glue4.c index b8062257b0..798d0b2819 100644 --- a/usr/src/cmd/refer/glue4.c +++ b/usr/src/cmd/refer/glue4.c @@ -1,19 +1,18 @@ +/* + * 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. */ -/* - * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc. - * All Rights Reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" +#pragma ident "%Z%%M% %I% %E% SMI" #include <stdio.h> @@ -21,99 +20,99 @@ extern char gfile[]; -grepcall (in, out, arg) -char *in, *out, *arg; +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, oldc = 0, alph = 0, nv = 0; int sv0, sv1; - strcpy (argig, arg); + strcpy(argig, arg); strcat(argig, ".ig"); - strcpy (inp=inb, in); - if (gfile[0]==0) + strcpy(inp = inb, in); + if (gfile[0] == 0) sprintf(gfile, "/tmp/rj%dg", getpid()); -# if D1 - fprintf(stderr, "in grepcall, gfile %s in %o out %o\n", gfile,in,out); -# endif - for(cv[nv++] = "fgrep"; c = *inp; inp++) - { - if (c== ' ') +#if D1 + fprintf(stderr, "in grepcall, gfile %s in %o out %o\n", + gfile, in, out); +#endif + 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; + alph = (c == 0) ? 0 : alph+1; if (alph == 1) cv[nv++] = inp; if (alph > 6) *inp = 0; - oldc=c; + oldc = c; } -# if D1 +#if D1 fprintf(stderr, "%d args set up\n", nv); -# endif +#endif { sv0 = dup(0); close(0); - if (open (argig, 0) != 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); -# if D1 +#if D1 fprintf(stderr, "fgrep returned, output is..\n"); -# endif - close (0); - dup(sv0); +#endif + close(0); + dup(sv0); close(sv0); - close (1); - dup(sv1); + close(1); + dup(sv1); close(sv1); } -# if D1 +#if D1 fprintf(stderr, "back from fgrep\n"); -# endif +#endif gf = fopen(gfile, "r"); - if (gf==NULL) + if (gf == NULL) err("can't read fgrep output %s", gfile); - while (fgets(line, 100, gf) == line) - { - line[100]=0; -# if D1 - fprintf(stderr, "read line as //%s//\n",line); -# endif - for(s=line; *s && (*s != '\t'); s++); - if (*s == '\t') - { + while (fgets(line, 100, gf) == line) { + line[100] = 0; +#if D1 + fprintf(stderr, "read line as //%s//\n", line); +#endif + for (s = line; *s && (*s != '\t'); s++) + ; + if (*s == '\t') { *s++ = '\n'; *s++ = 0; } if (line[0]) strcat(out, line); -# if D1 - fprintf(stderr, "out now /%s/\n",out); -# endif +#if D1 + fprintf(stderr, "out now /%s/\n", out); +#endif while (*s) s++; -# if D1 - fprintf(stderr, "line %o s %o s-1 %o\n",line,s,s[-1]); -# endif - if (s[-1]!= '\n') - while (!feof(gf) && getc(gf)!= '\n') ; +#if D1 + fprintf(stderr, "line %o s %o s-1 %o\n", line, s, s[-1]); +#endif + if (s[-1] != '\n') + while (!feof(gf) && getc(gf) != '\n') + ; } fclose(gf); -# if D1 - fprintf(stderr, "back from reading %, out %s\n",out); -# else - unlink (gfile); -# endif - return(0); +#if D1 + fprintf(stderr, "back from reading %, out %s\n", out); +#else + unlink(gfile); +#endif } -clfgrep() +void +clfgrep(void) { if (gfile[0]) unlink(gfile); diff --git a/usr/src/cmd/refer/glue5.c b/usr/src/cmd/refer/glue5.c index 18138986ec..d4831e8d3d 100644 --- a/usr/src/cmd/refer/glue5.c +++ b/usr/src/cmd/refer/glue5.c @@ -1,19 +1,18 @@ +/* + * 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. */ -/* - * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc. - * All Rights Reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" +#pragma ident "%Z%%M% %I% %E% SMI" #include <stdio.h> @@ -27,14 +26,14 @@ * 2 - some error */ #define MAXSIZ 700 -#define QSIZE 400 +#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]; @@ -49,195 +48,205 @@ int numwords; int nfound; static int flag = 0; -fgrep(argc, argv) -char **argv; +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) + 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; + 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]) - { + 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]; + 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 + 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); + xargv++; xargc--; + } + if (xargc <= 0) { + write(2, "bad fgrep call\n", 15); exit(2); - } -# if D1 + } +#if D1 fprintf(stderr, "before cgoto\n"); -# endif +#endif cgotofn(); -# if D1 +#if D1 fprintf(stderr, "before cfail\n"); -# endif +#endif cfail(); -# if D1 +#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 + instr ? instr[inct-3] : '\0', + instr ? instr[inct-2] : '\0', + instr ? instr[inct-1] : '\0'); +#endif execute(); -# if D1 +#if D1 fprintf(stderr, "returning nsucc %d\n", nsucc); - fprintf(stderr, "fgrep done www %o\n",www); -# endif - return(nsucc == 0); + fprintf(stderr, "fgrep done www %o\n", www); +#endif + return (nsucc == 0); } -execute() +static void +execute(void) { - register char *p; - register struct words *c; - register ch; - register ccount; + char *p; + struct words *c; + char ch; + int ccount; int f; char *nlp; - f=0; + f = 0; ccount = instr ? inct : 0; - nfound=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 +#if D2 +fprintf(stderr, "in execute ccount %d inct %d\n", ccount, inct); +#endif for (;;) { -# if D3 +#if D3 fprintf(stderr, "down ccount\n"); -# endif +#endif if (--ccount <= 0) { -# if D2 -fprintf(stderr, "ex loop ccount %d instr %o\n",ccount, instr); -# endif +#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 + 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); +{ + char xx[20]; + sprintf(xx, "they are %%.%ds\n", ccount); + fprintf(stderr, xx, p); } -# endif +#endif } nstate: ch = *p; -# if D2 -fprintf(stderr, "roaming along in ex ch %c c %o\n",ch,c); -# endif +#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) { + } else if (c->link != 0) { c = c->link; goto nstate; - } - else { + } else { c = c->fail; - if (c==0) { + if (c == 0) { c = www; istate: if (c->inp == ch) { c = c->nst; - } - else if (c->link != 0) { + } else if (c->link != 0) { c = c->link; goto istate; } - } - else goto nstate; + } 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) + 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 +#if D3 fprintf(stderr, "down ccount2\n"); -# endif +#endif if (--ccount <= 0) { - if (p == &buf[2*BUFSIZ]) p = buf; + 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); + 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 +#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 (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, nlp, + &buf[2*BUFSIZ] - nlp); write(1, buf, p-&buf[0]); - } - if (p[-1]!= '\n') write (1, "\n", 1); } - if (instr==0) - { + if (p[-1] != '\n') write(1, "\n", 1); + } + if (instr == 0) { nlp = p; c = www; - nfound=0; - } - } - else + nfound = 0; + } + } else ccount++; continue; } -# if D2 -fprintf(stderr, "nr end loop p %o\n",p); -# endif +#if D2 +fprintf(stderr, "nr end loop p %o\n", p); +#endif if (instr) p++; else @@ -245,29 +254,31 @@ fprintf(stderr, "nr end loop p %o\n",p); { nlp = p; c = www; - nfound=0; + nfound = 0; } } - if (instr==0) + if (instr == 0) close(f); } -cgotofn() { - register c; - register struct words *s; +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; +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: + } else { +loop: if (s->inp == c) { s = s->nst; continue; @@ -290,8 +301,9 @@ enter: if (smax >= &www[MAXSIZ - 1]) overflo(); s->nst = ++smax; s = smax; - } - while ((c = gch()) != '\n'); + } + while ((c = gch()) != '\n') + ; smax->out = 1; s = www; numwords++; @@ -299,38 +311,45 @@ enter: } -gch() +static char +gch(void) { static char *s; - if (flag==0) - { - flag=1; + if (flag == 0) { + flag = 1; s = *xargv++; -# if D1 +#if D1 fprintf(stderr, "next arg is %s xargc %d\n", xargc > 0 ? s : "", xargc); -# endif - if (xargc-- <=0) return(0); +#endif + if (xargc-- <= 0) + return (0); } - if (*s) return(*s++); - for(flag=0; flag<2*BUFSIZ; flag++) - buf[flag]=0; - flag=0; - return('\n'); + if (*s) + return (*s++); + for (flag = 0; flag < 2*BUFSIZ; flag++) + buf[flag] = 0; + flag = 0; + return ('\n'); } -overflo() { - write(2,"wordlist too large\n", 19); +static void +overflo(void) +{ + write(2, "wordlist too large\n", 19); exit(2); } -cfail() { + +static void +cfail(void) +{ struct words *queue[QSIZE]; struct words **front, **rear; struct words *state; - register char c; - register struct words *s; + char c; + struct words *s; s = www; front = rear = queue; -init: +init: if ((s->inp) != 0) { *rear++ = s->nst; if (rear >= &queue[QSIZE - 1]) overflo(); @@ -339,12 +358,12 @@ init: goto init; } - while (rear!=front) { + while (rear != front) { s = *front; if (front == &queue[QSIZE-1]) front = queue; else front++; -cloop: +cloop: if ((c = s->inp) != 0) { *rear = (q = s->nst); if (front < rear) @@ -355,14 +374,13 @@ cloop: else if (++rear == front) overflo(); state = s->fail; -floop: +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) + } else if ((state = state->link) != 0) goto floop; } if ((s = s->link) != 0) @@ -370,13 +388,15 @@ floop: } } -static int seen[50]; -new (x) +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); + for (i = 0; i < nfound; i++) + if (seen[i] == x) + return (0); + seen[i] = x; + return (1); } diff --git a/usr/src/cmd/refer/hunt1.c b/usr/src/cmd/refer/hunt1.c index 1417abad52..964ddc5d30 100644 --- a/usr/src/cmd/refer/hunt1.c +++ b/usr/src/cmd/refer/hunt1.c @@ -1,57 +1,69 @@ +/* + * 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. */ -/* - * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc. - * All Rights Reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" +#pragma ident "%Z%%M% %I% %E% SMI" -# include <locale.h> -# include <stdio.h> -# include <assert.h> +#include <locale.h> +#include <stdio.h> +#include <assert.h> extern char refdir[]; extern int keepold; extern char *fgnames[]; extern char **fgnamp; -FILE *fd =NULL; -int lmaster =500; +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; +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 *calloc(); +char *todir(); char gfile[50]; -static int full =1000; -static int tags =0; +static int full = 1000; +static int tags = 0; char *sinput, *soutput, *tagout; -long indexdate =0, gdate(); +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(); -main(argc,argv) -char *argv[]; +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; + 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; + unsigned *master = 0; int falseflg, nhash, nitem, nfound, frtbl, kk; /* special wart for refpart: default is tags only */ @@ -59,21 +71,19 @@ char *argv[]; (void) setlocale(LC_ALL, ""); #if !defined(TEXT_DOMAIN) -#define TEXT_DOMAIN "SYS_TEST" +#define TEXT_DOMAIN "SYS_TEST" #endif (void) textdomain(TEXT_DOMAIN); falseflg = 0; - while (argc > 1 && argv[1][0] == '-') - { - switch(argv[1][1]) - { + while (argc > 1 && argv[1][0] == '-') { + switch (argv[1][1]) { case 'a': /* all output, incl. false drops */ - falseflg = 1; + falseflg = 1; break; case 'r': - argc--; + argc--; argv++; rprog = argv[1]; break; @@ -84,29 +94,28 @@ char *argv[]; tags = setfrom(argv[1][2]); break; case 'i': /* input in argument string */ - argc--; + argc--; argv++; sinput = argv[1]; break; - case 's': /*text output to string */ + case 's': /* text output to string */ case 'o': - argc--; + argc--; argv++; soutput = argv[1]; - if ((int) argv[2]<16000) - { + if ((int)argv[2] < 16000) { soutlen = (int)argv[2]; - argc--; + argc--; argv++; } break; - case 't': /*tag output to string */ - argc--; + case 't': /* tag output to string */ + argc--; argv++; tagout = argv[1]; break; case 'l': /* length of internal lists */ - argc--; + argc--; argv++; lmaster = atoi(argv[1]); break; @@ -115,132 +124,127 @@ char *argv[]; break; case 'C': /* coordination level */ colevel = atoi(argv[1]+2); -# if D1 - fprintf(stderr, "colevel set to %d\n",colevel); -# endif +#if D1 + fprintf(stderr, "colevel set to %d\n", colevel); +#endif break; case 'P': /* print term freqs */ - prfreqs=1; + prfreqs = 1; break; case 'm': - measure=1; + measure = 1; break; } - argc--; + argc--; argv++; } - if(argc < 2) + 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); + 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; + 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) - { + 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); + 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 +#if D1 fprintf(stderr, "read freqs %d\n", frtbl); -# endif +#endif search: - while (1) - { + while (1) { nitem = getq(qitem); if (measure) tick(); - if (nitem==0) continue; + if (nitem == 0) continue; if (nitem < 0) break; - if (tagout) tagout[0]=0; - if (fb!=NULL) - { + 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 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 + nfound = baddrop(master, nfound, fc, + nitem, qitem, rprog, full); +#if D1 + fprintf(stderr, "after baddrop nfound %d\n", nfound); +#endif } - if (fgnamp>fgnames) - { + if (fgnamp > fgnames) { char **fgp, tgbuff[100]; int k; -# if D1 +#if D1 fprintf(stderr, "were %d bad files\n", fgnamp-fgnames); -# endif +#endif (void) memset(tgbuff, 0, sizeof (tgbuff)); - grepquery[0]=0; - for(k=0; k<nitem; k++) - { + 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 +#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 +#if D1 fprintf(stderr, "grepmade\n"); -# endif - if (tagout==0) - tagout=tgbuff; +#endif + if (tagout == 0) + tagout = tgbuff; grepcall(grepquery, tagout, *fgp); -# if D1 +#if D1 fprintf(stderr, "tagout now /%s/\n", tagout); -# endif - if (full) - { +#endif + if (full) { int nout; char *bout; char *tagp; @@ -248,62 +252,64 @@ search: tagp = tagout; while (*tagp) { oldtagp = tagp; - while (*tagp && (*tagp != '\n')) + while (*tagp && + (*tagp != '\n')) tagp++; - if (*tagp) + if (*tagp) tagp++; - nout = findline(oldtagp, &bout, 1000, 0L); - if (nout > 0) - { + nout = findline(oldtagp, &bout, + 1000, 0L); + if (nout > 0) { fputs(bout, stdout); - free(bout); + free(bout); } } } } } if (tags) - result (master, nfound >tags ? tags: nfound, fc); + result(master, nfound > tags ? tags : nfound, fc); if (measure) tock(); } - /* NOTREACHED */ + return (0); } char * -todir(t) -char *t; +todir(char *t) { char *s; - s=t; + s = t; while (*s) s++; - while (s>=t && *s != '/') s--; - if (s<t) return(t); + while (s >= t && *s != '/') s--; + if (s < t) + return (t); *s++ = 0; t = (*t ? t : "/"); - chdir (t); - strcpy (usedir,t); - return(s); + chdir(t); + strcpy(usedir, t); + return (s); } -setfrom(c) + +static int +setfrom(char c) { - switch(c) - { - case 'y': + switch (c) { + case 'y': case '\0': default: - return(1000); + return (1000); case '1': - case '2': - case '3': - case '4': + case '2': + case '3': + case '4': case '5': - case '6': - case '7': - case '8': + case '6': + case '7': + case '8': case '9': - return(c-'0'); - case 'n': + return (c-'0'); + case 'n': case '0': - return(0); + return (0); } } diff --git a/usr/src/cmd/refer/hunt2.c b/usr/src/cmd/refer/hunt2.c index 941c979790..5d2611d57a 100644 --- a/usr/src/cmd/refer/hunt2.c +++ b/usr/src/cmd/refer/hunt2.c @@ -1,36 +1,41 @@ +/* + * 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. */ -/* - * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc. - * All Rights Reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" +#pragma ident "%Z%%M% %I% %E% SMI" #include "refer..c" static int *coord = 0; -int hh[50]; -extern int *hfreq, hfrflg, hcomp(), hexch(); +int hh[50]; +extern int *hfreq, hfrflg; extern int prfreqs; union ptr { - unsigned *a; + unsigned *a; long *b; }; -doquery(hpt, nhash, fb, nitem, qitem, mptr) -long *hpt; -FILE *fb; -char *qitem[]; -unsigned *mptr; +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; @@ -38,99 +43,89 @@ unsigned *mptr; int *prevcoord; long lp; extern int lmaster, colevel, reached; - long getl(); extern int iflong; if (iflong) { - master.b = (long *) mptr; - } - else { + 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 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)); + 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; + 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++) - { +#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, "query wd X%sX has hash %d\n", qitem[i], hh[i]); +#endif } -# if D1 +#if D1 fprintf(stderr, "past that loop nhash %d hpt is %lo\n", nhash, hpt); -# endif +#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]]); + 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++) + 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 +#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 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 + coord[i] = 1; +#if D2 if (iflong) - fprintf(stderr,"master has %ld\n",(master.b[i])); + 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) - { + fprintf(stderr, "master has %d\n", (master.a[i])); +#endif + assert(i < lmaster); + if (iflong) { if (master.b[i] == -1L) break; - } - else - { + } else { if (master.a[i] == -1) break; } } - nf= i; - for(nterm=1; nterm<nitem; nterm++) - { -# ifdef D1 + 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++) - { +#endif + if (colevel > 0) { + for (j = 0; j < nf; j++) { if (iflong) prevdrop.b[j] = master.b[j]; else @@ -139,163 +134,177 @@ unsigned *mptr; } } 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) - { + 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 (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)); + 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 + 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)); + 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 + 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); + 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 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]); + 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 + 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 (colevel == 0 && j >= nf) break; + if (j < nf && + (iflong ? prevdrop.b[j] : prevdrop.a[j]) == k) { if (iflong) - master.b[g]=k; + master.b[g] = k; else - master.a[g]=k; + master.a[g] = k; coord[g++] = prevcoord[j++]+1; -# if D1 +#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]); + 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) - { + 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; + master.b[g] = k; else - master.a[g]=k; + 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 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]); +#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 + 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 + 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 +#endif reached = best; - for(g=j=0; j<nf; j++) - if (coord[j]==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 + 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)); +#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]); +#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); -} - -long -getl(fb) -FILE *fb; -{ - return(getw(fb)); + fprintf(stderr, ":%d\n", master.a[g]); +#endif + return (nf); } -putl(ll, f) -long ll; -FILE *f; +static long +getl(FILE *fb) { - putw(ll, f); + return (getw(fb)); } -hcomp( n1, n2) +static int +hcomp(int n1, int n2) { - return (hfreq[hh[n1]]<=hfreq[hh[n2]]); + return (hfreq[hh[n1]] <= hfreq[hh[n2]]); } -hexch( n1, n2 ) +static void +hexch(int n1, int n2) { int t; t = hh[n1]; diff --git a/usr/src/cmd/refer/hunt3.c b/usr/src/cmd/refer/hunt3.c index 72767b1865..099c4fd3e5 100644 --- a/usr/src/cmd/refer/hunt3.c +++ b/usr/src/cmd/refer/hunt3.c @@ -1,64 +1,60 @@ +/* + * 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. */ -/* - * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc. - * All Rights Reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" +#pragma ident "%Z%%M% %I% %E% SMI" #include <locale.h> #include "refer..c" -#define BSIZ 250 +#define BSIZ 250 -getq(v) -char *v[]; +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); + if (eof) + return (-1); p = buff; - while ( (c = (sinput ? *sinput++ : getchar()) ) > 0) - { - if (c== '\n') + while ((c = (sinput ? *sinput++ : getchar())) > 0) { + if (c == '\n') break; - if (isalpha(c) || isdigit(c)) - { - if (las==0) - { + if (isalpha(c) || isdigit(c)) { + if (las == 0) { v[n++] = p; - las=1; + las = 1; } if (las++ <= 6) *p++ = c; - } - else - { - if (las>0) + } else { + if (las > 0) *p++ = 0; - las=0; + las = 0; } } - *p=0; + *p = 0; if (p > buff + BSIZ) - fprintf(stderr, gettext("query long than %d characters\n"), 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++) + 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); +#endif + return (n); } diff --git a/usr/src/cmd/refer/hunt5.c b/usr/src/cmd/refer/hunt5.c index 9cf66aac62..90e086e558 100644 --- a/usr/src/cmd/refer/hunt5.c +++ b/usr/src/cmd/refer/hunt5.c @@ -1,19 +1,18 @@ +/* + * 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. */ -/* - * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc. - * All Rights Reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" +#pragma ident "%Z%%M% %I% %E% SMI" #include <stdio.h> #include <sys/types.h> @@ -21,13 +20,12 @@ extern char *soutput, *tagout, usedir[]; union ptr { - unsigned *a; + unsigned *a; long *b; }; -result(mptr, nf, fc) -unsigned *mptr; -FILE *fc; +void +result(unsigned *mptr, int nf, FILE *fc) { int i, c; char *s; @@ -37,34 +35,28 @@ FILE *fc; union ptr master; if (iflong) { - master.b = (long *) mptr; - } - else { + master.b = (long *)mptr; + } else { master.a = mptr; } - for(i=0; i<nf; i++) - { + for (i = 0; i < nf; i++) { lp = iflong ? master.b[i] : master.a[i]; - fseek(fc,lp, 0); + fseek(fc, lp, 0); fgets(res, 100, fc); - for(s=res; c = *s; s++) - if (c== ';') - { - *s=0; + for (s = res; c = *s; s++) + if (c == ';') { + *s = 0; break; } - if (tagout !=0) - { - if (res[0]=='/' || usedir[0]==0) + 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) + } else { + if (res[0] != '/' || usedir[0] == 0) printf("%s/", usedir); printf("%s\n", res); } @@ -76,6 +68,6 @@ gdate(f) FILE *f; { struct stat sb; - fstat (fileno(f), &sb); - return (sb . st_mtime); + fstat(fileno(f), &sb); + return (sb . st_mtime); } diff --git a/usr/src/cmd/refer/hunt6.c b/usr/src/cmd/refer/hunt6.c index 53283e3292..f3f7dde158 100644 --- a/usr/src/cmd/refer/hunt6.c +++ b/usr/src/cmd/refer/hunt6.c @@ -1,38 +1,42 @@ +/* + * 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. */ -/* - * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc. - * All Rights Reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" +#pragma ident "%Z%%M% %I% %E% SMI" #include <stdio.h> #include <assert.h> #include <string.h> -#define TXTLEN 1000 +#define TXTLEN 1000 char *outbuf = 0; extern char *soutput; extern int soutlen, iflong; extern long indexdate; union ptr { - unsigned *a; - long *b; + unsigned *a; + long *b; }; -baddrop(mptr, nf, fc, nitem, qitem, rprog, full) -unsigned *mptr; -FILE *fc; -char *qitem[], *rprog; +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; @@ -42,125 +46,116 @@ char *qitem[], *rprog; extern int colevel, reached; if (iflong) { - master.b = (long *) mptr; - } - else { + master.b = (long *)mptr; + } else { master.a = mptr; } -# if D1 +#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]); + 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++) - { + 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 D1 if (iflong) fprintf(stderr, "i %d master %lo lp %lo\n", - i, master.b[i], lp); + 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 + 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; +#endif + if (!auxil(res, output)) { + char *s; int c; -# if D1 +#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; + rprog ? 'y': 'n'); +#endif + for (s = res; c = *s; s++) + if (c == ';' || c == '\n') { + *s = 0; break; } if (rprog) - len = corout(res, output, rprog, 0, TXTLEN); - else - { + len = corout(res, output, rprog, "", TXTLEN); + else { len = findline(res, &mput, TXTLEN, indexdate); - if (len > 0) /* copy and free */ - { + if (len > 0) { /* copy and free */ strncpy(output, mput, TXTLEN); free(mput); - } - else /* insufficient memory or other... */ + } 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) +#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; + na = 0; ar[na++] = "fgrep"; ar[na++] = "-r"; ar[na++] = "-n"; - ar[na++] = (char *) need; + ar[na++] = (char *)need; ar[na++] = "-i"; ar[na++] = output; - ar[na++] = (char *) len; - for(j=0; j<nitem; j++) + ar[na++] = (char *)len; + for (j = 0; j < nitem; j++) ar[na++] = qitem[j]; -# ifdef D1 +#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 + len, ar[4], ar[5], ar[6]); +#endif + if (fgrep(na, ar) == 0) { +#ifdef D1 fprintf(stderr, "fgrep found it\n"); -# endif +#endif if (iflong) master.b[g++] = master.b[i]; else master.a[g++] = master.a[i]; if (full >= g) - if (soutput==0) + if (soutput == 0) fputs(output, stdout); else - strcpy (soutput, output); + strcpy(soutput, output); } -# ifdef D1 +#ifdef D1 fprintf(stderr, "after fgrep\n"); -# endif +#endif } - return(g); + return (g); } -auxil( res, output) -char *res, *output; +static int +auxil(char *res, char *output) { extern FILE *fd; - long lp, c; + long lp, c; int len; - if (fd==0)return(0); - while (c = *res++) - { - if (c == ';') - { + if (fd == 0) + return (0); + while (c = *res++) { + if (c == ';') { sscanf(res, "%ld,%d", &lp, &len); - fseek (fd, lp, 0); + fseek(fd, lp, 0); fgets(output, len, fd); - return(1); + return (1); } } - return(0); + return (0); } diff --git a/usr/src/cmd/refer/hunt7.c b/usr/src/cmd/refer/hunt7.c index b92de26439..7720c0f089 100644 --- a/usr/src/cmd/refer/hunt7.c +++ b/usr/src/cmd/refer/hunt7.c @@ -1,26 +1,25 @@ +/* + * 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. */ -/* - * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc. - * All Rights Reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" +#pragma ident "%Z%%M% %I% %E% SMI" #include <stdio.h> #include <locale.h> #include <assert.h> -#define SAME 0 -#define FGCT 10 -#define FGSIZE 150 +#define SAME 0 +#define FGCT 10 +#define FGSIZE 150 int keepold = 1; /* keep old things for fgrep search */ char fgspace[FGSIZE]; @@ -28,9 +27,10 @@ char *fgp = fgspace; char *fgnames[FGCT]; char **fgnamp = fgnames; -findline(in, out, outlen, indexdate) -long indexdate; -char *in, **out; +extern char *mindex(); + +long +findline(char *in, char **out, int outlen, long indexdate) { static char name[100] = ""; char *p, **ftp; @@ -39,92 +39,88 @@ char *in, **out; long lp, llen; int len, k, nofil; -# if D1 +#if D1 fprintf(stderr, "findline: %s\n", in); -# endif +#endif if (mindex(in, '!')) - /* return(remote(in, *out)); /* Does NOTHING */ - return(0); + return (0); - nofil = in[0]==0; - for(p=in; *p && *p != ':' && *p != ';'; p++) + nofil = in[0] == 0; + for (p = in; *p && *p != ':' && *p != ';'; p++) ; - if (*p) *p++=0; - else p=in; + if (*p) *p++ = 0; + else p = in; k = sscanf(p, "%ld,%ld", &lp, &llen); -# ifdef D1 - fprintf(stderr, "p %s k %d lp %ld llen %ld\n",p,k,lp,llen); -# endif - if (k<2) - { +#ifdef D1 + fprintf(stderr, "p %s k %d lp %ld llen %ld\n", p, k, lp, llen); +#endif + if (k < 2) { lp = 0; - llen=outlen; + llen = outlen; } -# ifdef D1 - fprintf(stderr, "lp %ld llen %ld\n",lp, llen); -# endif -# ifdef D1 - fprintf(stderr, "fa now %o, p %o in %o %s\n",fa, p,in,in); -# endif - if (nofil) - { -# if D1 +#ifdef D1 + fprintf(stderr, "lp %ld llen %ld\n", lp, llen); +#endif +#ifdef D1 + fprintf(stderr, "fa now %o, p %o in %o %s\n", fa, p, in, in); +#endif + if (nofil) { +#if D1 fprintf(stderr, "set fa to stdin\n"); -# endif +#endif fa = stdin; - } - else - if (strcmp (name, in) != 0 || 1) - { -# if D1 - fprintf(stderr, "old: %s new %s not equal\n",name,in); -# endif + } else + if (strcmp(name, in) != 0 || 1) { +#if D1 + fprintf(stderr, "old: %s new %s not equal\n", name, in); +#endif if (fa != NULL) fa = freopen(in, "r", fa); else fa = fopen(in, "r"); -# if D1 - if (fa==NULL) - fprintf(stderr, "failed to (re)open *%s*\n",in); -# endif +#if D1 if (fa == NULL) - return(0); + fprintf(stderr, "failed to (re)open *%s*\n", + in); +#endif + if (fa == NULL) + return (0); /* err("Can't open %s", in); */ strcpy(name, in); - if (gdate(fa) > indexdate && indexdate != 0) - { - if (keepold) - { - for(ftp=fgnames; ftp<fgnamp; ftp++) - if (strcmp(*ftp, name)==SAME) - return(0); - strcpy (*fgnamp++ = fgp, name); - assert(fgnamp<fgnames+FGCT); - while (*fgp && *fgp!=':') + 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); + assert(fgp < fgspace+FGSIZE); + return (0); } - fprintf(stderr, gettext("Warning: index predates file '%s'\n"), name); + fprintf(stderr, gettext( + "Warning: index predates file '%s'\n"), + name); } } -# if D1 +#if D1 else - fprintf(stderr, "old %s new %s same fa %o\n", name,in,fa); -# endif - if (fa != NULL) - { + fprintf(stderr, "old %s new %s same fa %o\n", + name, in, fa); +#endif + if (fa != NULL) { fseek(fa, lp, 0); - *out = (char *) malloc(llen + 1); - if (*out == NULL) { - return(0); - } + *out = (char *)malloc(llen + 1); + if (*out == NULL) { + return (0); + } len = fread(*out, 1, llen, fa); *(*out + llen) = 0; -# ifdef D1 - fprintf(stderr, "length as read is %d\n",len); -# endif +#ifdef D1 + fprintf(stderr, "length as read is %d\n", len); +#endif } - return(llen); + return (llen); } diff --git a/usr/src/cmd/refer/hunt8.c b/usr/src/cmd/refer/hunt8.c index 0be035d9a1..f33a5bc026 100644 --- a/usr/src/cmd/refer/hunt8.c +++ b/usr/src/cmd/refer/hunt8.c @@ -1,96 +1,92 @@ +/* + * 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. */ -/* - * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc. - * All Rights Reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" +#pragma ident "%Z%%M% %I% %E% SMI" #include <locale.h> #include <stdio.h> #include <assert.h> -#define unopen(fil) {if (fil!=NULL) {fclose(fil); fil=NULL;}} +#define unopen(fil) {if (fil != NULL) {fclose(fil); fil = NULL; }} +extern void err(); extern long indexdate, gdate(); extern FILE *iopen(); -runbib (s) -char *s; + +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); + sprintf(tmp, "/usr/lib/refer/mkey '%s' > '%s.ig'", s, s); system(tmp); } -makefgrep(indexname) -char *indexname; +int +makefgrep(char *indexname) { FILE *fa, *fb; - if (ckexist(indexname, ".ig")) - { + if (ckexist(indexname, ".ig")) { /* existing gfrep -type index */ -# if D1 +#if D1 fprintf(stderr, "found fgrep\n"); -# endif +#endif fa = iopen(indexname, ".ig"); fb = iopen(indexname, ""); - if (gdate(fb)>gdate(fa)) - { - if (fa!=NULL) + if (gdate(fb) > gdate(fa)) { + if (fa != NULL) fclose(fa); runbib(indexname); - fa= iopen(indexname, ".ig"); + fa = iopen(indexname, ".ig"); } indexdate = gdate(fa); - unopen(fa); + unopen(fa); unopen(fb); - } - else - if (ckexist(indexname, "")) - { + } else + if (ckexist(indexname, "")) { /* make fgrep */ -# if D1 +#if D1 fprintf(stderr, "make fgrep\n"); -# endif +#endif runbib(indexname); time(&indexdate); - } - else /* failure */ - return(0); - return(1); /* success */ + } else /* failure */ + return (0); + return (1); /* success */ } -ckexist(s, t) -char *s, *t; +int +ckexist(char *s, char *t) { char fnam[100]; - strcpy (fnam, s); - strcat (fnam, t); + strcpy(fnam, s); + strcat(fnam, t); return (access(fnam, 04) != -1); } FILE * -iopen(s, t) -char *s, *t; +iopen(char *s, char *t) { char fnam[100]; FILE *f; - strcpy (fnam, s); - strcat (fnam, t); - f = fopen (fnam, "r"); - if (f == NULL) - { + strcpy(fnam, s); + strcat(fnam, t); + f = fopen(fnam, "r"); + if (f == NULL) { err(gettext("Missing expected file %s"), fnam); exit(1); } - return(f); + return (f); } diff --git a/usr/src/cmd/refer/hunt9.c b/usr/src/cmd/refer/hunt9.c deleted file mode 100644 index a45a3b9e35..0000000000 --- a/usr/src/cmd/refer/hunt9.c +++ /dev/null @@ -1,23 +0,0 @@ -/* 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. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -remote(in, out) -char *in, *out; -{ - /* "in" is a long distance file name: get it */ - ; -} diff --git a/usr/src/cmd/refer/inv1.c b/usr/src/cmd/refer/inv1.c index d679615ea8..5a183eec9b 100644 --- a/usr/src/cmd/refer/inv1.c +++ b/usr/src/cmd/refer/inv1.c @@ -1,28 +1,33 @@ +/* + * 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. */ -/* - * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc. - * All Rights Reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" +#pragma ident "%Z%%M% %I% %E% SMI" #include <stdio.h> #include <locale.h> #include <assert.h> -main(argc, argv) -char *argv[]; +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 + /* + * 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. @@ -42,88 +47,80 @@ char *argv[]; 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; + int i, j, k; long keys; - int iflong =0; + int iflong = 0; char *sortdir; (void) setlocale(LC_ALL, ""); #if !defined(TEXT_DOMAIN) -#define TEXT_DOMAIN "SYS_TEST" +#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]) - { + 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); + nhash = atoi(argv[1]+2); break; case 'n': /* new, don't append */ - appflg=0; + appflg = 0; break; case 'a': /* append to old file */ - appflg=1; + appflg = 1; break; case 'v': /* verbose output */ - chatty=1; + chatty = 1; break; case 'd': /* keep keys on file .id for check on searching */ - keepkey=1; + keepkey = 1; break; - case 'p': /* pipe into sort (saves space, costs time)*/ - pipein = 1; + 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 */ + if (argv[1][2] == 'u') /* unlink */ remove = argv[2]; - argc--; + 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"); + 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) - { + if (pipein) { sprintf(com, "/usr/bin/sort -T %s -o %s", sortdir, tmpa); fta = popen(com, "w"); - } - else /* use tmp file */ - { + } else { /* use tmp file */ fta = fopen(tmpa, "w"); - assert (fta != NULL); + assert(fta != NULL); } fb = 0; - if (appflg ) - { - if (fb = fopen(nmb, "r")) - { + 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); + if (ftb == NULL) + err(gettext("Can't get scratch file %s"), tmpb); nhash = recopy(ftb, fb, fopen(nma, "r")); fclose(ftb); - } - else - appflg=0; + } else + appflg = 0; } fc = fopen(nmc, appflg ? "a" : "w"); if (keepkey) @@ -133,8 +130,7 @@ char *argv[]; if (remove != NULL) unlink(remove); fclose(fta); - if (pipein) - { + if (pipein) { pclose(fta); } else @@ -142,13 +138,12 @@ char *argv[]; sprintf(com, "sort -T %s %s -o %s", sortdir, tmpa, tmpa); system(com); } - if (appflg) - { + 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); + tmpb, tmpc, tmpa); system(com); } fta = fopen(tmpa, "r"); @@ -156,19 +151,16 @@ char *argv[]; fb = fopen(nmb, "w"); whash(fta, fa, fb, nhash, iflong, &keys, &hashes); fclose(fta); -# ifndef D1 +#ifndef D1 unlink(tmpa); -# endif - if (appflg) - { +#endif + if (appflg) { unlink(tmpb); unlink(tmpc); } if (chatty) + printf(gettext("%ld key occurrences, %d hashes, %d docs\n"), + keys, hashes, docs); - printf (gettext("%ld key occurrences, %d hashes, %d docs\n"), - keys, hashes, docs); - - exit(0); - /* NOTREACHED */ + return (0); } diff --git a/usr/src/cmd/refer/inv2.c b/usr/src/cmd/refer/inv2.c index 966d79d40e..526b4852d0 100644 --- a/usr/src/cmd/refer/inv2.c +++ b/usr/src/cmd/refer/inv2.c @@ -1,35 +1,36 @@ +/* + * 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. */ -/* - * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc. - * All Rights Reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" +#pragma ident "%Z%%M% %I% %E% SMI" #include <stdio.h> #include <assert.h> -#define LINESIZ 1250 +#define LINESIZ 1250 + +extern int hash(); -newkeys (outf, inf, recf, nhash, fd, iflong) -FILE *outf, *inf, *recf, *fd; -int *iflong; +int +newkeys(FILE *outf, FILE *inf, FILE *recf, int nhash, FILE *fd, int *iflong) { - /* reads key lines from inf; hashes and writes on outf; + /* + * 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; + long ld = 0; int ll = 0, lt = 0; char line[LINESIZ]; char key[30], bkeys[40]; @@ -37,15 +38,13 @@ int *iflong; char *keyv[500]; int i, nk, ndoc = 0, more = 0, c; - lp = ftell (recf); - while (fgets(line, LINESIZ, inf)) - { + lp = ftell(recf); + while (fgets(line, LINESIZ, inf)) { p = line; while (*p != '\t') p++; - *p++ =0; + *p++ = 0; fputs(line, recf); - if (fd) - { + if (fd) { sprintf(bkeys, ";%ld", ld); ll = strlen(p); lt = strlen(bkeys); @@ -56,55 +55,55 @@ int *iflong; 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); + 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 */ - { + 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 != ' ') - { + 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 = 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 */ + *iflong = (lp >= 65536L); + if (sizeof (int) > 2) *iflong = 1; /* force long on VAX */ fclose(recf); - return(ndoc); + return (ndoc); } -trimnl(p) -char *p; + +void +trimnl(char *p) { while (*p) p++; p--; - if (*p == '\n') *p=0; + if (*p == '\n') *p = 0; } diff --git a/usr/src/cmd/refer/inv3.c b/usr/src/cmd/refer/inv3.c index 3ef8a6de93..bab98eff29 100644 --- a/usr/src/cmd/refer/inv3.c +++ b/usr/src/cmd/refer/inv3.c @@ -1,37 +1,35 @@ +/* + * 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. */ -/* - * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc. - * All Rights Reserved. - */ +#pragma ident "%Z%%M% %I% %E% SMI" -#pragma ident "%Z%%M% %I% %E% SMI" - -getargs(s, arps) -char *s, *arps[]; +int +getargs(char *s, char *arps[]) { int i = 0; - while (1) - { + while (1) { arps[i++] = s; - while (*s != 0 && *s!=' '&& *s != '\t') + while (*s != 0 && *s != ' ' && *s != '\t') s++; if (*s == 0) break; *s++ = 0; - while (*s==' ' || *s=='\t') + while (*s == ' ' || *s == '\t') s++; - if (*s==0) + if (*s == 0) break; } - return(i); + return (i); } diff --git a/usr/src/cmd/refer/inv5.c b/usr/src/cmd/refer/inv5.c index f31af7b815..23b901c10d 100644 --- a/usr/src/cmd/refer/inv5.c +++ b/usr/src/cmd/refer/inv5.c @@ -1,25 +1,26 @@ +/* + * 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. */ -/* - * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc. - * All Rights Reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" +#pragma ident "%Z%%M% %I% %E% SMI" #include <stdio.h> #include <locale.h> -recopy (ft, fb, fa, nhash) -FILE *ft, *fb, *fa; +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; @@ -29,40 +30,35 @@ FILE *ft, *fb, *fa; int (*getfun)(); long *hpt_l; long k, lp; - if (fa==NULL) - { - err(gettext("No old pointers"),0); - return; + 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); + 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); + 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++) - { + 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); + while ((k = (*getfun)(fb)) != -1) + fprintf(ft, "%04d %06ld\n", i, k); } fclose(fb); - return(n); + return (n); } diff --git a/usr/src/cmd/refer/inv6.c b/usr/src/cmd/refer/inv6.c index df7a199052..572c10a36d 100644 --- a/usr/src/cmd/refer/inv6.c +++ b/usr/src/cmd/refer/inv6.c @@ -1,27 +1,27 @@ +/* + * 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. */ -/* - * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc. - * All Rights Reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" +#pragma ident "%Z%%M% %I% %E% SMI" #include <stdio.h> #include <assert.h> -whash(ft, fa, fb, nhash, iflong, ptotct, phused) -FILE *fa, *fb, *ft; -int nhash, *phused; -long *ptotct; +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; @@ -30,68 +30,62 @@ long *ptotct; long point; long opoint = -1; int m; - int k; + 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 = (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)) - { + lp = 0; + while (fgets(line, 100, ft)) { totct++; sscanf(line, "%d %ld", &k, &point); - if (hash < k) - { + if (hash < k) { hused++; - if (iflong) putl(-1L, fb); + if (iflong) putl(-1L, fb); else putw(-1, fb); - hfreq[hash]=ct; - while (hash<k) - { + hfreq[hash] = ct; + while (hash < k) { hpt[++hash] = lp; hfreq[hash] = 0; } - hpt[hash] = lp += iflong? sizeof(long) : sizeof(int); - opoint= -1; - ct=0; + hpt[hash] = lp += iflong ? sizeof (long) : sizeof (int); + opoint = -1; + ct = 0; } - if (point!=opoint) - { + if (point != opoint) { if (iflong) - putl(opoint=point, fb); + putl(opoint = point, fb); else - putw( (int)(opoint=point), fb); - lp += iflong? sizeof(long) : sizeof(int); + 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); + 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; } -putl(ll, f) -long ll; -FILE *f; +static void +putl(long ll, FILE *f) { putw(ll, f); } long -getl(f) -FILE *f; +getl(FILE *f) { - return(getw(f)); + return (getw(f)); } diff --git a/usr/src/cmd/refer/lookbib.c b/usr/src/cmd/refer/lookbib.c index f9682ebc8c..d66184e08e 100644 --- a/usr/src/cmd/refer/lookbib.c +++ b/usr/src/cmd/refer/lookbib.c @@ -1,27 +1,29 @@ +/* + * 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. */ -/* - * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc. - * All Rights Reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" +#pragma ident "%Z%%M% %I% %E% SMI" #include <stdio.h> #include <ctype.h> #include <locale.h> -main(argc, argv) /* look in biblio for record matching keywords */ -int argc; -char **argv; +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]; @@ -29,7 +31,7 @@ char **argv; (void) setlocale(LC_ALL, ""); #if !defined(TEXT_DOMAIN) -#define TEXT_DOMAIN "SYS_TEST" +#define TEXT_DOMAIN "SYS_TEST" #endif (void) textdomain(TEXT_DOMAIN); @@ -40,7 +42,7 @@ char **argv; } sprintf(s, "%s.ia", argv[1]); if (access(s, 0) == -1) { - sprintf (s, "%s", argv[1]); + sprintf(s, "%s", argv[1]); if (access(s, 0) == -1) { perror(s); fprintf(stderr, gettext("\tNeither index file %s.ia \ @@ -55,7 +57,7 @@ nor reference file %s found\n"), s, s); if (*s == 'y') instruct(); } - again: +again: fprintf(stderr, "> "); if (fgets(s, BUFSIZ, stdin)) { if (*s == '\n') @@ -72,19 +74,19 @@ nor reference file %s found\n"), s, s); goto again; } fprintf(stderr, gettext("EOT\n")); - exit(0); - /* NOTREACHED */ + return (0); } -map_lower(s) /* map string s to lower case */ -char *s; +static void +map_lower(char *s) /* map string s to lower case */ { - for ( ; *s; ++s) + for (; *s; ++s) if (isupper(*s)) *s = tolower(*s); } -instruct() +static void +instruct(void) { fputs(gettext( "\nType keywords (such as author and date) after the > prompt.\n\ diff --git a/usr/src/cmd/refer/mkey1.c b/usr/src/cmd/refer/mkey1.c index 93ce60bea2..6ecfdc841d 100644 --- a/usr/src/cmd/refer/mkey1.c +++ b/usr/src/cmd/refer/mkey1.c @@ -1,19 +1,18 @@ +/* + * 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. */ -/* - * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc. - * All Rights Reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" +#pragma ident "%Z%%M% %I% %E% SMI" #include <stdio.h> #include <locale.h> @@ -26,10 +25,15 @@ int minlen = 3; extern int comcount; char *iglist = "XYZ#"; -main (argc,argv) -char *argv[]; +extern void dofile(); +extern void err(); +extern char *trimnl(); + +int +main(int argc, char *argv[]) { - /* this program expects as its arguments a list of + /* + * 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 @@ -46,35 +50,33 @@ char *argv[]; (void) setlocale(LC_ALL, ""); #if !defined(TEXT_DOMAIN) -#define TEXT_DOMAIN "SYS_TEST" +#define TEXT_DOMAIN "SYS_TEST" #endif (void) textdomain(TEXT_DOMAIN); - while (argc>1 && argv[1][0] == '-') - { - switch(argv[1][1]) - { + while (argc > 1 && argv[1][0] == '-') { + switch (argv[1][1]) { case 'c': comname = argv[2]; - argv++; + argv++; argc--; break; case 'w': - wholefile = 1; + wholefile = 1; break; case 'f': inlist = argv[2]; - argv++; + argv++; argc--; break; case 'i': iglist = argv[2]; - argv++; + argv++; argc--; break; case 'l': minlen = atoi(argv[1]+2); - if (minlen<=0) minlen=3; + if (minlen <= 0) minlen = 3; break; case 'n': /* number of common words to use */ comcount = atoi(argv[1]+2); @@ -86,34 +88,29 @@ char *argv[]; labels = 0; break; } - argc--; + argc--; argv++; } - if (inlist) - { + if (inlist) { ff = fopen(inlist, "r"); - while (fgets(qn, 200, ff)) - { + while (fgets(qn, 200, ff)) { trimnl(qn); - f = fopen (qn, "r"); - if (f!=NULL) + f = fopen(qn, "r"); + if (f != NULL) dofile(f, qn); else - fprintf(stderr, gettext("Can't read %s\n"),qn); + fprintf(stderr, gettext("Can't read %s\n"), qn); } - } - else - if (argc<=1) + } 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); + 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); } - exit(0); - /* NOTREACHED */ + return (0); } diff --git a/usr/src/cmd/refer/mkey2.c b/usr/src/cmd/refer/mkey2.c index d59186e9cc..121825950c 100644 --- a/usr/src/cmd/refer/mkey2.c +++ b/usr/src/cmd/refer/mkey2.c @@ -1,164 +1,158 @@ +/* + * 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. */ -/* - * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc. - * All Rights Reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" +#pragma ident "%Z%%M% %I% %E% SMI" #include <stdio.h> #include <ctype.h> -#define MAXLINE 500 +#define MAXLINE 500 static int eof = 0; static long lp, lim; static int alph, used, prevc; static char *p, key[20]; -dofile(f, name) -FILE *f; -char *name; +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; - long grec(); extern int wholefile; extern char *iglist; - alph=used=prevc=eof=0; + 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; + 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++) + 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); + } else { + p = key; + used = alph = 0; + while ((c = getc(f)) != EOF && used < keycount) + chkey(c, name); if (used) putchar('\n'); } fclose(f); } -outkey( ky, lead, trail) -char *ky; +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 (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); + return (0); if (common(ky)) - return(0); - return(1); + return (0); + return (1); } -long -grec (s, f) -char *s; -FILE *f; +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); + if (eof) + return (0); *s = 0; - while (fgets(tm, 200, f)) - { + while (fgets(tm, 200, f)) { tlen += strlen(tm); if (tm[0] == '%' || tm[0] == '.') curtype = tm[1]; - if (tlen < MAXLINE && mindex(iglist,curtype)==0) + 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)); + 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); + eof = 1; + return (s[0] ? len : 0L); } char * -trimnl(ln) -char *ln; +trimnl(char *ln) { - register char *p = ln; + char *p = ln; while (*p) p++; p--; - if (*p == '\n') *p=0; - return(ln); + if (*p == '\n') *p = 0; + return (ln); } -chkey (c, name) +static void +chkey(int c, char *name) { extern int labels; extern int wholefile; - if (isalpha(c) || isdigit(c)) - { + if (isalpha(c) || isdigit(c)) { if (alph++ < 6) *p++ = c; - } - else - { + } else { *p = 0; - for(p=key; *p; p++) + 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); + 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 + } else putchar(' '); fputs(key, stdout); used++; } - prevc=c; - alph=0; + prevc = c; + alph = 0; } } diff --git a/usr/src/cmd/refer/mkey3.c b/usr/src/cmd/refer/mkey3.c index 378c5af33e..93f0c7673f 100644 --- a/usr/src/cmd/refer/mkey3.c +++ b/usr/src/cmd/refer/mkey3.c @@ -1,23 +1,22 @@ +/* + * 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. */ -/* - * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc. - * All Rights Reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" +#pragma ident "%Z%%M% %I% %E% SMI" #include <stdio.h> -#define COMNUM 500 -#define COMTSIZE 997 +#define COMNUM 500 +#define COMTSIZE 997 char *comname = "/usr/lib/refer/eign"; static int cgate = 0; @@ -27,44 +26,51 @@ static char cbuf[COMNUM*9]; static char *cwds[COMTSIZE]; static char *cbp; -common (s) -char *s; +extern int hash(); +extern char *trimnl(); + +static void cominit(void); +static int c_look(char *, int); + +int +common(char *s) { - if (cgate==0) cominit(); + if (cgate == 0) cominit(); return (c_look(s, 1)); } -cominit() +static void +cominit(void) { int i; FILE *f; - cgate=1; + cgate = 1; f = fopen(comname, "r"); - if (f==NULL) return; - cbp=cbuf; - for(i=0; i<comcount; i++) - { - if (fgets(cbp, 15, f)==NULL) + 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++); + c_look(cbp, 0); + while (*cbp++) + ; } fclose(f); } -c_look (s, fl) -char *s; +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); + while (cwds[h] != 0) { + if (strcmp(s, cwds[h]) == 0) + return (1); h = (h+1) % (COMTSIZE); } - if (fl==0) + if (fl == 0) cwds[h] = s; - return(0); + return (0); } diff --git a/usr/src/cmd/refer/refer1.c b/usr/src/cmd/refer/refer1.c index 553dc43e5d..f21504bdf4 100644 --- a/usr/src/cmd/refer/refer1.c +++ b/usr/src/cmd/refer/refer1.c @@ -1,41 +1,52 @@ +/* + * 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. */ -/* - * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc. - * All Rights Reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" +#pragma ident "%Z%%M% %I% %E% SMI" +#include <stdlib.h> #include <signal.h> #include <locale.h> #include "refer..c" -main(argc,argv) /* process command-line arguments */ -char *argv[]; +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" +#define TEXT_DOMAIN "SYS_TEST" #endif (void) textdomain(TEXT_DOMAIN); signals(); while (argc > 1 && argv[1][0] == '-') { - switch(argv[1][1]) { + switch (argv[1][1]) { case 'e': - endpush++; + endpush++; break; case 's': sort++; @@ -43,7 +54,7 @@ char *argv[]; if (argv[1][2]) keystr = argv[1]+2; break; - case 'l': + case 'l': labels++; s = argv[1]+2; nmlen = atoi(s); @@ -60,15 +71,16 @@ char *argv[]; nodeflt = 1; break; case 'p': - argc--; + argc--; argv++; *search++ = argv[1]; if (search-rdata > NSERCH) - err(gettext("too many -p options (%d)"), NSERCH); + err(gettext( + "too many -p options (%d)"), NSERCH); break; case 'a': authrev = atoi(argv[1]+2); - if (authrev<=0) + if (authrev <= 0) authrev = 1000; break; case 'b': @@ -94,7 +106,7 @@ char *argv[]; postpunct++; break; } - argc--; + argc--; argv++; } if (getenv("REFER") != NULL) @@ -116,15 +128,15 @@ char *argv[]; fo = ftemp; fprintf(stderr, gettext("Can't open scratch file")); } - sep = 002; /* separate records without confusing sort..*/ - } else + 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--; + argc--; argv++; if (in == NULL) { err(gettext("Can't read %s"), Ifile); @@ -151,13 +163,13 @@ char *argv[]; recopy(ofile); clfgrep(); cleanup(); - exit(0); - /* NOTREACHED */ + return (0); } extern void intr(); -signals() +void +signals(void) { if (signal(SIGINT, SIG_IGN) != SIG_IGN) signal(SIGINT, intr); @@ -166,14 +178,16 @@ signals() signal(SIGTERM, intr); } -void intr() +void +intr(void) { signal(SIGINT, SIG_IGN); cleanup(); exit(1); } -cleanup() +void +cleanup(void) { if (tfile[0]) unlink(tfile); diff --git a/usr/src/cmd/refer/refer2.c b/usr/src/cmd/refer/refer2.c index fd66a91698..f6fe088d3c 100644 --- a/usr/src/cmd/refer/refer2.c +++ b/usr/src/cmd/refer/refer2.c @@ -1,39 +1,54 @@ +/* + * 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. */ -/* - * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc. - * All Rights Reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" +#pragma ident "%Z%%M% %I% %E% SMI" #include "refer..c" #include <locale.h> -#define NFLD 30 -#define TLEN 512 +#define NFLD 30 +#define TLEN 512 extern FILE *in; char one[ANSLEN]; int onelen = ANSLEN; static char dr [100] = ""; -doref(line1) -char *line1; +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: +again: buff[0] = dbuff[0] = NULL; if (biblio && Iline == 1 && line1[0] == '%') strcat(dbuff, line1); @@ -55,8 +70,8 @@ char *line1; } if (biblio && line[0] == '\n' && feof(in)) return; - if (strcmp(buff, "$LIST$\n")==0) { - assert (dbuff[0] == 0); + if (strcmp(buff, "$LIST$\n") == 0) { + assert(dbuff[0] == 0); dumpold(); return; } @@ -81,7 +96,7 @@ char *line1; } if (alph == 0 && digs > 0) { r = p-digs; - if (digs != 4 || atoi(r)/100 != 19) { + if (digs != 4 || atoi(r)/100 != 19) { while (r < p) *r++ = ' '; } @@ -97,10 +112,12 @@ char *line1; corout(buff, temp, "hunt", *sr, TLEN); assert(strlen(temp) < TLEN); if (strlen(temp)+strlen(answer) > BUFSIZ) - err(gettext("Accumulated answers too large"),0); + err(gettext( + "Accumulated answers too large"), 0); strcat(answer, temp); - if (strlen(answer)>BUFSIZ) - err(gettext("answer too long (%d)"), strlen(answer)); + if (strlen(answer) > BUFSIZ) + err(gettext("answer too long (%d)"), + strlen(answer)); if (newline(answer) > 0) break; } @@ -113,7 +130,8 @@ char *line1; fprintf(stderr, gettext("No such paper: %s\n"), buff); return; default: - fprintf(stderr, gettext("Too many hits: %s\n"), trimnl(buff)); + fprintf(stderr, gettext( + "Too many hits: %s\n"), trimnl(buff)); choices(answer); p = buff; while (*p != '\n') @@ -126,7 +144,8 @@ char *line1; nf = tabs(flds, one); nf += tabs(flds+nf, dbuff); assert(nf < NFLD); - putsig(nf,flds,nr,line1,line,0); + putsig(nf, flds, nr, line1, + line, 0); } return; } @@ -153,19 +172,19 @@ char *line1; fprintf(fo, "%s%c%s", convert+1, sep, line+3); } -newline(s) -char *s; +static int +newline(char *s) { int k = 0, c; while (c = *s++) if (c == '\n') k++; - return(k); + return (k); } -choices(buff) -char *buff; +void +choices(char *buff) { char ob[BUFSIZ], *p, *r, *q, *t; int nl; @@ -176,29 +195,31 @@ char *buff; corout(r, ob, "deliv", dr, BUFSIZ); nl = 1; for (q = ob; *q; q++) { - if (nl && (q[0]=='.'||q[0]=='%') && q[1]=='T') { + if (nl && (q[0] == '.' || q[0] == '%') && + q[1] == 'T') { q += 3; for (t = q; *t && *t != '\n'; t++) ; - *t = 0; + *t = 0; fprintf(stderr, "%.70s\n", q); - q = 0; - break; - } + q = 0; + break; + } nl = *q == '\n'; - } + } if (q) - fprintf(stderr, gettext("??? at %s\n"),r); - r=p; + fprintf(stderr, gettext("??? at %s\n"), r); + r = p; } } } -control(c) +int +control(char c) { if (c == '.') - return(1); + return (1); if (c == '%') - return(1); - return(0); + return (1); + return (0); } diff --git a/usr/src/cmd/refer/refer3.c b/usr/src/cmd/refer/refer3.c index dc1a3ebeaa..29b25aba57 100644 --- a/usr/src/cmd/refer/refer3.c +++ b/usr/src/cmd/refer/refer3.c @@ -1,51 +1,51 @@ +/* + * 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. */ -/* - * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc. - * All Rights Reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" +#pragma ident "%Z%%M% %I% %E% SMI" #include "refer..c" -#define move(x, y) close(y); dup(x); close(x); +#define move(x, y) close(y); dup(x); close(x); + +extern void err(); -corout(in, out, rprog, arg, outlen) -char *in, *out, *rprog; +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]; + pipe(pipev); + fr1 = pipev[0]; fw1 = pipev[1]; - pipe(pipev); - fr2 = pipev[0]; + pipe(pipev); + fr2 = pipev[0]; fw2 = pipev[1]; - if (fork() == 0) - { - close(fw1); + 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(fw2); close(fr1); - write(fw1, in , strlen(in)); + write(fw1, in, strlen(in)); close(fw1); wait(&status); n = read(fr2, out, outlen); out[n] = 0; close(fr2); - return(n); + return (n); } diff --git a/usr/src/cmd/refer/refer4.c b/usr/src/cmd/refer/refer4.c index 4e4b483ec8..e8cd5f22ab 100644 --- a/usr/src/cmd/refer/refer4.c +++ b/usr/src/cmd/refer/refer4.c @@ -1,33 +1,37 @@ +/* + * 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. */ -/* - * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc. - * All Rights Reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" +#pragma ident "%Z%%M% %I% %E% SMI" #include "refer..c" #include <locale.h> -#define punctuat(c) (c=='.' || c=='?' || c=='!' || c==',' || c==';' || c==':') +#define punctuat(c) (c == '.' || c == '?' || c == '!' || \ + c == ',' || c == ';' || c == ':') -static gate = 0; +static int gate = 0; static char buff[BUFSIZ]; -output(s) -char *s; +extern void err(); + +char *trimnl(char *); + +void +output(char *s) { if (gate) - fputs(buff,ftemp); + fputs(buff, ftemp); else gate = 1; strcpy(buff, s); @@ -35,8 +39,8 @@ char *s; err(gettext("one buff too big (%d)!"), BUFSIZ); } -append(s) -char *s; +void +append(char *s) { char *p; int lch; @@ -49,7 +53,7 @@ char *s; *p = NULL; else /* pre-punctuation */ switch (lch) { - case '.': + case '.': case '?': case '!': case ',': @@ -60,14 +64,14 @@ char *s; } strcat(buff, s); if (postpunct) - switch(lch) { - case '.': + switch (lch) { + case '.': case '?': case '!': case ',': case ';': case ':': - for(p = buff; *p; p++) + for (p = buff; *p; p++) ; if (*--p == '\n') *p = NULL; @@ -79,23 +83,23 @@ char *s; err(gettext("output buff too long (%d)"), BUFSIZ); } -flout() +void +flout(void) { if (gate) - fputs(buff,ftemp); + fputs(buff, ftemp); gate = 0; } char * -trimnl(ln) -char *ln; +trimnl(char *ln) { - register char *p = ln; + char *p = ln; while (*p) p++; p--; if (*p == '\n') *p = 0; - return(ln); + return (ln); } diff --git a/usr/src/cmd/refer/refer5.c b/usr/src/cmd/refer/refer5.c index e5e37a648c..61392a4ee2 100644 --- a/usr/src/cmd/refer/refer5.c +++ b/usr/src/cmd/refer/refer5.c @@ -1,24 +1,23 @@ +/* + * 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. */ -/* - * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc. - * All Rights Reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" +#pragma ident "%Z%%M% %I% %E% SMI" #include "refer..c" -#define SAME 0 -#define NFLAB 3000 /* number of bytes to record all labels */ -#define NLABC 1000 /* max number of labels */ +#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]; @@ -28,8 +27,22 @@ static char labc[NLABC]; static char stbuff[50]; static int prevsig; -putsig (nf, flds, nref, nstline, endline, toindex) /* choose signal style */ -char *flds[], *nstline, *endline; +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; @@ -46,15 +59,16 @@ char *flds[], *nstline, *endline; 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) { + 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); + 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)) { @@ -81,14 +95,12 @@ char *flds[], *nstline, *endline; } } if ((!keywant || addon) && !science) { - addch(t, keylet(t, nref)); - } - else { - tokeytab (t,nref); + addch(t, keylet(t, nref)); + } else { + tokeytab(t, nref); } } - } - else { + } else { if (sort) sprintf(t, "%c%d%c", FLAG, nref, FLAG); else @@ -96,26 +108,26 @@ char *flds[], *nstline, *endline; } 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); + 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)); + 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; + strcpy(stline, nstline); + prevsig = 1; } if (stline[2] || endline[2]) { stline += 2; endline += 2; - } - else { + } else { stline = "\\*([."; endline = "\\*(.]"; } @@ -134,7 +146,7 @@ char *flds[], *nstline, *endline; prevsig = 0; if (fo == fhide) { int ch; - fclose(fhide); + fclose(fhide); fhide = fopen(hidenam, "r"); fo = ftemp; while ((ch = getc(fhide)) != EOF) @@ -142,8 +154,7 @@ char *flds[], *nstline, *endline; fclose(fhide); unlink(hidenam); } - } - else { + } else { if (labels) { strcat(sig, ",\\|"); } else { @@ -162,30 +173,30 @@ char *flds[], *nstline, *endline; #endif fhide = fopen(hidenam, "w"); if (fhide == NULL) - err(gettext("Can't get scratch file %s"), - hidenam); + 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); + fprintf(fo, ".ds [F %s%c", t, sep); if (bare > 0) flout(); #if EBUG - fprintf(stderr, "sig is now %s\n",sig); + fprintf(stderr, "sig is now %s\n", sig); #endif } char * -fpar (nf, flds, out, c, seq, prepend) -char *flds[], *out; +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++) + 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') { @@ -197,33 +208,33 @@ char *flds[], *out; if (prefix("The ", p)) p += 4; mycpy2(out, p, 20); - return(out); + 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--; + for (; *p; p++) + ; + while (p > s && *p != ' ') + p--; } /* special wart for authors */ - if (c == 'A' && (p[-1] == ',' || p[1] =='(')) { + if (c == 'A' && (p[-1] == ',' || p[1] == '(')) { p--; while (p > s && *p != ' ') p--; mycpy(out, p+1); - } - else + } else strcpy(out, p+1); if (c == 'A' && prepend) initadd(out, flds[i]+2, p); - return(out); + return (out); } - return(0); + return (0); } -putkey(nf, flds, nref, keystr) -char *flds[], *keystr; +void +putkey(int nf, char *flds[], int nref, char *keystr) { char t1[50], *sf; int ctype, i, count; @@ -234,11 +245,11 @@ char *flds[], *keystr; else { while (ctype = *keystr++) { count = atoi(keystr); - if (*keystr=='+') - count=999; + if (*keystr == '+') + count = 999; if (count <= 0) count = 1; - for(i = 1; i <= count; i++) { + for (i = 1; i <= count; i++) { sf = fpar(nf, flds, t1, ctype, i, 1); if (sf == 0) break; @@ -251,25 +262,25 @@ char *flds[], *keystr; } -tokeytab (t, nref) -char *t; +void +tokeytab(char *t, int nref) { - strcpy(labtab[nref]=lbp, t); + strcpy(labtab[nref] = lbp, t); while (*lbp++) ; } -keylet(t, nref) -char *t; +char +keylet(char *t, int nref) { int i; int x = 'a' - 1; - for(i = 1; i < nref; i++) { + for (i = 1; i < nref; i++) { if (strcmp(labtab[i], t) == 0) x = labc[i]; } - tokeytab (t, nref); + tokeytab(t, nref); if (lbp-bflab > NFLAB) err(gettext("bflab overflow (%d)"), NFLAB); if (nref > NLABC) @@ -277,23 +288,23 @@ char *t; #if EBUG fprintf(stderr, "lbp up to %d of %d\n", lbp-bflab, NFLAB); #endif - return(labc[nref] = x+1); + return (labc[nref] = x+1); } -mycpy(s, t) -char *s, *t; +static void +mycpy(char *s, char *t) { while (*t && *t != ',' && *t != ' ') *s++ = *t++; *s = 0; } -mycpy2(s, t, n) -char *s, *t; +static void +mycpy2(char *s, char *t, int n) { int c; - while (n-- && (c= *t++) > 0) { + while (n-- && (c = *t++) > 0) { if (c == ' ') c = '-'; *s++ = c; @@ -301,8 +312,8 @@ char *s, *t; *s = 0; } -initadd(to, from, stop) -char *to, *from, *stop; +static void +initadd(char *to, char *from, char *stop) { int c, nalph = 1; @@ -335,10 +346,10 @@ char *s; for (p = articles; *p; p++) { r2 = s; - for (r1 = *p; ((*r1 ^ *r2) & ~040 ) == 0; r1++) + for (r1 = *p; ((*r1 ^ *r2) & ~040) == 0; r1++) r2++; if (*r1 == 0 && *r2 != 0) - return(r2); + return (r2); } - return(s); + return (s); } diff --git a/usr/src/cmd/refer/refer6.c b/usr/src/cmd/refer/refer6.c index 61605ece2f..2c73b7f6b3 100644 --- a/usr/src/cmd/refer/refer6.c +++ b/usr/src/cmd/refer/refer6.c @@ -1,26 +1,34 @@ +/* + * 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. */ -/* - * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc. - * All Rights Reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" +#pragma ident "%Z%%M% %I% %E% SMI" #include "refer..c" -#define dsde (macro? "de" : "ds") -#define ifnl (macro? sep : ' ') +#define dsde (macro? "de" : "ds") +#define ifnl (macro? sep : ' ') -putref(n, tvec) -char *tvec[]; +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]; @@ -39,33 +47,33 @@ char *tvec[]; cch = s[2]; tx = s+3; macro = 1; - } - else { + } else { cch = s[1]; tx = s+2; macro = 0; } - } - else { + } else { cch = lastype; tx = s; } #if EBUG - fprintf(stderr, "smallcaps %s cch %c\n",smallcaps, cch); + 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); + 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); + fprintf(fo, ".as [%c \" %s%c", + lastype, tx, sep); if (lastype == 'T') - ltitle = (mindex(".;,?", last(tx))!=0); + ltitle = (mindex(".;,?", + last(tx)) != 0); if (lastype == 'A') lauth = last(tx) == '.'; } @@ -74,40 +82,40 @@ char *tvec[]; if (mindex("XYZ[]", cch)) { /* skip these */ lastype = 0; continue; - } - else { + } 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); + fprintf(fo, ".de [%c%c%s%c", + cch, sep, tx, sep); else - fprintf(fo, - ".ds [%c%s%c", cch,tx,sep); + fprintf(fo, ".ds [%c%s%c", + cch, tx, sep); else { - la = (tvec[i+1][1]!='A'); + 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", + mindex(smallcaps, 'A') ? + " \\s-2AND\\s+2" : " and"); fprintf(fo, "%s%c", tx, sep); } lauth = last(tx) == '.'; - } - else { + } else { if (macro) - fprintf(fo, - ".de [%c%c%s%c",cch,sep,tx,sep); + fprintf(fo, ".de [%c%c%s%c", + cch, sep, tx, sep); else - fprintf(fo, ".ds [%c%s%c",cch,tx, sep); + fprintf(fo, ".ds [%c%s%c", + cch, tx, sep); } } if (cch == 'P') - fprintf(fo, ".nr [P %d%c", mindex(s, '-')!=0, sep); + fprintf(fo, ".nr [P %d%c", mindex(s, '-') != 0, sep); lastype = cch; if (cch == 'T') ltitle = (mindex(".;,?", last(tx)) != 0); @@ -122,8 +130,8 @@ char *tvec[]; fprintf(fo, ".][ %s%c", class(n, tvec), '\n'); } -tabs (sv, line) -char *sv[], *line; +int +tabs(char *sv[], char *line) { char *p; int n = 0; @@ -135,41 +143,39 @@ char *sv[], *line; sv[n++] = p+1; } } - return(n-1); + return (n-1); } char * -class (nt, tv) -char *tv[]; +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')) + 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')) + if (hastype(nt, tv, 'G')) return ("4 tech-report"); - if (hastype (nt, tv, 'I')) - return("2 book"); - if (hastype (nt, tv,'M')) + if (hastype(nt, tv, 'I')) + return ("2 book"); + if (hastype(nt, tv, 'M')) return ("5 bell-tm"); - return("0 other"); + return ("0 other"); } -hastype (nt, tv, c) -char *tv[]; +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); + if (control(tv[i][0]) && tv[i][1] == c) + return (1); + return (0); } char * -caps(a, b) -char *a, *b; +caps(char *a, char *b) { char *p; int c, alph, this; @@ -202,12 +208,11 @@ char *a, *b; *b++ = '2'; } *b = 0; - return(p); + return (p); } char * -revauth(s, b) -char *s, *b; +revauth(char *s, char *b) { char *init, *name, *jr, *p, *bcop; @@ -216,11 +221,11 @@ char *s, *b; while (*name) name++; jr = name; - while (name > init && *name!= ' ') + while (name > init && *name != ' ') name--; - if (name[-1] == ',' || name[-1]== '(' ) { + if (name[-1] == ',' || name[-1] == '(') { jr = --name; - while (name>init && *name != ' ') + while (name > init && *name != ' ') name--; } p = name; @@ -231,16 +236,16 @@ char *s, *b; *b++ = *init++; if (*jr) jr++; - while(*jr) + while (*jr) *b++ = *jr++; *b++ = 0; - return(bcop); + return (bcop); } -last(s) -char *s; +static char +last(char *s) { while (*s) s++; - return(*--s); + return (*--s); } diff --git a/usr/src/cmd/refer/refer7.c b/usr/src/cmd/refer/refer7.c index de74f6da8b..717880d63e 100644 --- a/usr/src/cmd/refer/refer7.c +++ b/usr/src/cmd/refer/refer7.c @@ -1,45 +1,51 @@ +/* + * 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. */ -/* - * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc. - * All Rights Reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" +#pragma ident "%Z%%M% %I% %E% SMI" #include "refer..c" #include <locale.h> int newr[250]; -chkdup(tag) -char *tag; +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); + 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++); + while (*rtp++) + ; if (rtp > reftext + NRFTXT) err(gettext("reference pointers too long (%d)"), rtp-reftext); - return(0); + return (0); } -dumpold() +void +dumpold(void) { FILE *fi; int c, g1 = 0, nr = 1; @@ -75,10 +81,10 @@ dumpold() 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); + fprintf(stderr, "nr %d assigned to atoi(tb) %d\n", + nr, atoi(tb)); +#endif + fprintf(ftemp, "%d", nr); continue; } putc(c, ftemp); @@ -90,8 +96,8 @@ dumpold() fprintf(ftemp, ".]>\n"); } -recopy (fnam) -char *fnam; +void +recopy(char *fnam) { int c; int *wref = NULL; @@ -101,7 +107,7 @@ char *fnam; char sig[MXSIG]; extern int *realloc(); - wref = (int *)calloc((unsigned)wsize, (unsigned)sizeof(int)); + wref = (int *)calloc((unsigned)wsize, (unsigned)sizeof (int)); fclose(ftemp); ftemp = fopen(fnam, "r"); if (ftemp == NULL) { @@ -123,16 +129,17 @@ char *fnam; 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.")); + 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) + if ((c = getc(ftemp)) == AFLAG) continue; wref[wcnt] = 0; - condense(wref,wcnt,sig); + condense(wref, wcnt, sig); wcnt = 0; printf("%s", sig); } @@ -147,31 +154,29 @@ char *fnam; * 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 */ -condense(wref, wcnt, sig) -int *wref; -int wcnt; -char *sig; +static void +condense(int *wref, int wcnt, char *sig) { - register int i = 0; + int i = 0; char wt[4]; extern int wswap(); - qsort(wref, wcnt, sizeof(int), wswap); + qsort(wref, wcnt, sizeof (int), wswap); sig[0] = 0; while (i < wcnt) { - sprintf(wt,"%d",wref[i]); - strcat(sig,wt); + 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,",\\|"); + strcat(sig, ",\\|"); } } -wswap(iw1, iw2) -register int *iw1,*iw2; +int +wswap(int *iw1, int *iw2) { - return(*iw1 - *iw2); + return (*iw1 - *iw2); } diff --git a/usr/src/cmd/refer/refer8.c b/usr/src/cmd/refer/refer8.c index 4c7b8e1d79..6894439d4e 100644 --- a/usr/src/cmd/refer/refer8.c +++ b/usr/src/cmd/refer/refer8.c @@ -1,52 +1,50 @@ +/* + * 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. */ -/* - * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc. - * All Rights Reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" +#pragma ident "%Z%%M% %I% %E% SMI" #include "refer..c" static char ahead[1024]; static int peeked = 0; -static char *noteof = (char *) 1; +static char *noteof = (char *)1; char * -input(s) -char *s; +input(char *s) { if (peeked) { peeked = 0; if (noteof == 0) - return(0); + return (0); strcpy(s, ahead); - return(s); + return (s); } - return(fgets(s, 1000, in)); + return (fgets(s, 1000, in)); } char * -lookat() +lookat(void) { if (peeked) - return(ahead); + return (ahead); noteof = input(ahead); peeked = 1; - return(noteof); + return (noteof); } -addch(s, c) -char *s; +void +addch(char *s, char c) { while (*s) s++; diff --git a/usr/src/cmd/refer/shell.c b/usr/src/cmd/refer/shell.c index 0a08a0c90b..4801bb17bf 100644 --- a/usr/src/cmd/refer/shell.c +++ b/usr/src/cmd/refer/shell.c @@ -1,45 +1,42 @@ +/* + * 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. */ -/* - * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc. - * All Rights Reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" +#pragma ident "%Z%%M% %I% %E% SMI" /* * SORTS UP. * IF THERE ARE NO EXCHANGES (IEX=0) ON A SWEEP * THE COMPARISON GAP (IGAP) IS HALVED FOR THE NEXT SWEEP */ -shell (n, comp, exch) -int (*comp)(), (*exch)(); +void +shell(int n, int (*comp)(), int (*exch)()) { int igap, iplusg, iex, i, imax; - igap=n; - while (igap > 1) - { + igap = n; + while (igap > 1) { igap /= 2; imax = n-igap; - do - { - iex=0; - for(i=0; i<imax; i++) - { + do { + iex = 0; + for (i = 0; i < imax; i++) { iplusg = i + igap; - if ((*comp) (i, iplusg) ) continue; + if ((*comp)(i, iplusg)) continue; (*exch) (i, iplusg); - iex=1; + iex = 1; } - } - while (iex>0); + } + while (iex > 0) + ; } } diff --git a/usr/src/cmd/refer/sortbib.c b/usr/src/cmd/refer/sortbib.c index 9482ba3049..b05bf3b96e 100644 --- a/usr/src/cmd/refer/sortbib.c +++ b/usr/src/cmd/refer/sortbib.c @@ -1,18 +1,17 @@ +/* + * 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. */ -/* - * Copyright (c) 1983-1988 by Sun Microsystems, Inc. - * All Rights Reserved. - */ - #pragma ident "%Z%%M% %I% %E% SMI" #include <locale.h> @@ -29,13 +28,21 @@ 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? */ -main(argc, argv) /* sortbib: sort bibliographic database in place */ -int argc; -char *argv[]; +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 onintr(); (void) setlocale(LC_ALL, ""); @@ -44,22 +51,19 @@ char *argv[]; #endif (void) textdomain(TEXT_DOMAIN); - if (argc == 1) /* can't use stdin for seeking anyway */ - { + 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 (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 */ - { + if (argc > MXFILES+1) { /* too many open file streams */ fprintf(stderr, gettext("sortbib: More than %d databases specified\n"), MXFILES); @@ -74,7 +78,7 @@ char *argv[]; (void) close(tmpfd); if (signal(SIGINT, SIG_IGN) != SIG_IGN) /* remove if interrupted */ - signal(SIGINT, onintr); + signal(SIGINT, (void(*)())onintr); if ((tfp = fopen(tempfile, "w")) == NULL) { (void) unlink(tempfile); error(tempfile); @@ -84,55 +88,49 @@ char *argv[]; fclose(tfp); deliver(fp, tfp); /* do disk seeks and read from biblio files */ (void) unlink(tempfile); - exit(0); - /* NOTREACHED */ + return (0); } int rsmode = 0; /* record separator: 1 = null line, 2 = bracket */ -sortbib(fp, tfp, i) /* read records, prepare list for sorting */ -FILE *fp, *tfp; -int i; +/* 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)) - { + 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 (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 (line[0] == '.' && line[1] == '[') { /* also accept .[ .] */ if (!rsmode) rsmode = 2; /* bracket pair mode */ if (rsmode == 2) newrec = 1; } - if (newrec) /* by whatever means above */ - { + 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); + gettext("sortbib: record %d longer than %d " + "(%d)\n"), recno, BUF*8, length); (void) unlink(tempfile); exit(1); } - if (recno++) /* info for sorting */ - { + 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]); + i, lastoffset, length, + fld[0], fld[1], fld[2], fld[3]); if (ferror(tfp)) { (void) unlink(tempfile); error(tempfile); @@ -147,19 +145,16 @@ int i; } offset = ftell(fp); /* measure byte offset at EOF */ length = offset - lastoffset; /* measure final record length */ - if (length > BUF*8) - { + 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 */ - { + 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]); + i, lastoffset, length, fld[0], fld[1], fld[2], fld[3]); if (ferror(tfp)) { (void) unlink(tempfile); error(tempfile); /* disk error in /tmp */ @@ -167,8 +162,9 @@ int i; } } -deliver(fp, tfp) /* deliver sorted entries out of database(s) */ -FILE *fp[], *tfp; +/* 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 */ @@ -182,8 +178,7 @@ FILE *fp[], *tfp; error("sortbib"); } tfp = fopen(tempfile, "r"); - while (fgets(str, sizeof (str), tfp)) - { + 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")); @@ -208,9 +203,9 @@ FILE *fp[], *tfp; } } -parse(line, fld) /* get fields out of line, prepare for sorting */ -char line[]; -char fld[][BUF]; +/* 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; @@ -218,13 +213,10 @@ char fld[][BUF]; for (i = 0; i < 8; i++) /* zap out old strings */ *wd[i] = NULL; 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') - { + 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 */ @@ -260,8 +252,9 @@ char fld[][BUF]; } } -article(str) /* see if string contains an article */ -char *str; +/* see if string contains an article */ +static int +article(char *str) { if (strcmp("The", str) == 0) /* English */ return (1); @@ -286,15 +279,14 @@ char *str; return (0); } -eval(keystr) /* evaluate key string for A+ marking */ -char keystr[]; +/* 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] == '+') - { + for (i = 0, j = 0; keystr[i]; i++, j++) { + if (keystr[i] == '+') { multauth = 1; i++; } @@ -305,29 +297,30 @@ char keystr[]; keystr[j] = NULL; } -error(s) /* exit in case of various system errors */ -char *s; +/* exit in case of various system errors */ +static void +error(char *s) { perror(s); exit(1); } -void -onintr() /* remove tempfile in case of interrupt */ +/* remove tempfile in case of interrupt */ +static void +onintr(void) { fprintf(stderr, gettext("\nInterrupt\n")); unlink(tempfile); exit(1); } -endcomma(str) -char *str; +static int +endcomma(char *str) { int n; n = strlen(str) - 1; - if (str[n] == ',') - { + if (str[n] == ',') { str[n] = NULL; return (1); } diff --git a/usr/src/cmd/refer/tick.c b/usr/src/cmd/refer/tick.c index 198df0480c..efa94aef5f 100644 --- a/usr/src/cmd/refer/tick.c +++ b/usr/src/cmd/refer/tick.c @@ -1,23 +1,22 @@ +/* + * 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. */ -/* - * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc. - * All Rights Reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" +#pragma ident "%Z%%M% %I% %E% SMI" /* time programs */ -# include "stdio.h" -# include "sys/types.h" +#include <stdio.h> +#include <sys/types.h> struct tbuffer { long proc_user_time; @@ -26,27 +25,32 @@ struct tbuffer { long child_system_time; }; static long start, user, systm; -tick() + +void +tick(void) { struct tbuffer tx; time_t tp; - times (&tx); - time (&tp); + times(&tx); + time(&tp); user = tx.proc_user_time; - systm= tx.proc_system_time; + systm = tx.proc_system_time; start = tp; } -tock() + +void +tock(void) { struct tbuffer tx; time_t tp; float lap, use, sys; - if (start==0) return; - times (&tx); - time (&tp); + 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); + lap, use+sys, use, sys); } |