From: Michael R Sweet Date: Mon, 1 May 2017 20:52:23 +0000 (-0400) Subject: Implement cupsAddIntegerOption and cupsGetIntegerOption functions (Issue #4992) X-Git-Tag: v2.2.4~72 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0d7cb94a77d71670daa0afd14eb2cfb2519fe040;p=thirdparty%2Fcups.git Implement cupsAddIntegerOption and cupsGetIntegerOption functions (Issue #4992) --- diff --git a/CHANGES.txt b/CHANGES.txt index 3edf65ded1..898434bf8e 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,4 @@ -CHANGES.txt - 2.2.4 - 2017-04-24 +CHANGES.txt - 2.2.4 - 2017-05-01 -------------------------------- CHANGES IN CUPS V2.2.4 @@ -7,6 +7,10 @@ CHANGES IN CUPS V2.2.4 - cupsEnumDests did not return early when all printers had been discovered (Issue #4989) - The CUPS build system now supports cross-compilation (Issue #4897) + - Added a new CUPS Programming Manual to replace the aging API + documentation. + - Added the cupsAddIntegerOption and cupsGetIntegerOption functions + (Issue #4992) CHANGES IN CUPS V2.2.3 diff --git a/cups/cups.h b/cups/cups.h index b2419f1b5a..22d4be3e14 100644 --- a/cups/cups.h +++ b/cups/cups.h @@ -600,6 +600,10 @@ extern int cupsSetServerCredentials(const char *path, const char *common_name, /* New in CUPS 2.2/macOS 10.12 */ extern ssize_t cupsHashData(const char *algorithm, const void *data, size_t datalen, unsigned char *hash, size_t hashsize) _CUPS_API_2_2; +/* New in CUPS 2.2.4 */ +extern int cupsAddIntegerOption(const char *name, int value, int num_options, cups_option_t **options) _CUPS_API_2_2_4; +extern int cupsGetIntegerOption(const char *name, int num_options, cups_option_t *options) _CUPS_API_2_2_4; + # ifdef __cplusplus } # endif /* __cplusplus */ diff --git a/cups/options.c b/cups/options.c index aa70992853..901c75df3c 100644 --- a/cups/options.c +++ b/cups/options.c @@ -29,6 +29,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@ + */ + +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. * @@ -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 2.2.4@ + */ + +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. */ diff --git a/cups/versioning.h b/cups/versioning.h index 2e92e6ba45..5a000c050c 100644 --- a/cups/versioning.h +++ b/cups/versioning.h @@ -1,7 +1,7 @@ /* * API versioning definitions for CUPS. * - * Copyright 2007-2016 by Apple Inc. + * Copyright 2007-2017 by Apple Inc. * * These coded instructions, statements, and computer programs are the * property of Apple Inc. and are protected by Federal copyright @@ -17,11 +17,10 @@ /* * This header defines several constants - _CUPS_DEPRECATED, - * _CUPS_DEPRECATED_MSG, _CUPS_INTERNAL_MSG, _CUPS_API_1_1, _CUPS_API_1_1_19, - * _CUPS_API_1_1_20, _CUPS_API_1_1_21, _CUPS_API_1_2, _CUPS_API_1_3, - * _CUPS_API_1_4, _CUPS_API_1_5, _CUPS_API_1_6, _CUPS_API_1_7, and - * _CUPS_API_2_0 - which add compiler-specific attributes that flag functions - * that are deprecated, added in particular releases, or internal to CUPS. + * _CUPS_DEPRECATED_MSG, _CUPS_INTERNAL_MSG, _CUPS_API_major_minor, and + * _CUPS_API_major_minor_patch - which add compiler-specific attributes that + * flag functions that are deprecated, added in particular releases, or internal + * to CUPS. * * On macOS, the _CUPS_API_* constants are defined based on the values of * the MAC_OS_X_VERSION_MIN_ALLOWED and MAC_OS_X_VERSION_MAX_ALLOWED constants @@ -57,6 +56,9 @@ # ifndef AVAILABLE_MAC_OS_X_VERSION_10_12_AND_LATER # define AVAILABLE_MAC_OS_X_VERSION_10_12_AND_LATER __attribute__((unavailable)) # endif /* !AVAILABLE_MAC_OS_X_VERSION_10_12_AND_LATER */ +# ifndef AVAILABLE_MAC_OS_X_VERSION_10_13_AND_LATER +# define AVAILABLE_MAC_OS_X_VERSION_10_13_AND_LATER __attribute__((unavailable)) +# endif /* !AVAILABLE_MAC_OS_X_VERSION_10_13_AND_LATER */ # define _CUPS_API_1_1_19 AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER # define _CUPS_API_1_1_20 AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER # define _CUPS_API_1_1_21 AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER @@ -68,6 +70,7 @@ # define _CUPS_API_1_7 AVAILABLE_MAC_OS_X_VERSION_10_9_AND_LATER # define _CUPS_API_2_0 AVAILABLE_MAC_OS_X_VERSION_10_10_AND_LATER # define _CUPS_API_2_2 AVAILABLE_MAC_OS_X_VERSION_10_12_AND_LATER +# define _CUPS_API_2_2_4 AVAILABLE_MAC_OS_X_VERSION_10_13_AND_LATER # else # define _CUPS_API_1_1_19 # define _CUPS_API_1_1_20 @@ -80,6 +83,7 @@ # define _CUPS_API_1_7 # define _CUPS_API_2_0 # define _CUPS_API_2_2 +# define _CUPS_API_2_2_4 # endif /* __APPLE__ && !_CUPS_SOURCE */ /*