File: apertium_lex_tools.i

package info (click to toggle)
apertium-lex-tools 0.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,212 kB
  • sloc: python: 5,788; cpp: 3,086; xml: 395; makefile: 86; awk: 63; sh: 61
file content (93 lines) | stat: -rw-r--r-- 1,822 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
%module apertium_lex_tools

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

%typemap(in) (int argc, char **argv) {
  if (PyTuple_Check($input)) {
    int i = 0;
    $1 = PyTuple_Size($input);
    $2 = (char **) malloc(($1 + 1)*sizeof(char *));
    for (i = 0; i < $1; i++) {
      PyObject *py_obj = PyTuple_GetItem($input, i);
      if (PyUnicode_Check(py_obj)) {
        $2[i] = strdup(PyUnicode_AsUTF8(py_obj));
      }
      else {
        PyErr_SetString(PyExc_TypeError, "tuple must contain strings");
        free($2);
        return NULL;
      }
    }
    $2[i] = 0;
  } else {
    PyErr_SetString(PyExc_TypeError, "not a tuple");
    return NULL;
  }
}

%typemap(freearg) (int argc, char **argv) {
  free((char *) $2);
}

%inline%{
#define SWIG_FILE_WITH_INIT
#include <lrx_processor.h>
#include <lttoolbox/lt_locale.h>
#include <unicode/ustdio.h>

#include <getopt.h>

class LRXProc: public LRXProcessor
{
public:
  /**
   * Imitates functionality of lrx_proc using file path
   */
  LRXProc(char *dictionary_path)
  {
    FILE *dictionary = fopen(dictionary_path, "rb");
    load(dictionary);
    fclose(dictionary);
  }

  void lrx_proc(int argc, char **argv, char *input_path, char *output_path)
  {
	InputFile input;
	input.open(input_path);
	UFILE* output = u_fopen(output_path, "w", NULL, NULL);
    optind = 1;
    while(true)
    {
      int c = getopt(argc, argv, "mztd");
      if(c == -1)
      {
        break;
      }

      switch(c)
      {
        case 'm':
          break;

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

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

        case 'd':
          setDebugMode(true);
          break;
        default:
          break;
      }
    }
    process(input, output);
    u_fclose(output);
  }
};

%}