charsets.h 2.9 KB

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