Patch from Yoshida Masato to fill in the missing pieces of Windows
[u/mdw/putty] / terminal.c
index 08ce42e..d23cbe9 100644 (file)
@@ -3016,8 +3016,8 @@ static void term_out(Terminal *term)
                        width = 1;
                    if (!width)
                        width = (term->cjk_ambig_wide ?
-                                mk_wcwidth_cjk((wchar_t) c) :
-                                mk_wcwidth((wchar_t) c));
+                                mk_wcwidth_cjk((unsigned int) c) :
+                                mk_wcwidth((unsigned int) c));
 
                    if (term->wrapnext && term->wrap && width > 0) {
                        cline->lattr |= LATTR_WRAPPED;
@@ -4692,7 +4692,7 @@ static termchar *term_bidi_line(Terminal *term, struct termline *ldata,
                }
 
                term->wcFrom[it].origwc = term->wcFrom[it].wc =
-                   (wchar_t)uc;
+                   (unsigned int)uc;
                term->wcFrom[it].index = it;
            }
 
@@ -5067,10 +5067,17 @@ static void do_paint(Terminal *term, Context ctx, int may_optimise)
                dirty_run = TRUE;
            }
 
-           if (ccount >= chlen) {
+           if (ccount+2 > chlen) {
                chlen = ccount + 256;
                ch = sresize(ch, chlen, wchar_t);
            }
+
+#ifdef PLATFORM_IS_UTF16
+           if (tchar > 0x10000 && tchar < 0x110000) {
+               ch[ccount++] = (wchar_t) HIGH_SURROGATE_OF(tchar);
+               ch[ccount++] = (wchar_t) LOW_SURROGATE_OF(tchar);
+           } else
+#endif /* PLATFORM_IS_UTF16 */
            ch[ccount++] = (wchar_t) tchar;
 
            if (d->cc_next) {
@@ -5094,10 +5101,17 @@ static void do_paint(Terminal *term, Context ctx, int may_optimise)
                        break;
                    }
 
-                   if (ccount >= chlen) {
+                   if (ccount+2 > chlen) {
                        chlen = ccount + 256;
                        ch = sresize(ch, chlen, wchar_t);
                    }
+
+#ifdef PLATFORM_IS_UTF16
+                   if (schar > 0x10000 && schar < 0x110000) {
+                       ch[ccount++] = (wchar_t) HIGH_SURROGATE_OF(schar);
+                       ch[ccount++] = (wchar_t) LOW_SURROGATE_OF(schar);
+                   } else
+#endif /* PLATFORM_IS_UTF16 */
                    ch[ccount++] = (wchar_t) schar;
                }
 
@@ -6604,7 +6618,7 @@ int term_get_userpass_input(Terminal *term, prompts_t *p,
        {
            int i;
            for (i = 0; i < (int)p->n_prompts; i++)
-               memset(p->prompts[i]->result, 0, p->prompts[i]->result_len);
+                prompt_set_result(p->prompts[i], "");
        }
     }
 
@@ -6631,8 +6645,8 @@ int term_get_userpass_input(Terminal *term, prompts_t *p,
              case 10:
              case 13:
                term_data(term, 0, "\r\n", 2);
+                prompt_ensure_result_size(pr, s->pos + 1);
                pr->result[s->pos] = '\0';
-               pr->result[pr->result_len - 1] = '\0';
                /* go to next prompt, if any */
                s->curr_prompt++;
                s->done_prompt = 0;
@@ -6667,10 +6681,9 @@ int term_get_userpass_input(Terminal *term, prompts_t *p,
                 * when we're doing password input, because some people
                 * have control characters in their passwords.
                 */
-               if ((!pr->echo ||
-                    (c >= ' ' && c <= '~') ||
-                    ((unsigned char) c >= 160))
-                   && s->pos < pr->result_len - 1) {
+               if (!pr->echo || (c >= ' ' && c <= '~') ||
+                    ((unsigned char) c >= 160)) {
+                    prompt_ensure_result_size(pr, s->pos + 1);
                    pr->result[s->pos++] = c;
                    if (pr->echo)
                        term_data(term, 0, &c, 1);