[pango/pango2: 7/168] Drop deprecated utils apis




commit 178e080d85c596251ea92e9203106ac8a2dcbfd9
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Jan 10 11:32:10 2022 -0500

    Drop deprecated utils apis

 pango/pango-utils-private.h |  59 -----
 pango/pango-utils.c         | 527 --------------------------------------------
 pango/pango-utils.h         |  27 ---
 pango/pangowin32-fontmap.c  |  91 ++++++++
 utils/viewer-render.c       |  85 +++++--
 5 files changed, 155 insertions(+), 634 deletions(-)
---
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 2800e06e..d8fc9c1a 100644
--- a/pango/pangowin32-fontmap.c
+++ b/pango/pangowin32-fontmap.c
@@ -355,6 +355,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
@@ -419,36 +419,79 @@ do_output (PangoContext     *context,
   g_object_unref (layout);
 }
 
+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;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]