From 3bef1314a3ae1e5bdc3ffb771e32866e05072d48 Mon Sep 17 00:00:00 2001 From: rodri Date: Sun, 7 Jun 2020 19:34:17 +0000 Subject: ptinline: the user sets the line. fixed coordinate input. --- ptinline.c | 23 +++++++++++++++++------ 1 file 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 #include #include +#include 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; } -- cgit v1.2.3