]> gitweb.hhaalo.de Git - discspan.git/commitdiff
change: remove global variables
authorBastian Dehn <hhaalo@arcor.de>
Wed, 28 Jul 2021 16:19:57 +0000 (18:19 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Wed, 28 Jul 2021 16:19:57 +0000 (18:19 +0200)
discspan.c
readfile.c
readfile.h
splitter.c
splitter.h

index e3d5547e9cf469334f1a770534564890ce956319..209826c6cd037bb1887d48d66185fbd5573544b3 100644 (file)
@@ -12,10 +12,7 @@ extern void (*printEvent)(const char *output, unsigned long long splitgroesse);
 extern void useage();
 extern file_size_t * read_input_file();
 extern file_size_t * splitter(file_size_t *input, const char *output,
-                       unsigned long long splitgroesse);
-
-int struct_array_length = 0;
-unsigned long long split = 0;
+                       unsigned long long splitgroesse, int *arraylength);
 
 int cmpfunc(const void *filea, const void *fileb)
 {
@@ -32,8 +29,10 @@ int cmpfunc(const void *filea, const void *fileb)
                return -2;
 }
 
-void readArgument(int argc, char *argv[])
+const unsigned long long readArgument(int argc, char *argv[])
 {
+       unsigned long long split = 0;
+
        // Medien groessen
        const unsigned long long bluray = 24159191040;
        const unsigned long long dvd9 = 8500000000;
@@ -63,6 +62,8 @@ void readArgument(int argc, char *argv[])
                        break;
                }
        }
+
+       return split;
 }
 
 void printHumanReadSize(const char *output, unsigned long long splitgroesse)
@@ -95,16 +96,18 @@ int main(int argc, char *argv[])
        const char *input = argv[1];
        const char *output = argv[2];
 
-       readArgument(argc, argv);
-       file_size_t *fs = read_input_file(input);
+       int arraylength = 0;
+
+       const unsigned long long split = readArgument(argc, argv);
+       file_size_t *fs = read_input_file(input, split, &arraylength);
 
-       qsort(fs, struct_array_length, sizeof(file_size_t), cmpfunc);
+       qsort(fs, arraylength, sizeof(file_size_t), cmpfunc);
 
        char outname[strlen(output) + 3];
        int num = 1;
-       while (struct_array_length > 0) {
+       while (arraylength > 0) {
                sprintf(outname, "%s%03d", output, num++);
-               fs = splitter(fs, outname, split);
+               fs = splitter(fs, outname, split, &arraylength);
        }
 
        free(fs);
index 6f0a4967bf57bd02c607fbeab5ad48271b872b2f..3c8eb10a448bb12f86d64ca3323ed4929a0e9fe2 100644 (file)
@@ -6,7 +6,6 @@
 #include "discspan.h"
 #include "readfile.h"
 
-extern int struct_array_length;
 extern unsigned long long split;
 
 /**
@@ -39,7 +38,8 @@ int get_array_length(FILE *in)
  * @return Arraylaenge
  */
 file_size_t * fill_array_from_file(FILE *in, file_size_t *fs,
-               const unsigned long long split)
+               const unsigned long long split,
+               int *length)
 {
        FILE *ignore = NULL;
        char pfad[255];
@@ -65,21 +65,23 @@ file_size_t * fill_array_from_file(FILE *in, file_size_t *fs,
        if (ignore != NULL)
                fclose(ignore);
 
-       struct_array_length = lines;
+       length = &lines;
        return fs;
 }
 
-file_size_t * read_input_file(const char *input)
+file_size_t * read_input_file(const char *input,
+               const unsigned long long split,
+               int *arraylength)
 {
        FILE *in = fopen(input, "r");
 
-       struct_array_length = get_array_length(in);
+       *arraylength = get_array_length(in);
        file_size_t *fs = (file_size_t *)
-               malloc(struct_array_length * sizeof(file_size_t));
+               malloc(*arraylength * sizeof(file_size_t));
 
-       fs = fill_array_from_file(in, fs, split);
+       fs = fill_array_from_file(in, fs, split, arraylength);
        fs = (file_size_t *)
-               realloc(fs, struct_array_length * sizeof(file_size_t));
+               realloc(fs, *arraylength * sizeof(file_size_t));
 
        fclose(in);
 
index d7237d68a75127710a6361b28e100667f30507d9..927da6846318fd3719144bf2a07c8af4c72997f3 100644 (file)
@@ -8,6 +8,8 @@
  *
  * @return file_size struct array
  */
-file_size_t * read_input_file(const char *input);
+file_size_t * read_input_file(const char *input,
+              const unsigned long long split,
+              int *arraylength);
 
 #endif
index f2eb2351b63079fa48c1a8ee44cb9558a96ae493..85f1e8e9481303dce25115d535d7af01cdbe70a9 100644 (file)
@@ -6,8 +6,6 @@
 #include "discspan.h"
 #include "splitter.h"
 
-extern int struct_array_length;
-
 void writeOutputFile(const char *outputPath, file_size_t *disc, int length)
 {
        FILE *out = fopen(outputPath, "w");
@@ -26,18 +24,18 @@ void onPrintEvent(const char *output, unsigned long long splitgroesse)
 }
 
 file_size_t * splitter(file_size_t *input, const char *output,
-               unsigned long long splitgroesse)
+               unsigned long long splitgroesse, int *arraylength)
 {
        file_size_t *rest = (file_size_t *)
-               malloc(struct_array_length * sizeof(file_size_t));
+               malloc(*arraylength * sizeof(file_size_t));
        file_size_t *disc = (file_size_t *)
-               malloc(struct_array_length * sizeof(file_size_t));
+               malloc(*arraylength * sizeof(file_size_t));
 
        unsigned long long filesize = 0;
        int restcount = 0;
        int disccount = 0;
 
-       for (int i = 0; i < struct_array_length; i++) {
+       for (int i = 0; i < *arraylength; i++) {
                // ISO9660 filesystem overhead
                filesize = ceil(input[i].fsize / 2048.0) * 2048;
 
@@ -61,6 +59,6 @@ file_size_t * splitter(file_size_t *input, const char *output,
 
        free(rest);
        free(disc);
-       struct_array_length = restcount;
+       *arraylength = restcount;
        return input;
 }
index 77614a44a35c78ce17be03c2fd61faf96e30d4ec..37c4e276851caae1b93ce5400abd1ccf0aa14dab 100644 (file)
@@ -22,6 +22,6 @@ void (*printEvent)(const char *output, unsigned long long splitgroesse);
  * @return Restlaenge des neuen Arrays
  */
 file_size_t * splitter(file_size_t *input, const char *output,
-               unsigned long long splitgroesse);
+               unsigned long long splitgroesse, int *arraylength);
 
 #endif