home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Emulation / ZXAMSpectrum / ZXAM_Rexx / English / BatchConvert.zxam next >
Text File  |  1995-07-31  |  3KB  |  126 lines

  1. /* This script converts all selected snapshots to the format you want */
  2.  
  3.     /* test if emulator is present */
  4.     address command
  5.     
  6.     if ~show(ports,ZXAM_REXX) then do
  7.         requestchoice '>nil: title "ZXAM Script error..." body "I can''t find the emulator''s port!!" gadgets "AARGH!"'
  8.         exit
  9.         end
  10.  
  11.     /* store the initial status of the emulator */
  12.     running=zxamactrun()    /* 1=running */
  13.     zxamstop()              /* stop the emulation */
  14.     
  15.     /* old window status */
  16.     oldname=zxamactname()
  17.     oldformat=zxamactformat()
  18.     oldsaveformat=zxamactsaveformat()
  19.     
  20.     /* ask for the files to be converted */
  21.     'requestfile >t:zxamconvert.tmp "'zxamactloadpath()'" title "Select snapshots to convert..." pattern "'zxamactpattern()'" multiselect'
  22.     names=zxampploadfile('t:zxamconvert.tmp')
  23.     names=left(names,length(names)-1) /* discard LF */
  24.     
  25.     /* asf for destination drawer */
  26.     'requestfile >t:zxamconvert.tmp "'zxamactsavepath()'" drawersonly savemode'
  27.     destdrawer=zxampploadfile('t:zxamconvert.tmp')
  28.     destdrawer=strip(left(destdrawer,length(destdrawer)-1),'B','"') /* discard LF and " */
  29.     
  30.     /* ask for destination format */
  31.     requestchoice '>t:zxamconvert.tmp "ZXAM convert..."' '"What format do you want?"' GADGETS "PC|PC_PP|MIRAGE|MIRAGE_PP|CANCEL"
  32.     destformat=zxampploadfile('t:zxamconvert.tmp')
  33.     destformat=left(destformat,length(destformat)-1) /* discard LF */
  34.     
  35.     if names='' then exit
  36.     
  37.     if destformat=0 then exit /* CANCEL */
  38.     
  39.     if destformat=1 then do
  40.         destextension='.SP'
  41.         destformname='pc'
  42.         crunched=0
  43.         end
  44.  
  45.     if destformat=2 then do
  46.         destextension='.SP'
  47.         destformname='pc'
  48.         crunched=1
  49.         end
  50.         
  51.     if destformat=3 then do
  52.         destextension='.mirage'
  53.         destformname='mirage'
  54.         crunched=0
  55.         end
  56.         
  57.     if destformat=4 then do
  58.         destextension='.mirage'
  59.         destformname='mirage'
  60.         crunched=1
  61.         end
  62.     
  63.     ZXAMSaveFormat(destformname)    /* destination format */
  64.     
  65.     ZXAMEnableAbort()        /* enables the 'Abort ARexx' gadget */
  66.     
  67.     /* inside the loop we extract and process the selected files */
  68.     /* we change the extension of the file to the suitable for */
  69.     /* the destination format */
  70.     
  71.     do forever
  72.     name=strip(left(names,pos('"',names,2)),'B','"') /* extract the path&name */
  73.     nameonly=zxamfilepart(name)
  74.     
  75.     if ZXAMReadAbort() then signal cleanup
  76.     
  77.     /* process the file */
  78.     
  79.     zxamnameformat('Loading "'nameonly'"','Wait...')
  80.     
  81.     block=zxampploadfile(name)
  82.     origformat=zxamparseloaded(block)
  83.     
  84.     namenoext=nameonly
  85.     if lastpos('.',namenoext)~=0 then namenoext=left(namenoext,lastpos('.',namenoext)-1)
  86.     /* namenoext is the file name without extension */
  87.     
  88.     if origformat~='' then do
  89.             block=zxamparsetosave()
  90.             if crunched then
  91.                 do
  92.                 zxamnameformat('Compressing "'nameonly'"','Wait...')
  93.                 zxamppsavefile(zxamjoinpathname(destdrawer,namenoext)destextension,block)
  94.                 end
  95.             else 
  96.                 do
  97.                 zxamnameformat('Saving "'nameonly'"','Wait...')
  98.                 /* abrimos el fichero */
  99.                 if ~open('fichero',zxamjoinpathname(destdrawer,namenoext)destextension,'W') then signal cleanup
  100.     
  101.                 /* write the snapshot to the file */
  102.                 dummy=writech('fichero',block)
  103.     
  104.                 dummy=close('fichero')
  105.                 end
  106.         end
  107.     
  108.     if pos('"',names,2)=length(names) then signal cleanup /* end of list */
  109.     names=right(names,length(names)-(length(name)+3))
  110.     
  111.     end
  112.     
  113.     
  114. cleanup:
  115.     if oldname='' then
  116.         zxamclearnameformat()
  117.     else
  118.         zxamnameformat(oldname,oldformat)
  119.  
  120.     zxamsaveformat(oldsaveformat)
  121.  
  122.     /* restore the status */
  123.     if running=1 then zxamrun()
  124.     
  125.     exit
  126.