1 #undef G_DISABLE_ASSERT
17 compare_collate (const void *a, const void *b)
19 const Line *line_a = a;
20 const Line *line_b = b;
22 return g_utf8_collate (line_a->str, line_b->str);
26 compare_key (const void *a, const void *b)
28 const Line *line_a = a;
29 const Line *line_b = b;
31 return strcmp (line_a->key, line_b->key);
34 int main (int argc, char **argv)
38 GArray *line_array = g_array_new (FALSE, FALSE, sizeof(Line));
40 gboolean do_key = FALSE;
41 gboolean do_file = FALSE;
44 /* FIXME: need to modify environment here,
45 * since g_utf8_collate_key calls setlocal (LC_COLLATE, "")
47 g_setenv ("LC_ALL", "en_US", TRUE);
48 locale = setlocale (LC_ALL, "");
49 if (locale == NULL || strcmp (locale, "en_US") != 0)
51 fprintf (stderr, "No suitable locale, skipping test\n");
55 if (argc != 1 && argc != 2 && argc != 3)
57 fprintf (stderr, "Usage: unicode-collate [--key|--file] [FILE]\n");
64 if (strcmp (argv[1], "--key") == 0)
69 else if (strcmp (argv[1], "--file") == 0)
79 in = g_io_channel_new_file (argv[i], "r", &error);
82 fprintf (stderr, "Cannot open %s: %s\n", argv[i], error->message);
88 in = g_io_channel_unix_new (fileno (stdin));
97 if (g_io_channel_read_line (in, &str, NULL, &term_pos, &error) != G_IO_STATUS_NORMAL)
100 str[term_pos] = '\0';
103 line.key = g_utf8_collate_key_for_filename (str, -1);
105 line.key = g_utf8_collate_key (str, -1);
108 g_array_append_val (line_array, line);
113 fprintf (stderr, "Error reading test file, %s\n", error->message);
117 qsort (line_array->data, line_array->len, sizeof (Line), do_key ? compare_key : compare_collate);
118 for (i = 0; i < line_array->len; i++)
119 printf ("%s\n", g_array_index (line_array, Line, i).str);
121 g_io_channel_unref (in);