Commit ff3908b9bed7f7c5641f98f05929dc3b178617bf
1 parent
d60dc771
Exists in
master
and in
5 other branches
Implementando extensão python.
Showing
4 changed files
with
58 additions
and
0 deletions
Show diff stats
src/python/get.cc
@@ -61,3 +61,50 @@ PyObject * terminal_is_ready(PyObject *self, PyObject *args) { | @@ -61,3 +61,50 @@ PyObject * terminal_is_ready(PyObject *self, PyObject *args) { | ||
61 | 61 | ||
62 | } | 62 | } |
63 | 63 | ||
64 | +PyObject * terminal_cmp_string_at(PyObject *self, PyObject *args) { | ||
65 | + | ||
66 | + int row, col, rc; | ||
67 | + const char *text; | ||
68 | + | ||
69 | + if (!PyArg_ParseTuple(args, "iis", &row, &col, &text)) { | ||
70 | + PyErr_SetString(terminalError, strerror(EINVAL)); | ||
71 | + return NULL; | ||
72 | + } | ||
73 | + | ||
74 | + try { | ||
75 | + | ||
76 | + rc = ((pw3270_TerminalObject *) self)->session->cmp_string_at(row,col,text); | ||
77 | + | ||
78 | + } catch(std::exception &e) { | ||
79 | + | ||
80 | + PyErr_SetString(terminalError, e.what()); | ||
81 | + return NULL; | ||
82 | + } | ||
83 | + | ||
84 | + return PyLong_FromLong(rc); | ||
85 | + | ||
86 | +} | ||
87 | + | ||
88 | +PyObject * terminal_get_string_at(PyObject *self, PyObject *args) { | ||
89 | + | ||
90 | + int row, col, sz; | ||
91 | + string rc; | ||
92 | + | ||
93 | + if (!PyArg_ParseTuple(args, "iii", &row, &col, &sz)) { | ||
94 | + PyErr_SetString(terminalError, strerror(EINVAL)); | ||
95 | + return NULL; | ||
96 | + } | ||
97 | + | ||
98 | + try { | ||
99 | + | ||
100 | + rc = ((pw3270_TerminalObject *) self)->session->get_string_at(row,col,sz); | ||
101 | + | ||
102 | + } catch(std::exception &e) { | ||
103 | + | ||
104 | + PyErr_SetString(terminalError, e.what()); | ||
105 | + return NULL; | ||
106 | + } | ||
107 | + | ||
108 | + return PyString_FromString(rc.c_str()); | ||
109 | + | ||
110 | +} |
src/python/private.h
@@ -36,6 +36,8 @@ | @@ -36,6 +36,8 @@ | ||
36 | #include <lib3270/config.h> | 36 | #include <lib3270/config.h> |
37 | #include <pw3270/class.h> | 37 | #include <pw3270/class.h> |
38 | 38 | ||
39 | + using namespace std; | ||
40 | + | ||
39 | typedef struct { | 41 | typedef struct { |
40 | 42 | ||
41 | PyObject_HEAD | 43 | PyObject_HEAD |
@@ -61,6 +63,9 @@ | @@ -61,6 +63,9 @@ | ||
61 | PyObject * terminal_connect(PyObject *self, PyObject *args); | 63 | PyObject * terminal_connect(PyObject *self, PyObject *args); |
62 | PyObject * terminal_disconnect(PyObject *self, PyObject *args); | 64 | PyObject * terminal_disconnect(PyObject *self, PyObject *args); |
63 | 65 | ||
66 | + PyObject * terminal_get_string_at(PyObject *self, PyObject *args); | ||
67 | + PyObject * terminal_cmp_string_at(PyObject *self, PyObject *args); | ||
68 | + | ||
64 | } | 69 | } |
65 | 70 | ||
66 | #endif // PRIVATE_H_INCLUDED | 71 | #endif // PRIVATE_H_INCLUDED |
src/python/py3270.cc
@@ -59,6 +59,9 @@ static PyMethodDef terminal_methods[] = { | @@ -59,6 +59,9 @@ static PyMethodDef terminal_methods[] = { | ||
59 | { "Connect", terminal_connect, METH_VARARGS, "Connect to the host." }, | 59 | { "Connect", terminal_connect, METH_VARARGS, "Connect to the host." }, |
60 | { "Disconnect", terminal_disconnect, METH_NOARGS, "Disconnect from host." }, | 60 | { "Disconnect", terminal_disconnect, METH_NOARGS, "Disconnect from host." }, |
61 | 61 | ||
62 | + { "CmpStringAt", terminal_cmp_string_at, METH_VARARGS, "Compare string with terminal buffer at the position." }, | ||
63 | + { "GetStringAt", terminal_get_string_at, METH_VARARGS, "Get string from terminal buffer." }, | ||
64 | + | ||
62 | {NULL} // Sentinel | 65 | {NULL} // Sentinel |
63 | 66 | ||
64 | }; | 67 | }; |
src/python/sample.py
@@ -16,6 +16,9 @@ term.Connect("tn3270://zos.efglobe.com:telnet",10); | @@ -16,6 +16,9 @@ term.Connect("tn3270://zos.efglobe.com:telnet",10); | ||
16 | print term.IsConnected() | 16 | print term.IsConnected() |
17 | print term.IsReady() | 17 | print term.IsReady() |
18 | 18 | ||
19 | +print term.GetStringAt(14,19,38) | ||
20 | + | ||
21 | + | ||
19 | 22 | ||
20 | 23 | ||
21 | 24 |