⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vt100.c

📁 minicom2.0源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * vt100.c	ANSI/VT102 emulator code. *		This code was integrated to the Minicom communications *		package, but has been reworked to allow usage as a separate *		module. * *		It's not a "real" vt102 emulator - it's more than that: *		somewhere between vt220 and vt420 in commands. * *		This file is part of the minicom communications package, *		Copyright 1991-1995 Miquel van Smoorenburg. * *		This program is free software; you can redistribute it and/or *		modify it under the terms of the GNU General Public License *		as published by the Free Software Foundation; either version *		2 of the License, or (at your option) any later version. * * // jl 04.09.97 character map conversions in and out *    jl 06.07.98 use conversion tables with the capture file */#ifdef HAVE_CONFIG_H#include <config.h>#endif#include "rcsid.h"RCSID("$Id: vt100.c,v 1.3 2000/02/09 08:34:57 misiek Exp $")#include "port.h"#include "window.h"#include "vt100.h"#include "config.h"#include "configsym.h"#define OLD 0/* * The global variable esc_s holds the escape sequence status: * 0 - normal * 1 - ESC * 2 - ESC [ * 3 - ESC [ ? * 4 - ESC ( * 5 - ESC ) * 6 - ESC # * 7 - ESC P */static int esc_s = 0;#define ESC 27/* Structure to hold escape sequences. */struct escseq {  int code;  char *vt100_st;  char *vt100_app;  char *ansi;};/* Escape sequences for different terminal types. */static struct escseq vt_keys[] = {#ifndef _DGUX_SOURCE  { K_F1,	"OP",	"OP",	"OP" },  { K_F2,	"OQ",	"OQ",	"OQ" },  { K_F3,	"OR",	"OR",	"OR" },  { K_F4,	"OS",	"OS",	"OS" },  { K_F5,	"[16~",	"[16~",	"OT" },  { K_F6,	"[17~",	"[17~",	"OU" },  { K_F7,	"[18~",	"[18~",	"OV" },  { K_F8,	"[19~",	"[19~",	"OW" },  { K_F9,	"[20~",	"[20~",	"OX" },  { K_F10,	"[21~",	"[21~",	"OY" },  { K_F11,	"[23~",	"[23~",	"OY" },  { K_F12,	"[24~",	"[24~",	"OY" },  { K_HOME,	"[1~",	"[1~",	"[H" },  { K_PGUP,	"[5~",	"[5~",	"[V" },  { K_UP,	"[A",	"OA",	"[A" },  { K_LT,	"[D",	"OD",	"[D" },  { K_RT,	"[C",	"OC",	"[C" },  { K_DN,	"[B",	"OB",	"[B" },  { K_END,	"[4~",	"[4~",	"[Y" },  { K_PGDN,	"[6~",	"[6~",	"[U" },  { K_INS,	"[2~",	"[2~",	"[@" },  { K_DEL,	"[3~",	"[3~",	"\177" },  { 0,		NULL,	NULL,	NULL }#else  { K_F1,      "[17~", "[17~", "OP" },  { K_F2,      "[18~", "[18~", "OQ" },  { K_F3,      "[19~", "[19~", "OR" },  { K_F4,      "[20~", "[20~", "OS" },  { K_F5,      "[21~", "[21~", "OT" },  { K_F6,      "[23~", "[23~", "OU" },  { K_F7,      "[24~", "[24~", "OV" },  { K_F8,      "[25~", "[25~", "OW" },  { K_F9,      "[26~", "[26~", "OX" },  { K_F10,     "[28~", "[28~", "OY" },  { K_F11,     "[29~", "[29~", "OZ" },  { K_F12,     "[31~", "[31~", "OA" },  { K_HOME,    "OP",   "OP",   "[H" },  { K_PGUP,    "OQ",   "OQ",   "[V" },  { K_UP,      "[A",   "OA",   "[A" },  { K_LT,      "[D",   "OD",   "[D" },  { K_RT,      "[C",   "OC",   "[C" },  { K_DN,      "[B",   "OB",   "[B" },  { K_END,     "OR",   "OR",   "[Y" },  { K_PGDN,    "OS",   "OS",   "[U" },  { K_INS,     "[1~",  "[1~",  "[@"  },  { K_DEL,     "[3~",  "[3~",  "\177" },  { 0,         NULL,   NULL,   NULL }#endif};/* Two tables for user-defined character map conversions. * defmap.h should contain all characters 0-255 in ascending order * to default to no conversion.    jl 04.09.1997 */unsigned char vt_inmap[256] = {#include "defmap.h"};unsigned char vt_outmap[256] = {#include "defmap.h"};#if TRANSLATE/* Taken from the Linux kernel source: linux/drivers/char/console.c */static unsigned char * vt_map[] = {/* 8-bit Latin-1 mapped to the PC character set: '.' means non-printable */(unsigned char *)	"................"	"................"	" !\"#$%&'()*+,-./0123456789:;<=>?"	"@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"	"`abcdefghijklmnopqrstuvwxyz{|}~."	"................"	"................"	"\377\255\233\234\376\235\174\025\376\376\246\256\252\055\376\376"	"\370\361\375\376\376\346\024\371\376\376\247\257\254\253\376\250"	"\376\376\376\376\216\217\222\200\376\220\376\376\376\376\376\376"	"\376\245\376\376\376\376\231\376\350\376\376\376\232\376\376\341"	"\205\240\203\376\204\206\221\207\212\202\210\211\215\241\214\213"	"\376\244\225\242\223\376\224\366\355\227\243\226\201\376\376\230",/* vt100 graphics */(unsigned char *)	"................"	"\0\0\0\0\0\0\0\0\0\0\376\0\0\0\0\0"	" !\"#$%&'()*+,-./0123456789:;<=>?"	"@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^ "	"\004\261\007\007\007\007\370\361\007\007\331\277\332\300\305\304"	"\304\304\137\137\303\264\301\302\263\363\362\343\330\234\007\0"	"................"	"................"	"\377\255\233\234\376\235\174\025\376\376\246\256\252\055\376\376"	"\370\361\375\376\376\346\024\371\376\376\247\257\254\253\376\250"	"\376\376\376\376\216\217\222\200\376\220\376\376\376\376\376\376"	"\376\245\376\376\376\376\231\376\376\376\376\376\232\376\376\341"	"\205\240\203\376\204\206\221\207\212\202\210\211\215\241\214\213"	"\376\244\225\242\223\376\224\366\376\227\243\226\201\376\376\230"};static char *vt_trans[2];static int vt_charset = 0;	/* Character set. */#endif#ifdef HAVE_SELECTstatic int vt_echo;		/* Local echo on/off. */#endifint vt_nl_delay;		/* Delay after CR key */static int vt_type   = ANSI;	/* Terminal type. */static int vt_wrap   = 0;	/* Line wrap on/off */static int vt_addlf  = 0;	/* Add linefeed on/off */static int vt_fg;		/* Standard foreground color. */static int vt_bg;		/* Standard background color. */static int vt_keypad;		/* Keypad mode. */static int vt_cursor;		/* cursor key mode. */static int vt_asis = 0;		/* 8bit clean mode. */static int vt_bs = 8;		/* Code that backspace key sends. */static int vt_insert = 0;	/* Insert mode */static int vt_crlf = 0;		/* Return sends CR/LF */static int vt_om;		/* Origin mode. */WIN *vt_win          = NIL_WIN;	/* Output window. */static int vt_docap;		/* Capture on/off. */static FILE *vt_capfp;		/* Capture file. */static void (*vt_keyb)();	/* Gets called for NORMAL/APPL switch. */static void (*termout)();	/* Gets called to output a string. */static int escparms[8];		/* Cumulated escape sequence. */#if OLDstatic int ptr = -2;		/* Index into escparms array. */#elsestatic int ptr = 0;		/* Index into escparms array. */#endifstatic long vt_tabs[5];		/* Tab stops for max. 32*5 = 160 columns. */short newy1 = 0;		/* Current size of scrolling region. */short newy2 = 23;/* Saved color and posistions */static short savex = 0, savey = 0, saveattr = XA_NORMAL, savecol = 112;#if TRANSLATEstatic short savecharset;static char *savetrans[2];#endif/* * Initialize the emulator once. */void vt_install(fun1, fun2, win)void (*fun1)();void (*fun2)();WIN *win;{  termout = fun1;  vt_keyb = fun2;  vt_win = win;}/* Partial init (after screen resize) */void vt_pinit(win, fg, bg)WIN *win;int fg, bg;{  vt_win = win;  newy1 = 0;  newy2 = vt_win->ys - 1;  wresetregion(vt_win);  if (fg > 0) vt_fg = fg;  if (bg > 0) vt_bg = bg;  wsetfgcol(vt_win, vt_fg);  wsetbgcol(vt_win, vt_bg);}/* Set characteristics of emulator. */void vt_init(type, fg, bg, wrap, add)int type;int fg;int bg;int wrap;int add;{  vt_type = type;  if (vt_type == ANSI) {	vt_fg = WHITE;	vt_bg = BLACK;  } else {	vt_fg = fg;	vt_bg = bg;  }  if (wrap >= 0) vt_win->wrap = vt_wrap = wrap;  vt_addlf = add;  vt_insert = 0;  vt_crlf = 0;  vt_om = 0;  newy1 = 0;  newy2 = vt_win->ys - 1;  wresetregion(vt_win);  vt_keypad = NORMAL;  vt_cursor = NORMAL;#ifdef HAVE_SELECT  vt_echo = 0;#endif  vt_tabs[0] = 0x01010100;  vt_tabs[1] =  vt_tabs[2] =  vt_tabs[3] =  vt_tabs[4] = 0x01010101;#if TRANSLATE  vt_charset = 0;  vt_trans[0] = vt_map[0];  vt_trans[1] = vt_map[1];#endif#if OLD  ptr = -2;#else  ptr = 0;  memset(escparms, 0, sizeof(escparms));#endif  esc_s = 0;  if (vt_keyb) (*vt_keyb)(vt_keypad, vt_cursor);  wsetfgcol(vt_win, vt_fg);  wsetbgcol(vt_win, vt_bg);}/* Change some things on the fly. */void vt_set(addlf, wrap, capfp, docap, bscode, echo, cursor, asis)int addlf;int wrap;FILE *capfp;int docap;int bscode;int echo;int cursor;int asis;{  if (addlf >= 0) vt_addlf = addlf;  if (wrap >= 0)  vt_win->wrap = vt_wrap = wrap;  if (capfp != (FILE *)0) vt_capfp = capfp;  if (docap >= 0) vt_docap = docap;  if (bscode >= 0) vt_bs = bscode;#ifdef HAVE_SELECT  if (echo >= 0) vt_echo = echo;#endif  if (cursor >= 0) vt_cursor = cursor;  if (asis >=0) vt_asis = asis;}/* Output a string to the modem. */static void v_termout(s, len)char *s;int len;{#ifdef HAVE_SELECT  char *p;  if (vt_echo) {	for(p = s; *p; p++) {		vt_out(*p);		if (!vt_addlf && *p == '\r') vt_out('\n');	}	wflush();  }#endif  (*termout)(s, len);}/* * Escape code handling. *//* * ESC was seen the last time. Process the next character. */static void state1(c)int c;{  short x, y, f;  switch(c) {	case '[': /* ESC [ */		esc_s = 2;		return;	case '(': /* ESC ( */		esc_s = 4;		return;	case ')': /* ESC ) */		esc_s = 5;		return;	case '#': /* ESC # */		esc_s = 6;		return;	case 'P': /* ESC P (DCS, Device Control String) */		esc_s = 7;		return;	case 'D': /* Cursor down */	case 'M': /* Cursor up */		x = vt_win->curx;		if (c == 'D')  { /* Down. */			y = vt_win->cury + 1;			if (y == newy2 + 1)				wscroll(vt_win, S_UP);			else if (vt_win->cury < vt_win->ys)				wlocate(vt_win, x, y);		}				if (c == 'M')  { /* Up. */			y = vt_win->cury - 1;			if (y == newy1 - 1)				wscroll(vt_win, S_DOWN);			else if (y >= 0)				wlocate(vt_win, x, y);		}		break;	case 'E': /* CR + NL */ 		wputs(vt_win, "\r\n"); 		break; 	case '7': /* Save attributes and cursor position */ 	case 's': 		savex = vt_win->curx; 		savey = vt_win->cury; 		saveattr = vt_win->attr; 		savecol = vt_win->color;#if TRANSLATE		savecharset = vt_charset;		savetrans[0] = vt_trans[0];		savetrans[1] = vt_trans[1];#endif 		break; 	case '8': /* Restore them */ 	case 'u':	#if TRANSLATE		vt_charset = savecharset;		vt_trans[0] = savetrans[0];		vt_trans[1] = savetrans[1];#endif 		vt_win->color = savecol; /* HACK should use wsetfgcol etc */ 		wsetattr(vt_win, saveattr); 		wlocate(vt_win, savex, savey); 		break; 	case '=': /* Keypad into applications mode */		vt_keypad = APPL;		if (vt_keyb) (*vt_keyb)(vt_keypad, vt_cursor); 		break; 	case '>': /* Keypad into numeric mode */ 		vt_keypad = NORMAL;		if (vt_keyb) (*vt_keyb)(vt_keypad, vt_cursor); 		break; 	case 'Z': /* Report terminal type */		if (vt_type == VT100)			v_termout("\033[?1;0c", 0); 		else	 			v_termout("\033[?c", 0); 		break;	 	case 'c': /* Reset to initial state */ 		f = XA_NORMAL; 		wsetattr(vt_win, f);		vt_win->wrap = (vt_type != VT100);		if (vt_wrap != -1) vt_win->wrap = vt_wrap;		vt_crlf = vt_insert = 0;		vt_init(vt_type, vt_fg, vt_bg, vt_win->wrap, 0); 		wlocate(vt_win, 0, 0); 		break; 	case 'H': /* Set tab in current position */		x = vt_win->curx;		if (x > 159) x = 159;		vt_tabs[x / 32] |= 1 << (x % 32);		break; 	case 'N': /* G2 character set for next character only*/ 	case 'O': /* G3 "				"    */ 	case '<': /* Exit vt52 mode */ 	default: 		/* ALL IGNORED */ 		break;  }  esc_s = 0;  return;}/* ESC [ ... [hl] seen. */static void ansi_mode(on_off)int on_off;{  int i;  for(i = 0; i <= ptr; i++) {	switch(escparms[i]) {		case 4: /* Insert mode  */			vt_insert = on_off;			break;		case 20: /* Return key mode */			vt_crlf = on_off;			break;	}  }}/* * ESC [ ... was seen the last time. Process next character. */static void state2(c)int c;{  short x, y, attr, f;  char temp[32];  /* See if a number follows */  if (c >= '0' && c <= '9') {#if OLD	if (ptr < 0) ptr = 0;#endif	escparms[ptr] = 10*(escparms[ptr]) + c - '0';	return;  }  /* Separation between numbers ? */  if (c == ';') {#if OLD	if (ptr < 0) ptr = 0; /* keithr@primenet.com */	if (ptr >= 0 && ptr < 15) ptr++;#else	if (ptr < 15) ptr++;#endif	return;  }  /* ESC [ ? sequence */#if OLD  if (ptr < 0 && c == '?') {#else  if (escparms[0] == 0 && ptr == 0 && c == '?') {#endif	esc_s = 3;	return;  }  /* Process functions with zero, one, two or more arguments */  switch(c) {	case 'A':	case 'B':	case 'C':	case 'D': /* Cursor motion */		if ((f = escparms[0]) == 0) f = 1;		x = vt_win->curx;		y = vt_win->cury;		x += f * ((c == 'C') - (c == 'D'));		if (x < 0) x = 0;		if (x >= vt_win->xs) x = vt_win->xs - 1;		if (c == 'B') { /* Down. */			y += f;			if (y >= vt_win->ys) y = vt_win->ys - 1;			if (y >= newy2 + 1) y = newy2;		}		if (c == 'A') { /* Up. */			y -= f;	 		if (y < 0) y = 0;			if (y <= newy1 - 1) y = newy1;		}			wlocate(vt_win, x, y);		break;	case 'K': /* Line erasing */		switch(escparms[0]) {			case 0:				wclreol(vt_win);				break;			case 1:				wclrbol(vt_win);				break;			case 2:				wclrel(vt_win);				break;		}		break;	case 'J': /* Screen erasing */		x = vt_win->color;		y = vt_win->attr;		if (vt_type == ANSI) {			wsetattr(vt_win, XA_NORMAL);			wsetfgcol(vt_win, WHITE);			wsetbgcol(vt_win, BLACK);		}		switch(escparms[0]) {			case 0:				wclreos(vt_win);				break;			case 1:				wclrbos(vt_win);				break;			case 2:				winclr(vt_win);				break;		}		if (vt_type == ANSI) {			vt_win->color = x;			vt_win->attr = y;		}

⌨️ 快捷键说明

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