xref: /titanic_41/usr/src/cmd/tbl/tb.c (revision 450396635f70344c58b6b1e4db38cf17ff34445c)
1 /*
2  * Copyright 1991 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
7 /*	  All Rights Reserved  	*/
8 
9 /*
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.
13  */
14 
15 #pragma ident	"%Z%%M%	%I%	%E% SMI"
16 
17  /* tb.c: check which entries exist, also storage allocation */
18 # include "t..c"
19 #include <stdlib.h>
20 
21 void
22 checkuse(void)
23 {
24 int i,c, k;
25 for(c=0; c<ncol; c++)
26 	{
27 	used[c]=lused[c]=rused[c]=0;
28 	for(i=0; i<nlin; i++)
29 		{
30 		if (instead[i] || fullbot[i]) continue;
31 		k = ctype(i,c);
32 		if (k== '-' || k == '=') continue;
33 		if ((k=='n'||k=='a'))
34 			{
35 			rused[c]|= real(table[i][c].rcol);
36 			if( !real(table[i][c].rcol))
37 			used[c] |= real(table[i][c].col);
38 			if (table[i][c].rcol)
39 			lused[c] |= real(table[i][c].col);
40 			}
41 		else
42 			used[c] |= real(table[i][c].col);
43 		}
44 	}
45 }
46 
47 int
48 real(char *s)
49 {
50 if (s==0) return(0);
51 if (!point(s)) return(1);
52 if (*s==0) return(0);
53 return(1);
54 }
55 
56 int spcount = 0;
57 
58 # define MAXVEC 20
59 
60 char *spvecs[MAXVEC];
61 
62 char *
63 chspace(void)
64 {
65 char *pp;
66 if (spvecs[spcount])
67 	return(spvecs[spcount++]);
68 if (spcount>=MAXVEC)
69 	error(gettext("Too many characters in table"));
70 spvecs[spcount++]= pp = calloc(MAXCHS+MAXSTR,1);
71 if (pp == 0)
72 	error(gettext("no space for characters"));
73 return(pp);
74 }
75 
76 # define MAXPC 50
77 
78 char *thisvec;
79 int tpcount = -1;
80 char *tpvecs[MAXPC];
81 
82 int *
83 alocv(int n)
84 {
85 int *tp, *q;
86 if (tpcount<0 || thisvec+n > tpvecs[tpcount]+MAXCHS)
87 	{
88 	tpcount++;
89 	if (tpvecs[tpcount]==0)
90 		{
91 		tpvecs[tpcount] = calloc(MAXCHS,1);
92 		}
93 	thisvec = tpvecs[tpcount];
94 	if (thisvec == 0)
95 		error(gettext("no space for vectors"));
96 	}
97 tp=(int *)thisvec;
98 thisvec+=n;
99 for(q=tp; q<(int *)thisvec; q++)
100 	*q=0;
101 return(tp);
102 }
103 
104 void
105 release(void)
106 {
107 extern char *exstore;
108 /* give back unwanted space in some vectors */
109 spcount=0;
110 tpcount= -1;
111 exstore=0;
112 }
113