- Fixed option processing of bool options in config file.
- Tried to make option order more consistent
This commit is contained in:
@@ -193,7 +193,7 @@ typedef struct lcd_logical_driver {
|
||||
/* Configfile functions */
|
||||
/* See configfile.h for descriptions and usage. */
|
||||
|
||||
unsigned char (*config_get_bool)( char *sectionname, char *keyname, int skip, unsigned char default_value );
|
||||
short (*config_get_bool)( char *sectionname, char *keyname, int skip, short default_value );
|
||||
long int (*config_get_int) ( char *sectionname, char *keyname, int skip, long int default_value );
|
||||
double (*config_get_float) ( char *sectionname, char *keyname, int skip, double default_value );
|
||||
char *( *config_get_string) ( char *sectionname, char *keyname, int skip, char *default_value );
|
||||
|
||||
+37
-51
@@ -275,33 +275,28 @@ process_command_line (int argc, char **argv)
|
||||
optind = 0;
|
||||
opterr = 0; /* Prevent some message to strerr */
|
||||
|
||||
/* analyze options here..*/
|
||||
while ((c = getopt(argc, argv, "ha:p:f:i:b:w:c:u:s:r:")) > 0) {
|
||||
/* Analyze options here.. (please try to keep list of options the
|
||||
* same everywhere) */
|
||||
while ((c = getopt(argc, argv, "hc:d:f:a:p:u:w:s:r:i:" )) > 0) {
|
||||
switch(c) {
|
||||
case 'h':
|
||||
help = 1; /* Continue to process the other
|
||||
* options */
|
||||
break;
|
||||
case 'c':
|
||||
strncpy(configfile, optarg, sizeof(configfile));
|
||||
configfile[sizeof(configfile)-1] = 0; /* Terminate string */
|
||||
break;
|
||||
case 'd':
|
||||
/* Add to a list of drivers to be initialized later...*/
|
||||
if (num_drivers < MAX_DRIVERS) {
|
||||
drivernames[num_drivers] = malloc( strlen(optarg)+1 );
|
||||
strcpy( drivernames[num_drivers], optarg );
|
||||
num_drivers ++;
|
||||
} else
|
||||
} else {
|
||||
report( RPT_ERR, "Too many drivers!" );
|
||||
e = -1;
|
||||
break;
|
||||
case 'p':
|
||||
lcd_port = atoi(optarg);
|
||||
break;
|
||||
case 'u':
|
||||
strncpy(user, optarg, sizeof(user));
|
||||
user[sizeof(user)-1] = 0; /* Terminate string */
|
||||
break;
|
||||
case 'a':
|
||||
strncpy(bind_addr, optarg, sizeof(bind_addr));
|
||||
bind_addr[sizeof(bind_addr)-1] = 0; /* Terminate string */
|
||||
break;
|
||||
case 'h':
|
||||
help = 1; /* Continue to process the other
|
||||
* options */
|
||||
}
|
||||
break;
|
||||
case 'f':
|
||||
b = interpret_boolean_arg( optarg );
|
||||
@@ -312,40 +307,23 @@ process_command_line (int argc, char **argv)
|
||||
daemon_mode = !b;
|
||||
}
|
||||
break;
|
||||
case 'c':
|
||||
strncpy(configfile, optarg, sizeof(configfile));
|
||||
configfile[sizeof(configfile)-1] = 0; /* Terminate string */
|
||||
case 'a':
|
||||
strncpy(bind_addr, optarg, sizeof(bind_addr));
|
||||
bind_addr[sizeof(bind_addr)-1] = 0; /* Terminate string */
|
||||
break;
|
||||
case 'i':
|
||||
b = interpret_boolean_arg( optarg );
|
||||
if( b == -1 ) {
|
||||
report( RPT_ERR, "Not a boolean value: '%s'", optarg );
|
||||
e = -1;
|
||||
} else {
|
||||
rotate_server_screen = b;
|
||||
}
|
||||
case 'p':
|
||||
lcd_port = atoi(optarg);
|
||||
break;
|
||||
case 'b':
|
||||
if( strcmp( optarg, "on" ) == 0 ) {
|
||||
backlight = BACKLIGHT_ON;
|
||||
}
|
||||
else if( strcmp( optarg, "off" ) == 0 ) {
|
||||
backlight = BACKLIGHT_OFF;
|
||||
}
|
||||
else if( strcmp( optarg, "open" ) == 0 ) {
|
||||
backlight = BACKLIGHT_OPEN;
|
||||
}
|
||||
else if( strcmp( optarg, "" ) != 0 ) {
|
||||
report( RPT_ERR, "Backlight state should be on, off or open" );
|
||||
e = -1;
|
||||
}
|
||||
case 'u':
|
||||
strncpy(user, optarg, sizeof(user));
|
||||
user[sizeof(user)-1] = 0; /* Terminate string */
|
||||
break;
|
||||
case 'w':
|
||||
default_duration = (int) (atof(optarg) * 1e6 / TIME_UNIT);
|
||||
if ( default_duration * TIME_UNIT < 2e6 ) {
|
||||
report( RPT_ERR, "Waittime should be at least 2 (seconds), not %.8s", optarg );
|
||||
e = -1;
|
||||
};
|
||||
}
|
||||
break;
|
||||
case 's':
|
||||
b = interpret_boolean_arg( optarg );
|
||||
@@ -359,6 +337,15 @@ process_command_line (int argc, char **argv)
|
||||
case 'r':
|
||||
report_level = atoi(optarg);
|
||||
break;
|
||||
case 'i':
|
||||
b = interpret_boolean_arg( optarg );
|
||||
if( b == -1 ) {
|
||||
report( RPT_ERR, "Not a boolean value: '%s'", optarg );
|
||||
e = -1;
|
||||
} else {
|
||||
rotate_server_screen = b;
|
||||
}
|
||||
break;
|
||||
case '?':
|
||||
/* For some reason getopt also returns an '?'
|
||||
* when an option argument is mission... */
|
||||
@@ -856,17 +843,12 @@ output_help_screen ()
|
||||
*/
|
||||
debug( RPT_DEBUG, "%s()", __FUNCTION__ );
|
||||
|
||||
fprintf (stdout, "\nLCDd: LCDproc Server Daemon, %s\n", version);
|
||||
fprintf (stdout, "LCDd: LCDproc Server Daemon, %s\n", version);
|
||||
fprintf (stdout, "Copyright (c) 1999-2003 Scott Scriven, William Ferrell, and misc contributors\n");
|
||||
fprintf (stdout, "This program is freely redistributable under the terms of the GNU Public License\n\n");
|
||||
|
||||
/* Actually set reporting settings and flush all report messages */
|
||||
set_reporting( "LCDd", report_level, (report_to_syslog?RPT_DEST_SYSLOG:RPT_DEST_STDERR) );
|
||||
|
||||
/* Now the actual help message */
|
||||
fprintf (stdout, "Usage: LCDd [ -h ] [ -c <config> ] [ -d <driver> ] [ -f <bool> ] \\\n");
|
||||
fprintf (stdout, "\t[-a <addr> ] [ -p <port> ] [ -u <user> ] [ -w <time> ]\\\n");
|
||||
fprintf (stdout, "\t[ -r <level> ] [ -s <bool> ] [ -u <user> ] [ -i <bool> ]\n\n");
|
||||
fprintf (stdout, "\t[ -r <level> ] [ -s <bool> ] [ -i <bool> ]\n\n");
|
||||
fprintf (stdout, "Available options are:\n");
|
||||
fprintf (stdout, "\t-h\t\tDisplay this help screen\n");
|
||||
fprintf (stdout, "\t-c <config>\tUse a configuration file other than %s\n", DEFAULT_CONFIGFILE);
|
||||
@@ -880,4 +862,8 @@ output_help_screen ()
|
||||
fprintf (stdout, "\t-r <level>\tReport level [%d]\n", DEFAULT_REPORTLEVEL);
|
||||
fprintf (stdout, "\t-i <bool>\tWhether to rotate the server info screen\n");
|
||||
fprintf (stdout, "\n");
|
||||
|
||||
/* Error messages will be flushed to the configured output after this
|
||||
* help message.
|
||||
*/
|
||||
}
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
*
|
||||
* The servermenu is created from servermenu.c
|
||||
*
|
||||
* For separation this file should never need to include menuscreen.h.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
@@ -33,6 +35,7 @@
|
||||
#include "drivers.h"
|
||||
|
||||
#include "screen.h"
|
||||
#include "widget.h"
|
||||
|
||||
Menu *
|
||||
menu_create (char *id, MenuEventFunc(*event_func),
|
||||
|
||||
+4
-4
@@ -127,8 +127,8 @@ char *config_get_string( char * sectionname, char * keyname,
|
||||
}
|
||||
|
||||
|
||||
unsigned char config_get_bool( char *sectionname, char *keyname,
|
||||
unsigned int skip, unsigned char default_value )
|
||||
short config_get_bool( char *sectionname, char *keyname,
|
||||
int skip, short default_value )
|
||||
{
|
||||
section * s;
|
||||
key * k;
|
||||
@@ -151,7 +151,7 @@ unsigned char config_get_bool( char *sectionname, char *keyname,
|
||||
|
||||
|
||||
long int config_get_int( char *sectionname, char *keyname,
|
||||
unsigned int skip, long int default_value )
|
||||
int skip, long int default_value )
|
||||
{
|
||||
section * s;
|
||||
key * k;
|
||||
@@ -173,7 +173,7 @@ long int config_get_int( char *sectionname, char *keyname,
|
||||
|
||||
|
||||
double config_get_float( char *sectionname, char *keyname,
|
||||
unsigned int skip, double default_value )
|
||||
int skip, double default_value )
|
||||
{
|
||||
section * s;
|
||||
key * k;
|
||||
|
||||
+2
-2
@@ -32,8 +32,8 @@ int config_read_string( char *sectionname, char *str );
|
||||
* Returns -16 if a malloc went wrong.
|
||||
*/
|
||||
|
||||
unsigned char config_get_bool( char *sectionname, char *keyname,
|
||||
int skip, unsigned char default_value );
|
||||
short config_get_bool( char *sectionname, char *keyname,
|
||||
int skip, short default_value );
|
||||
/* Tries to interpret a value in the config file as a boolean.
|
||||
* 0, false, no, n = false
|
||||
* 1, true, yes, y = true
|
||||
|
||||
Reference in New Issue
Block a user