summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-05-15 14:50:40 (UTC)
committer llornkcor <llornkcor>2002-05-15 14:50:40 (UTC)
commit7658cbe0e8d0c7e86871d6e18506ff29eb594e4b (patch) (side-by-side diff)
tree599e1fa2d20d45ced8e1d04934b68ebafa436ec0
parent7977d9c5793100040b645974be1573572a550f62 (diff)
downloadopie-7658cbe0e8d0c7e86871d6e18506ff29eb594e4b.zip
opie-7658cbe0e8d0c7e86871d6e18506ff29eb594e4b.tar.gz
opie-7658cbe0e8d0c7e86871d6e18506ff29eb594e4b.tar.bz2
added fugly hack for sending ^ sequences for input methods.. thanks to Max and Gonz
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/apps/embeddedkonsole/TEmuVt102.cpp41
1 files changed, 35 insertions, 6 deletions
diff --git a/core/apps/embeddedkonsole/TEmuVt102.cpp b/core/apps/embeddedkonsole/TEmuVt102.cpp
index 752c49f..275c18d 100644
--- a/core/apps/embeddedkonsole/TEmuVt102.cpp
+++ b/core/apps/embeddedkonsole/TEmuVt102.cpp
@@ -1,208 +1,208 @@
/* ------------------------------------------------------------------------- */
/* */
/* [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 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>
/* 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 32
void TEmuVt102::initTokenizer()
{ int i; UINT8* s;
for(i = 0; i < 256; i++) tbl[ i] = 0;
@@ -554,438 +554,467 @@ void TEmuVt102::tau( int token, int p, int q )
case TY_CSI_PR('l', 47) : resetMode (MODE_AppScreen); break; //VT100
case TY_CSI_PR('h', 1000) : setMode (MODE_Mouse1000); break; //XTERM
case TY_CSI_PR('l', 1000) : resetMode (MODE_Mouse1000); break; //XTERM
case TY_CSI_PR('s', 1000) : saveMode (MODE_Mouse1000); break; //XTERM
case TY_CSI_PR('r', 1000) : restoreMode (MODE_Mouse1000); break; //XTERM
case TY_CSI_PR('h', 1001) : /* IGNORED: hilite mouse tracking */ break; //XTERM
case TY_CSI_PR('l', 1001) : /* IGNORED: hilite mouse tracking */ break; //XTERM
case TY_CSI_PR('s', 1001) : /* IGNORED: hilite mouse tracking */ break; //XTERM
case TY_CSI_PR('r', 1001) : /* IGNORED: hilite mouse tracking */ break; //XTERM
case TY_CSI_PR('h', 1047) : setMode (MODE_AppScreen); break; //XTERM
case TY_CSI_PR('l', 1047) : resetMode (MODE_AppScreen); break; //XTERM
//FIXME: Unitoken: save translations
case TY_CSI_PR('h', 1048) : saveCursor ( ); break; //XTERM
case TY_CSI_PR('l', 1048) : restoreCursor ( ); break; //XTERM
//FIXME: every once new sequences like this pop up in xterm.
// Here's a guess of what they could mean.
case TY_CSI_PR('h', 1049) : setMode (MODE_AppScreen); break; //XTERM
case TY_CSI_PR('l', 1049) : resetMode (MODE_AppScreen); break; //XTERM
//FIXME: when changing between vt52 and ansi mode evtl do some resetting.
case TY_VT52__('A' ) : scr->cursorUp ( 1); break; //VT52
case TY_VT52__('B' ) : scr->cursorDown ( 1); break; //VT52
case TY_VT52__('C' ) : scr->cursorRight ( 1); break; //VT52
case TY_VT52__('D' ) : scr->cursorLeft ( 1); break; //VT52
case TY_VT52__('F' ) : setAndUseCharset (0, '0'); break; //VT52
case TY_VT52__('G' ) : setAndUseCharset (0, 'B'); break; //VT52
case TY_VT52__('H' ) : scr->setCursorYX (1,1 ); break; //VT52
case TY_VT52__('I' ) : scr->reverseIndex ( ); break; //VT52
case TY_VT52__('J' ) : scr->clearToEndOfScreen ( ); break; //VT52
case TY_VT52__('K' ) : scr->clearToEndOfLine ( ); break; //VT52
case TY_VT52__('Y' ) : scr->setCursorYX (p-31,q-31 ); break; //VT52
case TY_VT52__('Z' ) : reportTerminalType ( ); break; //VT52
case TY_VT52__('<' ) : setMode (MODE_Ansi ); break; //VT52
case TY_VT52__('=' ) : setMode (MODE_AppKeyPad); break; //VT52
case TY_VT52__('>' ) : resetMode (MODE_AppKeyPad); break; //VT52
default : ReportErrorToken(); break;
};
}
/* ------------------------------------------------------------------------- */
/* */
/* Terminal to Host protocol */
/* */
/* ------------------------------------------------------------------------- */
/*
Outgoing bytes originate from several sources:
- Replies to Enquieries.
- Mouse Events
- Keyboard Events
*/
/*!
*/
void TEmuVt102::sendString(const char* s)
{
emit sndBlock(s,strlen(s));
}
// Replies ----------------------------------------------------------------- --
// This section copes with replies send as response to an enquiery control code.
/*!
*/
void TEmuVt102::reportCursorPosition()
{ char tmp[20];
sprintf(tmp,"\033[%d;%dR",scr->getCursorY()+1,scr->getCursorX()+1);
sendString(tmp);
}
/*
What follows here is rather obsolete and faked stuff.
The correspondent enquieries are neverthenless issued.
*/
/*!
*/
void TEmuVt102::reportTerminalType()
{
//FIXME: should change?
if (getMode(MODE_Ansi))
// sendString("\033[?1;2c"); // I'm a VT100 with AP0 //FIXME: send only in response to ^[[0c
sendString("\033[>0;115;0c"); // I'm a VT220 //FIXME: send only in response to ^[[>c
else
sendString("\033/Z"); // I'm a VT52
}
void TEmuVt102::reportTerminalParms(int p)
// DECREPTPARM
{ char tmp[100];
sprintf(tmp,"\033[%d;1;1;112;112;1;0x",p); // not really true.
sendString(tmp);
}
/*!
*/
void TEmuVt102::reportStatus()
{
sendString("\033[0n"); //VT100. Device status report. 0 = Ready.
}
/*!
*/
#define ANSWER_BACK "" // This is really obsolete VT100 stuff.
void TEmuVt102::reportAnswerBack()
{
sendString(ANSWER_BACK);
}
// Mouse Handling ---------------------------------------------------------- --
/*!
Mouse clicks are possibly reported to the client
application if it has issued interest in them.
They are normally consumed by the widget for copy
and paste, but may be propagated from the widget
when gui->setMouseMarks is set via setMode(MODE_Mouse1000).
`x',`y' are 1-based.
`ev' (event) indicates the button pressed (0-2)
or a general mouse release (3).
*/
void TEmuVt102::onMouse( int cb, int cx, int cy )
{ char tmp[20];
if (!connected) return;
sprintf(tmp,"\033[M%c%c%c",cb+040,cx+040,cy+040);
sendString(tmp);
}
// Keyboard Handling ------------------------------------------------------- --
#define encodeMode(M,B) BITS(B,getMode(M))
#define encodeStat(M,B) BITS(B,((ev->state() & (M)) == (M)))
/*
Keyboard event handling has been simplified somewhat by pushing
the complications towards a configuration file [see KeyTrans class].
*/
void TEmuVt102::onKeyPress( QKeyEvent* ev )
{
if (!connected) return; // someone else gets the keys
//printf("State/Key: 0x%04x 0x%04x (%d,%d)\n",ev->state(),ev->key(),ev->text().length(),ev->text().length()?ev->text().ascii()[0]:0);
// revert to non-history when typing
if (scr->getHistCursor() != scr->getHistLines());
scr->setHistCursor(scr->getHistLines());
// lookup in keyboard translation table ...
int cmd; const char* txt; int len;
if (keytrans->findEntry(ev->key(), encodeMode(MODE_NewLine , BITS_NewLine ) + // OLD,
encodeMode(MODE_Ansi , BITS_Ansi ) + // OBSOLETE,
encodeMode(MODE_AppCuKeys, BITS_AppCuKeys ) + // VT100 stuff
encodeStat(ControlButton , BITS_Control ) +
encodeStat(ShiftButton , BITS_Shift ) +
encodeStat(AltButton , BITS_Alt ),
&cmd, &txt, &len ))
//printf("cmd: %d, %s, %d\n",cmd,txt,len);
switch(cmd) // ... and execute if found.
{
case CMD_emitSelection : gui->emitSelection(); return;
case CMD_scrollPageUp : gui->doScroll(-gui->Lines()/2); return;
case CMD_scrollPageDown : gui->doScroll(+gui->Lines()/2); return;
case CMD_scrollLineUp : gui->doScroll(-1 ); return;
case CMD_scrollLineDown : gui->doScroll(+1 ); return;
case CMD_send : emit sndBlock(txt,len); return;
case CMD_prevSession : emit prevSession(); return;
case CMD_nextSession : emit nextSession(); return;
}
// fall back handling
if (!ev->text().isEmpty())
{
if (ev->state() & AltButton) sendString("\033"); // ESC, this is the ALT prefix
- QCString s = codec->fromUnicode(ev->text()); // encode for application
- emit sndBlock(s.data(),s.length()); // we may well have s.length() > 1
+ /// very hacky
+ if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='A')) sendString("\01");
+ else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='B')) sendString("\02");
+ else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='C')) sendString("\03");
+ else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='D')) sendString("\04");
+ else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='E')) sendString("\05");
+ else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='F')) sendString("\06");
+ else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='G')) sendString("\07");
+ else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='H')) sendString("\010");
+ else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='I')) sendString("\011");
+ else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='J')) sendString("\012");
+ else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='K')) sendString("\013");
+ else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='L')) sendString("\014");
+ else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='M')) sendString("\015");
+ else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='N')) sendString("\016");
+ else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='O')) sendString("\017");
+ else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='P')) sendString("\020");
+ else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='Q')) sendString("\021");
+ else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='R')) sendString("\022");
+ else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='S')) sendString("\023");
+ else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='T')) sendString("\024");
+ else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='U')) sendString("\025");
+ else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='V')) sendString("\026");
+ else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='W')) sendString("\027");
+ else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='X')) sendString("\030");
+ else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='Y')) sendString("\031");
+ else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='Z')) sendString("\032");
+ else {
+ QCString s = codec->fromUnicode(ev->text()); // encode for application
+ emit sndBlock(s.data(),s.length()); // we may well have s.length() > 1
+ }
return;
}
}
/* ------------------------------------------------------------------------- */
/* */
/* VT100 Charsets */
/* */
/* ------------------------------------------------------------------------- */
// Character Set Conversion ------------------------------------------------ --
/*
The processing contains a VT100 specific code translation layer.
It's still in use and mainly responsible for the line drawing graphics.
These and some other glyphs are assigned to codes (0x5f-0xfe)
normally occupied by the latin letters. Since this codes also
appear within control sequences, the extra code conversion
does not permute with the tokenizer and is placed behind it
in the pipeline. It only applies to tokens, which represent
plain characters.
This conversion it eventually continued in TEWidget.C, since
it might involve VT100 enhanced fonts, which have these
particular glyphs allocated in (0x00-0x1f) in their code page.
*/
#define CHARSET charset[scr==screen[1]]
// Apply current character map.
unsigned short TEmuVt102::applyCharset(unsigned short c)
{
if (CHARSET.graphic && 0x5f <= c && c <= 0x7e) return vt100_graphics[c-0x5f];
if (CHARSET.pound && c == '#' ) return 0xa3; //This mode is obsolete
return c;
}
/*
"Charset" related part of the emulation state.
This configures the VT100 charset filter.
While most operation work on the current screen,
the following two are different.
*/
void TEmuVt102::resetCharset(int scrno)
{
charset[scrno].cu_cs = 0;
strncpy(charset[scrno].charset,"BBBB",4);
charset[scrno].sa_graphic = FALSE;
charset[scrno].sa_pound = FALSE;
charset[scrno].graphic = FALSE;
charset[scrno].pound = FALSE;
}
/*!
*/
void TEmuVt102::setCharset(int n, int cs) // on both screens.
{
charset[0].charset[n&3] = cs; useCharset(charset[0].cu_cs);
charset[1].charset[n&3] = cs; useCharset(charset[1].cu_cs);
}
/*!
*/
void TEmuVt102::setAndUseCharset(int n, int cs)
{
CHARSET.charset[n&3] = cs;
useCharset(n&3);
}
/*!
*/
void TEmuVt102::useCharset(int n)
{
CHARSET.cu_cs = n&3;
CHARSET.graphic = (CHARSET.charset[n&3] == '0');
CHARSET.pound = (CHARSET.charset[n&3] == 'A'); //This mode is obsolete
}
/*! Save the cursor position and the rendition attribute settings. */
void TEmuVt102::saveCursor()
{
CHARSET.sa_graphic = CHARSET.graphic;
CHARSET.sa_pound = CHARSET.pound; //This mode is obsolete
// we are not clear about these
//sa_charset = charsets[cScreen->charset];
//sa_charset_num = cScreen->charset;
scr->saveCursor();
}
/*! Restore the cursor position and the rendition attribute settings. */
void TEmuVt102::restoreCursor()
{
CHARSET.graphic = CHARSET.sa_graphic;
CHARSET.pound = CHARSET.sa_pound; //This mode is obsolete
scr->restoreCursor();
}
/* ------------------------------------------------------------------------- */
/* */
/* Mode Operations */
/* */
/* ------------------------------------------------------------------------- */
/*
Some of the emulations state is either added to the state of the screens.
This causes some scoping problems, since different emulations choose to
located the mode either to the current screen or to both.
For strange reasons, the extend of the rendition attributes ranges over
all screens and not over the actual screen.
We decided on the precise precise extend, somehow.
*/
// "Mode" related part of the state. These are all booleans.
void TEmuVt102::resetModes()
{
resetMode(MODE_Mouse1000); saveMode(MODE_Mouse1000);
resetMode(MODE_AppScreen); saveMode(MODE_AppScreen);
// here come obsolete modes
resetMode(MODE_AppCuKeys); saveMode(MODE_AppCuKeys);
resetMode(MODE_NewLine );
setMode(MODE_Ansi );
}
void TEmuVt102::setMode(int m)
{
currParm.mode[m] = TRUE;
switch (m)
{
case MODE_Mouse1000 : gui->setMouseMarks(FALSE);
break;
case MODE_AppScreen : screen[1]->clearSelection();
screen[1]->clearEntireScreen();
setScreen(1);
- break;
+ break;
}
if (m < MODES_SCREEN || m == MODE_NewLine)
{
screen[0]->setMode(m);
screen[1]->setMode(m);
}
}
void TEmuVt102::resetMode(int m)
{
currParm.mode[m] = FALSE;
switch (m)
{
case MODE_Mouse1000 : gui->setMouseMarks(TRUE);
break;
case MODE_AppScreen : screen[0]->clearSelection();
setScreen(0);
break;
}
if (m < MODES_SCREEN || m == MODE_NewLine)
{
screen[0]->resetMode(m);
screen[1]->resetMode(m);
}
}
void TEmuVt102::saveMode(int m)
{
saveParm.mode[m] = currParm.mode[m];
}
void TEmuVt102::restoreMode(int m)
{
if(saveParm.mode[m]) setMode(m); else resetMode(m);
}
BOOL TEmuVt102::getMode(int m)
{
return currParm.mode[m];
}
void TEmuVt102::setConnect(bool c)
{
TEmulation::setConnect(c);
if (c)
{ // refresh mouse mode
if (getMode(MODE_Mouse1000))
setMode(MODE_Mouse1000);
else
resetMode(MODE_Mouse1000);
}
}
/* ------------------------------------------------------------------------- */
/* */
/* Diagnostic */
/* */
/* ------------------------------------------------------------------------- */
/*! shows the contents of the scan buffer.
This functions is used for diagnostics. It is called by \e ReportErrorToken
to inform about strings that cannot be decoded or handled by the emulation.
\sa ReportErrorToken
*/
/*!
*/
static void hexdump(int* s, int len)
{ int i;
for (i = 0; i < len; i++)
{
if (s[i] == '\\')
printf("\\\\");
else
if ((s[i]) > 32 && s[i] < 127)
printf("%c",s[i]);
else
printf("\\%04x(hex)",s[i]);
}
}
void TEmuVt102::scan_buffer_report()
{
if (ppos == 0 || ppos == 1 && (pbuf[0] & 0xff) >= 32) return;
printf("token: "); hexdump(pbuf,ppos); printf("\n");
}
/*!
*/
void TEmuVt102::ReportErrorToken()
{
printf("undecodable "); scan_buffer_report();
}