mirror of
https://github.com/Unidata/netcdf-c.git
synced 2024-11-21 03:13:42 +08:00
Merge pull request #2900 from ZedThree/silence-ncgen3-warnings
Fix warnings in `ncgen3`
This commit is contained in:
commit
6dc3789efe
@ -14,23 +14,32 @@ SET(ncgen3_FILES main.c load.c escapes.c getfill.c init.c genlib.c ncgeny.c ${XG
|
||||
FILE(GLOB COPY_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.nc ${CMAKE_CURRENT_SOURCE_DIR}/*.sh ${CMAKE_CURRENT_SOURCE_DIR}/*.cdl)
|
||||
FILE(COPY ${COPY_FILES} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/ FILE_PERMISSIONS OWNER_WRITE OWNER_READ OWNER_EXECUTE)
|
||||
|
||||
IF(NOT EXISTS ${netCDF_SOURCE_DIR}/ncgen3/ncgeny.c AND NOT EXISTS
|
||||
${netCDF_SOURCE_DIR}/ncgen3/ncgeny.h)
|
||||
ADD_CUSTOM_COMMAND(
|
||||
OUTPUT ncgentab.h
|
||||
COMMAND flex -Pncg -8 ncgen.l
|
||||
COMMAND rm -f ncgenl.c
|
||||
COMMAND mv lex.ncg.c ncgenl.c
|
||||
COMMAND bison -pncg -t -d ncgen.y
|
||||
COMMAND rm -f ncgeny.c ncgeny.h
|
||||
COMMAND mv ncgen.tab.c ncgeny.c
|
||||
COMMAND mv ncgen.tab.h ncgeny.h
|
||||
COMMAND mv ncgeny.h ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
COMMAND mv ncgeny.c ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
COMMAND mv ncgenl.c ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
VERBATIM
|
||||
# With this option enabled, automatically generate the parser source
|
||||
# files from the yacc input files when they're changed. They don't
|
||||
# change very often, so this option is off by default.
|
||||
if (NETCDF_GENERATE_NCGEN)
|
||||
find_program(FLEX flex REQUIRED)
|
||||
find_program(BISON bison REQUIRED)
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/ncgeny.h ${CMAKE_CURRENT_SOURCE_DIR}/ncgeny.c ${CMAKE_CURRENT_SOURCE_DIR}/ncgenl.c
|
||||
DEPENDS ncgen.y ncgen.l
|
||||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
||||
|
||||
COMMAND ${FLEX} -Pncg -8 ncgen/ncgen.l
|
||||
COMMAND mv lex.ncg.c "${CMAKE_CURRENT_SOURCE_DIR}/ncgenl.c"
|
||||
|
||||
COMMAND ${BISON} -pncg -t -d ncgen/ncgen.y
|
||||
COMMAND mv ncgen.tab.c "${CMAKE_CURRENT_SOURCE_DIR}/ncgeny.c"
|
||||
COMMAND mv ncgen.tab.h "${CMAKE_CURRENT_SOURCE_DIR}/ncgeny.h"
|
||||
|
||||
# Fix the `#line` preprocessor directives with the correct source paths
|
||||
COMMAND sed -i s/ncgen.tab/ncgeny/ "${CMAKE_CURRENT_SOURCE_DIR}/ncgeny.c"
|
||||
COMMAND sed -i s/lex.ncg/ncgenl/ "${CMAKE_CURRENT_SOURCE_DIR}/ncgenl.c"
|
||||
COMMAND sed -i s/ncgen.tab/ncgeny/ "${CMAKE_CURRENT_SOURCE_DIR}/ncgeny.h"
|
||||
VERBATIM
|
||||
)
|
||||
ENDIF()
|
||||
endif()
|
||||
|
||||
ADD_EXECUTABLE(ncgen3 ${ncgen3_FILES})
|
||||
TARGET_LINK_LIBRARIES(ncgen3 netcdf ${ALL_TLL_LIBS})
|
||||
|
@ -193,7 +193,7 @@ cstring(
|
||||
return cp;
|
||||
|
||||
case NC_DOUBLE:
|
||||
cp_size = 20;
|
||||
cp_size = 24;
|
||||
cp = (char *) emalloc (cp_size);
|
||||
doublep = (double *)valp;
|
||||
(void) snprintf(cp,cp_size,"%.16g",* (doublep + num));
|
||||
@ -1866,13 +1866,13 @@ extern char*
|
||||
decodify (
|
||||
const char *name)
|
||||
{
|
||||
int count; /* number chars in newname */
|
||||
size_t count; /* number chars in newname */
|
||||
char *newname;
|
||||
const char *cp;
|
||||
char *sp;
|
||||
static int init = 0;
|
||||
static char* repls[256]; /* replacement string for each char */
|
||||
static int lens[256]; /* lengths of replacement strings */
|
||||
static size_t lens[256]; /* lengths of replacement strings */
|
||||
static struct {
|
||||
char c;
|
||||
char *s;
|
||||
@ -1911,7 +1911,7 @@ decodify (
|
||||
{'/', "_SLASH_"} /* should not occur in names */
|
||||
/* {'_', "_UNDERSCORE_"} */
|
||||
};
|
||||
static int idtlen;
|
||||
static size_t idtlen;
|
||||
static size_t hexlen;
|
||||
int nctable = (sizeof(ctable))/(sizeof(ctable[0]));
|
||||
size_t newlen;
|
||||
@ -1924,12 +1924,12 @@ decodify (
|
||||
|
||||
for(i = 0; i < 128; i++) {
|
||||
rp = emalloc(2);
|
||||
rp[0] = i;
|
||||
rp[0] = (char)i;
|
||||
rp[1] = '\0';
|
||||
repls[i] = rp;
|
||||
}
|
||||
for(i=0; i < nctable; i++) {
|
||||
size_t j = ctable[i].c;
|
||||
size_t j = (size_t)ctable[i].c;
|
||||
free(repls[j]);
|
||||
repls[j] = ctable[i].s;
|
||||
}
|
||||
@ -1950,9 +1950,9 @@ decodify (
|
||||
while(*cp != '\0') { /* get number of extra bytes for newname */
|
||||
size_t j;
|
||||
if(*cp < 0) { /* handle signed or unsigned chars */
|
||||
j = *cp + 256;
|
||||
j = (size_t)*cp + 256;
|
||||
} else {
|
||||
j = *cp;
|
||||
j = (size_t)*cp;
|
||||
}
|
||||
count += lens[j] - 1;
|
||||
cp++;
|
||||
@ -1976,9 +1976,9 @@ decodify (
|
||||
size_t j, len;
|
||||
/* cp is current position in name, sp is current position in newname */
|
||||
if(*cp < 0) { /* j is table index for character *cp */
|
||||
j = *cp + 256;
|
||||
j = (size_t)*cp + 256;
|
||||
} else {
|
||||
j = *cp;
|
||||
j = (size_t)*cp;
|
||||
}
|
||||
len = strlcat(sp, repls[j], newlen);
|
||||
assert(len < newlen);
|
||||
|
@ -142,8 +142,8 @@ data:|DATA: {return (DATA);}
|
||||
yyerror("netCDF name required");
|
||||
return (DATA); /* generate syntax error */
|
||||
}
|
||||
netcdfname = (char *) emalloc(t-s+1);
|
||||
(void) strncpy(netcdfname, s, t-s);
|
||||
netcdfname = (char *) emalloc((size_t)(t-s+1));
|
||||
(void) strncpy(netcdfname, s, (size_t)(t-s));
|
||||
netcdfname[t-s] = '\0';
|
||||
deescapify(netcdfname); /* so "\5foo" becomes "5foo", for example */
|
||||
return (NETCDF);
|
||||
@ -184,7 +184,7 @@ FloatInf|-?Inff { /* missing value (pre-2.4 backward compatibility) */
|
||||
snprintf(errstr, sizeof(errstr),"bad byte constant: %s",(char*)yytext);
|
||||
yyerror(errstr);
|
||||
}
|
||||
byte_val = ii;
|
||||
byte_val = (signed char)ii;
|
||||
if (ii != (int)byte_val) {
|
||||
snprintf(errstr, sizeof(errstr),"byte constant out of range (-128,127): %s",(char*)yytext);
|
||||
yyerror(errstr);
|
||||
|
@ -142,7 +142,7 @@ dimdecline: dimdecl
|
||||
dimdecl: dimd '=' INT_CONST
|
||||
{ if (int_val <= 0)
|
||||
derror("dimension length must be positive");
|
||||
dims[ndims].size = int_val;
|
||||
dims[ndims].size = (size_t)int_val;
|
||||
ndims++;
|
||||
}
|
||||
| dimd '=' DOUBLE_CONST
|
||||
@ -629,10 +629,10 @@ const: CHAR_CONST
|
||||
atype_code = NC_SHORT;
|
||||
switch (valtype) {
|
||||
case NC_CHAR:
|
||||
*char_valp++ = short_val;
|
||||
*char_valp++ = (char)short_val;
|
||||
break;
|
||||
case NC_BYTE:
|
||||
*byte_valp++ = short_val;
|
||||
*byte_valp++ = (signed char)short_val;
|
||||
break;
|
||||
case NC_SHORT:
|
||||
*short_valp++ = short_val;
|
||||
@ -655,19 +655,19 @@ const: CHAR_CONST
|
||||
atype_code = NC_INT;
|
||||
switch (valtype) {
|
||||
case NC_CHAR:
|
||||
*char_valp++ = int_val;
|
||||
*char_valp++ = (char)int_val;
|
||||
break;
|
||||
case NC_BYTE:
|
||||
*byte_valp++ = int_val;
|
||||
*byte_valp++ = (signed char)int_val;
|
||||
break;
|
||||
case NC_SHORT:
|
||||
*short_valp++ = int_val;
|
||||
*short_valp++ = (short)int_val;
|
||||
break;
|
||||
case NC_INT:
|
||||
*int_valp++ = int_val;
|
||||
break;
|
||||
case NC_FLOAT:
|
||||
*float_valp++ = int_val;
|
||||
*float_valp++ = (float)int_val;
|
||||
break;
|
||||
case NC_DOUBLE:
|
||||
*double_valp++ = int_val;
|
||||
@ -681,16 +681,16 @@ const: CHAR_CONST
|
||||
atype_code = NC_FLOAT;
|
||||
switch (valtype) {
|
||||
case NC_CHAR:
|
||||
*char_valp++ = float_val;
|
||||
*char_valp++ = (char)float_val;
|
||||
break;
|
||||
case NC_BYTE:
|
||||
*byte_valp++ = float_val;
|
||||
*byte_valp++ = (signed char)float_val;
|
||||
break;
|
||||
case NC_SHORT:
|
||||
*short_valp++ = float_val;
|
||||
*short_valp++ = (short)float_val;
|
||||
break;
|
||||
case NC_INT:
|
||||
*int_valp++ = float_val;
|
||||
*int_valp++ = (int)float_val;
|
||||
break;
|
||||
case NC_FLOAT:
|
||||
*float_valp++ = float_val;
|
||||
@ -707,22 +707,22 @@ const: CHAR_CONST
|
||||
atype_code = NC_DOUBLE;
|
||||
switch (valtype) {
|
||||
case NC_CHAR:
|
||||
*char_valp++ = double_val;
|
||||
*char_valp++ = (char)double_val;
|
||||
break;
|
||||
case NC_BYTE:
|
||||
*byte_valp++ = double_val;
|
||||
*byte_valp++ = (signed char)double_val;
|
||||
break;
|
||||
case NC_SHORT:
|
||||
*short_valp++ = double_val;
|
||||
*short_valp++ = (short)double_val;
|
||||
break;
|
||||
case NC_INT:
|
||||
*int_valp++ = double_val;
|
||||
*int_valp++ = (int)double_val;
|
||||
break;
|
||||
case NC_FLOAT:
|
||||
if (double_val == NC_FILL_DOUBLE)
|
||||
*float_valp++ = NC_FILL_FLOAT;
|
||||
else
|
||||
*float_valp++ = double_val;
|
||||
*float_valp++ = (float)double_val;
|
||||
break;
|
||||
case NC_DOUBLE:
|
||||
*double_valp++ = double_val;
|
||||
|
933
ncgen3/ncgenl.c
933
ncgen3/ncgenl.c
File diff suppressed because it is too large
Load Diff
1497
ncgen3/ncgeny.c
1497
ncgen3/ncgeny.c
File diff suppressed because it is too large
Load Diff
@ -1,8 +1,9 @@
|
||||
/* A Bison parser, made by GNU Bison 3.0.4. */
|
||||
/* A Bison parser, made by GNU Bison 3.8.2. */
|
||||
|
||||
/* Bison interface for Yacc-like parsers in C
|
||||
|
||||
Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc.
|
||||
Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation,
|
||||
Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@ -15,7 +16,7 @@
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
/* As a special exception, you may create a larger work that contains
|
||||
part or all of the Bison parser skeleton and distribute that work
|
||||
@ -30,6 +31,10 @@
|
||||
This special exception was added by the Free Software Foundation in
|
||||
version 2.2 of Bison. */
|
||||
|
||||
/* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual,
|
||||
especially those whose name start with YY_ or yy_. They are
|
||||
private implementation details that can be changed or removed. */
|
||||
|
||||
#ifndef YY_NCG_NCGEN_TAB_H_INCLUDED
|
||||
# define YY_NCG_NCGEN_TAB_H_INCLUDED
|
||||
/* Debug traces. */
|
||||
@ -40,32 +45,37 @@
|
||||
extern int ncgdebug;
|
||||
#endif
|
||||
|
||||
/* Token type. */
|
||||
/* Token kinds. */
|
||||
#ifndef YYTOKENTYPE
|
||||
# define YYTOKENTYPE
|
||||
enum yytokentype
|
||||
{
|
||||
NC_UNLIMITED_K = 258,
|
||||
BYTE_K = 259,
|
||||
CHAR_K = 260,
|
||||
SHORT_K = 261,
|
||||
INT_K = 262,
|
||||
FLOAT_K = 263,
|
||||
DOUBLE_K = 264,
|
||||
IDENT = 265,
|
||||
TERMSTRING = 266,
|
||||
BYTE_CONST = 267,
|
||||
CHAR_CONST = 268,
|
||||
SHORT_CONST = 269,
|
||||
INT_CONST = 270,
|
||||
FLOAT_CONST = 271,
|
||||
DOUBLE_CONST = 272,
|
||||
DIMENSIONS = 273,
|
||||
VARIABLES = 274,
|
||||
NETCDF = 275,
|
||||
DATA = 276,
|
||||
FILLVALUE = 277
|
||||
YYEMPTY = -2,
|
||||
YYEOF = 0, /* "end of file" */
|
||||
YYerror = 256, /* error */
|
||||
YYUNDEF = 257, /* "invalid token" */
|
||||
NC_UNLIMITED_K = 258, /* NC_UNLIMITED_K */
|
||||
BYTE_K = 259, /* BYTE_K */
|
||||
CHAR_K = 260, /* CHAR_K */
|
||||
SHORT_K = 261, /* SHORT_K */
|
||||
INT_K = 262, /* INT_K */
|
||||
FLOAT_K = 263, /* FLOAT_K */
|
||||
DOUBLE_K = 264, /* DOUBLE_K */
|
||||
IDENT = 265, /* IDENT */
|
||||
TERMSTRING = 266, /* TERMSTRING */
|
||||
BYTE_CONST = 267, /* BYTE_CONST */
|
||||
CHAR_CONST = 268, /* CHAR_CONST */
|
||||
SHORT_CONST = 269, /* SHORT_CONST */
|
||||
INT_CONST = 270, /* INT_CONST */
|
||||
FLOAT_CONST = 271, /* FLOAT_CONST */
|
||||
DOUBLE_CONST = 272, /* DOUBLE_CONST */
|
||||
DIMENSIONS = 273, /* DIMENSIONS */
|
||||
VARIABLES = 274, /* VARIABLES */
|
||||
NETCDF = 275, /* NETCDF */
|
||||
DATA = 276, /* DATA */
|
||||
FILLVALUE = 277 /* FILLVALUE */
|
||||
};
|
||||
typedef enum yytokentype yytoken_kind_t;
|
||||
#endif
|
||||
|
||||
/* Value type. */
|
||||
@ -78,6 +88,8 @@ typedef int YYSTYPE;
|
||||
|
||||
extern YYSTYPE ncglval;
|
||||
|
||||
|
||||
int ncgparse (void);
|
||||
|
||||
|
||||
#endif /* !YY_NCG_NCGEN_TAB_H_INCLUDED */
|
||||
|
Loading…
Reference in New Issue
Block a user