BSD 4_3 release
[unix-history] / usr / src / usr.bin / refer / refer5.c
index 7ca0be7..2ffde4b 100644 (file)
@@ -1,13 +1,13 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)refer5.c    4.2 (Berkeley) 7/18/83";
+static char *sccsid = "@(#)refer5.c    4.7 (Berkeley) 4/23/86";
 #endif
 
 #include "refer..c"
 #define SAME 0
 #endif
 
 #include "refer..c"
 #define SAME 0
-#define NFLAB 2000
-#define NLABC 100
+#define NFLAB 3000             /* number of bytes to record all labels */
+#define NLABC 1000             /* max number of labels */
 
 
-static char sig[NLABC];
+static char sig[MXSIG];
 static char bflab[NFLAB];
 static char *labtab[NLABC];
 static char *lbp = bflab;
 static char bflab[NFLAB];
 static char *labtab[NLABC];
 static char *lbp = bflab;
@@ -15,10 +15,10 @@ static char labc[NLABC];
 static char stbuff[50];
 static int  prevsig;
 
 static char stbuff[50];
 static int  prevsig;
 
-putsig (nf, flds, nref, nstline, endline)      /* choose signal style */
+putsig (nf, flds, nref, nstline, endline, toindex)   /* choose signal style */
 char *flds[], *nstline, *endline;
 {
 char *flds[], *nstline, *endline;
 {
-       char t[100], t1[100], t2[100], format[10], *sd, *stline;
+       char t[100], t1[MXSIG], t2[100], format[10], *sd, *stline;
        int addon, another = 0;
        static FILE *fhide = 0;
        int i;
        int addon, another = 0;
        static FILE *fhide = 0;
        int i;
@@ -72,15 +72,14 @@ char *flds[], *nstline, *endline;
                }
        }
        else {
                }
        }
        else {
-               if (sort)
-                       sprintf(t, "%c%d%c", FLAG, nref, FLAG);
-               else
-                       sprintf(t, "%d", nref);
+               sprintf(t, "%c%d%c", FLAG, nref, FLAG);
        }
        another = prefix (".[", sd=lookat());
        if (another && (strcmp(".[\n", sd) != SAME))
                fprintf(stderr, "File %s line %d: punctuation ignored from: %s",
                        Ifile, Iline, sd);
        }
        another = prefix (".[", sd=lookat());
        if (another && (strcmp(".[\n", sd) != SAME))
                fprintf(stderr, "File %s line %d: punctuation ignored from: %s",
                        Ifile, Iline, sd);
+       if ((strlen(sig) + strlen(t)) > MXSIG)
+               err("sig overflow (%d)", MXSIG);
        strcat(sig, t);
 #if EBUG
        fprintf(stderr, "sig is now %s leng %d\n",sig,strlen(sig));
        strcat(sig, t);
 #if EBUG
        fprintf(stderr, "sig is now %s leng %d\n",sig,strlen(sig));
@@ -107,6 +106,8 @@ char *flds[], *nstline, *endline;
        if (bare == 0) {
                if (!another) {
                        sprintf(t1, "%s%s\%s\n", stline, sig, endline);
        if (bare == 0) {
                if (!another) {
                        sprintf(t1, "%s%s\%s\n", stline, sig, endline);
+                       if (strlen(t1) > MXSIG)
+                               err("t1 overflow (%d)", MXSIG);
                        append(t1);
                        flout();
                        sig[0] = 0;
                        append(t1);
                        flout();
                        sig[0] = 0;
@@ -123,7 +124,17 @@ char *flds[], *nstline, *endline;
                        }
                }
                else {
                        }
                }
                else {
-                       strcat(sig, ",\\|");
+                       if (labels) {
+                               strcat(sig, ",\\|");
+                       } else {
+                               /*
+                                * Seperate reference numbers with AFLAG
+                                * for later sorting and condensing.
+                                */
+                               t1[0] = AFLAG;
+                               t1[1] = '\0';
+                               strcat(sig, t1);
+                       }
                        if (fo == ftemp) {      /* hide if need be */
                                sprintf(hidenam, "/tmp/rj%dc", getpid());
 #if EBUG
                        if (fo == ftemp) {      /* hide if need be */
                                sprintf(hidenam, "/tmp/rj%dc", getpid());
 #if EBUG
@@ -132,13 +143,13 @@ char *flds[], *nstline, *endline;
                                fhide = fopen(hidenam, "w");
                                if (fhide == NULL)
                                        err("Can't get scratch file %s",
                                fhide = fopen(hidenam, "w");
                                if (fhide == NULL)
                                        err("Can't get scratch file %s",
-                                               (void) hidenam);
+                                               hidenam);
                                fo = fhide;
                        }
                }
        }
        if (bare < 2)
                                fo = fhide;
                        }
                }
        }
        if (bare < 2)
-               if (nf > 0)
+               if (nf > 0 && toindex)
                        fprintf(fo,".ds [F %s%c",t,sep);
        if (bare > 0)
                flout();
                        fprintf(fo,".ds [F %s%c",t,sep);
        if (bare > 0)
                flout();
@@ -232,7 +243,7 @@ keylet(t, nref)
 char *t;
 {
        int i;
 char *t;
 {
        int i;
-       int x = -1;
+       int x = 'a' - 1;
 
        for(i = 1; i < nref; i++) {
                if (strcmp(labtab[i], t) == 0)
 
        for(i = 1; i < nref; i++) {
                if (strcmp(labtab[i], t) == 0)
@@ -244,7 +255,7 @@ char *t;
        if (nref > NLABC)
                err("nref in labc overflow (%d)", NLABC);
 #if EBUG
        if (nref > NLABC)
                err("nref in labc overflow (%d)", NLABC);
 #if EBUG
-       fprintf(stderr, "lbp up to %d of 2000\n", lbp-bflab);
+       fprintf(stderr, "lbp up to %d of %d\n", lbp-bflab, NFLAB);
 #endif
        return(labc[nref] = x+1);
 }
 #endif
        return(labc[nref] = x+1);
 }