Stty learning notes

Source: Internet
Author: User
Tags control characters eol uppercase character

<1> simple mode, displaying the baud rate
Stty
Speed38400 baud; line = 0;
EOL = m-^ ?; Eol2 = m-^ ?; Swtch = m-^ ?;
Ixany iutf8

 

<2> display all set commands
Stty-
Speed 38400 baud; rows 24; columns 80; line = 0;
Intr = ^ C; quit = ^/; erase = ^ ?; Kill = ^ U; EOF = ^ d; EOL = m-^ ?; Eol2 = m-^ ?;
Swtch = m-^ ?; Start = ^ Q; stop = ^ s; susp = ^ Z; rprnt = ^ r; werase = ^ W;
Lnext = ^ V; flush = ^ O; min = 1; time = 0;
-Parenb-parodd cs8 hupcl-cstopb cread-clocal-crtscts
-Ignbrk brkint-ignpar-parmrk-inpck-istrip-inlcr-igncr icrnl ixon-ixoff
-Iuclc ixany imaxbel iutf8
Opost-olcuc-ocrnl onlcr-onocr-onlret-ofill-ofdel nl0 Cr0 tab0 bs0 vt0 ff0
Isig icanon iexten echo echoe echok-echonl-noflsh-xcase-tostop-echoprt
Echoctl echoke

 

Important:
The minus sign before the attribute indicates that it is forbidden.
No minus signs

 

<3> Programming

The above heap contains corresponding characters in struct termios {} or corresponding characters. The corresponding characters are in c_cc [].

Define the structure and corresponding bit in include/asm-i386/termbits. h

Struct termios {
Tcflag_t c_iflag;/* input mode flags */
Tcflag_t c_oflag;/* output mode flags */
Tcflag_t c_cflag;/* Control Mode flags */
Tcflag_t c_lflag;/* Local Mode flags */
Cc_t c_line;/* line discipline */
Cc_t c_cc [NCCs];/* control characters */
};

 

<3.1> input mode


C_iflag contains the following mark:
/* C_iflag bits */
# Define ignbrk 0000001
# Define brkint 0000002
# Define ignpar 0000004
# Define parmrk 0000010
# Define inpck 0000020
# Define istrip 0000040
# Define inlcr 0000100
# Define igncr 0000200
# Define icrnl 0000400
# Define iuclc 0001000
# Define ixon 0002000
# Define ixany 0004000
# Define ixoff 0010000
# Define imaxbel 0020000
# Define iutf8 0040000

Intr signal is triggered when brkint is interrupted.
-When brkint is interrupted, no intr signal is sent.


When icrnl is input, Cr is mapped to NL.
-When icrnl is input, Cr is not mapped to NL.


Ignore break when entering ignbrk.
-The break is not ignored when the ignbrk is input.


Ignore Cr when entering igncr.
-Cr is not ignored when igncr is input.


Ignpar ignores parity errors.
-Ignpar does not ignore parity errors.


When inlcr is input, NL is mapped to Cr.
-When inlcr is input, NL is not mapped to Cr.


Inpck enables parity.
-Inpck disables parity.


Istrip splits the input characters to seven characters.
-Istrip does not strip the input characters to seven characters.


Iuclc maps uppercase letters and characters to lowercase letters.
-Iuclc does not map uppercase letters to lowercase letters.


Ixany allows output to be restarted by any character.
-Ixany only allows start (CTRL-q) to restart output.


Ixoff when the input queue is close to null or full, send the start/stop character.
-Ixoff does not send start/stop characters.


Ixon enables start/stop output control. Once start/stop output control is enabled,
You can press Ctrl-s to pause the output to the workstation, or press Ctrl-Q to resume the output.
-Ixon disables start/stop output control.


When the input of imaxbel overflows, the bel character is returned and the last input character is discarded.
-When the input overflows, all input is discarded.


Parmrk indicates a parity error.
-Parmrk does not mark a parity error [1].


