├── .gitignore ├── Makefile ├── README.markdown ├── reference ├── console_codes.man.html └── ctlseqs.pdf ├── tests ├── .gitignore ├── 01_expected_output.txt ├── 01_input.txt ├── 02_tabs_expected_output.txt ├── 02_tabs_input.txt ├── 03_tabs_expected_output.txt ├── 03_tabs_input.txt ├── 04_esc_D_expected_output.txt ├── 04_esc_D_input.txt ├── 05_esc_E_expected_output.txt ├── 05_esc_E_input.txt ├── 06_esc_M_expected_output.txt ├── 06_esc_M_input.txt ├── 07_OSC_0_setwi_expected_output.txt ├── 07_OSC_0_setwi_input.txt ├── 08_insert_blank_expected_output.txt ├── 08_insert_blank_input.txt ├── 09_insert_blank_expected_output.txt ├── 09_insert_blank_input.txt ├── 10_insert_blank_expected_output.txt ├── 10_insert_blank_input.txt ├── 11_insert_blank_expected_output.txt ├── 11_insert_blank_input.txt ├── 12_CSI_A_expected_output.txt ├── 12_CSI_A_input.txt ├── 13_CSI_A_expected_output.txt ├── 13_CSI_A_input.txt ├── 14_CSI_A_expected_output.txt ├── 14_CSI_A_input.txt ├── 15_CSI_A_expected_output.txt ├── 15_CSI_A_input.txt ├── 16_CSI_AB_expected_output.txt ├── 16_CSI_AB_input.txt ├── 17_CSI_B_expected_output.txt ├── 17_CSI_B_input.txt ├── 18_CSI_B_expected_output.txt ├── 18_CSI_B_input.txt ├── 19_CSI_C_expected_output.txt ├── 19_CSI_C_input.txt ├── 20_CSI_C_expected_output.txt ├── 20_CSI_C_input.txt ├── 21_CSI_P_expected_output.txt ├── 21_CSI_P_input.txt ├── 22_CSI_P_expected_output.txt ├── 22_CSI_P_input.txt ├── 23_CSI_P_expected_output.txt ├── 23_CSI_P_input.txt ├── 24_CSI_P_expected_output.txt ├── 24_CSI_P_input.txt ├── 25_CSI_K_expected_output.txt ├── 25_CSI_K_input.txt ├── 26_CSI_K_expected_output.txt ├── 26_CSI_K_input.txt ├── 27_CSI_K_expected_output.txt ├── 27_CSI_K_input.txt ├── 28_CSI_K_expected_output.txt ├── 28_CSI_K_input.txt ├── 29_CSI_K_expected_output.txt ├── 29_CSI_K_input.txt ├── 30_CSI_K_expected_output.txt ├── 30_CSI_K_input.txt ├── 31_raw_expected_output.txt ├── 31_raw_input.txt ├── 32_raw_expected_output.txt └── 32_raw_input.txt └── typescript2txt.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | typescript2txt 2 | *.o 3 | 4 | test_01_actual_output.txt 5 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | CC=g++ 2 | CFLAGS=-Wall -Wextra -g 3 | CPPFLAGS=-Wall -Wextra -g 4 | 5 | all: typescript2txt 6 | 7 | typescript2txt: typescript2txt.o 8 | 9 | tests/01_passed: ./typescript2txt tests/01_input.txt tests/01_expected_output.txt 10 | @./typescript2txt < tests/01_input.txt > tests/01_actual_output.txt 11 | @diff -q tests/01_expected_output.txt tests/01_actual_output.txt 12 | touch tests/01_passed 13 | 14 | tests/02_passed: ./typescript2txt tests/02_tabs_input.txt tests/02_tabs_expected_output.txt 15 | @./typescript2txt < tests/02_tabs_input.txt > tests/02_tabs_actual_output.txt 16 | @diff -q tests/02_tabs_expected_output.txt tests/02_tabs_actual_output.txt 17 | touch tests/02_passed 18 | 19 | tests/03_passed: ./typescript2txt tests/03_tabs_input.txt tests/03_tabs_expected_output.txt 20 | @./typescript2txt < tests/03_tabs_input.txt > tests/03_tabs_actual_output.txt 21 | @diff -q tests/03_tabs_expected_output.txt tests/03_tabs_actual_output.txt 22 | touch tests/03_passed 23 | 24 | tests/04_passed: ./typescript2txt tests/04_esc_D_input.txt tests/04_esc_D_expected_output.txt 25 | @./typescript2txt < tests/04_esc_D_input.txt > tests/04_esc_D_actual_output.txt 26 | @diff -q tests/04_esc_D_expected_output.txt tests/04_esc_D_actual_output.txt 27 | touch tests/04_passed 28 | 29 | tests/05_passed: ./typescript2txt tests/05_esc_E_input.txt tests/05_esc_E_expected_output.txt 30 | @./typescript2txt < tests/05_esc_E_input.txt > tests/05_esc_E_actual_output.txt 31 | @diff -q tests/05_esc_E_expected_output.txt tests/05_esc_E_actual_output.txt 32 | touch tests/05_passed 33 | 34 | tests/06_passed: ./typescript2txt tests/06_esc_M_input.txt tests/06_esc_M_expected_output.txt 35 | @./typescript2txt < tests/06_esc_M_input.txt > tests/06_esc_M_actual_output.txt 36 | @diff -q tests/06_esc_M_expected_output.txt tests/06_esc_M_actual_output.txt 37 | touch tests/06_passed 38 | 39 | tests/07_passed: ./typescript2txt tests/07_OSC_0_setwi_input.txt tests/07_OSC_0_setwi_expected_output.txt 40 | @./typescript2txt < tests/07_OSC_0_setwi_input.txt > tests/07_OSC_0_setwi_actual_output.txt 41 | @diff -q tests/07_OSC_0_setwi_expected_output.txt tests/07_OSC_0_setwi_actual_output.txt 42 | touch tests/07_passed 43 | 44 | tests/08_passed: ./typescript2txt tests/08_insert_blank_input.txt tests/08_insert_blank_expected_output.txt 45 | @./typescript2txt < tests/08_insert_blank_input.txt > tests/08_insert_blank_actual_output.txt 46 | @diff -q tests/08_insert_blank_expected_output.txt tests/08_insert_blank_actual_output.txt 47 | touch tests/08_passed 48 | 49 | tests/09_passed: ./typescript2txt tests/09_insert_blank_input.txt tests/09_insert_blank_expected_output.txt 50 | @./typescript2txt < tests/09_insert_blank_input.txt > tests/09_insert_blank_actual_output.txt 51 | @diff -q tests/09_insert_blank_expected_output.txt tests/09_insert_blank_actual_output.txt 52 | touch tests/09_passed 53 | 54 | tests/10_passed: ./typescript2txt tests/10_insert_blank_input.txt tests/10_insert_blank_expected_output.txt 55 | @./typescript2txt < tests/10_insert_blank_input.txt > tests/10_insert_blank_actual_output.txt 56 | @diff -q tests/10_insert_blank_expected_output.txt tests/10_insert_blank_actual_output.txt 57 | touch tests/10_passed 58 | 59 | tests/11_passed: ./typescript2txt tests/11_insert_blank_input.txt tests/11_insert_blank_expected_output.txt 60 | @./typescript2txt < tests/11_insert_blank_input.txt > tests/11_insert_blank_actual_output.txt 61 | @diff -q tests/11_insert_blank_expected_output.txt tests/11_insert_blank_actual_output.txt 62 | touch tests/11_passed 63 | 64 | tests/12_passed: ./typescript2txt tests/12_CSI_A_input.txt tests/12_CSI_A_expected_output.txt 65 | @./typescript2txt < tests/12_CSI_A_input.txt > tests/12_CSI_A_actual_output.txt 66 | @diff -q tests/12_CSI_A_expected_output.txt tests/12_CSI_A_actual_output.txt 67 | touch tests/12_passed 68 | 69 | tests/13_passed: ./typescript2txt tests/13_CSI_A_input.txt tests/13_CSI_A_expected_output.txt 70 | @./typescript2txt < tests/13_CSI_A_input.txt > tests/13_CSI_A_actual_output.txt 71 | @diff -q tests/13_CSI_A_expected_output.txt tests/13_CSI_A_actual_output.txt 72 | touch tests/13_passed 73 | 74 | tests/14_passed: ./typescript2txt tests/14_CSI_A_input.txt tests/14_CSI_A_expected_output.txt 75 | @./typescript2txt < tests/14_CSI_A_input.txt > tests/14_CSI_A_actual_output.txt 76 | @diff -q tests/14_CSI_A_expected_output.txt tests/14_CSI_A_actual_output.txt 77 | touch tests/14_passed 78 | 79 | tests/15_passed: ./typescript2txt tests/15_CSI_A_input.txt tests/15_CSI_A_expected_output.txt 80 | @./typescript2txt < tests/15_CSI_A_input.txt > tests/15_CSI_A_actual_output.txt 81 | @diff -q tests/15_CSI_A_expected_output.txt tests/15_CSI_A_actual_output.txt 82 | touch tests/15_passed 83 | 84 | tests/16_passed: ./typescript2txt tests/16_CSI_AB_input.txt tests/16_CSI_AB_expected_output.txt 85 | @./typescript2txt < tests/16_CSI_AB_input.txt > tests/16_CSI_AB_actual_output.txt 86 | @diff -q tests/16_CSI_AB_expected_output.txt tests/16_CSI_AB_actual_output.txt 87 | touch tests/16_passed 88 | 89 | tests/17_passed: ./typescript2txt tests/17_CSI_B_input.txt tests/17_CSI_B_expected_output.txt 90 | @./typescript2txt < tests/17_CSI_B_input.txt > tests/17_CSI_B_actual_output.txt 91 | @diff -q tests/17_CSI_B_expected_output.txt tests/17_CSI_B_actual_output.txt 92 | touch tests/17_passed 93 | 94 | tests/18_passed: ./typescript2txt tests/18_CSI_B_input.txt tests/18_CSI_B_expected_output.txt 95 | @./typescript2txt < tests/18_CSI_B_input.txt > tests/18_CSI_B_actual_output.txt 96 | @diff -q tests/18_CSI_B_expected_output.txt tests/18_CSI_B_actual_output.txt 97 | touch tests/18_passed 98 | 99 | tests/19_passed: ./typescript2txt tests/19_CSI_C_input.txt tests/19_CSI_C_expected_output.txt 100 | @./typescript2txt < tests/19_CSI_C_input.txt > tests/19_CSI_C_actual_output.txt 101 | @diff -q tests/19_CSI_C_expected_output.txt tests/19_CSI_C_actual_output.txt 102 | touch tests/19_passed 103 | 104 | tests/20_passed: ./typescript2txt tests/20_CSI_C_input.txt tests/20_CSI_C_expected_output.txt 105 | @./typescript2txt < tests/20_CSI_C_input.txt > tests/20_CSI_C_actual_output.txt 106 | @diff -q tests/20_CSI_C_expected_output.txt tests/20_CSI_C_actual_output.txt 107 | touch tests/20_passed 108 | 109 | tests/21_passed: ./typescript2txt tests/21_CSI_P_input.txt tests/21_CSI_P_expected_output.txt 110 | @./typescript2txt < tests/21_CSI_P_input.txt > tests/21_CSI_P_actual_output.txt 111 | @diff -q tests/21_CSI_P_expected_output.txt tests/21_CSI_P_actual_output.txt 112 | touch tests/21_passed 113 | 114 | tests/22_passed: ./typescript2txt tests/22_CSI_P_input.txt tests/22_CSI_P_expected_output.txt 115 | @./typescript2txt < tests/22_CSI_P_input.txt > tests/22_CSI_P_actual_output.txt 116 | @diff -q tests/22_CSI_P_expected_output.txt tests/22_CSI_P_actual_output.txt 117 | touch tests/22_passed 118 | 119 | tests/23_passed: ./typescript2txt tests/23_CSI_P_input.txt tests/23_CSI_P_expected_output.txt 120 | @./typescript2txt < tests/23_CSI_P_input.txt > tests/23_CSI_P_actual_output.txt 121 | @diff -q tests/23_CSI_P_expected_output.txt tests/23_CSI_P_actual_output.txt 122 | touch tests/23_passed 123 | 124 | tests/24_passed: ./typescript2txt tests/24_CSI_P_input.txt tests/24_CSI_P_expected_output.txt 125 | @./typescript2txt < tests/24_CSI_P_input.txt > tests/24_CSI_P_actual_output.txt 126 | @diff -q tests/24_CSI_P_expected_output.txt tests/24_CSI_P_actual_output.txt 127 | touch tests/24_passed 128 | 129 | tests/25_passed: ./typescript2txt tests/25_CSI_K_input.txt tests/25_CSI_K_expected_output.txt 130 | @./typescript2txt < tests/25_CSI_K_input.txt > tests/25_CSI_K_actual_output.txt 131 | @diff -q tests/25_CSI_K_expected_output.txt tests/25_CSI_K_actual_output.txt 132 | touch tests/25_passed 133 | 134 | tests/26_passed: ./typescript2txt tests/26_CSI_K_input.txt tests/26_CSI_K_expected_output.txt 135 | @./typescript2txt < tests/26_CSI_K_input.txt > tests/26_CSI_K_actual_output.txt 136 | @diff -q tests/26_CSI_K_expected_output.txt tests/26_CSI_K_actual_output.txt 137 | touch tests/26_passed 138 | 139 | tests/27_passed: ./typescript2txt tests/27_CSI_K_input.txt tests/27_CSI_K_expected_output.txt 140 | @./typescript2txt < tests/27_CSI_K_input.txt > tests/27_CSI_K_actual_output.txt 141 | @diff -q tests/27_CSI_K_expected_output.txt tests/27_CSI_K_actual_output.txt 142 | touch tests/27_passed 143 | 144 | tests/28_passed: ./typescript2txt tests/28_CSI_K_input.txt tests/28_CSI_K_expected_output.txt 145 | @./typescript2txt < tests/28_CSI_K_input.txt > tests/28_CSI_K_actual_output.txt 146 | @diff -q tests/28_CSI_K_expected_output.txt tests/28_CSI_K_actual_output.txt 147 | touch tests/28_passed 148 | 149 | tests/29_passed: ./typescript2txt tests/29_CSI_K_input.txt tests/29_CSI_K_expected_output.txt 150 | @./typescript2txt < tests/29_CSI_K_input.txt > tests/29_CSI_K_actual_output.txt 151 | @diff -q tests/29_CSI_K_expected_output.txt tests/29_CSI_K_actual_output.txt 152 | touch tests/29_passed 153 | 154 | tests/30_passed: ./typescript2txt tests/30_CSI_K_input.txt tests/30_CSI_K_expected_output.txt 155 | @./typescript2txt < tests/30_CSI_K_input.txt > tests/30_CSI_K_actual_output.txt 156 | @diff -q tests/30_CSI_K_expected_output.txt tests/30_CSI_K_actual_output.txt 157 | touch tests/30_passed 158 | 159 | tests/31_passed: ./typescript2txt tests/31_raw_input.txt tests/31_raw_expected_output.txt 160 | @./typescript2txt < tests/31_raw_input.txt > tests/31_raw_actual_output.txt 161 | @diff -q tests/31_raw_expected_output.txt tests/31_raw_actual_output.txt 162 | touch tests/31_passed 163 | 164 | tests/32_passed: ./typescript2txt tests/32_raw_input.txt tests/32_raw_expected_output.txt 165 | @./typescript2txt < tests/32_raw_input.txt > tests/32_raw_actual_output.txt 166 | @diff -q tests/32_raw_expected_output.txt tests/32_raw_actual_output.txt 167 | touch tests/32_passed 168 | 169 | test: tests/02_passed tests/03_passed 170 | test: tests/04_passed tests/05_passed tests/06_passed 171 | test: tests/07_passed tests/08_passed tests/09_passed 172 | test: tests/10_passed tests/11_passed 173 | test: tests/12_passed tests/13_passed tests/14_passed 174 | test: tests/15_passed tests/16_passed tests/17_passed 175 | test: tests/18_passed tests/19_passed tests/20_passed 176 | test: tests/21_passed tests/22_passed tests/23_passed 177 | test: tests/24_passed tests/25_passed tests/26_passed 178 | test: tests/27_passed tests/28_passed tests/29_passed 179 | test: tests/30_passed tests/31_passed tests/32_passed 180 | test: #Tests after here are not expected to pass yet 181 | test: tests/01_passed 182 | 183 | clean: 184 | -rm -f *.o typescript2txt 185 | -rm -f tests/??_passed tests/??_*actual_output.txt 186 | 187 | .PHONY: all clean test -------------------------------------------------------------------------------- /README.markdown: -------------------------------------------------------------------------------- 1 | #typescript2txt 2 | 3 | typescript2txt is a program to strip out (some of) the extra control 4 | characters from the output of the unix script command. 5 | 6 | It attempts to address the bug mentioned in the unix man page: 7 | 8 | Script places everything in the log file, including linefeeds and 9 | backspaces. This is not what the naive user expects. 10 | 11 | And generate output closer to what the naive user would expect. 12 | 13 | #Usage 14 | 15 | typescript2txt < output_of_script_cmd > output_as_plain_text 16 | 17 | #Compilation 18 | 19 | The code is set up to compile under linux using gcc and gmake. 20 | 21 | make 22 | 23 | Will compile everything and produce a typescript2txt executable. No 24 | install target has been created. You'll need to copy the executable 25 | to an appropriate directory. 26 | 27 | #History 28 | 29 | This program was inspired by code written by John C. McCabe-Dansted 30 | (gmatht@gmail.com) in 2008 and posted at 31 | https://launchpadlibrarian.net/14571190/script2txt.c as part of a [bug 32 | report on 33 | launchpad](https://bugs.launchpad.net/ubuntu/+source/util-linux/+bug/231340). 34 | It had some memory access problems (that kept RadixSeven from using it 35 | as-is) so he decided to fix it. In order to share it with the world, 36 | he made a github repo for it. 37 | 38 | After fixing the memory access and trying to fix other things 39 | RadixSeven realized the process of making it usable would be much 40 | faster and produce better code if he just rewrote everything from 41 | scratch. This resulted in the code you see here. 42 | 43 | #Testing Philosophy 44 | 45 | You can run the tests assuming you have diff installed. 46 | 47 | The tests are **very** minimal. It takes a lot of time to write good 48 | tests. The initial author did not want to invest that time. There is 49 | usually only one test for a code. So most of the complexity of the 50 | implementation is not tested. 51 | 52 | Further, only tests for codes actually implemented are included. This 53 | means that any code that is supposed to generate a warning or a code 54 | that is ignored is likely to be absent from the test suite. 55 | 56 | Anyone who would like to is welcome to make things more robust by 57 | fleshing out the test cases to really check the functionality. Other 58 | users should be aware that there are likely to be major bugs that 59 | didn't interfere with the purposes of the earlier authors. 60 | 61 | The test cases were created by: 62 | 63 | 1. Creating a file containing the desired input named *_input.txt 64 | 65 | 2. Dumping that file to a terminal window (either Gnome's terminal or 66 | Konsole depending on which computer the developer was using at the 67 | time) 68 | 69 | 3. Copying the new contents of the terminal window to the 70 | expected_output.txt file 71 | 72 | #Source for console codes 73 | 74 | The files I used to crib the console codes from are in the reference 75 | directory. Their original locations are 76 | http://www.kernel.org/doc/man-pages/online/pages/man4/console_codes.4.html 77 | and http://www.kitebird.com/csh-tcsh-book/ctlseqs.pdf 78 | -------------------------------------------------------------------------------- /reference/console_codes.man.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | console_codes(4) - Linux manual page 6 | 20 | 21 |
22 | 23 | 24 | 34 | 39 | 40 |
25 | 26 | 27 | home   28 | contributing   29 | bugs   30 | download   31 | online pages   32 | 33 | 35 | 36 | 37 | 38 |
41 |
42 |
43 |

