main.c (1070B)
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h> 4 5 #include "command/command.h" 6 #include "common/usage.h" 7 #include "erkkah/naett.h" 8 #include "rxi/microtar.h" 9 10 struct cmd_struct *commands = NULL; 11 12 int main(int argc, const char **argv) { 13 int show_version = 0; 14 15 argc = dep_global_options(argc, argv, &show_version); 16 17 /* --version is nothing but another way of calling the version command */ 18 if (show_version) { 19 static const char *version_argv[] = {"version", NULL}; 20 argv = version_argv; 21 argc = 1; 22 } 23 24 if (argc < 1) { 25 dep_print_global_usage(); 26 return 0; 27 } 28 29 /* Try to run command with args provided. */ 30 struct cmd_struct *cmd = commands; 31 while (cmd) { 32 const char **name = cmd->name; 33 while (*name) { 34 if (!strcmp(*name, argv[0])) { 35 goto found; 36 } 37 name++; 38 } 39 cmd = cmd->next; 40 } 41 found: 42 43 if (cmd) { 44 return cmd->fn(argc, argv); 45 } else { 46 fprintf(stderr, "Unknown command: %s\n", argv[0]); 47 return 1; 48 } 49 50 return 0; 51 }