]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - ppdc/ppdc-import.cxx
License change: Apache License, Version 2.0.
[thirdparty/cups.git] / ppdc / ppdc-import.cxx
index 486f9b72c43edcbf5d4677dc91e5996feec5b2d8..04b587d7ff6d398a00c30630792855ecf74fdf03 100644 (file)
@@ -1,28 +1,17 @@
 //
-// "$Id$"
+// PPD file import methods for the CUPS PPD Compiler.
 //
-//   PPD file import methods for the CUPS PPD Compiler.
+// Copyright 2007-2011 by Apple Inc.
+// Copyright 2002-2006 by Easy Software Products.
 //
-//   Copyright 2007 by Apple Inc.
-//   Copyright 2002-2006 by Easy Software Products.
-//
-//   These coded instructions, statements, and computer programs are the
-//   property of Apple Inc. and are protected by Federal copyright
-//   law.  Distribution and use rights are outlined in the file "LICENSE.txt"
-//   which should have been included with this file.  If this file is
-//   file is missing or damaged, see the license at "http://www.cups.org/".
-//
-// Contents:
-//
-//   ppdcSource::import_ppd() - Import a PPD file.
-//   ppd_gets()               - Get a line from a PPD file.
+// Licensed under Apache License v2.0.  See the file "LICENSE" for more information.
 //
 
 //
 // Include necessary headers...
 //
 
-#include "ppdc.h"
+#include "ppdc-private.h"
 #include <cups/ppd.h>
 
 
@@ -37,6 +26,7 @@ ppdcSource::import_ppd(const char *f) // I - Filename
   cups_file_t  *fp;                    // File
   char         line[256],              // Comment line
                *ptr;                   // Pointer into line
+  int          cost;                   // Cost for filter
   ppd_file_t   *ppd;                   // PPD file data
   ppd_group_t  *group;                 // PPD group
   ppd_option_t *option;                // PPD option
@@ -46,6 +36,7 @@ ppdcSource::import_ppd(const char *f) // I - Filename
   ppd_const_t  *constraint2;           // Temp PPD UI constraint
   ppd_size_t   *size;                  // PPD page size
   ppdcDriver   *driver;                // Driver
+  ppdcFilter   *filter;                // Current filter
   ppdcFont     *font;                  // Font
   ppdcGroup    *cgroup;                // UI group
   ppdcOption   *coption;               // UI option
@@ -88,7 +79,7 @@ ppdcSource::import_ppd(const char *f) // I - Filename
     while (cupsFileGets(fp, line, sizeof(line)))
       if (strncmp(line, "*%", 2))
         break;
-      else
+      else if (strncmp(line, "*%%%% ", 6))
       {
         for (ptr = line + 2; isspace(*ptr); ptr ++);
 
@@ -99,7 +90,7 @@ ppdcSource::import_ppd(const char *f) // I - Filename
 
     // Then add the stuff from the PPD file...
     if (ppd->modelname && ppd->manufacturer &&
-        !strncasecmp(ppd->modelname, ppd->manufacturer,
+        !_cups_strncasecmp(ppd->modelname, ppd->manufacturer,
                      strlen(ppd->manufacturer)))
     {
       ptr = ppd->modelname + strlen(ppd->manufacturer);
@@ -110,15 +101,49 @@ ppdcSource::import_ppd(const char *f)     // I - Filename
     else
       ptr = ppd->modelname;
 
-    driver->manufacturer  = new ppdcString(ppd->manufacturer);
-    driver->model_name    = new ppdcString(ptr);
-    driver->pc_file_name  = new ppdcString(ppd->pcfilename);
+    if (ppd->nickname)
+      driver->add_attr(new ppdcAttr("NickName", NULL, NULL, ppd->nickname));
+
+    if (ppd->shortnickname)
+      driver->add_attr(new ppdcAttr("ShortNickName", NULL, NULL,
+                                    ppd->shortnickname));
+
+    driver->manufacturer        = new ppdcString(ppd->manufacturer);
+    driver->model_name          = new ppdcString(ptr);
+    driver->pc_file_name        = new ppdcString(ppd->pcfilename);
     attr = ppdFindAttr(ppd, "FileVersion", NULL);
-    driver->version       = new ppdcString(attr ? attr->value : NULL);
-    driver->model_number  = ppd->model_number;
-    driver->manual_copies = ppd->manual_copies;
-    driver->color_device  = ppd->color_device;
-    driver->throughput    = ppd->throughput;
+    driver->version             = new ppdcString(attr ? attr->value : NULL);
+    driver->model_number        = ppd->model_number;
+    driver->manual_copies       = ppd->manual_copies;
+    driver->color_device        = ppd->color_device;
+    driver->throughput          = ppd->throughput;
+    driver->variable_paper_size = ppd->variable_sizes;
+    driver->max_width           = ppd->custom_max[0];
+    driver->max_length          = ppd->custom_max[1];
+    driver->min_width           = ppd->custom_min[0];
+    driver->min_length          = ppd->custom_min[1];
+    driver->left_margin         = ppd->custom_margins[0];
+    driver->bottom_margin       = ppd->custom_margins[1];
+    driver->right_margin        = ppd->custom_margins[2];
+    driver->top_margin          = ppd->custom_margins[3];
+
+    for (i = 0; i < ppd->num_filters; i ++)
+    {
+      strlcpy(line, ppd->filters[i], sizeof(line));
+
+      for (ptr = line; *ptr; ptr ++)
+        if (isspace(*ptr & 255))
+         break;
+      *ptr++ = '\0';
+
+      cost = strtol(ptr, &ptr, 10);
+
+      while (isspace(*ptr & 255))
+        ptr ++;
+
+      filter = new ppdcFilter(line, ptr, cost);
+      driver->add_filter(filter);
+    }
 
     attr = ppdFindAttr(ppd, "DefaultFont", NULL);
     driver->default_font  = new ppdcString(attr ? attr->value : NULL);
@@ -135,7 +160,7 @@ ppdcSource::import_ppd(const char *f)       // I - Filename
     for (i = ppd->num_sizes, size = ppd->sizes; i > 0; i --, size ++)
     {
       // Don't do custom size here...
-      if (!strcasecmp(size->name, "Custom"))
+      if (!_cups_strcasecmp(size->name, "Custom"))
         continue;
 
       // Get the code for the PageSize and PageRegion options...
@@ -151,7 +176,7 @@ ppdcSource::import_ppd(const char *f)       // I - Filename
 
        driver->add_size(csize);
 
-       if (!strcasecmp(size_option->defchoice, size->name))
+       if (!_cups_strcasecmp(size_option->defchoice, size->name))
          driver->set_default_size(csize);
     }
 
@@ -165,7 +190,7 @@ ppdcSource::import_ppd(const char *f)       // I - Filename
       {
         if (!strcmp(option->keyword, "PageSize") || !strcmp(option->keyword, "PageRegion"))
           continue;
-            
+
         coption = new ppdcOption((ppdcOptType)option->ui, option->keyword,
                                 option->text, (ppdcOptSection)option->section,
                                 option->order);
@@ -173,10 +198,13 @@ ppdcSource::import_ppd(const char *f)     // I - Filename
 
         for (k = option->num_choices, choice = option->choices; k > 0; k --, choice ++)
         {
+         if (!strcmp(choice->choice, "Custom"))
+           continue;
+
           cchoice = new ppdcChoice(choice->choice, choice->text, choice->code);
           coption->add_choice(cchoice);
 
-          if (!strcasecmp(option->defchoice, choice->choice))
+          if (!_cups_strcasecmp(option->defchoice, choice->choice))
             coption->set_defchoice(cchoice);
         }
       }
@@ -187,25 +215,21 @@ ppdcSource::import_ppd(const char *f)     // I - Filename
          i > 0;
         i --, constraint ++)
     {
-      for (j = i - 1, constraint2 = constraint;
+      // Look for mirrored constraints...
+      for (j = i - 1, constraint2 = constraint + 1;
            j > 0;
           j --, constraint2 ++)
-       if (constraint != constraint2 &&
-           !strcmp(constraint->option1, constraint2->option2) &&
-           (constraint->choice1 == constraint2->choice2 ||
-            (constraint->choice1 && constraint2->choice2 &&
-             !strcmp(constraint->choice1, constraint2->choice2))) &&
+       if (!strcmp(constraint->option1, constraint2->option2) &&
+           !strcmp(constraint->choice1, constraint2->choice2) &&
            !strcmp(constraint->option2, constraint2->option1) &&
-           (constraint->choice2 == constraint2->choice1 ||
-            (constraint->choice2 && constraint2->choice1 &&
-             !strcmp(constraint->choice2, constraint2->choice1))))
+           !strcmp(constraint->choice2, constraint2->choice1))
           break;
 
       if (j)
         continue;
 
-      cconstraint = new ppdcConstraint(constraint->option1, constraint->choice1,
-                                       constraint->option2, constraint->choice2);
+      cconstraint = new ppdcConstraint(constraint->option2, constraint->choice2,
+                                       constraint->option1, constraint->choice1);
       driver->add_constraint(cconstraint);
     }
 
@@ -226,7 +250,8 @@ ppdcSource::import_ppd(const char *f)       // I - Filename
         if (sscanf(attr->value, "%s%*[^\"]\"%[^\"]\"%s%s", encoding, version,
                   charset, status) != 4)
        {
-         fprintf(stderr, "Bad font attribute: %s\n", attr->value);
+         _cupsLangPrintf(stderr, _("ppdc: Bad font attribute: %s"),
+                         attr->value);
          continue;
        }
 
@@ -239,6 +264,10 @@ ppdcSource::import_ppd(const char *f)      // I - Filename
 
        driver->add_font(font);
       }
+      else if (!strcmp(attr->name, "CustomPageSize"))
+      {
+        driver->set_custom_size_code(attr->value);
+      }
       else if ((strncmp(attr->name, "Default", 7) ||
                !strcmp(attr->name, "DefaultColorSpace")) &&
               strcmp(attr->name, "ColorDevice") &&
@@ -247,15 +276,35 @@ ppdcSource::import_ppd(const char *f)     // I - Filename
               strcmp(attr->name, "MaxMediaHeight") &&
               strcmp(attr->name, "MaxMediaWidth") &&
               strcmp(attr->name, "NickName") &&
+              strcmp(attr->name, "ParamCustomPageSize") &&
               strcmp(attr->name, "ShortNickName") &&
               strcmp(attr->name, "Throughput") &&
               strcmp(attr->name, "PCFileName") &&
               strcmp(attr->name, "FileVersion") &&
               strcmp(attr->name, "FormatVersion") &&
+              strcmp(attr->name, "HWMargins") &&
               strcmp(attr->name, "VariablePaperSize") &&
               strcmp(attr->name, "LanguageEncoding") &&
-              strcmp(attr->name, "LanguageVersion"))
+              strcmp(attr->name, "LanguageVersion") &&
+              strcmp(attr->name, "cupsFilter") &&
+              strcmp(attr->name, "cupsFlipDuplex") &&
+              strcmp(attr->name, "cupsLanguages") &&
+              strcmp(attr->name, "cupsManualCopies") &&
+              strcmp(attr->name, "cupsModelNumber") &&
+              strcmp(attr->name, "cupsVersion"))
       {
+        if ((ptr = strchr(attr->name, '.')) != NULL &&
+           ((ptr - attr->name) == 2 || (ptr - attr->name) == 5))
+       {
+         // Might be a localization attribute; test further...
+         if (isalpha(attr->name[0] & 255) &&
+             isalpha(attr->name[1] & 255) &&
+             (attr->name[2] == '.' ||
+              (attr->name[2] == '_' && isalpha(attr->name[3] & 255) &&
+               isalpha(attr->name[4] & 255))))
+            continue;
+       }
+
         // Attribute...
         driver->add_attr(new ppdcAttr(attr->name, attr->spec, attr->text,
                                      attr->value));
@@ -276,8 +325,3 @@ ppdcSource::import_ppd(const char *f)       // I - Filename
 
   return (1);
 }
-
-
-//
-// End of "$Id$".
-//