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/tc.c |
Import sources from 2011-03-30 iso image
Diffstat (limited to 'sys/src/cmd/tbl/tc.c')
-rwxr-xr-x | sys/src/cmd/tbl/tc.c | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/sys/src/cmd/tbl/tc.c b/sys/src/cmd/tbl/tc.c new file mode 100755 index 000000000..84f244528 --- /dev/null +++ b/sys/src/cmd/tbl/tc.c @@ -0,0 +1,61 @@ +/* tc.c: find character not in table to delimit fields */ +# include "t.h" + +# define COMMON "\002\003\005\006\007!%&#/?,:;<=>@`^~_{}+-*" \ + "ABCDEFGHIJKMNOPQRSTUVWXZabcdefgjkoqrstwxyz" + +void +choochar(void) +{ + /* choose funny characters to delimit fields */ + int had[128], ilin, icol, k; + char *s; + + for (icol = 0; icol < 128; icol++) + had[icol] = 0; + F1 = F2 = 0; + for (ilin = 0; ilin < nlin; ilin++) { + if (instead[ilin] || fullbot[ilin]) + continue; + for (icol = 0; icol < ncol; icol++) { + k = ctype(ilin, icol); + if (k == 0 || k == '-' || k == '=') + continue; + s = table[ilin][icol].col; + if (point(s)) + for (; *s; s++) + if((unsigned char)*s < 128) + had[(unsigned char)*s] = 1; + s = table[ilin][icol].rcol; + if (point(s)) + for (; *s; s++) + if((unsigned char)*s < 128) + had[(unsigned char)*s] = 1; + } + } + /* choose first funny character */ + for (s = COMMON "Y"; *s; s++) { + if (had[*s] == 0) { + F1 = *s; + had[F1] = 1; + break; + } + } + /* choose second funny character */ + for (s = COMMON "u"; *s; s++) { + if (had[*s] == 0) { + F2 = *s; + break; + } + } + if (F1 == 0 || F2 == 0) + error("couldn't find characters to use for delimiters"); +} + +int +point(char *ss) +{ + vlong s = (uintptr)ss; + + return(s >= 128 || s < 0); +} |