<3.2> output mode
C_oflag contains the following mark:
/* C_oflag bits */
# Define opost 0000001
# Define olcuc 0000002
# Define onlcr 0000004
# Define ocrnl 0000010
# Define onocr 0000020
# Define onlret 0000040
# Define ofill 0000100
# Define ofdel 0000200
# Define nldly 0000400
# Define nl0 0000000
# Define nl1 0000400
# Define CRC 0003000
# Deprecision Cr0 0000000
# Define CR1 1 0001000
# Define Cr2 0002000.
# Define H13 0003000
# Define tabdly 0014000
# Define tab0 0000000
# Define tab1 0004000
# Define tab2 0010000
# Define table 3 0014000
# Define xtabs 0014000
# Define bsdly 0020000
# Define bs0 0000000
# Define BS1 0020000
# Define vtdly 0040000
# Define vt0 0000000
# Define vt1 0040000
# Define ffdly 0100000
# Deprecision ff0 0000000
# Define ff1 1 0100000

Bs0 and BS1 select a latency style for the return character (bs0 indicates no latency ).
Cr0, CR1, CR2, and so on (Cr0 indicates no delay) is selected for Cr characters ).
Ff0 and ff1 select the latency style for the page feed (ff0 indicates no latency ).
Nl0 and nl1 select a latency style for NL characters (nl0 indicates no latency ).
Ofill uses delayed padding characters.
-Ofill uses latency timing.
Ocrnl maps Cr characters to Nl characters.
-Ocrnl does not map Cr characters to Nl characters.
When olcuc outputs, lowercase letter characters are mapped to uppercase letters.
-In olcuc output, lowercase letter characters are not mapped to uppercase letters.
Onlcr maps the NL character to a CR-NL character.
-Onlcr does not map the NL character to a CR-NL character.
Onlret performs Cr on the terminal NL.
-Onlret does not execute the CR function on the terminal NL.
Onocr does not output Cr characters in the zero column.
-Onocr outputs Cr characters in the zero column.
Opost processing output.
-Opost does not process output, that is, all other output options are ignored.
Ofdel uses the del character as the filling character.
-Ofdel uses the NUL character as the filling character.
Tab0, tab1, and tab2 select a latency style for the horizontal tab (tab0 indicates no latency ).
Tab3 extends the tabs to multiple spaces.
Vt0 and vt1 select a latency style for the vertical tab (vt0 indicates no latency) [1].

 

<3.3> Control Mode
/* C_cflag bit meaning */
# Define cbaud 0010017
# Define B0 0000000/* hang up */
# Define B50 0000001
# Define b75 0000002
# Define b110 0000003
# Define b134 0000004
# Define b150 0000005
# Define b200 0000006
# Define b300 0000007
# Define b600 0000010
# Define b1200 0000011
# Define b1800 0000012
# Define b2400 0000013
# Define b4800 0000014
# Define b9600 0000015
# Define b19200 0000016
# Define b38400 0000017
# Define exta b19200
# Define extb b38400
# Define csize 0000060
# Define cs5 5 0000000
# Define cs6. 0000020
# Define cs7 0000040.
# Define cs8. 0000060
# Define cstopb 0000100
# Define cread 0000200.
# Define partition 0000400
# Define parodd 0001000
# Define hupcl 0002000
# Define clocal 0004000
# Define cbaudex 0010000
# Define b57600 0010001
# Define b115200 0010002
# Define b230400 0010003
# Define b460800 0010004
# Define b500000 0010005
# Define b576000 0010006
# Define b921600 0010007
# Define b000000 0010010
# Define b1152000 0010011
# Define b1500000 0010012
# Define b2000000 0010013
# Define b2500000 0010014
# Define b3000000 0010015
# Define b3500000 0010016
# Define b4000000 0010017
# Define cibaud 002003600000/* input baud rate (not used )*/
# Define cmspar 010000000000/* mark or space (stick) Parity */
# Define crtscts 020000000000/* Flow Control */

