From b119e2e741dc82bca93374df7c5e4cd4b6468bc1 Mon Sep 17 00:00:00 2001 From: Amlal Date: Tue, 18 Feb 2025 17:03:17 +0100 Subject: ADD: Refactor make_app command line to work with NeOS, like the open command. --- dev/Kernel/HALKit/AMD64/HalSystemCallInstall.cc | 1 - dev/LibSCI/Macros.h | 2 +- dev/LibSCI/SCI.h | 20 +++++++++ dev/Usr/LibCF/Array.h | 12 +++++- public/apps/.keepme | 0 public/tools/make_app/Common.h | 11 +---- public/tools/make_app/Steps.h | 10 ++--- public/tools/make_app/src/CommandLine.cc | 56 ++++++++++++------------- 8 files changed, 64 insertions(+), 48 deletions(-) create mode 100644 public/apps/.keepme diff --git a/dev/Kernel/HALKit/AMD64/HalSystemCallInstall.cc b/dev/Kernel/HALKit/AMD64/HalSystemCallInstall.cc index 3e360582..e4e9daab 100644 --- a/dev/Kernel/HALKit/AMD64/HalSystemCallInstall.cc +++ b/dev/Kernel/HALKit/AMD64/HalSystemCallInstall.cc @@ -5,4 +5,3 @@ ------------------------------------------- */ #include - diff --git a/dev/LibSCI/Macros.h b/dev/LibSCI/Macros.h index 3236176c..92461f3f 100644 --- a/dev/LibSCI/Macros.h +++ b/dev/LibSCI/Macros.h @@ -78,5 +78,5 @@ IMPORT_C void _rtl_assert(Bool expr, const Char* origin); #ifndef ARRAY_SIZE #define ARRAY_SIZE(a) \ (((sizeof(a) / sizeof(*(a))) / \ - (static_cast(!(sizeof(a) % sizeof(*(a))))))) + (static_cast(!(sizeof(a) % sizeof(*(a))))))) #endif \ No newline at end of file diff --git a/dev/LibSCI/SCI.h b/dev/LibSCI/SCI.h index 736c2d33..3b03bee2 100644 --- a/dev/LibSCI/SCI.h +++ b/dev/LibSCI/SCI.h @@ -329,4 +329,24 @@ IMPORT_C SInt32 VideoGetColorProfile(VoidPtr* in); IMPORT_C SInt32 VideoQueryInfo(VoidPtr* info_ptr, SizeT* info_sz); +IMPORT_C BOOL FsCopy(const char* path, const char* dst); +IMPORT_C BOOL FsMove(const char* path, const char* dst); + +IMPORT_C BOOL FsExists(const char* path); + +IMPORT_C BOOL FsCreateDir(const char* path); +IMPORT_C BOOL FsCreateFile(const char* path); +IMPORT_C BOOL FsCreateAlias(const char* path, const char* from); + +IMPORT_C Char* StrFmt(const Char* fmt, ...); + +IMPORT_C SInt32 MsgFree(VoidPtr handle); +IMPORT_C SInt32 MsgShow(VoidPtr handle); + +/// @note fmt could be any POSIX argument, or the extended ones (%$, %{}) +IMPORT_C SInt32 MsgSend(VoidPtr handle, const Char* fmt, ...); +IMPORT_C SInt32 MsgAlloc(VoidPtr handle); + +IMPORT_C VoidPtr kAlertMsg, kInfoMsg, kErrorMsg; + #endif // ifndef SCI_SCI_H diff --git a/dev/Usr/LibCF/Array.h b/dev/Usr/LibCF/Array.h index ed3e736b..c466b0fb 100644 --- a/dev/Usr/LibCF/Array.h +++ b/dev/Usr/LibCF/Array.h @@ -38,7 +38,15 @@ namespace LibCF const SizeT Count() { - return N; + auto cnt = 0UL; + + for (auto i = 0; i < N; ++i) + { + if (fArray[i]) + ++cnt; + } + + return cnt; } const T* CData() @@ -52,7 +60,7 @@ namespace LibCF } private: - T fArray[N]; + T fArray[N] = {nullptr}; }; template diff --git a/public/apps/.keepme b/public/apps/.keepme new file mode 100644 index 00000000..e69de29b diff --git a/public/tools/make_app/Common.h b/public/tools/make_app/Common.h index 7dead76c..2df215f3 100644 --- a/public/tools/make_app/Common.h +++ b/public/tools/make_app/Common.h @@ -6,14 +6,7 @@ #ifndef APPS_COMMON_H #define APPS_COMMON_H -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include #endif // APPS_COMMON_H diff --git a/public/tools/make_app/Steps.h b/public/tools/make_app/Steps.h index b742724d..29fd19aa 100644 --- a/public/tools/make_app/Steps.h +++ b/public/tools/make_app/Steps.h @@ -13,11 +13,11 @@ struct StepsCommonRecord final { - char setup_name[255]; - char setup_company[255]; - char setup_author[255]; - int32_t setup_version; - int32_t setup_pages; + char setup_name[255]; + char setup_company[255]; + char setup_author[255]; + SInt32 setup_version; + SInt32 setup_pages; }; #endif // ifndef APPS_STEPS_H \ No newline at end of file diff --git a/public/tools/make_app/src/CommandLine.cc b/public/tools/make_app/src/CommandLine.cc index 3339bfe3..1858303b 100644 --- a/public/tools/make_app/src/CommandLine.cc +++ b/public/tools/make_app/src/CommandLine.cc @@ -7,70 +7,66 @@ #include #include +#include + /// @brief This program makes a framework directory for NeKernel OS. int main(int argc, char* argv[]) { - std::vector files; + LibCF::CFArray files; auto ext = kFKExtension; - for (size_t i = 2UL; i < argc; ++i) + for (SizeT i = 2UL; i < argc; ++i) { - if (strcmp(argv[i], "-h") == 0) + if (MmStrCmp(argv[i], "-h") == 0) { - std::cout << "make_app: Framework/Application Creation Tool.\n"; - std::cout << "make_app: © Amlal EL Mahrouss, All rights reserved.\n"; + MsgAlloc(kAlertMsg); + + MsgSend(kAlertMsg, "%s", "make_app: Framework/Application Creation Tool.\n"); + MsgSend(kAlertMsg, "%s", "make_app: © Amlal EL Mahrouss, All rights reserved.\n"); + + MsgSend(kAlertMsg, "%s", "make_app: -a: Application format.\n"); + MsgSend(kAlertMsg, "%s", "make_app: -s: Steps (Setup pages) format.\n"); + MsgSend(kAlertMsg, "%s", "make_app: -f: Framework format.\n"); - std::cout << "make_app: -a: Application format.\n"; - std::cout << "make_app: -s: Steps (Setup pages) format.\n"; - std::cout << "make_app: -f: Framework format.\n"; + MsgShow(kAlertMsg); + MsgFree(kAlertMsg); return EXIT_SUCCESS; } - if (strcmp(argv[i], "-a") == 0) + if (MmStrCmp(argv[i], "-a") == 0) { ext = kAppExtension; continue; } - else if (strcmp(argv[i], "-s") == 0) + else if (MmStrCmp(argv[i], "-s") == 0) { ext = kStepsExtension; continue; } - else if (strcmp(argv[i], "-f") == 0) + else if (MmStrCmp(argv[i], "-f") == 0) { ext = kFKExtension; continue; } - files.push_back(argv[i]); + files[i] = argv[i]; } - auto path = std::string(argv[1]); + auto path = argv[1]; - if (!std::filesystem::exists(path)) - return EXIT_FAILURE; - - std::filesystem::path path_arg = path + ext; - - if (std::filesystem::create_directory(path_arg)) + if (FsCreateDir(path)) { - std::filesystem::create_directory(path_arg / kRootDirectory); - std::filesystem::create_directory(path_arg / kExecDirectory); + FsCreateDir(StrFmt("{}{}", path, kRootDirectory)); + FsCreateDir(StrFmt("{}{}", path, kExecDirectory)); - for (auto& file : files) + for (SInt32 i = 0; i < files.Count(); ++i) { - std::string file_cpy = file; - - while (file_cpy.find("/") != std::string::npos) - { - file_cpy.erase(0, file_cpy.find("/")); - file_cpy.erase(file_cpy.find("/"), 1); - } + auto& file = files[i]; - std::filesystem::copy(path, path_arg / kExecDirectory / file_cpy); + FsCopy(path, StrFmt("{}{}", path, file)); } return EXIT_SUCCESS; -- cgit v1.2.3