project(discspan)
-set(SOURCES discspan.c readfile.c splitter.c help.c)
+set(SOURCES discspan.c filehandler.c splitter.c help.c)
add_executable(discspan ${SOURCES})
target_link_libraries(discspan m)
all: discspan
-discspan: discspan.o readfile.o readfile.h splitter.o splitter.h help.o help.h
- $(CC) $(CFLAGS) -o discspan discspan.o readfile.o splitter.o help.o
+discspan: discspan.o filehandler.o filehandler.h splitter.o splitter.h help.o help.h
+ $(CC) $(CFLAGS) -o discspan discspan.o filehandler.o splitter.o help.o
discspan.o: discspan.h discspan.c
$(CC) $(CFLAGS) -c discspan.c
-readfile.o: discspan.h readfile.h readfile.c
- $(CC) $(CFLAGS) -c readfile.c
+filehandler.o: discspan.h filehandler.h filehandler.c
+ $(CC) $(CFLAGS) -c filehandler.c
splitter.o: splitter.h splitter.c
$(CC) $(CFLAGS) -c splitter.c
help.o: help.h help.c
#include "discspan.h"
#include "splitter.h"
-#include "readfile.h"
+#include "filehandler.h"
#include "help.h"
extern void (*printEvent)(const char *output, unsigned long long splitgroesse);
extern void useage();
extern void read_input_file(const char *input, const unsigned long long split,
file_size_handler_t *handler);
-extern void splitter(file_size_handler_t *handler, const char *output,
- unsigned long long splitgroesse);
+extern void write_output_file(const char *output, file_size_handler_t disc);
+extern file_size_handler_t splitter(file_size_handler_t *handler,
+ const char *output, unsigned long long splitgroesse);
int cmpfunc(const void *filea, const void *fileb)
{
char outname[strlen(output) + 3];
int num = 1;
+ file_size_handler_t disc;
while (arrayhandler.length > 0) {
sprintf(outname, "%s%03d", output, num++);
- splitter(&arrayhandler, outname, split);
+ disc = splitter(&arrayhandler, outname, split);
+ write_output_file(outname, disc);
+ free(disc.filearray);
}
free(arrayhandler.filearray);
--- /dev/null
+#include <sys/stat.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "discspan.h"
+#include "filehandler.h"
+
+void malloc_array_length(FILE *in, file_size_handler_t *handler)
+{
+ int lines = 0;
+ char pfad[255];
+
+ while (fscanf(in, "%[^\n]\n", pfad) == 1) {
+ lines++;
+ }
+ rewind(in);
+
+ handler->length = lines;
+ handler->filearray = (file_size_t *)
+ malloc(handler->length * sizeof(file_size_t));
+}
+
+void fill_array_from_file(FILE *in, const unsigned long long split,
+ file_size_handler_t *handler)
+{
+ FILE *ignore = NULL;
+ char pfad[255];
+ struct stat st;
+ int lines = 0;
+
+ while (fscanf(in, "%[^\n]\n", pfad) == 1) {
+ // Lese Dateieigenschaften in st struct
+ stat(pfad, &st);
+
+ if (st.st_size <= split) {
+ strcpy(handler->filearray[lines].name, pfad);
+ handler->filearray[lines++].fsize = st.st_size;
+ } else {
+ // irgnore List erstellen
+ if (ignore == NULL)
+ ignore = fopen("ignore", "w");
+
+ fprintf(ignore, "%s\n", pfad);
+ }
+ }
+
+ if (ignore != NULL)
+ fclose(ignore);
+
+ handler->length = lines;
+ handler->filearray = (file_size_t *)
+ realloc(handler->filearray,
+ handler->length * sizeof(file_size_t));
+}
+
+void read_input_file(const char *input,
+ const unsigned long long split,
+ file_size_handler_t *handler)
+{
+ FILE *in = fopen(input, "r");
+
+ malloc_array_length(in, handler);
+ fill_array_from_file(in, split, handler);
+
+ fclose(in);
+}
+
+void write_output_file(const char *output, file_size_handler_t disc)
+{
+ FILE *out = fopen(output, "w");
+
+ for (int i = 0; i < disc.length; i++) {
+ fprintf(out, "%s\n", disc.filearray[i].name);
+ }
+
+ fclose(out);
+}
--- /dev/null
+#ifndef _FILEHANDLER_H
+#define _FILEHANDLER_H
+
+void read_input_file(const char *input,
+ const unsigned long long split,
+ file_size_handler_t *handler);
+
+void write_output_file(const char *output, file_size_handler_t disc);
+
+#endif
+++ /dev/null
-#include <sys/stat.h>
-#include <string.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-#include "discspan.h"
-#include "readfile.h"
-
-void malloc_array_length(FILE *in, file_size_handler_t *handler)
-{
- int lines = 0;
- char pfad[255];
-
- while (fscanf(in, "%[^\n]\n", pfad) == 1) {
- lines++;
- }
- rewind(in);
-
- handler->length = lines;
- handler->filearray = (file_size_t *)
- malloc(handler->length * sizeof(file_size_t));
-}
-
-void fill_array_from_file(FILE *in, const unsigned long long split,
- file_size_handler_t *handler)
-{
- FILE *ignore = NULL;
- char pfad[255];
- struct stat st;
- int lines = 0;
-
- while (fscanf(in, "%[^\n]\n", pfad) == 1) {
- // Lese Dateieigenschaften in st struct
- stat(pfad, &st);
-
- if (st.st_size <= split) {
- strcpy(handler->filearray[lines].name, pfad);
- handler->filearray[lines++].fsize = st.st_size;
- } else {
- // irgnore List erstellen
- if (ignore == NULL)
- ignore = fopen("ignore", "w");
-
- fprintf(ignore, "%s\n", pfad);
- }
- }
-
- if (ignore != NULL)
- fclose(ignore);
-
- handler->length = lines;
- handler->filearray = (file_size_t *)
- realloc(handler->filearray,
- handler->length * sizeof(file_size_t));
-}
-
-void read_input_file(const char *input,
- const unsigned long long split,
- file_size_handler_t *handler)
-{
- FILE *in = fopen(input, "r");
-
- malloc_array_length(in, handler);
- fill_array_from_file(in, split, handler);
-
- fclose(in);
-}
+++ /dev/null
-#ifndef _READFILE_H
-#define _READFILE_H
-
-void read_input_file(const char *input,
- const unsigned long long split,
- file_size_handler_t *handler);
-
-#endif
#include "discspan.h"
#include "splitter.h"
-void writeOutputFile(const char *outputPath, file_size_handler_t disc)
-{
- FILE *out = fopen(outputPath, "w");
-
- for (int i = 0; i < disc.length; i++) {
- fprintf(out, "%s\n", disc.filearray[i].name);
- }
-
- fclose(out);
-}
-
void onPrintEvent(const char *output, unsigned long long splitgroesse)
{
if (printEvent != NULL)
printEvent(output, splitgroesse);
}
-void splitter(file_size_handler_t *handler, const char *output, unsigned long long splitgroesse)
+file_size_handler_t splitter(file_size_handler_t *handler, const char *output,
+ unsigned long long splitgroesse)
{
- file_size_t *rest = (file_size_t *)
- malloc(handler->length * sizeof(file_size_t));
+ file_size_handler_t rest;
+ rest.length = handler->length;
+ rest.filearray = (file_size_t *)
+ malloc(rest.length * sizeof(file_size_t));
file_size_handler_t disc;
disc.length = handler->length;
splitgroesse -= filesize;
disc.filearray[disccount++] = handler->filearray[i];
} else {
- rest[restcount++] = handler->filearray[i];
+ rest.filearray[restcount++] = handler->filearray[i];
}
}
disc.filearray = (file_size_t *)
realloc(disc.filearray, disc.length * sizeof(file_size_t));
- writeOutputFile(output, disc);
-
onPrintEvent(output, splitgroesse);
- memcpy(handler->filearray, rest, restcount * sizeof(file_size_t));
- handler->filearray = (file_size_t *) realloc(handler->filearray,
- restcount * sizeof(file_size_t));
+ memcpy(handler->filearray, rest.filearray,
+ restcount * sizeof(file_size_t));
handler->length = restcount;
- free(disc.filearray);
- free(rest);
+ handler->filearray = (file_size_t *) realloc(handler->filearray,
+ handler->length * sizeof(file_size_t));
+
+ free(rest.filearray);
+ return disc;
}
void (*printEvent)(const char *output, unsigned long long splitgroesse);
-void splitter(file_size_handler_t *handler, const char *output,
+file_size_handler_t splitter(file_size_handler_t *handler, const char *output,
unsigned long long splitgroesse);
#endif