Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
preprocessor
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
7
Issues
7
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dynare
preprocessor
Commits
1393bf1d
Verified
Commit
1393bf1d
authored
Dec 19, 2018
by
Sébastien Villemot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Parse the options list at the top of the mod-file
Ref
dynare#1630
parent
bb624ec6
Pipeline
#504
passed with stage
in 1 minute and 36 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
67 additions
and
38 deletions
+67
-38
src/DynareMain.cc
src/DynareMain.cc
+67
-38
No files found.
src/DynareMain.cc
View file @
1393bf1d
...
...
@@ -20,6 +20,9 @@
#include <iostream>
#include <sstream>
#include <fstream>
#include <vector>
#include <string>
#include <regex>
#include <cstdlib>
#include <cstring>
...
...
@@ -65,6 +68,29 @@ usage()
exit
(
EXIT_FAILURE
);
}
vector
<
string
>
parse_options_line
(
const
string
&
modfiletxt
)
{
// Looks for an options list in the first line of the mod file
vector
<
string
>
options
;
auto
pos
=
modfiletxt
.
find
(
'\n'
);
string
first_line
{
modfiletxt
.
substr
(
0
,
pos
)};
regex
pat
{
"^
\\
s*//
\\
s*--
\\
+
\\
s*options:([^
\\
+]*)
\\
+--"
};
smatch
matches
;
if
(
regex_search
(
first_line
,
matches
,
pat
))
if
(
matches
.
size
()
>
1
&&
matches
[
1
].
matched
)
{
regex
pat2
{
"([^,
\\
s]+)"
};
string
s
{
matches
[
1
]};
for
(
sregex_iterator
p
(
s
.
begin
(),
s
.
end
(),
pat2
);
p
!=
sregex_iterator
{};
++
p
)
options
.
push_back
((
*
p
)[
1
]);
}
return
options
;
}
int
main
(
int
argc
,
char
**
argv
)
{
...
...
@@ -81,6 +107,44 @@ main(int argc, char **argv)
usage
();
}
/* Construct basename (i.e. remove file extension if there is one) and put
contents of mod-file into a buffer */
string
basename
=
argv
[
1
];
string
modfile
,
modfiletxt
;
size_t
fsc
=
basename
.
find_first_of
(
';'
);
if
(
fsc
!=
string
::
npos
)
{
// If a semicolon is found in argv[1], treat it as the text of the modfile
modfile
=
"mod_file_passed_as_string.mod"
;
basename
=
"mod_file_passed_as_string"
;
modfiletxt
=
argv
[
1
];
}
else
{
// If a semicolon is NOT found in argv[1], treat it as the name of the modfile
modfile
=
argv
[
1
];
size_t
pos
=
basename
.
find_last_of
(
'.'
);
if
(
pos
!=
string
::
npos
)
basename
.
erase
(
pos
);
ifstream
modfile
(
argv
[
1
],
ios
::
binary
);
if
(
modfile
.
fail
())
{
cerr
<<
"ERROR: Could not open file: "
<<
argv
[
1
]
<<
endl
;
exit
(
EXIT_FAILURE
);
}
stringstream
buffer
;
buffer
<<
modfile
.
rdbuf
();
modfiletxt
=
buffer
.
str
();
}
// Create options list, using first line of mod-file and command line
vector
<
string
>
options
=
parse_options_line
(
modfiletxt
);
for
(
int
arg
=
2
;
arg
<
argc
;
arg
++
)
options
.
push_back
(
argv
[
arg
]);
// Parse options
bool
clear_all
=
true
;
bool
clear_global
=
false
;
bool
save_macro
=
false
;
...
...
@@ -124,11 +188,8 @@ main(int argc, char **argv)
dynareroot
=
dynareroot
/
".."
/
".."
;
bool
onlymodel
=
false
;
// Parse options
for
(
int
arg
=
2
;
arg
<
argc
;
arg
++
)
for
(
auto
s
:
options
)
{
string
s
{
argv
[
arg
]};
if
(
s
==
"debug"
)
debug
=
true
;
else
if
(
s
==
"noclearall"
)
...
...
@@ -357,37 +418,6 @@ main(int argc, char **argv)
if
(
!
nopreprocessoroutput
)
cout
<<
"Starting preprocessing of the model file ..."
<<
endl
;
// Construct basename (i.e. remove file extension if there is one)
string
basename
=
argv
[
1
];
string
modfile
,
modfiletxt
;
size_t
fsc
=
basename
.
find_first_of
(
';'
);
if
(
fsc
!=
string
::
npos
)
{
// If a semicolon is found in argv[1], treat it as the text of the modfile
modfile
=
"mod_file_passed_as_string.mod"
;
basename
=
"mod_file_passed_as_string"
;
modfiletxt
=
argv
[
1
];
}
else
{
// If a semicolon is NOT found in argv[1], treat it as the name of the modfile
modfile
=
argv
[
1
];
size_t
pos
=
basename
.
find_last_of
(
'.'
);
if
(
pos
!=
string
::
npos
)
basename
.
erase
(
pos
);
ifstream
modfile
(
argv
[
1
],
ios
::
binary
);
if
(
modfile
.
fail
())
{
cerr
<<
"ERROR: Could not open file: "
<<
argv
[
1
]
<<
endl
;
exit
(
EXIT_FAILURE
);
}
stringstream
buffer
;
buffer
<<
modfile
.
rdbuf
();
modfiletxt
=
buffer
.
str
();
}
WarningConsolidation
warnings
(
no_warn
);
// Process config file
...
...
@@ -399,9 +429,8 @@ main(int argc, char **argv)
// If Include option was passed to the [paths] block of the config file, add
// it to paths before macroprocessing
vector
<
string
>
config_include_paths
=
config_file
.
getIncludePaths
();
for
(
vector
<
string
>::
const_iterator
it
=
config_include_paths
.
begin
();
it
!=
config_include_paths
.
end
();
it
++
)
path
.
push_back
(
*
it
);
for
(
const
auto
&
it
:
config_include_paths
)
path
.
push_back
(
it
);
// Do macro processing
stringstream
macro_output
;
...
...
Write
Preview
Markdown
is supported
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