mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-30 08:34:16 +01:00
print usage prettier (with an apparent off-by-one error)
This commit is contained in:
parent
b82383a5ad
commit
3534bc0e49
1 changed files with 18 additions and 2 deletions
|
@ -804,15 +804,31 @@ make_longopts()
|
|||
static void
|
||||
usage( char* appName, char* msg )
|
||||
{
|
||||
const char* param = "<param>";
|
||||
int ii;
|
||||
if ( msg != NULL ) {
|
||||
fprintf( stderr, "Error: %s\n\n", msg );
|
||||
}
|
||||
fprintf( stderr, "usage: %s \n", appName );
|
||||
|
||||
int maxWidth = 0;
|
||||
for ( ii = 0; ii < VSIZE(CmdInfoRecs); ++ii ) {
|
||||
const CmdInfoRec* rec = &CmdInfoRecs[ii];
|
||||
fprintf( stderr, " --%s %-20s # %s\n", rec->param,
|
||||
rec->hasArg? "<param>" : "", rec->hint );
|
||||
int width = strlen(rec->param) + 1;
|
||||
if ( rec->hasArg ) {
|
||||
width += strlen(param) + 1;
|
||||
}
|
||||
if ( width > maxWidth ) {
|
||||
maxWidth = width;
|
||||
}
|
||||
}
|
||||
|
||||
for ( ii = 0; ii < VSIZE(CmdInfoRecs); ++ii ) {
|
||||
const CmdInfoRec* rec = &CmdInfoRecs[ii];
|
||||
char buf[120];
|
||||
snprintf( buf, sizeof(buf), "--%s %s", rec->param,
|
||||
(rec->hasArg ? param : "") );
|
||||
fprintf( stderr, " %-*s # %s\n", maxWidth, buf, rec->hint );
|
||||
}
|
||||
fprintf( stderr, "\n(revision: %s)\n", SVN_REV);
|
||||
exit(1);
|
||||
|
|
Loading…
Add table
Reference in a new issue