Skip to content

Commit

Permalink
Adding logic to search for alternative names of a component
Browse files Browse the repository at this point in the history
  • Loading branch information
karurochari committed Dec 15, 2024
1 parent 9485f28 commit c1290cb
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 52 deletions.
12 changes: 1 addition & 11 deletions include/fetcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,7 @@
namespace vs{


enum struct component_t{
NONE,
VS,
XML,
WASM,
LIB,
CNATIVE,
MARKDOWN,
};
component_t component_t_i(const char* t);
constexpr const char* component_t_s(component_t t);



//Fetch any resource from any path to memory.
Expand Down
29 changes: 24 additions & 5 deletions include/utils/paths.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
* @file paths.hpp
* @author karurochari
* @brief Utilities to handle virtual and real paths in a safe and portable way.
*
* @details This library DOES NOT fetch nor verify those files actually exists, but error codes are provided so that they can be used in cascade.
* The only checks performed are about policies, to ensure that path in that context was usable.
* @copyright Copyright (c) 2024
*
*/

#include <cstdint>
#include <cstring>
#include <string>
#include <utils/policies.hpp>
Expand All @@ -21,12 +21,31 @@ namespace vs{
#define rprefix(b) if(strncmp((src),rpath_type_t::as_string(b),std::char_traits<char>::length(rpath_type_t::as_string(b)))==0){type=b;location=src+std::char_traits<char>::length(rpath_type_t::as_string(b));}


enum struct component_t{
NONE,
VS,
XML,
WASM,
LIB,
CNATIVE,
MARKDOWN,
};
component_t component_t_i(const char* t);
constexpr const char* component_t_s(component_t t);

/**
* @brief In case of a file inclusion without extension, like `this://component`, this function tells which one to look for next.
*
* @return std::pair<bool,component_t> boolean true if a file, false if a file inside the folder.
*/
std::pair<bool,component_t> next_component_attempt(std::pair<bool,component_t>);

struct vpath_type_t{
enum t{
NONE,
THIS,FS,HTTP,HTTPS,GEMINI,TMP,DATA,REPO,APP,VS,CWD, //Real paths
SOCKET, //External endpoint
STORAGE,SESSION //Cache loopbacks
THIS,FS,HTTP,HTTPS,GEMINI,TMP,DATA,REPO,APP,VS,CWD, //Real paths
SOCKET, //External endpoint
STORAGE,SESSION //Cache loopbacks
};

static inline constexpr const char* prefixes[] = {
Expand Down
35 changes: 0 additions & 35 deletions src/fetcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,6 @@

namespace vs{

component_t component_t_i(const char* t){
if(false);
else if(strcmp(t,".vs")==1)return component_t::VS;
else if(strcmp(t,".xml")==1)return component_t::XML;
else if(strcmp(t,".wasm")==1)return component_t::WASM;
# if defined(__linux__)
else if(strcmp(t,".so")==1)return component_t::LIB;
# elif defined(_WIN32) || defined(_WIN64)
else if(strcmp(t,".dll")==1)return component_t::LIB;
# elif defined(__APPLE__)
else if(strcmp(t,".dylib")==1)return component_t::LIB;
# endif
else if(strcmp(t,".c")==1)return component_t::CNATIVE;
else if(strcmp(t,".md")==1)return component_t::MARKDOWN;
else return component_t::NONE;
}

constexpr const char* component_t_s(component_t t){
if(t==component_t::NONE)return nullptr;
else if(t==component_t::VS)return ".vs";
else if(t==component_t::XML)return ".xml";
else if(t==component_t::WASM)return ".wasm";
else if(t==component_t::LIB){
# if defined(__linux__)
return ".so";
# elif defined(_WIN32) || defined(_WIN64)
return ".dll";
# elif defined(__APPLE__)
return ".dylib";
# endif
}
else if(t==component_t::CNATIVE)return ".c";
else if(t==component_t::MARKDOWN)return ".md";
else return nullptr;
}

std::tuple<resolve_path::reason_t::t, cache::mem_storage_t::entry_it*, component_t> fetch_component(){
//TODO:
Expand Down
1 change: 0 additions & 1 deletion src/globals.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <cstdio>
#include <globals.hpp>
#include <cstdlib>
#include <chrono>

namespace vs{
namespace singleton{
Expand Down
61 changes: 61 additions & 0 deletions src/utils/paths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,67 @@

namespace vs{

std::pair<bool,component_t> next_component_attempt(std::pair<bool,component_t> current){
/*static constexpr std::pair<bool,component_t> next[] = {
{true, component_t::VS},
{true,component_t::XML},
{true,component_t::WASM},
{true,component_t::LIB},
{true,component_t::CNATIVE},
{false, component_t::VS},
{false,component_t::XML},
{false,component_t::WASM},
{false,component_t::LIB},
{false,component_t::CNATIVE},
{true,component_t::MARKDOWN},
{false,component_t::MARKDOWN},
{false,component_t::NONE},
};*/
if(current.second<component_t::CNATIVE)return {current.first,(component_t)((int)current.second+1)};
else if (current.first==true && current.second==component_t::CNATIVE)return {false,component_t::VS};
else if(current.first==false && current.second==component_t::CNATIVE)return {true,component_t::MARKDOWN};
else if (current.first==true && current.second==component_t::MARKDOWN)return {false,component_t::MARKDOWN};
else if(current.first==false && current.second==component_t::MARKDOWN)return {false,component_t::NONE};

return {false, component_t::NONE};
}

component_t component_t_i(const char* t){
if(false);
else if(strcmp(t,".vs")==1)return component_t::VS;
else if(strcmp(t,".xml")==1)return component_t::XML;
else if(strcmp(t,".wasm")==1)return component_t::WASM;
# if defined(__linux__)
else if(strcmp(t,".so")==1)return component_t::LIB;
# elif defined(_WIN32) || defined(_WIN64)
else if(strcmp(t,".dll")==1)return component_t::LIB;
# elif defined(__APPLE__)
else if(strcmp(t,".dylib")==1)return component_t::LIB;
# endif
else if(strcmp(t,".c")==1)return component_t::CNATIVE;
else if(strcmp(t,".md")==1)return component_t::MARKDOWN;
else return component_t::NONE;
}

constexpr const char* component_t_s(component_t t){
if(t==component_t::NONE)return nullptr;
else if(t==component_t::VS)return ".vs";
else if(t==component_t::XML)return ".xml";
else if(t==component_t::WASM)return ".wasm";
else if(t==component_t::LIB){
# if defined(__linux__)
return ".so";
# elif defined(_WIN32) || defined(_WIN64)
return ".dll";
# elif defined(__APPLE__)
return ".dylib";
# endif
}
else if(t==component_t::CNATIVE)return ".c";
else if(t==component_t::MARKDOWN)return ".md";
else return nullptr;
}

void scoped_vpath_t::from_string(const char* src){
vprefix(vpath_type_t::THIS)
else vprefix(vpath_type_t::DATA)
Expand Down

0 comments on commit c1290cb

Please sign in to comment.