From 0489092ac538610a3db7dee2e000bc63db11be67 Mon Sep 17 00:00:00 2001
From: Ferenc Szontágh <szf@fsociety.hu>
Date: Sat, 12 Apr 2025 18:07:50 +0000
Subject: [PATCH] rename the interpreter

---
 cli/main.cpp |   52 ++++++++++++++++++++++++----------------------------
 1 files changed, 24 insertions(+), 28 deletions(-)

diff --git a/cli/main.cpp b/cli/main.cpp
index 1e8a582..882134c 100644
--- a/cli/main.cpp
+++ b/cli/main.cpp
@@ -2,51 +2,47 @@
 #include <fstream>
 
 #include "Builtins/PrintModule.hpp"
-#include "SScriptInterpreter.hpp"
+#include "ScriptInterpreter.hpp"
 
 static bool DEBUG = false;
 
 int main(int argc, char * argv[]) {
-    SScriptInterpreter interp;
-    interp.registerFunction("print", std::make_shared<PrintFunction>());
-
-
     if (argc < 2) {
-        std::cerr << "Usage: " << argv[0] << " [-d / --debug] <script_file>" << std::endl;
-        return 1;
-    }
-    if (argc > 2) {
-        if (std::string(argv[1]) == "-d" || std::string(argv[1]) == "--debug") {
-            DEBUG = true;
-        } else {
-            std::cerr << "Usage: " << argv[0] << " [-d / --debug] <script_file>" << std::endl;
-            return 1;
-        }
-    }
-    if (argc > 3) {
-        std::cerr << "Error: Too many arguments." << std::endl;
+        std::cerr << "Usage: " << argv[0] << " [-d / --debug] <script_file>\n";
         return 1;
     }
 
-    if (!std::filesystem::exists(argv[2])) {
-        std::cerr << "Error: File " << argv[2] << " does not exist." << std::endl;
+    std::string file;
+    if (argc == 2) {
+        file = argv[1];
+    } else if (argc == 3 && (std::string(argv[1]) == "-d" || std::string(argv[1]) == "--debug")) {
+        DEBUG = true;
+        file  = argv[2];
+    } else {
+        std::cerr << "Usage: " << argv[0] << " [-d / --debug] <script_file>\n";
         return 1;
     }
-    // get the absolute path of the file
-    const std::string filename = std::filesystem::canonical(argv[2]).string();
+
+    if (!std::filesystem::exists(file)) {
+        std::cerr << "Error: File " << file << " does not exist.\n";
+        return 1;
+    }
+
+    const std::string filename = std::filesystem::canonical(file).string();
 
     try {
-        std::ifstream file(filename);
-        if (!file.is_open()) {
-            std::cerr << "Error: Could not open file " << filename << std::endl;
+        std::ifstream input(filename);
+        if (!input.is_open()) {
+            std::cerr << "Error: Could not open file " << filename << "\n";
             return 1;
         }
 
-        std::string content((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
-
+        std::string        content((std::istreambuf_iterator<char>(input)), std::istreambuf_iterator<char>());
+        ScriptInterpreter interp;
+        interp.registerFunction("print", std::make_shared<PrintFunction>());
         interp.executeScript(content, filename, DEBUG);
     } catch (const std::exception & e) {
-        std::cerr << "Parser error: " << e.what() << std::endl;
+        std::cerr << "Parser error: " << e.what() << "\n";
         return 1;
     }
 

--
Gitblit v1.9.3