]> gitweb.hhaalo.de Git - discspan.git/commitdiff
Sortierfunktion nach Dateigroesse
authorBastian Dehn <hhaalo@arcor.de>
Fri, 17 Jul 2015 16:51:41 +0000 (18:51 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Fri, 17 Jul 2015 16:51:41 +0000 (18:51 +0200)
discspan.c

index b5b1b6750fa16c28441dbecb8978ac851be109a6..1b1abe18213981e2e4e7c8102f2498bc3f520238 100644 (file)
@@ -86,6 +86,41 @@ void splitter(const char *input, char *output, const char *rest, unsigned long l
        printf("Restlicher Platz in Bytes(%s): %lld (%lld %c)\n", output, splitgroesse, humanread, einheit);
 }
 
+int cmpfunc(const void * a, const void * b)
+{
+       if(*(long long unsigned int*)a < *(long long unsigned int*)b)
+               return 1;
+       if(*(long long unsigned int*)a > *(long long unsigned int*)b)
+               return -1;
+       if(*(long long unsigned int*)a == *(long long unsigned int*)b)
+               return 0;
+}
+
+long long unsigned int * filesize_sort(const char *input, const char *output)
+{
+       FILE *in; FILE *out;
+       char pfad[255];
+       struct stat st;
+       int lines = 0;
+
+       in = fopen(input, "r");
+
+       while(fscanf(in, "%[^\n]\n", pfad) == 1)
+       {
+               lines++;                
+       }
+       fseek(in, 0L, SEEK_SET);
+       long long unsigned int fsize[lines];
+       lines = 0;
+       while(fscanf(in, "%[^\n]\n", pfad) == 1)
+       {
+               stat(pfad, &st);
+               fsize[lines++] = st.st_size;
+       }
+       qsort(fsize, lines, sizeof(unsigned long long), cmpfunc);
+       return fsize;
+}
+
 void usage()
 {      
        printf("\nUsage: discspan <input> <output> <option>\n\n");
@@ -145,6 +180,7 @@ int main(int argc, char *argv[])
                }
        }
 
+       long long unsigned int *fsort = filesize_sort(input, rest);
        filecopy(input, rest);
        while(exists(rest) == 0)
        {