implemented handling of multiple path arguments

This commit is contained in:
root committed 2026-10-09 17:00:50 +02:00
1 parent 030ca4584a
commit 6293ef1740
3 files changed
+43 -37

No files matched your search

+6 -9
View File
@@ -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
View File
@@ -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;
}