2 * src/fstream.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 file stream type.
\r
15 #include <fstream.h>
\r
17 #include <context.h>
\r
18 #include <command.h>
\r
20 #include <str_replace.h>
\r
21 #include <variable.h>
\r
23 #include <readline.h>
\r
26 #include <getpath.h>
\r
29 #include <xsignal.h>
\r
34 is_w32_cmd(char* cmd, char** path)
\r
37 struct stat stat_buff = {0};
\r
38 char buff[PATH_MAX + 1] = {0};
\r
48 if(stat(cmd, &stat_buff) || !S_ISREG(stat_buff.st_mode))
\r
52 for (i = 0; path[i] != NULL; i++)
\r
54 /* use Cat.exe on Windows */
\r
55 if(!strcmp(cmd, "cat"))
\r
58 sprintf(buff,"%s\\%s",path[i], cmd);
\r
60 if(!stat(buff, &stat_buff) && S_ISREG(stat_buff.st_mode))
\r
74 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh);
\r
77 long fstream_getline(fstream_t fstream, char **buf, size_t *n) {
\r
79 return readline(fstream->stream, buf, n);
\r
84 failure(unit_t unit)
\r
86 if(!keep_going_unit_flag)
\r
88 unit_t root = unit->root ? unit->root : unit;
\r
90 if(!root->interrupted)
\r
92 /* the unit interrupted (exit for the loop) */
\r
93 root->interrupted = 1;
\r
95 /* release the unit */
\r
96 xbt_os_sem_release(root->sem);
\r
99 /* if the --keep-going option is not specified */
\r
100 if(!keep_going_flag)
\r
104 /* request an global interruption by the runner */
\r
107 /* release the runner */
\r
108 xbt_os_sem_release(units_sem);
\r
115 fstream_new(const char* directory, const char* name)
\r
125 if(!directory && !strcmp("stdin", name))
\r
127 fstream = xbt_new0(s_fstream_t, 1);
\r
128 fstream->name = strdup("stdin");
\r
131 else if(!directory)
\r
137 fstream = xbt_new0(s_fstream_t, 1);
\r
139 if(!(fstream->name = strdup(name)))
\r
145 if(!(fstream->directory = strdup(directory)))
\r
147 free(fstream->name);
\r
152 fstream->stream = NULL;
\r
153 fstream->unit = NULL;
\r
154 fstream->parsed = 0;
\r
161 fstream_open(fstream_t fstream)
\r
163 char path[PATH_MAX + 1] = {0};
\r
165 /* check the parameter */
\r
172 if(!fstream || fstream->stream)
\r
178 if(!strcmp(fstream->name, "stdin"))
\r
180 fstream->stream = stdin;
\r
185 sprintf(path,"%s/%s",fstream->directory, fstream->name);
\r
187 sprintf(path,"%s\\%s",fstream->directory, fstream->name);
\r
190 if(!(fstream->stream = fopen(path, "r")))
\r
199 fstream_close(fstream_t fstream)
\r
201 /* check the parameter */
\r
202 if(!(fstream) || !strcmp(fstream->name, "stdin") )
\r
208 if(!fstream->stream)
\r
211 if(EOF == fclose(fstream->stream))
\r
214 fstream->stream = NULL;
\r
220 fstream_free(fstream_t* ptr)
\r
223 /* check the parameter */
\r
234 fclose((*ptr)->stream);
\r
237 free((*ptr)->name);
\r
239 if((*ptr)->directory)
\r
240 free((*ptr)->directory);
\r
251 fstream_parse(fstream_t fstream, xbt_os_mutex_t mutex)
\r
254 char * line = NULL;
\r
256 char file_pos[256];
\r
257 xbt_strbuff_t buff;
\r
258 int buffbegin = 0;
\r
262 /* Count the line length while checking wheather it's blank */
\r
265 /* Deal with \ at the end of the line, and call handle_line on result */
\r
266 int to_be_continued;
\r
268 /* check the parameter */
\r
269 if(!(fstream) || !mutex)
\r
275 buff = xbt_strbuff_new();
\r
277 if(!(context = context_new()))
\r
280 unit = fstream->unit;
\r
282 /*while(!(unit->root->interrupted) && getline(&line, &len, fstream->stream) != -1)*/
\r
283 while(!(unit->root->interrupted) && fstream_getline(fstream, &line, &len) != -1)
\r
288 to_be_continued = 0;
\r
292 while(line[linelen] != '\0')
\r
294 if (line[linelen] != ' ' && line[linelen] != '\t' && line[linelen]!='\n' && line[linelen]!='\r')
\r
302 if(!context->command_line && (context->input->used || context->output->used))
\r
304 snprintf(file_pos,256,"%s:%d",fstream->name, line_num);
\r
305 ERROR1("[%s] Error : no command found in the last chunk of lines", file_pos);
\r
307 unit_set_error(fstream->unit, ESYNTAX, 1, file_pos);
\r
312 else if(unit->is_running_suite)
\r
313 {/* it's the end of a suite */
\r
315 unit_t* current_suite = xbt_dynar_get_ptr(unit->suites, xbt_dynar_length(unit->suites) - 1);
\r
317 if(!xbt_dynar_length((*current_suite)->includes))
\r
319 ERROR2("[%s] Malformated suite `(%s)' : include missing", file_pos, (*current_suite)->description);
\r
321 unit_set_error(*current_suite, ESYNTAX, 1, file_pos);
\r
327 unit->is_running_suite = 0;
\r
330 if(context->command_line)
\r
332 if(fstream_launch_command(fstream, context, mutex) < 0)
\r
339 if(linelen>1 && line[linelen-2]=='\\')
\r
341 if(linelen>2 && line[linelen-3] == '\\')
\r
343 /* Damn. Escaped \ */
\r
344 line[linelen-2] = '\n';
\r
345 line[linelen-1] = '\0';
\r
349 to_be_continued = 1;
\r
350 line[linelen-2] = '\0';
\r
354 buffbegin = line_num;
\r
358 if(buff->used || to_be_continued)
\r
360 xbt_strbuff_append(buff,line);
\r
362 if (!to_be_continued)
\r
364 snprintf(file_pos,256,"%s:%d",fstream->name, buffbegin);
\r
365 fstream_lex_line(fstream, context, mutex, file_pos, buff->data);
\r
366 xbt_strbuff_empty(buff);
\r
371 snprintf(file_pos,256,"%s:%d",fstream->name, line_num);
\r
372 fstream_lex_line(fstream, context, mutex, file_pos, line);
\r
376 /* Check that last command of the file ran well */
\r
377 if(context->command_line)
\r
379 if(fstream_launch_command(fstream, context, mutex) < 0)
\r
383 /* clear buffers */
\r
387 xbt_strbuff_free(buff);
\r
389 if(context_free(&context) < 0)
\r
392 return (exit_code || errno) ? -1 : 0;
\r
397 fstream_lex_line(fstream_t fstream, context_t context, xbt_os_mutex_t mutex, const char * filepos, char *line)
\r
400 variable_t variable;
\r
402 char exp[PATH_MAX + 1] = {0};
\r
403 unit_t unit = fstream->unit;
\r
404 xbt_dynar_t variables = unit->runner->variables;
\r
408 char buff[PATH_MAX + 1] = {0};
\r
410 char delimiters[4] = {' ', '\t', '\n', '\0'};
\r
417 if(unit->is_running_suite && strncmp(line, "! include", strlen("! include")))
\r
418 {/* it's the end of a suite */
\r
420 unit_t* current_suite = xbt_dynar_get_ptr(unit->suites, xbt_dynar_length(unit->suites) - 1);
\r
422 if(!xbt_dynar_length((*current_suite)->includes))
\r
423 ERROR2("[%s] Malformated suite `(%s)': include missing", filepos, (*current_suite)->description);
\r
425 ERROR2("[%s] Malformated suite `(%s)': blank line missing", filepos, (*current_suite)->description);
\r
427 unit_set_error(*current_suite, ESYNTAX, 1, filepos);
\r
429 failure(fstream->unit);
\r
432 context->line = strdup(filepos);
\r
435 xbt_str_rtrim(line + 2,"\n");
\r
437 line2 = strdup(line);
\r
439 len = strlen(line2 + 2) + 1;
\r
441 /* replace each variable by its value */
\r
442 xbt_os_mutex_acquire(unit->mutex);
\r
445 /* replace all existing
\r
454 xbt_dynar_foreach(variables, i, variable)
\r
456 if(!(p = strstr(line2 + 2, "${")))
\r
459 memset(buff, 0, len);
\r
461 sprintf(buff,"${%s",variable->name);
\r
464 if((p = strstr(line2 + 2, buff)))
\r
466 memset(buff, 0, len);
\r
470 while(*(p++) != '\0')
\r
478 if(buff[j - 1] != '}')
\r
480 xbt_os_mutex_release(unit->mutex);
\r
483 ERROR2("[%s] Syntax error : `%s'.",filepos, p - j);
\r
485 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
486 failure(fstream->unit);
\r
490 if((p = strstr(buff , ":=")))
\r
494 /* if the value of the variable is empty, update its value by the value*/
\r
497 end = strchr(p, '}');
\r
499 if(!end || (end == p))
\r
501 xbt_os_mutex_release(unit->mutex);
\r
504 ERROR2("[%s] Bad substitution : `%s'.",filepos, strstr(buff, "${"));
\r
506 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
507 failure(fstream->unit);
\r
511 val = (char*) calloc((size_t)(end - p) + 1, sizeof(char));
\r
513 strncpy(val, p,(end - p));
\r
516 /* replace the expression by the expression of the value of the variable*/
\r
517 sprintf(exp, "${%s:=%s}", variable->name, val);
\r
520 str_replace_all(&line2, exp, variable->val, NULL);
\r
523 str_replace_all(&line2, exp, val, NULL);
\r
525 variable->val = strdup(val);
\r
528 memset(exp, 0, VAR_NAME_MAX + 1);
\r
537 else if((p = strstr(buff, ":-")))
\r
541 /* if the value of the variable is empty, replace the expression by the value */
\r
543 end = strchr(p, '}');
\r
545 if(!end || (end == p))
\r
547 xbt_os_mutex_release(unit->mutex);
\r
549 ERROR2("[%s] Bad substitution : `%s'.",filepos, strstr(line2, "${"));
\r
551 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
552 failure(fstream->unit);
\r
556 val = (char*) calloc((size_t)(end - p) + 1, sizeof(char));
\r
558 strncpy(val, p,(end - p));
\r
560 sprintf(exp, "${%s:-%s}", variable->name, val);
\r
562 str_replace_all(&line2, exp, variable->val ? variable->val : val, NULL);
\r
565 memset(exp, 0, VAR_NAME_MAX + 1);
\r
574 else if((p = strstr(buff, ":+")))
\r
578 /* if the value of the variable is not empty, replace the expression by the value */
\r
581 end = strchr(p, '}');
\r
583 if(!end || (end == p))
\r
585 xbt_os_mutex_release(unit->mutex);
\r
588 ERROR2("[%s] Bad substitution : `%s'.",filepos, strstr(line2, "${"));
\r
590 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
591 failure(fstream->unit);
\r
595 val = (char*) calloc((size_t)(end - p) + 1, sizeof(char));
\r
597 strncpy(val, p,(end - p));
\r
599 sprintf(exp, "${%s:+%s}", variable->name, val);
\r
603 str_replace_all(&line2, exp, val, NULL);
\r
607 str_replace_all(&line2, exp, NULL , NULL);
\r
608 variable->val = strdup(val);
\r
611 memset(exp, 0, VAR_NAME_MAX + 1);
\r
619 else if((p = strstr(buff, ":?")))
\r
623 /* if the value of the variable is not empty, replace the expression by the value */
\r
625 end = strchr(p, '}');
\r
627 if(!end || (end == p))
\r
629 xbt_os_mutex_release(unit->mutex);
\r
631 ERROR2("[%s] Bad substitution : `%s'.",filepos, strstr(line2, "${"));
\r
633 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
634 failure(fstream->unit);
\r
638 val = (char*) calloc((size_t)(end - p) + 1, sizeof(char));
\r
640 strncpy(val, p,(end - p));
\r
642 sprintf(exp, "${%s:?%s}", variable->name, val);
\r
645 str_replace_all(&line2, exp, variable->val, NULL);
\r
649 xbt_os_mutex_release(unit->mutex);
\r
651 ERROR2("[%s] %s.",filepos, val);
\r
653 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
654 failure(fstream->unit);
\r
658 memset(exp, 0, VAR_NAME_MAX + 1);
\r
669 /* replace all existing $var */
\r
670 xbt_dynar_foreach(variables, i, variable)
\r
672 if(!strchr(line2 + 2, '$'))
\r
675 if(strstr(line2 + 2, variable->name))
\r
678 sprintf(exp, "${#%s}", variable->name);
\r
680 if(strstr(line2 + 2, exp))
\r
685 char slen[4] = {0};
\r
686 sprintf(slen,"%d", (int)strlen(variable->val));
\r
687 str_replace_all(&line2, exp, slen, NULL);
\r
690 str_replace_all(&line2, exp, "0", NULL);
\r
693 memset(exp, 0, VAR_NAME_MAX + 1);
\r
695 sprintf(exp, "${%s}", variable->name);
\r
697 if(strstr(line2 + 2, exp))
\r
700 str_replace_all(&line2, exp, variable->val, NULL);
\r
702 str_replace_all(&line2, exp, NULL, NULL);
\r
705 memset(exp, 0, VAR_NAME_MAX + 1);
\r
707 sprintf(exp, "$%s", variable->name);
\r
709 if((p = strstr(line2 + 2, exp)))
\r
711 if((p + strlen(variable->name) + 1)[0] != '\0' && !(isalpha((p + strlen(variable->name) + 1)[0])))
\r
712 delimiters[0] = (p + strlen(variable->name) + 1)[0];
\r
715 str_replace_all(&line2, exp, variable->val, delimiters);
\r
717 str_replace_all(&line2, exp, NULL, delimiters);
\r
720 memset(exp, 0, VAR_NAME_MAX + 1);
\r
725 while((p = strstr(line2 + 2, "${")))
\r
727 /*if(*(p+1) != '{')
\r
732 while(*(p++) != '\0')
\r
734 if(*p != ' ' && *p !='\t')
\r
741 str_replace_all(&line2, exp, NULL, " \t\n\r");
\r
742 memset(exp, 0, VAR_NAME_MAX + 1);
\r
747 char* begin = NULL;
\r
752 while(*(p++) != '\0')
\r
754 if((!begin && *p != ' ' && *p !='\t') || begin)
\r
756 /* `:' must be before this caracter, bad substitution : exit loop
\r
758 the current character is already present, bad substitution : exit loop
\r
762 *(p - 1) != ':' && (
\r
763 (*p == '=') || (*p == '-') || (*p == '+') || (*p == '?')
\r
769 (*p == ':') || (*p == '=') || (*p == '-') || (*p == '+') || (*p == '?')
\r
779 /* save the begining of the value */
\r
780 if((*(p+1) == '=') || (*(p+1) == '-') || (*(p+1) == '+') || (*(p+1) == '?'))
\r
789 /* the current char is `:' but the next is invalid, bad substitution : exit loop */
\r
792 /* end of the substitution : exit loop */
\r
800 if(exp[j - 1] == '}')
\r
807 if(4 == strlen(exp))
\r
809 xbt_os_mutex_release(unit->mutex);
\r
811 ERROR2("[%s] Bad substitution : `%s'.",filepos, strchr(line2 + 2, '$'));
\r
813 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
814 failure(fstream->unit);
\r
818 str_replace_all(&line2, exp, "0", NULL);
\r
820 else if(strstr(exp,":="))
\r
822 /* ${var:=value} */
\r
824 end = strchr(p, '}');
\r
826 if(!end || (end == begin))
\r
828 xbt_os_mutex_release(unit->mutex);
\r
831 ERROR2("[%s] Bad substitution : `%s'.",filepos, strchr(line2 + 2, '$'));
\r
833 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
834 failure(fstream->unit);
\r
838 variable = xbt_new0(s_variable_t, 1);
\r
840 variable->val = (char*) calloc((size_t)(end - begin) + 1, sizeof(char));
\r
842 strncpy(variable->val, begin ,(end - begin));
\r
845 end = strchr(exp, ':');
\r
847 if(!end || (end == begin))
\r
849 xbt_os_mutex_release(unit->mutex);
\r
852 ERROR2("[%s] Bad substitution : `%s'.",filepos, strchr(line2 + 2, '$'));
\r
854 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
855 failure(fstream->unit);
\r
859 variable->name = (char*) calloc((size_t)(end - begin) + 1, sizeof(char));
\r
861 strncpy(variable->name, exp + 2 ,(end - begin));
\r
863 str_replace_all(&line2, exp, variable->val, NULL);
\r
865 xbt_dynar_push(variables, &variable);
\r
868 else if(strstr(exp,":-"))
\r
870 /* ${var:-value} */
\r
873 end = strchr(p, '}');
\r
875 if(!end || (end == begin))
\r
877 xbt_os_mutex_release(unit->mutex);
\r
880 ERROR2("[%s] Bad substitution : `%s'.",filepos, strchr(line2 + 2, '$'));
\r
882 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
883 failure(fstream->unit);
\r
887 val = (char*) calloc((size_t)(end - begin) + 1, sizeof(char));
\r
889 strncpy(val, begin ,(end - begin));
\r
891 str_replace_all(&line2, exp, val, NULL);
\r
897 else if(strstr(exp,":+"))
\r
899 /* ${var:+value} */
\r
901 end = strchr(p, '}');
\r
903 if(!end || (end == begin))
\r
905 xbt_os_mutex_release(unit->mutex);
\r
907 ERROR2("[%s] Bad substitution : `%s'.",filepos, strchr(line2 + 2, '$'));
\r
909 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
910 failure(fstream->unit);
\r
914 str_replace_all(&line2, exp, NULL, NULL);
\r
916 else if(strstr(exp,":?"))
\r
918 /* ${var:?value} */
\r
920 end = strchr(p, '}');
\r
922 if(!end || (end == begin))
\r
924 xbt_os_mutex_release(unit->mutex);
\r
926 ERROR2("[%s] Bad substitution : `%s'.",filepos, strchr(line2 + 2, '$'));
\r
928 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
929 failure(fstream->unit);
\r
933 val = (char*) calloc((size_t)(end - begin) + 1, sizeof(char));
\r
935 strncpy(val, begin ,(end - begin));
\r
937 xbt_os_mutex_release(unit->mutex);
\r
939 ERROR2("[%s] : `%s'.",filepos, val);
\r
944 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
945 failure(fstream->unit);
\r
954 if(3 == strlen(exp))
\r
956 xbt_os_mutex_release(unit->mutex);
\r
958 ERROR2("[%s] Bad substitution : `%s'.",filepos, strchr(line2 + 2, '$'));
\r
960 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
961 failure(fstream->unit);
\r
965 str_replace_all(&line2, exp, NULL, NULL);
\r
969 memset(exp, 0, VAR_NAME_MAX + 1);
\r
973 xbt_os_mutex_release(unit->mutex);
\r
975 if(strstr(line2 + 2, "${"))
\r
976 ERROR2("[%s] Bad substitution : `%s'.",filepos, strstr(line2, "${"));
\r
978 ERROR2("[%s] Syntax error : `%s'.",filepos, strstr(line2, "${"));
\r
980 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
981 failure(fstream->unit);
\r
993 if((p = strchr(p, '$')))
\r
1000 while(*(p++) != '\0')
\r
1002 if(*p != ' ' && *p !='\t')
\r
1009 str_replace_all(&line2, exp, NULL, " \t\n\r");
\r
1010 memset(exp, 0, VAR_NAME_MAX + 1);
\r
1014 /* maybe < $ cmd */
\r
1022 xbt_os_mutex_release(unit->mutex);
\r
1033 if(line[1] != ' ')
\r
1036 if(line2[0] == '$')
\r
1037 ERROR1("[%s] Missing space after `$' `(usage : $ <command>)'", filepos);
\r
1039 ERROR1("[%s] Missing space after & `(usage : & <command>)'", filepos);
\r
1041 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1047 context->async = (line2[0] == '&');
\r
1050 /* further trim useless chars which are significant for in/output */
\r
1051 xbt_str_rtrim(line2 + 2," \t");
\r
1053 /* deal with CD commands here, not in context */
\r
1054 if(!strncmp("cd ",line2 + 2, 3))
\r
1056 char* dir = strdup(line2 + 4);
\r
1058 if(context->command_line)
\r
1060 if(fstream_launch_command(fstream, context, mutex) < 0)
\r
1064 /* search begining */
\r
1065 while(*(dir++) == ' ');
\r
1072 INFO2("[%s] cd %s", filepos, dir);
\r
1074 if(!just_print_flag)
\r
1078 ERROR3("[%s] Chdir to %s failed: %s",filepos, dir,error_to_string(errno, 0));
\r
1079 unit_set_error(fstream->unit, errno, 0, filepos);
\r
1090 fstream_process_token(fstream, context, mutex, filepos, line2[0], line2 + 2);
\r
1098 if(line[0] == '!' && line[1] != ' ')
\r
1100 ERROR1("[%s] Missing space after `!' `(usage : ! <command> [[=]value])'", filepos);
\r
1102 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1108 fstream_process_token(fstream, context, mutex, filepos, line2[0], line2 + 2);
\r
1117 char* prompt = line2 + 2;
\r
1119 for(j = 0; j < strlen(prompt); j++)
\r
1121 if (prompt[j] != ' ' && prompt[j] != '\t')
\r
1130 ERROR1("[%s] Bad usage of the metacommand p `(usage : p <prompt>)'", filepos);
\r
1132 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1139 INFO2("[%s] %s",filepos,prompt);
\r
1151 char* prompt = line2 + 2;
\r
1153 for(j = 0; j < strlen(prompt); j++)
\r
1154 if (prompt[j] != ' ' && prompt[j] != '\t')
\r
1159 ERROR1("[%s] Bad usage of the metacommand P `(usage : P <prompt>)'", filepos);
\r
1161 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1167 if(!dry_run_flag)
\r
1168 CRITICAL2("[%s] %s",filepos, prompt);
\r
1174 if(unit->description)
\r
1175 WARN2("[%s] Description already specified `%s'",filepos, line2 + 2);
\r
1181 char* desc = line2 + 2;
\r
1183 for(j = 0; j < strlen(desc); j++)
\r
1184 if (desc[j] != ' ' && desc[j] != '\t')
\r
1189 ERROR1("[%s] Bad usage of the metacommand D `(usage : D <Description>)'", filepos);
\r
1191 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1197 unit->description = strdup(desc);
\r
1202 ERROR2("[%s] Syntax error `%s'", filepos, line2);
\r
1203 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1212 fstream_process_token(fstream_t fstream, context_t context, xbt_os_mutex_t mutex, const char* filepos, char token, char *line)
\r
1214 unit_t unit = fstream->unit;
\r
1221 if(context->command_line)
\r
1224 if(context->output->used || context->input->used)
\r
1226 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
1228 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1233 if(fstream_launch_command(fstream, context, mutex) < 0)
\r
1236 VERB1("[%s] More than one command in this chunk of lines",filepos);
\r
1243 for(j = 0; j < strlen(line); j++)
\r
1244 if (line[j] != ' ' && line[j] != '\t')
\r
1250 ERROR1("[%s] Undefinite command for `$' `(usage: $ <command>)'", filepos);
\r
1252 ERROR1("[%s] Undefinite command for `&' `(usage: & <command>)'", filepos);
\r
1254 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1261 context->command_line = strdup(line);
\r
1263 xbt_str_ltrim(context->command_line," ");
\r
1265 context->line = /*strdup(filepos)*/ filepos;
\r
1266 context->pos = strdup(filepos);
\r
1271 /* translate the command line */
\r
1273 char* path = NULL;
\r
1275 char command_line[PATH_MAX + 1] = {0};
\r
1277 char* args = NULL;
\r
1281 /*if(strstr(context->command_line,".exe"))
\r
1282 strcpy(command_line,context->command_line);*/
\r
1289 len = strlen(context->command_line);
\r
1293 if(context->command_line[i] != ' ' && context->command_line[i] != '\t' && context->command_line[i] != '>')
\r
1294 command_line[j++] = context->command_line[i];
\r
1301 if(!strstr(context->command_line,".exe"))
\r
1302 strcat(command_line,".exe");
\r
1304 args = strdup(context->command_line + i);
\r
1307 if(!is_w32_cmd(command_line, fstream->unit->runner->path) && getpath(command_line, &path) < 0)
\r
1309 ERROR3("[%s] `%s' : NOK (%s)", filepos, command_line, error_to_string(ECMDNOTFOUND, 1));
\r
1310 unit_set_error(fstream->unit, ECMDNOTFOUND, 1, filepos);
\r
1315 delimiter = strrchr(command_line,'/');
\r
1318 delimiter = strrchr(command_line,'\\');
\r
1320 /*free(context->command_line);*/
\r
1327 context->t_command_line = (char*)calloc(strlen(path) + strlen(delimiter ? delimiter + 1 : command_line) + strlen(args) + 2, sizeof(char));
\r
1328 sprintf(context->t_command_line,"%s\\%s%s",path,delimiter ? delimiter + 1 : command_line, args);
\r
1335 context->t_command_line = (char*)calloc(strlen(path) + strlen(delimiter ? delimiter + 1 : command_line) + 2, sizeof(char));
\r
1336 sprintf(context->t_command_line,"%s\\%s",path,delimiter ? delimiter + 1 : command_line);
\r
1346 context->t_command_line = (char*)calloc(strlen(command_line) + strlen(args) + 1, sizeof(char));
\r
1347 sprintf(context->t_command_line,"%s%s",command_line, args);
\r
1355 context->t_command_line = (char*)calloc(strlen(command_line) + 1, sizeof(char));
\r
1356 strcpy(context->t_command_line,command_line);
\r
1368 xbt_strbuff_append(context->input,line);
\r
1369 xbt_strbuff_append(context->input,"\n");
\r
1373 xbt_strbuff_append(context->output,line);
\r
1374 xbt_strbuff_append(context->output,"\n");
\r
1379 if(context->command_line)
\r
1381 if(fstream_launch_command(fstream, context, mutex) < 0)
\r
1385 if(!strncmp(line,"timeout no",strlen("timeout no")))
\r
1387 VERB1("[%s] (disable timeout)", filepos);
\r
1388 context->timeout = INDEFINITE;
\r
1390 else if(!strncmp(line,"timeout ",strlen("timeout ")))
\r
1395 char* p = line + strlen("timeout ");
\r
1398 for(j = 0; j < strlen(p); j++)
\r
1399 if (p[j] != ' ' && p[j] != '\t')
\r
1404 ERROR1("[%s] Undefinite timeout value `(usage :timeout <seconds>)'", filepos);
\r
1406 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1412 while(p[i] != '\0')
\r
1414 if(!isdigit(p[i]))
\r
1416 ERROR2("[%s] Invalid timeout value `(%s)' : `(usage :timeout <seconds>)'", filepos, line + strlen("timeout "));
\r
1418 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1427 context->timeout = atoi(line + strlen("timeout"));
\r
1428 VERB2("[%s] (new timeout value: %d)",filepos,context->timeout);
\r
1431 else if (!strncmp(line,"expect signal ",strlen("expect signal ")))
\r
1437 char* p = line + strlen("expect signal ");
\r
1440 for(j = 0; j < strlen(p); j++)
\r
1441 if (p[j] != ' ' && p[j] != '\t')
\r
1446 ERROR1("[%s] Undefinite signal name `(usage :expect signal <signal name>)'", filepos);
\r
1448 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1454 context->signal = strdup(line + strlen("expect signal "));
\r
1456 xbt_str_trim(context->signal," \n");
\r
1459 if(!strstr("SIGSEGVSIGTRAPSIGBUSSIGFPESIGILL", context->signal))
\r
1461 ERROR2("[%s] Signal `%s' not supported by this platform", filepos, context->signal);
\r
1463 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1470 if(!sig_exists(context->signal))
\r
1472 ERROR2("[%s] Signal `%s' not supported by Tesh", filepos, context->signal);
\r
1474 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1484 VERB2("[%s] (next command must raise signal %s)", filepos, context->signal);
\r
1487 else if (!strncmp(line,"expect return ",strlen("expect return ")))
\r
1493 char* p = line + strlen("expect return ");
\r
1496 for(j = 0; j < strlen(p); j++)
\r
1497 if (p[j] != ' ' && p[j] != '\t')
\r
1502 ERROR1("[%s] Undefinite return value `(usage :expect return <return value>)'", filepos);
\r
1504 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1510 while(p[i] != '\0')
\r
1512 if(!isdigit(p[i]))
\r
1514 ERROR2("[%s] Invalid exit code value `(%s)' : must be an integer >= 0 and <=255", filepos, line + strlen("expect return "));
\r
1516 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1525 context->exit_code = atoi(line+strlen("expect return "));
\r
1526 VERB2("[%s] (next command must return code %d)",filepos, context->exit_code);
\r
1529 else if (!strncmp(line,"output ignore",strlen("output ignore")))
\r
1531 context->output_handling = oh_ignore;
\r
1532 VERB1("[%s] (ignore output of next command)", filepos);
\r
1535 else if (!strncmp(line,"output display",strlen("output display")))
\r
1537 context->output_handling = oh_display;
\r
1538 VERB1("[%s] (ignore output of next command)", filepos);
\r
1541 else if(!strncmp(line,"include ", strlen("include ")))
\r
1546 p1 = line + strlen("include");
\r
1548 while(*p1 == ' ' || *p1 == '\t')
\r
1554 ERROR1("[%s] no file specified : `(usage : include <file> [<description>])'", filepos);
\r
1556 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1563 char file_name[PATH_MAX + 1] = {0};
\r
1567 while(*p2 != '\0' && *p2 != ' ' && *p2 != '\t')
\r
1570 strncpy(file_name, p1, p2 - p1);
\r
1574 while(*p2 == ' ' || *p2 == '\t')
\r
1577 fstream_handle_include(fstream, context, mutex, file_name, p2[0] != '\0' ? p2 : NULL);
\r
1581 else if(!strncmp(line,"suite ", strlen("suite ")))
\r
1585 char* p = line + strlen("suite ");
\r
1588 for(j = 0; j < strlen(p); j++)
\r
1589 if (p[j] != ' ' && p[j] != '\t')
\r
1594 ERROR1("[%s] Undefinite suit description : `(usage : suite <description>)", filepos);
\r
1596 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1602 if(unit->is_running_suite)
\r
1604 ERROR1("[%s] Suite already in progress", filepos);
\r
1606 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1612 fstream_handle_suite(fstream, line + strlen("suite "), filepos);
\r
1614 else if(!strncmp(line,"unsetenv ", strlen("unsetenv ")))
\r
1616 unsigned int i, j;
\r
1620 variable_t variable;
\r
1623 char* name = line + strlen("unsetenv ");
\r
1627 for(j = 0; j < strlen(name); j++)
\r
1628 if (name[j] != ' ' && name[j] != '\t')
\r
1633 ERROR1("[%s] Bad usage of the metacommand unsetenv : `(usage : unsetenv variable)'", filepos);
\r
1635 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1641 xbt_os_mutex_acquire(unit->mutex);
\r
1644 xbt_dynar_foreach(unit->runner->variables, i, variable)
\r
1646 if(!strcmp(variable->name, name))
\r
1648 env = variable->env;
\r
1649 err = variable->err;
\r
1662 SetEnvironmentVariable(name, NULL);
\r
1664 xbt_dynar_cursor_rm(unit->runner->variables, &i);
\r
1668 ERROR2("[%s] `(%s)' environment variable not found : impossible to unset it",filepos, name);
\r
1669 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1670 xbt_os_mutex_release(unit->mutex);
\r
1681 ERROR2("[%s] `(%s)' is not an environment variable : use `unset' instead `unsetenv'",filepos, name);
\r
1682 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1684 xbt_os_mutex_release(unit->mutex);
\r
1689 ERROR2("[%s] `(%s)' is not an environment variable (it's a system variable) : impossible to unset it",filepos, name);
\r
1690 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1691 xbt_os_mutex_release(unit->mutex);
\r
1698 ERROR2("[%s] `(%s)' environment variable not found : impossible to unset it",filepos, name);
\r
1699 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1700 xbt_os_mutex_release(unit->mutex);
\r
1706 xbt_os_mutex_release(unit->mutex);
\r
1710 else if(!strncmp(line,"setenv ", strlen("setenv ")))
\r
1713 char name[PATH_MAX + 1] = {0};
\r
1719 p = line + strlen("setenv ");
\r
1721 val = strchr(p, '=');
\r
1725 variable_t variable;
\r
1731 /* syntax error */
\r
1732 if(val[0] == '\0' || val[0] ==' ' || val[0] =='\t')
\r
1734 ERROR1("[%s] Bad usage of the metacommand setenv `(usage : setenv variable=value)'", filepos);
\r
1736 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1744 strncpy(name, p, (val - p -1));
\r
1748 for(j = 0; j < strlen(name); j++)
\r
1749 if (name[j] != ' ' && name[j] != '\t')
\r
1755 ERROR1("[%s] Bad usage of the metacommand setenv `(usage : setenv variable=value)'", filepos);
\r
1757 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1763 /* test if the variable is already registred */
\r
1764 xbt_os_mutex_acquire(unit->mutex);
\r
1766 xbt_dynar_foreach(unit->runner->variables, i, variable)
\r
1768 if(!strcmp(variable->name, name))
\r
1770 env = variable->env;
\r
1771 err = variable->err;
\r
1777 /* if the variable is already registred, update its value;
\r
1778 * otherwise register it.
\r
1784 if(!strcmp(val, variable->val))
\r
1785 WARN3("[%s] This environment variable `(%s)' is already set with the value `(%s)'", filepos, name, val);
\r
1787 free(variable->val);
\r
1788 variable->val = strdup(val);
\r
1791 SetEnvironmentVariable(variable->name, variable->val);
\r
1793 setenv(variable->name, variable->val, 1);
\r
1799 ERROR2("[%s] Conflict : a system variable `(%s)' already exists", filepos, name);
\r
1801 ERROR2("[%s] Conflict : (none environment) variable `(%s)' already exists", filepos, name);
\r
1803 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1804 xbt_os_mutex_release(unit->mutex);
\r
1813 ERROR2("[%s] A system variable named `(%s)' already exists", filepos, name);
\r
1815 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1816 xbt_os_mutex_release(unit->mutex);
\r
1822 variable = variable_new(name, val);
\r
1823 variable->env = 1;
\r
1825 xbt_dynar_push(unit->runner->variables, &variable);
\r
1828 SetEnvironmentVariable(variable->name, variable->val);
\r
1830 setenv(variable->name, variable->val, 0);
\r
1835 xbt_os_mutex_release(unit->mutex);
\r
1840 ERROR1("[%s] Bad usage of the metacommand setenv `(usage : setenv variable=value)'", filepos);
\r
1842 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1847 else if(!strncmp(line,"unset ", strlen("unset ")))
\r
1849 unsigned int i, j;
\r
1853 variable_t variable;
\r
1856 char* name = line + strlen("unset ");
\r
1860 for(j = 0; j < strlen(name); j++)
\r
1861 if (name[j] != ' ' && name[j] != '\t')
\r
1867 ERROR1("[%s] Bad usage of the metacommand unset `(usage : unset variable)'", filepos);
\r
1869 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1876 xbt_os_mutex_acquire(unit->mutex);
\r
1878 xbt_dynar_foreach(unit->runner->variables, i, variable)
\r
1880 if(!strcmp(variable->name, name))
\r
1882 env = variable->env;
\r
1883 err = variable->err;
\r
1893 /*xbt_dynar_remove_at(unit->runner->variables, i, NULL);*/
\r
1894 /*xbt_dynar_cursor_rm(unit->runner->variables, &i);*/
\r
1897 free(variable->val);
\r
1898 variable->val = NULL;
\r
1902 WARN2("[%s] Variable `(%s)' already unseted",filepos, variable->name);
\r
1907 ERROR2("[%s] `(%s)' variable not found",filepos, name);
\r
1908 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1909 xbt_os_mutex_release(unit->mutex);
\r
1916 ERROR2("[%s] `(%s)' is an environment variable use `unsetenv' instead `unset'",filepos, name);
\r
1917 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1918 xbt_os_mutex_release(unit->mutex);
\r
1924 ERROR2("[%s] `(%s)' is system variable : you can unset it",filepos, name);
\r
1925 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1926 xbt_os_mutex_release(unit->mutex);
\r
1931 xbt_os_mutex_release(unit->mutex);
\r
1934 else if(!strncmp(line,"set ", strlen("set ")))
\r
1937 char name[PATH_MAX + 1] = {0};
\r
1941 val = strchr(line + strlen("set "), '=');
\r
1945 variable_t variable;
\r
1954 /* syntax error */
\r
1955 if(val[0] == '\0')
\r
1957 ERROR1("[%s] Bad usage of the metacommand set `(usage : set variable=value)'", filepos);
\r
1959 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1964 else if(val[0] ==' ' || val[0] =='\t')
\r
1966 strncpy(name, line + strlen("set "), (val - (line + strlen("set "))));
\r
1968 ERROR2("[%s] No space avaible after`(%s)'", filepos, name);
\r
1970 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1977 /* assume it's a varibale */
\r
1979 strncpy(name, line + strlen("set "), (val - (line + strlen("set ")) -1));
\r
1983 for(j = 0; j < strlen(name); j++)
\r
1984 if (name[j] != ' ' && name[j] != '\t')
\r
1990 ERROR1("[%s] Bad usage of the metacommand set `(usage : set variable=value)'", filepos);
\r
1992 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
1998 xbt_os_mutex_acquire(unit->mutex);
\r
2000 /* test if the variable is already registred */
\r
2001 xbt_dynar_foreach(unit->runner->variables, i, variable)
\r
2003 if(!strcmp(variable->name, name))
\r
2006 err = variable->err;
\r
2007 env = variable->env;
\r
2012 /* if the variable is already registred, update its value (if same value warns);
\r
2013 * otherwise register it.
\r
2019 ERROR2("[%s] A system variable named `(%s)' already exists", filepos, name);
\r
2021 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
2022 xbt_os_mutex_release(unit->mutex);
\r
2029 ERROR2("[%s] `(%s)' is an environment variable use `setenv' instead `set'", filepos, name);
\r
2031 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
2032 xbt_os_mutex_release(unit->mutex);
\r
2039 if(!strcmp(val, variable->val))
\r
2040 WARN3("[%s] Variable `(%s)' already contains value `<%s>'",filepos, variable->name, val);
\r
2042 free(variable->val);
\r
2043 variable->val = strdup(val);
\r
2048 variable_t new_var = variable_new(name, val);
\r
2049 xbt_dynar_push(unit->runner->variables, &new_var);
\r
2053 xbt_os_mutex_release(unit->mutex);
\r
2057 ERROR1("[%s] Bad usage of the metacommand set `(usage : set variable=value)'", filepos);
\r
2059 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
2065 {/* assume it's a variable */
\r
2067 char name[PATH_MAX + 1] = {0};
\r
2068 unsigned int i, j;
\r
2071 val = strchr(line, '=');
\r
2075 variable_t variable;
\r
2082 /* syntax error */
\r
2083 if(val[0] == '\0')
\r
2085 strncpy(name, line, (val - line -1));
\r
2089 for(j = 0; j < strlen(name); j++)
\r
2090 if (name[j] != ' ' && name[j] != '\t')
\r
2094 ERROR1("[%s] Bad usage of Tesh variable mechanism `(usage : variable=value)'", filepos);
\r
2095 else if(!strcmp("setenv", name))
\r
2096 ERROR1("[%s] Bad usage of the metacommand setenv `(usage : setenv variable=value)'", filepos);
\r
2097 else if(!strcmp("set", name))
\r
2098 ERROR1("[%s] Bad usage of the metacommand set `(usage : set variable=value)'", filepos);
\r
2100 ERROR2("[%s] Undefined variable `(%s)'", filepos, name);
\r
2102 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
2107 else if(val[0] ==' ' || val[0] =='\t')
\r
2109 strncpy(name, line, (val - line));
\r
2111 ERROR2("[%s] No space avaible after`(%s)'", filepos, name);
\r
2113 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
2119 /* assume it's a varibale */
\r
2121 strncpy(name, line, (val - line -1));
\r
2125 for(j = 0; j < strlen(name); j++)
\r
2126 if (name[j] != ' ' && name[j] != '\t')
\r
2132 ERROR1("[%s] Bad usage of Tesh variable capability `(usage : variable=value)'", filepos);
\r
2134 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
2140 if(!strcmp("set", name))
\r
2142 ERROR1("[%s] Bad usage of the metacommand set `(usage : set variable=value)'", filepos);
\r
2144 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
2148 else if(!strcmp("setenv", name))
\r
2150 ERROR1("[%s] Bad usage of the metacommand setenv `(usage : setenv variable=value)'", filepos);
\r
2152 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
2157 xbt_os_mutex_acquire(unit->mutex);
\r
2159 /* test if the variable is already registred */
\r
2160 xbt_dynar_foreach(unit->runner->variables, i, variable)
\r
2162 if(!strcmp(variable->name, name))
\r
2165 err = variable->err;
\r
2166 env = variable->env;
\r
2171 /* if the variable is already registred, update its value (if same value warns);
\r
2172 * otherwise register it.
\r
2178 ERROR2("[%s] A system variable named `(%s)' already exists", filepos, name);
\r
2180 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
2181 xbt_os_mutex_release(unit->mutex);
\r
2187 ERROR2("[%s] `(%s)' is an environment variable use `setenv' metacommand", filepos, name);
\r
2189 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
2190 xbt_os_mutex_release(unit->mutex);
\r
2197 if(!strcmp(val, variable->val))
\r
2198 WARN3("[%s] Variable `(%s)' already contains value `<%s>'",filepos, variable->name, val);
\r
2200 free(variable->val);
\r
2201 variable->val = strdup(val);
\r
2206 variable_t new_var = variable_new(name, val);
\r
2207 xbt_dynar_push(unit->runner->variables, &new_var);
\r
2211 xbt_os_mutex_release(unit->mutex);
\r
2216 if(!strncmp("setenv", line, strlen("setenv")))
\r
2217 ERROR1("[%s] Bad usage of the metacommand setenv : `(usage : setenv variable=value)'", filepos);
\r
2218 else if(!strncmp("set", line, strlen("set")))
\r
2219 ERROR1("[%s] Bad usage of the metacommand set : `(usage : set variable=value)'", filepos);
\r
2220 else if(!strncmp("unsetenv", line, strlen("unsetenv")))
\r
2221 ERROR1("[%s] Bad usage of the metacommand unsetenv : `(usage : unsetenv variable)'", filepos);
\r
2222 else if(!strncmp("unset", line, strlen("unset")))
\r
2223 ERROR1("[%s] Bad usage of the metacommand unset : `(usage : unset variable)'", filepos);
\r
2224 else if(!strncmp("timeout", line, strlen("timeout")))
\r
2225 ERROR1("[%s] Bad usage of the metacommand timeout : `(usage : timeout <integral positive integer>)'", filepos);
\r
2226 else if(!strncmp("expect signal", line, strlen("expect signal")))
\r
2227 ERROR1("[%s] Bad usage of the metacommand expect signal : `(usage : expect signal <sig_name>)'", filepos);
\r
2228 else if(!strncmp("expect return", line, strlen("expect return")))
\r
2229 ERROR1("[%s] Bad usage of the metacommand expect return : `(usage : expect return <return value (>=0 <=255)>)'", filepos);
\r
2230 else if(!strncmp("include", line, strlen("include")))
\r
2231 ERROR1("[%s] Bad usage of the metacommand include :`(usage : include <file> [<description>])'", filepos);
\r
2232 else if(!strncmp("suite", line, strlen("suite")))
\r
2233 ERROR1("[%s] Bad usage of the metacommand suite : `(usage : suite <description>)'", filepos);
\r
2235 ERROR2("[%s] Unknown metacommand: `%s'",filepos,line);
\r
2237 unit_set_error(fstream->unit, ESYNTAX, 1, filepos);
\r
2249 fstream_handle_include(fstream_t fstream, context_t context, xbt_os_mutex_t mutex, const char* file_name, const char* description)
\r
2252 char* prev_directory = NULL;
\r
2253 fstream_t _fstream = NULL;
\r
2254 struct stat buffer = {0};
\r
2255 unit_t unit = fstream->unit;
\r
2257 if(!stat(file_name, &buffer) && S_ISREG(buffer.st_mode))
\r
2259 /* the file is in the current directory */
\r
2260 _fstream = fstream_new(getcwd(NULL, 0), file_name);
\r
2261 fstream_open(_fstream);
\r
2263 /* the file to include is not in the current directory, check if it is in a include directory */
\r
2267 prev_directory = getcwd(NULL, 0);
\r
2269 xbt_dynar_foreach(include_dirs, i, dir)
\r
2273 if(!stat(file_name, &buffer) && S_ISREG(buffer.st_mode))
\r
2275 _fstream = fstream_new(dir->name, file_name);
\r
2276 fstream_open(_fstream);
\r
2281 chdir(prev_directory);
\r
2282 free(prev_directory);
\r
2285 /* the file to include is not found handle the failure */
\r
2288 if(file_name[0] == '$')
\r
2290 ERROR3("[%s] Include file `(%s)' not found or variable `(%s)' doesn't exist",context->line, file_name, file_name + 1);
\r
2295 /* may be a variable */
\r
2296 variable_t variable;
\r
2300 xbt_dynar_foreach(unit->runner->variables, i, variable)
\r
2302 if(!strcmp(variable->name, file_name))
\r
2310 ERROR3("[%s] Include file `(%s)' not found (if you want to use the variable <%s> add the prefix `$')",context->line, file_name, file_name);
\r
2312 ERROR2("[%s] Include file `(%s)' not found",context->line, file_name);
\r
2315 unit_set_error(fstream->unit, EINCLUDENOTFOUND, 1, context->line);
\r
2317 failure(fstream->unit);
\r
2323 if(!unit->is_running_suite)
\r
2324 {/* it's the unit of a suite */
\r
2325 unit_t include = unit_new(unit->runner, unit->root, unit, _fstream);
\r
2327 include->mutex = unit->root->mutex;
\r
2330 include->description = strdup(description);
\r
2332 xbt_dynar_push(unit->includes, &include);
\r
2337 INFO2("Include from %s (%s)", _fstream->name, description);
\r
2339 INFO1("Include from %s", _fstream->name);
\r
2343 INFO1("Checking include %s...",_fstream->name);
\r
2345 fstream_parse(_fstream, mutex);
\r
2348 {/* it's a include */
\r
2353 owner = xbt_dynar_get_ptr(unit->suites, xbt_dynar_length(unit->suites) - 1);
\r
2355 include = unit_new(unit->runner, unit->root, *owner, _fstream);
\r
2357 include->mutex = unit->root->mutex;
\r
2360 include->description = strdup(description);
\r
2362 xbt_dynar_push((*owner)->includes, &include);
\r
2367 INFO2("Include from %s (%s)", _fstream->name, description);
\r
2369 INFO1("Include from %s", _fstream->name);
\r
2372 INFO1("Checking include %s...",_fstream->name);
\r
2374 fstream_parse(_fstream, mutex);
\r
2380 fstream_handle_suite(fstream_t fstream, const char* description, const char* filepos)
\r
2382 unit_t unit = fstream->unit;
\r
2383 unit_t suite = unit_new(unit->runner, unit->root, unit, NULL);
\r
2386 suite->description = strdup(description);
\r
2388 suite->filepos = strdup(filepos);
\r
2390 xbt_dynar_push(unit->suites, &suite);
\r
2391 unit->is_running_suite = 1;
\r
2394 INFO1("Test suite %s", description);
\r
2396 INFO1("Checking suite %s...",description);
\r
2401 fstream_launch_command(fstream_t fstream, context_t context, xbt_os_mutex_t mutex)
\r
2403 unit_t unit = fstream->unit;
\r
2407 command_t command;
\r
2409 if(!(command = command_new(unit, context, mutex)))
\r
2411 if(EINVAL == errno)
\r
2413 ERROR3("[%s] Cannot instantiate the command `%s' (%d)",context->pos, strerror(errno), errno);
\r
2415 unit_set_error(unit, errno, 0, context->pos);
\r
2419 else if(ENOMEM == errno)
\r
2421 ERROR3("[%s] Cannot instantiate the command `%s' (%d)",context->pos, strerror(errno), errno);
\r
2423 unit_set_error(unit, errno, 0, context->pos);
\r
2430 if(command_run(command) < 0)
\r
2432 ERROR3("[%s] Cannot run the command `%s' (%d)",context->pos, strerror(errno), errno);
\r
2433 unit_set_error(unit, errno, 0, context->pos);
\r
2439 if(context_reset(context) < 0)
\r
2441 ERROR3("[%s] Cannot reset the context of the command `%s' (%d)",context->pos, strerror(errno), errno);
\r
2443 unit_set_error(fstream->unit, errno, 0, context->pos);
\r