]>
git.ipfire.org Git - thirdparty/cups.git/blob - scheduler/util.c
2 * "$Id: util.c 5305 2006-03-18 03:05:12Z mike $"
4 * Mini-daemon utility functions for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2005 by Easy Software Products.
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
26 * cupsdCompareNames() - Compare two names.
27 * cupsdSendIPPGroup() - Send a group tag.
28 * cupsdSendIPPHeader() - Send the IPP response header.
29 * cupsdSendIPPInteger() - Send an integer attribute.
30 * cupsdSendIPPString() - Send a string attribute.
31 * cupsdSendIPPTrailer() - Send the end-of-message tag.
35 * Include necessary headers...
42 * 'cupsdCompareNames()' - Compare two names.
44 * This function basically does a strcasecmp() of the two strings,
45 * but is also aware of numbers so that "a2" < "a100".
48 int /* O - Result of comparison */
49 cupsdCompareNames(const char *s
, /* I - First string */
50 const char *t
) /* I - Second string */
52 int diff
, /* Difference between digits */
53 digits
; /* Number of digits */
57 * Loop through both names, returning only when a difference is
58 * seen. Also, compare whole numbers rather than just characters, too!
63 if (isdigit(*s
& 255) && isdigit(*t
& 255))
66 * Got a number; start by skipping leading 0's...
75 * Skip equal digits...
78 while (isdigit(*s
& 255) && *s
== *t
)
85 * Bounce out if *s and *t aren't both digits...
88 if (isdigit(*s
& 255) && !isdigit(*t
& 255))
90 else if (!isdigit(*s
& 255) && isdigit(*t
& 255))
92 else if (!isdigit(*s
& 255) || !isdigit(*t
& 255))
101 * Figure out how many more digits there are...
108 while (isdigit(*s
& 255))
114 while (isdigit(*t
& 255))
121 * Return if the number or value of the digits is different...
131 else if (tolower(*s
) < tolower(*t
))
133 else if (tolower(*s
) > tolower(*t
))
143 * Return the results of the final comparison...
156 * 'cupsdSendIPPGroup()' - Send a group tag.
160 cupsdSendIPPGroup(ipp_tag_t group_tag
) /* I - Group tag */
163 * Send IPP group tag (1 byte)...
171 * 'cupsdSendIPPHeader()' - Send the IPP response header.
176 ipp_status_t status_code
, /* I - Status code */
177 int request_id
) /* I - Request ID */
180 * Send IPP/1.1 response header: version number (2 bytes), status code
181 * (2 bytes), and request ID (4 bytes)...
187 putchar(status_code
>> 8);
188 putchar(status_code
);
190 putchar(request_id
>> 24);
191 putchar(request_id
>> 16);
192 putchar(request_id
>> 8);
197 #if 0 /* Not currently used */
199 * 'cupsdSendIPPInteger()' - Send an integer attribute.
204 ipp_tag_t value_tag
, /* I - Value tag */
205 const char *name
, /* I - Attribute name */
206 int value
) /* I - Attribute value */
208 size_t len
; /* Length of attribute name */
212 * Send IPP integer value: value tag (1 byte), name length (2 bytes),
213 * name string (without nul), and value (4 bytes)...
224 putchar(value
>> 24);
225 putchar(value
>> 16);
233 * 'cupsdSendIPPString()' - Send a string attribute.
238 ipp_tag_t value_tag
, /* I - Value tag */
239 const char *name
, /* I - Attribute name */
240 const char *value
) /* I - Attribute value */
242 size_t len
; /* Length of attribute name */
246 * Send IPP string value: value tag (1 byte), name length (2 bytes),
247 * name string (without nul), value length (2 bytes), and value string
263 fputs(value
, stdout
);
268 * 'cupsdSendIPPTrailer()' - Send the end-of-message tag.
272 cupsdSendIPPTrailer(void)
274 putchar(IPP_TAG_END
);
280 * End of "$Id: util.c 5305 2006-03-18 03:05:12Z mike $".