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
|
|
|
|
|
|
|
|
1997-08-06 06:47:41 +00:00
|
|
|
#if 0
|
2002-07-21 12:55:04 +00:00
|
|
|
#ifndef lint
|
2005-05-31 20:00:29 +00:00
|
|
|
#ident "@(#)rpc_main.c 1.21 94/04/25 SMI"
|
1995-12-13 03:31:10 +00:00
|
|
|
static char sccsid[] = "@(#)rpc_main.c 1.30 89/03/30 (C) 1987 SMI";
|
1994-08-07 18:01:39 +00:00
|
|
|
#endif
|
1997-08-06 06:47:41 +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_main.c, Top level of the RPC protocol compiler.
|
|
|
|
* Copyright (C) 1987, Sun Microsystems, Inc.
|
1994-08-07 18:01:39 +00:00
|
|
|
*/
|
|
|
|
|
1997-08-06 06:47:41 +00:00
|
|
|
#include <err.h>
|
|
|
|
#include <ctype.h>
|
1994-08-07 18:01:39 +00:00
|
|
|
#include <stdio.h>
|
1995-12-13 03:31:10 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/param.h>
|
1994-08-07 18:01:39 +00:00
|
|
|
#include <sys/file.h>
|
1995-12-13 03:31:10 +00:00
|
|
|
#include <sys/stat.h>
|
1994-08-07 18:01:39 +00:00
|
|
|
#include "rpc_parse.h"
|
|
|
|
#include "rpc_scan.h"
|
2005-08-31 20:45:15 +00:00
|
|
|
#include "rpc_util.h"
|
1994-08-07 18:01:39 +00:00
|
|
|
|
2005-11-13 21:17:24 +00:00
|
|
|
static void c_output(const char *, const char *, int, const char *);
|
|
|
|
static void h_output(const char *, const char *, int, const char *, int);
|
|
|
|
static void l_output(const char *, const char *, int, const char *);
|
|
|
|
static void t_output(const char *, const char *, int, const char *);
|
|
|
|
static void clnt_output(const char *, const char *, int, const char * );
|
|
|
|
static char *generate_guard(const char *);
|
|
|
|
static void c_initialize(void);
|
1995-12-13 03:31:10 +00:00
|
|
|
|
2002-03-22 01:33:25 +00:00
|
|
|
static void usage(void);
|
|
|
|
static void options_usage(void);
|
2005-11-13 21:17:24 +00:00
|
|
|
static int do_registers(int, const char **);
|
|
|
|
static int parseargs(int, const char **, struct commandline *);
|
|
|
|
static void svc_output(const char *, const char *, int, const char *);
|
2002-03-22 01:33:25 +00:00
|
|
|
static void mkfile_output(struct commandline *);
|
2005-11-13 21:17:24 +00:00
|
|
|
static void s_output(int, const char **, const char *, const char *, int, const char *, int, int);
|
1995-12-13 03:31:10 +00:00
|
|
|
|
|
|
|
#define EXTEND 1 /* alias for TRUE */
|
|
|
|
#define DONT_EXTEND 0 /* alias for FALSE */
|
|
|
|
|
2005-11-13 21:17:24 +00:00
|
|
|
static const char *svcclosetime = "120";
|
Let rpcgen(1) support an environment variable RPCGEN_CPP to find the C
preprocessor to run. Previously, it always ran /usr/bin/cpp, unless you
used the -Y option, and even then you could not set the basename. It
also attempted to run /usr/ccs/lib/cpp for SVR4 compatibility, but this
is obsolete, and has been removed.
Note that setting RPCGEN_CPP to a command with arguments is supported,
though the command line parsing is simplistic. However, setting it to
e.g. "gcc46 -E" or "clang -E" will lead to problems, because both gcc
and clang in -E mode will consider files with unknown extensions (such
as .x) as object files, and attempt to link them.
This could be worked around by also adding "-x c", but it is much safer
to set RPCGEN_CPP to e.g. "cpp46" or "clang-cpp" instead.
MFC after: 1 week
2012-02-06 12:03:21 +00:00
|
|
|
static const char *CPP = NULL;
|
2005-11-13 21:17:24 +00:00
|
|
|
static const char CPPFLAGS[] = "-C";
|
1995-12-13 03:31:10 +00:00
|
|
|
static char pathbuf[MAXPATHLEN + 1];
|
2005-11-13 21:17:24 +00:00
|
|
|
static const char *allv[] = {
|
1994-08-07 18:01:39 +00:00
|
|
|
"rpcgen", "-s", "udp", "-s", "tcp",
|
|
|
|
};
|
2016-08-16 15:53:05 +00:00
|
|
|
static int allc = nitems(allv);
|
2005-11-13 21:17:24 +00:00
|
|
|
static const char *allnv[] = {
|
1995-12-13 03:31:10 +00:00
|
|
|
"rpcgen", "-s", "netpath",
|
|
|
|
};
|
2016-08-16 15:53:05 +00:00
|
|
|
static int allnc = nitems(allnv);
|
1995-12-13 03:31:10 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* machinations for handling expanding argument list
|
|
|
|
*/
|
2005-11-13 21:17:24 +00:00
|
|
|
static void addarg(const char *); /* add another argument to the list */
|
Let rpcgen(1) support an environment variable RPCGEN_CPP to find the C
preprocessor to run. Previously, it always ran /usr/bin/cpp, unless you
used the -Y option, and even then you could not set the basename. It
also attempted to run /usr/ccs/lib/cpp for SVR4 compatibility, but this
is obsolete, and has been removed.
Note that setting RPCGEN_CPP to a command with arguments is supported,
though the command line parsing is simplistic. However, setting it to
e.g. "gcc46 -E" or "clang -E" will lead to problems, because both gcc
and clang in -E mode will consider files with unknown extensions (such
as .x) as object files, and attempt to link them.
This could be worked around by also adding "-x c", but it is much safer
to set RPCGEN_CPP to e.g. "cpp46" or "clang-cpp" instead.
MFC after: 1 week
2012-02-06 12:03:21 +00:00
|
|
|
static void insarg(int, const char *); /* insert arg at specified location */
|
2005-11-13 21:17:24 +00:00
|
|
|
static void checkfiles(const char *, const char *);
|
|
|
|
/* check if out file already exists */
|
1995-12-13 03:31:10 +00:00
|
|
|
|
2019-10-15 16:05:17 +00:00
|
|
|
static char **arglist;
|
|
|
|
static int argcount = 0;
|
|
|
|
static int argmax = 0;
|
1995-12-13 03:31:10 +00:00
|
|
|
|
|
|
|
int nonfatalerrors; /* errors */
|
2002-07-14 17:54:00 +00:00
|
|
|
int inetdflag = 0; /* Support for inetd is disabled by default, use -I */
|
|
|
|
int pmflag = 0; /* Support for port monitors is disabled by default */
|
|
|
|
int tirpc_socket = 1; /* TI-RPC on socket, no TLI library */
|
1995-12-13 03:31:10 +00:00
|
|
|
int logflag; /* Use syslog instead of fprintf for errors */
|
|
|
|
int tblflag; /* Support for dispatch table file */
|
|
|
|
int mtflag = 0; /* Support for MT */
|
2002-07-14 17:54:00 +00:00
|
|
|
|
1995-12-13 03:31:10 +00:00
|
|
|
#define INLINE 0
|
|
|
|
/* length at which to start doing an inline */
|
|
|
|
|
2005-08-31 19:44:40 +00:00
|
|
|
int inline_size = INLINE;
|
1995-12-13 03:31:10 +00:00
|
|
|
/*
|
|
|
|
* Length at which to start doing an inline. INLINE = default
|
|
|
|
* if 0, no xdr_inline code
|
|
|
|
*/
|
|
|
|
|
|
|
|
int indefinitewait; /* If started by port monitors, hang till it wants */
|
|
|
|
int exitnow; /* If started by port monitors, exit after the call */
|
|
|
|
int timerflag; /* TRUE if !indefinite && !exitnow */
|
|
|
|
int newstyle; /* newstyle of passing arguments (by value) */
|
|
|
|
int CCflag = 0; /* C++ files */
|
|
|
|
static int allfiles; /* generate all files */
|
|
|
|
int tirpcflag = 1; /* generating code for tirpc, by default */
|
|
|
|
xdrfunc *xdrfunc_head = NULL; /* xdr function list */
|
|
|
|
xdrfunc *xdrfunc_tail = NULL; /* xdr function list */
|
|
|
|
pid_t childpid;
|
1994-08-07 18:01:39 +00:00
|
|
|
|
|
|
|
|
1996-07-12 19:08:36 +00:00
|
|
|
int
|
2005-11-13 21:17:24 +00:00
|
|
|
main(int argc, const char *argv[])
|
1994-08-07 18:01:39 +00:00
|
|
|
{
|
|
|
|
struct commandline cmd;
|
|
|
|
|
1995-12-13 03:31:10 +00:00
|
|
|
(void) memset((char *)&cmd, 0, sizeof (struct commandline));
|
|
|
|
if (!parseargs(argc, argv, &cmd))
|
|
|
|
usage();
|
|
|
|
/*
|
|
|
|
* Only the client and server side stubs are likely to be customized,
|
|
|
|
* so in that case only, check if the outfile exists, and if so,
|
|
|
|
* print an error message and exit.
|
|
|
|
*/
|
|
|
|
if (cmd.Ssflag || cmd.Scflag || cmd.makefileflag) {
|
|
|
|
checkfiles(cmd.infile, cmd.outfile);
|
1994-08-07 18:01:39 +00:00
|
|
|
}
|
1995-12-13 03:31:10 +00:00
|
|
|
else
|
|
|
|
checkfiles(cmd.infile, NULL);
|
|
|
|
|
1994-08-07 18:01:39 +00:00
|
|
|
if (cmd.cflag) {
|
1995-12-13 03:31:10 +00:00
|
|
|
c_output(cmd.infile, "-DRPC_XDR", DONT_EXTEND, cmd.outfile);
|
1994-08-07 18:01:39 +00:00
|
|
|
} else if (cmd.hflag) {
|
2005-09-01 19:16:25 +00:00
|
|
|
h_output(cmd.infile, "-DRPC_HDR", DONT_EXTEND, cmd.outfile,
|
|
|
|
cmd.hflag);
|
1994-08-07 18:01:39 +00:00
|
|
|
} else if (cmd.lflag) {
|
1995-12-13 03:31:10 +00:00
|
|
|
l_output(cmd.infile, "-DRPC_CLNT", DONT_EXTEND, cmd.outfile);
|
|
|
|
} else if (cmd.sflag || cmd.mflag || (cmd.nflag)) {
|
|
|
|
s_output(argc, argv, cmd.infile, "-DRPC_SVC", DONT_EXTEND,
|
|
|
|
cmd.outfile, cmd.mflag, cmd.nflag);
|
|
|
|
} else if (cmd.tflag) {
|
|
|
|
t_output(cmd.infile, "-DRPC_TBL", DONT_EXTEND, cmd.outfile);
|
|
|
|
} else if (cmd.Ssflag) {
|
|
|
|
svc_output(cmd.infile, "-DRPC_SERVER", DONT_EXTEND,
|
|
|
|
cmd.outfile);
|
|
|
|
} else if (cmd.Scflag) {
|
|
|
|
clnt_output(cmd.infile, "-DRPC_CLIENT", DONT_EXTEND,
|
|
|
|
cmd.outfile);
|
|
|
|
} else if (cmd.makefileflag) {
|
|
|
|
mkfile_output(&cmd);
|
1994-08-07 18:01:39 +00:00
|
|
|
} else {
|
1995-12-13 03:31:10 +00:00
|
|
|
/* the rescans are required, since cpp may effect input */
|
1994-08-07 18:01:39 +00:00
|
|
|
c_output(cmd.infile, "-DRPC_XDR", EXTEND, "_xdr.c");
|
|
|
|
reinitialize();
|
2005-09-01 19:16:25 +00:00
|
|
|
h_output(cmd.infile, "-DRPC_HDR", EXTEND, ".h", cmd.hflag);
|
1994-08-07 18:01:39 +00:00
|
|
|
reinitialize();
|
|
|
|
l_output(cmd.infile, "-DRPC_CLNT", EXTEND, "_clnt.c");
|
|
|
|
reinitialize();
|
1995-12-13 03:31:10 +00:00
|
|
|
if (inetdflag || !tirpcflag)
|
|
|
|
s_output(allc, allv, cmd.infile, "-DRPC_SVC", EXTEND,
|
|
|
|
"_svc.c", cmd.mflag, cmd.nflag);
|
|
|
|
else
|
|
|
|
s_output(allnc, allnv, cmd.infile, "-DRPC_SVC",
|
|
|
|
EXTEND, "_svc.c", cmd.mflag, cmd.nflag);
|
|
|
|
if (tblflag) {
|
|
|
|
reinitialize();
|
2004-05-02 01:55:23 +00:00
|
|
|
t_output(cmd.infile, "-DRPC_TBL", EXTEND, "_tbl.i");
|
1995-12-13 03:31:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (allfiles) {
|
|
|
|
reinitialize();
|
|
|
|
svc_output(cmd.infile, "-DRPC_SERVER", EXTEND,
|
|
|
|
"_server.c");
|
|
|
|
reinitialize();
|
|
|
|
clnt_output(cmd.infile, "-DRPC_CLIENT", EXTEND,
|
|
|
|
"_client.c");
|
|
|
|
|
|
|
|
}
|
|
|
|
if (allfiles || (cmd.makefileflag == 1)){
|
|
|
|
reinitialize();
|
|
|
|
mkfile_output(&cmd);
|
|
|
|
}
|
|
|
|
|
1994-08-07 18:01:39 +00:00
|
|
|
}
|
1995-12-13 03:31:10 +00:00
|
|
|
exit(nonfatalerrors);
|
|
|
|
/* NOTREACHED */
|
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
|
|
|
* add extension to filename
|
1994-08-07 18:01:39 +00:00
|
|
|
*/
|
|
|
|
static char *
|
2005-11-13 21:17:24 +00:00
|
|
|
extendfile(const char *path, const char *ext)
|
1994-08-07 18:01:39 +00:00
|
|
|
{
|
|
|
|
char *res;
|
2005-11-13 21:17:24 +00:00
|
|
|
const char *p;
|
|
|
|
const char *file;
|
1994-08-07 18:01:39 +00:00
|
|
|
|
2012-01-03 18:51:58 +00:00
|
|
|
if ((file = strrchr(path, '/')) == NULL)
|
1995-03-04 17:47:50 +00:00
|
|
|
file = path;
|
|
|
|
else
|
|
|
|
file++;
|
2002-07-21 12:55:04 +00:00
|
|
|
res = xmalloc(strlen(file) + strlen(ext) + 1);
|
1995-12-13 03:31:10 +00:00
|
|
|
p = strrchr(file, '.');
|
1994-08-07 18:01:39 +00:00
|
|
|
if (p == NULL) {
|
|
|
|
p = file + strlen(file);
|
|
|
|
}
|
|
|
|
(void) strcpy(res, file);
|
|
|
|
(void) strcpy(res + (p - file), ext);
|
|
|
|
return (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1995-05-30 06:41:30 +00:00
|
|
|
* Open output file with given extension
|
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
|
|
|
open_output(const char *infile, const char *outfile)
|
1994-08-07 18:01:39 +00:00
|
|
|
{
|
1995-12-13 03:31:10 +00:00
|
|
|
|
1994-08-07 18:01:39 +00:00
|
|
|
if (outfile == NULL) {
|
|
|
|
fout = stdout;
|
|
|
|
return;
|
|
|
|
}
|
1995-12-13 03:31:10 +00:00
|
|
|
|
1994-08-07 18:01:39 +00:00
|
|
|
if (infile != NULL && streq(outfile, infile)) {
|
1997-08-06 06:47:41 +00:00
|
|
|
warnx("%s already exists. No output generated", infile);
|
1994-08-07 18:01:39 +00:00
|
|
|
crash();
|
|
|
|
}
|
|
|
|
fout = fopen(outfile, "w");
|
|
|
|
if (fout == NULL) {
|
1997-08-06 06:47:41 +00:00
|
|
|
warn("unable to open %s", outfile);
|
1994-08-07 18:01:39 +00:00
|
|
|
crash();
|
|
|
|
}
|
|
|
|
record_open(outfile);
|
1995-12-13 03:31:10 +00:00
|
|
|
|
1996-07-12 19:08:36 +00:00
|
|
|
return;
|
1995-12-13 03:31:10 +00:00
|
|
|
}
|
|
|
|
|
1996-07-12 19:08:36 +00:00
|
|
|
static void
|
2005-11-13 21:17:24 +00:00
|
|
|
add_warning(void)
|
1995-12-13 03:31:10 +00:00
|
|
|
{
|
|
|
|
f_print(fout, "/*\n");
|
|
|
|
f_print(fout, " * Please do not edit this file.\n");
|
|
|
|
f_print(fout, " * It was generated using rpcgen.\n");
|
|
|
|
f_print(fout, " */\n\n");
|
|
|
|
}
|
|
|
|
|
Let rpcgen(1) support an environment variable RPCGEN_CPP to find the C
preprocessor to run. Previously, it always ran /usr/bin/cpp, unless you
used the -Y option, and even then you could not set the basename. It
also attempted to run /usr/ccs/lib/cpp for SVR4 compatibility, but this
is obsolete, and has been removed.
Note that setting RPCGEN_CPP to a command with arguments is supported,
though the command line parsing is simplistic. However, setting it to
e.g. "gcc46 -E" or "clang -E" will lead to problems, because both gcc
and clang in -E mode will consider files with unknown extensions (such
as .x) as object files, and attempt to link them.
This could be worked around by also adding "-x c", but it is much safer
to set RPCGEN_CPP to e.g. "cpp46" or "clang-cpp" instead.
MFC after: 1 week
2012-02-06 12:03:21 +00:00
|
|
|
/* prepend C-preprocessor and flags before arguments */
|
2005-11-13 21:17:24 +00:00
|
|
|
static void
|
Let rpcgen(1) support an environment variable RPCGEN_CPP to find the C
preprocessor to run. Previously, it always ran /usr/bin/cpp, unless you
used the -Y option, and even then you could not set the basename. It
also attempted to run /usr/ccs/lib/cpp for SVR4 compatibility, but this
is obsolete, and has been removed.
Note that setting RPCGEN_CPP to a command with arguments is supported,
though the command line parsing is simplistic. However, setting it to
e.g. "gcc46 -E" or "clang -E" will lead to problems, because both gcc
and clang in -E mode will consider files with unknown extensions (such
as .x) as object files, and attempt to link them.
This could be worked around by also adding "-x c", but it is much safer
to set RPCGEN_CPP to e.g. "cpp46" or "clang-cpp" instead.
MFC after: 1 week
2012-02-06 12:03:21 +00:00
|
|
|
prepend_cpp(void)
|
1995-12-13 03:31:10 +00:00
|
|
|
{
|
Let rpcgen(1) support an environment variable RPCGEN_CPP to find the C
preprocessor to run. Previously, it always ran /usr/bin/cpp, unless you
used the -Y option, and even then you could not set the basename. It
also attempted to run /usr/ccs/lib/cpp for SVR4 compatibility, but this
is obsolete, and has been removed.
Note that setting RPCGEN_CPP to a command with arguments is supported,
though the command line parsing is simplistic. However, setting it to
e.g. "gcc46 -E" or "clang -E" will lead to problems, because both gcc
and clang in -E mode will consider files with unknown extensions (such
as .x) as object files, and attempt to link them.
This could be worked around by also adding "-x c", but it is much safer
to set RPCGEN_CPP to e.g. "cpp46" or "clang-cpp" instead.
MFC after: 1 week
2012-02-06 12:03:21 +00:00
|
|
|
int idx = 1;
|
|
|
|
const char *var;
|
|
|
|
char *dupvar, *s, *t;
|
1995-12-13 03:31:10 +00:00
|
|
|
|
Let rpcgen(1) support an environment variable RPCGEN_CPP to find the C
preprocessor to run. Previously, it always ran /usr/bin/cpp, unless you
used the -Y option, and even then you could not set the basename. It
also attempted to run /usr/ccs/lib/cpp for SVR4 compatibility, but this
is obsolete, and has been removed.
Note that setting RPCGEN_CPP to a command with arguments is supported,
though the command line parsing is simplistic. However, setting it to
e.g. "gcc46 -E" or "clang -E" will lead to problems, because both gcc
and clang in -E mode will consider files with unknown extensions (such
as .x) as object files, and attempt to link them.
This could be worked around by also adding "-x c", but it is much safer
to set RPCGEN_CPP to e.g. "cpp46" or "clang-cpp" instead.
MFC after: 1 week
2012-02-06 12:03:21 +00:00
|
|
|
if (CPP != NULL)
|
|
|
|
insarg(0, CPP);
|
|
|
|
else if ((var = getenv("RPCGEN_CPP")) == NULL)
|
|
|
|
insarg(0, "/usr/bin/cpp");
|
|
|
|
else {
|
|
|
|
/* Parse command line in a rudimentary way */
|
|
|
|
dupvar = xstrdup(var);
|
|
|
|
for (s = dupvar, idx = 0; (t = strsep(&s, " \t")) != NULL; ) {
|
|
|
|
if (t[0])
|
|
|
|
insarg(idx++, t);
|
1995-12-13 03:31:10 +00:00
|
|
|
}
|
Let rpcgen(1) support an environment variable RPCGEN_CPP to find the C
preprocessor to run. Previously, it always ran /usr/bin/cpp, unless you
used the -Y option, and even then you could not set the basename. It
also attempted to run /usr/ccs/lib/cpp for SVR4 compatibility, but this
is obsolete, and has been removed.
Note that setting RPCGEN_CPP to a command with arguments is supported,
though the command line parsing is simplistic. However, setting it to
e.g. "gcc46 -E" or "clang -E" will lead to problems, because both gcc
and clang in -E mode will consider files with unknown extensions (such
as .x) as object files, and attempt to link them.
This could be worked around by also adding "-x c", but it is much safer
to set RPCGEN_CPP to e.g. "cpp46" or "clang-cpp" instead.
MFC after: 1 week
2012-02-06 12:03:21 +00:00
|
|
|
free(dupvar);
|
1995-12-13 03:31:10 +00:00
|
|
|
}
|
Let rpcgen(1) support an environment variable RPCGEN_CPP to find the C
preprocessor to run. Previously, it always ran /usr/bin/cpp, unless you
used the -Y option, and even then you could not set the basename. It
also attempted to run /usr/ccs/lib/cpp for SVR4 compatibility, but this
is obsolete, and has been removed.
Note that setting RPCGEN_CPP to a command with arguments is supported,
though the command line parsing is simplistic. However, setting it to
e.g. "gcc46 -E" or "clang -E" will lead to problems, because both gcc
and clang in -E mode will consider files with unknown extensions (such
as .x) as object files, and attempt to link them.
This could be worked around by also adding "-x c", but it is much safer
to set RPCGEN_CPP to e.g. "cpp46" or "clang-cpp" instead.
MFC after: 1 week
2012-02-06 12:03:21 +00:00
|
|
|
|
|
|
|
insarg(idx, CPPFLAGS);
|
1994-08-07 18:01:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1995-05-30 06:41:30 +00:00
|
|
|
* Open input file with given define for C-preprocessor
|
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
|
|
|
open_input(const char *infile, const char *define)
|
1994-08-07 18:01:39 +00:00
|
|
|
{
|
|
|
|
int pd[2];
|
|
|
|
|
|
|
|
infilename = (infile == NULL) ? "<stdin>" : infile;
|
|
|
|
(void) pipe(pd);
|
1995-12-13 03:31:10 +00:00
|
|
|
switch (childpid = fork()) {
|
1994-08-07 18:01:39 +00:00
|
|
|
case 0:
|
Let rpcgen(1) support an environment variable RPCGEN_CPP to find the C
preprocessor to run. Previously, it always ran /usr/bin/cpp, unless you
used the -Y option, and even then you could not set the basename. It
also attempted to run /usr/ccs/lib/cpp for SVR4 compatibility, but this
is obsolete, and has been removed.
Note that setting RPCGEN_CPP to a command with arguments is supported,
though the command line parsing is simplistic. However, setting it to
e.g. "gcc46 -E" or "clang -E" will lead to problems, because both gcc
and clang in -E mode will consider files with unknown extensions (such
as .x) as object files, and attempt to link them.
This could be worked around by also adding "-x c", but it is much safer
to set RPCGEN_CPP to e.g. "cpp46" or "clang-cpp" instead.
MFC after: 1 week
2012-02-06 12:03:21 +00:00
|
|
|
prepend_cpp();
|
1995-12-13 03:31:10 +00:00
|
|
|
addarg(define);
|
|
|
|
if (infile)
|
|
|
|
addarg(infile);
|
|
|
|
addarg((char *)NULL);
|
1994-08-07 18:01:39 +00:00
|
|
|
(void) close(1);
|
|
|
|
(void) dup2(pd[1], 1);
|
|
|
|
(void) close(pd[0]);
|
2012-02-06 21:35:11 +00:00
|
|
|
execvp(arglist[0], arglist);
|
|
|
|
err(1, "execvp %s", arglist[0]);
|
1994-08-07 18:01:39 +00:00
|
|
|
case -1:
|
2002-07-21 12:55:04 +00:00
|
|
|
err(1, "fork");
|
1994-08-07 18:01:39 +00:00
|
|
|
}
|
|
|
|
(void) close(pd[1]);
|
|
|
|
fin = fdopen(pd[0], "r");
|
|
|
|
if (fin == NULL) {
|
1997-08-06 06:47:41 +00:00
|
|
|
warn("%s", infilename);
|
1994-08-07 18:01:39 +00:00
|
|
|
crash();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1995-12-13 03:31:10 +00:00
|
|
|
/* valid tirpc nettypes */
|
2005-11-13 21:17:24 +00:00
|
|
|
static const char *valid_ti_nettypes[] =
|
1995-12-13 03:31:10 +00:00
|
|
|
{
|
|
|
|
"netpath",
|
|
|
|
"visible",
|
|
|
|
"circuit_v",
|
|
|
|
"datagram_v",
|
|
|
|
"circuit_n",
|
|
|
|
"datagram_n",
|
|
|
|
"udp",
|
|
|
|
"tcp",
|
|
|
|
"raw",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
/* valid inetd nettypes */
|
2005-11-13 21:17:24 +00:00
|
|
|
static const char *valid_i_nettypes[] =
|
1995-12-13 03:31:10 +00:00
|
|
|
{
|
|
|
|
"udp",
|
|
|
|
"tcp",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2005-11-13 21:17:24 +00:00
|
|
|
static int
|
|
|
|
check_nettype(const char *name, const char *list_to_check[])
|
1995-12-13 03:31:10 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; list_to_check[i] != NULL; i++) {
|
|
|
|
if (strcmp(name, list_to_check[i]) == 0) {
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
}
|
1997-08-06 06:47:41 +00:00
|
|
|
warnx("illegal nettype :\'%s\'", name);
|
1995-12-13 03:31:10 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2005-11-13 21:17:24 +00:00
|
|
|
static const char *
|
|
|
|
file_name(const char *file, const char *ext)
|
1995-12-13 03:31:10 +00:00
|
|
|
{
|
|
|
|
char *temp;
|
|
|
|
temp = extendfile(file, ext);
|
|
|
|
|
|
|
|
if (access(temp, F_OK) != -1)
|
|
|
|
return (temp);
|
|
|
|
else
|
2005-11-13 21:17:24 +00:00
|
|
|
return (" ");
|
1995-12-13 03:31:10 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-07-12 19:08:36 +00:00
|
|
|
static void
|
2005-11-13 21:17:24 +00:00
|
|
|
c_output(const char *infile, const char *define, int extend, const char *outfile)
|
1994-08-07 18:01:39 +00:00
|
|
|
{
|
|
|
|
definition *def;
|
|
|
|
char *include;
|
2005-11-13 21:17:24 +00:00
|
|
|
const char *outfilename;
|
1994-08-07 18:01:39 +00:00
|
|
|
long tell;
|
|
|
|
|
1995-12-13 03:31:10 +00:00
|
|
|
c_initialize();
|
1995-05-30 06:41:30 +00:00
|
|
|
open_input(infile, define);
|
1994-08-07 18:01:39 +00:00
|
|
|
outfilename = extend ? extendfile(infile, outfile) : outfile;
|
|
|
|
open_output(infile, outfilename);
|
1995-12-13 03:31:10 +00:00
|
|
|
add_warning();
|
1994-08-07 18:01:39 +00:00
|
|
|
if (infile && (include = extendfile(infile, ".h"))) {
|
|
|
|
f_print(fout, "#include \"%s\"\n", include);
|
|
|
|
free(include);
|
1995-12-13 03:31:10 +00:00
|
|
|
/* .h file already contains rpc/rpc.h */
|
|
|
|
} else
|
|
|
|
f_print(fout, "#include <rpc/rpc.h>\n");
|
1994-08-07 18:01:39 +00:00
|
|
|
tell = ftell(fout);
|
1996-07-12 19:08:36 +00:00
|
|
|
while ( (def = get_definition()) ) {
|
1994-08-07 18:01:39 +00:00
|
|
|
emit(def);
|
|
|
|
}
|
|
|
|
if (extend && tell == ftell(fout)) {
|
|
|
|
(void) unlink(outfilename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1995-12-13 03:31:10 +00:00
|
|
|
|
1996-07-12 19:08:36 +00:00
|
|
|
void
|
2005-11-13 21:17:24 +00:00
|
|
|
c_initialize(void)
|
1995-12-13 03:31:10 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
/* add all the starting basic types */
|
|
|
|
add_type(1, "int");
|
|
|
|
add_type(1, "long");
|
|
|
|
add_type(1, "short");
|
|
|
|
add_type(1, "bool");
|
|
|
|
add_type(1, "u_int");
|
|
|
|
add_type(1, "u_long");
|
|
|
|
add_type(1, "u_short");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-10-19 14:49:42 +00:00
|
|
|
static const char rpcgen_table_dcl[] = "struct rpcgen_table {\n\
|
1995-12-13 03:31:10 +00:00
|
|
|
char *(*proc)(); \n\
|
|
|
|
xdrproc_t xdr_arg; \n\
|
|
|
|
unsigned len_arg; \n\
|
|
|
|
xdrproc_t xdr_res; \n\
|
|
|
|
unsigned len_res; \n\
|
|
|
|
}; \n";
|
|
|
|
|
|
|
|
|
2005-11-13 21:17:24 +00:00
|
|
|
char *
|
|
|
|
generate_guard(const char *pathname)
|
1995-12-13 03:31:10 +00:00
|
|
|
{
|
2005-11-13 21:17:24 +00:00
|
|
|
const char *filename;
|
|
|
|
char *guard, *tmp, *stopat;
|
1995-12-13 03:31:10 +00:00
|
|
|
|
|
|
|
filename = strrchr(pathname, '/'); /* find last component */
|
2016-04-18 06:02:26 +00:00
|
|
|
filename = ((filename == NULL) ? pathname : filename+1);
|
2002-07-21 12:55:04 +00:00
|
|
|
guard = xstrdup(filename);
|
2004-05-02 07:07:54 +00:00
|
|
|
stopat = strrchr(guard, '.');
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert to a valid C macro name and make it upper case.
|
|
|
|
* Map macro unfriendly characterss to '_'.
|
2004-05-02 01:55:23 +00:00
|
|
|
*/
|
2004-05-02 07:07:54 +00:00
|
|
|
for (tmp = guard; *tmp != '\000'; ++tmp) {
|
1995-12-13 03:31:10 +00:00
|
|
|
if (islower(*tmp))
|
|
|
|
*tmp = toupper(*tmp);
|
2004-05-02 07:07:54 +00:00
|
|
|
else if (isupper(*tmp) || *tmp == '_')
|
2004-05-02 01:55:23 +00:00
|
|
|
/* OK for C */;
|
|
|
|
else if (tmp == guard)
|
|
|
|
*tmp = '_';
|
|
|
|
else if (isdigit(*tmp))
|
|
|
|
/* OK for all but first character */;
|
2004-05-02 07:07:54 +00:00
|
|
|
else if (tmp == stopat) {
|
|
|
|
*tmp = '\0';
|
2004-05-02 01:55:23 +00:00
|
|
|
break;
|
|
|
|
} else
|
|
|
|
*tmp = '_';
|
|
|
|
}
|
2004-05-02 07:07:54 +00:00
|
|
|
/*
|
|
|
|
* Can't have a '_' in front, because it'll end up being "__".
|
|
|
|
* "__" macros shoudln't be used. So, remove all of the
|
|
|
|
* '_' characters from the front.
|
2004-05-02 01:55:23 +00:00
|
|
|
*/
|
2004-05-02 07:07:54 +00:00
|
|
|
if (*guard == '_') {
|
|
|
|
for (tmp = guard; *tmp == '_'; ++tmp)
|
|
|
|
;
|
|
|
|
strcpy(guard, tmp);
|
1995-12-13 03:31:10 +00:00
|
|
|
}
|
2017-12-28 05:33:34 +00:00
|
|
|
tmp = guard;
|
1995-12-13 03:31:10 +00:00
|
|
|
guard = extendfile(guard, "_H_RPCGEN");
|
2017-12-28 05:33:34 +00:00
|
|
|
free(tmp);
|
1995-12-13 03:31:10 +00:00
|
|
|
return (guard);
|
|
|
|
}
|
|
|
|
|
1994-08-07 18:01:39 +00:00
|
|
|
/*
|
|
|
|
* Compile into an XDR header file
|
|
|
|
*/
|
1995-12-13 03:31:10 +00:00
|
|
|
|
|
|
|
|
1996-07-12 19:08:36 +00:00
|
|
|
static void
|
2005-11-13 21:17:24 +00:00
|
|
|
h_output(const char *infile, const char *define, int extend, const char *outfile, int headeronly)
|
1994-08-07 18:01:39 +00:00
|
|
|
{
|
|
|
|
definition *def;
|
2005-11-13 21:17:24 +00:00
|
|
|
const char *outfilename;
|
1994-08-07 18:01:39 +00:00
|
|
|
long tell;
|
2005-11-13 21:17:24 +00:00
|
|
|
const char *guard;
|
1995-12-13 03:31:10 +00:00
|
|
|
list *l;
|
|
|
|
xdrfunc *xdrfuncp;
|
2017-12-28 05:33:34 +00:00
|
|
|
void *tmp = NULL;
|
1994-08-07 18:01:39 +00:00
|
|
|
|
|
|
|
open_input(infile, define);
|
|
|
|
outfilename = extend ? extendfile(infile, outfile) : outfile;
|
|
|
|
open_output(infile, outfilename);
|
1995-12-13 03:31:10 +00:00
|
|
|
add_warning();
|
|
|
|
if (outfilename || infile){
|
2017-12-28 05:33:34 +00:00
|
|
|
guard = tmp = generate_guard(outfilename ? outfilename: infile);
|
1995-12-13 03:31:10 +00:00
|
|
|
} else
|
|
|
|
guard = "STDIN_";
|
|
|
|
|
|
|
|
f_print(fout, "#ifndef _%s\n#define _%s\n\n", guard,
|
|
|
|
guard);
|
|
|
|
|
|
|
|
f_print(fout, "#include <rpc/rpc.h>\n");
|
|
|
|
|
2002-07-14 17:54:00 +00:00
|
|
|
if (mtflag)
|
1998-09-25 11:43:48 +00:00
|
|
|
f_print(fout, "#include <pthread.h>\n");
|
1995-12-13 03:31:10 +00:00
|
|
|
|
|
|
|
/* put the C++ support */
|
2005-09-02 10:23:26 +00:00
|
|
|
if (!CCflag) {
|
1995-12-13 03:31:10 +00:00
|
|
|
f_print(fout, "\n#ifdef __cplusplus\n");
|
|
|
|
f_print(fout, "extern \"C\" {\n");
|
|
|
|
f_print(fout, "#endif\n\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* put in a typedef for quadprecision. Only with Cflag */
|
|
|
|
|
1994-08-07 18:01:39 +00:00
|
|
|
tell = ftell(fout);
|
1995-12-13 03:31:10 +00:00
|
|
|
|
|
|
|
/* print data definitions */
|
1996-07-12 19:08:36 +00:00
|
|
|
while ( (def = get_definition()) ) {
|
2005-09-01 19:16:25 +00:00
|
|
|
print_datadef(def, headeronly);
|
1994-08-07 18:01:39 +00:00
|
|
|
}
|
1995-12-13 03:31:10 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* print function declarations.
|
|
|
|
* Do this after data definitions because they might be used as
|
|
|
|
* arguments for functions
|
|
|
|
*/
|
|
|
|
for (l = defined; l != NULL; l = l->next) {
|
2005-09-01 19:16:25 +00:00
|
|
|
print_funcdef(l->val, headeronly);
|
1995-12-13 03:31:10 +00:00
|
|
|
}
|
|
|
|
/* Now print all xdr func declarations */
|
|
|
|
if (xdrfunc_head != NULL){
|
|
|
|
|
|
|
|
f_print(fout,
|
|
|
|
"\n/* the xdr functions */\n");
|
|
|
|
|
|
|
|
if (CCflag){
|
2005-09-02 10:23:26 +00:00
|
|
|
f_print(fout, "\n#ifdef __cplusplus\n");
|
|
|
|
f_print(fout, "extern \"C\" {\n");
|
|
|
|
f_print(fout, "#endif\n");
|
|
|
|
}
|
1995-12-13 03:31:10 +00:00
|
|
|
|
2005-09-02 10:23:26 +00:00
|
|
|
xdrfuncp = xdrfunc_head;
|
|
|
|
while (xdrfuncp != NULL){
|
|
|
|
print_xdr_func_def(xdrfuncp->name, xdrfuncp->pointerp);
|
|
|
|
xdrfuncp = xdrfuncp->next;
|
1995-12-13 03:31:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1994-08-07 18:01:39 +00:00
|
|
|
if (extend && tell == ftell(fout)) {
|
|
|
|
(void) unlink(outfilename);
|
1995-12-13 03:31:10 +00:00
|
|
|
} else if (tblflag) {
|
|
|
|
f_print(fout, rpcgen_table_dcl);
|
1994-08-07 18:01:39 +00:00
|
|
|
}
|
1995-12-13 03:31:10 +00:00
|
|
|
|
2005-09-02 10:23:26 +00:00
|
|
|
f_print(fout, "\n#ifdef __cplusplus\n");
|
|
|
|
f_print(fout, "}\n");
|
|
|
|
f_print(fout, "#endif\n");
|
1995-12-13 03:31:10 +00:00
|
|
|
|
|
|
|
f_print(fout, "\n#endif /* !_%s */\n", guard);
|
2017-12-28 05:33:34 +00:00
|
|
|
free(tmp);
|
1994-08-07 18:01:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Compile into an RPC service
|
|
|
|
*/
|
1996-07-12 19:08:36 +00:00
|
|
|
static void
|
2005-11-13 21:17:24 +00:00
|
|
|
s_output(int argc, const char *argv[], const char *infile, const char *define,
|
|
|
|
int extend, const char *outfile, int nomain, int netflag)
|
1994-08-07 18:01:39 +00:00
|
|
|
{
|
|
|
|
char *include;
|
|
|
|
definition *def;
|
1995-12-13 03:31:10 +00:00
|
|
|
int foundprogram = 0;
|
2005-11-13 21:17:24 +00:00
|
|
|
const char *outfilename;
|
1994-08-07 18:01:39 +00:00
|
|
|
|
|
|
|
open_input(infile, define);
|
|
|
|
outfilename = extend ? extendfile(infile, outfile) : outfile;
|
|
|
|
open_output(infile, outfilename);
|
1995-12-13 03:31:10 +00:00
|
|
|
add_warning();
|
1994-08-07 18:01:39 +00:00
|
|
|
if (infile && (include = extendfile(infile, ".h"))) {
|
|
|
|
f_print(fout, "#include \"%s\"\n", include);
|
|
|
|
free(include);
|
1995-12-13 03:31:10 +00:00
|
|
|
} else
|
|
|
|
f_print(fout, "#include <rpc/rpc.h>\n");
|
|
|
|
|
|
|
|
f_print(fout, "#include <stdio.h>\n");
|
|
|
|
f_print(fout, "#include <stdlib.h> /* getenv, exit */\n");
|
2005-09-02 10:23:26 +00:00
|
|
|
f_print (fout, "#include <rpc/pmap_clnt.h> /* for pmap_unset */\n");
|
|
|
|
f_print (fout, "#include <string.h> /* strcmp */\n");
|
2003-01-16 07:27:30 +00:00
|
|
|
if (tirpcflag)
|
|
|
|
f_print(fout, "#include <rpc/rpc_com.h>\n");
|
1995-12-13 03:31:10 +00:00
|
|
|
if (strcmp(svcclosetime, "-1") == 0)
|
|
|
|
indefinitewait = 1;
|
|
|
|
else if (strcmp(svcclosetime, "0") == 0)
|
|
|
|
exitnow = 1;
|
|
|
|
else if (inetdflag || pmflag) {
|
|
|
|
f_print(fout, "#include <signal.h>\n");
|
|
|
|
timerflag = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!tirpcflag && inetdflag)
|
|
|
|
f_print(fout, "#include <sys/ttycom.h> /* TIOCNOTTY */\n");
|
2005-09-02 10:23:26 +00:00
|
|
|
if (inetdflag || pmflag) {
|
1995-12-13 03:31:10 +00:00
|
|
|
f_print(fout, "#ifdef __cplusplus\n");
|
|
|
|
f_print(fout,
|
2007-08-23 09:38:26 +00:00
|
|
|
"#include <sys/sysent.h> /* getdtablesize, open */\n");
|
1995-12-13 03:31:10 +00:00
|
|
|
f_print(fout, "#endif /* __cplusplus */\n");
|
|
|
|
}
|
2002-07-14 17:54:00 +00:00
|
|
|
if (tirpcflag) {
|
|
|
|
f_print(fout, "#include <fcntl.h> /* open */\n");
|
|
|
|
f_print(fout, "#include <unistd.h> /* fork / setsid */\n");
|
1995-12-13 03:31:10 +00:00
|
|
|
f_print(fout, "#include <sys/types.h>\n");
|
2002-07-14 17:54:00 +00:00
|
|
|
}
|
1995-12-13 03:31:10 +00:00
|
|
|
|
2005-02-10 08:12:38 +00:00
|
|
|
f_print(fout, "#include <string.h>\n");
|
1995-12-13 03:31:10 +00:00
|
|
|
if (inetdflag || !tirpcflag) {
|
|
|
|
f_print(fout, "#include <sys/socket.h>\n");
|
|
|
|
f_print(fout, "#include <netinet/in.h>\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((netflag || pmflag) && tirpcflag && !nomain) {
|
|
|
|
f_print(fout, "#include <netconfig.h>\n");
|
1994-08-07 18:01:39 +00:00
|
|
|
}
|
1995-12-13 03:31:10 +00:00
|
|
|
if (tirpcflag)
|
|
|
|
f_print(fout, "#include <sys/resource.h> /* rlimit */\n");
|
2002-07-14 17:54:00 +00:00
|
|
|
if (logflag || inetdflag || pmflag || tirpcflag)
|
1995-12-13 03:31:10 +00:00
|
|
|
f_print(fout, "#include <syslog.h>\n");
|
|
|
|
|
|
|
|
f_print(fout, "\n#ifdef DEBUG\n#define RPC_SVC_FG\n#endif\n");
|
|
|
|
if (timerflag)
|
|
|
|
f_print(fout, "\n#define _RPCSVC_CLOSEDOWN %s\n",
|
|
|
|
svcclosetime);
|
1996-07-12 19:08:36 +00:00
|
|
|
while ( (def = get_definition()) ) {
|
1994-08-07 18:01:39 +00:00
|
|
|
foundprogram |= (def->def_kind == DEF_PROGRAM);
|
|
|
|
}
|
|
|
|
if (extend && !foundprogram) {
|
|
|
|
(void) unlink(outfilename);
|
|
|
|
return;
|
|
|
|
}
|
1995-12-13 03:31:10 +00:00
|
|
|
write_most(infile, netflag, nomain);
|
|
|
|
if (!nomain) {
|
|
|
|
if (!do_registers(argc, argv)) {
|
|
|
|
if (outfilename)
|
|
|
|
(void) unlink(outfilename);
|
|
|
|
usage();
|
|
|
|
}
|
1994-08-07 18:01:39 +00:00
|
|
|
write_rest();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1995-12-13 03:31:10 +00:00
|
|
|
/*
|
|
|
|
* generate client side stubs
|
|
|
|
*/
|
1996-07-12 19:08:36 +00:00
|
|
|
static void
|
2005-11-13 21:17:24 +00:00
|
|
|
l_output(const char *infile, const char *define, int extend, const char *outfile)
|
1994-08-07 18:01:39 +00:00
|
|
|
{
|
|
|
|
char *include;
|
|
|
|
definition *def;
|
1995-12-13 03:31:10 +00:00
|
|
|
int foundprogram = 0;
|
2005-11-13 21:17:24 +00:00
|
|
|
const char *outfilename;
|
1994-08-07 18:01:39 +00:00
|
|
|
|
|
|
|
open_input(infile, define);
|
|
|
|
outfilename = extend ? extendfile(infile, outfile) : outfile;
|
|
|
|
open_output(infile, outfilename);
|
1995-12-13 03:31:10 +00:00
|
|
|
add_warning();
|
2005-09-02 10:23:26 +00:00
|
|
|
f_print (fout, "#include <string.h> /* for memset */\n");
|
1994-08-07 18:01:39 +00:00
|
|
|
if (infile && (include = extendfile(infile, ".h"))) {
|
|
|
|
f_print(fout, "#include \"%s\"\n", include);
|
|
|
|
free(include);
|
1995-12-13 03:31:10 +00:00
|
|
|
} else
|
|
|
|
f_print(fout, "#include <rpc/rpc.h>\n");
|
1996-07-12 19:08:36 +00:00
|
|
|
while ( (def = get_definition()) ) {
|
1994-08-07 18:01:39 +00:00
|
|
|
foundprogram |= (def->def_kind == DEF_PROGRAM);
|
|
|
|
}
|
|
|
|
if (extend && !foundprogram) {
|
|
|
|
(void) unlink(outfilename);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
write_stubs();
|
|
|
|
}
|
|
|
|
|
1995-12-13 03:31:10 +00:00
|
|
|
/*
|
|
|
|
* generate the dispatch table
|
|
|
|
*/
|
1996-07-12 19:08:36 +00:00
|
|
|
static void
|
2005-11-13 21:17:24 +00:00
|
|
|
t_output(const char *infile, const char *define, int extend, const char *outfile)
|
1995-12-13 03:31:10 +00:00
|
|
|
{
|
|
|
|
definition *def;
|
|
|
|
int foundprogram = 0;
|
2005-11-13 21:17:24 +00:00
|
|
|
const char *outfilename;
|
1995-12-13 03:31:10 +00:00
|
|
|
|
|
|
|
open_input(infile, define);
|
|
|
|
outfilename = extend ? extendfile(infile, outfile) : outfile;
|
|
|
|
open_output(infile, outfilename);
|
|
|
|
add_warning();
|
1996-07-12 19:08:36 +00:00
|
|
|
while ( (def = get_definition()) ) {
|
1995-12-13 03:31:10 +00:00
|
|
|
foundprogram |= (def->def_kind == DEF_PROGRAM);
|
|
|
|
}
|
|
|
|
if (extend && !foundprogram) {
|
|
|
|
(void) unlink(outfilename);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
write_tables();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* sample routine for the server template */
|
1996-07-12 19:08:36 +00:00
|
|
|
static void
|
2005-11-13 21:17:24 +00:00
|
|
|
svc_output(const char *infile, const char *define, int extend, const char *outfile)
|
1995-12-13 03:31:10 +00:00
|
|
|
{
|
|
|
|
definition *def;
|
|
|
|
char *include;
|
2005-11-13 21:17:24 +00:00
|
|
|
const char *outfilename;
|
1995-12-13 03:31:10 +00:00
|
|
|
long tell;
|
|
|
|
open_input(infile, define);
|
|
|
|
outfilename = extend ? extendfile(infile, outfile) : outfile;
|
|
|
|
checkfiles(infile, outfilename);
|
|
|
|
/*
|
|
|
|
* Check if outfile already exists.
|
|
|
|
* if so, print an error message and exit
|
|
|
|
*/
|
|
|
|
open_output(infile, outfilename);
|
|
|
|
add_sample_msg();
|
|
|
|
|
|
|
|
if (infile && (include = extendfile(infile, ".h"))) {
|
|
|
|
f_print(fout, "#include \"%s\"\n", include);
|
|
|
|
free(include);
|
|
|
|
} else
|
|
|
|
f_print(fout, "#include <rpc/rpc.h>\n");
|
|
|
|
|
|
|
|
tell = ftell(fout);
|
1996-07-12 19:08:36 +00:00
|
|
|
while ( (def = get_definition()) ) {
|
1995-12-13 03:31:10 +00:00
|
|
|
write_sample_svc(def);
|
|
|
|
}
|
|
|
|
if (extend && tell == ftell(fout)) {
|
|
|
|
(void) unlink(outfilename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* sample main routine for client */
|
1996-07-12 19:08:36 +00:00
|
|
|
static void
|
2005-11-13 21:17:24 +00:00
|
|
|
clnt_output(const char *infile, const char *define, int extend, const char *outfile)
|
1995-12-13 03:31:10 +00:00
|
|
|
{
|
|
|
|
definition *def;
|
|
|
|
char *include;
|
2005-11-13 21:17:24 +00:00
|
|
|
const char *outfilename;
|
1995-12-13 03:31:10 +00:00
|
|
|
long tell;
|
|
|
|
int has_program = 0;
|
|
|
|
|
|
|
|
open_input(infile, define);
|
|
|
|
outfilename = extend ? extendfile(infile, outfile) : outfile;
|
|
|
|
checkfiles(infile, outfilename);
|
|
|
|
/*
|
|
|
|
* Check if outfile already exists.
|
|
|
|
* if so, print an error message and exit
|
|
|
|
*/
|
|
|
|
|
|
|
|
open_output(infile, outfilename);
|
|
|
|
add_sample_msg();
|
|
|
|
if (infile && (include = extendfile(infile, ".h"))) {
|
|
|
|
f_print(fout, "#include \"%s\"\n", include);
|
|
|
|
free(include);
|
|
|
|
} else
|
|
|
|
f_print(fout, "#include <rpc/rpc.h>\n");
|
2013-12-26 11:38:33 +00:00
|
|
|
f_print(fout, "#include <stdio.h>\n");
|
|
|
|
f_print(fout, "#include <stdlib.h>\n");
|
1995-12-13 03:31:10 +00:00
|
|
|
tell = ftell(fout);
|
1996-07-12 19:08:36 +00:00
|
|
|
while ( (def = get_definition()) ) {
|
1995-12-13 03:31:10 +00:00
|
|
|
has_program += write_sample_clnt(def);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (has_program)
|
|
|
|
write_sample_clnt_main();
|
|
|
|
|
|
|
|
if (extend && tell == ftell(fout)) {
|
|
|
|
(void) unlink(outfilename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-13 21:17:24 +00:00
|
|
|
static void mkfile_output(struct commandline *cmd)
|
1995-12-13 03:31:10 +00:00
|
|
|
{
|
2005-11-13 21:17:24 +00:00
|
|
|
const char *mkfilename, *clientname, *clntname, *xdrname, *hdrname;
|
|
|
|
const char *servername, *svcname, *servprogname, *clntprogname;
|
|
|
|
char *temp, *mkftemp;
|
1995-12-13 03:31:10 +00:00
|
|
|
|
|
|
|
svcname = file_name(cmd->infile, "_svc.c");
|
|
|
|
clntname = file_name(cmd->infile, "_clnt.c");
|
|
|
|
xdrname = file_name(cmd->infile, "_xdr.c");
|
|
|
|
hdrname = file_name(cmd->infile, ".h");
|
|
|
|
|
|
|
|
|
|
|
|
if (allfiles){
|
|
|
|
servername = extendfile(cmd->infile, "_server.c");
|
|
|
|
clientname = extendfile(cmd->infile, "_client.c");
|
|
|
|
}else{
|
|
|
|
servername = " ";
|
|
|
|
clientname = " ";
|
|
|
|
}
|
|
|
|
servprogname = extendfile(cmd->infile, "_server");
|
|
|
|
clntprogname = extendfile(cmd->infile, "_client");
|
|
|
|
|
|
|
|
if (allfiles){
|
2005-11-13 21:17:24 +00:00
|
|
|
mkftemp = xmalloc(strlen("makefile.") +
|
2002-07-21 12:55:04 +00:00
|
|
|
strlen(cmd->infile) + 1);
|
2012-01-03 18:51:58 +00:00
|
|
|
temp = strrchr(cmd->infile, '.');
|
2005-11-13 21:17:24 +00:00
|
|
|
strcpy(mkftemp, "makefile.");
|
|
|
|
(void) strncat(mkftemp, cmd->infile,
|
1995-12-13 03:31:10 +00:00
|
|
|
(temp - cmd->infile));
|
2005-11-13 21:17:24 +00:00
|
|
|
mkfilename = mkftemp;
|
1995-12-13 03:31:10 +00:00
|
|
|
} else
|
|
|
|
mkfilename = cmd->outfile;
|
|
|
|
|
|
|
|
|
|
|
|
checkfiles(NULL, mkfilename);
|
|
|
|
open_output(NULL, mkfilename);
|
|
|
|
|
|
|
|
f_print(fout, "\n# This is a template makefile generated\
|
|
|
|
by rpcgen \n");
|
|
|
|
|
|
|
|
f_print(fout, "\n# Parameters \n\n");
|
|
|
|
|
|
|
|
f_print(fout, "CLIENT = %s\nSERVER = %s\n\n",
|
|
|
|
clntprogname, servprogname);
|
|
|
|
f_print(fout, "SOURCES_CLNT.c = \nSOURCES_CLNT.h = \n");
|
|
|
|
f_print(fout, "SOURCES_SVC.c = \nSOURCES_SVC.h = \n");
|
|
|
|
f_print(fout, "SOURCES.x = %s\n\n", cmd->infile);
|
|
|
|
f_print(fout, "TARGETS_SVC.c = %s %s %s \n",
|
|
|
|
svcname, servername, xdrname);
|
|
|
|
f_print(fout, "TARGETS_CLNT.c = %s %s %s \n",
|
|
|
|
clntname, clientname, xdrname);
|
|
|
|
f_print(fout, "TARGETS = %s %s %s %s %s %s\n\n",
|
|
|
|
hdrname, xdrname, clntname,
|
|
|
|
svcname, clientname, servername);
|
|
|
|
|
|
|
|
f_print(fout, "OBJECTS_CLNT = $(SOURCES_CLNT.c:%%.c=%%.o) \
|
|
|
|
$(TARGETS_CLNT.c:%%.c=%%.o) ");
|
|
|
|
|
|
|
|
f_print(fout, "\nOBJECTS_SVC = $(SOURCES_SVC.c:%%.c=%%.o) \
|
|
|
|
$(TARGETS_SVC.c:%%.c=%%.o) ");
|
|
|
|
|
|
|
|
|
|
|
|
f_print(fout, "\n# Compiler flags \n");
|
|
|
|
if (mtflag)
|
2002-07-14 17:54:00 +00:00
|
|
|
f_print(fout, "\nCFLAGS += -D_REENTRANT -D_THEAD_SAFE \nLDLIBS += -pthread\n");
|
|
|
|
|
1995-12-13 03:31:10 +00:00
|
|
|
f_print(fout, "RPCGENFLAGS = \n");
|
|
|
|
|
|
|
|
f_print(fout, "\n# Targets \n\n");
|
|
|
|
|
|
|
|
f_print(fout, "all : $(CLIENT) $(SERVER)\n\n");
|
|
|
|
f_print(fout, "$(TARGETS) : $(SOURCES.x) \n");
|
|
|
|
f_print(fout, "\trpcgen $(RPCGENFLAGS) $(SOURCES.x)\n\n");
|
2013-12-26 11:38:33 +00:00
|
|
|
if (allfiles) {
|
|
|
|
f_print(fout, "\trpcgen -Sc $(RPCGENFLAGS) $(SOURCES.x) -o %s\n\n", clientname);
|
|
|
|
f_print(fout, "\trpcgen -Ss $(RPCGENFLAGS) $(SOURCES.x) -o %s\n\n", servername);
|
|
|
|
}
|
1995-12-13 03:31:10 +00:00
|
|
|
f_print(fout, "$(OBJECTS_CLNT) : $(SOURCES_CLNT.c) $(SOURCES_CLNT.h) \
|
|
|
|
$(TARGETS_CLNT.c) \n\n");
|
|
|
|
|
|
|
|
f_print(fout, "$(OBJECTS_SVC) : $(SOURCES_SVC.c) $(SOURCES_SVC.h) \
|
|
|
|
$(TARGETS_SVC.c) \n\n");
|
|
|
|
f_print(fout, "$(CLIENT) : $(OBJECTS_CLNT) \n");
|
|
|
|
f_print(fout, "\t$(CC) -o $(CLIENT) $(OBJECTS_CLNT) \
|
|
|
|
$(LDLIBS) \n\n");
|
|
|
|
f_print(fout, "$(SERVER) : $(OBJECTS_SVC) \n");
|
2014-06-06 17:38:37 +00:00
|
|
|
f_print(fout, "\t$(CC) -o $(SERVER) $(OBJECTS_SVC) $(LDLIBS)\n\n");
|
|
|
|
f_print(fout, "clean:\n\t rm -f core $(TARGETS) $(OBJECTS_CLNT) \
|
1995-12-13 03:31:10 +00:00
|
|
|
$(OBJECTS_SVC) $(CLIENT) $(SERVER)\n\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1994-08-07 18:01:39 +00:00
|
|
|
/*
|
1995-05-30 06:41:30 +00:00
|
|
|
* Perform registrations for service output
|
1995-12-13 03:31:10 +00:00
|
|
|
* Return 0 if failed; 1 otherwise.
|
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
|
|
|
do_registers(int argc, const char *argv[])
|
1994-08-07 18:01:39 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
1995-12-13 03:31:10 +00:00
|
|
|
if (inetdflag || !tirpcflag) {
|
|
|
|
for (i = 1; i < argc; i++) {
|
|
|
|
if (streq(argv[i], "-s")) {
|
|
|
|
if (!check_nettype(argv[i + 1],
|
|
|
|
valid_i_nettypes))
|
|
|
|
return (0);
|
|
|
|
write_inetd_register(argv[i + 1]);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (i = 1; i < argc; i++)
|
|
|
|
if (streq(argv[i], "-s")) {
|
|
|
|
if (!check_nettype(argv[i + 1],
|
|
|
|
valid_ti_nettypes))
|
|
|
|
return (0);
|
|
|
|
write_nettype_register(argv[i + 1]);
|
|
|
|
i++;
|
|
|
|
} else if (streq(argv[i], "-n")) {
|
|
|
|
write_netid_register(argv[i + 1]);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2019-10-15 16:05:17 +00:00
|
|
|
* Extend the argument list
|
1995-12-13 03:31:10 +00:00
|
|
|
*/
|
|
|
|
static void
|
2019-10-15 16:05:17 +00:00
|
|
|
moreargs(void)
|
1995-12-13 03:31:10 +00:00
|
|
|
{
|
2019-10-15 16:05:17 +00:00
|
|
|
char **newarglist;
|
|
|
|
|
|
|
|
argmax = argmax == 0 ? 32 : argmax << 1;
|
|
|
|
if (argmax > INT_MAX / 4) {
|
|
|
|
warnx("refusing to allocate too many arguments");
|
|
|
|
crash();
|
|
|
|
}
|
|
|
|
newarglist = realloc(arglist, argmax * sizeof(*arglist));
|
|
|
|
if (newarglist == NULL) {
|
|
|
|
warnx("unable to allocate arglist");
|
1995-12-13 03:31:10 +00:00
|
|
|
crash();
|
|
|
|
}
|
2019-10-15 16:05:17 +00:00
|
|
|
free(arglist);
|
|
|
|
arglist = newarglist;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add another argument to the arg list
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
addarg(const char *cp)
|
|
|
|
{
|
|
|
|
if (argcount >= argmax)
|
|
|
|
moreargs();
|
|
|
|
|
2005-11-14 13:35:08 +00:00
|
|
|
if (cp != NULL)
|
|
|
|
arglist[argcount++] = xstrdup(cp);
|
|
|
|
else
|
|
|
|
arglist[argcount++] = NULL;
|
1995-12-13 03:31:10 +00:00
|
|
|
}
|
|
|
|
|
Let rpcgen(1) support an environment variable RPCGEN_CPP to find the C
preprocessor to run. Previously, it always ran /usr/bin/cpp, unless you
used the -Y option, and even then you could not set the basename. It
also attempted to run /usr/ccs/lib/cpp for SVR4 compatibility, but this
is obsolete, and has been removed.
Note that setting RPCGEN_CPP to a command with arguments is supported,
though the command line parsing is simplistic. However, setting it to
e.g. "gcc46 -E" or "clang -E" will lead to problems, because both gcc
and clang in -E mode will consider files with unknown extensions (such
as .x) as object files, and attempt to link them.
This could be worked around by also adding "-x c", but it is much safer
to set RPCGEN_CPP to e.g. "cpp46" or "clang-cpp" instead.
MFC after: 1 week
2012-02-06 12:03:21 +00:00
|
|
|
/*
|
|
|
|
* Insert an argument at the specified location
|
|
|
|
*/
|
1995-12-13 03:31:10 +00:00
|
|
|
static void
|
Let rpcgen(1) support an environment variable RPCGEN_CPP to find the C
preprocessor to run. Previously, it always ran /usr/bin/cpp, unless you
used the -Y option, and even then you could not set the basename. It
also attempted to run /usr/ccs/lib/cpp for SVR4 compatibility, but this
is obsolete, and has been removed.
Note that setting RPCGEN_CPP to a command with arguments is supported,
though the command line parsing is simplistic. However, setting it to
e.g. "gcc46 -E" or "clang -E" will lead to problems, because both gcc
and clang in -E mode will consider files with unknown extensions (such
as .x) as object files, and attempt to link them.
This could be worked around by also adding "-x c", but it is much safer
to set RPCGEN_CPP to e.g. "cpp46" or "clang-cpp" instead.
MFC after: 1 week
2012-02-06 12:03:21 +00:00
|
|
|
insarg(int place, const char *cp)
|
1995-12-13 03:31:10 +00:00
|
|
|
{
|
Let rpcgen(1) support an environment variable RPCGEN_CPP to find the C
preprocessor to run. Previously, it always ran /usr/bin/cpp, unless you
used the -Y option, and even then you could not set the basename. It
also attempted to run /usr/ccs/lib/cpp for SVR4 compatibility, but this
is obsolete, and has been removed.
Note that setting RPCGEN_CPP to a command with arguments is supported,
though the command line parsing is simplistic. However, setting it to
e.g. "gcc46 -E" or "clang -E" will lead to problems, because both gcc
and clang in -E mode will consider files with unknown extensions (such
as .x) as object files, and attempt to link them.
This could be worked around by also adding "-x c", but it is much safer
to set RPCGEN_CPP to e.g. "cpp46" or "clang-cpp" instead.
MFC after: 1 week
2012-02-06 12:03:21 +00:00
|
|
|
int i;
|
|
|
|
|
2019-10-15 16:05:17 +00:00
|
|
|
if (argcount >= argmax)
|
|
|
|
moreargs();
|
Let rpcgen(1) support an environment variable RPCGEN_CPP to find the C
preprocessor to run. Previously, it always ran /usr/bin/cpp, unless you
used the -Y option, and even then you could not set the basename. It
also attempted to run /usr/ccs/lib/cpp for SVR4 compatibility, but this
is obsolete, and has been removed.
Note that setting RPCGEN_CPP to a command with arguments is supported,
though the command line parsing is simplistic. However, setting it to
e.g. "gcc46 -E" or "clang -E" will lead to problems, because both gcc
and clang in -E mode will consider files with unknown extensions (such
as .x) as object files, and attempt to link them.
This could be worked around by also adding "-x c", but it is much safer
to set RPCGEN_CPP to e.g. "cpp46" or "clang-cpp" instead.
MFC after: 1 week
2012-02-06 12:03:21 +00:00
|
|
|
|
|
|
|
/* Move up existing arguments */
|
2012-02-06 12:08:41 +00:00
|
|
|
for (i = argcount - 1; i >= place; i--)
|
Let rpcgen(1) support an environment variable RPCGEN_CPP to find the C
preprocessor to run. Previously, it always ran /usr/bin/cpp, unless you
used the -Y option, and even then you could not set the basename. It
also attempted to run /usr/ccs/lib/cpp for SVR4 compatibility, but this
is obsolete, and has been removed.
Note that setting RPCGEN_CPP to a command with arguments is supported,
though the command line parsing is simplistic. However, setting it to
e.g. "gcc46 -E" or "clang -E" will lead to problems, because both gcc
and clang in -E mode will consider files with unknown extensions (such
as .x) as object files, and attempt to link them.
This could be worked around by also adding "-x c", but it is much safer
to set RPCGEN_CPP to e.g. "cpp46" or "clang-cpp" instead.
MFC after: 1 week
2012-02-06 12:03:21 +00:00
|
|
|
arglist[i + 1] = arglist[i];
|
|
|
|
|
|
|
|
arglist[place] = xstrdup(cp);
|
|
|
|
argcount++;
|
1995-12-13 03:31:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* if input file is stdin and an output file is specified then complain
|
|
|
|
* if the file already exists. Otherwise the file may get overwritten
|
|
|
|
* If input file does not exist, exit with an error
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
2005-11-13 21:17:24 +00:00
|
|
|
checkfiles(const char *infile, const char *outfile)
|
1995-12-13 03:31:10 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
struct stat buf;
|
|
|
|
|
|
|
|
if (infile) /* infile ! = NULL */
|
|
|
|
if (stat(infile, &buf) < 0)
|
|
|
|
{
|
1997-08-06 06:47:41 +00:00
|
|
|
warn("%s", infile);
|
1995-12-13 03:31:10 +00:00
|
|
|
crash();
|
2016-04-15 22:31:22 +00:00
|
|
|
}
|
1995-12-13 03:31:10 +00:00
|
|
|
if (outfile) {
|
|
|
|
if (stat(outfile, &buf) < 0)
|
|
|
|
return; /* file does not exist */
|
|
|
|
else {
|
1997-08-06 06:47:41 +00:00
|
|
|
warnx("file '%s' already exists and may be overwritten", outfile);
|
1995-12-13 03:31:10 +00:00
|
|
|
crash();
|
1994-08-07 18:01:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1995-05-30 06:41:30 +00:00
|
|
|
* Parse command line arguments
|
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
|
|
|
parseargs(int argc, const char *argv[], struct commandline *cmd)
|
1994-08-07 18:01:39 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int j;
|
1995-12-13 03:31:10 +00:00
|
|
|
char c, ch;
|
|
|
|
char flag[(1 << 8 * sizeof (char))];
|
1994-08-07 18:01:39 +00:00
|
|
|
int nflags;
|
|
|
|
|
|
|
|
cmd->infile = cmd->outfile = NULL;
|
|
|
|
if (argc < 2) {
|
|
|
|
return (0);
|
|
|
|
}
|
1995-12-13 03:31:10 +00:00
|
|
|
allfiles = 0;
|
1994-08-07 18:01:39 +00:00
|
|
|
flag['c'] = 0;
|
|
|
|
flag['h'] = 0;
|
|
|
|
flag['l'] = 0;
|
|
|
|
flag['m'] = 0;
|
1995-12-13 03:31:10 +00:00
|
|
|
flag['o'] = 0;
|
|
|
|
flag['s'] = 0;
|
|
|
|
flag['n'] = 0;
|
|
|
|
flag['t'] = 0;
|
|
|
|
flag['S'] = 0;
|
|
|
|
flag['C'] = 0;
|
|
|
|
flag['M'] = 0;
|
|
|
|
|
1994-08-07 18:01:39 +00:00
|
|
|
for (i = 1; i < argc; i++) {
|
|
|
|
if (argv[i][0] != '-') {
|
|
|
|
if (cmd->infile) {
|
1997-08-06 06:47:41 +00:00
|
|
|
warnx("cannot specify more than one input file");
|
1994-08-07 18:01:39 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
cmd->infile = argv[i];
|
|
|
|
} else {
|
|
|
|
for (j = 1; argv[i][j] != 0; j++) {
|
|
|
|
c = argv[i][j];
|
|
|
|
switch (c) {
|
1995-12-13 03:31:10 +00:00
|
|
|
case 'a':
|
|
|
|
allfiles = 1;
|
|
|
|
break;
|
1994-08-07 18:01:39 +00:00
|
|
|
case 'c':
|
|
|
|
case 'h':
|
|
|
|
case 'l':
|
|
|
|
case 'm':
|
1995-12-13 03:31:10 +00:00
|
|
|
case 't':
|
1996-07-12 19:08:36 +00:00
|
|
|
if (flag[(int)c]) {
|
1994-08-07 18:01:39 +00:00
|
|
|
return (0);
|
|
|
|
}
|
1996-07-12 19:08:36 +00:00
|
|
|
flag[(int)c] = 1;
|
1994-08-07 18:01:39 +00:00
|
|
|
break;
|
1995-12-13 03:31:10 +00:00
|
|
|
case 'S':
|
|
|
|
/*
|
|
|
|
* sample flag: Ss or Sc.
|
|
|
|
* Ss means set flag['S'];
|
|
|
|
* Sc means set flag['C'];
|
|
|
|
* Sm means set flag['M'];
|
|
|
|
*/
|
|
|
|
ch = argv[i][++j]; /* get next char */
|
|
|
|
if (ch == 's')
|
|
|
|
ch = 'S';
|
|
|
|
else if (ch == 'c')
|
|
|
|
ch = 'C';
|
|
|
|
else if (ch == 'm')
|
|
|
|
ch = 'M';
|
|
|
|
else
|
|
|
|
return (0);
|
|
|
|
|
1996-07-12 19:08:36 +00:00
|
|
|
if (flag[(int)ch]) {
|
1995-12-13 03:31:10 +00:00
|
|
|
return (0);
|
|
|
|
}
|
1996-07-12 19:08:36 +00:00
|
|
|
flag[(int)ch] = 1;
|
1995-12-13 03:31:10 +00:00
|
|
|
break;
|
|
|
|
case 'C': /* ANSI C syntax */
|
|
|
|
ch = argv[i][j+1]; /* get next char */
|
|
|
|
|
|
|
|
if (ch != 'C')
|
|
|
|
break;
|
|
|
|
CCflag = 1;
|
|
|
|
break;
|
|
|
|
case 'b':
|
|
|
|
/*
|
|
|
|
* Turn TIRPC flag off for
|
|
|
|
* generating backward compatible
|
|
|
|
* code
|
|
|
|
*/
|
|
|
|
tirpcflag = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'I':
|
|
|
|
inetdflag = 1;
|
|
|
|
break;
|
|
|
|
case 'N':
|
|
|
|
newstyle = 1;
|
|
|
|
break;
|
|
|
|
case 'L':
|
|
|
|
logflag = 1;
|
|
|
|
break;
|
2002-07-14 17:54:00 +00:00
|
|
|
case 'P':
|
|
|
|
pmflag = 1;
|
|
|
|
break;
|
1995-12-13 03:31:10 +00:00
|
|
|
case 'K':
|
|
|
|
if (++i == argc) {
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
svcclosetime = argv[i];
|
|
|
|
goto nextarg;
|
|
|
|
case 'T':
|
|
|
|
tblflag = 1;
|
|
|
|
break;
|
|
|
|
case 'M':
|
|
|
|
mtflag = 1;
|
|
|
|
break;
|
|
|
|
case 'i' :
|
|
|
|
if (++i == argc) {
|
|
|
|
return (0);
|
|
|
|
}
|
2005-08-31 19:44:40 +00:00
|
|
|
inline_size = atoi(argv[i]);
|
1995-12-13 03:31:10 +00:00
|
|
|
goto nextarg;
|
|
|
|
case 'n':
|
1994-08-07 18:01:39 +00:00
|
|
|
case 'o':
|
|
|
|
case 's':
|
1995-05-30 06:41:30 +00:00
|
|
|
if (argv[i][j - 1] != '-' ||
|
1994-08-07 18:01:39 +00:00
|
|
|
argv[i][j + 1] != 0) {
|
|
|
|
return (0);
|
|
|
|
}
|
1996-07-12 19:08:36 +00:00
|
|
|
flag[(int)c] = 1;
|
1994-08-07 18:01:39 +00:00
|
|
|
if (++i == argc) {
|
|
|
|
return (0);
|
|
|
|
}
|
1995-12-13 03:31:10 +00:00
|
|
|
if (c == 'o') {
|
1994-08-07 18:01:39 +00:00
|
|
|
if (cmd->outfile) {
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
cmd->outfile = argv[i];
|
|
|
|
}
|
|
|
|
goto nextarg;
|
1995-12-13 03:31:10 +00:00
|
|
|
case 'D':
|
|
|
|
if (argv[i][j - 1] != '-') {
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
(void) addarg(argv[i]);
|
|
|
|
goto nextarg;
|
|
|
|
case 'Y':
|
|
|
|
if (++i == argc) {
|
|
|
|
return (0);
|
|
|
|
}
|
2012-02-05 20:55:38 +00:00
|
|
|
if (strlcpy(pathbuf, argv[i],
|
|
|
|
sizeof(pathbuf)) >= sizeof(pathbuf)
|
|
|
|
|| strlcat(pathbuf, "/cpp",
|
|
|
|
sizeof(pathbuf)) >=
|
|
|
|
sizeof(pathbuf)) {
|
2001-08-20 09:43:04 +00:00
|
|
|
warnx("argument too long");
|
|
|
|
return (0);
|
|
|
|
}
|
1995-12-13 03:31:10 +00:00
|
|
|
CPP = pathbuf;
|
|
|
|
goto nextarg;
|
|
|
|
|
|
|
|
|
1994-08-07 18:01:39 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
1995-12-13 03:31:10 +00:00
|
|
|
nextarg:
|
1994-08-07 18:01:39 +00:00
|
|
|
;
|
|
|
|
}
|
|
|
|
}
|
1995-12-13 03:31:10 +00:00
|
|
|
|
1994-08-07 18:01:39 +00:00
|
|
|
cmd->cflag = flag['c'];
|
|
|
|
cmd->hflag = flag['h'];
|
|
|
|
cmd->lflag = flag['l'];
|
|
|
|
cmd->mflag = flag['m'];
|
1995-12-13 03:31:10 +00:00
|
|
|
cmd->nflag = flag['n'];
|
|
|
|
cmd->sflag = flag['s'];
|
|
|
|
cmd->tflag = flag['t'];
|
|
|
|
cmd->Ssflag = flag['S'];
|
|
|
|
cmd->Scflag = flag['C'];
|
|
|
|
cmd->makefileflag = flag['M'];
|
|
|
|
|
|
|
|
if (tirpcflag) {
|
2002-07-14 17:54:00 +00:00
|
|
|
if (inetdflag)
|
|
|
|
pmflag = 0;
|
1995-12-13 03:31:10 +00:00
|
|
|
if ((inetdflag && cmd->nflag)) {
|
|
|
|
/* netid not allowed with inetdflag */
|
1997-08-06 06:47:41 +00:00
|
|
|
warnx("cannot use netid flag with inetd flag");
|
1995-12-13 03:31:10 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
} else { /* 4.1 mode */
|
|
|
|
pmflag = 0; /* set pmflag only in tirpcmode */
|
|
|
|
if (cmd->nflag) { /* netid needs TIRPC */
|
1997-08-06 06:47:41 +00:00
|
|
|
warnx("cannot use netid flag without TIRPC");
|
1995-12-13 03:31:10 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newstyle && (tblflag || cmd->tflag)) {
|
1997-08-06 06:47:41 +00:00
|
|
|
warnx("cannot use table flags with newstyle");
|
1995-12-13 03:31:10 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check no conflicts with file generation flags */
|
|
|
|
nflags = cmd->cflag + cmd->hflag + cmd->lflag + cmd->mflag +
|
|
|
|
cmd->sflag + cmd->nflag + cmd->tflag + cmd->Ssflag +
|
|
|
|
cmd->Scflag + cmd->makefileflag;
|
|
|
|
|
1994-08-07 18:01:39 +00:00
|
|
|
if (nflags == 0) {
|
|
|
|
if (cmd->outfile != NULL || cmd->infile == NULL) {
|
|
|
|
return (0);
|
|
|
|
}
|
1995-12-13 03:31:10 +00:00
|
|
|
} else if (cmd->infile == NULL &&
|
|
|
|
(cmd->Ssflag || cmd->Scflag || cmd->makefileflag)) {
|
1997-08-06 06:47:41 +00:00
|
|
|
warnx("\"infile\" is required for template generation flags");
|
1995-12-13 03:31:10 +00:00
|
|
|
return (0);
|
|
|
|
} if (nflags > 1) {
|
1997-08-06 06:47:41 +00:00
|
|
|
warnx("cannot have more than one file generation flag");
|
1994-08-07 18:01:39 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
return (1);
|
|
|
|
}
|
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
|
|
|
usage(void)
|
1995-12-13 03:31:10 +00:00
|
|
|
{
|
2002-07-21 12:55:04 +00:00
|
|
|
f_print(stderr, "%s\n%s\n%s\n%s\n%s\n",
|
1997-08-06 06:47:41 +00:00
|
|
|
"usage: rpcgen infile",
|
|
|
|
" rpcgen [-abCLNTM] [-Dname[=value]] [-i size]\
|
2002-07-14 17:54:00 +00:00
|
|
|
[-I -P [-K seconds]] [-Y path] infile",
|
1997-08-06 06:47:41 +00:00
|
|
|
" rpcgen [-c | -h | -l | -m | -t | -Sc | -Ss | -Sm]\
|
|
|
|
[-o outfile] [infile]",
|
|
|
|
" rpcgen [-s nettype]* [-o outfile] [infile]",
|
|
|
|
" rpcgen [-n netid]* [-o outfile] [infile]");
|
1995-12-13 03:31:10 +00:00
|
|
|
options_usage();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
1996-07-12 19:08:36 +00:00
|
|
|
static void
|
2010-01-02 10:09:20 +00:00
|
|
|
options_usage(void)
|
1995-12-13 03:31:10 +00:00
|
|
|
{
|
|
|
|
f_print(stderr, "options:\n");
|
|
|
|
f_print(stderr, "-a\t\tgenerate all files, including samples\n");
|
2002-07-14 17:54:00 +00:00
|
|
|
f_print(stderr, "-b\t\tbackward compatibility mode (generates code \
|
|
|
|
for FreeBSD 4.X)\n");
|
1995-12-13 03:31:10 +00:00
|
|
|
f_print(stderr, "-c\t\tgenerate XDR routines\n");
|
|
|
|
f_print(stderr, "-C\t\tANSI C mode\n");
|
|
|
|
f_print(stderr, "-Dname[=value]\tdefine a symbol (same as #define)\n");
|
|
|
|
f_print(stderr, "-h\t\tgenerate header file\n");
|
|
|
|
f_print(stderr, "-i size\t\tsize at which to start generating\
|
|
|
|
inline code\n");
|
2002-07-14 17:54:00 +00:00
|
|
|
f_print(stderr, "-I\t\tgenerate code for inetd support in server\n");
|
1995-12-13 03:31:10 +00:00
|
|
|
f_print(stderr, "-K seconds\tserver exits after K seconds of\
|
|
|
|
inactivity\n");
|
|
|
|
f_print(stderr, "-l\t\tgenerate client side stubs\n");
|
|
|
|
f_print(stderr, "-L\t\tserver errors will be printed to syslog\n");
|
|
|
|
f_print(stderr, "-m\t\tgenerate server side stubs\n");
|
|
|
|
f_print(stderr, "-M\t\tgenerate MT-safe code\n");
|
|
|
|
f_print(stderr, "-n netid\tgenerate server code that supports\
|
|
|
|
named netid\n");
|
|
|
|
f_print(stderr, "-N\t\tsupports multiple arguments and\
|
|
|
|
call-by-value\n");
|
|
|
|
f_print(stderr, "-o outfile\tname of the output file\n");
|
2002-07-14 17:54:00 +00:00
|
|
|
f_print(stderr, "-P\t\tgenerate code for port monitoring support in server\n");
|
1995-12-13 03:31:10 +00:00
|
|
|
f_print(stderr, "-s nettype\tgenerate server code that supports named\
|
|
|
|
nettype\n");
|
|
|
|
f_print(stderr, "-Sc\t\tgenerate sample client code that uses remote\
|
|
|
|
procedures\n");
|
|
|
|
f_print(stderr, "-Ss\t\tgenerate sample server code that defines\
|
|
|
|
remote procedures\n");
|
|
|
|
f_print(stderr, "-Sm \t\tgenerate makefile template \n");
|
|
|
|
|
|
|
|
f_print(stderr, "-t\t\tgenerate RPC dispatch table\n");
|
|
|
|
f_print(stderr, "-T\t\tgenerate code to support RPC dispatch tables\n");
|
|
|
|
f_print(stderr, "-Y path\t\tpath where cpp is found\n");
|
|
|
|
exit(1);
|
|
|
|
}
|