svn commit: r231079 - head/usr.bin/rpcgen
Dimitry Andric
dim at FreeBSD.org
Mon Feb 6 12:03:22 UTC 2012
Author: dim
Date: Mon Feb 6 12:03:21 2012
New Revision: 231079
URL: http://svn.freebsd.org/changeset/base/231079
Log:
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
Modified:
head/usr.bin/rpcgen/rpc_main.c
head/usr.bin/rpcgen/rpcgen.1
Modified: head/usr.bin/rpcgen/rpc_main.c
==============================================================================
--- head/usr.bin/rpcgen/rpc_main.c Mon Feb 6 11:51:04 2012 (r231078)
+++ head/usr.bin/rpcgen/rpc_main.c Mon Feb 6 12:03:21 2012 (r231079)
@@ -75,13 +75,8 @@ static void s_output(int, const char **,
#define EXTEND 1 /* alias for TRUE */
#define DONT_EXTEND 0 /* alias for FALSE */
-#define SVR4_CPP "/usr/ccs/lib/cpp"
-#define SUNOS_CPP "/usr/bin/cpp"
-
-static int cppDefined = 0; /* explicit path for C preprocessor */
-
static const char *svcclosetime = "120";
-static const char *CPP = SVR4_CPP;
+static const char *CPP = NULL;
static const char CPPFLAGS[] = "-C";
static char pathbuf[MAXPATHLEN + 1];
static const char *allv[] = {
@@ -97,7 +92,7 @@ static int allnc = sizeof (allnv)/sizeof
* machinations for handling expanding argument list
*/
static void addarg(const char *); /* add another argument to the list */
-static void putarg(int, const char *); /* put argument at specified location */
+static void insarg(int, const char *); /* insert arg at specified location */
static void clear_args(void); /* clear argument list */
static void checkfiles(const char *, const char *);
/* check if out file already exists */
@@ -105,7 +100,7 @@ static void checkfiles(const char *, con
#define ARGLISTLEN 20
-#define FIXEDARGS 2
+#define FIXEDARGS 0
static char *arglist[ARGLISTLEN];
static int argcount = FIXEDARGS;
@@ -288,24 +283,35 @@ clear_args(void)
argcount = FIXEDARGS;
}
-/* make sure that a CPP exists */
+/* prepend C-preprocessor and flags before arguments */
static void
-find_cpp(void)
+prepend_cpp(void)
{
+ int idx = 1;
+ const char *var;
+ char *dupvar, *s, *t;
struct stat buf;
- if (stat(CPP, &buf) < 0) { /* SVR4 or explicit cpp does not exist */
- if (cppDefined) {
- warnx("cannot find C preprocessor: %s", CPP);
- crash();
- } else { /* try the other one */
- CPP = SUNOS_CPP;
- if (stat(CPP, &buf) < 0) { /* can't find any cpp */
- warnx("cannot find C preprocessor: %s", CPP);
- crash();
- }
+ 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);
}
+ free(dupvar);
}
+
+ if (stat(arglist[0], &buf) < 0) {
+ warnx("cannot find C preprocessor: %s", arglist[0]);
+ crash();
+ }
+
+ insarg(idx, CPPFLAGS);
}
/*
@@ -320,9 +326,7 @@ open_input(const char *infile, const cha
(void) pipe(pd);
switch (childpid = fork()) {
case 0:
- find_cpp();
- putarg(0, CPP);
- putarg(1, CPPFLAGS);
+ prepend_cpp();
addarg(define);
if (infile)
addarg(infile);
@@ -934,18 +938,26 @@ addarg(const char *cp)
}
+/*
+ * Insert an argument at the specified location
+ */
static void
-putarg(int place, const char *cp)
+insarg(int place, const char *cp)
{
- if (place >= ARGLISTLEN) {
- warnx("arglist coding error");
+ int i;
+
+ if (argcount >= ARGLISTLEN) {
+ warnx("too many defines");
crash();
/*NOTREACHED*/
}
- if (cp != NULL)
- arglist[place] = xstrdup(cp);
- else
- arglist[place] = NULL;
+
+ /* Move up existing arguments */
+ for (i = argcount - 1; i > place; i--)
+ arglist[i + 1] = arglist[i];
+
+ arglist[place] = xstrdup(cp);
+ argcount++;
}
/*
@@ -1134,7 +1146,6 @@ parseargs(int argc, const char *argv[],
return (0);
}
CPP = pathbuf;
- cppDefined = 1;
goto nextarg;
Modified: head/usr.bin/rpcgen/rpcgen.1
==============================================================================
--- head/usr.bin/rpcgen/rpcgen.1 Mon Feb 6 11:51:04 2012 (r231078)
+++ head/usr.bin/rpcgen/rpcgen.1 Mon Feb 6 12:03:21 2012 (r231079)
@@ -490,6 +490,11 @@ Give the name of the directory where
.Nm
will start looking for the C-preprocessor.
.El
+.Sh ENVIRONMENT
+If the
+.Ev RPCGEN_CPP
+environment variable is set, its value is used as the command line of the
+C preprocessor to be run on the input file.
.Sh EXAMPLES
The following example:
.Dl example% rpcgen -T prot.x
More information about the svn-src-head
mailing list