static void show_help(const char *data) { COMMAND_REC *rec, *last; GSList *tmp, *cmdlist; int items, findlen; int header, found, fullmatch; g_return_if_fail(data != NULL); /* sort the commands list */ commands = g_slist_sort(commands, (GCompareFunc) commands_equal); /* print command, sort by category */ cmdlist = NULL; last = NULL; header = FALSE; fullmatch = FALSE; items = 0; findlen = strlen(data); found = FALSE; for (tmp = commands; tmp != NULL; last = rec, tmp = tmp->next) { rec = tmp->data; if (last != NULL && rec->category != NULL && (last->category == NULL || strcmp(rec->category, last->category) != 0)) { /* category changed */ if (items > 0) { if (!header) { printtext(NULL, NULL, MSGLEVEL_CLIENTCRAP, "Irssi commands:"); header = TRUE; } if (last->category != NULL) { printtext(NULL, NULL, MSGLEVEL_CLIENTCRAP, ""); printtext(NULL, NULL, MSGLEVEL_CLIENTCRAP, "%s:", last->category); } help_category(cmdlist, items); } g_slist_free(cmdlist); cmdlist = NULL; items = 0; } if (last != NULL && g_strcasecmp(rec->cmd, last->cmd) == 0) continue; /* don't display same command twice */ if ((int)strlen(rec->cmd) >= findlen && g_strncasecmp(rec->cmd, data, findlen) == 0) { if (rec->cmd[findlen] == '\0') { fullmatch = TRUE; found = TRUE; break; } else if (strchr(rec->cmd+findlen+1, ' ') == NULL) { /* not a subcommand (and matches the query) */ items++; cmdlist = g_slist_append(cmdlist, rec); found = TRUE; } } } if ((!found || fullmatch) && !show_help_file(data)) { printtext(NULL, NULL, MSGLEVEL_CLIENTCRAP, "No help for %s", data); } if (*data != '\0' && data[strlen(data)-1] != ' ' && command_have_sub(data)) { char *cmd; cmd = g_strconcat(data, " ", NULL); show_help(cmd); g_free(cmd); } if (items != 0) { /* display the last category */ if (!header) { printtext(NULL, NULL, MSGLEVEL_CLIENTCRAP, "Irssi commands:"); header = TRUE; } if (last->category != NULL) { printtext(NULL, NULL, MSGLEVEL_CLIENTCRAP, ""); printtext(NULL, NULL, MSGLEVEL_CLIENTCRAP, "%s:", last->category); } help_category(cmdlist, items); g_slist_free(cmdlist); } }
static void help_cb(GtkWidget *widget) { show_help_file("help.txt"); }