Преглед на файлове

[Settings] Allow encapsulated options to be specified as named settings

Allow encapsulated options to be specified as e.g. "175.3".  As a
side-effect, change the separator character for the type field from "." to
":"; for example, the IP address pseudo-option is now "175.3:ipv4".
tags/v0.9.4
Michael Brown преди 16 години
родител
ревизия
03398e3389
променени са 1 файла, в които са добавени 10 реда и са изтрити 4 реда
  1. 10
    4
      src/core/settings.c

+ 10
- 4
src/core/settings.c Целия файл

@@ -91,7 +91,7 @@ static struct config_setting * find_config_setting ( const char *name ) {
91 91
  * @ret setting		Configuration setting, or NULL
92 92
  *
93 93
  * Find setting if it exists.  If it doesn't exist, but the name is of
94
- * the form "<num>.<type>" (e.g. "12.string"), then construct a
94
+ * the form "<num>:<type>" (e.g. "12:string"), then construct a
95 95
  * setting for that tag and data type, and return it.  The constructed
96 96
  * setting will be placed in the temporary buffer.
97 97
  */
@@ -106,13 +106,19 @@ find_or_build_config_setting ( const char *name,
106 106
 	if ( setting )
107 107
 		return setting;
108 108
 
109
-	/* If name is of the form "<num>.<type>", try to construct a setting */
109
+	/* If name is of the form "<num>:<type>", try to construct a setting */
110 110
 	setting = tmp_setting;
111 111
 	memset ( setting, 0, sizeof ( *setting ) );
112 112
 	setting->name = name;
113
-	setting->tag = strtoul ( name, &separator, 10 );
113
+	for ( separator = ( char * ) name ; 1 ; separator++ ) {
114
+		setting->tag = ( ( setting->tag << 8 ) |
115
+				 strtoul ( separator, &separator, 0 ) );
116
+		if ( *separator != '.' )
117
+			break;
118
+	}
119
+
114 120
 	switch ( *separator ) {
115
-	case '.' :
121
+	case ':' :
116 122
 		setting->type = find_config_setting_type ( separator + 1 );
117 123
 		break;
118 124
 	case '\0' :

Loading…
Отказ
Запис