]> git.pond.sub.org Git - empserver/blobdiff - src/lib/common/xy.c
(strtox, strtoy): New. Use it instead of inputxy() to avoid the
[empserver] / src / lib / common / xy.c
index 469d961541d925b7c217d8a0f77bbaa697fceb6c..a5a398b450d998b08e2e6f83a3e0727bab5cfced 100644 (file)
  */
 
 #include <ctype.h>
+#include <errno.h>
 #include <stdarg.h>
+#include <stdio.h>
 #include "misc.h"
 #include "xy.h"
 #include "nat.h"
 #include "sect.h"
 #include "file.h"
-#include <stdio.h>
 #include "common.h"
 #include "optlist.h"
 
@@ -117,14 +118,42 @@ xyabsrange(struct natstr *np, struct range *src, struct range *dst)
     dst->height = src->height;
 }
 
-void
-inputxy(coord *xp, coord *yp, natid cn)
+/*
+ * Convert initial part of STR to normalized x-coordinate.
+ * Return -1 on error.  This works, as normalized coordinates are
+ * non-negative.
+ * Assign pointer to first character after the coordinate to *END,
+ * unless END is a null pointer.
+ */
+coord
+strtox(char *str, char **end)
 {
-    struct natstr *np;
+    long l;
+
+    errno = 0;
+    l = strtol(str, end, 10);
+    if (*end == str || errno != 0)
+       return -1;
+    return XNORM(l);
+}
+
+/*
+ * Convert initial part of STR to normalized y-coordinate.
+ * Return -1 on error.  This works, as normalized coordinates are
+ * non-negative.
+ * Assign pointer to first character after the coordinate to *END,
+ * unless END is a null pointer.
+ */
+coord
+strtoy(char *str, char **end)
+{
+    long l;
 
-    np = getnatp(cn);
-    *xp = xabs(np, *xp);
-    *yp = yabs(np, *yp);
+    errno = 0;
+    l = strtol(str, end, 10);
+    if (*end == str || errno != 0)
+       return -1;
+    return YNORM(l);
 }
 
 coord