void tree_drop() { if ( dir_tree_changed ) tree_save(); dir_tree.undef(); dir_tree_changed = 0; }
void keyValue(char a[][30] ,int n) { int i; TREE_T *root=tree_new("m for root"); TREE_T *backup=tree_load(); for(i=0;i<n;i++) { char *p=a[i]; int value; char name[MAXN+1]; TREE_T *t; switch(p[0]) { case 'S': sscanf(p,"SET %s %d",&name,&value); t=tree_get(root,name); t->value=value; break; case 'G': sscanf(p,"GET %s",&name); t=tree_has(root,name); if (!t) t=tree_get(backup,name); printf("%d\n",t->value); break; case 'R': tree_free(root); root=tree_new("m for root"); break; case 'C': tree_commit(backup,root); root=tree_new("m for root"); break; default: assert(0); } } tree_free(root); tree_save(backup); }
void tree_rebuild() { #ifdef _TARGET_GO32_ // we do need only files sizes -- so the other stuff under dos is unneeded :) _djstat_flags = _STAT_INODE | _STAT_EXEC_EXT | _STAT_EXEC_MAGIC | _STAT_EXEC_MAGIC | _STAT_DIRSIZE | _STAT_ROOT_TIME | _STAT_WRITEBIT; // _djstat_flags = 0; #endif dir_tree.undef(); size_cache.undef(); say1( "Rebuilding tree..." ); __tree_rebuild_process( "/" ); tree_fix(); #ifdef _TARGET_GO32_ _djstat_flags = 0; #endif dir_tree_changed = 1; tree_save(); };
void tree_view() { VString str; if (dir_tree.count() == 0) { tree_load(); if (dir_tree.count() == 0) tree_rebuild(); } say1( " " ); int new_pos = tree_index( work_path ); if ( new_pos == -1 ) new_pos = 0; BSet set; /* used for searching */ set.set_range1( 'a', 'z' ); set.set_range1( 'A', 'Z' ); set.set_range1( '0', '9' ); set.set_str1( "._-~" ); set.set_str1( "?*>[]" ); ScrollPos scroll; scroll.set_min_max( 0, dir_tree.count()-1 ); scroll.set_pagesize( PS+2 ); scroll.go( new_pos ); int key = 0; int opos = -1; int opage = -1; while( key != 27 && key != 13 && key != '-' && toupper( key ) != 'Q' && toupper( key ) != 'X' && key != KEY_ALT_X ) { if ( key >= 'A' && key <= 'Z' ) key = tolower( key ); if ( key == 's' ) { str = ""; say1( "Enter search pattern: ( use TAB to advance )" ); key = con_getch(); while( set.in( key ) || key == 8 || key == KEY_BACKSPACE || key == 9 ) { if ( key == 8 || key == KEY_BACKSPACE ) str_trim_right( str, 1 ); else if ( key != 9 ) str_add_ch( str, key ); say2( str ); if ( dir_tree.count() == 0 ) { key = con_getch(); continue; } int z; if ( key == 9 ) { z = scroll.pos() + 1; if (z > scroll.max() ) z = scroll.min(); } else z = scroll.pos(); int direction = 1; int found = 0; int loops = 0; VString s_mask = str; vfu_expand_mask( s_mask ); while(1) { if ( z > scroll.max() ) z = scroll.min(); if ( z < scroll.min() ) z = scroll.max(); VString str1 = dir_tree[z]; str_trim_right( str1, 1 ); int j = str_rfind(str1,'/'); if (j < 0) str1 = ""; else str_trim_left( str1, j+1 ); found = ( FNMATCH( s_mask, str1 ) == 0 ); if ( found ) break; z += direction; if ( loops++ > dir_tree.count() ) break; } if (found) { scroll.go(z); tree_draw_page( scroll ); tree_draw_pos( scroll, opos ); } key = con_getch(); } say1( "" ); say2( "" ); } else switch( key ) { case KEY_UP : scroll.up(); break; case KEY_DOWN : scroll.down(); break; case KEY_PPAGE : scroll.ppage(); break; case KEY_NPAGE : scroll.npage(); break; case KEY_HOME : scroll.home(); break; case KEY_END : scroll.end(); break; case 'r' : tree_rebuild(); scroll.set_min_max( 0, dir_tree.count()-1 ); scroll.home(); say1( "Rebuild done." ); break; case 'w' : tree_save(); break; case 'l' : tree_load(); scroll.set_min_max( 0, dir_tree.count()-1 ); scroll.home(); break; case 'z' : case KEY_CTRL_Z : str = dir_tree[scroll.pos()]; str_tr( str, "\\", "/" ); size_cache_set( str, vfu_dir_size( str ) ); tree_draw_page( scroll ); tree_draw_pos( scroll, opos ); say1( "Done." ); break; } if (opage != scroll.page()) tree_draw_page( scroll ); if (opos != scroll.pos() - scroll.page() || opage != scroll.page()) tree_draw_pos( scroll, opos ); opos = scroll.pos() - scroll.page(); opage = scroll.page(); key = con_getch(); } if ( key == 13 ) { str = dir_tree[scroll.pos()]; str_tr( str, "\\", "/" ); vfu_chdir( str ); } do_draw = 2; };