Blame src/sofort.c

f46039
#include <stdio.h>
f46039
#include <unistd.h>
f46039
#include <sofort/sofort.h>
f46039
#include "sofort_version.h"
a6709e
#include "sofort_driver_impl.h"
f46039
f46039
#ifndef SFRT_DRIVER_FLAGS
f46039
#define SFRT_DRIVER_FLAGS	SFRT_DRIVER_VERBOSITY_ERRORS \
f46039
				| SFRT_DRIVER_VERBOSITY_USAGE
f46039
#endif
f46039
4f3978
static const char vermsg[] = "%s (git://localhost/sofort): commit %s.\n";
f46039
f46039
static ssize_t sofort_version(struct sfrt_driver_ctx * dctx)
f46039
{
f46039
	return fprintf(stdout,vermsg,dctx->program,SOFORT_GIT_VERSION);
f46039
}
f46039
f46039
static void sofort_perform_unit_actions(struct sfrt_unit_ctx * uctx)
f46039
{
bbc20f
	uint64_t flags = uctx->cctx->actflags;			/* dummy */
bbc20f
								/* dummy */
bbc20f
	if (flags & SFRT_OUTPUT_NAME) {				/* dummy */
bbc20f
		uctx->status = sfrt_output_name(uctx,stdout);	/* dummy */
bbc20f
		uctx->nerrors += !!uctx->status;		/* dummy */
bbc20f
	}							/* dummy */
bbc20f
								/* dummy */
bbc20f
	if (flags & SFRT_OUTPUT_ADDRESS) {			/* dummy */
bbc20f
		uctx->status = sfrt_output_address(uctx,stdout);/* dummy */
bbc20f
		uctx->nerrors += !!uctx->status;		/* dummy */
bbc20f
	}							/* dummy */
f46039
}
f46039
f46039
static int sofort_exit(struct sfrt_driver_ctx * dctx, int nerrors)
f46039
{
f46039
	sfrt_free_driver_ctx(dctx);
f46039
	return nerrors ? 2 : 0;
f46039
}
f46039
4a749a
int sofort_main(int argc, char ** argv, char ** envp)
f46039
{
f46039
	int				ret;
f46039
	struct sfrt_driver_ctx *	dctx;
f46039
	struct sfrt_unit_ctx *		uctx;
f46039
	const char **			unit;
f46039
f46039
	if ((ret = sfrt_get_driver_ctx(argv,envp,SFRT_DRIVER_FLAGS,&dctx)))
f46039
		return (ret == SFRT_USAGE) ? !--argc : 2;
f46039
f46039
	if (dctx->cctx->drvflags & SFRT_DRIVER_VERSION)
f46039
		if ((sofort_version(dctx)) < 0)
f46039
			return sofort_exit(dctx,2);
f46039
bbc20f
	if (dctx->cctx->anystring)				/* dummy */
bbc20f
		if ((sfrt_output_dummy(dctx->cctx,stdout)) < 0)	/* dummy */
bbc20f
			return sofort_exit(dctx,2);		/* dummy */
bbc20f
								/* dummy */
f46039
	for (unit=dctx->units; *unit; unit++) {
f46039
		if (!(sfrt_get_unit_ctx(dctx,*unit,&uctx))) {
f46039
			sofort_perform_unit_actions(uctx);
f46039
			ret += uctx->nerrors;
f46039
			sfrt_free_unit_ctx(uctx);
f46039
		}
f46039
	}
f46039
f46039
	return sofort_exit(dctx,ret);
f46039
}
f46039
f46039
#ifndef SOFORT_IN_A_BOX
f46039
4a749a
int main(int argc, char ** argv, char ** envp)
f46039
{
f46039
	return sofort_main(argc,argv,envp);
f46039
}
f46039
f46039
#endif