2016-05-28 19:19:08 -05:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2016-06-01 20:33:47 -05:00
|
|
|
#include <string.h>
|
2016-05-28 19:19:08 -05:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdarg.h>
|
2016-06-01 20:33:47 -05:00
|
|
|
#include <unistd.h>
|
2016-05-28 19:19:08 -05:00
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include <tabby/link.h>
|
2016-05-29 14:21:16 -05:00
|
|
|
#include <tabby/printer.h>
|
2016-05-28 19:19:08 -05:00
|
|
|
|
2016-06-10 03:20:20 +00:00
|
|
|
#include "commands.h"
|
|
|
|
|
2016-05-28 19:19:08 -05:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2016-06-10 03:20:20 +00:00
|
|
|
fprintf(stderr, "usage: %1$s print ...\n"
|
2016-06-10 17:34:17 -05:00
|
|
|
" %1$s capture ...\n",
|
2016-06-10 03:20:20 +00:00
|
|
|
argv[0]);
|
2016-05-28 19:19:08 -05:00
|
|
|
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2016-06-10 03:20:20 +00:00
|
|
|
static struct {
|
|
|
|
char *name;
|
|
|
|
int (*fun)(int, char **);
|
|
|
|
} commands[] = {
|
2016-06-10 17:34:17 -05:00
|
|
|
{ "print", tabby_command_print },
|
|
|
|
{ "capture", tabby_command_capture },
|
2016-07-04 18:29:53 -05:00
|
|
|
{ NULL, NULL }
|
2016-06-10 03:20:20 +00:00
|
|
|
};
|
2016-05-28 19:19:08 -05:00
|
|
|
|
2016-06-10 03:20:20 +00:00
|
|
|
int main(int argc, char **argv) {
|
|
|
|
int i;
|
2016-05-28 19:19:08 -05:00
|
|
|
|
2016-06-10 03:20:20 +00:00
|
|
|
if (argc < 2) {
|
|
|
|
usage(argc, argv, "No command specified");
|
2016-05-28 19:19:08 -05:00
|
|
|
}
|
|
|
|
|
2016-06-10 03:20:20 +00:00
|
|
|
for (i=0; commands[i].name; i++) {
|
|
|
|
if (strcmp(argv[1], commands[i].name) == 0) {
|
|
|
|
return commands[i].fun(argc, argv);
|
2016-06-06 19:42:15 -05:00
|
|
|
}
|
2016-06-05 02:39:06 -05:00
|
|
|
}
|
|
|
|
|
2016-06-10 03:20:20 +00:00
|
|
|
usage(argc, argv, "Unknown command '%s'", argv[1]);
|
2016-05-28 19:19:08 -05:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|