]> git.ipfire.org Git - thirdparty/cups-filters.git/commitdiff
libppd: Merged libppdc into libppd, *.drv support for PPD collections
authorTill Kamppeter <till.kamppeter@gmail.com>
Tue, 26 Oct 2021 17:02:59 +0000 (19:02 +0200)
committerTill Kamppeter <till.kamppeter@gmail.com>
Tue, 26 Oct 2021 17:02:59 +0000 (19:02 +0200)
CUPS PPD compiler (ppdc) was mainly ported into cups-filters to get
driver information file (*.drv) support for PPD file collections, so
that it gets easier to retro-fit CUPS drivers into Printer
Applications if the drivers provide their PPD files as a driver
information file.

In a first approach the ppdc functionality simply got added by an
additional shared library (libppdc), but this would cause circular
dependencies between libppdc and libppd. Therefore we simply merge the
two into one library.

In addition, all PPD legacy support is in a single library now.

Also note that the ppdc functions are written in C++, so you need to
declare a program which uses them as C++ (give it a *.cxx or *.cpp and
not the simple *.c file name extension), even if the program itself is
written in simple C.

The functions for handling PPD collections nw also take into account
any driver information file (*.drv) in the directories supplied to
them, in addition to the already supported static PPD files, PPD file
tarballs, and PPD-generating executables, both for enumerating
available PPDs/drivers and for loading the actual PPD files.

32 files changed:
Makefile.am
configure.ac
libppdc.pc.in [deleted file]
ppd/drv2ppd.cxx [moved from ppdc/drv2ppd.cxx with 100% similarity]
ppd/epson.h [moved from ppdc/epson.h with 100% similarity]
ppd/font.defs [moved from ppdc/font.defs with 100% similarity]
ppd/hp.h [moved from ppdc/hp.h with 100% similarity]
ppd/label.h [moved from ppdc/label.h with 100% similarity]
ppd/media.defs [moved from ppdc/media.defs with 100% similarity]
ppd/ppd-collection.cxx [moved from ppd/ppd-collection.c with 90% similarity]
ppd/ppdc-array.cxx [moved from ppdc/ppdc-array.cxx with 100% similarity]
ppd/ppdc-attr.cxx [moved from ppdc/ppdc-attr.cxx with 100% similarity]
ppd/ppdc-catalog.cxx [moved from ppdc/ppdc-catalog.cxx with 100% similarity]
ppd/ppdc-choice.cxx [moved from ppdc/ppdc-choice.cxx with 100% similarity]
ppd/ppdc-constraint.cxx [moved from ppdc/ppdc-constraint.cxx with 100% similarity]
ppd/ppdc-driver.cxx [moved from ppdc/ppdc-driver.cxx with 96% similarity]
ppd/ppdc-file.cxx [moved from ppdc/ppdc-file.cxx with 100% similarity]
ppd/ppdc-filter.cxx [moved from ppdc/ppdc-filter.cxx with 100% similarity]
ppd/ppdc-font.cxx [moved from ppdc/ppdc-font.cxx with 100% similarity]
ppd/ppdc-group.cxx [moved from ppdc/ppdc-group.cxx with 100% similarity]
ppd/ppdc-import.cxx [moved from ppdc/ppdc-import.cxx with 100% similarity]
ppd/ppdc-mediasize.cxx [moved from ppdc/ppdc-mediasize.cxx with 100% similarity]
ppd/ppdc-message.cxx [moved from ppdc/ppdc-message.cxx with 100% similarity]
ppd/ppdc-option.cxx [moved from ppdc/ppdc-option.cxx with 100% similarity]
ppd/ppdc-private.h [moved from ppdc/ppdc-private.h with 100% similarity]
ppd/ppdc-profile.cxx [moved from ppdc/ppdc-profile.cxx with 100% similarity]
ppd/ppdc-shared.cxx [moved from ppdc/ppdc-shared.cxx with 100% similarity]
ppd/ppdc-source.cxx [moved from ppdc/ppdc-source.cxx with 100% similarity]
ppd/ppdc-string.cxx [moved from ppdc/ppdc-string.cxx with 100% similarity]
ppd/ppdc-variable.cxx [moved from ppdc/ppdc-variable.cxx with 100% similarity]
ppd/ppdc.h [moved from ppdc/ppdc.h with 100% similarity]
ppd/raster.defs [moved from ppdc/raster.defs with 100% similarity]

index 510d36ca96f04125fcbc8b25bbcdad4e1bdbb3b9..e1e8f3c5851266424dcee7daa43681666f36300f 100644 (file)
@@ -5,10 +5,6 @@ pkgconf_DATA = \
        libcupsfilters.pc \
        libppd.pc \
        libfontembed.pc
