Commit e36c57a12113745392c584787df041b74b45b378
1 parent
c6cfe226
Exists in
master
and in
3 other branches
Implementando remapeamento de caracteres por arquivo .xml
Showing
2 changed files
with
35 additions
and
27 deletions
Show diff stats
charset.c
... | ... | @@ -212,6 +212,15 @@ typedef struct _info |
212 | 212 | static const remap charset[] = |
213 | 213 | { |
214 | 214 | { |
215 | + "us", | |
216 | + LIB3270_DEFAULT_CGEN | LIB3270_DEFAULT_CSET, | |
217 | + (const unsigned short const []) | |
218 | + { | |
219 | + 0x0000, 0x0000 | |
220 | + } | |
221 | + }, | |
222 | + | |
223 | + { | |
215 | 224 | "bracket", |
216 | 225 | LIB3270_DEFAULT_CGEN|LIB3270_DEFAULT_CSET, |
217 | 226 | (const unsigned short const []) |
... | ... | @@ -255,31 +264,16 @@ static void copy_charset(const unsigned short *from, unsigned short *to) |
255 | 264 | to[f+UT_OFFSET] = from[f]; |
256 | 265 | } |
257 | 266 | |
258 | -LIB3270_EXPORT void lib3270_remap(H3270 *hSession,const char *host, const char *display, unsigned long cgcsgid, const unsigned short *chr) | |
259 | -{ | |
260 | - int c; | |
261 | - | |
262 | - hSession->charset.host = host; | |
263 | - hSession->charset.display = display; | |
264 | - hSession->charset.cgcsgid = cgcsgid; | |
265 | - | |
266 | - for(c=0;chr[c];c+=2) | |
267 | - { | |
268 | - lib3270_remap_char(hSession,chr[c],chr[c+1], BOTH, 0); | |
269 | - } | |
270 | - | |
271 | -} | |
272 | - | |
273 | -LIB3270_EXPORT int lib3270_set_host_charset(H3270 *hSession, const char *name) | |
267 | +LIB3270_EXPORT void lib3270_reset_charset(H3270 *hSession, const char * host, const char * display, unsigned long cgcsgid) | |
274 | 268 | { |
275 | 269 | int f; |
276 | 270 | |
277 | - hSession->charset.host = "us"; | |
278 | - hSession->charset.display = "ISO-8859-1"; | |
279 | - hSession->charset.cgcsgid = LIB3270_DEFAULT_CGEN | LIB3270_DEFAULT_CSET; // 0x02b90025 | |
271 | + #define replace_pointer(x,v) if(x) { lib3270_free(x); }; x = strdup(v) | |
280 | 272 | |
281 | -// lib3270_write_log(hSession,"charset","host.charset=%s display.charset=%s", | |
282 | -// hSession->charset.host,hSession->charset.display); | |
273 | + replace_pointer(hSession->charset.host, host); | |
274 | + replace_pointer(hSession->charset.display,display); | |
275 | + | |
276 | + hSession->charset.cgcsgid = cgcsgid; | |
283 | 277 | |
284 | 278 | memcpy(hSession->charset.ebc2asc, ebc2asc0, sizeof(hSession->charset.ebc2asc)); |
285 | 279 | memcpy(hSession->charset.asc2ebc, asc2ebc0, sizeof(hSession->charset.asc2ebc)); |
... | ... | @@ -296,7 +290,19 @@ LIB3270_EXPORT int lib3270_set_host_charset(H3270 *hSession, const char *name) |
296 | 290 | #endif |
297 | 291 | */ |
298 | 292 | |
299 | - if(!(name && strcasecmp(name,hSession->charset.host))) | |
293 | +} | |
294 | + | |
295 | +LIB3270_EXPORT int lib3270_set_host_charset(H3270 *hSession, const char *name) | |
296 | +{ | |
297 | + int f; | |
298 | + | |
299 | + if(!name) | |
300 | + { | |
301 | + lib3270_reset_charset(hSession,"us","ISO-8859-1", LIB3270_DEFAULT_CGEN | LIB3270_DEFAULT_CSET); | |
302 | + return 0; | |
303 | + } | |
304 | + | |
305 | + if(hSession->charset.host && !strcasecmp(name,hSession->charset.host)) | |
300 | 306 | return 0; |
301 | 307 | |
302 | 308 | for(f=0;charset[f].name != NULL;f++) |
... | ... | @@ -304,16 +310,15 @@ LIB3270_EXPORT int lib3270_set_host_charset(H3270 *hSession, const char *name) |
304 | 310 | if(!strcasecmp(name,charset[f].name)) |
305 | 311 | { |
306 | 312 | // Found required charset |
307 | - lib3270_remap(hSession,charset[f].name,"ISO-8859-1",charset[f].cgcsgid,charset[f].chr); | |
308 | - /* | |
309 | 313 | int c; |
310 | 314 | |
311 | - hSession->charset.host = charset[f].name; | |
312 | - hSession->charset.cgcsgid = charset[f].cgcsgid; | |
315 | + debug("%s: %s -> %s",__FUNCTION__,hSession->charset.host,charset[f].name); | |
316 | + | |
317 | + lib3270_reset_charset(hSession,charset[f].name,"ISO-8859-1", charset[f].cgcsgid); | |
313 | 318 | |
314 | 319 | for(c=0;charset[f].chr[c];c+=2) |
315 | 320 | lib3270_remap_char(hSession,charset[f].chr[c],charset[f].chr[c+1], BOTH, 0); |
316 | - */ | |
321 | + | |
317 | 322 | return 0; |
318 | 323 | } |
319 | 324 | } | ... | ... |
session.c
... | ... | @@ -103,6 +103,9 @@ void lib3270_session_free(H3270 *h) |
103 | 103 | release_pointer(h->host.srvc); |
104 | 104 | release_pointer(h->host.qualified); |
105 | 105 | |
106 | + release_pointer(h->charset.host); | |
107 | + release_pointer(h->charset.display); | |
108 | + | |
106 | 109 | trace("Releasing session %p",h); |
107 | 110 | lib3270_free(h); |
108 | 111 | ... | ... |