diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/driver/mdso_driver_ctx.c | 14 | ||||
-rw-r--r-- | src/internal/mdso_driver_impl.h | 2 | ||||
-rw-r--r-- | src/mdso.c | 7 | ||||
-rw-r--r-- | src/output/mdso_output_export_symbols.c | 49 | ||||
-rw-r--r-- | src/skin/mdso_skin_default.c | 6 |
5 files changed, 78 insertions, 0 deletions
diff --git a/src/driver/mdso_driver_ctx.c b/src/driver/mdso_driver_ctx.c index 9c891de..c1e34ba 100644 --- a/src/driver/mdso_driver_ctx.c +++ b/src/driver/mdso_driver_ctx.c @@ -11,6 +11,7 @@ #define ARGV_DRIVER #include <mdso/mdso.h> +#include <mdso/mdso_output.h> #include "mdso_driver_impl.h" #include "argv/argv.h" @@ -98,6 +99,7 @@ int mdso_get_driver_ctx( struct argv_entry * entry; size_t nunits; const char * program; + const char * pretty; options = mdso_default_options; @@ -105,6 +107,7 @@ int mdso_get_driver_ctx( return -1; nunits = 0; + pretty = 0; program = argv_program_name(argv[0]); memset(&cctx,0,sizeof(cctx)); @@ -122,11 +125,22 @@ int mdso_get_driver_ctx( case TAG_VERSION: cctx.drvflags |= MDSO_DRIVER_VERSION; break; + + case TAG_PRETTY: + pretty = entry->arg; + break; + + case TAG_EXPSYMS: + cctx.fmtflags |= MDSO_OUTPUT_EXPORT_SYMS; + break; } } else nunits++; } + if (pretty && !strcmp(pretty,"yaml")) + cctx.fmtflags |= MDSO_PRETTY_YAML; + if (!(ctx = mdso_driver_ctx_alloc(meta,nunits))) return mdso_get_driver_ctx_fail(meta); diff --git a/src/internal/mdso_driver_impl.h b/src/internal/mdso_driver_impl.h index aa09197..d76f29e 100644 --- a/src/internal/mdso_driver_impl.h +++ b/src/internal/mdso_driver_impl.h @@ -10,6 +10,8 @@ enum app_tags { TAG_HELP, TAG_VERSION, + TAG_PRETTY, + TAG_EXPSYMS, }; struct mdso_expsyms { @@ -7,6 +7,7 @@ #include <stdio.h> #include <unistd.h> #include <mdso/mdso.h> +#include <mdso/mdso_output.h> #include "mdso_version.h" #ifndef MDSO_DRIVER_FLAGS @@ -23,6 +24,12 @@ static ssize_t mdso_version(struct mdso_driver_ctx * dctx) static void mdso_perform_unit_actions(struct mdso_unit_ctx * uctx) { + uint64_t flags = uctx->cctx->fmtflags; + + if (flags & MDSO_OUTPUT_EXPORT_SYMS) { + uctx->status = mdso_output_export_symbols(uctx,uctx->cctx,stdout); + uctx->nerrors += !!uctx->status; + } } static int mdso_exit(struct mdso_driver_ctx * dctx, int nerrors) diff --git a/src/output/mdso_output_export_symbols.c b/src/output/mdso_output_export_symbols.c new file mode 100644 index 0000000..eaac241 --- /dev/null +++ b/src/output/mdso_output_export_symbols.c @@ -0,0 +1,49 @@ +/****************************************************************/ +/* mdso: midipix dso scavenger */ +/* Copyright (C) 2015 Z. Gilboa */ +/* Released under GPLv2 and GPLv3; see COPYING.MDSO. */ +/****************************************************************/ + +#include <stdint.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <errno.h> + +#include <mdso/mdso.h> +#include <mdso/mdso_output.h> + +static int pretty_header(const struct mdso_common_ctx * cctx, FILE * fout) +{ + return (cctx->fmtflags & MDSO_PRETTY_YAML) + ? fputs("exports:\n",fout) + : 0; +} + +static int pretty_export_item(const struct mdso_common_ctx * cctx, const char * name, FILE * fout) +{ + if (cctx->fmtflags & MDSO_PRETTY_YAML) + return fprintf(fout,"- %s\n",name); + else + return fprintf(fout,"%s\n",name); +} + +int mdso_output_export_symbols( + const struct mdso_unit_ctx * uctx, + const struct mdso_common_ctx * cctx, + FILE * fout) +{ + const char * const * sym; + + if (!uctx->syms[0]) + return 0; + + if ((pretty_header(cctx,fout)) < 0) + return -1; + + for (sym=uctx->syms; *sym; sym++) + if ((pretty_export_item(cctx,*sym,fout)) < 0) + return -1; + + return 0; +} diff --git a/src/skin/mdso_skin_default.c b/src/skin/mdso_skin_default.c index c12f371..cf65a3f 100644 --- a/src/skin/mdso_skin_default.c +++ b/src/skin/mdso_skin_default.c @@ -8,5 +8,11 @@ const struct argv_option mdso_default_options[] = { {"help", 'h',TAG_HELP,ARGV_OPTARG_OPTIONAL,"short|long",0, "show usage information [listing %s options only]"}, + {"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" }, + {0} }; |