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