? buildit.ksh
? env.sh
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gcalctool/ChangeLog,v
retrieving revision 1.201
diff -u -r1.201 ChangeLog
--- ChangeLog	20 Dec 2003 12:44:06 -0000	1.201
+++ ChangeLog	22 Dec 2003 15:35:29 -0000
@@ -6,9 +6,20 @@
 
 gcalctool change history.
 =========================
+
+2003-12-22  Miloslav Trmac <mitr at volny dot cz>
+
+    * Fixed bug 129539 (http://bugzilla.gnome.org/show_bug.cgi?id=129539)
+      The thousands separator is a null terminated string, not a single
+      character. Same for the radix. Adjusted various functions to handle
+      this. Note that in the C locale, nl_langinfo(THOUSEP) returns an empty
+      string, so get_tsep() has been adjusted to return "," for that case.
+      If nl_langinfo(RADIXCHAR) returns an empty string (it shouldn't do),
+      then get_radix() will return ".".
+
 2003-12-20  Arafat Medini <lumina@silverpen.de>
-                                                                                
-        * ar.po: Added Arabic Locale "ar" to ALL_LINGUAS
+
+    * ar.po: Added Arabic Locale "ar" to ALL_LINGUAS
 
 2003-12-05  Rich Burridge <rich.burridge@sun.com>
 
Index: NEWS
===================================================================
RCS file: /cvs/gnome/gcalctool/NEWS,v
retrieving revision 1.108
diff -u -r1.108 NEWS
--- NEWS	16 Dec 2003 22:10:51 -0000	1.108
+++ NEWS	22 Dec 2003 15:35:29 -0000
@@ -5,6 +5,13 @@
  *  All Rights Reserved.
  */
 
+Overview of changes in gcalctool 4.3.31
+
+* Fixed bug 129539.  The thousands separator is a null terminated string, 
+  not a single character. Same for the radix.
+
+----
+
 Overview of changes in gcalctool 4.3.30
 
 * Fixed bug 129496. "Gradients" should be "Gradians".
Index: configure.in
===================================================================
RCS file: /cvs/gnome/gcalctool/configure.in,v
retrieving revision 1.199
diff -u -r1.199 configure.in
--- configure.in	20 Dec 2003 12:44:06 -0000	1.199
+++ configure.in	22 Dec 2003 15:35:30 -0000
@@ -1,7 +1,7 @@
 dnl Process this file with autoconf to produce a configure script.
 
 AC_INIT(configure.in)
-AM_INIT_AUTOMAKE(gcalctool, 4.3.30)
+AM_INIT_AUTOMAKE(gcalctool, 4.3.31)
 AM_CONFIG_HEADER(config.h)
 AM_MAINTAINER_MODE
 
Index: gcalctool/calctool.c
===================================================================
RCS file: /cvs/gnome/gcalctool/gcalctool/calctool.c,v
retrieving revision 1.63
diff -u -r1.63 calctool.c
--- gcalctool/calctool.c	16 Dec 2003 22:10:51 -0000	1.63
+++ gcalctool/calctool.c	22 Dec 2003 15:35:30 -0000
@@ -1017,8 +1017,8 @@
         }
     }
 
-    v->radix_char = get_radix_char();   /* Locale specific radix character. */
-    v->tsep_char  = get_tsep_char();  /* Locale specific thousands seperator. */
+    v->radix = get_radix();    /* Locale specific radix string. */
+    v->tsep  = get_tsep();     /* Locale specific thousands seperator. */
 
     init_text();               /* Setup text strings depending upon language. */
     init_vars();               /* Setup default values for variables. */
Index: gcalctool/calctool.h
===================================================================
RCS file: /cvs/gnome/gcalctool/gcalctool/calctool.h,v
retrieving revision 1.44
diff -u -r1.44 calctool.h
--- gcalctool/calctool.h	3 Dec 2003 22:20:02 -0000	1.44
+++ gcalctool/calctool.h	22 Dec 2003 15:35:30 -0000
@@ -159,6 +159,7 @@
 #endif /*LINT_CAST*/
 
 #define MAX_DIGITS     40         /* Maximum displayable number of digits. */
+#define MAX_BUFFER     (MAX_DIGITS + MAX_DIGITS / 3 * MB_LEN_MAX + 1)
 
 /* Maximum number of various graphics pieces. */
 #define MAXITEMS       8          /* Maximum number of panel items. */
