From 746c90d1a04dda1ecc512577e2f81d851e62a3a5 Mon Sep 17 00:00:00 2001 From: smkelly Date: Sun, 2 May 2004 07:07:54 +0000 Subject: - 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 "__". --- usr.bin/rpcgen/rpc_main.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'usr.bin/rpcgen') 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); -- cgit v1.1