help-gengetopt
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[help-gengetopt] spaces in group names


From: Matthew K. Junker
Subject: [help-gengetopt] spaces in group names
Date: Fri, 18 Apr 2003 10:27:33 -0500

It would be handy to have spaces in group names when using the --help
option.  I modified three files to make this possible.  In the
generated code, all non-alphanumeric characters in the group name
string are replaced with "_".  In the printed text, the string is left
unaltered.

I'm not familiar with the process of generating files in the skels
directory, and I'm not a heavy-duty C++ user, so I just did what
worked (it took me long enough to find the c_str() function).  I'm
sure it can be improved.  One major improvement would be not to have a
separate copy of clean_string in every file.

Here is a patch for version 2.9.

diff -C2 ../generic_option_group.cc ./generic_option_group.cc
*** ../generic_option_group.cc  Sat Feb  1 05:27:14 2003
--- ./generic_option_group.cc   Fri Apr 18 10:15:19 2003
***************
*** 7,10 ****
--- 7,26 ----
  #include "generic_option_group.h"
  
+ static char *
+ clean_string(const char *s) 
+ {
+   static char gn[100];
+   char *a;
+ 
+   strcpy( gn, s );
+   for ( a = gn; *a; a++ ) {
+     if ( !isalnum(*a) ) {
+       *a = '_';
+     }
+   }
+   return gn;
+ }
+ 
+ 
  void
  generic_option_group_gen_class::generate_generic_option_group(ostream 
&stream, unsigned int indent)
***************
*** 13,17 ****
    indent = 0;
  
!   stream << group_var_name;
    stream << "_group_counter += 1;";
    stream << "\n";
--- 29,33 ----
    indent = 0;
  
!   stream << clean_string(group_var_name.c_str());
    stream << "_group_counter += 1;";
    stream << "\n";
diff -C2 ../group_counter.cc ./group_counter.cc
*** ../group_counter.cc Sat Feb  1 05:27:14 2003
--- ./group_counter.cc  Fri Apr 18 10:15:35 2003
***************
*** 7,10 ****
--- 7,26 ----
  #include "group_counter.h"
  
+ static char *
+ clean_string(const char *s) 
+ {
+   static char gn[100];
+   char *a;
+ 
+   strcpy( gn, s );
+   for ( a = gn; *a; a++ ) {
+     if ( !isalnum(*a) ) {
+       *a = '_';
+     }
+   }
+   return gn;
+ }
+ 
+ 
  void
  group_counter_gen_class::generate_group_counter(ostream &stream, unsigned int 
indent)
***************
*** 14,18 ****
  
    stream << "int ";
!   stream << group_name;
    stream << "_group_counter = 0;";
    stream << "\n";
--- 30,34 ----
  
    stream << "int ";
!   stream << clean_string(group_name.c_str());
    stream << "_group_counter = 0;";
    stream << "\n";
diff -C2 ../group_option.cc ./group_option.cc
*** ../group_option.cc  Sat Feb  1 05:27:14 2003
--- ./group_option.cc   Fri Apr 18 10:15:03 2003
***************
*** 7,10 ****
--- 7,27 ----
  #include "group_option.h"
  
+ static char *
+ clean_string(const char *s) 
+ {
+   static char gn[100];
+   char *a;
+ 
+   strcpy( gn, s );
+   for ( a = gn; *a; a++ ) {
+     if ( !isalnum(*a) ) {
+       *a = '_';
+     }
+   }
+   return gn;
+ }
+ 
+ 
+ 
  void
  group_option_gen_class::generate_group_option(ostream &stream, unsigned int 
indent)
***************
*** 14,18 ****
  
    stream << "if ( ";
!   stream << group_var_name;
    stream << "_group_counter ";
    stream << Comparison_rule;
--- 31,35 ----
  
    stream << "if ( ";
!   stream << clean_string(group_var_name.c_str());
    stream << "_group_counter ";
    stream << Comparison_rule;
***************
*** 28,32 ****
    stream << number_required;
    stream << " is required\\n\", PACKAGE,";
!   stream << group_var_name;
    stream << "_group_counter);";
    stream << "\n";
--- 45,49 ----
    stream << number_required;
    stream << " is required\\n\", PACKAGE,";
!   stream << clean_string(group_var_name.c_str());
    stream << "_group_counter);";
    stream << "\n";






reply via email to

[Prev in Thread] Current Thread [Next in Thread]