@@ -235,7 +236,7 @@
     char con_names[MAXREGS][MAXLINE];  /* Selectable constant names. */
     char display[MAXLINE];             /* Current calculator display. */
     char *exp_posn;                    /* Position of the exponent sign. */
-    char fnum[MAX_DIGITS+1];           /* Scratchpad for fixed numbers. */
+    char fnum[MAX_BUFFER];             /* Scratchpad for fixed numbers. */
     char fun_names[MAXREGS][MAXLINE];  /* Function names from .gcalctoolcf. */
     char fun_vals[MAXREGS][MAXLINE];   /* Function defs from .gcalctoolcf. */
     char *home;                        /* Pathname for users home directory. */
@@ -244,11 +245,11 @@
     char opstr[5];                     /* Operand string during pending op. */
     char *progname;                    /* Name of this program. */
     char pstr[5];                      /* Current button text string. */
-    char radix_char;                   /* Locale specific radix character. */
+    const char *radix;                 /* Locale specific radix string. */
     char *shelf;                       /* PUT selection shelf contents. */
-    char snum[MAX_DIGITS+1];           /* Scratchpad for scientific numbers. */
-    char tnum[MAX_DIGITS+1];           /* Scratchpad for tsep numbers. */
-    char tsep_char;                 /* Locale specific thousands seperator. */
+    char snum[MAX_BUFFER];             /* Scratchpad for scientific numbers. */
+    char tnum[MAX_BUFFER];             /* Scratchpad for tsep numbers. */
+    const char *tsep;                /* Locale specific thousands seperator. */
     char *titleline;                   /* Value of titleline (if present). */
     char *tool_label;                  /* Title line for calculator window. */
 
@@ -315,9 +316,9 @@
 
 char *button_str(int);
 char *convert(char *);
-char get_radix_char();
+const char *get_radix();
 char *get_resource(enum res_type);
-char get_tsep_char();
+const char *get_tsep();
 char *make_number(int *, int, BOOLEAN, BOOLEAN);
 char *set_bool(int);
 
