From 93f54135a8b7f959d2b7873a4ec8f9a5ff2df3b6 Mon Sep 17 00:00:00 2001 From: Neil Date: Fri, 11 Jun 2021 20:42:19 -0700 Subject: [PATCH] Tested and improved speed. --- readme.md | 20 +++++++++++++------- src/gifbar.c | 15 ++++++++------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/readme.md b/readme.md index 794c77a..bd41f8c 100644 --- a/readme.md +++ b/readme.md @@ -1,11 +1,17 @@ -# gifbar # +# gifbar\.c # -This is a CGI gif percentage (well, per-0xFF) bar using -hard-coded data and colour-cycling. + * [Description](#user-content-preamble) + * [License](#user-content-license) + +## Description ## + +This is a CGI gif percentage \(well, per\-0xFF\) bar using hard\-coded data and colour\-cycling\. Outputs `image/gif` of the progress bar in nice mottled style\. Usage `gifbar?[0-255]`\. + + + +## License ## + +1997, 2007 Neil Edelman, distributed under the terms of the [GNU General Public License 3](https://opensource.org/licenses/GPL-3.0)\. -Usage: gifbar?[0-255] -## License ## -1997, 2007 Neil Edelman, distributed under the terms of -the [MIT License](https://opensource.org/licenses/MIT). diff --git a/src/gifbar.c b/src/gifbar.c index c177767..f1628fa 100644 --- a/src/gifbar.c +++ b/src/gifbar.c @@ -1,8 +1,9 @@ /** @license 1997, 2007 Neil Edelman, distributed under the terms of the [GNU General Public License 3](https://opensource.org/licenses/GPL-3.0). - CGI GET a single argument, a number from [0-255]. Outputs `image/gif` - of the progress bar in nice mottled style. */ + This is a CGI gif percentage (well, per-0xFF) bar using hard-coded data and + colour-cycling. Outputs `image/gif` of the progress bar in nice mottled style. + Usage `gifbar?[0-255]`. */ /* I was looking though old code, and the one is genius. I cleaned it up. September 3, 2007. @@ -52,8 +53,8 @@ trailer: (one per data stream) #include /* strcmp() */ #include -/** Prints the GIF of `parm` per-`[0, 255]` on `stdout`. */ -static void print_gif(unsigned char parm) { +/** Prints the GIF of `parm` per-`[0, 255]` on `stdout`. @return Success. */ +static int print_gif(unsigned char parm) { /* Binary `gif` output that I made up with a painting programme; could replace with anything, make it `00-FF` as it goes across the image. */ static unsigned char table[256 * 3]; @@ -284,7 +285,8 @@ static void print_gif(unsigned char parm) { if(fwrite(header, 1, sizeof header, stdout) != sizeof header || fwrite(table, 1, sizeof table, stdout) != sizeof table || fwrite(descriptor_data_end, 1, sizeof descriptor_data_end, stdout) - != sizeof descriptor_data_end) perror("stdout"); + != sizeof descriptor_data_end) return perror("stdout"), 0; + return 1; } int main(void) { @@ -299,6 +301,5 @@ int main(void) { printf("Content-type: image/gif\n\n"); /* May need to set `stdout` to binary mode to avoid line feed translation; if on Windows? if(setmode(stdout, O_BINARY) == -1) return 1; */ - print_gif((unsigned char)atoi(env)); /* Don't care ab conversion errors. */ - return EXIT_SUCCESS; + return print_gif((unsigned char)atoi(env)) ? EXIT_SUCCESS : EXIT_FAILURE; }