From: nishi Date: Wed, 29 May 2024 05:48:36 +0000 (+0000) Subject: add atof X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=0654d2dabf595dc7a7aa503d016af8cb28885c32;p=dataworks.git add atof git-svn-id: file:///raid/svn-main/nishi-dataworks/trunk@135 d4a5a174-5a4a-5b4b-b672-37683c10d7d5 --- diff --git a/Client/main.c b/Client/main.c index a0dfbce..b330acd 100644 --- a/Client/main.c +++ b/Client/main.c @@ -130,7 +130,7 @@ int main(int argc, char** argv) { printf("This system is big-endian.\n"); } printf("\n"); - if(!dataworks_get_if_supported()){ + if(!dataworks_get_if_supported()) { printf("!!! THIS PLATFORM IS UNSUPPORTED! !!!\n\n"); } printf("%s\n", dataworks_get_copyright()); diff --git a/Library/dataworks.c b/Library/dataworks.c index 12c7b87..def7b61 100644 --- a/Library/dataworks.c +++ b/Library/dataworks.c @@ -62,7 +62,7 @@ char dataworks_get_endian(void) { } const char* dataworks_get_copyright(void) { return dataworks_copyright; } -bool dataworks_get_if_supported(void){ +bool dataworks_get_if_supported(void) { #ifdef SUPPORTED return true; #else diff --git a/Library/dw_util.h b/Library/dw_util.h index dade3b6..736c19d 100644 --- a/Library/dw_util.h +++ b/Library/dw_util.h @@ -51,6 +51,7 @@ char* __dw_strcat(const char* a, const char* b); bool __dw_strcaseequ(const char* a, const char* b); bool __dw_lockfile(struct dataworks_db* db); bool __dw_unlockfile(struct dataworks_db* db); +double __dw_atof(const char* str); #define __dw_xstr(x) #x #define __dw_str(x) __dw_xstr(x) diff --git a/Library/util.c b/Library/util.c index 849570f..1ef6b46 100644 --- a/Library/util.c +++ b/Library/util.c @@ -100,3 +100,24 @@ bool __dw_unlockfile(struct dataworks_db* db) { db->locked = false; return true; } + +double __dw_atof(const char* str) { + double num = 0; + bool pr = false; + int i; + double mul = 10; + for(i = 0; str[i] != 0; i++) { + if(str[i] >= '0' && str[i] <= '9') { + if(!pr) { + num *= 10; + num += str[i] - '0'; + } else { + num += (str[i] - '0') / mul; + mul *= 10; + } + } else if(str[i] == '.') { + pr = true; + } + } + return str[0] == '-' ? -num : num; +}