diff options
author | mvglasow <michael -at- vonglasow.com> | 2015-11-02 12:13:56 +0100 |
---|---|---|
committer | mvglasow <michael -at- vonglasow.com> | 2015-11-02 12:13:56 +0100 |
commit | c2381c174cc6fe7e7e1e7b87a9e5988e7e59d1f2 (patch) | |
tree | f4e9bc0bd01a584d956f7a7fa38559e247e64a87 /navit | |
parent | 271fe67afa751b7a793027052262e8d2044f10e1 (diff) | |
download | navit-c2381c174cc6fe7e7e1e7b87a9e5988e7e59d1f2.tar.gz |
Add:core:Log descriptive error strings for saved commands
Signed-off-by: mvglasow <michael -at- vonglasow.com>
Diffstat (limited to 'navit')
-rw-r--r-- | navit/command.c | 50 | ||||
-rw-r--r-- | navit/command.h | 1 | ||||
-rw-r--r-- | navit/osd.c | 12 |
3 files changed, 60 insertions, 3 deletions
diff --git a/navit/command.c b/navit/command.c index abc64ee14..812abbc90 100644 --- a/navit/command.c +++ b/navit/command.c @@ -88,6 +88,51 @@ enum set_type { static void eval_comma(struct context *ctx, struct result *res); static struct attr ** eval_list(struct context *ctx); +/** + * @brief Converts an error to human-readable text. + * + * @param err The error code + * + * @return A string containing the error description. The caller is responsible for freeing up the string by + * calling {@code g_free()} when it is no longer needed. + */ +char *command_error_to_text(int err) { + switch (err) { + case no_error: + return g_strdup("no_error"); + case missing_double_quote: + return g_strdup("missing_double_quote"); + case missing_opening_parenthesis: + return g_strdup("missing_opening_parenthesis"); + case missing_closing_parenthesis: + return g_strdup("missing_closing_parenthesis"); + case missing_closing_brace: + return g_strdup("missing_closing_brace"); + case missing_colon: + return g_strdup("missing_colon"); + case missing_semicolon: + return g_strdup("missing_semicolon"); + case wrong_type: + return g_strdup("wrong_type"); + case illegal_number_format: + return g_strdup("illegal_number_format"); + case illegal_character: + return g_strdup("illegal_character"); + case missing_closing_bracket: + return g_strdup("missing_closing_bracket"); + case invalid_type: + return g_strdup("invalid_type"); + case not_ready: + return g_strdup("not_ready"); + case internal: + return g_strdup("internal"); + case eof_reached: + return g_strdup("eof_reached"); + default: + return g_strdup("unknown"); + } +} + static void result_free(struct result *res) { @@ -1360,6 +1405,7 @@ command_evaluate(struct attr *attr, const char *expr) * subsequent command call. Hence the g_strdup. */ char *expr_dup; + char *err = NULL; /* Error description */ struct context ctx={0,}; ctx.attr=attr; ctx.error=0; @@ -1372,7 +1418,9 @@ command_evaluate(struct attr *attr, const char *expr) char expr[32]; strncpy(expr, ctx.expr, 32); expr[31]='\0'; - dbg(lvl_error,"error %d starting at %s\n",ctx.error,expr); + err = command_error_to_text(ctx.error); + dbg(lvl_error, "error %s starting at %s\n", err, expr); + g_free(err); } g_free(expr_dup); } diff --git a/navit/command.h b/navit/command.h index 25d2dee09..985f347eb 100644 --- a/navit/command.h +++ b/navit/command.h @@ -39,6 +39,7 @@ struct callback_list; struct command_saved; struct command_table; struct navit; +char *command_error_to_text(int err); enum attr_type command_evaluate_to_attr(struct attr *attr, char *expr, int *error, struct attr *ret); void command_evaluate_to_void(struct attr *attr, char *expr, int *error); char *command_evaluate_to_string(struct attr *attr, char *expr, int *error); diff --git a/navit/osd.c b/navit/osd.c index 921b2d8ab..d5841b1ec 100644 --- a/navit/osd.c +++ b/navit/osd.c @@ -240,12 +240,16 @@ osd_std_keypress(struct osd_item *item, struct navit *nav, char *key) static void osd_std_reconfigure(struct osd_item *item, struct command_saved *cs) { + char *err = NULL; /* Error description */ + if (!command_saved_error(cs)) { item->configured = !! command_saved_get_int(cs); if (item->gr && !(item->flags & 16)) graphics_overlay_disable(item->gr, !item->configured); } else { - dbg(lvl_error, "Error in saved command: %i\n", command_saved_error(cs)); + err = command_error_to_text(command_saved_error(cs)); + dbg(lvl_error, "Error in saved command: %s, cs=%p.\n", err, cs); + g_free(err); } } @@ -330,6 +334,8 @@ void osd_std_config(struct osd_item *item, struct navit *navit) { struct attr attr; + char *err = NULL; /* Error description */ + dbg(lvl_debug,"enter\n"); if (item->enable_cs) { item->reconfig_cb = callback_new_1(callback_cast(osd_std_reconfigure), item); @@ -338,7 +344,9 @@ osd_std_config(struct osd_item *item, struct navit *navit) if (!command_saved_error(item->enable_cs)) { item->configured = !! command_saved_get_int(item->enable_cs); } else { - dbg(lvl_error, "Error in saved command: %i.\n", command_saved_error(item->enable_cs)); + err = command_error_to_text(command_saved_error(item->enable_cs)); + dbg(lvl_error, "Error in saved command: %s, item=%p.\n", err, item); + g_free(err); } } else { if (!navit_get_attr(navit, attr_osd_configuration, &attr, NULL)) |