Lines Matching +full:check +full:- +full:macos
4 * Copyright 2007-2014 by Apple Inc.
5 * Copyright 1997-2007 by Easy Software Products.
15 #include "string-private.h"
16 #include "debug-internal.h"
17 #include "array-private.h"
68 * 'cupsArrayAdd()' - Add an element to the array.
70 * When adding an element to a sorted array, non-unique elements are
74 * @since CUPS 1.2/macOS 10.5@
77 int /* O - 1 on success, 0 on failure */
78 cupsArrayAdd(cups_array_t *a, /* I - Array */ in cupsArrayAdd()
79 void *e) /* I - Element */ in cupsArrayAdd()
84 * Range check input... in cupsArrayAdd()
102 * '_cupsArrayAddStrings()' - Add zero or more delimited strings to an array.
109 int /* O - 1 on success, 0 on failure */
110 _cupsArrayAddStrings(cups_array_t *a, /* I - Array */ in _cupsArrayAddStrings()
111 const char *s, /* I - Delimited strings or NULL */ in _cupsArrayAddStrings()
112 char delim)/* I - Delimiter character */ in _cupsArrayAddStrings()
198 * 'cupsArrayClear()' - Clear the array.
204 * @since CUPS 1.2/macOS 10.5@
208 cupsArrayClear(cups_array_t *a) /* I - Array */ in cupsArrayClear()
211 * Range check input... in cupsArrayClear()
221 if (a->freefunc) in cupsArrayClear()
226 for (i = a->num_elements, e = a->elements; i > 0; i --, e ++) in cupsArrayClear()
227 (a->freefunc)(*e, a->data); in cupsArrayClear()
232 * here - that is done in cupsArrayDelete()... in cupsArrayClear()
235 a->num_elements = 0; in cupsArrayClear()
236 a->current = -1; in cupsArrayClear()
237 a->insert = -1; in cupsArrayClear()
238 a->unique = 1; in cupsArrayClear()
239 a->num_saved = 0; in cupsArrayClear()
244 * 'cupsArrayCount()' - Get the number of elements in the array.
246 * @since CUPS 1.2/macOS 10.5@
249 int /* O - Number of elements */
250 cupsArrayCount(cups_array_t *a) /* I - Array */ in cupsArrayCount()
253 * Range check input... in cupsArrayCount()
263 return (a->num_elements); in cupsArrayCount()
268 * 'cupsArrayCurrent()' - Return the current element in the array.
273 * @since CUPS 1.2/macOS 10.5@
276 void * /* O - Element */
277 cupsArrayCurrent(cups_array_t *a) /* I - Array */ in cupsArrayCurrent()
280 * Range check input... in cupsArrayCurrent()
290 if (a->current >= 0 && a->current < a->num_elements) in cupsArrayCurrent()
291 return (a->elements[a->current]); in cupsArrayCurrent()
298 * 'cupsArrayDelete()' - Free all memory used by the array.
303 * @since CUPS 1.2/macOS 10.5@
307 cupsArrayDelete(cups_array_t *a) /* I - Array */ in cupsArrayDelete()
310 * Range check input... in cupsArrayDelete()
321 if (a->freefunc) in cupsArrayDelete()
326 for (i = a->num_elements, e = a->elements; i > 0; i --, e ++) in cupsArrayDelete()
327 (a->freefunc)(*e, a->data); in cupsArrayDelete()
334 if (a->alloc_elements) in cupsArrayDelete()
335 free(a->elements); in cupsArrayDelete()
337 if (a->hashsize) in cupsArrayDelete()
338 free(a->hash); in cupsArrayDelete()
345 * 'cupsArrayDup()' - Duplicate the array.
347 * @since CUPS 1.2/macOS 10.5@
350 cups_array_t * /* O - Duplicate array */
351 cupsArrayDup(cups_array_t *a) /* I - Array */ in cupsArrayDup()
357 * Range check input... in cupsArrayDup()
371 da->compare = a->compare; in cupsArrayDup()
372 da->data = a->data; in cupsArrayDup()
373 da->current = a->current; in cupsArrayDup()
374 da->insert = a->insert; in cupsArrayDup()
375 da->unique = a->unique; in cupsArrayDup()
376 da->num_saved = a->num_saved; in cupsArrayDup()
378 memcpy(da->saved, a->saved, sizeof(a->saved)); in cupsArrayDup()
380 if (a->num_elements) in cupsArrayDup()
386 da->elements = malloc((size_t)a->num_elements * sizeof(void *)); in cupsArrayDup()
387 if (!da->elements) in cupsArrayDup()
397 if (a->copyfunc) in cupsArrayDup()
405 for (i = 0; i < a->num_elements; i ++) in cupsArrayDup()
406 da->elements[i] = (a->copyfunc)(a->elements[i], a->data); in cupsArrayDup()
414 memcpy(da->elements, a->elements, (size_t)a->num_elements * sizeof(void *)); in cupsArrayDup()
417 da->num_elements = a->num_elements; in cupsArrayDup()
418 da->alloc_elements = a->num_elements; in cupsArrayDup()
430 * 'cupsArrayFind()' - Find an element in the array.
432 * @since CUPS 1.2/macOS 10.5@
435 void * /* O - Element found or @code NULL@ */
436 cupsArrayFind(cups_array_t *a, /* I - Array */ in cupsArrayFind()
437 void *e) /* I - Element */ in cupsArrayFind()
445 * Range check input... in cupsArrayFind()
455 if (!a->num_elements) in cupsArrayFind()
462 if (a->hash) in cupsArrayFind()
464 hash = (*(a->hashfunc))(e, a->data); in cupsArrayFind()
466 if (hash < 0 || hash >= a->hashsize) in cupsArrayFind()
468 current = a->current; in cupsArrayFind()
469 hash = -1; in cupsArrayFind()
473 current = a->hash[hash]; in cupsArrayFind()
475 if (current < 0 || current >= a->num_elements) in cupsArrayFind()
476 current = a->current; in cupsArrayFind()
481 current = a->current; in cupsArrayFind()
482 hash = -1; in cupsArrayFind()
493 if (!a->unique && a->compare) in cupsArrayFind()
499 while (current > 0 && !(*(a->compare))(e, a->elements[current - 1], in cupsArrayFind()
500 a->data)) in cupsArrayFind()
501 current --; in cupsArrayFind()
504 a->current = current; in cupsArrayFind()
507 a->hash[hash] = current; in cupsArrayFind()
509 return (a->elements[current]); in cupsArrayFind()
517 a->current = -1; in cupsArrayFind()
525 * 'cupsArrayFirst()' - Get the first element in the array.
527 * @since CUPS 1.2/macOS 10.5@
530 void * /* O - First element or @code NULL@ if the array is empty */
531 cupsArrayFirst(cups_array_t *a) /* I - Array */ in cupsArrayFirst()
534 * Range check input... in cupsArrayFirst()
544 a->current = 0; in cupsArrayFirst()
551 * 'cupsArrayGetIndex()' - Get the index of the current element.
556 * @since CUPS 1.3/macOS 10.5@
559 int /* O - Index of the current element, starting at 0 */
560 cupsArrayGetIndex(cups_array_t *a) /* I - Array */ in cupsArrayGetIndex()
563 return (-1); in cupsArrayGetIndex()
565 return (a->current); in cupsArrayGetIndex()
570 * 'cupsArrayGetInsert()' - Get the index of the last inserted element.
572 * @since CUPS 1.3/macOS 10.5@
575 int /* O - Index of the last inserted element, starting at 0 */
576 cupsArrayGetInsert(cups_array_t *a) /* I - Array */ in cupsArrayGetInsert()
579 return (-1); in cupsArrayGetInsert()
581 return (a->insert); in cupsArrayGetInsert()
586 * 'cupsArrayIndex()' - Get the N-th element in the array.
588 * @since CUPS 1.2/macOS 10.5@
591 void * /* O - N-th element or @code NULL@ */
592 cupsArrayIndex(cups_array_t *a, /* I - Array */ in cupsArrayIndex()
593 int n) /* I - Index into array, starting at 0 */ in cupsArrayIndex()
598 a->current = n; in cupsArrayIndex()
605 * 'cupsArrayInsert()' - Insert an element in the array.
607 * When inserting an element in a sorted array, non-unique elements are
611 * @since CUPS 1.2/macOS 10.5@
614 int /* O - 0 on failure, 1 on success */
615 cupsArrayInsert(cups_array_t *a, /* I - Array */ in cupsArrayInsert()
616 void *e) /* I - Element */ in cupsArrayInsert()
621 * Range check input... in cupsArrayInsert()
639 * 'cupsArrayLast()' - Get the last element in the array.
641 * @since CUPS 1.2/macOS 10.5@
644 void * /* O - Last element or @code NULL@ if the array is empty */
645 cupsArrayLast(cups_array_t *a) /* I - Array */ in cupsArrayLast()
648 * Range check input... in cupsArrayLast()
658 a->current = a->num_elements - 1; in cupsArrayLast()
665 * 'cupsArrayNew()' - Create a new array.
668 * receives pointers to two elements and the user data pointer ("d") - the user
672 * @since CUPS 1.2/macOS 10.5@
675 cups_array_t * /* O - Array */
676 cupsArrayNew(cups_array_func_t f, /* I - Comparison function or @code NULL@ for an unsorted array */ in cupsArrayNew()
677 void *d) /* I - User data pointer or @code NULL@ */ in cupsArrayNew()
684 * 'cupsArrayNew2()' - Create a new array with hash.
687 * receives pointers to two elements and the user data pointer ("d") - the user
694 * @since CUPS 1.3/macOS 10.5@
697 cups_array_t * /* O - Array */
698 cupsArrayNew2(cups_array_func_t f, /* I - Comparison function or @code NULL@ for an unsorted array… in cupsArrayNew2()
699 void *d, /* I - User data or @code NULL@ */ in cupsArrayNew2()
700 cups_ahash_func_t h, /* I - Hash function or @code NULL@ for unhashed lookups */ in cupsArrayNew2()
701 int hsize) /* I - Hash size (>= 0) */ in cupsArrayNew2()
708 * 'cupsArrayNew3()' - Create a new array with hash and/or free function.
711 * receives pointers to two elements and the user data pointer ("d") - the user
724 * @since CUPS 1.5/macOS 10.7@
727 cups_array_t * /* O - Array */
728 cupsArrayNew3(cups_array_func_t f, /* I - Comparison function or @code NULL@ for an unsorted array… in cupsArrayNew3()
729 void *d, /* I - User data or @code NULL@ */ in cupsArrayNew3()
730 cups_ahash_func_t h, /* I - Hash function or @code NULL@ for unhashed lookups */ in cupsArrayNew3()
731 int hsize, /* I - Hash size (>= 0) */ in cupsArrayNew3()
732 cups_acopy_func_t cf, /* I - Copy function */ in cupsArrayNew3()
733 cups_afree_func_t ff) /* I - Free function */ in cupsArrayNew3()
746 a->compare = f; in cupsArrayNew3()
747 a->data = d; in cupsArrayNew3()
748 a->current = -1; in cupsArrayNew3()
749 a->insert = -1; in cupsArrayNew3()
750 a->num_saved = 0; in cupsArrayNew3()
751 a->unique = 1; in cupsArrayNew3()
755 a->hashfunc = h; in cupsArrayNew3()
756 a->hashsize = hsize; in cupsArrayNew3()
757 a->hash = malloc((size_t)hsize * sizeof(int)); in cupsArrayNew3()
759 if (!a->hash) in cupsArrayNew3()
765 memset(a->hash, -1, (size_t)hsize * sizeof(int)); in cupsArrayNew3()
768 a->copyfunc = cf; in cupsArrayNew3()
769 a->freefunc = ff; in cupsArrayNew3()
776 * '_cupsArrayNewStrings()' - Create a new array of comma-delimited strings.
783 cups_array_t * /* O - Array */
784 _cupsArrayNewStrings(const char *s, /* I - Delimited strings or NULL */ in _cupsArrayNewStrings()
785 char delim) /* I - Delimiter character */ in _cupsArrayNewStrings()
800 * 'cupsArrayNext()' - Get the next element in the array.
808 * @since CUPS 1.2/macOS 10.5@
811 void * /* O - Next element or @code NULL@ */
812 cupsArrayNext(cups_array_t *a) /* I - Array */ in cupsArrayNext()
815 * Range check input... in cupsArrayNext()
825 if (a->current < a->num_elements) in cupsArrayNext()
826 a->current ++; in cupsArrayNext()
833 * 'cupsArrayPrev()' - Get the previous element in the array.
835 * This function is equivalent to "cupsArrayIndex(a, cupsArrayGetIndex(a) - 1)".
841 * @since CUPS 1.2/macOS 10.5@
844 void * /* O - Previous element or @code NULL@ */
845 cupsArrayPrev(cups_array_t *a) /* I - Array */ in cupsArrayPrev()
848 * Range check input... in cupsArrayPrev()
858 if (a->current >= 0) in cupsArrayPrev()
859 a->current --; in cupsArrayPrev()
866 * 'cupsArrayRemove()' - Remove an element from the array.
874 * @since CUPS 1.2/macOS 10.5@
877 int /* O - 1 on success, 0 on failure */
878 cupsArrayRemove(cups_array_t *a, /* I - Array */ in cupsArrayRemove()
879 void *e) /* I - Element */ in cupsArrayRemove()
887 * Range check input... in cupsArrayRemove()
897 if (!a->num_elements) in cupsArrayRemove()
900 current = cups_array_find(a, e, a->current, &diff); in cupsArrayRemove()
908 a->num_elements --; in cupsArrayRemove()
910 if (a->freefunc) in cupsArrayRemove()
911 (a->freefunc)(a->elements[current], a->data); in cupsArrayRemove()
913 if (current < a->num_elements) in cupsArrayRemove()
914 memmove(a->elements + current, a->elements + current + 1, in cupsArrayRemove()
915 (size_t)(a->num_elements - current) * sizeof(void *)); in cupsArrayRemove()
917 if (current <= a->current) in cupsArrayRemove()
918 a->current --; in cupsArrayRemove()
920 if (current < a->insert) in cupsArrayRemove()
921 a->insert --; in cupsArrayRemove()
922 else if (current == a->insert) in cupsArrayRemove()
923 a->insert = -1; in cupsArrayRemove()
925 for (i = 0; i < a->num_saved; i ++) in cupsArrayRemove()
926 if (current <= a->saved[i]) in cupsArrayRemove()
927 a->saved[i] --; in cupsArrayRemove()
929 if (a->num_elements <= 1) in cupsArrayRemove()
930 a->unique = 1; in cupsArrayRemove()
937 * 'cupsArrayRestore()' - Reset the current element to the last @link cupsArraySave@.
939 * @since CUPS 1.2/macOS 10.5@
942 void * /* O - New current element */
943 cupsArrayRestore(cups_array_t *a) /* I - Array */ in cupsArrayRestore()
948 if (a->num_saved <= 0) in cupsArrayRestore()
951 a->num_saved --; in cupsArrayRestore()
952 a->current = a->saved[a->num_saved]; in cupsArrayRestore()
954 if (a->current >= 0 && a->current < a->num_elements) in cupsArrayRestore()
955 return (a->elements[a->current]); in cupsArrayRestore()
962 * 'cupsArraySave()' - Mark the current element for a later @link cupsArrayRestore@.
970 * @since CUPS 1.2/macOS 10.5@
973 int /* O - 1 on success, 0 on failure */
974 cupsArraySave(cups_array_t *a) /* I - Array */ in cupsArraySave()
979 if (a->num_saved >= _CUPS_MAXSAVE) in cupsArraySave()
982 a->saved[a->num_saved] = a->current; in cupsArraySave()
983 a->num_saved ++; in cupsArraySave()
990 * 'cupsArrayUserData()' - Return the user data for an array.
992 * @since CUPS 1.2/macOS 10.5@
995 void * /* O - User data */
996 cupsArrayUserData(cups_array_t *a) /* I - Array */ in cupsArrayUserData()
999 return (a->data); in cupsArrayUserData()
1006 * 'cups_array_add()' - Insert or append an element to the array.
1008 * @since CUPS 1.2/macOS 10.5@
1011 static int /* O - 1 on success, 0 on failure */
1012 cups_array_add(cups_array_t *a, /* I - Array */ in cups_array_add()
1013 void *e, /* I - Element to add */ in cups_array_add()
1014 int insert) /* I - 1 = insert, 0 = append */ in cups_array_add()
1027 if (a->num_elements >= a->alloc_elements) in cups_array_add()
1039 if (a->alloc_elements == 0) in cups_array_add()
1046 if (a->alloc_elements < 1024) in cups_array_add()
1047 count = a->alloc_elements * 2; in cups_array_add()
1049 count = a->alloc_elements + 1024; in cups_array_add()
1051 temp = realloc(a->elements, (size_t)count * sizeof(void *)); in cups_array_add()
1062 a->alloc_elements = count; in cups_array_add()
1063 a->elements = temp; in cups_array_add()
1071 if (!a->num_elements || !a->compare) in cups_array_add()
1080 current = a->num_elements; /* Append to the end */ in cups_array_add()
1088 current = cups_array_find(a, e, a->insert, &diff); in cups_array_add()
1105 a->unique = 0; in cups_array_add()
1113 while (current > 0 && !(*(a->compare))(e, a->elements[current - 1], in cups_array_add()
1114 a->data)) in cups_array_add()
1115 current --; in cups_array_add()
1127 while (current < a->num_elements && in cups_array_add()
1128 !(*(a->compare))(e, a->elements[current], a->data)); in cups_array_add()
1137 if (current < a->num_elements) in cups_array_add()
1143 memmove(a->elements + current + 1, a->elements + current, in cups_array_add()
1144 (size_t)(a->num_elements - current) * sizeof(void *)); in cups_array_add()
1146 if (a->current >= current) in cups_array_add()
1147 a->current ++; in cups_array_add()
1149 for (i = 0; i < a->num_saved; i ++) in cups_array_add()
1150 if (a->saved[i] >= current) in cups_array_add()
1151 a->saved[i] ++; in cups_array_add()
1160 if (a->copyfunc) in cups_array_add()
1162 if ((a->elements[current] = (a->copyfunc)(e, a->data)) == NULL) in cups_array_add()
1169 a->elements[current] = e; in cups_array_add()
1171 a->num_elements ++; in cups_array_add()
1172 a->insert = current; in cups_array_add()
1175 for (current = 0; current < a->num_elements; current ++) in cups_array_add()
1176 …DEBUG_printf(("9cups_array_add: a->elements[" CUPS_LLFMT "]=%p", CUPS_LLCAST current, a->elements[… in cups_array_add()
1186 * 'cups_array_find()' - Find an element in the array.
1189 static int /* O - Index of match */
1190 cups_array_find(cups_array_t *a, /* I - Array */ in cups_array_find()
1191 void *e, /* I - Element */ in cups_array_find()
1192 int prev, /* I - Previous index */ in cups_array_find()
1193 int *rdiff) /* O - Difference of match */ in cups_array_find()
1203 if (a->compare) in cups_array_find()
1211 if (prev >= 0 && prev < a->num_elements) in cups_array_find()
1217 if ((diff = (*(a->compare))(e, a->elements[prev], a->data)) == 0 || in cups_array_find()
1219 (diff > 0 && prev == (a->num_elements - 1))) in cups_array_find()
1247 right = a->num_elements - 1; in cups_array_find()
1257 right = a->num_elements - 1; in cups_array_find()
1263 diff = (*(a->compare))(e, a->elements[current], a->data); in cups_array_find()
1275 while ((right - left) > 1); in cups_array_find()
1280 * Check the last 1 or 2 elements... in cups_array_find()
1283 if ((diff = (*(a->compare))(e, a->elements[left], a->data)) <= 0) in cups_array_find()
1287 diff = (*(a->compare))(e, a->elements[right], a->data); in cups_array_find()
1302 for (current = 0; current < a->num_elements; current ++) in cups_array_find()
1303 if (a->elements[current] == e) in cups_array_find()