diff --git a/HISTORY b/HISTORY index 72a036e..6fe4449 100755 --- a/HISTORY +++ b/HISTORY @@ -1,3 +1,6 @@ +Aug. 29 2017 +Added a prompting for inputer + Jul. 24 2017 Added an mb_get_var_name function diff --git a/MY-BASIC Quick Reference.pdf b/MY-BASIC Quick Reference.pdf index 19d53a1..0b5ceab 100644 Binary files a/MY-BASIC Quick Reference.pdf and b/MY-BASIC Quick Reference.pdf differ diff --git a/core/my_basic.c b/core/my_basic.c index 18016a8..c4a337b 100755 --- a/core/my_basic.c +++ b/core/my_basic.c @@ -14005,8 +14005,9 @@ _exit: } /* Safe stdin reader function */ -int mb_gets(char* buf, int s) { +int mb_gets(const char* pmt, char* buf, int s) { int result = 0; + mb_unrefvar(pmt); if(buf && s) { if(fgets(buf, s, stdin) == 0) { @@ -17464,6 +17465,7 @@ static int _std_input(mb_interpreter_t* s, void** l) { _object_t* obj = 0; char line[_INPUT_MAX_LENGTH]; char* conv_suc = 0; + const char* pmt = 0; mb_assert(s && l); @@ -17478,12 +17480,13 @@ static int _std_input(mb_interpreter_t* s, void** l) { #ifdef MB_CP_VC getch(); #else /* MB_CP_VC */ - _get_inputer(s)(line, sizeof(line)); + _get_inputer(s)(pmt, line, sizeof(line)); #endif /* MB_CP_VC */ goto _exit; } if(obj->type == _DT_STRING) { + pmt = obj->data.string; _print_string(s, obj); ast = ast->next; obj = (_object_t*)ast->data; @@ -17497,7 +17500,7 @@ static int _std_input(mb_interpreter_t* s, void** l) { _handle_error_on_obj(s, SE_RN_VAR_EXPECTED, s->source_file, DON(ast), MB_FUNC_ERR, _exit, result); } if(obj->data.variable->data->type == _DT_INT || obj->data.variable->data->type == _DT_REAL) { - _get_inputer(s)(line, sizeof(line)); + _get_inputer(s)(pmt, line, sizeof(line)); obj->data.variable->data->type = _DT_INT; obj->data.variable->data->data.integer = (int_t)mb_strtol(line, &conv_suc, 0); if(*conv_suc != _ZERO_CHAR) { @@ -17515,7 +17518,7 @@ static int _std_input(mb_interpreter_t* s, void** l) { if(obj->data.variable->data->data.string && !obj->data.variable->data->is_ref) { safe_free(obj->data.variable->data->data.string); } - len = (size_t)_get_inputer(s)(line, sizeof(line)); + len = (size_t)_get_inputer(s)(pmt, line, sizeof(line)); #if defined MB_CP_VC && defined MB_ENABLE_UNICODE do { _dynamic_buffer_t buf; diff --git a/core/my_basic.h b/core/my_basic.h index 4c0eb6d..5612dce 100755 --- a/core/my_basic.h +++ b/core/my_basic.h @@ -573,7 +573,7 @@ typedef int (* mb_routine_func_t)(struct mb_interpreter_t*, void**, mb_value_t*, typedef int (* mb_debug_stepped_handler_t)(struct mb_interpreter_t*, void**, char*, int, unsigned short, unsigned short); typedef void (* mb_error_handler_t)(struct mb_interpreter_t*, mb_error_e, char*, char*, int, unsigned short, unsigned short, int); typedef int (* mb_print_func_t)(const char*, ...); -typedef int (* mb_input_func_t)(char*, int); +typedef int (* mb_input_func_t)(const char*, char*, int); typedef int (* mb_import_handler_t)(struct mb_interpreter_t*, const char*); typedef void (* mb_dtor_func_t)(struct mb_interpreter_t*, void*); typedef void* (* mb_clone_func_t)(struct mb_interpreter_t*, void*); @@ -685,7 +685,7 @@ MBAPI int mb_gc(struct mb_interpreter_t* s, int_t* collected/* = NULL*/); MBAPI int mb_get_userdata(struct mb_interpreter_t* s, void** d); MBAPI int mb_set_userdata(struct mb_interpreter_t* s, void* d); MBAPI int mb_set_import_handler(struct mb_interpreter_t* s, mb_import_handler_t h); -MBAPI int mb_gets(char* buf, int s); +MBAPI int mb_gets(const char* pmt, char* buf, int s); MBAPI char* mb_memdup(const char* val, unsigned size); MBAPI int mb_set_memory_manager(mb_memory_allocate_func_t a, mb_memory_free_func_t f); diff --git a/shell/main.c b/shell/main.c index 90e12a0..0158b4d 100755 --- a/shell/main.c +++ b/shell/main.c @@ -853,7 +853,7 @@ static void _edit_program(const char* no) { --lno; memset(line, 0, _MAX_LINE_LENGTH); _printf("%ld]", lno + 1); - mb_gets(line, _MAX_LINE_LENGTH); + mb_gets(0, line, _MAX_LINE_LENGTH); l = (int)strlen(line); _code()->lines[lno] = (char*)realloc(_code()->lines[lno], l + 2); strcpy(_code()->lines[lno], line); @@ -878,7 +878,7 @@ static void _insert_program(const char* no) { --lno; memset(line, 0, _MAX_LINE_LENGTH); _printf("%ld]", lno + 1); - mb_gets(line, _MAX_LINE_LENGTH); + mb_gets(0, line, _MAX_LINE_LENGTH); if(_code()->count + 1 == _code()->size) { _code()->size += _REALLOC_INC_STEP; _code()->lines = (char**)realloc(_code()->lines, sizeof(char*) * _code()->size); @@ -1028,7 +1028,7 @@ static int _do_line(void) { memset(line, 0, _MAX_LINE_LENGTH); _printf("]"); - mb_gets(line, _MAX_LINE_LENGTH); + mb_gets(0, line, _MAX_LINE_LENGTH); memcpy(dup, line, _MAX_LINE_LENGTH); strtok(line, " ");