Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for bin2rexx.rex

(view source code of bin2rexx.rex as plain text)

  1. /*
  2.  浜様様様様様様様様様様様様様様様様様様様様様様様様様様様様様様様様様様様様様
  3.    Bin2Rexx                                        last update: 31/12/2002  
  4.    (C) 1997-2002, Rob van der Woude                                         
  5.    http://www.robvanderwoude.com                                            
  6.    Convert small binaries to Rexx programs that will recreate those same    
  7.    binaries when executed.                                                  
  8.    Originally written to allow creation of icon files from installation     
  9.    scripts.                                                                 
  10.  藩様様様様様様様様様様様様様様様様様様様様様様様様様様様様様様様様様様様様様
  11. */
  12.  
  13. /* Initialize RexxUtil */
  14. Call RxFuncAdd "sysloadfuncs", "RexxUtil", "sysloadfuncs"
  15. Call sysloadfuncs
  16.  
  17. /* Get OS and location of this script */
  18. Parse Source os type program
  19. If os = "OS/2" Then rexxext = "cmd"; Else rexxext = "rex"
  20.  
  21. /* Check command line parameters */
  22. Parse arg binfile outfile dummy
  23. If binfile = "" Then Call Syntax
  24. If dummy  <> "" Then Call Syntax
  25. If outfile = "" Then outfile = binfile
  26.  
  27. /* Define output file name */
  28. rexxfile = Strip( Directory( ), "T", "\" )||"\bin."||rexxext
  29.  
  30. /* Check if source and target files exist and take appropriate actions */
  31. If Argchk( binfile )  = 0 Then Call Syntax
  32. If Argchk( rexxfile ) = 1 Then Call Blocked rexxfile
  33.  
  34. Call SysFileTree binfile, "found.", "F"
  35. If found.0 <> 1 Then Do
  36. 	Call Syntax
  37. 	Exit
  38. End
  39. Parse Value found.1 With fdate ftime fsize fattr fname
  40.  
  41. Call LineOut rexxfile, '/* Recreate '||Filespec( "N", binfile )||' */'
  42. Call LineOut rexxfile, '/* This file was created on '||date( "E" )||' '||time( "N" )||' */'
  43. Call LineOut rexxfile, '/* by Bin2Rexx, (C) 1997-2002, Rob van der Woude */'
  44. Call LineOut rexxfile, '/* http://www.robvanderwoude.com                 */'
  45. Call LineOut rexxfile, ''
  46. Call LineOut rexxfile, '/* Load RexxUtil */'
  47. Call LineOut rexxfile, 'Call RxFuncAdd "sysloadfuncs", "RexxUtil", "sysloadfuncs"'
  48. Call LineOut rexxfile, 'Call sysloadfuncs'
  49. Call LineOut rexxfile, ''
  50. Call LineOut rexxfile, 'tempfile = "'||outfile||'"'
  51. Call LineOut rexxfile, 'Call SysFileTree tempfile, "exist.", "F"'
  52. Call LineOut rexxfile, 'If exist.0 > 0 Then Do'
  53. Call LineOut rexxfile, '    Call Beep 220, 250'
  54. Call LineOut rexxfile, '    Say ""'
  55. Call LineOut rexxfile, '    Say " File "||Filespec( "N", tempfile )||" already exists"'
  56. Call LineOut rexxfile, '    Say ""'
  57. Call LineOut rexxfile, '    Exit'
  58. Call LineOut rexxfile, 'End'
  59. Call LineOut rexxfile, ''
  60.  
  61. binstr = CharIn( binfile, 1, Min( 26, fsize ) )
  62. Call LineOut rexxfile, 'Call CharOut tempfile, "'||C2X( binstr )||'"X'
  63.  
  64. i = 1
  65. Do Until Chars( binfile ) = 0
  66. 	binstr = CharIn( binfile, ( 26 * i ) + 1, Min( 26, fsize - ( i * 26 ) ) )
  67. 	Call LineOut rexxfile, 'Call CharOut tempfile, "'||C2X( binstr )||'"X'
  68. 	i = i + 1
  69. End
  70. Call LineOut rexxfile, 'Call LineOut tempfile'
  71. Call LineOut rexxfile
  72. Exit
  73.  
  74.  
  75. /* Check if specified file exists */
  76. Argchk: Procedure
  77. 	If Strip( Arg( 1 ) ) = "" Then Call Syntax
  78. 	Call SysFileTree Strip( Arg( 1 ) ), "exist.", "F", , "**---"
  79. 	If exist.0 = 1 Then Do
  80. 		chk = 1
  81. 	End
  82. 	Else Do
  83. 		chk = 0
  84. 	End
  85. Return chk
  86.  
  87.  
  88. Syntax:
  89. 	Say
  90. 	Say "Bin2Rexx,  Version 2.00"
  91. 	Say "Convert small binaries to Rexx programs that will in turn recreate those"
  92. 	Say "same binaries when executed"
  93. 	Say
  94. 	Say "Usage:    BIN2REXX  binary_in  [ binary_out ]"
  95. 	Say
  96. 	Say 'Where:    "binary_in"  is the name of the binary file to be converted'
  97. 	Say '          "binary_out" is the name of the binary file to be recreated'
  98. 	Say "          (if binary_out is not specified, binary_in will be used)"
  99. 	Say
  100. 	Say "Example:  BIN2REXX SAMPLE.ICO"
  101. 	Say
  102. 	Say "          would convert a file named SAMPLE.ICO into a Rexx program named"
  103. 	Say "          BIN."||Translate( rexxext )||" that would, whenever executed, create an exact copy"
  104. 	Say "          of SAMPLE.ICO"
  105. 	Say
  106. 	Say "Written by Rob van der Woude"
  107. 	Say "http://www.robvanderwoude.com"
  108. 	Exit 1
  109. return
  110.  
  111.  
  112. Blocked: Procedure
  113. 	Say ""
  114. 	Say " File "||Filespec( "N", arg( 1 ) )||" already exists."
  115. 	Say ""
  116. 	Call Syntax
  117. Return
  118.  

page last uploaded: 2016-12-15, 11:20