From 668ed828b338df76d1196fc4ca7b24959fd1421f Mon Sep 17 00:00:00 2001 From: Matthias Andree Date: Mon, 15 Aug 2005 21:22:40 +0000 Subject: Standalone mode: print usage if wrong argument count is used. Exit with failure in standalone mode when searching for host/login pair does not come up with results. svn path=/trunk/; revision=4235 --- netrc.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'netrc.c') diff --git a/netrc.c b/netrc.c index 3c76595f..765f5f1d 100644 --- a/netrc.c +++ b/netrc.c @@ -1,11 +1,14 @@ -/* netrc.c -- parse the .netrc file to get hosts, accounts, and passwords - +/* + * netrc.c -- parse the .netrc file to get hosts, accounts, and passwords + * Gordon Matzigkeit , 1996 Copyright assigned to Eric S. Raymond, October 2001. For license terms, see the file COPYING in this directory. - Compile with -DSTANDALONE to test this module. */ + Compile with -DSTANDALONE to test this module. + (Makefile.am should have a rule so you can just type "make netrc") +*/ #include #include @@ -325,6 +328,15 @@ int main (int argc, char **argv) host = argv[2]; login = argv[3]; + switch (argc) { + case 2: + case 4: + break; + default: + fprintf (stderr, "Usage: %s [ ]\n", argv[0]); + exit(EXIT_FAILURE); + } + if (stat (file, &sb)) { fprintf (stderr, "%s: cannot stat %s: %s\n", argv[0], file, @@ -342,7 +354,7 @@ int main (int argc, char **argv) if (host && login) { int status; - status = 0; + status = EXIT_SUCCESS; printf("Host: %s, Login: %s\n", host, login); @@ -352,10 +364,10 @@ int main (int argc, char **argv) /* Print out the password (if any). */ if (a->password) { - fputc (' ', stdout); - fputs (a->password, stdout); + printf("Password: %s\n", a->password); } - } + } else + status = EXIT_FAILURE; fputc ('\n', stdout); exit (status); -- cgit v1.2.3