78 lines
2.7 KiB
C++
78 lines
2.7 KiB
C++
|
|
//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
|
// FILE : Parser.h
|
|
// AUTHOR : Catalin Cocos
|
|
//__________________________________________________________________________________________________
|
|
|
|
#ifndef __PARSER__
|
|
#define __PARSER__
|
|
|
|
//__________________________________________________________________________________________________
|
|
// defines
|
|
//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
|
//#define DWORD unsigned long
|
|
|
|
#define CTP_TEXT 0x00 // fixed value, do not alter
|
|
#define CTP_SEPARATOR 0x01
|
|
#define CTP_NEWLINE 0x02
|
|
#define CTP_COMMENT 0x04
|
|
#define CTP_LINE_COMMENT 0x08
|
|
#define CTP_EOF 0x10
|
|
#define CTP_WORD_WRAPPER 0x20
|
|
#define CTP_USER_CODE 0x40
|
|
|
|
#define CTP_MAX_USER_CODE 26
|
|
#define CTP_UserCode(X) ( CTP_USER_CODE << X )
|
|
|
|
//__________________________________________________________________________________________________
|
|
// the parser
|
|
//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
|
class CTextParser
|
|
{
|
|
unsigned char* m_arFile, * m_pFileEnd, *m_pWord, *m_pCrt, *m_pCountStart;
|
|
DWORD m_nCode, m_nCountCode;
|
|
DWORD m_arCode[ 256 ];
|
|
unsigned m_uLine;
|
|
int GetUC();
|
|
public:
|
|
DWORD Position() { return m_pCrt - m_arFile; }
|
|
int GetCodeCount( DWORD Code);
|
|
DWORD Code() { return m_nCode; }
|
|
unsigned Line() { return m_uLine; }
|
|
CTextParser();
|
|
~CTextParser();
|
|
void SetType( char*, int);
|
|
void ResetDefaults();
|
|
BOOL AccessFile( char* );
|
|
void ReleaseFile();
|
|
DWORD Advance( DWORD *res = NULL );
|
|
char* AllocWord();
|
|
char* Word();
|
|
};
|
|
|
|
//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
|
// DESC. : word obtaining
|
|
// AUTHOR : Catalin Cocos
|
|
//__________________________________________________________________________________________________
|
|
|
|
inline char* CTextParser::Word() { return (char*)m_pWord; }
|
|
|
|
//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
|
// DESC. : word copying (allocation uses new)
|
|
// AUTHOR : Catalin Cocos
|
|
//__________________________________________________________________________________________________
|
|
|
|
inline char* CTextParser::AllocWord() { return strcpy (new char[strlen((char*)m_pWord)+1], (char*)m_pWord); }
|
|
|
|
//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
|
// DESC. : character read
|
|
// AUTHOR : Catalin Cocos
|
|
//__________________________________________________________________________________________________
|
|
inline int CTextParser::GetUC()
|
|
{
|
|
if(m_pCrt<m_pFileEnd) return m_arCode[*m_pCrt++];
|
|
else return CTP_EOF; //end of file reached
|
|
}
|
|
|
|
|
|
#endif |