Add trivial equivalence class support in tr(1) and update manpage

Equivalence classes are a hard matter and there's still no "standard"
way to solve the issue.
Previously, tr would just skip those classes, but it's much
better when it resolves a [=c=] to a normal c instead of treating
it as a literal.

Also, reflect recent changes in the manpage (octal escapes) and fix
the markup in some areas.
This commit is contained in:
FRIGN 2015-01-28 19:44:05 +01:00
parent 63d7f29bd9
commit ee6f7d3fc0
2 changed files with 18 additions and 7 deletions

19
tr.1
View File

@ -25,22 +25,27 @@ Squeeze repeated characters matching
.Ar set1 .Ar set1
or or
.Ar set2 .Ar set2
if -d is set. if
.Fl d
is set.
.El .El
.Sh SET .Sh SET
.Bl -tag -width Ds .Bl -tag -width Ds
.It Literal 'c' .It Literal Sy c
.It Escape sequence '\ec' .It Escape sequence Sy \ec
\e\e, \ea, \eb, \ef, \en, \er, \et, \ev \e\e, \ea, \eb, \ef, \en, \er, \et, \ev, \eO[OO]
.It Range 'c-d' .It Range Sy c-d
.It Repeat '[c*n]' .It Repeat Sy [c*n]
Only in Only in
.Ar set2 . .Ar set2 .
If n = 0 or left out, set n to length of If n = 0 or left out, set n to length of
.Ar set1 . .Ar set1 .
.It Character class '[:class:]' .It Character class Sy [:class:]
See See
.Xr wctype 3 . .Xr wctype 3 .
.It Equivalence class Sy [=c=]
Resolve to
.Sy c .
.El .El
.Sh TRANSLATION .Sh TRANSLATION
If no options are specified, If no options are specified,

6
tr.c
View File

@ -143,6 +143,12 @@ nextbrack:
/* CLASSES [=EQUIV=] (skip) */ /* CLASSES [=EQUIV=] (skip) */
if (j - i > 3 && rstr[i + 1] == '=' && rstr[m - 1] == '=') { if (j - i > 3 && rstr[i + 1] == '=' && rstr[m - 1] == '=') {
if (j - i != 4)
goto literal;
(*set)[setranges].start = rstr[i + 2];
(*set)[setranges].end = rstr[i + 2];
(*set)[setranges].quant = 1;
setranges++;
i = j; i = j;
continue; continue;
} }