From: Bastian Dehn Date: Sat, 7 Aug 2021 17:42:22 +0000 (+0200) Subject: change: calc collection in mem X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=46b4c8ff3e3da604d929773c3de1a445ceee936c;p=discspan.git change: calc collection in mem --- diff --git a/discspan.h b/discspan.h index 4e3a537..fb8d10f 100644 --- a/discspan.h +++ b/discspan.h @@ -13,4 +13,9 @@ typedef struct { file_size_t *filearray; } medium_t; +typedef struct { + int length; + medium_t *disc; +} collection_t; + #endif diff --git a/logic.c b/logic.c index 76fe95e..ac9b85b 100644 --- a/logic.c +++ b/logic.c @@ -40,21 +40,15 @@ void run(const char *input, const char *output, unsigned long long split) qsort(srcdata.filearray, srcdata.length, sizeof(file_size_t), cmpfunc); - medium_t disc; - disc = ignore(&srcdata); - if (disc.length > 0) - write_output_file("ignore", disc); - free(disc.filearray); + collection_t col = split_all(&srcdata); char outname[strlen(output) + 3]; - while (srcdata.length > 0) { - srcdata.nr++; - sprintf(outname, "%s%03d", output, srcdata.nr); - disc = splitter(&srcdata); - on_status_print(outname, disc); - write_output_file(outname, disc); - free(disc.filearray); + for (int i = 0; i < col.length; i++) { + sprintf(outname, "%s%03d", output, col.disc[i].nr); + on_status_print(outname, col.disc[i]); + write_output_file(outname, col.disc[i]); + free(col.disc[i].filearray); } - free(srcdata.filearray); + free(col.disc); } diff --git a/splitter.c b/splitter.c index cef826f..5b9aedf 100644 --- a/splitter.c +++ b/splitter.c @@ -72,6 +72,33 @@ medium_t splitter_to_disc(medium_t *srcdata, return disc; } +collection_t split_all(medium_t *srcdata) +{ + collection_t col; + col.length = 0; + col.disc = NULL; + + medium_t ignoredisc; + ignoredisc = ignore(srcdata); + if (ignoredisc.length > 0) { + col.disc = (medium_t *)malloc(sizeof(medium_t)); + col.disc[col.length] = ignoredisc; + col.length++; + } + + while (srcdata->length > 0) { + srcdata->nr++; + medium_t disc = splitter(srcdata); + col.disc = (medium_t *) + realloc(col.disc, (col.length + 1) * sizeof(medium_t)); + col.disc[col.length] = disc; + col.length++; + } + + free(srcdata->filearray); + return col; +} + medium_t splitter(medium_t *srcdata) { medium_t disc = splitter_to_disc(srcdata, can_add_file_to_medium); diff --git a/splitter.h b/splitter.h index 7557b38..efd1a80 100644 --- a/splitter.h +++ b/splitter.h @@ -1,6 +1,8 @@ #ifndef _SPLITTER_H #define _SPLITTER_H +collection_t split_all(medium_t *srcdata); + medium_t splitter(medium_t *srcdata); medium_t ignore(medium_t *srcdata);