Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added PathMatchRegex for Win32 #122

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions src/KM_fileio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#ifdef KM_WIN32
#include <direct.h>
#include <regex>
#else
#define _getcwd getcwd
#define _unlink unlink
Expand Down Expand Up @@ -563,12 +564,10 @@ Kumu::FindInPath(const IPathMatch& Pattern, const std::string& SearchDir,
return FoundPaths;
}


#ifndef KM_WIN32

//
Kumu::PathMatchRegex::PathMatchRegex(const std::string& s)
{
#ifndef KM_WIN32
int result = regcomp(&m_regex, s.c_str(), REG_NOSUB); // (REG_EXTENDED|REG_NOSUB|REG_NEWLINE));

if ( result )
Expand All @@ -578,22 +577,36 @@ Kumu::PathMatchRegex::PathMatchRegex(const std::string& s)
DefaultLogSink().Error("PathMatchRegex: %s\n", buf);
regfree(&m_regex);
}
#else
try {
m_regex.assign(s.c_str(), s.length(), std::regex_constants::nosubs);
}
catch (const std::regex_error& e) {
DefaultLogSink().Error("PathMatchRegex: %s\n", e.what());
}
#endif
}

Kumu::PathMatchRegex::PathMatchRegex(const PathMatchRegex& rhs) : IPathMatch() {
m_regex = rhs.m_regex;
}

Kumu::PathMatchRegex::~PathMatchRegex() {
#ifndef KM_WIN32
regfree(&m_regex);
#endif
}

bool
Kumu::PathMatchRegex::Match(const std::string& s) const {
#ifndef KM_WIN32
return ( regexec(&m_regex, s.c_str(), 0, 0, 0) == 0 );
#else
return std::regex_match(s, m_regex);
#endif
}


#ifndef KM_WIN32

//
Kumu::PathMatchGlob::PathMatchGlob(const std::string& glob)
Expand Down Expand Up @@ -652,7 +665,7 @@ Kumu::GetExecutablePath(const std::string& default_path)

#if defined(KM_WIN32)
DWORD size = X_BUFSIZE;
DWORD rc = GetModuleFileName(0, path, size);
DWORD rc = GetModuleFileNameA(0, path, size);
success = ( rc != 0 );
#elif defined(KM_MACOSX)
uint32_t size = X_BUFSIZE;
Expand Down
12 changes: 9 additions & 3 deletions src/KM_fileio.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <string>

#ifdef KM_WIN32
# include <io.h>
# include "dirent_win.h"
#include <io.h>
#include <regex>
#include "dirent_win.h"

#else
# include <dirent.h>
# include <unistd.h>
Expand Down Expand Up @@ -214,11 +216,14 @@ namespace Kumu
inline bool Match(const std::string&) const { return true; }
};

#ifndef KM_WIN32
// matches pathnames using a regular expression
class PathMatchRegex : public IPathMatch
{
#ifndef KM_WIN32
regex_t m_regex;
#else
std::regex m_regex;
#endif
PathMatchRegex();
const PathMatchRegex& operator=(const PathMatchRegex&);

Expand All @@ -229,6 +234,7 @@ namespace Kumu
bool Match(const std::string& s) const;
};

#ifndef KM_WIN32
// matches pathnames using a Bourne shell glob expression
class PathMatchGlob : public IPathMatch
{
Expand Down
3 changes: 0 additions & 3 deletions src/TimedText_Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,7 @@ ASDCP::TimedText::LocalFilenameResolver::ResolveRID(const byte_t* uuid, TimedTex
UUID RID(uuid);
PathList_t found_list;

#ifndef KM_WIN32
// TODO, fix this for win32 (needs regex)
FindInPath(PathMatchRegex(RID.EncodeHex(buf, 64)), m_Dirname, found_list);
#endif

if ( found_list.size() == 1 )
{
Expand Down