about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/LYKeymap.c4
-rw-r--r--src/LYMain.c4
-rw-r--r--src/LYReadCFG.c4
-rw-r--r--src/LYStrings.c72
-rw-r--r--src/LYStrings.h4
5 files changed, 80 insertions, 8 deletions
diff --git a/src/LYKeymap.c b/src/LYKeymap.c
index ddad2284..f5c1af27 100644
--- a/src/LYKeymap.c
+++ b/src/LYKeymap.c
@@ -1,4 +1,4 @@
-/* $LynxId: LYKeymap.c,v 1.67 2009/01/03 02:06:45 Paul.Gilmartin Exp $ */
+/* $LynxId: LYKeymap.c,v 1.68 2009/01/25 18:34:57 tom Exp $ */
 #include <HTUtils.h>
 #include <LYUtils.h>
 #include <LYGlobalDefs.h>
@@ -1382,7 +1382,7 @@ int lkcstring_to_lkc(const char *src)
     else if (strlen(src) == 2 && *src == '^')
 	c = src[1] & 037;
     else if (strlen(src) >= 2 && isdigit(UCH(*src))) {
-	if (sscanf(src, "%i", &c) != 1)
+	if (sscanf(src, "%d", &c) != 1)
 	    return (-1);
 #ifdef USE_KEYMAPS
     } else {
diff --git a/src/LYMain.c b/src/LYMain.c
index e1f772ba..9cd31114 100644
--- a/src/LYMain.c
+++ b/src/LYMain.c
@@ -1,5 +1,5 @@
 /*
- * $LynxId: LYMain.c,v 1.195 2009/01/01 17:12:48 tom Exp $
+ * $LynxId: LYMain.c,v 1.196 2009/01/25 18:46:17 tom Exp $
  */
 #include <HTUtils.h>
 #include <HTTP.h>
@@ -4310,7 +4310,7 @@ static BOOL parse_arg(char **argv,
 	    if ((q->int_value != 0) && (next_arg != 0)) {
 		float ival;
 
-		if (1 == sscanf(next_arg, "%f", &ival)) {
+		if (1 == LYscanFloat(next_arg, &ival)) {
 		    *(q->int_value) = (int) SECS2Secs(ival);
 		}
 	    }
diff --git a/src/LYReadCFG.c b/src/LYReadCFG.c
index 7deeb875..e914661d 100644
--- a/src/LYReadCFG.c
+++ b/src/LYReadCFG.c
@@ -1,5 +1,5 @@
 /*
- * $LynxId: LYReadCFG.c,v 1.135 2009/01/01 23:29:54 tom Exp $
+ * $LynxId: LYReadCFG.c,v 1.136 2009/01/25 18:46:29 tom Exp $
  */
 #ifndef NO_RULES
 #include <HTRules.h>
@@ -1777,7 +1777,7 @@ void LYSetConfigValue(char *name,
 	if (q->int_value != 0) {
 	    float ival;
 
-	    if (1 == sscanf(value, "%f", &ival)) {
+	    if (1 == LYscanFloat(value, &ival)) {
 		*(q->int_value) = (int) SECS2Secs(ival);
 	    }
 	}
diff --git a/src/LYStrings.c b/src/LYStrings.c
index 8c207994..17ed7311 100644
--- a/src/LYStrings.c
+++ b/src/LYStrings.c
@@ -1,4 +1,4 @@
-/* $LynxId: LYStrings.c,v 1.161 2009/01/20 01:05:11 tom Exp $ */
+/* $LynxId: LYStrings.c,v 1.163 2009/01/25 22:06:08 tom Exp $ */
 #include <HTUtils.h>
 #include <HTCJK.h>
 #include <UCAux.h>
@@ -5283,6 +5283,76 @@ const char *LYLineeditHelpURL(void)
 }
 
 /*
+ * Wrapper for sscanf to ensure that lynx can "always" read a POSIX float.
+ * In some locales, the decimal point changes.
+ */
+int LYscanFloat2(const char **source, float *result)
+{
+    int count = 0;
+    char *temp;
+    const char *src = *source;
+
+    src = LYSkipCBlanks(src);
+    if (strchr(src, '.') != 0) {
+	long frc_part = 0;
+	float scale = 1.0;
+
+	if (*src != '.') {
+	    temp = NULL;
+	    *result = strtol(src, &temp, 10);
+	    src = temp;
+	}
+	if (src != 0 && *src == '.') {
+	    ++src;
+	    if (isdigit(UCH(*src))) {
+		temp = NULL;
+		frc_part = strtol(src, &temp, 10);
+		if (temp != 0) {
+		    int digits = temp - src;
+
+		    while (digits-- > 0)
+			scale *= 10.0;
+		    *result += (frc_part / scale);
+		}
+		src = temp;
+	    }
+	}
+	if (src != 0 && *src != '\0' && strchr(" \t+", *src) == 0) {
+	    char *extra = malloc(2 + strlen(src));
+
+	    if (extra != 0) {
+		extra[0] = '1';
+		strcpy(extra + 1, src);
+		if (sscanf(extra, "%f", &scale) == 1) {
+		    *result *= scale;
+		}
+		src = LYSkipCNonBlanks(src);
+	    } else {
+		src = 0;
+	    }
+	}
+	if (src != 0)
+	    count = 1;
+    } else {
+	count = sscanf(src, "%f", result);
+	src = LYSkipCNonBlanks(src);
+    }
+    CTRACE2(TRACE_CFG,
+	    (tfp, "LYscanFloat \"%s\" -> %f (%s)\n",
+	     *source, *result,
+	     count ? "ok" : "error"));
+    *source = src;
+    return count;
+}
+
+int LYscanFloat(const char *source, float *result)
+{
+    const char *temp = source;
+
+    return LYscanFloat2(&temp, result);
+}
+
+/*
  * A replacement for 'strsep()'
  */
 char *LYstrsep(char **stringp,
diff --git a/src/LYStrings.h b/src/LYStrings.h
index 9b9804c7..207a7be7 100644
--- a/src/LYStrings.h
+++ b/src/LYStrings.h
@@ -1,5 +1,5 @@
 /*
- * $LynxId: LYStrings.h,v 1.70 2009/01/01 21:36:55 tom Exp $
+ * $LynxId: LYStrings.h,v 1.72 2009/01/25 19:49:28 tom Exp $
  */
 #ifndef LYSTRINGS_H
 #define LYSTRINGS_H
@@ -47,6 +47,8 @@ extern "C" {
 			int hidden,
 			size_t bufsize,
 			RecallType recall);
+    extern int LYscanFloat(const char *source, float *result);
+    extern int LYscanFloat2(const char **source, float *result);
     extern char *LYstrsep(char **stringp,
 			  const char *delim);
     extern char *LYstrstr(char *chptr,