From bbf9e9debd761b5c5024d8417ad38e1cadc70d5b Mon Sep 17 00:00:00 2001 From: midipix Date: Sat, 21 Nov 2015 21:17:19 -0500 Subject: driver integration 1/9: remove old (ad-hoc) driver, prepare source tree. --- src/main/perk.c | 116 -------------------------------------------------------- 1 file changed, 116 deletions(-) delete mode 100644 src/main/perk.c (limited to 'src/main/perk.c') diff --git a/src/main/perk.c b/src/main/perk.c deleted file mode 100644 index 0382186..0000000 --- a/src/main/perk.c +++ /dev/null @@ -1,116 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include "perk_impl.h" - -static int perk_parse_opts(struct perk_ctx * ctx) -{ - int i; - char * ch; - const char ** popt; - - for (i=1; iargc; i++) { - ch = ctx->argv[i]; - - if (*ch == '-') { - switch (*++ch) { - case 'i': - popt = &ctx->fname; - break; - case 'h': - ctx->flags = PERK_HELP; - return 0; - default: - ctx->status = PERK_BAD_OPT; - return ctx->status; - } - - while ((*++ch == '\t') || (*ch == ' ')); - - if (!*ch) { - if (++i < ctx->argc) - *popt = ctx->argv[i]; - else - ctx->status = PERK_BAD_OPT_VAL; - } else - *popt = ch; - } else if (!ctx->fname) - ctx->fname = ch; - else - ctx->status = PERK_BAD_OPT; - - } - - return ctx->status; -} - - -static int perk_map_input(struct perk_ctx * ctx) -{ - ctx->fd = open(ctx->fname,O_RDONLY | O_CLOEXEC); - - if (ctx->fd < 0) { - ctx->status = PERK_IO_ERROR; - return ctx->status; - } - - ctx->status = pe_map_raw_image(ctx->fd,0,PROT_READ,&ctx->map); - - return ctx->status; -} - - -static int perk_exit(struct perk_ctx * ctx) -{ - if (ctx->map.addr) - pe_unmap_raw_image(&ctx->map); - - return ctx->status; -} - - -static int perk_run(struct perk_ctx * ctx) -{ - struct pe_image_meta * meta; - - if (perk_map_input(ctx)) - return perk_exit(ctx); - - if ((ctx->status = pe_get_image_meta(&ctx->map,&meta))) - return perk_exit(ctx); - - /* pre-alpha default output */ - pe_output_export_symbols( - meta, - PERK_OUTPUT_FORMAT_LIST | PERK_OUTPUT_FIELD_NAME, - stdout); - - ctx->status = pe_free_image_meta(meta); - - return perk_exit(ctx); -} - -static int perk_main(int argc, char ** argv, char ** envp) -{ - struct perk_ctx ctx = {argc,argv,envp}; - - if (perk_parse_opts(&ctx)) - return ctx.status; - else - return perk_run(&ctx); -} - -int main(int argc, char ** argv, char ** envp) -{ - return perk_main(argc,argv,envp); -} -- cgit v1.2.3