From ed25b0cd454d216034d9419e45e28312fd96c1b2 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Wed, 15 Feb 2006 00:42:53 -0800 Subject: Move strcmp of command name into main loop --- ssh-bleach.c | 70 ++++++++++++++++++++++++++++-------------------------------- 1 file 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 #include #include +#include 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; } -- cgit v1.2.3