Example #1
0
int big5_reset(big5prober* THIS) {
    int retval = 1;

    retval = retval & statemachine_reset(THIS->codingsm);
    retval = retval & Big5dist_analysis_reset(&(THIS->distanalyser));
    THIS->state = eDetecting;

    return retval;
}
Example #2
0
int sjis_reset(sjisprober* THIS) {
    int retval = 1;

    retval = retval & statemachine_reset(THIS->codingsm);
    retval = retval & sjiscontext_analysis_reset(&(THIS->contextanalyser));
    retval = retval & SJISdist_analysis_reset(&(THIS->distanalyser));
    THIS->state = eDetecting;

    return retval;
}
/* Tests error handling logic when we try to follow non existent transitions. */
int test_error()
{
  statemachine_definition *def;
  statemachine_ctx *sm;
  int res;

  def = statemachine_definition_new(NUM_STATES);
  sm = statemachine_new(def, NULL);

  statemachine_definition_populate(def, simple_state_transitions,
                                   NULL);
  ASSERT(sm->current_state == SIMPLE_STATE_A);

  ASSERT(statemachine_get_error_msg(sm) == NULL);

  res = statemachine_parse_str(sm, "00E");
  ASSERT(sm->current_state == SIMPLE_STATE_ERROR_TEST);
  ASSERT(sm->current_state == res);

  res = statemachine_parse(sm, "3", 1);
  ASSERT(res == STATEMACHINE_ERROR);
  ASSERT_STREQ(statemachine_get_error_msg(sm),
               "Unexpected character '3'");

  statemachine_reset(sm);
  ASSERT(statemachine_get_error_msg(sm) == NULL);

  statemachine_delete(sm);

  def = statemachine_definition_new(NUM_STATES);
  sm = statemachine_new(def, NULL);

  statemachine_definition_populate(def, simple_state_transitions,
                                   simple_states_internal_names);
  ASSERT(sm->current_state == SIMPLE_STATE_A);

  res = statemachine_parse_str(sm, "00E");
  ASSERT(sm->current_state == SIMPLE_STATE_ERROR_TEST);
  ASSERT(sm->current_state == res);

  res = statemachine_parse(sm, "3", 1);
  ASSERT(res == STATEMACHINE_ERROR);
  ASSERT_STREQ(statemachine_get_error_msg(sm),
               "Unexpected character '3' in state 'error_test'");

  statemachine_delete(sm);

  return 0;
}
/* Initializes a new statemachine. Receives a statemachine definition object
 * that should have been initialized with statemachine_definition_new() and a
 * user reference to be used by the caller.
 *
 * The user reference is used by the caller to store any instance specific data
 * the caller may need and is typically used to propagate context information
 * to the event callbacks. The user pointer can just be set to NULL if the
 * caller doesn't need it.
 *
 * Returns NULL if initialization fails.
 *
 * Initialization failure is fatal, and if this function fails it may not
 * deallocate all previously allocated memory.
 */
statemachine_ctx *statemachine_new(statemachine_definition *def,
                                   void *user)
{
    statemachine_ctx *ctx;
    assert(def != NULL);
    ctx = CAST(statemachine_ctx *, malloc(sizeof(statemachine_ctx)));
    if (ctx == NULL)
      return NULL;

    statemachine_reset(ctx);

    ctx->definition = def;
    ctx->user = user;

    return ctx;
}
Example #5
0
int utf8_reset(utf8prober* THIS) {
    THIS->state = eDetecting;
	THIS->numofmbchar = 0;

    return statemachine_reset(THIS->codingsm);
}