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->pos = NULL;
\r
29 context->command_line = NULL;
\r
30 context->exit_code = 0;
\r
31 context->timeout = INDEFINITE;
\r
32 context->input = xbt_strbuff_new();
\r
33 context->output = xbt_strbuff_new();
\r
34 context->signal = INDEFINITE_SIGNAL;
\r
35 context->output_handling = oh_check;
\r
39 context->t_command_line = NULL;
\r
40 context->is_not_found = 0;
\r
47 context_free(context_t* ptr)
\r
50 xbt_strbuff_free(((*ptr)->input));
\r
52 if(((*ptr)->output))
\r
53 xbt_strbuff_free(((*ptr)->output));
\r
55 if((*ptr)->command_line)
\r
56 free((*ptr)->command_line);
\r
62 free((*ptr)->signal);
\r
65 if((*ptr)->t_command_line)
\r
66 free((*ptr)->t_command_line);
\r
75 context_reset(context_t context)
\r
77 context->line = NULL;
\r
78 context->pos = NULL;
\r
80 if(context->command_line)
\r
82 free(context->command_line);
\r
83 context->command_line = NULL;
\r
87 if(context->t_command_line)
\r
89 free(context->t_command_line);
\r
90 context->t_command_line = NULL;
\r
93 context->is_not_found = 0;
\r
100 context->pos = NULL;
\r
104 xbt_strbuff_empty(context->input);
\r
106 if(context->output)
\r
107 xbt_strbuff_empty(context->output);
\r
109 if(context->signal)
\r
111 free(context->signal);
\r
112 context->signal = NULL;
\r
115 /* default expected exit code */
\r
116 context->exit_code = 0;
\r
118 context->output_handling = oh_check;
\r
119 context->async = 0;
\r
126 context_dup(context_t context)
\r
130 dup = xbt_new0(s_context_t, 1);
\r
132 dup->line = context->line;
\r
133 dup->pos = strdup(context->pos);
\r
134 dup->command_line = strdup(context->command_line);
\r
138 dup->t_command_line = strdup(context->t_command_line);
\r
139 dup->is_not_found = context->is_not_found;
\r
142 dup->exit_code = context->exit_code;
\r
143 dup->timeout = context->timeout;
\r
144 dup->output = NULL;
\r
146 dup->signal = NULL;
\r
148 if(context->input->used)
\r
150 dup->input = xbt_strbuff_new();
\r
151 xbt_strbuff_append(dup->input,context->input->data);
\r
154 dup->output = xbt_strbuff_new();
\r
156 if(context->output->used)
\r
158 xbt_strbuff_append(dup->output,context->output->data);
\r
161 if(context->signal)
\r
163 if(!(dup->signal = strdup(context->signal)))
\r
170 dup->output_handling = context->output_handling;
\r
172 dup->async = context->async;
\r
178 context_clear(context_t context)
\r
180 context->line = NULL;
\r
181 context->pos = NULL;
\r
183 if(context->command_line)
\r
185 free(context->command_line);
\r
186 context->command_line = NULL;
\r
190 if(context->t_command_line)
\r
192 free(context->t_command_line);
\r
193 context->t_command_line = NULL;
\r
195 context->is_not_found = 0;
\r
201 free(context->pos);
\r
202 context->pos = NULL;
\r
205 context->exit_code = 0;
\r
206 context->timeout = INDEFINITE;
\r
209 xbt_strbuff_empty(context->input);
\r
211 if(context->output)
\r
212 xbt_strbuff_empty(context->output);
\r
214 if(context->signal)
\r
216 free(context->signal);
\r
217 context->signal = INDEFINITE_SIGNAL;
\r
220 context->output_handling = oh_check;
\r
221 context->async = 0;
\r
226 context_input_write(context_t context, const char* buffer)
\r
228 xbt_strbuff_append(context->input, buffer);
\r
232 context_ouput_read(context_t context, const char* buffer)
\r
234 xbt_strbuff_append(context->output, buffer);
\r