nav_flat.c File Reference


Detailed Description

FAT 12/16/32 Services.

This plug-in allow a navigation in FLAT mode This plug-in is connected on the navigation module. The flat mode includes in the file list all directories and all files of the current directory AND the sub directories Before use the flat mode, you must call nav_partition_mount() to reset navigation

Author:
Atmel Corporation: http://www.atmel.com
Support and FAQ: http://support.atmel.no/

Definition in file nav_flat.c.

#include "conf_explorer.h"
#include "navigation.h"
#include "nav_flat.h"
#include "file.h"
#include "ctrl_access.h"

Go to the source code of this file.

Functions

Bool nav_flat_cd (void)
 This function enters in the selected directory in file list FLAT.
Bool nav_flat_fileisnotopen (void)
 This function checks if no file is opened.
Bool nav_flat_findname (const FS_STRING sz_name, Bool b_match_case)
 This function searchs a file name in file list FLAT.
U16 nav_flat_get (void)
 This function returns the position of selected file in file list FLAT.
Bool nav_flat_goto (U16 u16_newpos)
 This function goes to a position in file list FLAT.
Bool nav_flat_gotoparent (void)
 This function goes to the parent directory.
Bool nav_flat_mount (void)
 This function mounts the selected partition.
U16 nav_flat_nb (void)
 This function computes the number of files and directories present in the file list FLAT.
Bool nav_flat_next (void)
 Go to next file or directory in file list FLAT.
Bool nav_flat_previous (void)
 Go to previous file or directory in file list FLAT.
Bool nav_flat_reset (void)
 This function resets the selection pointer, so "no file is selected" in file list FLAT.
Bool nav_flat_root (void)
 This function initializes the file filtered list on the root directory.
Bool nav_flat_validpos (void)
 This function checks if a file is selected.


Function Documentation

Bool nav_flat_cd ( void   ) 

This function enters in the selected directory in file list FLAT.

Returns:
FALSE in case of error, see global value "fs_g_status" for more detail

TRUE otherwise

Definition at line 324 of file nav_flat.c.

References fs_g_nav, nav_dir_cd(), Fs_management::u16_flat_pos_offset, and Fs_management::u8_flat_dir_level.

00325 {
00326    if( !nav_dir_cd() )
00327       return FALSE;
00328    fs_g_nav.u8_flat_dir_level   = 0;
00329    fs_g_nav.u16_flat_pos_offset = 0;
00330    return TRUE;
00331 }

Bool nav_flat_fileisnotopen ( void   ) 

This function checks if no file is opened.

Returns:
TRUE if no file is opened

FALSE if a file is opened

Definition at line 124 of file nav_flat.c.

References nav_filelist_fileisnotopen().

00125 {
00126    return nav_filelist_fileisnotopen();
00127 }

Bool nav_flat_findname ( const FS_STRING  sz_name,
Bool  b_match_case 
)

This function searchs a file name in file list FLAT.

Parameters:
sz_name name to search (UNICODE or ASCII)
It must be terminated by NULL or '*' value
b_match_case FALSE to ignore the case
Returns:
FALSE in case of error, see global value "fs_g_status" for more detail

TRUE otherwise

//! This function starts a search at the next position of the current in file list 
//! 

Definition at line 278 of file nav_flat.c.

References FS_NAME_CHECK, nav_file_name(), and nav_flat_next().

00279 {
00280    while( 1 )
00281    {
00282       if ( !nav_flat_next() )
00283          return FALSE;
00284       if ( nav_file_name( sz_name , 0 , FS_NAME_CHECK , b_match_case ))
00285          return TRUE;
00286    }
00287 }

U16 nav_flat_get ( void   ) 

This function returns the position of selected file in file list FLAT.

Returns:
position of selected file (0 is the first position)

FS_NO_SEL, in case of no file selected

Definition at line 223 of file nav_flat.c.

References fs_g_nav, nav_filelist_get(), and Fs_management::u16_flat_pos_offset.

Referenced by nav_flat_goto(), and nav_flat_nb().

00224 {
00225    return (fs_g_nav.u16_flat_pos_offset + nav_filelist_get());
00226 }

Bool nav_flat_goto ( U16  u16_newpos  ) 

This function goes to a position in file list FLAT.

Parameters:
u16_newpos new position to select (0 is the first position)
Returns:
FALSE in case of error, see global value "fs_g_status" for more detail

TRUE otherwise

Definition at line 236 of file nav_flat.c.

References nav_flat_get(), nav_flat_next(), nav_flat_previous(), nav_flat_reset(), and nav_flat_validpos().

Referenced by nav_flat_nb().