Clocal assumes that one row has no modem control.
-Clocal assumes that a row has modem control.
Enable the receiver in cread.
-Cread: Disable the receiver.
Cstopb selects two stop bits for each character.
-Cstopb: select a stop bit for each character.
Select the character size for cs5, CS6, cs7, and cs8.
Hup. When hupcl is closed, the dial-up connection is suspended.
-Hup,-When hupcl is closed, the dial-up connection is not suspended.
Parenb enables generation and detection of parity verification.
-Parenb disables generation and detection of parity verification.
Select odd check for parodd.
-Select parity check for parodd.
0. Suspend the telephone line immediately.
Speed sets the input and output speed of the workstation to the specified speed (in bits/s ).
Not all hardware interfaces support all speeds.
Possible values of speed include: 50, 75, 110, 134, 200, 300, 600, 1200, 1800,
2400, 4800, 9600, 19200, 19.2, 38400, 38.4, exta, and extb.
Note:
Exta, 19200, and 19.2 are synonyms. extb, 38400, and 38.4 are synonyms.
Ispeed speed sets the input speed of the workstation to the specified speed (in bits/s ).
Not all hardware interfaces support all speeds, and not all hardware interfaces support this option.
The value of speed may be the same as that of speed.
Ospeed speed sets the output speed of the workstation to the specified speed (in bits/s ).
Not all hardware interfaces support all speeds, and not all hardware interfaces support this option.
The value of speed may be the same as that of speed option [1].

 

<1, 3.4
Local Mode
/* C_lflag bits */
# Define isig 0000001
# Define Ican 0000002
# Define xcase 0000004
# Define echo 0000010
# Define echoe 0000020
# Define echok 0000040
# Define echonl 0000100
# Define noflsh 0000200
# Define tostop 0000400
# Define echoctl 0001000
# Define echoprt 0002000
# Define echoke 0004000
# Define flusho 0010000.
# Define Pendin 0040000
# Define iexten 0100000

