78 lines
1.7 KiB
C
78 lines
1.7 KiB
C
/*
|
|
* mpl.c
|
|
*
|
|
* by Alexander Zhirov (alexander@zhirov.kz)
|
|
* Telegram @alexanderzhirov
|
|
*/
|
|
|
|
#include "mpl.h"
|
|
#include <getopt.h>
|
|
|
|
static MPL *mpl;
|
|
|
|
const char *const short_options = "hcv";
|
|
|
|
const struct option long_options[] = {
|
|
{"help", 0, NULL, 'h'},
|
|
{"check-devices", 0, NULL, 'c'},
|
|
{"version", 0, NULL, 'v'},
|
|
{NULL, 0, NULL, 0}};
|
|
|
|
[[noreturn]] void static print_usage_and_exit(int code)
|
|
{
|
|
printf("Usage: %s [OPTION]...\n\n", MPL_NAME);
|
|
puts(" -c, --check-devices checking connected devices at startup");
|
|
puts(" -h, --help display this help text and exit");
|
|
puts(" -v, --version display version information and exit\n");
|
|
exit(code);
|
|
}
|
|
|
|
[[noreturn]] void static print_version_and_exit()
|
|
{
|
|
printf("%s version %s\n", MPL_NAME, VERSION);
|
|
exit(0);
|
|
}
|
|
|
|
static void signals_handler(int signum)
|
|
{
|
|
MPLOG(LOG_WARNING, "cancelling the mportlink loop (%d)", signum);
|
|
mpl->cancellable.signal = signum;
|
|
mpl->cancellable.exit = 1;
|
|
}
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
int c;
|
|
|
|
MPL_PARAMETERS parameters =
|
|
{
|
|
.check_device = 0
|
|
};
|
|
|
|
while ((c = getopt_long(argc, argv, short_options, long_options, NULL)) != -1)
|
|
switch (c)
|
|
{
|
|
case 'c':
|
|
parameters.check_device = 1;
|
|
break;
|
|
case 'v':
|
|
print_version_and_exit();
|
|
case 'h':
|
|
print_usage_and_exit(0);
|
|
case '?':
|
|
print_usage_and_exit(1);
|
|
}
|
|
|
|
mpl = mpl_init(¶meters);
|
|
|
|
signal(SIGHUP, signals_handler);
|
|
signal(SIGINT, signals_handler);
|
|
signal(SIGTERM, signals_handler);
|
|
|
|
mpl_loop(mpl);
|
|
|
|
mpl_stop(mpl);
|
|
|
|
return 0;
|
|
}
|