[util] Make main_font_text a struct again
Going to move to G_OPTION_REMAINING.
This commit is contained in:
parent
5bd463f130
commit
9d8bbe3e53
|
@ -27,9 +27,9 @@
|
||||||
|
|
||||||
typedef int (*main_func_t) (int argc, char **argv);
|
typedef int (*main_func_t) (int argc, char **argv);
|
||||||
|
|
||||||
template <bool report_status=false>
|
template <typename main_t, bool report_status=false>
|
||||||
int
|
int
|
||||||
batch_main (main_func_t main_func, int argc, char **argv)
|
batch_main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
if (argc == 2 && !strcmp (argv[1], "--batch"))
|
if (argc == 2 && !strcmp (argv[1], "--batch"))
|
||||||
{
|
{
|
||||||
|
@ -53,7 +53,7 @@ batch_main (main_func_t main_func, int argc, char **argv)
|
||||||
args[argc++] = p = e;
|
args[argc++] = p = e;
|
||||||
}
|
}
|
||||||
|
|
||||||
int result = main_func (argc, args);
|
int result = main_t () (argc, args);
|
||||||
|
|
||||||
if (report_status)
|
if (report_status)
|
||||||
fprintf (stdout, result == 0 ? "success\n" : "failure\n");
|
fprintf (stdout, result == 0 ? "success\n" : "failure\n");
|
||||||
|
@ -64,7 +64,7 @@ batch_main (main_func_t main_func, int argc, char **argv)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
return main_func (argc, argv);
|
return main_t () (argc, argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -114,5 +114,5 @@ struct shape_closure_consumer_t
|
||||||
int
|
int
|
||||||
main (int argc, char **argv)
|
main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
return main_font_text<shape_closure_consumer_t, font_options_t, text_options_t> (argc, argv);
|
return main_font_text<shape_closure_consumer_t, font_options_t, text_options_t> () (argc, argv);
|
||||||
}
|
}
|
||||||
|
|
|
@ -162,6 +162,6 @@ struct output_buffer_t : output_options_t
|
||||||
int
|
int
|
||||||
main (int argc, char **argv)
|
main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
auto main_func = main_font_text<shape_consumer_t<output_buffer_t>, font_options_t, text_options_t>;
|
using main_t = main_font_text<shape_consumer_t<output_buffer_t>, font_options_t, text_options_t>;
|
||||||
return batch_main<> (main_func, argc, argv);
|
return batch_main<main_t> (argc, argv);
|
||||||
}
|
}
|
||||||
|
|
|
@ -129,6 +129,6 @@ struct subset_consumer_t : subset_options_t, output_options_t
|
||||||
int
|
int
|
||||||
main (int argc, char **argv)
|
main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
auto main_func = main_font_text<subset_consumer_t, face_options_t, text_options_t>;
|
using main_t = main_font_text<subset_consumer_t, face_options_t, text_options_t>;
|
||||||
return batch_main<true> (main_func, argc, argv);
|
return batch_main<main_t, true> (argc, argv);
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,5 +37,5 @@ const unsigned SUBPIXEL_BITS = 6;
|
||||||
int
|
int
|
||||||
main (int argc, char **argv)
|
main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
return main_font_text<shape_consumer_t<view_cairo_t>, font_options_t, text_options_t> (argc, argv);
|
return main_font_text<shape_consumer_t<view_cairo_t>, font_options_t, text_options_t> () (argc, argv);
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,40 +32,43 @@
|
||||||
/* main() body for utilities taking font and processing text.*/
|
/* main() body for utilities taking font and processing text.*/
|
||||||
|
|
||||||
template <typename consumer_t, typename font_options_t, typename text_options_t>
|
template <typename consumer_t, typename font_options_t, typename text_options_t>
|
||||||
int
|
struct main_font_text : font_options_t, text_options_t, consumer_t
|
||||||
main_font_text (int argc, char **argv)
|
|
||||||
{
|
{
|
||||||
|
void add_options (struct option_parser_t *parser)
|
||||||
|
{
|
||||||
|
font_options_t::add_options (parser);
|
||||||
|
text_options_t::add_options (parser);
|
||||||
|
consumer_t::add_options (parser);
|
||||||
|
}
|
||||||
|
|
||||||
font_options_t font_opts;
|
int
|
||||||
text_options_t input;
|
operator () (int argc, char **argv)
|
||||||
consumer_t consumer;
|
{
|
||||||
|
option_parser_t options ("[FONT-FILE] [TEXT]");
|
||||||
|
add_options (&options);
|
||||||
|
options.parse (&argc, &argv);
|
||||||
|
|
||||||
option_parser_t options ("[FONT-FILE] [TEXT]");
|
argc--, argv++;
|
||||||
font_opts.add_options (&options);
|
if (argc && !this->font_file) this->font_file = locale_to_utf8 (argv[0]), argc--, argv++;
|
||||||
input.add_options (&options);
|
if (argc && !this->text && !this->text_file) this->text = locale_to_utf8 (argv[0]), argc--, argv++;
|
||||||
consumer.add_options (&options);
|
if (argc)
|
||||||
options.parse (&argc, &argv);
|
fail (true, "Too many arguments on the command line");
|
||||||
|
if (!this->font_file)
|
||||||
|
options.usage ();
|
||||||
|
if (!this->text && !this->text_file)
|
||||||
|
this->text_file = g_strdup ("-");
|
||||||
|
|
||||||
argc--, argv++;
|
this->init (this);
|
||||||
if (argc && !font_opts.font_file) font_opts.font_file = locale_to_utf8 (argv[0]), argc--, argv++;
|
|
||||||
if (argc && !input.text && !input.text_file) input.text = locale_to_utf8 (argv[0]), argc--, argv++;
|
|
||||||
if (argc)
|
|
||||||
fail (true, "Too many arguments on the command line");
|
|
||||||
if (!font_opts.font_file)
|
|
||||||
options.usage ();
|
|
||||||
if (!input.text && !input.text_file)
|
|
||||||
input.text_file = g_strdup ("-");
|
|
||||||
|
|
||||||
consumer.init (&font_opts);
|
unsigned int line_len;
|
||||||
|
const char *line;
|
||||||
|
while ((line = this->get_line (&line_len)))
|
||||||
|
this->consume_line (line, line_len, this->text_before, this->text_after);
|
||||||
|
|
||||||
unsigned int text_len;
|
this->finish (this);
|
||||||
const char *text;
|
|
||||||
while ((text = input.get_line (&text_len)))
|
|
||||||
consumer.consume_line (text, text_len, input.text_before, input.text_after);
|
|
||||||
|
|
||||||
consumer.finish (&font_opts);
|
return this->failed ? 1 : 0;
|
||||||
|
}
|
||||||
return consumer.failed ? 1 : 0;
|
};
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue