|
|
1.1 root 1: #ifndef lint
2: static char *sccsid = "@(#)refer7.c 4.4 (Berkeley) 9/30/87";
3: #endif
4:
5: #include "refer..c"
6:
7: int newr[250];
8:
9: chkdup(tag)
10: char *tag;
11: {
12: int i;
13:
14: for(i = 1; i <= refnum; i++) {
15: if (strcmp(reftable[i], tag)==0)
16: return(i);
17: }
18: reftable[refnum+1] = rtp;
19: if (refnum >= NRFTBL)
20: err("too many references (%d) for table", refnum);
21: strcpy(rtp, tag);
22: while (*rtp++);
23: if (rtp > reftext + NRFTXT)
24: err("reference pointers too long (%d)", rtp-reftext);
25: return(0);
26: }
27:
28: dumpold()
29: {
30: FILE *fi;
31: int c, g1 = 0, nr = 1;
32:
33: if (!endpush)
34: return;
35: if (fo != NULL) {
36: fclose(fo);
37: fo = NULL;
38: }
39: if (sort) {
40: char comm[100];
41: sprintf(comm, "sort -f %s -o %s", tfile, tfile);
42: system(comm);
43: }
44: fi = fopen(tfile, "r");
45: if (fi == NULL)
46: return;
47: flout();
48: fprintf(ftemp, ".]<\n");
49: while ((c = getc(fi)) > 0) {
50: if (c == '\n') {
51: nr++;
52: g1 = 0;
53: }
54: if (c == sep)
55: c = '\n';
56: if (c == FLAG) {
57: /* make old-new ref number table */
58: char tb[20];
59: char *s = tb;
60: while ((c = getc(fi)) != FLAG)
61: *s++ = c;
62: *s = 0;
63: if (g1++ == 0)
64: newr[atoi(tb)] = nr;
65: #if EBUG
66: fprintf(stderr,
67: "nr %d assigned to atoi(tb) %d\n",nr,atoi(tb));
68: # endif
69: fprintf(ftemp,"%d", nr);
70: continue;
71: }
72: putc(c, ftemp);
73: }
74: fclose(fi);
75: #ifndef TF
76: unlink(tfile);
77: #endif
78: fprintf(ftemp, ".]>\n");
79: }
80:
81: recopy (fnam)
82: char *fnam;
83: {
84: int c;
85: int *wref = NULL;
86: int wcnt = 0;
87: int wsize = 50;
88: int finalrn;
89: char sig[MXSIG];
90: extern int *realloc();
91:
92: wref = (int *)calloc((unsigned)wsize, (unsigned)sizeof(int));
93: fclose(ftemp);
94: ftemp = fopen(fnam, "r");
95: if (ftemp == NULL) {
96: fprintf(stderr, "Can't reopen %s\n", fnam);
97: exit(1);
98: }
99: while ((c = getc(ftemp)) != EOF) {
100: if (c == FLAG) {
101: char tb[10];
102: char *s = tb;
103: while ((c = getc(ftemp)) != FLAG)
104: *s++ = c;
105: *s = 0;
106: /*
107: * If sort was done, permute the reference number
108: * to obtain the final reference number, finalrn.
109: */
110: if (sort)
111: finalrn = newr[atoi(tb)];
112: else
113: finalrn = atoi(tb);
114: if ((++wcnt > wsize) &&
115: ((wref=realloc(wref,(wsize+=50)*sizeof(int)))==NULL)){
116: fprintf(stderr, "Ref condense out of memory.");
117: exit(1);
118: }
119: wref[wcnt-1] = finalrn;
120: if ((c = getc(ftemp)) == AFLAG)
121: continue;
122: wref[wcnt] = 0;
123: condense(wref,wcnt,sig);
124: wcnt = 0;
125: printf("%s", sig);
126: }
127: putchar(c);
128: }
129: fclose(ftemp);
130: unlink(fnam);
131: }
132:
133: /*
134: * sort and condense referance signals when they are placed in
135: * the text. Viz, the signal 1,2,3,4 is condensed to 1-4 and signals
136: * of the form 5,2,9 are converted to 2,5,9
137: */
138: condense(wref, wcnt, sig)
139: int *wref;
140: int wcnt;
141: char *sig;
142: {
143: register int i = 0;
144: char wt[4];
145: extern int wswap();
146:
147: qsort(wref, wcnt, sizeof(int), wswap);
148: sig[0] = 0;
149: while (i < wcnt) {
150: sprintf(wt,"%d",wref[i]);
151: strcat(sig,wt);
152: if ((i+2 < wcnt) && (wref[i] == (wref[i+2] - 2))) {
153: while (wref[i] == (wref[i+1] - 1))
154: i++;
155: strcat(sig, "-");
156: } else if (++i < wcnt)
157: strcat(sig,",\\|");
158: }
159: }
160:
161: wswap(iw1, iw2)
162: register int *iw1,*iw2;
163: {
164: return(*iw1 - *iw2);
165: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.