[1/2] net: Fix the parameter checking, /help handling and usage.
Francois Gouget
fgouget at free.fr
Fri Aug 26 10:40:17 CDT 2011
Also simplify and improve the usage messages.
---
It does not seem necessary to have separate help message for 'net' and
'net help'.
Also the usage message claimed that 'net start /help' was supported but
in fact '/help' was not supported at all.
Finally "Specify service name to start." seemed very short as a help
message for the 'net help start' (ditto for net stop).
programs/net/net.c | 47 +++++++++++++++++++++++++++------------------
programs/net/net.rc | 8 ++----
programs/net/resources.h | 1 -
3 files changed, 31 insertions(+), 25 deletions(-)
diff --git a/programs/net/net.c b/programs/net/net.c
index 07369ab..249c14d 100644
--- a/programs/net/net.c
+++ b/programs/net/net.c
@@ -227,9 +227,11 @@ static int arg_is(const WCHAR* str1, const WCHAR* str2)
int wmain(int argc, const WCHAR* argv[])
{
static const WCHAR helpW[]={'h','e','l','p',0};
+ static const WCHAR shelpW[]={'/','h','e','l','p',0};
static const WCHAR startW[]={'s','t','a','r','t',0};
static const WCHAR stopW[]={'s','t','o','p',0};
static const WCHAR useW[]={'u','s','e',0};
+
if (argc < 2)
{
output_string(STRING_USAGE);
@@ -238,43 +240,50 @@ int wmain(int argc, const WCHAR* argv[])
if(arg_is(argv[1], helpW))
{
- output_string(STRING_HELP_USAGE);
+ if(argc > 3)
+ {
+ output_string(STRING_USAGE);
+ return 1;
+ }
+ if(argc == 2)
+ output_string(STRING_USAGE);
+ else if(arg_is(argv[2], startW))
+ output_string(STRING_START_USAGE);
+ else if(arg_is(argv[2], stopW))
+ output_string(STRING_STOP_USAGE);
+ else
+ output_string(STRING_USAGE);
}
-
- if(arg_is(argv[1], startW))
+ else if(arg_is(argv[1], startW))
{
- if(argc < 3)
+ if(argc != 3)
{
output_string(STRING_START_USAGE);
return 1;
}
-
- if(!net_service(NET_START, argv[2]))
- {
+ if(arg_is(argv[2], shelpW))
+ output_string(STRING_START_USAGE);
+ else if(!net_service(NET_START, argv[2]))
return 1;
- }
- return 0;
}
-
- if(arg_is(argv[1], stopW))
+ else if(arg_is(argv[1], stopW))
{
- if(argc < 3)
+ if(argc != 3)
{
output_string(STRING_STOP_USAGE);
return 1;
}
-
- if(!net_service(NET_STOP, argv[2]))
- {
+ if(arg_is(argv[2], shelpW))
+ output_string(STRING_STOP_USAGE);
+ else if(!net_service(NET_STOP, argv[2]))
return 1;
- }
- return 0;
}
-
- if(arg_is(argv[1], useW))
+ else if(arg_is(argv[1], useW))
{
if(!net_use(argc, argv)) return 1;
}
+ else
+ output_string(STRING_USAGE);
return 0;
}
diff --git a/programs/net/net.rc b/programs/net/net.rc
index 9b691f9..3f0ddef 100644
--- a/programs/net/net.rc
+++ b/programs/net/net.rc
@@ -24,9 +24,9 @@ LANGUAGE LANG_ENGLISH, SUBLANG_DEFAULT
STRINGTABLE
{
- STRING_USAGE, "The syntax of this command is:\n\nNET [ HELP | START | STOP | USE ]\n"
- STRING_START_USAGE, "Specify service name to start.\n"
- STRING_STOP_USAGE, "Specify service name to stop.\n"
+ STRING_USAGE, "The syntax of this command is:\n\nNET command [arguments]\n -or-\nNET command /HELP\n\nWhere 'command' is one of HELP, START, STOP or USE\n"
+ STRING_START_USAGE, "The syntax of this command is:\n\nNET START service\n\nWhere 'service' is the name of the service to start.\n"
+ STRING_STOP_USAGE, "The syntax of this command is:\n\nNET STOP service\n\nWhere 'service' is the name of the service to stop.\n"
STRING_STOP_DEP, "Stopping dependent service: %s\n"
STRING_CANT_STOP, "Could not stop service %s\n"
STRING_NO_SCM, "Could not get handle to service control manager.\n"
@@ -37,8 +37,6 @@ STRINGTABLE
STRING_STOP_SVC, "The %s service is stopping.\n"
STRING_STOP_SVC_SUCCESS, "The %s service was stopped successfully.\n"
STRING_STOP_SVC_FAIL, "The %s service failed to stop.\n"
- STRING_HELP_USAGE, "The syntax of this command is:\n\nNET HELP command\n -or-\nNET command /HELP\n\n"\
- " Commands available are:\n NET HELP NET START NET STOP NET USE\n"
STRING_NO_ENTRIES, "There are no entries in the list.\n"
STRING_USE_HEADER, "\nStatus Local Remote\n---------------------------------------------------------------\n"
STRING_USE_ENTRY, "%s %s %s Open resources: %lu\n"
diff --git a/programs/net/resources.h b/programs/net/resources.h
index cdb1c44..5accad7 100644
--- a/programs/net/resources.h
+++ b/programs/net/resources.h
@@ -31,7 +31,6 @@
#define STRING_STOP_SVC 111
#define STRING_STOP_SVC_SUCCESS 112
#define STRING_STOP_SVC_FAIL 113
-#define STRING_HELP_USAGE 114
#define STRING_NO_ENTRIES 115
#define STRING_USE_HEADER 116
#define STRING_USE_ENTRY 117
--
1.7.5.4
More information about the wine-patches
mailing list