|
|
|
/**
|
|
|
|
* TODO file description
|
|
|
|
*
|
|
|
|
* Created on 2021/11/21.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef FORTH_FH_INPUT_H
|
|
|
|
#define FORTH_FH_INPUT_H
|
|
|
|
|
|
|
|
struct fh_thread_s;
|
|
|
|
struct fh_input_spec_s;
|
|
|
|
|
|
|
|
/** Refill the input buffer, returns false on failure / EOF */
|
|
|
|
typedef bool (*fh_input_refill_t)(struct fh_thread_s *fh, struct fh_input_spec_s *spec);
|
|
|
|
/** Spec free func */
|
|
|
|
typedef void (*fh_input_free_t)(void *spec);
|
|
|
|
|
|
|
|
struct fh_input_spec_s {
|
|
|
|
struct fh_input_spec_s *previous;
|
|
|
|
fh_input_refill_t refill_input_buffer;
|
|
|
|
fh_input_free_t free_self;
|
|
|
|
uint32_t linenum;
|
|
|
|
char *cwd; // CWD of the input, used for relative includes. malloc'd (strdup)
|
|
|
|
|
|
|
|
// saved values, filled when pushing
|
|
|
|
char saved_buffer[INPUT_BUFFER_SIZE];
|
|
|
|
uint32_t saved_inputptr;
|
|
|
|
uint32_t saved_inputlen;
|
|
|
|
uint32_t saved_execptr;
|
|
|
|
enum fh_state saved_state;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Push current input spec and state, replace with new one
|
|
|
|
*/
|
|
|
|
enum fh_error fh_push_input(struct fh_thread_s *fh, struct fh_input_spec_s *newinput);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Discard current input spec, restore previous.
|
|
|
|
* fh->input will be NULL if this was the topmost one
|
|
|
|
*/
|
|
|
|
enum fh_error fh_pop_input(struct fh_thread_s *fh);
|
|
|
|
|
|
|
|
struct fh_input_spec_s *fh_create_input_from_filename(char *path);
|
|
|
|
struct fh_input_spec_s *fh_create_input_from_filestruct(FILE *f, const char *path);
|
|
|
|
struct fh_input_spec_s *fh_create_input_from_string(char *str, size_t len, const char *cwd); // cwd is strduped.
|
|
|
|
void fh_input_teardown(struct fh_thread_s *fh);
|
|
|
|
|
|
|
|
#endif //FORTH_FH_INPUT_H
|