home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / bgiem.zip / install.cmd < prev    next >
OS/2 REXX Batch file  |  1993-11-07  |  7KB  |  324 lines

  1. /*  This file in the BGI Emulator package to the specified directory
  2. */
  3. "@echo off"
  4. call RxFuncAdd 'SysFileTree', 'RexxUtil', 'SysFileTree'
  5.  
  6. parse arg argument     /* Get the arguments */
  7.  
  8. /* Parse the arguments into separate parts of a stem variable */
  9. num_args = words(argument)
  10. do i=1 to num_args
  11.     args.i = word(argument,i)
  12. end
  13.  
  14. /* Check to make sure that the path to the BCOS2 installation is given */
  15. if (num_args < 1) then
  16. do
  17.    say "You must specify the directory where Borland C++ for OS/2 is installed"
  18.    exit 0
  19. end
  20.  
  21. /* Now check to see if it is a valid path */
  22. rc = SysFileTree(args.1,stem,'D')
  23. if (stem.0 \= 1) then
  24. do
  25.    say args.1" does not exist on this system"
  26.    exit 0
  27. end
  28.  
  29. /* Define the paths for different files */
  30.  
  31. bcos2_path   = args.1
  32. lib_path     = bcos2_path"\lib"
  33. include_path = bcos2_path"\include"
  34. install_path = "."
  35.  
  36. state = 0   /* Determines how much is done so far */
  37.  
  38. /* If there are any problems, make sure things are set back to normal. */
  39.  
  40. signal on failure name abnormal_term
  41. signal on halt name abnormal_term
  42. signal on syntax name abnormal_term
  43.  
  44. /* Copies the library file to the appropriate place */
  45.  
  46. state = 1
  47. "copy "install_path"\bgi.lib "lib_path
  48.  
  49. /* Make edits to the graphics file
  50.    This consists of three operations - commenting out the lines that prevent
  51.    graphics.h from being compiled when OS/2 is the operating system, 
  52.    adding some stuff to the enum
  53.    linestyles, and adding in all of the OS/2 function declarations.
  54. */
  55.  
  56. gfile   = include_path"\graphics.h"
  57. tmpfile = include_path"\graphics.bak"
  58. ch1file = install_path"\graphics.ch1"  /* Stuff for linestyle */
  59. ch2file = install_path"\graphics.ch2"  /* Function definitions */
  60.  
  61. /* Copy the graphics.h file to graphics.bak */
  62. "copy "gfile" "tmpfile
  63. state = 1                       /* Now we know graphics.bak exists */
  64.  
  65. /* Remove the graphics.h file */
  66. "del "gfile
  67.  
  68. say "**Modifying graphics.h file "
  69.  
  70. /* Open the graphics.bak file and the new graphics.h file */
  71.  
  72. err = stream(gfile,'C',"OPEN")
  73. if (err \= "READY:") then
  74. do
  75.     say "Error: Unable to open new graphics.h file"
  76.     call abnormal_term
  77. end
  78. state=3
  79.  
  80. err = stream(tmpfile,'C',"OPEN")
  81. if (err \= "READY:") then
  82. do
  83.     say "Error: Unable to open old graphics.h file"
  84.     call abnormal_term
  85. end
  86. state=4
  87.  
  88. /* Now read until we find the lines that prevent compiling graphics.h when
  89.    OS/2 is the operating system
  90. */
  91.  
  92. a=""
  93. do forever
  94.    a=linein(tmpfile)
  95.    if (stream(tmpfile) \= "READY") then    /* If that was the last line of the file */
  96.    do
  97.       say "Unable to read from "tmpfile
  98.       call abnormal_term
  99.    end
  100.    if (left(a,22) = "#if defined( __OS2__ )") then leave
  101.    err = lineout(gfile,a)
  102.    if (err \= 0) then
  103.    do
  104.       say "Error writing to "gfile
  105.       call abnormal_term
  106.    end
  107. end /* do */
  108.  
  109. /* We now have the first line to be commented out.  Comment out all lines until
  110.    we get to #endif
  111. */
  112. do while (left(a,6) <> "#endif")
  113.    err = lineout(gfile,"/* "a" */")
  114.    if (err \= 0) then
  115.    do
  116.       say "Error writing to "gfile
  117.       call abnormal_term
  118.    end
  119.    a=linein(tmpfile)
  120.    if (stream(tmpfile) \= "READY") then    /* If that was the last line of the file */
  121.    do
  122.       say "Unable to read from "tmpfile
  123.       call abnormal_term
  124.    end
  125. end /* do */
  126.  
  127. err = lineout(gfile,"/* "a" */")
  128. if (err \= 0) then
  129. do
  130.    say "Error writing to "gfile
  131.    call abnormal_term
  132. end
  133.  
  134. /* Now, have to eliminate the cdecl line for OS/2 versions */
  135. a=""
  136. do forever
  137.    a=linein(tmpfile)
  138.    if (stream(tmpfile) \= "READY") then    /* If that was the last line of the file */
  139.    do
  140.       say "Unable to read from "tmpfile
  141.       call abnormal_term
  142.    end
  143.    if (pos("#define _Cdecl  cdecl",a) \= 0) then leave
  144.    err = lineout(gfile,a)
  145.    if (err \= 0) then
  146.    do
  147.       say "Error writing to "gfile
  148.       call abnormal_term
  149.    end
  150. end /* do */
  151.  
  152. /* Now, comment it out */
  153. err = lineout(gfile,"#if !defined( __OS2__ )")
  154. if (err \= 0) then
  155. do
  156.    say "Error writing to "gfile
  157.    call abnormal_term
  158. end
  159. err = lineout(gfile,a)
  160. if (err \= 0) then
  161. do
  162.    say "Error writing to "gfile
  163.    call abnormal_term
  164. end
  165.  
  166. err = lineout(gfile,"#endif")
  167. if (err \= 0) then
  168. do
  169.    say "Error writing to "gfile
  170.    call abnormal_term
  171. end
  172.  
  173.  
  174. /* Now, search for the enum linestyle part */
  175. do forever
  176.    a=linein(tmpfile)
  177.    if (stream(tmpfile) \= "READY") then    /* If that was the last line of the file */
  178.    do
  179.       say "Unable to read from "tmpfile
  180.       call abnormal_term
  181.    end
  182.    err = lineout(gfile,a)
  183.    if (err \= 0) then
  184.    do
  185.       say "Error writing to "gfile
  186.       call abnormal_term
  187.    end
  188.    if (pos("USERBIT_LINE",a) <> 0) then leave
  189. end /* do */
  190.  
  191. /* Now, open up ch1file, and copy it into graphics.h */
  192. err = stream(ch1file,'C',"OPEN")
  193. if (err \= "READY:") then
  194. do
  195.     say "Error: Unable to open "ch1file
  196.     call abnormal_term
  197. end
  198. state=5
  199.  
  200. do forever
  201.    a=linein(ch1file)
  202.    err = lineout(gfile,a)
  203.    if (err \= 0) then
  204.    do
  205.       say "Error writing to "gfile
  206.       call abnormal_term
  207.    end
  208.    if (stream(ch1file) \= "READY") then 
  209.    do
  210.       leave
  211.    end
  212. end /* do */
  213.  
  214. err = stream(ch1file,'C',"CLOSE")
  215.  
  216. state = 4  /* Go back to previous state now that file is closed */
  217.  
  218.  
  219. /* Now, find the place where the functions are defined */
  220. do forever
  221.    a=linein(tmpfile)
  222.    if (stream(tmpfile) \= "READY") then    /* If that was the last line of the file */
  223.    do
  224.       say "Unable to read from "tmpfile
  225.       call abnormal_term
  226.    end
  227.    if (pos("far _Cdecl arc(int __x",a) <> 0) then leave
  228.    err = lineout(gfile,a)
  229.    if (err \= 0) then
  230.    do
  231.       say "Error writing to "gfile
  232.       call abnormal_term
  233.    end
  234. end /* do */
  235.  
  236. /* Save the current line for use later */
  237. b=a
  238.  
  239. /* Now insert the ch2file */
  240. err = stream(ch2file,'C',"OPEN")
  241. if (err \= "READY:") then
  242. do
  243.     say "Error: Unable to open "ch2file
  244.     call abnormal_term
  245. end
  246. state=6
  247.  
  248. do forever
  249.    a=linein(ch2file)
  250.    err = lineout(gfile,a)
  251.    if (err \= 0) then
  252.    do
  253.       say "Error writing to "gfile
  254.       call abnormal_term
  255.    end
  256.    if (stream(ch2file) \= "READY") then leave
  257. end /* do */
  258. err = stream(ch2file,'C',"CLOSE")
  259.  
  260. state = 4  /* Go back to previous state now that file is closed */
  261.  
  262. /* Write out the rest of the file, and then append a #endif */
  263. a=b
  264. do forever
  265.    err = lineout(gfile,a)
  266.    if (err \= 0) then
  267.    do
  268.       say "Error writing to "gfile
  269.       call abnormal_term
  270.    end
  271.    if (stream(tmpfile) \= "READY") then leave
  272.    a=linein(tmpfile)
  273. end /* do */
  274.  
  275. err=lineout(gfile,"#endif")
  276. if (err \= 0) then
  277. do
  278.    say "Error writing to "gfile
  279.    call abnormal_term
  280. end
  281.  
  282. /* Close the open files */
  283. err = stream(gfile,'C',"CLOSE")
  284. err = stream(tmpfile,'C',"CLOSE")
  285.  
  286. exit 1
  287.  
  288. abnormal_term: nop
  289.  
  290. say "Restoring to original configuration"
  291. if (state >= 1) then
  292. do
  293.    "del "lib_path"\bgi.lib"
  294. end
  295.  
  296. if (state >= 2) then
  297. do
  298.    "copy "tmpfile" "gfile   /* Restore graphics.h */
  299.    "del "tmpfile
  300. end
  301.  
  302. if (state >= 3) then 
  303. do
  304.    err = stream(gfile,'C',"CLOSE")
  305. end
  306.  
  307. if (state >= 4) then
  308. do
  309.    err = stream(tmpfile,'C',"CLOSE")
  310. end
  311.  
  312. if (state = 5) then
  313. do
  314.    err = stream(ch1file,'C',"CLOSE")
  315. end
  316.  
  317. if (state = 6) then
  318. do
  319.    err = stream(ch2file,'C',"CLOSE")
  320. end
  321.  
  322. exit 0
  323.  
  324.