Skip to content

Commit

Permalink
lib/raster3d: fix -Wdeprecated-non-prototype compiler warnings (#2901)
Browse files Browse the repository at this point in the history
Split read and write functions, using function pointers do not work as the parameters
has deviating qualifiers (const vs non-const).
It does introduce some repetitive code, but do not remove the correctly used const
qualifiers in the Rast3d_key_set_double() and similar functions.
Note: the "write" part of Rast3d_readWriteWindow() in windowio.c is never used and
therefore removed. A write function is easily implemented if needed.
  • Loading branch information
nilason committed Feb 17, 2024
1 parent 047e004 commit 37c2bae
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 69 deletions.
132 changes: 103 additions & 29 deletions lib/raster3d/header.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,106 @@ int xdrLength;

/*---------------------------------------------------------------------------*/

static int Rast3d_readWriteHeader(
struct Key_Value *headerKeys, int doRead, int *proj, int *zone,
double *north, double *south, double *east, double *west, double *top,
double *bottom, int *rows, int *cols, int *depths, double *ew_res,
double *ns_res, double *tb_res, int *tileX, int *tileY, int *tileZ,
int *type, int *compression, int *useRle, int *useLzw, int *precision,
int *dataOffset, int *useXdr, int *hasIndex, char **unit,
int *vertical_unit, int *version)
static int Rast3d__readHeader(
struct Key_Value *headerKeys, int *proj, int *zone, double *north,
double *south, double *east, double *west, double *top, double *bottom,
int *rows, int *cols, int *depths, double *ew_res, double *ns_res,
double *tb_res, int *tileX, int *tileY, int *tileZ, int *type,
int *compression, int *useRle, int *useLzw, int *precision, int *dataOffset,
int *useXdr, int *hasIndex, char **unit, int *vertical_unit, int *version)
{
int returnVal;
int (*headerInt)(), (*headerDouble)(), (*headerValue)();
int (*headerString)();

if (doRead) {
headerDouble = Rast3d_key_get_double;
headerInt = Rast3d_key_get_int;
headerString = Rast3d_key_get_string;
headerValue = Rast3d_key_get_value;
}
else {
headerDouble = Rast3d_key_set_double;
headerInt = Rast3d_key_set_int;
headerString = Rast3d_key_set_string;
headerValue = Rast3d_key_set_value;
int (*headerInt)(struct Key_Value *, const char *, int *),
(*headerDouble)(struct Key_Value *, const char *, double *),
(*headerValue)(struct Key_Value *, const char *, char *, char *, int,
int, int *);
int (*headerString)(struct Key_Value *, const char *, char **);

headerDouble = Rast3d_key_get_double;
headerInt = Rast3d_key_get_int;
headerString = Rast3d_key_get_string;
headerValue = Rast3d_key_get_value;

returnVal = 1;
returnVal &= headerInt(headerKeys, RASTER3D_REGION_PROJ, proj);
returnVal &= headerInt(headerKeys, RASTER3D_REGION_ZONE, zone);

returnVal &= headerDouble(headerKeys, RASTER3D_REGION_NORTH, north);
returnVal &= headerDouble(headerKeys, RASTER3D_REGION_SOUTH, south);
returnVal &= headerDouble(headerKeys, RASTER3D_REGION_EAST, east);
returnVal &= headerDouble(headerKeys, RASTER3D_REGION_WEST, west);
returnVal &= headerDouble(headerKeys, RASTER3D_REGION_TOP, top);
returnVal &= headerDouble(headerKeys, RASTER3D_REGION_BOTTOM, bottom);

returnVal &= headerInt(headerKeys, RASTER3D_REGION_ROWS, rows);
returnVal &= headerInt(headerKeys, RASTER3D_REGION_COLS, cols);
returnVal &= headerInt(headerKeys, RASTER3D_REGION_DEPTHS, depths);

returnVal &= headerDouble(headerKeys, RASTER3D_REGION_NSRES, ns_res);
returnVal &= headerDouble(headerKeys, RASTER3D_REGION_EWRES, ew_res);
returnVal &= headerDouble(headerKeys, RASTER3D_REGION_TBRES, tb_res);

returnVal &= headerInt(headerKeys, RASTER3D_HEADER_TILEX, tileX);
returnVal &= headerInt(headerKeys, RASTER3D_HEADER_TILEY, tileY);
returnVal &= headerInt(headerKeys, RASTER3D_HEADER_TILEZ, tileZ);

returnVal &= headerValue(headerKeys, RASTER3D_HEADER_TYPE, "double",
"float", DCELL_TYPE, FCELL_TYPE, type);
returnVal &= headerValue(headerKeys, RASTER3D_HEADER_COMPRESSION, "0", "1",
0, 1, compression);
returnVal &=
headerValue(headerKeys, RASTER3D_HEADER_USERLE, "0", "1", 0, 1, useRle);
returnVal &=
headerValue(headerKeys, RASTER3D_HEADER_USELZW, "0", "1", 0, 1, useLzw);

returnVal &= headerInt(headerKeys, RASTER3D_HEADER_PRECISION, precision);
returnVal &= headerInt(headerKeys, RASTER3D_HEADER_DATA_OFFSET, dataOffset);

returnVal &=
headerValue(headerKeys, RASTER3D_HEADER_USEXDR, "0", "1", 0, 1, useXdr);
returnVal &= headerValue(headerKeys, RASTER3D_HEADER_HASINDEX, "0", "1", 0,
1, hasIndex);
returnVal &= headerString(headerKeys, RASTER3D_HEADER_UNIT, unit);
/* New format and API changes */
if (!headerInt(headerKeys, RASTER3D_HEADER_VERTICAL_UNIT, vertical_unit))
G_warning("You are using an old raster3d data format, the vertical "
"unit is undefined. "
"Please use r3.support to define the vertical unit to avoid "
"this warning.");
/* New format and API changes */
if (!headerInt(headerKeys, RASTER3D_HEADER_VERSION, version)) {
G_warning("You are using an old raster3d data format, the version is "
"undefined.");
*version = 1;
}

if (returnVal)
return 1;

Rast3d_error("Rast3d_readWriteHeader: error reading/writing header");
return 0;
}

static int Rast3d__writeHeader(
struct Key_Value *headerKeys, int *proj, int *zone, double *north,
double *south, double *east, double *west, double *top, double *bottom,
int *rows, int *cols, int *depths, double *ew_res, double *ns_res,
double *tb_res, int *tileX, int *tileY, int *tileZ, int *type,
int *compression, int *useRle, int *useLzw, int *precision, int *dataOffset,
int *useXdr, int *hasIndex, char **unit, int *vertical_unit, int *version)
{
int returnVal;
int (*headerInt)(struct Key_Value *, const char *, const int *),
(*headerDouble)(struct Key_Value *, const char *, const double *),
(*headerValue)(struct Key_Value *, const char *, const char *,
const char *, int, int, const int *);
int (*headerString)(struct Key_Value *, const char *, char *const *);

headerDouble = Rast3d_key_set_double;
headerInt = Rast3d_key_set_int;
headerString = Rast3d_key_set_string;
headerValue = Rast3d_key_set_value;

returnVal = 1;
returnVal &= headerInt(headerKeys, RASTER3D_REGION_PROJ, proj);
returnVal &= headerInt(headerKeys, RASTER3D_REGION_ZONE, zone);
Expand Down Expand Up @@ -141,11 +215,11 @@ int Rast3d_read_header(RASTER3D_Map *map, int *proj, int *zone, double *north,

headerKeys = G_read_key_value_file(path);

if (!Rast3d_readWriteHeader(
headerKeys, 1, proj, zone, north, south, east, west, top, bottom,
rows, cols, depths, ew_res, ns_res, tb_res, tileX, tileY, tileZ,
type, compression, useRle, useLzw, precision, dataOffset, useXdr,
hasIndex, unit, vertical_unit, version)) {
if (!Rast3d__readHeader(headerKeys, proj, zone, north, south, east, west,
top, bottom, rows, cols, depths, ew_res, ns_res,
tb_res, tileX, tileY, tileZ, type, compression,
useRle, useLzw, precision, dataOffset, useXdr,
hasIndex, unit, vertical_unit, version)) {
Rast3d_error(
"Rast3d_read_header: error extracting header key(s) of file %s",
path);
Expand All @@ -172,8 +246,8 @@ int Rast3d_write_header(RASTER3D_Map *map, int proj, int zone, double north,

headerKeys = G_create_key_value();

if (!Rast3d_readWriteHeader(
headerKeys, 0, &proj, &zone, &north, &south, &east, &west, &top,
if (!Rast3d__writeHeader(
headerKeys, &proj, &zone, &north, &south, &east, &west, &top,
&bottom, &rows, &cols, &depths, &ew_res, &ns_res, &tb_res, &tileX,
&tileY, &tileZ, &type, &compression, &useRle, &useLzw, &precision,
&dataOffset, &useXdr, &hasIndex, &unit, &vertical_unit, &version)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/raster3d/window.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void Rast3d_get_window(RASTER3D_Region *window)

/*---------------------------------------------------------------------------*/

RASTER3D_Region *Rast3d_window_ptr()
RASTER3D_Region *Rast3d_window_ptr(void)
{
return &g3d_window;
}
Expand Down
73 changes: 34 additions & 39 deletions lib/raster3d/windowio.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,38 @@

/*---------------------------------------------------------------------------*/

static int Rast3d_readWriteWindow(struct Key_Value *windowKeys, int doRead,
int *proj, int *zone, double *north,
double *south, double *east, double *west,
double *top, double *bottom, int *rows,
int *cols, int *depths, double *ew_res,
double *ns_res, double *tb_res)
static int Rast3d__readWindow(struct Key_Value *windowKeys, int *proj,
int *zone, double *north, double *south,
double *east, double *west, double *top,
double *bottom, int *rows, int *cols, int *depths,
double *ew_res, double *ns_res, double *tb_res)
{
int returnVal;
int (*windowInt)(), (*windowDouble)();

if (doRead) {
windowDouble = Rast3d_key_get_double;
windowInt = Rast3d_key_get_int;
}
else {
windowDouble = Rast3d_key_set_double;
windowInt = Rast3d_key_set_int;
}

returnVal = 1;
returnVal &= windowInt(windowKeys, RASTER3D_REGION_PROJ, proj);
returnVal &= windowInt(windowKeys, RASTER3D_REGION_ZONE, zone);

returnVal &= windowDouble(windowKeys, RASTER3D_REGION_NORTH, north);
returnVal &= windowDouble(windowKeys, RASTER3D_REGION_SOUTH, south);
returnVal &= windowDouble(windowKeys, RASTER3D_REGION_EAST, east);
returnVal &= windowDouble(windowKeys, RASTER3D_REGION_WEST, west);
returnVal &= windowDouble(windowKeys, RASTER3D_REGION_TOP, top);
returnVal &= windowDouble(windowKeys, RASTER3D_REGION_BOTTOM, bottom);

returnVal &= windowInt(windowKeys, RASTER3D_REGION_ROWS, rows);
returnVal &= windowInt(windowKeys, RASTER3D_REGION_COLS, cols);
returnVal &= windowInt(windowKeys, RASTER3D_REGION_DEPTHS, depths);

returnVal &= windowDouble(windowKeys, RASTER3D_REGION_EWRES, ew_res);
returnVal &= windowDouble(windowKeys, RASTER3D_REGION_NSRES, ns_res);
returnVal &= windowDouble(windowKeys, RASTER3D_REGION_TBRES, tb_res);
returnVal &= Rast3d_key_get_int(windowKeys, RASTER3D_REGION_PROJ, proj);
returnVal &= Rast3d_key_get_int(windowKeys, RASTER3D_REGION_ZONE, zone);

returnVal &=
Rast3d_key_get_double(windowKeys, RASTER3D_REGION_NORTH, north);
returnVal &=
Rast3d_key_get_double(windowKeys, RASTER3D_REGION_SOUTH, south);
returnVal &= Rast3d_key_get_double(windowKeys, RASTER3D_REGION_EAST, east);
returnVal &= Rast3d_key_get_double(windowKeys, RASTER3D_REGION_WEST, west);
returnVal &= Rast3d_key_get_double(windowKeys, RASTER3D_REGION_TOP, top);
returnVal &=
Rast3d_key_get_double(windowKeys, RASTER3D_REGION_BOTTOM, bottom);

returnVal &= Rast3d_key_get_int(windowKeys, RASTER3D_REGION_ROWS, rows);
returnVal &= Rast3d_key_get_int(windowKeys, RASTER3D_REGION_COLS, cols);
returnVal &= Rast3d_key_get_int(windowKeys, RASTER3D_REGION_DEPTHS, depths);

returnVal &=
Rast3d_key_get_double(windowKeys, RASTER3D_REGION_EWRES, ew_res);
returnVal &=
Rast3d_key_get_double(windowKeys, RASTER3D_REGION_NSRES, ns_res);
returnVal &=
Rast3d_key_get_double(windowKeys, RASTER3D_REGION_TBRES, tb_res);

if (returnVal)
return 1;
Expand Down Expand Up @@ -169,12 +164,12 @@ int Rast3d_read_window(RASTER3D_Region *window, const char *windowName)

windowKeys = G_read_key_value_file(path);

if (!Rast3d_readWriteWindow(
windowKeys, 1, &(window->proj), &(window->zone),
&(window->north), &(window->south), &(window->east),
&(window->west), &(window->top), &(window->bottom),
&(window->rows), &(window->cols), &(window->depths),
&(window->ew_res), &(window->ns_res), &(window->tb_res))) {
if (!Rast3d__readWindow(
windowKeys, &(window->proj), &(window->zone), &(window->north),
&(window->south), &(window->east), &(window->west),
&(window->top), &(window->bottom), &(window->rows),
&(window->cols), &(window->depths), &(window->ew_res),
&(window->ns_res), &(window->tb_res))) {
Rast3d_error(
"Rast3d_read_window: error extracting window key(s) of file %s",
path);
Expand Down

0 comments on commit 37c2bae

Please sign in to comment.