2016-05-07 16:11:34 -05:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
2016-07-04 19:48:48 -05:00
|
|
|
#include <string.h>
|
2016-05-07 16:11:34 -05:00
|
|
|
|
2021-12-03 18:23:04 -05:00
|
|
|
#include <cammy/camera.h>
|
2016-05-11 22:34:09 -05:00
|
|
|
|
2016-07-04 19:48:48 -05:00
|
|
|
#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[] = {
|
2021-11-30 14:10:12 -05:00
|
|
|
{ "import", cammy_import },
|
|
|
|
{ "export", cammy_export },
|
|
|
|
{ "dither", cammy_dither },
|
2021-12-04 17:14:47 -05:00
|
|
|
{ "split", cammy_split },
|
2021-12-07 17:07:36 -05:00
|
|
|
{ "merge", cammy_merge },
|
2021-11-30 14:10:12 -05:00
|
|
|
{ NULL, NULL }
|
2016-07-06 17:12:47 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
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) {
|
2021-12-03 18:23:04 -05:00
|
|
|
if (num < 1 || num > CAMMY_CAMERA_PHOTO_COUNT) {
|
2016-07-06 17:12:47 -05:00
|
|
|
usage(argc, argv, "Invalid photo number");
|
2016-05-20 22:24:11 +00:00
|
|
|
}
|
2016-06-09 01:12:06 -05:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|