]> git.openfabrics.org - ~shefty/rdma-win.git/commitdiff
wvtests: add getopt() routine to process test options
authorshefty <shefty@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Wed, 5 Mar 2008 01:30:23 +0000 (01:30 +0000)
committershefty <shefty@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Wed, 5 Mar 2008 01:30:23 +0000 (01:30 +0000)
Signed-off-by: Sean Hefty <sean.hefty@intel.com>
git-svn-id: svn://openib.tc.cornell.edu/gen1@972 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86

branches/winverbs/tests/wvtests/user/SOURCES
branches/winverbs/tests/wvtests/user/getopt.cpp [new file with mode: 0644]
branches/winverbs/tests/wvtests/user/getopt.h [new file with mode: 0644]
branches/winverbs/tests/wvtests/user/wv_main.cpp

index 5eedd231c0ea0684bd0ecd9c3b3ebd55e7e204c6..1182c49fbba6f6f85d24d9e7858d687c694a020c 100644 (file)
@@ -7,15 +7,16 @@ USE_MSVCRT=1
 USE_STL=1\r
 \r
 SOURCES=\\r
-       wv_main.cpp\r
+       wv_main.cpp             \\r
+       getopt.cpp\r
        \r
 INCLUDES=..\..\..\inc;..\..\..\inc\user;\r
 \r
 TARGETLIBS= \\r
        $(SDK_LIB_PATH)\kernel32.lib    \\r
        $(SDK_LIB_PATH)\advapi32.lib    \\r
-       $(SDK_LIB_PATH)\user32.lib      \\r
-       $(SDK_LIB_PATH)\ole32.lib       \\r
+       $(SDK_LIB_PATH)\user32.lib              \\r
+       $(SDK_LIB_PATH)\ole32.lib               \\r
 !if $(FREEBUILD)\r
        $(TARGETPATH)\*\winverbs.lib\r
 !else\r
diff --git a/branches/winverbs/tests/wvtests/user/getopt.cpp b/branches/winverbs/tests/wvtests/user/getopt.cpp
new file mode 100644 (file)
index 0000000..8a80658
--- /dev/null
@@ -0,0 +1,64 @@
+/*\r
+ * Copyright (c) 2008 Intel Corporation. All rights reserved.\r
+ *\r
+ * This software is available to you under the OpenIB.org BSD license\r
+ * below:\r
+ *\r
+ *     Redistribution and use in source and binary forms, with or\r
+ *     without modification, are permitted provided that the following\r
+ *     conditions are met:\r
+ *\r
+ *      - Redistributions of source code must retain the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer.\r
+ *\r
+ *      - Redistributions in binary form must reproduce the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer in the documentation and/or other materials\r
+ *        provided with the distribution.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AWV\r
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS\r
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\r
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
+ * SOFTWARE.\r
+ */\r
+\r
+#include <string.h>\r
+#include "getopt.h"\r
+\r
+char *optarg;\r
+\r
+int getopt(int argc, char **argv, char *opts)\r
+{\r
+       static int index = 1;\r
+       char *opt;\r
+\r
+       if (index >= argc)\r
+               return -1;\r
+\r
+       optarg = NULL;\r
+       if (argv[index][0] != '-' || strlen(argv[index]) != 2)\r
+               goto err;\r
+\r
+       opt = strchr(opts, argv[index][1]);\r
+       if (!opt)\r
+               goto err;\r
+\r
+       if (opt[1] == ':')\r
+       {\r
+               if (++index >= argc)\r
+                       goto err;\r
+               optarg = argv[index];\r
+       }\r
+\r
+       index++;\r
+       return *opt;\r
+\r
+err:\r
+       index++;\r
+       return '?';\r
+}\r
diff --git a/branches/winverbs/tests/wvtests/user/getopt.h b/branches/winverbs/tests/wvtests/user/getopt.h
new file mode 100644 (file)
index 0000000..61fa593
--- /dev/null
@@ -0,0 +1,38 @@
+/*\r
+ * Copyright (c) 2008 Intel Corporation. All rights reserved.\r
+ *\r
+ * This software is available to you under the OpenIB.org BSD license\r
+ * below:\r
+ *\r
+ *     Redistribution and use in source and binary forms, with or\r
+ *     without modification, are permitted provided that the following\r
+ *     conditions are met:\r
+ *\r
+ *      - Redistributions of source code must retain the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer.\r
+ *\r
+ *      - Redistributions in binary form must reproduce the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer in the documentation and/or other materials\r
+ *        provided with the distribution.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AWV\r
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS\r
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\r
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
+ * SOFTWARE.\r
+ */\r
+\r
+#pragma once\r
+\r
+#ifndef _GETOPT_H_\r
+#define _GETOPT_H_\r
+\r
+extern char *optarg;\r
+int getopt(int argc, char **argv, char *opts);\r
+\r
+#endif // _GETOPT_H_\r
index 0210d59e9f80ee341dc24bc14f0673f909440ccd..7d4e5a491ac1c81f8bd394c2ae682111bc33d30f 100644 (file)
 #include <iostream>\r
 using namespace std;\r
 \r
+#include "getopt.h"\r
 #include <rdma\winverbs.h>\r
 \r
 static void ShowProviderOptions()\r
 {\r
+       cout << "usage: winverb provider [options]" << endl;\r
        cout << "provider options" << endl;\r
-       cout << "\t" << "--help" << endl;\r
-       cout << "\t\t" << "display this message" << endl;\r
+       cout << "\t" << "-?" << "\t" << "display this message" << endl;\r
 }\r
 \r
 static int ProviderTest(int argc, char *argv[])\r
@@ -44,11 +45,12 @@ static int ProviderTest(int argc, char *argv[])
        IWVProvider *prov;\r
        HRESULT hr;\r
        ULONG ref;\r
+       int op;\r
 \r
-       if (argc > 2)\r
-       {\r
+       if ((op = getopt(argc, argv, "?")) != -1)
+       {
                ShowProviderOptions();\r
-               return 0;\r
+               return -1;\r
        }\r
 \r
        cout << "Validating IWVProvider interface" << endl;\r
@@ -73,11 +75,11 @@ static int ProviderTest(int argc, char *argv[])
 \r
 static void ShowUsage()\r
 {\r
-       cout << "winverb <interface> [options]" << endl;\r
+       cout << "usage: winverb <interface> [options]" << endl;\r
        cout << "<interface> is one of the following:" << endl;\r
        cout << "\t" << "provider" << endl;\r
        cout << endl;\r
-       cout << "Type 'winverb <interface> --help' for option details" << endl;\r
+       cout << "Type 'winverb <interface> -?' for option details" << endl;\r
 }\r
 \r
 int __cdecl main(int argc, char *argv[])\r
@@ -90,7 +92,7 @@ int __cdecl main(int argc, char *argv[])
 \r
        if (!strcmp("provider", argv[1]))\r
        {\r
-               return ProviderTest(argc, argv);\r
+               return ProviderTest(argc - 1, &argv[1]);\r
        }\r
        else\r
        {\r