2010-06-03 21:24:43 +08:00
|
|
|
%{
|
|
|
|
/*********************************************************************
|
|
|
|
* Copyright 1993, UCAR/Unidata
|
|
|
|
* See netcdf/COPYRIGHT file for copying and redistribution conditions.
|
|
|
|
* $Id: ncgen.l,v 1.24 2009/09/25 18:22:35 dmh Exp $
|
|
|
|
*********************************************************************/
|
|
|
|
|
|
|
|
/* Problems:
|
2012-08-01 04:34:13 +08:00
|
|
|
1. We assume the input is true utf8.
|
2010-06-03 21:24:43 +08:00
|
|
|
Unfortunately, we may actually get iso-latin-8859-1.
|
|
|
|
This means that there will be ambiguity about the characters
|
|
|
|
in the range 128-255 because they will look like n-byte unicode
|
|
|
|
when they are 1-byte 8859 characters. Because of our encoding,
|
|
|
|
8859 characters above 128 will be handles as n-byte utf8 and so
|
|
|
|
will probably not lex correctly.
|
|
|
|
Solution: assume utf8 and note in the documentation that
|
2012-02-14 08:25:32 +08:00
|
|
|
ISO8859 is specifically unsupported.
|
2010-06-03 21:24:43 +08:00
|
|
|
2. The netcdf function NC_check_name in string.c must be modified to
|
|
|
|
conform to the use of UTF8.
|
|
|
|
3. We actually have three tests for UTF8 of increasing correctness
|
|
|
|
(in the sense that the least correct will allow some sequences that
|
|
|
|
are technically illegal UTF8).
|
|
|
|
The tests are derived from the table at
|
|
|
|
http://www.w3.org/2005/03/23-lex-U
|
|
|
|
We include lexical definitions for all three, but use the second version.
|
2012-01-27 11:17:03 +08:00
|
|
|
4. Single character constants enclosed in '...' cannot be
|
2012-08-01 04:34:13 +08:00
|
|
|
utf-8, so we assume they are by default encoded using the 1-byte
|
|
|
|
subset of utf-8. It turns out that this subset is in fact
|
|
|
|
equivalent to US-Ascii (7-bit).
|
2012-02-14 08:25:32 +08:00
|
|
|
We could use ISO-8859-1, but that conflicts with UTF-8 above value 127.
|
2010-06-03 21:24:43 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* lex specification for tokens for ncgen */
|
|
|
|
|
|
|
|
/* Fill value used by ncdump from version 2.4 and later. Should match
|
|
|
|
definition of FILL_STRING in ../ncdump/vardata.h */
|
|
|
|
#define FILL_STRING "_"
|
|
|
|
#define XDR_INT32_MIN (-2147483647-1)
|
|
|
|
#define XDR_INT32_MAX 2147483647
|
|
|
|
#define XDR_INT64_MIN (-9223372036854775807LL-1)
|
|
|
|
#define XDR_INT64_MAX (9223372036854775807LL)
|
|
|
|
|
2013-11-20 12:58:56 +08:00
|
|
|
/*Mnemonics*/
|
|
|
|
#define ISIDENT 1
|
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
char errstr[100]; /* for short error messages */
|
|
|
|
|
|
|
|
int lineno; /* line number for error messages */
|
2012-02-14 08:25:32 +08:00
|
|
|
Bytebuffer* lextext; /* name or string with escapes removed */
|
2010-06-03 21:24:43 +08:00
|
|
|
|
|
|
|
#define YY_BREAK /* defining as nothing eliminates unreachable
|
|
|
|
statement warnings from flex output,
|
|
|
|
but make sure every action ends with
|
|
|
|
"return" or "break"! */
|
|
|
|
|
2010-11-10 06:53:03 +08:00
|
|
|
int specialconstants; /* 1 if nan, nanf, infinity, etc is used */
|
2010-06-03 21:24:43 +08:00
|
|
|
double double_val; /* last double value read */
|
|
|
|
float float_val; /* last float value read */
|
|
|
|
long long int64_val; /* last int64 value read */
|
|
|
|
int int32_val; /* last int32 value read */
|
|
|
|
short int16_val; /* last short value read */
|
|
|
|
unsigned long long uint64_val; /* last int64 value read */
|
|
|
|
unsigned int uint32_val; /* last int32 value read */
|
|
|
|
unsigned short uint16_val; /* last short value read */
|
|
|
|
char char_val; /* last char value read */
|
|
|
|
signed char byte_val; /* last byte value read */
|
|
|
|
unsigned char ubyte_val; /* last byte value read */
|
|
|
|
|
|
|
|
static Symbol* makepath(char* text);
|
|
|
|
static int lexdebug(int);
|
2011-05-13 01:51:32 +08:00
|
|
|
static int parseLL(char* text);
|
2010-06-03 21:24:43 +08:00
|
|
|
|
|
|
|
static struct Specialtoken {
|
|
|
|
char* name;
|
|
|
|
int token;
|
|
|
|
} specials[] = {
|
|
|
|
{"_FillValue",_FILLVALUE},
|
|
|
|
{"_Format",_FORMAT},
|
|
|
|
{"_Storage",_STORAGE},
|
|
|
|
{"_ChunkSizes",_CHUNKSIZES},
|
|
|
|
{"_Fletcher32",_FLETCHER32},
|
|
|
|
{"_DeflateLevel",_DEFLATELEVEL},
|
|
|
|
{"_Shuffle",_SHUFFLE},
|
|
|
|
{"_Endianness",_ENDIANNESS},
|
|
|
|
{"_NoFill",_NOFILL},
|
|
|
|
{NULL,0} /* null terminate */
|
|
|
|
};
|
|
|
|
|
|
|
|
%}
|
|
|
|
%x ST_C_COMMENT
|
|
|
|
%x TEXT
|
|
|
|
%p 6000
|
|
|
|
|
|
|
|
/* The most correct (validating) version of UTF8 character set
|
|
|
|
(Taken from: http://www.w3.org/2005/03/23-lex-U)
|
|
|
|
|
|
|
|
The lines of the expression cover the UTF8 characters as follows:
|
|
|
|
1. non-overlong 2-byte
|
|
|
|
2. excluding overlongs
|
|
|
|
3. straight 3-byte
|
|
|
|
4. excluding surrogates
|
|
|
|
5. straight 3-byte
|
|
|
|
6. planes 1-3
|
|
|
|
7. planes 4-15
|
|
|
|
8. plane 16
|
|
|
|
|
|
|
|
UTF8 ([\xC2-\xDF][\x80-\xBF]) \
|
|
|
|
| (\xE0[\xA0-\xBF][\x80-\xBF]) \
|
|
|
|
| ([\xE1-\xEC][\x80-\xBF][\x80-\xBF]) \
|
|
|
|
| (\xED[\x80-\x9F][\x80-\xBF]) \
|
|
|
|
| ([\xEE-\xEF][\x80-\xBF][\x80-\xBF]) \
|
|
|
|
| (\xF0[\x90-\xBF][\x80-\xBF][\x80-\xBF]) \
|
|
|
|
| ([\xF1-\xF3][\x80-\xBF][\x80-\xBF][\x80-\xBF]) \
|
|
|
|
| (\xF4[\x80-\x8F][\x80-\xBF][\x80-\xBF]) \
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Wish there was some way to ifdef lex files */
|
|
|
|
|
|
|
|
/*The most relaxed version of UTF8 (not used)
|
|
|
|
UTF8 ([\xC0-\xD6].)|([\xE0-\xEF]..)|([\xF0-\xF7]...)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*The partially relaxed version of UTF8, and the one used here */
|
|
|
|
UTF8 ([\xC0-\xD6][\x80-\xBF])|([\xE0-\xEF][\x80-\xBF][\x80-\xBF])|([\xF0-\xF7][\x80-\xBF][\x80-\xBF][\x80-\xBF])
|
|
|
|
|
|
|
|
/* The old definition of ID
|
|
|
|
ID ([A-Za-z_]|{UTF8})([A-Z.@#\[\]a-z_0-9+-]|{UTF8})*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Don't permit control characters or '/' in names, but other special
|
|
|
|
chars OK if escaped. Note that to preserve backwards
|
|
|
|
compatibility, none of the characters _.@+- should be escaped, as
|
|
|
|
they were previously permitted in names without escaping. */
|
|
|
|
|
|
|
|
idescaped \\[ !"#$%&'()*,:;<=>?\[\\\]^`{|}~]
|
|
|
|
numescaped \\[0-9]
|
|
|
|
|
|
|
|
/* New definition to conform to a subset of string.c */
|
|
|
|
ID ([a-zA-Z_]|{UTF8}|{numescaped})([a-zA-Z0-9_.@+-]|{UTF8}|{idescaped})*
|
|
|
|
|
|
|
|
escaped \\.
|
|
|
|
|
|
|
|
/* Capture a datasetidentifier */
|
|
|
|
/* DATASETID ([a-zA-Z0-9!#$%&*:;<=>?/^|~_.@+-]|{UTF8})* */
|
|
|
|
DATASETID [^{][^{]*
|
|
|
|
|
|
|
|
|
|
|
|
/* Note: this definition of string will work for utf8 as well,
|
|
|
|
although it is a very relaxed definition
|
|
|
|
*/
|
|
|
|
nonquotes ([^"\\]|{escaped})*
|
|
|
|
exp ([eE][+-]?[0-9]+)
|
|
|
|
|
|
|
|
OPAQUESTRING (0[xX][0-9A-Fa-f][0-9A-Fa-f]*)
|
|
|
|
|
|
|
|
PATH ([/]|([/]{ID})([/]{ID})*)
|
|
|
|
|
|
|
|
SIMPLENUMBER [+-]?[0-9][0-9]*
|
|
|
|
XUNUMBER {OPAQUESTRING}[SsLl]
|
|
|
|
UNUMBER [0-9][0-9]*[Uu][BbSsLl]?
|
|
|
|
NUMBER [+-]?[0-9][0-9]*[BbSsLl]
|
|
|
|
DBLNUMBER [+-]?[0-9]*\.[0-9]*{exp}?[LlDd]?|[+-]?[0-9]*{exp}[LlDd]?
|
|
|
|
FLTNUMBER [+-]?[0-9]*\.[0-9]*{exp}?[Ff]|[+-]?[0-9]*{exp}[Ff]
|
|
|
|
|
|
|
|
SPECIAL "_FillValue"|"_Format"|"_Storage"|"_ChunkSizes"|"_Fletcher32"|"_DeflateLevel"|"_Shuffle"|"_Endianness"|"_NoFill"
|
|
|
|
|
2012-02-14 08:25:32 +08:00
|
|
|
USASCII [\x01-\x7F]
|
2012-01-27 11:17:03 +08:00
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
%%
|
|
|
|
[ \r\t\f]+ { /* whitespace */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
\/\/.* { /* comment */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-09-24 04:19:40 +08:00
|
|
|
\"{nonquotes}\" {int len;
|
2010-06-03 21:24:43 +08:00
|
|
|
/* In netcdf4, this will be used in a variety
|
|
|
|
of places, so only remove escapes */
|
|
|
|
/*
|
|
|
|
if(yyleng > MAXTRST) {
|
|
|
|
yyerror("string too long, truncated\n");
|
|
|
|
yytext[MAXTRST-1] = '\0';
|
|
|
|
}
|
|
|
|
*/
|
2013-09-24 04:19:40 +08:00
|
|
|
/* FIX: Assumes unescape also does normalization */
|
2013-09-24 07:08:50 +08:00
|
|
|
bbSetlength(lextext,yyleng-2);
|
2013-09-24 04:19:40 +08:00
|
|
|
len = unescape(bbContents(lextext),
|
2013-11-20 12:58:56 +08:00
|
|
|
(char *)yytext+1,yyleng-2,!ISIDENT);
|
2013-09-24 07:08:50 +08:00
|
|
|
if(len < 0) {
|
|
|
|
sprintf(errstr,"Illegal character: %s",yytext);
|
|
|
|
yyerror(errstr);
|
|
|
|
}
|
|
|
|
bbSetlength(lextext,len);
|
2012-02-14 08:25:32 +08:00
|
|
|
bbNull(lextext);
|
2010-06-03 21:24:43 +08:00
|
|
|
return lexdebug(TERMSTRING);
|
|
|
|
}
|
|
|
|
|
|
|
|
{OPAQUESTRING} { /* drop leading 0x; pad to even number of chars */
|
|
|
|
char* p = yytext+2;
|
|
|
|
int len = yyleng - 2;
|
2012-02-14 08:25:32 +08:00
|
|
|
bbClear(lextext);
|
|
|
|
bbAppendn(lextext,p,len);
|
2012-05-06 06:31:24 +08:00
|
|
|
if((len % 2) == 1) bbAppend(lextext,'0');
|
2012-02-14 08:25:32 +08:00
|
|
|
bbNull(lextext);
|
2010-06-03 21:24:43 +08:00
|
|
|
/* convert all chars to lower case */
|
2012-02-14 08:25:32 +08:00
|
|
|
for(p=bbContents(lextext);*p;p++) *p = tolower(*p);
|
2010-06-03 21:24:43 +08:00
|
|
|
return lexdebug(OPAQUESTRING);
|
|
|
|
}
|
|
|
|
|
2013-05-16 01:37:04 +08:00
|
|
|
compound|struct|structure {return lexdebug(COMPOUND);}
|
|
|
|
enum {return lexdebug(ENUM);}
|
|
|
|
opaque {return lexdebug(OPAQUE);}
|
|
|
|
|
|
|
|
float|real {return lexdebug(FLOAT_K);}
|
|
|
|
char {return lexdebug(CHAR_K);}
|
|
|
|
byte {return lexdebug(BYTE_K);}
|
|
|
|
ubyte {return lexdebug(UBYTE_K);}
|
|
|
|
short {return lexdebug(SHORT_K);}
|
|
|
|
ushort {return lexdebug(USHORT_K);}
|
|
|
|
long|int|integer {return lexdebug(INT_K);}
|
|
|
|
ulong|uint|uinteger {return lexdebug(UINT_K);}
|
|
|
|
int64 {return lexdebug(INT64_K);}
|
|
|
|
uint64 {return lexdebug(UINT64_K);}
|
|
|
|
double {return lexdebug(DOUBLE_K);}
|
2010-06-03 21:24:43 +08:00
|
|
|
unlimited|UNLIMITED {int32_val = -1;
|
|
|
|
return lexdebug(NC_UNLIMITED_K);}
|
|
|
|
|
2010-08-26 03:01:07 +08:00
|
|
|
types: {return lexdebug(TYPES);}
|
|
|
|
dimensions: {return lexdebug(DIMENSIONS);}
|
|
|
|
variables: {return lexdebug(VARIABLES);}
|
|
|
|
data: {return lexdebug(DATA);}
|
|
|
|
group: {return lexdebug(GROUP);}
|
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
(netcdf|NETCDF|netCDF) {BEGIN(TEXT);return lexdebug(NETCDF);}
|
|
|
|
|
2010-11-10 06:53:03 +08:00
|
|
|
DoubleInf|-?Infinity { /* missing value (pre-2.4 backward compatibility) */
|
2010-06-03 21:24:43 +08:00
|
|
|
if (yytext[0] == '-') {
|
2013-01-04 04:45:34 +08:00
|
|
|
double_val = NEGNC_INFINITE;
|
2010-06-03 21:24:43 +08:00
|
|
|
} else {
|
2013-01-04 04:45:34 +08:00
|
|
|
double_val = NC_INFINITE;
|
2010-06-03 21:24:43 +08:00
|
|
|
}
|
2010-11-10 06:53:03 +08:00
|
|
|
specialconstants = 1;
|
2010-06-03 21:24:43 +08:00
|
|
|
return lexdebug(DOUBLE_CONST);
|
|
|
|
}
|
2010-11-10 06:53:03 +08:00
|
|
|
NaN|nan { /* missing value (pre-2.4 backward compatibility) */
|
|
|
|
double_val = NAN;
|
|
|
|
specialconstants = 1;
|
|
|
|
return lexdebug(DOUBLE_CONST);
|
|
|
|
}
|
|
|
|
|
|
|
|
FloatInf|-?Infinityf|-?Inff {/* missing value (pre-2.4 backward compatibility)*/
|
2010-06-03 21:24:43 +08:00
|
|
|
if (yytext[0] == '-') {
|
2013-01-04 04:45:34 +08:00
|
|
|
float_val = NEGNC_INFINITEF;
|
2010-06-03 21:24:43 +08:00
|
|
|
} else {
|
2013-01-04 04:45:34 +08:00
|
|
|
float_val = NC_INFINITEF;
|
2010-06-03 21:24:43 +08:00
|
|
|
}
|
2010-11-10 06:53:03 +08:00
|
|
|
specialconstants = 1;
|
|
|
|
return lexdebug(FLOAT_CONST);
|
|
|
|
}
|
|
|
|
NaNf|nanf { /* missing value (pre-2.4 backward compatibility) */
|
|
|
|
float_val = NANF;
|
|
|
|
specialconstants = 1;
|
2010-06-03 21:24:43 +08:00
|
|
|
return lexdebug(FLOAT_CONST);
|
|
|
|
}
|
|
|
|
|
2013-07-11 04:00:48 +08:00
|
|
|
NIL|nil|Nil {
|
|
|
|
#ifdef USE_NETCDF4
|
2013-09-21 10:31:21 +08:00
|
|
|
if(l_flag == L_C || l_flag == L_BINARY)
|
2013-07-11 04:00:48 +08:00
|
|
|
return lexdebug(NIL);
|
|
|
|
yyerror("NIL only allowed for netcdf-4 and for -lc or -lb");
|
|
|
|
#else
|
|
|
|
yyerror("NIL only allowed for netcdf-4 and for -lc or -lb");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
{PATH} {
|
2012-02-14 08:25:32 +08:00
|
|
|
bbClear(lextext);
|
|
|
|
bbAppendn(lextext,(char*)yytext,yyleng+1); /* include null */
|
|
|
|
bbNull(lextext);
|
|
|
|
yylval.sym = makepath(bbContents(lextext));
|
2010-06-03 21:24:43 +08:00
|
|
|
return lexdebug(PATH);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
{SPECIAL} {struct Specialtoken* st;
|
2012-02-14 08:25:32 +08:00
|
|
|
bbClear(lextext);
|
|
|
|
bbAppendn(lextext,(char*)yytext,yyleng+1); /* include null */
|
|
|
|
bbNull(lextext);
|
2010-06-03 21:24:43 +08:00
|
|
|
for(st=specials;st->name;st++) {
|
2012-02-14 08:25:32 +08:00
|
|
|
if(strcmp(bbContents(lextext),st->name)==0) {return lexdebug(st->token);}
|
2010-06-03 21:24:43 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
<TEXT>{DATASETID} {
|
|
|
|
int c;
|
|
|
|
char* p; char* q;
|
|
|
|
/* copy the trimmed name */
|
2012-02-14 08:25:32 +08:00
|
|
|
bbClear(lextext);
|
|
|
|
bbAppendn(lextext,(char*)yytext,yyleng+1); /* include null */
|
|
|
|
bbNull(lextext);
|
|
|
|
p = bbContents(lextext);
|
|
|
|
q = p;
|
2010-06-03 21:24:43 +08:00
|
|
|
while((c=*p++)) {if(c > ' ') *q++ = c;}
|
|
|
|
*q = '\0';
|
2012-02-14 08:25:32 +08:00
|
|
|
datasetname = bbDup(lextext);
|
2010-06-03 21:24:43 +08:00
|
|
|
BEGIN(INITIAL);
|
|
|
|
return lexdebug(DATASETID);
|
|
|
|
}
|
|
|
|
|
2013-09-24 04:19:40 +08:00
|
|
|
{ID} { char* id; int len;
|
2012-02-14 08:25:32 +08:00
|
|
|
bbClear(lextext);
|
|
|
|
bbAppendn(lextext,(char*)yytext,yyleng+1); /* include null */
|
|
|
|
bbNull(lextext);
|
|
|
|
id = bbContents(lextext);
|
2013-11-20 12:58:56 +08:00
|
|
|
len = unescape(id,id,bbLength(lextext),ISIDENT);
|
2013-09-24 07:08:50 +08:00
|
|
|
bbSetlength(lextext,len);
|
2012-02-14 08:25:32 +08:00
|
|
|
if (STREQ(id, FILL_STRING)) return lexdebug(FILLMARKER);
|
|
|
|
yylval.sym = install(id);
|
2010-06-03 21:24:43 +08:00
|
|
|
return lexdebug(IDENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
{SIMPLENUMBER} {
|
|
|
|
/* We need to try to see what size of integer ((u)int). */
|
|
|
|
/* Technically, the user should specify, but... */
|
2011-05-13 01:51:32 +08:00
|
|
|
/* If out of any integer range, then complain */
|
|
|
|
switch (parseLL(yytext)) {
|
|
|
|
case 0:
|
|
|
|
return lexdebug(INT64_CONST); /* meaningless */
|
|
|
|
case -1:
|
2010-06-03 21:24:43 +08:00
|
|
|
#ifdef USE_NETCDF4
|
|
|
|
if(int64_val >= NC_MIN_INT) {
|
|
|
|
int32_val = (int)int64_val;
|
|
|
|
return lexdebug(INT_CONST);
|
|
|
|
} else
|
|
|
|
return lexdebug(INT64_CONST);
|
|
|
|
#else
|
2011-05-13 01:51:32 +08:00
|
|
|
/* Convert to int32, unless overflow then complain */
|
|
|
|
if(int64_val >=NC_MIN_INT) {
|
|
|
|
int32_val = (int)int64_val;
|
|
|
|
} else {
|
|
|
|
sprintf(errstr,"32 bit integer constant out of range: %s",(char*)yytext);
|
|
|
|
yyerror(errstr);
|
|
|
|
}
|
|
|
|
return lexdebug(INT_CONST);
|
2010-06-03 21:24:43 +08:00
|
|
|
#endif
|
2011-05-13 01:51:32 +08:00
|
|
|
case 1:
|
2010-06-03 21:24:43 +08:00
|
|
|
#ifdef USE_NETCDF4
|
|
|
|
if(uint64_val <= NC_MAX_INT) {
|
|
|
|
int32_val = (int)uint64_val;
|
|
|
|
return lexdebug(INT_CONST);
|
|
|
|
} else if(uint64_val <= NC_MAX_UINT) {
|
|
|
|
uint32_val = (unsigned int)uint64_val;
|
|
|
|
return lexdebug(UINT_CONST);
|
|
|
|
} else if(uint64_val <= NC_MAX_INT64) {
|
|
|
|
int64_val = (long long)uint64_val;
|
|
|
|
return lexdebug(INT64_CONST);
|
|
|
|
} else
|
|
|
|
return lexdebug(UINT64_CONST);
|
|
|
|
#else
|
2011-05-13 01:51:32 +08:00
|
|
|
/* Convert to int32 but complain if overflow */
|
|
|
|
if(uint64_val > NC_MAX_INT) {
|
|
|
|
sprintf(errstr,"32 bit integer constant out of range: %s",(char*)yytext);
|
|
|
|
yyerror(errstr);
|
|
|
|
}
|
2010-06-03 21:24:43 +08:00
|
|
|
int32_val = (int)uint64_val;
|
|
|
|
return lexdebug(INT_CONST);
|
|
|
|
#endif
|
Corrected "BAIL" macros to avoid infinite loop when logging is disabled and an
error occurs after an "exit:" label.
Corrected a dozen Coverity errors (mainly allocation issues, along with a few
other things):
711711, 711802, 711803, 711905, 970825, 996123, 996124, 1025787,
1047274, 1130013, 1130014, 1139538
Refactored internal fill-value code to correctly handle string types, and
especially to allow NULL pointers and null strings (ie. "") to be
distinguished. The code now avoids partially aliasing the two together
(which only happened on the 'write' side of things and wasn't reflected on
the 'read' side, adding to the previous confusion).
Probably still weak on handling fill-values of variable-length and compound
datatypes.
Refactored the recursive metadata reads a bit more, to process HDF5 named
datatypes and datasets immediately, avoiding chewing up memory for those
types of objects, etc.
Finished uncommenting and updating the nc_test4/tst_fills2.c code (as I'm
proceeding alphabetically through the nc_test4 code files).
2013-12-29 15:12:43 +08:00
|
|
|
default:
|
|
|
|
yyerror("Unknown integer size");
|
2010-06-03 21:24:43 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{NUMBER} { /* The number may be signed or unsigned (signed has priority) */
|
|
|
|
int slen = strlen(yytext);
|
|
|
|
int tag = yytext[slen-1];
|
|
|
|
int token = 0;
|
|
|
|
switch (tag) {
|
|
|
|
case 'B': case 'b':
|
|
|
|
if (sscanf((char*)yytext, "%d", &int32_val) != 1) {
|
|
|
|
sprintf(errstr,"bad byte constant: %s",(char*)yytext);
|
|
|
|
yyerror(errstr);
|
|
|
|
} else if(int32_val >= NC_MIN_BYTE && int32_val <= NC_MAX_BYTE) {
|
|
|
|
byte_val = (signed char)int32_val;
|
|
|
|
token = BYTE_CONST;
|
|
|
|
} else if(int32_val >= 0 && int32_val <= NC_MAX_UBYTE) {
|
|
|
|
ubyte_val = (unsigned char)int32_val;
|
|
|
|
token = UBYTE_CONST;
|
|
|
|
} else {
|
|
|
|
sprintf(errstr,"bad byte constant: %s",(char*)yytext);
|
|
|
|
yyerror(errstr);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'S': case 's':
|
|
|
|
if (sscanf((char*)yytext, "%d", &int32_val) != 1) {
|
|
|
|
sprintf(errstr,"bad short constant: %s",(char*)yytext);
|
|
|
|
yyerror(errstr);
|
|
|
|
} else if(int32_val >= NC_MIN_SHORT && int32_val <= NC_MAX_SHORT) {
|
|
|
|
int16_val = (signed short)int32_val;
|
|
|
|
token = SHORT_CONST;
|
|
|
|
} else if(int32_val >= 0 && int32_val <= NC_MAX_USHORT) {
|
|
|
|
uint16_val = (unsigned short)int32_val;
|
|
|
|
token = USHORT_CONST;
|
|
|
|
} else {
|
|
|
|
sprintf(errstr,"bad short constant: %s",(char*)yytext);
|
|
|
|
yyerror(errstr);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'L': case 'l':
|
2011-05-13 01:51:32 +08:00
|
|
|
switch(parseLL(yytext)) {
|
|
|
|
case 0:
|
2010-06-03 21:24:43 +08:00
|
|
|
sprintf(errstr,"bad int64 constant: %s",(char*)yytext);
|
|
|
|
yyerror(errstr);
|
2011-05-13 01:51:32 +08:00
|
|
|
break;
|
|
|
|
case -1: token = INT64_CONST; break;
|
2013-11-18 05:26:14 +08:00
|
|
|
case 1:
|
|
|
|
/* if value is too big, complain */
|
2014-03-09 11:41:30 +08:00
|
|
|
/* cannot actually test this.
|
2013-11-18 05:26:14 +08:00
|
|
|
if(uint64_val > NC_MAX_INT64) {
|
2014-03-09 11:41:30 +08:00
|
|
|
sprintf(errstr,"64 bit integer constant out of range: %s",(char*)yytext);
|
2013-11-18 05:26:14 +08:00
|
|
|
yyerror(errstr);
|
|
|
|
}
|
2014-03-09 11:41:30 +08:00
|
|
|
*/
|
|
|
|
int64_val = (long long)(uint64_val & 0x7fffffffffffffffLL);
|
2013-11-18 05:26:14 +08:00
|
|
|
token = INT64_CONST;
|
|
|
|
break;
|
2010-06-03 21:24:43 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:/*(optionally)signed string of digits; treat like int*/
|
|
|
|
sprintf(errstr,"bad numeric constant: %s",(char*)yytext);
|
|
|
|
yyerror(errstr);
|
|
|
|
}
|
|
|
|
return lexdebug(token);
|
|
|
|
}
|
|
|
|
|
|
|
|
{UNUMBER} {
|
|
|
|
int slen = strlen(yytext);
|
|
|
|
int tag = yytext[slen-1];
|
|
|
|
int token = 0;
|
|
|
|
switch (tag) {
|
|
|
|
case 'B': case 'b':
|
|
|
|
if (sscanf((char*)yytext, "%u", &uint32_val) != 1
|
|
|
|
|| uint32_val > NC_MAX_UBYTE) {
|
|
|
|
sprintf(errstr,"bad unsigned byte constant: %s",(char*)yytext);
|
|
|
|
yyerror(errstr);
|
|
|
|
}
|
|
|
|
ubyte_val = (unsigned char)uint32_val;
|
|
|
|
token = UBYTE_CONST;
|
|
|
|
break;
|
|
|
|
case 'S': case 's':
|
|
|
|
if (sscanf((char*)yytext, "%u", &uint32_val) != 1
|
|
|
|
|| uint32_val > NC_MAX_USHORT) {
|
|
|
|
sprintf(errstr,"bad unsigned short constant: %s",(char*)yytext);
|
|
|
|
yyerror(errstr);
|
|
|
|
}
|
|
|
|
uint16_val = (unsigned short)uint32_val;
|
|
|
|
token = USHORT_CONST;
|
|
|
|
break;
|
|
|
|
case 'L': case 'l':
|
|
|
|
if (sscanf((char*)yytext, "%llu", &uint64_val) != 1) {
|
|
|
|
sprintf(errstr,"bad unsigned int64 constant: %s",(char*)yytext);
|
|
|
|
yyerror(errstr);
|
|
|
|
}
|
|
|
|
token = UINT64_CONST;
|
|
|
|
break;
|
|
|
|
default: /* string of digits; treat like int */
|
|
|
|
if (sscanf((char*)yytext, "%u", &uint32_val) != 1) {
|
|
|
|
sprintf(errstr,"bad unsigned int constant: %s",(char*)yytext);
|
|
|
|
yyerror(errstr);
|
|
|
|
}
|
|
|
|
token = UINT_CONST;
|
|
|
|
}
|
|
|
|
return lexdebug(token);
|
|
|
|
}
|
|
|
|
{XUNUMBER} {
|
|
|
|
int c;
|
|
|
|
int token = 0;
|
|
|
|
int slen = strlen(yytext);
|
|
|
|
int tag = yytext[slen-1];
|
|
|
|
char* hex = yytext+2; /* point to first true hex digit */
|
|
|
|
int xlen = (slen - 3); /* true hex length */
|
|
|
|
yytext[slen-1] = '\0';
|
|
|
|
if(xlen > 16) { /* truncate hi order digits */
|
|
|
|
hex += (xlen - 16);
|
|
|
|
}
|
|
|
|
/* convert to an unsigned long long */
|
|
|
|
uint64_val = 0;
|
|
|
|
while((c=*hex++)) {
|
|
|
|
unsigned int hexdigit = (c <= '9'?(c-'0'):(c-'a')+0xa);
|
|
|
|
uint64_val = ((uint64_val << 4) | hexdigit);
|
|
|
|
}
|
|
|
|
switch (tag) {
|
|
|
|
case 'S': case 's':
|
|
|
|
uint16_val = (unsigned short)uint64_val;
|
|
|
|
token = USHORT_CONST;
|
|
|
|
break;
|
|
|
|
case 'L': case 'l':
|
|
|
|
token = UINT64_CONST;
|
|
|
|
break;
|
|
|
|
default: /* should never happen */
|
|
|
|
if (sscanf((char*)yytext, "%i", &uint32_val) != 1) {
|
|
|
|
sprintf(errstr,"bad unsigned int constant: %s",(char*)yytext);
|
|
|
|
yyerror(errstr);
|
|
|
|
}
|
|
|
|
token = UINT_CONST;
|
|
|
|
}
|
|
|
|
return lexdebug(token);
|
|
|
|
}
|
|
|
|
{DBLNUMBER} {
|
|
|
|
if (sscanf((char*)yytext, "%le", &double_val) != 1) {
|
|
|
|
sprintf(errstr,"bad long or double constant: %s",(char*)yytext);
|
|
|
|
yyerror(errstr);
|
|
|
|
}
|
|
|
|
return lexdebug(DOUBLE_CONST);
|
|
|
|
}
|
|
|
|
{FLTNUMBER} {
|
|
|
|
if (sscanf((char*)yytext, "%e", &float_val) != 1) {
|
|
|
|
sprintf(errstr,"bad float constant: %s",(char*)yytext);
|
|
|
|
yyerror(errstr);
|
|
|
|
}
|
|
|
|
return lexdebug(FLOAT_CONST);
|
|
|
|
}
|
|
|
|
\'[^\\]\' {
|
|
|
|
(void) sscanf((char*)&yytext[1],"%c",&byte_val);
|
|
|
|
return lexdebug(BYTE_CONST);
|
|
|
|
}
|
2013-09-24 07:08:50 +08:00
|
|
|
\'\\[0-7][0-7][0-7]\' {
|
2013-09-27 00:10:26 +08:00
|
|
|
int oct = unescapeoct(&yytext[2]);
|
|
|
|
if(oct < 0) {
|
2013-09-24 04:19:40 +08:00
|
|
|
sprintf(errstr,"bad octal character constant: %s",(char*)yytext);
|
|
|
|
yyerror(errstr);
|
|
|
|
}
|
2013-09-27 00:10:26 +08:00
|
|
|
byte_val = (unsigned int)oct;
|
2010-06-03 21:24:43 +08:00
|
|
|
return lexdebug(BYTE_CONST);
|
|
|
|
}
|
2013-09-24 07:08:50 +08:00
|
|
|
\'\\[xX][0-9a-fA-F][0-9a-fA-F]\' {
|
2013-09-27 00:10:26 +08:00
|
|
|
int hex = unescapehex(&yytext[3]);
|
2013-09-24 04:19:40 +08:00
|
|
|
if(byte_val < 0) {
|
|
|
|
sprintf(errstr,"bad hex character constant: %s",(char*)yytext);
|
|
|
|
yyerror(errstr);
|
|
|
|
}
|
2013-09-27 00:10:26 +08:00
|
|
|
byte_val = (unsigned int)hex;
|
2010-06-03 21:24:43 +08:00
|
|
|
return lexdebug(BYTE_CONST);
|
|
|
|
}
|
|
|
|
\'\\.\' {
|
|
|
|
switch ((char)yytext[2]) {
|
|
|
|
case 'a': byte_val = '\007'; break; /* not everyone under-
|
|
|
|
* stands '\a' yet */
|
|
|
|
case 'b': byte_val = '\b'; break;
|
|
|
|
case 'f': byte_val = '\f'; break;
|
|
|
|
case 'n': byte_val = '\n'; break;
|
|
|
|
case 'r': byte_val = '\r'; break;
|
|
|
|
case 't': byte_val = '\t'; break;
|
|
|
|
case 'v': byte_val = '\v'; break;
|
|
|
|
case '\\': byte_val = '\\'; break;
|
|
|
|
case '?': byte_val = '\177'; break;
|
|
|
|
case '\'': byte_val = '\''; break;
|
|
|
|
default: byte_val = (char)yytext[2];
|
|
|
|
}
|
|
|
|
return lexdebug(BYTE_CONST);
|
|
|
|
}
|
|
|
|
|
|
|
|
\n {
|
|
|
|
lineno++ ;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
"/""*" {/*initial*/
|
|
|
|
BEGIN(ST_C_COMMENT);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
<ST_C_COMMENT>([^*]|"*"[^/])* {/* continuation */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
<ST_C_COMMENT>"*/" {/* final */
|
|
|
|
BEGIN(INITIAL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
<ST_C_COMMENT><<EOF>> {/* final, error */
|
|
|
|
fprintf(stderr,"unterminated /**/ comment");
|
|
|
|
BEGIN(INITIAL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
. {/* Note: this next rule will not work for UTF8 characters */
|
|
|
|
return lexdebug(yytext[0]) ;
|
|
|
|
}
|
|
|
|
%%
|
|
|
|
static int
|
|
|
|
lexdebug(int token)
|
|
|
|
{
|
2010-11-10 06:53:03 +08:00
|
|
|
if(debug >= 2)
|
|
|
|
{
|
2012-08-31 00:43:34 +08:00
|
|
|
char* text = yytext;
|
|
|
|
text[yyleng] = 0;
|
|
|
|
fprintf(stderr,"Token=%d |%s| line=%d\n",token,text,lineno);
|
2010-06-03 21:24:43 +08:00
|
|
|
}
|
|
|
|
return token;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
lex_init(void)
|
|
|
|
{
|
|
|
|
lineno = 1;
|
2012-02-14 08:25:32 +08:00
|
|
|
lextext = bbNew();
|
2010-06-03 21:24:43 +08:00
|
|
|
if(0) unput(0); /* keep -Wall quiet */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Symbol*
|
|
|
|
makepath(char* text0)
|
|
|
|
{
|
2013-09-21 10:31:21 +08:00
|
|
|
/* Create a reference symbol.
|
|
|
|
Convert path to a sequence of symbols.
|
|
|
|
Use last name as symbol name (with root group reference ('/') as exception).
|
|
|
|
*/
|
|
|
|
Symbol* refsym = NULL;
|
2010-06-03 21:24:43 +08:00
|
|
|
/* walk the path converting to a sequence of symbols */
|
|
|
|
if(strcmp(text0,"/")==0) {
|
|
|
|
/* special case of root reference */
|
2013-09-21 10:31:21 +08:00
|
|
|
refsym = rootgroup;
|
2010-06-03 21:24:43 +08:00
|
|
|
} else {
|
|
|
|
List* prefix = listnew();
|
|
|
|
/* split the text into IDENT chunks, convert to symbols */
|
|
|
|
Symbol* container = rootgroup;
|
|
|
|
char *ident, *p;
|
|
|
|
char* text = strdup(text0);
|
2013-09-21 10:31:21 +08:00
|
|
|
int c,lastident;
|
2010-06-03 21:24:43 +08:00
|
|
|
ident=text+1; p=ident; /* skip leading '/' */
|
|
|
|
do {
|
2013-09-21 10:31:21 +08:00
|
|
|
lastident = 0;
|
2010-06-03 21:24:43 +08:00
|
|
|
switch ((c=*p)) {
|
|
|
|
default: p++; break;
|
|
|
|
case '\\': p++; if(*p == '/') p++; break;
|
|
|
|
case '\0': /* treat null terminator like trailing '/' (mostly) */
|
2013-09-21 10:31:21 +08:00
|
|
|
lastident=1; /* this is the last ident in the path */
|
2010-06-03 21:24:43 +08:00
|
|
|
/*fall thru */
|
|
|
|
case '/':
|
|
|
|
*p='\0';
|
2013-09-21 10:31:21 +08:00
|
|
|
if(!lastident) {
|
2013-11-20 12:58:56 +08:00
|
|
|
unescape(ident,ident,strlen(ident),ISIDENT);
|
2013-09-21 10:31:21 +08:00
|
|
|
refsym = lookupingroup(NC_GRP,ident,container);
|
|
|
|
if(refsym == NULL) {
|
2010-06-03 21:24:43 +08:00
|
|
|
sprintf(errstr,"Undefined or forward referenced group: %s",ident);
|
|
|
|
yyerror(errstr);
|
2013-09-21 10:31:21 +08:00
|
|
|
refsym = rootgroup;
|
2010-06-03 21:24:43 +08:00
|
|
|
} else {
|
2013-09-21 10:31:21 +08:00
|
|
|
listpush(prefix,(void*)refsym);
|
2010-06-03 21:24:43 +08:00
|
|
|
}
|
2013-09-21 10:31:21 +08:00
|
|
|
} else { /* lastident is true */
|
2013-11-20 12:58:56 +08:00
|
|
|
unescape(ident,ident,strlen(ident),ISIDENT);
|
2013-09-21 10:31:21 +08:00
|
|
|
refsym = install(ident);
|
|
|
|
refsym->objectclass = NC_GRP;/* tentative */
|
|
|
|
refsym->ref.is_ref = 1;
|
|
|
|
refsym->container = container;
|
|
|
|
refsym->subnodes = listnew();
|
2010-06-03 21:24:43 +08:00
|
|
|
}
|
2013-09-21 10:31:21 +08:00
|
|
|
container = refsym;
|
2010-06-03 21:24:43 +08:00
|
|
|
ident=p+1; p=ident;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while(c != '\0');
|
2013-09-21 10:31:21 +08:00
|
|
|
refsym->prefix = prefix;
|
2010-06-03 21:24:43 +08:00
|
|
|
free(text);
|
|
|
|
}
|
2013-09-21 10:31:21 +08:00
|
|
|
return refsym;
|
2010-06-03 21:24:43 +08:00
|
|
|
}
|
2011-05-13 01:51:32 +08:00
|
|
|
|
2013-09-21 10:31:21 +08:00
|
|
|
|
2011-05-13 01:51:32 +08:00
|
|
|
static int
|
|
|
|
parseLL(char* text)
|
|
|
|
{
|
|
|
|
int result = 0;
|
|
|
|
#if defined(HAVE_STRTOLL) && defined(HAVE_STRTOULL)
|
|
|
|
extern int errno;
|
|
|
|
char* endptr;
|
|
|
|
errno = 0; endptr = NULL;
|
|
|
|
if(text[0] == '-') {
|
|
|
|
int64_val = strtoll(text,&endptr,10);
|
|
|
|
result = -1; /* negative int64_val */
|
|
|
|
} else {
|
|
|
|
uint64_val = strtoull(text,&endptr,10);
|
|
|
|
result = 1; /* positive uint64_val */
|
|
|
|
}
|
|
|
|
if(result == 0) {
|
|
|
|
sprintf(errstr,"Unparseable 64 bit integer constant: %s",(char*)text);
|
|
|
|
yyerror(errstr);
|
|
|
|
} else if(errno == ERANGE) {
|
|
|
|
sprintf(errstr,"64 bit integer constant out of range: %s",(char*)text);
|
|
|
|
yyerror(errstr);
|
|
|
|
result = 0; /* out of range */
|
|
|
|
}
|
|
|
|
#else /*!(defined HAVE_STRTOLL && defined HAVE_STRTOULL)*/
|
|
|
|
if(text[0] == '-') {
|
|
|
|
sscanf((char*)text, "%lld", &int64_val);
|
|
|
|
result = -1; /* negative int64_val */
|
|
|
|
} else {
|
|
|
|
sscanf((char*)text, "%llu", &uint64_val);
|
|
|
|
result = 1; /* positive uint64_val */
|
|
|
|
}
|
|
|
|
/* Have no useful way to detect out of range */
|
|
|
|
#endif /*!(defined HAVE_STRTOLL && defined HAVE_STRTOULL)*/
|
|
|
|
return result;
|
|
|
|
}
|
2012-08-31 00:43:34 +08:00
|
|
|
|
|
|
|
|