[pango/segmentation-tweaks] pango-segmentation: Add a --text option
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/segmentation-tweaks] pango-segmentation: Add a --text option
- Date: Fri, 9 Jul 2021 11:20:41 +0000 (UTC)
commit 1f104f1411c0cf0a5945d759936ba9dad7f33aef
Author: Matthias Clasen <mclasen redhat com>
Date: Wed Jul 7 21:43:35 2021 -0400
pango-segmentation: Add a --text option
Change pango-segmentation to interpret its argument as
a filename, and add a --text=STRING option to specify
the text directly. This matches what pango-view does.
utils/pango-segmentation.c | 24 ++++++++++++++++++++----
1 file changed, 20 insertions(+), 4 deletions(-)
---
diff --git a/utils/pango-segmentation.c b/utils/pango-segmentation.c
index 0d5b5a49..1d22fb38 100644
--- a/utils/pango-segmentation.c
+++ b/utils/pango-segmentation.c
@@ -141,19 +141,23 @@ int
main (int argc, char *argv[])
{
char *opt_kind = "grapheme";
+ char *opt_text = NULL;
gboolean opt_version = FALSE;
GOptionEntry entries[] = {
{ "kind", 0, 0, G_OPTION_ARG_STRING, &opt_kind, "Kind of boundary (grapheme/word/line/sentence)", "KIND"
},
+ { "text", 0, 0, G_OPTION_ARG_STRING, &opt_text, "Text to display", "STRING" },
{ "version", 0, 0, G_OPTION_ARG_NONE, &opt_version, "Show version" },
{ NULL, },
};
GOptionContext *context;
GError *error = NULL;
+ char *text;
+ gsize len;
g_set_prgname ("pango-segmentation");
setlocale (LC_ALL, "");
- context = g_option_context_new ("TEXT");
+ context = g_option_context_new ("[FILE]");
g_option_context_add_main_entries (context, entries, NULL);
g_option_context_set_description (context,
"Show text segmentation as determined by Pango.");
@@ -169,13 +173,25 @@ main (int argc, char *argv[])
exit (0);
}
- if (argc < 2)
+ if (opt_text)
+ {
+ text = opt_text;
+ }
+ else if (argc > 1)
+ {
+ if (!g_file_get_contents (argv[1], &text, &len, &error))
+ {
+ g_printerr ("%s\n", error->message);
+ exit (1);
+ }
+ }
+ else
{
- g_printerr ("Usage: pango-segmentation [OPTIONS…] TEXT\n");
+ g_printerr ("Usage: pango-segmentation [OPTIONS…] FILE\n");
exit (1);
}
- show_segmentation (argv[1], kind_from_string (opt_kind));
+ show_segmentation (text, kind_from_string (opt_kind));
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]