]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/ppd.c
Update all references to OS X to macOS.
[thirdparty/cups.git] / cups / ppd.c
index 2c826ff1bae1e8d94234e1941400acf7ddbe20af..44a22c5cb3f3bb443b0999f22e38fdfe8d5da409 100644 (file)
@@ -1,61 +1,25 @@
 /*
- * "$Id: ppd.c 9900 2011-08-17 20:59:46Z mike $"
+ * PPD file routines for CUPS.
  *
- *   PPD file routines for CUPS.
+ * Copyright 2007-2015 by Apple Inc.
+ * Copyright 1997-2007 by Easy Software Products, all rights reserved.
  *
- *   Copyright 2007-2011 by Apple Inc.
- *   Copyright 1997-2007 by Easy Software Products, all rights reserved.
+ * These coded instructions, statements, and computer programs are the
+ * property of Apple Inc. and are protected by Federal copyright
+ * law.  Distribution and use rights are outlined in the file "LICENSE.txt"
+ * which should have been included with this file.  If this file is
+ * file is missing or damaged, see the license at "http://www.cups.org/".
  *
- *   These coded instructions, statements, and computer programs are the
- *   property of Apple Inc. and are protected by Federal copyright
- *   law.  Distribution and use rights are outlined in the file "LICENSE.txt"
- *   which should have been included with this file.  If this file is
- *   file is missing or damaged, see the license at "http://www.cups.org/".
+ * PostScript is a trademark of Adobe Systems, Inc.
  *
- *   PostScript is a trademark of Adobe Systems, Inc.
+ * This code and any derivative of it may be used and distributed
+ * freely under the terms of the GNU General Public License when
+ * used with GNU Ghostscript or its derivatives.  Use of the code
+ * (or any derivative of it) with software other than GNU
+ * GhostScript (or its derivatives) is governed by the CUPS license
+ * agreement.
  *
- *   This code and any derivative of it may be used and distributed
- *   freely under the terms of the GNU General Public License when
- *   used with GNU Ghostscript or its derivatives.  Use of the code
- *   (or any derivative of it) with software other than GNU
- *   GhostScript (or its derivatives) is governed by the CUPS license
- *   agreement.
- *
- *   This file is subject to the Apple OS-Developed Software exception.
- *
- * Contents:
- *
- *   ppdClose()             - Free all memory used by the PPD file.
- *   ppdErrorString()       - Returns the text assocated with a status.
- *   _ppdGetEncoding()      - Get the CUPS encoding value for the given
- *                            LanguageEncoding.
- *   ppdLastError()         - Return the status from the last ppdOpen*().
- *   ppdOpen()              - Read a PPD file into memory.
- *   _ppdOpen()             - Read a PPD file into memory.
- *   ppdOpen2()             - Read a PPD file into memory.
- *   ppdOpenFd()            - Read a PPD file into memory.
- *   _ppdOpenFile()         - Read a PPD file into memory.
- *   ppdOpenFile()          - Read a PPD file into memory.
- *   ppdSetConformance()    - Set the conformance level for PPD files.
- *   ppd_add_attr()         - Add an attribute to the PPD data.
- *   ppd_add_choice()       - Add a choice to an option.
- *   ppd_add_size()         - Add a page size.
- *   ppd_compare_attrs()    - Compare two attributes.
- *   ppd_compare_choices()  - Compare two choices...
- *   ppd_compare_coptions() - Compare two custom options.
- *   ppd_compare_options()  - Compare two options.
- *   ppd_decode()           - Decode a string value...
- *   ppd_free_filters()     - Free the filters array.
- *   ppd_free_group()       - Free a single UI group.
- *   ppd_free_option()      - Free a single option.
- *   ppd_get_coption()      - Get a custom option record.
- *   ppd_get_cparam()       - Get a custom parameter record.
- *   ppd_get_group()        - Find or create the named group as needed.
- *   ppd_get_option()       - Find or create the named option as needed.
- *   ppd_hash_option()      - Generate a hash of the option name...
- *   ppd_read()             - Read a line from a PPD file, skipping comment
- *                            lines as necessary.
- *   ppd_update_filters()   - Update the filters array as needed.
+ * This file is subject to the Apple OS-Developed Software exception.
  */
 
 /*
  * Definitions...
  */
 
-#if defined(WIN32) || defined(__EMX__)
-#  define READ_BINARY  "rb"            /* Open a binary file for reading */
-#  define WRITE_BINARY "wb"            /* Open a binary file for writing */
-#else
-#  define READ_BINARY  "r"             /* Open a binary file for reading */
-#  define WRITE_BINARY "w"             /* Open a binary file for writing */
-#endif /* WIN32 || __EMX__ */
-
 #define ppd_free(p)    if (p) free(p)  /* Safe free macro */
 
 #define PPD_KEYWORD    1               /* Line contained a keyword */
@@ -99,6 +55,18 @@ typedef struct _ppd_line_s
 } _ppd_line_t;
 
 
+/*
+ * Local globals...
+ */
+
+static _cups_threadkey_t ppd_globals_key = _CUPS_THREADKEY_INITIALIZER;
+                                       /* Thread local storage key */
+#ifdef HAVE_PTHREAD_H
+static pthread_once_t  ppd_globals_key_once = PTHREAD_ONCE_INIT;
+                                       /* One-time initialization object */
+#endif /* HAVE_PTHREAD_H */
+
+
 /*
  * Local functions...
  */
@@ -122,16 +90,23 @@ static ppd_cparam_t        *ppd_get_cparam(ppd_coption_t *opt,
                                        const char *param,
                                        const char *text);
 static ppd_group_t     *ppd_get_group(ppd_file_t *ppd, const char *name,
-                                      const char *text, _cups_globals_t *cg,
+                                      const char *text, _ppd_globals_t *pg,
                                       cups_encoding_t encoding);
 static ppd_option_t    *ppd_get_option(ppd_group_t *group, const char *name);
+static _ppd_globals_t  *ppd_globals_alloc(void);
+#if defined(HAVE_PTHREAD_H) || defined(WIN32)
+static void            ppd_globals_free(_ppd_globals_t *g);
+#endif /* HAVE_PTHREAD_H || WIN32 */
+#ifdef HAVE_PTHREAD_H
+static void            ppd_globals_init(void);
+#endif /* HAVE_PTHREAD_H */
 static int             ppd_hash_option(ppd_option_t *option);
 static int             ppd_read(cups_file_t *fp, _ppd_line_t *line,
                                 char *keyword, char *option, char *text,
                                 char **string, int ignoreblank,
-                                _cups_globals_t *cg);
+                                _ppd_globals_t *pg);
 static int             ppd_update_filters(ppd_file_t *ppd,
-                                          _cups_globals_t *cg);
+                                          _ppd_globals_t *pg);
 
 
 /*
@@ -325,9 +300,9 @@ ppdClose(ppd_file_t *ppd)           /* I - PPD file record */
 
 
 /*
- * 'ppdErrorString()' - Returns the text assocated with a status.
+ * 'ppdErrorString()' - Returns the text associated with a status.
  *
- * @since CUPS 1.1.19/Mac OS X 10.3@
+ * @since CUPS 1.1.19/macOS 10.3@
  */
 
 const char *                           /* O - Status string */
@@ -394,30 +369,70 @@ _ppdGetEncoding(const char *name) /* I - LanguageEncoding string */
 }
 
 
+/*
+ * '_ppdGlobals()' - Return a pointer to thread local storage
+ */
+
+_ppd_globals_t *                       /* O - Pointer to global data */
+_ppdGlobals(void)
+{
+  _ppd_globals_t *pg;                  /* Pointer to global data */
+
+
+#ifdef HAVE_PTHREAD_H
+ /*
+  * Initialize the global data exactly once...
+  */
+
+  pthread_once(&ppd_globals_key_once, ppd_globals_init);
+#endif /* HAVE_PTHREAD_H */
+
+ /*
+  * See if we have allocated the data yet...
+  */
+
+  if ((pg = (_ppd_globals_t *)_cupsThreadGetData(ppd_globals_key)) == NULL)
+  {
+   /*
+    * No, allocate memory as set the pointer for the key...
+    */
+
+    if ((pg = ppd_globals_alloc()) != NULL)
+      _cupsThreadSetData(ppd_globals_key, pg);
+  }
+
+ /*
+  * Return the pointer to the data...
+  */
+
+  return (pg);
+}
+
+
 /*
  * 'ppdLastError()' - Return the status from the last ppdOpen*().
  *
- * @since CUPS 1.1.19/Mac OS X 10.3@
+ * @since CUPS 1.1.19/macOS 10.3@
  */
 
 ppd_status_t                           /* O - Status code */
 ppdLastError(int *line)                        /* O - Line number */
 {
-  _cups_globals_t      *cg = _cupsGlobals();
+  _ppd_globals_t       *pg = _ppdGlobals();
                                        /* Global data */
 
 
   if (line)
-    *line = cg->ppd_line;
+    *line = pg->ppd_line;
 
-  return (cg->ppd_status);
+  return (pg->ppd_status);
 }
 
 
 /*
  * '_ppdOpen()' - Read a PPD file into memory.
  *
- * @since CUPS 1.2/Mac OS X 10.5@
+ * @since CUPS 1.2/macOS 10.5@
  */
 
 ppd_file_t *                           /* O - PPD file record or @code NULL@ if the PPD file could not be opened. */
@@ -455,15 +470,15 @@ _ppdOpen(
   int                  ui_keyword;     /* Is this line a UI keyword? */
   cups_lang_t          *lang;          /* Language data */
   cups_encoding_t      encoding;       /* Encoding of PPD file */
-  _cups_globals_t      *cg = _cupsGlobals();
+  _ppd_globals_t       *pg = _ppdGlobals();
                                        /* Global data */
   char                 custom_name[PPD_MAX_NAME];
                                        /* CustomFoo attribute name */
   ppd_attr_t           *custom_attr;   /* CustomFoo attribute */
-  char                 ll[4],          /* Language + '.' */
-                       ll_CC[7];       /* Language country + '.' */
-  size_t               ll_len = 0,     /* Language length */
-                       ll_CC_len = 0;  /* Language country length */
+  char                 ll[7],          /* Base language + '.' */
+                       ll_CC[7];       /* Language w/country + '.' */
+  size_t               ll_len = 0,     /* Base language length */
+                       ll_CC_len = 0;  /* Language w/country length */
   static const char * const ui_keywords[] =
                        {
 #ifdef CUPS_USE_FULL_UI_KEYWORDS_LIST
@@ -538,8 +553,8 @@ _ppdOpen(
   * Default to "OK" status...
   */
 
-  cg->ppd_status = PPD_OK;
-  cg->ppd_line   = 0;
+  pg->ppd_status = PPD_OK;
+  pg->ppd_line   = 0;
 
  /*
   * Range check input...
@@ -547,7 +562,7 @@ _ppdOpen(
 
   if (fp == NULL)
   {
-    cg->ppd_status = PPD_NULL_FILE;
+    pg->ppd_status = PPD_NULL_FILE;
     return (NULL);
   }
 
@@ -561,7 +576,17 @@ _ppdOpen(
       return (NULL);
 
     snprintf(ll_CC, sizeof(ll_CC), "%s.", lang->language);
-    snprintf(ll, sizeof(ll), "%2.2s.", lang->language);
+
+   /*
+    * <rdar://problem/22130168>
+    *
+    * Need to use a different base language for some locales...
+    */
+
+    if (!strcmp(lang->language, "zh_HK"))
+      strlcpy(ll, "zh_TW.", sizeof(ll));
+    else
+      snprintf(ll, sizeof(ll), "%2.2s.", lang->language);
 
     ll_CC_len = strlen(ll_CC);
     ll_len    = strlen(ll);
@@ -577,7 +602,7 @@ _ppdOpen(
   line.buffer  = NULL;
   line.bufsize = 0;
 
-  mask = ppd_read(fp, &line, keyword, name, text, &string, 0, cg);
+  mask = ppd_read(fp, &line, keyword, name, text, &string, 0, pg);
 
   DEBUG_printf(("2_ppdOpen: mask=%x, keyword=\"%s\"...", mask, keyword));
 
@@ -589,8 +614,8 @@ _ppdOpen(
     * Either this is not a PPD file, or it is not a 4.x PPD file.
     */
 
-    if (cg->ppd_status == PPD_OK)
-      cg->ppd_status = PPD_MISSING_PPDADOBE4;
+    if (pg->ppd_status == PPD_OK)
+      pg->ppd_status = PPD_MISSING_PPDADOBE4;
 
     _cupsStrFree(string);
     ppd_free(line.buffer);
@@ -608,7 +633,7 @@ _ppdOpen(
 
   if ((ppd = calloc(1, sizeof(ppd_file_t))) == NULL)
   {
-    cg->ppd_status = PPD_ALLOC_ERROR;
+    pg->ppd_status = PPD_ALLOC_ERROR;
 
     _cupsStrFree(string);
     ppd_free(line.buffer);
@@ -635,20 +660,20 @@ _ppdOpen(
   encoding   = CUPS_ISO8859_1;
   loc        = localeconv();
 
-  while ((mask = ppd_read(fp, &line, keyword, name, text, &string, 1, cg)) != 0)
+  while ((mask = ppd_read(fp, &line, keyword, name, text, &string, 1, pg)) != 0)
   {
     DEBUG_printf(("2_ppdOpen: mask=%x, keyword=\"%s\", name=\"%s\", "
                   "text=\"%s\", string=%d chars...", mask, keyword, name, text,
                  string ? (int)strlen(string) : 0));
 
     if (strncmp(keyword, "Default", 7) && !string &&
-        cg->ppd_conform != PPD_CONFORM_RELAXED)
+        pg->ppd_conform != PPD_CONFORM_RELAXED)
     {
      /*
       * Need a string value!
       */
 
-      cg->ppd_status = PPD_MISSING_VALUE;
+      pg->ppd_status = PPD_MISSING_VALUE;
 
       goto error;
     }
@@ -739,7 +764,7 @@ _ppdOpen(
 
         if (!group)
        {
-          if ((group = ppd_get_group(ppd, "General", _("General"), cg,
+          if ((group = ppd_get_group(ppd, "General", _("General"), pg,
                                     encoding)) == NULL)
            goto error;
 
@@ -752,7 +777,7 @@ _ppdOpen(
 
        if (option == NULL)
        {
-          cg->ppd_status = PPD_ALLOC_ERROR;
+          pg->ppd_status = PPD_ALLOC_ERROR;
 
           goto error;
        }
@@ -872,12 +897,11 @@ _ppdOpen(
       if (ppd->num_profiles == 0)
         profile = malloc(sizeof(ppd_profile_t));
       else
-        profile = realloc(ppd->profiles, sizeof(ppd_profile_t) *
-                                        (ppd->num_profiles + 1));
+        profile = realloc(ppd->profiles, sizeof(ppd_profile_t) * (size_t)(ppd->num_profiles + 1));
 
       if (!profile)
       {
-        cg->ppd_status = PPD_ALLOC_ERROR;
+        pg->ppd_status = PPD_ALLOC_ERROR;
 
        goto error;
       }
@@ -907,11 +931,11 @@ _ppdOpen(
       if (ppd->num_filters == 0)
         filter = malloc(sizeof(char *));
       else
-        filter = realloc(ppd->filters, sizeof(char *) * (ppd->num_filters + 1));
+        filter = realloc(ppd->filters, sizeof(char *) * (size_t)(ppd->num_filters + 1));
 
       if (filter == NULL)
       {
-        cg->ppd_status = PPD_ALLOC_ERROR;
+        pg->ppd_status = PPD_ALLOC_ERROR;
 
        goto error;
       }
@@ -937,12 +961,11 @@ _ppdOpen(
       if (ppd->num_fonts == 0)
         tempfonts = (char **)malloc(sizeof(char *));
       else
-        tempfonts = (char **)realloc(ppd->fonts,
-                                    sizeof(char *) * (ppd->num_fonts + 1));
+        tempfonts = (char **)realloc(ppd->fonts, sizeof(char *) * (size_t)(ppd->num_fonts + 1));
 
       if (tempfonts == NULL)
       {
-        cg->ppd_status = PPD_ALLOC_ERROR;
+        pg->ppd_status = PPD_ALLOC_ERROR;
 
        goto error;
       }
@@ -967,14 +990,14 @@ _ppdOpen(
 
       if ((coption = ppd_get_coption(ppd, keyword + 11)) == NULL)
       {
-        cg->ppd_status = PPD_ALLOC_ERROR;
+        pg->ppd_status = PPD_ALLOC_ERROR;
 
        goto error;
       }
 
       if ((cparam = ppd_get_cparam(coption, name, text)) == NULL)
       {
-        cg->ppd_status = PPD_ALLOC_ERROR;
+        pg->ppd_status = PPD_ALLOC_ERROR;
 
        goto error;
       }
@@ -987,7 +1010,7 @@ _ppdOpen(
           sscanf(string, "%d%32s%64s%64s", &corder, ctype, cminimum,
                  cmaximum) != 4)
       {
-        cg->ppd_status = PPD_BAD_CUSTOM_PARAM;
+        pg->ppd_status = PPD_BAD_CUSTOM_PARAM;
 
        goto error;
       }
@@ -1044,7 +1067,7 @@ _ppdOpen(
       }
       else
       {
-        cg->ppd_status = PPD_BAD_CUSTOM_PARAM;
+        pg->ppd_status = PPD_BAD_CUSTOM_PARAM;
 
        goto error;
       }
@@ -1084,7 +1107,7 @@ _ppdOpen(
 
       if (!ppd_get_coption(ppd, keyword + 6))
       {
-        cg->ppd_status = PPD_ALLOC_ERROR;
+        pg->ppd_status = PPD_ALLOC_ERROR;
 
        goto error;
       }
@@ -1105,7 +1128,7 @@ _ppdOpen(
          {
            DEBUG_puts("1_ppdOpen: Unable to add Custom choice!");
 
-           cg->ppd_status = PPD_ALLOC_ERROR;
+           pg->ppd_status = PPD_ALLOC_ERROR;
 
            goto error;
          }
@@ -1145,7 +1168,7 @@ _ppdOpen(
            {
              DEBUG_puts("1_ppdOpen: Unable to add Custom choice!");
 
-             cg->ppd_status = PPD_ALLOC_ERROR;
+             pg->ppd_status = PPD_ALLOC_ERROR;
 
              goto error;
            }
@@ -1173,9 +1196,9 @@ _ppdOpen(
        }
 
       ppd->num_emulations = count;
-      if ((ppd->emulations = calloc(count, sizeof(ppd_emul_t))) == NULL)
+      if ((ppd->emulations = calloc((size_t)count, sizeof(ppd_emul_t))) == NULL)
       {
-        cg->ppd_status = PPD_ALLOC_ERROR;
+        pg->ppd_status = PPD_ALLOC_ERROR;
 
        goto error;
       }
@@ -1232,19 +1255,19 @@ _ppdOpen(
           * Found "*JobPatchFile: int: string"...
           */
 
-          cg->ppd_status = PPD_BAD_VALUE;
+          pg->ppd_status = PPD_BAD_VALUE;
 
          goto error;
         }
       }
 
-      if (!name[0] && cg->ppd_conform == PPD_CONFORM_STRICT)
+      if (!name[0] && pg->ppd_conform == PPD_CONFORM_STRICT)
       {
        /*
         * Found "*JobPatchFile: string"...
         */
 
-        cg->ppd_status = PPD_MISSING_OPTION_KEYWORD;
+        pg->ppd_status = PPD_MISSING_OPTION_KEYWORD;
 
        goto error;
       }
@@ -1257,14 +1280,14 @@ _ppdOpen(
                                     strlen(string) + 1);
         if (temp == NULL)
        {
-          cg->ppd_status = PPD_ALLOC_ERROR;
+          pg->ppd_status = PPD_ALLOC_ERROR;
 
          goto error;
        }
 
         ppd->patches = temp;
 
-        strcpy(ppd->patches + strlen(ppd->patches), string);
+        memcpy(ppd->patches + strlen(ppd->patches), string, strlen(string) + 1);
       }
     }
     else if (!strcmp(keyword, "OpenUI"))
@@ -1273,9 +1296,9 @@ _ppdOpen(
       * Don't allow nesting of options...
       */
 
-      if (option && cg->ppd_conform == PPD_CONFORM_STRICT)
+      if (option && pg->ppd_conform == PPD_CONFORM_STRICT)
       {
-        cg->ppd_status = PPD_NESTED_OPEN_UI;
+        pg->ppd_status = PPD_NESTED_OPEN_UI;
 
        goto error;
       }
@@ -1299,7 +1322,7 @@ _ppdOpen(
         option = ppd_get_option(subgroup, name);
       else if (group == NULL)
       {
-       if ((group = ppd_get_group(ppd, "General", _("General"), cg,
+       if ((group = ppd_get_group(ppd, "General", _("General"), pg,
                                   encoding)) == NULL)
          goto error;
 
@@ -1312,7 +1335,7 @@ _ppdOpen(
 
       if (option == NULL)
       {
-        cg->ppd_status = PPD_ALLOC_ERROR;
+        pg->ppd_status = PPD_ALLOC_ERROR;
 
        goto error;
       }
@@ -1327,9 +1350,9 @@ _ppdOpen(
         option->ui = PPD_UI_BOOLEAN;
       else if (string && !strcmp(string, "PickOne"))
         option->ui = PPD_UI_PICKONE;
-      else if (cg->ppd_conform == PPD_CONFORM_STRICT)
+      else if (pg->ppd_conform == PPD_CONFORM_STRICT)
       {
-        cg->ppd_status = PPD_BAD_OPEN_UI;
+        pg->ppd_status = PPD_BAD_OPEN_UI;
 
        goto error;
       }
@@ -1378,7 +1401,7 @@ _ppdOpen(
       */
 
       if (!_cups_strcasecmp(name, "PageRegion"))
-        strcpy(custom_name, "CustomPageSize");
+        strlcpy(custom_name, "CustomPageSize", sizeof(custom_name));
       else
         snprintf(custom_name, sizeof(custom_name), "Custom%s", name);
 
@@ -1389,7 +1412,7 @@ _ppdOpen(
          {
            DEBUG_puts("1_ppdOpen: Unable to add Custom choice!");
 
-           cg->ppd_status = PPD_ALLOC_ERROR;
+           pg->ppd_status = PPD_ALLOC_ERROR;
 
            goto error;
          }
@@ -1406,9 +1429,9 @@ _ppdOpen(
       * Don't allow nesting of options...
       */
 
-      if (option && cg->ppd_conform == PPD_CONFORM_STRICT)
+      if (option && pg->ppd_conform == PPD_CONFORM_STRICT)
       {
-        cg->ppd_status = PPD_NESTED_OPEN_UI;
+        pg->ppd_status = PPD_NESTED_OPEN_UI;
 
        goto error;
       }
@@ -1417,7 +1440,7 @@ _ppdOpen(
       * Find the JCL group, and add if needed...
       */
 
-      group = ppd_get_group(ppd, "JCL", _("JCL"), cg, encoding);
+      group = ppd_get_group(ppd, "JCL", _("JCL"), pg, encoding);
 
       if (group == NULL)
        goto error;
@@ -1433,7 +1456,7 @@ _ppdOpen(
 
       if (option == NULL)
       {
-        cg->ppd_status = PPD_ALLOC_ERROR;
+        pg->ppd_status = PPD_ALLOC_ERROR;
 
        goto error;
       }
@@ -1450,7 +1473,7 @@ _ppdOpen(
         option->ui = PPD_UI_PICKONE;
       else
       {
-        cg->ppd_status = PPD_BAD_OPEN_UI;
+        pg->ppd_status = PPD_BAD_OPEN_UI;
 
        goto error;
       }
@@ -1492,7 +1515,7 @@ _ppdOpen(
        {
          DEBUG_puts("1_ppdOpen: Unable to add Custom choice!");
 
-         cg->ppd_status = PPD_ALLOC_ERROR;
+         pg->ppd_status = PPD_ALLOC_ERROR;
 
          goto error;
        }
@@ -1518,14 +1541,14 @@ _ppdOpen(
 
       if (group != NULL)
       {
-        cg->ppd_status = PPD_NESTED_OPEN_GROUP;
+        pg->ppd_status = PPD_NESTED_OPEN_GROUP;
 
        goto error;
       }
 
       if (!string)
       {
-        cg->ppd_status = PPD_BAD_OPEN_GROUP;
+        pg->ppd_status = PPD_BAD_OPEN_GROUP;
 
        goto error;
       }
@@ -1549,7 +1572,7 @@ _ppdOpen(
       * Find/add the group...
       */
 
-      group = ppd_get_group(ppd, string, sptr, cg, encoding);
+      group = ppd_get_group(ppd, string, sptr, pg, encoding);
 
       if (group == NULL)
        goto error;
@@ -1570,7 +1593,7 @@ _ppdOpen(
 
       if (!sptr || sscanf(sptr, "%40s%40s", name, keyword) != 2)
       {
-        cg->ppd_status = PPD_BAD_ORDER_DEPENDENCY;
+        pg->ppd_status = PPD_BAD_ORDER_DEPENDENCY;
 
        goto error;
       }
@@ -1690,19 +1713,18 @@ _ppdOpen(
     {
       if (!string)
       {
-       cg->ppd_status = PPD_BAD_UI_CONSTRAINTS;
+       pg->ppd_status = PPD_BAD_UI_CONSTRAINTS;
        goto error;
       }
 
       if (ppd->num_consts == 0)
        constraint = calloc(2, sizeof(ppd_const_t));
       else
-       constraint = realloc(ppd->consts,
-                            (ppd->num_consts + 2) * sizeof(ppd_const_t));
+       constraint = realloc(ppd->consts, (size_t)(ppd->num_consts + 2) * sizeof(ppd_const_t));
 
       if (constraint == NULL)
       {
-        cg->ppd_status = PPD_ALLOC_ERROR;
+        pg->ppd_status = PPD_ALLOC_ERROR;
 
        goto error;
       }
@@ -1717,7 +1739,7 @@ _ppdOpen(
       {
         case 0 : /* Error */
        case 1 : /* Error */
-           cg->ppd_status = PPD_BAD_UI_CONSTRAINTS;
+           pg->ppd_status = PPD_BAD_UI_CONSTRAINTS;
            goto error;
 
        case 2 : /* Two options... */
@@ -1725,11 +1747,11 @@ _ppdOpen(
            * Check for broken constraints like "* Option"...
            */
 
-           if (cg->ppd_conform == PPD_CONFORM_STRICT &&
+           if (pg->ppd_conform == PPD_CONFORM_STRICT &&
                (!strcmp(constraint->option1, "*") ||
                 !strcmp(constraint->choice1, "*")))
            {
-             cg->ppd_status = PPD_BAD_UI_CONSTRAINTS;
+             pg->ppd_status = PPD_BAD_UI_CONSTRAINTS;
              goto error;
            }
 
@@ -1740,17 +1762,17 @@ _ppdOpen(
 
            if (constraint->option1[0] == '*')
              _cups_strcpy(constraint->option1, constraint->option1 + 1);
-           else if (cg->ppd_conform == PPD_CONFORM_STRICT)
+           else if (pg->ppd_conform == PPD_CONFORM_STRICT)
            {
-             cg->ppd_status = PPD_BAD_UI_CONSTRAINTS;
+             pg->ppd_status = PPD_BAD_UI_CONSTRAINTS;
              goto error;
            }
 
            if (constraint->choice1[0] == '*')
              _cups_strcpy(constraint->option2, constraint->choice1 + 1);
-           else if (cg->ppd_conform == PPD_CONFORM_STRICT)
+           else if (pg->ppd_conform == PPD_CONFORM_STRICT)
            {
-             cg->ppd_status = PPD_BAD_UI_CONSTRAINTS;
+             pg->ppd_status = PPD_BAD_UI_CONSTRAINTS;
              goto error;
            }
 
@@ -1763,12 +1785,12 @@ _ppdOpen(
            * Check for broken constraints like "* Option"...
            */
 
-           if (cg->ppd_conform == PPD_CONFORM_STRICT &&
+           if (pg->ppd_conform == PPD_CONFORM_STRICT &&
                (!strcmp(constraint->option1, "*") ||
                 !strcmp(constraint->choice1, "*") ||
                 !strcmp(constraint->option2, "*")))
            {
-             cg->ppd_status = PPD_BAD_UI_CONSTRAINTS;
+             pg->ppd_status = PPD_BAD_UI_CONSTRAINTS;
              goto error;
            }
 
@@ -1779,18 +1801,18 @@ _ppdOpen(
 
            if (constraint->option1[0] == '*')
              _cups_strcpy(constraint->option1, constraint->option1 + 1);
-           else if (cg->ppd_conform == PPD_CONFORM_STRICT)
+           else if (pg->ppd_conform == PPD_CONFORM_STRICT)
            {
-             cg->ppd_status = PPD_BAD_UI_CONSTRAINTS;
+             pg->ppd_status = PPD_BAD_UI_CONSTRAINTS;
              goto error;
            }
 
            if (constraint->choice1[0] == '*')
            {
-             if (cg->ppd_conform == PPD_CONFORM_STRICT &&
+             if (pg->ppd_conform == PPD_CONFORM_STRICT &&
                  constraint->option2[0] == '*')
              {
-               cg->ppd_status = PPD_BAD_UI_CONSTRAINTS;
+               pg->ppd_status = PPD_BAD_UI_CONSTRAINTS;
                goto error;
              }
 
@@ -1802,9 +1824,9 @@ _ppdOpen(
            {
              if (constraint->option2[0] == '*')
                _cups_strcpy(constraint->option2, constraint->option2 + 1);
-             else if (cg->ppd_conform == PPD_CONFORM_STRICT)
+             else if (pg->ppd_conform == PPD_CONFORM_STRICT)
              {
-               cg->ppd_status = PPD_BAD_UI_CONSTRAINTS;
+               pg->ppd_status = PPD_BAD_UI_CONSTRAINTS;
                goto error;
              }
 
@@ -1817,43 +1839,43 @@ _ppdOpen(
            * Check for broken constraints like "* Option"...
            */
 
-           if (cg->ppd_conform == PPD_CONFORM_STRICT &&
+           if (pg->ppd_conform == PPD_CONFORM_STRICT &&
                (!strcmp(constraint->option1, "*") ||
                 !strcmp(constraint->choice1, "*") ||
                 !strcmp(constraint->option2, "*") ||
                 !strcmp(constraint->choice2, "*")))
            {
-             cg->ppd_status = PPD_BAD_UI_CONSTRAINTS;
+             pg->ppd_status = PPD_BAD_UI_CONSTRAINTS;
              goto error;
            }
 
            if (constraint->option1[0] == '*')
              _cups_strcpy(constraint->option1, constraint->option1 + 1);
-           else if (cg->ppd_conform == PPD_CONFORM_STRICT)
+           else if (pg->ppd_conform == PPD_CONFORM_STRICT)
            {
-             cg->ppd_status = PPD_BAD_UI_CONSTRAINTS;
+             pg->ppd_status = PPD_BAD_UI_CONSTRAINTS;
              goto error;
            }
 
-            if (cg->ppd_conform == PPD_CONFORM_STRICT &&
+            if (pg->ppd_conform == PPD_CONFORM_STRICT &&
                constraint->choice1[0] == '*')
            {
-             cg->ppd_status = PPD_BAD_UI_CONSTRAINTS;
+             pg->ppd_status = PPD_BAD_UI_CONSTRAINTS;
              goto error;
            }
 
            if (constraint->option2[0] == '*')
              _cups_strcpy(constraint->option2, constraint->option2 + 1);
-           else if (cg->ppd_conform == PPD_CONFORM_STRICT)
+           else if (pg->ppd_conform == PPD_CONFORM_STRICT)
            {
-             cg->ppd_status = PPD_BAD_UI_CONSTRAINTS;
+             pg->ppd_status = PPD_BAD_UI_CONSTRAINTS;
              goto error;
            }
 
-            if (cg->ppd_conform == PPD_CONFORM_STRICT &&
+            if (pg->ppd_conform == PPD_CONFORM_STRICT &&
                constraint->choice2[0] == '*')
            {
-             cg->ppd_status = PPD_BAD_UI_CONSTRAINTS;
+             pg->ppd_status = PPD_BAD_UI_CONSTRAINTS;
              goto error;
            }
            break;
@@ -1877,7 +1899,7 @@ _ppdOpen(
         * Unable to add or find size!
        */
 
-        cg->ppd_status = PPD_ALLOC_ERROR;
+        pg->ppd_status = PPD_ALLOC_ERROR;
 
        goto error;
       }
@@ -1899,7 +1921,7 @@ _ppdOpen(
         * Unable to add or find size!
        */
 
-        cg->ppd_status = PPD_ALLOC_ERROR;
+        pg->ppd_status = PPD_ALLOC_ERROR;
 
        goto error;
       }
@@ -1935,7 +1957,7 @@ _ppdOpen(
 
       if ((choice = ppd_add_choice(option, name)) == NULL)
       {
-        cg->ppd_status = PPD_ALLOC_ERROR;
+        pg->ppd_status = PPD_ALLOC_ERROR;
 
        goto error;
       }
@@ -1944,9 +1966,9 @@ _ppdOpen(
         cupsCharsetToUTF8((cups_utf8_t *)choice->text, text,
                           sizeof(choice->text), encoding);
       else if (!strcmp(name, "True"))
-        strcpy(choice->text, _("Yes"));
+        strlcpy(choice->text, _("Yes"), sizeof(choice->text));
       else if (!strcmp(name, "False"))
-        strcpy(choice->text, _("No"));
+        strlcpy(choice->text, _("No"), sizeof(choice->text));
       else
         strlcpy(choice->text, name, sizeof(choice->text));
 
@@ -1972,9 +1994,9 @@ _ppdOpen(
   * Check for a missing CloseGroup...
   */
 
-  if (group && cg->ppd_conform == PPD_CONFORM_STRICT)
+  if (group && pg->ppd_conform == PPD_CONFORM_STRICT)
   {
-    cg->ppd_status = PPD_MISSING_CLOSE_GROUP;
+    pg->ppd_status = PPD_MISSING_CLOSE_GROUP;
     goto error;
   }
 
@@ -1990,7 +2012,7 @@ _ppdOpen(
                   (unsigned long)cupsFileTell(fp)));
 #endif /* DEBUG */
 
-  if (cg->ppd_status != PPD_OK)
+  if (pg->ppd_status != PPD_OK)
   {
    /*
     * Had an error reading the PPD file, cannot continue!
@@ -2005,7 +2027,7 @@ _ppdOpen(
   * Update the filters array as needed...
   */
 
-  if (!ppd_update_filters(ppd, cg))
+  if (!ppd_update_filters(ppd, pg))
   {
     ppdClose(ppd);
 
@@ -2106,7 +2128,7 @@ ppdOpen(FILE *fp)                 /* I - File to read from */
 /*
  * 'ppdOpen2()' - Read a PPD file into memory.
  *
- * @since CUPS 1.2/Mac OS X 10.5@
+ * @since CUPS 1.2/macOS 10.5@
  */
 
 ppd_file_t *                           /* O - PPD file record or @code NULL@ if the PPD file could not be opened. */
@@ -2125,7 +2147,7 @@ ppdOpenFd(int fd)                 /* I - File to read from */
 {
   cups_file_t          *fp;            /* CUPS file pointer */
   ppd_file_t           *ppd;           /* PPD file record */
-  _cups_globals_t      *cg = _cupsGlobals();
+  _ppd_globals_t       *pg = _ppdGlobals();
                                        /* Global data */
 
 
@@ -2133,7 +2155,7 @@ ppdOpenFd(int fd)                 /* I - File to read from */
   * Set the line number to 0...
   */
 
-  cg->ppd_line = 0;
+  pg->ppd_line = 0;
 
  /*
   * Range check input...
@@ -2141,7 +2163,7 @@ ppdOpenFd(int fd)                 /* I - File to read from */
 
   if (fd < 0)
   {
-    cg->ppd_status = PPD_NULL_FILE;
+    pg->ppd_status = PPD_NULL_FILE;
 
     return (NULL);
   }
@@ -2158,7 +2180,7 @@ ppdOpenFd(int fd)                 /* I - File to read from */
   }
   else
   {
-    cg->ppd_status = PPD_FILE_OPEN_ERROR;
+    pg->ppd_status = PPD_FILE_OPEN_ERROR;
     ppd            = NULL;
   }
 
@@ -2176,7 +2198,7 @@ _ppdOpenFile(const char             *filename,    /* I - File to read from */
 {
   cups_file_t          *fp;            /* File pointer */
   ppd_file_t           *ppd;           /* PPD file record */
-  _cups_globals_t      *cg = _cupsGlobals();
+  _ppd_globals_t       *pg = _ppdGlobals();
                                        /* Global data */
 
 
@@ -2184,7 +2206,7 @@ _ppdOpenFile(const char             *filename,    /* I - File to read from */
   * Set the line number to 0...
   */
 
-  cg->ppd_line = 0;
+  pg->ppd_line = 0;
 
  /*
   * Range check input...
@@ -2192,7 +2214,7 @@ _ppdOpenFile(const char             *filename,    /* I - File to read from */
 
   if (filename == NULL)
   {
-    cg->ppd_status = PPD_NULL_FILE;
+    pg->ppd_status = PPD_NULL_FILE;
 
     return (NULL);
   }
@@ -2209,7 +2231,7 @@ _ppdOpenFile(const char             *filename,    /* I - File to read from */
   }
   else
   {
-    cg->ppd_status = PPD_FILE_OPEN_ERROR;
+    pg->ppd_status = PPD_FILE_OPEN_ERROR;
     ppd            = NULL;
   }
 
@@ -2231,17 +2253,17 @@ ppdOpenFile(const char *filename)       /* I - File to read from */
 /*
  * 'ppdSetConformance()' - Set the conformance level for PPD files.
  *
- * @since CUPS 1.1.20/Mac OS X 10.4@
+ * @since CUPS 1.1.20/macOS 10.4@
  */
 
 void
 ppdSetConformance(ppd_conform_t c)     /* I - Conformance level */
 {
-  _cups_globals_t      *cg = _cupsGlobals();
+  _ppd_globals_t       *pg = _ppdGlobals();
                                        /* Global data */
 
 
-  cg->ppd_conform = c;
+  pg->ppd_conform = c;
 }
 
 
@@ -2282,7 +2304,7 @@ ppd_add_attr(ppd_file_t *ppd,             /* I - PPD file data */
   if (ppd->num_attrs == 0)
     ptr = malloc(sizeof(ppd_attr_t *));
   else
-    ptr = realloc(ppd->attrs, (ppd->num_attrs + 1) * sizeof(ppd_attr_t *));
+    ptr = realloc(ppd->attrs, (size_t)(ppd->num_attrs + 1) * sizeof(ppd_attr_t *));
 
   if (ptr == NULL)
     return (NULL);
@@ -2334,8 +2356,7 @@ ppd_add_choice(ppd_option_t *option,      /* I - Option */
   if (option->num_choices == 0)
     choice = malloc(sizeof(ppd_choice_t));
   else
-    choice = realloc(option->choices,
-                    sizeof(ppd_choice_t) * (option->num_choices + 1));
+    choice = realloc(option->choices, sizeof(ppd_choice_t) * (size_t)(option->num_choices + 1));
 
   if (choice == NULL)
     return (NULL);
@@ -2365,7 +2386,7 @@ ppd_add_size(ppd_file_t *ppd,             /* I - PPD file */
   if (ppd->num_sizes == 0)
     size = malloc(sizeof(ppd_size_t));
   else
-    size = realloc(ppd->sizes, sizeof(ppd_size_t) * (ppd->num_sizes + 1));
+    size = realloc(ppd->sizes, sizeof(ppd_size_t) * (size_t)(ppd->num_sizes + 1));
 
   if (size == NULL)
     return (NULL);
@@ -2454,9 +2475,9 @@ ppd_decode(char *string)          /* I - String to decode */
       while (isxdigit(*inptr & 255))
       {
        if (_cups_isalpha(*inptr))
-         *outptr = (tolower(*inptr) - 'a' + 10) << 4;
+         *outptr = (char)((tolower(*inptr) - 'a' + 10) << 4);
        else
-         *outptr = (*inptr - '0') << 4;
+         *outptr = (char)((*inptr - '0') << 4);
 
        inptr ++;
 
@@ -2464,9 +2485,9 @@ ppd_decode(char *string)          /* I - String to decode */
          break;
 
        if (_cups_isalpha(*inptr))
-         *outptr |= tolower(*inptr) - 'a' + 10;
+         *outptr |= (char)(tolower(*inptr) - 'a' + 10);
        else
-         *outptr |= *inptr - '0';
+         *outptr |= (char)(*inptr - '0');
 
        inptr ++;
        outptr ++;
@@ -2659,7 +2680,7 @@ static ppd_group_t *                      /* O - Named group */
 ppd_get_group(ppd_file_t      *ppd,    /* I - PPD file */
               const char      *name,   /* I - Name of group */
              const char      *text,    /* I - Text for group */
-              _cups_globals_t *cg,     /* I - Global data */
+              _ppd_globals_t  *pg,     /* I - Global data */
              cups_encoding_t encoding) /* I - Encoding of text */
 {
   int          i;                      /* Looping var */
@@ -2667,7 +2688,7 @@ ppd_get_group(ppd_file_t      *ppd,       /* I - PPD file */
 
 
   DEBUG_printf(("7ppd_get_group(ppd=%p, name=\"%s\", text=\"%s\", cg=%p)",
-                ppd, name, text, cg));
+                ppd, name, text, pg));
 
   for (i = ppd->num_groups, group = ppd->groups; i > 0; i --, group ++)
     if (!strcmp(group->name, name))
@@ -2677,9 +2698,9 @@ ppd_get_group(ppd_file_t      *ppd,       /* I - PPD file */
   {
     DEBUG_printf(("8ppd_get_group: Adding group %s...", name));
 
-    if (cg->ppd_conform == PPD_CONFORM_STRICT && strlen(text) >= sizeof(group->text))
+    if (pg->ppd_conform == PPD_CONFORM_STRICT && strlen(text) >= sizeof(group->text))
     {
-      cg->ppd_status = PPD_ILLEGAL_TRANSLATION;
+      pg->ppd_status = PPD_ILLEGAL_TRANSLATION;
 
       return (NULL);
     }
@@ -2687,12 +2708,11 @@ ppd_get_group(ppd_file_t      *ppd,     /* I - PPD file */
     if (ppd->num_groups == 0)
       group = malloc(sizeof(ppd_group_t));
     else
-      group = realloc(ppd->groups,
-                     (ppd->num_groups + 1) * sizeof(ppd_group_t));
+      group = realloc(ppd->groups, (size_t)(ppd->num_groups + 1) * sizeof(ppd_group_t));
 
     if (group == NULL)
     {
-      cg->ppd_status = PPD_ALLOC_ERROR;
+      pg->ppd_status = PPD_ALLOC_ERROR;
 
       return (NULL);
     }
@@ -2736,8 +2756,7 @@ ppd_get_option(ppd_group_t *group,        /* I - Group */
     if (group->num_options == 0)
       option = malloc(sizeof(ppd_option_t));
     else
-      option = realloc(group->options,
-                      (group->num_options + 1) * sizeof(ppd_option_t));
+      option = realloc(group->options, (size_t)(group->num_options + 1) * sizeof(ppd_option_t));
 
     if (option == NULL)
       return (NULL);
@@ -2754,6 +2773,47 @@ ppd_get_option(ppd_group_t *group,       /* I - Group */
 }
 
 
+/*
+ * 'ppd_globals_alloc()' - Allocate and initialize global data.
+ */
+
+static _ppd_globals_t *                /* O - Pointer to global data */
+ppd_globals_alloc(void)
+{
+  return ((_ppd_globals_t *)calloc(1, sizeof(_ppd_globals_t)));
+}
+
+
+/*
+ * 'ppd_globals_free()' - Free global data.
+ */
+
+#if defined(HAVE_PTHREAD_H) || defined(WIN32)
+static void
+ppd_globals_free(_ppd_globals_t *pg)   /* I - Pointer to global data */
+{
+  free(pg);
+}
+#endif /* HAVE_PTHREAD_H || WIN32 */
+
+
+#ifdef HAVE_PTHREAD_H
+/*
+ * 'ppd_globals_init()' - Initialize per-thread globals...
+ */
+
+static void
+ppd_globals_init(void)
+{
+ /*
+  * Register the global data for this thread...
+  */
+
+  pthread_key_create(&ppd_globals_key, (void (*)(void *))ppd_globals_free);
+}
+#endif /* HAVE_PTHREAD_H */
+
+
 /*
  * 'ppd_hash_option()' - Generate a hash of the option name...
  */
@@ -2785,7 +2845,7 @@ ppd_read(cups_file_t    *fp,              /* I - File to read from */
          char           *text,         /* O - Human-readable text from line */
         char           **string,       /* O - Code/string data */
          int            ignoreblank,   /* I - Ignore blank lines? */
-        _cups_globals_t *cg)           /* I - Global data */
+        _ppd_globals_t *pg)            /* I - Global data */
 {
   int          ch,                     /* Character from file */
                col,                    /* Column in line */
@@ -2807,7 +2867,7 @@ ppd_read(cups_file_t    *fp,              /* I - File to read from */
 
   *string   = NULL;
   col       = 0;
-  startline = cg->ppd_line + 1;
+  startline = pg->ppd_line + 1;
 
   if (!line->buffer)
   {
@@ -2846,8 +2906,8 @@ ppd_read(cups_file_t    *fp,              /* I - File to read from */
          * Don't allow lines longer than 256k!
          */
 
-          cg->ppd_line   = startline;
-          cg->ppd_status = PPD_LINE_TOO_LONG;
+          pg->ppd_line   = startline;
+          pg->ppd_status = PPD_LINE_TOO_LONG;
 
          return (0);
        }
@@ -2855,8 +2915,8 @@ ppd_read(cups_file_t    *fp,              /* I - File to read from */
         temp = realloc(line->buffer, line->bufsize);
        if (!temp)
        {
-          cg->ppd_line   = startline;
-          cg->ppd_status = PPD_LINE_TOO_LONG;
+          pg->ppd_line   = startline;
+          pg->ppd_status = PPD_LINE_TOO_LONG;
 
          return (0);
        }
@@ -2871,7 +2931,7 @@ ppd_read(cups_file_t    *fp,              /* I - File to read from */
        * Line feed or carriage return...
        */
 
-        cg->ppd_line ++;
+        pg->ppd_line ++;
        col = 0;
 
        if (ch == '\r')
@@ -2900,14 +2960,14 @@ ppd_read(cups_file_t    *fp,            /* I - File to read from */
 
        *lineptr++ = '\n';
       }
-      else if (ch < ' ' && ch != '\t' && cg->ppd_conform == PPD_CONFORM_STRICT)
+      else if (ch < ' ' && ch != '\t' && pg->ppd_conform == PPD_CONFORM_STRICT)
       {
        /*
         * Other control characters...
        */
 
-        cg->ppd_line   = startline;
-        cg->ppd_status = PPD_ILLEGAL_CHARACTER;
+        pg->ppd_line   = startline;
+        pg->ppd_status = PPD_ILLEGAL_CHARACTER;
 
         return (0);
       }
@@ -2917,7 +2977,7 @@ ppd_read(cups_file_t    *fp,              /* I - File to read from */
        * Any other character...
        */
 
-       *lineptr++ = ch;
+       *lineptr++ = (char)ch;
        col ++;
 
        if (col > (PPD_MAX_LINE - 1))
@@ -2926,8 +2986,8 @@ ppd_read(cups_file_t    *fp,              /* I - File to read from */
           * Line is too long...
          */
 
-          cg->ppd_line   = startline;
-          cg->ppd_status = PPD_LINE_TOO_LONG;
+          pg->ppd_line   = startline;
+          pg->ppd_status = PPD_LINE_TOO_LONG;
 
           return (0);
        }
@@ -2951,7 +3011,7 @@ ppd_read(cups_file_t    *fp,              /* I - File to read from */
          break;
        else if (ch == '\r' || ch == '\n')
        {
-         cg->ppd_line ++;
+         pg->ppd_line ++;
          col = 0;
 
          if (ch == '\r')
@@ -2966,14 +3026,14 @@ ppd_read(cups_file_t    *fp,            /* I - File to read from */
              cupsFileGetChar(fp);
          }
        }
-       else if (ch < ' ' && ch != '\t' && cg->ppd_conform == PPD_CONFORM_STRICT)
+       else if (ch < ' ' && ch != '\t' && pg->ppd_conform == PPD_CONFORM_STRICT)
        {
         /*
           * Other control characters...
          */
 
-          cg->ppd_line   = startline;
-          cg->ppd_status = PPD_ILLEGAL_CHARACTER;
+          pg->ppd_line   = startline;
+          pg->ppd_status = PPD_ILLEGAL_CHARACTER;
 
           return (0);
        }
@@ -2987,8 +3047,8 @@ ppd_read(cups_file_t    *fp,              /* I - File to read from */
             * Line is too long...
            */
 
-            cg->ppd_line   = startline;
-            cg->ppd_status = PPD_LINE_TOO_LONG;
+            pg->ppd_line   = startline;
+            pg->ppd_status = PPD_LINE_TOO_LONG;
 
             return (0);
          }
@@ -3008,7 +3068,7 @@ ppd_read(cups_file_t    *fp,              /* I - File to read from */
          * Line feed or carriage return...
          */
 
-          cg->ppd_line ++;
+          pg->ppd_line ++;
          col = 0;
 
          if (ch == '\r')
@@ -3025,14 +3085,14 @@ ppd_read(cups_file_t    *fp,            /* I - File to read from */
 
          break;
        }
-       else if (ch < ' ' && ch != '\t' && cg->ppd_conform == PPD_CONFORM_STRICT)
+       else if (ch < ' ' && ch != '\t' && pg->ppd_conform == PPD_CONFORM_STRICT)
        {
         /*
           * Other control characters...
          */
 
-          cg->ppd_line   = startline;
-          cg->ppd_status = PPD_ILLEGAL_CHARACTER;
+          pg->ppd_line   = startline;
+          pg->ppd_status = PPD_ILLEGAL_CHARACTER;
 
           return (0);
        }
@@ -3046,8 +3106,8 @@ ppd_read(cups_file_t    *fp,              /* I - File to read from */
             * Line is too long...
            */
 
-            cg->ppd_line   = startline;
-            cg->ppd_status = PPD_LINE_TOO_LONG;
+            pg->ppd_line   = startline;
+            pg->ppd_status = PPD_LINE_TOO_LONG;
 
             return (0);
          }
@@ -3062,7 +3122,7 @@ ppd_read(cups_file_t    *fp,              /* I - File to read from */
     DEBUG_printf(("9ppd_read: LINE=\"%s\"", line->buffer));
 
    /*
-    * The dynamically created PPDs for older style Mac OS X
+    * The dynamically created PPDs for older style macOS
     * drivers include a large blob of data inserted as comments
     * at the end of the file.  As an optimization we can stop
     * reading the PPD when we get to the start of this data.
@@ -3091,21 +3151,21 @@ ppd_read(cups_file_t    *fp,            /* I - File to read from */
          !strcmp(line->buffer, "*End")) && /* End of multi-line string */
         ignoreblank)                   /* Ignore these? */
     {
-      startline = cg->ppd_line + 1;
+      startline = pg->ppd_line + 1;
       continue;
     }
 
     if (!strcmp(line->buffer, "*"))    /* (Bad) comment line */
     {
-      if (cg->ppd_conform == PPD_CONFORM_RELAXED)
+      if (pg->ppd_conform == PPD_CONFORM_RELAXED)
       {
-       startline = cg->ppd_line + 1;
+       startline = pg->ppd_line + 1;
        continue;
       }
       else
       {
-        cg->ppd_line   = startline;
-        cg->ppd_status = PPD_ILLEGAL_MAIN_KEYWORD;
+        pg->ppd_line   = startline;
+        pg->ppd_status = PPD_ILLEGAL_MAIN_KEYWORD;
 
         return (0);
       }
@@ -3123,7 +3183,7 @@ ppd_read(cups_file_t    *fp,              /* I - File to read from */
 
       if (*lineptr)
       {
-        cg->ppd_status = PPD_MISSING_ASTERISK;
+        pg->ppd_status = PPD_MISSING_ASTERISK;
         return (0);
       }
       else if (ignoreblank)
@@ -3143,7 +3203,7 @@ ppd_read(cups_file_t    *fp,              /* I - File to read from */
       if (*lineptr <= ' ' || *lineptr > 126 || *lineptr == '/' ||
           (keyptr - keyword) >= (PPD_MAX_NAME - 1))
       {
-        cg->ppd_status = PPD_ILLEGAL_MAIN_KEYWORD;
+        pg->ppd_status = PPD_ILLEGAL_MAIN_KEYWORD;
        return (0);
       }
 
@@ -3174,7 +3234,7 @@ ppd_read(cups_file_t    *fp,              /* I - File to read from */
        if (*lineptr <= ' ' || *lineptr > 126 ||
            (optptr - option) >= (PPD_MAX_NAME - 1))
         {
-          cg->ppd_status = PPD_ILLEGAL_OPTION_KEYWORD;
+          pg->ppd_status = PPD_ILLEGAL_OPTION_KEYWORD;
          return (0);
        }
 
@@ -3183,9 +3243,9 @@ ppd_read(cups_file_t    *fp,              /* I - File to read from */
 
       *optptr = '\0';
 
-      if (_cups_isspace(*lineptr) && cg->ppd_conform == PPD_CONFORM_STRICT)
+      if (_cups_isspace(*lineptr) && pg->ppd_conform == PPD_CONFORM_STRICT)
       {
-        cg->ppd_status = PPD_ILLEGAL_WHITESPACE;
+        pg->ppd_status = PPD_ILLEGAL_WHITESPACE;
        return (0);
       }
 
@@ -3209,7 +3269,7 @@ ppd_read(cups_file_t    *fp,              /* I - File to read from */
          if (((unsigned char)*lineptr < ' ' && *lineptr != '\t') ||
              (textptr - text) >= (PPD_MAX_LINE - 1))
          {
-           cg->ppd_status = PPD_ILLEGAL_TRANSLATION;
+           pg->ppd_status = PPD_ILLEGAL_TRANSLATION;
            return (0);
          }
 
@@ -3219,9 +3279,9 @@ ppd_read(cups_file_t    *fp,              /* I - File to read from */
        *textptr = '\0';
        textlen  = ppd_decode(text);
 
-       if (textlen > PPD_MAX_TEXT && cg->ppd_conform == PPD_CONFORM_STRICT)
+       if (textlen > PPD_MAX_TEXT && pg->ppd_conform == PPD_CONFORM_STRICT)
        {
-         cg->ppd_status = PPD_ILLEGAL_TRANSLATION;
+         pg->ppd_status = PPD_ILLEGAL_TRANSLATION;
          return (0);
        }
 
@@ -3229,9 +3289,9 @@ ppd_read(cups_file_t    *fp,              /* I - File to read from */
       }
     }
 
-    if (_cups_isspace(*lineptr) && cg->ppd_conform == PPD_CONFORM_STRICT)
+    if (_cups_isspace(*lineptr) && pg->ppd_conform == PPD_CONFORM_STRICT)
     {
-      cg->ppd_status = PPD_ILLEGAL_WHITESPACE;
+      pg->ppd_status = PPD_ILLEGAL_WHITESPACE;
       return (0);
     }
 
@@ -3283,8 +3343,8 @@ ppd_read(cups_file_t    *fp,              /* I - File to read from */
  */
 
 static int                             /* O - 1 on success, 0 on failure */
-ppd_update_filters(ppd_file_t      *ppd,/* I - PPD file */
-                   _cups_globals_t *cg)        /* I - Global data */
+ppd_update_filters(ppd_file_t     *ppd,        /* I - PPD file */
+                   _ppd_globals_t *pg) /* I - Global data */
 {
   ppd_attr_t   *attr;                  /* Current cupsFilter2 value */
   char         srcsuper[16],           /* Source MIME media type */
@@ -3298,7 +3358,7 @@ ppd_update_filters(ppd_file_t      *ppd,/* I - PPD file */
   int          cost;                   /* Cost of filter */
 
 
-  DEBUG_printf(("4ppd_update_filters(ppd=%p, cg=%p)", ppd, cg));
+  DEBUG_printf(("4ppd_update_filters(ppd=%p, cg=%p)", ppd, pg));
 
  /*
   * See if we have any cupsFilter2 lines...
@@ -3331,7 +3391,7 @@ ppd_update_filters(ppd_file_t      *ppd,/* I - PPD file */
               srcsuper, srctype, dstsuper, dsttype, &cost, program) != 6)
     {
       DEBUG_puts("5ppd_update_filters: Bad cupsFilter2 line.");
-      cg->ppd_status = PPD_BAD_VALUE;
+      pg->ppd_status = PPD_BAD_VALUE;
 
       return (0);
     }
@@ -3370,12 +3430,12 @@ ppd_update_filters(ppd_file_t      *ppd,/* I - PPD file */
     if (ppd->num_filters == 0)
       filter = malloc(sizeof(char *));
     else
-      filter = realloc(ppd->filters, sizeof(char *) * (ppd->num_filters + 1));
+      filter = realloc(ppd->filters, sizeof(char *) * (size_t)(ppd->num_filters + 1));
 
     if (filter == NULL)
     {
       DEBUG_puts("5ppd_update_filters: Out of memory.");
-      cg->ppd_status = PPD_ALLOC_ERROR;
+      pg->ppd_status = PPD_ALLOC_ERROR;
 
       return (0);
     }
@@ -3391,8 +3451,3 @@ ppd_update_filters(ppd_file_t      *ppd,/* I - PPD file */
   DEBUG_puts("5ppd_update_filters: Completed OK.");
   return (1);
 }
-
-
-/*
- * End of "$Id: ppd.c 9900 2011-08-17 20:59:46Z mike $".
- */