nvramcui: Reformat nvramcui.c

Change-Id: I89dca25d93a4c94cc51f313397e49ba763948450
Signed-off-by: Martin Roth <martinroth@google.com>
Reviewed-on: https://review.coreboot.org/14484
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
This commit is contained in:
Martin Roth 2016-04-23 17:24:57 -06:00
parent 9bc6674b7c
commit f62065f15b
1 changed files with 68 additions and 52 deletions

View File

@ -13,12 +13,12 @@
* GNU General Public License for more details.
*/
#include <libpayload.h>
#include <coreboot_tables.h>
#include <libpayload.h>
#include <curses.h>
#include <menu.h>
#include <form.h>
#include <menu.h>
#ifndef HOSTED
#define HOSTED 0
@ -50,7 +50,8 @@ void render_form(FORM *form)
wclear(der);
wrefresh(der);
delwin(der);
copywin(inner_w, w, line, 0, 1, 1, min(numlines, getmaxy(inner_w)-line), 68, 0);
copywin(inner_w, w, line, 0, 1, 1,
min(numlines, getmaxy(inner_w) - line), 68, 0);
wmove(w, y + 1 - line, x + 1);
wrefresh(w);
}
@ -76,7 +77,8 @@ int main()
int maxlength = 0;
struct cb_cmos_entries *option = first_cmos_entry(opttbl);
while (option) {
if ((option->config != 'r') && (strcmp("check_sum", option->name) != 0)) {
if ((option->config != 'r') &&
(strcmp("check_sum", option->name) != 0)) {
maxlength = max(maxlength, strlen(option->name));
numopts++;
}
@ -92,19 +94,24 @@ int main()
/* walk over options, fetch details */
option = first_cmos_entry(opttbl);
for (i = 0; i < numopts; i++) {
while ((option->config == 'r') || (strcmp("check_sum", option->name) == 0)) {
while ((option->config == 'r') ||
(strcmp("check_sum", option->name) == 0)) {
option = next_cmos_entry(option);
}
fields[2*i] = new_field(1, strlen(option->name), i*2, 1, 0, 0);
fields[2 * i] =
new_field(1, strlen(option->name), i * 2, 1, 0, 0);
set_field_buffer(fields[2 * i], 0, option->name);
field_opts_off(fields[2 * i], O_ACTIVE);
fields[2*i+1] = new_field(1, 40, i*2, maxlength+2, 0, 0);
fields[2 * i + 1] =
new_field(1, 40, i * 2, maxlength + 2, 0, 0);
char *buf = NULL;
int fail = get_option_as_string(use_nvram, opttbl, &buf, option->name);
int fail =
get_option_as_string(use_nvram, opttbl, &buf, option->name);
switch (option->config) {
case 'h': {
set_field_type(fields[2*i+1], TYPE_INTEGER, 0, 0, (1<<option->length)-1);
set_field_type(fields[2 * i + 1], TYPE_INTEGER, 0, 0,
(1 << option->length) - 1);
field_opts_on(fields[2 * i + 1], O_BLANK);
break;
}
@ -115,7 +122,8 @@ int main()
}
case 'e': {
int numvals = 0;
struct cb_cmos_enums *cmos_enum = first_cmos_enum_of_id(opttbl, option->config_id);
struct cb_cmos_enums *cmos_enum =
first_cmos_enum_of_id(opttbl, option->config_id);
/* if invalid data in CMOS, set buf to first enum */
if (fail && cmos_enum) {
@ -124,33 +132,39 @@ int main()
while (cmos_enum) {
numvals++;
cmos_enum = next_cmos_enum_of_id(cmos_enum, option->config_id);
cmos_enum = next_cmos_enum_of_id(
cmos_enum, option->config_id);
}
char **values = malloc(sizeof(char *) * (numvals + 1));
int cnt = 0;
cmos_enum = first_cmos_enum_of_id(opttbl, option->config_id);
cmos_enum =
first_cmos_enum_of_id(opttbl, option->config_id);
while (cmos_enum) {
values[cnt] = cmos_enum->text;
cnt++;
cmos_enum = next_cmos_enum_of_id(cmos_enum, option->config_id);
cmos_enum = next_cmos_enum_of_id(
cmos_enum, option->config_id);
}
values[cnt] = NULL;
field_opts_off(fields[2 * i + 1], O_EDIT);
set_field_type(fields[2*i+1], TYPE_ENUM, values, 1, 1);
set_field_type(fields[2 * i + 1], TYPE_ENUM, values, 1,
1);
free(values); // copied by set_field_type
break;
}
default:
break;
}
if (buf) set_field_buffer(fields[2*i+1], 0, buf);
if (buf)
set_field_buffer(fields[2 * i + 1], 0, buf);
#if HOSTED
// underline is non-trivial on VGA text
set_field_back(fields[2 * i + 1], A_UNDERLINE);
#endif
field_opts_off(fields[2*i+1], O_BLANK | O_AUTOSKIP | O_NULLOK);
field_opts_off(fields[2 * i + 1],
O_BLANK | O_AUTOSKIP | O_NULLOK);
option = next_cmos_entry(option);
}
@ -187,7 +201,8 @@ int main()
while (!done) {
render_form(form);
ch = getch();
if (ch == ERR) continue;
if (ch == ERR)
continue;
switch (ch) {
case KEY_DOWN:
form_driver(form, REQ_NEXT_FIELD);
@ -232,7 +247,8 @@ int main()
char *value = field_buffer(fields[2 * i + 1], 0);
char *ptr;
for (ptr = value + strlen(value) - 1;
ptr >= value && *ptr == ' '; ptr--);
ptr >= value && *ptr == ' '; ptr--)
;
ptr[1] = '\0';
set_option_from_string(use_nvram, opttbl, value, name);
}