Skip to content

Commit eb7c175

Browse files
committed
COMMON: update for dymanic sys vars
1 parent f6c9e77 commit eb7c175

File tree

5 files changed

+20
-10
lines changed

5 files changed

+20
-10
lines changed

src/common/blib.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ void cmd_diffeq(void);
9595
void graph_reset(void); // graphics module - reset
9696
void graph_get_xstep(var_t *r);
9797
void graph_get_ystep(var_t *r);
98+
void graph_get_mx(var_t *r);
99+
void graph_get_my(var_t *r);
98100
void cmd_pset(void);
99101
void cmd_line(void);
100102
void cmd_rect(void);

src/common/blib_graph.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ void graph_get_ystep(var_t *r) {
3333
v_setint(r, gra_y);
3434
}
3535

36+
void graph_get_mx(var_t *r) {
37+
v_setint(r, os_graf_mx - 1);
38+
}
39+
40+
void graph_get_my(var_t *r) {
41+
v_setint(r, os_graf_my - 1);
42+
}
43+
3644
//
3745
// VIEW [x1,y1,x2,y2[,c[,b]]]
3846
//

src/common/brun.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,10 @@ void setsysvar_str(int index, const char *value) {
287287
activate_task(tid);
288288
}
289289

290+
void sysvar_getcwd(var_t *r) {
291+
v_setstr(r, dev_getcwd());
292+
}
293+
290294
/**
291295
* create predefined system variables for this task
292296
*/
@@ -298,12 +302,12 @@ void exec_setup_predefined_variables() {
298302

299303
setsysvar_str(SYSVAR_SBVER, SB_STR_VER);
300304
setsysvar_num(SYSVAR_PI, SB_PI);
301-
setsysvar_int(SYSVAR_XMAX, os_graf_mx - 1);
302-
setsysvar_int(SYSVAR_YMAX, os_graf_my - 1);
303305
setsysvar_int(SYSVAR_TRUE, 1);
304306
setsysvar_int(SYSVAR_FALSE, 0);
305-
setsysvar_str(SYSVAR_CWD, dev_getcwd());
306307
setsysvar_str(SYSVAR_COMMAND, opt_command);
308+
setsysvar_fn(SYSVAR_CWD, sysvar_getcwd);
309+
setsysvar_fn(SYSVAR_XMAX, graph_get_mx);
310+
setsysvar_fn(SYSVAR_YMAX, graph_get_my);
307311
setsysvar_fn(SYSVAR_LASTX, graph_get_xstep);
308312
setsysvar_fn(SYSVAR_LASTY, graph_get_ystep);
309313

@@ -321,14 +325,13 @@ void exec_setup_predefined_variables() {
321325
}
322326
setsysvar_str(SYSVAR_HOME, homedir);
323327
#elif defined(_Win32)
324-
if (dev_getenv("HOME")) { // this works on cygwin
328+
if (dev_getenv("HOME")) {
329+
// this works on cygwin
325330
strcpy(homedir, dev_getenv("HOME"));
326331
}
327332
else {
328-
char *p;
329-
330333
GetModuleFileName(NULL, homedir, 1024);
331-
p = strrchr(homedir, '\\');
334+
char *p = strrchr(homedir, '\\');
332335
*p = '\0';
333336
strcat(homedir, "\\");
334337

src/common/file.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,6 @@ void dev_chdir(const char *dir) {
616616
if (chdir(dir) != 0) {
617617
err_file(errno);
618618
}
619-
setsysvar_str(SYSVAR_CWD, dev_getcwd());
620619
}
621620

622621
/**

src/ui/system.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -728,8 +728,6 @@ void System::setupPath() {
728728
void System::setDimensions() {
729729
os_graf_mx = _output->getWidth();
730730
os_graf_my = _output->getHeight();
731-
setsysvar_int(SYSVAR_XMAX, os_graf_mx - 1);
732-
setsysvar_int(SYSVAR_YMAX, os_graf_my - 1);
733731
}
734732

735733
void System::setRunning(bool running) {

0 commit comments

Comments
 (0)