mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-10 03:16:17 +01:00
e070fdea39
Modified Files: glib/ChangeLog glib/glib.def glib/glib/giochannel.c glib/glib/giochannel.h glib/glib/giounix.c glib/glib/giowin32.c glib/docs/reference/glib/glib-sections.txt glib/tests/iochannel-test.c glib/tests/unicode-collate.c glib/tests/unicode-normalize.c Added Files: glib/tests/iochannel-test-infile * glib/giochannel.c: API changes, fixes to error handling, some internal restructuring * glib/giochannel.h: API changes, documentation for elements in GIOChannel structure * glib/giounix.c: Matched API changes, implemented backend to set is_readable, is_writeable, is_seekable flags, added a test to catch large values of count for which the behavior of write() is undefined * glib/giowin32.c: Changed to match new prototypes for io_close() and io_seek(), removed references to G_IO_STATUS_INTR, set is_seekable flag in channel creation functions * glib.def: Renamed g_channel_error_quark() and g_channel_error_from_errno() to g_io_channel_error_quark() and g_io_channel_error_from_errno(); added new functions g_io_channel_get_buffered() and g_io_channel_set_buffered() * docs/reference/glib/glib-sections.txt: Modified iochannel section to reflect new functions and API changes * tests/iochannel-test.c: Fixed to work with API changes * tests/iochannel-test-infile: New file; input file for iochannel-test * tests/unicode-collate.c tests/unicode-normalize.c: Changed G_IO_FILE_MODE_READ to "r" to match API change
96 lines
1.9 KiB
C
96 lines
1.9 KiB
C
#include <glib.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
typedef struct {
|
|
const char *key;
|
|
const char *str;
|
|
} Line;
|
|
|
|
|
|
int
|
|
compare_collate (const void *a, const void *b)
|
|
{
|
|
const Line *line_a = a;
|
|
const Line *line_b = b;
|
|
|
|
return g_utf8_collate (line_a->str, line_b->str);
|
|
}
|
|
|
|
int
|
|
compare_key (const void *a, const void *b)
|
|
{
|
|
const Line *line_a = a;
|
|
const Line *line_b = b;
|
|
|
|
return strcmp (line_a->key, line_b->key);
|
|
}
|
|
|
|
int main (int argc, char **argv)
|
|
{
|
|
GIOChannel *in;
|
|
GError *error = NULL;
|
|
GArray *line_array = g_array_new (FALSE, FALSE, sizeof(Line));
|
|
guint i;
|
|
|
|
if (argc != 1 && argc != 2)
|
|
{
|
|
fprintf (stderr, "Usage: unicode-collate [FILE]\n");
|
|
return 1;
|
|
}
|
|
|
|
if (argc == 2)
|
|
{
|
|
in = g_io_channel_new_file (argv[1], "r", &error);
|
|
if (!in)
|
|
{
|
|
fprintf (stderr, "Cannot open %s: %s\n", argv[1], error->message);
|
|
return 1;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
in = g_io_channel_unix_new (fileno (stdin));
|
|
}
|
|
|
|
while (TRUE)
|
|
{
|
|
gsize term_pos;
|
|
gchar *str;
|
|
Line line;
|
|
|
|
if (g_io_channel_read_line (in, &str, NULL, &term_pos, &error) != G_IO_STATUS_NORMAL)
|
|
break;
|
|
|
|
str[term_pos] = '\0';
|
|
|
|
line.key = g_utf8_collate_key (str, -1);
|
|
line.str = str;
|
|
|
|
g_array_append_val (line_array, line);
|
|
}
|
|
|
|
if (error)
|
|
{
|
|
fprintf (stderr, "Error reading test file, %s\n", error->message);
|
|
return 1;
|
|
}
|
|
|
|
printf ("== g_utf8_collate ==\n");
|
|
|
|
qsort (line_array->data, line_array->len, sizeof (Line), compare_collate);
|
|
for (i = 0; i < line_array->len; i++)
|
|
printf ("%s\n", g_array_index (line_array, Line, i).str);
|
|
|
|
printf ("== g_utf8_collate_key ==\n");
|
|
|
|
qsort (line_array->data, line_array->len, sizeof (Line), compare_key);
|
|
for (i = 0; i < line_array->len; i++)
|
|
printf ("%s\n", g_array_index (line_array, Line, i).str);
|
|
|
|
g_io_channel_close (in);
|
|
|
|
return 0;
|
|
}
|