giftcurs-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[giFTcurs-commits] giFTcurs/src list.c list.h


From: Christian Häggström
Subject: [giFTcurs-commits] giFTcurs/src list.c list.h
Date: Thu, 27 Nov 2003 15:29:17 -0500

CVSROOT:        /cvsroot/giftcurs
Module name:    giFTcurs
Branch:         
Changes by:     Christian Häggström <address@hidden>    03/11/27 15:29:17

Modified files:
        src            : list.c list.h 

Log message:
        Revert a misbehaving CLAMP, and add some GNUC attributes

Patches:
Index: giFTcurs/src/list.c
diff -u giFTcurs/src/list.c:1.87 giFTcurs/src/list.c:1.88
--- giFTcurs/src/list.c:1.87    Sun Nov 16 11:15:35 2003
+++ giFTcurs/src/list.c Thu Nov 27 15:29:17 2003
@@ -18,7 +18,7 @@
  * along with giFTcurs; if not, write to the Free Software Foundation,
  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307,  USA.
  *
- * $Id: list.c,v 1.87 2003/11/16 16:15:35 weinholt Exp $
+ * $Id: list.c,v 1.88 2003/11/27 20:29:17 saturn Exp $
  */
 #include "giftcurs.h"
 
@@ -181,10 +181,20 @@
        /* Check against list frame */
        if (h <= soff * 2)
                soff = (h - 1) / 2;
+
+       /* Cannot use CLAMP below since order does matter */
+
        /* check against bottom */
-       snafu->start = CLAMP(snafu->start, snafu->sel - h + 1 + soff, 
snafu->num - h);
+       if (snafu->start < snafu->sel - h + 1 + soff)
+               snafu->start = snafu->sel - h + 1 + soff;
+       if (snafu->start > snafu->num - h)
+               snafu->start = snafu->num - h;
+
        /* check against top */
-       snafu->start = CLAMP(snafu->start, 0, snafu->sel - soff);
+       if (snafu->start > snafu->sel - soff)
+               snafu->start = snafu->sel - soff;
+       if (snafu->start < 0)
+               snafu->start = 0;
 }
 
 /* This is for list that don't have a selector */
@@ -197,7 +207,7 @@
                snafu->start = 0;
 }
 
-static void *list_member(list *snafu, int i)
+static G_GNUC_PURE void *list_member(const list *snafu, int i)
 {
        if (!snafu->num)
                return NULL;
@@ -207,12 +217,12 @@
        return snafu->entries[i];
 }
 
-void *list_selected(list *snafu)
+void *list_selected(const list *snafu)
 {
        return list_member(snafu, snafu->sel);
 }
 
-void *below_selected(list *snafu)
+void *below_selected(const list *snafu)
 {
        return list_member(snafu, snafu->sel + 1);
 }
@@ -220,8 +230,10 @@
 /* This finds out where 'item' should be inserted to keep list in order
  * It keeps track of lower and upper bound, always halving the possible range.
  * Therefore it's O(log n) */
-static int sortpos(void **l, CmpFunc cmp, const void *item, int lower, int 
upper)
+static G_GNUC_PURE int sortpos(void **l, CmpFunc cmp, const void *item, int 
upper)
 {
+       int lower = 0;
+
        while (upper != lower) {
                int mid, res;
                void *item2;
@@ -234,7 +246,7 @@
                if (item == item2)
                        return mid;
 
-               res = cmp(item, l[mid]);
+               res = cmp(item, item2);
 
                if (res < 0)
                        upper = mid;
@@ -258,7 +270,7 @@
 
        if (pos > 0 && cmp(l->entries[pos - 1], item) > 0) {
                /* sort item towards lower index */
-               int newpos = sortpos(l->entries, cmp, item, 0, pos);
+               int newpos = sortpos(l->entries, cmp, item, pos);
 
                memmove(l->entries + newpos + 1, l->entries + newpos, (pos - 
newpos) * sizeof(void *));
                l->entries[newpos] = item;
@@ -272,9 +284,10 @@
                }
        } else if (pos < l->num - 1 && cmp(item, l->entries[pos + 1]) > 0) {
                /* sort item towards higher index */
-               int newpos = sortpos(l->entries, cmp, item, pos + 1, l->num) - 
1;
+               int newpos = sortpos(l->entries + pos + 1, cmp, item, l->num - 
pos - 1);
 
-               memmove(l->entries + pos, l->entries + pos + 1, (newpos - pos) 
* sizeof(void *));
+               memmove(l->entries + pos, l->entries + pos + 1, newpos * 
sizeof(void *));
+               newpos += pos;
                l->entries[newpos] = item;
 
                if (l->sel >= 0) {
@@ -314,7 +327,7 @@
                while (cmp(pivot, *hi) <= 0);
                *lo = *hi;
        }
-  done:
+done:
        *lo = pivot;
        my_qsort(lo + 1, last, cmp);
        my_qsort(base, lo - 1, cmp);
@@ -371,7 +384,7 @@
        return count;
 }
 
-int list_find(list *snafu, const void *elem)
+int list_find(const list *snafu, const void *elem)
 {
        int i;
        CmpFunc cmp = snafu->order;
@@ -379,7 +392,7 @@
        if (!cmp)
                return dynarray_find((dynarray *) snafu, elem);
 
-       i = sortpos(snafu->entries, cmp, elem, 0, snafu->num);
+       i = sortpos(snafu->entries, cmp, elem, snafu->num);
 
        if (i < snafu->num && cmp(elem, snafu->entries[i]) == 0)
                return i;
Index: giFTcurs/src/list.h
diff -u giFTcurs/src/list.h:1.52 giFTcurs/src/list.h:1.53
--- giFTcurs/src/list.h:1.52    Mon Sep 15 17:28:19 2003
+++ giFTcurs/src/list.h Thu Nov 27 15:29:17 2003
@@ -18,7 +18,7 @@
  * along with giFTcurs; if not, write to the Free Software Foundation,
  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307,  USA.
  *
- * $Id: list.h,v 1.52 2003/09/15 21:28:19 saturn Exp $
+ * $Id: list.h,v 1.53 2003/11/27 20:29:17 saturn Exp $
  */
 #ifndef _LIST_H
 #define _LIST_H
@@ -65,17 +65,17 @@
 void list_check_values_simple(list *, int h);
 
 /* return the selected entry */
-void *list_selected(list *);
+void *list_selected(const list *) G_GNUC_PURE;
 
 /* return the entry below selected entry */
-void *below_selected(list *);
+void *below_selected(const list *) G_GNUC_PURE;
 
 /* Sorts a list and keep it sorted */
 /* If compare funcion takes a third parameter, snafu->udata is sent */
 void list_sort(list *snafu, CmpFunc order);
 
 /* simple CmpFunc that sorts after address */
-int compare_pointers(const void *a, const void *b);
+int compare_pointers(const void *a, const void *b) G_GNUC_CONST;
 
 /* insert an entry into a sorted list */
 int list_resort(list *snafu, int pos);
@@ -91,7 +91,7 @@
 /* unsorted list: find the pointer in list
  * sorted list: find element equal to list according to the compare function
  */
-int list_find(list *snafu, const void *elem);
+int list_find(const list *snafu, const void *elem) G_GNUC_PURE;
 
 /* set scroll offset */
 void list_set_scrolloff(int val);
@@ -104,7 +104,7 @@
 void dynarray_remove_fast(dynarray *arry, const void *item);
 void dynarray_foreach(const dynarray *arry, LFunc func);
 void dynarray_removeall(dynarray *arry);
-int dynarray_find(const dynarray *arry, const void *item);
+int dynarray_find(const dynarray *arry, const void *item) G_GNUC_PURE;
 void *dynarray_pop(dynarray *arry);
 
 #endif




reply via email to

[Prev in Thread] Current Thread [Next in Thread]