r15838 - gnucash/trunk/src/engine - The function name xaccSplitDateOrder is misleading, so rename it to

David Hampton hampton at cvs.gnucash.org
Thu Apr 5 22:31:29 EDT 2007


Author: hampton
Date: 2007-04-05 22:31:28 -0400 (Thu, 05 Apr 2007)
New Revision: 15838
Trac: http://svn.gnucash.org/trac/changeset/15838

Modified:
   gnucash/trunk/src/engine/Account.c
   gnucash/trunk/src/engine/Split.c
   gnucash/trunk/src/engine/Split.h
   gnucash/trunk/src/engine/Transaction.c
   gnucash/trunk/src/engine/gnc-lot.c
Log:
The function name xaccSplitDateOrder is misleading, so rename it to
xaccSplitOrder.  Add a new xaccSplitOrderDateOnly function.


Modified: gnucash/trunk/src/engine/Account.c
===================================================================
--- gnucash/trunk/src/engine/Account.c	2007-04-06 02:22:29 UTC (rev 15837)
+++ gnucash/trunk/src/engine/Account.c	2007-04-06 02:31:28 UTC (rev 15838)
@@ -804,7 +804,7 @@
 {
   if (!acc || !acc->sort_dirty || (!force && acc->inst.editlevel > 0)) return;
 
-  acc->splits = g_list_sort(acc->splits, (GCompareFunc)xaccSplitDateOrder);
+  acc->splits = g_list_sort(acc->splits, (GCompareFunc)xaccSplitOrder);
   acc->sort_dirty = FALSE;
   acc->balance_dirty = TRUE;
 }

Modified: gnucash/trunk/src/engine/Split.c
===================================================================
--- gnucash/trunk/src/engine/Split.c	2007-04-06 02:22:29 UTC (rev 15837)
+++ gnucash/trunk/src/engine/Split.c	2007-04-06 02:31:28 UTC (rev 15838)
@@ -525,7 +525,7 @@
         if (!g_list_find(acc->splits, s)) {
             if (acc->inst.editlevel == 0) {
                 acc->splits = g_list_insert_sorted(
-                    acc->splits, s, (GCompareFunc)xaccSplitDateOrder);
+                    acc->splits, s, (GCompareFunc)xaccSplitOrder);
             } else {
                 acc->splits = g_list_prepend(acc->splits, s);
                 acc->sort_dirty = TRUE;
@@ -1126,8 +1126,8 @@
 /********************************************************************\
 \********************************************************************/
 
-int
-xaccSplitDateOrder (const Split *sa, const Split *sb)
+gint
+xaccSplitOrder (const Split *sa, const Split *sb)
 {
   int retval;
   int comp;
@@ -1178,6 +1178,30 @@
   return 0;
 }
 
+gint
+xaccSplitOrderDateOnly (const Split *sa, const Split *sb)
+{
+  Transaction *ta, *tb;
+
+  if (sa == sb) return 0;
+  /* nothing is always less than something */
+  if (!sa && sb) return -1;
+  if (sa && !sb) return +1;
+
+  ta = sa->parent;
+  tb = sb->parent;
+  if ( ta && !tb ) return -1;
+  if ( !ta && tb ) return +1;
+  if ( !ta && !tb ) return 0;
+
+  /* if dates differ, return */
+  DATE_CMP(ta,tb,date_posted);
+
+  /* If the dates are the same, do not change the order */
+  return -1;
+}
+
+
 static gboolean
 get_corr_account_split(const Split *sa, const Split **retval)
 {
@@ -1843,7 +1867,7 @@
     { NULL },
   };
 
-  qof_class_register (GNC_ID_SPLIT, (QofSortFunc)xaccSplitDateOrder, params);
+  qof_class_register (GNC_ID_SPLIT, (QofSortFunc)xaccSplitOrder, params);
   qof_class_register (SPLIT_ACCT_FULLNAME,
                       (QofSortFunc)xaccSplitCompareAccountFullNames, NULL);
   qof_class_register (SPLIT_CORR_ACCT_NAME,

Modified: gnucash/trunk/src/engine/Split.h
===================================================================
--- gnucash/trunk/src/engine/Split.h	2007-04-06 02:22:29 UTC (rev 15837)
+++ gnucash/trunk/src/engine/Split.h	2007-04-06 02:31:28 UTC (rev 15838)
@@ -348,7 +348,7 @@
 void xaccSplitMakeStockSplit(Split *s);
 
 /**
- * The xaccSplitDateOrder(sa,sb) method is useful for sorting.
+ * The xaccSplitOrder(sa,sb) method is useful for sorting.
  *    if sa and sb have different transactions, return their xaccTransOrder
  *    return a negative value if split sa has a smaller currency-value than sb,
  *    return a positive value if split sa has a larger currency-value than sb,
@@ -359,7 +359,8 @@
  *    Then it compares the reconciled flags, then the reconciled dates,
  *    Finally, it returns zero if all of the above match.
  */
-int  xaccSplitDateOrder (const Split *sa, const Split *sb);
+gint xaccSplitOrder (const Split *sa, const Split *sb);
+gint xaccSplitOrderDateOnly (const Split *sa, const Split *sb);
 
 
 /*

Modified: gnucash/trunk/src/engine/Transaction.c
===================================================================
--- gnucash/trunk/src/engine/Transaction.c	2007-04-06 02:22:29 UTC (rev 15837)
+++ gnucash/trunk/src/engine/Transaction.c	2007-04-06 02:31:28 UTC (rev 15838)
@@ -777,7 +777,7 @@
 
     /* This test needs to correspond to the comparison function used when
        sorting the splits for computing the running balance. */
-    if (xaccSplitDateOrder (last_split, split) < 0)
+    if (xaccSplitOrder (last_split, split) < 0)
       last_split = split;
   }
 

Modified: gnucash/trunk/src/engine/gnc-lot.c
===================================================================
--- gnucash/trunk/src/engine/gnc-lot.c	2007-04-06 02:22:29 UTC (rev 15837)
+++ gnucash/trunk/src/engine/gnc-lot.c	2007-04-06 02:31:28 UTC (rev 15838)
@@ -375,7 +375,7 @@
 {
   if (! lot->splits)
     return NULL;
-  lot->splits = g_list_sort (lot->splits, (GCompareFunc) xaccSplitDateOrder);
+  lot->splits = g_list_sort (lot->splits, (GCompareFunc) xaccSplitOrderDateOnly);
   return lot->splits->data;
 }
 
@@ -386,7 +386,7 @@
 
   if (! lot->splits)
     return NULL;
-  lot->splits = g_list_sort (lot->splits, (GCompareFunc) xaccSplitDateOrder);
+  lot->splits = g_list_sort (lot->splits, (GCompareFunc) xaccSplitOrderDateOnly);
 
   for (node = lot->splits; node->next; node = node->next)
     ;



More information about the gnucash-changes mailing list