Changeset 23961 in vbox for trunk/src/VBox/Runtime/common
- Timestamp:
- Oct 22, 2009 9:35:19 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/string/strformatrt.cpp
r21337 r23961 51 51 * - \%RTiop - Takes a #RTIOPORT value. 52 52 * - \%RTldrm - Takes a #RTLDRMOD value. 53 * - \%RTmac - Takes a #PCRTMAC pointer. 54 * - \%RTnaipv4 - Takes a #RTNETADDRIPV4 value. 55 * - \%RTnaipv6 - Takes a #PCRTNETADDRIPV6 value. 56 * - \%RTnthrd - Takes a #RTNATIVETHREAD value. 53 57 * - \%RTnthrd - Takes a #RTNATIVETHREAD value. 54 58 * - \%RTproc - Takes a #RTPROCESS value. … … 153 157 # include <iprt/err.h> 154 158 #endif 159 #include <iprt/ctype.h> 155 160 #include <iprt/time.h> 156 #include <iprt/ ctype.h>161 #include <iprt/net.h> 157 162 #include "internal/string.h" 158 163 … … 198 203 * Interpret the type. 199 204 */ 200 typedef enum { RTSF_INT, RTSF_INTW, RTSF_FP16, RTSF_FP32, RTSF_FP64, RTSF_UUID, RTSF_BOOL } RTSF; 205 typedef enum 206 { 207 RTSF_INT, 208 RTSF_INTW, 209 RTSF_BOOL, 210 RTSF_FP16, 211 RTSF_FP32, 212 RTSF_FP64, 213 RTSF_IPV4, 214 RTSF_IPV6, 215 RTSF_MAC, 216 RTSF_UUID 217 } RTSF; 201 218 static const struct 202 219 { … … 247 264 { STRMEM("Tiop"), sizeof(RTIOPORT), 16, RTSF_INTW, 0 }, 248 265 { STRMEM("Tldrm"), sizeof(RTLDRMOD), 16, RTSF_INTW, 0 }, 266 { STRMEM("Tmac"), sizeof(PCRTMAC), 16, RTSF_MAC, 0 }, 267 { STRMEM("Tnaipv4"), sizeof(RTNETADDRIPV4), 10, RTSF_IPV4, 0 }, 268 { STRMEM("Tnaipv6"), sizeof(PCRTNETADDRIPV6),16, RTSF_IPV6, 0 }, 249 269 { STRMEM("Tnthrd"), sizeof(RTNATIVETHREAD), 16, RTSF_INTW, 0 }, 250 270 { STRMEM("Tproc"), sizeof(RTPROCESS), 16, RTSF_INTW, 0 }, … … 271 291 #undef STRMEM 272 292 }; 293 static const char s_szNull[] = "<NULL>"; 294 273 295 const char *pszType = *ppszFormat - 1; 274 296 int iStart = 0; … … 278 300 union 279 301 { 280 uint8_t u8; 281 uint16_t u16; 282 uint32_t u32; 283 uint64_t u64; 284 int8_t i8; 285 int16_t i16; 286 int32_t i32; 287 int64_t i64; 288 RTFAR16 fp16; 289 RTFAR32 fp32; 290 RTFAR64 fp64; 291 bool fBool; 292 PCRTUUID pUuid; 302 uint8_t u8; 303 uint16_t u16; 304 uint32_t u32; 305 uint64_t u64; 306 int8_t i8; 307 int16_t i16; 308 int32_t i32; 309 int64_t i64; 310 RTFAR16 fp16; 311 RTFAR32 fp32; 312 RTFAR64 fp64; 313 bool fBool; 314 PCRTMAC pMac; 315 RTNETADDRIPV4 Ipv4Addr; 316 PCRTNETADDRIPV6 pIpv6Addr; 317 PCRTUUID pUuid; 293 318 } u; 294 319 char szBuf[80]; … … 414 439 } 415 440 441 case RTSF_BOOL: 442 { 443 static const char s_szTrue[] = "true "; 444 static const char s_szFalse[] = "false"; 445 if (u.u64 == 1) 446 return pfnOutput(pvArgOutput, s_szTrue, sizeof(s_szTrue) - 1); 447 if (u.u64 == 0) 448 return pfnOutput(pvArgOutput, s_szFalse, sizeof(s_szFalse) - 1); 449 /* invalid boolean value */ 450 return RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, "!%lld!", u.u64); 451 } 452 416 453 case RTSF_FP16: 417 454 { … … 448 485 } 449 486 487 case RTSF_IPV4: 488 return RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, 489 "%u.%u.%u.%u", 490 u.Ipv4Addr.au8[0], 491 u.Ipv4Addr.au8[1], 492 u.Ipv4Addr.au8[2], 493 u.Ipv4Addr.au8[3]); 494 495 case RTSF_IPV6: 496 { 497 if (VALID_PTR(u.pIpv6Addr)) 498 return RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, 499 "%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x", 500 u.pIpv6Addr->au8[0], 501 u.pIpv6Addr->au8[1], 502 u.pIpv6Addr->au8[2], 503 u.pIpv6Addr->au8[3], 504 u.pIpv6Addr->au8[4], 505 u.pIpv6Addr->au8[5], 506 u.pIpv6Addr->au8[6], 507 u.pIpv6Addr->au8[7], 508 u.pIpv6Addr->au8[8], 509 u.pIpv6Addr->au8[9], 510 u.pIpv6Addr->au8[10], 511 u.pIpv6Addr->au8[11], 512 u.pIpv6Addr->au8[12], 513 u.pIpv6Addr->au8[13], 514 u.pIpv6Addr->au8[14], 515 u.pIpv6Addr->au8[15]); 516 return pfnOutput(pvArgOutput, s_szNull, sizeof(s_szNull) - 1); 517 } 518 519 case RTSF_MAC: 520 { 521 if (VALID_PTR(u.pMac)) 522 return RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, 523 "%02x:%02x:%02x:%02x:%02x:%02x", 524 u.pMac->au8[0], 525 u.pMac->au8[1], 526 u.pMac->au8[2], 527 u.pMac->au8[3], 528 u.pMac->au8[4], 529 u.pMac->au8[5]); 530 return pfnOutput(pvArgOutput, s_szNull, sizeof(s_szNull) - 1); 531 } 532 450 533 case RTSF_UUID: 451 534 { 452 static const char szNull[] = "<NULL>";453 454 535 if (VALID_PTR(u.pUuid)) 455 536 { … … 469 550 u.pUuid->Gen.au8Node[5]); 470 551 } 471 return pfnOutput(pvArgOutput, szNull, sizeof(szNull) - 1); 472 } 473 474 case RTSF_BOOL: 475 { 476 static const char szTrue[] = "true "; 477 static const char szFalse[] = "false"; 478 if (u.u64 == 1) 479 return pfnOutput(pvArgOutput, szTrue, sizeof(szTrue) - 1); 480 if (u.u64 == 0) 481 return pfnOutput(pvArgOutput, szFalse, sizeof(szFalse) - 1); 482 /* invalid boolean value */ 483 return RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, "!%lld!", u.u64); 552 return pfnOutput(pvArgOutput, s_szNull, sizeof(s_szNull) - 1); 484 553 } 485 554
Note:
See TracChangeset
for help on using the changeset viewer.