From 9e4bec6b79158f4ebb2ea6bd13f0002606640da7 Mon Sep 17 00:00:00 2001 From: DRAGONTOS Date: Sat, 19 Oct 2024 02:43:34 +0200 Subject: [PATCH] regex: moved it to a seperate file --- line-count | 6 +-- src/includes/{getHttp.h => getHttp.hpp} | 1 - src/includes/regex.hpp | 6 +++ src/main.cpp | 67 +++---------------------- src/regex.cpp | 65 ++++++++++++++++++++++++ 5 files changed, 82 insertions(+), 63 deletions(-) rename src/includes/{getHttp.h => getHttp.hpp} (99%) create mode 100644 src/includes/regex.hpp create mode 100644 src/regex.cpp diff --git a/line-count b/line-count index af5c8ed..f3118d6 100644 --- a/line-count +++ b/line-count @@ -1,8 +1,8 @@ =============================================================================== Language Files Lines Code Comments Blanks =============================================================================== - C Header 1 6 5 0 1 - C++ 2 289 217 24 48 + C++ 3 313 236 25 52 + C++ Header 3 33 30 0 3 =============================================================================== - Total 3 295 222 24 49 + Total 6 346 266 25 55 =============================================================================== diff --git a/src/includes/getHttp.h b/src/includes/getHttp.hpp similarity index 99% rename from src/includes/getHttp.h rename to src/includes/getHttp.hpp index 41b876f..c1f645d 100644 --- a/src/includes/getHttp.h +++ b/src/includes/getHttp.hpp @@ -3,4 +3,3 @@ #include void getHttp(std::string url, std::string *outputfile); #endif - diff --git a/src/includes/regex.hpp b/src/includes/regex.hpp new file mode 100644 index 0000000..44f7414 --- /dev/null +++ b/src/includes/regex.hpp @@ -0,0 +1,6 @@ +#ifndef REGEX_H +#define REGEX_H +#include + +void regex(std::string collectionid, std::string gameid, std::string cacheid, std::string cachesc); +#endif diff --git a/src/main.cpp b/src/main.cpp index 611eed1..d298483 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,9 +9,9 @@ #include #include #include -#include "includes/getHttp.h" +#include "includes/getHttp.hpp" #include "includes/Strings.hpp" -#include "regex" +#include "includes/regex.hpp" std::string woof(std::ifstream &meow) { std::ostringstream nya; @@ -24,9 +24,9 @@ int main(int argc, char **argv, char **envp) { // need some cleaning in the future ata const char *userHome = getenv("HOME"); - std::string userCache = std::string(userHome) + "/.cache/"; - std::string cacheid = std::string(userCache) + "ids.txt"; - std::string cachesc = std::string(userCache) + "sources.html"; + std::string usercache = std::string(userHome) + "/.cache/"; + std::string cacheid = std::string(usercache) + "ids.txt"; + std::string cachesc = std::string(usercache) + "sources.html"; std::string collectionid; std::string modid; @@ -177,59 +177,8 @@ int main(int argc, char **argv, char **envp) { } } - // regex and stuff (collectionid) - if (!collectionid.empty()) { - // Input and output file paths - std::string inputFilePath = cachesc; - std::string outputFilePath = cacheid; + regex({collectionid}, {gameid}, {cacheid}, {cachesc}); - // Open the input file (source.html) - std::ifstream inputFile(inputFilePath); - std::ofstream outputFile(outputFilePath, std::ios::app); - - if (!inputFile.is_open() && !outputFile.is_open()) { - std::cerr << "Unable to open file"; - return 1; - } - - std::regex grepRegex(R"(