File Coverage

ulib/parse.c
Criterion Covered Total %
statement 119 121 98.3
branch 23 26 88.4
condition n/a
subroutine n/a
pod n/a
total 142 147 96.6


line stmt bran cond sub pod time code
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 100         if (strlen(in) != 36)
17 6           return -1;
18 1373624 100         for (i=0, cp = in; i <= 36; i++,cp++) {
19 1337476 100         if ((i == 8) || (i == 13) || (i == 18) || (i == 23)) {
    100          
    100          
    100          
20 144592 50         if (*cp == '-')
21 144592           continue;
22 0           return -1;
23             }
24 1192884 100         if (i == 36 && *cp == 0)
    50          
25 36148           continue;
26 1156736 50         if (!isxdigit((int)*cp))
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 100         for (i=0; i < 6; i++) {
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 958169           static void uu_u64_2hex(const U64 in, char *out, const int len, const char *fmt) {
50 958169           U64 n = in;
51 958169           int i = len;
52              
53             do {
54 3439738           out[--i] = fmt[n % 16];
55 3439738           n >>= 4;
56 3439738 100         } while (n > 0);
57              
58 988287 100         while (i > 0)
59 30118           out[--i] = '0';
60 958169           }
61              
62 217           void uu_parse_unparse_x0(const struct_uu_t *in, char *out, const char *fmt) {
63 217           char *dst = out;
64              
65 217           uu_u64_2hex(in->v1.time_low, dst, 8, fmt); dst += 8; *dst++ = '-';
66 217           uu_u64_2hex(in->v1.time_mid, dst, 4, fmt); dst += 4; *dst++ = '-';
67 217           uu_u64_2hex(in->v1.time_high_and_version, dst, 4, fmt); dst += 4; *dst++ = '-';
68 217           uu_u64_2hex(in->v1.clock_seq_and_variant, dst, 4, fmt); dst += 4; *dst++ = '-';
69 217           uu_u64_2hex(in->v1.node[0], dst, 2, fmt); dst += 2;
70 217           uu_u64_2hex(in->v1.node[1], dst, 2, fmt); dst += 2;
71 217           uu_u64_2hex(in->v1.node[2], dst, 2, fmt); dst += 2;
72 217           uu_u64_2hex(in->v1.node[3], dst, 2, fmt); dst += 2;
73 217           uu_u64_2hex(in->v1.node[4], dst, 2, fmt); dst += 2;
74 217           uu_u64_2hex(in->v1.node[5], dst, 2, fmt); dst += 2;
75 217           *dst = 0;
76 217           }
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: */