2 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
6 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
7 /* All Rights Reserved */
10 * Copyright (c) 1980 Regents of the University of California.
11 * All rights reserved. The Berkeley software License Agreement
12 * specifies the terms and conditions for redistribution.
15 #pragma ident "%Z%%M% %I% %E% SMI"
25 static void condense(int *, int, char *);
32 for (i
= 1; i
<= refnum
; i
++) {
33 if (reftable
[i
] && strcmp(reftable
[i
], tag
) == 0)
36 reftable
[refnum
+1] = rtp
;
38 err(gettext("too many references (%d) for table"), refnum
);
42 if (rtp
> reftext
+ NRFTXT
)
43 err(gettext("reference pointers too long (%d)"), rtp
-reftext
);
51 int c
, g1
= 0, nr
= 1;
59 sprintf(comm
, "sort -f %s -o %s", tfile
, tfile
);
62 fi
= fopen(tfile
, "r");
66 fprintf(ftemp
, ".]<\n");
67 while ((c
= getc(fi
)) > 0) {
75 /* make old-new ref number table */
78 while ((c
= getc(fi
)) != FLAG
)
84 fprintf(stderr
, "nr %d assigned to atoi(tb) %d\n",
87 fprintf(ftemp
, "%d", nr
);
96 fprintf(ftemp
, ".]>\n");
108 extern int *realloc();
110 wref
= (int *)calloc((unsigned)wsize
, (unsigned)sizeof (int));
112 ftemp
= fopen(fnam
, "r");
114 fprintf(stderr
, gettext("Can't reopen %s\n"), fnam
);
117 while ((c
= getc(ftemp
)) != EOF
) {
121 while ((c
= getc(ftemp
)) != FLAG
)
125 * If sort was done, permute the reference number
126 * to obtain the final reference number, finalrn.
129 finalrn
= newr
[atoi(tb
)];
132 if ((++wcnt
> wsize
) && ((wref
= realloc(wref
,
133 (wsize
+= 50) * sizeof (int))) == NULL
)) {
134 fprintf(stderr
, gettext(
135 "Ref condense out of memory."));
138 wref
[wcnt
-1] = finalrn
;
139 if ((c
= getc(ftemp
)) == AFLAG
)
142 condense(wref
, wcnt
, sig
);
153 * sort and condense reference signals when they are placed in
154 * the text. Viz, the signal 1,2,3,4 is condensed to 1-4 and signals
155 * of the form 5,2,9 are converted to 2,5,9
158 condense(int *wref
, int wcnt
, char *sig
)
164 qsort(wref
, wcnt
, sizeof (int), wswap
);
167 sprintf(wt
, "%d", wref
[i
]);
169 if ((i
+2 < wcnt
) && (wref
[i
] == (wref
[i
+2] - 2))) {
170 while (wref
[i
] == (wref
[i
+1] - 1))
173 } else if (++i
< wcnt
)
179 wswap(int *iw1
, int *iw2
)
181 return (*iw1
- *iw2
);