    A new StringToNum() function without a call to sscanf()

    It seems a shame to scan a string twice, as the older version does.

diff -ur nedit_official/source/interpret.c nedit_mod/source/interpret.c
--- nedit_official/source/interpret.c	2004-11-23 09:37:37.000000000 -0500
+++ nedit_mod/source/interpret.c	2004-12-20 20:15:08.949807000 -0500
@@ -2797,33 +2797,52 @@
     return STAT_ERROR;
 }
 
+/*
+** read an integer from a string, returning True if successful. The string must
+** not contain anything other than the number (perhaps surrounded by spaces).
+*/
 int StringToNum(const char *string, int *number)
 {
     const char *c = string;
+    int n = 0, new_n;
+    int sign = 1;
+    int haveDigit = False;
     
     while (*c == ' ' || *c == '\t') {
         ++c;
     }
-    if (*c == '+' || *c == '-') {
+    if (*c == '+') {
         ++c;
-    }
-    while (isdigit((unsigned char)*c)) {
+    } else if (*c == '-') {
         ++c;
+        sign = -1;
     }
-    while (*c == ' ' || *c == '\t') {
-        ++c;
+    if (isdigit((unsigned char)*c)) {
+        haveDigit = True;               /* now pick up any other digits */
+        do {
+            new_n = 10 * n + *c - '0';  /* evaluate the number as we go */
+            if (new_n == INT_MIN) {
+                if (sign != -1) {
+                    return False;       /* special case: INT_MIN must be < 0 */
+                }
+            } else if (new_n < n) {
+                return False;           /* overflow: digit sequence too long! */
+            }
+            n = new_n;
+            ++c;
+        } while (isdigit((unsigned char)*c));
+        while (*c == ' ' || *c == '\t') {
+            ++c;
+        }
+    }
+    if (number) {
+        *number = sign * n;
     }
     if (*c) {
         /* if everything went as expected, we should be at end, but we're not */
         return False;
     }
-    if (number) {
-        if (sscanf(string, "%d", number) != 1) {
-            /* This case is here to support old behavior */
-    	    *number = 0;
-        }
-    }
-    return True;
+    return haveDigit;
 }
 
 #ifdef DEBUG_DISASSEMBLER   /* dumping values in disassembly or stack dump */