Index: gcalctool/display.c
===================================================================
RCS file: /cvs/gnome/gcalctool/gcalctool/display.c,v
retrieving revision 1.35
diff -u -r1.35 display.c
--- gcalctool/display.c	5 Dec 2003 20:53:25 -0000	1.35
+++ gcalctool/display.c	22 Dec 2003 15:35:30 -0000
@@ -37,25 +37,28 @@
 {
     if (v->show_tsep && v->base == DEC) {
 	char *dstp, *radixp, *srcp;
-	int n;
+	int n, i;
+	size_t tsep_len;
 
 	/* Process the fractional part (if any). */
 	srcp = v->fnum + strlen(v->fnum) - 1;
 	dstp = v->tnum;
-	if ((radixp = strchr(v->fnum, v->radix_char)) != NULL) {
-            while (*srcp != v->radix_char) {
+	if ((radixp = strstr(v->fnum, v->radix)) != NULL) {
+            while (srcp != radixp) {
     		*dstp++ = *srcp--;
             }
-            *dstp++ = *srcp--;	   /* Copy over the radix char. */
+	    *dstp++ = *srcp--;
     	}
 
     	/* Process the integer part, add in thousand separators. */
+	tsep_len = strlen(v->tsep);
     	n = 0;
     	while (srcp >= v->fnum) {
             *dstp++ = *srcp--;
             n++;
             if (n == 3 && srcp >= v->fnum) {
-		*dstp++ = v->tsep_char;
+	        for (i = tsep_len - 1; i >= 0; i--)
+		    *dstp++ = v->tsep[i];
 		n = 0;
             }
 	}
@@ -76,27 +79,20 @@
 
 void
 remove_tsep(char *str) {
-    gboolean found = FALSE;
     char *srcp = str;
     char *dstp = str;
+    size_t tsep_len;
 
 /* If there are no thousands separators in the numeric string, just return
  * without doing anything. This is needed because the initial constant
  * definitions are potentially in read-only memory, and shouldn't be adjusted.
  */
 
-    while (*srcp != '\0') {
-        if (*srcp == v->tsep_char) {
-            found = TRUE;
-        }
-        srcp++;
-    }
-
-    if (found == TRUE) {
-        srcp = str;
+    if (strstr(str, v->tsep) != NULL) {
+        tsep_len = strlen(v->tsep);
         while (*srcp != '\0') {
-            if (*srcp == v->tsep_char) {
-                srcp++;
+            if (memcmp(srcp, v->tsep, tsep_len) == 0) {
+                srcp += tsep_len;
                 continue;
             }
             *dstp++ = *srcp++;
@@ -180,17 +176,18 @@
 
 
 /* Convert MP number to fixed number string in the given base to the
- * maximum number of characters specified.
+ * maximum number of digits specified.
  */
 
 static char *
 make_fixed(int *MPnumber, int base, int cmax)
 {
-    char half[4], *optr;
+    char half[3 + MB_LEN_MAX], *optr;
     int MP1base[MP_SIZE], MP1[MP_SIZE], MP2[MP_SIZE], MPval[MP_SIZE];
     int ndig;                   /* Total number of digits to generate. */
     int ddig;                   /* Number of digits to left of decimal sep. */
     int dval, n;
+    size_t radix_len = strlen(v->radix);
  
     optr = v->fnum;
     mpabs(MPnumber, MPval);
@@ -203,7 +200,7 @@
     mpcim(&basevals[base], MP1base);
 
     mppwr(MP1base, &v->accuracy, MP1);
-    SPRINTF(half, "0%c5", v->radix_char);
+    SPRINTF(half, "0%s5", v->radix);
     MPstr_to_num(half, DEC, MP2);
     mpdiv(MP2, MP1, MP1);
     mpadd(MPval, MP1, MPval);
@@ -224,7 +221,8 @@
 
     while (ndig-- > 0) {
         if (ddig-- == 0) {
-            *optr++ = v->radix_char;
+	    memcpy(optr, v->radix, radix_len);
+	    optr += radix_len;
         }
         mpmul(MPval, MP1base, MPval);
         mpcmi(MPval, &dval);
@@ -246,8 +244,11 @@
         while (*optr == '0') {
             optr--;
         }
-        if (*optr != v->radix_char) {
-            optr++;
+	if (optr < v->fnum + radix_len - 1 || 
+            memcmp(optr - (radix_len - 1), v->radix, radix_len) != 0) {
+	    optr++;
+	} else {
+	    optr -= radix_len - 1;
         }
         *optr = '\0';
     }
@@ -293,7 +294,7 @@
 static char *
 make_eng_sci(int *MPnumber, int base)
 {
-    char half[4], fixed[MAX_DIGITS+1], *optr;
+    char half[3 + MB_CUR_MAX], fixed[MAX_BUFFER], *optr;
     int MP1[MP_SIZE], MPatmp[MP_SIZE], MPval[MP_SIZE];
     int MP1base[MP_SIZE], MP3base[MP_SIZE], MP10base[MP_SIZE];
     int i, dval, len, n;
@@ -367,7 +368,7 @@
         *optr++ = '+';
     }
  
-    SPRINTF(half, "0%c5", v->radix_char);
+    SPRINTF(half, "0%s5", v->radix);
     MPstr_to_num(half, DEC, MP1);
     mpaddi(MP1, &exp, MPval);
     n = 1;
@@ -405,6 +406,7 @@
     int i, inum;
     int exp      = 0;
     int exp_sign = 1;
+    size_t radix_len;
 
     i = 0;
     mpcim(&i, MPval);
@@ -419,12 +421,15 @@
         optr++;
     }
 
-    if (*optr == v->radix_char) {
-        for (i = 1; (inum = char_val(*++optr)) >= 0; i++) {
+    radix_len = strlen (v->radix);
+    if (memcmp(optr, v->radix, radix_len) == 0) {
+        optr += radix_len;
+        for (i = 1; (inum = char_val(*optr)) >= 0; i++) {
             mppwr(MPbase, &i, MP1);
             mpcim(&inum, MP2);
             mpdiv(MP2, MP1, MP1);
             mpadd(MPval, MP1, MPval);
+	    optr++;
         }
     }
 
Index: gcalctool/functions.c
===================================================================
RCS file: /cvs/gnome/gcalctool/gcalctool/functions.c,v
retrieving revision 1.31
diff -u -r1.31 functions.c
--- gcalctool/functions.c	3 Dec 2003 22:20:03 -0000	1.31
+++ gcalctool/functions.c	22 Dec 2003 15:35:30 -0000
@@ -386,8 +386,24 @@
 void
 do_delete()     /* Remove the last numeric character typed. */
 {
-    if (strlen(v->display) > 0) {
-        v->display[strlen(v->display)-1] = '\0';
+    size_t len;
+
+    len = strlen(v->display);
+    if (len > 0) {
+        size_t l2;
+
+	l2 = strlen(v->radix);
+        if (len >= l2 && memcmp(v->display + len - l2, v->radix, l2) == 0) {
+	    v->display[len-l2] = '\0';
+	} else {
+	    l2 = strlen(v->tsep);
+	    if (len >= l2
+		&& memcmp(v->display + len - l2, v->tsep, l2) == 0) {
+	        v->display[len-l2] = '\0';
+	    } else {
+	        v->display[len-1] = '\0';
+	    }
+	}
     }
 
 /*  If we were entering a scientific number, and we have backspaced over
@@ -401,7 +417,7 @@
 
 /* If we've backspaced over the numeric point, clear the pointed flag. */
 
-    if (v->pointed && !(strchr(v->display, v->radix_char))) {
+    if (v->pointed && !(strstr(v->display, v->radix))) {
         v->pointed = 0;
     }
 
@@ -431,14 +447,14 @@
 void
 do_expno()           /* Get exponential number. */
 {
-    v->pointed = (strchr(v->display, v->radix_char) != NULL);
+    v->pointed = (strstr(v->display, v->radix) != NULL);
     if (!v->new_input) {
         STRCPY(v->display, "1.0 +");
         v->new_input = v->pointed = 1;
     } else if (!v->pointed) {
         char str[4];
 
-        SPRINTF(str, "%c +", v->radix_char);
+        SPRINTF(str, "%s +", v->radix);
         STRNCAT(v->display, str, 3);
         v->pointed = 1;
     } else if (!v->key_exp) {
@@ -779,15 +795,12 @@
 void
 do_point()                   /* Handle numeric point. */
 {
-    char radix_str[2];
-
     if (!v->pointed) {
-	SPRINTF(radix_str, "%c", v->radix_char);
         if (v->toclear) {
-            STRCPY(v->display, radix_str);
+            STRCPY(v->display, v->radix);
             v->toclear = 0;
         } else {
-            STRNCAT(v->display, radix_str, 1);
+            STRCAT(v->display, v->radix);
         }
         v->pointed = 1;
     }
Index: gcalctool/get.c
===================================================================
RCS file: /cvs/gnome/gcalctool/gcalctool/get.c,v
retrieving revision 1.24
diff -u -r1.24 get.c
--- gcalctool/get.c	26 Nov 2003 20:29:52 -0000	1.24
+++ gcalctool/get.c	22 Dec 2003 15:35:30 -0000
@@ -118,17 +118,23 @@
 }
 
 
-/* Return the radix character. For most locales, this is a period. */
+/* Return the radix character. For most locales, this is a period. 
+ * If nl_langinfo(RADIXCHAR) returns an empty string, return ",".
+ */
 
-char
-get_radix_char()
+const char *
+get_radix()
 {
-    char *radix_char;
+    char *radix;
 
     setlocale(LC_NUMERIC, "");
-    radix_char = nl_langinfo(RADIXCHAR);
+    radix = nl_langinfo(RADIXCHAR);
 
-    return(radix_char[0]);
+    if (radix == NULL || radix[0] == '\0') {
+        return(".");
+    } else {
+        return(radix);
+    }
 }
 
 
@@ -211,19 +217,24 @@
 }
 
 
-/* Return the thousands separator character. For most locales, this is a 
- * comma.
+/* Return the thousands separator string. For most locales, this is a 
+ * comma. If this is the C locale, nl_langinfo(THOUSEP) returns an empty 
+ * string, in which case we return ",".
  */
 
-char
-get_tsep_char()
+const char *
+get_tsep()
 {
-    char *tsep_char;
+    char *tsep;
 
     setlocale(LC_NUMERIC, "");
-    tsep_char = nl_langinfo(THOUSEP);
+    tsep = nl_langinfo(THOUSEP);
 
-    return(tsep_char[0]);
+    if (tsep == NULL || tsep[0] == '\0') {
+        return(",");
+    } else {
+        return(tsep);
+    }
 }
 
 
