extern void useage();
+int struct_array_length = 0;
+unsigned long long int split = 0;
+
typedef struct file_size {
char name[255];
long long unsigned int fsize;
return restcount;
}
-unsigned long long readArgument(int argc, char *argv[])
+void readArgument(int argc, char *argv[])
{
// Medien groessen
const unsigned long long bluray = 25000000000;
const unsigned long long dvd5 = 4700000000;
const unsigned long long cd = 734003200;
- unsigned long long split = 0;
-
int c = 0;
while ((c = getopt(argc, argv, ":59bcf:")) != -1) {
switch (c) {
break;
case 'h':
usage();
- return 0;
break;
}
}
+}
+
+file_size * read_input_file(const char *input)
+{
+ FILE *in = fopen(input, "r");
+
+ struct_array_length = get_array_length(in);
+ struct file_size *fs = (struct file_size *)
+ malloc(struct_array_length * sizeof(struct file_size));
+
+ struct_array_length = fill_array_from_file(in, fs, split);
+ fs = (struct file_size *)
+ realloc(fs, struct_array_length * sizeof(struct file_size));
+
+ fclose(in);
- return split;
+ return fs;
}
-/**
- * Hauptfunktion
- *
- * @param Anzahl der Argumente
- * @param Argument Array
- *
- * @return Erfolgreich 0; Fehler 1
- */
int main(int argc, char *argv[])
{
const char *input = argv[1];
const char *output = argv[2];
- unsigned long long int split = 0;
- // gib die Funktionsübersicht aus bei zu wenig Parameter
if (argc <= 3) {
usage();
return 1;
}
- split = readArgument(argc, argv);
-
- // Liest die Quelldatei in den Ram
- FILE *in = fopen(input, "r");
-
- int s_length = get_array_length(in);
- struct file_size *fs = (struct file_size *)
- malloc(s_length * sizeof(struct file_size));
-
- s_length = fill_array_from_file(in, fs, split);
- fs = (struct file_size *)
- realloc(fs, s_length * sizeof(struct file_size));
-
- fclose(in);
+ readArgument(argc, argv);
+ struct file_size *fs = read_input_file(input);
- // sortieren
- // s_length is array length 0 bis xy
- qsort(fs, (s_length + 1), sizeof(struct file_size), cmpfunc);
+ qsort(fs, (struct_array_length + 1), sizeof(struct file_size), cmpfunc);
char outname[strlen(output) + 3];
int num = 1;
- while (s_length > 0) {
+ while (struct_array_length > 0) {
sprintf(outname, "%s%03d", output, num++);
- s_length = splitter(fs, outname, split, s_length);
+ struct_array_length = splitter(fs, outname, split, struct_array_length);
}
free(fs);