implemented handling of multiple path arguments
This commit is contained in:
1 parent
030ca4584a
commit
6293ef1740
3 files changed
+43
-37
No files matched your search
+4
-1
@@ -10,6 +10,8 @@
|
||||
#include <stdbool.h>
|
||||
#include <argp.h>
|
||||
|
||||
#define MAX_PATH_NUM ( ( int )256 )
|
||||
|
||||
typedef enum {
|
||||
no_permissions = 0,
|
||||
char_permissions = 1,
|
||||
@@ -44,7 +46,8 @@ typedef struct {
|
||||
permission_mode_t permission_mode;
|
||||
sorting_mode_t sorting_mode;
|
||||
time_mode_t time_mode;
|
||||
char* path;
|
||||
char* path[MAX_PATH_NUM];
|
||||
size_t path_count;
|
||||
} arguments_t;
|
||||
|
||||
void initialise_args( arguments_t* arguments );
|
||||
|
||||
+6
-9
@@ -172,7 +172,8 @@ void initialise_args( arguments_t* arguments )
|
||||
arguments->permission_mode = octal_permissions;
|
||||
arguments->sorting_mode = sort_by_extension;
|
||||
arguments->time_mode = time_none;
|
||||
arguments->path = ".";
|
||||
arguments->path[ 0 ] = ".";
|
||||
arguments->path_count = 1u;
|
||||
}
|
||||
|
||||
|
||||
@@ -309,15 +310,11 @@ static error_t arg_parser( int key, char* arg, struct argp_state* state )
|
||||
}
|
||||
break;
|
||||
case ARGP_KEY_ARG:
|
||||
// TODO: handle multiple paths
|
||||
if ( 0 == state->arg_num )
|
||||
{
|
||||
arguments->path = arg;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ARGP_ERR_UNKNOWN;
|
||||
}
|
||||
arguments->path_count = 0u;
|
||||
|
||||
arguments->path[ arguments->path_count ] = arg;
|
||||
arguments->path_count++;
|
||||
break;
|
||||
default:
|
||||
return ARGP_ERR_UNKNOWN;
|
||||
|
||||
+33
-27
@@ -60,40 +60,46 @@ int main( int argc, char** argv )
|
||||
if ( args.display_help )
|
||||
return SUCCESS;
|
||||
|
||||
DIR* directory = opendir( args.path );
|
||||
|
||||
if ( !directory )
|
||||
for ( size_t n = 0; n < args.path_count; n++ )
|
||||
{
|
||||
if ( ENOENT == errno )
|
||||
DIR* directory = opendir( args.path[ n ] );
|
||||
|
||||
if ( !directory )
|
||||
{
|
||||
log_error( "no directory `%s`", args.path );
|
||||
return -ENOENT;
|
||||
if ( ENOENT == errno )
|
||||
{
|
||||
log_error( "no directory `%s`", args.path[ n ] );
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
log_error( "failed to open directory `%s`", args.path[ n ] );
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
log_error( "failed to open directory `%s`", args.path );
|
||||
return -EIO;
|
||||
}
|
||||
if ( args.tree_view )
|
||||
log_info( "%s", args.path[ n ] );
|
||||
|
||||
if ( args.tree_view )
|
||||
log_info( "%s", args.path );
|
||||
if ( !chdir( args.path[ n ] ) )
|
||||
{
|
||||
// TODO: handle return code
|
||||
handle_directory(
|
||||
&args,
|
||||
directory,
|
||||
0,
|
||||
0
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
log_error( "failed to enter directory '%s'", args.path[ n ] );
|
||||
retval = -EIO;
|
||||
}
|
||||
|
||||
if ( !chdir( args.path ) )
|
||||
{
|
||||
// TODO: handle return code
|
||||
handle_directory(
|
||||
&args,
|
||||
directory,
|
||||
0,
|
||||
0
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
log_error( "failed to enter directory '%s'", args.path );
|
||||
retval = -EIO;
|
||||
}
|
||||
chdir( ".." );
|
||||
closedir( directory );
|
||||
|
||||
closedir( directory );
|
||||
fputc( '\n', stdout );
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user