void closeSample(GtkWidget *app) { Context *context = (Context *) gtk_object_get_data(GTK_OBJECT(app), "context"); if (context->paragraph != NULL) { pf_close(context->paragraph); } DELETE_ARRAY(context); appList = g_slist_remove(appList, app); gtk_widget_destroy(app); if (appList == NULL) { gtk_main_quit(); } }
int HttpServer::readFile(const char *file, std::string &data) { int file_size = 0; int fd_file; if ((fd_file = open(file, O_RDONLY | O_NONBLOCK)) < 0) { SI_LOG_ERROR("readFile %s", file); PERROR("File not found"); return 0; } const off_t size = lseek(fd_file, 0, SEEK_END); lseek(fd_file, 0, SEEK_SET); char *buf = new char[size]; if (buf != nullptr) { file_size = read(fd_file, buf, size); data.assign(buf, file_size); DELETE_ARRAY(buf); } CLOSE_FD(fd_file); // SI_LOG_DEBUG("GET %s (size %d)", file, file_size); return file_size; }
static UnicodeString &getWindowsFormat(int32_t lcid, UBool currency, UnicodeString &appendTo, const wchar_t *fmt, ...) { wchar_t nStackBuffer[STACK_BUFFER_SIZE]; wchar_t *nBuffer = nStackBuffer; va_list args; int result; nBuffer[0] = 0x0000; /* Due to the arguments causing a result to be <= 23 characters (+2 for NULL and minus), we don't need to reallocate the buffer. */ va_start(args, fmt); result = _vsnwprintf(nBuffer, STACK_BUFFER_SIZE, fmt, args); va_end(args); /* Just to make sure of the above statement, we add this assert */ U_ASSERT(result >=0); // The following code is not used because _vscwprintf isn't available on MinGW at the moment. /*if (result < 0) { int newLength; va_start(args, fmt); newLength = _vscwprintf(fmt, args); va_end(args); nBuffer = NEW_ARRAY(UChar, newLength + 1); va_start(args, fmt); result = _vsnwprintf(nBuffer, newLength + 1, fmt, args); va_end(args); }*/ // vswprintf is sensitive to the locale set by setlocale. For some locales // it doesn't use "." as the decimal separator, which is what GetNumberFormatW // and GetCurrencyFormatW both expect to see. // // To fix this, we scan over the string and replace the first non-digits, except // for a leading "-", with a "." // // Note: (nBuffer[0] == L'-') will evaluate to 1 if there is a leading '-' in the // number, and 0 otherwise. for (wchar_t *p = &nBuffer[nBuffer[0] == L'-']; *p != L'\0'; p += 1) { if (*p < L'0' || *p > L'9') { *p = L'.'; break; } } wchar_t stackBuffer[STACK_BUFFER_SIZE]; wchar_t *buffer = stackBuffer; buffer[0] = 0x0000; if (currency) { result = GetCurrencyFormatW(lcid, 0, nBuffer, NULL, buffer, STACK_BUFFER_SIZE); if (result == 0) { DWORD lastError = GetLastError(); if (lastError == ERROR_INSUFFICIENT_BUFFER) { int newLength = GetCurrencyFormatW(lcid, 0, nBuffer, NULL, NULL, 0); buffer = NEW_ARRAY(UChar, newLength); buffer[0] = 0x0000; GetCurrencyFormatW(lcid, 0, nBuffer, NULL, buffer, newLength); } } } else { result = GetNumberFormatW(lcid, 0, nBuffer, NULL, buffer, STACK_BUFFER_SIZE); if (result == 0) { DWORD lastError = GetLastError(); if (lastError == ERROR_INSUFFICIENT_BUFFER) { int newLength = GetNumberFormatW(lcid, 0, nBuffer, NULL, NULL, 0); buffer = NEW_ARRAY(UChar, newLength); buffer[0] = 0x0000; GetNumberFormatW(lcid, 0, nBuffer, NULL, buffer, newLength); } } } appendTo.append(buffer, (int32_t) wcslen(buffer)); if (buffer != stackBuffer) { DELETE_ARRAY(buffer); } /*if (nBuffer != nStackBuffer) { DELETE_ARRAY(nBuffer); }*/ return appendTo; }
/* Destructor */ tagSTJ1939_MSG::~tagSTJ1939_MSG() { memset(&m_sMsgProperties, 0, sizeof(STJ1939_MSG_PROPERTIES)); m_unDLC = 0; DELETE_ARRAY(m_pbyData); }
Sound_Engine::Internal::Sub_Sound::~Sub_Sound(){ Internal::LoadedSounds.erase(File_Name); DELETE_ARRAY(buffer.pAudioData); DELETE_ARRAY(wmaBuffer.pDecodedPacketCumulativeBytes); }
//--------------------------------------------------------- double CSG_mRMR::Get_MutualInfo(double *pab, long pabhei, long pabwid) { //----------------------------------------------------- // check if parameters are correct if( !pab ) { SG_UI_Msg_Add_Error("Got illeagal parameter in compute_mutualinfo()."); return( -1.0 ); } //----------------------------------------------------- long i, j; double **pab2d = new double *[pabwid]; for(j=0; j<pabwid; j++) { pab2d[j] = pab + (long)j * pabhei; } double *p1 = 0, *p2 = 0; long p1len = 0, p2len = 0; int b_findmarginalprob = 1; //----------------------------------------------------- //generate marginal probability arrays if( b_findmarginalprob != 0 ) { p1len = pabhei; p2len = pabwid; p1 = new double[p1len]; p2 = new double[p2len]; for (i = 0; i < p1len; i++) p1[i] = 0; for (j = 0; j < p2len; j++) p2[j] = 0; for (i = 0; i < p1len; i++) //p1len = pabhei { for (j = 0; j < p2len; j++) //p2len = panwid { // printf("%f ",pab2d[j][i]); p1[i] += pab2d[j][i]; p2[j] += pab2d[j][i]; } } } //----------------------------------------------------- // calculate the mutual information double muInf = 0; muInf = 0.0; for (j = 0; j < pabwid; j++) // should for p2 { for (i = 0; i < pabhei; i++) // should for p1 { if (pab2d[j][i] != 0 && p1[i] != 0 && p2[j] != 0) { muInf += pab2d[j][i] * log (pab2d[j][i] / p1[i] / p2[j]); // printf("%f %fab %fa %fb\n",muInf,pab2d[j][i]/p1[i]/p2[j],p1[i],p2[j]); } } } muInf /= log(2.0); //----------------------------------------------------- // free memory DELETE_ARRAY(pab2d); if( b_findmarginalprob != 0 ) { DELETE_ARRAY(p1); DELETE_ARRAY(p2); } return muInf; }
CABuffer * CGmResMan::NewABuffer( const char *pcFileName ) { CABuffer * poABuffer = (CABuffer *)FindFileEntry( pcFileName ); if( !poABuffer ) { CStr oFileName( CGmResMan::DATA_DIR + "audio/" + pcFileName ); const int iDot = oFileName.FindRev( oFileName.GetSize() - 1, '.' ); if( iDot < 0 ) return false; CStr oExt( oFileName.GetData() + iDot + 1 ); oExt.ToLower(); bool bLoadOk = false; LOG( "Loading %s.\n", oFileName.GetData() ); poABuffer = new CABuffer; poABuffer->Init(); if( oExt == "wav" ) { CFileStreamWav oWav; if( oWav.Open( oFileName, CFile::FLAG_READ ) ) { unsigned char * pcBuffer = new unsigned char[oWav.m_uiDataBytes]; if( pcBuffer ) { oWav.Read( pcBuffer, oWav.m_uiDataBytes ); //ASSERT( oWav.m_uiChannels == 1 ); if( poABuffer->Load( pcBuffer, oWav.m_uiDataBytes, oWav.m_uiChannels, oWav.m_uiSampleFreq ) ) { bLoadOk = true; } else { ERR( "Audio Buffer %s.\n", pcFileName ); DELETE_INSTANCE( poABuffer ); } DELETE_ARRAY( pcBuffer ); } } else { bLoadOk = false; } } #ifdef GM_USE_OGG else if( oExt == "ogg" ) { unsigned char *pucData = 0; unsigned int uiBytes = 0; unsigned int uiChannelCount = 0; unsigned int uiSampleFreq = 0; if( bLoadOk = LoadOGG_( oFileName, &pucData, &uiBytes, &uiChannelCount, &uiSampleFreq ) ) { poABuffer->Load( pucData, uiBytes, uiChannelCount, uiSampleFreq ); DELETE_ARRAY( pucData ); } } #endif // GM_USE_OGG else { ERR( "Audio File %s.\n", oFileName.GetData() ); bLoadOk = false; } if( poABuffer && bLoadOk ) { m_oArrABuffer.Append( poABuffer ); NewFileEntry( pcFileName, poABuffer ); } else { DELETE_INSTANCE( poABuffer ); } } else { LOG( "Audio file skipped: %s.\n", pcFileName ); } return poABuffer; }
PPForestSZ<L>::~PPForestSZ() { DELETE_ARRAY(m_lml); DELETE_ARRAY(m_lb); DELETE_ARRAY(m_keyroot); }
PPForest<L>::~PPForest() { DELETE_ARRAY(m_lb); }
BadCharacterTable::~BadCharacterTable() { DELETE_ARRAY(minLengthCache); }
void PerfSocket::Recv_TCP( void ) { extern Mutex clients_mutex; extern Iperf_ListEntry *clients; // get the remote address and remove it later from the set of clients SocketAddr remote = getRemoteAddress(); iperf_sockaddr peer = *(iperf_sockaddr *) (remote.get_sockaddr()); // keep track of read sizes -> gives some indication of MTU size // on SGI this must be dynamically allocated to avoid seg faults int currLen; int *readLenCnt = new int[ mSettings->mBufLen+1 ]; for ( int i = 0; i <= mSettings->mBufLen; i++ ) { readLenCnt[ i ] = 0; } InitTransfer(); #ifndef WIN32 signal (SIGPIPE, SIG_IGN); #endif do { // perform read currLen = read( mSock, mBuf, mSettings->mBufLen ); if ( false ) { DELETE_ARRAY( readLenCnt ); Server_Send_TCP(); return; } mPacketTime.setnow(); // periodically report bandwidths ReportPeriodicBW(); mTotalLen += currLen; // count number of reads of each size if ( currLen <= mSettings->mBufLen ) { readLenCnt[ currLen ]++; } } while ( currLen > 0 && sInterupted == false ); // stop timing mEndTime.setnow(); sReporting.Lock(); ReportBW( mTotalLen, 0.0, mEndTime.subSec( mStartTime )); sReporting.Unlock(); if ( mSettings->mPrintMSS ) { // read the socket option for MSS (maximum segment size) ReportMSS( getsock_tcp_mss( mSock )); // on WANs the most common read length is often the MSS // on fast LANs it is much harder to detect int totalReads = 0; for ( currLen = 0; currLen < mSettings->mBufLen+1; currLen++ ) { totalReads += readLenCnt[ currLen ]; } // print each read length that occured > 5% of reads int thresh = (int) (0.05 * totalReads); printf( report_read_lengths, mSock ); for ( currLen = 0; currLen < mSettings->mBufLen+1; currLen++ ) { if ( readLenCnt[ currLen ] > thresh ) { printf( report_read_length_times, mSock, (int) currLen, readLenCnt[ currLen ], (100.0 * readLenCnt[ currLen ]) / totalReads ); } } } DELETE_ARRAY( readLenCnt ); clients_mutex.Lock(); Iperf_delete ( &peer, &clients ); clients_mutex.Unlock(); }
U_CDECL_BEGIN void readTestFile(const char *testFilePath, TestCaseCallback callback) { #if !UCONFIG_NO_REGULAR_EXPRESSIONS UErrorCode status = U_ZERO_ERROR; UXMLParser *parser = UXMLParser::createParser(status); UXMLElement *root = parser->parseFile(testFilePath, status); if (root == NULL) { log_err("Could not open the test data file: %s\n", testFilePath); delete parser; return; } UnicodeString test_case = UNICODE_STRING_SIMPLE("test-case"); UnicodeString test_text = UNICODE_STRING_SIMPLE("test-text"); UnicodeString test_font = UNICODE_STRING_SIMPLE("test-font"); UnicodeString result_glyphs = UNICODE_STRING_SIMPLE("result-glyphs"); UnicodeString result_indices = UNICODE_STRING_SIMPLE("result-indices"); UnicodeString result_positions = UNICODE_STRING_SIMPLE("result-positions"); // test-case attributes UnicodeString id_attr = UNICODE_STRING_SIMPLE("id"); UnicodeString script_attr = UNICODE_STRING_SIMPLE("script"); UnicodeString lang_attr = UNICODE_STRING_SIMPLE("lang"); // test-font attributes UnicodeString name_attr = UNICODE_STRING_SIMPLE("name"); UnicodeString ver_attr = UNICODE_STRING_SIMPLE("version"); UnicodeString cksum_attr = UNICODE_STRING_SIMPLE("checksum"); const UXMLElement *testCase; int32_t tc = 0; while((testCase = root->nextChildElement(tc)) != NULL) { if (testCase->getTagName().compare(test_case) == 0) { char *id = getCString(testCase->getAttribute(id_attr)); char *script = getCString(testCase->getAttribute(script_attr)); char *lang = getCString(testCase->getAttribute(lang_attr)); char *fontName = NULL; char *fontVer = NULL; char *fontCksum = NULL; const UXMLElement *element; int32_t ec = 0; int32_t charCount = 0; // int32_t typoFlags = 3; // kerning + ligatures... UScriptCode scriptCode; le_int32 languageCode = -1; UnicodeString text, glyphs, indices, positions; int32_t glyphCount = 0, indexCount = 0, positionCount = 0; TestResult expected = {0, NULL, NULL, NULL}; uscript_getCode(script, &scriptCode, 1, &status); if (LE_FAILURE(status)) { log_err("invalid script name: %s.\n", script); goto free_c_strings; } if (lang != NULL) { languageCode = getLanguageCode(lang); if (languageCode < 0) { log_err("invalid language name: %s.\n", lang); goto free_c_strings; } } while((element = testCase->nextChildElement(ec)) != NULL) { UnicodeString tag = element->getTagName(); // TODO: make sure that each element is only used once. if (tag.compare(test_font) == 0) { fontName = getCString(element->getAttribute(name_attr)); fontVer = getCString(element->getAttribute(ver_attr)); fontCksum = getCString(element->getAttribute(cksum_attr)); } else if (tag.compare(test_text) == 0) { text = element->getText(TRUE); charCount = text.length(); } else if (tag.compare(result_glyphs) == 0) { glyphs = element->getText(TRUE); } else if (tag.compare(result_indices) == 0) { indices = element->getText(TRUE); } else if (tag.compare(result_positions) == 0) { positions = element->getText(TRUE); } else { // an unknown tag... char *cTag = getCString(&tag); log_info("Test %s: unknown element with tag \"%s\"\n", id, cTag); freeCString(cTag); } } expected.glyphs = (LEGlyphID *) getHexArray(glyphs, glyphCount); expected.indices = (le_int32 *) getHexArray(indices, indexCount); expected.positions = getFloatArray(positions, positionCount); expected.glyphCount = glyphCount; if (glyphCount < charCount || indexCount != glyphCount || positionCount < glyphCount * 2 + 2) { log_err("Test %s: inconsistent input data: charCount = %d, glyphCount = %d, indexCount = %d, positionCount = %d\n", id, charCount, glyphCount, indexCount, positionCount); goto free_expected; }; (*callback)(id, fontName, fontVer, fontCksum, scriptCode, languageCode, text.getBuffer(), charCount, &expected); free_expected: DELETE_ARRAY(expected.positions); DELETE_ARRAY(expected.indices); DELETE_ARRAY(expected.glyphs); free_c_strings: freeCString(fontCksum); freeCString(fontVer); freeCString(fontName); freeCString(lang); freeCString(script); freeCString(id); } } delete root; delete parser; #endif }
bool HttpServer::methodGet(SocketClient &client) { std::string htmlBody; std::string docType; int docTypeSize = 0; bool exitRequest = false; // Parse what to get if (StringConverter::isRootFile(client.getMessage())) { const std::string HTML_MOVED = "<html>\r\n" \ "<head>\r\n" \ "<title>Page is moved</title>\r\n" \ "</head>\r\n" \ "<body>\r\n" \ "<h1>Moved</h1>\r\n" \ "<p>This page is moved:\r\n" \ "<a href=\"%s:%d%s\">link</a>.</p>\r\n" \ "</body>\r\n" \ "</html>"; StringConverter::addFormattedString(docType, HTML_MOVED.c_str(), _interface.getIPAddress().c_str(), _properties.getHttpPort(), "/index.html"); docTypeSize = docType.size(); getHtmlBodyWithContent(htmlBody, HTML_MOVED_PERMA, "/index.html", CONTENT_TYPE_XML, docTypeSize, 0); } else { std::string file; if (StringConverter::hasTransportParameters(client.getMessage())) { processStreamingRequest(client); } else if (StringConverter::getRequestedFile(client.getMessage(), file)) { // remove first '/' file.erase(0, 1); const std::string filePath = _properties.getWebPath() + "/" + file; if (file.compare("data.xml") == 0) { makeDataXML(docType); docTypeSize = docType.size(); getHtmlBodyWithContent(htmlBody, HTML_OK, file, CONTENT_TYPE_XML, docTypeSize, 0); } else if (file.compare("streams.xml") == 0) { makeStreamsXML(docType); docTypeSize = docType.size(); getHtmlBodyWithContent(htmlBody, HTML_OK, file, CONTENT_TYPE_XML, docTypeSize, 0); } else if (file.compare(_properties.getFileName()) == 0) { _properties.addToXML(docType); docTypeSize = docType.size(); getHtmlBodyWithContent(htmlBody, HTML_OK, file, CONTENT_TYPE_XML, docTypeSize, 0); #ifdef LIBDVBCSA } else if (file.compare(_streams.getDecrypt()->getFileName()) == 0) { _streams.getDecrypt()->addToXML(docType); docTypeSize = docType.size(); getHtmlBodyWithContent(htmlBody, HTML_OK, file, CONTENT_TYPE_XML, docTypeSize, 0); #endif } else if (file.compare("log.xml") == 0) { docType = make_log_xml(); docTypeSize = docType.size(); getHtmlBodyWithContent(htmlBody, HTML_OK, file, CONTENT_TYPE_XML, docTypeSize, 0); } else if (file.compare("STOP") == 0) { exitRequest = true; getHtmlBodyWithContent(htmlBody, HTML_NO_RESPONSE, "", CONTENT_TYPE_HTML, 0, 0); } else if ((docTypeSize = readFile(filePath.c_str(), docType))) { if (file.find(".xml") != std::string::npos) { // check if the request is the SAT>IP description xml then fill in the server version, UUID and tuner string if (docType.find("urn:ses-com:device") != std::string::npos) { SI_LOG_DEBUG("Client: %s requesed %s", client.getIPAddress().c_str(), file.c_str()); // check did we get our desc.xml (we assume there are some %s in there) if (docType.find("%s") != std::string::npos) { docTypeSize -= 4 * 2; // minus 4x %s docTypeSize += _properties.getDeliverySystemString().size(); docTypeSize += _properties.getUUID().size(); docTypeSize += _properties.getSoftwareVersion().size(); docTypeSize += _properties.getXSatipM3U().size(); char *doc_desc_xml = new char[docTypeSize + 1]; if (doc_desc_xml != nullptr) { snprintf(doc_desc_xml, docTypeSize + 1, docType.c_str(), _properties.getSoftwareVersion().c_str(), _properties.getUUID().c_str(), _properties.getDeliverySystemString().c_str(), _properties.getXSatipM3U().c_str()); docType = doc_desc_xml; DELETE_ARRAY(doc_desc_xml); } } } getHtmlBodyWithContent(htmlBody, HTML_OK, file, CONTENT_TYPE_XML, docTypeSize, 0); } else if (file.find(".html") != std::string::npos) { getHtmlBodyWithContent(htmlBody, HTML_OK, file, CONTENT_TYPE_HTML, docTypeSize, 0); } else if (file.find(".js") != std::string::npos) { getHtmlBodyWithContent(htmlBody, HTML_OK, file, CONTENT_TYPE_JS, docTypeSize, 0); } else if (file.find(".css") != std::string::npos) { getHtmlBodyWithContent(htmlBody, HTML_OK, file, CONTENT_TYPE_CSS, docTypeSize, 0); } else if (file.find(".m3u") != std::string::npos) { getHtmlBodyWithContent(htmlBody, HTML_OK, file, CONTENT_TYPE_VIDEO, docTypeSize, 0); } else if ((file.find(".png") != std::string::npos) || (file.find(".ico") != std::string::npos)) { getHtmlBodyWithContent(htmlBody, HTML_OK, file, CONTENT_TYPE_PNG, docTypeSize, 0); } else { getHtmlBodyWithContent(htmlBody, HTML_OK, file, CONTENT_TYPE_HTML, docTypeSize, 0); } } else { file = _properties.getWebPath() + "/" + "404.html"; docTypeSize = readFile(file.c_str(), docType); getHtmlBodyWithContent(htmlBody, HTML_NOT_FOUND, file, CONTENT_TYPE_HTML, docTypeSize, 0); } } } // send something? if (docType.size() > 0) { // SI_LOG_INFO("%s", htmlBody); // send 'htmlBody' to client if (send(client.getFD(), htmlBody.c_str(), htmlBody.size(), 0) == -1) { PERROR("send htmlBody"); return false; } // send 'docType' to client if (send(client.getFD(), docType.c_str(), docTypeSize, 0) == -1) { PERROR("send docType"); return false; } return true; } // check did we have stop request if (exitRequest) { _properties.setExitApplication(); } return false; }
void CMeshRenderer::Free ( void ) { int i = 0; for ( i = 0; i < nMatCount; i ++ ) { m_ppTB[i]->Release(); m_ppTB[i] = NULL; } for ( i = 0; i < nObjCount; i ++ ) { m_ppVB[i]->Release(); m_ppIB[i]->Release(); m_ppVB[i] = NULL; m_ppIB[i] = NULL; } DELETE_ARRAY( m_ppTB ); DELETE_ARRAY( m_ppVB ); DELETE_ARRAY( m_ppIB ); DELETE_ARRAY( m_pnMatID ); DELETE_ARRAY( m_pnVNum ); DELETE_ARRAY( m_pnINum ); DELETE_ARRAY( m_pmMatrix ); DELETE_ARRAY( m_pvPivot ); DELETE_ARRAY( m_pvPos ); DELETE_ARRAY( m_pvRot ); DELETE_ARRAY( m_pvScl ); }
RCEBuffer::~RCEBuffer() { if (buffer != defaultBuffer) { DELETE_ARRAY(buffer); } }
GoodSuffixTable::GoodSuffixTable(CEList &patternCEs, BadCharacterTable &badCharacterTable, UErrorCode &status) : goodSuffixTable(NULL) { int32_t patlen = patternCEs.size(); // **** need a better way to deal with this **** if (U_FAILURE(status) || patlen <= 0) { return; } int32_t *suff = NEW_ARRAY(int32_t, patlen); int32_t start = patlen - 1, end = - 1; int32_t maxSkip = badCharacterTable.getMaxSkip(); if (suff == NULL) { status = U_MEMORY_ALLOCATION_ERROR; return; } // initialze suff suff[patlen - 1] = patlen; for (int32_t i = patlen - 2; i >= 0; i -= 1) { // (i > start) means we're inside the last suffix match we found // ((patlen - 1) - end) is how far the end of that match is from end of pattern // (i - start) is how far we are from start of that match // (i + (patlen - 1) - end) is index of same character at end of pattern // so if any suffix match at that character doesn't extend beyond the last match, // it's the suffix for this character as well if (i > start && suff[i + patlen - 1 - end] < i - start) { suff[i] = suff[i + patlen - 1 - end]; } else { start = end = i; int32_t s = patlen; while (start >= 0 && patternCEs[start] == patternCEs[--s]) { start -= 1; } suff[i] = end - start; } } // now build goodSuffixTable goodSuffixTable = NEW_ARRAY(int32_t, patlen); if (goodSuffixTable == NULL) { DELETE_ARRAY(suff); status = U_MEMORY_ALLOCATION_ERROR; return; } // initialize entries to minLengthInChars of the pattern for (int32_t i = 0; i < patlen; i += 1) { goodSuffixTable[i] = maxSkip; } int32_t prefix = 0; for (int32_t i = patlen - /*1*/ 2; i >= 0; i -= 1) { if (suff[i] == i + 1) { // this matching suffix is a prefix of the pattern int32_t prefixSkip = badCharacterTable.minLengthInChars(i + 1); // for any mis-match before this suffix, we should skip // so that the front of the pattern (i.e. the prefix) // lines up with the front of the suffix. // (patlen - 1 - i) is the start of the suffix while (prefix < patlen - 1 - i) { // value of maxSkip means never set... if (goodSuffixTable[prefix] == maxSkip) { goodSuffixTable[prefix] = prefixSkip; } prefix += 1; } } } for (int32_t i = 0; i < patlen - 1; i += 1) { goodSuffixTable[patlen - 1 - suff[i]] = badCharacterTable.minLengthInChars(i + 1); } DELETE_ARRAY(suff); }
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; Context *context; static le_int32 windowCount = 0; static fm_fontMap *fontMap = NULL; static rs_surface *surface = NULL; static gs_guiSupport *guiSupport = NULL; static le_font *font = NULL; switch (message) { case WM_CREATE: { LEErrorCode fontStatus = LE_NO_ERROR; hdc = GetDC(hwnd); guiSupport = gs_gdiGuiSupportOpen(); surface = rs_gdiRenderingSurfaceOpen(hdc); fontMap = fm_gdiFontMapOpen(surface, "FontMap.GDI", 24, guiSupport, &fontStatus); font = le_scriptCompositeFontOpen(fontMap); if (LE_FAILURE(fontStatus)) { ReleaseDC(hwnd, hdc); return -1; } context = NEW_ARRAY(Context, 1); context->width = 600; context->height = 400; context->paragraph = pf_factory("Sample.txt", font, guiSupport); SetWindowLongPtr(hwnd, 0, (LONG_PTR) context); windowCount += 1; ReleaseDC(hwnd, hdc); PrettyTitle(hwnd, "Sample.txt"); return 0; } case WM_SIZE: { context = (Context *) GetWindowLongPtr(hwnd, 0); context->width = LOWORD(lParam); context->height = HIWORD(lParam); InitParagraph(hwnd, context); return 0; } case WM_VSCROLL: { SCROLLINFO si; le_int32 vertPos; si.cbSize = sizeof si; si.fMask = SIF_ALL; GetScrollInfo(hwnd, SB_VERT, &si); vertPos = si.nPos; switch (LOWORD(wParam)) { case SB_TOP: si.nPos = si.nMin; break; case SB_BOTTOM: si.nPos = si.nMax; break; case SB_LINEUP: si.nPos -= 1; break; case SB_LINEDOWN: si.nPos += 1; break; case SB_PAGEUP: si.nPos -= si.nPage; break; case SB_PAGEDOWN: si.nPos += si.nPage; break; case SB_THUMBTRACK: si.nPos = si.nTrackPos; break; default: break; } si.fMask = SIF_POS; SetScrollInfo(hwnd, SB_VERT, &si, TRUE); GetScrollInfo(hwnd, SB_VERT, &si); context = (Context *) GetWindowLongPtr(hwnd, 0); if (context->paragraph != NULL && si.nPos != vertPos) { ScrollWindow(hwnd, 0, pf_getLineHeight(context->paragraph) * (vertPos - si.nPos), NULL, NULL); UpdateWindow(hwnd); } return 0; } case WM_PAINT: { PAINTSTRUCT ps; SCROLLINFO si; le_int32 firstLine, lastLine; hdc = BeginPaint(hwnd, &ps); SetBkMode(hdc, TRANSPARENT); si.cbSize = sizeof si; si.fMask = SIF_ALL; GetScrollInfo(hwnd, SB_VERT, &si); firstLine = si.nPos; context = (Context *) GetWindowLongPtr(hwnd, 0); if (context->paragraph != NULL) { rs_gdiRenderingSurfaceSetHDC(surface, hdc); // NOTE: si.nPos + si.nPage may include a partial line at the bottom // of the window. We need this because scrolling assumes that the // partial line has been painted. lastLine = min (si.nPos + (le_int32) si.nPage, pf_getLineCount(context->paragraph) - 1); pf_draw(context->paragraph, surface, firstLine, lastLine); } EndPaint(hwnd, &ps); return 0; } case WM_COMMAND: switch (LOWORD(wParam)) { case IDM_FILE_OPEN: { OPENFILENAMEA ofn; char szFileName[MAX_PATH], szTitleName[MAX_PATH]; static char szFilter[] = "Text Files (.txt)\0*.txt\0" "All Files (*.*)\0*.*\0\0"; ofn.lStructSize = sizeof (OPENFILENAMEA); ofn.hwndOwner = hwnd; ofn.hInstance = NULL; ofn.lpstrFilter = szFilter; ofn.lpstrCustomFilter = NULL; ofn.nMaxCustFilter = 0; ofn.nFilterIndex = 0; ofn.lpstrFile = szFileName; ofn.nMaxFile = MAX_PATH; ofn.lpstrFileTitle = szTitleName; ofn.nMaxFileTitle = MAX_PATH; ofn.lpstrInitialDir = NULL; ofn.lpstrTitle = NULL; ofn.Flags = OFN_HIDEREADONLY | OFN_PATHMUSTEXIST; ofn.nFileOffset = 0; ofn.nFileExtension = 0; ofn.lpstrDefExt = "txt"; ofn.lCustData = 0L; ofn.lpfnHook = NULL; ofn.lpTemplateName = NULL; szFileName[0] = '\0'; if (GetOpenFileNameA(&ofn)) { pf_flow *newParagraph; hdc = GetDC(hwnd); rs_gdiRenderingSurfaceSetHDC(surface, hdc); newParagraph = pf_factory(szFileName, font, guiSupport); if (newParagraph != NULL) { context = (Context *) GetWindowLongPtr(hwnd, 0); if (context->paragraph != NULL) { pf_close(context->paragraph); } context->paragraph = newParagraph; InitParagraph(hwnd, context); PrettyTitle(hwnd, szTitleName); InvalidateRect(hwnd, NULL, TRUE); } } //ReleaseDC(hwnd, hdc); return 0; } case IDM_FILE_EXIT: case IDM_FILE_CLOSE: SendMessage(hwnd, WM_CLOSE, 0, 0); return 0; case IDM_HELP_ABOUTLAYOUTSAMPLE: MessageBox(hwnd, TEXT("Windows Layout Sample 0.1\n") TEXT("Copyright (C) 2016 and later: Unicode, Inc. and others. License & terms of use: http://www.unicode.org/copyright.html\n") TEXT("Author: Eric Mader"), szAppName, MB_ICONINFORMATION | MB_OK); return 0; } break; case WM_DESTROY: { context = (Context *) GetWindowLongPtr(hwnd, 0); if (context != NULL && context->paragraph != NULL) { pf_close(context->paragraph); } DELETE_ARRAY(context); if (--windowCount <= 0) { le_fontClose(font); rs_gdiRenderingSurfaceClose(surface); gs_gdiGuiSupportClose(guiSupport); PostQuitMessage(0); } return 0; } default: return DefWindowProc(hwnd, message, wParam, lParam); } return 0; }
GoodSuffixTable::~GoodSuffixTable() { DELETE_ARRAY(goodSuffixTable); }
U_CDECL_END U_NAMESPACE_BEGIN void CharsetDetector::setRecognizers(UErrorCode &status) { UBool needsInit; CharsetRecognizer **recognizers; if (U_FAILURE(status)) { return; } umtx_lock(NULL); needsInit = (UBool) (fCSRecognizers == NULL); umtx_unlock(NULL); if (needsInit) { CharsetRecognizer *tempArray[] = { new CharsetRecog_UTF8(), new CharsetRecog_UTF_16_BE(), new CharsetRecog_UTF_16_LE(), new CharsetRecog_UTF_32_BE(), new CharsetRecog_UTF_32_LE(), new CharsetRecog_8859_1_en(), new CharsetRecog_8859_1_da(), new CharsetRecog_8859_1_de(), new CharsetRecog_8859_1_es(), new CharsetRecog_8859_1_fr(), new CharsetRecog_8859_1_it(), new CharsetRecog_8859_1_nl(), new CharsetRecog_8859_1_no(), new CharsetRecog_8859_1_pt(), new CharsetRecog_8859_1_sv(), new CharsetRecog_8859_2_cs(), new CharsetRecog_8859_2_hu(), new CharsetRecog_8859_2_pl(), new CharsetRecog_8859_2_ro(), new CharsetRecog_8859_5_ru(), new CharsetRecog_8859_6_ar(), new CharsetRecog_8859_7_el(), new CharsetRecog_8859_8_I_he(), new CharsetRecog_8859_8_he(), new CharsetRecog_windows_1251(), new CharsetRecog_windows_1256(), new CharsetRecog_KOI8_R(), new CharsetRecog_8859_9_tr(), new CharsetRecog_sjis(), new CharsetRecog_gb_18030(), new CharsetRecog_euc_jp(), new CharsetRecog_euc_kr(), new CharsetRecog_big5(), new CharsetRecog_2022JP(), new CharsetRecog_2022KR(), new CharsetRecog_2022CN() }; int32_t rCount = ARRAY_SIZE(tempArray); int32_t r; recognizers = NEW_ARRAY(CharsetRecognizer *, rCount); if (recognizers == NULL) { status = U_MEMORY_ALLOCATION_ERROR; } else { for (r = 0; r < rCount; r += 1) { recognizers[r] = tempArray[r]; if (recognizers[r] == NULL) { status = U_MEMORY_ALLOCATION_ERROR; break; } } } if (U_SUCCESS(status)) { umtx_lock(NULL); if (fCSRecognizers == NULL) { fCSRecognizers = recognizers; fCSRecognizers_size = rCount; } umtx_unlock(NULL); } if (fCSRecognizers != recognizers) { for (r = 0; r < rCount; r += 1) { delete recognizers[r]; recognizers[r] = NULL; } DELETE_ARRAY(recognizers); } recognizers = NULL; ucln_i18n_registerCleanup(UCLN_I18N_CSDET, csdet_cleanup); } }
PerfSocket::~PerfSocket() { DELETE_ARRAY( mBuf ); DELETE_PTR( extractor ); }
InputText::~InputText() { DELETE_ARRAY(fDeclaredEncoding); DELETE_ARRAY(fByteStats); DELETE_ARRAY(fInputBytes); }
void tagSTJ1939_MSG::vClear(void) { m_sMsgProperties.m_eType = MSG_TYPE_NONE; m_unDLC = 0; DELETE_ARRAY(m_pbyData); }
CEList::~CEList() { if (ces != ceBuffer) { DELETE_ARRAY(ces); } }
tagFormattedData_J1939::~tagFormattedData_J1939() { DELETE_ARRAY(m_pcDataHex); DELETE_ARRAY(m_pcDataDec); }
//--------------------------------------------------------- template <class T> double * CSG_mRMR::Get_JointProb(T * img1, T * img2, long len, long maxstatenum, int &nstate1, int &nstate2) { long i, j; //----------------------------------------------------- // get and check size information if (!img1 || !img2 || len < 0) { SG_UI_Msg_Add_Error("At least one of the input vectors is invalid."); return( NULL ); } int b_findstatenum = 1; // int nstate1 = 0, nstate2 = 0; int b_returnprob = 1; //----------------------------------------------------- // copy data into new INT type array (hence quantization) and then reange them begin from 0 (i.e. state1) int *vec1 = new int[len]; int *vec2 = new int[len]; if( !vec1 || !vec2 ) { SG_UI_Msg_Add_Error("Fail to allocate memory.\n"); return( NULL ); } int nrealstate1 = 0, nrealstate2 = 0; Copy_Vector(img1, len, vec1, nrealstate1); Copy_Vector(img2, len, vec2, nrealstate2); //update the #state when necessary nstate1 = (nstate1 < nrealstate1) ? nrealstate1 : nstate1; //printf("First vector #state = %i\n",nrealstate1); nstate2 = (nstate2 < nrealstate2) ? nrealstate2 : nstate2; //printf("Second vector #state = %i\n",nrealstate2); // if (nstate1!=maxstatenum || nstate2!=maxstatenum) // printf("find nstate1=%d nstate2=%d\n", nstate1, nstate2); //----------------------------------------------------- // generate the joint-distribution table double *hab = new double[nstate1 * nstate2]; double **hab2d = new double *[nstate2]; if( !hab || !hab2d ) { SG_UI_Msg_Add_Error("Fail to allocate memory."); return( NULL ); } for(j=0; j<nstate2; j++) { hab2d[j] = hab + (long)j * nstate1; } for(i=0; i<nstate1; i++) { for(j=0; j<nstate2; j++) { hab2d[j][i] = 0; } } for(i=0; i<len; i++) { // old method -- slow // indx = (long)(vec2[i]) * nstate1 + vec1[i]; // hab[indx] += 1; // new method -- fast hab2d[vec2[i]][vec1[i]] += 1; //printf("vec2[%d]=%d vec1[%d]=%d\n", i, vec2[i], i, vec1[i]); } //----------------------------------------------------- // return the probabilities, otherwise return count numbers if( b_returnprob ) { for(i=0; i<nstate1; i++) { for(j=0; j<nstate2; j++) { hab2d[j][i] /= len; } } } //----------------------------------------------------- // finish DELETE_ARRAY(hab2d); DELETE_ARRAY(vec1); DELETE_ARRAY(vec2); return hab; }
LRESULT CALLBACK winproc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { MENUITEMINFO mii; HMENU hMenu = GetMenu(hWnd); OPENFILENAME ofn; char path[MAX_PATH]; HCURSOR hcur; switch (uMsg) { case WM_COMMAND: switch (LOWORD(wParam)) { case ID_MENU_FILE_OPEN: // wczytywanie pliku memset(&ofn, 0, sizeof(ofn)); memset(path, 0, MAX_PATH); ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = hWnd; ofn.lpstrFile = path; ofn.nMaxFile = MAX_PATH; ofn.lpstrFilter = "3D Studio R4 (*.3ds)\0*.3ds\0\0"; ofn.lpstrTitle = NULL; ofn.Flags = OFN_EXPLORER | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; ofn.lpstrInitialDir = ".\\"; if (::GetOpenFileName(&ofn)) { CLoader3DS load_3ds(g_Scene); hcur = ::SetCursor(LoadCursor(NULL, IDC_WAIT)); load_3ds.Load(path); if (!g_Scene.SetActiveCamera("Camera01")) g_Scene.SetFirstCamera(); ::SetCursor(hcur); /// ustaw odpowiednio menu systemowe: ::ZeroMemory(&mii, sizeof(mii)); mii.cbSize = sizeof(mii); mii.fMask = MIIM_STATE; mii.fState = MFS_ENABLED; ::SetMenuItemInfo(hMenu, ID_MENU_VIEW_ANIMATION, FALSE, &mii); ::SetMenuItemInfo(hMenu, ID_MENU_FILE_CLOSE, FALSE, &mii); /// dopisz do titlebar'u nazwê otwartego pliku: char *foo = new char [strlen(g_lpszNoFileProgName) + strlen(path + ofn.nFileOffset) + 4]; strcpy(foo, g_lpszNoFileProgName); strcat(foo, " - "); strcat(foo, path + ofn.nFileOffset); DELETE_ARRAY(g_lpszProgName); g_lpszProgName = foo; ::SetWindowText(hWnd, g_lpszProgName); /// tutaj poœrednio ustawienie odpowiednie nazwu dla okienka z animacj¹: DELETE_ARRAY(g_WindowParams.szTitle); g_WindowParams.szTitle = strdup(path + ofn.nFileOffset); } break; case ID_MENU_FILE_CLOSE: { g_Scene.Release(); /// wygaœ odpowiednie opcje w menu: ZeroMemory(&mii, sizeof(mii)); mii.cbSize = sizeof(mii); mii.fMask = MIIM_STATE; mii.fState = MFS_GRAYED; ::SetMenuItemInfo(hMenu, ID_MENU_VIEW_ANIMATION, FALSE, &mii); ::SetMenuItemInfo(hMenu, ID_MENU_FILE_CLOSE, FALSE, &mii); /// umieœæ w titlebarze sam¹ nazwê aplikacji: DELETE_ARRAY(g_lpszProgName); g_lpszProgName = strdup(g_lpszNoFileProgName); ::SetWindowText(hWnd, g_lpszProgName); } break; case ID_MENU_FILE_EXIT: g_Scene.Release(); ::SendMessage(hWnd, WM_CLOSE, 0, 0); break; case ID_MENU_VIEW_ANIMATION: { if (!DialogBox(g_hInstance, MAKEINTRESOURCE(IDD_DIALOG1), MainhWnd, (DLGPROC)SetupDlgProc)) return 0; if (g_WindowParams.szTitle == NULL) g_WindowParams.szTitle = strdup("test"); g_WindowParams.lpfnProc = MainWndProc; g_WindowParams.hInst = g_hInstance; try { if (!g_Scene.SetActiveCamera("Camera01")) g_Scene.SetFirstCamera(); ::EnableWindow(hWnd, FALSE); InitOpenGL(g_WindowParams, hWnd); g_Scene.SetScreenAspect((float)g_WindowParams.nWidth/g_WindowParams.nHeight); //g_Scene.PrintInfo(LOG); g_Scene.PrepareAnimation(); g_Scene.InitTextures(); g_Scene.InitDisplayLists(); PlayAnimation(); g_Scene.DeinitDisplayLists(); g_Scene.DeinitTextures(); DeInitOpenGL(g_WindowParams); ::EnableWindow(hWnd, TRUE); ::SetActiveWindow(hWnd); } catch (CException ex) { if (ex.type == CException::EXCEPTION_STRING) { static char *error_msg = strdup(ex.error_string); fatal_error(error_msg); } else { char buffer[10]; _itoa(ex.error, buffer, 10); fatal_error(buffer); } } catch (...) { fatal_error("Unknown error!"); } } break; case ID_MENU_HELP_ABOUT: ::DialogBox(g_hInstance, MAKEINTRESOURCE(IDD_ABOUTBOX), MainhWnd, (DLGPROC)AboutDlgProc); break; default: break; } break; case WM_DESTROY: ::PostQuitMessage(0); break; case WM_CREATE: ZeroMemory(&mii, sizeof(mii)); mii.cbSize = sizeof(mii); mii.fMask = MIIM_STATE; mii.fState = MFS_GRAYED; ::SetMenuItemInfo(hMenu, ID_MENU_VIEW_ANIMATION, FALSE, &mii); ::SetMenuItemInfo(hMenu, ID_MENU_FILE_CLOSE, FALSE, &mii); break; default: return ::DefWindowProc(hWnd, uMsg, wParam, lParam); break; } return 0; }