'Unicoder v1.0.1, 2025-10-26.
'https://www.reddit.com/user/jcunews1
'https://pastebin.com/u/jcunews
'https://greasyfork.org/en/users/85671-jcunews
'
'Convert text with source character set to Unicode.
'A tool to help displaying CJK text when system codepage is not set to CJK.
'For use in console only.
sub help
wsh.stdout.writeline "Usage: unicoder [/u] {charset} [input file]" _
& vbcrlf & "If not input file is specified, use standard input." _
& vbcrlf & "Use /u switch for UTF-8 output (for redirected output)."
wsh.quit 1
end sub
if wsh.arguments.unnamed.count = 0 then help
set ds = createobject("adodb.stream") : ds.open
on error resume next
cs = wsh.arguments.unnamed(0)
ds.charset = cs
if err.number <> 0 then
wsh.stdout.writeline "Invalid charset."
wsh.quit 2
end if
on error goto 0
if wsh.arguments.unnamed.count >= 2 then
ds.loadfromfile wsh.arguments.unnamed(1)
ds.position = 0
s = ""
do while not ds.eos
s = s & ds.readtext(1)
loop
wsh.stdout.write s
wsh.quit
else
ds.charset = "x-user-defined"
ds.writetext wsh.stdin.readall
ds.position = 0
ds.charset = cs
end if
s = ""
do while not ds.eos
s = s & ds.readtext(1)
loop
if wsh.arguments.named.exists("u") then
set d = createobject("htmlfile")
d.open
d.write ""
d.close
s = d.s
on error resume next
for i = 1 to len(s)
c = mid(s, i, 1)
err.number = 0
wsh.stdout.write c
if err.number <> 0 then wsh.stdout.write chr(ascw(c))
next
else
wsh.stdout.write s
end if