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

📄 esc_seq.hpp

📁 使用BorlandC++4.5编译的一个MUD客户端程序
💻 HPP
字号:
head	2.1;access;symbols;locks; strict;comment	@// @;2.1date	95.10.24.15.52.51;	author tsurace;	state Release;branches;next	1.4;1.4date	95.10.11.21.00.23;	author tsurace;	state Beta;branches;next	1.3;1.3date	95.10.08.23.28.25;	author tsurace;	state Exp;branches;next	1.2;1.2date	95.10.07.00.34.37;	author tsurace;	state Exp;branches;next	1.1;1.1date	95.10.05.18.33.23;	author tsurace;	state Exp;branches;next	;desc@Simple cheesy parser class for a subset of VT102 language.@2.1log@Roll.@text@#ifndef ESC_SEQ_HPP
#define ESC_SEQ_HPP

#include "debug.hpp"

// ------------------------------------------------------------------------
// EscapeSequence - VT 102 escape sequence parser
//
// $Id: esc_seq.hpp 1.4 1995/10/11 21:00:23 tsurace Beta tsurace $
// $Log: esc_seq.hpp $// Revision 1.4  1995/10/11  21:00:23  tsurace// Switched to my ASSERT macro.//
// Revision 1.3  1995/10/08  23:28:25  tsurace
// Modified to allow ANSI color/attributes.
//
//
// NEWLINE
//   This is special parameters[0] = count of consecutive newlines, and
//   parameters[1]  is the next character
//
class EscapeSequence
{
  public:
    enum _Type {
        NONE,
        UNKNOWN,
        CMOVE,
        SCROLL,
        REV_NEWLINE,
        CLRSCR,
        CLREOL,
        ANSI_COLOR, // param(0) = bold? param(1) = color
    };

    // These are all the same as the ANSI codes
    enum _TextAttribute {
        CLEAR_ATTR = 0,    // Reset all attributes to default 
        BOLD    = 1,       // Bold
        UNDERLINE = 4,
        BLINKING = 5,
        REVERSE_VIDEO = 7,
        INVISIBLE = 8,
        FG_BLACK   = 30,   // Foreground colors
        FG_RED     = 31,
        FG_GREEN   = 32,
        FG_YELLOW  = 33,
        FG_BLUE    = 34,
        FG_MAGENTA = 35,
        FG_CYAN    = 36,
        FG_WHITE   = 37,
    };
        
        
    EscapeSequence(char * buf);
    _Type   Type() const;
    int     IsComplete() const;
    int     IsEscapeSequence() const;
    int     Parameter(int which) const;
    int     ParameterCount() const;

  protected:
    _Type _type;
    int   _isComplete;
    int   _isEscapeSequence;
    int   _parameters[20];   // Up to 20 of 'em
    int   _nParameters;

    // Helper functions
    int  _EndOfString(char * buf);
    void _SetType(_Type type);
    
    // Recursive descent parser for subset of VT102 escape code language:
    // int _ParseNewlineSequence(char * buf); // Obsolete
    int _ParseEscapeSequence(char * buf);
    int _ScrollReverse(char * buf);
    int _LeftSquareBracket(char * buf);

    // Called from LeftSquareBracket:
    int _ClearScreen(char * buf); 
    int _ClearEOL(char * buf);
    int _GetParameters(char ** buf);

    int _GetType(char terminator);

    // Parameterized types
    int _CursorMove(char * buf);
    int _Scroll(char * buf);
};


// ------------------------------------------------------------------------
// Type - returns the type of escape sequence.
//
// Type is always NONE until the sequence IsComplete.
//
inline EscapeSequence::_Type EscapeSequence::Type() const
{
    return _type;
};

// ------------------------------------------------------------------------
// IsComplete - returns nonzero if the sequence is complete.  Extra
//   characters after the escape sequence are ignored.
//
inline int EscapeSequence::IsComplete() const
{
    return _isComplete;
}

// IsEscapeSequence - if this is not a valid escape sequence, this 
//   returns 0.  
//
inline int EscapeSequence::IsEscapeSequence() const
{
    return _isEscapeSequence;
}

inline int EscapeSequence::Parameter(int which) const
{
    ASSERT(which >= 0, "Negative array index not allowed");
    ASSERT(which < _nParameters, "Index past end of array");
    
    return _parameters[which];
}

inline int EscapeSequence::ParameterCount() const
{
    return _nParameters;
}

// ------------------------------------------------------------------------
// _EndOfString - returns nonzero at the NULL at the end of a string
//
inline int EscapeSequence::_EndOfString(char * buf)
{
    return (*buf == '\0');
}



#endif // ESC_SEQ_HPP
@1.4log@Switched to my ASSERT macro.@text@d9 5a13 2// $Id: esc_seq.hpp 1.3 1995/10/08 23:28:25 tsurace Exp tsurace $// $Log: esc_seq.hpp $@1.3log@Modified to allow ANSI color/attributes.@text@d4 2d9 5a13 2// $Id$// $Log$d118 3a120 1    assert(which >= 0 && which < _nParameters); // Parameter out of bounds@1.2log@Changed name of scroll-reverse definition.@text@d7 3d25 19a43 2        BOLD_ON,        BOLD_OFF,d46 1d51 2a52 1    int     Parameter(int which);d58 2a59 1    int   _parameters[2];d74 1a74 3    int _BoldOn(char * buf);    int _BoldOff(char * buf);    int _TwoParameters(char * buf);d76 3a78 1    // Two-parameter typesd111 1a111 1inline int EscapeSequence::Parameter(int which)d113 1a113 1    assert(which >= 0 && which < 2); // Parameter out of boundsd115 5@1.1log@Initial revision@text@d19 1a19 1        SCR_REV,d93 9@

⌨️ 快捷键说明

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