]> Nishi Git Mirror - dataworks.git/commitdiff
fix
authornishi <nishi@d4a5a174-5a4a-5b4b-b672-37683c10d7d5>
Wed, 5 Jun 2024 02:51:26 +0000 (02:51 +0000)
committernishi <nishi@d4a5a174-5a4a-5b4b-b672-37683c10d7d5>
Wed, 5 Jun 2024 02:51:26 +0000 (02:51 +0000)
git-svn-id: file:///raid/svn-main/nishi-dataworks/trunk@151 d4a5a174-5a4a-5b4b-b672-37683c10d7d5

Client/client.c

index 1f5479f4e57a01a93b4afc1bd262fc2dc9c7d1af..3a02d8888748e6d835da2850b714c5dbf58bd0be 100644 (file)
 HANDLE winstdout;
 #endif
 
-#if defined(__WATCOMC__) || defined(__MINGW32__)
-#define LONGOPT_PREFIX "/"
-#define SHORTOPT_PREFIX "/"
-#define OPT_CHAR '/'
-#else
-#define LONGOPT_PREFIX "--"
-#define SHORTOPT_PREFIX "-"
-#define OPT_CHAR '-'
-#endif
-
 void padleft(int leftpad, const char* str) {
        char* spaces = malloc(leftpad - strlen(str) + 1);
        memset(spaces, ' ', leftpad - strlen(str));
@@ -64,6 +54,15 @@ void padleft(int leftpad, const char* str) {
        free(spaces);
 }
 
+bool option(const char* str, const char* shortopt, const char* longopt){
+       char* dos_shortopt = __dw_strcat("/", shortopt);
+       char* dos_longopt = __dw_strcat("/", longopt);
+       char* nix_shortopt = __dw_strcat("-", shortopt);
+       char* nix_longopt = __dw_strcat("--", longopt);
+       if(__dw_strcaseequ(str, dos_longopt) || __dw_strcaseequ(str, nix_longopt) || strcmp(str, dos_shortopt) == 0 || strcmp(str, nix_shortopt) == 0) return true;
+       return false;
+}
+
 int main(int argc, char** argv) {
 #ifdef __MINGW32__
        setlocale(LC_ALL, "");
@@ -76,22 +75,23 @@ int main(int argc, char** argv) {
        const char* fname = NULL;
        const char* fprog = NULL;
        for(i = 1; i < argc; i++) {
-               if(argv[i][0] == OPT_CHAR) {
-                       if(__dw_strcaseequ(argv[i], LONGOPT_PREFIX "version") || strcmp(argv[i], SHORTOPT_PREFIX "V") == 0) {
+               if(argv[i][0] == '-' || argv[i][0] == '/') {
+                       if(option(argv[i], "V", "version")) {
                                printf("DataWorks  version %s  %s %s\n", dataworks_get_version(), dataworks_get_compile_date(), dataworks_get_platform());
                                return 0;
-                       } else if(__dw_strcaseequ(argv[i], LONGOPT_PREFIX "create") || strcmp(argv[i], SHORTOPT_PREFIX "C") == 0) {
+                       } else if(option(argv[i], "C", "create")){
                                create = true;
-                       } else if(__dw_strcaseequ(argv[i], LONGOPT_PREFIX "noclear") || strcmp(argv[i], SHORTOPT_PREFIX "NC") == 0) {
+                       } else if(option(argv[i], "NC", "noclear")) {
                                clear = false;
-                       } else if(__dw_strcaseequ(argv[i], LONGOPT_PREFIX "quiet") || strcmp(argv[i], SHORTOPT_PREFIX "q") == 0) {
+                       } else if(option(argv[i], "q", "quiet")) {
                                banner = false;
                                log = false;
-                       } else if(__dw_strcaseequ(argv[i], LONGOPT_PREFIX "nobanner") || strcmp(argv[i], SHORTOPT_PREFIX "NB") == 0) {
+                               clear = false;
+                       } else if(option(argv[i], "NB", "nobanner")){
                                banner = false;
-                       } else if(__dw_strcaseequ(argv[i], LONGOPT_PREFIX "nolog") || strcmp(argv[i], SHORTOPT_PREFIX "NL") == 0) {
+                       } else if(option(argv[i], "NL", "nolog")) {
                                log = false;
-                       } else if(strcmp(argv[i], SHORTOPT_PREFIX "f") == 0) {
+                       } else if(option(argv[i], "f", "file")){
                                fprog = argv[i + 1];
                                i++;
                        } else {
@@ -261,7 +261,7 @@ int main(int argc, char** argv) {
                                                        line[i] = 0;
                                                        memcpy(line, linebuf, i);
 
-                                                       struct dataworks_db_result* r = dataworks_database_execute_code(db, line, true);
+                                                       struct dataworks_db_result* r = dataworks_database_execute_code(db, line, log);
                                                        if(r->error) {
                                                                printf("%s.\n", dataworks_database_strerror(r->errnum));
                                                        }