qse/ase/lsp/token.c

78 lines
1.6 KiB
C
Raw Normal View History

2005-02-04 15:39:11 +00:00
/*
2006-10-22 13:10:46 +00:00
* $Id: token.c,v 1.13 2006-10-22 13:10:46 bacon Exp $
2005-02-04 15:39:11 +00:00
*/
2006-10-22 13:10:46 +00:00
#include <sse/lsp/token.h>
#include <sse/bas/memory.h>
2005-02-04 15:39:11 +00:00
2006-10-22 13:10:46 +00:00
sse_lsp_token_t* sse_lsp_token_open (
sse_lsp_token_t* token, sse_word_t capacity)
2005-02-04 15:39:11 +00:00
{
2006-10-22 13:10:46 +00:00
if (token == SSE_NULL) {
token = (sse_lsp_token_t*)
sse_malloc (sse_sizeof(sse_lsp_token_t));
if (token == SSE_NULL) return SSE_NULL;
token->__dynamic = sse_true;
2005-09-18 08:10:50 +00:00
}
2006-10-22 13:10:46 +00:00
else token->__dynamic = sse_false;
2005-09-18 08:10:50 +00:00
2006-10-22 13:10:46 +00:00
if (sse_lsp_name_open(&token->name, capacity) == SSE_NULL) {
if (token->__dynamic) sse_free (token);
return SSE_NULL;
2005-02-04 15:39:11 +00:00
}
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
*/
2006-10-22 13:10:46 +00:00
token->type = SSE_LSP_TOKEN_END;
2005-02-04 15:39:11 +00:00
return token;
}
2006-10-22 13:10:46 +00:00
void sse_lsp_token_close (sse_lsp_token_t* token)
2005-02-04 15:39:11 +00:00
{
2006-10-22 13:10:46 +00:00
sse_lsp_name_close (&token->name);
if (token->__dynamic) sse_free (token);
2005-02-04 15:39:11 +00:00
}
2006-10-22 13:10:46 +00:00
int sse_lsp_token_addc (sse_lsp_token_t* token, sse_cint_t c)
2005-02-04 15:39:11 +00:00
{
2006-10-22 13:10:46 +00:00
return sse_lsp_name_addc (&token->name, c);
2005-09-18 08:10:50 +00:00
}
2005-02-04 15:39:11 +00:00
2006-10-22 13:10:46 +00:00
int sse_lsp_token_adds (sse_lsp_token_t* token, const sse_char_t* s)
2005-09-18 08:10:50 +00:00
{
2006-10-22 13:10:46 +00:00
return sse_lsp_name_adds (&token->name, s);
2005-02-04 15:39:11 +00:00
}
2006-10-22 13:10:46 +00:00
void sse_lsp_token_clear (sse_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
2006-10-22 13:10:46 +00:00
token->type = SSE_LSP_TOKEN_END;
sse_lsp_name_clear (&token->name);
2005-02-04 15:39:11 +00:00
}
2006-10-22 13:10:46 +00:00
sse_char_t* sse_lsp_token_yield (sse_lsp_token_t* token, sse_word_t capacity)
2005-02-04 15:39:11 +00:00
{
2006-10-22 13:10:46 +00:00
sse_char_t* p;
2005-02-04 15:39:11 +00:00
2006-10-22 13:10:46 +00:00
p = sse_lsp_name_yield (&token->name, capacity);
if (p == SSE_NULL) return SSE_NULL;
2005-02-04 15:39:11 +00:00
2005-09-18 08:10:50 +00:00
/*
token->ivalue = 0;
token->fvalue = .0;
*/
2006-10-22 13:10:46 +00:00
token->type = SSE_LSP_TOKEN_END;
2005-09-18 08:10:50 +00:00
return p;
2005-02-04 15:39:11 +00:00
}
2006-10-22 13:10:46 +00:00
int sse_lsp_token_compare_name (sse_lsp_token_t* token, const sse_char_t* str)
2005-02-04 15:39:11 +00:00
{
2006-10-22 13:10:46 +00:00
return sse_lsp_name_compare (&token->name, str);
2005-02-04 15:39:11 +00:00
}