/*
- * (c) 2009-2019 by Art Cancro and citadel.org
+ * (c) 2009-2020 by Art Cancro and citadel.org
* This program is open source. It runs great on the Linux operating system.
* It's released under the General Public License (GPL) version 3.
*/
-struct wow {
- char *cmd[5]; // increase this if we need to have larger commands
- char *description;
-};
-
-struct wow wows[] = {
- {{ "help" } , "list available commands" },
- {{ "date" } , "print the server's date and time" },
- {{ "show", "eggs" } , "show how many eggs are available for serving" },
- {{ "kill", "mark", "zuckerberg" } , "die motherfucker die" },
- {{ "show", "undead", "zombies", "real" } , "show how many zombies are actually undead" },
- {{ "show", "undead", "zombies", "hollywood" } , "show how many zombies are hollywood communists" },
- {{ NULL } , "NULL" }
-};
-
-
-int num_wows = sizeof(wows) / sizeof(struct wow);
-
-
-
-
-
int cmd_help(int sock, char *cmdbuf)
{
int i;
- for (i = 0; wows[i].cmd[0]; ++i) {
- printf("%-10s %s\n", wows[i].cmd[0], wows[i].description);
+ 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)
+int do_one_command(int server_socket, char *cmd)
+{
+ int i;
+ int ret;
+ 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);
+ }
+ }
+ return ret;
+}
+
+char *command_name_generator(const char *text, int state)
{
- static int list_index;
- static int len;
+ static int list_index, len;
char *name;
if (!state) {
len = strlen(text);
}
- while (name = commands[list_index].name) {
- ++list_index;
-
- if (!strncmp(name, text, len)) {
- return (strdup(name));
+ while (name = commands[list_index++].name) {
+ if (strncmp(name, text, len) == 0) {
+ return strdup(name);
}
}
- return (NULL);
+ return NULL;
}
-/* Auto-completer function */
-char **ctdlsh_completion(const char *text, int start, int end)
+char **command_name_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 {
- rl_bind_key('\t', rl_abort);
- }
-
- return (matches);
-}
-
-
-int do_one_command(int server_socket, char *cmd)
-{
- int i;
- int ret;
- 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);
- }
- }
- return ret;
+ rl_attempted_completion_over = 1;
+ return rl_completion_matches(text, command_name_generator);
}
int i;
int ret = (-1);
-
strcpy(prompt, "> ");
/* Do an INFO command and learn the hostname for the prompt */
}
}
- /* Tell libreadline how we will help with auto-completion of commands */
- rl_attempted_completion_function = ctdlsh_completion;
-
/* Here we go ... main command loop */
+ rl_attempted_completion_function = command_name_completion;
while ( (cmd = readline(prompt)) , cmd ) {
if (*cmd) {
add_history(cmd);
int is_interactive = ((strlen(cmd) == 0) ? 1 : 0);
if (is_interactive) {
- printf("\nCitadel administration shell (c) 2009-2019 by citadel.org\n"
+ printf("\nCitadel administration shell (c) 2009-2020 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");
printf("Connecting to Citadel server in %s...\n", ctdldir);