1
/* This software is subject to the terms of the Common Public License
2
You must accept the terms of this license to use this software.
4
Copyright (C) 2002, International Business Machines Corporation
5
and others. All Rights Reserved.
7
Further information about Common Public License Version 0.5 is obtained
8
from url http://oss.software.ibm.com/developer/opensource/license-cpl.html */
15
void State_store_digit(void *object, Char *ch, int *params, int n_params)
18
State *state = (State *)object;
19
tmp = params[state->n_params-1];
20
if(tmp == DEFAULT_PARAM)
22
state->params[state->n_params-1] = 10 * tmp + (Char_get_first_byte(ch) - '0');
25
void State_next_param(void *object, Char *ch, int *params, int n_params)
27
State *state = (State *)object;
28
if(state->n_params < state->max_params )
29
state->params[state->n_params++] = DEFAULT_PARAM;
32
/* State method impl */
33
void State_register_char(State *state, State *next_state,
34
int c, callback_func func, void *object)
36
state->sequence[c].next_state = next_state;
37
state->sequence[c].update = func;
38
state->sequence[c].object = object;
42
* @param state reference to State object
43
* @param ch reference to Char object to be parsed
45
State *State_parse(State *state, Char *ch)
47
State *next_state = state;
49
if(Char_get_length(ch) == 1 &&
50
(state->sequence[Char_get_first_byte(ch)].update != NULL ||
51
state->sequence[Char_get_first_byte(ch)].next_state != NULL))
53
if (state->sequence[Char_get_first_byte(ch)].update != NULL)
54
state->sequence[Char_get_first_byte(ch)].update(state->sequence[Char_get_first_byte(ch)].object,
55
ch,state->params,state->n_params);
56
if (state->sequence[Char_get_first_byte(ch)].next_state != NULL)
57
next_state = state->sequence[Char_get_first_byte(ch)].next_state;
59
else if(Char_is_printable(ch) && state->when_printable.update)
61
state->when_printable.update(state->when_printable.object,ch,
62
state->params,state->n_params);
63
if(state->when_printable.next_state != NULL)
64
next_state = state->when_printable.next_state;
70
static void State_get_in(State *state, Char *ch)
73
state->params[0] = DEFAULT_PARAM;
76
void State_init(State *state, int max_params)
79
state->get_in = State_get_in;
80
state->when_printable.update = NULL;
81
state->when_printable.next_state = state;
83
for(i=0;i<N_TRANS;i++)
85
state->sequence[i].update = NULL;
86
state->sequence[i].next_state = NULL;
89
state->max_params = max_params;
91
state->params = (int *)calloc(sizeof(int),state->max_params);
96
memset(state->state_name,0,sizeof(state->state_name));
99
/* State private method impl end*/
101
/* State Objects end*/