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.64 by pcg, Wed Mar 3 04:07:52 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
545 break; 535 break;
546 } 536 }
547 if (newlen) 537 if (newlen)
548 len = STRLEN (kbuf); 538 len = STRLEN (kbuf);
549 } 539 }
540
550 /* 541 /*
551 * Pass meta for all function keys, if 'meta' option set 542 * Pass meta for all function keys, if 'meta' option set
552 */ 543 */
553#ifdef META8_OPTION 544#ifdef META8_OPTION
554 if (meta && (meta_char == 0x80) && len > 0) 545 if (meta && (meta_char == 0x80) && len > 0)
569 { 560 {
570 unsigned char *ch; 561 unsigned char *ch;
571 562
572 for (ch = kbuf; ch < kbuf + len; ch++) 563 for (ch = kbuf; ch < kbuf + len; ch++)
573 *ch |= 0x80; 564 *ch |= 0x80;
565
574 meta = 0; 566 meta = 0;
575 } 567 }
576#endif 568#endif
577 /* nil */ ; 569 /* nil */ ;
578 } 570 }
631/*{{{ rxvt_cmd_write (), rxvt_cmd_getc () */ 623/*{{{ rxvt_cmd_write (), rxvt_cmd_getc () */
632/* attempt to `write' count to the input buffer */ 624/* attempt to `write' count to the input buffer */
633unsigned int 625unsigned int
634rxvt_term::cmd_write (const unsigned char *str, unsigned int count) 626rxvt_term::cmd_write (const unsigned char *str, unsigned int count)
635{ 627{
636 unsigned int n, s; 628 unsigned int n, s;
637 629
638 n = cmdbuf_ptr - cmdbuf_base; 630 n = cmdbuf_ptr - cmdbuf_base;
639 s = cmdbuf_base + BUFSIZ - 1 - cmdbuf_endp; 631 s = cmdbuf_base + CBUFSIZ - 1 - cmdbuf_endp;
640 632
641 if (n > 0 && s < count) 633 if (n > 0 && s < count)
642 { 634 {
643 MEMMOVE (cmdbuf_base, cmdbuf_ptr, 635 MEMMOVE (cmdbuf_base, cmdbuf_ptr,
644 (unsigned int) (cmdbuf_endp - cmdbuf_ptr)); 636 (unsigned int) (cmdbuf_endp - cmdbuf_ptr));
647 s += n; 639 s += n;
648 } 640 }
649 641
650 if (count > s) 642 if (count > s)
651 { 643 {
652 rxvt_print_error ("data loss: cmd_write too large"); 644 rxvt_warn ("data loss: cmd_write too large, continuing.\n");
653 count = s; 645 count = s;
654 } 646 }
655 647
656 for (; count--;) 648 for (; count--;)
657 *cmdbuf_endp++ = *str++; 649 *cmdbuf_endp++ = *str++;
728 720
729 memmove (cmdbuf_base, cmdbuf_ptr, n); 721 memmove (cmdbuf_base, cmdbuf_ptr, n);
730 cmdbuf_ptr = cmdbuf_base; 722 cmdbuf_ptr = cmdbuf_base;
731 cmdbuf_endp = cmdbuf_ptr + n; 723 cmdbuf_endp = cmdbuf_ptr + n;
732 724
733 n = read (cmd_fd, cmdbuf_endp, BUFSIZ - n); 725 n = read (cmd_fd, cmdbuf_endp, CBUFSIZ - n);
734 726
735 if (n > 0) 727 if (n > 0)
736 { 728 {
737 cmdbuf_endp += n; 729 cmdbuf_endp += n;
738 return true; 730 return true;
751 743
752 if (revents & EVENT_WRITE) 744 if (revents & EVENT_WRITE)
753 tt_write (0, 0); 745 tt_write (0, 0);
754 else if (revents & EVENT_READ) 746 else if (revents & EVENT_READ)
755 { 747 {
756 bool flag = true;
757
758 // loop, but don't allow a single term to monopolize us 748 // loop, but don't allow a single term to monopolize us
759 // the number of loops is fully arbitrary, and thus wrong 749 // the number of loops is fully arbitrary, and thus wrong
760 while (flag && pty_fill ()) 750 while (pty_fill ())
761 { 751 {
762 if (!seen_input) 752 if (!seen_input)
763 { 753 {
764 seen_input = 1; 754 seen_input = 1;
765 /* 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.
766 tt_winch (); 757 tt_winch ();
767 } 758 }
768 759
769 if (cmd_parse ()) 760 if (cmd_parse ())
770 break; 761 break;
771 } 762 }
772 }
773}
774
775bool
776rxvt_term::cmd_parse ()
777{
778 bool flag = false;
779 uint32_t ch = NOCHAR;
780
781 for (;;)
782 {
783 if (ch == NOCHAR)
784 ch = next_char ();
785
786 if (ch == NOCHAR) // TODO: improve
787 break;
788
789 if (ch >= ' ' || ch == '\t' || ch == '\n' || ch == '\r')
790 {
791 /* Read a text string from the input buffer */
792 uint32_t buf[BUFSIZ];
793 bool refreshnow = false;
794 int nlines = 0;
795 uint32_t *str = buf;
796
797 *str++ = ch;
798
799 for (;;)
800 {
801 ch = next_char ();
802
803 if (ch == NOCHAR || (ch < ' ' && ch != '\t' && ch != '\n' && ch != '\r'))
804 break;
805 else
806 {
807 *str++ = ch;
808
809 if (ch == '\n')
810 {
811 nlines++;
812 refresh_count++;
813
814 if (! (Options & Opt_jumpScroll)
815 || (refresh_count >= (refresh_limit * (TermWin.nrow - 1))))
816 {
817 refreshnow = true;
818 flag = false;
819 ch = NOCHAR;
820 break;
821 }
822
823 // scr_add_lines only works for nlines < TermWin.nrow - 1.
824 if (nlines >= TermWin.nrow - 1)
825 {
826 scr_add_lines (buf, nlines, str - buf);
827 nlines = 0;
828 str = buf;
829 }
830 }
831
832 if (str >= buf + BUFSIZ)
833 {
834 ch = NOCHAR;
835 break;
836 }
837 }
838 }
839
840 scr_add_lines (buf, nlines, str - buf);
841
842 /*
843 * If there have been a lot of new lines, then update the screen
844 * What the heck I'll cheat and only refresh less than every page-full.
845 * the number of pages between refreshes is refresh_limit, which
846 * is incremented here because we must be doing flat-out scrolling.
847 *
848 * refreshing should be correct for small scrolls, because of the
849 * time-out
850 */
851 if (refreshnow)
852 {
853 if ((Options & Opt_jumpScroll) && refresh_limit < REFRESH_PERIOD)
854 refresh_limit++;
855
856 scr_refresh (refresh_type);
857 }
858
859 }
860 else
861 {
862 switch (ch)
863 {
864 default:
865 process_nonprinting (ch);
866 break;
867 case C0_ESC: /* escape char */
868 process_escape_seq ();
869 break;
870 /*case 0x9b: */ /* CSI */
871 /* process_csi_seq (); */
872 }
873
874 ch = NOCHAR;
875 }
876 }
877
878 return flag;
879}
880
881// read the next character, currently handles UTF-8
882// will probably handle all sorts of other stuff in the future
883uint32_t
884rxvt_term::next_char ()
885{
886 while (cmdbuf_ptr < cmdbuf_endp)
887 {
888 // assume 0x20 .. 0x7f to be ascii ALWAYS (all shift-states etc.) uh-oh
889 if ((*cmdbuf_ptr <= 0x7f && 0x20 <= *cmdbuf_ptr)
890 || !*cmdbuf_ptr)
891 return *cmdbuf_ptr++;
892
893 wchar_t wc;
894 size_t len = mbrtowc (&wc, (char *)cmdbuf_ptr, cmdbuf_endp - cmdbuf_ptr, mbstate);
895
896 if (len == (size_t)-2)
897 {
898 // the mbstate stores incomplete sequences. didn't know this :/
899 cmdbuf_ptr = cmdbuf_endp;
900 break;
901 }
902
903 if (len == (size_t)-1)
904 return *cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through
905
906 // assume wchar == unicode
907 cmdbuf_ptr += len;
908 return wc;
909 }
910
911 return NOCHAR;
912}
913
914/* rxvt_cmd_getc () - Return next input character */
915/*
916 * Return the next input character after first passing any keyboard input
917 * to the command.
918 */
919uint32_t
920rxvt_term::cmd_getc ()
921{
922 for (;;)
923 {
924 uint32_t c = next_char ();
925 if (c != NOCHAR)
926 return c;
927
928 // incomplete sequences should occur rarely, still, a better solution
929 // would be preferred. either setjmp/longjmp or better design.
930 fcntl (cmd_fd, F_SETFL, 0);
931 pty_fill ();
932 fcntl (cmd_fd, F_SETFL, O_NONBLOCK);
933 } 763 }
934} 764}
935 765
936#ifdef POINTER_BLANK 766#ifdef POINTER_BLANK
937void 767void
1306 1136
1307 } 1137 }
1308 break; 1138 break;
1309 1139
1310 case SelectionClear: 1140 case SelectionClear:
1311 display->set_selection_owner (0); 1141 selection_clear ();
1312 break; 1142 break;
1313 1143
1314 case SelectionNotify: 1144 case SelectionNotify:
1315 if (selection_wait == Sel_normal) 1145 if (selection_wait == Sel_normal)
1316 selection_paste (ev.xselection.requestor, 1146 selection_paste (ev.xselection.requestor,
1934 if (have_pixmap) 1764 if (have_pixmap)
1935 { 1765 {
1936 /* 1766 /*
1937 * Copy display->root pixmap transparency 1767 * Copy display->root pixmap transparency
1938 */ 1768 */
1939 int sx, sy, nx, ny; 1769 int sx, sy, nx, ny;
1940 unsigned int nw, nh; 1770 unsigned int nw, nh;
1941 Window cr; 1771 Window cr;
1942 XImage *image; 1772 XImage *image;
1943 GC gc; 1773 GC gc;
1944 XGCValues gcvalue; 1774 XGCValues gcvalue;
1945 1775
1946 XTranslateCoordinates (display->display, TermWin.parent[0], display->root, 1776 XTranslateCoordinates (display->display, TermWin.parent[0], display->root,
1947 0, 0, &sx, &sy, &cr); 1777 0, 0, &sx, &sy, &cr);
1948 nw = (unsigned int)szHint.width; 1778 nw = (unsigned int)szHint.width;
1949 nh = (unsigned int)szHint.height; 1779 nh = (unsigned int)szHint.height;
1950 nx = ny = 0; 1780 nx = ny = 0;
1781
1951 if (sx < 0) 1782 if (sx < 0)
1952 { 1783 {
1953 nw += sx; 1784 nw += sx;
1954 nx = -sx; 1785 nx = -sx;
1955 sx = 0; 1786 sx = 0;
1956 } 1787 }
1788
1957 if (sy < 0) 1789 if (sy < 0)
1958 { 1790 {
1959 nh += sy; 1791 nh += sy;
1960 ny = -sy; 1792 ny = -sy;
1961 sy = 0; 1793 sy = 0;
1962 } 1794 }
1795
1963 MIN_IT (nw, (unsigned int) (wrootattr.width - sx)); 1796 MIN_IT (nw, (unsigned int) (wrootattr.width - sx));
1964 MIN_IT (nh, (unsigned int) (wrootattr.height - sy)); 1797 MIN_IT (nh, (unsigned int) (wrootattr.height - sy));
1965 allowedxerror = -1; 1798 allowedxerror = -1;
1966 image = XGetImage (display->display, rootpixmap, sx, sy, nw, nh, AllPlanes, 1799 image = XGetImage (display->display, rootpixmap, sx, sy, nw, nh, AllPlanes,
1967 ZPixmap); 1800 ZPixmap);
2000 if (!am_transparent || !am_pixmap_trans) 1833 if (!am_transparent || !am_pixmap_trans)
2001 pchanged = 1; 1834 pchanged = 1;
2002 am_transparent = am_pixmap_trans = 1; 1835 am_transparent = am_pixmap_trans = 1;
2003 } 1836 }
2004 } 1837 }
1838
2005 if (!am_pixmap_trans) 1839 if (!am_pixmap_trans)
2006 { 1840 {
2007 unsigned int n; 1841 unsigned int n;
2008 /* 1842 /*
2009 * InheritPixmap transparency 1843 * InheritPixmap transparency
2024 break; 1858 break;
2025 } 1859 }
2026 if (oldp != TermWin.parent[i]) 1860 if (oldp != TermWin.parent[i])
2027 pchanged = 1; 1861 pchanged = 1;
2028 } 1862 }
1863
2029 n = 0; 1864 n = 0;
1865
2030 if (pchanged) 1866 if (pchanged)
2031 { 1867 {
2032 for (; n < (unsigned int)i; n++) 1868 for (; n < (unsigned int)i; n++)
2033 { 1869 {
2034 XGetWindowAttributes (display->display, TermWin.parent[n], &wattr); 1870 XGetWindowAttributes (display->display, TermWin.parent[n], &wattr);
2038 n = (int) (sizeof (TermWin.parent) / sizeof (Window)) + 1; 1874 n = (int) (sizeof (TermWin.parent) / sizeof (Window)) + 1;
2039 break; 1875 break;
2040 } 1876 }
2041 } 1877 }
2042 } 1878 }
1879
2043 if (n > (int) (sizeof (TermWin.parent) 1880 if (n > (int) (sizeof (TermWin.parent)
2044 / sizeof (TermWin.parent[0]))) 1881 / sizeof (TermWin.parent[0])))
2045 { 1882 {
2046 D_X ((stderr, "InheritPixmap Turning off")); 1883 D_X ((stderr, "InheritPixmap Turning off"));
2047 XSetWindowBackground (display->display, TermWin.parent[0], 1884 XSetWindowBackground (display->display, TermWin.parent[0],
2070 ParentRelative); 1907 ParentRelative);
2071 XSetWindowBackgroundPixmap (display->display, TermWin.vt, 1908 XSetWindowBackgroundPixmap (display->display, TermWin.vt,
2072 ParentRelative); 1909 ParentRelative);
2073 am_transparent = 1; 1910 am_transparent = 1;
2074 } 1911 }
1912
2075 for (; i < (int) (sizeof (TermWin.parent) / sizeof (Window)); i++) 1913 for (; i < (int) (sizeof (TermWin.parent) / sizeof (Window)); i++)
2076 TermWin.parent[i] = None; 1914 TermWin.parent[i] = None;
2077 } 1915 }
2078 return pchanged; 1916 return pchanged;
2079} 1917}
2080#endif 1918#endif
2081 1919
2082/*}}} */ 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}
2083 2076
2084/*{{{ print pipe */ 2077/*{{{ print pipe */
2085/*----------------------------------------------------------------------*/ 2078/*----------------------------------------------------------------------*/
2086#ifdef PRINTPIPE 2079#ifdef PRINTPIPE
2087FILE * 2080FILE *
2088rxvt_term::popen_printer () 2081rxvt_term::popen_printer ()
2089{ 2082{
2090 FILE *stream = popen (rs[Rs_print_pipe], "w"); 2083 FILE *stream = popen (rs[Rs_print_pipe], "w");
2091 2084
2092 if (stream == NULL) 2085 if (stream == NULL)
2093 rxvt_print_error ("can't open printer pipe"); 2086 rxvt_warn ("can't open printer pipe, not printing.\n");
2087
2094 return stream; 2088 return stream;
2095} 2089}
2096 2090
2097int 2091int
2098rxvt_term::pclose_printer (FILE *stream) 2092rxvt_term::pclose_printer (FILE *stream)
2099{ 2093{
2100 fflush (stream); 2094 fflush (stream);
2101 /* pclose () reported not to work on SunOS 4.1.3 */
2102# if defined (__sun__) /* TODO: RESOLVE THIS */
2103 /* pclose works provided SIGCHLD handler uses waitpid */
2104 return pclose (stream); /* return fclose (stream); */
2105# else
2106 return pclose (stream); 2095 return pclose (stream);
2107# endif
2108} 2096}
2109 2097
2110/* 2098/*
2111 * simulate attached vt100 printer 2099 * simulate attached vt100 printer
2112 */ 2100 */
2113void 2101void
2114rxvt_term::process_print_pipe () 2102rxvt_term::process_print_pipe ()
2115{ 2103{
2116 int done; 2104 int done;
2117 FILE *fd; 2105 FILE *fd;
2118 2106
2119 if ((fd = popen_printer ()) == NULL) 2107 if ((fd = popen_printer ()) == NULL)
2120 return; 2108 return;
2121 2109
2122 /* 2110 /*
2123 * 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
2124 * is received. 2112 * is received.
2125 */ 2113 */
2126 for (done = 0; !done;) 2114 for (done = 0; !done;)
2127 { 2115 {
2128 unsigned char buf[8]; 2116 unsigned char buf[8];
2129 unsigned char ch; 2117 unicode_t ch;
2130 unsigned int i, len; 2118 unsigned int i, len;
2131 2119
2132 if ((ch = cmd_getc ()) != C0_ESC) 2120 if ((ch = cmd_getc ()) != C0_ESC)
2133 { 2121 {
2134 if (putc (ch, fd) == EOF) 2122 if (putc (ch, fd) == EOF)
2135 break; /* done = 1 */ 2123 break; /* done = 1 */
2150 { 2138 {
2151 if ((buf[len++] = cmd_getc ()) == 'i') 2139 if ((buf[len++] = cmd_getc ()) == 'i')
2152 break; /* done = 1 */ 2140 break; /* done = 1 */
2153 } 2141 }
2154 } 2142 }
2143
2155 for (i = 0; i < len; i++) 2144 for (i = 0; i < len; i++)
2156 if (putc (buf[i], fd) == EOF) 2145 if (putc (buf[i], fd) == EOF)
2157 { 2146 {
2158 done = 1; 2147 done = 1;
2159 break; 2148 break;
2160 } 2149 }
2161 } 2150 }
2162 } 2151 }
2152
2163 pclose_printer (fd); 2153 pclose_printer (fd);
2164} 2154}
2165#endif /* PRINTPIPE */ 2155#endif /* PRINTPIPE */
2166/*}}} */ 2156/*}}} */
2167 2157
2175}; 2165};
2176/* *INDENT-ON* */ 2166/* *INDENT-ON* */
2177 2167
2178/*{{{ process non-printing single characters */ 2168/*{{{ process non-printing single characters */
2179void 2169void
2180rxvt_term::process_nonprinting (unsigned char ch) 2170rxvt_term::process_nonprinting (unicode_t ch)
2181{ 2171{
2182 switch (ch) 2172 switch (ch)
2183 { 2173 {
2174 case C0_ESC:
2175 process_escape_seq ();
2176 break;
2184 case C0_ENQ: /* terminal Status */ 2177 case C0_ENQ: /* terminal Status */
2185 if (rs[Rs_answerbackstring]) 2178 if (rs[Rs_answerbackstring])
2186 tt_write ( 2179 tt_write (
2187 (const unsigned char *)rs[Rs_answerbackstring], 2180 (const unsigned char *)rs[Rs_answerbackstring],
2188 (unsigned int)STRLEN (rs[Rs_answerbackstring])); 2181 (unsigned int)STRLEN (rs[Rs_answerbackstring]));
2211 scr_charset_choose (1); 2204 scr_charset_choose (1);
2212 break; 2205 break;
2213 case C0_SI: /* shift in - acs */ 2206 case C0_SI: /* shift in - acs */
2214 scr_charset_choose (0); 2207 scr_charset_choose (0);
2215 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;
2216 } 2220 }
2217} 2221}
2218/*}}} */ 2222/*}}} */
2219 2223
2220 2224
2221/*{{{ process VT52 escape sequences */ 2225/*{{{ process VT52 escape sequences */
2222void 2226void
2223rxvt_term::process_escape_vt52 (unsigned char ch) 2227rxvt_term::process_escape_vt52 (unicode_t ch)
2224{ 2228{
2225 int row, col; 2229 int row, col;
2226 2230
2227 switch (ch) 2231 switch (ch)
2228 { 2232 {
2280 2284
2281/*{{{ process escape sequences */ 2285/*{{{ process escape sequences */
2282void 2286void
2283rxvt_term::process_escape_seq () 2287rxvt_term::process_escape_seq ()
2284{ 2288{
2285 unsigned char ch = cmd_getc (); 2289 unicode_t ch = cmd_getc ();
2286 2290
2287 if (PrivateModes & PrivMode_vt52) 2291 if (PrivateModes & PrivMode_vt52)
2288 { 2292 {
2289 process_escape_vt52 (ch); 2293 process_escape_vt52 (ch);
2290 return; 2294 return;
2338 break; 2342 break;
2339 2343
2340 /* 8.3.87: NEXT LINE */ 2344 /* 8.3.87: NEXT LINE */
2341 case C1_NEL: /* ESC E */ 2345 case C1_NEL: /* ESC E */
2342 { 2346 {
2343 uint32_t nlcr[] = { '\n', '\r' }; 2347 unicode_t nlcr[] = { L'\n', L'\r' };
2344 scr_add_lines (nlcr, 1, 2); 2348 scr_add_lines (nlcr, 1, 2);
2345 } 2349 }
2346 break; 2350 break;
2347 2351
2348 /* kidnapped escape sequence: Should be 8.3.48 */ 2352 /* kidnapped escape sequence: Should be 8.3.48 */
2440/* *INDENT-ON* */ 2444/* *INDENT-ON* */
2441 2445
2442void 2446void
2443rxvt_term::process_csi_seq () 2447rxvt_term::process_csi_seq ()
2444{ 2448{
2445 unsigned char ch, priv, i; 2449 unicode_t ch, priv, i;
2446 unsigned int nargs, p; 2450 unsigned int nargs, p;
2447 int n, ndef; 2451 int n, ndef;
2448 int arg[ESC_ARGS]; 2452 int arg[ESC_ARGS];
2449 2453
2450 for (nargs = ESC_ARGS; nargs > 0;) 2454 for (nargs = ESC_ARGS; nargs > 0;)
2451 arg[--nargs] = 0; 2455 arg[--nargs] = 0;
2452 2456
2453 priv = 0; 2457 priv = 0;
2455 if (ch >= '<' && ch <= '?') 2459 if (ch >= '<' && ch <= '?')
2456 { /* '<' '=' '>' '?' */ 2460 { /* '<' '=' '>' '?' */
2457 priv = ch; 2461 priv = ch;
2458 ch = cmd_getc (); 2462 ch = cmd_getc ();
2459 } 2463 }
2464
2460 /* read any numerical arguments */ 2465 /* read any numerical arguments */
2461 for (n = -1; ch < CSI_ICH; ) 2466 for (n = -1; ch < CSI_ICH; )
2462 { 2467 {
2463 if (isdigit (ch)) 2468 if (isdigit (ch))
2464 { 2469 {
2471 { 2476 {
2472 if (nargs < ESC_ARGS) 2477 if (nargs < ESC_ARGS)
2473 arg[nargs++] = n; 2478 arg[nargs++] = n;
2474 n = -1; 2479 n = -1;
2475 } 2480 }
2476 else if (ch == '\b') 2481 else if (IS_CONTROL (ch))
2477 {
2478 scr_backspace ();
2479 }
2480 else if (ch == C0_ESC)
2481 {
2482 process_escape_seq ();
2483 return;
2484 }
2485 else if (ch < ' ')
2486 {
2487 process_nonprinting (ch); 2482 process_nonprinting (ch);
2488 } 2483
2489 ch = cmd_getc (); 2484 ch = cmd_getc ();
2490 } 2485 }
2491 2486
2492 if (ch > CSI_7F) 2487 if (ch > CSI_7F)
2493 return; 2488 return;
2735#endif 2730#endif
2736 2731
2737 case CSI_78: /* DECREQTPARM */ 2732 case CSI_78: /* DECREQTPARM */
2738 if (arg[0] == 0 || arg[0] == 1) 2733 if (arg[0] == 0 || arg[0] == 1)
2739 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);
2740 /* FALLTHROUGH */ 2735 break;
2741 2736
2742 default: 2737 default:
2743 break; 2738 break;
2744 } 2739 }
2745} 2740}
2748#ifndef NO_FRILLS 2743#ifndef NO_FRILLS
2749/* ARGSUSED */ 2744/* ARGSUSED */
2750void 2745void
2751rxvt_term::process_window_ops (const int *args, unsigned int nargs) 2746rxvt_term::process_window_ops (const int *args, unsigned int nargs)
2752{ 2747{
2753 int x, y; 2748 int x, y;
2754#if 0
2755 char *s;
2756#endif
2757 XWindowAttributes wattr; 2749 XWindowAttributes wattr;
2758 Window wdummy; 2750 Window wdummy;
2759 2751
2760 if (nargs == 0) 2752 if (nargs == 0)
2761 return; 2753 return;
2754
2762 switch (args[0]) 2755 switch (args[0])
2763 { 2756 {
2764 /* 2757 /*
2765 * commands 2758 * commands
2766 */ 2759 */
2767 case 1: /* deiconify window */ 2760 case 1: /* deiconify window */
2768 XMapWindow (display->display, TermWin.parent[0]); 2761 XMapWindow (display->display, TermWin.parent[0]);
2769 break; 2762 break;
2770 case 2: /* iconify window */ 2763 case 2: /* iconify window */
2771 XIconifyWindow (display->display, TermWin.parent[0], 2764 XIconifyWindow (display->display, TermWin.parent[0],
2788 break; 2781 break;
2789 case 8: /* set size (chars) */ 2782 case 8: /* set size (chars) */
2790 set_widthheight ((unsigned int) (args[2] * TermWin.fwidth), 2783 set_widthheight ((unsigned int) (args[2] * TermWin.fwidth),
2791 (unsigned int) (args[1] * TermWin.fheight)); 2784 (unsigned int) (args[1] * TermWin.fheight));
2792 break; 2785 break;
2786
2787 //case 9: NYI, TODO, restore maximized window or maximize window
2793 default: 2788 default:
2794 if (args[0] >= 24) /* set height (chars) */ 2789 if (args[0] >= 24) /* set height (chars) */
2795 set_widthheight ((unsigned int)TermWin.width, 2790 set_widthheight ((unsigned int)TermWin.width,
2796 (unsigned int) (args[1] * TermWin.fheight)); 2791 (unsigned int) (args[1] * TermWin.fheight));
2797 break; 2792 break;
2793
2794
2798 /* 2795 /*
2799 * reports - some output format copied from XTerm 2796 * reports - some output format copied from XTerm
2800 */ 2797 */
2801 case 11: /* report window state */ 2798 case 11: /* report window state */
2802 XGetWindowAttributes (display->display, TermWin.parent[0], &wattr); 2799 XGetWindowAttributes (display->display, TermWin.parent[0], &wattr);
2803 tt_printf ("\033[%dt", wattr.map_state == IsViewable ? 1 : 2); 2800 tt_printf ("\033[%dt", wattr.map_state == IsViewable ? 1 : 2);
2804 break; 2801 break;
2805 case 13: /* report window position */ 2802 case 13: /* report window position */
2811 break; 2808 break;
2812 case 14: /* report window size (pixels) */ 2809 case 14: /* report window size (pixels) */
2813 XGetWindowAttributes (display->display, TermWin.parent[0], &wattr); 2810 XGetWindowAttributes (display->display, TermWin.parent[0], &wattr);
2814 tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width); 2811 tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width);
2815 break; 2812 break;
2816 case 18: /* report window size (chars) */ 2813 case 18: /* report text area size (chars) */
2817 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);
2818 break; 2818 break;
2819#if 0 /* XXX: currently disabled due to security concerns */ 2819#if 0 /* XXX: currently disabled due to security concerns */
2820 case 20: /* report icon label */ 2820 case 20: /* report icon label */
2821 XGetIconName (display->display, TermWin.parent[0], &s); 2821 XGetIconName (display->display, TermWin.parent[0], &s);
2822 tt_printf ("\033]L%-.200s\234", s ? s : ""); /* 8bit ST */ 2822 tt_printf ("\033]L%-.200s\234", s ? s : ""); /* 8bit ST */
2824 case 21: /* report window title */ 2824 case 21: /* report window title */
2825 XFetchName (display->display, TermWin.parent[0], &s); 2825 XFetchName (display->display, TermWin.parent[0], &s);
2826 tt_printf ("\033]l%-.200s\234", s ? s : ""); /* 8bit ST */ 2826 tt_printf ("\033]l%-.200s\234", s ? s : ""); /* 8bit ST */
2827 break; 2827 break;
2828#endif 2828#endif
2829
2830 } 2829 }
2831} 2830}
2832#endif 2831#endif
2833 2832
2834/*----------------------------------------------------------------------*/ 2833/*----------------------------------------------------------------------*/
2835/* 2834/*
2836 * get input up until STRING TERMINATOR (or BEL) 2835 * get input up until STRING TERMINATOR (or BEL)
2837 * ends_how is terminator used. returned input must be free ()d 2836 * ends_how is terminator used. returned input must be free ()d
2838 */ 2837 */
2839unsigned char * 2838unsigned char *
2840rxvt_term::get_to_st (unsigned char *ends_how) 2839rxvt_term::get_to_st (unicode_t &ends_how)
2841{ 2840{
2842 int seen_esc = 0; /* seen escape? */ 2841 int seen_esc = 0; /* seen escape? */
2843 unsigned int n = 0; 2842 unsigned int n = 0;
2844 unsigned char *s; 2843 unsigned char *s;
2844 unicode_t ch;
2845 unsigned char ch, string[STRING_MAX]; 2845 unsigned char string[STRING_MAX];
2846 2846
2847 for (; (ch = cmd_getc ());) 2847 while ((ch = cmd_getc ()))
2848 { 2848 {
2849 if (ch == C0_BEL 2849 if (ch == C0_BEL
2850 || ch == CHAR_ST 2850 || ch == CHAR_ST
2851 || (ch == 0x5c && seen_esc)) /* 7bit ST */ 2851 || (ch == 0x5c && seen_esc)) /* 7bit ST */
2852 break; 2852 break;
2853
2853 if (ch == C0_ESC) 2854 if (ch == C0_ESC)
2854 { 2855 {
2855 seen_esc = 1; 2856 seen_esc = 1;
2856 continue; 2857 continue;
2857 } 2858 }
2858 else if (ch == '\t') 2859 else if (ch == '\t')
2859 ch = ' '; /* translate '\t' to space */ 2860 ch = ' '; /* translate '\t' to space */
2860 else if (ch < 0x08 || (ch > 0x0d && ch < 0x20)) 2861 else if (ch < 0x08 || (ch > 0x0d && ch < 0x20))
2861 return NULL; /* other control character - exit */ 2862 return NULL; /* other control character - exit */
2863
2862 if (n < sizeof (string) - 1) 2864 if (n < sizeof (string) - 1)
2863 string[n++] = ch; 2865 string[n++] = ch;
2866
2864 seen_esc = 0; 2867 seen_esc = 0;
2865 } 2868 }
2869
2866 string[n++] = '\0'; 2870 string[n++] = '\0';
2871
2867 if ((s = (unsigned char *)rxvt_malloc (n)) == NULL) 2872 if ((s = (unsigned char *)rxvt_malloc (n)) == NULL)
2868 return NULL; 2873 return NULL;
2874
2869 *ends_how = (ch == 0x5c ? C0_ESC : ch); 2875 ends_how = (ch == 0x5c ? C0_ESC : ch);
2870 STRNCPY (s, string, n); 2876 STRNCPY (s, string, n);
2871 return s; 2877 return s;
2872} 2878}
2873 2879
2874/*----------------------------------------------------------------------*/ 2880/*----------------------------------------------------------------------*/
2876 * 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)'
2877 */ 2883 */
2878void 2884void
2879rxvt_term::process_dcs_seq () 2885rxvt_term::process_dcs_seq ()
2880{ 2886{
2881 unsigned char eh, *s; 2887 unsigned char *s;
2888 unicode_t eh;
2889
2882 /* 2890 /*
2883 * Not handled yet 2891 * Not handled yet
2884 */ 2892 */
2885 s = get_to_st (&eh); 2893 s = get_to_st (eh);
2886 if (s) 2894 if (s)
2887 free (s); 2895 free (s);
2896
2888 return; 2897 return;
2889} 2898}
2890 2899
2891/*----------------------------------------------------------------------*/ 2900/*----------------------------------------------------------------------*/
2892/* 2901/*
2893 * process OPERATING SYSTEM COMMAND sequence `ESC ] Ps ; Pt (ST|BEL)' 2902 * process OPERATING SYSTEM COMMAND sequence `ESC ] Ps ; Pt (ST|BEL)'
2894 */ 2903 */
2895void 2904void
2896rxvt_term::process_osc_seq () 2905rxvt_term::process_osc_seq ()
2897{ 2906{
2898 unsigned char ch, eh, *s; 2907 unicode_t ch, eh;
2899 int arg; 2908 int arg;
2900 2909
2901 ch = cmd_getc (); 2910 ch = cmd_getc ();
2902 for (arg = 0; isdigit (ch); ch = cmd_getc ()) 2911 for (arg = 0; isdigit (ch); ch = cmd_getc ())
2903 arg = arg * 10 + (ch - '0'); 2912 arg = arg * 10 + (ch - '0');
2904 2913
2905 if (ch == ';') 2914 if (ch == ';')
2906 { 2915 {
2907 s = get_to_st (&eh); 2916 unsigned char *s = get_to_st (eh);
2917
2908 if (s) 2918 if (s)
2909 { 2919 {
2910 /* 2920 /*
2911 * rxvt_menubar_dispatch () violates the constness of the string, 2921 * rxvt_menubar_dispatch () violates the constness of the string,
2912 * so do it here 2922 * so do it here
2917#else 2927#else
2918 (void)0; 2928 (void)0;
2919#endif 2929#endif
2920 else 2930 else
2921 xterm_seq (arg, (char *)s, eh); 2931 xterm_seq (arg, (char *)s, eh);
2932
2922 free (s); 2933 free (s);
2923 } 2934 }
2924 } 2935 }
2925} 2936}
2926/* 2937/*
2936 * 19 = change underlined character color 2947 * 19 = change underlined character color
2937 * 46 = change logfile (not implemented) 2948 * 46 = change logfile (not implemented)
2938 * 50 = change font 2949 * 50 = change font
2939 * 2950 *
2940 * rxvt extensions: 2951 * rxvt extensions:
2941 * 9 = change locale (NYI)
2942 * 10 = menu (may change in future) 2952 * 10 = menu (may change in future)
2943 * 20 = bg pixmap 2953 * 20 = bg pixmap
2944 * 39 = change default fg color 2954 * 39 = change default fg color
2945 * 49 = change default bg color 2955 * 49 = change default bg color
2946 * 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
2947 */ 2959 */
2948void 2960void
2949rxvt_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)))
2950{ 2962{
2951 int changed = 0; 2963 int changed = 0;
2952 int color; 2964 int color;
2953 char *buf, *name; 2965 char *buf, *name;
2954 2966
2955 assert (str != NULL); 2967 assert (str != NULL);
2956 switch (op) 2968 switch (op)
2957 { 2969 {
2958 case XTerm_name: 2970 case XTerm_name:
2959 set_title (str); 2971 set_title (str);
2960 /* FALLTHROUGH */ 2972 /* FALLTHROUGH */
2961 case XTerm_iconName: 2973 case XTerm_iconName:
2962 set_iconName (str); 2974 set_icon_name (str);
2963 break; 2975 break;
2964 case XTerm_title: 2976 case XTerm_title:
2965 set_title (str); 2977 set_title (str);
2966 break; 2978 break;
2967 case XTerm_Color: 2979 case XTerm_Color:
2968 for (buf = (char *)str; buf && *buf;) 2980 for (buf = (char *)str; buf && *buf;)
2969 { 2981 {
2970 if ((name = STRCHR (buf, ';')) == NULL) 2982 if ((name = STRCHR (buf, ';')) == NULL)
2971 break; 2983 break;
2984
2972 *name++ = '\0'; 2985 *name++ = '\0';
2973 color = atoi (buf); 2986 color = atoi (buf);
2987
2974 if (color < 0 || color >= TOTAL_COLORS) 2988 if (color < 0 || color >= TOTAL_COLORS)
2975 break; 2989 break;
2990
2976 if ((buf = STRCHR (name, ';')) != NULL) 2991 if ((buf = STRCHR (name, ';')) != NULL)
2977 *buf++ = '\0'; 2992 *buf++ = '\0';
2993
2978 set_window_color (color + minCOLOR, name); 2994 set_window_color (color + minCOLOR, name);
2979 } 2995 }
2980 break; 2996 break;
2981#ifndef NO_CURSORCOLOR 2997#ifndef NO_CURSORCOLOR
2982 case XTerm_Color_cursor: 2998 case XTerm_Color_cursor:
3035 break; 3051 break;
3036 case XTerm_restoreBG: 3052 case XTerm_restoreBG:
3037 set_window_color (Color_bg, str); 3053 set_window_color (Color_bg, str);
3038 break; 3054 break;
3039 case XTerm_logfile: 3055 case XTerm_logfile:
3056 // TODO, when secure mode?
3040 break; 3057 break;
3041 case XTerm_font: 3058 case XTerm_font:
3042 change_font (str); 3059 change_font (str);
3043 break; 3060 break;
3044#ifndef NO_FRILLS 3061#ifndef NO_FRILLS
3049 { 3066 {
3050 set_locale (str); 3067 set_locale (str);
3051# ifdef USE_XIM 3068# ifdef USE_XIM
3052 im_cb (); 3069 im_cb ();
3053# endif 3070# endif
3054 // TODO: call selection_make with the right values set
3055 // to re-fresh the selection.
3056 if (display->selection_owner == this)
3057 display->set_selection_owner (0);
3058 } 3071 }
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 }
3059 break; 3078 break;
3060#endif 3079#endif
3061#if 0 3080#if 0
3062 case XTerm_dumpscreen: /* no error notices */ 3081 case XTerm_dumpscreen: /* no error notices */
3063 { 3082 {
3068 close (fd); 3087 close (fd);
3069 } 3088 }
3070 } 3089 }
3071 break; 3090 break;
3072#endif 3091#endif
3073
3074 } 3092 }
3075} 3093}
3076/*----------------------------------------------------------------------*/ 3094/*----------------------------------------------------------------------*/
3077 3095
3078/*{{{ process DEC private mode sequences `ESC [ ? Ps mode' */ 3096/*{{{ process DEC private mode sequences `ESC [ ? Ps mode' */
3086 * so no need for fancy checking 3104 * so no need for fancy checking
3087 */ 3105 */
3088int 3106int
3089rxvt_term::privcases (int mode, unsigned long bit) 3107rxvt_term::privcases (int mode, unsigned long bit)
3090{ 3108{
3091 int state; 3109 int state;
3092 3110
3093 if (mode == 's') 3111 if (mode == 's')
3094 { 3112 {
3095 SavedModes |= (PrivateModes & bit); 3113 SavedModes |= (PrivateModes & bit);
3096 return -1; 3114 return -1;
3101 state = (SavedModes & bit) ? 1 : 0; /* no overlapping */ 3119 state = (SavedModes & bit) ? 1 : 0; /* no overlapping */
3102 else 3120 else
3103 state = (mode == 't') ? ! (PrivateModes & bit) : mode; 3121 state = (mode == 't') ? ! (PrivateModes & bit) : mode;
3104 PrivMode (state, bit); 3122 PrivMode (state, bit);
3105 } 3123 }
3124
3106 return state; 3125 return state;
3107} 3126}
3108 3127
3109/* we're not using priv _yet_ */ 3128/* we're not using priv _yet_ */
3110void 3129void
3111rxvt_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)
3112{ 3131{
3113 unsigned int i, j; 3132 unsigned int i, j;
3114 int state; 3133 int state;
3134
3115 static const struct 3135 static const struct
3116 { 3136 {
3117 const int argval; 3137 const int argval;
3118 const unsigned long bit; 3138 const unsigned long bit;
3119 } 3139 }
3140
3120 argtopriv[] = { 3141 argtopriv[] = {
3121 { 1, PrivMode_aplCUR }, 3142 { 1, PrivMode_aplCUR },
3122 { 2, PrivMode_vt52 }, 3143 { 2, PrivMode_vt52 },
3123 { 3, PrivMode_132 }, 3144 { 3, PrivMode_132 },
3124 { 4, PrivMode_smoothScroll }, 3145 { 4, PrivMode_smoothScroll },
3130 { menuBar_esc, PrivMode_menuBar }, 3151 { menuBar_esc, PrivMode_menuBar },
3131#endif 3152#endif
3132#ifdef scrollBar_esc 3153#ifdef scrollBar_esc
3133 { scrollBar_esc, PrivMode_scrollBar }, 3154 { scrollBar_esc, PrivMode_scrollBar },
3134#endif 3155#endif
3156 // 18, 19 printing-related
3135 { 25, PrivMode_VisibleCursor }, 3157 { 25, PrivMode_VisibleCursor },
3158 // 30 show scrollbar rxvt. extension
3136 { 35, PrivMode_ShiftKeys }, 3159 { 35, PrivMode_ShiftKeys }, // rxvt extension
3137 { 40, PrivMode_132OK }, 3160 { 40, PrivMode_132OK },
3161 // 41 xterm more fixes NYI
3162 // 45 margin bell NYI
3163 // 46 start logging
3138 { 47, PrivMode_Screen }, 3164 { 47, PrivMode_Screen },
3139 { 66, PrivMode_aplKP }, 3165 { 66, PrivMode_aplKP },
3140#ifndef NO_BACKSPACE_KEY 3166#ifndef NO_BACKSPACE_KEY
3141 { 67, PrivMode_BackSpace }, 3167 { 67, PrivMode_BackSpace },
3142#endif 3168#endif
3143 { 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
3144 { 1010, PrivMode_TtyOutputInh }, 3173 { 1010, PrivMode_TtyOutputInh }, // rxvt extension
3145 { 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
3146 { 1047, PrivMode_Screen }, 3178 { 1047, PrivMode_Screen },
3179 // 1048 save and restore cursor
3147 { 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
3148 }; 3182 };
3149 3183
3150 if (nargs == 0) 3184 if (nargs == 0)
3151 return; 3185 return;
3152 3186
3167 state = privcases (mode, argtopriv[j].bit); 3201 state = privcases (mode, argtopriv[j].bit);
3168 break; 3202 break;
3169 } 3203 }
3170 3204
3171 /* 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
3172 if (state == -1) 3217 if (state >= 0)
3218 /* extra handling for values with valid 0 or 1 state */
3173 switch (arg[i]) 3219 switch (arg[i])
3174 { 3220 {
3175 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 */
3176 if (mode == 0) 3234 if (state)
3177 scr_cursor (RESTORE); 3235 Options &= ~Opt_jumpScroll;
3178 else if (mode == 1) 3236 else
3179 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);
3180 /* FALLTHROUGH */ 3305 /* FALLTHROUGH */
3181 default: 3306 default:
3182 continue; /* for (;i;) */ 3307 break;
3183 } 3308 }
3184
3185 /* extra handling for values with valid 0 or 1 state */
3186 switch (arg[i])
3187 {
3188 /* case 1: - application cursor keys */
3189 case 2: /* VT52 mode */
3190 /* oddball mode. should be set regardless of set/reset
3191 * parameter. Return from VT52 mode with an ESC < from
3192 * within VT52 mode
3193 */
3194 PrivMode (1, PrivMode_vt52);
3195 break;
3196 case 3: /* 80/132 */
3197 if (PrivateModes & PrivMode_132OK)
3198 set_widthheight ( (unsigned int) ((state ? 132 : 80) * TermWin.fwidth),
3199 (unsigned int)TermWin.height);
3200 break;
3201 case 4: /* smooth scrolling */
3202 if (state)
3203 Options &= ~Opt_jumpScroll;
3204 else
3205 Options |= Opt_jumpScroll;
3206 break;
3207 case 5: /* reverse video */
3208 scr_rvideo_mode (state);
3209 break;
3210 case 6: /* relative/absolute origins */
3211 scr_relative_origin (state);
3212 break;
3213 case 7: /* autowrap */
3214 scr_autowrap (state);
3215 break;
3216 /* case 8: - auto repeat, can't do on a per window basis */
3217 case 9: /* X10 mouse reporting */
3218 if (state) /* orthogonal */
3219 PrivateModes &= ~ (PrivMode_MouseX11);
3220 break;
3221#ifdef menuBar_esc
3222 case menuBar_esc:
3223#ifdef MENUBAR
3224 map_menuBar (state);
3225#endif
3226 break;
3227#endif
3228#ifdef scrollBar_esc
3229 case scrollBar_esc:
3230 if (scrollbar_mapping (state))
3231 {
3232 resize_all_windows (0, 0, 0);
3233 scr_touch (true);
3234 }
3235 break;
3236#endif
3237 case 25: /* visible/invisible cursor */
3238 scr_cursor_visible (state);
3239 break;
3240 /* case 35: - shift keys */
3241 /* case 40: - 80 <--> 132 mode */
3242 case 47: /* secondary screen */
3243 scr_change_screen (state);
3244 break;
3245 /* case 66: - application key pad */
3246 /* case 67: - backspace key */
3247 case 1000: /* X11 mouse reporting */
3248 if (state) /* orthogonal */
3249 PrivateModes &= ~ (PrivMode_MouseX10);
3250 break;
3251#if 0
3252 case 1001:
3253 break; /* X11 mouse highlighting */
3254#endif
3255 case 1010: /* scroll to bottom on TTY output inhibit */
3256 if (state)
3257 Options &= ~Opt_scrollTtyOutput;
3258 else
3259 Options |= Opt_scrollTtyOutput;
3260 break;
3261 case 1011: /* scroll to bottom on key press */
3262 if (state)
3263 Options |= Opt_scrollTtyKeypress;
3264 else
3265 Options &= ~Opt_scrollTtyKeypress;
3266 break;
3267 case 1047: /* secondary screen w/ clearing */
3268 case 1049: /* better secondary screen w/ clearing, but not fully implemented */
3269 if (current_screen != PRIMARY)
3270 scr_erase_screen (2);
3271 scr_change_screen (state);
3272 /* FALLTHROUGH */
3273 default:
3274 break;
3275 }
3276 } 3309 }
3277} 3310}
3278/*}}} */ 3311/*}}} */
3279 3312
3280/*{{{ process sgr sequences */ 3313/*{{{ process sgr sequences */
3281void 3314void
3282rxvt_term::process_sgr_mode (unsigned int nargs, const int *arg) 3315rxvt_term::process_sgr_mode (unsigned int nargs, const int *arg)
3283{ 3316{
3284 unsigned int i; 3317 unsigned int i;
3285 short rendset; 3318 short rendset;
3286 int rendstyle; 3319 int rendstyle;
3287 3320
3288 if (nargs == 0) 3321 if (nargs == 0)
3289 { 3322 {
3290 scr_rendition (0, ~RS_None); 3323 scr_rendition (0, ~RS_None);
3291 return; 3324 return;
3292 } 3325 }
3326
3293 for (i = 0; i < nargs; i++) 3327 for (i = 0; i < nargs; i++)
3294 { 3328 {
3295 rendset = -1; 3329 rendset = -1;
3296 switch (arg[i]) 3330 switch (arg[i])
3297 { 3331 {
3308 rendset = 1, rendstyle = RS_Blink; 3342 rendset = 1, rendstyle = RS_Blink;
3309 break; 3343 break;
3310 case 7: 3344 case 7:
3311 rendset = 1, rendstyle = RS_RVid; 3345 rendset = 1, rendstyle = RS_RVid;
3312 break; 3346 break;
3347 case 8:
3348 // invisible. NYI
3349 break;
3313 case 22: 3350 case 22:
3314 rendset = 0, rendstyle = RS_Bold; 3351 rendset = 0, rendstyle = RS_Bold;
3315 break; 3352 break;
3316 case 24: 3353 case 24:
3317 rendset = 0, rendstyle = RS_Uline; 3354 rendset = 0, rendstyle = RS_Uline;
3320 rendset = 0, rendstyle = RS_Blink; 3357 rendset = 0, rendstyle = RS_Blink;
3321 break; 3358 break;
3322 case 27: 3359 case 27:
3323 rendset = 0, rendstyle = RS_RVid; 3360 rendset = 0, rendstyle = RS_RVid;
3324 break; 3361 break;
3362 case 28:
3363 // visible. NYI
3364 break;
3325 } 3365 }
3366
3326 if (rendset != -1) 3367 if (rendset != -1)
3327 { 3368 {
3328 scr_rendition (rendset, rendstyle); 3369 scr_rendition (rendset, rendstyle);
3329 continue; /* for (;i;) */ 3370 continue; /* for (;i;) */
3330 } 3371 }
3337 case 33: 3378 case 33:
3338 case 34: 3379 case 34:
3339 case 35: 3380 case 35:
3340 case 36: 3381 case 36:
3341 case 37: 3382 case 37:
3342 scr_color ((unsigned int) (minCOLOR + (arg[i] - 30)), 3383 scr_color ((unsigned int) (minCOLOR + (arg[i] - 30)), Color_fg);
3343 Color_fg);
3344 break; 3384 break;
3345#ifdef TTY_256COLOR 3385#ifdef TTY_256COLOR
3346 case 38: 3386 case 38:
3347 if (nargs > i + 2 && arg[i + 1] == 5) 3387 if (nargs > i + 2 && arg[i + 1] == 5)
3348 { 3388 {
3349 scr_color ((unsigned int) (minCOLOR + arg[i + 2]), 3389 scr_color ((unsigned int) (minCOLOR + arg[i + 2]), Color_fg);
3350 Color_fg);
3351 i += 2; 3390 i += 2;
3352 } 3391 }
3353 break; 3392 break;
3354#endif 3393#endif
3355 case 39: /* default fg */ 3394 case 39: /* default fg */
3362 case 43: 3401 case 43:
3363 case 44: 3402 case 44:
3364 case 45: 3403 case 45:
3365 case 46: 3404 case 46:
3366 case 47: 3405 case 47:
3367 scr_color ((unsigned int) (minCOLOR + (arg[i] - 40)), 3406 scr_color ((unsigned int) (minCOLOR + (arg[i] - 40)), Color_bg);
3368 Color_bg);
3369 break; 3407 break;
3370#ifdef TTY_256COLOR 3408#ifdef TTY_256COLOR
3371 case 48: 3409 case 48:
3372 if (nargs > i + 2 && arg[i + 1] == 5) 3410 if (nargs > i + 2 && arg[i + 1] == 5)
3373 { 3411 {
3374 scr_color ((unsigned int) (minCOLOR + arg[i + 2]), 3412 scr_color ((unsigned int) (minCOLOR + arg[i + 2]), Color_bg);
3375 Color_bg);
3376 i += 2; 3413 i += 2;
3377 } 3414 }
3378 break; 3415 break;
3379#endif 3416#endif
3380 case 49: /* default bg */ 3417 case 49: /* default bg */
3413 3450
3414/*{{{ process Rob Nation's own graphics mode sequences */ 3451/*{{{ process Rob Nation's own graphics mode sequences */
3415void 3452void
3416rxvt_term::process_graphics () 3453rxvt_term::process_graphics ()
3417{ 3454{
3418 unsigned char ch, cmd = cmd_getc (); 3455 unicode_t ch, cmd = cmd_getc ();
3419 3456
3420 if (cmd == 'Q') 3457 if (cmd == 'Q')
3421 { /* query graphics */ 3458 { /* query graphics */
3422 tt_printf ("\033G0\n"); /* no graphics */ 3459 tt_printf ("\033G0\n"); /* no graphics */
3423 return; 3460 return;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines