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

📄 temuvt102.cpp

📁 Trolltech公司发布的图形界面操作系统。可在qt-embedded-2.3.7平台上编译为嵌入式图形界面操作系统。
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/* ------------------------------------------------------------------------- *//*                                                                           *//* [TEmuVt102.C]            VT102 Terminal Emulation                         *//*                                                                           *//* ------------------------------------------------------------------------- *//*                                                                           *//* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de>           *//*                                                                           *//* This file is part of Konsole - an X terminal for KDE                      *//*                                                                           *//* ------------------------------------------------------------------------- *//*									      *//* Ported Konsole to Qt/Embedded                                              *//*									      *//* Copyright (C) 2000 by John Ryland <jryland@trolltech.com>                  *//*									      *//* -------------------------------------------------------------------------- *//* \class TEmuVt102   \brief The TEmuVt102 class is the actual emulation for Konsole.   \sa TEWidget \sa TEScreen*/#include "TEmuVt102.h"#include "TEWidget.h"#include "TEScreen.h"#include "keytrans.h"#include <stdio.h>#include <unistd.h>#include <qkeycode.h>#include <qtextcodec.h>#include <qtopia/qpemenubar.h>/* VT102 Terminal Emulation   This class puts together the screens, the pty and the widget to a   complete terminal emulation. Beside combining it's componentes, it   handles the emulations's protocol.   This module consists of the following sections:   - Constructor/Destructor   - Incoming Bytes Event pipeline   - Outgoing Bytes     - Mouse Events     - Keyboard Events   - Modes and Charset State   - Diagnostics*//* ------------------------------------------------------------------------- *//*                                                                           *//*                       Constructor / Destructor                            *//*                                                                           *//* ------------------------------------------------------------------------- *//*   Nothing really intesting happens here.*//**/TEmuVt102::TEmuVt102(TEWidget* gui) : TEmulation(gui){  QObject::connect(gui,SIGNAL(mouseSignal(int,int,int)),                   this,SLOT(onMouse(int,int,int)));  initTokenizer();  reset();}/**/TEmuVt102::~TEmuVt102(){}/**/void TEmuVt102::reset(){  resetToken();  resetModes();  resetCharset(0); screen[0]->reset();  resetCharset(1); screen[0]->reset();  setCodec(0);  setKeytrans("linux.keytab");}/* ------------------------------------------------------------------------- *//*                                                                           *//*                     Processing the incoming byte stream                   *//*                                                                           *//* ------------------------------------------------------------------------- *//* Incoming Bytes Event pipeline   This section deals with decoding the incoming character stream.   Decoding means here, that the stream is first seperated into `tokens'   which are then mapped to a `meaning' provided as operations by the   `TEScreen' class or by the emulation class itself.   The pipeline proceeds as follows:   - Tokenizing the ESC codes (onRcvChar)   - VT100 code page translation of plain characters (applyCharset)   - Interpretation of ESC codes (tau)   The escape codes and their meaning are described in the   technical reference of this program.*/// Tokens ------------------------------------------------------------------ --/*   Since the tokens are the central notion if this section, we've put them   in front. They provide the syntactical elements used to represent the   terminals operations as byte sequences.   They are encodes here into a single machine word, so that we can later   switch over them easily. Depending on the token itself, additional   argument variables are filled with parameter values.   The tokens are defined below:   - CHR        - Printable characters     (32..255 but DEL (=127))   - CTL        - Control characters       (0..31 but ESC (= 27), DEL)   - ESC        - Escape codes of the form <ESC><CHR but `[]()+*#'>   - ESC_DE     - Escape codes of the form <ESC><any of `()+*#%'> C   - CSI_PN     - Escape codes of the form <ESC>'['     {Pn} ';' {Pn} C   - CSI_PS     - Escape codes of the form <ESC>'['     {Pn} ';' ...  C   - CSI_PR     - Escape codes of the form <ESC>'[' '?' {Pn} ';' ...  C   - VT52       - VT52 escape codes                  - <ESC><Chr>                  - <ESC>'Y'{Pc}{Pc}   - XTE_HA     - Xterm hacks              <ESC>`]' {Pn} `;' {Text} <BEL>                  note that this is handled differently   The last two forms allow list of arguments. Since the elements of   the lists are treated individually the same way, they are passed   as individual tokens to the interpretation. Further, because the   meaning of the parameters are names (althought represented as numbers),   they are includes within the token ('N').*/#define TY_CONSTR(T,A,N) ( ((((int)N) & 0xffff) << 16) | ((((int)A) & 0xff) << 8) | (((int)T) & 0xff) )#define TY_CHR___(   )  TY_CONSTR(0,0,0)#define TY_CTL___(A  )  TY_CONSTR(1,A,0)#define TY_ESC___(A  )  TY_CONSTR(2,A,0)#define TY_ESC_CS(A,B)  TY_CONSTR(3,A,B)#define TY_ESC_DE(A  )  TY_CONSTR(4,A,0)#define TY_CSI_PS(A,N)  TY_CONSTR(5,A,N)#define TY_CSI_PN(A  )  TY_CONSTR(6,A,0)#define TY_CSI_PR(A,N)  TY_CONSTR(7,A,N)#define TY_VT52__(A  )  TY_CONSTR(8,A,0)// Tokenizer --------------------------------------------------------------- --/* The tokenizers state   The state is represented by the buffer (pbuf, ppos),   and accompanied by decoded arguments kept in (argv,argc).   Note that they are kept internal in the tokenizer.*/void TEmuVt102::resetToken(){  ppos = 0; argc = 0; argv[0] = 0; argv[1] = 0;}void TEmuVt102::addDigit(int dig){  argv[argc] = 10*argv[argc] + dig;}void TEmuVt102::addArgument(){  argc = QMIN(argc+1,MAXARGS-1);  argv[argc] = 0;}void TEmuVt102::pushToToken(int cc){  pbuf[ppos] = cc;  ppos = QMIN(ppos+1,MAXPBUF-1);}// Character Classes used while decoding#define CTL  1#define CHR  2#define CPN  4#define DIG  8#define SCS 16#define GRP 32void TEmuVt102::initTokenizer(){ int i; UINT8* s;  for(i =  0;                    i < 256; i++) tbl[ i]  = 0;  for(i =  0;                    i <  32; i++) tbl[ i] |= CTL;  for(i = 32;                    i < 256; i++) tbl[ i] |= CHR;  for(s = (UINT8*)"@ABCDGHLMPXcdfry"; *s; s++) tbl[*s] |= CPN;  for(s = (UINT8*)"0123456789"      ; *s; s++) tbl[*s] |= DIG;  for(s = (UINT8*)"()+*%"           ; *s; s++) tbl[*s] |= SCS;  for(s = (UINT8*)"()+*#[]%"        ; *s; s++) tbl[*s] |= GRP;  resetToken();}/* Ok, here comes the nasty part of the decoder.   Instead of keeping an explicit state, we deduce it from the   token scanned so far. It is then immediately combined with   the current character to form a scanning decision.   This is done by the following defines.   - P is the length of the token scanned so far.   - L (often P-1) is the position on which contents we base a decision.   - C is a character or a group of characters (taken from 'tbl').   Note that they need to applied in proper order.*/#define lec(P,L,C) (p == (P) &&                     s[(L)]         == (C))#define lun(     ) (p ==  1  &&                       cc           >= 32 )#define les(P,L,C) (p == (P) && s[L] < 256  && (tbl[s[(L)]] & (C)) == (C))#define eec(C)     (p >=  3  &&        cc                          == (C))#define ees(C)     (p >=  3  && cc < 256 &&    (tbl[  cc  ] & (C)) == (C))#define eps(C)     (p >=  3  && s[2] != '?' && cc < 256 && (tbl[  cc  ] & (C)) == (C))#define epp( )     (p >=  3  && s[2] == '?'                              )#define egt(     ) (p ==  3  && s[2] == '>'                              )#define Xpe        (ppos>=2  && pbuf[1] == ']'                           )#define Xte        (Xpe                        &&     cc           ==  7 )#define ces(C)     (            cc < 256 &&    (tbl[  cc  ] & (C)) == (C) && !Xte)#define ESC 27#define CNTL(c) ((c)-'@')// process an incoming unicode charactervoid TEmuVt102::onRcvChar(int cc){ int i;  if (cc == 127) return; //VT100: ignore.  if (ces(    CTL))  { // DEC HACK ALERT! Control Characters are allowed *within* esc sequences in VT100    // This means, they do neither a resetToken nor a pushToToken. Some of them, do    // of course. Guess this originates from a weakly layered handling of the X-on    // X-off protocol, which comes really below this level.    if (cc == CNTL('X') || cc == CNTL('Z') || cc == ESC) resetToken(); //VT100: CAN or SUB    if (cc != ESC)    { tau( TY_CTL___(cc+'@' ),    0,   0); return; }  }  pushToToken(cc); // advance the state  int* s = pbuf;  int  p = ppos;  if (getMode(MODE_Ansi)) // decide on proper action  {    if (lec(1,0,ESC)) {                                                       return; }    if (les(2,1,GRP)) {                                                       return; }    if (Xte         ) { XtermHack();                            resetToken(); return; }    if (Xpe         ) {                                                       return; }    if (lec(3,2,'?')) {                                                       return; }    if (lec(3,2,'>')) {                                                       return; }    if (lun(       )) { tau( TY_CHR___(), applyCharset(cc), 0); resetToken(); return; }    if (lec(2,0,ESC)) { tau( TY_ESC___(s[1]),    0,   0);       resetToken(); return; }    if (les(3,1,SCS)) { tau( TY_ESC_CS(s[1],s[2]),    0,   0);  resetToken(); return; }    if (lec(3,1,'#')) { tau( TY_ESC_DE(s[2]),    0,   0);       resetToken(); return; }//  if (egt(       )) { tau( TY_CSI_PG(cc       ),  '>',   0);  resetToken(); return; }    if (eps(    CPN)) { tau( TY_CSI_PN(cc), argv[0],argv[1]);   resetToken(); return; }    if (ees(    DIG)) { addDigit(cc-'0');                                     return; }    if (eec(    ';')) { addArgument();                                        return; }    for (i=0;i<=argc;i++)    if (epp(       ))   tau( TY_CSI_PR(cc,argv[i]),    0,   0);          else                        tau( TY_CSI_PS(cc,argv[i]),    0,   0);    resetToken();  }  else // mode VT52  {    if (lec(1,0,ESC))                                                      return;    if (les(1,0,CHR)) { tau( TY_CHR___(       ), s[0],   0); resetToken(); return; }    if (lec(2,1,'Y'))                                                      return;    if (lec(3,1,'Y'))                                                      return;    if (p < 4)        { tau( TY_VT52__(s[1]   ),    0,   0); resetToken(); return; }                        tau( TY_VT52__(s[1]   ), s[2],s[3]); resetToken(); return;  }}void TEmuVt102::XtermHack(){ int i,arg = 0;  for (i = 2; i < ppos && '0'<=pbuf[i] && pbuf[i]<'9' ; i++)    arg = 10*arg + (pbuf[i]-'0');  if (pbuf[i] != ';') { ReportErrorToken(); return; }  QChar *str = new QChar[ppos-i-2];  for (int j = 0; j < ppos-i-2; j++) str[j] = pbuf[i+1+j];  QString unistr(str,ppos-i-2);  // arg == 1 doesn't change the title. In XTerm it only changes the icon name  // (btw: arg=0 changes title and icon, arg=1 only icon, arg=2 only title  if (arg == 0 || arg == 2) emit changeTitle(arg,unistr);  delete [] str;}// Interpreting Codes ---------------------------------------------------------/*   Now that the incoming character stream is properly tokenized,   meaning is assigned to them. These are either operations of   the current screen, or of the emulation class itself.   The token to be interpreteted comes in as a machine word   possibly accompanied by two parameters.   Likewise, the operations assigned to, come with up to two   arguments. One could consider to make up a proper table   from the function below.   The technical reference manual provides more informations   about this mapping.*/

⌨️ 快捷键说明

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