6 print_enum (const char *name, int val, void *unused)
8 printf ("iter test: %s has value %i\n", name, val);
13 main (int argc, char *argv[])
25 fprintf (stderr, "Syntax: %s PROGRAM\n", argv[0]);
29 if ((ctf = ctf_open (argv[1], NULL, &err)) == NULL)
31 if ((fp = ctf_dict_open (ctf, NULL, &err)) == NULL)
34 /* Try getting some enum values by hand. */
36 if ((type = ctf_lookup_by_name (fp, "enum e") ) == CTF_ERR)
38 if (ctf_enum_value (fp, type, "ENUMSAMPLE_1", &val) < 0)
40 printf ("Enum e enumerand ENUMSAMPLE_1 has value %i\n", val);
42 if ((name = ctf_enum_name (fp, type, 1)) == NULL)
44 printf ("Enum e enumerand %s has value 1\n", name);
46 /* Try getting some values using both sorts of iterator. */
48 if ((type = ctf_lookup_by_name (fp, "enum ie") ) == CTF_ERR)
51 if ((ctf_enum_iter (fp, type, print_enum, NULL)) < 0)
54 while ((name = ctf_enum_next (fp, type, &i, &val)) != NULL)
56 printf ("next test: %s has value %i\n", name, val);
58 if (ctf_errno (fp) != ECTF_NEXT_END)
67 fprintf (stderr, "%s: cannot open: %s\n", argv[0], ctf_errmsg (err));
70 fprintf (stderr, "Lookup failed: %s\n", ctf_errmsg (ctf_errno (fp)));
73 fprintf (stderr, "_iter iteration failed: %s\n", ctf_errmsg (ctf_errno (fp)));
76 fprintf (stderr, "_next iteration failed: %s\n", ctf_errmsg (ctf_errno (fp)));