67 lines
1.4 KiB
C
67 lines
1.4 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <stdarg.h>
|
|
#include <string.h>
|
|
|
|
#include <cammy/camera.h>
|
|
|
|
#include "commands.h"
|
|
|
|
static struct {
|
|
char *name;
|
|
int (*fun)(int, char **);
|
|
} commands[] = {
|
|
{ "import", cammy_import },
|
|
{ "export", cammy_export },
|
|
{ "dither", cammy_dither },
|
|
{ "split", cammy_split },
|
|
{ "merge", cammy_merge },
|
|
{ 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_CAMERA_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;
|
|
}
|