Blob
1 #include <u.h>2 #include <libc.h>3 #include <draw.h>4 #include <memdraw.h>5 #include "devdraw.h"7 int8 parsewinsize(char *s, Rectangle *r, int *havemin)9 {10 char c, *os;11 int i, j, k, l;13 os = s;14 *havemin = 0;15 *r = Rect(0,0,0,0);16 if(!isdigit((uchar)*s))17 goto oops;18 i = strtol(s, &s, 0);19 if(*s == 'x'){20 s++;21 if(!isdigit((uchar)*s))22 goto oops;23 j = strtol(s, &s, 0);24 r->max.x = i;25 r->max.y = j;26 if(*s == 0)27 return 0;28 if(*s != '@')29 goto oops;31 s++;32 if(!isdigit((uchar)*s))33 goto oops;34 i = strtol(s, &s, 0);35 if(*s != ',' && *s != ' ')36 goto oops;37 s++;38 if(!isdigit((uchar)*s))39 goto oops;40 j = strtol(s, &s, 0);41 if(*s != 0)42 goto oops;43 *r = rectaddpt(*r, Pt(i,j));44 *havemin = 1;45 return 0;46 }48 c = *s;49 if(c != ' ' && c != ',')50 goto oops;51 s++;52 if(!isdigit((uchar)*s))53 goto oops;54 j = strtol(s, &s, 0);55 if(*s != c)56 goto oops;57 s++;58 if(!isdigit((uchar)*s))59 goto oops;60 k = strtol(s, &s, 0);61 if(*s != c)62 goto oops;63 s++;64 if(!isdigit((uchar)*s))65 goto oops;66 l = strtol(s, &s, 0);67 if(*s != 0)68 goto oops;69 *r = Rect(i,j,k,l);70 *havemin = 1;71 return 0;73 oops:74 werrstr("bad syntax in window size '%s'", os);75 return -1;76 }