git-clone: fix local clone
[git/dscho.git] / shell.c
blob2c4789e944058c7dcab2deb5935a054691550d36
1 #include "cache.h"
2 #include "quote.h"
4 static int do_generic_cmd(const char *me, char *arg)
6 const char *my_argv[4];
8 arg = sq_dequote(arg);
9 if (!arg)
10 die("bad argument");
12 my_argv[0] = me;
13 my_argv[1] = arg;
14 my_argv[2] = NULL;
16 return execvp(me, (char**) my_argv);
19 static struct commands {
20 const char *name;
21 int (*exec)(const char *me, char *arg);
22 } cmd_list[] = {
23 { "git-receive-pack", do_generic_cmd },
24 { "git-upload-pack", do_generic_cmd },
25 { NULL },
28 int main(int argc, char **argv)
30 char *prog;
31 struct commands *cmd;
33 /* We want to see "-c cmd args", and nothing else */
34 if (argc != 3 || strcmp(argv[1], "-c"))
35 die("What do you think I am? A shell?");
37 prog = argv[2];
38 argv += 2;
39 argc -= 2;
40 for (cmd = cmd_list ; cmd->name ; cmd++) {
41 int len = strlen(cmd->name);
42 char *arg;
43 if (strncmp(cmd->name, prog, len))
44 continue;
45 arg = NULL;
46 switch (prog[len]) {
47 case '\0':
48 arg = NULL;
49 break;
50 case ' ':
51 arg = prog + len + 1;
52 break;
53 default:
54 continue;
56 exit(cmd->exec(cmd->name, arg));
58 die("unrecognized command '%s'", prog);