2005-05-22 10:32:37 +00:00
|
|
|
/*
|
2007-03-22 11:21:59 +00:00
|
|
|
* $Id: token.c,v 1.11 2007-03-22 11:19:28 bacon Exp $
|
2005-05-22 10:32:37 +00:00
|
|
|
*/
|
|
|
|
|
2007-03-22 11:21:59 +00:00
|
|
|
#include <ase/stx/token.h>
|
|
|
|
#include <ase/stx/misc.h>
|
2005-05-22 10:32:37 +00:00
|
|
|
|
2007-03-22 11:21:59 +00:00
|
|
|
ase_stx_token_t* ase_stx_token_open (
|
|
|
|
ase_stx_token_t* token, ase_word_t capacity)
|
2005-05-22 10:32:37 +00:00
|
|
|
{
|
2007-03-22 11:21:59 +00:00
|
|
|
if (token == ASE_NULL) {
|
|
|
|
token = (ase_stx_token_t*)
|
|
|
|
ase_malloc (ase_sizeof(ase_stx_token_t));
|
|
|
|
if (token == ASE_NULL) return ASE_NULL;
|
|
|
|
token->__dynamic = ase_true;
|
2005-05-22 10:32:37 +00:00
|
|
|
}
|
2007-03-22 11:21:59 +00:00
|
|
|
else token->__dynamic = ase_false;
|
2005-05-22 10:32:37 +00:00
|
|
|
|
2007-03-22 11:21:59 +00:00
|
|
|
if (ase_stx_name_open(&token->name, capacity) == ASE_NULL) {
|
|
|
|
if (token->__dynamic) ase_free (token);
|
|
|
|
return ASE_NULL;
|
2005-05-22 10:32:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
token->ivalue = 0;
|
|
|
|
token->fvalue = .0;
|
|
|
|
*/
|
2007-03-22 11:21:59 +00:00
|
|
|
token->type = ASE_STX_TOKEN_END;
|
2005-05-22 10:32:37 +00:00
|
|
|
return token;
|
|
|
|
}
|
|
|
|
|
2007-03-22 11:21:59 +00:00
|
|
|
void ase_stx_token_close (ase_stx_token_t* token)
|
2005-05-22 10:32:37 +00:00
|
|
|
{
|
2007-03-22 11:21:59 +00:00
|
|
|
ase_stx_name_close (&token->name);
|
|
|
|
if (token->__dynamic) ase_free (token);
|
2005-05-22 10:32:37 +00:00
|
|
|
}
|
|
|
|
|
2007-03-22 11:21:59 +00:00
|
|
|
int ase_stx_token_addc (ase_stx_token_t* token, ase_cint_t c)
|
2005-05-22 10:32:37 +00:00
|
|
|
{
|
2007-03-22 11:21:59 +00:00
|
|
|
return ase_stx_name_addc (&token->name, c);
|
2005-05-22 10:32:37 +00:00
|
|
|
}
|
|
|
|
|
2007-03-22 11:21:59 +00:00
|
|
|
int ase_stx_token_adds (ase_stx_token_t* token, const ase_char_t* s)
|
2005-06-12 16:07:23 +00:00
|
|
|
{
|
2007-03-22 11:21:59 +00:00
|
|
|
return ase_stx_name_adds (&token->name, s);
|
2005-06-12 16:07:23 +00:00
|
|
|
}
|
|
|
|
|
2007-03-22 11:21:59 +00:00
|
|
|
void ase_stx_token_clear (ase_stx_token_t* token)
|
2005-05-22 10:32:37 +00:00
|
|
|
{
|
2005-05-22 13:41:14 +00:00
|
|
|
/*
|
2005-06-12 16:22:47 +00:00
|
|
|
token->ivalue = 0;
|
|
|
|
token->fvalue = .0;
|
2005-05-22 13:41:14 +00:00
|
|
|
*/
|
2005-05-22 10:32:37 +00:00
|
|
|
|
2007-03-22 11:21:59 +00:00
|
|
|
token->type = ASE_STX_TOKEN_END;
|
|
|
|
ase_stx_name_clear (&token->name);
|
2005-05-22 10:32:37 +00:00
|
|
|
}
|
|
|
|
|
2007-03-22 11:21:59 +00:00
|
|
|
ase_char_t* ase_stx_token_yield (ase_stx_token_t* token, ase_word_t capacity)
|
2005-05-22 10:32:37 +00:00
|
|
|
{
|
2007-03-22 11:21:59 +00:00
|
|
|
ase_char_t* p;
|
2005-06-12 15:46:02 +00:00
|
|
|
|
2007-03-22 11:21:59 +00:00
|
|
|
p = ase_stx_name_yield (&token->name, capacity);
|
|
|
|
if (p == ASE_NULL) return ASE_NULL;
|
2005-05-22 10:32:37 +00:00
|
|
|
|
2005-06-12 16:22:47 +00:00
|
|
|
/*
|
|
|
|
token->ivalue = 0;
|
|
|
|
token->fvalue = .0;
|
|
|
|
*/
|
2007-03-22 11:21:59 +00:00
|
|
|
token->type = ASE_STX_TOKEN_END;
|
2005-06-12 16:22:47 +00:00
|
|
|
return p;
|
2005-05-22 10:32:37 +00:00
|
|
|
}
|
|
|
|
|
2007-03-22 11:21:59 +00:00
|
|
|
int ase_stx_token_compare_name (ase_stx_token_t* token, const ase_char_t* str)
|
2005-05-22 10:32:37 +00:00
|
|
|
{
|
2007-03-22 11:21:59 +00:00
|
|
|
return ase_stx_name_compare (&token->name, str);
|
2005-05-22 10:32:37 +00:00
|
|
|
}
|