From 65f50ebecaf46f23cd99a879dd185abe4f145547 Mon Sep 17 00:00:00 2001 From: paladin-t Date: Thu, 18 Feb 2016 19:19:46 +0800 Subject: [PATCH] +added a SYS statement to the shell. --- HISTORY | 1 + shell/main.c | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/HISTORY b/HISTORY index 6a44ebc..f49c45a 100755 --- a/HISTORY +++ b/HISTORY @@ -1,5 +1,6 @@ Feb. 18 2016 Added a generic iterator type +Added a SYS statement to the shell Fixed a wrong list linkage bug with list sorting Feb. 16 2016 diff --git a/shell/main.c b/shell/main.c index 5eb4946..d777a4c 100755 --- a/shell/main.c +++ b/shell/main.c @@ -1102,7 +1102,7 @@ static int_t _ticks(void) { clock_gettime(CLOCK_MONOTONIC, &ts); - return ts.tv_sec * 1000 + ts.tv_nsec / 1000000; + return (int_t)(ts.tv_sec * 1000 + ts.tv_nsec / 1000000); } #else /* _MSC_VER */ # undef _HAS_TICKS @@ -1171,6 +1171,24 @@ static int set_importing_dirs(struct mb_interpreter_t* s, void** l) { return result; } +static int sys(struct mb_interpreter_t* s, void** l) { + int result = MB_FUNC_OK; + char* arg = 0; + + mb_assert(s && l); + + mb_check(mb_attempt_open_bracket(s, l)); + + mb_check(mb_pop_string(s, l, &arg)); + + mb_check(mb_attempt_close_bracket(s, l)); + + if(arg) + system(arg); + + return result; +} + static int trace(struct mb_interpreter_t* s, void** l) { int result = MB_FUNC_OK; char* frames[16]; @@ -1300,6 +1318,7 @@ static void _on_startup(void) { #endif /* _HAS_TICKS */ mb_reg_fun(bas, now); mb_reg_fun(bas, set_importing_dirs); + mb_reg_fun(bas, sys); mb_reg_fun(bas, trace); mb_reg_fun(bas, gc); mb_reg_fun(bas, beep);