71 lines
1.7 KiB
C
71 lines
1.7 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <stdarg.h>
|
|
#include <string.h>
|
|
|
|
#include <cammy/sram.h>
|
|
|
|
#include "commands.h"
|
|
|
|
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;
|
|
|
|
if (message) {
|
|
va_list args;
|
|
|
|
va_start(args, message);
|
|
vfprintf(stderr, message, args);
|
|
va_end(args);
|
|
fprintf(stderr, "\n");
|
|
}
|
|
|
|
for (i=0; commands[i].name; i++) {
|
|
if (i == 0) {
|
|
fprintf(stderr, "usage: %s %s ...\n", argv[0], commands[i].name);
|
|
} else {
|
|
fprintf(stderr, " %s %s ...\n", argv[0], commands[i].name);
|
|
}
|
|
}
|
|
|
|
exit(1);
|
|
}
|
|
|
|
void cammy_validate_photo_number(int argc, char **argv, int num) {
|
|
if (num < 1 || num > CAMMY_SRAM_PHOTO_COUNT) {
|
|
usage(argc, argv, "Invalid photo number");
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|