xref: /csrg-svn/old/tbl/tm.c (revision 14514)
1 #ifndef lint
2 static char sccsid[] = "@(#)tm.c	4.2 08/11/83";
3 #endif
4 
5  /* tm.c: split numerical fields */
6 # include "t..c"
7 maknew(str)
8 	char *str;
9 {
10 	/* make two numerical fields */
11 	int dpoint, c;
12 	char *p, *q, *ba;
13 	p = str;
14 	for (ba= 0; c = *str; str++)
15 		if (c == '\\' && *(str+1)== '&')
16 			ba=str;
17 	str=p;
18 	if (ba==0)
19 		{
20 		for (dpoint=0; *str; str++)
21 			{
22 			if (*str=='.' && !ineqn(str,p) &&
23 				(str>p && digit(*(str-1)) ||
24 				digit(*(str+1))))
25 					dpoint=str;
26 			}
27 		if (dpoint==0)
28 			for(; str>p; str--)
29 			{
30 			if (digit( * (str-1) ) && !ineqn(str, p))
31 				break;
32 			}
33 		if (!dpoint && p==str) /* not numerical, don't split */
34 			return(0);
35 		if (dpoint) str=dpoint;
36 		}
37 	else
38 		str = ba;
39 	p =str;
40 	if (exstore ==0 || exstore >exlim)
41 		{
42 		exstore = chspace();
43 		exlim= exstore+MAXCHS;
44 		}
45 	q = exstore;
46 	while (*exstore++ = *str++);
47 	*p = 0;
48 	return(q);
49 	}
50 ineqn (s, p)
51 	char *s, *p;
52 {
53 /* true if s is in a eqn within p */
54 int ineq = 0, c;
55 while (c = *p)
56 	{
57 	if (s == p)
58 		return(ineq);
59 	p++;
60 	if ((ineq == 0) && (c == delim1))
61 		ineq = 1;
62 	else
63 	if ((ineq == 1) && (c == delim2))
64 		ineq = 0;
65 	}
66 return(0);
67 }
68