Hi,

let's start tackling the last file which is using stuff from charset.c:
the file cmdbuf.c.  The first dirty function is cmd_putstr().
Fortunately, it doesn't actually need to handle non-ASCII characters.

The function cmd_putstr() is called only from command.c.
Almost all callers pass literal ASCII strings.
The only exception is start_mca(), which passes on its second argument.
Again, almost all callers of start_mca() pass literal ASCII strings.
The only exception is mca_opt_char(), which passes the return value
of opt_prompt(), defined in option.c.

The argument of opt_prompt() is the static variable curropt,
which is only set to non-NULL from findopt_name() or findopt() in opttbl.c.
Both of these functions only ever return literal ASCII strings contained
in the static struct loption option[].

To summarize, cmd_putstr() is only ever called with ASCII strings,
so it can be radically simplified, deleting two LWCHAR variables,
one call to step_char(), is_composing_char(), is_combining_char(),
and is_wide_char() each.

OK?
  Ingo


Index: cmdbuf.c
===================================================================
RCS file: /cvs/src/usr.bin/less/cmdbuf.c,v
retrieving revision 1.16
diff -u -p -r1.16 cmdbuf.c
--- cmdbuf.c    17 Sep 2016 15:06:41 -0000      1.16
+++ cmdbuf.c    9 May 2019 12:22:51 -0000
@@ -117,29 +117,16 @@ clear_cmd(void)
 }
 
 /*
- * Display a string, usually as a prompt for input into the command buffer.
+ * Display an ASCII string, usually as a prompt for input,
+ * into the command buffer.
  */
 void
 cmd_putstr(char *s)
 {
-       LWCHAR prev_ch = 0;
-       LWCHAR ch;
-       char *endline = s + strlen(s);
        while (*s != '\0') {
-               char *ns = s;
-               ch = step_char(&ns, +1, endline);
-               while (s < ns)
-                       putchr(*s++);
-               if (!utf_mode) {
-                       cmd_col++;
-                       prompt_col++;
-               } else if (!is_composing_char(ch) &&
-                   !is_combining_char(prev_ch, ch)) {
-                       int width = is_wide_char(ch) ? 2 : 1;
-                       cmd_col += width;
-                       prompt_col += width;
-               }
-               prev_ch = ch;
+               putchr(*s++);
+               cmd_col++;
+               prompt_col++;
        }
 }
 

Reply via email to