+++ /dev/null
-/*\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
-{
- \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
-{
- \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
-{
- \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
-{
- \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
-{
- \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
-{
- \rxbt_strbuff_append(context->input, buffer);
-\r} \r\rvoid \r context_ouput_read(context_t context, const char *buffer) \r
-{
- \rxbt_strbuff_append(context->output, buffer);
-\r} \r\r\r\r