Skip to content
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
2 changes: 2 additions & 0 deletions msvc/ugrep.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,7 @@
<ClInclude Include="..\src\glob.hpp" />
<ClInclude Include="..\src\mmap.hpp" />
<ClInclude Include="..\src\output.hpp" />
<ClInclude Include="..\src\path.hpp" />
<ClInclude Include="..\src\query.hpp" />
<ClInclude Include="..\src\screen.hpp" />
<ClInclude Include="..\src\stats.hpp" />
Expand Down Expand Up @@ -541,6 +542,7 @@
<ClCompile Include="..\src\cnf.cpp" />
<ClCompile Include="..\src\glob.cpp" />
<ClCompile Include="..\src\output.cpp" />
<ClCompile Include="..\src\path.cpp" />
<ClCompile Include="..\src\query.cpp" />
<ClCompile Include="..\src\screen.cpp" />
<ClCompile Include="..\src\stats.cpp" />
Expand Down
6 changes: 6 additions & 0 deletions msvc/ugrep.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@
<ClInclude Include="..\src\query.hpp">
<Filter>src</Filter>
</ClInclude>
<ClInclude Include="..\src\path.hpp">
<Filter>src</Filter>
</ClInclude>
<ClInclude Include="..\src\output.hpp">
<Filter>src</Filter>
</ClInclude>
Expand Down Expand Up @@ -159,6 +162,9 @@
<ClCompile Include="..\src\output.cpp">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\src\path.cpp">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\lib\posix.cpp">
<Filter>lib</Filter>
</ClCompile>
Expand Down
4 changes: 4 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ ugrep_SOURCES = \
mmap.hpp \
output.hpp \
output.cpp \
path.hpp \
path.cpp \
query.hpp \
query.cpp \
screen.hpp \
Expand All @@ -62,6 +64,8 @@ ugrep_indexer_SOURCES = \
ugrep-indexer.cpp \
glob.hpp \
glob.cpp \
path.hpp \
path.cpp \
zopen.h \
zopen.c \
zstream.hpp \
Expand Down
57 changes: 49 additions & 8 deletions src/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ am__installdirs = "$(DESTDIR)$(bindir)"
PROGRAMS = $(bin_PROGRAMS)
am_ugrep_OBJECTS = ugrep-ugrep.$(OBJEXT) ugrep-cnf.$(OBJEXT) \
ugrep-glob.$(OBJEXT) ugrep-output.$(OBJEXT) \
ugrep-query.$(OBJEXT) ugrep-screen.$(OBJEXT) \
ugrep-stats.$(OBJEXT) ugrep-vkey.$(OBJEXT) \
ugrep-zopen.$(OBJEXT)
ugrep-path.$(OBJEXT) ugrep-query.$(OBJEXT) \
ugrep-screen.$(OBJEXT) ugrep-stats.$(OBJEXT) \
ugrep-vkey.$(OBJEXT) ugrep-zopen.$(OBJEXT)
ugrep_OBJECTS = $(am_ugrep_OBJECTS)
am__DEPENDENCIES_1 =
ugrep_DEPENDENCIES = $(am__DEPENDENCIES_1) \
Expand All @@ -124,7 +124,8 @@ am__dirstamp = $(am__leading_dot)dirstamp
am_ugrep_indexer_OBJECTS = \
$(top_builddir)/lib/ugrep_indexer-input.$(OBJEXT) \
ugrep_indexer-ugrep-indexer.$(OBJEXT) \
ugrep_indexer-glob.$(OBJEXT) ugrep_indexer-zopen.$(OBJEXT)
ugrep_indexer-glob.$(OBJEXT) ugrep_indexer-path.$(OBJEXT) \
ugrep_indexer-zopen.$(OBJEXT)
ugrep_indexer_OBJECTS = $(am_ugrep_indexer_OBJECTS)
ugrep_indexer_DEPENDENCIES = $(am__DEPENDENCIES_1)
AM_V_P = $(am__v_P_@AM_V@)
Expand All @@ -145,10 +146,12 @@ am__maybe_remake_depfiles = depfiles
am__depfiles_remade = \
$(top_builddir)/lib/$(DEPDIR)/ugrep_indexer-input.Po \
./$(DEPDIR)/ugrep-cnf.Po ./$(DEPDIR)/ugrep-glob.Po \
./$(DEPDIR)/ugrep-output.Po ./$(DEPDIR)/ugrep-query.Po \
./$(DEPDIR)/ugrep-screen.Po ./$(DEPDIR)/ugrep-stats.Po \
./$(DEPDIR)/ugrep-ugrep.Po ./$(DEPDIR)/ugrep-vkey.Po \
./$(DEPDIR)/ugrep-zopen.Po ./$(DEPDIR)/ugrep_indexer-glob.Po \
./$(DEPDIR)/ugrep-output.Po ./$(DEPDIR)/ugrep-path.Po \
./$(DEPDIR)/ugrep-query.Po ./$(DEPDIR)/ugrep-screen.Po \
./$(DEPDIR)/ugrep-stats.Po ./$(DEPDIR)/ugrep-ugrep.Po \
./$(DEPDIR)/ugrep-vkey.Po ./$(DEPDIR)/ugrep-zopen.Po \
./$(DEPDIR)/ugrep_indexer-glob.Po \
./$(DEPDIR)/ugrep_indexer-path.Po \
./$(DEPDIR)/ugrep_indexer-ugrep-indexer.Po \
./$(DEPDIR)/ugrep_indexer-zopen.Po
am__mv = mv -f
Expand Down Expand Up @@ -373,6 +376,8 @@ ugrep_SOURCES = \
mmap.hpp \
output.hpp \
output.cpp \
path.hpp \
path.cpp \
query.hpp \
query.cpp \
screen.hpp \
Expand Down Expand Up @@ -402,6 +407,8 @@ ugrep_indexer_SOURCES = \
ugrep-indexer.cpp \
glob.hpp \
glob.cpp \
path.hpp \
path.cpp \
zopen.h \
zopen.c \
zstream.hpp \
Expand Down Expand Up @@ -514,13 +521,15 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ugrep-cnf.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ugrep-glob.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ugrep-output.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ugrep-path.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ugrep-query.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ugrep-screen.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ugrep-stats.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ugrep-ugrep.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ugrep-vkey.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ugrep-zopen.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ugrep_indexer-glob.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ugrep_indexer-path.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ugrep_indexer-ugrep-indexer.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ugrep_indexer-zopen.Po@am__quote@ # am--include-marker

Expand Down Expand Up @@ -646,6 +655,20 @@ ugrep-output.obj: output.cpp
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ugrep_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o ugrep-output.obj `if test -f 'output.cpp'; then $(CYGPATH_W) 'output.cpp'; else $(CYGPATH_W) '$(srcdir)/output.cpp'; fi`

ugrep-path.o: path.cpp
@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ugrep_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT ugrep-path.o -MD -MP -MF $(DEPDIR)/ugrep-path.Tpo -c -o ugrep-path.o `test -f 'path.cpp' || echo '$(srcdir)/'`path.cpp
@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/ugrep-path.Tpo $(DEPDIR)/ugrep-path.Po
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='path.cpp' object='ugrep-path.o' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ugrep_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o ugrep-path.o `test -f 'path.cpp' || echo '$(srcdir)/'`path.cpp

ugrep-path.obj: path.cpp
@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ugrep_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT ugrep-path.obj -MD -MP -MF $(DEPDIR)/ugrep-path.Tpo -c -o ugrep-path.obj `if test -f 'path.cpp'; then $(CYGPATH_W) 'path.cpp'; else $(CYGPATH_W) '$(srcdir)/path.cpp'; fi`
@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/ugrep-path.Tpo $(DEPDIR)/ugrep-path.Po
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='path.cpp' object='ugrep-path.obj' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ugrep_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o ugrep-path.obj `if test -f 'path.cpp'; then $(CYGPATH_W) 'path.cpp'; else $(CYGPATH_W) '$(srcdir)/path.cpp'; fi`

ugrep-query.o: query.cpp
@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ugrep_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT ugrep-query.o -MD -MP -MF $(DEPDIR)/ugrep-query.Tpo -c -o ugrep-query.o `test -f 'query.cpp' || echo '$(srcdir)/'`query.cpp
@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/ugrep-query.Tpo $(DEPDIR)/ugrep-query.Po
Expand Down Expand Up @@ -744,6 +767,20 @@ ugrep_indexer-glob.obj: glob.cpp
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ugrep_indexer_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o ugrep_indexer-glob.obj `if test -f 'glob.cpp'; then $(CYGPATH_W) 'glob.cpp'; else $(CYGPATH_W) '$(srcdir)/glob.cpp'; fi`

ugrep_indexer-path.o: path.cpp
@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ugrep_indexer_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT ugrep_indexer-path.o -MD -MP -MF $(DEPDIR)/ugrep_indexer-path.Tpo -c -o ugrep_indexer-path.o `test -f 'path.cpp' || echo '$(srcdir)/'`path.cpp
@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/ugrep_indexer-path.Tpo $(DEPDIR)/ugrep_indexer-path.Po
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='path.cpp' object='ugrep_indexer-path.o' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ugrep_indexer_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o ugrep_indexer-path.o `test -f 'path.cpp' || echo '$(srcdir)/'`path.cpp

