1
/* Copyright (c) 2008 PrimeBase Technologies GmbH, Germany
3
* PrimeBase Media Stream for MySQL
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
* Original author: Paul McCullagh (H&G2JCtL)
20
* Continued development: Barry Leslie
25
* A token stream. The tokens are identified in the same
26
* manner as the UNIX/DOS command line.
28
* This basically means that all tokens must be sepparated
29
* by at least one space.
31
* EOL and EOF are also tokens.
38
#include "CSTokenStream.h"
40
const char *CSToken::singletons = "=[]!#$^&*()|;<>?~";
42
CSTokenStream::~CSTokenStream()
50
void CSTokenStream::open(CSInputStream *stream, u_int line)
61
void CSTokenStream::close()
68
void CSTokenStream::nextChar()
71
iChar = iStream->read();
75
CSTokenStream *CSTokenStream::newTokenStream(CSInputStream *stream, u_int line)
77
return UXTokenStream::newTokenStream(stream, line);
80
CSToken *UXTokenStream::nextToken()
86
/* Initialize the current character: */
91
while (iChar == ' ' || iChar == '\t')
94
/* Handle the singletons: */
95
if ((ptr = strchr(CSToken::singletons, iChar))) {
99
return_(newToken((int) (ptr - CSToken::singletons), ch));
102
/* Handle EOF and EOL: */
105
return_(newToken(CS_TKN_EOS, "[EOF]"));
111
return_(newToken(CS_TKN_EOL, "\r\n"));
114
return_(newToken(CS_TKN_EOL, "\r"));
118
return_(newToken(CS_TKN_EOL, "\n"));
121
/* Now we have some text
122
* The text ends with the first space, EOF, EOL
125
CSStringBuffer *text;
127
new_(text, CSStringBuffer());
133
// ` are included in the string to indicate it should be executed
134
text->append((char) iChar);
140
while (iChar != quote && iChar != -1 && iChar != '\r' && iChar != '\n') {
141
text->append((char) iChar);
144
if (iChar == quote) {
146
text->append((char) quote);
151
/* Escaped character: */
154
text->append((char) iChar);
163
/* These characters terminated the text: */
166
/* Singletons terminate the text as well, unless they
167
* were escaped or in quotes.
169
if ((ptr = strchr(CSToken::singletons, iChar)))
171
text->append((char) iChar);
177
char *str = text->take();
179
return_(newToken(CS_TKN_TEXT, str));
182
CSToken *UXTokenStream::newToken(int type, const char *text)
186
new_(tk, UXToken(type, text));
190
CSToken *UXTokenStream::newToken(int type, char ch)
194
new_(tk, UXToken(type, ch));
198
CSTokenStream *UXTokenStream::newTokenStream(CSInputStream *stream, u_int line)
203
new_(s, UXTokenStream());
205
s->open(stream, line);