From 6bad092aa87bc3e6bbf0b9faf07693e6ebbe55f2 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 21 Dec 2012 16:01:52 -0500 Subject: [PATCH] [util] Default to "text" output format in hb-shape If you say: hb-shape font.ttf text --output-file out.txt This was previously failing: Unknown output format `txt'; supported formats are: TEXT / JSON Now we simply fallback to TEXT if no explicit format was requested. --- util/hb-shape.cc | 11 ++++++++--- util/options.hh | 5 +++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/util/hb-shape.cc b/util/hb-shape.cc index ca94152..adbb034 100644 --- a/util/hb-shape.cc +++ b/util/hb-shape.cc @@ -47,9 +47,14 @@ struct output_buffer_t output_format = hb_buffer_serialize_format_from_string (options.output_format, -1); if (!hb_buffer_serialize_format_to_string (output_format)) { - fail (false, "Unknown output format `%s'; supported formats are: %s", - options.output_format, - g_strjoinv (" / ", (gchar**) hb_buffer_serialize_list_formats ())); + if (options.explicit_output_format) + fail (false, "Unknown output format `%s'; supported formats are: %s", + options.output_format, + g_strjoinv (" / ", (gchar**) hb_buffer_serialize_list_formats ())); + else + /* Just default to TEXT if not explicitly requested and the + * file extension is not recognized. */ + output_format = HB_BUFFER_SERIALIZE_FORMAT_TEXT; } unsigned int flags = HB_BUFFER_SERIALIZE_FLAGS_DEFAULT; diff --git a/util/options.hh b/util/options.hh index 093f052..c664731 100644 --- a/util/options.hh +++ b/util/options.hh @@ -313,6 +313,7 @@ struct output_options_t : option_group_t output_options_t (option_parser_t *parser) { output_file = NULL; output_format = NULL; + explicit_output_format = false; fp = NULL; @@ -327,6 +328,9 @@ struct output_options_t : option_group_t void post_parse (GError **error G_GNUC_UNUSED) { + if (output_format) + explicit_output_format = true; + if (output_file && !output_format) { output_format = strrchr (output_file, '.'); if (output_format) @@ -341,6 +345,7 @@ struct output_options_t : option_group_t const char *output_file; const char *output_format; + bool explicit_output_format; mutable FILE *fp; }; -- 2.7.4