1 /* $MirOS: src/usr.bin/oldroff/tbl/tb.c,v 1.4 2010/12/25 14:22:13 tg Exp $ */
2
3 /*-
4 * Copyright (c) 1979, 1980, 1981, 1986, 1988, 1990, 1991, 1992
5 * The Regents of the University of California.
6 * Copyright (C) Caldera International Inc. 2001-2002.
7 * Copyright (c) 2003, 2004, 2005, 2010
8 * Thorsten "mirabilos" Glaser <tg@mirbsd.org>
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms,
12 * with or without modification, are permitted provided
13 * that the following conditions are met:
14 *
15 * Redistributions of source code and documentation must retain
16 * the above copyright notice, this list of conditions and the
17 * following disclaimer. Redistributions in binary form must
18 * reproduce the above copyright notice, this list of conditions
19 * and the following disclaimer in the documentation and/or other
20 * materials provided with the distribution.
21 *
22 * All advertising materials mentioning features or use of this
23 * software must display the following acknowledgement:
24 * This product includes software developed or owned by
25 * Caldera International, Inc.
26 *
27 * Neither the name of Caldera International, Inc. nor the names
28 * of other contributors may be used to endorse or promote products
29 * derived from this software without specific prior written permission.
30 *
31 * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
32 * INTERNATIONAL, INC. AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
33 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
34 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35 * ARE DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE
36 * LIABLE FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR
37 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
38 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
39 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
40 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
41 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
42 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43 */
44
45 #include <stdlib.h>
46
47 /* tb.c: check which entries exist, also storage allocation */
48
49 # include "t..c"
50 __SCCSID("@(#)tb.c 4.6 (Berkeley) 4/18/91");
51 __RCSID("$MirOS: src/usr.bin/oldroff/tbl/tb.c,v 1.4 2010/12/25 14:22:13 tg Exp $");
52
checkuse()53 checkuse()
54 {
55 int i,c, k;
56 for(c=0; c<ncol; c++)
57 {
58 used[c]=lused[c]=rused[c]=0;
59 for(i=0; i<nlin; i++)
60 {
61 if (instead[i] || fullbot[i]) continue;
62 k = ctype(i,c);
63 if (k== '-' || k == '=') continue;
64 if ((k=='n'||k=='a'))
65 {
66 rused[c]|= real(table[i][c].rcol);
67 if( !real(table[i][c].rcol))
68 used[c] |= real(table[i][c].col);
69 if (table[i][c].rcol)
70 lused[c] |= real(table[i][c].col);
71 }
72 else
73 used[c] |= real(table[i][c].col);
74 }
75 }
76 }
real(s)77 real(s)
78 char *s;
79 {
80 if (s==0) return(0);
81 if (!point(s)) return(1);
82 if (*s==0) return(0);
83 return(1);
84 }
85 int spcount = 0;
86 # define MAXVEC 20
87 char *spvecs[MAXVEC];
88
89 char *
chspace()90 chspace()
91 {
92 char *pp;
93 if (spvecs[spcount])
94 return(spvecs[spcount++]);
95 if (spcount>=MAXVEC)
96 error("Too many characters in table");
97 spvecs[spcount++]= pp = calloc(MAXCHS+BUFSIZ,1);
98 if (pp == 0)
99 error("no space for characters");
100 return(pp);
101 }
102 # define MAXPC 50
103 char *thisvec;
104 int tpcount = -1;
105 char *tpvecs[MAXPC];
106
107 int *
alocv(n)108 alocv(n)
109 {
110 int *tp, *q;
111 if (tpcount<0 || thisvec+n > tpvecs[tpcount]+MAXCHS)
112 {
113 tpcount++;
114 if (tpvecs[tpcount]==0)
115 {
116 tpvecs[tpcount] = calloc(MAXCHS,1);
117 }
118 thisvec = tpvecs[tpcount];
119 if (thisvec == 0)
120 error("no space for vectors");
121 }
122 tp=(int *)thisvec;
123 thisvec+=n;
124 for(q=tp; q<(int *)thisvec; q++)
125 *q=0;
126 return(tp);
127 }
release()128 release()
129 {
130 extern char *exstore;
131 /* give back unwanted space in some vectors */
132 spcount=0;
133 tpcount= -1;
134 exstore=0;
135 }
136