From a2c0b707c11f5f1b0130a0b432a8adea3dc88cfa Mon Sep 17 00:00:00 2001 From: nishi Date: Wed, 5 Jun 2024 02:51:26 +0000 Subject: [PATCH] fix git-svn-id: file:///raid/svn-main/nishi-dataworks/trunk@151 d4a5a174-5a4a-5b4b-b672-37683c10d7d5 --- Client/client.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/Client/client.c b/Client/client.c index 1f5479f..3a02d88 100644 --- a/Client/client.c +++ b/Client/client.c @@ -46,16 +46,6 @@ 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)); } -- 2.43.0