From 7d2e9164ab6681bfd9fa0946a1150905a1aba283 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 7 Aug 2021 13:38:19 -0600 Subject: [PATCH] [util] Move text options into text_options_t Remove now empty options.cc. --- util/Makefile.sources | 8 +- util/hb-ot-shape-closure.cc | 1 + util/hb-shape.cc | 4 +- util/hb-subset.cc | 1 + util/hb-view.cc | 2 + util/meson.build | 4 - util/options.hh | 43 ---------- util/{options.cc => text-options.hh} | 118 ++++++++++++++++----------- 8 files changed, 80 insertions(+), 101 deletions(-) rename util/{options.cc => text-options.hh} (74%) diff --git a/util/Makefile.sources b/util/Makefile.sources index 56c455661..470fd3c64 100644 --- a/util/Makefile.sources +++ b/util/Makefile.sources @@ -6,11 +6,11 @@ HB_VIEW_sources = \ helper-cairo-ansi.hh \ helper-cairo.hh \ main-font-text.hh \ - options.cc \ options.hh \ output-options.hh \ shape-consumer.hh \ shape-options.hh \ + text-options.hh \ view-cairo.hh \ view-options.hh \ $(NULL) @@ -20,22 +20,22 @@ HB_SHAPE_sources = \ font-options.hh \ hb-shape.cc \ main-font-text.hh \ - options.cc \ options.hh \ output-options.hh \ shape-consumer.hh \ shape-format.hh \ shape-options.hh \ + text-options.hh \ $(NULL) HB_SUBSET_CLI_sources = \ face-options.hh \ hb-subset.cc \ main-font-text.hh \ - options.cc \ options.hh \ output-options.hh \ subset-options.hh \ + text-options.hh \ $(NULL) HB_OT_SHAPE_CLOSURE_sources = \ @@ -43,6 +43,6 @@ HB_OT_SHAPE_CLOSURE_sources = \ font-options.hh \ hb-ot-shape-closure.cc \ main-font-text.hh \ - options.cc \ options.hh \ + text-options.hh \ $(NULL) diff --git a/util/hb-ot-shape-closure.cc b/util/hb-ot-shape-closure.cc index b9cab9815..41d18b549 100644 --- a/util/hb-ot-shape-closure.cc +++ b/util/hb-ot-shape-closure.cc @@ -26,6 +26,7 @@ #include "shape-options.hh" #include "font-options.hh" +#include "text-options.hh" #include "main-font-text.hh" const unsigned DEFAULT_FONT_SIZE = FONT_SIZE_NONE; diff --git a/util/hb-shape.cc b/util/hb-shape.cc index 29f99176b..d9c727f55 100644 --- a/util/hb-shape.cc +++ b/util/hb-shape.cc @@ -25,9 +25,11 @@ * Google Author(s): Behdad Esfahbod */ +#include "output-options.hh" +#include "font-options.hh" +#include "text-options.hh" #include "shape-consumer.hh" #include "shape-format.hh" -#include "output-options.hh" #include "main-font-text.hh" const unsigned DEFAULT_FONT_SIZE = FONT_SIZE_UPEM; diff --git a/util/hb-subset.cc b/util/hb-subset.cc index b5f3f7f0a..da808f901 100644 --- a/util/hb-subset.cc +++ b/util/hb-subset.cc @@ -30,6 +30,7 @@ #include "subset-options.hh" #include "output-options.hh" #include "face-options.hh" +#include "text-options.hh" #include "main-font-text.hh" /* diff --git a/util/hb-view.cc b/util/hb-view.cc index ec148ecf0..5d2dfe52a 100644 --- a/util/hb-view.cc +++ b/util/hb-view.cc @@ -27,6 +27,8 @@ #include "shape-consumer.hh" #include "view-cairo.hh" +#include "font-options.hh" +#include "text-options.hh" #include "main-font-text.hh" const unsigned DEFAULT_FONT_SIZE = 256; diff --git a/util/meson.build b/util/meson.build index 3773e68a6..fdab620fc 100644 --- a/util/meson.build +++ b/util/meson.build @@ -1,21 +1,17 @@ hb_view_sources = [ 'hb-view.cc', - 'options.cc', ] hb_shape_sources = [ 'hb-shape.cc', - 'options.cc', ] hb_ot_shape_closure_sources = [ 'hb-ot-shape-closure.cc', - 'options.cc', ] hb_subset_cli_sources = [ 'hb-subset.cc', - 'options.cc', ] util_deps = [freetype_dep, cairo_dep, cairo_ft_dep, glib_dep] diff --git a/util/options.hh b/util/options.hh index 246a7c6df..ff542f4c5 100644 --- a/util/options.hh +++ b/util/options.hh @@ -218,49 +218,6 @@ option_parser_t::parse (int *argc, char ***argv) } } -// XXXXXXXXXXXX - - -struct text_options_t -{ - ~text_options_t () - { - g_free (text_before); - g_free (text_after); - g_free (text); - g_free (text_file); - if (gs) - g_string_free (gs, true); - if (fp && fp != stdin) - fclose (fp); - } - - void add_options (option_parser_t *parser); - - void post_parse (GError **error G_GNUC_UNUSED) - { - if (text && text_file) - g_set_error (error, - G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, - "Only one of text and text-file can be set"); - } - - const char *get_line (unsigned int *len, int eol = '\n'); - - char *text_before = nullptr; - char *text_after = nullptr; - - int text_len = -1; - char *text = nullptr; - char *text_file = nullptr; - - private: - FILE *fp = nullptr; - GString *gs = nullptr; - char *line = nullptr; - unsigned int line_len = UINT_MAX; -}; - /* fallback implementation for scalbn()/scalbnf() for pre-2013 MSVC */ #if defined (_MSC_VER) && (_MSC_VER < 1800) diff --git a/util/options.cc b/util/text-options.hh similarity index 74% rename from util/options.cc rename to util/text-options.hh index 66ddaa8e6..ad72d7384 100644 --- a/util/options.cc +++ b/util/text-options.hh @@ -1,30 +1,45 @@ -/* - * Copyright © 2011,2012 Google, Inc. - * - * This is part of HarfBuzz, a text shaping library. - * - * Permission is hereby granted, without written agreement and without - * license or royalty fees, to use, copy, modify, and distribute this - * software and its documentation for any purpose, provided that the - * above copyright notice and the following two paragraphs appear in - * all copies of this software. - * - * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR - * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES - * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN - * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH - * DAMAGE. - * - * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, - * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS - * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO - * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. - * - * Google Author(s): Behdad Esfahbod - */ -#include "options.hh" +struct text_options_t +{ + ~text_options_t () + { + g_free (text_before); + g_free (text_after); + g_free (text); + g_free (text_file); + if (gs) + g_string_free (gs, true); + if (fp && fp != stdin) + fclose (fp); + } + + void add_options (option_parser_t *parser); + + void post_parse (GError **error G_GNUC_UNUSED) + { + if (text && text_file) + g_set_error (error, + G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, + "Only one of text and text-file can be set"); + } + + const char *get_line (unsigned int *len, int eol = '\n'); + + char *text_before = nullptr; + char *text_after = nullptr; + + int text_len = -1; + char *text = nullptr; + char *text_file = nullptr; + + private: + FILE *fp = nullptr; + GString *gs = nullptr; + char *line = nullptr; + unsigned int line_len = UINT_MAX; +}; + + static gboolean parse_text (const char *name G_GNUC_UNUSED, const char *arg, @@ -102,29 +117,11 @@ parse_unicodes (const char *name G_GNUC_UNUSED, return true; } -void -text_options_t::add_options (option_parser_t *parser) -{ - GOptionEntry entries[] = - { - {"text", 0, 0, G_OPTION_ARG_CALLBACK, (gpointer) &parse_text, "Set input text", "string"}, - {"text-file", 0, 0, G_OPTION_ARG_STRING, &this->text_file, "Set input text file-name\n\n If no text is provided, standard input is used for input.\n", "filename"}, - {"unicodes", 'u', 0, G_OPTION_ARG_CALLBACK, (gpointer) &parse_unicodes, "Set input Unicode codepoints", "list of hex numbers"}, - {"text-before", 0, 0, G_OPTION_ARG_STRING, &this->text_before, "Set text context before each line", "string"}, - {"text-after", 0, 0, G_OPTION_ARG_STRING, &this->text_after, "Set text context after each line", "string"}, - {nullptr} - }; - parser->add_group (entries, - "text", - "Text options:", - "Options for the input text", - this); -} - const char * text_options_t::get_line (unsigned int *len, int eol) { - if (text) { + if (text) + { if (!line) { line = text; @@ -141,11 +138,14 @@ text_options_t::get_line (unsigned int *len, int eol) const char *ret = line; const char *p = (const char *) memchr (line, eol, line_len); unsigned int ret_len; - if (!p) { + if (!p) + { ret_len = line_len; line += ret_len; line_len = 0; - } else { + } + else + { ret_len = p - ret; line += ret_len + 1; line_len -= ret_len + 1; @@ -155,7 +155,8 @@ text_options_t::get_line (unsigned int *len, int eol) return ret; } - if (!fp) { + if (!fp) + { if (!text_file) fail (true, "At least one of text or text-file must be set"); @@ -189,3 +190,22 @@ text_options_t::get_line (unsigned int *len, int eol) *len = gs->len; return !*len && feof (fp) ? nullptr : gs->str; } + +void +text_options_t::add_options (option_parser_t *parser) +{ + GOptionEntry entries[] = + { + {"text", 0, 0, G_OPTION_ARG_CALLBACK, (gpointer) &parse_text, "Set input text", "string"}, + {"text-file", 0, 0, G_OPTION_ARG_STRING, &this->text_file, "Set input text file-name\n\n If no text is provided, standard input is used for input.\n", "filename"}, + {"unicodes", 'u', 0, G_OPTION_ARG_CALLBACK, (gpointer) &parse_unicodes, "Set input Unicode codepoints", "list of hex numbers"}, + {"text-before", 0, 0, G_OPTION_ARG_STRING, &this->text_before, "Set text context before each line", "string"}, + {"text-after", 0, 0, G_OPTION_ARG_STRING, &this->text_after, "Set text context after each line", "string"}, + {nullptr} + }; + parser->add_group (entries, + "text", + "Text options:", + "Options for the input text", + this); +}