xref: /titanic_52/usr/src/cmd/tbl/tm.c (revision 1a7c1b724419d3cb5fa6eea75123c6b2060ba31b)
1 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
2 /*	  All Rights Reserved  	*/
3 
4 
5 /*
6  * Copyright (c) 1980 Regents of the University of California.
7  * All rights reserved. The Berkeley software License Agreement
8  * specifies the terms and conditions for redistribution.
9  */
10 
11 /*
12  * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
13  * All Rights Reserved.
14  */
15 
16 #ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.1	*/
17 
18  /* tm.c: split numerical fields */
19 # include "t..c"
20 char *
21 maknew(str)
22 	char *str;
23 {
24 	/* make two numerical fields */
25 	int c;
26 	char *dpoint, *p, *q, *ba;
27 	p = str;
28 	for (ba= 0; c = *str; str++)
29 		if (c == '\\' && *(str+1)== '&')
30 			ba=str;
31 	str=p;
32 	if (ba==0)
33 		{
34 		for (dpoint=0; *str; str++)
35 			{
36 			if (*str=='.' && !ineqn(str,p) &&
37 				(str>p && digit(*(str-1)) ||
38 				digit(*(str+1))))
39 					dpoint=str;
40 			}
41 		if (dpoint==0)
42 			for(; str>p; str--)
43 			{
44 			if (digit( * (str-1) ) && !ineqn(str, p))
45 				break;
46 			}
47 		if (!dpoint && p==str) /* not numerical, don't split */
48 			return(0);
49 		if (dpoint) str=dpoint;
50 		}
51 	else
52 		str = ba;
53 	p =str;
54 	if (exstore ==0 || exstore >exlim)
55 		{
56 		exstore = chspace();
57 		exlim= exstore+MAXCHS;
58 		}
59 	q = exstore;
60 	ba = exstore + MAXSTR;
61 	do {
62 		if (exstore > ba)
63 			error(gettext("numeric field too big"));
64 	} while (*exstore++ = *str++);
65 	*p = 0;
66 	return(q);
67 	}
68 ineqn (s, p)
69 	char *s, *p;
70 {
71 /* true if s is in a eqn within p */
72 int ineq = 0, c;
73 while (c = *p)
74 	{
75 	if (s == p)
76 		return(ineq);
77 	p++;
78 	if ((ineq == 0) && (c == delim1))
79 		ineq = 1;
80 	else
81 	if ((ineq == 1) && (c == delim2))
82 		ineq = 0;
83 	}
84 return(0);
85 }
86