xref: /onnv-gate/usr/src/cmd/rpcgen/rpc_util.c (revision 9497:b07c573232c0)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*9497SJordan.Brown@Sun.COM  * Common Development and Distribution License (the "License").
6*9497SJordan.Brown@Sun.COM  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
20132Srobinson  */
21132Srobinson 
22132Srobinson /*
23*9497SJordan.Brown@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
270Sstevel@tonic-gate /* All Rights Reserved */
280Sstevel@tonic-gate /*
290Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
300Sstevel@tonic-gate  * The Regents of the University of California
310Sstevel@tonic-gate  * All Rights Reserved
320Sstevel@tonic-gate  *
330Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
340Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
350Sstevel@tonic-gate  * contributors.
360Sstevel@tonic-gate  */
370Sstevel@tonic-gate 
380Sstevel@tonic-gate /*
390Sstevel@tonic-gate  * rpc_util.c, Utility routines for the RPC protocol compiler
400Sstevel@tonic-gate  */
410Sstevel@tonic-gate #include <stdio.h>
42132Srobinson #include <stdlib.h>
43132Srobinson #include <unistd.h>
440Sstevel@tonic-gate #include <ctype.h>
45132Srobinson #include <string.h>
460Sstevel@tonic-gate #include "rpc_scan.h"
470Sstevel@tonic-gate #include "rpc_parse.h"
480Sstevel@tonic-gate #include "rpc_util.h"
490Sstevel@tonic-gate 
50132Srobinson extern void crash(void);
51132Srobinson 
52132Srobinson static void printwhere(void);
53132Srobinson 
540Sstevel@tonic-gate #define	ARGEXT "argument"
550Sstevel@tonic-gate 
560Sstevel@tonic-gate char curline[MAXLINESIZE];	/* current read line */
570Sstevel@tonic-gate char *where = curline;		/* current point in line */
580Sstevel@tonic-gate int linenum = 0;		/* current line number */
590Sstevel@tonic-gate 
600Sstevel@tonic-gate char *infilename;		/* input filename */
610Sstevel@tonic-gate 
620Sstevel@tonic-gate #define	NFILES   15
630Sstevel@tonic-gate char *outfiles[NFILES];		/* output file names */
640Sstevel@tonic-gate int nfiles;
650Sstevel@tonic-gate 
660Sstevel@tonic-gate FILE *fout;			/* file pointer of current output */
670Sstevel@tonic-gate FILE *fin;			/* file pointer of current input */
680Sstevel@tonic-gate 
690Sstevel@tonic-gate list *defined;			/* list of defined things */
700Sstevel@tonic-gate 
710Sstevel@tonic-gate /*
720Sstevel@tonic-gate  * Reinitialize the world
730Sstevel@tonic-gate  */
74132Srobinson void
reinitialize(void)75132Srobinson reinitialize(void)
760Sstevel@tonic-gate {
77132Srobinson 	(void) memset(curline, 0, MAXLINESIZE);
780Sstevel@tonic-gate 	where = curline;
790Sstevel@tonic-gate 	linenum = 0;
800Sstevel@tonic-gate 	defined = NULL;
810Sstevel@tonic-gate }
820Sstevel@tonic-gate 
830Sstevel@tonic-gate /*
840Sstevel@tonic-gate  * string equality
850Sstevel@tonic-gate  */
86132Srobinson int
streq(char * a,char * b)87132Srobinson streq(char *a, char *b)
880Sstevel@tonic-gate {
890Sstevel@tonic-gate 	return (strcmp(a, b) == 0);
900Sstevel@tonic-gate }
910Sstevel@tonic-gate 
920Sstevel@tonic-gate /*
930Sstevel@tonic-gate  * find a value in a list
940Sstevel@tonic-gate  */
950Sstevel@tonic-gate definition *
findval(list * lst,char * val,int (* cmp)())96132Srobinson findval(list *lst, char *val, int (*cmp)())
970Sstevel@tonic-gate {
980Sstevel@tonic-gate 	for (; lst != NULL; lst = lst->next) {
99132Srobinson 		if ((*cmp) (lst->val, val))
1000Sstevel@tonic-gate 			return (lst->val);
1010Sstevel@tonic-gate 	}
1020Sstevel@tonic-gate 	return (NULL);
1030Sstevel@tonic-gate }
1040Sstevel@tonic-gate 
1050Sstevel@tonic-gate /*
1060Sstevel@tonic-gate  * store a value in a list
1070Sstevel@tonic-gate  */
1080Sstevel@tonic-gate void
storeval(list ** lstp,definition * val)109132Srobinson storeval(list **lstp, definition *val)
1100Sstevel@tonic-gate {
1110Sstevel@tonic-gate 	list **l;
1120Sstevel@tonic-gate 	list *lst;
1130Sstevel@tonic-gate 
114*9497SJordan.Brown@Sun.COM 	for (l = lstp; *l != NULL; l = (list **)&(*l)->next)
115*9497SJordan.Brown@Sun.COM 		/* LOOP */;
116132Srobinson 	lst = calloc(1, sizeof (list));
1170Sstevel@tonic-gate 	lst->val = val;
1180Sstevel@tonic-gate 	lst->next = NULL;
1190Sstevel@tonic-gate 	*l = lst;
1200Sstevel@tonic-gate }
1210Sstevel@tonic-gate 
122132Srobinson static int
findit(definition * def,char * type)123132Srobinson findit(definition *def, char *type)
1240Sstevel@tonic-gate {
1250Sstevel@tonic-gate 	return (streq(def->def_name, type));
1260Sstevel@tonic-gate }
1270Sstevel@tonic-gate 
1280Sstevel@tonic-gate static char *
fixit(char * type,char * orig)129132Srobinson fixit(char *type, char *orig)
1300Sstevel@tonic-gate {
1310Sstevel@tonic-gate 	definition *def;
1320Sstevel@tonic-gate 
133132Srobinson 	def = (definition *)FINDVAL(defined, type, findit);
134132Srobinson 	if (def == NULL || def->def_kind != DEF_TYPEDEF)
1350Sstevel@tonic-gate 		return (orig);
1360Sstevel@tonic-gate 	switch (def->def.ty.rel) {
1370Sstevel@tonic-gate 	case REL_VECTOR:
1380Sstevel@tonic-gate 		if (streq(def->def.ty.old_type, "opaque"))
1390Sstevel@tonic-gate 			return ("char");
140132Srobinson 		return (def->def.ty.old_type);
1410Sstevel@tonic-gate 
1420Sstevel@tonic-gate 	case REL_ALIAS:
1430Sstevel@tonic-gate 		return (fixit(def->def.ty.old_type, orig));
1440Sstevel@tonic-gate 	default:
1450Sstevel@tonic-gate 		return (orig);
1460Sstevel@tonic-gate 	}
1470Sstevel@tonic-gate }
1480Sstevel@tonic-gate 
1490Sstevel@tonic-gate char *
fixtype(char * type)150132Srobinson fixtype(char *type)
1510Sstevel@tonic-gate {
1520Sstevel@tonic-gate 	return (fixit(type, type));
1530Sstevel@tonic-gate }
1540Sstevel@tonic-gate 
1550Sstevel@tonic-gate char *
stringfix(char * type)156132Srobinson stringfix(char *type)
1570Sstevel@tonic-gate {
158132Srobinson 	if (streq(type, "string"))
1590Sstevel@tonic-gate 		return ("wrapstring");
160132Srobinson 	return (type);
1610Sstevel@tonic-gate }
1620Sstevel@tonic-gate 
1630Sstevel@tonic-gate void
ptype(char * prefix,char * type,int follow)164132Srobinson ptype(char *prefix, char *type, int follow)
1650Sstevel@tonic-gate {
1660Sstevel@tonic-gate 	if (prefix != NULL) {
1670Sstevel@tonic-gate 		if (streq(prefix, "enum")) {
1680Sstevel@tonic-gate 			f_print(fout, "enum ");
1690Sstevel@tonic-gate 		} else {
1700Sstevel@tonic-gate 			f_print(fout, "struct ");
1710Sstevel@tonic-gate 		}
1720Sstevel@tonic-gate 	}
1730Sstevel@tonic-gate 	if (streq(type, "bool")) {
1740Sstevel@tonic-gate 		f_print(fout, "bool_t ");
1750Sstevel@tonic-gate 	} else if (streq(type, "string")) {
1760Sstevel@tonic-gate 		f_print(fout, "char *");
1770Sstevel@tonic-gate 	} else if (streq(type, "oneway")) {
1780Sstevel@tonic-gate 		f_print(fout, "void ");
1790Sstevel@tonic-gate 	} else {
1800Sstevel@tonic-gate 		f_print(fout, "%s ", follow ? fixtype(type) : type);
1810Sstevel@tonic-gate 	}
1820Sstevel@tonic-gate }
1830Sstevel@tonic-gate 
184132Srobinson static int
typedefed(definition * def,char * type)185132Srobinson typedefed(definition *def, char *type)
1860Sstevel@tonic-gate {
187132Srobinson 	if (def->def_kind != DEF_TYPEDEF || def->def.ty.old_prefix != NULL)
1880Sstevel@tonic-gate 		return (0);
189132Srobinson 	return (streq(def->def_name, type));
1900Sstevel@tonic-gate }
1910Sstevel@tonic-gate 
192132Srobinson int
isvectordef(char * type,relation rel)193132Srobinson isvectordef(char *type, relation rel)
1940Sstevel@tonic-gate {
1950Sstevel@tonic-gate 	definition *def;
1960Sstevel@tonic-gate 
1970Sstevel@tonic-gate 	for (;;) {
1980Sstevel@tonic-gate 		switch (rel) {
1990Sstevel@tonic-gate 		case REL_VECTOR:
2000Sstevel@tonic-gate 			return (!streq(type, "string"));
2010Sstevel@tonic-gate 		case REL_ARRAY:
2020Sstevel@tonic-gate 			return (0);
2030Sstevel@tonic-gate 		case REL_POINTER:
2040Sstevel@tonic-gate 			return (0);
2050Sstevel@tonic-gate 		case REL_ALIAS:
206132Srobinson 			def = (definition *)FINDVAL(defined, type, typedefed);
2070Sstevel@tonic-gate 			if (def == NULL)
2080Sstevel@tonic-gate 				return (0);
2090Sstevel@tonic-gate 			type = def->def.ty.old_type;
2100Sstevel@tonic-gate 			rel = def->def.ty.rel;
2110Sstevel@tonic-gate 		}
2120Sstevel@tonic-gate 	}
2130Sstevel@tonic-gate }
2140Sstevel@tonic-gate 
2150Sstevel@tonic-gate char *
locase(char * str)216132Srobinson locase(char *str)
2170Sstevel@tonic-gate {
2180Sstevel@tonic-gate 	char c;
2190Sstevel@tonic-gate 	static char buf[100];
2200Sstevel@tonic-gate 	char *p = buf;
2210Sstevel@tonic-gate 
222132Srobinson 	while (c = *str++)
2230Sstevel@tonic-gate 		*p++ = (c >= 'A' && c <= 'Z') ? (c - 'A' + 'a') : c;
2240Sstevel@tonic-gate 	*p = 0;
2250Sstevel@tonic-gate 	return (buf);
2260Sstevel@tonic-gate }
2270Sstevel@tonic-gate 
2280Sstevel@tonic-gate void
pvname_svc(char * pname,char * vnum)229132Srobinson pvname_svc(char *pname, char *vnum)
2300Sstevel@tonic-gate {
2310Sstevel@tonic-gate 	f_print(fout, "%s_%s_svc", locase(pname), vnum);
2320Sstevel@tonic-gate }
2330Sstevel@tonic-gate 
2340Sstevel@tonic-gate void
pvname(char * pname,char * vnum)235132Srobinson pvname(char *pname, char *vnum)
2360Sstevel@tonic-gate {
2370Sstevel@tonic-gate 	f_print(fout, "%s_%s", locase(pname), vnum);
2380Sstevel@tonic-gate }
2390Sstevel@tonic-gate 
2400Sstevel@tonic-gate /*
2410Sstevel@tonic-gate  * print a useful (?) error message, and then die
2420Sstevel@tonic-gate  */
2430Sstevel@tonic-gate void
error(char * msg)244132Srobinson error(char *msg)
2450Sstevel@tonic-gate {
2460Sstevel@tonic-gate 	printwhere();
2470Sstevel@tonic-gate 	f_print(stderr, "%s, line %d: ", infilename, linenum);
2480Sstevel@tonic-gate 	f_print(stderr, "%s\n", msg);
2490Sstevel@tonic-gate 	crash();
2500Sstevel@tonic-gate }
2510Sstevel@tonic-gate 
2520Sstevel@tonic-gate /*
2530Sstevel@tonic-gate  * Something went wrong, unlink any files that we may have created and then
2540Sstevel@tonic-gate  * die.
2550Sstevel@tonic-gate  */
256132Srobinson void
crash(void)257132Srobinson crash(void)
2580Sstevel@tonic-gate {
2590Sstevel@tonic-gate 	int i;
2600Sstevel@tonic-gate 
261132Srobinson 	for (i = 0; i < nfiles; i++)
2620Sstevel@tonic-gate 		(void) unlink(outfiles[i]);
2630Sstevel@tonic-gate 	exit(1);
2640Sstevel@tonic-gate }
2650Sstevel@tonic-gate 
2660Sstevel@tonic-gate void
record_open(char * file)267132Srobinson record_open(char *file)
2680Sstevel@tonic-gate {
2690Sstevel@tonic-gate 	if (nfiles < NFILES) {
2700Sstevel@tonic-gate 		outfiles[nfiles++] = file;
271132Srobinson 		return;
2720Sstevel@tonic-gate 	}
273132Srobinson 	f_print(stderr, "too many files!\n");
274132Srobinson 	crash();
2750Sstevel@tonic-gate }
2760Sstevel@tonic-gate 
2770Sstevel@tonic-gate static char expectbuf[100];
2780Sstevel@tonic-gate static char *toktostr();
2790Sstevel@tonic-gate 
2800Sstevel@tonic-gate /*
2810Sstevel@tonic-gate  * error, token encountered was not the expected one
2820Sstevel@tonic-gate  */
2830Sstevel@tonic-gate void
expected1(tok_kind exp1)284132Srobinson expected1(tok_kind exp1)
2850Sstevel@tonic-gate {
286132Srobinson 	(void) snprintf(expectbuf,
287*9497SJordan.Brown@Sun.COM 	    sizeof (expectbuf), "expected '%s'", toktostr(exp1));
2880Sstevel@tonic-gate 	error(expectbuf);
2890Sstevel@tonic-gate }
2900Sstevel@tonic-gate 
2910Sstevel@tonic-gate /*
2920Sstevel@tonic-gate  * error, token encountered was not one of two expected ones
2930Sstevel@tonic-gate  */
2940Sstevel@tonic-gate void
expected2(tok_kind exp1,tok_kind exp2)295132Srobinson expected2(tok_kind exp1, tok_kind exp2)
2960Sstevel@tonic-gate {
297132Srobinson 	(void) snprintf(expectbuf,
298*9497SJordan.Brown@Sun.COM 	    sizeof (expectbuf), "expected '%s' or '%s'", toktostr(exp1),
299*9497SJordan.Brown@Sun.COM 	    toktostr(exp2));
3000Sstevel@tonic-gate 	error(expectbuf);
3010Sstevel@tonic-gate }
3020Sstevel@tonic-gate 
3030Sstevel@tonic-gate /*
3040Sstevel@tonic-gate  * error, token encountered was not one of 3 expected ones
3050Sstevel@tonic-gate  */
3060Sstevel@tonic-gate void
expected3(tok_kind exp1,tok_kind exp2,tok_kind exp3)307132Srobinson expected3(tok_kind exp1, tok_kind exp2, tok_kind exp3)
3080Sstevel@tonic-gate {
309132Srobinson 	(void) snprintf(expectbuf,
310*9497SJordan.Brown@Sun.COM 	    sizeof (expectbuf), "expected '%s', '%s' or '%s'",
311*9497SJordan.Brown@Sun.COM 	    toktostr(exp1), toktostr(exp2), toktostr(exp3));
3120Sstevel@tonic-gate 	error(expectbuf);
3130Sstevel@tonic-gate }
3140Sstevel@tonic-gate 
3150Sstevel@tonic-gate void
tabify(FILE * f,int tab)316132Srobinson tabify(FILE *f, int tab)
3170Sstevel@tonic-gate {
318132Srobinson 	while (tab--)
3190Sstevel@tonic-gate 		(void) fputc('\t', f);
3200Sstevel@tonic-gate }
3210Sstevel@tonic-gate 
3220Sstevel@tonic-gate static token tokstrings[] = {
3230Sstevel@tonic-gate 			{TOK_IDENT, "identifier"},
3240Sstevel@tonic-gate 			{TOK_CONST, "const"},
3250Sstevel@tonic-gate 			{TOK_RPAREN, ")"},
3260Sstevel@tonic-gate 			{TOK_LPAREN, "("},
3270Sstevel@tonic-gate 			{TOK_RBRACE, "}"},
3280Sstevel@tonic-gate 			{TOK_LBRACE, "{"},
3290Sstevel@tonic-gate 			{TOK_LBRACKET, "["},
3300Sstevel@tonic-gate 			{TOK_RBRACKET, "]"},
3310Sstevel@tonic-gate 			{TOK_STAR, "*"},
3320Sstevel@tonic-gate 			{TOK_COMMA, ","},
3330Sstevel@tonic-gate 			{TOK_EQUAL, "="},
3340Sstevel@tonic-gate 			{TOK_COLON, ":"},
3350Sstevel@tonic-gate 			{TOK_SEMICOLON, ";"},
3360Sstevel@tonic-gate 			{TOK_UNION, "union"},
3370Sstevel@tonic-gate 			{TOK_STRUCT, "struct"},
3380Sstevel@tonic-gate 			{TOK_SWITCH, "switch"},
3390Sstevel@tonic-gate 			{TOK_CASE, "case"},
3400Sstevel@tonic-gate 			{TOK_DEFAULT, "default"},
3410Sstevel@tonic-gate 			{TOK_ENUM, "enum"},
3420Sstevel@tonic-gate 			{TOK_TYPEDEF, "typedef"},
3430Sstevel@tonic-gate 			{TOK_INT, "int"},
3440Sstevel@tonic-gate 			{TOK_SHORT, "short"},
3450Sstevel@tonic-gate 			{TOK_LONG, "long"},
3460Sstevel@tonic-gate 			{TOK_UNSIGNED, "unsigned"},
3470Sstevel@tonic-gate 			{TOK_DOUBLE, "double"},
3480Sstevel@tonic-gate 			{TOK_FLOAT, "float"},
3490Sstevel@tonic-gate 			{TOK_CHAR, "char"},
3500Sstevel@tonic-gate 			{TOK_STRING, "string"},
3510Sstevel@tonic-gate 			{TOK_OPAQUE, "opaque"},
3520Sstevel@tonic-gate 			{TOK_BOOL, "bool"},
3530Sstevel@tonic-gate 			{TOK_VOID, "void"},
3540Sstevel@tonic-gate 			{TOK_PROGRAM, "program"},
3550Sstevel@tonic-gate 			{TOK_VERSION, "version"},
3560Sstevel@tonic-gate 			{TOK_EOF, "??????"}
3570Sstevel@tonic-gate };
3580Sstevel@tonic-gate 
3590Sstevel@tonic-gate static char *
toktostr(tok_kind kind)360132Srobinson toktostr(tok_kind kind)
3610Sstevel@tonic-gate {
3620Sstevel@tonic-gate 	token *sp;
3630Sstevel@tonic-gate 
364*9497SJordan.Brown@Sun.COM 	for (sp = tokstrings; sp->kind != TOK_EOF && sp->kind != kind; sp++)
365*9497SJordan.Brown@Sun.COM 		/* LOOP */;
3660Sstevel@tonic-gate 	return (sp->str);
3670Sstevel@tonic-gate }
3680Sstevel@tonic-gate 
369132Srobinson static void
printbuf(void)370132Srobinson printbuf(void)
3710Sstevel@tonic-gate {
3720Sstevel@tonic-gate 	char c;
3730Sstevel@tonic-gate 	int i;
3740Sstevel@tonic-gate 	int cnt;
3750Sstevel@tonic-gate 
376132Srobinson #define	TABSIZE 4
3770Sstevel@tonic-gate 
378132Srobinson 	for (i = 0; (c = curline[i]) != '\0'; i++) {
3790Sstevel@tonic-gate 		if (c == '\t') {
3800Sstevel@tonic-gate 			cnt = 8 - (i % TABSIZE);
3810Sstevel@tonic-gate 			c = ' ';
3820Sstevel@tonic-gate 		} else {
3830Sstevel@tonic-gate 			cnt = 1;
3840Sstevel@tonic-gate 		}
385132Srobinson 		while (cnt--)
3860Sstevel@tonic-gate 			(void) fputc(c, stderr);
3870Sstevel@tonic-gate 	}
3880Sstevel@tonic-gate }
3890Sstevel@tonic-gate 
390132Srobinson static void
printwhere(void)391132Srobinson printwhere(void)
3920Sstevel@tonic-gate {
3930Sstevel@tonic-gate 	int i;
3940Sstevel@tonic-gate 	char c;
3950Sstevel@tonic-gate 	int cnt;
3960Sstevel@tonic-gate 
3970Sstevel@tonic-gate 	printbuf();
3980Sstevel@tonic-gate 	for (i = 0; i < where - curline; i++) {
3990Sstevel@tonic-gate 		c = curline[i];
4000Sstevel@tonic-gate 		if (c == '\t') {
4010Sstevel@tonic-gate 			cnt = 8 - (i % TABSIZE);
4020Sstevel@tonic-gate 		} else {
4030Sstevel@tonic-gate 			cnt = 1;
4040Sstevel@tonic-gate 		}
405132Srobinson 		while (cnt--)
4060Sstevel@tonic-gate 			(void) fputc('^', stderr);
4070Sstevel@tonic-gate 	}
4080Sstevel@tonic-gate 	(void) fputc('\n', stderr);
4090Sstevel@tonic-gate }
4100Sstevel@tonic-gate 
4110Sstevel@tonic-gate char *
make_argname(char * pname,char * vname)412132Srobinson make_argname(char *pname, char *vname)
4130Sstevel@tonic-gate {
4140Sstevel@tonic-gate 	char *name;
415132Srobinson 	size_t nlen;
4160Sstevel@tonic-gate 
417132Srobinson 	nlen = strlen(pname) + strlen(vname) + strlen(ARGEXT) + 3;
418132Srobinson 	name = malloc(nlen);
419132Srobinson 	if (name == NULL) {
420132Srobinson 		(void) fprintf(stderr, "failed in malloc");
4210Sstevel@tonic-gate 		exit(1);
4220Sstevel@tonic-gate 	}
423132Srobinson 	(void) snprintf(name, nlen, "%s_%s_%s", locase(pname), vname, ARGEXT);
4240Sstevel@tonic-gate 	return (name);
4250Sstevel@tonic-gate }
4260Sstevel@tonic-gate 
4270Sstevel@tonic-gate bas_type *typ_list_h;
4280Sstevel@tonic-gate bas_type *typ_list_t;
4290Sstevel@tonic-gate 
430132Srobinson void
add_type(int len,char * type)431132Srobinson add_type(int len, char *type)
4320Sstevel@tonic-gate {
4330Sstevel@tonic-gate 	bas_type *ptr;
4340Sstevel@tonic-gate 
435132Srobinson 	if ((ptr = malloc(sizeof (bas_type))) == NULL) {
436132Srobinson 		(void) fprintf(stderr, "failed in malloc");
4370Sstevel@tonic-gate 		exit(1);
4380Sstevel@tonic-gate 	}
4390Sstevel@tonic-gate 
4400Sstevel@tonic-gate 	ptr->name = type;
4410Sstevel@tonic-gate 	ptr->length = len;
4420Sstevel@tonic-gate 	ptr->next = NULL;
443132Srobinson 	if (typ_list_t == NULL) {
4440Sstevel@tonic-gate 		typ_list_t = ptr;
4450Sstevel@tonic-gate 		typ_list_h = ptr;
446132Srobinson 	} else {
4470Sstevel@tonic-gate 		typ_list_t->next = ptr;
4480Sstevel@tonic-gate 		typ_list_t = ptr;
449132Srobinson 	}
4500Sstevel@tonic-gate }
4510Sstevel@tonic-gate 
4520Sstevel@tonic-gate 
453132Srobinson bas_type *
find_type(char * type)454132Srobinson find_type(char *type)
4550Sstevel@tonic-gate {
456132Srobinson 	bas_type *ptr;
4570Sstevel@tonic-gate 
4580Sstevel@tonic-gate 	ptr = typ_list_h;
459132Srobinson 	while (ptr != NULL) {
4600Sstevel@tonic-gate 		if (strcmp(ptr->name, type) == 0)
4610Sstevel@tonic-gate 			return (ptr);
462132Srobinson 		ptr = ptr->next;
463132Srobinson 	}
4640Sstevel@tonic-gate 	return (NULL);
4650Sstevel@tonic-gate }
466