david/ipxe
david
/
ipxe
Archived
1
0
Fork 0

Added descriptive text for settings and setting types, and display it in

the option config UI.
This commit is contained in:
Michael Brown 2006-12-20 04:58:26 +00:00
parent 35edecac34
commit b93ff48173
3 changed files with 87 additions and 10 deletions

View File

@ -19,6 +19,7 @@
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <strings.h>
#include <byteswap.h> #include <byteswap.h>
#include <errno.h> #include <errno.h>
#include <assert.h> #include <assert.h>
@ -56,7 +57,7 @@ find_config_setting_type ( const char *name ) {
for ( type = config_setting_types ; type < config_setting_types_end ; for ( type = config_setting_types ; type < config_setting_types_end ;
type++ ) { type++ ) {
if ( strcmp ( name, type->name ) == 0 ) if ( strcasecmp ( name, type->name ) == 0 )
return type; return type;
} }
return NULL; return NULL;
@ -73,7 +74,7 @@ static struct config_setting * find_config_setting ( const char *name ) {
for ( setting = config_settings ; setting < config_settings_end ; for ( setting = config_settings ; setting < config_settings_end ;
setting++ ) { setting++ ) {
if ( strcmp ( name, setting->name ) == 0 ) if ( strcasecmp ( name, setting->name ) == 0 )
return setting; return setting;
} }
return NULL; return NULL;
@ -216,6 +217,7 @@ static int set_string ( struct config_context *context,
/** A string configuration setting */ /** A string configuration setting */
struct config_setting_type config_setting_type_string __config_setting_type = { struct config_setting_type config_setting_type_string __config_setting_type = {
.name = "string", .name = "string",
.description = "Text string",
.show = show_string, .show = show_string,
.set = set_string, .set = set_string,
}; };
@ -269,6 +271,7 @@ static int set_ipv4 ( struct config_context *context,
/** An IPv4 configuration setting */ /** An IPv4 configuration setting */
struct config_setting_type config_setting_type_ipv4 __config_setting_type = { struct config_setting_type config_setting_type_ipv4 __config_setting_type = {
.name = "ipv4", .name = "ipv4",
.description = "IPv4 address",
.show = show_ipv4, .show = show_ipv4,
.set = set_ipv4, .set = set_ipv4,
}; };
@ -348,6 +351,7 @@ static int set_int8 ( struct config_context *context,
/** An 8-bit integer configuration setting */ /** An 8-bit integer configuration setting */
struct config_setting_type config_setting_type_int8 __config_setting_type = { struct config_setting_type config_setting_type_int8 __config_setting_type = {
.name = "int8", .name = "int8",
.description = "8-bit integer",
.show = show_int, .show = show_int,
.set = set_int8, .set = set_int8,
}; };
@ -355,31 +359,37 @@ struct config_setting_type config_setting_type_int8 __config_setting_type = {
/** Some basic setting definitions */ /** Some basic setting definitions */
struct config_setting ip_config_setting __config_setting = { struct config_setting ip_config_setting __config_setting = {
.name = "ip", .name = "ip",
.description = "IP address of this machine (e.g. 192.168.0.1)",
.tag = DHCP_EB_YIADDR, .tag = DHCP_EB_YIADDR,
.type = &config_setting_type_ipv4, .type = &config_setting_type_ipv4,
}; };
struct config_setting hostname_config_setting __config_setting = { struct config_setting hostname_config_setting __config_setting = {
.name = "hostname", .name = "hostname",
.description = "Host name of this machine",
.tag = DHCP_HOST_NAME, .tag = DHCP_HOST_NAME,
.type = &config_setting_type_string, .type = &config_setting_type_string,
}; };
struct config_setting username_config_setting __config_setting = { struct config_setting username_config_setting __config_setting = {
.name = "username", .name = "username",
.description = "User name for authentication to servers",
.tag = DHCP_EB_USERNAME, .tag = DHCP_EB_USERNAME,
.type = &config_setting_type_string, .type = &config_setting_type_string,
}; };
struct config_setting password_config_setting __config_setting = { struct config_setting password_config_setting __config_setting = {
.name = "password", .name = "password",
.description = "Password for authentication to servers",
.tag = DHCP_EB_PASSWORD, .tag = DHCP_EB_PASSWORD,
.type = &config_setting_type_string, .type = &config_setting_type_string,
}; };
struct config_setting root_path_config_setting __config_setting = { struct config_setting root_path_config_setting __config_setting = {
.name = "root-path", .name = "root-path",
.description = "NFS/iSCSI root path",
.tag = DHCP_ROOT_PATH, .tag = DHCP_ROOT_PATH,
.type = &config_setting_type_string, .type = &config_setting_type_string,
}; };
struct config_setting priority_config_setting __config_setting = { struct config_setting priority_config_setting __config_setting = {
.name = "priority", .name = "priority",
.description = "Priority of these options",
.tag = DHCP_EB_PRIORITY, .tag = DHCP_EB_PRIORITY,
.type = &config_setting_type_int8, .type = &config_setting_type_int8,
}; };

View File

@ -16,6 +16,7 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
#include <stdarg.h>
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
#include <curses.h> #include <curses.h>
@ -39,8 +40,10 @@ extern struct nvo_block *ugly_nvo_hack;
#define CPAIR_ALERT 4 #define CPAIR_ALERT 4
/* Screen layout */ /* Screen layout */
#define BANNER_ROW 1
#define SETTINGS_LIST_ROW 3 #define SETTINGS_LIST_ROW 3
#define SETTINGS_LIST_COL 1 #define SETTINGS_LIST_COL 1
#define INFO_ROW 20
#define ALERT_ROW 20 #define ALERT_ROW 20
/** Layout of text within a setting widget */ /** Layout of text within a setting widget */
@ -203,21 +206,72 @@ static void init_setting_index ( struct setting_widget *widget,
( SETTINGS_LIST_ROW + index ), SETTINGS_LIST_COL ); ( SETTINGS_LIST_ROW + index ), SETTINGS_LIST_COL );
} }
static void alert ( const char *fmt, ... ) { /**
* Print message centred on specified row
*
* @v row Row
* @v fmt printf() format string
* @v args printf() argument list
*/
static void vmsg ( unsigned int row, const char *fmt, va_list args ) {
char buf[COLS]; char buf[COLS];
va_list args;
size_t len; size_t len;
va_start ( args, fmt );
len = vsnprintf ( buf, sizeof ( buf ), fmt, args ); len = vsnprintf ( buf, sizeof ( buf ), fmt, args );
va_end ( args ); mvprintw ( row, ( ( COLS - len ) / 2 ), "%s", buf );
}
/**
* Print message centred on specified row
*
* @v row Row
* @v fmt printf() format string
* @v .. printf() arguments
*/
static void msg ( unsigned int row, const char *fmt, ... ) {
va_list args;
va_start ( args, fmt );
vmsg ( row, fmt, args );
va_end ( args );
}
/**
* Clear message on specified row
*
* @v row Row
*/
static void clearmsg ( unsigned int row ) {
move ( row, 0 );
clrtoeol();
}
/**
* Print alert message
*
* @v fmt printf() format string
* @v args printf() argument list
*/
static void valert ( const char *fmt, va_list args ) {
color_set ( CPAIR_ALERT, NULL ); color_set ( CPAIR_ALERT, NULL );
mvprintw ( ALERT_ROW, ( ( COLS - len ) / 2 ), "%s", buf ); vmsg ( ALERT_ROW, fmt, args );
sleep ( 2 ); sleep ( 2 );
color_set ( CPAIR_NORMAL, NULL ); color_set ( CPAIR_NORMAL, NULL );
move ( ALERT_ROW, 0 ); clearmsg ( ALERT_ROW );
clrtoeol(); }
/**
* Print alert message
*
* @v fmt printf() format string
* @v ... printf() arguments
*/
static void alert ( const char *fmt, ... ) {
va_list args;
va_start ( args, fmt );
valert ( fmt, args );
va_end ( args );
} }
static void main_loop ( struct config_context *context ) { static void main_loop ( struct config_context *context ) {
@ -230,12 +284,21 @@ static void main_loop ( struct config_context *context ) {
/* Print initial screen content */ /* Print initial screen content */
color_set ( CPAIR_NORMAL, NULL ); color_set ( CPAIR_NORMAL, NULL );
attron ( A_BOLD );
msg ( BANNER_ROW, "gPXE option configuration console" );
attroff ( A_BOLD );
for ( i = ( NUM_SETTINGS - 1 ) ; i >= 0 ; i-- ) { for ( i = ( NUM_SETTINGS - 1 ) ; i >= 0 ; i-- ) {
init_setting_index ( &widget, context, i ); init_setting_index ( &widget, context, i );
draw_setting ( &widget ); draw_setting ( &widget );
} }
while ( 1 ) { while ( 1 ) {
/* Redraw information row */
clearmsg ( INFO_ROW );
msg ( INFO_ROW, "%s (%s) - %s", widget.setting->name,
widget.setting->type->description,
widget.setting->description );
/* Redraw current setting */ /* Redraw current setting */
color_set ( ( widget.editing ? CPAIR_EDIT : CPAIR_SELECT ), color_set ( ( widget.editing ? CPAIR_EDIT : CPAIR_SELECT ),
NULL ); NULL );
@ -293,7 +356,7 @@ void uitest ( void ) {
initscr(); initscr();
start_color(); start_color();
init_pair ( CPAIR_NORMAL, COLOR_WHITE, COLOR_BLUE ); init_pair ( CPAIR_NORMAL, COLOR_WHITE, COLOR_BLUE );
init_pair ( CPAIR_SELECT, COLOR_BLACK, COLOR_WHITE ); init_pair ( CPAIR_SELECT, COLOR_WHITE, COLOR_RED );
init_pair ( CPAIR_EDIT, COLOR_BLACK, COLOR_CYAN ); init_pair ( CPAIR_EDIT, COLOR_BLACK, COLOR_CYAN );
init_pair ( CPAIR_ALERT, COLOR_WHITE, COLOR_RED ); init_pair ( CPAIR_ALERT, COLOR_WHITE, COLOR_RED );
color_set ( CPAIR_NORMAL, NULL ); color_set ( CPAIR_NORMAL, NULL );

View File

@ -40,6 +40,8 @@ struct config_setting_type {
* This is the name exposed to the user (e.g. "string"). * This is the name exposed to the user (e.g. "string").
*/ */
const char *name; const char *name;
/** Description */
const char *description;
/** Show value of setting /** Show value of setting
* *
* @v context Configuration context * @v context Configuration context
@ -79,6 +81,8 @@ struct config_setting {
* dhcp-options(5)). * dhcp-options(5)).
*/ */
const char *name; const char *name;
/** Description */
const char *description;
/** DHCP option tag /** DHCP option tag
* *
* This is the DHCP tag used to identify the option in DHCP * This is the DHCP tag used to identify the option in DHCP