]>
git.ipfire.org Git - thirdparty/cups.git/blob - scheduler/util.c
2 * "$Id: util.c 4719 2005-09-28 21:12:44Z 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);
198 * 'cupsdSendIPPInteger()' - Send an integer attribute.
203 ipp_tag_t value_tag
, /* I - Value tag */
204 const char *name
, /* I - Attribute name */
205 int value
) /* I - Attribute value */
207 size_t len
; /* Length of attribute name */
211 * Send IPP integer value: value tag (1 byte), name length (2 bytes),
212 * name string (without nul), and value (4 bytes)...
223 putchar(value
>> 24);
224 putchar(value
>> 16);
231 * 'cupsdSendIPPString()' - Send a string attribute.
236 ipp_tag_t value_tag
, /* I - Value tag */
237 const char *name
, /* I - Attribute name */
238 const char *value
) /* I - Attribute value */
240 size_t len
; /* Length of attribute name */
244 * Send IPP string value: value tag (1 byte), name length (2 bytes),
245 * name string (without nul), value length (2 bytes), and value string
261 fputs(value
, stdout
);
266 * 'cupsdSendIPPTrailer()' - Send the end-of-message tag.
270 cupsdSendIPPTrailer(void)
272 putchar(IPP_TAG_END
);
278 * End of "$Id: util.c 4719 2005-09-28 21:12:44Z mike $".