Echo returns each input character.
-Echo does not return characters.
Echoctl takes the ^ X (CTRL-x) return control character, and X is the character that is added to the control character code.
-Echoctl does not use the ^ X (CTRL-x) return control character.
Echoe returns the erase character with the "backspace space backspace" string.
Note:
This mode does not keep track of the column position, so you may get unexpected results when erasing symbols such as tabs and escape sequences.
-Echoe only returns the escape character if it does not return the erase character.
Echok returns the NL character after the kill character.
-Echok does not return the NL character after the kill character.
The echoke erases each character in the output line and returns the kill character.
-Echoke only returns kill characters.
Echonl returns the NL character.
-Echonl does not return NL characters.
Echoprt returns the erased characters with/(slash) And/(backslash.
-Echoprt does not return the erased characters with a slash (/) or a backslash (backslash.
Icanon enables canonicalized input (canonicalized input can be edited using erase and kill characters ).
See in Aix 5l version 5.2 communications programming concepts
The canonical mode input in line discipline module (ldterm.
-Icanon disables standard input.
Iexten specifies the ability to identify the definition of realization from input data.
To recognize the following control characters,
You need to set iexten: eol2, dsusp, reprint, discard, werase, and lnext.
For features associated with these modes, you also need to set iexten: imaxbel, echoke, echoprt, and echoctl.
-Iexten indicates the ability to identify the definition of realization from input data.
Isig enables character check for special control characters (intr, susp, and quit special control characters.
-Isig disables character check for special control characters (intr, susp, and quit special control characters.
Noflsh does not clear the buffer after intr, susp, or quit control characters.
-Noflsh clears the buffer after intr, susp, or quit control characters.
When pending is temporarily suspended for the next read operation or the input arrives, you need to re-enter the input that is temporarily suspended after switching from the original mode to the standard mode.
Temporary suspension is an internal status bit.
-No text is suspended for pending.
Tostop sends a sigtou signal to the background output.
-Tostop does not send a sigtou signal to the background output.
Xcase returns uppercase characters in the input, and adds/(backslash) before the uppercase characters displayed in the output ).
-When xcase is not input, an uppercase character [1] is returned.

 

<3.5> control characters
/* C_cc characters */
# Define vintr 0
# Define vquit 1
# Define verase 2
# Define vkill 3
# Define veof 4
# Define vtime 5
# Define Vmin 6
# Define vswtc 7
# Define vstart 8
# Define vstop 9
# Define vsusp 10
# Define veol 11
# Define vreprint 12
# Define vdiscard 13
# Define vwerase 14
# Define vlnext 15
# Define veol2 16
Control specified
To specify a control character to a string, enter:
Stty control string
The control parameters can be intr, quit, erase, kill, eof, EOL, eol2, start, stop,
Susp, dsusp, reprint, discard, werase,
Lnext, Min, or time parameters. (When using characters min and time, add the-icanon option .) [1]

 

 

<4> Test

<4.1> print the number of rows and columns of the terminal.
Stty size
24 80
24 rows and 80 columns


& Lt; 4.2 & gt;
Stty Cols 25
Set the column to 25 rows and narrow the output.
Stty-
Speed38400 baud;
Rows 24; columns 25;
Line = 0;
Intr = ^ C; quit = ^ /;
Erase = ^ ?; Kill = ^ U;
EOF = ^ d; EOL = <UNDEF>;
Eol2 = <UNDEF>;
Swtch = <UNDEF>;
Start = ^ Q; stop = ^ s;
Susp = ^ Z; rprnt = ^ r;
Werase = ^ W; lnext = ^ V;
Flush = ^ O;
Min = 1; time = 0;
-Parenb-parodd cs8 hupcl
-Cstopb cread-clocal
-Crtscts
-Ignbrk brkint ignpar
-Parmrk-inpck istrip
-Inlcr-igncr icrnl ixon
-Ixoff-iuclc-ixany
Imaxbel-iutf8
Opost-olcuc-ocrnl onlcr
-Onocr-onlret-ofill
-Ofdel nl0 Cr0 tab0 bs0
Vt0 ff0
Isig icanon iexten echo
Echoe echok-echonl
-Noflsh-xcase-tostop
-Echoprt echoctl echoke

<4.3> stty speed
Display rate

<4.4> stty intr C
C becomes the interrupt key, and it is impossible to enter C.

<4.5> stty raw
It is found that Ctrl + C is useless, and the output is messy.
Allow input in the original mode (excluding input processing, such as erase, kill, or interrupt); return the parity bit.

& Lt; 4.6 & gt; stty-raw
The standard input mode is allowed.

<4.7> disable the upper-case output method under the command line.
Stty iuclc # enable
Stty-iuclc # restore

<4.8> disable lower-case output under the command line
Stty olcuc # enable
Stty-olcuc # restore

<4.9> stty sane
Reset the parameter to a reasonable value.

<4.10> ignore carriage return
Stty igncr # enable
Enter does not work. To display the execution result, press Ctrl + J.

Stty-igncr # restore. to display the execution result, press Ctrl + J.

<4.11> stty erase x
It is impossible to enter X when the unregeed deletion key is changed to X because X is the return key.
Stty erase ^? Returns the original return key.

& Lt; 4.12 & gt; stty-echo
No buttons are found.
Stty echo
Input display

<4.13> stty-icanon
Disable the standard mode processing in the driver and skip the buffer layer. You cannot delete characters,

Test
Gui. c
# Include <stdio. h>
Main ()
{
Char C;
File * fp_tty;
Fp_tty = fopen ("/dev/tty", "R ");
If (fp_tty = NULL)
Exit (1 );
While (C = GETC (fp_tty ))! = EOF)
{
Printf ("% d", C );
}
}

GCC gui. C-o Gui

Stty icanon
./GUI
D
10010f
10210d
10010f
10210
You can use the return key and press the Enter key to display the number.

Stty-icanon
./GUI
D100f102g103h104
10

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.