Commit 251db281 authored by Karl Wette's avatar Karl Wette
Browse files

UserInput: extend user variable help string to a printf() format

- XLALRegister<...>UserVar() functions now take 'cvar' pointer as first argument
- Requires a literal string for help
- XLALFstatMethodHelpString() now just returns list of F-statistic methods
- Refs #3514
Original: 331af742df01a9c1886b9908f14d70714f455897
parent ca4b7de9
...@@ -41,9 +41,14 @@ ...@@ -41,9 +41,14 @@
// ----- macro template for defining registration functions for UserInput variables // ----- macro template for defining registration functions for UserInput variables
#define DEFN_REGISTER_UVAR(UTYPE,CTYPE) \ #define DEFN_REGISTER_UVAR(UTYPE,CTYPE) \
DECL_REGISTER_UVAR(UTYPE,CTYPE) \ int XLALRegister ##UTYPE## UserVar ( CTYPE *cvar, const CHAR *name, CHAR optchar, UserVarCategory category, const CHAR *fmt, ... ) \
{ \ { \
return XLALRegisterUserVar (name, UVAR_TYPE_ ## UTYPE, optchar, category, helpstr, cvar); \ char helpstr[2048]; \
va_list ap; \
va_start(ap, fmt); \
vsnprintf(helpstr, sizeof(helpstr), fmt, ap); \
va_end(ap); \
return XLALRegisterUserVar (cvar, name, UVAR_TYPE_ ## UTYPE, optchar, category, helpstr); \
} }
// ---------- local type definitions ---------- // ---------- local type definitions ----------
...@@ -74,7 +79,7 @@ typedef struct tagLALUserVariable { ...@@ -74,7 +79,7 @@ typedef struct tagLALUserVariable {
CHAR name[64]; // full name CHAR name[64]; // full name
UserVarType type; // variable type: BOOLEAN, INT4, REAL8, ... UserVarType type; // variable type: BOOLEAN, INT4, REAL8, ...
CHAR optchar; // cmd-line character CHAR optchar; // cmd-line character
const CHAR *help; // help-string CHAR help[2048]; // help-string
void *varp; // pointer to the actual C-variable void *varp; // pointer to the actual C-variable
UserVarCategory category; // category (optional, required, developer, ... ) UserVarCategory category; // category (optional, required, developer, ... )
BOOLEAN was_set; // was this set by the user in any way? (ie vie cmdline or cfg-file) BOOLEAN was_set; // was this set by the user in any way? (ie vie cmdline or cfg-file)
...@@ -82,7 +87,7 @@ typedef struct tagLALUserVariable { ...@@ -82,7 +87,7 @@ typedef struct tagLALUserVariable {
} LALUserVariable; } LALUserVariable;
// ---------- local prototypes ---------- // ---------- local prototypes ----------
int XLALRegisterUserVar (const CHAR *name, UserVarType type, CHAR optchar, UserVarCategory category, const CHAR *helpstr, void *cvar); int XLALRegisterUserVar (void *cvar, const CHAR *name, UserVarType type, CHAR optchar, UserVarCategory category, const CHAR *helpstr);
void check_and_mark_as_set ( LALUserVariable *ptr ); void check_and_mark_as_set ( LALUserVariable *ptr );
// ----- define templated registration functions for all supported UVAR_TYPE_ 'UTYPES' // ----- define templated registration functions for all supported UVAR_TYPE_ 'UTYPES'
...@@ -164,18 +169,19 @@ static const CHAR *program_name; // keep a pointer to the program name ...@@ -164,18 +169,19 @@ static const CHAR *program_name; // keep a pointer to the program name
* ==> use the type-safe macro XLALRegisterUvarMember(name,type,option,category,help) instead! * ==> use the type-safe macro XLALRegisterUvarMember(name,type,option,category,help) instead!
*/ */
int int
XLALRegisterUserVar ( const CHAR *name, /**< name of user-variable to register */ XLALRegisterUserVar ( void *cvar, /**< pointer to the actual C-variabe to link to this user-variable */
const CHAR *name, /**< name of user-variable to register */
UserVarType type, /**< variable type (int,bool,string,real) */ UserVarType type, /**< variable type (int,bool,string,real) */
CHAR optchar, /**< optional short-option character */ CHAR optchar, /**< optional short-option character */
UserVarCategory category, /**< sets category to this */ UserVarCategory category, /**< sets category to this */
const CHAR *helpstr, /**< help-string explaining this input-variable */ const CHAR *helpstr /**< help-string explaining this input-variable */
void *cvar /**< pointer to the actual C-variabe to link to this user-variable */
) )
{ {
XLAL_CHECK ( cvar != NULL, XLAL_EINVAL );
XLAL_CHECK ( name != NULL, XLAL_EINVAL ); XLAL_CHECK ( name != NULL, XLAL_EINVAL );
XLAL_CHECK ( strlen(name) < sizeof(UVAR_vars.name), XLAL_EINVAL, "User-variable name '%s' is too long", name ); XLAL_CHECK ( strlen(name) < sizeof(UVAR_vars.name), XLAL_EINVAL, "User-variable name '%s' is too long", name );
XLAL_CHECK ( (category > UVAR_CATEGORY_START) && (category < UVAR_CATEGORY_END), XLAL_EINVAL ); XLAL_CHECK ( (category > UVAR_CATEGORY_START) && (category < UVAR_CATEGORY_END), XLAL_EINVAL );
XLAL_CHECK ( cvar != NULL, XLAL_EINVAL ); XLAL_CHECK ( strlen(helpstr) < sizeof(UVAR_vars.help), XLAL_EINVAL, "User-variable help '%s' is too long", helpstr );
// find end of uvar-list && check that neither short- nor long-option are taken already // find end of uvar-list && check that neither short- nor long-option are taken already
LALUserVariable *ptr = &UVAR_vars; LALUserVariable *ptr = &UVAR_vars;
...@@ -199,11 +205,11 @@ XLALRegisterUserVar ( const CHAR *name, /**< name of user-variable to register ...@@ -199,11 +205,11 @@ XLALRegisterUserVar ( const CHAR *name, /**< name of user-variable to register
// fill in entry name, replacing '_' with '-' so // fill in entry name, replacing '_' with '-' so
// that e.g. uvar->an_option maps to --an-option // that e.g. uvar->an_option maps to --an-option
XLALStringReplaceChar( strncpy( ptr->name, name, sizeof(ptr->name) ), '_', '-' ); XLALStringReplaceChar( strncpy( ptr->name, name, sizeof(ptr->name) ), '_', '-' );
strncpy( ptr->help, helpstr, sizeof(ptr->help) );
// fill in entry values // fill in entry values
ptr->type = type; ptr->type = type;
ptr->optchar = optchar; ptr->optchar = optchar;
ptr->help = helpstr;
ptr->varp = cvar; ptr->varp = cvar;
ptr->category = category; ptr->category = category;
...@@ -929,7 +935,7 @@ LALRegisterREALUserVar (LALStatus *status, ...@@ -929,7 +935,7 @@ LALRegisterREALUserVar (LALStatus *status,
REAL8 *cvar) REAL8 *cvar)
{ {
INITSTATUS(status); INITSTATUS(status);
if ( XLALRegisterUserVar ( name, UVAR_TYPE_REAL8, optchar, category, helpstr, cvar ) != XLAL_SUCCESS ) { if ( XLALRegisterUserVar ( cvar, name, UVAR_TYPE_REAL8, optchar, category, helpstr ) != XLAL_SUCCESS ) {
XLALPrintError ("Call to XLALRegisterUserVar() failed: %d\n", xlalErrno ); XLALPrintError ("Call to XLALRegisterUserVar() failed: %d\n", xlalErrno );
ABORT ( status, USERINPUTH_EXLAL, USERINPUTH_MSGEXLAL ); ABORT ( status, USERINPUTH_EXLAL, USERINPUTH_MSGEXLAL );
} }
...@@ -946,7 +952,7 @@ LALRegisterINTUserVar (LALStatus *status, ...@@ -946,7 +952,7 @@ LALRegisterINTUserVar (LALStatus *status,
INT4 *cvar) INT4 *cvar)
{ {
INITSTATUS(status); INITSTATUS(status);
if ( XLALRegisterUserVar ( name, UVAR_TYPE_INT4, optchar, category, helpstr, cvar ) != XLAL_SUCCESS ) { if ( XLALRegisterUserVar ( cvar, name, UVAR_TYPE_INT4, optchar, category, helpstr ) != XLAL_SUCCESS ) {
XLALPrintError ("Call to XLALRegisterUserVar() failed: %d\n", xlalErrno ); XLALPrintError ("Call to XLALRegisterUserVar() failed: %d\n", xlalErrno );
ABORT ( status, USERINPUTH_EXLAL, USERINPUTH_MSGEXLAL ); ABORT ( status, USERINPUTH_EXLAL, USERINPUTH_MSGEXLAL );
} }
...@@ -963,7 +969,7 @@ LALRegisterBOOLUserVar (LALStatus *status, ...@@ -963,7 +969,7 @@ LALRegisterBOOLUserVar (LALStatus *status,
BOOLEAN *cvar) BOOLEAN *cvar)
{ {
INITSTATUS(status); INITSTATUS(status);
if ( XLALRegisterUserVar ( name, UVAR_TYPE_BOOLEAN, optchar, category, helpstr, cvar ) != XLAL_SUCCESS ) { if ( XLALRegisterUserVar ( cvar, name, UVAR_TYPE_BOOLEAN, optchar, category, helpstr ) != XLAL_SUCCESS ) {
XLALPrintError ("Call to XLALRegisterUserVar() failed: %d\n", xlalErrno ); XLALPrintError ("Call to XLALRegisterUserVar() failed: %d\n", xlalErrno );
ABORT ( status, USERINPUTH_EXLAL, USERINPUTH_MSGEXLAL ); ABORT ( status, USERINPUTH_EXLAL, USERINPUTH_MSGEXLAL );
} }
...@@ -980,7 +986,7 @@ LALRegisterSTRINGUserVar (LALStatus *status, ...@@ -980,7 +986,7 @@ LALRegisterSTRINGUserVar (LALStatus *status,
CHAR **cvar) CHAR **cvar)
{ {
INITSTATUS(status); INITSTATUS(status);
if ( XLALRegisterUserVar ( name, UVAR_TYPE_STRING, optchar, category, helpstr, cvar ) != XLAL_SUCCESS ) { if ( XLALRegisterUserVar ( cvar, name, UVAR_TYPE_STRING, optchar, category, helpstr ) != XLAL_SUCCESS ) {
XLALPrintError ("Call to XLALRegisterUserVar() failed: %d\n", xlalErrno ); XLALPrintError ("Call to XLALRegisterUserVar() failed: %d\n", xlalErrno );
ABORT ( status, USERINPUTH_EXLAL, USERINPUTH_MSGEXLAL ); ABORT ( status, USERINPUTH_EXLAL, USERINPUTH_MSGEXLAL );
} }
...@@ -997,7 +1003,7 @@ LALRegisterLISTUserVar (LALStatus *status, ...@@ -997,7 +1003,7 @@ LALRegisterLISTUserVar (LALStatus *status,
LALStringVector **cvar) LALStringVector **cvar)
{ {
INITSTATUS(status); INITSTATUS(status);
if ( XLALRegisterUserVar ( name, UVAR_TYPE_STRINGVector, optchar, category, helpstr, cvar ) != XLAL_SUCCESS ) { if ( XLALRegisterUserVar ( cvar, name, UVAR_TYPE_STRINGVector, optchar, category, helpstr ) != XLAL_SUCCESS ) {
XLALPrintError ("Call to XLALRegisterUserVar() failed: %d\n", xlalErrno ); XLALPrintError ("Call to XLALRegisterUserVar() failed: %d\n", xlalErrno );
ABORT ( status, USERINPUTH_EXLAL, USERINPUTH_MSGEXLAL ); ABORT ( status, USERINPUTH_EXLAL, USERINPUTH_MSGEXLAL );
} }
......
...@@ -153,8 +153,8 @@ someEpoch = {2147483596 s, 816000000 ns}, RA = 2.727813 rad, DEC = -0.523599 rad ...@@ -153,8 +153,8 @@ someEpoch = {2147483596 s, 816000000 ns}, RA = 2.727813 rad, DEC = -0.523599 rad
* Shortcut Macro for registering new user variables, which are assumed * Shortcut Macro for registering new user variables, which are assumed
* to be accessible via the \e struct-pointer '*uvar' * to be accessible via the \e struct-pointer '*uvar'
*/ */
#define XLALRegisterUvarMember(name,type,option,category,help) \ #define XLALRegisterUvarMember(name,type,option,category,...) \
XLALRegister ##type## UserVar( #name, option, UVAR_CATEGORY_ ## category, help, &(uvar-> name)) XLALRegister ##type## UserVar( &(uvar-> name), #name, option, UVAR_CATEGORY_ ## category, __VA_ARGS__)
/// (mutually exclusive) UserVariable categories: optional, required, help, developer, ... /// (mutually exclusive) UserVariable categories: optional, required, help, developer, ...
typedef enum { typedef enum {
...@@ -251,7 +251,7 @@ CHAR * XLALUserVarGetLog ( UserVarLogFormat format ); ...@@ -251,7 +251,7 @@ CHAR * XLALUserVarGetLog ( UserVarLogFormat format );
// declare type-specific wrappers to XLALRegisterUserVar() to allow for strict C type-checking! // declare type-specific wrappers to XLALRegisterUserVar() to allow for strict C type-checking!
#define DECL_REGISTER_UVAR(UTYPE,CTYPE) \ #define DECL_REGISTER_UVAR(UTYPE,CTYPE) \
int XLALRegister ##UTYPE## UserVar ( const CHAR *name, CHAR optchar, UserVarCategory category, const CHAR *helpstr, CTYPE *cvar ) int XLALRegister ##UTYPE## UserVar ( CTYPE *cvar, const CHAR *name, CHAR optchar, UserVarCategory category, const CHAR *fmt, ... ) _LAL_GCC_PRINTF_FORMAT_(5,6)
// ------ declare registration functions // ------ declare registration functions
DECL_REGISTER_UVAR(REAL8,REAL8); DECL_REGISTER_UVAR(REAL8,REAL8);
......
...@@ -1026,7 +1026,7 @@ initUserVars ( UserInput_t *uvar ) ...@@ -1026,7 +1026,7 @@ initUserVars ( UserInput_t *uvar )
XLALRegisterUvarMember( transient_tauDaysBand,REAL8, 0, OPTIONAL, "TransientCW: Range of transient-CW duration timescales to search, in days"); XLALRegisterUvarMember( transient_tauDaysBand,REAL8, 0, OPTIONAL, "TransientCW: Range of transient-CW duration timescales to search, in days");
XLALRegisterUvarMember( transient_dtau, INT4, 0, OPTIONAL, "TransientCW: Step-size in transient-CW duration timescale, in seconds [Default:Tsft]"); XLALRegisterUvarMember( transient_dtau, INT4, 0, OPTIONAL, "TransientCW: Step-size in transient-CW duration timescale, in seconds [Default:Tsft]");
XLALRegisterUvarMember(FstatMethod, STRING, 0, OPTIONAL, XLALFstatMethodHelpString() ); XLALRegisterUvarMember(FstatMethod, STRING, 0, OPTIONAL, "F-statistic method to use. Available methods: %s", XLALFstatMethodHelpString() );
XLALRegisterUvarMember( version, BOOLEAN, 'V', SPECIAL, "Output version information"); XLALRegisterUvarMember( version, BOOLEAN, 'V', SPECIAL, "Output version information");
......
...@@ -411,6 +411,7 @@ int MAIN( int argc, char *argv[]) { ...@@ -411,6 +411,7 @@ int MAIN( int argc, char *argv[]) {
CHAR *uvar_outputTiming = NULL; CHAR *uvar_outputTiming = NULL;
CHAR helpstr_buf[2048];
CHAR *uvar_FstatMethod = XLALStringDuplicate("DemodBest"); CHAR *uvar_FstatMethod = XLALStringDuplicate("DemodBest");
CHAR *uvar_FstatMethodRecalc = XLALStringDuplicate("DemodBest"); CHAR *uvar_FstatMethodRecalc = XLALStringDuplicate("DemodBest");
...@@ -496,8 +497,10 @@ int MAIN( int argc, char *argv[]) { ...@@ -496,8 +497,10 @@ int MAIN( int argc, char *argv[]) {
LAL_CALL( LALRegisterBOOLUserVar( &status, "BSGLlogcorr", 0, UVAR_DEVELOPER, "BSGL: include log-correction terms (slower) or not (faster)", &uvar_BSGLlogcorr), &status); LAL_CALL( LALRegisterBOOLUserVar( &status, "BSGLlogcorr", 0, UVAR_DEVELOPER, "BSGL: include log-correction terms (slower) or not (faster)", &uvar_BSGLlogcorr), &status);
// -------------------------------------------- // --------------------------------------------
LAL_CALL( LALRegisterSTRINGUserVar( &status, "FstatMethod", 0, UVAR_OPTIONAL, XLALFstatMethodHelpString(), &uvar_FstatMethod ), &status); snprintf( helpstr_buf, sizeof(helpstr_buf), "F-statistic method to use. Available methods: %s", XLALFstatMethodHelpString() );
LAL_CALL( LALRegisterSTRINGUserVar( &status, "FstatMethodRecalc", 0, UVAR_OPTIONAL, XLALFstatMethodHelpString(), &uvar_FstatMethodRecalc ), &status); LAL_CALL( LALRegisterSTRINGUserVar( &status, "FstatMethod", 0, UVAR_OPTIONAL, helpstr_buf, &uvar_FstatMethod ), &status);
snprintf( helpstr_buf, sizeof(helpstr_buf), "F-statistic method to use for recalc. Available methods: %s", XLALFstatMethodHelpString() );
LAL_CALL( LALRegisterSTRINGUserVar( &status, "FstatMethodRecalc", 0, UVAR_OPTIONAL, helpstr_buf, &uvar_FstatMethodRecalc ), &status);
/* developer user variables */ /* developer user variables */
LAL_CALL( LALRegisterINTUserVar( &status, "blocksRngMed", 0, UVAR_DEVELOPER, "RngMed block size", &uvar_blocksRngMed), &status); LAL_CALL( LALRegisterINTUserVar( &status, "blocksRngMed", 0, UVAR_DEVELOPER, "RngMed block size", &uvar_blocksRngMed), &status);
LAL_CALL( LALRegisterINTUserVar ( &status, "SSBprecision", 0, UVAR_DEVELOPER, "Precision for SSB transform.", &uvar_SSBprecision), &status); LAL_CALL( LALRegisterINTUserVar ( &status, "SSBprecision", 0, UVAR_DEVELOPER, "Precision for SSB transform.", &uvar_SSBprecision), &status);
......
...@@ -925,9 +925,7 @@ XLALFstatMethodHelpString ( void ) ...@@ -925,9 +925,7 @@ XLALFstatMethodHelpString ( void )
static CHAR helpstr[1024]; static CHAR helpstr[1024];
if ( firstCall ) if ( firstCall )
{ {
XLAL_LAST_ELEM ( helpstr ) = '\0'; XLAL_INIT_MEM ( helpstr );
strcpy ( helpstr, "Available methods:" );
CHAR separator = ' ';
for (int i = FMETHOD_START + 1; i < FMETHOD_END; i++ ) for (int i = FMETHOD_START + 1; i < FMETHOD_END; i++ )
{ {
if ( ! XLALFstatMethodIsAvailable(i) ) { if ( ! XLALFstatMethodIsAvailable(i) ) {
...@@ -936,11 +934,10 @@ XLALFstatMethodHelpString ( void ) ...@@ -936,11 +934,10 @@ XLALFstatMethodHelpString ( void )
XLAL_CHECK_NULL ( FstatMethodNames[i] != NULL, XLAL_EFAULT ); XLAL_CHECK_NULL ( FstatMethodNames[i] != NULL, XLAL_EFAULT );
if ( strcmp ( FstatMethodNames[i] + strlen(FstatMethodNames[i]) - 4, "Best" ) == 0 ) { if ( strcmp ( FstatMethodNames[i] + strlen(FstatMethodNames[i]) - 4, "Best" ) == 0 ) {
strcat ( helpstr, "=" ); strcat ( helpstr, "=" );
} else { } else if ( i > FMETHOD_START + 1 ) {
strncat ( helpstr, &separator, 1 ); strcat ( helpstr, "|" );
} }
strcat ( helpstr, FstatMethodNames[i] ); strcat ( helpstr, FstatMethodNames[i] );
separator = '|';
} // for i < FMETHOD_LAST } // for i < FMETHOD_LAST
XLAL_CHECK_NULL ( XLAL_LAST_ELEM ( helpstr ) == '\0', XLAL_EBADLEN, "FstatMethod help-string exceeds buffer length (%zu)\n", sizeof(helpstr) ); XLAL_CHECK_NULL ( XLAL_LAST_ELEM ( helpstr ) == '\0', XLAL_EBADLEN, "FstatMethod help-string exceeds buffer length (%zu)\n", sizeof(helpstr) );
......
...@@ -83,7 +83,7 @@ main ( int argc, char *argv[] ) ...@@ -83,7 +83,7 @@ main ( int argc, char *argv[] )
uvar->outputInfo = NULL; uvar->outputInfo = NULL;
XLAL_CHECK ( XLALRegisterUvarMember ( help, BOOLEAN, 'h', HELP, "Print help message" ) == XLAL_SUCCESS, XLAL_EFUNC ); XLAL_CHECK ( XLALRegisterUvarMember ( help, BOOLEAN, 'h', HELP, "Print help message" ) == XLAL_SUCCESS, XLAL_EFUNC );
XLAL_CHECK ( XLALRegisterUvarMember ( FstatMethod, STRING, 0, OPTIONAL, XLALFstatMethodHelpString() ) == XLAL_SUCCESS, XLAL_EFUNC ); XLAL_CHECK ( XLALRegisterUvarMember ( FstatMethod, STRING, 0, OPTIONAL, "F-statistic method to use. Available methods: %s", XLALFstatMethodHelpString() ) == XLAL_SUCCESS, XLAL_EFUNC );
XLAL_CHECK ( XLALRegisterUvarMember ( Freq, REAL8, 0, OPTIONAL, "Search frequency in Hz" ) == XLAL_SUCCESS, XLAL_EFUNC ); XLAL_CHECK ( XLALRegisterUvarMember ( Freq, REAL8, 0, OPTIONAL, "Search frequency in Hz" ) == XLAL_SUCCESS, XLAL_EFUNC );
XLAL_CHECK ( XLALRegisterUvarMember ( f1dot, REAL8, 0, OPTIONAL, "Search spindown f1dot in Hz/s" ) == XLAL_SUCCESS, XLAL_EFUNC ); XLAL_CHECK ( XLALRegisterUvarMember ( f1dot, REAL8, 0, OPTIONAL, "Search spindown f1dot in Hz/s" ) == XLAL_SUCCESS, XLAL_EFUNC );
XLAL_CHECK ( XLALRegisterUvarMember ( FreqResolution, REAL8Vector, 0, OPTIONAL, "Range of frequency resolution factor 'r' (st dFreq = 1/(r*T)) [2-number range input]" ) == XLAL_SUCCESS, XLAL_EFUNC ); XLAL_CHECK ( XLALRegisterUvarMember ( FreqResolution, REAL8Vector, 0, OPTIONAL, "Range of frequency resolution factor 'r' (st dFreq = 1/(r*T)) [2-number range input]" ) == XLAL_SUCCESS, XLAL_EFUNC );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment