fill the map backwards (to use first occurrence of duplicates);
add a cache to ensure basic ASCII mapping is bijective
This commit is contained in:
parent
5743c00a5b
commit
7ff7821d6a
25
shf.c
25
shf.c
@ -25,7 +25,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.90 2017/04/28 11:13:49 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.91 2017/04/28 11:27:58 tg Exp $");
|
||||
|
||||
/* flags to shf_emptybuf() */
|
||||
#define EB_READSW 0x01 /* about to switch to reading */
|
||||
@ -1209,10 +1209,10 @@ const uint32_t tpl_ctypes[128] = {
|
||||
void
|
||||
set_ifs(const char *s)
|
||||
{
|
||||
ifs0 = *s;
|
||||
memcpy(ksh_ctypes, tpl_ctypes, sizeof(tpl_ctypes));
|
||||
memset((char *)ksh_ctypes + sizeof(tpl_ctypes), '\0',
|
||||
sizeof(ksh_ctypes) - sizeof(tpl_ctypes));
|
||||
ifs0 = *s;
|
||||
while (*s)
|
||||
ksh_ctypes[rtt2asc(*s++)] |= CiIFS;
|
||||
}
|
||||
@ -1225,9 +1225,11 @@ ebcdic_init(void)
|
||||
{
|
||||
int i = 256;
|
||||
unsigned char t;
|
||||
bool mapcache[128];
|
||||
|
||||
while (i--)
|
||||
ebcdic_rtt_toascii[i] = i;
|
||||
memset(ebcdic_rtt_fromascii, 0xFF, sizeof(ebcdic_rtt_fromascii));
|
||||
setlocale(LC_ALL, "");
|
||||
#ifdef MKSH_EBCDIC
|
||||
if (__etoa_l(ebcdic_rtt_toascii, 256) != 256) {
|
||||
@ -1236,10 +1238,12 @@ ebcdic_init(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
i = 0;
|
||||
do {
|
||||
memset(mapcache, 0, sizeof(mapcache));
|
||||
i = 256;
|
||||
while (i--) {
|
||||
t = ebcdic_rtt_toascii[i];
|
||||
/* fill the complete round-trip map */
|
||||
ebcdic_rtt_fromascii[ebcdic_rtt_toascii[i]] = i;
|
||||
ebcdic_rtt_fromascii[t] = i;
|
||||
/*
|
||||
* Only use the converted value if it's in the range
|
||||
* [0x00; 0x7F], which I checked; the "extended ASCII"
|
||||
@ -1251,10 +1255,15 @@ ebcdic_init(void)
|
||||
* an unsigned int, and or the raw unconverted EBCDIC
|
||||
* values with 0x01000000 instead.
|
||||
*/
|
||||
if ((t = ebcdic_rtt_toascii[i]) < 0x80U)
|
||||
if (t < 0x80U) {
|
||||
if (mapcache[t]) {
|
||||
write(2, "mksh: duplicate EBCDIC to ASCII mapping\n", 40);
|
||||
exit(255);
|
||||
}
|
||||
mapcache[t] = true;
|
||||
ebcdic_map[i] = (unsigned short)ord(t);
|
||||
else
|
||||
} else
|
||||
ebcdic_map[i] = (unsigned short)(0x100U | ord(i));
|
||||
} while (++i < 256);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user