Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
dynare
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Frédéric Karamé
dynare
Commits
c42c6750
Commit
c42c6750
authored
Mar 29, 2011
by
Houtan Bastani
Browse files
Options
Downloads
Patches
Plain Diff
implement the possibility of passing macro-processor defines on the command-line (ticket 171)
parent
3e92f410
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
preprocessor/DynareMain.cc
+25
-2
25 additions, 2 deletions
preprocessor/DynareMain.cc
preprocessor/macro/MacroDriver.cc
+4
-1
4 additions, 1 deletion
preprocessor/macro/MacroDriver.cc
preprocessor/macro/MacroDriver.hh
+1
-1
1 addition, 1 deletion
preprocessor/macro/MacroDriver.hh
with
30 additions
and
4 deletions
preprocessor/DynareMain.cc
+
25
−
2
View file @
c42c6750
...
@@ -47,6 +47,7 @@ usage()
...
@@ -47,6 +47,7 @@ usage()
{
{
cerr
<<
"Dynare usage: dynare mod_file [debug] [noclearall] [savemacro[=macro_file]] [onlymacro] [nolinemacro] [notmpterms] [warn_uninit]"
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__)
#if defined(_WIN32) || defined(__CYGWIN32__)
<<
" [cygwin] [msvc]"
<<
" [cygwin] [msvc]"
#endif
#endif
...
@@ -81,6 +82,7 @@ main(int argc, char **argv)
...
@@ -81,6 +82,7 @@ main(int argc, char **argv)
string
cluster_name
;
string
cluster_name
;
bool
parallel_slave_open_mode
=
false
;
bool
parallel_slave_open_mode
=
false
;
bool
parallel_test
=
false
;
bool
parallel_test
=
false
;
map
<
string
,
string
>
defines
;
// Parse options
// Parse options
for
(
int
arg
=
2
;
arg
<
argc
;
arg
++
)
for
(
int
arg
=
2
;
arg
<
argc
;
arg
++
)
...
@@ -144,6 +146,27 @@ main(int argc, char **argv)
...
@@ -144,6 +146,27 @@ main(int argc, char **argv)
cluster_name
=
string
(
argv
[
arg
]
+
9
);
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
else
{
{
cerr
<<
"Unknown option: "
<<
argv
[
arg
]
<<
endl
;
cerr
<<
"Unknown option: "
<<
argv
[
arg
]
<<
endl
;
...
@@ -164,7 +187,7 @@ main(int argc, char **argv)
...
@@ -164,7 +187,7 @@ main(int argc, char **argv)
MacroDriver
m
;
MacroDriver
m
;
stringstream
macro_output
;
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
)
{
{
if
(
save_macro_file
.
empty
())
if
(
save_macro_file
.
empty
())
...
...
This diff is collapsed.
Click to expand it.
preprocessor/macro/MacroDriver.cc
+
4
−
1
View file @
c42c6750
...
@@ -36,7 +36,7 @@ MacroDriver::~MacroDriver()
...
@@ -36,7 +36,7 @@ MacroDriver::~MacroDriver()
}
}
void
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
;
file
=
f
;
...
@@ -53,6 +53,9 @@ MacroDriver::parse(const string &f, ostream &out, bool debug, bool no_line_macro
...
@@ -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.
an @#endif or an @#endfor - but no newline - no longer trigger an error.
*/
*/
stringstream
file_with_endl
;
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
;
file_with_endl
<<
in
.
rdbuf
()
<<
endl
;
lexer
=
new
MacroFlex
(
&
file_with_endl
,
&
out
,
no_line_macro
);
lexer
=
new
MacroFlex
(
&
file_with_endl
,
&
out
,
no_line_macro
);
...
...
This diff is collapsed.
Click to expand it.
preprocessor/macro/MacroDriver.hh
+
1
−
1
View file @
c42c6750
...
@@ -176,7 +176,7 @@ public:
...
@@ -176,7 +176,7 @@ public:
//! Starts parsing a file, returns output in out
//! Starts parsing a file, returns output in out
/*! \param no_line_macro should we omit the @#line statements ? */
/*! \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
//! Name of main file being parsed
string
file
;
string
file
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment