]>
git.ipfire.org Git - thirdparty/cups.git/blob - scheduler/util.c
2 * "$Id: util.c 6649 2007-07-11 21:46:42Z mike $"
4 * Mini-daemon utility functions for the Common UNIX Printing System (CUPS).
6 * Copyright 2007 by Apple Inc.
7 * Copyright 1997-2005 by Easy Software Products.
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
17 * cupsdCompareNames() - Compare two names.
18 * cupsdSendIPPGroup() - Send a group tag.
19 * cupsdSendIPPHeader() - Send the IPP response header.
20 * cupsdSendIPPInteger() - Send an integer attribute.
21 * cupsdSendIPPString() - Send a string attribute.
22 * cupsdSendIPPTrailer() - Send the end-of-message tag.
26 * Include necessary headers...
33 * 'cupsdCompareNames()' - Compare two names.
35 * This function basically does a strcasecmp() of the two strings,
36 * but is also aware of numbers so that "a2" < "a100".
39 int /* O - Result of comparison */
40 cupsdCompareNames(const char *s
, /* I - First string */
41 const char *t
) /* I - Second string */
43 int diff
, /* Difference between digits */
44 digits
; /* Number of digits */
48 * Loop through both names, returning only when a difference is
49 * seen. Also, compare whole numbers rather than just characters, too!
54 if (isdigit(*s
& 255) && isdigit(*t
& 255))
57 * Got a number; start by skipping leading 0's...
66 * Skip equal digits...
69 while (isdigit(*s
& 255) && *s
== *t
)
76 * Bounce out if *s and *t aren't both digits...
79 if (isdigit(*s
& 255) && !isdigit(*t
& 255))
81 else if (!isdigit(*s
& 255) && isdigit(*t
& 255))
83 else if (!isdigit(*s
& 255) || !isdigit(*t
& 255))
92 * Figure out how many more digits there are...
99 while (isdigit(*s
& 255))
105 while (isdigit(*t
& 255))
112 * Return if the number or value of the digits is different...
122 else if (tolower(*s
) < tolower(*t
))
124 else if (tolower(*s
) > tolower(*t
))
134 * Return the results of the final comparison...
147 * 'cupsdSendIPPGroup()' - Send a group tag.
151 cupsdSendIPPGroup(ipp_tag_t group_tag
) /* I - Group tag */
154 * Send IPP group tag (1 byte)...
162 * 'cupsdSendIPPHeader()' - Send the IPP response header.
167 ipp_status_t status_code
, /* I - Status code */
168 int request_id
) /* I - Request ID */
171 * Send IPP/1.1 response header: version number (2 bytes), status code
172 * (2 bytes), and request ID (4 bytes)...
178 putchar(status_code
>> 8);
179 putchar(status_code
);
181 putchar(request_id
>> 24);
182 putchar(request_id
>> 16);
183 putchar(request_id
>> 8);
189 * 'cupsdSendIPPInteger()' - Send an integer attribute.
194 ipp_tag_t value_tag
, /* I - Value tag */
195 const char *name
, /* I - Attribute name */
196 int value
) /* I - Attribute value */
198 size_t len
; /* Length of attribute name */
202 * Send IPP integer value: value tag (1 byte), name length (2 bytes),
203 * name string (without nul), value length (2 bytes), and value (4 bytes)...
217 putchar(value
>> 24);
218 putchar(value
>> 16);
225 * 'cupsdSendIPPString()' - Send a string attribute.
230 ipp_tag_t value_tag
, /* I - Value tag */
231 const char *name
, /* I - Attribute name */
232 const char *value
) /* I - Attribute value */
234 size_t len
; /* Length of attribute name */
238 * Send IPP string value: value tag (1 byte), name length (2 bytes),
239 * name string (without nul), value length (2 bytes), and value string
255 fputs(value
, stdout
);
260 * 'cupsdSendIPPTrailer()' - Send the end-of-message tag.
264 cupsdSendIPPTrailer(void)
266 putchar(IPP_TAG_END
);
272 * End of "$Id: util.c 6649 2007-07-11 21:46:42Z mike $".