[util/hb-subset] Move output-file validation code into post_parse
This commit is contained in:
parent
58bfe40794
commit
c98773ebb0
|
@ -36,7 +36,7 @@
|
|||
const unsigned DEFAULT_FONT_SIZE = FONT_SIZE_UPEM;
|
||||
const unsigned SUBPIXEL_BITS = 0;
|
||||
|
||||
struct output_buffer_t : output_options_t
|
||||
struct output_buffer_t : output_options_t<>
|
||||
{
|
||||
void add_options (option_parser_t *parser)
|
||||
{
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
* Command line interface to the harfbuzz font subsetter.
|
||||
*/
|
||||
|
||||
struct subset_main_t : option_parser_t, face_options_t, text_options_t, subset_options_t, output_options_t
|
||||
struct subset_main_t : option_parser_t, face_options_t, text_options_t, subset_options_t, output_options_t<false>
|
||||
{
|
||||
int operator () (int argc, char **argv)
|
||||
{
|
||||
|
@ -92,8 +92,7 @@ struct subset_main_t : option_parser_t, face_options_t, text_options_t, subset_o
|
|||
bool
|
||||
write_file (const char *output_file, hb_blob_t *blob)
|
||||
{
|
||||
if (!output_file)
|
||||
fail (true, "No output file was specified");
|
||||
assert (out_fp);
|
||||
|
||||
unsigned int size;
|
||||
const char* data = hb_blob_get_data (blob, &size);
|
||||
|
|
|
@ -426,6 +426,8 @@ static const char *helper_cairo_supported_formats[] =
|
|||
nullptr
|
||||
};
|
||||
|
||||
template <typename view_options_t,
|
||||
typename output_options_t>
|
||||
static inline cairo_t *
|
||||
helper_cairo_create_context (double w, double h,
|
||||
view_options_t *view_opts,
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
|
||||
#include "options.hh"
|
||||
|
||||
template <bool default_stdout = true>
|
||||
struct output_options_t
|
||||
{
|
||||
~output_options_t ()
|
||||
|
@ -40,57 +41,7 @@ struct output_options_t
|
|||
}
|
||||
|
||||
void add_options (option_parser_t *parser,
|
||||
const char **supported_formats = nullptr);
|
||||
|
||||
void post_parse (GError **error G_GNUC_UNUSED);
|
||||
|
||||
char *output_file = nullptr;
|
||||
char *output_format = nullptr;
|
||||
|
||||
bool explicit_output_format = false;
|
||||
FILE *out_fp = nullptr;
|
||||
};
|
||||
|
||||
void
|
||||
output_options_t::post_parse (GError **error)
|
||||
{
|
||||
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)
|
||||
out_fp = fopen (output_file, "wb");
|
||||
else
|
||||
{
|
||||
#if defined(_WIN32) || defined(__CYGWIN__)
|
||||
setmode (fileno (stdout), O_BINARY);
|
||||
#endif
|
||||
out_fp = stdout;
|
||||
}
|
||||
if (!out_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));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
output_options_t::add_options (option_parser_t *parser,
|
||||
const char **supported_formats)
|
||||
const char **supported_formats = nullptr)
|
||||
{
|
||||
const char *text = nullptr;
|
||||
|
||||
|
@ -116,4 +67,51 @@ output_options_t::add_options (option_parser_t *parser,
|
|||
this);
|
||||
}
|
||||
|
||||
void post_parse (GError **error)
|
||||
{
|
||||
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, "-"))
|
||||
out_fp = fopen (output_file, "wb");
|
||||
else
|
||||
{
|
||||
if (!default_stdout && !output_file)
|
||||
{
|
||||
g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_FAILED,
|
||||
"No output file was specified");
|
||||
return;
|
||||
}
|
||||
|
||||
#if defined(_WIN32) || defined(__CYGWIN__)
|
||||
setmode (fileno (stdout), O_BINARY);
|
||||
#endif
|
||||
out_fp = stdout;
|
||||
}
|
||||
if (!out_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));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
char *output_file = nullptr;
|
||||
char *output_format = nullptr;
|
||||
|
||||
bool explicit_output_format = false;
|
||||
FILE *out_fp = nullptr;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
#include "output-options.hh"
|
||||
#include "helper-cairo.hh"
|
||||
|
||||
struct view_cairo_t : view_options_t, output_options_t
|
||||
struct view_cairo_t : view_options_t, output_options_t<>
|
||||
{
|
||||
~view_cairo_t ()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue