diff -wur nano-cvs/src/winio.c nano-new/src/winio.c --- nano-cvs/src/winio.c 2006-05-26 22:14:04.000000000 +0200 +++ nano-new/src/winio.c 2006-05-27 15:45:54.000000000 +0200 @@ -1252,7 +1252,7 @@ } /* Translate a Unicode sequence: turn a six-digit hexadecimal number - * from 000000 to 10FFFF (case-insensitive) into its corresponding + * (from 000000 to 10FFFF, case-insensitive) into its corresponding * multibyte value. */ long get_unicode_kbinput(int kbinput) { @@ -1260,97 +1260,67 @@ static long uni = 0; long retval = ERR; + long add_unicode_digit(int kbinput, int factor) + { + long retval = ERR; + + if ('0' <= kbinput && kbinput <= '9') + uni += (kbinput - '0') * factor; + else if ('a' <= tolower(kbinput) && tolower(kbinput) <= 'f') + uni += (tolower(kbinput) - 'a' + 10) * factor; + else { + /* If the character is out of range, save it as the result. */ + retval = kbinput; + statusbar(_("Cancelled")); + } + + return retval; + } + /* Increment the Unicode digit counter. */ uni_digits++; switch (uni_digits) { case 1: - /* One digit: reset the Unicode sequence holder and add the - * digit we got to the 0x100000's position of the Unicode - * sequence holder. */ - uni = 0; - if ('0' <= kbinput && kbinput <= '1') - uni += (kbinput - '0') * 0x100000; - else - /* If the character we got isn't a hexadecimal digit, or - * if it is and it would put the Unicode sequence out of - * valid range, save it as the result. */ + /* First digit: must be zero or one. Put it in the + * 0x100000's position of the Unicode sequence holder. */ + if ('0' <= kbinput && kbinput <= '1') { + uni = (kbinput - '0') * 0x100000; + statusbar(_("Unicode Input")); + } else + /* This isn't the start of a Unicode; return the typed + * character as the result. */ retval = kbinput; break; case 2: - /* Two digits: add the digit we got to the 0x10000's - * position of the Unicode sequence holder. */ - if ('0' == kbinput || (uni < 0x100000 && '1' <= kbinput && - kbinput <= '9')) - uni += (kbinput - '0') * 0x10000; - else if (uni < 0x100000 && 'a' <= tolower(kbinput) && - tolower(kbinput) <= 'f') - uni += (tolower(kbinput) + 10 - 'a') * 0x10000; - else - /* If the character we got isn't a hexadecimal digit, or - * if it is and it would put the Unicode sequence out of - * valid range, save it as the result. */ + /* Second digit: must be zero if the first was one, may be + * any hexadecimal value if the first was zero. */ + if (kbinput == '0' || uni == 0 ) + retval = add_unicode_digit(kbinput, 0x10000); + else { retval = kbinput; + statusbar(_("Cancelled")); + } break; case 3: - /* Three digits: add the digit we got to the 0x1000's - * position of the Unicode sequence holder. */ - if ('0' <= kbinput && kbinput <= '9') - uni += (kbinput - '0') * 0x1000; - else if ('a' <= tolower(kbinput) && tolower(kbinput) <= 'f') - uni += (tolower(kbinput) + 10 - 'a') * 0x1000; - else - /* If the character we got isn't a hexadecimal digit, or - * if it is and it would put the Unicode sequence out of - * valid range, save it as the result. */ - retval = kbinput; + retval = add_unicode_digit(kbinput, 0x1000); break; case 4: - /* Four digits: add the digit we got to the 0x100's position - * of the Unicode sequence holder. */ - if ('0' <= kbinput && kbinput <= '9') - uni += (kbinput - '0') * 0x100; - else if ('a' <= tolower(kbinput) && tolower(kbinput) <= 'f') - uni += (tolower(kbinput) + 10 - 'a') * 0x100; - else - /* If the character we got isn't a hexadecimal digit, or - * if it is and it would put the Unicode sequence out of - * valid range, save it as the result. */ - retval = kbinput; + retval = add_unicode_digit(kbinput, 0x100); break; case 5: - /* Five digits: add the digit we got to the 0x10's position - * of the Unicode sequence holder. */ - if ('0' <= kbinput && kbinput <= '9') - uni += (kbinput - '0') * 0x10; - else if ('a' <= tolower(kbinput) && tolower(kbinput) <= 'f') - uni += (tolower(kbinput) + 10 - 'a') * 0x10; - else - /* If the character we got isn't a hexadecimal digit, or - * if it is and it would put the Unicode sequence out of - * valid range, save it as the result. */ - retval = kbinput; + retval = add_unicode_digit(kbinput, 0x10); break; case 6: - /* Six digits: add the digit we got to the 1's position of - * the Unicode sequence holder, and save the corresponding - * Unicode value as the result. */ - if ('0' <= kbinput && kbinput <= '9') { - uni += (kbinput - '0'); + retval = add_unicode_digit(kbinput, 0x1); + /* If the last charcater was a valid hexadecimal value, + * then the Unicode is complete. */ + if (retval == ERR) retval = uni; - } else if ('a' <= tolower(kbinput) && tolower(kbinput) <= - 'f') { - uni += (tolower(kbinput) + 10 - 'a'); - retval = uni; - } else - /* If the character we got isn't a hexadecimal digit, or - * if it is and it would put the Unicode sequence out of - * valid range, save it as the result. */ - retval = kbinput; break; default: - /* More than six digits: save the character we got as the - * result. */ + /* XXX More than six digits: could this ever happen? + * Produce an error instead of returning a value? */ retval = kbinput; break; }