Commit 9186a206be90f86999a3883b123c40b87f41a5ed

Authored by Perry Werneck
1 parent 4ee125ba

Moving charset method to main library.

src/core/charset.c
... ... @@ -29,9 +29,10 @@
29 29 *
30 30 */
31 31  
32   -/*
33   - * charset.c
34   - * This module handles character sets.
  32 +/**
  33 + * @file charset.c
  34 + *
  35 + * @brief This module handles character sets.
35 36 */
36 37  
37 38 #include <lib3270-internals.h>
... ... @@ -268,7 +269,6 @@ LIB3270_EXPORT int lib3270_set_host_charset(H3270 *hSession, const char *name)
268 269  
269 270 }
270 271  
271   -
272 272 LIB3270_EXPORT const char * lib3270_get_default_charset(void)
273 273 {
274 274 return "ISO-8859-1";
... ... @@ -400,7 +400,9 @@ LIB3270_EXPORT const char * lib3270_ebc2asc(H3270 *hSession, unsigned char *buff
400 400 }
401 401  
402 402  
403   -// Process a single character definition.
  403 +///
  404 +/// @brief Process a single character definition.
  405 +///
404 406 LIB3270_EXPORT void lib3270_remap_char(H3270 *hSession, unsigned short ebc, unsigned short iso, lib3270_remap_scope scope, unsigned char one_way)
405 407 {
406 408 // unsigned char cg;
... ... @@ -431,5 +433,253 @@ LIB3270_EXPORT void lib3270_remap_char(H3270 *hSession, unsigned short ebc, unsi
431 433 }
432 434 }
433 435  
  436 +LIB3270_EXPORT unsigned short lib3270_translate_char(const char *id)
  437 +{
  438 +
  439 + static const struct
  440 + {
  441 + const char * name;
  442 + unsigned short keysym;
  443 + }
  444 + latin[] =
  445 + {
  446 + { "space", XK_space },
  447 + { "exclam", XK_exclam },
  448 + { "quotedbl", XK_quotedbl },
  449 + { "numbersign", XK_numbersign },
  450 + { "dollar", XK_dollar },
  451 + { "percent", XK_percent },
  452 + { "ampersand", XK_ampersand },
  453 + { "apostrophe", XK_apostrophe },
  454 + { "quoteright", XK_quoteright },
  455 + { "parenleft", XK_parenleft },
  456 + { "parenright", XK_parenright },
  457 + { "asterisk", XK_asterisk },
  458 + { "plus", XK_plus },
  459 + { "comma", XK_comma },
  460 + { "minus", XK_minus },
  461 + { "period", XK_period },
  462 + { "slash", XK_slash },
  463 + { "0", XK_0 },
  464 + { "1", XK_1 },
  465 + { "2", XK_2 },
  466 + { "3", XK_3 },
  467 + { "4", XK_4 },
  468 + { "5", XK_5 },
  469 + { "6", XK_6 },
  470 + { "7", XK_7 },
  471 + { "8", XK_8 },
  472 + { "9", XK_9 },
  473 + { "colon", XK_colon },
  474 + { "semicolon", XK_semicolon },
  475 + { "less", XK_less },
  476 + { "equal", XK_equal },
  477 + { "greater", XK_greater },
  478 + { "question", XK_question },
  479 + { "at", XK_at },
  480 + { "A", XK_A },
  481 + { "B", XK_B },
  482 + { "C", XK_C },
  483 + { "D", XK_D },
  484 + { "E", XK_E },
  485 + { "F", XK_F },
  486 + { "G", XK_G },
  487 + { "H", XK_H },
  488 + { "I", XK_I },
  489 + { "J", XK_J },
  490 + { "K", XK_K },
  491 + { "L", XK_L },
  492 + { "M", XK_M },
  493 + { "N", XK_N },
  494 + { "O", XK_O },
  495 + { "P", XK_P },
  496 + { "Q", XK_Q },
  497 + { "R", XK_R },
  498 + { "S", XK_S },
  499 + { "T", XK_T },
  500 + { "U", XK_U },
  501 + { "V", XK_V },
  502 + { "W", XK_W },
  503 + { "X", XK_X },
  504 + { "Y", XK_Y },
  505 + { "Z", XK_Z },
  506 + { "bracketleft", XK_bracketleft },
  507 + { "backslash", XK_backslash },
  508 + { "bracketright", XK_bracketright },
  509 + { "asciicircum", XK_asciicircum },
  510 + { "underscore", XK_underscore },
  511 + { "grave", XK_grave },
  512 + { "quoteleft", XK_quoteleft },
  513 + { "a", XK_a },
  514 + { "b", XK_b },
  515 + { "c", XK_c },
  516 + { "d", XK_d },
  517 + { "e", XK_e },
  518 + { "f", XK_f },
  519 + { "g", XK_g },
  520 + { "h", XK_h },
  521 + { "i", XK_i },
  522 + { "j", XK_j },
  523 + { "k", XK_k },
  524 + { "l", XK_l },
  525 + { "m", XK_m },
  526 + { "n", XK_n },
  527 + { "o", XK_o },
  528 + { "p", XK_p },
  529 + { "q", XK_q },
  530 + { "r", XK_r },
  531 + { "s", XK_s },
  532 + { "t", XK_t },
  533 + { "u", XK_u },
  534 + { "v", XK_v },
  535 + { "w", XK_w },
  536 + { "x", XK_x },
  537 + { "y", XK_y },
  538 + { "z", XK_z },
  539 + { "braceleft", XK_braceleft },
  540 + { "bar", XK_bar },
  541 + { "braceright", XK_braceright },
  542 + { "asciitilde", XK_asciitilde },
  543 + { "nobreakspace", XK_nobreakspace },
  544 + { "exclamdown", XK_exclamdown },
  545 + { "cent", XK_cent },
  546 + { "sterling", XK_sterling },
  547 + { "currency", XK_currency },
  548 + { "yen", XK_yen },
  549 + { "brokenbar", XK_brokenbar },
  550 + { "section", XK_section },
  551 + { "diaeresis", XK_diaeresis },
  552 + { "copyright", XK_copyright },
  553 + { "ordfeminine", XK_ordfeminine },
  554 + { "guillemotleft", XK_guillemotleft },
  555 + { "notsign", XK_notsign },
  556 + { "hyphen", XK_hyphen },
  557 + { "registered", XK_registered },
  558 + { "macron", XK_macron },
  559 + { "degree", XK_degree },
  560 + { "plusminus", XK_plusminus },
  561 + { "twosuperior", XK_twosuperior },
  562 + { "threesuperior", XK_threesuperior },
  563 + { "acute", XK_acute },
  564 + { "mu", XK_mu },
  565 + { "paragraph", XK_paragraph },
  566 + { "periodcentered", XK_periodcentered },
  567 + { "cedilla", XK_cedilla },
  568 + { "onesuperior", XK_onesuperior },
  569 + { "masculine", XK_masculine },
  570 + { "guillemotright", XK_guillemotright },
  571 + { "onequarter", XK_onequarter },
  572 + { "onehalf", XK_onehalf },
  573 + { "threequarters", XK_threequarters },
  574 + { "questiondown", XK_questiondown },
  575 + { "Agrave", XK_Agrave },
  576 + { "Aacute", XK_Aacute },
  577 + { "Acircumflex", XK_Acircumflex },
  578 + { "Atilde", XK_Atilde },
  579 + { "Adiaeresis", XK_Adiaeresis },
  580 + { "Aring", XK_Aring },
  581 + { "AE", XK_AE },
  582 + { "Ccedilla", XK_Ccedilla },
  583 + { "Egrave", XK_Egrave },
  584 + { "Eacute", XK_Eacute },
  585 + { "Ecircumflex", XK_Ecircumflex },
  586 + { "Ediaeresis", XK_Ediaeresis },
  587 + { "Igrave", XK_Igrave },
  588 + { "Iacute", XK_Iacute },
  589 + { "Icircumflex", XK_Icircumflex },
  590 + { "Idiaeresis", XK_Idiaeresis },
  591 + { "ETH", XK_ETH },
  592 + { "Eth", XK_Eth },
  593 + { "Ntilde", XK_Ntilde },
  594 + { "Ograve", XK_Ograve },
  595 + { "Oacute", XK_Oacute },
  596 + { "Ocircumflex", XK_Ocircumflex },
  597 + { "Otilde", XK_Otilde },
  598 + { "Odiaeresis", XK_Odiaeresis },
  599 + { "multiply", XK_multiply },
  600 + { "Ooblique", XK_Ooblique },
  601 + { "Ugrave", XK_Ugrave },
  602 + { "Uacute", XK_Uacute },
  603 + { "Ucircumflex", XK_Ucircumflex },
  604 + { "Udiaeresis", XK_Udiaeresis },
  605 + { "Yacute", XK_Yacute },
  606 + { "THORN", XK_THORN },
  607 + { "Thorn", XK_Thorn },
  608 + { "ssharp", XK_ssharp },
  609 + { "agrave", XK_agrave },
  610 + { "aacute", XK_aacute },
  611 + { "acircumflex", XK_acircumflex },
  612 + { "atilde", XK_atilde },
  613 + { "adiaeresis", XK_adiaeresis },
  614 + { "aring", XK_aring },
  615 + { "ae", XK_ae },
  616 + { "ccedilla", XK_ccedilla },
  617 + { "egrave", XK_egrave },
  618 + { "eacute", XK_eacute },
  619 + { "ecircumflex", XK_ecircumflex },
  620 + { "ediaeresis", XK_ediaeresis },
  621 + { "igrave", XK_igrave },
  622 + { "iacute", XK_iacute },
  623 + { "icircumflex", XK_icircumflex },
  624 + { "idiaeresis", XK_idiaeresis },
  625 + { "eth", XK_eth },
  626 + { "ntilde", XK_ntilde },
  627 + { "ograve", XK_ograve },
  628 + { "oacute", XK_oacute },
  629 + { "ocircumflex", XK_ocircumflex },
  630 + { "otilde", XK_otilde },
  631 + { "odiaeresis", XK_odiaeresis },
  632 + { "division", XK_division },
  633 + { "oslash", XK_oslash },
  634 + { "ugrave", XK_ugrave },
  635 + { "uacute", XK_uacute },
  636 + { "ucircumflex", XK_ucircumflex },
  637 + { "udiaeresis", XK_udiaeresis },
  638 + { "yacute", XK_yacute },
  639 + { "thorn", XK_thorn },
  640 + { "ydiaeresis", XK_ydiaeresis },
  641 +
  642 + // The following are, umm, hacks to allow symbolic names for
  643 + // control codes.
  644 + #if !defined(_WIN32)
  645 + { "BackSpace", 0x08 },
  646 + { "Tab", 0x09 },
  647 + { "Linefeed", 0x0a },
  648 + { "Return", 0x0d },
  649 + { "Escape", 0x1b },
  650 + { "Delete", 0x7f },
  651 + #endif
  652 + };
  653 +
  654 + size_t ix;
  655 +
  656 + if(strncasecmp(id,"0x",2) == 0) {
  657 +
  658 + unsigned int rc = 0;
  659 +
  660 + if(sscanf(id + 2, "%x", &rc) != 1)
  661 + {
  662 + errno = EINVAL;
  663 + return 0;
  664 + }
  665 +
  666 + return (unsigned short) rc;
  667 +
  668 + }
  669 +
  670 + for(ix=0;ix < (sizeof(latin)/sizeof(latin[0])); ix++) {
  671 + if(!strcasecmp(id,latin[ix].name))
  672 + return latin[ix].keysym;
  673 + }
  674 +
  675 + if(strlen(id) != 1)
  676 + {
  677 + errno = EINVAL;
  678 + return 0;
  679 + }
  680 +
  681 + return (unsigned short) *id;
  682 +
  683 +}
434 684  
435 685  
... ...
src/include/lib3270/charset.h
... ... @@ -66,6 +66,14 @@
66 66 LIB3270_EXPORT const char * lib3270_ebc2asc(H3270 *hSession, unsigned char *buffer, int sz);
67 67 LIB3270_EXPORT const char * lib3270_asc2ebc(H3270 *hSession, unsigned char *buffer, int sz);
68 68  
  69 + /**
  70 + * @brief Get character code from string definition.
  71 + *
  72 + * @param id The character definition (id or 0x[code]).
  73 + *
  74 + * @return Character code if ok, 0 if not (sets errno).
  75 + */
  76 + LIB3270_EXPORT unsigned short lib3270_translate_char(const char *id);
69 77  
70 78 #ifdef __cplusplus
71 79 }
... ...