per Benno Schulenberg's patch with a few tweaks by me, if we're using

verbatim input to enter a Unicode sequence, indicate it on the
statusbar; also, refactor the Unicode sequence handler function to
remove redundant code


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@3581 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
David Lawrence Ramsey 2006-05-27 15:52:26 +00:00
parent 9a5139e9d3
commit 12e3708ead
3 changed files with 99 additions and 108 deletions

View File

@ -109,6 +109,12 @@ CVS code -
its description across all documentation. Changes to nano.1, its description across all documentation. Changes to nano.1,
nanorc.5, nanorc.sample, and nano.texi. (Benno Schulenberg and nanorc.5, nanorc.sample, and nano.texi. (Benno Schulenberg and
DLR) DLR)
- If we're using verbatim input to enter a Unicode sequence,
indicate it on the statusbar. Also, refactor the Unicode
sequence handler function to remove redundant code. New
function add_unicode_digit(); changes to get_unicode_input()
and parse_verbatim_kninput(). (Benno Schulenberg, minor tweaks
by DLR)
- browser.c: - browser.c:
do_browser() do_browser()
- Reference NANO_GOTODIR_(ALT|F)?KEY instead of - Reference NANO_GOTODIR_(ALT|F)?KEY instead of
@ -295,6 +301,7 @@ CVS code -
get_byte_kbinput() get_byte_kbinput()
- Fix typo preventing Esc Esc 3 through Esc Esc 6 from being - Fix typo preventing Esc Esc 3 through Esc Esc 6 from being
interpreted as control key sequences. (DLR) interpreted as control key sequences. (DLR)
- Tweak to more closely match get_unicode_kbinput(). (DLR)
get_control_kbinput() get_control_kbinput()
- Add Ctrl-/ as an alias for Ctrl-_. (DLR, found by Benno - Add Ctrl-/ as an alias for Ctrl-_. (DLR, found by Benno
Schulenberg) Schulenberg)

View File

@ -729,6 +729,7 @@ int get_escape_seq_abcd(int kbinput);
int parse_escape_seq_kbinput(int kbinput); int parse_escape_seq_kbinput(int kbinput);
int get_byte_kbinput(int kbinput); int get_byte_kbinput(int kbinput);
long get_unicode_kbinput(int kbinput); long get_unicode_kbinput(int kbinput);
long add_unicode_digit(int kbinput, long factor, long *uni);
int get_control_kbinput(int kbinput); int get_control_kbinput(int kbinput);
void unparse_kbinput(char *output, size_t output_len); void unparse_kbinput(char *output, size_t output_len);
int *get_verbatim_kbinput(WINDOW *win, size_t *kbinput_len); int *get_verbatim_kbinput(WINDOW *win, size_t *kbinput_len);

View File

