Changeset 871 for trunk/dll/literal.c
- Timestamp:
- Nov 17, 2007, 2:13:23 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/dll/literal.c
r834 r871 8 8 9 9 Copyright (c) 1993-98 M. Kimes 10 Copyright (c) 2004, 200 6Steven H.Levine10 Copyright (c) 2004, 2007 Steven H.Levine 11 11 12 12 Archive containers … … 16 16 22 Jul 06 SHL Check more run time errors 17 17 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat 18 16 Nov 07 SHL Report fixup buffer overflow 18 19 19 20 ***********************************************************************/ … … 100 101 switch (pszBuf[iBuf + 1]) { 101 102 case 'x': /* hexadecimal */ 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 103 wchar = 0; 104 iBuf += 2; /* get past "\x" */ 105 if (index(HEX, (CHAR) toupper(pszBuf[iBuf])) != -1) { 106 iBufSave = iBuf; 107 while (((wpos = index(HEX, (CHAR) toupper(pszBuf[iBuf]))) != -1) && 108 iBuf < iBufSave + 2) { 109 wchar = (CHAR) (wchar << 4) + (CHAR) wpos; 110 iBuf++; 111 } 112 } 113 else 114 wchar = 'x'; /* just an x */ 115 iBuf--; 116 *pszOut++ = wchar; 117 break; 117 118 118 119 case '\\': /* we want a "\" */ 119 120 121 120 iBuf++; 121 *pszOut++ = '\\'; 122 break; 122 123 123 124 case 't': /* tab CHAR */ 124 125 126 125 iBuf++; 126 *pszOut++ = '\t'; 127 break; 127 128 128 129 case 'n': /* new line */ 129 130 131 130 iBuf++; 131 *pszOut++ = '\n'; 132 break; 132 133 133 134 case 'r': /* carr return */ 134 135 136 135 iBuf++; 136 *pszOut++ = '\r'; 137 break; 137 138 138 139 case 'b': /* back space */ 139 140 141 140 iBuf++; 141 *pszOut++ = '\b'; 142 break; 142 143 143 144 case 'f': /* formfeed */ 144 145 146 145 iBuf++; 146 *pszOut++ = '\x0c'; 147 break; 147 148 148 149 case 'a': /* bell */ 149 150 151 150 iBuf++; 151 *pszOut++ = '\07'; 152 break; 152 153 153 154 case '\'': /* single quote */ 154 155 156 155 iBuf++; 156 *pszOut++ = '\''; 157 break; 157 158 158 159 case '\"': /* double quote */ 159 160 160 161 162 161 iBuf++; 162 *pszOut++ = '\"'; 163 break; 163 164 164 165 default: /* decimal */ 165 166 167 168 169 170 171 172 173 174 175 176 177 166 iBuf++; /* get past "\" */ 167 wchar = 0; 168 if (index(DEC, pszBuf[iBuf]) != -1) { 169 iBufSave = iBuf; 170 do { /* cvt to binary */ 171 wchar = (CHAR) (wchar * 10 + (pszBuf[iBuf++] - 48)); 172 } while (index(DEC, pszBuf[iBuf]) != -1 && iBuf < iBufSave + 3); 173 iBuf--; 174 } 175 else 176 wchar = pszBuf[iBuf]; 177 *pszOut++ = wchar; 178 break; 178 179 } // switch 179 180 break; … … 202 203 203 204 BOOL wildcard(const PSZ pszBuf, const PSZ pszWildCard, 204 205 const BOOL fNotFileSpec) 205 206 { 206 207 const CHAR *fstr = pszBuf; … … 215 216 tcard[strlen(tcard) - 1] = 0; 216 217 if (!(strchr(tcard, '?')) && !(strchr(tcard, '*'))){ 217 218 219 220 221 222 223 224 218 if (strstr(fstr, tcard)){ //strstr match for *stuff* pattern no wildcards in "stuff" 219 xfree(tcard); 220 return TRUE; 221 } 222 else{ 223 xfree(tcard); 224 return FALSE; 225 } 225 226 } 226 227 xfree(tcard); … … 228 229 else //reverse search for *stuff pattern "stuff" can contain wildcards 229 230 if (*fcard == '*' && fcard[strlen(fcard) - 1] != '*'){ 230 231 232 231 fstr = strrev(pszBuf); 232 fcard = strrev(pszWildCard); 233 reverse = TRUE; 233 234 } 234 235 switch (*fcard) { //fm2 standard forward search for all other cases 235 236 case '?': /* character substitution */ 236 237 238 239 237 fcard++; 238 if (fNotFileSpec || (*fstr != '.' && *fstr != '/' && *fstr != '\\')) 239 fstr++; /* skip (match) next character */ 240 break; 240 241 241 242 case '*': 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 243 /* find next non-wild character in wildcard */ 244 while (*fcard && (*fcard == '?' || *fcard == '*')) 245 fcard++; 246 if (!*fcard){ /* if last char of wildcard is *, it matches */ 247 if (reverse){ 248 fstr = strrev(pszBuf); 249 fcard = strrev(pszWildCard); 250 } 251 return TRUE; 252 } 253 /* skip until partition, match, or eos */ 254 while (*fstr && toupper(*fstr) != toupper(*fcard) && 255 (fNotFileSpec || (*fstr != '\\' && 256 *fstr != '/' && *fstr != '.'))) 257 fstr++; 258 if (!fNotFileSpec && !*fstr) /* implicit '.' */ 259 if (*fcard == '.') 260 fcard++; 261 break; 261 262 262 263 default: 263 264 265 266 267 268 269 270 264 if (!fNotFileSpec && ((*fstr == '/' || *fstr == '\\') && 265 (*fcard == '/' || *fcard == '\\'))) 266 wmatch = TRUE; 267 else 268 wmatch = (toupper(*fstr) == toupper(*fcard)); 269 fstr++; 270 fcard++; 271 break; 271 272 } 272 273 } //while … … 292 293 293 294 PSZ fixup(const PCH pachIn, PSZ pszOutBuf, const UINT cBufBytes, 294 295 const UINT cInBytes) 295 296 { 296 297 PCH pchIn = pachIn; 297 298 PCH pchOut = pszOutBuf; 298 PSZ pszTemp;299 static CHAR szTemp[5] = "\\x"; // Constant prefix300 299 301 300 // input is a character array, not a string - may not be null terminated 302 301 // cBufBytes is buffer size 303 302 if (pachIn) { 303 // 16 Nov 07 SHL fixme to optimize counting and speed 304 304 // Ensure room for null and possible \ escape 305 while (pchIn - pachIn < cInBytes && pchOut - pszOutBuf + 2 < cBufBytes) { 305 while (pchIn - pachIn < cInBytes) { 306 if (pchOut - pszOutBuf + 4 >= cBufBytes) { 307 *pchOut = 0; 308 Runtime_Error(pszSrcFile, __LINE__, "buffer too small for %s", pszOutBuf); 309 break; 310 } 311 306 312 if (!isprint(*pchIn)) { 307 if (*pchIn == '\r') { 308 *pchOut++ = '\\'; 309 *pchOut++ = 'r'; 310 } 311 else if (*pchIn == '\n') { 312 *pchOut++ = '\\'; 313 *pchOut++ = 'n'; 314 } 315 else if (*pchIn == '\b') { 316 *pchOut++ = '\\'; 317 *pchOut++ = 'b'; 318 } 319 else { 320 sprintf(szTemp + 2, "%02x", (UCHAR)*pchIn); 321 for (pszTemp = szTemp; *pszTemp;) 322 *pchOut++ = *pszTemp++; 323 } 324 pchIn++; 313 if (*pchIn == '\r') { 314 *pchOut++ = '\\'; 315 *pchOut++ = 'r'; 316 } 317 else if (*pchIn == '\n') { 318 *pchOut++ = '\\'; 319 *pchOut++ = 'n'; 320 } 321 else if (*pchIn == '\b') { 322 *pchOut++ = '\\'; 323 *pchOut++ = 'b'; 324 } 325 else { 326 sprintf(pchOut, "\\x%02x", (UCHAR)*pchIn); 327 pchOut += 4; 328 } 329 pchIn++; 325 330 } 326 331 else if (*pchIn == '\\') { 327 328 329 332 *pchOut++ = '\\'; 333 *pchOut++ = '\\'; 334 pchIn++; 330 335 } 331 336 else 332 *pchOut++ = *pchIn++; 333 } // while 334 } // if pachIn 337 *pchOut++ = *pchIn++; 338 } // while 339 340 } // if pachIn 335 341 *pchOut = 0; 336 342 return pszOutBuf;
Note:
See TracChangeset
for help on using the changeset viewer.