From f36484f4043be83dba7e3a242d96636f2f7a29c1 Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Thu, 18 Jul 2013 11:29:10 +0200 Subject: 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 --- src/Makefile.am | 1 + src/calcurse.c | 101 +-------------------------------------- src/calcurse.h | 3 ++ src/help.c | 144 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 149 insertions(+), 100 deletions(-) create mode 100644 src/help.c (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index 85a8780..3559a25 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -19,6 +19,7 @@ calcurse_SOURCES = \ day.c \ event.c \ getstring.c \ + help.c \ ical.c \ io.c \ keys.c \ diff --git a/src/calcurse.c b/src/calcurse.c index 2588721..3879fec 100644 --- a/src/calcurse.c +++ b/src/calcurse.c @@ -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, diff --git a/src/calcurse.h b/src/calcurse.h index a433361..38b18e1 100644 --- a/src/calcurse.h +++ b/src/calcurse.h @@ -723,6 +723,9 @@ void event_paste_item(struct event *, long); enum getstr getstring(WINDOW *, char *, int, int, int); int updatestring(WINDOW *, char **, int, int); +/* help.c */ +int display_help(const char *); + /* ical.c */ void ical_import_data(FILE *, FILE *, unsigned *, unsigned *, unsigned *, unsigned *, unsigned *); diff --git a/src/help.c b/src/help.c new file mode 100644 index 0000000..bf755fd --- /dev/null +++ b/src/help.c @@ -0,0 +1,144 @@ +/* + * Calcurse - text-based organizer + * + * Copyright (c) 2004-2013 calcurse Development Team + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above + * copyright notice, this list of conditions and the + * following disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the + * following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Send your feedback or comments to : misc@calcurse.org + * Calcurse home page : http://calcurse.org + * + */ + +#include "calcurse.h" + +int display_help(const char *topic) +{ + char path[BUFSIZ]; + + if (!topic) + topic = "intro"; + + snprintf(path, BUFSIZ, DOCDIR "/%s.txt", topic); + + if (!io_file_exists(path) && keys_str2int(topic) > 0 && + keys_get_action(keys_str2int(topic)) > 0) { + int ch = keys_str2int(topic); + enum key action = keys_get_action(ch); + topic = keys_get_label(action); + snprintf(path, BUFSIZ, DOCDIR "/%s.txt", topic); + } + + if (!io_file_exists(path)) { + if (!strcmp(topic, "generic-credits")) + topic = "credits"; + else if (!strcmp(topic, "generic-help")) + topic = "intro"; + else if (!strcmp(topic, "generic-save")) + topic = "save"; + else if (!strcmp(topic, "generic-copy")) + topic = "copy_paste"; + else if (!strcmp(topic, "generic-paste")) + topic = "copy_paste"; + else if (!strcmp(topic, "generic-change-view")) + topic = "tab"; + else if (!strcmp(topic, "generic-import")) + topic = "import"; + else if (!strcmp(topic, "generic-export")) + topic = "export"; + else if (!strcmp(topic, "generic-goto")) + topic = "goto"; + else if (!strcmp(topic, "generic-other-cmd")) + topic = "other"; + else if (!strcmp(topic, "generic-config-menu")) + topic = "config"; + else if (!strcmp(topic, "generic-add-appt")) + topic = "general"; + else if (!strcmp(topic, "generic-add-todo")) + topic = "general"; + else if (!strcmp(topic, "generic-prev-day")) + topic = "general"; + else if (!strcmp(topic, "generic-next-day")) + topic = "general"; + else if (!strcmp(topic, "generic-prev-week")) + topic = "general"; + else if (!strcmp(topic, "generic-next-week")) + topic = "general"; + else if (!strcmp(topic, "generic-prev-month")) + topic = "general"; + else if (!strcmp(topic, "generic-next-month")) + topic = "general"; + else if (!strcmp(topic, "generic-prev-year")) + topic = "general"; + else if (!strcmp(topic, "generic-next-year")) + topic = "general"; + else if (!strcmp(topic, "generic-goto-today")) + topic = "general"; + else if (!strcmp(topic, "move-right")) + topic = "displacement"; + else if (!strcmp(topic, "move-left")) + topic = "displacement"; + else if (!strcmp(topic, "move-down")) + topic = "displacement"; + else if (!strcmp(topic, "move-up")) + topic = "displacement"; + else if (!strcmp(topic, "start-of-week")) + topic = "displacement"; + else if (!strcmp(topic, "end-of-week")) + topic = "displacement"; + else if (!strcmp(topic, "add-item")) + topic = "add"; + else if (!strcmp(topic, "del-item")) + topic = "delete"; + else if (!strcmp(topic, "edit-item")) + topic = "edit"; + else if (!strcmp(topic, "view-item")) + topic = "view"; + else if (!strcmp(topic, "pipe-item")) + topic = "pipe"; + else if (!strcmp(topic, "flag-item")) + topic = "flag"; + else if (!strcmp(topic, "repeat")) + topic = "repeat"; + else if (!strcmp(topic, "edit-note")) + topic = "enote"; + else if (!strcmp(topic, "view-note")) + topic = "vnote"; + else if (!strcmp(topic, "raise-priority")) + topic = "priority"; + else if (!strcmp(topic, "lower-priority")) + topic = "priority"; + snprintf(path, BUFSIZ, DOCDIR "/%s.txt", topic); + } + + if (io_file_exists(path)) { + wins_launch_external(path, conf.pager); + return 1; + } else { + return 0; + } +} -- cgit v1.2.3