tabby/bin/main.c
XANTRONIX Development 39d1e331f6 Whitespace
2016-07-04 18:29:53 -05:00

56 lines
1.1 KiB
C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <stdarg.h>
#include <unistd.h>
#include <errno.h>
#include <tabby/link.h>
#include <tabby/printer.h>
#include "commands.h"
static void usage(int argc, char **argv, char *message, ...) {
if (message) {
va_list args;
va_start(args, message);
vfprintf(stderr, message, args);
fprintf(stderr, "\n");
va_end(args);
}
fprintf(stderr, "usage: %1$s print ...\n"
" %1$s capture ...\n",
argv[0]);
exit(1);
}
static struct {
char *name;
int (*fun)(int, char **);
} commands[] = {
{ "print", tabby_command_print },
{ "capture", tabby_command_capture },
{ NULL, NULL }
};
int main(int argc, char **argv) {
int i;
if (argc < 2) {
usage(argc, argv, "No command specified");
}
for (i=0; commands[i].name; i++) {
if (strcmp(argv[1], commands[i].name) == 0) {
return commands[i].fun(argc, argv);
}
}
usage(argc, argv, "Unknown command '%s'", argv[1]);
return 0;
}