OpenCoverage

strtrans.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/bash/src/lib/sh/strtrans.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* strtrans.c - Translate and untranslate strings with ANSI-C escape sequences. */-
2-
3/* Copyright (C) 2000-2015 Free Software Foundation, Inc.-
4-
5 This file is part of GNU Bash, the Bourne Again SHell.-
6-
7 Bash is free software: you can redistribute it and/or modify-
8 it under the terms of the GNU General Public License as published by-
9 the Free Software Foundation, either version 3 of the License, or-
10 (at your option) any later version.-
11-
12 Bash is distributed in the hope that it will be useful,-
13 but WITHOUT ANY WARRANTY; without even the implied warranty of-
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-
15 GNU General Public License for more details.-
16-
17 You should have received a copy of the GNU General Public License-
18 along with Bash. If not, see <http://www.gnu.org/licenses/>.-
19*/-
20-
21#include <config.h>-
22-
23#if defined (HAVE_UNISTD_H)-
24# include <unistd.h>-
25#endif-
26-
27#include <bashansi.h>-
28#include <stdio.h>-
29#include <chartypes.h>-
30-
31#include "shell.h"-
32-
33#include "shmbchar.h"-
34#include "shmbutil.h"-
35-
36#ifdef ESC-
37#undef ESC-
38#endif-
39#define ESC '\033' /* ASCII */-
40-
41/* Convert STRING by expanding the escape sequences specified by the-
42 ANSI C standard. If SAWC is non-null, recognize `\c' and use that-
43 as a string terminator. If we see \c, set *SAWC to 1 before-
44 returning. LEN is the length of STRING. If (FLAGS&1) is non-zero,-
45 that we're translating a string for `echo -e', and therefore should not-
46 treat a single quote as a character that may be escaped with a backslash.-
47 If (FLAGS&2) is non-zero, we're expanding for the parser and want to-
48 quote CTLESC and CTLNUL with CTLESC. If (flags&4) is non-zero, we want-
49 to remove the backslash before any unrecognized escape sequence. */-
50char *-
51ansicstr (string, len, flags, sawc, rlen)-
52 char *string;-
53 int len, flags, *sawc, *rlen;-
54{-
55 int c, temp;-
56 char *ret, *r, *s;-
57 unsigned long v;-
58-
59 if (string == 0 || *string == '\0')
string == 0Description
TRUEnever evaluated
FALSEevaluated 2682 times by 1 test
Evaluated by:
  • Self test
*string == '\0'Description
TRUEnever evaluated
FALSEevaluated 2682 times by 1 test
Evaluated by:
  • Self test
0-2682
60 return ((char *)NULL);
never executed: return ((char *) ((void *)0) );
0
61-
62#if defined (HANDLE_MULTIBYTE)-
63 temp = 4*len + 1;-
64 if (temp < 12)
temp < 12Description
TRUEevaluated 176 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2506 times by 1 test
Evaluated by:
  • Self test
176-2506
65 temp = 12; /* ensure enough for eventual u32cesc */
executed 176 times by 1 test: temp = 12;
Executed by:
  • Self test
176
66 ret = (char *)xmalloc (temp);-
67#else-
68 ret = (char *)xmalloc (2*len + 1); /* 2*len for possible CTLESC */-
69#endif-
70 for (r = ret, s = string; s && *s; )
sDescription
TRUEevaluated 9248 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
*sDescription
TRUEevaluated 6586 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2662 times by 1 test
Evaluated by:
  • Self test
0-9248
71 {-
72 c = *s++;-
73 if (c != '\\' || *s == '\0')
c != '\\'Description
TRUEevaluated 1679 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4907 times by 1 test
Evaluated by:
  • Self test
*s == '\0'Description
TRUEnever evaluated
FALSEevaluated 4907 times by 1 test
Evaluated by:
  • Self test
0-4907
74 *r++ = c;
executed 1679 times by 1 test: *r++ = c;
Executed by:
  • Self test
1679
75 else-
76 {-
77 switch (c = *s++)-
78 {-
79#if defined (__STDC__)-
80 case 'a': c = '\a'; break;
executed 28 times by 1 test: break;
Executed by:
  • Self test
executed 28 times by 1 test: case 'a':
Executed by:
  • Self test
28
81 case 'v': c = '\v'; break;
executed 16 times by 1 test: break;
Executed by:
  • Self test
executed 16 times by 1 test: case 'v':
Executed by:
  • Self test
16
82#else-
83 case 'a': c = (int) 0x07; break;-
84 case 'v': c = (int) 0x0B; break;-
85#endif-
86 case 'b': c = '\b'; break;
executed 18 times by 1 test: break;
Executed by:
  • Self test
executed 18 times by 1 test: case 'b':
Executed by:
  • Self test
18
87 case 'e': case 'E': /* ESC -- non-ANSI */
executed 10 times by 1 test: case 'e':
Executed by:
  • Self test
executed 1 time by 1 test: case 'E':
Executed by:
  • Self test
1-10
88 c = ESC; break;
executed 11 times by 1 test: break;
Executed by:
  • Self test
11
89 case 'f': c = '\f'; break;
executed 16 times by 1 test: break;
Executed by:
  • Self test
executed 16 times by 1 test: case 'f':
Executed by:
  • Self test
16
90 case 'n': c = '\n'; break;
executed 218 times by 1 test: break;
Executed by:
  • Self test
executed 218 times by 1 test: case 'n':
Executed by:
  • Self test
218
91 case 'r': c = '\r'; break;
executed 11 times by 1 test: break;
Executed by:
  • Self test
executed 11 times by 1 test: case 'r':
Executed by:
  • Self test
11
92 case 't': c = '\t'; break;
executed 60 times by 1 test: break;
Executed by:
  • Self test
executed 60 times by 1 test: case 't':
Executed by:
  • Self test
60
93 case '1': case '2': case '3':
executed 293 times by 1 test: case '1':
Executed by:
  • Self test
executed 2093 times by 1 test: case '2':
Executed by:
  • Self test
executed 1284 times by 1 test: case '3':
Executed by:
  • Self test
293-2093
94 case '4': case '5': case '6':
never executed: case '4':
never executed: case '5':
never executed: case '6':
0
95 case '7':
never executed: case '7':
0
96#if 1-
97 if (flags & 1)
flags & 1Description
TRUEnever evaluated
FALSEevaluated 3670 times by 1 test
Evaluated by:
  • Self test
0-3670
98 {-
99 *r++ = '\\';-
100 break;
never executed: break;
0
101 }-
102 /*FALLTHROUGH*/-
103#endif-
104 case '0':
code before this statement executed 3670 times by 1 test: case '0':
Executed by:
  • Self test
executed 332 times by 1 test: case '0':
Executed by:
  • Self test
332-3670
105 /* If (FLAGS & 1), we're translating a string for echo -e (or-
106 the equivalent xpg_echo option), so we obey the SUSv3/-
107 POSIX-2001 requirement and accept 0-3 octal digits after-
108 a leading `0'. */-
109 temp = 2 + ((flags & 1) && (c == '0'));
(flags & 1)Description
TRUEevaluated 7 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3995 times by 1 test
Evaluated by:
  • Self test
(c == '0')Description
TRUEevaluated 7 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-3995
110 for (c -= '0'; ISOCTAL (*s) && temp--; s++)
(*s) >= '0'Description
TRUEevaluated 10112 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1856 times by 1 test
Evaluated by:
  • Self test
(*s) <= '7'Description
TRUEevaluated 7970 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2142 times by 1 test
Evaluated by:
  • Self test
temp--Description
TRUEevaluated 7966 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
4-10112
111 c = (c * 8) + OCTVALUE (*s);
executed 7966 times by 1 test: c = (c * 8) + ((*s) - '0');
Executed by:
  • Self test
7966
112 c &= 0xFF;-
113 break;
executed 4002 times by 1 test: break;
Executed by:
  • Self test
4002
114 case 'x': /* Hex digit -- non-ANSI */
executed 269 times by 1 test: case 'x':
Executed by:
  • Self test
269
115 if ((flags & 2) && *s == '{')
(flags & 2)Description
TRUEevaluated 255 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 14 times by 1 test
Evaluated by:
  • Self test
*s == '{'Description
TRUEevaluated 16 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 239 times by 1 test
Evaluated by:
  • Self test
14-255
116 {-
117 flags |= 16; /* internal flag value */-
118 s++;-
119 }
executed 16 times by 1 test: end of block
Executed by:
  • Self test
16
120 /* Consume at least two hex characters */-
121 for (temp = 2, c = 0; ISXDIGIT ((unsigned char)*s) && temp--; s++)
((*__ctype_b_l...nt) _ISxdigit)Description
TRUEevaluated 529 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 247 times by 1 test
Evaluated by:
  • Self test
temp--Description
TRUEevaluated 507 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 22 times by 1 test
Evaluated by:
  • Self test
22-529
122 c = (c * 16) + HEXVALUE (*s);
executed 507 times by 1 test: c = (c * 16) + (((*s) >= 'a' && (*s) <= 'f') ? (*s)-'a'+10 : (*s) >= 'A' && (*s) <= 'F' ? (*s)-'A'+10 : (*s)-'0');
Executed by:
  • Self test
(*s) >= 'a'Description
TRUEevaluated 57 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 450 times by 1 test
Evaluated by:
  • Self test
(*s) <= 'f'Description
TRUEevaluated 57 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(*s) >= 'A'Description
TRUEevaluated 135 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 315 times by 1 test
Evaluated by:
  • Self test
(*s) <= 'F'Description
TRUEevaluated 135 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-507
123 /* DGK says that after a `\x{' ksh93 consumes ISXDIGIT chars-
124 until a non-xdigit or `}', so potentially more than two-
125 chars are consumed. */-
126 if (flags & 16)
flags & 16Description
TRUEevaluated 16 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 253 times by 1 test
Evaluated by:
  • Self test
16-253
127 {-
128 for ( ; ISXDIGIT ((unsigned char)*s); s++)
((*__ctype_b_l...nt) _ISxdigit)Description
TRUEevaluated 10 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 16 times by 1 test
Evaluated by:
  • Self test
10-16
129 c = (c * 16) + HEXVALUE (*s);
executed 10 times by 1 test: c = (c * 16) + (((*s) >= 'a' && (*s) <= 'f') ? (*s)-'a'+10 : (*s) >= 'A' && (*s) <= 'F' ? (*s)-'A'+10 : (*s)-'0');
Executed by:
  • Self test
(*s) >= 'a'Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
(*s) <= 'f'Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(*s) >= 'A'Description
TRUEnever evaluated
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
(*s) <= 'F'Description
TRUEnever evaluated
FALSEnever evaluated
0-10
130 flags &= ~16;-
131 if (*s == '}')
*s == '}'Description
TRUEevaluated 10 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
6-10
132 s++;
executed 10 times by 1 test: s++;
Executed by:
  • Self test
10
133 }
executed 16 times by 1 test: end of block
Executed by:
  • Self test
16
134 /* \x followed by non-hex digits is passed through unchanged */-
135 else if (temp == 2)
temp == 2Description
TRUEevaluated 10 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 243 times by 1 test
Evaluated by:
  • Self test
10-243
136 {-
137 *r++ = '\\';-
138 c = 'x';-
139 }
executed 10 times by 1 test: end of block
Executed by:
  • Self test
10
140 c &= 0xFF;-
141 break;
executed 269 times by 1 test: break;
Executed by:
  • Self test
269
142#if defined (HANDLE_MULTIBYTE)-
143 case 'u':
executed 81 times by 1 test: case 'u':
Executed by:
  • Self test
81
144 case 'U':
executed 26 times by 1 test: case 'U':
Executed by:
  • Self test
26
145 temp = (c == 'u') ? 4 : 8; /* \uNNNN \UNNNNNNNN */
(c == 'u')Description
TRUEevaluated 81 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 26 times by 1 test
Evaluated by:
  • Self test
26-81
146 for (v = 0; ISXDIGIT ((unsigned char)*s) && temp--; s++)
((*__ctype_b_l...nt) _ISxdigit)Description
TRUEevaluated 423 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 107 times by 1 test
Evaluated by:
  • Self test
temp--Description
TRUEevaluated 423 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-423
147 v = (v * 16) + HEXVALUE (*s);
executed 423 times by 1 test: v = (v * 16) + (((*s) >= 'a' && (*s) <= 'f') ? (*s)-'a'+10 : (*s) >= 'A' && (*s) <= 'F' ? (*s)-'A'+10 : (*s)-'0');
Executed by:
  • Self test
(*s) >= 'a'Description
TRUEevaluated 394 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 29 times by 1 test
Evaluated by:
  • Self test
(*s) <= 'f'Description
TRUEevaluated 394 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(*s) >= 'A'Description
TRUEnever evaluated
FALSEevaluated 29 times by 1 test
Evaluated by:
  • Self test
(*s) <= 'F'Description
TRUEnever evaluated
FALSEnever evaluated
0-423
148 if (temp == ((c == 'u') ? 4 : 8))
temp == ((c == 'u') ? 4 : 8)Description
TRUEnever evaluated
FALSEevaluated 107 times by 1 test
Evaluated by:
  • Self test
(c == 'u')Description
TRUEevaluated 81 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 26 times by 1 test
Evaluated by:
  • Self test
0-107
149 {-
150 *r++ = '\\'; /* c remains unchanged */-
151 break;
never executed: break;
0
152 }-
153 else if (v <= 0x7f) /* <= 0x7f translates directly */
v <= 0x7fDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 106 times by 1 test
Evaluated by:
  • Self test
1-106
154 {-
155 c = v;-
156 break;
executed 1 time by 1 test: break;
Executed by:
  • Self test
1
157 }-
158 else-
159 {-
160 temp = u32cconv (v, r);-
161 r += temp;-
162 continue;
executed 106 times by 1 test: continue;
Executed by:
  • Self test
106
163 }-
164#endif-
165 case '\\':
executed 37 times by 1 test: case '\\':
Executed by:
  • Self test
37
166 break;
executed 37 times by 1 test: break;
Executed by:
  • Self test
37
167 case '\'': case '"': case '?':
executed 45 times by 1 test: case '\'':
Executed by:
  • Self test
executed 5 times by 1 test: case '"':
Executed by:
  • Self test
never executed: case '?':
0-45
168 if (flags & 1)
flags & 1Description
TRUEevaluated 20 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 30 times by 1 test
Evaluated by:
  • Self test
20-30
169 *r++ = '\\';
executed 20 times by 1 test: *r++ = '\\';
Executed by:
  • Self test
20
170 break;
executed 50 times by 1 test: break;
Executed by:
  • Self test
50
171 case 'c':
executed 48 times by 1 test: case 'c':
Executed by:
  • Self test
48
172 if (sawc)
sawcDescription
TRUEevaluated 20 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 28 times by 1 test
Evaluated by:
  • Self test
20-28
173 {-
174 *sawc = 1;-
175 *r = '\0';-
176 if (rlen)
rlenDescription
TRUEevaluated 20 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-20
177 *rlen = r - ret;
executed 20 times by 1 test: *rlen = r - ret;
Executed by:
  • Self test
20
178 return ret;
executed 20 times by 1 test: return ret;
Executed by:
  • Self test
20
179 }-
180 else if ((flags & 1) == 0 && *s == 0)
(flags & 1) == 0Description
TRUEevaluated 28 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
*s == 0Description
TRUEnever evaluated
FALSEevaluated 28 times by 1 test
Evaluated by:
  • Self test
0-28
181 ; /* pass \c through */
never executed: ;
0
182 else if ((flags & 1) == 0 && (c = *s))
(flags & 1) == 0Description
TRUEevaluated 28 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(c = *s)Description
TRUEevaluated 28 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-28
183 {-
184 s++;-
185 if ((flags & 2) && c == '\\' && c == *s)
(flags & 2)Description
TRUEevaluated 28 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
c == '\\'Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 25 times by 1 test
Evaluated by:
  • Self test
c == *sDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-28
186 s++; /* Posix requires $'\c\\' do backslash escaping */
executed 3 times by 1 test: s++;
Executed by:
  • Self test
3
187 c = TOCTRL(c);
never executed: end of block
never executed: __res = toupper ( c );
never executed: __res = (*__ctype_toupper_loc ())[(int) ( c )];
sizeof ( c ) > 1Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_constant_p ( c )Description
TRUEnever evaluated
FALSEnever evaluated
(c) == '?'Description
TRUEevaluated 13 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 15 times by 1 test
Evaluated by:
  • Self test
((*__ctype_b_l...int) _ISlower)Description
TRUEnever evaluated
FALSEevaluated 15 times by 1 test
Evaluated by:
  • Self test
__c < -128Description
TRUEnever evaluated
FALSEnever evaluated
__c > 255Description
TRUEnever evaluated
FALSEnever evaluated
0-15
188 break;
executed 28 times by 1 test: break;
Executed by:
  • Self test
28
189 }-
190 /*FALLTHROUGH*/-
191 default:
code before this statement never executed: default:
executed 16 times by 1 test: default:
Executed by:
  • Self test
0-16
192 if ((flags & 4) == 0)
(flags & 4) == 0Description
TRUEevaluated 16 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-16
193 *r++ = '\\';
executed 16 times by 1 test: *r++ = '\\';
Executed by:
  • Self test
16
194 break;
executed 16 times by 1 test: break;
Executed by:
  • Self test
16
195 }-
196 if ((flags & 2) && (c == CTLESC || c == CTLNUL))
(flags & 2)Description
TRUEevaluated 4720 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 61 times by 1 test
Evaluated by:
  • Self test
c == '\001'Description
TRUEevaluated 235 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4485 times by 1 test
Evaluated by:
  • Self test
c == '\177'Description
TRUEevaluated 266 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4219 times by 1 test
Evaluated by:
  • Self test
61-4720
197 *r++ = CTLESC;
executed 501 times by 1 test: *r++ = '\001';
Executed by:
  • Self test
501
198 *r++ = c;-
199 }
executed 4781 times by 1 test: end of block
Executed by:
  • Self test
4781
200 }-
201 *r = '\0';-
202 if (rlen)
rlenDescription
TRUEevaluated 2651 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 11 times by 1 test
Evaluated by:
  • Self test
11-2651
203 *rlen = r - ret;
executed 2651 times by 1 test: *rlen = r - ret;
Executed by:
  • Self test
2651
204 return ret;
executed 2662 times by 1 test: return ret;
Executed by:
  • Self test
2662
205}-
206-
207/* Take a string STR, possibly containing non-printing characters, and turn it-
208 into a $'...' ANSI-C style quoted string. Returns a new string. */-
209char *-
210ansic_quote (str, flags, rlen)-
211 char *str;-
212 int flags, *rlen;-
213{-
214 char *r, *ret, *s;-
215 int l, rsize;-
216 unsigned char c;-
217 size_t clen;-
218 int b;-
219#if defined (HANDLE_MULTIBYTE)-
220 wchar_t wc;-
221#endif-
222-
223 if (str == 0 || *str == 0)
str == 0Description
TRUEnever evaluated
FALSEevaluated 198 times by 1 test
Evaluated by:
  • Self test
*str == 0Description
TRUEnever evaluated
FALSEevaluated 198 times by 1 test
Evaluated by:
  • Self test
0-198
224 return ((char *)0);
never executed: return ((char *)0);
0
225-
226 l = strlen (str);-
227 rsize = 4 * l + 4;-
228 r = ret = (char *)xmalloc (rsize);-
229-
230 *r++ = '$';-
231 *r++ = '\'';-
232-
233 for (s = str; c = *s; s++)
c = *sDescription
TRUEevaluated 337 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 198 times by 1 test
Evaluated by:
  • Self test
198-337
234 {-
235 b = l = 1; /* 1 == add backslash; 0 == no backslash */-
236 clen = 1;-
237-
238 switch (c)-
239 {-
240 case ESC: c = 'E'; break;
never executed: break;
never executed: case '\033':
0
241#ifdef __STDC__-
242 case '\a': c = 'a'; break;
executed 6 times by 1 test: break;
Executed by:
  • Self test
executed 6 times by 1 test: case '\a':
Executed by:
  • Self test
6
243 case '\v': c = 'v'; break;
never executed: break;
never executed: case '\v':
0
244#else-
245 case 0x07: c = 'a'; break;-
246 case 0x0b: c = 'v'; break;-
247#endif-
248-
249 case '\b': c = 'b'; break;
never executed: break;
never executed: case '\b':
0
250 case '\f': c = 'f'; break;
never executed: break;
never executed: case '\f':
0
251 case '\n': c = 'n'; break;
executed 12 times by 1 test: break;
Executed by:
  • Self test
executed 12 times by 1 test: case '\n':
Executed by:
  • Self test
12
252 case '\r': c = 'r'; break;
never executed: break;
never executed: case '\r':
0
253 case '\t': c = 't'; break;
executed 11 times by 1 test: break;
Executed by:
  • Self test
executed 11 times by 1 test: case '\t':
Executed by:
  • Self test
11
254 case '\\':
executed 6 times by 1 test: case '\\':
Executed by:
  • Self test
6
255 case '\'':
never executed: case '\'':
0
256 break;
executed 6 times by 1 test: break;
Executed by:
  • Self test
6
257 default:
executed 302 times by 1 test: default:
Executed by:
  • Self test
302
258#if defined (HANDLE_MULTIBYTE)-
259 b = is_basic (c);-
260 /* XXX - clen comparison to 0 is dicey */-
261 if ((b == 0 && ((clen = mbrtowc (&wc, s, MB_CUR_MAX, 0)) < 0 || MB_INVALIDCH (clen) || iswprint (wc) == 0)) ||
b == 0Description
TRUEevaluated 246 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 56 times by 1 test
Evaluated by:
  • Self test
(clen = mbrtow... ()) , 0)) < 0Description
TRUEnever evaluated
FALSEevaluated 246 times by 1 test
Evaluated by:
  • Self test
(clen) == (size_t)-1Description
TRUEevaluated 187 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 59 times by 1 test
Evaluated by:
  • Self test
(clen) == (size_t)-2Description
TRUEnever evaluated
FALSEevaluated 59 times by 1 test
Evaluated by:
  • Self test
iswprint (wc) == 0Description
TRUEevaluated 55 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
0-246
262 (b == 1 && ISPRINT (c) == 0))
b == 1Description
TRUEevaluated 56 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
(1 && ((*__cty...Sprint) ) == 0Description
TRUEnever evaluated
FALSEevaluated 56 times by 1 test
Evaluated by:
  • Self test
((*__ctype_b_l...int) _ISprint)Description
TRUEevaluated 56 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-56
263#else-
264 if (ISPRINT (c) == 0)-
265#endif-
266 {-
267 *r++ = '\\';-
268 *r++ = TOCHAR ((c >> 6) & 07);-
269 *r++ = TOCHAR ((c >> 3) & 07);-
270 *r++ = TOCHAR (c & 07);-
271 continue;
executed 242 times by 1 test: continue;
Executed by:
  • Self test
242
272 }-
273 l = 0;-
274 break;
executed 60 times by 1 test: break;
Executed by:
  • Self test
60
275 }-
276 if (b == 0 && clen == 0)
b == 0Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 91 times by 1 test
Evaluated by:
  • Self test
clen == 0Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
0-91
277 break;
never executed: break;
0
278-
279 if (l)
lDescription
TRUEevaluated 35 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 60 times by 1 test
Evaluated by:
  • Self test
35-60
280 *r++ = '\\';
executed 35 times by 1 test: *r++ = '\\';
Executed by:
  • Self test
35
281-
282 if (clen == 1)
clen == 1Description
TRUEevaluated 95 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-95
283 *r++ = c;
executed 95 times by 1 test: *r++ = c;
Executed by:
  • Self test
95
284 else-
285 {-
286 for (b = 0; b < (int)clen; b++)
b < (int)clenDescription
TRUEnever evaluated
FALSEnever evaluated
0
287 *r++ = (unsigned char)s[b];
never executed: *r++ = (unsigned char)s[b];
0
288 s += clen - 1; /* -1 because of the increment above */-
289 }
never executed: end of block
0
290 }-
291-
292 *r++ = '\'';-
293 *r = '\0';-
294 if (rlen)
rlenDescription
TRUEnever evaluated
FALSEevaluated 198 times by 1 test
Evaluated by:
  • Self test
