/* $NetBSD: rpc_hout.c,v 1.25 2016/01/23 02:33:09 dholland Exp $ */
/*
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for
* unrestricted use provided that this legend is included on all tape
* media and as a part of the software program in whole or part. Users
* 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 or with the express written consent of
* Sun Microsystems, Inc.
*
* 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
*/
/*
* Print the C-version of an xdr definition
*/
void
print_datadef(definition *def)
{
if (def->def_kind == DEF_PROGRAM) /* handle data only */
return;
if (def->def_kind != DEF_CONST) {
f_print(fout, "\n");
}
switch (def->def_kind) {
case DEF_STRUCT:
pstructdef(def);
break;
case DEF_UNION:
puniondef(def);
break;
case DEF_ENUM:
penumdef(def);
break;
case DEF_TYPEDEF:
ptypedef(def);
break;
case DEF_PROGRAM:
pprogramdef(def);
break;
case DEF_CONST:
pconstdef(def);
break;
}
}
void
print_progdef(definition *def)
{
switch (def->def_kind) {
case DEF_PROGRAM:
f_print(fout, "\n");
pprogramdef(def);
break;
case DEF_CONST:
case DEF_TYPEDEF:
case DEF_ENUM:
case DEF_UNION:
case DEF_STRUCT:
break;
}
}
void
print_funcdef(definition *def, int *did)
{
switch (def->def_kind) {
case DEF_PROGRAM:
case DEF_CONST:
break;
case DEF_TYPEDEF:
case DEF_ENUM:
case DEF_UNION:
case DEF_STRUCT:
if (!*did) {
f_print(fout, "\n");
cplusplusstart();
*did = 1;
}
pxdrfuncdecl(def->def_name,
def->def_kind != DEF_TYPEDEF ||
!isvectordef(def->def.ty.old_type, def->def.ty.rel));
break;
}
}
void
print_funcend(int did) {
if (did) {
cplusplusend();
}
}
void
pxdrfuncdecl(const char *name, int pointerp)
{
/* print out the definitions for the arguments of functions in the
header file
*/
static void
pargdef(definition *def)
{
decl_list *l;
version_list *vers;
char *name;
proc_list *plist;
int did;
for (vers = def->def.pr.versions; vers != NULL; vers = vers->next) {
for (plist = vers->procs; plist != NULL; plist = plist->next) {
if (!newstyle || plist->arg_num < 2) {
continue; /* old style or single args */
}
name = plist->args.argname;
f_print(fout, "struct %s {\n", name);
for (l = plist->args.decls;
l != NULL; l = l->next) {
pdeclaration(name, &l->decl, 1, ";\n");
}
f_print(fout, "};\n");
f_print(fout, "typedef struct %s %s;\n", name, name);
}
}
did = 0;
for (vers = def->def.pr.versions; vers != NULL; vers = vers->next) {
for (plist = vers->procs; plist != NULL; plist = plist->next) {
if (!newstyle || plist->arg_num < 2) {
continue; /* old style or single args */
}
if (!did) {
cplusplusstart();
did = 1;
}
pxdrfuncdecl(plist->args.argname, 1);
}
}
if (did) {
cplusplusend();
}
puldefine(def->def_name, def->def.pr.prog_num);
for (vers = def->def.pr.versions; vers != NULL; vers = vers->next) {
if (tblflag) {
f_print(fout, "extern struct rpcgen_table %s_%s_table[];\n",
locase(def->def_name), vers->vers_num);
f_print(fout, "extern %s_%s_nproc;\n",
locase(def->def_name), vers->vers_num);
}
puldefine(vers->vers_name, vers->vers_num);
for (proc = vers->procs; proc != NULL; proc = proc->next) {
if (!define_printed(proc, def->def.pr.versions)) {
puldefine(proc->proc_name, proc->proc_num);
}
}
}
/*
* Print out 3 definitions, one for ANSI-C, another for C++, a
* third for old style C
*/
f_print(fout, "\n");
cplusplusstart();
for (vers = def->def.pr.versions; vers != NULL; vers = vers->next) {
for (proc = vers->procs; proc != NULL; proc = proc->next) {
pprocdef(proc, vers, "CLIENT *", 0);
pprocdef(proc, vers, "struct svc_req *", 1);
}
}
cplusplusend();
}