Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Added a jitter functionallity to GTNets model, latency is increased by a random numbe...
[simgrid.git] / tools / tesh2 / src / context.c
index 4f98e10..3ddd1b2 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
@@ -33,6 +34,11 @@ context_new(void)
        context->signal = INDEFINITE_SIGNAL;\r
        context->output_handling = oh_check;\r
        context->async = 0;\r
+\r
+       #ifdef WIN32\r
+       context->t_command_line = NULL;\r
+       context->is_not_found = 0;\r
+       #endif\r
        \r
        return context;\r
 }\r
@@ -40,16 +46,26 @@ 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
+       #ifdef WIN32\r
+       if((*ptr)->t_command_line)\r
+               free((*ptr)->t_command_line);\r
+       #endif\r
+\r
        *ptr = NULL;\r
        \r
        return 0;\r
@@ -58,11 +74,31 @@ 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
+       #ifdef WIN32\r
+       if(context->t_command_line)\r
+       {\r
+               free(context->t_command_line);\r
+               context->t_command_line = NULL;\r
+       }\r
+\r
+       context->is_not_found = 0;\r
+\r
+       #endif\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 +125,20 @@ 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
+\r
+       \r
+       #ifdef WIN32\r
+       dup->t_command_line = strdup(context->t_command_line);\r
+       dup->is_not_found = context->is_not_found;\r
+       #endif\r
+\r
        dup->exit_code = context->exit_code;\r
        dup->timeout = context->timeout;\r
        dup->output = NULL;\r
@@ -109,10 +150,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 +178,30 @@ 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
+       #ifdef WIN32\r
+       if(context->t_command_line)\r
+       {\r
+               free(context->t_command_line);\r
+               context->t_command_line = NULL;\r
+       }\r
+       context->is_not_found = 0;\r
+\r
+       #endif\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