cammy/bin/main.c
2016-07-04 19:48:48 -05:00

72 lines
2.2 KiB
C

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <cammy/sram.h>
#include "commands.h"
void cammy_command_usage(int argc, char **argv, const char *message, ...) {
if (message) {
va_list args;
va_start(args, message);
vfprintf(stderr, message, args);
va_end(args);
fprintf(stderr, "\n");
}
fprintf(stderr, "usage: %1$s import file.sav 1..30 input.png\n"
" %1$s export file.sav 1..30 output.png\n"
" %1$s dither input.png output.png\n"
" %1$s split-rgb file.sav rn gn bn input.png\n"
" %1$s merge-rgb file.sav rn gn bn output.png\n"
" %1$s import-tile file.sav 1..30 printer.tile\n"
" %1$s export-tile file.sav 1..30 output.tile\n"
" %1$s convert-tile printer.tile output.png\n"
" %1$s slice x-pad y-pad input.png\n",
argv[0]);
exit(1);
}
void cammy_command_validate_photo_number(int argc, char **argv, int num) {
if (num < 1 || num > CAMMY_SRAM_PHOTO_COUNT) {
cammy_command_usage(argc, argv, "Invalid photo number");
}
}
static struct {
char *name;
int (*fun)(int, char **);
} commands[] = {
{ "import", cammy_command_import },
{ "export", cammy_command_export },
{ "dither", cammy_command_dither },
{ "split-rgb", cammy_command_split_rgb },
{ "merge-rgb", cammy_command_merge_rgb },
{ "import-tile", cammy_command_import_tile },
{ "export-tile", cammy_command_export_tile },
{ "convert-tile", cammy_command_convert_tile },
{ "slice", cammy_command_slice },
{ NULL, NULL }
};
int main(int argc, char **argv) {
int i;
if (argc < 2) {
cammy_command_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);
}
}
cammy_command_usage(argc, argv, "Unknown command '%s'", argv[1]);
return 0;
}