Skip to content

Commit

Permalink
added: getopts and more flags
Browse files Browse the repository at this point in the history
  • Loading branch information
singh-lokendra committed Aug 18, 2019
1 parent 088ce8e commit 37cded7
Showing 1 changed file with 62 additions and 20 deletions.
82 changes: 62 additions & 20 deletions python/lex_tools.i
@@ -1,9 +1,40 @@
%module lextools

%{
%include <lrx_processor.h>
%include <lttoolbox/lt_locale.h>

%typemap(in) char ** {
if (PyList_Check($input)) {
int size = PyList_Size($input);
int i = 0;
$1 = (char **) malloc((size+1)*sizeof(char *));
for (i = 0; i < size; i++) {
PyObject *py_obj = PyList_GetItem($input, i);
if (PyUnicode_Check(py_obj)) {
$1[i] = strdup(PyUnicode_AsUTF8(py_obj));
}
else {
PyErr_SetString(PyExc_TypeError, "list must contain strings");
free($1);
return NULL;
}
}
$1[i] = 0;
} else {
PyErr_SetString(PyExc_TypeError, "not a list");
return NULL;
}
}

%typemap(freearg) char ** {
free((char *) $1);
}

%inline%{
#define SWIG_FILE_WITH_INIT
#include <lrx_processor.h>

#include <getopt.h>

class LRXProc: public LRXProcessor
{
Expand All @@ -18,17 +49,40 @@ public:
fclose(dictionary);
}

void lrx_proc(char arg, char *input_path, char *output_path)
void lrx_proc(char argc, char **argv, char *input_path, char *output_path)
{
bool useMaxEnt = false;
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)
{
case 'm':
useMaxEnt = true;
int c = getopt(argc, argv, "mztd");
if(c == -1)
{
break;
default:
useMaxEnt = false;
}

switch(c)
{
case 'm':
useMaxEnt = true;
break;

case 'z':
setNullFlush(true);
break;

case 't':
setTraceMode(true);
break;

case 'd':
setDebugMode(true);
break;
default:
break;
}
}
init();
if(useMaxEnt)
Expand All @@ -45,15 +99,3 @@ public:
};

%}


%include <lrx_processor.h>
%include <lttoolbox/lt_locale.h>


class LRXProc: public LRXProcessor
{
public:
LRXProc(char *dictionary_path);
void lrx_proc(char arg, char *input_path, char *output_path);
};

0 comments on commit 37cded7

Please sign in to comment.