]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/attr.c
Don't map Primera name to Fargo anymore (STR #4708)
[thirdparty/cups.git] / cups / attr.c
index aabd0ee75116a33e5fd84228f098a7397e4812f7..c98a36b47e570651942bd7fd7d1a10a8a82400c4 100644 (file)
@@ -1,38 +1,30 @@
 /*
- * "$Id: attr.c 7584 2008-05-16 22:55:53Z mike $"
+ * "$Id$"
  *
- *   PPD model-specific attribute routines for the Common UNIX Printing System
- *   (CUPS).
+ * PPD model-specific attribute routines for CUPS.
  *
- *   Copyright 2007-2008 by Apple Inc.
- *   Copyright 1997-2006 by Easy Software Products.
+ * Copyright 2007-2015 by Apple Inc.
+ * Copyright 1997-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:
- *
- *   ppdFindAttr()     - Find the first matching attribute.
- *   ppdFindNextAttr() - Find the next matching attribute.
+ * 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/".
  */
 
 /*
  * Include necessary headers...
  */
 
+#include "cups-private.h"
 #include "ppd-private.h"
-#include "debug.h"
-#include "string.h"
-#include <stdlib.h>
 
 
 /*
  * 'ppdFindAttr()' - Find the first matching attribute.
  *
- * @since CUPS 1.1.19@
+ * @since CUPS 1.1.19/OS X 10.3@
  */
 
 ppd_attr_t *                           /* O - Attribute or @code NULL@ if not found */
