Skip to content

Commit df2e113

Browse files
authored
Merge branch 'smallbasic:master' into 12_26
2 parents 0cd6240 + dc61154 commit df2e113

File tree

8 files changed

+27
-44
lines changed

8 files changed

+27
-44
lines changed

samples/distro-examples/tests/all.bas

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ print "PTDISTSEG:" + PTDISTSEG (Bx,By,Cx,Cy,Ax,Ay)
191191
print "PTSIGN:" + PTSIGN (Ax,Ay,Bx,By,Qx,Qy)
192192
print "RAD:" + RAD (x)
193193
print "REPLACE:" + REPLACE ("source", 1, "sorce", 2)
194-
print "RGB:" + RGB (80,80,80)
195-
print "RGBF:" + RGBF (.1,.1,.1)
194+
print "RGB:" + RGB (80,90,100) + " " + RGB (-100, 0, 300)
195+
print "RGBF:" + RGBF (.1,.2,.3) + " " + RGBF (-1, 0, 3)
196196
print "RIGHT:" + RIGHT (s,2)
197197
print "RIGHTOF:" + RIGHTOF (s1, s2)
198198
print "RIGHTOFLAST:" + RIGHTOFLAST (s1, s2)

samples/distro-examples/tests/output/all.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ PTDISTSEG:0
174174
PTSIGN:0
175175
RAD:0.2146754979953
176176
REPLACE:sorceurce
177-
RGB:-5263440
178-
RGBF:-1710618
177+
RGB:-5266020 -255
178+
RGBF:-1717069 -255
179179
RIGHT:gs
180180
RIGHTOF:
181181
RIGHTOFLAST:

src/common/blib_db.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,8 @@ void join_path(char *path, char *ext) {
781781
int len = strlen(path);
782782
if (path[len - 1] != OS_DIRSEP) {
783783
if (ext[0] != OS_DIRSEP) {
784-
strcat(path, "/");
784+
char ch[] = {OS_DIRSEP, '\0'};
785+
strcat(path, ch);
785786
strcat(path, ext);
786787
} else {
787788
strcat(path, ext);
@@ -793,6 +794,11 @@ void join_path(char *path, char *ext) {
793794
strcat(path, ext + 1);
794795
}
795796
}
797+
// don't end with trailing slash
798+
len = strlen(path);
799+
if (path[len - 1] == OS_DIRSEP) {
800+
path[len - 1] = '\0';
801+
}
796802
}
797803

798804
/*

src/common/blib_func.c

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,24 @@ static char *date_mN_table[] = TABLE_MONTH_FULL;
3434
#define BIN_LEN 32 // Number of max bits (digits) kwBIN creates
3535

3636
/*
37+
* Clamp floating point number and convert to integer
38+
* x: number, l: lower bound, h: upper bound
3739
*/
3840
var_int_t r2int(var_num_t x, var_int_t l, var_int_t h) {
3941
var_int_t nx;
40-
42+
4143
if (x < 0.0) {
42-
nx = (var_int_t) -floor(-x + .5);
44+
nx = (var_int_t) (x - .5);
4345
} else {
44-
nx = (var_int_t) floor(x + .5);
46+
nx = (var_int_t) (x + .5);
4547
}
4648

4749
if (nx < l) {
4850
nx = l;
4951
} else if (nx > h) {
5052
nx = h;
5153
}
54+
5255
return nx;
5356
}
5457

@@ -1935,37 +1938,22 @@ void cmd_intN(long funcCode, var_t *r) {
19351938
// i <- RGB(r,g,b)
19361939
// i <- RGBF(r,g,b)
19371940
case kwRGB:
1938-
case kwRGBF: {
1941+
case kwRGBF:
19391942
var_num_t rc, gc, bc;
1940-
int code;
19411943

19421944
par_massget("FFF", &rc, &gc, &bc);
19431945
IF_ERR_RETURN;
1944-
code = 0;
1945-
if (funcCode == kwRGBF) {
1946-
if ((rc >= 0 && rc <= 1) && (gc >= 0 && gc <= 1) && (bc >= 0 && bc <= 1)) {
1947-
code = 1;
1948-
}
1949-
} else {
1950-
if ((rc >= 0 && rc <= 255) && (gc >= 0 && gc <= 255) && (bc >= 0 && bc <= 255)) {
1951-
code = 2;
1952-
}
1953-
}
19541946

1955-
switch (code) {
1956-
case 1:
1957-
r->v.i = (r2int(rc * 255.0, 0, 255) << 16) | (r2int(gc * 255.0, 0, 255) << 8)
1958-
| r2int(bc * 255.0, 0, 255);
1947+
switch (funcCode) {
1948+
case kwRGB:
1949+
r->v.i = (r2int(rc, 0, 255) << 16) | (r2int(gc, 0, 255) << 8) | r2int(bc, 0, 255);
19591950
break;
1960-
case 2:
1961-
r->v.i = ((uint32_t) rc << 16) | ((uint32_t) gc << 8) | (uint32_t) bc;
1951+
case kwRGBF:
1952+
r->v.i = (r2int(rc * 255.0, 0, 255) << 16) | (r2int(gc * 255.0, 0, 255) << 8) | r2int(bc * 255.0, 0, 255);
19621953
break;
1963-
default:
1964-
err_argerr();
19651954
}
1966-
1955+
19671956
r->v.i = -r->v.i;
1968-
}
19691957
break;
19701958

19711959
default:

src/common/brun.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,6 @@ void exec_setup_predefined_variables() {
287287
*p = '\0';
288288
}
289289
}
290-
for (char *p = homedir; *p; p++) {
291-
if (*p == '\\') {
292-
*p = '/';
293-
}
294-
}
295290
#elif defined(_UnixOS)
296291
if (getenv("HOME")) {
297292
strlcpy(homedir, getenv("HOME"), sizeof(homedir));

src/common/file.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -674,13 +674,6 @@ char *dev_getcwd() {
674674
retbuf[l] = OS_DIRSEP;
675675
retbuf[l + 1] = '\0';
676676
}
677-
#if defined(_Win32)
678-
for (int i = 0; i < l; i++) {
679-
if (retbuf[i] == '\\') {
680-
retbuf[i] = OS_DIRSEP;
681-
}
682-
}
683-
#endif
684677
return retbuf;
685678
}
686679

src/common/sys.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,15 @@ extern "C" {
5050
#define OS_PATHNAME_SIZE 1024
5151
#define OS_FILENAME_SIZE 256
5252
#define OS_FILEHANDLES 256
53-
#define OS_DIRSEP '/'
5453

5554
#if defined(_Win32)
5655
#define SB_VERSYS "Win"
5756
#define OS_LINESEPARATOR "\r\n"
57+
#define OS_DIRSEP '\\'
5858
#else
5959
#define SB_VERSYS "Unix"
6060
#define OS_LINESEPARATOR "\n"
61+
#define OS_DIRSEP '/'
6162
#endif
6263

6364
#define STRLEN(s) ((sizeof(s) / sizeof(s[0])) - 1)

src/include/var.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ typedef struct var_s {
9999
uint32_t capacity;
100100
// upper and lower bounds
101101
int32_t ubound[MAXDIM];
102-
int8_t lbound[MAXDIM];
102+
int32_t lbound[MAXDIM];
103103
// number of dimensions
104104
uint8_t maxdim;
105105
} a;

0 commit comments

Comments
 (0)