diff --git a/.gitignore b/.gitignore
index e2af0e2..f0ccae9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -29,3 +29,6 @@
# Cmake build directory
build
+
+# Visual Studio build directory
+build_vs2013
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 54e89a4..3547f65 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -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
diff --git a/build/.ignore b/build/.ignore
deleted file mode 100644
index e69de29..0000000
diff --git a/linecount.vcxproj b/build_vs2013/linecount.vcxproj
similarity index 90%
rename from linecount.vcxproj
rename to build_vs2013/linecount.vcxproj
index 831c1e1..0a6d23d 100644
--- a/linecount.vcxproj
+++ b/build_vs2013/linecount.vcxproj
@@ -18,6 +18,13 @@
x64
+
+
+
+
+
+
+
{E5D80D5A-FDE6-44FE-9E97-DF3D470DD5E9}
Win32Proj
@@ -109,10 +116,13 @@
Level3
- MaxSpeed
+ Full
true
true
WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)
+ Speed
+ AnySuitable
+ true
Console
@@ -126,10 +136,13 @@
Level3
- MaxSpeed
+ Full
true
true
WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)
+ AnySuitable
+ Speed
+ true
Console
@@ -138,13 +151,6 @@
true
-
-
-
-
-
-
-
diff --git a/linecount.sln b/build_vs2013/turbo-linecount.sln
similarity index 100%
rename from linecount.sln
rename to build_vs2013/turbo-linecount.sln
diff --git a/main.cpp b/src/main.cpp
similarity index 88%
rename from main.cpp
rename to src/main.cpp
index 7fa6f38..448214d 100644
--- a/main.cpp
+++ b/src/main.cpp
@@ -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());
diff --git a/linecount.cpp b/src/turbo_linecount.cpp
similarity index 83%
rename from linecount.cpp
rename to src/turbo_linecount.cpp
index 2654931..d758afd 100644
--- a/linecount.cpp
+++ b/src/turbo_linecount.cpp
@@ -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
#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;
\ No newline at end of file
+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
diff --git a/linecount.h b/src/turbo_linecount.h
similarity index 62%
rename from linecount.h
rename to src/turbo_linecount.h
index fbe1701..76fd600 100644
--- a/linecount.h
+++ b/src/turbo_linecount.h
@@ -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
#include
#include
-#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
diff --git a/compare_testfiles.sh b/tests/compare_testfiles.sh
old mode 100755
new mode 100644
similarity index 100%
rename from compare_testfiles.sh
rename to tests/compare_testfiles.sh
diff --git a/create_testfiles.sh b/tests/create_testfiles.sh
old mode 100755
new mode 100644
similarity index 100%
rename from create_testfiles.sh
rename to tests/create_testfiles.sh