Skip to content
Snippets Groups Projects
Commit 1fdbc264 authored by pjwilliams's avatar pjwilliams
Browse files

smartd uses getopt_long() if HAVE_GETOPT_LONG is defined and getopt() otherwise.

git-svn-id: https://smartmontools.svn.sourceforge.net/svnroot/smartmontools/trunk@342 4ea69e1a-61f1-4043-bf83-b5c94c648137
parent ad92b8a8
No related branches found
No related tags found
No related merge requests found
CHANGELOG for smartmontools CHANGELOG for smartmontools
$Id: CHANGELOG,v 1.63 2002/12/01 07:07:46 ballen4705 Exp $ $Id: CHANGELOG,v 1.64 2002/12/01 12:14:15 pjwilliams Exp $
Copyright (C) 2002 Bruce Allen <smartmontools-support@lists.sourceforge.net> Copyright (C) 2002 Bruce Allen <smartmontools-support@lists.sourceforge.net>
...@@ -32,6 +32,10 @@ NOTES FOR FUTURE RELEASES: see TODO file. ...@@ -32,6 +32,10 @@ NOTES FOR FUTURE RELEASES: see TODO file.
CURRENT RELEASE (see VERSION file in this directory): CURRENT RELEASE (see VERSION file in this directory):
[PW] smartd: ParseOpts() now uses getopt_long() if HAVE_GETOPT_LONG is
defined and uses getopt() otherwise. This is controlled by CPPFLAGS in
the Makefile.
[BA] smartd: Fixed a couple of error messages done with perror() [BA] smartd: Fixed a couple of error messages done with perror()
to redirect them as needed. to redirect them as needed.
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# #
# Home page: http://smartmontools.sourceforge.net # Home page: http://smartmontools.sourceforge.net
# #
# $Id: Makefile,v 1.38 2002/11/15 14:51:31 ballen4705 Exp $ # $Id: Makefile,v 1.39 2002/12/01 12:14:15 pjwilliams Exp $
# #
# Copyright (C) 2002 Bruce Allen <smartmontools-support@lists.sourceforge.net> # Copyright (C) 2002 Bruce Allen <smartmontools-support@lists.sourceforge.net>
# #
...@@ -35,6 +35,7 @@ CC = gcc ...@@ -35,6 +35,7 @@ CC = gcc
# uncommenting LDFLAGS -s below. Stripping the symbols seems to fix # uncommenting LDFLAGS -s below. Stripping the symbols seems to fix
# the problem. # the problem.
CFLAGS = -fsigned-char -Wall -O2 CFLAGS = -fsigned-char -Wall -O2
CPPFLAGS = -DHAVE_GETOPT_H -DHAVE_GETOPT_LONG
LDFLAGS = # -s LDFLAGS = # -s
releasefiles=atacmds.c atacmds.h ataprint.c ataprint.h CHANGELOG COPYING extern.h Makefile\ releasefiles=atacmds.c atacmds.h ataprint.c ataprint.h CHANGELOG COPYING extern.h Makefile\
...@@ -52,25 +53,25 @@ all: smartd smartctl ...@@ -52,25 +53,25 @@ all: smartd smartctl
smartctl: smartctl.c atacmds.o ataprint.o scsicmds.o scsiprint.o \ smartctl: smartctl.c atacmds.o ataprint.o scsicmds.o scsiprint.o \
smartctl.h atacmds.h ataprint.h scsicmds.h scsiprint.h extern.h VERSION Makefile smartctl.h atacmds.h ataprint.h scsicmds.h scsiprint.h extern.h VERSION Makefile
$(CC) -DSMARTMONTOOLS_VERSION=$(counter) -o smartctl $(CFLAGS) $(LDFLAGS) smartctl.c \ $(CC) -DSMARTMONTOOLS_VERSION=$(counter) -o smartctl $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) smartctl.c \
atacmds.o scsicmds.o ataprint.o scsiprint.o atacmds.o scsicmds.o ataprint.o scsiprint.o
smartd: smartd.c atacmds.o ataprint.o scsicmds.o \ smartd: smartd.c atacmds.o ataprint.o scsicmds.o \
smartd.h atacmds.h ataprint.h scsicmds.h extern.h VERSION Makefile smartd.h atacmds.h ataprint.h scsicmds.h extern.h VERSION Makefile
$(CC) -DSMARTMONTOOLS_VERSION=$(counter) -o smartd $(CFLAGS) $(LDFLAGS) smartd.c \ $(CC) -DSMARTMONTOOLS_VERSION=$(counter) -o smartd $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) smartd.c \
scsicmds.o atacmds.o ataprint.o scsicmds.o atacmds.o ataprint.o
atacmds.o: atacmds.h atacmds.c Makefile atacmds.o: atacmds.h atacmds.c Makefile
$(CC) $(CFLAGS) -c atacmds.c $(CC) $(CFLAGS) $(CPPFLAGS) -c atacmds.c
ataprint.o: ataprint.c atacmds.h ataprint.h smartctl.h extern.h Makefile ataprint.o: ataprint.c atacmds.h ataprint.h smartctl.h extern.h Makefile
$(CC) $(CFLAGS) -c ataprint.c $(CC) $(CFLAGS) $(CPPFLAGS) -c ataprint.c
scsicmds.o: scsicmds.c scsicmds.h Makefile scsicmds.o: scsicmds.c scsicmds.h Makefile
$(CC) $(CFLAGS) -c scsicmds.c $(CC) $(CFLAGS) $(CPPFLAGS) -c scsicmds.c
scsiprint.o: scsiprint.c extern.h scsicmds.h scsiprint.h smartctl.h Makefile scsiprint.o: scsiprint.c extern.h scsicmds.h scsiprint.h smartctl.h Makefile
$(CC) $(CFLAGS) -c scsiprint.c $(CC) $(CFLAGS) $(CPPFLAGS) -c scsiprint.c
# This extracts the configuration file directives from smartd.8 and # This extracts the configuration file directives from smartd.8 and
# inserts them into smartd.conf.5 # inserts them into smartd.conf.5
......
...@@ -37,7 +37,9 @@ ...@@ -37,7 +37,9 @@
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#include <limits.h> #include <limits.h>
#ifdef HAVE_GETOPT_H
#include <getopt.h> #include <getopt.h>
#endif
#include "atacmds.h" #include "atacmds.h"
#include "scsicmds.h" #include "scsicmds.h"
#include "smartd.h" #include "smartd.h"
...@@ -47,7 +49,7 @@ ...@@ -47,7 +49,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.80 2002/12/01 07:16:16 ballen4705 Exp $" const char *CVSid6="$Id: smartd.c,v 1.81 2002/12/01 12:14:16 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.
...@@ -1316,6 +1318,7 @@ void ParseOpts(int argc, char **argv){ ...@@ -1316,6 +1318,7 @@ 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;
#ifdef HAVE_GETOPT_LONG
struct option long_options[] = { struct option long_options[] = {
{ "debugmode", no_argument, 0, 'X'}, { "debugmode", no_argument, 0, 'X'},
{ "version", no_argument, 0, 'V'}, { "version", no_argument, 0, 'V'},
...@@ -1325,11 +1328,16 @@ void ParseOpts(int argc, char **argv){ ...@@ -1325,11 +1328,16 @@ void ParseOpts(int argc, char **argv){
{ "usage", no_argument, 0, 'h'}, { "usage", no_argument, 0, 'h'},
{ 0, 0, 0, 0 } { 0, 0, 0, 0 }
}; };
#endif
opterr=optopt=0; opterr=optopt=0;
// Parse input options: // Parse input options:
#ifdef HAVE_GETOPT_LONG
while (-1 != (optchar = getopt_long(argc, argv, "XVh?", long_options, NULL))){ while (-1 != (optchar = getopt_long(argc, argv, "XVh?", long_options, NULL))){
#else
while (-1 != (optchar = getopt(argc, argv, "XVh?"))){
#endif
switch(optchar) { switch(optchar) {
case 'X': case 'X':
debugmode = TRUE; debugmode = TRUE;
...@@ -1347,11 +1355,13 @@ void ParseOpts(int argc, char **argv){ ...@@ -1347,11 +1355,13 @@ 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);
#ifdef HAVE_GETOPT_LONG
} else if (optchar == '?' && argv[optind-1][1] == '-') { } else if (optchar == '?' && argv[optind-1][1] == '-') {
printhead(); printhead();
printout(LOG_CRIT,"=======> UNRECOGNIZED OPTION: %s <======= \n\n",argv[optind-1]+2); printout(LOG_CRIT,"=======> UNRECOGNIZED OPTION: %s <======= \n\n",argv[optind-1]+2);
Usage(); Usage();
exit(-1); exit(-1);
#endif
} }
printhead(); printhead();
Usage(); Usage();
......
...@@ -37,7 +37,9 @@ ...@@ -37,7 +37,9 @@
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#include <limits.h> #include <limits.h>
#ifdef HAVE_GETOPT_H
#include <getopt.h> #include <getopt.h>
#endif
#include "atacmds.h" #include "atacmds.h"
#include "scsicmds.h" #include "scsicmds.h"
#include "smartd.h" #include "smartd.h"
...@@ -47,7 +49,7 @@ ...@@ -47,7 +49,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.80 2002/12/01 07:16:16 ballen4705 Exp $" const char *CVSid6="$Id: smartd.cpp,v 1.81 2002/12/01 12:14:16 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.
...@@ -1316,6 +1318,7 @@ void ParseOpts(int argc, char **argv){ ...@@ -1316,6 +1318,7 @@ 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;
#ifdef HAVE_GETOPT_LONG
struct option long_options[] = { struct option long_options[] = {
{ "debugmode", no_argument, 0, 'X'}, { "debugmode", no_argument, 0, 'X'},
{ "version", no_argument, 0, 'V'}, { "version", no_argument, 0, 'V'},
...@@ -1325,11 +1328,16 @@ void ParseOpts(int argc, char **argv){ ...@@ -1325,11 +1328,16 @@ void ParseOpts(int argc, char **argv){
{ "usage", no_argument, 0, 'h'}, { "usage", no_argument, 0, 'h'},
{ 0, 0, 0, 0 } { 0, 0, 0, 0 }
}; };
#endif
opterr=optopt=0; opterr=optopt=0;
// Parse input options: // Parse input options:
#ifdef HAVE_GETOPT_LONG
while (-1 != (optchar = getopt_long(argc, argv, "XVh?", long_options, NULL))){ while (-1 != (optchar = getopt_long(argc, argv, "XVh?", long_options, NULL))){
#else
while (-1 != (optchar = getopt(argc, argv, "XVh?"))){
#endif
switch(optchar) { switch(optchar) {
case 'X': case 'X':
debugmode = TRUE; debugmode = TRUE;
...@@ -1347,11 +1355,13 @@ void ParseOpts(int argc, char **argv){ ...@@ -1347,11 +1355,13 @@ 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);
#ifdef HAVE_GETOPT_LONG
} else if (optchar == '?' && argv[optind-1][1] == '-') { } else if (optchar == '?' && argv[optind-1][1] == '-') {
printhead(); printhead();
printout(LOG_CRIT,"=======> UNRECOGNIZED OPTION: %s <======= \n\n",argv[optind-1]+2); printout(LOG_CRIT,"=======> UNRECOGNIZED OPTION: %s <======= \n\n",argv[optind-1]+2);
Usage(); Usage();
exit(-1); exit(-1);
#endif
} }
printhead(); printhead();
Usage(); Usage();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment