aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/htmlroff/t18.c
blob: 51f08219c40aca87d46433bac18b60ab809f390b (plain)
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
#include "a.h"

/*
 * 18. Insertions from the standard input
 */
void
r_rd(int argc, Rune **argv)
{
	char *s;
	Rune *p;
	Fmt fmt;
	static int didstdin;
	static Biobuf bstdin;

	/*
	 * print prompt, then read until double newline,
	 * then run the text just read as though it were
	 * a macro body, using the remaining arguments.
	 */
	if(isatty(0)){
		if(argc > 1)
			fprint(2, "%S", argv[1]);
		else
			fprint(2, "%c", 7/*BEL*/);
	}

	if(!didstdin){
		Binit(&bstdin, 0, OREAD);
		didstdin = 1;
	}
	runefmtstrinit(&fmt);
	while((s = Brdstr(&bstdin, '\n', 0)) != nil){
		if(s[0] == '\n'){
			free(s);
			break;
		}
		fmtprint(&fmt, "%s", s);
		free(s);
	}
	p = runefmtstrflush(&fmt);
	if(p == nil)
		warn("out of memory in %Crd", dot);
	ds(L(".rd"), p);
	argc--;
	argv++;
	argv[0] = L(".rd");
	runmacro('.', argc, argv);
	ds(L(".rd"), nil);
}

/* terminate exactly as if input had ended */
void
r_ex(int argc, Rune **argv)
{
	USED(argc);
	USED(argv);

	while(popinput())
		;
}

void
t18init(void)
{
	addreq(L("rd"), r_rd, -1);
	addreq(L("ex"), r_ex, 0);
}