From 67a51e3a364a5c26008d1366c70e5a9a2bee7789 Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Fri, 26 Jul 2019 14:22:46 -0300 Subject: [PATCH] Exporting "save" options. --- src/core/session.c | 9 ++++++++- src/core/util.c | 31 +++++++++++++++++++++++++++---- src/include/lib3270.h | 31 +++++++++++++++++++++++-------- src/include/lib3270/session.h | 3 ++- 4 files changed, 60 insertions(+), 14 deletions(-) diff --git a/src/core/session.c b/src/core/session.c index 8df6330..4fed4d7 100644 --- a/src/core/session.c +++ b/src/core/session.c @@ -192,12 +192,18 @@ static void set_cursor(H3270 GNUC_UNUSED(*session), LIB3270_POINTER GNUC_UNUSED( { } -static int print(H3270 *session, LIB3270_PRINT_MODE GNUC_UNUSED(mode)) +static int print(H3270 *session, LIB3270_CONTENT_OPTION GNUC_UNUSED(mode)) { lib3270_write_log(session, "print", "%s", "Printing is unavailable"); return errno = ENOTSUP; } +static int save(H3270 *session, LIB3270_CONTENT_OPTION GNUC_UNUSED(mode), const char GNUC_UNUSED(*filename)) +{ + lib3270_write_log(session, "save", "%s", "Saving is unavailable"); + return errno = ENOTSUP; +} + static void message(H3270 *session, LIB3270_NOTIFY GNUC_UNUSED(id), const char *title, const char *msg, const char *text) { #ifdef ANDROID @@ -301,6 +307,7 @@ void lib3270_reset_callbacks(H3270 *hSession) hSession->cbk.autostart = nop; hSession->cbk.set_timer = set_timer; hSession->cbk.print = print; + hSession->cbk.save = save; hSession->cbk.set_peer_certificate = set_peer_certificate; hSession->cbk.update_luname = default_update_luname; diff --git a/src/core/util.c b/src/core/util.c index 60482a4..3d9cac7 100644 --- a/src/core/util.c +++ b/src/core/util.c @@ -593,28 +593,51 @@ void lib3270_popup_an_errno(H3270 *hSession, int errn, const char *fmt, ...) } -LIB3270_EXPORT int lib3270_print(H3270 *hSession, LIB3270_PRINT_MODE mode) +LIB3270_EXPORT int lib3270_print(H3270 *hSession, LIB3270_CONTENT_OPTION mode) { return hSession->cbk.print(hSession, mode); } LIB3270_EXPORT int lib3270_print_all(H3270 *hSession) { - return lib3270_print(hSession,LIB3270_PRINT_ALL); + return lib3270_print(hSession,LIB3270_CONTENT_ALL); } LIB3270_EXPORT int lib3270_print_selected(H3270 *hSession) { if(lib3270_has_selection(hSession)) - return lib3270_print(hSession,LIB3270_PRINT_SELECTED); + return lib3270_print(hSession,LIB3270_CONTENT_SELECTED); return errno = ENODATA; } LIB3270_EXPORT int lib3270_print_copy(H3270 *hSession) { - return lib3270_print(hSession,LIB3270_PRINT_COPY); + return lib3270_print(hSession,LIB3270_CONTENT_COPY); } +LIB3270_EXPORT int lib3270_save(H3270 *hSession, LIB3270_CONTENT_OPTION mode, const char *filename) +{ + return hSession->cbk.save(hSession, mode, filename); +} + +LIB3270_EXPORT int lib3270_save_all(H3270 *hSession, const char *filename) +{ + return lib3270_save(hSession,LIB3270_CONTENT_ALL,filename); +} + +LIB3270_EXPORT int lib3270_save_selected(H3270 *hSession, const char *filename) +{ + if(lib3270_has_selection(hSession)) + return lib3270_save(hSession,LIB3270_CONTENT_SELECTED,filename); + return errno = ENODATA; +} + +LIB3270_EXPORT int lib3270_save_copy(H3270 *hSession, const char *filename) +{ + return lib3270_save(hSession,LIB3270_CONTENT_COPY,filename); +} + + LIB3270_EXPORT LIB3270_POINTER lib3270_get_pointer(H3270 *hSession, int baddr) { static const struct _ptr { diff --git a/src/include/lib3270.h b/src/include/lib3270.h index 24c6a55..9ea1553 100644 --- a/src/include/lib3270.h +++ b/src/include/lib3270.h @@ -84,15 +84,15 @@ #define LIB3270_LUNAME_LENGTH 16 /** - * @brief Print modes. + * @brief Selection mode. * */ - typedef enum _lib3270_print_mode + typedef enum _lib3270_content_option { - LIB3270_PRINT_ALL, - LIB3270_PRINT_SELECTED, - LIB3270_PRINT_COPY - } LIB3270_PRINT_MODE; + LIB3270_CONTENT_ALL, ///< @brief Get all the terminal data. + LIB3270_CONTENT_SELECTED, ///< @brief Get only selected contents. + LIB3270_CONTENT_COPY ///< @brief Get internal copy. + } LIB3270_CONTENT_OPTION; /** * @brief Character attributes. @@ -784,18 +784,33 @@ * @brief Print page * * @param hSession Session Handle. - * @param mode Print mode. + * @param mode Content option. * * @return 0 if ok, error code if not. * */ - LIB3270_EXPORT int lib3270_print(H3270 *hSession, LIB3270_PRINT_MODE mode); + LIB3270_EXPORT int lib3270_print(H3270 *hSession, LIB3270_CONTENT_OPTION mode); LIB3270_EXPORT int lib3270_print_all(H3270 *hSession); LIB3270_EXPORT int lib3270_print_selected(H3270 *hSession); LIB3270_EXPORT int lib3270_print_copy(H3270 *hSession); /** + * @brief Save contents to file. + * + * @param hSession Session Handle. + * @param mode Content option. + * @param filename File name. + * + * @return 0 if ok, error code if not. + */ + LIB3270_EXPORT int lib3270_save(H3270 *hSession, LIB3270_CONTENT_OPTION mode, const char *filename); + + LIB3270_EXPORT int lib3270_save_all(H3270 *hSession, const char *filename); + LIB3270_EXPORT int lib3270_save_selected(H3270 *hSession, const char *filename); + LIB3270_EXPORT int lib3270_save_copy(H3270 *hSession, const char *filename); + + /** * @brief Get buffer contents. * * @param h Session handle. diff --git a/src/include/lib3270/session.h b/src/include/lib3270/session.h index c20a545..29e5245 100644 --- a/src/include/lib3270/session.h +++ b/src/include/lib3270/session.h @@ -74,7 +74,8 @@ void (*set_selection)(H3270 *session, unsigned char on); void (*ctlr_done)(H3270 *session); void (*autostart)(H3270 *session); - int (*print)(H3270 *session, LIB3270_PRINT_MODE mode); + int (*print)(H3270 *session, LIB3270_CONTENT_OPTION mode); + int (*save)(H3270 *session, LIB3270_CONTENT_OPTION mode, const char *filename); void (*message)(H3270 *session, LIB3270_NOTIFY id , const char *title, const char *message, const char *text); void (*popup)(H3270 *session, LIB3270_NOTIFY id, const char *title, const char *msg, const char *fmt, va_list); -- libgit2 0.21.2