implemented sorting by extension
This commit is contained in:
1 parent
cdfa9fec4e
commit
b81dcc10ac
4 files changed
+134
-78
No files matched your search
+41
-26
@@ -57,10 +57,28 @@ int sort_entries(
|
||||
|
||||
__compar_fn_t compare_function;
|
||||
|
||||
if ( true == args->case_sensitive_sorting )
|
||||
{
|
||||
compare_function = compare_string_case_sensitive;
|
||||
}
|
||||
else
|
||||
{
|
||||
compare_function = compare_string_case_insensitive;
|
||||
}
|
||||
|
||||
if ( args->sorting_mode != sort_by_name )
|
||||
{
|
||||
qsort(
|
||||
( void* )entry_table,
|
||||
( size_t )num_entries,
|
||||
sizeof( *entry_table ),
|
||||
compare_function
|
||||
);
|
||||
}
|
||||
|
||||
switch ( args->sorting_mode )
|
||||
{
|
||||
case sort_by_name:
|
||||
compare_function = compare_string_case_insensitive;
|
||||
break;
|
||||
case sort_by_extension:
|
||||
compare_function = compare_extension;
|
||||
@@ -162,30 +180,19 @@ int compare_extension(
|
||||
exit( -EINVAL );
|
||||
}
|
||||
|
||||
// directory_entry_t* a = *( directory_entry_t** )operand_a;
|
||||
// directory_entry_t* b = *( directory_entry_t** )operand_b;
|
||||
// char* extension;
|
||||
//
|
||||
// size_t len_a = strnlen(a->name, NAME_MAX);
|
||||
// size_t len_b = strnlen(b->name, NAME_MAX);
|
||||
//
|
||||
// char* entry_a = ( char* )calloc(
|
||||
// len_b,
|
||||
// sizeof( char )
|
||||
// );
|
||||
// char* entry_b = ( char* )calloc(
|
||||
// len_b,
|
||||
// sizeof( char )
|
||||
// );
|
||||
//
|
||||
// extension = strrchr( a->name, '.' );
|
||||
//
|
||||
// strncpy( &entry_a[ 0 ], )
|
||||
//
|
||||
// free( entry_a );
|
||||
// free( entry_b );
|
||||
directory_entry_t* a = *( directory_entry_t** )operand_a;
|
||||
directory_entry_t* b = *( directory_entry_t** )operand_b;
|
||||
char* extension_a = strrchr( a->name, '.' );
|
||||
char* extension_b = strrchr( b->name, '.' );
|
||||
|
||||
return 0;
|
||||
if ( extension_a == a->name ) extension_a = NULL;
|
||||
if ( extension_b == b->name ) extension_b = NULL;
|
||||
|
||||
if ( !extension_a && !extension_b ) return 0;
|
||||
if ( !extension_a && extension_b ) return -1;
|
||||
if ( extension_a && !extension_b ) return 1;
|
||||
|
||||
return compare_strings( extension_a, extension_b, NAME_MAX, false );
|
||||
}
|
||||
|
||||
int compare_timestamp(
|
||||
@@ -198,7 +205,11 @@ int compare_timestamp(
|
||||
log_error( "invalid parameter to compare function" );
|
||||
exit( -EINVAL );
|
||||
}
|
||||
return 0;
|
||||
|
||||
directory_entry_t* a = *( directory_entry_t** )operand_a;
|
||||
directory_entry_t* b = *( directory_entry_t** )operand_b;
|
||||
|
||||
return ( int )( b->stats.st_mtim.tv_sec - a->stats.st_mtim.tv_sec );
|
||||
}
|
||||
|
||||
int compare_size(
|
||||
@@ -211,5 +222,9 @@ int compare_size(
|
||||
log_error( "invalid parameter to compare function" );
|
||||
exit( -EINVAL );
|
||||
}
|
||||
return 0;
|
||||
|
||||
directory_entry_t* a = *( directory_entry_t** )operand_a;
|
||||
directory_entry_t* b = *( directory_entry_t** )operand_b;
|
||||
|
||||
return ( int )( b->stats.st_size - a->stats.st_size );
|
||||
}
|
||||
Reference in new issue
Block a user