diff options
author | unknown <jimw@mysql.com> | 2005-07-18 18:04:52 -0700 |
---|---|---|
committer | unknown <jimw@mysql.com> | 2005-07-18 18:04:52 -0700 |
commit | 1e3be5e98ab82c9ab57e7b6e2ea67d4c2e38f88e (patch) | |
tree | fa67b28487ba02e61e89d6ec639d7684c1f5674f /cmd-line-utils/readline/mbutil.c | |
parent | cdf03871061e2131153f4cf6ddcbc25db4108781 (diff) | |
parent | 42d10743d14ac79b4cf8a1feabb724e1c8355d4f (diff) | |
download | mariadb-git-1e3be5e98ab82c9ab57e7b6e2ea67d4c2e38f88e.tar.gz |
Merge mysqldev@production.mysql.com:jimw/mysql-5.0-readline
into mysql.com:/home/jimw/my/mysql-5.0-readline
Diffstat (limited to 'cmd-line-utils/readline/mbutil.c')
-rw-r--r-- | cmd-line-utils/readline/mbutil.c | 53 |
1 files changed, 32 insertions, 21 deletions
diff --git a/cmd-line-utils/readline/mbutil.c b/cmd-line-utils/readline/mbutil.c index 3113b7b0538..c88e9485f39 100644 --- a/cmd-line-utils/readline/mbutil.c +++ b/cmd-line-utils/readline/mbutil.c @@ -1,6 +1,6 @@ /* mbutil.c -- readline multibyte character utility functions */ -/* Copyright (C) 2001 Free Software Foundation, Inc. +/* Copyright (C) 2001-2004 Free Software Foundation, Inc. This file is part of the GNU Readline Library, a library for reading lines of text with interactive input and history editing. @@ -90,12 +90,12 @@ _rl_find_next_mbchar_internal (string, seed, count, find_non_zero) /* if this is true, means that seed was not pointed character started byte. So correct the point and consume count */ if (seed < point) - count --; + count--; while (count > 0) { tmp = mbrtowc (&wc, string+point, strlen(string + point), &ps); - if ((size_t)(tmp) == (size_t)-1 || (size_t)(tmp) == (size_t)-2) + if (MB_INVALIDCH ((size_t)tmp)) { /* invalid bytes. asume a byte represents a character */ point++; @@ -103,9 +103,8 @@ _rl_find_next_mbchar_internal (string, seed, count, find_non_zero) /* reset states. */ memset(&ps, 0, sizeof(mbstate_t)); } - else if (tmp == (size_t)0) - /* found '\0' char */ - break; + else if (MB_NULLWCH (tmp)) + break; /* found wide '\0' */ else { /* valid bytes */ @@ -158,7 +157,7 @@ _rl_find_prev_mbchar_internal (string, seed, find_non_zero) while (point < seed) { tmp = mbrtowc (&wc, string + point, length - point, &ps); - if ((size_t)(tmp) == (size_t)-1 || (size_t)(tmp) == (size_t)-2) + if (MB_INVALIDCH ((size_t)tmp)) { /* in this case, bytes are invalid or shorted to compose multibyte char, so assume that the first byte represents @@ -167,8 +166,12 @@ _rl_find_prev_mbchar_internal (string, seed, find_non_zero) /* clear the state of the byte sequence, because in this case effect of mbstate is undefined */ memset(&ps, 0, sizeof (mbstate_t)); + + /* Since we're assuming that this byte represents a single + non-zero-width character, don't forget about it. */ + prev = point; } - else if (tmp == 0) + else if (MB_NULLWCH (tmp)) break; /* Found '\0' char. Can this happen? */ else { @@ -194,7 +197,7 @@ _rl_find_prev_mbchar_internal (string, seed, find_non_zero) if it couldn't parse a complete multibyte character. */ int _rl_get_char_len (src, ps) - const char *src; + char *src; mbstate_t *ps; { size_t tmp; @@ -203,14 +206,16 @@ _rl_get_char_len (src, ps) if (tmp == (size_t)(-2)) { /* shorted to compose multibyte char */ - memset (ps, 0, sizeof(mbstate_t)); + if (ps) + memset (ps, 0, sizeof(mbstate_t)); return -2; } else if (tmp == (size_t)(-1)) { /* invalid to compose multibyte char */ /* initialize the conversion state */ - memset (ps, 0, sizeof(mbstate_t)); + if (ps) + memset (ps, 0, sizeof(mbstate_t)); return -1; } else if (tmp == (size_t)0) @@ -223,9 +228,12 @@ _rl_get_char_len (src, ps) return 1. Otherwise return 0. */ int _rl_compare_chars (buf1, pos1, ps1, buf2, pos2, ps2) - char *buf1, *buf2; - mbstate_t *ps1, *ps2; - int pos1, pos2; + char *buf1; + int pos1; + mbstate_t *ps1; + char *buf2; + int pos2; + mbstate_t *ps2; { int i, w1, w2; @@ -249,7 +257,7 @@ _rl_compare_chars (buf1, pos1, ps1, buf2, pos2, ps2) it returns -1 */ int _rl_adjust_point(string, point, ps) - const char *string; + char *string; int point; mbstate_t *ps; { @@ -266,7 +274,7 @@ _rl_adjust_point(string, point, ps) while (pos < point) { tmp = mbrlen (string + pos, length - pos, ps); - if((size_t)(tmp) == (size_t)-1 || (size_t)(tmp) == (size_t)-2) + if (MB_INVALIDCH ((size_t)tmp)) { /* in this case, bytes are invalid or shorted to compose multibyte char, so assume that the first byte represents @@ -274,8 +282,11 @@ _rl_adjust_point(string, point, ps) pos++; /* clear the state of the byte sequence, because in this case effect of mbstate is undefined */ - memset (ps, 0, sizeof (mbstate_t)); + if (ps) + memset (ps, 0, sizeof (mbstate_t)); } + else if (MB_NULLWCH (tmp)) + pos++; else pos += tmp; } @@ -308,8 +319,8 @@ _rl_is_mbchar_matched (string, seed, end, mbchar, length) #undef _rl_find_next_mbchar int _rl_find_next_mbchar (string, seed, count, flags) - char *string __attribute__((unused)); - int seed, count, flags __attribute__((unused)); + char *string; + int seed, count, flags; { #if defined (HANDLE_MULTIBYTE) return _rl_find_next_mbchar_internal (string, seed, count, flags); @@ -324,8 +335,8 @@ _rl_find_next_mbchar (string, seed, count, flags) #undef _rl_find_prev_mbchar int _rl_find_prev_mbchar (string, seed, flags) - char *string __attribute__((unused)); - int seed, flags __attribute__((unused)); + char *string; + int seed, flags; { #if defined (HANDLE_MULTIBYTE) return _rl_find_prev_mbchar_internal (string, seed, flags); |