doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Token.cpp
Go to the documentation of this file.
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 "precompiled.h"
30 #pragma hdrstop
31 
32 
33 /*
34 ================
35 idToken::NumberValue
36 ================
37 */
38 void idToken::NumberValue( void ) {
39  int i, pow, div, c;
40  const char *p;
41  double m;
42 
43  assert( type == TT_NUMBER );
44  p = c_str();
45  floatvalue = 0;
46  intvalue = 0;
47  // floating point number
48  if ( subtype & TT_FLOAT ) {
49  if ( subtype & ( TT_INFINITE | TT_INDEFINITE | TT_NAN ) ) {
50  if ( subtype & TT_INFINITE ) { // 1.#INF
51  unsigned int inf = 0x7f800000;
52  floatvalue = (double) *(float*)&inf;
53  }
54  else if ( subtype & TT_INDEFINITE ) { // 1.#IND
55  unsigned int ind = 0xffc00000;
56  floatvalue = (double) *(float*)&ind;
57  }
58  else if ( subtype & TT_NAN ) { // 1.#QNAN
59  unsigned int nan = 0x7fc00000;
60  floatvalue = (double) *(float*)&nan;
61  }
62  }
63  else {
64  while( *p && *p != '.' && *p != 'e' ) {
65  floatvalue = floatvalue * 10.0 + (double) (*p - '0');
66  p++;
67  }
68  if ( *p == '.' ) {
69  p++;
70  for( m = 0.1; *p && *p != 'e'; p++ ) {
71  floatvalue = floatvalue + (double) (*p - '0') * m;
72  m *= 0.1;
73  }
74  }
75  if ( *p == 'e' ) {
76  p++;
77  if ( *p == '-' ) {
78  div = true;
79  p++;
80  }
81  else if ( *p == '+' ) {
82  div = false;
83  p++;
84  }
85  else {
86  div = false;
87  }
88  pow = 0;
89  for ( pow = 0; *p; p++ ) {
90  pow = pow * 10 + (int) (*p - '0');
91  }
92  for ( m = 1.0, i = 0; i < pow; i++ ) {
93  m *= 10.0;
94  }
95  if ( div ) {
96  floatvalue /= m;
97  }
98  else {
99  floatvalue *= m;
100  }
101  }
102  }
104  }
105  else if ( subtype & TT_DECIMAL ) {
106  while( *p ) {
107  intvalue = intvalue * 10 + (*p - '0');
108  p++;
109  }
111  }
112  else if ( subtype & TT_IPADDRESS ) {
113  c = 0;
114  while( *p && *p != ':' ) {
115  if ( *p == '.' ) {
116  while( c != 3 ) {
117  intvalue = intvalue * 10;
118  c++;
119  }
120  c = 0;
121  }
122  else {
123  intvalue = intvalue * 10 + (*p - '0');
124  c++;
125  }
126  p++;
127  }
128  while( c != 3 ) {
129  intvalue = intvalue * 10;
130  c++;
131  }
133  }
134  else if ( subtype & TT_OCTAL ) {
135  // step over the first zero
136  p += 1;
137  while( *p ) {
138  intvalue = (intvalue << 3) + (*p - '0');
139  p++;
140  }
142  }
143  else if ( subtype & TT_HEX ) {
144  // step over the leading 0x or 0X
145  p += 2;
146  while( *p ) {
147  intvalue <<= 4;
148  if (*p >= 'a' && *p <= 'f')
149  intvalue += *p - 'a' + 10;
150  else if (*p >= 'A' && *p <= 'F')
151  intvalue += *p - 'A' + 10;
152  else
153  intvalue += *p - '0';
154  p++;
155  }
157  }
158  else if ( subtype & TT_BINARY ) {
159  // step over the leading 0b or 0B
160  p += 2;
161  while( *p ) {
162  intvalue = (intvalue << 1) + (*p - '0');
163  p++;
164  }
166  }
168 }
169 
170 /*
171 ================
172 idToken::ClearTokenWhiteSpace
173 ================
174 */
178  linesCrossed = 0;
179 }
const char * whiteSpaceStart_p
Definition: Token.h:103
assert(prefInfo.fullscreenBtn)
#define TT_INDEFINITE
Definition: Token.h:60
double floatvalue
Definition: Token.h:102
case const int
Definition: Callbacks.cpp:52
int subtype
Definition: Token.h:78
int linesCrossed
Definition: Token.h:80
GLuint GLuint GLsizei GLenum type
Definition: glext.h:2845
void ClearTokenWhiteSpace(void)
Definition: Token.cpp:175
int i
Definition: process.py:33
#define TT_DECIMAL
Definition: Token.h:49
#define TT_NUMBER
Definition: Token.h:43
#define TT_BINARY
Definition: Token.h:52
#define TT_IPADDRESS
Definition: Token.h:62
const GLubyte * c
Definition: glext.h:4677
void NumberValue(void)
Definition: Token.cpp:38
#define TT_HEX
Definition: Token.h:50
#define NULL
Definition: Lib.h:88
const char * whiteSpaceEnd_p
Definition: Token.h:104
#define TT_VALUESVALID
Definition: Token.h:64
static unsigned long Ftol(float f)
Definition: Math.h:829
#define TT_NAN
Definition: Token.h:61
#define TT_INFINITE
Definition: Token.h:59
const char * c_str(void) const
Definition: Str.h:487
#define TT_OCTAL
Definition: Token.h:51
#define TT_FLOAT
Definition: Token.h:55
unsigned long intvalue
Definition: Token.h:101
GLfloat GLfloat p
Definition: glext.h:4674