ctdlsh now has two working commands, 'date' and 'passwd'
[citadel.git] / ctdlsh / src / main.c
index c47b89c997db3edcc84f3c1c4de3ac94caa4f625..3dd4b9dd7136d16eec6cbacd3f08cdc16f35244b 100644 (file)
@@ -8,30 +8,45 @@
 
 
 
-int cmd_quit(char *cmdbuf) {
-       abort();
+int cmd_quit(int sock, char *cmdbuf) {
+       return(cmdret_exit);
 }
 
 
-
-
 /*
  * Commands understood by ctdlsh
  */
 typedef struct {
        char *name;
-       rl_icpfunc_t *func;
+       ctdlsh_cmdfunc_t *func;
        char *doc;
 } COMMAND;
 
-
 COMMAND commands[] = {
+       {       "?",            cmd_help,       "Display this message"                  },
+       {       "help",         cmd_help,       "Display this message"                  },
        {       "quit",         cmd_quit,       "Quit using ctdlsh"                     },
+       {       "exit",         cmd_quit,       "Quit using ctdlsh"                     },
        {       "date",         cmd_datetime,   "Print the server's date and time"      },
+       {       "time",         cmd_datetime,   "Print the server's date and time"      },
+       {       "passwd",       cmd_passwd,     "Set or change an account password"     },
        {       NULL,           NULL,           NULL                                    }
 };
 
 
+int cmd_help(int sock, char *cmdbuf) {
+       int i;
+
+       for (i=0; commands[i].func != NULL; ++i) {
+               printf("%-10s %s\n", commands[i].name, commands[i].doc);
+       }
+}
+
+
+
+
+
+
 int discover_ipgm_secret(char *dirname) {
        int fd;
        struct partial_config ccc;
@@ -101,6 +116,7 @@ void do_main_loop(int server_socket) {
        char buf[1024];
        char server_reply[1024];
        int i;
+       int ret = (-1);
 
        strcpy(prompt, "> ");
 
@@ -121,11 +137,17 @@ void do_main_loop(int server_socket) {
        rl_attempted_completion_function = ctdlsh_completion;
 
        /* Here we go ... main command loop */
-       while (cmd = readline(prompt)) {
+       while ((ret != cmdret_exit) && (cmd = readline(prompt))) {
 
                if ((cmd) && (*cmd)) {
                        add_history(cmd);
-                       /* FIXME put something here */
+
+                       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);
+                               }
+                       }
+
                }
 
                free(cmd);