ref: 149d0efdd886eb0b9e78690376ed51e4716397a3
parent: e16aafb5603edde57dc889578c9706df9a427574
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Mon Feb 15 05:43:17 EST 2021
remove disgusting space
--- a/picker.c
+++ b/picker.c
@@ -142,7 +142,7 @@
Color *c;
c = va_arg(f->args, Color*);
- if (c->nchan < 4)
+ if(c->nchan < 4)
sprint(s, "%06ux", c->u>>8);
else
sprint(s, "%08ux", c->u);
@@ -162,17 +162,17 @@
rect = Rect(0, 0, w, 1);
s = sliders[si];
- if (s == nil || Dx(s->r) != w) {
+ if(s == nil || Dx(s->r) != w){
buf[si] = realloc(buf[si], 4*w);
- if (s != nil)
+ if(s != nil)
freeimage(s);
- if ((s = sliders[si] = allocimage(display, rect, RGBA32, 1, DNofill)) == nil)
+ if((s = sliders[si] = allocimage(display, rect, RGBA32, 1, DNofill)) == nil)
sysfatal("allocimage: %r");
}
b = buf[si];
memmove(c, color->v, sizeof(c));
- if (space->single) {
+ if(space->single){
memset(c, 0, 3*sizeof(double));
c[si] = color->v[si];
}
@@ -179,21 +179,21 @@
dt = space->max[si] / w;
mi = c[si] / dt;
c[si] = 0.0;
- for (i = n = 0; i < w; i++, n += 4) {
+ for(i = n = 0; i < w; i++, n += 4){
space->torgb(c, rgba);
rgba[3] = c[3];
u = rgba2u(rgba);
u = setalpha(u, u&0xff);
b[n] = 0xff;
- if (mi-2 == i)
+ if(mi-2 == i)
memset(b+n+1, 0, 3);
- else if (mi-1 == i)
+ else if(mi-1 == i)
memset(b+n+1, 0xff, 3);
- else if (mi+1 == i)
+ else if(mi+1 == i)
memset(b+n+1, 0xff, 3);
- else if (mi+2 == i)
+ else if(mi+2 == i)
memset(b+n+1, 0, 3);
- else {
+ else{
b[n+0] = u & 0xff;
b[n+1] = (u>>8) & 0xff;
b[n+2] = (u>>16) & 0xff;
@@ -226,7 +226,7 @@
r.max.y = r.min.y + Sliderheight;
/* sliders */
- for (i = 0; i < color->nchan; i++) {
+ for(i = 0; i < color->nchan; i++){
srects[i] = r;
im = slider(i, Dx(r));
draw(screen, r, bg, nil, ZP);
@@ -243,9 +243,9 @@
colw = MIN(Sliderheight, (Dx(r)-(ncolors-1)*Offset)/ncolors);
cr = r;
cr.min.x += (Dx(cr) - colw*ncolors - (ncolors-1)*Offset) / 2;
- for (c = colors; c != nil; c = c->next) {
- if (c->i == nil) {
- if ((c->i = allocimage(display, Rect(0, 0, 1, 1), RGBA32, 1, setalpha(c->u|0xff, c->u&0xff))) == nil)
+ for(c = colors; c != nil; c = c->next){
+ if(c->i == nil){
+ if((c->i = allocimage(display, Rect(0, 0, 1, 1), RGBA32, 1, setalpha(c->u|0xff, c->u&0xff))) == nil)
sysfatal("allocimage: %r");
}
@@ -254,7 +254,7 @@
draw(screen, cr, c->i, nil, ZP);
border(screen, cr, 1, display->black, ZP);
c->r = insetrect(cr, -3);
- if (c == color)
+ if(c == color)
border(screen, c->r, 3, display->black, ZP);
cr.min.x += colw + Offset;
}
@@ -285,7 +285,7 @@
int i;
print("usage: %s [-e] [-", argv0);
- for (i = 0; i < nelem(spaces); i++)
+ for(i = 0; i < nelem(spaces); i++)
print("%c", spaces[i].opt);
print("]\n");
@@ -301,17 +301,17 @@
r = Rect(0, 0, Sliderheight, Sliderheight);
d = calloc(1, Sliderheight*Sliderheight);
- for (i = 0; i < Sliderheight/2; i++) {
- for (j = 0; j < Sliderheight/2; j++)
+ for(i = 0; i < Sliderheight/2; i++){
+ for(j = 0; j < Sliderheight/2; j++)
d[j*Sliderheight+i] = 0xff;
}
- for (; i < Sliderheight; i++) {
- for (j = Sliderheight/2; j < Sliderheight; j++)
+ for(; i < Sliderheight; i++){
+ for(j = Sliderheight/2; j < Sliderheight; j++)
d[j*Sliderheight+i] = 0xff;
}
- if ((bg = allocimage(display, r, GREY8, 1, DNofill)) == nil)
+ if((bg = allocimage(display, r, GREY8, 1, DNofill)) == nil)
sysfatal("allocimage: %r");
- if (loadimage(bg, r, d, Sliderheight*Sliderheight) < 0)
+ if(loadimage(bg, r, d, Sliderheight*Sliderheight) < 0)
sysfatal("loadimage: %r");
free(d);
}
@@ -335,23 +335,23 @@
char *e;
n = strlen(h);
- if (n != 6 && n != 8) {
+ if(n != 6 && n != 8){
werrstr("components: %d", n);
return -1;
}
c->nchan = n == 6 ? 3 : 4;
v = strtoll(h, &e, 16);
- if (v == 0 && (e == h || *e || v < 0 || (n == 6 && v > 0xffffff) || (n == 8 && v > 0xffffffff))) {
+ if(v == 0 && (e == h || *e || v < 0 || (n == 6 && v > 0xffffff) || (n == 8 && v > 0xffffffff))){
werrstr("color: '%s'", h);
return -1;
}
- if (c->nchan < 4) {
+ if(c->nchan < 4){
v <<= 8;
v |= 0xff;
}
c->u = v;
- for (i = 0; i < 4; i++) {
+ for(i = 0; i < 4; i++){
c->rgba[i] = (double)((v>>24)&0xff) / 255.0;
v <<= 8;
}
@@ -367,11 +367,11 @@
char *a[3];
int n;
- if ((n = tokenize(s, a, nelem(a))) < 2) {
+ if((n = tokenize(s, a, nelem(a))) < 2){
werrstr("columns: %d", n);
return -1;
}
- if (hex2color(a[1], c) != 0)
+ if(hex2color(a[1], c) != 0)
return -1;
c->id = strdup(a[0]);
@@ -392,21 +392,21 @@
fd2path(Bfildes(b), tmp+n, sizeof(tmp)-n);
threadsetname(tmp);
new = nil;
- for (i = 1; (s = Brdstr(b, '\n', 1)) != nil; i++) {
- if (new == nil)
+ for(i = 1; (s = Brdstr(b, '\n', 1)) != nil; i++){
+ if(new == nil)
new = calloc(1, sizeof(Color));
n = line2color(s, new);
free(s);
- if (n != 0) {
+ if(n != 0){
fprint(2, "readcolors: line %d: %r\n", i);
continue;
}
lockdisplay(display);
- for (c = colors; c != nil; c = c->next) {
- if (strcmp(c->id, new->id) == 0) {
+ for(c = colors; c != nil; c = c->next){
+ if(strcmp(c->id, new->id) == 0){
free(c->id);
new->prev = c->prev;
new->next = c->next;
@@ -416,21 +416,21 @@
}
}
- if (c == nil) {
+ if(c == nil){
c = new;
memmove(c->rgba0, c->rgba, sizeof(c->rgba));
- if (last != nil)
+ if(last != nil)
last->next = new;
new->prev = last;
last = new;
- if (colors == nil)
+ if(colors == nil)
colors = color = new;
new = nil;
ncolors++;
}
- if (!once)
+ if(!once)
printcolor(1, c);
unlockdisplay(display);
sendul(loaded, 0);
@@ -444,7 +444,7 @@
{
Color *c;
- for (c = colors; c != nil; c = c->next)
+ for(c = colors; c != nil; c = c->next)
printcolor(f, c);
}
@@ -453,7 +453,7 @@
{
Biobuf *b;
- if ((b = Bopen(filename, OREAD)) != nil)
+ if((b = Bopen(filename, OREAD)) != nil)
proccreate(readcolors, b, 4096);
}
@@ -464,8 +464,8 @@
Plumbmsg *m;
threadsetname("plumb");
- if ((f = plumbopen("picker", OREAD)) >= 0) {
- while ((m = plumbrecv(f)) != nil) {
+ if((f = plumbopen("picker", OREAD)) >= 0){
+ while((m = plumbrecv(f)) != nil){
loadtheme(m->data);
plumbfree(m);
}
@@ -503,13 +503,13 @@
break;
default:
space = nil;
- for (i = 0; i < nelem(spaces); i++) {
- if (spaces[i].opt == ARGC()) {
+ for(i = 0; i < nelem(spaces); i++){
+ if(spaces[i].opt == ARGC()){
space = &spaces[i];
break;
}
}
- if (space == nil) {
+ if(space == nil){
fprint(2, "unknown color space '%c'\n", ARGC());
usage();
}
@@ -516,15 +516,15 @@
break;
}ARGEND
- if (argc > 1)
+ if(argc > 1)
usage();
b = argc == 1 ? Bopen(argv[0], OREAD) : Bfdopen(0, OREAD);
- if (b == nil)
+ if(b == nil)
sysfatal("no colors: %r");
loaded = chancreate(sizeof(ulong), 0);
- for (i = 0; i < nelem(spaces); i++)
+ for(i = 0; i < nelem(spaces); i++)
menu2i[i] = spaces[i].name;
menu2i[menusnarf = i++] = "snarf";
menu2i[menusnarfall = i++] = "snarf all";
@@ -532,12 +532,12 @@
menu2i[menurevertall = i++] = "revert all";
menu2i[menuexit = i] = "exit";
- if (initdraw(nil, nil, "picker") < 0)
+ if(initdraw(nil, nil, "picker") < 0)
sysfatal("initdraw: %r");
- if ((kctl = initkeyboard(nil)) == nil)
+ if((kctl = initkeyboard(nil)) == nil)
sysfatal("initkeyboard: %r");
a[Ckey].c = kctl->c;
- if ((mctl = initmouse(nil, screen)) == nil)
+ if((mctl = initmouse(nil, screen)) == nil)
sysfatal("initmouse: %r");
a[Cmouse].c = mctl->c;
a[Cresize].c = mctl->resizec;
@@ -550,28 +550,28 @@
proccreate(readcolors, b, 4096);
proccreate(plumbproc, nil, 4096);
- for (;;) {
+ for(;;){
next:
c = color;
oldbuttons = m.buttons;
- switch (alt(a)) {
+ switch(alt(a)){
case -1:
goto end;
case Ckey:
- if (r == Kdel)
+ if(r == Kdel)
goto end;
- if (c == nil)
+ if(c == nil)
break;
- switch (r) {
+ switch(r){
case Kleft:
- if (c->prev != nil)
+ if(c->prev != nil)
color = c->prev;
redraw();
break;
case Kright:
- if (c->next != nil)
+ if(c->next != nil)
color = c->next;
redraw();
break;
@@ -579,16 +579,16 @@
break;
case Cmouse:
- if (c == nil)
+ if(c == nil)
break;
- if (m.buttons == 1) {
+ if(m.buttons == 1){
m.xy.x = MAX(screen->r.min.x, MIN(screen->r.max.x, m.xy.x));
- for (i = 0; i < c->nchan; i++) {
+ for(i = 0; i < c->nchan; i++){
Rectangle r = srects[i];
r.max.x += 1;
- if (oldbuttons == 0 && ptinrect(m.xy, r))
+ if(oldbuttons == 0 && ptinrect(m.xy, r))
slider = i;
- if (slider != i)
+ if(slider != i)
continue;
c->v[i] = MIN(space->max[i], (double)(m.xy.x - r.min.x) * space->max[i]/(double)(Dx(r)-1));
@@ -596,9 +596,9 @@
changed:
space->torgb(c->v, c->rgba);
u = rgba2u(c->rgba);
- if (c->u != u) {
+ if(c->u != u){
c->u = u;
- if (!once)
+ if(!once)
printcolor(1, c);
}
redraw();
@@ -605,45 +605,45 @@
goto next;
}
- for (c = colors; c != nil; c = c->next) {
- if (ptinrect(m.xy, c->r)) {
+ for(c = colors; c != nil; c = c->next){
+ if(ptinrect(m.xy, c->r)){
color = c;
space->fromrgb(c->rgba, c->v);
- for (i = 0; i < 3; i++)
+ for(i = 0; i < 3; i++)
c->v[i] = MAX(0.0, MIN(space->max[i], c->v[i]));
goto changed;
}
}
- } else if (m.buttons == 4 && (i = menuhit(3, mctl, &menu2, nil)) >= 0) {
- if (i == menuexit)
+ }else if(m.buttons == 4 && (i = menuhit(3, mctl, &menu2, nil)) >= 0){
+ if(i == menuexit)
goto end;
- if (i < nelem(spaces)) {
+ if(i < nelem(spaces)){
space = &spaces[i];
space->fromrgb(c->rgba, c->v);
for (i = 0; i < 3; i++)
c->v[i] = MAX(0.0, MIN(space->max[i], c->v[i]));
goto changed;
- } else if (i == menusnarf || i == menusnarfall) {
+ }else if(i == menusnarf || i == menusnarfall){
int f;
- if ((f = open("/dev/snarf", OWRITE)) >= 0) {
- if (i == menusnarf)
+ if((f = open("/dev/snarf", OWRITE)) >= 0){
+ if(i == menusnarf)
write(f, hex, strlen(hex));
else
dump(f);
close(f);
}
- } else if (i == menurevert) {
+ }else if(i == menurevert){
space->fromrgb(c->rgba0, c->v);
goto changed;
- } else if (i == menurevertall) {
- for (c = colors; c != nil; c = c->next) {
+ }else if(i == menurevertall){
+ for(c = colors; c != nil; c = c->next){
memmove(c->rgba, c->rgba0, sizeof(c->rgba));
space->fromrgb(c->rgba, c->v);
space->torgb(c->v, c->rgba);
u = rgba2u(c->rgba);
- if (c->u != u) {
+ if(c->u != u){
c->u = u;
- if (!once)
+ if(!once)
printcolor(1, c);
freeimage(c->i);
c->i = nil;
@@ -652,11 +652,11 @@
redraw();
break;
}
- } else if (m.buttons == 2) {
+ }else if(m.buttons == 2){
strcpy(buf, hex);
- if (enter("rgb(a):", buf, sizeof(buf), mctl, kctl, nil) > 0) {
+ if(enter("rgb(a):", buf, sizeof(buf), mctl, kctl, nil) > 0){
u = c->u;
- if (hex2color(buf, c) == 0 && c->u != u) {
+ if(hex2color(buf, c) == 0 && c->u != u){
c->u = ~c->u; /* just for the update to kick in */
goto changed;
}
@@ -667,7 +667,7 @@
case Cresize:
getwindow(display, Refnone);
- if (color != nil)
+ if(color != nil)
redraw();
break;
@@ -678,7 +678,7 @@
}
end:
- if (once)
+ if(once)
dump(1);
threadexitsall(nil);