Split online help code into a separate function

Reintroduce help.c and move the online help code into a new function
display_help().

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
This commit is contained in:
Lukas Fleischer
2013-07-18 11:29:10 +02:00
parent beac8bdd9b
commit f36484f404
4 changed files with 149 additions and 100 deletions

View File

@@ -500,107 +500,8 @@ static inline void key_generic_cmd(void)
if (!strcmp(cmd_name, "help")) {
char *topic = strtok(NULL, " ");
char *topic_res = topic;
char path[BUFSIZ];
if (!topic_res)
topic_res = "intro";
snprintf(path, BUFSIZ, DOCDIR "/%s.txt", topic_res);
if (!io_file_exists(path) && keys_str2int(topic_res) > 0 &&
keys_get_action(keys_str2int(topic_res)) > 0) {
int ch = keys_str2int(topic_res);
enum key action = keys_get_action(ch);
topic_res = (char *)keys_get_label(action);
snprintf(path, BUFSIZ, DOCDIR "/%s.txt", topic_res);
}
if (!io_file_exists(path)) {
if (!strcmp(topic_res, "generic-credits"))
topic_res = "credits";
else if (!strcmp(topic_res, "generic-help"))
topic_res = "intro";
else if (!strcmp(topic_res, "generic-save"))
topic_res = "save";
else if (!strcmp(topic_res, "generic-copy"))
topic_res = "copy_paste";
else if (!strcmp(topic_res, "generic-paste"))
topic_res = "copy_paste";
else if (!strcmp(topic_res, "generic-change-view"))
topic_res = "tab";
else if (!strcmp(topic_res, "generic-import"))
topic_res = "import";
else if (!strcmp(topic_res, "generic-export"))
topic_res = "export";
else if (!strcmp(topic_res, "generic-goto"))
topic_res = "goto";
else if (!strcmp(topic_res, "generic-other-cmd"))
topic_res = "other";
else if (!strcmp(topic_res, "generic-config-menu"))
topic_res = "config";
else if (!strcmp(topic_res, "generic-add-appt"))
topic_res = "general";
else if (!strcmp(topic_res, "generic-add-todo"))
topic_res = "general";
else if (!strcmp(topic_res, "generic-prev-day"))
topic_res = "general";
else if (!strcmp(topic_res, "generic-next-day"))
topic_res = "general";
else if (!strcmp(topic_res, "generic-prev-week"))
topic_res = "general";
else if (!strcmp(topic_res, "generic-next-week"))
topic_res = "general";
else if (!strcmp(topic_res, "generic-prev-month"))
topic_res = "general";
else if (!strcmp(topic_res, "generic-next-month"))
topic_res = "general";
else if (!strcmp(topic_res, "generic-prev-year"))
topic_res = "general";
else if (!strcmp(topic_res, "generic-next-year"))
topic_res = "general";
else if (!strcmp(topic_res, "generic-goto-today"))
topic_res = "general";
else if (!strcmp(topic_res, "move-right"))
topic_res = "displacement";
else if (!strcmp(topic_res, "move-left"))
topic_res = "displacement";
else if (!strcmp(topic_res, "move-down"))
topic_res = "displacement";
else if (!strcmp(topic_res, "move-up"))
topic_res = "displacement";
else if (!strcmp(topic_res, "start-of-week"))
topic_res = "displacement";
else if (!strcmp(topic_res, "end-of-week"))
topic_res = "displacement";
else if (!strcmp(topic_res, "add-item"))
topic_res = "add";
else if (!strcmp(topic_res, "del-item"))
topic_res = "delete";
else if (!strcmp(topic_res, "edit-item"))
topic_res = "edit";
else if (!strcmp(topic_res, "view-item"))
topic_res = "view";
else if (!strcmp(topic_res, "pipe-item"))
topic_res = "pipe";
else if (!strcmp(topic_res, "flag-item"))
topic_res = "flag";
else if (!strcmp(topic_res, "repeat"))
topic_res = "repeat";
else if (!strcmp(topic_res, "edit-note"))
topic_res = "enote";
else if (!strcmp(topic_res, "view-note"))
topic_res = "vnote";
else if (!strcmp(topic_res, "raise-priority"))
topic_res = "priority";
else if (!strcmp(topic_res, "lower-priority"))
topic_res = "priority";
snprintf(path, BUFSIZ, DOCDIR "/%s.txt", topic_res);
}
if (io_file_exists(path)) {
wins_launch_external(path, conf.pager);
} else {
if (!display_help(topic)) {
char error_msg[BUFSIZ];
snprintf(error_msg, BUFSIZ,