+
+int cmd_quit(int sock, char *cmdbuf) {
+ return(cmdret_exit);
+}
+
+
+/*
+ * Commands understood by ctdlsh
+ */
+typedef struct {
+ char *name;
+ 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" },
+ { "shutdown", cmd_shutdown, "Shut down the Citadel server" },
+ { 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);
+ }
+}
+
+
+/* Auto-completer function */
+char *command_generator(const char *text, int state) {
+ static int list_index;
+ static int len;
+ char *name;
+
+ if (!state) {
+ list_index = 0;
+ len = strlen(text);
+ }
+
+ while (name = commands[list_index].name) {
+ ++list_index;
+
+ if (!strncmp(name, text, len)) {
+ return(strdup(name));
+ }
+ }
+
+ return(NULL);
+}
+
+
+/* Auto-completer function */
+char **ctdlsh_completion(const char *text, int start, int end) {
+ char **matches = (char **) NULL;
+
+ if (start == 0) {
+ matches = rl_completion_matches(text, command_generator);
+ }
+ else {
+ rl_bind_key('\t', rl_abort);
+ }
+
+ return (matches);
+}
+
+
+void do_main_loop(int server_socket) {