ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/command.C
(Generate patch)

Comparing rxvt-unicode/src/command.C (file contents):
Revision 1.11 by pcg, Tue Dec 2 21:49:46 2003 UTC vs.
Revision 1.14 by pcg, Mon Dec 8 23:14:40 2003 UTC

1/*--------------------------------*-C-*---------------------------------* 1/*--------------------------------*-C-*---------------------------------*
2 * File: command.c 2 * File: command.c
3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
4 * $Id: command.C,v 1.11 2003/12/02 21:49:46 pcg Exp $ 4 * $Id: command.C,v 1.14 2003/12/08 23:14:40 pcg Exp $
5 * 5 *
6 * All portions of code are copyright by their respective author/s. 6 * All portions of code are copyright by their respective author/s.
7 * Copyright (c) 1992 John Bovey, University of Kent at Canterbury <jdb@ukc.ac.uk> 7 * Copyright (c) 1992 John Bovey, University of Kent at Canterbury <jdb@ukc.ac.uk>
8 * - original version 8 * - original version
9 * Copyright (c) 1994 Robert Nation <nation@rocket.sanders.lockheed.com> 9 * Copyright (c) 1994 Robert Nation <nation@rocket.sanders.lockheed.com>
61 unsigned int newlen; 61 unsigned int newlen;
62 KeySym keysym; 62 KeySym keysym;
63#ifdef DEBUG_CMD 63#ifdef DEBUG_CMD
64 static int debug_key = 1; /* accessible by a debugger only */ 64 static int debug_key = 1; /* accessible by a debugger only */
65#endif 65#endif
66#ifdef USE_XIM
67 int valid_keysym; 66 int valid_keysym;
68#endif
69 unsigned char *kbuf = R->kbuf; 67 unsigned char *kbuf = R->kbuf;
70 68
71/* 69/*
72 * use Num_Lock to toggle Keypad on/off. If Num_Lock is off, allow an 70 * use Num_Lock to toggle Keypad on/off. If Num_Lock is off, allow an
73 * escape sequence to toggle the Keypad. 71 * escape sequence to toggle the Keypad.
75 * Always permit `shift' to override the current setting 73 * Always permit `shift' to override the current setting
76 */ 74 */
77 shft = (ev->state & ShiftMask); 75 shft = (ev->state & ShiftMask);
78 ctrl = (ev->state & ControlMask); 76 ctrl = (ev->state & ControlMask);
79 meta = (ev->state & R->ModMetaMask); 77 meta = (ev->state & R->ModMetaMask);
78
80 if (R->numlock_state || (ev->state & R->ModNumLockMask)) { 79 if (R->numlock_state || (ev->state & R->ModNumLockMask))
80 {
81 R->numlock_state = (ev->state & R->ModNumLockMask); 81 R->numlock_state = (ev->state & R->ModNumLockMask);
82 PrivMode((!R->numlock_state), PrivMode_aplKP); 82 PrivMode((!R->numlock_state), PrivMode_aplKP);
83 } 83 }
84
85 kbuf[0] = 0;
86
84#ifdef USE_XIM 87#ifdef USE_XIM
85 if (R->Input_Context != NULL) { 88 if (R->Input_Context)
89 {
86 Status status_return; 90 Status status_return;
87 91
88 kbuf[0] = '\0';
89#ifdef X_HAVE_UTF8_STRING 92#ifdef X_HAVE_UTF8_STRING
90 len = Xutf8LookupString(R->Input_Context, ev, (char *)kbuf, 93 len = Xutf8LookupString(R->Input_Context, ev, (char *)kbuf,
91 KBUFSZ, &keysym, &status_return); 94 KBUFSZ, &keysym, &status_return);
92#else 95#else
93 len = XmbLookupString(R->Input_Context, ev, (char *)kbuf, 96 len = XmbLookupString(R->Input_Context, ev, (char *)kbuf,
94 KBUFSZ, &keysym, &status_return); 97 KBUFSZ, &keysym, &status_return);
95#endif 98#endif
96 valid_keysym = ((status_return == XLookupKeySym) 99 valid_keysym = ((status_return == XLookupKeySym)
97 || (status_return == XLookupBoth)); 100 || (status_return == XLookupBoth));
101 }
98 } else { 102 else
103#endif
104 {
99 len = XLookupString(ev, (char *)kbuf, KBUFSZ, &keysym, 105 len = XLookupString(ev, (char *)kbuf, KBUFSZ, &keysym, &R->compose);
100 &R->compose);
101 valid_keysym = 1; 106 valid_keysym = !len;
102 } 107 }
103#else /* USE_XIM */
104 len = XLookupString(ev, (char *)kbuf, KBUFSZ, &keysym,
105 &R->compose);
106/*
107 * map unmapped Latin[2-4]/Katakana/Arabic/Cyrillic/Greek entries -> Latin1
108 * good for installations with correct fonts, but without XLOCALE
109 */
110 if (!len) {
111 if ((keysym >= 0x0100) && (keysym < 0x0800)) {
112 kbuf[0] = (keysym & 0xFF);
113 kbuf[1] = '\0';
114 len = 1;
115 } else
116 kbuf[0] = '\0';
117 }
118#endif /* USE_XIM */
119 108
120#ifdef USE_XIM
121 if (valid_keysym) 109 if (valid_keysym)
122#endif
123 { 110 {
124/* for some backwards compatibility */ 111/* for some backwards compatibility */
125#if defined(HOTKEY_CTRL) || defined(HOTKEY_META) 112#if defined(HOTKEY_CTRL) || defined(HOTKEY_META)
126# ifdef HOTKEY_CTRL 113# ifdef HOTKEY_CTRL
127 if (ctrl) { 114 if (ctrl)
128# else 115# else
129 if (meta) { 116 if (meta)
130# endif 117# endif
118 {
131 if (keysym == R->ks_bigfont) { 119 if (keysym == R->ks_bigfont)
120 {
132 rxvt_change_font(aR_ 0, FONT_UP); 121 rxvt_change_font(aR_ 0, FONT_UP);
133 return; 122 return;
123 }
134 } else if (keysym == R->ks_smallfont) { 124 else if (keysym == R->ks_smallfont)
125 {
135 rxvt_change_font(aR_ 0, FONT_DN); 126 rxvt_change_font(aR_ 0, FONT_DN);
136 return; 127 return;
137 } 128 }
138 } 129 }
139#endif 130#endif
140 131
141 if (R->TermWin.saveLines) { 132 if (R->TermWin.saveLines) {
142#ifdef UNSHIFTED_SCROLLKEYS 133#ifdef UNSHIFTED_SCROLLKEYS
143 if (!ctrl && !meta) { 134 if (!ctrl && !meta) {
237 /* escape prefix */ 228 /* escape prefix */
238 if (meta) 229 if (meta)
239# ifdef META8_OPTION 230# ifdef META8_OPTION
240 if (R->meta_char == C0_ESC) 231 if (R->meta_char == C0_ESC)
241# endif 232# endif
242 R->tt_write(&ch, 1); 233 R->tt_write (&ch, 1);
243 R->tt_write(kbuf0, l); 234 R->tt_write (kbuf0, l);
244 return; 235 return;
245 } else 236 } else
246#endif 237#endif
247 { 238 {
248 newlen = 1; 239 newlen = 1;
572 if (R->greek_mode) 563 if (R->greek_mode)
573 len = greek_xlat(kbuf, len); 564 len = greek_xlat(kbuf, len);
574#endif 565#endif
575 /* nil */ ; 566 /* nil */ ;
576 } 567 }
577 } 568 }
578 569
579 if (len <= 0) 570 if (len <= 0)
580 return; /* not mapped */ 571 return; /* not mapped */
581 572
582 if (R->Options & Opt_scrollTtyKeypress) 573 if (R->Options & Opt_scrollTtyKeypress)
772 if (n > 0) 763 if (n > 0)
773 { 764 {
774 cmdbuf_endp += n; 765 cmdbuf_endp += n;
775 return true; 766 return true;
776 } 767 }
777 else if (n < 0 && errno == EAGAIN) 768 else if (n < 0 && errno != EAGAIN)
769 destroy ();
770
778 return false; 771 return false;
779
780 destroy ();
781} 772}
782 773
783void 774void
784rxvt_term::pty_cb (io_watcher &w, short revents) 775rxvt_term::pty_cb (io_watcher &w, short revents)
785{ 776{
786 SET_R (this); 777 SET_R (this);
787 778
788 if (revents & EVENT_WRITE) 779 if (revents & EVENT_WRITE)
789 tt_write (0, 0); 780 tt_write (0, 0);
790 else if (revents & EVENT_READ) 781 else if (revents & EVENT_READ)
782 {
783 bool flag = true;
784
791 // loop, but don't allow a single term to monopolize us 785 // loop, but don't allow a single term to monopolize us
792 // the number of loops is fully arbitrary, and thus wrong 786 // the number of loops is fully arbitrary, and thus wrong
793 for (int i = 1; i-- && pty_fill (); ) 787 while (flag && pty_fill ())
794 { 788 {
795 if (!seen_input) 789 if (!seen_input)
796 { 790 {
797 seen_input = 1; 791 seen_input = 1;
798 /* once we know the shell is running, send the screen size. Again! */ 792 /* once we know the shell is running, send the screen size. Again! */
799 tt_winch (); 793 tt_winch ();
800 } 794 }
801 795
802 uint32_t ch = NOCHAR; 796 uint32_t ch = NOCHAR;
803 797
804 for (;;) 798 for (;;)
805 { 799 {
806 if (ch == NOCHAR) 800 if (ch == NOCHAR)
807 ch = next_char (); 801 ch = next_char ();
808 802
809 if (ch == NOCHAR) // TODO: improve 803 if (ch == NOCHAR) // TODO: improve
810 break; 804 break;
811 805
812 if (ch >= ' ' || ch == '\t' || ch == '\n' || ch == '\r') 806 if (ch >= ' ' || ch == '\t' || ch == '\n' || ch == '\r')
813 { 807 {
814 /* Read a text string from the input buffer */ 808 /* Read a text string from the input buffer */
815 uint32_t buf[BUFSIZ]; 809 uint32_t buf[BUFSIZ];
816 bool refreshnow = false; 810 bool refreshnow = false;
817 int nlines = 0; 811 int nlines = 0;
818 uint32_t *str = buf; 812 uint32_t *str = buf;
819 813
820 *str++ = ch; 814 *str++ = ch;
821 815
822 for (;;) 816 for (;;)
823 { 817 {
824 ch = next_char (); 818 ch = next_char ();
825 819
826 if (ch == NOCHAR || (ch < ' ' && ch != '\t' && ch != '\n' && ch != '\r')) 820 if (ch == NOCHAR || (ch < ' ' && ch != '\t' && ch != '\n' && ch != '\r'))
827 break; 821 break;
828 else 822 else
829 { 823 {
830 *str++ = ch; 824 *str++ = ch;
831 825
832 if (ch == '\n') 826 if (ch == '\n')
833 { 827 {
834 nlines++; 828 nlines++;
835 refresh_count++; 829 refresh_count++;
836 830
837 if (!(Options & Opt_jumpScroll) 831 if (!(Options & Opt_jumpScroll)
838 || (refresh_count >= (refresh_limit * (TermWin.nrow - 1)))) 832 || (refresh_count >= (refresh_limit * (TermWin.nrow - 1))))
839 { 833 {
840 refreshnow = true; 834 refreshnow = true;
835 flag = false;
841 ch = NOCHAR; 836 ch = NOCHAR;
842 break; 837 break;
843 } 838 }
844 } 839 }
845 840
846 if (str >= buf + BUFSIZ) 841 if (str >= buf + BUFSIZ)
847 { 842 {
848 ch = NOCHAR; 843 ch = NOCHAR;
849 break; 844 break;
850 } 845 }
851 } 846 }
852 } 847 }
853 848
854 rxvt_scr_add_lines (this, buf, nlines, str - buf); 849 rxvt_scr_add_lines (this, buf, nlines, str - buf);
855 850
856 /* 851 /*
857 * If there have been a lot of new lines, then update the screen 852 * If there have been a lot of new lines, then update the screen
858 * What the heck I'll cheat and only refresh less than every page-full. 853 * What the heck I'll cheat and only refresh less than every page-full.
859 * the number of pages between refreshes is refresh_limit, which 854 * the number of pages between refreshes is refresh_limit, which
860 * is incremented here because we must be doing flat-out scrolling. 855 * is incremented here because we must be doing flat-out scrolling.
861 * 856 *
862 * refreshing should be correct for small scrolls, because of the 857 * refreshing should be correct for small scrolls, because of the
863 * time-out 858 * time-out
864 */ 859 */
865 if (refreshnow) 860 if (refreshnow)
866 { 861 {
867 if ((Options & Opt_jumpScroll) && refresh_limit < REFRESH_PERIOD) 862 if ((Options & Opt_jumpScroll) && refresh_limit < REFRESH_PERIOD)
868 refresh_limit++; 863 refresh_limit++;
869 864
870 rxvt_scr_refresh (this, refresh_type); 865 rxvt_scr_refresh (this, refresh_type);
871 } 866 }
872 867
873 } 868 }
874 else 869 else
875 { 870 {
876 switch (ch) 871 switch (ch)
877 { 872 {
878 default: 873 default:
879 rxvt_process_nonprinting (this, ch); 874 rxvt_process_nonprinting (this, ch);
880 break; 875 break;
881 case C0_ESC: /* escape char */ 876 case C0_ESC: /* escape char */
882 rxvt_process_escape_seq (this); 877 rxvt_process_escape_seq (this);
883 break; 878 break;
884 /*case 0x9b: */ /* CSI */ 879 /*case 0x9b: */ /* CSI */
885 /* rxvt_process_csi_seq (this); */ 880 /* rxvt_process_csi_seq (this); */
886 } 881 }
887 882
888 ch = NOCHAR; 883 ch = NOCHAR;
889 } 884 }
890 } 885 }
891 } 886 }
887 }
892} 888}
893 889
894// read the next character, currently handles UTF-8 890// read the next character, currently handles UTF-8
895// will probably handle all sorts of other stuff in the future 891// will probably handle all sorts of other stuff in the future
896uint32_t 892uint32_t

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines