APUE 笔记 Terminal I/O

来源:互联网 发布:bootstrap 数据库后端 编辑:程序博客网 时间:2024/06/17 10:54

18.2

1. Terminal I/O mode

canonical mode input processing :终端驱动(终端)每次处理一行(用户)输入,对应的实现模块是 terminal line discipline;

noncanonical mode input processing

2.

   struct termios {
     tcflag_t  c_iflag;    /* input flags */
     tcflag_t  c_oflag;    /* output flags */
     tcflag_t  c_cflag;    /* control flags */
     tcflag_t  c_lflag;    /* local flags */
     cc_t      c_cc[NCCS]; /* control characters */
   };


SUS 不在终端上使用ioctl,而是使用了针对终端的13个函数,这些函数一部分对termios结构进行操作,因外一些和terminal line discipline 模块和终端驱动交换,见下图:

Figure 18.8. Relationships among the terminal-related functions

(18.2)

18.3

1.Special Input Charaters

特殊字符有不同的用处,有一部分是和信号相关的:SIGINT、SIGQUIT、SIGTSTP、SIGQUIT,还有像EOF、CR、NL

Typical value 表示如何通过键盘操作打出这些输送字符。


Figure 18.10. Disable interrupt character and change end-of-file character

#include "apue.h"
#include <termios.h>
int
main(void)
{
    struct termios term;

    long           vdisable;


    if (isatty(STDIN_FILENO) == 0)//STDIN_FILENO和终端相关联,返回1,否则返回0
        err_quit("standard input is not a terminal device");
    if ((vdisable = fpathconf(STDIN_FILENO, _PC_VDISABLE)) < 0) //??
        err_quit("fpathconf error or _POSIX_VDISABLE not in effect");
    if (tcgetattr(STDIN_FILENO, &term) < 0) /* fetch tty state */
        err_sys("tcgetattr error");
    term.c_cc[VINTR] = vdisable;    /* disable INTR character */
    term.c_cc[VEOF]  = 2;           /* EOF is Control-B */
    if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &term) < 0) // 第二个参数控制设置何时起效,参考18.4
        err_sys("tcsetattr error");
    exit(0);
}



18.4

#include <termios.h>
int tcgetattr(int filedes, struct termios *termptr);
int tcsetattr(int filedes, int opt, const struct termios *termptr);

。。。下面的终端相关的,暂时不想看了

原创粉丝点击