WIP. Somewhere in between the init of basic_cmd_run and basic_cmd_list calls to _cputs stop working with constant character string pointers and only work with pointers off the heap.
This commit is contained in:
82
src/basic.c
82
src/basic.c
@@ -42,27 +42,37 @@ void basic_cmd_rem(void *expr)
|
||||
void basic_cmd_list(void *data)
|
||||
{
|
||||
int i = 0;
|
||||
int x = 0;
|
||||
int limit = basic_last_stored_lineno;
|
||||
char *lineptr = NULL;
|
||||
|
||||
i = 0;
|
||||
/* I don't know why, but somehow, this makes the interspersed _cputs() calls below work.
|
||||
* Take this out, and those lines stop working.
|
||||
*
|
||||
* WHAT. THE. FUCK.
|
||||
*
|
||||
*
|
||||
* memcpy((char *)&const_string_test, (char *)" \0", strlen(" \0"));
|
||||
* _cputs((char *)&const_string_test);
|
||||
*/
|
||||
memcpy((char *)&const_string_test, (char *)"OMG WTF BBQ\n\0", strlen("OMG WTF BBQ\n\0"));
|
||||
_cputs((char *)&const_string_test);
|
||||
/* 12 characters of nothing? This does the same thing as the cputs above.
|
||||
* But cputs is still broken after this. It's the memcpy that is fixing whatever is wrong.
|
||||
*/
|
||||
/*for ( i = 0; i < 12; i++ ) {
|
||||
_putch(' ');
|
||||
advanceCursor();
|
||||
}*/
|
||||
for ( i = 0; i <= limit ; i++ ) {
|
||||
lineptr = basic_memory_line_address(i);
|
||||
if ( lineptr == NULL ) {
|
||||
continue;
|
||||
}
|
||||
if ( (char)*lineptr != 0x00 ) {
|
||||
if ( basic_memory_lines[i][0] != 0 ) {
|
||||
itoa(i+1, (char *)&decimal);
|
||||
_cputs((char *)&decimal);
|
||||
_cputs(" WTF");
|
||||
_cputs(lineptr);
|
||||
_cputs("BBQ\n");
|
||||
_putch(' ');
|
||||
advanceCursor();
|
||||
_cputs(basic_memory_line_address(i));
|
||||
_putch('\n');
|
||||
_cursor_x = 80;
|
||||
advanceCursor();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -86,9 +96,9 @@ void basic_cmd_run(void *data)
|
||||
char *lineptr;
|
||||
for ( i = 0; i <= basic_last_stored_lineno ; i++ ) {
|
||||
basic_errno = 0;
|
||||
lineptr = basic_memory_line_address(i);
|
||||
if ( (char)*lineptr != 0x00 ) {
|
||||
rc = basic_run_line_v2(lineptr, 0);
|
||||
/*lineptr = basic_memory_line_address(i);*/
|
||||
if ( basic_memory_lines[i][0] != 0x00 ) {
|
||||
rc = basic_run_line_v2((char *)basic_memory_lines[i], 1);
|
||||
if ( rc != 0 || basic_errno != 0 ) {
|
||||
_cputs("Error at Line ");
|
||||
itoa(i+1, (char *)&decimal);
|
||||
@@ -134,20 +144,21 @@ char *_tokenize(char *ptr, char *token)
|
||||
|
||||
memset(&_tokenizer_value, 0x00, BASIC_TOKENIZER_MAX_LENGTH);
|
||||
while ( *ptr != 0x0 ) {
|
||||
tokenptr = token;
|
||||
for ( i = 0 ; i < numtokens; i++) {
|
||||
if ( *ptr == *(tokenptr + i)) {
|
||||
if ( len == 0 ) {
|
||||
len = 1;
|
||||
ptr += 1;
|
||||
}
|
||||
goto _tokenize_copy;
|
||||
}
|
||||
/*for ( tokenptr = token ; *tokenptr != 0x00; tokenptr += 1) {
|
||||
if ( *ptr == *tokenptr) {
|
||||
goto _tokenize_copy;*/
|
||||
if ( *ptr == ' ' ) {
|
||||
break;
|
||||
}
|
||||
/*}*/
|
||||
ptr += 1;
|
||||
len += 1;
|
||||
}
|
||||
_tokenize_copy:
|
||||
if ( len == 0 ) {
|
||||
len = 1;
|
||||
ptr += 1;
|
||||
}
|
||||
if ( len > BASIC_TOKENIZER_MAX_LENGTH ) {
|
||||
basic_errno = BASIC_ERR_SYNTAX_TOKEN_LENGTH;
|
||||
return NULL;
|
||||
@@ -192,9 +203,10 @@ int basic_memory_line_store(char *content, int lineno)
|
||||
* through to LIST those lines later we may find garbage. Let's clean it up.
|
||||
*/
|
||||
for ( i = basic_last_stored_lineno+1; i <= lineno ; i++ ) {
|
||||
ptr = basic_memory_line_address(i);
|
||||
/* We don't need to zero the entire string, just the first character, don't waste time */
|
||||
memset(ptr, 0x00, BASIC_MAX_LINE_LENGTH);
|
||||
basic_memory_lines[i][0] = 0x00;
|
||||
/*ptr = basic_memory_line_address(i);*/
|
||||
/*memset(ptr, 0x00, BASIC_MAX_LINE_LENGTH);*/
|
||||
}
|
||||
}
|
||||
lineno -= 1;
|
||||
@@ -246,6 +258,7 @@ int basic_run_line_v2(char *codeline, int repl_mode)
|
||||
|
||||
/* Report errors */
|
||||
if ( basic_errno != 0 ) {
|
||||
/*_cputs(token);*/
|
||||
basic_report_error("Parsing error: ");
|
||||
}
|
||||
|
||||
@@ -289,11 +302,10 @@ void basic_repl(void)
|
||||
char keybuff[512];
|
||||
int i;
|
||||
char *ptr;
|
||||
char *token;
|
||||
|
||||
blankScreen();
|
||||
setCursorPosition(0, 0);
|
||||
_cputs("Piquant Basic v0.1\n");
|
||||
_cputs("READY\n");
|
||||
|
||||
basic_repl_mode = 1;
|
||||
basic_memory_line_store("LIST", 10);
|
||||
@@ -301,13 +313,29 @@ void basic_repl(void)
|
||||
basic_memory_line_store("PRINT WORLD\n", 30);
|
||||
basic_memory_line_store("PRINT GOODBYE\n", 40);
|
||||
|
||||
_cputs("Piquant Basic v0.1\n");
|
||||
_cputs("READY\n");
|
||||
|
||||
while ( 1 ) {
|
||||
basic_errno = 0;
|
||||
if ( basic_repl_mode == 1 ) {
|
||||
basic_cmd_run(NULL);
|
||||
/*basic_cmd_list(NULL);
|
||||
ptr = _tokenize((char *)&basic_memory_lines[19], " ");
|
||||
token = tokenizer_token();
|
||||
basic_cmd_print(ptr);
|
||||
ptr = _tokenize((char *)&basic_memory_lines[29], " ");
|
||||
token = tokenizer_token();
|
||||
basic_cmd_print(ptr);
|
||||
ptr = _tokenize((char *)&basic_memory_lines[39], " ");
|
||||
token = tokenizer_token();
|
||||
basic_cmd_print(ptr);
|
||||
basic_run_line_v2((char *)&basic_memory_lines[19], 1);
|
||||
basic_run_line_v2((char *)&basic_memory_lines[29], 1);
|
||||
basic_run_line_v2((char *)&basic_memory_lines[39], 1);*/
|
||||
basic_repl_mode = 0;
|
||||
}
|
||||
_cputs("> ");
|
||||
_cputs("\n> ");
|
||||
|
||||
/* Read */
|
||||
memset((void *)&keybuff, 0x00, 512);
|
||||
|
||||
Reference in New Issue
Block a user