qse/ase/lsp/token.c

78 lines
1.5 KiB
C
Raw Normal View History

2005-02-04 15:39:11 +00:00
/*
2005-09-18 08:10:50 +00:00
* $Id: token.c,v 1.11 2005-09-18 08:10:50 bacon Exp $
2005-02-04 15:39:11 +00:00
*/
2005-05-28 13:34:26 +00:00
#include <xp/lsp/token.h>
2005-04-24 07:48:16 +00:00
#include <xp/bas/memory.h>
2005-02-04 15:39:11 +00:00
2005-09-18 08:10:50 +00:00
xp_lsp_token_t* xp_lsp_token_open (
xp_lsp_token_t* token, xp_word_t capacity)
2005-02-04 15:39:11 +00:00
{
2005-09-18 08:10:50 +00:00
if (token == XP_NULL) {
token = (xp_lsp_token_t*)
xp_malloc (xp_sizeof(xp_lsp_token_t));
if (token == XP_NULL) return XP_NULL;
token->__malloced = xp_true;
}
else token->__malloced = xp_false;
if (xp_lsp_name_open(&token->name, capacity) == XP_NULL) {
if (token->__malloced) xp_free (token);
2005-02-04 15:39:11 +00:00
return XP_NULL;
}
2005-09-18 08:10:50 +00:00
/*
2005-02-04 15:39:11 +00:00
token->ivalue = 0;
token->fvalue = .0;
2005-09-18 08:10:50 +00:00
*/
token->type = XP_LSP_TOKEN_END;
2005-02-04 15:39:11 +00:00
return token;
}
2005-09-18 08:10:50 +00:00
void xp_lsp_token_close (xp_lsp_token_t* token)
2005-02-04 15:39:11 +00:00
{
2005-09-18 08:10:50 +00:00
xp_lsp_name_close (&token->name);
if (token->__malloced) xp_free (token);
2005-02-04 15:39:11 +00:00
}
2005-09-18 08:10:50 +00:00
int xp_lsp_token_addc (xp_lsp_token_t* token, xp_cint_t c)
2005-02-04 15:39:11 +00:00
{
2005-09-18 08:10:50 +00:00
return xp_lsp_name_addc (&token->name, c);
}
2005-02-04 15:39:11 +00:00
2005-09-18 08:10:50 +00:00
int xp_lsp_token_adds (xp_lsp_token_t* token, const xp_char_t* s)
{
return xp_lsp_name_adds (&token->name, s);
2005-02-04 15:39:11 +00:00
}
2005-09-18 08:10:50 +00:00
void xp_lsp_token_clear (xp_lsp_token_t* token)
2005-02-04 15:39:11 +00:00
{
2005-09-18 08:10:50 +00:00
/*
token->ivalue = 0;
token->fvalue = .0;
*/
2005-02-04 15:39:11 +00:00
2005-09-18 08:10:50 +00:00
token->type = XP_LSP_TOKEN_END;
xp_lsp_name_clear (&token->name);
2005-02-04 15:39:11 +00:00
}
2005-09-18 08:10:50 +00:00
xp_char_t* xp_lsp_token_yield (xp_lsp_token_t* token, xp_word_t capacity)
2005-02-04 15:39:11 +00:00
{
2005-09-18 08:10:50 +00:00
xp_char_t* p;
2005-02-04 15:39:11 +00:00
2005-09-18 08:10:50 +00:00
p = xp_lsp_name_yield (&token->name, capacity);
if (p == XP_NULL) return XP_NULL;
2005-02-04 15:39:11 +00:00
2005-09-18 08:10:50 +00:00
/*
token->ivalue = 0;
token->fvalue = .0;
*/
token->type = XP_LSP_TOKEN_END;
return p;
2005-02-04 15:39:11 +00:00
}
2005-09-18 08:10:50 +00:00
int xp_lsp_token_compare_name (xp_lsp_token_t* token, const xp_char_t* str)
2005-02-04 15:39:11 +00:00
{
2005-09-18 08:10:50 +00:00
return xp_lsp_name_compare (&token->name, str);
2005-02-04 15:39:11 +00:00
}