Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Last corrections of Tesh tool.
[simgrid.git] / tools / tesh2 / src / context.c
index 4f98e10..22a44fc 100644 (file)
@@ -25,6 +25,7 @@ context_new(void)
        context_t context = xbt_new0(s_context_t,1);\r
        \r
        context->line = NULL;\r
+       context->pos = NULL;\r
        context->command_line = NULL;\r
        context->exit_code = 0;\r
        context->timeout = INDEFINITE;\r
@@ -40,13 +41,18 @@ context_new(void)
 int\r
 context_free(context_t* ptr)\r
 {\r
-       /* TODO : check the parameter */\r
        if(((*ptr)->input))\r
                xbt_strbuff_free(((*ptr)->input));\r
 \r
        if(((*ptr)->output))\r
                xbt_strbuff_free(((*ptr)->output));\r
        \r
+       if((*ptr)->command_line)\r
+               free((*ptr)->command_line);\r
+\r
+       if((*ptr)->pos)\r
+               free((*ptr)->pos);\r
+\r
        if((*ptr)->signal)\r
                free((*ptr)->signal);\r
 \r
@@ -58,11 +64,20 @@ context_free(context_t* ptr)
 int\r
 context_reset(context_t context)\r
 {\r
-       \r
-       /* TODO : check the parameter */\r
-       \r
        context->line = NULL;\r
-       context->command_line = NULL;\r
+       context->pos = NULL;\r
+\r
+       if(context->command_line)\r
+       {\r
+               free(context->command_line);\r
+               context->command_line = NULL;\r
+       }\r
+\r
+       if(context->pos)\r
+       {\r
+               free(context->pos);\r
+               context->pos = NULL;\r
+       }\r
 \r
        if(context->input)\r
                xbt_strbuff_empty(context->input);\r
@@ -89,15 +104,13 @@ context_reset(context_t context)
 context_t\r
 context_dup(context_t context)\r
 {\r
-       \r
        context_t dup;\r
        \r
-       /* TODO : check the parameter */\r
-       \r
        dup = xbt_new0(s_context_t, 1);\r
        \r
        dup->line = context->line;\r
-       dup->command_line = context->command_line;\r
+       dup->pos = strdup(context->pos);\r
+       dup->command_line = strdup(context->command_line);\r
        dup->exit_code = context->exit_code;\r
        dup->timeout = context->timeout;\r
        dup->output = NULL;\r
@@ -109,10 +122,11 @@ context_dup(context_t context)
                dup->input = xbt_strbuff_new();\r
                xbt_strbuff_append(dup->input,context->input->data);\r
        }\r
+       \r
+       dup->output = xbt_strbuff_new();\r
 \r
        if(context->output->used)\r
        {\r
-               dup->output = xbt_strbuff_new();\r
                xbt_strbuff_append(dup->output,context->output->data);\r
        }\r
 \r
@@ -136,7 +150,20 @@ void
 context_clear(context_t context)\r
 {\r
        context->line = NULL;\r
-       context->command_line = NULL;\r
+       context->pos = NULL;\r
+       \r
+       if(context->command_line)\r
+       {\r
+               free(context->command_line);\r
+               context->command_line = NULL;\r
+       }\r
+\r
+       if(context->pos)\r
+       {\r
+               free(context->pos);\r
+               context->pos = NULL;\r
+       }\r
+\r
        context->exit_code = 0;\r
        context->timeout = INDEFINITE;\r
        \r