geany/src/encodings.h

210 lines
5.6 KiB
C
Raw Normal View History

/*
* encodings.h - this file is part of Geany, a fast and lightweight IDE
*
2012-06-18 01:13:05 +02:00
* Copyright 2005-2012 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
* Copyright 2006-2012 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
2012-08-24 19:25:57 +02:00
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/**
* @file encodings.h
* Encoding conversion and Byte Order Mark (BOM) handling.
**/
/*
* Modified by the gedit Team, 2002. See the gedit AUTHORS file for a
* list of people on the gedit Team.
* See the gedit ChangeLog files for a list of changes.
*/
/* Stolen from anjuta */
#ifndef GEANY_ENCODINGS_H
#define GEANY_ENCODINGS_H 1
Include what you use This is a mega-commit - because most of it had to be done in one go otherwise some commits would fail to compile - that attempts to fix a few problems with Geany's includes as well as various other related cleanups. After this change it's easier to use includes and there's little worry about which order things are included in or who includes what. Overview of changes: * Include config.h at the start of each source file if HAVE_CONFIG_H is defined (and never in headers). * Go through each source file and make the includes section generally like this: - Always config.h first as above - Then if the file has a header with the same name, include that - Then include in alphabetical order each other internal/geany header. - Then include standard headers - Then include non-standard system headers - Then include GLib/GTK+ related stuff * Doing as above makes it easier to find implicit header include dependencies and it exposed quite a few weird problems with includes or forward declarations, fix those. * Make geany.h contain not much besides some defines. - Add a little header file "app.h" for GeanyApp and move it there - Move "app" global to new "app.h" file - Move "ignore_callback" global to "callbacks.h" - Move "geany_object" global to "geanyobject.h" * Add an include in "geany.h" for "app.h" since GeanyApp used to be defined there and some plugins included this header to access GeanyApp. * Include "gtkcompat.h" everywhere instead of gtk/gtk.h so that everywhere sees the same definitions (not a problem in practice AFAIK so this could be changed back if better that way. * Remove forward declarations from previous commits as some people apparently consider this bad style, despite that it reduces inter- header dependencies. TODO: * As always, to test on win32 * As always, to test with not Autotools * Test plugins better, both builtin and geany-plugins, likely API/ABI bump * Test with various defines/flags that may change what is included * win32.[ch] not really touched since I couldn't test
2014-05-18 17:31:51 -07:00
#include "gtkcompat.h"
G_BEGIN_DECLS
typedef enum
{
NONE = 0,
WESTEUROPEAN,
EASTEUROPEAN,
EASTASIAN,
ASIAN,
MIDDLEEASTERN,
UNICODE,
GEANY_ENCODING_GROUPS_MAX
} GeanyEncodingGroup;
/*
* The original versions of the following tables are taken from profterm
*
* Copyright (C) 2002 Red Hat, Inc.
*/
/**
* @enum GeanyEncodingIndex
* List of known and supported encodings.
**/
typedef enum
{
GEANY_ENCODING_ISO_8859_1,
GEANY_ENCODING_ISO_8859_2,
GEANY_ENCODING_ISO_8859_3,
GEANY_ENCODING_ISO_8859_4,
GEANY_ENCODING_ISO_8859_5,
GEANY_ENCODING_ISO_8859_6,
GEANY_ENCODING_ISO_8859_7,
GEANY_ENCODING_ISO_8859_8,
GEANY_ENCODING_ISO_8859_8_I,
GEANY_ENCODING_ISO_8859_9,
GEANY_ENCODING_ISO_8859_10,
GEANY_ENCODING_ISO_8859_13,
GEANY_ENCODING_ISO_8859_14,
GEANY_ENCODING_ISO_8859_15,
GEANY_ENCODING_ISO_8859_16,
GEANY_ENCODING_UTF_7,
GEANY_ENCODING_UTF_8,
GEANY_ENCODING_UTF_16LE,
GEANY_ENCODING_UTF_16BE,
GEANY_ENCODING_UCS_2LE,
GEANY_ENCODING_UCS_2BE,
GEANY_ENCODING_UTF_32LE,
GEANY_ENCODING_UTF_32BE,
GEANY_ENCODING_ARMSCII_8,
GEANY_ENCODING_BIG5,
GEANY_ENCODING_BIG5_HKSCS,
GEANY_ENCODING_CP_866,
GEANY_ENCODING_EUC_JP,
GEANY_ENCODING_EUC_KR,
GEANY_ENCODING_EUC_TW,
GEANY_ENCODING_GB18030,
GEANY_ENCODING_GB2312,
GEANY_ENCODING_GBK,
GEANY_ENCODING_GEOSTD8,
GEANY_ENCODING_HZ,
GEANY_ENCODING_IBM_850,
GEANY_ENCODING_IBM_852,
GEANY_ENCODING_IBM_855,
GEANY_ENCODING_IBM_857,
GEANY_ENCODING_IBM_862,
GEANY_ENCODING_IBM_864,
GEANY_ENCODING_ISO_2022_JP,
GEANY_ENCODING_ISO_2022_KR,
GEANY_ENCODING_ISO_IR_111,
GEANY_ENCODING_JOHAB,
GEANY_ENCODING_KOI8_R,
GEANY_ENCODING_KOI8_U,
GEANY_ENCODING_SHIFT_JIS,
GEANY_ENCODING_TCVN,
GEANY_ENCODING_TIS_620,
GEANY_ENCODING_UHC,
GEANY_ENCODING_VISCII,
GEANY_ENCODING_WINDOWS_1250,
GEANY_ENCODING_WINDOWS_1251,
GEANY_ENCODING_WINDOWS_1252,
GEANY_ENCODING_WINDOWS_1253,
GEANY_ENCODING_WINDOWS_1254,
GEANY_ENCODING_WINDOWS_1255,
GEANY_ENCODING_WINDOWS_1256,
GEANY_ENCODING_WINDOWS_1257,
GEANY_ENCODING_WINDOWS_1258,
GEANY_ENCODING_NONE,
GEANY_ENCODING_CP_932,
GEANY_ENCODINGS_MAX
} GeanyEncodingIndex;
/** Structure to represent an encoding to be used in Geany. */
typedef struct
{
/** The index of the encoding, must be one of GeanyEncodingIndex. */
gint idx;
/** Internally used member for grouping */
gint order;
/** Internally used member for grouping */
GeanyEncodingGroup group;
/** String representation of the encoding, e.g. "ISO-8859-3" */
const gchar *charset;
/** Translatable and descriptive name of the encoding, e.g. "South European" */
const gchar *name;
} GeanyEncoding;
gchar *encodings_convert_to_utf8(const gchar *buffer, gssize size, gchar **used_encoding);
/* Converts a string from the given charset to UTF-8.
* If fast is set, no further checks are performed. */
gchar *encodings_convert_to_utf8_from_charset(const gchar *buffer, gssize size,
const gchar *charset, gboolean fast);
const gchar* encodings_get_charset_from_index(gint idx);
#ifdef GEANY_PRIVATE
const GeanyEncoding* encodings_get_from_charset(const gchar *charset);
const GeanyEncoding* encodings_get_from_index(gint idx);
gchar* encodings_to_string(const GeanyEncoding* enc);
const gchar* encodings_get_charset(const GeanyEncoding* enc);
void encodings_select_radio_item(const gchar *charset);
void encodings_init(void);
void encodings_finalize(void);
GtkTreeStore *encodings_encoding_store_new(gboolean has_detect);
gint encodings_encoding_store_get_encoding(GtkTreeStore *store, GtkTreeIter *iter);
gboolean encodings_encoding_store_get_iter(GtkTreeStore *store, GtkTreeIter *iter, gint enc);
void encodings_encoding_store_cell_data_func(GtkCellLayout *cell_layout, GtkCellRenderer *cell,
GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data);
gboolean encodings_is_unicode_charset(const gchar *string);
gboolean encodings_convert_to_utf8_auto(gchar **buf, gsize *size, const gchar *forced_enc,
gchar **used_encoding, gboolean *has_bom, gboolean *partial);
extern GeanyEncoding encodings[GEANY_ENCODINGS_MAX];
GeanyEncodingIndex encodings_scan_unicode_bom(const gchar *string, gsize len, guint *bom_len);
GeanyEncodingIndex encodings_get_idx_from_charset(const gchar *charset);
#endif /* GEANY_PRIVATE */
G_END_DECLS
#endif /* GEANY_ENCODINGS_H */