OpenMoHAA 0.82.0
Loading...
Searching...
No Matches
script.h
1/*
2===========================================================================
3Copyright (C) 2015 the OpenMoHAA team
4
5This file is part of OpenMoHAA source code.
6
7OpenMoHAA source code is free software; you can redistribute it
8and/or modify it under the terms of the GNU General Public License as
9published by the Free Software Foundation; either version 2 of the License,
10or (at your option) any later version.
11
12OpenMoHAA source code is distributed in the hope that it will be
13useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with OpenMoHAA source code; if not, write to the Free Software
19Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20===========================================================================
21*/
22
23// script.h: C++ implementation of tokenization/interpretation.
24
25#ifndef __SCRIPT_H__
26#define __SCRIPT_H__
27
28#include "class.h"
29#include "vector.h"
30#include "str.h"
31
32#if defined(ARCHIVE_SUPPORTED)
33# include "../fgame/archive.h"
34#endif
35
36#define TOKENCOMMENT (';')
37#define TOKENCOMMENT2 ('#')
38#define TOKENEOL ('\n')
39// #define TOKENNULL ('\0')
40#define TOKENSPACE (' ')
41#define TOKENSPECIAL ('$')
42
43#define SCRIPT_MAXTOKEN 512
44
45typedef struct {
46 qboolean tokenready;
47 int offset;
48 int line;
49 char token[SCRIPT_MAXTOKEN];
51
52typedef struct {
53 // const char *macroName;
54 // const char *macroText;
55 str macroName;
56 str macroText;
57} macro;
58
59class Script : public Class
60{
61protected:
62 qboolean tokenready;
63
64 str filename;
65 const char *script_p;
66 const char *end_p;
67 Container<macro *> macrolist;
68
69 int line;
70 char token[SCRIPT_MAXTOKEN];
71
72 qboolean releaseBuffer;
73 qboolean hasError;
74
75 qboolean AtComment(void);
76 void CheckOverflow(void);
77
78public:
79 const char *buffer;
80 size_t length;
81
82 CLASS_PROTOTYPE(Script);
83
84#if defined(ARCHIVE_SUPPORTED)
85 void Archive(Archiver& arc) override;
86#endif
87
88 ~Script();
89 Script(const char *filename);
90 Script();
91
92 void Close(void);
93 const char *Filename(void);
94 int GetLineNumber(void);
95 void Reset(void);
96 void MarkPosition(scriptmarker_t *mark);
97 void RestorePosition(const scriptmarker_t *mark);
98 qboolean SkipToEOL(void);
99 void SkipWhiteSpace(qboolean crossline);
100 void SkipNonToken(qboolean crossline);
101 qboolean TokenAvailable(qboolean crossline);
102 qboolean CommentAvailable(qboolean crossline);
103 void UnGetToken(void);
104 qboolean AtString(qboolean crossline);
105 qboolean AtOpenParen(qboolean crossline);
106 qboolean AtCloseParen(qboolean crossline);
107 qboolean AtComma(qboolean crossline);
108 qboolean AtDot(qboolean crossline);
109 qboolean AtAssignment(qboolean crossline);
110 const char *GetToken(qboolean crossline);
111 const char *GetLine(qboolean crossline);
112 const char *GetRaw(void);
113 const char *GetString(qboolean crossline);
114 qboolean GetSpecific(const char *string);
115 qboolean GetBoolean(qboolean crossline);
116 int GetInteger(qboolean crossline);
117 double GetDouble(qboolean crossline);
118 float GetFloat(qboolean crossline);
119 Vector GetVector(qboolean crossline);
120 int LinesInFile(void);
121 void Parse(const char *data, size_t length, const char *name);
122 void LoadFile(const char *name);
123 void LoadFile(const char *name, int length, const char *buf);
124 const char *Token(void);
125 void AddMacroDefinition(qboolean crossline);
126 const char *GetMacroString(const char *theMacroName);
127 char *EvaluateMacroString(const char *theMacroString);
128 float EvaluateMacroMath(float value, float newval, char oper);
129 const char *GetExprToken(const char *ptr, char *token);
130 const char *GrabNextToken(qboolean crossline);
131 qboolean isMacro(void);
132
133 qboolean EndOfFile();
134 qboolean isValid(void);
135
136 Container<macro *> *GetMacroList() { return &macrolist; }
137
138 void AddMacro(const char *name, const char *value);
139};
140
141#if defined(ARCHIVE_SUPPORTED)
142
143inline void Script::Archive(Archiver& arc)
144{
145 int pos;
146
147 arc.ArchiveBoolean(&tokenready);
148
149 arc.ArchiveString(&filename);
150 if (arc.Loading()) {
151 //
152 // load the file in
153 //
154 LoadFile(filename.c_str());
155 }
156
157 if (!arc.Loading()) {
158 //
159 // save out current pointer as an offset
160 //
161 pos = script_p - buffer;
162 }
163 arc.ArchiveInteger(&pos);
164 if (arc.Loading()) {
165 //
166 // restore the script pointer
167 //
168 script_p = buffer + pos;
169 }
170
171 // const char *end_p;
172 // Container<macro *> macrolist;
173
174 arc.ArchiveInteger(&line);
175 arc.ArchiveRaw(&token, sizeof(token));
176
177 // qboolean releaseBuffer;
178}
179#endif
180
181#endif
Definition archive.h:86
Definition container.h:85
Definition vector.h:61
Definition str.h:77
Definition script.h:52
Definition script.h:45