X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/610eb721db6930318d297090f8b931b56a675e21..a7430c3a3c007a1746ac3d8ff320058a66e70b64:/src/surf/surfxml_parse.c diff --git a/src/surf/surfxml_parse.c b/src/surf/surfxml_parse.c index 0187aa5180..aee71a9f7b 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" @@ -18,18 +20,32 @@ int ETag_surfxml_include_state(void); #include "simgrid_dtd.c" +char* surf_parsed_filename = NULL; // to locate parse error messages + /* * Helping functions */ -void surf_parse_error(const char *msg) { - xbt_die("Parse error on line %d: %s\n", 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) { double res; int ret = sscanf(string, "%lg", &res); if (ret != 1) - surf_parse_error(bprintf("%s is not a double", string)); + surf_parse_error("%s is not a double", string); return res; } @@ -37,7 +53,7 @@ int surf_parse_get_int(const char *string) { int res; int ret = sscanf(string, "%d", &res); if (ret != 1) - surf_parse_error(bprintf("%s is not an integer", string)); + surf_parse_error("%s is not an integer", string); return res; } @@ -90,21 +106,25 @@ static void add_randomness(void); /* * Stuff relative to the tag */ - static xbt_dynar_t surf_input_buffer_stack = NULL; static xbt_dynar_t surf_file_to_parse_stack = NULL; +static xbt_dynar_t surf_parsed_filename_stack = NULL; void STag_surfxml_include(void) { XBT_INFO("STag_surfxml_include '%s'",A_surfxml_include_file); - xbt_dynar_push(surf_file_to_parse_stack, &surf_file_to_parse); //save old filename + xbt_dynar_push(surf_parsed_filename_stack,&surf_parsed_filename); // save old file name + surf_parsed_filename = xbt_strdup(A_surfxml_include_file); - surf_file_to_parse = surf_fopen(A_surfxml_include_file, "r"); // read new filename + xbt_dynar_push(surf_file_to_parse_stack, &surf_file_to_parse); //save old file descriptor + + surf_file_to_parse = surf_fopen(A_surfxml_include_file, "r"); // read new file descriptor xbt_assert((surf_file_to_parse), "Unable to open \"%s\"\n", A_surfxml_include_file); xbt_dynar_push(surf_input_buffer_stack,&surf_input_buffer); surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE); surf_parse_push_buffer_state(surf_input_buffer); + fflush(NULL); } @@ -122,18 +142,26 @@ void ETag_surfxml_include(void) { * * Yeah, that's terribly hackish, but it works. A better solution should be dealed with in flexml * directly: a command line flag could instruct it to do the correct thing when #include is encountered - * on a line. + * on a line. One day maybe, if the maya allow it. */ int ETag_surfxml_include_state(void) { fflush(NULL); XBT_INFO("ETag_surfxml_include_state '%s'",A_surfxml_include_file); - if(!xbt_dynar_is_empty(surf_input_buffer_stack)) + + if(!xbt_dynar_is_empty(surf_input_buffer_stack)) // nope, that's a true premature EOF. Let the parser die verbosely. return 1; + + // Yeah, we were in an Restore state and proceed. fclose(surf_file_to_parse); xbt_dynar_pop(surf_file_to_parse_stack, &surf_file_to_parse); surf_parse_pop_buffer_state(); xbt_dynar_pop(surf_input_buffer_stack,surf_input_buffer); + + // Restore the filename for error messages + free(surf_parsed_filename); + xbt_dynar_pop(surf_parsed_filename_stack,&surf_parsed_filename); + return 0; } @@ -318,9 +346,8 @@ void STag_surfxml_cluster(void){ cluster.sharing_policy = SURF_LINK_FATPIPE; break; default: - surf_parse_error(bprintf - ("Invalid cluster sharing policy for cluster %s", - cluster.id)); + surf_parse_error("Invalid cluster sharing policy for cluster %s", + cluster.id); break; } switch (AX_surfxml_cluster_bb_sharing_policy) { @@ -331,9 +358,8 @@ void STag_surfxml_cluster(void){ cluster.bb_sharing_policy = SURF_LINK_SHARED; break; default: - surf_parse_error(bprintf - ("Invalid bb sharing policy in cluster %s", - cluster.id)); + surf_parse_error("Invalid bb sharing policy in cluster %s", + cluster.id); break; } @@ -386,7 +412,7 @@ void ETag_surfxml_link(void){ link.state = SURF_RESOURCE_OFF; break; default: - surf_parse_error(bprintf("invalid state for link %s",link.id)); + surf_parse_error("invalid state for link %s", link.id); break; } link.state_trace = tmgr_trace_new(A_surfxml_link_state_file); @@ -402,7 +428,7 @@ void ETag_surfxml_link(void){ link.policy = SURF_LINK_FULLDUPLEX; break; default: - surf_parse_error(bprintf("Invalid sharing policy in link %s",link.id)); + surf_parse_error("Invalid sharing policy in link %s", link.id); break; } @@ -502,6 +528,10 @@ void surf_parse_open(const char *file) if (!surf_file_to_parse_stack) surf_file_to_parse_stack = xbt_dynar_new(sizeof(FILE *), NULL); + if (!surf_file_to_parse_stack) + surf_parsed_filename_stack = xbt_dynar_new(sizeof(FILE *), xbt_free_f); + surf_parsed_filename = xbt_strdup(file); + surf_file_to_parse = surf_fopen(file, "r"); xbt_assert((surf_file_to_parse), "Unable to open \"%s\"\n", file); surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE); @@ -513,6 +543,9 @@ void surf_parse_close(void) { xbt_dynar_free(&surf_input_buffer_stack); xbt_dynar_free(&surf_file_to_parse_stack); + xbt_dynar_free(&surf_parsed_filename_stack); + + free(surf_parsed_filename); if (surf_file_to_parse) { surf_parse__delete_buffer(surf_input_buffer); @@ -605,8 +638,8 @@ double get_cpu_power(const char *power) return power_scale; } -double random_min, random_max, random_mean, random_std_deviation, - random_generator; +double random_min, random_max, random_mean, random_std_deviation; +e_random_generator_t random_generator; char *random_id; static void init_randomness(void) @@ -616,7 +649,24 @@ static void init_randomness(void) random_max = surf_parse_get_double(A_surfxml_random_max); random_mean = surf_parse_get_double(A_surfxml_random_mean); random_std_deviation = surf_parse_get_double(A_surfxml_random_std_deviation); - random_generator = A_surfxml_random_generator; + switch (A_surfxml_random_generator) { + case AU_surfxml_random_generator: + case A_surfxml_random_generator_NONE: + random_generator = NONE; + break; + case A_surfxml_random_generator_DRAND48: + random_generator = DRAND48; + break; + case A_surfxml_random_generator_RAND: + random_generator = RAND; + break; + case A_surfxml_random_generator_RNGSTREAM: + random_generator = RNGSTREAM; + break; + default: + surf_parse_error("Invalid random generator"); + break; + } } static void add_randomness(void)