7 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh);
10 fstream_new(const char* directory, const char* name)
20 if(!directory && !strcmp("stdin", name))
22 fstream = xbt_new0(s_fstream_t, 1);
23 fstream->name = strdup("stdin");
32 fstream = xbt_new0(s_fstream_t, 1);
34 fstream->name = strdup(name);
36 fstream->directory = strdup(directory);
37 fstream->stream = NULL;
44 fstream_open(fstream_t fstream)
46 char path[MAX_PATH] = {0};
48 if(!fstream || fstream->stream)
51 if(!strcmp(fstream->name, "stdin"))
53 fstream->stream = stdin;
57 sprintf(path,"%s/%s",fstream->directory, fstream->name);
59 if(!(fstream->stream = fopen(path, "r")))
66 fstream_close(fstream_t fstream)
68 if(!fstream || !strcmp(fstream->name, "stdin"))
74 fclose(fstream->stream);
75 fstream->stream = NULL;
80 fstream_free(void** fstreamptr)
85 if((*((fstream_t*)fstreamptr))->stream)
86 fclose((*((fstream_t*)fstreamptr))->stream);
88 free((*((fstream_t*)fstreamptr))->name);
90 if((*((fstream_t*)fstreamptr))->directory)
91 free((*((fstream_t*)fstreamptr))->directory);
102 fstream_parse(fstream_t fstream, unit_t unit, xbt_os_mutex_t mutex)
112 /* Count the line length while checking wheather it's blank */
115 /* Deal with \ at the end of the line, and call handle_line on result */
118 buff=xbt_strbuff_new();
119 context = context_new();
121 while(!(unit->root->interrupted) && getline(&line, &len, fstream->stream) != -1)
130 while(line[linelen] != '\0')
132 if (line[linelen] != ' ' && line[linelen] != '\t' && line[linelen]!='\n' && line[linelen]!='\r')
140 if(!context->command_line && (context->input->used || context->output->used))
142 ERROR1("[%d] Error: no command found in this chunk of lines.",buffbegin);
143 ERROR1("Unit `%s': NOK (syntax error)", fstream->name);
147 unit_handle_failure(unit);
150 else if(unit->running_suite)
151 unit->running_suite = 0;
154 if(context->command_line)
158 command_t command = command_new(unit, context, mutex);
159 command_run(command);
163 context_reset(context);
169 if(linelen>1 && line[linelen-2]=='\\')
171 if(linelen>2 && line[linelen-3] == '\\')
173 /* Damn. Escaped \ */
174 line[linelen-2] = '\n';
175 line[linelen-1] = '\0';
180 line[linelen-2] = '\0';
184 buffbegin = line_num;
188 if(buff->used || to_be_continued)
190 xbt_strbuff_append(buff,line);
192 if (!to_be_continued)
194 snprintf(file_pos,256,"%s:%d",fstream->name, buffbegin);
195 unit_handle_line(unit, context, mutex, file_pos, buff->data);
196 xbt_strbuff_empty(buff);
201 snprintf(file_pos,256,"%s:%d",fstream->name, line_num);
202 unit_handle_line(unit, context, mutex, file_pos, line);
208 /* Check that last command of the file ran well */
209 if(context->command_line)
213 command_t command = command_new(unit, context, mutex);
214 command_run(command);
217 context_reset(context);
226 xbt_strbuff_free(buff);
227 context_free(&context);