From 5e38d6be357ac3f60a5df5882608cb5c6a28061a Mon Sep 17 00:00:00 2001 From: pjwilliams <pjwilliams@4ea69e1a-61f1-4043-bf83-b5c94c648137> Date: Tue, 7 Jan 2003 19:47:24 +0000 Subject: [PATCH] Added printvalidarglistmessage() git-svn-id: https://smartmontools.svn.sourceforge.net/svnroot/smartmontools/trunk@440 4ea69e1a-61f1-4043-bf83-b5c94c648137 --- sm5/smartctl.c | 21 +++++++++++++++++---- sm5/smartctl.cpp | 21 +++++++++++++++++---- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/sm5/smartctl.c b/sm5/smartctl.c index 100f1673c..a13d54ac1 100644 --- a/sm5/smartctl.c +++ b/sm5/smartctl.c @@ -42,7 +42,7 @@ #include "extern.h" extern const char *CVSid1, *CVSid2, *CVSid3, *CVSid4; -const char* CVSid5="$Id: smartctl.c,v 1.46 2003/01/07 19:29:26 pjwilliams Exp $" +const char* CVSid5="$Id: smartctl.c,v 1.47 2003/01/07 19:47:24 pjwilliams Exp $" CVSID1 CVSID2 CVSID3 CVSID4 CVSID5 CVSID6; // This is a block containing all the "control variables". We declare @@ -236,6 +236,19 @@ const char *getvalidarglist(char opt) { } } +/* Prints the message "=======> VALID ARGUMENTS ARE: <LIST> <=======\n", where + <LIST> is the list of valid arguments for option opt. */ +void printvalidarglistmessage(char opt) { + const char *s; + + pout("=======> VALID ARGUMENTS ARE: "); + if (!(s = getvalidarglist(opt))) + pout("Error whilst constructing argument list for option %c", opt); + else + pout((char *)s); + pout(" <=======\n"); +} + unsigned char tryata=0,tryscsi=0; /* Takes command options and sets features to be run */ @@ -460,7 +473,7 @@ void ParseOpts (int argc, char** argv){ // Iff optopt holds a valid option then argument must be missing. if (optopt && (strchr(shortopts, optopt) != NULL)) { pout("=======> ARGUMENT REQUIRED FOR OPTION: %s <=======\n", arg+2); - pout("=======> VALID ARGUMENTS ARE: %s <=======\n", getvalidarglist(optopt)); + printvalidarglistmessage(optopt); } else pout("=======> UNRECOGNIZED OPTION: %s <=======\n",arg+2); pout("\nUse smartctl --help to get a usage summary\n\n"); @@ -471,7 +484,7 @@ void ParseOpts (int argc, char** argv){ // Iff optopt holds a valid option then argument must be missing. if (strchr(shortopts, optopt) != NULL) { pout("=======> ARGUMENT REQUIRED FOR OPTION: %c <=======\n", optopt); - pout("=======> VALID ARGUMENTS ARE: %s <=======\n", getvalidarglist(optopt)); + printvalidarglistmessage(optopt); } else pout("=======> UNRECOGNIZED OPTION: %c <=======\n",optopt); pout("\nUse smartctl -h to get a usage summary\n\n"); @@ -488,7 +501,7 @@ void ParseOpts (int argc, char** argv){ // here, but we just print the short form. Please fix this if you know // a clean way to do it. pout("=======> INVALID ARGUMENT TO -%c: %s <======= \n", optchar, optarg); - pout("=======> VALID ARGUMENTS ARE: %s <=======\n", getvalidarglist(optchar)); + printvalidarglistmessage(optchar); pout("\nUse smartctl -h to get a usage summary\n\n"); exit(FAILCMD); } diff --git a/sm5/smartctl.cpp b/sm5/smartctl.cpp index f95087321..1c244f095 100644 --- a/sm5/smartctl.cpp +++ b/sm5/smartctl.cpp @@ -42,7 +42,7 @@ #include "extern.h" extern const char *CVSid1, *CVSid2, *CVSid3, *CVSid4; -const char* CVSid5="$Id: smartctl.cpp,v 1.46 2003/01/07 19:29:26 pjwilliams Exp $" +const char* CVSid5="$Id: smartctl.cpp,v 1.47 2003/01/07 19:47:24 pjwilliams Exp $" CVSID1 CVSID2 CVSID3 CVSID4 CVSID5 CVSID6; // This is a block containing all the "control variables". We declare @@ -236,6 +236,19 @@ const char *getvalidarglist(char opt) { } } +/* Prints the message "=======> VALID ARGUMENTS ARE: <LIST> <=======\n", where + <LIST> is the list of valid arguments for option opt. */ +void printvalidarglistmessage(char opt) { + const char *s; + + pout("=======> VALID ARGUMENTS ARE: "); + if (!(s = getvalidarglist(opt))) + pout("Error whilst constructing argument list for option %c", opt); + else + pout((char *)s); + pout(" <=======\n"); +} + unsigned char tryata=0,tryscsi=0; /* Takes command options and sets features to be run */ @@ -460,7 +473,7 @@ void ParseOpts (int argc, char** argv){ // Iff optopt holds a valid option then argument must be missing. if (optopt && (strchr(shortopts, optopt) != NULL)) { pout("=======> ARGUMENT REQUIRED FOR OPTION: %s <=======\n", arg+2); - pout("=======> VALID ARGUMENTS ARE: %s <=======\n", getvalidarglist(optopt)); + printvalidarglistmessage(optopt); } else pout("=======> UNRECOGNIZED OPTION: %s <=======\n",arg+2); pout("\nUse smartctl --help to get a usage summary\n\n"); @@ -471,7 +484,7 @@ void ParseOpts (int argc, char** argv){ // Iff optopt holds a valid option then argument must be missing. if (strchr(shortopts, optopt) != NULL) { pout("=======> ARGUMENT REQUIRED FOR OPTION: %c <=======\n", optopt); - pout("=======> VALID ARGUMENTS ARE: %s <=======\n", getvalidarglist(optopt)); + printvalidarglistmessage(optopt); } else pout("=======> UNRECOGNIZED OPTION: %c <=======\n",optopt); pout("\nUse smartctl -h to get a usage summary\n\n"); @@ -488,7 +501,7 @@ void ParseOpts (int argc, char** argv){ // here, but we just print the short form. Please fix this if you know // a clean way to do it. pout("=======> INVALID ARGUMENT TO -%c: %s <======= \n", optchar, optarg); - pout("=======> VALID ARGUMENTS ARE: %s <=======\n", getvalidarglist(optchar)); + printvalidarglistmessage(optchar); pout("\nUse smartctl -h to get a usage summary\n\n"); exit(FAILCMD); } -- GitLab