SaneWinMain( argc, argv ) { FILE *input; if( argc > 2 ) { input = sack_fopen( 0, argv[2], WIDE("rb+") ); if( input ) { if( StrCaseCmpEx( argv[1], WIDE( "u" ), 1 ) == 0 ) { read_ascii( input ); ascii_to_unicode(); write_unicode( input ); } else { read_unicode( input ); unicode_to_ascii(); write_ascii( input ); } fclose( input ); } else printf( WIDE( "Failed to open %s" ), argv[2] ); } else { printf( WIDE("Usage: %s [u/a] [filename]\n"), argv[0] ); printf( WIDE(" u or a is unicode or ascii mode; unicode translates from ascii to unicode\n") ); printf( WIDE(" ascii translates from unicode to ascii\n") ); printf( WIDE(" file will be written back in-place\n") ); } return 0; }
//------------------------------------------------------------------------------------------------------------------- wchar_t* bytebuffer::readASTRINGtoUNICODE() { unsigned short size = readSHORT(); char* tempArray = new char[size]; readDATA(tempArray,size); wchar_t* ret = (wchar_t*)createArray(size * 2 +2); ascii_to_unicode(ret,tempArray,size); delete [] tempArray; ret[size] = 0; return ret; }
//------------------------------------------------------------------------------------------------------------------- void bytebuffer::writeUSTRING(const char* string) { unsigned int size; for(size = 0;string[size] != '\0';size++) ; wchar_t* new_string = new wchar_t[size]; ascii_to_unicode(new_string,string,size); writeINT(size); writeDATA((char*)new_string,size *2); delete [] new_string; }
/*This static functions are copies from ZLib miniunz.c with some changes.*/ static std::wstring codepage_issue_fixFromOEM( const char* sVal) { #if defined(_WIN32) || defined (_WIN64) int nBufferSize = MultiByteToWideChar( CP_OEMCP, 0, sVal, -1, NULL, 0 ); wchar_t* pBuffer = new wchar_t[nBufferSize]; MultiByteToWideChar( CP_OEMCP, 0, sVal, -1, pBuffer, nBufferSize ); //If this parameter is -1, the function processes the entire input string, including the terminating null character. //Therefore, the resulting Unicode string has a terminating null character, and the length returned by the function includes this character. std::wstring sRes(pBuffer, nBufferSize - 1); RELEASEARRAYOBJECTS(pBuffer); return sRes; #else return ascii_to_unicode(sVal); #endif }