2009-02-05 21:28:18 +03:00
|
|
|
/** \file charsets.h
|
|
|
|
* \brief Header: Text conversion from one charset to another
|
|
|
|
*/
|
|
|
|
|
2010-11-09 14:02:28 +03:00
|
|
|
#ifndef MC__CHARSETS_H
|
|
|
|
#define MC__CHARSETS_H
|
2001-05-31 05:27:20 +04:00
|
|
|
|
2010-09-16 13:39:29 +04:00
|
|
|
#include "lib/global.h"
|
|
|
|
|
2002-10-31 02:14:26 +03:00
|
|
|
|
2010-11-09 14:02:28 +03:00
|
|
|
/*** typedefs(not structures) and defined constants **********************************************/
|
|
|
|
|
|
|
|
#ifdef HAVE_CHARSET
|
2001-05-31 05:27:20 +04:00
|
|
|
#define UNKNCHAR '\001'
|
2010-11-09 14:02:28 +03:00
|
|
|
#else
|
|
|
|
#define convert_to_display_c(c) (c)
|
|
|
|
#define convert_from_input_c(c) (c)
|
|
|
|
#define convert_to_display(str) do {} while (0)
|
|
|
|
#define convert_from_input(str) do {} while (0)
|
|
|
|
#endif /* HAVE_CHARSET */
|
2001-05-31 05:27:20 +04:00
|
|
|
|
2010-11-09 14:02:28 +03:00
|
|
|
/*** enums ***************************************************************************************/
|
|
|
|
|
|
|
|
/*** structures declarations (and typedefs of structures)*****************************************/
|
|
|
|
#ifdef HAVE_CHARSET
|
2001-05-31 05:27:20 +04:00
|
|
|
|
2010-09-16 13:39:29 +04:00
|
|
|
typedef struct
|
|
|
|
{
|
2004-08-30 14:38:00 +04:00
|
|
|
char *id;
|
|
|
|
char *name;
|
2010-09-16 13:39:29 +04:00
|
|
|
} codepage_desc;
|
2001-05-31 05:27:20 +04:00
|
|
|
|
2010-11-09 14:02:28 +03:00
|
|
|
/*** global variables defined in .c file *********************************************************/
|
|
|
|
|
|
|
|
extern unsigned char conv_displ[256];
|
|
|
|
extern unsigned char conv_input[256];
|
|
|
|
|
2009-04-22 20:20:42 +04:00
|
|
|
extern const char *cp_display;
|
|
|
|
extern const char *cp_source;
|
2010-09-16 13:39:29 +04:00
|
|
|
extern GPtrArray *codepages;
|
2001-05-31 05:27:20 +04:00
|
|
|
|
2010-11-09 14:02:28 +03:00
|
|
|
/*** declarations of public functions ************************************************************/
|
|
|
|
|
2009-04-20 11:30:32 +04:00
|
|
|
const char *get_codepage_id (const int n);
|
2002-10-31 02:14:26 +03:00
|
|
|
int get_codepage_index (const char *id);
|
2010-09-16 13:39:29 +04:00
|
|
|
void load_codepages_list (void);
|
2002-10-31 02:14:26 +03:00
|
|
|
void free_codepages_list (void);
|
2010-09-13 13:32:27 +04:00
|
|
|
gboolean is_supported_encoding (const char *encoding);
|
2010-03-31 14:02:45 +04:00
|
|
|
char *init_translation_table (int cpsource, int cpdisplay);
|
2002-10-31 02:14:26 +03:00
|
|
|
void convert_to_display (char *str);
|
|
|
|
void convert_from_input (char *str);
|
|
|
|
void convert_string (unsigned char *str);
|
2010-11-09 14:02:28 +03:00
|
|
|
|
2009-04-17 14:27:59 +04:00
|
|
|
/*
|
|
|
|
* Converter from utf to selected codepage
|
|
|
|
* param str, utf char
|
2011-02-10 18:02:54 +03:00
|
|
|
* return char in needle codepage (by global int mc_global.source_codepage)
|
2010-11-09 14:02:28 +03:00
|
|
|
*/
|
2009-04-17 01:26:08 +04:00
|
|
|
unsigned char convert_from_utf_to_current (const char *str);
|
2010-11-09 14:02:28 +03:00
|
|
|
|
2009-04-17 14:27:59 +04:00
|
|
|
/*
|
|
|
|
* Converter from utf to selected codepage
|
|
|
|
* param input_char, gunichar
|
2011-02-10 18:02:54 +03:00
|
|
|
* return char in needle codepage (by global int mc_global.source_codepage)
|
2010-11-09 14:02:28 +03:00
|
|
|
*/
|
2009-08-13 09:59:31 +04:00
|
|
|
unsigned char convert_from_utf_to_current_c (const int input_char, GIConv conv);
|
2010-11-09 14:02:28 +03:00
|
|
|
|
2009-04-20 00:28:00 +04:00
|
|
|
/*
|
|
|
|
* Converter from selected codepage 8-bit
|
2009-08-13 09:59:31 +04:00
|
|
|
* param char input_char, GIConv converter
|
2009-04-20 00:28:00 +04:00
|
|
|
* return int utf char
|
2010-11-09 14:02:28 +03:00
|
|
|
*/
|
2009-08-13 09:59:31 +04:00
|
|
|
int convert_from_8bit_to_utf_c (const char input_char, GIConv conv);
|
2010-11-09 14:02:28 +03:00
|
|
|
|
2009-04-20 13:08:48 +04:00
|
|
|
/*
|
|
|
|
* Converter from display codepage 8-bit to utf-8
|
2009-08-13 09:59:31 +04:00
|
|
|
* param char input_char, GIConv converter
|
2009-04-20 13:08:48 +04:00
|
|
|
* return int utf char
|
2010-11-09 14:02:28 +03:00
|
|
|
*/
|
2009-04-20 13:08:48 +04:00
|
|
|
int convert_from_8bit_to_utf_c2 (const char input_char);
|
2009-04-20 00:28:00 +04:00
|
|
|
|
2009-04-21 15:19:42 +04:00
|
|
|
GString *str_convert_to_input (char *str);
|
|
|
|
GString *str_nconvert_to_input (char *str, int len);
|
|
|
|
|
2009-04-20 11:30:32 +04:00
|
|
|
GString *str_convert_to_display (char *str);
|
2009-04-21 15:19:42 +04:00
|
|
|
GString *str_nconvert_to_display (char *str, int len);
|
2002-10-31 02:14:26 +03:00
|
|
|
|
2010-11-09 14:02:28 +03:00
|
|
|
/*** inline functions ****************************************************************************/
|
|
|
|
|
2002-10-31 02:42:21 +03:00
|
|
|
/* Convert single characters */
|
|
|
|
static inline int
|
|
|
|
convert_to_display_c (int c)
|
|
|
|
{
|
|
|
|
if (c < 0 || c >= 256)
|
2010-11-09 14:02:28 +03:00
|
|
|
return c;
|
2002-10-31 02:42:21 +03:00
|
|
|
return conv_displ[c];
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
convert_from_input_c (int c)
|
|
|
|
{
|
|
|
|
if (c < 0 || c >= 256)
|
2010-11-09 14:02:28 +03:00
|
|
|
return c;
|
2002-10-31 02:42:21 +03:00
|
|
|
return conv_input[c];
|
|
|
|
}
|
|
|
|
|
2002-10-31 02:14:26 +03:00
|
|
|
#endif /* HAVE_CHARSET */
|
2001-05-31 05:27:20 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
#endif /* MC__CHARSETS_H */
|