xref: /freebsd/usr.bin/rpcgen/rpc_parse.c (revision 4e115012be61e89caf65497654493e52630b15e4)
14e115012SGarrett Wollman /* @(#)rpc_parse.c	2.1 88/08/01 4.0 RPCSRC */
24e115012SGarrett Wollman /*
34e115012SGarrett Wollman  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
44e115012SGarrett Wollman  * unrestricted use provided that this legend is included on all tape
54e115012SGarrett Wollman  * media and as a part of the software program in whole or part.  Users
64e115012SGarrett Wollman  * may copy or modify Sun RPC without charge, but are not authorized
74e115012SGarrett Wollman  * to license or distribute it to anyone else except as part of a product or
84e115012SGarrett Wollman  * program developed by the user.
94e115012SGarrett Wollman  *
104e115012SGarrett Wollman  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
114e115012SGarrett Wollman  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
124e115012SGarrett Wollman  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
134e115012SGarrett Wollman  *
144e115012SGarrett Wollman  * Sun RPC is provided with no support and without any obligation on the
154e115012SGarrett Wollman  * part of Sun Microsystems, Inc. to assist in its use, correction,
164e115012SGarrett Wollman  * modification or enhancement.
174e115012SGarrett Wollman  *
184e115012SGarrett Wollman  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
194e115012SGarrett Wollman  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
204e115012SGarrett Wollman  * OR ANY PART THEREOF.
214e115012SGarrett Wollman  *
224e115012SGarrett Wollman  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
234e115012SGarrett Wollman  * or profits or other special, indirect and consequential damages, even if
244e115012SGarrett Wollman  * Sun has been advised of the possibility of such damages.
254e115012SGarrett Wollman  *
264e115012SGarrett Wollman  * Sun Microsystems, Inc.
274e115012SGarrett Wollman  * 2550 Garcia Avenue
284e115012SGarrett Wollman  * Mountain View, California  94043
294e115012SGarrett Wollman  */
304e115012SGarrett Wollman #ifndef lint
314e115012SGarrett Wollman /*static char sccsid[] = "from: @(#)rpc_parse.c 1.4 87/04/28 (C) 1987 SMI";*/
324e115012SGarrett Wollman static char rcsid[] = "$Id: rpc_parse.c,v 1.1 1993/09/13 23:20:16 jtc Exp $";
334e115012SGarrett Wollman #endif
344e115012SGarrett Wollman 
354e115012SGarrett Wollman /*
364e115012SGarrett Wollman  * rpc_parse.c, Parser for the RPC protocol compiler
374e115012SGarrett Wollman  * Copyright (C) 1987 Sun Microsystems, Inc.
384e115012SGarrett Wollman  */
394e115012SGarrett Wollman #include <stdio.h>
404e115012SGarrett Wollman #include "rpc_util.h"
414e115012SGarrett Wollman #include "rpc_scan.h"
424e115012SGarrett Wollman #include "rpc_parse.h"
434e115012SGarrett Wollman 
444e115012SGarrett Wollman static int isdefined(), def_struct(), def_program(), def_enum(), def_const(),
454e115012SGarrett Wollman 	   def_union(), def_typedef(), get_declaration(), get_type(),
464e115012SGarrett Wollman 	   unsigned_dec();
474e115012SGarrett Wollman /*
484e115012SGarrett Wollman  * return the next definition you see
494e115012SGarrett Wollman  */
504e115012SGarrett Wollman definition *
514e115012SGarrett Wollman get_definition()
524e115012SGarrett Wollman {
534e115012SGarrett Wollman 	definition *defp;
544e115012SGarrett Wollman 	token tok;
554e115012SGarrett Wollman 
564e115012SGarrett Wollman 	defp = ALLOC(definition);
574e115012SGarrett Wollman 	get_token(&tok);
584e115012SGarrett Wollman 	switch (tok.kind) {
594e115012SGarrett Wollman 	case TOK_STRUCT:
604e115012SGarrett Wollman 		def_struct(defp);
614e115012SGarrett Wollman 		break;
624e115012SGarrett Wollman 	case TOK_UNION:
634e115012SGarrett Wollman 		def_union(defp);
644e115012SGarrett Wollman 		break;
654e115012SGarrett Wollman 	case TOK_TYPEDEF:
664e115012SGarrett Wollman 		def_typedef(defp);
674e115012SGarrett Wollman 		break;
684e115012SGarrett Wollman 	case TOK_ENUM:
694e115012SGarrett Wollman 		def_enum(defp);
704e115012SGarrett Wollman 		break;
714e115012SGarrett Wollman 	case TOK_PROGRAM:
724e115012SGarrett Wollman 		def_program(defp);
734e115012SGarrett Wollman 		break;
744e115012SGarrett Wollman 	case TOK_CONST:
754e115012SGarrett Wollman 		def_const(defp);
764e115012SGarrett Wollman 		break;
774e115012SGarrett Wollman 	case TOK_EOF:
784e115012SGarrett Wollman 		return (NULL);
794e115012SGarrett Wollman 		break;
804e115012SGarrett Wollman 	default:
814e115012SGarrett Wollman 		error("definition keyword expected");
824e115012SGarrett Wollman 	}
834e115012SGarrett Wollman 	scan(TOK_SEMICOLON, &tok);
844e115012SGarrett Wollman 	isdefined(defp);
854e115012SGarrett Wollman 	return (defp);
864e115012SGarrett Wollman }
874e115012SGarrett Wollman 
884e115012SGarrett Wollman static
894e115012SGarrett Wollman isdefined(defp)
904e115012SGarrett Wollman 	definition *defp;
914e115012SGarrett Wollman {
924e115012SGarrett Wollman 	STOREVAL(&defined, defp);
934e115012SGarrett Wollman }
944e115012SGarrett Wollman 
954e115012SGarrett Wollman 
964e115012SGarrett Wollman static
974e115012SGarrett Wollman def_struct(defp)
984e115012SGarrett Wollman 	definition *defp;
994e115012SGarrett Wollman {
1004e115012SGarrett Wollman 	token tok;
1014e115012SGarrett Wollman 	declaration dec;
1024e115012SGarrett Wollman 	decl_list *decls;
1034e115012SGarrett Wollman 	decl_list **tailp;
1044e115012SGarrett Wollman 
1054e115012SGarrett Wollman 	defp->def_kind = DEF_STRUCT;
1064e115012SGarrett Wollman 
1074e115012SGarrett Wollman 	scan(TOK_IDENT, &tok);
1084e115012SGarrett Wollman 	defp->def_name = tok.str;
1094e115012SGarrett Wollman 	scan(TOK_LBRACE, &tok);
1104e115012SGarrett Wollman 	tailp = &defp->def.st.decls;
1114e115012SGarrett Wollman 	do {
1124e115012SGarrett Wollman 		get_declaration(&dec, DEF_STRUCT);
1134e115012SGarrett Wollman 		decls = ALLOC(decl_list);
1144e115012SGarrett Wollman 		decls->decl = dec;
1154e115012SGarrett Wollman 		*tailp = decls;
1164e115012SGarrett Wollman 		tailp = &decls->next;
1174e115012SGarrett Wollman 		scan(TOK_SEMICOLON, &tok);
1184e115012SGarrett Wollman 		peek(&tok);
1194e115012SGarrett Wollman 	} while (tok.kind != TOK_RBRACE);
1204e115012SGarrett Wollman 	get_token(&tok);
1214e115012SGarrett Wollman 	*tailp = NULL;
1224e115012SGarrett Wollman }
1234e115012SGarrett Wollman 
1244e115012SGarrett Wollman static
1254e115012SGarrett Wollman def_program(defp)
1264e115012SGarrett Wollman 	definition *defp;
1274e115012SGarrett Wollman {
1284e115012SGarrett Wollman 	token tok;
1294e115012SGarrett Wollman 	version_list *vlist;
1304e115012SGarrett Wollman 	version_list **vtailp;
1314e115012SGarrett Wollman 	proc_list *plist;
1324e115012SGarrett Wollman 	proc_list **ptailp;
1334e115012SGarrett Wollman 
1344e115012SGarrett Wollman 	defp->def_kind = DEF_PROGRAM;
1354e115012SGarrett Wollman 	scan(TOK_IDENT, &tok);
1364e115012SGarrett Wollman 	defp->def_name = tok.str;
1374e115012SGarrett Wollman 	scan(TOK_LBRACE, &tok);
1384e115012SGarrett Wollman 	vtailp = &defp->def.pr.versions;
1394e115012SGarrett Wollman 	scan(TOK_VERSION, &tok);
1404e115012SGarrett Wollman 	do {
1414e115012SGarrett Wollman 		scan(TOK_IDENT, &tok);
1424e115012SGarrett Wollman 		vlist = ALLOC(version_list);
1434e115012SGarrett Wollman 		vlist->vers_name = tok.str;
1444e115012SGarrett Wollman 		scan(TOK_LBRACE, &tok);
1454e115012SGarrett Wollman 		ptailp = &vlist->procs;
1464e115012SGarrett Wollman 		do {
1474e115012SGarrett Wollman 			plist = ALLOC(proc_list);
1484e115012SGarrett Wollman 			get_type(&plist->res_prefix, &plist->res_type, DEF_PROGRAM);
1494e115012SGarrett Wollman 			if (streq(plist->res_type, "opaque")) {
1504e115012SGarrett Wollman 				error("illegal result type");
1514e115012SGarrett Wollman 			}
1524e115012SGarrett Wollman 			scan(TOK_IDENT, &tok);
1534e115012SGarrett Wollman 			plist->proc_name = tok.str;
1544e115012SGarrett Wollman 			scan(TOK_LPAREN, &tok);
1554e115012SGarrett Wollman 			get_type(&plist->arg_prefix, &plist->arg_type, DEF_PROGRAM);
1564e115012SGarrett Wollman 			if (streq(plist->arg_type, "opaque")) {
1574e115012SGarrett Wollman 				error("illegal argument type");
1584e115012SGarrett Wollman 			}
1594e115012SGarrett Wollman 			scan(TOK_RPAREN, &tok);
1604e115012SGarrett Wollman 			scan(TOK_EQUAL, &tok);
1614e115012SGarrett Wollman 			scan_num(&tok);
1624e115012SGarrett Wollman 			scan(TOK_SEMICOLON, &tok);
1634e115012SGarrett Wollman 			plist->proc_num = tok.str;
1644e115012SGarrett Wollman 			*ptailp = plist;
1654e115012SGarrett Wollman 			ptailp = &plist->next;
1664e115012SGarrett Wollman 			peek(&tok);
1674e115012SGarrett Wollman 		} while (tok.kind != TOK_RBRACE);
1684e115012SGarrett Wollman 		*vtailp = vlist;
1694e115012SGarrett Wollman 		vtailp = &vlist->next;
1704e115012SGarrett Wollman 		scan(TOK_RBRACE, &tok);
1714e115012SGarrett Wollman 		scan(TOK_EQUAL, &tok);
1724e115012SGarrett Wollman 		scan_num(&tok);
1734e115012SGarrett Wollman 		vlist->vers_num = tok.str;
1744e115012SGarrett Wollman 		scan(TOK_SEMICOLON, &tok);
1754e115012SGarrett Wollman 		scan2(TOK_VERSION, TOK_RBRACE, &tok);
1764e115012SGarrett Wollman 	} while (tok.kind == TOK_VERSION);
1774e115012SGarrett Wollman 	scan(TOK_EQUAL, &tok);
1784e115012SGarrett Wollman 	scan_num(&tok);
1794e115012SGarrett Wollman 	defp->def.pr.prog_num = tok.str;
1804e115012SGarrett Wollman 	*vtailp = NULL;
1814e115012SGarrett Wollman }
1824e115012SGarrett Wollman 
1834e115012SGarrett Wollman static
1844e115012SGarrett Wollman def_enum(defp)
1854e115012SGarrett Wollman 	definition *defp;
1864e115012SGarrett Wollman {
1874e115012SGarrett Wollman 	token tok;
1884e115012SGarrett Wollman 	enumval_list *elist;
1894e115012SGarrett Wollman 	enumval_list **tailp;
1904e115012SGarrett Wollman 
1914e115012SGarrett Wollman 	defp->def_kind = DEF_ENUM;
1924e115012SGarrett Wollman 	scan(TOK_IDENT, &tok);
1934e115012SGarrett Wollman 	defp->def_name = tok.str;
1944e115012SGarrett Wollman 	scan(TOK_LBRACE, &tok);
1954e115012SGarrett Wollman 	tailp = &defp->def.en.vals;
1964e115012SGarrett Wollman 	do {
1974e115012SGarrett Wollman 		scan(TOK_IDENT, &tok);
1984e115012SGarrett Wollman 		elist = ALLOC(enumval_list);
1994e115012SGarrett Wollman 		elist->name = tok.str;
2004e115012SGarrett Wollman 		elist->assignment = NULL;
2014e115012SGarrett Wollman 		scan3(TOK_COMMA, TOK_RBRACE, TOK_EQUAL, &tok);
2024e115012SGarrett Wollman 		if (tok.kind == TOK_EQUAL) {
2034e115012SGarrett Wollman 			scan_num(&tok);
2044e115012SGarrett Wollman 			elist->assignment = tok.str;
2054e115012SGarrett Wollman 			scan2(TOK_COMMA, TOK_RBRACE, &tok);
2064e115012SGarrett Wollman 		}
2074e115012SGarrett Wollman 		*tailp = elist;
2084e115012SGarrett Wollman 		tailp = &elist->next;
2094e115012SGarrett Wollman 	} while (tok.kind != TOK_RBRACE);
2104e115012SGarrett Wollman 	*tailp = NULL;
2114e115012SGarrett Wollman }
2124e115012SGarrett Wollman 
2134e115012SGarrett Wollman static
2144e115012SGarrett Wollman def_const(defp)
2154e115012SGarrett Wollman 	definition *defp;
2164e115012SGarrett Wollman {
2174e115012SGarrett Wollman 	token tok;
2184e115012SGarrett Wollman 
2194e115012SGarrett Wollman 	defp->def_kind = DEF_CONST;
2204e115012SGarrett Wollman 	scan(TOK_IDENT, &tok);
2214e115012SGarrett Wollman 	defp->def_name = tok.str;
2224e115012SGarrett Wollman 	scan(TOK_EQUAL, &tok);
2234e115012SGarrett Wollman 	scan2(TOK_IDENT, TOK_STRCONST, &tok);
2244e115012SGarrett Wollman 	defp->def.co = tok.str;
2254e115012SGarrett Wollman }
2264e115012SGarrett Wollman 
2274e115012SGarrett Wollman static
2284e115012SGarrett Wollman def_union(defp)
2294e115012SGarrett Wollman 	definition *defp;
2304e115012SGarrett Wollman {
2314e115012SGarrett Wollman 	token tok;
2324e115012SGarrett Wollman 	declaration dec;
2334e115012SGarrett Wollman 	case_list *cases;
2344e115012SGarrett Wollman 	case_list **tailp;
2354e115012SGarrett Wollman 
2364e115012SGarrett Wollman 	defp->def_kind = DEF_UNION;
2374e115012SGarrett Wollman 	scan(TOK_IDENT, &tok);
2384e115012SGarrett Wollman 	defp->def_name = tok.str;
2394e115012SGarrett Wollman 	scan(TOK_SWITCH, &tok);
2404e115012SGarrett Wollman 	scan(TOK_LPAREN, &tok);
2414e115012SGarrett Wollman 	get_declaration(&dec, DEF_UNION);
2424e115012SGarrett Wollman 	defp->def.un.enum_decl = dec;
2434e115012SGarrett Wollman 	tailp = &defp->def.un.cases;
2444e115012SGarrett Wollman 	scan(TOK_RPAREN, &tok);
2454e115012SGarrett Wollman 	scan(TOK_LBRACE, &tok);
2464e115012SGarrett Wollman 	scan(TOK_CASE, &tok);
2474e115012SGarrett Wollman 	while (tok.kind == TOK_CASE) {
2484e115012SGarrett Wollman 		scan(TOK_IDENT, &tok);
2494e115012SGarrett Wollman 		cases = ALLOC(case_list);
2504e115012SGarrett Wollman 		cases->case_name = tok.str;
2514e115012SGarrett Wollman 		scan(TOK_COLON, &tok);
2524e115012SGarrett Wollman 		get_declaration(&dec, DEF_UNION);
2534e115012SGarrett Wollman 		cases->case_decl = dec;
2544e115012SGarrett Wollman 		*tailp = cases;
2554e115012SGarrett Wollman 		tailp = &cases->next;
2564e115012SGarrett Wollman 		scan(TOK_SEMICOLON, &tok);
2574e115012SGarrett Wollman 		scan3(TOK_CASE, TOK_DEFAULT, TOK_RBRACE, &tok);
2584e115012SGarrett Wollman 	}
2594e115012SGarrett Wollman 	*tailp = NULL;
2604e115012SGarrett Wollman 	if (tok.kind == TOK_DEFAULT) {
2614e115012SGarrett Wollman 		scan(TOK_COLON, &tok);
2624e115012SGarrett Wollman 		get_declaration(&dec, DEF_UNION);
2634e115012SGarrett Wollman 		defp->def.un.default_decl = ALLOC(declaration);
2644e115012SGarrett Wollman 		*defp->def.un.default_decl = dec;
2654e115012SGarrett Wollman 		scan(TOK_SEMICOLON, &tok);
2664e115012SGarrett Wollman 		scan(TOK_RBRACE, &tok);
2674e115012SGarrett Wollman 	} else {
2684e115012SGarrett Wollman 		defp->def.un.default_decl = NULL;
2694e115012SGarrett Wollman 	}
2704e115012SGarrett Wollman }
2714e115012SGarrett Wollman 
2724e115012SGarrett Wollman 
2734e115012SGarrett Wollman static
2744e115012SGarrett Wollman def_typedef(defp)
2754e115012SGarrett Wollman 	definition *defp;
2764e115012SGarrett Wollman {
2774e115012SGarrett Wollman 	declaration dec;
2784e115012SGarrett Wollman 
2794e115012SGarrett Wollman 	defp->def_kind = DEF_TYPEDEF;
2804e115012SGarrett Wollman 	get_declaration(&dec, DEF_TYPEDEF);
2814e115012SGarrett Wollman 	defp->def_name = dec.name;
2824e115012SGarrett Wollman 	defp->def.ty.old_prefix = dec.prefix;
2834e115012SGarrett Wollman 	defp->def.ty.old_type = dec.type;
2844e115012SGarrett Wollman 	defp->def.ty.rel = dec.rel;
2854e115012SGarrett Wollman 	defp->def.ty.array_max = dec.array_max;
2864e115012SGarrett Wollman }
2874e115012SGarrett Wollman 
2884e115012SGarrett Wollman 
2894e115012SGarrett Wollman static
2904e115012SGarrett Wollman get_declaration(dec, dkind)
2914e115012SGarrett Wollman 	declaration *dec;
2924e115012SGarrett Wollman 	defkind dkind;
2934e115012SGarrett Wollman {
2944e115012SGarrett Wollman 	token tok;
2954e115012SGarrett Wollman 
2964e115012SGarrett Wollman 	get_type(&dec->prefix, &dec->type, dkind);
2974e115012SGarrett Wollman 	dec->rel = REL_ALIAS;
2984e115012SGarrett Wollman 	if (streq(dec->type, "void")) {
2994e115012SGarrett Wollman 		return;
3004e115012SGarrett Wollman 	}
3014e115012SGarrett Wollman 	scan2(TOK_STAR, TOK_IDENT, &tok);
3024e115012SGarrett Wollman 	if (tok.kind == TOK_STAR) {
3034e115012SGarrett Wollman 		dec->rel = REL_POINTER;
3044e115012SGarrett Wollman 		scan(TOK_IDENT, &tok);
3054e115012SGarrett Wollman 	}
3064e115012SGarrett Wollman 	dec->name = tok.str;
3074e115012SGarrett Wollman 	if (peekscan(TOK_LBRACKET, &tok)) {
3084e115012SGarrett Wollman 		if (dec->rel == REL_POINTER) {
3094e115012SGarrett Wollman 			error("no array-of-pointer declarations -- use typedef");
3104e115012SGarrett Wollman 		}
3114e115012SGarrett Wollman 		dec->rel = REL_VECTOR;
3124e115012SGarrett Wollman 		scan_num(&tok);
3134e115012SGarrett Wollman 		dec->array_max = tok.str;
3144e115012SGarrett Wollman 		scan(TOK_RBRACKET, &tok);
3154e115012SGarrett Wollman 	} else if (peekscan(TOK_LANGLE, &tok)) {
3164e115012SGarrett Wollman 		if (dec->rel == REL_POINTER) {
3174e115012SGarrett Wollman 			error("no array-of-pointer declarations -- use typedef");
3184e115012SGarrett Wollman 		}
3194e115012SGarrett Wollman 		dec->rel = REL_ARRAY;
3204e115012SGarrett Wollman 		if (peekscan(TOK_RANGLE, &tok)) {
3214e115012SGarrett Wollman 			dec->array_max = "~0";	/* unspecified size, use max */
3224e115012SGarrett Wollman 		} else {
3234e115012SGarrett Wollman 			scan_num(&tok);
3244e115012SGarrett Wollman 			dec->array_max = tok.str;
3254e115012SGarrett Wollman 			scan(TOK_RANGLE, &tok);
3264e115012SGarrett Wollman 		}
3274e115012SGarrett Wollman 	}
3284e115012SGarrett Wollman 	if (streq(dec->type, "opaque")) {
3294e115012SGarrett Wollman 		if (dec->rel != REL_ARRAY && dec->rel != REL_VECTOR) {
3304e115012SGarrett Wollman 			error("array declaration expected");
3314e115012SGarrett Wollman 		}
3324e115012SGarrett Wollman 	} else if (streq(dec->type, "string")) {
3334e115012SGarrett Wollman 		if (dec->rel != REL_ARRAY) {
3344e115012SGarrett Wollman 			error("variable-length array declaration expected");
3354e115012SGarrett Wollman 		}
3364e115012SGarrett Wollman 	}
3374e115012SGarrett Wollman }
3384e115012SGarrett Wollman 
3394e115012SGarrett Wollman 
3404e115012SGarrett Wollman static
3414e115012SGarrett Wollman get_type(prefixp, typep, dkind)
3424e115012SGarrett Wollman 	char **prefixp;
3434e115012SGarrett Wollman 	char **typep;
3444e115012SGarrett Wollman 	defkind dkind;
3454e115012SGarrett Wollman {
3464e115012SGarrett Wollman 	token tok;
3474e115012SGarrett Wollman 
3484e115012SGarrett Wollman 	*prefixp = NULL;
3494e115012SGarrett Wollman 	get_token(&tok);
3504e115012SGarrett Wollman 	switch (tok.kind) {
3514e115012SGarrett Wollman 	case TOK_IDENT:
3524e115012SGarrett Wollman 		*typep = tok.str;
3534e115012SGarrett Wollman 		break;
3544e115012SGarrett Wollman 	case TOK_STRUCT:
3554e115012SGarrett Wollman 	case TOK_ENUM:
3564e115012SGarrett Wollman 	case TOK_UNION:
3574e115012SGarrett Wollman 		*prefixp = tok.str;
3584e115012SGarrett Wollman 		scan(TOK_IDENT, &tok);
3594e115012SGarrett Wollman 		*typep = tok.str;
3604e115012SGarrett Wollman 		break;
3614e115012SGarrett Wollman 	case TOK_UNSIGNED:
3624e115012SGarrett Wollman 		unsigned_dec(typep);
3634e115012SGarrett Wollman 		break;
3644e115012SGarrett Wollman 	case TOK_SHORT:
3654e115012SGarrett Wollman 		*typep = "short";
3664e115012SGarrett Wollman 		(void) peekscan(TOK_INT, &tok);
3674e115012SGarrett Wollman 		break;
3684e115012SGarrett Wollman 	case TOK_LONG:
3694e115012SGarrett Wollman 		*typep = "long";
3704e115012SGarrett Wollman 		(void) peekscan(TOK_INT, &tok);
3714e115012SGarrett Wollman 		break;
3724e115012SGarrett Wollman 	case TOK_VOID:
3734e115012SGarrett Wollman 		if (dkind != DEF_UNION && dkind != DEF_PROGRAM) {
3744e115012SGarrett Wollman 			error("voids allowed only inside union and program definitions");
3754e115012SGarrett Wollman 		}
3764e115012SGarrett Wollman 		*typep = tok.str;
3774e115012SGarrett Wollman 		break;
3784e115012SGarrett Wollman 	case TOK_STRING:
3794e115012SGarrett Wollman 	case TOK_OPAQUE:
3804e115012SGarrett Wollman 	case TOK_CHAR:
3814e115012SGarrett Wollman 	case TOK_INT:
3824e115012SGarrett Wollman 	case TOK_FLOAT:
3834e115012SGarrett Wollman 	case TOK_DOUBLE:
3844e115012SGarrett Wollman 	case TOK_BOOL:
3854e115012SGarrett Wollman 		*typep = tok.str;
3864e115012SGarrett Wollman 		break;
3874e115012SGarrett Wollman 	default:
3884e115012SGarrett Wollman 		error("expected type specifier");
3894e115012SGarrett Wollman 	}
3904e115012SGarrett Wollman }
3914e115012SGarrett Wollman 
3924e115012SGarrett Wollman 
3934e115012SGarrett Wollman static
3944e115012SGarrett Wollman unsigned_dec(typep)
3954e115012SGarrett Wollman 	char **typep;
3964e115012SGarrett Wollman {
3974e115012SGarrett Wollman 	token tok;
3984e115012SGarrett Wollman 
3994e115012SGarrett Wollman 	peek(&tok);
4004e115012SGarrett Wollman 	switch (tok.kind) {
4014e115012SGarrett Wollman 	case TOK_CHAR:
4024e115012SGarrett Wollman 		get_token(&tok);
4034e115012SGarrett Wollman 		*typep = "u_char";
4044e115012SGarrett Wollman 		break;
4054e115012SGarrett Wollman 	case TOK_SHORT:
4064e115012SGarrett Wollman 		get_token(&tok);
4074e115012SGarrett Wollman 		*typep = "u_short";
4084e115012SGarrett Wollman 		(void) peekscan(TOK_INT, &tok);
4094e115012SGarrett Wollman 		break;
4104e115012SGarrett Wollman 	case TOK_LONG:
4114e115012SGarrett Wollman 		get_token(&tok);
4124e115012SGarrett Wollman 		*typep = "u_long";
4134e115012SGarrett Wollman 		(void) peekscan(TOK_INT, &tok);
4144e115012SGarrett Wollman 		break;
4154e115012SGarrett Wollman 	case TOK_INT:
4164e115012SGarrett Wollman 		get_token(&tok);
4174e115012SGarrett Wollman 		*typep = "u_int";
4184e115012SGarrett Wollman 		break;
4194e115012SGarrett Wollman 	default:
4204e115012SGarrett Wollman 		*typep = "u_int";
4214e115012SGarrett Wollman 		break;
4224e115012SGarrett Wollman 	}
4234e115012SGarrett Wollman }
424