Skip to content

Commit 312ae02

Browse files
committedNov 13, 2010
[settings] Add "hexhyp" setting type
Provide a "hexhyp" setting type, which functions identically to the "hex" setting type except that it uses a hyphen instead of a colon as the byte delimiter. For example, if ${mac} expands to "52:54:00:12:34:56", then ${mac:hexhyp} will expand to "52-54-00-12-34-56". Originally-implemented-by: Jarrod Johnson <jarrod.b.johnson@gmail.com> Signed-off-by: Michael Brown <mcb30@ipxe.org>
1 parent 4526f43 commit 312ae02

File tree

1 file changed

+43
-4
lines changed

1 file changed

+43
-4
lines changed
 

‎src/core/settings.c

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,6 +1312,7 @@ static int storef_hex ( struct settings *settings, struct setting *setting,
13121312
case '\0' :
13131313
return store_setting ( settings, setting, bytes, len );
13141314
case ':' :
1315+
case '-' :
13151316
ptr++;
13161317
break;
13171318
default :
@@ -1327,10 +1328,11 @@ static int storef_hex ( struct settings *settings, struct setting *setting,
13271328
* @v setting Setting to fetch
13281329
* @v buf Buffer to contain formatted value
13291330
* @v len Length of buffer
1331+
* @v delimiter Byte delimiter
13301332
* @ret len Length of formatted value, or negative error
13311333
*/
13321334
static int fetchf_hex ( struct settings *settings, struct setting *setting,
1333-
char *buf, size_t len ) {
1335+
char *buf, size_t len, const char *delimiter ) {
13341336
int raw_len;
13351337
int check_len;
13361338
int used = 0;
@@ -1353,18 +1355,55 @@ static int fetchf_hex ( struct settings *settings, struct setting *setting,
13531355
buf[0] = 0; /* Ensure that a terminating NUL exists */
13541356
for ( i = 0 ; i < raw_len ; i++ ) {
13551357
used += ssnprintf ( ( buf + used ), ( len - used ),
1356-
"%s%02x", ( used ? ":" : "" ),
1358+
"%s%02x", ( used ? delimiter : "" ),
13571359
raw[i] );
13581360
}
13591361
return used;
13601362
}
13611363
}
13621364

1363-
/** A hex-string setting */
1365+
/**
1366+
* Fetch and format value of hex string setting (using colon delimiter)
1367+
*
1368+
* @v settings Settings block, or NULL to search all blocks
1369+
* @v setting Setting to fetch
1370+
* @v buf Buffer to contain formatted value
1371+
* @v len Length of buffer
1372+
* @ret len Length of formatted value, or negative error
1373+
*/
1374+
static int fetchf_hex_colon ( struct settings *settings,
1375+
struct setting *setting,
1376+
char *buf, size_t len ) {
1377+
return fetchf_hex ( settings, setting, buf, len, ":" );
1378+
}
1379+
1380+
/**
1381+
* Fetch and format value of hex string setting (using hyphen delimiter)
1382+
*
1383+
* @v settings Settings block, or NULL to search all blocks
1384+
* @v setting Setting to fetch
1385+
* @v buf Buffer to contain formatted value
1386+
* @v len Length of buffer
1387+
* @ret len Length of formatted value, or negative error
1388+
*/
1389+
static int fetchf_hex_hyphen ( struct settings *settings,
1390+
struct setting *setting,
1391+
char *buf, size_t len ) {
1392+
return fetchf_hex ( settings, setting, buf, len, "-" );
1393+
}
1394+
1395+
/** A hex-string setting (colon-delimited) */
13641396
struct setting_type setting_type_hex __setting_type = {
13651397
.name = "hex",
13661398
.storef = storef_hex,
1367-
.fetchf = fetchf_hex,
1399+
.fetchf = fetchf_hex_colon,
1400+
};
1401+
1402+
/** A hex-string setting (hyphen-delimited) */
1403+
struct setting_type setting_type_hexhyp __setting_type = {
1404+
.name = "hexhyp",
1405+
.storef = storef_hex,
1406+
.fetchf = fetchf_hex_hyphen,
13681407
};
13691408

13701409
/**

0 commit comments

Comments
 (0)