Skip to content
Snippets Groups Projects
Commit 67cede04 authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Code formatting, doxygen documentation, no \t for indentation in parser output.

parent faa38a1d
No related branches found
No related tags found
1 merge request!161Fix parameter file parsing for duplicate names
...@@ -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,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment