Commit c7857f1b6a3c11b8880066abef5a670f627dba08

Authored by perry.werneck@gmail.com
1 parent 6c93bad8

Corrigindo opções da transferência de arquivos

src/include/lib3270/charset.h
... ... @@ -47,8 +47,8 @@
47 47 unsigned short ebc2asc[256];
48 48 unsigned short asc2ebc[256];
49 49  
50   - unsigned short asc2ft[256];
51   - unsigned short ft2asc[256];
  50 +// unsigned short asc2ft[256];
  51 +// unsigned short ft2asc[256];
52 52  
53 53 unsigned short asc2uc[256];
54 54  
... ...
src/include/lib3270/filetransfer.h
... ... @@ -35,6 +35,7 @@
35 35 #define LIB3270_FILETRANSFER_INCLUDED 1
36 36 #include <stdio.h>
37 37 #include <sys/time.h>
  38 + #include <lib3270/charset.h>
38 39  
39 40 #define LIB3270_FT_OPTION_SEND 0x0000
40 41  
... ... @@ -53,11 +54,11 @@
53 54 typedef enum _lib3270_FT_FLAG
54 55 {
55 56 LIB3270_FT_OPTION_RECEIVE = 0x0001,
56   - LIB3270_FT_OPTION_ASCII = 0x0002,
57   - LIB3270_FT_OPTION_CRLF = 0x0004,
  57 + LIB3270_FT_OPTION_ASCII = 0x0002, /**< Convert to ascii */
  58 + LIB3270_FT_OPTION_CRLF = 0x0004, /**< Add crlf to each line */
58 59 LIB3270_FT_OPTION_APPEND = 0x0008,
59   -// LIB3270_FT_OPTION_TSO = 0x0010,
60   - LIB3270_FT_OPTION_REMAP_ASCII = 0x0020
  60 + LIB3270_FT_OPTION_REMAP = 0x0010 /**< Remap ASCII<->EBCDIC */
  61 +
61 62 } LIB3270_FT_OPTION;
62 63  
63 64 typedef enum _lib3270_ft_state
... ... @@ -73,53 +74,55 @@
73 74  
74 75 typedef struct _h3270ft
75 76 {
76   - unsigned short sz; /**< Size of FT data structure */
  77 + unsigned short sz; /**< Size of FT data structure */
77 78  
78   - int ft_last_cr : 1; /**< CR was last char in local file */
79   - int remap_flag : 1; /**< Remap ASCII<->EBCDIC */
80   - int cr_flag : 1; /**< Add crlf to each line */
81   - int message_flag : 1; /**< Open Request for msg received */
82   - int ascii_flag : 1; /**< Convert to ascii */
83   - int ft_is_cut : 1; /**< File transfer is CUT-style */
84   - int dft_eof : 1;
  79 + int ft_last_cr : 1; /**< CR was last char in local file */
  80 + int remap_flag : 1; /**< Remap ASCII<->EBCDIC */
  81 + int cr_flag : 1;
  82 + int message_flag : 1; /**< Open Request for msg received */
  83 + int ascii_flag : 1; /**< Convert to ascii */
  84 + int ft_is_cut : 1; /**< File transfer is CUT-style */
  85 + int dft_eof : 1;
85 86  
86 87  
87   - H3270 * host;
88   - void * widget; /**< File transfer dialog handle */
89   - FILE * local_file; /**< File descriptor for local file */
90   - unsigned long length; /**< File length */
  88 + H3270 * host;
  89 + void * widget; /**< File transfer dialog handle */
  90 + FILE * local_file; /**< File descriptor for local file */
  91 + unsigned long length; /**< File length */
91 92  
92   - LIB3270_FT_STATE state;
93   - LIB3270_FT_OPTION flags;
  93 + LIB3270_FT_STATE state;
  94 + LIB3270_FT_OPTION flags;
94 95  
95   - int lrecl;
96   - int blksize;
97   - int primspace;
98   - int secspace;
99   - int dft;
  96 + int lrecl;
  97 + int blksize;
  98 + int primspace;
  99 + int secspace;
  100 + int dft;
100 101  
101   - unsigned long ft_length; /**< Length of transfer */
  102 + unsigned long ft_length; /**< Length of transfer */
102 103  
103   - struct timeval starting_time; /**< Starting time */
  104 + struct timeval starting_time; /**< Starting time */
104 105  
105   - const char * local; /**< Local filename */
106   - const char * remote; /**< Remote filename */
  106 + const char * local; /**< Local filename */
  107 + const char * remote; /**< Remote filename */
107 108  
108 109 // ft_dft.c
109   - char * abort_string;
110   - unsigned long recnum;
111   - unsigned char * dft_savebuf;
112   - int dft_savebuf_len;
113   - int dft_savebuf_max;
  110 + char * abort_string;
  111 + unsigned long recnum;
  112 + unsigned char * dft_savebuf;
  113 + int dft_savebuf_len;
  114 + int dft_savebuf_max;
114 115  
115 116 // ft_cut.c
116   - int quadrant;
117   - unsigned long expanded_length;
118   - char * saved_errmsg;
119   - int xlate_buffered; /**< buffer count */
120   - int xlate_buf_ix; /**< buffer index */
121   - unsigned char xlate_buf[LIB3270_XLATE_NBUF]; /**< buffer */
122   -
  117 + int quadrant;
  118 + unsigned long expanded_length;
  119 + char * saved_errmsg;
  120 + int xlate_buffered; /**< buffer count */
  121 + int xlate_buf_ix; /**< buffer index */
  122 + unsigned char xlate_buf[LIB3270_XLATE_NBUF]; /**< buffer */
  123 +
  124 + // Charset
  125 + struct lib3270_charset charset;
123 126  
124 127 // Callbacks
125 128 void (*complete)(struct _h3270ft *ft,unsigned long length,double kbytes_sec,const char *mode);
... ...
src/lib3270/charset.c
... ... @@ -132,6 +132,7 @@ static const unsigned short asc2ebc0[256] =
132 132 /*f8*/ 0x70, 0xdd, 0xde, 0xdb, 0xdc, 0x8d, 0x8e, 0xdf
133 133 };
134 134  
  135 +/*
135 136 static const unsigned short ft2asc[256] =
136 137 {
137 138 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,
... ... @@ -171,6 +172,7 @@ const unsigned short asc2ft[256] =
171 172 0xa3,0xa4,0xa1,0xa5,0xa2,0xa6,0xcd,0xa7,0xac,0xa9,0xaa,0xab,0xb0,0xad,0xae,0xaf,
172 173 0xc6,0xa8,0xeb,0xec,0xe9,0xed,0xea,0x9f,0xba,0xf1,0xf2,0xef,0xf0,0xc7,0xc8,0xf3
173 174 };
  175 +*/
174 176  
175 177 static const unsigned short asc2uc[UT_SIZE] =
176 178 {
... ... @@ -271,10 +273,12 @@ LIB3270_EXPORT int lib3270_set_host_charset(H3270 *hSession, const char *name)
271 273 hSession->charset.asc2uc[f] = f;
272 274 copy_charset(asc2uc,hSession->charset.asc2uc);
273 275  
  276 +/*
274 277 #if defined(X3270_FT)
275 278 memcpy(hSession->charset.ft2asc, ft2asc, sizeof(hSession->charset.ft2asc));
276 279 memcpy(hSession->charset.asc2ft, asc2ft, sizeof(hSession->charset.asc2ft));
277 280 #endif
  281 +*/
278 282  
279 283 if(!(name && strcasecmp(name,hSession->charset.host)))
280 284 return 0;
... ... @@ -451,9 +455,9 @@ LIB3270_EXPORT void lib3270_remap(H3270 *hSession, unsigned short ebc, unsigned
451 455  
452 456 if (iso <= 0xff)
453 457 {
454   -#if defined(X3270_FT)
455   - unsigned char aa;
456   -#endif
  458 +//#if defined(X3270_FT)
  459 +// unsigned char aa;
  460 +//#endif
457 461  
458 462 if (scope == BOTH || scope == CS_ONLY)
459 463 {
... ... @@ -484,6 +488,8 @@ LIB3270_EXPORT void lib3270_remap(H3270 *hSession, unsigned short ebc, unsigned
484 488 hSession->charset.asc2ebc[iso] = ebc;
485 489 }
486 490 }
  491 +
  492 +/*
487 493 #if defined(X3270_FT)
488 494 if (iso <= 0xff && ebc > 0x40)
489 495 {
... ... @@ -522,14 +528,8 @@ LIB3270_EXPORT void lib3270_remap(H3270 *hSession, unsigned short ebc, unsigned
522 528 }
523 529 }
524 530 #endif
525   - }
526   -/*
527   - else
528   - {
529   - // Auto-keymap.
530   - add_xk(iso, (KeySym)hSession->charset.ebc2asc[ebc]);
531   - }
532 531 */
  532 + }
533 533 }
534 534  
535 535  
... ...
src/lib3270/ft.c
... ... @@ -210,9 +210,10 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state);
210 210 ftHandle->host = session;
211 211  
212 212 ftHandle->ft_last_cr = 0;
213   - ftHandle->remap_flag = 1; // Remap ASCII<->EBCDIC
214   - ftHandle->cr_flag = 1;
215   - ftHandle->ascii_flag = 1;
  213 +
  214 + ftHandle->ascii_flag = (flags & LIB3270_FT_OPTION_ASCII) ? 1 : 0;
  215 + ftHandle->cr_flag = (flags & LIB3270_FT_OPTION_CRLF) ? 1 : 0;
  216 + ftHandle->remap_flag = (flags & LIB3270_FT_OPTION_REMAP) ? 1 : 0;
