27 #include "FileTokenizer.hpp"
28 #include "MsqError.hpp"
29 #ifdef MSQ_USE_OLD_C_HEADERS
42 FileTokenizer::FileTokenizer( FILE* file_ptr )
43 : filePtr( file_ptr ),
110 memmove(
buffer, result, remaining );
147 const char *token_end, *token =
get_string( err );
154 if (token[0] && token[1] && token[0] ==
'0' && toupper(token[1]) ==
'X')
157 "Syntax error at line %d: expected number, got \"%s\"",
164 result = strtod( token, (
char**)&token_end );
172 "Syntax error at line %d: expected number, got \"%s\"",
188 if (d != (
double)result)
200 const char *token_end, *token =
get_string( err );
205 result = strtol( token, (
char**)&token_end, 0 );
213 "Syntax error at line %d: expected integer, got \"%s\"",
228 result = (
unsigned char)i;
229 if (i != (
long)result)
246 if (i != (
long)result)
263 if (i != (
long)result)
279 if (token[1] || (token[0] !=
'0' && token[0] !=
'1'))
282 "Syntax error at line %d: expected 0 or 1, got \"%s\"",
287 result = token[0] ==
'1';
293 for (
size_t i = 0; i < count; ++
i)
304 for (
size_t i = 0; i < count; ++
i)
316 for (
size_t i = 0; i < count; ++
i)
328 for (
size_t i = 0; i < count; ++
i)
341 for (
size_t i = 0; i < count; ++
i)
353 for (
size_t i = 0; i < count; ++
i)
365 for (
size_t i = 0; i < count; ++
i)
400 if (0 == strcmp( token, str ))
405 "Syntax error at line %d: expected \"%s\", got \"%s\"",
419 const char*
const* ptr;
420 for (ptr = list; *ptr; ++ptr)
421 if (0 == strcmp( token, *ptr ))
422 return ptr - list + 1;
425 msq_std::string message(
"Parsing error at line " );
429 message +=
": expected one of {";
430 for (ptr = list; *ptr; ++ptr)
435 message +=
" } got \"";
An I/O error occured (e.g.
bool get_boolean_internal(bool &result, MsqError &err)
Internal implementation of get_Booleans.
int line_number() const
Get the line number the last token was read from.
void unget_token()
Put current token back in buffer.
int fread(T *const ptr, const unsigned int nmemb, std::FILE *stream)
Read file data, and check for possible errors.
~FileTokenizer()
destructor : closes file.
bool get_float_internal(float &result, MsqError &err)
Internal implementation of get_floats.
char buffer[512]
Input buffer.
bool get_long_int_internal(long &result, MsqError &err)
Internal implementation of get_long_ints.
bool match_token(const char *string, MsqError &err)
Match current token to passed string.
bool get_newline(MsqError &err)
check for newline
int fclose(std::FILE *file)
Close a file, and check for possible errors.
bool get_floats(size_t count, float *array, MsqError &err)
Parse a sequence of float values.
bool get_short_ints(size_t count, short *array, MsqError &err)
Parse a sequence of integer values.
bool get_doubles(size_t count, double *array, MsqError &err)
Parse a sequence of double values.
const char * get_string(MsqError &err)
get next token
bool get_bytes(size_t count, unsigned char *array, MsqError &err)
Parse a sequence of integer values.
#define MSQ_CHKERR(err)
Mesquite's Error Checking macro.
#define MSQ_SETERR(err)
Macro to set error - use err.clear() to clear.
bool get_long_ints(size_t count, long *array, MsqError &err)
Parse a sequence of integer values.
bool get_short_int_internal(short &result, MsqError &err)
Internal implementation of get_short_ints.
char * bufferEnd
One past the last used byte of the buffer.
char * nextToken
One past the end of the last token returned.
bool get_double_internal(double &result, MsqError &err)
Internal implementation of get_doubles.
bool get_integer_internal(int &result, MsqError &err)
Internal implementation of get_integers.
bool get_booleans(size_t count, bool *array, MsqError &err)
Parse a sequence of bit or boolean values.
bool get_byte_internal(unsigned char &result, MsqError &err)
Internal implementation of get_bytes.
msq_stdc::FILE * filePtr
Pointer to standard C FILE struct.
bool get_integers(size_t count, int *array, MsqError &err)
Parse a sequence of integer values.
Error parsing input (or input file)
int lineNumber
Line number of last returned token.
char lastChar
The whitespace character marking the end of the last returned token.
bool eof() const
Check for end-of-file condition.