diff options
author | Taru Karttunen <taruti@taruti.net> | 2011-03-30 15:46:40 +0300 |
---|---|---|
committer | Taru Karttunen <taruti@taruti.net> | 2011-03-30 15:46:40 +0300 |
commit | e5888a1ffdae813d7575f5fb02275c6bb07e5199 (patch) | |
tree | d8d51eac403f07814b9e936eed0c9a79195e2450 /sys/src/cmd/tbl/tm.c |
Import sources from 2011-03-30 iso image
Diffstat (limited to 'sys/src/cmd/tbl/tm.c')
-rwxr-xr-x | sys/src/cmd/tbl/tm.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/sys/src/cmd/tbl/tm.c b/sys/src/cmd/tbl/tm.c new file mode 100755 index 000000000..5b58f0d1b --- /dev/null +++ b/sys/src/cmd/tbl/tm.c @@ -0,0 +1,65 @@ +/* tm.c: split numerical fields */ +# include "t.h" + +char * +maknew(char *str) +{ + /* make two numerical fields */ + int c; + char *p, *q, *ba, *dpoint; + + p = str; + for (ba = 0; c = *str; str++) + 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)) || + digit(*(str + 1)))) + dpoint = str; + } + 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) + str = dpoint; + } else + str = ba; + p = str; + if (exstore == 0 || exstore > exlim) { + exstore = exspace = chspace(); + exlim = exstore + MAXCHS; + } + q = exstore; + while (*exstore++ = *str++) + ; + *p = 0; + return(q); +} + + +int +ineqn (char *s, char *p) +{ + /* true if s is in a eqn within p */ + int ineq = 0, c; + + while (c = *p) { + if (s == p) + return(ineq); + p++; + if ((ineq == 0) && (c == delim1)) + ineq = 1; + else if ((ineq == 1) && (c == delim2)) + ineq = 0; + } + return(0); +} + + |