Skip to content
Snippets Groups Projects
Commit 31423acd authored by pjwilliams's avatar pjwilliams
Browse files

Added support for long options.

git-svn-id: https://smartmontools.svn.sourceforge.net/svnroot/smartmontools/trunk@323 4ea69e1a-61f1-4043-bf83-b5c94c648137
parent adf7a39a
No related branches found
No related tags found
No related merge requests found
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#include <limits.h> #include <limits.h>
#include <getopt.h>
#include "atacmds.h" #include "atacmds.h"
#include "scsicmds.h" #include "scsicmds.h"
#include "smartd.h" #include "smartd.h"
...@@ -46,7 +47,7 @@ ...@@ -46,7 +47,7 @@
// CVS ID strings // CVS ID strings
extern const char *CVSid1, *CVSid2; extern const char *CVSid1, *CVSid2;
const char *CVSid6="$Id: smartd.c,v 1.73 2002/11/22 16:51:49 ballen4705 Exp $" const char *CVSid6="$Id: smartd.c,v 1.74 2002/11/23 17:09:59 pjwilliams Exp $"
CVSID1 CVSID2 CVSID3 CVSID4 CVSID7; CVSID1 CVSID2 CVSID3 CVSID4 CVSID7;
// global variable used for control of printing, passing arguments, etc. // global variable used for control of printing, passing arguments, etc.
...@@ -80,7 +81,6 @@ void sleephandler(int sig){ ...@@ -80,7 +81,6 @@ void sleephandler(int sig){
// Global Variables for command line options. These should go into a // Global Variables for command line options. These should go into a
// structure at some point. // structure at some point.
unsigned char debugmode = FALSE; unsigned char debugmode = FALSE;
unsigned char printcopyleft = FALSE;
// This function prints either to stdout or to the syslog as needed // This function prints either to stdout or to the syslog as needed
...@@ -328,10 +328,14 @@ return; ...@@ -328,10 +328,14 @@ return;
/* prints help information for command syntax */ /* prints help information for command syntax */
void Usage (void){ void Usage (void){
printout(LOG_INFO,"usage: smartd -[opts] \n\n"); printout(LOG_INFO,"Usage: smartd [OPTION]...\n\n");
printout(LOG_INFO,"Command Line Options:\n"); printout(LOG_INFO,"Command Line Options:\n");
printout(LOG_INFO," %c Start smartd in debug Mode\n",(int)DEBUGMODE); printout(LOG_INFO," -X, --debugmode Start smartd in debug mode\n");
printout(LOG_INFO," %c Print License, Copyright, and version information\n\n",(int)PRINTCOPYLEFT); printout(LOG_INFO," -V, --version, --license, --copyright\n");
printout(LOG_INFO," Print License, Copyright, and version information\n");
printout(LOG_INFO," -h, --help, --usage Display this help and exit\n");
printout(LOG_INFO," -? Same as -h\n");
printout(LOG_INFO,"\n");
printout(LOG_INFO,"Optional configuration file: %s\n",CONFIGFILE); printout(LOG_INFO,"Optional configuration file: %s\n",CONFIGFILE);
Directives(); Directives();
} }
...@@ -1282,7 +1286,20 @@ int parseconfigfile(){ ...@@ -1282,7 +1286,20 @@ int parseconfigfile(){
exit(1); exit(1);
} }
const char opts[] = {DEBUGMODE, PRINTCOPYLEFT,'h','?','\0' }; // Prints copyright, license and version information
void PrintCopyleft(void){
char out[CVSMAXLEN];
debugmode=1;
printhead();
printout(LOG_INFO,copyleftstring);
printout(LOG_INFO,"CVS version IDs of files used to build this code are:\n");
printone(out,CVSid1);
printout(LOG_INFO,"%s",out);
printone(out,CVSid2);
printout(LOG_INFO,"%s",out);
printone(out,CVSid6);
printout(LOG_INFO,"%s",out);
}
// Parses input line, prints usage message and // Parses input line, prints usage message and
// version/license/copyright messages // version/license/copyright messages
...@@ -1290,18 +1307,28 @@ void ParseOpts(int argc, char **argv){ ...@@ -1290,18 +1307,28 @@ void ParseOpts(int argc, char **argv){
extern char *optarg; extern char *optarg;
extern int optopt, optind, opterr; extern int optopt, optind, opterr;
int optchar; int optchar;
struct option long_options[] = {
{ "debugmode", no_argument, 0, 'X'},
{ "version", no_argument, 0, 'V'},
{ "license", no_argument, 0, 'V'},
{ "copyright", no_argument, 0, 'V'},
{ "help", no_argument, 0, 'h'},
{ "usage", no_argument, 0, 'h'},
{ 0, 0, 0, 0 }
};
opterr=optopt=0; opterr=optopt=0;
// Parse input options: // Parse input options:
while (-1 != (optchar = getopt(argc, argv, opts))){ while (-1 != (optchar = getopt_long(argc, argv, "XVh?", long_options, NULL))){
switch(optchar) { switch(optchar) {
case PRINTCOPYLEFT: case 'X':
printcopyleft=TRUE;
break;
case DEBUGMODE :
debugmode = TRUE; debugmode = TRUE;
break; break;
case 'V':
PrintCopyleft();
exit(0);
break;
case '?': case '?':
case 'h': case 'h':
default: default:
...@@ -1311,28 +1338,17 @@ void ParseOpts(int argc, char **argv){ ...@@ -1311,28 +1338,17 @@ void ParseOpts(int argc, char **argv){
printout(LOG_CRIT,"=======> UNRECOGNIZED OPTION: %c <======= \n\n",optopt); printout(LOG_CRIT,"=======> UNRECOGNIZED OPTION: %c <======= \n\n",optopt);
Usage(); Usage();
exit(-1); exit(-1);
} } else if (optchar == '?' && argv[optind-1][1] == '-') {
printhead(); printhead();
printout(LOG_CRIT,"=======> UNRECOGNIZED OPTION: %s <======= \n\n",argv[optind-1]+2);
Usage(); Usage();
exit(0); exit(-1);
}
} }
// If needed print copyright, license and version information
if (printcopyleft){
char out[CVSMAXLEN];
debugmode=1;
printhead(); printhead();
printout(LOG_INFO,copyleftstring); Usage();
printout(LOG_INFO,"CVS version IDs of files used to build this code are:\n");
printone(out,CVSid1);
printout(LOG_INFO,"%s",out);
printone(out,CVSid2);
printout(LOG_INFO,"%s",out);
printone(out,CVSid6);
printout(LOG_INFO,"%s",out);
exit(0); exit(0);
} }
}
// print header // print header
printhead(); printhead();
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#include <limits.h> #include <limits.h>
#include <getopt.h>
#include "atacmds.h" #include "atacmds.h"
#include "scsicmds.h" #include "scsicmds.h"
#include "smartd.h" #include "smartd.h"
...@@ -46,7 +47,7 @@ ...@@ -46,7 +47,7 @@
// CVS ID strings // CVS ID strings
extern const char *CVSid1, *CVSid2; extern const char *CVSid1, *CVSid2;
const char *CVSid6="$Id: smartd.cpp,v 1.73 2002/11/22 16:51:49 ballen4705 Exp $" const char *CVSid6="$Id: smartd.cpp,v 1.74 2002/11/23 17:09:59 pjwilliams Exp $"
CVSID1 CVSID2 CVSID3 CVSID4 CVSID7; CVSID1 CVSID2 CVSID3 CVSID4 CVSID7;
// global variable used for control of printing, passing arguments, etc. // global variable used for control of printing, passing arguments, etc.
...@@ -80,7 +81,6 @@ void sleephandler(int sig){ ...@@ -80,7 +81,6 @@ void sleephandler(int sig){
// Global Variables for command line options. These should go into a // Global Variables for command line options. These should go into a
// structure at some point. // structure at some point.
unsigned char debugmode = FALSE; unsigned char debugmode = FALSE;
unsigned char printcopyleft = FALSE;
// This function prints either to stdout or to the syslog as needed // This function prints either to stdout or to the syslog as needed
...@@ -328,10 +328,14 @@ return; ...@@ -328,10 +328,14 @@ return;
/* prints help information for command syntax */ /* prints help information for command syntax */
void Usage (void){ void Usage (void){
printout(LOG_INFO,"usage: smartd -[opts] \n\n"); printout(LOG_INFO,"Usage: smartd [OPTION]...\n\n");
printout(LOG_INFO,"Command Line Options:\n"); printout(LOG_INFO,"Command Line Options:\n");
printout(LOG_INFO," %c Start smartd in debug Mode\n",(int)DEBUGMODE); printout(LOG_INFO," -X, --debugmode Start smartd in debug mode\n");
printout(LOG_INFO," %c Print License, Copyright, and version information\n\n",(int)PRINTCOPYLEFT); printout(LOG_INFO," -V, --version, --license, --copyright\n");
printout(LOG_INFO," Print License, Copyright, and version information\n");
printout(LOG_INFO," -h, --help, --usage Display this help and exit\n");
printout(LOG_INFO," -? Same as -h\n");
printout(LOG_INFO,"\n");
printout(LOG_INFO,"Optional configuration file: %s\n",CONFIGFILE); printout(LOG_INFO,"Optional configuration file: %s\n",CONFIGFILE);
Directives(); Directives();
} }
...@@ -1282,7 +1286,20 @@ int parseconfigfile(){ ...@@ -1282,7 +1286,20 @@ int parseconfigfile(){
exit(1); exit(1);
} }
const char opts[] = {DEBUGMODE, PRINTCOPYLEFT,'h','?','\0' }; // Prints copyright, license and version information
void PrintCopyleft(void){
char out[CVSMAXLEN];
debugmode=1;
printhead();
printout(LOG_INFO,copyleftstring);
printout(LOG_INFO,"CVS version IDs of files used to build this code are:\n");
printone(out,CVSid1);
printout(LOG_INFO,"%s",out);
printone(out,CVSid2);
printout(LOG_INFO,"%s",out);
printone(out,CVSid6);
printout(LOG_INFO,"%s",out);
}
// Parses input line, prints usage message and // Parses input line, prints usage message and
// version/license/copyright messages // version/license/copyright messages
...@@ -1290,18 +1307,28 @@ void ParseOpts(int argc, char **argv){ ...@@ -1290,18 +1307,28 @@ void ParseOpts(int argc, char **argv){
extern char *optarg; extern char *optarg;
extern int optopt, optind, opterr; extern int optopt, optind, opterr;
int optchar; int optchar;
struct option long_options[] = {
{ "debugmode", no_argument, 0, 'X'},
{ "version", no_argument, 0, 'V'},
{ "license", no_argument, 0, 'V'},
{ "copyright", no_argument, 0, 'V'},
{ "help", no_argument, 0, 'h'},
{ "usage", no_argument, 0, 'h'},
{ 0, 0, 0, 0 }
};
opterr=optopt=0; opterr=optopt=0;
// Parse input options: // Parse input options:
while (-1 != (optchar = getopt(argc, argv, opts))){ while (-1 != (optchar = getopt_long(argc, argv, "XVh?", long_options, NULL))){
switch(optchar) { switch(optchar) {
case PRINTCOPYLEFT: case 'X':
printcopyleft=TRUE;
break;
case DEBUGMODE :
debugmode = TRUE; debugmode = TRUE;
break; break;
case 'V':
PrintCopyleft();
exit(0);
break;
case '?': case '?':
case 'h': case 'h':
default: default:
...@@ -1311,28 +1338,17 @@ void ParseOpts(int argc, char **argv){ ...@@ -1311,28 +1338,17 @@ void ParseOpts(int argc, char **argv){
printout(LOG_CRIT,"=======> UNRECOGNIZED OPTION: %c <======= \n\n",optopt); printout(LOG_CRIT,"=======> UNRECOGNIZED OPTION: %c <======= \n\n",optopt);
Usage(); Usage();
exit(-1); exit(-1);
} } else if (optchar == '?' && argv[optind-1][1] == '-') {
printhead(); printhead();
printout(LOG_CRIT,"=======> UNRECOGNIZED OPTION: %s <======= \n\n",argv[optind-1]+2);
Usage(); Usage();
exit(0); exit(-1);
}
} }
// If needed print copyright, license and version information
if (printcopyleft){
char out[CVSMAXLEN];
debugmode=1;
printhead(); printhead();
printout(LOG_INFO,copyleftstring); Usage();
printout(LOG_INFO,"CVS version IDs of files used to build this code are:\n");
printone(out,CVSid1);
printout(LOG_INFO,"%s",out);
printone(out,CVSid2);
printout(LOG_INFO,"%s",out);
printone(out,CVSid6);
printout(LOG_INFO,"%s",out);
exit(0); exit(0);
} }
}
// print header // print header
printhead(); printhead();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment