parser-helper: Make parser_helper_log a function
This commit is contained in:
@@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
#include "parser_helper.h"
|
#include "parser_helper.h"
|
||||||
|
|
||||||
@@ -196,6 +197,32 @@ METHOD(parser_helper_t, destroy, void,
|
|||||||
free(this);
|
free(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Described in header
|
||||||
|
*/
|
||||||
|
void parser_helper_log(int level, parser_helper_t *ctx, char *fmt, ...)
|
||||||
|
{
|
||||||
|
parser_helper_file_t *file;
|
||||||
|
char msg[8192];
|
||||||
|
va_list args;
|
||||||
|
int line;
|
||||||
|
|
||||||
|
va_start(args, fmt);
|
||||||
|
vsnprintf(msg, sizeof(msg), fmt, args);
|
||||||
|
va_end(args);
|
||||||
|
|
||||||
|
file = ctx->file_current(ctx);
|
||||||
|
line = ctx->get_lineno ? ctx->get_lineno(ctx->scanner) : 0;
|
||||||
|
if (file)
|
||||||
|
{
|
||||||
|
dbg(DBG_CFG, level, "%s:%d: %s", file->name, line, msg);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dbg(DBG_CFG, level, "%s", msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Described in header
|
* Described in header
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -148,15 +148,7 @@ struct parser_helper_file_t {
|
|||||||
* @param fmt error message format
|
* @param fmt error message format
|
||||||
* @param ... additional arguments
|
* @param ... additional arguments
|
||||||
*/
|
*/
|
||||||
#define parser_helper_log(level, ctx, fmt, ...) ({ \
|
void parser_helper_log(int level, parser_helper_t *ctx, char *fmt, ...);
|
||||||
parser_helper_file_t *_file = (ctx)->file_current(ctx); \
|
|
||||||
int _line = (ctx)->get_lineno ? (ctx)->get_lineno((ctx)->scanner) : 0; \
|
|
||||||
if (_file) {\
|
|
||||||
DBG##level(DBG_CFG, "%s:%d: " fmt, _file->name, _line, ##__VA_ARGS__); \
|
|
||||||
} else { \
|
|
||||||
DBG##level(DBG_CFG, fmt, ##__VA_ARGS__); \
|
|
||||||
} \
|
|
||||||
})
|
|
||||||
|
|
||||||
#define PARSER_DBG1(ctx, fmt, ...) parser_helper_log(1, ctx, fmt, ##__VA_ARGS__)
|
#define PARSER_DBG1(ctx, fmt, ...) parser_helper_log(1, ctx, fmt, ##__VA_ARGS__)
|
||||||
#define PARSER_DBG2(ctx, fmt, ...) parser_helper_log(2, ctx, fmt, ##__VA_ARGS__)
|
#define PARSER_DBG2(ctx, fmt, ...) parser_helper_log(2, ctx, fmt, ##__VA_ARGS__)
|
||||||
|
|||||||
Reference in New Issue
Block a user