+#define META_STRCASECMP_NAME( i, i_small ) { \
+ char *psz_i = input_item_GetName( pp_items[i]->p_input ); \
+ char *psz_ismall = input_item_GetName( pp_items[i_small]->p_input ); \
+ i_test = strcasecmp( psz_i, psz_ismall ); \
+ free( psz_i ); \
+ free( psz_ismall ); \
+}
+
+
+#define DO_META_SORT( node ) { \
+ char *psz_a = input_item_GetMeta( pp_items[i]->p_input, vlc_meta_##node ); \
+ char *psz_b = input_item_GetMeta( pp_items[i_small]->p_input, vlc_meta_##node ); \
+ /* Nodes go first */ \
+ if( pp_items[i]->i_children == -1 && pp_items[i_small]->i_children >= 0 ) \
+ i_test = 1;\
+ else if( pp_items[i]->i_children >= 0 &&\
+ pp_items[i_small]->i_children == -1 ) \
+ i_test = -1; \
+ /* Both are nodes, sort by name */ \
+ else if( pp_items[i]->i_children >= 0 && \
+ pp_items[i_small]->i_children >= 0 ) \
+ { \
+ META_STRCASECMP_NAME( i, i_small ) \
+ } \
+ /* Both are items */ \
+ else if( psz_a == NULL && psz_b != NULL ) \
+ i_test = 1; \
+ else if( psz_a != NULL && psz_b == NULL ) \
+ i_test = -1;\
+ /* No meta, sort by name */ \
+ else if( psz_a == NULL && psz_b == NULL ) \
+ { \
+ META_STRCASECMP_NAME( i, i_small ); \
+ } \
+ else \
+ { \
+ i_test = strcmp( psz_b, psz_a ); \
+ } \
+ free( psz_a ); \
+ free( psz_b ); \
+}
+
+ for( i_position = 0; i_position < i_items -1 ; i_position ++ )