mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-22 04:22:34 +03:00
Core, mceditor, mcviewer and mcdiffviewer code tweak and cleanup
...in case of build with --disable-charset option. Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
parent
315c499c09
commit
e7fb3526f3
@ -29,8 +29,6 @@
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#ifdef HAVE_CHARSET
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -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 */
|
||||
|
@ -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 */
|
||||
|
@ -31,8 +31,6 @@
|
||||
#include "lib/search.h"
|
||||
#include "lib/strescape.h"
|
||||
|
||||
#include "lib/charsets.h"
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
@ -33,8 +33,6 @@
|
||||
#include "lib/search.h"
|
||||
#include "lib/strescape.h"
|
||||
|
||||
#include "lib/charsets.h"
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
@ -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 ****************************************************************************/
|
||||
|
||||
|
@ -30,8 +30,6 @@
|
||||
#include "lib/strutil.h"
|
||||
#include "lib/search.h"
|
||||
|
||||
#include "lib/charsets.h"
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
@ -34,8 +34,6 @@
|
||||
#include "lib/search.h"
|
||||
#include "lib/strescape.h"
|
||||
|
||||
#include "lib/charsets.h"
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
@ -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"
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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"
|
||||
|
||||
|
@ -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))
|
||||
|
@ -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() */
|
||||
|
@ -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"
|
||||
|
@ -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)
|
||||
|
@ -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)))
|
||||
{
|
||||
char_for_insertion = x_key;
|
||||
goto fin;
|
||||
}
|
||||
}
|
||||
|
||||
/* 8-bit source */
|
||||
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;
|
||||
}
|
||||
}
|
||||
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 */
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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() */
|
||||
|
||||
|
@ -31,8 +31,6 @@
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#ifdef HAVE_CHARSET
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
@ -176,5 +174,3 @@ do_select_codepage (void)
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
#endif /* HAVE_CHARSET */
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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"
|
||||
|
||||
|
@ -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() */
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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 = '.';
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user