26 #include <lal/LALStdlib.h>
27 #include <lal/LALError.h>
28 #include <lal/LALStdio.h>
29 #include <lal/LALString.h>
30 #include <lal/FileIO.h>
31 #include <lal/StreamInput.h>
32 #include <lal/AVFactories.h>
33 #include <lal/StringVector.h>
35 #include <lal/UserInputParse.h>
37 #include <lal/ConfigFile.h>
40 #define WHITESPACE " \t"
76 dataBuffer[strlen(dataBuffer)-1] = 0;
104 strcpy ( rawdata,
string );
149 if ( cfgdata == NULL ) {
177 if ( secName == NULL || cfgdata == NULL || cfgdata->
lines == NULL )
182 CHAR *secName_cleaned;
191 if ( strcmp ( secName_cleaned, toc->
data[i] ) == 0 )
223 if ( lines->
tokens[0][0] !=
'[' )
233 if ( thisLine[0] ==
'[' )
255 size_t lenLine = strlen ( lineCleaned );
256 if ( lineCleaned[0] !=
'[' || lineCleaned[lenLine-1] !=
']' ) {
257 XLALPrintError (
"Invalid input line '%s' is not of the form '[...]' specifying a section name\n", lineCleaned );
279 const CHAR * secName,
280 const CHAR * varName,
297 CHAR *secName_cleaned = NULL;
298 if ( secName == NULL )
300 inRightSection =
TRUE;
308 size_t searchlen = strlen ( varName );
314 if ( inRightSection ) {
323 if ( (secName_cleaned != NULL) && ( strcmp ( secName_cleaned, thisSec ) == 0 ) )
325 inRightSection =
TRUE;
331 if ( !inRightSection ) {
339 if ( varlen != searchlen ) {
344 if ( strncmp ( varName, cfgdata->
lines->
tokens[i], varlen ) == 0 )
367 #define DEFINE_XLALREADCONFIGVARIABLE(TYPE,CTYPE) \
368 DECLARE_XLALREADCONFIGVARIABLE(TYPE,CTYPE) \
371 CHAR *valString = NULL; \
372 XLAL_CHECK ( XLALReadConfigSTRINGVariable ( &valString, cfgdata, secName, varName, wasRead ) == XLAL_SUCCESS, XLAL_EFUNC ); \
373 if ( ! (*wasRead ) ) { \
374 return XLAL_SUCCESS; \
376 XLAL_CHECK ( XLALParseStringValueAs ##TYPE ( varp, valString ) == XLAL_SUCCESS, XLAL_EFUNC ); \
377 XLALFree (valString); \
378 return XLAL_SUCCESS; \
446 if ( text == NULL ) {
451 CHAR *ptr, *ptr2, *eol;
453 INT4 inBracesCount = 0;
460 if ( (*ptr) ==
'\"' ) {
461 inQuotes = !inQuotes;
463 if ( (*ptr) ==
'{' ) {
466 if ( (*ptr) ==
'}' ) {
470 if ( ((*ptr) ==
'#') || ( (*ptr) ==
'%') ) {
473 len = strcspn (ptr,
"\n");
474 memset ( (
void*)ptr,
'\n', len);
479 if ( (!inQuotes) && (inBracesCount == 0) && ((*ptr) ==
';') ) {
483 if ( (*ptr) ==
'\r' ) {
495 while ( (ptr = strchr(ptr,
'\\')) != NULL )
497 if ( ptr[1] ==
'\n' )
503 len = strlen (ptr+2);
504 memmove(ptr, ptr+2, len+1);
516 while ( (ptr = strchr(ptr,
'\t')) != NULL ) {
524 char *endptr = text + strlen(text);
525 while (ptr < endptr )
527 eol = strchr (ptr,
'\n');
530 if (len) { memset ( (
void*)ptr,
'\n', len); }
536 ptr = strchr (ptr,
'\0');
541 while ( ptr2 >= text && ( strspn ( ptr2,
WHITESPACE ) != 0 ) ) {
int XLALReadConfigSTRINGVariable(CHAR **varp, LALParsedDataFile *cfgdata, const CHAR *secName, const CHAR *varName, BOOLEAN *wasRead)
String parser for config-file: can read config-variables of the form VARIABLE [=:] VALUE.
static void cleanConfig(char *text)
static CHAR * XLALGetSectionName(const CHAR *line)
#define DEFINE_XLALREADCONFIGVARIABLE(TYPE, CTYPE)
int XLALPrintError(const char *fmt,...)
UINT4Vector * XLALConfigFileGetUnreadEntries(const LALParsedDataFile *cfgdata)
Return a list of unread config-file entries, NULL if none found (without error).
int XLALParseDataFileContent(LALParsedDataFile **cfgdata, const CHAR *string)
int XLALParseDataFile(LALParsedDataFile **cfgdata, const CHAR *path)
Parse an ASCII data-file into a pre-cleaned array of lines.
int XLALConfigSectionExists(const LALParsedDataFile *cfgdata, const CHAR *secName)
Function to determine whether a given section secName exists in the parsed config-file contents cfgda...
LALStringVector * XLALListConfigFileSections(const LALParsedDataFile *cfgdata)
Function to find all sections in given config-file contents cfgdata.
void XLALDestroyParsedDataFile(LALParsedDataFile *cfgdata)
Free memory associated with a LALParsedDataFile structure.
char * XLALFileLoad(const char *path)
Read a complete data-file into memory as a string.
unsigned char BOOLEAN
Boolean logical type, see Headers LAL(Atomic)Datatypes.h for more details.
uint64_t UINT8
Eight-byte unsigned integer; on some platforms this is equivalent to unsigned long int instead.
double REAL8
Double precision real floating-point number (8 bytes).
int64_t INT8
Eight-byte signed integer; on some platforms this is equivalent to long int instead.
char CHAR
One-byte signed integer, see Headers LAL(Atomic)Datatypes.h for more details.
uint32_t UINT4
Four-byte unsigned integer.
int32_t INT4
Four-byte signed integer.
#define XLALRealloc(p, n)
char * XLALStringDuplicate(const char *s)
Like strdup but uses LAL allocation routines (free with LALFree).
LALStringVector * XLALAppendString2Vector(LALStringVector *vect, const CHAR *string)
Append the given string to the string-vector (XLAL interface), return pointer to the resulting string...
char * XLALDeblankString(const CHAR *start, UINT4 len)
Copy (and allocate) string from 'start' with length 'len', removing all starting- and trailing blanks...
void XLALDestroyStringVector(LALStringVector *vect)
XLAL-interface: Free a string-vector ;)
#define XLAL_ERROR_NULL(...)
Macro to invoke a failure from a XLAL routine returning a pointer.
#define XLAL_ERROR(...)
Macro to invoke a failure from a XLAL routine returning an integer.
#define XLAL_CHECK(assertion,...)
Macro to test an assertion and invoke a failure if it is not true in a function that returns an integ...
#define XLAL_CHECK_NULL(assertion,...)
Macro to test an assertion and invoke a failure if it is not true in a function that returns a pointe...
@ XLAL_ENOMEM
Memory allocation error.
@ XLAL_SUCCESS
Success return value (not an error number)
@ XLAL_EFUNC
Internal function call failed bit: "or" this with existing error number.
@ XLAL_EDOM
Input domain error.
@ XLAL_EINVAL
Invalid argument.
This structure is returned by XLALParseDataFile() and holds the contents of an ASCII data-file in a p...
TokenList * lines
list of pre-parsed data-file lines
BOOLEAN * wasRead
keep track of successfully read lines
Vector of type CHAR*, ie 'strings', see DATATYPE-Vector types for more details.
UINT4 length
Number of elements in array.
CHAR ** data
Pointer to the data array.
Epoch relative to GPS epoch, see LIGOTimeGPS type for more details.
This structure stores a number of null-terminated strings of arbitrary length.
CHAR ** tokens
A list of pointers to the individual tokens; the elements tokens[0..nTokens-1] point to tokens,...
UINT4 nTokens
The number of tokens in the list.
Vector of type UINT4, see DATATYPE-Vector types for more details.
UINT4 length
Number of elements in array.
UINT4 * data
Pointer to the data array.