comparison src/doc.c @ 20619:0a559893331d

Include charset.h. (Fsubstitute_command_keys): Scan by bytes.
author Richard M. Stallman <rms@gnu.org>
date Fri, 09 Jan 1998 23:08:46 +0000
parents c7ada1684ebb
children ed9ed828415e
comparison
equal deleted inserted replaced
20618:d5acac3af6e3 20619:0a559893331d
37 #endif 37 #endif
38 38
39 #include "lisp.h" 39 #include "lisp.h"
40 #include "buffer.h" 40 #include "buffer.h"
41 #include "keyboard.h" 41 #include "keyboard.h"
42 #include "charset.h"
42 43
43 Lisp_Object Vdoc_file_name; 44 Lisp_Object Vdoc_file_name;
44 45
45 extern char *index (); 46 extern char *index ();
46 47
476 while (p != end && *p != '\037') p++; 477 while (p != end && *p != '\037') p++;
477 /* p points to ^_Ffunctionname\n or ^_Vvarname\n. */ 478 /* p points to ^_Ffunctionname\n or ^_Vvarname\n. */
478 if (p != end) 479 if (p != end)
479 { 480 {
480 end = index (p, '\n'); 481 end = index (p, '\n');
481 sym = oblookup (Vobarray, p + 2, end - p - 2); 482 sym = oblookup (Vobarray, p + 2,
483 multibyte_chars_in_text (p + 2, end - p - 2),
484 end - p - 2);
482 if (SYMBOLP (sym)) 485 if (SYMBOLP (sym))
483 { 486 {
484 /* Attach a docstring to a variable? */ 487 /* Attach a docstring to a variable? */
485 if (p[1] == 'V') 488 if (p[1] == 'V')
486 { 489 {
534 Lisp_Object keymap; 537 Lisp_Object keymap;
535 unsigned char *start; 538 unsigned char *start;
536 int length; 539 int length;
537 Lisp_Object name; 540 Lisp_Object name;
538 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; 541 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
542 int multibyte;
543 int nchars;
539 544
540 if (NILP (string)) 545 if (NILP (string))
541 return Qnil; 546 return Qnil;
542 547
543 CHECK_STRING (string, 0); 548 CHECK_STRING (string, 0);
544 tem = Qnil; 549 tem = Qnil;
545 keymap = Qnil; 550 keymap = Qnil;
546 name = Qnil; 551 name = Qnil;
547 GCPRO4 (string, tem, keymap, name); 552 GCPRO4 (string, tem, keymap, name);
553
554 multibyte = STRING_MULTIBYTE (string);
555 nchars = 0;
548 556
549 /* KEYMAP is either nil (which means search all the active keymaps) 557 /* KEYMAP is either nil (which means search all the active keymaps)
550 or a specified local map (which means search just that and the 558 or a specified local map (which means search just that and the
551 global map). If non-nil, it might come from Voverriding_local_map, 559 global map). If non-nil, it might come from Voverriding_local_map,
552 or from a \\<mapname> construct in STRING itself.. */ 560 or from a \\<mapname> construct in STRING itself.. */
553 keymap = current_kboard->Voverriding_terminal_local_map; 561 keymap = current_kboard->Voverriding_terminal_local_map;
554 if (NILP (keymap)) 562 if (NILP (keymap))
555 keymap = Voverriding_local_map; 563 keymap = Voverriding_local_map;
556 564
557 bsize = XSTRING (string)->size; 565 bsize = XSTRING (string)->size_byte;
558 bufp = buf = (unsigned char *) xmalloc (bsize); 566 bufp = buf = (unsigned char *) xmalloc (bsize);
559 567
560 strp = (unsigned char *) XSTRING (string)->data; 568 strp = (unsigned char *) XSTRING (string)->data;
561 while (strp < (unsigned char *) XSTRING (string)->data + XSTRING (string)->size) 569 while (strp < XSTRING (string)->data + XSTRING (string)->size_byte)
562 { 570 {
563 if (strp[0] == '\\' && strp[1] == '=') 571 if (strp[0] == '\\' && strp[1] == '=')
564 { 572 {
565 /* \= quotes the next character; 573 /* \= quotes the next character;
566 thus, to put in \[ without its special meaning, use \=\[. */ 574 thus, to put in \[ without its special meaning, use \=\[. */
567 changed = 1; 575 changed = 1;
568 *bufp++ = strp[2]; 576 strp += 2;
569 strp += 3; 577 if (multibyte)
578 {
579 int len;
580 int maxlen = XSTRING (string)->data + XSTRING (string)->size_byte - strp;
581
582 STRING_CHAR_AND_LENGTH (strp, maxlen, len);
583 if (len == 1)
584 *bufp = *strp;
585 else
586 bcopy (strp, bufp, len);
587 strp += len;
588 bufp += len;
589 nchars++;
590 }
591 else
592 *bufp++ = *strp++, nchars++;
570 } 593 }
571 else if (strp[0] == '\\' && strp[1] == '[') 594 else if (strp[0] == '\\' && strp[1] == '[')
572 { 595 {
573 Lisp_Object firstkey; 596 Lisp_Object firstkey;
597 int length_byte;
574 598
575 changed = 1; 599 changed = 1;
576 strp += 2; /* skip \[ */ 600 strp += 2; /* skip \[ */
577 start = strp; 601 start = strp;
578 602
579 while ((strp - (unsigned char *) XSTRING (string)->data 603 while ((strp - (unsigned char *) XSTRING (string)->data
580 < XSTRING (string)->size) 604 < XSTRING (string)->size_byte)
581 && *strp != ']') 605 && *strp != ']')
582 strp++; 606 strp++;
583 length = strp - start; 607 length_byte = strp - start;
608
584 strp++; /* skip ] */ 609 strp++; /* skip ] */
585 610
586 /* Save STRP in IDX. */ 611 /* Save STRP in IDX. */
587 idx = strp - (unsigned char *) XSTRING (string)->data; 612 idx = strp - (unsigned char *) XSTRING (string)->data;
588 tem = Fintern (make_string (start, length), Qnil); 613 tem = Fintern (make_string (start, length_byte), Qnil);
589 tem = Fwhere_is_internal (tem, keymap, Qt, Qnil); 614 tem = Fwhere_is_internal (tem, keymap, Qt, Qnil);
590 615
591 /* Disregard menu bar bindings; it is positively annoying to 616 /* Disregard menu bar bindings; it is positively annoying to
592 mention them when there's no menu bar, and it isn't terribly 617 mention them when there's no menu bar, and it isn't terribly
593 useful even when there is a menu bar. */ 618 useful even when there is a menu bar. */
603 new = (unsigned char *) xrealloc (buf, bsize += 4); 628 new = (unsigned char *) xrealloc (buf, bsize += 4);
604 bufp += new - buf; 629 bufp += new - buf;
605 buf = new; 630 buf = new;
606 bcopy ("M-x ", bufp, 4); 631 bcopy ("M-x ", bufp, 4);
607 bufp += 4; 632 bufp += 4;
633 nchars += 4;
634 if (multibyte)
635 length = multibyte_chars_in_text (start, length_byte);
636 else
637 length = length_byte;
608 goto subst; 638 goto subst;
609 } 639 }
610 else 640 else
611 { /* function is on a key */ 641 { /* function is on a key */
612 tem = Fkey_description (tem); 642 tem = Fkey_description (tem);
616 /* \{foo} is replaced with a summary of the keymap (symbol-value foo). 646 /* \{foo} is replaced with a summary of the keymap (symbol-value foo).
617 \<foo> just sets the keymap used for \[cmd]. */ 647 \<foo> just sets the keymap used for \[cmd]. */
618 else if (strp[0] == '\\' && (strp[1] == '{' || strp[1] == '<')) 648 else if (strp[0] == '\\' && (strp[1] == '{' || strp[1] == '<'))
619 { 649 {
620 struct buffer *oldbuf; 650 struct buffer *oldbuf;
651 int length_byte;
621 652
622 changed = 1; 653 changed = 1;
623 strp += 2; /* skip \{ or \< */ 654 strp += 2; /* skip \{ or \< */
624 start = strp; 655 start = strp;
625 656
626 while ((strp - (unsigned char *) XSTRING (string)->data 657 while ((strp - (unsigned char *) XSTRING (string)->data
627 < XSTRING (string)->size) 658 < XSTRING (string)->size)
628 && *strp != '}' && *strp != '>') 659 && *strp != '}' && *strp != '>')
629 strp++; 660 strp++;
630 length = strp - start; 661
662 length_byte = strp - start;
631 strp++; /* skip } or > */ 663 strp++; /* skip } or > */
632 664
633 /* Save STRP in IDX. */ 665 /* Save STRP in IDX. */
634 idx = strp - (unsigned char *) XSTRING (string)->data; 666 idx = strp - (unsigned char *) XSTRING (string)->data;
635 667
636 /* Get the value of the keymap in TEM, or nil if undefined. 668 /* Get the value of the keymap in TEM, or nil if undefined.
637 Do this while still in the user's current buffer 669 Do this while still in the user's current buffer
638 in case it is a local variable. */ 670 in case it is a local variable. */
639 name = Fintern (make_string (start, length), Qnil); 671 name = Fintern (make_string (start, length_byte), Qnil);
640 tem = Fboundp (name); 672 tem = Fboundp (name);
641 if (! NILP (tem)) 673 if (! NILP (tem))
642 { 674 {
643 tem = Fsymbol_value (name); 675 tem = Fsymbol_value (name);
644 if (! NILP (tem)) 676 if (! NILP (tem))
651 683
652 if (NILP (tem)) 684 if (NILP (tem))
653 { 685 {
654 name = Fsymbol_name (name); 686 name = Fsymbol_name (name);
655 insert_string ("\nUses keymap \""); 687 insert_string ("\nUses keymap \"");
656 insert_from_string (name, 0, XSTRING (name)->size, 1); 688 insert_from_string (name, 0, 0,
689 XSTRING (name)->size,
690 XSTRING (name)->size_byte, 1);
657 insert_string ("\", which is not currently defined.\n"); 691 insert_string ("\", which is not currently defined.\n");
658 if (start[-1] == '<') keymap = Qnil; 692 if (start[-1] == '<') keymap = Qnil;
659 } 693 }
660 else if (start[-1] == '<') 694 else if (start[-1] == '<')
661 keymap = tem; 695 keymap = tem;
666 set_buffer_internal (oldbuf); 700 set_buffer_internal (oldbuf);
667 701
668 subst_string: 702 subst_string:
669 start = XSTRING (tem)->data; 703 start = XSTRING (tem)->data;
670 length = XSTRING (tem)->size; 704 length = XSTRING (tem)->size;
705 length_byte = XSTRING (tem)->size_byte;
671 subst: 706 subst:
672 new = (unsigned char *) xrealloc (buf, bsize += length); 707 new = (unsigned char *) xrealloc (buf, bsize += length_byte);
673 bufp += new - buf; 708 bufp += new - buf;
674 buf = new; 709 buf = new;
675 bcopy (start, bufp, length); 710 bcopy (start, bufp, length_byte);
676 bufp += length; 711 bufp += length_byte;
712 nchars += length;
677 /* Check STRING again in case gc relocated it. */ 713 /* Check STRING again in case gc relocated it. */
678 strp = (unsigned char *) XSTRING (string)->data + idx; 714 strp = (unsigned char *) XSTRING (string)->data + idx;
679 } 715 }
680 else /* just copy other chars */ 716 else if (! multibyte) /* just copy other chars */
681 *bufp++ = *strp++; 717 *bufp++ = *strp++, nchars++;
718 else
719 {
720 int len;
721 int maxlen = XSTRING (string)->data + XSTRING (string)->size_byte - strp;
722
723 STRING_CHAR_AND_LENGTH (strp, maxlen, len);
724 if (len == 1)
725 *bufp = *strp;
726 else
727 bcopy (strp, bufp, len);
728 strp += len;
729 bufp += len;
730 nchars++;
731 }
682 } 732 }
683 733
684 if (changed) /* don't bother if nothing substituted */ 734 if (changed) /* don't bother if nothing substituted */
685 tem = make_string (buf, bufp - buf); 735 tem = make_multibyte_string (buf, nchars, bufp - buf);
686 else 736 else
687 tem = string; 737 tem = string;
688 xfree (buf); 738 xfree (buf);
689 RETURN_UNGCPRO (tem); 739 RETURN_UNGCPRO (tem);
690 } 740 }