From 5b10cc103857ddfd40029abbc838f6720de09a48 Mon Sep 17 00:00:00 2001 From: Joseph Aquino Date: Fri, 26 Dec 2025 02:13:48 -0500 Subject: [PATCH] finished windows support --- CMakeLists.txt | 20 ++++++++++---------- build.bat | 2 +- include/shellUtils.h | 2 +- src/main.cpp | 8 +++++--- src/shellUtils.cpp | 9 ++++----- 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c8aad85..7fef876 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,19 +1,19 @@ cmake_minimum_required(VERSION 3.10) project(shell) - - -if(CMAKE_SYSTEM_NAME STREQUAL "Windows") - set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/windows) - set_property(GLOBAL PROPERTY USE_FOLDERS ON) -elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") - set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/linux) -endif() - set(CMAKE_CXX_STANDARD 23) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin) + add_executable(shell src/main.cpp src/shellUtils.cpp include/shellUtils.h) -target_include_directories(shell PRIVATE include) \ No newline at end of file +target_include_directories(shell PRIVATE include) + +if(CMAKE_SYSTEM_NAME STREQUAL "Windows") + set_property(GLOBAL PROPERTY USE_FOLDERS ON) + set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT shell) +elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") + +endif() diff --git a/build.bat b/build.bat index c664eef..6be6e5e 100644 --- a/build.bat +++ b/build.bat @@ -1,5 +1,5 @@ mkdir build cd build cmake -S .. -B . -cmake --build . +cmake --build . --config Release PAUSE \ No newline at end of file diff --git a/include/shellUtils.h b/include/shellUtils.h index 86d2a5c..d510d84 100644 --- a/include/shellUtils.h +++ b/include/shellUtils.h @@ -25,7 +25,7 @@ namespace sh Command getCommand(std::string_view input); - std::optional isExec(const std::string& input); + std::optional isExec(const std::string& input); void printType(const std::string& input); } \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 565c862..db6976e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,6 +6,8 @@ #include "shellUtils.h" +#define WIN_EXEC .append(".exe") + int main() { std::cout << std::unitbuf; @@ -17,7 +19,7 @@ int main() std::string input; std::cout << "$ "; std::getline(std::cin, input); - std::optional result; + std::optional result; switch (sh::Command command = sh::getCommand(input)) { case sh::Command::exit: @@ -27,7 +29,7 @@ int main() std::cout << input.substr(5) << "\n"; break; case sh::Command::unknown: - result = sh::isExec(input.substr(0, input.find(' '))); + result = sh::isExec(input.substr(0, input.find(' '))WIN_EXEC); if (result) { std::system(input.c_str()); @@ -38,7 +40,7 @@ int main() } break; case sh::Command::type: - sh::printType(input.substr(5)); + sh::printType(input.substr(5)WIN_EXEC); break; } } diff --git a/src/shellUtils.cpp b/src/shellUtils.cpp index 6935408..5a698b7 100644 --- a/src/shellUtils.cpp +++ b/src/shellUtils.cpp @@ -21,7 +21,7 @@ namespace sh } } - std::optional isExec(const std::string& input) + std::optional isExec(const std::string& input) { const std::string_view pathEnv {std::getenv("PATH")}; @@ -34,10 +34,9 @@ namespace sh size_t nextDelimIndex{pathEnv.find(delimiter)}; while (nextDelimIndex != std::string::npos) { - std::string currentPath {pathEnv.substr(startCharIndex, nextDelimIndex - startCharIndex)}; - std::string fullPath; - fullPath.append(currentPath).append("/").append(input); - + std::filesystem::path currentPath {pathEnv.substr(startCharIndex, nextDelimIndex - startCharIndex)}; + std::filesystem::path fullPath; + fullPath = currentPath / input; namespace fs = std::filesystem; if (!fs::exists(fullPath))