fix a few warnings; tighten arg checks; harmonize -f handling: it is a simple flag!

This commit is contained in:
marschap
2006-04-28 17:10:25 +00:00
parent ff0e33b82f
commit ecc9320b54
8 changed files with 218 additions and 225 deletions
+1
View File
@@ -120,6 +120,7 @@ int read_connect_string()
report(RPT_ERR, "Received invalid LCDd connect response.");
return -1;
}
return 0;
}
int read_response(char * buf, int maxsize)
+20 -23
View File
@@ -38,7 +38,7 @@ char * help_text =
" -c <file>\tSpecify a configfile to load ["DEFAULT_CONFIGFILE"]\n"
" -a <address>\tDNS name or IP address of the LCDd server [localhost]\n"
" -p <port>\tPort of the LCDd server [13666]\n"
" -f <0|1>\tRun in 1=foreground or 0=background\n"
" -f \tRun in foreground\n"
" -r <level>\tSet reporting level (0-5) [2: errors and warnings]\n"
" -s <0|1>\tReport to 1=syslog or 0=stderr\n"
" -h\t\tShow this help\n";
@@ -95,14 +95,15 @@ int main( int argc, char ** argv )
int process_command_line( int argc, char ** argv )
{
char c;
char * p;
int temp_int;
int error = 0;
/* No error output from getopt */
opterr = 0;
while ((c = getopt(argc, argv, "hc:a:p:f:r:s:")) > 0) {
while ((c = getopt(argc, argv, "hc:a:p:fr:s:")) > 0) {
char *end;
int temp_int;
switch (c) {
case 'h':
fprintf(stderr, "%s", help_text);
@@ -114,38 +115,33 @@ int process_command_line( int argc, char ** argv )
address = strdup(optarg);
break;
case 'p':
temp_int = strtol(optarg, &p, 0);
if ( *optarg != 0 && *p == 0) {
temp_int = strtol(optarg, &end, 0);
if ((*optarg != '\0') && (*end == '\0') &&
(temp_int > 0) && (temp_int <= 0xFFFF)) {
port = temp_int;
} else {
report(RPT_ERR, "Could not interpret value for -%c", c);
report(RPT_ERR, "Illegal port value %s", optarg);
error = -1;
}
break;
case 'f':
temp_int = strtol(optarg, &p, 0);
if (*optarg != 0 && *p == 0) {
foreground_mode = temp_int;
} else {
report(RPT_ERR, "Could not interpret value for -%c", c);
error = -1;
}
foreground_mode = 1;
break;
case 'r':
temp_int = strtol(optarg, &p, 0);
if (*optarg != 0 && *p == 0 ) {
temp_int = strtol(optarg, &end, 0);
if ((*optarg != '\0') && (*end == '\0') && (temp_int >= 0)) {
report_level = temp_int;
} else {
report(RPT_ERR, "Could not interpret value for -%c", c);
report(RPT_ERR, "Illegal report level value %s", optarg);
error = -1;
}
break;
case 's':
temp_int = strtol( optarg, &p, 0 );
if (*optarg != 0 && *p == 0 ) {
report_dest = (temp_int?RPT_DEST_SYSLOG:RPT_DEST_STDERR);
temp_int = strtol(optarg, &end, 0);
if ((*optarg != '\0') && (*end == '\0') && (temp_int >= 0)) {
report_dest = (temp_int ? RPT_DEST_SYSLOG : RPT_DEST_STDERR);
} else {
report(RPT_ERR, "Could not interpret value for -%c", c);
report(RPT_ERR, "Illegal log destination value %s", optarg);
error = -1;
}
break;
@@ -154,6 +150,7 @@ int process_command_line( int argc, char ** argv )
error = -1;
break;
case '?':
default:
report(RPT_ERR, "Unknown option: %c", optopt);
error = -1;
break;
@@ -188,7 +185,7 @@ int process_configfile( char * configfile )
}
}
if (foreground_mode == UNSET_INT) {
foreground_mode = config_get_bool(progname, "Foreground", 0, 1);
foreground_mode = config_get_bool(progname, "Foreground", 0, 0);
}
vcs_device = strdup(config_get_string(progname, "vcsDevice", 0, "/dev/vcs"));
vcsa_device = strdup(config_get_string(progname, "vcsaDevice", 0, "/dev/vcsa"));
@@ -235,7 +232,7 @@ int main_loop()
{
int num_bytes;
char buf[80];
short w;
short w = 0;
/* Continuously check if we get a menu event... */
+1 -1
View File
@@ -15,7 +15,7 @@
# Same as with LCDd.
#ReportLevel=4
# If false, it forks to the background.
# run in foreground [default: false; legal: true, false]
#Foreground=false
# Keys to move the visible area around the screen.