00237 {
00238    if (u16_newpos < (nav_flat_get()/2))
00239    {
00240       // Restart at the beginning of list to accelerate the search
00241       if (!nav_flat_reset())
00242          return FALSE;      
00243    }
00244    if (!nav_flat_validpos())
00245    {
00246       // Go to first position
00247       if (!nav_flat_next())
00248          return FALSE;  // Empty list
00249    }
00250    
00251    while(u16_newpos < nav_flat_get())
00252    {
00253       if( !nav_flat_previous())
00254          return FALSE; // Position error
00255    }
00256    while(u16_newpos > nav_flat_get())
00257    {
00258       if( !nav_flat_next())
00259          return FALSE; // End of the list, then the position is bad
00260    }
00261    return TRUE;
00262 }

Bool nav_flat_gotoparent ( void   ) 

This function goes to the parent directory.

Returns:
FALSE in case of error, see global value "fs_g_status" for more detail

TRUE otherwise

//! After the selected file is the first entry of the new file list FLAT
//! 

Definition at line 343 of file nav_flat.c.

References fs_g_nav, nav_dir_gotoparent(), nav_filelist_reset(), nav_flat_next(), nav_getindex(), nav_gotoindex(), Fs_management::u16_flat_pos_offset, and Fs_management::u8_flat_dir_level.

00344 {
00345    _MEM_TYPE_SLOW_ Fs_index index;
00346    index = nav_getindex();
00347    while( 0 != fs_g_nav.u8_flat_dir_level ) 
00348    {
00349       fs_g_nav.u8_flat_dir_level--;
00350       nav_dir_gotoparent();
00351    }
00352    if( !nav_dir_gotoparent() )
00353    {
00354       nav_gotoindex( &index );
00355       return FALSE;
00356    }
00357    // Go to at the beginning of FLAT list
00358    fs_g_nav.u8_flat_dir_level   = 0;
00359    fs_g_nav.u16_flat_pos_offset = 0;
00360    nav_filelist_reset();
00361    nav_flat_next();
00362    return TRUE;
00363 }

Bool nav_flat_mount ( void   ) 

This function mounts the selected partition.

Returns:
FALSE in case of error, see global value "fs_g_status" for more detail

TRUE otherwise

//! If the FS_MULTI_PARTITION option is disabled
//! then the mount routine selects the first partition supported by file system. <br>
//! After mount, the file list contains files and directories of ROOT directory 
//! 

Definition at line 71 of file nav_flat.c.

References fs_g_nav, nav_partition_mount(), Fs_management::u16_flat_pos_offset, and Fs_management::u8_flat_dir_level.

00072 {
00073    fs_g_nav.u8_flat_dir_level = 0;
00074    fs_g_nav.u16_flat_pos_offset = 0;   
00075    return nav_partition_mount();
00076 }

U16 nav_flat_nb ( void   ) 

This function computes the number of files and directories present in the file list FLAT.

Returns:
number of files and directories present in the file list FLAT

Definition at line 294 of file nav_flat.c.

References nav_flat_get(), nav_flat_goto(), nav_flat_next(), and nav_flat_reset().

00295 {
00296    U16   u16_save_position;
00297    U16   u16_number;
00298    
00299    // Save current position
00300    u16_save_position = nav_flat_get();
00301 
00302    // Reset position
00303    if ( !nav_flat_reset())
00304       return 0;
00305 
00306    // Scan all directories
00307    u16_number  = 0;
00308    while( nav_flat_next() )
00309    {
00310       u16_number++;
00311    }
00312    // Restore previous position
00313    nav_flat_goto( u16_save_position );
00314 
00315    return u16_number;
00316 }

Bool nav_flat_next ( void   ) 

Go to next file or directory in file list FLAT.

Returns:
FALSE in case of error, see global value "fs_g_status" for more detail

TRUE otherwise

Definition at line 135 of file nav_flat.c.

References FS_FIND_NEXT, fs_g_nav, nav_dir_cd(), nav_dir_gotoparent(), nav_file_isdir(), nav_filelist_get(), nav_filelist_set(), Fs_management::u16_flat_pos_offset, and Fs_management::u8_flat_dir_level.

Referenced by nav_flat_findname(), nav_flat_goto(), nav_flat_gotoparent(), and nav_flat_nb().

00136 {
00137    U16 u16_save_current_pos;
00138    
00139    u16_save_current_pos = nav_filelist_get();
00140    if( nav_file_isdir() ) 
00141    {
00142       // The current file is a dir then enter in this
00143       if( !nav_dir_cd() )
00144          return FALSE;
00145       if( nav_filelist_set( 0 , FS_FIND_NEXT ) )
00146       {
00147          // A file is present in this dir then valid the new position
00148          fs_g_nav.u8_flat_dir_level++;
00149          fs_g_nav.u16_flat_pos_offset += u16_save_current_pos+1;
00150          return TRUE;
00151       }else{
00152          // No file then return in parent dir
00153          if( !nav_dir_gotoparent() )
00154             return FALSE;  // Error
00155       }
00156    }
00157    // Find next file in the current dir or the parent dir
00158    while( !nav_filelist_set( 0 , FS_FIND_NEXT ) )
00159    {
00160       // End of the directory then goes to parent
00161       if( 0 == fs_g_nav.u8_flat_dir_level )
00162          return FALSE;  // End of list FLAT
00163       if( !nav_dir_gotoparent() )
00164          return FALSE;  // Error
00165       fs_g_nav.u8_flat_dir_level--;
00166    }
00167    fs_g_nav.u16_flat_pos_offset = (fs_g_nav.u16_flat_pos_offset +u16_save_current_pos +1) -nav_filelist_get();
00168    return TRUE;
00169 }

