aboutsummaryrefslogtreecommitdiffstats
path: root/src/blind-coordinate-field.c
blob: 3b8a7c65f392c4eb819991b8232a572678f54462 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* See LICENSE file for copyright and license details. */
#ifndef TYPE
#include "common.h"

USAGE("[-f frames | -f 'inf'] [-F pixel-format] -w width -h height")

static struct stream stream = { .width = 0, .height = 0, .frames = 1 };
static int inf = 0;

#define FILE "blind-coordinate-field.c"
#include "define-functions.h"

int
main(int argc, char *argv[])
{
	char *arg;
	const char *pixfmt = "xyza";
	void (*process)(void);

	ARGBEGIN {
	case 'f':
		arg = UARGF();
		if (!strcmp(arg, "inf"))
			inf = 1, stream.frames = 0;
		else
			stream.frames = etozu_flag('f', arg, 1, SIZE_MAX);
		break;
	case 'F':
		pixfmt = UARGF();
		break;
	case 'w':
		stream.width = etozu_flag('w', UARGF(), 1, SIZE_MAX);
		break;
	case 'h':
		stream.height = etozu_flag('h', UARGF(), 1, SIZE_MAX);
		break;
	default:
		usage();
	} ARGEND;

	if (!stream.width || !stream.height || argc)
		usage();

	if (inf)
		einf_check_fd(STDOUT_FILENO, "<stdout>");

	eset_pixel_format(&stream, pixfmt);
	SELECT_PROCESS_FUNCTION(&stream);
	fprint_stream_head(stdout, &stream);
	efflush(stdout, "<stdout>");
	process();
	return 0;
}

#else

static void
PROCESS(void)
{
	TYPE buf[4] = {0, 0, 0, 0};
	size_t x, y;
	while (inf || stream.frames--) {
		for (y = 0; y < stream.height; y++) {
			buf[1] = (TYPE)y;
			for (x = 0; x < stream.width; x++) {
				buf[0] = (TYPE)x;
				ewrite(STDOUT_FILENO, buf, sizeof(buf), "<stdout>");
			}
		}
	}
}

#endif