home *** CD-ROM | disk | FTP | other *** search
/ Da Capo / da_capo_vol1.bin / programs / amiga / edit / sidconverter / convertmus.rexx < prev    next >
OS/2 REXX Batch file  |  1994-09-03  |  5KB  |  174 lines

  1. /*************************************************************************/
  2. /*       Compute!'s .MUS file conversion script V1.0b for SIDPLAYER      */
  3. /*                Written by David Poland on 9/1/94                      */
  4. /*************************************************************************/
  5.  
  6. /* Please note that this script requires "rexxsupport.library" in the
  7.    libs directory */
  8.  
  9. /* Change the prompt for input from shell */
  10.  
  11. options prompt '> '
  12.  
  13. /* If the library is not already loaded into memory then do so.  Then we
  14.    check to see if the library is available.  If it is, load it up, if not
  15.    report the error. */
  16.  
  17. if ~show('L', "rexxsupport.library") then do
  18.     if addlib('rexxsupport.library',0,-30,0) then
  19.         say "Added rexxsupport.library"
  20.     else do
  21.         say "ERROR! Rexxsupport.library is required for this script."
  22.         exit 10
  23.     end
  24. end
  25.  
  26.  
  27. /* Announce who we are :-) */
  28.  
  29. say ""
  30. say "* ConvertMUS arexx script V1.0b *"
  31.  
  32. /* Get the current directory we are in */
  33.  
  34. CurrentPath = pragma('D')
  35.  
  36. /* Now get the destination directory where we will send the converted
  37.    files to */
  38.  
  39. GetDestDir(DestDir,CurrentPath)
  40.  
  41. /* Assign the filenames (excluding subdirs etc) to a variable */
  42.  
  43. FileList = showdir(CurrentPath, 'f', ':')
  44.  
  45. /*************************************************************************/
  46. /* Now process all the filenames in the FileList                         */
  47. /*************************************************************************/
  48.  
  49. ExitLoop = 0     /* Init our Boolean flag to FALSE */
  50. FileNumber = 0   /* Number of files converted */
  51.  
  52. /* While ExitLoop is not equal to TRUE, keep looping */
  53.  
  54.  
  55. say ""
  56. say "File conversion in process..."
  57.  
  58. do while ExitLoop ~= 1
  59.  
  60.     /* Each filename is separated by a colon as specified by the pragma
  61.        command earlier.  Find the position of the first colon */
  62.  
  63.     Position = index(FileList, ":")
  64.  
  65.     /* Now if no colon was found, we are done and exit the loop.
  66.        If a colon was found, we need to extract the filename from
  67.        the list and assign it to "FileName".  Then we'll need to remove
  68.        the filename from the list so we use DelStr to remove it. */
  69.     
  70.     if Position > 0 then do
  71.         FileName = Left(FileList,Position-1)
  72.         ConvertFile(pad)
  73.         FileList = delstr(FileList,1,Position)
  74.     end 
  75.     else do
  76.         /* Here we need to check and see if only ONE filename is in the
  77.            FileList and to process it if this is so. */
  78.  
  79.         if length(FileList) ~= 0 then do
  80.             FileLength = Length(FileList)
  81.             FileName = Left(FileList,FileLength)
  82.             ConvertFile(pad)   
  83.             FileList = ""
  84.         end
  85.         else 
  86.             ExitLoop = 1
  87.     end
  88.  
  89. end /*DO*/
  90.  
  91. say ""
  92. say "File conversion completed!  " || FileNumber || " files converted."
  93. say ""
  94.  
  95. exit
  96.  
  97. /*************************************************************************/
  98. /* Procedure to handle the actual file conversion                        */
  99. /*************************************************************************/
  100.  
  101. ConvertFile:
  102.  
  103.     arg pad /* Can't call a function without an arg so we provide a dummy */
  104.  
  105.     InfoString = ".mus"
  106.    
  107.     /* Check to see if we have a Compute! .MUS file */
  108.  
  109.     InfoFlag = pos(upper(InfoString),upper(FileName))
  110.    
  111.     /* For the .MUS file we need to make an icon for it indicating that
  112.        it is a .MUS SID file, then we need to run the conversion program
  113.        over it to turn it into one file. */
  114.  
  115.     if InfoFlag ~= 0 then do
  116.         NewFileName = left(FileName,length(FileName)-4) /*Strip .mus off*/
  117.         NewFileName = space(NewFileName,0) /* Strip out spaces */
  118.  
  119.         address command "sid:MakeSIDIcon " || """" || FileName || """" ||,
  120.                         " SID"
  121.  
  122.         address command "sid:sidconv " || """" || FileName || """" || " " ||,
  123.                         DestDir || "/" || NewFileName
  124.  
  125.         FileNumber = FileNumber + 1
  126.     end
  127.   
  128. return 0
  129.  
  130. /*************************************************************************/
  131. /* Procedure to handle destination directory                             */
  132. /*************************************************************************/
  133.  
  134. GetDestDir:
  135.  
  136.     arg DestDir, CurrentPath
  137.  
  138.     say ""
  139.     say "Please enter the path for the destination of the converted files."
  140.     say "NOTE!!! Do not select the current directory as the destination or"
  141.     say "your original files will be overwritten!!!"
  142.     say ""
  143.     say "Current directory path is: " || CurrentPath
  144.     say ""
  145.  
  146.     pull DestDir
  147.  
  148.     /* Strip off a "/" on the end if the user added one. */
  149.  
  150.     if pos("/",DestDir,length(DestDir)) ~= 0 then
  151.         DestDir = left(DestDir,Length(DestDir)-1)
  152.  
  153.     /* Check to see if the selected destination directory exists, if
  154.        it does, then continue on, if not ask if they want to create it */
  155.  
  156.     if ~exists(DestDir) then do
  157.         say ""
  158.         say "The selected destination directory does not exist.  Shall I"
  159.         say "create it for you? (Y/N)"
  160.         pull Answer
  161.  
  162.         if Answer = "Y" then do
  163.             address command "makedir " || DestDir
  164.             say "Directory " || DestDir || " has been created."
  165.         end
  166.         else do
  167.             say "Directory not created - script aborted."
  168.             exit
  169.         end
  170.  
  171.     end
  172.          
  173. return DestDir
  174.