aboutsummaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorSean Kelly <smkelly@FreeBSD.org>2004-05-02 07:07:54 +0000
committerSean Kelly <smkelly@FreeBSD.org>2004-05-02 07:07:54 +0000
commit080f4020a3e4a4f750f687ba8116e7bde553a9bc (patch)
treea8deee20edb7970731390a178b52a8b06f281fa4 /usr.bin
parentab884d993e101e1328824b0dd5064673bd2a9809 (diff)
Notes
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/rpcgen/rpc_main.c30
1 files changed, 18 insertions, 12 deletions
diff --git a/usr.bin/rpcgen/rpc_main.c b/usr.bin/rpcgen/rpc_main.c
index 9a2536ca5f161..022c4f1b7eeb7 100644
--- a/usr.bin/rpcgen/rpc_main.c
+++ b/usr.bin/rpcgen/rpc_main.c
@@ -469,35 +469,41 @@ char rpcgen_table_dcl[] = "struct rpcgen_table {\n\
char *generate_guard(pathname)
char* pathname;
{
- char* filename, *guard, *tmp;
+ char* filename, *guard, *tmp, *stopat;
filename = strrchr(pathname, '/'); /* find last component */
filename = ((filename == 0) ? pathname : filename+1);
guard = xstrdup(filename);
- /* convert to a valid C macro name, and upper case
- * =~ m,[A-Za-z_][A-Za-z_0-9]*, else map other chars to '_'.
+ stopat = strrchr(guard, '.');
+
+ /*
+ * Convert to a valid C macro name and make it upper case.
+ * Map macro unfriendly characterss to '_'.
*/
- for (tmp = guard; '\000' != *tmp; ++tmp) {
+ for (tmp = guard; *tmp != '\000'; ++tmp) {
if (islower(*tmp))
*tmp = toupper(*tmp);
- else if (isupper(*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';
+ else if (tmp == stopat) {
+ *tmp = '\0';
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
+ /*
+ * 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.
*/
- if ('\000' == *guard) {
- guard = "DOT";
+ if (*guard == '_') {
+ for (tmp = guard; *tmp == '_'; ++tmp)
+ ;
+ strcpy(guard, tmp);
}
guard = extendfile(guard, "_H_RPCGEN");
return (guard);