* 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
*/
/*
- * rpc_cout.c, XDR routine outputter for the RPC protocol compiler
- * Copyright (C) 1987, Sun Microsystems, Inc.
+ * rpc_cout.c, XDR routine outputter for the RPC protocol compiler
+ * Copyright (C) 1987, Sun Microsystems, Inc.
*/
#include <afsconfig.h>
#include <afs/param.h>
+#include <roken.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
#include "rpc_scan.h"
#include "rpc_parse.h"
#include "rpc_util.h"
static void print_trailer(void);
static void print_ifopen(int indent, char *name);
static void print_ifarg(char *arg);
+static void print_ifarg_with_cast(int ptr_to, char *type, char *arg);
static void print_ifsizeof(char *prefix, char *type);
static void print_ifclose(int indent);
static void space(void);
/*
- * Emit the C-routine for the given definition
+ * Emit the C-routine for the given definition
*/
void
emit(definition * def)
{
- if (def->def_kind == DEF_PROGRAM || def->def_kind == DEF_CONST) {
+ if (def->def_kind == DEF_CONST) {
return;
}
print_header(def);
static int
findtype(definition * def, char *type)
{
- if (def->def_kind == DEF_PROGRAM || def->def_kind == DEF_CONST) {
+ if (def->def_kind == DEF_CONST) {
return (0);
} else {
return (streq(def->def_name, type));
static void
+print_ifarg_with_cast(int ptr_to, char *type, char *arg)
+{
+ if (streq(type, "bool")) {
+ f_print(fout, ptr_to ? ", (bool_t *) %s" : ", (bool_t) %s", arg);
+ } else {
+ f_print(fout, ptr_to ? ", (%s *) %s" : ", (%s) %s", type, arg);
+ }
+}
+
+static void
print_ifsizeof(char *prefix, char *type)
{
if (streq(type, "bool")) {
}
static void
+print_ifarg_val(char *objname, char *name)
+{
+ if (*objname == '&') {
+ if (brief_flag) {
+ f_print(fout, "%s.val", objname);
+ } else {
+ f_print(fout, "%s.%s_val", objname, name);
+ }
+ } else {
+ if (brief_flag) {
+ f_print(fout, "&%s->val", objname);
+ } else {
+ f_print(fout, "&%s->%s_val", objname, name);
+ }
+ }
+}
+
+static void
+print_ifarg_len(char *objname, char *name)
+{
+ if (*objname == '&') {
+ if (brief_flag) {
+ f_print(fout, "(u_int *)%s.len", objname);
+ } else {
+ f_print(fout, "(u_int *)%s.%s_len", objname, name);
+ }
+ } else {
+ if (brief_flag) {
+ f_print(fout, "(u_int *)&%s->len", objname);
+ } else {
+ f_print(fout, "(u_int *)&%s->%s_len", objname, name);
+ }
+ }
+}
+
+static void
print_ifstat(int indent, char *prefix, char *type, relation rel, char *amax,
char *objname, char *name)
{
char *alt = NULL;
+ char *altcast = NULL;
switch (rel) {
case REL_POINTER:
print_ifopen(indent, "pointer");
- print_ifarg("(char **)");
- f_print(fout, "%s", objname);
+ print_ifarg_with_cast(1, "char *", objname);
print_ifsizeof(prefix, type);
break;
case REL_VECTOR:
alt = "string";
} else if (streq(type, "opaque")) {
alt = "opaque";
+ altcast = "caddr_t";
}
if (alt) {
print_ifopen(indent, alt);
- print_ifarg(objname);
+ if (altcast) {
+ print_ifarg_with_cast(0, altcast, objname);
+ } else {
+ print_ifarg(objname);
+ }
} else {
print_ifopen(indent, "vector");
- print_ifarg("(char *)");
- f_print(fout, "%s", objname);
+ print_ifarg_with_cast(1, "char", objname);
}
print_ifarg(amax);
if (!alt) {
alt = "string";
} else if (streq(type, "opaque")) {
alt = "bytes";
+ tabify(fout, indent);
+ f_print(fout, "{\n");
+ ++indent;
+ tabify(fout, indent);
+ f_print(fout, "u_int __len = (u_int) ");
+ f_print(fout, "*(");
+ print_ifarg_len(objname, name);
+ f_print(fout, ");\n");
}
if (streq(type, "string")) {
print_ifopen(indent, alt);
} else {
if (alt) {
print_ifopen(indent, alt);
+ print_ifarg("(char **)");
} else {
print_ifopen(indent, "array");
+ print_ifarg("(caddr_t *)");
}
- print_ifarg("(char **)");
- if (*objname == '&') {
- f_print(fout, "%s.%s_val, (u_int *)%s.%s_len", objname, name,
- objname, name);
+ print_ifarg_val(objname, name);
+ f_print(fout, ", ");
+ if (streq(type, "opaque")) {
+ f_print(fout, "&__len");
} else {
- f_print(fout, "&%s->%s_val, (u_int *)&%s->%s_len", objname,
- name, objname, name);
+ print_ifarg_len(objname, name);
}
}
print_ifarg(amax);
break;
}
print_ifclose(indent);
+ if (rel == REL_ARRAY && streq(type, "opaque")) {
+ tabify(fout, indent);
+ f_print(fout, "*(");
+ print_ifarg_len(objname, name);
+ f_print(fout, ")");
+ f_print(fout, " = __len;\n");
+ --indent;
+ tabify(fout, indent);
+ f_print(fout, "}\n");
+ }
+
}
declaration *cs;
char *object;
char *format = "&objp->%s_u.%s";
+ char *briefformat = "&objp->u.%s";
print_stat(&def->def.un.enum_decl);
f_print(fout, "\tswitch (objp->%s) {\n", def->def.un.enum_decl.name);
object =
alloc(strlen(def->def_name) + strlen(format) +
strlen(cs->name) + 1);
- s_print(object, format, def->def_name, cs->name);
+
+ if (brief_flag)
+ s_print(object, briefformat, cs->name);
+ else
+ s_print(object, format, def->def_name, cs->name);
+
print_ifstat(2, cs->prefix, cs->type, cs->rel, cs->array_max,
object, cs->name);
free(object);
switch (dec->rel) {
case REL_ARRAY:
f_print(fout, "struct %s {\n", dec->name);
- f_print(fout, "\tu_int %s_len;\n", dec->name);
- f_print(fout, "\t%s%s *%s_val;\n", prefix, dec->type, dec->name);
+ if (brief_flag) {
+ f_print(fout, "\tu_int %s_len;\n", dec->name);
+ f_print(fout, "\t%s%s *%s_val;\n", prefix,
+ dec->type, dec->name);
+ } else {
+ f_print(fout, "\tu_int %s_len;\n", dec->name);
+ f_print(fout, "\t%s%s *%s_val;\n", prefix,
+ dec->type, dec->name);
+ }
f_print(fout, "} %s", dec->name);
break;
default:
} else if (streq(type, "opaque")) {
alt = "opaque";
}
- if (alt) {
+ if (alt)
print_rxifopen(alt);
- print_rxifarg(amp, objname, 0);
- } else {
+ else
print_rxifopen("vector");
- print_rxifarg(amp, "(char *)", 0);
- sprintf(temp, "%s", objname);
- strcat(Proc_list->code, temp);
- strcat(Proc_list->scode, temp);
- }
+
+ print_rxifarg(amp, "(char *)", 0);
+ sprintf(temp, "%s", objname);
+ strcat(Proc_list->code, temp);
+ strcat(Proc_list->scode, temp);
print_rxifarg("", amax, 1);
if (!alt) {
print_rxifsizeof(prefix, type);
Proc_list->pl.param_flag |= OUT_STRING;
print_rxifarg("", objname, 0);
} else
- print_rxifarg("&", objname, 0);
+ print_rxifarg("(char **) &", objname, 0);
/* print_rxifarg(amp, objname, 0); */
print_rxifarg("", amax, 1);
if (!alt) {