MCPcopy Create free account
hub / github.com/OpenPrinting/cups / with_distinct_values

Function with_distinct_values

tools/ipptool.c:5668–5786  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5666 */
5667
5668static int // O - 1 if distinct, 0 if duplicate
5669with_distinct_values(
5670 cups_array_t *errors, // I - Array of errors
5671 ipp_attribute_t *attr) // I - Attribute to test
5672{
5673 int i, // Looping var
5674 count; // Number of values
5675 ipp_tag_t value_tag; // Value syntax
5676 const char *value; // Current value
5677 char buffer[8192]; // Temporary buffer
5678 cups_array_t *values; // Array of values as strings
5679
5680
5681 // If there is only 1 value, it must be distinct
5682 if ((count = ippGetCount(attr)) == 1)
5683 return (1);
5684
5685 // Only check integers, enums, rangeOfInteger, resolution, and nul-terminated
5686 // strings...
5687 switch (value_tag = ippGetValueTag(attr))
5688 {
5689 case IPP_TAG_INTEGER :
5690 case IPP_TAG_ENUM :
5691 case IPP_TAG_RANGE :
5692 case IPP_TAG_RESOLUTION :
5693 case IPP_TAG_KEYWORD :
5694 case IPP_TAG_URISCHEME :
5695 case IPP_TAG_CHARSET :
5696 case IPP_TAG_LANGUAGE :
5697 case IPP_TAG_MIMETYPE :
5698 case IPP_TAG_BEGIN_COLLECTION :
5699 break;
5700
5701 default :
5702 add_stringf(errors, "WITH-DISTINCT-VALUES %s not supported for 1setOf %s", ippGetName(attr), ippTagString(value_tag));
5703 return (0);
5704 }
5705
5706 // Collect values and determine they are all unique...
5707 values = cupsArrayNew3((cups_array_func_t)strcmp, NULL, NULL, 0, (cups_acopy_func_t)strdup, (cups_afree_func_t)free);
5708
5709 for (i = 0; i < count; i ++)
5710 {
5711 switch (value_tag)
5712 {
5713 case IPP_TAG_INTEGER :
5714 case IPP_TAG_ENUM :
5715 snprintf(buffer, sizeof(buffer), "%d", ippGetInteger(attr, i));
5716 value = buffer;
5717 break;
5718 case IPP_TAG_RANGE :
5719 {
5720 int upper, lower = ippGetRange(attr, i, &upper);
5721 // Range values
5722
5723 snprintf(buffer, sizeof(buffer), "%d-%d", lower, upper);
5724 value = buffer;
5725 }

Callers 2

do_monitor_printer_stateFunction · 0.85
do_testFunction · 0.85

Calls 15

ippGetCountFunction · 0.85
ippGetValueTagFunction · 0.85
add_stringfFunction · 0.85
ippGetNameFunction · 0.85
ippTagStringFunction · 0.85
cupsArrayNew3Function · 0.85
ippGetIntegerFunction · 0.85
ippGetRangeFunction · 0.85
ippGetResolutionFunction · 0.85
ippGetStringFunction · 0.85
ippGetCollectionFunction · 0.85
ippFirstAttributeFunction · 0.85

Tested by

no test coverage detected