| 876 | */ |
| 877 | |
| 878 | int /* O - 1 on success, 0 on failure */ |
| 879 | cupsArrayRemove(cups_array_t *a, /* I - Array */ |
| 880 | void *e) /* I - Element */ |
| 881 | { |
| 882 | ssize_t i, /* Looping var */ |
| 883 | current; /* Current element */ |
| 884 | int diff; /* Difference */ |
| 885 | |
| 886 | |
| 887 | /* |
| 888 | * Range check input... |
| 889 | */ |
| 890 | |
| 891 | if (!a || !e) |
| 892 | return (0); |
| 893 | |
| 894 | /* |
| 895 | * See if the element is in the array... |
| 896 | */ |
| 897 | |
| 898 | if (!a->num_elements) |
| 899 | return (0); |
| 900 | |
| 901 | current = cups_array_find(a, e, a->current, &diff); |
| 902 | if (diff) |
| 903 | return (0); |
| 904 | |
| 905 | /* |
| 906 | * Yes, now remove it... |
| 907 | */ |
| 908 | |
| 909 | a->num_elements --; |
| 910 | |
| 911 | if (a->freefunc) |
| 912 | (a->freefunc)(a->elements[current], a->data); |
| 913 | |
| 914 | if (current < a->num_elements) |
| 915 | memmove(a->elements + current, a->elements + current + 1, |
| 916 | (size_t)(a->num_elements - current) * sizeof(void *)); |
| 917 | |
| 918 | if (current <= a->current) |
| 919 | a->current --; |
| 920 | |
| 921 | if (current < a->insert) |
| 922 | a->insert --; |
| 923 | else if (current == a->insert) |
| 924 | a->insert = -1; |
| 925 | |
| 926 | for (i = 0; i < a->num_saved; i ++) |
| 927 | if (current <= a->saved[i]) |
| 928 | a->saved[i] --; |
| 929 | |
| 930 | if (a->num_elements <= 1) |
| 931 | a->unique = 1; |
| 932 | |
| 933 | return (1); |
| 934 | } |
| 935 | |