Skip to content
Snippets Groups Projects
Commit 4cada1bc authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

namelist: add large file support.

parent 6f2b1868
No related branches found
No related tags found
No related merge requests found
Pipeline #8636 passed
......@@ -6,6 +6,7 @@
2021-06-14 Uwe Schulzweida
* namelist: add large file support
* KVListAppendNamelist: replace snprintf() my memcpy()
2021-06-13 Uwe Schulzweida
......
......@@ -8,6 +8,7 @@ Version 2.0.0 (25 October 2021):
New features:
* Changed to C++14
* Expr: Add function cdeltaz(x)
* namelist: Add large file support
* outputtab: Add key x and y to print coordinates of the original grid
New operators:
* selcircle: select cells inside a circle
......
......@@ -26,7 +26,7 @@ NamelistParser::allocToken()
{
if (this->toknext >= this->num_tokens)
{
constexpr unsigned int TOK_MEM_INCR = 64;
constexpr unsigned long TOK_MEM_INCR = 64;
this->num_tokens += TOK_MEM_INCR;
this->tokens.resize(this->num_tokens);
}
......@@ -38,7 +38,7 @@ NamelistParser::allocToken()
// Fills token type and boundaries.
void
NamelistToken::fill(NamelistType _type, int _start, int _end)
NamelistToken::fill(NamelistType _type, long _start, long _end)
{
this->type = _type;
this->start = _start;
......@@ -98,12 +98,12 @@ NamelistParser::parseString(const char *buf, size_t len, char quote)
this->pos++;
/* Skip starting quote */
// Skip starting quote
for (; this->pos < len && buf[this->pos] != '\0'; this->pos++)
{
const auto c = buf[this->pos];
/* Quote: end of string */
// Quote: end of string
if (c == quote)
{
auto token = this->allocToken();
......@@ -111,7 +111,7 @@ NamelistParser::parseString(const char *buf, size_t len, char quote)
return NamelistError::UNDEFINED;
}
/* Backslash: Quoted symbol expected */
// Backslash: Quoted symbol expected
if (c == '\\' && this->pos + 1 < len)
{
this->pos++;
......@@ -128,7 +128,7 @@ NamelistParser::parseString(const char *buf, size_t len, char quote)
// Allows escaped symbol \uXXXX
case 'u':
this->pos++;
for (int i = 0; i < 4 && this->pos < len && buf[this->pos] != '\0'; i++)
for (long i = 0; i < 4 && this->pos < len && buf[this->pos] != '\0'; i++)
{
// If it isn't a hex character we have an error
if (!((buf[this->pos] >= 48 && buf[this->pos] <= 57) || // 0-9
......@@ -161,7 +161,7 @@ NamelistParser::checkKeyname(const char *buf, NamelistToken *t)
while (isspace((int) buf[t->start]) && t->start < t->end) t->start++;
while (isspace((int) buf[t->end - 1]) && t->start < t->end) t->end--;
if ((t->end - t->start) < 1) return NamelistError::EMKEY;
for (int i = t->start; i < t->end; ++i)
for (long i = t->start; i < t->end; ++i)
if (isspace((int) buf[i])) return NamelistError::INKEY;
t->type = NamelistType::KEY;
break;
......@@ -186,7 +186,7 @@ NamelistParser::parse(const char *buf, size_t len)
{
case '&': this->newObject(); break;
case '/':
for (int i = this->toknext - 1; i >= 0; i--)
for (long i = this->toknext - 1; i >= 0; i--)
{
auto token = &this->tokens[i];
if (token->start != -1 && token->end == -1)
......@@ -236,7 +236,7 @@ NamelistParser::dump(const char *buf)
for (unsigned int it = 0; it < ntok; ++it)
{
auto t = &this->tokens[it];
auto length = t->end - t->start;
int length = t->end - t->start;
const auto start = buf + t->start;
printf("Token %u", it + 1);
if (t->type == NamelistType::OBJECT)
......
......@@ -44,10 +44,10 @@ class NamelistToken
{
public:
NamelistType type; // type (object, key, string word)
int start; // start position in NAMELIST buffer
int end; // end position in NAMELIST buffer
long start; // start position in NAMELIST buffer
long end; // end position in NAMELIST buffer
void fill(NamelistType type, int start, int end);
void fill(NamelistType type, long start, long end);
};
class NamelistParser
......@@ -56,7 +56,7 @@ public:
std::vector<NamelistToken> tokens;
unsigned int num_tokens = 0;
unsigned int toknext = 0;
unsigned int pos = 0;
unsigned long pos = 0;
unsigned int lineno = 0;
NamelistError parse(const char *buf, size_t len);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment