Commit 9bf6e475 authored by Benjamin Eikel's avatar Benjamin Eikel

Imported Upstream version 1.0.1+git3224cf2

parent a4db0471

Too many changes to show.

To preserve performance only 416 of 416+ files are displayed.

CMAKE_MINIMUM_REQUIRED(VERSION 2.4)
IF(COMMAND CMAKE_POLICY)
CMAKE_POLICY(SET CMP0003 NEW)
ENDIF(COMMAND CMAKE_POLICY)
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.4)
FOREACH(p
CMP0003
CMP0026
CMP0054
)
IF(POLICY ${p})
CMAKE_POLICY(SET ${p} NEW)
ENDIF()
ENDFOREACH()
PROJECT(KWStyle)
......@@ -36,6 +43,7 @@ ENDIF (BUILD_TESTING)
INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_BINARY_DIR}
${KWStyle_BINARY_DIR}/Utilities
${KWStyle_SOURCE_DIR}/Utilities
)
SET(KWStyle_HDRS
......@@ -77,6 +85,8 @@ kwsCheckStruct.cxx
kwsCheckVariables.cxx
kwsCheckMemberFunctions.cxx
kwsCheckFunctions.cxx
kwsCheckUsingDirectives.cxx
kwsCheckRelativePathInInclude.cxx
)
SUBDIRS(Utilities)
......@@ -94,15 +104,9 @@ ADD_LIBRARY(KWStyleLib ${KWStyle_SRCS} ${KWStyle_HDRS})
ADD_EXECUTABLE(KWStyle kwsStyle.cxx)
TARGET_LINK_LIBRARIES(KWStyle KWStyleLib kwssys)
# Move the executable to the top binary tree
GET_TARGET_PROPERTY(EXECUTABLE_PATH KWStyle LOCATION)
GET_FILENAME_COMPONENT(EXECUTABLE_NAME ${EXECUTABLE_PATH} NAME)
ADD_CUSTOM_COMMAND(
TARGET KWStyle
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${EXECUTABLE_PATH} ${KWStyle_BINARY_DIR}/${EXECUTABLE_NAME}
)
ADD_CUSTOM_COMMAND(TARGET KWStyle POST_BUILD COMMAND "${CMAKE_COMMAND}" -E copy
"$<TARGET_FILE:KWStyle>" "${KWStyle_BINARY_DIR}/${EXECUTABLE_NAME}"
COMMENT "Move the executable to the top binary tree")
# Installation file
INSTALL(TARGETS KWStyle
......@@ -123,7 +127,7 @@ INCLUDE(InstallRequiredSystemLibraries)
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "KWStyle")
SET(CPACK_PACKAGE_VENDOR "Kitware Inc.")
SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/ReadMe.txt")
SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/Copyright.txt")
SET(CPACK_PACKAGE_VERSION_MAJOR "1")
SET(CPACK_PACKAGE_VERSION_MINOR "0")
......
/*=========================================================================
Program: KWStyle - Kitware Style Checker
Module: $RCSfile: KWStyleConfigure.h.in,v $
Module: KWStyleConfigure.h.in
Copyright (c) Kitware, Inc. All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
......
KWStyle
=======
[![Circle CI]( https://circleci.com/gh/Kitware/KWStyle.svg?style=svg)](https://circleci.com/gh/Kitware/KWStyle )
Overview
--------
KWStyle is a style checker for source code which is integrated in the software process
to ensure that the code written by several users is consistent and can be
viewed/printed as it was written by one person.
Features
--------
Among the fearures provided by KWStyle:
- Several Indentation checking
- Copyright Header correctness
- Maximum line length
- Encapsulation preservation
- Internal variable checking via regular expressions
- New line at the end of file
A complete list of the features is available [here][fl].
[fl]: https://kitware.github.io/KWStyle/resources/features.html
......@@ -35,6 +35,7 @@ MACRO(ADD_TEST_FROM_BUG_TRACKER BUG_NUMBER FILENAME)
ENDMACRO(ADD_TEST_FROM_BUG_TRACKER BUG_NUMBER FILENAME)
ADD_TEST_FROM_BUG_TRACKER(kwsTabsTest test.cxx)
ADD_TEST_FROM_BUG_TRACKER(0001 test.cpp)
ADD_TEST_FROM_BUG_TRACKER(4204 test.cpp)
ADD_TEST_FROM_BUG_TRACKER(4227 test.cpp)
......@@ -65,3 +66,4 @@ ADD_TEST_FROM_BUG_TRACKER(9935 test.cxx)
ADD_TEST_FROM_BUG_TRACKER(9937 test.cxx)
ADD_TEST_FROM_BUG_TRACKER(9938 test.cxx)
ADD_TEST_FROM_BUG_TRACKER(9939 test.cxx)
ADD_TEST_FROM_BUG_TRACKER(10872 test.cxx)
<?xml version="1.0" encoding="iso-8859-1"?>
<Description>
<LineLength>120</LineLength>
<DeclarationOrder>0,1,2</DeclarationOrder>
<Typedefs>^[A-Z](\w|\d)*</Typedefs>
<MemberFunctions>^~?(\w|\d)*</MemberFunctions>
<InternalVariables>^[A-Z](\w|\d)*</InternalVariables>
<SemicolonSpace>0</SemicolonSpace>
<EndOfFileNewLine>1</EndOfFileNewLine>
<Tabs>1</Tabs>
<Spaces>3</Spaces>
<Comments>/**, *, */,true</Comments>
<Indent>SPACE,2,true,true</Indent>
<NameOfClass>[NameOfClass],qZ</NameOfClass>
<IfNDefDefine>__[NameOfClass]_[Extension]</IfNDefDefine>
<EmptyLines>2</EmptyLines>
<Template>[TNV]</Template>
<Operator>1,1</Operator>
</Description>
A()
{
f("//");
}
B()
{
g("//");
}
C()
{
}
<?xml version="1.0" encoding="iso-8859-1"?>
<Description>
<LineLength>120</LineLength>
<Tabs>1</Tabs>
</Description>
<Error>
<SourceLineNumber1>3</SourceLineNumber1>
<SourceLineNumber2>3</SourceLineNumber2>
<ErrorNumber>10</ErrorNumber>
</Error>
<Error>
<SourceLineNumber1>4</SourceLineNumber1>
<SourceLineNumber2>4</SourceLineNumber2>
<ErrorNumber>10</ErrorNumber>
</Error>
<Error>
<SourceLineNumber1>5</SourceLineNumber1>
<SourceLineNumber2>5</SourceLineNumber2>
<ErrorNumber>10</ErrorNumber>
</Error>
<Error>
<SourceLineNumber1>6</SourceLineNumber1>
<SourceLineNumber2>6</SourceLineNumber2>
<ErrorNumber>10</ErrorNumber>
</Error>
if (1) // this line has no tabs
{ // this line has no tabs
// this line has a leading tab
// this line has a tab in the middle
// this line has a tab at the end
// this line has lots of tabs
} // this line has no tabs
FROM debian:8
MAINTAINER Insight Software Consortium <community@itk.org>
RUN apt-get update && apt-get install -y \
build-essential \
cmake \
ninja-build \
git
RUN mkdir -p /usr/src/KWStyle-build
WORKDIR /usr/src
#!/bin/sh
script_dir="`cd $(dirname $0); pwd`"
docker build -t kitware/kwstyle-testing $script_dir
#!/bin/sh
script_dir="`cd $(dirname $0); pwd`"
docker run \
--rm \
-v $script_dir/../..:/usr/src/KWStyle \
kitware/kwstyle-testing \
/usr/src/KWStyle/Testing/Docker/test.sh
#!/bin/bash
# This is a script to build the modules and run the test suite in the base
# Docker container.
die() {
echo "Error: $@" 1>&2
exit 1;
}
cd /usr/src/KWStyle-build || die "Could not cd into the build directory"
cmake \
-G Ninja \
-DCMAKE_BUILD_TYPE:STRING=Release \
/usr/src/KWStyle || die "CMake configuration failed"
ctest -VV -D Experimental || die "ctest failed"
/*=========================================================================
Program: KWStyle - Kitware Style Checker
Module: $RCSfile: KWStyleTests.cxx,v $
Module: KWStyleTests.cxx
Copyright (c) Kitware, Inc. All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
......
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile: kwsBadCharactersTest.cxx,v $
Module: kwsBadCharactersTest.cxx
Language: C++
Date: $Date: 2006-09-12 01:19:48 $
Version: $Revision: 1.1 $
Date: $Date$
Version: $Revision$
Copyright (c) Insight Software Consortium. All rights reserved.
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
......@@ -18,6 +18,10 @@
#pragma warning ( disable : 4786 )
#endif
#if defined(__clang__)
#pragma clang diagnostic ignored "-Winvalid-source-encoding"
#endif
#include "kwsParser.h"
int kwsBadCharactersTest(int, char* [] )
......@@ -52,6 +56,7 @@ int kwsBadCharactersTest(int, char* [] )
parser.ClearErrors();
parser.SetBuffer(buffer);
parser.Check("LineLength","999");
// the point is that now we don't check in comments
parser.Check("BadCharacters","false");
std::cout << "Test for good syntax: ";
......@@ -60,7 +65,7 @@ int kwsBadCharactersTest(int, char* [] )
{
for(unsigned int i=0;i<errors.size();i++)
{
std::cout << errors[i].line << " : "
std::cout << errors[i].line << " : "
<< errors[i].description << std::endl;
}
std::cout << "[FAILED]" << std::endl;
......@@ -69,6 +74,6 @@ int kwsBadCharactersTest(int, char* [] )
std::cout << "[PASSED]" << std::endl;
std::cout << "[DONE]" << std::endl;
return 0;
}
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile: kwsRunKWStyleTest.cxx,v $
Module: kwsRunKWStyleTest.cxx
Language: C++
Date: $Date: 2009-02-06 20:07:12 $
Version: $Revision: 1.2 $
Date: $Date$
Version: $Revision$
Copyright (c) Insight Software Consortium. All rights reserved.
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
......@@ -21,7 +21,7 @@
#include <iostream>
#include <kwssys/Process.h>
int kwsRunKWStyleTest(int argc, char* argv[] )
int kwsRunKWStyleTest(int , char* argv[] )
{
argv++;
......
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile: kwsSemiColonSpaceTest.cxx,v $
Module: kwsSemiColonSpaceTest.cxx
Language: C++
Date: $Date: 2009-11-24 18:06:20 $
Version: $Revision: 1.4 $
Date: $Date$
Version: $Revision$
Copyright (c) Insight Software Consortium. All rights reserved.
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
......
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile: kwsStatementPerLineTest.cxx,v $
Module: kwsStatementPerLineTest.cxx
Language: C++
Date: $Date: 2006-08-01 16:23:03 $
Version: $Revision: 1.1 $
Date: $Date$
Version: $Revision$
Copyright (c) Insight Software Consortium. All rights reserved.
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
......
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile: kwsSwitchCaseTest.cxx,v $
Module: kwsSwitchCaseTest.cxx
Language: C++
Date: $Date: 2006-09-12 01:19:48 $
Version: $Revision: 1.1 $
Date: $Date$
Version: $Revision$
Copyright (c) Insight Software Consortium. All rights reserved.
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
......
......@@ -2,10 +2,10 @@
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile: kwsTestMain.h,v $
Module: kwsTestMain.h
Language: C++
Date: $Date: 2009-02-06 20:07:15 $
Version: $Revision: 1.6 $
Date: $Date$
Version: $Revision$
Copyright (c) Insight Software Consortium. All rights reserved.
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
......@@ -108,19 +108,19 @@ int Compare(const char* baseline, const char* testfile)
// Go through the testfile and check if we have the same errors than the
// baseline
long int posError = testfileBuffer.find("<Error>");
long int posErrorBase = testfileBuffer.find("<Error>");;
long int posError = static_cast<long int>(testfileBuffer.find("<Error>"));
long int posErrorBase = static_cast<long int>(testfileBuffer.find("<Error>"));
while(posError != -1)
{
long int posErrorEnd = testfileBuffer.find("</Error>",posError);
long int posErrorEnd = static_cast<long int>(testfileBuffer.find("</Error>",posError));
std::string subError = testfileBuffer.substr(posError,posErrorEnd-posError);
long int line1a = subError.find("<SourceLineNumber1>");
long int line1b = subError.find("</SourceLineNumber1>");
long int line2a = subError.find("<SourceLineNumber2>");
long int line2b = subError.find("</SourceLineNumber2>");
long int errorNumbera = subError.find("<ErrorNumber>");
long int errorNumberb = subError.find("</ErrorNumber>");
long int line1a = static_cast<long int>(subError.find("<SourceLineNumber1>"));
long int line1b = static_cast<long int>(subError.find("</SourceLineNumber1>"));
long int line2a = static_cast<long int>(subError.find("<SourceLineNumber2>"));
long int line2b = static_cast<long int>(subError.find("</SourceLineNumber2>"));
long int errorNumbera = static_cast<long int>(subError.find("<ErrorNumber>"));
long int errorNumberb = static_cast<long int>(subError.find("</ErrorNumber>"));
unsigned int l1 = atoi(subError.substr(line1a+19,line1b-line1a-19).c_str());
unsigned int l2 = atoi(subError.substr(line2a+19,line2b-line2a-19).c_str());
unsigned int errorNumber = atoi(subError.substr(errorNumbera+13,errorNumberb-errorNumbera-13).c_str());
......@@ -131,14 +131,14 @@ int Compare(const char* baseline, const char* testfile)
std::cout << "Error not found" << std::endl;
return 1;
}
long int posErrorEndBase = baselineBuffer.find("</Error>",posErrorBase);
long int posErrorEndBase = static_cast<long int>(baselineBuffer.find("</Error>",posErrorBase));
std::string subErrorBase = baselineBuffer.substr(posErrorBase,posErrorEndBase-posErrorBase);
long int line1aBase = subErrorBase.find("<SourceLineNumber1>");
long int line1bBase = subErrorBase.find("</SourceLineNumber1>");
long int line2aBase = subErrorBase.find("<SourceLineNumber2>");
long int line2bBase = subErrorBase.find("</SourceLineNumber2>");
long int errorNumberaBase = subErrorBase.find("<ErrorNumber>");
long int errorNumberbBase = subErrorBase.find("</ErrorNumber>");
long int line1aBase = static_cast<long int>(subErrorBase.find("<SourceLineNumber1>"));
long int line1bBase = static_cast<long int>(subErrorBase.find("</SourceLineNumber1>"));
long int line2aBase = static_cast<long int>(subErrorBase.find("<SourceLineNumber2>"));
long int line2bBase = static_cast<long int>(subErrorBase.find("</SourceLineNumber2>"));
long int errorNumberaBase = static_cast<long int>(subErrorBase.find("<ErrorNumber>"));
long int errorNumberbBase = static_cast<long int>(subErrorBase.find("</ErrorNumber>"));
unsigned int l1Base = atoi(subErrorBase.substr(line1aBase+19,line1bBase-line1aBase-19).c_str());
unsigned int l2Base = atoi(subErrorBase.substr(line2aBase+19,line2bBase-line2aBase-19).c_str());
unsigned int errorNumberBase = atoi(subErrorBase.substr(errorNumberaBase+13,errorNumberbBase-errorNumberaBase-13).c_str());
......@@ -152,8 +152,8 @@ int Compare(const char* baseline, const char* testfile)
return 1;
}
posError = testfileBuffer.find("<Error>",posError+1);
posErrorBase = baselineBuffer.find("<Error>",posErrorBase+1);
posError = static_cast<long int>(testfileBuffer.find("<Error>",posError+1));
posErrorBase = static_cast<long int>(baselineBuffer.find("<Error>",posErrorBase+1));
}
// Check that we don't have any other errors in the baseline
......
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile: kwsVariablePerLineTest.cxx,v $
Module: kwsVariablePerLineTest.cxx
Language: C++
Date: $Date: 2006-08-02 18:23:03 $
Version: $Revision: 1.1 $
Date: $Date$
Version: $Revision$
Copyright (c) Insight Software Consortium. All rights reserved.
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
......
......@@ -115,10 +115,10 @@ void kwsysBase64_Encode1(const unsigned char *src, unsigned char *dest)
actually knowing how much data to expect (if the input is not a multiple of
3 bytes then the extra padding needed to complete the encode 4 bytes will
stop the decoding anyway). */
unsigned long kwsysBase64_Encode(const unsigned char *input,
unsigned long length,
unsigned char *output,
int mark_end)
size_t kwsysBase64_Encode(const unsigned char *input,
size_t length,
unsigned char *output,
int mark_end)
{
const unsigned char *ptr = input;
const unsigned char *end = input + length;
......@@ -157,7 +157,7 @@ unsigned long kwsysBase64_Encode(const unsigned char *input,
optr += 4;
}
return (unsigned long)(optr - output);
return (size_t)(optr - output);
}
/*--------------------------------------------------------------------------*/
......@@ -207,10 +207,10 @@ int kwsysBase64_Decode3(const unsigned char *src, unsigned char *dest)
'length' parameter is ignored. This enables the caller to decode a stream
without actually knowing how much decoded data to expect (of course, the
buffer must be large enough). */
unsigned long kwsysBase64_Decode(const unsigned char *input,
unsigned long length,
unsigned char *output,
unsigned long max_input_length)
size_t kwsysBase64_Decode(const unsigned char *input,
size_t length,
unsigned char *output,
size_t max_input_length)
{
const unsigned char *ptr = input;
unsigned char *optr = output;
......@@ -226,7 +226,7 @@ unsigned long kwsysBase64_Decode(const unsigned char *input,
optr += len;
if(len < 3)
{
return (unsigned long)(optr - output);
return (size_t)(optr - output);
}
ptr += 4;
}
......@@ -240,7 +240,7 @@ unsigned long kwsysBase64_Decode(const unsigned char *input,
optr += len;
if(len < 3)
{
return (unsigned long)(optr - output);
return (size_t)(optr - output);
}
ptr += 4;
}
......@@ -275,5 +275,5 @@ unsigned long kwsysBase64_Decode(const unsigned char *input,
}
}
return (unsigned long)(optr - output);
return (size_t)(optr - output);
}
......@@ -14,6 +14,8 @@
#include <@KWSYS_NAMESPACE@/Configure.h>
#include <stddef.h> /* size_t */
/* Redefine all public interface symbol names to be in the proper
namespace. These macros are used internally to kwsys only, and are
not visible to user code. Use kwsysHeaderDump.pl to reproduce
......@@ -68,10 +70,10 @@ kwsysEXPORT void kwsysBase64_Encode1(const unsigned char *src,
* the extra padding needed to complete the encode 4 bytes will stop
* the decoding anyway).
*/
kwsysEXPORT unsigned long kwsysBase64_Encode(const unsigned char *input,
unsigned long length,