Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Dynare
preprocessor
Commits
c209c1cd
Commit
c209c1cd
authored
Mar 29, 2011
by
Houtan Bastani
Browse files
implement the possibility of passing macro-processor defines on the command-line (ticket 171)
parent
be4c5c92
Changes
3
Hide whitespace changes
Inline
Side-by-side
DynareMain.cc
View file @
c209c1cd
...
...
@@ -46,7 +46,8 @@ void
usage
()
{
cerr
<<
"Dynare usage: dynare mod_file [debug] [noclearall] [savemacro[=macro_file]] [onlymacro] [nolinemacro] [notmpterms] [warn_uninit]"
<<
" [console] [parallel[=cluster_name]] [conffile=parallel_config_path_and_filename] [parallel_slave_open_mode] [parallel_test]"
<<
" [console] [parallel[=cluster_name]] [conffile=parallel_config_path_and_filename] [parallel_slave_open_mode] [parallel_test] "
<<
" [-D<variable>[=<value>]]"
#if defined(_WIN32) || defined(__CYGWIN32__)
<<
" [cygwin] [msvc]"
#endif
...
...
@@ -81,6 +82,7 @@ main(int argc, char **argv)
string
cluster_name
;
bool
parallel_slave_open_mode
=
false
;
bool
parallel_test
=
false
;
map
<
string
,
string
>
defines
;
// Parse options
for
(
int
arg
=
2
;
arg
<
argc
;
arg
++
)
...
...
@@ -144,6 +146,27 @@ main(int argc, char **argv)
cluster_name
=
string
(
argv
[
arg
]
+
9
);
}
}
else
if
(
strlen
(
argv
[
arg
])
>=
2
&&
!
strncmp
(
argv
[
arg
],
"-D"
,
2
))
{
if
(
strlen
(
argv
[
arg
])
==
2
)
{
cerr
<<
"Incorrect syntax for command line define: the defined variable "
<<
"must not be separated from -D by whitespace."
<<
endl
;
usage
();
}
size_t
equal_index
=
string
(
argv
[
arg
]).
find
(
'='
);
if
(
equal_index
!=
string
::
npos
)
{
string
key
=
string
(
argv
[
arg
]).
erase
(
equal_index
).
erase
(
0
,
2
);
defines
[
key
]
=
string
(
argv
[
arg
]).
erase
(
0
,
equal_index
+
1
);
}
else
{
string
key
=
string
(
argv
[
arg
]).
erase
(
0
,
2
);
defines
[
key
]
=
"1"
;
}
}
else
{
cerr
<<
"Unknown option: "
<<
argv
[
arg
]
<<
endl
;
...
...
@@ -164,7 +187,7 @@ main(int argc, char **argv)
MacroDriver
m
;
stringstream
macro_output
;
m
.
parse
(
argv
[
1
],
macro_output
,
debug
,
no_line_macro
);
m
.
parse
(
argv
[
1
],
macro_output
,
debug
,
no_line_macro
,
defines
);
if
(
save_macro
)
{
if
(
save_macro_file
.
empty
())
...
...
macro/MacroDriver.cc
View file @
c209c1cd
...
...
@@ -36,7 +36,7 @@ MacroDriver::~MacroDriver()
}
void
MacroDriver
::
parse
(
const
string
&
f
,
ostream
&
out
,
bool
debug
,
bool
no_line_macro
)
MacroDriver
::
parse
(
const
string
&
f
,
ostream
&
out
,
bool
debug
,
bool
no_line_macro
,
map
<
string
,
string
>
defines
)
{
file
=
f
;
...
...
@@ -53,6 +53,9 @@ MacroDriver::parse(const string &f, ostream &out, bool debug, bool no_line_macro
an @#endif or an @#endfor - but no newline - no longer trigger an error.
*/
stringstream
file_with_endl
;
for
(
map
<
string
,
string
>::
iterator
it
=
defines
.
begin
();
it
!=
defines
.
end
();
it
++
)
file_with_endl
<<
"@#define "
<<
it
->
first
<<
" = "
<<
it
->
second
<<
endl
;
file_with_endl
<<
in
.
rdbuf
()
<<
endl
;
lexer
=
new
MacroFlex
(
&
file_with_endl
,
&
out
,
no_line_macro
);
...
...
macro/MacroDriver.hh
View file @
c209c1cd
...
...
@@ -176,7 +176,7 @@ public:
//! Starts parsing a file, returns output in out
/*! \param no_line_macro should we omit the @#line statements ? */
void
parse
(
const
string
&
f
,
ostream
&
out
,
bool
debug
,
bool
no_line_macro
);
void
parse
(
const
string
&
f
,
ostream
&
out
,
bool
debug
,
bool
no_line_macro
,
map
<
string
,
string
>
defines
);
//! Name of main file being parsed
string
file
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment