Fix tr(1) behaviour in special cases and be stricter about stuff
This commit is contained in:
parent
f9d9672326
commit
ff0347e391
21
tr.c
21
tr.c
|
@ -202,6 +202,8 @@ main(int argc, char *argv[])
|
||||||
eprintf("set2 must be non-empty.\n");
|
eprintf("set2 must be non-empty.\n");
|
||||||
if (set2check && set2check != iswlower && set2check != iswupper)
|
if (set2check && set2check != iswlower && set2check != iswupper)
|
||||||
eprintf("set2 can only be the 'lower' or 'upper' class.\n");
|
eprintf("set2 can only be the 'lower' or 'upper' class.\n");
|
||||||
|
if (set2check && cflag && !dflag)
|
||||||
|
eprintf("set2 can't be imaged to from a complement.\n");
|
||||||
read:
|
read:
|
||||||
if (!readrune("<stdin>", stdin, &r))
|
if (!readrune("<stdin>", stdin, &r))
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -209,10 +211,10 @@ read:
|
||||||
for (i = 0; i < set1ranges; i++) {
|
for (i = 0; i < set1ranges; i++) {
|
||||||
if (set1[i].start <= r && r <= set1[i].end) {
|
if (set1[i].start <= r && r <= set1[i].end) {
|
||||||
if (dflag) {
|
if (dflag) {
|
||||||
if (cflag)
|
if (!cflag || (sflag && r == lastrune))
|
||||||
goto write;
|
|
||||||
else
|
|
||||||
goto read;
|
goto read;
|
||||||
|
else
|
||||||
|
goto write;
|
||||||
}
|
}
|
||||||
if (sflag) {
|
if (sflag) {
|
||||||
if (r == lastrune)
|
if (r == lastrune)
|
||||||
|
@ -241,11 +243,12 @@ read:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (set1check && set1check((wint_t)r)) {
|
if (set1check && set1check((wint_t)r)) {
|
||||||
if (dflag)
|
if (dflag) {
|
||||||
if (cflag)
|
if (!cflag || (sflag && r == lastrune))
|
||||||
goto write;
|
|
||||||
else
|
|
||||||
goto read;
|
goto read;
|
||||||
|
else
|
||||||
|
goto write;
|
||||||
|
}
|
||||||
if (sflag) {
|
if (sflag) {
|
||||||
if (r == lastrune)
|
if (r == lastrune)
|
||||||
goto read;
|
goto read;
|
||||||
|
@ -257,9 +260,11 @@ read:
|
||||||
else if (set1check == iswlower && set2check == iswupper)
|
else if (set1check == iswlower && set2check == iswupper)
|
||||||
r = towupper((wint_t)r);
|
r = towupper((wint_t)r);
|
||||||
else if (set2ranges > 0)
|
else if (set2ranges > 0)
|
||||||
r = set2[set2ranges - 1].end;
|
r = cflag ? r : set2[set2ranges - 1].end;
|
||||||
else
|
else
|
||||||
eprintf("Misaligned character classes.\n");
|
eprintf("Misaligned character classes.\n");
|
||||||
|
} else if (cflag && set2ranges > 0) {
|
||||||
|
r = set2[set2ranges - 1].end;
|
||||||
}
|
}
|
||||||
if (dflag && cflag)
|
if (dflag && cflag)
|
||||||
goto read;
|
goto read;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user