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