mirror of
https://github.com/crioux/turbo-linecount.git
synced 2024-10-27 17:24:01 +00:00
refactor
This commit is contained in:
parent
6749faea62
commit
cb3365a7e0
3
.gitignore
vendored
3
.gitignore
vendored
@ -29,3 +29,6 @@
|
||||
|
||||
# Cmake build directory
|
||||
build
|
||||
|
||||
# Visual Studio build directory
|
||||
build_vs2013
|
||||
|
@ -1,19 +1,18 @@
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 3.3.0)
|
||||
PROJECT (LINECOUNT)
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 3.0.0)
|
||||
PROJECT (turbo-linecount)
|
||||
|
||||
IF(MSVC)
|
||||
SET(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "limited configs" FORCE)
|
||||
SET(CMAKE_CXX_FLAGS_RELEASE "/Ox /Ob2")
|
||||
SET(CMAKE_C_FLAGS_RELEASE "/Ox /Ob2")
|
||||
ELSE()
|
||||
SET(CMAKE_CXX_FLAGS_RELEASE "/O3")
|
||||
SET(CMAKE_CXX_FLAGS_RELEASE "-O3")
|
||||
SET(CMAKE_C_FLAGS_RELEASE "-O3")
|
||||
SET(CMAKE_EXE_LINKER_FLAGS "-s")
|
||||
ENDIF()
|
||||
|
||||
ADD_LIBRARY (linecount SHARED linecount.cpp linecount.h)
|
||||
ADD_LIBRARY (linecount_static STATIC linecount.cpp linecount.h)
|
||||
ADD_EXECUTABLE (lc main.cpp)
|
||||
ADD_LIBRARY (linecount SHARED src/linecount.cpp src/linecount.h)
|
||||
ADD_LIBRARY (linecount_static STATIC src/linecount.cpp src/linecount.h)
|
||||
ADD_EXECUTABLE (lc src/main.cpp)
|
||||
TARGET_LINK_LIBRARIES (lc linecount_static)
|
||||
|
||||
INSTALL(TARGETS lc
|
||||
|
@ -18,6 +18,13 @@
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\src\turbo_linecount.cpp" />
|
||||
<ClCompile Include="..\src\main.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\src\turbo_linecount.h" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{E5D80D5A-FDE6-44FE-9E97-DF3D470DD5E9}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
@ -109,10 +116,13 @@
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<Optimization>Full</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
|
||||
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
|
||||
<OmitFramePointers>true</OmitFramePointers>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
@ -126,10 +136,13 @@
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<Optimization>Full</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
|
||||
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
|
||||
<OmitFramePointers>true</OmitFramePointers>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
@ -138,13 +151,6 @@
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="linecount.cpp" />
|
||||
<ClCompile Include="main.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="linecount.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
@ -1,4 +1,12 @@
|
||||
#include"linecount.h"
|
||||
//
|
||||
// Turbo Linecount
|
||||
// Copyright 2015, Christien Rioux
|
||||
//
|
||||
// MIT Licensed, see file 'LICENSE' for details
|
||||
//
|
||||
///////////////////////////////////////////////
|
||||
|
||||
#include"turbo_linecount.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
@ -18,7 +26,7 @@
|
||||
|
||||
#endif
|
||||
|
||||
using namespace LineCount;
|
||||
using namespace TURBO_LINECOUNT;
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
|
||||
@ -153,7 +161,7 @@ int main(int argc, char **argv)
|
||||
|
||||
if (!lc.open(filename))
|
||||
{
|
||||
LCERROR err = lc.lastError();
|
||||
errno_t err = lc.lastError();
|
||||
LCSTRING errstr = lc.lastErrorString();
|
||||
|
||||
_ftprintf(stderr, _T("%s: Error %d (%s)\n"), argv[0], err, errstr.c_str());
|
||||
@ -164,7 +172,7 @@ int main(int argc, char **argv)
|
||||
LCLINECOUNT count;
|
||||
if (!lc.countLines(count))
|
||||
{
|
||||
LCERROR err = lc.lastError();
|
||||
errno_t err = lc.lastError();
|
||||
LCSTRING errstr = lc.lastErrorString();
|
||||
|
||||
_ftprintf(stderr, _T("%s: Error %d: (%s)\n"), argv[0], err, errstr.c_str());
|
@ -1,4 +1,12 @@
|
||||
#include"linecount.h"
|
||||
//
|
||||
// Turbo Linecount
|
||||
// Copyright 2015, Christien Rioux
|
||||
//
|
||||
// MIT Licensed, see file 'LICENSE' for details
|
||||
//
|
||||
///////////////////////////////////////////////
|
||||
|
||||
#include"turbo_linecount.h"
|
||||
#include<algorithm>
|
||||
#ifdef min
|
||||
#undef min
|
||||
@ -49,7 +57,7 @@ typedef off_t LCFILEOFFSET;
|
||||
|
||||
///////////////////////////// Line Count Class
|
||||
|
||||
BEGIN_LINECOUNT_NAMESPACE;
|
||||
BEGIN_TURBO_LINECOUNT_NAMESPACE;
|
||||
|
||||
struct LCTHREADCONTEXT
|
||||
{
|
||||
@ -122,13 +130,13 @@ void CLineCount::init(void)
|
||||
m_threadlinecounts.clear();
|
||||
}
|
||||
|
||||
void CLineCount::setLastError(LCERROR lasterror, LCSTRING lasterrorstring)
|
||||
void CLineCount::setLastError(errno_t lasterror, LCSTRING lasterrorstring)
|
||||
{
|
||||
m_lasterror = lasterror;
|
||||
m_lasterrorstring = lasterrorstring;
|
||||
}
|
||||
|
||||
LCERROR CLineCount::lastError() const
|
||||
errno_t CLineCount::lastError() const
|
||||
{
|
||||
return m_lasterror;
|
||||
}
|
||||
@ -461,7 +469,7 @@ bool CLineCount::countLines(LCLINECOUNT & linecount)
|
||||
}
|
||||
|
||||
// Static helpers
|
||||
LCLINECOUNT CLineCount::LineCount(LCFILEHANDLE fhandle, LCERROR * error, LCSTRING *errorstring)
|
||||
LCLINECOUNT CLineCount::LineCount(LCFILEHANDLE fhandle, errno_t * error, LCSTRING *errorstring)
|
||||
{
|
||||
CLineCount lc;
|
||||
if (!lc.open(fhandle))
|
||||
@ -498,7 +506,7 @@ LCLINECOUNT CLineCount::LineCount(LCFILEHANDLE fhandle, LCERROR * error, LCSTRIN
|
||||
return count;
|
||||
}
|
||||
|
||||
LCLINECOUNT CLineCount::LineCount(const TCHAR *filename, LCERROR * error, LCSTRING *errorstring)
|
||||
LCLINECOUNT CLineCount::LineCount(const TCHAR *filename, errno_t * error, LCSTRING *errorstring)
|
||||
{
|
||||
CLineCount lc;
|
||||
if (!lc.open(filename))
|
||||
@ -535,4 +543,47 @@ LCLINECOUNT CLineCount::LineCount(const TCHAR *filename, LCERROR * error, LCSTRI
|
||||
return count;
|
||||
}
|
||||
|
||||
END_LINECOUNT_NAMESPACE;
|
||||
END_TURBO_LINECOUNT_NAMESPACE;
|
||||
|
||||
|
||||
///////////////////////////// C Linkage
|
||||
|
||||
#ifndef _NO_TURBO_LINECOUNT_C
|
||||
|
||||
#ifdef _WIN32
|
||||
long long turbo_linecount_handle(HANDLE fhandle, errno_t * error, TCHAR ** errorstring)
|
||||
#else
|
||||
long long turbo_linecount_handle(int fhandle, errno_t * error, char ** errorstring)
|
||||
#endif
|
||||
{
|
||||
TURBO_LINECOUNT::LCSTRING errstr;
|
||||
|
||||
long long linecount = TURBO_LINECOUNT::CLineCount::LineCount(fhandle, error, &errstr);
|
||||
|
||||
if (errorstring)
|
||||
{
|
||||
*errorstring = _tcsdup(errstr.c_str());
|
||||
}
|
||||
|
||||
return linecount;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
long long turbo_linecount_file(const TCHAR *filename, errno_t * error, TCHAR ** errorstring)
|
||||
#else
|
||||
long long turbo_linecount_file(const char *filename, errno_t * error, char ** errorstring)
|
||||
#endif
|
||||
{
|
||||
TURBO_LINECOUNT::LCSTRING errstr;
|
||||
|
||||
long long linecount = TURBO_LINECOUNT::CLineCount::LineCount(filename, error, &errstr);
|
||||
|
||||
if (errorstring)
|
||||
{
|
||||
*errorstring = _tcsdup(errstr.c_str());
|
||||
}
|
||||
|
||||
return linecount;
|
||||
}
|
||||
|
||||
#endif
|
@ -1,9 +1,19 @@
|
||||
#ifndef __INC_LINECOUNT_H
|
||||
#define __INC_LINECOUNT_H
|
||||
//
|
||||
// Turbo Linecount
|
||||
// Copyright 2015, Christien Rioux
|
||||
//
|
||||
// MIT Licensed, see file 'LICENSE' for details
|
||||
//
|
||||
///////////////////////////////////////////////
|
||||
|
||||
#ifndef __INC_TURBO_LINECOUNT_H
|
||||
#define __INC_TURBO_LINECOUNT_H
|
||||
|
||||
#define LINECOUNT_VERSION_MAJOR 1
|
||||
#define LINECOUNT_VERSION_MINOR 0
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
///////////////////////////////////////////// Headers
|
||||
|
||||
////////////// Platform independent
|
||||
@ -11,8 +21,9 @@
|
||||
#include<string>
|
||||
#include<vector>
|
||||
#include<errno.h>
|
||||
#define BEGIN_LINECOUNT_NAMESPACE namespace LineCount {
|
||||
#define END_LINECOUNT_NAMESPACE }
|
||||
|
||||
#define BEGIN_TURBO_LINECOUNT_NAMESPACE namespace TURBO_LINECOUNT {
|
||||
#define END_TURBO_LINECOUNT_NAMESPACE }
|
||||
|
||||
////////////// Platform specific
|
||||
|
||||
@ -28,7 +39,7 @@
|
||||
|
||||
///////////////////////////////////////////// Line Count Class
|
||||
|
||||
BEGIN_LINECOUNT_NAMESPACE;
|
||||
BEGIN_TURBO_LINECOUNT_NAMESPACE;
|
||||
|
||||
////////////// Platform specific
|
||||
#ifdef _WIN32 // Windows
|
||||
@ -38,8 +49,8 @@ BEGIN_LINECOUNT_NAMESPACE;
|
||||
#else
|
||||
typedef std::string LCSTRING;
|
||||
#endif
|
||||
|
||||
typedef HANDLE LCFILEHANDLE;
|
||||
typedef errno_t LCERROR;
|
||||
typedef long long LCFILEOFFSET;
|
||||
typedef LCFILEOFFSET LCLINECOUNT;
|
||||
#define LCLINECOUNTFMT "%I64d"
|
||||
@ -48,7 +59,6 @@ BEGIN_LINECOUNT_NAMESPACE;
|
||||
|
||||
typedef std::string LCSTRING;
|
||||
typedef int LCFILEHANDLE;
|
||||
typedef errno_t LCERROR;
|
||||
#if (defined (__APPLE__) && defined (__MACH__))
|
||||
typedef off_t LCFILEOFFSET;
|
||||
#define LCLINECOUNTFMT "%lld"
|
||||
@ -79,7 +89,7 @@ private:
|
||||
bool m_opened;
|
||||
bool m_auto_close;
|
||||
LCFILEHANDLE m_fh;
|
||||
LCERROR m_lasterror;
|
||||
errno_t m_lasterror;
|
||||
LCSTRING m_lasterrorstring;
|
||||
LCFILEOFFSET m_filesize;
|
||||
PARAMETERS m_parameters;
|
||||
@ -95,7 +105,7 @@ private:
|
||||
|
||||
private:
|
||||
|
||||
void setLastError(LCERROR error, LCSTRING lasterrorstring);
|
||||
void setLastError(errno_t error, LCSTRING lasterrorstring);
|
||||
void init();
|
||||
bool createThread(int thread_number);
|
||||
#ifdef _WIN32
|
||||
@ -111,7 +121,7 @@ public:
|
||||
~CLineCount();
|
||||
|
||||
bool isOpened() const;
|
||||
LCERROR lastError() const;
|
||||
errno_t lastError() const;
|
||||
LCSTRING lastErrorString() const;
|
||||
|
||||
bool open(LCFILEHANDLE fhandle, bool auto_close = false);
|
||||
@ -123,10 +133,36 @@ public:
|
||||
public:
|
||||
|
||||
// Static utility functions
|
||||
static LCLINECOUNT LineCount(LCFILEHANDLE fhandle, LCERROR * error = NULL, LCSTRING * errorstring = NULL);
|
||||
static LCLINECOUNT LineCount(const TCHAR *filename, LCERROR * error = NULL, LCSTRING * errorstring = NULL);
|
||||
static LCLINECOUNT LineCount(LCFILEHANDLE fhandle, errno_t * error = NULL, LCSTRING * errorstring = NULL);
|
||||
static LCLINECOUNT LineCount(const TCHAR *filename, errno_t * error = NULL, LCSTRING * errorstring = NULL);
|
||||
};
|
||||
|
||||
END_LINECOUNT_NAMESPACE;
|
||||
END_TURBO_LINECOUNT_NAMESPACE;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
// C compatibility functions
|
||||
#ifndef _NO_TURBO_LINECOUNT_C
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
long long turbo_linecount_handle(HANDLE fhandle, errno_t * error = NULL, TCHAR ** errorstring = NULL);
|
||||
long long turbo_linecount_file(const TCHAR *filename, errno_t * error = NULL, TCHAR ** errorstring = NULL);
|
||||
#else
|
||||
long long turbo_linecount_handle(int fhandle, errno_t * error = NULL, char ** errorstring = NULL);
|
||||
long long turbo_linecount_file(const char *filename, errno_t * error = NULL, char ** errorstring = NULL);
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
0
compare_testfiles.sh → tests/compare_testfiles.sh
Executable file → Normal file
0
compare_testfiles.sh → tests/compare_testfiles.sh
Executable file → Normal file
0
create_testfiles.sh → tests/create_testfiles.sh
Executable file → Normal file
0
create_testfiles.sh → tests/create_testfiles.sh
Executable file → Normal file
Loading…
Reference in New Issue
Block a user