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
21aef1a0
Commit
21aef1a0
authored
9 years ago
by
Matthieu Schaller
Browse files
Options
Downloads
Patches
Plain Diff
Parser reports an error if there are too many params.
parent
15b49080
No related branches found
No related tags found
1 merge request
!173
Parameter file in snapshot
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/parser.c
+30
-7
30 additions, 7 deletions
src/parser.c
src/parser.h
+3
-2
3 additions, 2 deletions
src/parser.h
with
33 additions
and
9 deletions
src/parser.c
+
30
−
7
View file @
21aef1a0
...
...
@@ -276,7 +276,13 @@ static void parse_value(char *line, struct swift_params *params) {
find_duplicate_params
(
params
,
tmpStr
);
strcpy
(
section
,
tmpSectionName
);
strcpy
(
params
->
section
[
params
->
sectionCount
++
].
name
,
tmpSectionName
);
strcpy
(
params
->
section
[
params
->
sectionCount
].
name
,
tmpSectionName
);
if
(
params
->
sectionCount
==
PARSER_MAX_NO_OF_SECTIONS
-
1
)
{
error
(
"Maximal number of sections in parameter file reached. Aborting !"
);
}
else
{
params
->
sectionCount
++
;
}
inSection
=
1
;
isFirstParam
=
1
;
}
else
{
...
...
@@ -294,7 +300,14 @@ static void parse_value(char *line, struct swift_params *params) {
/* Must be a standalone parameter so no need to prefix name with a
* section. */
strcpy
(
params
->
data
[
params
->
paramCount
].
name
,
tmpStr
);
strcpy
(
params
->
data
[
params
->
paramCount
++
].
value
,
token
);
strcpy
(
params
->
data
[
params
->
paramCount
].
value
,
token
);
if
(
params
->
paramCount
==
PARSER_MAX_NO_OF_PARAMS
-
1
)
{
error
(
"MMaximal number of parameters in parameter file reached. Aborting "
"!"
);
}
else
{
params
->
paramCount
++
;
}
inSection
=
0
;
isFirstParam
=
1
;
}
...
...
@@ -346,7 +359,13 @@ static void parse_section_param(char *line, int *isFirstParam,
find_duplicate_params
(
params
,
paramName
);
strcpy
(
params
->
data
[
params
->
paramCount
].
name
,
paramName
);
strcpy
(
params
->
data
[
params
->
paramCount
++
].
value
,
token
);
strcpy
(
params
->
data
[
params
->
paramCount
].
value
,
token
);
if
(
params
->
paramCount
==
PARSER_MAX_NO_OF_PARAMS
-
1
)
{
error
(
"MMaximal number of parameters in parameter file reached. Aborting !"
);
}
else
{
params
->
paramCount
++
;
}
}
/**
...
...
@@ -376,7 +395,8 @@ int parser_get_param_int(const struct swift_params *params, const char *name) {
}
}
error
(
"Cannot find '%s' in the structure, in file '%s'."
,
name
,
params
->
fileName
);
error
(
"Cannot find '%s' in the structure, in file '%s'."
,
name
,
params
->
fileName
);
return
0
;
}
...
...
@@ -408,7 +428,8 @@ char parser_get_param_char(const struct swift_params *params,
}
}
error
(
"Cannot find '%s' in the structure, in file '%s'."
,
name
,
params
->
fileName
);
error
(
"Cannot find '%s' in the structure, in file '%s'."
,
name
,
params
->
fileName
);
return
0
;
}
...
...
@@ -440,7 +461,8 @@ float parser_get_param_float(const struct swift_params *params,
}
}
error
(
"Cannot find '%s' in the structure, in file '%s'."
,
name
,
params
->
fileName
);
error
(
"Cannot find '%s' in the structure, in file '%s'."
,
name
,
params
->
fileName
);
return
0
.
f
;
}
...
...
@@ -471,7 +493,8 @@ double parser_get_param_double(const struct swift_params *params,
}
}
error
(
"Cannot find '%s' in the structure, in file '%s'."
,
name
,
params
->
fileName
);
error
(
"Cannot find '%s' in the structure, in file '%s'."
,
name
,
params
->
fileName
);
return
0
.;
}
...
...
This diff is collapsed.
Click to expand it.
src/parser.h
+
3
−
2
View file @
21aef1a0
...
...
@@ -24,7 +24,8 @@
/* Some constants. */
#define PARSER_MAX_LINE_SIZE 256
#define PARSER_MAX_NO_OF_PARAMS 512
#define PARSER_MAX_NO_OF_PARAMS 256
#define PARSER_MAX_NO_OF_SECTIONS 64
/* A parameter in the input file */
struct
parameter
{
...
...
@@ -38,7 +39,7 @@ struct section {
/* The array of parameters read from a file */
struct
swift_params
{
struct
section
section
[
PARSER_MAX_NO_OF_
PARAM
S
];
struct
section
section
[
PARSER_MAX_NO_OF_
SECTION
S
];
struct
parameter
data
[
PARSER_MAX_NO_OF_PARAMS
];
int
sectionCount
;
int
paramCount
;
...
...
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