diff options
Diffstat (limited to 'usr.bin/rpcgen/rpc_util.c')
-rw-r--r-- | usr.bin/rpcgen/rpc_util.c | 203 |
1 files changed, 136 insertions, 67 deletions
diff --git a/usr.bin/rpcgen/rpc_util.c b/usr.bin/rpcgen/rpc_util.c index fb3307d..5d3fa06 100644 --- a/usr.bin/rpcgen/rpc_util.c +++ b/usr.bin/rpcgen/rpc_util.c @@ -1,4 +1,3 @@ -/* @(#)rpc_util.c 2.1 88/08/01 4.0 RPCSRC */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for * unrestricted use provided that this legend is included on all tape @@ -6,64 +5,69 @@ * may copy or modify Sun RPC without charge, but are not authorized * to license or distribute it to anyone else except as part of a product or * program developed by the user. - * + * * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. - * + * * Sun RPC is provided with no support and without any obligation on the * part of Sun Microsystems, Inc. to assist in its use, correction, * modification or enhancement. - * + * * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC * OR ANY PART THEREOF. - * + * * In no event will Sun Microsystems, Inc. be liable for any lost revenue * or profits or other special, indirect and consequential damages, even if * Sun has been advised of the possibility of such damages. - * + * * Sun Microsystems, Inc. * 2550 Garcia Avenue * Mountain View, California 94043 */ + +#ident "@(#)rpc_util.c 1.14 93/07/05 SMI" + #ifndef lint -/*static char sccsid[] = "from: @(#)rpc_util.c 1.5 87/06/24 (C) 1987 SMI";*/ -static char rcsid[] = "$Id: rpc_util.c,v 1.1 1994/08/07 18:01:37 wollman Exp $"; +static char sccsid[] = "@(#)rpc_util.c 1.11 89/02/22 (C) 1987 SMI"; #endif /* * rpc_util.c, Utility routines for the RPC protocol compiler - * Copyright (C) 1987, Sun Microsystems, Inc. + * Copyright (C) 1989, Sun Microsystems, Inc. */ #include <stdio.h> +#include <ctype.h> #include "rpc_scan.h" #include "rpc_parse.h" #include "rpc_util.h" +#define ARGEXT "argument" + char curline[MAXLINESIZE]; /* current read line */ -char *where = curline; /* current point in line */ -int linenum = 0; /* current line number */ +char *where = curline; /* current point in line */ +int linenum = 0; /* current line number */ -char *infilename; /* input filename */ +char *infilename; /* input filename */ -#define NFILES 4 -char *outfiles[NFILES]; /* output file names */ +#define NFILES 7 +char *outfiles[NFILES]; /* output file names */ int nfiles; -FILE *fout; /* file pointer of current output */ -FILE *fin; /* file pointer of current input */ +FILE *fout; /* file pointer of current output */ +FILE *fin; /* file pointer of current input */ -list *defined; /* list of defined things */ +list *defined; /* list of defined things */ -static int printwhere(); +static int printwhere __P(( void )); /* * Reinitialize the world */ reinitialize() { - bzero(curline, MAXLINESIZE); + memset(curline, 0, MAXLINESIZE); where = curline; linenum = 0; defined = NULL; @@ -82,7 +86,7 @@ streq(a, b) /* * find a value in a list */ -char * +definition * findval(lst, val, cmp) list *lst; char *val; @@ -103,7 +107,7 @@ findval(lst, val, cmp) void storeval(lstp, val) list **lstp; - char *val; + definition *val; { list **l; list *lst; @@ -115,7 +119,6 @@ storeval(lstp, val) *l = lst; } - static findit(def, type) definition *def; @@ -124,7 +127,6 @@ findit(def, type) return (streq(def->def_name, type)); } - static char * fixit(type, orig) char *type; @@ -138,7 +140,11 @@ fixit(type, orig) } switch (def->def.ty.rel) { case REL_VECTOR: - return (def->def.ty.old_type); + if (streq(def->def.ty.old_type, "opaque")) + return ("char"); + else + return (def->def.ty.old_type); + case REL_ALIAS: return (fixit(def->def.ty.old_type, orig)); default: @@ -186,7 +192,6 @@ ptype(prefix, type, follow) } } - static typedefed(def, type) definition *def; @@ -224,8 +229,7 @@ isvectordef(type, rel) } } - -static char * +char * locase(str) char *str; { @@ -240,6 +244,13 @@ locase(str) return (buf); } +void +pvname_svc(pname, vnum) + char *pname; + char *vnum; +{ + f_print(fout, "%s_%s_svc", locase(pname), vnum); +} void pvname(pname, vnum) @@ -249,7 +260,6 @@ pvname(pname, vnum) f_print(fout, "%s_%s", locase(pname), vnum); } - /* * print a useful (?) error message, and then die */ @@ -277,7 +287,6 @@ crash() exit(1); } - void record_open(file) char *file; @@ -343,42 +352,41 @@ tabify(f, tab) } - static token tokstrings[] = { - {TOK_IDENT, "identifier"}, - {TOK_CONST, "const"}, - {TOK_RPAREN, ")"}, - {TOK_LPAREN, "("}, - {TOK_RBRACE, "}"}, - {TOK_LBRACE, "{"}, - {TOK_LBRACKET, "["}, - {TOK_RBRACKET, "]"}, - {TOK_STAR, "*"}, - {TOK_COMMA, ","}, - {TOK_EQUAL, "="}, - {TOK_COLON, ":"}, - {TOK_SEMICOLON, ";"}, - {TOK_UNION, "union"}, - {TOK_STRUCT, "struct"}, - {TOK_SWITCH, "switch"}, - {TOK_CASE, "case"}, - {TOK_DEFAULT, "default"}, - {TOK_ENUM, "enum"}, - {TOK_TYPEDEF, "typedef"}, - {TOK_INT, "int"}, - {TOK_SHORT, "short"}, - {TOK_LONG, "long"}, - {TOK_UNSIGNED, "unsigned"}, - {TOK_DOUBLE, "double"}, - {TOK_FLOAT, "float"}, - {TOK_CHAR, "char"}, - {TOK_STRING, "string"}, - {TOK_OPAQUE, "opaque"}, - {TOK_BOOL, "bool"}, - {TOK_VOID, "void"}, - {TOK_PROGRAM, "program"}, - {TOK_VERSION, "version"}, - {TOK_EOF, "??????"} + {TOK_IDENT, "identifier"}, + {TOK_CONST, "const"}, + {TOK_RPAREN, ")"}, + {TOK_LPAREN, "("}, + {TOK_RBRACE, "}"}, + {TOK_LBRACE, "{"}, + {TOK_LBRACKET, "["}, + {TOK_RBRACKET, "]"}, + {TOK_STAR, "*"}, + {TOK_COMMA, ","}, + {TOK_EQUAL, "="}, + {TOK_COLON, ":"}, + {TOK_SEMICOLON, ";"}, + {TOK_UNION, "union"}, + {TOK_STRUCT, "struct"}, + {TOK_SWITCH, "switch"}, + {TOK_CASE, "case"}, + {TOK_DEFAULT, "default"}, + {TOK_ENUM, "enum"}, + {TOK_TYPEDEF, "typedef"}, + {TOK_INT, "int"}, + {TOK_SHORT, "short"}, + {TOK_LONG, "long"}, + {TOK_UNSIGNED, "unsigned"}, + {TOK_DOUBLE, "double"}, + {TOK_FLOAT, "float"}, + {TOK_CHAR, "char"}, + {TOK_STRING, "string"}, + {TOK_OPAQUE, "opaque"}, + {TOK_BOOL, "bool"}, + {TOK_VOID, "void"}, + {TOK_PROGRAM, "program"}, + {TOK_VERSION, "version"}, + {TOK_EOF, "??????"} }; static char * @@ -391,8 +399,6 @@ toktostr(kind) return (sp->str); } - - static printbuf() { @@ -415,7 +421,6 @@ printbuf() } } - static printwhere() { @@ -437,3 +442,67 @@ printwhere() } (void) fputc('\n', stderr); } + +char * +make_argname(pname, vname) + char *pname; + char *vname; +{ + char *name; + + name = malloc(strlen(pname) + strlen(vname) + strlen(ARGEXT) + 3); + if (!name) { + fprintf(stderr, "failed in malloc"); + exit(1); + } + sprintf(name, "%s_%s_%s", locase(pname), vname, ARGEXT); + return (name); +} + +bas_type *typ_list_h; +bas_type *typ_list_t; + +add_type(len, type) +int len; +char *type; +{ + bas_type *ptr; + + if ((ptr = (bas_type *) malloc(sizeof (bas_type))) == + (bas_type *)NULL) { + fprintf(stderr, "failed in malloc"); + exit(1); + } + + ptr->name = type; + ptr->length = len; + ptr->next = NULL; + if (typ_list_t == NULL) + { + + typ_list_t = ptr; + typ_list_h = ptr; + } + else + { + typ_list_t->next = ptr; + typ_list_t = ptr; + }; +} + + +bas_type *find_type(type) +char *type; +{ + bas_type * ptr; + + ptr = typ_list_h; + while (ptr != NULL) + { + if (strcmp(ptr->name, type) == 0) + return (ptr); + else + ptr = ptr->next; + }; + return (NULL); +} |