X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/ec5e183d26c5427920071f551e4081c1fe54db35..a95ea5c578ac402346f202c411986425fb1fcf8b:/tools/tesh/tesh.c diff --git a/tools/tesh/tesh.c b/tools/tesh/tesh.c index 959362bc2c..9fcee3e11a 100644 --- a/tools/tesh/tesh.c +++ b/tools/tesh/tesh.c @@ -32,53 +32,53 @@ static void handle_line(const char * filepos, char *line) { rctx->input->used, rctx->input->data, rctx->output_wanted->used,rctx->output_wanted->data, rctx->output_got->used, rctx->output_got->data); - */ + */ DEBUG2("[%s] %s",filepos,line); switch (line[0]) { - case '#': break; - - case '$': - /* further trim useless chars which are significant for in/output */ - xbt_str_rtrim(line+2," \t"); + case '#': break; + + case '$': + /* further trim useless chars which are significant for in/output */ + xbt_str_rtrim(line+2," \t"); + + /* Deal with CD commands here, not in rctx */ + if (!strncmp("cd ",line+2,3)) { + char *dir=line+4; + + if (rctx->cmd) + rctx_start(); + + /* search beginning */ + while (*(dir++) == ' '); + dir--; + VERB1("Saw cd '%s'",dir); + if (chdir(dir)) { + ERROR2("Chdir to %s failed: %s",dir,strerror(errno)); + ERROR1("Test suite `%s': NOK (system error)", testsuite_name); + rctx_armageddon(rctx,4); + } + break; + } /* else, pushline */ + case '&': + case '<': + case '>': + case '!': + rctx_pushline(filepos, line[0], line+2 /* pass '$ ' stuff*/); + break; - /* Deal with CD commands here, not in rctx */ - if (!strncmp("cd ",line+2,3)) { - char *dir=line+4; + case 'p': + INFO2("[%s] %s",filepos,line+2); + break; + case 'P': + CRITICAL2("[%s] %s",filepos,line+2); + break; - if (rctx->cmd) - rctx_start(); - - /* search begining */ - while (*(dir++) == ' '); - dir--; - VERB1("Saw cd '%s'",dir); - if (chdir(dir)) { - ERROR2("Chdir to %s failed: %s",dir,strerror(errno)); - ERROR1("Test suite `%s': NOK (system error)", testsuite_name); - rctx_armageddon(rctx,4); - } + default: + ERROR2("[%s] Syntax error: %s",filepos, line); + ERROR1("Test suite `%s': NOK (syntax error)",testsuite_name); + rctx_armageddon(rctx,1); break; - } /* else, pushline */ - case '&': - case '<': - case '>': - case '!': - rctx_pushline(filepos, line[0], line+2 /* pass '$ ' stuff*/); - break; - - case 'p': - INFO2("[%s] %s",filepos,line+2); - break; - case 'P': - CRITICAL2("[%s] %s",filepos,line+2); - break; - - default: - ERROR2("[%s] Syntax error: %s",filepos, line); - ERROR1("Test suite `%s': NOK (syntax error)",testsuite_name); - rctx_armageddon(rctx,1); - break; } } @@ -101,19 +101,19 @@ static void handle_suite(const char* filename, FILE* IN) { int linelen = 0; while (line[linelen] != '\0') { if (line[linelen] != ' ' && line[linelen] != '\t' && line[linelen]!='\n') - blankline = 0; + blankline = 0; linelen++; } if (blankline) { if (!rctx->cmd && !rctx->is_empty) { - ERROR1("[%d] Error: no command found in this chunk of lines.", - buffbegin); - ERROR1("Test suite `%s': NOK (syntax error)",testsuite_name); - rctx_armageddon(rctx,1); + ERROR1("[%d] Error: no command found in this chunk of lines.", + buffbegin); + ERROR1("Test suite `%s': NOK (syntax error)",testsuite_name); + rctx_armageddon(rctx,1); } if (rctx->cmd) - rctx_start(); + rctx_start(); continue; } @@ -122,15 +122,15 @@ static void handle_suite(const char* filename, FILE* IN) { int to_be_continued = 0; if (linelen>1 && line[linelen-2]=='\\') { if (linelen>2 && line[linelen-3] == '\\') { - /* Damn. Escaped \ */ - line[linelen-2] = '\n'; - line[linelen-1] = '\0'; + /* Damn. Escaped \ */ + line[linelen-2] = '\n'; + line[linelen-1] = '\0'; } else { - to_be_continued = 1; - line[linelen-2] = '\0'; - linelen -= 2; - if (!buff->used) - buffbegin = line_num; + to_be_continued = 1; + line[linelen-2] = '\0'; + linelen -= 2; + if (!buff->used) + buffbegin = line_num; } } @@ -138,9 +138,9 @@ static void handle_suite(const char* filename, FILE* IN) { xbt_strbuff_append(buff,line); if (!to_be_continued) { - snprintf(file_pos,256,"%s:%d",filename,buffbegin); - handle_line(file_pos, buff->data); - xbt_strbuff_empty(buff); + snprintf(file_pos,256,"%s:%d",filename,buffbegin); + handle_line(file_pos, buff->data); + xbt_strbuff_empty(buff); } } else { @@ -163,6 +163,19 @@ static void handle_suite(const char* filename, FILE* IN) { } +static void parse_environ(){ + char *p; + int i; + env = xbt_dict_new(); + for (i=0; environ[i];i++) { + p=environ[i]; + char *eq = strchr(p,'='); + char *key = bprintf("%.*s",(int)(eq-p),p); + xbt_dict_set(env,key,xbt_strdup(eq+1),xbt_free_f); + free(key); + } +} + int main(int argc,char *argv[]) { FILE *IN; @@ -177,6 +190,7 @@ int main(int argc,char *argv[]) { xbt_init(&argc,argv); rctx_init(); + parse_environ(); /* Find the description file */ if (argc == 1) { @@ -191,19 +205,19 @@ int main(int argc,char *argv[]) { for (i=1; i