Blame src/apimagic.c

383aa6
/**********************************************************/
383aa6
/*  apimagic: cparser-based API normalization utility     */
383aa6
/*  Copyright (C) 2015--2016  Z. Gilboa                   */
383aa6
/*  Released under GPLv2 and GPLv3; see COPYING.APIMAGIC. */
383aa6
/**********************************************************/
383aa6
383aa6
#include <stdio.h>
383aa6
#include <unistd.h>
383aa6
#include <apimagic/apimagic.h>
383aa6
#include "apimagic_version.h"
383aa6
383aa6
#ifndef AMGC_DRIVER_FLAGS
383aa6
#define AMGC_DRIVER_FLAGS	AMGC_DRIVER_VERBOSITY_ERRORS \
383aa6
				| AMGC_DRIVER_VERBOSITY_USAGE
383aa6
#endif
383aa6
383aa6
static const char vermsg[] = "%s (git://midipix.org/apimagic): commit %s.\n";
383aa6
383aa6
static ssize_t apimagic_version(struct amgc_driver_ctx * dctx)
383aa6
{
383aa6
	return fprintf(stdout,vermsg,dctx->program,APIMAGIC_GIT_VERSION);
383aa6
}
383aa6
383aa6
static void apimagic_perform_unit_actions(struct amgc_unit_ctx * uctx)
383aa6
{
383aa6
}
383aa6
383aa6
static int apimagic_exit(struct amgc_driver_ctx * dctx, int nerrors)
383aa6
{
383aa6
	amgc_free_driver_ctx(dctx);
383aa6
	return nerrors ? 2 : 0;
383aa6
}
383aa6
383aa6
int apimagic_main(int argc, const char ** argv, const char ** envp)
383aa6
{
383aa6
	int				ret;
383aa6
	struct amgc_driver_ctx *	dctx;
383aa6
	struct amgc_unit_ctx *		uctx;
383aa6
	const char **			unit;
383aa6
383aa6
	if ((ret = amgc_get_driver_ctx(argv,envp,AMGC_DRIVER_FLAGS,&dctx)))
383aa6
		return (ret == AMGC_USAGE) ? !--argc : 2;
383aa6
383aa6
	if (dctx->cctx->drvflags & AMGC_DRIVER_VERSION)
383aa6
		if ((apimagic_version(dctx)) < 0)
383aa6
			return apimagic_exit(dctx,2);
383aa6
383aa6
	for (unit=dctx->units; *unit; unit++) {
383aa6
		if (!(amgc_get_unit_ctx(dctx,*unit,&uctx))) {
383aa6
			apimagic_perform_unit_actions(uctx);
383aa6
			ret += uctx->nerrors;
383aa6
			amgc_free_unit_ctx(uctx);
383aa6
		}
383aa6
	}
383aa6
383aa6
	return apimagic_exit(dctx,ret);
383aa6
}
383aa6
383aa6
#ifndef APIMAGIC_IN_A_BOX
383aa6
383aa6
int main(int argc, const char ** argv, const char ** envp)
383aa6
{
383aa6
	return apimagic_main(argc,argv,envp);
383aa6
}
383aa6
383aa6
#endif