ugrep_indexer-path.obj: path.cpp
@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ugrep_indexer_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT ugrep_indexer-path.obj -MD -MP -MF $(DEPDIR)/ugrep_indexer-path.Tpo -c -o ugrep_indexer-path.obj `if test -f 'path.cpp'; then $(CYGPATH_W) 'path.cpp'; else $(CYGPATH_W) '$(srcdir)/path.cpp'; fi`
@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/ugrep_indexer-path.Tpo $(DEPDIR)/ugrep_indexer-path.Po
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='path.cpp' object='ugrep_indexer-path.obj' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ugrep_indexer_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o ugrep_indexer-path.obj `if test -f 'path.cpp'; then $(CYGPATH_W) 'path.cpp'; else $(CYGPATH_W) '$(srcdir)/path.cpp'; fi`

ID: $(am__tagged_files)
$(am__define_uniq_tagged_files); mkid -fID $$unique
tags: tags-am
Expand Down Expand Up @@ -876,13 +913,15 @@ distclean: distclean-am
-rm -f ./$(DEPDIR)/ugrep-cnf.Po
-rm -f ./$(DEPDIR)/ugrep-glob.Po
-rm -f ./$(DEPDIR)/ugrep-output.Po
-rm -f ./$(DEPDIR)/ugrep-path.Po
-rm -f ./$(DEPDIR)/ugrep-query.Po
-rm -f ./$(DEPDIR)/ugrep-screen.Po
-rm -f ./$(DEPDIR)/ugrep-stats.Po
-rm -f ./$(DEPDIR)/ugrep-ugrep.Po
-rm -f ./$(DEPDIR)/ugrep-vkey.Po
-rm -f ./$(DEPDIR)/ugrep-zopen.Po
-rm -f ./$(DEPDIR)/ugrep_indexer-glob.Po
-rm -f ./$(DEPDIR)/ugrep_indexer-path.Po
-rm -f ./$(DEPDIR)/ugrep_indexer-ugrep-indexer.Po
-rm -f ./$(DEPDIR)/ugrep_indexer-zopen.Po
-rm -f Makefile
Expand Down Expand Up @@ -934,13 +973,15 @@ maintainer-clean: maintainer-clean-am
-rm -f ./$(DEPDIR)/ugrep-cnf.Po
-rm -f ./$(DEPDIR)/ugrep-glob.Po
-rm -f ./$(DEPDIR)/ugrep-output.Po
-rm -f ./$(DEPDIR)/ugrep-path.Po
-rm -f ./$(DEPDIR)/ugrep-query.Po
-rm -f ./$(DEPDIR)/ugrep-screen.Po
-rm -f ./$(DEPDIR)/ugrep-stats.Po
-rm -f ./$(DEPDIR)/ugrep-ugrep.Po
-rm -f ./$(DEPDIR)/ugrep-vkey.Po
-rm -f ./$(DEPDIR)/ugrep-zopen.Po
-rm -f ./$(DEPDIR)/ugrep_indexer-glob.Po
-rm -f ./$(DEPDIR)/ugrep_indexer-path.Po
-rm -f ./$(DEPDIR)/ugrep_indexer-ugrep-indexer.Po
-rm -f ./$(DEPDIR)/ugrep_indexer-zopen.Po
-rm -f Makefile
Expand Down
92 changes: 92 additions & 0 deletions src/path.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/******************************************************************************\
* Copyright (c) 2019, Robert van Engelen, Genivia Inc. All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions are met: *
* *
* (1) Redistributions of source code must retain the above copyright notice, *
* this list of conditions and the following disclaimer. *
* *
* (2) Redistributions in binary form must reproduce the above copyright *
* notice, this list of conditions and the following disclaimer in the *
* documentation and/or other materials provided with the distribution. *
* *
* (3) The name of the author may not be used to endorse or promote products *
* derived from this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED *
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF *
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO *
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; *
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, *
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR *
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF *
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
\******************************************************************************/

/**
@file path.cpp
@brief Handling of file paths
@author Robert van Engelen - [email protected]
@copyright (c) 2025, Robert van Engelen, Genivia Inc. All rights reserved.
@copyright (c) BSD-3 License - see LICENSE.txt
*/

#include "path.hpp"

// check if we are natively compiling for a Windows OS (not Cygwin and not MinGW)
#if (defined(__WIN32__) || defined(_WIN32) || defined(WIN32) || defined(_WIN64) || defined(__BORLANDC__)) && !defined(__CYGWIN__) && !defined(__MINGW32__) && !defined(__MINGW64__)
# define OS_WIN
#endif

#ifdef OS_WIN
#define PATHSEPCHR '\\'
#define PATHSEPSTR "\\"
#else
#define PATHSEPCHR '/'
#define PATHSEPSTR "/"
#endif

// get a path from a directory, or as is if already absolute
std::string Path::from_dir(const std::string& dir, const std::string& path)
{
// C++17's std::filesystem::path may be used to implement our Path if present

#ifdef OS_WIN
char drive;

drive = path.front();
if (path.length() >= 2 &&
path[1] == ':' &&
((drive >= 'A' && drive <= 'Z') ||
(drive >= 'a' && drive <= 'z')))
#else
if (path.front() == PATHSEPCHR)
#endif
return path;

std::string fullpath;

if (path.front() == '~')
{
const char *home;
#ifdef OS_WIN
home = getenv("USERPROFILE");
#else
home = getenv("HOME");
#endif
if (home != NULL)
fullpath.assign(home);
else
fullpath.assign(dir);
fullpath.append(path.c_str() + 1);

return fullpath;
}

fullpath.assign(dir).append(PATHSEPSTR).append(path);

return fullpath;
}
53 changes: 53 additions & 0 deletions src/path.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/******************************************************************************\
* Copyright (c) 2019, Robert van Engelen, Genivia Inc. All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions are met: *
* *
* (1) Redistributions of source code must retain the above copyright notice, *
* this list of conditions and the following disclaimer. *
* *
* (2) Redistributions in binary form must reproduce the above copyright *
* notice, this list of conditions and the following disclaimer in the *
* documentation and/or other materials provided with the distribution. *
* *
* (3) The name of the author may not be used to endorse or promote products *
* derived from this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED *
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF *
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO *
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; *
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, *
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR *
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF *
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
\******************************************************************************/

/**
@file path.hpp
@brief Handling of file paths
@author Robert van Engelen - [email protected]
@copyright (c) 2025, Robert van Engelen, Genivia Inc. All rights reserved.
@copyright (c) BSD-3 License - see LICENSE.txt

Supports Unix/Linux, MacOS, DOS, and Windows.
*/

#ifndef PATH_HPP
#define PATH_HPP

#include <string>

class Path {

public:

// get a path from a directory, or as is if already absolute
static std::string from_dir(const std::string& dir, const std::string& path);

};

#endif
3 changes: 2 additions & 1 deletion src/ugrep-indexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ inline uint64_t file_size(const struct stat& buf)

#include "reflex/input.h"
#include "glob.hpp"
#include "path.hpp"
#include <cctype>
#include <cinttypes>
#include <iostream>
Expand Down Expand Up @@ -1203,7 +1204,7 @@ void cat(const std::string& pathname, std::stack<Entry>& dir_entries, std::vecto

for (const auto& ignore : flag_ignore_files)
{
filepath.assign(pathname).append(PATHSEPSTR).append(ignore);
filepath.assign(Path::from_dir(pathname, ignore));

FILE *file = NULL;

Expand Down
3 changes: 2 additions & 1 deletion src/ugrep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ After this, you may want to test ugrep and install it (optional):
#include "glob.hpp"
#include "mmap.hpp"
#include "output.hpp"
#include "path.hpp"
#include "query.hpp"
#include "stats.hpp"
#include <reflex/matcher.h>
Expand Down Expand Up @@ -9698,7 +9699,7 @@ void Grep::recurse(size_t level, const char *pathname)

for (const auto& ignore_file : flag_ignore_files)
{
ignore_filename.assign(pathname).append(PATHSEPSTR).append(ignore_file);
ignore_filename.assign(Path::from_dir(pathname, ignore_file));

FILE *file = NULL;
if (fopenw_s(&file, ignore_filename.c_str(), "r") == 0)
Expand Down
2 changes: 2 additions & 0 deletions vs/ugrep/ugrep/ugrep.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
<ClCompile Include="src\cnf.cpp" />
<ClCompile Include="src\glob.cpp" />
<ClCompile Include="src\output.cpp" />
<ClCompile Include="src\path.cpp" />
<ClCompile Include="src\query.cpp" />
<ClCompile Include="src\screen.cpp" />
<ClCompile Include="src\stats.cpp" />
Expand Down Expand Up @@ -106,6 +107,7 @@
<ClInclude Include="src\glob.hpp" />
<ClInclude Include="src\mmap.hpp" />
<ClInclude Include="src\output.hpp" />
<ClInclude Include="src\path.hpp" />
<ClInclude Include="src\query.hpp" />
<ClInclude Include="src\screen.hpp" />
<ClInclude Include="src\stats.hpp" />
Expand Down
Loading