]> Nishi Git Mirror - dataworks.git/commitdiff
add atof
authornishi <nishi@d4a5a174-5a4a-5b4b-b672-37683c10d7d5>
Wed, 29 May 2024 05:48:36 +0000 (05:48 +0000)
committernishi <nishi@d4a5a174-5a4a-5b4b-b672-37683c10d7d5>
Wed, 29 May 2024 05:48:36 +0000 (05:48 +0000)
git-svn-id: file:///raid/svn-main/nishi-dataworks/trunk@135 d4a5a174-5a4a-5b4b-b672-37683c10d7d5

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

index a0dfbce35448379fa57e99df0d785487017e3238..b330acd5aee690b1dfc2dffe6e6df19d6afeafe7 100644 (file)
@@ -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());
index 12c7b870408367fc62c0ab0db5474cc14a7c3d22..def7b610a51aca68edc3292b3b87b42cd175d683 100644 (file)
@@ -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
index dade3b6c6e67fc308288d8616ea0e4ebbc4e4e2c..736c19d1800f9af56c1133d6f5b896f58d1c4af2 100644 (file)
@@ -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)
index 849570fa5daf5b7782fbe105bbe6083fc3bfdf54..1ef6b46e7aa9949207fc0935554cc93acdcf0b8e 100644 (file)
@@ -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;
+}