implemented listing files (path to file as argument)
This commit is contained in:
1 parent
6293ef1740
commit
d256d2b863
3 files changed
+159
-119
No files matched your search
+92
-7
@@ -7,6 +7,7 @@
|
||||
|
||||
#include "display.h"
|
||||
#include "type_definitions.h"
|
||||
#include "arguments.h"
|
||||
#include "log.h"
|
||||
#include "format.h"
|
||||
#include "config.h"
|
||||
@@ -15,14 +16,20 @@
|
||||
// function signatures
|
||||
void set_type_style( const directory_entry_t* const entry );
|
||||
void set_file_style( const directory_entry_t* const entry );
|
||||
void display_permissions( const char* const permissions, bool no_colour );
|
||||
bool compare_makefile( const directory_entry_t* const entry );
|
||||
bool compare_archives( const directory_entry_t* const entry );
|
||||
bool compare_sources( const directory_entry_t* const entry );
|
||||
static void size_to_string(
|
||||
directory_entry_t* entry,
|
||||
const directory_entry_t* const entry,
|
||||
char* file_size,
|
||||
size_t length
|
||||
);
|
||||
void permissions_to_string(
|
||||
size_t file_mode,
|
||||
permission_mode_t permission_mode,
|
||||
char* const string
|
||||
);
|
||||
|
||||
// module logic
|
||||
void display_type( entry_type_t type, bool no_colour )
|
||||
@@ -78,7 +85,7 @@ void display_permissions( const char* const permissions, bool no_colour )
|
||||
fputc( ' ', stdout );
|
||||
}
|
||||
|
||||
void display_size( directory_entry_t *entry, bool no_colour )
|
||||
void display_size( const directory_entry_t* const entry, bool no_colour )
|
||||
{
|
||||
const size_t length = 9;
|
||||
char size_string[ length ];
|
||||
@@ -98,7 +105,7 @@ void display_size( directory_entry_t *entry, bool no_colour )
|
||||
fputc( ' ', stdout );
|
||||
}
|
||||
|
||||
void display_user( directory_entry_t* entry, bool no_colour )
|
||||
void display_user( const directory_entry_t* const entry, bool no_colour )
|
||||
{
|
||||
struct passwd* user = getpwuid( entry->stats.st_uid );
|
||||
const size_t length = 8;
|
||||
@@ -138,11 +145,32 @@ void display_time( time_t time, bool no_colour )
|
||||
fputc( ' ', stdout );
|
||||
}
|
||||
|
||||
void display_entry( const directory_entry_t* const entry, bool no_colour )
|
||||
void display_entry(
|
||||
const directory_entry_t* const entry,
|
||||
const arguments_t* const args
|
||||
)
|
||||
{
|
||||
if ( !entry ) return;
|
||||
|
||||
if ( !no_colour )
|
||||
if ( args->long_view && !args->tree_view )
|
||||
{
|
||||
const size_t PERMISSION_LENGTH = 11u;
|
||||
char file_permissions[ PERMISSION_LENGTH ];
|
||||
|
||||
permissions_to_string(
|
||||
entry->stats.st_mode,
|
||||
octal_permissions,
|
||||
file_permissions
|
||||
);
|
||||
|
||||
display_type( entry->type, args->no_colour );
|
||||
display_permissions( file_permissions, args->no_colour );
|
||||
display_size( entry, args->no_colour );
|
||||
display_user( entry, args->no_colour );
|
||||
display_time( entry->stats.st_mtime, args->no_colour );
|
||||
}
|
||||
|
||||
if ( !args->no_colour )
|
||||
{
|
||||
set_type_style( entry );
|
||||
}
|
||||
@@ -150,9 +178,18 @@ void display_entry( const directory_entry_t* const entry, bool no_colour )
|
||||
format_clear();
|
||||
|
||||
fputc( ' ', stdout );
|
||||
|
||||
if ( type_link == entry->type )
|
||||
{
|
||||
display_link_target( entry, args->no_colour );
|
||||
}
|
||||
fputc( '\n', stdout );
|
||||
}
|
||||
|
||||
void display_link_target(const directory_entry_t* const entry, bool no_colour )
|
||||
void display_link_target(
|
||||
const directory_entry_t* const entry,
|
||||
bool no_colour
|
||||
)
|
||||
{
|
||||
char link[ PATH_MAX ];
|
||||
ssize_t length = 0;
|
||||
@@ -282,7 +319,7 @@ bool compare_sources( const directory_entry_t* const entry )
|
||||
}
|
||||
|
||||
void size_to_string(
|
||||
directory_entry_t* entry,
|
||||
const directory_entry_t* const entry,
|
||||
char* file_size,
|
||||
size_t length
|
||||
)
|
||||
@@ -333,3 +370,51 @@ void size_to_string(
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void permissions_to_string(
|
||||
size_t file_mode,
|
||||
permission_mode_t permission_mode,
|
||||
char* const string
|
||||
)
|
||||
{
|
||||
const char PERMISSION_CHARS[] = { 'x', 'w', 'r' };
|
||||
|
||||
if ( !string ) return;
|
||||
|
||||
mode_t permissions = file_mode
|
||||
& ( S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO );
|
||||
|
||||
switch ( permission_mode )
|
||||
{
|
||||
case no_permissions:
|
||||
string[0] = '\0';
|
||||
break;
|
||||
|
||||
case char_permissions:
|
||||
string[ 0 ] = ' ';
|
||||
for ( int n = 0; n < 9; n++ )
|
||||
{
|
||||
if ( permissions & ( 1 << n ) )
|
||||
{
|
||||
string[ 9 - n ] = PERMISSION_CHARS[ n % 3 ];
|
||||
}
|
||||
else
|
||||
{
|
||||
string[ 9 - n ] = '-';
|
||||
}
|
||||
}
|
||||
string[ 10 ] = '\0';
|
||||
|
||||
break;
|
||||
|
||||
case octal_permissions:
|
||||
snprintf(
|
||||
&string[ 0 ],
|
||||
10,
|
||||
"%04o",
|
||||
permissions
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user