44 |
NAME | DESCRIPTION | NOTES | BUGS | SEE ALSO | COLOPHONThe Linux Programming Interface
45 |


 46 | CONSOLE_CODES(4)              Linux Programmer's Manual              CONSOLE_CODES(4)
 47 | 
48 |

NAME         top

       console_codes - Linux console escape and control sequences
 49 | 
50 |

DESCRIPTION         top

       The Linux console implements a large subset of the VT102 and ECMA-48/ISO
 51 |        6429/ANSI X3.64 terminal controls, plus certain private-mode sequences for
 52 |        changing the color palette, character-set mapping, etc.  In the tabular
 53 |        descriptions below, the second column gives ECMA-48 or DEC mnemonics (the
 54 |        latter if prefixed with DEC) for the given function.  Sequences without a
 55 |        mnemonic are neither ECMA-48 nor VT102.
 56 | 
 57 |        After all the normal output processing has been done, and a stream of
 58 |        characters arrives at the console driver for actual printing, the first thing
 59 |        that happens is a translation from the code used for processing to the code
 60 |        used for printing.
 61 | 
 62 |        If the console is in UTF-8 mode, then the incoming bytes are first assembled
 63 |        into 16-bit Unicode codes.  Otherwise each byte is transformed according to
 64 |        the current mapping table (which translates it to a Unicode value).  See the
 65 |        Character Sets section below for discussion.
 66 | 
 67 |        In the normal case, the Unicode value is converted to a font index, and this
 68 |        is stored in video memory, so that the corresponding glyph (as found in video
 69 |        ROM) appears on the screen.  Note that the use of Unicode (and the design of
 70 |        the PC hardware) allows us to use 512 different glyphs simultaneously.
 71 | 
 72 |        If the current Unicode value is a control character, or we are currently
 73 |        processing an escape sequence, the value will treated specially.  Instead of
 74 |        being turned into a font index and rendered as a glyph, it may trigger cursor
 75 |        movement or other control functions.  See the Linux Console Controls section
 76 |        below for discussion.
 77 | 
 78 |        It is generally not good practice to hard-wire terminal controls into
 79 |        programs.  Linux supports a terminfo(5) database of terminal capabilities.
 80 |        Rather than emitting console escape sequences by hand, you will almost always
 81 |        want to use a terminfo-aware screen library or utility such as ncurses(3),
 82 |        tput(1), or reset(1).
 83 | 

Linux Console Controls

84 |
       This section describes all the control characters and escape sequences that
 85 |        invoke special functions (i.e., anything other than writing a glyph at the
 86 |        current cursor location) on the Linux console.
 87 | 
 88 |        Control characters
 89 | 
 90 |        A character is a control character if (before transformation according to the
 91 |        mapping table) it has one of the 14 codes 00 (NUL), 07 (BEL), 08 (BS), 09
 92 |        (HT), 0a (LF), 0b (VT), 0c (FF), 0d (CR), 0e (SO), 0f (SI), 18 (CAN), 1a
 93 |        (SUB), 1b (ESC), 7f (DEL).  One can set a "display control characters" mode
 94 |        (see below), and allow 07, 09, 0b, 18, 1a, 7f to be displayed as glyphs.  On
 95 |        the other hand, in UTF-8 mode all codes 00-1f are regarded as control
 96 |        characters, regardless of any "display control characters" mode.
 97 | 
 98 |        If we have a control character, it is acted upon immediately and then
 99 |        discarded (even in the middle of an escape sequence) and the escape sequence
