home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Extra 1997 #5 / AmigaPlus_Extra-CD_5-97.iso / online-tools / mail / mailserver / sys / autoencode next >
Text File  |  1995-04-08  |  1KB  |  63 lines

  1. /* $VER: 1.0 */
  2. /* Check for binary files, then automatically uuencode them to OUTFILE
  3.    If not binary, simply copy the file to OUTFILE */
  4.  
  5. parse arg files
  6.  
  7. if words(files) < 2 then
  8.   do
  9.    say 'USAGE: autoencode INFILE OUTFILE'
  10.    exit
  11.   end
  12.  
  13. infile  = word(files,1)
  14. outfile = word(files,2)
  15. outfile2 = outfile'.2'
  16.  
  17. uucmd   = 'c:uuxt a 'outfile2' 'infile' >nil:'
  18.  
  19.  
  20. if ~exists(infile) then
  21.   do
  22.     say 'File "'infile'" does not exist.'
  23.     exit
  24.   end
  25.  
  26.  
  27. open(tmpfile,infile,'r')
  28.  
  29.   /* Find file length */
  30.   lof = seek(tmpfile,0,'E')
  31.   len = min(lof,100)
  32.   seek(tmpfile,0,'B')
  33.   string = readch(tmpfile,100)
  34. close(tmpfile)
  35.  
  36. bin = 'no'
  37.  
  38. do chrnum = 1 to 100
  39.   chr = substr(string,chrnum,1)
  40.  if c2d(chr) >127 then bin = 'yes'
  41.  
  42. end
  43.  
  44.  
  45. if bin = 'no' then
  46.    address command 'copy 'infile' 'outfile2
  47.  
  48.     else
  49.  
  50.    address command uucmd
  51.  
  52. /* Add the filename to the file */
  53.  
  54. address command 'echo File: 'infile' > 'outfile
  55. address command 'echo "" >> 'outfile
  56. address command 'echo ---------- 8< ----- Cut Here ---------------------------------------- >> 'outfile
  57. address command 'echo "" >> 'outfile
  58. address command 'type 'outfile2' >> 'outfile
  59. address command 'delete >nil: 'outfile2
  60.  
  61.  
  62. exit
  63.