@ -1180,8 +1180,8 @@ int parse_escape_seq_kbinput(int kbinput)
return retval; return retval;
} }
/* Translate a byte sequence: turn a three-digit decimal number from /* Translate a byte sequence: turn a three-digit decimal number (from
* 000 to 255 into its corresponding byte value. */ * 000 to 255) into its corresponding byte value. */
int get_byte_kbinput(int kbinput) int get_byte_kbinput(int kbinput)
{ {
static int byte_digits = 0, byte = 0; static int byte_digits = 0, byte = 0;
@ -1192,47 +1192,49 @@ int get_byte_kbinput(int kbinput)
switch (byte_digits) { switch (byte_digits) {
case 1: case 1:
/* One digit: reset the byte sequence holder and add the /* First digit: This must be from zero to two. Put it in
* digit we got to the 100's position of the byte sequence * the 100's position of the byte sequence holder. */
* holder. */
byte = 0;
if ('0' <= kbinput && kbinput <= '2') if ('0' <= kbinput && kbinput <= '2')
byte += (kbinput - '0') * 100; byte = (kbinput - '0') * 100;
else else
/* If the character we got isn't a decimal digit, or if /* This isn't the start of a byte sequence. Return this
* it is and it would put the byte sequence out of byte * character as the result. */
* range, save it as the result. */
retval = kbinput; retval = kbinput;
break; break;
case 2: case 2:
/* Two digits: add the digit we got to the 10's position of /* Second digit: This must be from zero to five if the first
* the byte sequence holder. */ * was two, and may be any decimal value if the first was
* zero or one. Put it in the 10's position of the byte
* sequence holder. */
if (('0' <= kbinput && kbinput <= '5') || (byte < 200 && if (('0' <= kbinput && kbinput <= '5') || (byte < 200 &&
'6' <= kbinput && kbinput <= '9')) '6' <= kbinput && kbinput <= '9'))
byte += (kbinput - '0') * 10; byte += (kbinput - '0') * 10;
else else
/* If the character we got isn't a decimal digit, or if /* This isn't the second digit of a byte sequence.
* it is and it would put the byte sequence out of byte * Return this character as the result. */
* range, save it as the result. */
retval = kbinput; retval = kbinput;
break; break;
case 3: case 3:
/* Three digits: add the digit we got to the 1's position of /* Third digit: This must be from zero to five if the first
* the byte sequence holder, and save the corresponding byte * was two and the second was between zero and five, and may
* value as the result. */ * be any decimal value if the first was zero or one and the
* second was between six and nine. Put it in the 1's
* position of the byte sequence holder. */
if (('0' <= kbinput && kbinput <= '5') || (byte < 250 && if (('0' <= kbinput && kbinput <= '5') || (byte < 250 &&
'6' <= kbinput && kbinput <= '9')) { '6' <= kbinput && kbinput <= '9')) {
byte += (kbinput - '0'); byte += (kbinput - '0');
/* If this character is a valid decimal value, then the
* byte sequence is complete. */
retval = byte; retval = byte;
} else } else
/* If the character we got isn't a decimal digit, or if /* This isn't the third digit of a byte sequence.
* it is and it would put the byte sequence out of byte * Return this character as the result. */
* range, save it as the result. */
retval = kbinput; retval = kbinput;
break; break;
default: default:
/* More than three digits: save the character we got as the /* If there are more than three digits, return this
* result. */ * character as the result. (Maybe we should produce an
* error instead?) */
retval = kbinput; retval = kbinput;
break; break;
} }
@ -1252,7 +1254,7 @@ int get_byte_kbinput(int kbinput)
} }
/* Translate a Unicode sequence: turn a six-digit hexadecimal number /* 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. */ * multibyte value. */
long get_unicode_kbinput(int kbinput) long get_unicode_kbinput(int kbinput)
{ {
@ -1265,92 +1267,57 @@ long get_unicode_kbinput(int kbinput)
switch (uni_digits) { switch (uni_digits) {
case 1: case 1:
/* One digit: reset the Unicode sequence holder and add the /* First digit: This must be zero or one. Put it in the
* digit we got to the 0x100000's position of the Unicode * 0x100000's position of the Unicode sequence holder. */
* sequence holder. */
uni = 0;
if ('0' <= kbinput && kbinput <= '1') if ('0' <= kbinput && kbinput <= '1')
uni += (kbinput - '0') * 0x100000; uni = (kbinput - '0') * 0x100000;
else else
/* If the character we got isn't a hexadecimal digit, or /* This isn't the first digit of a Unicode sequence.
* if it is and it would put the Unicode sequence out of * Return this character as the result. */
* valid range, save it as the result. */
retval = kbinput; retval = kbinput;
break; break;
case 2: case 2:
/* Two digits: add the digit we got to the 0x10000's /* Second digit: This must be zero if the first was one, and
* position of the Unicode sequence holder. */ * may be any hexadecimal value if the first was zero. Put
if ('0' == kbinput || (uni < 0x100000 && '1' <= kbinput && * it in the 0x10000's position of the Unicode sequence
kbinput <= '9')) * holder. */
uni += (kbinput - '0') * 0x10000; if (uni == 0 || '0' == kbinput)
else if (uni < 0x100000 && 'a' <= tolower(kbinput) && retval = add_unicode_digit(kbinput, 0x10000, &uni);
tolower(kbinput) <= 'f')
uni += (tolower(kbinput) + 10 - 'a') * 0x10000;
else else
/* If the character we got isn't a hexadecimal digit, or /* This isn't the second digit of a Unicode sequence.
* if it is and it would put the Unicode sequence out of * Return this character as the result. */
* valid range, save it as the result. */
retval = kbinput; retval = kbinput;
break; break;
case 3: case 3:
/* Three digits: add the digit we got to the 0x1000's /* Third digit: This may be any hexadecimal value. Put it
* position of the Unicode sequence holder. */ * in the 0x1000's position of the Unicode sequence
if ('0' <= kbinput && kbinput <= '9') * holder. */
uni += (kbinput - '0') * 0x1000; retval = add_unicode_digit(kbinput, 0x1000, &uni);
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;
break; break;
case 4: case 4:
/* Four digits: add the digit we got to the 0x100's position /* Fourth digit: This may be any hexadecimal value. Put it
* of the Unicode sequence holder. */ * in the 0x100's position of the Unicode sequence
if ('0' <= kbinput && kbinput <= '9') * holder. */
uni += (kbinput - '0') * 0x100; retval = add_unicode_digit(kbinput, 0x100, &uni);
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;
break; break;
case 5: case 5:
/* Five digits: add the digit we got to the 0x10's position /* Fifth digit: This may be any hexadecimal value. Put it
* of the Unicode sequence holder. */ * in the 0x10's position of the Unicode sequence holder. */
if ('0' <= kbinput && kbinput <= '9') retval = add_unicode_digit(kbinput, 0x10, &uni);
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;
break; break;
case 6: case 6:
/* Six digits: add the digit we got to the 1's position of /* Sixth digit: This may be any hexadecimal value. Put it
* the Unicode sequence holder, and save the corresponding * in the 0x1's position of the Unicode sequence holder. */
* Unicode value as the result. */ retval = add_unicode_digit(kbinput, 0x1, &uni);
if ('0' <= kbinput && kbinput <= '9') { /* If this character is a valid hexadecimal value, then the
uni += (kbinput - '0'); * Unicode sequence is complete. */
if (retval == ERR)
retval = uni; 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; break;
default: default:
/* More than six digits: save the character we got as the /* If there are more than six digits, return this character
* result. */ * as the result. (Maybe we should produce an error
* instead?) */
retval = kbinput; retval = kbinput;
break; break;
} }
@ -1369,6 +1336,24 @@ long get_unicode_kbinput(int kbinput)
return retval; return retval;
} }
/* If the character in kbinput is a valid hexadecimal digit, multiply it
* by factor and add the result to uni. */
long add_unicode_digit(int kbinput, long factor, long *uni)
{
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 this character isn't a valid hexadecimal value, save it as
* the result. */
retval = kbinput;
return retval;
}
/* Translate a control character sequence: turn an ASCII non-control /* Translate a control character sequence: turn an ASCII non-control
* character into its corresponding control character. */ * character into its corresponding control character. */
int get_control_kbinput(int kbinput) int get_control_kbinput(int kbinput)
@ -1376,29 +1361,23 @@ int get_control_kbinput(int kbinput)
int retval; int retval;
/* Ctrl-Space (Ctrl-2, Ctrl-@, Ctrl-`) */ /* Ctrl-Space (Ctrl-2, Ctrl-@, Ctrl-`) */
if (kbinput == ' ') if (kbinput == ' ' || kbinput == '2')
retval = kbinput - 32; retval = NANO_CONTROL_SPACE;
/* Ctrl-/ (Ctrl-7, Ctrl-_) */ /* Ctrl-/ (Ctrl-7, Ctrl-_) */
else if (kbinput == '/') else if (kbinput == '/')
retval = kbinput - 16; retval = NANO_CONTROL_7;
/* Ctrl-2 (Ctrl-Space, Ctrl-@, Ctrl-`) */
else if (kbinput == '2')
retval = kbinput - 50;
/* Ctrl-3 (Ctrl-[, Esc) to Ctrl-7 (Ctrl-/, Ctrl-_) */ /* Ctrl-3 (Ctrl-[, Esc) to Ctrl-7 (Ctrl-/, Ctrl-_) */
else if ('3' <= kbinput && kbinput <= '7') else if ('3' <= kbinput && kbinput <= '7')
retval = kbinput - 24; retval = kbinput - 24;
/* Ctrl-8 (Ctrl-?) */ /* Ctrl-8 (Ctrl-?) */
else if (kbinput == '8') else if (kbinput == '8' || kbinput == '?')
retval = kbinput + 71; retval = NANO_CONTROL_8;
/* Ctrl-? (Ctrl-8) */
else if (kbinput == '?')
retval = kbinput + 64;
/* Ctrl-@ (Ctrl-Space, Ctrl-2, Ctrl-`) to Ctrl-_ (Ctrl-/, Ctrl-7) */ /* Ctrl-@ (Ctrl-Space, Ctrl-2, Ctrl-`) to Ctrl-_ (Ctrl-/, Ctrl-7) */
else if ('@' <= kbinput && kbinput <= '_') else if ('@' <= kbinput && kbinput <= '_')
retval = kbinput - 64; retval = kbinput - '@';
/* Ctrl-` (Ctrl-2, Ctrl-Space, Ctrl-@) to Ctrl-~ (Ctrl-6, Ctrl-^) */ /* Ctrl-` (Ctrl-2, Ctrl-Space, Ctrl-@) to Ctrl-~ (Ctrl-6, Ctrl-^) */
else if ('`' <= kbinput && kbinput <= '~') else if ('`' <= kbinput && kbinput <= '~')
retval = kbinput - 96; retval = kbinput - '`';
else else
retval = kbinput; retval = kbinput;
@ -1465,11 +1444,12 @@ int *parse_verbatim_kbinput(WINDOW *win, size_t *kbinput_len)
/* Read in the first keystroke. */ /* Read in the first keystroke. */
while ((kbinput = get_input(win, 1)) == NULL); while ((kbinput = get_input(win, 1)) == NULL);
/* Check whether the first keystroke is a hexadecimal digit. */ /* Check whether the first keystroke is a valid hexadecimal
* digit. */
uni = get_unicode_kbinput(*kbinput); uni = get_unicode_kbinput(*kbinput);
/* If the first keystroke isn't a hexadecimal digit, put back the /* If the first keystroke isn't a valid hexadecimal digit, put back
* first keystroke. */ * the first keystroke. */
if (uni != ERR) if (uni != ERR)
unget_input(kbinput, 1); unget_input(kbinput, 1);
/* Otherwise, read in keystrokes until we have a complete Unicode /* Otherwise, read in keystrokes until we have a complete Unicode
@ -1478,6 +1458,9 @@ int *parse_verbatim_kbinput(WINDOW *win, size_t *kbinput_len)
char *uni_mb; char *uni_mb;
int uni_mb_len, *seq, i; int uni_mb_len, *seq, i;
if (win == edit)
statusbar(_("Unicode Input"));
while (uni == ERR) { while (uni == ERR) {
while ((kbinput = get_input(win, 1)) == NULL); while ((kbinput = get_input(win, 1)) == NULL);