~kaction/config

ref: 1ab4be43ae3f278dc70cd8da11c4a06c69414dda config/aux/mk-template.c.m4 -rw-r--r-- 566 bytes
1ab4be43 — Dmitry Bogatov nix: import old patch for rc shell 2 years ago
                                                                                
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
m4_changequote(<|, |>)
#include <stdio.h>
#include <limits.h>
#include <ctype.h>
static const char bytes[] = {
	m4_esyscmd(xxd -i < THE_SOURCE), 0x0
};

/* If *p is digit, return it; return INT_MAX otherwise */
static int digit(const char *p)
{
	const char c = *p;
	if (isdigit(c)) {
		return c - '0';
	}
	return INT_MAX;
}

int
main(int argc, char **argv)
{
	const char *p = bytes;
	while (*p) {
		int ix;
		if (*p == '#' && ((ix = digit(p+1)) < argc)) {
			fputs(argv[ix], stdout);
			p += 2;
		} else {
			putchar(*p);
			p += 1;
		}
	}
	return 0;
}
// vim: ft=c