13 compare_collate (const void *a, const void *b)
15 const Line *line_a = a;
16 const Line *line_b = b;
18 return g_utf8_collate (line_a->str, line_b->str);
22 compare_key (const void *a, const void *b)
24 const Line *line_a = a;
25 const Line *line_b = b;
27 return strcmp (line_a->key, line_b->key);
30 int main (int argc, char **argv)
34 GArray *line_array = g_array_new (FALSE, FALSE, sizeof(Line));
37 if (argc != 1 && argc != 2)
39 fprintf (stderr, "Usage: unicode-collate [FILE]\n");
45 in = g_io_channel_new_file (argv[1], "r", &error);
48 fprintf (stderr, "Cannot open %s: %s\n", argv[1], error->message);
54 in = g_io_channel_unix_new (fileno (stdin));
63 if (g_io_channel_read_line (in, &str, NULL, &term_pos, &error) != G_IO_STATUS_NORMAL)
68 line.key = g_utf8_collate_key (str, -1);
71 g_array_append_val (line_array, line);
76 fprintf (stderr, "Error reading test file, %s\n", error->message);
80 printf ("== g_utf8_collate ==\n");
82 qsort (line_array->data, line_array->len, sizeof (Line), compare_collate);
83 for (i = 0; i < line_array->len; i++)
84 printf ("%s\n", g_array_index (line_array, Line, i).str);
86 printf ("== g_utf8_collate_key ==\n");
88 qsort (line_array->data, line_array->len, sizeof (Line), compare_key);
89 for (i = 0; i < line_array->len; i++)
90 printf ("%s\n", g_array_index (line_array, Line, i).str);
92 g_io_channel_close (in);