diff --git a/src/Makefile_Eolian.am b/src/Makefile_Eolian.am index 09fa4d7085..a067ec0b7b 100644 --- a/src/Makefile_Eolian.am +++ b/src/Makefile_Eolian.am @@ -12,6 +12,7 @@ lib_eolian_libeolian_la_SOURCES = \ lib/eolian/eo_parser.c \ lib/eolian/eo_parser.h \ lib/eolian/eolian.c \ + lib/eolian/eolian_priv.h \ lib/eolian/eolian_database.c \ lib/eolian/eolian_database.h \ lib/eolian/database_class.c \ diff --git a/src/lib/eolian/database_class_api.c b/src/lib/eolian/database_class_api.c index 68e9338283..963a874f03 100644 --- a/src/lib/eolian/database_class_api.c +++ b/src/lib/eolian/database_class_api.c @@ -4,6 +4,7 @@ #include #include "eolian_database.h" +#include "eolian_priv.h" EAPI Eina_Stringshare * eolian_class_file_get(const Eolian_Class *cl) @@ -147,7 +148,7 @@ eolian_class_function_get_by_name(const Eolian_Class *cl, const char *func_name, } } - fprintf(stderr, "eolian: function '%s' not found in class '%s'\n", func_name, cl->name); + _eolian_log("function '%s' not found in class '%s'", func_name, cl->name); return NULL; } diff --git a/src/lib/eolian/database_expr.c b/src/lib/eolian/database_expr.c index 09be53e7f1..6a3b1d52f1 100644 --- a/src/lib/eolian/database_expr.c +++ b/src/lib/eolian/database_expr.c @@ -6,11 +6,12 @@ #include #include "eolian_database.h" +#include "eolian_priv.h" static Eina_Bool node_error(const Eolian_Object *obj, const char *msg) { - fprintf(stderr, "eolian:%s:%d:%d: %s\n", obj->file, obj->line, obj->column, msg); + _eolian_log_line(obj->file, obj->line, obj->column, "%s", msg); return EINA_FALSE; } diff --git a/src/lib/eolian/database_validate.c b/src/lib/eolian/database_validate.c index ed005edb3b..6ed286866b 100644 --- a/src/lib/eolian/database_validate.c +++ b/src/lib/eolian/database_validate.c @@ -6,6 +6,7 @@ #endif #include "eo_lexer.h" +#include "eolian_priv.h" static Eina_Bool _validate(Eolian_Object *obj) @@ -33,8 +34,8 @@ _validate_docstr(Eina_Stringshare *str, const Eolian_Object *info) if (eolian_doc_token_ref_get(NULL, &tok, NULL, NULL) == EOLIAN_DOC_REF_INVALID) { char *refn = eolian_doc_token_text_get(&tok); - fprintf(stderr, "eolian:%s:%d:%d: failed validating reference '%s'\n", - info->file, info->line, info->column, refn); + _eolian_log_line(info->file, info->line, info->column, + "failed validating reference '%s'", refn); free(refn); ret = EINA_FALSE; break; @@ -98,7 +99,7 @@ _ef_map_cb(const Eina_Hash *hash EINA_UNUSED, const void *key EINA_UNUSED, static Eina_Bool _obj_error(const Eolian_Object *o, const char *msg) { - fprintf(stderr, "eolian:%s:%d:%d: %s\n", o->file, o->line, o->column, msg); + _eolian_log_line(o->file, o->line, o->column, "%s", msg); return EINA_FALSE; } diff --git a/src/lib/eolian/eo_lexer.c b/src/lib/eolian/eo_lexer.c index c081fce4a7..d3f3f09b03 100644 --- a/src/lib/eolian/eo_lexer.c +++ b/src/lib/eolian/eo_lexer.c @@ -10,6 +10,7 @@ #include #include "eo_lexer.h" +#include "eolian_priv.h" static int lastbytes = 0; @@ -107,8 +108,8 @@ throw(Eo_Lexer *ls, const char *fmt, ...) for (i = 0; i < ls->column; ++i) eina_strbuf_append_char(buf, ' '); eina_strbuf_append(buf, "^\n"); - fprintf(stderr, "eolian:%s:%d:%d: %s\n", ls->source, ls->line_number, - ls->column, eina_strbuf_string_get(buf)); + _eolian_log_line(ls->source, ls->line_number, ls->column, + "%s", eina_strbuf_string_get(buf)); eina_strbuf_free(buf); longjmp(ls->err_jmp, EINA_TRUE); } @@ -1018,7 +1019,7 @@ eo_lexer_set_input(Eo_Lexer *ls, const char *source) Eina_File *f = eina_file_open(source, EINA_FALSE); if (!f) { - fprintf(stderr, "eolian: %s\n", strerror(errno)); + _eolian_log("%s", strerror(errno)); longjmp(ls->err_jmp, EINA_TRUE); } ls->lookahead.token = -1; @@ -1255,7 +1256,7 @@ eo_lexer_context_push(Eo_Lexer *ls) Lexer_Ctx *ctx = malloc(sizeof(Lexer_Ctx)); if (!ctx) { - fprintf(stderr, "eolian: out of memory pushing context\n"); + _eolian_log("out of memory pushing context"); longjmp(ls->err_jmp, EINA_TRUE); } ctx->line = ls->line_number; diff --git a/src/lib/eolian/eo_parser.c b/src/lib/eolian/eo_parser.c index e6d8b6bbb4..aa46dd95f1 100644 --- a/src/lib/eolian/eo_parser.c +++ b/src/lib/eolian/eo_parser.c @@ -5,6 +5,7 @@ #endif #include "eo_parser.h" +#include "eolian_priv.h" #define CASE_LOCK(ls, var, msg) \ if (has_##var) \ @@ -1118,10 +1119,10 @@ parse_accessor: { if (getenv("EOLIAN_PROPERTY_DOC_WARN")) { - fprintf(stderr, "eolian:%s:%d:%d: %s doc without property " - "doc for '%s.%s'\n", - prop->base.file, line, col, is_get ? "getter" : "setter", - ls->tmp.kls->full_name, prop->name); + _eolian_log_line(prop->base.file, line, col, + "%s doc without property doc for '%s.%s'", + is_get ? "getter" : "setter", + ls->tmp.kls->full_name, prop->name); } } if (is_get) @@ -2257,11 +2258,8 @@ _get_impl_class(const Eolian_Class *cl, const char *cln) return NULL; } -static void -_print_linecol(const Eolian_Object *base) -{ - fprintf(stderr, "eolian:%s:%d:%d: ", base->file, base->line, base->column); -} +#define _eo_parser_log(_base, ...) \ + _eolian_log_line((_base)->file, (_base)->line, (_base)->column, __VA_ARGS__) static Eina_Bool _db_fill_implement(Eolian_Class *cl, Eolian_Implement *impl) @@ -2290,9 +2288,8 @@ _db_fill_implement(Eolian_Class *cl, Eolian_Implement *impl) const Eolian_Class *tcl = _get_impl_class(cl, clname); if (!tcl) { - _print_linecol(&impl->base); - fprintf(stderr, "class '%s' not found within the inheritance tree of '%s'\n", - clname, cl->full_name); + _eo_parser_log(&impl->base, "class '%s' not found within the inheritance tree of '%s'", + clname, cl->full_name); return EINA_FALSE; } @@ -2301,8 +2298,7 @@ _db_fill_implement(Eolian_Class *cl, Eolian_Implement *impl) const Eolian_Function *fid = eolian_class_function_get_by_name(tcl, fnname, EOLIAN_UNRESOLVED); if (!fid) { - _print_linecol(&impl->base); - fprintf(stderr, "function '%s' not known in class '%s'\n", fnname, clname); + _eo_parser_log(&impl->base, "function '%s' not known in class '%s'", fnname, clname); return EINA_FALSE; } @@ -2316,8 +2312,7 @@ _db_fill_implement(Eolian_Class *cl, Eolian_Implement *impl) /* property */ if (aftype != EOLIAN_PROPERTY) { - _print_linecol(&impl->base); - fprintf(stderr, "function '%s' is not a complete property", fnname); + _eo_parser_log(&impl->base, "function '%s' is not a complete property", fnname); return EINA_FALSE; } auto_empty = auto_empty && (impl->set_auto || impl->set_empty); @@ -2327,8 +2322,7 @@ _db_fill_implement(Eolian_Class *cl, Eolian_Implement *impl) /* setter */ if ((aftype != EOLIAN_PROP_SET) && (aftype != EOLIAN_PROPERTY)) { - _print_linecol(&impl->base); - fprintf(stderr, "function '%s' doesn't have a setter\n", fnname); + _eo_parser_log(&impl->base, "function '%s' doesn't have a setter", fnname); return EINA_FALSE; } auto_empty = (impl->set_auto || impl->set_empty); @@ -2338,15 +2332,13 @@ _db_fill_implement(Eolian_Class *cl, Eolian_Implement *impl) /* getter */ if ((aftype != EOLIAN_PROP_GET) && (aftype != EOLIAN_PROPERTY)) { - _print_linecol(&impl->base); - fprintf(stderr, "function '%s' doesn't have a getter\n", fnname); + _eo_parser_log(&impl->base, "function '%s' doesn't have a getter", fnname); return EINA_FALSE; } } else if (aftype != EOLIAN_METHOD) { - _print_linecol(&impl->base); - fprintf(stderr, "function '%s' is not a method\n", fnname); + _eo_parser_log(&impl->base, "function '%s' is not a method", fnname); return EINA_FALSE; } @@ -2355,8 +2347,7 @@ _db_fill_implement(Eolian_Class *cl, Eolian_Implement *impl) /* only allow explicit implements from other classes, besides auto and * empty... also prevents pure virtuals from being implemented */ - _print_linecol(&impl->base); - fprintf(stderr, "invalid implement '%s'\n", impl->full_name); + _eo_parser_log(&impl->base, "invalid implement '%s'", impl->full_name); return EINA_FALSE; } @@ -2380,8 +2371,7 @@ _db_fill_implements(Eolian_Class *cl) Eina_Bool prop = (impl->is_prop_get || impl->is_prop_set); if (eina_hash_find(prop ? pth : th, impl->full_name)) { - _print_linecol(&impl->base); - fprintf(stderr, "duplicate implement '%s'\n", impl->full_name); + _eo_parser_log(&impl->base, "duplicate implement '%s'", impl->full_name); ret = EINA_FALSE; goto end; } @@ -2422,8 +2412,7 @@ _db_fill_ctors(Eolian_Class *cl) { if (eina_hash_find(th, ctor->full_name)) { - _print_linecol(&ctor->base); - fprintf(stderr, "duplicate ctor '%s'\n", ctor->full_name); + _eo_parser_log(&ctor->base, "duplicate ctor '%s'", ctor->full_name); ret = EINA_FALSE; goto end; } @@ -2439,9 +2428,8 @@ _db_fill_ctors(Eolian_Class *cl) const Eolian_Class *tcl = _get_impl_class(cl, cnbuf); if (!tcl) { - _print_linecol(&ctor->base); - fprintf(stderr, "class '%s' not found within the inheritance " - "tree of '%s'\n", cnbuf, cl->full_name); + _eo_parser_log(&ctor->base, "class '%s' not found within the inheritance tree of '%s'", + cnbuf, cl->full_name); ret = EINA_FALSE; goto end; } @@ -2449,8 +2437,7 @@ _db_fill_ctors(Eolian_Class *cl) const Eolian_Function *cfunc = eolian_constructor_function_get(ctor); if (!cfunc) { - _print_linecol(&ctor->base); - fprintf(stderr, "unable to find function '%s'\n", ctor->full_name); + _eo_parser_log(&ctor->base, "unable to find function '%s'", ctor->full_name); ret = EINA_FALSE; goto end; } @@ -2474,7 +2461,7 @@ eo_parser_database_fill(const char *filename, Eina_Bool eot) Eo_Lexer *ls = eo_lexer_new(filename); if (!ls) { - fprintf(stderr, "eolian: unable to create lexer for file '%s'\n", filename); + _eolian_log("unable to create lexer for file '%s'", filename); goto error; } @@ -2491,7 +2478,7 @@ eo_parser_database_fill(const char *filename, Eina_Bool eot) if (!(cl = ls->tmp.kls)) { - fprintf(stderr, "eolian: no class for file '%s'\n", filename); + _eolian_log("eolian: no class for file '%s'", filename); goto error; } ls->tmp.kls = NULL; diff --git a/src/lib/eolian/eolian_database.c b/src/lib/eolian/eolian_database.c index 4ba4b69f7d..eacc5b94fb 100644 --- a/src/lib/eolian/eolian_database.c +++ b/src/lib/eolian/eolian_database.c @@ -6,6 +6,7 @@ #include #include "eo_parser.h" #include "eolian_database.h" +#include "eolian_priv.h" Eina_Hash *_classes = NULL; Eina_Hash *_aliases = NULL; @@ -675,7 +676,7 @@ _eolian_file_parse_nodep(const char *filepath) is_eo = eina_str_has_suffix(filepath, EO_SUFFIX); if (!is_eo && !eina_str_has_suffix(filepath, EOT_SUFFIX)) { - fprintf(stderr, "eolian: file '%s' doesn't have a correct extension\n", filepath); + _eolian_log("file '%s' doesn't have a correct extension", filepath); return EINA_FALSE; } if (!(eopath = eina_hash_find(is_eo ? _filenames : _tfilenames, filepath))) diff --git a/src/lib/eolian/eolian_priv.h b/src/lib/eolian/eolian_priv.h new file mode 100644 index 0000000000..58c0f229ae --- /dev/null +++ b/src/lib/eolian/eolian_priv.h @@ -0,0 +1,60 @@ +#ifndef EOLIAN_PRIV_H +#define EOLIAN_PRIV_H + +#include +#include +#include + +static inline void _eolian_log_line(const char *file, int line, int column, const char *fmt, ...) EINA_ARG_NONNULL(1, 4) EINA_PRINTF(4, 5); +static inline void _eolian_log(const char *fmt, ...) EINA_ARG_NONNULL(1) EINA_PRINTF(1, 2); + +static inline void +_eolian_log_line(const char *file, int line, int column, const char *fmt, ...) +{ + Eina_Strbuf *sb = eina_strbuf_new(); + va_list args; + + va_start(args, fmt); + eina_strbuf_append_vprintf(sb, fmt, args); + va_end(args); + + if (!eina_log_color_disable_get()) + { + fprintf(stderr, EINA_COLOR_RED "eolian" EINA_COLOR_RESET ": " + EINA_COLOR_WHITE "%s" EINA_COLOR_RESET ":%d:%d: " + EINA_COLOR_ORANGE "%s\n" EINA_COLOR_RESET, + file, line, column, eina_strbuf_string_get(sb)); + } + else + { + fprintf(stderr, "eolian: %s:%d:%d: %s\n", file, line, column, + eina_strbuf_string_get(sb)); + } + eina_strbuf_free(sb); +} + +static inline void +_eolian_log(const char *fmt, ...) +{ + Eina_Strbuf *sb = eina_strbuf_new(); + va_list args; + + va_start(args, fmt); + eina_strbuf_append_vprintf(sb, fmt, args); + va_end(args); + + if (!eina_log_color_disable_get()) + { + fprintf(stderr, EINA_COLOR_RED "eolian" EINA_COLOR_RESET ": " + EINA_COLOR_ORANGE "%s\n" EINA_COLOR_RESET, + eina_strbuf_string_get(sb)); + } + else + { + fprintf(stderr, "eolian: %s\n", eina_strbuf_string_get(sb)); + } + eina_strbuf_free(sb); +} + +#endif +