]> gitweb.hhaalo.de Git - discspan.git/commitdiff
add: move splitter func into module
authorBastian Dehn <hhaalo@arcor.de>
Sun, 12 Jan 2020 19:28:25 +0000 (20:28 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Sun, 12 Jan 2020 19:35:15 +0000 (20:35 +0100)
Makefile
discspan.c
splitter.c [new file with mode: 0644]
splitter.h [new file with mode: 0644]

index bcc9f91da0238fd829dd90fdb94999cac9683c2d..4be349b89775a9fa7a33210e7bc10b2f7d87df1d 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -5,13 +5,15 @@ BINPATH=/usr/bin
 
 all: discspan
 
-discspan: discspan.o readfile.o readfile.h help.o help.h
-       $(CC) $(CFLAGS) -o discspan discspan.o readfile.o help.o
+discspan: discspan.o readfile.o readfile.h splitter.o splitter.h help.o help.h
+       $(CC) $(CFLAGS) -o discspan discspan.o readfile.o splitter.o help.o
 
 discspan.o: discspan.h discspan.c
        $(CC) $(CFLAGS) -c discspan.c
 readfile.o: discspan.h readfile.h readfile.c
        $(CC) $(CFLAGS) -c readfile.c
+splitter.o: splitter.h splitter.c
+       $(CC) $(CFLAGS) -c splitter.c
 help.o: help.h help.c
        $(CC) $(CFLAGS) -c help.c
 
index 15eeef5cc54e03c3b42686850ab1cd662aed6b87..369bc32b536794e35c70190bd754996aad3d31f2 100644 (file)
@@ -1,38 +1,21 @@
 #include <stdio.h>
-#include <math.h>
 #include <unistd.h>
-#include <string.h>
 #include <stdlib.h>
+#include <string.h>
 
 #include "discspan.h"
+#include "splitter.h"
 #include "readfile.h"
 #include "help.h"
 
 extern void useage();
 extern file_size_t * read_input_file();
+extern int splitter(file_size_t *input, const char *output,
+                       unsigned long long splitgroesse, int length);
 
 int struct_array_length = 0;
 unsigned long long split = 0;
 
-void printHumanReadSize(const char *output, unsigned long long splitgroesse)
-{
-       unsigned long long humanread;
-       char einheit[6] = {'B', 'K', 'M', 'G', 'T', 'P'};
-       int i = 0;
-
-       humanread = splitgroesse;
-       while (humanread >= 1024) {
-               humanread /= 1024;
-               i++;
-       }
-
-       if (i > sizeof(einheit)/sizeof(einheit[0]))
-               i = 0;
-
-       printf("Restlicher Platz in Bytes(%s): %lld (%lld %c)\n", output,
-                       splitgroesse, humanread, einheit[i]);
-}
-
 int cmpfunc(const void *filea, const void *fileb)
 {
        unsigned long long a = ((const file_size_t*)filea)->fsize;
@@ -48,55 +31,6 @@ int cmpfunc(const void *filea, const void *fileb)
                return -2;
 }
 
-/**
- * Schreibt in eine Datei die Pfade der Dateien, die auf das Medium passen. Wenn
- * ein Rest uebrig bleibt wird das Array reallociert und die Restlange zurueck-
- * gegeben.
- *
- * @param pointer auf das Array mit file_size struct
- * @param pointer auf den string fuer den Ausgabepfad der Datei
- * @param Splitgroesse
- * @param maximale Laenge des neuen Arrays
- *
- * @return Restlaenge des neuen Arrays
- */
-int splitter(file_size_t *input, const char *output,
-               unsigned long long splitgroesse, int length)
-{
-       file_size_t *rest = (file_size_t *)
-               malloc(length * sizeof(file_size_t));
-
-       unsigned long long filesize = 0;
-       int restcount = 0;
-       FILE *out;
-
-       out = fopen(output, "w");
-       for (int i = 0; i <= length; i++) {
-               // ISO9660 filesystem overhead
-               filesize = ceil(input[i].fsize / 2048.0) * 2048;
-
-               if (splitgroesse >= filesize) {
-                       splitgroesse -= filesize;
-                       fprintf(out, "%s\n", input[i].name);
-               } else {
-                       rest[restcount++] = input[i];
-               }
-       }
-       fclose(out);
-
-       printHumanReadSize(output, splitgroesse);
-
-       if (restcount > 0) {
-               memcpy(input, rest, length * sizeof(file_size_t));
-               input = (file_size_t *)
-                       realloc(input, restcount * sizeof(file_size_t));
-       }
-
-       free(rest);
-       restcount--;
-       return restcount;
-}
-
 void readArgument(int argc, char *argv[])
 {
        // Medien groessen
diff --git a/splitter.c b/splitter.c
new file mode 100644 (file)
index 0000000..49bf94f
--- /dev/null
@@ -0,0 +1,75 @@
+#include "stdio.h"
+#include <math.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "discspan.h"
+#include "splitter.h"
+
+void printHumanReadSize(const char *output, unsigned long long splitgroesse)
+{
+       unsigned long long humanread;
+       char einheit[6] = {'B', 'K', 'M', 'G', 'T', 'P'};
+       int i = 0;
+
+       humanread = splitgroesse;
+       while (humanread >= 1024) {
+               humanread /= 1024;
+               i++;
+       }
+
+       if (i > sizeof(einheit)/sizeof(einheit[0]))
+               i = 0;
+
+       printf("Restlicher Platz in Bytes(%s): %lld (%lld %c)\n", output,
+                       splitgroesse, humanread, einheit[i]);
+}
+
+/**
+ * Schreibt in eine Datei die Pfade der Dateien, die auf das Medium passen. Wenn
+ * ein Rest uebrig bleibt wird das Array reallociert und die Restlange zurueck-
+ * gegeben.
+ *
+ * @param pointer auf das Array mit file_size struct
+ * @param pointer auf den string fuer den Ausgabepfad der Datei
+ * @param Splitgroesse
+ * @param maximale Laenge des neuen Arrays
+ *
+ * @return Restlaenge des neuen Arrays
+ */
+int splitter(file_size_t *input, const char *output,
+               unsigned long long splitgroesse, int length)
+{
+       file_size_t *rest = (file_size_t *)
+               malloc(length * sizeof(file_size_t));
+
+       unsigned long long filesize = 0;
+       int restcount = 0;
+       FILE *out;
+
+       out = fopen(output, "w");
+       for (int i = 0; i <= length; i++) {
+               // ISO9660 filesystem overhead
+               filesize = ceil(input[i].fsize / 2048.0) * 2048;
+
+               if (splitgroesse >= filesize) {
+                       splitgroesse -= filesize;
+                       fprintf(out, "%s\n", input[i].name);
+               } else {
+                       rest[restcount++] = input[i];
+               }
+       }
+       fclose(out);
+
+       printHumanReadSize(output, splitgroesse);
+
+       if (restcount > 0) {
+               memcpy(input, rest, length * sizeof(file_size_t));
+               input = (file_size_t *)
+                       realloc(input, restcount * sizeof(file_size_t));
+       }
+
+       free(rest);
+       restcount--;
+       return restcount;
+}
diff --git a/splitter.h b/splitter.h
new file mode 100644 (file)
index 0000000..6498eef
--- /dev/null
@@ -0,0 +1,7 @@
+#ifndef _SPLITTER_H
+#define _SPLITTER_H
+
+int splitter(file_size_t *input, const char *output,
+               unsigned long long splitgroesse, int length);
+
+#endif