Tested and improved speed.

This commit is contained in:
Neil 2021-06-11 20:42:19 -07:00
parent 69745478f5
commit 93f54135a8
2 changed files with 21 additions and 14 deletions

View File

@ -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)
## <a id = "user-content-preamble" name = "user-content-preamble">Description</a> ##
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]`\.
## <a id = "user-content-license" name = "user-content-license">License</a> ##
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).

View File

@ -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 <string.h> /* strcmp() */
#include <assert.h>
/** 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;
}