Merge branch '2620_cleanup'

* 2620_cleanup: (25 commits)
  vfs_parse_ls_lga: The checks for timestamp is commented out.
  Include config.h to all test's files
  vfs_parse_ls_lga: Make tests output more verbose
  Ticket #2627: Fixed several errors in manpages.
  Fix build with --disable-charset option.
  Added the 'c' hotkey for 'Compile and link current .c file' item of user menu.
  Editor: reduce scope of some functions.
  Editor: reduce scope of some functions.
  Editor: reduce scope of some functions.
  (get_paragraph): fix of pointer difference.
  (load_keymap_from_section): minor optimization.
  (load_keymap_from_section): remove unneeded keybind conversions.
  Added percent sign to key names.
  keymap files: unification of Fxx keys: move to lower case.
  (mc_refresh): moved from lib/widget/wtools.[ch] to lib/widget/dialog-switch.[ch]
  Man pages clean up
  Remove CK_Help action handler in diffviewer
  (size_trunc_len): fixed potential integer overflow if SI is used.
  VFS small optimization
  Remove extra screen update after show help.
  ...
This commit is contained in:
Slava Zanko 2011-10-18 13:36:46 +03:00
commit e7ffcc49b5
59 changed files with 698 additions and 693 deletions

View File

@ -2415,9 +2415,6 @@ Egy sort gördít vissza.
.B C\-l
Frissíti képernyőt.
.PP
.B !
Shell belépés a jelenlegi munkakönyvtárba.
.PP
.B "[n] m"
Beállítja az n kijelölést.
.PP

View File

@ -2452,9 +2452,6 @@ Ridisegna lo schermo.
.B C\-o
Passa alla subshell e mostra la schermata dei comandi.
.PP
.B !
Come C\-o, ma esegue una nuova shell se la subshell non sta andando.
.PP
.B "[n] m"
Imposta l'indice n.
.PP

View File

@ -2887,9 +2887,6 @@ Refresh the screen.
.B C\-o
Switch to the subshell and show the command screen.
.PP
.B !
Like C\-o, but run a new shell if the subshell is not running.
.PP
.B "[n] m"
Set the mark n.
.PP
@ -3532,8 +3529,8 @@ with the assignment of colors, as described in Section
Colors\&.
.\"Colors"
.PP
If your skin contains any of 256\-color definitions, you should define the
'256colors' key set to TRUE value in [skin] section.
If your skin contains any of 256\-color definitions, you should define
the '256colors' key set to TRUE value in [skin] section.
.PP
A skin\-file is searched on the following algorithm (to the first one found):

View File

@ -2075,9 +2075,6 @@ Przewija jedną linię wstecz.
.BR C\-l .
Odświeża ekran.
.PP
.BR ! .
Włącza powłokę w aktualnym katalogu roboczym.
.PP
.BR C\-f .
Przeskakuje do następnego pliku.
.PP

View File

@ -1494,7 +1494,7 @@ Midnight Commander создает дерево путем просмотра т
Компоненты списка должны быть разделены двоеточиями. Например
.PP
.nf
.cdrom:/nfs/wuarchive:/afs
/cdrom:/nfs/wuarchive:/afs
.fi
.PP
Относительные пути также поддерживаются. Следующий пример показывает, как
@ -3157,11 +3157,6 @@ ASCII и шестнадцатеричный (hex). Для переключени
.B C\-o
Переключиться в subshell и показать окно команд.
.PP
.B !
Запустить новый экземпляр оболочки в текущем каталоге (временный выход в
shell, возврат в программу просмотра по
.BR C\-d ).
.PP
.B [n] m
Установить метку с номером n (кавычки не вводятся).
.PP

View File

