UFO: Alien Invasion
Main Page
Related Pages
Modules
Namespaces
Data Structures
Files
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Modules
Pages
scriplib.cpp
Go to the documentation of this file.
1
6
/*
7
Copyright (C) 1997-2001 Id Software, Inc.
8
9
This program is free software; you can redistribute it and/or
10
modify it under the terms of the GNU General Public License
11
as published by the Free Software Foundation; either version 2
12
of the License, or (at your option) any later version.
13
14
This program is distributed in the hope that it will be useful,
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17
18
See the GNU General Public License for more details.
19
20
You should have received a copy of the GNU General Public License
21
along with this program; if not, write to the Free Software
22
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
24
*/
25
26
27
#include "
shared.h
"
28
#include "
scriplib.h
"
29
30
/*
31
=============================================================================
32
PARSING STUFF
33
=============================================================================
34
*/
35
36
typedef
struct
{
37
char
filename
[
MAX_OSPATH
];
38
char
*
buffer
;
39
const
char
*
script_p
;
40
const
char
*
end_p
;
41
}
script_t
;
42
43
static
script_t
script
;
44
45
char
parsedToken
[
MAX_TOKEN_CHARS
];
46
47
void
LoadScriptFile
(
const
char
*
filename
)
48
{
49
strncpy(script.
filename
, filename,
sizeof
(script.
filename
));
50
51
const
int
size
=
FS_LoadFile
(script.
filename
, (
byte
**)&script.
buffer
);
52
if
(size == -1)
53
Sys_Error
(
"file '%s' doesn't exist"
, script.
filename
);
54
55
script.
script_p
= script.
buffer
;
56
script.
end_p
= script.
buffer
+
size
;
57
}
58
62
void
ParseFromMemory
(
char
* buffer,
int
size
)
63
{
64
Q_strncpyz
(script.
filename
,
"memory buffer"
,
sizeof
(script.
filename
));
65
66
script.
buffer
= buffer;
67
script.
script_p
= script.
buffer
;
68
script.
end_p
= script.
buffer
+
size
;
69
}
70
75
const
char
*
GetToken
()
76
{
77
const
char
* token =
Com_Parse
(&script.
script_p
,
parsedToken
,
sizeof
(
parsedToken
));
78
if
(!script.
script_p
) {
79
/* not if the current script is a memory buffer */
80
if
(!
Q_streq
(script.
filename
,
"memory buffer"
))
81
Mem_Free
(script.
buffer
);
82
assert(
Q_strnull
(
parsedToken
));
83
return
parsedToken
;
84
}
85
86
return
token;
87
}
88
92
bool
TokenAvailable
(
void
)
93
{
94
const
char
* search_p = script.
script_p
;
95
96
if
(search_p >= script.
end_p
)
97
return
false
;
98
99
while
(*search_p <=
' '
) {
100
if
(*search_p ==
'\n'
)
101
return
false
;
102
search_p++;
103
if
(search_p == script.
end_p
)
104
return
false
;
105
}
106
107
return
true
;
108
}
Q_strnull
bool Q_strnull(const char *string)
Definition:
shared.h:138
Sys_Error
void Sys_Error(const char *error,...)
Definition:
g_main.cpp:421
script_t
Definition:
scriplib.cpp:36
scriplib.h
script_t::buffer
char * buffer
Definition:
scriplib.cpp:38
filename
const char * filename
Definition:
ioapi.h:41
FS_LoadFile
int FS_LoadFile(const char *path, byte **buffer)
Filenames are relative to the quake search path.
Definition:
files.cpp:384
MAX_OSPATH
#define MAX_OSPATH
Definition:
filesys.h:44
LoadScriptFile
void LoadScriptFile(const char *filename)
Definition:
scriplib.cpp:47
Q_strncpyz
void Q_strncpyz(char *dest, const char *src, size_t destsize)
Safe strncpy that ensures a trailing zero.
Definition:
shared.cpp:457
size
GLsizei size
Definition:
r_gl.h:152
MAX_TOKEN_CHARS
#define MAX_TOKEN_CHARS
Definition:
defines.h:372
parsedToken
char parsedToken[MAX_TOKEN_CHARS]
Definition:
scriplib.cpp:45
Com_Parse
const char * Com_Parse(const char *data_p[], char *target, size_t size, bool replaceWhitespaces)
Parse a token out of a string.
Definition:
parse.cpp:107
script_t::script_p
const char * script_p
Definition:
scriplib.cpp:39
script_t::end_p
const char * end_p
Definition:
scriplib.cpp:40
Mem_Free
#define Mem_Free(ptr)
Definition:
mem.h:35
GetToken
const char * GetToken()
Parses the next token from the current script on the stack and store the result in parsedToken...
Definition:
scriplib.cpp:75
Q_streq
#define Q_streq(a, b)
Definition:
shared.h:136
TokenAvailable
bool TokenAvailable(void)
Returns true if there is another token on the line.
Definition:
scriplib.cpp:92
script_t::filename
char filename[MAX_OSPATH]
Definition:
scriplib.cpp:37
shared.h
byte
uint8_t byte
Definition:
ufotypes.h:34
ParseFromMemory
void ParseFromMemory(char *buffer, int size)
Parses e.g. the entity string that is already stored in memory.
Definition:
scriplib.cpp:62
script
static script_t script
Definition:
scriplib.cpp:43
src
tools
ufo2map
common
scriplib.cpp
Generated on Mon Feb 24 2020 05:28:06 for UFO: Alien Invasion by
1.8.8