From e7fb3526f3645d2fffed77daebb245c9355b1990 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Mon, 30 Apr 2012 15:52:39 +0400 Subject: [PATCH] Core, mceditor, mcviewer and mcdiffviewer code tweak and cleanup ...in case of build with --disable-charset option. Signed-off-by: Andrew Borodin --- lib/charsets.c | 6 +-- lib/charsets.h | 15 ------- lib/search/glob.c | 2 - lib/search/hex.c | 2 - lib/search/lib.c | 4 +- lib/search/normal.c | 2 - lib/search/regex.c | 2 - lib/search/search.c | 3 +- lib/utilunix.c | 2 + src/diffviewer/search.c | 2 + src/diffviewer/ydiff.c | 16 +++++--- src/editor/editcmd.c | 6 ++- src/editor/editcmd_dialogs.c | 2 + src/editor/editdraw.c | 5 ++- src/editor/editkeys.c | 98 ++++++++++++++++++++------------------------ src/filemanager/ext.c | 4 ++ src/filemanager/panel.c | 2 + src/selcodepage.c | 4 -- src/viewer/actions_cmd.c | 4 ++ src/viewer/dialogs.c | 2 + src/viewer/hex.c | 12 ++++-- src/viewer/lib.c | 4 ++ src/viewer/mcviewer.c | 1 - src/viewer/nroff.c | 17 +++----- src/viewer/plain.c | 5 ++- 25 files changed, 111 insertions(+), 111 deletions(-) diff --git a/lib/charsets.c b/lib/charsets.c index 2ad5bf7d4..f7770903d 100644 --- a/lib/charsets.c +++ b/lib/charsets.c @@ -29,8 +29,6 @@ #include -#ifdef HAVE_CHARSET - #include #include #include @@ -52,6 +50,8 @@ const char *cp_source = NULL; /*** file scope macro definitions ****************************************************************/ +#define UNKNCHAR '\001' + #define OTHER_8BIT "Other_8_bit" /* @@ -571,5 +571,3 @@ convert_from_8bit_to_utf_c2 (const char input_char) } /* --------------------------------------------------------------------------------------------- */ - -#endif /* HAVE_CHARSET */ diff --git a/lib/charsets.h b/lib/charsets.h index 060ec0b3d..2b95d8ff1 100644 --- a/lib/charsets.h +++ b/lib/charsets.h @@ -5,24 +5,11 @@ #ifndef MC__CHARSETS_H #define MC__CHARSETS_H -#include "lib/global.h" - - /*** typedefs(not structures) and defined constants **********************************************/ -#ifdef HAVE_CHARSET -#define UNKNCHAR '\001' -#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 */ - /*** enums ***************************************************************************************/ /*** structures declarations (and typedefs of structures)*****************************************/ -#ifdef HAVE_CHARSET typedef struct { @@ -104,6 +91,4 @@ convert_from_input_c (int c) return (int) conv_input[c]; } -#endif /* HAVE_CHARSET */ - #endif /* MC__CHARSETS_H */ diff --git a/lib/search/glob.c b/lib/search/glob.c index 3a929d2e7..dd28c52b8 100644 --- a/lib/search/glob.c +++ b/lib/search/glob.c @@ -31,8 +31,6 @@ #include "lib/search.h" #include "lib/strescape.h" -#include "lib/charsets.h" - #include "internal.h" /*** global variables ****************************************************************************/ diff --git a/lib/search/hex.c b/lib/search/hex.c index 1f9fd5fc1..5c67a83c5 100644 --- a/lib/search/hex.c +++ b/lib/search/hex.c @@ -33,8 +33,6 @@ #include "lib/search.h" #include "lib/strescape.h" -#include "lib/charsets.h" - #include "internal.h" /*** global variables ****************************************************************************/ diff --git a/lib/search/lib.c b/lib/search/lib.c index c19834a82..0ecbff93e 100644 --- a/lib/search/lib.c +++ b/lib/search/lib.c @@ -32,9 +32,11 @@ #include "lib/global.h" #include "lib/strutil.h" #include "lib/search.h" +#ifdef HAVE_CHARSET +#include "lib/charsets.h" +#endif #include "internal.h" -#include "lib/charsets.h" /*** global variables ****************************************************************************/ diff --git a/lib/search/normal.c b/lib/search/normal.c index 7be4c809e..00f87c855 100644 --- a/lib/search/normal.c +++ b/lib/search/normal.c @@ -30,8 +30,6 @@ #include "lib/strutil.h" #include "lib/search.h" -#include "lib/charsets.h" - #include "internal.h" /*** global variables ****************************************************************************/ diff --git a/lib/search/regex.c b/lib/search/regex.c index fdff4ab00..f5e1fc762 100644 --- a/lib/search/regex.c +++ b/lib/search/regex.c @@ -34,8 +34,6 @@ #include "lib/search.h" #include "lib/strescape.h" -#include "lib/charsets.h" - #include "internal.h" /*** global variables ****************************************************************************/ diff --git a/lib/search/search.c b/lib/search/search.c index 853396722..42c8e45d2 100644 --- a/lib/search/search.c +++ b/lib/search/search.c @@ -32,8 +32,9 @@ #include "lib/global.h" #include "lib/strutil.h" #include "lib/search.h" - +#ifdef HAVE_CHARSET #include "lib/charsets.h" +#endif #include "internal.h" diff --git a/lib/utilunix.c b/lib/utilunix.c index 0ea2eb57f..382161057 100644 --- a/lib/utilunix.c +++ b/lib/utilunix.c @@ -550,7 +550,9 @@ custom_canonicalize_pathname (char *path, CANON_PATH_FLAGS flags) if (flags & CANON_PATH_REMDOUBLEDOTS) { +#ifdef HAVE_CHARSET const size_t enc_prefix_len = strlen (VFS_ENCODING_PREFIX); +#endif /* HAVE_CHARSET */ /* Collapse "/.." with the previous part of path */ p = lpath; diff --git a/src/diffviewer/search.c b/src/diffviewer/search.c index 00573a87f..40e10b4e3 100644 --- a/src/diffviewer/search.c +++ b/src/diffviewer/search.c @@ -31,7 +31,9 @@ #include "lib/strutil.h" #include "lib/tty/key.h" #include "lib/widget.h" +#ifdef HAVE_CHARSET #include "lib/charsets.h" +#endif #include "src/history.h" diff --git a/src/diffviewer/ydiff.c b/src/diffviewer/ydiff.c index ff87b8ed3..8cd1be7bd 100644 --- a/src/diffviewer/ydiff.c +++ b/src/diffviewer/ydiff.c @@ -43,7 +43,9 @@ #include "lib/util.h" #include "lib/widget.h" #include "lib/strutil.h" +#ifdef HAVE_CHARSET #include "lib/charsets.h" +#endif #include "lib/event.h" /* mc_event_raise() */ #include "src/filemanager/cmd.h" /* do_edit_at_line(), view_other_cmd() */ @@ -52,7 +54,9 @@ #include "src/keybind-defaults.h" #include "src/history.h" +#ifdef HAVE_CHARSET #include "src/selcodepage.h" +#endif #include "ydiff.h" #include "internal.h" @@ -142,16 +146,14 @@ dview_set_codeset (WDiff * dview) /* --------------------------------------------------------------------------------------------- */ +#ifdef HAVE_CHARSET static void dview_select_encoding (WDiff * dview) { -#ifdef HAVE_CHARSET if (do_select_codepage ()) dview_set_codeset (dview); -#else - (void) dview; -#endif } +#endif /* HAVE_CHARSET */ /* --------------------------------------------------------------------------------------------- */ @@ -2602,8 +2604,8 @@ dview_display_file (const WDiff * dview, int ord, int r, int c, int height, int next_ch = convert_from_utf_to_current_c (next_ch, dview->converter); else -#endif next_ch = convert_to_display_c (next_ch); +#endif tty_print_anychar (next_ch); col++; @@ -2678,8 +2680,8 @@ dview_display_file (const WDiff * dview, int ord, int r, int c, int height, int else if (dview->utf8) next_ch = convert_from_utf_to_current_c (next_ch, dview->converter); else -#endif next_ch = convert_to_display_c (next_ch); +#endif tty_print_anychar (next_ch); col++; @@ -3160,7 +3162,9 @@ dview_handle_key (WDiff * dview, int key) { unsigned long command; +#ifdef HAVE_CHARSET key = convert_from_input_c (key); +#endif command = keybind_lookup_keymap_command (diff_map, key); if ((command != CK_IgnoreKey) && (dview_execute_cmd (dview, command) == MSG_HANDLED)) diff --git a/src/editor/editcmd.c b/src/editor/editcmd.c index 045420763..418d8ebd3 100644 --- a/src/editor/editcmd.c +++ b/src/editor/editcmd.c @@ -60,13 +60,17 @@ #include "lib/util.h" /* tilde_expand() */ #include "lib/vfs/vfs.h" #include "lib/widget.h" -#include "lib/charsets.h" #include "lib/event.h" /* mc_event_raise() */ +#ifdef HAVE_CHARSET +#include "lib/charsets.h" +#endif #include "src/history.h" #include "src/setup.h" /* option_tab_spacing */ #include "src/main.h" /* mactos_t */ +#ifdef HAVE_CHARSET #include "src/selcodepage.h" +#endif #include "src/keybind-defaults.h" #include "src/util.h" /* check_for_default() */ #include "src/filemanager/layout.h" /* mc_refresh() */ diff --git a/src/editor/editcmd_dialogs.c b/src/editor/editcmd_dialogs.c index 764cc2f25..1642dacc6 100644 --- a/src/editor/editcmd_dialogs.c +++ b/src/editor/editcmd_dialogs.c @@ -32,7 +32,9 @@ #include "lib/search.h" #include "lib/strutil.h" #include "lib/widget.h" +#ifdef HAVE_CHARSET #include "lib/charsets.h" +#endif #include "src/main.h" #include "src/history.h" diff --git a/src/editor/editdraw.c b/src/editor/editdraw.c index 6b11171ee..22fac69c1 100644 --- a/src/editor/editdraw.c +++ b/src/editor/editdraw.c @@ -48,7 +48,10 @@ #include "lib/skin.h" #include "lib/strutil.h" /* utf string functions */ #include "lib/util.h" /* is_printable() */ +#include "lib/widget.h" +#ifdef HAVE_CHARSET #include "lib/charsets.h" +#endif #include "src/setup.h" /* edit_tab_spacing */ #include "src/main.h" /* macro_index */ @@ -729,8 +732,8 @@ edit_draw_this_line (WEdit * edit, long b, long row, long start_col, long end_co else if (edit->utf8) c = convert_from_utf_to_current_c (c, edit->converter); else -#endif c = convert_to_display_c (c); +#endif /* Caret notation for control characters */ if (c < 32) diff --git a/src/editor/editkeys.c b/src/editor/editkeys.c index d9512909b..45cacec1a 100644 --- a/src/editor/editkeys.c +++ b/src/editor/editkeys.c @@ -47,7 +47,9 @@ #include "lib/tty/key.h" /* KEY_M_SHIFT */ #include "lib/strutil.h" /* str_isutf8 () */ #include "lib/util.h" /* is_printable() */ -#include "lib/charsets.h" /* convert_from_input_c() */ +#ifdef HAVE_CHARSET +#include "lib/charsets.h" +#endif #include "edit-impl.h" #include "editwidget.h" /* WEdit */ @@ -79,12 +81,19 @@ edit_translate_key (WEdit * edit, long x_key, int *cmd, int *ch) { unsigned long command = (unsigned long) CK_InsertChar; int char_for_insertion = -1; - int c; /* an ordinary insertable character */ if (!edit->extmod && x_key < 256) { -#ifdef HAVE_CHARSET +#ifndef HAVE_CHARSET + if (is_printable (x_key)) + { + char_for_insertion = x_key; + goto fin; + } +#else + int c; + if (edit->charpoint >= 4) { edit->charpoint = 0; @@ -100,84 +109,67 @@ edit_translate_key (WEdit * edit, long x_key, int *cmd, int *ch) if (!mc_global.utf8_display) { /* source in 8-bit codeset */ - if (!edit->utf8) + c = convert_from_input_c (x_key); + + if (is_printable (c)) { -#endif /* HAVE_CHARSET */ - c = convert_from_input_c (x_key); - if (is_printable (c)) - { + if (!edit->utf8) char_for_insertion = c; - goto fin; - } -#ifdef HAVE_CHARSET - } - else - { - c = convert_from_input_c (x_key); - if (is_printable (c)) - { + else char_for_insertion = convert_from_8bit_to_utf_c2 ((unsigned char) x_key); - goto fin; - } + goto fin; } - /* UTF-8 locale */ } else { - /* source in UTF-8 codeset */ + /* UTF-8 locale */ + int res; + + res = str_is_valid_char (edit->charbuf, edit->charpoint); + if (res < 0 && res != -2) + { + edit->charpoint = 0; /* broken multibyte char, skip */ + goto fin; + } + if (edit->utf8) { - int res = str_is_valid_char (edit->charbuf, edit->charpoint); + /* source in UTF-8 codeset */ if (res < 0) { - if (res != -2) - { - edit->charpoint = 0; /* broken multibyte char, skip */ - goto fin; - } char_for_insertion = x_key; goto fin; } - else + + edit->charbuf[edit->charpoint] = '\0'; + edit->charpoint = 0; + if (g_unichar_isprint (g_utf8_get_char (edit->charbuf))) { - edit->charbuf[edit->charpoint] = '\0'; - edit->charpoint = 0; - if (g_unichar_isprint (g_utf8_get_char (edit->charbuf))) - { - char_for_insertion = x_key; - goto fin; - } + char_for_insertion = x_key; + goto fin; } - - /* 8-bit source */ } else { - int res = str_is_valid_char (edit->charbuf, edit->charpoint); + /* 8-bit source */ if (res < 0) { - if (res != -2) - { - edit->charpoint = 0; /* broken multibyte char, skip */ - goto fin; - } /* not finised multibyte input (in meddle multibyte utf-8 char) */ goto fin; } - else + + if (g_unichar_isprint (g_utf8_get_char (edit->charbuf))) { - if (g_unichar_isprint (g_utf8_get_char (edit->charbuf))) - { - c = convert_from_utf_to_current (edit->charbuf); - edit->charbuf[0] = '\0'; - edit->charpoint = 0; - char_for_insertion = c; - goto fin; - } - /* unprinteble utf input, skip it */ + c = convert_from_utf_to_current (edit->charbuf); edit->charbuf[0] = '\0'; edit->charpoint = 0; + char_for_insertion = c; + goto fin; } + + /* unprinteble utf input, skip it */ + edit->charbuf[0] = '\0'; + edit->charpoint = 0; } } #endif /* HAVE_CHARSET */ diff --git a/src/filemanager/ext.c b/src/filemanager/ext.c index 4799f62c5..2fba1ad8e 100644 --- a/src/filemanager/ext.c +++ b/src/filemanager/ext.c @@ -46,7 +46,9 @@ #include "lib/util.h" #include "lib/vfs/vfs.h" #include "lib/widget.h" +#ifdef HAVE_CHARSET #include "lib/charsets.h" /* get_codepage_index */ +#endif #include "src/setup.h" /* use_file_to_check_type */ #include "src/execute.h" @@ -601,7 +603,9 @@ regex_check_type (const vfs_path_t * filename_vpath, const char *ptr, int *have_ /* Following variables are valid if *have_type is 1 */ static char content_string[2048]; +#ifdef HAVE_CHARSET static char encoding_id[21]; /* CSISO51INISCYRILLIC -- 20 */ +#endif static size_t content_shift = 0; static int got_data = 0; diff --git a/src/filemanager/panel.c b/src/filemanager/panel.c index f38bc2c35..2d3627be9 100644 --- a/src/filemanager/panel.c +++ b/src/filemanager/panel.c @@ -58,7 +58,9 @@ #include "src/setup.h" /* For loading/saving panel options */ #include "src/execute.h" +#ifdef HAVE_CHARSET #include "src/selcodepage.h" /* select_charset (), SELECT_CHARSET_NO_TRANSLATE */ +#endif #include "src/keybind-defaults.h" /* global_keymap_t */ #include "src/subshell.h" /* do_subshell_chdir() */ diff --git a/src/selcodepage.c b/src/selcodepage.c index d00bfac2d..f26bb4800 100644 --- a/src/selcodepage.c +++ b/src/selcodepage.c @@ -31,8 +31,6 @@ #include -#ifdef HAVE_CHARSET - #include #include @@ -176,5 +174,3 @@ do_select_codepage (void) } /* --------------------------------------------------------------------------------------------- */ - -#endif /* HAVE_CHARSET */ diff --git a/src/viewer/actions_cmd.c b/src/viewer/actions_cmd.c index 5401a9c18..22abc545e 100644 --- a/src/viewer/actions_cmd.c +++ b/src/viewer/actions_cmd.c @@ -55,7 +55,9 @@ #include "lib/lock.h" /* lock_file() */ #include "lib/util.h" #include "lib/widget.h" +#ifdef HAVE_CHARSET #include "lib/charsets.h" +#endif #include "lib/event.h" /* mc_event_raise() */ #include "src/filemanager/layout.h" @@ -513,7 +515,9 @@ mcview_handle_key (mcview_t * view, int key) { unsigned long command; +#ifdef HAVE_CHARSET key = convert_from_input_c (key); +#endif if (view->hex_mode) { diff --git a/src/viewer/dialogs.c b/src/viewer/dialogs.c index ed492616e..59ce4ec99 100644 --- a/src/viewer/dialogs.c +++ b/src/viewer/dialogs.c @@ -43,7 +43,9 @@ #include "lib/search.h" #include "lib/strutil.h" #include "lib/widget.h" +#ifdef HAVE_CHARSET #include "lib/charsets.h" +#endif #include "src/history.h" diff --git a/src/viewer/hex.c b/src/viewer/hex.c index 9b0303dde..2431457fb 100644 --- a/src/viewer/hex.c +++ b/src/viewer/hex.c @@ -47,7 +47,9 @@ #include "lib/lock.h" /* lock_file() and unlock_file() */ #include "lib/util.h" #include "lib/widget.h" +#ifdef HAVE_CHARSET #include "lib/charsets.h" +#endif #include "internal.h" @@ -72,6 +74,7 @@ static const char hex_char[] = "0123456789ABCDEF"; /*** file scope functions ************************************************************************/ /* --------------------------------------------------------------------------------------------- */ +#ifdef HAVE_CHARSET static int utf8_to_int (char *str, int *char_width, gboolean * result) { @@ -114,6 +117,7 @@ utf8_to_int (char *str, int *char_width, gboolean * result) *char_width = width; return ch; } +#endif /* HAVE_CHARSET */ /* --------------------------------------------------------------------------------------------- */ /*** public functions ****************************************************************************/ @@ -139,7 +143,9 @@ mcview_display_hex (mcview_t * view) int c; mark_t boldflag = MARK_NORMAL; struct hexedit_change_node *curr = view->change_list; +#ifdef HAVE_CHARSET int ch = 0; +#endif /* HAVE_CHARSET */ char hex_buff[10]; /* A temporary buffer for sprintf and mvwaddstr */ int bytes; /* Number of bytes already printed on the line */ @@ -202,7 +208,7 @@ mcview_display_hex (mcview_t * view) curr = corr; } } -#endif +#endif /* HAVE_CHARSET */ if (!mcview_get_byte (view, from, &c)) break; @@ -297,7 +303,9 @@ mcview_display_hex (mcview_t * view) else #endif { +#ifdef HAVE_CHARSET c = convert_to_display_c (c); +#endif if (!is_printable (c)) c = '.'; @@ -312,9 +320,7 @@ mcview_display_hex (mcview_t * view) tty_print_anychar (ch); else #endif - { tty_print_char (c); - } } /* Save the cursor position for mcview_place_cursor() */ diff --git a/src/viewer/lib.c b/src/viewer/lib.c index 3a8db2501..42fcaf4b2 100644 --- a/src/viewer/lib.c +++ b/src/viewer/lib.c @@ -44,10 +44,14 @@ #include "lib/strutil.h" #include "lib/util.h" /* save_file_position() */ #include "lib/widget.h" +#ifdef HAVE_CHARSET #include "lib/charsets.h" +#endif #include "src/main.h" +#ifdef HAVE_CHARSET #include "src/selcodepage.h" +#endif #include "internal.h" #include "mcviewer.h" diff --git a/src/viewer/mcviewer.c b/src/viewer/mcviewer.c index 5db10368d..a9c7c25f1 100644 --- a/src/viewer/mcviewer.c +++ b/src/viewer/mcviewer.c @@ -45,7 +45,6 @@ #include "lib/strutil.h" #include "lib/util.h" /* load_file_position() */ #include "lib/widget.h" -#include "lib/charsets.h" #include "src/main.h" diff --git a/src/viewer/nroff.c b/src/viewer/nroff.c index 4968535da..a8a77afdb 100644 --- a/src/viewer/nroff.c +++ b/src/viewer/nroff.c @@ -39,7 +39,9 @@ #include "lib/global.h" #include "lib/tty/tty.h" #include "lib/skin.h" +#ifdef HAVE_CHARSET #include "lib/charsets.h" +#endif #include "src/setup.h" /* option_tab_spacing */ @@ -227,19 +229,10 @@ mcview_display_nroff (mcview_t * view) if (!g_unichar_isprint (c)) c = '.'; } + else if (view->utf8) + c = convert_from_utf_to_current_c (c, view->converter); else - { - if (view->utf8) - { - c = convert_from_utf_to_current_c (c, view->converter); - } - else - { -#endif - c = convert_to_display_c (c); -#ifdef HAVE_CHARSET - } - } + c = convert_to_display_c (c); #endif tty_print_anychar (c); } diff --git a/src/viewer/plain.c b/src/viewer/plain.c index 64a35c2a8..5bf019d74 100644 --- a/src/viewer/plain.c +++ b/src/viewer/plain.c @@ -40,7 +40,9 @@ #include "lib/tty/tty.h" #include "lib/skin.h" #include "lib/util.h" /* is_printable() */ +#ifdef HAVE_CHARSET #include "lib/charsets.h" +#endif #include "src/setup.h" /* option_tab_spacing */ @@ -168,8 +170,9 @@ mcview_display_text (mcview_t * view) else #endif { +#ifdef HAVE_CHARSET c = convert_to_display_c (c); - +#endif if (!is_printable (c)) c = '.'; } -- 2.11.4.GIT