Skip to content

Commit 60bcd0b

Browse files
committed
Added an MB_PRINT_INPUT_PROMPT macro
Added an MB_PRINT_INPUT_CONTENT macro Fixed a wrong return value of the mb_get_array_len function Fixed a newline bug of the shell
1 parent 85276e8 commit 60bcd0b

File tree

5 files changed

+45
-21
lines changed

5 files changed

+45
-21
lines changed

HISTORY

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1+
Jul. 9 2022
2+
Added an MB_PRINT_INPUT_PROMPT macro
3+
Added an MB_PRINT_INPUT_CONTENT macro
4+
Fixed a wrong return value of the mb_get_array_len function
5+
Fixed a newline bug of the shell
6+
17
Jul. 8 2022
2-
Added a mb_get_vars function to retrieve active variables
8+
Added an mb_get_vars function to retrieve active variables
39
Added a clear_vars parameter to the mb_reset function
4-
Added a mb_debug_count_stack_frames function to get the stack frame count
10+
Added an mb_debug_count_stack_frames function to get the stack frame count
511
Removed a few unused parameters
612

713
Jun. 16 2022

MY-BASIC Quick Reference.pdf

1.95 KB
Binary file not shown.

core/my_basic.c

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13540,11 +13540,8 @@ int mb_get_array_len(struct mb_interpreter_t* s, void** l, void* a, int r, int*
1354013540
int result = 0;
1354113541
_array_t* arr = 0;
1354213542

13543-
if(!s || !l) {
13544-
result = MB_FUNC_ERR;
13545-
13543+
if(!s || !l)
1354613544
goto _exit;
13547-
}
1354813545

1354913546
arr = (_array_t*)a;
1355013547
if(r < 0 || r >= arr->dimension_count) {
@@ -13814,7 +13811,7 @@ int mb_remove_coll(struct mb_interpreter_t* s, void** l, mb_value_t coll, mb_val
1381413811

1381513812
/* Tell the element count of a collection */
1381613813
int mb_count_coll(struct mb_interpreter_t* s, void** l, mb_value_t coll, int* c) {
13817-
int result = 0;
13814+
int result = MB_FUNC_OK;
1381813815
_object_t ocoll;
1381913816
#ifdef MB_ENABLE_COLLECTION_LIB
1382013817
_list_t* lst = 0;
@@ -18545,7 +18542,9 @@ static int _std_input(mb_interpreter_t* s, void** l) {
1854518542
}
1854618543
if(obj->type == _DT_STRING) {
1854718544
pmt = obj->data.string;
18545+
#if MB_PRINT_INPUT_PROMPT
1854818546
_print_string(s, obj);
18547+
#endif /* MB_PRINT_INPUT_PROMPT */
1854918548
ast = ast->next;
1855018549
obj = (_object_t*)ast->data;
1855118550
if(!_IS_SEP(obj, ',')) {
@@ -18561,10 +18560,18 @@ static int _std_input(mb_interpreter_t* s, void** l) {
1856118560
_get_inputer(s)(s, pmt, line, sizeof(line));
1856218561
obj->data.variable->data->type = _DT_INT;
1856318562
obj->data.variable->data->data.integer = (int_t)mb_strtol(line, &conv_suc, 0);
18564-
if(*conv_suc != _ZERO_CHAR) {
18563+
if(*conv_suc == _ZERO_CHAR) {
18564+
#if MB_PRINT_INPUT_CONTENT
18565+
_get_printer(s)(s, MB_INT_FMT "\n", obj->data.variable->data->data.integer);
18566+
#endif /* MB_PRINT_INPUT_CONTENT */
18567+
} else {
1856518568
obj->data.variable->data->type = _DT_REAL;
1856618569
obj->data.variable->data->data.float_point = (real_t)mb_strtod(line, &conv_suc);
18567-
if(*conv_suc != _ZERO_CHAR) {
18570+
if(*conv_suc == _ZERO_CHAR) {
18571+
#if MB_PRINT_INPUT_CONTENT
18572+
_get_printer(s)(s, MB_REAL_FMT "\n", obj->data.variable->data->data.float_point);
18573+
#endif /* MB_PRINT_INPUT_CONTENT */
18574+
} else {
1856818575
_handle_error_on_obj(s, SE_RN_INVALID_ID_USAGE, s->source_file, DON(ast), MB_FUNC_ERR, _exit, result);
1856918576
}
1857018577
}
@@ -18587,12 +18594,18 @@ static int _std_input(mb_interpreter_t* s, void** l) {
1858718594
while((len = mb_wchar_to_bytes(_WCHAR_BUF_PTR(wbuf), &_CHAR_BUF_PTR(buf), _CHARS_OF_BUF(buf))) > _CHARS_OF_BUF(buf)) {
1858818595
_RESIZE_CHAR_BUF(buf, len);
1858918596
}
18597+
#if MB_PRINT_INPUT_CONTENT
18598+
_get_printer(s)(s, "%ls\n", _WCHAR_BUF_PTR(wbuf));
18599+
#endif /* MB_PRINT_INPUT_CONTENT */
1859018600
_DISPOSE_BUF(wbuf);
1859118601
obj->data.variable->data->data.string = _HEAP_CHAR_BUF(buf);
1859218602
obj->data.variable->data->is_ref = false;
1859318603
} while(0);
1859418604
#else /* MB_CP_VC && MB_ENABLE_UNICODE */
1859518605
obj->data.variable->data->data.string = mb_memdup(line, (unsigned)(len + 1));
18606+
#if MB_PRINT_INPUT_CONTENT
18607+
_get_printer(s)(s, "%s\n", obj->data.variable->data->data.string);
18608+
#endif /* MB_PRINT_INPUT_CONTENT */
1859618609
#endif /* MB_CP_VC && MB_ENABLE_UNICODE */
1859718610
ast = ast->next;
1859818611
} else {

core/my_basic.h

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,14 @@ extern "C" {
188188
# define MB_CONVERT_TO_INT_LEVEL MB_CONVERT_TO_INT_LEVEL_ALL
189189
#endif /* MB_CONVERT_TO_INT_LEVEL */
190190

191+
#ifndef MB_PRINT_INPUT_PROMPT
192+
# define MB_PRINT_INPUT_PROMPT 1
193+
#endif /* MB_PRINT_INPUT_PROMPT */
194+
195+
#ifndef MB_PRINT_INPUT_CONTENT
196+
# define MB_PRINT_INPUT_CONTENT 0
197+
#endif /* MB_PRINT_INPUT_CONTENT */
198+
191199
#ifndef MB_PREFER_SPEED
192200
# define MB_PREFER_SPEED
193201
#endif /* MB_PREFER_SPEED */
@@ -278,15 +286,13 @@ extern "C" {
278286
#ifndef mb_stricmp
279287
# ifdef MB_CP_VC
280288
# define mb_stricmp _strcmpi
281-
# else /* MB_CP_VC */
282-
# ifdef MB_CP_BORLANDC
283-
# define mb_stricmp stricmp
284-
# elif defined MB_CP_PELLESC
285-
# define mb_stricmp _stricmp
286-
# else
287-
# define mb_stricmp strcasecmp
288-
# endif
289-
# endif /* MB_CP_VC */
289+
# elif defined MB_CP_BORLANDC
290+
# define mb_stricmp stricmp
291+
# elif defined MB_CP_PELLESC
292+
# define mb_stricmp _stricmp
293+
# else
294+
# define mb_stricmp strcasecmp
295+
# endif
290296
#endif /* mb_stricmp */
291297

292298
#ifndef mb_assert

shell/main.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -468,11 +468,10 @@ static int _append_line(const char* txt) {
468468
code->lines = (char**)realloc(code->lines, sizeof(char*) * code->size);
469469
}
470470
result = l = (int)strlen(txt);
471-
buf = (char*)malloc(l + 2);
471+
buf = (char*)malloc(l + 1);
472472
_CHECK_MEM(buf);
473473
memcpy(buf, txt, l);
474-
buf[l] = '\n';
475-
buf[l + 1] = '\0';
474+
buf[l] = '\0';
476475
code->lines[code->count++] = buf;
477476

478477
return result;

0 commit comments

Comments
 (0)