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
 	return 0;
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
  * Parse and store value of named setting
1085
  * Parse and store value of named setting
1065
  *
1086
  *
1101
 	struct settings *settings;
1122
 	struct settings *settings;
1102
 	struct setting setting;
1123
 	struct setting setting;
1103
 	struct settings *origin;
1124
 	struct settings *origin;
1104
-	const char *origin_name;
1105
 	char tmp_name[ strlen ( name ) + 1 ];
1125
 	char tmp_name[ strlen ( name ) + 1 ];
1106
 	int rc;
1126
 	int rc;
1107
 
1127
 
1118
 	/* Construct setting name */
1138
 	/* Construct setting name */
1119
 	origin = fetch_setting_origin ( settings, &setting );
1139
 	origin = fetch_setting_origin ( settings, &setting );
1120
 	assert ( origin != NULL );
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
 	return 0;
1143
 	return 0;
1127
 }
1144
 }

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

97
 static void msg ( unsigned int row, const char *fmt, ... ) __nonnull;
97
 static void msg ( unsigned int row, const char *fmt, ... ) __nonnull;
98
 static void valert ( const char *fmt, va_list args ) __nonnull;
98
 static void valert ( const char *fmt, va_list args ) __nonnull;
99
 static void alert ( const char *fmt, ... ) __nonnull;
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
 static int main_loop ( struct settings *settings ) __nonnull;
102
 static int main_loop ( struct settings *settings ) __nonnull;
102
 
103
 
103
 /**
104
 /**
313
 /**
314
 /**
314
  * Draw information row
315
  * Draw information row
315
  *
316
  *
317
+ * @v settings		Settings block
316
  * @v setting		Current configuration setting
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
 	clearmsg ( INFO_ROW );
331
 	clearmsg ( INFO_ROW );
320
 	attron ( A_BOLD );
332
 	attron ( A_BOLD );
321
-	msg ( INFO_ROW, "%s - %s", setting->name, setting->description );
333
+	msg ( INFO_ROW, "%s - %s", buf, setting->description );
322
 	attroff ( A_BOLD );
334
 	attroff ( A_BOLD );
323
 }
335
 }
324
 
336
 
400
 	
412
 	
401
 	while ( 1 ) {
413
 	while ( 1 ) {
402
 		/* Redraw information and instruction rows */
414
 		/* Redraw information and instruction rows */
403
-		draw_info_row ( widget.setting );
415
+		draw_info_row ( widget.settings, widget.setting );
404
 		draw_instruction_row ( widget.editing );
416
 		draw_instruction_row ( widget.editing );
405
 
417
 
406
 		/* Redraw current setting */
418
 		/* Redraw current setting */

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

251
 extern struct settings * find_settings ( const char *name );
251
 extern struct settings * find_settings ( const char *name );
252
 extern struct setting * find_setting ( const char *name );
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
 extern int storef_setting ( struct settings *settings,
256
 extern int storef_setting ( struct settings *settings,
255
 			    struct setting *setting,
257
 			    struct setting *setting,
256
 			    const char *value );
258
 			    const char *value );

Loading…
Cancel
Save