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
67cede04
Commit
67cede04
authored
9 years ago
by
Matthieu Schaller
Browse files
Options
Downloads
Patches
Plain Diff
Code formatting, doxygen documentation, no \t for indentation in parser output.
parent
faa38a1d
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
+21
-20
21 additions, 20 deletions
src/parser.c
with
21 additions
and
20 deletions
src/parser.c
+
21
−
20
View file @
67cede04
...
@@ -158,8 +158,8 @@ static void find_duplicate_params(const struct swift_params *params,
...
@@ -158,8 +158,8 @@ static void find_duplicate_params(const struct swift_params *params,
for
(
int
i
=
0
;
i
<
params
->
paramCount
;
i
++
)
{
for
(
int
i
=
0
;
i
<
params
->
paramCount
;
i
++
)
{
/*strcmp returns 0 if both strings are the same.*/
/*strcmp returns 0 if both strings are the same.*/
if
(
!
strcmp
(
param_name
,
params
->
data
[
i
].
name
))
{
if
(
!
strcmp
(
param_name
,
params
->
data
[
i
].
name
))
{
error
(
"Invalid line:%d '%s', parameter is a duplicate."
,
error
(
"Invalid line:%d '%s', parameter is a duplicate."
,
lineNumber
,
lineNumber
,
param_name
);
param_name
);
}
}
}
}
}
}
...
@@ -168,16 +168,16 @@ static void find_duplicate_params(const struct swift_params *params,
...
@@ -168,16 +168,16 @@ static void find_duplicate_params(const struct swift_params *params,
* @brief Look for duplicate sections.
* @brief Look for duplicate sections.
*
*
* @param params Structure that holds the parameters
* @param params Structure that holds the parameters
* @param
param
_name Name of section to be searched for
* @param
section
_name Name of section to be searched for
*/
*/
static
void
find_duplicate_section
(
const
struct
swift_params
*
params
,
static
void
find_duplicate_section
(
const
struct
swift_params
*
params
,
const
char
*
section_name
)
{
const
char
*
section_name
)
{
for
(
int
i
=
0
;
i
<
params
->
sectionCount
;
i
++
)
{
for
(
int
i
=
0
;
i
<
params
->
sectionCount
;
i
++
)
{
/*strcmp returns 0 if both strings are the same.*/
/*strcmp returns 0 if both strings are the same.*/
if
(
!
strcmp
(
section_name
,
params
->
section
[
i
].
name
))
{
if
(
!
strcmp
(
section_name
,
params
->
section
[
i
].
name
))
{
error
(
"Invalid line:%d '%s', section is a duplicate."
,
error
(
"Invalid line:%d '%s', section is a duplicate."
,
lineNumber
,
lineNumber
,
section_name
);
section_name
);
}
}
}
}
}
}
...
@@ -266,29 +266,30 @@ static void parse_value(char *line, struct swift_params *params) {
...
@@ -266,29 +266,30 @@ static void parse_value(char *line, struct swift_params *params) {
if
(
token
==
NULL
)
{
if
(
token
==
NULL
)
{
strcpy
(
tmpSectionName
,
tmpStr
);
strcpy
(
tmpSectionName
,
tmpStr
);
strcat
(
tmpSectionName
,
PARSER_VALUE_STRING
);
strcat
(
tmpSectionName
,
PARSER_VALUE_STRING
);
/* Check for duplicate section name. */
/* Check for duplicate section name. */
find_duplicate_section
(
params
,
tmpSectionName
);
find_duplicate_section
(
params
,
tmpSectionName
);
/* Check for duplicate standalone parameter name used as a section name. */
/* Check for duplicate standalone parameter name used as a section name.
find_duplicate_params
(
params
,
tmpStr
);
*/
find_duplicate_params
(
params
,
tmpStr
);
strcpy
(
section
,
tmpSectionName
);
strcpy
(
section
,
tmpSectionName
);
strcpy
(
params
->
section
[
params
->
sectionCount
++
].
name
,
tmpSectionName
);
strcpy
(
params
->
section
[
params
->
sectionCount
++
].
name
,
tmpSectionName
);
inSection
=
1
;
inSection
=
1
;
isFirstParam
=
1
;
isFirstParam
=
1
;
}
else
{
}
else
{
/* Create string with standalone parameter name appended with ":" to aid
/* Create string with standalone parameter name appended with ":" to aid
* duplicate search as section names are stored with ":" at the end.*/
* duplicate search as section names are stored with ":" at the end.*/
strcpy
(
tmpSectionName
,
tmpStr
);
strcpy
(
tmpSectionName
,
tmpStr
);
strcat
(
tmpSectionName
,
PARSER_VALUE_STRING
);
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. */
/* Check for duplicate section name used as standalone parameter name. */
find_duplicate_section
(
params
,
tmpSectionName
);
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
);
...
@@ -341,8 +342,8 @@ static void parse_section_param(char *line, int *isFirstParam,
...
@@ -341,8 +342,8 @@ static void parse_section_param(char *line, int *isFirstParam,
strcat
(
paramName
,
tmpStr
);
strcat
(
paramName
,
tmpStr
);
/* Check for duplicate parameter name. */
/* Check for duplicate parameter name. */
find_duplicate_params
(
params
,
paramName
);
find_duplicate_params
(
params
,
paramName
);
strcpy
(
params
->
data
[
params
->
paramCount
].
name
,
paramName
);
strcpy
(
params
->
data
[
params
->
paramCount
].
name
,
paramName
);
strcpy
(
params
->
data
[
params
->
paramCount
++
].
value
,
token
);
strcpy
(
params
->
data
[
params
->
paramCount
++
].
value
,
token
);
}
}
...
@@ -543,7 +544,7 @@ void parser_write_params_to_file(const struct swift_params *params,
...
@@ -543,7 +544,7 @@ void parser_write_params_to_file(const struct swift_params *params,
/* Remove white space from parameter name and write it to the file. */
/* Remove white space from parameter name and write it to the file. */
token
=
strtok
(
NULL
,
" #
\n
"
);
token
=
strtok
(
NULL
,
" #
\n
"
);
fprintf
(
file
,
"
\t
%s%c %s
\n
"
,
token
,
PARSER_VALUE_CHAR
,
fprintf
(
file
,
"
%s%c %s
\n
"
,
token
,
PARSER_VALUE_CHAR
,
params
->
data
[
i
].
value
);
params
->
data
[
i
].
value
);
}
else
{
}
else
{
fprintf
(
file
,
"
\n
%s%c %s
\n
"
,
params
->
data
[
i
].
name
,
PARSER_VALUE_CHAR
,
fprintf
(
file
,
"
\n
%s%c %s
\n
"
,
params
->
data
[
i
].
name
,
PARSER_VALUE_CHAR
,
...
...
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