static void sig_complete_load(GList **list, WINDOW_REC *window, const char *word, const char *line, int *want_space) { char *user_dir; if (*line != '\0') return; /* completing filename parameter for /SCRIPT LOAD */ user_dir = g_strdup_printf("%s/scripts", get_irssi_dir()); *list = filename_complete(word, user_dir); *list = g_list_concat(*list, filename_complete(word, SCRIPTDIR)); g_free(user_dir); if (*list != NULL) { *want_space = FALSE; signal_stop(); } }
/* first argument of command is file name - complete it */ static void sig_complete_filename(GList **list, WINDOW_REC *window, const char *word, const char *line, int *want_space) { g_return_if_fail(list != NULL); g_return_if_fail(word != NULL); g_return_if_fail(line != NULL); if (*line != '\0') return; *list = filename_complete(word); if (*list != NULL) { *want_space = FALSE; signal_stop(); } }
static void sig_dcc_send_complete(GList **list, WINDOW_REC *window, const char *word, const char *line, int *want_space) { g_return_if_fail(list != NULL); g_return_if_fail(word != NULL); g_return_if_fail(line != NULL); if (*line == '\0' || strchr(line, ' ') != NULL) return; /* completing filename parameter for /DCC SEND */ *list = filename_complete(word); if (*list != NULL) { *want_space = FALSE; signal_stop(); } }
static void sig_complete_word(GList **list, WINDOW_REC *window, const char *word, const char *linestart, int *want_space) { const char *newword, *cmdchars; char *signal, *cmd, *args, *line; g_return_if_fail(list != NULL); g_return_if_fail(word != NULL); g_return_if_fail(linestart != NULL); /* check against "completion words" list */ newword = completion_find(word, FALSE); if (newword != NULL) { *list = g_list_append(*list, g_strdup(newword)); signal_stop(); return; } if (*linestart != '\0' && (*word == '/' || *word == '~')) { /* quite likely filename completion */ *list = g_list_concat(*list, filename_complete(word, NULL)); if (*list != NULL) { *want_space = FALSE; signal_stop(); return; } } /* command completion? */ cmdchars = settings_get_str("cmdchars"); if (*word != '\0' && ((*linestart == '\0' && strchr(cmdchars, *word)) || (*linestart != '\0' && linestart[1] == '\0' && strchr(cmdchars, *linestart)))) { gboolean skip = *linestart == '\0' ? TRUE : FALSE; /* complete /command */ *list = completion_get_commands(word + (skip ? 1 : 0), skip ? *word : '\0'); /* complete aliases, too */ *list = g_list_concat(*list, completion_get_aliases(word + (skip ? 1 : 0), skip ? *word : '\0')); if (*list != NULL) signal_stop(); return; } /* check only for /command completions from now on */ if (*linestart == '\0') return; cmdchars = strchr(cmdchars, *linestart); if (cmdchars == NULL) return; /* check if there's aliases */ line = linestart[1] == *cmdchars ? g_strdup(linestart+2) : expand_aliases(linestart+1); cmd = line_get_command(line, &args, FALSE); if (cmd == NULL) { g_free(line); return; } /* we're completing -option? */ if (*word == '-') { *list = completion_get_options(cmd, word+1); if (*list != NULL) signal_stop(); g_free(cmd); g_free(line); return; } /* complete parameters */ signal = g_strconcat("complete command ", cmd, NULL); signal_emit(signal, 5, list, window, word, args, want_space); if (command_have_sub(line)) { /* complete subcommand */ g_free(cmd); cmd = g_strconcat(line, " ", word, NULL); *list = g_list_concat(completion_get_subcommands(cmd), *list); } if (*list != NULL) signal_stop(); g_free(signal); g_free(cmd); g_free(line); }