Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Indent the rest of the code (examples, buildtools, doc...) except for examples/SMPI...
[simgrid.git] / tools / tesh2 / src / context.c
index 261d4b7..5db6bee 100644 (file)
-#include <context.h>
-
-
-XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh);
-
-#define INDEFINITE_SIGNAL      NULL
-
-context_t
-context_new(void)
+/*\r
+ * src/context.c - type representing the tesh file stream.\r
+ *\r
+ * Copyright 2008,2009 Martin Quinson, Malek Cherier All right reserved. \r
+ *\r
+ * This program is free software; you can redistribute it and/or modify it \r
+ * under the terms of the license (GNU LGPL) which comes with this package.\r
+ *\r
+ * Purpose:\r
+ *             This file contains all the definitions of the functions related with\r
+ *             the tesh context type.\r
+ *\r
+ */  \r
+    \r
+#include <context.h>\r
+    \r\rXBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh);
+\r\r
+#define INDEFINITE_SIGNAL      NULL\r
+    \rcontext_t \r context_new(void) \r
 {
-       context_t context = xbt_new0(s_context_t, 1);
-       
-       context->line = NULL;
-       context->command_line = NULL;
-       context->exit_code = 0;
-       context->timeout = INDEFINITE;
-       context->input = xbt_strbuff_new();
-       context->output = xbt_strbuff_new();
-       context->signal = INDEFINITE_SIGNAL;
-       context->output_handling = oh_check;
-       context->async = 0;
-       
-       return context;
-}
-
-context_t
-context_dup(context_t context)
+  \rcontext_t context = xbt_new0(s_context_t, 1);
+  \r\rcontext->line = NULL;
+  \rcontext->pos = NULL;
+  \rcontext->command_line = NULL;
+  \rcontext->exit_code = 0;
+  \rcontext->timeout = INDEFINITE;
+  \rcontext->input = xbt_strbuff_new();
+  \rcontext->output = xbt_strbuff_new();
+  \rcontext->signal = INDEFINITE_SIGNAL;
+  \rcontext->output_handling = oh_check;
+  \rcontext->async = 0;
+  \r\r
+#ifdef _XBT_WIN32\r
+      context->t_command_line = NULL;
+  \rcontext->is_not_found = 0;
+  \r
+#endif  /* \r */
+      \rreturn context;
+\r}
+
+\r\rint \r context_free(context_t * ptr) \r
 {
-       
-       context_t dup = xbt_new0(s_context_t, 1);
-       
-       dup->line = context->line;
-       dup->command_line = context->command_line;
-       dup->exit_code = context->exit_code;
-       dup->timeout = context->timeout;
-       dup->output = NULL;
-       dup->input = NULL;
-       dup->signal = NULL;
-       
-       if(context->input->used)
-       {
-               dup->input = xbt_strbuff_new();
-               xbt_strbuff_append(dup->input,context->input->data);
-       }
-
-       if(context->output->used)
-       {
-               dup->output = xbt_strbuff_new();
-               xbt_strbuff_append(dup->output,context->output->data);
-       }
-
-       if(context->signal)
-               dup->signal = strdup(context->signal);
-
-       dup->output_handling = context->output_handling;
-       
-       dup->async = context->async;
-       
-       return dup;
-}
-
-void
-context_clear(context_t context)
+  \rif (((*ptr)->input))
+    \rxbt_strbuff_free(((*ptr)->input));
+  \r\rif (((*ptr)->output))
+    \rxbt_strbuff_free(((*ptr)->output));
+  \r\rif ((*ptr)->command_line)
+    \rfree((*ptr)->command_line);
+  \r\rif ((*ptr)->pos)
+    \rfree((*ptr)->pos);
+  \r\rif ((*ptr)->signal)
+    \rfree((*ptr)->signal);
+  \r\r
+#ifdef _XBT_WIN32\r
+      if ((*ptr)->t_command_line)
+    \rfree((*ptr)->t_command_line);
+  \r
+#endif  /* \r */
+      \r*ptr = NULL;
+  \r\rreturn 0;
+\r}
+
+\r\rint \r context_reset(context_t context) \r
 {
-       context->line = NULL;
-       context->command_line = NULL;
-       context->exit_code = 0;
-       context->timeout = INDEFINITE;
-       
-       if(context->input)
-               xbt_strbuff_empty(context->input);
-
-       if(context->output)
-               xbt_strbuff_empty(context->output);
-       
-       if(context->signal)
-       {
-               free(context->signal);
-               context->signal = INDEFINITE_SIGNAL;
-       }
-
-       context->output_handling = oh_check;
-       context->async = 0;
-
-}
-
-void
-context_reset(context_t context)
+  \rcontext->line = NULL;
+  \rcontext->pos = NULL;
+  \r\rif (context->command_line)
+    \r {
+    \rfree(context->command_line);
+    \rcontext->command_line = NULL;
+    \r}
+  \r\r
+#ifdef _XBT_WIN32\r
+      if (context->t_command_line)
+    \r {
+    \rfree(context->t_command_line);
+    \rcontext->t_command_line = NULL;
+    \r}
+  \r\rcontext->is_not_found = 0;
+  \r\r
+#endif  /* \r */
+      \rif (context->pos)
+    \r {
+    \rfree(context->pos);
+    \rcontext->pos = NULL;
+    \r}
+  \r\rif (context->input)
+    \rxbt_strbuff_empty(context->input);
+  \r\rif (context->output)
+    \rxbt_strbuff_empty(context->output);
+  \r\rif (context->signal)
+    \r {
+    \rfree(context->signal);
+    \rcontext->signal = NULL;
+    \r}
+  \r\r
+      /* default expected exit code */ \r
+      context->exit_code = 0;
+  \r\rcontext->output_handling = oh_check;
+  \rcontext->async = 0;
+  \r\rreturn 0;
+\r\r}
+
+\r\rcontext_t \r context_dup(context_t context) \r
 {
-       context->line = NULL;
-       context->command_line = NULL;
-
-       if(context->input)
-               xbt_strbuff_empty(context->input);
-
-       if(context->output)
-               xbt_strbuff_empty(context->output);
-       
-       if(context->signal)
-       {
-               free(context->signal);
-               context->signal = NULL;
-       }
-       
-       /* default expected exit code */
-       context->exit_code = 0;
-
-       context->output_handling = oh_check;
-       context->async = 0;
-
-}
-
-void
-context_input_write(context_t context, const char* buffer)
+  \rcontext_t dup;
+  \r\rdup = xbt_new0(s_context_t, 1);
+  \r\rdup->line = context->line;
+  \rdup->pos = strdup(context->pos);
+  \rdup->command_line = strdup(context->command_line);
+  \r\r\r
+#ifdef _XBT_WIN32\r
+      dup->t_command_line = strdup(context->t_command_line);
+  \rdup->is_not_found = context->is_not_found;
+  \r
+#endif  /* \r */
+      \rdup->exit_code = context->exit_code;
+  \rdup->timeout = context->timeout;
+  \rdup->output = NULL;
+  \rdup->input = NULL;
+  \rdup->signal = NULL;
+  \r\rif (context->input->used)
+    \r {
+    \rdup->input = xbt_strbuff_new();
+    \rxbt_strbuff_append(dup->input, context->input->data);
+    \r}
+  \r\rdup->output = xbt_strbuff_new();
+  \r\rif (context->output->used)
+    \r {
+    \rxbt_strbuff_append(dup->output, context->output->data);
+    \r}
+  \r\rif (context->signal)
+    \r {
+    \rif (!(dup->signal = strdup(context->signal)))
+      \r {
+      \rfree(dup);
+      \rreturn NULL;
+      \r}
+    \r}
+  \r\rdup->output_handling = context->output_handling;
+  \r\rdup->async = context->async;
+  \r\rreturn dup;
+\r}
+
+\r\rvoid \r context_clear(context_t context) \r
 {
-       xbt_strbuff_append(context->input, buffer);
-}
-
-void
-context_ouput_read(context_t context, const char* buffer)
+  \rcontext->line = NULL;
+  \rcontext->pos = NULL;
+  \r\rif (context->command_line)
+    \r {
+    \rfree(context->command_line);
+    \rcontext->command_line = NULL;
+    \r}
+  \r\r
+#ifdef _XBT_WIN32\r
+      if (context->t_command_line)
+    \r {
+    \rfree(context->t_command_line);
+    \rcontext->t_command_line = NULL;
+    \r}
+  \rcontext->is_not_found = 0;
+  \r\r
+#endif  /* \r */
+      \rif (context->pos)
+    \r {
+    \rfree(context->pos);
+    \rcontext->pos = NULL;
+    \r}
+  \r\rcontext->exit_code = 0;
+  \rcontext->timeout = INDEFINITE;
+  \r\rif (context->input)
+    \rxbt_strbuff_empty(context->input);
+  \r\rif (context->output)
+    \rxbt_strbuff_empty(context->output);
+  \r\rif (context->signal)
+    \r {
+    \rfree(context->signal);
+    \rcontext->signal = INDEFINITE_SIGNAL;
+    \r}
+  \r\rcontext->output_handling = oh_check;
+  \rcontext->async = 0;
+\r\r}
+
+\r\rvoid \r context_input_write(context_t context, const char *buffer) \r
 {
-       xbt_strbuff_append(context->output, buffer);
-}
-
-void
-context_free(context_t* context)
+  \rxbt_strbuff_append(context->input, buffer);
+\r\r\rvoid \r context_ouput_read(context_t context, const char *buffer) \r
 {
-       if(((*context)->input))
-               xbt_strbuff_free(((*context)->input));
-
-       if(((*context)->output))
-               xbt_strbuff_free(((*context)->output));
-       
-       if((*context)->signal)
-               free((*context)->signal);
-
-       *context = NULL;
-}
-
+  \rxbt_strbuff_append(context->output, buffer);
+\r\r\r\r\r