/// Parse a transient window name string into the corresponding transientWindowType int XLALParseTransientWindowName ( const char *windowName ) { XLAL_CHECK ( windowName != NULL, XLAL_EINVAL ); // convert input window-name into lower-case first char windowNameLC [ strlen(windowName) + 1 ]; strcpy ( windowNameLC, windowName ); XLALStringToLowerCase ( windowNameLC ); int winType = -1; for ( UINT4 j=0; j < TRANSIENT_LAST; j ++ ) { if ( !strcmp ( windowNameLC, transientWindowNames[j] ) ) { winType = j; break; } } // j < TRANSIENT_LAST if ( winType == -1 ) { XLALPrintError ("Invalid transient Window-name '%s', allowed are (case-insensitive): [%s", windowName, transientWindowNames[0] ); for ( UINT4 j = 1; j < TRANSIENT_LAST; j ++ ) { XLALPrintError (", %s", transientWindowNames[j] ); } XLALPrintError ("]\n"); XLAL_ERROR ( XLAL_EINVAL ); } // if windowName not valid return winType; } // XLALParseTransientWindowName()
/// Parse a string into a BOOLEAN /// Allowed string-values are (case-insensitive): /// {"yes", "true", "1"} --> TRUE /// {"no", "false", "0"} --> FALSE /// /// NOTE: This throws an error on _any_ extraneous leading or trailing characters or whitespace int XLALParseStringValueAsBOOLEAN ( BOOLEAN *valBOOLEAN, ///< [out] return BOOLEAN value const char *valString ///< [in] input string value ) { XLAL_CHECK ( (valBOOLEAN != NULL) && (valString != NULL ), XLAL_EINVAL ); /* get rid of case ambiguities */ char *valStringLower; XLAL_CHECK ( (valStringLower = XLALMalloc ( strlen(valString) + 1 )) != NULL, XLAL_ENOMEM ); strcpy ( valStringLower, valString ); XLALStringToLowerCase ( valStringLower ); /* parse it as a bool */ if ( !strcmp(valStringLower, "yes") || !strcmp(valStringLower, "true") || !strcmp(valStringLower, "1") ) { (*valBOOLEAN) = 1; } else if ( !strcmp(valStringLower, "no") || !strcmp(valStringLower, "false") || !strcmp(valStringLower, "0") ) { (*valBOOLEAN) = 0; } else { XLALFree ( valStringLower ); XLAL_ERROR ( XLAL_EINVAL, "Illegal bool-string '%s', needs to be one of {'yes', 'true', '1'} or {'no', 'false', '0'} (case-insensitive)\n", valString ); } XLALFree ( valStringLower ); return XLAL_SUCCESS; } // XLALParseStringValueAsBOOLEAN()