wmail: added command-line option to specify a different config-file.

This commit is contained in:
Jeremy Sowden 2019-06-12 21:37:21 +01:00 committed by Carlos R. Mafra
parent 7590c32f82
commit 6e48b4a431
4 changed files with 219 additions and 195 deletions

View file

@ -132,6 +132,11 @@ Description:
rc-file statement: Colors.NonShapedFrame = "<string>" rc-file statement: Colors.NonShapedFrame = "<string>"
default value : <unset, this color is translucent> default value : <unset, this color is translucent>
item : rc-file location
cmd-line option : -rc <path>
rc-file statement: <none>
default value : "~/.wmailrc"
libdockapp provides the following additional cmd-line options: libdockapp provides the following additional cmd-line options:
windowed-mode : -w windowed-mode : -w
@ -206,8 +211,7 @@ Install:
your X11 base library directory or let $LD_LIBRARY_PATH point to the lib). your X11 base library directory or let $LD_LIBRARY_PATH point to the lib).
If you would like to use rc-based configuration, look into the provided If you would like to use rc-based configuration, look into the provided
sample-file "wmailrc-sample" and use it as a base for your particular needs sample-file "wmailrc-sample" and use it as a base for your particular needs
by copying it to ~/.wmailrc. Note: the name of this rc-file is hard-wired and by copying it to ~/.wmailrc.
cannot be customized.
Run: Run:

View file

@ -234,21 +234,13 @@ static void PostProcessConfiguration( void )
} }
} }
void ReadConfigFile( bool resetConfigStrings ) void ReadConfigFile( const char *configFile, bool resetConfigStrings )
{ {
char *usersHome;
// free all config strings and reset their pointers if required // free all config strings and reset their pointers if required
if( resetConfigStrings ) if( resetConfigStrings )
ResetConfigStrings(); ResetConfigStrings();
if(( usersHome = getenv( "HOME" )) != NULL ) FILE *f = fopen( configFile, "r" );
{
char *fileName;
if(( fileName = MakePathName( usersHome, WMAIL_RC_FILE )) != NULL )
{
FILE *f = fopen( fileName, "rt" );
if( f != NULL ) if( f != NULL )
{ {
char buf[1024]; char buf[1024];
@ -414,15 +406,7 @@ void ReadConfigFile( bool resetConfigStrings )
fclose( f ); fclose( f );
} else { } else {
TRACE( "unable to open config-file \"%s\"\n", fileName ); TRACE( "unable to open config-file \"%s\"\n", configFile );
}
free( fileName );
} else {
TRACE( "unable to allocate config-file\n" );
}
} else {
TRACE( "no $HOME defined - config-file not read\n" );
} }
PostProcessConfiguration(); PostProcessConfiguration();

View file

@ -67,7 +67,8 @@ enum {
CL_CMDONMAIL = 1<<15, CL_CMDONMAIL = 1<<15,
CL_CONSIDERSTATUSFIELD = 1<<16, CL_CONSIDERSTATUSFIELD = 1<<16,
CL_READSTATUS = 1<<17, CL_READSTATUS = 1<<17,
CL_USEX11FONT = 1<<18 CL_USEX11FONT = 1<<18,
CL_CONFIGFILE = 1<<19
}; };
typedef struct _config_t { typedef struct _config_t {
@ -100,7 +101,7 @@ typedef struct _config_t {
extern config_t config; extern config_t config;
// config manipulation functions // config manipulation functions
void ReadConfigFile( bool resetConfigStrings ); void ReadConfigFile( const char *configFile, bool resetConfigStrings );
void ResetConfigStrings( void ); void ResetConfigStrings( void );

View file

@ -115,6 +115,7 @@ typedef enum {
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// data // data
static char *configFile;
static unsigned long lastTimeOut; static unsigned long lastTimeOut;
static sig_atomic_t caughtSig; static sig_atomic_t caughtSig;
static mail_state_t state; static mail_state_t state;
@ -158,7 +159,8 @@ enum
OPT_INDEX_EXECUTE, OPT_INDEX_EXECUTE,
OPT_INDEX_STATUS_FIELD, OPT_INDEX_STATUS_FIELD,
OPT_INDEX_READ_STATUS, OPT_INDEX_READ_STATUS,
OPT_INDEX_TICKER_FONT OPT_INDEX_TICKER_FONT,
OPT_INDEX_CONFIG_FILE,
}; };
static DAProgramOption options[] = { static DAProgramOption options[] = {
@ -276,6 +278,13 @@ static DAProgramOption options[] = {
.description = "use specified X11 font to draw the ticker", .description = "use specified X11 font to draw the ticker",
.type = DOString, .type = DOString,
.value = { .string = &config.useX11Font } .value = { .string = &config.useX11Font }
},
[OPT_INDEX_CONFIG_FILE] = {
.shortForm = "-rc",
.longForm = "--rcfile",
.description = "specify another rc-file ($HOME/.wmailrc is default)",
.type = DOString,
.value = { .string = &configFile }
} }
}; };
@ -324,7 +333,7 @@ static bool HasTickerWork( void );
int main( int argc, char **argv ) int main( int argc, char **argv )
{ {
char *usersHome; char *usersHome = getenv( "HOME" );
struct sigaction sa = { .sa_handler = ExitHandler }; struct sigaction sa = { .sa_handler = ExitHandler };
struct stat fileStat; struct stat fileStat;
XTextProperty windowName; XTextProperty windowName;
@ -383,22 +392,46 @@ int main( int argc, char **argv )
if( options[OPT_INDEX_TICKER_FONT].used ) if( options[OPT_INDEX_TICKER_FONT].used )
config.givenOptions |= CL_USEX11FONT; config.givenOptions |= CL_USEX11FONT;
if( configFile == NULL)
{
if( usersHome == NULL)
{
WARNING( "HOME environment-variable is not set, looking for %s in current directory!\n",
WMAIL_RC_FILE );
configFile = strdup( WMAIL_RC_FILE );
}
else
configFile = MakePathName( usersHome, WMAIL_RC_FILE );
if( configFile == NULL )
{
WARNING( "Cannot allocate config file-name.\n");
exit( EXIT_FAILURE );
}
}
TRACE( "%s: configFile = %s\n", __func__, configFile );
// read the config file // read the config file
ReadConfigFile( false ); ReadConfigFile( configFile, false );
if( config.checksumFileName == NULL ) { if( config.checksumFileName == NULL ) {
if(( usersHome = getenv( "HOME" )) == NULL ) { if( usersHome == NULL )
WARNING( "HOME environment-variable is not set, placing %s in current directory!\n", WMAIL_CHECKSUM_FILE ); {
WARNING( "HOME environment-variable is not set, placing %s in current directory!\n",
WMAIL_CHECKSUM_FILE );
config.checksumFileName = strdup( WMAIL_CHECKSUM_FILE ); config.checksumFileName = strdup( WMAIL_CHECKSUM_FILE );
} else
config.checksumFileName = MakePathName( usersHome, WMAIL_CHECKSUM_FILE );
} }
else
config.checksumFileName = MakePathName( usersHome, WMAIL_CHECKSUM_FILE );
if( config.checksumFileName == NULL ) if( config.checksumFileName == NULL )
{ {
WARNING( "Cannot allocate checksum file-name.\n"); WARNING( "Cannot allocate checksum file-name.\n");
exit( EXIT_FAILURE ); exit( EXIT_FAILURE );
} }
}
TRACE( "using checksum-file \"%s\"\n", config.checksumFileName ); TRACE( "using checksum-file \"%s\"\n", config.checksumFileName );
@ -672,6 +705,8 @@ static void TimedOut( void )
if( caughtSig ) { if( caughtSig ) {
ClearAllNames(); ClearAllNames();
ResetConfigStrings(); ResetConfigStrings();
if( !options[OPT_INDEX_CONFIG_FILE].used )
free( configFile );
exit( EXIT_SUCCESS ); exit( EXIT_SUCCESS );
} }
@ -1472,7 +1507,7 @@ static void UpdateConfiguration( void )
TRACE( "reading configuration file...\n" ); TRACE( "reading configuration file...\n" );
ReadConfigFile( true ); ReadConfigFile( configFile, true );
// if no path/name to an mbox or maildir inbox directory was given, // if no path/name to an mbox or maildir inbox directory was given,
// use the environment // use the environment