aboutsummaryrefslogtreecommitdiffstats
path: root/src/character.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/character.c')
-rw-r--r--src/character.c113
1 files changed, 55 insertions, 58 deletions
diff --git a/src/character.c b/src/character.c
index 82bc2bfef4e..b85cedad937 100644
--- a/src/character.c
+++ b/src/character.c
@@ -67,8 +67,8 @@ static Lisp_Object Qchar_script_table;
67/* If character code C has modifier masks, reflect them to the 67/* If character code C has modifier masks, reflect them to the
68 character code if possible. Return the resulting code. */ 68 character code if possible. Return the resulting code. */
69 69
70int 70EMACS_INT
71char_resolve_modifier_mask (int c) 71char_resolve_modifier_mask (EMACS_INT c)
72{ 72{
73 /* A non-ASCII character can't reflect modifier bits to the code. */ 73 /* A non-ASCII character can't reflect modifier bits to the code. */
74 if (! ASCII_CHAR_P ((c & ~CHAR_MODIFIER_MASK))) 74 if (! ASCII_CHAR_P ((c & ~CHAR_MODIFIER_MASK)))
@@ -311,10 +311,10 @@ If the multibyte character does not represent a byte, return -1. */)
311 311
312/* Return width (columns) of C considering the buffer display table DP. */ 312/* Return width (columns) of C considering the buffer display table DP. */
313 313
314static EMACS_INT 314static ptrdiff_t
315char_width (int c, struct Lisp_Char_Table *dp) 315char_width (int c, struct Lisp_Char_Table *dp)
316{ 316{
317 EMACS_INT width = CHAR_WIDTH (c); 317 ptrdiff_t width = CHAR_WIDTH (c);
318 318
319 if (dp) 319 if (dp)
320 { 320 {
@@ -346,7 +346,7 @@ usage: (char-width CHAR) */)
346 (Lisp_Object ch) 346 (Lisp_Object ch)
347{ 347{
348 int c; 348 int c;
349 EMACS_INT width; 349 ptrdiff_t width;
350 350
351 CHECK_CHARACTER (ch); 351 CHECK_CHARACTER (ch);
352 c = XINT (ch); 352 c = XINT (ch);
@@ -361,19 +361,19 @@ usage: (char-width CHAR) */)
361 characters and bytes of the substring in *NCHARS and *NBYTES 361 characters and bytes of the substring in *NCHARS and *NBYTES
362 respectively. */ 362 respectively. */
363 363
364EMACS_INT 364ptrdiff_t
365c_string_width (const unsigned char *str, EMACS_INT len, int precision, 365c_string_width (const unsigned char *str, ptrdiff_t len, int precision,
366 EMACS_INT *nchars, EMACS_INT *nbytes) 366 ptrdiff_t *nchars, ptrdiff_t *nbytes)
367{ 367{
368 EMACS_INT i = 0, i_byte = 0; 368 ptrdiff_t i = 0, i_byte = 0;
369 EMACS_INT width = 0; 369 ptrdiff_t width = 0;
370 struct Lisp_Char_Table *dp = buffer_display_table (); 370 struct Lisp_Char_Table *dp = buffer_display_table ();
371 371
372 while (i_byte < len) 372 while (i_byte < len)
373 { 373 {
374 int bytes; 374 int bytes;
375 int c = STRING_CHAR_AND_LENGTH (str + i_byte, bytes); 375 int c = STRING_CHAR_AND_LENGTH (str + i_byte, bytes);
376 EMACS_INT thiswidth = char_width (c, dp); 376 ptrdiff_t thiswidth = char_width (c, dp);
377 377
378 if (precision <= 0) 378 if (precision <= 0)
379 { 379 {
@@ -404,8 +404,8 @@ c_string_width (const unsigned char *str, EMACS_INT len, int precision,
404 current buffer. The width is measured by how many columns it 404 current buffer. The width is measured by how many columns it
405 occupies on the screen. */ 405 occupies on the screen. */
406 406
407EMACS_INT 407ptrdiff_t
408strwidth (const char *str, EMACS_INT len) 408strwidth (const char *str, ptrdiff_t len)
409{ 409{
410 return c_string_width ((const unsigned char *) str, len, -1, NULL, NULL); 410 return c_string_width ((const unsigned char *) str, len, -1, NULL, NULL);
411} 411}
@@ -417,26 +417,26 @@ strwidth (const char *str, EMACS_INT len)
417 PRECISION, and set number of characters and bytes of the substring 417 PRECISION, and set number of characters and bytes of the substring
418 in *NCHARS and *NBYTES respectively. */ 418 in *NCHARS and *NBYTES respectively. */
419 419
420EMACS_INT 420ptrdiff_t
421lisp_string_width (Lisp_Object string, EMACS_INT precision, 421lisp_string_width (Lisp_Object string, ptrdiff_t precision,
422 EMACS_INT *nchars, EMACS_INT *nbytes) 422 ptrdiff_t *nchars, ptrdiff_t *nbytes)
423{ 423{
424 EMACS_INT len = SCHARS (string); 424 ptrdiff_t len = SCHARS (string);
425 /* This set multibyte to 0 even if STRING is multibyte when it 425 /* This set multibyte to 0 even if STRING is multibyte when it
426 contains only ascii and eight-bit-graphic, but that's 426 contains only ascii and eight-bit-graphic, but that's
427 intentional. */ 427 intentional. */
428 int multibyte = len < SBYTES (string); 428 int multibyte = len < SBYTES (string);
429 unsigned char *str = SDATA (string); 429 unsigned char *str = SDATA (string);
430 EMACS_INT i = 0, i_byte = 0; 430 ptrdiff_t i = 0, i_byte = 0;
431 EMACS_INT width = 0; 431 ptrdiff_t width = 0;
432 struct Lisp_Char_Table *dp = buffer_display_table (); 432 struct Lisp_Char_Table *dp = buffer_display_table ();
433 433
434 while (i < len) 434 while (i < len)
435 { 435 {
436 EMACS_INT chars, bytes, thiswidth; 436 ptrdiff_t chars, bytes, thiswidth;
437 Lisp_Object val; 437 Lisp_Object val;
438 ptrdiff_t cmp_id; 438 ptrdiff_t cmp_id;
439 EMACS_INT ignore, end; 439 ptrdiff_t ignore, end;
440 440
441 if (find_composition (i, -1, &ignore, &end, &val, string) 441 if (find_composition (i, -1, &ignore, &end, &val, string)
442 && ((cmp_id = get_composition_id (i, i_byte, end - i, val, string)) 442 && ((cmp_id = get_composition_id (i, i_byte, end - i, val, string))
@@ -512,8 +512,8 @@ usage: (string-width STRING) */)
512 However, if the current buffer has enable-multibyte-characters = 512 However, if the current buffer has enable-multibyte-characters =
513 nil, we treat each byte as a character. */ 513 nil, we treat each byte as a character. */
514 514
515EMACS_INT 515ptrdiff_t
516chars_in_text (const unsigned char *ptr, EMACS_INT nbytes) 516chars_in_text (const unsigned char *ptr, ptrdiff_t nbytes)
517{ 517{
518 /* current_buffer is null at early stages of Emacs initialization. */ 518 /* current_buffer is null at early stages of Emacs initialization. */
519 if (current_buffer == 0 519 if (current_buffer == 0
@@ -528,15 +528,15 @@ chars_in_text (const unsigned char *ptr, EMACS_INT nbytes)
528 sequences while assuming that there's no invalid sequence. It 528 sequences while assuming that there's no invalid sequence. It
529 ignores enable-multibyte-characters. */ 529 ignores enable-multibyte-characters. */
530 530
531EMACS_INT 531ptrdiff_t
532multibyte_chars_in_text (const unsigned char *ptr, EMACS_INT nbytes) 532multibyte_chars_in_text (const unsigned char *ptr, ptrdiff_t nbytes)
533{ 533{
534 const unsigned char *endp = ptr + nbytes; 534 const unsigned char *endp = ptr + nbytes;
535 EMACS_INT chars = 0; 535 ptrdiff_t chars = 0;
536 536
537 while (ptr < endp) 537 while (ptr < endp)
538 { 538 {
539 EMACS_INT len = MULTIBYTE_LENGTH (ptr, endp); 539 int len = MULTIBYTE_LENGTH (ptr, endp);
540 540
541 if (len == 0) 541 if (len == 0)
542 abort (); 542 abort ();
@@ -554,11 +554,12 @@ multibyte_chars_in_text (const unsigned char *ptr, EMACS_INT nbytes)
554 represented by 2-byte in a multibyte text. */ 554 represented by 2-byte in a multibyte text. */
555 555
556void 556void
557parse_str_as_multibyte (const unsigned char *str, EMACS_INT len, 557parse_str_as_multibyte (const unsigned char *str, ptrdiff_t len,
558 EMACS_INT *nchars, EMACS_INT *nbytes) 558 ptrdiff_t *nchars, ptrdiff_t *nbytes)
559{ 559{
560 const unsigned char *endp = str + len; 560 const unsigned char *endp = str + len;
561 EMACS_INT n, chars = 0, bytes = 0; 561 int n;
562 ptrdiff_t chars = 0, bytes = 0;
562 563
563 if (len >= MAX_MULTIBYTE_LENGTH) 564 if (len >= MAX_MULTIBYTE_LENGTH)
564 { 565 {
@@ -596,13 +597,13 @@ parse_str_as_multibyte (const unsigned char *str, EMACS_INT len,
596 area and that is enough. Return the number of bytes of the 597 area and that is enough. Return the number of bytes of the
597 resulting text. */ 598 resulting text. */
598 599
599EMACS_INT 600ptrdiff_t
600str_as_multibyte (unsigned char *str, EMACS_INT len, EMACS_INT nbytes, 601str_as_multibyte (unsigned char *str, ptrdiff_t len, ptrdiff_t nbytes,
601 EMACS_INT *nchars) 602 ptrdiff_t *nchars)
602{ 603{
603 unsigned char *p = str, *endp = str + nbytes; 604 unsigned char *p = str, *endp = str + nbytes;
604 unsigned char *to; 605 unsigned char *to;
605 EMACS_INT chars = 0; 606 ptrdiff_t chars = 0;
606 int n; 607 int n;
607 608
608 if (nbytes >= MAX_MULTIBYTE_LENGTH) 609 if (nbytes >= MAX_MULTIBYTE_LENGTH)
@@ -673,11 +674,11 @@ str_as_multibyte (unsigned char *str, EMACS_INT len, EMACS_INT nbytes,
673 bytes it may occupy when converted to multibyte string by 674 bytes it may occupy when converted to multibyte string by
674 `str_to_multibyte'. */ 675 `str_to_multibyte'. */
675 676
676EMACS_INT 677ptrdiff_t
677count_size_as_multibyte (const unsigned char *str, EMACS_INT len) 678count_size_as_multibyte (const unsigned char *str, ptrdiff_t len)
678{ 679{
679 const unsigned char *endp = str + len; 680 const unsigned char *endp = str + len;
680 EMACS_INT bytes; 681 ptrdiff_t bytes;
681 682
682 for (bytes = 0; str < endp; str++) 683 for (bytes = 0; str < endp; str++)
683 { 684 {
@@ -696,8 +697,8 @@ count_size_as_multibyte (const unsigned char *str, EMACS_INT len)
696 that we can use LEN bytes at STR as a work area and that is 697 that we can use LEN bytes at STR as a work area and that is
697 enough. */ 698 enough. */
698 699
699EMACS_INT 700ptrdiff_t
700str_to_multibyte (unsigned char *str, EMACS_INT len, EMACS_INT bytes) 701str_to_multibyte (unsigned char *str, ptrdiff_t len, ptrdiff_t bytes)
701{ 702{
702 unsigned char *p = str, *endp = str + bytes; 703 unsigned char *p = str, *endp = str + bytes;
703 unsigned char *to; 704 unsigned char *to;
@@ -725,8 +726,8 @@ str_to_multibyte (unsigned char *str, EMACS_INT len, EMACS_INT bytes)
725 actually converts characters in the range 0x80..0xFF to 726 actually converts characters in the range 0x80..0xFF to
726 unibyte. */ 727 unibyte. */
727 728
728EMACS_INT 729ptrdiff_t
729str_as_unibyte (unsigned char *str, EMACS_INT bytes) 730str_as_unibyte (unsigned char *str, ptrdiff_t bytes)
730{ 731{
731 const unsigned char *p = str, *endp = str + bytes; 732 const unsigned char *p = str, *endp = str + bytes;
732 unsigned char *to; 733 unsigned char *to;
@@ -767,10 +768,10 @@ str_as_unibyte (unsigned char *str, EMACS_INT bytes)
767 of that character code. 768 of that character code.
768 Note: Currently the arg ACCEPT_LATIN_1 is not used. */ 769 Note: Currently the arg ACCEPT_LATIN_1 is not used. */
769 770
770EMACS_INT 771ptrdiff_t
771str_to_unibyte (const unsigned char *src, unsigned char *dst, EMACS_INT chars, int accept_latin_1) 772str_to_unibyte (const unsigned char *src, unsigned char *dst, ptrdiff_t chars, int accept_latin_1)
772{ 773{
773 EMACS_INT i; 774 ptrdiff_t i;
774 775
775 for (i = 0; i < chars; i++) 776 for (i = 0; i < chars; i++)
776 { 777 {
@@ -787,14 +788,14 @@ str_to_unibyte (const unsigned char *src, unsigned char *dst, EMACS_INT chars, i
787} 788}
788 789
789 790
790static EMACS_INT 791static ptrdiff_t
791string_count_byte8 (Lisp_Object string) 792string_count_byte8 (Lisp_Object string)
792{ 793{
793 int multibyte = STRING_MULTIBYTE (string); 794 int multibyte = STRING_MULTIBYTE (string);
794 EMACS_INT nbytes = SBYTES (string); 795 ptrdiff_t nbytes = SBYTES (string);
795 unsigned char *p = SDATA (string); 796 unsigned char *p = SDATA (string);
796 unsigned char *pend = p + nbytes; 797 unsigned char *pend = p + nbytes;
797 EMACS_INT count = 0; 798 ptrdiff_t count = 0;
798 int c, len; 799 int c, len;
799 800
800 if (multibyte) 801 if (multibyte)
@@ -820,10 +821,10 @@ string_count_byte8 (Lisp_Object string)
820Lisp_Object 821Lisp_Object
821string_escape_byte8 (Lisp_Object string) 822string_escape_byte8 (Lisp_Object string)
822{ 823{
823 EMACS_INT nchars = SCHARS (string); 824 ptrdiff_t nchars = SCHARS (string);
824 EMACS_INT nbytes = SBYTES (string); 825 ptrdiff_t nbytes = SBYTES (string);
825 int multibyte = STRING_MULTIBYTE (string); 826 int multibyte = STRING_MULTIBYTE (string);
826 EMACS_INT byte8_count; 827 ptrdiff_t byte8_count;
827 const unsigned char *src, *src_end; 828 const unsigned char *src, *src_end;
828 unsigned char *dst; 829 unsigned char *dst;
829 Lisp_Object val; 830 Lisp_Object val;
@@ -924,7 +925,6 @@ usage: (unibyte-string &rest BYTES) */)
924 (ptrdiff_t n, Lisp_Object *args) 925 (ptrdiff_t n, Lisp_Object *args)
925{ 926{
926 ptrdiff_t i; 927 ptrdiff_t i;
927 int c;
928 unsigned char *buf, *p; 928 unsigned char *buf, *p;
929 Lisp_Object str; 929 Lisp_Object str;
930 USE_SAFE_ALLOCA; 930 USE_SAFE_ALLOCA;
@@ -934,11 +934,8 @@ usage: (unibyte-string &rest BYTES) */)
934 934
935 for (i = 0; i < n; i++) 935 for (i = 0; i < n; i++)
936 { 936 {
937 CHECK_NATNUM (args[i]); 937 CHECK_RANGED_INTEGER (0, args[i], 255);
938 c = XFASTINT (args[i]); 938 *p++ = XINT (args[i]);
939 if (c >= 256)
940 args_out_of_range_3 (args[i], make_number (0), make_number (255));
941 *p++ = c;
942 } 939 }
943 940
944 str = make_string_from_bytes ((char *) buf, n, p - buf); 941 str = make_string_from_bytes ((char *) buf, n, p - buf);
@@ -954,7 +951,7 @@ code. Unresolved modifiers are kept in the value.
954usage: (char-resolve-modifiers CHAR) */) 951usage: (char-resolve-modifiers CHAR) */)
955 (Lisp_Object character) 952 (Lisp_Object character)
956{ 953{
957 int c; 954 EMACS_INT c;
958 955
959 CHECK_NUMBER (character); 956 CHECK_NUMBER (character);
960 c = XINT (character); 957 c = XINT (character);
@@ -974,7 +971,7 @@ character is not ASCII nor 8-bit character, an error is signaled. */)
974 (Lisp_Object position, Lisp_Object string) 971 (Lisp_Object position, Lisp_Object string)
975{ 972{
976 int c; 973 int c;
977 EMACS_INT pos; 974 ptrdiff_t pos;
978 unsigned char *p; 975 unsigned char *p;
979 976
980 if (NILP (string)) 977 if (NILP (string))