Skip to content

Commit ae0ed52

Browse files
committed
lib/raster3d: fix -Wdeprecated-non-prototype compiler warnings
Split read and write functions, using function pointers do not work as the parameters has deviating qualifiers (const vs non-const).
1 parent 3d91a65 commit ae0ed52

File tree

3 files changed

+138
-69
lines changed

3 files changed

+138
-69
lines changed

lib/raster3d/header.c

Lines changed: 103 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -32,32 +32,106 @@ int xdrLength;
3232

3333
/*---------------------------------------------------------------------------*/
3434

35-
static int Rast3d_readWriteHeader(
36-
struct Key_Value *headerKeys, int doRead, int *proj, int *zone,
37-
double *north, double *south, double *east, double *west, double *top,
38-
double *bottom, int *rows, int *cols, int *depths, double *ew_res,
39-
double *ns_res, double *tb_res, int *tileX, int *tileY, int *tileZ,
40-
int *type, int *compression, int *useRle, int *useLzw, int *precision,
41-
int *dataOffset, int *useXdr, int *hasIndex, char **unit,
42-
int *vertical_unit, int *version)
35+
static int Rast3d__readHeader(
36+
struct Key_Value *headerKeys, int *proj, int *zone, double *north,
37+
double *south, double *east, double *west, double *top, double *bottom,
38+
int *rows, int *cols, int *depths, double *ew_res, double *ns_res,
39+
double *tb_res, int *tileX, int *tileY, int *tileZ, int *type,
40+
int *compression, int *useRle, int *useLzw, int *precision, int *dataOffset,
41+
int *useXdr, int *hasIndex, char **unit, int *vertical_unit, int *version)
4342
{
4443
int returnVal;
45-
int (*headerInt)(), (*headerDouble)(), (*headerValue)();
46-
int (*headerString)();
47-
48-
if (doRead) {
49-
headerDouble = Rast3d_key_get_double;
50-
headerInt = Rast3d_key_get_int;
51-
headerString = Rast3d_key_get_string;
52-
headerValue = Rast3d_key_get_value;
53-
}
54-
else {
55-
headerDouble = Rast3d_key_set_double;
56-
headerInt = Rast3d_key_set_int;
57-
headerString = Rast3d_key_set_string;
58-
headerValue = Rast3d_key_set_value;
44+
int (*headerInt)(struct Key_Value *, const char *, int *),
45+
(*headerDouble)(struct Key_Value *, const char *, double *),
46+
(*headerValue)(struct Key_Value *, const char *, char *, char *, int,
47+
int, int *);
48+
int (*headerString)(struct Key_Value *, const char *, char **);
49+
50+
headerDouble = Rast3d_key_get_double;
51+
headerInt = Rast3d_key_get_int;
52+
headerString = Rast3d_key_get_string;
53+
headerValue = Rast3d_key_get_value;
54+
55+
returnVal = 1;
56+
returnVal &= headerInt(headerKeys, RASTER3D_REGION_PROJ, proj);
57+
returnVal &= headerInt(headerKeys, RASTER3D_REGION_ZONE, zone);
58+
59+
returnVal &= headerDouble(headerKeys, RASTER3D_REGION_NORTH, north);
60+
returnVal &= headerDouble(headerKeys, RASTER3D_REGION_SOUTH, south);
61+
returnVal &= headerDouble(headerKeys, RASTER3D_REGION_EAST, east);
62+
returnVal &= headerDouble(headerKeys, RASTER3D_REGION_WEST, west);
63+
returnVal &= headerDouble(headerKeys, RASTER3D_REGION_TOP, top);
64+
returnVal &= headerDouble(headerKeys, RASTER3D_REGION_BOTTOM, bottom);
65+
66+
returnVal &= headerInt(headerKeys, RASTER3D_REGION_ROWS, rows);
67+
returnVal &= headerInt(headerKeys, RASTER3D_REGION_COLS, cols);
68+
returnVal &= headerInt(headerKeys, RASTER3D_REGION_DEPTHS, depths);
69+
70+
returnVal &= headerDouble(headerKeys, RASTER3D_REGION_NSRES, ns_res);
71+
returnVal &= headerDouble(headerKeys, RASTER3D_REGION_EWRES, ew_res);
72+
returnVal &= headerDouble(headerKeys, RASTER3D_REGION_TBRES, tb_res);
73+
74+
returnVal &= headerInt(headerKeys, RASTER3D_HEADER_TILEX, tileX);
75+
returnVal &= headerInt(headerKeys, RASTER3D_HEADER_TILEY, tileY);
76+
returnVal &= headerInt(headerKeys, RASTER3D_HEADER_TILEZ, tileZ);
77+
78+
returnVal &= headerValue(headerKeys, RASTER3D_HEADER_TYPE, "double",
79+
"float", DCELL_TYPE, FCELL_TYPE, type);
80+
returnVal &= headerValue(headerKeys, RASTER3D_HEADER_COMPRESSION, "0", "1",
81+
0, 1, compression);
82+
returnVal &=
83+
headerValue(headerKeys, RASTER3D_HEADER_USERLE, "0", "1", 0, 1, useRle);
84+
returnVal &=
85+
headerValue(headerKeys, RASTER3D_HEADER_USELZW, "0", "1", 0, 1, useLzw);
86+
87+
returnVal &= headerInt(headerKeys, RASTER3D_HEADER_PRECISION, precision);
88+
returnVal &= headerInt(headerKeys, RASTER3D_HEADER_DATA_OFFSET, dataOffset);
89+
90+
returnVal &=
91+
headerValue(headerKeys, RASTER3D_HEADER_USEXDR, "0", "1", 0, 1, useXdr);
92+
returnVal &= headerValue(headerKeys, RASTER3D_HEADER_HASINDEX, "0", "1", 0,
93+
1, hasIndex);
94+
returnVal &= headerString(headerKeys, RASTER3D_HEADER_UNIT, unit);
95+
/* New format and API changes */
96+
if (!headerInt(headerKeys, RASTER3D_HEADER_VERTICAL_UNIT, vertical_unit))
97+
G_warning("You are using an old raster3d data format, the vertical "
98+
"unit is undefined. "
99+
"Please use r3.support to define the vertical unit to avoid "
100+
"this warning.");
101+
/* New format and API changes */
102+
if (!headerInt(headerKeys, RASTER3D_HEADER_VERSION, version)) {
103+
G_warning("You are using an old raster3d data format, the version is "
104+
"undefined.");
105+
*version = 1;
59106
}
60107

108+
if (returnVal)
109+
return 1;
110+
111+
Rast3d_error("Rast3d_readWriteHeader: error reading/writing header");
112+
return 0;
113+
}
114+
115+
static int Rast3d__writeHeader(
116+
struct Key_Value *headerKeys, int *proj, int *zone, double *north,
117+
double *south, double *east, double *west, double *top, double *bottom,
118+
int *rows, int *cols, int *depths, double *ew_res, double *ns_res,
119+
double *tb_res, int *tileX, int *tileY, int *tileZ, int *type,
120+
int *compression, int *useRle, int *useLzw, int *precision, int *dataOffset,
121+
int *useXdr, int *hasIndex, char **unit, int *vertical_unit, int *version)
122+
{
123+
int returnVal;
124+
int (*headerInt)(struct Key_Value *, const char *, const int *),
125+
(*headerDouble)(struct Key_Value *, const char *, const double *),
126+
(*headerValue)(struct Key_Value *, const char *, const char *,
127+
const char *, int, int, const int *);
128+
int (*headerString)(struct Key_Value *, const char *, char *const *);
129+
130+
headerDouble = Rast3d_key_set_double;
131+
headerInt = Rast3d_key_set_int;
132+
headerString = Rast3d_key_set_string;
133+
headerValue = Rast3d_key_set_value;
134+
61135
returnVal = 1;
62136
returnVal &= headerInt(headerKeys, RASTER3D_REGION_PROJ, proj);
63137
returnVal &= headerInt(headerKeys, RASTER3D_REGION_ZONE, zone);
@@ -141,11 +215,11 @@ int Rast3d_read_header(RASTER3D_Map *map, int *proj, int *zone, double *north,
141215

142216
headerKeys = G_read_key_value_file(path);
143217

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

173247
headerKeys = G_create_key_value();
174248

175-
if (!Rast3d_readWriteHeader(
176-
headerKeys, 0, &proj, &zone, &north, &south, &east, &west, &top,
249+
if (!Rast3d__writeHeader(
250+
headerKeys, &proj, &zone, &north, &south, &east, &west, &top,
177251
&bottom, &rows, &cols, &depths, &ew_res, &ns_res, &tb_res, &tileX,
178252
&tileY, &tileZ, &type, &compression, &useRle, &useLzw, &precision,
179253
&dataOffset, &useXdr, &hasIndex, &unit, &vertical_unit, &version)) {

lib/raster3d/window.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void Rast3d_get_window(RASTER3D_Region *window)
6262

6363
/*---------------------------------------------------------------------------*/
6464

65-
RASTER3D_Region *Rast3d_window_ptr()
65+
RASTER3D_Region *Rast3d_window_ptr(void)
6666
{
6767
return &g3d_window;
6868
}

lib/raster3d/windowio.c

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -9,43 +9,38 @@
99

1010
/*---------------------------------------------------------------------------*/
1111

12-
static int Rast3d_readWriteWindow(struct Key_Value *windowKeys, int doRead,
13-
int *proj, int *zone, double *north,
14-
double *south, double *east, double *west,
15-
double *top, double *bottom, int *rows,
16-
int *cols, int *depths, double *ew_res,
17-
double *ns_res, double *tb_res)
12+
static int Rast3d__readWindow(struct Key_Value *windowKeys, int *proj,
13+
int *zone, double *north, double *south,
14+
double *east, double *west, double *top,
15+
double *bottom, int *rows, int *cols, int *depths,
16+
double *ew_res, double *ns_res, double *tb_res)
1817
{
1918
int returnVal;
20-
int (*windowInt)(), (*windowDouble)();
21-
22-
if (doRead) {
23-
windowDouble = Rast3d_key_get_double;
24-
windowInt = Rast3d_key_get_int;
25-
}
26-
else {
27-
windowDouble = Rast3d_key_set_double;
28-
windowInt = Rast3d_key_set_int;
29-
}
3019

3120
returnVal = 1;
32-
returnVal &= windowInt(windowKeys, RASTER3D_REGION_PROJ, proj);
33-
returnVal &= windowInt(windowKeys, RASTER3D_REGION_ZONE, zone);
34-
35-
returnVal &= windowDouble(windowKeys, RASTER3D_REGION_NORTH, north);
36-
returnVal &= windowDouble(windowKeys, RASTER3D_REGION_SOUTH, south);
37-
returnVal &= windowDouble(windowKeys, RASTER3D_REGION_EAST, east);
38-
returnVal &= windowDouble(windowKeys, RASTER3D_REGION_WEST, west);
39-
returnVal &= windowDouble(windowKeys, RASTER3D_REGION_TOP, top);
40-
returnVal &= windowDouble(windowKeys, RASTER3D_REGION_BOTTOM, bottom);
41-
42-
returnVal &= windowInt(windowKeys, RASTER3D_REGION_ROWS, rows);
43-
returnVal &= windowInt(windowKeys, RASTER3D_REGION_COLS, cols);
44-
returnVal &= windowInt(windowKeys, RASTER3D_REGION_DEPTHS, depths);
45-
46-
returnVal &= windowDouble(windowKeys, RASTER3D_REGION_EWRES, ew_res);
47-
returnVal &= windowDouble(windowKeys, RASTER3D_REGION_NSRES, ns_res);
48-
returnVal &= windowDouble(windowKeys, RASTER3D_REGION_TBRES, tb_res);
21+
returnVal &= Rast3d_key_get_int(windowKeys, RASTER3D_REGION_PROJ, proj);
22+
returnVal &= Rast3d_key_get_int(windowKeys, RASTER3D_REGION_ZONE, zone);
23+
24+
returnVal &=
25+
Rast3d_key_get_double(windowKeys, RASTER3D_REGION_NORTH, north);
26+
returnVal &=
27+
Rast3d_key_get_double(windowKeys, RASTER3D_REGION_SOUTH, south);
28+
returnVal &= Rast3d_key_get_double(windowKeys, RASTER3D_REGION_EAST, east);
29+
returnVal &= Rast3d_key_get_double(windowKeys, RASTER3D_REGION_WEST, west);
30+
returnVal &= Rast3d_key_get_double(windowKeys, RASTER3D_REGION_TOP, top);
31+
returnVal &=
32+
Rast3d_key_get_double(windowKeys, RASTER3D_REGION_BOTTOM, bottom);
33+
34+
returnVal &= Rast3d_key_get_int(windowKeys, RASTER3D_REGION_ROWS, rows);
35+
returnVal &= Rast3d_key_get_int(windowKeys, RASTER3D_REGION_COLS, cols);
36+
returnVal &= Rast3d_key_get_int(windowKeys, RASTER3D_REGION_DEPTHS, depths);
37+
38+
returnVal &=
39+
Rast3d_key_get_double(windowKeys, RASTER3D_REGION_EWRES, ew_res);
40+
returnVal &=
41+
Rast3d_key_get_double(windowKeys, RASTER3D_REGION_NSRES, ns_res);
42+
returnVal &=
43+
Rast3d_key_get_double(windowKeys, RASTER3D_REGION_TBRES, tb_res);
4944

5045
if (returnVal)
5146
return 1;
@@ -169,12 +164,12 @@ int Rast3d_read_window(RASTER3D_Region *window, const char *windowName)
169164

170165
windowKeys = G_read_key_value_file(path);
171166

172-
if (!Rast3d_readWriteWindow(
173-
windowKeys, 1, &(window->proj), &(window->zone),
174-
&(window->north), &(window->south), &(window->east),
175-
&(window->west), &(window->top), &(window->bottom),
176-
&(window->rows), &(window->cols), &(window->depths),
177-
&(window->ew_res), &(window->ns_res), &(window->tb_res))) {
167+
if (!Rast3d__readWindow(
168+
windowKeys, &(window->proj), &(window->zone), &(window->north),
169+
&(window->south), &(window->east), &(window->west),
170+
&(window->top), &(window->bottom), &(window->rows),
171+
&(window->cols), &(window->depths), &(window->ew_res),
172+
&(window->ns_res), &(window->tb_res))) {
178173
Rast3d_error(
179174
"Rast3d_read_window: error extracting window key(s) of file %s",
180175
path);

0 commit comments

Comments
 (0)