… | |
… | |
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 |
|
|
60 | class out_of_input { } out_of_input; |
|
|
61 | |
57 | /*{{{ Convert the keypress event into a string */ |
62 | /*{{{ Convert the keypress event into a string */ |
58 | void |
63 | void |
59 | rxvt_term::lookup_key (XKeyEvent &ev) |
64 | rxvt_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 */ |
618 | unsigned int |
625 | unsigned int |
619 | rxvt_term::cmd_write (const unsigned char *str, unsigned int count) |
626 | rxvt_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 | |
|
|
760 | bool |
|
|
761 | rxvt_term::cmd_parse () |
|
|
762 | { |
|
|
763 | bool flag = false; |
|
|
764 | uint32_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 | uint32_t buf[BUFSIZ]; |
|
|
778 | bool refreshnow = false; |
|
|
779 | int nlines = 0; |
|
|
780 | uint32_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 |
|
|
868 | uint32_t |
|
|
869 | rxvt_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 | */ |
|
|
904 | uint32_t |
|
|
905 | rxvt_term::cmd_getc () |
|
|
906 | { |
|
|
907 | for (;;) |
|
|
908 | { |
|
|
909 | uint32_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 |
922 | void |
767 | void |
… | |
… | |
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 | |
|
|
1922 | bool |
|
|
1923 | rxvt_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 |
|
|
2031 | unicode_t |
|
|
2032 | rxvt_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 | */ |
|
|
2066 | unicode_t |
|
|
2067 | rxvt_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 |
2080 | FILE * |
2080 | FILE * |
2081 | rxvt_term::popen_printer () |
2081 | rxvt_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 | |
2090 | int |
2091 | int |
2091 | rxvt_term::pclose_printer (FILE *stream) |
2092 | rxvt_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 | */ |
2106 | void |
2101 | void |
2107 | rxvt_term::process_print_pipe () |
2102 | rxvt_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 */ |
2172 | void |
2169 | void |
2173 | rxvt_term::process_nonprinting (unsigned char ch) |
2170 | rxvt_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 */ |
2215 | void |
2226 | void |
2216 | rxvt_term::process_escape_vt52 (unsigned char ch) |
2227 | rxvt_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 */ |
2275 | void |
2286 | void |
2276 | rxvt_term::process_escape_seq () |
2287 | rxvt_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; |
… | |
… | |
2331 | break; |
2342 | break; |
2332 | |
2343 | |
2333 | /* 8.3.87: NEXT LINE */ |
2344 | /* 8.3.87: NEXT LINE */ |
2334 | case C1_NEL: /* ESC E */ |
2345 | case C1_NEL: /* ESC E */ |
2335 | { |
2346 | { |
2336 | uint32_t nlcr[] = { '\n', '\r' }; |
2347 | unicode_t nlcr[] = { L'\n', L'\r' }; |
2337 | scr_add_lines (nlcr, 1, 2); |
2348 | scr_add_lines (nlcr, 1, 2); |
2338 | } |
2349 | } |
2339 | break; |
2350 | break; |
2340 | |
2351 | |
2341 | /* kidnapped escape sequence: Should be 8.3.48 */ |
2352 | /* kidnapped escape sequence: Should be 8.3.48 */ |
… | |
… | |
2433 | /* *INDENT-ON* */ |
2444 | /* *INDENT-ON* */ |
2434 | |
2445 | |
2435 | void |
2446 | void |
2436 | rxvt_term::process_csi_seq () |
2447 | rxvt_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 */ |
2743 | void |
2745 | void |
2744 | rxvt_term::process_window_ops (const int *args, unsigned int nargs) |
2746 | rxvt_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 | */ |
2832 | unsigned char * |
2838 | unsigned char * |
2833 | rxvt_term::get_to_st (unsigned char *ends_how) |
2839 | rxvt_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 | */ |
2871 | void |
2884 | void |
2872 | rxvt_term::process_dcs_seq () |
2885 | rxvt_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 | */ |
2888 | void |
2904 | void |
2889 | rxvt_term::process_osc_seq () |
2905 | rxvt_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 | */ |
2942 | void |
2960 | void |
2943 | rxvt_term::xterm_seq (int op, const char *str, unsigned char resp __attribute__ ((unused))) |
2961 | rxvt_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 | */ |
3084 | int |
3106 | int |
3085 | rxvt_term::privcases (int mode, unsigned long bit) |
3107 | rxvt_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_ */ |
3106 | void |
3129 | void |
3107 | rxvt_term::process_terminal_mode (int mode, int priv __attribute__ ((unused)), unsigned int nargs, const int *arg) |
3130 | rxvt_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 }, |
… | |
… | |
3126 | { menuBar_esc, PrivMode_menuBar }, |
3151 | { menuBar_esc, PrivMode_menuBar }, |
3127 | #endif |
3152 | #endif |
3128 | #ifdef scrollBar_esc |
3153 | #ifdef scrollBar_esc |
3129 | { scrollBar_esc, PrivMode_scrollBar }, |
3154 | { scrollBar_esc, PrivMode_scrollBar }, |
3130 | #endif |
3155 | #endif |
|
|
3156 | // 18, 19 printing-related |
3131 | { 25, PrivMode_VisibleCursor }, |
3157 | { 25, PrivMode_VisibleCursor }, |
|
|
3158 | // 30 show scrollbar rxvt. extension |
3132 | { 35, PrivMode_ShiftKeys }, |
3159 | { 35, PrivMode_ShiftKeys }, // rxvt extension |
3133 | { 40, PrivMode_132OK }, |
3160 | { 40, PrivMode_132OK }, |
|
|
3161 | // 41 xterm more fixes NYI |
|
|
3162 | // 45 margin bell NYI |
|
|
3163 | // 46 start logging |
3134 | { 47, PrivMode_Screen }, |
3164 | { 47, PrivMode_Screen }, |
3135 | { 66, PrivMode_aplKP }, |
3165 | { 66, PrivMode_aplKP }, |
3136 | #ifndef NO_BACKSPACE_KEY |
3166 | #ifndef NO_BACKSPACE_KEY |
3137 | { 67, PrivMode_BackSpace }, |
3167 | { 67, PrivMode_BackSpace }, |
3138 | #endif |
3168 | #endif |
3139 | { 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 |
3140 | { 1010, PrivMode_TtyOutputInh }, |
3173 | { 1010, PrivMode_TtyOutputInh }, // rxvt extension |
3141 | { 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 |
3142 | { 1047, PrivMode_Screen }, |
3178 | { 1047, PrivMode_Screen }, |
|
|
3179 | // 1048 save and restore cursor |
3143 | { 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 |
3144 | }; |
3182 | }; |
3145 | |
3183 | |
3146 | if (nargs == 0) |
3184 | if (nargs == 0) |
3147 | return; |
3185 | return; |
3148 | |
3186 | |
… | |
… | |
3163 | state = privcases (mode, argtopriv[j].bit); |
3201 | state = privcases (mode, argtopriv[j].bit); |
3164 | break; |
3202 | break; |
3165 | } |
3203 | } |
3166 | |
3204 | |
3167 | /* 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 | |
3168 | if (state == -1) |
3217 | if (state >= 0) |
|
|
3218 | /* extra handling for values with valid 0 or 1 state */ |
3169 | switch (arg[i]) |
3219 | switch (arg[i]) |
3170 | { |
3220 | { |
3171 | 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 */ |
3172 | if (mode == 0) |
3234 | if (state) |
3173 | scr_cursor (RESTORE); |
3235 | Options &= ~Opt_jumpScroll; |
3174 | else if (mode == 1) |
3236 | else |
3175 | 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); |
3176 | /* FALLTHROUGH */ |
3305 | /* FALLTHROUGH */ |
3177 | default: |
3306 | default: |
3178 | continue; /* for (;i;) */ |
3307 | break; |
3179 | } |
3308 | } |
3180 | |
|
|
3181 | /* extra handling for values with valid 0 or 1 state */ |
|
|
3182 | switch (arg[i]) |
|
|
3183 | { |
|
|
3184 | /* case 1: - application cursor keys */ |
|
|
3185 | case 2: /* VT52 mode */ |
|
|
3186 | /* oddball mode. should be set regardless of set/reset |
|
|
3187 | * parameter. Return from VT52 mode with an ESC < from |
|
|
3188 | * within VT52 mode |
|
|
3189 | */ |
|
|
3190 | PrivMode (1, PrivMode_vt52); |
|
|
3191 | break; |
|
|
3192 | case 3: /* 80/132 */ |
|
|
3193 | if (PrivateModes & PrivMode_132OK) |
|
|
3194 | set_widthheight (((state ? 132 : 80) * TermWin.fwidth), TermWin.height); |
|
|
3195 | break; |
|
|
3196 | case 4: /* smooth scrolling */ |
|
|
3197 | if (state) |
|
|
3198 | Options &= ~Opt_jumpScroll; |
|
|
3199 | else |
|
|
3200 | Options |= Opt_jumpScroll; |
|
|
3201 | break; |
|
|
3202 | case 5: /* reverse video */ |
|
|
3203 | scr_rvideo_mode (state); |
|
|
3204 | break; |
|
|
3205 | case 6: /* relative/absolute origins */ |
|
|
3206 | scr_relative_origin (state); |
|
|
3207 | break; |
|
|
3208 | case 7: /* autowrap */ |
|
|
3209 | scr_autowrap (state); |
|
|
3210 | break; |
|
|
3211 | /* case 8: - auto repeat, can't do on a per window basis */ |
|
|
3212 | case 9: /* X10 mouse reporting */ |
|
|
3213 | if (state) /* orthogonal */ |
|
|
3214 | PrivateModes &= ~ (PrivMode_MouseX11); |
|
|
3215 | break; |
|
|
3216 | #ifdef menuBar_esc |
|
|
3217 | case menuBar_esc: |
|
|
3218 | #ifdef MENUBAR |
|
|
3219 | map_menuBar (state); |
|
|
3220 | #endif |
|
|
3221 | break; |
|
|
3222 | #endif |
|
|
3223 | #ifdef scrollBar_esc |
|
|
3224 | case scrollBar_esc: |
|
|
3225 | if (scrollbar_mapping (state)) |
|
|
3226 | { |
|
|
3227 | resize_all_windows (0, 0, 0); |
|
|
3228 | scr_touch (true); |
|
|
3229 | } |
|
|
3230 | break; |
|
|
3231 | #endif |
|
|
3232 | case 25: /* visible/invisible cursor */ |
|
|
3233 | scr_cursor_visible (state); |
|
|
3234 | break; |
|
|
3235 | /* case 35: - shift keys */ |
|
|
3236 | /* case 40: - 80 <--> 132 mode */ |
|
|
3237 | case 47: /* secondary screen */ |
|
|
3238 | scr_change_screen (state); |
|
|
3239 | break; |
|
|
3240 | /* case 66: - application key pad */ |
|
|
3241 | /* case 67: - backspace key */ |
|
|
3242 | case 1000: /* X11 mouse reporting */ |
|
|
3243 | if (state) /* orthogonal */ |
|
|
3244 | PrivateModes &= ~ (PrivMode_MouseX10); |
|
|
3245 | break; |
|
|
3246 | #if 0 |
|
|
3247 | case 1001: |
|
|
3248 | break; /* X11 mouse highlighting */ |
|
|
3249 | #endif |
|
|
3250 | case 1010: /* scroll to bottom on TTY output inhibit */ |
|
|
3251 | if (state) |
|
|
3252 | Options &= ~Opt_scrollTtyOutput; |
|
|
3253 | else |
|
|
3254 | Options |= Opt_scrollTtyOutput; |
|
|
3255 | break; |
|
|
3256 | case 1011: /* scroll to bottom on key press */ |
|
|
3257 | if (state) |
|
|
3258 | Options |= Opt_scrollTtyKeypress; |
|
|
3259 | else |
|
|
3260 | Options &= ~Opt_scrollTtyKeypress; |
|
|
3261 | break; |
|
|
3262 | case 1047: /* secondary screen w/ clearing */ |
|
|
3263 | case 1049: /* better secondary screen w/ clearing, but not fully implemented */ |
|
|
3264 | if (current_screen != PRIMARY) |
|
|
3265 | scr_erase_screen (2); |
|
|
3266 | scr_change_screen (state); |
|
|
3267 | /* FALLTHROUGH */ |
|
|
3268 | default: |
|
|
3269 | break; |
|
|
3270 | } |
|
|
3271 | } |
3309 | } |
3272 | } |
3310 | } |
3273 | /*}}} */ |
3311 | /*}}} */ |
3274 | |
3312 | |
3275 | /*{{{ process sgr sequences */ |
3313 | /*{{{ process sgr sequences */ |
3276 | void |
3314 | void |
3277 | rxvt_term::process_sgr_mode (unsigned int nargs, const int *arg) |
3315 | rxvt_term::process_sgr_mode (unsigned int nargs, const int *arg) |
3278 | { |
3316 | { |
3279 | unsigned int i; |
3317 | unsigned int i; |
3280 | short rendset; |
3318 | short rendset; |
3281 | int rendstyle; |
3319 | int rendstyle; |
3282 | |
3320 | |
3283 | if (nargs == 0) |
3321 | if (nargs == 0) |
3284 | { |
3322 | { |
3285 | scr_rendition (0, ~RS_None); |
3323 | scr_rendition (0, ~RS_None); |
3286 | return; |
3324 | return; |
3287 | } |
3325 | } |
|
|
3326 | |
3288 | for (i = 0; i < nargs; i++) |
3327 | for (i = 0; i < nargs; i++) |
3289 | { |
3328 | { |
3290 | rendset = -1; |
3329 | rendset = -1; |
3291 | switch (arg[i]) |
3330 | switch (arg[i]) |
3292 | { |
3331 | { |
… | |
… | |
3303 | rendset = 1, rendstyle = RS_Blink; |
3342 | rendset = 1, rendstyle = RS_Blink; |
3304 | break; |
3343 | break; |
3305 | case 7: |
3344 | case 7: |
3306 | rendset = 1, rendstyle = RS_RVid; |
3345 | rendset = 1, rendstyle = RS_RVid; |
3307 | break; |
3346 | break; |
|
|
3347 | case 8: |
|
|
3348 | // invisible. NYI |
|
|
3349 | break; |
3308 | case 22: |
3350 | case 22: |
3309 | rendset = 0, rendstyle = RS_Bold; |
3351 | rendset = 0, rendstyle = RS_Bold; |
3310 | break; |
3352 | break; |
3311 | case 24: |
3353 | case 24: |
3312 | rendset = 0, rendstyle = RS_Uline; |
3354 | rendset = 0, rendstyle = RS_Uline; |
… | |
… | |
3315 | rendset = 0, rendstyle = RS_Blink; |
3357 | rendset = 0, rendstyle = RS_Blink; |
3316 | break; |
3358 | break; |
3317 | case 27: |
3359 | case 27: |
3318 | rendset = 0, rendstyle = RS_RVid; |
3360 | rendset = 0, rendstyle = RS_RVid; |
3319 | break; |
3361 | break; |
|
|
3362 | case 28: |
|
|
3363 | // visible. NYI |
|
|
3364 | break; |
3320 | } |
3365 | } |
|
|
3366 | |
3321 | if (rendset != -1) |
3367 | if (rendset != -1) |
3322 | { |
3368 | { |
3323 | scr_rendition (rendset, rendstyle); |
3369 | scr_rendition (rendset, rendstyle); |
3324 | continue; /* for (;i;) */ |
3370 | continue; /* for (;i;) */ |
3325 | } |
3371 | } |
… | |
… | |
3332 | case 33: |
3378 | case 33: |
3333 | case 34: |
3379 | case 34: |
3334 | case 35: |
3380 | case 35: |
3335 | case 36: |
3381 | case 36: |
3336 | case 37: |
3382 | case 37: |
3337 | scr_color ((unsigned int) (minCOLOR + (arg[i] - 30)), |
3383 | scr_color ((unsigned int) (minCOLOR + (arg[i] - 30)), Color_fg); |
3338 | Color_fg); |
|
|
3339 | break; |
3384 | break; |
3340 | #ifdef TTY_256COLOR |
3385 | #ifdef TTY_256COLOR |
3341 | case 38: |
3386 | case 38: |
3342 | if (nargs > i + 2 && arg[i + 1] == 5) |
3387 | if (nargs > i + 2 && arg[i + 1] == 5) |
3343 | { |
3388 | { |
3344 | scr_color ((unsigned int) (minCOLOR + arg[i + 2]), |
3389 | scr_color ((unsigned int) (minCOLOR + arg[i + 2]), Color_fg); |
3345 | Color_fg); |
|
|
3346 | i += 2; |
3390 | i += 2; |
3347 | } |
3391 | } |
3348 | break; |
3392 | break; |
3349 | #endif |
3393 | #endif |
3350 | case 39: /* default fg */ |
3394 | case 39: /* default fg */ |
… | |
… | |
3357 | case 43: |
3401 | case 43: |
3358 | case 44: |
3402 | case 44: |
3359 | case 45: |
3403 | case 45: |
3360 | case 46: |
3404 | case 46: |
3361 | case 47: |
3405 | case 47: |
3362 | scr_color ((unsigned int) (minCOLOR + (arg[i] - 40)), |
3406 | scr_color ((unsigned int) (minCOLOR + (arg[i] - 40)), Color_bg); |
3363 | Color_bg); |
|
|
3364 | break; |
3407 | break; |
3365 | #ifdef TTY_256COLOR |
3408 | #ifdef TTY_256COLOR |
3366 | case 48: |
3409 | case 48: |
3367 | if (nargs > i + 2 && arg[i + 1] == 5) |
3410 | if (nargs > i + 2 && arg[i + 1] == 5) |
3368 | { |
3411 | { |
3369 | scr_color ((unsigned int) (minCOLOR + arg[i + 2]), |
3412 | scr_color ((unsigned int) (minCOLOR + arg[i + 2]), Color_bg); |
3370 | Color_bg); |
|
|
3371 | i += 2; |
3413 | i += 2; |
3372 | } |
3414 | } |
3373 | break; |
3415 | break; |
3374 | #endif |
3416 | #endif |
3375 | case 49: /* default bg */ |
3417 | case 49: /* default bg */ |
… | |
… | |
3408 | |
3450 | |
3409 | /*{{{ process Rob Nation's own graphics mode sequences */ |
3451 | /*{{{ process Rob Nation's own graphics mode sequences */ |
3410 | void |
3452 | void |
3411 | rxvt_term::process_graphics () |
3453 | rxvt_term::process_graphics () |
3412 | { |
3454 | { |
3413 | unsigned char ch, cmd = cmd_getc (); |
3455 | unicode_t ch, cmd = cmd_getc (); |
3414 | |
3456 | |
3415 | if (cmd == 'Q') |
3457 | if (cmd == 'Q') |
3416 | { /* query graphics */ |
3458 | { /* query graphics */ |
3417 | tt_printf ("\033G0\n"); /* no graphics */ |
3459 | tt_printf ("\033G0\n"); /* no graphics */ |
3418 | return; |
3460 | return; |