home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / iconea.zip / ICONEA.CMD < prev    next >
OS/2 REXX Batch file  |  1994-04-19  |  17KB  |  308 lines

  1. /*=======================================================================*/
  2. /* European Personal Systems Centre, Mountbatten House, Basingstoke, UK. */
  3. /*=======================================================================*/
  4. /* SECURITY     ===>  IBM DAPTOOLS Use Only                              */
  5. /* PROGRAM NAME ===>  ICONEA.CMD                                         */
  6. /* VERSION      ===>  1.16                                               */
  7. /* RELEASE      ===>  4                                                  */
  8. /* LANGUAGE     ===>  OS/2 Procedures Language 2/REXX                    */
  9. /* AUTHOR       ===>  Karri Mooney                     (KARRI at WINVMK) */
  10. /* DATE         ===>  14th July 1992                                     */
  11. /* SUPPORT      ===>  Author                                             */
  12. /* PURPOSE      ===>  To attach an icon, bitmap or metafile to a file or */
  13. /*              ===>  files in Extended Attributes.                      */
  14. /*              ===>                                                     */
  15. /* SYNTAX       ===>  ICONEA File_Name Source_File Option                */
  16. /*              ===>                                                     */
  17. /*              ===>  where: File_Name is the target file (wildcards are */
  18. /*              ===>         supported).                                 */
  19. /*              ===>                                                     */
  20. /*              ===>         Source_File is a .ICO, .BMP or .MET file    */
  21. /*              ===>         (only one file can be specified).           */
  22. /*              ===>                                                     */
  23. /*              ===>    and: Option can be either blank or /S for        */
  24. /*              ===>         recursive search through subdirectories.    */
  25. /*              ===>                                                     */
  26. /* COMMENTS     ===>  If you have any comments/suggestions, please append*/
  27. /*                    to ICONEA FORUM on IBMPC or alternatively, send me */
  28. /*                    a VM/PROFS note.                                   */
  29. /* SYSTEM S/W   ===>  Operating System/2 Version 2.00                    */
  30. /*=======================================================================*/
  31. /* CHANGE HISTORY:                                                       */
  32. /*                                                                       */
  33. /* Version Release DD/MM/YY Comments                                     */
  34. /*=======================================================================*/
  35. /*    1.00    1    29/06/92 First Release.                               */
  36. /*    1.05    -    01/07/92 Added support for bitmaps and metafiles.     */
  37. /*    1.07    -    01/07/92 Added support for multiple files (wildcards).*/
  38. /*    1.10    2    01/07/92 Added checking routines that a file is an    */
  39. /*                          icon, bitmap or a metafile.                  */
  40. /*    1.15    3    14/07/92 Added recursive search through all           */
  41. /*                          subdirectories. Thanks to Richard Polisuk for*/
  42. /*                          the suggestion.                              */
  43. /*    1.16    4    14/07/92 Added check for REXXUTIL.DLL.                */
  44. /*=======================================================================*/
  45. /*-----------------------------------------------------------------------*/
  46. /* Check if REXXUTIL.DLL exists before anything. First of all check the  */
  47. /* current drive and if it's not there we'll try the C: drive.           */
  48. /*-----------------------------------------------------------------------*/
  49.   rc = stream("\OS2\DLL\REXXUTIL.DLL",'c','query exists')
  50.   if rc = '' then do
  51.     rc = stream("C:\OS2\DLL\REXXUTIL.DLL",'c','query exists')
  52.     if rc = '' then do
  53.       say
  54.       say 'Cannot find \OS2\DLL\REXXUTIL.DLL and therefore cannot'
  55.       say 'continue...please use the OS/2 Installation diskettes '
  56.       say 'to find REXXUTIL.DLL.'
  57.       say 'Sorry!'
  58.       exit
  59.     end
  60.   end
  61.  
  62. /*-----------------------------------------------------------------------*/
  63. /* Add the RexxUtil function SysPutEA.                                   */
  64. /*                                                                       */
  65. /* Syntax: call SysPutEA File_Name,EA_Name,Full_EA                       */
  66. /*                                                                       */
  67. /* where:            File_Name  -  File name of the target               */
  68. /*                   EA_Name    -  Name of the Extended Attribute        */
  69. /*                   Full_EA    -  Stream of EA data                     */
  70. /*-----------------------------------------------------------------------*/
  71.   call RxFuncAdd SysPutEA,RexxUtil,SysPutEA
  72.  
  73. /*-----------------------------------------------------------------------*/
  74. /* Add the RexxUtil function SysFileTree                                 */
  75. /*                                                                       */
  76. /* Syntax: call SysFileTree Source_File,'Files','FO'                     */
  77. /*         call SysFileTree Source_File,'Files','SO'                     */
  78. /*                                                                       */
  79. /* where:            Source_File -  File name of the target              */
  80. /*                   Files       -  Array for results                    */
  81. /*                   F           -  Indicates search for files only      */
  82. /*                   S           -  Recursive search through directories */
  83. /*                   O           -  Return fully qualified file names    */
  84. /*-----------------------------------------------------------------------*/
  85.   call RxFuncAdd SysFileTree,RexxUtil,SysFileTree
  86.  
  87. /*-----------------------------------------------------------------------*/
  88. /* Parse the command line for the file names and the only option so far. */
  89. /*-----------------------------------------------------------------------*/
  90.   arg File_Name Source_File Option .
  91.  
  92. /*-----------------------------------------------------------------------*/
  93. /* Check that both file names were entered.                              */
  94. /*-----------------------------------------------------------------------*/
  95.   if File_Name = '' | File_Name = '?' | Source_File = '' then do
  96.     call Help
  97.     exit
  98.   end
  99.  
  100. /*-----------------------------------------------------------------------*/
  101. /* Define some constants and variables.                                  */
  102. /*-----------------------------------------------------------------------*/
  103.   FALSE         = 0                /* Boolean False                      */
  104.   TRUE          = 1                /* Boolean True                       */
  105.   Error         = FALSE            /* Error flag                         */
  106.   Icon_Sig      = 15               /* Icon signature position            */
  107.   Bitmap_Sig    ="BM"              /* Bitmap signature                   */
  108.   Metafile_Sig  ='D3A8A8'x         /* Metafile BDT signature             */
  109.   EAT_ICON      ='F9FF'x           /* EA identifier for .ICON            */
  110.   EAT_BITMAP    ='FBFF'x           /* EA identifier for .BITMAP          */
  111.   EAT_METAFILE  ='FAFF'x           /* EA identifier for .METAFILE        */
  112.   Target.       = ''               /* Target file name array             */
  113.   Source.       = ''               /* Source file name array             */
  114.  
  115. /*-----------------------------------------------------------------------*/
  116. /* Get all the target files.                                             */
  117. /*-----------------------------------------------------------------------*/
  118.   if Option = "/S" |,
  119.      Option = "-S" then call SysFileTree File_Name,'Target','SO'
  120.   else                  call SysFileTree File_Name,'Target','FO'
  121.  
  122.   if Target.0 = 0 then do
  123.     say
  124.     say 'Cannot find any files matching 'File_Name'...please try again.'
  125.     exit
  126.   end
  127.  
  128. /*-----------------------------------------------------------------------*/
  129. /* Now find the size of the EA source file. We need this for the EA.     */
  130. /*-----------------------------------------------------------------------*/
  131.   call SysFileTree Source_File,'Source','F'
  132.  
  133.   if Source.0 = 0 then do
  134.     say
  135.     say 'Cannot find a file matching 'Source_File'...please try again.'
  136.     exit
  137.   end
  138.  
  139.   Source_Size = word(Source.1,3)
  140.  
  141. /*-----------------------------------------------------------------------*/
  142. /* And read it in before we go and process the different formats. We need*/
  143. /* to do it here, otherwise the following line will be repeated three    */
  144. /* times (once for each supported format).                               */
  145. /*-----------------------------------------------------------------------*/
  146.   EA_Value = charin(Source_File,1,Source_Size)
  147.  
  148. /*-----------------------------------------------------------------------*/
  149. /* Check which of the three formats it is.                               */
  150. /*-----------------------------------------------------------------------*/
  151.   Extension = substr(Source_File,lastpos('.',Source_File),4)
  152.  
  153.   select
  154.     when Extension = '.ICO' then call Icon_Format
  155.     when Extension = '.BMP' then call Bitmap_Format
  156.     when Extension = '.MET' then call Metafile_Format
  157.     otherwise do
  158.       say
  159.       say 'The EA source file is not an icon, bitmap or a metafile.'
  160.       exit
  161.     end
  162.   end
  163.  
  164. /*-----------------------------------------------------------------------*/
  165. /* If an error has occurred, a message has already been displayed by one */
  166. /* of the three routines.                                                */
  167. /*-----------------------------------------------------------------------*/
  168.   if Error then exit
  169.  
  170. /*-----------------------------------------------------------------------*/
  171. /* Loop for all the target files found.                                  */
  172. /*-----------------------------------------------------------------------*/
  173.   do i = 1 to Target.0
  174.  
  175. /*-----------------------------------------------------------------------*/
  176. /* And attach the icon/bitmap/metafile into EAs.                         */
  177. /*-----------------------------------------------------------------------*/
  178.     call SysPutEA Target.i,EA_Name,Full_EA
  179.  
  180.     if result = 0 then do
  181.       say
  182.       say Source_File' was attached to 'Target.i' successfully.'
  183.     end
  184.     else do
  185.       say
  186.       say  Source_File' could not be attached to 'Target.i' .'
  187.       say 'The return code was 'result'.'
  188.     end
  189.   end
  190.  
  191.   exit
  192. /*=======================================================================*/
  193. /* End of main program logic.                                            */
  194. /*=======================================================================*/
  195.  
  196. /*=======================================================================*/
  197. /* Start of procedures:                                                  */
  198. /*=======================================================================*/
  199. /*=======================================================================*/
  200. /* Icon_Format: Process the .ICON Extended Attribute.                    */
  201. /*=======================================================================*/
  202. Icon_Format:
  203.  
  204. /*-----------------------------------------------------------------------*/
  205. /* Check that the file really is an icon.                                */
  206. /*-----------------------------------------------------------------------*/
  207.   if substr(EA_Value,Icon_Sig,2) <> 'CI' &,
  208.      substr(EA_Value,Icon_Sig,2) <> 'IC' then do
  209.     say
  210.     say Source_File 'is not an icon.'
  211.     Error = TRUE
  212.     return
  213.   end
  214.  
  215. /*-----------------------------------------------------------------------*/
  216. /* Build the EA.                                                         */
  217. /*-----------------------------------------------------------------------*/
  218.   EA_Name    = ".ICON"                        /* Icon EA name            */
  219.   Full_EA    = EAT_ICON         ||,           /* Icon EA identifier      */
  220.                d2c(Source_Size) ||,           /* Length                  */
  221.                EA_Value                       /* Data stream             */
  222.  
  223. return
  224.  
  225. /*=======================================================================*/
  226. /* Bitmap_Format: Process the .BITMAP Extended Attribute.                */
  227. /*=======================================================================*/
  228. Bitmap_Format:
  229.  
  230. /*-----------------------------------------------------------------------*/
  231. /* Check that the file really is a bitmap.                               */
  232. /*-----------------------------------------------------------------------*/
  233.   if substr(EA_Value,1,2) <> Bitmap_Sig then do
  234.     say
  235.     say Source_File 'is not a bitmap.'
  236.     Error = TRUE
  237.     return
  238.   end
  239.  
  240. /*-----------------------------------------------------------------------*/
  241. /* Build the EA.                                                         */
  242. /*-----------------------------------------------------------------------*/
  243.   EA_Name    = ".BITMAP"                      /* Bitmap EA name          */
  244.   Full_EA    = EAT_BITMAP       ||,           /* Bitmap EA identifier    */
  245.                d2c(Source_Size) ||,           /* Length                  */
  246.                EA_Value                       /* Data stream             */
  247.  
  248. return
  249.  
  250. /*=======================================================================*/
  251. /* Metafile_Format: Process the .METAFILE Extended Attribute.            */
  252. /*=======================================================================*/
  253. Metafile_Format:
  254.  
  255. /*-----------------------------------------------------------------------*/
  256. /* Check that the file really is a metafile.                             */
  257. /*-----------------------------------------------------------------------*/
  258.   if substr(EA_Value,3,3) <> Metafile_Sig then do
  259.     say
  260.     say Source_File 'is not a metafile.'
  261.     Error = TRUE
  262.     return
  263.   end
  264.  
  265. /*-----------------------------------------------------------------------*/
  266. /* Build the EA.                                                         */
  267. /*-----------------------------------------------------------------------*/
  268.   EA_Name    = ".METAFILE"                    /* Metafile EA name        */
  269.   Full_EA    = EAT_METAFILE     ||,           /* Metafile EA identifie   */
  270.                d2c(Source_Size) ||,           /* Length                  */
  271.                EA_Value                       /* Data stream             */
  272.  
  273. return
  274.  
  275. /*=======================================================================*/
  276. /* Help: Display little bit of information for the user.                 */
  277. /*=======================================================================*/
  278. Help:
  279.  
  280. say '┌───────────────────────────────────────────────────────────────────┐'
  281. say '│ ICONEA - IBM DAPTOOLS Use Only - 14th July 1992 - by Karri Mooney │'
  282. say '├───────────────────────────────────────────────────────────────────┤'
  283. say '│                                                                   │'
  284. say '│ This REXX Command file attaches an icon, bitmap or metafile to    │'
  285. say '│ a file or files in Extended Attributes.                           │'
  286. say '│                                                                   │'
  287. say '│ Correct syntax: ICONEA File_Name Source_File Option               │'
  288. say '│                                                                   │'
  289. say '│ where: File_Name   = the target file(s) to which the EAs will be  │'
  290. say '│                      attached to. Wildcards are allowed.          │'
  291. say '│        Source_File = a .ICO, .BMP or .MET file.                   │'
  292. say '│                                                                   │'
  293. say '│        Option      = Blank or /S for recursive search through     │'
  294. say '│                      subdirectories.                              │'
  295. say '│                                                                   │'
  296. say '│ Example: ICONEA D:\*.HLP MYHELP.ICO /S                            │'
  297. say '│                                                                   │'
  298. say '│   would: Attach MYHELP.ICO to all the .HLP files on drive D.      │'
  299. say '│                                                                   │'
  300. say '├───────────────────────────────────────────────────────────────────┤'
  301. say '│                         Version 1.16                              │'
  302. say '└───────────────────────────────────────────────────────────────────┘'
  303.  
  304. return
  305. /*=======================================================================*/
  306. /* End of REXX .CMD file.                                                */
  307. /*=======================================================================*/
  308.