2 * src/context.c - type representing the tesh file stream.
\r
4 * Copyright 2008,2009 Martin Quinson, Malek Cherier All right reserved.
\r
6 * This program is free software; you can redistribute it and/or modify it
\r
7 * under the terms of the license (GNU LGPL) which comes with this package.
\r
10 * This file contains all the definitions of the functions related with
\r
11 * the tesh context type.
\r
15 #include <context.h>
\r
18 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh);
\r
20 #define INDEFINITE_SIGNAL NULL
\r
25 context_t context = xbt_new0(s_context_t,1);
\r
27 context->line = NULL;
\r
28 context->command_line = NULL;
\r
29 context->exit_code = 0;
\r
30 context->timeout = INDEFINITE;
\r
31 context->input = xbt_strbuff_new();
\r
32 context->output = xbt_strbuff_new();
\r
33 context->signal = INDEFINITE_SIGNAL;
\r
34 context->output_handling = oh_check;
\r
41 context_free(context_t* ptr)
\r
43 /* TODO : check the parameter */
\r
45 xbt_strbuff_free(((*ptr)->input));
\r
47 if(((*ptr)->output))
\r
48 xbt_strbuff_free(((*ptr)->output));
\r
51 free((*ptr)->signal);
\r
59 context_reset(context_t context)
\r
62 /* TODO : check the parameter */
\r
64 context->line = NULL;
\r
65 context->command_line = NULL;
\r
68 xbt_strbuff_empty(context->input);
\r
71 xbt_strbuff_empty(context->output);
\r
75 free(context->signal);
\r
76 context->signal = NULL;
\r
79 /* default expected exit code */
\r
80 context->exit_code = 0;
\r
82 context->output_handling = oh_check;
\r
90 context_dup(context_t context)
\r
95 /* TODO : check the parameter */
\r
97 dup = xbt_new0(s_context_t, 1);
\r
99 dup->line = context->line;
\r
100 dup->command_line = context->command_line;
\r
101 dup->exit_code = context->exit_code;
\r
102 dup->timeout = context->timeout;
\r
103 dup->output = NULL;
\r
105 dup->signal = NULL;
\r
107 if(context->input->used)
\r
109 dup->input = xbt_strbuff_new();
\r
110 xbt_strbuff_append(dup->input,context->input->data);
\r
113 if(context->output->used)
\r
115 dup->output = xbt_strbuff_new();
\r
116 xbt_strbuff_append(dup->output,context->output->data);
\r
119 if(context->signal)
\r
121 if(!(dup->signal = strdup(context->signal)))
\r
128 dup->output_handling = context->output_handling;
\r
130 dup->async = context->async;
\r
136 context_clear(context_t context)
\r
138 context->line = NULL;
\r
139 context->command_line = NULL;
\r
140 context->exit_code = 0;
\r
141 context->timeout = INDEFINITE;
\r
144 xbt_strbuff_empty(context->input);
\r
146 if(context->output)
\r
147 xbt_strbuff_empty(context->output);
\r
149 if(context->signal)
\r
151 free(context->signal);
\r
152 context->signal = INDEFINITE_SIGNAL;
\r
155 context->output_handling = oh_check;
\r
156 context->async = 0;
\r
161 context_input_write(context_t context, const char* buffer)
\r
163 xbt_strbuff_append(context->input, buffer);
\r
167 context_ouput_read(context_t context, const char* buffer)
\r
169 xbt_strbuff_append(context->output, buffer);
\r