Commit | Line | Data |
---|---|---|
2b1a705e TL |
1 | # include "refer..c" |
2 | int newr[250]; | |
3 | chkdup ( tag ) | |
4 | char *tag; | |
5 | { | |
6 | int i; | |
7 | for(i=1; i<=refnum; i++) | |
8 | { | |
9 | if (strcmp(reftable[i], tag)==0) | |
10 | return(i); | |
11 | } | |
12 | reftable[refnum+1] = rtp; | |
13 | if (refnum>=NRFTBL) | |
14 | err("too many references (%d) for table", refnum); | |
15 | strcpy (rtp, tag); | |
16 | while (*rtp++); | |
17 | if (rtp > reftext + NRFTXT) | |
18 | err("reftext too big (%d)", rtp-reftext); | |
19 | return(0); | |
20 | } | |
21 | dumpold() | |
22 | { | |
23 | FILE *fi; | |
24 | int c, g1 = 0, nr = 1; | |
25 | if (!endpush) return; | |
26 | fclose(fo); | |
27 | if (sort) | |
28 | { | |
29 | char comm[100]; | |
30 | sprintf(comm, "sort %s -o %s", tfile, tfile); | |
31 | system(comm); | |
32 | } | |
33 | fi = fopen(tfile, "r"); | |
34 | if (fi==NULL) return; | |
35 | flout(); | |
36 | fprintf(ftemp,".]<\n"); | |
37 | while ( (c = getc(fi)) >0) | |
38 | { | |
39 | if (c=='\n') | |
40 | { | |
41 | nr++; | |
42 | g1 = 0; | |
43 | } | |
44 | if (c==sep) | |
45 | c = '\n'; | |
46 | if (c== FLAG) | |
47 | { | |
48 | /* make old-new ref number table */ | |
49 | char tb[20]; | |
50 | char *s = tb; | |
51 | while ( (c=getc(fi)) != FLAG) | |
52 | *s++ = c; | |
53 | *s=0; | |
54 | if (g1++ == 0) | |
55 | newr[atoi(tb)] = nr; | |
56 | # if D1 | |
57 | fprintf(stderr, "nr %d assigned to atoi(tb) %d\n",nr,atoi(tb)); | |
58 | # endif | |
59 | fprintf(ftemp,"%d", nr); | |
60 | continue; | |
61 | } | |
62 | putc(c, ftemp); | |
63 | } | |
64 | fclose(fi); | |
65 | # ifndef D1 | |
66 | unlink(tfile); | |
67 | # endif | |
68 | fprintf(ftemp, ".]>\n"); | |
69 | } | |
70 | ||
71 | recopy (fnam) | |
72 | char *fnam; | |
73 | { | |
74 | int c; | |
75 | fclose(ftemp); | |
76 | ||
77 | ftemp = fopen(fnam, "r"); | |
78 | if (ftemp==NULL) | |
79 | { | |
80 | fprintf(stderr, "Can't reopen %s\n", fnam); | |
81 | exit(1); | |
82 | } | |
83 | while ( (c = getc(ftemp)) != EOF) | |
84 | { | |
85 | if (c == FLAG) | |
86 | { | |
87 | char tb[10]; | |
88 | char *s = tb; | |
89 | while ( (c = getc(ftemp)) != FLAG) | |
90 | *s++ = c; | |
91 | *s=0; | |
92 | printf("%d", newr[atoi(tb)]); | |
93 | continue; | |
94 | } | |
95 | putchar(c); | |
96 | } | |
97 | fclose(ftemp); | |
98 | unlink(fnam); | |
99 | } |