int Var::PathCompress(int reg, int blocknum, int *tr) { Var *v; Tree *t; int n; *tr = -1; v = Find2(reg); if (v == nullptr) { *tr = -1; return (-1); } // Find the tree with the basic block for (n = 0; n < v->trees.treecount; n++) { t = v->trees.trees[n]; if (t->blocks->isMember(blocknum)) { break; } } if (n < v->trees.treecount) { *tr = t->num; t->blocks->resetPtr(); // The root of the tree is the lowest block number return (t->blocks->nextMember()); } // else error: path not found return (-1); }
// This variant keeps the tree flat applying path compression. ListNode * Find2(int x) { assert(x<alloc_size); ListNode * node = array[x]; if (node != node->parent) { node->parent = Find2(node->parent->val); } return node->parent; }
void CFLTKEditor::Find() { char *pcVal; pcVal = (char *) fl_input("Search String:", GetSearchString()); if (pcVal != NULL) { // User entered a string - go find it! strcpy(GetSearchString(), pcVal); Find2(); } }
CSet *Var::Find3(int reg, int blocknum) { Var *v; Tree *t; int n; v = Find2(reg); // Find the tree with the basic block for (n = 0; n < v->trees.treecount; n++) { t = v->trees.trees[n]; if (t->blocks->isMember(blocknum)) { return (t->blocks); } } // else error: return (nullptr); }
int Var::FindTreeno(int reg, int blocknum) { Var *v; Tree *t; int n, m; // Find the associated variable v = Find2(reg); if (v == nullptr) return (-1); // Find the tree with the basic block. The individual trees in a given // var should be disjoint. Only one tree will contain the block. for (m = n = 0; n < v->trees.treecount; n++) { t = v->trees.trees[n]; if (t->blocks->isMember(blocknum)) return(t->num); } return (-1); }
RCODE f_fileFindNext( F_IO_FIND_DATA * pFindData, char * pszFoundPath, FLMUINT * puiFoundAttrib) { RCODE rc = NE_FLM_OK; IF_FileSystem * pFileSystem = f_getFileSysPtr(); int iRetVal; if( (iRetVal = Find2( pFindData)) != 0) { // If there were no more files found then return no more files // instead of mapping to error path not found or io error. // To return no more files ret_val is ENOENT (set in Find2) // and errno is not set if( iRetVal == ENOENT && errno == 0) { return( RC_SET( NE_FLM_IO_NO_MORE_FILES)); } return( f_mapPlatformError( errno, NE_FLM_READING_FILE)); } // Append the file name to the path name f_strcpy( pszFoundPath, pFindData->search_path); if( RC_BAD( rc = pFileSystem->pathAppend( pszFoundPath, (char *)pFindData->name))) { goto Exit; } *puiFoundAttrib = (FLMUINT)ReturnAttributes( pFindData->FileStat.st_mode, pszFoundPath); Exit: return( rc); }
void TreeItemData::Find2(wxTreeCtrl* pTree, wxTreeItemId tree_id, wxListCtrl* pList, const Omega::string_t& strFind, bool bKeys, bool bValues, bool bData, bool bMatchAll, bool bIgnoreCase) { TreeItemData* pItem = (TreeItemData*)pTree->GetItemData(tree_id); bool bKey = false; Omega::string_t strFoundPos = Find3(pItem->m_ptrKey,strFind,bKeys,bValues,bData,bMatchAll,bIgnoreCase,bKey); if (!strFoundPos.IsEmpty()) { // Expand and select the item wxString strSubKey; for (;;) { size_t pos = strFoundPos.Find('/'); if (pos != Omega::string_t::npos) { strSubKey = strFoundPos.Left(pos).c_wstr(); strFoundPos = strFoundPos.Mid(pos+1); } else { strSubKey = strFoundPos.c_wstr(); strFoundPos.Clear(); if (!bKey) break; } //pTree->SelectItem(tree_id); pTree->Expand(tree_id); if (strSubKey == pTree->GetItemText(tree_id)) continue; if (pTree->ItemHasChildren(tree_id)) { wxTreeItemIdValue cookie; wxTreeItemId id_child = pTree->GetFirstChild(tree_id,cookie); while (id_child && strSubKey != pTree->GetItemText(id_child)) { id_child = pTree->GetNextChild(tree_id,cookie); } if (!id_child) { break; } tree_id = id_child; } else { break; } } pTree->SelectItem(tree_id); if (!bKey) { long item; while ((item=pList->GetNextItem(-1,wxLIST_NEXT_ALL,wxLIST_STATE_SELECTED)) != -1) { pList->SetItemState(item,0,wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED ); } item = pList->FindItem(-1,wxString(strSubKey)); pList->SetItemState(item,wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED,wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED); pList->SetFocus(); } else { pTree->SetFocus(); } return; } // Try the next sibling wxTreeItemId next_id = pTree->GetNextSibling(tree_id); while (!next_id) { if (tree_id == pTree->GetRootItem()) { wxMessageBox(_("Reached the end of the registry."),_("Find"),wxOK|wxICON_INFORMATION,NULL); return; } tree_id = pTree->GetItemParent(tree_id); next_id = pTree->GetNextSibling(tree_id); } Find2(pTree,next_id,pList,strFind,bKeys,bValues,bData,bMatchAll,bIgnoreCase); }
RCODE f_fileFindFirst( char * pszSearchPath, FLMUINT uiSearchAttrib, F_IO_FIND_DATA * pFindData, char * pszFoundPath, FLMUINT * puiFoundAttrib) { RCODE rc = NE_FLM_OK; char szTmpPath[ F_PATH_MAX_SIZE]; FSTATIC char pszWildCard[] = {'*',0}; int iRetVal; IF_FileSystem * pFileSystem = f_getFileSysPtr(); if( !pszSearchPath) { rc = RC_SET( NE_FLM_IO_PATH_NOT_FOUND); goto Exit; } f_strcpy( szTmpPath, pszSearchPath); if( RC_BAD( rc = pFileSystem->pathAppend( szTmpPath, pszWildCard))) { goto Exit; } f_memset( pFindData, 0, sizeof( F_IO_FIND_DATA)); if( uiSearchAttrib & F_IO_FA_DIRECTORY) { pFindData->mode_flag |= S_IFDIR; } if( uiSearchAttrib & F_IO_FA_RDONLY) { pFindData->mode_flag |= S_IREAD; } iRetVal = Find1( (char*)szTmpPath, pFindData); if( iRetVal != 0) { // If there were no more files found then return no more files // instead of mapping to error path not found or io error. // To return no more files ret_val is ENOENT (set in Find2) // and errno is not set if( iRetVal == ENOENT && errno == 0) { rc = RC_SET( NE_FLM_IO_NO_MORE_FILES); } else { rc = f_mapPlatformError( errno, NE_FLM_READING_FILE); } goto Exit; } // filter out ".." (PARENT) and "." (CURRENT) directories if( uiSearchAttrib & F_IO_FA_DIRECTORY ) { while( (f_strcmp( pFindData->name, "..") == 0) || (f_strcmp( pFindData->name, ".") == 0)) { if( (iRetVal = Find2( pFindData)) != 0) { // If there were no more files found then return no more files // instead of mapping to error path not found or io error. // To return no more files ret_val is ENOENT (set in Find2) // and errno is not set if( iRetVal == ENOENT && errno == 0) { rc = RC_SET( NE_FLM_IO_NO_MORE_FILES); } else { rc = f_mapPlatformError( errno, NE_FLM_READING_FILE); } goto Exit; } } } // Append the file name to the path name f_strcpy( pszFoundPath, pszSearchPath); if( RC_BAD( rc = pFileSystem->pathAppend( pszFoundPath, (char *)pFindData->name))) { goto Exit; } *puiFoundAttrib = (FLMUINT)ReturnAttributes( pFindData->FileStat.st_mode, pszFoundPath); // Save the search path in the NE_FLM_IO_FIND_DATA struct // for a find next call f_strcpy( pFindData->search_path, pszSearchPath); Exit: return( rc); }
FSTATIC int Find1( char * FindTemplate, F_IO_FIND_DATA * DirInfo) { char MaskNam[ F_PATH_MAX_SIZE]; char *PathSeparator; FLMINT uiFindLen; FLMINT uiLen; #ifdef FLM_LIBC_NLM char szPosixNam[ F_PATH_MAX_SIZE]; FLMINT uiCount; #endif // If supplied template is illegal, return immediately if( (FindTemplate == NULL) || (uiFindLen = f_strlen( FindTemplate)) == 0) { return( EINVAL); } // Now separate the template into a PATH and a template MASK // If no separating slash character found, use current directory // as path! f_strcpy( DirInfo->full_path, FindTemplate); #ifdef FLM_LIBC_NLM if( (( PathSeparator = strrchr( DirInfo->full_path, '/')) == NULL) && ( PathSeparator = strrchr( DirInfo->full_path, '\\')) == NULL) #else if( (PathSeparator = strrchr( DirInfo->full_path, '/')) == NULL) #endif { (void) getcwd( DirInfo->full_path, F_PATH_MAX_SIZE); uiLen = f_strlen( DirInfo->full_path ); DirInfo->full_path[uiLen] = '/'; DirInfo->full_path[uiLen+1] = '\0'; (void) f_strcat( DirInfo->full_path, FindTemplate ); PathSeparator = strrchr( DirInfo->full_path, '/'); } // Copy the template MASK, and null terminate the PATH f_strcpy( MaskNam, PathSeparator + 1); if( ! f_strlen(MaskNam)) { (void) f_strcpy( MaskNam, "*"); } *PathSeparator = '\0'; // Use ROOT directory if PATH is empty if( ! f_strlen(DirInfo->full_path)) { (void) f_strcpy( DirInfo->full_path, "/"); } f_strcpy( DirInfo->dirpath, DirInfo->full_path ); // Open the specified directory. Return immediately // if error detected! errno = 0; DirInfo->globbuf.gl_pathv = 0; #ifdef FLM_LIBC_NLM // glob does not seem to be able to handle a non-posix path // on NetWare. for( uiCount = 0; uiCount <= uiFindLen; uiCount++) { if( FindTemplate[ uiCount] == '\\') { szPosixNam[ uiCount] = '/'; } else { szPosixNam[ uiCount] = FindTemplate[ uiCount]; } } if( glob( szPosixNam, GLOB_NOSORT, 0, &DirInfo->globbuf) != 0 && !DirInfo->globbuf.gl_pathc) #else if( glob( FindTemplate, GLOB_NOSORT, 0, &DirInfo->globbuf) != 0 && !DirInfo->globbuf.gl_pathc) #endif { globfree(&DirInfo->globbuf); DirInfo->globbuf.gl_pathv = 0; return ENOENT; } // Call Find2 to get the 1st matching file return( Find2(DirInfo) ); }