| 1 |
|
| #ifdef __cplusplus |
| 2 |
|
| extern "C" { |
| 3 |
|
| #endif |
| 4 |
|
| |
| 5 |
|
| #include "ulib/parse.h" |
| 6 |
|
| |
| 7 |
|
| #ifdef __cplusplus |
| 8 |
|
| } |
| 9 |
|
| #endif |
| 10 |
|
| |
| 11 |
36154 |
| IV uu_parse(const char *in, struct_uu_t *out) { |
| 12 |
|
| int i; |
| 13 |
|
| const char *cp; |
| 14 |
|
| char buf[3]; |
| 15 |
|
| |
| 16 |
36154 |
▶ | if (strlen(in) != 36) |
Branch: 1 branch
| Branch | True | False | Total |
| if (strlen(in) != 36) |
6 |
36148 |
36154 |
|
| 17 |
6 |
| return -1; |
| 18 |
1373624 |
▶ | for (i=0, cp = in; i <= 36; i++,cp++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i=0, cp = in; i <= 36; i++,cp++) { |
1337476 |
36148 |
1373624 |
|
| 19 |
1337476 |
▶ | if ((i == 8) || (i == 13) || (i == 18) || (i == 23)) { |
Branch: 4 branches
| Branch | True | False | Total |
| if ((i == 8) || (i == 13) || (i == 18) || (i == 23)) { |
1301328 |
36148 |
1337476 |
| if ((i == 8) || (i == 13) || (i == 18) || (i == 23)) { |
1265180 |
36148 |
1301328 |
| if ((i == 8) || (i == 13) || (i == 18) || (i == 23)) { |
1229032 |
36148 |
1265180 |
| if ((i == 8) || (i == 13) || (i == 18) || (i == 23)) { |
36148 |
1192884 |
1229032 |
|
| 20 |
144592 |
▶ | if (*cp == '-') |
Branch: 1 branch
| Branch | True | False | Total |
| if (*cp == '-') |
144592 |
0 |
144592 |
|
| 21 |
144592 |
| continue; |
| 22 |
0 |
| return -1; |
| 23 |
|
| } |
| 24 |
1192884 |
▶ | if (i == 36 && *cp == 0) |
Branch: 2 branches
| Branch | True | False | Total |
| if (i == 36 && *cp == 0) |
36148 |
1156736 |
1192884 |
| if (i == 36 && *cp == 0) |
36148 |
0 |
36148 |
|
| 25 |
36148 |
| continue; |
| 26 |
1156736 |
▶ | if (!isxdigit((int)*cp)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!isxdigit((int)*cp)) |
0 |
1156736 |
1156736 |
|
| 27 |
0 |
| return -1; |
| 28 |
|
| } |
| 29 |
36148 |
| out->v1.time_low = strtoul(in, NULL, 16); |
| 30 |
36148 |
| out->v1.time_mid = (U16)strtoul(in+9, NULL, 16); |
| 31 |
36148 |
| out->v1.time_high_and_version = (U16)strtoul(in+14, NULL, 16); |
| 32 |
36148 |
| out->v1.clock_seq_and_variant = (U16)strtoul(in+19, NULL, 16); |
| 33 |
36148 |
| cp = in+24; |
| 34 |
36148 |
| buf[2] = 0; |
| 35 |
253036 |
▶ | for (i=0; i < 6; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i=0; i < 6; i++) { |
216888 |
36148 |
253036 |
|
| 36 |
216888 |
| buf[0] = *cp++; |
| 37 |
216888 |
| buf[1] = *cp++; |
| 38 |
216888 |
| out->v1.node[i] = (U8)strtoul(buf, NULL, 16); |
| 39 |
|
| } |
| 40 |
|
| |
| 41 |
36148 |
| return 0; |
| 42 |
|
| } |
| 43 |
|
| |
| 44 |
|
| |
| 45 |
|
| const char *uu_parse_unparse_fmt_lower = "0123456789abcdef"; |
| 46 |
|
| const char *uu_parse_unparse_fmt_upper = "0123456789ABCDEF"; |
| 47 |
|
| |
| 48 |
|
| /* convert U64 to hex chars. */ |
| 49 |
956589 |
| static void uu_u64_2hex(const U64 in, char *out, const int len, const char *fmt) { |
| 50 |
956589 |
| U64 n = in; |
| 51 |
956589 |
| int i = len; |
| 52 |
|
| |
| 53 |
|
| do { |
| 54 |
3437214 |
| out[--i] = fmt[n % 16]; |
| 55 |
3437214 |
| n >>= 4; |
| 56 |
3437214 |
▶ | } while (n > 0); |
Branch: 1 branch
| Branch | True | False | Total |
| } while (n > 0); |
2480625 |
956589 |
3437214 |
|
| 57 |
|
| |
| 58 |
984175 |
▶ | while (i > 0) |
Branch: 1 branch
| Branch | True | False | Total |
| while (i > 0) |
27586 |
956589 |
984175 |
|
| 59 |
27586 |
| out[--i] = '0'; |
| 60 |
956589 |
| } |
| 61 |
|
| |
| 62 |
59 |
| void uu_parse_unparse_x0(const struct_uu_t *in, char *out, const char *fmt) { |
| 63 |
59 |
| char *dst = out; |
| 64 |
|
| |
| 65 |
59 |
| uu_u64_2hex(in->v1.time_low, dst, 8, fmt); dst += 8; *dst++ = '-'; |
| 66 |
59 |
| uu_u64_2hex(in->v1.time_mid, dst, 4, fmt); dst += 4; *dst++ = '-'; |
| 67 |
59 |
| uu_u64_2hex(in->v1.time_high_and_version, dst, 4, fmt); dst += 4; *dst++ = '-'; |
| 68 |
59 |
| uu_u64_2hex(in->v1.clock_seq_and_variant, dst, 4, fmt); dst += 4; *dst++ = '-'; |
| 69 |
59 |
| uu_u64_2hex(in->v1.node[0], dst, 2, fmt); dst += 2; |
| 70 |
59 |
| uu_u64_2hex(in->v1.node[1], dst, 2, fmt); dst += 2; |
| 71 |
59 |
| uu_u64_2hex(in->v1.node[2], dst, 2, fmt); dst += 2; |
| 72 |
59 |
| uu_u64_2hex(in->v1.node[3], dst, 2, fmt); dst += 2; |
| 73 |
59 |
| uu_u64_2hex(in->v1.node[4], dst, 2, fmt); dst += 2; |
| 74 |
59 |
| uu_u64_2hex(in->v1.node[5], dst, 2, fmt); dst += 2; |
| 75 |
59 |
| *dst = 0; |
| 76 |
59 |
| } |
| 77 |
|
| |
| 78 |
38092 |
| void uu_parse_unparse_x1(const struct_uu_t *in, char *out, const char *fmt) { |
| 79 |
38092 |
| char *dst = out; |
| 80 |
|
| |
| 81 |
38092 |
| uu_u64_2hex(in->v1.time_low, dst, 8, fmt); dst += 8; *dst++ = '-'; |
| 82 |
38092 |
| uu_u64_2hex(in->v1.time_mid, dst, 4, fmt); dst += 4; *dst++ = '-'; |
| 83 |
38092 |
| uu_u64_2hex(in->v1.time_high_and_version, dst, 4, fmt); dst += 4; *dst++ = '-'; |
| 84 |
38092 |
| uu_u64_2hex(in->v1.clock_seq_and_variant, dst, 4, fmt); dst += 4; *dst++ = '-'; |
| 85 |
38092 |
| uu_u64_2hex(in->v1.node[0], dst, 2, fmt); dst += 2; |
| 86 |
38092 |
| uu_u64_2hex(in->v1.node[1], dst, 2, fmt); dst += 2; |
| 87 |
38092 |
| uu_u64_2hex(in->v1.node[2], dst, 2, fmt); dst += 2; |
| 88 |
38092 |
| uu_u64_2hex(in->v1.node[3], dst, 2, fmt); dst += 2; |
| 89 |
38092 |
| uu_u64_2hex(in->v1.node[4], dst, 2, fmt); dst += 2; |
| 90 |
38092 |
| uu_u64_2hex(in->v1.node[5], dst, 2, fmt); dst += 2; |
| 91 |
38092 |
| *dst = 0; |
| 92 |
38092 |
| } |
| 93 |
|
| |
| 94 |
14029 |
| void uu_parse_unparse_x3(const struct_uu_t *in, char *out, const char *fmt) { |
| 95 |
14029 |
| char *dst = out; |
| 96 |
|
| |
| 97 |
14029 |
| uu_u64_2hex(in->v1.time_low, dst, 8, fmt); dst += 8; *dst++ = '-'; |
| 98 |
14029 |
| uu_u64_2hex(in->v1.time_mid, dst, 4, fmt); dst += 4; *dst++ = '-'; |
| 99 |
14029 |
| uu_u64_2hex(in->v1.time_high_and_version, dst, 4, fmt); dst += 4; *dst++ = '-'; |
| 100 |
14029 |
| uu_u64_2hex(in->v1.clock_seq_and_variant, dst, 4, fmt); dst += 4; *dst++ = '-'; |
| 101 |
14029 |
| uu_u64_2hex(in->v1.node[0], dst, 2, fmt); dst += 2; |
| 102 |
14029 |
| uu_u64_2hex(in->v1.node[1], dst, 2, fmt); dst += 2; |
| 103 |
14029 |
| uu_u64_2hex(in->v1.node[2], dst, 2, fmt); dst += 2; |
| 104 |
14029 |
| uu_u64_2hex(in->v1.node[3], dst, 2, fmt); dst += 2; |
| 105 |
14029 |
| uu_u64_2hex(in->v1.node[4], dst, 2, fmt); dst += 2; |
| 106 |
14029 |
| uu_u64_2hex(in->v1.node[5], dst, 2, fmt); dst += 2; |
| 107 |
14029 |
| *dst = 0; |
| 108 |
14029 |
| } |
| 109 |
|
| |
| 110 |
14019 |
| void uu_parse_unparse_x4(const struct_uu_t *in, char *out, const char *fmt) { |
| 111 |
14019 |
| char *dst = out; |
| 112 |
|
| |
| 113 |
14019 |
| uu_u64_2hex(in->v4.rand_a, dst, 8, fmt); dst += 8; *dst++ = '-'; |
| 114 |
14019 |
| uu_u64_2hex(in->v4.rand_b_and_version >> 16, dst, 4, fmt); dst += 4; *dst++ = '-'; |
| 115 |
14019 |
| uu_u64_2hex(in->v4.rand_b_and_version & 0xffff, dst, 4, fmt); dst += 4; *dst++ = '-'; |
| 116 |
14019 |
| uu_u64_2hex(in->v4.rand_c_and_variant >> 16, dst, 4, fmt); dst += 4; *dst++ = '-'; |
| 117 |
14019 |
| uu_u64_2hex(in->v4.rand_c_and_variant & 0xffff, dst, 4, fmt); dst += 4; |
| 118 |
14019 |
| uu_u64_2hex(in->v4.rand_d, dst, 8, fmt); dst += 8; |
| 119 |
14019 |
| *dst = 0; |
| 120 |
14019 |
| } |
| 121 |
|
| |
| 122 |
14023 |
| void uu_parse_unparse_x5(const struct_uu_t *in, char *out, const char *fmt) { |
| 123 |
14023 |
| char *dst = out; |
| 124 |
|
| |
| 125 |
14023 |
| uu_u64_2hex(in->v1.time_low, dst, 8, fmt); dst += 8; *dst++ = '-'; |
| 126 |
14023 |
| uu_u64_2hex(in->v1.time_mid, dst, 4, fmt); dst += 4; *dst++ = '-'; |
| 127 |
14023 |
| uu_u64_2hex(in->v1.time_high_and_version, dst, 4, fmt); dst += 4; *dst++ = '-'; |
| 128 |
14023 |
| uu_u64_2hex(in->v1.clock_seq_and_variant, dst, 4, fmt); dst += 4; *dst++ = '-'; |
| 129 |
14023 |
| uu_u64_2hex(in->v1.node[0], dst, 2, fmt); dst += 2; |
| 130 |
14023 |
| uu_u64_2hex(in->v1.node[1], dst, 2, fmt); dst += 2; |
| 131 |
14023 |
| uu_u64_2hex(in->v1.node[2], dst, 2, fmt); dst += 2; |
| 132 |
14023 |
| uu_u64_2hex(in->v1.node[3], dst, 2, fmt); dst += 2; |
| 133 |
14023 |
| uu_u64_2hex(in->v1.node[4], dst, 2, fmt); dst += 2; |
| 134 |
14023 |
| uu_u64_2hex(in->v1.node[5], dst, 2, fmt); dst += 2; |
| 135 |
14023 |
| *dst = 0; |
| 136 |
14023 |
| } |
| 137 |
|
| |
| 138 |
14036 |
| void uu_parse_unparse_x6(const struct_uu_t *in, char *out, const char *fmt) { |
| 139 |
14036 |
| char *dst = out; |
| 140 |
|
| |
| 141 |
14036 |
| uu_u64_2hex(in->v6.time_high, dst, 8, fmt); dst += 8; *dst++ = '-'; |
| 142 |
14036 |
| uu_u64_2hex(in->v6.time_mid, dst, 4, fmt); dst += 4; *dst++ = '-'; |
| 143 |
14036 |
| uu_u64_2hex(in->v6.time_low_and_version, dst, 4, fmt); dst += 4; *dst++ = '-'; |
| 144 |
14036 |
| uu_u64_2hex(in->v6.clock_seq_and_variant, dst, 4, fmt); dst += 4; *dst++ = '-'; |
| 145 |
14036 |
| uu_u64_2hex(in->v6.node[0], dst, 2, fmt); dst += 2; |
| 146 |
14036 |
| uu_u64_2hex(in->v6.node[1], dst, 2, fmt); dst += 2; |
| 147 |
14036 |
| uu_u64_2hex(in->v6.node[2], dst, 2, fmt); dst += 2; |
| 148 |
14036 |
| uu_u64_2hex(in->v6.node[3], dst, 2, fmt); dst += 2; |
| 149 |
14036 |
| uu_u64_2hex(in->v6.node[4], dst, 2, fmt); dst += 2; |
| 150 |
14036 |
| uu_u64_2hex(in->v6.node[5], dst, 2, fmt); dst += 2; |
| 151 |
14036 |
| *dst = 0; |
| 152 |
14036 |
| } |
| 153 |
|
| |
| 154 |
14017 |
| void uu_parse_unparse_x7(const struct_uu_t *in, char *out, const char *fmt) { |
| 155 |
14017 |
| char *dst = out; |
| 156 |
|
| |
| 157 |
14017 |
| uu_u64_2hex(in->v7.time_high, dst, 8, fmt); dst += 8; *dst++ = '-'; |
| 158 |
14017 |
| uu_u64_2hex(in->v7.time_low, dst, 4, fmt); dst += 4; *dst++ = '-'; |
| 159 |
14017 |
| uu_u64_2hex(in->v7.rand_a_and_version, dst, 4, fmt); dst += 4; *dst++ = '-'; |
| 160 |
14017 |
| uu_u64_2hex(in->v7.rand_b_and_variant >> 48, dst, 4, fmt); dst += 4; *dst++ = '-'; |
| 161 |
14017 |
| uu_u64_2hex(in->v7.rand_b_and_variant & 0xffffffffffffULL, dst, 12, fmt); dst += 12; |
| 162 |
14017 |
| *dst = 0; |
| 163 |
14017 |
| } |
| 164 |
|
| |
| 165 |
|
| /* ex:set ts=2 sw=2 itab=spaces: */ |