@@ -42,11 +34,10 @@ ppdFindAttr(ppd_file_t *ppd,                /* I - PPD file data */
 {
   ppd_attr_t   key,                    /* Search key */
                *attr;                  /* Current attribute */
-  int          diff;                   /* Current difference */
 
 
-  DEBUG_printf(("ppdFindAttr(ppd=%p, name=\"%s\", spec=\"%s\")\n", ppd,
-                name ? name : "(null)", spec ? spec : "(null)"));
+  DEBUG_printf(("2ppdFindAttr(ppd=%p, name=\"%s\", spec=\"%s\")", ppd, name,
+                spec));
 
  /*
   * Range check input...
@@ -61,39 +52,25 @@ ppdFindAttr(ppd_file_t *ppd,                /* I - PPD file data */
 
   memset(&key, 0, sizeof(key));
   strlcpy(key.name, name, sizeof(key.name));
-  if (spec)
-    strlcpy(key.spec, spec, sizeof(key.spec));
 
  /*
   * Return the first matching attribute, if any...
   */
 
   if ((attr = (ppd_attr_t *)cupsArrayFind(ppd->sorted_attrs, &key)) != NULL)
-    return (attr);
-  else if (spec)
-    return (NULL);
-
- /*
-  * No match found, loop through the sorted attributes to see if we can
-  * find a "wildcard" match for the attribute...
-  */
-
-  for (attr = (ppd_attr_t *)cupsArrayFirst(ppd->sorted_attrs);
-       attr;
-       attr = (ppd_attr_t *)cupsArrayNext(ppd->sorted_attrs))
   {
-    if ((diff = strcasecmp(attr->name, name)) == 0)
-      break;
-
-    if (diff > 0)
+    if (spec)
     {
      /*
-      * All remaining attributes are > than the one we are trying to find...
+      * Loop until we find the first matching attribute for "spec"...
       */
 
-      cupsArrayIndex(ppd->sorted_attrs, cupsArrayCount(ppd->sorted_attrs));
-
-      return (NULL);
+      while (attr && _cups_strcasecmp(spec, attr->spec))
+      {
+        if ((attr = (ppd_attr_t *)cupsArrayNext(ppd->sorted_attrs)) != NULL &&
+           _cups_strcasecmp(attr->name, name))
+         attr = NULL;
+      }
     }
   }
 
@@ -104,7 +81,7 @@ ppdFindAttr(ppd_file_t *ppd,         /* I - PPD file data */
 /*
  * 'ppdFindNextAttr()' - Find the next matching attribute.
  *
- * @since CUPS 1.1.19@
+ * @since CUPS 1.1.19/OS X 10.3@
  */
 
 ppd_attr_t *                           /* O - Attribute or @code NULL@ if not found */
@@ -119,120 +96,39 @@ ppdFindNextAttr(ppd_file_t *ppd,  /* I - PPD file data */
   * Range check input...
   */
 
-  if (!ppd || !name || ppd->num_attrs == 0 ||
-      !cupsArrayCurrent(ppd->sorted_attrs))
+  if (!ppd || !name || ppd->num_attrs == 0)
     return (NULL);
 
  /*
   * See if there are more attributes to return...
   */
 
-  if ((attr = (ppd_attr_t *)cupsArrayNext(ppd->sorted_attrs)) == NULL)
-    return (NULL);
-
- /*
-  * Check the next attribute to see if it is a match...
-  */
-
-  if (strcasecmp(attr->name, name) || (spec && strcasecmp(attr->spec, spec)))
+  while ((attr = (ppd_attr_t *)cupsArrayNext(ppd->sorted_attrs)) != NULL)
   {
    /*
-    * Nope, reset the current pointer to the end of the array...
+    * Check the next attribute to see if it is a match...
     */
 
-    cupsArrayIndex(ppd->sorted_attrs, cupsArrayCount(ppd->sorted_attrs));
-
-    return (NULL);
-  }
-  
- /*
-  * Return the next attribute's value...
-  */
-
-  return (attr);
-}
-
-
-/*
- * '_ppdGet1284Values()' - Get 1284 device ID keys and values.
- *
- * The returned dictionary is a CUPS option array that can be queried with
- * cupsGetOption and freed with cupsFreeOptions.
- */
-
-int                                    /* O - Number of key/value pairs */
-_ppdGet1284Values(
-    const char *device_id,             /* I - IEEE-1284 device ID string */
-    cups_option_t **values)            /* O - Array of key/value pairs */
-{
-  int          num_values;             /* Number of values */
-  char         key[256],               /* Key string */
-               value[256],             /* Value string */
-               *ptr;                   /* Pointer into key/value */
-
+    if (_cups_strcasecmp(attr->name, name))
+    {
+     /*
+      * Nope, reset the current pointer to the end of the array...
+      */
 
- /*
-  * Range check input...
-  */
+      cupsArrayIndex(ppd->sorted_attrs, cupsArrayCount(ppd->sorted_attrs));
 
-  if (values)
-    *values = NULL;
+      return (NULL);
+    }
 
-  if (!device_id || !values)
-    return (0);
+    if (!spec || !_cups_strcasecmp(attr->spec, spec))
+      break;
+  }
 
  /*
-  * Parse the 1284 device ID value into keys and values.  The format is
-  * repeating sequences of:
-  *
-  *   [whitespace]key:value[whitespace];
+  * Return the next attribute's value...
   */
 
-  num_values = 0;
-  while (*device_id)
-  {
-    while (isspace(*device_id & 255))
-      device_id ++;
-
-    if (!*device_id)
-      break;
-
-    for (ptr = key; *device_id && *device_id != ':'; device_id ++)
-      if (ptr < (key + sizeof(key) - 1))
-        *ptr++ = *device_id;
-
-    if (!*device_id)
-      break;
-
-    while (ptr > key && isspace(ptr[-1] & 255))
-      ptr --;
-
-    *ptr = '\0';
-    device_id ++;
-
-    while (isspace(*device_id & 255))
-      device_id ++;
-
-    if (!*device_id)
-      break;
-
-    for (ptr = value; *device_id && *device_id != ';'; device_id ++)
-      if (ptr < (value + sizeof(value) - 1))
-        *ptr++ = *device_id;
-
-    if (!*device_id)
-      break;
-
-    while (ptr > value && isspace(ptr[-1] & 255))
-      ptr --;
-
-    *ptr = '\0';
-    device_id ++;
-
-    num_values = cupsAddOption(key, value, num_values, values);
-  }
-
-  return (num_values);
+  return (attr);
 }
 
 
@@ -264,7 +160,7 @@ _ppdNormalizeMakeAndModel(
   * Skip leading whitespace...
   */
 
-  while (isspace(*make_and_model & 255))
+  while (_cups_isspace(*make_and_model))
     make_and_model ++;
 
  /*
@@ -278,7 +174,7 @@ _ppdNormalizeMakeAndModel(
     if ((bufptr = strrchr(buffer, ')')) != NULL)
       *bufptr = '\0';
   }
-  else if (!strncasecmp(make_and_model, "XPrint", 6))
+  else if (!_cups_strncasecmp(make_and_model, "XPrint", 6))
   {
    /*
     * Xerox XPrint...
@@ -286,7 +182,7 @@ _ppdNormalizeMakeAndModel(
 
     snprintf(buffer, bufsize, "Xerox %s", make_and_model);
   }
-  else if (!strncasecmp(make_and_model, "Eastman", 7))
+  else if (!_cups_strncasecmp(make_and_model, "Eastman", 7))
   {
    /*
     * Kodak...
@@ -294,7 +190,7 @@ _ppdNormalizeMakeAndModel(
 
     snprintf(buffer, bufsize, "Kodak %s", make_and_model + 7);
   }
-  else if (!strncasecmp(make_and_model, "laserwriter", 11))
+  else if (!_cups_strncasecmp(make_and_model, "laserwriter", 11))
   {
    /*
     * Apple LaserWriter...
@@ -302,7 +198,7 @@ _ppdNormalizeMakeAndModel(
 
     snprintf(buffer, bufsize, "Apple LaserWriter%s", make_and_model + 11);
   }
-  else if (!strncasecmp(make_and_model, "colorpoint", 10))
+  else if (!_cups_strncasecmp(make_and_model, "colorpoint", 10))
   {
    /*
     * Seiko...
@@ -310,7 +206,7 @@ _ppdNormalizeMakeAndModel(
 
     snprintf(buffer, bufsize, "Seiko %s", make_and_model);
   }
-  else if (!strncasecmp(make_and_model, "fiery", 5))
+  else if (!_cups_strncasecmp(make_and_model, "fiery", 5))
   {
    /*
     * EFI...
@@ -318,8 +214,8 @@ _ppdNormalizeMakeAndModel(
 
     snprintf(buffer, bufsize, "EFI %s", make_and_model);
   }
-  else if (!strncasecmp(make_and_model, "ps ", 3) ||
-          !strncasecmp(make_and_model, "colorpass", 9))
+  else if (!_cups_strncasecmp(make_and_model, "ps ", 3) ||
+          !_cups_strncasecmp(make_and_model, "colorpass", 9))
   {
    /*
     * Canon...
@@ -327,16 +223,8 @@ _ppdNormalizeMakeAndModel(
 
     snprintf(buffer, bufsize, "Canon %s", make_and_model);
   }
-  else if (!strncasecmp(make_and_model, "primera", 7))
-  {
-   /*
-    * Fargo...
-    */
-
-    snprintf(buffer, bufsize, "Fargo %s", make_and_model);
-  }
-  else if (!strncasecmp(make_and_model, "designjet", 9) ||
-           !strncasecmp(make_and_model, "deskjet", 7))
+  else if (!_cups_strncasecmp(make_and_model, "designjet", 9) ||
+           !_cups_strncasecmp(make_and_model, "deskjet", 7))
   {
    /*
     * HP...
@@ -351,7 +239,7 @@ _ppdNormalizeMakeAndModel(
   * Clean up the make...
   */
 
-  if (!strncasecmp(buffer, "agfa", 4))
+  if (!_cups_strncasecmp(buffer, "agfa", 4))
   {
    /*
     * Replace with AGFA (all uppercase)...
@@ -362,7 +250,7 @@ _ppdNormalizeMakeAndModel(
     buffer[2] = 'F';
     buffer[3] = 'A';
   }
-  else if (!strncasecmp(buffer, "Hewlett-Packard hp ", 19))
+  else if (!_cups_strncasecmp(buffer, "Hewlett-Packard hp ", 19))
   {
    /*
     * Just put "HP" on the front...
@@ -372,7 +260,7 @@ _ppdNormalizeMakeAndModel(
     buffer[1] = 'P';
     _cups_strcpy(buffer + 2, buffer + 18);
   }
-  else if (!strncasecmp(buffer, "Hewlett-Packard ", 16))
+  else if (!_cups_strncasecmp(buffer, "Hewlett-Packard ", 16))
   {
    /*
     * Just put "HP" on the front...
@@ -382,7 +270,7 @@ _ppdNormalizeMakeAndModel(
     buffer[1] = 'P';
     _cups_strcpy(buffer + 2, buffer + 15);
   }
-  else if (!strncasecmp(buffer, "Lexmark International", 21))
+  else if (!_cups_strncasecmp(buffer, "Lexmark International", 21))
   {
    /*
     * Strip "International"...
@@ -390,7 +278,7 @@ _ppdNormalizeMakeAndModel(
 
     _cups_strcpy(buffer + 8, buffer + 21);
   }
-  else if (!strncasecmp(buffer, "herk", 4))
+  else if (!_cups_strncasecmp(buffer, "herk", 4))
   {
    /*
     * Replace with LHAG...
@@ -401,7 +289,7 @@ _ppdNormalizeMakeAndModel(
     buffer[2] = 'A';
     buffer[3] = 'G';
   }
-  else if (!strncasecmp(buffer, "linotype", 8))
+  else if (!_cups_strncasecmp(buffer, "linotype", 8))
   {
    /*
     * Replace with LHAG...
@@ -419,7 +307,7 @@ _ppdNormalizeMakeAndModel(
   */
 
   for (bufptr = buffer + strlen(buffer) - 1;
-       bufptr >= buffer && isspace(*bufptr & 255);
+       bufptr >= buffer && _cups_isspace(*bufptr);
        bufptr --);
 
   bufptr[1] = '\0';
@@ -429,5 +317,5 @@ _ppdNormalizeMakeAndModel(
 
 
 /*
- * End of "$Id: attr.c 7584 2008-05-16 22:55:53Z mike $".
+ * End of "$Id$".
  */