Method: FOMA::FSM#initialize

Defined in:
ext/foma.c

#initialize(filename) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'ext/foma.c', line 38

static VALUE foma_fsm_init(VALUE obj, VALUE filename)
{
  FILE *file;
  struct foma_fsm *t;

  t = malloc(sizeof(struct foma_fsm));

  if (!t)
    rb_raise(rb_eRuntimeError, "error allocating memory");

  file = fopen(RSTRING_PTR(filename), "rb");

  if (!file) {
    free(t);
    rb_raise(rb_eRuntimeError, "unable to open file");
  }

  fclose(file);

  t->net = fsm_read_binary_file(RSTRING_PTR(filename));

  if (!t->net) {
    free(t);
    rb_raise(rb_eRuntimeError, "unable to read file");
  }

  t->ah = apply_init(t->net);

  DATA_PTR(obj) = t;
  return Qnil;
}