1 #undef G_DISABLE_ASSERT
16 compare_collate (const void *a, const void *b)
18 const Line *line_a = a;
19 const Line *line_b = b;
21 return g_utf8_collate (line_a->str, line_b->str);
25 compare_key (const void *a, const void *b)
27 const Line *line_a = a;
28 const Line *line_b = b;
30 return strcmp (line_a->key, line_b->key);
33 int main (int argc, char **argv)
37 GArray *line_array = g_array_new (FALSE, FALSE, sizeof(Line));
40 if (argc != 1 && argc != 2)
42 fprintf (stderr, "Usage: unicode-collate [FILE]\n");
48 in = g_io_channel_new_file (argv[1], "r", &error);
51 fprintf (stderr, "Cannot open %s: %s\n", argv[1], error->message);
57 in = g_io_channel_unix_new (fileno (stdin));
66 if (g_io_channel_read_line (in, &str, NULL, &term_pos, &error) != G_IO_STATUS_NORMAL)
71 line.key = g_utf8_collate_key (str, -1);
74 g_array_append_val (line_array, line);
79 fprintf (stderr, "Error reading test file, %s\n", error->message);
83 printf ("== g_utf8_collate ==\n");
85 qsort (line_array->data, line_array->len, sizeof (Line), compare_collate);
86 for (i = 0; i < line_array->len; i++)
87 printf ("%s\n", g_array_index (line_array, Line, i).str);
89 printf ("== g_utf8_collate_key ==\n");
91 qsort (line_array->data, line_array->len, sizeof (Line), compare_key);
92 for (i = 0; i < line_array->len; i++)
93 printf ("%s\n", g_array_index (line_array, Line, i).str);
95 g_io_channel_unref (in);