ReactOS 0.4.15-dev-5669-g09dde2c
tokenize.c File Reference
#include <ctype.h>
#include <stdarg.h>
#include <stdlib.h>
#include "windef.h"
#include "winbase.h"
#include "query.h"
#include "sql.tab.h"
Include dependency graph for tokenize.c:

Go to the source code of this file.

Classes

struct  Keyword
 

Macros

#define MAX_TOKEN_LEN   11
 
#define X(str)   str, ARRAY_SIZE(str) - 1
 

Typedefs

typedef struct Keyword Keyword
 

Functions

static int __cdecl compKeyword (const void *m1, const void *m2)
 
static int sqliteKeywordCode (const WCHAR *z, int n)
 
static int isDigit (WCHAR c)
 
static int isSpace (WCHAR c)
 
int sqliteGetToken (const WCHAR *z, int *tokenType, int *skip)
 

Variables

static const Keyword aKeywordTable []
 
static const char isIdChar []
 

Macro Definition Documentation

◆ MAX_TOKEN_LEN

#define MAX_TOKEN_LEN   11

Definition at line 39 of file tokenize.c.

◆ X

#define X (   str)    str, ARRAY_SIZE(str) - 1

Definition at line 45 of file tokenize.c.

Typedef Documentation

◆ Keyword

Definition at line 32 of file tokenize.c.

Function Documentation

◆ compKeyword()

static int __cdecl compKeyword ( const void m1,
const void m2 
)
static

Definition at line 90 of file tokenize.c.

90 {
91 const Keyword *k1 = m1, *k2 = m2;
92 int ret, len = min( k1->len, k2->len );
93
94 if ((ret = wcsnicmp( k1->name, k2->name, len ))) return ret;
95 if (k1->len < k2->len) return -1;
96 else if (k1->len > k2->len) return 1;
97 return 0;
98}
#define wcsnicmp
Definition: compat.h:14
GLenum GLsizei len
Definition: glext.h:6722
#define min(a, b)
Definition: monoChain.cc:55
const WCHAR * name
Definition: tokenize.c:34
unsigned int len
Definition: tokenize.c:35
int ret

Referenced by sqliteKeywordCode().

◆ isDigit()

static int isDigit ( WCHAR  c)
inlinestatic

Definition at line 154 of file tokenize.c.

155{
156 return c >= '0' && c <= '9';
157}
const GLubyte * c
Definition: glext.h:8905

Referenced by sqliteGetToken().

◆ isSpace()

static int isSpace ( WCHAR  c)
inlinestatic

Definition at line 162 of file tokenize.c.

163{
164 return c == ' ' || c == '\t' || c == '\n' || c == '\f';
165}

Referenced by sqliteGetToken().

◆ sqliteGetToken()

int sqliteGetToken ( const WCHAR z,
int tokenType,
int skip 
)

Definition at line 172 of file tokenize.c.

172 {
173 int i;
174
175 *skip = 0;
176 switch( *z ){
177 case ' ': case '\t': case '\n': case '\f':
178 for(i=1; isSpace(z[i]); i++){}
179 *tokenType = TK_SPACE;
180 return i;
181 case '-':
182 if( z[1]==0 ) return -1;
183 *tokenType = TK_MINUS;
184 return 1;
185 case '(':
186 *tokenType = TK_LP;
187 return 1;
188 case ')':
189 *tokenType = TK_RP;
190 return 1;
191 case '*':
192 *tokenType = TK_STAR;
193 return 1;
194 case '=':
195 *tokenType = TK_EQ;
196 return 1;
197 case '<':
198 if( z[1]=='=' ){
199 *tokenType = TK_LE;
200 return 2;
201 }else if( z[1]=='>' ){
202 *tokenType = TK_NE;
203 return 2;
204 }else{
205 *tokenType = TK_LT;
206 return 1;
207 }
208 case '>':
209 if( z[1]=='=' ){
210 *tokenType = TK_GE;
211 return 2;
212 }else{
213 *tokenType = TK_GT;
214 return 1;
215 }
216 case '!':
217 if( z[1]!='=' ){
218 *tokenType = TK_ILLEGAL;
219 return 2;
220 }else{
221 *tokenType = TK_NE;
222 return 2;
223 }
224 case '?':
225 *tokenType = TK_WILDCARD;
226 return 1;
227 case ',':
228 *tokenType = TK_COMMA;
229 return 1;
230 case '`': case '\'': {
231 int delim = z[0];
232 for(i=1; z[i]; i++){
233 if( z[i]==delim )
234 break;
235 }
236 if( z[i] ) i++;
237 if( delim == '`' )
238 *tokenType = TK_ID;
239 else
240 *tokenType = TK_STRING;
241 return i;
242 }
243 case '.':
244 if( !isDigit(z[1]) ){
245 *tokenType = TK_DOT;
246 return 1;
247 }
248 /* Fall through */
249 case '0': case '1': case '2': case '3': case '4':
250 case '5': case '6': case '7': case '8': case '9':
251 *tokenType = TK_INTEGER;
252 for(i=1; isDigit(z[i]); i++){}
253 return i;
254 case '[':
255 for(i=1; z[i] && z[i-1]!=']'; i++){}
256 *tokenType = TK_ID;
257 return i;
258 default:
259 if( !isIdChar[*z] ){
260 break;
261 }
262 for(i=1; isIdChar[z[i]]; i++){}
263 *tokenType = sqliteKeywordCode(z, i);
264 if( *tokenType == TK_ID && z[i] == '`' ) *skip = 1;
265 return i;
266 }
267 *tokenType = TK_ILLEGAL;
268 return 1;
269}
#define skip(...)
Definition: atltest.h:64
GLdouble GLdouble z
Definition: glext.h:5874
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static int sqliteKeywordCode(const WCHAR *z, int n)
Definition: tokenize.c:105
static const char isIdChar[]
Definition: tokenize.c:131
static int isDigit(WCHAR c)
Definition: tokenize.c:154
static int isSpace(WCHAR c)
Definition: tokenize.c:162

◆ sqliteKeywordCode()

static int sqliteKeywordCode ( const WCHAR z,
int  n 
)
static

Definition at line 105 of file tokenize.c.

105 {
106 Keyword key, *r;
107
108 if( n>MAX_TOKEN_LEN )
109 return TK_ID;
110
111 key.tokenType = 0;
112 key.name = z;
113 key.len = n;
115 if( r )
116 return r->tokenType;
117 return TK_ID;
118}
#define ARRAY_SIZE(a)
Definition: main.h:24
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLdouble n
Definition: glext.h:7729
Definition: copy.c:22
WCHAR * name
Definition: path.c:43
#define bsearch
#define MAX_TOKEN_LEN
Definition: tokenize.c:39
static const Keyword aKeywordTable[]
Definition: tokenize.c:46
static int __cdecl compKeyword(const void *m1, const void *m2)
Definition: tokenize.c:90

Referenced by sqliteGetToken().

Variable Documentation

◆ aKeywordTable

const Keyword aKeywordTable[]
static

Definition at line 46 of file tokenize.c.

Referenced by sqliteKeywordCode().

◆ isIdChar

const char isIdChar[]
static
Initial value:
= {
0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1,
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
}

Definition at line 131 of file tokenize.c.

Referenced by sqliteGetToken().