code:ttyinput - ikarishinjieva/unixV6-code-analyze-chs GitHub Wiki

Source

  • 向tty原始队列送入1个字符
  • 输入2个参数 ac , atp
    • ac : 指定字符
    • atp : 指定tty

8327 /* Place a character on raw TTY input queue, putting in

8328  * delimiters and waking up top half as needed.

8329  * Also echo if required.

8330  * The arguments are the character and the appropriate

8331  * tty structure.

8332  */

8333 ttyinput(ac, atp)

8334 struct tty *atp;

8335 {

8336     register int t_flags, c;

8337     register struct tty *tp;

8338

8339     tp = atp;

8340     c = ac;

8341     t_flags = tp->t_flags;

8342     if ((c =& 0177) == ’\r’ && t_flags&CRMOD)

8343          c = ’ \n’;

  • 若tty 使用了CR换行,则
  • \r →
\n (输出(ttyoutput)时 \n → \r \n)
8344     if ((t_flags&RAW)==0 && (c==CQUIT || c==CINTR)) {

8345          signal(tp, c==CINTR? SIGINT:SIGQIT);

8346          flushtty(tp);

8347          return;

8348     }

  • tty不是原始模式时
    • CQUIT : 向该终端所有进程 发送SIGQIT 信号
    • CINTR : 向该终端所有进程 发送SIGINT 信号 
8349     if (tp->t_rawq.c_cc>=TTYHOG) {

8350          flushtty(tp);

8351          return;

8352     }

  • 若 tty原始队列 元素过多,则 清tty队列
(处理过量输入,方式过于粗暴...)
8353     if (t_flags&LCASE && c>=’A’ && c<=’Z’)

8354          c =+ ’a’-’A’;

  • tty 带 LCASE 标志(tty 只支持 64字符 ASCII 子集)
8355     putc(c, &tp->t_rawq);
  • 向 tty 原始队列送入 c
8356     if (t_flags&RAW || c==’ \n’ || c==004) {

8357          wakeup(&tp->t_rawq);

8358          if (putc(0377, &tp->t_rawq)==0)

8359           tp->t_delct++;

8360     }

  • tty 为 原始模式,或c 为 换行符(
\n) 或 传输结尾(EOT = 004),则
    • 唤醒 等待 tty原始队列的进程
    • 向原始队列送入 定界符 (送入不一定成功,参看 LIONS源代码分析)
8361     if (t_flags&ECHO) {

8362          ttyoutput(c, tp);

8363          ttstart(tp);

8364     }

  • tty 为 全双工模式(输入字符需回显),则回显字符
8365 }

8366 /* ------------------------- */

Caller

⚠️ **GitHub.com Fallback** ⚠️