|
|
616016 |
/****************************************************************/
|
|
|
616016 |
/* mdso: midipix dso scavenger */
|
|
|
616016 |
/* Copyright (C) 2015--2016 Z. Gilboa */
|
|
|
616016 |
/* Released under GPLv2 and GPLv3; see COPYING.MDSO. */
|
|
|
616016 |
/****************************************************************/
|
|
|
616016 |
|
|
|
616016 |
#include <stdio.h>
|
|
|
616016 |
#include <unistd.h>
|
|
|
616016 |
#include <mdso/mdso.h>
|
|
|
616016 |
#include <mdso/mdso_output.h>
|
|
|
616016 |
#include "mdso_driver_impl.h"
|
|
|
616016 |
|
|
|
616016 |
#ifndef MDSO_DRIVER_FLAGS
|
|
|
616016 |
#define MDSO_DRIVER_FLAGS MDSO_DRIVER_VERBOSITY_ERRORS \
|
|
|
616016 |
| MDSO_DRIVER_VERBOSITY_USAGE
|
|
|
616016 |
#endif
|
|
|
616016 |
|
|
|
616016 |
static const char vermsg[] = "%s%s%s (git://midipix.org/mdso): "
|
|
|
616016 |
"version %s%d.%d.%d%s.\n"
|
|
|
616016 |
"[commit reference: %s%s%s]\n";
|
|
|
616016 |
|
|
|
616016 |
static const char * const mdso_ver_color[6] = {
|
|
|
616016 |
"\x1b[1m\x1b[35m","\x1b[0m",
|
|
|
616016 |
"\x1b[1m\x1b[32m","\x1b[0m",
|
|
|
616016 |
"\x1b[1m\x1b[34m","\x1b[0m"
|
|
|
616016 |
};
|
|
|
616016 |
|
|
|
616016 |
static const char * const mdso_ver_plain[6] = {
|
|
|
616016 |
"","",
|
|
|
616016 |
"","",
|
|
|
616016 |
"",""
|
|
|
616016 |
};
|
|
|
616016 |
|
|
|
616016 |
static ssize_t mdso_version(struct mdso_driver_ctx * dctx)
|
|
|
616016 |
{
|
|
|
616016 |
const struct mdso_source_version * verinfo;
|
|
|
616016 |
const char * const * verclr;
|
|
|
616016 |
|
|
|
616016 |
verinfo = mdso_source_version();
|
|
|
616016 |
verclr = isatty(STDOUT_FILENO) ? mdso_ver_color : mdso_ver_plain;
|
|
|
616016 |
|
|
|
616016 |
return fprintf(stdout,vermsg,
|
|
|
616016 |
verclr[0],dctx->program,verclr[1],
|
|
|
616016 |
verclr[2],verinfo->major,verinfo->minor,
|
|
|
616016 |
verinfo->revision,verclr[3],
|
|
|
616016 |
verclr[4],verinfo->commit,verclr[5]);
|
|
|
616016 |
}
|
|
|
616016 |
|
|
|
616016 |
static void mdso_perform_unit_actions(struct mdso_unit_ctx * uctx)
|
|
|
616016 |
{
|
|
|
616016 |
uint64_t flags = uctx->cctx->fmtflags;
|
|
|
616016 |
|
|
|
616016 |
if (flags & MDSO_OUTPUT_EXPORT_SYMS) {
|
|
|
616016 |
uctx->status = mdso_output_export_symbols(uctx,uctx->cctx,stdout);
|
|
|
616016 |
uctx->nerrors += !!uctx->status;
|
|
|
616016 |
}
|
|
|
616016 |
}
|
|
|
616016 |
|
|
|
616016 |
static int mdso_exit(struct mdso_driver_ctx * dctx, int nerrors)
|
|
|
616016 |
{
|
|
|
616016 |
mdso_free_driver_ctx(dctx);
|
|
|
616016 |
return nerrors ? 2 : 0;
|
|
|
616016 |
}
|
|
|
616016 |
|
|
|
616016 |
int mdso_main(int argc, char ** argv, char ** envp)
|
|
|
616016 |
{
|
|
|
616016 |
int ret;
|
|
|
616016 |
struct mdso_driver_ctx * dctx;
|
|
|
616016 |
struct mdso_unit_ctx * uctx;
|
|
|
616016 |
const char ** unit;
|
|
|
616016 |
|
|
|
616016 |
if ((ret = mdso_get_driver_ctx(argv,envp,MDSO_DRIVER_FLAGS,&dctx)))
|
|
|
616016 |
return (ret == MDSO_USAGE) ? !--argc : 2;
|
|
|
616016 |
|
|
|
616016 |
if (dctx->cctx->drvflags & MDSO_DRIVER_VERSION)
|
|
|
616016 |
if ((mdso_version(dctx)) < 0)
|
|
|
616016 |
return mdso_exit(dctx,2);
|
|
|
616016 |
|
|
|
616016 |
for (unit=dctx->units; *unit; unit++) {
|
|
|
616016 |
if (!(mdso_get_unit_ctx(dctx,*unit,&uctx))) {
|
|
|
616016 |
mdso_perform_unit_actions(uctx);
|
|
|
616016 |
ret += uctx->nerrors;
|
|
|
616016 |
mdso_free_unit_ctx(uctx);
|
|
|
616016 |
}
|
|
|
616016 |
}
|
|
|
616016 |
|
|
|
616016 |
if (*dctx->units) {
|
|
|
616016 |
dctx->status = mdso_create_implib_sources(dctx);
|
|
|
616016 |
dctx->nerrors += !!dctx->status;
|
|
|
616016 |
ret += dctx->nerrors;
|
|
|
616016 |
}
|
|
|
616016 |
|
|
|
616016 |
return mdso_exit(dctx,ret);
|
|
|
616016 |
}
|