summaryrefslogtreecommitdiffstats
path: root/usr.bin/rpcgen
diff options
context:
space:
mode:
authorsmkelly <smkelly@FreeBSD.org>2004-05-02 07:07:54 +0000
committersmkelly <smkelly@FreeBSD.org>2004-05-02 07:07:54 +0000
commit746c90d1a04dda1ecc512577e2f81d851e62a3a5 (patch)
treea8deee20edb7970731390a178b52a8b06f281fa4 /usr.bin/rpcgen
parent8f62dbebe1b55307f420e4b9164fb86ec654824f (diff)
downloadFreeBSD-src-746c90d1a04dda1ecc512577e2f81d851e62a3a5.zip
FreeBSD-src-746c90d1a04dda1ecc512577e2f81d851e62a3a5.tar.gz
- style(9) improvements courtesy of bde.
- Revise the former commit to behave nicer on filenames containing multiple '.' characters. - Prevent the generation of macros starting with "__".
Diffstat (limited to 'usr.bin/rpcgen')
-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 9a2536c..022c4f1 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);
OpenPOWER on IntegriCloud