all: discspan
-discspan: discspan.o help.o help.h
- $(CC) $(CFLAGS) -o discspan discspan.o help.o
+discspan: discspan.o readfile.o readfile.h help.o help.h
+ $(CC) $(CFLAGS) -o discspan discspan.o readfile.o help.o
-discspan.o: discspan.c
+discspan.o: discspan.h discspan.c
$(CC) $(CFLAGS) -c discspan.c
+readfile.o: discspan.h readfile.h readfile.c
+ $(CC) $(CFLAGS) -c readfile.c
help.o: help.h help.c
$(CC) $(CFLAGS) -c help.c
#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/stat.h>
#include <math.h>
#include <unistd.h>
+#include <string.h>
+#include <stdlib.h>
+#include "discspan.h"
+#include "readfile.h"
#include "help.h"
extern void useage();
int struct_array_length = 0;
unsigned long long split = 0;
-typedef struct file_size {
- char name[255];
- long long unsigned fsize;
-} file_size;
-
-/**
- * Gibt die Groesse in einer lesbaren Darstellung aus
- */
void printHumanReadSize(const char *output, unsigned long long splitgroesse)
{
unsigned long long humanread;
splitgroesse, humanread, einheit[i]);
}
-/**
- * Vergleicht zwei Dateien mit ihrer Groesse
- *
- * @param filea erste Datei
- * @param fileb zweite Datei
- *
- * @return integer
- */
int cmpfunc(const void *filea, const void *fileb)
{
unsigned long long a = ((const struct file_size*)filea)->fsize;
return -2;
}
-/**
- * Ermittelt die Zeilen der Textdatei
- *
- * @param Datei pointer
- *
- * @return Anzahl von Zeilen
- */
-int get_array_length(FILE *in)
-{
- int lines = 0;
- char pfad[255];
-
- while (fscanf(in, "%[^\n]\n", pfad) == 1) {
- lines++;
- }
- rewind(in);
-
- return lines;
-}
-
-/**
- * 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
- */
-int fill_array_from_file(FILE *in, struct file_size *fs,
- const unsigned long long split)
-{
- 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(fs[lines].name, pfad);
- fs[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);
-
- lines--;
- return lines;
-}
-
/**
* 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-
}
}
-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 fs;
-}
-
int main(int argc, char *argv[])
{
const char *input = argv[1];
--- /dev/null
+#include <sys/stat.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include "readfile.h"
+
+extern int struct_array_length;
+extern unsigned long long split;
+extern struct file_size *fs;
+
+/**
+ * Ermittelt die Zeilen der Textdatei
+ *
+ * @param Datei pointer
+ *
+ * @return Anzahl von Zeilen
+ */
+int get_array_length(FILE *in)
+{
+ int lines = 0;
+ char pfad[255];
+
+ while (fscanf(in, "%[^\n]\n", pfad) == 1) {
+ lines++;
+ }
+ rewind(in);
+
+ return lines;
+}
+
+/**
+ * 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
+ */
+int fill_array_from_file(FILE *in, struct file_size *fs,
+ const unsigned long long split)
+{
+ 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(fs[lines].name, pfad);
+ fs[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);
+
+ lines--;
+ return lines;
+}
+
+/**
+ * Liest die Input Datei in den RAM ein
+ *
+ * @input Pfad zur Textdatei mit dem Dateipfaden
+ *
+ * @return file_size struct array
+ */
+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 fs;
+}