Skip to content

Commit

Permalink
Som devel (#6)
Browse files Browse the repository at this point in the history
* wip: glob

* interim towards glob

* interim demo.cmd

* glob

* docopts: use existing args -> no copy

* fix: make

* fix: make
  • Loading branch information
sorgom authored Nov 23, 2024
1 parent f6c43d8 commit 296bb96
Show file tree
Hide file tree
Showing 18 changed files with 643 additions and 86 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/c-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: "Checkout repository"
- name: checkout
uses: actions/checkout@v3
with:
submodules: 'true'
Expand Down
58 changes: 58 additions & 0 deletions include/SOM/Glob.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#pragma once
#ifndef GLOB_H
#define GLOB_H

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

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

class I_GlobProcessor
{
public:
virtual void process(const std::string& fpath) = 0;
virtual ~I_GlobProcessor() = default;
};


class Glob
{
public:
Glob(I_GlobProcessor& proc, bool onlyFiles=false, bool onlyDirs=false);
void glob(const std::string& fpath);

private:
using strVec = std::vector<std::string>;
struct pathVec : strVec
{
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();

NOCOPY(Glob)
};
#endif // _H
37 changes: 37 additions & 0 deletions include/SOM/GlobProcessors.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once
#ifndef GLOBPROCESSORS_H
#define GLOBPROCESSORS_H

#include "Glob.h"
#include <SOM/BaseTypes.h>
#include <SOM/coding.h>

#include <regex>

class GlobTrace : public I_GlobProcessor
{
public:
void process(const std::string& fpath) override;
};

class GlobXargs : public I_GlobProcessor
{
public:
GlobXargs(CONST_C_STRING cmd, CONST_C_STRING placeholder=nullptr);
void process(const std::string& fpath) override;
private:
const std::string cmd;
const std::regex re;
NODEF(GlobXargs)
NOCOPY(GlobXargs)
};

class GlobArgs : public I_GlobProcessor
{
public:
GlobArgs();
~GlobArgs();
void process(const std::string& fpath) override;
};

#endif // _H
6 changes: 2 additions & 4 deletions include/SOM/docopts.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ class DocOpts
{
public:
inline DocOpts() = default;
inline ~DocOpts() { rmArgs(); }
bool process(CONST_C_STRING help, INT32 argc, const CONST_C_STRING* argv, INT32 start = 1);
bool getValue(CONST_C_STRING& value, CHAR key) const;
inline bool isSet(CHAR key) const
{
return mSwitches.find(key) != mSwitches.end();
}
void reset();
CONST_C_STRING* args() const { return mArgs; }
const CONST_C_STRING* args() const { return mArgs; }
INT32 argc() const { return mArgc; }
void toShell() const;
const std::set<CHAR>& activeSwitches() const { return mSwitches; }
Expand All @@ -28,9 +27,8 @@ class DocOpts
std::set<CHAR>mValueKeys;
std::set<CHAR>mSwitchKeys;
bool mOk = false;
CONST_C_STRING* mArgs = nullptr;
const CONST_C_STRING* mArgs = nullptr;
INT32 mArgc = 0;
void rmArgs();

NOCOPY(DocOpts)
};
Expand Down
9 changes: 5 additions & 4 deletions include/SOM/fglob.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,21 @@
#define FGLOB_H

#include <SOM/BaseTypes.h>
#include <string>

class I_FglobProcessor
{
public:
virtual void process(CONST_C_STRING fpath) = 0;
virtual void process(const std::string& fpath) = 0;
};

//! glob files
//! @param item file, or directory with file glob pattern
//! @param proc I_FglobProcessor
//! @param proc I_GlobProcessor
#ifdef _WIN32
void fglob(CONST_C_STRING item, I_FglobProcessor& proc);
void fglob(const std::string& item, I_FglobProcessor& proc);
#else
inline void fglob(CONST_C_STRING item, I_FglobProcessor& proc)
inline void fglob(const std::string& item, I_FglobProcessor& proc)
{
proc.process(item);
}
Expand Down
31 changes: 21 additions & 10 deletions make/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,26 @@ endif
ifeq ($(config),ci)
docopts_config = ci
fglob_config = ci
lib_config = ci
glob_config = ci
somcpp_config = ci

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

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

else
$(error "invalid configuration $(config)")
endif

PROJECTS := docopts fglob lib
PROJECTS := docopts fglob glob somcpp

.PHONY: all clean help $(PROJECTS)

Expand All @@ -45,16 +48,23 @@ ifneq (,$(fglob_config))
@${MAKE} --no-print-directory -C . -f fglob.make config=$(fglob_config)
endif

lib:
ifneq (,$(lib_config))
@echo "==== Building lib ($(lib_config)) ===="
@${MAKE} --no-print-directory -C . -f lib.make config=$(lib_config)
glob:
ifneq (,$(glob_config))
@echo "==== Building glob ($(glob_config)) ===="
@${MAKE} --no-print-directory -C . -f glob.make config=$(glob_config)
endif

somcpp:
ifneq (,$(somcpp_config))
@echo "==== Building somcpp ($(somcpp_config)) ===="
@${MAKE} --no-print-directory -C . -f somcpp.make config=$(somcpp_config)
endif

clean:
@${MAKE} --no-print-directory -C . -f docopts.make clean
@${MAKE} --no-print-directory -C . -f fglob.make clean
@${MAKE} --no-print-directory -C . -f lib.make clean
@${MAKE} --no-print-directory -C . -f glob.make clean
@${MAKE} --no-print-directory -C . -f somcpp.make clean

help:
@echo "Usage: make [config=name] [target]"
Expand All @@ -69,6 +79,7 @@ help:
@echo " clean"
@echo " docopts"
@echo " fglob"
@echo " lib"
@echo " glob"
@echo " somcpp"
@echo ""
@echo "For more information, see https://github.com/premake/premake-core/wiki"
6 changes: 3 additions & 3 deletions make/docopts.make
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ define POSTBUILDCMDS
endef

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

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

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

endif
Expand Down
6 changes: 3 additions & 3 deletions make/fglob.make
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ define POSTBUILDCMDS
endef

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

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

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

endif
Expand Down
Loading

0 comments on commit 296bb96

Please sign in to comment.