summaryrefslogtreecommitdiffstats
path: root/libhb/batch.c
diff options
context:
space:
mode:
authorjstebbins <[email protected]>2014-02-22 05:21:10 +0000
committerjstebbins <[email protected]>2014-02-22 05:21:10 +0000
commitdf8ed184b7afb55f4870ee0e43bd38e59e63f8d3 (patch)
treea374518e2b9247dfa028a23daa7d0936bea77312 /libhb/batch.c
parent993d19bcffe30ae1213ebe040083a86b2c33300f (diff)
libhb: sort the list of files in batch mode
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6058 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'libhb/batch.c')
-rw-r--r--libhb/batch.c33
1 files changed, 30 insertions, 3 deletions
diff --git a/libhb/batch.c b/libhb/batch.c
index aaf43eaa9..45fcee1a8 100644
--- a/libhb/batch.c
+++ b/libhb/batch.c
@@ -16,6 +16,11 @@ struct hb_batch_s
hb_list_t * list_file;
};
+static int compare_str(const void *a, const void *b)
+{
+ return strncmp(*(const char**)a, *(const char**)b, PATH_MAX);
+}
+
/***********************************************************************
* hb_batch_init
***********************************************************************
@@ -28,6 +33,8 @@ hb_batch_t * hb_batch_init( char * path )
HB_DIR * dir;
struct dirent * entry;
char * filename;
+ int count, ii;
+ char ** files;
if ( hb_stat( path, &sb ) )
return NULL;
@@ -39,9 +46,16 @@ hb_batch_t * hb_batch_init( char * path )
if ( dir == NULL )
return NULL;
- d = calloc( sizeof( hb_batch_t ), 1 );
- d->list_file = hb_list_init();
+ // Count the total number of entries
+ while ( (entry = hb_readdir( dir ) ) )
+ {
+ count++;
+ }
+ files = malloc(count * sizeof(char*));
+ // Find all regular files
+ ii = 0;
+ hb_rewinddir(dir);
while ( (entry = hb_readdir( dir ) ) )
{
filename = hb_strdup_printf( "%s" DIR_SEP_STR "%s", path, entry->d_name );
@@ -57,10 +71,23 @@ hb_batch_t * hb_batch_init( char * path )
continue;
}
- hb_list_add( d->list_file, filename );
+ files[ii++] = filename;
}
+ count = ii;
+
+ // Sort the files
+ qsort(files, count, sizeof(char*), compare_str);
+ // Create file list
+ d = calloc( sizeof( hb_batch_t ), 1 );
+ d->list_file = hb_list_init();
+ for (ii = 0; ii < count; ii++)
+ {
+ hb_list_add( d->list_file, files[ii] );
+ }
hb_closedir( dir );
+ free(files);
+
if ( hb_list_count( d->list_file ) == 0 )
{
hb_list_close( &d->list_file );