From 83c1f3bcb7ec8d6219ce4af96b06ac35a172a7ba Mon Sep 17 00:00:00 2001 From: alegrand Date: Thu, 2 Dec 2004 22:00:17 +0000 Subject: [PATCH 1/1] Publishing some internal parsing function. git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@538 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- src/include/surf/surf_parse.h | 4 +++ src/surf/cpu.c | 53 +++++++---------------------------- src/surf/surf_parse.l | 41 +++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 43 deletions(-) diff --git a/src/include/surf/surf_parse.h b/src/include/surf/surf_parse.h index 547ab6a55d..02ea0ae942 100644 --- a/src/include/surf/surf_parse.h +++ b/src/include/surf/surf_parse.h @@ -26,6 +26,10 @@ extern int char_pos; extern int tok_num; e_surf_token_t surf_parse(void); +void find_section(const char* file, const char* section_name); +void close_section(const char* section_name); + +/* Should not be called if you use the previous "section" functions */ void surf_parse_open(const char *file); void surf_parse_close(void); diff --git a/src/surf/cpu.c b/src/surf/cpu.c index 3e34704648..83dd5bc370 100644 --- a/src/surf/cpu.c +++ b/src/surf/cpu.c @@ -54,45 +54,6 @@ static void *cpu_new(const char *name, xbt_maxmin_float_t power_scale, return cpu; } -static void find_section(const char* file, const char* section_name) -{ - e_surf_token_t token; - int found = 0; - - surf_parse_open(file); - - while((token=surf_parse())) { - if(token!=TOKEN_BEGIN_SECTION) continue; - - token=surf_parse(); - xbt_assert1((token==TOKEN_WORD),"Parse error line %d",line_pos); - if(strcmp(surf_parse_text,section_name)==0) found=1; - - token=surf_parse(); - xbt_assert1((token==TOKEN_CLOSURE),"Parse error line %d",line_pos); - - if(found) return; - } - - CRITICAL2("Could not find %s section in %s\n",section_name,file); -} - -static void close_section(const char* section_name) -{ - e_surf_token_t token; - - token=surf_parse(); - xbt_assert1((token==TOKEN_WORD),"Parse error line %d",line_pos); - xbt_assert1((strcmp(surf_parse_text,"CPU")==0), - "Closing section does not match the opening one (%s).", - section_name); - - token=surf_parse(); - xbt_assert1((token==TOKEN_CLOSURE),"Parse error line %d",line_pos); - - surf_parse_close(); -} - /* Semantic: name scale initial power initial state power trace state trace @@ -132,8 +93,11 @@ static void parse_host(void) xbt_assert1((token==TOKEN_WORD),"Parse error line %d",line_pos); if(strcmp(surf_parse_text,"ON")==0) initial_state = SURF_CPU_ON; else if(strcmp(surf_parse_text,"OFF")==0) initial_state = SURF_CPU_OFF; - else CRITICAL2("Invalid cpu state (line %d): %s neq ON or OFF\n",line_pos, - surf_parse_text); + else { + CRITICAL2("Invalid cpu state (line %d): %s neq ON or OFF\n",line_pos, + surf_parse_text); + xbt_abort(); + } token=surf_parse(); /* state_trace */ xbt_assert1((token==TOKEN_WORD),"Parse error line %d",line_pos); @@ -156,7 +120,10 @@ static void parse_file(const char *file) if(token==TOKEN_NEWLINE) continue; if(token==TOKEN_WORD) parse_host(); - else CRITICAL1("Parse error line %d\n",line_pos); + else { + CRITICAL1("Parse error line %d\n",line_pos); + xbt_abort(); + } } close_section("CPU"); @@ -281,7 +248,7 @@ static void update_resource_state(void *id, } else if (event_type==cpu->state_event) { if(value>0) cpu->current_state = SURF_CPU_ON; else cpu->current_state = SURF_CPU_OFF; - } else abort(); + } else {CRITICAL0("Unknown event ! \n");xbt_abort();} return; } diff --git a/src/surf/surf_parse.l b/src/surf/surf_parse.l index 0d1005435c..39fd337953 100644 --- a/src/surf/surf_parse.l +++ b/src/surf/surf_parse.l @@ -140,6 +140,46 @@ e_surf_token_t surf_parse(void) { return(tok_num); } +void find_section(const char* file, const char* section_name) +{ + e_surf_token_t token; + int found = 0; + + surf_parse_open(file); + + while((token=surf_parse())) { + if(token!=TOKEN_BEGIN_SECTION) continue; + + token=surf_parse(); + xbt_assert1((token==TOKEN_WORD),"Parse error line %d",line_pos); + if(strcmp(surf_parse_text,section_name)==0) found=1; + + token=surf_parse(); + xbt_assert1((token==TOKEN_CLOSURE),"Parse error line %d",line_pos); + + if(found) return; + } + + CRITICAL2("Could not find %s section in %s\n",section_name,file); + xbt_abort(); +} + +void close_section(const char* section_name) +{ + e_surf_token_t token; + + token=surf_parse(); + xbt_assert1((token==TOKEN_WORD),"Parse error line %d",line_pos); + xbt_assert1((strcmp(surf_parse_text,section_name)==0), + "Closing section does not match the opening one (%s).", + section_name); + + token=surf_parse(); + xbt_assert1((token==TOKEN_CLOSURE),"Parse error line %d",line_pos); + + surf_parse_close(); +} + void surf_parse_open(const char *file) { file_to_parse = fopen(file,"r"); xbt_assert1((file_to_parse), "Unable to open \"%s\"\n",file) @@ -160,6 +200,7 @@ void surf_parse_close(void) { tok_num = 0; } + /* Local variables: */ /* mode: c */ /* End: */ -- 2.20.1