diff --git a/HISTORY b/HISTORY old mode 100644 new mode 100755 index 9a859d6..bbc4522 --- a/HISTORY +++ b/HISTORY @@ -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 diff --git a/MY-BASIC Quick Reference.pdf b/MY-BASIC Quick Reference.pdf old mode 100644 new mode 100755 index fcaa239..214a089 Binary files a/MY-BASIC Quick Reference.pdf and b/MY-BASIC Quick Reference.pdf differ diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/core/my_basic.c b/core/my_basic.c old mode 100644 new mode 100755 index e342a76..f7a06ab --- a/core/my_basic.c +++ b/core/my_basic.c @@ -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; diff --git a/core/my_basic.h b/core/my_basic.h old mode 100644 new mode 100755 index 77bae60..fc01e19 --- a/core/my_basic.h +++ b/core/my_basic.h @@ -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); diff --git a/output/my_basic.exe b/output/my_basic.exe old mode 100644 new mode 100755 index bce7c67..6081480 Binary files a/output/my_basic.exe and b/output/my_basic.exe differ diff --git a/output/my_basic_mac b/output/my_basic_mac index 8b5fca4..26693a4 100755 Binary files a/output/my_basic_mac and b/output/my_basic_mac differ diff --git a/resource/my_basic.aps b/resource/my_basic.aps old mode 100644 new mode 100755 diff --git a/resource/my_basic.rc b/resource/my_basic.rc old mode 100644 new mode 100755 index 4a6b859..3111977 --- a/resource/my_basic.rc +++ b/resource/my_basic.rc @@ -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" diff --git a/resource/resource.h b/resource/resource.h old mode 100644 new mode 100755 diff --git a/shell/main.c b/shell/main.c old mode 100644 new mode 100755 index 7ac6a75..a990d26 --- a/shell/main.c +++ b/shell/main.c @@ -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);