Sort galleries by name

This commit is contained in:
Stuart Longland 2008-01-10 15:12:56 +10:00
parent f59281a2fe
commit d38b420238

View File

@ -157,6 +157,13 @@ void va_rm_gallery( void* gallery ) {
destroy_gallery_info( (struct gallery_info*)gallery, 0 );
}
/* Helper Function: Compare two galleries ... used below */
int gallerycmp( const void* a_ptr, const void* b_ptr ) {
struct gallery_info* a = (struct gallery_info*)a_ptr;
struct gallery_info* b = (struct gallery_info*)b_ptr;
return strcasecmp( a->gallery_name, b->gallery_name );
}
/* The following function returns a linked-list of galleries known to the
* webapp, or NULL if such a list can't be constructed (due to memory
* constraints).
@ -232,10 +239,16 @@ struct gallery_list* list_galleries() {
*/
struct gallery_list* list =
(struct gallery_list*)export_obj_array( va );
/* Once this is done, we can dispense with the
* variable array and return the static one.
*/
destroy_vararray( va );
/* Sort the list before returning */
if ( list != NULL )
if ( list->length > 1 )
sort_array( (void**)list->gallery, list->length,
&gallerycmp );
return list;
}