Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions samples/distro-examples/tests/all.bas
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions samples/distro-examples/tests/output/all.out
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 7 additions & 1 deletion src/common/blib_db.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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';
}
}

/*
Expand Down
38 changes: 13 additions & 25 deletions src/common/blib_func.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,24 @@ 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) {
nx = l;
} else if (nx > h) {
nx = h;
}

return nx;
}

Expand Down Expand Up @@ -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:
Expand Down
5 changes: 0 additions & 5 deletions src/common/brun.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
7 changes: 0 additions & 7 deletions src/common/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
3 changes: 2 additions & 1 deletion src/common/sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/include/var.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down