diff --git a/src/action_class_assert.cc b/src/action_class_assert.cc index 4261524fd..66cf04f56 100644 --- a/src/action_class_assert.cc +++ b/src/action_class_assert.cc @@ -137,8 +137,8 @@ static int execute(grib_action* a, grib_handle* h) } else { grib_context_log(h->context, GRIB_LOG_ERROR, "Assertion failure: "); - grib_expression_print(h->context, self->expression, h); - printf("\n"); + grib_expression_print(h->context, self->expression, h, stderr); + fprintf(stderr, "\n"); return GRIB_ASSERTION_FAILURE; } } diff --git a/src/action_class_if.cc b/src/action_class_if.cc index c310bada2..ec99ba315 100644 --- a/src/action_class_if.cc +++ b/src/action_class_if.cc @@ -154,9 +154,9 @@ static int create_accessor(grib_section* p, grib_action* act, grib_loader* h) next = a->block_false; if (p->h->context->debug > 1) { - printf("EVALUATE create_accessor_handle "); - grib_expression_print(p->h->context, a->expression, p->h); - printf(" [%s][_if%p]\n", (next == a->block_true ? "true" : "false"), (void*)a); + fprintf(stderr, "EVALUATE create_accessor_handle "); + grib_expression_print(p->h->context, a->expression, p->h, stderr); + fprintf(stderr, " [%s][_if%p]\n", (next == a->block_true ? "true" : "false"), (void*)a); /*grib_dump_action_branch(stdout,next,5);*/ } @@ -176,8 +176,8 @@ static int create_accessor(grib_section* p, grib_action* act, grib_loader* h) static void print_expression_debug_info(grib_context* ctx, grib_expression* exp, grib_handle* h) { - grib_expression_print(ctx, exp, h); /* writes to stdout without a newline */ - printf("\n"); + grib_expression_print(ctx, exp, h, stderr); /* writes without a newline */ + fprintf(stderr, "\n"); } static int execute(grib_action* act, grib_handle* h) @@ -240,7 +240,7 @@ static void dump(grib_action* act, FILE* f, int lvl) grib_context_print(act->context, f, " "); printf("if(%s) { ", act->name); - grib_expression_print(act->context, a->expression, 0); + grib_expression_print(act->context, a->expression, 0, stdout); printf("\n"); if (a->block_true) { @@ -252,7 +252,7 @@ static void dump(grib_action* act, FILE* f, int lvl) for (i = 0; i < lvl; i++) grib_context_print(act->context, f, " "); printf("else(%s) { ", act->name); - grib_expression_print(act->context, a->expression, 0); + grib_expression_print(act->context, a->expression, 0, stdout); /* grib_context_print(act->context,f,"ELSE \n" );*/ grib_dump_action_branch(f, a->block_false, lvl + 1); } diff --git a/src/action_class_when.cc b/src/action_class_when.cc index 31f377b44..640e75aab 100644 --- a/src/action_class_when.cc +++ b/src/action_class_when.cc @@ -149,7 +149,7 @@ static void dump(grib_action* act, FILE* f, int lvl) grib_context_print(act->context, f, " "); printf("when(%s) { ", act->name); - grib_expression_print(act->context, a->expression, 0); + grib_expression_print(act->context, a->expression, 0, stdout); printf("\n"); grib_dump_action_branch(f, a->block_true, lvl + 1); @@ -195,8 +195,8 @@ static int notify_change(grib_action* a, grib_accessor* observer, grib_accessor* if (self->loop) { printf("LOOP detected...\n"); printf("WHEN triggered by %s %ld\n", observed->name, lres); - grib_expression_print(observed->context, self->expression, 0); - printf("\n"); + grib_expression_print(observed->context, self->expression, 0, stderr); + fprintf(stderr, "\n"); return ret; } #endif @@ -206,8 +206,8 @@ static int notify_change(grib_action* a, grib_accessor* observer, grib_accessor* grib_context_log(hand->context, GRIB_LOG_DEBUG, "------------- SECTION action %s is triggered by [%s] (%s)", a->name, observed->name, a->debug_info ? a->debug_info : "no debug info"); - //grib_expression_print(observed->context, self->expression, 0); - //fprintf(stderr, "\n"); + grib_expression_print(observed->context, self->expression, 0, stderr); + fprintf(stderr, "\n"); } if (lres) diff --git a/src/eccodes_prototypes.h b/src/eccodes_prototypes.h index 3ce4d0838..61b02b61d 100644 --- a/src/eccodes_prototypes.h +++ b/src/eccodes_prototypes.h @@ -830,7 +830,7 @@ int grib_expression_evaluate_long(grib_handle* h, grib_expression* g, long* resu int grib_expression_evaluate_double(grib_handle* h, grib_expression* g, double* result); const char* grib_expression_evaluate_string(grib_handle* h, grib_expression* g, char* buf, size_t* size, int* err); const char* grib_expression_get_name(grib_expression* g); -void grib_expression_print(grib_context* ctx, grib_expression* g, grib_handle* f); +void grib_expression_print(grib_context* ctx, grib_expression* g, grib_handle* f, FILE*); void grib_expression_free(grib_context* ctx, grib_expression* g); void grib_expression_add_dependency(grib_expression* e, grib_accessor* observer); grib_arguments* grib_arguments_new(grib_context* c, grib_expression* g, grib_arguments* n); diff --git a/src/grib_api_internal.h b/src/grib_api_internal.h index 335da5954..dc0742d8a 100644 --- a/src/grib_api_internal.h +++ b/src/grib_api_internal.h @@ -891,7 +891,7 @@ typedef int (*expression_evaluate_double_proc)(grib_expression*, grib_handle*, d typedef const char* (*expression_evaluate_string_proc)(grib_expression*, grib_handle*, char*, size_t*, int*); typedef const char* (*expression_get_name_proc)(grib_expression*); -typedef void (*expression_print_proc)(grib_context*, grib_expression*, grib_handle*); +typedef void (*expression_print_proc)(grib_context*, grib_expression*, grib_handle*, FILE*); typedef void (*expression_add_dependency_proc)(grib_expression* e, grib_accessor* observer); typedef struct grib_expression_class grib_expression_class; diff --git a/src/grib_expression.cc b/src/grib_expression.cc index 4c1109640..314e5ad8d 100644 --- a/src/grib_expression.cc +++ b/src/grib_expression.cc @@ -74,12 +74,12 @@ const char* grib_expression_get_name(grib_expression* g) return 0; } -void grib_expression_print(grib_context* ctx, grib_expression* g, grib_handle* f) +void grib_expression_print(grib_context* ctx, grib_expression* g, grib_handle* f, FILE* out) { grib_expression_class* c = g->cclass; while (c) { if (c->print) { - c->print(ctx, g, f); + c->print(ctx, g, f, out); return; } c = c->super ? *(c->super) : NULL; @@ -163,7 +163,7 @@ void grib_arguments_print(grib_context* c, grib_arguments* g, grib_handle* f) { if (g) { if (g->expression) - grib_expression_print(c, g->expression, f); + grib_expression_print(c, g->expression, f, stdout); if (g->next) { printf(","); grib_arguments_print(c, g->next, f); diff --git a/src/grib_expression_class_accessor.cc b/src/grib_expression_class_accessor.cc index 064cc2051..efa42714a 100644 --- a/src/grib_expression_class_accessor.cc +++ b/src/grib_expression_class_accessor.cc @@ -42,7 +42,7 @@ or edit "expression.class" and rerun ./make_class.pl typedef const char* string; /* to keep make_class.pl happy */ static void destroy(grib_context*,grib_expression* e); -static void print(grib_context*,grib_expression*,grib_handle*); +static void print(grib_context*,grib_expression*,grib_handle*, FILE*); static void add_dependency(grib_expression* e, grib_accessor* observer); static string get_name(grib_expression* e); static int native_type(grib_expression*,grib_handle*); @@ -128,16 +128,16 @@ static string evaluate_string(grib_expression* g, grib_handle* h, char* buf, siz return buf; } -static void print(grib_context* c, grib_expression* g, grib_handle* f) +static void print(grib_context* c, grib_expression* g, grib_handle* f, FILE* out) { const grib_expression_accessor* e = (grib_expression_accessor*)g; - printf("access('%s", e->name); + fprintf(out, "access('%s", e->name); if (f) { long s = 0; grib_get_long(f, e->name, &s); - printf("=%ld", s); + fprintf(out, "=%ld", s); } - printf("')"); + fprintf(out, "')"); } static void destroy(grib_context* c, grib_expression* g) diff --git a/src/grib_expression_class_binop.cc b/src/grib_expression_class_binop.cc index 5caefd701..e1c4f3d02 100644 --- a/src/grib_expression_class_binop.cc +++ b/src/grib_expression_class_binop.cc @@ -42,7 +42,7 @@ or edit "expression.class" and rerun ./make_class.pl typedef const char* string; /* to keep make_class.pl happy */ static void destroy(grib_context*,grib_expression* e); -static void print(grib_context*,grib_expression*,grib_handle*); +static void print(grib_context*,grib_expression*,grib_handle*, FILE*); static void add_dependency(grib_expression* e, grib_accessor* observer); static int native_type(grib_expression*,grib_handle*); static int evaluate_long(grib_expression*,grib_handle*,long*); @@ -144,14 +144,28 @@ static int evaluate_double(grib_expression* g, grib_handle* h, double* dres) return GRIB_SUCCESS; } -static void print(grib_context* c, grib_expression* g, grib_handle* f) +static void print(grib_context* c, grib_expression* g, grib_handle* f, FILE* out) { grib_expression_binop* e = (grib_expression_binop*)g; - printf("binop("); - grib_expression_print(c, e->left, f); - printf(","); - grib_expression_print(c, e->right, f); - printf(")"); + + // Cover a subset of the most commonly used functions + // TODO(masn): Can be done in a much better way! + // e.g., the yacc parser passing in the functions name + if (e->long_func && e->long_func == grib_op_eq) { + fprintf(out, "equals("); + } else if (e->long_func && e->long_func == grib_op_ne) { + fprintf(out, "not_equals("); + } else if (e->long_func && e->long_func == grib_op_lt) { + fprintf(out, "less_than("); + } else if (e->long_func && e->long_func == grib_op_gt) { + fprintf(out, "greater_than("); + } else { + fprintf(out, "binop("); + } + grib_expression_print(c, e->left, f, out); + fprintf(out, ","); + grib_expression_print(c, e->right, f, out); + fprintf(out, ")"); } static void destroy(grib_context* c, grib_expression* g) diff --git a/src/grib_expression_class_double.cc b/src/grib_expression_class_double.cc index 89747194b..52d40832f 100644 --- a/src/grib_expression_class_double.cc +++ b/src/grib_expression_class_double.cc @@ -38,7 +38,7 @@ or edit "expression.class" and rerun ./make_class.pl typedef const char* string; /* to keep make_class.pl happy */ static void destroy(grib_context*,grib_expression* e); -static void print(grib_context*,grib_expression*,grib_handle*); +static void print(grib_context*,grib_expression*,grib_handle*, FILE*); static void add_dependency(grib_expression* e, grib_accessor* observer); static int native_type(grib_expression*,grib_handle*); static int evaluate_long(grib_expression*,grib_handle*,long*); @@ -85,10 +85,10 @@ static int evaluate_double(grib_expression* g, grib_handle* h, double* dres) return GRIB_SUCCESS; } -static void print(grib_context* c, grib_expression* g, grib_handle* f) +static void print(grib_context* c, grib_expression* g, grib_handle* f, FILE* out) { const grib_expression_double* e = (grib_expression_double*)g; - printf("double(%g)", e->value); + fprintf(out, "double(%g)", e->value); } static void destroy(grib_context* c, grib_expression* g) diff --git a/src/grib_expression_class_functor.cc b/src/grib_expression_class_functor.cc index 530654ea2..f335966a0 100644 --- a/src/grib_expression_class_functor.cc +++ b/src/grib_expression_class_functor.cc @@ -38,7 +38,7 @@ or edit "expression.class" and rerun ./make_class.pl typedef const char* string; /* to keep make_class.pl happy */ static void destroy(grib_context*,grib_expression* e); -static void print(grib_context*,grib_expression*,grib_handle*); +static void print(grib_context*,grib_expression*,grib_handle*,FILE*); static void add_dependency(grib_expression* e, grib_accessor* observer); static int native_type(grib_expression*,grib_handle*); static int evaluate_long(grib_expression*,grib_handle*,long*); @@ -216,12 +216,12 @@ static int evaluate_long(grib_expression* g, grib_handle* h, long* lres) return GRIB_NOT_IMPLEMENTED; } -static void print(grib_context* c, grib_expression* g, grib_handle* f) +static void print(grib_context* c, grib_expression* g, grib_handle* f, FILE* out) { const grib_expression_functor* e = (grib_expression_functor*)g; - printf("%s(", e->name); + fprintf(out, "%s(", e->name); // grib_expression_print(c,e->args,f); - printf(")"); + fprintf(out, ")"); } static void destroy(grib_context* c, grib_expression* g) diff --git a/src/grib_expression_class_is_in_dict.cc b/src/grib_expression_class_is_in_dict.cc index 142287cdc..46e0833f6 100644 --- a/src/grib_expression_class_is_in_dict.cc +++ b/src/grib_expression_class_is_in_dict.cc @@ -39,7 +39,7 @@ or edit "expression.class" and rerun ./make_class.pl typedef const char* string; /* to keep make_class.pl happy */ -static void print(grib_context*,grib_expression*,grib_handle*); +static void print(grib_context*,grib_expression*,grib_handle*,FILE*); static void add_dependency(grib_expression* e, grib_accessor* observer); static string get_name(grib_expression* e); static int native_type(grib_expression*,grib_handle*); @@ -200,16 +200,16 @@ static string evaluate_string(grib_expression* g, grib_handle* h, char* buf, siz // return buf; } -static void print(grib_context* c, grib_expression* g, grib_handle* f) +static void print(grib_context* c, grib_expression* g, grib_handle* f, FILE* out) { const grib_expression_is_in_dict* e = (grib_expression_is_in_dict*)g; - printf("access('%s", e->key); + fprintf(out, "access('%s", e->key); if (f) { long s = 0; grib_get_long(f, e->key, &s); - printf("=%ld", s); + fprintf(out, "=%ld", s); } - printf("')"); + fprintf(out, "')"); } grib_expression* new_is_in_dict_expression(grib_context* c, const char* name, const char* list) diff --git a/src/grib_expression_class_is_in_list.cc b/src/grib_expression_class_is_in_list.cc index f5339c309..3e5e3728d 100644 --- a/src/grib_expression_class_is_in_list.cc +++ b/src/grib_expression_class_is_in_list.cc @@ -41,7 +41,7 @@ or edit "expression.class" and rerun ./make_class.pl typedef const char* string; /* to keep make_class.pl happy */ static void destroy(grib_context*,grib_expression* e); -static void print(grib_context*,grib_expression*,grib_handle*); +static void print(grib_context*,grib_expression*,grib_handle*,FILE*); static void add_dependency(grib_expression* e, grib_accessor* observer); static string get_name(grib_expression* e); static int native_type(grib_expression*,grib_handle*); @@ -199,16 +199,16 @@ static string evaluate_string(grib_expression* g, grib_handle* h, char* buf, siz return buf; } -static void print(grib_context* c, grib_expression* g, grib_handle* f) +static void print(grib_context* c, grib_expression* g, grib_handle* f, FILE* out) { const grib_expression_is_in_list* e = (grib_expression_is_in_list*)g; - printf("access('%s", e->name); + fprintf(out, "access('%s", e->name); if (f) { long s = 0; grib_get_long(f, e->name, &s); - printf("=%ld", s); + fprintf(out, "=%ld", s); } - printf("')"); + fprintf(out, "')"); } static void destroy(grib_context* c, grib_expression* g) diff --git a/src/grib_expression_class_is_integer.cc b/src/grib_expression_class_is_integer.cc index da81cc4cb..bf203bc81 100644 --- a/src/grib_expression_class_is_integer.cc +++ b/src/grib_expression_class_is_integer.cc @@ -42,7 +42,7 @@ or edit "expression.class" and rerun ./make_class.pl typedef const char* string; /* to keep make_class.pl happy */ static void destroy(grib_context*,grib_expression* e); -static void print(grib_context*,grib_expression*,grib_handle*); +static void print(grib_context*,grib_expression*,grib_handle*, FILE*); static void add_dependency(grib_expression* e, grib_accessor* observer); static string get_name(grib_expression* e); static int native_type(grib_expression*,grib_handle*); @@ -140,7 +140,7 @@ static string evaluate_string(grib_expression* g, grib_handle* h, char* buf, siz return buf; } -static void print(grib_context* c, grib_expression* g, grib_handle* f) +static void print(grib_context* c, grib_expression* g, grib_handle* f, FILE* out) { // grib_expression_is_integer* e = (grib_expression_is_integer*)g; // printf("access('%s", e->name); diff --git a/src/grib_expression_class_length.cc b/src/grib_expression_class_length.cc index c9e967c77..c8c63f8e8 100644 --- a/src/grib_expression_class_length.cc +++ b/src/grib_expression_class_length.cc @@ -42,7 +42,7 @@ or edit "expression.class" and rerun ./make_class.pl typedef const char* string; /* to keep make_class.pl happy */ static void destroy(grib_context*,grib_expression* e); -static void print(grib_context*,grib_expression*,grib_handle*); +static void print(grib_context*,grib_expression*,grib_handle*,FILE*); static void add_dependency(grib_expression* e, grib_accessor* observer); static string get_name(grib_expression* e); static int native_type(grib_expression*,grib_handle*); @@ -123,16 +123,16 @@ static string evaluate_string(grib_expression* g, grib_handle* h, char* buf, siz return buf; } -static void print(grib_context* c, grib_expression* g, grib_handle* f) +static void print(grib_context* c, grib_expression* g, grib_handle* f, FILE* out) { const grib_expression_length* e = (grib_expression_length*)g; - printf("access('%s", e->name); + fprintf(out, "access('%s", e->name); if (f) { long s = 0; grib_get_long(f, e->name, &s); - printf("=%ld", s); + fprintf(out, "=%ld", s); } - printf("')"); + fprintf(out, "')"); } static void destroy(grib_context* c, grib_expression* g) diff --git a/src/grib_expression_class_logical_and.cc b/src/grib_expression_class_logical_and.cc index 902119a5e..d95de8d92 100644 --- a/src/grib_expression_class_logical_and.cc +++ b/src/grib_expression_class_logical_and.cc @@ -39,7 +39,7 @@ or edit "expression.class" and rerun ./make_class.pl typedef const char* string; /* to keep make_class.pl happy */ static void destroy(grib_context*,grib_expression* e); -static void print(grib_context*,grib_expression*,grib_handle*); +static void print(grib_context*,grib_expression*,grib_handle*, FILE*); static void add_dependency(grib_expression* e, grib_accessor* observer); static int native_type(grib_expression*,grib_handle*); static int evaluate_long(grib_expression*,grib_handle*,long*); @@ -133,14 +133,14 @@ static int evaluate_double(grib_expression* g, grib_handle* h, double* dres) return ret; } -static void print(grib_context* c, grib_expression* g, grib_handle* f) +static void print(grib_context* c, grib_expression* g, grib_handle* f, FILE* out) { grib_expression_logical_and* e = (grib_expression_logical_and*)g; - printf("("); - grib_expression_print(c, e->left, f); - printf(" && "); - grib_expression_print(c, e->right, f); - printf(")"); + fprintf(out, "("); + grib_expression_print(c, e->left, f, out); + fprintf(out, " && "); + grib_expression_print(c, e->right, f, out); + fprintf(out, ")"); } static void destroy(grib_context* c, grib_expression* g) diff --git a/src/grib_expression_class_logical_or.cc b/src/grib_expression_class_logical_or.cc index 772a73d8a..aed0618f3 100644 --- a/src/grib_expression_class_logical_or.cc +++ b/src/grib_expression_class_logical_or.cc @@ -39,7 +39,7 @@ or edit "expression.class" and rerun ./make_class.pl typedef const char* string; /* to keep make_class.pl happy */ static void destroy(grib_context*,grib_expression* e); -static void print(grib_context*,grib_expression*,grib_handle*); +static void print(grib_context*,grib_expression*,grib_handle*,FILE*); static void add_dependency(grib_expression* e, grib_accessor* observer); static int native_type(grib_expression*,grib_handle*); static int evaluate_long(grib_expression*,grib_handle*,long*); @@ -134,14 +134,14 @@ static int evaluate_double(grib_expression* g, grib_handle* h, double* dres) return ret; } -static void print(grib_context* c, grib_expression* g, grib_handle* f) +static void print(grib_context* c, grib_expression* g, grib_handle* f, FILE* out) { grib_expression_logical_or* e = (grib_expression_logical_or*)g; - printf("("); - grib_expression_print(c, e->left, f); - printf(" || "); - grib_expression_print(c, e->right, f); - printf(")"); + fprintf(out, "("); + grib_expression_print(c, e->left, f, out); + fprintf(out, " || "); + grib_expression_print(c, e->right, f, out); + fprintf(out, ")"); } static void destroy(grib_context* c, grib_expression* g) diff --git a/src/grib_expression_class_long.cc b/src/grib_expression_class_long.cc index 3b61a83d1..774f736e6 100644 --- a/src/grib_expression_class_long.cc +++ b/src/grib_expression_class_long.cc @@ -38,7 +38,7 @@ or edit "expression.class" and rerun ./make_class.pl typedef const char* string; /* to keep make_class.pl happy */ static void destroy(grib_context*,grib_expression* e); -static void print(grib_context*,grib_expression*,grib_handle*); +static void print(grib_context*,grib_expression*,grib_handle*,FILE*); static void add_dependency(grib_expression* e, grib_accessor* observer); static int native_type(grib_expression*,grib_handle*); static int evaluate_long(grib_expression*,grib_handle*,long*); @@ -85,10 +85,10 @@ static int evaluate_double(grib_expression* g, grib_handle* h, double* dres) return GRIB_SUCCESS; } -static void print(grib_context* c, grib_expression* g, grib_handle* f) +static void print(grib_context* c, grib_expression* g, grib_handle* f, FILE* out) { const grib_expression_long* e = (grib_expression_long*)g; - printf("long(%ld)", e->value); + fprintf(out, "long(%ld)", e->value); } static void destroy(grib_context* c, grib_expression* g) diff --git a/src/grib_expression_class_string.cc b/src/grib_expression_class_string.cc index 79d42e247..379140de7 100644 --- a/src/grib_expression_class_string.cc +++ b/src/grib_expression_class_string.cc @@ -37,7 +37,7 @@ or edit "expression.class" and rerun ./make_class.pl typedef const char* string; /* to keep make_class.pl happy */ static void destroy(grib_context*,grib_expression* e); -static void print(grib_context*,grib_expression*,grib_handle*); +static void print(grib_context*,grib_expression*,grib_handle*,FILE*); static void add_dependency(grib_expression* e, grib_accessor* observer); static int native_type(grib_expression*,grib_handle*); static string evaluate_string(grib_expression*,grib_handle*,char*,size_t*,int*); @@ -76,10 +76,10 @@ static const char* evaluate_string(grib_expression* g, grib_handle* h, char* buf return e->value; } -static void print(grib_context* c, grib_expression* g, grib_handle* f) +static void print(grib_context* c, grib_expression* g, grib_handle* f, FILE* out) { const grib_expression_string* e = (grib_expression_string*)g; - printf("string('%s')", e->value); + fprintf(out, "string('%s')", e->value); } static void destroy(grib_context* c, grib_expression* g) diff --git a/src/grib_expression_class_string_compare.cc b/src/grib_expression_class_string_compare.cc index 3003b5ef6..ac54cb6d2 100644 --- a/src/grib_expression_class_string_compare.cc +++ b/src/grib_expression_class_string_compare.cc @@ -40,7 +40,7 @@ or edit "expression.class" and rerun ./make_class.pl typedef const char* string; /* to keep make_class.pl happy */ static void destroy(grib_context*,grib_expression* e); -static void print(grib_context*,grib_expression*,grib_handle*); +static void print(grib_context*,grib_expression*,grib_handle*,FILE*); static void add_dependency(grib_expression* e, grib_accessor* observer); static int native_type(grib_expression*,grib_handle*); static int evaluate_long(grib_expression*,grib_handle*,long*); @@ -128,14 +128,14 @@ static int evaluate_double(grib_expression* g, grib_handle* h, double* dres) return ret; } -static void print(grib_context* c, grib_expression* g, grib_handle* f) +static void print(grib_context* c, grib_expression* g, grib_handle* f, FILE* out) { grib_expression_string_compare* e = (grib_expression_string_compare*)g; - printf("string_compare("); - grib_expression_print(c, e->left, f); - printf(","); - grib_expression_print(c, e->right, f); - printf(")"); + fprintf(out, "string_compare("); + grib_expression_print(c, e->left, f, out); + fprintf(out, ","); + grib_expression_print(c, e->right, f, out); + fprintf(out, ")"); } static void destroy(grib_context* c, grib_expression* g) diff --git a/src/grib_expression_class_sub_string.cc b/src/grib_expression_class_sub_string.cc index a5a0da732..dd44ec323 100644 --- a/src/grib_expression_class_sub_string.cc +++ b/src/grib_expression_class_sub_string.cc @@ -37,7 +37,7 @@ or edit "expression.class" and rerun ./make_class.pl typedef const char* string; /* to keep make_class.pl happy */ static void destroy(grib_context*,grib_expression* e); -static void print(grib_context*,grib_expression*,grib_handle*); +static void print(grib_context*,grib_expression*,grib_handle*,FILE*); static void add_dependency(grib_expression* e, grib_accessor* observer); static int native_type(grib_expression*,grib_handle*); static string evaluate_string(grib_expression*,grib_handle*,char*,size_t*,int*); @@ -76,10 +76,10 @@ static const char* evaluate_string(grib_expression* g, grib_handle* h, char* buf return e->value; } -static void print(grib_context* c, grib_expression* g, grib_handle* f) +static void print(grib_context* c, grib_expression* g, grib_handle* f, FILE* out) { const grib_expression_sub_string* e = (grib_expression_sub_string*)g; - printf("string('%s')", e->value); + fprintf(out, "string('%s')", e->value); } static void destroy(grib_context* c, grib_expression* g) diff --git a/src/grib_expression_class_true.cc b/src/grib_expression_class_true.cc index 6b418cb2c..382dec868 100644 --- a/src/grib_expression_class_true.cc +++ b/src/grib_expression_class_true.cc @@ -37,7 +37,7 @@ or edit "expression.class" and rerun ./make_class.pl typedef const char* string; /* to keep make_class.pl happy */ static void destroy(grib_context*,grib_expression* e); -static void print(grib_context*,grib_expression*,grib_handle*); +static void print(grib_context*,grib_expression*,grib_handle*,FILE*); static void add_dependency(grib_expression* e, grib_accessor* observer); static int native_type(grib_expression*,grib_handle*); static int evaluate_long(grib_expression*,grib_handle*,long*); @@ -81,10 +81,10 @@ static int evaluate_double(grib_expression* g, grib_handle* h, double* dres) return GRIB_SUCCESS; } -static void print(grib_context* c, grib_expression* g, grib_handle* f) +static void print(grib_context* c, grib_expression* g, grib_handle* f, FILE* out) { - printf("true("); - printf(")"); + fprintf(out, "true("); + fprintf(out, ")"); } static void destroy(grib_context* c, grib_expression* g) diff --git a/src/grib_expression_class_unop.cc b/src/grib_expression_class_unop.cc index ae7678043..0de77a02d 100644 --- a/src/grib_expression_class_unop.cc +++ b/src/grib_expression_class_unop.cc @@ -41,7 +41,7 @@ or edit "expression.class" and rerun ./make_class.pl typedef const char* string; /* to keep make_class.pl happy */ static void destroy(grib_context*,grib_expression* e); -static void print(grib_context*,grib_expression*,grib_handle*); +static void print(grib_context*,grib_expression*,grib_handle*,FILE*); static void add_dependency(grib_expression* e, grib_accessor* observer); static string get_name(grib_expression* e); static int native_type(grib_expression*,grib_handle*); @@ -105,12 +105,12 @@ static const char* get_name(grib_expression* g) return grib_expression_get_name(e->exp); } -static void print(grib_context* c, grib_expression* g, grib_handle* f) +static void print(grib_context* c, grib_expression* g, grib_handle* f, FILE* out) { grib_expression_unop* e = (grib_expression_unop*)g; - printf("unop("); - grib_expression_print(c, e->exp, f); - printf(")"); + fprintf(out, "unop("); + grib_expression_print(c, e->exp, f, out); + fprintf(out, ")"); } static void destroy(grib_context* c, grib_expression* g)