From e5de5fcb3f2565cc20acd77f3c209568d1463b04 Mon Sep 17 00:00:00 2001 From: Joerg Siebenmorgen Date: Fri, 6 Jan 2023 22:14:34 +0100 Subject: [PATCH 1/3] RGB and RGBF clamp parameters --- samples/distro-examples/tests/all.bas | 4 +-- samples/distro-examples/tests/output/all.out | 4 +-- src/common/blib_func.c | 38 +++++++------------- 3 files changed, 17 insertions(+), 29 deletions(-) diff --git a/samples/distro-examples/tests/all.bas b/samples/distro-examples/tests/all.bas index 203931c0..8af5ebe1 100644 --- a/samples/distro-examples/tests/all.bas +++ b/samples/distro-examples/tests/all.bas @@ -191,8 +191,8 @@ print "PTDISTSEG:" + PTDISTSEG (Bx,By,Cx,Cy,Ax,Ay) print "PTSIGN:" + PTSIGN (Ax,Ay,Bx,By,Qx,Qy) print "RAD:" + RAD (x) print "REPLACE:" + REPLACE ("source", 1, "sorce", 2) -print "RGB:" + RGB (80,80,80) -print "RGBF:" + RGBF (.1,.1,.1) +print "RGB:" + RGB (80,90,100) + " " + RGB (-100, 0, 300) +print "RGBF:" + RGBF (.1,.2,.3) + " " + RGBF (-1, 0, 3) print "RIGHT:" + RIGHT (s,2) print "RIGHTOF:" + RIGHTOF (s1, s2) print "RIGHTOFLAST:" + RIGHTOFLAST (s1, s2) diff --git a/samples/distro-examples/tests/output/all.out b/samples/distro-examples/tests/output/all.out index f6f13563..30ed6627 100644 --- a/samples/distro-examples/tests/output/all.out +++ b/samples/distro-examples/tests/output/all.out @@ -174,8 +174,8 @@ PTDISTSEG:0 PTSIGN:0 RAD:0.2146754979953 REPLACE:sorceurce -RGB:-5263440 -RGBF:-1710618 +RGB:-5266020 -255 +RGBF:-1717069 -255 RIGHT:gs RIGHTOF: RIGHTOFLAST: diff --git a/src/common/blib_func.c b/src/common/blib_func.c index 4a30511a..8466186d 100644 --- a/src/common/blib_func.c +++ b/src/common/blib_func.c @@ -34,14 +34,16 @@ static char *date_mN_table[] = TABLE_MONTH_FULL; #define BIN_LEN 32 // Number of max bits (digits) kwBIN creates /* + * Clamp floating point number and convert to integer + * x: number, l: lower bound, h: upper bound */ var_int_t r2int(var_num_t x, var_int_t l, var_int_t h) { var_int_t nx; - + if (x < 0.0) { - nx = (var_int_t) -floor(-x + .5); + nx = (var_int_t) (x - .5); } else { - nx = (var_int_t) floor(x + .5); + nx = (var_int_t) (x + .5); } if (nx < l) { @@ -49,6 +51,7 @@ var_int_t r2int(var_num_t x, var_int_t l, var_int_t h) { } else if (nx > h) { nx = h; } + return nx; } @@ -1935,37 +1938,22 @@ void cmd_intN(long funcCode, var_t *r) { // i <- RGB(r,g,b) // i <- RGBF(r,g,b) case kwRGB: - case kwRGBF: { + case kwRGBF: var_num_t rc, gc, bc; - int code; par_massget("FFF", &rc, &gc, &bc); IF_ERR_RETURN; - code = 0; - if (funcCode == kwRGBF) { - if ((rc >= 0 && rc <= 1) && (gc >= 0 && gc <= 1) && (bc >= 0 && bc <= 1)) { - code = 1; - } - } else { - if ((rc >= 0 && rc <= 255) && (gc >= 0 && gc <= 255) && (bc >= 0 && bc <= 255)) { - code = 2; - } - } - switch (code) { - case 1: - r->v.i = (r2int(rc * 255.0, 0, 255) << 16) | (r2int(gc * 255.0, 0, 255) << 8) - | r2int(bc * 255.0, 0, 255); + switch (funcCode) { + case kwRGB: + r->v.i = (r2int(rc, 0, 255) << 16) | (r2int(gc, 0, 255) << 8) | r2int(bc, 0, 255); break; - case 2: - r->v.i = ((uint32_t) rc << 16) | ((uint32_t) gc << 8) | (uint32_t) bc; + case kwRGBF: + r->v.i = (r2int(rc * 255.0, 0, 255) << 16) | (r2int(gc * 255.0, 0, 255) << 8) | r2int(bc * 255.0, 0, 255); break; - default: - err_argerr(); } - + r->v.i = -r->v.i; - } break; default: From 2c14c1b89493cb188ba8edc348c16a13f89ef459 Mon Sep 17 00:00:00 2001 From: Joerg Siebenmorgen Date: Fri, 20 Jan 2023 19:52:03 +0100 Subject: [PATCH 2/3] Bugfix DIM lower bound --- src/include/var.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/include/var.h b/src/include/var.h index f5c09282..ac08b566 100644 --- a/src/include/var.h +++ b/src/include/var.h @@ -99,7 +99,7 @@ typedef struct var_s { uint32_t capacity; // upper and lower bounds int32_t ubound[MAXDIM]; - int8_t lbound[MAXDIM]; + int32_t lbound[MAXDIM]; // number of dimensions uint8_t maxdim; } a; From 6a1e00d08273db93bb02725e35e136306e778d54 Mon Sep 17 00:00:00 2001 From: Joerg Siebenmorgen Date: Sun, 22 Jan 2023 21:42:38 +0100 Subject: [PATCH 3/3] Bugfix for DIRWALK shows inconsistend path separator in Windows --- src/common/blib_db.c | 8 +++++++- src/common/brun.c | 5 ----- src/common/file.c | 7 ------- src/common/sys.h | 3 ++- 4 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/common/blib_db.c b/src/common/blib_db.c index 8c4bc2c1..f88e43ee 100644 --- a/src/common/blib_db.c +++ b/src/common/blib_db.c @@ -781,7 +781,8 @@ void join_path(char *path, char *ext) { int len = strlen(path); if (path[len - 1] != OS_DIRSEP) { if (ext[0] != OS_DIRSEP) { - strcat(path, "/"); + char ch[] = {OS_DIRSEP, '\0'}; + strcat(path, ch); strcat(path, ext); } else { strcat(path, ext); @@ -793,6 +794,11 @@ void join_path(char *path, char *ext) { strcat(path, ext + 1); } } + // don't end with trailing slash + len = strlen(path); + if (path[len - 1] == OS_DIRSEP) { + path[len - 1] = '\0'; + } } /* diff --git a/src/common/brun.c b/src/common/brun.c index 3dd9f289..bff50f16 100644 --- a/src/common/brun.c +++ b/src/common/brun.c @@ -287,11 +287,6 @@ void exec_setup_predefined_variables() { *p = '\0'; } } - for (char *p = homedir; *p; p++) { - if (*p == '\\') { - *p = '/'; - } - } #elif defined(_UnixOS) if (getenv("HOME")) { strlcpy(homedir, getenv("HOME"), sizeof(homedir)); diff --git a/src/common/file.c b/src/common/file.c index 175d3a0b..e9b5bdaa 100644 --- a/src/common/file.c +++ b/src/common/file.c @@ -674,13 +674,6 @@ char *dev_getcwd() { retbuf[l] = OS_DIRSEP; retbuf[l + 1] = '\0'; } -#if defined(_Win32) - for (int i = 0; i < l; i++) { - if (retbuf[i] == '\\') { - retbuf[i] = OS_DIRSEP; - } - } -#endif return retbuf; } diff --git a/src/common/sys.h b/src/common/sys.h index b3ab8d6a..08e751ae 100644 --- a/src/common/sys.h +++ b/src/common/sys.h @@ -50,14 +50,15 @@ extern "C" { #define OS_PATHNAME_SIZE 1024 #define OS_FILENAME_SIZE 256 #define OS_FILEHANDLES 256 -#define OS_DIRSEP '/' #if defined(_Win32) #define SB_VERSYS "Win" #define OS_LINESEPARATOR "\r\n" + #define OS_DIRSEP '\\' #else #define SB_VERSYS "Unix" #define OS_LINESEPARATOR "\n" + #define OS_DIRSEP '/' #endif #define STRLEN(s) ((sizeof(s) / sizeof(s[0])) - 1)