-if ENABLE_LIBPPDC
-pkgconf_DATA += \
-       libppdc.pc
-endif
 
 doc_DATA = \
        ABOUT-NLS \
@@ -25,7 +21,6 @@ EXTRA_DIST = \
        ln-srf \
        libcupsfilters.pc.in \
        libppd.pc.in \
-       libppdc.pc.in \
        libfontembed.pc.in \
        utils/cups-browsed.service \
        utils/cups-browsed-upstart.conf \
@@ -171,8 +166,18 @@ EXTRA_DIST += $(pkgcharset_DATA)
 pkgppdincludedir = $(includedir)/ppd
 pkgppdinclude_DATA = \
        ppd/ppd.h \
+       ppd/ppdc.h \
        cupsfilters/log.h
 
+pkgppddefsdir = $(datadir)/ppdc
+pkgppddefs_DATA = \
+       ppd/epson.h \
+       ppd/hp.h \
+       ppd/label.h \
+       ppd/font.defs \
+       ppd/media.defs \
+       ppd/raster.defs
+
 lib_LTLIBRARIES = libppd.la
 
 check_PROGRAMS = \
@@ -184,7 +189,7 @@ libppd_la_SOURCES = \
        ppd/ppd-attr.c \
        ppd/ppd.c \
        ppd/ppd-cache.c \
-       ppd/ppd-collection.c \
+       ppd/ppd-collection.cxx \
        ppd/ppd-conflicts.c \
        ppd/ppd-custom.c \
        ppd/ppd-emit.c \
@@ -211,7 +216,28 @@ libppd_la_SOURCES = \
        ppd/string-private.h \
        ppd/thread.c \
        ppd/thread-private.h \
-       $(pkgppdinclude_DATA)
+       ppd/ppdc-array.cxx \
+       ppd/ppdc-attr.cxx \
+       ppd/ppdc-catalog.cxx \
+       ppd/ppdc-choice.cxx \
+       ppd/ppdc-constraint.cxx \
+       ppd/ppdc-driver.cxx \
+       ppd/ppdc-file.cxx \
+       ppd/ppdc-filter.cxx \
+       ppd/ppdc-font.cxx \
+       ppd/ppdc-group.cxx \
+       ppd/ppdc-import.cxx \
+       ppd/ppdc-mediasize.cxx \
+       ppd/ppdc-message.cxx \
+       ppd/ppdc-option.cxx \
+       ppd/ppdc-private.h \
+       ppd/ppdc-profile.cxx \
+       ppd/ppdc-shared.cxx \
+       ppd/ppdc-source.cxx \
+       ppd/ppdc-string.cxx \
+       ppd/ppdc-variable.cxx \
+       $(pkgppdinclude_DATA) \
+       $(pkgppddefs_DATA)
 libppd_la_LIBADD = \
        $(CUPS_LIBS)
 libppd_la_CFLAGS = \
@@ -230,68 +256,9 @@ EXTRA_DIST += \
        ppd/test2.ppd \
        ppd/README.md
 
-# ===========================
-# PPDC legacy support library
-# ===========================
-pkgppdcincludefiles = \
-       ppdc/ppdc.h
-
-pkgppdcdefsfiles = \
-       ppdc/epson.h \
-       ppdc/hp.h \
-       ppdc/label.h \
-       ppdc/font.defs \
-       ppdc/media.defs \
-       ppdc/raster.defs
-
-if ENABLE_LIBPPDC
-pkgppdcincludedir = $(includedir)/ppdc
-pkgppdcinclude_DATA = \
-       $(pkgppdcincludefiles)
-pkgppdcdefsdir = $(datadir)/ppdc
-pkgppdcdefs_DATA = \
-       $(pkgppdcdefsfiles)
-lib_LTLIBRARIES += libppdc.la
-endif
-
-libppdc_la_SOURCES = \
-       ppdc/ppdc-array.cxx \
-       ppdc/ppdc-attr.cxx \
-       ppdc/ppdc-catalog.cxx \
-       ppdc/ppdc-choice.cxx \
-       ppdc/ppdc-constraint.cxx \
-       ppdc/ppdc-driver.cxx \
-       ppdc/ppdc-file.cxx \
-       ppdc/ppdc-filter.cxx \
-       ppdc/ppdc-font.cxx \
-       ppdc/ppdc-group.cxx \
-       ppdc/ppdc-import.cxx \
-       ppdc/ppdc-mediasize.cxx \
-       ppdc/ppdc-message.cxx \
-       ppdc/ppdc-option.cxx \
-       ppdc/ppdc-private.h \
-       ppdc/ppdc-profile.cxx \
-       ppdc/ppdc-shared.cxx \
-       ppdc/ppdc-source.cxx \
-       ppdc/ppdc-string.cxx \
-       ppdc/ppdc-variable.cxx \
-       $(pkgppdcincludefiles) \
-       $(pkgppdcdefsfiles)
-libppdc_la_LIBADD = \
-       libcupsfilters.la \
-       libppd.la \
-       $(CUPS_LIBS)
-libppdc_la_CFLAGS = \
-       -I$(srcdir)/cupsfilters/ \
-       -I$(srcdir)/ppd/ \
-       $(CUPS_CFLAGS)
-libppdc_la_LDFLAGS = \
-       -no-undefined \
-       -version-info 1
-
-EXTRA_DIST += \
-       $(pkgppdcincludefiles) \
-       $(pkgppdcdefsfiles)
+# =========================
+# ppdc PPD compiler utility
+# =========================
 
 if ENABLE_PPDC
 pkgutils_PROGRAMS += \
@@ -299,12 +266,12 @@ pkgutils_PROGRAMS += \
 endif
 
 drv2ppd_SOURCES = \
-       ppdc/drv2ppd.cxx
+       ppd/drv2ppd.cxx
 drv2ppd_LDADD = \
-       libppdc.la \
+       libppd.la \
        $(CUPS_LIBS)
 drv2ppd_CFLAGS = \
-       -I$(srcdir)/ppdc/ \
+       -I$(srcdir)/ppd/ \
        $(CUPS_CFLAGS)
 
 # =================
@@ -1252,11 +1219,9 @@ if ENABLE_DRIVERLESS
        $(LN_SRF) $(DESTDIR)$(pkgppdgendir)/driverless-fax $(DESTDIR)$(bindir)
        $(LN_SRF) $(DESTDIR)$(pkgppdgendir)/driverless-fax $(DESTDIR)$(pkgbackenddir)
 endif
-if ENABLE_LIBPPDC
 if ENABLE_PPDC
        $(LN_SRF) $(DESTDIR)$(bindir)/drv2ppd $(DESTDIR)$(bindir)/ppdc
 endif
-endif
 if ENABLE_BRAILLE
        $(LN_S) -f imagetobrf $(DESTDIR)$(pkgfilterdir)/imagetoubrl
        $(LN_S) -f vectortopdf $(DESTDIR)$(pkgfilterdir)/svgtopdf
@@ -1304,11 +1269,9 @@ if ENABLE_DRIVERLESS
        $(RM) $(DESTDIR)$(bindir)/driverless-fax
        $(RM) $(DESTDIR)$(pkgbackenddir)/driverless-fax
 endif
-if ENABLE_LIBPPDC
 if ENABLE_PPDC
        $(RM) $(DESTDIR)$(bindir)/ppdc
 endif
-endif
 if ENABLE_BRAILLE
        $(RM) $(DESTDIR)$(pkgfilterdir)/imagetoubrl
        $(RM) $(DESTDIR)$(pkgfilterdir)/svgtopdf
index 07f3ed3f1e4fdb632d133f7b9cc8cd96431430e2..574b568e4712186c576da9683f8f12cbf2864c02 100644 (file)
@@ -177,13 +177,6 @@ else
        fi
 fi
 
-AC_ARG_ENABLE([libppdc], [AS_HELP_STRING([--enable-libppdc], [enable libppdc, to handle driver information files (*.drv).])],
-        [enable_libppdc="$enableval"],
-        [enable_libppdc=yes]
-)
-AM_CONDITIONAL([ENABLE_LIBPPDC],
-[test "x$enable_libppdc" != "xno"])
-
 # Do not overwrite a ppdc which is already there from CUPS, in this case
 # default to not include a ppdc utility
 if test ! -e "$bindir/ppdc" || test -h "$bindir/ppdc"; then
