diff --git a/project/common.mk b/project/common.mk index c925124..3d8e96f 100644 --- a/project/common.mk +++ b/project/common.mk @@ -11,6 +11,7 @@ COMMON_SRCS = \ src/reader/pe_read_import_header.c \ src/reader/pe_read_optional_header.c \ src/reader/pe_read_section_header.c \ + src/skin/pe_skin_default.c \ APP_SRCS = \ src/perk.c diff --git a/project/headers.mk b/project/headers.mk index 57b9443..6cc3657 100644 --- a/project/headers.mk +++ b/project/headers.mk @@ -8,6 +8,7 @@ API_HEADERS = \ INTERNAL_HEADERS = \ $(PROJECT_DIR)/src/internal/argv/argv.h \ + $(PROJECT_DIR)/src/internal/$(PACKAGE)_driver_impl.h \ $(PROJECT_DIR)/src/internal/$(PACKAGE)_output_impl.h \ $(PROJECT_DIR)/src/internal/$(PACKAGE)_reader_impl.h \ diff --git a/project/tree.mk b/project/tree.mk index 386d8d5..b1d880c 100644 --- a/project/tree.mk +++ b/project/tree.mk @@ -5,4 +5,5 @@ tree.tag: mkdir -p src/logic mkdir -p src/output mkdir -p src/reader + mkdir -p src/skin touch tree.tag diff --git a/src/driver/pe_driver_ctx.c b/src/driver/pe_driver_ctx.c index e5df2a5..016302e 100644 --- a/src/driver/pe_driver_ctx.c +++ b/src/driver/pe_driver_ctx.c @@ -2,46 +2,15 @@ #include #include +#define ARGV_DRIVER + #include #include +#include "perk_driver_impl.h" #include "perk_impl.h" #include "argv/argv.h" -enum app_tags { - TAG_HELP, - TAG_VERSION, - TAG_OUTPUT, - TAG_PRETTY, - TAG_EXPSYMS, - TAG_IMPLIBS, - TAG_IMPSYMS, -}; - -static const struct argv_option options[] = { - {"version", 'v',TAG_VERSION,ARGV_OPTARG_NONE, 0,0, - "show version information"}, - - {"help", 'h',TAG_HELP, ARGV_OPTARG_OPTIONAL, "short|long",0, - "show usage information " - "[listing %s options only]"}, - - {"output", 'o',TAG_OUTPUT, ARGV_OPTARG_REQUIRED, 0,"", - "write output to %s"}, - - {"pretty", 'p',TAG_PRETTY, ARGV_OPTARG_REQUIRED, "yaml",0, - "format output for parsing by %s"}, - - {"expsyms", 'e',TAG_EXPSYMS,ARGV_OPTARG_NONE, 0,0, - "print exported symbols" }, - - {"implibs", 'i',TAG_IMPLIBS,ARGV_OPTARG_NONE, 0,0, - "list direct dependency libraries"}, - - {"impsyms", 'I',TAG_IMPSYMS,ARGV_OPTARG_NONE, 0,0, - "list direct dependency libraries " - "along with required symbols"}, - {0} -}; +extern const struct argv_option pe_default_options[]; struct pe_driver_ctx_alloc { struct argv_meta * meta; @@ -69,6 +38,7 @@ static uint32_t pe_argv_flags(uint32_t flags) static int pe_driver_usage( const char * program, const char * arg, + const struct argv_option * options, struct argv_meta * meta) { char header[512]; @@ -124,6 +94,7 @@ int pe_get_driver_ctx( struct pe_driver_ctx ** pctx) { struct pe_driver_ctx_impl * ctx; + const struct argv_option * options; struct argv_meta * meta; struct argv_entry * entry; size_t nunits; @@ -134,6 +105,8 @@ int pe_get_driver_ctx( const char * pretty; int fdout; + options = pe_default_options; + if (!(meta = argv_get(argv,options,pe_argv_flags(flags)))) return -1; @@ -146,7 +119,7 @@ int pe_get_driver_ctx( program = argv_program_name(argv[0]); if (!argv[1] && (flags & PERK_DRIVER_VERBOSITY_USAGE)) - return pe_driver_usage(program,0,meta); + return pe_driver_usage(program,0,options,meta); /* get options, count units */ for (entry=meta->entries; entry->fopt || entry->arg; entry++) { @@ -154,7 +127,7 @@ int pe_get_driver_ctx( switch (entry->tag) { case TAG_HELP: if (flags & PERK_DRIVER_VERBOSITY_USAGE) - return pe_driver_usage(program,entry->arg,meta); + return pe_driver_usage(program,entry->arg,options,meta); case TAG_VERSION: dflags |= PERK_DRIVER_VERSION; diff --git a/src/internal/argv/argv.h b/src/internal/argv/argv.h index 36615f6..b6be2a8 100644 --- a/src/internal/argv/argv.h +++ b/src/internal/argv/argv.h @@ -104,6 +104,8 @@ static void argv_free(struct argv_meta *); /* implementation of static functions */ /*------------------------------------*/ +#ifdef ARGV_DRIVER + static const struct argv_option * argv_short_option( const char * ch, const struct argv_option options[], @@ -870,3 +872,5 @@ static void argv_usage( } #endif + +#endif diff --git a/src/internal/perk_driver_impl.h b/src/internal/perk_driver_impl.h new file mode 100644 index 0000000..016a369 --- /dev/null +++ b/src/internal/perk_driver_impl.h @@ -0,0 +1,14 @@ +#ifndef PE_DRIVER_IMPL_H +#define PE_DRIVER_IMPL_H + +enum app_tags { + TAG_HELP, + TAG_VERSION, + TAG_OUTPUT, + TAG_PRETTY, + TAG_EXPSYMS, + TAG_IMPLIBS, + TAG_IMPSYMS, +}; + +#endif diff --git a/src/skin/pe_skin_default.c b/src/skin/pe_skin_default.c new file mode 100644 index 0000000..2ee828b --- /dev/null +++ b/src/skin/pe_skin_default.c @@ -0,0 +1,28 @@ +#include "perk_driver_impl.h" +#include "argv/argv.h" + +const struct argv_option pe_default_options[] = { + {"version", 'v',TAG_VERSION,ARGV_OPTARG_NONE, 0,0, + "show version information"}, + + {"help", 'h',TAG_HELP, ARGV_OPTARG_OPTIONAL, "short|long",0, + "show usage information " + "[listing %s options only]"}, + + {"output", 'o',TAG_OUTPUT, ARGV_OPTARG_REQUIRED, 0,"", + "write output to %s"}, + + {"pretty", 'p',TAG_PRETTY, ARGV_OPTARG_REQUIRED, "yaml",0, + "format output for parsing by %s"}, + + {"expsyms", 'e',TAG_EXPSYMS,ARGV_OPTARG_NONE, 0,0, + "print exported symbols" }, + + {"implibs", 'i',TAG_IMPLIBS,ARGV_OPTARG_NONE, 0,0, + "list direct dependency libraries"}, + + {"impsyms", 'I',TAG_IMPSYMS,ARGV_OPTARG_NONE, 0,0, + "list direct dependency libraries " + "along with required symbols"}, + {0} +};