cammy/bin/main.c

72 lines
1.7 KiB
C
Raw Normal View History

2016-05-07 16:11:34 -05:00
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
2016-05-07 16:11:34 -05:00
#include <cammy/sram.h>
#include "commands.h"
2016-05-17 02:23:19 -05:00
2016-07-06 17:12:47 -05:00
static struct {
char *name;
int (*fun)(int, char **);
} commands[] = {
{ "import", cammy_import },
{ "export", cammy_export },
{ "dither", cammy_dither },
{ "rgb-split", cammy_rgb_split },
{ "rgb-merge", cammy_rgb_merge },
{ "tile-import", cammy_tile_import },
{ "tile-export", cammy_tile_export },
{ "tile-convert", cammy_tile_convert },
{ "slice", cammy_slice },
{ NULL, NULL }
};
static void usage(int argc, char **argv, const char *message, ...) {
int i;
2016-05-07 16:11:34 -05:00
if (message) {
va_list args;
va_start(args, message);
vfprintf(stderr, message, args);
va_end(args);
fprintf(stderr, "\n");
}
2016-07-06 17:12:47 -05:00
for (i=0; commands[i].name; i++) {
if (i == 0) {
2016-07-06 19:03:19 -05:00
fprintf(stderr, "usage: %s %s ...\n", argv[0], commands[i].name);
2016-07-06 17:12:47 -05:00
} else {
2016-07-06 19:03:19 -05:00
fprintf(stderr, " %s %s ...\n", argv[0], commands[i].name);
2016-07-06 17:12:47 -05:00
}
}
2016-05-07 16:11:34 -05:00
exit(1);
}
2016-07-06 17:12:47 -05:00
void cammy_validate_photo_number(int argc, char **argv, int num) {
if (num < 1 || num > CAMMY_SRAM_PHOTO_COUNT) {
2016-07-06 17:12:47 -05:00
usage(argc, argv, "Invalid photo number");
}
}
2016-05-16 00:46:28 -05:00
int main(int argc, char **argv) {
int i;
if (argc < 2) {
2016-07-06 17:12:47 -05:00
usage(argc, argv, "No command specified");
2016-05-16 00:46:28 -05:00
}
for (i=0; commands[i].name; i++) {
if (strcmp(argv[1], commands[i].name) == 0) {
return commands[i].fun(argc, argv);
}
}
2016-07-06 17:12:47 -05:00
usage(argc, argv, "Unknown command '%s'", argv[1]);
2016-05-16 00:46:28 -05:00
return 0;
}