From 25ec56e0ecaa516a790fc409798e031af4bba650 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Fri, 31 Aug 2012 03:52:06 +0100 Subject: [settings] Use a generic setting's own type as its default type When fetching a named setting using a name that does not explicitly specify a type, default to using the type stored when the setting was created, rather than always defaulting to "string". This allows the behaviour of user-defined settings to match the behaviour of predefined settings (which have a sensible default type). For example: set server:ipv4 192.168.0.1 echo ${server} will now print "192.168.0.1", rather than trying to print out the raw IPv4 address bytes as a string. The downside of this change is that existing tricks for printing special characters within scripts may require (backwards-compatible) modification. For example, the "clear screen" sequence: set esc:hex 1b set cls ${esc}[2J echo ${cls} will now have to become set esc:hex 1b set cls ${esc:string}[2J # Must now explicitly specify ":string" echo ${cls} Signed-off-by: Michael Brown --- src/include/ipxe/settings.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/include/ipxe') diff --git a/src/include/ipxe/settings.h b/src/include/ipxe/settings.h index cd44620..a81e5cc 100644 --- a/src/include/ipxe/settings.h +++ b/src/include/ipxe/settings.h @@ -280,7 +280,12 @@ extern int fetchf_setting ( struct settings *settings, struct setting *setting, extern int storef_setting ( struct settings *settings, struct setting *setting, const char *value ); -extern int storef_named_setting ( const char *name, const char *value ); +extern int store_named_setting ( const char *name, + struct setting_type *default_type, + const void *data, size_t len ); +extern int storef_named_setting ( const char *name, + struct setting_type *default_type, + const char *value ); extern int fetchf_named_setting ( const char *name, char *name_buf, size_t name_len, char *value_buf, size_t value_len ); @@ -366,7 +371,7 @@ static inline int delete_setting ( struct settings *settings, * @ret rc Return status code */ static inline int delete_named_setting ( const char *name ) { - return storef_named_setting ( name, NULL ); + return store_named_setting ( name, NULL, NULL, 0 ); } /** -- cgit v1.1