summaryrefslogtreecommitdiffstats
path: root/usr.bin/rpcgen/rpc_parse.c
diff options
context:
space:
mode:
authorwpaul <wpaul@FreeBSD.org>1995-12-13 03:31:10 +0000
committerwpaul <wpaul@FreeBSD.org>1995-12-13 03:31:10 +0000
commit15a1e09c3d41cb01afc70a2ea4d20c5a0d09348a (patch)
tree3547b9f6ff2d917f7e05d08348c8ae595e59f942 /usr.bin/rpcgen/rpc_parse.c
parent914aabf9597b86239a1773687af4db7b2cc37d12 (diff)
downloadFreeBSD-src-15a1e09c3d41cb01afc70a2ea4d20c5a0d09348a.zip
FreeBSD-src-15a1e09c3d41cb01afc70a2ea4d20c5a0d09348a.tar.gz
Clean up. (I hope I'm doing this right.)
Update rpcgen with the one from the TI-RPC 2.3 distribution. Note that when built for FreeBSD, this version of rpcgen assumes backwards compatibility mode by default. This means that it will produce ONCRPC 4.0 compatible code unless otherwise instructed, instead of the other way around. One incompatibility has also been worked around: this rpcgen normally always emits an '#include <stropts.h>' directive whether you select backwards compatibility mode or not. We don't have STREAMS, so this behavior has been changed: now it will only emit this line if run in TI-RPC mode. The 'generate output files in current directory instead of the directory where the protocol definition file lives' hack from the original rpcgen has been preserved. Notable new features: - Can be used to generate RPC servers that can be launched from port monitors such as inetd(5). - Can generate ANSI C code. - Can generate sample client and server top-level programs and makefiles in addition to the usual client and server stubs. - Can generate inline XDR routines.
Diffstat (limited to 'usr.bin/rpcgen/rpc_parse.c')
-rw-r--r--usr.bin/rpcgen/rpc_parse.c279
1 files changed, 255 insertions, 24 deletions
diff --git a/usr.bin/rpcgen/rpc_parse.c b/usr.bin/rpcgen/rpc_parse.c
index d042b58..fb8eec1 100644
--- a/usr.bin/rpcgen/rpc_parse.c
+++ b/usr.bin/rpcgen/rpc_parse.c
@@ -1,4 +1,3 @@
-/* @(#)rpc_parse.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,30 +5,32 @@
* 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_parse.c 1.12 93/07/05 SMI"
+
#ifndef lint
-/*static char sccsid[] = "from: @(#)rpc_parse.c 1.4 87/04/28 (C) 1987 SMI";*/
-static char rcsid[] = "$Id: rpc_parse.c,v 1.2 1995/05/15 00:03:32 ache Exp $";
+static char sccsid[] = "@(#)rpc_parse.c 1.8 89/02/22 (C) 1987 SMI";
#endif
/*
@@ -37,13 +38,31 @@ static char rcsid[] = "$Id: rpc_parse.c,v 1.2 1995/05/15 00:03:32 ache Exp $";
* Copyright (C) 1987 Sun Microsystems, Inc.
*/
#include <stdio.h>
-#include "rpc_util.h"
+#include <string.h>
+#include "rpc/types.h"
#include "rpc_scan.h"
#include "rpc_parse.h"
+#include "rpc_util.h"
+
+#define ARGNAME "arg"
+
+extern char *make_argname __P(( char *, char * ));
+static int isdefined __P(( definition * ));
+static int def_struct __P(( definition * ));
+static int def_program __P(( definition * ));
+static int def_enum __P(( definition * ));
+static int def_const __P(( definition * ));
+static int def_union __P(( definition * ));
+static int def_typedef __P(( definition * ));
+static int get_declaration __P(( declaration *, defkind ));
+static int get_prog_declaration __P(( declaration *, defkind, int ));
+static int get_type __P(( char **, char **, defkind ));
+static int unsigned_dec __P(( char ** ));
+
+#ifndef __FreeBSD__
+extern char *strdup();
+#endif
-static int isdefined(), def_struct(), def_program(), def_enum(), def_const(),
- def_union(), def_typedef(), get_declaration(), get_type(),
- unsigned_dec();
/*
* return the next definition you see
*/
@@ -76,7 +95,6 @@ get_definition()
break;
case TOK_EOF:
return (NULL);
- break;
default:
error("definition keyword expected");
}
@@ -92,7 +110,6 @@ isdefined(defp)
STOREVAL(&defined, defp);
}
-
static
def_struct(defp)
definition *defp;
@@ -126,16 +143,21 @@ def_program(defp)
definition *defp;
{
token tok;
+ declaration dec;
+ decl_list *decls;
+ decl_list **tailp;
version_list *vlist;
version_list **vtailp;
proc_list *plist;
proc_list **ptailp;
-
+ int num_args;
+ bool_t isvoid = FALSE; /* whether first argument is void */
defp->def_kind = DEF_PROGRAM;
scan(TOK_IDENT, &tok);
defp->def_name = tok.str;
scan(TOK_LBRACE, &tok);
vtailp = &defp->def.pr.versions;
+ tailp = &defp->def.st.decls;
scan(TOK_VERSION, &tok);
do {
scan(TOK_IDENT, &tok);
@@ -144,23 +166,57 @@ def_program(defp)
scan(TOK_LBRACE, &tok);
ptailp = &vlist->procs;
do {
+ /* get result type */
plist = ALLOC(proc_list);
- get_type(&plist->res_prefix, &plist->res_type, DEF_PROGRAM);
+ get_type(&plist->res_prefix, &plist->res_type,
+ DEF_PROGRAM);
if (streq(plist->res_type, "opaque")) {
error("illegal result type");
}
scan(TOK_IDENT, &tok);
plist->proc_name = tok.str;
scan(TOK_LPAREN, &tok);
- get_type(&plist->arg_prefix, &plist->arg_type, DEF_PROGRAM);
- if (streq(plist->arg_type, "opaque")) {
- error("illegal argument type");
+ /* get args - first one */
+ num_args = 1;
+ isvoid = FALSE;
+ /*
+ * type of DEF_PROGRAM in the first
+ * get_prog_declaration and DEF_STURCT in the next
+ * allows void as argument if it is the only argument
+ */
+ get_prog_declaration(&dec, DEF_PROGRAM, num_args);
+ if (streq(dec.type, "void"))
+ isvoid = TRUE;
+ decls = ALLOC(decl_list);
+ plist->args.decls = decls;
+ decls->decl = dec;
+ tailp = &decls->next;
+ /* get args */
+ while (peekscan(TOK_COMMA, &tok)) {
+ num_args++;
+ get_prog_declaration(&dec, DEF_STRUCT,
+ num_args);
+ decls = ALLOC(decl_list);
+ decls->decl = dec;
+ *tailp = decls;
+ if (streq(dec.type, "void"))
+ isvoid = TRUE;
+ tailp = &decls->next;
+ }
+ /* multiple arguments are only allowed in newstyle */
+ if (!newstyle && num_args > 1) {
+ error("only one argument is allowed");
+ }
+ if (isvoid && num_args > 1) {
+ error("illegal use of void in program definition");
}
+ *tailp = NULL;
scan(TOK_RPAREN, &tok);
scan(TOK_EQUAL, &tok);
scan_num(&tok);
scan(TOK_SEMICOLON, &tok);
plist->proc_num = tok.str;
+ plist->arg_num = num_args;
*ptailp = plist;
ptailp = &plist->next;
peek(&tok);
@@ -172,6 +228,13 @@ def_program(defp)
scan(TOK_EQUAL, &tok);
scan_num(&tok);
vlist->vers_num = tok.str;
+ /* make the argument structure name for each arg */
+ for (plist = vlist->procs; plist != NULL;
+ plist = plist->next) {
+ plist->args.argname = make_argname(plist->proc_name,
+ vlist->vers_num);
+ /* free the memory ?? */
+ }
scan(TOK_SEMICOLON, &tok);
scan2(TOK_VERSION, TOK_RBRACE, &tok);
} while (tok.kind == TOK_VERSION);
@@ -181,6 +244,7 @@ def_program(defp)
*vtailp = NULL;
}
+
static
def_enum(defp)
definition *defp;
@@ -231,8 +295,9 @@ def_union(defp)
{
token tok;
declaration dec;
- case_list *cases;
+ case_list *cases, *tcase;
case_list **tailp;
+ int flag;
defp->def_kind = DEF_UNION;
scan(TOK_IDENT, &tok);
@@ -246,15 +311,40 @@ def_union(defp)
scan(TOK_LBRACE, &tok);
scan(TOK_CASE, &tok);
while (tok.kind == TOK_CASE) {
- scan(TOK_IDENT, &tok);
+ scan2(TOK_IDENT, TOK_CHARCONST, &tok);
cases = ALLOC(case_list);
cases->case_name = tok.str;
scan(TOK_COLON, &tok);
+ /* now peek at next token */
+ flag = 0;
+ if (peekscan(TOK_CASE, &tok)){
+ do {
+ scan2(TOK_IDENT, TOK_CHARCONST, &tok);
+ cases->contflag = 1;
+ /* continued case statement */
+ *tailp = cases;
+ tailp = &cases->next;
+ cases = ALLOC(case_list);
+ cases->case_name = tok.str;
+ scan(TOK_COLON, &tok);
+ } while (peekscan(TOK_CASE, &tok));
+ }
+ else
+ if (flag)
+ {
+
+ *tailp = cases;
+ tailp = &cases->next;
+ cases = ALLOC(case_list);
+ };
+
get_declaration(&dec, DEF_UNION);
cases->case_decl = dec;
+ cases->contflag = 0; /* no continued case statement */
*tailp = cases;
tailp = &cases->next;
scan(TOK_SEMICOLON, &tok);
+
scan3(TOK_CASE, TOK_DEFAULT, TOK_RBRACE, &tok);
}
*tailp = NULL;
@@ -270,6 +360,62 @@ def_union(defp)
}
}
+static char* reserved_words[] =
+{
+ "array",
+ "bytes",
+ "destroy",
+ "free",
+ "getpos",
+ "inline",
+ "pointer",
+ "reference",
+ "setpos",
+ "sizeof",
+ "union",
+ "vector",
+ NULL
+ };
+
+static char* reserved_types[] =
+{
+ "opaque",
+ "string",
+ NULL
+ };
+
+/*
+ * check that the given name is not one that would eventually result in
+ * xdr routines that would conflict with internal XDR routines.
+ */
+static check_type_name(name, new_type)
+int new_type;
+char* name;
+{
+ int i;
+ char tmp[100];
+
+ for (i = 0; reserved_words[i] != NULL; i++) {
+ if (strcmp(name, reserved_words[i]) == 0) {
+ sprintf(tmp,
+ "illegal (reserved) name :\'%s\' in type definition",
+ name);
+ error(tmp);
+ }
+ }
+ if (new_type) {
+ for (i = 0; reserved_types[i] != NULL; i++) {
+ if (strcmp(name, reserved_types[i]) == 0) {
+ sprintf(tmp,
+ "illegal (reserved) name :\'%s\' in type definition",
+ name);
+ error(tmp);
+ }
+ }
+ }
+}
+
+
static
def_typedef(defp)
@@ -280,13 +426,13 @@ def_typedef(defp)
defp->def_kind = DEF_TYPEDEF;
get_declaration(&dec, DEF_TYPEDEF);
defp->def_name = dec.name;
+ check_type_name(dec.name, 1);
defp->def.ty.old_prefix = dec.prefix;
defp->def.ty.old_type = dec.type;
defp->def.ty.rel = dec.rel;
defp->def.ty.array_max = dec.array_max;
}
-
static
get_declaration(dec, dkind)
declaration *dec;
@@ -299,6 +445,8 @@ get_declaration(dec, dkind)
if (streq(dec->type, "void")) {
return;
}
+
+ check_type_name(dec->type, 0);
scan2(TOK_STAR, TOK_IDENT, &tok);
if (tok.kind == TOK_STAR) {
dec->rel = REL_POINTER;
@@ -339,6 +487,79 @@ get_declaration(dec, dkind)
static
+get_prog_declaration(dec, dkind, num)
+ declaration *dec;
+ defkind dkind;
+ int num; /* arg number */
+{
+ token tok;
+ char name[10]; /* argument name */
+
+ if (dkind == DEF_PROGRAM) {
+ peek(&tok);
+ if (tok.kind == TOK_RPAREN) { /* no arguments */
+ dec->rel = REL_ALIAS;
+ dec->type = "void";
+ dec->prefix = NULL;
+ dec->name = NULL;
+ return;
+ }
+ }
+ get_type(&dec->prefix, &dec->type, dkind);
+ dec->rel = REL_ALIAS;
+ if (peekscan(TOK_IDENT, &tok)) /* optional name of argument */
+ strcpy(name, tok.str);
+ else
+ sprintf(name, "%s%d", ARGNAME, num);
+ /* default name of argument */
+
+ dec->name = (char *) strdup(name);
+ if (streq(dec->type, "void")) {
+ return;
+ }
+
+ if (streq(dec->type, "opaque")) {
+ error("opaque -- illegal argument type");
+ }
+ if (peekscan(TOK_STAR, &tok)) {
+ if (streq(dec->type, "string")) {
+ error("pointer to string not allowed in program arguments\n");
+ }
+ dec->rel = REL_POINTER;
+ if (peekscan(TOK_IDENT, &tok))
+ /* optional name of argument */
+ dec->name = strdup(tok.str);
+ }
+ if (peekscan(TOK_LANGLE, &tok)) {
+ if (!streq(dec->type, "string")) {
+ error("arrays cannot be declared as arguments to procedures -- use typedef");
+ }
+ dec->rel = REL_ARRAY;
+ if (peekscan(TOK_RANGLE, &tok)) {
+ dec->array_max = "~0";
+ /* unspecified size, use max */
+ } else {
+ scan_num(&tok);
+ dec->array_max = tok.str;
+ scan(TOK_RANGLE, &tok);
+ }
+ }
+ if (streq(dec->type, "string")) {
+ if (dec->rel != REL_ARRAY) {
+ /*
+ * .x specifies just string as
+ * type of argument
+ * - make it string<>
+ */
+ dec->rel = REL_ARRAY;
+ dec->array_max = "~0"; /* unspecified size, use max */
+ }
+ }
+}
+
+
+
+static
get_type(prefixp, typep, dkind)
char **prefixp;
char **typep;
@@ -370,9 +591,14 @@ get_type(prefixp, typep, dkind)
*typep = "long";
(void) peekscan(TOK_INT, &tok);
break;
+ case TOK_HYPER:
+ *typep = "longlong_t";
+ (void) peekscan(TOK_INT, &tok);
+ break;
+
case TOK_VOID:
if (dkind != DEF_UNION && dkind != DEF_PROGRAM) {
- error("voids allowed only inside union and program definitions");
+ error("voids allowed only inside union and program definitions with one argument");
}
*typep = tok.str;
break;
@@ -383,6 +609,7 @@ get_type(prefixp, typep, dkind)
case TOK_FLOAT:
case TOK_DOUBLE:
case TOK_BOOL:
+ case TOK_QUAD:
*typep = tok.str;
break;
default:
@@ -390,7 +617,6 @@ get_type(prefixp, typep, dkind)
}
}
-
static
unsigned_dec(typep)
char **typep;
@@ -413,6 +639,11 @@ unsigned_dec(typep)
*typep = "u_long";
(void) peekscan(TOK_INT, &tok);
break;
+ case TOK_HYPER:
+ get_token(&tok);
+ *typep = "ulonglong_t";
+ (void) peekscan(TOK_INT, &tok);
+ break;
case TOK_INT:
get_token(&tok);
*typep = "u_int";
OpenPOWER on IntegriCloud