diff --git a/util/hb-shape.cc b/util/hb-shape.cc index 06bb0adac..6b274ecc7 100644 --- a/util/hb-shape.cc +++ b/util/hb-shape.cc @@ -46,7 +46,6 @@ struct output_buffer_t : output_options_t void init (hb_buffer_t *buffer, const font_options_t *font_opts) { - get_file_handle (); gs = g_string_new (nullptr); line_no = 0; font = hb_font_reference (font_opts->font); diff --git a/util/helper-cairo.hh b/util/helper-cairo.hh index 948747da5..605f17e28 100644 --- a/util/helper-cairo.hh +++ b/util/helper-cairo.hh @@ -447,7 +447,7 @@ helper_cairo_create_context (double w, double h, const char *extension = out_opts->output_format; if (!extension) { #if HAVE_ISATTY - if (isatty (fileno (out_opts->get_file_handle ()))) + if (isatty (fileno (out_opts->fp))) { #ifdef CAIRO_HAS_PNG_FUNCTIONS const char *name; @@ -526,7 +526,7 @@ helper_cairo_create_context (double w, double h, content = CAIRO_CONTENT_COLOR_ALPHA; cairo_surface_t *surface; - FILE *f = out_opts->get_file_handle (); + FILE *f = out_opts->fp; if (constructor) surface = constructor (stdio_write_func, f, w, h); else if (constructor2) diff --git a/util/output-options.hh b/util/output-options.hh index f3fda61e3..c86096098 100644 --- a/util/output-options.hh +++ b/util/output-options.hh @@ -42,56 +42,49 @@ struct output_options_t void add_options (option_parser_t *parser, const char **supported_formats = nullptr); - 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) - { - output_format++; /* skip the dot */ - output_format = g_strdup (output_format); - } - } - - if (output_file && 0 == strcmp (output_file, "-")) - output_file = nullptr; /* STDOUT */ - } - - FILE *get_file_handle (); + void post_parse (GError **error G_GNUC_UNUSED); char *output_file = nullptr; char *output_format = nullptr; - bool explicit_output_format = false; - mutable FILE *fp = nullptr; + bool explicit_output_format = false; + FILE *fp = nullptr; }; - -FILE * -output_options_t::get_file_handle () +void +output_options_t::post_parse (GError **error) { - if (fp) - return fp; + if (output_format) + explicit_output_format = true; + + if (output_file && !output_format) + { + output_format = strrchr (output_file, '.'); + if (output_format) + { + output_format++; /* skip the dot */ + output_format = g_strdup (output_format); + } + } + + if (output_file && 0 == strcmp (output_file, "-")) + output_file = nullptr; /* STDOUT */ if (output_file) fp = fopen (output_file, "wb"); - else { + else + { #if defined(_WIN32) || defined(__CYGWIN__) setmode (fileno (stdout), O_BINARY); #endif fp = stdout; } if (!fp) - fail (false, "Cannot open output file `%s': %s", - g_filename_display_name (output_file), strerror (errno)); - - return fp; + g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_FAILED, + "Cannot open output file `%s': %s", + g_filename_display_name (output_file), strerror (errno)); } - void output_options_t::add_options (option_parser_t *parser, const char **supported_formats)