+++ /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
-\r
-XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh);\r
-\r
-#define INDEFINITE_SIGNAL NULL\r
-\r
-context_t\r
-context_new(void)\r
-{\r
- context_t context = xbt_new0(s_context_t,1);\r
- \r
- context->line = NULL;\r
- context->command_line = NULL;\r
- context->exit_code = 0;\r
- context->timeout = INDEFINITE;\r
- context->input = xbt_strbuff_new();\r
- context->output = xbt_strbuff_new();\r
- context->signal = INDEFINITE_SIGNAL;\r
- context->output_handling = oh_check;\r
- context->async = 0;\r
- \r
- return context;\r
-}\r
-\r
-int\r
-context_free(context_t* ptr)\r
-{\r
- /* TODO : check the parameter */\r
- if(((*ptr)->input))\r
- xbt_strbuff_free(((*ptr)->input));\r
-\r
- if(((*ptr)->output))\r
- xbt_strbuff_free(((*ptr)->output));\r
- \r
- if((*ptr)->signal)\r
- free((*ptr)->signal);\r
-\r
- *ptr = NULL;\r
- \r
- return 0;\r
-}\r
-\r
-int\r
-context_reset(context_t context)\r
-{\r
- \r
- /* TODO : check the parameter */\r
- \r
- context->line = NULL;\r
- context->command_line = NULL;\r
-\r
- if(context->input)\r
- xbt_strbuff_empty(context->input);\r
-\r
- if(context->output)\r
- xbt_strbuff_empty(context->output);\r
- \r
- if(context->signal)\r
- {\r
- free(context->signal);\r
- context->signal = NULL;\r
- }\r
- \r
- /* default expected exit code */\r
- context->exit_code = 0;\r
-\r
- context->output_handling = oh_check;\r
- context->async = 0;\r
- \r
- return 0;\r
-\r
-}\r
-\r
-context_t\r
-context_dup(context_t context)\r
-{\r
- \r
- context_t dup;\r
- \r
- /* TODO : check the parameter */\r
- \r
- dup = xbt_new0(s_context_t, 1);\r
- \r
- dup->line = context->line;\r
- dup->command_line = context->command_line;\r
- dup->exit_code = context->exit_code;\r
- dup->timeout = context->timeout;\r
- dup->output = NULL;\r
- dup->input = NULL;\r
- dup->signal = NULL;\r
- \r
- if(context->input->used)\r
- {\r
- dup->input = xbt_strbuff_new();\r
- xbt_strbuff_append(dup->input,context->input->data);\r
- }\r
-\r
- if(context->output->used)\r
- {\r
- dup->output = xbt_strbuff_new();\r
- xbt_strbuff_append(dup->output,context->output->data);\r
- }\r
-\r
- if(context->signal)\r
- {\r
- if(!(dup->signal = strdup(context->signal)))\r
- {\r
- free(dup);\r
- return NULL;\r
- }\r
- }\r
-\r
- dup->output_handling = context->output_handling;\r
- \r
- dup->async = context->async;\r
- \r
- return dup;\r
-}\r
-\r
-void\r
-context_clear(context_t context)\r
-{\r
- context->line = NULL;\r
- context->command_line = NULL;\r
- context->exit_code = 0;\r
- context->timeout = INDEFINITE;\r
- \r
- if(context->input)\r
- xbt_strbuff_empty(context->input);\r
-\r
- if(context->output)\r
- xbt_strbuff_empty(context->output);\r
- \r
- if(context->signal)\r
- {\r
- free(context->signal);\r
- context->signal = INDEFINITE_SIGNAL;\r
- }\r
-\r
- context->output_handling = oh_check;\r
- context->async = 0;\r
-\r
-}\r
-\r
-void\r
-context_input_write(context_t context, const char* buffer)\r
-{\r
- xbt_strbuff_append(context->input, buffer);\r
-}\r
-\r
-void\r
-context_ouput_read(context_t context, const char* buffer)\r
-{\r
- xbt_strbuff_append(context->output, buffer);\r
-}\r
-\r
-\r
-\r