aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/tbl/tm.c
blob: cee294c4fe462c6c4a58abdd0693a41d11343628 (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
/* tm.c: split numerical fields */
# include "t.h"

char	*
maknew(char *str)
{
				/* make two numerical fields */
	int	c;
	char	*p, *q, *ba, *dpoint;

	p = str;
	for (ba = 0; c = *str; str++)
		if (c == '\\' && *(str + 1) == '&')
			ba = str;
	str = p;
	if (ba == 0) {
		for (dpoint = 0; *str; str++) {
			if (*str == '.' && !ineqn(str, p) &&
			    (str > p && digit(*(str - 1)) ||
			    digit(*(str + 1))))
				dpoint = str;
		}
		if (dpoint == 0)
			for (; str > p; str--) {
				if (digit( *(str - 1) ) && !ineqn(str, p))
					break;
			}
		if (!dpoint && p == str) /* not numerical, don't split */
			return(0);
		if (dpoint)
			str = dpoint;
	} else
		str = ba;
	p = str;
	if (exstore == 0 || exstore > exlim) {
		exstore = exspace = chspace();
		exlim = exstore + MAXCHS;
	}
	q = exstore;
	while (*exstore++ = *str++)
		;
	*p = 0;
	return(q);
}


int
ineqn (char *s, char *p)
{
				/* true if s is in a eqn within p */
	int	ineq = 0, c;

	while (c = *p) {
		if (s == p)
			return(ineq);
		p++;
		if ((ineq == 0) && (c == delim1))
			ineq = 1;
		else if ((ineq == 1) && (c == delim2))
			ineq = 0;
	}
	return(0);
}