]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/options.c
Move debug printfs to internal usage only.
[thirdparty/cups.git] / cups / options.c
index a3f57cfc093a1d948e0c76e51a7ce6bc49dd3734..11814c9af256d8796016e14f1d27659dea7b160f 100644 (file)
@@ -1,16 +1,10 @@
 /*
  * Option routines for CUPS.
  *
- * Copyright 2007-2014 by Apple Inc.
+ * Copyright 2007-2017 by Apple Inc.
  * Copyright 1997-2007 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/".
- *
- * This file is subject to the Apple OS-Developed Software exception.
+ * Licensed under Apache License v2.0.  See the file "LICENSE" for more information.
  */
 
 /*
@@ -18,6 +12,7 @@
  */
 
 #include "cups-private.h"
+#include "debug-internal.h"
 
 
 /*
@@ -29,6 +24,31 @@ static int   cups_find_option(const char *name, int num_options,
                                 cups_option_t *option, int prev, int *rdiff);
 
 
+/*
+ * 'cupsAddIntegerOption()' - Add an integer option to an option array.
+ *
+ * New option arrays can be initialized simply by passing 0 for the
+ * "num_options" parameter.
+ *
+ * @since CUPS 2.2.4/macOS 10.13@
+ */
+
+int                                    /* O  - Number of options */
+cupsAddIntegerOption(
+    const char    *name,               /* I  - Name of option */
+    int           value,               /* I  - Value of option */
+    int           num_options,         /* I  - Number of options */
+    cups_option_t **options)           /* IO - Pointer to options */
+{
+  char strvalue[32];                   /* String value */
+
+
+  snprintf(strvalue, sizeof(strvalue), "%d", value);
+
+  return (cupsAddOption(name, strvalue, num_options, options));
+}
+
+
 /*
  * 'cupsAddOption()' - Add an option to an option array.
  *
@@ -55,6 +75,11 @@ cupsAddOption(const char    *name,   /* I  - Name of option */
     return (num_options);
   }
 
+  if (!_cups_strcasecmp(name, "cupsPrintQuality"))
+    num_options = cupsRemoveOption("print-quality", num_options, options);
+  else if (!_cups_strcasecmp(name, "print-quality"))
+    num_options = cupsRemoveOption("cupsPrintQuality", num_options, options);
+
  /*
   * Look for an existing option with the same name...
   */
@@ -154,6 +179,38 @@ cupsFreeOptions(
 }
 
 
+/*
+ * 'cupsGetIntegerOption()' - Get an integer option value.
+ *
+ * INT_MIN is returned when the option does not exist, is not an integer, or
+ * exceeds the range of values for the "int" type.
+ *
+ * @since CUPS 2.2.4/macOS 10.13@
+ */
+
+int                                    /* O - Option value or @code INT_MIN@ */
+cupsGetIntegerOption(
+    const char    *name,               /* I - Name of option */
+    int           num_options,         /* I - Number of options */
+    cups_option_t *options)            /* I - Options */
+{
+  const char   *value = cupsGetOption(name, num_options, options);
+                                       /* String value of option */
+  char         *ptr;                   /* Pointer into string value */
+  long         intvalue;               /* Integer value */
+
+
+  if (!value || !*value)
+    return (INT_MIN);
+
+  intvalue = strtol(value, &ptr, 10);
+  if (intvalue < INT_MIN || intvalue > INT_MAX || *ptr)
+    return (INT_MIN);
+
+  return ((int)intvalue);
+}
+
+
 /*
  * 'cupsGetOption()' - Get an option value.
  */