echo.c

来自「teco编辑器源码」· C语言 代码 · 共 53 行

C
53
字号
#include <ctype.h>
#include <stdio.h>
#include <string.h>

static char last='\0';
static char this='\0';

echo(c) /* Echo char appropriately on console */
{
#include "teco.h"

	if (cancel) return;			/* Skip if ^O sent */
	this=toascii(c);			/* Mask off parity */
	if (this == 27) {			/* Check for <ESC> */
		this='$';			/*  ..if so echo $ */
	} else {				/* Else process it */
		if (iscntrl(this)) {
			if (this == 10) {
				if (last == 13) {
					last=this;
					return;
				} else {
					fprintf(stderr,"\n");
					goto check;
				}
			} else {
				if (this == 13) {
					fprintf(stderr,"\n");
					goto check;
				}
				if (this == 9) {
					fprintf(stderr,"\11");
					goto check;
				} else {
					fprintf(stderr,"\^");
					this=this+64;
				}
			}
		}
	}
	fprintf(stderr,"%c",this);
	last=this;
	return;

check:	last=this;
	if (kbhit()) {
		if (15 == toascii(getch())) {
			cancel=1;
			fprintf(stderr,"\^O\n");
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?