light refactoring

This commit is contained in:
root committed 2026-10-08 21:48:35 +02:00
1 parent 4a8132c0b1
commit 5b1b974ac7
6 files changed
+97 -137

No files matched your search

+46 -75
View File
@@ -12,11 +12,44 @@
#include "stringing.h"
// function signatures
void set_type_style( const directory_entry_t* const entry );
void set_file_style( const directory_entry_t* const entry );
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 );
// module logic
void display_type( char type )
{
format_set_style( type_style, TYPE_STYLE_NUM );
format_set_colour( type_colour );
fprintf( stdout, "%c", type );
format_clear();
}
void display_permissions( const char* const permissions )
{
format_set_style( permission_style, PERM_STYLE_NUM );
format_set_colour( permission_colour );
fprintf( stdout, "%s", permissions );
format_clear();
}
void display_size( const char* const size )
{
format_set_style( size_style, SIZE_STYLE_NUM );
format_set_colour( size_colour );
fprintf( stdout, "%s", size );
format_clear();
}
void display_entry( const directory_entry_t* const entry )
{
set_type_style( entry );
fprintf( stdout, "%s", entry->name );
format_clear();
}
void display_link_target(const directory_entry_t* const entry)
{
char link[ PATH_MAX ];
@@ -39,12 +72,12 @@ void display_link_target(const directory_entry_t* const entry)
if ( link_invalid )
{
format_set_style( &brokenlink_style[ 0 ], BLNK_STYLE_NUM );
format_set_fg_colour( brokenlink_colour );
format_set_colour( brokenlink_colour );
}
else
{
format_set_style( &link_style[ 0 ], LINK_STYLE_NUM );
format_set_fg_colour( link_colour );
format_set_colour( link_colour );
}
fprintf( stdout, "%s", link );
@@ -52,12 +85,12 @@ void display_link_target(const directory_entry_t* const entry)
if ( link_invalid )
{
format_reset_style( &brokenlink_style[ 0 ], BLNK_STYLE_NUM );
format_clear_fg_colour();
format_clear_colour();
}
else
{
format_reset_style( &link_style[ 0 ], LINK_STYLE_NUM );
format_clear_fg_colour();
format_clear_colour();
}
}
@@ -67,27 +100,27 @@ void set_type_style( const directory_entry_t* const entry )
{
case type_block:
format_set_style( &block_style[ 0 ], BLK_STYLE_NUM );
format_set_fg_colour( block_colour );
format_set_colour( block_colour );
break;
case type_character:
format_set_style( &character_style[ 0 ], CHAR_STYLE_NUM );
format_set_fg_colour( character_colour );
format_set_colour( character_colour );
break;
case type_directory:
format_set_style( &directory_style[ 0 ], DIR_STYLE_NUM );
format_set_fg_colour( directory_colour );
format_set_colour( directory_colour );
break;
case type_fifo:
format_set_style( &fifo_style[ 0 ], FIFO_STYLE_NUM );
format_set_fg_colour( fifo_colour );
format_set_colour( fifo_colour );
break;
case type_link:
format_set_style( &link_style[ 0 ], LINK_STYLE_NUM );
format_set_fg_colour( link_colour );
format_set_colour( link_colour );
break;
case type_regular:
@@ -96,47 +129,7 @@ void set_type_style( const directory_entry_t* const entry )
case type_socket:
format_set_style( &socket_style[ 0 ], SOCK_STYLE_NUM );
format_set_fg_colour( socket_colour );
break;
}
}
void reset_type_style( const directory_entry_t* const entry )
{
switch ( entry->type )
{
case type_block:
format_reset_style( &block_style[ 0 ], BLK_STYLE_NUM );
format_clear_fg_colour();
break;
case type_character:
format_reset_style( &character_style[ 0 ], CHAR_STYLE_NUM );
format_clear_fg_colour();
break;
case type_directory:
format_reset_style( &directory_style[ 0 ], DIR_STYLE_NUM );
format_clear_fg_colour();
break;
case type_fifo:
format_reset_style( &fifo_style[ 0 ], FIFO_STYLE_NUM );
format_clear_fg_colour();
break;
case type_link:
format_reset_style( &link_style[ 0 ], LINK_STYLE_NUM );
format_clear_fg_colour();
break;
case type_regular:
reset_file_style( entry );
break;
case type_socket:
format_reset_style( &socket_style[ 0 ], SOCK_STYLE_NUM );
format_clear_fg_colour();
format_set_colour( socket_colour );
break;
}
}
@@ -149,39 +142,17 @@ void set_file_style( const directory_entry_t* const entry )
if ( compare_makefile( entry ) )
{
format_set_style( &makefile_style[ 0 ], MAKE_STYLE_NUM );
format_set_fg_colour( makefile_colour );
format_set_colour( makefile_colour );
}
else if ( compare_archives( entry ) )
{
format_set_style( &archive_style[ 0 ], AR_STYLE_NUM );
format_set_fg_colour( archive_colour );
format_set_colour( archive_colour );
}
else if ( compare_sources( entry ) )
{
format_set_style( &source_style[ 0 ], SRC_STYLE_NUM );
format_set_fg_colour( source_colour );
}
}
void reset_file_style( const directory_entry_t* const entry )
{
if ( !entry ) return;
// makefiles and readmes
if ( compare_makefile( entry ) )
{
format_reset_style( &makefile_style[ 0 ], MAKE_STYLE_NUM );
format_clear_fg_colour();
}
else if ( compare_archives( entry ) )
{
format_reset_style( &archive_style[ 0 ], AR_STYLE_NUM );
format_clear_fg_colour();
}
else if ( compare_sources( entry ) )
{
format_reset_style( &source_style[ 0 ], SRC_STYLE_NUM );
format_clear_fg_colour();
format_set_colour( source_colour );
}
}