@ -2442,10 +2442,6 @@ linux би вас одвело у /usr/src/linux).
.B C\-o
Прелази у подљуску и приказује наредбени екран.
.PP
.B !
Исто као C\-o, али у случају да подљуска није покренута покреће нову
љуску.
.PP
.B "[n] m"
Поставља ознаку `n'.
.PP

View File

@ -93,7 +93,7 @@ convert_to_display_c (int c)
{
if (c < 0 || c >= 256)
return c;
return conv_displ[c];
return (int) conv_displ[c];
}
static inline int
@ -101,7 +101,7 @@ convert_from_input_c (int c)
{
if (c < 0 || c >= 256)
return c;
return conv_input[c];
return (int) conv_input[c];
}
#endif /* HAVE_CHARSET */

View File

@ -88,6 +88,7 @@ static inline void
compute_namelen (struct dirent *dent __attribute__ ((unused)))
{
#ifdef DIRENT_LENGTH_COMPUTED
(void) dent;
return;
#else
dent->d_namlen = strlen (dent);

View File

@ -104,6 +104,7 @@ mc_global_t mc_global = {
.disable_colors = FALSE,
.ugly_line_drawing = FALSE,
.old_mouse = FALSE,
.alternate_plus_minus = FALSE,
},
.vfs =

View File

@ -258,6 +258,11 @@ typedef struct
/* Tries to use old highlight mouse tracking */
gboolean old_mouse;
/* If true, use + and \ keys normally and select/unselect do if M-+ / M-\.
and M-- and keypad + / - */
gboolean alternate_plus_minus;
} tty;
struct

View File

@ -381,33 +381,32 @@ str_8bit_term_trim (const char *text, int width)
actual = result;
remain = sizeof (result);
if (width < (int) length)
if (width > 0)
{
if (width <= 3)
if (width < (int) length)
{
memset (actual, '.', width);
actual += width;
remain -= width;
if (width <= 3)
{
memset (actual, '.', width);
actual += width;
remain -= width;
}
else
{
memset (actual, '.', 3);
actual += 3;
remain -= 3;
pos += length - width + 3;
for (; pos < length && remain > 1; pos++, actual++, remain--)
actual[0] = char_isprint (text[pos]) ? text[pos] : '.';
}
}
else
{
memset (actual, '.', 3);
actual += 3;
remain -= 3;
pos += length - width + 3;
for (; pos < length && remain > 1; pos++, actual++, remain--)
{
actual[0] = char_isprint (text[pos]) ? text[pos] : '.';
}
}
}
else
{
for (; pos < length && remain > 1; pos++, actual++, remain--)
{
actual[0] = char_isprint (text[pos]) ? text[pos] : '.';
}
}

View File

@ -327,23 +327,36 @@ str_ascii_term_trim (const char *text, int width)
actual = result;
remain = sizeof (result);
if (width < (int) length)
if (width > 0)
{
if (width <= 3)
if (width < (int) length)
{
memset (actual, '.', width);
actual += width;
remain -= width;
if (width <= 3)
{
memset (actual, '.', width);
actual += width;
remain -= width;
}
else
{
memset (actual, '.', 3);
actual += 3;
remain -= 3;
pos += length - width + 3;
/* copy suffix of text */
for (; pos < length && remain > 1; pos++, actual++, remain--)
{
actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
}
}
}
else
{
memset (actual, '.', 3);
actual += 3;
remain -= 3;
pos += length - width + 3;
/* copy suffix of text */
/* copy all characters */
for (; pos < length && remain > 1; pos++, actual++, remain--)
{
actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
@ -351,15 +364,6 @@ str_ascii_term_trim (const char *text, int width)
}
}
}
else
{
/* copy all characters */
for (; pos < length && remain > 1; pos++, actual++, remain--)
{
actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
}
}
actual[0] = '\0';
return result;

View File

@ -669,6 +669,12 @@ str_utf8_term_trim (const char *text, int width)
const struct term_form *pre_form;
struct utf8_tool tool;
if (width < 1)
{
result [0] = '\0';
return result;
}
pre_form = str_utf8_make_make_term_form (text, (size_t) (-1));
tool.cheked = pre_form->text;

View File

@ -75,10 +75,6 @@
/*** global variables ****************************************************************************/
/* If true, use + and \ keys normally and select/unselect do if M-+ / M-\.
and M-- and keypad + / - */
int alternate_plus_minus = 0;
int mou_auto_repeat = 100;
int double_click_speed = 250;
int old_esc_mode = 0;
@ -168,6 +164,7 @@ const key_code_name_t key_name_conv_tab[] = {
{(int) '&', "ampersand", N_("Ampersand"), "&"},
{(int) '$', "dollar", N_("Dollar sign"), "$"},
{(int) '"', "quota", N_("Quotation mark"), "\""},
{(int) '%', "percent", N_("Percent sign"), "%"},
{(int) '^', "caret", N_("Caret"), "^"},
{(int) '~', "tilda", N_("Tilda"), "~"},
{(int) '`', "prime", N_("Prime"), "`"},
@ -1058,7 +1055,7 @@ correct_key_code (int code)
mod &= ~KEY_M_SHIFT;
}
if (!alternate_plus_minus)
if (!mc_global.tty.alternate_plus_minus)
switch (c)
{
case KEY_KP_ADD:
@ -2102,7 +2099,7 @@ learn_key (void)
void
numeric_keypad_mode (void)
{
if (mc_global.tty.console_flag || mc_global.tty.xterm_flag)
if (mc_global.tty.console_flag != '\0' || mc_global.tty.xterm_flag)
{
fputs (ESC_STR ">", stdout);
fflush (stdout);
@ -2114,7 +2111,7 @@ numeric_keypad_mode (void)
void
application_keypad_mode (void)
{
if (mc_global.tty.console_flag || mc_global.tty.xterm_flag)
if (mc_global.tty.console_flag != '\0' || mc_global.tty.xterm_flag)
{
fputs (ESC_STR "=", stdout);
fflush (stdout);

View File

@ -53,7 +53,6 @@ extern const key_code_name_t key_name_conv_tab[];
extern int old_esc_mode_timeout;
extern int alternate_plus_minus;
extern int double_click_speed;
extern int old_esc_mode;
extern int use_8th_bit_as_meta;
@ -104,7 +103,7 @@ void application_keypad_mode (void);
static inline gboolean
is_abort_char (int c)
{
return ((c == ESC_CHAR) || (c == KEY_F (10)));
return ((c == (int) ESC_CHAR) || (c == (int) KEY_F (10)));
}
#endif /* MC_KEY_H */

View File

@ -431,7 +431,6 @@ size_trunc_len (char *buffer, unsigned int len, uintmax_t size, int units, gbool
static const char *const suffix[] = { "", "K", "M", "G", "T", "P", "E", "Z", "Y", NULL };
static const char *const suffix_lc[] = { "", "k", "m", "g", "t", "p", "e", "z", "y", NULL };
int j = 0;
int size_remain;
if (len == 0)
len = 9;
@ -453,6 +452,8 @@ size_trunc_len (char *buffer, unsigned int len, uintmax_t size, int units, gbool
if (use_si)
for (j = 0; j < units; j++)
{
uintmax_t size_remain;
size_remain = ((size % 125) * 1024) / 1000; /* size mod 125, recalculated */
size = size / 125; /* 128/125 = 1024/1000 */
size = size * 128; /* This will convert size from multiple of 1024 to multiple of 1000 */

View File

@ -1006,6 +1006,7 @@ get_user_permissions (struct stat *st)
char *
mc_build_filename (const char *first_element, ...)
{
gboolean absolute;
va_list args;
const char *element = first_element;
GString *path;
@ -1017,31 +1018,39 @@ mc_build_filename (const char *first_element, ...)
path = g_string_new ("");
va_start (args, first_element);
absolute = (*first_element != '\0' && *first_element == PATH_SEP);
do
{
char *tmp_element;
size_t len;
const char *start;
if (*element == '\0')
element = va_arg (args, char *);
else
{
char *tmp_element;
size_t len;
const char *start;
tmp_element = g_strdup (element);
tmp_element = g_strdup (element);
element = va_arg (args, char *);
element = va_arg (args, char *);
canonicalize_pathname (tmp_element);
len = strlen (tmp_element);
start = (tmp_element[0] == PATH_SEP) ? tmp_element + 1 : tmp_element;
canonicalize_pathname (tmp_element);
len = strlen (tmp_element);
start = (tmp_element[0] == PATH_SEP) ? tmp_element + 1 : tmp_element;
g_string_append (path, start);
if (tmp_element[len - 1] != PATH_SEP && element != NULL)
g_string_append_c (path, PATH_SEP);
g_string_append (path, start);
if (tmp_element[len - 1] != PATH_SEP && element != NULL)
g_string_append_c (path, PATH_SEP);
g_free (tmp_element);
g_free (tmp_element);
}
}
while (element != NULL);
va_end (args);
g_string_prepend_c (path, PATH_SEP);
if (absolute)
g_string_prepend_c (path, PATH_SEP);
ret = g_string_free (path, FALSE);
canonicalize_pathname (ret);

View File

@ -168,6 +168,25 @@ _vfs_translate_path (const char *path, int size, GIConv defcnv, GString * buffer
return state;
}
/* --------------------------------------------------------------------------------------------- */
static struct vfs_openfile *
vfs_get_openfile (int handle)
{
struct vfs_openfile *h;
if (handle < VFS_FIRST_HANDLE || (guint) (handle - VFS_FIRST_HANDLE) >= vfs_openfiles->len)
return NULL;
h = (struct vfs_openfile *) g_ptr_array_index (vfs_openfiles, handle - VFS_FIRST_HANDLE);
if (h == NULL)
return NULL;
g_assert (h->handle == handle);
return h;
}
/* --------------------------------------------------------------------------------------------- */
/*** public functions ****************************************************************************/
/* --------------------------------------------------------------------------------------------- */
@ -198,16 +217,9 @@ vfs_class_data_find_by_handle (int handle)
{
struct vfs_openfile *h;
if (handle < VFS_FIRST_HANDLE || (guint) (handle - VFS_FIRST_HANDLE) >= vfs_openfiles->len)
return NULL;
h = vfs_get_openfile (handle);
h = (struct vfs_openfile *) g_ptr_array_index (vfs_openfiles, handle - VFS_FIRST_HANDLE);
if (!h)
return NULL;
g_assert (h->handle == handle);
return h->fsinfo;
return h == NULL ? NULL : h->fsinfo;
}
/* --------------------------------------------------------------------------------------------- */
@ -218,16 +230,9 @@ vfs_class_find_by_handle (int handle)
{
struct vfs_openfile *h;
if (handle < VFS_FIRST_HANDLE || (guint) (handle - VFS_FIRST_HANDLE) >= vfs_openfiles->len)
return NULL;
h = vfs_get_openfile (handle);
h = (struct vfs_openfile *) g_ptr_array_index (vfs_openfiles, handle - VFS_FIRST_HANDLE);
if (!h)
return NULL;
g_assert (h->handle == handle);
return h->vclass;
return h == NULL ? NULL : h->vclass;
}
/* --------------------------------------------------------------------------------------------- */
@ -545,6 +550,8 @@ _vfs_get_cwd (void)
{
vfs_set_raw_current_dir (vfs_path_from_str (tmp));
}
g_free (tmp);
}
}

View File

@ -320,6 +320,25 @@ repaint_screen (void)
/* --------------------------------------------------------------------------------------------- */
void
mc_refresh (void)
{
#ifdef WITH_BACKGROUND
if (mc_global.we_are_background)
return;
#endif /* WITH_BACKGROUND */
if (!mc_global.tty.winch_flag)
tty_refresh ();
else
{
/* if winch was caugth, we should do not only redraw screen, but
reposition/resize all */
dialog_change_screen_size ();
}
}
/* --------------------------------------------------------------------------------------------- */
void
dialog_change_screen_size (void)
{

View File

@ -31,6 +31,7 @@ void dialog_switch_shutdown (void);
/* Clear screen */
void clr_scr (void);
void repaint_screen (void);
void mc_refresh (void);
void dialog_change_screen_size (void);
/*** inline functions ****************************************************************************/

View File

@ -296,7 +296,6 @@ dlg_execute_cmd (Dlg_head * h, unsigned long command)
{
ev_help_t event_data = { NULL, h->help_ctx };
mc_event_raise (MCEVENT_GROUP_CORE, "help", &event_data);
do_refresh ();
}
break;

View File

@ -517,22 +517,3 @@ input_expand_dialog (const char *header, const char *text,
}
/* --------------------------------------------------------------------------------------------- */
void
mc_refresh (void)
{
#ifdef WITH_BACKGROUND
if (mc_global.we_are_background)
return;
#endif /* WITH_BACKGROUND */
if (mc_global.tty.winch_flag == FALSE)
tty_refresh ();
else
{
/* if winch was caugth, we should do not only redraw screen, but
reposition/resize all */
dialog_change_screen_size ();
}
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -47,9 +47,6 @@ struct Dlg_head *create_message (int flags, const char *title,
void message (int flags, const char *title, const char *text, ...)
__attribute__ ((format (__printf__, 3, 4)));
/* Clear screen */
void mc_refresh (void);
/*** inline functions ****************************************************************************/
#endif /* MC__WTOOLS_H */

View File

@ -88,11 +88,11 @@ PageDown = pgdn; ctrl-v
Enter = enter
PanelOtherCd = alt-o
PanelOtherCdLink = alt-l
ViewRaw = F13
EditNew = F14
CopySingle = F15
MoveSingle = F16
DeleteSingle = F18
ViewRaw = f13
EditNew = f14
CopySingle = f15
MoveSingle = f16
DeleteSingle = f18
Select = alt-plus
Unselect = alt-minus
SelectInvert = alt-asterisk

View File

@ -89,11 +89,11 @@ PageDown = pgdn; ctrl-v
Enter = enter
PanelOtherCd = alt-o
PanelOtherCdLink = alt-l
ViewRaw = F13
EditNew = F14
CopySingle = F15
MoveSingle = F16
DeleteSingle = F18
ViewRaw = f13
EditNew = f14
CopySingle = f15
MoveSingle = f16
DeleteSingle = f18
Select = alt-plus
Unselect = alt-minus
SelectInvert = alt-asterisk

View File

@ -83,7 +83,7 @@ shell_patterns=0
= f \.c$ & t r
+ f \.c$ & t r & ! t t
Compile and link current .c file
с Compile and link current .c file
make `basename %f .c` 2>/dev/null || cc -O -o `basename %f .c` %f
+ t r & ! t t

View File

@ -88,7 +88,7 @@ show_console_contents_linux (int starty, unsigned char begin_line, unsigned char
ssize_t ret;
/* Is tty console? */
if (!mc_global.tty.console_flag)
if (mc_global.tty.console_flag == '\0')
return;
/* Paranoid: Is the cons.saver still running? */
if (cons_saver_pid < 1 || kill (cons_saver_pid, SIGCONT))
@ -128,7 +128,7 @@ show_console_contents_linux (int starty, unsigned char begin_line, unsigned char
/* --------------------------------------------------------------------------------------------- */
static void
handle_console_linux (unsigned char action)
handle_console_linux (console_action_t action)
{
char *tty_name;
char *mc_conssaver;
@ -166,7 +166,7 @@ handle_console_linux (unsigned char action)
status = close (pipefd2[1]);
/* Was the child successful? */
status = read (pipefd2[0], &mc_global.tty.console_flag, 1);
if (!mc_global.tty.console_flag)
if (mc_global.tty.console_flag == '\0')
{
pid_t ret;
status = close (pipefd1[1]);
@ -216,7 +216,7 @@ handle_console_linux (unsigned char action)
case CONSOLE_SAVE:
case CONSOLE_RESTORE:
/* Is tty console? */
if (!mc_global.tty.console_flag)
if (mc_global.tty.console_flag == '\0')
return;
/* Paranoid: Is the cons.saver still running? */
if (cons_saver_pid < 1 || kill (cons_saver_pid, SIGCONT))
@ -232,7 +232,7 @@ handle_console_linux (unsigned char action)
/* Wait the console handler to do its job */
status = read (pipefd2[0], &mc_global.tty.console_flag, 1);
}
if (action == CONSOLE_DONE || !mc_global.tty.console_flag)
if (action == CONSOLE_DONE || mc_global.tty.console_flag == '\0')
{
/* We are done -> Let's clean up */
pid_t ret;
@ -242,6 +242,8 @@ handle_console_linux (unsigned char action)
mc_global.tty.console_flag = '\0';
}
break;
default:
break;
}
}
@ -256,7 +258,7 @@ handle_console_linux (unsigned char action)
static void
console_init (void)
{
if (mc_global.tty.console_flag)
if (mc_global.tty.console_flag != '\0')
return;
screen_info.size = sizeof (screen_info);
@ -297,7 +299,7 @@ console_restore (void)
{
int i, last;
if (!mc_global.tty.console_flag)
if (mc_global.tty.console_flag == '\0')
return;
cursor_to (0, 0);
@ -321,7 +323,7 @@ console_restore (void)
static void
console_shutdown (void)
{
if (!mc_global.tty.console_flag)
if (mc_global.tty.console_flag == '\0')
return;
g_free (screen_shot.buf);
@ -338,7 +340,7 @@ console_save (void)
scrmap_t map;
scrmap_t revmap;
if (!mc_global.tty.console_flag)
if (mc_global.tty.console_flag == '\0')
return;
/* screen_info.size is already set in console_init() */
@ -376,8 +378,8 @@ console_save (void)
for (i = 0; i < screen_shot.xsize * screen_shot.ysize; i++)
{
screen_shot.buf[i] =
(screen_shot.buf[i] & 0xff00) | (unsigned char) revmap.
scrmap[screen_shot.buf[i] & 0xff];
(screen_shot.buf[i] & 0xff00) | (unsigned char) revmap.scrmap[screen_shot.
buf[i] & 0xff];
}
}
@ -389,7 +391,7 @@ show_console_contents_freebsd (int starty, unsigned char begin_line, unsigned ch
int col, line;
char c;
if (!mc_global.tty.console_flag)
if (mc_global.tty.console_flag == '\0')
return;
for (line = begin_line; line <= end_line; line++)
@ -406,7 +408,7 @@ show_console_contents_freebsd (int starty, unsigned char begin_line, unsigned ch
/* --------------------------------------------------------------------------------------------- */
static void
handle_console_freebsd (unsigned char action)
handle_console_freebsd (console_action_t action)
{
switch (action)
{
@ -425,6 +427,8 @@ handle_console_freebsd (unsigned char action)
case CONSOLE_RESTORE:
console_restore ();
break;
default:
break;
}
}
#endif /* __FreeBSD__ */
@ -455,7 +459,7 @@ show_console_contents (int starty, unsigned char begin_line, unsigned char end_l
/* --------------------------------------------------------------------------------------------- */
void
handle_console (unsigned char action)
handle_console (console_action_t action)
{
(void) action;

View File

@ -16,14 +16,14 @@
/*** enums ***************************************************************************************/
enum
typedef enum
{
CONSOLE_INIT = '1',
CONSOLE_DONE,
CONSOLE_SAVE,
CONSOLE_RESTORE,
CONSOLE_CONTENTS
};
} console_action_t;
/*** structures declarations (and typedefs of structures)*****************************************/
@ -39,7 +39,7 @@ extern int cons_saver_pid;
#ifndef LINUX_CONS_SAVER_C
/* Used only in mc, not in cons.saver */
void show_console_contents (int starty, unsigned char begin_line, unsigned char end_line);
void handle_console (unsigned char action);
void handle_console (console_action_t action);
#endif /* !LINUX_CONS_SAVER_C */
/*** inline functions ****************************************************************************/

View File

@ -2981,12 +2981,6 @@ dview_execute_cmd (WDiff * dview, unsigned long command)
cb_ret_t res = MSG_HANDLED;
switch (command)
{
case CK_Help:
{
ev_help_t event_data = { NULL, "[Diff Viewer]" };
mc_event_raise (MCEVENT_GROUP_CORE, "help", &event_data);
}
break;
case CK_ShowSymbols:
dview->display_symbols ^= 1;
dview->new_frame = 1;

View File

@ -202,10 +202,7 @@ void edit_init_menu (struct WMenuBar *menubar);
void menu_save_mode_cmd (void);
int edit_translate_key (WEdit * edit, long x_key, int *cmd, int *ch);
int edit_get_byte (WEdit * edit, long byte_index);
char *edit_get_byte_ptr (WEdit * edit, long byte_index);
char *edit_get_buf_ptr (WEdit * edit, long byte_index);
int edit_get_utf (WEdit * edit, long byte_index, int *char_width);
int edit_get_prev_utf (WEdit * edit, long byte_index, int *char_width);
long edit_count_lines (WEdit * edit, long current, long upto);
long edit_move_forward (WEdit * edit, long current, long lines, long upto);
long edit_move_forward3 (WEdit * edit, long current, int cols, long upto);
@ -232,13 +229,10 @@ void edit_block_copy_cmd (WEdit * edit);
void edit_block_move_cmd (WEdit * edit);
int edit_block_delete_cmd (WEdit * edit);
void edit_delete_line (WEdit * edit);
void insert_spaces_tab (WEdit * edit, int half);
int edit_delete (WEdit * edit, const int byte_delete);
void edit_insert (WEdit * edit, int c);
void edit_cursor_move (WEdit * edit, long increment);
void edit_move_block_to_right (WEdit * edit);
void edit_move_block_to_left (WEdit * edit);
void edit_push_undo_action (WEdit * edit, long c, ...);
void edit_push_redo_action (WEdit * edit, long c, ...);
void edit_push_key_press (WEdit * edit);
@ -268,8 +262,6 @@ int edit_save_block (WEdit * edit, const char *filename, long start, long finish
int edit_save_block_cmd (WEdit * edit);
int edit_insert_file_cmd (WEdit * edit);
void edit_insert_over (WEdit * edit);
void edit_insert_column_of_text (WEdit * edit, unsigned char *data, int size, int width,
long *start_pos, long *end_pos, int *col1, int *col2);
int edit_insert_column_of_text_from_file (WEdit * edit, int file,
long *start_pos, long *end_pos, int *col1, int *col2);
long edit_insert_file (WEdit * edit, const char *filename);
@ -283,7 +275,6 @@ int eval_marks (WEdit * edit, long *start_mark, long *end_mark);
void edit_status (WEdit * edit);
void edit_execute_key_command (WEdit * edit, unsigned long command, int char_for_insertion);
void edit_update_screen (WEdit * edit);
int edit_print_string (WEdit * e, const char *s);
void edit_move_to_line (WEdit * e, long line);
void edit_move_display (WEdit * e, long line);
void edit_word_wrap (WEdit * edit);

View File

@ -669,6 +669,121 @@ edit_modification (WEdit * edit)
/* --------------------------------------------------------------------------------------------- */
static char *
edit_get_byte_ptr (WEdit * edit, long byte_index)
{
if (byte_index >= (edit->curs1 + edit->curs2) || byte_index < 0)
return NULL;
if (byte_index >= edit->curs1)
{
unsigned long p;
p = edit->curs1 + edit->curs2 - byte_index - 1;
return (char *) (edit->buffers2[p >> S_EDIT_BUF_SIZE] +
(EDIT_BUF_SIZE - (p & M_EDIT_BUF_SIZE) - 1));
}
return (char *) (edit->buffers1[byte_index >> S_EDIT_BUF_SIZE] +
(byte_index & M_EDIT_BUF_SIZE));
}
/* --------------------------------------------------------------------------------------------- */
static char *
edit_get_buf_ptr (WEdit * edit, long byte_index)
{
if (byte_index >= (edit->curs1 + edit->curs2))
byte_index--;
if (byte_index < 0)
return NULL;
if (byte_index >= edit->curs1)
{
unsigned long p;
p = edit->curs1 + edit->curs2 - 1;
return (char *) (edit->buffers2[p >> S_EDIT_BUF_SIZE] +
(EDIT_BUF_SIZE - (p & M_EDIT_BUF_SIZE) - 1));
}
return (char *) (edit->buffers1[byte_index >> S_EDIT_BUF_SIZE] + (0 & M_EDIT_BUF_SIZE));
}
/* --------------------------------------------------------------------------------------------- */
static int
edit_get_prev_utf (WEdit * edit, long byte_index, int *char_width)
{
gchar *str, *buf = NULL;
int res = -1;
gunichar ch;
gchar *next_ch = NULL;
int width = 0;
if (byte_index > 0)
byte_index--;
if (byte_index >= (edit->curs1 + edit->curs2) || byte_index < 0)
{
*char_width = 0;
return 0;
}
ch = edit_get_utf (edit, byte_index, &width);
if (width == 1)
{
*char_width = width;
return ch;
}
str = edit_get_byte_ptr (edit, byte_index);
buf = edit_get_buf_ptr (edit, byte_index);
if (str == NULL || buf == NULL)
{
*char_width = 0;
return 0;
}
/* get prev utf8 char */
if (str != buf)
str = g_utf8_find_prev_char (buf, str);
if (str == NULL)
{
*char_width = 0;
return 0;
}
else
res = g_utf8_get_char_validated (str, -1);
if (res < 0)
{
ch = *str;
width = 0;
}
else
{
ch = res;
/* Calculate UTF-8 char width */
next_ch = g_utf8_next_char (str);
if (next_ch)
{
width = next_ch - str;
}
else
{
ch = 0;
width = 0;
}
}
*char_width = width;
return ch;
}
/* --------------------------------------------------------------------------------------------- */
static int
edit_backspace (WEdit * edit, const int byte_delete)
{
@ -1498,6 +1613,26 @@ edit_double_newline (WEdit * edit)
edit_insert (edit, '\n');
}
/* --------------------------------------------------------------------------------------------- */
static void
insert_spaces_tab (WEdit * edit, gboolean half)
{
int i;
edit_update_curs_col (edit);
i = option_tab_spacing * space_width;
if (half)
i /= 2;
i = ((edit->curs_col / i) + 1) * i - edit->curs_col;
while (i > 0)
{
edit_insert (edit, ' ');
i -= space_width;
}
}
/* --------------------------------------------------------------------------------------------- */
static inline void
@ -1512,27 +1647,21 @@ edit_tab_cmd (WEdit * edit)
/*insert a half tab (usually four spaces) unless there is a
half tab already behind, then delete it and insert a
full tab. */
if (!option_fill_tabs_with_spaces && right_of_four_spaces (edit))
if (option_fill_tabs_with_spaces || !right_of_four_spaces (edit))
insert_spaces_tab (edit, TRUE);
else
{
for (i = 1; i <= HALF_TAB_SIZE; i++)
edit_backspace (edit, 1);
edit_insert (edit, '\t');
}
else
{
insert_spaces_tab (edit, 1);
}
return;
}
}
if (option_fill_tabs_with_spaces)
{
insert_spaces_tab (edit, 0);
}
insert_spaces_tab (edit, FALSE);
else
{
edit_insert (edit, '\t');
}
}
/* --------------------------------------------------------------------------------------------- */
@ -1636,6 +1765,105 @@ edit_goto_matching_bracket (WEdit * edit)
}
}
/* --------------------------------------------------------------------------------------------- */
static void
edit_move_block_to_right (WEdit * edit)
{
long start_mark, end_mark;
long cur_bol, start_bol;
if (eval_marks (edit, &start_mark, &end_mark))
return;
start_bol = edit_bol (edit, start_mark);
cur_bol = edit_bol (edit, end_mark - 1);
do
{
edit_cursor_move (edit, cur_bol - edit->curs1);
if (option_fill_tabs_with_spaces)
insert_spaces_tab (edit, option_fake_half_tabs);
else
edit_insert (edit, '\t');
edit_cursor_move (edit, edit_bol (edit, cur_bol) - edit->curs1);
if (cur_bol == 0)
break;
cur_bol = edit_bol (edit, cur_bol - 1);
}
while (cur_bol >= start_bol);
edit->force |= REDRAW_PAGE;
}
/* --------------------------------------------------------------------------------------------- */
static void
edit_move_block_to_left (WEdit * edit)
{
long start_mark, end_mark;
long cur_bol, start_bol;
int i;
if (eval_marks (edit, &start_mark, &end_mark))
return;
start_bol = edit_bol (edit, start_mark);
cur_bol = edit_bol (edit, end_mark - 1);
do
{
int del_tab_width;
int next_char;
edit_cursor_move (edit, cur_bol - edit->curs1);
if (option_fake_half_tabs)
del_tab_width = HALF_TAB_SIZE;
else
del_tab_width = option_tab_spacing;
next_char = edit_get_byte (edit, edit->curs1);
if (next_char == '\t')
edit_delete (edit, 1);
else if (next_char == ' ')
for (i = 1; i <= del_tab_width; i++)
{
if (next_char == ' ')
edit_delete (edit, 1);
next_char = edit_get_byte (edit, edit->curs1);
}
if (cur_bol == 0)
break;
cur_bol = edit_bol (edit, cur_bol - 1);
}
while (cur_bol >= start_bol);
edit->force |= REDRAW_PAGE;
}
/* --------------------------------------------------------------------------------------------- */
/**
* prints at the cursor
* @returns the number of chars printed
*/
static size_t
edit_print_string (WEdit * e, const char *s)
{
size_t i = 0;
while (s[i] != '\0')
edit_execute_cmd (e, CK_InsertChar, (unsigned char) s[i++]);
e->force |= REDRAW_COMPLETELY;
edit_update_screen (e);
return i;
}
/* --------------------------------------------------------------------------------------------- */
/*** public functions ****************************************************************************/
/* --------------------------------------------------------------------------------------------- */
@ -1710,53 +1938,6 @@ edit_get_byte (WEdit * edit, long byte_index)
/* --------------------------------------------------------------------------------------------- */
char *
edit_get_byte_ptr (WEdit * edit, long byte_index)
{
unsigned long p;
if (byte_index >= (edit->curs1 + edit->curs2) || byte_index < 0)
return NULL;
if (byte_index >= edit->curs1)
{
p = edit->curs1 + edit->curs2 - byte_index - 1;
return (char *) (edit->buffers2[p >> S_EDIT_BUF_SIZE] +
(EDIT_BUF_SIZE - (p & M_EDIT_BUF_SIZE) - 1));
}
else
{
return (char *) (edit->buffers1[byte_index >> S_EDIT_BUF_SIZE] +
(byte_index & M_EDIT_BUF_SIZE));
}
}
/* --------------------------------------------------------------------------------------------- */
char *
edit_get_buf_ptr (WEdit * edit, long byte_index)
{
unsigned long p;
if (byte_index >= (edit->curs1 + edit->curs2))
byte_index--;
if (byte_index < 0)
return NULL;
if (byte_index >= edit->curs1)
{
p = edit->curs1 + edit->curs2 - 1;
return (char *) (edit->buffers2[p >> S_EDIT_BUF_SIZE] +
(EDIT_BUF_SIZE - (p & M_EDIT_BUF_SIZE) - 1));
}
else
{
return (char *) (edit->buffers1[byte_index >> S_EDIT_BUF_SIZE] + (0 & M_EDIT_BUF_SIZE));
}
}
/* --------------------------------------------------------------------------------------------- */
int
edit_get_utf (WEdit * edit, long byte_index, int *char_width)
{
@ -1808,77 +1989,6 @@ edit_get_utf (WEdit * edit, long byte_index, int *char_width)
/* --------------------------------------------------------------------------------------------- */
int
edit_get_prev_utf (WEdit * edit, long byte_index, int *char_width)
{
gchar *str, *buf = NULL;
int res = -1;
gunichar ch;
gchar *next_ch = NULL;
int width = 0;
if (byte_index > 0)
byte_index--;
if (byte_index >= (edit->curs1 + edit->curs2) || byte_index < 0)
{
*char_width = 0;
return 0;
}
ch = edit_get_utf (edit, byte_index, &width);
if (width == 1)
{
*char_width = width;
return ch;
}
str = edit_get_byte_ptr (edit, byte_index);
buf = edit_get_buf_ptr (edit, byte_index);
if (str == NULL || buf == NULL)
{
*char_width = 0;
return 0;
}
/* get prev utf8 char */
if (str != buf)
str = g_utf8_find_prev_char (buf, str);
if (str == NULL)
{