216 217 ftHandle->ft_is_cut = 0;
217 218 ftHandle->flags = flags;
218 219 ftHandle->local_file = ft_local_file;
... ... @@ -230,6 +231,7 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state);
230 231 ftHandle->dft = dft;
231 232 ftHandle->quadrant = -1;
232 233  
  234 + memcpy(&ftHandle->charset,&session->charset,sizeof(struct lib3270_charset));
233 235  
234 236 ftHandle->local = (char *) (ftHandle+1);
235 237 strcpy((char *) ftHandle->local,local);
... ... @@ -239,6 +241,8 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state);
239 241  
240 242 session->ft = ftHandle;
241 243  
  244 +
  245 +
242 246 return ftHandle;
243 247 }
244 248  
... ... @@ -260,16 +264,23 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state);
260 264 if(!ft)
261 265 return EINVAL;
262 266  
263   - recfm = (ft->flags & FT_RECORD_FORMAT_MASK) >> 8;
264   - units = (ft->flags & FT_ALLOCATION_UNITS_MASK) >> 12;
265   - ft->ascii_flag = ((ft->flags & LIB3270_FT_OPTION_ASCII) == 0) ? 1 : 0;
266   - ft->cr_flag = ((ft->flags & LIB3270_FT_OPTION_CRLF) == 0) ? 1 : 0;
267   - ft->remap_flag = ((ft->flags & LIB3270_FT_OPTION_ASCII) == 0) ? 1 : 0;
  267 + recfm = (ft->flags & FT_RECORD_FORMAT_MASK) >> 8;
  268 + units = (ft->flags & FT_ALLOCATION_UNITS_MASK) >> 12;
  269 + ft->ascii_flag = (ft->flags & LIB3270_FT_OPTION_ASCII) ? 1 : 0;
  270 + ft->cr_flag = (ft->flags & LIB3270_FT_OPTION_CRLF) ? 1 : 0;
  271 + ft->remap_flag = (ft->flags & LIB3270_FT_OPTION_REMAP) ? 1 : 0;
