/* Script to Play Number to Sound Card */

parse arg caller
if caller='' then exit

path=".\number\"

number=substr(caller,11,7)

/* Load the DLL, initialize MCI REXX support */
call RXFUNCADD 'mciRxInit','MCIAPI','mciRxInit'
rc=mciRxInit()

do while rc \= ""
rc=linein(users.lst,,1)
parse value rc with . c_id . . v_name u_name
if c_id = "ID:"||number & left(v_name,1) <> "-" then
  do
  mcihallo=".\names\"word(rc,5)".wav"
  call play_wav_file
  signal mci_end
  end
end

If pos("XXXXX",Number)>0 Then Do
   Call Play "unknown.wav"
   Return
End
Else do
 call Play "num.wav"
 call Play "none.wav"
 Char=SubStr(Number,1,1)
 If Char="1" Then
   Call Play "100.wav" 
 If Char="2" Then
   Call Play "200.wav" 
 If Char="3" Then
   Call Play "300.wav"
 If Char="4" Then
   Call Play "400.wav"
 If Char="5" Then
   Call Play "500.wav"
 If Char="6" Then
   Call Play "600.wav"
 If Char="7" Then
   Call Play "700.wav"
 If Char="8" Then
   Call Play "800.wav"
 If Char="9" Then
   Call Play "900.wav"
End
Call Play "none.wav"
Do i=0 To 2
  k=2+i*2
  Char=SubStr(Number,k,1)
  If Char="1" Then Do
    Char=SubStr(Number,k+1,1)
    Select
      When Char="1" Then
        Call Play "11.wav"
      When Char="2" Then
        Call Play "12.wav" 
      When Char="3" Then
        Call Play "13.wav" 
      When Char="4" Then
        Call Play "14.wav" 
      When Char="5" Then
        Call Play "15.wav" 
      When Char="6" Then
        Call Play "16.wav" 
      When Char="7" Then
        Call Play "17.wav" 
      When Char="8" Then
        Call Play "18.wav" 
      When Char="9" Then
        Call Play "19.wav" 
      When Char="0" Then
        Call Play "10.wav"
    Otherwise
      Call Play("1.wav")
      Call Play("pop.wav")
    End
   Call Play("none.wav")
  End
  Else Do
    Select
      When Char="2" Then
        Call Play "20.wav" 
      When Char="3" Then
        Call Play "30.wav" 
      When Char="4" Then
        Call Play "40.wav" 
      When Char="5" Then
        Call Play "50.wav" 
      When Char="6" Then
        Call Play "60.wav" 
      When Char="7" Then
        Call Play "70.wav" 
      When Char="8" Then
        Call Play "80.wav" 
      When Char="9" Then
        Call Play "90.wav" 
      When Char="0" Then
        Call Play "null" 
      Otherwise
        Call Play "pop.wav" 
    End
    Call Play "none.wav" 
    If Char="0" Then Do
      Char=SubStr(Number,k+1,1)
      Select
        When Char="1" Then
          Call Play "1.wav" 
        When Char="2" Then
          Call Play "2.wav" 
        When Char="3" Then
          Call Play "3.wav" 
        When Char="4" Then
          Call Play "4.wav" 
        When Char="5" Then
          Call Play "5.wav" 
        When Char="6" Then
          Call Play "6.wav" 
        When Char="7" Then
          Call Play "7.wav" 
        When Char="8" Then
          Call Play "8.wav" 
        When Char="9" Then
          Call Play "9.wav" 
        When Char="0" Then
          Call Play "null" 
        Otherwise
          Call Play "pop.wav" 
      End
      Call Play "none.wav" 
     End
     Else Do
       Char=SubStr(Number,k+1,1)
       If CharToPlay<>"0" Then do
         Select
           When Char="1" Then
             Call Play "1.wav" 
           When Char="2" Then
             Call Play "2.wav" 
           When Char="3" Then
             Call Play "3.wav" 
           When Char="4" Then
             Call Play "4.wav" 
           When Char="5" Then
             Call Play "5.wav" 
           When Char="6" Then
             Call Play "6.wav" 
           When Char="7" Then
             Call Play "7.wav" 
           When Char="8" Then
             Call Play "8.wav" 
           When Char="9" Then
             Call Play "9.wav" 
           When Char="0" Then
             Call Play "null" 
           Otherwise
             Call Play "pop.wav" 
         End
         Call Play "none.wav" 
       End
     End 
  End
End

mci_end:
call stream users.lst,"c","close"
MacRC = mciRxExit()
call RXFUNCDROP "mciRxInit"
exit(0)

/* -------------- Sound Card Ends -------------- */

/* -------------- Play_wave_File --------------- */

Play:procedure expose path
 parse arg mcihallo
 mcihallo=path||mcihallo
 call play_wav_file
return

play_wav_file:procedure expose mcihallo

retst=""
myopen="Open" mcihallo "Alias wave shareable Wait"
myplay="Play wave Wait"


MacRC = mciRxSendString(myopen, "RetSt", "0", "0")

MacRC = mciRxSendString(myplay, "RetSt", "0", "0")

MacRC = mciRxSendString("close wave wait", "RetSt", "0", "0")

return

/* -------------- Play_wave_File Ends ---------- */

