shellharden 4.0.1

The corrective bash syntax highlighter
#!/usr/bin/env python3

import subprocess
import sys

readarray = (
	'if test "$0" = ""; then\n'
	'    readarray -td $\'\\0\' array || true\n'
	'else\n'
	'    readarray -td "$0" array || true\n'
	'fi\n'
	'printf "«%s»" "${array[@]}"\n'
)
read_array = (
	'IFS="$0" read -rd \'\' -a array || true\n'
	'printf "«%s»" "${array[@]}"\n'
)
while_read = (
	'array=()\n'
	'if test "$0" = ""; then\n'
	'    while read -rd $\'\\0\' i; do array+=("$i"); done\n'
	'else\n'
	'    while read -rd "$0" i; do array+=("$i"); done\n'
	'fi\n'
	'printf "«%s»" "${array[@]}"\n'
)

def prove(i, bash):
	sep = bytes([i])
	pseudoarray = sep + b'a' + sep + sep + b'a' + sep + sep
	if i == 0:
		sep = b''
	p = subprocess.Popen([b'bash', b'-ec', bash.encode('UTF-8'), sep], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
	p.stdin.write(pseudoarray)
	out, err = p.communicate()
	if err:
		return b'FAIL';
	if out == '«»«a»«»«a»«»'.encode('UTF-8'):
		return b'PASS'
	return out

def nibble2hex(n):
	if n < 10:
		return n + 48
	return n + 87

def byte2hex(b):
	return bytes([nibble2hex(b >> 4), nibble2hex(b & 0xF), 32])

for i in range(0, 128):
	if i == 97:
		continue
	sys.stdout.buffer.write(byte2hex(i) + prove(i, readarray) + b'\n')

for i in range(1, 256):
	if i == 97:
		continue
	sys.stdout.buffer.write(byte2hex(i) + prove(i, read_array) + b'\n')

for i in range(0, 256):
	if i == 97:
		continue
	sys.stdout.buffer.write(byte2hex(i) + prove(i, while_read) + b'\n')