diff options
Diffstat (limited to '')
-rw-r--r-- | util/ChangeLog | 4 | ||||
-rw-r--r-- | util/argparse.c | 77 | ||||
-rw-r--r-- | util/iobuf.c | 5 |
3 files changed, 71 insertions, 15 deletions
diff --git a/util/ChangeLog b/util/ChangeLog index 23d284b1a..a62ba84db 100644 --- a/util/ChangeLog +++ b/util/ChangeLog @@ -1,3 +1,7 @@ +Thu May 14 16:45:13 1998 Werner Koch ([email protected]) + + * argparse.c (show_help): Add some formatting stuff + Fri May 8 17:06:49 1998 Werner Koch ([email protected]) * errors.c (strerror): New if !HAVE_STRERROR diff --git a/util/argparse.c b/util/argparse.c index 9c1cd4214..ce1dbc6af 100644 --- a/util/argparse.c +++ b/util/argparse.c @@ -521,6 +521,35 @@ set_opt_arg(ARGPARSE_ARGS *arg, unsigned flags, char *s) } } + +static size_t +long_opt_strlen( ARGPARSE_OPTS *o ) +{ + size_t n = strlen(o->long_opt); + + if( o->description && *o->description == '|' ) { + const char *s; + + s=o->description+1; + if( *s != '=' ) + n++; + for(; *s && *s != '|'; s++ ) + n++; + } + return n; +} + +/**************** + * Print formatted help. The description string has some special + * meanings: + * - A description string which is "@" suppresses help output for + * this option + * - a description,ine which starts with a '@' and is followed by + * any other characters is printed as is; this may be used for examples + * ans such. + * - A description which starts with a '|' outputs the string between this + * bar and the next one as arguments of the long option. + */ static void show_help( ARGPARSE_OPTS *opts, unsigned flags ) { @@ -535,19 +564,19 @@ show_help( ARGPARSE_OPTS *opts, unsigned flags ) /* get max. length of long options */ for(i=indent=0; opts[i].short_opt; i++ ) { if( opts[i].long_opt ) - if( !opts[i].description || *opts[i].description != '\v' ) - if( (j=strlen(opts[i].long_opt)) > indent && j < 35 ) + if( !opts[i].description || *opts[i].description != '@' ) + if( (j=long_opt_strlen(opts+i)) > indent && j < 35 ) indent = j; } /* example: " -v, --verbose Viele Sachen ausgeben" */ indent += 10; - if( *opts[0].description != '\v' ) + if( *opts[0].description != '@' ) puts("Options:"); for(i=0; opts[i].short_opt; i++ ) { s = _( opts[i].description ); - if( s && *s== '\r' ) /* hide this line */ + if( s && *s== '@' && !s[1] ) /* hide this line */ continue; - if( s && *s == '\v' ) { /* unindented comment only line */ + if( s && *s == '@' ) { /* unindented comment only line */ for(s++; *s; s++ ) { if( *s == '\n' ) { if( s[1] ) @@ -560,17 +589,45 @@ show_help( ARGPARSE_OPTS *opts, unsigned flags ) continue; } - if( opts[i].short_opt < 256 ) + j = 3; + if( opts[i].short_opt < 256 ) { printf(" -%c", opts[i].short_opt ); + if( !opts[i].long_opt ) { + if(s && *s == '|' ) { + putchar(' '); j++; + for(s++ ; *s && *s != '|'; s++, j++ ) + putchar(*s); + if( *s ) + s++; + } + } + } else fputs(" ", stdout); - j = 3; - if( opts[i].long_opt ) - j += printf("%c --%s ", opts[i].short_opt < 256?',':' ', - opts[i].long_opt ); + if( opts[i].long_opt ) { + j += printf("%c --%s", opts[i].short_opt < 256?',':' ', + opts[i].long_opt ); + if(s && *s == '|' ) { + if( *++s != '=' ) { + putchar(' '); + j++; + } + for( ; *s && *s != '|'; s++, j++ ) + putchar(*s); + if( *s ) + s++; + } + fputs(" ", stdout); + j += 3; + } for(;j < indent; j++ ) putchar(' '); if( s ) { + if( *s && j > indent ) { + putchar('\n'); + for(j=0;j < indent; j++ ) + putchar(' '); + } for(; *s; s++ ) { if( *s == '\n' ) { if( s[1] ) { diff --git a/util/iobuf.c b/util/iobuf.c index d43fad9ba..772dfa167 100644 --- a/util/iobuf.c +++ b/util/iobuf.c @@ -743,11 +743,6 @@ iobuf_read(IOBUF a, byte *buf, unsigned buflen ) return n; } - if( a->filter_eof ) { - if( DBG_IOBUF ) - log_debug("iobuf-%d.%d: filter eof in iobuf_read\n", a->no, a->subno ); - return -1; - } n = 0; do { for( ; n < buflen && a->d.start < a->d.len; n++ ) |