extern void (*printEvent)(const char *output, unsigned long long splitgroesse);
extern void useage();
-extern file_size_t * read_input_file();
-extern file_size_t * splitter(file_size_t *input, const char *output,
- unsigned long long splitgroesse, int *arraylength);
+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);
int cmpfunc(const void *filea, const void *fileb)
{
}
printEvent = printHumanReadSize;
+
const char *input = argv[1];
const char *output = argv[2];
- int arraylength = 0;
+ file_size_handler_t arrayhandler = { NULL, 0 };
const unsigned long long split = readArgument(argc, argv);
- file_size_t *fs = read_input_file(input, split, &arraylength);
+ read_input_file(input, split, &arrayhandler);
- qsort(fs, arraylength, sizeof(file_size_t), cmpfunc);
+ qsort(arrayhandler.filearray, arrayhandler.length, sizeof(file_size_t),
+ cmpfunc);
char outname[strlen(output) + 3];
int num = 1;
- while (arraylength > 0) {
+ while (arrayhandler.length > 0) {
sprintf(outname, "%s%03d", output, num++);
- fs = splitter(fs, outname, split, &arraylength);
+ splitter(&arrayhandler, outname, split);
}
- free(fs);
+ free(arrayhandler.filearray);
return 0;
}
long long unsigned fsize;
} file_size_t;
+typedef struct {
+ file_size_t *filearray;
+ int length;
+} file_size_handler_t;
+
#endif
#include "discspan.h"
#include "readfile.h"
-extern unsigned long long split;
-
-/**
- * Ermittelt die Zeilen der Textdatei
- *
- * @param Datei pointer
- *
- * @return Anzahl von Zeilen
- */
-int get_array_length(FILE *in)
+void malloc_array_length(FILE *in, file_size_handler_t *handler)
{
int lines = 0;
char pfad[255];
}
rewind(in);
- return lines;
+ handler->length = lines;
+ handler->filearray = (file_size_t *)
+ malloc(handler->length * sizeof(file_size_t));
}
-/**
- * Liest die Datei in den Ram ein und gibt die Laenge des Arrays zurueck
- *
- * @param Datei pointer
- * @param file_size pointer
- * @param Splitgroesse
- *
- * @return Arraylaenge
- */
-file_size_t * fill_array_from_file(FILE *in, file_size_t *fs,
- const unsigned long long split,
- int *length)
+void fill_array_from_file(FILE *in, const unsigned long long split,
+ file_size_handler_t *handler)
{
FILE *ignore = NULL;
char pfad[255];
stat(pfad, &st);
if (st.st_size <= split) {
- strcpy(fs[lines].name, pfad);
- fs[lines++].fsize = st.st_size;
+ strcpy(handler->filearray[lines].name, pfad);
+ handler->filearray[lines++].fsize = st.st_size;
} else {
// irgnore List erstellen
if (ignore == NULL)
if (ignore != NULL)
fclose(ignore);
- length = &lines;
- return fs;
+ handler->length = lines;
+ handler->filearray = (file_size_t *)
+ realloc(handler->filearray,
+ handler->length * sizeof(file_size_t));
}
-file_size_t * read_input_file(const char *input,
+void read_input_file(const char *input,
const unsigned long long split,
- int *arraylength)
+ file_size_handler_t *handler)
{
FILE *in = fopen(input, "r");
- *arraylength = get_array_length(in);
- file_size_t *fs = (file_size_t *)
- malloc(*arraylength * sizeof(file_size_t));
-
- fs = fill_array_from_file(in, fs, split, arraylength);
- fs = (file_size_t *)
- realloc(fs, *arraylength * sizeof(file_size_t));
+ malloc_array_length(in, handler);
+ fill_array_from_file(in, split, handler);
fclose(in);
-
- return fs;
}
#ifndef _READFILE_H
#define _READFILE_H
-/**
- * Liest die Input Datei in den RAM ein
- *
- * @input Pfad zur Textdatei mit dem Dateipfaden
- *
- * @return file_size struct array
- */
-file_size_t * read_input_file(const char *input,
+void read_input_file(const char *input,
const unsigned long long split,
- int *arraylength);
+ file_size_handler_t *handler);
#endif
printEvent(output, splitgroesse);
}
-file_size_t * splitter(file_size_t *input, const char *output,
- unsigned long long splitgroesse, int *arraylength)
+void splitter(file_size_handler_t *handler, const char *output, unsigned long long splitgroesse)
{
file_size_t *rest = (file_size_t *)
- malloc(*arraylength * sizeof(file_size_t));
+ malloc(handler->length * sizeof(file_size_t));
file_size_t *disc = (file_size_t *)
- malloc(*arraylength * sizeof(file_size_t));
+ malloc(handler->length * sizeof(file_size_t));
unsigned long long filesize = 0;
int restcount = 0;
int disccount = 0;
- for (int i = 0; i < *arraylength; i++) {
+ for (int i = 0; i < handler->length; i++) {
// ISO9660 filesystem overhead
- filesize = ceil(input[i].fsize / 2048.0) * 2048;
+ filesize = ceil(handler->filearray[i].fsize / 2048.0) * 2048;
if (splitgroesse >= filesize) {
splitgroesse -= filesize;
- disc[disccount++] = input[i];
+ disc[disccount++] = handler->filearray[i];
} else {
- rest[restcount++] = input[i];
+ rest[restcount++] = handler->filearray[i];
}
}
onPrintEvent(output, splitgroesse);
- if (restcount > 0) {
- memcpy(input, rest, restcount * sizeof(file_size_t));
- input = (file_size_t *)
- realloc(input, restcount * sizeof(file_size_t));
- }
+ memcpy(handler->filearray, rest, restcount * sizeof(file_size_t));
+ handler->filearray = (file_size_t *) realloc(handler->filearray,
+ restcount * sizeof(file_size_t));
- free(rest);
+ handler->length = restcount;
free(disc);
- *arraylength = restcount;
- return input;
+ free(rest);
}
#ifndef _SPLITTER_H
#define _SPLITTER_H
-/**
- * PrintEvent umd Informationen Anzeigen zur laufzeit Anzeigen zu lassen.
- *
- * @param output Ausgabedateinamen
- * @param splitgroesse die Bytes, die uebrig geblieben sind
- */
void (*printEvent)(const char *output, unsigned long long splitgroesse);
-/**
- * Schreibt in eine Datei die Pfade der Dateien, die auf das Medium passen. Wenn
- * ein Rest uebrig bleibt wird das Array reallociert und die Restlange zurueck-
- * gegeben.
- *
- * @param pointer auf das Array mit file_size struct
- * @param pointer auf den string fuer den Ausgabepfad der Datei
- * @param Splitgroesse
- * @param maximale Laenge des neuen Arrays
- *
- * @return Restlaenge des neuen Arrays
- */
-file_size_t * splitter(file_size_t *input, const char *output,
- unsigned long long splitgroesse, int *arraylength);
+void splitter(file_size_handler_t *handler, const char *output,
+ unsigned long long splitgroesse);
#endif