ECC-1233: grib_filter: Allow printing of 'byte' keys like bitmap and section paddings

This commit is contained in:
Shahram Najm 2021-04-13 12:17:01 +01:00
parent 035d5635c4
commit ded1337e56
1 changed files with 24 additions and 22 deletions

View File

@ -173,6 +173,7 @@ int grib_recompose_name(grib_handle* h, grib_accessor* observer, const char* una
return GRIB_SUCCESS; return GRIB_SUCCESS;
} }
#if 0
int grib_accessor_print(grib_accessor* a, const char* name, int type, const char* format, int grib_accessor_print(grib_accessor* a, const char* name, int type, const char* format,
const char* separator, int maxcols, int* newline, FILE* out) const char* separator, int maxcols, int* newline, FILE* out)
{ {
@ -296,12 +297,13 @@ int grib_accessor_print(grib_accessor* a, const char* name, int type, const char
} }
return ret; return ret;
} }
#endif
int grib_accessors_list_print(grib_handle* h, grib_accessors_list* al, const char* name, int grib_accessors_list_print(grib_handle* h, grib_accessors_list* al, const char* name,
int type, const char* format, const char* separator, int maxcols, int* newline, FILE* out) int type, const char* format, const char* separator, int maxcols, int* newline, FILE* out)
{ {
size_t size = 0, len = 0, replen = 0; size_t size = 0, len = 0, replen = 0, j = 0;
char* sval = NULL; unsigned char* bval = NULL;
char* p = NULL; char* p = NULL;
double* dval = 0; double* dval = 0;
long* lval = 0; long* lval = 0;
@ -336,14 +338,14 @@ int grib_accessors_list_print(grib_handle* h, grib_accessors_list* al, const cha
} }
} }
else { else {
int i = 0;
int cols = 0; int cols = 0;
j = 0;
cvals = (char**)grib_context_malloc_clear(h->context, sizeof(char*) * size); cvals = (char**)grib_context_malloc_clear(h->context, sizeof(char*) * size);
grib_accessors_list_unpack_string(al, cvals, &size); grib_accessors_list_unpack_string(al, cvals, &size);
for (i = 0; i < size; i++) { for (j = 0; j < size; j++) {
*newline = 1; *newline = 1;
fprintf(out, "%s", cvals[i]); fprintf(out, "%s", cvals[j]);
if (i < size - 1) if (j < size - 1)
fprintf(out, "%s", myseparator); fprintf(out, "%s", myseparator);
cols++; cols++;
if (cols >= maxcols) { if (cols >= maxcols) {
@ -351,7 +353,7 @@ int grib_accessors_list_print(grib_handle* h, grib_accessors_list* al, const cha
*newline = 1; *newline = 1;
cols = 0; cols = 0;
} }
grib_context_free(h->context, cvals[i]); grib_context_free(h->context, cvals[j]);
} }
} }
grib_context_free(h->context, cvals); grib_context_free(h->context, cvals);
@ -364,12 +366,12 @@ int grib_accessors_list_print(grib_handle* h, grib_accessors_list* al, const cha
if (size == 1) if (size == 1)
fprintf(out, myformat, dval[0]); fprintf(out, myformat, dval[0]);
else { else {
int i = 0;
int cols = 0; int cols = 0;
for (i = 0; i < size; i++) { j = 0;
for (j = 0; j < size; j++) {
*newline = 1; *newline = 1;
fprintf(out, myformat, dval[i]); fprintf(out, myformat, dval[j]);
if (i < size - 1) if (j < size - 1)
fprintf(out, "%s", myseparator); fprintf(out, "%s", myseparator);
cols++; cols++;
if (cols >= maxcols) { if (cols >= maxcols) {
@ -389,12 +391,12 @@ int grib_accessors_list_print(grib_handle* h, grib_accessors_list* al, const cha
if (size == 1) if (size == 1)
fprintf(out, myformat, lval[0]); fprintf(out, myformat, lval[0]);
else { else {
int i = 0;
int cols = 0; int cols = 0;
for (i = 0; i < size; i++) { j = 0;
for (j = 0; j < size; j++) {
*newline = 1; *newline = 1;
fprintf(out, myformat, lval[i]); fprintf(out, myformat, lval[j]);
if (i < size - 1) if (j < size - 1)
fprintf(out, "%s", myseparator); fprintf(out, "%s", myseparator);
cols++; cols++;
if (cols >= maxcols) { if (cols >= maxcols) {
@ -408,13 +410,13 @@ int grib_accessors_list_print(grib_handle* h, grib_accessors_list* al, const cha
break; break;
case GRIB_TYPE_BYTES: case GRIB_TYPE_BYTES:
replen = a->length; replen = a->length;
sval = (char*)grib_context_malloc(h->context, replen * sizeof(char)); bval = (unsigned char*)grib_context_malloc(h->context, replen * sizeof(unsigned char));
ret = grib_unpack_string(al->accessor, sval, &replen); ret = grib_unpack_bytes(al->accessor, bval, &replen);
p = sval; for (j = 0; j < replen; j++) {
while ((replen--) > 0) fprintf(out, "%02x", bval[j]);
fprintf(out, "%c", *(p++)); }
grib_context_free(h->context, sval); grib_context_free(h->context, bval);
*newline = 0; *newline = 1;
break; break;
default: default:
grib_context_log(h->context, GRIB_LOG_WARNING, grib_context_log(h->context, GRIB_LOG_WARNING,