2016-01-23 05:33:09 +03:00
|
|
|
/* $NetBSD: rpc_hout.c,v 1.25 2016/01/23 02:33:09 dholland Exp $ */
|
1993-04-03 04:51:49 +04: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
|
1995-06-12 01:49:50 +04:00
|
|
|
* program developed by the user or with the express written consent of
|
|
|
|
* Sun Microsystems, Inc.
|
|
|
|
*
|
1993-04-03 04:51:49 +04: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.
|
1995-06-12 01:49:50 +04:00
|
|
|
*
|
1993-04-03 04:51:49 +04: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.
|
1995-06-12 01:49:50 +04:00
|
|
|
*
|
1993-04-03 04:51:49 +04: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.
|
1995-06-12 01:49:50 +04:00
|
|
|
*
|
1993-04-03 04:51:49 +04: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.
|
1995-06-12 01:49:50 +04:00
|
|
|
*
|
1993-04-03 04:51:49 +04:00
|
|
|
* Sun Microsystems, Inc.
|
|
|
|
* 2550 Garcia Avenue
|
|
|
|
* Mountain View, California 94043
|
|
|
|
*/
|
1995-06-12 01:49:50 +04:00
|
|
|
|
2004-06-21 02:20:14 +04:00
|
|
|
#if HAVE_NBTOOL_CONFIG_H
|
|
|
|
#include "nbtool_config.h"
|
|
|
|
#endif
|
|
|
|
|
1997-10-12 01:01:26 +04:00
|
|
|
#include <sys/cdefs.h>
|
2002-02-01 01:43:33 +03:00
|
|
|
#if defined(__RCSID) && !defined(lint)
|
1997-10-12 01:01:26 +04:00
|
|
|
#if 0
|
1995-06-12 01:49:50 +04:00
|
|
|
static char sccsid[] = "@(#)rpc_hout.c 1.12 89/02/22 (C) 1987 SMI";
|
1997-10-12 01:01:26 +04:00
|
|
|
#else
|
2016-01-23 05:33:09 +03:00
|
|
|
__RCSID("$NetBSD: rpc_hout.c,v 1.25 2016/01/23 02:33:09 dholland Exp $");
|
1997-10-12 01:01:26 +04:00
|
|
|
#endif
|
1993-04-03 04:51:49 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
1997-10-18 14:53:37 +04:00
|
|
|
* rpc_hout.c, Header file outputter for the RPC protocol compiler
|
1993-04-03 04:51:49 +04:00
|
|
|
*/
|
|
|
|
#include <ctype.h>
|
2002-02-01 01:43:33 +03:00
|
|
|
#include <err.h>
|
|
|
|
#include <stdio.h>
|
1997-10-12 01:01:26 +04:00
|
|
|
#include "rpc_scan.h"
|
1993-04-03 04:51:49 +04:00
|
|
|
#include "rpc_parse.h"
|
1995-06-12 01:49:50 +04:00
|
|
|
#include "rpc_util.h"
|
1993-04-03 04:51:49 +04:00
|
|
|
|
2013-12-15 04:40:17 +04:00
|
|
|
static void pconstdef(definition *);
|
|
|
|
static void pargdef(definition *);
|
|
|
|
static void pstructdef(definition *);
|
|
|
|
static void puniondef(definition *);
|
|
|
|
static void pdefine(const char *, const char *);
|
|
|
|
static void puldefine(const char *, const char *);
|
|
|
|
static int define_printed(proc_list *, version_list *);
|
|
|
|
static void pprogramdef(definition *);
|
|
|
|
static void penumdef(definition *);
|
|
|
|
static void ptypedef(definition *);
|
|
|
|
static int undefined2(const char *, const char *);
|
|
|
|
static void cplusplusstart(void);
|
|
|
|
static void cplusplusend(void);
|
1993-04-03 04:51:49 +04:00
|
|
|
|
|
|
|
/*
|
1997-10-18 14:53:37 +04:00
|
|
|
* Print the C-version of an xdr definition
|
1993-04-03 04:51:49 +04:00
|
|
|
*/
|
|
|
|
void
|
2013-08-11 12:03:10 +04:00
|
|
|
print_datadef(definition *def)
|
1993-04-03 04:51:49 +04:00
|
|
|
{
|
1995-06-12 01:49:50 +04:00
|
|
|
|
1997-10-18 14:53:37 +04:00
|
|
|
if (def->def_kind == DEF_PROGRAM) /* handle data only */
|
|
|
|
return;
|
1995-06-12 01:49:50 +04:00
|
|
|
|
1993-04-03 04:51:49 +04: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:
|
|
|
|
pprogramdef(def);
|
|
|
|
break;
|
|
|
|
case DEF_CONST:
|
|
|
|
pconstdef(def);
|
|
|
|
break;
|
|
|
|
}
|
1995-06-12 01:49:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-12-15 04:40:17 +04:00
|
|
|
print_progdef(definition *def)
|
1995-06-12 01:49:50 +04:00
|
|
|
{
|
|
|
|
switch (def->def_kind) {
|
|
|
|
case DEF_PROGRAM:
|
1993-04-03 04:51:49 +04:00
|
|
|
f_print(fout, "\n");
|
1995-06-12 01:49:50 +04:00
|
|
|
pprogramdef(def);
|
|
|
|
break;
|
1997-10-12 01:01:26 +04:00
|
|
|
case DEF_CONST:
|
|
|
|
case DEF_TYPEDEF:
|
|
|
|
case DEF_ENUM:
|
|
|
|
case DEF_UNION:
|
|
|
|
case DEF_STRUCT:
|
|
|
|
break;
|
1997-10-18 14:53:37 +04:00
|
|
|
}
|
1995-06-12 01:49:50 +04:00
|
|
|
}
|
|
|
|
|
2013-12-15 04:40:17 +04:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-10-12 01:01:26 +04:00
|
|
|
void
|
2013-08-11 12:03:10 +04:00
|
|
|
pxdrfuncdecl(const char *name, int pointerp)
|
1995-06-12 01:49:50 +04:00
|
|
|
{
|
|
|
|
|
2013-12-15 04:40:17 +04:00
|
|
|
f_print(fout, "bool_t xdr_%s(XDR *, %s%s);\n", name,
|
2000-06-07 17:53:07 +04:00
|
|
|
name, pointerp ? (" *") : "");
|
1993-04-03 04:51:49 +04:00
|
|
|
}
|
|
|
|
|
1995-06-12 01:49:50 +04:00
|
|
|
|
1997-10-12 01:01:26 +04:00
|
|
|
static void
|
2013-08-11 12:03:10 +04:00
|
|
|
pconstdef(definition *def)
|
1993-04-03 04:51:49 +04:00
|
|
|
{
|
|
|
|
pdefine(def->def_name, def->def.co);
|
|
|
|
}
|
2013-08-11 12:03:10 +04:00
|
|
|
|
1997-10-18 14:53:37 +04:00
|
|
|
/* print out the definitions for the arguments of functions in the
|
|
|
|
header file
|
1995-06-12 01:49:50 +04:00
|
|
|
*/
|
1997-10-18 14:53:37 +04:00
|
|
|
static void
|
2013-08-11 12:03:10 +04:00
|
|
|
pargdef(definition *def)
|
1995-06-12 01:49:50 +04:00
|
|
|
{
|
|
|
|
decl_list *l;
|
|
|
|
version_list *vers;
|
1997-10-18 14:53:37 +04:00
|
|
|
char *name;
|
1995-06-12 01:49:50 +04:00
|
|
|
proc_list *plist;
|
2013-12-15 04:40:17 +04:00
|
|
|
int did;
|
1995-06-12 01:49:50 +04:00
|
|
|
|
1997-10-18 14:53:37 +04:00
|
|
|
|
1995-06-12 01:49:50 +04:00
|
|
|
for (vers = def->def.pr.versions; vers != NULL; vers = vers->next) {
|
2013-12-15 04:40:17 +04:00
|
|
|
for (plist = vers->procs; plist != NULL; plist = plist->next) {
|
1997-10-18 14:53:37 +04:00
|
|
|
if (!newstyle || plist->arg_num < 2) {
|
|
|
|
continue; /* old style or single args */
|
1995-06-12 01:49:50 +04:00
|
|
|
}
|
1997-10-18 14:53:37 +04:00
|
|
|
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);
|
1995-06-12 01:49:50 +04:00
|
|
|
}
|
1997-10-18 14:53:37 +04:00
|
|
|
}
|
2013-12-15 04:40:17 +04:00
|
|
|
did = 0;
|
|
|
|
for (vers = def->def.pr.versions; vers != NULL; vers = vers->next) {
|
|
|
|
for (plist = vers->procs; plist != NULL; plist = plist->next) {
|
2015-09-20 18:45:07 +03:00
|
|
|
if (!newstyle || plist->arg_num < 2) {
|
|
|
|
continue; /* old style or single args */
|
|
|
|
}
|
|
|
|
|
2013-12-15 04:40:17 +04:00
|
|
|
if (!did) {
|
|
|
|
cplusplusstart();
|
|
|
|
did = 1;
|
|
|
|
}
|
|
|
|
pxdrfuncdecl(plist->args.argname, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (did) {
|
|
|
|
cplusplusend();
|
|
|
|
}
|
1995-06-12 01:49:50 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-10-18 14:53:37 +04:00
|
|
|
static void
|
2013-08-11 12:03:10 +04:00
|
|
|
pstructdef(definition *def)
|
1993-04-03 04:51:49 +04:00
|
|
|
{
|
|
|
|
decl_list *l;
|
2013-08-11 12:03:10 +04:00
|
|
|
const char *name = def->def_name;
|
1993-04-03 04:51:49 +04:00
|
|
|
|
|
|
|
f_print(fout, "struct %s {\n", name);
|
|
|
|
for (l = def->def.st.decls; l != NULL; l = l->next) {
|
1995-06-12 01:49:50 +04:00
|
|
|
pdeclaration(name, &l->decl, 1, ";\n");
|
1993-04-03 04:51:49 +04:00
|
|
|
}
|
|
|
|
f_print(fout, "};\n");
|
|
|
|
f_print(fout, "typedef struct %s %s;\n", name, name);
|
|
|
|
}
|
|
|
|
|
1997-10-12 01:01:26 +04:00
|
|
|
static void
|
2013-08-11 12:03:10 +04:00
|
|
|
puniondef(definition *def)
|
1993-04-03 04:51:49 +04:00
|
|
|
{
|
|
|
|
case_list *l;
|
2013-08-11 12:03:10 +04:00
|
|
|
const char *name = def->def_name;
|
1993-04-03 04:51:49 +04: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) {
|
1997-10-18 14:53:37 +04:00
|
|
|
if (l->contflag == 0)
|
|
|
|
pdeclaration(name, &l->case_decl, 2, ";\n");
|
1993-04-03 04:51:49 +04:00
|
|
|
}
|
|
|
|
decl = def->def.un.default_decl;
|
|
|
|
if (decl && !streq(decl->type, "void")) {
|
1997-10-18 14:53:37 +04:00
|
|
|
pdeclaration(name, decl, 2, ";\n");
|
1993-04-03 04:51:49 +04:00
|
|
|
}
|
|
|
|
f_print(fout, "\t} %s_u;\n", name);
|
|
|
|
f_print(fout, "};\n");
|
|
|
|
f_print(fout, "typedef struct %s %s;\n", name, name);
|
|
|
|
}
|
|
|
|
|
1997-10-12 01:01:26 +04:00
|
|
|
static void
|
2013-08-11 12:03:10 +04:00
|
|
|
pdefine(const char *name, const char *num)
|
1993-04-03 04:51:49 +04:00
|
|
|
{
|
|
|
|
f_print(fout, "#define %s %s\n", name, num);
|
|
|
|
}
|
|
|
|
|
1997-10-12 01:01:26 +04:00
|
|
|
static void
|
2013-08-11 12:03:10 +04:00
|
|
|
puldefine(const char *name, const char *num)
|
1993-04-03 04:51:49 +04:00
|
|
|
{
|
2000-06-03 03:30:17 +04:00
|
|
|
f_print(fout, "#define %s %s\n", name, num);
|
1993-04-03 04:51:49 +04:00
|
|
|
}
|
|
|
|
|
1997-10-12 01:01:26 +04:00
|
|
|
static int
|
2013-08-11 12:03:10 +04:00
|
|
|
define_printed(proc_list *stop, version_list *start)
|
1993-04-03 04:51:49 +04: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);
|
1997-10-18 14:53:37 +04:00
|
|
|
} else
|
|
|
|
if (streq(proc->proc_name, stop->proc_name)) {
|
|
|
|
return (1);
|
|
|
|
}
|
1993-04-03 04:51:49 +04:00
|
|
|
}
|
|
|
|
}
|
2015-05-10 02:12:57 +03:00
|
|
|
errx(1, "Internal error at %s:%d: procedure not found",
|
1997-10-12 01:01:26 +04:00
|
|
|
__FILE__, __LINE__);
|
1993-04-03 04:51:49 +04:00
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
|
2013-12-15 04:40:17 +04:00
|
|
|
static void
|
|
|
|
cplusplusstart(void)
|
|
|
|
{
|
|
|
|
if (BSDflag)
|
|
|
|
f_print(fout, "__BEGIN_DECLS\n");
|
|
|
|
else
|
|
|
|
f_print(fout, "#ifdef __cplusplus\nextern \"C\" {\n#endif\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cplusplusend(void)
|
|
|
|
{
|
|
|
|
if (BSDflag)
|
|
|
|
f_print(fout, "__END_DECLS\n");
|
|
|
|
else
|
|
|
|
f_print(fout, "#ifdef __cplusplus\n};\n#endif\n");
|
|
|
|
}
|
|
|
|
|
1997-10-12 01:01:26 +04:00
|
|
|
static void
|
2013-08-11 12:03:10 +04:00
|
|
|
pprogramdef(definition *def)
|
1993-04-03 04:51:49 +04:00
|
|
|
{
|
|
|
|
version_list *vers;
|
|
|
|
proc_list *proc;
|
1997-10-18 14:53:37 +04:00
|
|
|
|
1995-06-12 01:49:50 +04:00
|
|
|
pargdef(def);
|
1993-04-03 04:51:49 +04:00
|
|
|
|
|
|
|
puldefine(def->def_name, def->def.pr.prog_num);
|
|
|
|
for (vers = def->def.pr.versions; vers != NULL; vers = vers->next) {
|
1995-06-12 01:49:50 +04:00
|
|
|
if (tblflag) {
|
|
|
|
f_print(fout, "extern struct rpcgen_table %s_%s_table[];\n",
|
1997-10-18 14:53:37 +04:00
|
|
|
locase(def->def_name), vers->vers_num);
|
1995-06-12 01:49:50 +04:00
|
|
|
f_print(fout, "extern %s_%s_nproc;\n",
|
1997-10-18 14:53:37 +04:00
|
|
|
locase(def->def_name), vers->vers_num);
|
1995-06-12 01:49:50 +04:00
|
|
|
}
|
1993-04-03 04:51:49 +04:00
|
|
|
puldefine(vers->vers_name, vers->vers_num);
|
2013-12-15 04:40:17 +04:00
|
|
|
for (proc = vers->procs; proc != NULL; proc = proc->next) {
|
|
|
|
if (!define_printed(proc, def->def.pr.versions)) {
|
|
|
|
puldefine(proc->proc_name, proc->proc_num);
|
1993-04-03 04:51:49 +04:00
|
|
|
}
|
2013-12-15 04:40:17 +04:00
|
|
|
}
|
|
|
|
}
|
1995-06-12 01:49:50 +04:00
|
|
|
|
2013-12-15 04:40:17 +04:00
|
|
|
/*
|
|
|
|
* 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);
|
1993-04-03 04:51:49 +04:00
|
|
|
}
|
|
|
|
}
|
2013-12-15 04:40:17 +04:00
|
|
|
cplusplusend();
|
1993-04-03 04:51:49 +04:00
|
|
|
}
|
|
|
|
|
1997-10-12 01:01:26 +04:00
|
|
|
void
|
2013-08-11 12:03:10 +04:00
|
|
|
pprocdef(proc_list *proc, version_list *vp, const char *addargtype,
|
2013-12-15 04:40:17 +04:00
|
|
|
int server_p)
|
1993-04-03 04:51:49 +04:00
|
|
|
{
|
2001-03-21 03:30:39 +03:00
|
|
|
decl_list *dl;
|
1995-06-12 01:49:50 +04:00
|
|
|
|
2001-03-21 03:30:39 +03:00
|
|
|
if (Mflag) {
|
|
|
|
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, "*");
|
|
|
|
}
|
1997-10-18 14:53:37 +04:00
|
|
|
if (server_p)
|
1995-06-12 01:49:50 +04:00
|
|
|
pvname_svc(proc->proc_name, vp->vers_num);
|
|
|
|
else
|
|
|
|
pvname(proc->proc_name, vp->vers_num);
|
|
|
|
|
2013-12-15 04:40:17 +04:00
|
|
|
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)
|
2001-03-21 03:30:39 +03:00
|
|
|
f_print(fout, "*");
|
1997-10-18 14:53:37 +04:00
|
|
|
f_print(fout, ", ");
|
1995-06-12 01:49:50 +04:00
|
|
|
}
|
1993-04-03 04:51:49 +04:00
|
|
|
}
|
2013-12-15 04:40:17 +04:00
|
|
|
if (Mflag) {
|
|
|
|
if (streq(proc->res_type, "void"))
|
|
|
|
f_print(fout, "char");
|
|
|
|
else
|
|
|
|
ptype(proc->res_prefix, proc->res_type, 0);
|
|
|
|
if (!isvectordef(proc->res_type, REL_ALIAS))
|
|
|
|
f_print(fout, "*");
|
|
|
|
f_print(fout, ", ");
|
|
|
|
}
|
|
|
|
f_print(fout, "%s);\n", addargtype);
|
1993-04-03 04:51:49 +04:00
|
|
|
}
|
|
|
|
|
2001-03-21 03:30:39 +03:00
|
|
|
|
1997-10-12 01:01:26 +04:00
|
|
|
static void
|
2013-08-11 12:03:10 +04:00
|
|
|
penumdef(definition *def)
|
1993-04-03 04:51:49 +04:00
|
|
|
{
|
2013-08-11 12:03:10 +04:00
|
|
|
const char *name = def->def_name;
|
1993-04-03 04:51:49 +04:00
|
|
|
enumval_list *l;
|
2013-08-11 12:03:10 +04:00
|
|
|
const char *last = NULL;
|
|
|
|
int count = 0;
|
|
|
|
const char *first = "";
|
1993-04-03 04:51:49 +04:00
|
|
|
|
|
|
|
f_print(fout, "enum %s {\n", name);
|
|
|
|
for (l = def->def.en.vals; l != NULL; l = l->next) {
|
2002-02-06 01:03:01 +03:00
|
|
|
f_print(fout, "%s\t%s", first, l->name);
|
1993-04-03 04:51:49 +04:00
|
|
|
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++);
|
|
|
|
}
|
|
|
|
}
|
2002-02-06 01:03:01 +03:00
|
|
|
first = ",\n";
|
1993-04-03 04:51:49 +04:00
|
|
|
}
|
2002-02-06 01:03:01 +03:00
|
|
|
f_print(fout, "\n};\n");
|
1993-04-03 04:51:49 +04:00
|
|
|
f_print(fout, "typedef enum %s %s;\n", name, name);
|
|
|
|
}
|
|
|
|
|
1997-10-12 01:01:26 +04:00
|
|
|
static void
|
2013-08-11 12:03:10 +04:00
|
|
|
ptypedef(definition *def)
|
1993-04-03 04:51:49 +04:00
|
|
|
{
|
2013-08-11 12:03:10 +04:00
|
|
|
const char *name = def->def_name;
|
|
|
|
const char *old = def->def.ty.old_type;
|
1997-10-18 14:53:37 +04:00
|
|
|
char prefix[8]; /* enough to contain "struct ", including NUL */
|
1993-04-03 04:51:49 +04:00
|
|
|
relation rel = def->def.ty.rel;
|
|
|
|
|
|
|
|
|
|
|
|
if (!streq(name, old)) {
|
|
|
|
if (streq(old, "string")) {
|
|
|
|
old = "char";
|
|
|
|
rel = REL_POINTER;
|
1997-10-18 14:53:37 +04:00
|
|
|
} else
|
|
|
|
if (streq(old, "opaque")) {
|
|
|
|
old = "char";
|
|
|
|
} else
|
|
|
|
if (streq(old, "bool")) {
|
|
|
|
old = "bool_t";
|
|
|
|
}
|
1993-04-03 04:51:49 +04:00
|
|
|
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");
|
2016-01-23 05:33:09 +03:00
|
|
|
f_print(fout, "\tunsigned int %s_len;\n", name);
|
1993-04-03 04:51:49 +04:00
|
|
|
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,
|
1997-10-18 14:53:37 +04:00
|
|
|
def->def.ty.array_max);
|
1993-04-03 04:51:49 +04:00
|
|
|
break;
|
|
|
|
case REL_ALIAS:
|
1995-06-12 01:49:50 +04:00
|
|
|
f_print(fout, "%s%s %s", prefix, old, name);
|
1993-04-03 04:51:49 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
f_print(fout, ";\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-10-12 01:01:26 +04:00
|
|
|
void
|
2013-08-11 12:03:10 +04:00
|
|
|
pdeclaration(const char *name, declaration *dec, int tab,
|
|
|
|
const char *separator)
|
1993-04-03 04:51:49 +04:00
|
|
|
{
|
1997-10-18 14:53:37 +04:00
|
|
|
char buf[8]; /* enough to hold "struct ", include NUL */
|
2013-08-11 12:03:10 +04:00
|
|
|
const char *prefix;
|
|
|
|
const char *type;
|
1993-04-03 04:51:49 +04: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";
|
1997-10-18 14:53:37 +04:00
|
|
|
} else
|
|
|
|
if (streq(dec->type, "opaque")) {
|
|
|
|
type = "char";
|
|
|
|
} else {
|
|
|
|
if (dec->prefix) {
|
|
|
|
s_print(buf, "%s ", dec->prefix);
|
|
|
|
prefix = buf;
|
|
|
|
}
|
|
|
|
type = dec->type;
|
1993-04-03 04:51:49 +04:00
|
|
|
}
|
|
|
|
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,
|
1997-10-18 14:53:37 +04:00
|
|
|
dec->array_max);
|
1993-04-03 04:51:49 +04:00
|
|
|
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);
|
2016-01-23 05:33:09 +03:00
|
|
|
f_print(fout, "\tunsigned int %s_len;\n", dec->name);
|
1993-04-03 04:51:49 +04:00
|
|
|
tabify(fout, tab);
|
|
|
|
f_print(fout, "\t%s%s *%s_val;\n", prefix, type, dec->name);
|
|
|
|
tabify(fout, tab);
|
|
|
|
f_print(fout, "} %s", dec->name);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2000-10-11 18:46:00 +04:00
|
|
|
f_print(fout, "%s", separator);
|
1993-04-03 04:51:49 +04:00
|
|
|
}
|
|
|
|
|
1997-10-12 01:01:26 +04:00
|
|
|
static int
|
2013-08-11 12:03:10 +04:00
|
|
|
undefined2(const char *type, const char *stop)
|
1993-04-03 04:51:49 +04:00
|
|
|
{
|
1997-10-18 14:53:37 +04:00
|
|
|
list *l;
|
1993-04-03 04:51:49 +04:00
|
|
|
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);
|
1997-10-18 14:53:37 +04:00
|
|
|
} else
|
|
|
|
if (streq(def->def_name, type)) {
|
|
|
|
return (0);
|
|
|
|
}
|
1993-04-03 04:51:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return (1);
|
|
|
|
}
|