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);
}
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);