From 4a218c52def333f2fe05a65be10dda84b8ba9e60 Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Thu, 1 Jun 2023 22:58:02 -0300 Subject: [PATCH 1/3] Better documentation. --- setup.py | 2 -- src/module/tools.cc | 1 + src/module/types.c | 62 ++++++++++++++++++++++----------------------- src/session/init.cc | 39 ---------------------------- src/session/misc.cc | 38 +++++++++++++-------------- src/session/type.c | 37 --------------------------- 6 files changed, 50 insertions(+), 129 deletions(-) delete mode 100644 src/session/init.cc delete mode 100644 src/session/type.c diff --git a/setup.py b/setup.py index 0b630a6..c5be1bf 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,6 @@ src_files = [ 'src/module/init.c', 'src/module/types.c', - 'src/session/type.c', 'src/action/methods.cc', 'src/action/new.cc', 'src/action/tools.cc', @@ -20,7 +19,6 @@ 'src/session/actions.cc', 'src/session/attributes.cc', 'src/session/get.cc', - 'src/session/init.cc', 'src/session/misc.cc', 'src/session/network.cc', 'src/session/set.cc', diff --git a/src/module/tools.cc b/src/module/tools.cc index 0ebe8cf..38e5820 100644 --- a/src/module/tools.cc +++ b/src/module/tools.cc @@ -37,6 +37,7 @@ const char * py3270_check_requires() { #ifdef _WIN32 + if(TN3270::getInstallLocation().empty()) { return "Can't determine location of pw3270 runtime, is it installed?"; } diff --git a/src/module/types.c b/src/module/types.c index 67ba730..3bdfce3 100644 --- a/src/module/types.c +++ b/src/module/types.c @@ -1,31 +1,29 @@ +/* SPDX-License-Identifier: LGPL-3.0-or-later */ + /* - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a - * aplicativos mainframe. Registro no INPI sob o nome G3270. - * - * Copyright (C) <2008> - * - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela - * Free Software Foundation. + * Copyright (C) <2008> Banco do Brasil S.A. * - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para - * obter mais detalhes. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin - * St, Fifth Floor, Boston, MA 02110-1301 USA + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * Este programa está nomeado como py3270.cc e possui - linhas de código. - * - * Contatos: + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +/* + * Authors: * * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) * - * Referências: + * Reference: * * * @@ -85,14 +83,16 @@ .ml_name = "find", .ml_meth = (PyCFunction) py3270_session_find, .ml_flags = METH_VARARGS, - .ml_doc = "" + .ml_doc = "Search for string on terminal\n\n" + "find('string'): Return the address of 'string' on terminal" }, { .ml_name = "count", .ml_meth = (PyCFunction) py3270_session_count, .ml_flags = METH_VARARGS, - .ml_doc = "" + .ml_doc = "Get the number of occurrences of a string in the terminal\n\n" + "count('string'): Return the numger of ocurrences of 'string' on terminal" }, { @@ -108,7 +108,7 @@ .ml_name = "getcursor", .ml_meth = (PyCFunction) py3270_session_get_cursor_position, .ml_flags = METH_NOARGS, - .ml_doc = "Get cursor position" + .ml_doc = "Get cursor position (row and column)" }, { @@ -176,17 +176,17 @@ static PyMethodDef py3270_action_methods[] = { { - "activate", - (PyCFunction) py3270_action_activate, - METH_VARARGS, - "Activate action" + .ml_name = "activate", + .ml_meth = (PyCFunction) py3270_action_activate, + .ml_flags = METH_VARARGS, + .ml_doc = "Activate action" }, { - "try_activate", - (PyCFunction) py3270_action_try_activate, - METH_VARARGS, - "Activate action only if available, returns 'true' if activated and 'false' if the action cant be activated" + .ml_name = "try_activate", + .ml_meth = (PyCFunction) py3270_action_try_activate, + .ml_flags = METH_VARARGS, + .ml_doc = "Activate action only if available, returns 'true' if activated and 'false' if the action cant be activated" }, { diff --git a/src/session/init.cc b/src/session/init.cc deleted file mode 100644 index af9ddc3..0000000 --- a/src/session/init.cc +++ /dev/null @@ -1,39 +0,0 @@ -/* - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a - * aplicativos mainframe. Registro no INPI sob o nome G3270. - * - * Copyright (C) <2008> - * - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela - * Free Software Foundation. - * - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para - * obter mais detalhes. - * - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin - * St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Este programa está nomeado como - e possui - linhas de código. - * - * Contatos: - * - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) - * - * Referênces: - * - * - * - * - */ - - #include - #include - -/*---[ Implement ]----------------------------------------------------------------------------------*/ - diff --git a/src/session/misc.cc b/src/session/misc.cc index 9fa8231..120e100 100644 --- a/src/session/misc.cc +++ b/src/session/misc.cc @@ -1,31 +1,29 @@ +/* SPDX-License-Identifier: LGPL-3.0-or-later */ + /* - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a - * aplicativos mainframe. Registro no INPI sob o nome G3270. - * - * Copyright (C) <2008> - * - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela - * Free Software Foundation. - * - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para - * obter mais detalhes. + * Copyright (C) <2008> Banco do Brasil S.A. * - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin - * St, Fifth Floor, Boston, MA 02110-1301 USA + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * Este programa está nomeado como set.cc e possui - linhas de código. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * Contatos + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +/* + * Authors: * * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) * - * Referências: + * Reference: * * * diff --git a/src/session/type.c b/src/session/type.c deleted file mode 100644 index 941a460..0000000 --- a/src/session/type.c +++ /dev/null @@ -1,37 +0,0 @@ -/* - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a - * aplicativos mainframe. Registro no INPI sob o nome G3270. - * - * Copyright (C) <2008> - * - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela - * Free Software Foundation. - * - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para - * obter mais detalhes. - * - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin - * St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Este programa está nomeado como py3270.cc e possui - linhas de código. - * - * Contatos: - * - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) - * - * Referências: - * - * - * - * - */ - - #include - -/*---[ Globals ]------------------------------------------------------------------------------------*/ From d31de92ad6a96ffa47ab196640e40fc360fb374a Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Fri, 2 Jun 2023 04:31:38 -0300 Subject: [PATCH 2/3] Cleaning unused code, adding action factory by name. --- py3270.cbp | 4 -- setup.py | 3 -- src/action/init.cc | 48 ----------------------- src/action/methods.cc | 49 ----------------------- src/action/new.cc | 86 ----------------------------------------- src/action/tools.cc | 63 ------------------------------ src/include/pysession.h | 2 +- src/module/types.c | 8 ++++ src/objects/session.cc | 35 ++++++++++++++++- 9 files changed, 43 insertions(+), 255 deletions(-) delete mode 100644 src/action/init.cc delete mode 100644 src/action/methods.cc delete mode 100644 src/action/new.cc delete mode 100644 src/action/tools.cc diff --git a/py3270.cbp b/py3270.cbp index 84cc260..8163161 100644 --- a/py3270.cbp +++ b/py3270.cbp @@ -42,10 +42,6 @@ - - - - diff --git a/setup.py b/setup.py index c5be1bf..66ed191 100644 --- a/setup.py +++ b/setup.py @@ -12,9 +12,6 @@ src_files = [ 'src/module/init.c', 'src/module/types.c', - 'src/action/methods.cc', - 'src/action/new.cc', - 'src/action/tools.cc', 'src/module/properties.cc', 'src/session/actions.cc', 'src/session/attributes.cc', diff --git a/src/action/init.cc b/src/action/init.cc deleted file mode 100644 index cfb22f8..0000000 --- a/src/action/init.cc +++ /dev/null @@ -1,48 +0,0 @@ -/* - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a - * aplicativos mainframe. Registro no INPI sob o nome G3270. - * - * Copyright (C) <2008> - * - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela - * Free Software Foundation. - * - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para - * obter mais detalhes. - * - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin - * St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Este programa está nomeado como py3270.cc e possui - linhas de código. - * - * Contatos: - * - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) - * - * Implementa métodos básicos inicio/final do objeto python - * - * Referências: - * - * - * - * - */ - -#ifdef _WIN32 - #include - #include -#endif // _WIN32 - - #include - #include - #include - -/*---[ Implement ]----------------------------------------------------------------------------------*/ - - diff --git a/src/action/methods.cc b/src/action/methods.cc deleted file mode 100644 index 3dcc385..0000000 --- a/src/action/methods.cc +++ /dev/null @@ -1,49 +0,0 @@ -/* - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a - * aplicativos mainframe. Registro no INPI sob o nome G3270. - * - * Copyright (C) <2008> - * - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela - * Free Software Foundation. - * - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para - * obter mais detalhes. - * - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin - * St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Este programa está nomeado como py3270.cc e possui - linhas de código. - * - * Contatos: - * - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) - * - * Implementa métodos básicos inicio/final do objeto python - * - * Referências: - * - * - * - * - */ - -#ifdef _WIN32 - #include - #include -#endif // _WIN32 - - #include - #include - #include - #include - #include - -/*---[ Implement ]----------------------------------------------------------------------------------*/ - diff --git a/src/action/new.cc b/src/action/new.cc deleted file mode 100644 index 9d033f4..0000000 --- a/src/action/new.cc +++ /dev/null @@ -1,86 +0,0 @@ -/* - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a - * aplicativos mainframe. Registro no INPI sob o nome G3270. - * - * Copyright (C) <2008> - * - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela - * Free Software Foundation. - * - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para - * obter mais detalhes. - * - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin - * St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Este programa está nomeado como py3270.cc e possui - linhas de código. - * - * Contatos: - * - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) - * - * Implementa métodos básicos inicio/final do objeto python - * - * Referências: - * - * - * - * - */ - -/* - #include - #include - #include - -DLL_PRIVATE PyObject * py3270_action_new_from_session(PyObject *session, void *action) { - - pyAction * pObj = (pyAction *) _PyObject_New(&py3270_action_type); - pObj->action = nullptr; - pObj->session = (pySession *) session; - Py_INCREF(pObj->session); - - try { - - pObj->action = pObj->session->host->getAction((const LIB3270_ACTION *) action); - - } catch(const std::exception &e) { - - Py_DECREF((PyObject *) pObj); - PyErr_SetString(PyExc_RuntimeError, e.what()); - return NULL; - - } catch(...) { - - Py_DECREF((PyObject *) pObj); - PyErr_SetString(PyExc_RuntimeError, "Unexpected error creating action object"); - return NULL; - - } - - return (PyObject *) pObj; - -} - -void py3270_action_dealloc(PyObject * self) { - - pyAction * pObj = (pyAction *) self; - - debug("%s: %p",__FUNCTION__,self); - - Py_DECREF(pObj->session); - - if(pObj->action) - delete pObj->action; - - pObj->action = nullptr; - -} -*/ - diff --git a/src/action/tools.cc b/src/action/tools.cc deleted file mode 100644 index 4fa3514..0000000 --- a/src/action/tools.cc +++ /dev/null @@ -1,63 +0,0 @@ -/* - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a - * aplicativos mainframe. Registro no INPI sob o nome G3270. - * - * Copyright (C) <2008> - * - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela - * Free Software Foundation. - * - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para - * obter mais detalhes. - * - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin - * St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Este programa está nomeado como misc.cc e possui - linhas de código. - * - * Contatos: - * - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) - * - * Implementa métodos básicos inicio/final do objeto python - * - * Referências: - * - * - * - * - */ - - #include - -/*---[ Implement ]----------------------------------------------------------------------------------*/ - -/* -PyObject * py3270_action_call(PyObject *self, std::function worker) noexcept { - - try { - - return worker(* (((pyAction * ) self)->action)); - - } catch(const exception &e) { - - PyErr_SetString(PyExc_RuntimeError, e.what()); - - } catch( ... ) { - - PyErr_SetString(PyExc_RuntimeError, "Unexpected error in action method"); - - } - - return NULL; - -} -*/ - - diff --git a/src/include/pysession.h b/src/include/pysession.h index 3d0e8ac..fc42959 100644 --- a/src/include/pysession.h +++ b/src/include/pysession.h @@ -42,7 +42,7 @@ DLL_PRIVATE int py3270_session_set_attribute(PyObject *self, PyObject *value, const LIB3270_PROPERTY *property); DLL_PRIVATE PyObject * py3270_session_get_action(PyObject *self, const LIB3270_ACTION *action); -// DLL_PRIVATE int py3270_session_set_action(PyObject *self, PyObject *value, const LIB3270_ACTION *action); + DLL_PRIVATE PyObject * py3270_session_action_factory(PyObject *self, PyObject *args); DLL_PRIVATE PyObject * py3270_session_get_timeout(PyObject *self, void *dunno); DLL_PRIVATE int py3270_session_set_timeout(PyObject *self, PyObject *value, void *dunno); diff --git a/src/module/types.c b/src/module/types.c index 3bdfce3..1329d93 100644 --- a/src/module/types.c +++ b/src/module/types.c @@ -45,6 +45,14 @@ "connect(url,timeout): Connect to host on url wait 'timeout' seconds for session startup\n" }, + { + .ml_name = "action", + .ml_meth = (PyCFunction) py3270_session_action_factory, + .ml_flags = METH_VARARGS, + .ml_doc = "Get action by name\n\n" + "action('enter'): Return the 'enter' action\n" + }, + { .ml_name = "wait", .ml_meth = (PyCFunction) py3270_session_wait, diff --git a/src/objects/session.cc b/src/objects/session.cc index a50eade..9ba34df 100644 --- a/src/objects/session.cc +++ b/src/objects/session.cc @@ -98,7 +98,6 @@ py3270_session_type.tp_getset[index].doc = (char *) (action->summary ? action->summary : ""); py3270_session_type.tp_getset[index].closure = (void *) action; py3270_session_type.tp_getset[index].get = (getter) py3270_session_get_action; - // py3270_session_type.tp_getset[index].set = (setter) py3270_session_set_action; index++; } @@ -246,6 +245,40 @@ } + PyObject * py3270_session_action_factory(PyObject *self, PyObject *args) { + + const char *name; + + if(!PyArg_ParseTuple(args, "s", &name)) + return (PyObject *) NULL; + + return py3270_call(self,[name](TN3270::Session &session){ + + PyObject *object = NULL; + + TN3270::for_each([&object,name,&session](const LIB3270_ACTION &action){ + +#ifdef _WIN32 + if(!strcmp(action.name,name)) { + object = py3270_action_new(session.ActionFactory(&action)); + return true; + } +#else + if(!strcasecmp(action.name,name)) { + object = py3270_action_new(session.ActionFactory(&action)); + return true; + } +#endif // _WIN32 + + return false; + }); + + return object; + + }); + + } + PyObject * py3270_session_get_action(PyObject *self, const LIB3270_ACTION *descriptor) { return py3270_call(self,[descriptor](TN3270::Session &session){ From 7acf62082c32fabeeb03076ac8fa55b208f1e99b Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Tue, 9 Jan 2024 14:04:13 -0300 Subject: [PATCH 3/3] Update README.md Updating URL to the prebuilt msvc library. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 49f0368..ed40194 100644 --- a/README.md +++ b/README.md @@ -129,7 +129,7 @@ input("Press enter to exit") 3. Download and unpack libipc3270 pre-compiled image ```shell - wget https://github.com/PerryWerneck/libipc3270/releases/download/5.5/msvc-libipc3270.zip + wget https://github.com/PerryWerneck/libipc3270/releases/download/5.5/msvc-libipc3270-x86_64.zip 7z x msvc-libipc3270.zip -y -oipc3270 ```