From 1b2eed1baac66f50aa098394ee0f7d0260bf7d53 Mon Sep 17 00:00:00 2001 From: nishi Date: Sat, 18 May 2024 09:08:39 +0000 Subject: [PATCH] should work git-svn-id: file:///raid/svn-main/nishi-dataworks/trunk@23 d4a5a174-5a4a-5b4b-b672-37683c10d7d5 --- Client/main.c | 3 +++ Library/dw_util.h | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/Client/main.c b/Client/main.c index 582d893..afb662b 100644 --- a/Client/main.c +++ b/Client/main.c @@ -114,6 +114,9 @@ int main(int argc, char** argv) { printf("\n"); printf("Type a command (.help) for the help\n"); printf("\n"); + double val; + __dw_big_endian(123.3, double, val = __converted); + printf("%f\n", val); int len = 0; char* buf = malloc(1); buf[0] = 0; diff --git a/Library/dw_util.h b/Library/dw_util.h index 0b5d689..2c3dd14 100644 --- a/Library/dw_util.h +++ b/Library/dw_util.h @@ -42,8 +42,30 @@ extern "C" { #include +#include "dataworks.h" + bool __dw_strcaseequ(const char* a, const char* b); +#define __dw_xstr(x) #x +#define __dw_str(x) __dw_xstr(x) + +#define __dw_big_endian(arg, type, exec) { \ + type __original = arg; \ + signed char* __ptr = (signed char*)&__original; \ + type __converted; \ + signed char* __converted_ptr = (signed char*)&__converted; \ + int __i; \ + char __endian = dataworks_get_endian(); \ + for(__i = 0; __i < sizeof(type); __i++){ \ + if(__endian == 'L'){ \ + __converted_ptr[sizeof(type) - __i - 1] = __ptr[__i]; \ + }else{ \ + __converted_ptr[__i] = __ptr[__i]; \ + } \ + } \ + exec; \ +} + #ifdef __cplusplus } #endif -- 2.43.0