]> Nishi Git Mirror - dataworks.git/commitdiff
works
authornishi <nishi@d4a5a174-5a4a-5b4b-b672-37683c10d7d5>
Thu, 16 May 2024 15:30:57 +0000 (15:30 +0000)
committernishi <nishi@d4a5a174-5a4a-5b4b-b672-37683c10d7d5>
Thu, 16 May 2024 15:30:57 +0000 (15:30 +0000)
git-svn-id: file:///raid/svn-main/nishi-dataworks/trunk@6 d4a5a174-5a4a-5b4b-b672-37683c10d7d5

Client/main.c
Library/dataworks.c
Library/dataworks.h

index 1dd059153949b23c45af6239c63d6ce7a41e4bd3..316d38bdfdc180fa31d7e136e63601d6e7b3b93e 100644 (file)
 
 #include <dataworks.h>
 
+#include <stdbool.h>
 #include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 
-int main(int argc, char** argv) { printf("DataWorks %s\n", dataworks_get_version()); }
+#ifdef __MINGW32__
+#include <windows.h>
+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");
+}
index e5f7584973ce218b508a23fa7a887048f7cd414c..eab3582a16f3cfcc62437f6fed21d53beea65ee6 100644 (file)
 
 #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; }
index e2f9da9054df584184e533034c9431d12093e0c4..4725a7557963ca64552dc583a82066325e292308 100644 (file)
@@ -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
 }