Browse Source

[settings] Display canonical setting name in "config" user interface

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 13 years ago
parent
commit
247ac80556
3 changed files with 40 additions and 9 deletions
  1. 22
    5
      src/core/settings.c
  2. 16
    4
      src/hci/tui/settings_ui.c
  3. 2
    0
      src/include/ipxe/settings.h

+ 22
- 5
src/core/settings.c View File

@@ -1060,6 +1060,27 @@ parse_setting_name ( const char *name,
1060 1060
 	return 0;
1061 1061
 }
1062 1062
 
1063
+/**
1064
+ * Return full setting name
1065
+ *
1066
+ * @v settings		Settings block, or NULL
1067
+ * @v setting		Setting
1068
+ * @v buf		Buffer
1069
+ * @v len		Length of buffer
1070
+ * @ret len		Length of setting name, or negative error
1071
+ */
1072
+int setting_name ( struct settings *settings, struct setting *setting,
1073
+		   char *buf, size_t len ) {
1074
+	const char *name;
1075
+
1076
+	if ( ! settings )
1077
+		settings = &settings_root;
1078
+
1079
+	name = settings_name ( settings );
1080
+	return snprintf ( buf, len, "%s%s%s:%s", name, ( name[0] ? "/" : "" ),
1081
+			  setting->name, setting->type->name );
1082
+}
1083
+
1063 1084
 /**
1064 1085
  * Parse and store value of named setting
1065 1086
  *
@@ -1101,7 +1122,6 @@ int fetchf_named_setting ( const char *name,
1101 1122
 	struct settings *settings;
1102 1123
 	struct setting setting;
1103 1124
 	struct settings *origin;
1104
-	const char *origin_name;
1105 1125
 	char tmp_name[ strlen ( name ) + 1 ];
1106 1126
 	int rc;
1107 1127
 
@@ -1118,10 +1138,7 @@ int fetchf_named_setting ( const char *name,
1118 1138
 	/* Construct setting name */
1119 1139
 	origin = fetch_setting_origin ( settings, &setting );
1120 1140
 	assert ( origin != NULL );
1121
-	origin_name = settings_name ( origin );
1122
-	snprintf ( name_buf, name_len, "%s%s%s:%s",
1123
-		   origin_name, ( origin_name[0] ? "/" : "" ),
1124
-		   setting.name, setting.type->name );
1141
+	setting_name ( origin, &setting, name_buf, name_len );
1125 1142
 
1126 1143
 	return 0;
1127 1144
 }

+ 16
- 4
src/hci/tui/settings_ui.c View File

@@ -97,7 +97,8 @@ static void vmsg ( unsigned int row, const char *fmt, va_list args ) __nonnull;
97 97
 static void msg ( unsigned int row, const char *fmt, ... ) __nonnull;
98 98
 static void valert ( const char *fmt, va_list args ) __nonnull;
99 99
 static void alert ( const char *fmt, ... ) __nonnull;
100
-static void draw_info_row ( struct setting *setting ) __nonnull;
100
+static void draw_info_row ( struct settings *settings,
101
+			    struct setting *setting ) __nonnull;
101 102
 static int main_loop ( struct settings *settings ) __nonnull;
102 103
 
103 104
 /**
@@ -313,12 +314,23 @@ static void draw_title_row ( void ) {
313 314
 /**
314 315
  * Draw information row
315 316
  *
317
+ * @v settings		Settings block
316 318
  * @v setting		Current configuration setting
317 319
  */
318
-static void draw_info_row ( struct setting *setting ) {
320
+static void draw_info_row ( struct settings *settings,
321
+			    struct setting *setting ) {
322
+	struct settings *origin;
323
+	char buf[32];
324
+
325
+	/* Determine a suitable setting name */
326
+	origin = fetch_setting_origin ( settings, setting );
327
+	if ( ! origin )
328
+		origin = settings;
329
+	setting_name ( origin, setting, buf, sizeof ( buf ) );
330
+
319 331
 	clearmsg ( INFO_ROW );
320 332
 	attron ( A_BOLD );
321
-	msg ( INFO_ROW, "%s - %s", setting->name, setting->description );
333
+	msg ( INFO_ROW, "%s - %s", buf, setting->description );
322 334
 	attroff ( A_BOLD );
323 335
 }
324 336
 
@@ -400,7 +412,7 @@ static int main_loop ( struct settings *settings ) {
400 412
 	
401 413
 	while ( 1 ) {
402 414
 		/* Redraw information and instruction rows */
403
-		draw_info_row ( widget.setting );
415
+		draw_info_row ( widget.settings, widget.setting );
404 416
 		draw_instruction_row ( widget.editing );
405 417
 
406 418
 		/* Redraw current setting */

+ 2
- 0
src/include/ipxe/settings.h View File

@@ -251,6 +251,8 @@ extern const char * settings_name ( struct settings *settings );
251 251
 extern struct settings * find_settings ( const char *name );
252 252
 extern struct setting * find_setting ( const char *name );
253 253
 
254
+extern int setting_name ( struct settings *settings, struct setting *setting,
255
+			  char *buf, size_t len );
254 256
 extern int storef_setting ( struct settings *settings,
255 257
 			    struct setting *setting,
256 258
 			    const char *value );

Loading…
Cancel
Save