1994-08-07 18:01:39 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
2002-07-21 12:55:04 +00:00
|
|
|
*
|
1994-08-07 18:01:39 +00:00
|
|
|
* 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.
|
2002-07-21 12:55:04 +00:00
|
|
|
*
|
1994-08-07 18:01:39 +00:00
|
|
|
* 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.
|
2002-07-21 12:55:04 +00:00
|
|
|
*
|
1994-08-07 18:01:39 +00:00
|
|
|
* 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.
|
2002-07-21 12:55:04 +00:00
|
|
|
*
|
1994-08-07 18:01:39 +00:00
|
|
|
* 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.
|
2002-07-21 12:55:04 +00:00
|
|
|
*
|
1994-08-07 18:01:39 +00:00
|
|
|
* Sun Microsystems, Inc.
|
|
|
|
* 2550 Garcia Avenue
|
|
|
|
* Mountain View, California 94043
|
|
|
|
*/
|
1995-12-13 03:31:10 +00:00
|
|
|
|
2002-07-14 17:54:00 +00:00
|
|
|
#if 0
|
2002-07-21 12:55:04 +00:00
|
|
|
#ifndef lint
|
2005-05-31 20:00:29 +00:00
|
|
|
#ident "@(#)rpc_hout.c 1.16 94/04/25 SMI"
|
1995-12-13 03:31:10 +00:00
|
|
|
static char sccsid[] = "@(#)rpc_hout.c 1.12 89/02/22 (C) 1987 SMI";
|
1994-08-07 18:01:39 +00:00
|
|
|
#endif
|
2002-07-14 17:54:00 +00:00
|
|
|
#endif
|
1994-08-07 18:01:39 +00:00
|
|
|
|
2002-07-21 12:55:04 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1994-08-07 18:01:39 +00:00
|
|
|
/*
|
1995-05-30 06:41:30 +00:00
|
|
|
* rpc_hout.c, Header file outputter for the RPC protocol compiler
|
|
|
|
* Copyright (C) 1987, Sun Microsystems, Inc.
|
1994-08-07 18:01:39 +00:00
|
|
|
*/
|
|
|
|
#include <stdio.h>
|
2009-12-13 03:14:06 +00:00
|
|
|
#include <ctype.h>
|
1994-08-07 18:01:39 +00:00
|
|
|
#include "rpc_parse.h"
|
2005-08-31 20:45:15 +00:00
|
|
|
#include "rpc_scan.h"
|
1995-12-13 03:31:10 +00:00
|
|
|
#include "rpc_util.h"
|
|
|
|
|
2005-11-13 21:17:24 +00:00
|
|
|
void storexdrfuncdecl(const char *, int );
|
2002-03-22 01:33:25 +00:00
|
|
|
static void pconstdef( definition * );
|
|
|
|
static void pstructdef( definition * );
|
|
|
|
static void puniondef( definition * );
|
2005-09-01 19:16:25 +00:00
|
|
|
static void pprogramdef( definition *, int );
|
2002-03-22 01:33:25 +00:00
|
|
|
static void penumdef( definition * );
|
|
|
|
static void ptypedef( definition * );
|
2005-11-13 21:17:24 +00:00
|
|
|
static void pdefine(const char *, const char *);
|
|
|
|
static int undefined2(const char *, const char *);
|
|
|
|
static void parglist(proc_list *, const char *);
|
|
|
|
static void pprocdef(proc_list *, version_list *, const char *, int);
|
1995-12-13 03:31:10 +00:00
|
|
|
|
1994-08-07 18:01:39 +00:00
|
|
|
/*
|
1995-05-30 06:41:30 +00:00
|
|
|
* Print the C-version of an xdr definition
|
1994-08-07 18:01:39 +00:00
|
|
|
*/
|
|
|
|
void
|
2005-09-01 19:16:25 +00:00
|
|
|
print_datadef(definition *def, int headeronly)
|
1994-08-07 18:01:39 +00:00
|
|
|
{
|
1995-12-13 03:31:10 +00:00
|
|
|
|
|
|
|
if (def->def_kind == DEF_PROGRAM) /* handle data only */
|
|
|
|
return;
|
|
|
|
|
1994-08-07 18:01:39 +00:00
|
|
|
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:
|
2005-09-01 19:16:25 +00:00
|
|
|
pprogramdef(def, headeronly);
|
1994-08-07 18:01:39 +00:00
|
|
|
break;
|
|
|
|
case DEF_CONST:
|
|
|
|
pconstdef(def);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (def->def_kind != DEF_PROGRAM && def->def_kind != DEF_CONST) {
|
1995-12-13 03:31:10 +00:00
|
|
|
storexdrfuncdecl(def->def_name,
|
|
|
|
def->def_kind != DEF_TYPEDEF ||
|
|
|
|
!isvectordef(def->def.ty.old_type,
|
|
|
|
def->def.ty.rel));
|
1994-08-07 18:01:39 +00:00
|
|
|
}
|
1995-12-13 03:31:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2005-09-01 19:16:25 +00:00
|
|
|
print_funcdef(definition *def, int headeronly)
|
1995-12-13 03:31:10 +00:00
|
|
|
{
|
|
|
|
switch (def->def_kind) {
|
|
|
|
case DEF_PROGRAM:
|
1994-08-07 18:01:39 +00:00
|
|
|
f_print(fout, "\n");
|
2005-09-01 19:16:25 +00:00
|
|
|
pprogramdef(def, headeronly);
|
1995-12-13 03:31:10 +00:00
|
|
|
break;
|
1996-07-12 19:08:36 +00:00
|
|
|
default:
|
2002-07-14 17:54:00 +00:00
|
|
|
break;
|
1996-07-12 19:08:36 +00:00
|
|
|
}
|
1995-12-13 03:31:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* store away enough information to allow the XDR functions to be spat
|
|
|
|
out at the end of the file */
|
|
|
|
|
|
|
|
void
|
2005-11-13 21:17:24 +00:00
|
|
|
storexdrfuncdecl(const char *name, int pointerp)
|
1995-12-13 03:31:10 +00:00
|
|
|
{
|
|
|
|
xdrfunc * xdrptr;
|
|
|
|
|
2002-07-21 12:55:04 +00:00
|
|
|
xdrptr = XALLOC(struct xdrfunc);
|
1995-12-13 03:31:10 +00:00
|
|
|
|
|
|
|
xdrptr->name = name;
|
|
|
|
xdrptr->pointerp = pointerp;
|
|
|
|
xdrptr->next = NULL;
|
|
|
|
|
|
|
|
if (xdrfunc_tail == NULL){
|
|
|
|
xdrfunc_head = xdrptr;
|
|
|
|
xdrfunc_tail = xdrptr;
|
|
|
|
} else {
|
|
|
|
xdrfunc_tail->next = xdrptr;
|
|
|
|
xdrfunc_tail = xdrptr;
|
1994-08-07 18:01:39 +00:00
|
|
|
}
|
1995-12-13 03:31:10 +00:00
|
|
|
|
|
|
|
|
1994-08-07 18:01:39 +00:00
|
|
|
}
|
|
|
|
|
1995-12-13 03:31:10 +00:00
|
|
|
void
|
2005-11-13 21:17:24 +00:00
|
|
|
print_xdr_func_def(const char *name, int pointerp)
|
1995-12-13 03:31:10 +00:00
|
|
|
{
|
2005-09-02 10:23:26 +00:00
|
|
|
f_print(fout, "extern bool_t xdr_%s(XDR *, %s%s);\n", name,
|
|
|
|
name, pointerp ? "*" : "");
|
1995-12-13 03:31:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-07-12 19:08:36 +00:00
|
|
|
static void
|
2010-01-02 10:09:20 +00:00
|
|
|
pconstdef(definition *def)
|
1994-08-07 18:01:39 +00:00
|
|
|
{
|
|
|
|
pdefine(def->def_name, def->def.co);
|
|
|
|
}
|
|
|
|
|
1995-12-13 03:31:10 +00:00
|
|
|
/* print out the definitions for the arguments of functions in the
|
|
|
|
header file
|
|
|
|
*/
|
1996-07-12 19:08:36 +00:00
|
|
|
static void
|
2005-11-13 21:17:24 +00:00
|
|
|
pargdef(definition *def)
|
1995-12-13 03:31:10 +00:00
|
|
|
{
|
|
|
|
decl_list *l;
|
|
|
|
version_list *vers;
|
|
|
|
char *name;
|
|
|
|
proc_list *plist;
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
storexdrfuncdecl(name, 1);
|
|
|
|
f_print(fout, "\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-07-12 19:08:36 +00:00
|
|
|
static void
|
2005-11-13 21:17:24 +00:00
|
|
|
pstructdef(definition *def)
|
1994-08-07 18:01:39 +00:00
|
|
|
{
|
|
|
|
decl_list *l;
|
2005-11-13 21:17:24 +00:00
|
|
|
const char *name = def->def_name;
|
1994-08-07 18:01:39 +00:00
|
|
|
|
|
|
|
f_print(fout, "struct %s {\n", name);
|
|
|
|
for (l = def->def.st.decls; l != NULL; l = l->next) {
|
1995-12-13 03:31:10 +00:00
|
|
|
pdeclaration(name, &l->decl, 1, ";\n");
|
1994-08-07 18:01:39 +00:00
|
|
|
}
|
|
|
|
f_print(fout, "};\n");
|
|
|
|
f_print(fout, "typedef struct %s %s;\n", name, name);
|
|
|
|
}
|
|
|
|
|
1996-07-12 19:08:36 +00:00
|
|
|
static void
|
2010-01-02 10:09:20 +00:00
|
|
|
puniondef(definition *def)
|
1994-08-07 18:01:39 +00:00
|
|
|
{
|
|
|
|
case_list *l;
|
2005-11-13 21:17:24 +00:00
|
|
|
const char *name = def->def_name;
|
1994-08-07 18:01:39 +00:00
|
|
|
declaration *decl;
|
|
|
|
|
|
|
|
f_print(fout, "struct %s {\n", name);
|
|
|
|
decl = &def->def.un.enum_decl;
|
|
|
|
if (streq(decl->type, "bool")) {
|
|
|
|
f_print(fout, "\tbool_t %s;\n", decl->name);
|
|
|
|
} else {
|
|
|
|
f_print(fout, "\t%s %s;\n", decl->type, decl->name);
|
|
|
|
}
|
|
|
|
f_print(fout, "\tunion {\n");
|
|
|
|
for (l = def->def.un.cases; l != NULL; l = l->next) {
|
1995-12-13 03:31:10 +00:00
|
|
|
if (l->contflag == 0)
|
|
|
|
pdeclaration(name, &l->case_decl, 2, ";\n");
|
1994-08-07 18:01:39 +00:00
|
|
|
}
|
|
|
|
decl = def->def.un.default_decl;
|
|
|
|
if (decl && !streq(decl->type, "void")) {
|
1995-12-13 03:31:10 +00:00
|
|
|
pdeclaration(name, decl, 2, ";\n");
|
1994-08-07 18:01:39 +00:00
|
|
|
}
|
|
|
|
f_print(fout, "\t} %s_u;\n", name);
|
|
|
|
f_print(fout, "};\n");
|
|
|
|
f_print(fout, "typedef struct %s %s;\n", name, name);
|
|
|
|
}
|
|
|
|
|
1996-07-12 19:08:36 +00:00
|
|
|
static void
|
2005-11-13 21:17:24 +00:00
|
|
|
pdefine(const char *name, const char *num)
|
1994-08-07 18:01:39 +00:00
|
|
|
{
|
1995-12-13 03:31:10 +00:00
|
|
|
f_print(fout, "#define\t%s %s\n", name, num);
|
1994-08-07 18:01:39 +00:00
|
|
|
}
|
|
|
|
|
1996-07-12 19:08:36 +00:00
|
|
|
static void
|
2005-11-13 21:17:24 +00:00
|
|
|
puldefine(const char *name, const char *num)
|
1994-08-07 18:01:39 +00:00
|
|
|
{
|
1995-12-13 03:31:10 +00:00
|
|
|
f_print(fout, "#define\t%s ((unsigned long)(%s))\n", name, num);
|
1994-08-07 18:01:39 +00:00
|
|
|
}
|
|
|
|
|
1996-07-12 19:08:36 +00:00
|
|
|
static int
|
2005-11-13 21:17:24 +00:00
|
|
|
define_printed(proc_list *stop, version_list *start)
|
1994-08-07 18:01:39 +00:00
|
|
|
{
|
|
|
|
version_list *vers;
|
|
|
|
proc_list *proc;
|
|
|
|
|
|
|
|
for (vers = start; vers != NULL; vers = vers->next) {
|
|
|
|
for (proc = vers->procs; proc != NULL; proc = proc->next) {
|
|
|
|
if (proc == stop) {
|
|
|
|
return (0);
|
|
|
|
} else if (streq(proc->proc_name, stop->proc_name)) {
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
abort();
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
|
1996-07-12 19:08:36 +00:00
|
|
|
static void
|
2005-11-13 21:17:24 +00:00
|
|
|
pfreeprocdef(const char * name, const char *vers)
|
1995-12-13 03:31:10 +00:00
|
|
|
{
|
|
|
|
f_print(fout, "extern int ");
|
|
|
|
pvname(name, vers);
|
2005-09-02 10:23:26 +00:00
|
|
|
f_print(fout, "_freeresult(SVCXPRT *, xdrproc_t, caddr_t);\n");
|
1995-12-13 03:31:10 +00:00
|
|
|
}
|
1994-08-07 18:01:39 +00:00
|
|
|
|
2001-11-13 11:08:29 +00:00
|
|
|
static void
|
2005-11-13 21:17:24 +00:00
|
|
|
pdispatch(const char * name, const char *vers)
|
2001-11-13 11:08:29 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
f_print(fout, "void ");
|
|
|
|
pvname(name, vers);
|
2005-09-02 10:32:05 +00:00
|
|
|
f_print(fout, "(struct svc_req *rqstp, SVCXPRT *transp);\n");
|
2001-11-13 11:08:29 +00:00
|
|
|
}
|
|
|
|
|
1996-07-12 19:08:36 +00:00
|
|
|
static void
|
2005-09-01 19:16:25 +00:00
|
|
|
pprogramdef(definition *def, int headeronly)
|
1994-08-07 18:01:39 +00:00
|
|
|
{
|
|
|
|
version_list *vers;
|
|
|
|
proc_list *proc;
|
2005-11-13 21:17:24 +00:00
|
|
|
const char *ext;
|
1995-12-13 03:31:10 +00:00
|
|
|
|
|
|
|
pargdef(def);
|
1994-08-07 18:01:39 +00:00
|
|
|
|
|
|
|
puldefine(def->def_name, def->def.pr.prog_num);
|
|
|
|
for (vers = def->def.pr.versions; vers != NULL; vers = vers->next) {
|
1995-12-13 03:31:10 +00:00
|
|
|
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);
|
|
|
|
}
|
1994-08-07 18:01:39 +00:00
|
|
|
puldefine(vers->vers_name, vers->vers_num);
|
1995-12-13 03:31:10 +00:00
|
|
|
|
2005-09-02 10:23:26 +00:00
|
|
|
f_print(fout, "\n");
|
|
|
|
ext = "extern ";
|
|
|
|
if (headeronly) {
|
|
|
|
f_print(fout, "%s", ext);
|
|
|
|
pdispatch(def->def_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);
|
1994-08-07 18:01:39 +00:00
|
|
|
}
|
2005-09-02 10:23:26 +00:00
|
|
|
f_print(fout, "%s", ext);
|
|
|
|
pprocdef(proc, vers, "CLIENT *", 0);
|
|
|
|
f_print(fout, "%s", ext);
|
|
|
|
pprocdef(proc, vers, "struct svc_req *", 1);
|
1994-08-07 18:01:39 +00:00
|
|
|
}
|
2005-09-02 10:23:26 +00:00
|
|
|
pfreeprocdef(def->def_name, vers->vers_num);
|
1994-08-07 18:01:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1996-07-12 19:08:36 +00:00
|
|
|
static void
|
2005-11-13 21:17:24 +00:00
|
|
|
pprocdef(proc_list *proc, version_list *vp, const char *addargtype, int server_p)
|
1994-08-07 18:01:39 +00:00
|
|
|
{
|
1995-12-13 03:31:10 +00:00
|
|
|
if (mtflag) {/* Print MT style stubs */
|
|
|
|
if (server_p)
|
|
|
|
f_print(fout, "bool_t ");
|
|
|
|
else
|
|
|
|
f_print(fout, "enum clnt_stat ");
|
|
|
|
} else {
|
|
|
|
ptype(proc->res_prefix, proc->res_type, 1);
|
|
|
|
f_print(fout, "* ");
|
|
|
|
}
|
|
|
|
if (server_p)
|
|
|
|
pvname_svc(proc->proc_name, vp->vers_num);
|
|
|
|
else
|
|
|
|
pvname(proc->proc_name, vp->vers_num);
|
|
|
|
|
2005-09-02 10:23:26 +00:00
|
|
|
parglist(proc, addargtype);
|
1995-12-13 03:31:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* print out argument list of procedure */
|
1996-07-12 19:08:36 +00:00
|
|
|
static void
|
2005-11-13 21:17:24 +00:00
|
|
|
parglist(proc_list *proc, const char *addargtype)
|
1995-12-13 03:31:10 +00:00
|
|
|
{
|
|
|
|
decl_list *dl;
|
|
|
|
|
|
|
|
f_print(fout, "(");
|
|
|
|
if (proc->arg_num < 2 && newstyle &&
|
|
|
|
streq(proc->args.decls->decl.type, "void")) {
|
|
|
|
/* 0 argument in new style: do nothing*/
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for (dl = proc->args.decls; dl != NULL; dl = dl->next) {
|
|
|
|
ptype(dl->decl.prefix, dl->decl.type, 1);
|
|
|
|
if (!newstyle)
|
|
|
|
f_print(fout, "*");
|
|
|
|
/* old style passes by reference */
|
|
|
|
f_print(fout, ", ");
|
1994-08-07 18:01:39 +00:00
|
|
|
}
|
|
|
|
}
|
1995-12-13 03:31:10 +00:00
|
|
|
|
|
|
|
if (mtflag) {
|
|
|
|
ptype(proc->res_prefix, proc->res_type, 1);
|
|
|
|
f_print(fout, "*, ");
|
1994-08-07 18:01:39 +00:00
|
|
|
}
|
1995-12-13 03:31:10 +00:00
|
|
|
|
|
|
|
f_print(fout, "%s);\n", addargtype);
|
|
|
|
|
1994-08-07 18:01:39 +00:00
|
|
|
}
|
|
|
|
|
1996-07-12 19:08:36 +00:00
|
|
|
static void
|
2010-01-02 10:09:20 +00:00
|
|
|
penumdef(definition *def)
|
1994-08-07 18:01:39 +00:00
|
|
|
{
|
2005-11-13 21:17:24 +00:00
|
|
|
const char *name = def->def_name;
|
1994-08-07 18:01:39 +00:00
|
|
|
enumval_list *l;
|
2005-11-13 21:17:24 +00:00
|
|
|
const char *last = NULL;
|
1994-08-07 18:01:39 +00:00
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
f_print(fout, "enum %s {\n", name);
|
|
|
|
for (l = def->def.en.vals; l != NULL; l = l->next) {
|
|
|
|
f_print(fout, "\t%s", l->name);
|
|
|
|
if (l->assignment) {
|
|
|
|
f_print(fout, " = %s", l->assignment);
|
|
|
|
last = l->assignment;
|
|
|
|
count = 1;
|
|
|
|
} else {
|
|
|
|
if (last == NULL) {
|
|
|
|
f_print(fout, " = %d", count++);
|
|
|
|
} else {
|
|
|
|
f_print(fout, " = %s + %d", last, count++);
|
|
|
|
}
|
|
|
|
}
|
1995-12-13 03:31:10 +00:00
|
|
|
if (l->next)
|
|
|
|
f_print(fout, ",\n");
|
|
|
|
else
|
|
|
|
f_print(fout, "\n");
|
1994-08-07 18:01:39 +00:00
|
|
|
}
|
|
|
|
f_print(fout, "};\n");
|
|
|
|
f_print(fout, "typedef enum %s %s;\n", name, name);
|
|
|
|
}
|
|
|
|
|
1996-07-12 19:08:36 +00:00
|
|
|
static void
|
2010-01-02 10:09:20 +00:00
|
|
|
ptypedef(definition *def)
|
1994-08-07 18:01:39 +00:00
|
|
|
{
|
2005-11-13 21:17:24 +00:00
|
|
|
const char *name = def->def_name;
|
|
|
|
const char *old = def->def.ty.old_type;
|
1994-08-07 18:01:39 +00:00
|
|
|
char prefix[8]; /* enough to contain "struct ", including NUL */
|
|
|
|
relation rel = def->def.ty.rel;
|
|
|
|
|
|
|
|
|
|
|
|
if (!streq(name, old)) {
|
|
|
|
if (streq(old, "string")) {
|
|
|
|
old = "char";
|
|
|
|
rel = REL_POINTER;
|
|
|
|
} else if (streq(old, "opaque")) {
|
|
|
|
old = "char";
|
|
|
|
} else if (streq(old, "bool")) {
|
|
|
|
old = "bool_t";
|
|
|
|
}
|
|
|
|
if (undefined2(old, name) && def->def.ty.old_prefix) {
|
|
|
|
s_print(prefix, "%s ", def->def.ty.old_prefix);
|
|
|
|
} else {
|
|
|
|
prefix[0] = 0;
|
|
|
|
}
|
|
|
|
f_print(fout, "typedef ");
|
|
|
|
switch (rel) {
|
|
|
|
case REL_ARRAY:
|
|
|
|
f_print(fout, "struct {\n");
|
|
|
|
f_print(fout, "\tu_int %s_len;\n", name);
|
|
|
|
f_print(fout, "\t%s%s *%s_val;\n", prefix, old, name);
|
|
|
|
f_print(fout, "} %s", name);
|
|
|
|
break;
|
|
|
|
case REL_POINTER:
|
|
|
|
f_print(fout, "%s%s *%s", prefix, old, name);
|
|
|
|
break;
|
|
|
|
case REL_VECTOR:
|
|
|
|
f_print(fout, "%s%s %s[%s]", prefix, old, name,
|
|
|
|
def->def.ty.array_max);
|
|
|
|
break;
|
|
|
|
case REL_ALIAS:
|
1995-12-13 03:31:10 +00:00
|
|
|
f_print(fout, "%s%s %s", prefix, old, name);
|
1994-08-07 18:01:39 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
f_print(fout, ";\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1996-07-12 19:08:36 +00:00
|
|
|
void
|
2005-11-13 21:17:24 +00:00
|
|
|
pdeclaration(const char *name, declaration *dec, int tab, const char *separator)
|
1994-08-07 18:01:39 +00:00
|
|
|
{
|
|
|
|
char buf[8]; /* enough to hold "struct ", include NUL */
|
2005-11-13 21:17:24 +00:00
|
|
|
const char *prefix;
|
|
|
|
const char *type;
|
1994-08-07 18:01:39 +00:00
|
|
|
|
|
|
|
if (streq(dec->type, "void")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
tabify(fout, tab);
|
|
|
|
if (streq(dec->type, name) && !dec->prefix) {
|
|
|
|
f_print(fout, "struct ");
|
|
|
|
}
|
|
|
|
if (streq(dec->type, "string")) {
|
|
|
|
f_print(fout, "char *%s", dec->name);
|
|
|
|
} else {
|
|
|
|
prefix = "";
|
|
|
|
if (streq(dec->type, "bool")) {
|
|
|
|
type = "bool_t";
|
|
|
|
} else if (streq(dec->type, "opaque")) {
|
|
|
|
type = "char";
|
|
|
|
} else {
|
|
|
|
if (dec->prefix) {
|
|
|
|
s_print(buf, "%s ", dec->prefix);
|
|
|
|
prefix = buf;
|
|
|
|
}
|
|
|
|
type = dec->type;
|
|
|
|
}
|
|
|
|
switch (dec->rel) {
|
|
|
|
case REL_ALIAS:
|
|
|
|
f_print(fout, "%s%s %s", prefix, type, dec->name);
|
|
|
|
break;
|
|
|
|
case REL_VECTOR:
|
|
|
|
f_print(fout, "%s%s %s[%s]", prefix, type, dec->name,
|
|
|
|
dec->array_max);
|
|
|
|
break;
|
|
|
|
case REL_POINTER:
|
|
|
|
f_print(fout, "%s%s *%s", prefix, type, dec->name);
|
|
|
|
break;
|
|
|
|
case REL_ARRAY:
|
|
|
|
f_print(fout, "struct {\n");
|
|
|
|
tabify(fout, tab);
|
|
|
|
f_print(fout, "\tu_int %s_len;\n", dec->name);
|
|
|
|
tabify(fout, tab);
|
1995-12-13 03:31:10 +00:00
|
|
|
f_print(fout,
|
|
|
|
"\t%s%s *%s_val;\n", prefix, type, dec->name);
|
1994-08-07 18:01:39 +00:00
|
|
|
tabify(fout, tab);
|
|
|
|
f_print(fout, "} %s", dec->name);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-05-18 20:52:52 +00:00
|
|
|
fputs(separator, fout);
|
1994-08-07 18:01:39 +00:00
|
|
|
}
|
|
|
|
|
1996-07-12 19:08:36 +00:00
|
|
|
static int
|
2005-11-13 21:17:24 +00:00
|
|
|
undefined2(const char *type, const char *stop)
|
1994-08-07 18:01:39 +00:00
|
|
|
{
|
|
|
|
list *l;
|
|
|
|
definition *def;
|
|
|
|
|
|
|
|
for (l = defined; l != NULL; l = l->next) {
|
|
|
|
def = (definition *) l->val;
|
|
|
|
if (def->def_kind != DEF_PROGRAM) {
|
|
|
|
if (streq(def->def_name, stop)) {
|
|
|
|
return (1);
|
|
|
|
} else if (streq(def->def_name, type)) {
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (1);
|
|
|
|
}
|