ansiprsr.cpp
上传用户:haiweijt
上传日期:2018-02-23
资源大小:8195k
文件大小:40k
- ///////////////////////////////////////////////////////////////////////////////
- //Telnet Win32 : an ANSI telnet client.
- //Copyright (C) 1998-2000 Paul Brannan
- //Copyright (C) 1998 I.Ioannou
- //Copyright (C) 1997 Brad Johnson
- //
- //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.
- //
- //This program is distributed in the hope that it will be useful,
- //but WITHOUT ANY WARRANTY; without even the implied warranty of
- //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- //GNU General Public License for more details.
- //
- //You should have received a copy of the GNU General Public License
- //along with this program; if not, write to the Free Software
- //Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- //
- //I.Ioannou
- //roryt@hol.gr
- //
- ///////////////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////////////
- //
- // Module: ansiprsr.cpp
- //
- // Contents: ANSI parser base class
- //
- // Product: telnet
- //
- // Revisions: August 30, 1998 Paul Brannan <pbranna@clemson.edu>
- // July 29, 1998 pbranna@clemson.edu
- // June 15, 1998 pbranna@clemson.edu
- // May 19, 1998 pbranna@clemson.edu
- // 24 Dec, 1997 Andrey.V.Smilianets
- // 05. Sep.1997 roryt@hol.gr (I.Ioannou)
- // 11.May.1997 roryt@hol.gr (I.Ioannou)
- // 6.April.1997 roryt@hol.gr (I.Ioannou)
- // 5.April.1997 jbj@nounname.com
- // 30.M剅z.1997 Titus_Boxberg@public.uni-hamburg.de
- // 14.Sept.1996 jbj@nounname.com
- // Version 2.0
- //
- // 13.Jul.1995 igor.milavec@uni-lj.si
- // Original code
- //
- ///////////////////////////////////////////////////////////////////////////////
- #include <windows.h>
- #include <string.h>
- #include "ansiprsr.h"
- // The constructor now takes different arguments and initializes different
- // variables (Paul Brannan 6/15/98)
- TANSIParser::TANSIParser(TConsole &RefConsole, KeyTranslator &RefKeyTrans,
- TScroller &RefScroller, TNetwork &RefNetwork,
- TCharmap &RefCharmap):
- TParser(RefConsole, RefKeyTrans, RefScroller, RefNetwork, RefCharmap) {
- Init();
- iSavedAttributes = (unsigned char) 7;
- // must also check to make sure the string is non-NULL
- // (Paul Brannan 5/8/98)
- if ((ini.get_dumpfile() != NULL) && (*ini.get_dumpfile() != ' ')){
- dumpfile = fopen(ini.get_dumpfile(), "wb");
- }else {
- dumpfile = NULL;
- }
- InPrintMode = 0;
- printfile = NULL;
- fast_write = ini.get_fast_write(); // Paul Brannan 6/28/98
- Scroller.init(&StripBuffer);
- }
- TANSIParser::~TANSIParser(){
- if (dumpfile) fclose (dumpfile);
- // Added I.Ioannou 06 April, 1997
- if (printfile != NULL) fclose (printfile);
- }
- // Created Init() function to initialize the parser but not clear the screen
- // (Paul Brannan 9/23/98)
- void TANSIParser::Init() {
- // Paul Brannan 6/25/98
- map_G0 = 'B'; map_G1 = 'B';
- Charmap.setmap(map_G0);
- current_map = 'B';
- ignore_margins = 0;
- vt52_mode = 0;
- print_ctrl = 0;
- newline_mode = false;
- KeyTrans.clear_ext_mode();
- iSavedCurY = 0; // Reset Variables
- iSavedCurX = 0;
- inGraphMode = 0;
- Console.SetScroll(-1, -1);
- Console.Normal(); // Reset Attributes
- // Set tabs stops
- resetTabStops();
- }
- void TANSIParser::ResetTerminal() {
- Init();
- Console.ClearScreen(); // Clear Screen
- Console.SetRawCursorPosition(0,0); // Home Cursor
- }
- void TANSIParser::SaveCurY(int iY){
- iSavedCurY=iY;
- }
- void TANSIParser::SaveCurX(int iX){
- iSavedCurX=iX;
- }
- void TANSIParser::resetTabStops() {
- for(int j = 0; j < MAX_TAB_POSITIONS; j++) {
- tab_stops[j] = 8 + j - (j%8);
- }
- }
- void TANSIParser::ConSetAttribute(unsigned char TextAttrib){
- // Paul Brannan 5/8/98
- // Made this go a little bit faster by changing from switch{} to an array
- // for the colors
- if(TextAttrib >= 30) {
- if(TextAttrib <= 37) {
- Console.SetForeground(ANSIColors[TextAttrib-30]);
- return;
- } else if((TextAttrib >= 40) && (TextAttrib <= 47)) {
- Console.SetBackground(ANSIColors[TextAttrib-40]);
- return;
- }
- }
-
- switch (TextAttrib){
- // Text Attributes
- case 0: Console.Normal(); break; // Normal video
- case 1: Console.HighVideo(); break; // High video
- case 2: Console.LowVideo(); break; // Low video
- case 4: Console.UnderlineOn(); break; // Underline on (I.Ioannou)
- case 5: Console.BlinkOn(); break; // Blink video
- // Corrected by I.Ioannou 11 May, 1997
- case 7: Console.ReverseOn(); break; // Reverse video
- case 8: break; // hidden
- // All from 10 thru 27 are hacked from linux kernel
- // I.Ioannou 06 April, 1997
- case 10:
- // I.Ioannou 04 Sep 1997 turn on/off high bit
- inGraphMode = 0;
- print_ctrl = 0;
- Charmap.setmap(current_map ? map_G1:map_G0); // Paul Brannan 6/25/98
- break; // ANSI X3.64-1979 (SCO-ish?)
- // Select primary font,
- // don't display control chars
- // if defined, don't set
- // bit 8 on output (normal)
- case 11:
- inGraphMode = 0;
- print_ctrl = 1;
- Charmap.setmap(0); // Paul Brannan 6/25/98
- break; // ANSI X3.64-1979 (SCO-ish?)
- // Select first alternate font,
- // let chars < 32 be displayed
- // as ROM chars
- case 12:
- inGraphMode = 1;
- print_ctrl = 1;
- Charmap.setmap(0); // Paul Brannan 6/25/98
- break; // ANSI X3.64-1979 (SCO-ish?)
- // Select second alternate font,
- // toggle high bit before
- // displaying as ROM char.
-
- case 21: // not really Low video
- case 22: Console.LowVideo(); break; // but this works good also
- case 24: Console.UnderlineOff(); break; // Underline off
- case 25: Console.BlinkOff(); break; // blink off
- // Corrected by I.Ioannou 11 May, 1997
- case 27: Console.ReverseOff(); break; //Reverse video off
- // Mutt needs this (Paul Brannan, Peter Jordan 12/31/98)
- // This is from the Linux kernel source
- case 38: /* ANSI X3.64-1979 (SCO-ish?)
- * Enables underscore, white foreground
- * with white underscore (Linux - use
- * default foreground).
- */
- Console.UnderlineOn();
- Console.SetForeground(ini.get_normal_fg());
- break;
- case 39: /* ANSI X3.64-1979 (SCO-ish?)
- * Disable underline option.
- * Reset colour to default? It did this
- * before...
- */
- Console.UnderlineOff();
- Console.SetForeground(ini.get_normal_fg());
- break;
- case 49:
- Console.SetBackground(ini.get_normal_bg());
- break;
- }
- }
- void TANSIParser::ConSetCursorPos(int x, int y) {
- if(ignore_margins)
- Console.SetRawCursorPosition(x, y);
- else
- Console.SetCursorPosition(x, y);
- }
- char* TANSIParser::GetTerminalID()
- {
- return "