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 struct_array_length = 0;
-unsigned long long split = 0;
+ unsigned long long splitgroesse, int *arraylength);
int cmpfunc(const void *filea, const void *fileb)
{
return -2;
}
-void readArgument(int argc, char *argv[])
+const unsigned long long readArgument(int argc, char *argv[])
{
+ unsigned long long split = 0;
+
// Medien groessen
const unsigned long long bluray = 24159191040;
const unsigned long long dvd9 = 8500000000;
break;
}
}
+
+ return split;
}
void printHumanReadSize(const char *output, unsigned long long splitgroesse)
const char *input = argv[1];
const char *output = argv[2];
- readArgument(argc, argv);
- file_size_t *fs = read_input_file(input);
+ int arraylength = 0;
+
+ const unsigned long long split = readArgument(argc, argv);
+ file_size_t *fs = read_input_file(input, split, &arraylength);
- qsort(fs, struct_array_length, sizeof(file_size_t), cmpfunc);
+ qsort(fs, arraylength, sizeof(file_size_t), cmpfunc);
char outname[strlen(output) + 3];
int num = 1;
- while (struct_array_length > 0) {
+ while (arraylength > 0) {
sprintf(outname, "%s%03d", output, num++);
- fs = splitter(fs, outname, split);
+ fs = splitter(fs, outname, split, &arraylength);
}
free(fs);
#include "discspan.h"
#include "readfile.h"
-extern int struct_array_length;
extern unsigned long long split;
/**
* @return Arraylaenge
*/
file_size_t * fill_array_from_file(FILE *in, file_size_t *fs,
- const unsigned long long split)
+ const unsigned long long split,
+ int *length)
{
FILE *ignore = NULL;
char pfad[255];
if (ignore != NULL)
fclose(ignore);
- struct_array_length = lines;
+ length = &lines;
return fs;
}
-file_size_t * read_input_file(const char *input)
+file_size_t * read_input_file(const char *input,
+ const unsigned long long split,
+ int *arraylength)
{
FILE *in = fopen(input, "r");
- struct_array_length = get_array_length(in);
+ *arraylength = get_array_length(in);
file_size_t *fs = (file_size_t *)
- malloc(struct_array_length * sizeof(file_size_t));
+ malloc(*arraylength * sizeof(file_size_t));
- fs = fill_array_from_file(in, fs, split);
+ fs = fill_array_from_file(in, fs, split, arraylength);
fs = (file_size_t *)
- realloc(fs, struct_array_length * sizeof(file_size_t));
+ realloc(fs, *arraylength * sizeof(file_size_t));
fclose(in);
*
* @return file_size struct array
*/
-file_size_t * read_input_file(const char *input);
+file_size_t * read_input_file(const char *input,
+ const unsigned long long split,
+ int *arraylength);
#endif
#include "discspan.h"
#include "splitter.h"
-extern int struct_array_length;
-
void writeOutputFile(const char *outputPath, file_size_t *disc, int length)
{
FILE *out = fopen(outputPath, "w");
}
file_size_t * splitter(file_size_t *input, const char *output,
- unsigned long long splitgroesse)
+ unsigned long long splitgroesse, int *arraylength)
{
file_size_t *rest = (file_size_t *)
- malloc(struct_array_length * sizeof(file_size_t));
+ malloc(*arraylength * sizeof(file_size_t));
file_size_t *disc = (file_size_t *)
- malloc(struct_array_length * sizeof(file_size_t));
+ malloc(*arraylength * sizeof(file_size_t));
unsigned long long filesize = 0;
int restcount = 0;
int disccount = 0;
- for (int i = 0; i < struct_array_length; i++) {
+ for (int i = 0; i < *arraylength; i++) {
// ISO9660 filesystem overhead
filesize = ceil(input[i].fsize / 2048.0) * 2048;
free(rest);
free(disc);
- struct_array_length = restcount;
+ *arraylength = restcount;
return input;
}
* @return Restlaenge des neuen Arrays
*/
file_size_t * splitter(file_size_t *input, const char *output,
- unsigned long long splitgroesse);
+ unsigned long long splitgroesse, int *arraylength);
#endif