Re: utf8 patch for mc, slang 2 version

2006-06-16 Thread Bart Oldeman
On Thu, 15 Jun 2006, Egmont Koblinger wrote:

 Anyway, there are plenty of apps (e.g. vim, joe) that perfectly support
 UTF-8 and use ncurses (not the w version). I wonder how it is possible...

Because they only use the terminfo (low-level) parts of ncurses, see man 
3ncurses terminfo. Those parts do not care about UTF-8.

MC uses a higher level part of ncurses (the display routines), but 
restricted to stdscr.

There's an even higher level part of ncurses that supports managing
(overlapping) windows, but MC does not use it. SLang (without the newt 
library) does not support that. So one advantage of using ncurses over 
slang is that MC could make use of ncurses' windowing code, thereby 
simplifying its own code. In the way that MC uses SLang and ncurses 
right now there is very little difference between the two libraries.

If you google (groups) for it (Miguel's posts) you'll find that around 
'95/'96 SLang was preferred over ncurses because it was faster, smaller, 
and less buggy. But that is no longer the case, there is not much 
difference now.

Bart



___
Mc-devel mailing list
http://mail.gnome.org/mailman/listinfo/mc-devel


Re: utf8 patch for mc, slang 2 version

2006-06-14 Thread Bart Oldeman
On Wed, 14 Jun 2006, Egmont Koblinger wrote:

 On Tue, Jun 13, 2006 at 07:14:41PM +0200, Tomasz K?oczko wrote:

 BTW: anyone is working on UFT-8 support for ncurses(w) backend ?

 I don't think so, and I don't think it is worth it. Maintaining two backends
 IMHO just causes headaches while it doesn't make mc better. I still can't
 see why developers do not decide which one to use and drop the other one.

Maybe compatibility with older UN*Xes with curses but no slang?

 With Unicode support maintaining the two will be much harder since AFAIK
 slang works with UTF-8 while ncurses uses UCS-4. Hence a completely
 different patch would be required for the two cases.

Last time I played with it ncursesw (but not plain ncurses) handled UTF-8 
just fine.

e.g. you can pass a UTF-8 encoded string to addstr(), and provided the
locale is set correctly, ncursesw will compute its width correctly. It is 
*also* possible to use addwstr() with UCS-4, but not compulsory.

Bart

___
Mc-devel mailing list
http://mail.gnome.org/mailman/listinfo/mc-devel


Re: some problems with do_*_ca_mode()

2005-11-24 Thread Bart Oldeman

On Thu, 24 Nov 2005, Andrey V. Malyshev wrote:


JN #ifdef HAVE_SLANG
JN   SLtt_write_string (ti_cap);
JN #else
JN   putp (ti_cap);
JN #endif
JN and similarly for the te_cap.

I argee, of course. Modified patch is attached.


You could also just fprintf the string to stdout. As far as I can see the 
main aim of your patch is to get the information out of terminfo.


also I think that the test

   if ((!xterm_flag)||(!ti_cap))
  return;

can simply be

   if (!ti_cap)
 return;


JN The question is whether not to call SLtt_initialize () and friends in
JN case of slang instead as slang takes care of setting proper ti/te
JN sequences itself.

Hmm. For now we combine this approaches: we call SLtt_initialize (), we  let
slang to take care of init itselt and prepare the SLtt_tgetstr() to work.
And then we use it to obtain ti/te sequences using proper slang mechanisms.

And the same in ncurses case, BTW.

The main points are:

from main():

#ifdef HAVE_SLANG
(1)slang_init () - [ SLtt_get_terminfo() - SLtt_initialize() -
Term_Init_Str = SLtt_tgetstr (ti) ]
#else
(2)init_curses () - [ initscr() - setupterm() ]
#endif
   init_xterm_support ();

Using [] brackets I've marked slang internal code at (1) and ncurses
internal code at (2).
The Term_Init_Str is internal slang variable, and it is unavailable for us
in common case. This is correct for current mcslang and libslang-1.4.9 both.

So, what prevents us from calling the same SLtt_tgetstr (ti) routine from
init_xterm_support() under #ifdef HAVE_SLANG?


it's just double work... look here:
main() - init_curses() - [ SLsmg_init_smg() - tt_init_video() (set to 
SLtt_init_video()) - tt_write_string (Term_Init_Str); ]


Bart

___
Mc-devel mailing list
http://mail.gnome.org/mailman/listinfo/mc-devel


Re: some problems with do_*_ca_mode()

2005-11-24 Thread Bart Oldeman

On Thu, 24 Nov 2005, Andrey V. Malyshev wrote:


BO it's just double work... look here:
BO main() - init_curses() - [ SLsmg_init_smg() - tt_init_video() (set
BO to SLtt_init_video()) - tt_write_string (Term_Init_Str); ]

You are right *. It is an overlook on my part :)
As far as I understand, using this we will necessarily need to add
SLsmg_reset_smg() call on exit, in slang_shutdown().


endwin() does that already as far as I can see.


Lets answer the previous question (for ncurses case) and I'll rewrite the
patch once more.


There is more going on. ncurses also automatically sends 
the relevant string automatically, in _nc_mvcur_init() (called via 
newterm() from initscr(), in the ncurses source code).


I wonder what the purpose is of do_enter_ca_mode now. Maybe it is just a 
left-over, necessary for other (non-ncurses) curses libraries, or xterms 
with broken terminfo's.



(*) By the way: in the slvideo.c file is defined another  SLtt_init_video()
function. It what cases this file is used instead of sldisply.c? I could not
understand off-hand. Looks like MSDOS-version :)


Yes, there are variations for various other operating systems/environments 
there.


Bart
___
Mc-devel mailing list
http://mail.gnome.org/mailman/listinfo/mc-devel


Re: mcslang2

2005-09-27 Thread Bart Oldeman

On Tue, 27 Sep 2005, Leonard den Ottolander wrote:


All the discussion about slang2 and the utf-8 patch has inspired me to
create an internal version of slang-2.0.4 to mc. This patch might still
be somewhat rough around the edges, but it builds after a configure
--with-screen=mcslang2. Please review.


just wondering, but why do you intend to keep two internal versions of 
slang? As slang2 is backwards compatible with slang1 (except for a few 
details that don't affect mc) it seems simpler to just upgrade the contents

of the slang directory?

And, no, -lslang2 doesn't make sense. It's just -lslang for both slang1 
and slang2.


Bart

___
Mc-devel mailing list
http://mail.gnome.org/mailman/listinfo/mc-devel


Re: [PATCH] eliminate buffer in screen.c

2005-08-29 Thread Bart Oldeman

On Sat, 27 Aug 2005, Pavel Tsekov wrote:


The text passed to add_permission_string as the first argument is supposed
to be justfied but your patch will sent is just as is . Did I get it wrong
?


No, you were right.
For octal permissions right alignment is used but the field is not 
expandable, so advancing txt by strlen(txt) - width is enough to get the 
right-aligned string (just chopping off the left-most digits really).


For non-octal permissions left alignment is used and that works.
Below is the adjusted patch.

Bart

--- screen.c.~1.216.~   2005-08-27 15:51:38.0 +1200
+++ screen.c2005-08-29 23:01:32.0 +1200
@@ -137,7 +137,7 @@

 /* This code relies on the default justification!!! */
 static void
-add_permission_string (char *dest, int width, file_entry *fe, int attr, int 
color, int is_octal)
+add_permission_string (const char *txt, int width, file_entry *fe, int attr, 
int color, int is_octal)
 {
 int i, r, l;

@@ -145,6 +145,7 @@

 if (is_octal){
/* Place of the access bit in octal mode */
+   txt += strlen(txt) - width;
 l = width + l - 3;
r = l + 1;
 } else {
@@ -162,7 +163,7 @@
 } else
 attrset (color);

-   addch (dest[i]);
+   addch (txt[i]);
 }
 }

@@ -450,15 +451,12 @@
 { dot,   1,  0, J_RIGHT,,  0, string_dot, NULL },
 };

