+line inserting/removing; *changed mb_dispose_value as public.
This commit is contained in:
parent
54e3a91365
commit
40bc0a9d0e
4
HISTORY
Normal file → Executable file
4
HISTORY
Normal file → Executable file
@ -1,3 +1,7 @@
|
||||
Apr. 27 2015
|
||||
Added code line inserting/removing to interpreter shell
|
||||
Changed mb_dispose_value as public
|
||||
|
||||
Apr. 23 2015 Version 1.1
|
||||
Added debug APIs
|
||||
Added (nestable) multi line IF statement support
|
||||
|
BIN
MY-BASIC Quick Reference.pdf
Normal file → Executable file
BIN
MY-BASIC Quick Reference.pdf
Normal file → Executable file
Binary file not shown.
42
core/my_basic.c
Normal file → Executable file
42
core/my_basic.c
Normal file → Executable file
@ -77,7 +77,7 @@ extern "C" {
|
||||
/** Macros */
|
||||
#define _VER_MAJOR 1
|
||||
#define _VER_MINOR 1
|
||||
#define _VER_REVISION 51
|
||||
#define _VER_REVISION 52
|
||||
#define _MB_VERSION ((_VER_MAJOR * 0x01000000) + (_VER_MINOR * 0x00010000) + (_VER_REVISION))
|
||||
|
||||
/* Uncomment this line to treat warnings as error */
|
||||
@ -686,15 +686,6 @@ static int _close_std_lib(mb_interpreter_t* s);
|
||||
|
||||
/* ========================================================} */
|
||||
|
||||
/*
|
||||
** {========================================================
|
||||
** Protected function declarations
|
||||
*/
|
||||
|
||||
MBAPI int mb_dispose_value(mb_interpreter_t* s, mb_value_t val);
|
||||
|
||||
/* ========================================================} */
|
||||
|
||||
/*
|
||||
** {========================================================
|
||||
** Lib declarations
|
||||
@ -3138,25 +3129,6 @@ int _close_std_lib(mb_interpreter_t* s) {
|
||||
|
||||
/* ========================================================} */
|
||||
|
||||
/*
|
||||
** {========================================================
|
||||
** Protected function definitions
|
||||
*/
|
||||
|
||||
int mb_dispose_value(mb_interpreter_t* s, mb_value_t val) {
|
||||
/* Dispose a value */
|
||||
int result = MB_FUNC_OK;
|
||||
|
||||
mb_assert(s);
|
||||
|
||||
if(val.type == MB_DT_STRING)
|
||||
mb_free(val.value.string);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/* ========================================================} */
|
||||
|
||||
/*
|
||||
** {========================================================
|
||||
** Public functions definitions
|
||||
@ -3751,6 +3723,18 @@ int mb_push_value(struct mb_interpreter_t* s, void** l, mb_value_t val) {
|
||||
return result;
|
||||
}
|
||||
|
||||
int mb_dispose_value(struct mb_interpreter_t* s, mb_value_t val) {
|
||||
/* Dispose a value */
|
||||
int result = MB_FUNC_OK;
|
||||
|
||||
mb_assert(s);
|
||||
|
||||
if(val.type == MB_DT_STRING)
|
||||
mb_free(val.value.string);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int mb_load_string(struct mb_interpreter_t* s, const char* l) {
|
||||
/* Load a script string */
|
||||
int result = MB_FUNC_OK;
|
||||
|
1
core/my_basic.h
Normal file → Executable file
1
core/my_basic.h
Normal file → Executable file
@ -247,6 +247,7 @@ MBAPI int mb_push_real(struct mb_interpreter_t* s, void** l, real_t val);
|
||||
MBAPI int mb_push_string(struct mb_interpreter_t* s, void** l, char* val);
|
||||
MBAPI int mb_push_usertype(struct mb_interpreter_t* s, void** l, void* val);
|
||||
MBAPI int mb_push_value(struct mb_interpreter_t* s, void** l, mb_value_t val);
|
||||
MBAPI int mb_dispose_value(struct mb_interpreter_t* s, mb_value_t val);
|
||||
|
||||
MBAPI int mb_load_string(struct mb_interpreter_t* s, const char* l);
|
||||
MBAPI int mb_load_file(struct mb_interpreter_t* s, const char* f);
|
||||
|
BIN
output/my_basic.exe
Normal file → Executable file
BIN
output/my_basic.exe
Normal file → Executable file
Binary file not shown.
Binary file not shown.
0
resource/my_basic.aps
Normal file → Executable file
0
resource/my_basic.aps
Normal file → Executable file
8
resource/my_basic.rc
Normal file → Executable file
8
resource/my_basic.rc
Normal file → Executable file
@ -36,8 +36,8 @@
|
||||
IDI_ICON_MAIN ICON "icon.ico"
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 1,1,51,0
|
||||
PRODUCTVERSION 1,1,51,0
|
||||
FILEVERSION 1,1,52,0
|
||||
PRODUCTVERSION 1,1,52,0
|
||||
FILEFLAGSMASK 0x17L
|
||||
# ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
@ -55,13 +55,13 @@
|
||||
VALUE "Comments", "MY-BASIC"
|
||||
VALUE "CompanyName", "W. Renxin"
|
||||
VALUE "FileDescription", "MY-BASIC interpreter"
|
||||
VALUE "FileVersion", "1, 1, 51, 0"
|
||||
VALUE "FileVersion", "1, 1, 52, 0"
|
||||
VALUE "InternalName", "my_basic"
|
||||
VALUE "LegalCopyright", "Copyright (C) 2011 - 2015 W. Renxin"
|
||||
VALUE "LegalTrademarks", "MY-BASIC"
|
||||
VALUE "OriginalFilename", "my_basic.exe"
|
||||
VALUE "ProductName", "MY-BASIC"
|
||||
VALUE "ProductVersion", "1, 1, 51, 0"
|
||||
VALUE "ProductVersion", "1, 1, 52, 0"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
|
0
resource/resource.h
Normal file → Executable file
0
resource/resource.h
Normal file → Executable file
57
shell/main.c
Normal file → Executable file
57
shell/main.c
Normal file → Executable file
@ -304,6 +304,49 @@ static void _edit_program(const char* no) {
|
||||
strcpy(c->lines[lno], line);
|
||||
}
|
||||
|
||||
static void _insert_program(const char* no) {
|
||||
char line[_MAX_LINE_LENGTH];
|
||||
long lno = 0;
|
||||
int i = 0;
|
||||
mb_assert(no);
|
||||
lno = atoi(no);
|
||||
if(lno < 1 || lno > c->count) {
|
||||
printf("Line number %ld out of bound.\n", lno);
|
||||
|
||||
return;
|
||||
}
|
||||
--lno;
|
||||
memset(line, 0, _MAX_LINE_LENGTH);
|
||||
printf("%ld]", lno + 1);
|
||||
mb_gets(line, _MAX_LINE_LENGTH);
|
||||
if(c->count + 1 == c->size) {
|
||||
c->size += _LINE_INC_STEP;
|
||||
c->lines = (char**)realloc(c->lines, sizeof(char*) * c->size);
|
||||
}
|
||||
for(i = c->count; i > lno; i--)
|
||||
c->lines[i] = c->lines[i - 1];
|
||||
c->lines[lno] = (char*)realloc(0, strlen(line) + 1);
|
||||
strcpy(c->lines[lno], line);
|
||||
c->count++;
|
||||
}
|
||||
|
||||
static void _alter_program(const char* no) {
|
||||
long lno = 0;
|
||||
int i = 0;
|
||||
mb_assert(no);
|
||||
lno = atoi(no);
|
||||
if(lno < 1 || lno > c->count) {
|
||||
printf("Line number %ld out of bound.\n", lno);
|
||||
|
||||
return;
|
||||
}
|
||||
--lno;
|
||||
free(c->lines[lno]);
|
||||
for(i = lno; i < c->count - 1; i++)
|
||||
c->lines[i] = c->lines[i + 1];
|
||||
c->count--;
|
||||
}
|
||||
|
||||
static void _load_program(const char* path) {
|
||||
char* txt = _load_file(path);
|
||||
if(txt) {
|
||||
@ -357,8 +400,10 @@ static void _show_help(void) {
|
||||
printf(" BYE - Quit interpreter\n");
|
||||
printf(" LIST - List current program\n");
|
||||
printf(" Usage: LIST [l [n]], l is start line number, n is line count\n");
|
||||
printf(" EDIT - Edit a line in current program\n");
|
||||
printf(" EDIT - Edit (modify/insert/remove) a line in current program\n");
|
||||
printf(" Usage: EDIT n, n is line number\n");
|
||||
printf(" EDIT -I n, insert a line before a given line, n is line number\n");
|
||||
printf(" EDIT -R n, remove a line, n is line number\n");
|
||||
printf(" LOAD - Load a file as current program\n");
|
||||
printf(" Usage: LOAD *.*\n");
|
||||
printf(" SAVE - Save current program to a file\n");
|
||||
@ -407,7 +452,15 @@ static int _do_line(void) {
|
||||
_list_program(sn, cn);
|
||||
} else if(_str_eq(line, "EDIT")) {
|
||||
char* no = line + strlen(line) + 1;
|
||||
_edit_program(no);
|
||||
char* ne = 0;
|
||||
strtok(no, " ");
|
||||
ne = no + strlen(no) + 1;
|
||||
if(!(*ne))
|
||||
_edit_program(no);
|
||||
else if(_str_eq(no, "-I"))
|
||||
_insert_program(ne);
|
||||
else if(_str_eq(no, "-R"))
|
||||
_alter_program(ne);
|
||||
} else if(_str_eq(line, "LOAD")) {
|
||||
char* path = line + strlen(line) + 1;
|
||||
_load_program(path);
|
||||
|
Loading…
x
Reference in New Issue
Block a user