]> gitweb.hhaalo.de Git - discspan.git/commitdiff
change init collection
authorBastian Dehn <hhaalo@arcor.de>
Sat, 30 Aug 2025 15:44:35 +0000 (17:44 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Sat, 30 Aug 2025 15:44:35 +0000 (17:44 +0200)
libs/spandisc/CMakeLists.txt
libs/spandisc/src/logic.c
libs/spandisc/src/spandisc.c [new file with mode: 0644]
libs/spandisc/src/spandisc.h
libs/spandisc/src/splitter.c
libs/spandisc/src/splitter.h

index de8179a9ecd3ca80f72c5e5e2fc8122180794711..038e6eb1c0b287a5efd8b017e628b7dd51523a47 100644 (file)
@@ -27,10 +27,10 @@ set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT
 option(BUILD_SHARED_LIBS "build shared libs" ON)
 
 # configure file
-message(STATUS "Generating header: include/config_spandisc.h")
+message(STATUS "Generating header: src/config_spandisc.h")
 configure_file(${CMAKE_CURRENT_LIST_DIR}/src/config_spandisc.h.in
        ${CMAKE_CURRENT_BINARY_DIR}/src/config_spandisc.h)
-include_directories(${CMAKE_CURRENT_BINARY_DIR}/include)
+include_directories(${CMAKE_CURRENT_BINARY_DIR}/src)
 
 # add source files
 file(GLOB SOURCES src/*.c)
index 4eef415e2f22a9b109eeaad0af9b0afce22c024a..2fc531ecac7853636cd3ba235fbb780f90b095ea 100644 (file)
@@ -26,14 +26,16 @@ void span(const char *input, const char *output, unsigned long long split)
        medium_t srcdata = { 0, split, 0, NULL };
        read_input_file(input, &srcdata);
 
-       collection_t col = split_all(&srcdata);
+       collection_t* col = init_collection();
+       split_all(&srcdata, col);
 
        char outname[strlen(output) + 4];
-       for (int i = 0; i < col.length; i++) {
-               sprintf(outname, "%s%04d", output, col.disc[i].nr);
-               on_status_print(outname, col.disc[i]);
-               write_output_file(outname, col.disc[i]);
+       for (int i = 0; i < col->length; i++) {
+               sprintf(outname, "%s%04d", output, col->disc[i].nr);
+               on_status_print(outname, col->disc[i]);
+               write_output_file(outname, col->disc[i]);
        }
 
-       free_collection(&col);
+       free_collection(col);
+       col = NULL;
 }
diff --git a/libs/spandisc/src/spandisc.c b/libs/spandisc/src/spandisc.c
new file mode 100644 (file)
index 0000000..7f983eb
--- /dev/null
@@ -0,0 +1,30 @@
+#include <stdlib.h>
+#include "spandisc.h"
+
+collection_t* init_collection()
+{
+       collection_t* col = malloc(sizeof(collection_t));
+
+       col->length = 0;
+       col->disc = NULL;
+
+       return col;
+}
+
+void free_medium(medium_t *medium)
+{
+       free(medium->filearray);
+       medium->filearray = NULL;
+}
+
+void free_collection(collection_t *col)
+{
+       for (int i = 0; i < col->length; i++) {
+               free_medium(&col->disc[i]);
+       }
+
+       free(col->disc);
+       col->disc = NULL;
+       free(col);
+       col = NULL;
+}
\ No newline at end of file
index a074299d0f9e8f0d630ad4014ba3c47de553faae..c19911db419f6a9db0f766ae9da713cd7d8cfe2a 100644 (file)
@@ -23,6 +23,10 @@ typedef struct {
        medium_t *disc;
 } collection_t;
 
+collection_t* init_collection();
+void free_medium(medium_t *medium);
+void free_collection(collection_t *col);
+
 #ifdef __cplusplus
 }
 #endif
index 8f96cf8f50988b3f389827296dabd0b707b2cbd8..52db0eaba96045a7a6ac873c2f4855398b3bf139 100644 (file)
@@ -30,22 +30,6 @@ int strcmpfunc(const void *filea, const void *fileb)
        return strcasecmp(filename1, filename2);
 }
 
-void free_medium(medium_t *medium)
-{
-       free(medium->filearray);
-       medium->filearray = NULL;
-}
-
-void free_collection(collection_t *col)
-{
-       for (int i = 0; i < col->length; i++) {
-               free_medium(&col->disc[i]);
-       }
-
-       free(col->disc);
-       col->disc = NULL;
-}
-
 medium_t init_medium(medium_t srcdata)
 {
        medium_t empty;
@@ -134,28 +118,25 @@ medium_t ignore(medium_t *srcdata)
        return ignore;
 }
 
-collection_t split_all(medium_t *srcdata)
+void split_all(medium_t *srcdata, collection_t* col)
 {
-       collection_t col = { 0, NULL };
-
        medium_t ignoredisc = { 0, 0, 0, NULL };
        ignoredisc = ignore(srcdata);
        ignoredisc.freespace = 0;
        if (ignoredisc.length > 0) {
-               col.disc = (medium_t *) malloc(sizeof(medium_t));
-               col.disc[col.length] = ignoredisc;
-               col.length++;
+               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++;
+               col->disc = (medium_t *)
+                       realloc(col->disc, (col->length + 1) * sizeof(medium_t));
+               col->disc[col->length] = disc;
+               col->length++;
        }
 
        free_medium(srcdata);
-       return col;
 }
index 9e12460a232de453fe4473b94591f4de6b011527..0b49a144ca79fb61437de176427d3272da238223 100644 (file)
@@ -8,32 +8,9 @@ extern "C" {
 void free_medium(medium_t *medium);
 void free_collection(collection_t *col);
 
-/**
- * Calc a medium from srcdata and shrink srcdata struct.
- *
- * @param srcdata struct with all pathes
- *
- * @return one splitted medium
- */
 medium_t splitter(medium_t *srcdata);
-
-/**
- * Calc all files to big to split.
- *
- * @param srcdata struct with all pathes
- *
- * @return medium with pathes can not split
- */
 medium_t ignore(medium_t *srcdata);
-
-/**
- * Calc all file pathes and make a medium collection
- *
- * @param srcdata with all file pathes
- *
- * @return collection with many mediums
- */
-collection_t split_all(medium_t *srcdata);
+void split_all(medium_t *srcdata, collection_t* col);
 
 #ifdef __cplusplus
 }