diff --git a/src/parser.c b/src/parser.c index 449f25a014aa43d80603e2d332cfefa2b7085445..eec257823cee22fd6bed925f85b60b1f610c5749 100644 --- a/src/parser.c +++ b/src/parser.c @@ -24,7 +24,7 @@ #include <stdlib.h> #include "error.h" -void parseFile(const char *file_name, struct swift_params *params) { +void parser_read_file(const char *file_name, struct swift_params *params) { FILE *fp; @@ -39,13 +39,13 @@ void parseFile(const char *file_name, struct swift_params *params) { /* Read until the end of the file is reached.*/ while(!feof(fp)) { - readParameter(fp,params); + read_param(fp,params); } fclose(fp); } -static int countChar(char *str, char val) { +static int count_char(char *str, char val) { int i, count = 0; @@ -59,7 +59,7 @@ static int countChar(char *str, char val) { return count; } -static void readParameter(FILE *fp, struct swift_params *params) { +static void read_param(FILE *fp, struct swift_params *params) { char line [MAX_LINE_SIZE]; char trim_line [MAX_LINE_SIZE]; @@ -73,14 +73,14 @@ static void readParameter(FILE *fp, struct swift_params *params) { strcpy(trim_line,token); /* Check if the line contains a value */ - if(strchr(trim_line,VALUE)) { + if(strchr(trim_line,':')) { /* Check for more than one parameter on the same line. */ - if(countChar(trim_line,VALUE) > 1) { + if(count_char(trim_line,':') > 1) { error("Found more than one parameter in '%s', only one allowed.",line); } else { /*Take first token as the parameter name. */ - token = strtok(trim_line,VALUE); + token = strtok(trim_line,":"); strcpy(params->data[params->count].name,token); /*Take second token as the parameter value. */ @@ -91,7 +91,7 @@ static void readParameter(FILE *fp, struct swift_params *params) { } } -void getParamInt(struct swift_params *params, char * name, int * retParam) { +void parser_get_param_int(struct swift_params *params, char * name, int * retParam) { int i; @@ -122,7 +122,7 @@ void getParamInt(struct swift_params *params, char * name, int * retParam) { } } -void getParamFloat(struct swift_params *params, char * name, float * retParam) { +void parser_get_param_float(struct swift_params *params, char * name, float * retParam) { int i; @@ -136,7 +136,7 @@ void getParamFloat(struct swift_params *params, char * name, float * retParam) { } } -void getParamString(struct swift_params *params, char * name, char * retParam) { +void parser_get_param_string(struct swift_params *params, char * name, char * retParam) { int i; @@ -150,7 +150,7 @@ void getParamString(struct swift_params *params, char * name, char * retParam) { } } -void printParameters(struct swift_params *params) { +void parser_print_params(struct swift_params *params) { int i; diff --git a/src/parser.h b/src/parser.h index 713bc1a9b55374ee28903d8ba9c87cc856188da5..9cd1578dfe01a8659ace925f4344c8cf68bacf49 100644 --- a/src/parser.h +++ b/src/parser.h @@ -26,7 +26,7 @@ #define MAX_NO_OF_PARAMS 512 #define COMMENT "#" -#define VALUE char ":" +#define VALUE ':' #define END_OF_FILE "..." struct parameter { @@ -40,13 +40,14 @@ struct swift_params { }; /* Public API. */ -void parseFile(const char *file_name, struct swift_params *params); -void printParameters(struct swift_params *params); -void getParamInt(struct swift_params *params, char *name, int *retParam); -void getParamFloat(struct swift_params *params, char *name, float *retParam); -void getParamString(struct swift_params *params, char *name, char *retParam); +void parser_read_file(const char *file_name, struct swift_params *params); +void parser_print_params(struct swift_params *params); +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_string(struct swift_params *params, char *name, char *retParam); /* Private functions. */ -static void readParameter(FILE *fp, struct swift_params *params); +static void read_param(FILE *fp, struct swift_params *params); +static int count_char(char *str, char val); #endif /* SWIFT_PARSER_H */ diff --git a/src/testParser.c b/src/testParser.c index ecf04bf40abd6201cb4991f53c3fa127d25e9e98..7a38002f70e3870b40525d93b88933e0129dc057 100644 --- a/src/testParser.c +++ b/src/testParser.c @@ -9,14 +9,14 @@ int main(int argc, char *argv[]) { float max_h = 0.0f; char ic_file [MAX_LINE_SIZE]; - parseFile(input_file,¶m_file); + parser_read_file(input_file,¶m_file); - printParameters(¶m_file); + parser_print_params(¶m_file); - getParamInt(¶m_file,"no_of_threads",&no_of_threads); - getParamInt(¶m_file,"no_of_time_steps",&no_of_time_steps); - getParamFloat(¶m_file,"max_h",&max_h); - getParamString(¶m_file,"ic_file",ic_file); + parser_get_param_int(¶m_file,"no_of_threads",&no_of_threads); + parser_get_param_int(¶m_file,"no_of_time_steps",&no_of_time_steps); + parser_get_param_float(¶m_file,"max_h",&max_h); + parser_get_param_string(¶m_file,"ic_file",ic_file); printf("no_of_threads: %d, no_of_time_steps: %d, max_h: %f, ic_file: %s\n",no_of_threads, no_of_time_steps, max_h, ic_file);