void CConnectRemoteMachineWindow::loadHistory() { CString appPath = GetAppPath(); CString fullPath = appPath + L"\\histroycommands1.xml"; char fname[4096] = {0}; int len = WideCharToMultiByte(CP_ACP, 0, fullPath, fullPath.GetLength(), NULL, 0, NULL, NULL); WideCharToMultiByte(CP_ACP,0, fullPath, fullPath.GetLength(), fname, len, NULL, NULL); fname[len + 1] = '\0'; TiXmlDocument *pDocument = new TiXmlDocument(fname); if(pDocument == NULL || !pDocument->LoadFile(TIXML_ENCODING_UTF8)) return; TiXmlElement *rootElement = pDocument->RootElement(); TiXmlNode* node = rootElement->FirstChild(); if(node) { do { std::string c = node->FirstChild()->Value(); wchar_t* strCommand = char2wchar(c.c_str()); m_historyCommand.push_back(strCommand); free(strCommand); }while((node = node->NextSibling())); } pDocument->Clear(); delete pDocument; }
/* SAVE-FILE USING DIRECT MicroSoft OUTPUT ROUTINE */ std::string XGDI::saveFileMS( const std::string file_name, const std::string format ) { if ( ! isValid() ) {return( std::string("invalid on entry") ); } if ( NULL == im ) {return( std::string("no contents to output") ); } CLSID encoder; if ( ! getImageEncoderClsid( format, &encoder ) ) {return( std::string("output format invalid" ) ); } wchar_t *fname = char2wchar( file_name.c_str() ); if ( NULL == fname ) {return( std::string("failure at char2wchar") ); } stat = im->Save( fname, &encoder, NULL); // `RAW' GDIPLUS METHOD free( fname ); if( Gdiplus::Ok == stat ) {return( std::string("") ); } char mbuf[100]; sprintf( mbuf, "failure at Gdiplus::Save, stat=%d", (int) stat ); return( std::string(mbuf) ); }
TParser * TParserInit(char *str, int len) { TParser *prs = (TParser *) palloc0(sizeof(TParser)); prs->charmaxlen = pg_database_encoding_max_length(); prs->str = str; prs->lenstr = len; #ifdef TS_USE_WIDE /* * Use wide char code only when max encoding length > 1. */ if (prs->charmaxlen > 1) { prs->usewide = true; prs->wstr = (wchar_t *) palloc(sizeof(wchar_t) * (prs->lenstr+1)); prs->lenwstr = char2wchar(prs->wstr, prs->str, prs->lenstr); } else #endif prs->usewide = false; prs->state = newTParserPosition(NULL); prs->state->state = TPS_Base; return prs; }
void AppManagerPrivate::copyUtf8ArgsToMembers(const std::vector<std::string>& utf8Args) { // Copy command line args to local members that live throughout the lifetime of AppManager #if PY_MAJOR_VERSION >= 3 // Python 3 commandLineArgsWideOriginal.resize(utf8Args.size()); #endif commandLineArgsUtf8Original.resize(utf8Args.size()); nArgs = (int)utf8Args.size(); for (std::size_t i = 0; i < utf8Args.size(); ++i) { commandLineArgsUtf8Original[i] = strdup(utf8Args[i].c_str()); // Python 3 needs wchar_t arguments #if PY_MAJOR_VERSION >= 3 // Python 3 commandLineArgsWideOriginal[i] = char2wchar(utf8Args[i].c_str()); #endif } commandLineArgsUtf8 = commandLineArgsUtf8Original; #if PY_MAJOR_VERSION >= 3 // Python 3 commandLineArgsWide = commandLineArgsWideOriginal; #endif }
RETCODE SQL_API SQLExecDirect ( SQLHSTMT pStmt, SQLCHAR* pStmtText, SQLINTEGER pTextLength ) { __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "SQLExecDirect called, strlen is %d, pTextLength is %d", strlen ( ( char* ) pStmtText ), pTextLength ) ); unique_ptr<wchar_t[]> pStmtTextW ( char2wchar ( ( char* ) pStmtText ) ); return SQLExecDirectW ( pStmt, ( SQLWCHAR* ) pStmtTextW.get(), pTextLength ); }
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool XGDI::getImageEncoderClsid( const std::string format, CLSID *pClsid ) const { std::string mime_type = std::string( "image/" ) + format; wchar_t *mt = char2wchar( mime_type.c_str() ); if ( NULL == mt ) {return( false ); } bool match = getEncoderClsid( mt, pClsid ); free( mt ); return( match ); }
int _t_isprint(const char *ptr) { wchar_t character[2]; if (lc_ctype_is_c()) return isprint(TOUCHAR(ptr)); char2wchar(character, ptr, 1); return iswprint((wint_t) *character); }
int t_isprint(const char *ptr) { int clen = pg_mblen(ptr); wchar_t character[2]; if (clen == 1 || lc_ctype_is_c()) return isprint(TOUCHAR(ptr)); char2wchar(character, 2, ptr, clen); return iswprint((wint_t) character[0]); }
int t_isprint(const char *ptr) { int clen = pg_mblen(ptr); wchar_t character[2]; Oid collation = DEFAULT_COLLATION_OID; /* TODO */ pg_locale_t mylocale = 0; /* TODO */ if (clen == 1 || lc_ctype_is_c(collation)) return isprint(TOUCHAR(ptr)); char2wchar(character, 2, ptr, clen, mylocale); return iswprint((wint_t) character[0]); }
/** * The program entry point under Windows CE * * @param argc number of arguments including program name * @param argv program argumants including its name */ int _tmain(int argc, _TCHAR* argv[]) { wchar_t *wcstring; (void)argc; (void)argv; test_known_strings(); test_alignment(); wcstring = char2wchar(g_msg ? g_msg : "Success!\r\nAll sums are working properly."); MessageBox(NULL, wcstring, _T("caption"), MB_OK|MB_ICONEXCLAMATION); free(wcstring); return (n_errors == 0 ? 0 : 1); }
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool XGDI::insertFileMS( const std::string file_name ) { FILE *ftest = fopen( file_name.c_str(), "rb" ); if ( NULL == ftest ) {setInvalid( "failed to open file" ); return( false ); } fclose( ftest ); wchar_t *fname = char2wchar( file_name.c_str() ); if ( NULL == fname ) {setInvalid( "failure at char2wchar" ); return( false ); } im = new Gdiplus::Image( fname ); // stat = im->GetLastError(); free( fname ); return( true ); }
RETCODE SQL_API SQLGetDiagRecW ( SQLSMALLINT pHandleType, SQLHANDLE pHandle, SQLSMALLINT pRecNum, SQLWCHAR* pSqlstate, SQLINTEGER* pNativeErrorPtr, SQLWCHAR* pMsgTxtPtr, SQLSMALLINT pMsgTxtSize, SQLSMALLINT* pMsgTxtSizePtr ) { __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "SQLGetDiagRecW called, HandleType: %d, RecNum: %d, BufLen: %d", pHandleType, pRecNum, pMsgTxtSize ) ); pODBCDiag diag; pODBCDiagRow diagrow; __CHK_HANDLE ( pHandle, pHandleType, SQL_ERROR ); diag = _SQLGetDiagHandle ( pHandleType, pHandle ); if ( !diag ) { return SQL_ERROR; } // now get the desired diag row if ( ( diagrow = _SQLGetDiagRowX ( diag, pRecNum ) ) == NULL ) { __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "sql no data" ) ); return SQL_NO_DATA; } // sql-state if ( pSqlstate ) { char2wchar ( diagrow->State, pSqlstate, -1 ); } // native error code if ( pNativeErrorPtr ) { ( *pNativeErrorPtr ) = diagrow->NativeErrorCode; } // msg __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "The message is %s", diagrow->Msg ) ); _SQLCopyWCharData ( diag, pMsgTxtPtr, pMsgTxtSize, pMsgTxtSizePtr, 16, diagrow->Msg, -1 ); // debug //__ODBCLOG(_ODBCLogMsg(LogLevel_DEBUG,"SQLGetDiagRec msg: %s", pMsgTxtPtr ? ( StrPtr )pMsgTxtPtr : "(unknown)" )); RETCODE ret = ( pMsgTxtSizePtr && ( *pMsgTxtSizePtr ) > pMsgTxtSize ) ? SQL_SUCCESS_WITH_INFO : SQL_SUCCESS; __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "The SQLGetDiagRecW return code is %d", ret ) ); return ret; }
int main(int argc, char **argv) { wchar_t **argv_copy = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*argc); /* We need a second copies, as Python might modify the first one. */ wchar_t **argv_copy2 = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*argc); int i, res; char *oldloc; /* 754 requires that FP exceptions run in "no stop" mode by default, * and until C vendors implement C99's ways to control FP exceptions, * Python requires non-stop mode. Alas, some platforms enable FP * exceptions by default. Here we disable them. */ #ifdef __FreeBSD__ fp_except_t m; m = fpgetmask(); fpsetmask(m & ~FP_X_OFL); #endif if (!argv_copy || !argv_copy2) { fprintf(stderr, "out of memory\n"); return 1; } oldloc = strdup(setlocale(LC_ALL, NULL)); setlocale(LC_ALL, ""); for (i = 0; i < argc; i++) { argv_copy2[i] = argv_copy[i] = char2wchar(argv[i]); if (!argv_copy[i]) return 1; } setlocale(LC_ALL, oldloc); free(oldloc); res = Py_Main(argc, argv_copy); for (i = 0; i < argc; i++) { PyMem_Free(argv_copy2[i]); } PyMem_Free(argv_copy); PyMem_Free(argv_copy2); return res; }
// ----------------------------------------------------------------------- // to connect to the driver // ----------------------------------------------------------------------- RETCODE SQL_API SQLDriverConnectW ( SQLHDBC hdbc, SQLHWND hwnd, SQLWCHAR* szConnStrIn, SQLSMALLINT cchConnStrIn, SQLWCHAR* szConnStrOut, SQLSMALLINT cchConnStrOutMax, SQLSMALLINT* pcchConnStrOut, SQLUSMALLINT fDriverCompletion ) { __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "SQLDriverConnectW called, cchConnStrIn %d, cchConnStrOutMax %d, wcslen %d", cchConnStrIn, cchConnStrOutMax, wcslen ( szConnStrIn ) ) ); int inStrLength = wcslen ( szConnStrIn ) + 1; __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "The inStr Length is : %d", inStrLength ) ); unique_ptr<char[]> pInStr ( new char[inStrLength] ); unique_ptr<char[]> pOutStr ( new char[cchConnStrOutMax + 1] ); wchar2char ( szConnStrIn, pInStr.get(), inStrLength ); //__ODBCLOG(_ODBCLogMsg(LogLevel_DEBUG,"The inStr is : %s",pInStr.get())); SQLSMALLINT outStrLength = 0 ; RETCODE code = SQLDriverConnect ( hdbc, hwnd, ( SQLCHAR* ) pInStr.get(), cchConnStrIn, ( SQLCHAR* ) pOutStr.get(), cchConnStrOutMax, &outStrLength, fDriverCompletion ); if ( code == SQL_ERROR ) { return code; } __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "pcchConnStrOut null? %d, cchConnStrOutMax > 0 ? %d, szConnStrOut null? %d", pcchConnStrOut == NULL, cchConnStrOutMax > 0 , szConnStrOut == NULL ) ); if ( cchConnStrOutMax > 0 && pcchConnStrOut && szConnStrOut ) { char2wchar ( pOutStr.get(), szConnStrOut, ( int ) cchConnStrOutMax ); *pcchConnStrOut = wcslen ( szConnStrOut ); __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "(W)The Length of Out Conn Str is %d", *pcchConnStrOut ) ); } __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "the ret code is %d", code ) ); return code; }
char * lowerstr(char *str) { char *ptr = str; char *out; int len = strlen(str); if ( len == 0 ) return pstrdup(""); #ifdef TS_USE_WIDE /* * Use wide char code only when max encoding length > 1 and ctype != C. * Some operating systems fail with multi-byte encodings and a C locale. * Also, for a C locale there is no need to process as multibyte. From * backend/utils/adt/oracle_compat.c Teodor */ if (pg_database_encoding_max_length() > 1 && !lc_ctype_is_c()) { wchar_t *wstr, *wptr; int wlen; /* *alloc number of wchar_t for worst case, len contains * number of bytes <= number of characters and * alloc 1 wchar_t for 0, because wchar2char(wcstombs in really) * wants zero-terminated string */ wptr = wstr = (wchar_t *) palloc(sizeof(wchar_t) * (len+1)); /* * str SHOULD be cstring, so wlen contains number * of converted character */ wlen = char2wchar(wstr, str, len); if ( wlen < 0 ) ereport(ERROR, (errcode(ERRCODE_CHARACTER_NOT_IN_REPERTOIRE), errmsg("translation failed from server encoding to wchar_t"))); Assert(wlen<=len); wstr[wlen] = 0; while (*wptr) { *wptr = towlower((wint_t) *wptr); wptr++; } /* * Alloc result string for worst case + '\0' */ len = sizeof(char)*pg_database_encoding_max_length()*(wlen+1); out = (char*)palloc(len); /* * wlen now is number of bytes which is always >= number of characters */ wlen = wchar2char(out, wstr, len); pfree(wstr); if ( wlen < 0 ) ereport(ERROR, (errcode(ERRCODE_CHARACTER_NOT_IN_REPERTOIRE), errmsg("translation failed from wchar_t to server encoding %d", errno))); Assert(wlen<=len); out[wlen]='\0'; } else #endif { char *outptr; outptr = out = (char*)palloc( sizeof(char) * (len+1) ); while (*ptr) { *outptr++ = tolower(*(unsigned char *) ptr); ptr++; } *outptr = '\0'; } return out; }
void initialize(int argc, char *argv[], bool setup_default_environment){ wchar_t **argv_copy; char exec_path[2048]; char home_path[2048]; wchar_t *wide_exec_path; wchar_t *wide_home_path; argv_copy = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*argc); for (int i = 0; i < argc - 1; i++) { argv_copy[i] = char2wchar(argv[i + 1]); // todo: handle the case where argv_copy is NULL } Mango::initialize(false); if (setup_default_environment) { Mango::GlobalFrame = new Mango::Core::Frame(true); Mango::Engine = new MangoPy::PyEngine(); Mango::Keyboard = new Mango::Core::CoreKeyboard(); Mango::Mouse = new Mango::Core::CoreMouse(); Mango::Camera = new Mango::Core::CoreCamera(); Mango::View = new Mango::Core::CoreCamera(); Mango::Camera->set(STEP); Mango::Camera->lookAt(Mango::Vector(0, 0, 0), 5); Mango::View->set(STEP); Mango::View->setMode(RMB_CYLINDRICAL_ROTATE | LMB_DRAG_FOCUS | ZOOM_SCALES); Mango::Engine->setCameraObject(Mango::Camera); Mango::Engine->setViewObject(Mango::View); } // Add modules - phase one PyImport_AppendInittab("_mpygen", PyInit__mpygen); PyImport_AppendInittab("Core", PyInit_Core); PyImport_AppendInittab("OpenGL", PyInit_OpenGL); PyImport_AppendInittab("Draw", PyInit_Draw); // Initialize Python if (!executable_path(exec_path, 2048)){ std::cout << "Warning: could not determine executable path." << std::endl; std::cout << " using argv[0], but this value is not reliable" << std::endl; std::cout << " and Mango may not be able to find or execute " << std::endl; std::cout << " files outside of its own directory" << std::endl; strncpy(exec_path, argv[0], 2047); exec_path[2047] = NULL; } wide_exec_path = char2wchar(exec_path); // Py_SetProgramName(wide_exec_path); #if !defined(WIN32) // Set Home Path // Windows seems to set exec_prefix just fine without this, so // it is skipped on windows until needed python_home_path(exec_path, home_path, 2048); wide_home_path = char2wchar(home_path); // Py_SetPythonHome(wide_home_path); #endif Py_Initialize(); PySys_SetArgv(argc - 1, argv_copy); // Add modules - phase two PyObject* main_module = PyImport_AddModule("__main__"); PyObject *module_mpygen = PyImport_ImportModule("_mpygen"); Py_INCREF(module_mpygen); PyModule_AddObject(main_module, "_mpygen", module_mpygen); if (module_mpygen == NULL){ std::cout << "MangoPy: Error creating module _mpygen" << std::endl; exit(1); } PyObject *module_core = PyImport_ImportModule("Core"); Py_INCREF(module_core); PyModule_AddObject(main_module, "Core", module_core); if (module_core == NULL){ std::cout << "MangoPy: Error creating module Core" << std::endl; exit(1); } PyObject *module_opengl = PyImport_ImportModule("OpenGL"); Py_INCREF(module_opengl); PyModule_AddObject(main_module, "OpenGL", module_opengl); if (module_opengl == NULL){ std::cout << "MangoPy: Error creating module OpenGL" << std::endl; exit(1); } PyObject *module_draw = PyImport_ImportModule("Draw"); Py_INCREF(module_draw); PyModule_AddObject(main_module, "Draw", module_draw); if (module_draw == NULL){ std::cout << "MangoPy: Error creating module Draw" << std::endl; exit(1); } // Add absolute path to engine to the module search path PyRun_SimpleString("import os, sys"); PyModule_AddStringConstant(module_core, "MANGO_LAUNCH_PATH", exec_path); PyRun_SimpleString("Core.MANGO_ABSOLUTE_PATH = os.path.dirname(os.path.normpath(os.path.realpath(Core.MANGO_LAUNCH_PATH)))"); PyRun_SimpleString("sys.path.append(Core.MANGO_ABSOLUTE_PATH)"); PyRun_SimpleString("sys.path.append(os.path.normpath(os.path.join(Core.MANGO_ABSOLUTE_PATH, '../script')))"); // Make the Core module globally available PyRun_SimpleString("__builtins__._mpygen = _mpygen"); PyRun_SimpleString("__builtins__.Core = Core"); PyRun_SimpleString("__builtins__.Draw = Draw"); PyRun_SimpleString("__builtins__.OpenGL = OpenGL"); PyRun_SimpleString("__builtins__.Vector = Core.Vector"); PyRun_SimpleString("__builtins__.STEP = Core.STEP"); PyRun_SimpleString("__builtins__.RENDER = Core.RENDER"); PyRun_SimpleString("__builtins__.DRAW = Core.DRAW"); PyRun_SimpleString("__builtins__.INPUT = Core.INPUT"); PyRun_SimpleString("__builtins__.CAMERA_DEFAULT_MODE = Core.CAMERA_DEFAULT_MODE"); PyRun_SimpleString("__builtins__.LOCK_PAN = Core.LOCK_PAN"); PyRun_SimpleString("__builtins__.LOCK_DISTANCE = Core.LOCK_DISTANCE"); PyRun_SimpleString("__builtins__.LOCK_ALPHA = Core.LOCK_ALPHA"); PyRun_SimpleString("__builtins__.LOCK_BETA = Core.LOCK_BETA"); PyRun_SimpleString("__builtins__.LOCK_GAMMA = Core.LOCK_GAMMA"); PyRun_SimpleString("__builtins__.RMB_CYLINDRICAL_ROTATE = Core.RMB_CYLINDRICAL_ROTATE"); PyRun_SimpleString("__builtins__.LMB_DRAG_FOCUS = Core.LMB_DRAG_FOCUS"); PyRun_SimpleString("__builtins__.LOCK_ALL = Core.LOCK_ALL"); PyRun_SimpleString("__builtins__.KEY_WINDOWS_MENU = Core.KEY_WINDOWS_MENU"); PyRun_SimpleString("__builtins__.KEY_WINDOWS_RIGHT = Core.KEY_WINDOWS_RIGHT"); PyRun_SimpleString("__builtins__.KEY_WINDOWS_LEFT = Core.KEY_WINDOWS_LEFT"); PyRun_SimpleString("__builtins__.KEY_NUMPAD_DIVIDE = Core.KEY_NUMPAD_DIVIDE"); PyRun_SimpleString("__builtins__.KEY_NUMPAD_DECIMAL = Core.KEY_NUMPAD_DECIMAL"); PyRun_SimpleString("__builtins__.KEY_NUMPAD_SUBTRACT = Core.KEY_NUMPAD_SUBTRACT"); PyRun_SimpleString("__builtins__.KEY_NUMPAD_SEPARATOR = Core.KEY_NUMPAD_SEPARATOR"); PyRun_SimpleString("__builtins__.KEY_NUMPAD_ADD = Core.KEY_NUMPAD_ADD"); PyRun_SimpleString("__builtins__.KEY_NUMPAD_MULTIPLY = Core.KEY_NUMPAD_MULTIPLY"); PyRun_SimpleString("__builtins__.KEY_NUMPAD_EQUAL = Core.KEY_NUMPAD_EQUAL"); PyRun_SimpleString("__builtins__.KEY_NUMPAD_DELETE = Core.KEY_NUMPAD_DELETE"); PyRun_SimpleString("__builtins__.KEY_NUMPAD_INSERT = Core.KEY_NUMPAD_INSERT"); PyRun_SimpleString("__builtins__.KEY_NUMPAD_BEGIN = Core.KEY_NUMPAD_BEGIN"); PyRun_SimpleString("__builtins__.KEY_NUMPAD_END = Core.KEY_NUMPAD_END"); PyRun_SimpleString("__builtins__.KEY_NUMPAD_PAGEDOWN = Core.KEY_NUMPAD_PAGEDOWN"); PyRun_SimpleString("__builtins__.KEY_NUMPAD_PAGEUP = Core.KEY_NUMPAD_PAGEUP"); PyRun_SimpleString("__builtins__.KEY_NUMPAD_DOWN = Core.KEY_NUMPAD_DOWN"); PyRun_SimpleString("__builtins__.KEY_NUMPAD_RIGHT = Core.KEY_NUMPAD_RIGHT"); PyRun_SimpleString("__builtins__.KEY_NUMPAD_UP = Core.KEY_NUMPAD_UP"); PyRun_SimpleString("__builtins__.KEY_NUMPAD_LEFT = Core.KEY_NUMPAD_LEFT"); PyRun_SimpleString("__builtins__.KEY_NUMPAD_HOME = Core.KEY_NUMPAD_HOME"); PyRun_SimpleString("__builtins__.KEY_NUMPAD_F4 = Core.KEY_NUMPAD_F4"); PyRun_SimpleString("__builtins__.KEY_NUMPAD_F3 = Core.KEY_NUMPAD_F3"); PyRun_SimpleString("__builtins__.KEY_NUMPAD_F2 = Core.KEY_NUMPAD_F2"); PyRun_SimpleString("__builtins__.KEY_NUMPAD_F1 = Core.KEY_NUMPAD_F1"); PyRun_SimpleString("__builtins__.KEY_NUMPAD_ENTER = Core.KEY_NUMPAD_ENTER"); PyRun_SimpleString("__builtins__.KEY_NUMPAD_TAB = Core.KEY_NUMPAD_TAB"); PyRun_SimpleString("__builtins__.KEY_NUMPAD_SPACE = Core.KEY_NUMPAD_SPACE"); PyRun_SimpleString("__builtins__.KEY_PAGEDOWN = Core.KEY_PAGEDOWN"); PyRun_SimpleString("__builtins__.KEY_PAGEUP = Core.KEY_PAGEUP"); PyRun_SimpleString("__builtins__.KEY_SCROLL = Core.KEY_SCROLL"); PyRun_SimpleString("__builtins__.KEY_NUMLOCK = Core.KEY_NUMLOCK"); PyRun_SimpleString("__builtins__.KEY_F24 = Core.KEY_F24"); PyRun_SimpleString("__builtins__.KEY_F23 = Core.KEY_F23"); PyRun_SimpleString("__builtins__.KEY_F22 = Core.KEY_F22"); PyRun_SimpleString("__builtins__.KEY_F21 = Core.KEY_F21"); PyRun_SimpleString("__builtins__.KEY_F20 = Core.KEY_F20"); PyRun_SimpleString("__builtins__.KEY_F19 = Core.KEY_F19"); PyRun_SimpleString("__builtins__.KEY_F18 = Core.KEY_F18"); PyRun_SimpleString("__builtins__.KEY_F17 = Core.KEY_F17"); PyRun_SimpleString("__builtins__.KEY_F16 = Core.KEY_F16"); PyRun_SimpleString("__builtins__.KEY_F15 = Core.KEY_F15"); PyRun_SimpleString("__builtins__.KEY_F14 = Core.KEY_F14"); PyRun_SimpleString("__builtins__.KEY_F13 = Core.KEY_F13"); PyRun_SimpleString("__builtins__.KEY_F12 = Core.KEY_F12"); PyRun_SimpleString("__builtins__.KEY_F11 = Core.KEY_F11"); PyRun_SimpleString("__builtins__.KEY_F10 = Core.KEY_F10"); PyRun_SimpleString("__builtins__.KEY_F9 = Core.KEY_F9"); PyRun_SimpleString("__builtins__.KEY_F8 = Core.KEY_F8"); PyRun_SimpleString("__builtins__.KEY_F7 = Core.KEY_F7"); PyRun_SimpleString("__builtins__.KEY_F6 = Core.KEY_F6"); PyRun_SimpleString("__builtins__.KEY_F5 = Core.KEY_F5"); PyRun_SimpleString("__builtins__.KEY_F4 = Core.KEY_F4"); PyRun_SimpleString("__builtins__.KEY_F3 = Core.KEY_F3"); PyRun_SimpleString("__builtins__.KEY_F2 = Core.KEY_F2"); PyRun_SimpleString("__builtins__.KEY_F1 = Core.KEY_F1"); PyRun_SimpleString("__builtins__.KEY_DIVIDE = Core.KEY_DIVIDE"); PyRun_SimpleString("__builtins__.KEY_DECIMAL = Core.KEY_DECIMAL"); PyRun_SimpleString("__builtins__.KEY_SUBTRACT = Core.KEY_SUBTRACT"); PyRun_SimpleString("__builtins__.KEY_SEPARATOR = Core.KEY_SEPARATOR"); PyRun_SimpleString("__builtins__.KEY_ADD = Core.KEY_ADD"); PyRun_SimpleString("__builtins__.KEY_MULTIPLY = Core.KEY_MULTIPLY"); PyRun_SimpleString("__builtins__.KEY_NUMPAD9 = Core.KEY_NUMPAD9"); PyRun_SimpleString("__builtins__.KEY_NUMPAD8 = Core.KEY_NUMPAD8"); PyRun_SimpleString("__builtins__.KEY_NUMPAD7 = Core.KEY_NUMPAD7"); PyRun_SimpleString("__builtins__.KEY_NUMPAD6 = Core.KEY_NUMPAD6"); PyRun_SimpleString("__builtins__.KEY_NUMPAD5 = Core.KEY_NUMPAD5"); PyRun_SimpleString("__builtins__.KEY_NUMPAD4 = Core.KEY_NUMPAD4"); PyRun_SimpleString("__builtins__.KEY_NUMPAD3 = Core.KEY_NUMPAD3"); PyRun_SimpleString("__builtins__.KEY_NUMPAD2 = Core.KEY_NUMPAD2"); PyRun_SimpleString("__builtins__.KEY_NUMPAD1 = Core.KEY_NUMPAD1"); PyRun_SimpleString("__builtins__.KEY_NUMPAD0 = Core.KEY_NUMPAD0"); PyRun_SimpleString("__builtins__.KEY_HELP = Core.KEY_HELP"); PyRun_SimpleString("__builtins__.KEY_INSERT = Core.KEY_INSERT"); PyRun_SimpleString("__builtins__.KEY_SNAPSHOT = Core.KEY_SNAPSHOT"); PyRun_SimpleString("__builtins__.KEY_EXECUTE = Core.KEY_EXECUTE"); PyRun_SimpleString("__builtins__.KEY_PRINT = Core.KEY_PRINT"); PyRun_SimpleString("__builtins__.KEY_SELECT = Core.KEY_SELECT"); PyRun_SimpleString("__builtins__.KEY_DOWN = Core.KEY_DOWN"); PyRun_SimpleString("__builtins__.KEY_RIGHT = Core.KEY_RIGHT"); PyRun_SimpleString("__builtins__.KEY_UP = Core.KEY_UP"); PyRun_SimpleString("__builtins__.KEY_LEFT = Core.KEY_LEFT"); PyRun_SimpleString("__builtins__.KEY_HOME = Core.KEY_HOME"); PyRun_SimpleString("__builtins__.KEY_END = Core.KEY_END"); PyRun_SimpleString("__builtins__.KEY_CAPITAL = Core.KEY_CAPITAL"); PyRun_SimpleString("__builtins__.KEY_PAUSE = Core.KEY_PAUSE"); PyRun_SimpleString("__builtins__.KEY_MENU = Core.KEY_MENU"); PyRun_SimpleString("__builtins__.KEY_CONTROL = Core.KEY_CONTROL"); PyRun_SimpleString("__builtins__.KEY_ALT = Core.KEY_ALT"); PyRun_SimpleString("__builtins__.KEY_SHIFT = Core.KEY_SHIFT"); PyRun_SimpleString("__builtins__.KEY_CLEAR = Core.KEY_CLEAR"); PyRun_SimpleString("__builtins__.KEY_MBUTTON = Core.KEY_MBUTTON"); PyRun_SimpleString("__builtins__.KEY_CANCEL = Core.KEY_CANCEL"); PyRun_SimpleString("__builtins__.KEY_RBUTTON = Core.KEY_RBUTTON"); PyRun_SimpleString("__builtins__.KEY_LBUTTON = Core.KEY_LBUTTON"); PyRun_SimpleString("__builtins__.KEY_START = Core.KEY_START"); PyRun_SimpleString("__builtins__.KEY_DELETE = Core.KEY_DELETE"); PyRun_SimpleString("__builtins__.KEY_SPACE = Core.KEY_SPACE"); PyRun_SimpleString("__builtins__.KEY_ESCAPE = Core.KEY_ESCAPE"); PyRun_SimpleString("__builtins__.KEY_RETURN = Core.KEY_RETURN"); PyRun_SimpleString("__builtins__.KEY_ENTER = Core.KEY_ENTER"); PyRun_SimpleString("__builtins__.KEY_TAB = Core.KEY_TAB"); PyRun_SimpleString("__builtins__.BUTTON_RIGHT = Core.BUTTON_RIGHT"); PyRun_SimpleString("__builtins__.KEY_BACKSPACE = Core.KEY_BACKSPACE"); PyRun_SimpleString("__builtins__.BUTTON_MIDDLE = Core.BUTTON_MIDDLE"); PyRun_SimpleString("__builtins__.BUTTON_LEFT = Core.BUTTON_LEFT"); PyRun_SimpleString("__builtins__.ANY = Core.ANY"); PyRun_SimpleString("__builtins__.RELEASE = Core.RELEASE"); PyRun_SimpleString("__builtins__.CLICK = Core.CLICK"); PyRun_SimpleString("__builtins__.PRESS = Core.PRESS"); PyRun_SimpleString("__builtins__.MOUSE = Core.MOUSE"); PyRun_SimpleString("__builtins__.KEYBOARD = Core.KEYBOARD"); PyRun_SimpleString("__builtins__.BUTTON_STATE_DOWN = Core.BUTTON_STATE_DOWN"); PyRun_SimpleString("__builtins__.BUTTON_STATE_UP = Core.BUTTON_STATE_UP"); PyRun_SimpleString("__builtins__.KEY_STATE_DOWN = Core.KEY_STATE_DOWN"); PyRun_SimpleString("__builtins__.KEY_STATE_UP = Core.KEY_STATE_UP"); // Make opengl methods available in the global namespace PyRun_SimpleString("__builtins__.GL_POINTS = OpenGL.GL_POINTS"); PyRun_SimpleString("__builtins__.GL_LINES = OpenGL.GL_LINES"); PyRun_SimpleString("__builtins__.GL_LINE_LOOP = OpenGL.GL_LINE_LOOP"); PyRun_SimpleString("__builtins__.GL_LINE_STRIP = OpenGL.GL_LINE_STRIP"); PyRun_SimpleString("__builtins__.GL_TRIANGLES = OpenGL.GL_TRIANGLES"); PyRun_SimpleString("__builtins__.GL_TRIANGLE_STRIP = OpenGL.GL_TRIANGLE_STRIP"); PyRun_SimpleString("__builtins__.GL_TRIANGLE_FAN = OpenGL.GL_TRIANGLE_FAN"); PyRun_SimpleString("__builtins__.GL_QUADS = OpenGL.GL_QUADS"); PyRun_SimpleString("__builtins__.GL_QUAD_STRIP = OpenGL.GL_QUAD_STRIP"); PyRun_SimpleString("__builtins__.GL_POLYGON = OpenGL.GL_POLYGON"); PyRun_SimpleString("__builtins__.glBegin = OpenGL.glBegin"); PyRun_SimpleString("__builtins__.glEnd = OpenGL.glEnd"); PyRun_SimpleString("__builtins__.glVertex = OpenGL.glVertex"); PyRun_SimpleString("__builtins__.glNormal = OpenGL.glNormal"); PyRun_SimpleString("__builtins__.glColor = OpenGL.glColor"); PyRun_SimpleString("__builtins__.glTranslate = OpenGL.glTranslate"); PyRun_SimpleString("__builtins__.glRotate = OpenGL.glRotate"); PyRun_SimpleString("__builtins__.glScale = OpenGL.glScale"); PyRun_SimpleString("__builtins__.glScale = OpenGL.glScale"); PyRun_SimpleString("__builtins__.glPushMatrix = OpenGL.glPushMatrix"); PyRun_SimpleString("__builtins__.glPopMatrix = OpenGL.glPopMatrix"); // Create global engine instance mpy_PyEngine *py_global_engine = mpy_PyEngine_NEW(); //py_global_engine->internalObject = (PyEngine *)Mango::Engine; // WARNING: this downcasting from a CoreEngine to a PyEngine is dangerous, and only works if you are SURE that Mango::Engine is actually a PyEngine! py_global_engine->internalObject = Mango::Engine; // WARNING: this downcasting from a CoreEngine to a PyEngine is dangerous, and only works if you are SURE that Mango::Engine is actually a PyEngine! PyModule_AddObject(module_core, "Engine", reinterpret_cast<PyObject *>(py_global_engine)); PyRun_SimpleString("__builtins__.Engine = Core.Engine"); // Create global keyboard instance mpy_CoreKeyboard *py_global_keyboard = mpy_CoreKeyboard_NEW(); py_global_keyboard->internalObject = Mango::Keyboard; PyModule_AddObject(module_core, "Keyboard", reinterpret_cast<PyObject *>(py_global_keyboard)); PyRun_SimpleString("__builtins__.Keyboard = Core.Keyboard"); // Create global mouse instance mpy_CoreMouse *py_global_mouse = mpy_CoreMouse_NEW(); py_global_mouse->internalObject = Mango::Mouse; PyModule_AddObject(module_core, "Mouse", reinterpret_cast<PyObject *>(py_global_mouse)); PyRun_SimpleString("__builtins__.Mouse = Core.Mouse"); // Create global frame instance PyGlobalFrame = mpy_Frame_NEW(); PyGlobalFrame->internalObject = Mango::GlobalFrame; PyGlobalFrame->parentFrame = NULL; Py_INCREF(PyGlobalFrame); PyModule_AddObject(module_core, "GlobalFrame", reinterpret_cast<PyObject *>(PyGlobalFrame)); PyRun_SimpleString("__builtins__.GlobalFrame = Core.GlobalFrame"); // Create global camera instance if (Mango::Camera != NULL){ mpy_Frame *py_camera_focus = mpy_Frame_NEW(); py_camera_focus->internalObject = Mango::Camera->parentFrame(); mpy_Frame_init(py_camera_focus, NULL, NULL); mpy_CoreCamera *py_global_camera = mpy_CoreCamera_NEW(); Py_INCREF(py_camera_focus); py_global_camera->parentFrame = py_camera_focus; mpy_Object_init((mpy_Object *)py_global_camera, NULL, NULL); py_global_camera->internalObject = Mango::Camera; PyModule_AddObject(module_core, "Camera", reinterpret_cast<PyObject *>(py_global_camera)); PyRun_SimpleString("__builtins__.Camera = Core.Camera"); } // Create global view instance if (Mango::View != NULL){ mpy_CoreCamera *py_global_view = mpy_CoreCamera_NEW(); py_global_view->internalObject = Mango::View; PyModule_AddObject(module_core, "View", reinterpret_cast<PyObject *>(py_global_view)); PyRun_SimpleString("__builtins__.View = Core.View"); } // Make environment available to extensions PyModule_AddObject(module_mpygen, "GLOBAL_FRAME", PyCapsule_New((void *)Mango::GlobalFrame, NULL, mpy_trivialDelMethod)); PyModule_AddObject(module_mpygen, "PY_GLOBAL_FRAME", PyCapsule_New((void *)PyGlobalFrame, NULL, mpy_trivialDelMethod)); PyModule_AddObject(module_mpygen, "ENGINE", PyCapsule_New((void *)Mango::Engine, NULL, mpy_trivialDelMethod)); PyModule_AddObject(module_mpygen, "CAMERA", PyCapsule_New((void *)Mango::Camera, NULL, mpy_trivialDelMethod)); PyModule_AddObject(module_mpygen, "VIEW", PyCapsule_New((void *)Mango::View, NULL, mpy_trivialDelMethod)); PyModule_AddObject(module_mpygen, "KEYBOARD", PyCapsule_New((void *)Mango::Keyboard, NULL, mpy_trivialDelMethod)); PyModule_AddObject(module_mpygen, "MOUSE", PyCapsule_New((void *)Mango::Mouse, NULL, mpy_trivialDelMethod)); //PyModule_AddObject(module_mpygen, "TYPE_OBJECT", PyCObject_FromVoidPtr((void *)&mpy_ObjectType, mpy_trivialDelMethod)); PyObject *global_types = PyDict_New(); PyModule_AddObject(module_mpygen, "TYPES", global_types); //PyDict_SetItemString(global_types, "mangopy.core.object", PyCObject_FromVoidPtr((void *)&mpy_ObjectType, mpy_trivialDelMethod)); MangoPy::register_py_type_object("mangopy.core.input_event", &mpy_InputEventType); MangoPy::register_py_type_object("mangopy.core.vector", &mpy_VectorType); MangoPy::register_py_type_object("mangopy.core.matrix", &mpy_MatrixType); MangoPy::register_py_type_object("mangopy.core.object", &mpy_ObjectType); MangoPy::register_py_type_object("mangopy.core.frame", &mpy_FrameType); MangoPy::register_py_type_object("mangopy.core.py_engine", &mpy_PyEngineType); MangoPy::register_py_type_object("mangopy.core.core_camera", &mpy_CoreCameraType); MangoPy::register_py_type_object("mangopy.core.core_keyboard", &mpy_CoreKeyboardType); MangoPy::register_py_type_object("mangopy.core.core_mouse", &mpy_CoreMouseType); MangoPy::register_py_type_object("mangopy.core.triangle", &mpy_TriangleType); // Setup Python error buffer PyRun_SimpleString("\n\ #import sys \n\ class MangoPy_StdErr: \n\ def write(self, msg): \n\ _mpygen.writeToPythonScriptStderr(msg) \n\ sys.stderr = MangoPy_StdErr() \n\ "); // Setup Paths Array PyRun_SimpleString("Core.SOURCES = []"); }
//------------------------------------------------------------------------------------- bool Script::install(const wchar_t* pythonHomeDir, std::wstring pyPaths, const char* moduleName, COMPONENT_TYPE componentType) { std::wstring pySysPaths = SCRIPT_PATH; wchar_t* pwpySysResPath = char2wchar(const_cast<char*>(Resmgr::getPySysResPath().c_str())); kbe_replace(pySysPaths, L"../../res/", pwpySysResPath); pyPaths += pySysPaths; free(pwpySysResPath); #if KBE_PLATFORM == PLATFORM_WIN32 Py_SetPythonHome(const_cast<wchar_t*>(pythonHomeDir)); // 先设置python的环境变量 #else std::wstring fs = L";"; std::wstring rs = L":"; size_t pos = 0; while(true) { pos = pyPaths.find(fs, pos); if (pos == std::wstring::npos) break; pyPaths.replace(pos, fs.length(), rs); } Py_SetPath(pyPaths.c_str()); char* tmpchar = wchar2char(const_cast<wchar_t*>(pyPaths.c_str())); DEBUG_MSG("Script::install: paths=%s.\n", tmpchar); free(tmpchar); #endif // Initialise python // Py_VerboseFlag = 2; Py_FrozenFlag = 1; // Warn if tab and spaces are mixed in indentation. // Py_TabcheckFlag = 1; Py_NoSiteFlag = 1; Py_IgnoreEnvironmentFlag = 1; Py_Initialize(); // python解释器的初始化 if (!Py_IsInitialized()) { ERROR_MSG("Script::install::Py_Initialize is failed!\n"); return false; } #if KBE_PLATFORM == PLATFORM_WIN32 PySys_SetPath(pyPaths.c_str()); #endif PyObject *m = PyImport_AddModule("__main__"); module_ = PyImport_AddModule(moduleName); // 添加一个脚本基础模块 if (module_ == NULL) return false; const char* componentName = COMPONENT_NAME_EX(componentType); if (PyModule_AddStringConstant(module_, "component", componentName)) { ERROR_MSG( "Script::init: Unable to set KBEngine.component to %s\n", componentName ); return false; } // 注册产生uuid方法到py APPEND_SCRIPT_MODULE_METHOD(module_, genUUID64, __py_genUUID64, METH_VARARGS, 0); #ifndef KBE_SINGLE_THREADED s_pOurInitTimeModules = PyDict_Copy( PySys_GetObject( "modules" ) ); s_pMainThreadState = PyThreadState_Get(); s_defaultContext = s_pMainThreadState; PyEval_InitThreads(); KBEConcurrency::setMainThreadIdleFunctions( &Script::releaseLock, &Script::acquireLock ); #endif ScriptStdOutErr::installScript(NULL); // 安装py重定向模块 ScriptStdOutErrHook::installScript(NULL); static struct PyModuleDef moduleDesc = { PyModuleDef_HEAD_INIT, moduleName, "This module is created by KBEngine!", -1, NULL }; PyModule_Create(&moduleDesc); // 初始化基础模块 PyObject_SetAttrString(m, moduleName, module_); // 将模块对象加入main pyStdouterr_ = new ScriptStdOutErr(); // 重定向python输出 pyStdouterrHook_ = new ScriptStdOutErrHook(); if(!pyStdouterr_->install()){ // 安装py重定向脚本模块 ERROR_MSG("Script::install::pyStdouterr_->install() is failed!\n"); SCRIPT_ERROR_CHECK(); return false; } Pickler::initialize(); Copy::initialize(); Uuid::initialize(); math::installModule("Math"); INFO_MSG("Script::install is successfully!\n"); return true; }
/* * lowerstr_with_len --- fold string to lower case * * Input string need not be null-terminated. * * Returned string is palloc'd */ char * lowerstr_with_len(const char *str, int len) { char *out; #ifdef USE_WIDE_UPPER_LOWER Oid collation = DEFAULT_COLLATION_OID; /* TODO */ pg_locale_t mylocale = 0; /* TODO */ #endif if (len == 0) return pstrdup(""); #ifdef USE_WIDE_UPPER_LOWER /* * Use wide char code only when max encoding length > 1 and ctype != C. * Some operating systems fail with multi-byte encodings and a C locale. * Also, for a C locale there is no need to process as multibyte. From * backend/utils/adt/oracle_compat.c Teodor */ if (pg_database_encoding_max_length() > 1 && !lc_ctype_is_c(collation)) { wchar_t *wstr, *wptr; int wlen; /* * alloc number of wchar_t for worst case, len contains number of * bytes >= number of characters and alloc 1 wchar_t for 0, because * wchar2char wants zero-terminated string */ wptr = wstr = (wchar_t *) palloc(sizeof(wchar_t) * (len + 1)); wlen = char2wchar(wstr, len + 1, str, len, mylocale); Assert(wlen <= len); while (*wptr) { *wptr = towlower((wint_t) *wptr); wptr++; } /* * Alloc result string for worst case + '\0' */ len = pg_database_encoding_max_length() * wlen + 1; out = (char *) palloc(len); wlen = wchar2char(out, wstr, len, mylocale); pfree(wstr); if (wlen < 0) ereport(ERROR, (errcode(ERRCODE_CHARACTER_NOT_IN_REPERTOIRE), errmsg("conversion from wchar_t to server encoding failed: %m"))); Assert(wlen < len); } else #endif /* USE_WIDE_UPPER_LOWER */ { const char *ptr = str; char *outptr; outptr = out = (char *) palloc(sizeof(char) * (len + 1)); while ((ptr - str) < len && *ptr) { *outptr++ = tolower(TOUCHAR(ptr)); ptr++; } *outptr = '\0'; } return out; }
void cSpeech::talking(int s, QString speech) // PC speech { /* Unicode speech format byte = char, short = char[2], int = char[4], wchar = char[2] = unicode character Message Sent By Client: 0xAD - Unicode Speech Request BYTE cmd(0xAD) short msgsize 1, 2 byte type(0 = say, 2 = emote, 8 = whisper, 9 = yell) 3 short color 4, 5 short font 6, 7 BYTE[4] lang(null terminated, "enu " for US english.) 8, 9, 10, 11 wchar[?] text(null terminated, ?=(msgsize - 12)/2) 13 Message Sent By Server: 0xAE - Unicode Speech Message BYTE cmd(0xAE) 0 short msgsize 1, 2 BYTE[4] ser(ser of speaker, all 0xFF if none) 3, 4, 5, 6 BYTE[2] model(id of speaker, all 0xFF if none)7, 8 BYTE type 9 short color 10, 11 short font 12, 13 BYTE[4] language(same as before) 14, 15, 16, 17 BYTE[30] speaker's name(normal chars, not wchars) 18 - 48 WCHAR[?] text(null terminated, ?=(msgsize - 48)/2 Importnat note regarding 0xAD: since 2.0.7 clients send between lang and text 0...10 bytes. (we can ignore them safely) Those bytes get cut out in network.cpp correctly, so the buffer THIS functions sees is actualy what is written above. The actual data the client sends is differently though. Just noted this to prevent from debugging if somebody finds out client data doesn't fit to this description (LB) */ //char nonuni[512]; unsigned char talk2[19]; QByteArray unicodetext; char lang[4]; char name[50] = {0,}; // it **IS** important to 0 out the remaining gaps P_CHAR pc_currchar = currchar[s]; // strcpy(nonuni, speech.latin1()); // len+font+color+type = same postion for non unicode and unicode speech packets // but 8 ... x DIFFER a lot for unicode and non unicode packets !!! strncpy(name, pc_currchar->name.c_str(), 50); char speech_type = buffer[s][3]; UI16 speech_color = ShortFromCharPtr(&buffer[s][4]); char speech_fontbyte1 = buffer[s][6]; char speech_fontbyte2 = buffer[s][7]; int ucl = ( speech.length() * 2 ) + 2; int tl = ucl + 48 ; if (pc_currchar->unicode) { lang[0]=buffer[s][8]; lang[1]=buffer[s][9]; lang[2]=buffer[s][10]; lang[3]=buffer[s][11]; unicodetext.duplicate( (char*)&buffer[s][12], ucl ); } else { lang[0]='E'; lang[1]='N'; lang[2]='U'; lang[3]=0; char2wchar(speech.latin1()); // we are sending unicode response no matter if the speech request was non unicode or not // so convert to uni-text in case of non unicode unicodetext.duplicate( (char*)&temp, ucl ); } /* clConsole.send("speech: %s\n",nonuni); clConsole.send("unicode speech:\n"); for ( a=0; a < tl-48; a++) clConsole.send("%02i ",unicodetext[a]); clConsole.send("\n");*/ //// Very important: do not use buffer[s][] anymore in this function !!!! //// unicode text that gets send is in unicodetext, nonunicode text for normal string processing in non uni code // string punt(nonuni); if (InputSpeech(speech, pc_currchar, s)) // handle things like renaming or describing an item return; if (pc_currchar->squelched) // not allowed to talk { sysmessage(s, "You have been squelched."); return; } // AntiChrist pc_currchar->unhide(); if (speech[0] == (char)SrvParams->commandPrefix() ) { Commands->Command(s, speech.latin1()); return; } if ( speech_type == '\x09' && pc_currchar->canBroadcast() ) { broadcast(s); return; } talk2[0] = 0xAE; ShortToCharPtr(tl, &talk2[1]); LongToCharPtr(pc_currchar->serial, &talk2[3]); ShortToCharPtr(pc_currchar->id(), &talk2[7]); talk2[9] = speech_type; ShortToCharPtr(speech_color, &talk2[10]); talk2[12] = speech_fontbyte1; talk2[13] = speech_fontbyte2; talk2[14] = lang[0]; talk2[15] = lang[1]; talk2[16] = lang[2]; talk2[17] = lang[3]; Xsend(s, talk2, 18); Xsend(s, name, 30); Xsend(s, unicodetext.data(), unicodetext.size()); if (speech_type == 0 || speech_type == 2) { pc_currchar->saycolor = speech_color; } if (SrvParams->speechLog()) // Logging bugfixed by LB { char temp2[512]; sprintf(temp2, "%s.speech_log", pc_currchar->name.c_str()); sprintf((char*)temp, "%s [%x] [%i] said:\n%s\n", pc_currchar->name.c_str(), pc_currchar->serial, pc_currchar->account, speech.latin1()); savelog((char*)temp, (char*)temp2); } //char SpeechUpr[512]; //strcpy(SpeechUpr, nonuni); //strupr(SpeechUpr); QString SpeechUpr = speech.upper(); //transform(SpeechUpr.begin(), SpeechUpr.end(), SpeechUpr.begin(), ::toupper); //if (!strcmp(SpeechUpr, "I RESIGN FROM MY GUILD")) if (SpeechUpr == "I RESIGN FROM MY GUILD") { GuildResign(s); } if (response(s,pc_currchar, SpeechUpr)) return; // Vendor responded already //if (strstr(SpeechUpr, "GUARDS")) if (SpeechUpr.contains("GUARDS")) callguards(currchar[s]); if (Boats->Speech(s, SpeechUpr)) return; house_speech(s, SpeechUpr); // houses crackerjack 8/12/99 int i, j; for (i = 0; i < now; i++) { // AntiChrist - don't check line of sight for talking!!! if (inrange1(i, s) && perm[i] && i!=s)//&&line_of_sight(s, pc_currchar->pos.x, pc_currchar->pos.y, pc_currchar->pos.z, chars[currchar[i]].x, chars[currchar[i]].y, chars[currchar[i]].z, WALLS_CHIMNEYS + DOORS + FLOORS_FLAT_ROOFING)) { Xsend(i, talk2, 18); Xsend(i, name, 30); if (pc_currchar->dead // a ghost is talking && !currchar[i]->dead // Ghost can talk normally to other ghosts && !currchar[i]->isGMorCounselor()// GM/Counselors can see ghosts talking always Seers? && currchar[i]->spiritspeaktimer == 0) { unsigned char ghostspeech[512]; memcpy(&ghostspeech, unicodetext.data(), unicodetext.size()); for (j = 1; j < ucl-2 ; j += 2) // -2: dont override /0 /0 terminator ! { if (ghostspeech[j] != 32) // keep the blanks ghostspeech[j] = (ghostspeech[j]%2) ? 'O' : 'o'; } Xsend(i, ghostspeech, ucl); // send 'ghostified' speech "OOoooOo Ooo" } else Xsend(i, unicodetext.data(), unicodetext.size()); } } if (pc_currchar->dead) return; // this makes it so npcs do not respond to dead people cChar* pc=NULL; cChar* pNpc=NULL; cRegion::RegionIterator4Chars ri(pc_currchar->pos); for (ri.Begin(); !ri.atEnd(); ri++) { pc = ri.GetData(); if (!pc->isSameAs(pc_currchar) && pc->isNpc() && pc->dist(pc_currchar) <= 2) { pNpc=pc; break; } } if (pNpc && pNpc->speech) { Script *pScp=i_scripts[speech_script]; if (!pScp->Open()) return; char sect[512]; sprintf(sect, "SPEECH %i", pNpc->speech); if (!pScp->find(sect)) { pScp->Close(); return; } int match = 0; strcpy(sect, "NO DEFAULT TEXT DEFINED"); unsigned long loopexit = 0; do { pScp->NextLineSplitted(); if (script1[0] != '}') { if (!(strcmp("DEFAULT", (char*)script1))) { strcpy(sect, (char*)script2); } if (!(strcmp("ON", (char*)script1))) { char scpUpr[500]; strcpy(scpUpr,script2); strupr(scpUpr); if (SpeechUpr.find(scpUpr)!= string::npos) match=1; } if (!(strcmp("SAY", (char*)script1))) { if (match == 1) { npctalk(s, pNpc, (char*)script2, 0); match = 2; } } if (!(strcmp("TRG", (char*)script1))) // Added by Magius(CHE) § { if (match == 1) { pNpc->trigger = str2num(script2); scpMark m=pScp->Suspend(); Trig->triggernpc(s, pNpc, 1); pScp->Resume(m); strcpy((char*)script1, "DUMMY"); match = 2; } } } } while (script1[0] != '}' && (++loopexit < MAXLOOPS)); if (match == 0) { npctalk(s, pNpc, sect, 0); } pScp->Close(); } }
RETCODE SQL_API _SQLCopyWCharData ( pODBCDiag pDiag, void* pTgtDataPtr, Long pDataBufSize, void* pSizePtr, Word pSizePtrSize, CStrPtr pSrcData, Long pSrcDataSize ) { unique_ptr<wchar_t[]> pWCS ( char2wchar ( pSrcData ) ); return _SQLCopyWCharDataW ( pDiag, pTgtDataPtr, pDataBufSize, pSizePtr, pSizePtrSize, pWCS.get(), pSrcDataSize ); }