From 20a9ede920f29d64b0278f61cc4ce220f7714cfd Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Thu, 5 May 2016 15:57:17 -0300 Subject: [PATCH] Download de arquivos texto precisa de tratamento diferente em windows (CR+LF & 0x1a no final). --- Makefile.in | 1 + src/include/lib3270/filetransfer.h | 47 ++++++++++++++++------------------------------- src/lib3270/ft.c | 19 +++++++++++-------- src/lib3270/ft_cut.c | 7 ++++--- src/lib3270/ft_dft.c | 9 ++++++--- src/pw3270/ft/ftdialog.c | 30 +++++++++++++++++++++++++----- 6 files changed, 63 insertions(+), 50 deletions(-) diff --git a/Makefile.in b/Makefile.in index c064e0b..a4da3a8 100644 --- a/Makefile.in +++ b/Makefile.in @@ -299,6 +299,7 @@ $(PACKAGE_TARNAME)-$(PACKAGE_VERSION).tar: clean pixmaps @cp AUTHORS LICENSE $(TMPDIR)/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION) @cp -r src $(TMPDIR)/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION) @cp -r scripts $(TMPDIR)/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION) + @cp -r nsi $(TMPDIR)/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION) @cp $(PACKAGE_TARNAME).spec $(TMPDIR)/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION) @cp debian.* $(TMPDIR)/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION) diff --git a/src/include/lib3270/filetransfer.h b/src/include/lib3270/filetransfer.h index f44e52f..c2f9623 100644 --- a/src/include/lib3270/filetransfer.h +++ b/src/include/lib3270/filetransfer.h @@ -37,32 +37,16 @@ #include #include - -/* - #define LIB3270_FT_RECORD_FORMAT_DEFAULT 0x0000 - #define LIB3270_FT_RECORD_FORMAT_FIXED 0x0100 - #define LIB3270_FT_RECORD_FORMAT_VARIABLE 0x0200 - #define LIB3270_FT_RECORD_FORMAT_UNDEFINED 0x0300 - #define LIB3270_FT_RECORD_FORMAT_MASK LIB3270_FT_RECORD_FORMAT_UNDEFINED -*/ - -/* - #define LIB3270_FT_ALLOCATION_UNITS_DEFAULT 0x0000 - #define LIB3270_FT_ALLOCATION_UNITS_TRACKS 0x1000 - #define LIB3270_FT_ALLOCATION_UNITS_CYLINDERS 0x2000 - #define LIB3270_FT_ALLOCATION_UNITS_AVBLOCK 0x3000 - #define LIB3270_FT_ALLOCATION_UNITS_MASK LIB3270_FT_ALLOCATION_UNITS_AVBLOCK -*/ - typedef enum _lib3270_FT_OPTION { LIB3270_FT_OPTION_SEND = 0x0000, LIB3270_FT_OPTION_RECEIVE = 0x0001, - LIB3270_FT_OPTION_ASCII = 0x0002, /**< Convert to ascii */ - LIB3270_FT_OPTION_CRLF = 0x0004, /**< Add crlf to each line */ + LIB3270_FT_OPTION_ASCII = 0x0002, ///< @brief Convert to ascii + LIB3270_FT_OPTION_CRLF = 0x0004, ///< @brief Add crlf to each line LIB3270_FT_OPTION_APPEND = 0x0008, - LIB3270_FT_OPTION_REMAP = 0x0010, /**< Remap ASCII<->EBCDIC */ + LIB3270_FT_OPTION_REMAP = 0x0010, ///< @brief Remap ASCII<->EBCDIC + LIB3270_FT_OPTION_UNIX = 0x0020, ///< @brief Unix text file LIB3270_FT_RECORD_FORMAT_DEFAULT = 0x0000, LIB3270_FT_RECORD_FORMAT_FIXED = 0x0100, @@ -92,21 +76,22 @@ typedef struct _h3270ft { - unsigned short sz; /**< Size of FT data structure */ - - int ft_last_cr : 1; /**< CR was last char in local file */ - int remap_flag : 1; /**< Remap ASCII<->EBCDIC */ - int cr_flag : 1; - int message_flag : 1; /**< Open Request for msg received */ - int ascii_flag : 1; /**< Convert to ascii */ - int ft_is_cut : 1; /**< File transfer is CUT-style */ + unsigned short sz; ///< @brief Size of FT data structure + + int ft_last_cr : 1; ///< @brief CR was last char in local file + int remap_flag : 1; ///< @brief Remap ASCII<->EBCDIC + int cr_flag : 1; ///< @brief Add crlf to each line + int unix_text : 1; ///< @brief Following the convention for UNIX text files. + int message_flag : 1; ///< @brief Open Request for msg received + int ascii_flag : 1; ///< @brief Convert to ascii + int ft_is_cut : 1; ///< @brief File transfer is CUT-style int dft_eof : 1; H3270 * host; - void * widget; /**< File transfer dialog handle */ - FILE * local_file; /**< File descriptor for local file */ - unsigned long length; /**< File length */ + void * widget; ///< @brief File transfer dialog handle + FILE * local_file; ///< @brief File descriptor for local file + unsigned long length; ///< @brief File length LIB3270_FT_STATE state; LIB3270_FT_OPTION flags; diff --git a/src/lib3270/ft.c b/src/lib3270/ft.c index c7dab90..38daa6d 100644 --- a/src/lib3270/ft.c +++ b/src/lib3270/ft.c @@ -298,6 +298,7 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state); ftHandle->ascii_flag = (flags & LIB3270_FT_OPTION_ASCII) ? 1 : 0; ftHandle->cr_flag = (flags & LIB3270_FT_OPTION_CRLF) ? 1 : 0; ftHandle->remap_flag = (flags & LIB3270_FT_OPTION_REMAP) ? 1 : 0; + ftHandle->unix_text = (flags & LIB3270_FT_OPTION_UNIX) ? 1 : 0; ftHandle->ft_is_cut = 0; ftHandle->flags = flags; ftHandle->local_file = ft_local_file; @@ -366,11 +367,12 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state); // Receiving file lib3270_write_dstrace( ft->host, - "\nReceiving file %s (%s %s %s)\n", + "\nReceiving file %s (%s %s %s %s)\n", ft->local, - ft->ascii_flag ? "ASCII" : "BINARY", - ft->cr_flag ? "CRLF" : "NOCRLF", - ft->remap_flag ? "REMAP" : "NOREMAP" + ft->ascii_flag ? "ASCII" : "BINARY", + ft->cr_flag ? "CRLF" : "NOCRLF", + ft->remap_flag ? "REMAP" : "NOREMAP", + ft->unix_text ? "LF Only" : "CR/LF" ); } else @@ -386,12 +388,13 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state); lib3270_write_dstrace( ft->host, - "\nSending file %s (%ld bytes %s %s %s)\n", + "\nSending file %s (%ld bytes %s %s %s %s)\n", ft->local, ft->length, - ft->ascii_flag ? "ASCII" : "BINARY", - ft->cr_flag ? "CRLF" : "NOCRLF", - ft->remap_flag ? "REMAP" : "NOREMAP" + ft->ascii_flag ? "ASCII" : "BINARY", + ft->cr_flag ? "CRLF" : "NOCRLF", + ft->remap_flag ? "REMAP" : "NOREMAP", + ft->unix_text ? "LF only" : "CR/LF" ); rewind(ft->local_file); diff --git a/src/lib3270/ft_cut.c b/src/lib3270/ft_cut.c index 9cbc3d0..6382f69 100644 --- a/src/lib3270/ft_cut.c +++ b/src/lib3270/ft_cut.c @@ -192,11 +192,12 @@ static int upload_convert(H3270 *hSession, unsigned char *buf, int len) /* Map it. */ c = conv[ft->quadrant].xlate[ix]; - if (ft->ascii_flag && ft->cr_flag && (c == '\r' || c == 0x1a)) +// if (ft->ascii_flag && ft->cr_flag && (c == '\r' || c == 0x1a)) + if (ft->unix_text && (c == '\r' || c == 0x1a)) continue; - - if (ft->ascii_flag && ft->remap_flag) + else if (ft->ascii_flag && ft->remap_flag) c = ft->charset.ebc2asc[c]; + *ob++ = c; } diff --git a/src/lib3270/ft_dft.c b/src/lib3270/ft_dft.c index b846544..fded513 100644 --- a/src/lib3270/ft_dft.c +++ b/src/lib3270/ft_dft.c @@ -294,12 +294,15 @@ static void dft_data_insert(H3270 *hSession, struct data_buffer *data_bufr) s++; } } - if (ft->ascii_flag && ft->cr_flag) + +// if (ft->ascii_flag && ft->cr_flag) + if (ft->unix_text) { + /* Delete CRs and ^Zs. */ + char *s = (char *)data_bufr->data; unsigned len = my_length; - /* Delete CRs and ^Zs. */ while (len) { unsigned l = filter_len(s, len); @@ -375,7 +378,7 @@ static void dft_get_request(H3270 *hSession) while (!ft->dft_eof && numbytes) { - if (ft->ascii_flag && ft->cr_flag) + if (ft->unix_text) { // ASCII text file diff --git a/src/pw3270/ft/ftdialog.c b/src/pw3270/ft/ftdialog.c index b458331..08f59b7 100644 --- a/src/pw3270/ft/ftdialog.c +++ b/src/pw3270/ft/ftdialog.c @@ -375,8 +375,12 @@ GtkWidget * v3270_ft_dialog_new(GtkWidget *parent, LIB3270_FT_OPTION options) { LIB3270_FT_OPTION_CRLF, BUTTON_CRLF, - N_( "Remove <_CR> from end of the line." ), - N_( "Following the convention for LINUX text files, are used to terminate records in the PC file.") + N_( "Follow the convention for ASCII text files." ), +#ifdef _WIN32 + N_( "Following the convention for ASCII text files, pairs are used to terminate records in the PC file, and a CTRL-Z (x'1A') marks the end of file.") +#else + N_( "Following the convention for ASCII text files, is used to terminate records in the PC file.") +#endif // _WIN32 }, { LIB3270_FT_OPTION_APPEND, @@ -465,8 +469,12 @@ GtkWidget * v3270_ft_dialog_new(GtkWidget *parent, LIB3270_FT_OPTION options) { LIB3270_FT_OPTION_CRLF, BUTTON_CRLF, - N_( "Add at end of the line." ), - N_( "Add an extra to follow the convention for ASCII text files.") + N_( "Follow the convention for ASCII text files." ), +#ifdef _WIN32 + N_( "Following the convention for ASCII text files, pairs are used to terminate records in the PC file, and a CTRL-Z (x'1A') marks the end of file.") +#else + N_( "Following the convention for ASCII text files, is used to terminate records in the PC file.") +#endif // _WIN32 }, { LIB3270_FT_OPTION_APPEND, @@ -689,8 +697,20 @@ const gchar * v3270_ft_dialog_get_local_filename(GtkWidget *widget) LIB3270_FT_OPTION v3270_ft_dialog_get_options(GtkWidget *widget) { + LIB3270_FT_OPTION opt; + g_return_val_if_fail(GTK_IS_V3270FTD(widget),0); - return GTK_V3270FTD(widget)->options; + + opt = GTK_V3270FTD(widget)->options; + +#ifndef _WIN32 + if( (opt & (LIB3270_FT_OPTION_ASCII|LIB3270_FT_OPTION_CRLF)) == (LIB3270_FT_OPTION_ASCII|LIB3270_FT_OPTION_CRLF) ) + { + opt |= LIB3270_FT_OPTION_UNIX; + } +#endif // _WIN32 + + return opt; } void v3270_ft_dialog_set_options(GtkWidget *widget,LIB3270_FT_OPTION options) -- libgit2 0.21.2