summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Worth <cworth@raht.cworth.org>2006-02-15 00:42:53 -0800
committerCarl Worth <cworth@raht.cworth.org>2006-02-15 00:42:53 -0800
commited25b0cd454d216034d9419e45e28312fd96c1b2 (patch)
treef3bbb5a134528f418fe8eb02fb40801c7b50b78c
parent98a8dc72fcd3c813bdd16ae685913e7934081006 (diff)
Move strcmp of command name into main loop
-rw-r--r--ssh-bleach.c70
1 files changed, 33 insertions, 37 deletions
diff --git a/ssh-bleach.c b/ssh-bleach.c
index c31ec7f..d0cab2b 100644
--- a/ssh-bleach.c
+++ b/ssh-bleach.c
@@ -20,13 +20,11 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
int cvs_server (char *line) {
- if (!strcmp (line, "cvs server")) {
- printf ("cvs server\n");
- return execl ("/usr/bin/cvs", "cvs", "server", NULL);
- }
- return 0;
+ printf ("cvs server\n");
+ return execl ("/usr/bin/cvs", "cvs", "server", NULL);
}
char *get_quoted_arg (char *line)
@@ -57,40 +55,37 @@ char *get_quoted_arg (char *line)
}
int git_receive_pack (char *line) {
- char *arg;
-
- if (!strncmp (line, "git-receive-pack '", 18) &&
- (arg = get_quoted_arg (line)))
- {
- printf ("git-receive-pack '%s'\n", arg);
- return execl ("/usr/local/bin/git-receive-pack",
- "git-receive-pack",
- arg,
- NULL);
- }
- return 0;
+ char *arg = get_quoted_arg (line);
+ if (! arg)
+ return 0;
+
+ printf ("git-receive-pack '%s'\n", arg);
+ return execl ("/usr/local/bin/git-receive-pack",
+ "git-receive-pack",
+ arg,
+ NULL);
}
int git_upload_pack (char *line) {
- char *arg;
-
- if (!strncmp (line, "git-upload-pack '", 17) &&
- (arg = get_quoted_arg (line)))
- {
- printf ("git-upload-pack '%s'\n", arg);
- return execl ("/usr/local/bin/git-upload-pack",
- "git-upload-pack",
- arg,
- NULL);
- }
- return 0;
+ char *arg = get_quoted_arg (line);
+ if (! arg)
+ return 0;
+
+ printf ("git-upload-pack '%s'\n", arg);
+ return execl ("/usr/local/bin/git-upload-pack",
+ "git-upload-pack",
+ arg,
+ NULL);
}
-int (*commands[]) (char *line) = {
- cvs_server,
- git_receive_pack,
- git_upload_pack,
- NULL
+struct {
+ char *name;
+ int (*command) (char *line);
+} commands[] = {
+ { "cvs server", cvs_server },
+ { "git-receive-pack ", git_receive_pack },
+ { "git-upload-pack ", git_upload_pack },
+ { 0 }
};
int main (int argc, char **argv)
@@ -100,8 +95,9 @@ int main (int argc, char **argv)
if (!line)
return 1;
- for (i = 0; commands[i]; i++)
- if ((*commands[i]) (line) != 0)
- break;
+ for (i = 0; commands[i].name; i++)
+ if (! strncmp (line, commands[i].name, strlen (commands[i].name)))
+ if ((*commands[i].command) (line) != 0)
+ break;
return 1;
}