From: Bastian Dehn Date: Sat, 24 Jul 2021 17:51:18 +0000 (+0200) Subject: change: information output splitter event X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=a8651cf071b2c5d094890fd51704a4a8e4bb6695;p=discspan.git change: information output splitter event --- diff --git a/discspan.c b/discspan.c index 52dee16..ab390f2 100644 --- a/discspan.c +++ b/discspan.c @@ -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]; diff --git a/splitter.c b/splitter.c index a0b2ffc..19f3c50 100644 --- a/splitter.c +++ b/splitter.c @@ -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)); diff --git a/splitter.h b/splitter.h index b2d71be..bfc7a3d 100644 --- a/splitter.h +++ b/splitter.h @@ -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-