Blame src/perk.c

846f96
#include <stdio.h>
bbf9e9
#include <perk/perk.h>
949bb3
#include <perk/perk_output.h>
bbf9e9
846f96
#ifndef PERK_DRIVER_FLAGS
846f96
#define PERK_DRIVER_FLAGS	PERK_DRIVER_VERBOSITY_ERRORS|PERK_DRIVER_VERBOSITY_USAGE
846f96
#endif
846f96
846f96
static void perk_perform_unit_actions(struct pe_unit_ctx * uctx)
846f96
{
846f96
	uint64_t flags = uctx->cctx.fmtflags;
846f96
8fd1f5
	if (flags & PERK_OUTPUT_EXPORT_SYMS)
846f96
		uctx->cctx.status = pe_output_export_symbols(uctx->meta,&uctx->cctx,0);
846f96
}
846f96
846f96
static int perk_exit(struct pe_driver_ctx * dctx, int status)
bbf9e9
{
846f96
	pe_free_driver_ctx(dctx);
846f96
	return (status < 0) ? 2 : status;
846f96
}
846f96
846f96
static int perk_main(int argc, const char ** argv, const char ** envp)
846f96
{
846f96
	int			ret;
846f96
	struct pe_driver_ctx *	dctx;
846f96
	struct pe_unit_ctx *	uctx;
846f96
	const char **		unit;
846f96
846f96
	if ((ret = pe_get_driver_ctx(argv,envp,PERK_DRIVER_FLAGS,&dctx)))
846f96
		return (ret == PERK_USAGE) ? 0 : 2;
846f96
846f96
	for (unit=dctx->units; *unit; unit++) {
846f96
		if (!(pe_get_unit_ctx(dctx,*unit,&uctx))) {
846f96
			perk_perform_unit_actions(uctx);
846f96
			ret = uctx->cctx.status ? uctx->cctx.status : ret;
846f96
			pe_free_unit_ctx(uctx);
846f96
		}
846f96
	}
846f96
846f96
	return perk_exit(dctx,ret);
bbf9e9
}
bbf9e9
846f96
int main(int argc, const char ** argv, const char ** envp)
bbf9e9
{
bbf9e9
	return perk_main(argc,argv,envp);
bbf9e9
}