show broken links with distinct style
This commit is contained in:
1 parent
9c65543633
commit
8bd7c06509
2 files changed
+49
-21
No files matched your search
+3
-3
@@ -48,9 +48,9 @@ const uint32_t fifo_colour = 0xEEEEEE;
|
||||
const style_t link_style[LINK_STYLE_NUM] = { style_none };
|
||||
const uint32_t link_colour = 0x19D1DE;
|
||||
|
||||
// #define BLNK_STYLE_NUM ( ( int )1 )
|
||||
// const style_t brokenlink_style[BLNK_STYLE_NUM] = { style_none };
|
||||
// const uint32_t brokenlink_colour = 0xEEEEEE;
|
||||
#define BLNK_STYLE_NUM ( ( int )1 )
|
||||
const style_t brokenlink_style[BLNK_STYLE_NUM] = { style_none };
|
||||
const uint32_t brokenlink_colour = 0xC00008;
|
||||
|
||||
#define SOCK_STYLE_NUM ( ( int )1 )
|
||||
const style_t socket_style[SOCK_STYLE_NUM] = { style_none };
|
||||
|
||||
+46
-18
@@ -55,6 +55,7 @@ static int display_directory_contents(
|
||||
size_t recursion_level,
|
||||
size_t is_last
|
||||
);
|
||||
void display_link_target(const directory_entry_t* const entry);
|
||||
void set_style( const directory_entry_t* const entry );
|
||||
void reset_style( const directory_entry_t* const entry );
|
||||
|
||||
@@ -393,24 +394,7 @@ int display_directory_contents(
|
||||
|
||||
if ( type_link == entry->type )
|
||||
{
|
||||
char link[ PATH_MAX ];
|
||||
ssize_t length = 0;
|
||||
|
||||
length = readlink( entry->name, &link[ 0 ], PATH_MAX );
|
||||
|
||||
if ( 0 > length )
|
||||
{
|
||||
log_error( "failed to read link '%s'", entry->name );
|
||||
}
|
||||
link[ length ] = '\0';
|
||||
|
||||
fprintf( stdout, " --> ");
|
||||
|
||||
format_set_style( &link_style[ 0 ], LINK_STYLE_NUM );
|
||||
format_set_fg_colour( link_colour );
|
||||
fprintf( stdout, "%s", link );
|
||||
format_reset_style( &link_style[ 0 ], LINK_STYLE_NUM );
|
||||
format_clear_fg_colour();
|
||||
display_link_target( entry );
|
||||
}
|
||||
|
||||
fputc( '\n', stdout );
|
||||
@@ -502,6 +486,50 @@ void size_to_string(
|
||||
}
|
||||
}
|
||||
|
||||
void display_link_target(const directory_entry_t* const entry)
|
||||
{
|
||||
char link[ PATH_MAX ];
|
||||
ssize_t length = 0;
|
||||
struct stat link_stat;
|
||||
int link_invalid;
|
||||
|
||||
length = readlink( entry->name, &link[ 0 ], PATH_MAX );
|
||||
|
||||
if ( 0 > length )
|
||||
{
|
||||
log_error( "failed to read link '%s'", entry->name );
|
||||
}
|
||||
|
||||
link[ length ] = '\0';
|
||||
link_invalid = stat( link, &link_stat );
|
||||
|
||||
fprintf( stdout, " --> ");
|
||||
|
||||
if ( link_invalid )
|
||||
{
|
||||
format_set_style( &brokenlink_style[ 0 ], BLNK_STYLE_NUM );
|
||||
format_set_fg_colour( brokenlink_colour );
|
||||
}
|
||||
else
|
||||
{
|
||||
format_set_style( &link_style[ 0 ], LINK_STYLE_NUM );
|
||||
format_set_fg_colour( link_colour );
|
||||
}
|
||||
|
||||
fprintf( stdout, "%s", link );
|
||||
|
||||
if ( link_invalid )
|
||||
{
|
||||
format_reset_style( &brokenlink_style[ 0 ], BLNK_STYLE_NUM );
|
||||
format_clear_fg_colour();
|
||||
}
|
||||
else
|
||||
{
|
||||
format_reset_style( &link_style[ 0 ], LINK_STYLE_NUM );
|
||||
format_clear_fg_colour();
|
||||
}
|
||||
}
|
||||
|
||||
void set_style( const directory_entry_t* const entry )
|
||||
{
|
||||
switch ( entry->type )
|
||||
|
||||
Reference in new issue
Block a user