X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=ctdlsh%2Fmain.c;h=cda33ec44c1fff20c562b3d02dc04576afbf815e;hb=eda46d460765e708116f0225f6435b576c2869d4;hp=b159c9c12185ad9d74e02f0db0b40fde7dfec67c;hpb=78a4a16e111b8d56d72ff2714995282ddb8728e0;p=citadel.git diff --git a/ctdlsh/main.c b/ctdlsh/main.c index b159c9c12..cda33ec44 100644 --- a/ctdlsh/main.c +++ b/ctdlsh/main.c @@ -6,8 +6,9 @@ #include "ctdlsh.h" -int cmd_quit(int sock, char *cmdbuf) { - return(cmdret_exit); +int cmd_quit(int sock, char *cmdbuf) +{ + return (cmdret_exit); } @@ -21,33 +22,35 @@ typedef struct { } COMMAND; COMMAND commands[] = { - { "?", cmd_help, "Display this message" }, - { "help", cmd_help, "Display this message" }, - { "date", cmd_datetime, "Print the server's date and time" }, - { "config", cmd_config, "Configure the Citadel server" }, - { "export", cmd_export, "Export all Citadel databases" }, - { "shutdown", cmd_shutdown, "Shut down the Citadel server" }, - { "time", cmd_datetime, "Print the server's date and time" }, - { "passwd", cmd_passwd, "Set or change an account password" }, - { "who", cmd_who, "Display a list of online users" }, - { "exit", cmd_quit, "Quit using ctdlsh" }, - { "quit", cmd_quit, "Quit using ctdlsh" }, - { "mailq", cmd_mailq, "Show the outbound email queue" }, - { NULL, NULL, NULL } + {"?", cmd_help, "Display this message"}, + {"help", cmd_help, "Display this message"}, + {"date", cmd_datetime, "Print the server's date and time"}, + {"config", cmd_config, "Configure the Citadel server"}, + {"export", cmd_export, "Export all Citadel databases"}, + {"shutdown", cmd_shutdown, "Shut down the Citadel server"}, + {"time", cmd_datetime, "Print the server's date and time"}, + {"passwd", cmd_passwd, "Set or change an account password"}, + {"who", cmd_who, "Display a list of online users"}, + {"exit", cmd_quit, "Quit using ctdlsh"}, + {"quit", cmd_quit, "Quit using ctdlsh"}, + {"mailq", cmd_mailq, "Show the outbound email queue"}, + {NULL, NULL, NULL} }; -int cmd_help(int sock, char *cmdbuf) { +int cmd_help(int sock, char *cmdbuf) +{ int i; - for (i=0; commands[i].func != NULL; ++i) { + for (i = 0; commands[i].func != NULL; ++i) { printf("%-10s %s\n", commands[i].name, commands[i].doc); } } /* Auto-completer function */ -char *command_generator(const char *text, int state) { +char *command_generator(const char *text, int state) +{ static int list_index; static int len; char *name; @@ -61,23 +64,23 @@ char *command_generator(const char *text, int state) { ++list_index; if (!strncmp(name, text, len)) { - return(strdup(name)); + return (strdup(name)); } } - return(NULL); + return (NULL); } /* Auto-completer function */ -char **ctdlsh_completion(const char *text, int start, int end) { +char **ctdlsh_completion(const char *text, int start, int end) +{ char **matches = (char **) NULL; rl_completer_word_break_characters = " "; if (start == 0) { matches = rl_completion_matches(text, command_generator); - } - else { + } else { rl_bind_key('\t', rl_abort); } @@ -85,10 +88,11 @@ char **ctdlsh_completion(const char *text, int start, int end) { } -int do_one_command(int server_socket, char *cmd) { +int do_one_command(int server_socket, char *cmd) +{ int i; int ret; - for (i=0; commands[i].func != NULL; ++i) { + for (i = 0; commands[i].func != NULL; ++i) { if (!strncasecmp(cmd, commands[i].name, strlen(commands[i].name))) { ret = (*commands[i].func) (server_socket, cmd); } @@ -97,7 +101,8 @@ int do_one_command(int server_socket, char *cmd) { } -void do_main_loop(int server_socket) { +void do_main_loop(int server_socket) +{ char *cmd = NULL; char prompt[1024]; char buf[1024]; @@ -112,7 +117,7 @@ void do_main_loop(int server_socket) { sock_getln(server_socket, buf, sizeof buf); if (buf[0] == '1') { i = 0; - while(sock_getln(server_socket, buf, sizeof buf), strcmp(buf, "000")) { + while (sock_getln(server_socket, buf, sizeof buf), strcmp(buf, "000")) { if (i == 1) { sprintf(prompt, "\n%s> ", buf); } @@ -131,9 +136,9 @@ void do_main_loop(int server_socket) { ret = do_one_command(server_socket, cmd); //for (i=0; commands[i].func != NULL; ++i) { - //if (!strncasecmp(cmd, commands[i].name, strlen(commands[i].name))) { - //ret = (*commands[i].func) (server_socket, cmd); - //} + //if (!strncasecmp(cmd, commands[i].name, strlen(commands[i].name))) { + //ret = (*commands[i].func) (server_socket, cmd); + //} //} } @@ -152,14 +157,13 @@ int main(int argc, char **argv) char buf[1024]; int i; char *ctdldir = CTDLDIR; - char cmd[1024] = { 0 } ; + char cmd[1024] = { 0 }; int exitcode = 0; - for (i=1; i 0) { strcat(cmd, " "); } @@ -171,9 +175,8 @@ int main(int argc, char **argv) if (is_interactive) { printf("\nCitadel administration shell (c) 2009-2017 by citadel.org\n" - "This is open source software made available to you under the terms\n" - "of the GNU General Public License v3. All other rights reserved.\n" - ); + "This is open source software made available to you under the terms\n" + "of the GNU General Public License v3. All other rights reserved.\n"); printf("Trying %s...\n", ctdldir); } @@ -188,8 +191,7 @@ int main(int argc, char **argv) if (is_interactive) { printf("Connected: %s\n", buf); do_main_loop(server_socket); - } - else { + } else { exitcode = do_one_command(server_socket, cmd); } }