tr: fix escape code handling in set2
Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>
This commit is contained in:
parent
e3c62682ff
commit
3e49e946b7
36
tr.c
36
tr.c
@ -49,32 +49,30 @@ handleescapes(char *s)
|
|||||||
static void
|
static void
|
||||||
parsemapping(const char *set1, const char *set2, wchar_t *mappings)
|
parsemapping(const char *set1, const char *set2, wchar_t *mappings)
|
||||||
{
|
{
|
||||||
char *s;
|
char *s1, *s2;
|
||||||
wchar_t runeleft;
|
wchar_t runeleft;
|
||||||
wchar_t runeright;
|
wchar_t runeright;
|
||||||
int leftbytes;
|
int leftbytes;
|
||||||
int rightbytes;
|
int rightbytes;
|
||||||
size_t n = 0;
|
|
||||||
size_t lset2;
|
|
||||||
|
|
||||||
if(set2) {
|
s1 = (char *)set1;
|
||||||
lset2 = strnlen(set2, 255 * sizeof(wchar_t));
|
if(set2)
|
||||||
} else {
|
s2 = (char *)set2;
|
||||||
set2 = &set1[0];
|
else
|
||||||
lset2 = 0;
|
s2 = (char *)set1;
|
||||||
}
|
|
||||||
|
|
||||||
s = (char *)set1;
|
while(*s1) {
|
||||||
while(*s) {
|
if(*s1 == '\\')
|
||||||
if(*s == '\\')
|
handleescapes(++s1);
|
||||||
handleescapes(++s);
|
leftbytes = mbtowc(&runeleft, s1, 4);
|
||||||
leftbytes = mbtowc(&runeleft, s, 4);
|
s1 += leftbytes;
|
||||||
if(set2[n] != '\0')
|
if(*s2 == '\\')
|
||||||
rightbytes = mbtowc(&runeright, set2 + n, 4);
|
handleescapes(++s2);
|
||||||
|
if(*s2 != '\0') {
|
||||||
|
rightbytes = mbtowc(&runeright, s2, 4);
|
||||||
|
s2 += rightbytes;
|
||||||
|
}
|
||||||
mappings[runeleft] = runeright;
|
mappings[runeleft] = runeright;
|
||||||
s += leftbytes;
|
|
||||||
if(n < lset2)
|
|
||||||
n += rightbytes;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user