[vlc-commits] input/subtitles: sort subtitles coming from the file system

Thomas Guillem git at videolan.org
Tue Jun 7 18:26:00 CEST 2016


vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Tue Jun  7 17:08:08 2016 +0200| [31a41f79473c9172e5749ee1ad24733d4170da59] | committer: Thomas Guillem

input/subtitles: sort subtitles coming from the file system

Keep the same subtitles order than before slaves commits (in order to don't
disturb the user).

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=31a41f79473c9172e5749ee1ad24733d4170da59
---

 src/input/subtitles.c |   20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/src/input/subtitles.c b/src/input/subtitles.c
index ed6d72a..34eede4 100644
--- a/src/input/subtitles.c
+++ b/src/input/subtitles.c
@@ -116,6 +116,22 @@ static int whiteonly( const char *s )
     return 1;
 }
 
+static int slave_strcmp( const void *a, const void *b )
+{
+    const input_item_slave_t *p_slave0 = *((const input_item_slave_t **) a);
+    const input_item_slave_t *p_slave1 = *((const input_item_slave_t **) b);
+
+    if( p_slave0 == NULL || p_slave1 == NULL )
+        return 0;
+
+    /* We can compare these uris since they come from the file system */
+#ifdef HAVE_STRCOLL
+    return strcoll( p_slave0->psz_uri, p_slave1->psz_uri );
+#else
+    return strcmp( p_slave0->psz_uri, p_slave1->psz_uri );
+#endif
+}
+
 /*
  * Check if a file ends with a subtitle extension
  */
@@ -402,6 +418,10 @@ int subtitles_Detect( input_thread_t *p_this, char *psz_path, const char *psz_na
         }
     }
 
+    /* Sort alphabetically */
+    if( i_slaves > 0 )
+        qsort( pp_slaves, i_slaves, sizeof (input_item_slave_t*), slave_strcmp );
+
     *ppp_slaves = pp_slaves; /* in case of realloc */
     *p_slaves = i_slaves;
     return VLC_SUCCESS;



More information about the vlc-commits mailing list