xref: /onnv-gate/usr/src/cmd/rpcgen/rpc_util.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  *
22*0Sstevel@tonic-gate  * Copyright 2001 Sun Microsystems, Inc.  All rights reserved.
23*0Sstevel@tonic-gate  * Use is subject to license terms.
24*0Sstevel@tonic-gate  */
25*0Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
26*0Sstevel@tonic-gate /* All Rights Reserved */
27*0Sstevel@tonic-gate /*
28*0Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
29*0Sstevel@tonic-gate  * The Regents of the University of California
30*0Sstevel@tonic-gate  * All Rights Reserved
31*0Sstevel@tonic-gate  *
32*0Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
33*0Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
34*0Sstevel@tonic-gate  * contributors.
35*0Sstevel@tonic-gate  */
36*0Sstevel@tonic-gate 
37*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
38*0Sstevel@tonic-gate 
39*0Sstevel@tonic-gate /*
40*0Sstevel@tonic-gate  * rpc_util.c, Utility routines for the RPC protocol compiler
41*0Sstevel@tonic-gate  */
42*0Sstevel@tonic-gate #include <stdio.h>
43*0Sstevel@tonic-gate #include <ctype.h>
44*0Sstevel@tonic-gate #include "rpc_scan.h"
45*0Sstevel@tonic-gate #include "rpc_parse.h"
46*0Sstevel@tonic-gate #include "rpc_util.h"
47*0Sstevel@tonic-gate 
48*0Sstevel@tonic-gate #define	ARGEXT "argument"
49*0Sstevel@tonic-gate 
50*0Sstevel@tonic-gate char curline[MAXLINESIZE];	/* current read line */
51*0Sstevel@tonic-gate char *where = curline;		/* current point in line */
52*0Sstevel@tonic-gate int linenum = 0;		/* current line number */
53*0Sstevel@tonic-gate 
54*0Sstevel@tonic-gate char *infilename;		/* input filename */
55*0Sstevel@tonic-gate 
56*0Sstevel@tonic-gate #define	NFILES   15
57*0Sstevel@tonic-gate char *outfiles[NFILES];		/* output file names */
58*0Sstevel@tonic-gate int nfiles;
59*0Sstevel@tonic-gate 
60*0Sstevel@tonic-gate FILE *fout;			/* file pointer of current output */
61*0Sstevel@tonic-gate FILE *fin;			/* file pointer of current input */
62*0Sstevel@tonic-gate 
63*0Sstevel@tonic-gate list *defined;			/* list of defined things */
64*0Sstevel@tonic-gate 
65*0Sstevel@tonic-gate /*
66*0Sstevel@tonic-gate  * Reinitialize the world
67*0Sstevel@tonic-gate  */
68*0Sstevel@tonic-gate reinitialize()
69*0Sstevel@tonic-gate {
70*0Sstevel@tonic-gate 	memset(curline, 0, MAXLINESIZE);
71*0Sstevel@tonic-gate 	where = curline;
72*0Sstevel@tonic-gate 	linenum = 0;
73*0Sstevel@tonic-gate 	defined = NULL;
74*0Sstevel@tonic-gate }
75*0Sstevel@tonic-gate 
76*0Sstevel@tonic-gate /*
77*0Sstevel@tonic-gate  * string equality
78*0Sstevel@tonic-gate  */
79*0Sstevel@tonic-gate streq(a, b)
80*0Sstevel@tonic-gate 	char *a;
81*0Sstevel@tonic-gate 	char *b;
82*0Sstevel@tonic-gate {
83*0Sstevel@tonic-gate 	return (strcmp(a, b) == 0);
84*0Sstevel@tonic-gate }
85*0Sstevel@tonic-gate 
86*0Sstevel@tonic-gate /*
87*0Sstevel@tonic-gate  * find a value in a list
88*0Sstevel@tonic-gate  */
89*0Sstevel@tonic-gate definition *
90*0Sstevel@tonic-gate findval(lst, val, cmp)
91*0Sstevel@tonic-gate 	list *lst;
92*0Sstevel@tonic-gate 	char *val;
93*0Sstevel@tonic-gate 	int (*cmp) ();
94*0Sstevel@tonic-gate 
95*0Sstevel@tonic-gate {
96*0Sstevel@tonic-gate 	for (; lst != NULL; lst = lst->next) {
97*0Sstevel@tonic-gate 		if ((*cmp) (lst->val, val)) {
98*0Sstevel@tonic-gate 			return (lst->val);
99*0Sstevel@tonic-gate 		}
100*0Sstevel@tonic-gate 	}
101*0Sstevel@tonic-gate 	return (NULL);
102*0Sstevel@tonic-gate }
103*0Sstevel@tonic-gate 
104*0Sstevel@tonic-gate /*
105*0Sstevel@tonic-gate  * store a value in a list
106*0Sstevel@tonic-gate  */
107*0Sstevel@tonic-gate void
108*0Sstevel@tonic-gate storeval(lstp, val)
109*0Sstevel@tonic-gate 	list **lstp;
110*0Sstevel@tonic-gate 	definition *val;
111*0Sstevel@tonic-gate {
112*0Sstevel@tonic-gate 	list **l;
113*0Sstevel@tonic-gate 	list *lst;
114*0Sstevel@tonic-gate 
115*0Sstevel@tonic-gate 	for (l = lstp; *l != NULL; l = (list **) & (*l)->next);
116*0Sstevel@tonic-gate 	lst = ALLOC(list);
117*0Sstevel@tonic-gate 	lst->val = val;
118*0Sstevel@tonic-gate 	lst->next = NULL;
119*0Sstevel@tonic-gate 	*l = lst;
120*0Sstevel@tonic-gate }
121*0Sstevel@tonic-gate 
122*0Sstevel@tonic-gate static
123*0Sstevel@tonic-gate findit(def, type)
124*0Sstevel@tonic-gate 	definition *def;
125*0Sstevel@tonic-gate 	char *type;
126*0Sstevel@tonic-gate {
127*0Sstevel@tonic-gate 	return (streq(def->def_name, type));
128*0Sstevel@tonic-gate }
129*0Sstevel@tonic-gate 
130*0Sstevel@tonic-gate static char *
131*0Sstevel@tonic-gate fixit(type, orig)
132*0Sstevel@tonic-gate 	char *type;
133*0Sstevel@tonic-gate 	char *orig;
134*0Sstevel@tonic-gate {
135*0Sstevel@tonic-gate 	definition *def;
136*0Sstevel@tonic-gate 
137*0Sstevel@tonic-gate 	def = (definition *) FINDVAL(defined, type, findit);
138*0Sstevel@tonic-gate 	if (def == NULL || def->def_kind != DEF_TYPEDEF) {
139*0Sstevel@tonic-gate 		return (orig);
140*0Sstevel@tonic-gate 	}
141*0Sstevel@tonic-gate 	switch (def->def.ty.rel) {
142*0Sstevel@tonic-gate 	case REL_VECTOR:
143*0Sstevel@tonic-gate 		if (streq(def->def.ty.old_type, "opaque"))
144*0Sstevel@tonic-gate 			return ("char");
145*0Sstevel@tonic-gate 		else
146*0Sstevel@tonic-gate 			return (def->def.ty.old_type);
147*0Sstevel@tonic-gate 
148*0Sstevel@tonic-gate 	case REL_ALIAS:
149*0Sstevel@tonic-gate 		return (fixit(def->def.ty.old_type, orig));
150*0Sstevel@tonic-gate 	default:
151*0Sstevel@tonic-gate 		return (orig);
152*0Sstevel@tonic-gate 	}
153*0Sstevel@tonic-gate }
154*0Sstevel@tonic-gate 
155*0Sstevel@tonic-gate char *
156*0Sstevel@tonic-gate fixtype(type)
157*0Sstevel@tonic-gate 	char *type;
158*0Sstevel@tonic-gate {
159*0Sstevel@tonic-gate 	return (fixit(type, type));
160*0Sstevel@tonic-gate }
161*0Sstevel@tonic-gate 
162*0Sstevel@tonic-gate char *
163*0Sstevel@tonic-gate stringfix(type)
164*0Sstevel@tonic-gate 	char *type;
165*0Sstevel@tonic-gate {
166*0Sstevel@tonic-gate 	if (streq(type, "string")) {
167*0Sstevel@tonic-gate 		return ("wrapstring");
168*0Sstevel@tonic-gate 	} else {
169*0Sstevel@tonic-gate 		return (type);
170*0Sstevel@tonic-gate 	}
171*0Sstevel@tonic-gate }
172*0Sstevel@tonic-gate 
173*0Sstevel@tonic-gate void
174*0Sstevel@tonic-gate ptype(prefix, type, follow)
175*0Sstevel@tonic-gate 	char *prefix;
176*0Sstevel@tonic-gate 	char *type;
177*0Sstevel@tonic-gate 	int follow;
178*0Sstevel@tonic-gate {
179*0Sstevel@tonic-gate 	if (prefix != NULL) {
180*0Sstevel@tonic-gate 		if (streq(prefix, "enum")) {
181*0Sstevel@tonic-gate 			f_print(fout, "enum ");
182*0Sstevel@tonic-gate 		} else {
183*0Sstevel@tonic-gate 			f_print(fout, "struct ");
184*0Sstevel@tonic-gate 		}
185*0Sstevel@tonic-gate 	}
186*0Sstevel@tonic-gate 	if (streq(type, "bool")) {
187*0Sstevel@tonic-gate 		f_print(fout, "bool_t ");
188*0Sstevel@tonic-gate 	} else if (streq(type, "string")) {
189*0Sstevel@tonic-gate 		f_print(fout, "char *");
190*0Sstevel@tonic-gate 	} else if (streq(type, "oneway")) {
191*0Sstevel@tonic-gate 		f_print(fout, "void ");
192*0Sstevel@tonic-gate 	} else {
193*0Sstevel@tonic-gate 		f_print(fout, "%s ", follow ? fixtype(type) : type);
194*0Sstevel@tonic-gate 	}
195*0Sstevel@tonic-gate }
196*0Sstevel@tonic-gate 
197*0Sstevel@tonic-gate static
198*0Sstevel@tonic-gate typedefed(def, type)
199*0Sstevel@tonic-gate 	definition *def;
200*0Sstevel@tonic-gate 	char *type;
201*0Sstevel@tonic-gate {
202*0Sstevel@tonic-gate 	if (def->def_kind != DEF_TYPEDEF || def->def.ty.old_prefix != NULL) {
203*0Sstevel@tonic-gate 		return (0);
204*0Sstevel@tonic-gate 	} else {
205*0Sstevel@tonic-gate 		return (streq(def->def_name, type));
206*0Sstevel@tonic-gate 	}
207*0Sstevel@tonic-gate }
208*0Sstevel@tonic-gate 
209*0Sstevel@tonic-gate isvectordef(type, rel)
210*0Sstevel@tonic-gate 	char *type;
211*0Sstevel@tonic-gate 	relation rel;
212*0Sstevel@tonic-gate {
213*0Sstevel@tonic-gate 	definition *def;
214*0Sstevel@tonic-gate 
215*0Sstevel@tonic-gate 	for (;;) {
216*0Sstevel@tonic-gate 		switch (rel) {
217*0Sstevel@tonic-gate 		case REL_VECTOR:
218*0Sstevel@tonic-gate 			return (!streq(type, "string"));
219*0Sstevel@tonic-gate 		case REL_ARRAY:
220*0Sstevel@tonic-gate 			return (0);
221*0Sstevel@tonic-gate 		case REL_POINTER:
222*0Sstevel@tonic-gate 			return (0);
223*0Sstevel@tonic-gate 		case REL_ALIAS:
224*0Sstevel@tonic-gate 			def = (definition *) FINDVAL(defined, type, typedefed);
225*0Sstevel@tonic-gate 			if (def == NULL)
226*0Sstevel@tonic-gate 				return (0);
227*0Sstevel@tonic-gate 			type = def->def.ty.old_type;
228*0Sstevel@tonic-gate 			rel = def->def.ty.rel;
229*0Sstevel@tonic-gate 		}
230*0Sstevel@tonic-gate 	}
231*0Sstevel@tonic-gate }
232*0Sstevel@tonic-gate 
233*0Sstevel@tonic-gate char *
234*0Sstevel@tonic-gate locase(str)
235*0Sstevel@tonic-gate 	char *str;
236*0Sstevel@tonic-gate {
237*0Sstevel@tonic-gate 	char c;
238*0Sstevel@tonic-gate 	static char buf[100];
239*0Sstevel@tonic-gate 	char *p = buf;
240*0Sstevel@tonic-gate 
241*0Sstevel@tonic-gate 	while (c = *str++) {
242*0Sstevel@tonic-gate 		*p++ = (c >= 'A' && c <= 'Z') ? (c - 'A' + 'a') : c;
243*0Sstevel@tonic-gate 	}
244*0Sstevel@tonic-gate 	*p = 0;
245*0Sstevel@tonic-gate 	return (buf);
246*0Sstevel@tonic-gate }
247*0Sstevel@tonic-gate 
248*0Sstevel@tonic-gate void
249*0Sstevel@tonic-gate pvname_svc(pname, vnum)
250*0Sstevel@tonic-gate 	char *pname;
251*0Sstevel@tonic-gate 	char *vnum;
252*0Sstevel@tonic-gate {
253*0Sstevel@tonic-gate 	f_print(fout, "%s_%s_svc", locase(pname), vnum);
254*0Sstevel@tonic-gate }
255*0Sstevel@tonic-gate 
256*0Sstevel@tonic-gate void
257*0Sstevel@tonic-gate pvname(pname, vnum)
258*0Sstevel@tonic-gate 	char *pname;
259*0Sstevel@tonic-gate 	char *vnum;
260*0Sstevel@tonic-gate {
261*0Sstevel@tonic-gate 	f_print(fout, "%s_%s", locase(pname), vnum);
262*0Sstevel@tonic-gate }
263*0Sstevel@tonic-gate 
264*0Sstevel@tonic-gate /*
265*0Sstevel@tonic-gate  * print a useful (?) error message, and then die
266*0Sstevel@tonic-gate  */
267*0Sstevel@tonic-gate void
268*0Sstevel@tonic-gate error(msg)
269*0Sstevel@tonic-gate 	char *msg;
270*0Sstevel@tonic-gate {
271*0Sstevel@tonic-gate 	printwhere();
272*0Sstevel@tonic-gate 	f_print(stderr, "%s, line %d: ", infilename, linenum);
273*0Sstevel@tonic-gate 	f_print(stderr, "%s\n", msg);
274*0Sstevel@tonic-gate 	crash();
275*0Sstevel@tonic-gate }
276*0Sstevel@tonic-gate 
277*0Sstevel@tonic-gate /*
278*0Sstevel@tonic-gate  * Something went wrong, unlink any files that we may have created and then
279*0Sstevel@tonic-gate  * die.
280*0Sstevel@tonic-gate  */
281*0Sstevel@tonic-gate crash()
282*0Sstevel@tonic-gate {
283*0Sstevel@tonic-gate 	int i;
284*0Sstevel@tonic-gate 
285*0Sstevel@tonic-gate 	for (i = 0; i < nfiles; i++) {
286*0Sstevel@tonic-gate 		(void) unlink(outfiles[i]);
287*0Sstevel@tonic-gate 	}
288*0Sstevel@tonic-gate 	exit(1);
289*0Sstevel@tonic-gate }
290*0Sstevel@tonic-gate 
291*0Sstevel@tonic-gate void
292*0Sstevel@tonic-gate record_open(file)
293*0Sstevel@tonic-gate 	char *file;
294*0Sstevel@tonic-gate {
295*0Sstevel@tonic-gate 	if (nfiles < NFILES) {
296*0Sstevel@tonic-gate 		outfiles[nfiles++] = file;
297*0Sstevel@tonic-gate 	} else {
298*0Sstevel@tonic-gate 		f_print(stderr, "too many files!\n");
299*0Sstevel@tonic-gate 		crash();
300*0Sstevel@tonic-gate 	}
301*0Sstevel@tonic-gate }
302*0Sstevel@tonic-gate 
303*0Sstevel@tonic-gate static char expectbuf[100];
304*0Sstevel@tonic-gate static char *toktostr();
305*0Sstevel@tonic-gate 
306*0Sstevel@tonic-gate /*
307*0Sstevel@tonic-gate  * error, token encountered was not the expected one
308*0Sstevel@tonic-gate  */
309*0Sstevel@tonic-gate void
310*0Sstevel@tonic-gate expected1(exp1)
311*0Sstevel@tonic-gate 	tok_kind exp1;
312*0Sstevel@tonic-gate {
313*0Sstevel@tonic-gate 	s_print(expectbuf, "expected '%s'",
314*0Sstevel@tonic-gate 		toktostr(exp1));
315*0Sstevel@tonic-gate 	error(expectbuf);
316*0Sstevel@tonic-gate }
317*0Sstevel@tonic-gate 
318*0Sstevel@tonic-gate /*
319*0Sstevel@tonic-gate  * error, token encountered was not one of two expected ones
320*0Sstevel@tonic-gate  */
321*0Sstevel@tonic-gate void
322*0Sstevel@tonic-gate expected2(exp1, exp2)
323*0Sstevel@tonic-gate 	tok_kind exp1, exp2;
324*0Sstevel@tonic-gate {
325*0Sstevel@tonic-gate 	s_print(expectbuf, "expected '%s' or '%s'",
326*0Sstevel@tonic-gate 		toktostr(exp1),
327*0Sstevel@tonic-gate 		toktostr(exp2));
328*0Sstevel@tonic-gate 	error(expectbuf);
329*0Sstevel@tonic-gate }
330*0Sstevel@tonic-gate 
331*0Sstevel@tonic-gate /*
332*0Sstevel@tonic-gate  * error, token encountered was not one of 3 expected ones
333*0Sstevel@tonic-gate  */
334*0Sstevel@tonic-gate void
335*0Sstevel@tonic-gate expected3(exp1, exp2, exp3)
336*0Sstevel@tonic-gate 	tok_kind exp1, exp2, exp3;
337*0Sstevel@tonic-gate {
338*0Sstevel@tonic-gate 	s_print(expectbuf, "expected '%s', '%s' or '%s'",
339*0Sstevel@tonic-gate 		toktostr(exp1),
340*0Sstevel@tonic-gate 		toktostr(exp2),
341*0Sstevel@tonic-gate 		toktostr(exp3));
342*0Sstevel@tonic-gate 	error(expectbuf);
343*0Sstevel@tonic-gate }
344*0Sstevel@tonic-gate 
345*0Sstevel@tonic-gate void
346*0Sstevel@tonic-gate tabify(f, tab)
347*0Sstevel@tonic-gate 	FILE *f;
348*0Sstevel@tonic-gate 	int tab;
349*0Sstevel@tonic-gate {
350*0Sstevel@tonic-gate 	while (tab--) {
351*0Sstevel@tonic-gate 		(void) fputc('\t', f);
352*0Sstevel@tonic-gate 	}
353*0Sstevel@tonic-gate }
354*0Sstevel@tonic-gate 
355*0Sstevel@tonic-gate 
356*0Sstevel@tonic-gate static token tokstrings[] = {
357*0Sstevel@tonic-gate 			{TOK_IDENT, "identifier"},
358*0Sstevel@tonic-gate 			{TOK_CONST, "const"},
359*0Sstevel@tonic-gate 			{TOK_RPAREN, ")"},
360*0Sstevel@tonic-gate 			{TOK_LPAREN, "("},
361*0Sstevel@tonic-gate 			{TOK_RBRACE, "}"},
362*0Sstevel@tonic-gate 			{TOK_LBRACE, "{"},
363*0Sstevel@tonic-gate 			{TOK_LBRACKET, "["},
364*0Sstevel@tonic-gate 			{TOK_RBRACKET, "]"},
365*0Sstevel@tonic-gate 			{TOK_STAR, "*"},
366*0Sstevel@tonic-gate 			{TOK_COMMA, ","},
367*0Sstevel@tonic-gate 			{TOK_EQUAL, "="},
368*0Sstevel@tonic-gate 			{TOK_COLON, ":"},
369*0Sstevel@tonic-gate 			{TOK_SEMICOLON, ";"},
370*0Sstevel@tonic-gate 			{TOK_UNION, "union"},
371*0Sstevel@tonic-gate 			{TOK_STRUCT, "struct"},
372*0Sstevel@tonic-gate 			{TOK_SWITCH, "switch"},
373*0Sstevel@tonic-gate 			{TOK_CASE, "case"},
374*0Sstevel@tonic-gate 			{TOK_DEFAULT, "default"},
375*0Sstevel@tonic-gate 			{TOK_ENUM, "enum"},
376*0Sstevel@tonic-gate 			{TOK_TYPEDEF, "typedef"},
377*0Sstevel@tonic-gate 			{TOK_INT, "int"},
378*0Sstevel@tonic-gate 			{TOK_SHORT, "short"},
379*0Sstevel@tonic-gate 			{TOK_LONG, "long"},
380*0Sstevel@tonic-gate 			{TOK_UNSIGNED, "unsigned"},
381*0Sstevel@tonic-gate 			{TOK_DOUBLE, "double"},
382*0Sstevel@tonic-gate 			{TOK_FLOAT, "float"},
383*0Sstevel@tonic-gate 			{TOK_CHAR, "char"},
384*0Sstevel@tonic-gate 			{TOK_STRING, "string"},
385*0Sstevel@tonic-gate 			{TOK_OPAQUE, "opaque"},
386*0Sstevel@tonic-gate 			{TOK_BOOL, "bool"},
387*0Sstevel@tonic-gate 			{TOK_VOID, "void"},
388*0Sstevel@tonic-gate 			{TOK_PROGRAM, "program"},
389*0Sstevel@tonic-gate 			{TOK_VERSION, "version"},
390*0Sstevel@tonic-gate 			{TOK_EOF, "??????"}
391*0Sstevel@tonic-gate };
392*0Sstevel@tonic-gate 
393*0Sstevel@tonic-gate static char *
394*0Sstevel@tonic-gate toktostr(kind)
395*0Sstevel@tonic-gate 	tok_kind kind;
396*0Sstevel@tonic-gate {
397*0Sstevel@tonic-gate 	token *sp;
398*0Sstevel@tonic-gate 
399*0Sstevel@tonic-gate 	for (sp = tokstrings; sp->kind != TOK_EOF && sp->kind != kind; sp++);
400*0Sstevel@tonic-gate 	return (sp->str);
401*0Sstevel@tonic-gate }
402*0Sstevel@tonic-gate 
403*0Sstevel@tonic-gate static
404*0Sstevel@tonic-gate printbuf()
405*0Sstevel@tonic-gate {
406*0Sstevel@tonic-gate 	char c;
407*0Sstevel@tonic-gate 	int i;
408*0Sstevel@tonic-gate 	int cnt;
409*0Sstevel@tonic-gate 
410*0Sstevel@tonic-gate #	define TABSIZE 4
411*0Sstevel@tonic-gate 
412*0Sstevel@tonic-gate 	for (i = 0; c = curline[i]; i++) {
413*0Sstevel@tonic-gate 		if (c == '\t') {
414*0Sstevel@tonic-gate 			cnt = 8 - (i % TABSIZE);
415*0Sstevel@tonic-gate 			c = ' ';
416*0Sstevel@tonic-gate 		} else {
417*0Sstevel@tonic-gate 			cnt = 1;
418*0Sstevel@tonic-gate 		}
419*0Sstevel@tonic-gate 		while (cnt--) {
420*0Sstevel@tonic-gate 			(void) fputc(c, stderr);
421*0Sstevel@tonic-gate 		}
422*0Sstevel@tonic-gate 	}
423*0Sstevel@tonic-gate }
424*0Sstevel@tonic-gate 
425*0Sstevel@tonic-gate static
426*0Sstevel@tonic-gate printwhere()
427*0Sstevel@tonic-gate {
428*0Sstevel@tonic-gate 	int i;
429*0Sstevel@tonic-gate 	char c;
430*0Sstevel@tonic-gate 	int cnt;
431*0Sstevel@tonic-gate 
432*0Sstevel@tonic-gate 	printbuf();
433*0Sstevel@tonic-gate 	for (i = 0; i < where - curline; i++) {
434*0Sstevel@tonic-gate 		c = curline[i];
435*0Sstevel@tonic-gate 		if (c == '\t') {
436*0Sstevel@tonic-gate 			cnt = 8 - (i % TABSIZE);
437*0Sstevel@tonic-gate 		} else {
438*0Sstevel@tonic-gate 			cnt = 1;
439*0Sstevel@tonic-gate 		}
440*0Sstevel@tonic-gate 		while (cnt--) {
441*0Sstevel@tonic-gate 			(void) fputc('^', stderr);
442*0Sstevel@tonic-gate 		}
443*0Sstevel@tonic-gate 	}
444*0Sstevel@tonic-gate 	(void) fputc('\n', stderr);
445*0Sstevel@tonic-gate }
446*0Sstevel@tonic-gate 
447*0Sstevel@tonic-gate char *
448*0Sstevel@tonic-gate make_argname(pname, vname)
449*0Sstevel@tonic-gate     char *pname;
450*0Sstevel@tonic-gate     char *vname;
451*0Sstevel@tonic-gate {
452*0Sstevel@tonic-gate 	char *name;
453*0Sstevel@tonic-gate 
454*0Sstevel@tonic-gate 	name = malloc(strlen(pname) + strlen(vname) + strlen(ARGEXT) + 3);
455*0Sstevel@tonic-gate 	if (!name) {
456*0Sstevel@tonic-gate 		fprintf(stderr, "failed in malloc");
457*0Sstevel@tonic-gate 		exit(1);
458*0Sstevel@tonic-gate 	}
459*0Sstevel@tonic-gate 	sprintf(name, "%s_%s_%s", locase(pname), vname, ARGEXT);
460*0Sstevel@tonic-gate 	return (name);
461*0Sstevel@tonic-gate }
462*0Sstevel@tonic-gate 
463*0Sstevel@tonic-gate bas_type *typ_list_h;
464*0Sstevel@tonic-gate bas_type *typ_list_t;
465*0Sstevel@tonic-gate 
466*0Sstevel@tonic-gate add_type(len, type)
467*0Sstevel@tonic-gate int len;
468*0Sstevel@tonic-gate char *type;
469*0Sstevel@tonic-gate {
470*0Sstevel@tonic-gate 	bas_type *ptr;
471*0Sstevel@tonic-gate 
472*0Sstevel@tonic-gate 	if ((ptr = (bas_type *) malloc(sizeof (bas_type))) ==
473*0Sstevel@tonic-gate 	    (bas_type *)NULL) {
474*0Sstevel@tonic-gate 		fprintf(stderr, "failed in malloc");
475*0Sstevel@tonic-gate 		exit(1);
476*0Sstevel@tonic-gate 	}
477*0Sstevel@tonic-gate 
478*0Sstevel@tonic-gate 	ptr->name = type;
479*0Sstevel@tonic-gate 	ptr->length = len;
480*0Sstevel@tonic-gate 	ptr->next = NULL;
481*0Sstevel@tonic-gate 	if (typ_list_t == NULL)
482*0Sstevel@tonic-gate 	{
483*0Sstevel@tonic-gate 
484*0Sstevel@tonic-gate 		typ_list_t = ptr;
485*0Sstevel@tonic-gate 		typ_list_h = ptr;
486*0Sstevel@tonic-gate 	}
487*0Sstevel@tonic-gate 	else
488*0Sstevel@tonic-gate 	{
489*0Sstevel@tonic-gate 		typ_list_t->next = ptr;
490*0Sstevel@tonic-gate 		typ_list_t = ptr;
491*0Sstevel@tonic-gate 	};
492*0Sstevel@tonic-gate }
493*0Sstevel@tonic-gate 
494*0Sstevel@tonic-gate 
495*0Sstevel@tonic-gate bas_type *find_type(type)
496*0Sstevel@tonic-gate char *type;
497*0Sstevel@tonic-gate {
498*0Sstevel@tonic-gate 	bas_type * ptr;
499*0Sstevel@tonic-gate 
500*0Sstevel@tonic-gate 	ptr = typ_list_h;
501*0Sstevel@tonic-gate 	while (ptr != NULL)
502*0Sstevel@tonic-gate 	{
503*0Sstevel@tonic-gate 		if (strcmp(ptr->name, type) == 0)
504*0Sstevel@tonic-gate 			return (ptr);
505*0Sstevel@tonic-gate 		else
506*0Sstevel@tonic-gate 			ptr = ptr->next;
507*0Sstevel@tonic-gate 	};
508*0Sstevel@tonic-gate 	return (NULL);
509*0Sstevel@tonic-gate }
510