]> gitweb.hhaalo.de Git - discspan.git/commitdiff
change: read input file function
authorBastian Dehn <hhaalo@arcor.de>
Mon, 6 Jan 2020 08:34:17 +0000 (09:34 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Mon, 6 Jan 2020 08:36:03 +0000 (09:36 +0100)
discspan.c

index 71594a0a48f81a340e4cfdc97a40d4a43dcf282e..fb144740cbec253ae40b3ed7f0a4536ef49d378b 100644 (file)
@@ -9,6 +9,9 @@
 
 extern void useage();
 
+int struct_array_length = 0;
+unsigned long long int split = 0;
+
 typedef struct file_size {
        char name[255];
        long long unsigned int fsize;
@@ -168,7 +171,7 @@ int splitter(struct file_size *input, const char *output,
        return restcount;
 }
 
-unsigned long long readArgument(int argc, char *argv[])
+void readArgument(int argc, char *argv[])
 {
        // Medien groessen
        const unsigned long long bluray = 25000000000;
@@ -176,8 +179,6 @@ unsigned long long readArgument(int argc, char *argv[])
        const unsigned long long dvd5 = 4700000000;
        const unsigned long long cd = 734003200;
 
-       unsigned long long split = 0;
-
        int c = 0;
        while ((c = getopt(argc, argv, ":59bcf:")) != -1) {
                switch (c) {
@@ -198,58 +199,48 @@ unsigned long long readArgument(int argc, char *argv[])
                        break;
                case 'h':
                        usage();
-                       return 0;
                        break;
                }
        }
+}
+
+file_size * read_input_file(const char *input)
+{
+       FILE *in = fopen(input, "r");
+
+       struct_array_length = get_array_length(in);
+       struct file_size *fs = (struct file_size *)
+               malloc(struct_array_length * sizeof(struct file_size));
+
+       struct_array_length = fill_array_from_file(in, fs, split);
+       fs = (struct file_size *)
+               realloc(fs, struct_array_length * sizeof(struct file_size));
+
+       fclose(in);
 
-       return split;
+       return fs;
 }
 
-/**
- * Hauptfunktion
- *
- * @param Anzahl der Argumente
- * @param Argument Array
- *
- * @return Erfolgreich 0; Fehler 1
- */
 int main(int argc, char *argv[])
 {
        const char *input = argv[1];
        const char *output = argv[2];
-       unsigned long long int split = 0;
 
-       // gib die Funktionsübersicht aus bei zu wenig Parameter
        if (argc <= 3) {
                usage();
                return 1;
        }
 
-       split = readArgument(argc, argv);
-
-       // Liest die Quelldatei in den Ram
-       FILE *in = fopen(input, "r");
-
-       int s_length = get_array_length(in);
-       struct file_size *fs = (struct file_size *)
-               malloc(s_length * sizeof(struct file_size));
-
-       s_length = fill_array_from_file(in, fs, split);
-       fs = (struct file_size *)
-               realloc(fs, s_length * sizeof(struct file_size));
-
-       fclose(in);
+       readArgument(argc, argv);
+       struct file_size *fs = read_input_file(input);
 
-       // sortieren
-       // s_length is array length 0 bis xy
-       qsort(fs, (s_length + 1), sizeof(struct file_size), cmpfunc);
+       qsort(fs, (struct_array_length + 1), sizeof(struct file_size), cmpfunc);
 
        char outname[strlen(output) + 3];
        int num = 1;
-       while (s_length > 0) {
+       while (struct_array_length > 0) {
                sprintf(outname, "%s%03d", output, num++);
-               s_length = splitter(fs, outname, split, s_length);
+               struct_array_length = splitter(fs, outname, split, struct_array_length);
        }
 
        free(fs);