Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/coreutils/src/gl/lib/mbsalign.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||||||||||||||
2 | - | |||||||||||||||||||||||||
3 | - | |||||||||||||||||||||||||
4 | static | - | ||||||||||||||||||||||||
5 | _Bool | - | ||||||||||||||||||||||||
6 | - | |||||||||||||||||||||||||
7 | wc_ensure_printable (wchar_t *wchars) | - | ||||||||||||||||||||||||
8 | { | - | ||||||||||||||||||||||||
9 | - | |||||||||||||||||||||||||
10 | _Bool | - | ||||||||||||||||||||||||
11 | replaced = | - | ||||||||||||||||||||||||
12 | 0 | - | ||||||||||||||||||||||||
13 | ; | - | ||||||||||||||||||||||||
14 | wchar_t *wc = wchars; | - | ||||||||||||||||||||||||
15 | while (*
| 0 | ||||||||||||||||||||||||
16 | { | - | ||||||||||||||||||||||||
17 | if (!iswprint ((wint_t) *wc)
| 0 | ||||||||||||||||||||||||
18 | { | - | ||||||||||||||||||||||||
19 | *wc = 0xFFFD; | - | ||||||||||||||||||||||||
20 | replaced = | - | ||||||||||||||||||||||||
21 | 1 | - | ||||||||||||||||||||||||
22 | ; | - | ||||||||||||||||||||||||
23 | } never executed: end of block | 0 | ||||||||||||||||||||||||
24 | wc++; | - | ||||||||||||||||||||||||
25 | } never executed: end of block | 0 | ||||||||||||||||||||||||
26 | return never executed: replaced;return replaced; never executed: return replaced; | 0 | ||||||||||||||||||||||||
27 | } | - | ||||||||||||||||||||||||
28 | - | |||||||||||||||||||||||||
29 | - | |||||||||||||||||||||||||
30 | - | |||||||||||||||||||||||||
31 | - | |||||||||||||||||||||||||
32 | static size_t | - | ||||||||||||||||||||||||
33 | wc_truncate (wchar_t *wc, size_t width) | - | ||||||||||||||||||||||||
34 | { | - | ||||||||||||||||||||||||
35 | size_t cells = 0; | - | ||||||||||||||||||||||||
36 | int next_cells = 0; | - | ||||||||||||||||||||||||
37 | - | |||||||||||||||||||||||||
38 | while (*
| 0 | ||||||||||||||||||||||||
39 | { | - | ||||||||||||||||||||||||
40 | next_cells = wcwidth (*wc); | - | ||||||||||||||||||||||||
41 | if (next_cells == -1
| 0 | ||||||||||||||||||||||||
42 | { | - | ||||||||||||||||||||||||
43 | *wc = 0xFFFD; | - | ||||||||||||||||||||||||
44 | next_cells = 1; | - | ||||||||||||||||||||||||
45 | } never executed: end of block | 0 | ||||||||||||||||||||||||
46 | if (cells + next_cells > width
| 0 | ||||||||||||||||||||||||
47 | break; never executed: break; | 0 | ||||||||||||||||||||||||
48 | cells += next_cells; | - | ||||||||||||||||||||||||
49 | wc++; | - | ||||||||||||||||||||||||
50 | } never executed: end of block | 0 | ||||||||||||||||||||||||
51 | *wc = L'\0'; | - | ||||||||||||||||||||||||
52 | return never executed: cells;return cells; never executed: return cells; | 0 | ||||||||||||||||||||||||
53 | } | - | ||||||||||||||||||||||||
54 | - | |||||||||||||||||||||||||
55 | - | |||||||||||||||||||||||||
56 | - | |||||||||||||||||||||||||
57 | - | |||||||||||||||||||||||||
58 | - | |||||||||||||||||||||||||
59 | - | |||||||||||||||||||||||||
60 | static char* | - | ||||||||||||||||||||||||
61 | mbs_align_pad (char *dest, const char* dest_end, size_t n_spaces) | - | ||||||||||||||||||||||||
62 | { | - | ||||||||||||||||||||||||
63 | - | |||||||||||||||||||||||||
64 | - | |||||||||||||||||||||||||
65 | while (n_spaces--
| 0-119527 | ||||||||||||||||||||||||
66 | * executed 119527 times by 4 tests: dest++ = ' ';*dest++ = ' '; Executed by:
executed 119527 times by 4 tests: *dest++ = ' '; Executed by:
| 119527 | ||||||||||||||||||||||||
67 | *dest = '\0'; | - | ||||||||||||||||||||||||
68 | return executed 10062 times by 4 tests: dest;return dest; Executed by:
executed 10062 times by 4 tests: return dest; Executed by:
| 10062 | ||||||||||||||||||||||||
69 | } | - | ||||||||||||||||||||||||
70 | size_t | - | ||||||||||||||||||||||||
71 | mbsalign (const char *src, char *dest, size_t dest_size, | - | ||||||||||||||||||||||||
72 | size_t *width, mbs_align_t align, int flags) | - | ||||||||||||||||||||||||
73 | { | - | ||||||||||||||||||||||||
74 | size_t ret = | - | ||||||||||||||||||||||||
75 | (18446744073709551615UL) | - | ||||||||||||||||||||||||
76 | ; | - | ||||||||||||||||||||||||
77 | size_t src_size = strlen (src) + 1; | - | ||||||||||||||||||||||||
78 | char *newstr = | - | ||||||||||||||||||||||||
79 | ((void *)0) | - | ||||||||||||||||||||||||
80 | ; | - | ||||||||||||||||||||||||
81 | wchar_t *str_wc = | - | ||||||||||||||||||||||||
82 | ((void *)0) | - | ||||||||||||||||||||||||
83 | ; | - | ||||||||||||||||||||||||
84 | const char *str_to_print = src; | - | ||||||||||||||||||||||||
85 | size_t n_cols = src_size - 1; | - | ||||||||||||||||||||||||
86 | size_t n_used_bytes = n_cols; | - | ||||||||||||||||||||||||
87 | size_t n_spaces = 0; | - | ||||||||||||||||||||||||
88 | - | |||||||||||||||||||||||||
89 | _Bool | - | ||||||||||||||||||||||||
90 | conversion = | - | ||||||||||||||||||||||||
91 | 0 | - | ||||||||||||||||||||||||
92 | ; | - | ||||||||||||||||||||||||
93 | - | |||||||||||||||||||||||||
94 | _Bool | - | ||||||||||||||||||||||||
95 | wc_enabled = | - | ||||||||||||||||||||||||
96 | 0 | - | ||||||||||||||||||||||||
97 | ; | - | ||||||||||||||||||||||||
98 | - | |||||||||||||||||||||||||
99 | - | |||||||||||||||||||||||||
100 | - | |||||||||||||||||||||||||
101 | - | |||||||||||||||||||||||||
102 | if (!(flags & MBA_UNIBYTE_ONLY)
| 31-5000 | ||||||||||||||||||||||||
103 | (
| 0-5000 | ||||||||||||||||||||||||
104 | > 1
| 0-5000 | ||||||||||||||||||||||||
105 | { | - | ||||||||||||||||||||||||
106 | size_t src_chars = mbstowcs ( | - | ||||||||||||||||||||||||
107 | ((void *)0) | - | ||||||||||||||||||||||||
108 | , src, 0); | - | ||||||||||||||||||||||||
109 | if (src_chars ==
| 0 | ||||||||||||||||||||||||
110 | (18446744073709551615UL)
| 0 | ||||||||||||||||||||||||
111 | ) | - | ||||||||||||||||||||||||
112 | { | - | ||||||||||||||||||||||||
113 | if (flags & MBA_UNIBYTE_FALLBACK
| 0 | ||||||||||||||||||||||||
114 | goto never executed: mbsalign_unibyte;goto mbsalign_unibyte; never executed: goto mbsalign_unibyte; | 0 | ||||||||||||||||||||||||
115 | else | - | ||||||||||||||||||||||||
116 | goto never executed: mbsalign_cleanup;goto mbsalign_cleanup; never executed: goto mbsalign_cleanup; | 0 | ||||||||||||||||||||||||
117 | } | - | ||||||||||||||||||||||||
118 | src_chars += 1; | - | ||||||||||||||||||||||||
119 | str_wc = malloc (src_chars * sizeof (wchar_t)); | - | ||||||||||||||||||||||||
120 | if (str_wc ==
| 0 | ||||||||||||||||||||||||
121 | ((void *)0)
| 0 | ||||||||||||||||||||||||
122 | ) | - | ||||||||||||||||||||||||
123 | { | - | ||||||||||||||||||||||||
124 | if (flags & MBA_UNIBYTE_FALLBACK
| 0 | ||||||||||||||||||||||||
125 | goto never executed: mbsalign_unibyte;goto mbsalign_unibyte; never executed: goto mbsalign_unibyte; | 0 | ||||||||||||||||||||||||
126 | else | - | ||||||||||||||||||||||||
127 | goto never executed: mbsalign_cleanup;goto mbsalign_cleanup; never executed: goto mbsalign_cleanup; | 0 | ||||||||||||||||||||||||
128 | } | - | ||||||||||||||||||||||||
129 | if (mbstowcs (str_wc, src, src_chars) != 0
| 0 | ||||||||||||||||||||||||
130 | { | - | ||||||||||||||||||||||||
131 | str_wc[src_chars - 1] = L'\0'; | - | ||||||||||||||||||||||||
132 | wc_enabled = | - | ||||||||||||||||||||||||
133 | 1 | - | ||||||||||||||||||||||||
134 | ; | - | ||||||||||||||||||||||||
135 | conversion = wc_ensure_printable (str_wc); | - | ||||||||||||||||||||||||
136 | n_cols = wcswidth (str_wc, src_chars); | - | ||||||||||||||||||||||||
137 | } never executed: end of block | 0 | ||||||||||||||||||||||||
138 | } never executed: end of block | 0 | ||||||||||||||||||||||||
139 | - | |||||||||||||||||||||||||
140 | - | |||||||||||||||||||||||||
141 | - | |||||||||||||||||||||||||
142 | if (wc_enabled
| 0-5031 | ||||||||||||||||||||||||
143 | { | - | ||||||||||||||||||||||||
144 | if (conversion
| 0 | ||||||||||||||||||||||||
145 | { | - | ||||||||||||||||||||||||
146 | - | |||||||||||||||||||||||||
147 | - | |||||||||||||||||||||||||
148 | src_size = wcstombs ( | - | ||||||||||||||||||||||||
149 | ((void *)0) | - | ||||||||||||||||||||||||
150 | , str_wc, 0) + 1; | - | ||||||||||||||||||||||||
151 | } never executed: end of block | 0 | ||||||||||||||||||||||||
152 | newstr = malloc (src_size); | - | ||||||||||||||||||||||||
153 | if (newstr ==
| 0 | ||||||||||||||||||||||||
154 | ((void *)0)
| 0 | ||||||||||||||||||||||||
155 | ) | - | ||||||||||||||||||||||||
156 | { | - | ||||||||||||||||||||||||
157 | if (flags & MBA_UNIBYTE_FALLBACK
| 0 | ||||||||||||||||||||||||
158 | goto never executed: mbsalign_unibyte;goto mbsalign_unibyte; never executed: goto mbsalign_unibyte; | 0 | ||||||||||||||||||||||||
159 | else | - | ||||||||||||||||||||||||
160 | goto never executed: mbsalign_cleanup;goto mbsalign_cleanup; never executed: goto mbsalign_cleanup; | 0 | ||||||||||||||||||||||||
161 | } | - | ||||||||||||||||||||||||
162 | str_to_print = newstr; | - | ||||||||||||||||||||||||
163 | n_cols = wc_truncate (str_wc, *width); | - | ||||||||||||||||||||||||
164 | n_used_bytes = wcstombs (newstr, str_wc, src_size); | - | ||||||||||||||||||||||||
165 | } never executed: end of block | 0 | ||||||||||||||||||||||||
166 | - | |||||||||||||||||||||||||
167 | mbsalign_unibyte: code before this statement executed 5031 times by 4 tests: mbsalign_unibyte: Executed by:
| 5031 | ||||||||||||||||||||||||
168 | - | |||||||||||||||||||||||||
169 | if (n_cols > *width
| 0-5031 | ||||||||||||||||||||||||
170 | { | - | ||||||||||||||||||||||||
171 | n_cols = *width; | - | ||||||||||||||||||||||||
172 | n_used_bytes = n_cols; | - | ||||||||||||||||||||||||
173 | } never executed: end of block | 0 | ||||||||||||||||||||||||
174 | - | |||||||||||||||||||||||||
175 | if (*
| 1986-3045 | ||||||||||||||||||||||||
176 | n_spaces = *width - n_cols; executed 3045 times by 4 tests: n_spaces = *width - n_cols; Executed by:
| 3045 | ||||||||||||||||||||||||
177 | - | |||||||||||||||||||||||||
178 | - | |||||||||||||||||||||||||
179 | *width = n_cols; | - | ||||||||||||||||||||||||
180 | - | |||||||||||||||||||||||||
181 | { | - | ||||||||||||||||||||||||
182 | size_t start_spaces, end_spaces; | - | ||||||||||||||||||||||||
183 | - | |||||||||||||||||||||||||
184 | switch (align) | - | ||||||||||||||||||||||||
185 | { | - | ||||||||||||||||||||||||
186 | case executed 3927 times by 4 tests: MBS_ALIGN_LEFT:case MBS_ALIGN_LEFT: Executed by:
executed 3927 times by 4 tests: case MBS_ALIGN_LEFT: Executed by:
| 3927 | ||||||||||||||||||||||||
187 | start_spaces = 0; | - | ||||||||||||||||||||||||
188 | end_spaces = n_spaces; | - | ||||||||||||||||||||||||
189 | break; executed 3927 times by 4 tests: break; Executed by:
| 3927 | ||||||||||||||||||||||||
190 | case executed 1104 times by 2 tests: MBS_ALIGN_RIGHT:case MBS_ALIGN_RIGHT: Executed by:
executed 1104 times by 2 tests: case MBS_ALIGN_RIGHT: Executed by:
| 1104 | ||||||||||||||||||||||||
191 | start_spaces = n_spaces; | - | ||||||||||||||||||||||||
192 | end_spaces = 0; | - | ||||||||||||||||||||||||
193 | break; executed 1104 times by 2 tests: break; Executed by:
| 1104 | ||||||||||||||||||||||||
194 | case never executed: MBS_ALIGN_CENTER:case MBS_ALIGN_CENTER: never executed: case MBS_ALIGN_CENTER: | 0 | ||||||||||||||||||||||||
195 | default never executed: :default: never executed: default: | 0 | ||||||||||||||||||||||||
196 | start_spaces = n_spaces / 2 + n_spaces % 2; | - | ||||||||||||||||||||||||
197 | end_spaces = n_spaces / 2; | - | ||||||||||||||||||||||||
198 | break; never executed: break; | 0 | ||||||||||||||||||||||||
199 | } | - | ||||||||||||||||||||||||
200 | - | |||||||||||||||||||||||||
201 | if (flags & MBA_NO_LEFT_PAD
| 0-5031 | ||||||||||||||||||||||||
202 | start_spaces = 0; never executed: start_spaces = 0; | 0 | ||||||||||||||||||||||||
203 | if (flags & MBA_NO_RIGHT_PAD
| 311-4720 | ||||||||||||||||||||||||
204 | end_spaces = 0; executed 311 times by 1 test: end_spaces = 0; Executed by:
| 311 | ||||||||||||||||||||||||
205 | - | |||||||||||||||||||||||||
206 | - | |||||||||||||||||||||||||
207 | if (dest_size != 0
| 0-5031 | ||||||||||||||||||||||||
208 | { | - | ||||||||||||||||||||||||
209 | size_t space_left; | - | ||||||||||||||||||||||||
210 | char *dest_end = dest + dest_size - 1; | - | ||||||||||||||||||||||||
211 | - | |||||||||||||||||||||||||
212 | dest = mbs_align_pad (dest, dest_end, start_spaces); | - | ||||||||||||||||||||||||
213 | space_left = dest_end - dest; | - | ||||||||||||||||||||||||
214 | dest = mempcpy (dest, str_to_print, ((n_used_bytes) < (space_left) ? (n_used_bytes) : (space_left))); | - | ||||||||||||||||||||||||
215 | mbs_align_pad (dest, dest_end, end_spaces); | - | ||||||||||||||||||||||||
216 | } executed 5031 times by 4 tests: end of block Executed by:
| 5031 | ||||||||||||||||||||||||
217 | - | |||||||||||||||||||||||||
218 | - | |||||||||||||||||||||||||
219 | ret = n_used_bytes + ((start_spaces + end_spaces) * 1); | - | ||||||||||||||||||||||||
220 | } | - | ||||||||||||||||||||||||
221 | - | |||||||||||||||||||||||||
222 | mbsalign_cleanup: code before this statement executed 5031 times by 4 tests: mbsalign_cleanup: Executed by:
| 5031 | ||||||||||||||||||||||||
223 | - | |||||||||||||||||||||||||
224 | free (str_wc); | - | ||||||||||||||||||||||||
225 | free (newstr); | - | ||||||||||||||||||||||||
226 | - | |||||||||||||||||||||||||
227 | return executed 5031 times by 4 tests: ret;return ret; Executed by:
executed 5031 times by 4 tests: return ret; Executed by:
| 5031 | ||||||||||||||||||||||||
228 | } | - | ||||||||||||||||||||||||
229 | - | |||||||||||||||||||||||||
230 | - | |||||||||||||||||||||||||
231 | - | |||||||||||||||||||||||||
232 | - | |||||||||||||||||||||||||
233 | - | |||||||||||||||||||||||||
234 | char * | - | ||||||||||||||||||||||||
235 | ambsalign (const char *src, size_t *width, mbs_align_t align, int flags) | - | ||||||||||||||||||||||||
236 | { | - | ||||||||||||||||||||||||
237 | size_t orig_width = *width; | - | ||||||||||||||||||||||||
238 | size_t size = *width; | - | ||||||||||||||||||||||||
239 | size_t req = size; | - | ||||||||||||||||||||||||
240 | char *buf = | - | ||||||||||||||||||||||||
241 | ((void *)0) | - | ||||||||||||||||||||||||
242 | ; | - | ||||||||||||||||||||||||
243 | - | |||||||||||||||||||||||||
244 | while (req >= size
| 1688 | ||||||||||||||||||||||||
245 | { | - | ||||||||||||||||||||||||
246 | char *nbuf; | - | ||||||||||||||||||||||||
247 | size = req + 1; | - | ||||||||||||||||||||||||
248 | nbuf = realloc (buf, size); | - | ||||||||||||||||||||||||
249 | if (nbuf ==
| 0-1688 | ||||||||||||||||||||||||
250 | ((void *)0)
| 0-1688 | ||||||||||||||||||||||||
251 | ) | - | ||||||||||||||||||||||||
252 | { | - | ||||||||||||||||||||||||
253 | free (buf); | - | ||||||||||||||||||||||||
254 | buf = | - | ||||||||||||||||||||||||
255 | ((void *)0) | - | ||||||||||||||||||||||||
256 | ; | - | ||||||||||||||||||||||||
257 | break; never executed: break; | 0 | ||||||||||||||||||||||||
258 | } | - | ||||||||||||||||||||||||
259 | buf = nbuf; | - | ||||||||||||||||||||||||
260 | *width = orig_width; | - | ||||||||||||||||||||||||
261 | req = mbsalign (src, buf, size, width, align, flags); | - | ||||||||||||||||||||||||
262 | if (req ==
| 0-1688 | ||||||||||||||||||||||||
263 | (18446744073709551615UL)
| 0-1688 | ||||||||||||||||||||||||
264 | ) | - | ||||||||||||||||||||||||
265 | { | - | ||||||||||||||||||||||||
266 | free (buf); | - | ||||||||||||||||||||||||
267 | buf = | - | ||||||||||||||||||||||||
268 | ((void *)0) | - | ||||||||||||||||||||||||
269 | ; | - | ||||||||||||||||||||||||
270 | break; never executed: break; | 0 | ||||||||||||||||||||||||
271 | } | - | ||||||||||||||||||||||||
272 | } executed 1688 times by 1 test: end of block Executed by:
| 1688 | ||||||||||||||||||||||||
273 | - | |||||||||||||||||||||||||
274 | return executed 1688 times by 1 test: buf;return buf; Executed by:
executed 1688 times by 1 test: return buf; Executed by:
| 1688 | ||||||||||||||||||||||||
275 | } | - | ||||||||||||||||||||||||
Switch to Source code | Preprocessed file |