From 7fe37ca628a3709842d402bbd46cd28d62d09720 Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Wed, 14 Aug 2019 11:30:29 -0300 Subject: [PATCH] Debugging API. --- src/core/ctlr.c | 11 +++++++++-- src/core/iocalls.c | 2 +- src/core/paste.c | 40 ++++++++++++++++++++++++++++------------ src/include/lib3270.h | 4 ++-- 4 files changed, 40 insertions(+), 17 deletions(-) diff --git a/src/core/ctlr.c b/src/core/ctlr.c index ac4f2e5..a84b093 100644 --- a/src/core/ctlr.c +++ b/src/core/ctlr.c @@ -429,14 +429,21 @@ static void ctlr_connect(H3270 *hSession, int GNUC_UNUSED(ignored), void GNUC_UN hSession->crm_nattr = 0; } +/** + * @brief Get field address. + * + * @return Negative on error(sets errno) or field address. + * + */ LIB3270_EXPORT int lib3270_get_field_start(H3270 *hSession, int baddr) { int sbaddr; - CHECK_SESSION_HANDLE(hSession); + if(check_online_session(hSession)) + return - errno; if (!hSession->formatted) - return errno = ENOTCONN; + return - (errno = ENOTCONN); if(baddr < 0) baddr = hSession->cursor_addr; diff --git a/src/core/iocalls.c b/src/core/iocalls.c index 244da9a..2d1fb4b 100644 --- a/src/core/iocalls.c +++ b/src/core/iocalls.c @@ -472,7 +472,7 @@ LIB3270_EXPORT int lib3270_wait(H3270 *hSession, int seconds) return 0; } -LIB3270_EXPORT int wait_for_update(H3270 *hSession, int seconds) +LIB3270_EXPORT int lib3270_wait_for_update(H3270 *hSession, int seconds) { return errno = ENOTSUP; } diff --git a/src/core/paste.c b/src/core/paste.c index 483df4f..710c82b 100644 --- a/src/core/paste.c +++ b/src/core/paste.c @@ -93,9 +93,10 @@ /*---[ Implement ]----------------------------------------------------------------------------------------------*/ -/* - * Move the cursor back within the legal paste area. - * Returns a Boolean indicating success. +/** + * @brief Move the cursor back within the legal paste area. + * + * @return A Boolean indicating success. */ static int remargin(H3270 *hSession, int lmargin) { @@ -234,18 +235,22 @@ static int set_string(H3270 *hSession, const unsigned char *str, int length) * @param col Col for the first character. * @param str String to set. * - * @return -1 if error (sets errno) or number of processed characters. + * @return negative if error (sets errno) or number of processed characters. * */ LIB3270_EXPORT int lib3270_set_string_at(H3270 *hSession, unsigned int row, unsigned int col, const unsigned char *str) { int rc = 0; - FAIL_IF_NOT_ONLINE(hSession); + if(!(str && *str)) + return 0; + + if(check_online_session(hSession)) + return - errno; // Is Keyboard locked ? if(hSession->kybdlock) - return errno = EPERM; + return - (errno = EPERM); if(hSession->selected && !lib3270_get_toggle(hSession,LIB3270_TOGGLE_KEEP_SELECTED)) lib3270_unselect(hSession); @@ -272,12 +277,19 @@ LIB3270_EXPORT int lib3270_set_string_at_address(H3270 *hSession, int baddr, con { int rc = -1; - FAIL_IF_NOT_ONLINE(hSession); + if(!(str && *str)) + return 0; + + if(check_online_session(hSession)) + return - errno; + + if(length < 0) + length = (int) strlen((const char *) str); if(hSession->kybdlock) - return errno = EPERM; + return - (errno = EPERM); - if(lib3270_set_cursor_address(hSession,baddr) < 0) + if(baddr >= 0 && lib3270_set_cursor_address(hSession,baddr) < 0) return -1; if(hSession->selected && !lib3270_get_toggle(hSession,LIB3270_TOGGLE_KEEP_SELECTED)) @@ -296,17 +308,21 @@ LIB3270_EXPORT int lib3270_set_string_at_address(H3270 *hSession, int baddr, con * @param hSession Session handle. * @param str String to set * - * @return -1 if error (sets errno) or number of processed characters. + * @return negative if error (sets errno) or number of processed characters. * */ LIB3270_EXPORT int lib3270_set_string(H3270 *hSession, const unsigned char *str) { int rc; - FAIL_IF_NOT_ONLINE(hSession); + if(!(str && *str)) + return 0; + + if(check_online_session(hSession)) + return - errno; if(hSession->kybdlock) - return errno = EPERM; + return - (errno = EPERM); hSession->cbk.suspend(hSession); rc = set_string(hSession, str, -1); diff --git a/src/include/lib3270.h b/src/include/lib3270.h index 5a478c7..80ead89 100644 --- a/src/include/lib3270.h +++ b/src/include/lib3270.h @@ -723,7 +723,7 @@ * @brief Set string at defined adress. * * @param hSession Session handle. - * @param baddr Adress for the first character. + * @param baddr Adress for the first character (-1 for cursor position). * @param str String to set. * @param length Length of the string (-1 for auto-detect). * @@ -1017,7 +1017,7 @@ * @param seconds Number of seconds to wait. * */ - LIB3270_EXPORT int wait_for_update(H3270 *hSession, int seconds); + LIB3270_EXPORT int lib3270_wait_for_update(H3270 *hSession, int seconds); /** * Wait "N" seconds for "ready" state. -- libgit2 0.21.2