PLUTO
|
File parser utilities. More...
#include "pluto.h"
Go to the source code of this file.
Functions | |
static int | ParamFileGetWords (char *line, char **) |
int | ParamFileRead (char *fname) |
char * | ParamFileGet (const char *label, int pos) |
int | ParamFileHasBoth (const char *label1, const char *label2) |
int | ParamExist (const char *label) |
Variables | |
static int | nlines |
The total number of lines (including empty ones) contained in the file. More... | |
static char ** | fline |
All of the lines (including empty ones) in the file. More... | |
File parser utilities.
This file provides a set of useful functions to open / read and parse the content of a parameter file (typically pluto.ini). The parameter file can contain a number of lines with the general structure
label value1 value2 ...
where the number of values following the label can be different for each line.
ParamFileRead() reads the file and store its content into an array of lines (**fline
). ParamFileGet() can be used to retrieve the n-th parameter value following a given label, while ParQuery() check whether a parameter actually exists.
As an example consider the following file "myparam.txt":
---- File myparam.txt ----- nx 100 xdomain 15.0 30.0 ---------------------------
The parameter can be read with the following code snippet:
Definition in file parse_file.c.
int ParamExist | ( | const char * | label | ) |
Check whether *label exists in any of the lines (**fline).
[in] | label |
Definition at line 159 of file parse_file.c.
char* ParamFileGet | ( | const char * | label, |
int | pos | ||
) |
Search for *label
in all the lines pointed to by **fline
. If label exists, return a pointer to the string located pos words after label. Issue an error if this string cannot be located.
[in] | label | the first word of a line to be searched |
[in] | pos | an integer giving the position of the word |
Definition at line 86 of file parse_file.c.
|
static |
Return the words and their number contained in a single line.
Definition at line 185 of file parse_file.c.
int ParamFileHasBoth | ( | const char * | label1, |
const char * | label2 | ||
) |
Locate the line beginning with label1 and return 1 if label2 can be found on the same line. Return 0 otherwise.
[in] | label1 | The first word of the line to be searched |
[in] | label2 | A word containined in the same line beginning with label1 |
Definition at line 129 of file parse_file.c.
int ParamFileRead | ( | char * | fname | ) |
Parse file *fname and store its content line by line in *fline. Blank lines are excluded.
[in] | fname | the name of the file to be read |
Definition at line 53 of file parse_file.c.
|
static |
All of the lines (including empty ones) in the file.
Definition at line 49 of file parse_file.c.
|
static |
The total number of lines (including empty ones) contained in the file.
Definition at line 47 of file parse_file.c.