X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/f783ed4680c6862a1b7543237e89d1221334bae0..830b5c4bc694ade087c43f39015faa9065795630:/tools/tesh/tesh.c?ds=sidebyside diff --git a/tools/tesh/tesh.c b/tools/tesh/tesh.c index b4659fcf0a..ae83f641ff 100644 --- a/tools/tesh/tesh.c +++ b/tools/tesh/tesh.c @@ -22,7 +22,7 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(tesh, "TEst SHell utility"); int timeout_value = 5; /* child timeout value */ int sort_len = 19; /* length of the prefix to sort */ char *option; -int coverage = 0; /* whether the code coverage is enable */ +int coverage = 0; /* whether the code coverage is enable */ rctx_t rctx; const char *testsuite_name; @@ -172,8 +172,7 @@ static void handle_suite(const char *filename, FILE * IN) rctx_free(rctx); /* Clear buffers */ - if (line) - free(line); + free(line); xbt_strbuff_free(buff); } @@ -184,12 +183,12 @@ static void parse_environ() int i; char *eq = NULL; char *key = NULL; - env = xbt_dict_new(); + env = xbt_dict_new_homogeneous(xbt_free_f); for (i = 0; environ[i]; i++) { p = environ[i]; eq = strchr(p, '='); key = bprintf("%.*s", (int) (eq - p), p); - xbt_dict_set(env, key, xbt_strdup(eq + 1), xbt_free_f); + xbt_dict_set(env, key, xbt_strdup(eq + 1), NULL); free(key); } } @@ -200,6 +199,8 @@ int main(int argc, char *argv[]) int i; char *suitename = NULL; struct sigaction newact; + + XBT_LOG_CONNECT(tesh); xbt_init(&argc, argv); rctx_init(); parse_environ(); @@ -235,7 +236,7 @@ int main(int argc, char *argv[]) char *eq = strchr(argv[i+1], '='); xbt_assert(eq,"The argument of --setenv must contain a '=' (got %s instead)",argv[i+1]); char *key = bprintf("%.*s", (int) (eq - argv[i+1]), argv[i+1]); - xbt_dict_set(env, key, xbt_strdup(eq + 1), xbt_free_f); + xbt_dict_set(env, key, xbt_strdup(eq + 1), NULL); XBT_INFO("setting environment variable '%s' to '%s'", key, eq+1); free(key); memmove(argv + i, argv + i + 2, (argc - i - 1) * sizeof(char *)); @@ -246,10 +247,12 @@ int main(int argc, char *argv[]) XBT_ERROR("--cfg argument requires an argument"); exit(1); } - if(!option){ //if option is NULL - option = bprintf("--cfg=%s",argv[i+1]); - }else{ - option = bprintf("%s --cfg=%s",option,argv[i+1]); + if (!option){ //if option is NULL + option = bprintf("--cfg=%s",argv[i+1]); + } else { + char *newoption = bprintf("%s --cfg=%s", option, argv[i+1]); + free(option); + option = newoption; } XBT_INFO("Add option \'--cfg=%s\' to command line",argv[i+1]); memmove(argv + i, argv + i + 2, (argc - i - 1) * sizeof(char *)); @@ -257,11 +260,11 @@ int main(int argc, char *argv[]) i -= 2; } else if (!strcmp(argv[i], "--enable-coverage" )){ - coverage = 1; - XBT_INFO("Enable coverage"); - memmove(argv + i, argv + i + 1, (argc - i - 1) * sizeof(char *)); - argc -= 1; - i -= 1; + coverage = 1; + XBT_INFO("Enable coverage"); + memmove(argv + i, argv + i + 1, (argc - i - 1) * sizeof(char *)); + argc -= 1; + i -= 1; } } @@ -301,6 +304,6 @@ int main(int argc, char *argv[]) rctx_exit(); xbt_dict_free(&env); - xbt_free_f(option); + free(option); return 0; }