diff --git a/line-count b/line-count
index f0976f7..2f564cd 100644
--- a/line-count
+++ b/line-count
@@ -1,8 +1,8 @@
===============================================================================
Language Files Lines Code Comments Blanks
===============================================================================
- C++ 4 368 293 26 49
- C++ Header 4 71 56 6 9
+ C++ 4 320 253 20 47
+ C++ Header 4 67 54 5 8
===============================================================================
- Total 8 439 349 32 58
+ Total 8 387 307 25 55
===============================================================================
diff --git a/src/Regex.cpp b/src/Regex.cpp
index 1fa886c..9f632fd 100644
--- a/src/Regex.cpp
+++ b/src/Regex.cpp
@@ -8,23 +8,14 @@
// regex and stuff (collectionid)
void Regex(cmd *inputCmd) {
if (!inputCmd->collectionid.empty()) {
- // Input and output file paths
- std::string inputFilePath = inputCmd->cachesc; // Path to the input file
-
- // Open the input file
- std::ifstream inputFile(inputFilePath);
-
- // Check if the input file is open
- if (!inputFile.is_open()) {
- throw std::runtime_error("Unable to open file: " + inputFilePath);
- }
+ std::istringstream inputStream(inputCmd->source);
// Regex to search for the desired pattern
std::regex grepRegex(R"(
ids += "+quit\n";
-
- // Store the output back in the cmd structure (or handle it as needed)
- // inputCmd->ids = outputBuffer.str(); // Store output in cacheid
-
- // Close the input file
- inputFile.close();
-
- // Optionally print the output for verification
- // std::cout << inputCmd->ids; // Print output buffer content
}
}
diff --git a/src/getHttp.cpp b/src/getHttp.cpp
index 067f0d5..e7295ec 100644
--- a/src/getHttp.cpp
+++ b/src/getHttp.cpp
@@ -1,6 +1,6 @@
#include
#include
-#include
+#include "includes/Regex.hpp"
size_t appendCurlOutputToString(void *ptr, size_t size, size_t nmemb, std::string *woof) {
// append the output from curl to a string
@@ -8,35 +8,22 @@ size_t appendCurlOutputToString(void *ptr, size_t size, size_t nmemb, std::strin
return size * nmemb;
}
-void writeHtmlFile(std::string *woof, std::string *outputfile) {
- // check for nullptrs
- if (!woof || !outputfile) {
- throw("string is null\n");
- }
- // open file and write to it
- std::ofstream meow{*outputfile};
- meow << *woof;
-}
-
-void getHttp(std::string url, std::string *outputfile) {
+void getHttp(cmd *inputCmd, std::string url) {
// initialize curl object and curlcode
CURL *meow = curl_easy_init();
CURLcode res;
std::string woof;
- // check for nullptr and if nullptr throw an exception
- if (!outputfile) {
- curl_easy_cleanup(meow);
- throw("outputfile is null\n");
- }
+
// set the options
curl_easy_setopt(meow, CURLOPT_URL, url.c_str());
curl_easy_setopt(meow, CURLOPT_WRITEFUNCTION, appendCurlOutputToString);
curl_easy_setopt(meow, CURLOPT_WRITEDATA, &woof);
+
// perform the request
- res = curl_easy_perform(meow);
- if (res != CURLE_OK) {
+ if (curl_easy_perform(meow) != CURLE_OK) {
throw("failed to perform the request\n");
}
- writeHtmlFile(&woof, outputfile);
+
+ inputCmd->source = woof;
curl_easy_cleanup(meow);
}
diff --git a/src/includes/Regex.hpp b/src/includes/Regex.hpp
index b209ed4..ed2fc45 100644
--- a/src/includes/Regex.hpp
+++ b/src/includes/Regex.hpp
@@ -4,14 +4,9 @@
// all the var's
struct cmd {
-// legacy
-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";
-
-// unsure
+// buffers
std::string ids;
+std::string source;
// what the args need
std::string collectionid;
diff --git a/src/includes/getHttp.hpp b/src/includes/getHttp.hpp
index c1f645d..33b139d 100644
--- a/src/includes/getHttp.hpp
+++ b/src/includes/getHttp.hpp
@@ -1,5 +1,6 @@
#ifndef GETHTTP_H
#define GETHTTP_H
#include
-void getHttp(std::string url, std::string *outputfile);
+#include "Regex.hpp"
+void getHttp(cmd *inputCmd, std::string url);
#endif
diff --git a/src/main.cpp b/src/main.cpp
index 195003a..9da28cd 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,38 +1,20 @@
#include
-#include
#include
#include
#include
#include
-#include
#include
-#include
#include
+#include
#include "includes/getHttp.hpp"
#include "includes/Strings.hpp"
#include "includes/Regex.hpp"
#include "includes/maincommand.hpp"
-std::string woof(std::ifstream &meow) {
- std::ostringstream nya;
- nya << meow.rdbuf();
- return nya.str();
-}
-
int main(int argc, char **argv, char **envp) {
// struct cmd
cmd inputCmd;
-
inputCmd.dir = std::filesystem::current_path();
- // Removes cache
- if (std::filesystem::exists(inputCmd.cacheid) &&
- std::filesystem::is_directory(inputCmd.cacheid)) {
- std::filesystem::remove(inputCmd.cacheid);
- std::filesystem::remove(inputCmd.cachesc);
- } else {
- std::filesystem::remove(inputCmd.cacheid);
- std::filesystem::remove(inputCmd.cachesc);
- }
std::vector ARGS{argv, argv + argc};
for (int i = 0; i < argc; ++i) {
@@ -78,7 +60,7 @@ int main(int argc, char **argv, char **envp) {
inputCmd.ab = 0;
try {
- getHttp(std::string{"https://steamcommunity.com/sharedfiles/filedetails/?id=" + inputCmd.collectionid}, &inputCmd.cachesc);
+ getHttp(&inputCmd, std::string{"https://steamcommunity.com/sharedfiles/filedetails/?id=" + inputCmd.collectionid});
} catch (std::string &meow) {
std::cout << meow;
return 1;
@@ -98,7 +80,7 @@ int main(int argc, char **argv, char **envp) {
inputCmd.ab = 0;
try {
- getHttp(std::string{"https://steamcommunity.com/sharedfiles/filedetails/?id=" + inputCmd.collectionid}, &inputCmd.cachesc);
+ getHttp(&inputCmd, std::string{"https://steamcommunity.com/sharedfiles/filedetails/?id=" + inputCmd.collectionid});
} catch (std::string &meow) {
std::cout << meow;
return 1;
@@ -158,6 +140,7 @@ int main(int argc, char **argv, char **envp) {
}
}
+ // main functions
Regex(&inputCmd);
slashing(&inputCmd);
maincommand(&inputCmd);
diff --git a/src/maincommand.cpp b/src/maincommand.cpp
index a8bf8e5..0bbab25 100644
--- a/src/maincommand.cpp
+++ b/src/maincommand.cpp
@@ -70,7 +70,7 @@ void maincommand(cmd *inputCmd) {
running = false;
cursorThread.join();
} catch (const std::runtime_error& e) {
- std::cerr << "\nError: " << e.what() << std::endl;
+ std::cerr << "\nError: " << e.what() << "\n";
}
// mod or collection?