diff options
| author | Devine Lu Linvega <aliceffekt@gmail.com> | 2020-09-14 14:03:04 -0700 |
|---|---|---|
| committer | Devine Lu Linvega <aliceffekt@gmail.com> | 2020-09-14 14:03:04 -0700 |
| commit | afb04a529e8351ba7dd517a58b343c65157751d2 (patch) | |
| tree | 2d9445ddbf98c8720692198febb4dd306a1ab3f1 | |
| parent | adfb65521dfe51d70f0c3033afef76ec1c66880e (diff) | |
Added Plan9 implementation
| -rwxr-xr-x | tools/build.sh | 16 | ||||
| -rw-r--r-- | tools/themes.c (renamed from tools/main.c) | 41 | ||||
| -rw-r--r-- | tools/themes9.c | 153 |
3 files changed, 197 insertions, 13 deletions
diff --git a/tools/build.sh b/tools/build.sh index 256b3c9..a9ed3bc 100755 --- a/tools/build.sh +++ b/tools/build.sh @@ -1,18 +1,12 @@ #!/bin/bash -clang-format -i main.c +clang-format -i themes.c # Linux -cc -std=c89 -DDEBUG -Wall -Wpedantic -Wshadow -Wextra -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Wvla -g -Og -fsanitize=address -fsanitize=undefined -o main main.c +cc -std=c89 -DDEBUG -Wall -Wpedantic -Wshadow -Wextra -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Wvla -g -Og -fsanitize=address -fsanitize=undefined -o themes themes.c -# RPi -# tcc -Wall main.c -o main +# ./themes ../themes/apollo.svg -# Plan9 -# pcc main.c -o main +cat ../themes/apollo.svg | ./themes -# ./main ../themes/apollo.svg - -cat ../themes/apollo.svg | ./main - -rm ./main +rm ./themes diff --git a/tools/main.c b/tools/themes.c index 20c92ce..7866286 100644 --- a/tools/main.c +++ b/tools/themes.c @@ -21,7 +21,7 @@ cpos(char* s, char c) return -1; } -void +char* sstr(char* src, char* dest, int from, int to) { int i; @@ -29,6 +29,7 @@ sstr(char* src, char* dest, int from, int to) for(i = 0; i < to; i++) b[i] = a[i]; dest[to] = '\0'; + return dest; } unsigned char @@ -69,6 +70,42 @@ scmp(char* a, char* b) return 1; } +char* +scat(char* dest, const char* src) +{ + char* ptr = dest + slen(dest); + while(*src != '\0') + *ptr++ = *src++; + *ptr = '\0'; + return dest; +} + +int +parse2(FILE* f) +{ + int i, id = 0, next = 0; + long theme[9]; + char line[BUFLEN], hexs[BUFLEN], comb[1024]; + char* ptr; + while(fgets(line, BUFLEN, f)) { + scat(comb, line); + } + + for(i = 0; i < slen(comb); ++i) { + if(comb[i] != '#') + continue; + printf("%s ", sstr(comb, hexs, i, 7)); + id++; + } + + if(id != 9) + return error("Invalid theme"); + for(i = 0; i < 9; ++i) { + printf("%ld ", theme[i]); + } + return 1; +} + int parse(FILE* f) { @@ -102,5 +139,5 @@ main(int argc, char* argv[]) return error("Invalid input.\n"); } else input = stdin; - return parse(input); + return parse2(input); }
\ No newline at end of file diff --git a/tools/themes9.c b/tools/themes9.c new file mode 100644 index 0000000..ae3541d --- /dev/null +++ b/tools/themes9.c @@ -0,0 +1,153 @@ +#include <u.h> +#include <libc.h> +#include <draw.h> +#include <event.h> + +#define BUFLEN 1024 + +long theme[9]; +Image *bg, + *f_high, *f_med, *f_low, *f_inv, + *b_high, *b_med, *b_low, *b_inv; + +int +slen(char* s) +{ + int n = 0; + while(s[n] != '\0' && s[++n]) + ; + return n; +} + +char* +sstr(char* src, char* dest, int from, int to) +{ + int i; + char *a = (char*)src + from, *b = (char*)dest; + for(i = 0; i < to; i++) + b[i] = a[i]; + dest[to] = '\0'; + return dest; +} + +unsigned char +chex(char c) +{ + if(c >= 'a' && c <= 'f') + return 10 + c - 'a'; + if(c >= 'A' && c <= 'F') + return 10 + c - 'A'; + return (c - '0') & 0xF; +} + +unsigned long +shex(char* s) +{ + int i, n = 0, l = slen(s); + for(i = 0; i < l; ++i) + n |= (chex(s[i]) << ((l - i - 1) * 4)); + return n; +} + +void +parse(int fd) +{ + int i, id = 0; + char buf[BUFLEN], hexs[8]; + + read(fd, buf, BUFLEN); + + for(i = 0; i < BUFLEN; ++i) { + if(buf[i] != '#') + continue; + print("#%s ", sstr(buf, hexs, i + 1, 6)); + theme[id] = (shex(hexs) << 8) + 255; + id++; + } + + if(id != 9) + print("Invalid theme"); + + close(fd); + + bg = allocimage(display, Rect(0, 0, 1, 1), RGB24, 1, theme[0]); + f_high = allocimage(display, Rect(0, 0, 1, 1), RGB24, 1, theme[1]); + f_med = allocimage(display, Rect(0, 0, 1, 1), RGB24, 1, theme[2]); + f_low = allocimage(display, Rect(0, 0, 1, 1), RGB24, 1, theme[3]); + f_inv = allocimage(display, Rect(0, 0, 1, 1), RGB24, 1, theme[4]); + b_high = allocimage(display, Rect(0, 0, 1, 1), RGB24, 1, theme[5]); + b_med = allocimage(display, Rect(0, 0, 1, 1), RGB24, 1, theme[6]); + b_low = allocimage(display, Rect(0, 0, 1, 1), RGB24, 1, theme[7]); + b_inv = allocimage(display, Rect(0, 0, 1, 1), RGB24, 1, theme[8]); +} + +void +redraw(Image* dst) +{ + int size = 20; + Point s = subpt(screen->r.max, screen->r.min); + Point c = divpt(s, 2); + Point m = addpt(screen->r.min, c); + Point o = addpt(m, (Point){-size * 4, -size * 2}); + draw(screen, screen->r, bg, nil, ZP); + + fillellipse(screen, + addpt(o, (Point){size, size}), + size, size, f_high, ZP); + fillellipse(screen, + addpt(o, (Point){size * 3, size}), + size, size, f_med, ZP); + fillellipse(screen, + addpt(o, (Point){size * 5, size}), + size, size, f_low, ZP); + fillellipse(screen, + addpt(o, (Point){size * 7, size}), + size, size, f_inv, ZP); + fillellipse(screen, + addpt(o, (Point){size, size * 3}), + size, size, b_high, ZP); + fillellipse(screen, + addpt(o, (Point){size * 3, size * 3}), + size, size, b_med, ZP); + fillellipse(screen, + addpt(o, (Point){size * 5, size * 3}), + size, size, b_low, ZP); + fillellipse(screen, + addpt(o, (Point){size * 7, size * 3}), + size, size, b_inv, ZP); +} + +void +eresized(int new) +{ + Rectangle r; + r = screen->r; + if(new&& getwindow(display, Refnone) < 0) + fprint(2, "can't reattach to window"); + redraw(screen); +} + +void +main(int argc, char** argv) +{ + int fd; + Mouse m; + + initdraw(0, 0, "Themes"); + + if(argc == 1) + fd = 0; + else if((fd = open(argv[1], OREAD)) < 0) + perror(argv[1]); + parse(fd); + + eresized(0); + einit(Emouse); + + /* Break on mouse3 */ + for(;;) { + m = emouse(); + if(m.buttons & 4) + break; + } +}
\ No newline at end of file |
