]> git.ozlabs.org Git - petitboot/commitdiff
ui/ncurses: Use a separate type for help text
authorJeremy Kerr <jk@ozlabs.org>
Tue, 24 Jun 2014 05:18:03 +0000 (13:18 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Mon, 28 Jul 2014 05:20:34 +0000 (13:20 +0800)
Because it's initialised statically, help text won't be directly
gettext()-ed. Instead, we need to perform the gettext translation at
runtime, and pass untranslated strings into the help_screen code.

Instead of trusting callers to pass the untranslated strings though, we
encapsulate the help text data into struct help_text, so we know we have
an unstranslated string.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
14 files changed:
ui/ncurses/generic-main-help.c
ui/ncurses/generic-main.c
ui/ncurses/nc-boot-editor-help.c
ui/ncurses/nc-boot-editor.c
ui/ncurses/nc-config-help.c
ui/ncurses/nc-config.c
ui/ncurses/nc-cui.c
ui/ncurses/nc-cui.h
ui/ncurses/nc-helpscreen.c
ui/ncurses/nc-helpscreen.h
ui/ncurses/nc-menu.h
ui/ncurses/nc-sysinfo.c
ui/ncurses/nc-textscreen.c
ui/ncurses/nc-textscreen.h

index d3c566248d74a2db397eb4c47cbb793e9c2d4f3a..ac690c500aa824ed1b74064570ab9bbbfb3759b1 100644 (file)
@@ -1,5 +1,7 @@
 
 
-const char *main_menu_help_text =
+#include "nc-helpscreen.h"
+
+struct help_text main_menu_help_text = define_help_text(
 "From the main menu screen, select a boot option. The options displayed are \
 available on the system and the network.\n\
 \n\
 "From the main menu screen, select a boot option. The options displayed are \
 available on the system and the network.\n\
 \n\
@@ -14,4 +16,5 @@ network interface, type I (information).\n\
 \n\
 To make changes to the system configuration, type C (configure).\n\
 \n\
 \n\
 To make changes to the system configuration, type C (configure).\n\
 \n\
-To close the Petitboot interface, type X (exit).\n";
+To close the Petitboot interface, type X (exit).\n"
+);
index abf33563a13a10bf5cb82c3fb6a67bfe3a160d72..f253469f18832da67ff44102c6d3f5fbfa2616aa 100644 (file)
@@ -40,7 +40,7 @@
 #include "ui/common/discover-client.h"
 #include "nc-cui.h"
 
 #include "ui/common/discover-client.h"
 #include "nc-cui.h"
 
-extern const char *main_menu_help_text;
+extern const struct help_text main_menu_help_text;
 
 static void print_version(void)
 {
 
 static void print_version(void)
 {
@@ -234,7 +234,7 @@ static struct pmenu *pb_mm_init(struct pb_cui *pb_cui)
        }
 
        m->help_title = _("main menu");
        }
 
        m->help_title = _("main menu");
-       m->help_text = main_menu_help_text;
+       m->help_text = &main_menu_help_text;
 
        menu_opts_off(m->ncm, O_SHOWDESC);
        set_menu_mark(m->ncm, " *");
 
        menu_opts_off(m->ncm, O_SHOWDESC);
        set_menu_mark(m->ncm, " *");
index 3f0c7fbce354ae6dc9fa9b0f908f92ac8d88b56b..4c0ba24dd0a7b137262ffdf13a421131e4056539 100644 (file)
@@ -1,4 +1,6 @@
-const char *boot_editor_help_text = "\
+#include "nc-helpscreen.h"
+
+struct help_text boot_editor_help_text = define_help_text("\
 This screen allows you to edit or create boot options.\n\
 \n\
 Device: This is a list of block devices available on the system. Select \
 This screen allows you to edit or create boot options.\n\
 \n\
 Device: This is a list of block devices available on the system. Select \
@@ -21,4 +23,4 @@ Example: /boot/device-tree.dtb\n\
 \n\
 Boot arguments: enter the kernel command-line arguments. This is optional.\n\
 Example: root=/dev/sda1 console=hvc0\n\
 \n\
 Boot arguments: enter the kernel command-line arguments. This is optional.\n\
 Example: root=/dev/sda1 console=hvc0\n\
-\n";
+\n");
index 6bc1d89169b166da53a2eb502ffe12f1545665d5..6da36302f49641ba52c666c7fb75071b0088d3d5 100644 (file)
@@ -73,7 +73,7 @@ struct boot_editor {
        char                    *args;
 };
 
        char                    *args;
 };
 
-extern const char *boot_editor_help_text;
+extern const struct help_text boot_editor_help_text;
 
 static struct boot_editor *boot_editor_from_scr(struct nc_scr *scr)
 {
 
 static struct boot_editor *boot_editor_from_scr(struct nc_scr *scr)
 {
@@ -222,7 +222,7 @@ static void boot_editor_process_key(struct nc_scr *scr, int key)
        case STATE_HELP:
                boot_editor->state = STATE_EDIT;
                cui_show_help(boot_editor->cui, _("Boot Option Editor"),
        case STATE_HELP:
                boot_editor->state = STATE_EDIT;
                cui_show_help(boot_editor->cui, _("Boot Option Editor"),
-                               boot_editor_help_text);
+                               &boot_editor_help_text);
                break;
        default:
                break;
                break;
        default:
                break;
index 828fce73818df3cd756b7bc0c257470d2406d125..18c51d4691ba9ff9fadab246d567e8a49e4b1640 100644 (file)
@@ -1,4 +1,6 @@
-const char *config_help_text = "\
+#include "nc-helpscreen.h"
+
+struct help_text config_help_text = define_help_text("\
 Autoboot: There are three possible options for automatic-boot hehaviour:\n"
 "\n"
 "Don't autoboot: boot options will be listed in the petitboot menu, but none \
 Autoboot: There are three possible options for automatic-boot hehaviour:\n"
 "\n"
 "Don't autoboot: boot options will be listed in the petitboot menu, but none \
@@ -35,5 +37,4 @@ only want to configure a single interface during boot.\n"
 "Static IP configuration: Allows you to specify an IPv4 address and network \
 mask, gateway, and a DNS server or servers for a network interface. Select \
 this option if you do not have a DHCP server, or want explicit control of \
 "Static IP configuration: Allows you to specify an IPv4 address and network \
 mask, gateway, and a DNS server or servers for a network interface. Select \
 this option if you do not have a DHCP server, or want explicit control of \
-network settings."
-;
+network settings.");
index 54eb7ac5740d891bd32c6a7bcc57655cbf19bc8a..a09535371c7131d1f09e19457ecfee2fb2cbef77 100644 (file)
@@ -35,7 +35,7 @@
 
 #define N_FIELDS       25
 
 
 #define N_FIELDS       25
 
-extern const char *config_help_text;
+extern struct help_text config_help_text;
 
 enum autoboot_type {
        AUTOBOOT_ANY,
 
 enum autoboot_type {
        AUTOBOOT_ANY,
@@ -146,7 +146,7 @@ static void config_screen_process_key(struct nc_scr *scr, int key)
        } else if (screen->show_help) {
                screen->show_help = false;
                cui_show_help(screen->cui, _("System Configuration"),
        } else if (screen->show_help) {
                screen->show_help = false;
                cui_show_help(screen->cui, _("System Configuration"),
-                               config_help_text);
+                               &config_help_text);
 
        } else if (handled) {
                pad_refresh(screen);
 
        } else if (handled) {
                pad_refresh(screen);
index 96d82cac21aa184d90c81c3c5a2c95866ed73300..cd7952f860545e90cdf1245035b0b7b69868a57a 100644 (file)
@@ -270,7 +270,8 @@ static void cui_help_exit(struct cui *cui)
        cui->help_screen = NULL;
 }
 
        cui->help_screen = NULL;
 }
 
-void cui_show_help(struct cui *cui, const char *title, const char *text)
+void cui_show_help(struct cui *cui, const char *title,
+               const struct help_text *text)
 {
        if (!cui->current)
                return;
 {
        if (!cui->current)
                return;
index 8632806fcb52d4d2ca38f30f2a1288c39025ea70..e9e4d38b320ce8063b8c881687a9ae69b38b74bb 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "ui/common/joystick.h"
 #include "nc-menu.h"
 
 #include "ui/common/joystick.h"
 #include "nc-menu.h"
+#include "nc-helpscreen.h"
 
 struct cui_opt_data {
        const char *name;
 
 struct cui_opt_data {
        const char *name;
@@ -75,7 +76,8 @@ void cui_item_edit(struct pmenu_item *item);
 void cui_item_new(struct pmenu *menu);
 void cui_show_sysinfo(struct cui *cui);
 void cui_show_config(struct cui *cui);
 void cui_item_new(struct pmenu *menu);
 void cui_show_sysinfo(struct cui *cui);
 void cui_show_config(struct cui *cui);
-void cui_show_help(struct cui *cui, const char *title, const char *text);
+void cui_show_help(struct cui *cui, const char *title,
+               const struct help_text *text);
 int cui_send_config(struct cui *cui, struct config *config);
 void cui_send_reinit(struct cui *cui);
 
 int cui_send_config(struct cui *cui, struct config *config);
 void cui_send_reinit(struct cui *cui);
 
index 3b27d5760090c618a785fd513b2feebecb66127f..fd76a43226b6f59a52cbd679816ad75193518454 100644 (file)
@@ -48,7 +48,8 @@ struct nc_scr *help_screen_return_scr(struct help_screen *screen)
 
 struct help_screen *help_screen_init(struct cui *cui,
                struct nc_scr *current_scr,
 
 struct help_screen *help_screen_init(struct cui *cui,
                struct nc_scr *current_scr,
-               const char *title_suffix, const char *text,
+               const char *title_suffix,
+               const struct help_text *text,
                void (*on_exit)(struct cui *))
 {
        struct help_screen *screen;
                void (*on_exit)(struct cui *))
 {
        struct help_screen *screen;
@@ -63,7 +64,7 @@ struct help_screen *help_screen_init(struct cui *cui,
                                _("Petitboot help: %s"), title_suffix);
 
        text_screen_init(&screen->text_scr, cui, title, on_exit);
                                _("Petitboot help: %s"), title_suffix);
 
        text_screen_init(&screen->text_scr, cui, title, on_exit);
-       text_screen_set_text(&screen->text_scr, text);
+       text_screen_set_text(&screen->text_scr, text->text);
        text_screen_draw(&screen->text_scr);
 
        return screen;
        text_screen_draw(&screen->text_scr);
 
        return screen;
index f1044115d404d4b997f65f057a2ed9a72b9b864f..99b99f7c494afb05a41cd35ca4c38c30eb6a397b 100644 (file)
 #define _NC_HELPSCREEN_H
 
 struct help_screen;
 #define _NC_HELPSCREEN_H
 
 struct help_screen;
+struct cui;
+
+/* Container struct for type-safety; we need to use gettext() before
+ * displaying the untranslated string. */
+struct help_text {
+       const char *text;
+};
+
+#define define_help_text(s) { .text = s }
 
 struct nc_scr *help_screen_scr(struct help_screen *screen);
 struct nc_scr *help_screen_return_scr(struct help_screen *screen);
 
 struct help_screen *help_screen_init(struct cui *cui,
                struct nc_scr *current_scr,
 
 struct nc_scr *help_screen_scr(struct help_screen *screen);
 struct nc_scr *help_screen_return_scr(struct help_screen *screen);
 
 struct help_screen *help_screen_init(struct cui *cui,
                struct nc_scr *current_scr,
-               const char *title_suffix, const char *text,
+               const char *title_suffix,
+               const struct help_text *text,
                void (*on_exit)(struct cui *));
 
                void (*on_exit)(struct cui *));
 
+
 #endif /* defined _NC_HELPSCREEN_H */
 #endif /* defined _NC_HELPSCREEN_H */
index 12eafaf7650c5f902723506acd7abb8a93a1f7bb..2f66bbb2030b603a9a7f1e8c21bb9becee3b5852 100644 (file)
@@ -88,7 +88,7 @@ struct pmenu {
        unsigned int item_count;
        unsigned int insert_pt;
        const char *help_title;
        unsigned int item_count;
        unsigned int insert_pt;
        const char *help_title;
-       const char *help_text;
+       const struct help_text *help_text;
        int (*hot_key)(struct pmenu *menu, struct pmenu_item *item, int c);
        void (*on_exit)(struct pmenu *menu);
        void (*on_new)(struct pmenu *menu);
        int (*hot_key)(struct pmenu *menu, struct pmenu_item *item, int c);
        void (*on_exit)(struct pmenu *menu);
        void (*on_new)(struct pmenu *menu);
index 0d362e481d493ce88fa6ed4ca4478855f6cc6ddb..f79301019da3dd2da228fd5b403a9c9f515e2178 100644 (file)
@@ -35,7 +35,7 @@ struct sysinfo_screen {
        struct text_screen text_scr;
 };
 
        struct text_screen text_scr;
 };
 
-extern const char *sysinfo_help_text;
+extern const struct help_text sysinfo_help_text;
 
 struct nc_scr *sysinfo_screen_scr(struct sysinfo_screen *screen)
 {
 
 struct nc_scr *sysinfo_screen_scr(struct sysinfo_screen *screen)
 {
@@ -115,7 +115,7 @@ struct sysinfo_screen *sysinfo_screen_init(struct cui *cui,
        text_screen_init(&screen->text_scr, cui,
                        _("Petitboot System Information"), on_exit);
        text_screen_set_help(&screen->text_scr,
        text_screen_init(&screen->text_scr, cui,
                        _("Petitboot System Information"), on_exit);
        text_screen_set_help(&screen->text_scr,
-                       _("System Information"), sysinfo_help_text);
+                       _("System Information"), &sysinfo_help_text);
 
        sysinfo_screen_update(screen, sysinfo);
 
 
        sysinfo_screen_update(screen, sysinfo);
 
index 4ae0db42dfb989c824a5ddb1e2a036bdb6bcd35d..826244cb0a0e9618f086e5a47d133ca751a8de2f 100644 (file)
@@ -174,7 +174,7 @@ struct nc_scr *text_screen_scr(struct text_screen *screen)
 }
 
 void text_screen_set_help(struct text_screen *screen, const char *title,
 }
 
 void text_screen_set_help(struct text_screen *screen, const char *title,
-               const char *text)
+               const struct help_text *text)
 {
        screen->help_title = title;
        screen->help_text = text;
 {
        screen->help_title = title;
        screen->help_text = text;
index 72b8c8ae9972c0268fa2ebec653d6e2d3b2b6236..25107cb476caadf32fcf97d311960064ae0cace4 100644 (file)
 #include "nc-cui.h"
 
 struct text_screen {
 #include "nc-cui.h"
 
 struct text_screen {
-       struct nc_scr   scr;
-       struct cui      *cui;
-       const char      **lines;
-       int             n_lines;
-       int             n_alloc_lines;
-       int             scroll_y;
-       const char      *help_title;
-       const char      *help_text;
-       void            (*on_exit)(struct cui *);
+       struct nc_scr           scr;
+       struct cui              *cui;
+       const char              **lines;
+       int                     n_lines;
+       int                     n_alloc_lines;
+       int                     scroll_y;
+       const char              *help_title;
+       const struct help_text  *help_text;
+       void                    (*on_exit)(struct cui *);
 };
 
 void text_screen_init(struct text_screen *screen, struct cui *cui,
 };
 
 void text_screen_init(struct text_screen *screen, struct cui *cui,
@@ -45,7 +45,7 @@ void text_screen_append_line(struct text_screen *screen,
                const char *fmt, ...) __attribute__((format(printf, 2, 3)));
 void text_screen_set_text(struct text_screen *screen, const char *text);
 void text_screen_set_help(struct text_screen *screen, const char *title,
                const char *fmt, ...) __attribute__((format(printf, 2, 3)));
 void text_screen_set_text(struct text_screen *screen, const char *text);
 void text_screen_set_help(struct text_screen *screen, const char *title,
-               const char *text);
+               const struct help_text *text);
 
 /* interaction */
 void text_screen_process_key(struct nc_scr *scr, int key);
 
 /* interaction */
 void text_screen_process_key(struct nc_scr *scr, int key);