/* DESKSEAR.C 1/3/90 - 1/16/90 D.Mui */ /************************************************************************/ /* New Desktop for Atari ST/TT Computer */ /* Atari Corp */ /* Copyright 1989,1990 All Rights Reserved */ /************************************************************************/ #include #include #include #include #include #include #include #include #include EXTERN WINDOW *alloc_win(); EXTERN WINDOW *w_gfirst(); EXTERN WORD f_level; /* local level counter same as deskdir */ EXTERN WORD f_rename; /* window opened? */ EXTERN WINDOW *x_win; EXTERN WORD x_type; EXTERN WORD x_status; /* Position an item within a window */ pos_item( win, newi ) REG WINDOW *win; WORD newi; { REG WORD i,j,k; LONG l; /****** adjust the vertical bar ******/ j = newi / win->w_icol; i = win->w_items / win->w_icol; /* maximum number of row */ if ( win->w_items % win->w_icol ) i++; if ( j >= win->w_xrow ) j = j - win->w_xrow + 1; else j = 0; win->w_rowi = j; win->w_srtitems = j * win->w_icol; if ( i > win->w_xrow ) { l = 1000 * j; l = l / ( i - win->w_xrow ); } else l = 1000; win->w_obj->ob_y = win->w_work.y; wind_set( win->w_id, WF_VSLIDE, (UWORD)l, 0, 0, 0 ); /******* adjust the horizontal bar ********/ win->w_obj->ob_x = win->w_work.x; win->w_obj->ob_width = win->w_work.w; i = ( newi % win->w_icol ) + 1; /* column index */ if ( i > win->w_xcol ) /* bigger than one frame*/ j = i - win->w_xcol; /* move left */ else j = 0; win->w_coli = j; /* column index */ k = j * fobj.w; /* move the object if necessary */ win->w_obj->ob_x -= k; win->w_obj->ob_width += k; if ( win->w_hvicons ) { l = 1000 * j; l = l / win->w_hvicons; } else l = 1000; wind_set( win->w_id, WF_HSLIDE, (UWORD)l, 0, 0, 0 ); up_2( win ); } /* Search a file */ sea_file( filename ) BYTE *filename; { REG WINDOW *win; REG DIR *dir; REG WORD i; BYTE *str; WORD status,type,change,newi; BYTE buffer[16]; desk_wait( TRUE ); strcpy( filename, buffer ); mass_string( filename ); change = FALSE; if ( status = x_first( &str, &type ) ) { f_level = 0; f_rename = FALSE; while( status ) { if ( ( type == DISK ) || ( type == SUBDIR ) || ( type == XDIR ) ) { if ( *str == 'c' ) do1_alert( NOSEA ); else { set_dir( str ); /* set the current directory */ if ( rec_sea( filename ) ) goto s_ex1; } } status = x_next( &str, &type ); } if ( f_rename ) /* if there is a window opened, then the */ { /* search must be succeed */ do1_alert( NOMORE ); goto s_ex1; } } else { if ( win = w_gfirst() ) { if ( win->w_path[0] == 'c' ) { do1_alert( NOSEA ); goto s_ex2; } dir = win->w_memory; for ( i = 0; i < win->w_items; i++ ) { if ( wildcmp( filename, dir[i].d_name ) ) { dir[i].d_state = SELECTED; if ( !change ) newi = i; change = TRUE; } } if ( change ) { pos_item( win, newi ); goto s_ex2; } }/* if window */ }/* else */ fill_string( buffer, FNOTFIND ); goto s_ex3; s_ex1: /* if not select from top window */ if ( ( x_type == WINICON ) && ( x_status ) ) clr_xwin( x_win, TRUE ); s_ex2: clr_dicons(); s_ex3: desk_wait( FALSE ); } /* Recursive search of a file */ WORD rec_sea( filename ) REG BYTE *filename; { DTA *dtabuf; DTA *savedta; REG WORD status,ret; if ( !( dtabuf = Malloc( (LONG)sizeof(DTA) ) ) ) { do1_alert( FCNOMEM ); return( TRUE ); } savedta = Fgetdta(); /* save the dta buffer */ Fsetdta( dtabuf ); /* set the new dta */ status = FALSE; /* not found */ desk_wait( TRUE ); /* look for matching */ ret = Fsfirst( filename, 0x31 ); while( !ret ) { /* matched */ if ( wildcmp( filename, dtabuf->dirfile.d_name ) ) { if ( display( filename ) ) { if ( do1_alert( SNEXT ) == 1 ) goto s_more; } status = TRUE; goto s_exit; } ret = Fsnext(); } /* Look for folder */ s_more: desk_wait( TRUE ); Fsetdta( dtabuf ); /* set the new dta */ ret = Fsfirst( getall, 0x31 ); while( !ret ) { if ( ( dtabuf->dirfile.d_att & SUBDIR ) && ( dtabuf->dirfile.d_name[0] != '.' ) ) { path2[0] = '.'; path2[1] = '\\'; strcpy( dtabuf->dirfile.d_name, &path2[2] ); Dsetpath( path2 ); f_level++; if ( f_level > COPYMAXDEPTH ) { do1_alert( STFO8DEE ); status = TRUE; break; } status = rec_sea( filename ); f_level--; if ( !status ) /* if not found then back up one path */ Dsetpath( ".." ); else break; /* quit */ }/* if SUBDIR */ ret = Fsnext(); }/* while */ s_exit: Mfree( dtabuf ); Fsetdta( savedta ); return( status ); } /* Display a window and highlight the items */ display( filename ) BYTE *filename; { LONG size; REG BYTE *addr; REG WINDOW *win; REG DIR *dir; REG WORD i; WORD newi,ret,first; size = Malloc( 0xFFFFFFFFL ); if ( size ) { addr = Malloc( size ); Dgetpath( addr, 0 ); i = strlen( addr ) + 20; Mfree( addr ); /* free the memory */ addr = Malloc( (LONG)i ); addr[0] = Dgetdrv() + 'A'; /* get the default drive */ addr[1] = ':'; Dgetpath( &addr[2], 0 ); strcat( bckslsh, addr ); strcat( getall, addr ); if ( f_rename ) { if ( c_path_alloc( addr ) ) { win = w_gfirst(); strcpy( addr, win->w_path ); Mfree( addr ); first = TRUE; if ( open_subdir( win, 0, FALSE, FALSE, FALSE ) ) { dir = win->w_memory; for ( i = 0; i < win->w_items; i++ ) { if ( wildcmp( filename, dir[i].d_name ) ) { if ( first ) { newi = i; first = FALSE; } dir[i].d_state = SELECTED; } } }/* open subdir */ else return( FALSE ); } else { Mfree( addr ); return( FALSE ); } } else { f_rename = TRUE; if ( win = alloc_win() ) /* check for window */ { /* win->w_sizes.x = full.x; win->w_sizes.y = full.y; win->w_sizes.w = full.w; win->w_sizes.h = full.h / 3; rc_copy( &win->w_sizes, &win->w_work ); */ win->w_free = TRUE; /* return window */ ret = open_disk( 0, addr, FALSE ); } else ret = FALSE; Mfree( addr ); if ( !ret ) return( FALSE ); win = w_gfirst(); dir = win->w_memory; first = TRUE; for ( i = 0; i < win->w_items; i++ ) { if ( wildcmp( filename, dir[i].d_name ) ) { if ( first ) { newi = i; first = FALSE; } dir[i].d_state = SELECTED; } } wait_msg(); } pos_item( win, newi ); return( TRUE ); }/* No memory */ return( FALSE ); } /* Put in wild card in the name string */ mass_string( str1 ) BYTE *str1; { REG WORD i; BYTE buffer[6]; i = 0; while( *str1 ) { if ( *str1 == '.' ) { if ( i < 8 ) { *str1++ = '*'; strcpy( str1, buffer ); } else strcpy( str1 + 1, buffer ); i = strlen( buffer ); if ( i < 3 ) buffer[i++] = '*'; buffer[i] = 0; *str1++ = '.'; strcpy( buffer, str1 ); return; } else i++; str1++; } strcpy( getall, str1 ); /* *.* */ }