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)
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;
}
--- /dev/null
+#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
medium_t *disc;
} collection_t;
+collection_t* init_collection();
+void free_medium(medium_t *medium);
+void free_collection(collection_t *col);
+
#ifdef __cplusplus
}
#endif
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;
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;
}
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
}