]> gitweb.hhaalo.de Git - discspan.git/commitdiff
change: information output splitter event
authorBastian Dehn <hhaalo@arcor.de>
Sat, 24 Jul 2021 17:51:18 +0000 (19:51 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Sat, 24 Jul 2021 17:51:18 +0000 (19:51 +0200)
discspan.c
splitter.c
splitter.h

index 52dee167db7c38a60295e541187aaf0d62885b75..ab390f24d5442727232468c18e505a30da61a060 100644 (file)
@@ -8,6 +8,7 @@
 #include "readfile.h"
 #include "help.h"
 
+extern void (*printEvent)(const char *output, unsigned long long splitgroesse);
 extern void useage();
 extern file_size_t * read_input_file();
 extern int splitter(file_size_t *input, const char *output,
@@ -64,6 +65,25 @@ void readArgument(int argc, char *argv[])
        }
 }
 
+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 main(int argc, char *argv[])
 {
        if (argc <= 3) {
@@ -71,6 +91,7 @@ int main(int argc, char *argv[])
                return 1;
        }
 
+       printEvent = printHumanReadSize;
        const char *input = argv[1];
        const char *output = argv[2];
 
index a0b2ffcbd3b60f5136c894bb6611145e69f3eb6e..19f3c509429f2befcc9cb7f435cfdcc1c384cfab 100644 (file)
@@ -6,25 +6,6 @@
 #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]);
-}
-
 void writeOutputFile(const char *outputPath, file_size_t *disc, int length)
 {
        FILE *out = fopen(outputPath, "w");
@@ -36,6 +17,12 @@ void writeOutputFile(const char *outputPath, file_size_t *disc, int length)
        fclose(out);
 }
 
+void onPrintEvent(const char *output, unsigned long long splitgroesse)
+{
+       if (printEvent != NULL)
+               printEvent(output, splitgroesse);
+}
+
 int splitter(file_size_t *input, const char *output,
                unsigned long long splitgroesse, int length)
 {
@@ -64,7 +51,7 @@ int splitter(file_size_t *input, const char *output,
 
        writeOutputFile(output, disc, disccount);
 
-       printHumanReadSize(output, splitgroesse);
+       onPrintEvent(output, splitgroesse);
 
        if (restcount > 0) {
                memcpy(input, rest, length * sizeof(file_size_t));
index b2d71becb909092090b4300d32b6a904e60745ba..bfc7a3df014ed24b7d6b09233f2c5d10d3f596c1 100644 (file)
@@ -1,6 +1,14 @@
 #ifndef _SPLITTER_H
 #define _SPLITTER_H
 
+/**
+ * PrintEvent umd Informationen Anzeigen zur laufzeit Anzeigen zu lassen.
+ *
+ * @param output Ausgabedateinamen
+ * @param splitgroesse die Bytes, die uebrig geblieben sind
+ */
+void (*printEvent)(const char *output, unsigned long long splitgroesse);
+
 /**
  * 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-