1 #ifndef __SC_MAN_H__
2 #define __SC_MAN_H__
3 
4 class FScanner
5 {
6 public:
7 	struct SavedPos
8 	{
9 		const char *SavedScriptPtr;
10 		int SavedScriptLine;
11 	};
12 
13 	// Methods ------------------------------------------------------
14 	FScanner();
15 	FScanner(const FScanner &other);
16 	FScanner(int lumpnum);
17 	~FScanner();
18 
19 	FScanner &operator=(const FScanner &other);
20 
21 	void Open(const char *lumpname);
22 	void OpenFile(const char *filename);
23 	void OpenMem(const char *name, const char *buffer, int size);
24 	void OpenString(const char *name, FString buffer);
25 	void OpenLumpNum(int lump);
26 	void Close();
27 
28 	void SetCMode(bool cmode);
29 	void SetEscape(bool esc);
30 	const SavedPos SavePos();
31 	void RestorePos(const SavedPos &pos);
32 
33 	static FString TokenName(int token, const char *string=NULL);
34 
35 	bool GetString();
36 	void MustGetString();
37 	void MustGetStringName(const char *name);
38 	bool CheckString(const char *name);
39 
40 	bool GetToken();
41 	void MustGetAnyToken();
42 	void TokenMustBe(int token);
43 	void MustGetToken(int token);
44 	bool CheckToken(int token);
45 	bool CheckTokenId(ENamedName id);
46 
47 	bool GetNumber();
48 	void MustGetNumber();
49 	bool CheckNumber();
50 
51 	bool GetFloat();
52 	void MustGetFloat();
53 	bool CheckFloat();
54 
55 	void UnGet();
56 
57 	bool Compare(const char *text);
58 	int MatchString(const char * const *strings, size_t stride = sizeof(char*));
59 	int MustMatchString(const char * const *strings, size_t stride = sizeof(char*));
60 	int GetMessageLine();
61 
62 	void ScriptError(const char *message, ...);
63 	void ScriptMessage(const char *message, ...);
64 
65 	bool isText();
66 
67 	// Members ------------------------------------------------------
68 	char *String;
69 	int StringLen;
70 	int TokenType;
71 	int Number;
72 	double Float;
73 	FName Name;
74 	int Line;
75 	bool End;
76 	bool Crossed;
77 	int LumpNum;
78 	FString ScriptName;
79 
80 protected:
81 	void PrepareScript();
82 	void CheckOpen();
83 	bool ScanString(bool tokens);
84 
85 	// Strings longer than this minus one will be dynamically allocated.
86 	static const int MAX_STRING_SIZE = 128;
87 
88 	bool ScriptOpen;
89 	FString ScriptBuffer;
90 	const char *ScriptPtr;
91 	const char *ScriptEndPtr;
92 	char StringBuffer[MAX_STRING_SIZE];
93 	FString BigStringBuffer;
94 	bool AlreadyGot;
95 	int AlreadyGotLine;
96 	bool LastGotToken;
97 	const char *LastGotPtr;
98 	int LastGotLine;
99 	bool CMode;
100 	bool Escape;
101 };
102 
103 enum
104 {
105 	TK_SequenceStart = 256,
106 #define xx(sym,str) sym,
107 #include "sc_man_tokens.h"
108 	TK_LastToken
109 };
110 
111 
112 //==========================================================================
113 //
114 //
115 //
116 //==========================================================================
117 
118 enum
119 {
120 	MSG_WARNING,
121 	MSG_FATAL,
122 	MSG_ERROR,
123 	MSG_DEBUG,
124 	MSG_LOG,
125 	MSG_DEBUGLOG,
126 	MSG_MESSAGE
127 };
128 
129 //==========================================================================
130 //
131 // a class that remembers a parser position
132 //
133 //==========================================================================
134 
135 struct FScriptPosition
136 {
137 	static int ErrorCounter;
138 	FString FileName;
139 	int ScriptLine;
140 
FScriptPositionFScriptPosition141 	FScriptPosition()
142 	{
143 		ScriptLine=0;
144 	}
145 	FScriptPosition(const FScriptPosition &other);
146 	FScriptPosition(FString fname, int line);
147 	FScriptPosition(FScanner &sc);
148 	FScriptPosition &operator=(const FScriptPosition &other);
149 	void Message(int severity, const char *message,...) const;
ResetErrorCounterFScriptPosition150 	static void ResetErrorCounter()
151 	{
152 		ErrorCounter = 0;
153 	}
154 };
155 
156 
157 #endif //__SC_MAN_H__
158