Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SWIFTsim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SWIFT
SWIFTsim
Commits
b65e4002
Commit
b65e4002
authored
9 years ago
by
James Willis
Browse files
Options
Downloads
Patches
Plain Diff
Added function to write contents of structure to a file in YAML format.
parent
6967f09c
No related branches found
No related tags found
1 merge request
!140
First version of main() using a parameter file to get constants.
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/parser.c
+26
-9
26 additions, 9 deletions
src/parser.c
src/parser.h
+2
-0
2 additions, 0 deletions
src/parser.h
with
28 additions
and
9 deletions
src/parser.c
+
26
−
9
View file @
b65e4002
...
...
@@ -44,23 +44,23 @@ static void parse_line(FILE *fp, struct swift_params *params);
void
parser_read_file
(
const
char
*
file_name
,
struct
swift_params
*
params
)
{
FILE
*
fp
;
/* Open file for reading */
FILE
*
file
=
fopen
(
file_name
,
"r"
);
/* Initialise parameter count. */
params
->
count
=
0
;
/* Open file for reading */
fp
=
fopen
(
file_name
,
"r"
);
if
(
fp
==
NULL
)
{
/* Check if parameter file exits. */
if
(
file
==
NULL
)
{
error
(
"Error opening parameter file: %s"
,
file_name
);
}
/* Read until the end of the file is reached.*/
while
(
!
feof
(
f
p
))
{
parse_line
(
f
p
,
params
);
while
(
!
feof
(
f
ile
))
{
parse_line
(
f
ile
,
params
);
}
fclose
(
f
p
);
fclose
(
f
ile
);
}
/**
...
...
@@ -253,3 +253,20 @@ void parser_print_params(struct swift_params *params) {
}
}
void
parser_write_params_to_file
(
struct
swift_params
*
params
,
const
char
*
file_name
)
{
FILE
*
file
=
fopen
(
file_name
,
"w"
);
/* Start of file identifier in YAML. */
fprintf
(
file
,
"%s
\n
"
,
PARSER_START_OF_FILE
);
for
(
int
i
=
0
;
i
<
params
->
count
;
i
++
)
{
fprintf
(
file
,
"%s%c %s
\n
"
,
params
->
data
[
i
].
name
,
PARSER_VALUE_CHAR
,
params
->
data
[
i
].
value
);
}
/* End of file identifier in YAML. */
fprintf
(
file
,
PARSER_END_OF_FILE
);
fclose
(
file
);
}
This diff is collapsed.
Click to expand it.
src/parser.h
+
2
−
0
View file @
b65e4002
...
...
@@ -27,6 +27,7 @@
#define PARSER_COMMENT_CHAR "#"
#define PARSER_VALUE_CHAR ':'
#define PARSER_VALUE_STRING ":"
#define PARSER_START_OF_FILE "---"
#define PARSER_END_OF_FILE "..."
struct
parameter
{
...
...
@@ -42,6 +43,7 @@ struct swift_params {
/* Public API. */
void
parser_read_file
(
const
char
*
file_name
,
struct
swift_params
*
params
);
void
parser_print_params
(
struct
swift_params
*
params
);
void
parser_write_params_to_file
(
struct
swift_params
*
params
,
const
char
*
file_name
);
void
parser_get_param_int
(
struct
swift_params
*
params
,
char
*
name
,
int
*
retParam
);
void
parser_get_param_float
(
struct
swift_params
*
params
,
char
*
name
,
float
*
retParam
);
void
parser_get_param_double
(
struct
swift_params
*
params
,
char
*
name
,
double
*
retParam
);
...
...
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