void readNet(gpointer data, gint source, GdkInputCondition condition){ /// !!!! tlogin muss beim telnet Init auf false gesetzt werden. static guchar netInput[BUFFER_SIZE]; static guchar ttyOut [BUFFER_SIZE]; gint c; ttyOut[0]=0; c = recv(net, netInput, BUFFER_SIZE, 0); netInput[c]=0; telrcv(netInput, &ttyOut[0]); netflush(); telnetText(ttyOut); // login - procedure. if(t_login == FALSE){ if(strFind(ttyOut, STR_USER)){ sprintf(ttyOut, "%s\n", gtk_entry_get_text(GTK_ENTRY(MW_GET("OPT_NET_USER")))); send(net, ttyOut, strlen(ttyOut), 0); telnetText(ttyOut); } if(strFind(ttyOut, STR_PASS)){ int pos=0; sprintf(ttyOut, "%s\n", gtk_entry_get_text(GTK_ENTRY(MW_GET("OPT_NET_PASS")))); send(net, ttyOut, strlen(ttyOut), 0); while(ttyOut[pos]!='\n') ttyOut[pos++]='*'; telnetText(ttyOut); } if(strFind(ttyOut, STR_LOGIN)) t_login=TRUE; } }
ALERROR CAdventureDesc::OnCreateFromXML (SDesignLoadCtx &Ctx, CXMLElement *pDesc) // OnCreateFromXML // // Load from XML { ALERROR error; // If we are part of the default resource, then get the adventure UNID if (Ctx.pExtension == NULL) { m_dwExtensionUNID = pDesc->GetAttributeInteger(ADVENTURE_UNID_ATTRIB); m_fInDefaultResource = true; } // Otherwise, we remember the extension that we were loaded from else { m_dwExtensionUNID = Ctx.pExtension->dwUNID; m_fInDefaultResource = false; } // Load the name, etc m_sName = pDesc->GetAttribute(NAME_ATTRIB); m_dwBackgroundUNID = ::LoadUNID(Ctx, pDesc->GetAttribute(BACKGROUND_ID_ATTRIB)); // Starting ship criteria CString sCriteria; if (!pDesc->FindAttribute(STARTING_SHIP_CRITERIA_ATTRIB, &sCriteria)) sCriteria = CONSTLIT("*"); if (error = CDesignTypeCriteria::ParseCriteria(sCriteria, &m_StartingShips)) return ComposeLoadError(Ctx, ERR_STARTING_SHIP_CRITERIA); // Starting position m_sStartingNodeID = pDesc->GetAttribute(STARTING_SYSTEM_ATTRIB); m_sStartingPos = pDesc->GetAttribute(STARTING_POS_ATTRIB); // Welcome message if (!pDesc->FindAttribute(WELCOME_MESSAGE_ATTRIB, &m_sWelcomeMessage)) m_sWelcomeMessage = CONSTLIT("Welcome to Transcendence!"); // Init some flags m_fIsCurrentAdventure = false; // If the extension doesn't have a name, then we can set it if (Ctx.pExtension && strFind(Ctx.pExtension->sName, CONSTLIT("Extension")) == 0) Ctx.pExtension->sName = m_sName; return NOERROR; }
void CSystemCreateStats::AddLabel (const CString &sAttributes) // AddLabel // // Adds the attributes for the label { #ifdef DEBUG if (strFind(sAttributes, CONSTLIT("outerSystem")) != -1 && strFind(sAttributes, CONSTLIT("innerSystem")) != -1) g_pUniverse->DebugOutput("ERROR: %s", sAttributes.GetASCIIZPointer()); #endif if (m_PermuteAttribs.GetCount() > 0) AddLabelExpansion(sAttributes); else AddLabelAttributes(sAttributes); m_iLabelCount++; }
ICCItem *fnStrFind (CEvalContext *pCtx, ICCItem *pArgs, DWORD dwData) // fnStrFind // // Finds a string in some text { CCodeChain *pCC = pCtx->pCC; int iPos = strFind(pArgs->GetElement(0)->GetStringValue(), pArgs->GetElement(1)->GetStringValue()); if (iPos == -1) return pCC->CreateNil(); else return pCC->CreateInteger(iPos); }
ICCItem *fnFind (CEvalContext *pCtx, ICCItem *pArgs, DWORD dwData) // fnFind // // Finds a target in a source { int i; CCodeChain *pCC = pCtx->pCC; // Get the source and target ICCItem *pSource = pArgs->GetElement(0); ICCItem *pTarget = pArgs->GetElement(1); // If this is a list, then look for the target in the list and // return the item position in the list int iPos; if (pSource->IsList()) { iPos = -1; for (i = 0; i < pSource->GetCount(); i++) { ICCItem *pItem = pSource->GetElement(i); if (HelperCompareItems(pItem, pTarget) == 0) { iPos = i; break; } } } // Otherwise, look for the target string in the source string else { iPos = strFind(pSource->GetStringValue(), pTarget->GetStringValue()); } // Done if (iPos == -1) return pCC->CreateNil(); else return pCC->CreateInteger(iPos); }
void CGButtonArea::SetLabelAccelerator (const CString &sKey) // SetLabelAccelerator // // Sets the key to highlight as accelerator. { if (sKey.IsBlank()) m_iAccelerator = -1; else if (sKey.GetLength() > 1) m_sAccelerator = sKey; else { char *pStart = m_sLabel.GetASCIIZPointer(); char *pPos = pStart; char *pKey = sKey.GetASCIIZPointer(); bool bFirstLetter = true; // First look for the accelerator as the first letter in a word while (*pPos != '\0') { if (bFirstLetter && CharLower((LPTSTR)(BYTE)(*pKey)) == CharLower((LPTSTR)(BYTE)(*pPos))) { m_iAccelerator = pPos - pStart; return; } if (bFirstLetter) { // If we have a quote, then it still counts as the first letter if (*pPos != '\'' && *pPos != '\"' && *pPos != ' ') bFirstLetter = false; } else bFirstLetter = (*pPos == ' '); pPos++; } // Otherwise, look for the any matching letter m_iAccelerator = strFind(m_sLabel, sKey); } }
void AddWord (TraverseCtx &Ctx, const CString &sWord) { // If this is a single character, then skip it if (sWord.GetLength() == 1) ; // Skip words that are all numbers and hex numbers else if (isAllNumbers(sWord) || strFind(sWord, CONSTLIT("0x")) == 0) ; // Otherwise, add it else { Ctx.pWordList->AddEntry(strToLower(sWord), NULL); } }
void ViewShader( const char *pFile, const char *pName ){ char* pBuff = 0; //int nSize = vfsLoadFile( pFile, reinterpret_cast<void**>( &pBuff ) ); if ( pBuff == 0 ) { globalErrorStream() << "Failed to load shader file " << pFile << "\n"; return; } // look for the shader declaration StringOutputStream strFind( string_length( pName ) ); strFind << LowerCase( pName ); StringOutputStream strLook( string_length( pBuff ) ); strFind << LowerCase( pBuff ); // offset used when jumping over commented out definitions std::size_t nOffset = 0; while ( true ) { const char* substr = strstr( strFind.c_str() + nOffset, strFind.c_str() ); if ( substr == 0 ) { break; } std::size_t nStart = substr - strLook.c_str(); // we have found something, maybe it's a commented out shader name? char *strCheck = new char[string_length( strLook.c_str() ) + 1]; strcpy( strCheck, strLook.c_str() ); strCheck[nStart] = 0; char *pCheck = strrchr( strCheck, '\n' ); // if there's a commentary sign in-between we'll continue if ( pCheck && strstr( pCheck, "//" ) ) { delete[] strCheck; nOffset = nStart + 1; continue; } delete[] strCheck; nOffset = nStart; break; } // now close the file vfsFreeFile( pBuff ); DoTextEditor( pFile, static_cast<int>( nOffset ) ); }
//! 递归函数,读取一个文件夹的所有内容到传入的节点中 DWORD UpdateFolder::LoadDataFromDir(LPCSTR pDirPath, tagDirectory &Directory) { DWORD dwLoadFileNum = 0; string strFind(pDirPath); WIN32_FIND_DATA FindData; HANDLE hFind = ::FindFirstFile((strFind + "\\*").c_str(), &FindData); if(INVALID_HANDLE_VALUE != hFind) { do { if((FILE_ATTRIBUTE_DIRECTORY == FindData.dwFileAttributes)) { if(strcmp(FindData.cFileName, ".") && strcmp(FindData.cFileName, "..")) { //! 创建新节点 Directory.listDir.push_back(tagDirectory()); tagDirectory &NewDir = *(-- Directory.listDir.end()); strcpy(NewDir.szName, FindData.cFileName); //! 递归调用 dwLoadFileNum += LoadDataFromDir((strFind + "\\" + FindData.cFileName).c_str(), NewDir); } } else { Directory.listFile.push_back(CUpdateFile(FindData.cFileName)); CUpdateFile &NewFile = *(-- Directory.listFile.end()); if(NewFile.LoadDataFromDir((strFind + "\\" + FindData.cFileName).c_str())) ++ dwLoadFileNum; } } //! 读取不到就退出 while(FindNextFile(hFind, &FindData)); FindClose(hFind); } return dwLoadFileNum; }
// method 2 -- 调用函数法 char * Strtok2(char * str1, const char * str2) { static char * g_pos = NULL; if (NULL == str2) { printf("args err:check NULL == str2\n"); return NULL; } if (NULL == str1) str1 = g_pos; if (str1 != NULL) g_pos = str1; char *pCur = strNFind(str1, str2); if (pCur == NULL) return NULL; char *pNext = strFind(pCur, str2); *pNext = '\0'; g_pos = pNext + 1; return pCur; }
ALERROR CRandomItems::LoadFromXML (SDesignLoadCtx &Ctx, CXMLElement *pDesc) // LoadFromXML // // Load from XML { ALERROR error; CString sCriteria = pDesc->GetAttribute(CRITERIA_ATTRIB); if (sCriteria.IsBlank()) { CString sAttributes = pDesc->GetAttribute(ATTRIBUTES_ATTRIB); if (sAttributes.IsBlank()) sAttributes = pDesc->GetAttribute(MODIFIERS_ATTRIB); sCriteria = strPatternSubst(CONSTLIT("%s %s"), pDesc->GetAttribute(CATEGORIES_ATTRIB), sAttributes); } CItem::ParseCriteria(sCriteria, &m_Criteria); m_sLevelFrequency = pDesc->GetAttribute(LEVEL_FREQUENCY_ATTRIB); m_bDynamicLevelFrequency = (strFind(m_sLevelFrequency, CONSTLIT(":")) != -1); m_iDynamicLevel = 0; m_iLevel = pDesc->GetAttributeInteger(LEVEL_ATTRIB); m_iLevelCurve = pDesc->GetAttributeInteger(LEVEL_CURVE_ATTRIB); m_iDamaged = pDesc->GetAttributeInteger(DAMAGED_ATTRIB); if (error = m_Enhanced.InitFromXML(Ctx, pDesc)) return error; m_Table = NULL; m_iCount = 0; return NOERROR; }
void FileList::ReadFileNames(int KeepSelection, int UpdateEvenIfPanelInvisible, int DrawMessage) { SCOPED_ACTION(TPreRedrawFuncGuard)(std::make_unique<FileListPreRedrawItem>()); SCOPED_ACTION(TaskBar)(false); strOriginalCurDir = strCurDir; if (!IsVisible() && !UpdateEvenIfPanelInvisible) { UpdateRequired=TRUE; UpdateRequiredMode=KeepSelection; return; } UpdateRequired=FALSE; AccessTimeUpdateRequired=FALSE; DizRead=FALSE; api::FAR_FIND_DATA fdata; decltype(ListData) OldData; string strCurName, strNextCurName; StopFSWatcher(); if (this!=Global->CtrlObject->Cp()->LeftPanel && this!=Global->CtrlObject->Cp()->RightPanel) return; string strSaveDir; api::GetCurrentDirectory(strSaveDir); { string strOldCurDir(strCurDir); if (!SetCurPath()) { FlushInputBuffer(); // Очистим буффер ввода, т.к. мы уже можем быть в другом месте... if (strCurDir == strOldCurDir) //?? i?? { GetPathRoot(strOldCurDir,strOldCurDir); if (!api::IsDiskInDrive(strOldCurDir)) IfGoHome(strOldCurDir.front()); /* При смене каталога путь не изменился */ } return; } } SortGroupsRead=FALSE; if (GetFocus()) Global->CtrlObject->CmdLine->SetCurDir(strCurDir); LastCurFile=-1; Panel *AnotherPanel=Global->CtrlObject->Cp()->GetAnotherPanel(this); AnotherPanel->QViewDelTempName(); size_t PrevSelFileCount=SelFileCount; SelFileCount=0; SelFileSize=0; TotalFileCount=0; TotalFileSize=0; CacheSelIndex=-1; CacheSelClearIndex=-1; FreeDiskSize = -1; if (Global->Opt->ShowPanelFree) { api::GetDiskSize(strCurDir, nullptr, nullptr, &FreeDiskSize); } if (!ListData.empty()) { strCurName = ListData[CurFile].strName; if (ListData[CurFile].Selected && !ReturnCurrentFile) { for (size_t i=CurFile+1; i < ListData.size(); i++) { if (!ListData[i].Selected) { strNextCurName = ListData[i].strName; break; } } } } if (KeepSelection || PrevSelFileCount>0) { OldData.swap(ListData); } else DeleteListData(ListData); DWORD FileSystemFlags = 0; string PathRoot; GetPathRoot(strCurDir, PathRoot); api::GetVolumeInformation(PathRoot, nullptr, nullptr, nullptr, &FileSystemFlags, nullptr); ListData.clear(); bool ReadOwners = IsColumnDisplayed(OWNER_COLUMN); bool ReadNumLinks = IsColumnDisplayed(NUMLINK_COLUMN); bool ReadNumStreams = IsColumnDisplayed(NUMSTREAMS_COLUMN); bool ReadStreamsSize = IsColumnDisplayed(STREAMSSIZE_COLUMN); if (!(FileSystemFlags&FILE_SUPPORTS_HARD_LINKS) && IsWindows7OrGreater()) { ReadNumLinks = false; } if(!(FileSystemFlags&FILE_NAMED_STREAMS)) { ReadNumStreams = false; ReadStreamsSize = false; } string strComputerName; if (ReadOwners) { string strTemp; CurPath2ComputerName(strCurDir, strComputerName, strTemp); } SetLastError(ERROR_SUCCESS); // сформируем заголовок вне цикла string Title = MakeSeparator(X2-X1-1, 9, nullptr); BOOL IsShowTitle=FALSE; BOOL NeedHighlight=Global->Opt->Highlight && PanelMode != PLUGIN_PANEL; if (!Filter) Filter = std::make_unique<FileFilter>(this,FFT_PANEL); //Рефреш текущему времени для фильтра перед началом операции Filter->UpdateCurrentTime(); Global->CtrlObject->HiFiles->UpdateCurrentTime(); bool bCurDirRoot = false; ParsePath(strCurDir, nullptr, &bCurDirRoot); PATH_TYPE Type = ParsePath(strCurDir, nullptr, &bCurDirRoot); bool NetRoot = bCurDirRoot && (Type == PATH_REMOTE || Type == PATH_REMOTEUNC); string strFind(strCurDir); AddEndSlash(strFind); strFind+=L'*'; api::FindFile Find(strFind, true); DWORD FindErrorCode = ERROR_SUCCESS; bool UseFilter=Filter->IsEnabledOnPanel(); bool ReadCustomData=IsColumnDisplayed(CUSTOM_COLUMN0)!=0; DWORD StartTime = GetTickCount(); std::all_of(CONST_RANGE(Find, fdata) -> bool { Global->CatchError(); FindErrorCode = Global->CaughtError(); if ((Global->Opt->ShowHidden || !(fdata.dwFileAttributes & (FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM))) && (!UseFilter || Filter->FileInFilter(fdata, nullptr, &fdata.strFileName))) { if (ListData.size() == ListData.capacity()) ListData.reserve(ListData.size() + 4096); ListData.emplace_back(VALUE_TYPE(ListData)()); auto& NewItem = ListData.back(); NewItem.FileAttr = fdata.dwFileAttributes; NewItem.CreationTime = fdata.ftCreationTime; NewItem.AccessTime = fdata.ftLastAccessTime; NewItem.WriteTime = fdata.ftLastWriteTime; NewItem.ChangeTime = fdata.ftChangeTime; NewItem.FileSize = fdata.nFileSize; NewItem.AllocationSize = fdata.nAllocationSize; NewItem.strName = fdata.strFileName; NewItem.strShortName = fdata.strAlternateFileName; NewItem.Position = ListData.size() - 1; NewItem.NumberOfLinks=1; if (fdata.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) { NewItem.ReparseTag=fdata.dwReserved0; //MSDN } if (!(fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { TotalFileSize += NewItem.FileSize; if (ReadNumLinks) NewItem.NumberOfLinks = GetNumberOfLinks(fdata.strFileName, true); } else { NewItem.AllocationSize = 0; } NewItem.SortGroup=DEFAULT_SORT_GROUP; if (ReadOwners) { string strOwner; GetFileOwner(strComputerName, NewItem.strName,strOwner); NewItem.strOwner = strOwner; } NewItem.NumberOfStreams=NewItem.FileAttr&FILE_ATTRIBUTE_DIRECTORY?0:1; NewItem.StreamsSize=NewItem.FileSize; if (ReadNumStreams||ReadStreamsSize) { EnumStreams(TestParentFolderName(fdata.strFileName)? strCurDir : fdata.strFileName, NewItem.StreamsSize, NewItem.NumberOfStreams); } if (ReadCustomData) NewItem.strCustomData = Global->CtrlObject->Plugins->GetCustomData(NewItem.strName); if (!(fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) TotalFileCount++; DWORD CurTime = GetTickCount(); if (CurTime - StartTime > (DWORD)Global->Opt->RedrawTimeout) { StartTime = CurTime; if (IsVisible()) { if (!IsShowTitle) { if (!DrawMessage) { Text(X1+1,Y1,ColorIndexToColor(COL_PANELBOX),Title); IsShowTitle=TRUE; SetColor(Focus ? COL_PANELSELECTEDTITLE:COL_PANELTITLE); } } LangString strReadMsg(MReadingFiles); strReadMsg << ListData.size(); if (DrawMessage) { ReadFileNamesMsg(strReadMsg); } else { TruncStr(strReadMsg,static_cast<int>(Title.size())-2); int MsgLength=(int)strReadMsg.size(); GotoXY(X1+1+(static_cast<int>(Title.size())-MsgLength-1)/2,Y1); Global->FS << L" "<<strReadMsg<<L" "; } } Global->CtrlObject->Macro.SuspendMacros(true); bool check = CheckForEsc(); Global->CtrlObject->Macro.SuspendMacros(false); if (check) { // break loop return false; } } } return true; });
ALERROR CAdventureDesc::OnCreateFromXML (SDesignLoadCtx &Ctx, CXMLElement *pDesc) // OnCreateFromXML // // Load from XML { ALERROR error; int i; // If we are part of the default resource, then get the adventure UNID if (Ctx.pExtension == NULL) { m_dwExtensionUNID = pDesc->GetAttributeInteger(ADVENTURE_UNID_ATTRIB); m_fInDefaultResource = true; } // Otherwise, we remember the extension that we were loaded from else { m_dwExtensionUNID = Ctx.pExtension->GetUNID(); m_fInDefaultResource = false; } // Load the name, etc m_sName = pDesc->GetAttribute(NAME_ATTRIB); if (error = ::LoadUNID(Ctx, pDesc->GetAttribute(BACKGROUND_ID_ATTRIB), &m_dwBackgroundUNID)) return error; // Starting ship criteria CString sCriteria; if (!pDesc->FindAttribute(STARTING_SHIP_CRITERIA_ATTRIB, &sCriteria)) sCriteria = CONSTLIT("*"); if (error = CDesignTypeCriteria::ParseCriteria(sCriteria, &m_StartingShips)) return ComposeLoadError(Ctx, ERR_STARTING_SHIP_CRITERIA); m_fIncludeOldShipClasses = pDesc->GetAttributeBool(INCLUDE_10_STARTING_CLASSES_ATTRIB); // Starting position m_sStartingNodeID = pDesc->GetAttribute(STARTING_SYSTEM_ATTRIB); m_sStartingPos = pDesc->GetAttribute(STARTING_POS_ATTRIB); // Welcome message if (!pDesc->FindAttribute(WELCOME_MESSAGE_ATTRIB, &m_sWelcomeMessage)) m_sWelcomeMessage = CONSTLIT("Welcome to Transcendence!"); // Init some flags m_fIsCurrentAdventure = false; // If we don't have a name, then get it from the extension if (m_sName.IsBlank()) { if (Ctx.pExtension) m_sName = Ctx.pExtension->GetName(); } // Otherwise, if the extension doesn't have a name, then we can set it else if (Ctx.pExtension && strFind(Ctx.pExtension->GetName(), CONSTLIT("Extension")) == 0) Ctx.pExtension->SetName(m_sName); // Initialize armor and shield damage adjustment tables InitDefaultDamageAdj(); for (i = 1; i <= MAX_ITEM_LEVEL; i++) { m_ArmorDamageAdj[i - 1] = g_ArmorDamageAdj[i - 1]; m_ShieldDamageAdj[i - 1] = g_ShieldDamageAdj[i - 1]; } // Load constants CXMLElement *pConstants = pDesc->GetContentElementByTag(CONSTANTS_TAG); if (pConstants) { for (i = 0; i < pConstants->GetContentElementCount(); i++) { CXMLElement *pItem = pConstants->GetContentElement(i); if (strEquals(pItem->GetTag(), ARMOR_DAMAGE_ADJ_TAG)) { int iLevel = pItem->GetAttributeInteger(LEVEL_ATTRIB); if (iLevel < 1 || iLevel > MAX_ITEM_LEVEL) { Ctx.sError = strPatternSubst(CONSTLIT("Invalid level: %d."), iLevel); return ERR_FAIL; } if (error = m_ArmorDamageAdj[iLevel - 1].InitFromXML(Ctx, pItem, true)) return error; } else if (strEquals(pItem->GetTag(), SHIELD_DAMAGE_ADJ_TAG)) { int iLevel = pItem->GetAttributeInteger(LEVEL_ATTRIB); if (iLevel < 1 || iLevel > MAX_ITEM_LEVEL) { Ctx.sError = strPatternSubst(CONSTLIT("Invalid level: %d."), iLevel); return ERR_FAIL; } if (error = m_ShieldDamageAdj[iLevel - 1].InitFromXML(Ctx, pItem, true)) return error; } else { Ctx.sError = strPatternSubst(CONSTLIT("Invalid constant definition element: %s."), pItem->GetTag()); return ERR_FAIL; } } } return NOERROR; }
void load_file(GtkFileSelection *selector, gpointer file_selector) { FILE *stream; gchar *pfad; gchar *filename; gchar txtBuffer[200]; gchar bouquetName[MAX_TXT_LEN+1]; bouquetEntry *bouquet; channelEntry *channel; GNode *node_root; GNode *node_bouquet; GNode *node_channel; gint sumBouquets = 0; gint diseqc, transportID, frequenz, symbolRate, fec, polarity, onid, serviceID, serviceType; gchar name[MAX_TXT_LEN+1]; //****************************** // load bouquets file & fill GNode. //****************************** filename = (gchar*) gtk_file_selection_get_filename(GTK_FILE_SELECTION(file_selector)); if (!(stream = fopen(filename, "rb"))){ GtkWidget* dialog; sprintf(txtBuffer,_("Could not read: '%s' \n"),filename); dialog = gtk_message_dialog_new (NULL,0, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK,txtIn(txtBuffer)); center_window(GTK_WINDOW(dialog)); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); return; } fgets(txtBuffer,BUFFER_SIZE,stream); // xml Version. fgets(txtBuffer,BUFFER_SIZE,stream); // ZAPIT - ID. if (!strFind(txtBuffer,"<ZAPIT>" )){ GtkWidget* dialog= gtk_message_dialog_new (NULL,0, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, txtIn(_("channel format unknown"))); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); fclose(stream); return; } GTK_LIST_STORE(MW_GET("LEFT_LIST_STORE"))->sort_column_id = -2; // switch off sorting. clear_left_listview(); fgets(txtBuffer,BUFFER_SIZE,stream); // Bouquet-Kennung. if (!strFind(txtBuffer,"<BOUQUET" )){ GtkWidget* dialog= gtk_message_dialog_new (NULL,0, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, txtIn(_("This is not a Bouquet File.\n" "Please select a bouquet-file like 'bouquets.xml'."))); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); fclose(stream); return; } // ***** OK, this seems to be a bouquets file. fseek(stream,0,0); fgets(txtBuffer,BUFFER_SIZE,stream); // xml Version. fgets(txtBuffer,BUFFER_SIZE,stream); // ZAPIT - ID. node_root = MW_GET("LEFT_NODE_ROOT"); while(1){ // read all Bouquets. fgets(txtBuffer,BUFFER_SIZE,stream); // Bouquet-Daten. if (strFind(txtBuffer,"</ZAPIT>" )) break; bouquet = malloc(sizeof(bouquetEntry)); sumBouquets++; node_bouquet = g_node_append(node_root, g_node_new(bouquet)); XMLtoAsc(bouquetName, extractData(txtBuffer,"name")); strcpy(bouquet->bouquetName,bouquetName); bouquet->hidden = atoi(extractData(txtBuffer,"hidden")); bouquet->locked = atoi(extractData(txtBuffer,"locked")); node_channel = g_node_last_child (node_bouquet); while(1){ // read all channels. fgets(txtBuffer,BUFFER_SIZE,stream); if (strFind(txtBuffer,"</BOUQUET>" )) break; channel = malloc(sizeof(channelEntry)); node_channel = g_node_append(node_bouquet, g_node_new(channel)); channel->serviceID= strtol(extractData(txtBuffer,"serviceID"),NULL,16); XMLtoAsc(channel->channelName, extractData(txtBuffer,"name")); channel->onid= strtol(extractData(txtBuffer,"onid"),NULL, 16); channel->frequency = 0; } } fclose(stream); // ****************************** // die services Datei einlesen und die Bouquets in verkette Liste mit diesen // Daten ergänzen. // ****************************** pfad=filename+strlen(filename); while(*pfad!='\\' && *pfad!='/') pfad--; *++pfad='\0'; strcpy(txtBuffer, filename); strcat(txtBuffer,ZAPIT_SERV_NAME); if (!(stream = fopen(txtBuffer, "rb"))){ GtkWidget* dialog; strcat(txtBuffer, _(" not found.")); dialog = gtk_message_dialog_new (NULL,0, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK,txtIn(txtBuffer)); center_window(GTK_WINDOW(dialog)); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); clear_left_listview(); return; } fgets(txtBuffer,BUFFER_SIZE,stream); // xml Version. fgets(txtBuffer,BUFFER_SIZE,stream); // ZAPIT-Kennung. while (1){ // alle Satelliten einlesen. fgets(txtBuffer,BUFFER_SIZE,stream); // Sat / Kabel Daten. if (!strFind(txtBuffer,"<sat" ) && !strFind(txtBuffer,"<cable" )) break; diseqc = atoi(extractData(txtBuffer,"diseqc")); while (1){ // alle Transponder einlesen. fgets(txtBuffer,BUFFER_SIZE,stream); // Transponder if (strFind(txtBuffer,"</" )) break; transportID= strtol(extractData(txtBuffer,"transponder id"),NULL, 16); onid = strtol(extractData(txtBuffer,"onid"),NULL,16); frequenz= atoi(extractData(txtBuffer,"frequency")); symbolRate= atoi(extractData(txtBuffer,"symbol_rate")); fec= atoi(extractData(txtBuffer,"fec_inner")); polarity= atoi(extractData(txtBuffer,"polarization")); while(1){ // Alle Channels einlesen. gint test=0; fgets(txtBuffer,BUFFER_SIZE,stream); // Kanaldaten. if (strFind(txtBuffer,"</" )) break; serviceID = strtol(extractData(txtBuffer,"service_id"),NULL,16); XMLtoAsc(name, extractData(txtBuffer,"name")); serviceType = strtol(extractData(txtBuffer,"service_type"),NULL,16); // ****************************** // jeden einzelnen Sender in der Liste mit den neuen Daten ergänzen. // ****************************** node_bouquet = g_node_first_child(node_root); while (node_bouquet){ node_channel = g_node_first_child(node_bouquet); while (node_channel){ channel = node_channel->data; if ((serviceID == channel->serviceID) && (onid == channel->onid)) { // dieser Sender ist in den Bouquets. Also fehlende Daten ergänzen. channel->serviceType=serviceType; channel->diseqc=diseqc; channel->transportID=transportID; channel->frequency=frequenz; channel->symbolRate=symbolRate; channel->fec=fec; channel->polarisation=polarity; test++; } node_channel = node_channel->next; } node_bouquet=node_bouquet->next; } // ****************************** // Wenn der Sender aus den Services nicht in den Bouquets vorhanden war und die Liste // das komplette Bouquet enthält-> im Bouquet "*NEW*" eintragen. // ****************************** if (!test && sumBouquets > 1){ node_bouquet = g_node_last_child(node_root); bouquet = node_bouquet->data; if (strcmp(bouquet->bouquetName, "*NEW*")){ bouquet = malloc(sizeof(bouquetEntry)); node_bouquet = g_node_append(node_root, g_node_new(bouquet)); strcpy(bouquet->bouquetName,"*NEW*"); bouquet->hidden = FALSE; bouquet->locked = FALSE; sumBouquets++; } channel = malloc(sizeof(channelEntry)); g_node_append(node_bouquet, g_node_new(channel)); channel->serviceType=serviceType; channel->diseqc=diseqc; channel->transportID=transportID; channel->frequency=frequenz; channel->symbolRate=symbolRate; channel->fec=fec; channel->polarisation=polarity; XMLtoAsc(channel->channelName,name); channel->onid= onid; channel->serviceID= serviceID; } } } } fclose(stream); //****************************** // Die Bouquets überprüfen. Wenn kein Eintrag bei (z.B.) Frequez vorhanden ist, // war der Sender nicht in der services enthalten -> Daten sind nicht komplett! // -> löschen. Ebenso wenn Datendienste nicht eingelsen werden sollten. //****************************** node_bouquet = g_node_first_child(node_root); while (node_bouquet){ node_channel = g_node_first_child (node_bouquet); while (node_channel){ channel = node_channel->data; if ( (!channel->frequency) || ((!GTK_TOGGLE_BUTTON(MW_GET("OPT_READ_DATA"))->active) && (getServicePic(channel->serviceType) == DATA)) ) { // Sender war in der Bouquets-datei, aber nicht in der Services -> Sender löschen. node_channel = remove_node(node_channel); continue; } node_channel = node_channel ->next; } if (!g_node_first_child (node_bouquet)){ // bouquet now empty ? -> delete it. node_bouquet = remove_node(node_bouquet); sumBouquets--; continue; } node_bouquet = node_bouquet->next; } gtk_widget_grab_focus(GTK_WIDGET(MW_GET("OPT_READ_SHORT"))); // unfocus search entry. fill_left_listview(); }
ecConfigItem *ecConfigToolView::DoFind(const wxString& what, wxWindow* parent) { ecConfigToolDoc *pDoc = wxGetApp().GetConfigToolDoc(); if (!pDoc) return NULL; #if wxCHECK_VERSION(2, 6, 0) int nCount = pDoc->GetItems().GetCount(); #else int nCount = pDoc->GetItems().Number(); #endif // static LPCTSTR arWhereImage[]={_T("name"),_T("macro"),_T("description string"),_T("current value"),_T("default value")}; wxString strFind(what); if(! wxGetApp().GetSettings().m_findMatchCase) { strFind.MakeLower(); } wxTreeItemId h = wxGetApp().GetTreeCtrl()->GetSelection(); int nItem; if(!h){ nItem=0; } else { for (nItem=nCount-1;nItem>=0;--nItem) { if(h==pDoc->GetItem(nItem)->GetTreeItem()) { break; } } wxASSERT(nItem>=0); } ecConfigItem *pItem = NULL; int i; for (i=0 ; i < nCount ; i++) { if(wxGetApp().GetSettings().m_findDirection) { nItem=(nItem+1)%nCount; } else { nItem=(nCount+nItem-1)%nCount; } pItem = pDoc->GetItem(nItem); ecWhereType where = ecConfigItem::WhereStringToType(wxGetApp().GetSettings().m_findSearchWhat); wxString strName (pItem->StringValue(where)); if (!wxGetApp().GetSettings().m_findMatchCase) { strName.MakeLower(); } int nIndex = strName.Find(strFind); if(-1!=nIndex) { if (wxGetApp().GetSettings().m_findMatchWholeWord) { // Enforce whole-word semantics: to left and right if(nIndex>0 && IsWordChar(strName[(unsigned) (nIndex-1)])){ continue; } nIndex += strFind.Length(); if (nIndex < strName.Length() && IsWordChar(strName[(unsigned) nIndex])){ continue; } } break; } } if (i < nCount) { if(m_expandedForFind) { wxGetApp().GetTreeCtrl()->Collapse(m_expandedForFind); } wxTreeItemId h=pItem->GetTreeItem(); // Is h visible? wxTreeItemId hv; for(hv=wxGetApp().GetTreeCtrl()->GetFirstVisibleItem();hv;hv=wxGetApp().GetTreeCtrl()->GetNextVisible(hv)) { if(hv==h) { break; } } #if wxCHECK_VERSION(2, 6, 0) if (!hv.IsOk()) #else if (0==hv) #endif { // we want to record the highest unexpanded item for(hv=wxGetApp().GetTreeCtrl()->GetItemParent(h);hv;hv=wxGetApp().GetTreeCtrl()->GetItemParent(hv)) { if (!wxGetApp().GetTreeCtrl()->IsExpanded( hv)) { m_expandedForFind = hv; } } } wxGetApp().GetTreeCtrl()->EnsureVisible(h); wxGetApp().GetTreeCtrl()->SelectItem(h); } else { wxString msg; msg.Printf(_("Cannot find '%s' in %s"), (const wxChar*) what, (const wxChar*) wxGetApp().GetSettings().m_findSearchWhat ); wxMessageBox(msg, _("Find"), wxOK|wxICON_INFORMATION, parent); } return pItem; }
int CLuaInstMisc::strFind_old(lua_State *L) { MISC_FUNC_DEPRECATED(L, "strFind"); return strFind(L); }
void GenerateSystemLabelCount (CUniverse &Universe, CXMLElement *pCmdLine) { ALERROR error; int i, j; CString sError; enum STypes { typeSystemLabels, typeNodeAttributes, typeNodeDebug, }; // Figure out what kind of output we want STypes iType; if (pCmdLine->GetAttributeBool(CONSTLIT("nodes"))) iType = typeNodeAttributes; else if (pCmdLine->GetAttributeBool(CONSTLIT("nodeDebug"))) iType = typeNodeDebug; else iType = typeSystemLabels; // Samples int iSystemSample = pCmdLine->GetAttributeIntegerBounded(CONSTLIT("count"), 1, -1, 1); // Options bool bPermutations = pCmdLine->GetAttributeBool(CONSTLIT("permutations")); // Generate systems for multiple games CSystemCreateStats Stats; Stats.AddPermuteAttrib(CONSTLIT("asteroids")); Stats.AddPermuteAttrib(CONSTLIT("planetary")); Stats.AddPermuteAttrib(CONSTLIT("void")); Stats.AddPermuteAttrib(CONSTLIT("innerSystem")); Stats.AddPermuteAttrib(CONSTLIT("lifeZone")); Stats.AddPermuteAttrib(CONSTLIT("outerSystem")); Stats.AddPermuteAttrib(CONSTLIT("envAir")); Stats.AddPermuteAttrib(CONSTLIT("envEarth")); Stats.AddPermuteAttrib(CONSTLIT("envFire")); Stats.AddPermuteAttrib(CONSTLIT("envWater")); bPermutations = true; for (i = 0; i < iSystemSample; i++) { printf("pass %d...\n", i+1); // Initialize the universe if (error = Universe.InitGame(0, &sError)) { printf("ERROR: %s", sError.GetASCIIZPointer()); return; } // Loop over all topology nodes for (j = 0; j < Universe.GetTopologyNodeCount(); j++) { CTopologyNode *pNode = Universe.GetTopologyNode(j); if (pNode->IsEndGame()) continue; // Different stats depending on type switch (iType) { case typeSystemLabels: { // Create the system and generate stats CSystem *pSystem; if (error = Universe.CreateStarSystem(pNode, &pSystem, NULL, &Stats)) { printf("ERROR: Unable to create star system.\n"); return; } // Done Universe.DestroySystem(pSystem); break; } case typeNodeAttributes: { CString sAttribs = pNode->GetAttributes(); if (!sAttribs.IsBlank()) Stats.AddLabel(sAttribs); else Stats.AddLabel(CONSTLIT("[no attributes]")); break; } case typeNodeDebug: { CString sAttribs = pNode->GetAttributes(); printf("%s: %s\n", pNode->GetID().GetASCIIZPointer(), pNode->GetAttributes().GetASCIIZPointer()); break; } } } } // Titles int iTotalLabels100 = Stats.GetTotalLabelCount() * 100 / iSystemSample; int iTotalLabels = iTotalLabels100 / 100; int iTotalLabelsDecimal = iTotalLabels100 % 100; switch (iType) { case typeSystemLabels: printf("LABEL STATISTICS\n\n"); printf("Average no. of labels per universe: %d.%02d\n\n", iTotalLabels, iTotalLabelsDecimal); break; case typeNodeAttributes: printf("NODE ATTRIBUTES\n\n"); printf("Average no. of nodes per universe: %d.%02d\n\n", iTotalLabels, iTotalLabelsDecimal); break; } // Nodes if (iType != typeNodeDebug) { for (i = 0; i < Stats.GetLabelAttributesCount(); i++) { CString sAttribs; int iCount; Stats.GetLabelAttributes(i, &sAttribs, &iCount); if (bPermutations || strFind(sAttribs, CONSTLIT(",")) == -1) { int iCount100 = iCount * 100 / iSystemSample; int iPercent100 = iCount * 10000 / Stats.GetTotalLabelCount(); printf("%s: %d.%02d (%d.%02d%%)\n", sAttribs.GetASCIIZPointer(), iCount100 / 100, iCount100 % 100, iPercent100 / 100, iPercent100 % 100); } } } }
bool UrlView::parse(const StringView& _url) { clear(); const char* start = _url.getPtr(); const char* term = _url.getTerm(); const char* schemeEnd = strFind(StringView(start, term), "://"); const char* hostStart = NULL != schemeEnd ? schemeEnd+3 : start; const char* pathStart = strFind(StringView(hostStart, term), '/'); if (NULL == schemeEnd && NULL == pathStart) { return false; } if (NULL != schemeEnd && (NULL == pathStart || pathStart > schemeEnd) ) { StringView scheme(start, schemeEnd); if (!isAlpha(scheme) ) { return false; } m_tokens[Scheme].set(scheme); } if (NULL != pathStart) { const char* queryStart = strFind(StringView(pathStart, term), '?'); const char* fragmentStart = strFind(StringView(pathStart, term), '#'); if (NULL != fragmentStart && fragmentStart < queryStart) { return false; } m_tokens[Path].set(pathStart , NULL != queryStart ? queryStart : NULL != fragmentStart ? fragmentStart : term ); if (NULL != queryStart) { m_tokens[Query].set(queryStart+1 , NULL != fragmentStart ? fragmentStart : term ); } if (NULL != fragmentStart) { m_tokens[Fragment].set(fragmentStart+1, term); } term = pathStart; } const char* userPassEnd = strFind(StringView(hostStart, term), '@'); const char* userPassStart = NULL != userPassEnd ? hostStart : NULL; hostStart = NULL != userPassEnd ? userPassEnd+1 : hostStart; const char* portStart = strFind(StringView(hostStart, term), ':'); m_tokens[Host].set(hostStart, NULL != portStart ? portStart : term); if (NULL != portStart) { m_tokens[Port].set(portStart+1, term); } if (NULL != userPassStart) { const char* passStart = strFind(StringView(userPassStart, userPassEnd), ':'); m_tokens[UserName].set(userPassStart , NULL != passStart ? passStart : userPassEnd ); if (NULL != passStart) { m_tokens[Password].set(passStart+1, userPassEnd); } } return true; }
bool CBlackBox::ReadRecent (const CString &sPath, const CString &sFind, int iLines, TArray<CString> *retLines) // ReadRecent // // Returns the most recent set of lines. { // First we make a list of log files at the given path. TArray<CString> Files; if (!fileGetFileList(sPath, NULL_STR, CString("*.log"), 0, &Files)) return false; // Now sort them in reverse chronological order (we can do this because we // have encoded the date in the name). Files.Sort(DescendingSort); // Now loop until we have filled all the lines (or until we run out of log // files). int iLogFile = 0; int iLinesLeft = iLines; while (iLogFile < Files.GetCount() && iLinesLeft > 0) { // Open the log file for read-only CFileBuffer LogFile; if (!LogFile.OpenReadOnly(Files[iLogFile])) return false; // Parse backwards until we reach the number of lines that we want // or until we reach the beginning of the file. char *pBoF = LogFile.GetPointer(); char *pEoF = pBoF + LogFile.GetLength(); char *pStart = pEoF; while (pStart > pBoF && iLinesLeft > 0) { // Remember the end of the line. char *pLineEnd = pStart; // Go backwards until we hit a line ending while (pStart > pBoF && pStart[-1] != '\n') pStart--; // We're at the beginning of the line so get the whole thing. If // this is a line that we want, then add it to the result. CString sLine(pStart, (int)(pLineEnd - pStart)); if (!sLine.IsEmpty() && (sFind.IsEmpty() || strFind(sLine, sFind) != -1)) { // We add at the beginning because we are reading backwards retLines->Insert(sLine, 0); // We got a line iLinesLeft--; } // Now move backwards to skip the line ending if (pStart > pBoF && pStart[-1] == '\n') pStart--; if (pStart > pBoF && pStart[-1] == '\r') pStart--; } // Next file LogFile.Close(); iLogFile++; } // Done return true; }