|
|
@ -2,6 +2,8 @@ |
|
|
|
|
|
|
|
|
|
|
|
void fh_push_input(struct fh_thread_s *fh, struct fh_input_spec_s *newinput) |
|
|
|
void fh_push_input(struct fh_thread_s *fh, struct fh_input_spec_s *newinput) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
LOG("--- Push input spec ---"); |
|
|
|
|
|
|
|
|
|
|
|
if (newinput == NULL) { |
|
|
|
if (newinput == NULL) { |
|
|
|
LOGE("push input with NULL"); |
|
|
|
LOGE("push input with NULL"); |
|
|
|
return; |
|
|
|
return; |
|
|
@ -19,13 +21,21 @@ void fh_push_input(struct fh_thread_s *fh, struct fh_input_spec_s *newinput) |
|
|
|
memcpy(&oldinput->saved_buffer[0], &fh->heap[INPUTBUF_ADDR], INPUT_BUFFER_SIZE); |
|
|
|
memcpy(&oldinput->saved_buffer[0], &fh->heap[INPUTBUF_ADDR], INPUT_BUFFER_SIZE); |
|
|
|
oldinput->saved_inputlen = fh->inputlen; |
|
|
|
oldinput->saved_inputlen = fh->inputlen; |
|
|
|
oldinput->saved_inputptr = fh->inputptr; |
|
|
|
oldinput->saved_inputptr = fh->inputptr; |
|
|
|
|
|
|
|
// oldinput->saved_state = fh->state;
|
|
|
|
|
|
|
|
oldinput->saved_execptr = fh->execptr; |
|
|
|
newinput->previous = oldinput; |
|
|
|
newinput->previous = oldinput; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fh->inputlen = 0; |
|
|
|
|
|
|
|
fh->inputptr = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// fh_setstate(fh, FH_STATE_INTERPRET, 0);
|
|
|
|
fh->input = newinput; |
|
|
|
fh->input = newinput; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void fh_pop_input(struct fh_thread_s *fh) |
|
|
|
void fh_pop_input(struct fh_thread_s *fh) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
LOG("--- Pop input spec ---"); |
|
|
|
|
|
|
|
|
|
|
|
struct fh_input_spec_s *discarded = fh->input; |
|
|
|
struct fh_input_spec_s *discarded = fh->input; |
|
|
|
fh->input = NULL; |
|
|
|
fh->input = NULL; |
|
|
|
|
|
|
|
|
|
|
@ -38,6 +48,8 @@ void fh_pop_input(struct fh_thread_s *fh) |
|
|
|
memcpy(&fh->heap[INPUTBUF_ADDR], &restored->saved_buffer[0], INPUT_BUFFER_SIZE); |
|
|
|
memcpy(&fh->heap[INPUTBUF_ADDR], &restored->saved_buffer[0], INPUT_BUFFER_SIZE); |
|
|
|
fh->inputlen = restored->saved_inputlen; |
|
|
|
fh->inputlen = restored->saved_inputlen; |
|
|
|
fh->inputptr = restored->saved_inputptr; |
|
|
|
fh->inputptr = restored->saved_inputptr; |
|
|
|
|
|
|
|
fh->execptr = restored->saved_execptr; |
|
|
|
|
|
|
|
// fh_setstate(fh, restored->saved_state, 0);
|
|
|
|
|
|
|
|
|
|
|
|
if (discarded->free_self) { |
|
|
|
if (discarded->free_self) { |
|
|
|
discarded->free_self(discarded); |
|
|
|
discarded->free_self(discarded); |
|
|
@ -87,12 +99,13 @@ static bool file_refill(struct fh_thread_s *fh, struct fh_input_spec_s *spec) |
|
|
|
{ |
|
|
|
{ |
|
|
|
struct file_input_spec *fis = (struct file_input_spec *) spec; |
|
|
|
struct file_input_spec *fis = (struct file_input_spec *) spec; |
|
|
|
fh_input_memmove_leftovers(fh); |
|
|
|
fh_input_memmove_leftovers(fh); |
|
|
|
uint32_t space_left = INPUT_BUFFER_SIZE - fh->inputlen; |
|
|
|
uint32_t space_left = INPUT_BUFFER_SIZE - fh->inputlen - 1; |
|
|
|
char *wp = (char *) inputbuf_at(fh, fh->inputptr); |
|
|
|
char *wp = (char *) inputbuf_at(fh, fh->inputptr); |
|
|
|
LOG("spec %p, fgets %d", spec, space_left); |
|
|
|
LOG("spec %p, fgets %d", spec, space_left); |
|
|
|
if (fgets(wp, (int) space_left, fis->file)) { |
|
|
|
if (fgets(wp, (int) space_left, fis->file)) { |
|
|
|
spec->linenum++; |
|
|
|
spec->linenum++; |
|
|
|
fh->inputlen = strnlen(wp, INPUT_BUFFER_SIZE); |
|
|
|
fh->inputlen = strnlen(wp, INPUT_BUFFER_SIZE); |
|
|
|
|
|
|
|
LOG("read %d bytes from file", fh->inputlen); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
return fh->inputptr > fh->inputlen; // return false only if there is nothing left
|
|
|
|
return fh->inputptr > fh->inputlen; // return false only if there is nothing left
|
|
|
@ -103,7 +116,7 @@ static bool str_refill(struct fh_thread_s *fh, struct fh_input_spec_s *spec) |
|
|
|
{ |
|
|
|
{ |
|
|
|
struct string_input_spec *fis = (struct string_input_spec *) spec; |
|
|
|
struct string_input_spec *fis = (struct string_input_spec *) spec; |
|
|
|
fh_input_memmove_leftovers(fh); |
|
|
|
fh_input_memmove_leftovers(fh); |
|
|
|
uint32_t space_left = INPUTBUF_ADDR - fh->inputlen; |
|
|
|
uint32_t space_left = INPUT_BUFFER_SIZE - fh->inputlen - 1; |
|
|
|
char *wp = (char *) inputbuf_at(fh, fh->inputptr); |
|
|
|
char *wp = (char *) inputbuf_at(fh, fh->inputptr); |
|
|
|
|
|
|
|
|
|
|
|
uint32_t chars_remaining_in_string = fis->len - fis->readpos; |
|
|
|
uint32_t chars_remaining_in_string = fis->len - fis->readpos; |
|
|
@ -113,6 +126,9 @@ static bool str_refill(struct fh_thread_s *fh, struct fh_input_spec_s *spec) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
memcpy(wp, &fis->str[fis->readpos], space_left); |
|
|
|
memcpy(wp, &fis->str[fis->readpos], space_left); |
|
|
|
|
|
|
|
*(wp + space_left) = 0; |
|
|
|
|
|
|
|
fis->readpos += space_left; |
|
|
|
|
|
|
|
fh->inputlen += space_left; |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|