From 52880afad43651af4cede05fab2df0f49c6a3a8a Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Thu, 27 Dec 2018 09:51:10 -0200 Subject: [PATCH] Updating API calls for the new version. --- src/include/lib3270.h | 20 ++++++++++++++++---- src/lib3270++/local/session.cc | 4 ++-- src/lib3270/macros.c | 2 +- src/lib3270/paste.c | 35 +++++++++++++++++++++++++++++++---- src/lib3270/screen.c | 2 +- src/lib3270/selection.c | 10 +++++----- 6 files changed, 56 insertions(+), 17 deletions(-) diff --git a/src/include/lib3270.h b/src/include/lib3270.h index 69497ca..58c3df7 100644 --- a/src/include/lib3270.h +++ b/src/include/lib3270.h @@ -617,7 +617,7 @@ * @param h Session handle. * @param s String to input. * - * @return Negative if error or number of processed characters. + * @return -1 if error (sets errno) or number of processed characters. * */ LIB3270_EXPORT int lib3270_set_string(H3270 *h, const unsigned char *str); @@ -625,7 +625,7 @@ #define lib3270_set_text_at(h,r,c,t) lib3270_set_string_at(h,r,c,t) /** - * @brief Set string at defined position. + * @brief Set string at defined row/column. * * @param hSession Session handle. * @param row Row for the first character. @@ -637,6 +637,18 @@ */ LIB3270_EXPORT int lib3270_set_string_at(H3270 *hSession, int row, int col, const unsigned char *str); + /** + * @brief Set string at defined adress. + * + * @param hSession Session handle. + * @param baddr Adress for the first character. + * @param str String to set. + * + * @return Negative if error or number of processed characters. + * + */ + LIB3270_EXPORT int lib3270_set_string_at_address(H3270 *hSession, int baddr, const unsigned char *str); + LIB3270_EXPORT int lib3270_input_string(H3270 *hSession, const unsigned char *str); /** @@ -979,7 +991,7 @@ * @return Contents at position if available, or NULL. Release it with lib3270_free() * */ - LIB3270_EXPORT char * lib3270_get_text(H3270 *h, int offset, int len, char lf); + LIB3270_EXPORT char * lib3270_get_string_at_address(H3270 *h, int offset, int len, char lf); /** * @brief Get text at requested position @@ -993,7 +1005,7 @@ * @return Contents at position if available, or NULL. Release it with lib3270_free() * */ - LIB3270_EXPORT char * lib3270_get_text_at(H3270 *h, int row, int col, int len, char lf); + LIB3270_EXPORT char * lib3270_get_string_at(H3270 *h, int row, int col, int len, char lf); /** * @brief Check for text at requested position diff --git a/src/lib3270++/local/session.cc b/src/lib3270++/local/session.cc index 26c22d7..6ba8350 100644 --- a/src/lib3270++/local/session.cc +++ b/src/lib3270++/local/session.cc @@ -117,7 +117,7 @@ std::lock_guard lock(const_cast(this)->sync); - char * text = lib3270_get_text(hSession, baddr, len, lf); + char * text = lib3270_get_string_at_address(hSession, baddr, len, lf); if(!text) { throw std::runtime_error( _("Can't get screen contents") ); @@ -135,7 +135,7 @@ std::lock_guard lock(const_cast(this)->sync); - char * text = lib3270_get_text_at(hSession, row, col, sz, lf); + char * text = lib3270_get_string_at(hSession, row, col, sz, lf); if(!text) { throw std::runtime_error( _("Can't get screen contents") ); diff --git a/src/lib3270/macros.c b/src/lib3270/macros.c index c265a32..f494e24 100644 --- a/src/lib3270/macros.c +++ b/src/lib3270/macros.c @@ -103,7 +103,7 @@ switch(argc) { case 1: // Get entire screen - buffer = lib3270_get_text(hSession,0,-1,'\n'); + buffer = lib3270_get_string_at_address(hSession,0,-1,'\n'); break; /* diff --git a/src/lib3270/paste.c b/src/lib3270/paste.c index 4c488e0..8471bfa 100644 --- a/src/lib3270/paste.c +++ b/src/lib3270/paste.c @@ -266,24 +266,51 @@ LIB3270_EXPORT int lib3270_set_string_at(H3270 *hSession, int row, int col, cons return rc; } +LIB3270_EXPORT int lib3270_set_string_at_address(H3270 *hSession, int baddr, const unsigned char *str) +{ + int rc = -1; + + FAIL_IF_NOT_ONLINE(hSession); + + if(hSession->kybdlock) + { + errno = EPERM; + return -1; + } + + if(lib3270_set_cursor_address(hSession,baddr) < 0) + return -1; + + if(hSession->selected && !lib3270_get_toggle(hSession,LIB3270_TOGGLE_KEEP_SELECTED)) + lib3270_unselect(hSession); + + hSession->cbk.suspend(hSession); + rc = set_string(hSession, str); + hSession->cbk.resume(hSession); + + return rc; +} /** - * Set string at cursor position. + * @brief Set string at cursor position. * * @param hSession Session handle. * @param str String to set * - * @return Number of characters inserted; <0 in case of error. + * @return -1 if error (sets errno) or number of processed characters. * */ LIB3270_EXPORT int lib3270_set_string(H3270 *hSession, const unsigned char *str) { int rc; - CHECK_SESSION_HANDLE(hSession); + FAIL_IF_NOT_ONLINE(hSession); if(hSession->kybdlock) - return -EINVAL; + { + errno = EPERM; + return -1; + } hSession->cbk.suspend(hSession); rc = set_string(hSession, str); diff --git a/src/lib3270/screen.c b/src/lib3270/screen.c index 779752c..340e807 100644 --- a/src/lib3270/screen.c +++ b/src/lib3270/screen.c @@ -363,7 +363,7 @@ void screen_update(H3270 *session, int bstart, int bend) #ifdef DEBUG { - char *text = lib3270_get_text(session,0,-1,'\n'); + char *text = lib3270_get_string_at_address(session,0,-1,'\n'); trace("First screen:\n%s\n",text); lib3270_free(text); } diff --git a/src/lib3270/selection.c b/src/lib3270/selection.c index de271fb..ae0ca43 100644 --- a/src/lib3270/selection.c +++ b/src/lib3270/selection.c @@ -473,7 +473,7 @@ LIB3270_EXPORT char * lib3270_get_region(H3270 *h, int start_pos, int end_pos, u return lib3270_realloc(text,sz); } -LIB3270_EXPORT char * lib3270_get_text(H3270 *h, int offset, int len, char lf) +LIB3270_EXPORT char * lib3270_get_string_at_address(H3270 *h, int offset, int len, char lf) { char * buffer; int maxlen; @@ -528,10 +528,10 @@ LIB3270_EXPORT char * lib3270_get_text(H3270 *h, int offset, int len, char lf) return buffer; } -LIB3270_EXPORT char * lib3270_get_text_at(H3270 *h, int row, int col, int len, char lf) +LIB3270_EXPORT char * lib3270_get_string_at(H3270 *h, int row, int col, int len, char lf) { CHECK_SESSION_HANDLE(h); - return lib3270_get_text(h, ((row-1) * h->cols) + (col-1), len, lf); + return lib3270_get_string_at_address(h, ((row-1) * h->cols) + (col-1), len, lf); } LIB3270_EXPORT int lib3270_cmp_text_at(H3270 *h, int row, int col, const char *text, char lf) @@ -540,7 +540,7 @@ LIB3270_EXPORT int lib3270_cmp_text_at(H3270 *h, int row, int col, const char *t size_t sz = strlen(text); char * contents; - contents = lib3270_get_text_at(h,row,col,sz,lf); + contents = lib3270_get_string_at(h,row,col,sz,lf); if(!contents) return -1; @@ -567,7 +567,7 @@ LIB3270_EXPORT char * lib3270_get_field_text_at(H3270 *session, int baddr) if(first < 0) return NULL; - return lib3270_get_text(session,first,lib3270_field_length(session,first)+1,0); + return lib3270_get_string_at_address(session,first,lib3270_field_length(session,first)+1,0); } LIB3270_EXPORT int lib3270_has_selection(H3270 *hSession) -- libgit2 0.21.2