-static char *
-to_buffer (char *dest, int just_mode, int len, const char *txt)
+static void
+add_string (int just_mode, int len, const char *txt)
 {
 int txtlen = strlen (txt);
 int still, over;

-/* Fill buffer with spaces */
-memset (dest, ' ', len);
-
 still = (over=(txtlen  len)) ? (txtlen - len) : (len - txtlen);

 switch (HIDE_FIT(just_mode)){
@@ -475,15 +473,11 @@

 if (over){
if (IS_FIT(just_mode))
-   strcpy (dest, name_trunc(txt, len));
+   addstr (name_trunc(txt, len));
else
-   strncpy (dest, txt+still, len);
+   printw (%*s, len, txt+still);
 } else
-   strncpy (dest+still, txt, txtlen);
-
-dest[len] = '\0';
-
-return (dest + len);
+   printw (%*s%-*s, still, , len-still, txt);
 }

 static int
@@ -537,14 +531,12 @@
 return (NORMAL_COLOR);
 }

-/* Formats the file number file_index of panel in the buffer dest */
+/* Displays the file number file_index of panel */
 static void
-format_file (char *dest, int limit, WPanel *panel, int file_index, int width, 
int attr, int isstatus)
+display_file (WPanel *panel, int file_index, int width, int attr, int isstatus)
 {
 int  color, length, empty_line;
 const char *txt;
-char *old_pos;
-char *cdest = dest;
 format_e *format, *home;
 file_entry *fe;

@@ -571,26 +563,21 @@
else
txt = (*format-string_fn)(fe, format-field_len);

-   old_pos = cdest;
-
len = format-field_len;
if (len + length  width)
len = width - length;
-   if (len + (cdest - dest)  limit)
-   len = limit - (cdest - dest);
if (len = 0)
break;
-   cdest = to_buffer (cdest, format-just_mode, len, txt);
length += len;

 attrset (color);

 if (permission_mode  !strcmp(format-id, perm))
-add_permission_string (old_pos, format-field_len, fe, attr, 
color, 0);
+add_permission_string (txt, format-field_len, fe, attr, 
color, 0);
 else if (permission_mode  !strcmp(format-id, mode))
-add_permission_string (old_pos, format-field_len, fe, attr, 
color, 1);
+add_permission_string (txt, format-field_len, fe, attr, 
color, 1);
 else
-   addstr (old_pos);
+   add_string (format-just_mode, len, txt);

} else {
 if (attr == SELECTED || attr == MARKED_SELECTED)
@@ -614,7 +601,6 @@
 {
 intsecond_column = 0;
 int   width, offset;
-char   buffer [BUF_MEDIUM];

 offset = 0;
 if (!isstatus  panel-split){
@@ -643,7 +629,7 @@
widget_move (panel-widget, file_index - panel-top_file + 2, 1);
 }

-format_file (buffer, sizeof(buffer), panel, file_index, width, attr, 
isstatus);
+display_file (panel, file_index, width, attr, isstatus);

 if (!isstatus  panel-split){
if (second_column)
___
Mc-devel mailing list
http://mail.gnome.org/mailman/listinfo/mc-devel


[PATCH] eliminate buffer in screen.c

2005-08-27 Thread Bart Oldeman

Hi,

this patch was inspired by the UTF8 patch used by various distributions.
This is just a clean up: I realized that buffer[] in repaint_file is 
unnecessary. Instead of formatting into this buffer and then using addstr() one 
can just addstr and printw directly.


Just for the record: I (but then I'm an outsider, so this opinion can be 
completely worthless, take it with a big grain of salt ;) don't think using 
arrays of wchar_t (like in ecs.c) is the right approach for mc, at least 
outside the editor. Rather strings can just be kept UTF8 (or a few other mb 
encodings such as EUC-JP perhaps, but Slang only supports UTF8, that would be 
ncurses only then).


What is needed (IMHO) are a few support functions that calculate the width of a 
(partial) multibyte string, and the byte length of a substring that matches a 
certain width. It's the width that matters namely, not the number of characters 
in the corresponding wchar_t string: think of double-width and combining 
characters.


Bart

2005-08-27  Bart Oldeman  [EMAIL PROTECTED]

* screen.c (add_permission_string): Use const for dest.
* screen.c (to_buffer): Rename to add_string. Output directly to
  the screen instead of storing the output into a buffer.
* screen.c (format_file): Rename to display_file. Eliminate dest
  buffer.
* screen.c (repaint_file): Eliminate buffer.

--- screen.c.~1.216.~   2005-08-27 15:51:38.0 +1200
+++ screen.c2005-08-27 18:48:23.0 +1200
@@ -137,7 +137,7 @@

 /* This code relies on the default justification!!! */
 static void
-add_permission_string (char *dest, int width, file_entry *fe, int attr, int 
color, int is_octal)
+add_permission_string (const char *dest, int width, file_entry *fe, int attr, 
int color, int is_octal)
 {
 int i, r, l;

@@ -450,15 +450,12 @@
 { dot,   1,  0, J_RIGHT,,  0, string_dot, NULL },
 };

-static char *
-to_buffer (char *dest, int just_mode, int len, const char *txt)
+static void
+add_string (int just_mode, int len, const char *txt)
 {
 int txtlen = strlen (txt);
 int still, over;

-/* Fill buffer with spaces */
-memset (dest, ' ', len);
-
 still = (over=(txtlen  len)) ? (txtlen - len) : (len - txtlen);

 switch (HIDE_FIT(just_mode)){
@@ -475,15 +472,11 @@

 if (over){
if (IS_FIT(just_mode))
-   strcpy (dest, name_trunc(txt, len));
+   addstr (name_trunc(txt, len));
else
-   strncpy (dest, txt+still, len);
+   printw (%*s, len, txt+still);
 } else
-   strncpy (dest+still, txt, txtlen);
-
-dest[len] = '\0';
-
-return (dest + len);
+   printw (%*s%-*s, still, , len-still, txt);
 }

 static int
@@ -537,14 +530,12 @@
 return (NORMAL_COLOR);
 }

-/* Formats the file number file_index of panel in the buffer dest */
+/* Displays the file number file_index of panel */
 static void
-format_file (char *dest, int limit, WPanel *panel, int file_index, int width, 
int attr, int isstatus)
+display_file (WPanel *panel, int file_index, int width, int attr, int isstatus)
 {
 int  color, length, empty_line;
 const char *txt;
-char *old_pos;
-char *cdest = dest;
 format_e *format, *home;
 file_entry *fe;

@@ -571,26 +562,21 @@
else
txt = (*format-string_fn)(fe, format-field_len);

-   old_pos = cdest;
-
len = format-field_len;
if (len + length  width)
len = width - length;
-   if (len + (cdest - dest)  limit)
-   len = limit - (cdest - dest);
if (len = 0)
break;
-   cdest = to_buffer (cdest, format-just_mode, len, txt);
length += len;

 attrset (color);

 if (permission_mode  !strcmp(format-id, perm))
-add_permission_string (old_pos, format-field_len, fe, attr, 
color, 0);
+add_permission_string (txt, format-field_len, fe, attr, 
color, 0);
 else if (permission_mode  !strcmp(format-id, mode))
-add_permission_string (old_pos, format-field_len, fe, attr, 
color, 1);
+add_permission_string (txt, format-field_len, fe, attr, 
color, 1);
 else
-   addstr (old_pos);
+   add_string (format-just_mode, len, txt);

} else {
 if (attr == SELECTED || attr == MARKED_SELECTED)
@@ -614,7 +600,6 @@
 {
 intsecond_column = 0;
 int   width, offset;
-char   buffer [BUF_MEDIUM];

 offset = 0;
 if (!isstatus  panel-split){
@@ -643,7 +628,7 @@
widget_move (panel-widget, file_index - panel-top_file + 2, 1);
 }

-format_file (buffer, sizeof(buffer), panel, file_index, width, attr, 
isstatus);
+display_file (panel, file_index, width, attr, isstatus);

 if (!isstatus  panel-split){
if (second_column