~ubuntu-branches/ubuntu/natty/alien-arena/natty

« back to all changes in this revision

Viewing changes to source/utils3/common/scriplib.c

  • Committer: Bazaar Package Importer
  • Author(s): Andres Mejia, Barry deFreese, Ansgar Burchardt, Gonéri Le Bouder, Andres Mejia
  • Date: 2008-04-18 17:43:24 UTC
  • mfrom: (1.1.2 upstream) (3.1.1 hardy)
  • Revision ID: james.westby@ubuntu.com-20080418174324-si1umi8dngglaha4
Tags: 7.0-1
[ Barry deFreese ]
* Escape - in alien-arena-server.6.
* Add myself to uploaders.

[ Ansgar Burchardt ]
* Remove deprecated Encoding key from .desktop file.

[ Gonéri Le Bouder ]
* Remove Homepage from package description.

[ Andres Mejia ]
* New upstream release.
* Removing XS- part for Vcs-* lines.
* Removing +ssh part of Vcs-Svn line.
* Bumped to Standards-Version 3.7.3.
* Test for existence of *-stamp stamps before removing them.
* Removed Encoding field in desktop file.
* Modify patch for upstream Makefile to make Makefile more useful in building
  Debian packages.
  + Also fixes problem not detecting the existence of libcurl.
* Remove debug packages for release. Will support nostrip option instead.
* Add description for fix-CVE-2007-4754-CVE-2007-4755.dpatch, silences
  lintian warning.
* Add new link for watchfile.
  + Closes: #453555
* Moved debian/scripts/alien-arena-tarball.sh to
  debian/alien-arena-get-orig-source.
* Modified alien-arena-data-get-orig-source to make it easier to maintain.
* Switched from dpatch to quilt.
* Cut down package description.
* Closing bug about mouse constantly looking up. The submitter could not
  reproduce the bug after deleting the ~/.alien-arena directory.
  + Closes: #457700
* Updated copyright file for new release.
* Updated README.Debian files.
* Adding new images for icons. Need build dependency on sharutils.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// scriplib.c
 
2
 
 
3
#include "cmdlib.h"
 
4
#include "scriplib.h"
 
5
 
 
6
/*
 
7
=============================================================================
 
8
 
 
9
                                                PARSING STUFF
 
10
 
 
11
=============================================================================
 
12
*/
 
13
 
 
14
typedef struct
 
15
{
 
16
        char    filename[1024];
 
17
        char    *buffer,*script_p,*end_p;
 
18
        int     line;
 
19
} script_t;
 
20
 
 
21
#define MAX_INCLUDES    8
 
22
script_t        scriptstack[MAX_INCLUDES];
 
23
script_t        *script;
 
24
int                     scriptline;
 
25
 
 
26
char    token[MAXTOKEN];
 
27
qboolean endofscript;
 
28
qboolean tokenready;                     // only true if UnGetToken was just called
 
29
 
 
30
char brush_info[2000] = "No brushes processed yet. Look near beginning of map";
 
31
static int brush_begin = 1;
 
32
 
 
33
void MarkBrushBegin()
 
34
{
 
35
        brush_begin = 1;
 
36
}
 
37
 
 
38
void TestBrushBegin()
 
39
{
 
40
        if(!brush_begin)
 
41
                return;
 
42
 
 
43
        brush_begin = 0;
 
44
 
 
45
        sprintf(brush_info, "Line %d, file %s", script->line, script->filename);
 
46
}
 
47
 
 
48
/*
 
49
==============
 
50
AddScriptToStack
 
51
==============
 
52
*/
 
53
void AddScriptToStack (char *filename)
 
54
{
 
55
        int            size;
 
56
 
 
57
        script++;
 
58
        if (script == &scriptstack[MAX_INCLUDES])
 
59
                Error ("script file exceeded MAX_INCLUDES");
 
60
        strcpy (script->filename, ExpandPath (filename) );
 
61
 
 
62
        size = LoadFile (script->filename, (void **)&script->buffer);
 
63
 
 
64
        printf ("entering %s\n", script->filename);
 
65
 
 
66
        script->line = 1;
 
67
 
 
68
        script->script_p = script->buffer;
 
69
        script->end_p = script->buffer + size;
 
70
}
 
71
 
 
72
 
 
73
/*
 
74
==============
 
75
LoadScriptFile
 
76
==============
 
77
*/
 
78
void LoadScriptFile (char *filename)
 
79
{
 
80
        script = scriptstack;
 
81
        AddScriptToStack (filename);
 
82
 
 
83
        endofscript = false;
 
84
        tokenready = false;
 
85
}
 
86
 
 
87
 
 
88
/*
 
89
==============
 
90
ParseFromMemory
 
91
==============
 
92
*/
 
93
void ParseFromMemory (char *buffer, int size)
 
94
{
 
95
        script = scriptstack;
 
96
        script++;
 
97
        if (script == &scriptstack[MAX_INCLUDES])
 
98
                Error ("script file exceeded MAX_INCLUDES");
 
99
        strcpy (script->filename, "memory buffer" );
 
100
 
 
101
        script->buffer = buffer;
 
102
        script->line = 1;
 
103
        script->script_p = script->buffer;
 
104
        script->end_p = script->buffer + size;
 
105
 
 
106
        endofscript = false;
 
107
        tokenready = false;
 
108
}
 
109
 
 
110
 
 
111
/*
 
112
==============
 
113
UnGetToken
 
114
 
 
115
Signals that the current token was not used, and should be reported
 
116
for the next GetToken.  Note that
 
117
 
 
118
GetToken (true);
 
119
UnGetToken ();
 
120
GetToken (false);
 
121
 
 
122
could cross a line boundary.
 
123
==============
 
124
*/
 