100 |        continues with the next character.  (However, ESC starts a new escape
101 |        sequence, possibly aborting a previous unfinished one, and CAN and SUB abort
102 |        any escape sequence.)  The recognized control characters are BEL, BS, HT, LF,
103 |        VT, FF, CR, SO, SI, CAN, SUB, ESC, DEL, CSI.  They do what one would expect:
104 | 
105 |        BEL (0x07, ^G) beeps;
106 | 
107 |        BS (0x08, ^H) backspaces one column (but not past the beginning of the line);
108 | 
109 |        HT (0x09, ^I) goes to the next tab stop or to the end of the line if there is
110 |               no earlier tab stop;
111 | 
112 |        LF (0x0A, ^J), VT (0x0B, ^K) and FF (0x0C, ^L) all give a linefeed, and if
113 |               LF/NL (new-line mode) is set also a carriage return;
114 | 
115 |        CR (0x0D, ^M) gives a carriage return;
116 | 
117 |        SO (0x0E, ^N) activates the G1 character set;
118 | 
119 |        SI (0x0F, ^O) activates the G0 character set;
120 | 
121 |        CAN (0x18, ^X) and SUB (0x1A, ^Z) interrupt escape sequences;
122 | 
123 |        ESC (0x1B, ^[) starts an escape sequence;
124 | 
125 |        DEL (0x7F) is ignored;
126 | 
127 |        CSI (0x9B) is equivalent to ESC [.
128 | 
129 |        ESC- but not CSI-sequences
130 | 
131 |        ESC c     RIS      Reset.
132 |        ESC D     IND      Linefeed.
133 |        ESC E     NEL      Newline.
134 |        ESC H     HTS      Set tab stop at current column.
135 |        ESC M     RI       Reverse linefeed.
136 |        ESC Z     DECID    DEC private identification. The kernel returns the
137 |                           string  ESC [ ? 6 c, claiming that it is a VT102.
138 |        ESC 7     DECSC    Save current state (cursor coordinates,
139 |                           attributes, character sets pointed at by G0, G1).
140 |        ESC 8     DECRC    Restore state most recently saved by ESC 7.
141 |        ESC [     CSI      Control sequence introducer
142 |        ESC %              Start sequence selecting character set
143 |        ESC % @               Select default (ISO 646 / ISO 8859-1)
144 |        ESC % G               Select UTF-8
145 |        ESC % 8               Select UTF-8 (obsolete)
146 |        ESC # 8   DECALN   DEC screen alignment test - fill screen with E's.
147 |        ESC (              Start sequence defining G0 character set
148 |        ESC ( B               Select default (ISO 8859-1 mapping)
149 |        ESC ( 0               Select VT100 graphics mapping
150 |        ESC ( U               Select null mapping - straight to character ROM
151 |        ESC ( K               Select user mapping - the map that is loaded by
152 |                              the utility mapscrn(8).
153 |        ESC )              Start sequence defining G1
154 |                           (followed by one of B, 0, U, K, as above).
155 |        ESC >     DECPNM   Set numeric keypad mode
156 |        ESC =     DECPAM   Set application keypad mode
157 |        ESC ]     OSC      (Should be: Operating system command) ESC ] P
158 |                           nrrggbb: set palette, with parameter given in 7
159 |                           hexadecimal digits after the final P :-(.  Here n
160 |                           is the color (0-15), and rrggbb indicates the
161 |                           red/green/blue values (0-255).  ESC ] R: reset
162 |                           palette
163 | 
164 |        ECMA-48 CSI sequences
165 | 
166 |        CSI (or ESC [) is followed by a sequence of parameters, at most NPAR (16),
167 |        that are decimal numbers separated by semicolons.  An empty or absent
168 |        parameter is taken to be 0.  The sequence of parameters may be preceded by a
169 |        single question mark.
170 | 
171 |        However, after CSI [ (or ESC [ [) a single character is read and this entire
172 |        sequence is ignored.  (The idea is to ignore an echoed function key.)
173 | 
174 |        The action of a CSI sequence is determined by its final character.
175 | 
176 |        @   ICH       Insert the indicated # of blank characters.
177 |        A   CUU       Move cursor up the indicated # of rows.
178 |        B   CUD       Move cursor down the indicated # of rows.
179 |        C   CUF       Move cursor right the indicated # of columns.
180 |        D   CUB       Move cursor left the indicated # of columns.
181 |        E   CNL       Move cursor down the indicated # of rows, to column 1.
182 |        F   CPL       Move cursor up the indicated # of rows, to column 1.
183 |        G   CHA       Move cursor to indicated column in current row.
184 |        H   CUP       Move cursor to the indicated row, column (origin at 1,1).
185 |        J   ED        Erase display (default: from cursor to end of display).
186 |                      ESC [ 1 J: erase from start to cursor.
187 |                      ESC [ 2 J: erase whole display.
188 |        K   EL        Erase line (default: from cursor to end of line).
189 |                      ESC [ 1 K: erase from start of line to cursor.
190 |                      ESC [ 2 K: erase whole line.
191 |        L   IL        Insert the indicated # of blank lines.
192 |        M   DL        Delete the indicated # of lines.
193 |        P   DCH       Delete the indicated # of characters on the current line.
194 |        X   ECH       Erase the indicated # of characters on the current line.
195 |        a   HPR       Move cursor right the indicated # of columns.
196 |        c   DA        Answer ESC [ ? 6 c: "I am a VT102".
197 |        d   VPA       Move cursor to the indicated row, current column.
198 |        e   VPR       Move cursor down the indicated # of rows.
199 |        f   HVP       Move cursor to the indicated row, column.
200 |        g   TBC       Without parameter: clear tab stop at the current position.
201 |                      ESC [ 3 g: delete all tab stops.
202 |        h   SM        Set Mode (see below).
203 |        l   RM        Reset Mode (see below).
204 |        m   SGR       Set attributes (see below).
205 |        n   DSR       Status report (see below).
206 |        q   DECLL     Set keyboard LEDs.
207 |                      ESC [ 0 q: clear all LEDs
208 |                      ESC [ 1 q: set Scroll Lock LED
209 |                      ESC [ 2 q: set Num Lock LED
210 |                      ESC [ 3 q: set Caps Lock LED
211 |        r   DECSTBM   Set scrolling region; parameters are top and bottom row.
212 |        s   ?         Save cursor location.
213 |        u   ?         Restore cursor location.
214 |        `   HPA       Move cursor to indicated column in current row.
215 | 
216 |        ECMA-48 Set Graphics Rendition
217 | 
218 |        The ECMA-48 SGR sequence ESC [ parameters m sets display attributes.  Several
219 |        attributes can be set in the same sequence, separated by semicolons.  An empty
220 |        parameter (between semicolons or string initiator or terminator) is
221 |        interpreted as a zero.
222 | 
223 |        param   result
224 |        0       reset all attributes to their defaults
225 |        1       set bold
226 |        2       set half-bright (simulated with color on a color display)
227 |        4       set underscore (simulated with color on a color display)
228 |                (the colors used to simulate dim or underline are set
229 |                using ESC ] ...)
230 |        5       set blink
231 |        7       set reverse video
232 |        10      reset selected mapping, display control flag, and toggle
233 |                meta flag (ECMA-48 says "primary font").
234 |        11      select null mapping, set display control flag, reset
235 |                toggle meta flag (ECMA-48 says "first alternate font").
236 | 
237 |        12      select null mapping, set display control flag, set toggle
238 |                meta flag (ECMA-48 says "second alternate font").  The
239 |                toggle meta flag causes the high bit of a byte to be
240 |                toggled before the mapping table translation is done.
241 |        21      set normal intensity (ECMA-48 says "doubly underlined")
242 |        22      set normal intensity
243 |        24      underline off
244 |        25      blink off
245 |        27      reverse video off
246 |        30      set black foreground
247 |        31      set red foreground
248 |        32      set green foreground
249 |        33      set brown foreground
250 |        34      set blue foreground
251 |        35      set magenta foreground
252 |        36      set cyan foreground
253 |        37      set white foreground
254 |        38      set underscore on, set default foreground color
255 |        39      set underscore off, set default foreground color
256 |        40      set black background
257 |        41      set red background
258 |        42      set green background
259 |        43      set brown background
260 |        44      set blue background
261 |        45      set magenta background
262 |        46      set cyan background
263 |        47      set white background
264 |        49      set default background color
265 | 
266 |        ECMA-48 Mode Switches
267 | 
268 |        ESC [ 3 h
269 |               DECCRM (default off): Display control chars.
270 | 
271 |        ESC [ 4 h
272 |               DECIM (default off): Set insert mode.
273 | 
274 |        ESC [ 20 h
275 |               LF/NL (default off): Automatically follow echo of LF, VT or FF with CR.
276 | 
277 |        ECMA-48 Status Report Commands
278 | 
279 |        ESC [ 5 n
280 |               Device status report (DSR): Answer is ESC [ 0 n (Terminal OK).
281 | 
282 |        ESC [ 6 n
283 |               Cursor position report (CPR): Answer is ESC [ y ; x R, where x,y is the
284 |               cursor location.
285 | 
286 |        DEC Private Mode (DECSET/DECRST) sequences
287 | 
288 |        These are not described in ECMA-48.  We list the Set Mode sequences; the Reset
289 |        Mode sequences are obtained by replacing the final 'h' by 'l'.
290 | 
291 |        ESC [ ? 1 h
292 |               DECCKM (default off): When set, the cursor keys send an ESC O prefix,
293 |               rather than ESC [.
294 | 
295 |        ESC [ ? 3 h
296 |               DECCOLM (default off = 80 columns): 80/132 col mode switch.  The driver
297 |               sources note that this alone does not suffice; some user-mode utility
298 |               such as resizecons(8) has to change the hardware registers on the
299 |               console video card.
300 | 
301 |        ESC [ ? 5 h
302 |               DECSCNM (default off): Set reverse-video mode.
303 | 
304 |        ESC [ ? 6 h
305 |               DECOM (default off): When set, cursor addressing is relative to the
306 |               upper left corner of the scrolling region.
307 | 
308 |        ESC [ ? 7 h
309 |               DECAWM (default on): Set autowrap on.  In this mode, a graphic
310 |               character emitted after column 80 (or column 132 of DECCOLM is on)
311 |               forces a wrap to the beginning of the following line first.
312 | 
313 |        ESC [ ? 8 h
314 |               DECARM (default on): Set keyboard autorepeat on.
315 | 
316 |        ESC [ ? 9 h
317 |               X10 Mouse Reporting (default off): Set reporting mode to 1 (or reset to
318 |               0) -- see below.
319 | 
320 |        ESC [ ? 25 h
321 |               DECTECM (default on): Make cursor visible.
322 | 
323 |        ESC [ ? 1000 h
324 |               X11 Mouse Reporting (default off): Set reporting mode to 2 (or reset to
325 |               0) -- see below.
326 | 
327 |        Linux Console Private CSI Sequences
328 | 
329 |        The following sequences are neither ECMA-48 nor native VT102.  They are native
330 |        to the Linux console driver.  Colors are in SGR parameters: 0 = black, 1 =
331 |        red, 2 = green, 3 = brown, 4 = blue, 5 = magenta, 6 = cyan, 7 = white.
332 | 
333 |        ESC [ 1 ; n ]       Set color n as the underline color
334 |        ESC [ 2 ; n ]       Set color n as the dim color
335 |        ESC [ 8 ]           Make the current color pair the default attributes.
336 |        ESC [ 9 ; n ]       Set screen blank timeout to n minutes.
337 |        ESC [ 10 ; n ]      Set bell frequency in Hz.
338 |        ESC [ 11 ; n ]      Set bell duration in msec.
339 |        ESC [ 12 ; n ]      Bring specified console to the front.
340 |        ESC [ 13 ]          Unblank the screen.
341 |        ESC [ 14 ; n ]      Set the VESA powerdown interval in minutes.
342 | 

Character Sets

343 |
       The kernel knows about 4 translations of bytes into console-screen symbols.
344 |        The four tables are: a) Latin1 -> PC, b) VT100 graphics -> PC, c) PC -> PC, d)
345 |        user-defined.
346 | 
347 |        There are two character sets, called G0 and G1, and one of them is the current
348 |        character set.  (Initially G0.)  Typing ^N causes G1 to become current, ^O
349 |        causes G0 to become current.
350 | 
351 |        These variables G0 and G1 point at a translation table, and can be changed by
352 |        the user.  Initially they point at tables a) and b), respectively.  The
353 |        sequences ESC ( B and ESC ( 0 and ESC ( U and ESC ( K cause G0 to point at
354 |        translation table a), b), c) and d), respectively.  The sequences ESC ) B and
355 |        ESC ) 0 and ESC ) U and ESC ) K cause G1 to point at translation table a), b),
356 |        c) and d), respectively.
357 | 
358 |        The sequence ESC c causes a terminal reset, which is what you want if the
359 |        screen is all garbled.  The oft-advised "echo ^V^O" will only make G0 current,
360 |        but there is no guarantee that G0 points at table a).  In some distributions
361 |        there is a program reset(1) that just does "echo ^[c".  If your terminfo entry
362 |        for the console is correct (and has an entry rs1=\Ec), then "tput reset" will
363 |        also work.
364 | 
365 |        The user-defined mapping table can be set using mapscrn(8).  The result of the
366 |        mapping is that if a symbol c is printed, the symbol s = map[c] is sent to the
367 |        video memory.  The bitmap that corresponds to s is found in the character ROM,
368 |        and can be changed using setfont(8).
369 | 

Mouse Tracking

370 |
       The mouse tracking facility is intended to return xterm(1)-compatible mouse
371 |        status reports.  Because the console driver has no way to know the device or
372 |        type of the mouse, these reports are returned in the console input stream only
373 |        when the virtual terminal driver receives a mouse update ioctl.  These ioctls
374 |        must be generated by a mouse-aware user-mode application such as the gpm(8)
375 |        daemon.
376 | 
377 |        The mouse tracking escape sequences generated by xterm(1) encode numeric
378 |        parameters in a single character as value+040.  For example, '!' is 1.  The
379 |        screen coordinate system is 1-based.
380 | 
381 |        The X10 compatibility mode sends an escape sequence on button press encoding
382 |        the location and the mouse button pressed.  It is enabled by sending ESC [ ? 9
383 |        h and disabled with ESC [ ? 9 l.  On button press, xterm(1) sends ESC [ M bxy
384 |        (6 characters).  Here b is button-1, and x and y are the x and y coordinates
385 |        of the mouse when the button was pressed.  This is the same code the kernel
386 |        also produces.
387 | 
388 |        Normal tracking mode (not implemented in Linux 2.0.24) sends an escape
389 |        sequence on both button press and release.  Modifier information is also sent.
390 |        It is enabled by sending ESC [ ? 1000 h and disabled with ESC [ ? 1000 l.  On
391 |        button press or release, xterm(1) sends ESC [ M bxy.  The low two bits of b
392 |        encode button information: 0=MB1 pressed, 1=MB2 pressed, 2=MB3 pressed,
393 |        3=release.  The upper bits encode what modifiers were down when the button was
394 |        pressed and are added together: 4=Shift, 8=Meta, 16=Control.  Again x and y
395 |        are the x and y coordinates of the mouse event.  The upper left corner is
396 |        (1,1).
397 | 

Comparisons With Other Terminals

398 |
       Many different terminal types are described, like the Linux console, as being
399 |        "VT100-compatible".  Here we discuss differences between the Linux console and
400 |        the two most important others, the DEC VT102 and xterm(1).
401 | 
402 |        Control-character handling
403 | 
404 |        The VT102 also recognized the following control characters:
405 | 
406 |        NUL (0x00) was ignored;
407 | 
408 |        ENQ (0x05) triggered an answerback message;
409 | 
410 |        DC1 (0x11, ^Q, XON) resumed transmission;
411 | 
412 |        DC3 (0x13, ^S, XOFF) caused VT100 to ignore (and stop transmitting) all codes
413 |               except XOFF and XON.
414 | 
415 |        VT100-like DC1/DC3 processing may be enabled by the tty driver.
416 | 
417 |        The xterm(1) program (in VT100 mode) recognizes the control characters BEL,
418 |        BS, HT, LF, VT, FF, CR, SO, SI, ESC.
419 | 
420 |        Escape sequences
421 | 
422 |        VT100 console sequences not implemented on the Linux console:
423 | 
424 |        ESC N       SS2   Single shift 2. (Select G2 character set for the next
425 |                          character only.)
426 |        ESC O       SS3   Single shift 3. (Select G3 character set for the next
427 |                          character only.)
428 |        ESC P       DCS   Device control string (ended by ESC \)
429 |        ESC X       SOS   Start of string.
430 |        ESC ^       PM    Privacy message (ended by ESC \)
431 |        ESC \       ST    String terminator
432 |        ESC * ...         Designate G2 character set
433 |        ESC + ...         Designate G3 character set
434 | 
435 |        The program xterm(1) (in VT100 mode) recognizes ESC c, ESC # 8, ESC >, ESC =,
436 |        ESC D, ESC E, ESC H, ESC M, ESC N, ESC O, ESC P ... ESC \, ESC Z (it answers
437 |        ESC [ ? 1 ; 2 c, "I am a VT100 with advanced video option") and ESC ^ ... ESC
438 |        \ with the same meanings as indicated above.  It accepts ESC (, ESC ), ESC *,
439 |        ESC + followed by 0, A, B for the DEC special character and line drawing set,
440 |        UK, and US-ASCII, respectively.
441 | 
442 |        The user can configure xterm(1) to respond to VT220-specific control
443 |        sequences, and it will identify itself as a VT52, VT100, and up depending on
444 |        the way it is configured and initialized.
445 | 
446 |        It accepts ESC ] (OSC) for the setting of certain resources.  In addition to
447 |        the ECMA-48 string terminator (ST), xterm(1) accepts a BEL to terminate an OSC
448 |        string.  These are a few of the OSC control sequences recognized by xterm(1):
449 | 
450 |        ESC ] 0 ; txt ST        Set icon name and window title to txt.
451 |        ESC ] 1 ; txt ST        Set icon name to txt.
452 |        ESC ] 2 ; txt ST        Set window title to txt.
453 |        ESC ] 4 ; num; txt ST   Set ANSI color num to txt.
454 |        ESC ] 10 ; txt ST       Set dynamic text color to txt.
455 |        ESC ] 4 6 ; name ST     Change log file to name (normally disabled
456 |                                by a compile-time option)
457 |        ESC ] 5 0 ; fn ST       Set font to fn.
458 | 
459 |        It recognizes the following with slightly modified meaning (saving more state,
460 |        behaving closer to VT100/VT220):
461 | 
462 |        ESC 7  DECSC   Save cursor
463 |        ESC 8  DECRC   Restore cursor
464 | 
465 |        It also recognizes
466 | 
467 |        ESC F          Cursor to lower left corner of screen (if enabled by
468 |                       xterm(1)'s hpLowerleftBugCompat resource)
469 |        ESC l          Memory lock (per HP terminals).
470 |                       Locks memory above the cursor.
471 |        ESC m          Memory unlock (per HP terminals).
472 |        ESC n   LS2    Invoke the G2 character set.
473 |        ESC o   LS3    Invoke the G3 character set.
474 |        ESC |   LS3R   Invoke the G3 character set as GR.
475 |        ESC }   LS2R   Invoke the G2 character set as GR.
476 |        ESC ~   LS1R   Invoke the G1 character set as GR.
477 | 
478 |        It also recognizes ESC % and provides a more complete UTF-8 implementation
479 |        than Linux console.
480 | 
481 |        CSI Sequences
482 | 
483 |        Old versions of xterm(1), for example, from X11R5, interpret the blink SGR as
484 |        a bold SGR.  Later versions which implemented ANSI colors, for example,
485 |        XFree86 3.1.2A in 1995, improved this by allowing the blink attribute to be
486 |        displayed as a color.  Modern versions of xterm implement blink SGR as
487 |        blinking text and still allow colored text as an alternate rendering of SGRs.
488 |        Stock X11R6 versions did not recognize the color-setting SGRs until the
489 |        X11R6.8 release, which incorporated XFree86 xterm.  All ECMA-48 CSI sequences
490 |        recognized by Linux are also recognized by xterm, however xterm(1) implements
491 |        several ECMA-48 and DEC control sequences not recognized by Linux.
492 | 
493 |        The xterm(1) program recognizes all of the DEC Private Mode sequences listed
494 |        above, but none of the Linux private-mode sequences.  For discussion of
495 |        xterm(1)'s own private-mode sequences, refer to the Xterm Control Sequences
496 |        document by Edward Moy, Stephen Gildea, and Thomas E. Dickey available with
497 |        the X distribution.  That document, though terse, is much longer than this
498 |        manual page.  For a chronological overview,
499 | 
500 |            http://invisible-island.net/xterm/xterm.log.html
501 | 
502 |        details changes to xterm.
503 | 
504 |        The vttest program
505 | 
506 |            http://invisible-island.net/vttest/
507 | 
508 |        demonstrates many of these control sequences.  The xterm(1) source
509 |        distribution also contains sample scripts which exercise other features.
510 | 
511 |

NOTES         top

       ESC 8 (DECRC) is not able to restore the character set changed with ESC %.
512 | 
513 |

BUGS         top

       In 2.0.23, CSI is broken, and NUL is not ignored inside escape sequences.
514 | 
515 |        Some older kernel versions (after 2.0) interpret 8-bit control sequences.
516 |        These "C1 controls" use codes between 128 and 159 to replace ESC [, ESC ] and
517 |        similar two-byte control sequence initiators.  There are fragments of that in
518 |        modern kernels (either overlooked or broken by changes to support UTF-8), but
519 |        the implementation is incomplete and should be regarded as unreliable.
520 | 
521 |        Linux "private mode" sequences do not follow the rules in ECMA-48 for private
522 |        mode control sequences.  In particular, those ending with ] do not use a
523 |        standard terminating character.  The OSC (set palette) sequence is a greater
524 |        problem, since xterm(1) may interpret this as a control sequence which
525 |        requires a string terminator (ST).  Unlike the setterm(1) sequences which will
526 |        be ignored (since they are invalid control sequences), the palette sequence
527 |        will make xterm(1) appear to hang (though pressing the return-key will fix
528 |        that).  To accommodate applications which have been hardcoded to use Linux
529 |        control sequences, set the xterm(1) resource brokenLinuxOSC to true.
530 | 
531 |        An older version of this document implied that Linux recognizes the ECMA-48
532 |        control sequence for invisible text.  It is ignored.
533 | 
534 |

SEE ALSO         top

       console(4), console_ioctl(4), charsets(7)
535 | 
536 |

COLOPHON         top

       This page is part of release 3.32 of the Linux man-pages project.  A
537 |        description of the project, and information about reporting bugs, can be found
538 |        at http://www.kernel.org/doc/man-pages/.
539 | 
540 | Linux                                 2008-01-01                     CONSOLE_CODES(4)
541 | 
542 |
543 |

HTML rendering created 2010-12-03 by Michael Kerrisk, author of The Linux Programming Interface 544 | 545 |

546 | -------------------------------------------------------------------------------- /reference/ctlseqs.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RadixSeven/typescript2txt/ad0d0aa9e472dd502140c041486f6e36d2f15cfa/reference/ctlseqs.pdf -------------------------------------------------------------------------------- /tests/.gitignore: -------------------------------------------------------------------------------- 1 | ??_passed 2 | ??_*actual_output.txt 3 | -------------------------------------------------------------------------------- /tests/01_expected_output.txt: -------------------------------------------------------------------------------- 1 | Script started on Thu 03 Nov 2011 02:20:51 PM EDT 2 | To run a command as administrator (user "root"), use "sudo ". 3 | See "man sudo_root" for details. 4 | 5 | protein:...ta-Sets/Synthetic Data Sets/6$ ls -l *.arff 6 | -rw-r--r-- 1 eric bioinf 2304095 2011-11-03 14:06 foo33.arff 7 | -rw-r--r-- 1 eric bioinf 4373673 2011-11-03 13:47 foo65.arff 8 | -rw-r--r-- 1 eric bioinf 1139290 2011-11-03 13:41 foo.arff 9 | protein:...ta-Sets/Synthetic Data Sets/6$ ls -lh *.arff 10 | -rw-r--r-- 1 eric bioinf 2.2M 2011-11-03 14:06 foo33.arff 11 | -rw-r--r-- 1 eric bioinf 4.2M 2011-11-03 13:47 foo65.arff 12 | -rw-r--r-- 1 eric bioinf 1.1M 2011-11-03 13:41 foo.arff 13 | protein:...ta-Sets/Synthetic Data Sets/6$ rm foo.arff 14 | protein:...ta-Sets/Synthetic Data Sets/6$ mkdir ~/ANN_Data 15 | protein:...ta-Sets/Synthetic Data Sets/6$ rmdir ~/ANN_Data/ 16 | protein:...ta-Sets/Synthetic Data Sets/6$ mkdir ~/PkFindData 17 | protein:...ta-Sets/Synthetic Data Sets/6$ mv foo33.arff ~/PkFindData/two_spectra 18 | _window_33.arff 19 | protein:...ta-Sets/Synthetic Data Sets/6$ mv foo65.arff ~/PkFindData/two_spectra 20 | _window_65.arff 21 | protein:...ta-Sets/Synthetic Data Sets/6$ pushd ~/PkFindData/ 22 | ~/PkFindData ~/Dropbox/NMR-Training-and-Testing-Data-Sets/Synthetic Data Sets/6 23 | protein:~/PkFindData$ waffles_learn splittest -reps 10 -stddev -trainratio .7 Er 24 | ror:_Unexpected_token,_0,34,35,_in_arg_8^Cignore 0,34,35 -labels 36 neuralnet 25 | protein:~/PkFindData$ waffles_learn splittest -reps 10 -stddev -trainratio .7 fo 26 | o33.arff -ignore 0,34,35 -labels 36 neuralnet 27 | _________________________________ 28 | File not found: foo33.arff 29 | 30 | Brief Usage Information: 31 | 32 | waffles_learn splittest [dataset] [algorithm] 33 | This shuffles the data, then splits it into two parts, trains with one part, 34 | and tests with the other. (This also works with model-free algorithms.) 35 | Results are printed to stdout for each dimension in the label vector. 36 | Predictive accuracy is reported for nominal labels, and mean-squared-error 37 | is reported for continuous labels. 38 | 39 | -seed [value] 40 | Specify a seed for the random number generator. (Use this option to 41 | ensure that your results are reproduceable.) 42 | -trainratio [value] 43 | -------------------------------------------------------------------------------- /tests/01_input.txt: -------------------------------------------------------------------------------- 1 | Script started on Thu 03 Nov 2011 02:20:51 PM EDT 2 | To run a command as administrator (user "root"), use "sudo ". 3 | See "man sudo_root" for details. 4 | 5 | ]0;eric@protein: ~/Dropbox/NMR-Training-and-Testing-Data-Sets/Synthetic Data Sets/6protein:...ta-Sets/Synthetic Data Sets/6$ sudo apt-get install doxygen./regenerate_api_docs.bash [4@commandpushd ../web/waffles_learn chmod og-rw ../lib/ ../bin/sudo make installchmod o+rw ../binsudo make installchmod o+rw ../binsudo make installchmod og-rw ../lib/ ../bin/waffles_learn pushd ../web/./regenerate_command_docs.bash apisudo apt-get install doxygenmv foo65.arff trutwo_spectra_65_window.ar rfff  6 | ls -l *.arff 7 | -rw-r--r-- 1 eric bioinf 2304095 2011-11-03 14:06 foo33.arff 8 | -rw-r--r-- 1 eric bioinf 4373673 2011-11-03 13:47 foo65.arff 9 | -rw-r--r-- 1 eric bioinf 1139290 2011-11-03 13:41 foo.arff 10 | ]0;eric@protein: ~/Dropbox/NMR-Training-and-Testing-Data-Sets/Synthetic Data Sets/6protein:...ta-Sets/Synthetic Data Sets/6$ ls -l *.arffh *.arff 11 | -rw-r--r-- 1 eric bioinf 2.2M 2011-11-03 14:06 foo33.arff 12 | -rw-r--r-- 1 eric bioinf 4.2M 2011-11-03 13:47 foo65.arff 13 | -rw-r--r-- 1 eric bioinf 1.1M 2011-11-03 13:41 foo.arff 14 | ]0;eric@protein: ~/Dropbox/NMR-Training-and-Testing-Data-Sets/Synthetic Data Sets/6protein:...ta-Sets/Synthetic Data Sets/6$ rm foo.arff 15 | ]0;eric@protein: ~/Dropbox/NMR-Training-and-Testing-Data-Sets/Synthetic Data Sets/6protein:...ta-Sets/Synthetic Data Sets/6$ mkdir ~/DataANN_Data 16 | ]0;eric@protein: ~/Dropbox/NMR-Training-and-Testing-Data-Sets/Synthetic Data Sets/6protein:...ta-Sets/Synthetic Data Sets/6$ rmdir ~/ANN_)Data/ 17 | ]0;eric@protein: ~/Dropbox/NMR-Training-and-Testing-Data-Sets/Synthetic Data Sets/6protein:...ta-Sets/Synthetic Data Sets/6$ mkdir ~/PkFindData 18 | ]0;eric@protein: ~/Dropbox/NMR-Training-and-Testing-Data-Sets/Synthetic Data Sets/6protein:...ta-Sets/Synthetic Data Sets/6$ mv foo33.arff ~~/PkFindData/two_spectra _window_33.arff 19 | ]0;eric@protein: ~/Dropbox/NMR-Training-and-Testing-Data-Sets/Synthetic Data Sets/6protein:...ta-Sets/Synthetic Data Sets/6$ mv foo365.arff ~/PkFindData/two_spectra _window_65.arff 20 | ]0;eric@protein: ~/Dropbox/NMR-Training-and-Testing-Data-Sets/Synthetic Data Sets/6protein:...ta-Sets/Synthetic Data Sets/6$ pushd ~/PkFindData/ 21 | ~/PkFindData ~/Dropbox/NMR-Training-and-Testing-Data-Sets/Synthetic Data Sets/6 22 | ]0;eric@protein: ~/PkFindDataprotein:~/PkFindData$ waffles_learn splittest -reps 10 -stddev -trainratio .7 fo o33.arff -ignore 0,34,35 -labels 36 neuralnet  23 |   - protein:~/PkFindData$  -i protein:~/PkFindData$ t -[1@i protein:~/PkFindData$ w [1@- neu[7@ralnet   - protein:~/PkFindData$  -i protein:~/PkFindData$ t -[1@i protein:~/PkFindData$ w [1@- neu[7@ralnet   - protein:~/PkFindData$  -i protein:~/PkFindData$ Err[42@or:_Unexpected_token,_0,34,35,_in_arg_8 -i^C 24 | ]0;eric@protein: ~/PkFindDataprotein:~/PkFindData$ pushd ~/PkFindData/waffles_learn splittest -reps 10 -stddev -trainratio .7 fo o33.arff -ignore 0,34,35 -labels 36 neuralnet 25 | _________________________________ 26 | File not found: foo33.arff 27 | 28 | Brief Usage Information: 29 | 30 | waffles_learn splittest [dataset] [algorithm] 31 | This shuffles the data, then splits it into two parts, trains with one part, 32 | and tests with the other. (This also works with model-free algorithms.) 33 | Results are printed to stdout for each dimension in the label vector. 34 | Predictive accuracy is reported for nominal labels, and mean-squared-error 35 | is reported for continuous labels. 36 | 37 | -seed [value] 38 | Specify a seed for the random number generator. (Use this option to 39 | ensure that your results are reproduceable.) 40 | -trainratio [value] 41 | -------------------------------------------------------------------------------- /tests/02_tabs_expected_output.txt: -------------------------------------------------------------------------------- 1 | Thethe plain in spain lies mainly 2 | on 3 | -------------------------------------------------------------------------------- /tests/02_tabs_input.txt: -------------------------------------------------------------------------------- 1 | The rain in spain lies mainly 2 | on the plain 3 | 4 | -------------------------------------------------------------------------------- /tests/03_tabs_expected_output.txt: -------------------------------------------------------------------------------- 1 | The rain the plainlies mainly 2 | on 3 | -------------------------------------------------------------------------------- /tests/03_tabs_input.txt: -------------------------------------------------------------------------------- 1 | The rain in spain lies mainly 2 | on  the plain 3 | 4 | -------------------------------------------------------------------------------- /tests/04_esc_D_expected_output.txt: -------------------------------------------------------------------------------- 1 | The rain 2 | in spain 3 | -------------------------------------------------------------------------------- /tests/04_esc_D_input.txt: -------------------------------------------------------------------------------- 1 | The rainDin spain 2 | -------------------------------------------------------------------------------- /tests/05_esc_E_expected_output.txt: -------------------------------------------------------------------------------- 1 | The rain 2 | in spain 3 | -------------------------------------------------------------------------------- /tests/05_esc_E_input.txt: -------------------------------------------------------------------------------- 1 | The rainEin spain 2 | -------------------------------------------------------------------------------- /tests/06_esc_M_expected_output.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 in spain 4 | 5The rain 5 | 6 6 | 7 7 | -------------------------------------------------------------------------------- /tests/06_esc_M_input.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | 4The rainMin spain 5 | 5 6 | 6 7 | 7 8 | -------------------------------------------------------------------------------- /tests/07_OSC_0_setwi_expected_output.txt: -------------------------------------------------------------------------------- 1 | Script started on Thu 03 Nov 2011 02:20:51 PM EDT 2 | To run a command as administrator (user "root"), use "sudo ". 3 | See "man sudo_root" for details. 4 | 5 | Here we have 6 | the rain in spain again. 7 | -------------------------------------------------------------------------------- /tests/07_OSC_0_setwi_input.txt: -------------------------------------------------------------------------------- 1 | Script started on Thu 03 Nov 2011 02:20:51 PM EDT 2 | To run a command as administrator (user "root"), use "sudo ". 3 | See "man sudo_root" for details. 4 | 5 | ]0;eric@protein: ~/Dropbox/NMR-Training-and-Testing-Data-Sets/Synthetic Data Sets/6Here we have 6 | the rain in spain again. 7 | -------------------------------------------------------------------------------- /tests/08_insert_blank_expected_output.txt: -------------------------------------------------------------------------------- 1 | Some lettersThe letters start now 2 | -------------------------------------------------------------------------------- /tests/08_insert_blank_input.txt: -------------------------------------------------------------------------------- 1 | Some letters[4@The letters start now 2 | -------------------------------------------------------------------------------- /tests/09_insert_blank_expected_output.txt: -------------------------------------------------------------------------------- 1 | SomeXXXXXletters 2 | -------------------------------------------------------------------------------- /tests/09_insert_blank_input.txt: -------------------------------------------------------------------------------- 1 | Some letters[4@XXXXX 2 | -------------------------------------------------------------------------------- /tests/10_insert_blank_expected_output.txt: -------------------------------------------------------------------------------- 1 | SomeXXXXX letters 2 | -------------------------------------------------------------------------------- /tests/10_insert_blank_input.txt: -------------------------------------------------------------------------------- 1 | Some letters[8@XXXXX 2 | -------------------------------------------------------------------------------- /tests/11_insert_blank_expected_output.txt: -------------------------------------------------------------------------------- 1 | SomeXXXXXters 2 | -------------------------------------------------------------------------------- /tests/11_insert_blank_input.txt: -------------------------------------------------------------------------------- 1 | Some letters[@XXXXX 2 | -------------------------------------------------------------------------------- /tests/12_CSI_A_expected_output.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3This is cursor up 5 4 | 4 5 | 5 6 | 6 7 | 7 8 | 8 9 | -------------------------------------------------------------------------------- /tests/12_CSI_A_input.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | 4 5 | 5 6 | 6 7 | 7 8 | 8This is cursor up 5 9 | -------------------------------------------------------------------------------- /tests/13_CSI_A_expected_output.txt: -------------------------------------------------------------------------------- 1 | This is cursor up 5 with nothing above 2 | 1 3 | 2 4 | 3 5 | 4 6 | 5 7 | 6 8 | -------------------------------------------------------------------------------- /tests/13_CSI_A_input.txt: -------------------------------------------------------------------------------- 1 | This is cursor up 5 with nothing above 2 | 1 3 | 2 4 | 3 5 | 4 6 | 5 7 | 6 8 | -------------------------------------------------------------------------------- /tests/14_CSI_A_expected_output.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3ABCDE This is cursor up 5 with some preceeding characters 4 | 4AB 5 | 5AB 6 | 6AB 7 | 7AB 8 | 8ABCDEF 9 | -------------------------------------------------------------------------------- /tests/14_CSI_A_input.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3ABCDE 4 | 4AB 5 | 5AB 6 | 6AB 7 | 7AB 8 | 8ABCDEFThis is cursor up 5 with some preceeding characters 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /tests/15_CSI_A_expected_output.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3ABCDE 4 | 4AB This is cursor up 4 with some preceeding characters 5 | 5ABC 6 | 6A 7 | 7AB 8 | 8ABCDEF 9 | 10 | -------------------------------------------------------------------------------- /tests/15_CSI_A_input.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3ABCDE 4 | 4AB 5 | 5ABC 6 | 6A 7 | 7AB 8 | 8ABCDEFThis is cursor up 4 with some preceeding characters 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /tests/16_CSI_AB_expected_output.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3ABCDE 4 | 4AB 5 | 5ABC This is cursor up 4 then down 1 with preceeding characters 6 | 6A 7 | 7AB 8 | 8ABCDEF 9 | 10 | 11 | -------------------------------------------------------------------------------- /tests/16_CSI_AB_input.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3ABCDE 4 | 4AB 5 | 5ABC 6 | 6A 7 | 7AB 8 | 8ABCDEFThis is cursor up 4 then down 1 with preceeding characters 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /tests/17_CSI_B_expected_output.txt: -------------------------------------------------------------------------------- 1 | Cursor down at end of textText between cursor down and newline 2 | Next line 3 | -------------------------------------------------------------------------------- /tests/17_CSI_B_input.txt: -------------------------------------------------------------------------------- 1 | Cursor down at end of textText between cursor down and newline 2 | Next line 3 | -------------------------------------------------------------------------------- /tests/18_CSI_B_expected_output.txt: -------------------------------------------------------------------------------- 1 | 1Cursor down in middle of text 2 | 2 Text between cursor down and newline 3 | 4Text after newline 4 | -------------------------------------------------------------------------------- /tests/18_CSI_B_input.txt: -------------------------------------------------------------------------------- 1 | 1Cursor down in middle of text 2 | 2 3 | 3Should not appearText between cursor down and newline 4 | 4Text after newline 5 | -------------------------------------------------------------------------------- /tests/19_CSI_C_expected_output.txt: -------------------------------------------------------------------------------- 1 | Cursor right 5 at end of text Text after the command 2 | -------------------------------------------------------------------------------- /tests/19_CSI_C_input.txt: -------------------------------------------------------------------------------- 1 | Cursor right 5 at end of textText after the command 2 | -------------------------------------------------------------------------------- /tests/20_CSI_C_expected_output.txt: -------------------------------------------------------------------------------- 1 | Text after cursor right 5 at the beginning of the line 2 | -------------------------------------------------------------------------------- /tests/20_CSI_C_input.txt: -------------------------------------------------------------------------------- 1 | Text after cursor right 5 at the beginning of the line 2 | -------------------------------------------------------------------------------- /tests/21_CSI_P_expected_output.txt: -------------------------------------------------------------------------------- 1 | Script started on Thu 03 Nov 2011 02:20:51 PM EDT 2 | To run a command as administrator (user "root"), use "sudo ". 3 | See "man sudo_root" for details. 4 | 5 | protein:...ta-Sets/Synthetic Data Sets/6$ ./regenerate_api_docs.bashn 6 | -------------------------------------------------------------------------------- /tests/21_CSI_P_input.txt: -------------------------------------------------------------------------------- 1 | Script started on Thu 03 Nov 2011 02:20:51 PM EDT 2 | To run a command as administrator (user "root"), use "sudo ". 3 | See "man sudo_root" for details. 4 | 5 | ]0;eric@protein: ~/Dropbox/NMR-Training-and-Testing-Data-Sets/Synthetic Data Sets/6protein:...ta-Sets/Synthetic Data Sets/6$ sudo apt-get install doxygen./regenerate_api_docs.bash 6 | -------------------------------------------------------------------------------- /tests/22_CSI_P_expected_output.txt: -------------------------------------------------------------------------------- 1 | Deleting when there is nothing to delete 2 | -------------------------------------------------------------------------------- /tests/22_CSI_P_input.txt: -------------------------------------------------------------------------------- 1 | Deleting when there is nothing to delete 2 | -------------------------------------------------------------------------------- /tests/23_CSI_P_expected_output.txt: -------------------------------------------------------------------------------- 1 | Deleting past end of 2 | Characters after deletion 3 | -------------------------------------------------------------------------------- /tests/23_CSI_P_input.txt: -------------------------------------------------------------------------------- 1 | Deleting past end of line 2 | Characters after deletion 3 | -------------------------------------------------------------------------------- /tests/24_CSI_P_expected_output.txt: -------------------------------------------------------------------------------- 1 | Deleting past end of 2 | Characters after deletion 3 | -------------------------------------------------------------------------------- /tests/24_CSI_P_input.txt: -------------------------------------------------------------------------------- 1 | Deleting past end of line 2 | Characters after deletion 3 | 4 | -------------------------------------------------------------------------------- /tests/25_CSI_K_expected_output.txt: -------------------------------------------------------------------------------- 1 | 0123456789 2 | 0123456789Text after the erasure and down 3 | -------------------------------------------------------------------------------- /tests/25_CSI_K_input.txt: -------------------------------------------------------------------------------- 1 | 0123456789ABCDEF 2 | 0123456789ABCDEFText after the erasure and down 3 | -------------------------------------------------------------------------------- /tests/26_CSI_K_expected_output.txt: -------------------------------------------------------------------------------- 1 | BCDEF 2 | 0123456789Text after the erasure and down 3 | -------------------------------------------------------------------------------- /tests/26_CSI_K_input.txt: -------------------------------------------------------------------------------- 1 | 0123456789ABCDEF 2 | 0123456789ABCDEFText after the erasure and down 3 | -------------------------------------------------------------------------------- /tests/27_CSI_K_expected_output.txt: -------------------------------------------------------------------------------- 1 | 2 | 0123456789Text after the erasure and down 3 | -------------------------------------------------------------------------------- /tests/27_CSI_K_input.txt: -------------------------------------------------------------------------------- 1 | 0123456789ABCDEF 2 | 0123456789ABCDEFText after the erasure and down 3 | -------------------------------------------------------------------------------- /tests/28_CSI_K_expected_output.txt: -------------------------------------------------------------------------------- 1 | Text after the erasure 2 | Text after the erasure and down 3 | -------------------------------------------------------------------------------- /tests/28_CSI_K_input.txt: -------------------------------------------------------------------------------- 1 | STUFF 2 | Text after the erasureText after the erasure and down 3 | -------------------------------------------------------------------------------- /tests/29_CSI_K_expected_output.txt: -------------------------------------------------------------------------------- 1 | 2 | Text after the erasure and down 3 | -------------------------------------------------------------------------------- /tests/29_CSI_K_input.txt: -------------------------------------------------------------------------------- 1 | STUFF 2 | Text after the erasure and down 3 | -------------------------------------------------------------------------------- /tests/30_CSI_K_expected_output.txt: -------------------------------------------------------------------------------- 1 | 2 | Text after the erasure and down 3 | -------------------------------------------------------------------------------- /tests/30_CSI_K_input.txt: -------------------------------------------------------------------------------- 1 | STUFF 2 | Text after the erasure and down 3 | -------------------------------------------------------------------------------- /tests/31_raw_expected_output.txt: -------------------------------------------------------------------------------- 1 | Script started on Thu 03 Nov 2011 02:20:51 PM EDT 2 | To run a command as administrator (user "root"), use "sudo ". 3 | See "man sudo_root" for details. 4 | 5 | protein:...ta-Sets/Synthetic Data Sets/6$ mv foo65.arff two_spectra_65_window.ar 6 | rf 7 | -------------------------------------------------------------------------------- /tests/31_raw_input.txt: -------------------------------------------------------------------------------- 1 | Script started on Thu 03 Nov 2011 02:20:51 PM EDT 2 | To run a command as administrator (user "root"), use "sudo ". 3 | See "man sudo_root" for details. 4 | 5 | ]0;eric@protein: ~/Dropbox/NMR-Training-and-Testing-Data-Sets/Synthetic Data Sets/6protein:...ta-Sets/Synthetic Data Sets/6$ sudo apt-get install doxygen./regenerate_api_docs.bash [4@commandpushd ../web/waffles_learn chmod og-rw ../lib/ ../bin/sudo make installchmod o+rw ../binsudo make installchmod o+rw ../binsudo make installchmod og-rw ../lib/ ../bin/waffles_learn pushd ../web/./regenerate_command_docs.bash apisudo apt-get install doxygenmv foo65.arff trutwo_spectra_65_window.ar rf 6 | -------------------------------------------------------------------------------- /tests/32_raw_expected_output.txt: -------------------------------------------------------------------------------- 1 | Script started on Thu 03 Nov 2011 02:20:51 PM EDT 2 | To run a command as administrator (user "root"), use "sudo ". 3 | See "man sudo_root" for details. 4 | 5 | Some_text_to_show_where_we_areata Sets/6$ mv foo65.arff two_spectra_65_window.ar 6 | 7 | 8 | 3 9 | 4 10 | 5 11 | -------------------------------------------------------------------------------- /tests/32_raw_input.txt: -------------------------------------------------------------------------------- 1 | Script started on Thu 03 Nov 2011 02:20:51 PM EDT 2 | To run a command as administrator (user "root"), use "sudo ". 3 | See "man sudo_root" for details. 4 | 5 | ]0;eric@protein: ~/Dropbox/NMR-Training-and-Testing-Data-Sets/Synthetic Data Sets/6protein:...ta-Sets/Synthetic Data Sets/6$ sudo apt-get install doxygen./regenerate_api_docs.bash [4@commandpushd ../web/waffles_learn chmod og-rw ../lib/ ../bin/sudo make installchmod o+rw ../binsudo make installchmod o+rw ../binsudo make installchmod og-rw ../lib/ ../bin/waffles_learn pushd ../web/./regenerate_command_docs.bash apisudo apt-get install doxygenmv foo65.arff trutwo_spectra_65_window.ar rfff Some_text_to_show_where_we_are 6 | 7 | 8 | 3 9 | 4 10 | 5 11 | -------------------------------------------------------------------------------- /typescript2txt.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * "man script" reports the following bug 3 | * 4 | * Script places everything in the log file, including linefeeds and backspaces. This is not what the naive user expects. 5 | * 6 | * This program converts a script file back into a normal text file 7 | * 8 | * USAGE: typescript2txt < script_output > script.txt 9 | * 10 | * Although this does not handle all possible xterm output, it appears 11 | * to work fairly well for normal output from bash etc. 12 | * It also works well for linuxterms. 13 | * 14 | * http://www.kitebird.com/csh-tcsh-book/ctlseqs.pdf 15 | * documents other xterm commands that could be handled. 16 | * 17 | * The rewrite was accomplished mainly by referring to 18 | * http://unixhelp.ed.ac.uk/CGI/man-cgi?console_codes+4 and 19 | * http://www.kernel.org/doc/man-pages/online/pages/man4/console_codes.4.html 20 | * which can be seen in many linux distros as man console_codes 21 | * 22 | * It would be easy to support colours if we outputted to e.g. HTML. 23 | * 24 | * John C. McCabe-Dansted (gmatht@gmail.com) 2008 25 | * 26 | * Completely rewritten in C++ by Eric Moyer in 2011 27 | * 28 | * Permission is granted to distribute this software under any version 29 | * of the BSD and GPL licenses. 30 | *******************************************************************/ 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | /// Reads typescript output for a linuxterm (and maybe xterm?) and 43 | /// recreates what would be on a very long screen (long enough to hold 44 | /// everything in the file), ignoring color and other formatting 45 | /// characters 46 | class Reader{ 47 | /// The lines that will be output. 48 | std::vector > lines; 49 | /// The index of the cur 50 | std::size_t line_idx; 51 | /// The index of the cursor on the current line, where the next 52 | /// character will be written. May be (and very frequently is) one past 53 | /// the end of the line. 54 | std::size_t char_idx; 55 | 56 | /// The width (in characters) of the terminal that this Reader emulates 57 | const static std::size_t width = 80; 58 | 59 | /// The parameters that are used for the CSI sequences - also used 60 | /// by some of the OSC commands 61 | std::vector params; 62 | 63 | /// Enum to specify the different states the reader can be in 64 | enum RState{ 65 | SAW_NOTHING, 66 | SAW_ESC, ///ESC ( ^] ) was seen (but no trailing ] or [ ) 67 | SAW_CSI, ///Control sequence introducer - ESC [ or 0x9B 68 | SAW_OSC, ///Operating system command ESC ] 69 | SAW_OSC_EAT_2_BEL, ///Ignore all characters until ^G in OSC 70 | SAW_OSC_4, ///OSC followed by a 4 71 | SAW_OSC_5, ///OSC followed by a 5 72 | SAW_OSC_P, ///ESC ] P (will read 7 hex digits) 73 | SAW_ESC_NUM, /// ESC # 74 | SAW_ESC_PCT, /// ESC % 75 | SAW_ESC_LPAREN,/// ESC ( 76 | SAW_ESC_RPAREN, /// ESC ) 77 | SAW_CSI_LBRACKET /// ESC [ [ or CSI [ (just eats next char) 78 | }; 79 | 80 | /// The current state of the reader (in escape code etc.) 81 | RState state; 82 | 83 | /// Return the current line 84 | std::vector& cur_line(){ return lines.at(line_idx); } 85 | 86 | /// Perform a line-feed, adding blank lines and spaces if necessary 87 | void line_feed(){ 88 | ++line_idx; 89 | while(line_idx >= lines.size()) { 90 | lines.push_back(std::vector()); 91 | } 92 | while(char_idx > cur_line().size()){ 93 | cur_line().push_back(' '); 94 | } 95 | } 96 | 97 | /// Perform a reverse line-feed - go up one line 98 | void reverse_line_feed(){ 99 | if(line_idx > 0){ 100 | --line_idx; 101 | }else{ 102 | assert(line_idx == 0); //line_idx should never be negative 103 | lines.insert(lines.begin(),std::vector()); 104 | } 105 | while(char_idx > cur_line().size()){ 106 | cur_line().push_back(' '); 107 | } 108 | } 109 | 110 | /// Perform a tab: position the cursor at the next tab stop 111 | /// 112 | /// Since tab-stops cannot be set right now, just puts the cursor at 113 | /// the next multiple of 8 114 | void tab(){ 115 | char_idx += (8-(char_idx%8))%8; 116 | } 117 | 118 | /// Perform a carriage return - put the current character index at the beginning of the line 119 | void carriage_return(){ 120 | char_idx = 0; 121 | } 122 | 123 | /// Perform a back-space - move back over previous character 124 | void back_space(){ 125 | if(char_idx > 0){ 126 | --char_idx; 127 | } 128 | } 129 | 130 | /// Insert the given character at the current position, not moving 131 | /// 132 | /// Inserts \a c at the current position. Does not change the 133 | /// current position. If the current character is beyond the end of 134 | /// the line, inserts enough spaces so that the character is written 135 | /// at the correct position. 136 | /// 137 | /// \param c The character to insert 138 | void insert_char(char c){ 139 | while(char_idx > cur_line().size()){ 140 | cur_line().push_back(' '); 141 | } 142 | assert(char_idx <= cur_line().size()); 143 | if(char_idx == cur_line().size()){ 144 | cur_line().push_back(c); 145 | }else if(char_idx < cur_line().size()){ 146 | cur_line().insert(char_idx + cur_line().begin(), c); 147 | }else{ 148 | std::cerr << "SERIOUS WARNING: Impossible value for char_idx " 149 | << "in insert_char. Ignoring.\n" 150 | << issue_report_boilerplate(); 151 | } 152 | } 153 | 154 | /// Set the current character to \a c and advance to the next 155 | /// 156 | /// Sets the character a the current position to \a c then advances 157 | /// the current character to the next position. If the current 158 | /// character is beyond the end of the line, inserts enough spaces 159 | /// so that the character is written at the correct position. 160 | /// 161 | /// \param c The new value of the character at the current position 162 | void put_char(char c){ 163 | if(char_idx >= width){ 164 | std::cerr << "Warning: cursor beyond bounds of window in put_char."; 165 | char_idx = width - 1; 166 | } 167 | while(char_idx > cur_line().size()){ 168 | cur_line().push_back(' '); 169 | } 170 | assert(char_idx <= cur_line().size()); 171 | if(char_idx == cur_line().size()){ 172 | cur_line().push_back(c); 173 | ++char_idx; 174 | if(char_idx >= width){ 175 | carriage_return(); line_feed(); 176 | } 177 | }else if(char_idx < cur_line().size()){ 178 | cur_line().at(char_idx) = c; 179 | ++char_idx; 180 | if(char_idx >= width){ 181 | carriage_return(); line_feed(); 182 | } 183 | }else{ 184 | std::cerr << "SERIOUS WARNING: Impossible value for char_idx " 185 | << "in put_char. Ignoring.\n" 186 | << issue_report_boilerplate(); 187 | } 188 | } 189 | 190 | /// Set the state to new_state and clear parameter array 191 | /// 192 | /// Sets the state of the reader to new_state and (since the 193 | /// parameter array is in one sense part of the command reading 194 | /// state) clear that array. 195 | /// 196 | /// \param new_state the new state of the reader after set_state 197 | void set_state(RState new_state){ 198 | state = new_state; 199 | params.clear(); 200 | } 201 | 202 | 203 | /// Print a warning about \a c whose meaning is unknown in the given context 204 | /// 205 | /// \param context a string describing the context in which \c is unknown 206 | /// 207 | /// \param c the character whose meaning is unknown in the given context 208 | void unknown_code(std::string context, unsigned char c){ 209 | using std::cerr; 210 | cerr << "Warning: the meaning of the character '"; 211 | if(!isprint(c)){ 212 | if(c < 0x20){ 213 | cerr << '^' << (c+'@'); 214 | }else{ 215 | if(c == 0x7F){ 216 | cerr << "DEL"; 217 | }else{ 218 | cerr << "Unknown char"; 219 | } 220 | } 221 | cerr << "' (" << ((unsigned int)c) << " decimal) "; 222 | }else{ 223 | cerr << c << "' "; 224 | } 225 | cerr << "is unknown in the context of a " << context << ".\n"; 226 | } 227 | 228 | /// Return true if the given char is a control character (and process it) 229 | /// 230 | /// If \a c is a control character, changes the reader's state to 231 | /// reflect its having been received and returns true. Otherwise, 232 | /// does nothing and returns false. 233 | /// 234 | /// \param c the character to identify and process 235 | /// 236 | /// \return true if c is a control character, false otherwise 237 | bool id_and_process_control_char(unsigned char c){ 238 | if(c >= 0x20 && c != 0x7F && c != 0x9B){ return false; } 239 | c = c+'@'; //Make c into a printable character for easier coding 240 | switch(c){ 241 | case 'G': return true; 242 | case 'H': back_space(); return true; 243 | case 'I': tab(); return true; 244 | case 'J': case 'K': case 'L':carriage_return(); line_feed(); return true; 245 | case 'M': carriage_return(); return true; 246 | case 'N': character_set(1); return true; 247 | case 'O': character_set(0); return true; 248 | case 'X': case 'Z': set_state(SAW_NOTHING); return true; 249 | case '[': set_state(SAW_ESC); return true; 250 | case (0x7F+'@'): /*DEL=0x7F*/ return true; 251 | case (0x9B+'@'): /*CSI=0x9B*/ set_state(SAW_CSI); return true; 252 | default: return false; 253 | } 254 | } 255 | 256 | 257 | /// Performs the insert blank CSI command ESC [ ... @ 258 | /// 259 | /// If not at the end of a line, inserts the number of blanks 260 | /// required by \a param. 261 | /// 262 | /// At the end of a line, does nothing. 263 | /// 264 | /// \param params is an array with the parameters passed to the 265 | /// command. If no parameters are given, inserts one 266 | /// blank. Otherwise, inserts as many blanks as the 267 | /// value of the first parameter. Prints a warning if 268 | /// there is more than one parameter. 269 | void insert_blank(std::vector params){ 270 | if(params.size() == 0){ 271 | params.push_back(1); 272 | }else if(params.size() > 1){ 273 | std::cerr << "Warning: too many arguments given to insert " 274 | << "blank CSI command ESC [ ... @\n" 275 | << "Ignoring extra parameters\n"; 276 | } 277 | if(char_idx >= cur_line().size()){ 278 | return; 279 | } 280 | for(unsigned b = 0; b < params.front(); ++b){ 281 | insert_char(' '); 282 | } 283 | } 284 | 285 | /// Performs the cursor up CSI command ESC [ ... A 286 | /// 287 | /// Moves the cursor up the number of lines required by \a param. 288 | /// Does not make new lines above the first line. 289 | /// 290 | /// \param params is an array with the parameters passed to the 291 | /// command. If no parameters are given, goes up one 292 | /// line blank. Otherwise, goes up as many lines as 293 | /// the value of the first parameter. Prints a 294 | /// warning if there is more than one parameter. Does 295 | /// not go above the first line 296 | void cursor_up(std::vector params){ 297 | if(params.size() == 0){ 298 | params.push_back(1); 299 | }else if(params.size() > 1){ 300 | std::cerr << "Warning: too many arguments given to cursor up " 301 | << "CSI command ESC [ ... A\n" 302 | << "Ignoring extra parameters\n"; 303 | } 304 | if(line_idx > params.front()){ 305 | line_idx -= params.front(); 306 | }else{ 307 | line_idx = 0; 308 | } 309 | } 310 | 311 | /// Performs the cursor down CSI command ESC [ ... B 312 | /// 313 | /// Moves the cursor down the number of lines required by \a param. 314 | /// Does not make new lines below the last line. 315 | /// 316 | /// \param params is an array with the parameters passed to the 317 | /// command. If no parameters are given, goes down one 318 | /// line. Otherwise, goes down as many lines as 319 | /// the value of the first parameter. Prints a 320 | /// warning if there is more than one parameter. Does 321 | /// not go above the first line 322 | void cursor_down(std::vector params){ 323 | if(params.size() == 0){ 324 | params.push_back(1); 325 | }else if(params.size() > 1){ 326 | std::cerr << "Warning: too many arguments given to cursor down " 327 | << "CSI command ESC [ ... A\n" 328 | << "Ignoring extra parameters\n"; 329 | } 330 | if(line_idx + params.front() < lines.size()){ 331 | line_idx += params.front(); 332 | }else{ 333 | line_idx = params.size() - 1; 334 | } 335 | } 336 | 337 | /// Performs the cursor right CSI command ESC [ ... C 338 | /// 339 | /// Moves the cursor right the number of columns required by \a 340 | /// param. 341 | /// 342 | /// 343 | /// \param params is an array with the parameters passed to the 344 | /// command. If no parameters are given, goes right one 345 | /// column. Otherwise, goes right as many columns as 346 | /// the value of the first parameter. Prints a 347 | /// warning if there is more than one parameter. 348 | void cursor_right(std::vector params){ 349 | if(params.size() == 0){ 350 | params.push_back(1); 351 | }else if(params.size() > 1){ 352 | std::cerr << "Warning: too many arguments given to cursor right " 353 | << "CSI command ESC [ ... A\n" 354 | << "Ignoring extra parameters\n"; 355 | } 356 | char_idx += params.front(); 357 | } 358 | 359 | /// Performs the delete characters CSI command ESC [ ... P 360 | /// 361 | /// Removes the number of characters indicated by \a params from the 362 | /// line to the right of the current cursor location. Shifts all 363 | /// characters after the one to delete to the left to fill in the gap. 364 | /// If the cursor is past the end of the line, does nothing. 365 | /// 366 | /// \param params is an array with the parameters passed to the 367 | /// command. If no parameters are given, deletes one 368 | /// character. Otherwise, deletes as many characters 369 | /// as the value of the first parameter. Prints a 370 | /// warning if there is more than one parameter. 371 | void delete_characters(std::vector params){ 372 | if(params.size() == 0){ 373 | params.push_back(1); 374 | }else if(params.size() > 1){ 375 | std::cerr << "Warning: too many arguments given to delete characters " 376 | << "CSI command ESC [ ... P\n" 377 | << "Ignoring extra parameters\n"; 378 | } 379 | if(params.front() > 0){ 380 | if(char_idx < cur_line().size()){ 381 | unsigned chars_to_right = cur_line().size() - char_idx; 382 | unsigned chars_to_delete = std::min(chars_to_right, params.front()); 383 | std::vector::iterator del_first = cur_line().begin()+char_idx; 384 | std::vector::iterator del_end = del_first + chars_to_delete; 385 | cur_line().erase(del_first, del_end); 386 | } 387 | } 388 | } 389 | 390 | /// Performs the erase line CSI command ESC [ ... K 391 | /// 392 | /// If the parameters array is empty removes all characters in 393 | /// cur_line() at or after char_idx. 394 | /// 395 | /// If the parameters array holds at least one value, then the first 396 | /// value must be 1 or 2. If the first value is neither 1 or 2, 397 | /// then prints a warning and does nothing. 398 | /// 399 | /// If the first value is 1, the behavior depends on whether 400 | /// char_idx is past the end of the line. If there are characters 401 | /// past char_idx in the line, fills all characters from the 402 | /// beginning of the line to char_idx (inclusive) with blanks. 403 | /// Otherwise the behavior is identical to if the param value had 404 | /// been 2. 405 | /// 406 | /// If the first value is 2, deletes all characters in the array, 407 | /// but leaves char_idx the same. 408 | /// 409 | /// If there is more than one argument, prints a warning 410 | /// 411 | /// \param params The parameters passed to the CSI K command - see 412 | /// the main text for a description of behavior 413 | void erase_line(std::vector params){ 414 | if(params.size() == 0){ 415 | if(char_idx < cur_line().size()){ 416 | std::vector::iterator erasure_start = cur_line().begin()+char_idx; 417 | cur_line().erase(erasure_start, cur_line().end()); 418 | } 419 | }else{ 420 | if(params.size() > 1){ 421 | std::cerr << "Warning: too many arguments given to erase line " 422 | << "CSI command ESC [ ... K\n" 423 | << "Ignoring extra parameters\n"; 424 | } 425 | unsigned p = params.front(); 426 | if(p != 1 && p != 2){ 427 | std::cerr << "Warning: argument " << p << " passed to erase line " 428 | << "CSI command ESC [ ... K\n" 429 | << "The meaning of this argument is unknown. " 430 | << "Doing nothing.\n"; 431 | return; 432 | } 433 | if(p == 2 || (char_idx + 1) >= cur_line().size()){ 434 | //Delete whole line: 435 | //Param was 2 or we are at or past the last character in the line 436 | cur_line().clear(); 437 | return; 438 | }else{ 439 | //Delete chars before and at char_idx when there is at least 440 | //one character that won't be deleted 441 | assert(p == 1); 442 | assert(char_idx + 1 < cur_line().size()); 443 | std::vector::iterator erasure_start = cur_line().begin(); 444 | std::fill(erasure_start, erasure_start + char_idx + 1, ' '); 445 | return; 446 | } 447 | } 448 | } 449 | 450 | /// \brief Return a string containing instructions for reporting an issue 451 | /// \brief with the program 452 | /// 453 | /// \return a string containing instructions for reporting an issue 454 | /// with the program 455 | char const * issue_report_boilerplate(){ 456 | return "Please submit an issue report to " 457 | "https://github.com/RadixSeven/typescript2txt/issues " 458 | "and include the file you were processing by following the instructions " 459 | "in https://github.com/ned14/Easyshop/issues/1\n"; 460 | } 461 | 462 | 463 | /// Do nothing 464 | /// 465 | /// This function is called to document that a CSI command is 466 | /// intentionally not implemented because it is not appropriate to 467 | /// generating plain text files. 468 | void ignore_CSI(){ } 469 | 470 | 471 | //################################################### 472 | //################################################### 473 | //### Unimplemented Codes That Generate Warnings 474 | //################################################### 475 | //################################################### 476 | 477 | /// Print a warning that the given CSI command is unimplemented 478 | /// 479 | /// Unlike the regular escape codes which all have different 480 | /// structrues, I can use a generic warning routine because of the 481 | /// simple structure of the CSI codes: list of parameters followed 482 | /// by an action character. 483 | /// 484 | /// This warning lets a programmer just implement the codes needed 485 | /// to parse his files and ignore the rest. 486 | /// 487 | /// This is called for CSI codes that may impact plain text output, 488 | /// so someone may want to implement them in the future. 489 | /// 490 | /// \param code The single character command code that identifies 491 | /// the CSI command. This would be @ for insert blanks, 492 | /// A for cursor up, etc. 493 | /// 494 | /// \param descr A longer description of the code 495 | /// 496 | /// \param params The parameters that would have been passed to the code 497 | void unimplemented_CSI(char code, std::string descr, 498 | std::vector params){ 499 | std::cerr << "Warning: this typescript contains an unimplemented CSI " 500 | << "code \"ESC [ ... " << code << "\". " 501 | << "The code has description: \"" << descr << "\" and was " 502 | << "passed "; 503 | if(params.size() == 0){ 504 | std::cerr << "no parameters. "; 505 | }else{ 506 | std::cerr << "The parameters: " << params.at(0); 507 | for(std::size_t i=1; i < params.size(); ++i){ 508 | std::cerr << ", " << params.at(i); 509 | } 510 | std::cerr << ". "; 511 | } 512 | std::cerr << "Ignoring.\n"; 513 | } 514 | 515 | 516 | /// Execute character set change to \a num - just prints warning right now 517 | /// 518 | /// \param num the number of the character set to change to 519 | void character_set(int num){ 520 | std::cerr << "Warning: typescript file contains command to change to the " 521 | << "G" << num << " character set. This command is ignored by " 522 | << "this translator.\n"; 523 | } 524 | 525 | /// Set a horizontal tab stop at the current cursor position 526 | /// 527 | /// Right now, does nothing but print a warning 528 | void set_htab_stop(){ 529 | std::cerr << "Warning: typescript file contains tab-stop-changing " 530 | << "commands that are ignored by this translator.\n"; 531 | } 532 | 533 | /// Save the cursor state for later restoration 534 | /// 535 | /// Right now, does nothing but print a warning 536 | void save_cursor_state(){ 537 | std::cerr << "Warning: typescript file contains cursor-state-saving " 538 | << "commands that are ignored by this translator.\n"; 539 | } 540 | 541 | /// Restore the cursor state for later restoration 542 | /// 543 | /// Right now, does nothing but print a warning 544 | void restore_cursor_state(){ 545 | std::cerr << "Warning: typescript file contains cursor-state-restoring " 546 | << "commands that are ignored by this translator.\n"; 547 | } 548 | 549 | /// Select character set based on the given \a code which must be @,G, or 8 550 | /// 551 | /// Right now, does nothing but print a warning 552 | /// 553 | /// \param code @ selects the default (ISO 646/ISO 8859-1), G and 8 554 | /// select UTF-8 555 | void select_character_set(const char code){ 556 | assert(code == '@' || code == 'G' || code == '8'); 557 | if(code == '@'){ 558 | std::cerr << "Warning: typescript contains command to set the " 559 | << "character set to ISO 646/ISO 8859-1. This is " 560 | << "currently ignored by this translator.\n"; 561 | }else if(code == 'G' || code == '8'){ 562 | std::cerr << "Warning: typescript contains command to set the " 563 | << "character set to UTF8. This is " 564 | << "currently ignored by this translator.\n"; 565 | }else{ 566 | std::cerr << "SERIOUS WARNING: Illegal code passed to " 567 | << "select_character_set. Ignoring.\n" 568 | << issue_report_boilerplate(); 569 | return; 570 | } 571 | } 572 | 573 | /// Define the character set mapping for G0 or G1 574 | /// 575 | /// Right now does nothing but print a warning. 576 | /// 577 | /// Assumes code is one of B,0,U, or X and g_number is 0 or 1 578 | /// 579 | /// \param g_number if 0 defines, G0, if 1 defines G1 580 | /// 581 | /// \param code The character from the escape code indicating which 582 | /// mapping. From the man page: B = Select default (ISO 583 | /// 8859-1 mapping), 0 = Select VT100 graphics mapping, 584 | /// U = Select null mapping - straight to character ROM, 585 | /// K = Select user mapping - the map that is loaded by 586 | /// the utility mapscrn(8). 587 | void define_g_character_set(const unsigned g_number, const char code){ 588 | assert(code == 'B' || code == '0' || code == 'U' || code == 'K'); 589 | assert(g_number == 0 || g_number == 1); 590 | std::string mapping; 591 | switch(code){ 592 | case 'B': mapping = "ISO 8859-1"; break; 593 | case '0': mapping = "VT100 graphics"; break; 594 | case 'U': mapping = "the null mapping (straight to character ROM)"; break; 595 | case 'K': mapping = "the user mapping (loaded by mapscrn(8))"; break; 596 | default: 597 | std::cerr << "SERIOUS WARNING: Illegal code passed to " 598 | << "define_g_character_set. Ignoring." 599 | << issue_report_boilerplate(); 600 | return; 601 | } 602 | char g_char = (g_number == 0?'(':')'); 603 | std::cerr << "Warning: typescript contains command to define the G" 604 | << g_number << " character set as " << mapping << "\n" 605 | << "This command -- ESC " << g_char 606 | << ' ' << code << " -- is currently ignored by this translator."; 607 | } 608 | 609 | ///Set the palette entry at \a index to the color described by \a rgb 610 | /// 611 | /// Right now, just prints a warning 612 | /// 613 | /// \param index The index of of the palette entry to set 0-15 inclusive 614 | /// 615 | /// \param rgb The 24 bit number whose lower 3 bytes describe the 616 | /// red, green, and blue intensities in that order 617 | /// (xxxxxxxxRRRRRRRRGGGGGGGGBBBBBBBB) 618 | void set_palette(int index, int rgb){ 619 | if(rgb & 0xFF000000){ 620 | std::cerr << "SERIOUS WARNING: Illegal RGB value " 621 | << std::hex << ((unsigned)rgb) << " passed to " 622 | << "set_palette. Ignoring." 623 | << issue_report_boilerplate(); 624 | return; 625 | } 626 | if(index < 0 || index > 15){ 627 | std::cerr << "SERIOUS WARNING: Illegal index value " 628 | << index << " passed to " 629 | << "set_palette. Ignoring." 630 | << issue_report_boilerplate(); 631 | return; 632 | } 633 | int r = (rgb >> 16) & 0xFF; 634 | int g = (rgb >> 8) & 0xFF; 635 | int b = rgb & 0xFF; 636 | std::cerr << "Warning: typescript contains command to set palette " 637 | << "entry " << index << " to rgb=("<< r << ',' << g << ',' 638 | << b << ") This command is ignored by this translator.\n"; 639 | } 640 | 641 | /// Reset the palette 642 | /// 643 | /// Right now, does nothing but print a warning 644 | void reset_palette(){ 645 | std::cerr << "Warning: typescript contains command to reset the palette. " 646 | << "This command is ignored by this translator.\n"; 647 | } 648 | public: 649 | /// Create an empty reader that has read nothing 650 | Reader():line_idx(0),char_idx(0){ 651 | lines.push_back(std::vector()); 652 | } 653 | 654 | /// \brief Read from the given typescript output stream using the reader's 655 | /// \brief current state 656 | void read_from(std::istream& in); 657 | 658 | /// \brief Write the contents of this reader to the given stream 659 | /// 660 | /// The contents of the reader are the interpreted inputs it has 661 | /// read, not those inputs themselves. 662 | void write_to(std::ostream& out) const{ 663 | std::vector >::const_iterator line; 664 | for(line = lines.begin(); line != lines.end(); ++line){ 665 | std::vector >::const_iterator next_line = line; 666 | ++next_line; 667 | std::vector::const_iterator ch; 668 | for(ch = line->begin(); ch != line->end(); ++ch){ 669 | out << *ch; 670 | } 671 | //Output a newline unless this is the last line and it is blank 672 | //(meaning that it was created by a previous newline but nothing 673 | //was written to it) 674 | if(! (line->size() == 0 && next_line == lines.end()) ){ 675 | out << std::endl; 676 | } 677 | } 678 | } 679 | }; 680 | 681 | void Reader::read_from(std::istream& in){ 682 | while(in){ 683 | RState next_state = SAW_NOTHING; 684 | int tmp_val; 685 | char c = in.get(); 686 | if(in.eof()){ break; } //Don't process end of file 687 | //Process control characters unless in an operating system command 688 | //that terminates with a BEL character 689 | if(state != SAW_OSC_EAT_2_BEL){ 690 | if(id_and_process_control_char(c)){ 691 | continue; 692 | } 693 | } 694 | switch(state){ 695 | case SAW_NOTHING: 696 | put_char(c); 697 | break; 698 | case SAW_ESC: ///ESC ( ^] ) was seen (but no trailing ] or [ ) 699 | next_state = SAW_NOTHING; 700 | switch(c){ 701 | case 'c': break; //Terminal reset, do nothing 702 | case 'D': line_feed(); break; //Line feed 703 | case 'E': carriage_return(); line_feed(); break; //Newline 704 | case 'H': set_htab_stop(); break; //Set tab stop 705 | case 'M': reverse_line_feed(); break; //Reverse line feed 706 | case 'Z': break; //Ignore dec identification code request 707 | case '7': save_cursor_state(); break; //Save cursor state 708 | case '8': restore_cursor_state(); break; //Restore cursor state 709 | case '[': next_state = SAW_CSI; break; //Control sequence introducer 710 | case '%': next_state = SAW_ESC_PCT; break; //ESC % 711 | case '#': next_state = SAW_ESC_NUM; break; //ESC # 712 | case '(': next_state = SAW_ESC_LPAREN; break; //ESC ( 713 | case ')': next_state = SAW_ESC_RPAREN; break; //ESC ) 714 | case '>': break; //Ignore numeric keypad mode 715 | case '=': break; //Ignore application keypad mode 716 | case ']': next_state = SAW_OSC; break; //Operating system command 717 | default: 718 | unknown_code("escape",c); 719 | }; 720 | set_state(next_state); 721 | break; 722 | case SAW_CSI: ///Control sequence introducer - ESC [ or 0x9B 723 | switch(c){ 724 | case '?': 725 | if(params.size() != 0){ 726 | std::cerr << "Warning: typescript contains badly formatted CSI code. " 727 | << "The ? character appears in the parameter list but is " 728 | << "not the first character. Ignoring."; 729 | }; 730 | break; 731 | case '0': 732 | case '1': 733 | case '2': 734 | case '3': 735 | case '4': 736 | case '5': 737 | case '6': 738 | case '7': 739 | case '8': 740 | case '9': 741 | if(params.size() == 0){ 742 | params.push_back(0); 743 | } 744 | tmp_val = c-'0'; 745 | params.back() = (params.back()*10)+tmp_val; 746 | break; 747 | case ';': 748 | if(params.size() == 0){ 749 | params.push_back(0); 750 | } 751 | params.push_back(0); 752 | break; 753 | case '@': insert_blank(params); set_state(SAW_NOTHING); break; 754 | case 'A': cursor_up(params); set_state(SAW_NOTHING); break; 755 | case 'B': cursor_down(params); set_state(SAW_NOTHING); break; 756 | case 'C': cursor_right(params); set_state(SAW_NOTHING); break; 757 | case 'D': 758 | unimplemented_CSI(c, "Cursor left", params); 759 | set_state(SAW_NOTHING); 760 | break; 761 | case 'E': 762 | unimplemented_CSI(c, "Cursor down and to column 1", params); 763 | set_state(SAW_NOTHING); 764 | break; 765 | case 'F': 766 | unimplemented_CSI(c, "Cursor up and to column 1", params); 767 | set_state(SAW_NOTHING); 768 | break; 769 | case 'G': 770 | unimplemented_CSI(c, "Cursor to column", params); 771 | set_state(SAW_NOTHING); 772 | break; 773 | case 'H': 774 | unimplemented_CSI(c, "Cursor to row, column (origin is 1,1)", params); 775 | set_state(SAW_NOTHING); 776 | break; 777 | case 'J': 778 | unimplemented_CSI(c, "Erase display", params); 779 | set_state(SAW_NOTHING); 780 | break; 781 | case 'K': erase_line(params); set_state(SAW_NOTHING); break; 782 | case 'L': 783 | unimplemented_CSI(c, "Insert lines", params); 784 | set_state(SAW_NOTHING); 785 | break; 786 | case 'M': 787 | unimplemented_CSI(c, "Delete lines", params); 788 | set_state(SAW_NOTHING); 789 | break; 790 | case 'P': delete_characters(params); set_state(SAW_NOTHING); break; 791 | case 'X': 792 | unimplemented_CSI(c, "Erase chars", params); 793 | set_state(SAW_NOTHING); 794 | break; 795 | case 'a': 796 | unimplemented_CSI(c, "Cursor right", params); 797 | set_state(SAW_NOTHING); 798 | break; 799 | case 'c': ignore_CSI(); set_state(SAW_NOTHING); //Ignore VT102 id seq. 800 | break; 801 | case 'd': 802 | unimplemented_CSI(c, "Cursor to row", params); 803 | set_state(SAW_NOTHING); 804 | break; 805 | case 'e': 806 | unimplemented_CSI(c, "Cursor down", params); 807 | set_state(SAW_NOTHING); 808 | break; 809 | case 'f': 810 | unimplemented_CSI(c, "Cursor to row, column", params); 811 | set_state(SAW_NOTHING); 812 | break; 813 | case 'g': 814 | unimplemented_CSI(c, "Clear tab stop", params); 815 | set_state(SAW_NOTHING); 816 | break; 817 | case 'h': 818 | unimplemented_CSI(c, "Set mode", params); 819 | set_state(SAW_NOTHING); 820 | break; 821 | case 'l': 822 | unimplemented_CSI(c, "Reset mode", params); 823 | set_state(SAW_NOTHING); 824 | break; 825 | case 'm': ignore_CSI(); set_state(SAW_NOTHING); //Ignore char attributes 826 | break; 827 | case 'n': 828 | unimplemented_CSI(c, "Device status report", params); 829 | set_state(SAW_NOTHING); 830 | break; 831 | case 'q': ignore_CSI(); set_state(SAW_NOTHING); //Ignore LED setting 832 | break; 833 | case 'r': 834 | unimplemented_CSI(c, "Set srolling region", params); 835 | set_state(SAW_NOTHING); 836 | break; 837 | case 's': 838 | unimplemented_CSI(c, "Save cursor location", params); 839 | set_state(SAW_NOTHING); 840 | break; 841 | case 'u': 842 | unimplemented_CSI(c, "Restore cursor location", params); 843 | set_state(SAW_NOTHING); 844 | break; 845 | case '`': 846 | unimplemented_CSI(c, "Cursor to column", params); 847 | set_state(SAW_NOTHING); 848 | break; 849 | //The following parameters were only in references/ctlseqs.pdf 850 | case 'T': ignore_CSI(); set_state(SAW_NOTHING); //Ignore mouse tracking 851 | break; 852 | case 'x': ignore_CSI(); set_state(SAW_NOTHING); //Ignore term params req. 853 | break; 854 | default: 855 | unknown_code("conrol sequence (0x9B or ESC [)",c); 856 | } 857 | break; 858 | case SAW_ESC_PCT: /// ESC % 859 | switch(c){ 860 | case '@': 861 | case 'G': 862 | case '8': select_character_set(c); break; 863 | default: 864 | unknown_code("character set select command ESC %",c); 865 | }; 866 | set_state(SAW_NOTHING); 867 | break; 868 | case SAW_ESC_NUM: /// ESC # 869 | switch(c){ 870 | case '8': 871 | std::cerr << "Warning: typescript file contains DEC screen " 872 | << "alignment command which is ignored " 873 | << "by this translator.\n"; 874 | default: 875 | unknown_code("DEC screen alignment command ESC #",c); 876 | }; 877 | set_state(SAW_NOTHING); 878 | break; 879 | case SAW_ESC_LPAREN:/// ESC ( 880 | switch(c){ 881 | case 'B': 882 | case '0': 883 | case 'U': 884 | case 'K': define_g_character_set(0,c); break; 885 | default: 886 | unknown_code("define G0 character set command ESC (",c); 887 | }; 888 | set_state(SAW_NOTHING); 889 | break; 890 | case SAW_ESC_RPAREN: /// ESC ) 891 | switch(c){ 892 | case 'B': 893 | case '0': 894 | case 'U': 895 | case 'K': define_g_character_set(1,c); break; 896 | default: 897 | unknown_code("define G1 character set command ESC )",c); 898 | }; 899 | set_state(SAW_NOTHING); 900 | break; 901 | case SAW_OSC: ///Operating system command ESC ] 902 | next_state = SAW_NOTHING; 903 | switch(c){ 904 | case 'P': next_state = SAW_OSC_P; break; 905 | case 'R': reset_palette(); break; 906 | case '0': next_state = SAW_OSC_EAT_2_BEL; break; 907 | case '1': next_state = SAW_OSC_EAT_2_BEL; break; 908 | case '2': next_state = SAW_OSC_EAT_2_BEL; break; 909 | case '4': next_state = SAW_OSC_4; break; 910 | case '5': next_state = SAW_OSC_5; break; 911 | default: 912 | unknown_code("operating system command ESC ]",c); 913 | } 914 | set_state(next_state); 915 | break; 916 | case SAW_OSC_EAT_2_BEL: 917 | if(c=='\x07'){ //^G seen, go back to normal mode 918 | set_state(SAW_NOTHING); 919 | } 920 | break; 921 | case SAW_OSC_4: 922 | if(c!='6'){ 923 | unknown_code("operating system command number 4 (ESC ] 4)",c); 924 | } 925 | set_state(SAW_OSC_EAT_2_BEL); 926 | break; 927 | case SAW_OSC_5: 928 | if(c!='0'){ 929 | unknown_code("operating system command number 5 (ESC ] 5)",c); 930 | } 931 | set_state(SAW_OSC_EAT_2_BEL); 932 | break; 933 | case SAW_OSC_P: ///ESC ] P (will read 7 hex digits) 934 | //params[0] holds the number of hex digits read 935 | //params[1] holds the index to set 936 | //params[2] holds the color to set it to (24 bit integer) 937 | if(params.size() != 3 && params.size() != 0){ 938 | std::cerr << "SERIOUS WARNING: incorrect number of parameters " 939 | << "in OSC palette setting command SAW_OSC_P\n" 940 | << "Ignoring\n" 941 | << issue_report_boilerplate(); 942 | params.clear(); 943 | } 944 | if(params.size() == 0){ 945 | params.push_back(0); params.push_back(0); params.push_back(0); 946 | } 947 | tmp_val = -1; 948 | switch(c){ 949 | case '0': tmp_val = 0; break; 950 | case '1': tmp_val = 1; break; 951 | case '2': tmp_val = 2; break; 952 | case '3': tmp_val = 3; break; 953 | case '4': tmp_val = 4; break; 954 | case '5': tmp_val = 5; break; 955 | case '6': tmp_val = 6; break; 956 | case '7': tmp_val = 7; break; 957 | case '8': tmp_val = 8; break; 958 | case '9': tmp_val = 9; break; 959 | case 'A': tmp_val = 10; break; 960 | case 'B': tmp_val = 11; break; 961 | case 'C': tmp_val = 12; break; 962 | case 'D': tmp_val = 13; break; 963 | case 'E': tmp_val = 14; break; 964 | case 'F': tmp_val = 15; break; 965 | default: 966 | unknown_code("palette set command ESC ] P",c); 967 | } 968 | if(tmp_val != -1){ 969 | ++params.at(0); 970 | if(params.at(0) == 1){ 971 | params.at(1) = tmp_val; 972 | }else if(params.at(0) > 1 && params.at(0) <= 7){ 973 | params.at(2) = (params.at(2) << 4) + tmp_val; 974 | if(params.at(0) == 7){ 975 | set_palette(params.at(1), params.at(2)); 976 | } 977 | }else{ 978 | std::cerr << "SERIOUS WARNING: incorrect number of digits read " 979 | << '(' << params.at(0) << ')' 980 | << "in OSC palette setting command SAW_OSC_P\n" 981 | << "Ignoring\n" 982 | << issue_report_boilerplate(); 983 | } 984 | } 985 | break; 986 | case SAW_CSI_LBRACKET: /// ESC [ [ or CSI [ (just eats next char) 987 | set_state(SAW_NOTHING); 988 | break; 989 | default: 990 | std::cerr << "ERROR: Unknown reader state (" << ((unsigned)state) 991 | << ") encountered in read_from\n"; 992 | exit(-2); 993 | } 994 | } 995 | } 996 | 997 | int main(){ 998 | Reader r; 999 | r.read_from(std::cin); 1000 | r.write_to(std::cout); 1001 | } 1002 | --------------------------------------------------------------------------------