diff --git a/include/fetcher.hpp b/include/fetcher.hpp index 71750134..acb9c3e1 100644 --- a/include/fetcher.hpp +++ b/include/fetcher.hpp @@ -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. diff --git a/include/utils/paths.hpp b/include/utils/paths.hpp index 9274862b..f8cba564 100644 --- a/include/utils/paths.hpp +++ b/include/utils/paths.hpp @@ -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 #include #include #include @@ -21,12 +21,31 @@ namespace vs{ #define rprefix(b) if(strncmp((src),rpath_type_t::as_string(b),std::char_traits::length(rpath_type_t::as_string(b)))==0){type=b;location=src+std::char_traits::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 boolean true if a file, false if a file inside the folder. + */ +std::pair next_component_attempt(std::pair); + 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[] = { diff --git a/src/fetcher.cpp b/src/fetcher.cpp index e8d933be..a59732cd 100644 --- a/src/fetcher.cpp +++ b/src/fetcher.cpp @@ -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 fetch_component(){ //TODO: diff --git a/src/globals.cpp b/src/globals.cpp index c7cb8445..067c4aab 100644 --- a/src/globals.cpp +++ b/src/globals.cpp @@ -1,7 +1,6 @@ #include #include #include -#include namespace vs{ namespace singleton{ diff --git a/src/utils/paths.cpp b/src/utils/paths.cpp index 2c2f9a21..4f6671fe 100644 --- a/src/utils/paths.cpp +++ b/src/utils/paths.cpp @@ -2,6 +2,67 @@ namespace vs{ +std::pair next_component_attempt(std::pair current){ + /*static constexpr std::pair 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