Commit 2fd2b75ac77c25cc01b459ea832c25591b3a1129
1 parent
6c280698
Exists in
master
and in
5 other branches
Implementando conversao de charset
Showing
4 changed files
with
139 additions
and
8 deletions
Show diff stats
android/jni/main.cpp
@@ -281,7 +281,7 @@ static void autostart(H3270 *session) | @@ -281,7 +281,7 @@ static void autostart(H3270 *session) | ||
281 | 281 | ||
282 | jint JNI_OnLoad(JavaVM *vm, void *reserved) | 282 | jint JNI_OnLoad(JavaVM *vm, void *reserved) |
283 | { | 283 | { |
284 | - H3270 * session = lib3270_session_new(""); | 284 | + H3270 * session = lib3270_session_new("","bracket"); |
285 | 285 | ||
286 | __android_log_print(ANDROID_LOG_VERBOSE, PACKAGE_NAME, "Initializing %s",PACKAGE_NAME); | 286 | __android_log_print(ANDROID_LOG_VERBOSE, PACKAGE_NAME, "Initializing %s",PACKAGE_NAME); |
287 | 287 |
src/include/lib3270/session.h
@@ -112,7 +112,7 @@ | @@ -112,7 +112,7 @@ | ||
112 | int trace_skipping : 1; | 112 | int trace_skipping : 1; |
113 | int need_tls_follows : 1; | 113 | int need_tls_follows : 1; |
114 | int cut_xfer_in_progress : 1; | 114 | int cut_xfer_in_progress : 1; |
115 | - int auto_keymap : 1; | 115 | +// int auto_keymap : 1; |
116 | int formatted : 1; /**< Formatted screen flag */ | 116 | int formatted : 1; /**< Formatted screen flag */ |
117 | int starting : 1; /**< Is starting (no first screen)? */ | 117 | int starting : 1; /**< Is starting (no first screen)? */ |
118 | 118 |
src/lib3270/charset.c
@@ -35,6 +35,16 @@ | @@ -35,6 +35,16 @@ | ||
35 | */ | 35 | */ |
36 | 36 | ||
37 | #include "globals.h" | 37 | #include "globals.h" |
38 | +#include "X11keysym.h" | ||
39 | + | ||
40 | +typedef enum | ||
41 | +{ | ||
42 | + CS_ONLY, | ||
43 | + FT_ONLY, | ||
44 | + BOTH | ||
45 | +} remap_scope; | ||
46 | + | ||
47 | +static void remap_char(H3270 *hSession, unsigned short ebc, unsigned short iso, remap_scope scope, unsigned char one_way); | ||
38 | 48 | ||
39 | /* | 49 | /* |
40 | * EBCDIC-to-Unicode translation tables. | 50 | * EBCDIC-to-Unicode translation tables. |
@@ -44,6 +54,7 @@ | @@ -44,6 +54,7 @@ | ||
44 | #define UT_SIZE 190 | 54 | #define UT_SIZE 190 |
45 | #define UT_OFFSET 0x41 | 55 | #define UT_OFFSET 0x41 |
46 | 56 | ||
57 | +/* | ||
47 | typedef struct | 58 | typedef struct |
48 | { | 59 | { |
49 | const char * name; | 60 | const char * name; |
@@ -52,6 +63,7 @@ typedef struct | @@ -52,6 +63,7 @@ typedef struct | ||
52 | const char * display_charset; | 63 | const char * display_charset; |
53 | unsigned short code[UT_SIZE]; | 64 | unsigned short code[UT_SIZE]; |
54 | } charset_table; | 65 | } charset_table; |
66 | +*/ | ||
55 | 67 | ||
56 | 68 | ||
57 | /*---[ Statics ]--------------------------------------------------------------------------------------------------------------*/ | 69 | /*---[ Statics ]--------------------------------------------------------------------------------------------------------------*/ |
@@ -197,6 +209,16 @@ static const unsigned short asc2uc[UT_SIZE] = | @@ -197,6 +209,16 @@ static const unsigned short asc2uc[UT_SIZE] = | ||
197 | }; | 209 | }; |
198 | 210 | ||
199 | 211 | ||
212 | + | ||
213 | +// | ||
214 | +// bracket: "0xad: [ \n 0xba: XK_Yacute \n0xbd: ] \n 0xbb: XK_diaeresis \n" | ||
215 | +// | ||
216 | +// remap_char(hSession,0xad, '[', BOTH, 0); | ||
217 | +// remap_char(hSession,0xba, XK_Yacute, BOTH, 0); | ||
218 | +// remap_char(hSession,0xbd, ']', BOTH, 0); | ||
219 | +// remap_char(hSession,0xbb, XK_diaeresis, remap_scope scope,0); | ||
220 | +// | ||
221 | + | ||
200 | /*---[ Implement ]------------------------------------------------------------------------------------------------------------*/ | 222 | /*---[ Implement ]------------------------------------------------------------------------------------------------------------*/ |
201 | 223 | ||
202 | static void copy_charset(const unsigned short *from, unsigned short *to) | 224 | static void copy_charset(const unsigned short *from, unsigned short *to) |
@@ -210,11 +232,11 @@ LIB3270_EXPORT struct lib3270_charset * lib3270_load_charset(H3270 *hSession, co | @@ -210,11 +232,11 @@ LIB3270_EXPORT struct lib3270_charset * lib3270_load_charset(H3270 *hSession, co | ||
210 | { | 232 | { |
211 | int f; | 233 | int f; |
212 | 234 | ||
213 | - hSession->charset.host = "bracket"; | 235 | + hSession->charset.host = "us"; |
214 | hSession->charset.display = "ISO-8859-1"; | 236 | hSession->charset.display = "ISO-8859-1"; |
215 | 237 | ||
216 | - lib3270_write_log(hSession,"charset","host.charset=%s display.charset=%s", | ||
217 | - hSession->charset.host,hSession->charset.display); | 238 | +// lib3270_write_log(hSession,"charset","host.charset=%s display.charset=%s", |
239 | +// hSession->charset.host,hSession->charset.display); | ||
218 | 240 | ||
219 | memcpy(hSession->charset.ebc2asc, ebc2asc0, sizeof(hSession->charset.ebc2asc)); | 241 | memcpy(hSession->charset.ebc2asc, ebc2asc0, sizeof(hSession->charset.ebc2asc)); |
220 | memcpy(hSession->charset.asc2ebc, asc2ebc0, sizeof(hSession->charset.asc2ebc)); | 242 | memcpy(hSession->charset.asc2ebc, asc2ebc0, sizeof(hSession->charset.asc2ebc)); |
@@ -228,6 +250,16 @@ LIB3270_EXPORT struct lib3270_charset * lib3270_load_charset(H3270 *hSession, co | @@ -228,6 +250,16 @@ LIB3270_EXPORT struct lib3270_charset * lib3270_load_charset(H3270 *hSession, co | ||
228 | memcpy(hSession->charset.asc2ft, asc2ft, sizeof(hSession->charset.asc2ft)); | 250 | memcpy(hSession->charset.asc2ft, asc2ft, sizeof(hSession->charset.asc2ft)); |
229 | #endif | 251 | #endif |
230 | 252 | ||
253 | + //if(!(name && strcasecmp(name,hSession->charset.host))) | ||
254 | + // return &hSession->charset; | ||
255 | + | ||
256 | + // Bracket | ||
257 | + remap_char(hSession,0xad, '[', BOTH, 0); | ||
258 | + remap_char(hSession,0xba, XK_Yacute, BOTH, 0); | ||
259 | + remap_char(hSession,0xbd, ']', BOTH, 0); | ||
260 | + remap_char(hSession,0xbb, XK_diaeresis, BOTH, 0); | ||
261 | + | ||
262 | + | ||
231 | return &hSession->charset; | 263 | return &hSession->charset; |
232 | } | 264 | } |
233 | 265 | ||
@@ -303,6 +335,105 @@ LIB3270_ACTION( charsettable ) | @@ -303,6 +335,105 @@ LIB3270_ACTION( charsettable ) | ||
303 | return 0; | 335 | return 0; |
304 | } | 336 | } |
305 | 337 | ||
338 | +// Process a single character definition. | ||
339 | +static void remap_char(H3270 *hSession, unsigned short ebc, unsigned short iso, remap_scope scope, unsigned char one_way) | ||
340 | +{ | ||
341 | +// unsigned char cg; | ||
342 | + | ||
343 | + // Ignore mappings of EBCDIC control codes and the space character. | ||
344 | + if (ebc <= 0x40) | ||
345 | + return; | ||
346 | + | ||
347 | + // If they want to map to a NULL or a blank, make it a one-way blank. | ||
348 | + if (iso == 0x0) | ||
349 | + iso = 0x20; | ||
350 | + if (iso == 0x20) | ||
351 | + one_way = True; | ||
352 | + | ||
353 | + if (iso <= 0xff) | ||
354 | + { | ||
355 | +#if defined(X3270_FT) | ||
356 | + unsigned char aa; | ||
357 | +#endif | ||
358 | + | ||
359 | + if (scope == BOTH || scope == CS_ONLY) | ||
360 | + { | ||
361 | + /* | ||
362 | + if (iso <= 0xff) | ||
363 | + { | ||
364 | + cg = hSession->charset.asc2cg[iso]; | ||
365 | + | ||
366 | + if (hSession->charset.cg2asc[cg] == iso || iso == 0) | ||
367 | + { | ||
368 | + // well-defined | ||
369 | + hSession->charset.ebc2cg[ebc] = cg; | ||
370 | + if (!one_way) | ||
371 | + hSession->charset.cg2ebc[cg] = ebc; | ||
372 | + } | ||
373 | + else | ||
374 | + { | ||
375 | + // into a hole | ||
376 | + hSession->charset.ebc2cg[ebc] = CG_boxsolid; | ||
377 | + } | ||
378 | + } | ||
379 | + */ | ||
380 | + | ||
381 | + if (ebc > 0x40) | ||
382 | + { | ||
383 | + hSession->charset.ebc2asc[ebc] = iso; | ||
384 | + if (!one_way) | ||
385 | + hSession->charset.asc2ebc[iso] = ebc; | ||
386 | + } | ||
387 | + } | ||
388 | +#if defined(X3270_FT) | ||
389 | + if (iso <= 0xff && ebc > 0x40) | ||
390 | + { | ||
391 | + // Change the file transfer translation table. | ||
392 | + if (scope == BOTH) | ||
393 | + { | ||
394 | + // | ||
395 | + // We have an alternate mapping of an EBCDIC | ||
396 | + // code to an ASCII code. Modify the existing | ||
397 | + // ASCII(ft)-to-ASCII(desired) maps. | ||
398 | + // | ||
399 | + // This is done by figuring out which ASCII | ||
400 | + // code the host usually translates the given | ||
401 | + // EBCDIC code to (asc2ft0[ebc2asc0[ebc]]). | ||
402 | + // Now we want to translate that code to the | ||
403 | + // given ISO code, and vice-versa. | ||
404 | + // | ||
405 | + aa = asc2ft[ebc2asc0[ebc]]; | ||
406 | + if (aa != ' ') | ||
407 | + { | ||
408 | + hSession->charset.ft2asc[aa] = iso; | ||
409 | + hSession->charset.asc2ft[iso] = aa; | ||
410 | + } | ||
411 | + } | ||
412 | + else if (scope == FT_ONLY) | ||
413 | + { | ||
414 | + // | ||
415 | + // We have a map of how the host translates | ||
416 | + // the given EBCDIC code to an ASCII code. | ||
417 | + // Generate the translation between that code | ||
418 | + // and the ISO code that we would normally | ||
419 | + // use to display that EBCDIC code. | ||
420 | + // | ||
421 | + hSession->charset.ft2asc[iso] = hSession->charset.ebc2asc[ebc]; | ||
422 | + hSession->charset.asc2ft[hSession->charset.ebc2asc[ebc]] = iso; | ||
423 | + } | ||
424 | + } | ||
425 | +#endif | ||
426 | + } | ||
427 | +/* | ||
428 | + else | ||
429 | + { | ||
430 | + // Auto-keymap. | ||
431 | + add_xk(iso, (KeySym)hSession->charset.ebc2asc[ebc]); | ||
432 | + } | ||
433 | +*/ | ||
434 | +} | ||
435 | + | ||
436 | + | ||
306 | /*ISO-8859-1 | 437 | /*ISO-8859-1 |
307 | 438 | ||
308 | #include "resources.h" | 439 | #include "resources.h" |
src/lib3270/session.c
@@ -177,7 +177,7 @@ static void nop_int(H3270 *session, int width) | @@ -177,7 +177,7 @@ static void nop_int(H3270 *session, int width) | ||
177 | return; | 177 | return; |
178 | } | 178 | } |
179 | 179 | ||
180 | -static void lib3270_session_init(H3270 *hSession, const char *model) | 180 | +static void lib3270_session_init(H3270 *hSession, const char *model, const char *charset) |
181 | { | 181 | { |
182 | int ovc, ovr; | 182 | int ovc, ovr; |
183 | char junk; | 183 | char junk; |
@@ -187,7 +187,7 @@ static void lib3270_session_init(H3270 *hSession, const char *model) | @@ -187,7 +187,7 @@ static void lib3270_session_init(H3270 *hSession, const char *model) | ||
187 | memset(hSession,0,sizeof(H3270)); | 187 | memset(hSession,0,sizeof(H3270)); |
188 | hSession->sz = sizeof(H3270); | 188 | hSession->sz = sizeof(H3270); |
189 | 189 | ||
190 | - lib3270_load_charset(hSession,NULL); | 190 | + lib3270_load_charset(hSession,charset); |
191 | 191 | ||
192 | // Default calls | 192 | // Default calls |
193 | hSession->write = lib3270_sock_send; | 193 | hSession->write = lib3270_sock_send; |
@@ -321,7 +321,7 @@ H3270 * lib3270_session_new(const char *model) | @@ -321,7 +321,7 @@ H3270 * lib3270_session_new(const char *model) | ||
321 | 321 | ||
322 | hSession = default_session = lib3270_malloc(sizeof(H3270)); | 322 | hSession = default_session = lib3270_malloc(sizeof(H3270)); |
323 | 323 | ||
324 | - lib3270_session_init(hSession, model); | 324 | + lib3270_session_init(hSession, model, "bracket"); |
325 | 325 | ||
326 | if(screen_init(hSession)) | 326 | if(screen_init(hSession)) |
327 | return NULL; | 327 | return NULL; |