]> gitweb.hhaalo.de Git - discspan.git/commitdiff
change: compile with shared lib subdir
authorBastian Dehn <hhaalo@arcor.de>
Fri, 13 Aug 2021 21:50:50 +0000 (23:50 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Fri, 13 Aug 2021 21:50:50 +0000 (23:50 +0200)
24 files changed:
CMakeLists.txt
discspan/discspan.c [deleted file]
discspan/help.c [deleted file]
discspan/help.h [deleted file]
libs/spandisc/CMakeLists.txt [new file with mode: 0644]
libs/spandisc/include/filehandler.h [new file with mode: 0644]
libs/spandisc/include/libspandisc.h [new file with mode: 0644]
libs/spandisc/include/logic.h [new file with mode: 0644]
libs/spandisc/include/spandisc.h [new file with mode: 0644]
libs/spandisc/include/splitter.h [new file with mode: 0644]
libs/spandisc/src/filehandler.c [new file with mode: 0644]
libs/spandisc/src/logic.c [new file with mode: 0644]
libs/spandisc/src/splitter.c [new file with mode: 0644]
libspandisc/filehandler.c [deleted file]
libspandisc/filehandler.h [deleted file]
libspandisc/libspandisc.h [deleted file]
libspandisc/logic.c [deleted file]
libspandisc/logic.h [deleted file]
libspandisc/spandisc.h [deleted file]
libspandisc/splitter.c [deleted file]
libspandisc/splitter.h [deleted file]
src/discspan.c [new file with mode: 0644]
src/help.c [new file with mode: 0644]
src/help.h [new file with mode: 0644]

index b8136339f90097840c06e9b574049097ca50c941..f88f7938918b7da0cb7d2d6918d78474d92c70e2 100644 (file)
@@ -4,32 +4,16 @@ set(CMAKE_C_COMPILER gcc)
 set(CMAKE_C_FLAGS "-Wall")
 
 set(BINPATH "/usr/local/bin")
-set(LIBPATH "/usr/local/lib")
-set(HEADERPATH "/usr/local/include")
 
 project(discspan)
 
-include_directories(libspandisc)
-if (SHAREDLIB)
-       file(GLOB SOURCES discspan/*.c)
+file(GLOB SOURCES src/*.c)
+set(SOURCES ${SOURCES})
 
-       file(GLOB SOURCE_LIB libspandisc/*.c)
-       file(GLOB PUBLIC_HEADER libspandisc/*.h)
-       add_library(spandisc SHARED ${SOURCE_LIB})
-       set_target_properties(spandisc PROPERTIES PUBLIC_HEADER "${PUBLIC_HEADER}")
-       install(TARGETS spandisc DESTINATION ${BINPATH}
-               LIBRARY DESTINATION ${LIBPATH}
-               PUBLIC_HEADER DESTINATION ${HEADERPATH})
-else()
-       file(GLOB SOURCES discspan/*.c libspandisc/*.c)
-endif()
+include_directories(libs/spandisc/include)
+add_subdirectory(libs/spandisc)
 
 add_executable(discspan ${SOURCES})
-
-if (SHAREDLIB)
-       target_link_libraries(discspan m "-L." spandisc)
-else()
-       target_link_libraries(discspan m)
-endif()
+target_link_libraries(discspan m "-L." spandisc)
 
 install(TARGETS discspan DESTINATION ${BINPATH})
diff --git a/discspan/discspan.c b/discspan/discspan.c
deleted file mode 100644 (file)
index df1c561..0000000
+++ /dev/null
@@ -1,101 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-#include "spandisc.h"
-#include "logic.h"
-#include "help.h"
-
-typedef struct {
-       char *input;
-       char *output;
-       unsigned long long split;
-} param_t;
-
-param_t readArgument(int argc, char *argv[])
-{
-       param_t parameter = { NULL, NULL, 0 };
-
-       // Medien groessen
-       const unsigned long long bluray = 24159191040;
-       const unsigned long long dvd9 = 8500000000;
-       const unsigned long long dvd5 = 4700000000;
-       const unsigned long long cd = 734003200;
-
-       int c = 0;
-       while ((c = getopt(argc, argv, ":59bcf:hi:o:")) != -1) {
-               switch (c) {
-               case 'i':
-                       parameter.input = optarg;
-                       break;
-               case 'o':
-                       parameter.output = optarg;
-                       break;
-               case '5':
-                       parameter.split = dvd5;
-                       break;
-               case '9':
-                       parameter.split = dvd9;
-                       break;
-               case 'b':
-                       parameter.split = bluray;
-                       break;
-               case 'c':
-                       parameter.split = cd;
-                       break;
-               case 'f':
-                       parameter.split = atoll(optarg);
-                       break;
-               case 'h':
-                       useage();
-                       exit(0);
-                       break;
-               default:
-                       printf("WARNUNG: Parameter -%c unbekannt!\n", optopt);
-                       break;
-               }
-       }
-
-       return parameter;
-}
-
-void print_human_read_size(const char *output, medium_t medium)
-{
-       unsigned long long humanread;
-       char einheit[6] = {'B', 'K', 'M', 'G', 'T', 'P'};
-       int i = 0;
-
-       humanread = medium.freespace;
-       while (humanread >= 1024) {
-               humanread /= 1024;
-               i++;
-       }
-
-       if (i > sizeof(einheit)/sizeof(einheit[0]))
-               i = 0;
-
-       printf("Restlicher Platz in Bytes(%s): %lld (%lld %c)\n", output,
-                       medium.freespace, humanread, einheit[i]);
-}
-
-int main(int argc, char *argv[])
-{
-       param_t parameter = readArgument(argc, argv);
-
-       if (parameter.input == NULL
-                       || parameter.output == NULL
-                       || parameter.split < 2048) {
-               useage();
-               exit(1);
-       }
-
-       if (access(parameter.input, F_OK) < 0) {
-               printf("ERROR: %s existiert nicht!\n", parameter.input);
-               exit(1);
-       }
-
-       status_print = print_human_read_size;
-       span(parameter.input, parameter.output, parameter.split);
-
-       return 0;
-}
diff --git a/discspan/help.c b/discspan/help.c
deleted file mode 100644 (file)
index eb018f0..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-#include <stdio.h>
-#include "help.h"
-
-void useage()
-{
-       printf("\nUsage: discspan <option> -i <source> -o <prefix>\n\n");
-       printf("   -i <source>\tpath to source file\n");
-       printf("   -o <prefix>\tprefix for output files\n\n");
-       printf("Option:\n\n");
-       printf("   -b\t\tsize of Bluray: 25.000.000.000 bytes\n");
-       printf("   -9\t\tsize of double layer DVD 8.500.000.000 bytes\n");
-       printf("   -5\t\tsize of sigle layer DVD: 4.700.000.000 bytes\n");
-       printf("   -c\t\tsize of CD: 734.003.200 bytes\n");
-       printf("   -f <size>\tsize in bytes\n");
-       printf("   -h\t\tshow this help\n\n");
-}
diff --git a/discspan/help.h b/discspan/help.h
deleted file mode 100644 (file)
index 5744339..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-#ifndef _HELP_H
-#define _HELP_H
-
-void useage();
-
-#endif
diff --git a/libs/spandisc/CMakeLists.txt b/libs/spandisc/CMakeLists.txt
new file mode 100644 (file)
index 0000000..fec7038
--- /dev/null
@@ -0,0 +1,14 @@
+cmake_minimum_required(VERSION 3.13.4)
+
+set(INSTALL_LIBPATH /usr/local/lib)
+set(INSTALL_HEADER /usr/local/include/spandisc)
+
+project(spandisc)
+
+file(GLOB SOURCES src/*.c)
+file(GLOB PUBLIC_HEADER include/*.h)
+include_directories(include)
+add_library(spandisc SHARED ${SOURCES})
+set_target_properties(spandisc PROPERTIES PUBLIC_HEADER "${PUBLIC_HEADER}")
+install(TARGETS spandisc DESTINATION ${INSTALL_LIBPATH}
+       PUBLIC_HEADER DESTINATION ${INSTALL_HEADER})
diff --git a/libs/spandisc/include/filehandler.h b/libs/spandisc/include/filehandler.h
new file mode 100644 (file)
index 0000000..04bd2ee
--- /dev/null
@@ -0,0 +1,8 @@
+#ifndef _FILEHANDLER_H
+#define _FILEHANDLER_H
+
+void read_input_file(const char *input, medium_t *srcdata);
+
+void write_output_file(const char *output, medium_t disc);
+
+#endif
diff --git a/libs/spandisc/include/libspandisc.h b/libs/spandisc/include/libspandisc.h
new file mode 100644 (file)
index 0000000..5c07e22
--- /dev/null
@@ -0,0 +1,9 @@
+#ifndef LIBSPANDISC_H
+#define LIBSPANDISC_H
+
+#include "spandisc.h"
+#include "logic.h"
+#include "filehandler.h"
+#include "splitter.h"
+
+#endif
diff --git a/libs/spandisc/include/logic.h b/libs/spandisc/include/logic.h
new file mode 100644 (file)
index 0000000..e7e4740
--- /dev/null
@@ -0,0 +1,8 @@
+#ifndef _LOGIC_H
+#define _LOGIC_H
+
+void (*status_print)(const char *output, medium_t disc);
+
+void span(const char *input, const char *output, unsigned long long split);
+
+#endif
diff --git a/libs/spandisc/include/spandisc.h b/libs/spandisc/include/spandisc.h
new file mode 100644 (file)
index 0000000..244ee16
--- /dev/null
@@ -0,0 +1,22 @@
+#ifndef _SPANDISC_H
+#define _SPANDISC_H
+
+typedef struct {
+       char name[255];
+       unsigned long long fsize;
+       unsigned int type;
+} file_size_t;
+
+typedef struct {
+       int nr;
+       unsigned long long freespace;
+       int length;
+       file_size_t *filearray;
+} medium_t;
+
+typedef struct {
+       int length;
+       medium_t *disc;
+} collection_t;
+
+#endif
diff --git a/libs/spandisc/include/splitter.h b/libs/spandisc/include/splitter.h
new file mode 100644 (file)
index 0000000..3c5c148
--- /dev/null
@@ -0,0 +1,8 @@
+#ifndef _SPLITTER_H
+#define _SPLITTER_H
+
+medium_t splitter(medium_t *srcdata);
+medium_t ignore(medium_t *srcdata);
+collection_t split_all(medium_t *srcdata);
+
+#endif
diff --git a/libs/spandisc/src/filehandler.c b/libs/spandisc/src/filehandler.c
new file mode 100644 (file)
index 0000000..cb209af
--- /dev/null
@@ -0,0 +1,58 @@
+#include <sys/stat.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "spandisc.h"
+#include "filehandler.h"
+
+void malloc_array_length(FILE *in, medium_t *srcdata)
+{
+       int lines = 0;
+       char pfad[255];
+
+       while (fscanf(in, "%[^\n]\n", pfad) == 1) {
+               lines++;
+       }
+       rewind(in);
+
+       srcdata->length = lines;
+       srcdata->filearray = (file_size_t *)
+               malloc(srcdata->length * sizeof(file_size_t));
+}
+
+void fill_array_from_file(FILE *in, medium_t *srcdata)
+{
+       char pfad[255];
+       struct stat st;
+       int lines = 0;
+
+       while (fscanf(in, "%[^\n]\n", pfad) == 1) {
+               // Lese Dateieigenschaften in st struct
+               stat(pfad, &st);
+               strcpy(srcdata->filearray[lines].name, pfad);
+               srcdata->filearray[lines].type = st.st_mode;
+               srcdata->filearray[lines++].fsize = st.st_size;
+       }
+}
+
+void read_input_file(const char *input, medium_t *srcdata)
+{
+       FILE *in = fopen(input, "r");
+
+       malloc_array_length(in, srcdata);
+       fill_array_from_file(in, srcdata);
+
+       fclose(in);
+}
+
+void write_output_file(const char *output, medium_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);
+}
diff --git a/libs/spandisc/src/logic.c b/libs/spandisc/src/logic.c
new file mode 100644 (file)
index 0000000..0ab352d
--- /dev/null
@@ -0,0 +1,49 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "spandisc.h"
+#include "logic.h"
+#include "splitter.h"
+#include "filehandler.h"
+
+void on_status_print(const char *output, medium_t disc)
+{
+       if (status_print != NULL)
+               status_print(output, disc);
+}
+
+int cmpfunc(const void *filea, const void *fileb)
+{
+       unsigned long long a = ((const file_size_t*)filea)->fsize;
+       unsigned long long b = ((const file_size_t*)fileb)->fsize;
+
+       if (a < b)
+               return 1;
+       else if (a > b)
+               return -1;
+       else if (a == b)
+               return 0;
+       else
+               return -2;
+}
+
+void span(const char *input, const char *output, unsigned long long split)
+{
+       medium_t srcdata = { 0, split, 0, NULL };
+       read_input_file(input, &srcdata);
+
+       qsort(srcdata.filearray, srcdata.length, sizeof(file_size_t), cmpfunc);
+
+       collection_t col = split_all(&srcdata);
+
+       char outname[strlen(output) + 4];
+       for (int i = 0; i < col.length; i++) {
+               sprintf(outname, "%s%04d", output, col.disc[i].nr);
+               on_status_print(outname, col.disc[i]);
+               write_output_file(outname, col.disc[i]);
+               free(col.disc[i].filearray);
+       }
+
+       free(col.disc);
+}
diff --git a/libs/spandisc/src/splitter.c b/libs/spandisc/src/splitter.c
new file mode 100644 (file)
index 0000000..54f48a3
--- /dev/null
@@ -0,0 +1,121 @@
+#include <math.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "spandisc.h"
+#include "splitter.h"
+
+#define S_IFREG 0100000 // bitmask for regular file; man inode
+
+medium_t init_empty_medium(medium_t srcdata)
+{
+       medium_t empty;
+       empty.nr = srcdata.nr;
+       empty.freespace = srcdata.freespace;
+       empty.length = 0;
+       empty.filearray = (file_size_t *)
+               malloc(1 * sizeof(file_size_t));
+       return empty;
+}
+
+int can_add_file_to_medium(medium_t *disc, file_size_t file)
+{
+       int retvalue = 0;
+
+       // ISO9660 filesystem overhead
+       unsigned long long filesize = ceil(file.fsize / 2048.0) * 2048;
+
+       if (disc->freespace >= filesize) {
+               disc->freespace -= filesize;
+               retvalue = 1;
+       }
+
+       return retvalue;
+}
+
+int bigger_file_ignore_medium(medium_t *disc, file_size_t file)
+{
+       int retvalue = 0;
+       unsigned long long filesize = ceil(file.fsize /2048.0) * 2048;
+
+       if ((file.type & S_IFREG) != S_IFREG)
+               retvalue = 1;
+
+       if (disc->freespace < filesize)
+               retvalue = 1;
+
+       return retvalue;
+}
+
+void add_item_medium(medium_t *medium, file_size_t item)
+{
+       medium->filearray = (file_size_t *)realloc(medium->filearray,
+                       (medium->length + 1) *
+                       sizeof(file_size_t));
+       medium->filearray[medium->length] = item;
+       medium->length++;
+}
+
+medium_t splitter_to_disc(medium_t *srcdata,
+               int (*check)(medium_t*, file_size_t))
+{
+       medium_t rest = init_empty_medium(*srcdata);
+       medium_t disc = init_empty_medium(*srcdata);
+
+       for (int i = 0; i < srcdata->length; i++) {
+               if (check(&disc, srcdata->filearray[i]))
+                       add_item_medium(&disc, srcdata->filearray[i]);
+               else
+                       add_item_medium(&rest, srcdata->filearray[i]);
+       }
+
+       memcpy(srcdata->filearray, rest.filearray,
+                       rest.length * sizeof(file_size_t));
+
+       srcdata->length = rest.length;
+       srcdata->filearray = (file_size_t *) realloc(srcdata->filearray,
+                                       srcdata->length * sizeof(file_size_t));
+
+       free(rest.filearray);
+       return disc;
+}
+
+medium_t splitter(medium_t *srcdata)
+{
+       medium_t disc = splitter_to_disc(srcdata, can_add_file_to_medium);
+       return disc;
+}
+
+medium_t ignore(medium_t *srcdata)
+{
+       medium_t ignore = splitter_to_disc(srcdata, bigger_file_ignore_medium);
+       return ignore;
+}
+
+collection_t split_all(medium_t *srcdata)
+{
+       collection_t col;
+       col.length = 0;
+       col.disc = NULL;
+
+       medium_t ignoredisc;
+       ignoredisc = ignore(srcdata);
+       ignoredisc.freespace = 0;
+       if (ignoredisc.length > 0) {
+               col.disc = (medium_t *)malloc(sizeof(medium_t));
+               col.disc[col.length] = ignoredisc;
+               col.length++;
+       }
+
+       while (srcdata->length > 0) {
+               srcdata->nr++;
+               medium_t disc = splitter(srcdata);
+               col.disc = (medium_t *)
+                       realloc(col.disc, (col.length + 1) * sizeof(medium_t));
+               col.disc[col.length] = disc;
+               col.length++;
+       }
+
+       free(srcdata->filearray);
+       return col;
+}
diff --git a/libspandisc/filehandler.c b/libspandisc/filehandler.c
deleted file mode 100644 (file)
index cb209af..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-#include <sys/stat.h>
-#include <string.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-#include "spandisc.h"
-#include "filehandler.h"
-
-void malloc_array_length(FILE *in, medium_t *srcdata)
-{
-       int lines = 0;
-       char pfad[255];
-
-       while (fscanf(in, "%[^\n]\n", pfad) == 1) {
-               lines++;
-       }
-       rewind(in);
-
-       srcdata->length = lines;
-       srcdata->filearray = (file_size_t *)
-               malloc(srcdata->length * sizeof(file_size_t));
-}
-
-void fill_array_from_file(FILE *in, medium_t *srcdata)
-{
-       char pfad[255];
-       struct stat st;
-       int lines = 0;
-
-       while (fscanf(in, "%[^\n]\n", pfad) == 1) {
-               // Lese Dateieigenschaften in st struct
-               stat(pfad, &st);
-               strcpy(srcdata->filearray[lines].name, pfad);
-               srcdata->filearray[lines].type = st.st_mode;
-               srcdata->filearray[lines++].fsize = st.st_size;
-       }
-}
-
-void read_input_file(const char *input, medium_t *srcdata)
-{
-       FILE *in = fopen(input, "r");
-
-       malloc_array_length(in, srcdata);
-       fill_array_from_file(in, srcdata);
-
-       fclose(in);
-}
-
-void write_output_file(const char *output, medium_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);
-}
diff --git a/libspandisc/filehandler.h b/libspandisc/filehandler.h
deleted file mode 100644 (file)
index 04bd2ee..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-#ifndef _FILEHANDLER_H
-#define _FILEHANDLER_H
-
-void read_input_file(const char *input, medium_t *srcdata);
-
-void write_output_file(const char *output, medium_t disc);
-
-#endif
diff --git a/libspandisc/libspandisc.h b/libspandisc/libspandisc.h
deleted file mode 100644 (file)
index 5c07e22..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-#ifndef LIBSPANDISC_H
-#define LIBSPANDISC_H
-
-#include "spandisc.h"
-#include "logic.h"
-#include "filehandler.h"
-#include "splitter.h"
-
-#endif
diff --git a/libspandisc/logic.c b/libspandisc/logic.c
deleted file mode 100644 (file)
index 0ab352d..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "spandisc.h"
-#include "logic.h"
-#include "splitter.h"
-#include "filehandler.h"
-
-void on_status_print(const char *output, medium_t disc)
-{
-       if (status_print != NULL)
-               status_print(output, disc);
-}
-
-int cmpfunc(const void *filea, const void *fileb)
-{
-       unsigned long long a = ((const file_size_t*)filea)->fsize;
-       unsigned long long b = ((const file_size_t*)fileb)->fsize;
-
-       if (a < b)
-               return 1;
-       else if (a > b)
-               return -1;
-       else if (a == b)
-               return 0;
-       else
-               return -2;
-}
-
-void span(const char *input, const char *output, unsigned long long split)
-{
-       medium_t srcdata = { 0, split, 0, NULL };
-       read_input_file(input, &srcdata);
-
-       qsort(srcdata.filearray, srcdata.length, sizeof(file_size_t), cmpfunc);
-
-       collection_t col = split_all(&srcdata);
-
-       char outname[strlen(output) + 4];
-       for (int i = 0; i < col.length; i++) {
-               sprintf(outname, "%s%04d", output, col.disc[i].nr);
-               on_status_print(outname, col.disc[i]);
-               write_output_file(outname, col.disc[i]);
-               free(col.disc[i].filearray);
-       }
-
-       free(col.disc);
-}
diff --git a/libspandisc/logic.h b/libspandisc/logic.h
deleted file mode 100644 (file)
index e7e4740..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-#ifndef _LOGIC_H
-#define _LOGIC_H
-
-void (*status_print)(const char *output, medium_t disc);
-
-void span(const char *input, const char *output, unsigned long long split);
-
-#endif
diff --git a/libspandisc/spandisc.h b/libspandisc/spandisc.h
deleted file mode 100644 (file)
index 244ee16..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-#ifndef _SPANDISC_H
-#define _SPANDISC_H
-
-typedef struct {
-       char name[255];
-       unsigned long long fsize;
-       unsigned int type;
-} file_size_t;
-
-typedef struct {
-       int nr;
-       unsigned long long freespace;
-       int length;
-       file_size_t *filearray;
-} medium_t;
-
-typedef struct {
-       int length;
-       medium_t *disc;
-} collection_t;
-
-#endif
diff --git a/libspandisc/splitter.c b/libspandisc/splitter.c
deleted file mode 100644 (file)
index 54f48a3..0000000
+++ /dev/null
@@ -1,121 +0,0 @@
-#include <math.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "spandisc.h"
-#include "splitter.h"
-
-#define S_IFREG 0100000 // bitmask for regular file; man inode
-
-medium_t init_empty_medium(medium_t srcdata)
-{
-       medium_t empty;
-       empty.nr = srcdata.nr;
-       empty.freespace = srcdata.freespace;
-       empty.length = 0;
-       empty.filearray = (file_size_t *)
-               malloc(1 * sizeof(file_size_t));
-       return empty;
-}
-
-int can_add_file_to_medium(medium_t *disc, file_size_t file)
-{
-       int retvalue = 0;
-
-       // ISO9660 filesystem overhead
-       unsigned long long filesize = ceil(file.fsize / 2048.0) * 2048;
-
-       if (disc->freespace >= filesize) {
-               disc->freespace -= filesize;
-               retvalue = 1;
-       }
-
-       return retvalue;
-}
-
-int bigger_file_ignore_medium(medium_t *disc, file_size_t file)
-{
-       int retvalue = 0;
-       unsigned long long filesize = ceil(file.fsize /2048.0) * 2048;
-
-       if ((file.type & S_IFREG) != S_IFREG)
-               retvalue = 1;
-
-       if (disc->freespace < filesize)
-               retvalue = 1;
-
-       return retvalue;
-}
-
-void add_item_medium(medium_t *medium, file_size_t item)
-{
-       medium->filearray = (file_size_t *)realloc(medium->filearray,
-                       (medium->length + 1) *
-                       sizeof(file_size_t));
-       medium->filearray[medium->length] = item;
-       medium->length++;
-}
-
-medium_t splitter_to_disc(medium_t *srcdata,
-               int (*check)(medium_t*, file_size_t))
-{
-       medium_t rest = init_empty_medium(*srcdata);
-       medium_t disc = init_empty_medium(*srcdata);
-
-       for (int i = 0; i < srcdata->length; i++) {
-               if (check(&disc, srcdata->filearray[i]))
-                       add_item_medium(&disc, srcdata->filearray[i]);
-               else
-                       add_item_medium(&rest, srcdata->filearray[i]);
-       }
-
-       memcpy(srcdata->filearray, rest.filearray,
-                       rest.length * sizeof(file_size_t));
-
-       srcdata->length = rest.length;
-       srcdata->filearray = (file_size_t *) realloc(srcdata->filearray,
-                                       srcdata->length * sizeof(file_size_t));
-
-       free(rest.filearray);
-       return disc;
-}
-
-medium_t splitter(medium_t *srcdata)
-{
-       medium_t disc = splitter_to_disc(srcdata, can_add_file_to_medium);
-       return disc;
-}
-
-medium_t ignore(medium_t *srcdata)
-{
-       medium_t ignore = splitter_to_disc(srcdata, bigger_file_ignore_medium);
-       return ignore;
-}
-
-collection_t split_all(medium_t *srcdata)
-{
-       collection_t col;
-       col.length = 0;
-       col.disc = NULL;
-
-       medium_t ignoredisc;
-       ignoredisc = ignore(srcdata);
-       ignoredisc.freespace = 0;
-       if (ignoredisc.length > 0) {
-               col.disc = (medium_t *)malloc(sizeof(medium_t));
-               col.disc[col.length] = ignoredisc;
-               col.length++;
-       }
-
-       while (srcdata->length > 0) {
-               srcdata->nr++;
-               medium_t disc = splitter(srcdata);
-               col.disc = (medium_t *)
-                       realloc(col.disc, (col.length + 1) * sizeof(medium_t));
-               col.disc[col.length] = disc;
-               col.length++;
-       }
-
-       free(srcdata->filearray);
-       return col;
-}
diff --git a/libspandisc/splitter.h b/libspandisc/splitter.h
deleted file mode 100644 (file)
index 3c5c148..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-#ifndef _SPLITTER_H
-#define _SPLITTER_H
-
-medium_t splitter(medium_t *srcdata);
-medium_t ignore(medium_t *srcdata);
-collection_t split_all(medium_t *srcdata);
-
-#endif
diff --git a/src/discspan.c b/src/discspan.c
new file mode 100644 (file)
index 0000000..df1c561
--- /dev/null
@@ -0,0 +1,101 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "spandisc.h"
+#include "logic.h"
+#include "help.h"
+
+typedef struct {
+       char *input;
+       char *output;
+       unsigned long long split;
+} param_t;
+
+param_t readArgument(int argc, char *argv[])
+{
+       param_t parameter = { NULL, NULL, 0 };
+
+       // Medien groessen
+       const unsigned long long bluray = 24159191040;
+       const unsigned long long dvd9 = 8500000000;
+       const unsigned long long dvd5 = 4700000000;
+       const unsigned long long cd = 734003200;
+
+       int c = 0;
+       while ((c = getopt(argc, argv, ":59bcf:hi:o:")) != -1) {
+               switch (c) {
+               case 'i':
+                       parameter.input = optarg;
+                       break;
+               case 'o':
+                       parameter.output = optarg;
+                       break;
+               case '5':
+                       parameter.split = dvd5;
+                       break;
+               case '9':
+                       parameter.split = dvd9;
+                       break;
+               case 'b':
+                       parameter.split = bluray;
+                       break;
+               case 'c':
+                       parameter.split = cd;
+                       break;
+               case 'f':
+                       parameter.split = atoll(optarg);
+                       break;
+               case 'h':
+                       useage();
+                       exit(0);
+                       break;
+               default:
+                       printf("WARNUNG: Parameter -%c unbekannt!\n", optopt);
+                       break;
+               }
+       }
+
+       return parameter;
+}
+
+void print_human_read_size(const char *output, medium_t medium)
+{
+       unsigned long long humanread;
+       char einheit[6] = {'B', 'K', 'M', 'G', 'T', 'P'};
+       int i = 0;
+
+       humanread = medium.freespace;
+       while (humanread >= 1024) {
+               humanread /= 1024;
+               i++;
+       }
+
+       if (i > sizeof(einheit)/sizeof(einheit[0]))
+               i = 0;
+
+       printf("Restlicher Platz in Bytes(%s): %lld (%lld %c)\n", output,
+                       medium.freespace, humanread, einheit[i]);
+}
+
+int main(int argc, char *argv[])
+{
+       param_t parameter = readArgument(argc, argv);
+
+       if (parameter.input == NULL
+                       || parameter.output == NULL
+                       || parameter.split < 2048) {
+               useage();
+               exit(1);
+       }
+
+       if (access(parameter.input, F_OK) < 0) {
+               printf("ERROR: %s existiert nicht!\n", parameter.input);
+               exit(1);
+       }
+
+       status_print = print_human_read_size;
+       span(parameter.input, parameter.output, parameter.split);
+
+       return 0;
+}
diff --git a/src/help.c b/src/help.c
new file mode 100644 (file)
index 0000000..eb018f0
--- /dev/null
@@ -0,0 +1,16 @@
+#include <stdio.h>
+#include "help.h"
+
+void useage()
+{
+       printf("\nUsage: discspan <option> -i <source> -o <prefix>\n\n");
+       printf("   -i <source>\tpath to source file\n");
+       printf("   -o <prefix>\tprefix for output files\n\n");
+       printf("Option:\n\n");
+       printf("   -b\t\tsize of Bluray: 25.000.000.000 bytes\n");
+       printf("   -9\t\tsize of double layer DVD 8.500.000.000 bytes\n");
+       printf("   -5\t\tsize of sigle layer DVD: 4.700.000.000 bytes\n");
+       printf("   -c\t\tsize of CD: 734.003.200 bytes\n");
+       printf("   -f <size>\tsize in bytes\n");
+       printf("   -h\t\tshow this help\n\n");
+}
diff --git a/src/help.h b/src/help.h
new file mode 100644 (file)
index 0000000..5744339
--- /dev/null
@@ -0,0 +1,6 @@
+#ifndef _HELP_H
+#define _HELP_H
+
+void useage();
+
+#endif