1 #ifndef lint
2 static char sccsid[] = "@(#)numfields.c	1.2 (CWI) 85/10/02";
3 #endif lint
4 
5 #include "defs.h"
6 #include "ext.h"
7 
8 /*
9  * Make two numerical fields
10  */
11 char *
12 maknew(str)
13 char *str;
14 {
15 	extern char *chspace();
16 	int dpoint, c;
17 	register char *p, *q, *ba;
18 
19 	p = str;
20 	for(ba = 0; c = *str; str++){
21 		if(c == '\\' && *(str + 1) == '&')
22 			ba = str;
23 	}
24 	str = p;
25 	if(ba == 0){
26 		for(dpoint = 0; *str; str++){
27 			if(*str == '.' && !ineqn(str, p)
28 				       && (str > p && isdigit(*(str - 1)) ||
29 							isdigit(*(str + 1))))
30 				dpoint = (int) str;
31 		}
32 		if(dpoint == 0){
33 			for(; str > p; str--){
34 				if(isdigit(*(str - 1)) && !ineqn (str, p))
35 					break;
36 			}
37 		}
38 		if(!dpoint && p == str)
39 			/*
40 			 * not numerical, don't split
41 			 */
42 			return(0);
43 		if(dpoint)
44 			str = (char *)dpoint;
45 	} else
46 		str = ba;
47 	p = str;
48 	if(exstore == 0 || exstore > exlim){
49 		exstore = chspace();
50 		exlim = exstore + MAXCHS;
51 	}
52 	q = exstore;
53 	while(*exstore++ = *str++)
54 		;
55 	*p = 0;
56 	return(q);
57 }
58 
59 /*
60  * True, if s is in a eqn within p
61  */
62 ineqn(s, p)
63 char *s, *p;
64 {
65 	int ineq = 0, c;
66 
67 	while(c = *p){
68 		if(s == p)
69 			return(ineq);
70 		p++;
71 		if((ineq == 0) && (c == delim1)){
72 			ineq = 1;
73 		} else {
74 			if((ineq == 1) && (c == delim2))
75 				ineq = 0;
76 		}
77 	}
78 	return(0);
79 }
80