void split(StringVector& v, const String& s, const String& separator) { String sTmp(s); char *p = NULL; const char *sep = separator.c_str(); char *tokenHelper = NULL; p = strtok_s( const_cast<char*>(sTmp.c_str()), sep, &tokenHelper); while (p != NULL) { v.push_back(p); p = strtok_s( NULL, sep, &tokenHelper); } }
void DrawEllipsisText(CDC& dc,LPCTSTR sText,int n,LPRECT prc,bool bHorizontal) { assert(n>0); long width=bHorizontal ? prc->right - prc->left : prc->bottom - prc->top; CSize size; LPTSTR sTmp=0; bool bRes=(GetTextExtentPoint32(dc, sText, n,&size)!=FALSE); assert(bRes); if(width<size.cx) { LPCTSTR sEllipsis=_T("..."); int ellipsisLen = 3; CString sTmp(sEllipsis); sTmp.Append(sText, n); bRes=(GetTextExtentExPoint(dc,sTmp,sTmp.GetLength(),width,&n,NULL,&size)!=FALSE); if(bRes) { if(n<ellipsisLen+1) n=ellipsisLen+1; sTmp.SetString(sTmp, n-ellipsisLen); sTmp += sEllipsis; sText=sTmp; } } // UINT prevAlign=dc.SetTextAlign(TA_LEFT | TA_TOP | TA_NOUPDATECP); CPoint pt(prc->left,prc->top); if(bHorizontal) pt.y = (prc->bottom - prc->top-size.cy)/2+prc->top; else pt.x = prc->right-(prc->right - prc->left-size.cy)/2; dc.ExtTextOut(pt.x,pt.y,ETO_CLIPPED,prc,sText,n,NULL); // dc.SetTextAlign(prevAlign); delete [] sTmp; }
void ScriptEditorDialog::OnCheckSyntax() { int iAllocLen = ::GetWindowTextLength(m_hWndWindowItems[REDT_SCRIPT]); char * sBuf = (char *)malloc(iAllocLen+1); if(sBuf == nullptr) { ::MessageBox(m_hWndWindowItems[WINDOW_HANDLE], LanguageManager::m_Ptr->m_sTexts[LAN_FAILED_TO_CHECK_SYNTAX], LanguageManager::m_Ptr->m_sTexts[LAN_ERROR], MB_OK); return; } ::GetWindowText(m_hWndWindowItems[REDT_SCRIPT], sBuf, iAllocLen+1); lua_State * L = lua_newstate(LuaAlocator, nullptr); if(L == nullptr) { free(sBuf); ::MessageBox(m_hWndWindowItems[WINDOW_HANDLE], LanguageManager::m_Ptr->m_sTexts[LAN_FAILED_TO_CHECK_SYNTAX], LanguageManager::m_Ptr->m_sTexts[LAN_ERROR], MB_OK); return; } luaL_openlibs(L); if(ServerManager::m_bServerRunning == true) { #if LUA_VERSION_NUM > 501 luaL_requiref(L, "Core", RegCore, 1); lua_pop(L, 1); luaL_requiref(L, "SetMan", RegSetMan, 1); lua_pop(L, 1); luaL_requiref(L, "RegMan", RegRegMan, 1); lua_pop(L, 1); luaL_requiref(L, "BanMan", RegBanMan, 1); lua_pop(L, 1); luaL_requiref(L, "ProfMan", RegProfMan, 1); lua_pop(L, 1); luaL_requiref(L, "TmrMan", RegTmrMan, 1); lua_pop(L, 1); luaL_requiref(L, "UDPDbg", RegUDPDbg, 1); lua_pop(L, 1); luaL_requiref(L, "ScriptMan", RegScriptMan, 1); lua_pop(L, 1); luaL_requiref(L, "IP2Country", RegIP2Country, 1); lua_pop(L, 1); #else RegCore(L); RegSetMan(L); RegRegMan(L); RegBanMan(L); RegProfMan(L); RegTmrMan(L); RegUDPDbg(L); RegScriptMan(L); RegIP2Country(L); #endif } if(luaL_dostring(L, sBuf) == 0) { ::MessageBox(m_hWndWindowItems[WINDOW_HANDLE], LanguageManager::m_Ptr->m_sTexts[LAN_NO_SYNERR_IN_SCRIPT], g_sPtokaXTitle, MB_OK); lua_close(L); } else { size_t szLen = 0; char * stmp = (char*)lua_tolstring(L, -1, &szLen); string sTmp(LanguageManager::m_Ptr->m_sTexts[LAN_SYNTAX], (size_t)LanguageManager::m_Ptr->m_ui16TextsLens[LAN_SYNTAX]); sTmp += " "; sTmp += stmp; RichEditAppendText(MainWindowPageScripts::m_Ptr->m_hWndPageItems[MainWindowPageScripts::REDT_SCRIPTS_ERRORS], sTmp.c_str()); ::MessageBox(m_hWndWindowItems[WINDOW_HANDLE], sTmp.c_str(), LanguageManager::m_Ptr->m_sTexts[LAN_ERROR], MB_OK); lua_close(L); } free(sBuf); }
bool CProcessConfigReader::GetConfiguration(std::string sAppName, STRING_LIST &Params) { int nBrackets = 0; Params.clear(); Reset(); std::string sKey = "PROCESSCONFIG="+sAppName; if(GoTo(sKey)) { std::string sBracket = GetNextValidLine(); if(sBracket.find("{")==0) { nBrackets++; while(!GetFile()->eof()) { std::string sLine = GetNextValidLine(); MOOSRemoveChars(sLine," \t\r"); if(sLine.find("}")!=0) { #if(1) // jckerken 8-12-2004 // ignore if param = <empty string> std::string sTmp(sLine); std::string sTok = MOOSChomp(sTmp, "="); MOOSTrimWhiteSpace(sTok); // Handle potential whitespaces. MOOSTrimWhiteSpace(sTmp); if (sTok.size() > 0) { MOOSTrimWhiteSpace(sTmp); if (!sTmp.empty()) { Params.push_front(sTok+std::string("=")+sTmp); // Was: sLine } else if(sLine.find("[")!=std::string::npos || sLine.find("]")!=std::string::npos) { Params.push_front(sTok+std::string("=")+sTmp); // Was: sLine } } else { Params.push_front(sTok+std::string("=")+sTmp); // Was: sLine } #else Params.push_front(sLine); #endif } else { return true; } //quick error check - we don't allow nested { on single lines if(sLine.find("{")==0) { MOOSTrace("CProcessConfigReader::GetConfiguration() missing \"}\" syntax error in mission file\n"); } } } } return false; }
/*! * Fill the GUI tree with the styles as defined in the XP tree. */ void AP_UnixDialog_Stylist::_fillTree(void) { Stylist_tree * pStyleTree = getStyleTree(); if(pStyleTree == NULL) { updateDialog(); pStyleTree = getStyleTree(); } if(pStyleTree->getNumRows() == 0) { updateDialog(); pStyleTree = getStyleTree(); } UT_DEBUGMSG(("Number of rows of styles in document %d \n",pStyleTree->getNumRows())); if(m_wRenderer) { // g_object_unref (G_OBJECT (m_wRenderer)); gtk_widget_destroy (m_wStyleList); } GtkTreeIter iter; GtkTreeIter child_iter; GtkTreeSelection *sel; UT_sint32 row,col, page; m_wModel = gtk_tree_store_new (3, G_TYPE_STRING, G_TYPE_INT, G_TYPE_INT); page = 0; UT_UTF8String sTmp(""); for(row= 0; row < pStyleTree->getNumRows();row++) { gtk_tree_store_append (m_wModel, &iter, NULL); if(!pStyleTree->getNameOfRow(sTmp,row)) { UT_ASSERT(UT_SHOULD_NOT_HAPPEN); break; } if(pStyleTree->getNumCols(row) > 0) { xxx_UT_DEBUGMSG(("Adding Heading %s at row %d \n",sTmp.utf8_str(),row)); gtk_tree_store_set (m_wModel, &iter, 0, sTmp.utf8_str(), 1, row,2,0, -1); for(col =0 ; col < pStyleTree->getNumCols(row); col++) { gtk_tree_store_append (m_wModel, &child_iter, &iter); if(!pStyleTree->getStyleAtRowCol(sTmp,row,col)) { UT_ASSERT(UT_SHOULD_NOT_HAPPEN); break; } gtk_tree_store_set (m_wModel, &child_iter, 0, sTmp.utf8_str(), 1, row,2,col+1, -1); xxx_UT_DEBUGMSG(("Adding style %s at row %d col %d \n",sTmp.utf8_str(),row,col+1)); page++; } } else { xxx_UT_DEBUGMSG(("Adding style %s at row %d \n",sTmp.utf8_str(),row)); gtk_tree_store_set (m_wModel, &iter, 0, sTmp.utf8_str(), 1,row,2,0,-1); page++; } } // create a new treeview m_wStyleList = gtk_tree_view_new_with_model (GTK_TREE_MODEL (m_wModel)); g_object_unref (G_OBJECT (m_wModel)); gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (m_wStyleList), true); // get the current selection sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (m_wStyleList)); gtk_tree_selection_set_mode (sel, GTK_SELECTION_BROWSE); gtk_tree_selection_set_select_function (sel, tree_select_filter, NULL, NULL); const XAP_StringSet * pSS = m_pApp->getStringSet (); m_wRenderer = gtk_cell_renderer_text_new (); UT_UTF8String s; pSS->getValueUTF8(AP_STRING_ID_DLG_Stylist_Styles,s); gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (m_wStyleList), -1, s.utf8_str(), m_wRenderer, "text", 0, NULL); gtk_tree_view_collapse_all (GTK_TREE_VIEW (m_wStyleList)); gtk_container_add (GTK_CONTAINER (m_wStyleListContainer), m_wStyleList); g_signal_connect_after(G_OBJECT(m_wStyleList), "cursor-changed", G_CALLBACK(s_types_clicked), static_cast<gpointer>(this)); g_signal_connect_after(G_OBJECT(m_wStyleList), "row-activated", G_CALLBACK(s_types_dblclicked), static_cast<gpointer>(this)); gtk_widget_show_all(m_wStyleList); setStyleTreeChanged(false); }
/*! * Fill the GUI tree with the styles as defined in the XP tree. */ void AP_Win32Dialog_Stylist::_fillTree(void) { Stylist_tree * pStyleTree = getStyleTree(); if(pStyleTree == NULL) { updateDialog(); pStyleTree = getStyleTree(); } if(pStyleTree->getNumRows() == 0) { updateDialog(); pStyleTree = getStyleTree(); } UT_DEBUGMSG(("Number of rows of styles in document %d \n",pStyleTree->getNumRows())); HWND hTree = GetDlgItem(m_hWnd, AP_RID_DIALOG_STYLIST_TREE_STYLIST); // Purge any existing TreeView items TreeView_DeleteAllItems(hTree); TV_ITEM tvi; TV_INSERTSTRUCT tvins; HTREEITEM hParentItem; // Parent handle to link Styles to their Heading tvi.mask = TVIF_TEXT | TVIF_PARAM | TVIF_CHILDREN; tvi.stateMask =0; UT_sint32 row, col; UT_UTF8String sTmp(""), str_loc; UT_String str; //int iter = 0; // Unique key for each item in the treeview for(row= 0; row < pStyleTree->getNumRows(); row++) { if(!pStyleTree->getNameOfRow(sTmp,row)) { UT_ASSERT_HARMLESS(UT_SHOULD_NOT_HAPPEN); break; } pt_PieceTable::s_getLocalisedStyleName (sTmp.utf8_str(), str_loc); str = AP_Win32App::s_fromUTF8ToWinLocale (str_loc.utf8_str()); xxx_UT_DEBUGMSG(("Adding Heading %s at row %d \n",sTmp.utf8_str(),row)); // Insert the item into the treeview tvi.pszText = (LPTSTR)str.c_str(); tvi.cchTextMax = str.length() + 1; tvi.lParam = row; if (pStyleTree->getNumCols(row) > 0) tvi.cChildren = 1; else tvi.cChildren = 0; tvins.item = tvi; tvins.hParent = TVI_ROOT; tvins.hInsertAfter = TVI_LAST; hParentItem = TreeView_InsertItem(hTree, &tvins); // Add any children (columns) this row contains to be added if (pStyleTree->getNumCols(row) > 0) { for(col = 0; col < pStyleTree->getNumCols(row); col++) { if(!pStyleTree->getStyleAtRowCol(sTmp,row,col)) { UT_ASSERT_HARMLESS(UT_SHOULD_NOT_HAPPEN); break; } xxx_UT_DEBUGMSG(("Adding style %s at row %d col %d \n",sTmp.utf8_str(),row,col+1)); pt_PieceTable::s_getLocalisedStyleName (sTmp.utf8_str(), str_loc); str = AP_Win32App::s_fromUTF8ToWinLocale (str_loc.utf8_str()); // Insert the item into the treeview tvi.pszText = (LPTSTR)str.c_str(); tvi.cchTextMax = str.length() + 1; tvi.cChildren = 0; tvi.lParam = col; tvins.item = tvi; tvins.hParent = hParentItem; tvins.hInsertAfter = TVI_LAST; TreeView_InsertItem(hTree, &tvins); } } } setStyleTreeChanged(false); }
void XMLCALL KML::endElement(void* pUserData, const char* pszName) { KMLNode* poTmp = NULL; KML* poKML = (KML*) pUserData; poKML->nWithoutEventCounter = 0; if(poKML->poCurrent_ != NULL && poKML->poCurrent_->getName().compare(pszName) == 0) { poKML->nDepth_--; poTmp = poKML->poCurrent_; // Split the coordinates if(poKML->poCurrent_->getName().compare("coordinates") == 0 && poKML->poCurrent_->numContent() == 1) { std::string sData = poKML->poCurrent_->getContent(0); std::size_t nPos = 0; std::size_t nLength = sData.length(); const char* pszData = sData.c_str(); while(TRUE) { // Cut off whitespaces while(nPos < nLength && (pszData[nPos] == ' ' || pszData[nPos] == '\n' || pszData[nPos] == '\r' || pszData[nPos] == '\t' )) nPos ++; if (nPos == nLength) break; std::size_t nPosBegin = nPos; // Get content while(nPos < nLength && pszData[nPos] != ' ' && pszData[nPos] != '\n' && pszData[nPos] != '\r' && pszData[nPos] != '\t') nPos++; if(nPos - nPosBegin > 0) { std::string sTmp(pszData + nPosBegin, nPos - nPosBegin); poKML->poCurrent_->addContent(sTmp); } } if(poKML->poCurrent_->numContent() > 1) poKML->poCurrent_->deleteContent(0); } else if (poKML->poCurrent_->numContent() == 1) { std::string sData = poKML->poCurrent_->getContent(0); std::string sDataWithoutNL; std::size_t nPos = 0; std::size_t nLength = sData.length(); const char* pszData = sData.c_str(); std::size_t nLineStartPos = 0; int bLineStart = TRUE; /* Re-assemble multi-line content by removing leading spaces for each line */ /* I'm not sure why we do that. Shouldn't we preserve content as such ? */ while(nPos < nLength) { char ch = pszData[nPos]; if (bLineStart && (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r')) nLineStartPos ++; else if (ch == '\n' || ch == '\r') { if (!bLineStart) { std::string sTmp(pszData + nLineStartPos, nPos - nLineStartPos); if (sDataWithoutNL.size() > 0) sDataWithoutNL += " "; sDataWithoutNL += sTmp; bLineStart = TRUE; } nLineStartPos = nPos + 1; } else { bLineStart = FALSE; } nPos ++; } if (nLineStartPos > 0) { if (nLineStartPos < nPos) { std::string sTmp(pszData + nLineStartPos, nPos - nLineStartPos); if (sDataWithoutNL.size() > 0) sDataWithoutNL += " "; sDataWithoutNL += sTmp; } poKML->poCurrent_->deleteContent(0); poKML->poCurrent_->addContent(sDataWithoutNL); } } if(poKML->poCurrent_->getParent() != NULL) poKML->poCurrent_ = poKML->poCurrent_->getParent(); else poKML->poCurrent_ = NULL; if(!poKML->isHandled(pszName)) { CPLDebug("KML", "Not handled: %s", pszName); delete poTmp; } else { if(poKML->poCurrent_ != NULL) poKML->poCurrent_->addChildren(poTmp); } } else if(poKML->poCurrent_ != NULL) { std::string sNewContent = "</"; sNewContent += pszName; sNewContent += ">"; if(poKML->poCurrent_->numContent() == 0) poKML->poCurrent_->addContent(sNewContent); else poKML->poCurrent_->appendContent(sNewContent); } }