Skip to content

Commit 0df442c

Browse files
committed
COMMON: cleanup sysvar handling
1 parent 0808ff2 commit 0df442c

File tree

12 files changed

+16
-177
lines changed

12 files changed

+16
-177
lines changed

ChangeLog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2014-08-11
2+
Cleanup system var handling, removed os_ver
3+
14
2014-08-09
25
Renamed command "#UNIT-PATH:" to "UNITPATH"
36
Renamed command "#INC:" to "INCLUDE"

samples/distro-examples/tests/call_tau.bas

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,3 @@ rem check system-variables
2020
predef.prsys
2121

2222

23-
24-

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,4 @@ message from main
1010
message from tau
1111
[1,2,3,4]
1212
Predefined Variables
13-
OS VER =0x0
14-
OS NAME=Unix/Linux version 3.13.0-32-generic (buildd@kissel) (gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1) ) #57-Ubuntu SMP Tue Jul 15 03:51:08 UTC 2014
15-
SB VER =0x0
1613
PI =3.14159265358979
17-
XMAX =161
18-
YMAX =42
19-
CWD =/home/chrisws/src/SmallBASIC/src/platform/unix/
20-
HOME =/home/chrisws/

samples/distro-examples/tests/predef.bas

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,5 @@ export prsys
44

55
sub prsys
66
? cat(1);"Predefined Variables";cat(0)
7-
? "OS VER =0x"; HEX$(osver)
8-
? "OS NAME="; osname
9-
? "SB VER =0x"; HEX$(sbver)
107
? "PI ="; pi
11-
? "XMAX ="; xmax
12-
? "YMAX ="; ymax
13-
? "CWD ="; CWD
14-
? "HOME ="; HOME
158
end
16-
17-
18-

