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

Som devel proc #8

Merged
merged 7 commits into from
Nov 25, 2024
Merged
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: 1 addition & 1 deletion docopts.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
### regexes
value option
```
^ *-[a-zA-Z] +<\w+
^ *-[a-zA-Z] +<\w[\w ]*>
```
simple switch
```
Expand Down
60 changes: 31 additions & 29 deletions include/SOM/Glob.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@

#include <SOM/BaseTypes.h>
#include <SOM/coding.h>
#include <SOM/fglob.h>

#include <filesystem>
#include <functional>
#include <string>
#include <vector>

Expand All @@ -18,41 +16,45 @@ class I_GlobProcessor
virtual ~I_GlobProcessor() = default;
};


class Glob
{
public:
Glob(I_GlobProcessor& proc, bool onlyFiles=false, bool onlyDirs=false);
void glob(const std::string& fpath);
#if defined(_WIN32) or defined(GLOB_LINUX)
void glob(const CONST_C_STRING fpath);
#else
inline void glob(const CONST_C_STRING fpath)
{
callProc(fspath(fpath));
}
#endif // _WIN32
void glob(INT32 argc, const CONST_C_STRING* argv, INT32 start=0);

private:
using strVec = std::vector<std::string>;
struct pathVec : strVec
using fspath = std::filesystem::path;
static bool isGlob(const CONST_C_STRING token);
inline static bool todo(const CONST_C_STRING fpath)
{
void add(const std::string& s);
pathVec& operator << (const std::filesystem::directory_entry& e);
};

using ffunc = std::function<bool(const std::string&)>;
static const ffunc fd;
static const ffunc ff;
static const ffunc fx;
static bool isGlob(const std::string& token);
static void tokenize(strVec& tokens, const std::string& fpath);

const bool onlyDirs;
I_GlobProcessor& proc;
const ffunc filter;
pathVec buffs[2];
UINT8 pSrc = 0;
UINT8 pTrg = 1;
inline pathVec& getSrc() { return buffs[pSrc]; }
inline pathVec& getTrg() { return buffs[pTrg]; }
void getAll();
void getDirs(const pathVec& src, bool recursive=false);
void getGlob(const std::string& token, bool dirs=false);
void swap();
return isGlob(fpath) or fpath[0] == '~';
}
const bool mFiles;
const bool mDirs;
I_GlobProcessor& mProc;

#if defined(_WIN32) or defined(GLOB_LINUX)
using strVec = std::vector<std::string>;
strVec mItems;
static void tokenize(strVec& tokens, const CONST_C_STRING fpath);
void process(const fspath& path, size_t pos);
inline void process(const fspath&& path, size_t pos) { process(path, pos); }
void procDirs(const fspath& path, size_t pos, bool isLast=false, bool recursive=false);
void procGlob(const fspath& path, size_t pos, bool isLast=false);
void procAll(const fspath& path);
static CONST_C_STRING getHome();
#endif // _WIN32
void callProc(const fspath& path);

NODEF(Glob)
NOCOPY(Glob)
};
#endif // _H
10 changes: 5 additions & 5 deletions include/SOM/docopts.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ class DocOpts
return mSwitches.find(key) != mSwitches.end();
}
void reset();
const CONST_C_STRING* args() const { return mArgs; }
INT32 argc() const { return mArgc; }
inline const CONST_C_STRING* args() const { return mArgs; }
inline INT32 argc() const { return mArgc; }
void toShell() const;
const std::set<CHAR>& activeSwitches() const { return mSwitches; }
inline const std::set<CHAR>& activeSwitches() const { return mSwitches; }
private:
std::map<CHAR, CONST_C_STRING> mValues;
std::set<CHAR> mSwitches;
std::set<CHAR>mValueKeys;
std::set<CHAR>mSwitchKeys;
std::set<CHAR> mValueKeys;
std::set<CHAR> mSwitchKeys;
bool mOk = false;
const CONST_C_STRING* mArgs = nullptr;
INT32 mArgc = 0;
Expand Down
14 changes: 14 additions & 0 deletions make/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ else ifeq ($(config),trace_all)
glob_config = trace_all
somcpp_config = trace_all

else ifeq ($(config),glob_linux)
docopts_config = glob_linux
fglob_config = glob_linux
glob_config = glob_linux
somcpp_config = glob_linux

else ifeq ($(config),glob_linux_trace_all)
docopts_config = glob_linux_trace_all
fglob_config = glob_linux_trace_all
glob_config = glob_linux_trace_all
somcpp_config = glob_linux_trace_all

else
$(error "invalid configuration $(config)")
endif
Expand Down Expand Up @@ -73,6 +85,8 @@ help:
@echo " ci"
@echo " trace_on"
@echo " trace_all"
@echo " glob_linux"
@echo " glob_linux_trace_all"
@echo ""
@echo "TARGETS:"
@echo " all (default)"
Expand Down
12 changes: 10 additions & 2 deletions make/docopts.make
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ TARGET = $(TARGETDIR)/docopts
INCLUDES += -I../include
FORCE_INCLUDE +=
ALL_CPPFLAGS += $(CPPFLAGS) -MD -MP $(DEFINES) $(INCLUDES)
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -Os -std=c++17 -O3 -pedantic-errors -Wall
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -Os -std=c++17 -O3 -pedantic-errors -Wall
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -O3 -std=c++17 -O3 -pedantic-errors -Wall
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -O3 -std=c++17 -O3 -pedantic-errors -Wall
ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)
LIBS +=
LDDEPS +=
Expand All @@ -50,6 +50,14 @@ else ifeq ($(config),trace_all)
OBJDIR = ../build/linux/trace_all/docopts
DEFINES += -DNDEBUG -DTRACE_ALL

else ifeq ($(config),glob_linux)
OBJDIR = ../build/linux/glob_linux/docopts
DEFINES += -DNDEBUG -DGLOB_LINUX

else ifeq ($(config),glob_linux_trace_all)
OBJDIR = ../build/linux/glob_linux_trace_all/docopts
DEFINES += -DNDEBUG -DGLOB_LINUX -DTRACE_ALL

endif

# Per File Configurations
Expand Down
12 changes: 10 additions & 2 deletions make/fglob.make
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ TARGET = $(TARGETDIR)/fglob
INCLUDES += -I../include
FORCE_INCLUDE +=
ALL_CPPFLAGS += $(CPPFLAGS) -MD -MP $(DEFINES) $(INCLUDES)
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -Os -std=c++17 -O3 -pedantic-errors -Wall
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -Os -std=c++17 -O3 -pedantic-errors -Wall
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -O3 -std=c++17 -O3 -pedantic-errors -Wall
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -O3 -std=c++17 -O3 -pedantic-errors -Wall
ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)
LIBS +=
LDDEPS +=
Expand All @@ -50,6 +50,14 @@ else ifeq ($(config),trace_all)
OBJDIR = ../build/linux/trace_all/fglob
DEFINES += -DNDEBUG -DTRACE_ALL

else ifeq ($(config),glob_linux)
OBJDIR = ../build/linux/glob_linux/fglob
DEFINES += -DNDEBUG -DGLOB_LINUX

else ifeq ($(config),glob_linux_trace_all)
OBJDIR = ../build/linux/glob_linux_trace_all/fglob
DEFINES += -DNDEBUG -DGLOB_LINUX -DTRACE_ALL

endif

# Per File Configurations
Expand Down
12 changes: 10 additions & 2 deletions make/glob.make
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ TARGET = $(TARGETDIR)/glob
INCLUDES += -I../include
FORCE_INCLUDE +=
ALL_CPPFLAGS += $(CPPFLAGS) -MD -MP $(DEFINES) $(INCLUDES)
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -Os -std=c++17 -O3 -pedantic-errors -Wall
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -Os -std=c++17 -O3 -pedantic-errors -Wall
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -O3 -std=c++17 -O3 -pedantic-errors -Wall
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -O3 -std=c++17 -O3 -pedantic-errors -Wall
ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)
LIBS +=
LDDEPS +=
Expand All @@ -50,6 +50,14 @@ else ifeq ($(config),trace_all)
OBJDIR = ../build/linux/trace_all/glob
DEFINES += -DNDEBUG -DTRACE_ALL

else ifeq ($(config),glob_linux)
OBJDIR = ../build/linux/glob_linux/glob
DEFINES += -DNDEBUG -DGLOB_LINUX

else ifeq ($(config),glob_linux_trace_all)
OBJDIR = ../build/linux/glob_linux_trace_all/glob
DEFINES += -DNDEBUG -DGLOB_LINUX -DTRACE_ALL

endif

# Per File Configurations
Expand Down
11 changes: 9 additions & 2 deletions make/premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,20 @@ buildoptions_gcc = '-std=c++17 -O3 -pedantic-errors -Wall'

workspace 'somcpp'

configurations { 'ci', 'trace_on', 'trace_all' }
configurations { 'ci', 'trace_on', 'trace_all', 'glob_linux', 'glob_linux_trace_all' }
language 'C++'
targetdir '../build'
objdir '../build/%{_TARGET_OS}'
kind 'consoleapp'

defines { 'NDEBUG' }
optimize 'Size'
optimize 'Speed'
includedirs { '../include' }

filter { 'action:vs*' }
warnings 'high'
buildoptions { buildoptions_vs }
defines { '_CRT_SECURE_NO_WARNINGS' }

filter { 'action:gmake*' }
buildoptions { buildoptions_gcc }
Expand All @@ -33,6 +34,12 @@ workspace 'somcpp'
filter { 'configurations:trace_all' }
defines { 'TRACE_ALL' }

filter { 'configurations:glob_linux' }
defines { 'GLOB_LINUX' }

filter { 'configurations:glob_linux_trace_all' }
defines { 'GLOB_LINUX', 'TRACE_ALL' }

project 'docopts'
files { '../src/fio.cpp', '../src/docopts.cpp', '../runtime/docoptsMain.cpp' }

Expand Down
12 changes: 10 additions & 2 deletions make/somcpp.make
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ TARGET = $(TARGETDIR)/libsomcpp.a
INCLUDES += -I../include
FORCE_INCLUDE +=
ALL_CPPFLAGS += $(CPPFLAGS) -MD -MP $(DEFINES) $(INCLUDES)
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -Os -std=c++17 -O3 -pedantic-errors -Wall
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -Os -std=c++17 -O3 -pedantic-errors -Wall
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -O3 -std=c++17 -O3 -pedantic-errors -Wall
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -O3 -std=c++17 -O3 -pedantic-errors -Wall
ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)
LIBS +=
LDDEPS +=
Expand All @@ -50,6 +50,14 @@ else ifeq ($(config),trace_all)
OBJDIR = ../build/linux/trace_all/somcpp
DEFINES += -DNDEBUG -DTRACE_ALL

else ifeq ($(config),glob_linux)
OBJDIR = ../build/linux/glob_linux/somcpp
DEFINES += -DNDEBUG -DGLOB_LINUX

else ifeq ($(config),glob_linux_trace_all)
OBJDIR = ../build/linux/glob_linux_trace_all/somcpp
DEFINES += -DNDEBUG -DGLOB_LINUX -DTRACE_ALL

endif

# Per File Configurations
Expand Down
9 changes: 5 additions & 4 deletions runtime/globMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ INT32 main(const INT32 argc, const CONST_C_STRING* const argv)
proc = std::make_unique<GlobArgs>();
}
Glob glob(*proc, opts.isSet('f'), opts.isSet('d'));
for (auto i = 0; i < opts.argc(); ++i)
{
glob.glob(opts.args()[i]);
}
glob.glob(opts.argc(), opts.args());
// for (auto i = 0; i < opts.argc(); ++i)
// {
// glob.glob(opts.args()[i]);
// }
}
}
return ret;
Expand Down
Loading
Loading