]> gitweb.hhaalo.de Git - discspan.git/commitdiff
change: move sort into split all
authorBastian Dehn <hhaalo@arcor.de>
Sun, 15 Aug 2021 08:52:01 +0000 (10:52 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Sun, 15 Aug 2021 08:52:01 +0000 (10:52 +0200)
libs/spandisc/src/logic.c
libs/spandisc/src/splitter.c

index 9f6997fd03ba41537f7cf316f9159e4b4a90a7d2..4662d3bdc4768d8a8fa0c83bbe0da7920ce27548 100644 (file)
@@ -13,28 +13,11 @@ void on_status_print(const char *output, medium_t disc)
                status_print(output, disc);
 }
 
-int cmpfunc(const void *filea, const void *fileb)
-{
-       unsigned long long a = ((const file_size_t*)filea)->fsize;
-       unsigned long long b = ((const file_size_t*)fileb)->fsize;
-
-       if (a < b)
-               return 1;
-       else if (a > b)
-               return -1;
-       else if (a == b)
-               return 0;
-       else
-               return -2;
-}
-
 void span(const char *input, const char *output, unsigned long long split)
 {
        medium_t srcdata = { 0, split, 0, NULL };
        read_input_file(input, &srcdata);
 
-       qsort(srcdata.filearray, srcdata.length, sizeof(file_size_t), cmpfunc);
-
        collection_t col = split_all(&srcdata);
 
        char outname[strlen(output) + 4];
index 83be0984b1ee14a88a4e7c5354e42a6ee12d799d..d509f575f80e33193dac3cd6fefe8f7207582d84 100644 (file)
@@ -7,6 +7,21 @@
 
 #define S_IFREG 0100000 // bitmask for regular file; man inode
 
+int cmpfunc(const void *filea, const void *fileb)
+{
+       unsigned long long a = ((const file_size_t*)filea)->fsize;
+       unsigned long long b = ((const file_size_t*)fileb)->fsize;
+
+       if (a < b)
+               return 1;
+       else if (a > b)
+               return -1;
+       else if (a == b)
+               return 0;
+       else
+               return -2;
+}
+
 void free_medium(medium_t *medium)
 {
        free(medium->filearray);
@@ -107,6 +122,8 @@ medium_t ignore(medium_t *srcdata)
 
 collection_t split_all(medium_t *srcdata)
 {
+       qsort(srcdata->filearray, srcdata->length, sizeof(file_size_t), cmpfunc);
+
        collection_t col = { 0, NULL };
 
        medium_t ignoredisc = { 0, 0, 0, NULL };