From: nishi Date: Thu, 16 May 2024 15:30:57 +0000 (+0000) Subject: works X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=7650d445c8eabbd1ce189f497e074206e219346f;p=dataworks.git works git-svn-id: file:///raid/svn-main/nishi-dataworks/trunk@6 d4a5a174-5a4a-5b4b-b672-37683c10d7d5 --- diff --git a/Client/main.c b/Client/main.c index 1dd0591..316d38b 100644 --- a/Client/main.c +++ b/Client/main.c @@ -28,6 +28,79 @@ #include +#include #include +#include +#include -int main(int argc, char** argv) { printf("DataWorks %s\n", dataworks_get_version()); } +#ifdef __MINGW32__ +#include +HANDLE winstdout; +#endif + +int main(int argc, char** argv) { + int i; + bool noclear = false; + for(i = 1; i < argc; i++) { + if(argv[i][0] == '-') { + if(strcmp(argv[i], "--version") == 0 || strcmp(argv[i], "-V") == 0) { + printf("DataWorks version %s %s %s\n", dataworks_get_version(), dataworks_get_compile_date(), dataworks_get_platform()); + return 0; + } else if(strcmp(argv[i], "--noclear") == 0) { + noclear = true; + } else { + fprintf(stderr, "%s: %s: invalid option\n", argv[i]); + return 1; + } + } + } +#ifdef __MINGW32__ + winstdout = GetStdHandle(STD_OUTPUT_HANDLE); + DWORD mode = 0; + GetConsoleMode(winstdout, &mode); + const DWORD origmode = mode; + mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING; + SetConsoleMode(winstdout, mode); +#endif + if(!noclear) { + printf("\x1b[2J\x1b[1;1H"); + fflush(stdout); + } + printf("DataWorks version %s %s %s\n", dataworks_get_version(), dataworks_get_compile_date(), dataworks_get_platform()); + printf("\n"); + printf("Copyright (c) Nishi 2024\n"); + printf("All rights reserved.\n"); + printf("\n"); + printf("Type a command (.help) for the help\n"); + printf("\n"); + int len = 0; + char* buf = malloc(1); + buf[0] = 0; + char ch; + char prompt = '.'; + printf("%c ", prompt); + fflush(stdout); + while(1) { + if(fread(&ch, 1, 1, stdin) <= 0) break; + if(ch == '\n') { + printf("%c ", prompt); + fflush(stdout); + free(buf); + buf = malloc(1); + buf[0] = 0; + len = 0; + } else if(ch != '\r') { + char* newbuf = malloc(len + 2); + for(i = 0; i < len; i++) { + newbuf[i] = buf[i]; + } + newbuf[i] = ch; + newbuf[i + 1] = 0; + free(buf); + buf = newbuf; + len++; + } + } + free(buf); + printf("\n"); +} diff --git a/Library/dataworks.c b/Library/dataworks.c index e5f7584..eab3582 100644 --- a/Library/dataworks.c +++ b/Library/dataworks.c @@ -28,6 +28,19 @@ #include "dataworks.h" -const char* dataworks_version = DATAWORKS_VERSION; +const char* dataworks_version = "0.0.0"; +const char* dataworks_compile_date = __DATE__; + +#if defined(__MINGW32__) +const char* dataworks_platform = "Windows"; +#elif defined(__NetBSD__) +const char* dataworks_platform = "NetBSD"; +#elif defined(__linux__) +const char* dataworks_platform = "Linux"; +#else +const char* dataworks_platform = "Unknown"; +#endif const char* dataworks_get_version(void) { return dataworks_version; } +const char* dataworks_get_compile_date(void) { return dataworks_compile_date; } +const char* dataworks_get_platform(void) { return dataworks_platform; } diff --git a/Library/dataworks.h b/Library/dataworks.h index e2f9da9..4725a75 100644 --- a/Library/dataworks.h +++ b/Library/dataworks.h @@ -42,19 +42,27 @@ extern "C" { /** * @~english - * @brief Version of DataWorks - * @note Use dataworks_get_version. + * @brief Get the version of DataWorks + * @return Version of DataWorks * */ -#define DATAWORKS_VERSION "0.0.0" +const char* dataworks_get_version(void); /** * @~english - * @brief Get the version of DataWorks - * @return Version of DataWorks + * @brief Get the compilation date of DataWorks + * @return Compilation date of DataWorks * */ -const char* dataworks_get_version(void); +const char* dataworks_get_compile_date(void); + +/** + * @~english + * @brief Get the compilation platform of DataWorks + * @return Compilation platform of DataWorks + * + */ +const char* dataworks_get_platform(void); #ifdef __cplusplus }