diff options
-rw-r--r-- | src/driver/pe_driver_ctx.c | 32 | ||||
-rw-r--r-- | src/perk.c | 2 |
2 files changed, 23 insertions, 11 deletions
diff --git a/src/driver/pe_driver_ctx.c b/src/driver/pe_driver_ctx.c index 990738b..97ff3fa 100644 --- a/src/driver/pe_driver_ctx.c +++ b/src/driver/pe_driver_ctx.c @@ -63,6 +63,23 @@ static uint32_t pe_argv_flags(uint32_t flags) return ret; } +static int pe_driver_usage( + const unsigned char * program, + const unsigned char * arg, + struct argv_meta * meta) +{ + char header[512]; + + snprintf(header,sizeof(header), + "Usage: %s [options] <file>...\n" "Options:\n", + program); + + argv_usage(stdout,header,options,arg); + argv_free(meta); + + return PERK_USAGE; +} + static struct pe_driver_ctx * pe_driver_ctx_alloc(struct argv_meta * meta, size_t nunits) { struct pe_driver_ctx_impl * ictx; @@ -111,7 +128,6 @@ int pe_get_driver_ctx( const char * program; const char * output; int fdout; - char header[512]; if (!(meta = argv_get(argv,options,pe_argv_flags(flags)))) return -1; @@ -122,20 +138,16 @@ int pe_get_driver_ctx( nunits = 0; program = argv_program_name(argv[0]); + if (!argv[1] && (flags & PERK_DRIVER_VERBOSITY_USAGE)) + return pe_driver_usage(program,0,meta); + /* get options, count units */ for (entry=meta->entries; entry->fopt || entry->arg; entry++) { if (entry->fopt) { switch (entry->tag) { case TAG_HELP: - if (flags & PERK_DRIVER_VERBOSITY_USAGE) { - snprintf(header,sizeof(header), - "Usage: %s [options] <file>...\n" "Options:\n", - program); - - argv_usage(stdout,header,options,entry->arg); - argv_free(meta); - return PERK_USAGE; - } + if (flags & PERK_DRIVER_VERBOSITY_USAGE) + return pe_driver_usage(program,entry->arg,meta); case TAG_VERSION: dflags |= PERK_DRIVER_VERSION; @@ -64,7 +64,7 @@ static int perk_main(int argc, const char ** argv, const char ** envp) const char ** unit; if ((ret = pe_get_driver_ctx(argv,envp,PERK_DRIVER_FLAGS,&dctx))) - return (ret == PERK_USAGE) ? 0 : 2; + return (ret == PERK_USAGE) ? !--argc : 2; if (dctx->cctx.drvflags & PERK_DRIVER_VERSION) perk_version(dctx); |