#include "aplwc_internal.h" enum aplwc_rc aplwc_new(struct aplwc **p, uint8_t *data, size_t size) { struct memory m; m = memory_init(data, size); *p = memory_alloc_aplwc(&m); if(*p == NULL) return APLWC_OUT_OF_MEMORY; (*p)->memory = m; return APLWC_OK; } void aplwc_destroy(struct aplwc *p) { if(p) memory_free_aplwc(&p->memory, p); } const char * aplwc_errstr_rc(enum aplwc_rc rc) { switch(rc){ case APLWC_OK: return ""; case APLWC_OUT_OF_MEMORY: return "Out of memory"; case APLWC_NOT_YET_IMPLEMENTED: return "Not yet implemented"; case APLWC_INVALID_UTF8: return "Invalid UTF-8"; case APLWC_INVALID_SYNTAX: return "Invalid syntax"; default: return "(unable to produce error string)"; } } const char * aplwc_errstr(struct aplwc *aplwc) { enum { BUF_SIZE = 256 }; const char *err; enum aplwc_rc rc; err = NULL; rc = aplwc ? aplwc->last_error : APLWC_RC_LAST+1; err = aplwc_errstr_rc(rc); return err; } enum aplwc_rc aplwc_last_error(struct aplwc *aplwc) { return aplwc->last_error; } struct aplwc_line * aplwc_read(struct aplwc *aplwc, const char *line) { struct string *text; struct token_list *tokens; struct aplwc_line *ret; text = chars_to_string(aplwc, line); if(text == NULL) return NULL; tokens = scan_line(aplwc, text); if(tokens == NULL) return NULL; ret = memory_alloc_aplwc_line(&aplwc->memory); if(ret == NULL){ aplwc->last_error = APLWC_OUT_OF_MEMORY; return NULL; } ret->aplwc = aplwc; ret->text = text; ret->tokens = tokens; return ret; } void aplwc_free_line(struct aplwc_line *line) { if(line == NULL) return; memory_free_aplwc_line(&line->aplwc->memory, line); } enum aplwc_rc aplwc_eval(struct aplwc_line *line) { line->aplwc->last_error = APLWC_OK; eval_line(line); return line->aplwc->last_error; }