about check number heuristics

Ethy H. Brito ethy.brito at inexo.com.br
Sun Jan 28 12:42:47 EST 2007


On Fri, 26 Jan 2007 22:18:19 +0100
Christian Stimming <stimming at tuhh.de> wrote:

> 
> > If you think this is not necessary (maybe this is a "problem" complained by
> > myself only) I am satisfied with my (unsent) small patch. My sole intention
> > was to contribute. ;-)
> 
> Feel free to submit the patch, even if it seems small to you.


Ok. I couldn't make my point about my patch proposal.

Please find bellow my small patch to deal with check numbers as long integers.
(I still think this is not the right place to make the changes.)

Hope this pleases you guys.

Ethy

--- import-backend.c.distrib	2007-01-27 19:44:42.000000000 -0200
+++ import-backend.c	2007-01-28 14:54:07.000000000 -0200
@@ -31,7 +31,8 @@
 #include <glib/gi18n.h>
 #include <stdlib.h> 
 #include <math.h>
-
+#include <errno.h>
+                     
 #include "gnc-gconf-utils.h"
 #include "import-backend.h"
 #include "import-utilities.h"
@@ -658,23 +659,44 @@
       
       /* Check number heuristics */  
       if(strlen(xaccTransGetNum(new_trans))!=0)
-	{     
-	  if((strcmp(xaccTransGetNum (new_trans),
-		     xaccTransGetNum(xaccSplitGetParent(split)))
-	      ==0))
-	    {	
-	      /*An exact match of the Check number gives a +4 */
-	      prob = prob+4;
-	      /*DEBUG("heuristics:  probability + 5 (Check number)");*/
-	    }
-	  else if(strlen(xaccTransGetNum(new_trans)) > 0 &&
-		  strlen(xaccTransGetNum(xaccSplitGetParent(split))) > 0)
-	    {
-	      /* If both number are not empty yet do not match, add a little extre penality */
-	      prob = prob-2;
-	    }
-	}
-      
+        { 
+          long new_trans_number, split_number;
+          const gchar *new_trans_str, *split_str;
+          char *endptr;
+          int conversion_ok=1;
+          
+          new_trans_str = xaccTransGetNum (new_trans);
+          /* To distinguish success/failure after strtol call */
+          errno=0;
+          new_trans_number=strtol(new_trans_str, &endptr, 10);
+          /* Possible addressed problems: over/underflow, only non numbers on string and string empty */
+          if(errno || endptr == new_trans_str) 
+            {
+              conversion_ok = 0;
+            }
+            
+          split_str = xaccTransGetNum (split);
+          errno=0;
+          split_number=strtol(split_str, &endptr, 10);
+          if(errno || endptr == split_str) 
+            {
+              conversion_ok = 0;
+            }
+            
+          if((conversion_ok && (split_number == new_trans_number)) || 
+             (strcmp(new_trans_str, split_str)) == 0)
+            {	
+              /*An exact match of the Check number gives a +4 */
+              prob = prob+4;
+              /*DEBUG("heuristics:  probability + 5 (Check number)");*/
+            }
+          else if(strlen(new_trans_str) > 0 && strlen(split_str) > 0)
+            {
+              /* If both number are not empty yet do not match, add a little extra penality */
+              prob = prob-2;
+            }
+        }
+        
       /* Memo heuristics */  
       if(strlen(xaccSplitGetMemo(gnc_import_TransInfo_get_fsplit (trans_info)))!=0)
 	{




More information about the gnucash-devel mailing list