plan9port/src/cmd/tbl/tm.c

64 lines
1.1 KiB
C
Raw Normal View History

2004-05-15 23:24:00 +00:00
/* tm.c: split numerical fields */
# include "t.h"
char *
maknew(char *str)
{
/* make two numerical fields */
2006-04-20 21:00:21 +00:00
int c;
char *p, *q, *ba, *dpoint;
2004-05-15 23:24:00 +00:00
p = str;
2004-05-17 02:23:43 +00:00
for (ba = 0; c = *str; str++)
2004-05-15 23:24:00 +00:00
if (c == '\\' && *(str + 1) == '&')
ba = str;
str = p;
if (ba == 0) {
for (dpoint = 0; *str; str++) {
if (*str == '.' && !ineqn(str, p) &&
(str > p && digit(*(str - 1)) ||
2004-05-15 23:24:00 +00:00
digit(*(str + 1))))
2006-04-20 21:00:21 +00:00
dpoint = str;
2004-05-15 23:24:00 +00:00
}
if (dpoint == 0)
for (; str > p; str--) {
if (digit( *(str - 1) ) && !ineqn(str, p))
break;
}
if (!dpoint && p == str) /* not numerical, don't split */
return(0);
if (dpoint)
2006-04-20 21:00:21 +00:00
str = dpoint;
2004-05-15 23:24:00 +00:00
} else
str = ba;
p = str;
if (exstore == 0 || exstore > exlim) {
exstore = exspace = chspace();
exlim = exstore + MAXCHS;
}
q = exstore;
2004-05-17 02:23:43 +00:00
while (*exstore++ = *str++)
2004-05-15 23:24:00 +00:00
;
*p = 0;
return(q);
}
int
ineqn (char *s, char *p)
{
/* true if s is in a eqn within p */
int ineq = 0, c;
2004-05-17 02:23:43 +00:00
while (c = *p) {
2004-05-15 23:24:00 +00:00
if (s == p)
return(ineq);
p++;
if ((ineq == 0) && (c == delim1))
ineq = 1;
else if ((ineq == 1) && (c == delim2))
ineq = 0;
}
return(0);
}