summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2021-07-07 21:43:35 -0400
committerMatthias Clasen <mclasen@redhat.com>2021-07-09 07:19:33 -0400
commit1f104f1411c0cf0a5945d759936ba9dad7f33aef (patch)
tree0edf06531d14a5ef38cc9a8c7d863fd26d6f1982 /utils
parentf3aec778e817f685498e949663c67b72f27e0308 (diff)
downloadpango-1f104f1411c0cf0a5945d759936ba9dad7f33aef.tar.gz
pango-segmentation: Add a --text optionsegmentation-tweaks
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.
Diffstat (limited to 'utils')
-rw-r--r--utils/pango-segmentation.c24
1 files 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;
}