diff --git a/Aufgabe 1/main.c b/Aufgabe 1/main.c index 7f7ad39..7e8e77f 100644 --- a/Aufgabe 1/main.c +++ b/Aufgabe 1/main.c @@ -1,10 +1,54 @@ #include #include #include +#include #include "../libs/utf8.h" - #define SIZEOFARR(a) (sizeof(a)/sizeof(a[0])) +static struct argp_option options[] = { + {0} +}; +struct arguments{ + char *text; + char *stoerung; +}; +static char args_doc[] = "TEXT_PATH STOERUNG_PATH"; +static error_t parse_opt(int key, char *arg, struct argp_state *state){ + + struct arguments *arguments = state->input; + switch(key){ + + case ARGP_KEY_ARG: + switch (state->arg_num) + { + case 0: + arguments->text=arg; + break; + case 1: + arguments->stoerung=arg; + break; + default: + //To many arguments + argp_usage(state); + break; + } + break; + + case ARGP_KEY_END: + // Not enough arguments. + if(state->arg_num < 2) + argp_usage(state); + break; + + default: + return ARGP_ERR_UNKNOWN; + } + + return 0; +} +static struct argp argp = {options, parse_opt, args_doc}; + + char allowed_chars[] = "aäbcdefghijklmnoöpqrstuüvwxyzAÄBCDEFGHIJKLMNOÖPQRSTUÜVWXYZß1234567890 \n"; unsigned short int arrContains(char checkForVal, char *checkInArr, int arrSize) @@ -156,26 +200,30 @@ int get_matching_sentences(int text_occurances[],struct Gap_sentence *gap_senten return text_occurance_count-1; } -int main(int argc, char const *argv[]) +int main(int argc, char **argv) { + struct arguments arguments; + argp_parse(&argp, argc, argv, 0, 0, &arguments); + + char words[30000][20]; - if(import_text("/home/xor/coding/BwInf_41_1/Aufgabe 1/Alice_im_Wunderland.txt",sizeof(words[0])/sizeof(words[0][0]),words)!=0){ + if(import_text(arguments.text,SIZEOFARR(words[0]),words)!=0) + { + //printf("%s\n",arguments.text); printf("Error importing Text\n"); return -1; } struct Gap_sentence gap_sentence; - if(import_gap_sentence("/home/xor/coding/BwInf_41_1/Aufgabe 1/stoerung0.txt",&gap_sentence)!=0){ + if(import_gap_sentence(arguments.stoerung,&gap_sentence)!=0) + { printf("Error importing stoerung\n"); return -1; } - int text_occurances[100]; - int text_occurance_count = get_matching_sentences(text_occurances,&gap_sentence,sizeof(words)/sizeof(words[0]),sizeof(words[0])/sizeof(words[0][0]),words); + int text_occurance_count = get_matching_sentences(text_occurances,&gap_sentence,SIZEOFARR(words),SIZEOFARR(words[0]),words); - - for(int j = 0; j<=text_occurance_count;j++) { for (int i=0;i