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

Function cups_make_string

cups/dest.c:4334–4415  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4332 */
4333
4334static char * /* O - New string */
4335cups_make_string(
4336 ipp_attribute_t *attr, /* I - Attribute to convert */
4337 char *buffer, /* I - Buffer */
4338 size_t bufsize) /* I - Size of buffer */
4339{
4340 int i; /* Looping var */
4341 char *ptr, /* Pointer into buffer */
4342 *end, /* Pointer to end of buffer */
4343 *valptr; /* Pointer into string attribute */
4344
4345
4346 /*
4347 * Return quickly if we have a single string value...
4348 */
4349
4350 if (attr->num_values == 1 &&
4351 attr->value_tag != IPP_TAG_INTEGER &&
4352 attr->value_tag != IPP_TAG_ENUM &&
4353 attr->value_tag != IPP_TAG_BOOLEAN &&
4354 attr->value_tag != IPP_TAG_RANGE)
4355 return (attr->values[0].string.text);
4356
4357 /*
4358 * Copy the values to the string, separating with commas and escaping strings
4359 * as needed...
4360 */
4361
4362 end = buffer + bufsize - 1;
4363
4364 for (i = 0, ptr = buffer; i < attr->num_values && ptr < end; i ++)
4365 {
4366 if (i)
4367 *ptr++ = ',';
4368
4369 switch (attr->value_tag)
4370 {
4371 case IPP_TAG_INTEGER :
4372 case IPP_TAG_ENUM :
4373 snprintf(ptr, (size_t)(end - ptr + 1), "%d", attr->values[i].integer);
4374 break;
4375
4376 case IPP_TAG_BOOLEAN :
4377 if (attr->values[i].boolean)
4378 strlcpy(ptr, "true", (size_t)(end - ptr + 1));
4379 else
4380 strlcpy(ptr, "false", (size_t)(end - ptr + 1));
4381 break;
4382
4383 case IPP_TAG_RANGE :
4384 if (attr->values[i].range.lower == attr->values[i].range.upper)
4385 snprintf(ptr, (size_t)(end - ptr + 1), "%d", attr->values[i].range.lower);
4386 else
4387 snprintf(ptr, (size_t)(end - ptr + 1), "%d-%d", attr->values[i].range.lower, attr->values[i].range.upper);
4388 break;
4389
4390 default :
4391 for (valptr = attr->values[i].string.text;

Callers 1

_cupsGetDestsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected