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
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>
......@@ -32,6 +32,10 @@ NOTES FOR FUTURE RELEASES: see TODO file.
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()
to redirect them as needed.
......
......@@ -2,7 +2,7 @@
#
# 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>
#
......@@ -34,8 +34,9 @@ CC = gcc
# #8404. If you are getting strange output from gcc 3.2 try
# uncommenting LDFLAGS -s below. Stripping the symbols seems to fix
# the problem.
CFLAGS = -fsigned-char -Wall -O2
LDFLAGS = # -s
CFLAGS = -fsigned-char -Wall -O2
CPPFLAGS = -DHAVE_GETOPT_H -DHAVE_GETOPT_LONG
LDFLAGS = # -s
releasefiles=atacmds.c atacmds.h ataprint.c ataprint.h CHANGELOG COPYING extern.h Makefile\
README scsicmds.c scsicmds.h scsiprint.c scsiprint.h smartctl.8 smartctl.c smartctl.h\
......@@ -52,25 +53,25 @@ all: smartd smartctl
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
$(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
smartd: smartd.c atacmds.o ataprint.o scsicmds.o \
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
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
$(CC) $(CFLAGS) -c ataprint.c
$(CC) $(CFLAGS) $(CPPFLAGS) -c ataprint.c
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
$(CC) $(CFLAGS) -c scsiprint.c
$(CC) $(CFLAGS) $(CPPFLAGS) -c scsiprint.c
# This extracts the configuration file directives from smartd.8 and
# inserts them into smartd.conf.5
......
......@@ -37,7 +37,9 @@
#include <string.h>
#include <time.h>
#include <limits.h>
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
#include "atacmds.h"
#include "scsicmds.h"
#include "smartd.h"
......@@ -47,7 +49,7 @@
// CVS ID strings
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;
// global variable used for control of printing, passing arguments, etc.
......@@ -1316,6 +1318,7 @@ void ParseOpts(int argc, char **argv){
extern char *optarg;
extern int optopt, optind, opterr;
int optchar;
#ifdef HAVE_GETOPT_LONG
struct option long_options[] = {
{ "debugmode", no_argument, 0, 'X'},
{ "version", no_argument, 0, 'V'},
......@@ -1325,11 +1328,16 @@ void ParseOpts(int argc, char **argv){
{ "usage", no_argument, 0, 'h'},
{ 0, 0, 0, 0 }
};
#endif
opterr=optopt=0;
// Parse input options:
#ifdef HAVE_GETOPT_LONG
while (-1 != (optchar = getopt_long(argc, argv, "XVh?", long_options, NULL))){
#else
while (-1 != (optchar = getopt(argc, argv, "XVh?"))){
#endif
switch(optchar) {
case 'X':
debugmode = TRUE;
......@@ -1347,11 +1355,13 @@ void ParseOpts(int argc, char **argv){
printout(LOG_CRIT,"=======> UNRECOGNIZED OPTION: %c <======= \n\n",optopt);
Usage();
exit(-1);
#ifdef HAVE_GETOPT_LONG
} else if (optchar == '?' && argv[optind-1][1] == '-') {
printhead();
printout(LOG_CRIT,"=======> UNRECOGNIZED OPTION: %s <======= \n\n",argv[optind-1]+2);
Usage();
exit(-1);
#endif
}
printhead();
Usage();
......
......@@ -37,7 +37,9 @@
#include <string.h>
#include <time.h>
#include <limits.h>
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
#include "atacmds.h"
#include "scsicmds.h"
#include "smartd.h"
......@@ -47,7 +49,7 @@
// CVS ID strings
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;
// global variable used for control of printing, passing arguments, etc.
......@@ -1316,6 +1318,7 @@ void ParseOpts(int argc, char **argv){
extern char *optarg;
extern int optopt, optind, opterr;
int optchar;
#ifdef HAVE_GETOPT_LONG
struct option long_options[] = {
{ "debugmode", no_argument, 0, 'X'},
{ "version", no_argument, 0, 'V'},
......@@ -1325,11 +1328,16 @@ void ParseOpts(int argc, char **argv){
{ "usage", no_argument, 0, 'h'},
{ 0, 0, 0, 0 }
};
#endif
opterr=optopt=0;
// Parse input options:
#ifdef HAVE_GETOPT_LONG
while (-1 != (optchar = getopt_long(argc, argv, "XVh?", long_options, NULL))){
#else
while (-1 != (optchar = getopt(argc, argv, "XVh?"))){
#endif
switch(optchar) {
case 'X':
debugmode = TRUE;
......@@ -1347,11 +1355,13 @@ void ParseOpts(int argc, char **argv){
printout(LOG_CRIT,"=======> UNRECOGNIZED OPTION: %c <======= \n\n",optopt);
Usage();
exit(-1);
#ifdef HAVE_GETOPT_LONG
} else if (optchar == '?' && argv[optind-1][1] == '-') {
printhead();
printout(LOG_CRIT,"=======> UNRECOGNIZED OPTION: %s <======= \n\n",argv[optind-1]+2);
Usage();
exit(-1);
#endif
}
printhead();
Usage();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment