]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/ppd.c
Merge changes from CUPS 1.4svn-r8329.
[thirdparty/cups.git] / cups / ppd.c
index c10cbc491c385d85630715e71aead54e1cc4819f..c42d36d48f5cfb8008e48bfb7fc6eee7e06e76be 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: ppd.c 7552 2008-05-12 17:42:15Z mike $"
+ * "$Id: ppd.c 7906 2008-09-03 20:19:43Z mike $"
  *
  *   PPD file routines for the Common UNIX Printing System (CUPS).
  *
@@ -40,7 +40,6 @@
  *   ppd_add_size()         - Add a page size.
  *   ppd_compare_attrs()    - Compare two attributes.
  *   ppd_compare_choices()  - Compare two choices...
- *   ppd_compare_consts()   - Compare two constraints.
  *   ppd_compare_coptions() - Compare two custom options.
  *   ppd_compare_cparams()  - Compare two custom parameters.
  *   ppd_compare_options()  - Compare two options.
@@ -60,6 +59,7 @@
  * Include necessary headers.
  */
 
+#include "ppd-private.h"
 #include "globals.h"
 #include "debug.h"
 #include <stdlib.h>
@@ -109,7 +109,6 @@ static ppd_choice_t *ppd_add_choice(ppd_option_t *option, const char *name);
 static ppd_size_t      *ppd_add_size(ppd_file_t *ppd, const char *name);
 static int             ppd_compare_attrs(ppd_attr_t *a, ppd_attr_t *b);
 static int             ppd_compare_choices(ppd_choice_t *a, ppd_choice_t *b);
-static int             ppd_compare_consts(ppd_const_t *a, ppd_const_t *b);
 static int             ppd_compare_coptions(ppd_coption_t *a,
                                             ppd_coption_t *b);
 static int             ppd_compare_cparams(ppd_cparam_t *a, ppd_cparam_t *b);
@@ -162,7 +161,8 @@ ppdClose(ppd_file_t *ppd)           /* I - PPD file record */
 
   _cupsStrFree(ppd->lang_encoding);
   _cupsStrFree(ppd->nickname);
-  _cupsStrFree(ppd->patches);
+  if (ppd->patches)
+    free(ppd->patches);
   _cupsStrFree(ppd->jcl_begin);
   _cupsStrFree(ppd->jcl_end);
   _cupsStrFree(ppd->jcl_ps);
@@ -293,6 +293,26 @@ ppdClose(ppd_file_t *ppd)          /* I - PPD file record */
 
   cupsArrayDelete(ppd->coptions);
 
+ /*
+  * Free constraints...
+  */
+
+  if (ppd->cups_uiconstraints)
+  {
+    _ppd_cups_uiconsts_t *consts;      /* Current constraints */
+
+
+    for (consts = (_ppd_cups_uiconsts_t *)cupsArrayFirst(ppd->cups_uiconstraints);
+         consts;
+        consts = (_ppd_cups_uiconsts_t *)cupsArrayNext(ppd->cups_uiconstraints))
+    {
+      free(consts->constraints);
+      free(consts);
+    }
+
+    cupsArrayDelete(ppd->cups_uiconstraints);
+  }
+
  /*
   * Free the whole record...
   */
@@ -304,7 +324,7 @@ ppdClose(ppd_file_t *ppd)           /* I - PPD file record */
 /*
  * 'ppdErrorString()' - Returns the text assocated with a status.
  *
- * @since CUPS 1.1.19@
+ * @since CUPS 1.1.19/Mac OS X 10.3@
  */
 
 const char *                           /* O - Status string */
@@ -358,7 +378,7 @@ _ppdGetEncoding(const char *name)   /* I - LanguageEncoding string */
   else if (!strcasecmp(name, "ISOLatin5"))
     return (CUPS_ISO8859_5);
   else if (!strcasecmp(name, "JIS83-RKSJ"))
-    return (CUPS_WINDOWS_932);
+    return (CUPS_JIS_X0213);
   else if (!strcasecmp(name, "MacStandard"))
     return (CUPS_MAC_ROMAN);
   else if (!strcasecmp(name, "WindowsANSI"))
@@ -371,7 +391,7 @@ _ppdGetEncoding(const char *name)   /* I - LanguageEncoding string */
 /*
  * 'ppdLastError()' - Return the status from the last ppdOpen*().
  *
- * @since CUPS 1.1.19@
+ * @since CUPS 1.1.19/Mac OS X 10.3@
  */
 
 ppd_status_t                           /* O - Status code */
@@ -425,7 +445,7 @@ ppdOpen(FILE *fp)                   /* I - File to read from */
 /*
  * 'ppdOpen2()' - Read a PPD file into memory.
  *
- * @since CUPS 1.2@
+ * @since CUPS 1.2/Mac OS X 10.5@
  */
 
 ppd_file_t *                           /* O - PPD file record or @code NULL@ if the PPD file could not be opened. */
@@ -569,6 +589,7 @@ ppdOpen2(cups_file_t *fp)           /* I - File to read from */
       cg->ppd_status = PPD_MISSING_PPDADOBE4;
 
     _cupsStrFree(string);
