2 * dump-boundaries.c: Dump text boundaries for a file
4 * Copyright (C) 1999-2000 Red Hat Software
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
27 #include <pango/pango.h>
29 #define CHFORMAT "%0#6x"
31 static void fail (const char *format, ...) G_GNUC_PRINTF (1, 2) G_GNUC_NORETURN;
32 static void fail (const char *format, ...)
38 va_start (args, format);
39 str = g_strdup_vprintf (format, args);
42 fprintf (stderr, "Error: %s\n", str);
50 dump_text (const char *text)
57 if (!g_utf8_validate (text, -1, NULL))
58 fail ("Invalid UTF-8 in file");
60 len = g_utf8_strlen (text, -1);
61 attrs = g_new0 (PangoLogAttr, len + 1);
63 pango_get_log_attrs (text,
66 pango_language_from_string ("C"),
70 ucs4 = g_utf8_to_ucs4 (text, -1, NULL, NULL, NULL);
72 for (i = 0; i < len + 1; i++)
74 char buf[7] = { '\0', };
77 g_unichar_to_utf8 (ucs4[i], buf);
80 loc = g_strdup ("\\n");
81 else if (*buf == '\r')
82 loc = g_strdup ("\\r");
84 loc = g_locale_from_utf8 (buf, -1, NULL, NULL, NULL);
86 g_print (CHFORMAT " (%s):\t line_break = %d mandatory_break = %d char_break = %d\n"
87 " \t\t white = %d cursor_position = %d\n"
88 " \t\t word_start = %d word_end = %d\n"
89 " \t\t sentence_boundary = %d sentence_start = %d sentence_end = %d\n",
90 ucs4[i], loc ? loc : "?",
91 attrs[i].is_line_break,
92 attrs[i].is_mandatory_break,
93 attrs[i].is_char_break,
95 attrs[i].is_cursor_position,
96 attrs[i].is_word_start,
98 attrs[i].is_sentence_boundary,
99 attrs[i].is_sentence_start,
100 attrs[i].is_sentence_end);
115 g_setenv ("PANGO_RC_FILE", "./pangorc", TRUE);
118 fail ("must give a filename on the command line");
120 if (!g_file_get_contents (argv[1], &text, NULL, NULL))
121 fail ("Couldn't open sample text file");