diff options
author | Matthias Clasen <mclasen@redhat.com> | 2022-01-10 11:32:10 -0500 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2022-02-17 14:01:09 -0600 |
commit | 6199fca80806a54ed4af3f9d533babc26af64c07 (patch) | |
tree | 75376249af0854ea6fd3ce4e0ad25a696e17fb3e | |
parent | 482bb960096f54e5cc1ee089edd4d5add0a0d062 (diff) | |
download | pango-6199fca80806a54ed4af3f9d533babc26af64c07.tar.gz |
Drop deprecated utils apis
-rw-r--r-- | pango/pango-utils-private.h | 59 | ||||
-rw-r--r-- | pango/pango-utils.c | 527 | ||||
-rw-r--r-- | pango/pango-utils.h | 27 | ||||
-rw-r--r-- | pango/pangowin32-fontmap.c | 91 | ||||
-rw-r--r-- | utils/viewer-render.c | 85 |
5 files changed, 155 insertions, 634 deletions
diff --git a/pango/pango-utils-private.h b/pango/pango-utils-private.h deleted file mode 100644 index 4087dc14..00000000 --- a/pango/pango-utils-private.h +++ /dev/null @@ -1,59 +0,0 @@ -/* Pango - * pango-utils.c: Utilities for internal functions and modules - * - * Copyright (C) 2000 Red Hat Software - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifndef __PANGO_UTILS_PRIVATE_H__ -#define __PANGO_UTILS_PRIVATE_H__ - -#include <stdio.h> -#include <glib.h> -#include <pango/pango-font.h> -#include <pango/pango-utils.h> - -G_BEGIN_DECLS - -PANGO_DEPRECATED_IN_1_38 -char * pango_config_key_get_system (const char *key); -PANGO_DEPRECATED_IN_1_38 -char * pango_config_key_get (const char *key); -PANGO_DEPRECATED_IN_1_32 -void pango_lookup_aliases (const char *fontname, - char ***families, - int *n_families); - -/* On Unix, return the name of the "pango" subdirectory of SYSCONFDIR - * (which is set at compile time). On Win32, return the Pango - * installation directory (which is set at installation time, and - * stored in the registry). The returned string should not be - * g_free'd. - */ -PANGO_DEPRECATED -const char * pango_get_sysconf_subdirectory (void) G_GNUC_PURE; - -/* Ditto for LIBDIR/pango. On Win32, use the same Pango - * installation directory. This returned string should not be - * g_free'd either. - */ -PANGO_DEPRECATED -const char * pango_get_lib_subdirectory (void) G_GNUC_PURE; - -G_END_DECLS - -#endif /* __PANGO_UTILS_PRIATE_H__ */ diff --git a/pango/pango-utils.c b/pango/pango-utils.c index b942921e..aa292938 100644 --- a/pango/pango-utils.c +++ b/pango/pango-utils.c @@ -30,7 +30,6 @@ #include "pango-features.h" #include "pango-impl-utils.h" #include "pango-utils-internal.h" -#include "pango-utils-private.h" #include <glib/gstdio.h> @@ -138,22 +137,6 @@ pango_version_check (int required_major, return NULL; } -/** - * pango_trim_string: - * @str: a string - * - * Trims leading and trailing whitespace from a string. - * - * Return value: A newly-allocated string that must be freed with g_free() - * - * Deprecated: 1.38 - */ -char * -pango_trim_string (const char *str) -{ - return _pango_trim_string (str); -} - char * _pango_trim_string (const char *str) { @@ -171,366 +154,6 @@ _pango_trim_string (const char *str) return g_strndup (str, len); } -/** - * pango_split_file_list: - * @str: a %G_SEARCHPATH_SEPARATOR separated list of filenames - * - * Splits a %G_SEARCHPATH_SEPARATOR-separated list of files, stripping - * white space and substituting ~/ with $HOME/. - * - * Return value: (transfer full) (array zero-terminated=1): a list of - * strings to be freed with g_strfreev() - * - * Deprecated: 1.38 - */ -char ** -pango_split_file_list (const char *str) -{ - int i = 0; - int j; - char **files; - - files = g_strsplit (str, G_SEARCHPATH_SEPARATOR_S, -1); - - while (files[i]) - { - char *file = _pango_trim_string (files[i]); - - /* If the resulting file is empty, skip it */ - if (file[0] == '\0') - { - g_free(file); - g_free (files[i]); - - for (j = i + 1; files[j]; j++) - files[j - 1] = files[j]; - - files[j - 1] = NULL; - - continue; - } -#ifndef G_OS_WIN32 - /* '~' is a quite normal and common character in file names on - * Windows, especially in the 8.3 versions of long file names, which - * still occur now and then. Also, few Windows user are aware of the - * Unix shell convention that '~' stands for the home directory, - * even if they happen to have a home directory. - */ - if (file[0] == '~' && file[1] == G_DIR_SEPARATOR) - { - char *tmp = g_strconcat (g_get_home_dir(), file + 1, NULL); - g_free (file); - file = tmp; - } - else if (file[0] == '~' && file[1] == '\0') - { - g_free (file); - file = g_strdup (g_get_home_dir()); - } -#endif - g_free (files[i]); - files[i] = file; - - i++; - } - - return files; -} - -/** - * pango_read_line: - * @stream: a stdio stream - * @str: `GString` buffer into which to write the result - * - * Reads an entire line from a file into a buffer. - * - * Lines may be delimited with '\n', '\r', '\n\r', or '\r\n'. The delimiter - * is not written into the buffer. Text after a '#' character is treated as - * a comment and skipped. '\' can be used to escape a # character. - * '\' proceeding a line delimiter combines adjacent lines. A '\' proceeding - * any other character is ignored and written into the output buffer - * unmodified. - * - * Return value: 0 if the stream was already at an %EOF character, - * otherwise the number of lines read (this is useful for maintaining - * a line number counter which doesn't combine lines with '\') - * - * Deprecated: 1.38 - */ -gint -pango_read_line (FILE *stream, GString *str) -{ - gboolean quoted = FALSE; - gboolean comment = FALSE; - int n_read = 0; - int lines = 1; - - flockfile (stream); - - g_string_truncate (str, 0); - - while (1) - { - int c; - - c = getc_unlocked (stream); - - if (c == EOF) - { - if (quoted) - g_string_append_c (str, '\\'); - - goto done; - } - else - n_read++; - - if (quoted) - { - quoted = FALSE; - - switch (c) - { - case '#': - g_string_append_c (str, '#'); - break; - case '\r': - case '\n': - { - int next_c = getc_unlocked (stream); - - if (!(next_c == EOF || - (c == '\r' && next_c == '\n') || - (c == '\n' && next_c == '\r'))) - ungetc (next_c, stream); - - lines++; - - break; - } - default: - g_string_append_c (str, '\\'); - g_string_append_c (str, c); - } - } - else - { - switch (c) - { - case '#': - comment = TRUE; - break; - case '\\': - if (!comment) - quoted = TRUE; - break; - case '\r': - case '\n': - { - int next_c = getc_unlocked (stream); - - if (!(next_c == EOF || - (c == '\r' && next_c == '\n') || - (c == '\n' && next_c == '\r'))) - ungetc (next_c, stream); - - goto done; - } - default: - if (!comment) - g_string_append_c (str, c); - } - } - } - - done: - - funlockfile (stream); - - return (n_read > 0) ? lines : 0; -} - -/** - * pango_skip_space: - * @pos: (inout): in/out string position - * - * Skips 0 or more characters of white space. - * - * Return value: %FALSE if skipping the white space leaves - * the position at a '\0' character. - * - * Deprecated: 1.38 - */ -gboolean -pango_skip_space (const char **pos) -{ - const char *p = *pos; - - while (g_ascii_isspace (*p)) - p++; - - *pos = p; - - return !(*p == '\0'); -} - -/** - * pango_scan_word: - * @pos: (inout): in/out string position - * @out: a `GString` into which to write the result - * - * Scans a word into a `GString` buffer. - * - * A word consists of [A-Za-z_] followed by zero or more - * [A-Za-z_0-9]. Leading white space is skipped. - * - * Return value: %FALSE if a parse error occurred - * - * Deprecated: 1.38 - */ -gboolean -pango_scan_word (const char **pos, GString *out) -{ - const char *p = *pos; - - while (g_ascii_isspace (*p)) - p++; - - if (!((*p >= 'A' && *p <= 'Z') || - (*p >= 'a' && *p <= 'z') || - *p == '_')) - return FALSE; - - g_string_truncate (out, 0); - g_string_append_c (out, *p); - p++; - - while ((*p >= 'A' && *p <= 'Z') || - (*p >= 'a' && *p <= 'z') || - (*p >= '0' && *p <= '9') || - *p == '_') - { - g_string_append_c (out, *p); - p++; - } - - *pos = p; - - return TRUE; -} - -/** - * pango_scan_string: - * @pos: (inout): in/out string position - * @out: a `GString` into which to write the result - * - * Scans a string into a `GString` buffer. - * - * The string may either be a sequence of non-white-space characters, - * or a quoted string with '"'. Instead a quoted string, '\"' represents - * a literal quote. Leading white space outside of quotes is skipped. - * - * Return value: %FALSE if a parse error occurred - * - * Deprecated: 1.38 - */ -gboolean -pango_scan_string (const char **pos, GString *out) -{ - const char *p = *pos; - - while (g_ascii_isspace (*p)) - p++; - - if (G_UNLIKELY (!*p)) - return FALSE; - else if (*p == '"') - { - gboolean quoted = FALSE; - g_string_truncate (out, 0); - - p++; - - while (TRUE) - { - if (quoted) - { - int c = *p; - - switch (c) - { - case '\0': - return FALSE; - case 'n': - c = '\n'; - break; - case 't': - c = '\t'; - break; - default: - break; - } - - quoted = FALSE; - g_string_append_c (out, c); - } - else - { - switch (*p) - { - case '\0': - return FALSE; - case '\\': - quoted = TRUE; - break; - case '"': - p++; - goto done; - default: - g_string_append_c (out, *p); - break; - } - } - p++; - } - done: - ; - } - else - { - g_string_truncate (out, 0); - - while (*p && !g_ascii_isspace (*p)) - { - g_string_append_c (out, *p); - p++; - } - } - - *pos = p; - - return TRUE; -} - -/** - * pango_scan_int: - * @pos: (inout): in/out string position - * @out: (out): an int into which to write the result - * - * Scans an integer. - * - * Leading white space is skipped. - * - * Return value: %FALSE if a parse error occurred - * - * Deprecated: 1.38 - */ -gboolean -pango_scan_int (const char **pos, int *out) -{ - return _pango_scan_int (pos, out); -} - gboolean _pango_scan_int (const char **pos, int *out) { @@ -556,97 +179,6 @@ _pango_scan_int (const char **pos, int *out) return TRUE; } -/** - * pango_config_key_get_system: - * @key: Key to look up, in the form "SECTION/KEY" - * - * Do not use. Does not do anything. - * - * Return value: %NULL - * - * Deprecated: 1.38 - */ -char * -pango_config_key_get_system (const char *key) -{ - return NULL; -} - -/** - * pango_config_key_get: - * @key: Key to look up, in the form "SECTION/KEY" - * - * Do not use. Does not do anything. - * - * Return value: %NULL - * - * Deprecated: 1.38 - */ -char * -pango_config_key_get (const char *key) -{ - return NULL; -} - -/** - * pango_get_sysconf_subdirectory: - * - * Returns the name of the "pango" subdirectory of SYSCONFDIR - * (which is set at compile time). - * - * Return value: the Pango sysconf directory. The returned string should - * not be freed. - * - * Deprecated: 1.38 - */ -const char * -pango_get_sysconf_subdirectory (void) -{ - static const gchar *result = NULL; /* MT-safe */ - - if (g_once_init_enter (&result)) - { - const char *tmp_result = NULL; - const char *sysconfdir = g_getenv ("PANGO_SYSCONFDIR"); - if (sysconfdir != NULL) - tmp_result = g_build_filename (sysconfdir, "pango", NULL); - else - tmp_result = SYSCONFDIR "/pango"; - g_once_init_leave(&result, tmp_result); - } - return result; -} - -/** - * pango_get_lib_subdirectory: - * - * Returns the name of the "pango" subdirectory of LIBDIR - * (which is set at compile time). - * - * Return value: the Pango lib directory. The returned string should - * not be freed. - * - * Deprecated: 1.38 - */ -const char * -pango_get_lib_subdirectory (void) -{ - static const gchar *result = NULL; /* MT-safe */ - - if (g_once_init_enter (&result)) - { - const gchar *tmp_result = NULL; - const char *libdir = g_getenv ("PANGO_LIBDIR"); - if (libdir != NULL) - tmp_result = g_build_filename (libdir, "pango", NULL); - else - tmp_result = LIBDIR "/pango"; - g_once_init_leave(&result, tmp_result); - } - return result; -} - - static gboolean parse_int (const char *word, int *out) @@ -672,42 +204,6 @@ parse_int (const char *word, return FALSE; } -/** - * pango_parse_enum: - * @type: enum type to parse, eg. %PANGO_TYPE_ELLIPSIZE_MODE - * @str: (nullable): string to parse - * @value: (out) (optional): integer to store the result in - * @warn: if %TRUE, issue a g_warning() on bad input - * @possible_values: (out) (optional): place to store list of possible - * values on failure - * - * Parses an enum type and stores the result in @value. - * - * If @str does not match the nick name of any of the possible values - * for the enum and is not an integer, %FALSE is returned, a warning - * is issued if @warn is %TRUE, and a string representing the list of - * possible values is stored in @possible_values. The list is - * slash-separated, eg. "none/start/middle/end". - * - * If failed and @possible_values is not %NULL, returned string should - * be freed using g_free(). - * - * Return value: %TRUE if @str was successfully parsed - * - * Deprecated: 1.38 - * - * Since: 1.16 - */ -gboolean -pango_parse_enum (GType type, - const char *str, - int *value, - gboolean warn, - char **possible_values) -{ - return _pango_parse_enum (type, str, value, warn, possible_values); -} - gboolean _pango_parse_enum (GType type, const char *str, @@ -824,29 +320,6 @@ pango_parse_flags (GType type, return ret; } -/** - * pango_lookup_aliases: - * @fontname: an ASCII string - * @families: (out) (array length=n_families): will be set to an array of - * font family names. This array is owned by Pango and should not be freed - * @n_families: (out): will be set to the length of the @families array - * - * Look up all user defined aliases for the alias @fontname. - * - * The resulting font family names will be stored in @families, - * and the number of families in @n_families. - * - * Deprecated: 1.32: This function is not thread-safe. - */ -void -pango_lookup_aliases (const char *fontname, - char ***families, - int *n_families) -{ - *families = NULL; - *n_families = 0; -} - #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated-declarations" diff --git a/pango/pango-utils.h b/pango/pango-utils.h index 49566cf8..36635b12 100644 --- a/pango/pango-utils.h +++ b/pango/pango-utils.h @@ -28,33 +28,6 @@ G_BEGIN_DECLS -PANGO_DEPRECATED -char ** pango_split_file_list (const char *str); - -PANGO_DEPRECATED -char *pango_trim_string (const char *str); -PANGO_DEPRECATED -gint pango_read_line (FILE *stream, - GString *str); -PANGO_DEPRECATED -gboolean pango_skip_space (const char **pos); -PANGO_DEPRECATED -gboolean pango_scan_word (const char **pos, - GString *out); -PANGO_DEPRECATED -gboolean pango_scan_string (const char **pos, - GString *out); -PANGO_DEPRECATED -gboolean pango_scan_int (const char **pos, - int *out); - -PANGO_DEPRECATED -gboolean pango_parse_enum (GType type, - const char *str, - int *value, - gboolean warn, - char **possible_values); - /* Functions for parsing textual representations * of PangoFontDescription fields. They return TRUE if the input string * contains a valid value, which then has been assigned to the corresponding diff --git a/pango/pangowin32-fontmap.c b/pango/pangowin32-fontmap.c index f59eddf4..af42ca81 100644 --- a/pango/pangowin32-fontmap.c +++ b/pango/pangowin32-fontmap.c @@ -352,6 +352,97 @@ alias_free (struct PangoAlias *alias) g_slice_free (struct PangoAlias, alias); } +static gboolean +pango_skip_space (const char **pos) +{ + const char *p = *pos; + + while (g_ascii_isspace (*p)) + p++; + + *pos = p; + + return !(*p == '\0'); +} + +static gboolean +pango_scan_string (const char **pos, GString *out) +{ + const char *p = *pos; + + while (g_ascii_isspace (*p)) + p++; + + if (G_UNLIKELY (!*p)) + return FALSE; + else if (*p == '"') + { + gboolean quoted = FALSE; + g_string_truncate (out, 0); + + p++; + + while (TRUE) + { + if (quoted) + { + int c = *p; + + switch (c) + { + case '\0': + return FALSE; + case 'n': + c = '\n'; + break; + case 't': + c = '\t'; + break; + default: + break; + } + + quoted = FALSE; + g_string_append_c (out, c); + } + else + { + switch (*p) + { + case '\0': + return FALSE; + case '\\': + quoted = TRUE; + break; + case '"': + p++; + goto done; + default: + g_string_append_c (out, *p); + break; + } + } + p++; + } + done: + ; + } + else + { + g_string_truncate (out, 0); + + while (*p && !g_ascii_isspace (*p)) + { + g_string_append_c (out, *p); + p++; + } + } + + *pos = p; + + return TRUE; +} + static void handle_alias_line (GString *line_buffer, char **errstring, diff --git a/utils/viewer-render.c b/utils/viewer-render.c index d5ca5e3e..2f95af80 100644 --- a/utils/viewer-render.c +++ b/utils/viewer-render.c @@ -420,35 +420,78 @@ do_output (PangoContext *context, } static gboolean +parse_int (const char *word, + int *out) +{ + char *end; + long val; + int i; + + if (word == NULL) + return FALSE; + + val = strtol (word, &end, 10); + i = val; + + if (end != word && *end == '\0' && val >= 0 && val == i) + { + if (out) + *out = i; + + return TRUE; + } + + return FALSE; +} + +static gboolean parse_enum (GType type, - int *value, - const char *name, - const char *arg, - gpointer data G_GNUC_UNUSED, - GError **error) + int *value, + const char *name, + const char *arg, + gpointer data G_GNUC_UNUSED, + GError **error) { - char *possible_values = NULL; - gboolean ret; + GEnumClass *class = NULL; + gboolean ret = TRUE; + GEnumValue *v = NULL; -G_GNUC_BEGIN_IGNORE_DEPRECATIONS - ret = pango_parse_enum (type, - arg, - value, - FALSE, - &possible_values); -G_GNUC_END_IGNORE_DEPRECATIONS + class = g_type_class_ref (type); - if (!ret && error) + if (G_LIKELY (arg)) + v = g_enum_get_value_by_nick (class, arg); + + if (v) { + if (G_LIKELY (value)) + *value = v->value; + } + else if (!parse_int (arg, value)) + { + ret = FALSE; + int i; + GString *s = g_string_new (NULL); + + for (i = 0, v = g_enum_get_value (class, i); + v; + i++ , v = g_enum_get_value (class, i)) + { + if (i) + g_string_append_c (s, '/'); + g_string_append (s, v->value_nick); + } + g_set_error(error, - G_OPTION_ERROR, - G_OPTION_ERROR_BAD_VALUE, - "Argument for %s must be one of %s", - name, - possible_values); + G_OPTION_ERROR, + G_OPTION_ERROR_BAD_VALUE, + "Argument for %s must be one of %s", + name, + s->str); + + g_string_free (s, TRUE); } - g_free (possible_values); + g_type_class_unref (class); return ret; } |