[cig-commits] r6827 - cs/cigma/trunk/tools
luis at geodynamics.org
luis at geodynamics.org
Wed May 9 17:24:14 PDT 2007
Author: luis
Date: 2007-05-09 17:24:12 -0700 (Wed, 09 May 2007)
New Revision: 6827
Added:
cs/cigma/trunk/tools/cigma.c
Log:
Quick and dirty command-dispatcher, for testing purposes.
Added: cs/cigma/trunk/tools/cigma.c
===================================================================
--- cs/cigma/trunk/tools/cigma.c 2007-05-10 00:21:34 UTC (rev 6826)
+++ cs/cigma/trunk/tools/cigma.c 2007-05-10 00:24:12 UTC (rev 6827)
@@ -0,0 +1,48 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+void usage(FILE *fp, const char *pgm)
+{
+ fprintf(fp, "Usage: %s command\n\n", pgm);
+ fprintf(fp, "Commands: \n"
+ " help \n"
+ " init\n"
+ " extract\n"
+ " compare\n"
+ " project\n"
+ );
+}
+
+int match(char *arg, const char *command)
+{
+ return (strcmp(command, arg) == 0);
+}
+
+int main(int argc, char *argv[])
+{
+ int status;
+
+ if (argc == 1)
+ {
+ usage(stderr, argv[0]);
+ return EXIT_FAILURE;
+ }
+
+ if (match(argv[1], "help"))
+ {
+ usage(stdout, argv[0]);
+ return EXIT_SUCCESS;
+ }
+
+ status = execv(argv[1], &argv[1]);
+
+ if (status < 0)
+ {
+ fprintf(stderr, "Command not found: %s\n", argv[1]);
+
+ }
+
+ return status;
+}
More information about the cig-commits
mailing list