diff options
| author | Gerd Moellmann | 2001-07-13 09:30:42 +0000 |
|---|---|---|
| committer | Gerd Moellmann | 2001-07-13 09:30:42 +0000 |
| commit | 12bcae05840abde621f9de6c3917224c96d91a04 (patch) | |
| tree | 578186c02ade6c8767d0edcb1d0f62c720da7896 /src | |
| parent | ea9dd0918aad62a102f3493b05dd16b965c2bb8b (diff) | |
| download | emacs-12bcae05840abde621f9de6c3917224c96d91a04.tar.gz emacs-12bcae05840abde621f9de6c3917224c96d91a04.zip | |
(char_to_string_1): Extracted from char_to_string.
Return -1 instead of signaling an error.
(char_to_string): Use it.
Diffstat (limited to 'src')
| -rw-r--r-- | src/charset.c | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/src/charset.c b/src/charset.c index fa355fc21bd..b346f661e59 100644 --- a/src/charset.c +++ b/src/charset.c | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | /* Basic multilingual character support. | 1 | /* Basic multilingual character support. |
| 2 | Copyright (C) 1995, 1997, 1998 Electrotechnical Laboratory, JAPAN. | 2 | Copyright (C) 1995, 1997, 1998 Electrotechnical Laboratory, JAPAN. |
| 3 | Licensed to the Free Software Foundation. | 3 | Licensed to the Free Software Foundation. |
| 4 | Copyright (C) 2001 Free Software Foundation, Inc. | ||
| 4 | 5 | ||
| 5 | This file is part of GNU Emacs. | 6 | This file is part of GNU Emacs. |
| 6 | 7 | ||
| @@ -160,13 +161,10 @@ invalid_character (c) | |||
| 160 | /* Store multi-byte form of the character C in STR. The caller should | 161 | /* Store multi-byte form of the character C in STR. The caller should |
| 161 | allocate at least 4-byte area at STR in advance. Returns the | 162 | allocate at least 4-byte area at STR in advance. Returns the |
| 162 | length of the multi-byte form. If C is an invalid character code, | 163 | length of the multi-byte form. If C is an invalid character code, |
| 163 | signal an error. | 164 | return -1. */ |
| 164 | |||
| 165 | Use macro `CHAR_STRING (C, STR)' instead of calling this function | ||
| 166 | directly if C can be an ASCII character. */ | ||
| 167 | 165 | ||
| 168 | int | 166 | int |
| 169 | char_to_string (c, str) | 167 | char_to_string_1 (c, str) |
| 170 | int c; | 168 | int c; |
| 171 | unsigned char *str; | 169 | unsigned char *str; |
| 172 | { | 170 | { |
| @@ -176,7 +174,7 @@ char_to_string (c, str) | |||
| 176 | { | 174 | { |
| 177 | /* Multibyte character can't have a modifier bit. */ | 175 | /* Multibyte character can't have a modifier bit. */ |
| 178 | if (! SINGLE_BYTE_CHAR_P ((c & ~CHAR_MODIFIER_MASK))) | 176 | if (! SINGLE_BYTE_CHAR_P ((c & ~CHAR_MODIFIER_MASK))) |
| 179 | invalid_character (c); | 177 | return -1; |
| 180 | 178 | ||
| 181 | /* For Meta, Shift, and Control modifiers, we need special care. */ | 179 | /* For Meta, Shift, and Control modifiers, we need special care. */ |
| 182 | if (c & CHAR_META) | 180 | if (c & CHAR_META) |
| @@ -211,6 +209,7 @@ char_to_string (c, str) | |||
| 211 | /* If C still has any modifier bits, just ignore it. */ | 209 | /* If C still has any modifier bits, just ignore it. */ |
| 212 | c &= ~CHAR_MODIFIER_MASK; | 210 | c &= ~CHAR_MODIFIER_MASK; |
| 213 | } | 211 | } |
| 212 | |||
| 214 | if (SINGLE_BYTE_CHAR_P (c)) | 213 | if (SINGLE_BYTE_CHAR_P (c)) |
| 215 | { | 214 | { |
| 216 | if (ASCII_BYTE_P (c) || c >= 0xA0) | 215 | if (ASCII_BYTE_P (c) || c >= 0xA0) |
| @@ -237,7 +236,7 @@ char_to_string (c, str) | |||
| 237 | : LEADING_CODE_PRIVATE_22))); | 236 | : LEADING_CODE_PRIVATE_22))); |
| 238 | *p++ = charset; | 237 | *p++ = charset; |
| 239 | if (c1 > 0 && c1 < 32 || c2 > 0 && c2 < 32) | 238 | if (c1 > 0 && c1 < 32 || c2 > 0 && c2 < 32) |
| 240 | invalid_character (c); | 239 | return -1; |
| 241 | if (c1) | 240 | if (c1) |
| 242 | { | 241 | { |
| 243 | *p++ = c1 | 0x80; | 242 | *p++ = c1 | 0x80; |
| @@ -246,11 +245,33 @@ char_to_string (c, str) | |||
| 246 | } | 245 | } |
| 247 | } | 246 | } |
| 248 | else | 247 | else |
| 249 | invalid_character (c); | 248 | return -1; |
| 250 | 249 | ||
| 251 | return (p - str); | 250 | return (p - str); |
| 252 | } | 251 | } |
| 253 | 252 | ||
| 253 | |||
| 254 | /* Store multi-byte form of the character C in STR. The caller should | ||
| 255 | allocate at least 4-byte area at STR in advance. Returns the | ||
| 256 | length of the multi-byte form. If C is an invalid character code, | ||
| 257 | signal an error. | ||
| 258 | |||
| 259 | Use macro `CHAR_STRING (C, STR)' instead of calling this function | ||
| 260 | directly if C can be an ASCII character. */ | ||
| 261 | |||
| 262 | int | ||
| 263 | char_to_string (c, str) | ||
| 264 | int c; | ||
| 265 | unsigned char *str; | ||
| 266 | { | ||
| 267 | int len; | ||
| 268 | len = char_to_string_1 (c, str); | ||
| 269 | if (len == -1) | ||
| 270 | invalid_character (c); | ||
| 271 | return len; | ||
| 272 | } | ||
| 273 | |||
| 274 | |||
| 254 | /* Return the non-ASCII character corresponding to multi-byte form at | 275 | /* Return the non-ASCII character corresponding to multi-byte form at |
| 255 | STR of length LEN. If ACTUAL_LEN is not NULL, store the byte | 276 | STR of length LEN. If ACTUAL_LEN is not NULL, store the byte |
| 256 | length of the multibyte form in *ACTUAL_LEN. | 277 | length of the multibyte form in *ACTUAL_LEN. |