125
void UnGetToken (void)
 
126
{
 
127
        tokenready = true;
 
128
}
 
129
 
 
130
 
 
131
qboolean EndOfScript (qboolean crossline)
 
132
{
 
133
        if (!crossline)
 
134
                Error ("Line %i is incomplete\n",scriptline);
 
135
 
 
136
        if (!strcmp (script->filename, "memory buffer"))
 
137
        {
 
138
                endofscript = true;
 
139
                return false;
 
140
        }
 
141
 
 
142
        free (script->buffer);
 
143
        if (script == scriptstack+1)
 
144
        {
 
145
                endofscript = true;
 
146
                return false;
 
147
        }
 
148
        script--;
 
149
        scriptline = script->line;
 
150
        printf ("returning to %s\n", script->filename);
 
151
        return GetToken (crossline);
 
152
}
 
153
 
 
154
/*
 
155
==============
 
156
GetToken
 
157
==============
 
158
*/
 
159
qboolean GetToken (qboolean crossline)
 
160
{
 
161
        char    *token_p;
 
162
 
 
163
        if (tokenready)                         // is a token allready waiting?
 
164
        {
 
165
                tokenready = false;
 
166
                return true;
 
167
        }
 
168
 
 
169
        if (script->script_p >= script->end_p)
 
170
                return EndOfScript (crossline);
 
171
 
 
172
        TestBrushBegin();
 
173
//
 
174
// skip space
 
175
//
 
176
skipspace:
 
177
        while (*script->script_p <= 32)
 
178
        {
 
179
                if (script->script_p >= script->end_p)
 
180
                        return EndOfScript (crossline);
 
181
                if (*script->script_p++ == '\n')
 
182
                {
 
183
                        if (!crossline)
 
184
                                Error ("Line %i is incomplete\n",scriptline);
 
185
                        scriptline = script->line++;
 
186
                }
 
187
        }
 
188
 
 
189
        if (script->script_p >= script->end_p)
 
190
                return EndOfScript (crossline);
 
191
 
 
192
        // ; # // comments
 
193
        if (*script->script_p == ';' || *script->script_p == '#'
 
194
                || ( script->script_p[0] == '/' && script->script_p[1] == '/') )
 
195
        {
 
196
                if (!crossline)
 
197
                        Error ("Line %i is incomplete\n",scriptline);
 
198
                while (*script->script_p++ != '\n')
 
199
                        if (script->script_p >= script->end_p)
 
200
                                return EndOfScript (crossline);
 
201
                        scriptline = script->line++;
 
202
                goto skipspace;
 
203
        }
 
204
 
 
205
        // /* */ comments
 
206
        if (script->script_p[0] == '/' && script->script_p[1] == '*')
 
207
        {
 
208
                if (!crossline)
 
209
                        Error ("Line %i is incomplete\n",scriptline);
 
210
                script->script_p+=2;
 
211
                while (script->script_p[0] != '*' && script->script_p[1] != '/')
 
212
                {
 
213
                        if(script->script_p[0] == '\n')
 
214
                                scriptline = script->line++;
 
215
 
 
216
                        script->script_p++;
 
217
                        if (script->script_p >= script->end_p)
 
218
                                return EndOfScript (crossline);
 
219
                }
 
220
                script->script_p += 2;
 
221
                goto skipspace;
 
222
        }
 
223
 
 
224
//
 
225
// copy token
 
226
//
 
227
        token_p = token;
 
228
 
 
229
        if (*script->script_p == '"')
 
230
        {
 
231
                // quoted token
 
232
                script->script_p++;
 
233
                while (*script->script_p != '"')
 
234
                {
 
235
                        *token_p++ = *script->script_p++;
 
236
                        if (script->script_p == script->end_p)
 
237
                                break;
 
238
                        if (token_p == &token[MAXTOKEN])
 
239
                                Error ("Token too large on line %i\n",scriptline);
 
240
                }
 
241
                script->script_p++;
 
242
        }
 
243
        else    // regular token
 
244
        while ( *script->script_p > 32 && *script->script_p != ';')
 
245
        {
 
246
                *token_p++ = *script->script_p++;
 
247
                if (script->script_p == script->end_p)
 
248
                        break;
 
249
                if (token_p == &token[MAXTOKEN])
 
250
                        Error ("Token too large on line %i\n",scriptline);
 
251
        }
 
252
 
 
253
        *token_p = 0;
 
254
 
 
255
        if (!strcmp (token, "$include"))
 
256
        {
 
257
                GetToken (false);
 
258
                AddScriptToStack (token);
 
259
                return GetToken (crossline);
 
260
        }
 
261
 
 
262
        return true;
 
263
}
 
264
 
 
265
 
 
266
/*
 
267
==============
 
268
TokenAvailable
 
269
 
 
270
Returns true if there is another token on the line
 
271
==============
 
272
*/
 
273
qboolean TokenAvailable (void)
 
274
{
 
275
        char    *search_p;
 
276
 
 
277
        search_p = script->script_p;
 
278
 
 
279
        if (search_p >= script->end_p)
 
280
                return false;
 
281
 
 
282
        while ( *search_p <= 32)
 
283
        {
 
284
                if (*search_p == '\n')
 
285
                        return false;
 
286
                search_p++;
 
287
                if (search_p == script->end_p)
 
288
                        return false;
 
289
 
 
290
        }
 
291
 
 
292
        if (*search_p == ';')
 
293
                return false;
 
294
 
 
295
        return true;
 
296
}
 
297
 
 
298