[util] Use post_parse in output_options_t
This commit is contained in:
parent
24a9d8c78d
commit
fd0778aa2a
|
@ -46,7 +46,6 @@ struct output_buffer_t : output_options_t
|
||||||
|
|
||||||
void init (hb_buffer_t *buffer, const font_options_t *font_opts)
|
void init (hb_buffer_t *buffer, const font_options_t *font_opts)
|
||||||
{
|
{
|
||||||
get_file_handle ();
|
|
||||||
gs = g_string_new (nullptr);
|
gs = g_string_new (nullptr);
|
||||||
line_no = 0;
|
line_no = 0;
|
||||||
font = hb_font_reference (font_opts->font);
|
font = hb_font_reference (font_opts->font);
|
||||||
|
|
|
@ -447,7 +447,7 @@ helper_cairo_create_context (double w, double h,
|
||||||
const char *extension = out_opts->output_format;
|
const char *extension = out_opts->output_format;
|
||||||
if (!extension) {
|
if (!extension) {
|
||||||
#if HAVE_ISATTY
|
#if HAVE_ISATTY
|
||||||
if (isatty (fileno (out_opts->get_file_handle ())))
|
if (isatty (fileno (out_opts->fp)))
|
||||||
{
|
{
|
||||||
#ifdef CAIRO_HAS_PNG_FUNCTIONS
|
#ifdef CAIRO_HAS_PNG_FUNCTIONS
|
||||||
const char *name;
|
const char *name;
|
||||||
|
@ -526,7 +526,7 @@ helper_cairo_create_context (double w, double h,
|
||||||
content = CAIRO_CONTENT_COLOR_ALPHA;
|
content = CAIRO_CONTENT_COLOR_ALPHA;
|
||||||
|
|
||||||
cairo_surface_t *surface;
|
cairo_surface_t *surface;
|
||||||
FILE *f = out_opts->get_file_handle ();
|
FILE *f = out_opts->fp;
|
||||||
if (constructor)
|
if (constructor)
|
||||||
surface = constructor (stdio_write_func, f, w, h);
|
surface = constructor (stdio_write_func, f, w, h);
|
||||||
else if (constructor2)
|
else if (constructor2)
|
||||||
|
|
|
@ -42,12 +42,23 @@ struct output_options_t
|
||||||
void add_options (option_parser_t *parser,
|
void add_options (option_parser_t *parser,
|
||||||
const char **supported_formats = nullptr);
|
const char **supported_formats = nullptr);
|
||||||
|
|
||||||
void post_parse (GError **error G_GNUC_UNUSED)
|
void post_parse (GError **error G_GNUC_UNUSED);
|
||||||
|
|
||||||
|
char *output_file = nullptr;
|
||||||
|
char *output_format = nullptr;
|
||||||
|
|
||||||
|
bool explicit_output_format = false;
|
||||||
|
FILE *fp = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
void
|
||||||
|
output_options_t::post_parse (GError **error)
|
||||||
{
|
{
|
||||||
if (output_format)
|
if (output_format)
|
||||||
explicit_output_format = true;
|
explicit_output_format = true;
|
||||||
|
|
||||||
if (output_file && !output_format) {
|
if (output_file && !output_format)
|
||||||
|
{
|
||||||
output_format = strrchr (output_file, '.');
|
output_format = strrchr (output_file, '.');
|
||||||
if (output_format)
|
if (output_format)
|
||||||
{
|
{
|
||||||
|
@ -58,40 +69,22 @@ struct output_options_t
|
||||||
|
|
||||||
if (output_file && 0 == strcmp (output_file, "-"))
|
if (output_file && 0 == strcmp (output_file, "-"))
|
||||||
output_file = nullptr; /* STDOUT */
|
output_file = nullptr; /* STDOUT */
|
||||||
}
|
|
||||||
|
|
||||||
FILE *get_file_handle ();
|
|
||||||
|
|
||||||
char *output_file = nullptr;
|
|
||||||
char *output_format = nullptr;
|
|
||||||
bool explicit_output_format = false;
|
|
||||||
|
|
||||||
mutable FILE *fp = nullptr;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
FILE *
|
|
||||||
output_options_t::get_file_handle ()
|
|
||||||
{
|
|
||||||
if (fp)
|
|
||||||
return fp;
|
|
||||||
|
|
||||||
if (output_file)
|
if (output_file)
|
||||||
fp = fopen (output_file, "wb");
|
fp = fopen (output_file, "wb");
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
#if defined(_WIN32) || defined(__CYGWIN__)
|
#if defined(_WIN32) || defined(__CYGWIN__)
|
||||||
setmode (fileno (stdout), O_BINARY);
|
setmode (fileno (stdout), O_BINARY);
|
||||||
#endif
|
#endif
|
||||||
fp = stdout;
|
fp = stdout;
|
||||||
}
|
}
|
||||||
if (!fp)
|
if (!fp)
|
||||||
fail (false, "Cannot open output file `%s': %s",
|
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));
|
g_filename_display_name (output_file), strerror (errno));
|
||||||
|
|
||||||
return fp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
output_options_t::add_options (option_parser_t *parser,
|
output_options_t::add_options (option_parser_t *parser,
|
||||||
const char **supported_formats)
|
const char **supported_formats)
|
||||||
|
|
Loading…
Reference in New Issue