aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrodri <rgl@antares-labs.eu>2020-06-07 19:34:17 +0000
committerrodri <rgl@antares-labs.eu>2020-06-07 19:34:17 +0000
commit3bef1314a3ae1e5bdc3ffb771e32866e05072d48 (patch)
tree55466aeed195555327d568a022056c54719a9b2f
parentd6beda15798a3d1d604a033febca3756456345d1 (diff)
downloadetoys-3bef1314a3ae1e5bdc3ffb771e32866e05072d48.tar.gz
etoys-3bef1314a3ae1e5bdc3ffb771e32866e05072d48.tar.bz2
etoys-3bef1314a3ae1e5bdc3ffb771e32866e05072d48.zip
ptinline: the user sets the line. fixed coordinate input.
-rw-r--r--ptinline.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/ptinline.c b/ptinline.c
index 97be46e..caf6ffd 100644
--- a/ptinline.c
+++ b/ptinline.c
@@ -1,6 +1,7 @@
#include <u.h>
#include <libc.h>
#include <draw.h>
+#include <ctype.h>
int
max(int a, int b)
@@ -46,7 +47,7 @@ ptinline(Point p, Point q, Point t)
void
usage(void)
{
- fprint(2, "usage: %s\n", argv0);
+ fprint(2, "usage: %s x0 y0 x1 y1\n", argv0);
exits("usage");
}
@@ -61,22 +62,32 @@ main(int argc, char *argv[])
ARGBEGIN{
default: usage();
}ARGEND;
- if(argc > 0)
+ if(argc != 4)
usage();
- pts[0] = Pt(0,0);
- pts[1] = Pt(2,2);
+ pts[0].x = strtol(argv[0], &p, 10);
+ if(*p != 0)
+ usage();
+ pts[0].y = strtol(argv[1], &p, 10);
+ if(*p != 0)
+ usage();
+ pts[1].x = strtol(argv[2], &p, 10);
+ if(*p != 0)
+ usage();
+ pts[1].y = strtol(argv[3], &p, 10);
+ if(*p != 0)
+ usage();
while((n = read(0, buf, sizeof(buf)-1)) > 0){
buf[n-1] = buf[n] = 0;
pts[2].x = strtol(buf, &p, 10);
- if(p == nil || *p == 0){
+ if(!isspace(*p)){
fprint(2, "wrong x coordinate\n");
continue;
}
pts[2].y = strtol(p, &p, 10);
- if(p == nil || *p != 0){
+ if(*p != 0){
fprint(2, "wrong y coordinate\n");
continue;
}