xref: /illumos-gate/usr/src/cmd/tbl/tm.c (revision 2a8bcb4e)
1*b5514887Smuffin /*
2*b5514887Smuffin  * Copyright 1991 Sun Microsystems, Inc.  All rights reserved.
3*b5514887Smuffin  * Use is subject to license terms.
4*b5514887Smuffin  */
5*b5514887Smuffin 
67c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
77c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
87c478bd9Sstevel@tonic-gate 
97c478bd9Sstevel@tonic-gate /*
107c478bd9Sstevel@tonic-gate  * Copyright (c) 1980 Regents of the University of California.
117c478bd9Sstevel@tonic-gate  * All rights reserved. The Berkeley software License Agreement
127c478bd9Sstevel@tonic-gate  * specifies the terms and conditions for redistribution.
137c478bd9Sstevel@tonic-gate  */
147c478bd9Sstevel@tonic-gate 
157c478bd9Sstevel@tonic-gate  /* tm.c: split numerical fields */
167c478bd9Sstevel@tonic-gate # include "t..c"
17*b5514887Smuffin 
187c478bd9Sstevel@tonic-gate char *
maknew(char * str)19*b5514887Smuffin maknew(char *str)
207c478bd9Sstevel@tonic-gate {
217c478bd9Sstevel@tonic-gate 	/* make two numerical fields */
227c478bd9Sstevel@tonic-gate 	int c;
237c478bd9Sstevel@tonic-gate 	char *dpoint, *p, *q, *ba;
247c478bd9Sstevel@tonic-gate 	p = str;
257c478bd9Sstevel@tonic-gate 	for (ba= 0; c = *str; str++)
267c478bd9Sstevel@tonic-gate 		if (c == '\\' && *(str+1)== '&')
277c478bd9Sstevel@tonic-gate 			ba=str;
287c478bd9Sstevel@tonic-gate 	str=p;
297c478bd9Sstevel@tonic-gate 	if (ba==0)
307c478bd9Sstevel@tonic-gate 		{
317c478bd9Sstevel@tonic-gate 		for (dpoint=0; *str; str++)
327c478bd9Sstevel@tonic-gate 			{
337c478bd9Sstevel@tonic-gate 			if (*str=='.' && !ineqn(str,p) &&
347c478bd9Sstevel@tonic-gate 				(str>p && digit(*(str-1)) ||
357c478bd9Sstevel@tonic-gate 				digit(*(str+1))))
367c478bd9Sstevel@tonic-gate 					dpoint=str;
377c478bd9Sstevel@tonic-gate 			}
387c478bd9Sstevel@tonic-gate 		if (dpoint==0)
397c478bd9Sstevel@tonic-gate 			for(; str>p; str--)
407c478bd9Sstevel@tonic-gate 			{
417c478bd9Sstevel@tonic-gate 			if (digit( * (str-1) ) && !ineqn(str, p))
427c478bd9Sstevel@tonic-gate 				break;
437c478bd9Sstevel@tonic-gate 			}
447c478bd9Sstevel@tonic-gate 		if (!dpoint && p==str) /* not numerical, don't split */
457c478bd9Sstevel@tonic-gate 			return(0);
467c478bd9Sstevel@tonic-gate 		if (dpoint) str=dpoint;
477c478bd9Sstevel@tonic-gate 		}
487c478bd9Sstevel@tonic-gate 	else
497c478bd9Sstevel@tonic-gate 		str = ba;
507c478bd9Sstevel@tonic-gate 	p =str;
517c478bd9Sstevel@tonic-gate 	if (exstore ==0 || exstore >exlim)
527c478bd9Sstevel@tonic-gate 		{
537c478bd9Sstevel@tonic-gate 		exstore = chspace();
547c478bd9Sstevel@tonic-gate 		exlim= exstore+MAXCHS;
557c478bd9Sstevel@tonic-gate 		}
567c478bd9Sstevel@tonic-gate 	q = exstore;
577c478bd9Sstevel@tonic-gate 	ba = exstore + MAXSTR;
587c478bd9Sstevel@tonic-gate 	do {
597c478bd9Sstevel@tonic-gate 		if (exstore > ba)
607c478bd9Sstevel@tonic-gate 			error(gettext("numeric field too big"));
617c478bd9Sstevel@tonic-gate 	} while (*exstore++ = *str++);
627c478bd9Sstevel@tonic-gate 	*p = 0;
637c478bd9Sstevel@tonic-gate 	return(q);
64*b5514887Smuffin }
65*b5514887Smuffin 
66*b5514887Smuffin int
ineqn(char * s,char * p)67*b5514887Smuffin ineqn (char *s, char *p)
687c478bd9Sstevel@tonic-gate {
697c478bd9Sstevel@tonic-gate /* true if s is in a eqn within p */
707c478bd9Sstevel@tonic-gate int ineq = 0, c;
717c478bd9Sstevel@tonic-gate while (c = *p)
727c478bd9Sstevel@tonic-gate 	{
737c478bd9Sstevel@tonic-gate 	if (s == p)
747c478bd9Sstevel@tonic-gate 		return(ineq);
757c478bd9Sstevel@tonic-gate 	p++;
767c478bd9Sstevel@tonic-gate 	if ((ineq == 0) && (c == delim1))
777c478bd9Sstevel@tonic-gate 		ineq = 1;
787c478bd9Sstevel@tonic-gate 	else
797c478bd9Sstevel@tonic-gate 	if ((ineq == 1) && (c == delim2))
807c478bd9Sstevel@tonic-gate 		ineq = 0;
817c478bd9Sstevel@tonic-gate 	}
827c478bd9Sstevel@tonic-gate return(0);
837c478bd9Sstevel@tonic-gate }
84