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