0-198
295 *rlen = r - ret;
never executed: *rlen = r - ret;
0
296 return ret;
executed 198 times by 1 test: return ret;
Executed by:
  • Self test
198
297}-
298-
299#if defined (HANDLE_MULTIBYTE)-
300int-
301ansic_wshouldquote (string)-
302 const char *string;-
303{-
304 const wchar_t *wcs;-
305 wchar_t wcc;-
306 wchar_t *wcstr = NULL;-
307 size_t slen;-
308-
309 slen = mbstowcs (wcstr, string, 0);-
310-
311 if (slen == (size_t)-1)
slen == (size_t)-1Description
TRUEevaluated 131 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 168 times by 1 test
Evaluated by:
  • Self test
131-168
312 return 1;
executed 131 times by 1 test: return 1;
Executed by:
  • Self test
131
313-
314 wcstr = (wchar_t *)xmalloc (sizeof (wchar_t) * (slen + 1));-
315 mbstowcs (wcstr, string, slen + 1);-
316-
317 for (wcs = wcstr; wcc = *wcs; wcs++)
wcc = *wcsDescription
TRUEevaluated 294 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 112 times by 1 test
Evaluated by:
  • Self test
112-294
318 if (iswprint(wcc) == 0)
iswprint(wcc) == 0Description
TRUEevaluated 56 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 238 times by 1 test
Evaluated by:
  • Self test
56-238
319 {-
320 free (wcstr);-
321 return 1;
executed 56 times by 1 test: return 1;
Executed by:
  • Self test
56
322 }-
323-
324 free (wcstr);-
325 return 0;
executed 112 times by 1 test: return 0;
Executed by:
  • Self test
112
326}-
327#endif-
328-
329/* return 1 if we need to quote with $'...' because of non-printing chars. */-
330int-
331ansic_shouldquote (string)-
332 const char *string;-
333{-
334 const char *s;-
335 unsigned char c;-
336-
337 if (string == 0)
string == 0Description
TRUEnever evaluated
FALSEevaluated 2088 times by 1 test
Evaluated by:
  • Self test
0-2088
338 return 0;
never executed: return 0;
0
339-
340 for (s = string; c = *s; s++)
c = *sDescription
TRUEevaluated 11447 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1778 times by 1 test
Evaluated by:
  • Self test
1778-11447
341 {-
342#if defined (HANDLE_MULTIBYTE)-
343 if (is_basic (c) == 0)
is_basic (c) == 0Description
TRUEevaluated 299 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 11148 times by 1 test
Evaluated by:
  • Self test
299-11148
344 return (ansic_wshouldquote (s));
executed 299 times by 1 test: return (ansic_wshouldquote (s));
Executed by:
  • Self test
299
345#endif-
346 if (ISPRINT (c) == 0)
(1 && ((*__cty...Sprint) ) == 0Description
TRUEevaluated 11 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 11137 times by 1 test
Evaluated by:
  • Self test
((*__ctype_b_l...int) _ISprint)Description
TRUEevaluated 11137 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 11 times by 1 test
Evaluated by:
  • Self test
11-11137
347 return 1;
executed 11 times by 1 test: return 1;
Executed by:
  • Self test
11
348 }
executed 11137 times by 1 test: end of block
Executed by:
  • Self test
11137
349-
350 return 0;
executed 1778 times by 1 test: return 0;
Executed by:
  • Self test
1778
351}-
352-
353/* $'...' ANSI-C expand the portion of STRING between START and END and-
354 return the result. The result cannot be longer than the input string. */-
355char *-
356ansiexpand (string, start, end, lenp)-
357 char *string;-
358 int start, end, *lenp;-
359{-
360 char *temp, *t;-
361 int len, tlen;-
362-
363 temp = (char *)xmalloc (end - start + 1);-
364 for (tlen = 0, len = start; len < end; )
len < endDescription
TRUEevaluated 20079 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2608 times by 1 test
Evaluated by:
  • Self test
2608-20079
365 temp[tlen++] = string[len++];
executed 20079 times by 1 test: temp[tlen++] = string[len++];
Executed by:
  • Self test
20079
366 temp[tlen] = '\0';-
367-
368 if (*temp)
*tempDescription
TRUEevaluated 2603 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
5-2603
369 {-
370 t = ansicstr (temp, tlen, 2, (int *)NULL, lenp);-
371 free (temp);-
372 return (t);
executed 2603 times by 1 test: return (t);
Executed by:
  • Self test
2603
373 }-
374 else-
375 {-
376 if (lenp)
lenpDescription
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-5
377 *lenp = 0;
executed 5 times by 1 test: *lenp = 0;
Executed by:
  • Self test
5
378 return (temp);
executed 5 times by 1 test: return (temp);
Executed by:
  • Self test
5
379 }-
380}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2