home *** CD-ROM | disk | FTP | other *** search
/ Network CD 2 / Network CD - Volume 2.iso / twinopus / dopus / typefile.rexx < prev   
Encoding:
OS/2 REXX Batch file  |  1995-07-13  |  7.1 KB  |  258 lines

  1. /*
  2.  *
  3.  * Types a file Specified by the User....
  4.  *
  5.  * (c) 1994 by K.P. van Beem (2:280/464.2, patrick.van.beem@aobh.xs4all.nl)
  6.  *
  7.  * Written by Ray Abram to Supplement the DOpus Twin Package
  8.  *   - file is temporally stored to T:
  9.  *     - Thus ensure that there is enough free RAM to hold the data
  10.  *
  11.  *   - Program also attempts to recognize the following file types...
  12.  *   -    *.guide    - an Amiga Guide File  - Run AMIGAGUIDE
  13.  *   -    *.anim     - an Animation File    - Run VT   (ViewTek)
  14.  *   -    *.IFF      - an IFF picture       - Run VT   (ViewTek)
  15.  *   -    *.GIF      - a  GIF picture       - Run VT   (ViewTek)
  16.  *   -    *.jpg      - a  Jpegged Picture   - Run VT   (ViewTek)
  17.  *   -    *.info     - an Icon File         - Run DOPus's internal IconInfo
  18.  *   -    *.8svx     - a Sample File        - Run DOPus's internal Play
  19.  *   -    MOD.*      - a MOD file           - Run DOPus's internal PlayST
  20.  *   -    *.MOD      - a MOD file           - Run DOPus's internal PlayST
  21.  *      -> note: when Twin is Running, Modules play a bit ODD !!
  22.  *   -    NOT KNOWN  - any other file       - Run DOPus's internal ANSIREADer
  23.  *
  24.  *    - if you double click on a Cache Dir file, then the file is loaded into
  25.  *      the active window...
  26.  */
  27.  
  28. DOpusPort   = 'DOPUS.1'
  29.  
  30. if ~show(l,"rexxsupport.library") then
  31.     call addlib("rexxsupport.library",0,-30,0)
  32. if showlist('Ports', DOpusPort) = 0 then do
  33.    say 'Directory Opus Arexx port not found. Aborting.'
  34.    call CleanUp
  35. end
  36.  
  37. address 'DOPUS.1'
  38. options results
  39.  
  40. /*get the filename sent to me */
  41. parse arg FilePath
  42. if FilePath="" then do
  43.    TopText "You have to specify a File. !!"
  44.    exit
  45. end
  46.  
  47. if words(File) > 1 then do
  48.    Request "Spaces in a Filename are not Allowed !!"
  49. end
  50.  
  51. /* see if the requested file is a cache dir  (scan for ';'*/
  52. Filename = CutOutFilename(FilePath)
  53. FName    = Filename
  54.  
  55. Found = False
  56. pos =  length(Filename)
  57. do while pos > 0
  58.    if substr(Filename,pos,1) = '=' then
  59.       Found = True
  60.    pos = pos - 1
  61. end
  62.  
  63. if Found = True then do
  64.    Request "Do you want to Load Cache Dir :-" Filename
  65.    if result = 0 then
  66.       call CleanUp
  67.    else do
  68.       Filename = ConvertFrom(Filename)
  69.       ClearWin
  70.       address AREXX "rexx:dopus/ReadDir.rexx" Filename
  71.       call EndBit
  72.    end
  73. end
  74.  
  75. /* ensure user wants to do this */
  76. Request "Do you want to Process :-" Filename
  77. if result = 0 then
  78.    call CleanUp
  79.  
  80. else do
  81.    Busy on
  82.  
  83.    ToDir = 'T:' || FName
  84.  
  85.    /* setup DOpus window and tell user what's happening */
  86.    TopText "Reading in" FilePath "..."
  87.  
  88.    /*tell TWIN to copy the File...  and then put something into the Queue:*/
  89. Trace ?r
  90.  
  91.    Path = CutOutPath(FilePath)
  92.    SD   = EnterDir(Path)
  93.    address command 'echo >PPipe: copy' SD || FName ToDir
  94.    address command 'echo >PPipe: help'
  95.  
  96.    if open(PipeList, "QUEUE:Twin", 'R') then do
  97.       call WaitForAFile
  98.       close(PipeList)
  99.    end
  100.  
  101.    /* get the last file type */
  102.    FileEnd  =upper(right(FilePath,3))
  103.    FileStart=upper(left(Filename ,3))
  104.  
  105. /********************************************************************
  106.  *  do the recognition ...                                          *
  107.  *     - add more "when"'s if you want before the "otherwise"...    *
  108.  ********************************************************************/
  109.  
  110.    select
  111.       when FileStart = "MOD" then
  112.         PLAYST ToDir
  113.       otherwise
  114.          select
  115.             when FileEnd = "IDE" then do
  116.                DopusToBack
  117.                address command 'AMIGAGUIDE ' ToDir
  118.                DopusToFront
  119.             end
  120.             when FileEnd = "IFF" then
  121.               address command 'VT ' ToDir
  122.             when FileEnd = "NIM" then
  123.               address command 'VT ' ToDir
  124.             when FileEnd = "GIF" then
  125.               address command 'VT ' ToDir
  126.             when FileEnd = "JPG" then
  127.               address command 'VT ' ToDir
  128.             when FileEnd = "ZVX" then
  129.               PLAY ToDir
  130.             when FileEnd = "MOD" then
  131.               PLAYST ToDir
  132.             when FileEnd = "NFO" then
  133.               ICONINFO ToDir
  134.             otherwise ANSIREAD ToDir
  135.          end
  136.       end
  137.  
  138.    /* and now delete the temp file */
  139.    address command 'echo >PPipe: delete ' ToDir
  140.    address command 'echo >PPipe: help'
  141.    if open(PipeList, "QUEUE:Twin", 'R') then do
  142.       test = ''
  143.       /* deleted is for a deleted file */
  144.       do while (test ~= "deleted")
  145.         junk = readln(PipeList)
  146.         test = right(junk , 7, '')
  147.       end
  148.       close(PipeList)
  149.    end
  150.  
  151. end
  152.  
  153.  
  154. /* that's all folks !! */
  155. TopText "Ready"
  156.  
  157. /*---------------------------------------------------------------------------*/
  158.  
  159. CleanUp: /* Remove any files and exit */
  160.    Busy off
  161.    exit
  162. return
  163. /*--------------------------------------------------------------------------*/
  164.  
  165. Quote: procedure /* add quotes to string */
  166.    parse arg string
  167. return '"'||string||'"'
  168. /*---------------------------------------------------------------------------*/
  169.  
  170. CutOutFilename: procedure
  171.    parse arg string
  172.    bit = ''
  173.    pos = length(string)
  174.    count = 0
  175.    do while((bit ~= ":") & (bit ~= "/"))
  176.      bit = substr(string, pos, 1)
  177.      pos = pos - 1
  178.      count = count + 1
  179.    end
  180.  
  181. return right(string, count-1)
  182.  
  183. CutOutPath: procedure
  184.    parse arg string
  185.    bit = ''
  186.    pos = length(string)
  187.    count = 0
  188.    do while((bit ~= ":") & (bit ~= "/"))
  189.      bit = substr(string, pos, 1)
  190.      pos = pos - 1
  191.      count = count + 1
  192.    end
  193.  
  194. return left(string, length(string) - count + 1)
  195. /*---------------------------------------------------------------------------*/
  196.  
  197. WaitForAFile:
  198.    test = ''
  199.    /* received is for a normal copy,   sent is for a copy as */
  200.    do while ((test ~= "received") & (test ~= "   sent ") & (test ~= " copied ") & (test ~= "Error: D") & (test ~= "TWIN> Er"))
  201.      junk = readln(PipeList)
  202.      test = left(junk , 8, '')
  203.    end
  204.  
  205.    /* now see if the file stopped due to an error */
  206.    if ((test = "Error: De") | (test = "TWIN> Er")) then do
  207.       request "An Error occured during the Copying... (Disk Full ?)"
  208.       close(PipeList)
  209.       call EndBit
  210.    end
  211.  
  212. return
  213.  
  214. /*--------------------------------------------------------------------------*/
  215. /* convert a file name from df0=ray\was\here  ->  df0:ray/was/here (un-cached filename)*/
  216. ConvertFrom: procedure
  217.  
  218.    parse arg Dev '=' Path
  219.  
  220.    do until (t2 = '')
  221.        parse var Path t1 '\' t2
  222.        Path = t1 || '/' || t2
  223.    end
  224.  
  225.    if left(dev,1) = '`' then
  226.       dev = '~' || right(dev,length(dev)-1)
  227.  
  228. return Dev || ':' || left(Path,length(Path)-1)
  229.  
  230. /*--------------------------------------------------------------------------*/
  231.  
  232. /* Cd into the sent Directory path
  233.    - this is needed, as TWIN has a command parameter limit of 30 characters,
  234.       and as we all know AmigaDos file & paths can easily go over this limit !!*/
  235.  
  236. EnterDir: procedure
  237.  
  238.    parse arg Dev ':' Path
  239.  
  240.    /* get the 1st character to address the local or remote machine correctly */
  241.    if left(Dev,1) = '~' then
  242.       sbit = '~'
  243.      else
  244.       sbit = ''
  245.  
  246.    /* does the passed name have a DEVICE in it ? */
  247.    if Dev ~= '' then
  248.       address command 'echo >PPipe: cd' Dev || ':'
  249.  
  250.    do until (t2 = '')
  251.       parse var Path t1 '/' t2
  252.       path = t2
  253.       if t1 ~= '' then
  254.          address command 'echo >PPipe: cd' sbit || t1
  255.    end
  256.  
  257. return sbit
  258.