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.58 by pcg, Wed Feb 25 15:06:03 2004 UTC vs.
Revision 1.81 by pcg, Sun Mar 28 02:07:08 2004 UTC

52 52
53#include <wchar.h> 53#include <wchar.h>
54 54
55/*----------------------------------------------------------------------*/ 55/*----------------------------------------------------------------------*/
56 56
57#define IS_CONTROL(ch) !((ch) & 0xffffff60UL)
58
59// exception thrown when the command parser runs out of input data
60class out_of_input { } out_of_input;
61
57/*{{{ Convert the keypress event into a string */ 62/*{{{ Convert the keypress event into a string */
58void 63void
59rxvt_term::lookup_key (XKeyEvent &ev) 64rxvt_term::lookup_key (XKeyEvent &ev)
60{ 65{
61 int ctrl, meta, shft, len; 66 int ctrl, meta, shft, len;
88#ifdef USE_XIM 93#ifdef USE_XIM
89 if (Input_Context) 94 if (Input_Context)
90 { 95 {
91 Status status_return; 96 Status status_return;
92 97
98#if 0
93#ifdef X_HAVE_UTF8_STRING 99#ifdef X_HAVE_UTF8_STRING
94 if (enc_utf8 && 0) // currently disabled, doesn't seem to work, nor is useful 100 if (enc_utf8 && 0) // currently disabled, doesn't seem to work, nor is useful
95 len = Xutf8LookupString (Input_Context, &ev, (char *)kbuf, 101 len = Xutf8LookupString (Input_Context, &ev, (char *)kbuf,
96 KBUFSZ, &keysym, &status_return); 102 KBUFSZ, &keysym, &status_return);
97 else 103 else
104#endif
98#endif 105#endif
99 { 106 {
100 wchar_t wkbuf[KBUFSZ + 1]; 107 wchar_t wkbuf[KBUFSZ + 1];
101 108
102 // the XOpenIM manpage lies about hardcoding the locale 109 // the XOpenIM manpage lies about hardcoding the locale
140 valid_keysym = keysym != NoSymbol; 147 valid_keysym = keysym != NoSymbol;
141 } 148 }
142 149
143 if (valid_keysym) 150 if (valid_keysym)
144 { 151 {
145 /* for some backwards compatibility */
146#if defined(HOTKEY_CTRL) || defined(HOTKEY_META)
147# ifdef HOTKEY_CTRL
148 if (ctrl)
149# else
150 if (meta)
151# endif
152 {
153 if (keysym == ks_bigfont)
154 {
155 change_font (FONT_UP);
156 return;
157 }
158 else if (keysym == ks_smallfont)
159 {
160 change_font (FONT_DN);
161 return;
162 }
163 }
164#endif
165
166 if (TermWin.saveLines) 152 if (TermWin.saveLines)
167 { 153 {
168#ifdef UNSHIFTED_SCROLLKEYS 154#ifdef UNSHIFTED_SCROLLKEYS
169 if (!ctrl && !meta) 155 if (!ctrl && !meta)
170 { 156 {
261#ifdef KEYSYM_RESOURCE 247#ifdef KEYSYM_RESOURCE
262 if (! (shft | ctrl) && Keysym_map[keysym & 0xFF] != NULL) 248 if (! (shft | ctrl) && Keysym_map[keysym & 0xFF] != NULL)
263 { 249 {
264 unsigned int l; 250 unsigned int l;
265 const unsigned char *kbuf0; 251 const unsigned char *kbuf0;
266 const unsigned char ch = C0_ESC;
267 252
268 kbuf0 = (Keysym_map[keysym & 0xFF]); 253 kbuf0 = (Keysym_map[keysym & 0xFF]);
269 l = (unsigned int)*kbuf0++; 254 l = (unsigned int)*kbuf0++;
270 255
271 /* escape prefix */ 256 /* escape prefix */
272 if (meta) 257 if (meta
273# ifdef META8_OPTION 258# ifdef META8_OPTION
274 if (meta_char == C0_ESC) 259 && meta_char == C0_ESC
275# endif 260# endif
261 )
262 {
263 const unsigned char ch = C0_ESC;
276 tt_write (&ch, 1); 264 tt_write (&ch, 1);
265 }
266
277 tt_write (kbuf0, l); 267 tt_write (kbuf0, l);
278 return; 268 return;
279 } 269 }
280 else 270 else
281#endif 271#endif
291 ^ !!ctrl) ? '\b' : '\177'; 281 ^ !!ctrl) ? '\b' : '\177';
292 kbuf[1] = '\0'; 282 kbuf[1] = '\0';
293 } 283 }
294 else 284 else
295 STRCPY (kbuf, key_backspace); 285 STRCPY (kbuf, key_backspace);
296# ifdef MULTICHAR_SET
297 if ((Options & Opt_mc_hack) && screen.cur.col > 0)
298 {
299 int col, row;
300
301 newlen = STRLEN (kbuf);
302 col = screen.cur.col - 1;
303 row = screen.cur.row + TermWin.saveLines;
304 if (IS_MULTI2 (screen.rend[row][col]))
305 MEMMOVE (kbuf + newlen, kbuf, newlen + 1);
306 }
307# endif
308 break; 286 break;
309#endif 287#endif
310#ifndef NO_DELETE_KEY 288#ifndef NO_DELETE_KEY
311 case XK_Delete: 289 case XK_Delete:
312 STRCPY (kbuf, key_delete); 290 STRCPY (kbuf, key_delete);
313# ifdef MULTICHAR_SET
314 if (Options & Opt_mc_hack)
315 {
316 int col, row;
317
318 newlen = STRLEN (kbuf);
319 col = screen.cur.col;
320 row = screen.cur.row + TermWin.saveLines;
321 if (IS_MULTI1 (screen.rend[row][col]))
322 MEMMOVE (kbuf + newlen, kbuf, newlen + 1);
323 }
324# endif
325 break; 291 break;
326#endif 292#endif
327 case XK_Tab: 293 case XK_Tab:
328 if (shft) 294 if (shft)
329 STRCPY (kbuf, "\033[Z"); 295 STRCPY (kbuf, "\033[Z");
371 kbuf[1] = 'O'; 337 kbuf[1] = 'O';
372 kbuf[2] = "dacb"[keysym - XK_Left]; 338 kbuf[2] = "dacb"[keysym - XK_Left];
373 } 339 }
374 else if (PrivateModes & PrivMode_aplCUR) 340 else if (PrivateModes & PrivMode_aplCUR)
375 kbuf[1] = 'O'; 341 kbuf[1] = 'O';
376#ifdef MULTICHAR_SET
377 //TODO: ??
378 if (Options & Opt_mc_hack)
379 {
380 int col, row, m;
381
382 col = screen.cur.col;
383 row = screen.cur.row + TermWin.saveLines;
384 m = 0;
385 if (keysym == XK_Right
386 && IS_MULTI1 (screen.rend[row][col]))
387 m = 1;
388 else if (keysym == XK_Left)
389 {
390 if (col > 0)
391 {
392 if (IS_MULTI2 (screen.rend[row][col - 1]))
393 m = 1;
394 }
395 else if (screen.cur.row > 0)
396 {
397 col = screen.tlen[--row];
398 if (col == -1)
399 col = TermWin.ncol - 1;
400 else
401 col--;
402 if (col > 0
403 && IS_MULTI2 (screen.rend[row][col]))
404 m = 1;
405 }
406 }
407 if (m)
408 MEMMOVE (kbuf + 3, kbuf, 3 + 1);
409 }
410#endif
411 break; 342 break;
412 343
413#ifndef UNSHIFTED_SCROLLKEYS 344#ifndef UNSHIFTED_SCROLLKEYS
414# ifdef XK_KP_Prior 345# ifdef XK_KP_Prior
415 case XK_KP_Prior: 346 case XK_KP_Prior:
604 break; 535 break;
605 } 536 }
606 if (newlen) 537 if (newlen)
607 len = STRLEN (kbuf); 538 len = STRLEN (kbuf);
608 } 539 }
540
609 /* 541 /*
610 * Pass meta for all function keys, if 'meta' option set 542 * Pass meta for all function keys, if 'meta' option set
611 */ 543 */
612#ifdef META8_OPTION 544#ifdef META8_OPTION
613 if (meta && (meta_char == 0x80) && len > 0) 545 if (meta && (meta_char == 0x80) && len > 0)
628 { 560 {
629 unsigned char *ch; 561 unsigned char *ch;
630 562
631 for (ch = kbuf; ch < kbuf + len; ch++) 563 for (ch = kbuf; ch < kbuf + len; ch++)
632 *ch |= 0x80; 564 *ch |= 0x80;
565
633 meta = 0; 566 meta = 0;
634 } 567 }
635#endif 568#endif
636 /* nil */ ; 569 /* nil */ ;
637 } 570 }
690/*{{{ rxvt_cmd_write (), rxvt_cmd_getc () */ 623/*{{{ rxvt_cmd_write (), rxvt_cmd_getc () */
691/* attempt to `write' count to the input buffer */ 624/* attempt to `write' count to the input buffer */
692unsigned int 625unsigned int
693rxvt_term::cmd_write (const unsigned char *str, unsigned int count) 626rxvt_term::cmd_write (const unsigned char *str, unsigned int count)
694{ 627{
695 unsigned int n, s; 628 unsigned int n, s;
696 629
697 n = cmdbuf_ptr - cmdbuf_base; 630 n = cmdbuf_ptr - cmdbuf_base;
698 s = cmdbuf_base + BUFSIZ - 1 - cmdbuf_endp; 631 s = cmdbuf_base + CBUFSIZ - 1 - cmdbuf_endp;
699 632
700 if (n > 0 && s < count) 633 if (n > 0 && s < count)
701 { 634 {
702 MEMMOVE (cmdbuf_base, cmdbuf_ptr, 635 MEMMOVE (cmdbuf_base, cmdbuf_ptr,
703 (unsigned int) (cmdbuf_endp - cmdbuf_ptr)); 636 (unsigned int) (cmdbuf_endp - cmdbuf_ptr));
706 s += n; 639 s += n;
707 } 640 }
708 641
709 if (count > s) 642 if (count > s)
710 { 643 {
711 rxvt_print_error ("data loss: cmd_write too large"); 644 rxvt_warn ("data loss: cmd_write too large, continuing.\n");
712 count = s; 645 count = s;
713 } 646 }
714 647
715 for (; count--;) 648 for (; count--;)
716 *cmdbuf_endp++ = *str++; 649 *cmdbuf_endp++ = *str++;
787 720
788 memmove (cmdbuf_base, cmdbuf_ptr, n); 721 memmove (cmdbuf_base, cmdbuf_ptr, n);
789 cmdbuf_ptr = cmdbuf_base; 722 cmdbuf_ptr = cmdbuf_base;
790 cmdbuf_endp = cmdbuf_ptr + n; 723 cmdbuf_endp = cmdbuf_ptr + n;
791 724
792 n = read (cmd_fd, cmdbuf_endp, BUFSIZ - n); 725 n = read (cmd_fd, cmdbuf_endp, CBUFSIZ - n);
793 726
794 if (n > 0) 727 if (n > 0)
795 { 728 {
796 cmdbuf_endp += n; 729 cmdbuf_endp += n;
797 return true; 730 return true;
810 743
811 if (revents & EVENT_WRITE) 744 if (revents & EVENT_WRITE)
812 tt_write (0, 0); 745 tt_write (0, 0);
813 else if (revents & EVENT_READ) 746 else if (revents & EVENT_READ)
814 { 747 {
815 bool flag = true;
816
817 // loop, but don't allow a single term to monopolize us 748 // loop, but don't allow a single term to monopolize us
818 // the number of loops is fully arbitrary, and thus wrong 749 // the number of loops is fully arbitrary, and thus wrong
819 while (flag && pty_fill ()) 750 while (pty_fill ())
820 { 751 {
821 if (!seen_input) 752 if (!seen_input)
822 { 753 {
823 seen_input = 1; 754 seen_input = 1;
824 /* once we know the shell is running, send the screen size. Again! */ 755 /* once we know the shell is running, send the screen size. Again! */
756 // I don't know why, btw.
825 tt_winch (); 757 tt_winch ();
826 } 758 }
827 759
828 if (cmd_parse ()) 760 if (cmd_parse ())
829 break; 761 break;
830 } 762 }
831 }
832}
833
834bool
835rxvt_term::cmd_parse ()
836{
837 bool flag = false;
838 uint32_t ch = NOCHAR;
839
840 for (;;)
841 {
842 if (ch == NOCHAR)
843 ch = next_char ();
844
845 if (ch == NOCHAR) // TODO: improve
846 break;
847
848 if (ch >= ' ' || ch == '\t' || ch == '\n' || ch == '\r')
849 {
850 /* Read a text string from the input buffer */
851 uint32_t buf[BUFSIZ];
852 bool refreshnow = false;
853 int nlines = 0;
854 uint32_t *str = buf;
855
856 *str++ = ch;
857
858 for (;;)
859 {
860 ch = next_char ();
861
862 if (ch == NOCHAR || (ch < ' ' && ch != '\t' && ch != '\n' && ch != '\r'))
863 break;
864 else
865 {
866 *str++ = ch;
867
868 if (ch == '\n')
869 {
870 nlines++;
871 refresh_count++;
872
873 if (! (Options & Opt_jumpScroll)
874 || (refresh_count >= (refresh_limit * (TermWin.nrow - 1))))
875 {
876 refreshnow = true;
877 flag = false;
878 ch = NOCHAR;
879 break;
880 }
881
882 // scr_add_lines only works for nlines < TermWin.nrow - 1.
883 if (nlines >= TermWin.nrow - 1)
884 {
885 scr_add_lines (buf, nlines, str - buf);
886 nlines = 0;
887 str = buf;
888 }
889 }
890
891 if (str >= buf + BUFSIZ)
892 {
893 ch = NOCHAR;
894 break;
895 }
896 }
897 }
898
899 scr_add_lines (buf, nlines, str - buf);
900
901 /*
902 * If there have been a lot of new lines, then update the screen
903 * What the heck I'll cheat and only refresh less than every page-full.
904 * the number of pages between refreshes is refresh_limit, which
905 * is incremented here because we must be doing flat-out scrolling.
906 *
907 * refreshing should be correct for small scrolls, because of the
908 * time-out
909 */
910 if (refreshnow)
911 {
912 if ((Options & Opt_jumpScroll) && refresh_limit < REFRESH_PERIOD)
913 refresh_limit++;
914
915 scr_refresh (refresh_type);
916 }
917
918 }
919 else
920 {
921 switch (ch)
922 {
923 default:
924 process_nonprinting (ch);
925 break;
926 case C0_ESC: /* escape char */
927 process_escape_seq ();
928 break;
929 /*case 0x9b: */ /* CSI */
930 /* process_csi_seq (); */
931 }
932
933 ch = NOCHAR;
934 }
935 }
936
937 return flag;
938}
939
940// read the next character, currently handles UTF-8
941// will probably handle all sorts of other stuff in the future
942uint32_t
943rxvt_term::next_char ()
944{
945 while (cmdbuf_ptr < cmdbuf_endp)
946 {
947 if (*cmdbuf_ptr < 0x80) // assume < 0x80 to be ascii ALWAYS (all shift-states etc.) uh-oh
948 return *cmdbuf_ptr++;
949
950 wchar_t wc;
951 size_t len = mbrtowc (&wc, (char *)cmdbuf_ptr, cmdbuf_endp - cmdbuf_ptr, mbstate);
952
953 if (len == (size_t)-2)
954 return NOCHAR;
955
956 if (len == (size_t)-1)
957 return *cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through
958
959 // assume wchar == unicode
960 cmdbuf_ptr += len;
961 return wc;
962 }
963
964 return NOCHAR;
965}
966
967/* rxvt_cmd_getc () - Return next input character */
968/*
969 * Return the next input character after first passing any keyboard input
970 * to the command.
971 */
972uint32_t
973rxvt_term::cmd_getc ()
974{
975 for (;;)
976 {
977 uint32_t c = next_char ();
978 if (c != NOCHAR)
979 return c;
980
981 // incomplete sequences should occur rarely, still, a better solution
982 // would be preferred. either setjmp/longjmp or better design.
983 fcntl (cmd_fd, F_SETFL, 0);
984 pty_fill ();
985 fcntl (cmd_fd, F_SETFL, O_NONBLOCK);
986 } 763 }
987} 764}
988 765
989#ifdef POINTER_BLANK 766#ifdef POINTER_BLANK
990void 767void
1359 1136
1360 } 1137 }
1361 break; 1138 break;
1362 1139
1363 case SelectionClear: 1140 case SelectionClear:
1364 display->set_selection_owner (0); 1141 selection_clear ();
1365 break; 1142 break;
1366 1143
1367 case SelectionNotify: 1144 case SelectionNotify:
1368 if (selection_wait == Sel_normal) 1145 if (selection_wait == Sel_normal)
1369 selection_paste (ev.xselection.requestor, 1146 selection_paste (ev.xselection.requestor,
1987 if (have_pixmap) 1764 if (have_pixmap)
1988 { 1765 {
1989 /* 1766 /*
1990 * Copy display->root pixmap transparency 1767 * Copy display->root pixmap transparency
1991 */ 1768 */
1992 int sx, sy, nx, ny; 1769 int sx, sy, nx, ny;
1993 unsigned int nw, nh; 1770 unsigned int nw, nh;
1994 Window cr; 1771 Window cr;
1995 XImage *image; 1772 XImage *image;
1996 GC gc; 1773 GC gc;
1997 XGCValues gcvalue; 1774 XGCValues gcvalue;
1998 1775
1999 XTranslateCoordinates (display->display, TermWin.parent[0], display->root, 1776 XTranslateCoordinates (display->display, TermWin.parent[0], display->root,
2000 0, 0, &sx, &sy, &cr); 1777 0, 0, &sx, &sy, &cr);
2001 nw = (unsigned int)szHint.width; 1778 nw = (unsigned int)szHint.width;
2002 nh = (unsigned int)szHint.height; 1779 nh = (unsigned int)szHint.height;
2003 nx = ny = 0; 1780 nx = ny = 0;
1781
2004 if (sx < 0) 1782 if (sx < 0)
2005 { 1783 {
2006 nw += sx; 1784 nw += sx;
2007 nx = -sx; 1785 nx = -sx;
2008 sx = 0; 1786 sx = 0;
2009 } 1787 }
1788
2010 if (sy < 0) 1789 if (sy < 0)
2011 { 1790 {
2012 nh += sy; 1791 nh += sy;
2013 ny = -sy; 1792 ny = -sy;
2014 sy = 0; 1793 sy = 0;
2015 } 1794 }
1795
2016 MIN_IT (nw, (unsigned int) (wrootattr.width - sx)); 1796 MIN_IT (nw, (unsigned int) (wrootattr.width - sx));
2017 MIN_IT (nh, (unsigned int) (wrootattr.height - sy)); 1797 MIN_IT (nh, (unsigned int) (wrootattr.height - sy));
2018 allowedxerror = -1; 1798 allowedxerror = -1;
2019 image = XGetImage (display->display, rootpixmap, sx, sy, nw, nh, AllPlanes, 1799 image = XGetImage (display->display, rootpixmap, sx, sy, nw, nh, AllPlanes,
2020 ZPixmap); 1800 ZPixmap);
2053 if (!am_transparent || !am_pixmap_trans) 1833 if (!am_transparent || !am_pixmap_trans)
2054 pchanged = 1; 1834 pchanged = 1;
2055 am_transparent = am_pixmap_trans = 1; 1835 am_transparent = am_pixmap_trans = 1;
2056 } 1836 }
2057 } 1837 }
1838
2058 if (!am_pixmap_trans) 1839 if (!am_pixmap_trans)
2059 { 1840 {
2060 unsigned int n; 1841 unsigned int n;
2061 /* 1842 /*
2062 * InheritPixmap transparency 1843 * InheritPixmap transparency
2077 break; 1858 break;
2078 } 1859 }
2079 if (oldp != TermWin.parent[i]) 1860 if (oldp != TermWin.parent[i])
2080 pchanged = 1; 1861 pchanged = 1;
2081 } 1862 }
1863
2082 n = 0; 1864 n = 0;
1865
2083 if (pchanged) 1866 if (pchanged)
2084 { 1867 {
2085 for (; n < (unsigned int)i; n++) 1868 for (; n < (unsigned int)i; n++)
2086 { 1869 {
2087 XGetWindowAttributes (display->display, TermWin.parent[n], &wattr); 1870 XGetWindowAttributes (display->display, TermWin.parent[n], &wattr);
2091 n = (int) (sizeof (TermWin.parent) / sizeof (Window)) + 1; 1874 n = (int) (sizeof (TermWin.parent) / sizeof (Window)) + 1;
2092 break; 1875 break;
2093 } 1876 }
2094 } 1877 }
2095 } 1878 }
1879
2096 if (n > (int) (sizeof (TermWin.parent) 1880 if (n > (int) (sizeof (TermWin.parent)
2097 / sizeof (TermWin.parent[0]))) 1881 / sizeof (TermWin.parent[0])))
2098 { 1882 {
2099 D_X ((stderr, "InheritPixmap Turning off")); 1883 D_X ((stderr, "InheritPixmap Turning off"));
2100 XSetWindowBackground (display->display, TermWin.parent[0], 1884 XSetWindowBackground (display->display, TermWin.parent[0],
2123 ParentRelative); 1907 ParentRelative);
2124 XSetWindowBackgroundPixmap (display->display, TermWin.vt, 1908 XSetWindowBackgroundPixmap (display->display, TermWin.vt,
2125 ParentRelative); 1909 ParentRelative);
2126 am_transparent = 1; 1910 am_transparent = 1;
2127 } 1911 }
1912
2128 for (; i < (int) (sizeof (TermWin.parent) / sizeof (Window)); i++) 1913 for (; i < (int) (sizeof (TermWin.parent) / sizeof (Window)); i++)
2129 TermWin.parent[i] = None; 1914 TermWin.parent[i] = None;
2130 } 1915 }
2131 return pchanged; 1916 return pchanged;
2132} 1917}
2133#endif 1918#endif
2134 1919
2135/*}}} */ 1920/*}}} */
1921
1922bool
1923rxvt_term::cmd_parse ()
1924{
1925 bool flag = false;
1926 unicode_t ch = NOCHAR;
1927 unsigned char *seq_begin; // remember start of esc-sequence here
1928
1929 for (;;)
1930 {
1931 if (ch == NOCHAR)
1932 {
1933 seq_begin = cmdbuf_ptr;
1934 ch = next_char ();
1935 }
1936
1937 if (ch == NOCHAR) // TODO: improve
1938 break;
1939
1940 if (!IS_CONTROL (ch) || ch == '\t' || ch == '\n' || ch == '\r')
1941 {
1942 /* Read a text string from the input buffer */
1943 unicode_t buf[UBUFSIZ];
1944 bool refreshnow = false;
1945 int nlines = 0;
1946 unicode_t *str = buf;
1947
1948 *str++ = ch;
1949
1950 for (;;)
1951 {
1952 seq_begin = cmdbuf_ptr;
1953 ch = next_char ();
1954
1955 if (ch == NOCHAR || (IS_CONTROL (ch) && ch != '\t' && ch != '\n' && ch != '\r'))
1956 break;
1957
1958 *str++ = ch;
1959
1960 if (ch == '\n')
1961 {
1962 nlines++;
1963 refresh_count++;
1964
1965 if (! (Options & Opt_jumpScroll)
1966 || (refresh_count >= (refresh_limit * (TermWin.nrow - 1))))
1967 {
1968 refreshnow = true;
1969 flag = true;
1970 ch = NOCHAR;
1971 break;
1972 }
1973
1974 // scr_add_lines only works for nlines < TermWin.nrow - 1.
1975 if (nlines >= TermWin.nrow - 1)
1976 {
1977 scr_add_lines (buf, nlines, str - buf);
1978 nlines = 0;
1979 str = buf;
1980 }
1981 }
1982
1983 if (str >= buf + UBUFSIZ)
1984 {
1985 ch = NOCHAR;
1986 break;
1987 }
1988 }
1989
1990 scr_add_lines (buf, nlines, str - buf);
1991
1992 /*
1993 * If there have been a lot of new lines, then update the screen
1994 * What the heck I'll cheat and only refresh less than every page-full.
1995 * the number of pages between refreshes is refresh_limit, which
1996 * is incremented here because we must be doing flat-out scrolling.
1997 *
1998 * refreshing should be correct for small scrolls, because of the
1999 * time-out
2000 */
2001 if (refreshnow)
2002 {
2003 if ((Options & Opt_jumpScroll) && refresh_limit < REFRESH_PERIOD)
2004 refresh_limit++;
2005
2006 scr_refresh (refresh_type);
2007 }
2008
2009 }
2010 else
2011 {
2012 try
2013 {
2014 process_nonprinting (ch);
2015 }
2016 catch (const class out_of_input &o)
2017 {
2018 // we ran out of input, retry later
2019 cmdbuf_ptr = seq_begin;
2020 break;
2021 }
2022
2023 ch = NOCHAR;
2024 }
2025 }
2026
2027 return flag;
2028}
2029
2030// read the next character
2031unicode_t
2032rxvt_term::next_char ()
2033{
2034 while (cmdbuf_ptr < cmdbuf_endp)
2035 {
2036 // assume 7-bit to be ascii ALWAYS
2037 if (*cmdbuf_ptr <= 0x7f && *cmdbuf_ptr != 0x1b)
2038 return *cmdbuf_ptr++;
2039
2040 wchar_t wc;
2041 size_t len = mbrtowc (&wc, (char *)cmdbuf_ptr, cmdbuf_endp - cmdbuf_ptr, mbstate);
2042
2043 if (len == (size_t)-2)
2044 {
2045 // the mbstate stores incomplete sequences. didn't know this :/
2046 cmdbuf_ptr = cmdbuf_endp;
2047 break;
2048 }
2049
2050 if (len == (size_t)-1)
2051 return *cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through
2052
2053 // assume wchar == unicode
2054 cmdbuf_ptr += len;
2055 return wc;
2056 }
2057
2058 return NOCHAR;
2059}
2060
2061/* rxvt_cmd_getc () - Return next input character */
2062/*
2063 * Return the next input character after first passing any keyboard input
2064 * to the command.
2065 */
2066unicode_t
2067rxvt_term::cmd_getc ()
2068{
2069 unicode_t c = next_char ();
2070
2071 if (c == NOCHAR)
2072 throw out_of_input;
2073
2074 return c;
2075}
2136 2076
2137/*{{{ print pipe */ 2077/*{{{ print pipe */
2138/*----------------------------------------------------------------------*/ 2078/*----------------------------------------------------------------------*/
2139#ifdef PRINTPIPE 2079#ifdef PRINTPIPE
2140FILE * 2080FILE *
2141rxvt_term::popen_printer () 2081rxvt_term::popen_printer ()
2142{ 2082{
2143 FILE *stream = popen (rs[Rs_print_pipe], "w"); 2083 FILE *stream = popen (rs[Rs_print_pipe], "w");
2144 2084
2145 if (stream == NULL) 2085 if (stream == NULL)
2146 rxvt_print_error ("can't open printer pipe"); 2086 rxvt_warn ("can't open printer pipe, not printing.\n");
2087
2147 return stream; 2088 return stream;
2148} 2089}
2149 2090
2150int 2091int
2151rxvt_term::pclose_printer (FILE *stream) 2092rxvt_term::pclose_printer (FILE *stream)
2152{ 2093{
2153 fflush (stream); 2094 fflush (stream);
2154 /* pclose () reported not to work on SunOS 4.1.3 */
2155# if defined (__sun__) /* TODO: RESOLVE THIS */
2156 /* pclose works provided SIGCHLD handler uses waitpid */
2157 return pclose (stream); /* return fclose (stream); */
2158# else
2159 return pclose (stream); 2095 return pclose (stream);
2160# endif
2161} 2096}
2162 2097
2163/* 2098/*
2164 * simulate attached vt100 printer 2099 * simulate attached vt100 printer
2165 */ 2100 */
2166void 2101void
2167rxvt_term::process_print_pipe () 2102rxvt_term::process_print_pipe ()
2168{ 2103{
2169 int done; 2104 int done;
2170 FILE *fd; 2105 FILE *fd;
2171 2106
2172 if ((fd = popen_printer ()) == NULL) 2107 if ((fd = popen_printer ()) == NULL)
2173 return; 2108 return;
2174 2109
2175 /* 2110 /*
2176 * Send all input to the printer until either ESC[4i or ESC[?4i 2111 * Send all input to the printer until either ESC[4i or ESC[?4i
2177 * is received. 2112 * is received.
2178 */ 2113 */
2179 for (done = 0; !done;) 2114 for (done = 0; !done;)
2180 { 2115 {
2181 unsigned char buf[8]; 2116 unsigned char buf[8];
2182 unsigned char ch; 2117 unicode_t ch;
2183 unsigned int i, len; 2118 unsigned int i, len;
2184 2119
2185 if ((ch = cmd_getc ()) != C0_ESC) 2120 if ((ch = cmd_getc ()) != C0_ESC)
2186 { 2121 {
2187 if (putc (ch, fd) == EOF) 2122 if (putc (ch, fd) == EOF)
2188 break; /* done = 1 */ 2123 break; /* done = 1 */
2203 { 2138 {
2204 if ((buf[len++] = cmd_getc ()) == 'i') 2139 if ((buf[len++] = cmd_getc ()) == 'i')
2205 break; /* done = 1 */ 2140 break; /* done = 1 */
2206 } 2141 }
2207 } 2142 }
2143
2208 for (i = 0; i < len; i++) 2144 for (i = 0; i < len; i++)
2209 if (putc (buf[i], fd) == EOF) 2145 if (putc (buf[i], fd) == EOF)
2210 { 2146 {
2211 done = 1; 2147 done = 1;
2212 break; 2148 break;
2213 } 2149 }
2214 } 2150 }
2215 } 2151 }
2152
2216 pclose_printer (fd); 2153 pclose_printer (fd);
2217} 2154}
2218#endif /* PRINTPIPE */ 2155#endif /* PRINTPIPE */
2219/*}}} */ 2156/*}}} */
2220 2157
2228}; 2165};
2229/* *INDENT-ON* */ 2166/* *INDENT-ON* */
2230 2167
2231/*{{{ process non-printing single characters */ 2168/*{{{ process non-printing single characters */
2232void 2169void
2233rxvt_term::process_nonprinting (unsigned char ch) 2170rxvt_term::process_nonprinting (unicode_t ch)
2234{ 2171{
2235 switch (ch) 2172 switch (ch)
2236 { 2173 {
2174 case C0_ESC:
2175 process_escape_seq ();
2176 break;
2237 case C0_ENQ: /* terminal Status */ 2177 case C0_ENQ: /* terminal Status */
2238 if (rs[Rs_answerbackstring]) 2178 if (rs[Rs_answerbackstring])
2239 tt_write ( 2179 tt_write (
2240 (const unsigned char *)rs[Rs_answerbackstring], 2180 (const unsigned char *)rs[Rs_answerbackstring],
2241 (unsigned int)STRLEN (rs[Rs_answerbackstring])); 2181 (unsigned int)STRLEN (rs[Rs_answerbackstring]));
2264 scr_charset_choose (1); 2204 scr_charset_choose (1);
2265 break; 2205 break;
2266 case C0_SI: /* shift in - acs */ 2206 case C0_SI: /* shift in - acs */
2267 scr_charset_choose (0); 2207 scr_charset_choose (0);
2268 break; 2208 break;
2209
2210 // 8-bit controls
2211 case 0x90: /* DCS */
2212 process_dcs_seq ();
2213 break;
2214 case 0x9b: /* CSI */
2215 process_csi_seq ();
2216 break;
2217 case 0x9d: /* CSI */
2218 process_osc_seq ();
2219 break;
2269 } 2220 }
2270} 2221}
2271/*}}} */ 2222/*}}} */
2272 2223
2273 2224
2274/*{{{ process VT52 escape sequences */ 2225/*{{{ process VT52 escape sequences */
2275void 2226void
2276rxvt_term::process_escape_vt52 (unsigned char ch) 2227rxvt_term::process_escape_vt52 (unicode_t ch)
2277{ 2228{
2278 int row, col; 2229 int row, col;
2279 2230
2280 switch (ch) 2231 switch (ch)
2281 { 2232 {
2333 2284
2334/*{{{ process escape sequences */ 2285/*{{{ process escape sequences */
2335void 2286void
2336rxvt_term::process_escape_seq () 2287rxvt_term::process_escape_seq ()
2337{ 2288{
2338 unsigned char ch = cmd_getc (); 2289 unicode_t ch = cmd_getc ();
2339 2290
2340 if (PrivateModes & PrivMode_vt52) 2291 if (PrivateModes & PrivMode_vt52)
2341 { 2292 {
2342 process_escape_vt52 (ch); 2293 process_escape_vt52 (ch);
2343 return; 2294 return;
2360 scr_charset_set (2, (unsigned int)cmd_getc ()); 2311 scr_charset_set (2, (unsigned int)cmd_getc ());
2361 break; 2312 break;
2362 case '+': 2313 case '+':
2363 scr_charset_set (3, (unsigned int)cmd_getc ()); 2314 scr_charset_set (3, (unsigned int)cmd_getc ());
2364 break; 2315 break;
2365#ifdef MULTICHAR_SET
2366 case '$':
2367 scr_charset_set (-2, (unsigned int)cmd_getc ());
2368 break;
2369#endif
2370#ifndef NO_FRILLS 2316#ifndef NO_FRILLS
2371 case '6': 2317 case '6':
2372 scr_backindex (); 2318 scr_backindex ();
2373 break; 2319 break;
2374#endif 2320#endif
2396 break; 2342 break;
2397 2343
2398 /* 8.3.87: NEXT LINE */ 2344 /* 8.3.87: NEXT LINE */
2399 case C1_NEL: /* ESC E */ 2345 case C1_NEL: /* ESC E */
2400 { 2346 {
2401 uint32_t nlcr[] = { '\n', '\r' }; 2347 unicode_t nlcr[] = { L'\n', L'\r' };
2402 scr_add_lines (nlcr, 1, 2); 2348 scr_add_lines (nlcr, 1, 2);
2403 } 2349 }
2404 break; 2350 break;
2405 2351
2406 /* kidnapped escape sequence: Should be 8.3.48 */ 2352 /* kidnapped escape sequence: Should be 8.3.48 */
2498/* *INDENT-ON* */ 2444/* *INDENT-ON* */
2499 2445
2500void 2446void
2501rxvt_term::process_csi_seq () 2447rxvt_term::process_csi_seq ()
2502{ 2448{
2503 unsigned char ch, priv, i; 2449 unicode_t ch, priv, i;
2504 unsigned int nargs, p; 2450 unsigned int nargs, p;
2505 int n, ndef; 2451 int n, ndef;
2506 int arg[ESC_ARGS]; 2452 int arg[ESC_ARGS];
2507 2453
2508 for (nargs = ESC_ARGS; nargs > 0;) 2454 for (nargs = ESC_ARGS; nargs > 0;)
2509 arg[--nargs] = 0; 2455 arg[--nargs] = 0;
2510 2456
2511 priv = 0; 2457 priv = 0;
2513 if (ch >= '<' && ch <= '?') 2459 if (ch >= '<' && ch <= '?')
2514 { /* '<' '=' '>' '?' */ 2460 { /* '<' '=' '>' '?' */
2515 priv = ch; 2461 priv = ch;
2516 ch = cmd_getc (); 2462 ch = cmd_getc ();
2517 } 2463 }
2464
2518 /* read any numerical arguments */ 2465 /* read any numerical arguments */
2519 for (n = -1; ch < CSI_ICH; ) 2466 for (n = -1; ch < CSI_ICH; )
2520 { 2467 {
2521 if (isdigit (ch)) 2468 if (isdigit (ch))
2522 { 2469 {
2529 { 2476 {
2530 if (nargs < ESC_ARGS) 2477 if (nargs < ESC_ARGS)
2531 arg[nargs++] = n; 2478 arg[nargs++] = n;
2532 n = -1; 2479 n = -1;
2533 } 2480 }
2534 else if (ch == '\b') 2481 else if (IS_CONTROL (ch))
2535 {
2536 scr_backspace ();
2537 }
2538 else if (ch == C0_ESC)
2539 {
2540 process_escape_seq ();
2541 return;
2542 }
2543 else if (ch < ' ')
2544 {
2545 process_nonprinting (ch); 2482 process_nonprinting (ch);
2546 } 2483
2547 ch = cmd_getc (); 2484 ch = cmd_getc ();
2548 } 2485 }
2549 2486
2550 if (ch > CSI_7F) 2487 if (ch > CSI_7F)
2551 return; 2488 return;
2715 case 7: /* unofficial extension */ 2652 case 7: /* unofficial extension */
2716 tt_printf ("%-.250s\n", rs[Rs_display_name]); 2653 tt_printf ("%-.250s\n", rs[Rs_display_name]);
2717 break; 2654 break;
2718#endif 2655#endif
2719 case 8: /* unofficial extension */ 2656 case 8: /* unofficial extension */
2720 xterm_seq (XTerm_title, APL_NAME "-" VERSION, CHAR_ST); 2657 xterm_seq (XTerm_title, RESNAME "-" VERSION, CHAR_ST);
2721 break; 2658 break;
2722 } 2659 }
2723 break; 2660 break;
2724 2661
2725 case CSI_TBC: /* 8.3.155: (0) TABULATION CLEAR */ 2662 case CSI_TBC: /* 8.3.155: (0) TABULATION CLEAR */
2793#endif 2730#endif
2794 2731
2795 case CSI_78: /* DECREQTPARM */ 2732 case CSI_78: /* DECREQTPARM */
2796 if (arg[0] == 0 || arg[0] == 1) 2733 if (arg[0] == 0 || arg[0] == 1)
2797 tt_printf ("\033[%d;1;1;128;128;1;0x", arg[0] + 2); 2734 tt_printf ("\033[%d;1;1;128;128;1;0x", arg[0] + 2);
2798 /* FALLTHROUGH */ 2735 break;
2799 2736
2800 default: 2737 default:
2801 break; 2738 break;
2802 } 2739 }
2803} 2740}
2806#ifndef NO_FRILLS 2743#ifndef NO_FRILLS
2807/* ARGSUSED */ 2744/* ARGSUSED */
2808void 2745void
2809rxvt_term::process_window_ops (const int *args, unsigned int nargs) 2746rxvt_term::process_window_ops (const int *args, unsigned int nargs)
2810{ 2747{
2811 int x, y; 2748 int x, y;
2812#if 0
2813 char *s;
2814#endif
2815 XWindowAttributes wattr; 2749 XWindowAttributes wattr;
2816 Window wdummy; 2750 Window wdummy;
2817 2751
2818 if (nargs == 0) 2752 if (nargs == 0)
2819 return; 2753 return;
2754
2820 switch (args[0]) 2755 switch (args[0])
2821 { 2756 {
2822 /* 2757 /*
2823 * commands 2758 * commands
2824 */ 2759 */
2825 case 1: /* deiconify window */ 2760 case 1: /* deiconify window */
2826 XMapWindow (display->display, TermWin.parent[0]); 2761 XMapWindow (display->display, TermWin.parent[0]);
2827 break; 2762 break;
2828 case 2: /* iconify window */ 2763 case 2: /* iconify window */
2829 XIconifyWindow (display->display, TermWin.parent[0], 2764 XIconifyWindow (display->display, TermWin.parent[0],
2846 break; 2781 break;
2847 case 8: /* set size (chars) */ 2782 case 8: /* set size (chars) */
2848 set_widthheight ((unsigned int) (args[2] * TermWin.fwidth), 2783 set_widthheight ((unsigned int) (args[2] * TermWin.fwidth),
2849 (unsigned int) (args[1] * TermWin.fheight)); 2784 (unsigned int) (args[1] * TermWin.fheight));
2850 break; 2785 break;
2786
2787 //case 9: NYI, TODO, restore maximized window or maximize window
2851 default: 2788 default:
2852 if (args[0] >= 24) /* set height (chars) */ 2789 if (args[0] >= 24) /* set height (chars) */
2853 set_widthheight ((unsigned int)TermWin.width, 2790 set_widthheight ((unsigned int)TermWin.width,
2854 (unsigned int) (args[1] * TermWin.fheight)); 2791 (unsigned int) (args[1] * TermWin.fheight));
2855 break; 2792 break;
2793
2794
2856 /* 2795 /*
2857 * reports - some output format copied from XTerm 2796 * reports - some output format copied from XTerm
2858 */ 2797 */
2859 case 11: /* report window state */ 2798 case 11: /* report window state */
2860 XGetWindowAttributes (display->display, TermWin.parent[0], &wattr); 2799 XGetWindowAttributes (display->display, TermWin.parent[0], &wattr);
2861 tt_printf ("\033[%dt", wattr.map_state == IsViewable ? 1 : 2); 2800 tt_printf ("\033[%dt", wattr.map_state == IsViewable ? 1 : 2);
2862 break; 2801 break;
2863 case 13: /* report window position */ 2802 case 13: /* report window position */
2869 break; 2808 break;
2870 case 14: /* report window size (pixels) */ 2809 case 14: /* report window size (pixels) */
2871 XGetWindowAttributes (display->display, TermWin.parent[0], &wattr); 2810 XGetWindowAttributes (display->display, TermWin.parent[0], &wattr);
2872 tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width); 2811 tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width);
2873 break; 2812 break;
2874 case 18: /* report window size (chars) */ 2813 case 18: /* report text area size (chars) */
2875 tt_printf ("\033[8;%d;%dt", TermWin.nrow, TermWin.ncol); 2814 tt_printf ("\033[8;%d;%dt", TermWin.nrow, TermWin.ncol);
2815 break;
2816 case 19: /* report window size (chars) */
2817 tt_printf ("\033[9;%d;%dt", TermWin.nrow, TermWin.ncol);
2876 break; 2818 break;
2877#if 0 /* XXX: currently disabled due to security concerns */ 2819#if 0 /* XXX: currently disabled due to security concerns */
2878 case 20: /* report icon label */ 2820 case 20: /* report icon label */
2879 XGetIconName (display->display, TermWin.parent[0], &s); 2821 XGetIconName (display->display, TermWin.parent[0], &s);
2880 tt_printf ("\033]L%-.200s\234", s ? s : ""); /* 8bit ST */ 2822 tt_printf ("\033]L%-.200s\234", s ? s : ""); /* 8bit ST */
2882 case 21: /* report window title */ 2824 case 21: /* report window title */
2883 XFetchName (display->display, TermWin.parent[0], &s); 2825 XFetchName (display->display, TermWin.parent[0], &s);
2884 tt_printf ("\033]l%-.200s\234", s ? s : ""); /* 8bit ST */ 2826 tt_printf ("\033]l%-.200s\234", s ? s : ""); /* 8bit ST */
2885 break; 2827 break;
2886#endif 2828#endif
2887
2888 } 2829 }
2889} 2830}
2890#endif 2831#endif
2891 2832
2892/*----------------------------------------------------------------------*/ 2833/*----------------------------------------------------------------------*/
2893/* 2834/*
2894 * get input up until STRING TERMINATOR (or BEL) 2835 * get input up until STRING TERMINATOR (or BEL)
2895 * ends_how is terminator used. returned input must be free ()d 2836 * ends_how is terminator used. returned input must be free ()d
2896 */ 2837 */
2897unsigned char * 2838unsigned char *
2898rxvt_term::get_to_st (unsigned char *ends_how) 2839rxvt_term::get_to_st (unicode_t &ends_how)
2899{ 2840{
2900 int seen_esc = 0; /* seen escape? */ 2841 int seen_esc = 0; /* seen escape? */
2901 unsigned int n = 0; 2842 unsigned int n = 0;
2902 unsigned char *s; 2843 unsigned char *s;
2844 unicode_t ch;
2903 unsigned char ch, string[STRING_MAX]; 2845 unsigned char string[STRING_MAX];
2904 2846
2905 for (; (ch = cmd_getc ());) 2847 while ((ch = cmd_getc ()))
2906 { 2848 {
2907 if (ch == C0_BEL 2849 if (ch == C0_BEL
2908 || ch == CHAR_ST 2850 || ch == CHAR_ST
2909 || (ch == 0x5c && seen_esc)) /* 7bit ST */ 2851 || (ch == 0x5c && seen_esc)) /* 7bit ST */
2910 break; 2852 break;
2853
2911 if (ch == C0_ESC) 2854 if (ch == C0_ESC)
2912 { 2855 {
2913 seen_esc = 1; 2856 seen_esc = 1;
2914 continue; 2857 continue;
2915 } 2858 }
2916 else if (ch == '\t') 2859 else if (ch == '\t')
2917 ch = ' '; /* translate '\t' to space */ 2860 ch = ' '; /* translate '\t' to space */
2918 else if (ch < 0x08 || (ch > 0x0d && ch < 0x20)) 2861 else if (ch < 0x08 || (ch > 0x0d && ch < 0x20))
2919 return NULL; /* other control character - exit */ 2862 return NULL; /* other control character - exit */
2863
2920 if (n < sizeof (string) - 1) 2864 if (n < sizeof (string) - 1)
2921 string[n++] = ch; 2865 string[n++] = ch;
2866
2922 seen_esc = 0; 2867 seen_esc = 0;
2923 } 2868 }
2869
2924 string[n++] = '\0'; 2870 string[n++] = '\0';
2871
2925 if ((s = (unsigned char *)rxvt_malloc (n)) == NULL) 2872 if ((s = (unsigned char *)rxvt_malloc (n)) == NULL)
2926 return NULL; 2873 return NULL;
2874
2927 *ends_how = (ch == 0x5c ? C0_ESC : ch); 2875 ends_how = (ch == 0x5c ? C0_ESC : ch);
2928 STRNCPY (s, string, n); 2876 STRNCPY (s, string, n);
2929 return s; 2877 return s;
2930} 2878}
2931 2879
2932/*----------------------------------------------------------------------*/ 2880/*----------------------------------------------------------------------*/
2934 * process DEVICE CONTROL STRING `ESC P ... (ST|BEL)' or `0x90 ... (ST|BEL)' 2882 * process DEVICE CONTROL STRING `ESC P ... (ST|BEL)' or `0x90 ... (ST|BEL)'
2935 */ 2883 */
2936void 2884void
2937rxvt_term::process_dcs_seq () 2885rxvt_term::process_dcs_seq ()
2938{ 2886{
2939 unsigned char eh, *s; 2887 unsigned char *s;
2888 unicode_t eh;
2889
2940 /* 2890 /*
2941 * Not handled yet 2891 * Not handled yet
2942 */ 2892 */
2943 s = get_to_st (&eh); 2893 s = get_to_st (eh);
2944 if (s) 2894 if (s)
2945 free (s); 2895 free (s);
2896
2946 return; 2897 return;
2947} 2898}
2948 2899
2949/*----------------------------------------------------------------------*/ 2900/*----------------------------------------------------------------------*/
2950/* 2901/*
2951 * process OPERATING SYSTEM COMMAND sequence `ESC ] Ps ; Pt (ST|BEL)' 2902 * process OPERATING SYSTEM COMMAND sequence `ESC ] Ps ; Pt (ST|BEL)'
2952 */ 2903 */
2953void 2904void
2954rxvt_term::process_osc_seq () 2905rxvt_term::process_osc_seq ()
2955{ 2906{
2956 unsigned char ch, eh, *s; 2907 unicode_t ch, eh;
2957 int arg; 2908 int arg;
2958 2909
2959 ch = cmd_getc (); 2910 ch = cmd_getc ();
2960 for (arg = 0; isdigit (ch); ch = cmd_getc ()) 2911 for (arg = 0; isdigit (ch); ch = cmd_getc ())
2961 arg = arg * 10 + (ch - '0'); 2912 arg = arg * 10 + (ch - '0');
2962 2913
2963 if (ch == ';') 2914 if (ch == ';')
2964 { 2915 {
2965 s = get_to_st (&eh); 2916 unsigned char *s = get_to_st (eh);
2917
2966 if (s) 2918 if (s)
2967 { 2919 {
2968 /* 2920 /*
2969 * rxvt_menubar_dispatch () violates the constness of the string, 2921 * rxvt_menubar_dispatch () violates the constness of the string,
2970 * so do it here 2922 * so do it here
2975#else 2927#else
2976 (void)0; 2928 (void)0;
2977#endif 2929#endif
2978 else 2930 else
2979 xterm_seq (arg, (char *)s, eh); 2931 xterm_seq (arg, (char *)s, eh);
2932
2980 free (s); 2933 free (s);
2981 } 2934 }
2982 } 2935 }
2983} 2936}
2984/* 2937/*
2994 * 19 = change underlined character color 2947 * 19 = change underlined character color
2995 * 46 = change logfile (not implemented) 2948 * 46 = change logfile (not implemented)
2996 * 50 = change font 2949 * 50 = change font
2997 * 2950 *
2998 * rxvt extensions: 2951 * rxvt extensions:
2999 * 9 = change locale (NYI)
3000 * 10 = menu (may change in future) 2952 * 10 = menu (may change in future)
3001 * 20 = bg pixmap 2953 * 20 = bg pixmap
3002 * 39 = change default fg color 2954 * 39 = change default fg color
3003 * 49 = change default bg color 2955 * 49 = change default bg color
3004 * 55 = dump scrollback buffer and all of screen 2956 * 55 = dump scrollback buffer and all of screen
2957 * 701 = change locale
2958 * 702 = find font
3005 */ 2959 */
3006void 2960void
3007rxvt_term::xterm_seq (int op, const char *str, unsigned char resp __attribute__ ((unused))) 2961rxvt_term::xterm_seq (int op, const char *str, unsigned char resp __attribute__ ((unused)))
3008{ 2962{
3009 int changed = 0; 2963 int changed = 0;
3010 int color; 2964 int color;
3011 char *buf, *name; 2965 char *buf, *name;
3012 2966
3013 assert (str != NULL); 2967 assert (str != NULL);
3014 switch (op) 2968 switch (op)
3015 { 2969 {
3016 case XTerm_name: 2970 case XTerm_name:
3017 set_title (str); 2971 set_title (str);
3018 /* FALLTHROUGH */ 2972 /* FALLTHROUGH */
3019 case XTerm_iconName: 2973 case XTerm_iconName:
3020 set_iconName (str); 2974 set_icon_name (str);
3021 break; 2975 break;
3022 case XTerm_title: 2976 case XTerm_title:
3023 set_title (str); 2977 set_title (str);
3024 break; 2978 break;
3025 case XTerm_Color: 2979 case XTerm_Color:
3026 for (buf = (char *)str; buf && *buf;) 2980 for (buf = (char *)str; buf && *buf;)
3027 { 2981 {
3028 if ((name = STRCHR (buf, ';')) == NULL) 2982 if ((name = STRCHR (buf, ';')) == NULL)
3029 break; 2983 break;
2984
3030 *name++ = '\0'; 2985 *name++ = '\0';
3031 color = atoi (buf); 2986 color = atoi (buf);
2987
3032 if (color < 0 || color >= TOTAL_COLORS) 2988 if (color < 0 || color >= TOTAL_COLORS)
3033 break; 2989 break;
2990
3034 if ((buf = STRCHR (name, ';')) != NULL) 2991 if ((buf = STRCHR (name, ';')) != NULL)
3035 *buf++ = '\0'; 2992 *buf++ = '\0';
2993
3036 set_window_color (color + minCOLOR, name); 2994 set_window_color (color + minCOLOR, name);
3037 } 2995 }
3038 break; 2996 break;
3039#ifndef NO_CURSORCOLOR 2997#ifndef NO_CURSORCOLOR
3040 case XTerm_Color_cursor: 2998 case XTerm_Color_cursor:
3093 break; 3051 break;
3094 case XTerm_restoreBG: 3052 case XTerm_restoreBG:
3095 set_window_color (Color_bg, str); 3053 set_window_color (Color_bg, str);
3096 break; 3054 break;
3097 case XTerm_logfile: 3055 case XTerm_logfile:
3056 // TODO, when secure mode?
3098 break; 3057 break;
3099 case XTerm_font: 3058 case XTerm_font:
3100 change_font (str); 3059 change_font (str);
3101 break; 3060 break;
3061#ifndef NO_FRILLS
3102 case XTerm_locale: 3062 case XTerm_locale:
3103 if (str[0] == '?' && !str[1]) 3063 if (str[0] == '?' && !str[1])
3104 tt_printf ("%-.250s\n", locale); 3064 tt_printf ("%-.250s\n", locale);
3105 else 3065 else
3106 { 3066 {
3107 set_locale (str); 3067 set_locale (str);
3068# ifdef USE_XIM
3108 im_cb (); 3069 im_cb ();
3109 3070# endif
3110 if (display->selection_owner == this)
3111 display->set_selection_owner (0);
3112 } 3071 }
3113 break; 3072 break;
3073 case XTerm_findfont:
3074 {
3075 int fid = TermWin.fontset->find_font (atoi (str));
3076 tt_printf ("%d %-.250s\n", fid, (*TermWin.fontset)[fid]->name);
3077 }
3078 break;
3079#endif
3114#if 0 3080#if 0
3115 case XTerm_dumpscreen: /* no error notices */ 3081 case XTerm_dumpscreen: /* no error notices */
3116 { 3082 {
3117 int fd; 3083 int fd;
3118 if ((fd = open (str, O_RDWR | O_CREAT | O_EXCL, 0600)) >= 0) 3084 if ((fd = open (str, O_RDWR | O_CREAT | O_EXCL, 0600)) >= 0)
3121 close (fd); 3087 close (fd);
3122 } 3088 }
3123 } 3089 }
3124 break; 3090 break;
3125#endif 3091#endif
3126
3127 } 3092 }
3128} 3093}
3129/*----------------------------------------------------------------------*/ 3094/*----------------------------------------------------------------------*/
3130 3095
3131/*{{{ process DEC private mode sequences `ESC [ ? Ps mode' */ 3096/*{{{ process DEC private mode sequences `ESC [ ? Ps mode' */
3139 * so no need for fancy checking 3104 * so no need for fancy checking
3140 */ 3105 */
3141int 3106int
3142rxvt_term::privcases (int mode, unsigned long bit) 3107rxvt_term::privcases (int mode, unsigned long bit)
3143{ 3108{
3144 int state; 3109 int state;
3145 3110
3146 if (mode == 's') 3111 if (mode == 's')
3147 { 3112 {
3148 SavedModes |= (PrivateModes & bit); 3113 SavedModes |= (PrivateModes & bit);
3149 return -1; 3114 return -1;
3154 state = (SavedModes & bit) ? 1 : 0; /* no overlapping */ 3119 state = (SavedModes & bit) ? 1 : 0; /* no overlapping */
3155 else 3120 else
3156 state = (mode == 't') ? ! (PrivateModes & bit) : mode; 3121 state = (mode == 't') ? ! (PrivateModes & bit) : mode;
3157 PrivMode (state, bit); 3122 PrivMode (state, bit);
3158 } 3123 }
3124
3159 return state; 3125 return state;
3160} 3126}
3161 3127
3162/* we're not using priv _yet_ */ 3128/* we're not using priv _yet_ */
3163void 3129void
3164rxvt_term::process_terminal_mode (int mode, int priv __attribute__ ((unused)), unsigned int nargs, const int *arg) 3130rxvt_term::process_terminal_mode (int mode, int priv __attribute__ ((unused)), unsigned int nargs, const int *arg)
3165{ 3131{
3166 unsigned int i, j; 3132 unsigned int i, j;
3167 int state; 3133 int state;
3134
3168 static const struct 3135 static const struct
3169 { 3136 {
3170 const int argval; 3137 const int argval;
3171 const unsigned long bit; 3138 const unsigned long bit;
3172 } 3139 }
3140
3173 argtopriv[] = { 3141 argtopriv[] = {
3174 { 1, PrivMode_aplCUR }, 3142 { 1, PrivMode_aplCUR },
3175 { 2, PrivMode_vt52 }, 3143 { 2, PrivMode_vt52 },
3176 { 3, PrivMode_132 }, 3144 { 3, PrivMode_132 },
3177 { 4, PrivMode_smoothScroll }, 3145 { 4, PrivMode_smoothScroll },
3183 { menuBar_esc, PrivMode_menuBar }, 3151 { menuBar_esc, PrivMode_menuBar },
3184#endif 3152#endif
3185#ifdef scrollBar_esc 3153#ifdef scrollBar_esc
3186 { scrollBar_esc, PrivMode_scrollBar }, 3154 { scrollBar_esc, PrivMode_scrollBar },
3187#endif 3155#endif
3156 // 18, 19 printing-related
3188 { 25, PrivMode_VisibleCursor }, 3157 { 25, PrivMode_VisibleCursor },
3158 // 30 show scrollbar rxvt. extension
3189 { 35, PrivMode_ShiftKeys }, 3159 { 35, PrivMode_ShiftKeys }, // rxvt extension
3190 { 40, PrivMode_132OK }, 3160 { 40, PrivMode_132OK },
3161 // 41 xterm more fixes NYI
3162 // 45 margin bell NYI
3163 // 46 start logging
3191 { 47, PrivMode_Screen }, 3164 { 47, PrivMode_Screen },
3192 { 66, PrivMode_aplKP }, 3165 { 66, PrivMode_aplKP },
3193#ifndef NO_BACKSPACE_KEY 3166#ifndef NO_BACKSPACE_KEY
3194 { 67, PrivMode_BackSpace }, 3167 { 67, PrivMode_BackSpace },
3195#endif 3168#endif
3196 { 1000, PrivMode_MouseX11 }, 3169 { 1000, PrivMode_MouseX11 },
3170 // 1001 Use Hilite Mouse Tracking. NYI, TODO
3171 // 1002 Use Cell Motion Mouse Tracking. NYI, TODO
3172 // 1003 Use All Motion Mouse Tracking. NYI, TODO
3197 { 1010, PrivMode_TtyOutputInh }, 3173 { 1010, PrivMode_TtyOutputInh }, // rxvt extension
3198 { 1011, PrivMode_Keypress }, 3174 { 1011, PrivMode_Keypress }, // rxvt extension
3175 // 1035 enable modifiers for alt, numlock NYI
3176 // 1036 send ESC for meta keys NYI
3177 // 1037 send DEL for keypad delete NYI
3199 { 1047, PrivMode_Screen }, 3178 { 1047, PrivMode_Screen },
3179 // 1048 save and restore cursor
3200 { 1049, PrivMode_Screen }, /* xterm extension, not fully implemented */ 3180 { 1049, PrivMode_Screen }, /* xterm extension, not fully implemented */
3181 // 1051, 1052, 1060, 1061 keyboard emulation NYI
3201 }; 3182 };
3202 3183
3203 if (nargs == 0) 3184 if (nargs == 0)
3204 return; 3185 return;
3205 3186
3220 state = privcases (mode, argtopriv[j].bit); 3201 state = privcases (mode, argtopriv[j].bit);
3221 break; 3202 break;
3222 } 3203 }
3223 3204
3224 /* extra handling for values with state unkept */ 3205 /* extra handling for values with state unkept */
3206 switch (arg[i])
3207 {
3208 case 1048: /* alternative cursor save */
3209 case 1049:
3210 if (mode == 0)
3211 scr_cursor (RESTORE);
3212 else if (mode == 1)
3213 scr_cursor (SAVE);
3214 /* FALLTHROUGH */
3215 }
3216
3225 if (state == -1) 3217 if (state >= 0)
3218 /* extra handling for values with valid 0 or 1 state */
3226 switch (arg[i]) 3219 switch (arg[i])
3227 { 3220 {
3228 case 1048: /* alternative cursor save */ 3221 /* case 1: - application cursor keys */
3222 case 2: /* VT52 mode */
3223 /* oddball mode. should be set regardless of set/reset
3224 * parameter. Return from VT52 mode with an ESC < from
3225 * within VT52 mode
3226 */
3227 PrivMode (1, PrivMode_vt52);
3228 break;
3229 case 3: /* 80/132 */
3230 if (PrivateModes & PrivMode_132OK)
3231 set_widthheight (((state ? 132 : 80) * TermWin.fwidth), TermWin.height);
3232 break;
3233 case 4: /* smooth scrolling */
3229 if (mode == 0) 3234 if (state)
3230 scr_cursor (RESTORE); 3235 Options &= ~Opt_jumpScroll;
3231 else if (mode == 1) 3236 else
3232 scr_cursor (SAVE); 3237 Options |= Opt_jumpScroll;
3238 break;
3239 case 5: /* reverse video */
3240 scr_rvideo_mode (state);
3241 break;
3242 case 6: /* relative/absolute origins */
3243 scr_relative_origin (state);
3244 break;
3245 case 7: /* autowrap */
3246 scr_autowrap (state);
3247 break;
3248 /* case 8: - auto repeat, can't do on a per window basis */
3249 case 9: /* X10 mouse reporting */
3250 if (state) /* orthogonal */
3251 PrivateModes &= ~PrivMode_MouseX11;
3252 break;
3253#ifdef menuBar_esc
3254 case menuBar_esc:
3255#ifdef MENUBAR
3256 map_menuBar (state);
3257#endif
3258 break;
3259#endif
3260#ifdef scrollBar_esc
3261 case scrollBar_esc:
3262 if (scrollbar_mapping (state))
3263 {
3264 resize_all_windows (0, 0, 0);
3265 scr_touch (true);
3266 }
3267 break;
3268#endif
3269 case 25: /* visible/invisible cursor */
3270 scr_cursor_visible (state);
3271 break;
3272 /* case 35: - shift keys */
3273 /* case 40: - 80 <--> 132 mode */
3274 case 47: /* secondary screen */
3275 scr_change_screen (state);
3276 break;
3277 /* case 66: - application key pad */
3278 /* case 67: - backspace key */
3279 case 1000: /* X11 mouse reporting */
3280 if (state) /* orthogonal */
3281 PrivateModes &= ~PrivMode_MouseX10;
3282 break;
3283#if 0
3284 case 1001:
3285 break; /* X11 mouse highlighting */
3286#endif
3287 case 1010: /* scroll to bottom on TTY output inhibit */
3288 if (state)
3289 Options &= ~Opt_scrollTtyOutput;
3290 else
3291 Options |= Opt_scrollTtyOutput;
3292 break;
3293 case 1011: /* scroll to bottom on key press */
3294 if (state)
3295 Options |= Opt_scrollTtyKeypress;
3296 else
3297 Options &= ~Opt_scrollTtyKeypress;
3298 break;
3299 case 1047: /* secondary screen w/ clearing */
3300 case 1049: /* better secondary screen w/ clearing, but not fully implemented */
3301 if (current_screen != PRIMARY)
3302 scr_erase_screen (2);
3303
3304 scr_change_screen (state);
3233 /* FALLTHROUGH */ 3305 /* FALLTHROUGH */
3234 default: 3306 default:
3235 continue; /* for (;i;) */ 3307 break;
3236 } 3308 }
3237
3238 /* extra handling for values with valid 0 or 1 state */
3239 switch (arg[i])
3240 {
3241 /* case 1: - application cursor keys */
3242 case 2: /* VT52 mode */
3243 /* oddball mode. should be set regardless of set/reset
3244 * parameter. Return from VT52 mode with an ESC < from
3245 * within VT52 mode
3246 */
3247 PrivMode (1, PrivMode_vt52);
3248 break;
3249 case 3: /* 80/132 */
3250 if (PrivateModes & PrivMode_132OK)
3251 set_widthheight ( (unsigned int) ((state ? 132 : 80) * TermWin.fwidth),
3252 (unsigned int)TermWin.height);
3253 break;
3254 case 4: /* smooth scrolling */
3255 if (state)
3256 Options &= ~Opt_jumpScroll;
3257 else
3258 Options |= Opt_jumpScroll;
3259 break;
3260 case 5: /* reverse video */
3261 scr_rvideo_mode (state);
3262 break;
3263 case 6: /* relative/absolute origins */
3264 scr_relative_origin (state);
3265 break;
3266 case 7: /* autowrap */
3267 scr_autowrap (state);
3268 break;
3269 /* case 8: - auto repeat, can't do on a per window basis */
3270 case 9: /* X10 mouse reporting */
3271 if (state) /* orthogonal */
3272 PrivateModes &= ~ (PrivMode_MouseX11);
3273 break;
3274#ifdef menuBar_esc
3275 case menuBar_esc:
3276#ifdef MENUBAR
3277 map_menuBar (state);
3278#endif
3279 break;
3280#endif
3281#ifdef scrollBar_esc
3282 case scrollBar_esc:
3283 if (scrollbar_mapping (state))
3284 {
3285 resize_all_windows (0, 0, 0);
3286 scr_touch (true);
3287 }
3288 break;
3289#endif
3290 case 25: /* visible/invisible cursor */
3291 scr_cursor_visible (state);
3292 break;
3293 /* case 35: - shift keys */
3294 /* case 40: - 80 <--> 132 mode */
3295 case 47: /* secondary screen */
3296 scr_change_screen (state);
3297 break;
3298 /* case 66: - application key pad */
3299 /* case 67: - backspace key */
3300 case 1000: /* X11 mouse reporting */
3301 if (state) /* orthogonal */
3302 PrivateModes &= ~ (PrivMode_MouseX10);
3303 break;
3304#if 0
3305 case 1001:
3306 break; /* X11 mouse highlighting */
3307#endif
3308 case 1010: /* scroll to bottom on TTY output inhibit */
3309 if (state)
3310 Options &= ~Opt_scrollTtyOutput;
3311 else
3312 Options |= Opt_scrollTtyOutput;
3313 break;
3314 case 1011: /* scroll to bottom on key press */
3315 if (state)
3316 Options |= Opt_scrollTtyKeypress;
3317 else
3318 Options &= ~Opt_scrollTtyKeypress;
3319 break;
3320 case 1047: /* secondary screen w/ clearing */
3321 case 1049: /* better secondary screen w/ clearing, but not fully implemented */
3322 if (current_screen != PRIMARY)
3323 scr_erase_screen (2);
3324 scr_change_screen (state);
3325 /* FALLTHROUGH */
3326 default:
3327 break;
3328 }
3329 } 3309 }
3330} 3310}
3331/*}}} */ 3311/*}}} */
3332 3312
3333/*{{{ process sgr sequences */ 3313/*{{{ process sgr sequences */
3334void 3314void
3335rxvt_term::process_sgr_mode (unsigned int nargs, const int *arg) 3315rxvt_term::process_sgr_mode (unsigned int nargs, const int *arg)
3336{ 3316{
3337 unsigned int i; 3317 unsigned int i;
3338 short rendset; 3318 short rendset;
3339 int rendstyle; 3319 int rendstyle;
3340 3320
3341 if (nargs == 0) 3321 if (nargs == 0)
3342 { 3322 {
3343 scr_rendition (0, ~RS_None); 3323 scr_rendition (0, ~RS_None);
3344 return; 3324 return;
3345 } 3325 }
3326
3346 for (i = 0; i < nargs; i++) 3327 for (i = 0; i < nargs; i++)
3347 { 3328 {
3348 rendset = -1; 3329 rendset = -1;
3349 switch (arg[i]) 3330 switch (arg[i])
3350 { 3331 {
3361 rendset = 1, rendstyle = RS_Blink; 3342 rendset = 1, rendstyle = RS_Blink;
3362 break; 3343 break;
3363 case 7: 3344 case 7:
3364 rendset = 1, rendstyle = RS_RVid; 3345 rendset = 1, rendstyle = RS_RVid;
3365 break; 3346 break;
3347 case 8:
3348 // invisible. NYI
3349 break;
3366 case 22: 3350 case 22:
3367 rendset = 0, rendstyle = RS_Bold; 3351 rendset = 0, rendstyle = RS_Bold;
3368 break; 3352 break;
3369 case 24: 3353 case 24:
3370 rendset = 0, rendstyle = RS_Uline; 3354 rendset = 0, rendstyle = RS_Uline;
3373 rendset = 0, rendstyle = RS_Blink; 3357 rendset = 0, rendstyle = RS_Blink;
3374 break; 3358 break;
3375 case 27: 3359 case 27:
3376 rendset = 0, rendstyle = RS_RVid; 3360 rendset = 0, rendstyle = RS_RVid;
3377 break; 3361 break;
3362 case 28:
3363 // visible. NYI
3364 break;
3378 } 3365 }
3366
3379 if (rendset != -1) 3367 if (rendset != -1)
3380 { 3368 {
3381 scr_rendition (rendset, rendstyle); 3369 scr_rendition (rendset, rendstyle);
3382 continue; /* for (;i;) */ 3370 continue; /* for (;i;) */
3383 } 3371 }
3390 case 33: 3378 case 33:
3391 case 34: 3379 case 34:
3392 case 35: 3380 case 35:
3393 case 36: 3381 case 36:
3394 case 37: 3382 case 37:
3395 scr_color ((unsigned int) (minCOLOR + (arg[i] - 30)), 3383 scr_color ((unsigned int) (minCOLOR + (arg[i] - 30)), Color_fg);
3396 Color_fg);
3397 break; 3384 break;
3398#ifdef TTY_256COLOR 3385#ifdef TTY_256COLOR
3399 case 38: 3386 case 38:
3400 if (nargs > i + 2 && arg[i + 1] == 5) 3387 if (nargs > i + 2 && arg[i + 1] == 5)
3401 { 3388 {
3402 scr_color ((unsigned int) (minCOLOR + arg[i + 2]), 3389 scr_color ((unsigned int) (minCOLOR + arg[i + 2]), Color_fg);
3403 Color_fg);
3404 i += 2; 3390 i += 2;
3405 } 3391 }
3406 break; 3392 break;
3407#endif 3393#endif
3408 case 39: /* default fg */ 3394 case 39: /* default fg */
3415 case 43: 3401 case 43:
3416 case 44: 3402 case 44:
3417 case 45: 3403 case 45:
3418 case 46: 3404 case 46:
3419 case 47: 3405 case 47:
3420 scr_color ((unsigned int) (minCOLOR + (arg[i] - 40)), 3406 scr_color ((unsigned int) (minCOLOR + (arg[i] - 40)), Color_bg);
3421 Color_bg);
3422 break; 3407 break;
3423#ifdef TTY_256COLOR 3408#ifdef TTY_256COLOR
3424 case 48: 3409 case 48:
3425 if (nargs > i + 2 && arg[i + 1] == 5) 3410 if (nargs > i + 2 && arg[i + 1] == 5)
3426 { 3411 {
3427 scr_color ((unsigned int) (minCOLOR + arg[i + 2]), 3412 scr_color ((unsigned int) (minCOLOR + arg[i + 2]), Color_bg);
3428 Color_bg);
3429 i += 2; 3413 i += 2;
3430 } 3414 }
3431 break; 3415 break;
3432#endif 3416#endif
3433 case 49: /* default bg */ 3417 case 49: /* default bg */
3466 3450
3467/*{{{ process Rob Nation's own graphics mode sequences */ 3451/*{{{ process Rob Nation's own graphics mode sequences */
3468void 3452void
3469rxvt_term::process_graphics () 3453rxvt_term::process_graphics ()
3470{ 3454{
3471 unsigned char ch, cmd = cmd_getc (); 3455 unicode_t ch, cmd = cmd_getc ();
3472 3456
3473 if (cmd == 'Q') 3457 if (cmd == 'Q')
3474 { /* query graphics */ 3458 { /* query graphics */
3475 tt_printf ("\033G0\n"); /* no graphics */ 3459 tt_printf ("\033G0\n"); /* no graphics */
3476 return; 3460 return;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines