Skip to content

Instantly share code, notes, and snippets.

@ttdoda
Created July 8, 2014 11:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ttdoda/26af95afd6f48ed0991c to your computer and use it in GitHub Desktop.
Save ttdoda/26af95afd6f48ed0991c to your computer and use it in GitHub Desktop.
Tera Termマクロでのuudecodeの実装
setsync 1
timeout = 0
; getspecialfolder save_dir "MyDocuments"
getspecialfolder save_dir "Desktop"
; save_dir = "C:\My Documents"
; save_dir = ""
do
recvln
if result == 0 end
strmatch inputstr "^begin \d+ (\S+)"
if result == 1 break
loop
basename filename groupmatchstr1
ifdefined save_dir
if result == 3 then
strlen save_dir
if result > 0 makepath filename save_dir filename
endif
filecreate fh filename
bytes = 0
call status
do
recvln
if result == 0 then
messagebox "Connection closed" "uudecode: Error"
goto error
endif
strcompare inputstr "end"
if result == 0 break
strlen inputstr
inputlen = result
if inputlen == 0 continue
strcopy inputstr 1 1 c
str2code orglen c
orglen = (orglen - $20) & $3f
enclen = (orglen * 4 + 2) / 3
if enclen >= inputlen then
messagebox "Broken input" "uudecode: Error"
goto error
endif
strcopy inputstr 2 enclen encstr
while orglen > 0
v = 0
count = 0
call getc
call getc
offset = 4
call putc
if orglen == 1 break
call getc
offset = 2
call putc
if orglen == 2 break
call getc
offset = 0
call putc
enclen = enclen - 4
strcopy encstr 5 enclen encstr
orglen = orglen - 3
endwhile
call status
loop
:error
fileclose fh
filetruncate filename bytes
end
:getc
count = count + 1
strcopy encstr count 1 c
str2code t c
v = (v << 6) + ((t - $20) & $3f)
return
:putc
t = (v >> offset) & $ff
if t == 0 then
fileseek fh 1 1
else
code2str tc t
filewrite fh tc
endif
bytes = bytes + 1
return
:status
sprintf2 stitle "uudecode: %s" filename
sprintf2 msg "Filename: %s"#$0a"%d bytes received." filename bytes
statusbox msg stitle
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment