+added a SET_IMPORTING_DIRS statement to the shell; *fixed a memory corruption bug with importing directory setting.
This commit is contained in:
parent
25d76bb579
commit
6be1d905db
2
HISTORY
2
HISTORY
@ -1,6 +1,8 @@
|
||||
Jan. 26 2016
|
||||
Added a SET_IMPORTING_DIRS statement to the shell
|
||||
Added friendly error promption when memory overflow
|
||||
Added source file information to stepped handler
|
||||
Fixed a memory corruption bug with importing directory setting
|
||||
Optimized cached list accessing
|
||||
|
||||
Jan. 25 2016
|
||||
|
@ -127,6 +127,8 @@ Most of the fundamental topics are mentioned in the [MY-BASIC Quick Reference](M
|
||||
* [Use prototype-based class](https://github.com/paladin-t/my_basic/wiki/Use-prototype-based-class)
|
||||
* [Define a class in C](https://github.com/paladin-t/my_basic/wiki/Define-a-class-in-C)
|
||||
* [Meta methods](https://github.com/paladin-t/my_basic/wiki/Meta-methods)
|
||||
* Standalone shell
|
||||
* [Extra functions](https://github.com/paladin-t/my_basic/wiki/Extra-functions)
|
||||
* Integration
|
||||
* [Link with MY-BASIC](https://github.com/paladin-t/my_basic/wiki/Link-with-MY_BASIC)
|
||||
* [Write a debugger](https://github.com/paladin-t/my_basic/wiki/Write-a-debugger)
|
||||
|
45
shell/main.c
45
shell/main.c
@ -539,6 +539,18 @@ typedef struct _importing_dirs_t {
|
||||
|
||||
static _importing_dirs_t* importing_dirs = 0;
|
||||
|
||||
static void _destroy_importing_directories(void) {
|
||||
int i = 0;
|
||||
|
||||
if(!importing_dirs) return;
|
||||
|
||||
for(i = 0; i < importing_dirs->count; ++i) {
|
||||
free(importing_dirs->dirs[i]);
|
||||
}
|
||||
free(importing_dirs->dirs);
|
||||
free(importing_dirs);
|
||||
}
|
||||
|
||||
static _importing_dirs_t* _set_importing_directories(char* dirs) {
|
||||
if(dirs) {
|
||||
char* end = dirs + strlen(dirs);
|
||||
@ -560,7 +572,7 @@ static _importing_dirs_t* _set_importing_directories(char* dirs) {
|
||||
}
|
||||
l = (int)strlen(dirs);
|
||||
as = dirs[l - 1] != '/' && dirs[l - 1] != '\\';
|
||||
buf = (char*)malloc(l + as ? 2 : 1);
|
||||
buf = (char*)malloc(l + (as ? 2 : 1));
|
||||
memcpy(buf, dirs, l);
|
||||
if(as) {
|
||||
buf[l] = '/';
|
||||
@ -576,6 +588,7 @@ static _importing_dirs_t* _set_importing_directories(char* dirs) {
|
||||
dirs += l + 1;
|
||||
}
|
||||
|
||||
_destroy_importing_directories();
|
||||
importing_dirs = result;
|
||||
|
||||
return result;
|
||||
@ -584,18 +597,6 @@ static _importing_dirs_t* _set_importing_directories(char* dirs) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void _destroy_importing_directories(void) {
|
||||
int i = 0;
|
||||
|
||||
if(!importing_dirs) return;
|
||||
|
||||
for(i = 0; i < importing_dirs->count; ++i) {
|
||||
free(importing_dirs->dirs[i]);
|
||||
}
|
||||
free(importing_dirs->dirs);
|
||||
free(importing_dirs);
|
||||
}
|
||||
|
||||
static bool_t _try_import(struct mb_interpreter_t* s, const char* p) {
|
||||
bool_t result = false;
|
||||
int i = 0;
|
||||
@ -1114,6 +1115,23 @@ static int now(struct mb_interpreter_t* s, void** l) {
|
||||
return result;
|
||||
}
|
||||
|
||||
static int set_importing_dirs(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));
|
||||
if(arg)
|
||||
_set_importing_directories(arg);
|
||||
|
||||
mb_check(mb_attempt_close_bracket(s, l));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static int beep(struct mb_interpreter_t* s, void** l) {
|
||||
int result = MB_FUNC_OK;
|
||||
|
||||
@ -1197,6 +1215,7 @@ static void _on_startup(void) {
|
||||
mb_reg_fun(bas, ticks);
|
||||
#endif /* _HAS_TICKS */
|
||||
mb_reg_fun(bas, now);
|
||||
mb_reg_fun(bas, set_importing_dirs);
|
||||
mb_reg_fun(bas, beep);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user