show broken links with distinct style
This commit is contained in:
1 parent
9c65543633
commit
8bd7c06509
2 files changed
+70
-42
No files matched your search
+24
-24
@@ -28,37 +28,37 @@
|
|||||||
// const uint32_t size_colour = 0xEEEEEE;
|
// const uint32_t size_colour = 0xEEEEEE;
|
||||||
|
|
||||||
// files by type
|
// files by type
|
||||||
#define BLK_STYLE_NUM ( ( int )1 )
|
#define BLK_STYLE_NUM ( ( int )1 )
|
||||||
const style_t block_style[BLK_STYLE_NUM] = { style_none };
|
const style_t block_style[BLK_STYLE_NUM] = { style_none };
|
||||||
const uint32_t block_colour = 0xFFCC13;
|
const uint32_t block_colour = 0xFFCC13;
|
||||||
|
|
||||||
#define CHAR_STYLE_NUM ( ( int )1 )
|
#define CHAR_STYLE_NUM ( ( int )1 )
|
||||||
const style_t character_style[CHAR_STYLE_NUM] = { style_none };
|
const style_t character_style[CHAR_STYLE_NUM] = { style_none };
|
||||||
const uint32_t character_colour = 0xEEEEEE;
|
const uint32_t character_colour = 0xEEEEEE;
|
||||||
|
|
||||||
#define DIR_STYLE_NUM ( ( int )1 )
|
#define DIR_STYLE_NUM ( ( int )1 )
|
||||||
const style_t directory_style[DIR_STYLE_NUM] = { style_bold };
|
const style_t directory_style[DIR_STYLE_NUM] = { style_bold };
|
||||||
const uint32_t directory_colour = 0x6CA05C;
|
const uint32_t directory_colour = 0x6CA05C;
|
||||||
|
|
||||||
#define FIFO_STYLE_NUM ( ( int )1 )
|
#define FIFO_STYLE_NUM ( ( int )1 )
|
||||||
const style_t fifo_style[FIFO_STYLE_NUM] = { style_none };
|
const style_t fifo_style[FIFO_STYLE_NUM] = { style_none };
|
||||||
const uint32_t fifo_colour = 0xEEEEEE;
|
const uint32_t fifo_colour = 0xEEEEEE;
|
||||||
|
|
||||||
#define LINK_STYLE_NUM ( ( int )1 )
|
#define LINK_STYLE_NUM ( ( int )1 )
|
||||||
const style_t link_style[LINK_STYLE_NUM] = { style_none };
|
const style_t link_style[LINK_STYLE_NUM] = { style_none };
|
||||||
const uint32_t link_colour = 0x19D1DE;
|
const uint32_t link_colour = 0x19D1DE;
|
||||||
|
|
||||||
// #define BLNK_STYLE_NUM ( ( int )1 )
|
#define BLNK_STYLE_NUM ( ( int )1 )
|
||||||
// const style_t brokenlink_style[BLNK_STYLE_NUM] = { style_none };
|
const style_t brokenlink_style[BLNK_STYLE_NUM] = { style_none };
|
||||||
// const uint32_t brokenlink_colour = 0xEEEEEE;
|
const uint32_t brokenlink_colour = 0xC00008;
|
||||||
|
|
||||||
#define SOCK_STYLE_NUM ( ( int )1 )
|
#define SOCK_STYLE_NUM ( ( int )1 )
|
||||||
const style_t socket_style[SOCK_STYLE_NUM] = { style_none };
|
const style_t socket_style[SOCK_STYLE_NUM] = { style_none };
|
||||||
const uint32_t socket_colour = 0xEEEEEE;
|
const uint32_t socket_colour = 0xEEEEEE;
|
||||||
|
|
||||||
#define EXEC_STYLE_NUM ( ( int )1 )
|
#define EXEC_STYLE_NUM ( ( int )1 )
|
||||||
const style_t exec_style[EXEC_STYLE_NUM] = { style_none };
|
const style_t exec_style[EXEC_STYLE_NUM] = { style_none };
|
||||||
const uint32_t exec_colour = 0xEEEEEE;
|
const uint32_t exec_colour = 0xEEEEEE;
|
||||||
|
|
||||||
// // files by extension
|
// // files by extension
|
||||||
// #define MAKE_STYLE_NUM ( ( int )1 )
|
// #define MAKE_STYLE_NUM ( ( int )1 )
|
||||||
|
|||||||
+46
-18
@@ -55,6 +55,7 @@ static int display_directory_contents(
|
|||||||
size_t recursion_level,
|
size_t recursion_level,
|
||||||
size_t is_last
|
size_t is_last
|
||||||
);
|
);
|
||||||
|
void display_link_target(const directory_entry_t* const entry);
|
||||||
void set_style( const directory_entry_t* const entry );
|
void set_style( const directory_entry_t* const entry );
|
||||||
void reset_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 )
|
if ( type_link == entry->type )
|
||||||
{
|
{
|
||||||
char link[ PATH_MAX ];
|
display_link_target( entry );
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fputc( '\n', stdout );
|
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 )
|
void set_style( const directory_entry_t* const entry )
|
||||||
{
|
{
|
||||||
switch ( entry->type )
|
switch ( entry->type )
|
||||||
|
|||||||
Reference in new issue
Block a user