check number magical add

Chris cxl000 at hotmail.com
Thu Feb 1 06:29:18 EST 2007


This patch performs the perform the arithmetic on the numerical suffix
of the cheque number. There is a minor change to the symantics of
gnc_parse_num.
This patch does not make the next number feature work correctly, it only
privides the numerical part. I will either need to store the string
prefix or change the next_num field to a string. I'll provide a patch
anon.
Regards,
     Chris
-------------- next part --------------
--- gnucash/src/register/register-core/numcell.c	2006-02-04 10:24:33.000000000 +1100
+++ gnucash-build/src/register/register-core/numcell.c	2007-02-01 16:50:41.000000000 +1100
@@ -36,6 +36,7 @@
 #include <limits.h>
 #include <stdlib.h>
 #include <string.h>
+#include <ctype.h>
 
 #include "numcell.h"
 #include "gnc-engine.h"
@@ -47,28 +48,42 @@
 static void gnc_num_cell_init (NumCell *cell);
 
 
-/* Parses the string value and returns true if it is a
+/* Parses the string value and returns the length of the
  * number. In that case, *num is set to the value parsed. */
-static gboolean
+static gint
 gnc_parse_num (const char *string, long int *num)
 {
   long int number;
+  int slength;
+  int plength;
 
   if (string == NULL)
-    return FALSE;
+    return 0;
 
-  if (!gnc_strisnum (string))
-    return FALSE;
+  slength = strlen(string);
+  plength = slength;
+
+/*  Find length of prefix containing non digits */
+    while ((plength > 0) && isdigit(string[plength-1]))
+    {
+        plength--;
+    }
 
-  number = strtol (string, NULL, 10);
+  if (plength == slength)
+    return 0;
+
+  if (!gnc_strisnum (string+plength))
+    return 0;
+
+  number = strtol (string+plength, NULL, 10);
 
   if ((number == LONG_MIN) || (number == LONG_MAX))
-    return FALSE;
+    return 0;
 
   if (num != NULL)
     *num = number;
 
-  return TRUE;
+  return slength-plength;
 }
 
 static void
@@ -83,7 +98,7 @@
 {
   NumCell *cell = (NumCell *) _cell;
   gboolean accel = FALSE;
-  gboolean is_num;
+  gint is_num;
   long int number = 0;
   gunichar uc;
   glong change_chars;
@@ -110,7 +125,7 @@
   is_num = gnc_parse_num (_cell->value, &number);
 
   if (is_num && (number < 0))
-    is_num = FALSE;
+    is_num = 0;
 
   uc = g_utf8_get_char (change);
   switch (uc)
@@ -150,12 +165,20 @@
   if (accel)
   {
     char buff[128];
+    int  prefixlength = 0;
 
     if (!is_num)
       number = cell->next_num;
 
-    strcpy (buff, "");
-    snprintf (buff, sizeof(buff), "%ld", number);
+    if (_cell->value != NULL)
+    {
+        prefixlength = strlen(_cell->value)-is_num;
+        strncpy(buff, _cell->value, prefixlength);
+    } else
+    {
+        strcpy (buff, "");
+    }
+    snprintf (buff+prefixlength, sizeof(buff)-prefixlength, "%0*ld", is_num, number);
 
     if (safe_strcmp (buff, "") == 0)
       return;


More information about the gnucash-devel mailing list