rpc_cout.c revision a2f144d1eca25f33af1e19affd8eda208f547108
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* University Copyright- Copyright (c) 1982, 1986, 1988
* The Regents of the University of California
* All Rights Reserved
*
* University Acknowledgment- Portions of this document are derived from
* software developed by the University of California, Berkeley, and its
* contributors.
*/
/*
* rpc_cout.c, XDR routine outputter for the RPC protocol compiler
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "rpc_parse.h"
#include "rpc_util.h"
extern void crash(void);
static void print_header(definition *);
static void print_trailer(void);
static void emit_enum(definition *);
static void emit_program(definition *);
static void emit_union(definition *);
static void emit_struct(definition *);
static void emit_typedef(definition *);
static void print_stat(int, declaration *);
static void emit_inline(int, declaration *, int);
static void emit_inline64(int, declaration *, int);
static char *upcase(char *);
/*
* Emit the C-routine for the given definition
*/
void
{
return;
return;
}
/*
* now we need to handle declarations like
* struct typedef foo foo;
* since we dont want this to be expanded into 2 calls
* to xdr_foo
*/
return;
};
case DEF_UNION:
break;
case DEF_ENUM:
break;
case DEF_STRUCT:
break;
case DEF_TYPEDEF:
break;
}
}
static int
{
return (0);
}
static int
{
}
static void
{
if (Cflag) {
if (pointerp)
} else {
if (pointerp)
}
}
static void
{
/* Now add Inline support */
if (inlinelen == 0)
return;
/* May cause lint to complain. but ... */
}
static void
{
}
static void
print_trailer(void)
{
}
static void
{
}
static void
print_ifarg(char *arg)
{
}
static void
{
if (indent) {
} else {
}
} else {
}
}
}
static void
print_ifclose(int indent)
{
}
static void
{
switch (rel) {
case REL_POINTER:
print_ifarg("(char **)");
break;
case REL_VECTOR:
alt = "string";
alt = "opaque";
if (alt) {
} else {
print_ifarg("(char *)");
}
if (!alt)
break;
case REL_ARRAY:
alt = "string";
alt = "bytes";
} else {
if (alt)
else
print_ifarg("(char **)");
if (*objname == '&')
else
"&%s->%s_val, (u_int *) &%s->%s_len",
}
if (!alt)
break;
case REL_ALIAS:
break;
}
}
/* ARGSUSED */
static void
{
print_ifarg("(enum_t *)objp");
print_ifclose(1);
}
static void
{
continue; /* old style, or single argument */
}
}
static void
{
char *object;
continue;
strlen("&objp->%s_u.%s") +
else
}
}
strlen("&objp->%s_u.%s") +
else
}
} else {
}
}
static void
{
/*
* were already looking at a xdr_inlineable structure
*/
"buf = XDR_INLINE(xdrs, %d * BYTES_PER_XDR_UNIT);",
size);
else if (size == 0)
"buf = XDR_INLINE(xdrs, (%s) * BYTES_PER_XDR_UNIT);",
sizestr);
else
"buf = XDR_INLINE(xdrs, (%d + (%s)) "
}
}
}
}
/*
* An inline type is a base type (interger type) or a vector of base types.
*/
static int
{
*size = 0;
return (1);
}
}
return (0);
}
static char *
{
int len;
int digits;
int slen = 0;
char *plus = "";
char *tmp;
/*
* Calculate the size of a string to hold the size of all arrays
* to be inlined.
*
* We have the string representation of the total size that has already
* been seen. (Null if this is the first array).
* We have the string representation of array max from the declaration,
* optionally the plus string, " + ", if this is not the first array,
* and the number of digits for the element size for this declaration.
*/
plus = " + ";
}
/* Calculate the number of digits to hold the element size */
elsz /= 10;
/*
* If elsize != 1 the allocate 3 extra bytes for the times
* string, " * ", the "()" below, and the digits. One extra
* for the trailing NULL
*/
crash();
}
if (elsize == 1)
else
return (tmp);
}
static void
{
char *sizestr;
tsize = 0;
else {
/* this code is required to handle arrays */
}
} else {
/*
* don't expand into inline code
* if tsize < inlinelen
*/
}
} else {
}
tsize = 0;
}
}
return;
/* don't expand into inline code if tsize < inlinelen */
}
} else {
}
}
/*
* Check if we can inline this structure. While we are at it check if the
* declaration list has any vectors defined of "basic" types.
*/
static int
{
int tsize = 0;
int size;
int doinline = 0;
*have_vector = 0;
if (inlinelen == 0)
return (0);
tsize = 0;
continue;
}
*have_vector = 1;
return (1);
}
doinline = 1;
}
return (doinline);
}
static void
{
int indent = 3;
if (can_inline)
else
"&more_data))\n\t\t\t\treturn (FALSE);\n");
"(%s *)\n\t\t\t\t\tmem_alloc(sizeof (%s));\n",
if (can_inline)
else
"\t\t\t\treturn (FALSE);\n");
}
static void
{
int can_inline, have_vector;
if (have_vector)
/* Handle tail recursion elimination */
return;
}
if (can_inline) {
" else if (xdrs->x_op == XDR_DECODE) {\n");
}
/* now take care of XDR_FREE inline case or the non-inline cases */
}
static void
{
}
static void
{
char name[256];
else
}
static void
{
case REL_ALIAS :
break;
case REL_VECTOR :
}
}
static void
{
case REL_ALIAS :
break;
case REL_VECTOR :
}
}
static void
{
char *upp_case;
int freed = 0;
else
else
/* hack - XX */
freed = 1;
upp_case = "LONG";
}
freed = 1;
upp_case = "U_LONG";
}
else
else
if (!freed)
}
static void
{
char *upp_case;
int freed = 0;
else
else
/* hack - XX */
freed = 1;
upp_case = "INT32";
}
freed = 1;
upp_case = "U_INT32";
}
else
else
if (!freed)
}
static char *
{
exit(1);
};
while (*str != '\0')
*ptr = '\0';
return (hptr);
}