GIT 1.0.8
[git/jnareb-git/bp-gitweb.git] / shell.c
blobcd316185e96c73c1f7d0e6309abe3241c2deb7c4
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 if (!arg || !(arg = sq_dequote(arg)))
9 die("bad argument");
11 my_argv[0] = me;
12 my_argv[1] = arg;
13 my_argv[2] = NULL;
15 return execvp(me, (char**) my_argv);
18 static struct commands {
19 const char *name;
20 int (*exec)(const char *me, char *arg);
21 } cmd_list[] = {
22 { "git-receive-pack", do_generic_cmd },
23 { "git-upload-pack", do_generic_cmd },
24 { NULL },
27 int main(int argc, char **argv)
29 char *prog;
30 struct commands *cmd;
32 /* We want to see "-c cmd args", and nothing else */
33 if (argc != 3 || strcmp(argv[1], "-c"))
34 die("What do you think I am? A shell?");
36 prog = argv[2];
37 argv += 2;
38 argc -= 2;
39 for (cmd = cmd_list ; cmd->name ; cmd++) {
40 int len = strlen(cmd->name);
41 char *arg;
42 if (strncmp(cmd->name, prog, len))
43 continue;
44 arg = NULL;
45 switch (prog[len]) {
46 case '\0':
47 arg = NULL;
48 break;
49 case ' ':
50 arg = prog + len + 1;
51 break;
52 default:
53 continue;
55 exit(cmd->exec(cmd->name, arg));
57 die("unrecognized command '%s'", prog);