268 272  
269 273 if(ft->flags & LIB3270_FT_OPTION_RECEIVE)
270 274 {
271 275 // Receiving file
272   - lib3270_write_log(ft->host,"ft","Receiving file %s",ft->local);
  276 + lib3270_write_log( ft->host,
  277 + "ft",
  278 + "Receiving file %s %s %s %s",
  279 + ft->local,
  280 + ft->ascii_flag ? "ASCII" : "BINARY",
  281 + ft->cr_flag ? "CRLF" : "NOCRLF",
  282 + ft->remap_flag ? "REMAP" : "NOREMAP"
  283 + );
273 284 }
274 285 else
275 286 {
... ... @@ -283,7 +294,15 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state);
283 294 ft->length = ftell(ft->local_file);
284 295  
285 296  
286   - lib3270_write_log(ft->host,"ft","Sending file %s (%ld bytes)",ft->local,ft->length);
  297 + lib3270_write_log( ft->host,
  298 + "ft",
  299 + "Sending file %s (%ld bytes) %s %s %s",
  300 + ft->local,
  301 + ft->length,
  302 + ft->ascii_flag ? "ASCII" : "BINARY",
  303 + ft->cr_flag ? "CRLF" : "NOCRLF",
  304 + ft->remap_flag ? "REMAP" : "NOREMAP"
  305 + );
287 306 rewind(ft->local_file);
288 307 }
289 308  
... ...
src/lib3270/ft_cut.c
... ... @@ -194,7 +194,7 @@ static int upload_convert(H3270 *hSession, unsigned char *buf, int len)
194 194 if (ft->ascii_flag && ft->cr_flag && (c == '\r' || c == 0x1a))
195 195 continue;
196 196 if (ft->ascii_flag && ft->remap_flag)
197   - c = hSession->charset.ft2asc[c];
  197 + c = ft->charset.ebc2asc[c];
198 198 *ob++ = c;
199 199 }
200 200  
... ... @@ -231,7 +231,7 @@ static int download_convert(H3270FT *ft, unsigned const char *buf, unsigned len,
231 231  
232 232 /* Translate. */
233 233 if (ft->ascii_flag && ft->remap_flag)
234   - c = hSession->charset.asc2ft[c];
  234 + c = ft->charset.asc2ebc[c];
235 235  
236 236 /* Quadrant already defined. */
237 237 if (ft->quadrant >= 0) {
... ...
src/lib3270/ft_dft.c
... ... @@ -304,7 +304,7 @@ static void dft_data_insert(H3270 *hSession, struct data_buffer *data_bufr)
304 304  
305 305 while (len--)
306 306 {
307   - *s = hSession->charset.ft2asc[*s];
  307 + *s = ft->charset.ebc2asc[*s];
308 308 s++;
309 309 }
310 310 }
... ... @@ -413,7 +413,7 @@ static void dft_get_request(H3270 *hSession)
413 413 total_read++;
414 414 }
415 415 ft->ft_last_cr = (c == '\r') ? 1 : 0;
416   - *bufptr++ = ft->remap_flag? hSession->charset.asc2ft[c]: c;
  416 + *bufptr++ = ft->remap_flag ? ft->charset.asc2ebc[c]: c;
417 417 numbytes--;
418 418 total_read++;
419 419 } else {
... ... @@ -422,12 +422,14 @@ static void dft_get_request(H3270 *hSession)
422 422 if (numread <= 0) {
423 423 break;
424 424 }
425   - if (ft->ascii_flag && ft->remap_flag) {
  425 + if (ft->ascii_flag && ft->remap_flag)
  426 + {
426 427 unsigned char *s = bufptr;
427 428 int i = numread;
428 429  
429   - while (i) {
430   - *s = hSession->charset.asc2ft[*s];
  430 + while (i)
  431 + {
  432 + *s = ft->charset.asc2ebc[*s];
431 433 s++;
432 434 i--;
433 435 }
... ...
src/pw3270/filetransfer.c
... ... @@ -257,7 +257,7 @@ static void add_transfer_options(GObject *action, struct ftdialog *dlg)
257 257 { { LIB3270_FT_OPTION_ASCII, "text", N_( "_Text file" ) },
258 258 { LIB3270_FT_OPTION_CRLF, "cr", N_( "Add/Remove _CR at end of line" ) },
259 259 { LIB3270_FT_OPTION_APPEND, "append", N_( "_Append" ) },
260   - { LIB3270_FT_OPTION_REMAP_ASCII, "remap", N_( "_Remap ASCII Characters" ) }
  260 + { LIB3270_FT_OPTION_REMAP, "remap", N_( "_Remap ASCII Characters" ) }
261 261 };
262 262  
263 263 GtkTable * table = GTK_TABLE(gtk_table_new(3,2,TRUE));
... ...