/usr/include/crystalspace-2.0/csutil/ansiparse.h is in libcrystalspace-dev 2.0+dfsg-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | /*
Copyright (C) 2005 by Jorrit Tyberghein
(C) 2005 by Frank Richter
(C) 2006 by Marten Svanfeldt
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __CS_CSUTIL_ANSIPARSE_H__
#define __CS_CSUTIL_ANSIPARSE_H__
/**\file
* Helper to parse a string for ANSI codes.
*/
/**\addtogroup util
* @{ */
/// Helper to parse a string for ANSI codes.
class CS_CRYSTALSPACE_EXPORT csAnsiParser
{
public:
/// Identifier for the ANSI command
enum Command
{
/// Command was unrecognized
cmdUnknown,
/// Reset all attributes
cmdFormatAttrReset,
/// 'Enable attribute'
cmdFormatAttrEnable,
/// 'Disable attribute'
cmdFormatAttrDisable,
/// 'Set foreground color'
cmdFormatAttrForeground,
/// 'Set background color'
cmdFormatAttrBackground,
/// 'Clear screen'
cmdClearScreen,
/// 'Clear end of line'
cmdClearLine,
/// 'Set cursor position'
cmdCursorSetPosition,
/// Move cursor specified number of lines and columns relative to current position
cmdCursorMoveRelative
};
/// Classification of the command sequence
enum CommandClass
{
/// No ANSI sequence was found
classNone,
/// An ANSI sequence was found, but not recognized.
classUnknown,
/// A formatting sequence was found.
classFormat,
/// A screen or line clear sequence was found.
classClear,
/// A cursor movement sequence was found.
classCursor
};
/**
* Types of attributes in the cmdFormatAttrEnable/cmdFormatAttrBackground
* command
*/
enum FormatAttr
{
/// 'Bold' attribute
attrBold,
/// 'Italics' attribute
attrItalics,
/// 'Underline' attribute
attrUnderline,
/// 'Blink' attribute
attrBlink,
/// 'Reverse' attribute
attrReverse,
/// 'Strikethrough' attribute
attrStrikethrough,
/// 'Dim' attribute
attrDim,
/// 'Invisible' attribute
attrInvisible
};
/// Values for foreground/background color
enum FormatColor
{
/// None specified
colNone = -1,
/// Black
colBlack,
/// Red
colRed,
/// Green
colGreen,
/// Yellow
colYellow,
/// Blue
colBlue,
/// Magenta
colMagenta,
/// Cyan
colCyan,
/// White
colWhite
};
struct CursorParams
{
/// Column
int x;
/// Line
int y;
};
/// Parameters to ANSI command
struct CommandParams
{
union
{
/// Color for cmdFormatAttrForeground and cmdFormatAttrBackground commands
FormatColor colorVal;
/// Attribute for cmdFormatAttrEnable and cmdFormatAttrDisable commands
FormatAttr attrVal;
/// Attribute for cmdCursor*
CursorParams cursorVal;
};
};
/**
* Parse a string for ANSI codes.
* Looks if a string contains an ANSI code sequence at the beginning.
* If yes, the ansiCommandLen parameter is filled with the length of the
* sequence.
* \param str String to parse.
* \param ansiCommandLen Returns number of chars that the ANSI command takes
* up.
* \param cmdClass Returns the ANSI command class.
* \param textLen Contains the number of chars up to the next ANSI
* sequence or the end of the string if no sequence was found.
* \return Whether the parsing was successful.
*/
static bool ParseAnsi (const char* str, size_t& ansiCommandLen,
CommandClass& cmdClass, size_t& textLen);
/**
* Decode an ANSI code sequence.
* Decodes a part of an ANSI code sequence, if known.
* \remark Multiple sequences might occur, repeated call this function
* until <tt>false</tt> is returned.
* \param cmd String to decode. Updated to point to the start
* of the next sequence part.
* \param cmdLen Returns length of the command in chars.
* \param command The decoded command.
* \param commandParams Parameters for the decoded command.
* \return Whether the decoding was successful.
*/
static bool DecodeCommand (const char*& cmd, size_t& cmdLen,
Command& command, CommandParams& commandParams);
};
/** @} */
#endif // __CS_CSUTIL_ANSIPARSE_H__
|