-
Notifications
You must be signed in to change notification settings - Fork 2
/
Table.h
112 lines (89 loc) · 2.99 KB
/
Table.h
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
//-----------------------------------------------------------------------------
// Return Messages
//-----------------------------------------------------------------------------
#pragma once
#define TBL_OK 0x00 // Success
#define TBL_OPEN_ERROR 0x01 // Cannot open the Table properly
#define TBL_PARSE_ERROR 0x02 // Cannot parse how the Table is typed
#define NO_MATCHING_ENTRY 0x10 // There was an entry that cannot be matched in the table
// Other
#define SPACE 0x20
#include "stdafx.h"
#include <string>
#include <vector>
#include <fstream>
#include <map>
// Structure for errors
typedef struct TBL_ERROR
{
unsigned int LineNo; // The line number which the error occurred
std::string ErrorDesc; // A description of what the error was
} TBL_ERROR;
// Data Structure for a table bookmark
typedef struct TBL_BOOKMARK
{
unsigned int address;
std::string description;
} TBL_BOOKMARK;
// Data Structure for a script dump bookmark
typedef struct TBL_DUMPMARK
{
unsigned int StartAddress;
unsigned int EndAddress;
std::string description;
} TBL_DUMPMARK;
// Data Structure for a script insertion bookmark
typedef struct TBL_INSMARK
{
unsigned int address;
std::string filename;
std::string description;
} TBL_INSMARK;
// Data Structure for a script string
typedef struct TBL_STRING
{
std::string Text;
std::string EndToken;
} TBL_STRING;
// Data Structure for an unencoded (text) string
typedef struct TXT_STRING
{
std::string Text;
std::string EndToken;
} TXT_STRING;
typedef std::map<std::string, std::string> StrStrMap;
typedef std::list<TBL_STRING>::iterator ListTblStringIt;
typedef std::list<TXT_STRING>::iterator ListTxtStringIt;
//-----------------------------------------------------------------------------
// Table Interfaces
//-----------------------------------------------------------------------------
class Table
{
public:
Table();
~Table();
int OpenTable(const char* TableFilename);
unsigned int EncodeStream(std::string& scriptbuf, unsigned int& BadCharOffset);
std::vector<TBL_ERROR> Errors; // Errors
std::list<TBL_STRING> StringTable; // (Encoded) String table
std::list<TXT_STRING> TxtStringTable; // Text String Table
std::vector<std::string> EndTokens; // String end tokens
std::map<std::string, std::string> LookupHex; // for looking up hex values. (insertion)
unsigned int StringCount;
bool bAddEndToken;
private:
inline void InitHexTable();
inline bool parseendline(std::string line);
inline bool parseendstring(std::string line);
inline bool parseentry(std::string line);
inline void parsews(std::ifstream& file);
inline std::string& GetHexValue(std::string& Textstring);
inline void AddToTable(std::string& Hexstring, TBL_STRING* TblStr);
std::string DefEndLine;
std::string DefEndString;
unsigned int LineNumber; // The line number that the library is reading
unsigned int TblEntries; // The number of table entries
unsigned int LongestHex; // The longest hex entry, in bytes
unsigned int LongestText[256];
};
inline unsigned short HexToDec(char HexChar);