diff options
Diffstat (limited to 'packages')
| -rw-r--r-- | packages/mc/mc-4.6.2/00-70-utf8-common.patch | 46 | ||||
| -rw-r--r-- | packages/mc/mc-4.6.2/00-73-utf8-bottom-buttons-width.patch | 21 | ||||
| -rw-r--r-- | packages/mc/mc-4.6.2/00-75-utf8-cmdline-help.patch | 63 | ||||
| -rw-r--r-- | packages/mc/mc-4.6.2/00-76-utf8-hotlist-highlight.patch | 23 | ||||
| -rw-r--r-- | packages/mc/mc-4.6.2/00-77-utf8-filename-search-highlight.patch | 17 | ||||
| -rw-r--r-- | packages/mc/mc-4.6.2/mc-utf8-look-and-feel.patch | 206 | ||||
| -rw-r--r-- | packages/mc/mc-4.6.2/mc-utf8-nlink.patch | 11 | ||||
| -rw-r--r-- | packages/mc/mc-4.6.2/mc-utf8.patch | 5357 | ||||
| -rw-r--r-- | packages/mc/mc-4.6.2/mhl-stdbool.patch | 16 | ||||
| -rw-r--r-- | packages/mc/mc_4.6.2.bb | 60 |
10 files changed, 5820 insertions, 0 deletions
diff --git a/packages/mc/mc-4.6.2/00-70-utf8-common.patch b/packages/mc/mc-4.6.2/00-70-utf8-common.patch new file mode 100644 index 0000000000..244a01580a --- /dev/null +++ b/packages/mc/mc-4.6.2/00-70-utf8-common.patch @@ -0,0 +1,46 @@ +Some common stuff used by other UTF-8 patches. + +================================================================================ +--- mc-4.6.2/src/util.c ++++ mc-4.6.2/src/util.c +@@ -145,6 +145,30 @@ + return strlen (str); + } + ++int ++columns_to_bytes (const char *str, int col) ++{ ++ int bytes = 0; ++ int columns = 0; ++ int i; ++#ifdef UTF8 ++ if (SLsmg_Is_Unicode) { ++ static mbstate_t s; ++ while (columns < col) { ++ memset (&s, 0, sizeof (s)); ++ i = mbrlen (str + bytes, -1, &s); ++ if (i <= 0) { ++ return col + bytes - columns; ++ } ++ bytes += i; ++ columns ++; ++ } ++ return col + bytes - columns; ++ } else ++#endif ++ return col; ++} ++ + #ifdef UTF8 + + void +--- mc-4.6.2/src/util.h ++++ mc-4.6.2/src/util.h +@@ -104,6 +104,7 @@ + + void fix_utf8(char *str); + size_t mbstrlen (const char *); ++int columns_to_bytes (const char *, int); + wchar_t *mbstr_to_wchar (const char *); + char *wchar_to_mbstr (const wchar_t *); + char *utf8_to_local(char *str); diff --git a/packages/mc/mc-4.6.2/00-73-utf8-bottom-buttons-width.patch b/packages/mc/mc-4.6.2/00-73-utf8-bottom-buttons-width.patch new file mode 100644 index 0000000000..a7bc41c59b --- /dev/null +++ b/packages/mc/mc-4.6.2/00-73-utf8-bottom-buttons-width.patch @@ -0,0 +1,21 @@ +Use six character width cyan rectangles for bottom row's buttons. + +================================================================================ +--- mc-4.6.2/src/widget.c ++++ mc-4.6.2/src/widget.c +@@ -2562,11 +2562,14 @@ + attrset (DEFAULT_COLOR); + tty_printf ("%-*s", bb->widget.cols, ""); + for (i = 0; i < COLS / 8 && i < 10; i++) { ++ int j; + widget_move (&bb->widget, 0, i * 8); + attrset (DEFAULT_COLOR); + tty_printf ("%d", i + 1); + attrset (SELECTED_COLOR); +- tty_printf ("%-*s", ((i + 1) * 8 == COLS ? 5 : 6), ++ j = columns_to_bytes(bb->labels [i].text ? bb->labels [i].text : "", ++ ((i + 1) * 8 == COLS ? 5 : 6)); ++ tty_printf ("%-*s", j, + bb->labels[i].text ? bb->labels[i].text : ""); + attrset (DEFAULT_COLOR); + } diff --git a/packages/mc/mc-4.6.2/00-75-utf8-cmdline-help.patch b/packages/mc/mc-4.6.2/00-75-utf8-cmdline-help.patch new file mode 100644 index 0000000000..5f1227d30a --- /dev/null +++ b/packages/mc/mc-4.6.2/00-75-utf8-cmdline-help.patch @@ -0,0 +1,63 @@ +Fix formatting the output of "mc --help". + +================================================================================ +--- mc-4.6.2/src/main.c ++++ mc-4.6.2/src/main.c +@@ -1865,7 +1865,7 @@ + + /* print help for options */ + leftColWidth = poptPrintHelp (ctx, stream, 0); +- fprintf (stream, " %-*s %s\n", leftColWidth, _("+number"), ++ fprintf (stream, " %-*s %s\n", leftColWidth + strlen(_("+number")) - mbstrlen(_("+number")), _("+number"), + _("Set initial line number for the internal editor")); + fputs (_ + ("\n" +--- mc-4.6.2/src/popthelp.c ++++ mc-4.6.2/src/popthelp.c +@@ -101,7 +101,7 @@ + goto out; + } + +- helpLength = strlen(help); ++ helpLength = mbstrlen(help); + while (helpLength > lineLength) { + ch = help + lineLength - 1; + while (ch > help && !isspace((unsigned char) *ch)) ch--; +@@ -112,7 +112,7 @@ + fprintf(f, "%.*s\n%*s", (int) (ch - help), help, indentLength, " "); + help = ch; + while (isspace((unsigned char) *help) && *help) help++; +- helpLength = strlen(help); ++ helpLength = mbstrlen(help); + } + + if (helpLength) fprintf(f, "%s\n", help); +@@ -233,7 +233,7 @@ + if (len == 3) return cursor; + + if (argDescrip) +- len += strlen(argDescrip) + 1; ++ len += mbstrlen(argDescrip) + 1; + + if ((cursor + len) > 79) { + fprintf(f, "\n "); +@@ -304,7 +304,7 @@ + singleTableUsage(f, cursor, con->options, NULL); + + if (con->otherHelp) { +- cursor += strlen(con->otherHelp) + 1; ++ cursor += mbstrlen(con->otherHelp) + 1; + if (cursor > 79) fprintf(f, "\n "); + fprintf(f, " %s", con->otherHelp); + } +--- mc-4.6.2/src/util.c ++++ mc-4.6.2/src/util.c +@@ -152,7 +152,7 @@ + int columns = 0; + int i; + #ifdef UTF8 +- if (SLsmg_Is_Unicode) { ++ if (1) { + static mbstate_t s; + while (columns < col) { + memset (&s, 0, sizeof (s)); diff --git a/packages/mc/mc-4.6.2/00-76-utf8-hotlist-highlight.patch b/packages/mc/mc-4.6.2/00-76-utf8-hotlist-highlight.patch new file mode 100644 index 0000000000..38e0337ad6 --- /dev/null +++ b/packages/mc/mc-4.6.2/00-76-utf8-hotlist-highlight.patch @@ -0,0 +1,23 @@ +Highlight the lines of hotlist in full width. + +================================================================================ +--- mc-4.6.2/src/widget.c ++++ mc-4.6.2/src/widget.c +@@ -1994,6 +1994,7 @@ + { + WLEntry *e; + int i; ++ int j; + int sel_line; + Dlg_head *h = l->widget.parent; + int normalc = DLG_NORMALC (h); +@@ -2024,7 +2025,8 @@ + text = e->text; + e = e->next; + } +- tty_printf (" %-*s ", l->width-2, name_trunc (text, l->width-2)); ++ j = columns_to_bytes (name_trunc (text, l->width-2), l->width-2); ++ tty_printf (" %-*s ", j, name_trunc (text, l->width-2)); + } + l->cursor_y = sel_line; + if (!l->scrollbar) diff --git a/packages/mc/mc-4.6.2/00-77-utf8-filename-search-highlight.patch b/packages/mc/mc-4.6.2/00-77-utf8-filename-search-highlight.patch new file mode 100644 index 0000000000..912d8eb72b --- /dev/null +++ b/packages/mc/mc-4.6.2/00-77-utf8-filename-search-highlight.patch @@ -0,0 +1,17 @@ +Quick filename search (^S) highlights correct width. + +================================================================================ +--- mc-4.6.2/src/screen.c ++++ mc-4.6.2/src/screen.c +@@ -771,8 +771,10 @@ + widget_move (&panel->widget, llines (panel)+3, 1); + + if (panel->searching){ ++ int j; + attrset (INPUT_COLOR); +- tty_printf ("/%-*s", panel->widget.cols-3, panel->search_buffer); ++ j = columns_to_bytes (panel->search_buffer, panel->widget.cols-3); ++ tty_printf ("/%-*s", j, panel->search_buffer); + attrset (NORMAL_COLOR); + return; + } diff --git a/packages/mc/mc-4.6.2/mc-utf8-look-and-feel.patch b/packages/mc/mc-4.6.2/mc-utf8-look-and-feel.patch new file mode 100644 index 0000000000..83ad60135d --- /dev/null +++ b/packages/mc/mc-4.6.2/mc-utf8-look-and-feel.patch @@ -0,0 +1,206 @@ +Index: mc-4.6.2~git20080311/src/main.c +================================================================================ +--- mc-4.6.2/src/main.c ++++ mc-4.6.2/src/main.c +@@ -276,6 +276,9 @@ + /* The user's shell */ + const char *shell = NULL; + ++/* Is the LANG UTF-8 ? */ ++gboolean is_utf8 = FALSE; ++ + /* mc_home: The home of MC */ + char *mc_home = NULL; + +@@ -2126,6 +2129,16 @@ + int + main (int argc, char *argv[]) + { ++ /* Check whether we have UTF-8 locale */ ++ char *lang = getenv("LANG"); ++ size_t len = 0; ++ ++ if ( lang ) ++ len = strlen(lang); ++ ++ if ( len >= 5 && !strcasecmp(&lang[len-5],"UTF-8") ) ++ is_utf8 = TRUE; ++ + /* We had LC_CTYPE before, LC_ALL includs LC_TYPE as well */ + setlocale (LC_ALL, ""); + bindtextdomain ("mc", LOCALEDIR); +--- mc-4.6.2/src/main.h ++++ mc-4.6.2/src/main.h +@@ -69,6 +69,7 @@ + extern int only_leading_plus_minus; + extern int output_starts_shell; + extern int midnight_shutdown; ++extern gboolean is_utf8; + extern char cmd_buf [512]; + extern const char *shell; + +--- mc-4.6.2/src/screen.c ++++ mc-4.6.2/src/screen.c +@@ -892,6 +892,9 @@ + } + #endif /* HAVE_SLANG */ + ++ vscrollbar (panel->widget, panel->widget.lines, panel->widget.cols-1, 2, 2, ++ panel->selected, panel->count, TRUE); ++ + if (panel->active) + attrset (REVERSE_COLOR); + +@@ -1493,7 +1496,7 @@ + panel->dirty = 1; + + /* Status needn't to be split */ +- usable_columns = ((panel->widget.cols-2)/((isstatus) ++ usable_columns = ((panel->widget.cols-3)/((isstatus) + ? 1 + : (panel->split+1))) - (!isstatus && panel->split); + +--- mc-4.6.2/src/widget.c ++++ mc-4.6.2/src/widget.c +@@ -1944,52 +1944,86 @@ + return in; + } + +- +-/* Listbox widget */ ++/* Vertical scrollbar widget */ + +-/* Should draw the scrollbar, but currently draws only +- * indications that there is more information +- */ +-static int listbox_cdiff (WLEntry *s, WLEntry *e); +- +-static void +-listbox_drawscroll (WListbox *l) ++void ++vscrollbar (Widget widget, int height, int width, int tpad, int bpad, ++ int selected, int count, gboolean color) + { + int line; +- int i, top; +- int max_line = l->height-1; +- ++ int i; ++ + /* Are we at the top? */ +- widget_move (&l->widget, 0, l->width); +- if (l->list == l->top) +- one_vline (); ++ widget_move (&widget, tpad, width); ++#ifndef UTF8 ++ if (!selected) ++ one_vline (); + else +- addch ('^'); ++ addch ('^'); ++#else ++ if (color) attrset (MARKED_COLOR); ++ if (is_utf8) ++ SLsmg_write_string("▴"); ++ else ++ addch ('^'); ++ if (color) attrset (NORMAL_COLOR); ++#endif + + /* Are we at the bottom? */ +- widget_move (&l->widget, max_line, l->width); +- top = listbox_cdiff (l->list, l->top); +- if ((top + l->height == l->count) || l->height >= l->count) +- one_vline (); ++ widget_move (&widget, height-1-bpad, width); ++#ifndef UTF8 ++ if (selected == count-1) ++ one_vline (); ++ else ++ addch ('v'); ++#else ++ if (color) attrset (MARKED_COLOR); ++ if (is_utf8) ++ SLsmg_write_string("▾"); + else +- addch ('v'); ++ addch('v'); ++ if (color) attrset (NORMAL_COLOR); ++#endif + + /* Now draw the nice relative pointer */ +- if (l->count) +- line = 1+ ((l->pos * (l->height-2)) / l->count); ++ if (count > 1) ++ line = tpad + 1 + ((selected * (height-3-tpad-bpad)) / (count-1)); + else +- line = 0; +- +- for (i = 1; i < max_line; i++){ +- widget_move (&l->widget, i, l->width); +- if (i != line) +- one_vline (); +- else +- addch ('*'); ++ line = 0; ++ ++ for (i = tpad + 1; i < height-1-bpad; i++){ ++ widget_move (&widget, i, width); ++ if (i != line) ++#ifndef UTF8 ++ one_vline (); ++ else ++ addch ('*'); ++#else ++ if (is_utf8) ++ SLsmg_write_string("▒"); ++ else ++ one_vline(); ++ else { ++ if (color) attrset (MARKED_COLOR); ++ if (is_utf8) ++ SLsmg_write_string("◈"); ++ else ++ addch('*'); ++ if (color) attrset (NORMAL_COLOR); ++ } ++#endif + } + } +- +-static void ++ ++ ++/* Listbox widget */ ++ ++/* Should draw the scrollbar, but currently draws only ++ * indications that there is more information ++ */ ++static int listbox_cdiff (WLEntry *s, WLEntry *e); ++ ++void + listbox_draw (WListbox *l, int focused) + { + WLEntry *e; +@@ -2032,7 +2066,7 @@ + if (!l->scrollbar) + return; + attrset (normalc); +- listbox_drawscroll (l); ++ vscrollbar (l->widget, l->height, l->width, 0, 0, l->pos, l->count, FALSE); + } + + /* Returns the number of items between s and e, +--- mc-4.6.2/src/widget.h ++++ mc-4.6.2/src/widget.h +@@ -187,6 +187,10 @@ + /* Listbox manager */ + WLEntry *listbox_get_data (WListbox *l, int pos); + ++/* Vertical scrollbar */ ++void vscrollbar (Widget widget, int height, int width, int tpad, int bpad, ++ int selected, int count, gboolean color); ++ + /* search text int listbox entries */ + WLEntry *listbox_search_text (WListbox *l, const char *text); + void listbox_select_entry (WListbox *l, WLEntry *dest); diff --git a/packages/mc/mc-4.6.2/mc-utf8-nlink.patch b/packages/mc/mc-4.6.2/mc-utf8-nlink.patch new file mode 100644 index 0000000000..9e361630c4 --- /dev/null +++ b/packages/mc/mc-4.6.2/mc-utf8-nlink.patch @@ -0,0 +1,11 @@ +--- mc-4.6.2/src/screen.c ++++ mc-4.6.2/src/screen.c +@@ -671,7 +671,7 @@ + SLsmg_write_nwchars (((wchar_t *) buffer) + + txtlen - n2, n2); + } else +- SLsmg_write_nwchars ((wchar_t *) buffer, len); ++ SLsmg_write_nwchars ((wchar_t *) buffer + still, len); + } else { + printw ("%*s", still, ""); + SLsmg_write_nwchars ((wchar_t *) buffer, txtlen); diff --git a/packages/mc/mc-4.6.2/mc-utf8.patch b/packages/mc/mc-4.6.2/mc-utf8.patch new file mode 100644 index 0000000000..5778604350 --- /dev/null +++ b/packages/mc/mc-4.6.2/mc-utf8.patch @@ -0,0 +1,5357 @@ +--- mc-4.6.2/acinclude.m4 ++++ mc-4.6.2/acinclude.m4 +@@ -399,14 +399,14 @@ + fi + + dnl Unless external S-Lang was requested, reject S-Lang with UTF-8 hacks +- if test x$with_screen = xslang; then +- : +- m4_if([$1], strict, , +- [AC_CHECK_LIB([slang], [SLsmg_write_nwchars], +- [AC_MSG_WARN([Rejecting S-Lang with UTF-8 support, \ +-it's not fully supported yet]) +- with_screen=mcslang])]) +- fi ++dnl if test x$with_screen = xslang; then ++dnl : ++dnl m4_if([$1], strict, , ++dnl [AC_CHECK_LIB([slang], [SLsmg_write_nwchars], ++dnl [AC_MSG_WARN([Rejecting S-Lang with UTF-8 support, \ ++dnl it's not fully supported yet]) ++dnl with_screen=mcslang])]) ++dnl fi + + if test x$with_screen = xslang; then + AC_DEFINE(HAVE_SYSTEM_SLANG, 1, +--- mc-4.6.2/edit/edit-widget.h ++++ mc-4.6.2/edit/edit-widget.h +@@ -30,6 +30,11 @@ + long command; + } edit_key_map_type; + ++struct action { ++ mc_wchar_t ch; ++ long flags; ++}; ++ + struct WEdit { + Widget widget; + +@@ -42,8 +47,17 @@ + /* dynamic buffers and cursor position for editor: */ + long curs1; /* position of the cursor from the beginning of the file. */ + long curs2; /* position from the end of the file */ ++#ifndef UTF8 + unsigned char *buffers1[MAXBUFF + 1]; /* all data up to curs1 */ + unsigned char *buffers2[MAXBUFF + 1]; /* all data from end of file down to curs2 */ ++#else /* UTF8 */ ++ mc_wchar_t *buffers1[MAXBUFF + 1]; /* all data up to curs1 */ ++ mc_wchar_t *buffers2[MAXBUFF + 1]; /* all data from end of file down to curs2 */ ++ ++ unsigned char charbuf[MB_LEN_MAX]; ++ int charpoint; ++#endif /* UTF8 */ ++ + + /* search variables */ + long search_start; /* First character to start searching from */ +@@ -87,7 +101,7 @@ + + /* undo stack and pointers */ + unsigned long stack_pointer; +- long *undo_stack; ++ struct action *undo_stack; + unsigned long stack_size; + unsigned long stack_size_mask; + unsigned long stack_bottom; +--- mc-4.6.2/edit/edit.c ++++ mc-4.6.2/edit/edit.c +@@ -105,7 +105,11 @@ + + static void user_menu (WEdit *edit); + ++#ifndef UTF8 + int edit_get_byte (WEdit * edit, long byte_index) ++#else ++mc_wchar_t edit_get_byte (WEdit * edit, long byte_index) ++#endif + { + unsigned long p; + if (byte_index >= (edit->curs1 + edit->curs2) || byte_index < 0) +@@ -134,7 +138,7 @@ + + edit->curs1 = 0; + edit->curs2 = 0; +- edit->buffers2[0] = g_malloc (EDIT_BUF_SIZE); ++ edit->buffers2[0] = g_malloc (EDIT_BUF_SIZE * sizeof(mc_wchar_t)); + } + + /* +@@ -159,7 +163,7 @@ + } + + if (!edit->buffers2[buf2]) +- edit->buffers2[buf2] = g_malloc (EDIT_BUF_SIZE); ++ edit->buffers2[buf2] = g_malloc (EDIT_BUF_SIZE * sizeof(mc_wchar_t)); + + mc_read (file, + (char *) edit->buffers2[buf2] + EDIT_BUF_SIZE - +@@ -169,7 +173,7 @@ + for (buf = buf2 - 1; buf >= 0; buf--) { + /* edit->buffers2[0] is already allocated */ + if (!edit->buffers2[buf]) +- edit->buffers2[buf] = g_malloc (EDIT_BUF_SIZE); ++ edit->buffers2[buf] = g_malloc (EDIT_BUF_SIZE * sizeof(mc_wchar_t)); + mc_read (file, (char *) edit->buffers2[buf], EDIT_BUF_SIZE); + } + +@@ -242,9 +246,44 @@ + { + int c; + long i = 0; +- while ((c = fgetc (f)) >= 0) { ++#ifndef UTF8 ++ while ((c = fgetc (f)) != EOF) { + edit_insert (edit, c); + i++; ++#else /* UTF8 */ ++ unsigned char buf[MB_LEN_MAX]; ++ int charpos = 0; ++ mbstate_t mbs; ++ ++ while ((c = fgetc (f)) != EOF) { ++ mc_wchar_t wc; ++ int size; ++ int j; ++ ++ buf[charpos++] = c; ++ ++ memset (&mbs, 0, sizeof (mbs)); ++ size = mbrtowc(&wc, (char *)buf, charpos, &mbs); ++ ++ if (size == -2) ++ continue; /* incomplete */ ++ ++ else if (size >= 0) { ++ edit_insert (edit, wc); ++ i++; ++ charpos = 0; ++ continue; ++ } ++ else { ++ ++ /* invalid */ ++#ifdef __STDC_ISO_10646__ ++ for (j=0; j<charpos; j++) ++ edit_insert (edit, BINARY_CHAR_OFFSET + (mc_wchar_t)buf[j]); ++#endif ++ charpos = 0; ++ } ++#endif /* UTF8 */ + } + return i; + } +@@ -252,9 +291,32 @@ + long edit_write_stream (WEdit * edit, FILE * f) + { + long i; ++#ifndef UTF8 + for (i = 0; i < edit->last_byte; i++) + if (fputc (edit_get_byte (edit, i), f) < 0) + break; ++#else /* UTF8 */ ++ for (i = 0; i < edit->last_byte; i++) { ++ mc_wchar_t wc = edit_get_byte (edit, i); ++ int res; ++ char tmpbuf[MB_LEN_MAX]; ++ mbstate_t mbs; ++ ++ memset (&mbs, 0, sizeof (mbs)); ++ ++#ifdef __STDC_ISO_10646__ ++ if (wc >= BINARY_CHAR_OFFSET && wc < (BINARY_CHAR_OFFSET + 256)) { ++ res = 1; ++ tmpbuf[0] = (char) (wc - BINARY_CHAR_OFFSET); ++ } else ++#endif ++ res = wcrtomb(tmpbuf, wc, &mbs); ++ if (res > 0) { ++ if (fwrite(tmpbuf, res, 1, f) != 1) ++ break; ++ } ++ } ++#endif /* UTF8 */ + return i; + } + +@@ -293,12 +355,46 @@ + int i, file, blocklen; + long current = edit->curs1; + unsigned char *buf; ++#ifdef UTF8 ++ mbstate_t mbs; ++ int bufstart = 0; ++ ++ memset (&mbs, 0, sizeof (mbs)); ++#endif /* UTF8 */ + if ((file = mc_open (filename, O_RDONLY | O_BINARY)) == -1) + return 0; + buf = g_malloc (TEMP_BUF_LEN); ++#ifndef UTF8 + while ((blocklen = mc_read (file, (char *) buf, TEMP_BUF_LEN)) > 0) { + for (i = 0; i < blocklen; i++) + edit_insert (edit, buf[i]); ++#else /* UTF8 */ ++ while ((blocklen = mc_read (file, (char *) buf + bufstart, TEMP_BUF_LEN - bufstart)) > 0) { ++ blocklen += bufstart; ++ bufstart = 0; ++ for (i = 0; i < blocklen; ) { ++ mc_wchar_t wc; ++ int j; ++ int size = mbrtowc(&wc, (char *)buf + i, blocklen - i, &mbs); ++ if (size == -2) { /*incomplete char*/ ++ bufstart = blocklen - i; ++ memcpy(buf, buf+i, bufstart); ++ i = blocklen; ++ memset (&mbs, 0, sizeof (mbs)); ++ } ++ else if (size <= 0) { ++#ifdef __STDC_ISO_10646__ ++ edit_insert (edit, BINARY_CHAR_OFFSET + (mc_wchar_t)buf[i]); ++#endif ++ memset (&mbs, 0, sizeof (mbs)); ++ i++; /* skip broken char */ ++ } ++ else { ++ edit_insert (edit, wc); ++ i+=size; ++ } ++ } ++#endif /* UTF8 */ + } + edit_cursor_move (edit, current - edit->curs1); + g_free (buf); +@@ -388,7 +484,11 @@ + static int + edit_load_file (WEdit *edit) + { ++#ifndef UTF8 + int fast_load = 1; ++#else /* UTF8 */ ++ int fast_load = 0; /* can't be used with multibyte characters */ ++#endif /* UTF8 */ + + /* Cannot do fast load if a filter is used */ + if (edit_find_filter (edit->filename) >= 0) +@@ -454,6 +554,7 @@ + edit->prev_col = column; + edit_move_to_prev_col (edit, edit_bol (edit, edit->curs1)); + edit_move_display (edit, line - (edit->num_widget_lines / 2)); ++ edit->charpoint = 0; + } + + /* Save cursor position in the file */ +@@ -537,7 +638,7 @@ + edit_set_filename (edit, filename); + edit->stack_size = START_STACK_SIZE; + edit->stack_size_mask = START_STACK_SIZE - 1; +- edit->undo_stack = g_malloc ((edit->stack_size + 10) * sizeof (long)); ++ edit->undo_stack = g_malloc ((edit->stack_size + 10) * sizeof (struct action)); + if (edit_load_file (edit)) { + /* edit_load_file already gives an error message */ + if (to_free) +@@ -692,14 +793,23 @@ + { + unsigned long sp = edit->stack_pointer; + unsigned long spm1; +- long *t; ++ ++ struct action *t; ++ mc_wchar_t ch = 0; ++ ++ if (c == CHAR_INSERT || c == CHAR_INSERT_AHEAD) { ++ va_list ap; ++ va_start (ap, c); ++ ch = va_arg (ap, mc_wint_t); ++ va_end (ap); ++ } + + /* first enlarge the stack if necessary */ + if (sp > edit->stack_size - 10) { /* say */ + if (option_max_undo < 256) + option_max_undo = 256; + if (edit->stack_size < (unsigned long) option_max_undo) { +- t = g_realloc (edit->undo_stack, (edit->stack_size * 2 + 10) * sizeof (long)); ++ t = g_realloc (edit->undo_stack, (edit->stack_size * 2 + 10) * sizeof (struct action)); + if (t) { + edit->undo_stack = t; + edit->stack_size <<= 1; +@@ -714,7 +824,7 @@ + #ifdef FAST_MOVE_CURSOR + if (c == CURS_LEFT_LOTS || c == CURS_RIGHT_LOTS) { + va_list ap; +- edit->undo_stack[sp] = c == CURS_LEFT_LOTS ? CURS_LEFT : CURS_RIGHT; ++ edit->undo_stack[sp].flags = c == CURS_LEFT_LOTS ? CURS_LEFT : CURS_RIGHT; + edit->stack_pointer = (edit->stack_pointer + 1) & edit->stack_size_mask; + va_start (ap, c); + c = -(va_arg (ap, int)); +@@ -725,12 +835,14 @@ + && spm1 != edit->stack_bottom + && ((sp - 2) & edit->stack_size_mask) != edit->stack_bottom) { + int d; +- if (edit->undo_stack[spm1] < 0) { +- d = edit->undo_stack[(sp - 2) & edit->stack_size_mask]; +- if (d == c) { +- if (edit->undo_stack[spm1] > -1000000000) { ++ mc_wchar_t d_ch; ++ if (edit->undo_stack[spm1].flags < 0) { ++ d = edit->undo_stack[(sp - 2) & edit->stack_size_mask].flags; ++ d_ch = edit->undo_stack[(sp - 2) & edit->stack_size_mask].ch; ++ if (d == c && d_ch == ch) { ++ if (edit->undo_stack[spm1].flags > -1000000000) { + if (c < KEY_PRESS) /* --> no need to push multiple do-nothings */ +- edit->undo_stack[spm1]--; ++ edit->undo_stack[spm1].flags--; + return; + } + } +@@ -738,19 +850,20 @@ + #ifndef NO_STACK_CURSMOVE_ANIHILATION + else if ((c == CURS_LEFT && d == CURS_RIGHT) + || (c == CURS_RIGHT && d == CURS_LEFT)) { /* a left then a right anihilate each other */ +- if (edit->undo_stack[spm1] == -2) ++ if (edit->undo_stack[spm1].flags == -2) + edit->stack_pointer = spm1; + else +- edit->undo_stack[spm1]++; ++ edit->undo_stack[spm1].flags++; + return; + } + #endif + } else { +- d = edit->undo_stack[spm1]; +- if (d == c) { ++ d = edit->undo_stack[spm1].flags; ++ d_ch = edit->undo_stack[spm1].ch; ++ if (d == c && d_ch == ch) { + if (c >= KEY_PRESS) + return; /* --> no need to push multiple do-nothings */ +- edit->undo_stack[sp] = -2; ++ edit->undo_stack[sp].flags = -2; + goto check_bottom; + } + #ifndef NO_STACK_CURSMOVE_ANIHILATION +@@ -762,7 +875,9 @@ + #endif + } + } +- edit->undo_stack[sp] = c; ++ edit->undo_stack[sp].flags = c; ++ edit->undo_stack[sp].ch = ch; ++ + check_bottom: + + edit->stack_pointer = (edit->stack_pointer + 1) & edit->stack_size_mask; +@@ -775,10 +890,10 @@ + (((unsigned long) c + 1) & edit->stack_size_mask) == edit->stack_bottom) + do { + edit->stack_bottom = (edit->stack_bottom + 1) & edit->stack_size_mask; +- } while (edit->undo_stack[edit->stack_bottom] < KEY_PRESS && edit->stack_bottom != edit->stack_pointer); ++ } while (edit->undo_stack[edit->stack_bottom].flags < KEY_PRESS && edit->stack_bottom != edit->stack_pointer); + + /*If a single key produced enough pushes to wrap all the way round then we would notice that the [stack_bottom] does not contain KEY_PRESS. The stack is then initialised: */ +- if (edit->stack_pointer != edit->stack_bottom && edit->undo_stack[edit->stack_bottom] < KEY_PRESS) ++ if (edit->stack_pointer != edit->stack_bottom && edit->undo_stack[edit->stack_bottom].flags < KEY_PRESS) + edit->stack_bottom = edit->stack_pointer = 0; + } + +@@ -787,30 +902,30 @@ + then the file should be as it was when he loaded up. Then set edit->modified to 0. + */ + static long +-pop_action (WEdit * edit) ++pop_action (WEdit * edit, struct action *c) + { +- long c; + unsigned long sp = edit->stack_pointer; + if (sp == edit->stack_bottom) { +- return STACK_BOTTOM; ++ c->flags = STACK_BOTTOM; ++ return c->flags; + } + sp = (sp - 1) & edit->stack_size_mask; +- if ((c = edit->undo_stack[sp]) >= 0) { +-/* edit->undo_stack[sp] = '@'; */ ++ *c = edit->undo_stack[sp]; ++ if (edit->undo_stack[sp].flags >= 0) { + edit->stack_pointer = (edit->stack_pointer - 1) & edit->stack_size_mask; +- return c; ++ return c->flags; + } + if (sp == edit->stack_bottom) { + return STACK_BOTTOM; + } +- c = edit->undo_stack[(sp - 1) & edit->stack_size_mask]; +- if (edit->undo_stack[sp] == -2) { +-/* edit->undo_stack[sp] = '@'; */ ++ *c = edit->undo_stack[(sp - 1) & edit->stack_size_mask]; ++ ++ if (edit->undo_stack[sp].flags == -2) { + edit->stack_pointer = sp; + } else +- edit->undo_stack[sp]++; ++ edit->undo_stack[sp].flags++; + +- return c; ++ return c->flags; + } + + /* is called whenever a modification is made by one of the four routines below */ +@@ -831,7 +946,7 @@ + */ + + void +-edit_insert (WEdit *edit, int c) ++edit_insert (WEdit *edit, mc_wchar_t c) + { + /* check if file has grown to large */ + if (edit->last_byte >= SIZE_LIMIT) +@@ -869,12 +984,11 @@ + /* add a new buffer if we've reached the end of the last one */ + if (!(edit->curs1 & M_EDIT_BUF_SIZE)) + edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE] = +- g_malloc (EDIT_BUF_SIZE); ++ g_malloc (EDIT_BUF_SIZE * sizeof(mc_wchar_t)); + + /* perform the insertion */ +- edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE][edit-> +- curs1 & M_EDIT_BUF_SIZE] +- = (unsigned char) c; ++ edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE] ++ [edit->curs1 & M_EDIT_BUF_SIZE] = c; + + /* update file length */ + edit->last_byte++; +@@ -885,7 +999,7 @@ + + + /* same as edit_insert and move left */ +-void edit_insert_ahead (WEdit * edit, int c) ++void edit_insert_ahead (WEdit * edit, mc_wchar_t c) + { + if (edit->last_byte >= SIZE_LIMIT) + return; +@@ -908,7 +1022,7 @@ + edit->last_get_rule += (edit->last_get_rule >= edit->curs1); + + if (!((edit->curs2 + 1) & M_EDIT_BUF_SIZE)) +- edit->buffers2[(edit->curs2 + 1) >> S_EDIT_BUF_SIZE] = g_malloc (EDIT_BUF_SIZE); ++ edit->buffers2[(edit->curs2 + 1) >> S_EDIT_BUF_SIZE] = g_malloc (EDIT_BUF_SIZE * sizeof(mc_wchar_t)); + edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE][EDIT_BUF_SIZE - (edit->curs2 & M_EDIT_BUF_SIZE) - 1] = c; + + edit->last_byte++; +@@ -918,7 +1032,7 @@ + + int edit_delete (WEdit * edit) + { +- int p; ++ mc_wint_t p; + if (!edit->curs2) + return 0; + +@@ -942,7 +1056,7 @@ + edit->total_lines--; + edit->force |= REDRAW_AFTER_CURSOR; + } +- edit_push_action (edit, p + 256); ++ edit_push_action (edit, CHAR_INSERT_AHEAD, p); + if (edit->curs1 < edit->start_display) { + edit->start_display--; + if (p == '\n') +@@ -956,7 +1070,7 @@ + static int + edit_backspace (WEdit * edit) + { +- int p; ++ mc_wint_t p; + if (!edit->curs1) + return 0; + +@@ -980,7 +1094,7 @@ + edit->total_lines--; + edit->force |= REDRAW_AFTER_CURSOR; + } +- edit_push_action (edit, p); ++ edit_push_action (edit, CHAR_INSERT, p); + + if (edit->curs1 < edit->start_display) { + edit->start_display--; +@@ -993,10 +1107,18 @@ + + #ifdef FAST_MOVE_CURSOR + +-static void memqcpy (WEdit * edit, unsigned char *dest, unsigned char *src, int n) ++static void memqcpy (WEdit * edit, mc_wchar_t *dest, mc_wchar_t *src, int n) + { + unsigned long next; ++#ifndef UTF8 + while ((next = (unsigned long) memccpy (dest, src, '\n', n))) { ++#else /* UTF8 */ ++ while (n) { ++ next = 0; ++ while (next < n && src[next]!='\n') next++; ++ if (next < n) next++; ++ wmemcpy (dest, src, next) ++#endif /* UTF8 */ + edit->curs_line--; + next -= (unsigned long) dest; + n -= next; +@@ -1009,7 +1131,7 @@ + edit_move_backward_lots (WEdit *edit, long increment) + { + int r, s, t; +- unsigned char *p; ++ mc_wchar_t *p; + + if (increment > edit->curs1) + increment = edit->curs1; +@@ -1049,7 +1171,7 @@ + edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE] = p; + else + edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE] = +- g_malloc (EDIT_BUF_SIZE); ++ g_malloc (EDIT_BUF_SIZE * sizeof(mc_wchar_t)); + } else { + g_free (p); + } +@@ -1087,7 +1209,7 @@ + edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE] = p; + else + edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE] = +- g_malloc (EDIT_BUF_SIZE); ++ g_malloc (EDIT_BUF_SIZE * sizeof(mc_wchar_t)); + } else { + g_free (p); + } +@@ -1120,7 +1242,7 @@ + + c = edit_get_byte (edit, edit->curs1 - 1); + if (!((edit->curs2 + 1) & M_EDIT_BUF_SIZE)) +- edit->buffers2[(edit->curs2 + 1) >> S_EDIT_BUF_SIZE] = g_malloc (EDIT_BUF_SIZE); ++ edit->buffers2[(edit->curs2 + 1) >> S_EDIT_BUF_SIZE] = g_malloc (EDIT_BUF_SIZE * sizeof(mc_wchar_t)); + edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE][EDIT_BUF_SIZE - (edit->curs2 & M_EDIT_BUF_SIZE) - 1] = c; + edit->curs2++; + c = edit->buffers1[(edit->curs1 - 1) >> S_EDIT_BUF_SIZE][(edit->curs1 - 1) & M_EDIT_BUF_SIZE]; +@@ -1144,7 +1266,7 @@ + + c = edit_get_byte (edit, edit->curs1); + if (!(edit->curs1 & M_EDIT_BUF_SIZE)) +- edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE] = g_malloc (EDIT_BUF_SIZE); ++ edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE] = g_malloc (EDIT_BUF_SIZE * sizeof(mc_wchar_t)); + edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE][edit->curs1 & M_EDIT_BUF_SIZE] = c; + edit->curs1++; + c = edit->buffers2[(edit->curs2 - 1) >> S_EDIT_BUF_SIZE][EDIT_BUF_SIZE - ((edit->curs2 - 1) & M_EDIT_BUF_SIZE) - 1]; +@@ -1249,7 +1371,7 @@ + q = edit->last_byte + 2; + + for (col = 0, p = current; p < q; p++) { +- int c; ++ mc_wchar_t c; + if (cols != -10) { + if (col == cols) + return p; +@@ -1267,7 +1389,7 @@ + } else if (c < 32 || c == 127) + col += 2; /* Caret notation for control characters */ + else +- col++; ++ col += wcwidth(c); + } + return col; + } +@@ -1400,12 +1522,16 @@ + is_blank (WEdit *edit, long offset) + { + long s, f; +- int c; ++ mc_wchar_t c; + s = edit_bol (edit, offset); + f = edit_eol (edit, offset) - 1; + while (s <= f) { + c = edit_get_byte (edit, s++); ++#ifndef UTF8 + if (!isspace (c)) ++#else ++ if (!iswspace (c)) ++#endif /* UTF8 */ + return 0; + } + return 1; +@@ -1660,6 +1786,7 @@ + return 2; + return 0x80000000UL; + } ++#ifndef UTF8 + if (isupper (c)) + c = 'A'; + else if (islower (c)) +@@ -1670,6 +1797,18 @@ + c = '0'; + else if (isspace (c)) + c = ' '; ++#else ++ if (iswupper (c)) ++ c = 'A'; ++ else if (iswlower (c) |
