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
faa38a1d
Commit
faa38a1d
authored
9 years ago
by
James Willis
Browse files
Options
Downloads
Patches
Plain Diff
Added duplicate name checking for standalone parameters and section names.
parent
9169e2c9
No related branches found
No related tags found
1 merge request
!161
Fix parameter file parsing for duplicate names
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/parser.c
+37
-14
37 additions, 14 deletions
src/parser.c
with
37 additions
and
14 deletions
src/parser.c
+
37
−
14
View file @
faa38a1d
...
@@ -49,7 +49,8 @@ static void parse_section_param(char *line, int *isFirstParam,
...
@@ -49,7 +49,8 @@ static void parse_section_param(char *line, int *isFirstParam,
char
*
sectionName
,
struct
swift_params
*
params
);
char
*
sectionName
,
struct
swift_params
*
params
);
static
void
find_duplicate_params
(
const
struct
swift_params
*
params
,
static
void
find_duplicate_params
(
const
struct
swift_params
*
params
,
const
char
*
param_name
);
const
char
*
param_name
);
static
void
find_duplicate_section
(
const
struct
swift_params
*
params
,
const
char
*
section_name
);
static
int
lineNumber
=
0
;
static
int
lineNumber
=
0
;
/**
/**
...
@@ -163,6 +164,23 @@ static void find_duplicate_params(const struct swift_params *params,
...
@@ -163,6 +164,23 @@ static void find_duplicate_params(const struct swift_params *params,
}
}
}
}
/**
* @brief Look for duplicate sections.
*
* @param params Structure that holds the parameters
* @param param_name Name of section to be searched for
*/
static
void
find_duplicate_section
(
const
struct
swift_params
*
params
,
const
char
*
section_name
)
{
for
(
int
i
=
0
;
i
<
params
->
sectionCount
;
i
++
)
{
/*strcmp returns 0 if both strings are the same.*/
if
(
!
strcmp
(
section_name
,
params
->
section
[
i
].
name
))
{
error
(
"Invalid line:%d '%s', section is a duplicate."
,
lineNumber
,
section_name
);
}
}
}
/**
/**
* @brief Parses a line from a file and stores any parameters in a structure.
* @brief Parses a line from a file and stores any parameters in a structure.
*
*
...
@@ -215,6 +233,7 @@ static void parse_value(char *line, struct swift_params *params) {
...
@@ -215,6 +233,7 @@ static void parse_value(char *line, struct swift_params *params) {
name. */
name. */
static
int
isFirstParam
=
1
;
static
int
isFirstParam
=
1
;
char
tmpStr
[
PARSER_MAX_LINE_SIZE
];
char
tmpStr
[
PARSER_MAX_LINE_SIZE
];
char
tmpSectionName
[
PARSER_MAX_LINE_SIZE
];
char
*
token
;
char
*
token
;
...
@@ -245,25 +264,31 @@ static void parse_value(char *line, struct swift_params *params) {
...
@@ -245,25 +264,31 @@ static void parse_value(char *line, struct swift_params *params) {
/* If second token is NULL then the line must be a section heading. */
/* If second token is NULL then the line must be a section heading. */
if
(
token
==
NULL
)
{
if
(
token
==
NULL
)
{
strcat
(
tmpStr
,
PARSER_VALUE_STRING
);
strcpy
(
tmpSectionName
,
tmpStr
);
strcat
(
tmpSectionName
,
PARSER_VALUE_STRING
);
/* Check for duplicate section name. */
/* Check for duplicate section name. */
for
(
int
i
=
0
;
i
<
params
->
sectionCount
;
i
++
)
{
find_duplicate_section
(
params
,
tmpSectionName
);
/*strcmp returns 0 if both strings are the same.*/
if
(
!
strcmp
(
tmpStr
,
params
->
section
[
i
].
name
))
{
/* Check for duplicate standalone parameter name used as a section name. */
error
(
"Invalid line:%d '%s', section is a duplicate."
,
find_duplicate_params
(
params
,
tmpStr
);
lineNumber
,
line
);
}
strcpy
(
section
,
tmpSectionName
);
}
strcpy
(
params
->
section
[
params
->
sectionCount
++
].
name
,
tmpSectionName
);
strcpy
(
section
,
tmpStr
);
strcpy
(
params
->
section
[
params
->
sectionCount
++
].
name
,
tmpStr
);
inSection
=
1
;
inSection
=
1
;
isFirstParam
=
1
;
isFirstParam
=
1
;
}
else
{
}
else
{
/* Create string with standalone parameter name appended with ":" to aid
* duplicate search as section names are stored with ":" at the end.*/
strcpy
(
tmpSectionName
,
tmpStr
);
strcat
(
tmpSectionName
,
PARSER_VALUE_STRING
);
/* Check for duplicate parameter name. */
/* Check for duplicate parameter name. */
find_duplicate_params
(
params
,
tmpStr
);
find_duplicate_params
(
params
,
tmpStr
);
/* Check for duplicate section name used as standalone parameter name. */
find_duplicate_section
(
params
,
tmpSectionName
);
/* Must be a standalone parameter so no need to prefix name with a
/* Must be a standalone parameter so no need to prefix name with a
* section. */
* section. */
strcpy
(
params
->
data
[
params
->
paramCount
].
name
,
tmpStr
);
strcpy
(
params
->
data
[
params
->
paramCount
].
name
,
tmpStr
);
...
@@ -531,5 +556,3 @@ void parser_write_params_to_file(const struct swift_params *params,
...
@@ -531,5 +556,3 @@ void parser_write_params_to_file(const struct swift_params *params,
fclose
(
file
);
fclose
(
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