xref: /illumos-gate/usr/src/cmd/tbl/tm.c (revision e3ae4b35c024af1196582063ecee3ab79367227d)
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  /* tm.c: split numerical fields */
16 # include "t..c"
17 
18 char *
19 maknew(char *str)
20 {
21 	/* make two numerical fields */
22 	int c;
23 	char *dpoint, *p, *q, *ba;
24 	p = str;
25 	for (ba= 0; c = *str; str++)
26 		if (c == '\\' && *(str+1)== '&')
27 			ba=str;
28 	str=p;
29 	if (ba==0)
30 		{
31 		for (dpoint=0; *str; str++)
32 			{
33 			if (*str=='.' && !ineqn(str,p) &&
34 				(str>p && digit(*(str-1)) ||
35 				digit(*(str+1))))
36 					dpoint=str;
37 			}
38 		if (dpoint==0)
39 			for(; str>p; str--)
40 			{
41 			if (digit( * (str-1) ) && !ineqn(str, p))
42 				break;
43 			}
44 		if (!dpoint && p==str) /* not numerical, don't split */
45 			return(0);
46 		if (dpoint) str=dpoint;
47 		}
48 	else
49 		str = ba;
50 	p =str;
51 	if (exstore ==0 || exstore >exlim)
52 		{
53 		exstore = chspace();
54 		exlim= exstore+MAXCHS;
55 		}
56 	q = exstore;
57 	ba = exstore + MAXSTR;
58 	do {
59 		if (exstore > ba)
60 			error(gettext("numeric field too big"));
61 	} while (*exstore++ = *str++);
62 	*p = 0;
63 	return(q);
64 }
65 
66 int
67 ineqn (char *s, char *p)
68 {
69 /* true if s is in a eqn within p */
70 int ineq = 0, c;
71 while (c = *p)
72 	{
73 	if (s == p)
74 		return(ineq);
75 	p++;
76 	if ((ineq == 0) && (c == delim1))
77 		ineq = 1;
78 	else
79 	if ((ineq == 1) && (c == delim2))
80 		ineq = 0;
81 	}
82 return(0);
83 }
84