comparison src/xdisp.c @ 23647:d87960db41e9

(display_text_line): Check validity of a multibyte character. (display_string): Likewise. Handle an invalid character correctly.
author Kenichi Handa <handa@m17n.org>
date Fri, 06 Nov 1998 00:44:16 +0000
parents 5e25a31007e8
children b09b3351386f
comparison
equal deleted inserted replaced
23646:595d8a052b71 23647:d87960db41e9
3817 { 3817 {
3818 /* C is a multibyte character or a character to be displayed 3818 /* C is a multibyte character or a character to be displayed
3819 by octal form. */ 3819 by octal form. */
3820 int remaining_bytes = len; 3820 int remaining_bytes = len;
3821 3821
3822 if (c >= 0400) 3822 if (c >= 0400 && CHAR_VALID_P (c, 0))
3823 { 3823 {
3824 /* C is a multibyte character. */ 3824 /* C is a multibyte character. */
3825 int charset = CHAR_CHARSET (c); 3825 int charset = CHAR_CHARSET (c);
3826 int columns = (charset == CHARSET_COMPOSITION 3826 int columns = (charset == CHARSET_COMPOSITION
3827 ? cmpchar_table[COMPOSITE_CHAR_ID (c)]->width 3827 ? cmpchar_table[COMPOSITE_CHAR_ID (c)]->width
5247 p1++; 5247 p1++;
5248 if (p1 >= start && p1 < end) 5248 if (p1 >= start && p1 < end)
5249 *p1 = c ^ 0100; 5249 *p1 = c ^ 0100;
5250 p1++; 5250 p1++;
5251 } 5251 }
5252 else if (len == 1)
5253 {
5254 /* C is a control character or a binary byte data. */
5255 if (p1 >= start)
5256 *p1 = (fix_glyph
5257 (f, (dp && INTEGERP (DISP_ESCAPE_GLYPH (dp))
5258 && GLYPH_CHAR_VALID_P (XINT (DISP_ESCAPE_GLYPH (dp)))
5259 ? XINT (DISP_ESCAPE_GLYPH (dp)) : '\\'),
5260 0));
5261 p1++;
5262 if (p1 >= start && p1 < end)
5263 *p1 = (c >> 6) + '0';
5264 p1++;
5265 if (p1 >= start && p1 < end)
5266 *p1 = (7 & (c >> 3)) + '0';
5267 p1++;
5268 if (p1 >= start && p1 < end)
5269 *p1 = (7 & c) + '0';
5270 p1++;
5271 }
5272 else 5252 else
5273 { 5253 {
5274 /* C is a multibyte character. */ 5254 /* C is a multibyte character, control character or a binary
5275 int charset = CHAR_CHARSET (c); 5255 byte data. */
5276 int columns = (charset == CHARSET_COMPOSITION 5256 int remaining_bytes = len;
5277 ? cmpchar_table[COMPOSITE_CHAR_ID (c)]->width 5257
5278 : CHARSET_WIDTH (charset)); 5258 if (c >= 0400 && CHAR_VALID_P (c, 0))
5279
5280 if (p1 < start)
5281 { 5259 {
5282 /* Since we can't show the left part of C, fill all 5260 /* C is a multibyte character. */
5283 columns with spaces. */ 5261 int charset = CHAR_CHARSET (c);
5284 columns -= start - p1; 5262 int columns = (charset == CHARSET_COMPOSITION
5285 p1 = start; 5263 ? cmpchar_table[COMPOSITE_CHAR_ID (c)]->width
5286 while (columns--) 5264 : CHARSET_WIDTH (charset));
5265
5266 remaining_bytes -= CHARSET_BYTES (charset);
5267 if (p1 < start)
5287 { 5268 {
5288 if (p1 < end) 5269 /* Since we can't show the left part of C, fill all
5289 *p1 = SPACEGLYPH; 5270 columns with spaces. */
5290 p1++; 5271 columns -= start - p1;
5272 p1 = start;
5273 while (columns--)
5274 {
5275 if (p1 < end)
5276 *p1 = SPACEGLYPH;
5277 p1++;
5278 }
5279 }
5280 else if (p1 + columns > end)
5281 {
5282 /* Since we can't show the right part of C, fill all
5283 columns with TRUNCATE if TRUNCATE is specified. */
5284 if (truncate)
5285 {
5286 while (p1 < end)
5287 *p1++ = fix_glyph (f, truncate, 0);
5288 /* And tell the line is truncated. */
5289 truncated = 1;
5290 }
5291 break;
5292 }
5293 else
5294 {
5295 /* We can show the whole glyph of C. */
5296 *p1++ = c;
5297 while (--columns)
5298 *p1++ = c | GLYPH_MASK_PADDING;
5291 } 5299 }
5292 } 5300 }
5293 else if (p1 + columns > end) 5301
5302 while (remaining_bytes > 0)
5294 { 5303 {
5295 /* Since we can't show the right part of C, fill all 5304 c = *(string - remaining_bytes--);
5296 columns with TRUNCATE if TRUNCATE is specified. */ 5305
5297 if (truncate) 5306 if (p1 >= start)
5298 { 5307 *p1 = (fix_glyph
5299 while (p1 < end) 5308 (f, (dp && INTEGERP (DISP_ESCAPE_GLYPH (dp))
5300 *p1++ = fix_glyph (f, truncate, 0); 5309 && GLYPH_CHAR_VALID_P (XINT (DISP_ESCAPE_GLYPH (dp)))
5301 /* And tell the line is truncated. */ 5310 ? XINT (DISP_ESCAPE_GLYPH (dp)) : '\\'),
5302 truncated = 1; 5311 0));
5303 } 5312 p1++;
5304 break; 5313 if (p1 >= start && p1 < end)
5305 } 5314 *p1 = (c >> 6) + '0';
5306 else 5315 p1++;
5307 { 5316 if (p1 >= start && p1 < end)
5308 /* We can show the whole glyph of C. */ 5317 *p1 = (7 & (c >> 3)) + '0';
5309 *p1++ = c; 5318 p1++;
5310 while (--columns) 5319 if (p1 >= start && p1 < end)
5311 *p1++ = c | GLYPH_MASK_PADDING; 5320 *p1 = (7 & c) + '0';
5321 p1++;
5312 } 5322 }
5313 } 5323 }
5314 } 5324 }
5315 5325
5316 if (truncated) 5326 if (truncated)