aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/htmlroff/t17.c
blob: bbd095d54250a8ea9b63c1c4f5c88b00ba7929b9 (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include "a.h"

/*
 * 17.  Environment switching.
 */
typedef struct Env Env;
struct Env
{
	int s;
	int s0;
	int f;
	int f0;
	int fi;
	int ad;
	int ce;
	int v;
	int v0;
	int ls;
	int ls0;
	int it;
	/* - ta */
	/* - tc */
	/* - lc */
	/* - ul */
	/* - cu */
	/* - cc */
	/* - c2 */
	/* - nh */
	/* - hy */
	/* - hc */
	/* - lt */
	/* - nm */
	/* - nn */
	/* - mc */
};

Env defenv =
{
	10,
	10,
	1,
	1,
	1,
	1,
	0,
	12,
	12,
	0,
	0,
	0
};

Env env[3];
Env *evstack[20];
int nevstack;

void
saveenv(Env *e)
{
	e->s = getnr(L(".s"));
	e->s0 = getnr(L(".s0"));
	e->f = getnr(L(".f"));
	e->f0 = getnr(L(".f0"));
	e->fi = getnr(L(".fi"));
	e->ad = getnr(L(".ad"));
	e->ce = getnr(L(".ce"));
	e->v = getnr(L(".v"));
	e->v0 = getnr(L(".v0"));
	e->ls = getnr(L(".ls"));
	e->ls0 = getnr(L(".ls0"));
	e->it = getnr(L(".it"));
}

void
restoreenv(Env *e)
{
	nr(L(".s"), e->s);
	nr(L(".s0"), e->s0);
	nr(L(".f"), e->f);
	nr(L(".f0"), e->f0);
	nr(L(".fi"), e->fi);
	nr(L(".ad"), e->ad);
	nr(L(".ce"), e->ce);
	nr(L(".v"), e->v);
	nr(L(".v0"), e->v0);
	nr(L(".ls"), e->ls);
	nr(L(".ls0"), e->ls0);
	nr(L(".it"), e->it);

	nr(L(".ev"), e-env);
	runmacro1(L("font"));
}


void
r_ev(int argc, Rune **argv)
{
	int i;
	Env *e;
	
	if(argc == 1){
		if(nevstack <= 0){
			if(verbose) warn(".ev stack underflow");
			return;
		}
		restoreenv(evstack[--nevstack]);
		return;
	}
	if(nevstack >= nelem(evstack))
		sysfatal(".ev stack overflow");
	i = eval(argv[1]);
	if(i < 0 || i > 2){
		warn(".ev bad environment %d", i);
		i = 0;
	}
	e = &env[getnr(L(".ev"))];
	saveenv(e);
	evstack[nevstack++] = e;
	restoreenv(&env[i]);
}

void
t17init(void)
{
	int i;
	
	for(i=0; i<nelem(env); i++)
		env[i] = defenv;

	addreq(L("ev"), r_ev, -1);
}