commit 548ef13df181252d9064ef766b01e596b2190683 Author: vaydheesh Date: Sat Aug 17 22:16:09 2019 +0530 added: getopts and more flags diff --git a/python/apertium_core.i b/python/apertium_core.i index 2c6624f..39eed93 100644 --- a/python/apertium_core.i +++ b/python/apertium_core.i @@ -44,16 +44,47 @@ #include #include +#include + /** * Imitates functionality of apertium-core binaries using file path */ -void pretransfer(char arg, char *input_path, char *output_path) +void pretransfer(int argc, char **argv, char *input_path, char *output_path) { - bool useMaxEnt = false; - FILE *input = fopen(input_path, "r"), *output = fopen(output_path, "w"); - processStream(input, output, false, false, false); + FILE* input = fopen(input_path, "r"); + FILE* output = fopen(output_path, "w"); + bool compound_sep = false; + bool null_flush = false; + bool surface_forms = false; + + optind = 1; + while (true) + { + int c = getopt(argc, argv, "enz"); + if(c == -1) + { + break; + } + switch (c) + { + case 'z': + null_flush = true; + break; + + case 'e': + compound_sep = true; + break; + + case 'n': + surface_forms = true; + break; + default: + break; + } + } + processStream(input, output, null_flush, surface_forms, compound_sep); fclose(input); fclose(output); } @@ -67,11 +98,21 @@ class ApertiumTransfer: public Transfer read(transferfile, datafile); } - void transfer_text(char arg, char *input_path, char *output_path) + void transfer_text(char argc, char **argv, char *input_path, char *output_path) { - FILE *input = fopen(input_path, "r"), *output = fopen(output_path, "w"); - switch(arg) + FILE* input = fopen(input_path, "r"); + FILE* output = fopen(output_path, "w"); + optind = 1; + while (true) { + int c = getopt(argc, argv, "nbx:cztT"); + if(c == -1) + { + break; + } + + switch(c) + { case 'b': setPreBilingual(true); setUseBilingual(false); @@ -80,6 +121,30 @@ class ApertiumTransfer: public Transfer case 'n': setUseBilingual(false); break; + + case 'x': + setExtendedDictionary(optarg); + break; + + case 'c': + setCaseSensitiveness(true); + break; + + case 't': + setTrace(true); + break; + + case 'T': + setTrace(true); + setTraceATT(true); + break; + + case 'z': + setNullFlush(true); + break; + default: + break; + } } transfer(input, output); fclose(input); @@ -106,9 +171,31 @@ class ApertiumInterchunk: public Interchunk read(transferfile, datafile); } - void interchunk_text(char arg, char *input_path, char *output_path) + void interchunk_text(int argc, char **argv, char *input_path, char *output_path) { - FILE *input = fopen(input_path, "r"), *output = fopen(output_path, "w"); + FILE* input = fopen(input_path, "r"); + FILE* output = fopen(output_path, "w"); + optind = 1; + while (true) + { + int c = getopt(argc, argv, "zt"); + if(c == -1) + { + break; + } + switch (c) + { + case 'z': + setNullFlush(true); + break; + + case 't': + setTrace(true); + break; + default: + break; + } + } interchunk(input, output); fclose(input); fclose(output); @@ -124,9 +211,31 @@ class ApertiumPostchunk: public Postchunk read(transferfile, datafile); } - void postchunk_text(char arg, char *input_path, char *output_path) + void postchunk_text(int argc, char **argv, char *input_path, char *output_path) { - FILE *input = fopen(input_path, "r"), *output = fopen(output_path, "w"); + FILE* input = fopen(input_path, "r"); + FILE* output = fopen(output_path, "w"); + optind = 1; + while (true) + { + int c = getopt(argc, argv, "zt"); + if(c == -1) + { + break; + } + switch (c) + { + case 'z': + setNullFlush(true); + break; + + case 't': + setTrace(true); + break; + default: + break; + } + } postchunk(input, output); fclose(input); fclose(output);