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
46 context_free(context_t* ptr)
\r
49 xbt_strbuff_free(((*ptr)->input));
\r
51 if(((*ptr)->output))
\r
52 xbt_strbuff_free(((*ptr)->output));
\r
54 if((*ptr)->command_line)
\r
55 free((*ptr)->command_line);
\r
61 free((*ptr)->signal);
\r
64 if((*ptr)->t_command_line)
\r
65 free((*ptr)->t_command_line);
\r
74 context_reset(context_t context)
\r
76 context->line = NULL;
\r
77 context->pos = NULL;
\r
79 if(context->command_line)
\r
81 free(context->command_line);
\r
82 context->command_line = NULL;
\r
86 if(context->t_command_line)
\r
88 free(context->t_command_line);
\r
89 context->t_command_line = NULL;
\r
96 context->pos = NULL;
\r
100 xbt_strbuff_empty(context->input);
\r
102 if(context->output)
\r
103 xbt_strbuff_empty(context->output);
\r
105 if(context->signal)
\r
107 free(context->signal);
\r
108 context->signal = NULL;
\r
111 /* default expected exit code */
\r
112 context->exit_code = 0;
\r
114 context->output_handling = oh_check;
\r
115 context->async = 0;
\r
122 context_dup(context_t context)
\r
126 dup = xbt_new0(s_context_t, 1);
\r
128 dup->line = context->line;
\r
129 dup->pos = strdup(context->pos);
\r
130 dup->command_line = strdup(context->command_line);
\r
134 dup->t_command_line = strdup(context->t_command_line);
\r
137 dup->exit_code = context->exit_code;
\r
138 dup->timeout = context->timeout;
\r
139 dup->output = NULL;
\r
141 dup->signal = NULL;
\r
143 if(context->input->used)
\r
145 dup->input = xbt_strbuff_new();
\r
146 xbt_strbuff_append(dup->input,context->input->data);
\r
149 dup->output = xbt_strbuff_new();
\r
151 if(context->output->used)
\r
153 xbt_strbuff_append(dup->output,context->output->data);
\r
156 if(context->signal)
\r
158 if(!(dup->signal = strdup(context->signal)))
\r
165 dup->output_handling = context->output_handling;
\r
167 dup->async = context->async;
\r
173 context_clear(context_t context)
\r
175 context->line = NULL;
\r
176 context->pos = NULL;
\r
178 if(context->command_line)
\r
180 free(context->command_line);
\r
181 context->command_line = NULL;
\r
185 if(context->t_command_line)
\r
187 free(context->t_command_line);
\r
188 context->t_command_line = NULL;
\r
194 free(context->pos);
\r
195 context->pos = NULL;
\r
198 context->exit_code = 0;
\r
199 context->timeout = INDEFINITE;
\r
202 xbt_strbuff_empty(context->input);
\r
204 if(context->output)
\r
205 xbt_strbuff_empty(context->output);
\r
207 if(context->signal)
\r
209 free(context->signal);
\r
210 context->signal = INDEFINITE_SIGNAL;
\r
213 context->output_handling = oh_check;
\r
214 context->async = 0;
\r
219 context_input_write(context_t context, const char* buffer)
\r
221 xbt_strbuff_append(context->input, buffer);
\r
225 context_ouput_read(context_t context, const char* buffer)
\r
227 xbt_strbuff_append(context->output, buffer);
\r