From 9e14881bc2555401514a0b787ea26da2edbdf630 Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Wed, 21 Aug 2019 10:23:59 -0300 Subject: [PATCH] Updating documentation, adjusting return codes. --- Makefile.in | 3 +++ src/core/keyboard/kybd.c | 3 +++ src/core/paste.c | 24 +++++++++++++++--------- src/core/screen.c | 76 ++++++++++------------------------------------------------------------------ src/include/lib3270.h | 31 ++++++++++++++++++++++++++----- src/include/statusc.h | 40 ++++++++++++++++++++++++++-------------- src/selection/get.c | 1 - 7 files changed, 83 insertions(+), 95 deletions(-) diff --git a/Makefile.in b/Makefile.in index c3ecd96..a32e495 100644 --- a/Makefile.in +++ b/Makefile.in @@ -64,6 +64,7 @@ GENMARSHAL=@GENMARSHAL@ CONVERT=@CONVERT@ OPTIPNG=@OPTIPNG@ ZIP=@ZIP@ +DOXYGEN=@DOXYGEN@ #---[ Paths ]---------------------------------------------------------------------------- @@ -351,6 +352,8 @@ $(POTDIR)/lib3270.pot: \ locale: \ $(POTDIR)/lib3270.pot +doc: + @$(DOXYGEN) ./doxygen/doxyfile #---[ Debug Targets ]-------------------------------------------------------------------- diff --git a/src/core/keyboard/kybd.c b/src/core/keyboard/kybd.c index 44fd840..cf38639 100644 --- a/src/core/keyboard/kybd.c +++ b/src/core/keyboard/kybd.c @@ -940,6 +940,9 @@ LIB3270_EXPORT int lib3270_input_string(H3270 *hSession, const unsigned char *st if(length < 0) length = strlen((char *) str); + if(hSession->kybdlock) + return (errno = EPERM); + int pos; for(pos = 0; pos < length && str[pos] && !rc; pos++) rc = key_ACharacter(hSession,(str[pos] & 0xff), KT_STD, IA_KEY, NULL); diff --git a/src/core/paste.c b/src/core/paste.c index 4d76684..d44e6cf 100644 --- a/src/core/paste.c +++ b/src/core/paste.c @@ -248,15 +248,14 @@ LIB3270_EXPORT int lib3270_set_string_at(H3270 *hSession, unsigned int row, unsi row--; col--; - if(row <= hSession->rows && col <= hSession->cols) - { - hSession->cbk.suspend(hSession); + if(row > hSession->rows || col > hSession->cols) + return - (errno = EOVERFLOW); - hSession->cursor_addr = (row * hSession->cols) + col; - rc += set_string(hSession, str, length); + hSession->cbk.suspend(hSession); - hSession->cbk.resume(hSession); - } + hSession->cursor_addr = (row * hSession->cols) + col; + rc = set_string(hSession, str, length); + hSession->cbk.resume(hSession); trace("%s rc=%d",__FUNCTION__,rc); @@ -279,8 +278,12 @@ LIB3270_EXPORT int lib3270_set_string_at_address(H3270 *hSession, int baddr, con if(hSession->kybdlock) return - (errno = EPERM); - if(baddr >= 0 && lib3270_set_cursor_address(hSession,baddr) < 0) - return -1; + if(baddr >= 0) + { + rc = lib3270_set_cursor_address(hSession,baddr); + if(rc < 0) + return rc; + } if(hSession->selected && !lib3270_get_toggle(hSession,LIB3270_TOGGLE_KEEP_SELECTED)) lib3270_unselect(hSession); @@ -306,6 +309,9 @@ LIB3270_EXPORT int lib3270_set_string(H3270 *hSession, const unsigned char *str, if(hSession->kybdlock) return - (errno = EPERM); + if(hSession->selected && !lib3270_get_toggle(hSession,LIB3270_TOGGLE_KEEP_SELECTED)) + lib3270_unselect(hSession); + hSession->cbk.suspend(hSession); rc = set_string(hSession, str, length); hSession->cbk.resume(hSession); diff --git a/src/core/screen.c b/src/core/screen.c index 59561d0..f09303e 100644 --- a/src/core/screen.c +++ b/src/core/screen.c @@ -431,27 +431,12 @@ LIB3270_EXPORT int lib3270_translate_to_address(H3270 *hSession, unsigned int ro col--; if(row > hSession->rows || col > hSession->cols) - { - // Invalid coordinates - errno = EINVAL; - return -1; - } + return - (errno = EOVERFLOW); return (row * hSession->cols) + col; } -/** - * @brief Move cursor to a new position. - * - * @see lib3270_set_cursor_position - * - * @param hSession TN3270 session. - * @param baddr New cursor position. - * - * @return Old cursor address or -1 in case of error (sets errno). - * - */ LIB3270_EXPORT int lib3270_set_cursor_address(H3270 *hSession, unsigned int baddr) { FAIL_IF_NOT_ONLINE(hSession); @@ -459,10 +444,7 @@ LIB3270_EXPORT int lib3270_set_cursor_address(H3270 *hSession, unsigned int badd trace("%s(%d)",__FUNCTION__,baddr); if(baddr > (hSession->rows * hSession->cols)) - { - errno = EINVAL; - return -1; - } + return - (errno = EOVERFLOW); if(hSession->selected && !lib3270_get_toggle(hSession,LIB3270_TOGGLE_KEEP_SELECTED)) lib3270_unselect(hSession); @@ -470,46 +452,13 @@ LIB3270_EXPORT int lib3270_set_cursor_address(H3270 *hSession, unsigned int badd return cursor_move(hSession,baddr); } -/** - * @brief Move cursor to a new position. - * - * @see lib3270_set_cursor_position - * - * @param hSession TN3270 session. - * @param row New cursor row. - * @parma col New cursor column. - * - * @return Old cursor address or -1 in case of error (sets errno). - * - */ LIB3270_EXPORT int lib3270_set_cursor_position(H3270 *hSession, unsigned int row, unsigned int col) { - return lib3270_set_cursor_address(hSession,lib3270_translate_to_address(hSession, row, col)); - - /* - int baddr = -1; - - CHECK_SESSION_HANDLE(h); - - if(h->selected && !lib3270_get_toggle(h,LIB3270_TOGGLE_KEEP_SELECTED)) - lib3270_unselect(h); - - row--; - col--; - - if(row >= 0 && col >= 0 && row <= h->rows && col <= h->cols) - { - baddr = (row * h->cols) + col; + int baddr = lib3270_translate_to_address(hSession, row, col); + if(baddr < 0) + return -errno; - if(baddr != h->cursor_addr) - { - h->cursor_addr = baddr; - h->cbk.update_cursor(h,(unsigned short) row,(unsigned short) col,h->text[baddr].chr,h->text[baddr].attr); - } - } - - return baddr; - */ + return lib3270_set_cursor_address(hSession,baddr); } /** @@ -527,10 +476,7 @@ int cursor_move(H3270 *hSession, int baddr) { int ret = hSession->cursor_addr; - if(ret == baddr) - return ret; - - if(baddr >= 0) + if(ret != baddr && baddr >= 0) { hSession->cursor_addr = baddr; hSession->cbk.update_cursor( @@ -545,15 +491,13 @@ int cursor_move(H3270 *hSession, int baddr) return ret; } -/* Status line stuff. */ - +/** + * @brief Status line stuff. + */ void set_status(H3270 *session, LIB3270_FLAG id, Boolean on) { - CHECK_SESSION_HANDLE(session); - session->oia.flag[id] = (on != 0); session->cbk.update_oia(session,id,session->oia.flag[id]); - } void status_ctlr_done(H3270 *session) diff --git a/src/include/lib3270.h b/src/include/lib3270.h index 67c6c98..c2d7dfa 100644 --- a/src/include/lib3270.h +++ b/src/include/lib3270.h @@ -685,7 +685,9 @@ * @param row Row inside the screen. * @param col Col inside the screen. * - * @return Current address or -1 if invalid (sets errno). + * @return Current address or negative if invalid (sets errno). + * + * @retval -EOVERFLOW The coordinates are out of the screen. * */ LIB3270_EXPORT int lib3270_translate_to_address(H3270 *hSession, unsigned int row, unsigned int col); @@ -710,13 +712,19 @@ /** * @brief Set string at defined row/column. * + * Set the string in the defined row/column; returns number of processed caracter if succeeds or negative value if not. + * * @param hSession Session handle. * @param row Row for the first character. * @param col Col for the first character. * @param str String to set. * @param length Length of the string (-1 for auto-detect). * - * @return Negative if error or number of processed characters. + * @return Negative if error or number (sets errno) of processed characters. + * + * @retval -EPERM The keyboard is locked. + * @retval -EOVERFLOW The row or col is bigger than the screen size. + * @retval -ENOTCONN Disconnected from host. * */ LIB3270_EXPORT int lib3270_set_string_at(H3270 *hSession, unsigned int row, unsigned int col, const unsigned char *str, int length); @@ -731,6 +739,10 @@ * * @return Negative if error or number of processed characters. * + * @retval -EPERM The keyboard is locked. + * @retval -EOVERFLOW The address is beyond the screen length. + * @retval -ENOTCONN Disconnected from host. + * */ LIB3270_EXPORT int lib3270_set_string_at_address(H3270 *hSession, int baddr, const unsigned char *str, int length); @@ -741,7 +753,10 @@ * @param str Text to insert. * @param length Length of the string (-1 for auto-detect). * - * @return 0 if success, non zero if failed. + * @return 0 if success, non zero if failed (sets errno). + * + * @retval EPERM The keyboard is locked. + * @retval ENOTCONN Disconnected from host. * */ LIB3270_EXPORT int lib3270_input_string(H3270 *hSession, const unsigned char *str, int length); @@ -754,7 +769,11 @@ * @param hSession TN3270 session. * @param baddr New cursor position. * - * @return Old cursor address or -1 in case of error (sets errno). + * @return Old cursor address or negative in case of error (sets errno). + * + * @retval -EOVERFLOW The address is beyond the screen length. + * @retval -ENOTCONN Disconnected from host. + * */ LIB3270_EXPORT int lib3270_set_cursor_address(H3270 *hSession, unsigned int baddr); @@ -765,8 +784,10 @@ * @param row New cursor row. * @param col New cursor col. * - * @return last cursor address or -1 if invalid (sets errno). + * @return Old cursor address or negative in case of error (sets errno). * + * @retval -EOVERFLOW The address is beyond the screen length. + * @retval -ENOTCONN Disconnected from host. */ LIB3270_EXPORT int lib3270_set_cursor_position(H3270 *h, unsigned int row, unsigned int col); diff --git a/src/include/statusc.h b/src/include/statusc.h index 71c61ca..4de299a 100644 --- a/src/include/statusc.h +++ b/src/include/statusc.h @@ -1,20 +1,32 @@ /* - * Copyright 1999, 2000, 2002 by Paul Mattes. - * Permission to use, copy, modify, and distribute this software and its - * documentation for any purpose and without fee is hereby granted, - * provided that the above copyright notice appear in all copies and that - * both that copyright notice and this permission notice appear in - * supporting documentation. - * - * c3270 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 file LICENSE for more details. + * "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. 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 host.c e possui 1078 linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * */ -/* c3270 verson of statusc.h */ - -// #include "api.h" - LIB3270_INTERNAL void status_compose(int on, unsigned char c, enum keytype keytype); LIB3270_INTERNAL void status_ctlr_done(H3270 *session); diff --git a/src/selection/get.c b/src/selection/get.c index 4481b3c..4084987 100644 --- a/src/selection/get.c +++ b/src/selection/get.c @@ -182,7 +182,6 @@ LIB3270_EXPORT lib3270_selection * lib3270_get_selection(H3270 *hSession, int cu if(baddr < 0) { - errno = EINVAL; lib3270_free(selection); return NULL; } -- libgit2 0.21.2