void UnescapeHex(const STRING& str, size_t& i, STRING& Ret, BOOL Unicode) { STRING Num; // hexadecimal if (iswxdigit(str[i])) { Num += str[i]; ++i; if (iswxdigit(str[i])) { Num += str[i]; ++i; if (Unicode) { if (iswxdigit(str[i])) { Num += str[i]; ++i; if (iswxdigit(str[i])) { Num += str[i]; ++i; } } } } } if (!Num.empty()) { Ret += (WCHAR)wcstoul(&Num[0], NULL, 16); } }
int __cdecl main(int argc, char **argv) { int i; WCHAR c; int ret; if (PAL_Initialize(argc, argv)) { return FAIL; } for (i=0; i<=0xFFFF; i++) { ret = iswxdigit(i); c = (WCHAR) i; if (ret) { if (wcschr(ValidHexDigits, c) == NULL) { /* iswxdigit says its a hex digit. We know better */ Fail("iswxdigit incorrectly found %#x to be a hex digit!\n", c); } } else if (wcschr(ValidHexDigits, c) != NULL && c != 0) { /* iswxdigit says it isn't a hex digit. We know better */ Fail("iswxdigit failed to find %#x to be a hex digit!\n", c); } } PAL_Terminate(); return PASS; }
int get_trait (qse_wcint_t code) { int trait = 0; if (iswupper(code)) trait |= TRAIT_UPPER; if (iswlower(code)) trait |= TRAIT_LOWER; if (iswalpha(code)) trait |= TRAIT_ALPHA; if (iswdigit(code)) trait |= TRAIT_DIGIT; if (iswxdigit(code)) trait |= TRAIT_XDIGIT; if (iswalnum(code)) trait |= TRAIT_ALNUM; if (iswspace(code)) trait |= TRAIT_SPACE; if (iswprint(code)) trait |= TRAIT_PRINT; if (iswgraph(code)) trait |= TRAIT_GRAPH; if (iswcntrl(code)) trait |= TRAIT_CNTRL; if (iswpunct(code)) trait |= TRAIT_PUNCT; if (iswblank(code)) trait |= TRAIT_BLANK; /* if (iswascii(code)) trait |= TRAIT_ASCII; if (isphonogram(code)) trait |= TRAIT_PHONO; if (isideogram(code)) trait |= TRAIT_IDEOG; if (isenglish(code)) trait |= TRAIT_ENGLI; */ return trait; }
void File::ParseNumber(InputStream& s, Definition* pDef) { CStringW v, u; for(int c = s.SkipWhiteSpace(); iswxdigit(c) || wcschr(L"+-.x:", c); c = s.PeekChar()) { if((c == '+' || c == '-') && !v.IsEmpty() || (c == '.' && (v.IsEmpty() || v.Find('.') >= 0 || v.Find('x') >= 0)) || (c == 'x' && v != '0') || (c >= 'a' && c <= 'f' || c >= 'A' && c <= 'F') && v.Find(L"0x") != 0 || (c == ':' && v.IsEmpty())) { s.ThrowError(_T("unexpected character '%c' in number"), (TCHAR)c); } v += (WCHAR)s.GetChar(); } if(v.IsEmpty()) s.ThrowError(_T("invalid number")); for(int c = s.SkipWhiteSpace(); iswcsym(c); c = s.PeekChar()) { u += (WCHAR)s.GetChar(); } pDef->SetAsNumber(v, u); }
int iswctype(wint_t wc, wctype_t type) { switch (type) { case WCTYPE_ALNUM: return iswalnum(wc); case WCTYPE_ALPHA: return iswalpha(wc); case WCTYPE_BLANK: return iswblank(wc); case WCTYPE_CNTRL: return iswcntrl(wc); case WCTYPE_DIGIT: return iswdigit(wc); case WCTYPE_GRAPH: return iswgraph(wc); case WCTYPE_LOWER: return iswlower(wc); case WCTYPE_PRINT: return iswprint(wc); case WCTYPE_PUNCT: return iswpunct(wc); case WCTYPE_SPACE: return iswspace(wc); case WCTYPE_UPPER: return iswupper(wc); case WCTYPE_XDIGIT: return iswxdigit(wc); } return 0; }
int BLC_PREFIX(iswctype)(wint_t wc, wctype_t desc) { switch (desc) { case wctype_alnum: return iswalnum(wc); case wctype_alpha: return iswalpha(wc); case wctype_blank: return iswblank(wc); case wctype_cntrl: return iswcntrl(wc); case wctype_digit: return iswdigit(wc); case wctype_graph: return iswgraph(wc); case wctype_lower: return iswlower(wc); case wctype_print: return iswprint(wc); case wctype_punct: return iswpunct(wc); case wctype_space: return iswspace(wc); case wctype_upper: return iswupper(wc); case wctype_xdigit: return iswxdigit(wc); default: return 0; } }
void test1() { int i; for (i = 0; i < 256; i++) { printf(" %02x: ", i); check_bool(isalnum(i), iswalnum(i), '1'); check_bool(isalpha(i), iswalpha(i), '2'); check_bool(isblank(i), iswblank(i), '3'); check_bool(iscntrl(i), iswcntrl(i), '4'); check_bool(isdigit(i), iswdigit(i), '5'); check_bool(isgraph(i), iswgraph(i), '6'); check_bool(islower(i), iswlower(i), '6'); check_bool(isprint(i), iswprint(i), '7'); check_bool(ispunct(i), iswpunct(i), '8'); check_bool(isspace(i), iswspace(i), '9'); check_bool(isupper(i), iswupper(i), 'a'); check_bool(isxdigit(i), iswxdigit(i), 'b'); check_value(tolower(i), towlower(i), 'c'); check_value(toupper(i), towupper(i), 'd'); if (i % 8 == 7) printf("\n"); } printf("%\n"); }
//***************************************************************************** inline BYTE getXdigit(const WCHAR xc) //Returns: hex char converted into byte value { ASSERT(iswxdigit(xc)); if (iswdigit(xc)) return WCv(xc) - '0'; return 10 + (WCv(towlower(xc)) - 'a'); }
bool is_hex_digit(char_t c) { #ifdef _UTF16_STRINGS return iswxdigit(c) != 0; #else return isxdigit(c) != 0; #endif }
int main () { /* Check that the isw* functions exist as functions or as macros. */ (void) iswalnum (0); (void) iswalpha (0); #if 0 /* not portable: missing on mingw */ (void) iswblank (0); #endif (void) iswcntrl (0); (void) iswdigit (0); (void) iswgraph (0); (void) iswlower (0); (void) iswprint (0); (void) iswpunct (0); (void) iswspace (0); (void) iswupper (0); (void) iswxdigit (0); /* Check that the isw* functions map WEOF to 0. */ ASSERT (!iswalnum (e)); ASSERT (!iswalpha (e)); #if 0 /* not portable: missing on mingw */ ASSERT (!iswblank (e)); #endif ASSERT (!iswcntrl (e)); ASSERT (!iswdigit (e)); ASSERT (!iswgraph (e)); ASSERT (!iswlower (e)); ASSERT (!iswprint (e)); ASSERT (!iswpunct (e)); ASSERT (!iswspace (e)); ASSERT (!iswupper (e)); ASSERT (!iswxdigit (e)); /* Check that the tow* functions exist as functions or as macros. */ (void) towlower (0); (void) towupper (0); /* Check that the tow* functions map WEOF to WEOF. */ ASSERT (towlower (e) == e); ASSERT (towupper (e) == e); return 0; }
/* Decode a string of hex characters into the bytes they represent. The second * parameter specifies the length of the output buffer. The number of bytes * actually written to the output buffer is returned. */ size_t decodeHexWChars(unsigned char * bytes, size_t numBytes, const wchar_t * hex) { size_t numWritten = 0; /* We can't swscanf directly into the byte array since %02x expects a pointer to int, * not a pointer to unsigned char. Also, since we expect an unbroken string of hex * characters, we check for that before calling swscanf; otherwise we would get a * framing error if there's whitespace in the input string. */ while (numWritten < numBytes && iswxdigit(hex[2 * numWritten]) && iswxdigit(hex[2 * numWritten + 1])) { int byte; swscanf(&hex[2 * numWritten], L"%02x", &byte); bytes[numWritten] = (unsigned char) byte; ++numWritten; } return numWritten; }
LONG GetXNum() { LONG n = 0; while (iswxdigit (GetCharFTB())) n = n * 16 + ( ((curCharFTB = (WCHAR)towupper(curCharFTB)) >= L'A') ? (WCHAR)(curCharFTB - L'A' + 10) : (WCHAR)(curCharFTB - L'0')); return (n); }
INT GetBA(WCHAR **pp, BT_ADDR *pba) { while(**pp == ' ') ++*pp; int i; for( i = 0 ; i < 4 ; ++i, ++*pp) { if(! iswxdigit (**pp)) return FALSE; int c = **pp; if (c >= 'a') c = c - 'a' + 0xa; else if(c >= 'A') c = c - 'A' + 0xa; else c = c - '0'; if((c < 0) || (c > 16)) return FALSE; *pba = *pba * 16 + c; } for (i = 0 ; i < 8 ; ++i, ++*pp) { if(! iswxdigit (**pp)) return FALSE; int c = **pp; if(c >= 'a') c = c - 'a' + 0xa; else if(c >= 'A') c = c - 'A' + 0xa; else c = c - '0'; if((c < 0) || (c > 16)) return FALSE; *pba = *pba * 16 + c; } if((**pp != ' ') && (**pp != '\0')) return FALSE; return TRUE; }
bool iswxdigit(wstring _String) { for (wstring::const_iterator iter = _String.begin(); iter != _String.end(); iter++) { if (!iswxdigit(*iter)) { return false; } } return true; }
int main (void) { /* Check that the isw* functions exist as functions or as macros. */ (void) iswalnum (0); (void) iswalpha (0); (void) iswcntrl (0); (void) iswdigit (0); (void) iswgraph (0); (void) iswlower (0); (void) iswprint (0); (void) iswpunct (0); (void) iswspace (0); (void) iswupper (0); (void) iswxdigit (0); /* Check that the isw* functions map WEOF to 0. */ ASSERT (!iswalnum (e)); ASSERT (!iswalpha (e)); ASSERT (!iswcntrl (e)); ASSERT (!iswdigit (e)); ASSERT (!iswgraph (e)); ASSERT (!iswlower (e)); ASSERT (!iswprint (e)); ASSERT (!iswpunct (e)); ASSERT (!iswspace (e)); ASSERT (!iswupper (e)); ASSERT (!iswxdigit (e)); /* Check that the tow* functions exist as functions or as macros. */ (void) towlower (0); (void) towupper (0); /* Check that the tow* functions map WEOF to WEOF. */ ASSERT (towlower (e) == e); ASSERT (towupper (e) == e); return 0; }
unsigned long long wcstoull(const wchar_t *nptr,wchar_t **endptr,int base) { const wchar_t *p=nptr,*q; wchar_t c=0; unsigned long long r=0; if(base<0||base==1||base>36) { if(endptr!=NULL) *endptr=(wchar_t *)nptr; return 0; } while(iswspace(*p)) p++; if(*p==L'-'||*p==L'+') c=*p++; if(base==0) { if(p[0]==L'0') { if(towlower(p[1])=='x'&&iswxdigit(p[2])) { p+=2; base=16; } else base=8; }else base=10; } q=p; for(;;) { int a; int dig = *q; if(!iswalnum(dig)) break; a=(dig>=L'0'&&dig<=L'9')?*q-L'0':towlower(*q)-(L'a'-10); if(a>=base) break; if(r>(ULLONG_MAX-a)/base||r*base>ULLONG_MAX-a) { errno=ERANGE; /* overflow */ r=ULLONG_MAX; } else r=r*base+a; q++; } if(q==p) /* Not a single number read */ { if(endptr!=NULL) *endptr=(wchar_t *)nptr; return 0; } if(c==L'-') r=-r; if(endptr!=NULL) *endptr=(wchar_t *)q; return r; }
VOID StrToNameOrd( LPTSTR pszNameOrd, BOOL fDecOnly) { register INT i; INT nOrd; INT nLen; /* * Empty string? */ if (!(*pszNameOrd)) return; nLen = lstrlen(pszNameOrd); /* * Is a hex value ok and does this appear to be a hex value? */ if (!fDecOnly && pszNameOrd[0] == CHAR_0 && (pszNameOrd[1] == CHAR_X || pszNameOrd[1] == CHAR_CAP_X)) { for (i = 2; i < nLen; i++) { if (!iswxdigit(pszNameOrd[i])) return; } nOrd = axtoi(&pszNameOrd[2]); } else { /* * All characters must be numeric. Negative numbers may * or may not be allowed, based on the fDecOnly flag. */ for (i = 0; i < nLen; i++) { if (!iswdigit(pszNameOrd[i]) && (fDecOnly || i != 0 || pszNameOrd[0] != CHAR_MINUS)) return; } nOrd = awtoi(pszNameOrd); } /* * Return the ordinal in the original buffer. */ WriteOrd((PORDINAL)pszNameOrd, nOrd); }
/* For reading in resource names and types. */ int GetNameOrd() { PWCHAR pch; int fString; /* get space delimited string */ if (!GetGenText()) return FALSE; /* convert to upper case */ _wcsupr(tokenbuf); /* is it a string or number */ for (pch=tokenbuf,fString=0 ; *pch ; pch++ ) if (!iswdigit(*pch)) fString = 1; /* determine if ordinal */ if (tokenbuf[0] == L'0' && tokenbuf[1] == L'X') { int HexNum; int inc; USHORT wCount; PWCHAR s; HexNum = 0; s = &tokenbuf[2]; for (wCount = 4 ; wCount && iswxdigit(*s) ; --wCount) { if (*s >= L'A') inc = *s - L'A' + 10; else inc = *s - L'0'; HexNum = HexNum * 16 + inc; s++; } token.val = (USHORT)HexNum; } else if (fString) { token.val = 0; } else { token.val = (USHORT)wcsatoi(tokenbuf); } return TRUE; }
static int match_class (lua_WChar c, lua_WChar cl) { int res; switch (towlower(cl)) { case 'a' : res = iswalpha(c); break; case 'c' : res = iswcntrl(c); break; case 'd' : res = iswdigit(c); break; case 'l' : res = iswlower(c); break; case 'p' : res = iswpunct(c); break; case 's' : res = iswspace(c); break; case 'u' : res = iswupper(c); break; case 'w' : res = iswalnum(c); break; case 'x' : res = iswxdigit(c); break; case 'z' : res = (c == '\0'); break; default: return (cl == c); } return (iswlower(cl) ? res : !res); }
BOOL IsValue( LPTSTR pszValue) { INT i; if (pszValue[0] == CHAR_0 && (pszValue[1] == CHAR_X || pszValue[1] == CHAR_CAP_X)) { for (i = 2; iswxdigit(pszValue[i]); i++) ; } else { for (i = 0; iswdigit(pszValue[i]) || (i == 0 && pszValue[i] == CHAR_MINUS); i++) ; } return (pszValue[i] == 0); }
/* Determine if the given character is of the specified type. */ _WCRTLINK int iswctype( wint_t wc, wctype_t desc ) { switch( desc ) { case WCTYPE_ALNUM: return( iswalnum( wc ) ); case WCTYPE_ALPHA: return( iswalpha( wc ) ); case WCTYPE_BLANK: return( iswblank( wc ) ); case WCTYPE_CNTRL: return( iswcntrl( wc ) ); case WCTYPE_DIGIT: return( iswdigit( wc ) ); case WCTYPE_GRAPH: return( iswgraph( wc ) ); case WCTYPE_LOWER: return( iswlower( wc ) ); case WCTYPE_PRINT: return( iswprint( wc ) ); case WCTYPE_PUNCT: return( iswpunct( wc ) ); case WCTYPE_SPACE: return( iswspace( wc ) ); case WCTYPE_UPPER: return( iswupper( wc ) ); case WCTYPE_XDIGIT: return( iswxdigit( wc ) ); default: return( 0 ); } }
Uint32 CHTMLWidget::TranslateColor( //Returns: SDL numeric color value // //Params: SDL_Surface *pSurface, //(in) const WSTRING& wstr) //string of hex RGB values (i.e. "ffffff") const { //Skip '#', or any other non-hex chars at front of string UINT wIndex = 0; while (!iswxdigit(wstr[wIndex])) ++wIndex; //Convert hex chars to byte values. ASSERT(wstr.size() - wIndex == 6); const BYTE nR = getXdigit(wstr[wIndex]) * 16 + getXdigit(wstr[wIndex+1]); const BYTE nG = getXdigit(wstr[wIndex+2]) * 16 + getXdigit(wstr[wIndex+3]); const BYTE nB = getXdigit(wstr[wIndex+4]) * 16 + getXdigit(wstr[wIndex+5]); return SDL_MapRGB(pSurface->format, nR, nG, nB); }
int main () { /* Check that the isw* functions exist as functions or as macros. */ iswalnum (0); iswalpha (0); #if 0 /* not portable: missing on mingw */ iswblank (0); #endif iswcntrl (0); iswdigit (0); iswgraph (0); iswlower (0); iswprint (0); iswpunct (0); iswspace (0); iswupper (0); iswxdigit (0); return 0; }
void wctype_check_functions(wint_t i, wctype_t t, wctrans_t tr, locale_t l) { (void)iswalnum(i); (void)iswalnum_l(i, l); (void)iswalpha(i); (void)iswalpha_l(i, l); (void)iswblank(i); (void)iswblank_l(i, l); (void)iswcntrl(i); (void)iswcntrl_l(i, l); (void)iswctype(i, t); (void)iswctype_l(i, t, l); (void)iswdigit(i); (void)iswdigit_l(i, l); (void)iswgraph(i); (void)iswgraph_l(i, l); (void)iswlower(i); (void)iswlower_l(i, l); (void)iswprint(i); (void)iswprint_l(i, l); (void)iswpunct(i); (void)iswpunct_l(i, l); (void)iswspace(i); (void)iswspace_l(i, l); (void)iswupper(i); (void)iswupper_l(i, l); (void)iswxdigit(i); (void)iswxdigit_l(i, l); (void)towctrans(i, tr); (void)towctrans_l(i, tr, l); (void)towlower(i); (void)towlower_l(i, l); (void)towupper(i); (void)towupper_l(i, l); (void)wctrans((const char *)1234); (void)wctrans_l((const char *)1234, l); (void)wctype((const char *)1234); (void)wctype_l((const char *)1234, l); }
static TypeString checkTypeString(const wchar_t *TestStr) { TypeString typeTestStr=tsStr; if (TestStr && *TestStr) { const wchar_t *ptrTestStr=TestStr; wchar_t ch, ch2; bool isNum = true; // bool isDec = false; bool isBegDec = false; // bool isHex = false; bool isBegHex = false; // bool isOct = false; bool isBegOct = false; // bool isE = false; bool isExp = false; bool isPoint = false; bool isSign = false; bool isExpSign = false; if (*ptrTestStr == L'-' || *ptrTestStr == L'+') { isSign=true; ptrTestStr++; } if (*ptrTestStr == L'.' && iswdigit(ptrTestStr[1])) { isPoint=true; ptrTestStr++; } if (*ptrTestStr >= L'1' && *ptrTestStr <=L'9') isBegDec=true; else if (*ptrTestStr == L'0') { if ((ptrTestStr[1] == L'x' || ptrTestStr[1] == L'X') && iswxdigit(ptrTestStr[2])) { isBegHex=true; ptrTestStr+=2; } else { if (iswdigit(ptrTestStr[1]) || ptrTestStr[1] == L'.') isBegDec=true; else if (!ptrTestStr[1]) return tsInt; else isBegOct=true; } } while ((ch=*ptrTestStr++) ) { switch (ch) { case L'-': case L'+': if (ptrTestStr == TestStr+1) isSign=true; else if (isSign) { isNum=false; break; } if (isExp) { if (isExpSign) { isNum=false; break; } isExpSign=true; } break; case L'.': if (isPoint) { isNum=false; break; } isPoint=true; if (!(iswdigit(ptrTestStr[1]) || ptrTestStr[1] == L'e' || ptrTestStr[1] == L'E' || !ptrTestStr[1])) { isNum=false; break; } break; case L'e': case L'E': //isHex=true; //isE=true; ch2=*ptrTestStr++; if (ch2 == L'-' || ch2 == L'+') // E+D { if (isBegHex || isExpSign) // начало hex или уже был знак у порядка? { isNum=false; break; } isExpSign=true; wchar_t ch3=*ptrTestStr++; if (!iswdigit(ch3)) // за знаком идет число? { isNum=false; break; } else { isExp=true; } } else if (!iswdigit(ch2)) // ED { if (isBegDec) { isNum=false; break; } ptrTestStr--; } else { isExp=true; ptrTestStr--; } break; case L'a': case L'A': case L'b': case L'B': case L'c': case L'C': case L'd': case L'D': case L'f': case L'F': if (isBegDec || isExp) { isNum=false; break; } //isHex=true; break; case L'0': case L'1': case L'2': case L'3': case L'4': case L'5': case L'6': case L'7': //isOct=true; case L'8': case L'9': if (isBegOct && (ch == L'8' || ch == L'9')) { isNum=false; break; } //isDec=true; break; default: isNum=false; } if (!isNum) break; } if (isNum) { if (isBegDec && (isExp || isPoint)) typeTestStr=tsFloat; if ((isBegDec || isBegHex || isBegOct) && !(isExp || isPoint)) typeTestStr=tsInt; } } return typeTestStr; }
//int _tmain( int argc, TCHAR* argv[] ) int main( void ) { STARTUPINFO si; PROCESS_INFORMATION pi; TCHAR* cmd; BOOL option; BOOL opt_m; BOOL installed; HMODULE ansi; int rc = 0; int argc; LPWSTR* argv = CommandLineToArgvW( GetCommandLine(), &argc ); if (argc > 1) { if (lstrcmp( argv[1], L"--help" ) == 0 || (argv[1][0] == '-' && (argv[1][1] == '?' || argv[1][1] == 'h')) || (argv[1][0] == '/' && argv[1][1] == '?')) { help(); return rc; } if (lstrcmp( argv[1], L"--version" ) == 0) { _putws( L"ANSICON (" BITS L"-bit) version " PVERS L" (" PDATE L")." ); return rc; } } #if (MYDEBUG > 1) DEBUGSTR( NULL ); // create a new file #endif option = (argc > 1 && argv[1][0] == '-'); if (option && (towlower( argv[1][1] ) == 'i' || towlower( argv[1][1] ) == 'u')) { process_autorun( argv[1][1] ); argv[1][1] = 'p'; } get_original_attr(); opt_m = FALSE; if (option && argv[1][1] == 'm') { WORD attr = 7; if (iswxdigit( argv[1][2] )) { attr = iswdigit( argv[1][2] ) ? argv[1][2] - '0' : (argv[1][2] | 0x20) - 'a' + 10; if (iswxdigit( argv[1][3])) { attr <<= 4; attr |= iswdigit( argv[1][3] ) ? argv[1][3] - '0' : (argv[1][3] | 0x20) - 'a' + 10; } } SetConsoleTextAttribute( hConOut, attr ); opt_m = TRUE; ++argv; --argc; option = (argc > 1 && argv[1][0] == '-'); } installed = (GetEnvironmentVariable( L"ANSICON", NULL, 0 ) != 0); if (option && argv[1][1] == 'p') { // If it's already installed, there's no need to do anything. if (installed) ; else if (GetParentProcessInfo( &pi )) { pi.hProcess = OpenProcess( PROCESS_ALL_ACCESS, FALSE, pi.dwProcessId ); pi.hThread = OpenThread( THREAD_ALL_ACCESS, FALSE, pi.dwThreadId ); SuspendThread( pi.hThread ); if (!Inject( &pi )) { _putws( L"ANSICON: parent process type is not supported." ); rc = 1; } ResumeThread( pi.hThread ); CloseHandle( pi.hThread ); CloseHandle( pi.hProcess ); } else { _putws( L"ANSICON: could not obtain the parent process." ); rc = 1; } } else { ansi = 0; if (!installed) { ansi = LoadLibrary( L"ANSI" BITS L".dll" ); if (!ansi) { fputws( L"ANSICON: failed to load ANSI" BITS L".dll.\n", stderr ); rc = 1; } } if (option && (argv[1][1] == 't' || argv[1][1] == 'T')) { BOOL title = (argv[1][1] == 'T'); if (argc == 2) { argv[2] = L"-"; ++argc; } for (; argc > 2; ++argv, --argc) { if (title) wprintf( L"==> %s <==\n", argv[2] ); display( argv[2], title ); if (title) putwchar( '\n' ); } } else { // Retrieve the original command line, skipping our name and the option. cmd = skip_spaces( skip_arg( skip_spaces( GetCommandLine() ) ) ); if (opt_m) cmd = skip_spaces( skip_arg( cmd ) ); if (cmd[0] == '-' && (cmd[1] == 'e' || cmd[1] == 'E')) { fputws( cmd + 3, stdout ); if (cmd[1] == 'e') putwchar( '\n' ); } else if (!_isatty( 0 ) && *cmd == '\0') { display( L"-", FALSE ); } else { if (*cmd == '\0') { cmd = _wgetenv( L"ComSpec" ); if (cmd == NULL) cmd = L"cmd"; } ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); if (CreateProcess( NULL, cmd, NULL,NULL, TRUE, 0, NULL,NULL, &si, &pi )) { BOOL console = FALSE; TCHAR name[MAX_PATH]; DWORD rc; CoInitialize( NULL ); do { // When I first tried doing this, it took a little while to // succeed. Testing again shows it works immediately - perhaps the // CoInitialize introduces enough of a delay. Still, play it safe // and keep trying. And if you're wondering why I do it at all, // ProcessType may detect GUI, even for a console process. That's // fine after injection (including -p), but not here. We *need* to // suspend our own execution whilst running the child, otherwise // bad things happen (besides which, I want to restore the original // attributes when the child exits). if (GetModuleFileNameEx( pi.hProcess, NULL, name, lenof(name) )) { DWORD_PTR info; info = SHGetFileInfo( name, 0, NULL, 0, SHGFI_EXETYPE ); if (info == 0x00004550) // console PE console = TRUE; DEBUGSTR( L"%s", name ); DEBUGSTR( L" %s (%p)", (console) ? L"Console" : L"Not console", info ); break; } Sleep( 10 ); } while (GetExitCodeProcess( pi.hProcess, &rc ) && rc == STILL_ACTIVE); CoUninitialize(); if (console) { SetConsoleCtrlHandler( (PHANDLER_ROUTINE)CtrlHandler, TRUE ); WaitForSingleObject( pi.hProcess, INFINITE ); } CloseHandle( pi.hProcess ); CloseHandle( pi.hThread ); } else { *skip_arg( cmd ) = '\0'; wprintf( L"ANSICON: '%s' could not be executed.\n", cmd ); rc = 1; } } } if (ansi) FreeLibrary( ansi ); } set_original_attr(); return rc; }
/* * Read a string or regular expression, terminated by ``endc'', * for lexical analyzer, processing escape sequences. * Return string length. */ static size_t lexescape(wint_t endc, int regx, int cmd_line_operand) { static char nlre[256]; static char nlstr[256]; static char eofre[256]; static char eofstr[256]; int first_time = 1; wint_t c; wchar_t *cp; int n, max; if (first_time == 1) { (void) strcpy(nlre, gettext("Newline in regular expression\n")); (void) strcpy(nlstr, gettext("Newline in string\n")); (void) strcpy(eofre, gettext("EOF in regular expression\n")); (void) strcpy(eofstr, gettext("EOF in string\n")); first_time = 0; } cp = linebuf; while ((c = lexgetc()) != endc) { if (c == '\n') awkerr(regx ? nlre : nlstr); if (c == '\\') { switch (c = lexgetc(), c) { case '\\': if (regx) *cp++ = '\\'; break; case '/': c = '/'; break; case 'n': c = '\n'; break; case 'b': c = '\b'; break; case 't': c = '\t'; break; case 'r': c = '\r'; break; case 'f': c = '\f'; break; case 'v': c = '\v'; break; case 'a': c = (char)0x07; break; case 'x': n = 0; while (iswxdigit(c = lexgetc())) { if (iswdigit(c)) c -= '0'; else if (iswupper(c)) c -= 'A'-10; else c -= 'a'-10; n = (n<<4) + c; } lexungetc(c); c = n; break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': #if 0 /* * Posix.2 draft 10 disallows the use of back-referencing - it explicitly * requires processing of the octal escapes both in strings and * regular expressions. The following code is disabled instead of * removed as back-referencing may be reintroduced in a future draft * of the standard. */ /* * For regular expressions, we disallow * \ooo to mean octal character, in favour * of back referencing. */ if (regx) { *cp++ = '\\'; break; } #endif max = 3; n = 0; do { n = (n<<3) + c-'0'; if ((c = lexgetc()) > '7' || c < '0') break; } while (--max); lexungetc(c); /* * an octal escape sequence must have at least * 2 digits after the backslash, otherwise * it gets passed straight thru for possible * use in backreferencing. */ if (max == 3) { *cp++ = '\\'; n += '0'; } c = n; break; case '\n': continue; default: if (c != endc || cmd_line_operand) { *cp++ = '\\'; if (c == endc) lexungetc(c); } } } if (c == WEOF) awkerr(regx ? eofre : eofstr); *cp++ = c; } *cp = '\0'; return (cp - linebuf); }
bool NWChar::IsXDigit(wchar_t c) { return iswxdigit(c); }
/* All Rights Reserved */ #ifndef _WCS_LONGLONG #pragma weak wcstol = _wcstol #endif #include "synonyms.h" #include <limits.h> #include <errno.h> #include <wchar.h> #define DIGIT(x) (iswdigit(x) ? (x) - L'0' : \ iswlower(x) ? (x) + 10 - L'a' : (x) + 10 - L'A') #define MBASE (L'z' - L'a' + 1 + 10) #ifdef _WCS_LONGLONG #define _WLONG_T long long #define _WLONG_MAX LLONG_MAX #define _WLONG_MIN LLONG_MIN #else /* _WCS_LONGLONG */ #define _WLONG_T long #define _WLONG_MAX LONG_MAX #define _WLONG_MIN LONG_MIN #endif /* _WCS_LONGLONG */ #ifdef _WCS_LONGLONG long long wcstoll(const wchar_t *_RESTRICT_KYWD str, wchar_t **_RESTRICT_KYWD ptr, int base) #else /* _WCS_LONGLONG */ long _wcstol(const wchar_t *str, wchar_t **ptr, int base) #endif /* _WCS_LONGLONG */ { _WLONG_T val; wchar_t c; int xx, neg = 0; _WLONG_T multmin, limit; if (ptr != NULL) *ptr = (wchar_t *)str; /* in case no number is formed */ if (base < 0 || base > MBASE) { errno = EINVAL; return (0); /* base is invalid -- should be a fatal error */ } if (!iswalnum(c = *str)) { while (iswspace(c)) { c = *++str; } switch (c) { case L'-': neg++; /*FALLTHRU*/ case L'+': c = *++str; } } if (base == 0) { if (c != L'0') base = 10; else if (str[1] == L'x' || str[1] == L'X') base = 16; else base = 8; } /* * for any base > 10, the digits incrementally following * 9 are assumed to be "abc...z" or "ABC...Z" */ if (!iswalnum(c) || (xx = DIGIT(c)) >= base) { errno = EINVAL; return (0); /* no number formed */ } if (base == 16 && c == L'0' && iswxdigit(str[2]) && (str[1] == L'x' || str[1] == L'X')) { c = *(str += 2); /* skip over leading "0x" or "0X" */ } if (neg) { limit = _WLONG_MIN; } else { limit = -_WLONG_MAX; } multmin = limit / base; val = -DIGIT(c); for (; iswalnum(c = *++str) && (xx = DIGIT(c)) < base; ) { /* accumulate neg avoids surprises near MAXLONG */ if (val < multmin) goto overflow; val *= base; if (val < limit + xx) goto overflow; val -= xx; } if (ptr != NULL) *ptr = (wchar_t *)str; return (neg ? val : -val); overflow: while (iswalnum(c = *++str) && (xx = DIGIT(c)) < base) ; if (ptr != NULL) *ptr = (wchar_t *)str; errno = ERANGE; return (neg ? _WLONG_MIN : _WLONG_MAX); }
/// Print a \ escape sequence starting at ESCSTART. /// Return the number of characters in the escape sequence besides the backslash.. /// If OCTAL_0 is nonzero, octal escapes are of the form \0ooo, where o /// is an octal digit; otherwise they are of the form \ooo. long builtin_printf_state_t::print_esc(const wchar_t *escstart, bool octal_0) { const wchar_t *p = escstart + 1; int esc_value = 0; /* Value of \nnn escape. */ int esc_length; /* Length of \nnn escape. */ if (*p == L'x') { // A hexadecimal \xhh escape sequence must have 1 or 2 hex. digits. for (esc_length = 0, ++p; esc_length < 2 && iswxdigit(*p); ++esc_length, ++p) esc_value = esc_value * 16 + hex_to_bin(*p); if (esc_length == 0) this->fatal_error(_(L"missing hexadecimal number in escape")); this->append_output(ENCODE_DIRECT_BASE + esc_value % 256); } else if (is_octal_digit(*p)) { // Parse \0ooo (if octal_0 && *p == L'0') or \ooo (otherwise). Allow \ooo if octal_0 && *p // != L'0'; this is an undocumented extension to POSIX that is compatible with Bash 2.05b. // Wrap mod 256, which matches historic behavior. for (esc_length = 0, p += octal_0 && *p == L'0'; esc_length < 3 && is_octal_digit(*p); ++esc_length, ++p) esc_value = esc_value * 8 + octal_to_bin(*p); this->append_output(ENCODE_DIRECT_BASE + esc_value % 256); } else if (*p && std::wcschr(L"\"\\abcefnrtv", *p)) { print_esc_char(*p++); } else if (*p == L'u' || *p == L'U') { wchar_t esc_char = *p; p++; uint32_t uni_value = 0; for (size_t esc_length = 0; esc_length < (esc_char == L'u' ? 4 : 8); esc_length++) { if (!iswxdigit(*p)) { // Escape sequence must be done. Complain if we didn't get anything. if (esc_length == 0) { this->fatal_error(_(L"Missing hexadecimal number in Unicode escape")); } break; } uni_value = uni_value * 16 + hex_to_bin(*p); p++; } // PCA GNU printf respects the limitations described in ISO N717, about which universal // characters "shall not" be specified. I believe this limitation is for the benefit of // compilers; I see no reason to impose it in builtin_printf. // // If __STDC_ISO_10646__ is defined, then it means wchar_t can and does hold Unicode code // points, so just use that. If not defined, use the %lc printf conversion; this probably // won't do anything good if your wide character set is not Unicode, but such platforms are // exceedingly rare. if (uni_value > 0x10FFFF) { this->fatal_error(_(L"Unicode character out of range: \\%c%0*x"), esc_char, (esc_char == L'u' ? 4 : 8), uni_value); } else { #if defined(__STDC_ISO_10646__) this->append_output(uni_value); #else this->append_format_output(L"%lc", uni_value); #endif } } else { this->append_output(L'\\'); if (*p) { this->append_output(*p); p++; } } return p - escstart - 1; }