Showing the changes to devwsys/devdraw.c (1 of 6 files). Show all
Unified · Split
| @@ -6,7 +6,15 @@ · 5 unmodified lines | ||
| 6 | 6 | #include "dat.h" |
| 7 | 7 | #include "fns.h" |
| 8 | 8 | |
| 9 | +/* Error messages */ | |
| 10 | +static char | |
| 11 | + Enodrawimage[] = "unknown id for draw image", | |
| 12 | + Eoldname[] = "named image no longer valid"; | |
| 13 | + | |
| 14 | +DImage* drawlookup(Client*, int, int); | |
| 15 | + | |
| 9 | 16 | int nclient = 0; |
| 17 | +char *error = nil; | |
| 10 | 18 | |
| 11 | 19 | Client* |
| 12 | 20 | drawnewclient(Window *w) |
| @@ -30,10 +38,9 @@ drawnewclient(Window *w) · 17 unmodified lines | ||
| 30 | 38 | nclient++; |
| 31 | 39 | cp[i] = 0; |
| 32 | 40 | } |
| 33 | − cl = malloc(sizeof(Client)); | |
| 41 | + cl = mallocz(sizeof(Client), 1); | |
| 34 | 42 | if(cl == 0) |
| 35 | 43 | return 0; |
| 36 | − memset(cl, 0, sizeof(Client)); | |
| 37 | 44 | cl->slot = i; |
| 38 | 45 | cl->clientid = ++clientid; |
| 39 | 46 | cl->op = SoverD; |
| @@ -64,9 +71,102 @@ drawinstall(Client *client, int id, Memimage *i, DScreen *dscreen) · 24 unmodified lines | ||
| 64 | 71 | return i; |
| 65 | 72 | } |
| 66 | 73 | |
| 74 | +void | |
| 75 | +readdrawctl(char *buf, Client *cl) | |
| 76 | +{ | |
| 77 | + int n; | |
| 78 | + DImage *di; | |
| 79 | + Memimage *i; | |
| 80 | + | |
| 81 | + if(cl->infoid < 0) | |
| 82 | + error = Enodrawimage; | |
| 83 | + if(cl->infoid == 0){ | |
| 84 | + i = cl->window->screenimage; | |
| 85 | + if(i == nil) | |
| 86 | + error = Enodrawimage; | |
| 87 | + }else{ | |
| 88 | + di = drawlookup(cl, cl->infoid, 1); | |
| 89 | + if(di == nil) | |
| 90 | + error = Enodrawimage; | |
| 91 | + i = di->image; | |
| 92 | + } | |
| 93 | + n = sprint(buf, "%11d %11d %11s %11d %11d %11d %11d %11d %11d %11d %11d %11d ", | |
| 94 | + cl->clientid, cl->infoid, chantostr(buf, i->chan), (i->flags&Frepl)==Frepl, | |
| 95 | + i->r.min.x, i->r.min.y, i->r.max.x, i->r.max.y, | |
| 96 | + i->clipr.min.x, i->clipr.min.y, i->clipr.max.x, i->clipr.max.y); | |
| 97 | + cl->infoid = -1; | |
| 98 | +} | |
| 99 | + | |
| 100 | +void | |
| 101 | +drawmesg(Client *client, void *av, int n) | |
| 102 | +{ | |
| 103 | +} | |
| 104 | + | |
| 105 | +static | |
| 67 | 106 | int |
| 68 | −initscreenimage(Memimage *m) | |
| 107 | +drawcmp(char *a, char *b, int n) | |
| 108 | +{ | |
| 109 | + if(strlen(a) != n) | |
| 110 | + return 1; | |
| 111 | + return memcmp(a, b, n); | |
| 112 | +} | |
| 113 | + | |
| 114 | +DName* | |
| 115 | +drawlookupname(Draw *draw, int n, char *str) | |
| 69 | 116 | { |
| 70 | − // TODO: inferno-os/emu/port/devdraw.c:855,881 | |
| 117 | + DName *name, *ename; | |
| 118 | + | |
| 119 | + name = draw->name; | |
| 120 | + ename = &name[draw->nname]; | |
| 121 | + for(; name<ename; name++) | |
| 122 | + if(drawcmp(name->name, str, n) == 0) | |
| 123 | + return name; | |
| 124 | + return 0; | |
| 125 | +} | |
| 126 | + | |
| 127 | +int | |
| 128 | +drawgoodname(Draw *draw, DImage *d) | |
| 129 | +{ | |
| 130 | + DName *n; | |
| 131 | + | |
| 132 | + /* if window, validate the screen's own images */ | |
| 133 | + if(d->dscreen) | |
| 134 | + if(drawgoodname(draw, d->dscreen->dimage) == 0 | |
| 135 | + || drawgoodname(draw, d->dscreen->dfill) == 0) | |
| 136 | + return 0; | |
| 137 | + if(d->name == nil) | |
| 138 | + return 1; | |
| 139 | + n = drawlookupname(draw, strlen(d->name), d->name); | |
| 140 | + if(n==nil || n->vers!=d->vers) | |
| 141 | + return 0; | |
| 71 | 142 | return 1; |
| 72 | 143 | } |
| 144 | + | |
| 145 | +DImage* | |
| 146 | +drawlookup(Client *client, int id, int checkname) | |
| 147 | +{ | |
| 148 | + DImage *d; | |
| 149 | + Draw *draw; | |
| 150 | + | |
| 151 | + d = client->dimage[id&HASHMASK]; | |
| 152 | + while(d){ | |
| 153 | + if(d->id == id){ | |
| 154 | + draw = &client->window->draw; | |
| 155 | + if(checkname && !drawgoodname(draw, d)) | |
| 156 | + error = Eoldname; | |
| 157 | + return d; | |
| 158 | + } | |
| 159 | + d = d->next; | |
| 160 | + } | |
| 161 | + return 0; | |
| 162 | +} | |
| 163 | + | |
| 164 | +char* | |
| 165 | +drawerr(void) | |
| 166 | +{ | |
| 167 | + char *err; | |
| 168 | + | |
| 169 | + err = error; | |
| 170 | + error = nil; | |
| 171 | + return err; | |
| 172 | +} | |