C++: Const correctness

This commit is contained in:
Shahram Najm 2022-06-02 19:29:29 +01:00
parent 3fb07b118e
commit 9d07ddb3ab
4 changed files with 15 additions and 15 deletions

View File

@ -104,7 +104,7 @@ int grib_tool_init(grib_runtime_options* options)
{
int opt = grib_options_on("C") + grib_options_on("O");
options->dump_mode = "default";
options->dump_mode = (char*)"default";
options->strict = 1; /* Must set here as bufr_dump has its own -S option */
if (opt > 1) {
@ -113,7 +113,7 @@ int grib_tool_init(grib_runtime_options* options)
}
if (grib_options_on("j:")) {
options->dump_mode = "json";
options->dump_mode = (char*)"json";
json_option = grib_options_get_option("j:");
if (strlen(json_option) > 1 || (json_option[0] != 's' && json_option[0] != 'f' && json_option[0] != 'a')) {
printf("%s: Invalid JSON option %s\n", tool_name, json_option);
@ -123,13 +123,13 @@ int grib_tool_init(grib_runtime_options* options)
}
if (grib_options_on("O")) {
options->dump_mode = "wmo";
options->dump_mode = (char*)"wmo";
json = 0;
options->dump_flags = GRIB_DUMP_FLAG_CODED | GRIB_DUMP_FLAG_OCTET | GRIB_DUMP_FLAG_VALUES | GRIB_DUMP_FLAG_READ_ONLY;
}
if (grib_options_on("p")) {
options->dump_mode = "bufr_simple";
options->dump_mode = (char*)"bufr_simple";
json = 0;
}
@ -240,7 +240,7 @@ int grib_tool_new_file_action(grib_runtime_options* options, grib_tools_file* fi
return 0;
}
static char* get_dumper_name(grib_runtime_options* options)
static const char* get_dumper_name(grib_runtime_options* options)
{
if (grib_options_on("E:")) {
/* Dumper for ENCODING */
@ -306,7 +306,7 @@ static void bufr_dump_descriptors(grib_handle* h)
char** array_names = NULL;
char** array_abbrevs = NULL;
char** array_units = NULL;
char* the_key = "expandedDescriptors";
const char* the_key = "expandedDescriptors";
GRIB_CHECK_NOLINE(grib_get_size(h, the_key, &size_desc), 0);
array_descriptors = (long*)malloc(size_desc * sizeof(long));

View File

@ -66,7 +66,7 @@ int grib_tool_init(grib_runtime_options* options)
{
int opt = grib_options_on("C") + grib_options_on("O") + grib_options_on("D") + grib_options_on("j");
options->dump_mode = "default";
options->dump_mode = (char*)"default";
if (opt > 1) {
fprintf(stderr, "%s: simultaneous j/O/D options not allowed\n", tool_name);
@ -74,7 +74,7 @@ int grib_tool_init(grib_runtime_options* options)
}
if (grib_options_on("j")) {
options->dump_mode = "json";
options->dump_mode = (char*)"json";
json = 1;
}
@ -89,12 +89,12 @@ int grib_tool_init(grib_runtime_options* options)
*/
if (grib_options_on("O")) {
options->dump_mode = "wmo";
options->dump_mode = (char*)"wmo";
options->dump_flags = GRIB_DUMP_FLAG_CODED | GRIB_DUMP_FLAG_OCTET | GRIB_DUMP_FLAG_VALUES | GRIB_DUMP_FLAG_READ_ONLY;
}
if (grib_options_on("D")) {
options->dump_mode = "debug";
options->dump_mode = (char*)"debug";
options->dump_flags = GRIB_DUMP_FLAG_VALUES | GRIB_DUMP_FLAG_READ_ONLY;
}

View File

@ -19,8 +19,8 @@ const char* tool_description = "Build an index file for a set of input GRIB file
const char* tool_name = "grib_index_build";
const char* tool_usage = "[options] grib_file grib_file ... ";
static grib_index* idx = NULL;
static char* keys;
static char* default_keys = "mars";
static const char* keys;
static const char* default_keys = "mars";
grib_option grib_options[] = {
/* {id, args, help}, on, command_line, value */

View File

@ -47,7 +47,7 @@ const char* tool_description =
"some keys.\n\tIt does not fail when a key is not found.";
const char* tool_name = "grib_ls";
const char* tool_usage = "[options] grib_file grib_file ...";
static char* new_handle = "";
static const char* new_handle = "";
int grib_options_count = sizeof(grib_options) / sizeof(grib_option);
static double lat = 0;
@ -219,7 +219,7 @@ static void print_key_values(grib_runtime_options* options, grib_handle* h)
{
int i;
int ret = 0;
char* s = "\"keys\" : {";
const char* s = "\"keys\" : {";
double dvalue = 0;
long lvalue = 0;
char value[MAX_STRING_LEN];
@ -322,7 +322,7 @@ int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h)
}
if (json_latlon) {
char* s = "\n[\n";
const char* s = "\n[\n";
double missingValue = 9999;
char value[MAX_STRING_LEN];
size_t len = MAX_STRING_LEN;