1. --------------------------------------
  2. --
  3. --------------------------------------
  4. on uuencode(str)
  5.   ret=""
  6.   n = str.Length mod 3
  7.  
  8.   if (n <> 0) then
  9.     repeat with i = 1 to 3 - n
  10.       put numtochar(0) after str
  11.     end repeat
  12.   end if
  13.  
  14.   j = str.Length
  15.   i = 1
  16.  
  17.   repeat while true
  18.     if i>j then exit repeat
  19.    
  20.     put numtochar(chartonum(str.char[1+  i-1]) / 4 + 32) after ret
  21.     put numtochar(chartonum(str.char[1+  i-1]) mod 4 * 16 + chartonum(str.char[1+ i]) / 16 + 32) after ret
  22.     put numtochar(chartonum(str.char[1+  i  ]) mod 16 * 4 + chartonum(str.char[1+ i + 1]) / 64 + 32) after ret
  23.     put numtochar(chartonum(str.char[1+  i+1]) mod 64 + 32) after ret
  24.    
  25.     i = i + 3
  26.   end repeat
  27.   return ret
  28. end
  29.  
  30. --------------------------------------
  31. --
  32. --------------------------------------
  33. on uudecode(str)
  34.  
  35.   --if str starts "," then delete char 1 of str  
  36.   --if the last char of str = "`" then delete the last char of str
  37.   --if the last char of str = numtochar(10) then delete the last char of str
  38.  
  39.   str = str_replace("`"," ",str)
  40.  
  41.   ret=""
  42.   j = str.Length
  43.   i = 1
  44.  
  45.   repeat while true
  46.     if i>j then exit repeat
  47.    
  48.     put numtochar( ( chartonum(str.char[1+ i-1]) - 32)   * 4   + (chartonum( str.char[1+ i]) - 32) / 16 ) after ret
  49.     put numtochar( ((chartonum(str.char[1+ i  ]) mod 16) * 16) + (chartonum( str.char[1+ i+1]) - 32) / 4 ) after ret
  50.     put numtochar( ((chartonum(str.char[1+ i+1]) mod 4)  * 64) + (chartonum( str.char[1+ i+2]) - 32) ) after ret
  51.    
  52.     i = i + 4
  53.   end repeat
  54.   return ret
  55. end
  56.  
  57. --------------------------------------
  58. -- TO DO
  59. --------------------------------------
  60. on uuencode_file(str)
  61.   -- "begin %s %s\n" <mode>, <decode_pathname>
  62.  
  63.   -- "end\n"
  64. end
  65.  
  66. --------------------------------------
  67. --
  68. --------------------------------------
  69. on uudecode_file(str)
  70.   if str starts "begin " then delete line 1 of str
  71.   if str starts "," then delete char 1 of str
  72.  
  73.   repeat while true
  74.     if [numtochar(10),numtochar(13)].getPos(str.char[str.length]) then
  75.       delete the last char of str
  76.      
  77.     else if str.char[str.length-1..str.length]=numtochar(10)&"`" then
  78.       delete char str.length-2 to str.length of str
  79.      
  80.     else if str.char[str.length-2..str.length]="end" then
  81.       delete char str.length-2 to str.length of str
  82.     else
  83.       exit repeat
  84.     end if
  85.   end repeat
  86.  
  87.   -- if the last char of str = "`" then delete the last char of str
  88.   -- if the last char of str = numtochar(10) then delete the last char of str
  89.  
  90.   ret = ""
  91.  
  92.   cnt = str.line.count
  93.   repeat with k = 1 to cnt
  94.    
  95.     tLine = str.line[k]
  96.     if tLine.char[1]=numtochar(10) then delete char 1 of tLine
  97.     if k=cnt then len = chartonum(tLine.char[1])-32
  98.     delete char 1 of tLine -- usually "M"
  99.    
  100.     tLine = str_replace("`"," ",tLine)
  101.    
  102.     chunk=""
  103.     j = tLine.length
  104.     i = 1
  105.    
  106.     repeat while true
  107.       if i>j then exit repeat
  108.      
  109.       put numtochar( (chartonum(tLine.char[1+ i-1]) - 32) * 4 + (chartonum( tLine.char[1+ i]) - 32) / 16 ) after chunk
  110.       put numtochar( (chartonum(tLine.char[1+ i  ]) mod 16 * 16) + (chartonum( tLine.char[1+ i+1]) - 32) / 4 ) after chunk
  111.       put numtochar( (chartonum(tLine.char[1+ i+1]) mod 4 * 64) + (chartonum( tLine.char[1+ i+2]) - 32) ) after chunk
  112.      
  113.       i = i + 4
  114.     end repeat
  115.    
  116.     if k=cnt then delete char len+1 to chunk.length of chunk
  117.    
  118.     put chunk after ret
  119.   end repeat
  120.  
  121.   return ret
  122. end
  123.  
  124. ----------------------------------------
  125. -- replace in string
  126. ----------------------------------------
  127. on str_replace (stringToFind, stringToInsert, input)
  128.   output = ""
  129.   findLen = stringToFind.length - 1
  130.   repeat while true
  131.     currOffset = offset(stringToFind, input)
  132.     if currOffset=0 then exit repeat
  133.     put input.char [1..currOffset] after output
  134.     delete the last char of output
  135.     put stringToInsert after output
  136.     delete input.char [1.. (currOffset + findLen)]
  137.   end repeat
  138.   put input after output
  139.   return output
  140. end
  141.  
[raw code]