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.73 by pcg, Mon Mar 15 00:08:11 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
616/*{{{ rxvt_cmd_write (), rxvt_cmd_getc () */ 623/*{{{ rxvt_cmd_write (), rxvt_cmd_getc () */
617/* attempt to `write' count to the input buffer */ 624/* attempt to `write' count to the input buffer */
618unsigned int 625unsigned int
619rxvt_term::cmd_write (const unsigned char *str, unsigned int count) 626rxvt_term::cmd_write (const unsigned char *str, unsigned int count)
620{ 627{
621 unsigned int n, s; 628 unsigned int n, s;
622 629
623 n = cmdbuf_ptr - cmdbuf_base; 630 n = cmdbuf_ptr - cmdbuf_base;
624 s = cmdbuf_base + BUFSIZ - 1 - cmdbuf_endp; 631 s = cmdbuf_base + CBUFSIZ - 1 - cmdbuf_endp;
625 632
626 if (n > 0 && s < count) 633 if (n > 0 && s < count)
627 { 634 {
628 MEMMOVE (cmdbuf_base, cmdbuf_ptr, 635 MEMMOVE (cmdbuf_base, cmdbuf_ptr,
629 (unsigned int) (cmdbuf_endp - cmdbuf_ptr)); 636 (unsigned int) (cmdbuf_endp - cmdbuf_ptr));
632 s += n; 639 s += n;
633 } 640 }
634 641
635 if (count > s) 642 if (count > s)
636 { 643 {
637 rxvt_print_error ("data loss: cmd_write too large"); 644 rxvt_warn ("data loss: cmd_write too large, continuing.\n");
638 count = s; 645 count = s;
639 } 646 }
640 647
641 for (; count--;) 648 for (; count--;)
642 *cmdbuf_endp++ = *str++; 649 *cmdbuf_endp++ = *str++;
713 720
714 memmove (cmdbuf_base, cmdbuf_ptr, n); 721 memmove (cmdbuf_base, cmdbuf_ptr, n);
715 cmdbuf_ptr = cmdbuf_base; 722 cmdbuf_ptr = cmdbuf_base;
716 cmdbuf_endp = cmdbuf_ptr + n; 723 cmdbuf_endp = cmdbuf_ptr + n;
717 724
718 n = read (cmd_fd, cmdbuf_endp, BUFSIZ - n); 725 n = read (cmd_fd, cmdbuf_endp, CBUFSIZ - n);
719 726
720 if (n > 0) 727 if (n > 0)
721 { 728 {
722 cmdbuf_endp += n; 729 cmdbuf_endp += n;
723 return true; 730 return true;
736 743
737 if (revents & EVENT_WRITE) 744 if (revents & EVENT_WRITE)
738 tt_write (0, 0); 745 tt_write (0, 0);
739 else if (revents & EVENT_READ) 746 else if (revents & EVENT_READ)
740 { 747 {
741 bool flag = true;
742
743 // loop, but don't allow a single term to monopolize us 748 // loop, but don't allow a single term to monopolize us
744 // the number of loops is fully arbitrary, and thus wrong 749 // the number of loops is fully arbitrary, and thus wrong
745 while (flag && pty_fill ()) 750 while (pty_fill ())
746 { 751 {
747 if (!seen_input) 752 if (!seen_input)
748 { 753 {
749 seen_input = 1; 754 seen_input = 1;
750 /* 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.
751 tt_winch (); 757 tt_winch ();
752 } 758 }
753 759
754 if (cmd_parse ()) 760 if (cmd_parse ())
755 break; 761 break;
756 } 762 }
757 }
758}
759
760bool
761rxvt_term::cmd_parse ()
762{
763 bool flag = false;
764 unicode_t ch = NOCHAR;
765
766 for (;;)
767 {
768 if (ch == NOCHAR)
769 ch = next_char ();
770
771 if (ch == NOCHAR) // TODO: improve
772 break;
773
774 if (ch >= ' ' || ch == '\t' || ch == '\n' || ch == '\r')
775 {
776 /* Read a text string from the input buffer */
777 unicode_t buf[BUFSIZ];
778 bool refreshnow = false;
779 int nlines = 0;
780 unicode_t *str = buf;
781
782 *str++ = ch;
783
784 for (;;)
785 {
786 ch = next_char ();
787
788 if (ch == NOCHAR || (ch < ' ' && ch != '\t' && ch != '\n' && ch != '\r'))
789 break;
790 else
791 {
792 *str++ = ch;
793
794 if (ch == '\n')
795 {
796 nlines++;
797 refresh_count++;
798
799 if (! (Options & Opt_jumpScroll)
800 || (refresh_count >= (refresh_limit * (TermWin.nrow - 1))))
801 {
802 refreshnow = true;
803 flag = false;
804 ch = NOCHAR;
805 break;
806 }
807
808 // scr_add_lines only works for nlines < TermWin.nrow - 1.
809 if (nlines >= TermWin.nrow - 1)
810 {
811 scr_add_lines (buf, nlines, str - buf);
812 nlines = 0;
813 str = buf;
814 }
815 }
816
817 if (str >= buf + BUFSIZ)
818 {
819 ch = NOCHAR;
820 break;
821 }
822 }
823 }
824
825 scr_add_lines (buf, nlines, str - buf);
826
827 /*
828 * If there have been a lot of new lines, then update the screen
829 * What the heck I'll cheat and only refresh less than every page-full.
830 * the number of pages between refreshes is refresh_limit, which
831 * is incremented here because we must be doing flat-out scrolling.
832 *
833 * refreshing should be correct for small scrolls, because of the
834 * time-out
835 */
836 if (refreshnow)
837 {
838 if ((Options & Opt_jumpScroll) && refresh_limit < REFRESH_PERIOD)
839 refresh_limit++;
840
841 scr_refresh (refresh_type);
842 }
843
844 }
845 else
846 {
847 switch (ch)
848 {
849 default:
850 process_nonprinting (ch);
851 break;
852 case C0_ESC: /* escape char */
853 process_escape_seq ();
854 break;
855 /*case 0x9b: */ /* CSI */
856 /* process_csi_seq (); */
857 }
858
859 ch = NOCHAR;
860 }
861 }
862
863 return flag;
864}
865
866// read the next character, currently handles UTF-8
867// will probably handle all sorts of other stuff in the future
868unicode_t
869rxvt_term::next_char ()
870{
871 while (cmdbuf_ptr < cmdbuf_endp)
872 {
873 // assume 0x20 .. 0x7f to be ascii ALWAYS (all shift-states etc.) uh-oh
874 if ((*cmdbuf_ptr <= 0x7f && 0x20 <= *cmdbuf_ptr)
875 || !*cmdbuf_ptr)
876 return *cmdbuf_ptr++;
877
878 wchar_t wc;
879 size_t len = mbrtowc (&wc, (char *)cmdbuf_ptr, cmdbuf_endp - cmdbuf_ptr, mbstate);
880
881 if (len == (size_t)-2)
882 {
883 // the mbstate stores incomplete sequences. didn't know this :/
884 cmdbuf_ptr = cmdbuf_endp;
885 break;
886 }
887
888 if (len == (size_t)-1)
889 return *cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through
890
891 // assume wchar == unicode
892 cmdbuf_ptr += len;
893 return wc;
894 }
895
896 return NOCHAR;
897}
898
899/* rxvt_cmd_getc () - Return next input character */
900/*
901 * Return the next input character after first passing any keyboard input
902 * to the command.
903 */
904unicode_t
905rxvt_term::cmd_getc ()
906{
907 for (;;)
908 {
909 unicode_t c = next_char ();
910 if (c != NOCHAR)
911 return c;
912
913 // incomplete sequences should occur rarely, still, a better solution
914 // would be preferred. either setjmp/longjmp or better design.
915 fcntl (cmd_fd, F_SETFL, 0);
916 pty_fill ();
917 fcntl (cmd_fd, F_SETFL, O_NONBLOCK);
918 } 763 }
919} 764}
920 765
921#ifdef POINTER_BLANK 766#ifdef POINTER_BLANK
922void 767void
1291 1136
1292 } 1137 }
1293 break; 1138 break;
1294 1139
1295 case SelectionClear: 1140 case SelectionClear:
1296 display->set_selection_owner (0); 1141 selection_clear ();
1297 break; 1142 break;
1298 1143
1299 case SelectionNotify: 1144 case SelectionNotify:
1300 if (selection_wait == Sel_normal) 1145 if (selection_wait == Sel_normal)
1301 selection_paste (ev.xselection.requestor, 1146 selection_paste (ev.xselection.requestor,
2072} 1917}
2073#endif 1918#endif
2074 1919
2075/*}}} */ 1920/*}}} */
2076 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}
2076
2077/*{{{ print pipe */ 2077/*{{{ print pipe */
2078/*----------------------------------------------------------------------*/ 2078/*----------------------------------------------------------------------*/
2079#ifdef PRINTPIPE 2079#ifdef PRINTPIPE
2080FILE * 2080FILE *
2081rxvt_term::popen_printer () 2081rxvt_term::popen_printer ()
2082{ 2082{
2083 FILE *stream = popen (rs[Rs_print_pipe], "w"); 2083 FILE *stream = popen (rs[Rs_print_pipe], "w");
2084 2084
2085 if (stream == NULL) 2085 if (stream == NULL)
2086 rxvt_print_error ("can't open printer pipe"); 2086 rxvt_warn ("can't open printer pipe, not printing.\n");
2087
2087 return stream; 2088 return stream;
2088} 2089}
2089 2090
2090int 2091int
2091rxvt_term::pclose_printer (FILE *stream) 2092rxvt_term::pclose_printer (FILE *stream)
2092{ 2093{
2093 fflush (stream); 2094 fflush (stream);
2094 /* pclose () reported not to work on SunOS 4.1.3 */
2095# if defined (__sun__) /* TODO: RESOLVE THIS */
2096 /* pclose works provided SIGCHLD handler uses waitpid */
2097 return pclose (stream); /* return fclose (stream); */
2098# else
2099 return pclose (stream); 2095 return pclose (stream);
2100# endif
2101} 2096}
2102 2097
2103/* 2098/*
2104 * simulate attached vt100 printer 2099 * simulate attached vt100 printer
2105 */ 2100 */
2106void 2101void
2107rxvt_term::process_print_pipe () 2102rxvt_term::process_print_pipe ()
2108{ 2103{
2109 int done; 2104 int done;
2110 FILE *fd; 2105 FILE *fd;
2111 2106
2112 if ((fd = popen_printer ()) == NULL) 2107 if ((fd = popen_printer ()) == NULL)
2113 return; 2108 return;
2114 2109
2115 /* 2110 /*
2116 * 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
2117 * is received. 2112 * is received.
2118 */ 2113 */
2119 for (done = 0; !done;) 2114 for (done = 0; !done;)
2120 { 2115 {
2121 unsigned char buf[8]; 2116 unsigned char buf[8];
2122 unsigned char ch; 2117 unicode_t ch;
2123 unsigned int i, len; 2118 unsigned int i, len;
2124 2119
2125 if ((ch = cmd_getc ()) != C0_ESC) 2120 if ((ch = cmd_getc ()) != C0_ESC)
2126 { 2121 {
2127 if (putc (ch, fd) == EOF) 2122 if (putc (ch, fd) == EOF)
2128 break; /* done = 1 */ 2123 break; /* done = 1 */
2143 { 2138 {
2144 if ((buf[len++] = cmd_getc ()) == 'i') 2139 if ((buf[len++] = cmd_getc ()) == 'i')
2145 break; /* done = 1 */ 2140 break; /* done = 1 */
2146 } 2141 }
2147 } 2142 }
2143
2148 for (i = 0; i < len; i++) 2144 for (i = 0; i < len; i++)
2149 if (putc (buf[i], fd) == EOF) 2145 if (putc (buf[i], fd) == EOF)
2150 { 2146 {
2151 done = 1; 2147 done = 1;
2152 break; 2148 break;
2153 } 2149 }
2154 } 2150 }
2155 } 2151 }
2152
2156 pclose_printer (fd); 2153 pclose_printer (fd);
2157} 2154}
2158#endif /* PRINTPIPE */ 2155#endif /* PRINTPIPE */
2159/*}}} */ 2156/*}}} */
2160 2157
2168}; 2165};
2169/* *INDENT-ON* */ 2166/* *INDENT-ON* */
2170 2167
2171/*{{{ process non-printing single characters */ 2168/*{{{ process non-printing single characters */
2172void 2169void
2173rxvt_term::process_nonprinting (unsigned char ch) 2170rxvt_term::process_nonprinting (unicode_t ch)
2174{ 2171{
2175 switch (ch) 2172 switch (ch)
2176 { 2173 {
2174 case C0_ESC:
2175 process_escape_seq ();
2176 break;
2177 case C0_ENQ: /* terminal Status */ 2177 case C0_ENQ: /* terminal Status */
2178 if (rs[Rs_answerbackstring]) 2178 if (rs[Rs_answerbackstring])
2179 tt_write ( 2179 tt_write (
2180 (const unsigned char *)rs[Rs_answerbackstring], 2180 (const unsigned char *)rs[Rs_answerbackstring],
2181 (unsigned int)STRLEN (rs[Rs_answerbackstring])); 2181 (unsigned int)STRLEN (rs[Rs_answerbackstring]));
2204 scr_charset_choose (1); 2204 scr_charset_choose (1);
2205 break; 2205 break;
2206 case C0_SI: /* shift in - acs */ 2206 case C0_SI: /* shift in - acs */
2207 scr_charset_choose (0); 2207 scr_charset_choose (0);
2208 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;
2209 } 2220 }
2210} 2221}
2211/*}}} */ 2222/*}}} */
2212 2223
2213 2224
2214/*{{{ process VT52 escape sequences */ 2225/*{{{ process VT52 escape sequences */
2215void 2226void
2216rxvt_term::process_escape_vt52 (unsigned char ch) 2227rxvt_term::process_escape_vt52 (unicode_t ch)
2217{ 2228{
2218 int row, col; 2229 int row, col;
2219 2230
2220 switch (ch) 2231 switch (ch)
2221 { 2232 {
2273 2284
2274/*{{{ process escape sequences */ 2285/*{{{ process escape sequences */
2275void 2286void
2276rxvt_term::process_escape_seq () 2287rxvt_term::process_escape_seq ()
2277{ 2288{
2278 unsigned char ch = cmd_getc (); 2289 unicode_t ch = cmd_getc ();
2279 2290
2280 if (PrivateModes & PrivMode_vt52) 2291 if (PrivateModes & PrivMode_vt52)
2281 { 2292 {
2282 process_escape_vt52 (ch); 2293 process_escape_vt52 (ch);
2283 return; 2294 return;
2433/* *INDENT-ON* */ 2444/* *INDENT-ON* */
2434 2445
2435void 2446void
2436rxvt_term::process_csi_seq () 2447rxvt_term::process_csi_seq ()
2437{ 2448{
2438 unsigned char ch, priv, i; 2449 unicode_t ch, priv, i;
2439 unsigned int nargs, p; 2450 unsigned int nargs, p;
2440 int n, ndef; 2451 int n, ndef;
2441 int arg[ESC_ARGS]; 2452 int arg[ESC_ARGS];
2442 2453
2443 for (nargs = ESC_ARGS; nargs > 0;) 2454 for (nargs = ESC_ARGS; nargs > 0;)
2444 arg[--nargs] = 0; 2455 arg[--nargs] = 0;
2445 2456
2446 priv = 0; 2457 priv = 0;
2448 if (ch >= '<' && ch <= '?') 2459 if (ch >= '<' && ch <= '?')
2449 { /* '<' '=' '>' '?' */ 2460 { /* '<' '=' '>' '?' */
2450 priv = ch; 2461 priv = ch;
2451 ch = cmd_getc (); 2462 ch = cmd_getc ();
2452 } 2463 }
2464
2453 /* read any numerical arguments */ 2465 /* read any numerical arguments */
2454 for (n = -1; ch < CSI_ICH; ) 2466 for (n = -1; ch < CSI_ICH; )
2455 { 2467 {
2456 if (isdigit (ch)) 2468 if (isdigit (ch))
2457 { 2469 {
2464 { 2476 {
2465 if (nargs < ESC_ARGS) 2477 if (nargs < ESC_ARGS)
2466 arg[nargs++] = n; 2478 arg[nargs++] = n;
2467 n = -1; 2479 n = -1;
2468 } 2480 }
2469 else if (ch == '\b') 2481 else if (IS_CONTROL (ch))
2470 {
2471 scr_backspace ();
2472 }
2473 else if (ch == C0_ESC)
2474 {
2475 process_escape_seq ();
2476 return;
2477 }
2478 else if (ch < ' ')
2479 {
2480 process_nonprinting (ch); 2482 process_nonprinting (ch);
2481 } 2483
2482 ch = cmd_getc (); 2484 ch = cmd_getc ();
2483 } 2485 }
2484 2486
2485 if (ch > CSI_7F) 2487 if (ch > CSI_7F)
2486 return; 2488 return;
2728#endif 2730#endif
2729 2731
2730 case CSI_78: /* DECREQTPARM */ 2732 case CSI_78: /* DECREQTPARM */
2731 if (arg[0] == 0 || arg[0] == 1) 2733 if (arg[0] == 0 || arg[0] == 1)
2732 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);
2733 /* FALLTHROUGH */ 2735 break;
2734 2736
2735 default: 2737 default:
2736 break; 2738 break;
2737 } 2739 }
2738} 2740}
2741#ifndef NO_FRILLS 2743#ifndef NO_FRILLS
2742/* ARGSUSED */ 2744/* ARGSUSED */
2743void 2745void
2744rxvt_term::process_window_ops (const int *args, unsigned int nargs) 2746rxvt_term::process_window_ops (const int *args, unsigned int nargs)
2745{ 2747{
2746 int x, y; 2748 int x, y;
2747#if 0
2748 char *s;
2749#endif
2750 XWindowAttributes wattr; 2749 XWindowAttributes wattr;
2751 Window wdummy; 2750 Window wdummy;
2752 2751
2753 if (nargs == 0) 2752 if (nargs == 0)
2754 return; 2753 return;
2754
2755 switch (args[0]) 2755 switch (args[0])
2756 { 2756 {
2757 /* 2757 /*
2758 * commands 2758 * commands
2759 */ 2759 */
2760 case 1: /* deiconify window */ 2760 case 1: /* deiconify window */
2761 XMapWindow (display->display, TermWin.parent[0]); 2761 XMapWindow (display->display, TermWin.parent[0]);
2762 break; 2762 break;
2763 case 2: /* iconify window */ 2763 case 2: /* iconify window */
2764 XIconifyWindow (display->display, TermWin.parent[0], 2764 XIconifyWindow (display->display, TermWin.parent[0],
2781 break; 2781 break;
2782 case 8: /* set size (chars) */ 2782 case 8: /* set size (chars) */
2783 set_widthheight ((unsigned int) (args[2] * TermWin.fwidth), 2783 set_widthheight ((unsigned int) (args[2] * TermWin.fwidth),
2784 (unsigned int) (args[1] * TermWin.fheight)); 2784 (unsigned int) (args[1] * TermWin.fheight));
2785 break; 2785 break;
2786
2787 //case 9: NYI, TODO, restore maximized window or maximize window
2786 default: 2788 default:
2787 if (args[0] >= 24) /* set height (chars) */ 2789 if (args[0] >= 24) /* set height (chars) */
2788 set_widthheight ((unsigned int)TermWin.width, 2790 set_widthheight ((unsigned int)TermWin.width,
2789 (unsigned int) (args[1] * TermWin.fheight)); 2791 (unsigned int) (args[1] * TermWin.fheight));
2790 break; 2792 break;
2793
2794
2791 /* 2795 /*
2792 * reports - some output format copied from XTerm 2796 * reports - some output format copied from XTerm
2793 */ 2797 */
2794 case 11: /* report window state */ 2798 case 11: /* report window state */
2795 XGetWindowAttributes (display->display, TermWin.parent[0], &wattr); 2799 XGetWindowAttributes (display->display, TermWin.parent[0], &wattr);
2796 tt_printf ("\033[%dt", wattr.map_state == IsViewable ? 1 : 2); 2800 tt_printf ("\033[%dt", wattr.map_state == IsViewable ? 1 : 2);
2797 break; 2801 break;
2798 case 13: /* report window position */ 2802 case 13: /* report window position */
2804 break; 2808 break;
2805 case 14: /* report window size (pixels) */ 2809 case 14: /* report window size (pixels) */
2806 XGetWindowAttributes (display->display, TermWin.parent[0], &wattr); 2810 XGetWindowAttributes (display->display, TermWin.parent[0], &wattr);
2807 tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width); 2811 tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width);
2808 break; 2812 break;
2809 case 18: /* report window size (chars) */ 2813 case 18: /* report text area size (chars) */
2810 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);
2811 break; 2818 break;
2812#if 0 /* XXX: currently disabled due to security concerns */ 2819#if 0 /* XXX: currently disabled due to security concerns */
2813 case 20: /* report icon label */ 2820 case 20: /* report icon label */
2814 XGetIconName (display->display, TermWin.parent[0], &s); 2821 XGetIconName (display->display, TermWin.parent[0], &s);
2815 tt_printf ("\033]L%-.200s\234", s ? s : ""); /* 8bit ST */ 2822 tt_printf ("\033]L%-.200s\234", s ? s : ""); /* 8bit ST */
2817 case 21: /* report window title */ 2824 case 21: /* report window title */
2818 XFetchName (display->display, TermWin.parent[0], &s); 2825 XFetchName (display->display, TermWin.parent[0], &s);
2819 tt_printf ("\033]l%-.200s\234", s ? s : ""); /* 8bit ST */ 2826 tt_printf ("\033]l%-.200s\234", s ? s : ""); /* 8bit ST */
2820 break; 2827 break;
2821#endif 2828#endif
2822
2823 } 2829 }
2824} 2830}
2825#endif 2831#endif
2826 2832
2827/*----------------------------------------------------------------------*/ 2833/*----------------------------------------------------------------------*/
2828/* 2834/*
2829 * get input up until STRING TERMINATOR (or BEL) 2835 * get input up until STRING TERMINATOR (or BEL)
2830 * ends_how is terminator used. returned input must be free ()d 2836 * ends_how is terminator used. returned input must be free ()d
2831 */ 2837 */
2832unsigned char * 2838unsigned char *
2833rxvt_term::get_to_st (unsigned char *ends_how) 2839rxvt_term::get_to_st (unicode_t &ends_how)
2834{ 2840{
2835 int seen_esc = 0; /* seen escape? */ 2841 int seen_esc = 0; /* seen escape? */
2836 unsigned int n = 0; 2842 unsigned int n = 0;
2837 unsigned char *s; 2843 unsigned char *s;
2844 unicode_t ch;
2838 unsigned char ch, string[STRING_MAX]; 2845 unsigned char string[STRING_MAX];
2839 2846
2840 for (; (ch = cmd_getc ());) 2847 while ((ch = cmd_getc ()))
2841 { 2848 {
2842 if (ch == C0_BEL 2849 if (ch == C0_BEL
2843 || ch == CHAR_ST 2850 || ch == CHAR_ST
2844 || (ch == 0x5c && seen_esc)) /* 7bit ST */ 2851 || (ch == 0x5c && seen_esc)) /* 7bit ST */
2845 break; 2852 break;
2853
2846 if (ch == C0_ESC) 2854 if (ch == C0_ESC)
2847 { 2855 {
2848 seen_esc = 1; 2856 seen_esc = 1;
2849 continue; 2857 continue;
2850 } 2858 }
2851 else if (ch == '\t') 2859 else if (ch == '\t')
2852 ch = ' '; /* translate '\t' to space */ 2860 ch = ' '; /* translate '\t' to space */
2853 else if (ch < 0x08 || (ch > 0x0d && ch < 0x20)) 2861 else if (ch < 0x08 || (ch > 0x0d && ch < 0x20))
2854 return NULL; /* other control character - exit */ 2862 return NULL; /* other control character - exit */
2863
2855 if (n < sizeof (string) - 1) 2864 if (n < sizeof (string) - 1)
2856 string[n++] = ch; 2865 string[n++] = ch;
2866
2857 seen_esc = 0; 2867 seen_esc = 0;
2858 } 2868 }
2869
2859 string[n++] = '\0'; 2870 string[n++] = '\0';
2871
2860 if ((s = (unsigned char *)rxvt_malloc (n)) == NULL) 2872 if ((s = (unsigned char *)rxvt_malloc (n)) == NULL)
2861 return NULL; 2873 return NULL;
2874
2862 *ends_how = (ch == 0x5c ? C0_ESC : ch); 2875 ends_how = (ch == 0x5c ? C0_ESC : ch);
2863 STRNCPY (s, string, n); 2876 STRNCPY (s, string, n);
2864 return s; 2877 return s;
2865} 2878}
2866 2879
2867/*----------------------------------------------------------------------*/ 2880/*----------------------------------------------------------------------*/
2869 * 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)'
2870 */ 2883 */
2871void 2884void
2872rxvt_term::process_dcs_seq () 2885rxvt_term::process_dcs_seq ()
2873{ 2886{
2874 unsigned char eh, *s; 2887 unsigned char *s;
2888 unicode_t eh;
2889
2875 /* 2890 /*
2876 * Not handled yet 2891 * Not handled yet
2877 */ 2892 */
2878 s = get_to_st (&eh); 2893 s = get_to_st (eh);
2879 if (s) 2894 if (s)
2880 free (s); 2895 free (s);
2896
2881 return; 2897 return;
2882} 2898}
2883 2899
2884/*----------------------------------------------------------------------*/ 2900/*----------------------------------------------------------------------*/
2885/* 2901/*
2886 * process OPERATING SYSTEM COMMAND sequence `ESC ] Ps ; Pt (ST|BEL)' 2902 * process OPERATING SYSTEM COMMAND sequence `ESC ] Ps ; Pt (ST|BEL)'
2887 */ 2903 */
2888void 2904void
2889rxvt_term::process_osc_seq () 2905rxvt_term::process_osc_seq ()
2890{ 2906{
2891 unsigned char ch, eh, *s; 2907 unicode_t ch, eh;
2892 int arg; 2908 int arg;
2893 2909
2894 ch = cmd_getc (); 2910 ch = cmd_getc ();
2895 for (arg = 0; isdigit (ch); ch = cmd_getc ()) 2911 for (arg = 0; isdigit (ch); ch = cmd_getc ())
2896 arg = arg * 10 + (ch - '0'); 2912 arg = arg * 10 + (ch - '0');
2897 2913
2898 if (ch == ';') 2914 if (ch == ';')
2899 { 2915 {
2900 s = get_to_st (&eh); 2916 unsigned char *s = get_to_st (eh);
2917
2901 if (s) 2918 if (s)
2902 { 2919 {
2903 /* 2920 /*
2904 * rxvt_menubar_dispatch () violates the constness of the string, 2921 * rxvt_menubar_dispatch () violates the constness of the string,
2905 * so do it here 2922 * so do it here
2910#else 2927#else
2911 (void)0; 2928 (void)0;
2912#endif 2929#endif
2913 else 2930 else
2914 xterm_seq (arg, (char *)s, eh); 2931 xterm_seq (arg, (char *)s, eh);
2932
2915 free (s); 2933 free (s);
2916 } 2934 }
2917 } 2935 }
2918} 2936}
2919/* 2937/*
2940 * 702 = find font 2958 * 702 = find font
2941 */ 2959 */
2942void 2960void
2943rxvt_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)))
2944{ 2962{
2945 int changed = 0; 2963 int changed = 0;
2946 int color; 2964 int color;
2947 char *buf, *name; 2965 char *buf, *name;
2948 2966
2949 assert (str != NULL); 2967 assert (str != NULL);
2950 switch (op) 2968 switch (op)
2951 { 2969 {
2952 case XTerm_name: 2970 case XTerm_name:
2953 set_title (str); 2971 set_title (str);
2954 /* FALLTHROUGH */ 2972 /* FALLTHROUGH */
2955 case XTerm_iconName: 2973 case XTerm_iconName:
2956 set_iconName (str); 2974 set_icon_name (str);
2957 break; 2975 break;
2958 case XTerm_title: 2976 case XTerm_title:
2959 set_title (str); 2977 set_title (str);
2960 break; 2978 break;
2961 case XTerm_Color: 2979 case XTerm_Color:
2962 for (buf = (char *)str; buf && *buf;) 2980 for (buf = (char *)str; buf && *buf;)
2963 { 2981 {
2964 if ((name = STRCHR (buf, ';')) == NULL) 2982 if ((name = STRCHR (buf, ';')) == NULL)
2965 break; 2983 break;
2984
2966 *name++ = '\0'; 2985 *name++ = '\0';
2967 color = atoi (buf); 2986 color = atoi (buf);
2987
2968 if (color < 0 || color >= TOTAL_COLORS) 2988 if (color < 0 || color >= TOTAL_COLORS)
2969 break; 2989 break;
2990
2970 if ((buf = STRCHR (name, ';')) != NULL) 2991 if ((buf = STRCHR (name, ';')) != NULL)
2971 *buf++ = '\0'; 2992 *buf++ = '\0';
2993
2972 set_window_color (color + minCOLOR, name); 2994 set_window_color (color + minCOLOR, name);
2973 } 2995 }
2974 break; 2996 break;
2975#ifndef NO_CURSORCOLOR 2997#ifndef NO_CURSORCOLOR
2976 case XTerm_Color_cursor: 2998 case XTerm_Color_cursor:
3029 break; 3051 break;
3030 case XTerm_restoreBG: 3052 case XTerm_restoreBG:
3031 set_window_color (Color_bg, str); 3053 set_window_color (Color_bg, str);
3032 break; 3054 break;
3033 case XTerm_logfile: 3055 case XTerm_logfile:
3056 // TODO, when secure mode?
3034 break; 3057 break;
3035 case XTerm_font: 3058 case XTerm_font:
3036 change_font (str); 3059 change_font (str);
3037 break; 3060 break;
3038#ifndef NO_FRILLS 3061#ifndef NO_FRILLS
3064 close (fd); 3087 close (fd);
3065 } 3088 }
3066 } 3089 }
3067 break; 3090 break;
3068#endif 3091#endif
3069
3070 } 3092 }
3071} 3093}
3072/*----------------------------------------------------------------------*/ 3094/*----------------------------------------------------------------------*/
3073 3095
3074/*{{{ process DEC private mode sequences `ESC [ ? Ps mode' */ 3096/*{{{ process DEC private mode sequences `ESC [ ? Ps mode' */
3082 * so no need for fancy checking 3104 * so no need for fancy checking
3083 */ 3105 */
3084int 3106int
3085rxvt_term::privcases (int mode, unsigned long bit) 3107rxvt_term::privcases (int mode, unsigned long bit)
3086{ 3108{
3087 int state; 3109 int state;
3088 3110
3089 if (mode == 's') 3111 if (mode == 's')
3090 { 3112 {
3091 SavedModes |= (PrivateModes & bit); 3113 SavedModes |= (PrivateModes & bit);
3092 return -1; 3114 return -1;
3097 state = (SavedModes & bit) ? 1 : 0; /* no overlapping */ 3119 state = (SavedModes & bit) ? 1 : 0; /* no overlapping */
3098 else 3120 else
3099 state = (mode == 't') ? ! (PrivateModes & bit) : mode; 3121 state = (mode == 't') ? ! (PrivateModes & bit) : mode;
3100 PrivMode (state, bit); 3122 PrivMode (state, bit);
3101 } 3123 }
3124
3102 return state; 3125 return state;
3103} 3126}
3104 3127
3105/* we're not using priv _yet_ */ 3128/* we're not using priv _yet_ */
3106void 3129void
3107rxvt_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)
3108{ 3131{
3109 unsigned int i, j; 3132 unsigned int i, j;
3110 int state; 3133 int state;
3134
3111 static const struct 3135 static const struct
3112 { 3136 {
3113 const int argval; 3137 const int argval;
3114 const unsigned long bit; 3138 const unsigned long bit;
3115 } 3139 }
3140
3116 argtopriv[] = { 3141 argtopriv[] = {
3117 { 1, PrivMode_aplCUR }, 3142 { 1, PrivMode_aplCUR },
3118 { 2, PrivMode_vt52 }, 3143 { 2, PrivMode_vt52 },
3119 { 3, PrivMode_132 }, 3144 { 3, PrivMode_132 },
3120 { 4, PrivMode_smoothScroll }, 3145 { 4, PrivMode_smoothScroll },
3221 scr_autowrap (state); 3246 scr_autowrap (state);
3222 break; 3247 break;
3223 /* case 8: - auto repeat, can't do on a per window basis */ 3248 /* case 8: - auto repeat, can't do on a per window basis */
3224 case 9: /* X10 mouse reporting */ 3249 case 9: /* X10 mouse reporting */
3225 if (state) /* orthogonal */ 3250 if (state) /* orthogonal */
3226 PrivateModes &= ~ (PrivMode_MouseX11); 3251 PrivateModes &= ~PrivMode_MouseX11;
3227 break; 3252 break;
3228#ifdef menuBar_esc 3253#ifdef menuBar_esc
3229 case menuBar_esc: 3254 case menuBar_esc:
3230#ifdef MENUBAR 3255#ifdef MENUBAR
3231 map_menuBar (state); 3256 map_menuBar (state);
3251 break; 3276 break;
3252 /* case 66: - application key pad */ 3277 /* case 66: - application key pad */
3253 /* case 67: - backspace key */ 3278 /* case 67: - backspace key */
3254 case 1000: /* X11 mouse reporting */ 3279 case 1000: /* X11 mouse reporting */
3255 if (state) /* orthogonal */ 3280 if (state) /* orthogonal */
3256 PrivateModes &= ~ (PrivMode_MouseX10); 3281 PrivateModes &= ~PrivMode_MouseX10;
3257 break; 3282 break;
3258#if 0 3283#if 0
3259 case 1001: 3284 case 1001:
3260 break; /* X11 mouse highlighting */ 3285 break; /* X11 mouse highlighting */
3261#endif 3286#endif
3273 break; 3298 break;
3274 case 1047: /* secondary screen w/ clearing */ 3299 case 1047: /* secondary screen w/ clearing */
3275 case 1049: /* better secondary screen w/ clearing, but not fully implemented */ 3300 case 1049: /* better secondary screen w/ clearing, but not fully implemented */
3276 if (current_screen != PRIMARY) 3301 if (current_screen != PRIMARY)
3277 scr_erase_screen (2); 3302 scr_erase_screen (2);
3303
3278 scr_change_screen (state); 3304 scr_change_screen (state);
3279 /* FALLTHROUGH */ 3305 /* FALLTHROUGH */
3280 default: 3306 default:
3281 break; 3307 break;
3282 } 3308 }
3286 3312
3287/*{{{ process sgr sequences */ 3313/*{{{ process sgr sequences */
3288void 3314void
3289rxvt_term::process_sgr_mode (unsigned int nargs, const int *arg) 3315rxvt_term::process_sgr_mode (unsigned int nargs, const int *arg)
3290{ 3316{
3291 unsigned int i; 3317 unsigned int i;
3292 short rendset; 3318 short rendset;
3293 int rendstyle; 3319 int rendstyle;
3294 3320
3295 if (nargs == 0) 3321 if (nargs == 0)
3296 { 3322 {
3297 scr_rendition (0, ~RS_None); 3323 scr_rendition (0, ~RS_None);
3298 return; 3324 return;
3299 } 3325 }
3326
3300 for (i = 0; i < nargs; i++) 3327 for (i = 0; i < nargs; i++)
3301 { 3328 {
3302 rendset = -1; 3329 rendset = -1;
3303 switch (arg[i]) 3330 switch (arg[i])
3304 { 3331 {
3423 3450
3424/*{{{ process Rob Nation's own graphics mode sequences */ 3451/*{{{ process Rob Nation's own graphics mode sequences */
3425void 3452void
3426rxvt_term::process_graphics () 3453rxvt_term::process_graphics ()
3427{ 3454{
3428 unsigned char ch, cmd = cmd_getc (); 3455 unicode_t ch, cmd = cmd_getc ();
3429 3456
3430 if (cmd == 'Q') 3457 if (cmd == 'Q')
3431 { /* query graphics */ 3458 { /* query graphics */
3432 tt_printf ("\033G0\n"); /* no graphics */ 3459 tt_printf ("\033G0\n"); /* no graphics */
3433 return; 3460 return;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines