]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Make CUPS API threadsafe (STR #1276), replace FILE's with
authormike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Wed, 21 Sep 2005 09:28:39 +0000 (09:28 +0000)
committermike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Wed, 21 Sep 2005 09:28:39 +0000 (09:28 +0000)
cups_file_t's in several places, and drop CUPS_STRFTIME_FORMAT
usage.

cgi-bin/ipp-var.c:
    - ippSetCGIVars(): Use "%c" instead of CUPS_STRFTIME_FORMAT.

config.h.in:
    - Add HAVE_PTHREAD_H define.
    - Remote CUPS_STRFTIME_FORMAT define.

config-scripts/cups-common.m4:
    - Remove CUPS_STRFTIME_FORMAT definitions.

config-scripts/cups-threads.m4:
    - Added.

configure.in:
    - Include config-scripts/cups-threads.m4.

cups/emit.c:
    - Make PS code string a constant character array instead of a
      string pointer.

cups/globals.c:
cups/globals.h:
    - Added.

cups/http-addr.c:
    - httpGetHostByName(): Use _cupsGlobals() to get thread-local
      data.

cups/http.c:
    - httpGetDateString(): Use _cupsGlobals() to get thread-local
      data.

cups/ipp.c:
    - General documentation cleanup.
    - ippDateToTime(): Use _cupsGlobals() to get thread-local
      data.
    - ippDeleteAttribute(): Implemented.

cups/ipp-support.c:
    - ippErrorString(), ippOpString(), ippPort(), ippSetPort():
      Use _cupsGlobals() to get thread-local data.

cups/language.c:
    - cupsLangFlush(), cupsLangGet(), appleLangDefault(): Use
      _cupsGlobals() to get thread-local data.

cups/normalize.c:
    - cupsNormalizeMapsGet(), cupsNormalizeMapsFree(),
      cupsNormalizeMapsFlush(), cupsUTF32Normalize(),
      cupsUTF32CaseFold(): Use _cupsGlobals() to get thread-local
      data.
    - get_general_category(), get_bidi_category(),
      get_combining_class(), get_break_class(), get_normmap(),
      get_foldmap(), get_propmap(), get_combmap(),
      get_breakmap(): Use _cupsGlobals() to get thread-local
      data, and use cups_file_t and associated functions instead
      of stdio.

cups/ppd.c:
    - ppdLastError(), ppdOpen2(), ppdOpenFd(),
      ppdSetConformance(): Use _cupsGlobals() to get thread-local
      data.
    - ppdOpenFile(): Use _cupsGlobals() to get thread-local data,
      and use cups_file_t and associated functions instead of
      stdio.
    - ppd_get_group(), ppd_read(): Add and use cups_globals_t
      pointer argument for thread-local data.

cups/tempfile.c:
    - cupsTempFd(): Drop allocation of static filename buffer.
    - cupsTempFile(): Use _cupsGlobals() to get thread-local
      filename buffer.

cups/transcode.c:
    - cupsCharmapFree(), cupsCharmapFlush(): Use _cupsGlobals()
      to get thread-local data.
    - get_sbcs_charmap(), get_vbcs_charmap(): Use _cupsGlobals()
      to get thread-local data, and use cups_file_t and
      associated functions instead of stdio.

cups/usersys.c:
    - cupsEncryption(), cupsServer(): Use _cupsGlobals() to get
      thread-local data, and use cups_file_t and associated
      functions instead of stdio.
    - cupsSetEncryption(), cupsSetPasswordCB(), cupsSetServer(),
      cupsSetUser(), cupsUser(): Use _cupsGlobals() to get
      thread-local data.

cups/util.c:
    - cupsCancelJob(), cupsDoFileRequest(), cupsGetClasses(),
      cupsGetDefault(), cupsGetDefault2(), cupsGetJobs(),
      cupsGetJobs2(), cupsGetPPD(), cupsGetPPD2(),
      cupsGetPrinters(), cupsPrintFiles(), cupsPrintFiles2(),
      cups_connect(): Use _cupsGlobals() to get thread-local
      data.

filter/hpgl-prolog.c:
    - OutputProlog(): Use "%c" instead of CUPS_STRFTIME_FORMAT.

filter/imagetops.c:
    - main(): Use "%c" instead of CUPS_STRFTIME_FORMAT.

filter/texttops.c:
    - WriteProlog(): Use "%c" instead of CUPS_STRFTIME_FORMAT.

scheduler/classes.c:
    - SaveAllClasses(): Use "%c" instead of CUPS_STRFTIME_FORMAT.

scheduler/printers.c:
    - SaveAllPrinters(): Use "%c" instead of CUPS_STRFTIME_FORMAT.

scheduler/subscriptions.c:
    - SaveAllSubscriptions(): Use "%c" instead of CUPS_STRFTIME_FORMAT.

systemv/lpstat.c:
    - show_jobs(): Use "%c" instead of CUPS_STRFTIME_FORMAT.

git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@4680 7a7537e8-13f0-0310-91df-b6672ffda945

30 files changed:
CHANGES.txt
cgi-bin/ipp-var.c
config-scripts/cups-common.m4
config-scripts/cups-threads.m4 [new file with mode: 0644]
config.h.in
configure.in
cups/Dependencies
cups/Makefile
cups/emit.c
cups/globals.c [new file with mode: 0644]
cups/globals.h [new file with mode: 0644]
cups/http-addr.c
cups/http.c
cups/ipp-support.c
cups/ipp.c
cups/language.c
cups/normalize.c
cups/ppd.c
cups/tempfile.c
cups/transcode.c
cups/usersys.c
cups/util.c
filter/hpgl-prolog.c
filter/imagetops.c
filter/texttops.c
scheduler/Makefile
scheduler/classes.c
scheduler/printers.c
scheduler/subscriptions.c
systemv/lpstat.c

index fe05a5229469785ec93bc22d2a08fbd42529a7bc..9e7be93b87369ac0a5e076d207cab91ec2a5fb36 100644 (file)
@@ -1,8 +1,9 @@
-CHANGES.txt - 09/18/2005
+CHANGES.txt - 09/21/2005
 ------------------------
 
 CHANGES IN CUPS V1.2.0b1
 
+       - Made the CUPS API library thread-safe (STR #1276)
        - Added "media" option support for EFI EFMediaType option
          (STR #902)
        - Added write buffering to the HTTP code to improve
index 308eeae4c4c36da297398cc791d641bc50a90617..c74624b5cf503bb83d73af8b531f6e45a2655b08 100644 (file)
@@ -486,8 +486,7 @@ ippSetCGIVars(ipp_t      *response, /* I - Response data to be copied... */
                 t    = (time_t)attr->values[i].integer;
                date = localtime(&t);
 
-               strftime(valptr, sizeof(value) - (valptr - value),
-                        CUPS_STRFTIME_FORMAT, date);
+               strftime(valptr, sizeof(value) - (valptr - value), "%c", date);
              }
              else
                snprintf(valptr, sizeof(value) - (valptr - value),
index dc8b86bf8afdffcaaccd7dd24804b3b6bdc6a329..99da437bea7716b0bc038e53a6c783d7bdc22d98 100644 (file)
@@ -134,22 +134,6 @@ else
        AC_CHECK_FUNCS(snprintf vsnprintf)
 fi
 
-dnl Check OS version and use appropriate format string for strftime...
-AC_MSG_CHECKING(for correct format string to use with strftime)
-
-case "$uname" in
-       IRIX | SunOS*)
-               # IRIX and SunOS
-               AC_MSG_RESULT(NULL)
-               AC_DEFINE(CUPS_STRFTIME_FORMAT, NULL)
-               ;;
-       *)
-               # All others
-               AC_MSG_RESULT("%c")
-               AC_DEFINE(CUPS_STRFTIME_FORMAT, "%c")
-               ;;
-esac
-
 dnl Checks for mkstemp and mkstemps functions.
 AC_CHECK_FUNCS(mkstemp mkstemps)
 
diff --git a/config-scripts/cups-threads.m4 b/config-scripts/cups-threads.m4
new file mode 100644 (file)
index 0000000..69e8c03
--- /dev/null
@@ -0,0 +1,53 @@
+dnl
+dnl "$Id$"
+dnl
+dnl   Threading stuff for the Common UNIX Printing System (CUPS).
+dnl
+dnl   Copyright 1997-2005 by Easy Software Products, all rights reserved.
+dnl
+dnl   These coded instructions, statements, and computer programs are the
+dnl   property of Easy Software Products and are protected by Federal
+dnl   copyright law.  Distribution and use rights are outlined in the file
+dnl   "LICENSE.txt" which should have been included with this file.  If this
+dnl   file is missing or damaged please contact Easy Software Products
+dnl   at:
+dnl
+dnl       Attn: CUPS Licensing Information
+dnl       Easy Software Products
+dnl       44141 Airport View Drive, Suite 204
+dnl       Hollywood, Maryland 20636 USA
+dnl
+dnl       Voice: (301) 373-9600
+dnl       EMail: cups-info@cups.org
+dnl         WWW: http://www.cups.org
+dnl
+
+AC_ARG_ENABLE(threads, [  --enable-threads        enable multi-threading support])
+
+have_pthread=no
+
+if test "x$enable_threads" != xno; then
+       AC_CHECK_HEADER(pthread.h, AC_DEFINE(HAVE_PTHREAD_H))
+       AC_CHECK_LIB(pthread, pthread_create,
+               COMMONLIBS="-lpthread $COMMONLIBS")
+
+       if test "x$ac_cv_lib_pthread_pthread_create" = xyes -a x$ac_cv_header_pthread_h = xyes; then
+               have_pthread=yes
+       else
+               dnl *BSD uses -pthread option...
+               AC_MSG_CHECKING([for pthread_create using -pthread])
+               SAVELIBS="$LIBS"
+               LIBS="-pthread $LIBS"
+               AC_TRY_LINK([#include <pthread.h>],
+                       [pthread_create(0, 0, 0, 0);],
+                       COMMONLIBS="-pthread $COMMONLIBS"
+                       have_pthread=yes)
+               LIBS="$SAVELIBS"
+               AC_MSG_RESULT([$have_pthread])
+       fi
+fi
+
+
+dnl
+dnl End of "$Id$".
+dnl
index fedcded410c43a37009a67b3f19d22c7776fe078..28d55c4655abd3552984fad0835f06e91d149daa 100644 (file)
 #define CUPS_STATEDIR  "/var/run/cups"
 
 
-/*
- * What is the format string for strftime?
- */
-
-#define CUPS_STRFTIME_FORMAT   NULL
-
-
 /*
  * Do we have various image libraries?
  */
 
 #undef HAVE_USERSEC_H
 
+/*
+ * Do we have pthread support?
+ */
+
+#undef HAVE_PTHREAD_H
+
 
 /*
  * Various scripting languages...
index 73d232376bae13aa9abfbea1bd48bccbb28b6b50..690c0ffdec0456bb508ab4c4c8c13a4f0c87ac36 100644 (file)
@@ -38,6 +38,7 @@ sinclude(config-scripts/cups-network.m4)
 sinclude(config-scripts/cups-slp.m4)
 sinclude(config-scripts/cups-ssl.m4)
 sinclude(config-scripts/cups-pam.m4)
+sinclude(config-scripts/cups-threads.m4)
 
 MAKEDEFS="../Makedefs"
 AC_SUBST(MAKEDEFS)
index 26120a1cbfaac68c768b1057bf0380af546e6cd1..28da1917587b16df207c1dd3e8cd6787e20d88a6 100644 (file)
@@ -13,30 +13,40 @@ file.o: string.h ../config.h ../cups/debug.h file.h http-private.h http.h
 file.o: md5.h
 getputfile.o: cups.h ipp.h http.h string.h ../config.h md5.h ppd.h file.h
 getputfile.o: language.h debug.h
-http.o: http-private.h ../config.h http.h string.h md5.h debug.h
-http-addr.o: http.h string.h ../config.h md5.h debug.h
+globals.o: globals.h string.h ../config.h cups.h ipp.h http.h md5.h ppd.h
+globals.o: file.h language.h normalize.h transcode.h http-private.h
+http.o: http-private.h ../config.h http.h string.h md5.h globals.h cups.h
+http.o: ipp.h ppd.h file.h language.h normalize.h transcode.h debug.h
+http-addr.o: globals.h string.h ../config.h cups.h ipp.h http.h md5.h ppd.h
+http-addr.o: file.h language.h normalize.h transcode.h debug.h
 http-support.o: string.h ../config.h http.h md5.h ipp.h
-ipp.o: string.h ../config.h ipp.h http.h md5.h debug.h
-ipp-support.o: string.h ../config.h language.h ipp.h http.h md5.h debug.h
+ipp.o: globals.h string.h ../config.h cups.h ipp.h http.h md5.h ppd.h file.h
+ipp.o: language.h normalize.h transcode.h debug.h
+ipp-support.o: globals.h string.h ../config.h cups.h ipp.h http.h md5.h ppd.h
+ipp-support.o: file.h language.h normalize.h transcode.h debug.h
 langprintf.o: string.h ../config.h language.h transcode.h
-language.o: string.h ../config.h language.h debug.h cups_C.h
+language.o: globals.h string.h ../config.h cups.h ipp.h http.h md5.h ppd.h
+language.o: file.h language.h normalize.h transcode.h debug.h cups_C.h
 mark.o: ppd.h file.h string.h ../config.h debug.h
 md5.o: md5.h string.h ../config.h
 md5passwd.o: http.h string.h ../config.h md5.h
-normalize.o: string.h ../config.h language.h transcode.h normalize.h
+normalize.o: globals.h string.h ../config.h cups.h ipp.h http.h md5.h ppd.h
+normalize.o: file.h language.h normalize.h transcode.h debug.h
 options.o: cups.h ipp.h http.h string.h ../config.h md5.h ppd.h file.h
 options.o: debug.h
 page.o: ppd.h file.h string.h ../config.h
-ppd.o: ppd.h file.h string.h ../config.h language.h debug.h
+ppd.o: globals.h string.h ../config.h cups.h ipp.h http.h md5.h ppd.h file.h
+ppd.o: language.h normalize.h transcode.h debug.h
 snprintf.o: string.h ../config.h
 string.o: string.h ../config.h
-tempfile.o: cups.h ipp.h http.h string.h ../config.h md5.h ppd.h file.h
-tempfile.o: debug.h
-transcode.o: string.h ../config.h language.h transcode.h
-usersys.o: cups.h ipp.h http.h string.h ../config.h md5.h ppd.h file.h
-usersys.o: http-private.h
-util.o: cups.h ipp.h http.h string.h ../config.h md5.h ppd.h file.h
-util.o: language.h debug.h
+tempfile.o: globals.h string.h ../config.h cups.h ipp.h http.h md5.h ppd.h
+tempfile.o: file.h language.h normalize.h transcode.h debug.h
+transcode.o: globals.h string.h ../config.h cups.h ipp.h http.h md5.h ppd.h
+transcode.o: file.h language.h normalize.h transcode.h
+usersys.o: http-private.h ../config.h http.h string.h md5.h globals.h cups.h
+usersys.o: ipp.h ppd.h file.h language.h normalize.h transcode.h
+util.o: globals.h string.h ../config.h cups.h ipp.h http.h md5.h ppd.h file.h
+util.o: language.h normalize.h transcode.h debug.h
 testhttp.o: http.h string.h ../config.h md5.h
 testi18n.o: language.h string.h ../config.h transcode.h normalize.h
 testipp.o: ../cups/string.h ../config.h string.h ipp.h http.h md5.h
index 9c1d51a39d3c5013f062af7ea69c801887e82997..18cd8679d51bc8d5b679f2b0bcb2c3ced990350d 100644 (file)
@@ -30,12 +30,43 @@ include ../Makedefs
 # Object files...
 #
 
-LIBOBJS        =       attr.o auth.o backchannel.o dest.o dir.o emit.o encode.o \
-               file.o getputfile.o http.o http-addr.o http-support.o \
-               ipp.o ipp-support.o langprintf.o language.o mark.o \
-               md5.o md5passwd.o normalize.o options.o page.o ppd.o \
-               snprintf.o string.o tempfile.o transcode.o usersys.o util.o
-OBJS   =       $(LIBOBJS) testhttp.o testi18n.o testipp.o testlang.o \
+LIBOBJS        =       \
+               attr.o \
+               auth.o \
+               backchannel.o \
+               dest.o \
+               dir.o \
+               emit.o \
+               encode.o \
+               file.o \
+               getputfile.o \
+               globals.o \
+               http.o \
+               http-addr.o \
+               http-support.o \
+               ipp.o \
+               ipp-support.o \
+               langprintf.o \
+               language.o \
+               mark.o \
+               md5.o \
+               md5passwd.o \
+               normalize.o \
+               options.o \
+               page.o \
+               ppd.o \
+               snprintf.o \
+               string.o \
+               tempfile.o \
+               transcode.o \
+               usersys.o \
+               util.o
+OBJS   =       \
+               $(LIBOBJS) \
+               testhttp.o \
+               testi18n.o \
+               testipp.o \
+               testlang.o \
                php_cups_wrap.o
 
 
@@ -43,16 +74,30 @@ OBJS        =       $(LIBOBJS) testhttp.o testi18n.o testipp.o testlang.o \
 # Header files to install...
 #
 
-HEADERS        =       cups.h dir.h file.h http.h ipp.h language.h md5.h \
-               normalize.h ppd.h transcode.h
+HEADERS        =       \
+               cups.h \
+               dir.h \
+               file.h \
+               http.h \
+               ipp.h \
+               language.h \
+               md5.h \
+               normalize.h \
+               ppd.h \
+               transcode.h
 
 
 #
 # Targets in this directory...
 #
 
-TARGETS        =       $(LIBCUPS) libcups.a \
-               testhttp testi18n testipp testlang
+TARGETS        =       \
+               $(LIBCUPS) \
+               libcups.a \
+               testhttp \
+               testi18n \
+               testipp \
+               testlang
 
 
 #
index 9820046c0f8f5f524abb4fb7a7b57f24413e856b..bd38e7a0c0734213c61e686496578ffee4e8e082 100644 (file)
@@ -64,7 +64,7 @@ static int    ppd_sort(ppd_choice_t **c1, ppd_choice_t **c2);
  * Local globals...
  */
 
-static const char *ppd_custom_code =
+static const char ppd_custom_code[] =
                "pop pop pop\n"
                "<</PageSize[5 -2 roll]/ImagingBBox null>>setpagedevice\n";
 
diff --git a/cups/globals.c b/cups/globals.c
new file mode 100644 (file)
index 0000000..2ca8e7f
--- /dev/null
@@ -0,0 +1,173 @@
+/*
+ * "$Id$"
+ *
+ *   Global variable access routines for the Common UNIX Printing System (CUPS).
+ *
+ *   Copyright 1997-2005 by Easy Software Products, all rights reserved.
+ *
+ *   These coded instructions, statements, and computer programs are the
+ *   property of Easy Software Products 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 missing or damaged please contact Easy Software Products
+ *   at:
+ *
+ *       Attn: CUPS Licensing Information
+ *       Easy Software Products
+ *       44141 Airport View Drive, Suite 204
+ *       Hollywood, Maryland 20636 USA
+ *
+ *       Voice: (301) 373-9600
+ *       EMail: cups-info@cups.org
+ *         WWW: http://www.cups.org
+ *
+ *   This file is subject to the Apple OS-Developed Software exception.
+ *
+ * Contents:
+ *
+ *   _cupsGlobals()      - Return a pointer to thread local storage.
+ *   globals_init()       - Initialize globals once.
+ *   globals_destructor() - Free memory allocated by _cupsGlobals().
+ */
+
+/*
+ * Include necessary headers...
+ */
+
+#include "globals.h"
+#include "http-private.h"
+#include <stdlib.h>
+
+
+#ifdef HAVE_PTHREAD_H
+/*
+ * Implement per-thread globals...
+ */
+
+/*
+ * Local globals...
+ */
+
+static pthread_key_t   globals_key = -1;
+                                       /* Thread local storage key */
+static pthread_once_t  globals_key_once = PTHREAD_ONCE_INIT;
+                                       /* One-time initialization object */
+
+
+/*
+ * Local functions...
+ */
+
+static void    globals_init();
+static void    globals_destructor(void *value);
+
+
+/*
+ * '_cupsGlobals()' - Return a pointer to thread local storage
+ */
+
+cups_globals_t *                       /* O - Pointer to global data */
+_cupsGlobals(void)
+{
+  cups_globals_t *globals;             /* Pointer to global data */
+
+
+ /* 
+  * Initialize the global data exactly once...
+  */
+
+  pthread_once(&globals_key_once, globals_init);
+
+ /*
+  * See if we have allocated the data yet...
+  */
+
+  if ((globals = (cups_globals_t *)pthread_getspecific(globals_key)) == NULL)
+  {
+   /*
+    * No, allocate memory as set the pointer for the key...
+    */
+
+    globals = calloc(1, sizeof(cups_globals_t));
+    pthread_setspecific(globals_key, globals);
+
+   /*
+    * Initialize variables that have non-zero values
+    */
+
+    globals->encryption  = (http_encryption_t)-1;
+    globals->password_cb = _cupsGetPassword;
+  }
+
+ /*
+  * Return the pointer to the data...
+  */
+
+  return (globals);
+}
+
+
+/*
+ * 'globals_init()' - Initialize globals once.
+ */
+
+static void
+globals_init()
+{
+  pthread_key_create(&globals_key, globals_destructor);
+}
+
+
+/*
+ * 'globals_destructor()' - Free memory allocated by _cupsGlobals().
+ */
+
+static void
+globals_destructor(void *value)                /* I - Data to free */
+{
+  free(value);
+}
+
+
+#else
+/*
+ * Implement static globals...
+ */
+
+/*
+ * '_cupsGlobals()' - Return a pointer to thread local storage.
+ *
+ * @private
+ */
+
+cups_globals_t *                       /* O - Pointer to global data */
+_cupsGlobals(void)
+{
+  static cups_globals_t        globals = { 0 };/* Global data */
+  static int           initialized = 0;/* Global data initialized? */
+
+
+ /*
+  * Initialize global data as needed...
+  */
+
+  if (!initialized)
+  {
+    initialized = 1;
+
+   /*
+    * Initialize variables that have non-zero default values...
+    */
+
+    globals.encryption  = (http_encryption_t)-1;
+    globals.password_cb = _cupsGetPassword;
+  }
+
+  return (&cups_globals);
+}
+#endif /* HAVE_PTHREAD_H */
+
+
+/*
+ * End of "$Id$".
+ */
diff --git a/cups/globals.h b/cups/globals.h
new file mode 100644 (file)
index 0000000..79f6c23
--- /dev/null
@@ -0,0 +1,154 @@
+/*
+ * "$Id$"
+ *
+ *   Global variable definitions for the Common UNIX Printing System (CUPS).
+ *
+ *   Copyright 1997-2005 by Easy Software Products, all rights reserved.
+ *
+ *   These coded instructions, statements, and computer programs are the
+ *   property of Easy Software Products 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 missing or damaged please contact Easy Software Products
+ *   at:
+ *
+ *       Attn: CUPS Licensing Information
+ *       Easy Software Products
+ *       44141 Airport View Drive, Suite 204
+ *       Hollywood, Maryland 20636 USA
+ *
+ *       Voice: (301) 373-9600
+ *       EMail: cups-info@cups.org
+ *         WWW: http://www.cups.org
+ *
+ *   This file is subject to the Apple OS-Developed Software exception.
+ */
+
+#ifndef _CUPS_GLOBALS_H_
+#  define _CUPS_GLOBALS_H_
+
+/*
+ * Include necessary headers...
+ */
+
+#  include "string.h"
+#  include "cups.h"
+#  include "language.h"
+#  include "normalize.h"
+#  include "transcode.h"
+
+#  ifdef HAVE_PTHREAD_H
+#    include <pthread.h>
+#  endif /* HAVE_PTHREAD_H */
+
+
+/*
+ * C++ magic...
+ */
+
+#  ifdef __cplusplus
+extern "C" {
+#  endif /* __cplusplus */
+
+
+/*
+ * Constants/limits...
+ */
+
+#  define CUPS_MAX_ADDRS       100     /* Limit on number of addresses... */
+
+
+/*
+ * To make libcups thread safe, define thread safe globals (aka thread-
+ * specific data) for the static variables used in the library.
+ */
+
+typedef struct cups_globals_s          /**** CUPS global state data ****/
+{
+  /* http.c */
+  char                 http_date[256]; /* Date+time buffer */
+
+  /* http-addr.c */
+  unsigned             ip_addrs[CUPS_MAX_ADDRS][4];
+                                       /* Packed IPv4/6 addresses */
+  char                 *ip_ptrs[CUPS_MAX_ADDRS + 1];
+                                       /* Pointer to packed address */
+  struct hostent       hostent;        /* Host entry for IP address */
+#  ifdef HAVE_GETADDRINFO
+  char                 hostname[1024]; /* Hostname */
+#  endif /* HAVE_GETADDRINFO */
+
+  /* ipp.c */
+  ipp_uchar_t          ipp_date[11];   /* RFC-1903 date/time data */
+
+  /* ipp-support.c */
+  int                  ipp_port;       /* IPP port number */
+  char                 ipp_unknown[255];
+                                       /* Unknown error statuses */
+
+  /* normalize.c */
+  cups_normmap_t       *normmap_cache; /* Normalize Map cache */
+  cups_foldmap_t       *foldmap_cache; /* Case Fold cache */
+  cups_propmap_t       *propmap_cache; /* Char Prop Map Cache */
+  cups_combmap_t       *combmap_cache; /* Comb Class Map Cache */
+  cups_breakmap_t      *breakmap_cache;/* Line Break Map Cache */
+
+  /* language.c */
+  cups_lang_t          *lang_cache;    /* Language string cache */
+#  ifdef __APPLE__
+#    ifdef HAVE_CF_LOCALE_ID
+  char                 language[32];   /* Cached language */
+#    else
+  const char           *language;      /* Cached language */
+#    endif /* HAVE_CF_LOCALE_ID */
+#  endif /* __APPLE__ */
+
+  /* ppd.c */
+  ppd_status_t         ppd_status;     /* Status of last ppdOpen*() */
+  int                  ppd_line;       /* Current line number */
+  ppd_conform_t                ppd_conform;    /* Level of conformance required */
+
+  /* tempfile.c */
+  char                 tempfile[1024]; /* cupsTempFd/File buffer */
+
+  /* transcode.c */
+  cups_cmap_t          *cmap_cache;    /* SBCS Charmap Cache */
+  cups_vmap_t          *vmap_cache;    /* VBCS Charmap Cache */
+
+  /* usersys.c */
+  http_encryption_t    encryption;     /* Encryption setting */
+  char                 user[65],       /* User name */
+                       server[256];    /* Server address */
+  const char           *(*password_cb)(const char *);
+                                       /* Password callback */
+
+  /* util.c */
+  http_t               *http;          /* Current server connection */
+  ipp_status_t         last_error;     /* Last IPP error */
+  char                 def_printer[256];
+                                       /* Default printer */
+  char                 ppd_filename[HTTP_MAX_URI];
+                                       /* PPD filename */
+} cups_globals_t;
+
+
+/*
+ * Prototypes...
+ */
+
+extern const char      *_cupsGetPassword(const char *prompt);
+extern cups_globals_t  *_cupsGlobals(void);
+
+
+/*
+ * C++ magic...
+ */
+
+#  ifdef __cplusplus
+}
+#  endif /* __cplusplus */
+#endif /* !_CUPS_GLOBALS_H_ */
+
+/*
+ * End of "$Id$".
+ */
index 13c0c077a24d3c400f0c71b2c2af0bf7d1ead69e..b2682bd0771f770860e87a9a44aff2fdf03ec1f5 100644 (file)
@@ -37,9 +37,8 @@
  * Include necessary headers...
  */
 
-#include "http.h"
+#include "globals.h"
 #include "debug.h"
-#include "string.h"
 #include <stdlib.h>
 
 
@@ -275,22 +274,19 @@ httpGetHostByName(const char *name)       /* I - Hostname or IP address */
   int                  i;              /* Looping var */
   const char           *nameptr;       /* Pointer into name */
   unsigned             ip[4];          /* IP address components */
-  static unsigned      packed_ip[100][4];/* Packed IPv4/6 addresses */
-  static char          *packed_ptr[101];/* Pointer to packed address */
-  static struct hostent        host_ip;        /* Host entry for IP/domain address */
-#ifdef HAVE_GETADDRINFO
-  static char          h_name[1024];   /* Hostname */
-#endif /* HAVE_GETADDRINFO */
+  cups_globals_t       *cg = _cupsGlobals();
+                                       /* Pointer to library globals */
 
 
   DEBUG_printf(("httpGetHostByName(name=\"%s\")\n", name));
 
-#if defined(__APPLE__)
-  /* OS X hack to avoid it's ocassional long delay in lookupd */
-  static const char sLoopback[] = "127.0.0.1";
+ /*
+  * Avoid lookup delays and configuration problems when connecting
+  * to the localhost address...
+  */
+
   if (!strcmp(name, "localhost"))
-    name = sLoopback;
-#endif /* __APPLE__ */
+    name = "127.0.0.1";
 
  /*
   * This function is needed because some operating systems have a
@@ -312,17 +308,17 @@ httpGetHostByName(const char *name)       /* I - Hostname or IP address */
     * A domain socket address, so make an AF_LOCAL entry and return it...
     */
 
-    host_ip.h_name      = (char *)name;
-    host_ip.h_aliases   = NULL;
-    host_ip.h_addrtype  = AF_LOCAL;
-    host_ip.h_length    = strlen(name) + 1;
-    host_ip.h_addr_list = packed_ptr;
-    packed_ptr[0]       = (char *)name;
-    packed_ptr[1]       = NULL;
+    cg->hostent.h_name      = (char *)name;
+    cg->hostent.h_aliases   = NULL;
+    cg->hostent.h_addrtype  = AF_LOCAL;
+    cg->hostent.h_length    = strlen(name) + 1;
+    cg->hostent.h_addr_list = cg->ip_ptrs;
+    cg->ip_ptrs[0]          = (char *)name;
+    cg->ip_ptrs[1]          = NULL;
 
     DEBUG_puts("httpGetHostByName: returning domain socket address...");
 
-    return (&host_ip);
+    return (&cg->hostent);
   }
 #endif /* AF_LOCAL */
 #ifdef AF_INET6
@@ -332,22 +328,22 @@ httpGetHostByName(const char *name)       /* I - Hostname or IP address */
     * A raw 128-bit IPv6 address of the form "[xxxx:xxxx:xxxx:xxxx]"
     */
 
-    host_ip.h_name      = (char *)name;
-    host_ip.h_aliases   = NULL;
-    host_ip.h_addrtype  = AF_INET6;
-    host_ip.h_length    = 16;
-    host_ip.h_addr_list = packed_ptr;
-    packed_ptr[0]       = (char *)(packed_ip[0]);
-    packed_ptr[1]       = NULL;
+    cg->hostent.h_name      = (char *)name;
+    cg->hostent.h_aliases   = NULL;
+    cg->hostent.h_addrtype  = AF_INET6;
+    cg->hostent.h_length    = 16;
+    cg->hostent.h_addr_list = cg->ip_ptrs;
+    cg->ip_ptrs[0]       = (char *)(cg->ip_addrs[0]);
+    cg->ip_ptrs[1]       = NULL;
 
     for (i = 0, nameptr = name + 1; *nameptr && i < 4; i ++)
     {
       if (*nameptr == ']')
         break;
       else if (*nameptr == ':')
-        packed_ip[0][i] = 0;
+        cg->ip_addrs[0][i] = 0;
       else
-        packed_ip[0][i] = htonl(strtoul(nameptr, (char **)&nameptr, 16));
+        cg->ip_addrs[0][i] = htonl(strtoul(nameptr, (char **)&nameptr, 16));
 
       if (*nameptr == ':' || *nameptr == ']')
         nameptr ++;
@@ -355,7 +351,7 @@ httpGetHostByName(const char *name) /* I - Hostname or IP address */
 
     while (i < 4)
     {
-      packed_ip[0][i] = 0;
+      cg->ip_addrs[0][i] = 0;
       i ++;
     }
 
@@ -364,7 +360,7 @@ httpGetHostByName(const char *name) /* I - Hostname or IP address */
 
     DEBUG_puts("httpGetHostByName: returning IPv6 address...");
 
-    return (&host_ip);
+    return (&cg->hostent);
   }
 #endif /* AF_INET6 */
 
@@ -383,24 +379,24 @@ httpGetHostByName(const char *name)       /* I - Hostname or IP address */
     if (ip[0] > 255 || ip[1] > 255 || ip[2] > 255 || ip[3] > 255)
       return (NULL);                   /* Invalid byte ranges! */
 
-    packed_ip[0][0] = htonl(((((((ip[0] << 8) | ip[1]) << 8) | ip[2]) << 8) |
+    cg->ip_addrs[0][0] = htonl(((((((ip[0] << 8) | ip[1]) << 8) | ip[2]) << 8) |
                              ip[3]));
 
    /*
     * Fill in the host entry and return it...
     */
 
-    host_ip.h_name      = (char *)name;
-    host_ip.h_aliases   = NULL;
-    host_ip.h_addrtype  = AF_INET;
-    host_ip.h_length    = 4;
-    host_ip.h_addr_list = packed_ptr;
-    packed_ptr[0]       = (char *)packed_ip[0];
-    packed_ptr[1]       = NULL;
+    cg->hostent.h_name      = (char *)name;
+    cg->hostent.h_aliases   = NULL;
+    cg->hostent.h_addrtype  = AF_INET;
+    cg->hostent.h_length    = 4;
+    cg->hostent.h_addr_list = cg->ip_ptrs;
+    cg->ip_ptrs[0]       = (char *)cg->ip_addrs[0];
+    cg->ip_ptrs[1]       = NULL;
 
     DEBUG_puts("httpGetHostByName: returning IPv4 address...");
 
-    return (&host_ip);
+    return (&cg->hostent);
   }
   else
 #ifdef HAVE_GETADDRINFO
@@ -456,24 +452,26 @@ httpGetHostByName(const char *name)       /* I - Hostname or IP address */
       }
     }
 
-    strlcpy(h_name, current->ai_canonname, sizeof(h_name));
+    strlcpy(cg->hostname, current->ai_canonname, sizeof(cg->hostname));
 
-    host_ip.h_name      = h_name;
-    host_ip.h_aliases   = NULL;
-    host_ip.h_addrtype  = current->ai_family;
-    host_ip.h_addr_list = packed_ptr;
+    cg->hostent.h_name      = cg->hostname;
+    cg->hostent.h_aliases   = NULL;
+    cg->hostent.h_addrtype  = current->ai_family;
+    cg->hostent.h_addr_list = cg->ip_ptrs;
 
     if (current->ai_family == AF_INET6)
-      host_ip.h_length = 16;
+      cg->hostent.h_length = 16;
     else
-      host_ip.h_length = 4;
+      cg->hostent.h_length = 4;
 
    /*
     * Convert the address info to a hostent structure...
     */
 
-    for (i = 0, current = results; i < 100 && current; current = current->ai_next)
-      if (current->ai_family == host_ip.h_addrtype)
+    for (i = 0, current = results;
+         i < CUPS_MAX_ADDRS && current;
+        current = current->ai_next)
+      if (current->ai_family == cg->hostent.h_addrtype)
       {
        /*
         * Copy this address...
@@ -482,15 +480,15 @@ httpGetHostByName(const char *name)       /* I - Hostname or IP address */
         address = (http_addr_t *)(current->ai_addr);
 
         if (current->ai_family == AF_INET)
-         memcpy((char *)packed_ip[i], (char *)&(address->ipv4.sin_addr), 4);
+         memcpy((char *)cg->ip_addrs[i], (char *)&(address->ipv4.sin_addr), 4);
        else
-         memcpy((char *)packed_ip[i], (char *)&(address->ipv6.sin6_addr), 16);
+         memcpy((char *)cg->ip_addrs[i], (char *)&(address->ipv6.sin6_addr), 16);
 
-       packed_ptr[i] = (char *)packed_ip[i];
+       cg->ip_ptrs[i] = (char *)cg->ip_addrs[i];
        i ++;
       }
 
-    packed_ptr[i] = NULL;
+    cg->ip_ptrs[i] = NULL;
 
    /*
     * Free the getaddrinfo() results and return the hostent structure...
@@ -498,7 +496,7 @@ httpGetHostByName(const char *name) /* I - Hostname or IP address */
 
     freeaddrinfo(results);
 
-    return (&host_ip);
+    return (&cg->hostent);
   }
 #else
   {
index da4885227b25f2b1cb2e828786dac7665380303d..754ca0bb31fc677952aeaaad5a2e5950c1c1adfc 100644 (file)
  */
 
 #include "http-private.h"
-
-#include <stdio.h>
+#include "globals.h"
+#include "debug.h"
 #include <stdlib.h>
-#include <stdarg.h>
-#include <ctype.h>
-#include "string.h"
 #include <fcntl.h>
 #include <errno.h>
-
-#include "http.h"
-#include "debug.h"
-
 #ifndef WIN32
 #  include <signal.h>
 #  include <sys/time.h>
@@ -697,16 +690,16 @@ httpGet(http_t     *http,         /* I - HTTP data */
 /*
  * 'httpGetDateString()' - Get a formatted date/time string from a time value.
  *
- * This function is not thread-safe and is therefore deprecated.
+ * @deprecated
  */
 
 const char *                           /* O - Date/time string */
 httpGetDateString(time_t t)            /* I - UNIX time */
 {
-  static char  datetime[256];          /* Date/time string */
+  cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
 
 
-  return (httpGetDateString2(t, datetime, sizeof(datetime)));
+  return (httpGetDateString2(t, cg->http_date, sizeof(cg->http_date)));
 }
 
 
index 4f2d5212642118d879e074975e0de170ae781183..e6615dde62b4f9b7c8b071f313da2162dde7933b 100644 (file)
  * Include necessary headers...
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include "string.h"
-#include "language.h"
-
-#include "ipp.h"
+#include "globals.h"
 #include "debug.h"
-#include <ctype.h>
+#include <stdlib.h>
 
 
 /*
  * Local globals...
  */
 
-static int     ipp_port = 0;
 static const char * const ipp_status_oks[] =   /* "OK" status codes */
                {
                  "successful-ok",
@@ -169,10 +163,10 @@ static char       * const ipp_std_ops[] =
  * 'ippErrorString()' - Return a name for the given status code.
  */
 
-const char *                                   /* O - Text string */
-ippErrorString(ipp_status_t error)             /* I - Error status */
+const char *                           /* O - Text string */
+ippErrorString(ipp_status_t error)     /* I - Error status */
 {
-  static char  unknown[255];                   /* Unknown error statuses */
+  cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
 
 
  /*
@@ -192,9 +186,9 @@ ippErrorString(ipp_status_t error)          /* I - Error status */
   * No, build an "unknown-xxxx" error string...
   */
 
-  sprintf(unknown, "unknown-%04x", error);
+  sprintf(cg->ipp_unknown, "unknown-%04x", error);
 
-  return (unknown);
+  return (cg->ipp_unknown);
 }
 
 
@@ -234,7 +228,7 @@ ippErrorValue(const char *name)             /* I - Name */
 const char *                           /* O - Name */
 ippOpString(ipp_op_t op)               /* I - Operation ID */
 {
-  static char  unknown[255];           /* Unknown error statuses */
+  cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
 
 
  /*
@@ -252,9 +246,9 @@ ippOpString(ipp_op_t op)            /* I - Operation ID */
   * No, build an "unknown-xxxx" operation string...
   */
 
-  sprintf(unknown, "unknown-%04x", op);
+  sprintf(cg->ipp_unknown, "unknown-%04x", op);
 
-  return (unknown);
+  return (cg->ipp_unknown);
 }
 
 
@@ -287,21 +281,22 @@ ippOpValue(const char *name)              /* I - Textual name */
  * 'ippPort()' - Return the default IPP port number.
  */
 
-int                                            /* O - Port number */
+int                                    /* O - Port number */
 ippPort(void)
 {
-  const char   *server_port;                   /* SERVER_PORT environment variable */
-  struct servent *port;                                /* Port number info */  
+  const char   *server_port;           /* SERVER_PORT environment variable */
+  struct servent *port;                        /* Port number info */  
+  cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
 
 
-  if (ipp_port)
-    return (ipp_port);
+  if (cg->ipp_port)
+    return (cg->ipp_port);
   else if ((server_port = getenv("IPP_PORT")) != NULL)
-    return (ipp_port = atoi(server_port));
+    return (cg->ipp_port = atoi(server_port));
   else if ((port = getservbyname("ipp", NULL)) == NULL)
-    return (ipp_port = CUPS_DEFAULT_IPP_PORT);
+    return (cg->ipp_port = CUPS_DEFAULT_IPP_PORT);
   else
-    return (ipp_port = ntohs(port->s_port));
+    return (cg->ipp_port = ntohs(port->s_port));
 }
 
 
@@ -310,9 +305,9 @@ ippPort(void)
  */
 
 void
-ippSetPort(int p)                              /* I - Port number to use */
+ippSetPort(int p)                      /* I - Port number to use */
 {
-  ipp_port = p;
+  _cupsGlobals()->ipp_port = p;
 }
 
 
index 11823d2198edef24b73927c1e0604f1c0f3c9ff0..dbd50e0d00de6b3c0229c03a3ca8dc5940a99f74 100644 (file)
  * Include necessary headers...
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include "string.h"
-
-#include "ipp.h"
+#include "globals.h"
 #include "debug.h"
-#include <ctype.h>
+#include <stdlib.h>
 #include <errno.h>
-
 #ifdef WIN32
 #  include <io.h>
 #endif /* WIN32 */
@@ -96,13 +91,13 @@ static int          ipp_write_file(int *fd, ipp_uchar_t *buffer, int length);
  * 'ippAddBoolean()' - Add a boolean attribute to an IPP request.
  */
 
-ipp_attribute_t *                              /* O - New attribute */
-ippAddBoolean(ipp_t      *ipp,                 /* I - IPP request */
-              ipp_tag_t  group,                        /* I - IPP group */
-              const char *name,                        /* I - Name of attribute */
-              char       value)                        /* I - Value of attribute */
+ipp_attribute_t *                      /* O - New attribute */
+ippAddBoolean(ipp_t      *ipp,         /* I - IPP request */
+              ipp_tag_t  group,                /* I - IPP group */
+              const char *name,                /* I - Name of attribute */
+              char       value)                /* I - Value of attribute */
 {
-  ipp_attribute_t      *attr;                  /* New attribute */
+  ipp_attribute_t      *attr;          /* New attribute */
 
 
   DEBUG_printf(("ippAddBoolean(%p, %02x, \'%s\', %d)\n", ipp, group, name, value));
@@ -126,16 +121,16 @@ ippAddBoolean(ipp_t      *ipp,                    /* I - IPP request */
  * 'ippAddBooleans()' - Add an array of boolean values.
  */
 
-ipp_attribute_t *                              /* O - New attribute */
-ippAddBooleans(ipp_t      *ipp,                        /* I - IPP request */
-               ipp_tag_t  group,               /* I - IPP group */
-              const char *name,                /* I - Name of attribute */
-              int        num_values,           /* I - Number of values */
-              const char *values)              /* I - Values */
+ipp_attribute_t *                      /* O - New attribute */
+ippAddBooleans(ipp_t      *ipp,                /* I - IPP request */
+               ipp_tag_t  group,       /* I - IPP group */
+              const char *name,        /* I - Name of attribute */
+              int        num_values,   /* I - Number of values */
+              const char *values)      /* I - Values */
 {
-  int                  i;                      /* Looping var */
-  ipp_attribute_t      *attr;                  /* New attribute */
-  ipp_value_t          *value;                 /* Current value */
+  int                  i;              /* Looping var */
+  ipp_attribute_t      *attr;          /* New attribute */
+  ipp_value_t          *value;         /* Current value */
 
 
   DEBUG_printf(("ippAddBooleans(%p, %02x, \'%s\', %d, %p)\n", ipp,
@@ -165,13 +160,13 @@ ippAddBooleans(ipp_t      *ipp,                   /* I - IPP request */
  * 'ippAddCollection()' - Add a collection value.
  */
 
-ipp_attribute_t *                              /* O - New attribute */
-ippAddCollection(ipp_t      *ipp,              /* I - IPP request */
-                 ipp_tag_t  group,             /* I - IPP group */
-                const char *name,              /* I - Name of attribute */
-                ipp_t      *value)             /* I - Value */
+ipp_attribute_t *                      /* O - New attribute */
+ippAddCollection(ipp_t      *ipp,      /* I - IPP request */
+                 ipp_tag_t  group,     /* I - IPP group */
+                const char *name,      /* I - Name of attribute */
+                ipp_t      *value)     /* I - Value */
 {
-  ipp_attribute_t      *attr;                  /* New attribute */
+  ipp_attribute_t      *attr;          /* New attribute */
 
 
   DEBUG_printf(("ippAddCollection(%p, %02x, \'%s\', %p)\n", ipp, group, name,
@@ -196,16 +191,17 @@ ippAddCollection(ipp_t      *ipp,         /* I - IPP request */
  * 'ippAddCollections()' - Add an array of collection values.
  */
 
-ipp_attribute_t *                              /* O - New attribute */
-ippAddCollections(ipp_t       *ipp,            /* I - IPP request */
-                  ipp_tag_t   group,           /* I - IPP group */
-                 const char  *name,            /* I - Name of attribute */
-                 int         num_values,       /* I - Number of values */
-                 const ipp_t **values)         /* I - Values */
+ipp_attribute_t *                      /* O - New attribute */
+ippAddCollections(
+    ipp_t       *ipp,                  /* I - IPP request */
+    ipp_tag_t   group,                 /* I - IPP group */
+    const char  *name,                 /* I - Name of attribute */
+    int         num_values,            /* I - Number of values */
+    const ipp_t **values)              /* I - Values */
 {
-  int                  i;                      /* Looping var */
-  ipp_attribute_t      *attr;                  /* New attribute */
-  ipp_value_t          *value;                 /* Current value */
+  int                  i;              /* Looping var */
+  ipp_attribute_t      *attr;          /* New attribute */
+  ipp_value_t          *value;         /* Current value */
 
 
   DEBUG_printf(("ippAddCollections(%p, %02x, \'%s\', %d, %p)\n", ipp,
@@ -235,13 +231,13 @@ ippAddCollections(ipp_t       *ipp,               /* I - IPP request */
  * 'ippAddDate()' - Add a date attribute to an IPP request.
  */
 
-ipp_attribute_t *                              /* O - New attribute */
-ippAddDate(ipp_t             *ipp,             /* I - IPP request */
-           ipp_tag_t         group,            /* I - IPP group */
-          const char        *name,             /* I - Name of attribute */
-          const ipp_uchar_t *value)            /* I - Value */
+ipp_attribute_t *                      /* O - New attribute */
+ippAddDate(ipp_t             *ipp,     /* I - IPP request */
+           ipp_tag_t         group,    /* I - IPP group */
+          const char        *name,     /* I - Name of attribute */
+          const ipp_uchar_t *value)    /* I - Value */
 {
-  ipp_attribute_t      *attr;                  /* New attribute */
+  ipp_attribute_t      *attr;          /* New attribute */
 
 
   DEBUG_printf(("ippAddDate(%p, %02x, \'%s\', %p)\n", ipp, group, name,
@@ -266,14 +262,14 @@ ippAddDate(ipp_t             *ipp,                /* I - IPP request */
  * 'ippAddInteger()' - Add a integer attribute to an IPP request.
  */
 
-ipp_attribute_t *                              /* O - New attribute */
-ippAddInteger(ipp_t      *ipp,                 /* I - IPP request */
-              ipp_tag_t  group,                        /* I - IPP group */
-             ipp_tag_t  type,                  /* I - Type of attribute */
-              const char *name,                        /* I - Name of attribute */
-              int        value)                        /* I - Value of attribute */
+ipp_attribute_t *                      /* O - New attribute */
+ippAddInteger(ipp_t      *ipp,         /* I - IPP request */
+              ipp_tag_t  group,                /* I - IPP group */
+             ipp_tag_t  type,          /* I - Type of attribute */
+              const char *name,                /* I - Name of attribute */
+              int        value)                /* I - Value of attribute */
 {
-  ipp_attribute_t      *attr;                  /* New attribute */
+  ipp_attribute_t      *attr;          /* New attribute */
 
 
   DEBUG_printf(("ippAddInteger(%p, %d, \'%s\', %d)\n", ipp, group, name,
@@ -298,17 +294,17 @@ ippAddInteger(ipp_t      *ipp,                    /* I - IPP request */
  * 'ippAddIntegers()' - Add an array of integer values.
  */
 
-ipp_attribute_t *                              /* O - New attribute */
-ippAddIntegers(ipp_t      *ipp,                        /* I - IPP request */
-               ipp_tag_t  group,               /* I - IPP group */
-              ipp_tag_t  type,                 /* I - Type of attribute */
-              const char *name,                /* I - Name of attribute */
-              int        num_values,           /* I - Number of values */
-              const int  *values)              /* I - Values */
+ipp_attribute_t *                      /* O - New attribute */
+ippAddIntegers(ipp_t      *ipp,                /* I - IPP request */
+               ipp_tag_t  group,       /* I - IPP group */
+              ipp_tag_t  type,         /* I - Type of attribute */
+              const char *name,        /* I - Name of attribute */
+              int        num_values,   /* I - Number of values */
+              const int  *values)      /* I - Values */
 {
-  int                  i;                      /* Looping var */
-  ipp_attribute_t      *attr;                  /* New attribute */
-  ipp_value_t          *value;                 /* Current value */
+  int                  i;              /* Looping var */
+  ipp_attribute_t      *attr;          /* New attribute */
+  ipp_value_t          *value;         /* Current value */
 
 
   if (ipp == NULL || name == NULL || num_values < 1)
@@ -335,15 +331,15 @@ ippAddIntegers(ipp_t      *ipp,                   /* I - IPP request */
  * 'ippAddString()' - Add a language-encoded string to an IPP request.
  */
 
-ipp_attribute_t *                              /* O - New attribute */
-ippAddString(ipp_t      *ipp,                  /* I - IPP request */
-             ipp_tag_t  group,                 /* I - IPP group */
-            ipp_tag_t  type,                   /* I - Type of attribute */
-             const char *name,                 /* I - Name of attribute */
-             const char *charset,              /* I - Character set */
-             const char *value)                        /* I - Value */
+ipp_attribute_t *                      /* O - New attribute */
+ippAddString(ipp_t      *ipp,          /* I - IPP request */
+             ipp_tag_t  group,         /* I - IPP group */
+            ipp_tag_t  type,           /* I - Type of attribute */
+             const char *name,         /* I - Name of attribute */
+             const char *charset,      /* I - Character set */
+             const char *value)                /* I - Value */
 {
-  ipp_attribute_t      *attr;                  /* New attribute */
+  ipp_attribute_t      *attr;          /* New attribute */
 
 
   if (ipp == NULL || name == NULL)
@@ -396,18 +392,19 @@ ippAddString(ipp_t      *ipp,                     /* I - IPP request */
  * 'ippAddStrings()' - Add language-encoded strings to an IPP request.
  */
 
-ipp_attribute_t *                              /* O - New attribute */
-ippAddStrings(ipp_t              *ipp,         /* I - IPP request */
-              ipp_tag_t          group,                /* I - IPP group */
-             ipp_tag_t          type,          /* I - Type of attribute */
-             const char         *name,         /* I - Name of attribute */
-             int                num_values,    /* I - Number of values */
-             const char         *charset,      /* I - Character set */
-             const char * const *values)       /* I - Values */
+ipp_attribute_t *                      /* O - New attribute */
+ippAddStrings(
+    ipp_t              *ipp,           /* I - IPP request */
+    ipp_tag_t          group,          /* I - IPP group */
+    ipp_tag_t          type,           /* I - Type of attribute */
+    const char         *name,          /* I - Name of attribute */
+    int                num_values,     /* I - Number of values */
+    const char         *charset,       /* I - Character set */
+    const char * const *values)                /* I - Values */
 {
-  int                  i;                      /* Looping var */
-  ipp_attribute_t      *attr;                  /* New attribute */
-  ipp_value_t          *value;                 /* Current value */
+  int                  i;              /* Looping var */
+  ipp_attribute_t      *attr;          /* New attribute */
+  ipp_value_t          *value;         /* Current value */
 
 
   if (ipp == NULL || name == NULL || num_values < 1)
@@ -457,14 +454,14 @@ ippAddStrings(ipp_t              *ipp,            /* I - IPP request */
  * 'ippAddRange()' - Add a range of values to an IPP request.
  */
 
-ipp_attribute_t *                              /* O - New attribute */
-ippAddRange(ipp_t      *ipp,                   /* I - IPP request */
-            ipp_tag_t  group,                  /* I - IPP group */
-           const char *name,                   /* I - Name of attribute */
-           int        lower,                   /* I - Lower value */
-           int        upper)                   /* I - Upper value */
+ipp_attribute_t *                      /* O - New attribute */
+ippAddRange(ipp_t      *ipp,           /* I - IPP request */
+            ipp_tag_t  group,          /* I - IPP group */
+           const char *name,           /* I - Name of attribute */
+           int        lower,           /* I - Lower value */
+           int        upper)           /* I - Upper value */
 {
-  ipp_attribute_t      *attr;                  /* New attribute */
+  ipp_attribute_t      *attr;          /* New attribute */
 
 
   if (ipp == NULL || name == NULL)
@@ -487,17 +484,17 @@ ippAddRange(ipp_t      *ipp,                      /* I - IPP request */
  * 'ippAddRanges()' - Add ranges of values to an IPP request.
  */
 
-ipp_attribute_t *                              /* O - New attribute */
-ippAddRanges(ipp_t      *ipp,                  /* I - IPP request */
-             ipp_tag_t  group,                 /* I - IPP group */
-            const char *name,                  /* I - Name of attribute */
-            int        num_values,             /* I - Number of values */
-            const int  *lower,                 /* I - Lower values */
-            const int  *upper)                 /* I - Upper values */
+ipp_attribute_t *                      /* O - New attribute */
+ippAddRanges(ipp_t      *ipp,          /* I - IPP request */
+             ipp_tag_t  group,         /* I - IPP group */
+            const char *name,          /* I - Name of attribute */
+            int        num_values,     /* I - Number of values */
+            const int  *lower,         /* I - Lower values */
+            const int  *upper)         /* I - Upper values */
 {
-  int                  i;                      /* Looping var */
-  ipp_attribute_t      *attr;                  /* New attribute */
-  ipp_value_t          *value;                 /* Current value */
+  int                  i;              /* Looping var */
+  ipp_attribute_t      *attr;          /* New attribute */
+  ipp_value_t          *value;         /* Current value */
 
 
   if (ipp == NULL || name == NULL || num_values < 1)
@@ -527,15 +524,15 @@ ippAddRanges(ipp_t      *ipp,                     /* I - IPP request */
  * 'ippAddResolution()' - Add a resolution value to an IPP request.
  */
 
-ipp_attribute_t *                              /* O - New attribute */
-ippAddResolution(ipp_t      *ipp,              /* I - IPP request */
-                ipp_tag_t  group,              /* I - IPP group */
-                const char *name,              /* I - Name of attribute */
-                ipp_res_t  units,              /* I - Units for resolution */
-                int        xres,               /* I - X resolution */
-                int        yres)               /* I - Y resolution */
+ipp_attribute_t *                      /* O - New attribute */
+ippAddResolution(ipp_t      *ipp,      /* I - IPP request */
+                ipp_tag_t  group,      /* I - IPP group */
+                const char *name,      /* I - Name of attribute */
+                ipp_res_t  units,      /* I - Units for resolution */
+                int        xres,       /* I - X resolution */
+                int        yres)       /* I - Y resolution */
 {
-  ipp_attribute_t      *attr;                  /* New attribute */
+  ipp_attribute_t      *attr;          /* New attribute */
 
 
   if (ipp == NULL || name == NULL)
@@ -559,18 +556,18 @@ ippAddResolution(ipp_t      *ipp,         /* I - IPP request */
  * 'ippAddResolutions()' - Add resolution values to an IPP request.
  */
 
-ipp_attribute_t *                              /* O - New attribute */
-ippAddResolutions(ipp_t      *ipp,             /* I - IPP request */
-                 ipp_tag_t  group,             /* I - IPP group */
-                 const char *name,             /* I - Name of attribute */
-                 int        num_values,        /* I - Number of values */
-                 ipp_res_t  units,             /* I - Units for resolution */
-                 const int  *xres,             /* I - X resolutions */
-                 const int  *yres)             /* I - Y resolutions */
+ipp_attribute_t *                      /* O - New attribute */
+ippAddResolutions(ipp_t      *ipp,     /* I - IPP request */
+                 ipp_tag_t  group,     /* I - IPP group */
+                 const char *name,     /* I - Name of attribute */
+                 int        num_values,/* I - Number of values */
+                 ipp_res_t  units,     /* I - Units for resolution */
+                 const int  *xres,     /* I - X resolutions */
+                 const int  *yres)     /* I - Y resolutions */
 {
-  int                  i;                      /* Looping var */
-  ipp_attribute_t      *attr;                  /* New attribute */
-  ipp_value_t          *value;                 /* Current value */
+  int                  i;              /* Looping var */
+  ipp_attribute_t      *attr;          /* New attribute */
+  ipp_value_t          *value;         /* Current value */
 
 
   if (ipp == NULL || name == NULL || num_values < 1)
@@ -601,10 +598,10 @@ ippAddResolutions(ipp_t      *ipp,                /* I - IPP request */
  * 'ippAddSeparator()' - Add a group separator to an IPP request.
  */
 
-ipp_attribute_t *                              /* O - New attribute */
-ippAddSeparator(ipp_t *ipp)                    /* I - IPP request */
+ipp_attribute_t *                      /* O - New attribute */
+ippAddSeparator(ipp_t *ipp)            /* I - IPP request */
 {
-  ipp_attribute_t      *attr;                  /* New attribute */
+  ipp_attribute_t      *attr;          /* New attribute */
 
 
   DEBUG_printf(("ippAddSeparator(%p)\n", ipp));
@@ -627,11 +624,11 @@ ippAddSeparator(ipp_t *ipp)                       /* I - IPP request */
  *                     in seconds.
  */
 
-time_t                                         /* O - UNIX time value */
-ippDateToTime(const ipp_uchar_t *date)         /* I - RFC 1903 date info */
+time_t                                 /* O - UNIX time value */
+ippDateToTime(const ipp_uchar_t *date) /* I - RFC 1903 date info */
 {
-  struct tm    unixdate;                       /* UNIX date/time info */
-  time_t       t;                              /* Computed time */
+  struct tm    unixdate;               /* UNIX date/time info */
+  time_t       t;                      /* Computed time */
 
 
   memset(&unixdate, 0, sizeof(unixdate));
@@ -676,10 +673,10 @@ ippDateToTime(const ipp_uchar_t *date)            /* I - RFC 1903 date info */
  */
 
 void
-ippDelete(ipp_t *ipp)                          /* I - IPP request */
+ippDelete(ipp_t *ipp)                  /* I - IPP request */
 {
-  ipp_attribute_t      *attr,                  /* Current attribute */
-                       *next;                  /* Next attribute */
+  ipp_attribute_t      *attr,          /* Current attribute */
+                       *next;          /* Next attribute */
 
 
   DEBUG_printf(("ippDelete(): %p\n", ipp));
@@ -702,9 +699,42 @@ ippDelete(ipp_t *ipp)                              /* I - IPP request */
  */
 
 void
-ippDeleteAttribute(ipp_t           *ipp,       /* I - IPP request */
-                   ipp_attribute_t *attr)      /* I - Attribute to delete */
+ippDeleteAttribute(
+    ipp_t           *ipp,              /* I - IPP request */
+    ipp_attribute_t *attr)             /* I - Attribute to delete */
 {
+  ipp_attribute_t      *current,       /* Current attribute */
+                       *prev;          /* Previous attribute */
+
+
+ /*
+  * Find the attribute in the list...
+  */
+
+  for (current = ipp->attrs, prev = NULL;
+       current != NULL && current != attr;
+       prev = current, current = current->next);
+
+  if (current)
+  {
+   /*
+    * Found it, remove the attribute from the list...
+    */
+
+    if (prev)
+      prev->next = current->next;
+    else
+      ipp->attrs = current->next;
+
+    if (current == ipp->last)
+      ipp->last = prev;
+
+   /*
+    * Free memory used by the attribute...
+    */
+
+    _ipp_free_attr(current);
+  }
 }
 
 
@@ -712,10 +742,10 @@ ippDeleteAttribute(ipp_t           *ipp,  /* I - IPP request */
  * 'ippFindAttribute()' - Find a named attribute in a request...
  */
 
-ipp_attribute_t        *                               /* O - Matching attribute */
-ippFindAttribute(ipp_t      *ipp,              /* I - IPP request */
-                 const char *name,             /* I - Name of attribute */
-                ipp_tag_t  type)               /* I - Type of attribute */
+ipp_attribute_t        *                       /* O - Matching attribute */
+ippFindAttribute(ipp_t      *ipp,      /* I - IPP request */
+                 const char *name,     /* I - Name of attribute */
+                ipp_tag_t  type)       /* I - Type of attribute */
 {
   DEBUG_printf(("ippFindAttribute(%p, \'%s\')\n", ipp, name));
 
@@ -740,13 +770,13 @@ ippFindAttribute(ipp_t      *ipp,         /* I - IPP request */
  * 'ippFindNextAttribute()' - Find the next named attribute in a request...
  */
 
-ipp_attribute_t        *                               /* O - Matching attribute */
-ippFindNextAttribute(ipp_t      *ipp,          /* I - IPP request */
-                     const char *name,         /* I - Name of attribute */
-                    ipp_tag_t  type)           /* I - Type of attribute */
+ipp_attribute_t        *                       /* O - Matching attribute */
+ippFindNextAttribute(ipp_t      *ipp,  /* I - IPP request */
+                     const char *name, /* I - Name of attribute */
+                    ipp_tag_t  type)   /* I - Type of attribute */
 {
-  ipp_attribute_t      *attr;                  /* Current atttribute */
-  ipp_tag_t            value_tag;              /* Value tag */
+  ipp_attribute_t      *attr;          /* Current atttribute */
+  ipp_tag_t            value_tag;      /* Value tag */
 
 
   DEBUG_printf(("ippFindNextAttribute(%p, \'%s\')\n", ipp, name));
@@ -787,8 +817,8 @@ ippFindNextAttribute(ipp_t      *ipp,               /* I - IPP request */
  * 'ippLength()' - Compute the length of an IPP request.
  */
 
-size_t                                         /* O - Size of IPP request */
-ippLength(ipp_t *ipp)                          /* I - IPP request */
+size_t                                 /* O - Size of IPP request */
+ippLength(ipp_t *ipp)                  /* I - IPP request */
 {
   return (ipp_length(ipp, 0));
 }
@@ -824,9 +854,9 @@ ippNew(void)
  * 'ippRead()' - Read data for an IPP request from a HTTP connection.
  */
 
-ipp_state_t                                    /* O - Current state */
-ippRead(http_t *http,                          /* I - HTTP connection */
-        ipp_t  *ipp)                           /* I - IPP data */
+ipp_state_t                            /* O - Current state */
+ippRead(http_t *http,                  /* I - HTTP connection */
+        ipp_t  *ipp)                   /* I - IPP data */
 {
   DEBUG_printf(("ippRead(http=%p, ipp=%p), data_remaining=%d\n", http, ipp,
                 http ? http->data_remaining : -1));
@@ -845,9 +875,9 @@ ippRead(http_t *http,                               /* I - HTTP connection */
  * 'ippReadFile()' - Read data for an IPP request from a file.
  */
 
-ipp_state_t                                    /* O - Current state */
-ippReadFile(int   fd,                          /* I - HTTP data */
-            ipp_t *ipp)                                /* I - IPP data */
+ipp_state_t                            /* O - Current state */
+ippReadFile(int   fd,                  /* I - HTTP data */
+            ipp_t *ipp)                        /* I - IPP data */
 {
   DEBUG_printf(("ippReadFile(%d, %p)\n", fd, ipp));
 
@@ -859,19 +889,19 @@ ippReadFile(int   fd,                             /* I - HTTP data */
  * 'ippReadIO()' - Read data for an IPP request.
  */
 
-ipp_state_t                                    /* O - Current state */
-ippReadIO(void       *src,                     /* I - Data source */
-          ipp_iocb_t cb,                       /* I - Read callback function */
-         int        blocking,                  /* I - Use blocking IO? */
-         ipp_t      *parent,                   /* I - Parent request, if any */
-          ipp_t      *ipp)                     /* I - IPP data */
+ipp_state_t                            /* O - Current state */
+ippReadIO(void       *src,             /* I - Data source */
+          ipp_iocb_t cb,               /* I - Read callback function */
+         int        blocking,          /* I - Use blocking IO? */
+         ipp_t      *parent,           /* I - Parent request, if any */
+          ipp_t      *ipp)             /* I - IPP data */
 {
-  int                  n;                      /* Length of data */
-  unsigned char                buffer[32768],          /* Data buffer */
-                       *bufptr;                /* Pointer into buffer */
-  ipp_attribute_t      *attr;                  /* Current attribute */
-  ipp_tag_t            tag;                    /* Current tag */
-  ipp_value_t          *value;                 /* Current value */
+  int                  n;              /* Length of data */
+  unsigned char                buffer[32768],  /* Data buffer */
+                       *bufptr;        /* Pointer into buffer */
+  ipp_attribute_t      *attr;          /* Current attribute */
+  ipp_tag_t            tag;            /* Current tag */
+  ipp_value_t          *value;         /* Current value */
 
 
   DEBUG_printf(("ippReadIO(%p, %p, %d, %p, %p)\n", src, cb, blocking,
@@ -1343,11 +1373,12 @@ ippReadIO(void       *src,                      /* I - Data source */
  * 'ippTimeToDate()' - Convert from UNIX time to RFC 1903 format.
  */
 
-const ipp_uchar_t *                            /* O - RFC-1903 date/time data */
-ippTimeToDate(time_t t)                                /* I - UNIX time value */
+const ipp_uchar_t *                    /* O - RFC-1903 date/time data */
+ippTimeToDate(time_t t)                        /* I - UNIX time value */
 {
-  struct tm            *unixdate;              /* UNIX unixdate/time info */
-  static ipp_uchar_t   date[11];               /* RFC-1903 date/time data */
+  struct tm    *unixdate;              /* UNIX unixdate/time info */
+  ipp_uchar_t  *date = _cupsGlobals()->ipp_date;
+                                       /* RFC-1903 date/time data */
 
 
  /*
@@ -1390,9 +1421,9 @@ ippTimeToDate(time_t t)                           /* I - UNIX time value */
  * 'ippWrite()' - Write data for an IPP request to a HTTP connection.
  */
 
-ipp_state_t                                    /* O - Current state */
-ippWrite(http_t *http,                         /* I - HTTP connection */
-         ipp_t  *ipp)                          /* I - IPP data */
+ipp_state_t                            /* O - Current state */
+ippWrite(http_t *http,                 /* I - HTTP connection */
+         ipp_t  *ipp)                  /* I - IPP data */
 {
   DEBUG_printf(("ippWrite(%p, %p)\n", http, ipp));
 
@@ -1408,9 +1439,9 @@ ippWrite(http_t *http,                            /* I - HTTP connection */
  * 'ippWriteFile()' - Write data for an IPP request to a file.
  */
 
-ipp_state_t                                    /* O - Current state */
-ippWriteFile(int   fd,                         /* I - HTTP data */
-             ipp_t *ipp)                       /* I - IPP data */
+ipp_state_t                            /* O - Current state */
+ippWriteFile(int   fd,                 /* I - HTTP data */
+             ipp_t *ipp)               /* I - IPP data */
 {
   DEBUG_printf(("ippWriteFile(%d, %p)\n", fd, ipp));
 
@@ -1424,19 +1455,19 @@ ippWriteFile(int   fd,                          /* I - HTTP data */
  * 'ippWriteIO()' - Write data for an IPP request.
  */
 
-ipp_state_t                                    /* O - Current state */
-ippWriteIO(void       *dst,                    /* I - Destination */
-           ipp_iocb_t cb,                      /* I - Write callback function */
-          int        blocking,                 /* I - Use blocking IO? */
-          ipp_t      *parent,                  /* I - Parent IPP request */
-           ipp_t      *ipp)                    /* I - IPP data */
+ipp_state_t                            /* O - Current state */
+ippWriteIO(void       *dst,            /* I - Destination */
+           ipp_iocb_t cb,              /* I - Write callback function */
+          int        blocking,         /* I - Use blocking IO? */
+          ipp_t      *parent,          /* I - Parent IPP request */
+           ipp_t      *ipp)            /* I - IPP data */
 {
-  int                  i;                      /* Looping var */
-  int                  n;                      /* Length of data */
-  unsigned char                buffer[32768],          /* Data buffer */
-                       *bufptr;                /* Pointer into buffer */
-  ipp_attribute_t      *attr;                  /* Current attribute */
-  ipp_value_t          *value;                 /* Current value */
+  int                  i;              /* Looping var */
+  int                  n;              /* Length of data */
+  unsigned char                buffer[32768],  /* Data buffer */
+                       *bufptr;        /* Pointer into buffer */
+  ipp_attribute_t      *attr;          /* Current attribute */
+  ipp_value_t          *value;         /* Current value */
 
 
   DEBUG_printf(("ippWriteIO(%p, %p, %d, %p, %p)\n", dst, cb, blocking,
@@ -2204,11 +2235,11 @@ ippWriteIO(void       *dst,                     /* I - Destination */
  * '_ipp_add_attr()' - Add a new attribute to the request.
  */
 
-ipp_attribute_t *                              /* O - New attribute */
-_ipp_add_attr(ipp_t *ipp,                      /* I - IPP request */
-              int   num_values)                        /* I - Number of values */
+ipp_attribute_t *                      /* O - New attribute */
+_ipp_add_attr(ipp_t *ipp,              /* I - IPP request */
+              int   num_values)                /* I - Number of values */
 {
-  ipp_attribute_t      *attr;                  /* New attribute */
+  ipp_attribute_t      *attr;          /* New attribute */
 
 
   DEBUG_printf(("_ipp_add_attr(%p, %d)\n", ipp, num_values));
@@ -2242,10 +2273,10 @@ _ipp_add_attr(ipp_t *ipp,                       /* I - IPP request */
  */
 
 void
-_ipp_free_attr(ipp_attribute_t *attr)          /* I - Attribute to free */
+_ipp_free_attr(ipp_attribute_t *attr)  /* I - Attribute to free */
 {
-  int          i;                              /* Looping var */
-  ipp_value_t  *value;                         /* Current value */
+  int          i;                      /* Looping var */
+  ipp_value_t  *value;                 /* Current value */
 
 
   DEBUG_printf(("_ipp_free_attr(): %p\n", attr));
@@ -2294,15 +2325,15 @@ _ipp_free_attr(ipp_attribute_t *attr)           /* I - Attribute to free */
  * 'ipp_length()' - Compute the length of an IPP request or collection value.
  */
 
-static size_t                                  /* O - Size of IPP request */
-ipp_length(ipp_t *ipp,                         /* I - IPP request or collection */
-           int   collection)                   /* I - 1 if a collection, 0 otherwise */
+static size_t                          /* O - Size of IPP request */
+ipp_length(ipp_t *ipp,                 /* I - IPP request or collection */
+           int   collection)           /* I - 1 if a collection, 0 otherwise */
 {
-  int                  i;                      /* Looping var */
-  int                  bytes;                  /* Number of bytes */
-  ipp_attribute_t      *attr;                  /* Current attribute */
-  ipp_tag_t            group;                  /* Current group */
-  ipp_value_t          *value;                 /* Current value */
+  int                  i;              /* Looping var */
+  int                  bytes;          /* Number of bytes */
+  ipp_attribute_t      *attr;          /* Current attribute */
+  ipp_tag_t            group;          /* Current group */
+  ipp_value_t          *value;         /* Current value */
 
 
   if (ipp == NULL)
@@ -2437,14 +2468,14 @@ ipp_length(ipp_t *ipp,                          /* I - IPP request or collection */
  * 'ipp_read_http()' - Semi-blocking read on a HTTP connection...
  */
 
-static int                                     /* O - Number of bytes read */
-ipp_read_http(http_t      *http,               /* I - Client connection */
-              ipp_uchar_t *buffer,             /* O - Buffer for data */
-             int         length)               /* I - Total length */
+static int                             /* O - Number of bytes read */
+ipp_read_http(http_t      *http,       /* I - Client connection */
+              ipp_uchar_t *buffer,     /* O - Buffer for data */
+             int         length)       /* I - Total length */
 {
-  int          tbytes,                         /* Total bytes read */
-               bytes;                          /* Bytes read this pass */
-  char         len[32];                        /* Length string */
+  int          tbytes,                 /* Total bytes read */
+               bytes;                  /* Bytes read this pass */
+  char         len[32];                /* Length string */
   
 
   DEBUG_printf(("ipp_read_http(http=%p, buffer=%p, length=%d)\n",
@@ -2549,10 +2580,10 @@ ipp_read_http(http_t      *http,                /* I - Client connection */
  * 'ipp_read_file()' - Read IPP data from a file.
  */
 
-static int                                     /* O - Number of bytes read */
-ipp_read_file(int         *fd,                 /* I - File descriptor */
-              ipp_uchar_t *buffer,             /* O - Read buffer */
-             int         length)               /* I - Number of bytes to read */
+static int                             /* O - Number of bytes read */
+ipp_read_file(int         *fd,         /* I - File descriptor */
+              ipp_uchar_t *buffer,     /* O - Read buffer */
+             int         length)       /* I - Number of bytes to read */
 {
   return (read(*fd, buffer, length));
 }
@@ -2562,10 +2593,10 @@ ipp_read_file(int         *fd,                  /* I - File descriptor */
  * 'ipp_write_file()' - Write IPP data to a file.
  */
 
-static int                                     /* O - Number of bytes written */
-ipp_write_file(int         *fd,                        /* I - File descriptor */
-               ipp_uchar_t *buffer,            /* I - Data to write */
-               int         length)             /* I - Number of bytes to write */
+static int                             /* O - Number of bytes written */
+ipp_write_file(int         *fd,                /* I - File descriptor */
+               ipp_uchar_t *buffer,    /* I - Data to write */
+               int         length)     /* I - Number of bytes to write */
 {
   return (write(*fd, buffer, length));
 }
index a84fa2d378fdcf7204276f0b6bf99d18b2a14002..06e7f8d0aeb234610942dd0fbb139a78aac5c848 100644 (file)
@@ -42,8 +42,7 @@
  * Include necessary headers...
  */
 
-#include "string.h"
-#include "language.h"
+#include "globals.h"
 #include "debug.h"
 #include <stdlib.h>
 #ifdef HAVE_LANGINFO_H
@@ -64,7 +63,6 @@
 #  include <CoreFoundation/CoreFoundation.h>
 static const char      *appleLangDefault(void);
 #endif /* __APPLE__ */
-
 static cups_lang_t     *cups_cache_lookup(const char *name,
                                           cups_encoding_t encoding);
   
@@ -73,9 +71,7 @@ static cups_lang_t    *cups_cache_lookup(const char *name,
  * Local globals...
  */
 
-static cups_lang_t     *lang_cache = NULL;
-                                       /* Language string cache */
-static const char      *lang_blank = "";
+static const char      lang_blank[] = "";
                                        /* Blank constant string */
 static const char * const lang_encodings[] =
                        {               /* Encoding strings */
@@ -159,8 +155,8 @@ static const char *const lang_default[] =
  */
 
 const char *                           /* O - Character encoding */
-cupsEncodingName(cups_encoding_t encoding)
-                                       /* I - Encoding enum */
+cupsEncodingName(
+    cups_encoding_t encoding)          /* I - Encoding value */
 {
   if (encoding < 0 ||
       encoding >= (sizeof(lang_encodings) / sizeof(const char *)))
@@ -195,13 +191,14 @@ cupsLangFlush(void)
   int          i;                      /* Looping var */
   cups_lang_t  *lang,                  /* Current language */
                *next;                  /* Next language */
+  cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
 
 
  /*
   * Free all languages in the cache...
   */
 
-  for (lang = lang_cache; lang != NULL; lang = next)
+  for (lang = cg->lang_cache; lang != NULL; lang = next)
   {
    /*
     * Free all messages...
@@ -219,7 +216,7 @@ cupsLangFlush(void)
     free(lang);
   }
 
-  lang_cache = NULL;
+  cg->lang_cache = NULL;
 }
 
 
@@ -230,7 +227,7 @@ cupsLangFlush(void)
  */
 
 void
-cupsLangFree(cups_lang_t *lang)        /* I - Language to free */
+cupsLangFree(cups_lang_t *lang)                /* I - Language to free */
 {
   if (lang != NULL && lang->used > 0)
     lang->used --;
@@ -263,6 +260,8 @@ cupsLangGet(const char *language)   /* I - Language or locale */
   char                 *text;          /* Message text */
   cups_lang_t          *lang;          /* Current language... */
   char                 *oldlocale;     /* Old locale name */
+  cups_globals_t       *cg = _cupsGlobals();
+                                       /* Pointer to library globals */
   static const char * const locale_encodings[] =
                {                       /* Locale charset names */
                  "ASCII",      "ISO88591",     "ISO88592",     "ISO88593",
@@ -406,6 +405,8 @@ cupsLangGet(const char *language)   /* I - Language or locale */
 
 #if defined(__APPLE__)
   /* The ctype bug isn't in Apple's libc */
+  (void)locale;                        /* anti-compiler-warning-code */
+  (void)oldlocale;             /* anti-compiler-warning-code */
 #elif !defined(LC_CTYPE)
   oldlocale = _cupsSaveLocale(LC_ALL, "C");
 #else
@@ -602,7 +603,7 @@ cupsLangGet(const char *language)   /* I - Language or locale */
   * record...
   */
 
-  for (lang = lang_cache; lang != NULL; lang = lang->next)
+  for (lang = cg->lang_cache; lang != NULL; lang = lang->next)
     if (lang->used == 0)
       break;
 
@@ -618,8 +619,8 @@ cupsLangGet(const char *language)   /* I - Language or locale */
       return (NULL);
     }
 
-    lang->next lang_cache;
-    lang_cache = lang;
+    lang->next     = cg->lang_cache;
+    cg->lang_cache = lang;
   }
 
  /*
@@ -648,7 +649,7 @@ cupsLangGet(const char *language)   /* I - Language or locale */
     lang->encoding = CUPS_US_ASCII;
 
     for (i = 0; i < (sizeof(lang_encodings) / sizeof(lang_encodings[0])); i ++)
-      if (strcmp(lang_encodings[i], line) == 0)
+      if (!strcmp(lang_encodings[i], line))
       {
        lang->encoding = (cups_encoding_t)i;
        break;
@@ -803,15 +804,15 @@ appleLangDefault(void)
                                        /* List of localization data */
   CFStringRef          languageName;   /* Current name */
   CFStringRef          localeName;     /* Canonical from of name */
-  static char          language[32] = "";
-                                       /* Cached language */
+  cups_globals_t       *cg = _cupsGlobals();
+                                       /* Pointer to library globals */
 
 
  /*
   * Only do the lookup and translation the first time.
   */
 
-  if (!language[0])
+  if (!cg->language[0])
   {
     localizationList =
         CFPreferencesCopyAppValue(CFSTR("AppleLanguages"),
@@ -832,14 +833,14 @@ appleLangDefault(void)
 
          if (localeName != NULL)
          {
-           CFStringGetCString(localeName, language, sizeof(language),
+           CFStringGetCString(localeName, cg->language, sizeof(cg->language),
                               kCFStringEncodingASCII);
            CFRelease(localeName);
 
-           if (!strcmp(language, "en"))
-             strlcpy(language, "en_US.UTF-8", sizeof(language));
-           else if (strchr(language, '.') == NULL)
-             strlcat(language, ".UTF-8", sizeof(language));
+           if (!strcmp(cg->language, "en"))
+             strlcpy(cg->language, "en_US.UTF-8", sizeof(cg->language));
+           else if (strchr(cg->language, '.') == NULL)
+             strlcat(cg->language, ".UTF-8", sizeof(cg->language));
          }
         }
       }
@@ -851,15 +852,15 @@ appleLangDefault(void)
     * If we didn't find the language, default to en_US...
     */
 
-    if (!language[0])
-      strlcpy(language, "en_US.UTF-8", sizeof(language));
+    if (!cg->language[0])
+      strlcpy(cg->language, "en_US.UTF-8", sizeof(cg->language));
   }
 
  /*
   * Return the cached locale...
   */
 
-  return (language);
+  return (cg->language);
 }
 #  else
 /*
@@ -950,15 +951,15 @@ appleLangDefault(void)
   CFStringRef          localizationName;
                                        /* Current name */
   char                 buff[256];      /* Temporary buffer */
-  static const char    *language = NULL;
-                                       /* Cached language */
+  cups_globals_t       *cg = _cupsGlobals();
+                                       /* Pointer to library globals */
 
 
  /*
   * Only do the lookup and translation the first time.
   */
 
-  if (language == NULL)
+  if (cg->language == NULL)
   {
     localizationList =
         CFPreferencesCopyAppValue(CFSTR("AppleLanguages"),
@@ -988,7 +989,7 @@ appleLangDefault(void)
            {
              if (strcasecmp(buff, apple_name_locale[i].name) == 0)
              {
-               language = apple_name_locale[i].locale;
+               cg->language = apple_name_locale[i].locale;
                break;
              }
            }
@@ -1003,15 +1004,15 @@ appleLangDefault(void)
     * If we didn't find the language, default to en_US...
     */
 
-    if (language == NULL)
-      language = apple_name_locale[0].locale;
+    if (cg->language == NULL)
+      cg->language = apple_name_locale[0].locale;
   }
 
  /*
   * Return the cached locale...
   */
 
-  return (language);
+  return (cg->language);
 }
 #  endif /* HAVE_CF_LOCALE_ID */
 #endif /* __APPLE__ */
@@ -1037,7 +1038,7 @@ cups_cache_lookup(const char      *name,/* I - Name of locale */
   * Loop through the cache and return a match if found...
   */
 
-  for (lang = lang_cache; lang != NULL; lang = lang->next)
+  for (lang = _cupsGlobals()->lang_cache; lang != NULL; lang = lang->next)
   {
     DEBUG_printf(("cups_cache_lookup: lang=%p, language=\"%s\", encoding=%d(%s)\n",
                   lang, lang->language, lang->encoding,
index e5022823626bc80c5ebd44c56f70506916b45e83..85de9b1bd908ca961c7fe4f8d75b29255c1f73b9 100644 (file)
  * Include necessary headers...
  */
 
-#include <stdio.h>
+#include "globals.h"
+#include "debug.h"
 #include <stdlib.h>
-#include <string.h>
 #include <errno.h>
-#include <ctype.h>
 #include <time.h>
 
-#include "language.h"
-#include "string.h"
-#include "transcode.h"
-#include "normalize.h"
 
-/*
- * Local Globals...
- */
-
-static cups_normmap_t *normmap_cache = NULL;/* Normalize Map cache */
-static cups_foldmap_t *foldmap_cache = NULL;/* Case Fold cache */
-static cups_propmap_t *propmap_cache = NULL;/* Char Prop Map Cache */
-static cups_combmap_t *combmap_cache = NULL;/* Comb Class Map Cache */
-static cups_breakmap_t *breakmap_cache = NULL;/* Line Break Map Cache */
-
-typedef struct                  /**** General Category Index Struct****/
+typedef struct                         /**** General Category Index Struct****/
 {
-  cups_gencat_t         gencat;         /* General Category Value */
-  const char            *str;           /* General Category String */
+  cups_gencat_t        gencat;                 /* General Category Value */
+  const char   *str;                   /* General Category String */
 } gencat_t;
 
-static gencat_t gencat_index[] =        /* General Category Index */
+static const gencat_t gencat_index[] = /* General Category Index */
 {
-  { CUPS_GENCAT_LU, "Lu" },     /* Letter, Uppercase */
-  { CUPS_GENCAT_LL, "Ll" },     /* Letter, Lowercase */
-  { CUPS_GENCAT_LT, "Lt" },     /* Letter, Titlecase */
-  { CUPS_GENCAT_LM, "Lm" },     /* Letter, Modifier */
-  { CUPS_GENCAT_LO, "Lo" },     /* Letter, Other */
-  { CUPS_GENCAT_MN, "Mn" },     /* Mark, Non-Spacing */
-  { CUPS_GENCAT_MC, "Mc" },     /* Mark, Spacing Combining */
-  { CUPS_GENCAT_ME, "Me" },     /* Mark, Enclosing */
-  { CUPS_GENCAT_ND, "Nd" },     /* Number, Decimal Digit */
-  { CUPS_GENCAT_NL, "Nl" },     /* Number, Letter */
-  { CUPS_GENCAT_NO, "No" },     /* Number, Other */
-  { CUPS_GENCAT_PC, "Pc" },     /* Punctuation, Connector */
-  { CUPS_GENCAT_PD, "Pd" },     /* Punctuation, Dash */
-  { CUPS_GENCAT_PS, "Ps" },     /* Punctuation, Open (start) */
-  { CUPS_GENCAT_PE, "Pe" },     /* Punctuation, Close (end) */
-  { CUPS_GENCAT_PI, "Pi" },     /* Punctuation, Initial Quote */
-  { CUPS_GENCAT_PF, "Pf" },     /* Punctuation, Final Quote */
-  { CUPS_GENCAT_PO, "Po" },     /* Punctuation, Other */
-  { CUPS_GENCAT_SM, "Sm" },     /* Symbol, Math */
-  { CUPS_GENCAT_SC, "Sc" },     /* Symbol, Currency */
-  { CUPS_GENCAT_SK, "Sk" },     /* Symbol, Modifier */
-  { CUPS_GENCAT_SO, "So" },     /* Symbol, Other */
-  { CUPS_GENCAT_ZS, "Zs" },     /* Separator, Space */
-  { CUPS_GENCAT_ZL, "Zl" },     /* Separator, Line */
-  { CUPS_GENCAT_ZP, "Zp" },     /* Separator, Paragraph */
-  { CUPS_GENCAT_CC, "Cc" },     /* Other, Control */
-  { CUPS_GENCAT_CF, "Cf" },     /* Other, Format */
-  { CUPS_GENCAT_CS, "Cs" },     /* Other, Surrogate */
-  { CUPS_GENCAT_CO, "Co" },     /* Other, Private Use */
-  { CUPS_GENCAT_CN, "Cn" },     /* Other, Not Assigned */
+  { CUPS_GENCAT_LU, "Lu" },            /* Letter, Uppercase */
+  { CUPS_GENCAT_LL, "Ll" },            /* Letter, Lowercase */
+  { CUPS_GENCAT_LT, "Lt" },            /* Letter, Titlecase */
+  { CUPS_GENCAT_LM, "Lm" },            /* Letter, Modifier */
+  { CUPS_GENCAT_LO, "Lo" },            /* Letter, Other */
+  { CUPS_GENCAT_MN, "Mn" },            /* Mark, Non-Spacing */
+  { CUPS_GENCAT_MC, "Mc" },            /* Mark, Spacing Combining */
+  { CUPS_GENCAT_ME, "Me" },            /* Mark, Enclosing */
+  { CUPS_GENCAT_ND, "Nd" },            /* Number, Decimal Digit */
+  { CUPS_GENCAT_NL, "Nl" },            /* Number, Letter */
+  { CUPS_GENCAT_NO, "No" },            /* Number, Other */
+  { CUPS_GENCAT_PC, "Pc" },            /* Punctuation, Connector */
+  { CUPS_GENCAT_PD, "Pd" },            /* Punctuation, Dash */
+  { CUPS_GENCAT_PS, "Ps" },            /* Punctuation, Open (start) */
+  { CUPS_GENCAT_PE, "Pe" },            /* Punctuation, Close (end) */
+  { CUPS_GENCAT_PI, "Pi" },            /* Punctuation, Initial Quote */
+  { CUPS_GENCAT_PF, "Pf" },            /* Punctuation, Final Quote */
+  { CUPS_GENCAT_PO, "Po" },            /* Punctuation, Other */
+  { CUPS_GENCAT_SM, "Sm" },            /* Symbol, Math */
+  { CUPS_GENCAT_SC, "Sc" },            /* Symbol, Currency */
+  { CUPS_GENCAT_SK, "Sk" },            /* Symbol, Modifier */
+  { CUPS_GENCAT_SO, "So" },            /* Symbol, Other */
+  { CUPS_GENCAT_ZS, "Zs" },            /* Separator, Space */
+  { CUPS_GENCAT_ZL, "Zl" },            /* Separator, Line */
+  { CUPS_GENCAT_ZP, "Zp" },            /* Separator, Paragraph */
+  { CUPS_GENCAT_CC, "Cc" },            /* Other, Control */
+  { CUPS_GENCAT_CF, "Cf" },            /* Other, Format */
+  { CUPS_GENCAT_CS, "Cs" },            /* Other, Surrogate */
+  { CUPS_GENCAT_CO, "Co" },            /* Other, Private Use */
+  { CUPS_GENCAT_CN, "Cn" },            /* Other, Not Assigned */
   { 0, NULL }
 };
 
-static const char *bidicat_index[] =          /* Bidi Category Index */
+static const char * const bidicat_index[] =
+                                       /* Bidi Category Index */
 {
-  "L",  /* Left-to-Right (Alpha, Syllabic, Ideographic) */
-  "LRE",/* Left-to-Right Embedding (explicit) */
-  "LRO",/* Left-to-Right Override (explicit) */
-  "R",  /* Right-to-Left (Hebrew alphabet and most punct) */
-  "AL", /* Right-to-Left Arabic (Arabic, Thaana, Syriac) */
-  "RLE",/* Right-to-Left Embedding (explicit) */
-  "RLO",/* Right-to-Left Override (explicit) */
-  "PDF",/* Pop Directional Format */
-  "EN", /* Euro Number (Euro and East Arabic-Indic digits) */
-  "ES", /* Euro Number Separator (Slash) */
-  "ET", /* Euro Number Termintor (Plus, Minus, Degree, etc) */
-  "AN", /* Arabic Number (Arabic-Indic digits, separators) */
-  "CS", /* Common Number Separator (Colon, Comma, Dot, etc) */
-  "NSM",/* Non-Spacing Mark (category Mn / Me in UCD) */
-  "BN", /* Boundary Neutral (Formatting / Control chars) */
-  "B",  /* Paragraph Separator */
-  "S",  /* Segment Separator (Tab) */
-  "WS", /* Whitespace Space (Space, Line Separator, etc) */
-  "ON", /* Other Neutrals */
+  "L",                                 /* Left-to-Right (Alpha, Syllabic, Ideographic) */
+  "LRE",                               /* Left-to-Right Embedding (explicit) */
+  "LRO",                               /* Left-to-Right Override (explicit) */
+  "R",                                 /* Right-to-Left (Hebrew alphabet and most punct) */
+  "AL",                                        /* Right-to-Left Arabic (Arabic, Thaana, Syriac) */
+  "RLE",                               /* Right-to-Left Embedding (explicit) */
+  "RLO",                               /* Right-to-Left Override (explicit) */
+  "PDF",                               /* Pop Directional Format */
+  "EN",                                        /* Euro Number (Euro and East Arabic-Indic digits) */
+  "ES",                                        /* Euro Number Separator (Slash) */
+  "ET",                                        /* Euro Number Termintor (Plus, Minus, Degree, etc) */
+  "AN",                                        /* Arabic Number (Arabic-Indic digits, separators) */
+  "CS",                                        /* Common Number Separator (Colon, Comma, Dot, etc) */
+  "NSM",                               /* Non-Spacing Mark (category Mn / Me in UCD) */
+  "BN",                                        /* Boundary Neutral (Formatting / Control chars) */
+  "B",                                 /* Paragraph Separator */
+  "S",                                 /* Segment Separator (Tab) */
+  "WS",                                        /* Whitespace Space (Space, Line Separator, etc) */
+  "ON",                                        /* Other Neutrals */
   NULL
 };
 
-typedef struct                  /**** Line Break Class Index Struct****/
+typedef struct                         /**** Line Break Class Index Struct****/
 {
-  cups_breakclass_t     breakclass;     /* Line Break Class Value */
-  const char            *str;           /* Line Break Class String */
+  cups_breakclass_t    breakclass;     /* Line Break Class Value */
+  const char           *str;           /* Line Break Class String */
 } break_t;
 
-static break_t break_index[] =          /* Line Break Class Index */
+static const break_t break_index[] =   /* Line Break Class Index */
 {
-  { CUPS_BREAK_AI, "AI" },  /* Ambiguous (Alphabetic or Ideograph) */
-  { CUPS_BREAK_AL, "AL" },  /* Ordinary Alpha/Symbol Chars (XP) */
-  { CUPS_BREAK_BA, "BA" },  /* Break Opportunity After Chars (A) */
-  { CUPS_BREAK_BB, "BB" },  /* Break Opportunities Before Chars (B) */
-  { CUPS_BREAK_B2, "B2" },  /* Break Opportunity Either (B/A/XP) */
-  { CUPS_BREAK_BK, "BK" },  /* Mandatory Break (A) (norm) */
-  { CUPS_BREAK_CB, "CB" },  /* Contingent Break (B/A) (norm) */
-  { CUPS_BREAK_CL, "CL" },  /* Closing Punctuation (XB) */
-  { CUPS_BREAK_CM, "CM" },  /* Attached/Combining (XB) (norm) */
-  { CUPS_BREAK_CR, "CR" },  /* Carriage Return (A) (norm) */
-  { CUPS_BREAK_EX, "EX" },  /* Exclamation / Interrogation (XB) */
-  { CUPS_BREAK_GL, "GL" },  /* Non-breaking ("Glue") (XB/XA) (norm) */
-  { CUPS_BREAK_HY, "HY" },  /* Hyphen (XA) */
-  { CUPS_BREAK_ID, "ID" },  /* Ideographic (B/A) */
-  { CUPS_BREAK_IN, "IN" },  /* Inseparable chars (XP) */
-  { CUPS_BREAK_IS, "IS" },  /* Numeric Separator (Infix) (XB) */
-  { CUPS_BREAK_LF, "LF" },  /* Line Feed (A) (norm) */
-  { CUPS_BREAK_NS, "NS" },  /* Non-starters (XB) */
-  { CUPS_BREAK_NU, "NU" },  /* Numeric (XP) */
-  { CUPS_BREAK_OP, "OP" },  /* Opening Punctuation (XA) */
-  { CUPS_BREAK_PO, "PO" },  /* Postfix (Numeric) (XB) */
-  { CUPS_BREAK_PR, "PR" },  /* Prefix (Numeric) (XA) */
-  { CUPS_BREAK_QU, "QU" },  /* Ambiguous Quotation (XB/XA) */
-  { CUPS_BREAK_SA, "SA" },  /* Context Dependent (SE Asian) (P) */
-  { CUPS_BREAK_SG, "SG" },  /* Surrogates (XP) (norm) */
-  { CUPS_BREAK_SP, "SP" },  /* Space (A) (norm) */
-  { CUPS_BREAK_SY, "SY" },  /* Symbols Allowing Break After (A) */
-  { CUPS_BREAK_XX, "XX" },  /* Unknown (XP) */
-  { CUPS_BREAK_ZW, "ZW" },  /* Zero Width Space (A) (norm) */
+  { CUPS_BREAK_AI, "AI" },             /* Ambiguous (Alphabetic or Ideograph) */
+  { CUPS_BREAK_AL, "AL" },             /* Ordinary Alpha/Symbol Chars (XP) */
+  { CUPS_BREAK_BA, "BA" },             /* Break Opportunity After Chars (A) */
+  { CUPS_BREAK_BB, "BB" },             /* Break Opportunities Before Chars (B) */
+  { CUPS_BREAK_B2, "B2" },             /* Break Opportunity Either (B/A/XP) */
+  { CUPS_BREAK_BK, "BK" },             /* Mandatory Break (A) (norm) */
+  { CUPS_BREAK_CB, "CB" },             /* Contingent Break (B/A) (norm) */
+  { CUPS_BREAK_CL, "CL" },             /* Closing Punctuation (XB) */
+  { CUPS_BREAK_CM, "CM" },             /* Attached/Combining (XB) (norm) */
+  { CUPS_BREAK_CR, "CR" },             /* Carriage Return (A) (norm) */
+  { CUPS_BREAK_EX, "EX" },             /* Exclamation / Interrogation (XB) */
+  { CUPS_BREAK_GL, "GL" },             /* Non-breaking ("Glue") (XB/XA) (norm) */
+  { CUPS_BREAK_HY, "HY" },             /* Hyphen (XA) */
+  { CUPS_BREAK_ID, "ID" },             /* Ideographic (B/A) */
+  { CUPS_BREAK_IN, "IN" },             /* Inseparable chars (XP) */
+  { CUPS_BREAK_IS, "IS" },             /* Numeric Separator (Infix) (XB) */
+  { CUPS_BREAK_LF, "LF" },             /* Line Feed (A) (norm) */
+  { CUPS_BREAK_NS, "NS" },             /* Non-starters (XB) */
+  { CUPS_BREAK_NU, "NU" },             /* Numeric (XP) */
+  { CUPS_BREAK_OP, "OP" },             /* Opening Punctuation (XA) */
+  { CUPS_BREAK_PO, "PO" },             /* Postfix (Numeric) (XB) */
+  { CUPS_BREAK_PR, "PR" },             /* Prefix (Numeric) (XA) */
+  { CUPS_BREAK_QU, "QU" },             /* Ambiguous Quotation (XB/XA) */
+  { CUPS_BREAK_SA, "SA" },             /* Context Dependent (SE Asian) (P) */
+  { CUPS_BREAK_SG, "SG" },             /* Surrogates (XP) (norm) */
+  { CUPS_BREAK_SP, "SP" },             /* Space (A) (norm) */
+  { CUPS_BREAK_SY, "SY" },             /* Symbols Allowing Break After (A) */
+  { CUPS_BREAK_XX, "XX" },             /* Unknown (XP) */
+  { CUPS_BREAK_ZW, "ZW" },             /* Zero Width Space (A) (norm) */
   { 0, NULL }
 };
 
@@ -188,156 +174,200 @@ static break_t break_index[] =          /* Line Break Class Index */
  * Prototypes...
  */
 
+static int compare_breakchar(const void *k1, const void *k2);
+static int compare_combchar(const void *k1, const void *k2);
+static int compare_compose(const void *k1, const void *k2);
+static int compare_decompose(const void *k1, const void *k2);
+static int compare_foldchar(const void *k1, const void *k2);
+static int compare_propchar(const void *k1, const void *k2);
 static int get_bidi_category(const cups_utf32_t ch);
-static int get_combining_class(const cups_utf32_t ch);
 static int get_break_class(const cups_utf32_t ch);
+static int get_breakmap(void);
+static int get_combining_class(const cups_utf32_t ch);
+static int get_combmap(void);
+static int get_foldmap(const cups_folding_t fold);
 static int get_general_category(const cups_utf32_t ch);
 static int get_map_count(const char *filename);
 static int get_normmap(const cups_normalize_t normalize);
-static int get_foldmap(const cups_folding_t fold);
 static int get_propmap(void);
-static int get_combmap(void);
-static int get_breakmap(void);
-static int compare_compose(const void *k1, const void *k2);
-static int compare_decompose(const void *k1, const void *k2);
-static int compare_foldchar(const void *k1, const void *k2);
-static int compare_combchar(const void *k1, const void *k2);
-static int compare_propchar(const void *k1, const void *k2);
-static int compare_breakchar(const void *k1, const void *k2);
+
 
 /*
  * 'cupsNormalizeMapsGet()' - Get all normalization maps to cache.
  */
-int                                     /* O - Zero or -1 on error */
+
+int                                    /* O - Zero or -1 on error */
 cupsNormalizeMapsGet(void)
 {
-  cups_normmap_t    *nmap;      /* Unicode Normalization Map */
-  cups_foldmap_t    *fmap;      /* Unicode Case Folding Map */
+  cups_normmap_t       *nmap;          /* Unicode Normalization Map */
+  cups_foldmap_t       *fmap;          /* Unicode Case Folding Map */
+  cups_globals_t       *cg = _cupsGlobals();
+                                       /* Pointer to library globals */
+
 
  /*
   * See if we already have normalization maps loaded...
   */
-  if (normmap_cache)
+
+  if (cg->normmap_cache)
   {
-    for (nmap = normmap_cache; nmap != NULL; nmap = nmap->next)
+    for (nmap = cg->normmap_cache; nmap != NULL; nmap = nmap->next)
       nmap->used ++;
-    for (fmap = foldmap_cache; fmap != NULL; fmap = fmap->next)
+
+    for (fmap = cg->foldmap_cache; fmap != NULL; fmap = fmap->next)
       fmap->used ++;
-    if (combmap_cache)
-      combmap_cache->used ++;
-    if (propmap_cache)
-      propmap_cache->used ++;
-    if (breakmap_cache)
-      breakmap_cache->used ++;
+
+    if (cg->combmap_cache)
+      cg->combmap_cache->used ++;
+
+    if (cg->propmap_cache)
+      cg->propmap_cache->used ++;
+
+    if (cg->breakmap_cache)
+      cg->breakmap_cache->used ++;
+
     return (0);
   }
 
  /*
   * Get normalization maps...
   */
+
   if (get_normmap(CUPS_NORM_NFD) < 0)
     return (-1);
+
   if (get_normmap(CUPS_NORM_NFKD) < 0)
     return (-1);
+
   if (get_normmap(CUPS_NORM_NFC) < 0)
     return (-1);
 
  /*
   * Get case folding, combining class, character property maps...
   */
+
   if (get_foldmap(CUPS_FOLD_SIMPLE) < 0)
     return (-1);
+
   if (get_foldmap(CUPS_FOLD_FULL) < 0)
     return (-1);
+
   if (get_propmap() < 0)
     return (-1);
+
   if (get_combmap() < 0)
     return (-1);
+
   if (get_breakmap() < 0)
     return (-1);
+
   return (0);
 }
 
+
 /*
  * 'cupsNormalizeMapsFree()' - Free all normalization maps in cache.
  *
  * This does not actually free; use 'cupsNormalizeMapsFlush()' for that.
  */
-int                                     /* O - Zero or -1 on error */
+
+int                                    /* O - Zero or -1 on error */
 cupsNormalizeMapsFree(void)
 {
-  cups_normmap_t    *nmap;      /* Unicode Normalization Map */
-  cups_foldmap_t    *fmap;      /* Unicode Case Folding Map */
+  cups_normmap_t       *nmap;          /* Unicode Normalization Map */
+  cups_foldmap_t       *fmap;          /* Unicode Case Folding Map */
+  cups_globals_t       *cg = _cupsGlobals();
+                                       /* Pointer to library globals */
+
 
  /*
   * See if we already have normalization maps loaded...
   */
-  if (normmap_cache == NULL)
+
+  if (cg->normmap_cache == NULL)
     return (-1);
-  for (nmap = normmap_cache; nmap != NULL; nmap = nmap->next)
+
+  for (nmap = cg->normmap_cache; nmap != NULL; nmap = nmap->next)
     if (nmap->used > 0)
       nmap->used --;
-  for (fmap = foldmap_cache; fmap != NULL; fmap = fmap->next)
+
+  for (fmap = cg->foldmap_cache; fmap != NULL; fmap = fmap->next)
     if (fmap->used > 0)
       fmap->used --;
-  if (propmap_cache && (propmap_cache->used > 0))
-    propmap_cache->used --;
-  if (combmap_cache && (combmap_cache->used > 0))
-    combmap_cache->used --;
-  if (breakmap_cache && (breakmap_cache->used > 0))
-    breakmap_cache->used --;
+
+  if (cg->propmap_cache && (cg->propmap_cache->used > 0))
+    cg->propmap_cache->used --;
+
+  if (cg->combmap_cache && (cg->combmap_cache->used > 0))
+    cg->combmap_cache->used --;
+
+  if (cg->breakmap_cache && (cg->breakmap_cache->used > 0))
+    cg->breakmap_cache->used --;
+
   return (0);
 }
 
+
 /*
  * 'cupsNormalizeMapsFlush()' - Flush all normalization maps in cache.
  */
+
 void
 cupsNormalizeMapsFlush(void)
 {
-  cups_normmap_t    *nmap;      /* Unicode Normalization Map */
-  cups_normmap_t    *nextnorm;  /* Next Unicode Normalization Map */
-  cups_foldmap_t    *fmap;      /* Unicode Case Folding Map */
-  cups_foldmap_t    *nextfold;  /* Next Unicode Case Folding Map */
+  cups_normmap_t       *nmap;          /* Unicode Normalization Map */
+  cups_normmap_t       *nextnorm;      /* Next Unicode Normalization Map */
+  cups_foldmap_t       *fmap;          /* Unicode Case Folding Map */
+  cups_foldmap_t       *nextfold;      /* Next Unicode Case Folding Map */
+  cups_globals_t       *cg = _cupsGlobals();
+                                       /* Pointer to library globals */
+
 
  /*
   * Flush all normalization maps...
   */
-  for (nmap = normmap_cache; nmap != NULL; nmap = nextnorm)
+
+  for (nmap = cg->normmap_cache; nmap != NULL; nmap = nextnorm)
   {
     free(nmap->uni2norm);
     nextnorm = nmap->next;
     free(nmap);
   }
-  normmap_cache = NULL;
-  for (fmap = foldmap_cache; fmap != NULL; fmap = nextfold)
+
+  cg->normmap_cache = NULL;
+
+  for (fmap = cg->foldmap_cache; fmap != NULL; fmap = nextfold)
   {
     free(fmap->uni2fold);
     nextfold = fmap->next;
     free(fmap);
   }
-  foldmap_cache = NULL;
-  if (propmap_cache)
+
+  cg->foldmap_cache = NULL;
+
+  if (cg->propmap_cache)
   {
-    free(propmap_cache->uni2prop);
-    free(propmap_cache);
-    propmap_cache = NULL;
+    free(cg->propmap_cache->uni2prop);
+    free(cg->propmap_cache);
+    cg->propmap_cache = NULL;
   }
-  if (combmap_cache)
+
+  if (cg->combmap_cache)
   {
-    free(combmap_cache->uni2comb);
-    free(combmap_cache);
-    combmap_cache = NULL;
+    free(cg->combmap_cache->uni2comb);
+    free(cg->combmap_cache);
+    cg->combmap_cache = NULL;
   }
-  if (breakmap_cache)
+
+  if (cg->breakmap_cache)
   {
-    free(breakmap_cache->uni2break);
-    free(breakmap_cache);
-    breakmap_cache = NULL;
+    free(cg->breakmap_cache->uni2break);
+    free(cg->breakmap_cache);
+    cg->breakmap_cache = NULL;
   }
-  return;
 }
 
+
 /*
  * 'cupsUTF8Normalize()' - Normalize UTF-8 string.
  *
@@ -345,49 +375,56 @@ cupsNormalizeMapsFlush(void)
  * Note - Compatibility Normalization Forms (NFKD/NFKC) are
  * unsafe for subsequent transcoding to legacy charsets
  */
-int                                     /* O - Count or -1 on error */
-cupsUTF8Normalize(cups_utf8_t *dest,    /* O - Target string */
-    const cups_utf8_t *src,             /* I - Source string */
-    const int maxout,                   /* I - Max output */
-    const cups_normalize_t normalize)   /* I - Normalization */
+
+int                                    /* O - Count or -1 on error */
+cupsUTF8Normalize(
+    cups_utf8_t            *dest,      /* O - Target string */
+    const cups_utf8_t      *src,       /* I - Source string */
+    const int              maxout,     /* I - Max output */
+    const cups_normalize_t normalize)  /* I - Normalization */
 {
-  int           len;            /* String length */
-  cups_utf32_t       work1[CUPS_MAX_USTRING];
-                                /* First internal UCS-4 string */
-  cups_utf32_t       work2[CUPS_MAX_USTRING];
-                                /* Second internal UCS-4 string */
+  int          len;                    /* String length */
+  cups_utf32_t work1[CUPS_MAX_USTRING];/* First internal UCS-4 string */
+  cups_utf32_t work2[CUPS_MAX_USTRING];/* Second internal UCS-4 string */
+
 
  /*
   * Check for valid arguments and clear output...
   */
-  if ((dest == NULL)
-  || (src == NULL)
-  || (maxout < 1)
-  || (maxout > CUPS_MAX_USTRING))
+
+  if (!dest || !src || maxout < 1 || maxout > CUPS_MAX_USTRING)
     return (-1);
+
   *dest = 0;
 
  /*
   * Convert input UTF-8 to internal UCS-4 (and insert BOM)...
   */
+
   len = cupsUTF8ToUTF32(work1, src, CUPS_MAX_USTRING);
+
   if (len < 0)
     return (-1);
 
  /*
   * Normalize internal UCS-4 to second internal UCS-4...
   */
+
   len = cupsUTF32Normalize(work2, work1, CUPS_MAX_USTRING, normalize);
+
   if (len < 0)
     return (-1);
 
  /*
   * Convert internal UCS-4 to output UTF-8 (and delete BOM)...
   */
+
   len = cupsUTF32ToUTF8(dest, work2, maxout);
+
   return (len);
 }
 
+
 /*
  * 'cupsUTF32Normalize()' - Normalize UTF-32 string.
  *
@@ -395,96 +432,111 @@ cupsUTF8Normalize(cups_utf8_t *dest,    /* O - Target string */
  * Note - Compatibility Normalization Forms (NFKD/NFKC) are
  * unsafe for subsequent transcoding to legacy charsets
  */
-int                                     /* O - Count or -1 on error */
-cupsUTF32Normalize(cups_utf32_t *dest,  /* O - Target string */
-    const cups_utf32_t *src,            /* I - Source string */
-    const int maxout,                   /* I - Max output */
-    const cups_normalize_t normalize)   /* I - Normalization */
+
+int                                    /* O - Count or -1 on error */
+cupsUTF32Normalize(
+    cups_utf32_t           *dest,      /* O - Target string */
+    const cups_utf32_t     *src,       /* I - Source string */
+    const int              maxout,     /* I - Max output */
+    const cups_normalize_t normalize)  /* I - Normalization */
 {
-  int           i;              /* Looping variable */
-  int           result;         /* Result Value */
-  cups_ucs2_t   *mp;            /* Map char pointer */
-  int           pass;           /* Pass count for each transform */
-  int           hit;            /* Hit count from binary search */
-  cups_utf32_t  unichar1;       /* Unicode character value */
-  cups_utf32_t  unichar2;       /* Unicode character value */
-  cups_combclass_t  class1;     /* First Combining Class */
-  cups_combclass_t  class2;     /* Second Combining Class */
-  int           len;            /* String length */
-  cups_utf32_t  work1[CUPS_MAX_USTRING];
-                                /* First internal UCS-4 string */
-  cups_utf32_t  work2[CUPS_MAX_USTRING];
-                                /* Second internal UCS-4 string */
-  cups_utf32_t  *p1;            /* First UCS-4 string pointer */
-  cups_utf32_t  *p2;            /* Second UCS-4 string pointer */
-  cups_normmap_t    *nmap;      /* Unicode Normalization Map */
-  cups_normalize_t  decompose;  /* Decomposition Type */
+  int                  i;              /* Looping variable */
+  int                  result;         /* Result Value */
+  cups_ucs2_t          *mp;            /* Map char pointer */
+  int                  pass;           /* Pass count for each transform */
+  int                  hit;            /* Hit count from binary search */
+  cups_utf32_t         unichar1;       /* Unicode character value */
+  cups_utf32_t         unichar2;       /* Unicode character value */
+  cups_combclass_t     class1;         /* First Combining Class */
+  cups_combclass_t     class2;         /* Second Combining Class */
+  int                  len;            /* String length */
+  cups_utf32_t         work1[CUPS_MAX_USTRING];
+                                       /* First internal UCS-4 string */
+  cups_utf32_t         work2[CUPS_MAX_USTRING];
+                                       /* Second internal UCS-4 string */
+  cups_utf32_t         *p1;            /* First UCS-4 string pointer */
+  cups_utf32_t         *p2;            /* Second UCS-4 string pointer */
+  cups_normmap_t       *nmap;          /* Unicode Normalization Map */
+  cups_normalize_t     decompose;      /* Decomposition Type */
+  cups_globals_t       *cg = _cupsGlobals();
+                                       /* Pointer to library globals */
+
 
  /*
   * Check for valid arguments and clear output...
   */
-  if ((dest == NULL)
-  || (src == NULL)
-  || (maxout < 1)
-  || (maxout > CUPS_MAX_USTRING))
+
+  if (!dest || !src || maxout < 1 || maxout > CUPS_MAX_USTRING)
     return (-1);
+
   *dest = 0;
+
   result = cupsNormalizeMapsGet();
+
   if (result < 0)
     return (-1);
 
  /*
   * Find decomposition map...
   */
+
   switch (normalize)
   {
     case CUPS_NORM_NFD:
     case CUPS_NORM_NFC:
-      decompose = CUPS_NORM_NFD;
-      break;
+       decompose = CUPS_NORM_NFD;
+       break;
+
     case CUPS_NORM_NFKD:
     case CUPS_NORM_NFKC:
-      decompose = CUPS_NORM_NFKD;
-      break;
+       decompose = CUPS_NORM_NFKD;
+       break;
+
     default:
-      return (-1);
+       return (-1);
   }
-  for (nmap = normmap_cache; nmap != NULL; nmap = nmap->next)
+
+  for (nmap = cg->normmap_cache; nmap != NULL; nmap = nmap->next)
     if (nmap->normalize == decompose)
       break;
+
   if (nmap == NULL)
     return (-1);
 
  /*
   * Copy input to internal buffer...
   */
+
   p1 = &work1[0];
+
   for (i = 0; i < CUPS_MAX_USTRING; i ++)
   {
     if (*src == 0)
       break;
+
     *p1 ++ = *src ++;
   }
+
   *p1 = 0;
   len = i;
 
  /*
   * Decompose until no further decomposition...
   */
+
   for (pass = 0; pass < 20; pass ++)
   {
     p1 = &work1[0];
     p2 = &work2[0];
+
     for (hit = 0; *p1 != 0; p1 ++)
     {
      /*
       * Check for decomposition defined...
       */
-      mp = (cups_ucs2_t *) bsearch(p1,
-                                   nmap->uni2norm,
-                                   nmap->normcount,
-                                   (sizeof(cups_ucs2_t) * 3),
-                                   compare_decompose);
+
+      mp = (cups_ucs2_t *)bsearch(p1, nmap->uni2norm, nmap->normcount,
+                                  (sizeof(cups_ucs2_t) * 3), compare_decompose);
       if (mp == NULL)
       {
         *p2 ++ = *p1;
@@ -494,14 +546,17 @@ cupsUTF32Normalize(cups_utf32_t *dest,  /* O - Target string */
      /*
       * Decompose input character to one or two output characters...
       */
+
       hit ++;
       mp ++;
       *p2 ++ = (cups_utf32_t) *mp ++;
+
       if (*mp != 0)
         *p2 ++ = (cups_utf32_t) *mp;
     }
+
     *p2 = 0;
-    len = (int) (p2 - &work2[0]);
+    len = (int)(p2 - &work2[0]);
 
    /*
     * Check for decomposition finished...
@@ -514,37 +569,45 @@ cupsUTF32Normalize(cups_utf32_t *dest,  /* O - Target string */
  /*
   * Canonical reorder until no further reordering...
   */
+
   for (pass = 0; pass < 20; pass ++)
   {
     p1 = &work1[0];
+
     for (hit = 0; *p1 != 0; p1 ++)
     {
      /*
       * Check for combining characters to reorder...
       */
+
       unichar1 = *p1;
       unichar2 = *(p1 + 1);
+
       if (unichar2 == 0)
         break;
+
       class1 = get_combining_class(unichar1);
       class2 = get_combining_class(unichar2);
+
       if ((class1 < 0) || (class2 < 0))
         return (-1);
+
       if ((class1 == 0) || (class2 == 0))
         continue;
+
       if (class1 <= class2)
         continue;
 
      /*
       * Swap two combining characters...
       */
-      {
-        *p1 = unichar2;
-        p1 ++;
-        *p1 = unichar1;
-        hit ++;
-      }
+
+      *p1 = unichar2;
+      p1 ++;
+      *p1 = unichar1;
+      hit ++;
     }
+
     if (hit == 0)
       break;
   }
@@ -552,45 +615,50 @@ cupsUTF32Normalize(cups_utf32_t *dest,  /* O - Target string */
  /*
   * Check for decomposition only...
   */
-  if ((normalize == CUPS_NORM_NFD) || (normalize == CUPS_NORM_NFKD))
+
+  if (normalize == CUPS_NORM_NFD || normalize == CUPS_NORM_NFKD)
   {
-    memcpy (dest, work1, sizeof(cups_utf32_t) * (len + 1));
+    memcpy(dest, work1, sizeof(cups_utf32_t) * (len + 1));
     return (len);
   }
 
  /*
   * Find composition map...
   */
-  for (nmap = normmap_cache; nmap != NULL; nmap = nmap->next)
+
+  for (nmap = cg->normmap_cache; nmap != NULL; nmap = nmap->next)
     if (nmap->normalize == CUPS_NORM_NFC)
       break;
+
   if (nmap == NULL)
     return (-1);
 
  /*
   * Compose until no further composition...
   */
+
   for (pass = 0; pass < 20; pass ++)
   {
     p1 = &work1[0];
     p2 = &work2[0];
+
     for (hit = 0; *p1 != 0; p1 ++)
     {
      /*
       * Check for composition defined...
       */
+
       unichar1 = *p1;
       unichar2 = *(p1 + 1);
+
       if (unichar2 == 0)
       {
         *p2 ++ = unichar1;
         break;
       }
-      mp = (cups_ucs2_t *) bsearch(p1,
-                                   nmap->uni2norm,
-                                   nmap->normcount,
-                                   (sizeof(cups_ucs2_t) * 3),
-                                   compare_compose);
+
+      mp = (cups_ucs2_t *)bsearch(p1, nmap->uni2norm, nmap->normcount,
+                                  (sizeof(cups_ucs2_t) * 3), compare_compose);
       if (mp == NULL)
       {
         *p2 ++ = *p1;
@@ -600,26 +668,34 @@ cupsUTF32Normalize(cups_utf32_t *dest,  /* O - Target string */
      /*
       * Compose two input characters to one output character...
       */
+
       hit ++;
       mp += 2;
       *p2 ++ = (cups_utf32_t) *mp;
       p1 ++;
     }
+
     *p2 = 0;
     len = (int) (p2 - &work2[0]);
 
    /*
     * Check for composition finished...
     */
+
     if (hit == 0)
       break;
+
     memcpy (work1, work2, sizeof(cups_utf32_t) * (len + 1));
   }
+
   memcpy (dest, work1, sizeof(cups_utf32_t) * (len + 1));
+
   cupsNormalizeMapsFree();
+
   return (len);
 }
 
+
 /*
  * 'cupsUTF8CaseFold()' - Case fold UTF-8 string.
  *
@@ -627,51 +703,59 @@ cupsUTF32Normalize(cups_utf32_t *dest,  /* O - Target string */
  * Note - Case folding output is
  * unsafe for subsequent transcoding to legacy charsets
  */
-int                                     /* O - Count or -1 on error */
-cupsUTF8CaseFold(cups_utf8_t *dest,     /* O - Target string */
-    const cups_utf8_t *src,             /* I - Source string */
-    const int maxout,                   /* I - Max output */
-    const cups_folding_t fold)          /* I - Fold Mode */
+
+int                                    /* O - Count or -1 on error */
+cupsUTF8CaseFold(
+    cups_utf8_t          *dest,                /* O - Target string */
+    const cups_utf8_t    *src,         /* I - Source string */
+    const int            maxout,       /* I - Max output */
+    const cups_folding_t fold)         /* I - Fold Mode */
 {
-  int           len;            /* String length */
-  cups_utf32_t  work1[CUPS_MAX_USTRING];
-                                /* First internal UCS-4 string */
-  cups_utf32_t  work2[CUPS_MAX_USTRING];
-                                /* Second internal UCS-4 string */
+  int          len;                    /* String length */
+  cups_utf32_t work1[CUPS_MAX_USTRING];/* First internal UCS-4 string */
+  cups_utf32_t work2[CUPS_MAX_USTRING];/* Second internal UCS-4 string */
+
 
  /*
   * Check for valid arguments and clear output...
   */
-  if ((dest == NULL)
-  || (src == NULL)
-  || (maxout < 1)
-  || (maxout > CUPS_MAX_USTRING))
+
+  if (!dest || !src || maxout < 1 || maxout > CUPS_MAX_USTRING)
     return (-1);
+
   *dest = 0;
-  if ((fold != CUPS_FOLD_SIMPLE) && (fold != CUPS_FOLD_FULL))
+
+  if (fold != CUPS_FOLD_SIMPLE && fold != CUPS_FOLD_FULL)
     return (-1);
 
  /*
   * Convert input UTF-8 to internal UCS-4 (and insert BOM)...
   */
+
   len = cupsUTF8ToUTF32(work1, src, CUPS_MAX_USTRING);
+
   if (len < 0)
     return (-1);
 
  /*
   * Case Fold internal UCS-4 to second internal UCS-4...
   */
+
   len = cupsUTF32CaseFold(work2, work1, CUPS_MAX_USTRING, fold);
+
   if (len < 0)
     return (-1);
 
  /*
   * Convert internal UCS-4 to output UTF-8 (and delete BOM)...
   */
+
   len = cupsUTF32ToUTF8(dest, work2, maxout);
+
   return (len);
 }
 
+
 /*
  * 'cupsUTF32CaseFold()' - Case fold UTF-32 string.
  *
@@ -679,55 +763,63 @@ cupsUTF8CaseFold(cups_utf8_t *dest,     /* O - Target string */
  * Note - Case folding output is
  * unsafe for subsequent transcoding to legacy charsets
  */
-int                                     /* O - Count or -1 on error */
-cupsUTF32CaseFold(cups_utf32_t *dest,   /* O - Target string */
-    const cups_utf32_t *src,            /* I - Source string */
-    const int maxout,                   /* I - Max output */
-    const cups_folding_t fold)          /* I - Fold Mode */
+
+int                                    /* O - Count or -1 on error */
+cupsUTF32CaseFold(
+    cups_utf32_t         *dest,                /* O - Target string */
+    const cups_utf32_t   *src,         /* I - Source string */
+    const int            maxout,       /* I - Max output */
+    const cups_folding_t fold)         /* I - Fold Mode */
 {
-  cups_utf32_t  *start = dest;  /* Start of destination string */
-  int           i;              /* Looping variable */
-  int           result;         /* Result Value */
-  cups_ucs2_t   *mp;            /* Map char pointer */
-  cups_foldmap_t    *fmap;      /* Unicode Case Folding Map */
+  cups_utf32_t         *start = dest;  /* Start of destination string */
+  int                  i;              /* Looping variable */
+  int                  result;         /* Result Value */
+  cups_ucs2_t          *mp;            /* Map char pointer */
+  cups_foldmap_t       *fmap;          /* Unicode Case Folding Map */
+  cups_globals_t       *cg = _cupsGlobals();
+                                       /* Pointer to library globals */
+
 
  /*
   * Check for valid arguments and clear output...
   */
-  if ((dest == NULL)
-  || (src == NULL)
-  || (maxout < 1)
-  || (maxout > CUPS_MAX_USTRING))
+
+  if (!dest || !src || maxout < 1 || maxout > CUPS_MAX_USTRING)
     return (-1);
+
   *dest = 0;
-  if ((fold != CUPS_FOLD_SIMPLE) && (fold != CUPS_FOLD_FULL))
+
+  if (fold != CUPS_FOLD_SIMPLE && fold != CUPS_FOLD_FULL)
     return (-1);
 
  /*
   * Find case folding map...
   */
+
   result = cupsNormalizeMapsGet();
+
   if (result < 0)
     return (-1);
-  for (fmap = foldmap_cache; fmap != NULL; fmap = fmap->next)
+
+  for (fmap = cg->foldmap_cache; fmap != NULL; fmap = fmap->next)
     if (fmap->fold == fold)
       break;
+
   if (fmap == NULL)
     return (-1);
 
  /*
   * Case fold input string to output string...
   */
+
   for (i = 0; i < (maxout - 1); i ++, src ++)
   {
    /*
     * Check for case folding defined...
     */
-    mp = (cups_ucs2_t *) bsearch(src,
-                                 fmap->uni2fold,
-                                 fmap->foldcount,
-                                 (sizeof(cups_ucs2_t) * 4),
-                                 compare_foldchar);
+
+    mp = (cups_ucs2_t *)bsearch(src, fmap->uni2fold, fmap->foldcount,
+                                (sizeof(cups_ucs2_t) * 4), compare_foldchar);
     if (mp == NULL)
     {
       *dest ++ = *src;
@@ -737,345 +829,425 @@ cupsUTF32CaseFold(cups_utf32_t *dest,   /* O - Target string */
    /*
     * Case fold input character to one or two output characters...
     */
+
     mp ++;
     *dest ++ = (cups_utf32_t) *mp ++;
-    if ((*mp != 0) && (fold == CUPS_FOLD_FULL))
+
+    if (*mp != 0 && fold == CUPS_FOLD_FULL)
     {
       i ++;
-      if (i >= (maxout -1))
+      if (i >= (maxout - 1))
         break;
+
       *dest ++ = (cups_utf32_t) *mp;
     }
   }
+
   *dest = 0;
+
   cupsNormalizeMapsFree();
+
   return (dest - start);
 }
 
+
 /*
  * 'cupsUTF8CompareCaseless()' - Compare case folded UTF-8 strings.
  */
-int                                     /* O - Difference of strings */
-cupsUTF8CompareCaseless(const cups_utf8_t *s1,
-                                        /* I - String1 */
-    const cups_utf8_t *s2)              /* I - String2 */
+
+int                                    /* O - Difference of strings */
+cupsUTF8CompareCaseless(
+    const cups_utf8_t *s1,             /* I - String1 */
+    const cups_utf8_t *s2)             /* I - String2 */
 {
-  int           difference;     /* Difference of two strings */
-  int           len;            /* String length */
-  cups_utf32_t  work1[CUPS_MAX_USTRING];
-                                /* First internal UCS-4 string */
-  cups_utf32_t  work2[CUPS_MAX_USTRING];
-                                /* Second internal UCS-4 string */
+  int          difference;             /* Difference of two strings */
+  int          len;                    /* String length */
+  cups_utf32_t work1[CUPS_MAX_USTRING];/* First internal UCS-4 string */
+  cups_utf32_t work2[CUPS_MAX_USTRING];/* Second internal UCS-4 string */
+
 
  /*
   * Check for valid arguments...
   */
-  if ((s1 == NULL)
-  || (s2 == NULL))
+
+  if (!s1 || !s2)
     return (-1);
 
  /*
   * Convert input UTF-8 to internal UCS-4 (and insert BOM)...
   */
+
   len = cupsUTF8ToUTF32(work1, s1, CUPS_MAX_USTRING);
+
   if (len < 0)
     return (-1);
+
   len = cupsUTF8ToUTF32(work2, s2, CUPS_MAX_USTRING);
+
   if (len < 0)
     return (-1);
 
  /*
   * Compare first internal UCS-4 to second internal UCS-4...
   */
+
   difference = cupsUTF32CompareCaseless(work1, work2);
+
   return (difference);
 }
 
+
 /*
  * 'cupsUTF32CompareCaseless()' - Compare case folded UTF-32 strings.
  */
-int                                     /* O - Difference of strings */
-cupsUTF32CompareCaseless(const cups_utf32_t *s1,
-                                        /* I - String1 */
-    const cups_utf32_t *s2)             /* I - String2 */
+
+int                                    /* O - Difference of strings */
+cupsUTF32CompareCaseless(
+    const cups_utf32_t *s1,            /* I - String1 */
+    const cups_utf32_t *s2)            /* I - String2 */
 {
-  int           difference;     /* Difference of two strings */
-  int           len;            /* String length */
-  cups_folding_t fold = CUPS_FOLD_FULL;
-                                /* Case folding mode */
-  cups_utf32_t  fold1[CUPS_MAX_USTRING];
-                                /* First UCS-4 folded string */
-  cups_utf32_t  fold2[CUPS_MAX_USTRING];
-                                /* Second UCS-4 folded string */
-  cups_utf32_t  *p1;            /* First UCS-4 string pointer */
-  cups_utf32_t  *p2;            /* Second UCS-4 string pointer */
+  int                  difference;     /* Difference of two strings */
+  int                  len;            /* String length */
+  cups_folding_t       fold = CUPS_FOLD_FULL;
+                                       /* Case folding mode */
+  cups_utf32_t         fold1[CUPS_MAX_USTRING];
+                                       /* First UCS-4 folded string */
+  cups_utf32_t         fold2[CUPS_MAX_USTRING];
+                                       /* Second UCS-4 folded string */
+  cups_utf32_t         *p1;            /* First UCS-4 string pointer */
+  cups_utf32_t         *p2;            /* Second UCS-4 string pointer */
+
 
  /*
   * Check for valid arguments...
   */
-  if ((s1 == NULL)
-  || (s2 == NULL))
+
+  if (!s1 || !s2)
     return (-1);
 
  /*
   * Case Fold input UTF-32 strings to internal UCS-4 strings...
   */
+
   len = cupsUTF32CaseFold(fold1, s1, CUPS_MAX_USTRING, fold);
+
   if (len < 0)
     return (-1);
+
   len = cupsUTF32CaseFold(fold2, s2, CUPS_MAX_USTRING, fold);
+
   if (len < 0)
     return (-1);
 
  /*
   * Compare first internal UCS-4 to second internal UCS-4...
   */
+
   p1 = &fold1[0];
   p2 = &fold2[0];
+
   for (;; p1 ++, p2 ++)
   {
     difference = (int) (*p1 - *p2);
+
     if (difference != 0)
       break;
+
     if ((*p1 == 0) && (*p2 == 0))
       break;
   }
+
   return (difference);
 }
 
+
 /*
  * 'cupsUTF8CompareIdentifier()' - Compare folded NFKC UTF-8 strings.
  */
-int
-cupsUTF8CompareIdentifier(const cups_utf8_t *s1,
-                                        /* I - String1 */
-    const cups_utf8_t *s2)              /* I - String2 */
+
+int                                    /* O - Result of comparison */
+cupsUTF8CompareIdentifier(
+    const cups_utf8_t *s1,             /* I - String1 */
+    const cups_utf8_t *s2)             /* I - String2 */
 {
-  int           difference;     /* Difference of two strings */
-  int           len;            /* String length */
-  cups_utf32_t  work1[CUPS_MAX_USTRING];
-                                /* First internal UCS-4 string */
-  cups_utf32_t  work2[CUPS_MAX_USTRING];
-                                /* Second internal UCS-4 string */
+  int          difference;             /* Difference of two strings */
+  int          len;                    /* String length */
+  cups_utf32_t work1[CUPS_MAX_USTRING];/* First internal UCS-4 string */
+  cups_utf32_t work2[CUPS_MAX_USTRING];/* Second internal UCS-4 string */
+
 
  /*
   * Check for valid arguments...
   */
-  if ((s1 == NULL)
-  || (s2 == NULL))
+
+  if (!s1 || !s2)
     return (-1);
 
  /*
   * Convert input UTF-8 to internal UCS-4 (and insert BOM)...
   */
+
   len = cupsUTF8ToUTF32(work1, s1, CUPS_MAX_USTRING);
+
   if (len < 0)
     return (-1);
+
   len = cupsUTF8ToUTF32(work2, s2, CUPS_MAX_USTRING);
+
   if (len < 0)
     return (-1);
 
  /*
   * Compare first internal UCS-4 to second internal UCS-4...
   */
+
   difference = cupsUTF32CompareIdentifier(work1, work2);
+
   return (difference);
 }
 
+
 /*
  * 'cupsUTF32CompareIdentifier()' - Compare folded NFKC UTF-32 strings.
  */
-int
-cupsUTF32CompareIdentifier(const cups_utf32_t *s1,
-                                        /* I - String1 */
-    const cups_utf32_t *s2)             /* I - String2 */
+
+int                                    /* O - Result of comparison */
+cupsUTF32CompareIdentifier(
+    const cups_utf32_t *s1,            /* I - String1 */
+    const cups_utf32_t *s2)            /* I - String2 */
 {
-  int           difference;     /* Difference of two strings */
-  int           len;            /* String length */
-  cups_folding_t fold = CUPS_FOLD_FULL;
-                                /* Case folding mode */
-  cups_utf32_t  fold1[CUPS_MAX_USTRING];
-                                /* First UCS-4 folded string */
-  cups_utf32_t  fold2[CUPS_MAX_USTRING];
-                                /* Second UCS-4 folded string */
-  cups_normalize_t normalize = CUPS_NORM_NFKC;
-                                /* Normalization form */
-  cups_utf32_t  norm1[CUPS_MAX_USTRING];
-                                /* First UCS-4 normalized string */
-  cups_utf32_t  norm2[CUPS_MAX_USTRING];
-                                /* Second UCS-4 normalized string */
-  cups_utf32_t  *p1;            /* First UCS-4 string pointer */
-  cups_utf32_t  *p2;            /* Second UCS-4 string pointer */
+  int                  difference;     /* Difference of two strings */
+  int                  len;            /* String length */
+  cups_folding_t       fold = CUPS_FOLD_FULL;
+                                       /* Case folding mode */
+  cups_utf32_t         fold1[CUPS_MAX_USTRING];
+                                       /* First UCS-4 folded string */
+  cups_utf32_t         fold2[CUPS_MAX_USTRING];
+                                       /* Second UCS-4 folded string */
+  cups_normalize_t     normalize = CUPS_NORM_NFKC;
+                                       /* Normalization form */
+  cups_utf32_t         norm1[CUPS_MAX_USTRING];
+                                       /* First UCS-4 normalized string */
+  cups_utf32_t         norm2[CUPS_MAX_USTRING];
+                                       /* Second UCS-4 normalized string */
+  cups_utf32_t         *p1;            /* First UCS-4 string pointer */
+  cups_utf32_t         *p2;            /* Second UCS-4 string pointer */
+
 
  /*
   * Check for valid arguments...
   */
-  if ((s1 == NULL)
-  || (s2 == NULL))
+
+  if (!s1 || !s2)
     return (-1);
 
  /*
   * Case Fold input UTF-32 strings to internal UCS-4 strings...
   */
+
   len = cupsUTF32CaseFold(fold1, s1, CUPS_MAX_USTRING, fold);
+
   if (len < 0)
     return (-1);
+
   len = cupsUTF32CaseFold(fold2, s2, CUPS_MAX_USTRING, fold);
+
   if (len < 0)
     return (-1);
 
  /*
   * Normalize internal UCS-4 strings to NFKC...
   */
+
   len = cupsUTF32Normalize(norm1, fold1, CUPS_MAX_USTRING, normalize);
+
   if (len < 0)
     return (-1);
+
   len = cupsUTF32Normalize(norm2, fold2, CUPS_MAX_USTRING, normalize);
+
   if (len < 0)
     return (-1);
 
  /*
   * Compare first internal UCS-4 to second internal UCS-4...
   */
+
   p1 = &norm1[0];
   p2 = &norm2[0];
+
   for (;; p1 ++, p2 ++)
   {
     difference = (int) (*p1 - *p2);
+
     if (difference != 0)
       break;
+
     if ((*p1 == 0) && (*p2 == 0))
       break;
   }
+
   return (difference);
 }
 
+
 /*
  * 'cupsUTF32CharacterProperty()' - Get UTF-32 character property.
  */
-int
-cupsUTF32CharacterProperty(const cups_utf32_t ch,
-                                        /* I - Source char */
-    const cups_property_t prop)         /* I - Char Property */
+
+int                                    /* O - Result of comparison */
+cupsUTF32CharacterProperty(
+    const cups_utf32_t    ch,          /* I - Source char */
+    const cups_property_t prop)                /* I - Char Property */
 {
-  int               result;     /* Result Value */
+  int  result;                         /* Result Value */
+
 
  /*
   * Check for valid arguments...
   */
+
   if (ch == 0)
     return (-1);
 
  /*
   * Find character property...
   */
+
   switch (prop)
   {
     case CUPS_PROP_GENERAL_CATEGORY:
-      result = (get_general_category(ch));
-      break;
+       result = (get_general_category(ch));
+       break;
+
     case CUPS_PROP_BIDI_CATEGORY:
-      result = (get_bidi_category(ch));
-      break;
+       result = (get_bidi_category(ch));
+       break;
+
     case CUPS_PROP_COMBINING_CLASS:
-      result = (get_combining_class(ch));
-      break;
+       result = (get_combining_class(ch));
+       break;
     case CUPS_PROP_BREAK_CLASS:
-      result = (get_break_class(ch));
-      break;
+       result = (get_break_class(ch));
+       break;
+
     default:
-      return (-1);
+        return (-1);
   }
+
   return (result);
 }
 
+
 /*
  * 'get_general_category()' - Get UTF-32 Character General Category.
  */
-static int                              /* O - Class or -1 on error */
-get_general_category(const cups_utf32_t ch)
-                                        /* I - Source char */
+
+static int                             /* O - Class or -1 on error */
+get_general_category(
+    const cups_utf32_t ch)             /* I - Source char */
 {
-  int               result;     /* Result Value */
-  cups_gencat_t     gencat;     /* General Category Value */
-  cups_propmap_t    *pmap;      /* Unicode Property Map */
-  cups_prop_t       *uni2prop;  /* Unicode Char -> Properties */
+  int                  result;         /* Result Value */
+  cups_gencat_t                gencat;         /* General Category Value */
+  cups_propmap_t       *pmap;          /* Unicode Property Map */
+  cups_prop_t          *uni2prop;      /* Unicode Char -> Properties */
+  cups_globals_t       *cg = _cupsGlobals();
+                                       /* Pointer to library globals */
+
 
  /*
   * Check for valid argument...
   */
+
   if (ch == 0)
     return (-1);
 
  /*
   * Find property map...
   */
+
   result = cupsNormalizeMapsGet();
+
   if (result < 0)
     return (-1);
-  pmap = propmap_cache;
+
+  pmap = cg->propmap_cache;
+
   if (pmap == NULL)
     return (-1);
 
  /*
   * Find character in map...
   */
-  uni2prop = (cups_prop_t *) bsearch(&ch,
-                                     pmap->uni2prop,
-                                     pmap->propcount,
-                                     (sizeof(cups_prop_t)),
-                                     compare_propchar);
+
+  uni2prop = (cups_prop_t *)bsearch(&ch, pmap->uni2prop, pmap->propcount,
+                                    (sizeof(cups_prop_t)), compare_propchar);
+
   cupsNormalizeMapsFree();
+
   if (uni2prop == NULL)
     gencat = CUPS_GENCAT_CN;            /* Other, Not Assigned */
   else
-    gencat = (cups_gencat_t) uni2prop->gencat;
-  result = (int) gencat;
+    gencat = (cups_gencat_t)uni2prop->gencat;
+
+  result = (int)gencat;
+
   return (result);
 }
 
+
 /*
  * 'get_bidi_category()' - Get UTF-32 Character Bidi Category.
  */
-static int                              /* O - Class or -1 on error */
-get_bidi_category(const cups_utf32_t ch)
-                                        /* I - Source char */
+
+static int                             /* O - Class or -1 on error */
+get_bidi_category(const cups_utf32_t ch)/* I - Source char */
 {
-  int               result;     /* Result Value */
-  cups_bidicat_t    bidicat;    /* Bidi Category Value */
-  cups_propmap_t    *pmap;      /* Unicode Property Map */
-  cups_prop_t       *uni2prop;  /* Unicode Char -> Properties */
+  int                  result;         /* Result Value */
+  cups_bidicat_t       bidicat;        /* Bidi Category Value */
+  cups_propmap_t       *pmap;          /* Unicode Property Map */
+  cups_prop_t          *uni2prop;      /* Unicode Char -> Properties */
+  cups_globals_t       *cg = _cupsGlobals();
+                                       /* Pointer to library globals */
+
 
  /*
   * Check for valid argument...
   */
+
   if (ch == 0)
     return (-1);
 
  /*
   * Find property map...
   */
+
   result = cupsNormalizeMapsGet();
+
   if (result < 0)
     return (-1);
-  pmap = propmap_cache;
+
+  pmap = cg->propmap_cache;
+
   if (pmap == NULL)
     return (-1);
 
  /*
   * Find character in map...
   */
-  uni2prop = (cups_prop_t *) bsearch(&ch,
-                                     pmap->uni2prop,
-                                     pmap->propcount,
-                                     (sizeof(cups_prop_t)),
-                                     compare_propchar);
+
+  uni2prop = (cups_prop_t *)bsearch(&ch, pmap->uni2prop, pmap->propcount,
+                                    (sizeof(cups_prop_t)), compare_propchar);
+
   cupsNormalizeMapsFree();
+
   if (uni2prop == NULL)
     bidicat = CUPS_BIDI_ON;             /* Other Neutral */
   else
-    bidicat = (cups_bidicat_t) uni2prop->bidicat;
-  result = (int) bidicat;
+    bidicat = (cups_bidicat_t)uni2prop->bidicat;
+
+  result = (int)bidicat;
+
   return (result);
 }
 
@@ -1084,119 +1256,149 @@ get_bidi_category(const cups_utf32_t ch)
  *
  * Note - Zero is non-combining (base character)
  */
-static int                              /* O - Class or -1 on error */
-get_combining_class(const cups_utf32_t ch)
-                                        /* I - Source char */
+
+static int                             /* O - Class or -1 on error */
+get_combining_class(
+    const cups_utf32_t ch)             /* I - Source char */
 {
-  int               result;     /* Result Value */
-  cups_combmap_t    *cmap;      /* Unicode Combining Class Map */
-  cups_combclass_t  combclass;  /* Unicode Combining Class */
-  cups_comb_t       *uni2comb;  /* Unicode Char -> Combining Class */
+  int                  result;         /* Result Value */
+  cups_combmap_t       *cmap;          /* Unicode Combining Class Map */
+  cups_combclass_t     combclass;      /* Unicode Combining Class */
+  cups_comb_t          *uni2comb;      /* Unicode Char -> Combining Class */
+  cups_globals_t       *cg = _cupsGlobals();
+                                       /* Pointer to library globals */
+
 
  /*
   * Check for valid argument...
   */
+
   if (ch == 0)
     return (-1);
 
  /*
   * Find combining class map...
   */
+
   result = cupsNormalizeMapsGet();
+
   if (result < 0)
     return (-1);
-  cmap = combmap_cache;
+
+  cmap = cg->combmap_cache;
+
   if (cmap == NULL)
     return (-1);
 
  /*
   * Find combining character in map...
   */
-  uni2comb = (cups_comb_t *) bsearch(&ch,
-                                     cmap->uni2comb,
-                                     cmap->combcount,
-                                     (sizeof(cups_comb_t)),
-                                     compare_combchar);
+
+  uni2comb = (cups_comb_t *)bsearch(&ch, cmap->uni2comb, cmap->combcount,
+                                    (sizeof(cups_comb_t)), compare_combchar);
+
   cupsNormalizeMapsFree();
+
   if (uni2comb == NULL)
     combclass = 0;
   else
-    combclass = (cups_combclass_t) uni2comb->combclass;
-  result = (int) combclass;
+    combclass = (cups_combclass_t)uni2comb->combclass;
+
+  result = (int)combclass;
+
   return (result);
 }
 
+
 /*
  * 'get_break_class()' - Get UTF-32 Character Line Break Class.
  */
-static int                              /* O - Class or -1 on error */
-get_break_class(const cups_utf32_t ch)  /* I - Source char */
+
+static int                             /* O - Class or -1 on error */
+get_break_class(const cups_utf32_t ch) /* I - Source char */
 {
-  int               result;     /* Result Value */
-  cups_breakmap_t   *bmap;      /* Unicode Line Break Class Map */
-  cups_breakclass_t breakclass; /* Unicode Line Break Class */
-  cups_ucs2_t       *uni2break; /* Unicode -> Line Break Class */
+  int                  result;         /* Result Value */
+  cups_breakmap_t      *bmap;          /* Unicode Line Break Class Map */
+  cups_breakclass_t    breakclass;     /* Unicode Line Break Class */
+  cups_ucs2_t          *uni2break;     /* Unicode -> Line Break Class */
+  cups_globals_t       *cg = _cupsGlobals();
+                                       /* Pointer to library globals */
+
 
  /*
   * Check for valid argument...
   */
+
   if (ch == 0)
     return (-1);
 
  /*
   * Find line break class map...
   */
+
   result = cupsNormalizeMapsGet();
+
   if (result < 0)
     return (-1);
-  bmap = breakmap_cache;
+
+  bmap = cg->breakmap_cache;
+
   if (bmap == NULL)
     return (-1);
 
  /*
   * Find line break character in map...
   */
-  uni2break = (cups_ucs2_t *) bsearch(&ch,
-                                      bmap->uni2break,
-                                      bmap->breakcount,
-                                      (sizeof(cups_ucs2_t) * 3),
-                                      compare_breakchar);
+
+  uni2break = (cups_ucs2_t *)bsearch(&ch, bmap->uni2break, bmap->breakcount,
+                                     (sizeof(cups_ucs2_t) * 3),
+                                    compare_breakchar);
+
   cupsNormalizeMapsFree();
+
   if (uni2break == NULL)
     breakclass = CUPS_BREAK_AI;
   else
-    breakclass = (cups_breakclass_t) *(uni2break + 2);
-  result = (int) breakclass;
+    breakclass = (cups_breakclass_t)*(uni2break + 2);
+
+  result = (int)breakclass;
+
   return (result);
 }
 
+
 /*
  * 'get_map_count()' - Count lines in a map file.
  */
-static int                              /* O - Count or -1 on error */
-get_map_count(const char *filename)     /* I - Map Filename */
+
+static int                             /* O - Count or -1 on error */
+get_map_count(const char *filename)    /* I - Map Filename */
 {
-  int           i;              /* Looping variable */
-  FILE          *fp;            /* Map input file pointer */
-  char          *s;             /* Line parsing pointer */
-  char          line[256];      /* Line from input map file */
-  cups_utf32_t  unichar;        /* Unicode character value */
+  int          i;                      /* Looping variable */
+  cups_file_t  *fp;                    /* Map input file pointer */
+  char         *s;                     /* Line parsing pointer */
+  char         line[256];              /* Line from input map file */
+  cups_utf32_t unichar;                /* Unicode character value */
+
 
  /*
   * Open map input file...
   */
-  if ((filename == NULL) || (*filename == '\0'))
+
+  if (!filename || !*filename)
     return (-1);
-  fp = fopen(filename, "r");
+
+  fp = cupsFileOpen(filename, "r");
   if (fp == NULL)
     return (-1);
 
  /*
   * Count lines in map input file...
   */
+
   for (i = 0; i < 50000;)
   {
-    s = fgets(&line[0], sizeof(line), fp);
+    s = cupsFileGets(fp, line, sizeof(line));
     if (s == NULL)
       break;
     if ((*s == '#') || (*s == '\n') || (*s == '\0'))
@@ -1215,89 +1417,105 @@ get_map_count(const char *filename)     /* I - Map Filename */
  /*
   * Close file and return map count (non-comment line count)...
   */
-  fclose(fp);
+
+  cupsFileClose(fp);
+
   return (i);
 }
 
+
 /*
  * 'get_normmap()' - Get Unicode normalization map to cache.
  */
-static int                              /* O - Zero or -1 on error */
-get_normmap(const cups_normalize_t normalize)
-                                        /* I - Normalization Form */
+
+static int                             /* O - Zero or -1 on error */
+get_normmap(
+    const cups_normalize_t normalize)  /* I - Normalization Form */
 {
-  int           i;              /* Looping variable */
-  cups_utf32_t  unichar1;       /* Unicode character value */
-  cups_utf32_t  unichar2;       /* Unicode character value */
-  cups_utf32_t  unichar3;       /* Unicode character value */
-  cups_normmap_t    *nmap;      /* Unicode Normalization Map */
-  int           normcount;      /* Count of Unicode Source Chars */
-  cups_ucs2_t   *uni2norm;      /* Unicode Char -> Normalization */
-  char          *datadir;       /* CUPS_DATADIR environment variable */
-  char          *mapname;       /* Normalization map name */
-  char          filename[256];  /* Filename for charset map file */
-  FILE          *fp;            /* Normalization map file pointer */
-  char          *s;             /* Line parsing pointer */
-  char          line[256];      /* Line from input map file */
+  int                  i;              /* Looping variable */
+  cups_utf32_t         unichar1;       /* Unicode character value */
+  cups_utf32_t         unichar2;       /* Unicode character value */
+  cups_utf32_t         unichar3;       /* Unicode character value */
+  cups_normmap_t       *nmap;          /* Unicode Normalization Map */
+  int                  normcount;      /* Count of Unicode Source Chars */
+  cups_ucs2_t          *uni2norm;      /* Unicode Char -> Normalization */
+  char                 *datadir;       /* CUPS_DATADIR environment variable */
+  char                 *mapname;       /* Normalization map name */
+  char                 filename[1024]; /* Filename for charset map file */
+  cups_file_t          *fp;            /* Normalization map file pointer */
+  char                 *s;             /* Line parsing pointer */
+  char                 line[256];      /* Line from input map file */
+  cups_globals_t       *cg = _cupsGlobals();
+                                       /* Pointer to library globals */
+
 
  /*
   * See if we already have this normalization map loaded...
   */
-  for (nmap = normmap_cache; nmap != NULL; nmap = nmap->next)
+
+  for (nmap = cg->normmap_cache; nmap != NULL; nmap = nmap->next)
     if (nmap->normalize == normalize)
       return (0);
 
  /*
   * Get the data directory and mapping name...
   */
+
   if ((datadir = getenv("CUPS_DATADIR")) == NULL)
     datadir = CUPS_DATADIR;
+
   switch (normalize)
   {
     case CUPS_NORM_NFD:         /* Canonical Decomposition */
-      mapname = "uni-nfd.txt";
-      break;
+       mapname = "uni-nfd.txt";
+       break;
+
     case CUPS_NORM_NFKD:        /* Compatibility Decomposition */
-      mapname = "uni-nfkd.txt";
-      break;
+       mapname = "uni-nfkd.txt";
+       break;
+
     case CUPS_NORM_NFC:         /* Canonical Composition */
-      mapname = "uni-nfc.txt";
-      break;
+       mapname = "uni-nfc.txt";
+       break;
+
     case CUPS_NORM_NFKC:        /* no such map file... */
     default:
-      return (-1);
+        return (-1);
   }
 
  /*
   * Open normalization map input file...
   */
+
   snprintf(filename, sizeof(filename), "%s/charmaps/%s",
            datadir, mapname);
   if ((normcount = get_map_count(filename)) <= 0)
     return (-1);
-  fp = fopen(filename, "r");
+
+  fp = cupsFileOpen(filename, "r");
   if (fp == NULL)
     return (-1);
 
  /*
   * Allocate memory for normalization map and add to cache...
   */
-  nmap = (cups_normmap_t *)
-    calloc(1, sizeof(cups_normmap_t));
+
+  nmap = (cups_normmap_t *)calloc(1, sizeof(cups_normmap_t));
   if (nmap == NULL)
   {
-    fclose(fp);
+    cupsFileClose(fp);
     return (-1);
   }
-  uni2norm = (cups_ucs2_t *)
-    calloc(1, sizeof(cups_ucs2_t) * 3 * normcount);
+
+  uni2norm = (cups_ucs2_t *)calloc(1, sizeof(cups_ucs2_t) * 3 * normcount);
   if (uni2norm == NULL)
   {
-    fclose(fp);
+    free(nmap);
+    cupsFileClose(fp);
     return (-1);
   }
-  nmap->next = normmap_cache;
-  normmap_cache = nmap;
+  nmap->next = cg->normmap_cache;
+  cg->normmap_cache = nmap;
   nmap->used ++;
   nmap->normalize = normalize;
   nmap->normcount = normcount;
@@ -1308,7 +1526,7 @@ get_normmap(const cups_normalize_t normalize)
   */
   for (i = 0; i < normcount; )
   {
-    s = fgets(&line[0], sizeof(line), fp);
+    s = cupsFileGets(fp, line, sizeof(line));
     if (s == NULL)
       break;
     if ((*s == '#') || (*s == '\n') || (*s == '\0'))
@@ -1326,85 +1544,93 @@ get_normmap(const cups_normalize_t normalize)
   }
   if (i < normcount)
     nmap->normcount = i;
-  fclose(fp);
+  cupsFileClose(fp);
   return (0);
 }
 
+
 /*
  * 'get_foldmap()' - Get Unicode case folding map to cache.
  */
-static int                              /* O - Zero or -1 on error */
-get_foldmap(const cups_folding_t fold)  /* I - Case folding type */
+
+static int                             /* O - Zero or -1 on error */
+get_foldmap(const cups_folding_t fold) /* I - Case folding type */
 {
-  int           i;              /* Looping variable */
-  cups_utf32_t  unichar1;       /* Unicode character value */
-  cups_utf32_t  unichar2;       /* Unicode character value */
-  cups_utf32_t  unichar3;       /* Unicode character value */
-  cups_utf32_t  unichar4;       /* Unicode character value */
-  cups_foldmap_t    *fmap;      /* Unicode Case Folding Map */
-  int           foldcount;      /* Count of Unicode Source Chars */
-  cups_ucs2_t   *uni2fold;      /* Unicode -> Folded Char(s) */
-  char          *datadir;       /* CUPS_DATADIR env variable */
-  char          *mapname;       /* Case Folding map name */
-  char          filename[256];  /* Filename for charset map file */
-  FILE          *fp;            /* Case Folding map file pointer */
-  char          *s;             /* Line parsing pointer */
-  char          line[256];      /* Line from input map file */
+  int                  i;              /* Looping variable */
+  cups_utf32_t         unichar1;       /* Unicode character value */
+  cups_utf32_t         unichar2;       /* Unicode character value */
+  cups_utf32_t         unichar3;       /* Unicode character value */
+  cups_utf32_t         unichar4;       /* Unicode character value */
+  cups_foldmap_t       *fmap;          /* Unicode Case Folding Map */
+  int                  foldcount;      /* Count of Unicode Source Chars */
+  cups_ucs2_t          *uni2fold;      /* Unicode -> Folded Char(s) */
+  char                 *datadir;       /* CUPS_DATADIR env variable */
+  char                 *mapname;       /* Case Folding map name */
+  char                 filename[1024]; /* Filename for charset map file */
+  cups_file_t          *fp;            /* Case Folding map file pointer */
+  char                 *s;             /* Line parsing pointer */
+  char                 line[256];      /* Line from input map file */
+  cups_globals_t       *cg = _cupsGlobals();
+                                       /* Pointer to library globals */
+
 
  /*
   * See if we already have this case folding map loaded...
   */
-  for (fmap = foldmap_cache; fmap != NULL; fmap = fmap->next)
+
+  for (fmap = cg->foldmap_cache; fmap != NULL; fmap = fmap->next)
     if (fmap->fold == fold)
       return (0);
 
  /*
   * Get the data directory and mapping name...
   */
+
   if ((datadir = getenv("CUPS_DATADIR")) == NULL)
     datadir = CUPS_DATADIR;
+
   switch (fold)
   {
     case CUPS_FOLD_SIMPLE:      /* Simple case folding */
-      mapname = "uni-fold.txt";
-      break;
+       mapname = "uni-fold.txt";
+       break;
     case CUPS_FOLD_FULL:        /* Full case folding */
-      mapname = "uni-full.txt";
-      break;
+       mapname = "uni-full.txt";
+       break;
     default:
-      return (-1);
+       return (-1);
   }
 
  /*
   * Open case folding map input file...
   */
+
   snprintf(filename, sizeof(filename), "%s/charmaps/%s",
            datadir, mapname);
   if ((foldcount = get_map_count(filename)) <= 0)
     return (-1);
-  fp = fopen(filename, "r");
+  fp = cupsFileOpen(filename, "r");
   if (fp == NULL)
     return (-1);
 
  /*
   * Allocate memory for case folding map and add to cache...
   */
-  fmap = (cups_foldmap_t *)
-    calloc(1, sizeof(cups_foldmap_t));
+  fmap = (cups_foldmap_t *)calloc(1, sizeof(cups_foldmap_t));
   if (fmap == NULL)
   {
-    fclose(fp);
+    cupsFileClose(fp);
     return (-1);
   }
-  uni2fold = (cups_ucs2_t *)
-    calloc(1, sizeof(cups_ucs2_t) * 4 * foldcount);
+  uni2fold = (cups_ucs2_t *)calloc(1, sizeof(cups_ucs2_t) * 4 * foldcount);
   if (uni2fold == NULL)
   {
-    fclose(fp);
+    free(fmap);
+    cupsFileClose(fp);
     return (-1);
   }
-  fmap->next = foldmap_cache;
-  foldmap_cache = fmap;
+  fmap->next = cg->foldmap_cache;
+  cg->foldmap_cache = fmap;
   fmap->used ++;
   fmap->fold = fold;
   fmap->foldcount = foldcount;
@@ -1413,9 +1639,10 @@ get_foldmap(const cups_folding_t fold)  /* I - Case folding type */
  /*
   * Save case folding map into memory for later use...
   */
+
   for (i = 0; i < foldcount; )
   {
-    s = fgets(&line[0], sizeof(line), fp);
+    s = cupsFileGets(fp, line, sizeof(line));
     if (s == NULL)
       break;
     if ((*s == '#') || (*s == '\n') || (*s == '\0'))
@@ -1441,42 +1668,49 @@ get_foldmap(const cups_folding_t fold)  /* I - Case folding type */
   }
   if (i < foldcount)
     fmap->foldcount = i;
-  fclose(fp);
+  cupsFileClose(fp);
   return (0);
 }
 
 /*
  * 'get_propmap()' - Get Unicode character property map to cache.
  */
-static int                              /* O - Zero or -1 on error */
+
+static int                             /* O - Zero or -1 on error */
 get_propmap(void)
 {
-  int           i, j;           /* Looping variables */
-  int           len;            /* String length */
-  cups_utf32_t  unichar;        /* Unicode character value */
-  cups_gencat_t     gencat;     /* General Category Value */
-  cups_bidicat_t    bidicat;    /* Bidi Category Value */
-  cups_propmap_t    *pmap;      /* Unicode Char Property Map */
-  int           propcount;      /* Count of Unicode Source Chars */
-  cups_prop_t   *uni2prop;      /* Unicode Char -> Properties */
-  char          *datadir;       /* CUPS_DATADIR environment variable */
-  char          *mapname;       /* Char Property map name */
-  char          filename[256];  /* Filename for charset map file */
-  FILE          *fp;            /* Char Property map file pointer */
-  char          *s;             /* Line parsing pointer */
-  char          line[256];      /* Line from input map file */
+  int                  i, j;           /* Looping variables */
+  int                  len;            /* String length */
+  cups_utf32_t         unichar;        /* Unicode character value */
+  cups_gencat_t                gencat;         /* General Category Value */
+  cups_bidicat_t       bidicat;        /* Bidi Category Value */
+  cups_propmap_t       *pmap;          /* Unicode Char Property Map */
+  int                  propcount;      /* Count of Unicode Source Chars */
+  cups_prop_t          *uni2prop;      /* Unicode Char -> Properties */
+  char                 *datadir;       /* CUPS_DATADIR environment variable */
+  char                 *mapname;       /* Char Property map name */
+  char                 filename[1024]; /* Filename for charset map file */
+  cups_file_t          *fp;            /* Char Property map file pointer */
+  char                 *s;             /* Line parsing pointer */
+  char                 line[256];      /* Line from input map file */
+  cups_globals_t       *cg = _cupsGlobals();
+                                       /* Pointer to library globals */
+
 
  /*
   * See if we already have this char properties map loaded...
   */
-  if ((pmap = propmap_cache) != NULL)
+
+  if ((pmap = cg->propmap_cache) != NULL)
     return (0);
 
  /*
   * Get the data directory and mapping name...
   */
+
   if ((datadir = getenv("CUPS_DATADIR")) == NULL)
     datadir = CUPS_DATADIR;
+
   mapname = "uni-prop.txt";
 
  /*
@@ -1486,28 +1720,27 @@ get_propmap(void)
            datadir, mapname);
   if ((propcount = get_map_count(filename)) <= 0)
     return (-1);
-  fp = fopen(filename, "r");
+  fp = cupsFileOpen(filename, "r");
   if (fp == NULL)
     return (-1);
 
  /*
   * Allocate memory for char properties map and add to cache...
   */
-  pmap = (cups_propmap_t *)
-    calloc(1, sizeof(cups_propmap_t));
+  pmap = (cups_propmap_t *)calloc(1, sizeof(cups_propmap_t));
   if (pmap == NULL)
   {
-    fclose(fp);
+    cupsFileClose(fp);
     return (-1);
   }
-  uni2prop = (cups_prop_t *)
-    calloc(1, sizeof(cups_prop_t) * propcount);
+  uni2prop = (cups_prop_t *)calloc(1, sizeof(cups_prop_t) * propcount);
   if (uni2prop == NULL)
   {
-    fclose(fp);
+    free(pmap);
+    cupsFileClose(fp);
     return (-1);
   }
-  propmap_cache = pmap;
+  cg->propmap_cache = pmap;
   pmap->used ++;
   pmap->propcount = propcount;
   pmap->uni2prop = uni2prop;
@@ -1517,7 +1750,7 @@ get_propmap(void)
   */
   for (i = 0; i < propcount; )
   {
-    s = fgets(&line[0], sizeof(line), fp);
+    s = cupsFileGets(fp, line, sizeof(line));
     if (s == NULL)
       break;
     if (strlen(s) > 0)
@@ -1564,71 +1797,81 @@ get_propmap(void)
   }
   if (i < propcount)
     pmap->propcount = i;
-  fclose(fp);
+  cupsFileClose(fp);
   return (0);
 }
 
+
 /*
  * 'get_combmap()' - Get Unicode combining class map to cache.
  */
-static int                              /* O - Zero or -1 on error */
+
+static int                             /* O - Zero or -1 on error */
 get_combmap(void)
 {
-  int           i;              /* Looping variable */
-  cups_utf32_t  unichar;        /* Unicode character value */
-  int           combclass;      /* Unicode char combining class */
-  cups_combmap_t    *cmap;      /* Unicode Comb Class Map */
-  int           combcount;      /* Count of Unicode Source Chars */
-  cups_comb_t   *uni2comb;      /* Unicode Char -> Combining Class */
-  char          *datadir;       /* CUPS_DATADIR environment variable */
-  char          *mapname;       /* Comb Class map name */
-  char          filename[256];  /* Filename for charset map file */
-  FILE          *fp;            /* Comb Class map file pointer */
-  char          *s;             /* Line parsing pointer */
-  char          line[256];      /* Line from input map file */
+  int                  i;              /* Looping variable */
+  cups_utf32_t         unichar;        /* Unicode character value */
+  int                  combclass;      /* Unicode char combining class */
+  cups_combmap_t       *cmap;          /* Unicode Comb Class Map */
+  int                  combcount;      /* Count of Unicode Source Chars */
+  cups_comb_t          *uni2comb;      /* Unicode Char -> Combining Class */
+  char                 *datadir;       /* CUPS_DATADIR environment variable */
+  char                 *mapname;       /* Comb Class map name */
+  char                 filename[1024]; /* Filename for charset map file */
+  cups_file_t          *fp;            /* Comb Class map file pointer */
+  char                 *s;             /* Line parsing pointer */
+  char                 line[256];      /* Line from input map file */
+  cups_globals_t       *cg = _cupsGlobals();
+                                       /* Pointer to library globals */
+
 
  /*
   * See if we already have this combining class map loaded...
   */
-  if ((cmap = combmap_cache) != NULL)
+
+  if ((cmap = cg->combmap_cache) != NULL)
     return (0);
 
  /*
   * Get the data directory and mapping name...
   */
+
   if ((datadir = getenv("CUPS_DATADIR")) == NULL)
     datadir = CUPS_DATADIR;
+
   mapname = "uni-comb.txt";
 
  /*
   * Open combining class map input file...
   */
+
   snprintf(filename, sizeof(filename), "%s/charmaps/%s",
            datadir, mapname);
   if ((combcount = get_map_count(filename)) <= 0)
     return (-1);
-  fp = fopen(filename, "r");
+  fp = cupsFileOpen(filename, "r");
   if (fp == NULL)
     return (-1);
 
  /*
   * Allocate memory for combining class map and add to cache...
   */
-  cmap = (cups_combmap_t *)
-    calloc(1, sizeof(cups_combmap_t));
+
+  cmap = (cups_combmap_t *)calloc(1, sizeof(cups_combmap_t));
   if (cmap == NULL)
   {
-    fclose(fp);
+    cupsFileClose(fp);
     return (-1);
   }
-  uni2comb = (cups_comb_t *)
-    calloc(1, sizeof(cups_comb_t) * combcount);
+
+  uni2comb = (cups_comb_t *)calloc(1, sizeof(cups_comb_t) * combcount);
   if (uni2comb == NULL)
   {
-    fclose(fp);
+    free(cmap);
+    cupsFileClose(fp);
     return (-1);
   }
-  combmap_cache = cmap;
+  cg->combmap_cache = cmap;
   cmap->used ++;
   cmap->combcount = combcount;
   cmap->uni2comb = uni2comb;
@@ -1638,7 +1881,7 @@ get_combmap(void)
   */
   for (i = 0; i < combcount; )
   {
-    s = fgets(&line[0], sizeof(line), fp);
+    s = cupsFileGets(fp, line, sizeof(line));
     if (s == NULL)
       break;
     if ((*s == '#') || (*s == '\n') || (*s == '\0'))
@@ -1661,73 +1904,83 @@ get_combmap(void)
   }
   if (i < combcount)
     cmap->combcount = i;
-  fclose(fp);
+  cupsFileClose(fp);
   return (0);
 }
 
+
 /*
  * 'get_breakmap()' - Get Unicode line break class map to cache.
  */
-static int                              /* O - Zero or -1 on error */
+
+static int                             /* O - Zero or -1 on error */
 get_breakmap(void)
 {
-  int           i, j;           /* Looping variables */
-  int           len;            /* String length */
-  cups_utf32_t  unichar1;       /* Unicode character value */
-  cups_utf32_t  unichar2;       /* Unicode character value */
-  cups_breakclass_t breakclass; /* Unicode char line break class */
-  cups_breakmap_t   *bmap;      /* Unicode Line Break Class Map */
-  int           breakcount;     /* Count of Unicode Source Chars */
-  cups_ucs2_t   *uni2break;     /* Unicode -> Line Break Class */
-  char          *datadir;       /* CUPS_DATADIR environment variable */
-  char          *mapname;       /* Comb Class map name */
-  char          filename[256];  /* Filename for charset map file */
-  FILE          *fp;            /* Comb Class map file pointer */
-  char          *s;             /* Line parsing pointer */
-  char          line[256];      /* Line from input map file */
+  int                  i, j;           /* Looping variables */
+  int                  len;            /* String length */
+  cups_utf32_t         unichar1;       /* Unicode character value */
+  cups_utf32_t         unichar2;       /* Unicode character value */
+  cups_breakclass_t    breakclass;     /* Unicode char line break class */
+  cups_breakmap_t      *bmap;          /* Unicode Line Break Class Map */
+  int                  breakcount;     /* Count of Unicode Source Chars */
+  cups_ucs2_t          *uni2break;     /* Unicode -> Line Break Class */
+  char                 *datadir;       /* CUPS_DATADIR environment variable */
+  char                 *mapname;       /* Comb Class map name */
+  char                 filename[1024]; /* Filename for charset map file */
+  cups_file_t          *fp;            /* Comb Class map file pointer */
+  char                 *s;             /* Line parsing pointer */
+  char                 line[256];      /* Line from input map file */
+  cups_globals_t       *cg = _cupsGlobals();
+                                       /* Pointer to library globals */
+
 
  /*
   * See if we already have this line break class map loaded...
   */
-  if ((bmap = breakmap_cache) != NULL)
+
+  if ((bmap = cg->breakmap_cache) != NULL)
     return (0);
 
  /*
   * Get the data directory and mapping name...
   */
+
   if ((datadir = getenv("CUPS_DATADIR")) == NULL)
     datadir = CUPS_DATADIR;
+
   mapname = "uni-line.txt";
 
  /*
   * Open line break class map input file...
   */
+
   snprintf(filename, sizeof(filename), "%s/charmaps/%s",
            datadir, mapname);
   if ((breakcount = get_map_count(filename)) <= 0)
     return (-1);
-  fp = fopen(filename, "r");
+  fp = cupsFileOpen(filename, "r");
   if (fp == NULL)
     return (-1);
 
  /*
   * Allocate memory for line break class map and add to cache...
   */
-  bmap = (cups_breakmap_t *)
-    calloc(1, sizeof(cups_breakmap_t));
+
+  bmap = (cups_breakmap_t *)calloc(1, sizeof(cups_breakmap_t));
   if (bmap == NULL)
   {
-    fclose(fp);
+    cupsFileClose(fp);
     return (-1);
   }
-  uni2break = (cups_ucs2_t *)
-    calloc(1, sizeof(cups_ucs2_t) * 3 * breakcount);
+
+  uni2break = (cups_ucs2_t *)calloc(1, sizeof(cups_ucs2_t) * 3 * breakcount);
   if (uni2break == NULL)
   {
-    fclose(fp);
+    free(bmap);
+    cupsFileClose(fp);
     return (-1);
   }
-  breakmap_cache = bmap;
+  cg->breakmap_cache = bmap;
   bmap->used ++;
   bmap->breakcount = breakcount;
   bmap->uni2break = uni2break;
@@ -1737,7 +1990,7 @@ get_breakmap(void)
   */
   for (i = 0; i < breakcount; )
   {
-    s = fgets(&line[0], sizeof(line), fp);
+    s = cupsFileGets(fp, line, sizeof(line));
     if (s == NULL)
       break;
     if (strlen(s) > 0)
@@ -1770,150 +2023,175 @@ get_breakmap(void)
   }
   if (i < breakcount)
     bmap->breakcount = i;
-  fclose(fp);
+  cupsFileClose(fp);
   return (0);
 }
 
+
 /*
  * 'compare_compose()' - Compare key for compose match.
  *
  * Note - This function cannot be easily modified for 32-bit Unicode.
  */
-static int
-compare_compose(const void *k1,         /* I - Key char */
-    const void *k2)                     /* I - Map char */
+
+static int                             /* O - Result of comparison */
+compare_compose(const void *k1,                /* I - Key char */
+               const void *k2)         /* I - Map char */
 {
-  cups_utf32_t  *kp = (cups_utf32_t *) k1;
-                                /* Key char pointer */
-  cups_ucs2_t   *mp = (cups_ucs2_t *) k2;
-                                /* Map char pointer */
-  unsigned long key;            /* Pair of key characters */
-  unsigned long map;            /* Pair of map characters */
-  int           result;         /* Result Value */
+  cups_utf32_t *kp = (cups_utf32_t *)k1;
+                                       /* Key char pointer */
+  cups_ucs2_t  *mp = (cups_ucs2_t *)k2;/* Map char pointer */
+  unsigned long        key;                    /* Pair of key characters */
+  unsigned long        map;                    /* Pair of map characters */
+  int          result;                 /* Result Value */
+
 
   key = (*kp << 16);
   key |= *(kp + 1);
   map = (unsigned long) (*mp << 16);
   map |= (unsigned long) *(mp + 1);
+
   if (key >= map)
     result = (int) (key - map);
   else
     result = -1 * ((int) (map - key));
+
   return (result);
 }
 
+
 /*
  * 'compare_decompose()' - Compare key for decompose match.
  */
-static int
-compare_decompose(const void *k1,       /* I - Key char */
-    const void *k2)                     /* I - Map char */
+
+static int                             /* O - Result of comparison */
+compare_decompose(const void *k1,      /* I - Key char */
+                 const void *k2)       /* I - Map char */
 {
-  cups_utf32_t  *kp = (cups_utf32_t *) k1;
-                                /* Key char pointer */
-  cups_ucs2_t   *mp = (cups_ucs2_t *) k2;
-                                /* Map char pointer */
-  cups_ucs2_t   ch;             /* Key char as UCS-2 */
-  int           result;         /* Result Value */
+  cups_utf32_t *kp = (cups_utf32_t *)k1;
+                                       /* Key char pointer */
+  cups_ucs2_t  *mp = (cups_ucs2_t *)k2;/* Map char pointer */
+  cups_ucs2_t  ch;                     /* Key char as UCS-2 */
+  int          result;                 /* Result Value */
+
 
   ch = (cups_ucs2_t) *kp;
+
   if (ch >= *mp)
     result = (int) (ch - *mp);
   else
     result = -1 * ((int) (*mp - ch));
+
   return (result);
 }
 
+
 /*
  * 'compare_foldchar()' - Compare key for case fold match.
  */
-static int
-compare_foldchar(const void *k1,        /* I - Key char */
-    const void *k2)                     /* I - Map char */
+
+static int                             /* O - Result of comparison */
+compare_foldchar(const void *k1,       /* I - Key char */
+                const void *k2)        /* I - Map char */
 {
-  cups_utf32_t  *kp = (cups_utf32_t *) k1;
-                                /* Key char pointer */
-  cups_ucs2_t   *mp = (cups_ucs2_t *) k2;
-                                /* Map char pointer */
-  cups_ucs2_t   ch;             /* Key char as UCS-2 */
-  int           result;         /* Result Value */
+  cups_utf32_t *kp = (cups_utf32_t *)k1;
+                                       /* Key char pointer */
+  cups_ucs2_t  *mp = (cups_ucs2_t *)k2;/* Map char pointer */
+  cups_ucs2_t  ch;                     /* Key char as UCS-2 */
+  int          result;                 /* Result Value */
+
 
   ch = (cups_ucs2_t) *kp;
+
   if (ch >= *mp)
     result = (int) (ch - *mp);
   else
     result = -1 * ((int) (*mp - ch));
+
   return (result);
 }
 
+
 /*
  * 'compare_combchar()' - Compare key for combining char match.
  */
-static int
-compare_combchar(const void *k1,        /* I - Key char */
-    const void *k2)                     /* I - Map char */
+
+static int                             /* O - Result of comparison */
+compare_combchar(const void *k1,       /* I - Key char */
+                 const void *k2)       /* I - Map char */
 {
-  cups_utf32_t  *kp = (cups_utf32_t *) k1;
-                                /* Key char pointer */
-  cups_comb_t   *cp = (cups_comb_t *) k2;
-                                /* Combining map row pointer */
-  cups_ucs2_t   ch;             /* Key char as UCS-2 */
-  int           result;         /* Result Value */
+  cups_utf32_t *kp = (cups_utf32_t *)k1;
+                                       /* Key char pointer */
+  cups_comb_t  *cp = (cups_comb_t *)k2;/* Combining map row pointer */
+  cups_ucs2_t  ch;                     /* Key char as UCS-2 */
+  int          result;                 /* Result Value */
+
 
   ch = (cups_ucs2_t) *kp;
+
   if (ch >= cp->ch)
     result = (int) (ch - cp->ch);
   else
     result = -1 * ((int) (cp->ch - ch));
+
   return (result);
 }
 
+
 /*
  * 'compare_breakchar()' - Compare key for line break char match.
  */
-static int
-compare_breakchar(const void *k1,       /* I - Key char */
-    const void *k2)                     /* I - Map char */
+
+static int                             /* O - Result of comparison */
+compare_breakchar(const void *k1,      /* I - Key char */
+                  const void *k2)      /* I - Map char */
 {
-  cups_utf32_t  *kp = (cups_utf32_t *) k1;
-                                /* Key char pointer */
-  cups_ucs2_t   *mp = (cups_ucs2_t *) k2;
-                                /* Map char pointer */
-  cups_ucs2_t   ch;             /* Key char as UCS-2 */
-  int           result;         /* Result Value */
+  cups_utf32_t *kp = (cups_utf32_t *)k1;
+                                       /* Key char pointer */
+  cups_ucs2_t  *mp = (cups_ucs2_t *)k2;/* Map char pointer */
+  cups_ucs2_t  ch;                     /* Key char as UCS-2 */
+  int          result;                 /* Result Value */
+
 
   ch = (cups_ucs2_t) *kp;
+
   if (ch < *mp)
     result = -1 * (int) (*mp - ch);
   else if (ch > *(mp + 1))
     result = (int) (ch - *(mp + 1));
   else
     result = 0;
+
   return (result);
 }
 
+
 /*
  * 'compare_propchar()' - Compare key for property char match.
  */
-static int
-compare_propchar(const void *k1,        /* I - Key char */
-    const void *k2)                     /* I - Map char */
+
+static int                             /* O - Result of comparison */
+compare_propchar(const void *k1,       /* I - Key char */
+                const void *k2)        /* I - Map char */
 {
-  cups_utf32_t  *kp = (cups_utf32_t *) k1;
-                                /* Key char pointer */
-  cups_prop_t   *pp = (cups_prop_t *) k2;
-                                /* Property map row pointer */
-  cups_ucs2_t   ch;             /* Key char as UCS-2 */
-  int           result;         /* Result Value */
+  cups_utf32_t *kp = (cups_utf32_t *)k1;
+                                       /* Key char pointer */
+  cups_prop_t  *pp = (cups_prop_t *)k2;/* Property map row pointer */
+  cups_ucs2_t  ch;                     /* Key char as UCS-2 */
+  int          result;                 /* Result Value */
+
 
   ch = (cups_ucs2_t) *kp;
+
   if (ch >= pp->ch)
     result = (int) (ch - pp->ch);
   else
     result = -1 * ((int) (pp->ch - ch));
+
   return (result);
 }
 
+
 /*
  * End of "$Id$"
  */
index 6746465255d15eab80a2e93c1caa4c5fc64868ff..4f2c0fd4d1461f1328a298d476cdbd3259dbdd3e 100644 (file)
  * Include necessary headers.
  */
 
-#include "ppd.h"
-#include <stdlib.h>
-#include <ctype.h>
-#include "string.h"
-#include "language.h"
+#include "globals.h"
 #include "debug.h"
+#include <stdlib.h>
 
 
 /*
 #define PPD_STRING     8               /* Line contained a string or code */
 
 
-/*
- * Local globals...
- */
-
-static ppd_status_t    ppd_status = PPD_OK;
-                                       /* Status of last ppdOpen*() */
-static int             ppd_line = 0;   /* Current line number */
-static ppd_conform_t   ppd_conform = PPD_CONFORM_RELAXED;
-                                       /* Level of conformance required */
-
-
 /*
  * Local functions...
  */
@@ -131,10 +117,11 @@ static ppd_ext_param_t    *ppd_get_extparam(ppd_ext_option_t *opt,
                                          const char *text);
 #endif /* 0 */
 static ppd_group_t     *ppd_get_group(ppd_file_t *ppd, const char *name,
-                                      const char *text);
+                                      const char *text, cups_globals_t *cg);
 static ppd_option_t    *ppd_get_option(ppd_group_t *group, const char *name);
 static int             ppd_read(cups_file_t *fp, char *keyword, char *option,
-                                char *text, char **string, int ignoreblank);
+                                char *text, char **string, int ignoreblank,
+                                cups_globals_t *cg);
 
 
 /*
@@ -361,10 +348,14 @@ ppdErrorString(ppd_status_t status)       /* I - PPD status */
 ppd_status_t                           /* O - Status code */
 ppdLastError(int *line)                        /* O - Line number */
 {
+  cups_globals_t       *cg = _cupsGlobals();
+                                       /* Global data */
+
+
   if (line)
-    *line = ppd_line;
+    *line = cg->ppd_line;
 
-  return (ppd_status);
+  return (cg->ppd_status);
 }
 
 
@@ -437,6 +428,8 @@ ppdOpen2(cups_file_t *fp)           /* I - File to read from */
   char                 **filter;       /* Pointer to filter */
   cups_lang_t          *language;      /* Default language */
   int                  ui_keyword;     /* Is this line a UI keyword? */
+  cups_globals_t       *cg = _cupsGlobals();
+                                       /* Global data */
   static const char * const ui_keywords[] =
                        {
                          /* Boolean keywords */
@@ -490,8 +483,8 @@ ppdOpen2(cups_file_t *fp)           /* I - File to read from */
   * Default to "OK" status...
   */
 
-  ppd_status = PPD_OK;
-  ppd_line   = 0;
+  cg->ppd_status = PPD_OK;
+  cg->ppd_line   = 0;
 
  /*
   * Range check input...
@@ -499,7 +492,7 @@ ppdOpen2(cups_file_t *fp)           /* I - File to read from */
 
   if (fp == NULL)
   {
-    ppd_status = PPD_NULL_FILE;
+    cg->ppd_status = PPD_NULL_FILE;
     return (NULL);
   }
 
@@ -507,7 +500,7 @@ ppdOpen2(cups_file_t *fp)           /* I - File to read from */
   * Grab the first line and make sure it reads '*PPD-Adobe: "major.minor"'...
   */
 
-  mask = ppd_read(fp, keyword, name, text, &string, 0);
+  mask = ppd_read(fp, keyword, name, text, &string, 0, cg);
 
   DEBUG_printf(("mask=%x, keyword=\"%s\"...\n", mask, keyword));
 
@@ -519,8 +512,8 @@ ppdOpen2(cups_file_t *fp)           /* I - File to read from */
     * Either this is not a PPD file, or it is not a 4.x PPD file.
     */
 
-    if (ppd_status == PPD_OK)
-      ppd_status = PPD_MISSING_PPDADOBE4;
+    if (cg->ppd_status == PPD_OK)
+      cg->ppd_status = PPD_MISSING_PPDADOBE4;
 
     ppd_free(string);
 
@@ -537,7 +530,7 @@ ppdOpen2(cups_file_t *fp)           /* I - File to read from */
 
   if ((ppd = calloc(1, sizeof(ppd_file_t))) == NULL)
   {
-    ppd_status = PPD_ALLOC_ERROR;
+    cg->ppd_status = PPD_ALLOC_ERROR;
 
     return (NULL);
   }
@@ -569,7 +562,7 @@ ppdOpen2(cups_file_t *fp)           /* I - File to read from */
   choice     = NULL;
   ui_keyword = 0;
 
-  while ((mask = ppd_read(fp, keyword, name, text, &string, 1)) != 0)
+  while ((mask = ppd_read(fp, keyword, name, text, &string, 1, cg)) != 0)
   {
 #ifdef DEBUG
     printf("mask = %x, keyword = \"%s\"", mask, keyword);
@@ -601,7 +594,7 @@ ppdOpen2(cups_file_t *fp)           /* I - File to read from */
       * Need a string value!
       */
 
-      ppd_status = PPD_MISSING_VALUE;
+      cg->ppd_status = PPD_MISSING_VALUE;
 
       goto error;
     }
@@ -653,10 +646,10 @@ ppdOpen2(cups_file_t *fp)         /* I - File to read from */
               strcmp(keyword, "OutputMode") && strcmp(keyword, "OutputOrder") &&
              strcmp(keyword, "PageSize") && strcmp(keyword, "PageRegion"))
            group = ppd_get_group(ppd, "Extra",
-                                 cupsLangString(language, CUPS_MSG_EXTRA));
+                                 cupsLangString(language, CUPS_MSG_EXTRA), cg);
          else
            group = ppd_get_group(ppd, "General",
-                                 cupsLangString(language, CUPS_MSG_GENERAL));
+                                 cupsLangString(language, CUPS_MSG_GENERAL), cg);
 
           if (group == NULL)
            goto error;
@@ -670,7 +663,7 @@ ppdOpen2(cups_file_t *fp)           /* I - File to read from */
 
        if (option == NULL)
        {
-          ppd_status = PPD_ALLOC_ERROR;
+          cg->ppd_status = PPD_ALLOC_ERROR;
 
           goto error;
        }
@@ -806,7 +799,7 @@ ppdOpen2(cups_file_t *fp)           /* I - File to read from */
       {
         ppd_free(filter);
 
-        ppd_status = PPD_ALLOC_ERROR;
+        cg->ppd_status = PPD_ALLOC_ERROR;
 
        goto error;
       }
@@ -838,7 +831,7 @@ ppdOpen2(cups_file_t *fp)           /* I - File to read from */
 
       if (tempfonts == NULL)
       {
-        ppd_status = PPD_ALLOC_ERROR;
+        cg->ppd_status = PPD_ALLOC_ERROR;
 
        goto error;
       }
@@ -888,7 +881,7 @@ ppdOpen2(cups_file_t *fp)           /* I - File to read from */
 
          if ((gtemp = ppd_get_group(ppd, "General",
                                      cupsLangString(language,
-                                                    CUPS_MSG_GENERAL))) == NULL)
+                                                    CUPS_MSG_GENERAL), cg)) == NULL)
          {
            DEBUG_puts("Unable to get general group!");
 
@@ -899,7 +892,7 @@ ppdOpen2(cups_file_t *fp)           /* I - File to read from */
          {
            DEBUG_puts("Unable to get PageSize option!");
 
-            ppd_status = PPD_ALLOC_ERROR;
+            cg->ppd_status = PPD_ALLOC_ERROR;
 
            goto error;
          }
@@ -909,7 +902,7 @@ ppdOpen2(cups_file_t *fp)           /* I - File to read from */
        {
          DEBUG_puts("Unable to add Custom choice!");
 
-          ppd_status = PPD_ALLOC_ERROR;
+          cg->ppd_status = PPD_ALLOC_ERROR;
 
          goto error;
        }
@@ -923,7 +916,7 @@ ppdOpen2(cups_file_t *fp)           /* I - File to read from */
       {
        DEBUG_puts("Unable to find PageSize option!");
 
-        ppd_status = PPD_INTERNAL_ERROR;
+        cg->ppd_status = PPD_INTERNAL_ERROR;
 
        goto error;
       }
@@ -932,7 +925,7 @@ ppdOpen2(cups_file_t *fp)           /* I - File to read from */
       {
        DEBUG_puts("Unable to find Custom choice!");
 
-        ppd_status = PPD_INTERNAL_ERROR;
+        cg->ppd_status = PPD_INTERNAL_ERROR;
 
        goto error;
       }
@@ -1007,7 +1000,7 @@ ppdOpen2(cups_file_t *fp)         /* I - File to read from */
                                     strlen(string) + 1);
         if (temp == NULL)
        {
-          ppd_status = PPD_ALLOC_ERROR;
+          cg->ppd_status = PPD_ALLOC_ERROR;
 
          goto error;
        }
@@ -1023,9 +1016,9 @@ ppdOpen2(cups_file_t *fp)         /* I - File to read from */
       * Don't allow nesting of options...
       */
 
-      if (option && ppd_conform == PPD_CONFORM_STRICT)
+      if (option && cg->ppd_conform == PPD_CONFORM_STRICT)
       {
-        ppd_status = PPD_NESTED_OPEN_UI;
+        cg->ppd_status = PPD_NESTED_OPEN_UI;
 
        goto error;
       }
@@ -1054,10 +1047,10 @@ ppdOpen2(cups_file_t *fp)               /* I - File to read from */
             strcmp(name, "OutputMode") && strcmp(name, "OutputOrder") &&
            strcmp(name, "PageSize") && strcmp(name, "PageRegion"))
          group = ppd_get_group(ppd, "Extra",
-                               cupsLangString(language, CUPS_MSG_EXTRA));
+                               cupsLangString(language, CUPS_MSG_EXTRA), cg);
        else
          group = ppd_get_group(ppd, "General",
-                               cupsLangString(language, CUPS_MSG_GENERAL));
+                               cupsLangString(language, CUPS_MSG_GENERAL), cg);
 
         if (group == NULL)
          goto error;
@@ -1071,7 +1064,7 @@ ppdOpen2(cups_file_t *fp)         /* I - File to read from */
 
       if (option == NULL)
       {
-        ppd_status = PPD_ALLOC_ERROR;
+        cg->ppd_status = PPD_ALLOC_ERROR;
 
        goto error;
       }
@@ -1086,9 +1079,9 @@ ppdOpen2(cups_file_t *fp)         /* I - File to read from */
         option->ui = PPD_UI_BOOLEAN;
       else if (string && strcmp(string, "PickOne") == 0)
         option->ui = PPD_UI_PICKONE;
-      else if (ppd_conform == PPD_CONFORM_STRICT)
+      else if (cg->ppd_conform == PPD_CONFORM_STRICT)
       {
-        ppd_status = PPD_BAD_OPEN_UI;
+        cg->ppd_status = PPD_BAD_OPEN_UI;
 
        goto error;
       }
@@ -1144,9 +1137,9 @@ ppdOpen2(cups_file_t *fp)         /* I - File to read from */
       * Don't allow nesting of options...
       */
 
-      if (option && ppd_conform == PPD_CONFORM_STRICT)
+      if (option && cg->ppd_conform == PPD_CONFORM_STRICT)
       {
-        ppd_status = PPD_NESTED_OPEN_UI;
+        cg->ppd_status = PPD_NESTED_OPEN_UI;
 
        goto error;
       }
@@ -1155,7 +1148,7 @@ ppdOpen2(cups_file_t *fp)         /* I - File to read from */
       * Find the JCL group, and add if needed...
       */
 
-      group = ppd_get_group(ppd, "JCL", "JCL");
+      group = ppd_get_group(ppd, "JCL", "JCL", cg);
 
       if (group == NULL)
        goto error;
@@ -1171,7 +1164,7 @@ ppdOpen2(cups_file_t *fp)         /* I - File to read from */
 
       if (option == NULL)
       {
-        ppd_status = PPD_ALLOC_ERROR;
+        cg->ppd_status = PPD_ALLOC_ERROR;
 
        goto error;
       }
@@ -1188,7 +1181,7 @@ ppdOpen2(cups_file_t *fp)         /* I - File to read from */
         option->ui = PPD_UI_PICKONE;
       else
       {
-        ppd_status = PPD_BAD_OPEN_UI;
+        cg->ppd_status = PPD_BAD_OPEN_UI;
 
        goto error;
       }
@@ -1229,14 +1222,14 @@ ppdOpen2(cups_file_t *fp)               /* I - File to read from */
 
       if (group != NULL)
       {
-        ppd_status = PPD_NESTED_OPEN_GROUP;
+        cg->ppd_status = PPD_NESTED_OPEN_GROUP;
 
        goto error;
       }
 
       if (!string)
       {
-        ppd_status = PPD_BAD_OPEN_GROUP;
+        cg->ppd_status = PPD_BAD_OPEN_GROUP;
 
        goto error;
       }
@@ -1261,7 +1254,7 @@ ppdOpen2(cups_file_t *fp)         /* I - File to read from */
       * Find/add the group...
       */
 
-      group = ppd_get_group(ppd, string, sptr);
+      group = ppd_get_group(ppd, string, sptr, cg);
 
       if (group == NULL)
        goto error;
@@ -1281,7 +1274,7 @@ ppdOpen2(cups_file_t *fp)         /* I - File to read from */
     {
       if (sscanf(string, "%f%40s%40s", &order, name, keyword) != 3)
       {
-        ppd_status = PPD_BAD_ORDER_DEPENDENCY;
+        cg->ppd_status = PPD_BAD_ORDER_DEPENDENCY;
 
        goto error;
       }
@@ -1407,7 +1400,7 @@ ppdOpen2(cups_file_t *fp)         /* I - File to read from */
 
       if (constraint == NULL)
       {
-        ppd_status = PPD_ALLOC_ERROR;
+        cg->ppd_status = PPD_ALLOC_ERROR;
 
        goto error;
       }
@@ -1422,7 +1415,7 @@ ppdOpen2(cups_file_t *fp)         /* I - File to read from */
       {
         case 0 : /* Error */
        case 1 : /* Error */
-           ppd_status = PPD_BAD_UI_CONSTRAINTS;
+           cg->ppd_status = PPD_BAD_UI_CONSTRAINTS;
            goto error;
 
        case 2 : /* Two options... */
@@ -1490,7 +1483,7 @@ ppdOpen2(cups_file_t *fp)         /* I - File to read from */
         * Unable to add or find size!
        */
 
-        ppd_status = PPD_ALLOC_ERROR;
+        cg->ppd_status = PPD_ALLOC_ERROR;
 
        goto error;
       }
@@ -1511,7 +1504,7 @@ ppdOpen2(cups_file_t *fp)         /* I - File to read from */
         * Unable to add or find size!
        */
 
-        ppd_status = PPD_ALLOC_ERROR;
+        cg->ppd_status = PPD_ALLOC_ERROR;
 
        goto error;
       }
@@ -1808,7 +1801,7 @@ ppdOpen2(cups_file_t *fp)         /* I - File to read from */
     printf("Premature EOF at %lu...\n", (unsigned long)ftell(fp));
 #endif /* DEBUG */
 
-  if (ppd_status != PPD_OK)
+  if (cg->ppd_status != PPD_OK)
   {
    /*
     * Had an error reading the PPD file, cannot continue!
@@ -1949,15 +1942,17 @@ ppdOpen2(cups_file_t *fp)               /* I - File to read from */
 ppd_file_t *                           /* O - PPD file record */
 ppdOpenFd(int fd)                      /* I - File to read from */
 {
-  FILE         *fp;                    /* File pointer */
-  ppd_file_t   *ppd;                   /* PPD file record */
+  FILE                 *fp;            /* File pointer */
+  ppd_file_t           *ppd;           /* PPD file record */
+  cups_globals_t       *cg = _cupsGlobals();
+                                       /* Global data */
 
 
  /*
   * Set the line number to 0...
   */
 
-  ppd_line = 0;
+  cg->ppd_line = 0;
 
  /*
   * Range check input...
@@ -1965,7 +1960,7 @@ ppdOpenFd(int fd)                 /* I - File to read from */
 
   if (fd < 0)
   {
-    ppd_status = PPD_NULL_FILE;
+    cg->ppd_status = PPD_NULL_FILE;
 
     return (NULL);
   }
@@ -1984,7 +1979,7 @@ ppdOpenFd(int fd)                 /* I - File to read from */
   }
   else
   {
-    ppd_status = PPD_FILE_OPEN_ERROR;
+    cg->ppd_status = PPD_FILE_OPEN_ERROR;
     ppd        = NULL;
   }
 
@@ -1999,15 +1994,17 @@ ppdOpenFd(int fd)                       /* I - File to read from */
 ppd_file_t *                           /* O - PPD file record */
 ppdOpenFile(const char *filename)      /* I - File to read from */
 {
-  FILE         *fp;                    /* File pointer */
-  ppd_file_t   *ppd;                   /* PPD file record */
+  cups_file_t          *fp;            /* File pointer */
+  ppd_file_t           *ppd;           /* PPD file record */
+  cups_globals_t       *cg = _cupsGlobals();
+                                       /* Global data */
 
 
  /*
   * Set the line number to 0...
   */
 
-  ppd_line = 0;
+  cg->ppd_line = 0;
 
  /*
   * Range check input...
@@ -2015,7 +2012,7 @@ ppdOpenFile(const char *filename) /* I - File to read from */
 
   if (filename == NULL)
   {
-    ppd_status = PPD_NULL_FILE;
+    cg->ppd_status = PPD_NULL_FILE;
 
     return (NULL);
   }
@@ -2024,16 +2021,16 @@ ppdOpenFile(const char *filename)       /* I - File to read from */
   * Try to open the file and parse it...
   */
 
-  if ((fp = fopen(filename, "r")) != NULL)
+  if ((fp = cupsFileOpen(filename, "r")) != NULL)
   {
-    ppd = ppdOpen(fp);
+    ppd = ppdOpen2(fp);
 
-    fclose(fp);
+    cupsFileClose(fp);
   }
   else
   {
-    ppd_status = PPD_FILE_OPEN_ERROR;
-    ppd        = NULL;
+    cg->ppd_status = PPD_FILE_OPEN_ERROR;
+    ppd            = NULL;
   }
 
   return (ppd);
@@ -2047,7 +2044,11 @@ ppdOpenFile(const char *filename)        /* I - File to read from */
 void
 ppdSetConformance(ppd_conform_t c)     /* I - Conformance level */
 {
-  ppd_conform = c;
+  cups_globals_t       *cg = _cupsGlobals();
+                                       /* Global data */
+
+
+  cg->ppd_conform = c;
 }
 
 
@@ -2502,15 +2503,17 @@ ppd_get_extparam(ppd_ext_option_t *opt, /* I - PPD file */
  */
 
 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 */
+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 */
 {
   int          i;                      /* Looping var */
   ppd_group_t  *group;                 /* Group */
 
 
-  DEBUG_printf(("ppd_get_group(%p, \"%s\")\n", ppd, name));
+  DEBUG_printf(("ppd_get_group(ppd=%p, name=\"%s\", text=\"%s\", cg=%p)\n",
+                ppd, name, text, cg));
 
   for (i = ppd->num_groups, group = ppd->groups; i > 0; i --, group ++)
     if (strcmp(group->name, name) == 0)
@@ -2520,9 +2523,9 @@ ppd_get_group(ppd_file_t *ppd,            /* I - PPD file */
   {
     DEBUG_printf(("Adding group %s...\n", name));
 
-    if (ppd_conform == PPD_CONFORM_STRICT && strlen(text) >= sizeof(group->text))
+    if (cg->ppd_conform == PPD_CONFORM_STRICT && strlen(text) >= sizeof(group->text))
     {
-      ppd_status = PPD_ILLEGAL_TRANSLATION;
+      cg->ppd_status = PPD_ILLEGAL_TRANSLATION;
 
       return (NULL);
     }
@@ -2535,7 +2538,7 @@ ppd_get_group(ppd_file_t *ppd,            /* I - PPD file */
 
     if (group == NULL)
     {
-      ppd_status = PPD_ALLOC_ERROR;
+      cg->ppd_status = PPD_ALLOC_ERROR;
 
       return (NULL);
     }
@@ -2601,12 +2604,13 @@ ppd_get_option(ppd_group_t *group,      /* I - Group */
  */
 
 static int                             /* O - Bitmask of fields read */
-ppd_read(cups_file_t *fp,              /* I - File to read from */
-         char        *keyword,         /* O - Keyword from line */
-        char        *option,           /* O - Option from line */
-         char        *text,            /* O - Human-readable text from line */
-        char        **string,          /* O - Code/string data */
-         int         ignoreblank)      /* I - Ignore blank lines? */
+ppd_read(cups_file_t    *fp,           /* I - File to read from */
+         char           *keyword,      /* O - Keyword from line */
+        char           *option,        /* O - Option from line */
+         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 */
 {
   int          ch,                     /* Character from file */
                col,                    /* Column in line */
@@ -2636,7 +2640,7 @@ ppd_read(cups_file_t *fp,         /* I - File to read from */
 
   *string   = NULL;
   col       = 0;
-  startline = ppd_line + 1;
+  startline = cg->ppd_line + 1;
   linesize  = 1024;
   line      = malloc(linesize);
 
@@ -2671,8 +2675,8 @@ ppd_read(cups_file_t *fp,         /* I - File to read from */
          * Don't allow lines longer than 256k!
          */
 
-          ppd_line   = startline;
-          ppd_status = PPD_LINE_TOO_LONG;
+          cg->ppd_line   = startline;
+          cg->ppd_status = PPD_LINE_TOO_LONG;
 
          free(line);
 
@@ -2682,8 +2686,8 @@ ppd_read(cups_file_t *fp,         /* I - File to read from */
         temp = realloc(line, linesize);
        if (!temp)
        {
-          ppd_line   = startline;
-          ppd_status = PPD_LINE_TOO_LONG;
+          cg->ppd_line   = startline;
+          cg->ppd_status = PPD_LINE_TOO_LONG;
 
          free(line);
 
@@ -2700,7 +2704,7 @@ ppd_read(cups_file_t *fp,         /* I - File to read from */
        * Line feed or carriage return...
        */
 
-        ppd_line ++;
+        cg->ppd_line ++;
        col = 0;
 
        if (ch == '\r')
@@ -2725,14 +2729,14 @@ ppd_read(cups_file_t *fp,               /* I - File to read from */
 
        *lineptr++ = '\n';
       }
-      else if (ch < ' ' && ch != '\t' && ppd_conform == PPD_CONFORM_STRICT)
+      else if (ch < ' ' && ch != '\t' && cg->ppd_conform == PPD_CONFORM_STRICT)
       {
        /*
         * Other control characters...
        */
 
-        ppd_line   = startline;
-        ppd_status = PPD_ILLEGAL_CHARACTER;
+        cg->ppd_line   = startline;
+        cg->ppd_status = PPD_ILLEGAL_CHARACTER;
 
         free(line);
 
@@ -2753,8 +2757,8 @@ ppd_read(cups_file_t *fp,         /* I - File to read from */
           * Line is too long...
          */
 
-          ppd_line   = startline;
-          ppd_status = PPD_LINE_TOO_LONG;
+          cg->ppd_line   = startline;
+          cg->ppd_status = PPD_LINE_TOO_LONG;
 
           free(line);
 
@@ -2780,7 +2784,7 @@ ppd_read(cups_file_t *fp,         /* I - File to read from */
          break;
        else if (ch == '\r' || ch == '\n')
        {
-         ppd_line ++;
+         cg->ppd_line ++;
          col = 0;
 
          if (ch == '\r')
@@ -2797,14 +2801,14 @@ ppd_read(cups_file_t *fp,               /* I - File to read from */
 
          ch = '\n';
        }
-       else if (ch < ' ' && ch != '\t' && ppd_conform == PPD_CONFORM_STRICT)
+       else if (ch < ' ' && ch != '\t' && cg->ppd_conform == PPD_CONFORM_STRICT)
        {
         /*
           * Other control characters...
          */
 
-          ppd_line   = startline;
-          ppd_status = PPD_ILLEGAL_CHARACTER;
+          cg->ppd_line   = startline;
+          cg->ppd_status = PPD_ILLEGAL_CHARACTER;
 
           free(line);
 
@@ -2820,8 +2824,8 @@ ppd_read(cups_file_t *fp,         /* I - File to read from */
             * Line is too long...
            */
 
-            ppd_line   = startline;
-            ppd_status = PPD_LINE_TOO_LONG;
+            cg->ppd_line   = startline;
+            cg->ppd_status = PPD_LINE_TOO_LONG;
 
             free(line);
 
@@ -2843,7 +2847,7 @@ ppd_read(cups_file_t *fp,         /* I - File to read from */
          * Line feed or carriage return...
          */
 
-          ppd_line ++;
+          cg->ppd_line ++;
          col = 0;
 
          if (ch == '\r')
@@ -2860,14 +2864,14 @@ ppd_read(cups_file_t *fp,               /* I - File to read from */
 
          break;
        }
-       else if (ch < ' ' && ch != '\t' && ppd_conform == PPD_CONFORM_STRICT)
+       else if (ch < ' ' && ch != '\t' && cg->ppd_conform == PPD_CONFORM_STRICT)
        {
         /*
           * Other control characters...
          */
 
-          ppd_line   = startline;
-          ppd_status = PPD_ILLEGAL_CHARACTER;
+          cg->ppd_line   = startline;
+          cg->ppd_status = PPD_ILLEGAL_CHARACTER;
 
           free(line);
 
@@ -2883,8 +2887,8 @@ ppd_read(cups_file_t *fp,         /* I - File to read from */
             * Line is too long...
            */
 
-            ppd_line   = startline;
-            ppd_status = PPD_LINE_TOO_LONG;
+            cg->ppd_line   = startline;
+            cg->ppd_status = PPD_LINE_TOO_LONG;
 
             free(line);
 
@@ -2923,21 +2927,21 @@ ppd_read(cups_file_t *fp,               /* I - File to read from */
          strcmp(line, "*End") == 0) && /* End of multi-line string */
         ignoreblank)                   /* Ignore these? */
     {
-      startline = ppd_line + 1;
+      startline = cg->ppd_line + 1;
       continue;
     }
 
     if (strcmp(line, "*") == 0)                /* (Bad) comment line */
     {
-      if (ppd_conform == PPD_CONFORM_RELAXED)
+      if (cg->ppd_conform == PPD_CONFORM_RELAXED)
       {
-       startline = ppd_line + 1;
+       startline = cg->ppd_line + 1;
        continue;
       }
       else
       {
-        ppd_line   = startline;
-        ppd_status = PPD_ILLEGAL_MAIN_KEYWORD;
+        cg->ppd_line   = startline;
+        cg->ppd_status = PPD_ILLEGAL_MAIN_KEYWORD;
 
         free(line);
         return (0);
@@ -2946,9 +2950,9 @@ ppd_read(cups_file_t *fp,         /* I - File to read from */
 
     if (line[0] != '*')                        /* All lines start with an asterisk */
     {
-      if (ppd_conform == PPD_CONFORM_STRICT)
+      if (cg->ppd_conform == PPD_CONFORM_STRICT)
       {
-        ppd_status = PPD_MISSING_ASTERISK;
+        cg->ppd_status = PPD_MISSING_ASTERISK;
         free(line);
         return (0);
       }
@@ -2963,7 +2967,7 @@ ppd_read(cups_file_t *fp,         /* I - File to read from */
 
       if (*lineptr)
       {
-        ppd_status = PPD_MISSING_ASTERISK;
+        cg->ppd_status = PPD_MISSING_ASTERISK;
         free(line);
         return (0);
       }
@@ -2987,7 +2991,7 @@ ppd_read(cups_file_t *fp,         /* I - File to read from */
       if (*lineptr <= ' ' || *lineptr > 126 || *lineptr == '/' ||
           (keyptr - keyword) >= (PPD_MAX_NAME - 1))
       {
-        ppd_status = PPD_ILLEGAL_MAIN_KEYWORD;
+        cg->ppd_status = PPD_ILLEGAL_MAIN_KEYWORD;
         free(line);
        return (0);
       }
@@ -3021,7 +3025,7 @@ ppd_read(cups_file_t *fp,         /* I - File to read from */
        if (*lineptr <= ' ' || *lineptr > 126 ||
            (optptr - option) >= (PPD_MAX_NAME - 1))
         {
-          ppd_status = PPD_ILLEGAL_OPTION_KEYWORD;
+          cg->ppd_status = PPD_ILLEGAL_OPTION_KEYWORD;
           free(line);
          return (0);
        }
@@ -3031,9 +3035,9 @@ ppd_read(cups_file_t *fp,         /* I - File to read from */
 
       *optptr = '\0';
 
-      if (isspace(*lineptr & 255) && ppd_conform == PPD_CONFORM_STRICT)
+      if (isspace(*lineptr & 255) && cg->ppd_conform == PPD_CONFORM_STRICT)
       {
-        ppd_status = PPD_ILLEGAL_WHITESPACE;
+        cg->ppd_status = PPD_ILLEGAL_WHITESPACE;
         free(line);
        return (0);
       }
@@ -3060,7 +3064,7 @@ ppd_read(cups_file_t *fp,         /* I - File to read from */
          if (((unsigned char)*lineptr < ' ' && *lineptr != '\t') ||
              (textptr - text) >= (PPD_MAX_LINE - 1))
          {
-           ppd_status = PPD_ILLEGAL_TRANSLATION;
+           cg->ppd_status = PPD_ILLEGAL_TRANSLATION;
             free(line);
            return (0);
          }
@@ -3071,9 +3075,9 @@ ppd_read(cups_file_t *fp,         /* I - File to read from */
        *textptr = '\0';
        textlen  = ppd_decode(text);
 
-       if (textlen > PPD_MAX_TEXT && ppd_conform == PPD_CONFORM_STRICT)
+       if (textlen > PPD_MAX_TEXT && cg->ppd_conform == PPD_CONFORM_STRICT)
        {
-         ppd_status = PPD_ILLEGAL_TRANSLATION;
+         cg->ppd_status = PPD_ILLEGAL_TRANSLATION;
           free(line);
          return (0);
        }
@@ -3084,9 +3088,9 @@ ppd_read(cups_file_t *fp,         /* I - File to read from */
 /*      DEBUG_printf(("text = \"%s\", lineptr = \"%s\"\n", text, lineptr));*/
     }
 
-    if (isspace(*lineptr & 255) && ppd_conform == PPD_CONFORM_STRICT)
+    if (isspace(*lineptr & 255) && cg->ppd_conform == PPD_CONFORM_STRICT)
     {
-      ppd_status = PPD_ILLEGAL_WHITESPACE;
+      cg->ppd_status = PPD_ILLEGAL_WHITESPACE;
       free(line);
       return (0);
     }
index 841f0eabc13ab509cbdc38399c55d1aeffa90f54..7fe65466caca307da5fa063a0c93593d1452b372 100644 (file)
  * Include necessary headers...
  */
 
-#include "cups.h"
-#include "string.h"
+#include "globals.h"
 #include "debug.h"
 #include <stdlib.h>
-#include <ctype.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <sys/stat.h>
@@ -66,25 +64,8 @@ cupsTempFd(char *filename,           /* I - Pointer to buffer */
 #else
   struct timeval curtime;              /* Current time */
 #endif /* WIN32 */
-  static char  *buf = NULL;            /* Buffer if you pass in NULL and 0 */
 
 
- /*
-  * See if a filename was specified...
-  */
-
-  if (filename == NULL)
-  {
-    if (buf == NULL)
-      buf = calloc(1024, sizeof(char));
-
-    if (buf == NULL)
-      return (-1);
-
-    filename = buf;
-    len      = 1024;
-  }
-
  /*
   * See if TMPDIR is defined...
   */
@@ -183,7 +164,7 @@ cupsTempFile(char *filename,                /* I - Pointer to buffer */
              int  len)                 /* I - Size of buffer */
 {
   int          fd;                     /* File descriptor for temp file */
-  static char  buf[1024] = "";         /* Buffer if you pass in NULL and 0 */
+  cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
 
 
  /*
@@ -192,8 +173,8 @@ cupsTempFile(char *filename,                /* I - Pointer to buffer */
 
   if (filename == NULL)
   {
-    filename = buf;
-    len      = sizeof(buf);
+    filename = cg->tempfile;
+    len      = sizeof(cg->tempfile);
   }
 
  /*
index 05d404bbc0bbd00b5298e8ee316a1ac41ff67abb..5c18eeabc7bb82bbfbd5fd1297dce8a8e4c3913c 100644 (file)
  * Include necessary headers...
  */
 
-#include <stdio.h>
+#include "globals.h"
 #include <stdlib.h>
-#include <string.h>
 #include <errno.h>
-#include <ctype.h>
 #include <time.h>
 
-#include "language.h"
-#include "string.h"
-#include "transcode.h"
-
-
-/*
- * Local Globals...
- */
-
-static cups_cmap_t      *cmap_cache = NULL;    /* SBCS Charmap Cache */
-static cups_vmap_t      *vmap_cache = NULL;    /* VBCS Charmap Cache */
 
 /*
  * Prototypes...
@@ -111,7 +98,7 @@ cupsCharmapGet(const cups_encoding_t encoding)
 {
   char          *datadir;       /* CUPS_DATADIR environment variable */
   char          mapname[80];    /* Name of charset map */
-  char          filename[256];  /* Filename for charset map file */
+  char          filename[1024];  /* Filename for charset map file */
 
  /*
   * Check for valid arguments...
@@ -150,11 +137,13 @@ cupsCharmapFree(const cups_encoding_t encoding)
 {
   cups_cmap_t   *cmap;          /* Legacy SBCS / Unicode Charset Map */
   cups_vmap_t   *vmap;          /* Legacy VBCS / Unicode Charset Map */
+  cups_globals_t *cg = _cupsGlobals();
+                               /* Pointer to library globals */
 
  /*
   * See if we already have this SBCS charset map loaded...
   */
-  for (cmap = cmap_cache; cmap != NULL; cmap = cmap->next)
+  for (cmap = cg->cmap_cache; cmap != NULL; cmap = cmap->next)
   {
     if (cmap->encoding == encoding)
     {
@@ -167,7 +156,7 @@ cupsCharmapFree(const cups_encoding_t encoding)
  /*
   * See if we already have this DBCS/VBCS charset map loaded...
   */
-  for (vmap = vmap_cache; vmap != NULL; vmap = vmap->next)
+  for (vmap = cg->vmap_cache; vmap != NULL; vmap = vmap->next)
   {
     if (vmap->encoding == encoding)
     {
@@ -193,11 +182,13 @@ cupsCharmapFlush(void)
   cups_ucs2_t   *crow;          /* Pointer to UCS-2 row in 'char2uni' */
   cups_sbcs_t   *srow;          /* Pointer to SBCS row in 'uni2char' */
   cups_vbcs_t   *vrow;          /* Pointer to VBCS row in 'uni2char' */
+  cups_globals_t *cg = _cupsGlobals();
+                               /* Pointer to library globals */
 
  /*
   * Loop through SBCS charset map cache, free all memory...
   */
-  for (cmap = cmap_cache; cmap != NULL; cmap = cnext)
+  for (cmap = cg->cmap_cache; cmap != NULL; cmap = cnext)
   {
     for (i = 0; i < 256; i ++)
     {
@@ -207,12 +198,12 @@ cupsCharmapFlush(void)
     cnext = cmap->next;
     free(cmap);
   }
-  cmap_cache = NULL;
+  cg->cmap_cache = NULL;
 
  /*
   * Loop through DBCS/VBCS charset map cache, free all memory...
   */
-  for (vmap = vmap_cache; vmap != NULL; vmap = vnext)
+  for (vmap = cg->vmap_cache; vmap != NULL; vmap = vnext)
   {
     for (i = 0; i < 256; i ++)
     {
@@ -229,7 +220,7 @@ cupsCharmapFlush(void)
     vnext = vmap->next;
     free(vmap);
   }
-  vmap_cache = NULL;
+  cg->vmap_cache = NULL;
   return;
 }
 
@@ -815,7 +806,7 @@ static int                              /* O - Count or -1 on error */
 get_charmap_count(const char *filename) /* I - Charmap Filename */
 {
   int           i;              /* Looping variable */
-  FILE          *fp;            /* Map input file pointer */
+  cups_file_t  *fp;            /* Map input file pointer */
   char          *s;             /* Line parsing pointer */
   char          line[256];      /* Line from input map file */
   cups_utf32_t  unichar;        /* Unicode character value */
@@ -825,7 +816,7 @@ get_charmap_count(const char *filename) /* I - Charmap Filename */
   */
   if ((filename == NULL) || (*filename == '\0'))
     return (-1);
-  fp = fopen(filename, "r");
+  fp = cupsFileOpen(filename, "r");
   if (fp == NULL)
     return (-1);
 
@@ -834,7 +825,7 @@ get_charmap_count(const char *filename) /* I - Charmap Filename */
   */
   for (i = 0; i < CUPS_MAX_CHARMAP_LINES;)
   {
-    s = fgets(&line[0], sizeof(line), fp);
+    s = cupsFileGets(fp, line, sizeof(line));
     if (s == NULL)
       break;
     if ((*s == '#') || (*s == '\n') || (*s == '\0'))
@@ -848,7 +839,7 @@ get_charmap_count(const char *filename) /* I - Charmap Filename */
     if ((sscanf(s, "%lx", &unichar) != 1)
     || (unichar > 0xffff))
     {
-      fclose(fp);
+      cupsFileClose(fp);
       return (-1);
     }
     i ++;
@@ -859,7 +850,7 @@ get_charmap_count(const char *filename) /* I - Charmap Filename */
  /*
   * Close file and return charmap count (non-comment line count)...
   */
-  fclose(fp);
+  cupsFileClose(fp);
   return (i);
 }
 
@@ -875,11 +866,13 @@ get_sbcs_charmap(const cups_encoding_t encoding,
   unsigned long legchar;        /* Legacy character value */
   cups_utf32_t  unichar;        /* Unicode character value */
   cups_cmap_t   *cmap;          /* Legacy SBCS / Unicode Charset Map */
-  FILE          *fp;            /* Charset map file pointer */
+  cups_file_t   *fp;            /* Charset map file pointer */
   char          *s;             /* Line parsing pointer */
   cups_ucs2_t   *crow;          /* Pointer to UCS-2 row in 'char2uni' */
   cups_sbcs_t   *srow;          /* Pointer to SBCS row in 'uni2char' */
   char          line[256];      /* Line from charset map file */
+  cups_globals_t *cg = _cupsGlobals();
+                               /* Pointer to library globals */
 
  /*
   * Check for valid arguments...
@@ -890,7 +883,7 @@ get_sbcs_charmap(const cups_encoding_t encoding,
  /*
   * See if we already have this SBCS charset map loaded...
   */
-  for (cmap = cmap_cache; cmap != NULL; cmap = cmap->next)
+  for (cmap = cg->cmap_cache; cmap != NULL; cmap = cmap->next)
   {
     if (cmap->encoding == encoding)
     {
@@ -902,7 +895,7 @@ get_sbcs_charmap(const cups_encoding_t encoding,
  /*
   * Open SBCS charset map input file...
   */
-  fp = fopen(filename, "r");
+  fp = cupsFileOpen(filename, "r");
   if (fp == NULL)
     return (NULL);
 
@@ -912,11 +905,11 @@ get_sbcs_charmap(const cups_encoding_t encoding,
   cmap = (cups_cmap_t *) calloc(1, sizeof(cups_cmap_t));
   if (cmap == NULL)
   {
-    fclose(fp);
+    cupsFileClose(fp);
     return (NULL);
   }
-  cmap->next = cmap_cache;
-  cmap_cache = cmap;
+  cmap->next = cg->cmap_cache;
+  cg->cmap_cache = cmap;
   cmap->used ++;
   cmap->encoding = encoding;
 
@@ -925,7 +918,7 @@ get_sbcs_charmap(const cups_encoding_t encoding,
   */
   for (i = 0; i < CUPS_MAX_CHARMAP_LINES;)
   {
-    s = fgets(&line[0], sizeof(line), fp);
+    s = cupsFileGets(fp, line, sizeof(line));
     if (s == NULL)
       break;
     if ((*s == '#') || (*s == '\n') || (*s == '\0'))
@@ -935,7 +928,7 @@ get_sbcs_charmap(const cups_encoding_t encoding,
     if ((sscanf(s, "%lx", &legchar) != 1)
     || (legchar > 0xff))
     {
-      fclose(fp);
+      cupsFileClose(fp);
       cupsCharmapFlush();
       return (NULL);
     }
@@ -947,7 +940,7 @@ get_sbcs_charmap(const cups_encoding_t encoding,
       s += 2;
     if (sscanf(s, "%lx", &unichar) != 1)
     {
-      fclose(fp);
+      cupsFileClose(fp);
       cupsCharmapFlush();
       return (NULL);
     }
@@ -974,7 +967,7 @@ get_sbcs_charmap(const cups_encoding_t encoding,
       srow = (cups_sbcs_t *) calloc(256, sizeof(cups_sbcs_t));
       if (srow == NULL)
       {
-        fclose(fp);
+        cupsFileClose(fp);
         cupsCharmapFlush();
         return (NULL);
       }
@@ -994,7 +987,7 @@ get_sbcs_charmap(const cups_encoding_t encoding,
     if (*srow == 0)
       *srow = (cups_sbcs_t) legchar;
   }
-  fclose(fp);
+  cupsFileClose(fp);
   return (cmap);
 }
 
@@ -1014,11 +1007,13 @@ get_vbcs_charmap(const cups_encoding_t encoding,
   unsigned long     legchar;    /* Legacy character value */
   cups_utf32_t      unichar;    /* Unicode character value */
   int               mapcount;   /* Count of lines in charmap file */
-  FILE              *fp;        /* Charset map file pointer */
+  cups_file_t       *fp;        /* Charset map file pointer */
   char              *s;         /* Line parsing pointer */
   char              line[256];  /* Line from charset map file */
   int               i;          /* Loop variable */
   int               wide;       /* 32-bit legacy char */
+  cups_globals_t    *cg = _cupsGlobals();
+                               /* Pointer to library globals */
 
  /*
   * Check for valid arguments...
@@ -1029,7 +1024,7 @@ get_vbcs_charmap(const cups_encoding_t encoding,
  /*
   * See if we already have this DBCS/VBCS charset map loaded...
   */
-  for (vmap = vmap_cache; vmap != NULL; vmap = vmap->next)
+  for (vmap = cg->vmap_cache; vmap != NULL; vmap = vmap->next)
   {
     if (vmap->encoding == encoding)
     {
@@ -1048,7 +1043,7 @@ get_vbcs_charmap(const cups_encoding_t encoding,
  /*
   * Open VBCS charset map input file...
   */
-  fp = fopen(filename, "r");
+  fp = cupsFileOpen(filename, "r");
   if (fp == NULL)
     return (NULL);
 
@@ -1058,11 +1053,11 @@ get_vbcs_charmap(const cups_encoding_t encoding,
   vmap = (cups_vmap_t *) calloc(1, sizeof(cups_vmap_t));
   if (vmap == NULL)
   {
-    fclose(fp);
+    cupsFileClose(fp);
     return (NULL);
   }
-  vmap->next = vmap_cache;
-  vmap_cache = vmap;
+  vmap->next = cg->vmap_cache;
+  cg->vmap_cache = vmap;
   vmap->used ++;
   vmap->encoding = encoding;
 
@@ -1074,7 +1069,7 @@ get_vbcs_charmap(const cups_encoding_t encoding,
 
   for (i = 0, wide = 0; i < mapcount; )
   {
-    s = fgets(&line[0], sizeof(line), fp);
+    s = cupsFileGets(fp, line, sizeof(line));
     if (s == NULL)
       break;
     if ((*s == '#') || (*s == '\n') || (*s == '\0'))
@@ -1084,7 +1079,7 @@ get_vbcs_charmap(const cups_encoding_t encoding,
     if ((sscanf(s, "%lx", &legchar) != 1)
     || ((legchar > 0xffff) && (encoding < CUPS_ENCODING_DBCS_END)))
     {
-      fclose(fp);
+      cupsFileClose(fp);
       cupsCharmapFlush();
       return (NULL);
     }
@@ -1096,7 +1091,7 @@ get_vbcs_charmap(const cups_encoding_t encoding,
       s += 2;
     if (sscanf(s, "%lx", &unichar) != 1)
     {
-      fclose(fp);
+      cupsFileClose(fp);
       cupsCharmapFlush();
       return (NULL);
     }
@@ -1141,7 +1136,7 @@ get_vbcs_charmap(const cups_encoding_t encoding,
         crow = (cups_ucs2_t *) calloc(256, sizeof(cups_ucs2_t));
         if (crow == NULL)
         {
-          fclose(fp);
+          cupsFileClose(fp);
           cupsCharmapFlush();
           return (NULL);
         }
@@ -1163,7 +1158,7 @@ get_vbcs_charmap(const cups_encoding_t encoding,
           calloc(vmap->widecount, sizeof(cups_wide2uni_t));
         if (wide2uni == NULL)
         {
-          fclose(fp);
+          cupsFileClose(fp);
           cupsCharmapFlush();
           return (NULL);
         }
@@ -1183,7 +1178,7 @@ get_vbcs_charmap(const cups_encoding_t encoding,
       vrow = (cups_vbcs_t *) calloc(256, sizeof(cups_vbcs_t));
       if (vrow == NULL)
       {
-        fclose(fp);
+        cupsFileClose(fp);
         cupsCharmapFlush();
         return (NULL);
       }
@@ -1204,7 +1199,7 @@ get_vbcs_charmap(const cups_encoding_t encoding,
       *vrow = (cups_vbcs_t) legchar;
   }
   vmap->charcount = (i - vmap->widecount);
-  fclose(fp);
+  cupsFileClose(fp);
   return (vmap);
 }
 
index 5511aac08aa5e37aebc34d2f58ac9e09afdb7ddb..7b7134f184170d339edb7c57ab212143f0bb4180 100644 (file)
  *   cupsSetServer()     - Set the default server name...
  *   cupsSetUser()       - Set the default user name...
  *   cupsUser()          - Return the current users name.
- *   cups_get_password() - Get a password from the user...
- *   cups_get_line()     - Get a line from a file...
+ *   _cupsGetPassword()  - Get a password from the user...
  */
 
 /*
  * Include necessary headers...
  */
 
-#include "cups.h"
-#include "string.h"
 #include "http-private.h"
+#include "globals.h"
 #include <stdlib.h>
-
 #ifdef WIN32
 #  include <windows.h>
 #endif /* WIN32 */
 
 
-/*
- * Local functions...
- */
-
-static const char      *cups_get_password(const char *prompt);
-static char            *cups_get_line(char *buf, int buflen, FILE *fp);
-
-
-/*
- * Local globals...
- */
-
-static http_encryption_t cups_encryption = (http_encryption_t)-1;
-static char            cups_user[65] = "",
-                       cups_server[256] = "";
-static const char      *(*cups_pwdcb)(const char *) = cups_get_password;
-
-#ifdef HAVE_DOMAINSOCKETS
-char                   cups_server_domainsocket[104] = "";
-#endif /* HAVE_DOMAINSOCKETS */
-
 /*
  * 'cupsEncryption()' - Get the default encryption settings...
  */
@@ -80,17 +56,18 @@ char                        cups_server_domainsocket[104] = "";
 http_encryption_t
 cupsEncryption(void)
 {
-  FILE         *fp;                    /* client.conf file */
+  cups_file_t  *fp;                    /* client.conf file */
   char         *encryption;            /* CUPS_ENCRYPTION variable */
   const char   *home;                  /* Home directory of user */
   char         line[1024];             /* Line from file */
+  cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
 
 
  /*
   * First see if we have already set the encryption stuff...
   */
 
-  if (cups_encryption == (http_encryption_t)-1)
+  if (cg->encryption == (http_encryption_t)-1)
   {
    /*
     * Then see if the CUPS_ENCRYPTION environment variable is set...
@@ -105,7 +82,7 @@ cupsEncryption(void)
       if ((home = getenv("HOME")) != NULL)
       {
        snprintf(line, sizeof(line), "%s/.cupsrc", home);
-       fp = fopen(line, "r");
+       fp = cupsFileOpen(line, "r");
       }
       else
        fp = NULL;
@@ -115,10 +92,10 @@ cupsEncryption(void)
        if ((home = getenv("CUPS_SERVERROOT")) != NULL)
        {
          snprintf(line, sizeof(line), "%s/client.conf", home);
-         fp = fopen(line, "r");
+         fp = cupsFileOpen(line, "r");
        }
        else
-         fp = fopen(CUPS_SERVERROOT "/client.conf", "r");
+         fp = cupsFileOpen(CUPS_SERVERROOT "/client.conf", "r");
       }
 
       encryption = "IfRequested";
@@ -129,7 +106,7 @@ cupsEncryption(void)
        * Read the config file and look for an Encryption line...
        */
 
-       while (cups_get_line(line, sizeof(line), fp) != NULL)
+       while (cupsFileGets(fp, line, sizeof(line)) != NULL)
          if (strncmp(line, "Encryption ", 11) == 0 ||
              strncmp(line, "Encryption\t", 11) == 0)
          {
@@ -145,7 +122,7 @@ cupsEncryption(void)
            break;
          }
 
-       fclose(fp);
+       cupsFileClose(fp);
       }
     }
 
@@ -154,16 +131,16 @@ cupsEncryption(void)
     */
 
     if (strcasecmp(encryption, "never") == 0)
-      cups_encryption = HTTP_ENCRYPT_NEVER;
+      cg->encryption = HTTP_ENCRYPT_NEVER;
     else if (strcasecmp(encryption, "always") == 0)
-      cups_encryption = HTTP_ENCRYPT_ALWAYS;
+      cg->encryption = HTTP_ENCRYPT_ALWAYS;
     else if (strcasecmp(encryption, "required") == 0)
-      cups_encryption = HTTP_ENCRYPT_REQUIRED;
+      cg->encryption = HTTP_ENCRYPT_REQUIRED;
     else
-      cups_encryption = HTTP_ENCRYPT_IF_REQUESTED;
+      cg->encryption = HTTP_ENCRYPT_IF_REQUESTED;
   }
 
-  return (cups_encryption);
+  return (cg->encryption);
 }
 
 
@@ -174,7 +151,7 @@ cupsEncryption(void)
 const char *                           /* O - Password */
 cupsGetPassword(const char *prompt)    /* I - Prompt string */
 {
-  return ((*cups_pwdcb)(prompt));
+  return ((*_cupsGlobals()->password_cb)(prompt));
 }
 
 
@@ -185,7 +162,7 @@ cupsGetPassword(const char *prompt) /* I - Prompt string */
 void
 cupsSetEncryption(http_encryption_t e) /* I - New encryption preference */
 {
-  cups_encryption = e;
+  _cupsGlobals()->encryption = e;
 }
 
 
@@ -196,18 +173,21 @@ cupsSetEncryption(http_encryption_t e)    /* I - New encryption preference */
 const char *                           /* O - Server name */
 cupsServer(void)
 {
-  FILE         *fp;                    /* client.conf file */
+  cups_file_t  *fp;                    /* client.conf file */
   char         *server;                /* Pointer to server name */
   const char   *home;                  /* Home directory of user */
   char         *port;                  /* Port number */
-  char         line[1024];             /* Line from file */
+  char         line[1024],             /* Line from file */
+               *value;                 /* Value on line */
+  int          linenum;                /* Line number in file */
+  cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
 
 
  /*
   * First see if we have already set the server name...
   */
 
-  if (!cups_server[0])
+  if (!cg->server[0])
   {
    /*
     * Then see if the CUPS_SERVER environment variable is set...
@@ -222,7 +202,7 @@ cupsServer(void)
       if ((home = getenv("HOME")) != NULL)
       {
        snprintf(line, sizeof(line), "%s/.cupsrc", home);
-       fp = fopen(line, "r");
+       fp = cupsFileOpen(line, "r");
       }
       else
        fp = NULL;
@@ -232,10 +212,10 @@ cupsServer(void)
        if ((home = getenv("CUPS_SERVERROOT")) != NULL)
        {
          snprintf(line, sizeof(line), "%s/client.conf", home);
-         fp = fopen(line, "r");
+         fp = cupsFileOpen(line, "r");
        }
        else
-         fp = fopen(CUPS_SERVERROOT "/client.conf", "r");
+         fp = cupsFileOpen(CUPS_SERVERROOT "/client.conf", "r");
       }
 
       server = "localhost";
@@ -246,23 +226,19 @@ cupsServer(void)
        * Read the config file and look for a ServerName line...
        */
 
-       while (cups_get_line(line, sizeof(line), fp) != NULL)
-         if (strncmp(line, "ServerName ", 11) == 0 ||
-             strncmp(line, "ServerName\t", 11) == 0)
+        linenum = 0;
+       while (cupsFileGetConf(fp, line, sizeof(line), &value, &linenum) != NULL)
+         if (!strcmp(line, "ServerName") && value)
          {
           /*
-           * Got it!  Drop any trailing newline and find the name...
+           * Got it!
            */
 
-           server = line + strlen(line) - 1;
-           if (*server == '\n')
-              *server = '\0';
-
-           for (server = line + 11; isspace(*server & 255); server ++);
+           server = value;
            break;
          }
 
-       fclose(fp);
+       cupsFileClose(fp);
       }
     }
 
@@ -270,9 +246,9 @@ cupsServer(void)
     * Copy the server name over and set the port number, if any...
     */
 
-    strlcpy(cups_server, server, sizeof(cups_server));
+    strlcpy(cg->server, server, sizeof(cg->server));
 
-    if (cups_server[0] != '/' && (port = strrchr(cups_server, ':')) != NULL &&
+    if (cg->server[0] != '/' && (port = strrchr(cg->server, ':')) != NULL &&
         isdigit(port[1] & 255))
     {
       *port++ = '\0';
@@ -281,7 +257,7 @@ cupsServer(void)
     }
   }
 
-  return (cups_server);
+  return (cg->server);
 }
 
 
@@ -292,10 +268,13 @@ cupsServer(void)
 void
 cupsSetPasswordCB(const char *(*cb)(const char *))     /* I - Callback function */
 {
+  cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
+
+
   if (cb == (const char *(*)(const char *))0)
-    cups_pwdcb = cups_get_password;
+    cg->password_cb = _cupsGetPassword;
   else
-    cups_pwdcb = cb;
+    cg->password_cb = cb;
 }
 
 
@@ -306,10 +285,13 @@ cupsSetPasswordCB(const char *(*cb)(const char *))        /* I - Callback function */
 void
 cupsSetServer(const char *server)      /* I - Server name */
 {
+  cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
+
+
   if (server)
-    strlcpy(cups_server, server, sizeof(cups_server));
+    strlcpy(cg->server, server, sizeof(cg->server));
   else
-    cups_server[0] = '\0';
+    cg->server[0] = '\0';
 }
 
 
@@ -320,10 +302,13 @@ cupsSetServer(const char *server) /* I - Server name */
 void
 cupsSetUser(const char *user)          /* I - User name */
 {
+  cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
+
+
   if (user)
-    strlcpy(cups_user, user, sizeof(cups_user));
+    strlcpy(cg->user, user, sizeof(cg->user));
   else
-    cups_user[0] = '\0';
+    cg->user[0] = '\0';
 }
 
 
@@ -339,32 +324,35 @@ cupsSetUser(const char *user)             /* I - User name */
 const char *                           /* O - User name */
 cupsUser(void)
 {
-  if (!cups_user[0])
+  cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
+
+
+  if (!cg->user[0])
   {
     DWORD      size;           /* Size of string */
 
 
-    size = sizeof(cups_user);
-    if (!GetUserName(cups_user, &size))
+    size = sizeof(cg->user);
+    if (!GetUserName(cg->user, &size))
     {
      /*
       * Use the default username...
       */
 
-      strcpy(cups_user, "unknown");
+      strcpy(cg->user, "unknown");
     }
   }
 
-  return (cups_user);
+  return (cg->user);
 }
 
 
 /*
- * 'cups_get_password()' - Get a password from the user...
+ * '_cupsGetPassword()' - Get a password from the user...
  */
 
-static const char *                    /* O - Password */
-cups_get_password(const char *prompt)  /* I - Prompt string */
+const char *                           /* O - Password */
+_cupsGetPassword(const char *prompt)   /* I - Prompt string */
 {
   return (NULL);
 }
@@ -383,9 +371,10 @@ const char *                               /* O - User name */
 cupsUser(void)
 {
   struct passwd        *pwd;                   /* User/password entry */
+  cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
 
 
-  if (!cups_user[0])
+  if (!cg->user[0])
   {
    /*
     * Rewind the password file...
@@ -398,7 +387,7 @@ cupsUser(void)
     */
 
     if ((pwd = getpwuid(getuid())) == NULL)
-      strcpy(cups_user, "unknown");    /* Unknown user! */
+      strcpy(cg->user, "unknown");     /* Unknown user! */
     else
     {
      /*
@@ -407,7 +396,7 @@ cupsUser(void)
 
       setpwent();
 
-      strlcpy(cups_user, pwd->pw_name, sizeof(cups_user));
+      strlcpy(cg->user, pwd->pw_name, sizeof(cg->user));
     }
 
    /*
@@ -417,56 +406,22 @@ cupsUser(void)
     setpwent();
   }
 
-  return (cups_user);
+  return (cg->user);
 }
 
 
 /*
- * 'cups_get_password()' - Get a password from the user...
+ * '_cupsGetPassword()' - Get a password from the user...
  */
 
-static const char *                    /* O - Password */
-cups_get_password(const char *prompt)  /* I - Prompt string */
+const char *                           /* O - Password */
+_cupsGetPassword(const char *prompt)   /* I - Prompt string */
 {
   return (getpass(prompt));
 }
 #endif /* WIN32 */
 
 
-/*
- * 'cups_get_line()' - Get a line from a file.
- */
-
-static char *                  /* O - Line from file */
-cups_get_line(char *buf,       /* I - Line buffer */
-              int  buflen,     /* I - Size of line buffer */
-             FILE *fp)         /* I - File to read from */
-{
-  char *bufptr;                /* Pointer to end of buffer */
-
-
- /*
-  * Get the line from a file...
-  */
-
-  if (fgets(buf, buflen, fp) == NULL)
-    return (NULL);
-
- /*
-  * Remove all trailing whitespace...
-  */
-
-  bufptr = buf + strlen(buf) - 1;
-  if (bufptr < buf)
-    return (NULL);
-
-  while (bufptr >= buf && isspace(*bufptr & 255))
-    *bufptr-- = '\0';
-
-  return (buf);
-}
-
-
 /*
  * End of "$Id$".
  */
index 7c8b6e174c85320c34e56009ad061beebe701270..54434aad56ddc2e1cfcdaee7cfef2233b95f8e86 100644 (file)
  * Include necessary headers...
  */
 
-#include "cups.h"
-#include "language.h"
-#include "string.h"
+#include "globals.h"
 #include "debug.h"
 #include <stdlib.h>
-#include <ctype.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <sys/stat.h>
 #endif /* WIN32 || __EMX__ */
 
 
-/*
- * Local globals...
- */
-
-static http_t          *cups_server = NULL;    /* Current server connection */
-static ipp_status_t    last_error = IPP_OK;    /* Last IPP error */
-
-
 /*
  * Local functions...
  */
@@ -93,6 +82,7 @@ cupsCancelJob(const char *name,               /* I - Name of printer or class */
   ipp_t                *request,               /* IPP request */
                *response;              /* IPP response */
   cups_lang_t  *language;              /* Language info */
+  cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
 
 
  /*
@@ -102,7 +92,7 @@ cupsCancelJob(const char *name,              /* I - Name of printer or class */
   if (!cups_connect(name, printer, hostname))
   {
     DEBUG_puts("Unable to connect to server!");
-    last_error = IPP_SERVICE_UNAVAILABLE;
+    cg->last_error = IPP_SERVICE_UNAVAILABLE;
     return (0);
   }
 
@@ -146,10 +136,10 @@ cupsCancelJob(const char *name,           /* I - Name of printer or class */
   * Do the request...
   */
 
-  if ((response = cupsDoRequest(cups_server, request, "/jobs/")) != NULL)
+  if ((response = cupsDoRequest(cg->http, request, "/jobs/")) != NULL)
     ippDelete(response);
 
-  return (last_error < IPP_REDIRECTION_OTHER_SITE);
+  return (cg->last_error < IPP_REDIRECTION_OTHER_SITE);
 }
 
 
@@ -170,6 +160,7 @@ cupsDoFileRequest(http_t     *http, /* I - HTTP connection to server */
   struct stat  fileinfo;               /* File information */
   int          bytes;                  /* Number of bytes read/written */
   char         buffer[32768];          /* Output buffer */
+  cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
 
 
   DEBUG_printf(("cupsDoFileRequest(%p, %p, \'%s\', \'%s\')\n",
@@ -181,7 +172,7 @@ cupsDoFileRequest(http_t     *http, /* I - HTTP connection to server */
     if (request != NULL)
       ippDelete(request);
 
-    last_error = IPP_INTERNAL_ERROR;
+    cg->last_error = IPP_INTERNAL_ERROR;
     return (NULL);
   }
 
@@ -198,7 +189,7 @@ cupsDoFileRequest(http_t     *http, /* I - HTTP connection to server */
       */
 
       ippDelete(request);
-      last_error = IPP_NOT_FOUND;
+      cg->last_error = IPP_NOT_FOUND;
       return (NULL);
     }
 
@@ -213,7 +204,7 @@ cupsDoFileRequest(http_t     *http, /* I - HTTP connection to server */
       */
 
       ippDelete(request);
-      last_error = IPP_NOT_POSSIBLE;
+      cg->last_error = IPP_NOT_POSSIBLE;
       return (NULL);
     }
 
@@ -224,7 +215,7 @@ cupsDoFileRequest(http_t     *http, /* I - HTTP connection to server */
       */
 
       ippDelete(request);
-      last_error = IPP_NOT_FOUND;
+      cg->last_error = IPP_NOT_FOUND;
       return (NULL);
     }
   }
@@ -359,7 +350,11 @@ cupsDoFileRequest(http_t     *http,        /* I - HTTP connection to server */
       httpFlush(http);
 
       /* Reconnect... */
-      httpReconnect(http);
+      if (httpReconnect(http))
+      {
+        status = HTTP_ERROR;
+        break;
+      }
 
       /* Upgrade with encryption... */
       httpEncryption(http, HTTP_ENCRYPT_REQUIRED);
@@ -399,7 +394,7 @@ cupsDoFileRequest(http_t     *http, /* I - HTTP connection to server */
        ippDelete(response);
        response = NULL;
 
-        last_error = IPP_SERVICE_UNAVAILABLE;
+        cg->last_error = IPP_SERVICE_UNAVAILABLE;
        break;
       }
     }
@@ -425,43 +420,43 @@ cupsDoFileRequest(http_t     *http,       /* I - HTTP connection to server */
   ippDelete(request);
 
   if (response)
-    last_error = response->request.status.status_code;
+    cg->last_error = response->request.status.status_code;
   else if (status != HTTP_OK)
   {
     switch (status)
     {
       case HTTP_NOT_FOUND :
-          last_error = IPP_NOT_FOUND;
+          cg->last_error = IPP_NOT_FOUND;
          break;
 
       case HTTP_UNAUTHORIZED :
-          last_error = IPP_NOT_AUTHORIZED;
+          cg->last_error = IPP_NOT_AUTHORIZED;
          break;
 
       case HTTP_FORBIDDEN :
-          last_error = IPP_FORBIDDEN;
+          cg->last_error = IPP_FORBIDDEN;
          break;
 
       case HTTP_BAD_REQUEST :
-          last_error = IPP_BAD_REQUEST;
+          cg->last_error = IPP_BAD_REQUEST;
          break;
 
       case HTTP_REQUEST_TOO_LARGE :
-          last_error = IPP_REQUEST_VALUE;
+          cg->last_error = IPP_REQUEST_VALUE;
          break;
 
       case HTTP_NOT_IMPLEMENTED :
-          last_error = IPP_OPERATION_NOT_SUPPORTED;
+          cg->last_error = IPP_OPERATION_NOT_SUPPORTED;
          break;
 
       case HTTP_NOT_SUPPORTED :
-          last_error = IPP_VERSION_NOT_SUPPORTED;
+          cg->last_error = IPP_VERSION_NOT_SUPPORTED;
          break;
 
       default :
          DEBUG_printf(("HTTP error %d mapped to IPP_SERVICE_UNAVAILABLE!\n",
                        status));
-         last_error = IPP_SERVICE_UNAVAILABLE;
+         cg->last_error = IPP_SERVICE_UNAVAILABLE;
          break;
     }
   }
@@ -509,11 +504,12 @@ cupsGetClasses(char ***classes)           /* O - Classes */
   ipp_attribute_t *attr;               /* Current attribute */
   cups_lang_t  *language;              /* Default language */
   char         **temp;                 /* Temporary pointer */
+  cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
 
 
   if (classes == NULL)
   {
-    last_error = IPP_INTERNAL_ERROR;
+    cg->last_error = IPP_INTERNAL_ERROR;
     return (0);
   }
 
@@ -524,7 +520,7 @@ cupsGetClasses(char ***classes)             /* O - Classes */
   if (!cups_connect("default", NULL, NULL))
   {
     DEBUG_puts("Unable to connect to server!");
-    last_error = IPP_SERVICE_UNAVAILABLE;
+    cg->last_error = IPP_SERVICE_UNAVAILABLE;
     return (0);
   }
 
@@ -562,9 +558,9 @@ cupsGetClasses(char ***classes)             /* O - Classes */
   n        = 0;
   *classes = NULL;
 
-  if ((response = cupsDoRequest(cups_server, request, "/")) != NULL)
+  if ((response = cupsDoRequest(cg->http, request, "/")) != NULL)
   {
-    last_error = response->request.status.status_code;
+    cg->last_error = response->request.status.status_code;
 
     for (attr = response->attrs; attr != NULL; attr = attr->next)
       if (attr->name != NULL &&
@@ -601,7 +597,7 @@ cupsGetClasses(char ***classes)             /* O - Classes */
     ippDelete(response);
   }
   else
-    last_error = IPP_BAD_REQUEST;
+    cg->last_error = IPP_BAD_REQUEST;
 
   return (n);
 }
@@ -615,6 +611,7 @@ const char *                                /* O - Default printer or NULL */
 cupsGetDefault(void)
 {
   const char   *var;                   /* Environment variable */
+  cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
 
 
  /*
@@ -636,7 +633,7 @@ cupsGetDefault(void)
   if (!cups_connect("default", NULL, NULL))
   {
     DEBUG_puts("Unable to connect to server!");
-    last_error = IPP_SERVICE_UNAVAILABLE;
+    cg->last_error = IPP_SERVICE_UNAVAILABLE;
     return (NULL);
   }
 
@@ -644,7 +641,7 @@ cupsGetDefault(void)
   * Return the default printer...
   */
 
-  return (cupsGetDefault2(cups_server));
+  return (cupsGetDefault2(cg->http));
 }
 
 
@@ -660,7 +657,7 @@ cupsGetDefault2(http_t *http)               /* I - HTTP connection */
   ipp_attribute_t *attr;               /* Current attribute */
   cups_lang_t  *language;              /* Default language */
   const char   *var;                   /* Environment variable */
-  static char  def_printer[256];       /* Default printer */
+  cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
 
 
  /*
@@ -711,19 +708,19 @@ cupsGetDefault2(http_t *http)             /* I - HTTP connection */
 
   if ((response = cupsDoRequest(http, request, "/")) != NULL)
   {
-    last_error = response->request.status.status_code;
+    cg->last_error = response->request.status.status_code;
 
     if ((attr = ippFindAttribute(response, "printer-name", IPP_TAG_NAME)) != NULL)
     {
-      strlcpy(def_printer, attr->values[0].string.text, sizeof(def_printer));
+      strlcpy(cg->def_printer, attr->values[0].string.text, sizeof(cg->def_printer));
       ippDelete(response);
-      return (def_printer);
+      return (cg->def_printer);
     }
 
     ippDelete(response);
   }
   else
-    last_error = IPP_BAD_REQUEST;
+    cg->last_error = IPP_BAD_REQUEST;
 
   return (NULL);
 }
@@ -739,6 +736,8 @@ cupsGetJobs(cups_job_t **jobs,              /* O - Job data */
             int        myjobs,         /* I - Only show my jobs? */
            int        completed)       /* I - Only show completed jobs? */
 {
+  cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
+
  /*
   * Try to connect to the server...
   */
@@ -746,7 +745,7 @@ cupsGetJobs(cups_job_t **jobs,              /* O - Job data */
   if (!cups_connect("default", NULL, NULL))
   {
     DEBUG_puts("Unable to connect to server!");
-    last_error = IPP_SERVICE_UNAVAILABLE;
+    cg->last_error = IPP_SERVICE_UNAVAILABLE;
     return (-1);
   }
 
@@ -754,7 +753,7 @@ cupsGetJobs(cups_job_t **jobs,              /* O - Job data */
   * Return the jobs...
   */
 
-  return (cupsGetJobs2(cups_server, jobs, mydest, myjobs, completed));
+  return (cupsGetJobs2(cg->http, jobs, mydest, myjobs, completed));
 }
 
 
@@ -788,6 +787,7 @@ cupsGetJobs2(http_t     *http,              /* I - HTTP connection */
                *title,                 /* job-name */
                *user;                  /* job-originating-user-name */
   char         uri[HTTP_MAX_URI];      /* URI for jobs */
+  cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
   static const char * const attrs[] =  /* Requested attributes */
                {
                  "job-id",
@@ -806,7 +806,7 @@ cupsGetJobs2(http_t     *http,              /* I - HTTP connection */
 
   if (!http || !jobs)
   {
-    last_error = IPP_INTERNAL_ERROR;
+    cg->last_error = IPP_INTERNAL_ERROR;
     return (-1);
   }
 
@@ -869,7 +869,7 @@ cupsGetJobs2(http_t     *http,              /* I - HTTP connection */
 
   if ((response = cupsDoRequest(http, request, "/")) != NULL)
   {
-    last_error = response->request.status.status_code;
+    cg->last_error = response->request.status.status_code;
 
     for (attr = response->attrs; attr != NULL; attr = attr->next)
     {
@@ -1003,9 +1003,9 @@ cupsGetJobs2(http_t     *http,            /* I - HTTP connection */
     ippDelete(response);
   }
   else
-    last_error = IPP_BAD_REQUEST;
+    cg->last_error = IPP_BAD_REQUEST;
 
-  if (n == 0 && last_error >= IPP_BAD_REQUEST)
+  if (n == 0 && cg->last_error >= IPP_BAD_REQUEST)
     return (-1);
   else
     return (n);
@@ -1019,6 +1019,8 @@ cupsGetJobs2(http_t     *http,            /* I - HTTP connection */
 const char *                           /* O - Filename for PPD file */
 cupsGetPPD(const char *name)           /* I - Printer name */
 {
+  cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
+
  /*
   * See if we can connect to the server...
   */
@@ -1026,7 +1028,7 @@ cupsGetPPD(const char *name)              /* I - Printer name */
   if (!cups_connect(name, NULL, NULL))
   {
     DEBUG_puts("Unable to connect to server!");
-    last_error = IPP_SERVICE_UNAVAILABLE;
+    cg->last_error = IPP_SERVICE_UNAVAILABLE;
     return (NULL);
   }
 
@@ -1034,7 +1036,7 @@ cupsGetPPD(const char *name)              /* I - Printer name */
   * Return the PPD file...
   */
 
-  return (cupsGetPPD2(cups_server, name));
+  return (cupsGetPPD2(cg->http, name));
 }
 
 
@@ -1061,7 +1063,7 @@ cupsGetPPD2(http_t     *http,             /* I - HTTP connection */
                resource[HTTP_MAX_URI]; /* Resource name */
   int          port;                   /* Port number */
   http_status_t        status;                 /* HTTP status from server */
-  static char  filename[HTTP_MAX_URI]; /* Local filename */
+  cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
   static const char * const requested_attrs[] =
                {                       /* Requested attributes */
                  "printer-uri-supported",
@@ -1079,7 +1081,7 @@ cupsGetPPD2(http_t     *http,             /* I - HTTP connection */
 
   if (!http || !name)
   {
-    last_error = IPP_INTERNAL_ERROR;
+    cg->last_error = IPP_INTERNAL_ERROR;
     return (NULL);
   }
 
@@ -1125,7 +1127,7 @@ cupsGetPPD2(http_t     *http,             /* I - HTTP connection */
 
   if ((response = cupsDoRequest(http, request, "/")) != NULL)
   {
-    last_error  = response->request.status.status_code;
+    cg->last_error  = response->request.status.status_code;
     printer[0]  = '\0';
     hostname[0] = '\0';
 
@@ -1176,7 +1178,7 @@ cupsGetPPD2(http_t     *http,             /* I - HTTP connection */
 
   if (!printer[0])
   {
-    last_error = IPP_NOT_FOUND;
+    cg->last_error = IPP_NOT_FOUND;
     return (NULL);
   }
 
@@ -1190,7 +1192,7 @@ cupsGetPPD2(http_t     *http,             /* I - HTTP connection */
                                        cupsEncryption())) == NULL)
   {
     DEBUG_puts("Unable to connect to server!");
-    last_error = IPP_SERVICE_UNAVAILABLE;
+    cg->last_error = IPP_SERVICE_UNAVAILABLE;
     return (NULL);
   }
 
@@ -1198,13 +1200,13 @@ cupsGetPPD2(http_t     *http,           /* I - HTTP connection */
   * Get a temp file...
   */
 
-  if ((fd = cupsTempFd(filename, sizeof(filename))) < 0)
+  if ((fd = cupsTempFd(cg->ppd_filename, sizeof(cg->ppd_filename))) < 0)
   {
    /*
     * Can't open file; close the server connection and return NULL...
     */
 
-    last_error = IPP_INTERNAL_ERROR;
+    cg->last_error = IPP_INTERNAL_ERROR;
 
     if (http2 != http)
       httpClose(http2);
@@ -1234,21 +1236,21 @@ cupsGetPPD2(http_t     *http,           /* I - HTTP connection */
     switch (status)
     {
       case HTTP_NOT_FOUND :
-          last_error = IPP_NOT_FOUND;
+          cg->last_error = IPP_NOT_FOUND;
          break;
       case HTTP_ERROR :
           DEBUG_puts("Mapping HTTP error to IPP_ERROR");
-          last_error = IPP_ERROR;
+          cg->last_error = IPP_ERROR;
          break;
       case HTTP_UNAUTHORIZED :
-          last_error = IPP_NOT_AUTHORIZED;
+          cg->last_error = IPP_NOT_AUTHORIZED;
          break;
       default :
-          last_error = IPP_INTERNAL_ERROR;
+          cg->last_error = IPP_INTERNAL_ERROR;
          break;
     }
 
-    unlink(filename);
+    unlink(cg->ppd_filename);
 
     return (NULL);
   }
@@ -1257,7 +1259,7 @@ cupsGetPPD2(http_t     *http,             /* I - HTTP connection */
   * Return the PPD file...
   */
 
-  return (filename);
+  return (cg->ppd_filename);
 }
 
 
@@ -1274,11 +1276,12 @@ cupsGetPrinters(char ***printers)       /* O - Printers */
   ipp_attribute_t *attr;               /* Current attribute */
   cups_lang_t  *language;              /* Default language */
   char         **temp;                 /* Temporary pointer */
+  cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
 
 
   if (printers == NULL)
   {
-    last_error = IPP_INTERNAL_ERROR;
+    cg->last_error = IPP_INTERNAL_ERROR;
     return (0);
   }
 
@@ -1289,7 +1292,7 @@ cupsGetPrinters(char ***printers) /* O - Printers */
   if (!cups_connect("default", NULL, NULL))
   {
     DEBUG_puts("Unable to connect to server!");
-    last_error = IPP_SERVICE_UNAVAILABLE;
+    cg->last_error = IPP_SERVICE_UNAVAILABLE;
     return (0);
   }
 
@@ -1327,9 +1330,9 @@ cupsGetPrinters(char ***printers) /* O - Printers */
   n         = 0;
   *printers = NULL;
 
-  if ((response = cupsDoRequest(cups_server, request, "/")) != NULL)
+  if ((response = cupsDoRequest(cg->http, request, "/")) != NULL)
   {
-    last_error = response->request.status.status_code;
+    cg->last_error = response->request.status.status_code;
 
     for (attr = response->attrs; attr != NULL; attr = attr->next)
       if (attr->name != NULL &&
@@ -1366,7 +1369,7 @@ cupsGetPrinters(char ***printers) /* O - Printers */
     ippDelete(response);
   }
   else
-    last_error = IPP_BAD_REQUEST;
+    cg->last_error = IPP_BAD_REQUEST;
 
   return (n);
 }
@@ -1379,9 +1382,10 @@ cupsGetPrinters(char ***printers)        /* O - Printers */
 ipp_status_t                           /* O - IPP error code */
 cupsLastError(void)
 {
-  return (last_error);
+  return (_cupsGlobals()->last_error);
 }
 
+
 /*
  * 'cupsPrintFile()' - Print a file to a printer or class.
  */
@@ -1435,6 +1439,8 @@ cupsPrintFiles(const char    *name,       /* I - Printer or class name */
                                        /* I - Number of options */
               cups_option_t *options)  /* I - Options */
 {
+  cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
+
   DEBUG_printf(("cupsPrintFiles(name=\"%s\", num_files=%d, "
                 "files=%p, title=\"%s\", num_options=%d, options=%p)\n",
                 name, num_files, files, title, num_options, options));
@@ -1449,7 +1455,7 @@ cupsPrintFiles(const char    *name,       /* I - Printer or class name */
     DEBUG_printf(("cupsPrintFiles: Unable to open connection - %s.\n",
                   strerror(errno)));
     DEBUG_puts("Unable to connect to server!");
-    last_error = IPP_SERVICE_UNAVAILABLE;
+    cg->last_error = IPP_SERVICE_UNAVAILABLE;
     return (0);
   }
 
@@ -1457,7 +1463,7 @@ cupsPrintFiles(const char    *name,       /* I - Printer or class name */
   * Print the file(s)...
   */
 
-  return (cupsPrintFiles2(cups_server, name, num_files, files, title,
+  return (cupsPrintFiles2(cg->http, name, num_files, files, title,
                           num_options, options));
 }
 
@@ -1485,6 +1491,7 @@ cupsPrintFiles2(http_t        *http,      /* I - HTTP connection */
   char         uri[HTTP_MAX_URI];      /* Printer URI */
   cups_lang_t  *language;              /* Language to use */
   int          jobid;                  /* New job ID */
+  cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
 
 
   DEBUG_printf(("cupsPrintFiles(http=%p, name=\"%s\", num_files=%d, "
@@ -1565,7 +1572,7 @@ cupsPrintFiles2(http_t        *http,      /* I - HTTP connection */
   {
     DEBUG_puts("No job ID!");
 
-    last_error = IPP_SERVICE_UNAVAILABLE;
+    cg->last_error = IPP_SERVICE_UNAVAILABLE;
 
     jobid = 0;
   }
@@ -1657,13 +1664,14 @@ cups_connect(const char *name,          /* I - Destination (printer[@host]) */
              char       *hostname)     /* O - Hostname [HTTP_MAX_URI] */
 {
   char hostbuf[HTTP_MAX_URI];          /* Name of host */
+  cups_globals_t  *cg = _cupsGlobals();        /* Pointer to library globals */
 
 
   DEBUG_printf(("cups_connect(\"%s\", %p, %p)\n", name, printer, hostname));
 
   if (name == NULL)
   {
-    last_error = IPP_BAD_REQUEST;
+    cg->last_error = IPP_BAD_REQUEST;
     return (NULL);
   }
 
@@ -1685,21 +1693,21 @@ cups_connect(const char *name,          /* I - Destination (printer[@host]) */
   else
     printer = (char *)name;
 
-  if (cups_server != NULL)
+  if (cg->http != NULL)
   {
-    if (strcasecmp(cups_server->hostname, hostname) == 0)
+    if (strcasecmp(cg->http->hostname, hostname) == 0)
       return (printer);
 
-    httpClose(cups_server);
+    httpClose(cg->http);
   }
 
   DEBUG_printf(("connecting to %s on port %d...\n", hostname, ippPort()));
 
-  if ((cups_server = httpConnectEncrypt(hostname, ippPort(),
+  if ((cg->http = httpConnectEncrypt(hostname, ippPort(),
                                         cupsEncryption())) == NULL)
   {
     DEBUG_puts("Unable to connect to server!");
-    last_error = IPP_SERVICE_UNAVAILABLE;
+    cg->last_error = IPP_SERVICE_UNAVAILABLE;
     return (NULL);
   }
   else
index b96dd924fedc172c845687759096c151d4bd538f..f83c8f336650733ae57580ae76e742d909e3dc0e 100644 (file)
@@ -68,7 +68,7 @@ OutputProlog(char  *title,    /* I - Job title */
   puts("%%DocumentSuppliedResources: procset hpgltops 1.1 0");
   puts("%%DocumentNeededResources: font Courier Helvetica");
   puts("%%Creator: hpgltops/" CUPS_SVERSION);
-  strftime(line, sizeof(line), CUPS_STRFTIME_FORMAT, curtm);
+  strftime(line, sizeof(line), "%c", curtm);
   printf("%%%%CreationDate: %s\n", line);
   printf("%%%%Title: %s\n", title);
   printf("%%%%For: %s\n", user);
index 190aeff8d05deb880d7b7c31ae6167417c3c5b7c..6ab8af9cc5eaa7d1622e39e82d10b7369555902a 100644 (file)
@@ -574,7 +574,7 @@ main(int  argc,             /* I - Number of command-line arguments */
   puts("%%DocumentData: Clean7Bit");
   puts("%%DocumentNeededResources: font Helvetica-Bold");
   puts("%%Creator: imagetops/" CUPS_SVERSION);
-  strftime(curdate, sizeof(curdate), CUPS_STRFTIME_FORMAT, curtm);
+  strftime(curdate, sizeof(curdate), "%c", curtm);
   printf("%%%%CreationDate: %s\n", curdate);
   printf("%%%%Title: %s\n", argv[3]);
   printf("%%%%For: %s\n", argv[2]);
index 473ce9b29f36dfa99e0ba583f09eb05227070e3d..5f073363f1d59582a40890c23395ac690faa0bff 100644 (file)
@@ -201,7 +201,7 @@ WriteProlog(const char *title,              /* I - Title of job */
 
   curtime = time(NULL);
   curtm   = localtime(&curtime);
-  strftime(curdate, sizeof(curdate), CUPS_STRFTIME_FORMAT, curtm);
+  strftime(curdate, sizeof(curdate), "%c", curtm);
 
   puts("%!PS-Adobe-3.0");
   printf("%%%%BoundingBox: 0 0 %.0f %.0f\n", PageWidth, PageLength);
index 7b1d7b20c6ba2fcffd023b14d8dc666d79ab2fd4..1f4fc178c786821a44809cee85f10f62ad43133c 100644 (file)
@@ -169,7 +169,7 @@ libmime.a:  $(MIMEOBJS)
 
 testmime:      testmime.o libmime.a
        echo Linking $@...
-       $(CC) $(LDFLAGS) -o $@ testmime.o libmime.a ../cups/libcups.a $(LIBZ)
+       $(CC) $(LDFLAGS) -o $@ testmime.o libmime.a ../cups/libcups.a $(COMMONLIBS) $(LIBZ)
 
 
 #
index ddca89020065b306abd5e4f1d5f07c29cba1023e..0837e1dc064dd9498cbbe3144b4bb7428c5bbb73 100644 (file)
@@ -701,7 +701,7 @@ SaveAllClasses(void)
 
   curtime = time(NULL);
   curdate = localtime(&curtime);
-  strftime(temp, sizeof(temp) - 1, CUPS_STRFTIME_FORMAT, curdate);
+  strftime(temp, sizeof(temp) - 1, "%c", curdate);
 
   cupsFilePuts(fp, "# Class configuration file for " CUPS_SVERSION "\n");
   cupsFilePrintf(fp, "# Written by cupsd on %s\n", temp);
index 5d4cbd24235b77d9de21aa5939c0333e0bb29d83..c5e63bacb8d9069e700b791c9ec4f0a1d6b95c60 100644 (file)
@@ -1211,7 +1211,7 @@ SaveAllPrinters(void)
 
   curtime = time(NULL);
   curdate = localtime(&curtime);
-  strftime(temp, sizeof(temp) - 1, CUPS_STRFTIME_FORMAT, curdate);
+  strftime(temp, sizeof(temp) - 1, "%c", curdate);
 
   cupsFilePuts(fp, "# Printer configuration file for " CUPS_SVERSION "\n");
   cupsFilePrintf(fp, "# Written by cupsd on %s\n", temp);
index 2cba9001a12a251339113739613d04928fa23615..6eae9f9ff059b4591e87f3278c83e77fc5eea052 100644 (file)
@@ -1079,7 +1079,7 @@ cupsdSaveAllSubscriptions(void)
 
   curtime = time(NULL);
   curdate = localtime(&curtime);
-  strftime(temp, sizeof(temp) - 1, CUPS_STRFTIME_FORMAT, curdate);
+  strftime(temp, sizeof(temp) - 1, "%c", curdate);
 
   cupsFilePuts(fp, "# Subscription configuration file for " CUPS_SVERSION "\n");
   cupsFilePrintf(fp, "# Written by cupsd on %s\n", temp);
index d846b4b02ba685c7870242fec7f68a63cfb3ab5d..2ad570ffd635401c67d37d8da2f5e8c25817dc16 100644 (file)
@@ -1621,7 +1621,7 @@ show_jobs(http_t     *http,               /* I - HTTP connection to server */
        }
        else
        {
-         if (!strftime(date, sizeof(date), CUPS_STRFTIME_FORMAT, jobdate))
+         if (!strftime(date, sizeof(date), "%c", jobdate))
            strcpy(date, "Unknown");
 
           if (ranking)