aboutsummaryrefslogtreecommitdiff
path: root/gfsm/gfsm/src/libgfsm/tests/lab2ary.c
blob: e6dbee9f4891f1cce9eb95225b4c2b2d9326e7d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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
#include <gfsm.h>
#include <stdlib.h>


gfsmAutomaton *fsm;
gfsmAlphabet *ialph;
const char *tfstname = "lab2ary.tfst";
gfsmError *err = NULL;


int main (int argc, char **argv) {
  guint i;
  ialph = gfsm_identity_alphabet_new();
  //GArray *ary;
  GPtrArray *ary;

  fsm = gfsm_automaton_new();
  if (!gfsm_automaton_compile_filename(fsm,tfstname,&err)) {
    g_printerr("%s: compile failed for '%s': %s\n", *argv, tfstname, err->message);
    exit(255);
  }
  printf("%s: compiled test automaton from '%s'\n", *argv, tfstname);

  ialph = gfsm_automaton_get_alphabet(fsm, gfsmLSLower, ialph);

  printf("--\n");
  printf("alphabet size=%u ; min=%u ; max=%u\n",
	 gfsm_alphabet_size(ialph), ialph->lab_min, ialph->lab_max);

  printf("--\n");
  printf("alphabet array={");
  /*-- ok
  ary = g_array_new(FALSE,FALSE,sizeof(gfsmLabelVal));
  gfsm_alphabet_labels_to_array(ialph,ary);
  */
  /*-- ok
  ary = g_array_sized_new(FALSE,FALSE,sizeof(gfsmLabelVal),gfsm_alphabet_size(ialph));
  gfsm_alphabet_labels_to_array(ialph,ary);
  */
  /*-- ok */
  //ary = gfsm_alphabet_labels_to_array(ialph,NULL);

  /*-- ptr_array */
  ary = g_ptr_array_sized_new(gfsm_alphabet_size(ialph));
  gfsm_alphabet_labels_to_array(ialph,ary);

  for (i=0; i < ary->len; i++) {
    //printf(" %u", g_array_index(ary,gfsmLabelVal,i));
    printf(" %u", (gfsmLabelVal)g_ptr_array_index(ary,i));
  }
  printf(" }\n");

  //-- cleanup
  //g_array_free(ary,TRUE);
  g_ptr_array_free(ary,TRUE);

  gfsm_automaton_free(fsm);
  gfsm_alphabet_free(ialph);

  return 0;
}