=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/rpcgen/rpc_cout.c,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- src/usr.bin/rpcgen/rpc_cout.c 2001/11/24 19:17:47 1.8 +++ src/usr.bin/rpcgen/rpc_cout.c 2001/11/24 19:19:59 1.9 @@ -1,4 +1,4 @@ -/* $OpenBSD: rpc_cout.c,v 1.8 2001/11/24 19:17:47 deraadt Exp $ */ +/* $OpenBSD: rpc_cout.c,v 1.9 2001/11/24 19:19:59 deraadt Exp $ */ /* $NetBSD: rpc_cout.c,v 1.6 1996/10/01 04:13:53 cgd Exp $ */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for @@ -41,31 +41,29 @@ #include #include #include -#include #include "rpc_parse.h" #include "rpc_util.h" -static int findtype __P((definition *, char *)); -static int undefined __P((char *)); -static void print_generic_header __P((char *, int)); -static void print_header __P((definition *)); -static void print_prog_header __P((proc_list *)); -static void print_trailer __P((void)); -static void print_ifopen __P((int, char *)); -static void print_ifarg __P((char *)); -static void print_ifsizeof __P((char *, char *)); -static void print_ifclose __P((int)); -static void print_ifstat __P((int, char *, char *, relation, char *, char *, char *)); -static void emit_num __P((definition *)); -static void emit_program __P((definition *)); -static void emit_enum __P((definition *)); -static void emit_union __P((definition *)); -static void emit_struct __P((definition *)); -static void emit_typedef __P((definition *)); -static void print_stat __P((int, declaration *)); -void emit_inline __P((declaration *, int)); -void emit_single_in_line __P((declaration *, int, relation)); +static findtype __P((definition *, char *)); +static undefined __P((char *)); +static print_generic_header __P((char *, int)); +static print_header __P((definition *)); +static print_prog_header __P((proc_list *)); +static print_trailer __P((void)); +static print_ifopen __P((int, char *)); +static print_ifarg __P((char *)); +static print_ifsizeof __P((char *, char *)); +static print_ifclose __P((int)); +static print_ifstat __P((int, char *, char *, relation, char *, char *, char *)); +static emit_num __P((definition *)); +static emit_program __P((definition *)); +static emit_enum __P((definition *)); +static emit_union __P((definition *)); +static emit_struct __P((definition *)); +static emit_typedef __P((definition *)); +static print_stat __P((int, declaration *)); + /* * Emit the C-routine for the given definition */ @@ -107,10 +105,10 @@ print_trailer(); } -static int +static findtype(def, type) definition *def; - char *type; + char *type; { if (def->def_kind == DEF_PROGRAM || def->def_kind == DEF_CONST) { @@ -120,20 +118,22 @@ } } -static int +static undefined(type) - char *type; + char *type; { definition *def; def = (definition *) FINDVAL(defined, type, findtype); + + return (def == NULL); } -static void +static print_generic_header(procname, pointerp) - char *procname; - int pointerp; + char *procname; + int pointerp; { f_print(fout, "\n"); f_print(fout, "bool_t\n"); @@ -154,37 +154,46 @@ } } -static void +static print_header(def) definition *def; { + + decl_list *dl; + bas_type *ptr; + int i; + + print_generic_header(def->def_name, def->def_kind != DEF_TYPEDEF || !isvectordef(def->def.ty.old_type, def->def.ty.rel)); /* Now add Inline support */ + if (doinline == 0) return; /* May cause lint to complain. but ... */ f_print(fout, "\tint32_t *buf;\n\n"); + } -static void +static print_prog_header(plist) proc_list *plist; { print_generic_header(plist->args.argname, 1); } -static void +static print_trailer() { f_print(fout, "\treturn (TRUE);\n"); f_print(fout, "}\n"); } -static void + +static print_ifopen(indent, name) int indent; char *name; @@ -193,14 +202,14 @@ f_print(fout, "if (!xdr_%s(xdrs", name); } -static void +static print_ifarg(arg) char *arg; { f_print(fout, ", %s", arg); } -static void +static print_ifsizeof(prefix, type) char *prefix; char *type; @@ -216,7 +225,7 @@ } } -static void +static print_ifclose(indent) int indent; { @@ -227,7 +236,7 @@ f_print(fout, "}\n"); } -static void +static print_ifstat(indent, prefix, type, rel, amax, objname, name) int indent; char *prefix; @@ -305,7 +314,7 @@ } /* ARGSUSED */ -static void +static emit_enum(def) definition *def; { @@ -314,7 +323,7 @@ print_ifclose(1); } -static void +static emit_program(def) definition *def; { @@ -335,7 +344,8 @@ } } -static void + +static emit_union(def) definition *def; { @@ -349,6 +359,7 @@ print_stat(1, &def->def.un.enum_decl); f_print(fout, "\tswitch (objp->%s) {\n", def->def.un.enum_decl.name); for (cl = def->def.un.cases; cl != NULL; cl = cl->next) { + f_print(fout, "\tcase %s:\n", cl->case_name); if (cl->contflag == 1) /* a continued case statement */ continue; @@ -396,7 +407,7 @@ f_print(fout, "\t}\n"); } -static void +static emit_struct(def) definition *def; { @@ -408,6 +419,7 @@ char ptemp[256]; int can_inline; + if (doinline == 0) { for (dl = def->def.st.decls; dl != NULL; dl = dl->next) print_stat(1, &dl->decl); @@ -424,6 +436,7 @@ if ((dl->decl.prefix == NULL) && ((ptr = find_type(dl->decl.type)) != NULL) && ((dl->decl.rel == REL_ALIAS) || (dl->decl.rel == REL_VECTOR))) { + if (dl->decl.rel == REL_ALIAS) size += ptr->length; else { @@ -446,13 +459,18 @@ return; } + + + flag = PUT; for (j = 0; j < 2; j++) { + if (flag == PUT) f_print(fout, "\n\tif (xdrs->x_op == XDR_ENCODE) {\n"); else f_print(fout, "\t\treturn (TRUE);\n\t} else if (xdrs->x_op == XDR_DECODE) {\n"); + i = 0; size = 0; sizestr = NULL; @@ -485,6 +503,7 @@ else { sizestr = (char *)realloc(sizestr, strlen(sizestr) + strlen(ptemp) + 1); if (sizestr == NULL) { + f_print(stderr, "Fatal error : no memory\n"); crash(); } @@ -495,7 +514,7 @@ } } else { - if (i > 0) { + if (i > 0) if (sizestr == NULL && size < doinline) { /* don't expand into inline * code if size < doinline */ @@ -504,6 +523,9 @@ cur = cur->next; } } else { + + + /* were already looking at a * xdr_inlineable structure */ if (sizestr == NULL) @@ -537,7 +559,6 @@ f_print(fout, "\t\t}\n"); } - } size = 0; i = 0; sizestr = NULL; @@ -545,7 +566,7 @@ } } - if (i > 0) { + if (i > 0) if (sizestr == NULL && size < doinline) { /* don't expand into inline code if size < * doinline */ @@ -554,6 +575,7 @@ cur = cur->next; } } else { + /* were already looking at a xdr_inlineable * structure */ if (sizestr == NULL) @@ -588,7 +610,6 @@ } flag = GET; - } } f_print(fout, "\t\treturn (TRUE);\n\t}\n\n"); @@ -598,7 +619,7 @@ print_stat(1, &dl->decl); } -static void +static emit_typedef(def) definition *def; { @@ -607,10 +628,11 @@ char *amax = def->def.ty.array_max; relation rel = def->def.ty.rel; + print_ifstat(1, prefix, type, rel, amax, "objp", def->def_name); } -static void +static print_stat(indent, dec) declaration *dec; int indent; @@ -629,15 +651,17 @@ print_ifstat(indent, prefix, type, rel, amax, name, dec->name); } + char *upcase __P((char *)); -void + emit_inline(decl, flag) declaration *decl; int flag; { - /*check whether an array or not */ +/*check whether an array or not */ + switch (decl->rel) { case REL_ALIAS: f_print(fout, "\t"); @@ -653,7 +677,6 @@ } } -void emit_single_in_line(decl, flag, rel) declaration *decl; int flag; @@ -662,6 +685,8 @@ char *upp_case; int freed = 0; + + if (flag == PUT) f_print(fout, "\t\tIXDR_PUT_"); else @@ -693,14 +718,17 @@ f_print(fout, "%s(buf);\n", upp_case); if (!freed) free(upp_case); + } + char * upcase(str) char *str; { char *ptr, *hptr; + ptr = (char *) malloc(strlen(str)+1); if (ptr == (char *) NULL) { f_print(stderr, "malloc failed\n"); @@ -713,4 +741,5 @@ *ptr = '\0'; return (hptr); + }