summaryrefslogtreecommitdiffstats
path: root/usr.bin/rpcgen
diff options
context:
space:
mode:
authorsmkelly <smkelly@FreeBSD.org>2004-05-02 01:55:23 +0000
committersmkelly <smkelly@FreeBSD.org>2004-05-02 01:55:23 +0000
commit7d92f80dd20e07fd13c71a1150a9425629487012 (patch)
treefbf9fdda0f22dc9245131d9de3c387a9fbde8bb3 /usr.bin/rpcgen
parente3af2353c4be4d158a6e21613b28d7e9fad1528c (diff)
downloadFreeBSD-src-7d92f80dd20e07fd13c71a1150a9425629487012.zip
FreeBSD-src-7d92f80dd20e07fd13c71a1150a9425629487012.tar.gz
Teach rpcgen to generate .h files properly when the input filename contains
characters that can't be used in preprocessor macros. PR: bin/66156 Submitted by: K S Braunsdorf <rpc@ksb.npcguild.org>
Diffstat (limited to 'usr.bin/rpcgen')
-rw-r--r--usr.bin/rpcgen/rpc_main.c28
1 files changed, 23 insertions, 5 deletions
diff --git a/usr.bin/rpcgen/rpc_main.c b/usr.bin/rpcgen/rpc_main.c
index 7fbc8b8..9a2536c 100644
--- a/usr.bin/rpcgen/rpc_main.c
+++ b/usr.bin/rpcgen/rpc_main.c
@@ -205,7 +205,7 @@ main(argc, argv)
EXTEND, "_svc.c", cmd.mflag, cmd.nflag);
if (tblflag) {
reinitialize();
- t_output(cmd.infile, "-DRPC_TBL", EXTEND, "_tbl.i");
+ t_output(cmd.infile, "-DRPC_TBL", EXTEND, "_tbl.i");
}
if (allfiles) {
@@ -474,12 +474,30 @@ char *generate_guard(pathname)
filename = strrchr(pathname, '/'); /* find last component */
filename = ((filename == 0) ? pathname : filename+1);
guard = xstrdup(filename);
- /* convert to upper case */
- tmp = guard;
- while (*tmp) {
+ /* convert to a valid C macro name, and upper case
+ * =~ m,[A-Za-z_][A-Za-z_0-9]*, else map other chars to '_'.
+ */
+ for (tmp = guard; '\000' != *tmp; ++tmp) {
if (islower(*tmp))
*tmp = toupper(*tmp);
- tmp++;
+ else if (isupper(*tmp) || '_' == *tmp)
+ /* OK for C */;
+ else if (tmp == guard)
+ *tmp = '_';
+ else if (isdigit(*tmp))
+ /* OK for all but first character */;
+ else if ('.' == *tmp) {
+ *tmp = '\000';
+ break;
+ } else
+ *tmp = '_';
+ }
+ /* When the filename started with "." (wow, the is Poor Form)
+ * lets put in the word "DOT" so we don't violate ANSI's reservation
+ * of macros that start with "_" -- rpc at ksb.npcguild.org
+ */
+ if ('\000' == *guard) {
+ guard = "DOT";
}
guard = extendfile(guard, "_H_RPCGEN");
return (guard);
OpenPOWER on IntegriCloud