charsets.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 (const 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 (const 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 (const char input_char);
  54. GString *str_convert_to_input (char *str);
  55. GString *str_nconvert_to_input (char *str, int len);
  56. GString *str_convert_to_display (char *str);
  57. GString *str_nconvert_to_display (char *str, int len);
  58. /*** inline functions ****************************************************************************/
  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. static inline int
  68. convert_from_input_c (int c)
  69. {
  70. if (c < 0 || c >= 256)
  71. return c;
  72. return (int) conv_input[c];
  73. }
  74. #endif /* MC__CHARSETS_H */