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 1440154           IV uu_parse(const char *in, struct_uu_t *out) {
12             int i;
13             const char *cp;
14             char buf[3];
15              
16 1440154 100         if (strlen(in) != 36)
17 6           return -1;
18 54725624 100         for (i=0, cp = in; i <= 36; i++,cp++) {
19 53285476 100         if ((i == 8) || (i == 13) || (i == 18) || (i == 23)) {
    100          
    100          
    100          
20 5760592 50         if (*cp == '-')
21 5760592           continue;
22 0           return -1;
23             }
24 47524884 100         if (i == 36 && *cp == 0)
    50          
25 1440148           continue;
26 46084736 50         if (!isxdigit((int)*cp))
27 0           return -1;
28             }
29 1440148           out->v1.time_low = strtoul(in, NULL, 16);
30 1440148           out->v1.time_mid = (U16)strtoul(in+9, NULL, 16);
31 1440148           out->v1.time_high_and_version = (U16)strtoul(in+14, NULL, 16);
32 1440148           out->v1.clock_seq_and_variant = (U16)strtoul(in+19, NULL, 16);
33 1440148           cp = in+24;
34 1440148           buf[2] = 0;
35 10081036 100         for (i=0; i < 6; i++) {
36 8640888           buf[0] = *cp++;
37 8640888           buf[1] = *cp++;
38 8640888           out->v1.node[i] = (U8)strtoul(buf, NULL, 16);
39             }
40              
41 1440148           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 38524749           static void uu_u64_2hex(const U64 in, char *out, const int len, const char *fmt) {
50 38524749           U64 n = in;
51 38524749           int i = len;
52              
53             do {
54 136978904           out[--i] = fmt[n % 16];
55 136978904           n >>= 4;
56 136978904 100         } while (n > 0);
57              
58 39801557 100         while (i > 0)
59 1276808           out[--i] = '0';
60 38524749           }
61              
62 275           void uu_parse_unparse_x0(const struct_uu_t *in, char *out, const char *fmt) {
63 275           char *dst = out;
64              
65 275           uu_u64_2hex(in->v1.time_low, dst, 8, fmt); dst += 8; *dst++ = '-';
66 275           uu_u64_2hex(in->v1.time_mid, dst, 4, fmt); dst += 4; *dst++ = '-';
67 275           uu_u64_2hex(in->v1.time_high_and_version, dst, 4, fmt); dst += 4; *dst++ = '-';
68 275           uu_u64_2hex(in->v1.clock_seq_and_variant, dst, 4, fmt); dst += 4; *dst++ = '-';
69 275           uu_u64_2hex(in->v1.node[0], dst, 2, fmt); dst += 2;
70 275           uu_u64_2hex(in->v1.node[1], dst, 2, fmt); dst += 2;
71 275           uu_u64_2hex(in->v1.node[2], dst, 2, fmt); dst += 2;
72 275           uu_u64_2hex(in->v1.node[3], dst, 2, fmt); dst += 2;
73 275           uu_u64_2hex(in->v1.node[4], dst, 2, fmt); dst += 2;
74 275           uu_u64_2hex(in->v1.node[5], dst, 2, fmt); dst += 2;
75 275           *dst = 0;
76 275           }
77              
78 1720092           void uu_parse_unparse_x1(const struct_uu_t *in, char *out, const char *fmt) {
79 1720092           char *dst = out;
80              
81 1720092           uu_u64_2hex(in->v1.time_low, dst, 8, fmt); dst += 8; *dst++ = '-';
82 1720092           uu_u64_2hex(in->v1.time_mid, dst, 4, fmt); dst += 4; *dst++ = '-';
83 1720092           uu_u64_2hex(in->v1.time_high_and_version, dst, 4, fmt); dst += 4; *dst++ = '-';
84 1720092           uu_u64_2hex(in->v1.clock_seq_and_variant, dst, 4, fmt); dst += 4; *dst++ = '-';
85 1720092           uu_u64_2hex(in->v1.node[0], dst, 2, fmt); dst += 2;
86 1720092           uu_u64_2hex(in->v1.node[1], dst, 2, fmt); dst += 2;
87 1720092           uu_u64_2hex(in->v1.node[2], dst, 2, fmt); dst += 2;
88 1720092           uu_u64_2hex(in->v1.node[3], dst, 2, fmt); dst += 2;
89 1720092           uu_u64_2hex(in->v1.node[4], dst, 2, fmt); dst += 2;
90 1720092           uu_u64_2hex(in->v1.node[5], dst, 2, fmt); dst += 2;
91 1720092           *dst = 0;
92 1720092           }
93              
94 520029           void uu_parse_unparse_x3(const struct_uu_t *in, char *out, const char *fmt) {
95 520029           char *dst = out;
96              
97 520029           uu_u64_2hex(in->v1.time_low, dst, 8, fmt); dst += 8; *dst++ = '-';
98 520029           uu_u64_2hex(in->v1.time_mid, dst, 4, fmt); dst += 4; *dst++ = '-';
99 520029           uu_u64_2hex(in->v1.time_high_and_version, dst, 4, fmt); dst += 4; *dst++ = '-';
100 520029           uu_u64_2hex(in->v1.clock_seq_and_variant, dst, 4, fmt); dst += 4; *dst++ = '-';
101 520029           uu_u64_2hex(in->v1.node[0], dst, 2, fmt); dst += 2;
102 520029           uu_u64_2hex(in->v1.node[1], dst, 2, fmt); dst += 2;
103 520029           uu_u64_2hex(in->v1.node[2], dst, 2, fmt); dst += 2;
104 520029           uu_u64_2hex(in->v1.node[3], dst, 2, fmt); dst += 2;
105 520029           uu_u64_2hex(in->v1.node[4], dst, 2, fmt); dst += 2;
106 520029           uu_u64_2hex(in->v1.node[5], dst, 2, fmt); dst += 2;
107 520029           *dst = 0;
108 520029           }
109              
110 520019           void uu_parse_unparse_x4(const struct_uu_t *in, char *out, const char *fmt) {
111 520019           char *dst = out;
112              
113 520019           uu_u64_2hex(in->v4.rand_a, dst, 8, fmt); dst += 8; *dst++ = '-';
114 520019           uu_u64_2hex(in->v4.rand_b_and_version >> 16, dst, 4, fmt); dst += 4; *dst++ = '-';
115 520019           uu_u64_2hex(in->v4.rand_b_and_version & 0xffff, dst, 4, fmt); dst += 4; *dst++ = '-';
116 520019           uu_u64_2hex(in->v4.rand_c_and_variant >> 16, dst, 4, fmt); dst += 4; *dst++ = '-';
117 520019           uu_u64_2hex(in->v4.rand_c_and_variant & 0xffff, dst, 4, fmt); dst += 4;
118 520019           uu_u64_2hex(in->v4.rand_d, dst, 8, fmt); dst += 8;
119 520019           *dst = 0;
120 520019           }
121              
122 520023           void uu_parse_unparse_x5(const struct_uu_t *in, char *out, const char *fmt) {
123 520023           char *dst = out;
124              
125 520023           uu_u64_2hex(in->v1.time_low, dst, 8, fmt); dst += 8; *dst++ = '-';
126 520023           uu_u64_2hex(in->v1.time_mid, dst, 4, fmt); dst += 4; *dst++ = '-';
127 520023           uu_u64_2hex(in->v1.time_high_and_version, dst, 4, fmt); dst += 4; *dst++ = '-';
128 520023           uu_u64_2hex(in->v1.clock_seq_and_variant, dst, 4, fmt); dst += 4; *dst++ = '-';
129 520023           uu_u64_2hex(in->v1.node[0], dst, 2, fmt); dst += 2;
130 520023           uu_u64_2hex(in->v1.node[1], dst, 2, fmt); dst += 2;
131 520023           uu_u64_2hex(in->v1.node[2], dst, 2, fmt); dst += 2;
132 520023           uu_u64_2hex(in->v1.node[3], dst, 2, fmt); dst += 2;
133 520023           uu_u64_2hex(in->v1.node[4], dst, 2, fmt); dst += 2;
134 520023           uu_u64_2hex(in->v1.node[5], dst, 2, fmt); dst += 2;
135 520023           *dst = 0;
136 520023           }
137              
138 520036           void uu_parse_unparse_x6(const struct_uu_t *in, char *out, const char *fmt) {
139 520036           char *dst = out;
140              
141 520036           uu_u64_2hex(in->v6.time_high, dst, 8, fmt); dst += 8; *dst++ = '-';
142 520036           uu_u64_2hex(in->v6.time_mid, dst, 4, fmt); dst += 4; *dst++ = '-';
143 520036           uu_u64_2hex(in->v6.time_low_and_version, dst, 4, fmt); dst += 4; *dst++ = '-';
144 520036           uu_u64_2hex(in->v6.clock_seq_and_variant, dst, 4, fmt); dst += 4; *dst++ = '-';
145 520036           uu_u64_2hex(in->v6.node[0], dst, 2, fmt); dst += 2;
146 520036           uu_u64_2hex(in->v6.node[1], dst, 2, fmt); dst += 2;
147 520036           uu_u64_2hex(in->v6.node[2], dst, 2, fmt); dst += 2;
148 520036           uu_u64_2hex(in->v6.node[3], dst, 2, fmt); dst += 2;
149 520036           uu_u64_2hex(in->v6.node[4], dst, 2, fmt); dst += 2;
150 520036           uu_u64_2hex(in->v6.node[5], dst, 2, fmt); dst += 2;
151 520036           *dst = 0;
152 520036           }
153              
154 520017           void uu_parse_unparse_x7(const struct_uu_t *in, char *out, const char *fmt) {
155 520017           char *dst = out;
156              
157 520017           uu_u64_2hex(in->v7.time_high, dst, 8, fmt); dst += 8; *dst++ = '-';
158 520017           uu_u64_2hex(in->v7.time_low, dst, 4, fmt); dst += 4; *dst++ = '-';
159 520017           uu_u64_2hex(in->v7.rand_a_and_version, dst, 4, fmt); dst += 4; *dst++ = '-';
160 520017           uu_u64_2hex(in->v7.rand_b_and_variant >> 48, dst, 4, fmt); dst += 4; *dst++ = '-';
161 520017           uu_u64_2hex(in->v7.rand_b_and_variant & 0xffffffffffffULL, dst, 12, fmt); dst += 12;
162 520017           *dst = 0;
163 520017           }
164              
165             /* ex:set ts=2 sw=2 itab=spaces: */