mirror of
https://github.com/Kitware/CMake.git
synced 2026-04-22 06:09:14 -05:00
KWSys 2016-11-09 (18c65411)
Code extracted from:
http://public.kitware.com/KWSys.git
at commit 18c654114de3aa65429542f95308720bc68f9231 (master).
Upstream Shortlog
-----------------
Brad King (14):
37306a1c FStream: Quiet unused argument warning
15e90a3c Sort includes to stabilize include order w.r.t. clang-format
26509227 Copyright.txt: Add notice of copyright by contributors
fc42d3f2 Add temporary script to filter license notices
c41c1bc4 Simplify KWSys per-source license notices
1d4c0b4a Remove temporary script that filtered license notices
a4f5ef79 SystemInformation: Remove stray comment
8649a886 kwsysPrivate: Protect KWSYS_HEADER macro from clang-format
89b98af5 Configure clang-format for KWSys source tree
547dacad Add a script to run clang-format on the entire source tree
aa94be0c CONTRIBUTING: Add a section on coding style
6604c4b6 Empty commit at end of history preceding clang-format style transition
2b3e2b1c Tell Git to not export 'clang-format' infrastructure
18c65411 FStream: Include Configure.hxx before other headers
Kitware Robot (1):
6c973b46 Revise C++ coding style using clang-format
This commit is contained in:
committed by
Brad King
parent
53862f04a0
commit
773b36e5d4
+110
-89
@@ -1,21 +1,12 @@
|
||||
/*============================================================================
|
||||
KWSys - Kitware System Library
|
||||
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
||||
|
||||
Distributed under the OSI-approved BSD License (the "License");
|
||||
see accompanying file Copyright.txt for details.
|
||||
|
||||
This software is distributed WITHOUT ANY WARRANTY; without even the
|
||||
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
See the License for more information.
|
||||
============================================================================*/
|
||||
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||||
file Copyright.txt or https://cmake.org/licensing#kwsys for details. */
|
||||
#include "kwsysPrivate.h"
|
||||
#include KWSYS_HEADER(CommandLineArguments.hxx)
|
||||
|
||||
// Work-around CMake dependency scanning limitation. This must
|
||||
// duplicate the above list of headers.
|
||||
#if 0
|
||||
# include "CommandLineArguments.hxx.in"
|
||||
#include "CommandLineArguments.hxx.in"
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
@@ -28,33 +19,45 @@ static void* random_ptr = reinterpret_cast<void*>(0x123);
|
||||
|
||||
static int argument(const char* arg, const char* value, void* call_data)
|
||||
{
|
||||
std::cout << "Got argument: \"" << arg << "\" value: \"" << (value?value:"(null)") << "\"" << std::endl;
|
||||
if ( call_data != random_ptr )
|
||||
{
|
||||
std::cout << "Got argument: \"" << arg << "\" value: \""
|
||||
<< (value ? value : "(null)") << "\"" << std::endl;
|
||||
if (call_data != random_ptr) {
|
||||
std::cerr << "Problem processing call_data" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int unknown_argument(const char* argument, void* call_data)
|
||||
{
|
||||
std::cout << "Got unknown argument: \"" << argument << "\"" << std::endl;
|
||||
if ( call_data != random_ptr )
|
||||
{
|
||||
if (call_data != random_ptr) {
|
||||
std::cerr << "Problem processing call_data" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static bool CompareTwoItemsOnList(bool i1, bool i2) { return i1 == i2; }
|
||||
static bool CompareTwoItemsOnList(int i1, int i2) { return i1 == i2; }
|
||||
static bool CompareTwoItemsOnList(double i1, double i2) { return i1 == i2; }
|
||||
static bool CompareTwoItemsOnList(const char* i1,
|
||||
const char* i2) { return strcmp(i1, i2) == 0; }
|
||||
static bool CompareTwoItemsOnList(const std::string& i1,
|
||||
const std::string& i2) { return i1 == i2; }
|
||||
static bool CompareTwoItemsOnList(bool i1, bool i2)
|
||||
{
|
||||
return i1 == i2;
|
||||
}
|
||||
static bool CompareTwoItemsOnList(int i1, int i2)
|
||||
{
|
||||
return i1 == i2;
|
||||
}
|
||||
static bool CompareTwoItemsOnList(double i1, double i2)
|
||||
{
|
||||
return i1 == i2;
|
||||
}
|
||||
static bool CompareTwoItemsOnList(const char* i1, const char* i2)
|
||||
{
|
||||
return strcmp(i1, i2) == 0;
|
||||
}
|
||||
static bool CompareTwoItemsOnList(const std::string& i1, const std::string& i2)
|
||||
{
|
||||
return i1 == i2;
|
||||
}
|
||||
|
||||
int testCommandLineArguments(int argc, char* argv[])
|
||||
{
|
||||
@@ -97,73 +100,89 @@ int testCommandLineArguments(int argc, char* argv[])
|
||||
|
||||
typedef kwsys::CommandLineArguments argT;
|
||||
|
||||
arg.AddArgument("--some-int-variable", argT::SPACE_ARGUMENT, &some_int_variable, "Set some random int variable");
|
||||
arg.AddArgument("--some-double-variable", argT::CONCAT_ARGUMENT, &some_double_variable, "Set some random double variable");
|
||||
arg.AddArgument("--some-string-variable", argT::EQUAL_ARGUMENT, &some_string_variable, "Set some random string variable");
|
||||
arg.AddArgument("--some-stl-string-variable", argT::EQUAL_ARGUMENT, &some_stl_string_variable, "Set some random stl string variable");
|
||||
arg.AddArgument("--some-bool-variable", argT::EQUAL_ARGUMENT, &some_bool_variable, "Set some random bool variable");
|
||||
arg.AddArgument("--another-bool-variable", argT::NO_ARGUMENT, &some_bool_variable1, "Set some random bool variable 1");
|
||||
arg.AddBooleanArgument("--set-bool-arg1", &bool_arg1, "Test AddBooleanArgument 1");
|
||||
arg.AddBooleanArgument("--set-bool-arg2", &bool_arg2, "Test AddBooleanArgument 2");
|
||||
arg.AddArgument("--some-multi-argument", argT::MULTI_ARGUMENT, &numbers_argument, "Some multiple values variable");
|
||||
arg.AddArgument("-N", argT::SPACE_ARGUMENT, &doubles_argument, "Some explicit multiple values variable");
|
||||
arg.AddArgument("-BB", argT::CONCAT_ARGUMENT, &bools_argument, "Some explicit multiple values variable");
|
||||
arg.AddArgument("-SS", argT::EQUAL_ARGUMENT, &strings_argument, "Some explicit multiple values variable");
|
||||
arg.AddArgument("-SSS", argT::MULTI_ARGUMENT, &stl_strings_argument, "Some explicit multiple values variable");
|
||||
arg.AddArgument("--some-int-variable", argT::SPACE_ARGUMENT,
|
||||
&some_int_variable, "Set some random int variable");
|
||||
arg.AddArgument("--some-double-variable", argT::CONCAT_ARGUMENT,
|
||||
&some_double_variable, "Set some random double variable");
|
||||
arg.AddArgument("--some-string-variable", argT::EQUAL_ARGUMENT,
|
||||
&some_string_variable, "Set some random string variable");
|
||||
arg.AddArgument("--some-stl-string-variable", argT::EQUAL_ARGUMENT,
|
||||
&some_stl_string_variable,
|
||||
"Set some random stl string variable");
|
||||
arg.AddArgument("--some-bool-variable", argT::EQUAL_ARGUMENT,
|
||||
&some_bool_variable, "Set some random bool variable");
|
||||
arg.AddArgument("--another-bool-variable", argT::NO_ARGUMENT,
|
||||
&some_bool_variable1, "Set some random bool variable 1");
|
||||
arg.AddBooleanArgument("--set-bool-arg1", &bool_arg1,
|
||||
"Test AddBooleanArgument 1");
|
||||
arg.AddBooleanArgument("--set-bool-arg2", &bool_arg2,
|
||||
"Test AddBooleanArgument 2");
|
||||
arg.AddArgument("--some-multi-argument", argT::MULTI_ARGUMENT,
|
||||
&numbers_argument, "Some multiple values variable");
|
||||
arg.AddArgument("-N", argT::SPACE_ARGUMENT, &doubles_argument,
|
||||
"Some explicit multiple values variable");
|
||||
arg.AddArgument("-BB", argT::CONCAT_ARGUMENT, &bools_argument,
|
||||
"Some explicit multiple values variable");
|
||||
arg.AddArgument("-SS", argT::EQUAL_ARGUMENT, &strings_argument,
|
||||
"Some explicit multiple values variable");
|
||||
arg.AddArgument("-SSS", argT::MULTI_ARGUMENT, &stl_strings_argument,
|
||||
"Some explicit multiple values variable");
|
||||
|
||||
arg.AddCallback("-A", argT::NO_ARGUMENT, argument, random_ptr, "Some option -A. This option has a multiline comment. It should demonstrate how the code splits lines.");
|
||||
arg.AddCallback("-B", argT::SPACE_ARGUMENT, argument, random_ptr, "Option -B takes argument with space");
|
||||
arg.AddCallback("-C", argT::EQUAL_ARGUMENT, argument, random_ptr, "Option -C takes argument after =");
|
||||
arg.AddCallback("-D", argT::CONCAT_ARGUMENT, argument, random_ptr, "This option takes concatinated argument");
|
||||
arg.AddCallback("-A", argT::NO_ARGUMENT, argument, random_ptr,
|
||||
"Some option -A. This option has a multiline comment. It "
|
||||
"should demonstrate how the code splits lines.");
|
||||
arg.AddCallback("-B", argT::SPACE_ARGUMENT, argument, random_ptr,
|
||||
"Option -B takes argument with space");
|
||||
arg.AddCallback("-C", argT::EQUAL_ARGUMENT, argument, random_ptr,
|
||||
"Option -C takes argument after =");
|
||||
arg.AddCallback("-D", argT::CONCAT_ARGUMENT, argument, random_ptr,
|
||||
"This option takes concatinated argument");
|
||||
arg.AddCallback("--long1", argT::NO_ARGUMENT, argument, random_ptr, "-A");
|
||||
arg.AddCallback("--long2", argT::SPACE_ARGUMENT, argument, random_ptr, "-B");
|
||||
arg.AddCallback("--long3", argT::EQUAL_ARGUMENT, argument, random_ptr, "Same as -C but a bit different");
|
||||
arg.AddCallback("--long4", argT::CONCAT_ARGUMENT, argument, random_ptr, "-C");
|
||||
arg.AddCallback("--long3", argT::EQUAL_ARGUMENT, argument, random_ptr,
|
||||
"Same as -C but a bit different");
|
||||
arg.AddCallback("--long4", argT::CONCAT_ARGUMENT, argument, random_ptr,
|
||||
"-C");
|
||||
|
||||
if ( !arg.Parse() )
|
||||
{
|
||||
if (!arg.Parse()) {
|
||||
std::cerr << "Problem parsing arguments" << std::endl;
|
||||
res = 1;
|
||||
}
|
||||
}
|
||||
std::cout << "Help: " << arg.GetHelp() << std::endl;
|
||||
|
||||
std::cout << "Some int variable was set to: " << some_int_variable << std::endl;
|
||||
std::cout << "Some double variable was set to: " << some_double_variable << std::endl;
|
||||
if ( some_string_variable && strcmp(some_string_variable, "test string with space") == 0)
|
||||
{
|
||||
std::cout << "Some string variable was set to: " << some_string_variable << std::endl;
|
||||
delete [] some_string_variable;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Some int variable was set to: " << some_int_variable
|
||||
<< std::endl;
|
||||
std::cout << "Some double variable was set to: " << some_double_variable
|
||||
<< std::endl;
|
||||
if (some_string_variable &&
|
||||
strcmp(some_string_variable, "test string with space") == 0) {
|
||||
std::cout << "Some string variable was set to: " << some_string_variable
|
||||
<< std::endl;
|
||||
delete[] some_string_variable;
|
||||
} else {
|
||||
std::cerr << "Problem setting string variable" << std::endl;
|
||||
res = 1;
|
||||
}
|
||||
}
|
||||
size_t cc;
|
||||
#define CompareTwoLists(list1, list_valid, lsize) \
|
||||
if ( list1.size() != lsize ) \
|
||||
{ \
|
||||
std::cerr << "Problem setting " #list1 ". Size is: " << list1.size() \
|
||||
<< " should be: " << lsize << std::endl; \
|
||||
res = 1; \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
std::cout << #list1 " argument set:"; \
|
||||
for ( cc =0; cc < lsize; ++ cc ) \
|
||||
{ \
|
||||
std::cout << " " << list1[cc]; \
|
||||
if ( !CompareTwoItemsOnList(list1[cc], list_valid[cc]) ) \
|
||||
{ \
|
||||
std::cerr << "Problem setting " #list1 ". Value of " \
|
||||
<< cc << " is: [" << list1[cc] << "] <> [" \
|
||||
<< list_valid[cc] << "]" << std::endl; \
|
||||
res = 1; \
|
||||
break; \
|
||||
} \
|
||||
} \
|
||||
std::cout << std::endl; \
|
||||
}
|
||||
#define CompareTwoLists(list1, list_valid, lsize) \
|
||||
if (list1.size() != lsize) { \
|
||||
std::cerr << "Problem setting " #list1 ". Size is: " << list1.size() \
|
||||
<< " should be: " << lsize << std::endl; \
|
||||
res = 1; \
|
||||
} else { \
|
||||
std::cout << #list1 " argument set:"; \
|
||||
for (cc = 0; cc < lsize; ++cc) { \
|
||||
std::cout << " " << list1[cc]; \
|
||||
if (!CompareTwoItemsOnList(list1[cc], list_valid[cc])) { \
|
||||
std::cerr << "Problem setting " #list1 ". Value of " << cc \
|
||||
<< " is: [" << list1[cc] << "] <> [" << list_valid[cc] \
|
||||
<< "]" << std::endl; \
|
||||
res = 1; \
|
||||
break; \
|
||||
} \
|
||||
} \
|
||||
std::cout << std::endl; \
|
||||
}
|
||||
|
||||
CompareTwoLists(numbers_argument, valid_numbers, 10);
|
||||
CompareTwoLists(doubles_argument, valid_doubles, 3);
|
||||
@@ -171,17 +190,19 @@ int testCommandLineArguments(int argc, char* argv[])
|
||||
CompareTwoLists(strings_argument, valid_strings, 4);
|
||||
CompareTwoLists(stl_strings_argument, valid_stl_strings, 4);
|
||||
|
||||
std::cout << "Some STL String variable was set to: " << some_stl_string_variable << std::endl;
|
||||
std::cout << "Some bool variable was set to: " << some_bool_variable << std::endl;
|
||||
std::cout << "Some bool variable was set to: " << some_bool_variable1 << std::endl;
|
||||
std::cout << "Some STL String variable was set to: "
|
||||
<< some_stl_string_variable << std::endl;
|
||||
std::cout << "Some bool variable was set to: " << some_bool_variable
|
||||
<< std::endl;
|
||||
std::cout << "Some bool variable was set to: " << some_bool_variable1
|
||||
<< std::endl;
|
||||
std::cout << "bool_arg1 variable was set to: " << bool_arg1 << std::endl;
|
||||
std::cout << "bool_arg2 variable was set to: " << bool_arg2 << std::endl;
|
||||
std::cout << std::endl;
|
||||
|
||||
for ( cc = 0; cc < strings_argument.size(); ++ cc )
|
||||
{
|
||||
delete [] strings_argument[cc];
|
||||
for (cc = 0; cc < strings_argument.size(); ++cc) {
|
||||
delete[] strings_argument[cc];
|
||||
strings_argument[cc] = 0;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user