diff options
Diffstat (limited to 'src/cmd/devdraw/winsize.c')
-rw-r--r-- | src/cmd/devdraw/winsize.c | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/src/cmd/devdraw/winsize.c b/src/cmd/devdraw/winsize.c new file mode 100644 index 00000000..375401bf --- /dev/null +++ b/src/cmd/devdraw/winsize.c @@ -0,0 +1,76 @@ +#include <u.h> +#include <libc.h> +#include <draw.h> +#include <memdraw.h> +#include "devdraw.h" + +int +parsewinsize(char *s, Rectangle *r, int *havemin) +{ + char c, *os; + int i, j, k, l; + + os = s; + *havemin = 0; + *r = Rect(0,0,0,0); + if(!isdigit((uchar)*s)) + goto oops; + i = strtol(s, &s, 0); + if(*s == 'x'){ + s++; + if(!isdigit((uchar)*s)) + goto oops; + j = strtol(s, &s, 0); + r->max.x = i; + r->max.y = j; + if(*s == 0) + return 0; + if(*s != '@') + goto oops; + + s++; + if(!isdigit((uchar)*s)) + goto oops; + i = strtol(s, &s, 0); + if(*s != ',' && *s != ' ') + goto oops; + s++; + if(!isdigit((uchar)*s)) + goto oops; + j = strtol(s, &s, 0); + if(*s != 0) + goto oops; + *r = rectaddpt(*r, Pt(i,j)); + *havemin = 1; + return 0; + } + + c = *s; + if(c != ' ' && c != ',') + goto oops; + s++; + if(!isdigit((uchar)*s)) + goto oops; + j = strtol(s, &s, 0); + if(*s != c) + goto oops; + s++; + if(!isdigit((uchar)*s)) + goto oops; + k = strtol(s, &s, 0); + if(*s != c) + goto oops; + s++; + if(!isdigit((uchar)*s)) + goto oops; + l = strtol(s, &s, 0); + if(*s != 0) + goto oops; + *r = Rect(i,j,k,l); + *havemin = 1; + return 0; + +oops: + werrstr("bad syntax in window size '%s'", os); + return -1; +} |