diff options
author | midipix <writeonce@midipix.org> | 2015-11-26 22:30:10 -0500 |
---|---|---|
committer | midipix <writeonce@midipix.org> | 2016-11-10 23:35:28 -0500 |
commit | dd97ea947fa5a9796507a092b3d9e7984712e80b (patch) | |
tree | 1a3cc559102ed530915b250d3909cb74bba3e24e | |
parent | e8510034681b369e7140721f8fbeddaf1d813475 (diff) | |
download | perk-dd97ea947fa5a9796507a092b3d9e7984712e80b.tar.bz2 perk-dd97ea947fa5a9796507a092b3d9e7984712e80b.tar.xz |
driver: show usage if neither options nor units were specified.
-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); |