]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/ppd-cache.c
Import CUPS v2.0b1
[thirdparty/cups.git] / cups / ppd-cache.c
index 75eef2d9c85fbd48d599e1a13f70cd9ba92dd0ed..7b3a9e5bf6c921c635074c0d6228ad4b01731666 100644 (file)
@@ -1,49 +1,17 @@
 /*
- * "$Id: ppd-cache.c 11833 2014-04-24 15:04:15Z msweet $"
+ * "$Id: ppd-cache.c 11832 2014-04-24 15:04:00Z msweet $"
  *
- *   PPD cache implementation for CUPS.
+ * PPD cache implementation for CUPS.
  *
- *   Copyright 2010-2013 by Apple Inc.
+ * Copyright 2010-2014 by Apple Inc.
  *
- *   These coded instructions, statements, and computer programs are the
- *   property of Apple Inc. and are protected by Federal copyright
- *   law.  Distribution and use rights are outlined in the file "LICENSE.txt"
- *   which should have been included with this file.  If this file is
- *   file is missing or damaged, see the license at "http://www.cups.org/".
+ * These coded instructions, statements, and computer programs are the
+ * property of Apple Inc. and are protected by Federal copyright
+ * law.  Distribution and use rights are outlined in the file "LICENSE.txt"
+ * which should have been included with this file.  If this file is
+ * file is missing or damaged, see the license at "http://www.cups.org/".
  *
- *   This file is subject to the Apple OS-Developed Software exception.
- *
- * Contents:
- *
- *   _ppdCacheCreateWithFile() - Create PPD cache and mapping data from a
- *                               written file.
- *   _ppdCacheCreateWithPPD()  - Create PWG mapping data from a PPD file.
- *   _ppdCacheDestroy()        - Free all memory used for PWG mapping data.
- *   _ppdCacheGetBin()         - Get the PWG output-bin keyword associated with
- *                               a PPD OutputBin.
- *   _ppdCacheGetInputSlot()   - Get the PPD InputSlot associated with the job
- *                               attributes or a keyword string.
- *   _ppdCacheGetMediaType()   - Get the PPD MediaType associated with the job
- *                               attributes or a keyword string.
- *   _ppdCacheGetOutputBin()   - Get the PPD OutputBin associated with the
- *                               keyword string.
- *   _ppdCacheGetPageSize()    - Get the PPD PageSize associated with the job
- *                               attributes or a keyword string.
- *   _ppdCacheGetSize()        - Get the PWG size associated with a PPD
- *                               PageSize.
- *   _ppdCacheGetSource()      - Get the PWG media-source associated with a PPD
- *                               InputSlot.
- *   _ppdCacheGetType()        - Get the PWG media-type associated with a PPD
- *                               MediaType.
- *   _ppdCacheWriteFile()      - Write PWG mapping data to a file.
- *   _pwgInputSlotForSource()  - Get the InputSlot name for the given PWG
- *                               media-source.
- *   _pwgMediaTypeForType()    - Get the MediaType name for the given PWG
- *                               media-type.
- *   _pwgPageSizeForMedia()    - Get the PageSize name for the given media.
- *   pwg_ppdize_name()         - Convert an IPP keyword to a PPD keyword.
- *   pwg_unppdize_name()       - Convert a PPD keyword to a lowercase IPP
- *                               keyword.
+ * This file is subject to the Apple OS-Developed Software exception.
  */
 
 /*
@@ -290,7 +258,7 @@ _ppdCacheCreateWithFile(
        goto create_error;
       }
 
-      if ((pc->bins = calloc(num_bins, sizeof(pwg_map_t))) == NULL)
+      if ((pc->bins = calloc((size_t)num_bins, sizeof(pwg_map_t))) == NULL)
       {
         DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d bins.",
                      num_sizes));
@@ -340,7 +308,7 @@ _ppdCacheCreateWithFile(
 
       if (num_sizes > 0)
       {
-       if ((pc->sizes = calloc(num_sizes, sizeof(pwg_size_t))) == NULL)
+       if ((pc->sizes = calloc((size_t)num_sizes, sizeof(pwg_size_t))) == NULL)
        {
          DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d sizes.",
                        num_sizes));
@@ -428,7 +396,7 @@ _ppdCacheCreateWithFile(
        goto create_error;
       }
 
-      if ((pc->sources = calloc(num_sources, sizeof(pwg_map_t))) == NULL)
+      if ((pc->sources = calloc((size_t)num_sources, sizeof(pwg_map_t))) == NULL)
       {
         DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d sources.",
                      num_sources));
@@ -477,7 +445,7 @@ _ppdCacheCreateWithFile(
        goto create_error;
       }
 
-      if ((pc->types = calloc(num_types, sizeof(pwg_map_t))) == NULL)
+      if ((pc->types = calloc((size_t)num_types, sizeof(pwg_map_t))) == NULL)
       {
         DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d types.",
                      num_types));
@@ -553,7 +521,7 @@ _ppdCacheCreateWithFile(
       if ((finishings = calloc(1, sizeof(_pwg_finishings_t))) == NULL)
         goto create_error;
 
-      finishings->value       = strtol(value, &valueptr, 10);
+      finishings->value       = (ipp_finishings_t)strtol(value, &valueptr, 10);
       finishings->num_options = cupsParseOptions(valueptr, 0,
                                                  &(finishings->options));
 
@@ -714,7 +682,7 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd)     /* I - PPD file */
 
   if (ppd->num_sizes > 0)
   {
-    if ((pc->sizes = calloc(ppd->num_sizes, sizeof(pwg_size_t))) == NULL)
+    if ((pc->sizes = calloc((size_t)ppd->num_sizes, sizeof(pwg_size_t))) == NULL)
     {
       DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
                    "pwg_size_t's.", ppd->num_sizes));
@@ -782,8 +750,9 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd)     /* I - PPD file */
       * dimensions that are <= 0...
       */
 
-      if ((pwg_media = pwgMediaForSize(PWG_FROM_POINTS(ppd_size->width),
-                                       PWG_FROM_POINTS(ppd_size->length))) == NULL)
+      if ((pwg_media = _pwgMediaNearSize(PWG_FROM_POINTS(ppd_size->width),
+                                       PWG_FROM_POINTS(ppd_size->length),
+                                       0)) == NULL)
        continue;
 
       new_width      = pwg_media->width;
@@ -891,8 +860,7 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd)     /* I - PPD file */
   {
     pc->source_option = _cupsStrAlloc(input_slot->keyword);
 
-    if ((pc->sources = calloc(input_slot->num_choices,
-                               sizeof(pwg_map_t))) == NULL)
+    if ((pc->sources = calloc((size_t)input_slot->num_choices, sizeof(pwg_map_t))) == NULL)
     {
       DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
                     "pwg_map_t's for InputSlot.", input_slot->num_choices));
@@ -953,8 +921,7 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd)     /* I - PPD file */
 
   if ((media_type = ppdFindOption(ppd, "MediaType")) != NULL)
   {
-    if ((pc->types = calloc(media_type->num_choices,
-                             sizeof(pwg_map_t))) == NULL)
+    if ((pc->types = calloc((size_t)media_type->num_choices, sizeof(pwg_map_t))) == NULL)
     {
       DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
                     "pwg_map_t's for MediaType.", media_type->num_choices));
@@ -1018,8 +985,7 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd)    /* I - PPD file */
 
   if ((output_bin = ppdFindOption(ppd, "OutputBin")) != NULL)
   {
-    if ((pc->bins = calloc(output_bin->num_choices,
-                           sizeof(pwg_map_t))) == NULL)
+    if ((pc->bins = calloc((size_t)output_bin->num_choices, sizeof(pwg_map_t))) == NULL)
     {
       DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
                     "pwg_map_t's for OutputBin.", output_bin->num_choices));
@@ -1202,7 +1168,7 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd)   /* I - PPD file */
 
          num_options = pc->num_presets[_PWG_PRINT_COLOR_MODE_COLOR]
                                        [pwg_print_quality];
-         options     = calloc(sizeof(cups_option_t), num_options);
+         options     = calloc(sizeof(cups_option_t), (size_t)num_options);
 
          if (options)
          {
@@ -1371,7 +1337,7 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd)   /* I - PPD file */
       if ((finishings = calloc(1, sizeof(_pwg_finishings_t))) == NULL)
         goto create_error;
 
-      finishings->value       = atoi(ppd_attr->spec);
+      finishings->value       = (ipp_finishings_t)atoi(ppd_attr->spec);
       finishings->num_options = _ppdParseOptions(ppd_attr->value, 0,
                                                  &(finishings->options),
                                                  _PPD_PARSE_OPTIONS);
@@ -1611,7 +1577,7 @@ _ppdCacheGetFinishingOptions(
 
     for (i = 0; i < num_values; i ++)
     {
-      key.value = ippGetInteger(attr, i);
+      key.value = (ipp_finishings_t)ippGetInteger(attr, i);
 
       if ((f = cupsArrayFind(pc->finishings, &key)) != NULL)
       {
@@ -1665,8 +1631,13 @@ _ppdCacheGetFinishingValues(
   * Range check input...
   */
 
+  DEBUG_printf(("_ppdCacheGetFinishingValues(pc=%p, num_options=%d, options=%p, max_values=%d, values=%p)", pc, num_options, options, max_values, values));
+
   if (!pc || !pc->finishings || num_options < 1 || max_values < 1 || !values)
+  {
+    DEBUG_puts("_ppdCacheGetFinishingValues: Bad arguments, returning 0.");
     return (0);
+  }
 
  /*
   * Go through the finishings options and see what is set...
@@ -1676,13 +1647,24 @@ _ppdCacheGetFinishingValues(
        f;
        f = (_pwg_finishings_t *)cupsArrayNext(pc->finishings))
   {
+    DEBUG_printf(("_ppdCacheGetFinishingValues: Checking %d (%s)", f->value, ippEnumString("finishings", f->value)));
+
     for (i = f->num_options, option = f->options; i > 0; i --, option ++)
+    {
+      DEBUG_printf(("_ppdCacheGetFinishingValues: %s=%s?", option->name, option->value));
+
       if ((val = cupsGetOption(option->name, num_options, options)) == NULL ||
           _cups_strcasecmp(option->value, val))
+      {
+        DEBUG_puts("_ppdCacheGetFinishingValues: NO");
         break;
+      }
+    }
 
     if (i == 0)
     {
+      DEBUG_printf(("_ppdCacheGetFinishingValues: Adding %d.", f->value));
+
       values[num_values ++] = f->value;
 
       if (num_values >= max_values)
@@ -1690,6 +1672,8 @@ _ppdCacheGetFinishingValues(
     }
   }
 
+  DEBUG_printf(("_ppdCacheGetFinishingValues: Returning %d.", num_values));
+
   return (num_values);
 }
 
@@ -2629,7 +2613,7 @@ _pwgPageSizeForMedia(
     * Copy the size name from class_sizename_dimensions...
     */
 
-    memcpy(name, sizeptr + 1, dimptr - sizeptr - 1);
+    memcpy(name, sizeptr + 1, (size_t)(dimptr - sizeptr - 1));
     name[dimptr - sizeptr - 1] = '\0';
   }
 
@@ -2676,14 +2660,14 @@ pwg_ppdize_name(const char *ipp,        /* I - IPP keyword */
        *end;                           /* End of name buffer */
 
 
-  *name = toupper(*ipp++);
+  *name = (char)toupper(*ipp++);
 
   for (ptr = name + 1, end = name + namesize - 1; *ipp && ptr < end;)
   {
     if (*ipp == '-' && _cups_isalpha(ipp[1]))
     {
       ipp ++;
-      *ptr++ = toupper(*ipp++ & 255);
+      *ptr++ = (char)toupper(*ipp++ & 255);
     }
     else
       *ptr++ = *ipp++;
@@ -2710,7 +2694,7 @@ pwg_unppdize_name(const char *ppd,        /* I - PPD keyword */
   for (ptr = name, end = name + namesize - 1; *ppd && ptr < end; ppd ++)
   {
     if (_cups_isalnum(*ppd) || *ppd == '-')
-      *ptr++ = tolower(*ppd & 255);
+      *ptr++ = (char)tolower(*ppd & 255);
     else if (strchr(dashchars, *ppd))
       *ptr++ = '-';
     else
@@ -2728,5 +2712,5 @@ pwg_unppdize_name(const char *ppd,        /* I - PPD keyword */
 
 
 /*
- * End of "$Id: ppd-cache.c 11833 2014-04-24 15:04:15Z msweet $".
+ * End of "$Id: ppd-cache.c 11832 2014-04-24 15:04:00Z msweet $".
  */