home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / bmptodll.zip / BMPTODLL.CMD
OS/2 REXX Batch file  |  1994-01-17  |  4KB  |  118 lines

  1. /*----------------------------------------------------------------------------*/
  2. /*                                                                            */
  3. /* Create a resource .DLL file                                                */
  4. /*                                                                            */
  5. /* Written by: David C. Morrill                                               */
  6. /*                                                                            */
  7. /* Usage: BMPTODLL dllName [file1 ... filen]                                  */
  8. /* (e.g.: BMPTODLL myBmps my*.BMP your*.BMP                                   */
  9. /*                                                                            */
  10. /* (c) Copyright IBM Corporation 1993                                         */
  11. /*                                                                            */
  12. /*----------------------------------------------------------------------------*/
  13.  
  14. CALL RxFuncAdd "SysLoadFuncs", "RexxUtil", "SysLoadFuncs"
  15. Call SysLoadFuncs
  16.  
  17. /* Parse the arguments: */
  18. PARSE ARG dllName file rest
  19. IF (dllName = "") | (dllName = "?") THEN SIGNAL usage
  20. IF pos( ".", dllName ) = 0 THEN dllName = dllName".DLL"
  21. IF file = "" THEN file = "*.BMP"
  22.  
  23. /* Create a temporary .RC file: */
  24. rcFile = SysTempFileName( ".\BMP?????.RC" );
  25.  
  26. /* Expand each 'file' into matching file names and add them to the .RC file: */
  27. i = 0;
  28. DO WHILE file \= ""
  29.    IF (SysFileTree( file, "files", "FO" ) \= 0) | (files.0 = 0) THEN DO
  30.       SAY "Could not find:" file
  31.       EXIT 100
  32.      END
  33.    DO j = 1 TO files.0
  34.       i = i + 1
  35.       ext = translate( substr( file, pos( ".", files.j ) + 1 ) )
  36.            IF ext = "ICO" THEN type = "ICON"
  37.       ELSE IF ext = "PTR" THEN type = "POINTER"
  38.       ELSE                     type = "BITMAP"
  39.       IF LineOut( rcFile, type i files.j ) \= 0 THEN DO
  40.          SAY ""
  41.          SAY "Error occurred creating temporary file"
  42.          CALL LineOut rcFile
  43.          "@DEL" rcFile "1>NUL 2>NUL"
  44.          EXIT 100
  45.         END
  46.       CALL CharOut , "."
  47.    END
  48.    PARSE VAR rest file rest
  49. END
  50. SAY ""
  51.  
  52. /* Close the .RC file: */
  53. CALL LineOut rcFile
  54.  
  55. /* Get the root portion of the DLL file name: */
  56. root = translate( dllName )
  57. col  = pos( ":", root )
  58. IF col \= 0 THEN root = substr( root, col + 1 )
  59. DO FOREVER
  60.    col = pos( "\", root )
  61.    IF col = 0 THEN LEAVE
  62.    root = substr( root, col + 1 )
  63. END
  64. col = pos( ".", root )
  65. IF col \= 0 THEN root = left( root, col - 1 )
  66. IF length( root ) > 8 THEN root = left( root, 6 )
  67.  
  68. /* Try to find the 'dummy' DLL: */
  69. dllSource = SysSearchPath( "PATH", "BMPTODLL.DAT" )
  70. IF dllSource = "" THEN dllSource = SysSearchPath( "DPATH", "BMPTODLL.DAT" )
  71. IF dllSource = "" THEN DO
  72.    SAY "Could not find BMPTODLL.DAT"
  73.    "@DEL" rcFile "1>NUL 2>NUL"
  74.    EXIT 100
  75.   END
  76.  
  77. /* Copy the dummy DLL to the desired DLL and change its internal name: */
  78. dll = CharIn( dllSource, 1, Chars( dllSource ) )
  79. dll = left( dll, 388 ) || d2c( length( root ), 1 ) || root || copies( '00'x, 8 - length( root ) ) || substr( dll, 398 )
  80. "@DEL" dllName "1>NUL 2>NUL"
  81. IF CharOut( dllName, dll ) \= 0 THEN DO
  82.    SAY "Error creating" dllName
  83.    "@DEL" rcFile "1>NUL 2>NUL"
  84.    EXIT 100
  85.   END
  86. CALL CharOut dllName
  87.  
  88. /* Compile the resources and add them to the DLL: */
  89. "@RC" rcFile dllName "1>NUL 2>NUL"
  90. ok = rc
  91. "@DEL" rcFile "1>NUL 2>NUL"
  92. col = pos( ".", rcFile, 2 )
  93. IF col \= 0 THEN rcFile = left( rcFile, col - 1 )
  94. "@DEL" rcFile".RES 1>NUL 2>NUL"
  95. IF ok \= 0 THEN DO
  96.    SAY "Could not create" dllName
  97.    "@DEL" dllName "1>NUL 2>NUL"
  98.    EXIT 100
  99.   END
  100.  
  101. /* Indicate the operation was a success: */
  102. SAY
  103. SAY "Successfully created" dllName
  104. EXIT
  105.  
  106. /* Show usage: */
  107. usage:
  108.    SAY "Usage: BMPTODLL  dllName[.DLL]  [file1 ... filen]"
  109.    SAY "where: dllName      = name of .DLL to create"
  110.    SAY "       file1..filen = names of .BMP/.ICO/.PTR files to include"
  111.    SAY "                      (may contain wildcards: ? or *)"
  112.    SAY "                      (defaults to *.BMP)"
  113.    SAY "For example: BMPTODLL myBmps my*.BMP your*.BMP"
  114.    SAY ""
  115.    SAY "Notes: BMPTODLL.DAT must be in PATH or DPATH"
  116.    SAY "       RC (Resource Compiler) must be in PATH"
  117.    EXIT 100
  118.