Skip to content

Commit

Permalink
Fix include subcommand (#104)
Browse files Browse the repository at this point in the history
Signed-off-by: David P. Chassin <dchassin@slac.stanford.edu>
Signed-off-by: David P. Chassin <david.chassin@me.com>
  • Loading branch information
David P. Chassin authored and dchassin committed Oct 18, 2023
1 parent a2dbc97 commit d070d05
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
21 changes: 21 additions & 0 deletions source/autotest/test_include_subcommand.glm
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifexist ../test_include_subcommand.txt
#define DIR=..
#endif

#option verbose

#include (cat ${DIR:-.}/test_include_subcommand.txt)

module assert;

object test
{
x 12;
z 12+2j;
object assert {
status TRUE;
target x;
relation ==;
value 12;
};
}
5 changes: 5 additions & 0 deletions source/autotest/test_include_subcommand.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class test
{
double x;
complex z;
}
14 changes: 10 additions & 4 deletions source/load.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7793,10 +7793,16 @@ int GldLoader::process_macro(char *line, int size, char *_filename, int linenum)
else if (sscanf(term, "(%[^)])", value) == 1)
{
/* C include file */
IN_MYCONTEXT output_verbose("executing include shell \"%s\"", value);
my_instance->subcommand("%s",value);
// TODO: insert stdout here
strcpy(line,"\n");
IN_MYCONTEXT output_verbose("%s(%d): executing include shell command [%s]", filename, linenum, value);
FILE *out = NULL, *err = NULL;
struct s_pipes *pipes = popens(value, NULL, &out, &err);
if ( pipes == NULL )
{
output_error("process_macro(char *line, int size=%d, char *_filename='%s', int linenum=%d): unable to create pipes",size,_filename,linenum);
return FALSE;
}
ppolls(pipes,line,size-1,output_get_stream("error"));
pcloses(pipes);
return TRUE;
}
else
Expand Down

0 comments on commit d070d05

Please sign in to comment.