From 5d70e80ba1ee6504e8de77ac6e3233420905b384 Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Wed, 25 Sep 2019 11:37:06 -0300 Subject: [PATCH] Adding method to set field and jump to next. --- src/core/keyboard/kybd.c | 6 +++--- src/core/paste.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/include/lib3270.h | 33 ++++++++++++++++++++++++++++----- 3 files changed, 84 insertions(+), 8 deletions(-) diff --git a/src/core/keyboard/kybd.c b/src/core/keyboard/kybd.c index a347773..2ea5768 100644 --- a/src/core/keyboard/kybd.c +++ b/src/core/keyboard/kybd.c @@ -1631,17 +1631,17 @@ int lib3270_get_field_end(H3270 *hSession, int baddr) #if defined(X3270_ANSI) /*[*/ if (IN_ANSI) { - return errno = EINVAL; + return -(errno = ENOTSUP); } #endif /*]*/ if (!hSession->formatted) - return errno = EINVAL; + return -(errno = ENOTSUP); faddr = lib3270_field_addr(hSession,baddr); fa = hSession->ea_buf[faddr].fa; if (faddr == baddr || FA_IS_PROTECTED(fa)) - return errno = EPERM; + return -(errno = EPERM); baddr = faddr; while (True) diff --git a/src/core/paste.c b/src/core/paste.c index b78520a..2accbc3 100644 --- a/src/core/paste.c +++ b/src/core/paste.c @@ -295,6 +295,59 @@ LIB3270_EXPORT int lib3270_set_string_at_address(H3270 *hSession, int baddr, con return rc; } +LIB3270_EXPORT int lib3270_set_field(H3270 *hSession, const char *text, int length) +{ + int addr; + int numchars = 0; + + if(!text) + return - (errno = EINVAL); + + if(check_online_session(hSession)) + return - errno; + + if(hSession->kybdlock) + return - (errno = EPERM); + + if (!hSession->formatted) + return - (errno = ENOTSUP); + + if(length < 0) + length = (int) strlen((const char *) text); + + addr = lib3270_field_addr(hSession,hSession->cursor_addr); + if(addr < 0) + return addr; + + if(hSession->selected && !lib3270_get_toggle(hSession,LIB3270_TOGGLE_KEEP_SELECTED)) + lib3270_unselect(hSession); + + hSession->cbk.suspend(hSession); + hSession->cursor_addr = addr; + numchars = set_string(hSession, (const unsigned char *) text, length); + hSession->cbk.resume(hSession); + + if(numchars < 0) + return numchars; + + // Find the end of the field. + addr = lib3270_get_field_end(hSession,addr); + if(addr < 0) + return addr; + + addr = lib3270_get_next_unprotected(hSession, addr); + + if(addr > 0) { + addr = lib3270_set_cursor_address(hSession,addr); + if(addr < 0) + return addr; + } + + return hSession->cursor_addr; + +} + + LIB3270_EXPORT int lib3270_set_string(H3270 *hSession, const unsigned char *str, int length) { int rc; diff --git a/src/include/lib3270.h b/src/include/lib3270.h index 6cb5c9d..b081b1d 100644 --- a/src/include/lib3270.h +++ b/src/include/lib3270.h @@ -660,6 +660,26 @@ LIB3270_EXPORT int lib3270_translate_to_address(const H3270 *hSession, unsigned int row, unsigned int col); /** + * @brief Set field contents, jump to the next one. + * + * Set the string inside the corrent field, jump to the next one. + * + * @param hSession Session handle. + * @param text String to input. + * @param length Length of the string (-1 for auto-detect). + * + * @return address of the cursor, negative if failed. + * + * @retval 0 No next field. + * @retval -EPERM The keyboard is locked. + * @retval -ENOTCONN Disconnected from host. + * @retval -ENODATA No field at the current cursor position. + * @retval -ENOTSUP The screen is not formatted. + * + */ + LIB3270_EXPORT int lib3270_set_field(H3270 *hSession, const char *text, int length); + + /** * @brief Set string at current cursor position. * * Returns are ignored; newlines mean "move to beginning of next line"; @@ -1178,7 +1198,10 @@ * @param hSession Session handle. * @param baddr Field address. * - * @return address of the first blank or -1 if invalid. + * @return address of the first blank or negative if invalid. + * + * @retval -ENOTSUP Screen is not formatted. + * @retval -EPERM Current cursor position is protected. */ LIB3270_EXPORT int lib3270_get_field_end(H3270 *hSession, int baddr); @@ -1190,10 +1213,10 @@ * * @return field address or negative if the screen isn't formatted (sets errno). * - * @exception -ENOTCONN Not connected to host. - * @exception -EOVERFLOW Invalid position. - * @exception -ENOTSUP Screen is not formatted. - * @exception -ENODATA No field at the address. + * @retval -ENOTCONN Not connected to host. + * @retval -EOVERFLOW Invalid position. + * @retval -ENOTSUP Screen is not formatted. + * @retval -ENODATA No field at the address. * */ LIB3270_EXPORT int lib3270_field_addr(const H3270 *hSession, int baddr); -- libgit2 0.21.2