From: Martin Quinson Date: Fri, 3 Feb 2012 14:37:53 +0000 (+0100) Subject: add a surf_parse_warn and get surf_parse_error() accepting variable amount of parameters X-Git-Tag: exp_20120216~70 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/5110a2c2672cde3c914ed45462633dfff7026820 add a surf_parse_warn and get surf_parse_error() accepting variable amount of parameters --- diff --git a/include/surf/surfxml_parse.h b/include/surf/surfxml_parse.h index 721db6e027..cc8936de24 100644 --- a/include/surf/surfxml_parse.h +++ b/include/surf/surfxml_parse.h @@ -45,7 +45,8 @@ XBT_PUBLIC(void) surf_parse_close(void); XBT_PUBLIC(void) surf_parse_init_callbacks(void); XBT_PUBLIC(void) surf_parse_reset_callbacks(void); XBT_PUBLIC(void) surf_parse_free_callbacks(void); -XBT_PUBLIC(void) surf_parse_error(const char *msg) _XBT_GNUC_NORETURN; +XBT_PUBLIC(void) surf_parse_error(const char *msg,...) _XBT_GNUC_PRINTF(1,2) _XBT_GNUC_NORETURN; +XBT_PUBLIC(void) surf_parse_warn(const char *msg,...) _XBT_GNUC_PRINTF(1,2); XBT_PUBLIC(double) surf_parse_get_double(const char *string); XBT_PUBLIC(int) surf_parse_get_int(const char *string); /* Prototypes of the functions offered by flex */ diff --git a/src/surf/surfxml_parse.c b/src/surf/surfxml_parse.c index bad20fbb21..ab0282afe0 100644 --- a/src/surf/surfxml_parse.c +++ b/src/surf/surfxml_parse.c @@ -4,6 +4,8 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ +#include /* va_arg */ + #include "xbt/misc.h" #include "xbt/log.h" #include "xbt/str.h" @@ -23,8 +25,20 @@ char* surf_parsed_filename = NULL; // to locate parse error messages /* * Helping functions */ -void surf_parse_error(const char *msg) { - xbt_die("Parse error at %s:%d: %s\n", surf_parsed_filename, surf_parse_lineno, msg); +void surf_parse_error(const char *fmt, ...) { + va_list va; + va_start(va,fmt); + char *msg = bvprintf(fmt,va); + va_end(va); + xbt_die("Parse error at %s:%d: %s", surf_parsed_filename, surf_parse_lineno, msg); +} +void surf_parse_warn(const char *fmt, ...) { + va_list va; + va_start(va,fmt); + char *msg = bvprintf(fmt,va); + va_end(va); + XBT_WARN("%s:%d: %s", surf_parsed_filename, surf_parse_lineno, msg); + free(msg); } double surf_parse_get_double(const char *string) {