]> icculus.org git repositories - icculus/iodoom3.git/blob - neo/tools/radiant/PARSE.CPP
hello world
[icculus/iodoom3.git] / neo / tools / radiant / PARSE.CPP
1 /*
2 ===========================================================================
3
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company. 
6
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).  
8
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 Doom 3 Source Code 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.  See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code.  If not, see <http://www.gnu.org/licenses/>.
21
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code.  If not, please request a copy in writing from id Software at the address below.
23
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25
26 ===========================================================================
27 */
28
29 #include "../../idlib/precompiled.h"
30 #pragma hdrstop
31
32 #include "qe3.h"
33
34 char    token[MAXTOKEN];
35 bool    unget;
36 const char      *script_p;
37 int             scriptline;
38
39 void    StartTokenParsing (const char *data)
40 {
41         scriptline = 1;
42         script_p = data;
43         unget = false;
44 }
45
46 bool WINAPI GetToken (bool crossline)
47 {
48         char    *token_p;
49
50         if (unget)                         // is a token allready waiting?
51         {
52                 unget = false;
53                 return true;
54         }
55
56 //
57 // skip space
58 //
59 skipspace:
60         while (*script_p <= 32)
61         {
62                 if (!*script_p)
63                 {
64                         if (!crossline)
65                                 common->Printf("Warning: Line %i is incomplete [01]\n",scriptline);
66                         return false;
67                 }
68                 if (*script_p++ == '\n')
69                 {
70                         if (!crossline)
71                                 common->Printf("Warning: Line %i is incomplete [02]\n",scriptline);
72                         scriptline++;
73                 }
74         }
75
76         if (script_p[0] == '/' && script_p[1] == '/')   // comment field
77         {
78                 if (!crossline)
79                         common->Printf("Warning: Line %i is incomplete [03]\n",scriptline);
80                 while (*script_p++ != '\n')
81                         if (!*script_p)
82                         {
83                                 if (!crossline)
84                                         common->Printf("Warning: Line %i is incomplete [04]\n",scriptline);
85                                 return false;
86                         }
87                 goto skipspace;
88         }
89
90 //
91 // copy token
92 //
93         token_p = token;
94
95         if (*script_p == '"')
96         {
97                 script_p++;
98     //if (*script_p == '"')   // handle double quotes i suspect they are put in by other editors cccasionally
99     //  script_p++;
100                 while ( *script_p != '"' )
101                 {
102                         if (!*script_p)
103                                 Error ("EOF inside quoted token");
104                         *token_p++ = *script_p++;
105                         if (token_p == &token[MAXTOKEN])
106                                 Error ("Token too large on line %i",scriptline);
107                 }
108                 script_p++;
109     //if (*script_p == '"')   // handle double quotes i suspect they are put in by other editors cccasionally
110     //  script_p++;
111         }
112         else while ( *script_p > 32 )
113         {
114                 *token_p++ = *script_p++;
115                 if (token_p == &token[MAXTOKEN])
116                         Error ("Token too large on line %i",scriptline);
117         }
118
119         *token_p = 0;
120         
121         return true;
122 }
123
124 void WINAPI UngetToken (void)
125 {
126         unget = true;
127 }
128
129
130 /*
131 ==============
132 TokenAvailable
133
134 Returns true if there is another token on the line
135 ==============
136 */
137 bool TokenAvailable (void)
138 {
139         const char    *search_p;
140
141         search_p = script_p;
142
143         while ( *search_p <= 32)
144         {
145                 if (*search_p == '\n')
146                         return false;
147                 if (*search_p == 0)
148                         return false;
149                 search_p++;
150         }
151
152         if (*search_p == ';')
153                 return false;
154
155         return true;
156 }
157