[PATCH 1/2] spfquery: Fail with an appropriate error message when checking arguments.

Florian Forster <[email protected]> Sun, 23 Jan 2011 15:51:11 +0100
Newsgroups gmane.mail.spam.spf.devel
Message-ID <b1d1754d6746f309022e491d41efa0b13d851f2b.1295794247.git.ff@octo.it>
From: Florian Forster <[email protected]>

It's very annoying to be shown the "usage" output and not know *why*.

This patch prints an explanation to STDERR before the usage information,
so it's easier for users to recognize typos and misconceptions.
---
 src/spfquery/spfquery.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/spfquery/spfquery.c b/src/spfquery/spfquery.c
index c4dc5bb..1904c8a 100644
--- a/src/spfquery/spfquery.c
+++ b/src/spfquery/spfquery.c
@@ -547,8 +547,13 @@ int main( int argc, char *argv[] )
 	else {
 		fin = NULL;
 
-		if ((req->ip == NULL) ||
-			(req->sender == NULL && req->helo == NULL) ) {
+		if (req->ip == NULL) {
+			fprintf( stderr, "The required \"-ip\" option is missing.\n" );
+			usage();
+			FAIL_ERROR;
+		}
+		else if (req->sender == NULL && req->helo == NULL) {
+			fprintf( stderr, "Either the \"-sender\" or \"-helo\" option is required.\n" );
 			usage();
 			FAIL_ERROR;
 		}
-- 
1.7.2.3