void sistrip_reduce_file(string fname1, string fname2) { TFile* file1 = new TFile(fname1.c_str()); if (!file1 || !file1->IsOpen()) return; TDirectory* topDir1 = dynamic_cast<TDirectory*>( file1->Get("DQMData")); goToDir(topDir1, "SiStrip"); TDirectory* stripDir = gDirectory; TFile* file2 = new TFile(fname2.c_str(), "RECREATE"); if (!file2 || !file2->IsOpen()) return; TDirectory* topDir2 = file2->mkdir("DQMData"); if (!topDir2) { cout << " Can not create directory structure in " << fname2 << endl; return; } parseStructure(stripDir, topDir2); file1->Close(); file2->Write(); file2->Close(); }
/* * GUIGetFileName - get a file name from the user */ int GUIGetFileName( gui_window *gui, open_file_name *ofn ) { char olddir[_MAX_PATH]; dlg_info dlg; if( !ControlsInitialized ) { InitDlgControls(); ControlsInitialized = true; } dlg.currOFN = ofn; dlg.currExt = NULL; dlg.currExtIndex = ofn->filter_index; dlg.dialogRC = OFN_RC_NO_FILE_SELECTED; #if !defined( __UNIX__ ) && !defined( __NETWARE__ ) dlgControls[DRIVE_LIST_INDEX].text = buildDriveList(); if( dlgControls[DRIVE_LIST_INDEX].text == NULL ) { return( OFN_RC_FAILED_TO_INITIALIZE ); } #endif dlgControls[FILE_TYPES_INDEX].text = buildFileTypes( &dlg, ofn->filter_list ); if( dlgControls[FILE_TYPES_INDEX].text == NULL || dlg.fileExtensions == NULL ) { return( OFN_RC_FAILED_TO_INITIALIZE ); } getcwd( olddir, sizeof( olddir ) ); goToDir( gui, ofn->initial_dir ); GUIModalDlgOpen( gui, ofn->title, DLG_FILE_ROWS, DLG_FILE_COLS, dlgControls, NUM_CONTROLS, &GetFileNameEvent, &dlg ); if( !(ofn->flags & OFN_CHANGEDIR) ) { goToDir( gui, olddir ); } #if !defined( __UNIX__ ) && !defined( __NETWARE__ ) freeStringList( &dlgControls[DRIVE_LIST_INDEX].text ); #endif freeStringList( &dlgControls[FILE_TYPES_INDEX].text ); freeStringList( &dlg.fileExtensions ); GUIMemFree( dlg.currExt ); return( dlg.dialogRC ); } /* GUIGetFileName */
/* * GUIGetFileName - get a file name from the user */ int GUIGetFileName( gui_window *gui, open_file_name *ofn ) { char olddir[_MAX_PATH]; dlg_info dlg; bool ok; if( !ControlsInitialized ) { InitDlgControls(); ControlsInitialized = true; } #if !defined( __UNIX__ ) && !defined( __NETWARE__ ) if( !buildDriveList() ) { return( OFN_RC_FAILED_TO_INITIALIZE ); } #endif ok = buildFileTypesExts( &dlg, ofn->filter_list ); if( !ok ) { dlg.currExt = NULL; dlg.dialogRC = OFN_RC_FAILED_TO_INITIALIZE; } else { dlg.currOFN = ofn; dlg.currExt = NULL; dlg.currExtIndex = ofn->filter_index; dlg.dialogRC = OFN_RC_NO_FILE_SELECTED; getcwd( olddir, sizeof( olddir ) ); goToDir( gui, ofn->initial_dir ); GUIModalDlgOpen( gui, ofn->title, DLG_FILE_ROWS, DLG_FILE_COLS, dlgControls, NUM_CONTROLS, &GetFileNameEvent, &dlg ); if( !(ofn->flags & OFN_CHANGEDIR) ) { goToDir( gui, olddir ); } } #if !defined( __UNIX__ ) && !defined( __NETWARE__ ) freeDriveTextList(); #endif freeFileTypesTextList(); freeFileExtsTextList(); GUIMemFree( dlg.currExt ); return( dlg.dialogRC ); } /* GUIGetFileName */
bool goToDir(TDirectory* top_dir, string dname){ string dir_name = top_dir->GetTitle(); if (dir_name == dname) { return true; } else { TIter next(top_dir->GetListOfKeys()); TKey *key; while ( (key = dynamic_cast<TKey*>(next())) ) { string clName(key->GetClassName()); if (clName == "TDirectoryFile") { TDirectory *curr_dir = dynamic_cast<TDirectory*>(key->ReadObj()); curr_dir->cd(); if (goToDir(curr_dir, dname)) return true; curr_dir->cd(".."); } } } return false; }
void QvvMainWindow::slotChangeDir() { goToDir( 0 ); }
/* * processFileName - process a new file name */ static process_rc processFileName( gui_window *gui ) { char *tmp; char *txt; size_t len; char path[_MAX_PATH]; char dir[_MAX_DIR]; char drive[_MAX_DRIVE]; char fname[_MAX_PATH]; char ext[_MAX_PATH]; char *buff; bool has_wild; struct stat buf; int rc; dlg_info *dlg = GUIGetExtra( gui ); tmp = GUIGetText( gui, CTL_EDIT ); if( tmp == NULL ) { return( PROCESS_FALSE ); } txt = alloca( strlen( tmp ) + 1 ); if( txt == NULL ) { GUIMemFree( tmp ); return( PROCESS_FALSE ); } strcpy( txt, tmp ); GUIMemFree( tmp ); splitPath( txt, drive, dir, fname, ext ); has_wild = hasWild( txt ); if( has_wild && fname[0] == 0 ) { return( PROCESS_FALSE ); } if( !has_wild ) { rc = stat( txt, &buf ); if( !rc ) { if( S_ISDIR( buf.st_mode ) ) { goToDir( gui, txt ); if( !initDialog( gui, dlg->fileExtensions[dlg->currExtIndex], NULL ) ) { return( PROCESS_FAIL ); } return( PROCESS_FALSE ); } } _makepath( path, drive, dir, NULL, NULL ); if( !goToDir( gui, path ) ) { return( PROCESS_FALSE ); } if( !rc && (dlg->currOFN->flags & OFN_OVERWRITEPROMPT) ) { buff = alloca( strlen( txt ) + 100 ); strcpy( buff, txt ); strcat( buff, LIT( File_Exists_Replace ) ); rc = GUIDisplayMessage( gui, buff, dlg->currOFN->title, GUI_YES_NO ); if( rc == GUI_RET_NO ) { return( PROCESS_FALSE ); } } _makepath( path, NULL, NULL, fname, ext ); if( dlg->currOFN->base_file_name != NULL ) { len = strlen( txt ); if( len >= dlg->currOFN->max_base_file_name ) { len = dlg->currOFN->max_base_file_name - 1; } memcpy( dlg->currOFN->base_file_name, txt, len ); dlg->currOFN->base_file_name[len] = 0; } if( dlg->currOFN->file_name != NULL ) { getcwd( path, sizeof( path ) ); len = strlen( path ); if( path[len - 1] != FILE_SEP_CHAR ) { path[len] = FILE_SEP_CHAR; path[len + 1] = 0; } strcat( path, fname ); strcat( path, ext ); len = strlen( path ); if( len >= dlg->currOFN->max_file_name ) { len = dlg->currOFN->max_file_name-1; } memcpy( dlg->currOFN->file_name, path, len ); dlg->currOFN->file_name[len] = 0; } return( PROCESS_TRUE ); } _makepath( path, drive, dir, NULL, NULL ); if( !goToDir( gui, path ) ) { return( PROCESS_FALSE ); } _makepath( path, NULL, NULL, fname, ext ); if( !initDialog( gui, path, NULL ) ) { return( PROCESS_FAIL ); } return( PROCESS_FALSE ); } /* processFileName */
/* * GetFileNameEvent - event handler for GetFileName dialog */ extern bool GetFileNameEvent( gui_window *gui, gui_event gui_ev, void *param ) { unsigned id; int sel; char *ptr; char path[_MAX_PATH]; dlg_info *dlg = GUIGetExtra( gui ); switch( gui_ev ) { case GUI_INIT_DIALOG: dlg->initted = false; InitTextList( gui, CTL_FILE_TYPES, GetFileTypesTextList() ); #if !defined( __UNIX__ ) && !defined( __NETWARE__ ) InitTextList( gui, CTL_DRIVES, GetDriveTextList() ); #endif if( !initDialog( gui, dlg->fileExtensions[dlg->currExtIndex], dlg->currOFN->file_name ) ) { dlg->dialogRC = OFN_RC_FAILED_TO_INITIALIZE; return( false ); } dlg->initted = true; GUISetFocus( gui, CTL_EDIT ); return( true ); break; case GUI_CONTROL_DCLICKED: GUI_GETID( param, id ); switch( id ) { case CTL_FILE_LIST: case CTL_DIR_LIST: ProcessOKorDClick( gui, id ); break; } break; case GUI_CONTROL_CLICKED: if( !dlg->initted ) break; GUI_GETID( param, id ); switch( id ) { case CTL_OK: ProcessOKorDClick( gui, id ); break; case CTL_CANCEL: GUICloseDialog( gui ); break; case CTL_FILE_LIST: ptr = GUIGetText( gui, id ); GUISetText( gui, CTL_EDIT, ptr ); GUIMemFree( ptr ); break; case CTL_DRIVES : sel = GUIGetCurrSelect( gui, id ); strcpy( path, GetDriveTextList()[sel] ); path[2] = 0; goToDir( gui, path ); if( !initDialog( gui, NULL, NULL ) ) { dlg->dialogRC = OFN_RC_RUNTIME_ERROR; GUICloseDialog( gui ); } break; case CTL_FILE_TYPES: sel = GUIGetCurrSelect( gui, id ); if( !initDialog( gui, dlg->fileExtensions[sel], NULL ) ) { dlg->dialogRC = OFN_RC_RUNTIME_ERROR; GUICloseDialog( gui ); } break; } return( true ); default: break; // makes GCC happy. } return( false ); } /* GetFileNameEvent */
/* * ProcessOKorDClick -- user clicked OK or double clicked on a file */ void ProcessOKorDClick( gui_window *gui, unsigned id ) { process_rc prc; int sel; int realsel; char path[_MAX_PATH]; char *optr; char *ptr; int i; unsigned focusid; dlg_info *dlg = GUIGetExtra( gui ); if( id == CTL_OK ) { /* hit enter or clicked ok */ GUIGetFocus( gui, &focusid ); switch( focusid ) { case CTL_DIR_LIST : id = focusid; break; case CTL_FILE_LIST : ptr = GUIGetText( gui, CTL_FILE_LIST ); GUISetText( gui, CTL_EDIT, ptr ); GUIMemFree( ptr ); break; } } switch( id ) { case CTL_FILE_LIST : case CTL_OK : prc = processFileName( gui ); if( prc == PROCESS_TRUE ) { dlg->dialogRC = OFN_RC_FILE_SELECTED; GUICloseDialog( gui ); } else if( prc == PROCESS_FAIL ) { dlg->dialogRC = OFN_RC_RUNTIME_ERROR; GUICloseDialog( gui ); } break; case CTL_DIR_LIST : sel = GUIGetCurrSelect( gui, id ); #if defined( __UNIX__ ) || defined( __NETWARE__ ) path[0] = FILE_SEP_CHAR; path[1] = 0; #else path[0] = 0; #endif realsel = 0; for( i=0;i<sel;i++ ) { ptr = GUIGetListItem( gui, id, i ); if( ptr == NULL ) { return; } optr = ptr; while( *ptr == INDENT_CHAR ) { ptr++; } if( *ptr == '-' ) { strcat( path, ptr+1 ); realsel++; if( i > 0 ) { strcat( path, FILE_SEP ); } } else { GUIMemFree( optr ); break; } GUIMemFree( optr ); } ptr = GUIGetListItem( gui, id, sel ); if( ptr == NULL ) { return; } optr = ptr; while( *ptr == INDENT_CHAR ) { ptr++; } strcat( path, ptr+1 ); GUIMemFree( optr ); goToDir( gui, path ); if( !initDialog( gui, NULL, NULL ) ) { dlg->dialogRC = OFN_RC_RUNTIME_ERROR; GUICloseDialog( gui ); } else { GUISetCurrSelect( gui, id, realsel ); } break; } } /* ProcessOKorDClick */