+ else if((p = strstr(buff, ":-")))\r
+ {\r
+ /* ${var:-val} */\r
+ \r
+ /* if the value of the variable is empty, replace the expression by the value */\r
+ p += 2;\r
+ end = strchr(p, '}');\r
+\r
+ if(!end || (end == p))\r
+ {\r
+ xbt_os_mutex_release(unit->mutex); \r
+ \r
+ ERROR2("[%s] Bad substitution : `%s'.",filepos, strstr(line2, "${"));\r
+ \r
+ unit_set_error(fstream->unit, ESYNTAX, 1, filepos);\r
+ failure(fstream->unit);\r
+ return;\r
+ }\r
+\r
+ val = (char*) calloc((size_t)(end - p) + 1, sizeof(char));\r
+\r
+ strncpy(val, p,(end - p)); \r
+\r
+ sprintf(exp, "${%s:-%s}", variable->name, val);\r
+ \r
+ str_replace_all(&line2, exp, variable->val ? variable->val : val, NULL);\r
+ \r
+\r
+ memset(exp, 0, VAR_NAME_MAX + 1);\r
+ \r
+ if(val)\r
+ {\r
+ free(val);\r
+ val = NULL;\r
+ }\r
+\r
+ }\r
+ else if((p = strstr(buff, ":+")))\r
+ {\r
+ /* ${var:+val} */\r
+ \r
+ /* if the value of the variable is not empty, replace the expression by the value */\r
+ p += 2;\r
+\r
+ end = strchr(p, '}');\r
+\r
+ if(!end || (end == p))\r
+ {\r
+ xbt_os_mutex_release(unit->mutex); \r
+ \r
+ \r
+ ERROR2("[%s] Bad substitution : `%s'.",filepos, strstr(line2, "${"));\r
+ \r
+ unit_set_error(fstream->unit, ESYNTAX, 1, filepos);\r
+ failure(fstream->unit);\r
+ return;\r
+ }\r
+\r
+ val = (char*) calloc((size_t)(end - p) + 1, sizeof(char));\r
+\r
+ strncpy(val, p,(end - p));\r
+\r
+ sprintf(exp, "${%s:+%s}", variable->name, val);\r
+\r
+ if(variable->val)\r
+ {\r
+ str_replace_all(&line2, exp, val, NULL);\r
+ }\r
+ else\r
+ {\r
+ str_replace_all(&line2, exp, NULL , NULL);\r
+ variable->val = strdup(val);\r
+ }\r
+ \r
+ memset(exp, 0, VAR_NAME_MAX + 1);\r
+ \r
+ if(val)\r
+ {\r
+ free(val);\r
+ val = NULL;\r
+ }\r
+ }\r
+ else if((p = strstr(buff, ":?")))\r
+ {\r
+ /* ${var:?val} */\r
+ \r
+ /* if the value of the variable is not empty, replace the expression by the value */\r
+ p += 2;\r
+ end = strchr(p, '}');\r
+\r
+ if(!end || (end == p))\r
+ {\r
+ xbt_os_mutex_release(unit->mutex); \r
+ \r
+ ERROR2("[%s] Bad substitution : `%s'.",filepos, strstr(line2, "${"));\r
+ \r
+ unit_set_error(fstream->unit, ESYNTAX, 1, filepos);\r
+ failure(fstream->unit);\r
+ return;\r
+ }\r
+\r
+ val = (char*) calloc((size_t)(end - p) + 1, sizeof(char));\r
+\r
+ strncpy(val, p,(end - p));\r
+\r
+ sprintf(exp, "${%s:?%s}", variable->name, val);\r
+ \r
+ if(variable->val)\r
+ str_replace_all(&line2, exp, variable->val, NULL);\r
+ else\r
+ {\r
+\r
+ xbt_os_mutex_release(unit->mutex); \r
+\r
+ ERROR2("[%s] %s.",filepos, val);\r
+\r
+ unit_set_error(fstream->unit, ESYNTAX, 1, filepos);\r
+ failure(fstream->unit);\r
+ return;\r
+ }\r
+ \r
+ memset(exp, 0, VAR_NAME_MAX + 1);\r
+ \r
+ if(val)\r
+ {\r
+ free(val);\r
+ val = NULL;\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ /* replace all existing $var */\r
+ xbt_dynar_foreach(variables, i, variable)\r
+ {\r
+ if(!strchr(line2 + 2, '$'))\r
+ break;\r
+\r
+ if(strstr(line2 + 2, variable->name))\r
+ {\r
+\r
+ sprintf(exp, "${#%s}", variable->name);\r
+ \r
+ if(strstr(line2 + 2, exp))\r
+ {\r
+\r
+ if(variable->val)\r
+ {\r
+ char slen[4] = {0};\r
+ sprintf(slen,"%d", (int)strlen(variable->val));\r
+ str_replace_all(&line2, exp, slen, NULL);\r
+ }\r
+ else\r
+ str_replace_all(&line2, exp, "0", NULL);\r
+ }\r
+\r
+ memset(exp, 0, VAR_NAME_MAX + 1);\r
+\r
+ sprintf(exp, "${%s}", variable->name);\r
+\r
+ if(strstr(line2 + 2, exp))\r
+ {\r
+ if(variable->val)\r
+ str_replace_all(&line2, exp, variable->val, NULL);\r
+ else\r
+ str_replace_all(&line2, exp, NULL, NULL);\r
+ }\r
+\r
+ memset(exp, 0, VAR_NAME_MAX + 1);\r
+\r
+ sprintf(exp, "$%s", variable->name);\r
+ \r
+ if((p = strstr(line2 + 2, exp)))\r
+ {\r
+ if((p + strlen(variable->name) + 1)[0] != '\0' && !(isalpha((p + strlen(variable->name) + 1)[0])))\r
+ delimiters[0] = (p + strlen(variable->name) + 1)[0];\r
+\r
+ if(variable->val)\r
+ str_replace_all(&line2, exp, variable->val, delimiters);\r
+ else\r
+ str_replace_all(&line2, exp, NULL, delimiters);\r
+ }\r
+\r
+ memset(exp, 0, VAR_NAME_MAX + 1);\r
+\r
+ }\r
+ }\r
+\r
+ while((p = strstr(line2 + 2, "${")))\r
+ {\r
+ /*if(*(p+1) != '{')\r
+ {\r
+ j = 0;\r
+ p --;\r
+\r
+ while(*(p++) != '\0')\r
+ {\r
+ if(*p != ' ' && *p !='\t')\r
+ exp[j++] = *p;\r
+ else\r
+ break;\r
+\r
+ }\r
+ \r
+ str_replace_all(&line2, exp, NULL, " \t\n\r");\r
+ memset(exp, 0, VAR_NAME_MAX + 1);\r
+ }.\r
+ else\r
+ */\r
+ {\r
+ char* begin = NULL;\r
+ \r
+ j = 0;\r
+ p --;\r
+\r
+ while(*(p++) != '\0')\r
+ {\r
+ if((!begin && *p != ' ' && *p !='\t') || begin)\r
+ {\r
+ /* `:' must be before this caracter, bad substitution : exit loop \r
+ ||\r
+ the current character is already present, bad substitution : exit loop\r
+ */\r
+ if(\r
+ (\r
+ *(p - 1) != ':' && (\r
+ (*p == '=') || (*p == '-') || (*p == '+') || (*p == '?')\r
+ )\r
+ )\r
+ || \r
+ (\r
+ begin && (\r
+ (*p == ':') || (*p == '=') || (*p == '-') || (*p == '+') || (*p == '?')\r
+ )\r
+ )\r
+ )\r
+ break;\r
+ else\r
+ exp[j++] = *p;\r
+\r
+ if(*p == ':')\r
+ {\r
+ /* save the begining of the value */\r
+ if((*(p+1) == '=') || (*(p+1) == '-') || (*(p+1) == '+') || (*(p+1) == '?'))\r
+ {\r
+ begin = p + 2;\r
+ exp[j++] = *(p+1);\r
+ p++;\r
+ continue;\r
+\r
+ }\r
+ else\r
+ /* the current char is `:' but the next is invalid, bad substitution : exit loop */\r
+ break;\r
+ }\r
+ /* end of the substitution : exit loop */\r
+ else if(*p == '}')\r
+ break;\r
+ }\r
+ else\r
+ break;\r
+ }\r
+ \r
+ if(exp[j - 1] == '}')\r
+ {\r
+ if(exp[2] == '#')\r
+ {\r
+ /* ${#var} */\r
+\r
+\r
+ if(4 == strlen(exp))\r
+ {\r
+ xbt_os_mutex_release(unit->mutex); \r
+ \r
+ ERROR2("[%s] Bad substitution : `%s'.",filepos, strchr(line2 + 2, '$'));\r
+ \r
+ unit_set_error(fstream->unit, ESYNTAX, 1, filepos);\r
+ failure(fstream->unit);\r
+ return;\r
+ }\r
+ \r
+ str_replace_all(&line2, exp, "0", NULL); \r
+ }\r
+ else if(strstr(exp,":="))\r
+ {\r
+ /* ${var:=value} */ \r
+ \r
+ end = strchr(p, '}');\r
+\r
+ if(!end || (end == begin))\r
+ {\r
+ xbt_os_mutex_release(unit->mutex); \r
+ \r
+ \r
+ ERROR2("[%s] Bad substitution : `%s'.",filepos, strchr(line2 + 2, '$'));\r
+ \r
+ unit_set_error(fstream->unit, ESYNTAX, 1, filepos);\r
+ failure(fstream->unit);\r
+ return;\r
+ }\r
+\r
+ variable = xbt_new0(s_variable_t, 1);\r
+\r
+ variable->val = (char*) calloc((size_t)(end - begin) + 1, sizeof(char));\r
+\r
+ strncpy(variable->val, begin ,(end - begin));\r
+\r
+ begin = exp + 2;\r
+ end = strchr(exp, ':');\r
+\r
+ if(!end || (end == begin))\r
+ {\r
+ xbt_os_mutex_release(unit->mutex); \r
+ \r
+ \r
+ ERROR2("[%s] Bad substitution : `%s'.",filepos, strchr(line2 + 2, '$'));\r
+ \r
+ unit_set_error(fstream->unit, ESYNTAX, 1, filepos);\r
+ failure(fstream->unit);\r
+ return;\r
+ }\r
+\r
+ variable->name = (char*) calloc((size_t)(end - begin) + 1, sizeof(char));\r
+\r
+ strncpy(variable->name, exp + 2 ,(end - begin));\r
+\r
+ str_replace_all(&line2, exp, variable->val, NULL);\r
+\r
+ xbt_dynar_push(variables, &variable);\r
+\r
+ }\r
+ else if(strstr(exp,":-"))\r
+ {\r
+ /* ${var:-value} */ \r
+\r
+ \r
+ end = strchr(p, '}');\r
+\r
+ if(!end || (end == begin))\r
+ {\r
+ xbt_os_mutex_release(unit->mutex); \r
+ \r
+ \r
+ ERROR2("[%s] Bad substitution : `%s'.",filepos, strchr(line2 + 2, '$'));\r
+ \r
+ unit_set_error(fstream->unit, ESYNTAX, 1, filepos);\r
+ failure(fstream->unit);\r
+ return;\r
+ }\r
+\r
+ val = (char*) calloc((size_t)(end - begin) + 1, sizeof(char));\r
+\r
+ strncpy(val, begin ,(end - begin));\r
+\r
+ str_replace_all(&line2, exp, val, NULL);\r
+\r
+ if(val)\r
+ free(val);\r
+\r
+ }\r
+ else if(strstr(exp,":+"))\r
+ {\r
+ /* ${var:+value} */ \r
+\r
+ end = strchr(p, '}');\r
+\r
+ if(!end || (end == begin))\r
+ {\r
+ xbt_os_mutex_release(unit->mutex); \r
+ \r
+ ERROR2("[%s] Bad substitution : `%s'.",filepos, strchr(line2 + 2, '$'));\r
+ \r
+ unit_set_error(fstream->unit, ESYNTAX, 1, filepos);\r
+ failure(fstream->unit);\r
+ return;\r
+ }\r
+\r
+ str_replace_all(&line2, exp, NULL, NULL);\r
+ }\r
+ else if(strstr(exp,":?"))\r
+ {\r
+ /* ${var:?value} */\r
+ \r
+ end = strchr(p, '}');\r
+\r
+ if(!end || (end == begin))\r
+ {\r
+ xbt_os_mutex_release(unit->mutex); \r
+ \r
+ ERROR2("[%s] Bad substitution : `%s'.",filepos, strchr(line2 + 2, '$'));\r
+ \r
+ unit_set_error(fstream->unit, ESYNTAX, 1, filepos);\r
+ failure(fstream->unit);\r
+ return;\r
+ }\r
+\r
+ val = (char*) calloc((size_t)(end - begin) + 1, sizeof(char));\r
+\r
+ strncpy(val, begin ,(end - begin));\r
+\r
+ xbt_os_mutex_release(unit->mutex); \r
+ \r
+ ERROR2("[%s] : `%s'.",filepos, val);\r
+\r
+ if(val)\r
+ free(val);\r
+ \r
+ unit_set_error(fstream->unit, ESYNTAX, 1, filepos);\r
+ failure(fstream->unit);\r
+\r
+ return;\r
+ \r
+ }\r
+ else\r
+ {\r
+ /* ${var} */\r
+\r
+ if(3 == strlen(exp))\r
+ {\r
+ xbt_os_mutex_release(unit->mutex); \r
+ \r
+ ERROR2("[%s] Bad substitution : `%s'.",filepos, strchr(line2 + 2, '$'));\r
+ \r
+ unit_set_error(fstream->unit, ESYNTAX, 1, filepos);\r
+ failure(fstream->unit);\r
+ return;\r
+ }\r
+\r
+ str_replace_all(&line2, exp, NULL, NULL);\r
+ \r
+ }\r
+\r
+ memset(exp, 0, VAR_NAME_MAX + 1);\r
+ }\r
+ else\r
+ {\r
+ xbt_os_mutex_release(unit->mutex); \r
+ \r
+ if(strstr(line2 + 2, "${"))\r
+ ERROR2("[%s] Bad substitution : `%s'.",filepos, strstr(line2, "${"));\r
+ else\r
+ ERROR2("[%s] Syntax error : `%s'.",filepos, strstr(line2, "${"));\r
+\r
+ unit_set_error(fstream->unit, ESYNTAX, 1, filepos);\r
+ failure(fstream->unit);\r
+ return;\r
+ }\r
+\r
+ }\r
+ \r
+ }\r
+ \r
+ while(1)\r
+ {\r
+ p = line2 + (line2[0] =='<' ? 4 : 2);\r
+ \r
+ if((p = strchr(p, '$')))\r
+ {\r
+ if(*(p+1) != ' ')\r
+ {\r
+ j = 0;\r
+ p --;\r
+\r
+ while(*(p++) != '\0')\r
+ {\r
+ if(*p != ' ' && *p !='\t')\r
+ exp[j++] = *p;\r
+ else\r
+ break;\r
+\r
+ }\r
+ \r
+ str_replace_all(&line2, exp, NULL, " \t\n\r");\r
+ memset(exp, 0, VAR_NAME_MAX + 1);\r
+ }\r
+ else\r
+ {\r
+ /* maybe < $ cmd */\r
+ p++;\r
+ }\r
+ }\r
+ else\r
+ break;\r
+ }\r
+\r
+ xbt_os_mutex_release(unit->mutex); \r
+ \r
+ switch(line2[0]) \r
+ {\r
+ /*case '#': \r
+ break;\r
+ */\r
+ \r
+ case '$':\r
+ case '&':\r
+\r
+ if(line[1] != ' ')\r
+ {\r
+ \r
+ if(line2[0] == '$')\r
+ ERROR1("[%s] Missing space after `$' `(usage : $ <command>)'", filepos);\r
+ else\r
+ ERROR1("[%s] Missing space after & `(usage : & <command>)'", filepos);\r
+ \r
+ unit_set_error(fstream->unit, ESYNTAX, 1, filepos);\r
+\r
+ failure(unit);\r
+ return;\r
+ }\r
+ \r
+ context->async = (line2[0] == '&');\r
+\r
+ \r
+ /* further trim useless chars which are significant for in/output */\r
+ xbt_str_rtrim(line2 + 2," \t");\r
+ \r
+ /* deal with CD commands here, not in context */\r
+ if(!strncmp("cd ",line2 + 2, 3)) \r
+ {\r
+ char* dir = strdup(line2 + 4);\r
+ \r
+ if(context->command_line)\r
+ {\r
+ if(fstream_launch_command(fstream, context, mutex) < 0)\r
+ return;\r
+ }\r
+ \r
+ /* search begining */\r
+ while(*(dir++) == ' ');\r
+ \r
+ dir--;\r
+ \r
+ if(!dry_run_flag)\r
+ {\r
+ if(!silent_flag)\r
+ INFO2("[%s] cd %s", filepos, dir);\r
+ \r
+ if(!just_print_flag)\r
+ {\r
+ if(chdir(dir))\r
+ {\r
+ ERROR3("[%s] Chdir to %s failed: %s",filepos, dir,error_to_string(errno, 0));\r
+ unit_set_error(fstream->unit, errno, 0, filepos);\r
+\r
+ failure(unit);\r
+ }\r
+ }\r
+ }\r
+ \r
+ break;\r
+ }\r
+ else\r
+ {\r
+ fstream_process_token(fstream, context, mutex, filepos, line2[0], line2 + 2);\r
+ break;\r
+ }\r
+ \r
+ case '<':\r
+ case '>':\r
+ case '!':\r
+ \r
+ if(line[0] == '!' && line[1] != ' ')\r
+ {\r
+ ERROR1("[%s] Missing space after `!' `(usage : ! <command> [[=]value])'", filepos);\r
+ \r
+ unit_set_error(fstream->unit, ESYNTAX, 1, filepos);\r
+\r
+ failure(unit);\r
+ return;\r
+ }\r
+\r
+ fstream_process_token(fstream, context, mutex, filepos, line2[0], line2 + 2); \r
+ break;\r
+ \r
+ case 'p':\r
+ \r
+ {\r
+ unsigned int j;\r
+ int is_blank = 1;\r
+ \r
+ char* prompt = line2 + 2;\r
+\r
+ for(j = 0; j < strlen(prompt); j++)\r
+ {\r
+ if (prompt[j] != ' ' && prompt[j] != '\t')\r
+ {\r
+ is_blank = 0;\r
+ break;\r
+ }\r
+ }\r
+\r
+ if(is_blank)\r
+ {\r
+ ERROR1("[%s] Bad usage of the metacommand p `(usage : p <prompt>)'", filepos);\r
+ \r
+ unit_set_error(fstream->unit, ESYNTAX, 1, filepos);\r
+\r
+ failure(unit);\r
+ return;\r
+ }\r
+\r
+ if(!dry_run_flag)\r
+ INFO2("[%s] %s",filepos,prompt);\r
+ }\r
+\r
+ \r
+ break;\r
+ \r
+ case 'P':\r
+ \r
+ {\r
+ unsigned int j;\r
+ int is_blank = 1;\r
+ \r
+ char* prompt = line2 + 2;\r
+\r
+ for(j = 0; j < strlen(prompt); j++) \r
+ if (prompt[j] != ' ' && prompt[j] != '\t')\r
+ is_blank = 0;\r
+\r
+ if(is_blank)\r
+ {\r
+ ERROR1("[%s] Bad usage of the metacommand P `(usage : P <prompt>)'", filepos);\r
+ \r
+ unit_set_error(fstream->unit, ESYNTAX, 1, filepos);\r
+\r
+ failure(unit);\r
+ return;\r
+ }\r
+\r
+ if(!dry_run_flag) \r
+ CRITICAL2("[%s] %s",filepos, prompt);\r
+ }\r
+\r
+ break;\r
+ \r
+ case 'D':\r
+ if(unit->description)\r
+ WARN2("[%s] Description already specified `%s'",filepos, line2 + 2); \r
+ else\r
+ {\r
+ unsigned int j;\r
+ int is_blank = 1;\r
+ \r
+ char* desc = line2 + 2;\r
+\r
+ for(j = 0; j < strlen(desc); j++) \r
+ if (desc[j] != ' ' && desc[j] != '\t')\r
+ is_blank = 0;\r
+\r
+ if(is_blank)\r
+ {\r
+ ERROR1("[%s] Bad usage of the metacommand D `(usage : D <Description>)'", filepos);\r
+ \r
+ unit_set_error(fstream->unit, ESYNTAX, 1, filepos);\r
+\r
+ failure(unit);\r
+ return;\r
+ }\r
+\r
+ unit->description = strdup(desc);\r
+ }\r
+ break;\r
+ \r
+ default:\r
+ ERROR2("[%s] Syntax error `%s'", filepos, line2);\r
+ unit_set_error(fstream->unit, ESYNTAX, 1, filepos);\r
+ failure(unit);\r
+ break;\r
+ }\r
+ \r
+ free(line2);\r
+}\r
+\r
+void \r
+fstream_process_token(fstream_t fstream, context_t context, xbt_os_mutex_t mutex, const char* filepos, char token, char *line) \r
+{\r
+ unit_t unit = fstream->unit;\r
+ \r
+ switch (token) \r
+ {\r
+ case '$':\r
+ case '&':\r
+ \r
+ if(context->command_line) \r
+ {\r
+ \r
+ if(context->output->used || context->input->used) \r
+ {\r
+ ERROR2("[%s] More than one command in this chunk of lines (previous: %s).\nDunno which input/output belongs to which command.",filepos, context->command_line);\r
+\r
+ unit_set_error(fstream->unit, ESYNTAX, 1, filepos);\r
+ failure(unit);\r
+ return;\r
+ }\r
+ \r
+ if(fstream_launch_command(fstream, context, mutex) < 0)\r
+ return;\r
+ \r
+ VERB1("[%s] More than one command in this chunk of lines",filepos);\r
+ }\r
+ \r
+ {\r
+ size_t j,\r
+ is_blank = 1;\r
+\r
+ for(j = 0; j < strlen(line); j++) \r
+ if (line[j] != ' ' && line[j] != '\t')\r
+ is_blank = 0;\r
+\r
+ if(is_blank)\r
+ {\r
+ if(token == '$')\r
+ ERROR1("[%s] Undefinite command for `$' `(usage: $ <command>)'", filepos);\r
+ else\r
+ ERROR1("[%s] Undefinite command for `&' `(usage: & <command>)'", filepos);\r
+\r
+ unit_set_error(fstream->unit, ESYNTAX, 1, filepos);\r
+\r
+ failure(unit);\r
+ return;\r
+ }\r
+ }\r
+ \r
+ context->command_line = strdup(line);\r
+\r
+ xbt_str_ltrim(context->command_line," ");\r
+ \r
+ context->line = /*strdup(filepos)*/ filepos;\r
+ context->pos = strdup(filepos);\r
+ \r
+ #ifdef WIN32\r
+ {\r
+\r
+ /* translate the command line */\r
+\r
+ char* path = NULL;\r
+ char* delimiter;\r
+ char command_line[PATH_MAX + 1] = {0};\r
+ size_t i = 0;\r
+ char* args = NULL;\r
+\r
+ \r
+\r
+ /*if(strstr(context->command_line,".exe"))\r
+ strcpy(command_line,context->command_line);*/\r
+ \r
+ {\r
+ size_t len;\r
+ \r
+ size_t j = 0;\r
+ \r
+ len = strlen(context->command_line);\r
+ \r
+ while(i < len)\r
+ {\r
+ if(context->command_line[i] != ' ' && context->command_line[i] != '\t' && context->command_line[i] != '>')\r
+ command_line[j++] = context->command_line[i];\r
+ else\r
+ break;\r
+ \r
+ i++;\r
+ }\r
+ \r
+ if(!strstr(context->command_line,".exe"))\r
+ strcat(command_line,".exe");\r
+\r
+ args = strdup(context->command_line + i);\r
+ }\r
+ \r
+ if(!is_w32_cmd(command_line, fstream->unit->runner->path) && getpath(command_line, &path) < 0)\r
+ {\r
+ command_t command;\r
+\r
+ ERROR3("[%s] `%s' : NOK (%s)", filepos, command_line, error_to_string(ECMDNOTFOUND, 1));\r
+ unit_set_error(fstream->unit, ECMDNOTFOUND, 1, filepos);\r
+\r
+ context->is_not_found = 1;\r
+ \r
+ command = command_new(fstream->unit, context, mutex);\r
+\r
+ command->status = cs_failed;\r
+ command->reason = csr_command_not_found;\r
+\r
+ failure(unit);\r
+ \r
+ \r
+ return;\r
+ }\r
+ \r
+ delimiter = strrchr(command_line,'/');\r
+\r
+ if(!delimiter)\r
+ delimiter = strrchr(command_line,'\\');\r
+ \r
+ /*free(context->command_line);*/\r
+ \r
+ \r
+ if(path)\r
+ {\r
+ if(args)\r
+ {\r
+ context->t_command_line = (char*)calloc(strlen(path) + strlen(delimiter ? delimiter + 1 : command_line) + strlen(args) + 2, sizeof(char));\r
+ sprintf(context->t_command_line,"%s\\%s%s",path,delimiter ? delimiter + 1 : command_line, args);\r
+\r
+ free(args);\r
+\r
+ }\r
+ else\r
+ {\r
+ context->t_command_line = (char*)calloc(strlen(path) + strlen(delimiter ? delimiter + 1 : command_line) + 2, sizeof(char));\r
+ sprintf(context->t_command_line,"%s\\%s",path,delimiter ? delimiter + 1 : command_line);\r
+ }\r
+ \r
+ free(path);\r
+ }\r
+ else\r
+ {\r
+ if(args)\r
+ {\r
+\r
+ context->t_command_line = (char*)calloc(strlen(command_line) + strlen(args) + 1, sizeof(char));\r
+ sprintf(context->t_command_line,"%s%s",command_line, args);\r
+\r
+ \r
+ free(args);\r
+\r
+ }\r
+ else\r
+ {\r
+ context->t_command_line = (char*)calloc(strlen(command_line) + 1, sizeof(char));\r
+ strcpy(context->t_command_line,command_line);\r
+ }\r
+ }\r
+\r
+\r
+ }\r
+ #endif\r
+\r
+\r
+ break;\r
+ \r
+ case '<':\r
+ xbt_strbuff_append(context->input,line);\r
+ xbt_strbuff_append(context->input,"\n");\r
+ break;\r
+ \r
+ case '>':\r
+ xbt_strbuff_append(context->output,line);\r
+ xbt_strbuff_append(context->output,"\n");\r
+ break;\r
+ \r
+ case '!':\r
+ \r
+ if(context->command_line)\r
+ {\r
+ if(fstream_launch_command(fstream, context, mutex) < 0)\r
+ return;\r
+ }\r
+ \r
+ if(!strncmp(line,"timeout no",strlen("timeout no"))) \r
+ {\r
+ VERB1("[%s] (disable timeout)", filepos);\r
+ context->timeout = INDEFINITE;\r
+ } \r
+ else if(!strncmp(line,"timeout ",strlen("timeout "))) \r
+ {\r
+ int i = 0;\r
+ unsigned int j;\r
+ int is_blank = 1;\r
+ char* p = line + strlen("timeout ");\r
+\r
+\r
+ for(j = 0; j < strlen(p); j++) \r
+ if (p[j] != ' ' && p[j] != '\t')\r
+ is_blank = 0;\r
+\r
+ if(is_blank)\r
+ {\r
+ ERROR1("[%s] Undefinite timeout value `(usage :timeout <seconds>)'", filepos);\r
+ \r
+ unit_set_error(fstream->unit, ESYNTAX, 1, filepos);\r
+\r
+ failure(unit);\r
+ return;\r
+ }\r
+ \r
+ while(p[i] != '\0')\r
+ {\r
+ if(!isdigit(p[i]))\r
+ {\r
+ ERROR2("[%s] Invalid timeout value `(%s)' : `(usage :timeout <seconds>)'", filepos, line + strlen("timeout "));\r
+\r
+ unit_set_error(fstream->unit, ESYNTAX, 1, filepos);\r
+ \r
+ failure(unit);\r
+ return;\r
+ }\r
+\r
+ i++;\r
+ }\r
+ \r
+ context->timeout = atoi(line + strlen("timeout"));\r
+ VERB2("[%s] (new timeout value: %d)",filepos,context->timeout);\r
+ \r
+ } \r
+ else if (!strncmp(line,"expect signal ",strlen("expect signal "))) \r
+ {\r
+ unsigned int j;\r
+ int is_blank = 1;\r
+\r
+ \r
+ char* p = line + strlen("expect signal ");\r
+\r
+\r
+ for(j = 0; j < strlen(p); j++) \r
+ if (p[j] != ' ' && p[j] != '\t')\r
+ is_blank = 0;\r
+\r
+ if(is_blank)\r
+ {\r
+ ERROR1("[%s] Undefinite signal name `(usage :expect signal <signal name>)'", filepos);\r
+ \r
+ unit_set_error(fstream->unit, ESYNTAX, 1, filepos);\r
+\r
+ failure(unit);\r
+ return;\r
+ }\r
+\r
+ context->signal = strdup(line + strlen("expect signal "));\r
+ \r
+ xbt_str_trim(context->signal," \n");\r
+\r