When adding new options to gnu utilities, I am always annoyed that I 
have to add each option in four places :

long-options
short-options
usage()
whatever.texi

The solution I've come up with is to replace the glocal "stuct 
option" definition in the main program source with

typedef struct lineface {
   const char * longOpt;
   int          shortOpt;
   const char * parmName;
   const char * doc;
} lineface;

which might look like:
{"numeric-sort", 'n', 0, "compare according to string numerical value"},
{"delimiter", 't', "CHAR", "use DELIM instead of whitespace for field 
delimiter"},

Then with calls to functions like these :

char * GetShortOpts(const lineface * lf, enum HyphenType);
struct option * GetLongOpts(const lineface * lf);
void PrintUsage(FILE * f, const lineface * lf);

One generates what one needs on the fly.

Plus, with the hidden --generate_texinfo_template option, one calls
void PrintTexinfo(FILE * f, const lineface * lf, const char * program_name);
which gives a decent first blush of the texi file :

@item -n
@itemx --numeric-sort
@opindex -n
@opindex --numeric-sort
@cindex *** CONCEPT FOR --numeric-sort
compare according to string numerical value

@item -t @var{CHAR}
@itemx --delimiter=@var{CHAR}
@opindex -t
@opindex --delimiter
@cindex *** CONCEPT FOR --delimiter
use DELIM instead of whitespace for field delimiter


Note that this does not give access to all of the features of 
getopt_long, but does allow everything I've found in practice in gnu 
tools.


This is certainly a great boon going forward, but retro-fitting the 
code is a small pain.

Retro-fitting all the translations is a much larger pain (but can be 
automated) and again, the result will be easier going forward, as the 
msgid will become
"compare according to string numerical value"
instead of
"  -n, --numeric-sort          compare according to string numerical value\n"


Is this something of interest to the community as a whole?
Should I work on changing some standard tools and submitting patches, 
or should I shut the hell up?


Source, and more comments, available at 
http://alexautils.sourceforge.net/http://alexautils.sourceforge.net/textutils-2.0.21-alexa06.tar.gz
(join is the only command so far to make full use of it. Comments in 
lib/lineface.h)


Comments more than welcome,
Andy Jewell


_______________________________________________
Bug-textutils mailing list
[EMAIL PROTECTED]
http://mail.gnu.org/mailman/listinfo/bug-textutils

Reply via email to