Blame src/sofort.c

f46039
#include <stdio.h>
f46039
#include <unistd.h>
f46039
#include <sofort/sofort.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
b992f4
static const char vermsg[] = "%s%s%s (git://midipix.org/sofort): "
b992f4
			     "version %s%d.%d.%d%s.\n"
b992f4
			     "[commit reference: %s%s%s]\n";
b992f4
b992f4
static const char * const sfrt_ver_color[6] = {
ec2692
		"\x1b[1m\x1b[35m","\x1b[0m",
ec2692
		"\x1b[1m\x1b[32m","\x1b[0m",
ec2692
		"\x1b[1m\x1b[34m","\x1b[0m"
b992f4
};
b992f4
b992f4
static const char * const sfrt_ver_plain[6] = {
b992f4
		"","",
b992f4
		"","",
b992f4
		"",""
b992f4
};
f46039
f46039
static ssize_t sofort_version(struct sfrt_driver_ctx * dctx)
f46039
{
f16d2d
	const struct sfrt_source_version * verinfo;
b992f4
	const char * const * verclr;
f16d2d
f16d2d
	verinfo = sfrt_source_version();
b992f4
	verclr  = isatty(STDOUT_FILENO) ? sfrt_ver_color : sfrt_ver_plain;
f16d2d
b992f4
	return fprintf(stdout,vermsg,
b992f4
			verclr[0],dctx->program,verclr[1],
b992f4
			verclr[2],verinfo->major,verinfo->minor,
b992f4
			verinfo->revision,verclr[3],
b992f4
			verclr[4],verinfo->commit,verclr[5]);
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