@@ -195,9 +188,6 @@ AC_ARG_ENABLE([ppdc], [AS_HELP_STRING([--enable-ppdc], [enable ppdc utility, to
         [enable_ppdc="$enableval"],
         [enable_ppdc="$no_cups_ppdc"]
 )
-if test "x$enable_libppdc" = "xno"; then
-       enable_ppdc=no
-fi
 AM_CONDITIONAL([ENABLE_PPDC],
 [test "x$enable_ppdc" != "xno"])
 
@@ -957,7 +947,6 @@ fi
 AC_CONFIG_FILES([
        libcupsfilters.pc
        libppd.pc
-       libppdc.pc
        libfontembed.pc
        Makefile
        utils/cups-browsed
@@ -1028,7 +1017,6 @@ Build configuration:
        driverless:      ${enable_driverless}
        apple-raster:    ${APPLE_RASTER_FILTER}
        pclm:            ${enable_pclm}
-       libppdc:         ${enable_libppdc}
        ppdc:            ${enable_ppdc}
        local queue naming for remote CUPS queues: ${REMOTE_CUPS_LOCAL_QUEUE_NAMING}
        keep generated queues during shutdown:     ${SAVING_CREATED_QUEUES}
diff --git a/libppdc.pc.in b/libppdc.pc.in
deleted file mode 100644 (file)
index 8bd44b7..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-prefix=@prefix@
-exec_prefix=@exec_prefix@
-libdir=@libdir@
-includedir=@includedir@
-                                                                       
-Name: libppdc
-Description: Library for generating PPD files from *.drv files
-Version: @VERSION@
-
-Libs: -L${libdir} -lppdc
-Libs.private: @CUPS_LIBS@ -lcupsfilters -lppd
-Cflags: -I${includedir}/ppdc
similarity index 100%
rename from ppdc/drv2ppd.cxx
rename to ppd/drv2ppd.cxx
similarity index 100%
rename from ppdc/epson.h
rename to ppd/epson.h
similarity index 100%
rename from ppdc/font.defs
rename to ppd/font.defs
similarity index 100%
rename from ppdc/hp.h
rename to ppd/hp.h
similarity index 100%
rename from ppdc/label.h
rename to ppd/label.h
similarity index 100%
rename from ppdc/media.defs
rename to ppd/media.defs
similarity index 90%
rename from ppd/ppd-collection.c
rename to ppd/ppd-collection.cxx
index b1734dd853860fcb03392b135318f2212474af48..3892509475f14387739f58eeb9b631b327177653 100644 (file)
@@ -19,6 +19,7 @@
 #include <cups/dir.h>
 #include <cups/transcode.h>
 #include "ppd.h"
+#include "ppdc.h"
 #include "file-private.h"
 #include "array-private.h"
 #include <regex.h>
@@ -118,6 +119,8 @@ static ppd_info_t   *add_ppd(const char *filename, const char *name,
                                 size_t size, int model_number, int type,
                                 const char *scheme, ppd_list_t *ppdlist,
                                 filter_logfunc_t log, void *ld);
+static cups_file_t     *cat_drv(const char *name, char *ppdname,
+                                filter_logfunc_t log, void *ld);
 static cups_file_t     *cat_static(const char *name,
                                    filter_logfunc_t log, void *ld);
 static cups_file_t     *cat_tar(const char *name, char *ppdname,
@@ -135,6 +138,10 @@ static int         load_driver(const char *filename,
                                    const char *name,
                                    ppd_list_t *ppdlist,
                                    filter_logfunc_t log, void *ld);
+static int             load_drv(const char *filename, const char *name,
+                                cups_file_t *fp, time_t mtime, off_t size,
+                                ppd_list_t *ppdlist,
+                                filter_logfunc_t log, void *ld);
 static void            load_ppd(const char *filename, const char *name,
                                 const char *scheme, struct stat *fileinfo,
                                 ppd_info_t *ppd, cups_file_t *fp, off_t end,
@@ -624,6 +631,7 @@ ppdCollectionGetPPD(
   int          pid;
   int          bytes;
   int           is_archive = 0;
+  int           is_drv = 0;
   char         realname[1024],         /* Scheme from PPD name */
                buffer[8192],           /* Copy buffer */
                tempname[1024],         /* Temp file name */
@@ -645,6 +653,8 @@ ppdCollectionGetPPD(
 
   if (strstr(name, ".tar:") || strstr(name, ".tar.gz:"))
     is_archive = 1;
+  else if (strstr(name, ".drv:"))
+    is_drv = 1;
 
   if (ppd_collections)
   {
@@ -671,7 +681,7 @@ ppdCollectionGetPPD(
        ppdname = NULL;
       else
       {
-       if (!is_archive)
+       if (!is_archive && !is_drv)
          strlcpy(ppduri, realname, sizeof(ppduri));
        *ptr = '\0';
        ppdname = ptr + 1;
@@ -695,7 +705,7 @@ ppdCollectionGetPPD(
       ppdname = NULL;
     else
     {
-      if (!is_archive)
+      if (!is_archive && !is_drv)
        strlcpy(ppduri, realname, sizeof(ppduri));
       *ptr = '\0';
       ppdname = ptr + 1;
@@ -711,6 +721,8 @@ ppdCollectionGetPPD(
 
   if (is_archive)
     return(cat_tar(realname, ppdname, log, ld));
+  else if (is_drv)
+    return(cat_drv(realname, ppdname, log, ld));
   else if (ppdname == NULL)
     return(cat_static(realname, log, ld));
   else
@@ -916,6 +928,96 @@ add_ppd(const char *filename,              /* I - PPD filename */
 }
 
 
+/*
+ * 'cat_drv()' - Generate a PPD from a driver info file.
+ */
+
+static cups_file_t *                   /* O - Pointer to PPD file */
+cat_drv(const char *filename,          /* I - *.drv file name */
+       char *ppdname,                  /* I - PPD name in the *.drv file */
+       filter_logfunc_t log,           /* I - Log function */
+       void *ld)                       /* I - Aux. data for log function */
+{
+  cups_file_t  *fp;                    // File pointer
+  int          fd;
+  char         tempname[1024];         // Name for the temporary file
+  ppdcSource   *src;                   // PPD source file data
+  ppdcDriver   *d;                     // Current driver
+  cups_file_t  *out;                   // PPD output to temp file
+
+  if ((fp = cupsFileOpen(filename, "r")) == NULL)
+  {
+    if (log) log(ld, FILTER_LOGLEVEL_ERROR,
+                "libppd: [PPD Collections] Unable to open \"%s\" - %s\n",
+                filename, strerror(errno));
+
+    return (NULL);
+  }
+
+  src = new ppdcSource(filename, fp);
+
+  for (d = (ppdcDriver *)src->drivers->first();
+       d;
+       d = (ppdcDriver *)src->drivers->next())
+    if (!strcmp(ppdname, d->pc_file_name->value) ||
+        (d->file_name && !strcmp(ppdname, d->file_name->value)))
+      break;
+
+  if (d)
+  {
+    ppdcArray  *locales;               // Locale names
+    ppdcCatalog        *catalog;               // Message catalog in .drv file
+
+
+    if (log) log(ld, FILTER_LOGLEVEL_DEBUG,
+                "libppd: [PPD Collections] %u locales defined in \"%s\"...\n",
+                (unsigned)src->po_files->count, filename);
+
+    locales = new ppdcArray();
+    for (catalog = (ppdcCatalog *)src->po_files->first();
+         catalog;
+        catalog = (ppdcCatalog *)src->po_files->next())
+    {
+      if (log) log(ld, FILTER_LOGLEVEL_DEBUG,
+                  "libppd: [PPD Collections] Adding locale \"%s\"...\n",
+                  catalog->locale->value);
+      catalog->locale->retain();
+      locales->add(catalog->locale);
+    }
+
+    if ((fd = cupsTempFd(tempname, sizeof(tempname))) < 0)
+    {
+      if (log) log(ld, FILTER_LOGLEVEL_ERROR,
+                  "libppd: [PPD Collections] Unable to copy PPD to temp "
+                  "file: %s",
+                  strerror(errno));
+      return (NULL);
+    }
+    out = cupsFileOpenFd(fd, "w");
+    d->write_ppd_file(out, NULL, locales, src, PPDC_LFONLY);
+    cupsFileClose(out);
+    close(fd);
+    locales->release();
+    src->release();
+    cupsFileClose(fp);
+
+    out = cupsFileOpen(tempname, "r");
+    unlink(tempname);
+
+    return(out);
+
+  }
+  else
+    if (log) log(ld, FILTER_LOGLEVEL_ERROR,
+                "libppd: [PPD Collections] PPD \"%s\" not found.\n", ppdname);
+
+  src->release();
+  cupsFileClose(fp);
+
+  return (NULL);
+}
+
+
 /*
  * 'cat_static()' - Return pointer to static PPD file
  */
@@ -941,7 +1043,7 @@ cat_static(const char *name,               /* I - PPD name */
 
 
 /*
- * 'cat_tar()' - Copy an archived PPD file to stdout.
+ * 'cat_tar()' - Copy an archived PPD file to temp file.
  */
 
 static cups_file_t *                   /* O - Pointer to PPD file */
@@ -1328,6 +1430,139 @@ load_driver(const char *filename,       /* I - Driver excutable file name */
 }
 
 
+/*
+ * 'load_drv()' - Load the PPDs from a driver information file.
+ */
+
+static int                             /* O - 1 on success, 0 on failure */
+load_drv(const char  *filename,                /* I - Actual filename */
+         const char  *name,            /* I - Name to the rest of the world */
+         cups_file_t *fp,              /* I - File to read from */
+        time_t      mtime,             /* I - Mod time of driver info file */
+        off_t       size,              /* I - Size of driver info file */
+        ppd_list_t  *ppdlist,
+        filter_logfunc_t log,          /* I - Log function */
+        void *ld)                      /* I - Aux. data for log function */
+{
+  ppdcSource   *src;                   // Driver information file
+  ppdcDriver   *d;                     // Current driver
+  ppdcAttr     *device_id,             // 1284DeviceID attribute
+               *product,               // Current product value
+               *ps_version,            // PSVersion attribute
+               *cups_fax,              // cupsFax attribute
+               *nick_name;             // NickName attribute
+  ppdcFilter   *filter;                // Current filter
+  ppd_info_t   *ppd;                   // Current PPD
+  int          products_found;         // Number of products found
+  char         uri[2048],              // Driver URI
+               make_model[1024];       // Make and model
+  int          type;                   // Driver type
+
+
+ /*
+  * Load the driver info file...
+  */
+
+  src = new ppdcSource(filename, fp);
+
+  if (src->drivers->count == 0)
+  {
+    if (log) log(ld, FILTER_LOGLEVEL_ERROR,
+                "libppd: [PPD Collections] Bad driver information file \"%s\"!\n",
+                filename);
+    src->release();
+    return (0);
+  }
+
+ /*
+  * Add a dummy entry for the file...
+  */
+
+  add_ppd(filename, name, "", "", "", "", "", "", mtime, (size_t)size, 0,
+         PPD_TYPE_DRV, "drv", ppdlist, log, ld);
+
+ /*
+  * Then the drivers in the file...
+  */
+
+  for (d = (ppdcDriver *)src->drivers->first();
+       d;
+       d = (ppdcDriver *)src->drivers->next())
+  {
+    snprintf(uri, sizeof(uri), "%s:%s", name,
+            d->file_name ? d->file_name->value :
+            d->pc_file_name->value);
+
+    device_id  = d->find_attr("1284DeviceID", NULL);
+    ps_version = d->find_attr("PSVersion", NULL);
+    nick_name  = d->find_attr("NickName", NULL);
+
+    if (nick_name)
+      strncpy(make_model, nick_name->value->value, sizeof(make_model) - 1);
+    else if (strncasecmp(d->model_name->value, d->manufacturer->value,
+                         strlen(d->manufacturer->value)))
+      snprintf(make_model, sizeof(make_model), "%s %s, %s",
+               d->manufacturer->value, d->model_name->value,
+              d->version->value);
+    else
+      snprintf(make_model, sizeof(make_model), "%s, %s", d->model_name->value,
+               d->version->value);
+
+    if ((cups_fax = d->find_attr("cupsFax", NULL)) != NULL &&
+        !strcasecmp(cups_fax->value->value, "true"))
+      type = PPD_TYPE_FAX;
+    else if (d->type == PPDC_DRIVER_PS)
+      type = PPD_TYPE_POSTSCRIPT;
+    else if (d->type != PPDC_DRIVER_CUSTOM)
+      type = PPD_TYPE_RASTER;
+    else
+    {
+      for (filter = (ppdcFilter *)d->filters->first(),
+               type = PPD_TYPE_POSTSCRIPT;
+          filter;
+          filter = (ppdcFilter *)d->filters->next())
+        if (strcasecmp(filter->mime_type->value, "application/vnd.cups-raster"))
+         type = PPD_TYPE_RASTER;
+        else if (strcasecmp(filter->mime_type->value,
+                           "application/vnd.cups-pdf"))
+         type = PPD_TYPE_PDF;
+    }
+
+    for (product = (ppdcAttr *)d->attrs->first(), products_found = 0,
+             ppd = NULL;
+         product;
+        product = (ppdcAttr *)d->attrs->next())
+      if (!strcmp(product->name->value, "Product"))
+      {
+        if (!products_found)
+         ppd = add_ppd(filename, uri, "en", d->manufacturer->value,
+                       make_model, device_id ? device_id->value->value : "",
+                       product->value->value,
+                       ps_version ? ps_version->value->value : "(3010) 0",
+                       mtime, (size_t)size, d->model_number, type, "drv",
+                       ppdlist, log, ld);
+       else if (products_found < PPD_MAX_PROD)
+         strncpy(ppd->record.products[products_found], product->value->value,
+                 sizeof(ppd->record.products[0]));
+       else
+         break;
+
+       products_found ++;
+      }
+
+    if (!products_found)
+      add_ppd(filename, uri, "en", d->manufacturer->value, make_model,
+             device_id ? device_id->value->value : "", d->model_name->value,
+             ps_version ? ps_version->value->value : "(3010) 0", mtime,
+             (size_t)size, d->model_number, type, "drv", ppdlist, log, ld);
+  }
+
+  src->release();
+
+  return (1);
+}
+
+
 /*
  * 'load_ppd()' - Load a PPD file.
  */
@@ -1944,7 +2179,8 @@ load_ppds(const char *d,          /* I - Actual directory */
     else
     {
      /*
-      * Nope, treat it as a an archive or PPD-generating executable...
+      * Nope, treat it as a an archive, a PPD-generating executable, or a
+      * driver information file...
       */
 
       cupsFileRewind(fp);
@@ -1953,6 +2189,9 @@ load_ppds(const char *d,          /* I - Actual directory */
           (!strcmp(ptr, ".tar") || !strcmp(ptr, ".tar.gz")))
         load_tar(filename, name, fp, dent->fileinfo.st_mtime,
                  dent->fileinfo.st_size, ppdlist, log, ld);
+      else if ((ptr = strstr(filename, ".drv")) != NULL && !strcmp(ptr, ".drv"))
+       load_drv(filename, name, fp, dent->fileinfo.st_mtime,
+                dent->fileinfo.st_size, ppdlist, log, ld);
       else if ((dent->fileinfo.st_mode & 0111) &&
               S_ISREG(dent->fileinfo.st_mode))
       {
similarity index 100%
rename from ppdc/ppdc-array.cxx
rename to ppd/ppdc-array.cxx
similarity index 100%
rename from ppdc/ppdc-attr.cxx
rename to ppd/ppdc-attr.cxx
similarity index 100%
rename from ppdc/ppdc-catalog.cxx
rename to ppd/ppdc-catalog.cxx
similarity index 100%
rename from ppdc/ppdc-choice.cxx
rename to ppd/ppdc-choice.cxx
similarity index 96%
rename from ppdc/ppdc-driver.cxx
rename to ppd/ppdc-driver.cxx
index 2cc77c7ecbb12a29c40c9e349ffdd45fdede7be9..d8f9df83d43718258610cf0196e1629c5a53b8d7 100644 (file)
@@ -13,7 +13,7 @@
 //
 
 #include "ppdc-private.h"
-#include <cupsfilters/ppdgenerator.h>
+#include "string-private.h"
 
 
 //
@@ -603,8 +603,7 @@ ppdcDriver::write_ppd_file(
     if ((a = find_attr("cupsVersion", NULL)) != NULL)
       cupsFilePrintf(fp, "*cupsVersion: %s%s", a->value->value, lf);
     else
-      cupsFilePrintf(fp, "*cupsVersion: %d.%d%s", CUPS_VERSION_MAJOR,
-                    CUPS_VERSION_MINOR, lf);
+      cupsFilePrintf(fp, "*cupsVersion: %s%s", PACKAGE_VERSION, lf);
     cupsFilePrintf(fp, "*cupsModelNumber: %d%s", model_number, lf);
     cupsFilePrintf(fp, "*cupsManualCopies: %s%s",
                    manual_copies ? "True" : "False", lf);
@@ -661,11 +660,11 @@ ppdcDriver::write_ppd_file(
     {
       char density[255], gamma[255], profile[9][255];
 
-      cfStrFormatd(density, density + sizeof(density), p->density, loc);
-      cfStrFormatd(gamma, gamma + sizeof(gamma), p->gamma, loc);
+      _ppdStrFormatd(density, density + sizeof(density), p->density, loc);
+      _ppdStrFormatd(gamma, gamma + sizeof(gamma), p->gamma, loc);
 
       for (int i = 0; i < 9; i ++)
-       cfStrFormatd(profile[i], profile[i] + sizeof(profile[0]),
+       _ppdStrFormatd(profile[i], profile[i] + sizeof(profile[0]),
                        p->profile[i], loc);
 
       cupsFilePrintf(fp,
@@ -864,10 +863,10 @@ ppdcDriver::write_ppd_file(
        m;
        m = (ppdcMediaSize *)sizes->next())
   {
-    cfStrFormatd(left, left + sizeof(left), m->left, loc);
-    cfStrFormatd(bottom, bottom + sizeof(bottom), m->bottom, loc);
-    cfStrFormatd(right, right + sizeof(right), m->width - m->right, loc);
-    cfStrFormatd(top, top + sizeof(top), m->length - m->top, loc);
+    _ppdStrFormatd(left, left + sizeof(left), m->left, loc);
+    _ppdStrFormatd(bottom, bottom + sizeof(bottom), m->bottom, loc);
+    _ppdStrFormatd(right, right + sizeof(right), m->width - m->right, loc);
+    _ppdStrFormatd(top, top + sizeof(top), m->length - m->top, loc);
 
     cupsFilePrintf(fp, "*ImageableArea %s/%s: \"%s %s %s %s\"%s",
                    m->name->value, catalog->find_message(m->text->value),
@@ -893,8 +892,8 @@ ppdcDriver::write_ppd_file(
        m;
        m = (ppdcMediaSize *)sizes->next())
   {
-    cfStrFormatd(width, width + sizeof(width), m->width, loc);
-    cfStrFormatd(length, length + sizeof(length), m->length, loc);
+    _ppdStrFormatd(width, width + sizeof(width), m->width, loc);
+    _ppdStrFormatd(length, length + sizeof(length), m->length, loc);
 
     cupsFilePrintf(fp, "*PaperDimension %s/%s: \"%s %s\"%s",
                    m->name->value, catalog->find_message(m->text->value),
@@ -913,13 +912,13 @@ ppdcDriver::write_ppd_file(
   // Custom size support...
   if (variable_paper_size)
   {
-    cfStrFormatd(width, width + sizeof(width), max_width, loc);
-    cfStrFormatd(length, length + sizeof(length), max_length, loc);
+    _ppdStrFormatd(width, width + sizeof(width), max_width, loc);
+    _ppdStrFormatd(length, length + sizeof(length), max_length, loc);
 
-    cfStrFormatd(left, left + sizeof(left), left_margin, loc);
-    cfStrFormatd(bottom, bottom + sizeof(bottom), bottom_margin, loc);
-    cfStrFormatd(right, right + sizeof(right), right_margin, loc);
-    cfStrFormatd(top, top + sizeof(top), top_margin, loc);
+    _ppdStrFormatd(left, left + sizeof(left), left_margin, loc);
+    _ppdStrFormatd(bottom, bottom + sizeof(bottom), bottom_margin, loc);
+    _ppdStrFormatd(right, right + sizeof(right), right_margin, loc);
+    _ppdStrFormatd(top, top + sizeof(top), top_margin, loc);
 
     cupsFilePrintf(fp, "*MaxMediaWidth: \"%s\"%s", width, lf);
     cupsFilePrintf(fp, "*MaxMediaHeight: \"%s\"%s", length, lf);
@@ -947,8 +946,8 @@ ppdcDriver::write_ppd_file(
     {
       char width0[255];
 
-      cfStrFormatd(width0, width0 + sizeof(width0), min_width, loc);
-      cfStrFormatd(width, width + sizeof(width), max_width, loc);
+      _ppdStrFormatd(width0, width0 + sizeof(width0), min_width, loc);
+      _ppdStrFormatd(width, width + sizeof(width), max_width, loc);
 
       cupsFilePrintf(fp, "*ParamCustomPageSize Width: 1 points %s %s%s",
                      width0, width, lf);
@@ -961,8 +960,8 @@ ppdcDriver::write_ppd_file(
     {
       char length0[255];
 
-      cfStrFormatd(length0, length0 + sizeof(length0), min_length, loc);
-      cfStrFormatd(length, length + sizeof(length), max_length, loc);
+      _ppdStrFormatd(length0, length0 + sizeof(length0), min_length, loc);
+      _ppdStrFormatd(length, length + sizeof(length), max_length, loc);
 
       cupsFilePrintf(fp, "*ParamCustomPageSize Height: 2 points %s %s%s",
                      length0, length, lf);
@@ -1034,7 +1033,7 @@ ppdcDriver::write_ppd_file(
       }
 
       char order[255];
-      cfStrFormatd(order, order + sizeof(order), o->order, loc);
+      _ppdStrFormatd(order, order + sizeof(order), o->order, loc);
 
       cupsFilePrintf(fp, "*OrderDependency: %s ", order);
       switch (o->section)
similarity index 100%
rename from ppdc/ppdc-file.cxx
rename to ppd/ppdc-file.cxx
similarity index 100%
rename from ppdc/ppdc-filter.cxx
rename to ppd/ppdc-filter.cxx
similarity index 100%
rename from ppdc/ppdc-font.cxx
rename to ppd/ppdc-font.cxx
similarity index 100%
rename from ppdc/ppdc-group.cxx
rename to ppd/ppdc-group.cxx
similarity index 100%
rename from ppdc/ppdc-import.cxx
rename to ppd/ppdc-import.cxx
similarity index 100%
rename from ppdc/ppdc-message.cxx
rename to ppd/ppdc-message.cxx
similarity index 100%
rename from ppdc/ppdc-option.cxx
rename to ppd/ppdc-option.cxx
similarity index 100%
rename from ppdc/ppdc-private.h
rename to ppd/ppdc-private.h
similarity index 100%
rename from ppdc/ppdc-profile.cxx
rename to ppd/ppdc-profile.cxx
similarity index 100%
rename from ppdc/ppdc-shared.cxx
rename to ppd/ppdc-shared.cxx
similarity index 100%
rename from ppdc/ppdc-source.cxx
rename to ppd/ppdc-source.cxx
similarity index 100%
rename from ppdc/ppdc-string.cxx
rename to ppd/ppdc-string.cxx
similarity index 100%
rename from ppdc/ppdc-variable.cxx
rename to ppd/ppdc-variable.cxx
similarity index 100%
rename from ppdc/ppdc.h
rename to ppd/ppdc.h
similarity index 100%
rename from ppdc/raster.defs
rename to ppd/raster.defs