]> git.ozlabs.org Git - petitboot/commitdiff
ui/ncurses: ked -> boot-editor
authorJeremy Kerr <jk@ozlabs.org>
Wed, 27 Feb 2013 06:15:34 +0000 (14:15 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Mon, 15 Apr 2013 06:54:21 +0000 (14:54 +0800)
git mv ui/ncurses/nc-ked.c ui/ncurses/nc-boot-editor.c
git mv ui/ncurses/nc-ked.h ui/ncurses/nc-boot-editor.h
find ui/ncurses -type f |
xargs sed -i -e s/nc-ked\./nc-boot-editor./g \
             -e s/ked/boot_editor/g

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
ui/ncurses/Makefile.am
ui/ncurses/nc-boot-editor.c [new file with mode: 0644]
ui/ncurses/nc-boot-editor.h [new file with mode: 0644]
ui/ncurses/nc-cui.c
ui/ncurses/nc-cui.h
ui/ncurses/nc-ked.c [deleted file]
ui/ncurses/nc-ked.h [deleted file]
ui/ncurses/nc-scr.h

index 90b5cbf6f33314733c1ea0a184f59a1b08b2601f..3df91053bb25a673f455cf3451e254a795c97dde 100644 (file)
@@ -33,8 +33,8 @@ noinst_LTLIBRARIES = libpbnc.la
 libpbnc_la_SOURCES = \
        nc-cui.c \
        nc-cui.h \
 libpbnc_la_SOURCES = \
        nc-cui.c \
        nc-cui.h \
-       nc-ked.c \
-       nc-ked.h \
+       nc-boot-editor.c \
+       nc-boot-editor.h \
        nc-menu.c \
        nc-menu.h \
        nc-scr.c \
        nc-menu.c \
        nc-menu.h \
        nc-scr.c \
diff --git a/ui/ncurses/nc-boot-editor.c b/ui/ncurses/nc-boot-editor.c
new file mode 100644 (file)
index 0000000..a9256ff
--- /dev/null
@@ -0,0 +1,365 @@
+/*
+ *  Copyright (C) 2009 Sony Computer Entertainment Inc.
+ *  Copyright 2009 Sony Corp.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; version 2 of the License.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#define _GNU_SOURCE
+
+#include <assert.h>
+#include <string.h>
+
+#include "log/log.h"
+#include "talloc/talloc.h"
+#include "nc-boot-editor.h"
+
+static struct boot_editor *boot_editor_from_scr(struct nc_scr *scr)
+{
+       struct boot_editor *boot_editor;
+
+       assert(scr->sig == pb_boot_editor_sig);
+       boot_editor = (struct boot_editor *)
+               ((char *)scr - (size_t)&((struct boot_editor *)0)->scr);
+       assert(boot_editor->scr.sig == pb_boot_editor_sig);
+       return boot_editor;
+}
+
+static struct boot_editor *boot_editor_from_arg(void *arg)
+{
+       struct boot_editor *boot_editor = arg;
+
+       assert(boot_editor->scr.sig == pb_boot_editor_sig);
+       return boot_editor;
+}
+
+/**
+ * boot_editor_move_cursor - Move the cursor, setting correct attributes.
+ * @req: An ncurses request or char to send to form_driver().
+ */
+
+static int boot_editor_move_cursor(struct boot_editor *boot_editor, int req)
+{
+       int result;
+
+       wchgat(boot_editor->scr.sub_ncw, 1,
+                       boot_editor_attr_field_selected, 0, 0);
+       result = form_driver(boot_editor->ncf, req);
+       wchgat(boot_editor->scr.sub_ncw, 1, boot_editor->attr_cursor, 0, 0);
+       wrefresh(boot_editor->scr.main_ncw);
+       return result;
+}
+
+/**
+ * boot_editor_insert_mode_set - Set the insert mode.
+ */
+
+static void boot_editor_insert_mode_set(struct boot_editor *boot_editor,
+               int req)
+{
+       switch (req) {
+       case REQ_INS_MODE:
+               boot_editor->attr_cursor = boot_editor_attr_cursor_ins;
+               break;
+       case REQ_OVL_MODE:
+               boot_editor->attr_cursor = boot_editor_attr_cursor_ovl;
+               break;
+       default:
+               assert(0 && "bad req");
+               break;
+       }
+       boot_editor_move_cursor(boot_editor, req);
+}
+
+/**
+ * boot_editor_insert_mode_tog - Toggle the insert mode.
+ */
+
+static void boot_editor_insert_mode_tog(struct boot_editor *boot_editor)
+{
+       if (boot_editor->attr_cursor == boot_editor_attr_cursor_ins)
+               boot_editor_insert_mode_set(boot_editor, REQ_OVL_MODE);
+       else
+               boot_editor_insert_mode_set(boot_editor, REQ_INS_MODE);
+}
+
+/**
+ * boot_editor_move_field - Move selected field, setting correct attributes.
+ * @req: An ncurses request to send to form_driver().
+ */
+
+static int boot_editor_move_field(struct boot_editor *boot_editor, int req)
+{
+       int result;
+
+       set_field_back(current_field(boot_editor->ncf),
+                       boot_editor_attr_field_normal);
+
+       result = form_driver(boot_editor->ncf, req);
+
+       set_field_back(current_field(boot_editor->ncf),
+                       boot_editor_attr_field_selected);
+
+       boot_editor_move_cursor(boot_editor, REQ_END_FIELD);
+       return result;
+}
+
+static int boot_editor_post(struct nc_scr *scr)
+{
+       struct boot_editor *boot_editor = boot_editor_from_scr(scr);
+
+       post_form(boot_editor->ncf);
+
+       nc_scr_frame_draw(scr);
+       boot_editor_move_field(boot_editor, REQ_FIRST_FIELD);
+       boot_editor_move_field(boot_editor, REQ_END_FIELD);
+       boot_editor_insert_mode_set(boot_editor, REQ_INS_MODE);
+
+       redrawwin(boot_editor->scr.main_ncw);
+       wrefresh(boot_editor->scr.main_ncw);
+
+       return 0;
+}
+
+static int boot_editor_unpost(struct nc_scr *scr)
+{
+       return unpost_form(boot_editor_from_scr(scr)->ncf);
+}
+
+static void boot_editor_resize(struct nc_scr *scr)
+{
+       /* FIXME: forms can't be resized, need to recreate here */
+       boot_editor_unpost(scr);
+       boot_editor_post(scr);
+}
+
+/**
+ * boot_editor_chomp - Eat leading and trailing WS.
+ */
+
+static char *boot_editor_chomp(char *s)
+{
+       char *start;
+       char *end;
+       char *const s_end = s + strlen(s);
+
+       for (; s < s_end; s++)
+               if (*s != ' ' && *s != '\t')
+                       break;
+
+       start = end = s;
+
+       for (; s < s_end; s++)
+               if (*s != ' ' && *s != '\t')
+                       end = s;
+       *(end + 1) = 0;
+       return start;
+}
+
+static struct pb_kexec_data *boot_editor_prepare_data(
+               struct boot_editor *boot_editor)
+{
+       struct pb_kexec_data *kd;
+       char *s;
+
+       kd = talloc(boot_editor, struct pb_kexec_data);
+
+       if (!kd)
+               return NULL;
+
+       s = boot_editor_chomp(field_buffer(boot_editor->fields[0], 0));
+       kd->image = *s ? talloc_strdup(kd, s) : NULL;
+
+       s = boot_editor_chomp(field_buffer(boot_editor->fields[1], 0));
+       kd->initrd = *s ? talloc_strdup(kd, s) : NULL;
+
+       s = boot_editor_chomp(field_buffer(boot_editor->fields[2], 0));
+       kd->args = *s ? talloc_strdup(kd, s) : NULL;
+
+       return kd;
+}
+
+/**
+ * boot_editor_process_key - Process a user keystroke.
+ *
+ * Called from the cui via the scr:process_key method.
+ */
+
+static void boot_editor_process_key(struct nc_scr *scr)
+{
+       struct boot_editor *boot_editor = boot_editor_from_scr(scr);
+       struct pb_kexec_data *kd;
+
+       while (1) {
+               int c = getch();
+
+               if (c == ERR)
+                       return;
+
+               /* DBGS("%d (%o)\n", c, c); */
+
+               switch (c) {
+               default:
+                       boot_editor_move_cursor(boot_editor, c);
+                       break;
+
+               /* hot keys */
+               case 27: /* ESC */
+                       boot_editor->on_exit(boot_editor,
+                                       boot_editor_cancel, NULL);
+                       nc_flush_keys();
+                       return;
+               case '\n':
+               case '\r':
+                       form_driver(boot_editor->ncf, REQ_VALIDATION);
+                       kd = boot_editor_prepare_data(boot_editor);
+                       boot_editor->on_exit(boot_editor,
+                                       boot_editor_update, kd);
+                       nc_flush_keys();
+                       return;
+
+               /* insert mode */
+               case KEY_IC:
+                       boot_editor_insert_mode_tog(boot_editor);
+                       break;
+
+               /* form nav */
+               case KEY_PPAGE:
+                       boot_editor_move_field(boot_editor, REQ_FIRST_FIELD);
+                       break;
+               case KEY_NPAGE:
+                       boot_editor_move_field(boot_editor, REQ_LAST_FIELD);
+                       break;
+               case KEY_DOWN:
+                       boot_editor_move_field(boot_editor, REQ_NEXT_FIELD);
+                       break;
+               case KEY_UP:
+                       boot_editor_move_field(boot_editor, REQ_PREV_FIELD);
+                       break;
+
+               /* field nav */
+               case KEY_HOME:
+                       boot_editor_move_cursor(boot_editor, REQ_BEG_FIELD);
+                       break;
+               case KEY_END:
+                       boot_editor_move_cursor(boot_editor, REQ_END_FIELD);
+                       break;
+               case KEY_LEFT:
+                       boot_editor_move_cursor(boot_editor, REQ_LEFT_CHAR);
+                       break;
+               case KEY_RIGHT:
+                       boot_editor_move_cursor(boot_editor, REQ_RIGHT_CHAR);
+                       break;
+               case KEY_BACKSPACE:
+                       if (boot_editor_move_cursor(boot_editor, REQ_LEFT_CHAR)
+                                       == E_OK)
+                               boot_editor_move_cursor(boot_editor,
+                                               REQ_DEL_CHAR);
+                       break;
+               case KEY_DC:
+                       boot_editor_move_cursor(boot_editor, REQ_DEL_CHAR);
+                       break;
+               }
+       }
+}
+
+/**
+ * boot_editor_destructor - The talloc destructor for a boot_editor.
+ */
+
+static int boot_editor_destructor(void *arg)
+{
+       struct boot_editor *boot_editor = boot_editor_from_arg(arg);
+       FIELD **f;
+
+       for (f = boot_editor->fields; *f; f++)
+               free_field(*f);
+
+       free_form(boot_editor->ncf);
+       boot_editor->scr.sig = pb_removed_sig;
+
+       return 0;
+}
+
+static FIELD *boot_editor_setup_field(unsigned int y, unsigned int x, char *str)
+{
+       FIELD *f;
+
+       f = new_field(1, COLS - 1 - x, y, x, 0, 0);
+       field_opts_off(f, O_STATIC | O_WRAP);
+       set_max_field(f, 256);
+       set_field_buffer(f, 0, str);
+       set_field_status(f, 0);
+       return f;
+}
+
+static FIELD *boot_editor_setup_label(unsigned int y, unsigned int x, char *str)
+{
+       FIELD *f;
+
+       f = new_field(1, strlen(str), y, x, 0, 0);
+       field_opts_off(f, O_ACTIVE);
+       set_field_buffer(f, 0, str);
+       return f;
+}
+
+struct boot_editor *boot_editor_init(void *ui_ctx,
+               const struct pb_kexec_data *kd,
+               void (*on_exit)(struct boot_editor *,
+                               enum boot_editor_result,
+                               struct pb_kexec_data *))
+{
+       struct boot_editor *boot_editor;
+
+       pb_log("%s: image:  '%s'\n", __func__, kd->image);
+       pb_log("%s: initrd: '%s'\n", __func__, kd->initrd);
+       pb_log("%s: args:   '%s'\n", __func__, kd->args);
+
+       assert(on_exit);
+
+       boot_editor = talloc_zero(ui_ctx, struct boot_editor);
+
+       if (!boot_editor)
+               return NULL;
+
+       talloc_set_destructor(boot_editor, boot_editor_destructor);
+
+       nc_scr_init(&boot_editor->scr, pb_boot_editor_sig, 0,
+                       ui_ctx, boot_editor_process_key,
+               boot_editor_post, boot_editor_unpost, boot_editor_resize);
+
+       boot_editor->scr.frame.title = talloc_strdup(boot_editor,
+                       "Petitboot Option Editor");
+       boot_editor->scr.frame.help = talloc_strdup(boot_editor,
+                       "ESC=cancel, Enter=accept");
+
+       boot_editor->on_exit = on_exit;
+
+       boot_editor->fields = talloc_array(boot_editor, FIELD *, 7);
+
+       boot_editor->fields[0] = boot_editor_setup_field(0, 9, kd->image);
+       boot_editor->fields[1] = boot_editor_setup_field(1, 9, kd->initrd);
+       boot_editor->fields[2] = boot_editor_setup_field(2, 9, kd->args);
+       boot_editor->fields[3] = boot_editor_setup_label(0, 1, "image:");
+       boot_editor->fields[4] = boot_editor_setup_label(1, 1, "initrd:");
+       boot_editor->fields[5] = boot_editor_setup_label(2, 1, "args:");
+       boot_editor->fields[6] = NULL;
+
+       boot_editor->ncf = new_form(boot_editor->fields);
+
+       set_form_win(boot_editor->ncf, boot_editor->scr.main_ncw);
+       set_form_sub(boot_editor->ncf, boot_editor->scr.sub_ncw);
+
+       return boot_editor;
+}
diff --git a/ui/ncurses/nc-boot-editor.h b/ui/ncurses/nc-boot-editor.h
new file mode 100644 (file)
index 0000000..650c316
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ *  Copyright (C) 2009 Sony Computer Entertainment Inc.
+ *  Copyright 2009 Sony Corp.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; version 2 of the License.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#if !defined(_PB_NC_KED_H)
+#define _PB_NC_KED_H
+
+#include <assert.h>
+#include <linux/input.h> /* This must be included before ncurses.h */
+#include <form.h>
+
+#include "types/types.h"
+#include "ui/common/ui-system.h"
+#include "nc-scr.h"
+
+enum boot_editor_attr_field {
+       boot_editor_attr_field_normal = A_NORMAL,
+       boot_editor_attr_field_selected = A_REVERSE,
+};
+
+enum boot_editor_attr_cursor {
+       boot_editor_attr_cursor_ins = A_NORMAL,
+       boot_editor_attr_cursor_ovl = A_NORMAL | A_UNDERLINE,
+};
+
+/**
+ * enum boot_editor_result - Result code for boot_editor:on_exit().
+ * @boot_editor_cancel: The user canceled the operation.
+ * @boot_editor_update: The args were updated.
+ */
+
+enum boot_editor_result {
+       boot_editor_cancel,
+       boot_editor_update,
+};
+
+/**
+ * struct boot_editor - kexec args editor.
+ */
+
+struct boot_editor {
+       struct nc_scr scr;
+       FORM *ncf;
+       FIELD **fields;
+       enum boot_editor_attr_cursor attr_cursor;
+       void (*on_exit)(struct boot_editor *boot_editor,
+                       enum boot_editor_result result,
+                       struct pb_kexec_data *kd);
+};
+
+struct boot_editor *boot_editor_init(void *ui_ctx,
+               const struct pb_kexec_data *kd,
+               void (*on_exit)(struct boot_editor *,
+                               enum boot_editor_result,
+                               struct pb_kexec_data *));
+
+#endif
index a909b828d065f94c5a9129bd054f0c19bab6024e..51c14720dd760b1effc0bdca1600824eba095611 100644 (file)
@@ -161,15 +161,15 @@ static int cui_run_kexec(struct pmenu_item *item)
 }
 
 /**
 }
 
 /**
- * cui_ked_on_exit - The ked on_exit callback.
+ * cui_boot_editor_on_exit - The boot_editor on_exit callback.
  */
 
  */
 
-static void cui_ked_on_exit(struct ked *ked, enum ked_result ked_result,
+static void cui_boot_editor_on_exit(struct boot_editor *boot_editor, enum boot_editor_result boot_editor_result,
        struct pb_kexec_data *kd)
 {
        struct pb_kexec_data *kd)
 {
-       struct cui *cui = cui_from_arg(ked->scr.ui_ctx);
+       struct cui *cui = cui_from_arg(boot_editor->scr.ui_ctx);
 
 
-       if (ked_result == ked_update) {
+       if (boot_editor_result == boot_editor_update) {
                struct pmenu_item *i = pmenu_find_selected(cui->main);
                struct cui_opt_data *cod = cod_from_item(i);
                char *name;
                struct pmenu_item *i = pmenu_find_selected(cui->main);
                struct cui_opt_data *cod = cod_from_item(i);
                char *name;
@@ -194,17 +194,17 @@ static void cui_ked_on_exit(struct ked *ked, enum ked_result ked_result,
 
        cui_set_current(cui, &cui->main->scr);
 
 
        cui_set_current(cui, &cui->main->scr);
 
-       talloc_free(ked);
+       talloc_free(boot_editor);
 }
 
 }
 
-int cui_ked_run(struct pmenu_item *item)
+int cui_boot_editor_run(struct pmenu_item *item)
 {
        struct cui *cui = cui_from_item(item);
        struct cui_opt_data *cod = cod_from_item(item);
 {
        struct cui *cui = cui_from_item(item);
        struct cui_opt_data *cod = cod_from_item(item);
-       struct ked *ked;
+       struct boot_editor *boot_editor;
 
 
-       ked = ked_init(cui, cod->kd, cui_ked_on_exit);
-       cui_set_current(cui, &ked->scr);
+       boot_editor = boot_editor_init(cui, cod->kd, cui_boot_editor_on_exit);
+       cui_set_current(cui, &boot_editor->scr);
 
        return 0;
 }
 
        return 0;
 }
@@ -340,7 +340,7 @@ void cui_on_open(struct pmenu *menu)
        insert_pt = pmenu_grow(menu, 1);
        i = pmenu_item_alloc(menu);
 
        insert_pt = pmenu_grow(menu, 1);
        i = pmenu_item_alloc(menu);
 
-       i->on_edit = cui_ked_run;
+       i->on_edit = cui_boot_editor_run;
        i->on_execute = cui_run_kexec;
        i->data = cod = talloc_zero(i, struct cui_opt_data);
 
        i->on_execute = cui_run_kexec;
        i->data = cod = talloc_zero(i, struct cui_opt_data);
 
@@ -406,7 +406,7 @@ static int cui_device_add(struct device *dev, void *arg)
 
                opt->ui_info = i = pmenu_item_alloc(cui->main);
 
 
                opt->ui_info = i = pmenu_item_alloc(cui->main);
 
-               i->on_edit = cui_ked_run;
+               i->on_edit = cui_boot_editor_run;
                i->on_execute = cui_run_kexec;
                i->data = cod = talloc(i, struct cui_opt_data);
 
                i->on_execute = cui_run_kexec;
                i->data = cod = talloc(i, struct cui_opt_data);
 
index ddbf27f074ec53d3bc45c01559fb0b2ab3ecbe2e..4470ef44badee98fb9050d90db4d82b4ff316962 100644 (file)
@@ -24,7 +24,7 @@
 #include "ui/common/joystick.h"
 #include "ui/common/timer.h"
 #include "nc-menu.h"
 #include "ui/common/joystick.h"
 #include "ui/common/timer.h"
 #include "nc-menu.h"
-#include "nc-ked.h"
+#include "nc-boot-editor.h"
 
 struct cui_opt_data {
        const char *name;
 
 struct cui_opt_data {
        const char *name;
@@ -67,7 +67,7 @@ struct cui *cui_init(void* platform_info,
        int (*js_map)(const struct js_event *e), int start_deamon, int dry_run);
 struct nc_scr *cui_set_current(struct cui *cui, struct nc_scr *scr);
 int cui_run(struct cui *cui, struct pmenu *main, unsigned int default_item);
        int (*js_map)(const struct js_event *e), int start_deamon, int dry_run);
 struct nc_scr *cui_set_current(struct cui *cui, struct nc_scr *scr);
 int cui_run(struct cui *cui, struct pmenu *main, unsigned int default_item);
-int cui_ked_run(struct pmenu_item *item);
+int cui_boot_editor_run(struct pmenu_item *item);
 
 /* convenience routines */
 
 
 /* convenience routines */
 
diff --git a/ui/ncurses/nc-ked.c b/ui/ncurses/nc-ked.c
deleted file mode 100644 (file)
index 806d389..0000000
+++ /dev/null
@@ -1,347 +0,0 @@
-/*
- *  Copyright (C) 2009 Sony Computer Entertainment Inc.
- *  Copyright 2009 Sony Corp.
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; version 2 of the License.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-#define _GNU_SOURCE
-
-#include <assert.h>
-#include <string.h>
-
-#include "log/log.h"
-#include "talloc/talloc.h"
-#include "nc-ked.h"
-
-static struct ked *ked_from_scr(struct nc_scr *scr)
-{
-       struct ked *ked;
-
-       assert(scr->sig == pb_ked_sig);
-       ked = (struct ked *)((char *)scr - (size_t)&((struct ked *)0)->scr);
-       assert(ked->scr.sig == pb_ked_sig);
-       return ked;
-}
-
-static struct ked *ked_from_arg(void *arg)
-{
-       struct ked *ked = arg;
-
-       assert(ked->scr.sig == pb_ked_sig);
-       return ked;
-}
-
-/**
- * ked_move_cursor - Move the cursor, setting correct attributes.
- * @req: An ncurses request or char to send to form_driver().
- */
-
-static int ked_move_cursor(struct ked *ked, int req)
-{
-       int result;
-
-       wchgat(ked->scr.sub_ncw, 1, ked_attr_field_selected, 0, 0);
-       result = form_driver(ked->ncf, req);
-       wchgat(ked->scr.sub_ncw, 1, ked->attr_cursor, 0, 0);
-       wrefresh(ked->scr.main_ncw);
-       return result;
-}
-
-/**
- * ked_insert_mode_set - Set the insert mode.
- */
-
-static void ked_insert_mode_set(struct ked *ked, int req)
-{
-       switch (req) {
-       case REQ_INS_MODE:
-               ked->attr_cursor = ked_attr_cursor_ins;
-               break;
-       case REQ_OVL_MODE:
-               ked->attr_cursor = ked_attr_cursor_ovl;
-               break;
-       default:
-               assert(0 && "bad req");
-               break;
-       }
-       ked_move_cursor(ked, req);
-}
-
-/**
- * ked_insert_mode_tog - Toggle the insert mode.
- */
-
-static void ked_insert_mode_tog(struct ked *ked)
-{
-       if (ked->attr_cursor == ked_attr_cursor_ins)
-               ked_insert_mode_set(ked, REQ_OVL_MODE);
-       else
-               ked_insert_mode_set(ked, REQ_INS_MODE);
-}
-
-/**
- * ked_move_field - Move selected field, setting correct attributes.
- * @req: An ncurses request to send to form_driver().
- */
-
-static int ked_move_field(struct ked *ked, int req)
-{
-       int result;
-
-       set_field_back(current_field(ked->ncf), ked_attr_field_normal);
-       result = form_driver(ked->ncf, req);
-       set_field_back(current_field(ked->ncf), ked_attr_field_selected);
-       ked_move_cursor(ked, REQ_END_FIELD);
-       return result;
-}
-
-static int ked_post(struct nc_scr *scr)
-{
-       struct ked *ked = ked_from_scr(scr);
-
-       post_form(ked->ncf);
-
-       nc_scr_frame_draw(scr);
-       ked_move_field(ked, REQ_FIRST_FIELD);
-       ked_move_field(ked, REQ_END_FIELD);
-       ked_insert_mode_set(ked, REQ_INS_MODE);
-
-       redrawwin(ked->scr.main_ncw);
-       wrefresh(ked->scr.main_ncw);
-
-       return 0;
-}
-
-static int ked_unpost(struct nc_scr *scr)
-{
-       return unpost_form(ked_from_scr(scr)->ncf);
-}
-
-static void ked_resize(struct nc_scr *scr)
-{
-       /* FIXME: forms can't be resized, need to recreate here */
-       ked_unpost(scr);
-       ked_post(scr);
-}
-
-/**
- * ked_chomp - Eat leading and trailing WS.
- */
-
-static char *ked_chomp(char *s)
-{
-       char *start;
-       char *end;
-       char *const s_end = s + strlen(s);
-
-       for (; s < s_end; s++)
-               if (*s != ' ' && *s != '\t')
-                       break;
-
-       start = end = s;
-
-       for (; s < s_end; s++)
-               if (*s != ' ' && *s != '\t')
-                       end = s;
-       *(end + 1) = 0;
-       return start;
-}
-
-static struct pb_kexec_data *ked_prepare_data(struct ked *ked)
-{
-       struct pb_kexec_data *kd;
-       char *s;
-
-       kd = talloc(ked, struct pb_kexec_data);
-
-       if (!kd)
-               return NULL;
-
-       s = ked_chomp(field_buffer(ked->fields[0], 0));
-       kd->image = *s ? talloc_strdup(kd, s) : NULL;
-
-       s = ked_chomp(field_buffer(ked->fields[1], 0));
-       kd->initrd = *s ? talloc_strdup(kd, s) : NULL;
-
-       s = ked_chomp(field_buffer(ked->fields[2], 0));
-       kd->args = *s ? talloc_strdup(kd, s) : NULL;
-
-       return kd;
-}
-
-/**
- * ked_process_key - Process a user keystroke.
- *
- * Called from the cui via the scr:process_key method.
- */
-
-static void ked_process_key(struct nc_scr *scr)
-{
-       struct ked *ked = ked_from_scr(scr);
-       struct pb_kexec_data *kd;
-
-       while (1) {
-               int c = getch();
-
-               if (c == ERR)
-                       return;
-
-               /* DBGS("%d (%o)\n", c, c); */
-
-               switch (c) {
-               default:
-                       ked_move_cursor(ked, c);
-                       break;
-
-               /* hot keys */
-               case 27: /* ESC */
-                       ked->on_exit(ked, ked_cancel, NULL);
-                       nc_flush_keys();
-                       return;
-               case '\n':
-               case '\r':
-                       form_driver(ked->ncf, REQ_VALIDATION);
-                       kd = ked_prepare_data(ked);
-                       ked->on_exit(ked, ked_update, kd);
-                       nc_flush_keys();
-                       return;
-
-               /* insert mode */
-               case KEY_IC:
-                       ked_insert_mode_tog(ked);
-                       break;
-
-               /* form nav */
-               case KEY_PPAGE:
-                       ked_move_field(ked, REQ_FIRST_FIELD);
-                       break;
-               case KEY_NPAGE:
-                       ked_move_field(ked, REQ_LAST_FIELD);
-                       break;
-               case KEY_DOWN:
-                       ked_move_field(ked, REQ_NEXT_FIELD);
-                       break;
-               case KEY_UP:
-                       ked_move_field(ked, REQ_PREV_FIELD);
-                       break;
-
-               /* field nav */
-               case KEY_HOME:
-                       ked_move_cursor(ked, REQ_BEG_FIELD);
-                       break;
-               case KEY_END:
-                       ked_move_cursor(ked, REQ_END_FIELD);
-                       break;
-               case KEY_LEFT:
-                       ked_move_cursor(ked, REQ_LEFT_CHAR);
-                       break;
-               case KEY_RIGHT:
-                       ked_move_cursor(ked, REQ_RIGHT_CHAR);
-                       break;
-               case KEY_BACKSPACE:
-                       if (ked_move_cursor(ked, REQ_LEFT_CHAR) == E_OK)
-                               ked_move_cursor(ked, REQ_DEL_CHAR);
-                       break;
-               case KEY_DC:
-                       ked_move_cursor(ked, REQ_DEL_CHAR);
-                       break;
-               }
-       }
-}
-
-/**
- * ked_destructor - The talloc destructor for a ked.
- */
-
-static int ked_destructor(void *arg)
-{
-       struct ked *ked = ked_from_arg(arg);
-       FIELD **f;
-
-       for (f = ked->fields; *f; f++)
-               free_field(*f);
-
-       free_form(ked->ncf);
-       ked->scr.sig = pb_removed_sig;
-
-       return 0;
-}
-
-static FIELD *ked_setup_field(unsigned int y, unsigned int x, char *str)
-{
-       FIELD *f;
-
-       f = new_field(1, COLS - 1 - x, y, x, 0, 0);
-       field_opts_off(f, O_STATIC | O_WRAP);
-       set_max_field(f, 256);
-       set_field_buffer(f, 0, str);
-       set_field_status(f, 0);
-       return f;
-}
-
-static FIELD *ked_setup_label(unsigned int y, unsigned int x, char *str)
-{
-       FIELD *f;
-
-       f = new_field(1, strlen(str), y, x, 0, 0);
-       field_opts_off(f, O_ACTIVE);
-       set_field_buffer(f, 0, str);
-       return f;
-}
-
-struct ked *ked_init(void *ui_ctx, const struct pb_kexec_data *kd,
-       void (*on_exit)(struct ked *, enum ked_result, struct pb_kexec_data *))
-{
-       struct ked *ked;
-
-       pb_log("%s: image:  '%s'\n", __func__, kd->image);
-       pb_log("%s: initrd: '%s'\n", __func__, kd->initrd);
-       pb_log("%s: args:   '%s'\n", __func__, kd->args);
-
-       assert(on_exit);
-
-       ked = talloc_zero(ui_ctx, struct ked);
-
-       if (!ked)
-               return NULL;
-
-       talloc_set_destructor(ked, ked_destructor);
-
-       nc_scr_init(&ked->scr, pb_ked_sig, 0, ui_ctx, ked_process_key,
-               ked_post, ked_unpost, ked_resize);
-
-       ked->scr.frame.title = talloc_strdup(ked, "Petitboot Option Editor");
-       ked->scr.frame.help = talloc_strdup(ked,
-               "ESC=cancel, Enter=accept");
-
-       ked->on_exit = on_exit;
-
-       ked->fields = talloc_array(ked, FIELD *, 7);
-
-       ked->fields[0] = ked_setup_field(0, 9, kd->image);
-       ked->fields[1] = ked_setup_field(1, 9, kd->initrd);
-       ked->fields[2] = ked_setup_field(2, 9, kd->args);
-       ked->fields[3] = ked_setup_label(0, 1, "image:");
-       ked->fields[4] = ked_setup_label(1, 1, "initrd:");
-       ked->fields[5] = ked_setup_label(2, 1, "args:");
-       ked->fields[6] = NULL;
-
-       ked->ncf = new_form(ked->fields);
-
-       set_form_win(ked->ncf, ked->scr.main_ncw);
-       set_form_sub(ked->ncf, ked->scr.sub_ncw);
-
-       return ked;
-}
diff --git a/ui/ncurses/nc-ked.h b/ui/ncurses/nc-ked.h
deleted file mode 100644 (file)
index 2f2792d..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- *  Copyright (C) 2009 Sony Computer Entertainment Inc.
- *  Copyright 2009 Sony Corp.
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; version 2 of the License.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-#if !defined(_PB_NC_KED_H)
-#define _PB_NC_KED_H
-
-#include <assert.h>
-#include <linux/input.h> /* This must be included before ncurses.h */
-#include <form.h>
-
-#include "types/types.h"
-#include "ui/common/ui-system.h"
-#include "nc-scr.h"
-
-enum ked_attr_field {
-       ked_attr_field_normal = A_NORMAL,
-       ked_attr_field_selected = A_REVERSE,
-};
-
-enum ked_attr_cursor {
-       ked_attr_cursor_ins = A_NORMAL,
-       ked_attr_cursor_ovl = A_NORMAL | A_UNDERLINE,
-};
-
-/**
- * enum ked_result - Result code for ked:on_exit().
- * @ked_cancel: The user canceled the operation.
- * @ked_update: The args were updated.
- */
-
-enum ked_result {
-       ked_cancel,
-       ked_update,
-};
-
-/**
- * struct ked - kexec args editor.
- */
-
-struct ked {
-       struct nc_scr scr;
-       FORM *ncf;
-       FIELD **fields;
-       enum ked_attr_cursor attr_cursor;
-       void (*on_exit)(struct ked *ked, enum ked_result result,
-               struct pb_kexec_data *kd);
-};
-
-struct ked *ked_init(void *ui_ctx, const struct pb_kexec_data *kd,
-       void (*on_exit)(struct ked *, enum ked_result, struct pb_kexec_data *));
-
-#endif
index bda2c3241df0e6cb026f32a10f25cc7ef5f14138..0658dd06139844bf2c90887d4b21a25f28d5767c 100644 (file)
 
 
 enum pb_nc_sig {
 
 
 enum pb_nc_sig {
-       pb_cui_sig     = 111,
-       pb_pmenu_sig   = 222,
-       pb_item_sig    = 333,
-       pb_ked_sig     = 444,
-       pb_removed_sig = -555,
+       pb_cui_sig         = 111,
+       pb_pmenu_sig       = 222,
+       pb_item_sig        = 333,
+       pb_boot_editor_sig = 444,
+       pb_removed_sig     = -555,
 };
 
 void nc_start(void);
 };
 
 void nc_start(void);