Bool nav_flat_previous ( void   ) 

Go to previous file or directory in file list FLAT.

Returns:
FALSE in case of error, see global value "fs_g_status" for more detail

TRUE otherwise

Definition at line 177 of file nav_flat.c.

References FS_FIND_NEXT, FS_FIND_PREV, fs_g_nav, nav_dir_cd(), nav_dir_gotoparent(), nav_file_isdir(), nav_filelist_get(), nav_filelist_set(), Fs_management::u16_flat_pos_offset, and Fs_management::u8_flat_dir_level.

Referenced by nav_flat_goto().

00178 {
00179    U16 u16_save_current_pos;
00180    
00181    u16_save_current_pos = nav_filelist_get();
00182    if( nav_filelist_set( 0 , FS_FIND_PREV ) )
00183    {
00184       while( 1 )
00185       {
00186          if( !nav_file_isdir() ) 
00187          {
00188             fs_g_nav.u16_flat_pos_offset = ((fs_g_nav.u16_flat_pos_offset +u16_save_current_pos) -nav_filelist_get()) -1;
00189             return TRUE;   // New valid position
00190          }
00191          // The selection is a dir then enter in this
00192          if( !nav_dir_cd() )
00193             return FALSE;
00194          if( !nav_filelist_set( 0 , FS_FIND_NEXT ) )
00195          {
00196             // The dir is empty then goes to the parent
00197             nav_dir_gotoparent();
00198             // The parent dir is the new selection
00199             fs_g_nav.u16_flat_pos_offset = ((fs_g_nav.u16_flat_pos_offset +u16_save_current_pos) -nav_filelist_get()) -1;
00200             return TRUE;
00201          }
00202          fs_g_nav.u8_flat_dir_level++;
00203          // Go to the end of dir 
00204          while( nav_filelist_set( 0 , FS_FIND_NEXT ) );
00205       }
00206    }
00207    // Beginning of the directory then goes to parent directory
00208    if( 0 == fs_g_nav.u8_flat_dir_level )
00209       return FALSE;  // beginning of the file list FLAT
00210    if( !nav_dir_gotoparent() )
00211       return FALSE;
00212    fs_g_nav.u8_flat_dir_level--;
00213    fs_g_nav.u16_flat_pos_offset -= (nav_filelist_get()+1);
00214    return TRUE;
00215 }

Bool nav_flat_reset ( void   ) 

This function resets the selection pointer, so "no file is selected" in file list FLAT.

Returns:
FALSE in case of error, see global value "fs_g_status" for more detail

TRUE otherwise

Definition at line 96 of file nav_flat.c.

References fs_g_nav, nav_dir_gotoparent(), nav_filelist_reset(), Fs_management::u16_flat_pos_offset, and Fs_management::u8_flat_dir_level.

Referenced by nav_flat_goto(), and nav_flat_nb().

00097 {
00098    while( 0 != fs_g_nav.u8_flat_dir_level ) 
00099    {
00100       fs_g_nav.u8_flat_dir_level--;
00101       nav_dir_gotoparent();
00102    }
00103    fs_g_nav.u16_flat_pos_offset = 0;
00104    return nav_filelist_reset();
00105 }

Bool nav_flat_root ( void   ) 

This function initializes the file filtered list on the root directory.

This function initializes the falt list on the root directory.

Returns:
FALSE in case of error, see global value "fs_g_status" for more detail

TRUE otherwise

Definition at line 84 of file nav_flat.c.

References fs_g_nav, nav_dir_root(), Fs_management::u16_flat_pos_offset, and Fs_management::u8_flat_dir_level.

00085 {
00086    fs_g_nav.u8_flat_dir_level = 0;
00087    fs_g_nav.u16_flat_pos_offset = 0;   
00088    return nav_dir_root();
00089 }

Bool nav_flat_validpos ( void   ) 

This function checks if a file is selected.

Returns:
TRUE if a file is selected

FALSE if no file is selected

Definition at line 113 of file nav_flat.c.

References nav_filelist_validpos().

Referenced by nav_flat_goto().

00114 {
00115    return nav_filelist_validpos();
00116 }


Generated on Fri Feb 19 02:29:46 2010 for AVR32 UC3 - FSACCESS Services by  doxygen 1.5.5