summaryrefslogtreecommitdiffstats
path: root/usr.bin/tr
diff options
context:
space:
mode:
authortjr <tjr@FreeBSD.org>2002-07-29 14:50:54 +0000
committertjr <tjr@FreeBSD.org>2002-07-29 14:50:54 +0000
commitfb4f03d25610de0a32dd2a350951347ebeea6ace (patch)
treedd86d18e59ae8170623114290968505e139feca3 /usr.bin/tr
parenta8adf98c8204f370670e5624e9e11b497b7c97e8 (diff)
downloadFreeBSD-src-fb4f03d25610de0a32dd2a350951347ebeea6ace.zip
FreeBSD-src-fb4f03d25610de0a32dd2a350951347ebeea6ace.tar.gz
When translating and the -c option is specified, handle the case where the
second string argument is more than one character in length in the way required by SUSv3 (and the way GNU textutils and SVR4 do it).
Diffstat (limited to 'usr.bin/tr')
-rw-r--r--usr.bin/tr/tr.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/usr.bin/tr/tr.c b/usr.bin/tr/tr.c
index 524f66b..ff623cd 100644
--- a/usr.bin/tr/tr.c
+++ b/usr.bin/tr/tr.c
@@ -238,12 +238,17 @@ main(argc, argv)
(void)next(&s2);
}
- if (cflag)
- for (cnt = 0, p = string1; cnt < NCHARS; ++p, ++cnt)
- *p = *p == OOBCH ? ch : cnt;
- else if (Cflag)
- for (cnt = 0, p = string1; cnt < NCHARS; ++p, ++cnt)
- *p = *p == OOBCH && ISCHAR(cnt) ? ch : cnt;
+ if (cflag || Cflag) {
+ s2.str = argv[1];
+ s2.state = NORMAL;
+ for (cnt = 0, p = string1; cnt < NCHARS; ++p, ++cnt) {
+ if (*p == OOBCH && (!Cflag || ISCHAR(cnt))) {
+ (void)next(&s2);
+ *p = s2.lastch;
+ } else
+ *p = cnt;
+ }
+ }
if (sflag)
for (lastch = OOBCH; (ch = getchar()) != EOF;) {
OpenPOWER on IntegriCloud