+    ppd_free(line.buffer);
 
     return (NULL);
   }
@@ -585,6 +606,9 @@ ppdOpen2(cups_file_t *fp)           /* I - File to read from */
   {
     cg->ppd_status = PPD_ALLOC_ERROR;
 
+    _cupsStrFree(string);
+    ppd_free(line.buffer);
+
     return (NULL);
   }
 
@@ -619,7 +643,8 @@ ppdOpen2(cups_file_t *fp)           /* I - File to read from */
                   "string=%d chars...", mask, keyword, name, text,
                  string ? (int)strlen(string) : 0));
 
-    if (strncmp(keyword, "Default", 7) && !string)
+    if (strncmp(keyword, "Default", 7) && !string &&
+        cg->ppd_conform != PPD_CONFORM_RELAXED)
     {
      /*
       * Need a string value!
@@ -1031,19 +1056,23 @@ ppdOpen2(cups_file_t *fp)               /* I - File to read from */
        * Add the "custom" option...
        */
 
-       if ((choice = ppd_add_choice(custom_option, "Custom")) == NULL)
-       {
-         DEBUG_puts("Unable to add Custom choice!");
+        if ((choice = ppdFindChoice(custom_option, "Custom")) == NULL)
+         if ((choice = ppd_add_choice(custom_option, "Custom")) == NULL)
+         {
+           DEBUG_puts("Unable to add Custom choice!");
 
-         cg->ppd_status = PPD_ALLOC_ERROR;
+           cg->ppd_status = PPD_ALLOC_ERROR;
 
-         goto error;
-       }
+           goto error;
+         }
 
        strlcpy(choice->text, text[0] ? text : _("Custom"),
                sizeof(choice->text));
 
        choice->code = _cupsStrAlloc(string);
+
+       if (custom_option->section == PPD_ORDER_JCL)
+         ppd_decode(choice->code);
       }
 
      /*
@@ -1067,14 +1096,15 @@ ppdOpen2(cups_file_t *fp)               /* I - File to read from */
 
         if (custom_option)
        {
-         if ((choice = ppd_add_choice(custom_option, "Custom")) == NULL)
-         {
-           DEBUG_puts("Unable to add Custom choice!");
+         if ((choice = ppdFindChoice(custom_option, "Custom")) == NULL)
+           if ((choice = ppd_add_choice(custom_option, "Custom")) == NULL)
+           {
+             DEBUG_puts("Unable to add Custom choice!");
 
-           cg->ppd_status = PPD_ALLOC_ERROR;
+             cg->ppd_status = PPD_ALLOC_ERROR;
 
-           goto error;
-         }
+             goto error;
+           }
 
          strlcpy(choice->text, text[0] ? text : _("Custom"),
                  sizeof(choice->text));
@@ -1145,7 +1175,7 @@ ppdOpen2(cups_file_t *fp)         /* I - File to read from */
     else if (!strcmp(keyword, "JobPatchFile"))
     {
       if (ppd->patches == NULL)
-        ppd->patches = _cupsStrAlloc(string);
+        ppd->patches = strdup(string);
       else
       {
         temp = realloc(ppd->patches, strlen(ppd->patches) +
@@ -1279,19 +1309,20 @@ ppdOpen2(cups_file_t *fp)               /* I - File to read from */
 
       if ((custom_attr = ppdFindAttr(ppd, custom_name, "True")) != NULL)
       {
-       if ((choice = ppd_add_choice(option, "Custom")) == NULL)
-       {
-         DEBUG_puts("Unable to add Custom choice!");
+        if ((choice = ppdFindChoice(option, "Custom")) == NULL)
+         if ((choice = ppd_add_choice(option, "Custom")) == NULL)
+         {
+           DEBUG_puts("Unable to add Custom choice!");
 
-         cg->ppd_status = PPD_ALLOC_ERROR;
+           cg->ppd_status = PPD_ALLOC_ERROR;
 
-         goto error;
-       }
+           goto error;
+         }
 
        strlcpy(choice->text,
                custom_attr->text[0] ? custom_attr->text : _("Custom"),
                sizeof(choice->text));
-        choice->code = _cupsStrAlloc(custom_attr->value);
+        choice->code = _cupsStrRetain(custom_attr->value);
       }
     }
     else if (!strcmp(keyword, "JCLOpenUI"))
@@ -1394,7 +1425,7 @@ ppdOpen2(cups_file_t *fp)         /* I - File to read from */
        strlcpy(choice->text,
                custom_attr->text[0] ? custom_attr->text : _("Custom"),
                sizeof(choice->text));
-        choice->code = _cupsStrAlloc(custom_attr->value);
+        choice->code = _cupsStrRetain(custom_attr->value);
       }
     }
     else if (!strcmp(keyword, "CloseUI") || !strcmp(keyword, "JCLCloseUI"))
@@ -1747,52 +1778,6 @@ ppdOpen2(cups_file_t *fp)                /* I - File to read from */
            break;
       }
 
-     /*
-      * For CustomPageSize and InputSlot/ManualFeed, create a duplicate
-      * constraint for PageRegion...
-      */
-
-      if (!strcasecmp(constraint->option1, "CustomPageSize") &&
-          (!strcasecmp(constraint->option2, "InputSlot") ||
-          !strcasecmp(constraint->option2, "ManualFeed")))
-      {
-        ppd->num_consts ++;
-
-        strcpy(constraint[1].option1, "PageRegion");
-       strcpy(constraint[1].choice1, "Custom");
-       strcpy(constraint[1].option2, constraint->option2);
-       strcpy(constraint[1].choice2, constraint->choice2);
-      }
-      else if (!strcasecmp(constraint->option2, "CustomPageSize") &&
-               (!strcasecmp(constraint->option1, "InputSlot") ||
-               !strcasecmp(constraint->option1, "ManualFeed")))
-      {
-        ppd->num_consts ++;
-
-       strcpy(constraint[1].option1, constraint->option1);
-       strcpy(constraint[1].choice1, constraint->choice1);
-        strcpy(constraint[1].option2, "PageRegion");
-       strcpy(constraint[1].choice2, "Custom");
-      }
-
-     /*
-      * Handle CustomFoo option constraints...
-      */
-
-      if (!strncasecmp(constraint->option1, "Custom", 6) &&
-          !strcasecmp(constraint->choice1, "True"))
-      {
-        _cups_strcpy(constraint->option1, constraint->option1 + 6);
-       strcpy(constraint->choice1, "Custom");
-      }
-
-      if (!strncasecmp(constraint->option2, "Custom", 6) &&
-          !strcasecmp(constraint->choice2, "True"))
-      {
-        _cups_strcpy(constraint->option2, constraint->option2 + 6);
-       strcpy(constraint->choice2, "Custom");
-      }
-
      /*
       * Don't add this one as an attribute...
       */
@@ -1902,8 +1887,7 @@ ppdOpen2(cups_file_t *fp)         /* I - File to read from */
       _cupsStrFree(string);
   }
 
-  if (line.buffer)
-    free(line.buffer);
+  ppd_free(line.buffer);
 
  /*
   * Reset language preferences...
@@ -1958,14 +1942,6 @@ ppdOpen2(cups_file_t *fp)                /* I - File to read from */
     }
   }
 
- /*
-  * Sort the constraints...
-  */
-
-  if (ppd->num_consts > 1)
-    qsort(ppd->consts, ppd->num_consts, sizeof(ppd_const_t),
-          (int (*)(const void *, const void *))ppd_compare_consts);
-
  /*
   * Create an array to track the marked choices...
   */
@@ -1984,10 +1960,8 @@ ppdOpen2(cups_file_t *fp)                /* I - File to read from */
 
   error:
 
-  if (line.buffer)
-    free(line.buffer);
-
   _cupsStrFree(string);
+  ppd_free(line.buffer);
 
   ppdClose(ppd);
 
@@ -2100,7 +2074,7 @@ ppdOpenFile(const char *filename) /* I - File to read from */
 /*
  * 'ppdSetConformance()' - Set the conformance level for PPD files.
  *
- * @since CUPS 1.1.20@
+ * @since CUPS 1.1.20/Mac OS X 10.4@
  */
 
 void
@@ -2258,13 +2232,7 @@ static int                               /* O - Result of comparison */
 ppd_compare_attrs(ppd_attr_t *a,       /* I - First attribute */
                   ppd_attr_t *b)       /* I - Second attribute */
 {
-  int  ret;                            /* Result of comparison */
-
-
-  if ((ret = strcasecmp(a->name, b->name)) != 0)
-    return (ret);
-  else
-    return (strcasecmp(a->spec, b->spec));
+  return (strcasecmp(a->name, b->name));
 }
 
 
@@ -2280,28 +2248,6 @@ ppd_compare_choices(ppd_choice_t *a,     /* I - First choice */
 }
 
 
-/*
- * 'ppd_compare_consts()' - Compare two constraints.
- */
-
-static int                             /* O - Result of comparison */
-ppd_compare_consts(ppd_const_t *a,     /* I - First constraint */
-                   ppd_const_t *b)     /* I - Second constraint */
-{
-  int  ret;                            /* Result of comparison */
-
-
-  if ((ret = strcmp(a->option1, b->option1)) != 0)
-    return (ret);
-  else if ((ret = strcmp(a->choice1, b->choice1)) != 0)
-    return (ret);
-  else if ((ret = strcmp(a->option2, b->option2)) != 0)
-    return (ret);
-  else
-    return (strcmp(a->choice2, b->choice2));
-}
-
-
 /*
  * 'ppd_compare_coptions()' - Compare two custom options.
  */
@@ -3167,5 +3113,5 @@ ppd_read(cups_file_t    *fp,              /* I - File to read from */
 
 
 /*
- * End of "$Id: ppd.c 7552 2008-05-12 17:42:15Z mike $".
+ * End of "$Id: ppd.c 7906 2008-09-03 20:19:43Z mike $".
  */