charsets.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /** \file charsets.h
  2. * \brief Header: Text conversion from one charset to another
  3. */
  4. #ifndef MC__CHARSETS_H
  5. #define MC__CHARSETS_H
  6. /*** typedefs(not structures) and defined constants **********************************************/
  7. /*** enums ***************************************************************************************/
  8. /*** structures declarations (and typedefs of structures)*****************************************/
  9. typedef struct
  10. {
  11. char *id;
  12. char *name;
  13. } codepage_desc;
  14. /*** global variables defined in .c file *********************************************************/
  15. extern unsigned char conv_displ[256];
  16. extern unsigned char conv_input[256];
  17. extern const char *cp_display;
  18. extern const char *cp_source;
  19. extern GPtrArray *codepages;
  20. /*** declarations of public functions ************************************************************/
  21. const char *get_codepage_id (const int n);
  22. int get_codepage_index (const char *id);
  23. void load_codepages_list (void);
  24. void free_codepages_list (void);
  25. gboolean is_supported_encoding (const char *encoding);
  26. char *init_translation_table (int cpsource, int cpdisplay);
  27. void convert_to_display (char *str);
  28. void convert_from_input (char *str);
  29. void convert_string (unsigned char *str);
  30. /*
  31. * Converter from utf to selected codepage
  32. * param str, utf char
  33. * return char in needle codepage (by global int mc_global.source_codepage)
  34. */
  35. unsigned char convert_from_utf_to_current (const char *str);
  36. /*
  37. * Converter from utf to selected codepage
  38. * param input_char, gunichar
  39. * return char in needle codepage (by global int mc_global.source_codepage)
  40. */
  41. unsigned char convert_from_utf_to_current_c (int input_char, GIConv conv);
  42. /*
  43. * Converter from selected codepage 8-bit
  44. * param char input_char, GIConv converter
  45. * return int utf char
  46. */
  47. int convert_from_8bit_to_utf_c (char input_char, GIConv conv);
  48. /*
  49. * Converter from display codepage 8-bit to utf-8
  50. * param char input_char, GIConv converter
  51. * return int utf char
  52. */
  53. int convert_from_8bit_to_utf_c2 (char input_char);
  54. GString *str_nconvert_to_input (const char *str, int len);
  55. GString *str_nconvert_to_display (const char *str, int len);
  56. /* --------------------------------------------------------------------------------------------- */
  57. /*** inline functions ****************************************************************************/
  58. /* --------------------------------------------------------------------------------------------- */
  59. /* Convert single characters */
  60. static inline int
  61. convert_to_display_c (int c)
  62. {
  63. if (c < 0 || c >= 256)
  64. return c;
  65. return (int) conv_displ[c];
  66. }
  67. /* --------------------------------------------------------------------------------------------- */
  68. static inline int
  69. convert_from_input_c (int c)
  70. {
  71. if (c < 0 || c >= 256)
  72. return c;
  73. return (int) conv_input[c];
  74. }
  75. /* --------------------------------------------------------------------------------------------- */
  76. static inline GString *
  77. str_convert_to_input (const char *str)
  78. {
  79. return str_nconvert_to_input (str, -1);
  80. }
  81. /* --------------------------------------------------------------------------------------------- */
  82. static inline GString *
  83. str_convert_to_display (const char *str)
  84. {
  85. return str_nconvert_to_display (str, -1);
  86. }
  87. /* --------------------------------------------------------------------------------------------- */
  88. #endif /* MC__CHARSETS_H */