From 55abb4f6f81fc370e349385b38dffb05fa9d5dcb Mon Sep 17 00:00:00 2001
From: Ferenc Szontágh <szf@fsociety.hu>
Date: Sat, 19 Apr 2025 20:36:38 +0000
Subject: [PATCH] add vscodium / vscode and vim syntax highlight
---
cli/main.cpp | 28 ++++++++++++++++++++++------
1 files changed, 22 insertions(+), 6 deletions(-)
diff --git a/cli/main.cpp b/cli/main.cpp
index f0daa59..f7bbede 100644
--- a/cli/main.cpp
+++ b/cli/main.cpp
@@ -1,6 +1,7 @@
#include <filesystem>
#include <iostream>
#include <unordered_map>
+#include <unistd.h> // for isatty, STDIN_FILENO
#include "options.h"
#include "VoidScript.hpp"
@@ -17,6 +18,8 @@
for (const auto & [key, value] : params) {
usage.append(" [" + key + "]");
}
+ // [file] is optional; if omitted, script is read from stdin
+ usage.append(" [file]");
// Parse arguments: allow --help, --version, --debug[=component], and a single file
bool debugLexer = false;
bool debugParser = false;
@@ -61,6 +64,9 @@
std::cerr << usage << "\n";
return 1;
}
+ } else if (a == "-") {
+ // Read script from stdin
+ file = a;
} else if (a.starts_with("-")) {
std::cerr << "Error: Unknown option '" << a << "'\n";
std::cerr << usage << "\n";
@@ -74,17 +80,27 @@
}
}
if (file.empty()) {
- std::cerr << "Error: No input file specified\n";
+ // No input file specified: read script from stdin
+ file = "-";
+ }
+ // If reading from stdin but stdin is a tty (no piped input), show usage
+ if (file == "-" && isatty(STDIN_FILENO)) {
std::cerr << usage << "\n";
return 1;
}
- if (!std::filesystem::exists(file)) {
- std::cerr << "Error: File " << file << " does not exist.\n";
- return 1;
+ // Determine if reading from a file or stdin
+ std::string filename;
+ if (file == "-") {
+ // Read script from standard input
+ filename = file;
+ } else {
+ if (!std::filesystem::exists(file)) {
+ std::cerr << "Error: File " << file << " does not exist.\n";
+ return 1;
+ }
+ filename = std::filesystem::canonical(file).string();
}
-
- const std::string filename = std::filesystem::canonical(file).string();
// Initialize and run with debug options
VoidScript voidscript(filename, debugLexer, debugParser, debugInterp, debugSymbolTable);
--
Gitblit v1.9.3