src/common/brun.c

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -591,32 +591,16 @@ void setsysvar_str(int index, const char *value) {
591591
*/
592592
void exec_setup_predefined_variables() {
593593
char homedir[OS_PATHNAME_SIZE + 1];
594-
#if defined(_UnixOS)
595-
int l;
596-
#endif
597594

598595
// needed here (otherwise task will not updated)
599596
ctask->has_sysvars = 1;
600597

601-
setsysvar_int(SYSVAR_OSVER, os_ver);
602598
setsysvar_str(SYSVAR_OSNAME, OS_NAME);
603599
setsysvar_str(SYSVAR_SBVER, SB_STR_VER);
604600
setsysvar_num(SYSVAR_PI, SB_PI);
605-
606-
// Change from Haraszti - 30/3/2007 Thanks Atilla :)
607-
// setsysvar_int(SYSVAR_XMAX, 159);
608-
// setsysvar_int(SYSVAR_YMAX, 159);
609-
// setsysvar_int(SYSVAR_BPP, 1);
610601
setsysvar_int(SYSVAR_XMAX, os_graf_mx - 1);
611602
setsysvar_int(SYSVAR_YMAX, os_graf_my - 1);
612-
if (os_graphics) {
613-
setsysvar_int(SYSVAR_BPP, os_color_depth);
614-
}
615-
else {
616-
setsysvar_int(SYSVAR_BPP, 4);
617-
}
618-
// end of change
619-
603+
setsysvar_int(SYSVAR_BPP, os_graphics ? os_color_depth : 4);
620604
setsysvar_int(SYSVAR_TRUE, -1);
621605
setsysvar_int(SYSVAR_FALSE, 0);
622606
setsysvar_int(SYSVAR_LINECHART, 1);
@@ -631,7 +615,7 @@ void exec_setup_predefined_variables() {
631615
else {
632616
strcpy(homedir, "/tmp/");
633617
}
634-
l = strlen(homedir);
618+
int l = strlen(homedir);
635619
if (homedir[l - 1] != OS_DIRSEP) {
636620
homedir[l] = OS_DIRSEP;
637621
homedir[l + 1] = '\0';

src/common/device.c

Lines changed: 0 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,6 @@ void termination_handler(int signum) {
5353
* initialize all drivers
5454
*/
5555
int dev_init(int mode, int flags) {
56-
#if defined(_UnixOS)
57-
int verfd;
58-
// struct utsname uts;
59-
#endif
60-
6156
#if defined(DRV_SOUND)
6257
drvsound_ok = drvsound_init();
6358
#endif
@@ -73,21 +68,6 @@ int dev_init(int mode, int flags) {
7368
os_graphics = mode;
7469
term_init(); // by default
7570
if (mode) {
76-
#if defined(_UnixOS)
77-
char buf[256];
78-
79-
if (term_israw()) {
80-
setsysvar_str(SYSVAR_OSNAME, "Unix/RAW");
81-
} else {
82-
if (getenv("TERM")) {
83-
strcpy(buf, "Unix/Terminal:");
84-
strcat(buf, getenv("TERM"));
85-
setsysvar_str(SYSVAR_OSNAME, buf);
86-
} else {
87-
setsysvar_str(SYSVAR_OSNAME, "Unix/Stream");
88-
}
89-
}
90-
#endif
9171
if (osd_devinit() == 0) {
9272
panic("osd_devinit() failed");
9373
}
@@ -107,95 +87,6 @@ int dev_init(int mode, int flags) {
10787
} else {
10888
dev_fgcolor = 7;
10989
dev_bgcolor = 0;
110-
#if USE_TERM_IO
111-
// term_settextcolor(dev_fgcolor, dev_bgcolor);
112-
#endif
113-
}
114-
115-
#if defined(_UnixOS)
116-
/*
117-
if ( uname(&uts) == 0 ) {
118-
// will use the POSIX's uname()
119-
strcpy(tmp, "Unix/");
120-
strcat(tmp, uts.machine);
121-
strcat(tmp, "/");
122-
strcat(tmp, uts.sysname);
123-
setsysvar_str(SYSVAR_OSNAME, tmp);
124-
}
125-
else {
126-
*/
127-
// will try to read /proc/version
128-
verfd = open("/proc/version", O_RDONLY);
129-
if (verfd != -1) {
130-
char *p;
131-
char verstr[256];
132-
char tmp[300];
133-
int bytes;
134-
135-
memset(verstr, 0, 256);
136-
bytes = read(verfd, verstr, 255);
137-
verstr[(bytes < 256) ? bytes : 255] = '\0';
138-
p = strchr(verstr, '\n');
139-
if (p) {
140-
*p = '\0';
141-
}
142-
close(verfd);
143-
144-
// store name to system constant
145-
strcpy(tmp, "Unix/");
146-
strcat(tmp, verstr);
147-
setsysvar_str(SYSVAR_OSNAME, tmp);
148-
149-
// build OSVER
150-
if ((p = strstr(verstr, "ersion")) != NULL) {
151-
long vi = 0;
152-
int dg = 0;
153-
154-
p += 6;
155-
while (*p == ' ' || *p == '\t') {
156-
p++;
157-
}
158-
while (*p) {
159-
if (is_digit(*p)) {
160-
vi = (vi << 4) + (*p - '0');
161-
dg++;
162-
} else if (*p == '.') {
163-
switch (dg) {
164-
case 0:
165-
vi = vi << 8;
166-
break;
167-
case 1:
168-
vi = vi << 4;
169-
break;
170-
};
171-
172-
dg = 0;
173-
}
174-
else {
175-
break;
176-
}
177-
178-
p++;
179-
} // while (*p)
180-
181-
os_ver = vi;
182-
} // if ver
183-
} // verfd
184-
185-
setsysvar_int(SYSVAR_OSVER, os_ver);
186-
#elif defined(_DOS)
187-
os_ver = ((_osmajor << 16) | (_osminor)) << 8;
188-
setsysvar_int(SYSVAR_OSVER, os_ver);
189-
#else
190-
setsysvar_int(SYSVAR_OSVER, os_ver);
191-
#endif
192-
193-
setsysvar_int(SYSVAR_XMAX, os_graf_mx - 1);
194-
setsysvar_int(SYSVAR_YMAX, os_graf_my - 1);
195-
if (os_graphics) {
196-
setsysvar_int(SYSVAR_BPP, os_color_depth);
197-
} else {
198-
setsysvar_int(SYSVAR_BPP, 4);
19990
}
20091

20192
#if USE_TERM_IO && !defined(__MINGW32__)

src/common/device.h

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,8 @@ void g_line(int x1, int y1, int x2, int y2, void (*dotproc) (int, int));
100100
* Globals are needed for speed and for memory-usage optimization
101101
*
102102
* @code
103-
* dword os_ver; // OS version (ex: 0x330 for PalmOS 3.3)
104-
*
105103
* byte os_charset; // System's charset (see os_charset_codes)
106104
*
107-
* byte use_sony_clie; // True if the program runs under a Sony CLIE
108-
*
109-
* UInt16 sony_refHR; // Sony's HiRes lib ref
110-
*
111105
* byte os_color; // True if the output has real colors (256+ colors)
112106
*
113107
* dword os_color_depth; // The number of bits of the supported colors
@@ -144,18 +138,11 @@ enum os_charset_codes {
144138
};
145139

146140
#if !defined(DEVICE_MODULE)
147-
extern dword os_ver; // OS version (ex: 0x330 for PalmOS 3.3)
148141
extern byte os_charset;
149142

150-
#if defined(SONY_CLIE)
151-
extern byte use_sony_clie; // true if the program runs under a Sony CLIE
152-
extern UInt16 sony_refHR; // Sony's HiRes lib ref
153-
#endif
154-
155-
extern byte os_color; // true if the output has real colors (256+
156-
// colors)
143+
extern byte os_color; // true if the output has real colors (256+ colors)
157144
extern dword os_color_depth; // the number of bits of the supported colors
158-
// (ex: 8 for 256 colors, 15 or 16 for 64K, 24 or 32 for 1.6M)
145+
// (ex: 8 for 256 colors, 15 or 16 for 64K, 24 or 32 for 1.6M)
159146
extern byte os_graphics; // non-zero if the driver supports graphics
160147
extern int os_graf_mx; // graphic mode: maximum x
161148
extern int os_graf_my; // graphic mode: maximum y

src/common/scan.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919
#include "common/messages.h"
2020
#include "languages/keywords.en.c"
2121

22+
char *comp_array_uds_field(char *p, bc_t * bc);
23+
void comp_text_line(char *text);
24+
addr_t comp_search_bc(addr_t ip, code_t code);
25+
extern void expr_parser(bc_t * bc);
26+
extern void sc_raise2(const char *fmt, int line, const char *buff); // sberr
27+
2228
#define STRLEN(s) ((sizeof(s) / sizeof(s[0])) - 1)
2329
#define LEN_OPTION STRLEN(LCN_OPTION)
2430
#define LEN_IMPORT STRLEN(LCN_IMPORT_WRS)
@@ -37,12 +43,6 @@
3743
#define LEN_CSTR STRLEN(LCN_CSTR)
3844
#define LEN_COMMAND STRLEN(LCN_COMMAND)
3945

40-
char *comp_array_uds_field(char *p, bc_t * bc);
41-
void comp_text_line(char *text);
42-
addr_t comp_search_bc(addr_t ip, code_t code);
43-
extern void expr_parser(bc_t * bc);
44-
extern void sc_raise2(const char *fmt, int line, const char *buff); // sberr
45-
4646
#define SKIP_SPACES(p) \
4747
while (*p == ' ' || *p == '\t') { \
4848
p++; \

src/platform/android/jni/runtime.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,6 @@ void maAlert(const char *title, const char *message, const char *button1,
686686
// sbasic implementation
687687
//
688688
int osd_devinit(void) {
689-
setsysvar_str(SYSVAR_OSNAME, "Android");
690689
runtime->clearSoundQueue();
691690
runtime->setRunning(true);
692691
return 1;

src/platform/fltk/EditorWidget.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ bool EditorWidget::checkSave(bool discard) {
632632

633633
const char *msg = "The current file has not been saved.\n" "Would you like to save it now?";
634634
int r = discard ? choice(msg, "Save", "Discard", "Cancel") : choice(msg, "Save", "Cancel", 0);
635-
if (r == 0) {
635+
if (discard ? (r == 2) : (r == 1)) {
636636
save_file(); // Save the file
637637
return !dirty;
638638
}

0 commit comments

Comments
 (0)