|
|
@ -20,6 +20,7 @@ enum fh_error fh_push_input(struct fh_thread_s *fh, struct fh_input_spec_s *newi |
|
|
|
newinput->previous = oldinput; |
|
|
|
newinput->previous = oldinput; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fh->execptr = MAGICADDR_EXEC_INTERACTIVE; |
|
|
|
fh->inputlen = 0; |
|
|
|
fh->inputlen = 0; |
|
|
|
fh->inputptr = 0; |
|
|
|
fh->inputptr = 0; |
|
|
|
|
|
|
|
|
|
|
@ -86,17 +87,17 @@ void fh_input_memmove_leftovers(struct fh_thread_s *fh) |
|
|
|
// something is left
|
|
|
|
// something is left
|
|
|
|
uint32_t remains = fh->inputlen - fh->inputptr; |
|
|
|
uint32_t remains = fh->inputlen - fh->inputptr; |
|
|
|
if (remains > 0) { |
|
|
|
if (remains > 0) { |
|
|
|
LOG("Refill, reuse %d bytes left in buffer", remains); |
|
|
|
//LOG("Refill, reuse %d bytes left in buffer", remains);
|
|
|
|
memmove(inputbuf_at(fh, 0), inputbuf_at(fh, fh->inputptr), remains); |
|
|
|
memmove(inputbuf_at(fh, 0), inputbuf_at(fh, fh->inputptr), remains); |
|
|
|
fh->inputptr = 0; |
|
|
|
fh->inputptr = 0; |
|
|
|
fh->inputlen = remains; |
|
|
|
fh->inputlen = remains; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
LOG("Refill, nothing reused (1)"); |
|
|
|
//LOG("Refill, nothing reused (1)");
|
|
|
|
fh->inputptr = 0; |
|
|
|
fh->inputptr = 0; |
|
|
|
fh->inputlen = 0; |
|
|
|
fh->inputlen = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
LOG("Refill, nothing reused (2)"); |
|
|
|
//LOG("Refill, nothing reused (2)");
|
|
|
|
fh->inputptr = 0; |
|
|
|
fh->inputptr = 0; |
|
|
|
fh->inputlen = 0; |
|
|
|
fh->inputlen = 0; |
|
|
|
} |
|
|
|
} |
|
|
@ -108,11 +109,11 @@ static bool file_refill(struct fh_thread_s *fh, struct fh_input_spec_s *spec) |
|
|
|
fh_input_memmove_leftovers(fh); |
|
|
|
fh_input_memmove_leftovers(fh); |
|
|
|
uint32_t space_left = INPUT_BUFFER_SIZE - fh->inputlen - 1; |
|
|
|
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); |
|
|
|
//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
|
|
|
@ -174,6 +175,7 @@ struct fh_input_spec_s *fh_create_input_from_filestruct(FILE *f, const char *cwd |
|
|
|
return NULL; |
|
|
|
return NULL; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LOG("Input for FILE, cwd: %s", cwd); |
|
|
|
fis->spec.free_self = free_filespec; |
|
|
|
fis->spec.free_self = free_filespec; |
|
|
|
fis->spec.refill_input_buffer = file_refill; |
|
|
|
fis->spec.refill_input_buffer = file_refill; |
|
|
|
fis->file = f; |
|
|
|
fis->file = f; |
|
|
@ -221,6 +223,8 @@ struct fh_input_spec_s *fh_create_input_from_string(char *str, size_t len, const |
|
|
|
return NULL; |
|
|
|
return NULL; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LOG("Evaluating: \"%.*s\"", (int)len, str); |
|
|
|
|
|
|
|
|
|
|
|
sis->spec.free_self = free_strspec; |
|
|
|
sis->spec.free_self = free_strspec; |
|
|
|
sis->spec.refill_input_buffer = str_refill; |
|
|
|
sis->spec.refill_input_buffer = str_refill; |
|
|
|
sis->str = str; |
|
|
|
sis->str = str; |
|
|
|