|
|
|
@ -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
|