qse/ase/stx/token.c

78 lines
1.5 KiB
C
Raw Normal View History

2005-05-22 10:32:37 +00:00
/*
2005-12-05 15:11:29 +00:00
* $Id: token.c,v 1.10 2005-12-05 15:11:29 bacon Exp $
2005-05-22 10:32:37 +00:00
*/
#include <xp/stx/token.h>
#include <xp/stx/misc.h>
2005-05-30 15:01:01 +00:00
xp_stx_token_t* xp_stx_token_open (
2005-06-08 16:05:41 +00:00
xp_stx_token_t* token, xp_word_t capacity)
2005-05-22 10:32:37 +00:00
{
if (token == XP_NULL) {
token = (xp_stx_token_t*)
2005-06-08 16:05:41 +00:00
xp_malloc (xp_sizeof(xp_stx_token_t));
2005-05-22 10:32:37 +00:00
if (token == XP_NULL) return XP_NULL;
2005-12-05 15:11:29 +00:00
token->__dynamic = xp_true;
2005-05-22 10:32:37 +00:00
}
2005-12-05 15:11:29 +00:00
else token->__dynamic = xp_false;
2005-05-22 10:32:37 +00:00
2005-06-12 16:22:47 +00:00
if (xp_stx_name_open(&token->name, capacity) == XP_NULL) {
2005-12-05 15:11:29 +00:00
if (token->__dynamic) xp_free (token);
2005-06-12 16:22:47 +00:00
return XP_NULL;
2005-05-22 10:32:37 +00:00
}
/*
token->ivalue = 0;
token->fvalue = .0;
*/
2005-06-12 16:22:47 +00:00
token->type = XP_STX_TOKEN_END;
2005-05-22 10:32:37 +00:00
return token;
}
void xp_stx_token_close (xp_stx_token_t* token)
{
2005-06-12 16:22:47 +00:00
xp_stx_name_close (&token->name);
2005-12-05 15:11:29 +00:00
if (token->__dynamic) xp_free (token);
2005-05-22 10:32:37 +00:00
}
2005-06-08 16:05:41 +00:00
int xp_stx_token_addc (xp_stx_token_t* token, xp_cint_t c)
2005-05-22 10:32:37 +00:00
{
2005-06-12 16:22:47 +00:00
return xp_stx_name_addc (&token->name, c);
2005-05-22 10:32:37 +00:00
}
2005-06-12 16:07:23 +00:00
int xp_stx_token_adds (xp_stx_token_t* token, const xp_char_t* s)
{
2005-06-12 16:22:47 +00:00
return xp_stx_name_adds (&token->name, s);
2005-06-12 16:07:23 +00:00
}
2005-05-22 10:32:37 +00:00
void xp_stx_token_clear (xp_stx_token_t* token)
{
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
2005-06-12 16:22:47 +00:00
token->type = XP_STX_TOKEN_END;
xp_stx_name_clear (&token->name);
2005-05-22 10:32:37 +00:00
}
2005-06-08 16:05:41 +00:00
xp_char_t* xp_stx_token_yield (xp_stx_token_t* token, xp_word_t capacity)
2005-05-22 10:32:37 +00:00
{
2005-06-12 16:22:47 +00:00
xp_char_t* p;
2005-06-12 15:46:02 +00:00
2005-06-12 16:22:47 +00:00
p = xp_stx_name_yield (&token->name, capacity);
if (p == XP_NULL) return XP_NULL;
2005-05-22 10:32:37 +00:00
2005-06-12 16:22:47 +00:00
/*
token->ivalue = 0;
token->fvalue = .0;
*/
token->type = XP_STX_TOKEN_END;
return p;
2005-05-22 10:32:37 +00:00
}
2005-06-12 16:22:47 +00:00
int xp_stx_token_compare_name (xp_stx_token_t* token, const xp_char_t* str)
2005-05-22 10:32:37 +00:00
{
2005-06-12 16:22:47 +00:00
return xp_stx_name_compare (&token->name, str);
2005-05-22 10:32:37 +00:00
}