2005-02-04 15:39:11 +00:00
|
|
|
/*
|
2005-09-18 03:57:26 +00:00
|
|
|
* $Id: lsp.c,v 1.3 2005-09-18 03:57:26 bacon Exp $
|
2005-02-04 15:39:11 +00:00
|
|
|
*/
|
|
|
|
|
2005-09-18 03:57:26 +00:00
|
|
|
#include <xp/lsp/lsp.h>
|
2005-04-24 07:48:16 +00:00
|
|
|
#include <xp/bas/memory.h>
|
|
|
|
#include <xp/bas/assert.h>
|
2005-02-04 15:39:11 +00:00
|
|
|
|
2005-09-18 03:57:26 +00:00
|
|
|
xp_lsp_t* xp_lsp_open (xp_lsp_t* lsp,
|
|
|
|
xp_size_t mem_ubound, xp_size_t mem_ubound_inc)
|
2005-02-04 15:39:11 +00:00
|
|
|
{
|
2005-09-17 17:42:21 +00:00
|
|
|
if (lsp == XP_NULL) {
|
2005-09-18 03:57:26 +00:00
|
|
|
lsp = (xp_lsp_t*)xp_malloc(sizeofxp_lsp_t));
|
2005-09-17 17:42:21 +00:00
|
|
|
if (lsp == XP_NULL) return lsp;
|
|
|
|
lsp->__malloced = xp_true;
|
|
|
|
}
|
|
|
|
else lsp->__malloced = xp_false;
|
2005-02-04 15:39:11 +00:00
|
|
|
|
2005-09-18 03:57:26 +00:00
|
|
|
lsp->token = xp_lsp_token_new (256);
|
2005-02-04 15:39:11 +00:00
|
|
|
if (lsp->token == XP_NULL) {
|
2005-02-04 16:00:37 +00:00
|
|
|
xp_free (lsp);
|
2005-02-04 15:39:11 +00:00
|
|
|
return XP_NULL;
|
|
|
|
}
|
|
|
|
|
2005-02-04 16:00:37 +00:00
|
|
|
lsp->error = XP_LISP_ERR_NONE;
|
2005-02-04 15:39:11 +00:00
|
|
|
//lsp->opt_undef_symbol = 1;
|
|
|
|
lsp->opt_undef_symbol = 0;
|
|
|
|
|
2005-05-30 07:19:09 +00:00
|
|
|
lsp->curc = XP_CHAR_EOF;
|
2005-02-04 15:39:11 +00:00
|
|
|
lsp->creader = XP_NULL;
|
|
|
|
lsp->creader_extra = XP_NULL;
|
|
|
|
lsp->creader_just_set = 0;
|
2005-02-04 16:00:37 +00:00
|
|
|
lsp->outstream = xp_stdout;
|
2005-02-04 15:39:11 +00:00
|
|
|
|
2005-09-18 03:57:26 +00:00
|
|
|
lsp->mem = xp_lsp_mem_new (mem_ubound, mem_ubound_inc);
|
2005-02-04 15:39:11 +00:00
|
|
|
if (lsp->mem == XP_NULL) {
|
2005-09-18 03:57:26 +00:00
|
|
|
xp_lsp_token_free (lsp->token);
|
|
|
|
if (lsp->__malloced) xp_free (lsp);
|
2005-02-04 15:39:11 +00:00
|
|
|
return XP_NULL;
|
|
|
|
}
|
|
|
|
|
2005-09-18 03:57:26 +00:00
|
|
|
if (xp_lsp_add_prims (lsp->mem) == -1) {
|
|
|
|
xp_lsp_mem_free (lsp->mem);
|
|
|
|
xp_lsp_token_free (lsp->token);
|
|
|
|
if (lsp->__malloced) xp_free (lsp);
|
2005-02-04 15:39:11 +00:00
|
|
|
return XP_NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return lsp;
|
|
|
|
}
|
|
|
|
|
2005-09-18 03:57:26 +00:00
|
|
|
void xp_lsp_close (xp_lsp_t* lsp)
|
2005-02-04 15:39:11 +00:00
|
|
|
{
|
2005-02-05 05:18:20 +00:00
|
|
|
xp_assert (lsp != XP_NULL);
|
2005-09-18 03:57:26 +00:00
|
|
|
xp_lsp_mem_free (lsp->mem);
|
|
|
|
xp_lsp_token_free (lsp->token);
|
2005-09-17 17:42:21 +00:00
|
|
|
if (lsp->__malloced) xp_free (lsp);
|
2005-02-04 15:39:11 +00:00
|
|
|
}
|
|
|
|
|
2005-09-17 17:50:45 +00:00
|
|
|
intxp_lsp_error xp_lsp_t* lsp, xp_char_t* buf, xp_size_t size)
|
2005-02-04 15:39:11 +00:00
|
|
|
{
|
|
|
|
if (buf != XP_NULL || size == 0) return lsp->error;
|
|
|
|
|
|
|
|
// TODO:...
|
|
|
|
/*
|
|
|
|
switch (lsp->error) {
|
|
|
|
|
|
|
|
default:
|
2005-09-17 17:50:45 +00:00
|
|
|
xp_lsp_copy_string (buf, size, "unknown error");
|
2005-02-04 15:39:11 +00:00
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
return lsp->error;
|
|
|
|
}
|