|
|
9e67a4 |
#include <stdio.h>
|
|
|
9e67a4 |
#include <unistd.h>
|
|
|
9e67a4 |
#include <sofort/sofort.h>
|
|
|
9e67a4 |
#include "sofort_driver_impl.h"
|
|
|
d4f88d |
#include "sofort_dprintf_impl.h"
|
|
|
9e67a4 |
|
|
|
9e67a4 |
#ifndef SFRT_DRIVER_FLAGS
|
|
|
9e67a4 |
#define SFRT_DRIVER_FLAGS SFRT_DRIVER_VERBOSITY_ERRORS \
|
|
|
9e67a4 |
| SFRT_DRIVER_VERBOSITY_USAGE
|
|
|
9e67a4 |
#endif
|
|
|
9e67a4 |
|
|
|
9e67a4 |
static const char vermsg[] = "%s%s%s (git://midipix.org/sofort): "
|
|
|
9e67a4 |
"version %s%d.%d.%d%s.\n"
|
|
|
9e67a4 |
"[commit reference: %s%s%s]\n";
|
|
|
9e67a4 |
|
|
|
9e67a4 |
static const char * const sfrt_ver_color[6] = {
|
|
|
9e67a4 |
"\x1b[1m\x1b[35m","\x1b[0m",
|
|
|
9e67a4 |
"\x1b[1m\x1b[32m","\x1b[0m",
|
|
|
9e67a4 |
"\x1b[1m\x1b[34m","\x1b[0m"
|
|
|
9e67a4 |
};
|
|
|
9e67a4 |
|
|
|
9e67a4 |
static const char * const sfrt_ver_plain[6] = {
|
|
|
9e67a4 |
"","",
|
|
|
9e67a4 |
"","",
|
|
|
9e67a4 |
"",""
|
|
|
9e67a4 |
};
|
|
|
9e67a4 |
|
|
|
985580 |
static ssize_t sfrt_version(struct sfrt_driver_ctx * dctx, int fdout)
|
|
|
9e67a4 |
{
|
|
|
9e67a4 |
const struct sfrt_source_version * verinfo;
|
|
|
9e67a4 |
const char * const * verclr;
|
|
|
9e67a4 |
|
|
|
9e67a4 |
verinfo = sfrt_source_version();
|
|
|
d4f88d |
verclr = isatty(fdout) ? sfrt_ver_color : sfrt_ver_plain;
|
|
|
9e67a4 |
|
|
|
d4f88d |
return sfrt_dprintf(
|
|
|
d4f88d |
fdout,vermsg,
|
|
|
9e67a4 |
verclr[0],dctx->program,verclr[1],
|
|
|
9e67a4 |
verclr[2],verinfo->major,verinfo->minor,
|
|
|
9e67a4 |
verinfo->revision,verclr[3],
|
|
|
9e67a4 |
verclr[4],verinfo->commit,verclr[5]);
|
|
|
9e67a4 |
}
|
|
|
9e67a4 |
|
|
|
3be86d |
static void sfrt_perform_unit_actions(
|
|
|
3be86d |
const struct sfrt_driver_ctx * dctx,
|
|
|
3be86d |
struct sfrt_unit_ctx * uctx)
|
|
|
9e67a4 |
{
|
|
|
3be86d |
uint64_t flags = dctx->cctx->actflags; /* dummy */
|
|
|
9e67a4 |
/* dummy */
|
|
|
f530d3 |
if (flags & SFRT_OUTPUT_NAME) /* dummy */
|
|
|
2dfa01 |
sfrt_output_name(dctx,uctx); /* dummy */
|
|
|
9e67a4 |
/* dummy */
|
|
|
f530d3 |
if (flags & SFRT_OUTPUT_ADDRESS) /* dummy */
|
|
|
2dfa01 |
sfrt_output_address(dctx,uctx); /* dummy */
|
|
|
9e67a4 |
}
|
|
|
9e67a4 |
|
|
|
f530d3 |
static int sfrt_exit(struct sfrt_driver_ctx * dctx, int ret)
|
|
|
9e67a4 |
{
|
|
|
f530d3 |
sfrt_output_error_vector(dctx);
|
|
|
9e67a4 |
sfrt_free_driver_ctx(dctx);
|
|
|
f530d3 |
return ret;
|
|
|
9e67a4 |
}
|
|
|
9e67a4 |
|
|
|
69302d |
int sfrt_main(char ** argv, char ** envp, const struct sfrt_fd_ctx * fdctx)
|
|
|
9e67a4 |
{
|
|
|
9e67a4 |
int ret;
|
|
|
d4f88d |
int fdout;
|
|
|
d4f88d |
uint64_t flags;
|
|
|
9e67a4 |
struct sfrt_driver_ctx * dctx;
|
|
|
9e67a4 |
struct sfrt_unit_ctx * uctx;
|
|
|
9e67a4 |
const char ** unit;
|
|
|
9e67a4 |
|
|
|
d4f88d |
flags = SFRT_DRIVER_FLAGS;
|
|
|
d4f88d |
fdout = fdctx ? fdctx->fdout : STDOUT_FILENO;
|
|
|
d4f88d |
|
|
|
d4f88d |
if ((ret = sfrt_get_driver_ctx(argv,envp,flags,fdctx,&dctx)))
|
|
|
7ed7e6 |
return (ret == SFRT_USAGE)
|
|
|
69302d |
? !argv || !argv[0] || !argv[1]
|
|
|
7ed7e6 |
: SFRT_ERROR;
|
|
|
9e67a4 |
|
|
|
9e67a4 |
if (dctx->cctx->drvflags & SFRT_DRIVER_VERSION)
|
|
|
985580 |
if ((sfrt_version(dctx,fdout)) < 0)
|
|
|
7ed7e6 |
return sfrt_exit(dctx,SFRT_ERROR);
|
|
|
9e67a4 |
|
|
|
9e67a4 |
if (dctx->cctx->anystring) /* dummy */
|
|
|
2dfa01 |
if ((sfrt_output_dummy(dctx)) < 0) /* dummy */
|
|
|
9e67a4 |
return sfrt_exit(dctx,2); /* dummy */
|
|
|
9e67a4 |
/* dummy */
|
|
|
dcd526 |
for (unit=dctx->units; *unit && !dctx->errv[0]; unit++) {
|
|
|
9e67a4 |
if (!(sfrt_get_unit_ctx(dctx,*unit,&uctx))) {
|
|
|
3be86d |
sfrt_perform_unit_actions(dctx,uctx);
|
|
|
9e67a4 |
sfrt_free_unit_ctx(uctx);
|
|
|
9e67a4 |
}
|
|
|
9e67a4 |
}
|
|
|
9e67a4 |
|
|
|
7ed7e6 |
return sfrt_exit(dctx,dctx->errv[0] ? SFRT_ERROR : SFRT_OK);
|
|
|
9e67a4 |
}
|