home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Multimed / Multimed.zip / vclck02.zip / PLAY.CMD < prev    next >
OS/2 REXX Batch file  |  1996-02-29  |  9KB  |  321 lines

  1. /*-----------------------------------------------------------------------------
  2.  
  3.   Name:                   play.cmd
  4.   Date Created:    12/27/92
  5.                 Copyright (c) IBM Corporation  1992, 1993
  6.                           All Rights Reserved
  7.  
  8.  
  9.   OS/2 REXX command file that uses MultiMedia REXX functions
  10.   to play a file.
  11.  
  12.  -----------------------------------------------------------------------------*/
  13.  
  14. address cmd      /* Send commands to OS/2 command processor.  */
  15. signal on error   /* When commands fail, call "error" routine. */
  16. signal on halt    /* When user does a ctrl break               */
  17.  
  18. trace off
  19. /*trace ?r*/
  20.  
  21. /* initialize variables */
  22. FILE=''
  23. FROM=''
  24. TO=''
  25. DEV=''
  26. TIMEFMT=''
  27.  
  28. /* Setup keyword string array */
  29. kwd.0 = 5
  30. kwd.1 = 'FILE'
  31. kwd.2 = 'DEV'
  32. kwd.3 = 'TO'
  33. kwd.4 = 'FROM'
  34. kwd.5 = 'TIMEFMT'
  35.  
  36. /* Clear out argx variables */
  37. do i = 1 to 5
  38.   junk = value('arg'i,'')
  39. end
  40.  
  41. arg inline                      /* Get the command line parms */
  42. if (inline='' | inline='?') then
  43.    do
  44.      call Help
  45.      exit 0
  46.    end
  47.  
  48. /*
  49.  * Check for each keyword
  50.  * If "FILE" is found, look for quotes which signify possible embedded
  51.  *   blanks.
  52.  * Set argx (x is 1 to 5) to the entire keyword string, which ends in
  53.  *   either a blank or a quote.
  54.  */
  55. do i = 1 to kwd.0
  56.  
  57.   kwdpos = pos(kwd.i, inline)   /* Position of matching keyword */
  58.   if kwdpos > 0  then           /* Found a keyword */
  59.   do
  60.  
  61.     if kwd.i = 'FILE' then      /* Check for quote after FILE= */
  62.     do
  63.       endchar = substr(inline, kwdpos+length(kwd.i)+1,1)
  64.       if endchar <> '"' then endchar = ' '
  65.     end
  66.  
  67.     else  endchar = ' '         /* Not FILE=, use blank as delimiter */
  68.  
  69.     /*  Find delimiter (either next quote or blank) */
  70.     fnend = pos(endchar, inline, kwdpos+length(kwd.i)+2)
  71.     if fnend = 0 then           /* Ending quote/blank not found */
  72.     do
  73.       if endchar = '"' then
  74.         say 'Missing ending quote mark for' kwd.i 'keyword'
  75.       fnend = length(inline)    /* Assume it's just end of line */
  76.     end
  77.  
  78.     /* Set argx to the keyword=data */
  79.     junk = value('arg'i, substr(inline, kwdpos, fnend-kwdpos+1))
  80.  
  81.   end                           /* End if a keyword was found */
  82.  
  83. end                             /* End do i = 1 to num of keywords */
  84.  
  85. /* display values of the argx variables */
  86. /* do i = 1 to 5
  87.     say 'arg'i 'is' value('arg'i)
  88.    end        */
  89.  
  90. parse var arg1 arg1a'='arg1b
  91. parse var arg2 arg2a'='arg2b
  92. parse var arg3 arg3a'='arg3b
  93. parse var arg4 arg4a'='arg4b
  94. parse var arg5 arg5a'='arg5b
  95.  
  96.  
  97. /* Set the variables. */
  98. call keyword arg1a, arg1b
  99. call keyword arg2a, arg2b
  100. call keyword arg3a, arg3b
  101. call keyword arg4a, arg4b
  102. call keyword arg5a, arg5b
  103.  
  104.  
  105.  
  106. /* Load the DLL, initialize MCI REXX support */
  107. rc = RXFUNCADD('mciRxInit','MCIAPI','mciRxInit')
  108. InitRC = mciRxInit()
  109. MciCmd = 'open'
  110.  
  111. /*
  112. ** Check to see if the FILE && DEV variables are valid.
  113. */
  114.      if FILE<>'' then
  115.         do
  116.           if DEV<>'' then
  117.              MciCmd = MciCmd FILE 'type' DEV
  118.           else
  119.              MciCmd = MciCmd FILE
  120.         end
  121.      else if DEV<>'' then
  122.         MciCmd = MciCmd DEV
  123.      else
  124.            do
  125.              call Help
  126.              exit 0
  127.            end
  128.  
  129. /*
  130. ** Append the rest of the command line.
  131. */
  132.     MciCmd = MciCmd 'alias rexxalias wait'
  133.  
  134. /*
  135. ** Issue the open command.
  136. */
  137.     MacRC = SendString(MciCmd)
  138.      if MacRC <> 0 then signal ErrExit
  139.      else
  140.      do
  141.        if DEV='' then    /* device not specified */
  142.          do     /* determine the device type */
  143.           MacRC = SendString("capability rexxalias device type wait")
  144.           if MacRC <> 0 then
  145.               do
  146.                  junk = SendString("close rexxalias wait")
  147.                  signal ErrExit
  148.               end
  149.          end
  150.        else   /* set the device specified as the device type */
  151.          RetSt = DEV
  152.  
  153.        /* If a wave file is to be played then do a status length */
  154.        /* to determine if the wave file exists.  A wave file is  */
  155.        /* the only type of device that if it doesn't exist and   */
  156.        /* you play it, it won't come back as file not found      */
  157.        if TRANSLATE(RetSt) = 'WAVEAUDIO' then
  158.          do
  159.             MacRC = SendString("status rexxalias length wait")      /* If length is 0 no file exists */
  160.              if MacRC <> 0 then
  161.               do
  162.                  junk = SendString("close rexxalias wait")
  163.                  signal ErrExit
  164.               end
  165.              if RetSt = 0 then
  166.               do
  167.                  junk = SendString("close rexxalias wait")
  168.                  ErrRC = 70555
  169.                  MacRC = mciRxGetErrorString(ErrRC, 'ErrStVar')
  170.                  say 'mciRxGetErrorString('ErrRC') =' ErrStVar
  171.                  signal ErrExit
  172.               end
  173.          end
  174.      end
  175.  
  176. /*
  177. ** Exercise mciRxGetDeviceID function
  178. */
  179. DeviceID = mciRxGetDeviceID(""rexxalias"")
  180.  
  181. /*
  182. **  Check to see if a time format was given.
  183. */
  184. if TIMEFMT <> '' then
  185. do
  186.     MciCmd = 'set rexxalias time format' TIMEFMT 'wait'
  187.     MacRC = SendString(MciCmd)
  188.      if MacRC <> 0 then
  189.         do
  190.          junk = SendString("close rexxalias wait")
  191.          signal ErrExit
  192.         end
  193. end
  194.  
  195. /*
  196. ** Formulate the play command.
  197. */
  198. MciCmd = 'play rexxalias'
  199.  
  200. /*
  201. ** check to see if an origin was set.
  202. */
  203.  if FROM<>'' then
  204.         MciCmd = MciCmd 'from' FROM
  205.  
  206. /*
  207. ** check to see if a terminating point was given.
  208. */
  209.  if TO<>'' then
  210.         MciCmd = MciCmd 'to' TO
  211.  
  212. /*
  213. ** append a wait onto the end of the play string.
  214. */
  215. MciCmd = MciCmd 'wait'
  216.  
  217. /*
  218. ** actually send the play string.
  219. */
  220. MacRC = SendString(MciCmd)
  221.      if MacRC <> 0 then
  222.         do
  223.          junk = SendString("close rexxalias wait")
  224.          signal ErrExit
  225.         end
  226.  
  227. /*
  228. ** close the instance.
  229. */
  230. MacRC = SendString("close rexxalias wait")
  231. if MacRC <> 0 then signal ErrExit
  232.  
  233. /*
  234. ** Exit, return code = 0.
  235. */
  236. exit 0
  237.  
  238. /*   --- SendString --
  239. ** Call DLL function.  Pass the command to process and the
  240. ** name of a REXX variable that will receive textual return
  241. ** information.
  242. */
  243. SendString:
  244.    arg CmndTxt
  245.    /* Last two parameters are reserved, must be set to 0           */
  246.    /* Future use of last two parms are for notify window handle    */
  247.    /* and userparm.                                                 */
  248.    MacRC = mciRxSendString(CmndTxt, 'RetSt', '0', '0')
  249.    if MacRC<>0 then
  250.       do
  251.       ErrRC = MacRC
  252.       say 'MciCmd=' CmndTxt
  253.       say 'Err:mciRxSendString RC=' ErrRC RetSt
  254.       MacRC = mciRxGetErrorString(ErrRC, 'ErrStVar')
  255.       say 'mciRxGetErrorString('ErrRC') =' ErrStVar
  256.       MacRC = ErrRC /* return the error rc */
  257.       end
  258.    return MacRC
  259.  
  260. /* -- keywords --
  261. **
  262. ** Parse the arguments according to the keywords.
  263. */
  264. keyword:
  265.         arg key, value
  266.         if key='FILE' then
  267.             FILE=value
  268.         else if key='DEV' then
  269.             DEV=value
  270.         else if key='FROM' then
  271.              FROM=value
  272.         else if key='TO' then
  273.               TO=value
  274.         else if key='TIMEFMT' then
  275.                 TIMEFMT=value
  276.  
  277. return
  278.  
  279. /*  -- help --
  280. ** Display help text
  281. */
  282. Help:
  283.    say
  284.    say 'This command file plays a file or device using the MultiMedia'
  285.    say 'REXX string interface.'
  286.    say
  287.    say 'play [FILE="filename"] [DEV=device] [TIMEFMT=timefmt]'
  288.    say '         [FROM=from_position] [TO=to_position]'
  289. return
  290.  
  291. /*  --- ErrExit --
  292. ** Common routine for error clean up/program exit.
  293. ** Gets called when commands to DLL fail.
  294. */
  295. ErrExit:
  296.    MacRC = mciRxExit()   /* Tell the DLL we're going away        */
  297.    exit 1;               /* exit, tell caller things went poorly */
  298.  
  299.  
  300. /*   ---- error --
  301. ** Routine gets control when any command to the external
  302. ** environment (usually OS/2) returns a non-zero RC.
  303. ** This routine does not get called when the macapi.dll
  304. ** returns non-zero as it is a function provider rather
  305. ** than a command environment.
  306. */
  307. error:
  308.    ErrRC = rc
  309.    say 'Error' ErrRC 'at line' sigl ', sourceline:' sourceline(sigl)
  310.    MacRC = mciRxExit()       /* Tell the DLL we're going away */
  311.    exit ErrRC                /* exit, tell caller things went poorly */
  312.  
  313. /*   ---- halt --
  314. ** Routine gets control when user hits ctrl break to end
  315. */
  316. halt:
  317.    say 'Halting...'
  318.    MacRC = SendString("close rexxalias wait")
  319.    if MacRC <> 0 then signal ErrExit
  320.    exit 0
  321.