1*b1c8cee5Sbostic /*-
2*b1c8cee5Sbostic * %sccs.include.proprietary.c%
3*b1c8cee5Sbostic */
4*b1c8cee5Sbostic
534383f3aStut #ifndef lint
6*b1c8cee5Sbostic static char sccsid[] = "@(#)refer7.c 4.5 (Berkeley) 04/18/91";
7*b1c8cee5Sbostic #endif /* not lint */
834383f3aStut
934383f3aStut #include "refer..c"
1034383f3aStut
1134383f3aStut int newr[250];
1234383f3aStut
chkdup(tag)1334383f3aStut chkdup(tag)
1434383f3aStut char *tag;
1534383f3aStut {
1634383f3aStut int i;
1734383f3aStut
1834383f3aStut for(i = 1; i <= refnum; i++) {
1934383f3aStut if (strcmp(reftable[i], tag)==0)
2034383f3aStut return(i);
2134383f3aStut }
2234383f3aStut reftable[refnum+1] = rtp;
2334383f3aStut if (refnum >= NRFTBL)
2434383f3aStut err("too many references (%d) for table", refnum);
2534383f3aStut strcpy(rtp, tag);
2634383f3aStut while (*rtp++);
2734383f3aStut if (rtp > reftext + NRFTXT)
2834383f3aStut err("reference pointers too long (%d)", rtp-reftext);
2934383f3aStut return(0);
3034383f3aStut }
3134383f3aStut
dumpold()3234383f3aStut dumpold()
3334383f3aStut {
3434383f3aStut FILE *fi;
3534383f3aStut int c, g1 = 0, nr = 1;
3634383f3aStut
3734383f3aStut if (!endpush)
3834383f3aStut return;
395729aaadSsam if (fo != NULL) {
4034383f3aStut fclose(fo);
4134383f3aStut fo = NULL;
425729aaadSsam }
4334383f3aStut if (sort) {
4434383f3aStut char comm[100];
4524440b8eSmckusick sprintf(comm, "sort -f %s -o %s", tfile, tfile);
4634383f3aStut system(comm);
4734383f3aStut }
4834383f3aStut fi = fopen(tfile, "r");
4934383f3aStut if (fi == NULL)
5034383f3aStut return;
5134383f3aStut flout();
5234383f3aStut fprintf(ftemp, ".]<\n");
5334383f3aStut while ((c = getc(fi)) > 0) {
5434383f3aStut if (c == '\n') {
5534383f3aStut nr++;
5634383f3aStut g1 = 0;
5734383f3aStut }
5834383f3aStut if (c == sep)
5934383f3aStut c = '\n';
6034383f3aStut if (c == FLAG) {
6134383f3aStut /* make old-new ref number table */
6234383f3aStut char tb[20];
6334383f3aStut char *s = tb;
6434383f3aStut while ((c = getc(fi)) != FLAG)
6534383f3aStut *s++ = c;
6634383f3aStut *s = 0;
6734383f3aStut if (g1++ == 0)
6834383f3aStut newr[atoi(tb)] = nr;
6934383f3aStut #if EBUG
7034383f3aStut fprintf(stderr,
7134383f3aStut "nr %d assigned to atoi(tb) %d\n",nr,atoi(tb));
7234383f3aStut # endif
7334383f3aStut fprintf(ftemp,"%d", nr);
7434383f3aStut continue;
7534383f3aStut }
7634383f3aStut putc(c, ftemp);
7734383f3aStut }
7834383f3aStut fclose(fi);
7934383f3aStut #ifndef TF
8034383f3aStut unlink(tfile);
8134383f3aStut #endif
8234383f3aStut fprintf(ftemp, ".]>\n");
8334383f3aStut }
8434383f3aStut
recopy(fnam)8534383f3aStut recopy (fnam)
8634383f3aStut char *fnam;
8734383f3aStut {
8834383f3aStut int c;
899c42fd43Smckusick int *wref = NULL;
909c42fd43Smckusick int wcnt = 0;
919c42fd43Smckusick int wsize = 50;
929c42fd43Smckusick int finalrn;
939c42fd43Smckusick char sig[MXSIG];
949c42fd43Smckusick extern int *realloc();
9534383f3aStut
969c42fd43Smckusick wref = (int *)calloc((unsigned)wsize, (unsigned)sizeof(int));
9734383f3aStut fclose(ftemp);
9834383f3aStut ftemp = fopen(fnam, "r");
9934383f3aStut if (ftemp == NULL) {
10034383f3aStut fprintf(stderr, "Can't reopen %s\n", fnam);
10134383f3aStut exit(1);
10234383f3aStut }
10334383f3aStut while ((c = getc(ftemp)) != EOF) {
10434383f3aStut if (c == FLAG) {
10534383f3aStut char tb[10];
10634383f3aStut char *s = tb;
10734383f3aStut while ((c = getc(ftemp)) != FLAG)
10834383f3aStut *s++ = c;
10934383f3aStut *s = 0;
1109c42fd43Smckusick /*
1119c42fd43Smckusick * If sort was done, permute the reference number
1129c42fd43Smckusick * to obtain the final reference number, finalrn.
1139c42fd43Smckusick */
1149c42fd43Smckusick if (sort)
1159c42fd43Smckusick finalrn = newr[atoi(tb)];
1169c42fd43Smckusick else
1179c42fd43Smckusick finalrn = atoi(tb);
1189c42fd43Smckusick if ((++wcnt > wsize) &&
1199c42fd43Smckusick ((wref=realloc(wref,(wsize+=50)*sizeof(int)))==NULL)){
1209c42fd43Smckusick fprintf(stderr, "Ref condense out of memory.");
1219c42fd43Smckusick exit(1);
1229c42fd43Smckusick }
1239c42fd43Smckusick wref[wcnt-1] = finalrn;
1249c42fd43Smckusick if ((c = getc(ftemp)) == AFLAG)
12534383f3aStut continue;
1269c42fd43Smckusick wref[wcnt] = 0;
1279c42fd43Smckusick condense(wref,wcnt,sig);
1289c42fd43Smckusick wcnt = 0;
1299c42fd43Smckusick printf("%s", sig);
13034383f3aStut }
13134383f3aStut putchar(c);
13234383f3aStut }
13334383f3aStut fclose(ftemp);
13434383f3aStut unlink(fnam);
13534383f3aStut }
1369c42fd43Smckusick
1379c42fd43Smckusick /*
1389c42fd43Smckusick * sort and condense referance signals when they are placed in
1399c42fd43Smckusick * the text. Viz, the signal 1,2,3,4 is condensed to 1-4 and signals
1409c42fd43Smckusick * of the form 5,2,9 are converted to 2,5,9
1419c42fd43Smckusick */
condense(wref,wcnt,sig)1429c42fd43Smckusick condense(wref, wcnt, sig)
1439c42fd43Smckusick int *wref;
1449c42fd43Smckusick int wcnt;
1459c42fd43Smckusick char *sig;
1469c42fd43Smckusick {
1479c42fd43Smckusick register int i = 0;
1489c42fd43Smckusick char wt[4];
1499c42fd43Smckusick extern int wswap();
1509c42fd43Smckusick
1519c42fd43Smckusick qsort(wref, wcnt, sizeof(int), wswap);
1529c42fd43Smckusick sig[0] = 0;
1539c42fd43Smckusick while (i < wcnt) {
1549c42fd43Smckusick sprintf(wt,"%d",wref[i]);
1559c42fd43Smckusick strcat(sig,wt);
1569c42fd43Smckusick if ((i+2 < wcnt) && (wref[i] == (wref[i+2] - 2))) {
1579c42fd43Smckusick while (wref[i] == (wref[i+1] - 1))
1589c42fd43Smckusick i++;
1599c42fd43Smckusick strcat(sig, "-");
1609c42fd43Smckusick } else if (++i < wcnt)
1619c42fd43Smckusick strcat(sig,",\\|");
1629c42fd43Smckusick }
1639c42fd43Smckusick }
1649c42fd43Smckusick
wswap(iw1,iw2)1659c42fd43Smckusick wswap(iw1, iw2)
1669c42fd43Smckusick register int *iw1,*iw2;
1679c42fd43Smckusick {
1689c42fd43Smckusick return(*iw1 - *iw2);
1699c42fd43Smckusick }
170