From 30ebf99535b6398fc694e406489e70a06b939d6b Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Wed, 28 Jun 2023 10:35:39 +0100 Subject: [PATCH] Dead code removal --- src/grib_accessor_class_codetable.cc | 4 -- src/grib_accessor_class_codetable_title.cc | 4 -- ...b_accessor_class_data_g1complex_packing.cc | 16 +++--- src/grib_api_internal.h | 2 - src/grib_context.cc | 14 +++-- src/grib_date.cc | 18 +++---- src/grib_dumper_class_debug.cc | 9 +--- src/grib_dumper_class_default.cc | 6 --- src/grib_dumper_class_grib_encode_C.cc | 4 -- src/grib_dumper_class_wmo.cc | 13 ++--- src/grib_loader_from_handle.cc | 6 +-- src/md5.cc | 52 ------------------- 12 files changed, 28 insertions(+), 120 deletions(-) diff --git a/src/grib_accessor_class_codetable.cc b/src/grib_accessor_class_codetable.cc index dfc05ff62..1bed5b609 100644 --- a/src/grib_accessor_class_codetable.cc +++ b/src/grib_accessor_class_codetable.cc @@ -613,11 +613,7 @@ static int unpack_string(grib_accessor* a, char* buffer, size_t* len) strcpy(tmp, table->entries[value].abbreviation); } else { -#if 1 snprintf(tmp, sizeof(tmp), "%d", (int)value); -#else - return GRIB_DECODING_ERROR; -#endif } l = strlen(tmp) + 1; diff --git a/src/grib_accessor_class_codetable_title.cc b/src/grib_accessor_class_codetable_title.cc index d7ef6a6bc..c2c19b6aa 100644 --- a/src/grib_accessor_class_codetable_title.cc +++ b/src/grib_accessor_class_codetable_title.cc @@ -157,11 +157,7 @@ static int unpack_string(grib_accessor* a, char* buffer, size_t* len) strcpy(tmp, table->entries[value].title); } else { -#if 1 snprintf(tmp, sizeof(tmp), "%d", (int)value); -#else - return GRIB_DECODING_ERROR; -#endif } l = strlen(tmp) + 1; diff --git a/src/grib_accessor_class_data_g1complex_packing.cc b/src/grib_accessor_class_data_g1complex_packing.cc index f0b560660..0a4c0646e 100644 --- a/src/grib_accessor_class_data_g1complex_packing.cc +++ b/src/grib_accessor_class_data_g1complex_packing.cc @@ -210,17 +210,17 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) if (ret == GRIB_SUCCESS) { n = a->offset + 4 * ((sub_k + 1) * (sub_k + 2)); -#if 1 + /* Octet number starts from beginning of message but shouldn't */ if ((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->N, n)) != GRIB_SUCCESS) return ret; -#else - ret = grib_get_long_internal(grib_handle_of_accessor(a), self->offsetsection, &offsetsection); - if (ret != GRIB_SUCCESS) - return ret; - if ((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->N, n - offsetsection)) != GRIB_SUCCESS) - return ret; -#endif + + // ret = grib_get_long_internal(grib_handle_of_accessor(a), self->offsetsection, &offsetsection); + // if (ret != GRIB_SUCCESS) + // return ret; + // if ((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->N, n - offsetsection)) != GRIB_SUCCESS) + // return ret; + ret = grib_get_long_internal(grib_handle_of_accessor(a), self->bits_per_value, &bits_per_value); if (ret != GRIB_SUCCESS) return ret; diff --git a/src/grib_api_internal.h b/src/grib_api_internal.h index 94fd5e815..9f413495b 100644 --- a/src/grib_api_internal.h +++ b/src/grib_api_internal.h @@ -1252,7 +1252,6 @@ struct grib_int_array int* el; }; -#if 1 struct grib_fieldset { grib_context* context; @@ -1267,7 +1266,6 @@ struct grib_fieldset long current; grib_field** fields; }; -#endif /* concept index structures */ diff --git a/src/grib_context.cc b/src/grib_context.cc index b2983b49f..90b531f6f 100644 --- a/src/grib_context.cc +++ b/src/grib_context.cc @@ -1069,17 +1069,15 @@ void grib_context_log(const grib_context* c, int level, const char* fmt, ...) level = level & ~GRIB_LOG_PERROR; /* #if HAS_STRERROR */ -#if 1 strcat(msg, " ("); strcat(msg, strerror(errsv)); strcat(msg, ")"); -#else - if (errsv > 0 && errsv < sys_nerr) { - strcat(msg, " ("); - strcat(msg, sys_errlist[errsv]); - strcat(msg, " )"); - } -#endif + + // if (errsv > 0 && errsv < sys_nerr) { + // strcat(msg, " ("); + // strcat(msg, sys_errlist[errsv]); + // strcat(msg, " )"); + // } } if (c->output_log) diff --git a/src/grib_date.cc b/src/grib_date.cc index cd2fc32cf..b069cb8b6 100644 --- a/src/grib_date.cc +++ b/src/grib_date.cc @@ -45,21 +45,19 @@ int grib_julian_to_datetime(double jd, long* year, long* month, long* day, *day = (long)dday; dday -= *day; -#if 1 /* ANF-CG 02.03.2012 */ s = ROUND((double)(dday * 86400)); /* total in sec , no msec*/ *hour = (long)s / 3600; *minute = (long)((s % 3600) / 60); *second = (long)(s % 60); -#else - /* Old algorithm, now replaced by above. See GRIB-180 */ - dhour = dday * 24; - *hour = (long)dhour; - dhour -= *hour; - dminute = dhour * 60; - *minute = (long)dminute; - *second = (long)((dminute - *minute) * 60); -#endif + + // Old algorithm, now replaced by above. See GRIB-180 + // dhour = dday * 24; + // *hour = (long)dhour; + // dhour -= *hour; + // dminute = dhour * 60; + // *minute = (long)dminute; + // *second = (long)((dminute - *minute) * 60); if (e < 14) *month = e - 1; diff --git a/src/grib_dumper_class_debug.cc b/src/grib_dumper_class_debug.cc index 75a6c858c..79c1ea29c 100644 --- a/src/grib_dumper_class_debug.cc +++ b/src/grib_dumper_class_debug.cc @@ -453,7 +453,6 @@ static void dump_values(grib_dumper* d, grib_accessor* a) k = 0; while (k < size) { -#if 1 int j; for (i = 0; i < d->depth + 3; i++) fprintf(self->dumper.out, " "); @@ -463,11 +462,6 @@ static void dump_values(grib_dumper* d, grib_accessor* a) fprintf(self->dumper.out, ", "); } fprintf(self->dumper.out, "\n"); -#else - - fprintf(self->dumper.out, "%d %g\n", k, buf[k]); - -#endif } if (more) { for (i = 0; i < d->depth + 3; i++) @@ -497,12 +491,11 @@ static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accesso /* grib_section* s = grib_get_sub_section(a); */ grib_section* s = a->sub_section; -#if 1 if (a->name[0] == '_') { grib_dump_accessors_block(d, block); return; } -#endif + for (i = 0; i < d->depth; i++) fprintf(self->dumper.out, " "); fprintf(self->dumper.out, "======> %s %s (%ld,%ld,%ld)\n", a->creator->op, diff --git a/src/grib_dumper_class_default.cc b/src/grib_dumper_class_default.cc index b3c87eb7e..61aface7f 100644 --- a/src/grib_dumper_class_default.cc +++ b/src/grib_dumper_class_default.cc @@ -611,7 +611,6 @@ static void dump_values(grib_dumper* d, grib_accessor* a) k = 0; while (k < size) { -#if 1 int j; fprintf(self->dumper.out, " "); for (j = 0; j < 5 && k < size; j++, k++) { @@ -620,11 +619,6 @@ static void dump_values(grib_dumper* d, grib_accessor* a) fprintf(self->dumper.out, ", "); } fprintf(self->dumper.out, "\n"); -#else - - fprintf(self->dumper.out, "%d %g\n", k, buf[k]); - -#endif } if (more) { fprintf(self->dumper.out, " "); diff --git a/src/grib_dumper_class_grib_encode_C.cc b/src/grib_dumper_class_grib_encode_C.cc index e6af382db..91d07b688 100644 --- a/src/grib_dumper_class_grib_encode_C.cc +++ b/src/grib_dumper_class_grib_encode_C.cc @@ -135,10 +135,8 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) if ((a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY)) return; -#if 1 if (comment) pcomment(self->dumper.out, value, comment); -#endif if (((a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0) && (value == GRIB_MISSING_LONG)) fprintf(self->dumper.out, " GRIB_CHECK(grib_set_missing(h,\"%s\"),%d);\n", a->name, 0); @@ -231,10 +229,8 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) if (a->length == 0) return; -#if 1 if (comment) fprintf(self->dumper.out, "/* %s */\n", comment); -#endif fprintf(self->dumper.out, " p = \"%s\";\n", value); fprintf(self->dumper.out, " size = strlen(p);\n"); diff --git a/src/grib_dumper_class_wmo.cc b/src/grib_dumper_class_wmo.cc index 6d84a0b28..7c898543a 100644 --- a/src/grib_dumper_class_wmo.cc +++ b/src/grib_dumper_class_wmo.cc @@ -486,7 +486,6 @@ static void dump_values(grib_dumper* d, grib_accessor* a) k = 0; while (k < size) { -#if 1 int j; /*for(i = 0; i < d->depth + 3 ; i++) fprintf(self->dumper.out," ");*/ for (j = 0; j < 8 && k < size; j++, k++) { @@ -498,14 +497,10 @@ static void dump_values(grib_dumper* d, grib_accessor* a) fprintf(self->dumper.out, ", "); } fprintf(self->dumper.out, "\n"); -#else - - if (is_char) - fprintf(self->dumper.out, "%d '%c'\n", k, (char)buf[k]); - else - fprintf(self->dumper.out, "%d %g\n", k, buf[k]); - -#endif + // if (is_char) + // fprintf(self->dumper.out, "%d '%c'\n", k, (char)buf[k]); + // else + // fprintf(self->dumper.out, "%d %g\n", k, buf[k]); } if (more) { /*for(i = 0; i < d->depth + 3 ; i++) fprintf(self->dumper.out," ");*/ diff --git a/src/grib_loader_from_handle.cc b/src/grib_loader_from_handle.cc index ccda34362..e47f9fa92 100644 --- a/src/grib_loader_from_handle.cc +++ b/src/grib_loader_from_handle.cc @@ -51,13 +51,9 @@ int grib_lookup_long_from_handle(grib_context* gc, grib_loader* loader, const ch if (b) return grib_unpack_long(b, value, &len); - /* TODO: fix me. For now, we don't fail on a lookup. */ -#if 1 + /* TODO: fix me. For now, we don't fail on a lookup. */ *value = -1; return GRIB_SUCCESS; -#else - return GRIB_NOT_FOUND; -#endif } int grib_init_accessor_from_handle(grib_loader* loader, grib_accessor* ga, grib_arguments* default_value) diff --git a/src/md5.cc b/src/md5.cc index 1d04a291b..2e011c2fd 100644 --- a/src/md5.cc +++ b/src/md5.cc @@ -154,58 +154,6 @@ static void grib_md5_flush(grib_md5_state* s) I_(c, d, a, b, 2, 62); I_(b, c, d, a, 9, 63); -#else - unsigned long i, g; - unsigned long a = s->h0; - unsigned long b = s->h1; - unsigned long c = s->h2; - unsigned long d = s->h3; - unsigned long f; - unsigned long temp; - unsigned long* w = &s->words[0]; - unsigned long h; - for (i = 0; i < 16; i++) { - f = F(b, c, d); - g = i; - temp = d; - d = c; - c = b; - h = a + f + k[i] + w[g]; - b = b + rotate(h, r[i]); - a = temp; - } - - for (i = 16; i < 32; i++) { - f = G(b, c, d); - g = (5 * i + 1) % 16; - temp = d; - d = c; - c = b; - h = a + f + k[i] + w[g]; - b = b + rotate(h, r[i]); - a = temp; - } - for (i = 32; i < 48; i++) { - f = H(b, c, d); - g = (3 * i + 5) % 16; - temp = d; - d = c; - c = b; - h = a + f + k[i] + w[g]; - b = b + rotate(h, r[i]); - a = temp; - } - for (i = 48; i < 64; i++) { - f = I(b, c, d); - g = (7 * i) % 16; - temp = d; - d = c; - c = b; - h = a + f + k[i] + w[g]; - b = b + rotate(h, r[i]); - a = temp; - } - #endif s->h0 += a;