home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21fb.zip / octave / inst-octave.cmd < prev    next >
OS/2 REXX Batch file  |  2000-01-15  |  31KB  |  906 lines

  1. /*
  2. *******************************************************************************
  3. ** Install and Setup script for Octave/2 Version 0.6                         **
  4. ** (c) Klaus Gebhardt, 1996 - 1997                                           **
  5. *******************************************************************************
  6. */
  7.  
  8. /*
  9. *******************************************************************************
  10. ** This script will make all the necessary changes in the following files:   **
  11. **                                                                           **
  12. **   1. CONFIG.SYS                                                           **
  13. **   2. .emacs                                                               **
  14. **   3. .octaverc                                                            **
  15. **     (or the file pointed to by the environment variable OCTAVE_INITFILE)  **
  16. **   4. %INFOPATH%dir                                                        **
  17. *******************************************************************************
  18. ** It will also copy the info files to the directoy pointed to by the        **
  19. ** variable INFOPATH, and it replaces emx.dll, emxlibcs.dll and              **
  20. ** termcap.dat, if the files coming with Octave/2 are newer than those       **
  21. ** on your system.                                                           **
  22. *******************************************************************************
  23. ** This script also creates a folder with a program object for Octave/2      **
  24. ** on the WPS.                                                               **
  25. *******************************************************************************
  26. ** ALL ORIGINAL FILES, WHICH ARE MODIFIED OR REPLACED BY THIS SCRIPT         **
  27. ** ARE BACKUPED IN THE DIRECTORY YOU HAVE OCTAVE/2 INSTALLED IN.             **
  28. *******************************************************************************
  29. ** NO WARRANTY!                                                              **
  30. *******************************************************************************
  31. */
  32.  
  33. "@echo off"
  34. debug = ">NUL 2>NUL"
  35. debug_mode = 0;
  36.  
  37. version     = "2.1.23";
  38. script_arc  = "SCRIPTS.ZIP";
  39. dlfcn_arc   = "DLFCN.ZIP";
  40.  
  41. default_dir.0 = 3;
  42. default_dir.1 = "j:/apps2/science/octave";
  43. default_dir.2 = "h:/apps/science/octave-";
  44. default_dir.3 = "i:/apps/octave-";
  45.  
  46. config_modified   = 0;
  47. config.0.nr =  9;
  48. config.1.nr =  8; config.1.name = "LIBPATH=";             config.1.zeile = "";
  49. config.2.nr =  9; config.2.name = "SET PATH=";            config.2.zeile = "";
  50. config.3.nr = 16; config.3.name = "SET OCTAVE_HOME=";     config.3.zeile = "";
  51. config.4.nr = 12; config.4.name = "SET TERMCAP=";         config.4.zeile = "";
  52. config.5.nr =  9; config.5.name = "SET TERM=";            config.5.zeile = "";
  53. config.6.nr =  9; config.6.name = "SET HOME=";            config.6.zeile = "";
  54. config.7.nr = 20; config.7.name = "SET OCTAVE_INITFILE="; config.7.zeile = "";
  55. config.8.nr = 13; config.8.name = "SET INFOPATH=";        config.8.zeile = "";
  56. config.9.nr = 12; config.9.name = "SET GNUPLOT=";         config.9.zeile = "";
  57.  
  58. emacs_modified = 0;
  59. octaverc_modified = 0;
  60. dir_modified = 0;
  61.  
  62.  
  63. call RxFuncAdd "SysLoadFuncs", "RexxUtil", "SysLoadFuncs"
  64. call SysLoadFuncs
  65.  
  66. parse upper arg option cmdl
  67.  
  68. /*
  69. *******************************************************************************
  70. ** Debug-Mode                                                                **
  71. *******************************************************************************
  72. */
  73. if (option == "/DEBUG") then
  74.   do
  75.     say "info: Running in DEBUG mode!";
  76.     "@echo on"
  77.     debug = ""
  78.     debug_mode = 1;
  79.   end
  80. else
  81.   do
  82.     debug_mode = 0;
  83.     cmdl = option;
  84.   end
  85.  
  86. /*
  87. *******************************************************************************
  88. ** Removing unnecessary files                                                **
  89. *******************************************************************************
  90. */
  91. if (cmdl == "/CLEAN") then
  92.   do
  93.     say "info: Removing all for running Octave/2" version "unnecessary files";
  94.     "del Change*.* *.zip COPY*.* BUGS NEWS NEWS.1 PROJECTS README.*" debug
  95.     "del ROADMAP SENDING.PAT THANKS" debug
  96.     "del updt-oct*.cmd *.old *.new emx* unzip.exe" debug
  97.     exit;
  98.   end
  99.  
  100. /*
  101. *******************************************************************************
  102. ** Wrong argument and usage message                                          **
  103. *******************************************************************************
  104. */
  105. if ((cmdl <> "/INSTALL") & (cmdl <> "/USAGE") & (cmdl <> "")) then
  106.   do
  107.     say "error: Unknown command line option!";
  108.     say "";
  109.     cmdl = "";
  110.   end
  111.  
  112. if ((cmdl == "/USAGE") | (cmdl == "")) then
  113.   do
  114.     say "Usage:"
  115.     say "  Type 'inst-octave /install' to install Octave/2" version;
  116.     say "  Type 'inst-octave /usage'   to see this message.";
  117.     say "  Type 'inst-octave /clean'   to remove unnecessary files.";
  118.     say "on FAT systems you must type 'inst-oct' instead of 'inst-octave'";
  119.     exit;
  120.   end
  121.  
  122. /*
  123. *******************************************************************************
  124. ** Installation or Uodating the installation                                 **
  125. *******************************************************************************
  126. */
  127. say "info: Installing Octave/2" version "..."
  128.  
  129. boot_drive = get_boot_drive();
  130. say "info: OS/2 booted from" boot_drive;
  131.  
  132. octave_home = to_unix_sep(directory());
  133. octave_dll = octave_home || "/dll";
  134. if (check_octave_files(octave_home, 1) == 0) then
  135.   do
  136.     say "error: Run this script from within in the directory octave is"
  137.     say "error: installed in! If you are installing from the sources, you"
  138.     say "error: must compile Octave" version "before running this script!"
  139.     say "error: To do so, type: make -f makefile.os2"
  140.     exit;
  141.   end
  142. say "info: Octave/2 is installed in" octave_home || ".";
  143.  
  144. /* Analyse the CONFIG.SYS */
  145. octave_old_home = read_config_sys(boot_drive, octave_home);
  146. if (octave_old_home == "") then
  147.   do
  148.     say "info: There is no OCTAVE_HOME in your config.sys and also no";
  149.     say "info: entry in LIBPATH and SET PATH corresponding to an";
  150.     say "info: Octave/2 directory: This is the first installation of";
  151.     say "info: Octave/2 on this system.";
  152.     octave_old_dll = "";
  153.   end
  154. else
  155.   do
  156.     say "info: I found an old version of Octave/2 in your config.sys.";
  157.     say "info: This version was installed in:" octave_old_home;
  158.     say "info: I will remove all entries pointing to that version!"
  159.     octave_old_dll = octave_old_home || "/dll";
  160.   end
  161.  
  162. /* Replace older DLLs coming with EMX, if necessary */
  163. call emx_dlls config.1.zeile, "emx.dll"
  164. call emx_dlls config.1.zeile, "emxlibcs.dll"
  165.  
  166. /* Modify LIBPATH, PATH and OCTAVE_HOME */
  167. if to_upper(octave_old_home) <> to_upper(octave_home) then
  168.   do
  169.     config_modified = 1;
  170.     config.1.zeile = subst_paths(config.1.zeile, octave_old_dll,  octave_dll);
  171.     config.2.zeile = subst_paths(config.2.zeile, octave_old_home, octave_home);
  172.   end
  173.  
  174. if (to_upper(octave_home) <> to_upper(default_dir.1)) then
  175.   do
  176.     if (to_upper(config.3.zeile) <> to_upper(octave_home)) then
  177.       do
  178.         config_modified = 1;
  179.         config.3.zeile  = octave_home;
  180.       end
  181.   end
  182. else
  183.   do
  184.     if (to_upper(config.3.zeile) <> "") then
  185.       do
  186.         config_modified = 1;
  187.         config.3.zeile  = "";
  188.       end
  189.   end
  190.  
  191. /* Modify TERMCAP, TERM and move TERMCAP.DAT */
  192. if (config.4.zeile <> "") then
  193.   do
  194.     if ((octave_old_home == "") | (to_upper(octave_old_home || "/etc/termcap.dat") <> to_upper(config.4.zeile))) then
  195.       do
  196.         config.4.zeile = emx_termcap(config.4.zeile);
  197.       end
  198.     else config.4.zeile = "";
  199.   end
  200.  
  201. if (config.4.zeile == "") then
  202.   do
  203.     config.4.zeile  = octave_home || "/etc/termcap.dat";
  204.     config_modified = 1;
  205.   end
  206.  
  207. if (config.5.zeile == "") then
  208.   do
  209.     config.5.zeile  = "ansi";
  210.     config_modified = 1;
  211.   end
  212.  
  213. /* Set the thie home directory to the root of your boot drive. */
  214. if (config.6.zeile == "") then
  215.   do
  216.     config.6.zeile  = boot_drive || "/.";
  217.     config_modified = 1;
  218.   end
  219.  
  220. /* Create or modify .octaverc */
  221. octave_rc = update_octaverc(config.6.zeile, config.7.zeile, octave_old_home, octave_home);
  222. if (to_upper(octave_rc) <> to_upper(config.7.zeile)) then
  223.   do
  224.     config.7.zeile = octave_rc;
  225.     config_modified = 1;
  226.   end
  227.  
  228. /* Modify INFO_PATH */
  229. if (config.8.zeile == "") then
  230.   do
  231.     config.8.zeile  = ".;" || octave_home || "/doc";
  232.     config_modified = 1;
  233.   end
  234. else
  235.   do
  236.     if (pos(";", config.8.zeile) == 0) then
  237.       do
  238.         len_info_path = length(config.8.zeile);
  239.         if (substr(config.8.zeile, len_info_path, 1) == "/") then
  240.           do
  241.             old_info_path = substr(config.8.zeile, 1, len_info_path-1);
  242.           end
  243.         else
  244.           do
  245.             old_info_path = config.8.zeile;
  246.           end
  247.         config.8.zeile = ".;" || old_info_path;
  248.         config_modified = 1;
  249.       end
  250.     info_path = to_unix_sep(subst_paths(config.8.zeile, octave_old_home || "/doc", octave_home || "/doc"));
  251.     call info_path_dir info_path, octave_home, version
  252.   if (to_upper(info_path) <> to_upper(config.8.zeile)) then
  253.     do
  254.       config.8.zeile = info_path;
  255.       config_modified = 1;
  256.     end
  257.   end
  258.  
  259. /* Modify or Add the variable GNUPLOT */
  260. if (config.9.zeile == "") then
  261.   do
  262.     fullgplt = SysSearchPath(PATH, "gnuplot.exe");
  263.     if (fullgplt <> "") then
  264.       do
  265.         pathgplt = filespec("drive", fullgplt) || filespec("path", fullgplt);
  266.         gplt = to_unix_sep(substr(pathgplt, 1, length(pathgplt)-1));
  267.         if (gplt <> config.9.zeile) then
  268.           do
  269.             config.9.zeile = gplt;
  270.             config_modified = 1;
  271.           end
  272.       end
  273.   end
  274.  
  275. /* Unzip the files for dynamic loading */
  276. call unzip_dlfcn_files dlfcn_arc
  277.  
  278. /* Unzip the script files */
  279. call unzip_script_files script_arc
  280.  
  281. /* Install on the WPS */
  282. if (debug_mode == 0) then call create_wps_object octave_home, version
  283.  
  284. rc = ini_files(config.6.zeile, ".emacs", "emacs", octave_old_home, octave_home);
  285. if (rc == 2) then
  286.   do
  287.     if (debug_mode == 0) then
  288.       do
  289.         "copy emacs.new" to_os2_sep(config.6.zeile) || "\.emacs" debug
  290.       end
  291.     say "info: EMACS MUST BE RESTARTED!"
  292.   end
  293.  
  294. if (config_modified == 1) then
  295.   do
  296.     call write_config_new boot_drive, octave_home
  297.     if (debug_mode == 0) then
  298.       do
  299.         "copy config.new" boot_drive || "\config.sys" debug
  300.       end
  301.     say "info: YOU MUST REBOOT YOUR SYSTEM!";
  302.   end
  303.  
  304. say "info: Done.";
  305. exit;
  306.  
  307. /*
  308. *******************************************************************************
  309. ** Write the modified config.sys                                             **
  310. *******************************************************************************
  311. */
  312. write_config_new: procedure expose config. debug version
  313. parse arg boot, dir
  314.   config_old = to_os2_sep(dir) || "\config.old";
  315.   config_new = to_os2_sep(dir) || "\config.new";
  316.   "del" config_new debug
  317.  
  318.   rc = stream(config_old, "C", "open read");
  319.   if rc <> "READY:" then
  320.     do
  321.       say "error: Cannot open the backup of CONFIG.SYS!";
  322.       exit;
  323.     end
  324.  
  325.   rc = stream(config_new, "C", "open write");
  326.   if rc <> "READY:" then
  327.     do
  328.       say "error: Cannot open CONFIG.NEW!";
  329.       rc = stream(config_old, "C", "close");
  330.       exit;
  331.     end
  332.  
  333.   say "info: Writing" config_new "...";
  334.   do while(lines(config_old))
  335.     line = linein(config_old);
  336.     do i=1 to config.0.nr
  337.       if (to_upper(substr(strip(line), 1, config.i.nr)) == config.i.name) then
  338.         do
  339.           if config.i.zeile <> "" then
  340.             do
  341.               p = pos(to_upper(config.i.name), to_upper(config.i.name));
  342.               if (p <= 1) then
  343.                 line = config.i.name || config.i.zeile;
  344.               else
  345.                 line = substr(" ",1,p," ") || config.i.name || config.i.zeile;
  346.               config.i.zeile = "";
  347.             end
  348.           leave;
  349.         end
  350.     end
  351.     call lineout config_new, line
  352.   end
  353.  
  354.   sep = 0;
  355.   do i=1 to config.0.nr
  356.     if (config.i.zeile <> "") then
  357.       do
  358.         if (sep == 0) then
  359.           do
  360.             call lineout config_new, ""
  361.             call lineout config_new, "REM Octave/2" version
  362.             sep = 1;
  363.           end
  364.         call lineout config_new, config.i.name || config.i.zeile;
  365.         config.i.zeile = "";
  366.       end
  367.   end
  368.  
  369.   rc = stream(config_new, "C", "close");
  370.   rc = stream(config_old, "C", "close");
  371.   return;
  372.  
  373. /*
  374. *******************************************************************************
  375. ** Analysing CONFIG.SYS:                                                     **
  376. *******************************************************************************
  377. */
  378. read_config_sys: procedure expose config. default_dir. debug
  379. parse arg boot, dir
  380.   config_old = to_os2_sep(dir) || "\config.old";
  381.   say "info: Copying" boot || "\config.sys to" config_old "...";
  382.   "copy" boot || "\config.sys" config_old debug
  383.  
  384.   rc = stream(config_old, "C", "open read");
  385.   if (rc <> "READY:") then
  386.     do
  387.       say "error: Cannot open the backup of CONFIG.SYS!";
  388.       exit;
  389.     end
  390.  
  391.   say "info: Analysing" config_old "...";
  392.   do while(lines(config_old))
  393.     line  = strip(linein(config_old));
  394.     do i=1 to config.0.nr
  395.       strupper = to_upper(substr(line, 1, config.i.nr));
  396.       if (strupper == config.i.name) then
  397.         do
  398.           config.i.zeile = substr(line, config.i.nr+1);
  399.           leave;
  400.         end
  401.     end
  402.   end
  403.   rc = stream(config_old, "C", "close");
  404.  
  405.   if (config.1.zeile == "") then
  406.     do
  407.       say "error: No "LIBPATH" statement found!";
  408.       exit;
  409.     end
  410.   else libpath = config.1.zeile;
  411.  
  412.   if (config.2.zeile == "") then
  413.     do
  414.       say "error: No "SET PATH" statement found!";
  415.       exit;
  416.     end
  417.   else path = config.2.zeile;
  418.  
  419.   oh = config.3.zeile;
  420.   if (oh <> "") then return to_unix_sep(oh);
  421.   else
  422.     do
  423.       do i = 1 to default_dir.0
  424.         oh = check_octave_old_home(default_dir.i, libpath, path);
  425.         if (oh <> "") then return to_unix_sep(oh);
  426.       end
  427.     end
  428.   return "";
  429.  
  430. check_octave_old_home: procedure expose debug
  431. parse arg str, libpath, path
  432.   string = to_os2_sep(str);
  433.   pa = 0;
  434.   do while(1)
  435.     pa = pos(to_upper(string), to_upper(path), pa + 1);
  436.     if (pa == 0) then return "";
  437.     if (pa <> 1) then
  438.       do
  439.         if (substr(path, pa - 1, 1) <> ";") then iterate;
  440.       end
  441.     pe = pos(";", path, pa);
  442.     if (pe == 0) then old_home = substr(path, pa);
  443.     else              old_home = substr(path, pa, pe-pa);
  444.     qa = pos(to_upper(old_home || "\DLL"), to_upper(libpath));
  445.     if (qa == 0) then iterate;
  446.     if (qa <> 1) then
  447.       do
  448.         if (substr(path, qa - 1, 1) <> ";") then iterate;
  449.       end
  450.     qe = pos(";", libpath, qa);
  451.     if qe == 0 then old_dll = to_upper(substr(libpath, qa));
  452.     else            old_dll = to_upper(substr(libpath, qa, qe-qa));
  453.     if (to_upper(old_home || "\DLL") == old_dll) then
  454.       do
  455.     flag = check_octave_files(old_home, 0);
  456.     if (flag == 0) then
  457.           do
  458.             say "notice: I FOUND AN OLD OCTAVE DIRECTORY ("fullpath") IN";
  459.             say "notice: LIBPATH AND PATH, BUT WITHOUT ANY OCTAVE FILES.";
  460.             say "notice: SHOULD I REMOVE ALL ENTRIES IN LIBPATH AND PATH";
  461.             say "notice: POINTING TO THAT DIRECTORY [Y/N]";
  462.             parse pull in;
  463.             flag = (in == "Y") | (in == "y");
  464.           end
  465.         if (flag) then return to_unix_sep(old_home);
  466.       end
  467.     else  return "";
  468.   end
  469.  
  470. check_octave_files: procedure expose debug
  471. parse arg string, flag
  472.   path = to_os2_sep(string);
  473.   rc = SysFileTree(path || "\octave.exe",     exe, "FO");
  474.   rc = SysFileTree(path || "\octave.ico",     ico, "FO");
  475.   rc = SysFileTree(path || "\dll\cruft?.dll", crt, "FO");
  476.   if (flag <> 0) then rc = SysFileTree(path || "\dll\octave?.dll", oct, "FO");
  477.   else                oct.0 = 2;
  478.   res = (exe.0 == 1) & (ico.0 == 1) & (crt.0 == 4) & (oct.0 == 2);
  479.   return res;
  480.  
  481. /*
  482. *******************************************************************************
  483. ** Updating the emx TERMCAP.DAT                                              **
  484. *******************************************************************************
  485. */
  486. emx_termcap: procedure expose debug
  487. parse arg termcap
  488.   call SysFileTree "etc\termcap.dat", oct_datei, "FT";
  489.   if oct_datei.0 <> 1 then return termcap;
  490.   if datei.1 > 80 then oct = "19" || oct_datei.1;
  491.   else                 oct = "20" || oct_datei.1;
  492.  
  493.   call SysFileTree to_os2_sep(termcap), emx_datei, "FT";
  494.   if emx_datei.0 <> 1 then return "";
  495.   if datei.1 > 80 then emx = "19" || emx_datei.1;
  496.   else                 emx = "20" || emx_datei.1;
  497.  
  498.   if oct == emx then return termcap;
  499.   if oct > emx then
  500.     do
  501.       say "info: Replacing" to_os2_sep(termcap) "...";
  502.       "copy" to_os2_sep(termcap) "termcap.old" debug
  503.       "copy etc\termcap.dat" to_os2_sep(termcap) debug
  504.     end
  505.   else
  506.     do
  507.       say "info: Removing termcap.dat coming with Octave/2 ...";
  508.       "del etc\termcap.dat" debug
  509.       "rd etc" debug
  510.     end
  511.  
  512.   return termcap;
  513.  
  514. /*
  515. *******************************************************************************
  516. ** Replacing the emx-DLLs                                                    **
  517. *******************************************************************************
  518. */
  519. emx_dlls: procedure expose debug
  520. parse arg libpath, file
  521.   call SysFileTree "dll\" || file, oct_datei, "FT";
  522.   if oct_datei.0 <> 1 then return;
  523.   if datei.1 > 80 then oct = "19" || oct_datei.1;
  524.   else                 oct = "20" || oct_datei.1;
  525.  
  526.   count = 0;
  527.   do while(1)
  528.     n = setlocal();
  529.     "SET OCTAVE_LIBPATH=" || libpath
  530.     fullpath = SysSearchPath(OCTAVE_LIBPATH, file);
  531.     if fullpath == "" then leave;
  532.     call SysFileTree fullpath, emx_datei, "FT";
  533.     if emx_datei.0 <> 1 then leave;
  534.     if datei.1 > 80 then emx = "19" || emx_datei.1;
  535.     else                 emx = "20" || emx_datei.1;
  536.     n = endlocal();
  537.  
  538.     if oct == emx then leave;
  539.     if oct > emx then
  540.       do
  541.         count = count+1;
  542.         bak_file = substr(file, 1, length(file)-3) || count;
  543.         "copy" fullpath bak_file debug
  544.         say "info: Older DLL (" || file || ") saved as:" bak_file;
  545.         say "info: Removing DLL (" || file || ") ...";
  546.         rc = 1;
  547.         do while(rc <> 0)
  548.           rc = SysFileDelete(fullpath);
  549.           if rc <> 0 then
  550.             do
  551.               say "notice: UNABLE TO DELETE FILE:" fullpath;
  552.               say "notice: THE DLL IS USED BY ONE OR MORE EMX PROGRAMS!";
  553.               say "notice: KILL ALL THOSE PROGRAMS BEFORE CONTINUING!";
  554.               say "notice: PRESS ENTER, WHEN READY ...";
  555.               parse pull in;
  556.             end
  557.         end            
  558.       end
  559.     else
  560.       do
  561.         say "info: Removing" file "coming with Octave/2 ...";
  562.         "del dll\" || file debug;
  563.         leave;
  564.       end
  565.   end
  566.   return;
  567.  
  568. /*
  569. *******************************************************************************
  570. ** Updating .octaverc                                                        **
  571. *******************************************************************************
  572. */
  573. update_octaverc: procedure expose debug debug_mode version
  574. parse arg home, initfile, old, new
  575.   if (initfile == "") then octrc = ".octaverc";
  576.   else                     octrc = initfile;
  577.  
  578.   octrc_new = "octaverc.new";
  579.   rc = ini_files(home, octrc, "octaverc", old, new);
  580.   if (rc == -1) then
  581.     do
  582.       "del" octrc_new debug
  583.       rc = stream(octrc_new, "C", "open write");
  584.       if (rc == "READY:") then
  585.         do
  586.           call lineout octrc_new, "# Startup file"
  587.           call lineout octrc_new, "# Octave" version "for OS/2"
  588.           call lineout octrc_new, "# (c) 1996 - 1997, Klaus Gebhardt"
  589.           rc = stream(octrc_new, "C", "close");
  590.           rc = 2;
  591.         end
  592.       else
  593.         do
  594.           say "error: Cannot create octaverc.new!";
  595.          exit;
  596.         end
  597.     end
  598.  
  599.   if (rc == 2) then
  600.     do
  601.       "del" to_os2_sep(home) || "\" || octrc debug
  602.       octrc_ini = to_os2_sep(home) || "\octave.ini"
  603.       "copy" octrc_new octrc_ini debug
  604.       "ren" octrc_ini ".octaverc" debug
  605.       rc = stream(octrc_ini, "C", "open read");
  606.       if (rc == "READY:") then
  607.         do
  608.           rc = stream(octrc_new, "C", "close");
  609.           rc = stream(octrc_ini, "C", "open write");
  610.           call lineout octrc_new, ''
  611.           call lineout octrc_new, 'history_file = "octave.hst"'
  612.           rc = stream(octrc_new, "C", "close");
  613.           return "octave.ini";
  614.         end
  615.       return "";
  616.     end
  617.   return initfile;
  618.  
  619. /*
  620. *******************************************************************************
  621. ** Modify the files .emacs, .octaverc                                        **
  622. *******************************************************************************
  623. */
  624. ini_files: procedure expose debug
  625. parse arg home, inifile, newfile, oldpath, newpath
  626.   file = to_os2_sep(home) || "\" || inifile;
  627.   ini_old = newfile || ".old";
  628.   ini_new = newfile || ".new";
  629.   say "info: Copying" file "to" ini_old "...";
  630.   "copy" file ini_old debug
  631.  
  632.   old = to_unix_sep(oldpath);
  633.   new = to_unix_sep(newpath);
  634.  
  635.   rc = stream(ini_old, "C", "open read");
  636.   if (rc <> "READY:") then return -1;
  637.  
  638.   "del" ini_new debug;
  639.   rc = stream(ini_new, "C", "open write");
  640.   if (rc <> "READY:") then
  641.     do
  642.       say "info: Cannot open" ini_new || "!";
  643.       rc = stream(ini_old, "C", "close");
  644.       exit;
  645.     end
  646.  
  647.   if (to_upper(old) == to_upper(new)) then return 0;
  648.  
  649.   rv = 1;
  650.   do while(lines(ini_old))
  651.     line  = linein(ini_old);
  652.     p = pos(to_upper(old), to_upper(line));
  653.     if (p <> 0) then
  654.       do
  655.         rv = 2;
  656.         if (p == 1) then
  657.           do
  658.             line = new || substr(line, 1+length(old));
  659.           end
  660.         else
  661.           do
  662.             line = substr(line, 1, p-1) || new || substr(line, p+length(old));
  663.           end
  664.       end
  665.     call lineout ini_new, line
  666.   end
  667.  
  668.   rc = stream(ini_new, "C", "close");
  669.   rc = stream(ini_old, "C", "close");
  670.   return rv;
  671.  
  672. /*
  673. *******************************************************************************
  674. ** Remove old INFO files, modify all dir files                               **
  675. *******************************************************************************
  676. */
  677. info_path_dir: procedure expose debug
  678. parse arg info_path, octave_home, version
  679.   infopath = to_os2_sep(info_path);
  680.   octaveinfopath = to_os2_sep(octave_home || "/doc");
  681.  
  682.   p = 1;
  683.   q = 1;
  684.   do while (q > 0)
  685.     q = pos(";", infopath, p);
  686.     if (q == 0) then infodir = substr(infopath, p);
  687.     else             infodir = substr(infopath, p, q - p);
  688.     p = q + 1;
  689.  
  690.     if (infodir == "")  then iterate;
  691.     if (infodir == ".")  then iterate;
  692.     if (to_upper(infodir) == to_upper(octaveinfopath)) then iterate;
  693.  
  694.     say "info: Removing old info files in" infodir;
  695.     "del" infodir || "\octave" debug
  696.     "del" infodir || "\octave.i0?" debug
  697.     "del" infodir || "\octave.i1?" debug
  698.     "del" infodir || "\liboct" debug
  699.     "del" infodir || "\liboct.i0?" debug
  700.     "del" infodir || "\faq" debug
  701.     "del" infodir || "\oct-faq" debug
  702.  
  703.     file = infodir || "\dir"
  704.     dir_old = "dir" || p || ".old";
  705.     dir_new = "dir" || p || ".new";
  706.     say "info: Copying" file "to" dir_old "...";
  707.     "copy" file dir_old debug
  708.  
  709.     rc = stream(dir_old, "C", "open read");
  710.     if (rc <> "READY:") then return;
  711.  
  712.     "del" dir_new debug;
  713.     rc = stream(dir_new, "C", "open write");
  714.     if (rc <> "READY:") then
  715.       do
  716.         say "error: Cannot open" dir_new || "!";
  717.         rc = stream(dir_old, "C", "close");
  718.         exit;
  719.       end
  720.  
  721.     line = " ";
  722.     do while(lines(dir_old))
  723.       if line == d2c(31) then call lineout dir_new, line
  724.       line  = linein(dir_old);
  725.       parse var line w1 w2 ":" w3 "." w4
  726.       if ((w1 <> "*") | ((to_upper(w3) <> "(FAQ)") & (to_upper(w3) <> "(OCT-FAQ)") & (to_upper(w3) <> "(OCTAVE)") & (to_upper(w3) <> "(LIBOCT)"))) then
  727.         do
  728.           if line <> d2c(31) then call lineout dir_new, line
  729.         end
  730.     end
  731.  
  732.     call lineout dir_new, "* octave:    (octave).      Octave" version || "."
  733.     call lineout dir_new, "* liboctave: (liboct).      Info about liboctave" version || "."
  734.     call lineout dir_new, "* octave-faq:(oct-faq).     FAQs about Octave" version || "."
  735.    call lineout dir_new, d2c(31)
  736.  
  737.     rc = stream(dir_new, "C", "close");
  738.     rc = stream(dir_old, "C", "close");
  739.  
  740.     say "info: Copying" dir_new "to" file "...";
  741.     "copy" dir_new file debug
  742.   end
  743.   return;
  744.  
  745. /*
  746. *******************************************************************************
  747. ** Unzip DLFCN files                                                         **
  748. *******************************************************************************
  749. */
  750. unzip_dlfcn_files: procedure expose debug
  751. parse arg dlfcn
  752.   ".\unzip -uo" dlfcn debug
  753.   return;
  754.  
  755. /*
  756. *******************************************************************************
  757. ** Unzip script files                                                        **
  758. *******************************************************************************
  759. */
  760. unzip_script_files: procedure expose debug
  761. parse arg zipfile
  762.   rc = SysFileTree(zipfile, fs, "F");
  763.   if fs.0 = 0 then return;
  764.   rc = SysFileTree("ChangeLog", fs, "F");
  765.   if fs.0 = 1 then scr = "scripts/*";
  766.   else             scr = "scripts.fat/*";
  767.   say "info: Unzipping scriptfiles ...";
  768.   if fs.0 = 0 then "ren scripts scripts.fat";
  769.   ".\unzip -uo" zipfile scr debug
  770.   if fs.0 = 0 then "ren scripts.fat scripts";
  771.   return;
  772.  
  773. /*
  774. *******************************************************************************
  775. ** Create a WPS object for Octave/2                                          **
  776. *******************************************************************************
  777. */
  778. create_wps_object: procedure expose debug
  779. parse arg octave_home, version
  780.  
  781.   octave_folder_id = "<HWB_OCTAVE_FOLDER>";
  782.  
  783.   call SysCreateObject "WPFolder", "Octave/2", "<WP_DESKTOP>", ,
  784.        "OBJECTID="||octave_folder_id, "fail"
  785.  
  786.   object_name = "Octave" version;
  787.   octave_file = to_os2_sep(octave_home) || "\octave.exe";
  788.   octave_icon = to_os2_sep(octave_home) || "\octave.ico";
  789.  
  790.   rc = SysCreateObject("WPProgram", object_name, octave_folder_id, ,
  791.        "EXENAME="octave_file";PROGTYPE=WINDOWABLEVIO;ICONFILE="octave_icon||,
  792.        ";OBJECTID=<HWB_OCTAVE>", "replace");
  793.  
  794.   if rc == 1 then say "info: Program object for Octave created successfully."
  795.   else            say "notice: Could not create program object for Octave."
  796.  
  797.   call make_book 'oct-faq.inf', 'FAQ about Octave', ''
  798.   call make_book 'octave.inf', 'GNU Octave', ''
  799.   call make_book 'liboct.inf', 'Octave C++ Classes', ''
  800.  
  801.   return;
  802.  
  803. make_book: procedure expose octave_folder_id octave_home
  804. parse arg name, title, parm
  805.  
  806.   file = to_os2_sep(octave_home) || "\doc\" || name;
  807.  
  808.   rc = SysCreateObject('WPProgram', title, octave_folder_id, ,
  809.                       'PROGTYPE=PM;EXENAME=VIEW.EXE;PARAMETERS='||file||parm, ,
  810.                       'replace');
  811.  
  812.   if rc == 1 then say "info: Book object" title "created successfully."
  813.   else            say "notice: Could not create book object" title "."
  814.   return;
  815.  
  816. /*
  817. *******************************************************************************
  818. ** Determine the drive OS/2 is booted from                                   **
  819. *******************************************************************************
  820. */
  821. get_boot_drive: procedure expose debug
  822.   irc = SysIni("BOTH", "FolderWorkareaRunningObjects",,
  823.                "ALL:", "Objects");
  824.   boot1 = left(Objects.1, 2);;
  825.   do i = 2 to Objects.0
  826.     if (to_upper(right(Objects.i, 7)) == "DESKTOP")           then boot1 = left(Objects.i, 2);
  827.     if (to_upper(right(Objects.i,17)) == "ARBEITSOBERFLÄCHE") then boot1 = left(Objects.i, 2);
  828.     if (to_upper(right(Objects.i, 9)) == "SKRIVBORD")         then boot1 = left(Objects.i, 2);
  829.   end
  830.   boot2 = substr(translate(value("PATH", , "OS2ENVIRONMENT")), pos("\OS2\SYSTEM", translate(value("PATH", , "OS2ENVIRONMENT")))-2, 2);
  831.   rc = SysFileTree(boot1 || "\config.sys", cfg, "FO");
  832.   if ((to_upper(boot1) == to_upper(boot2)) & (cfg.0 == 1)) then return boot1;
  833.   else
  834.     do
  835.       say "error: Unable to determine the boot drive!";
  836.       do while (1)
  837.         say "error: Available disk drives are:"
  838.         drivelist = SysDriveMap()
  839.         say "error:   " drivelist
  840.  
  841.         say "error: Please enter the OS/2 boot drive OS/2 (example, c:)?  "
  842.         pull drive
  843.  
  844.         rc = SysFileTree(drive || "\config.sys", cfg, "FO");
  845.         if ((wordpos(drive, drivelist) == 0) & (cfg.0 <> 1)) then
  846.           do
  847.             say "error: You must enter a proper drive letter with colon."
  848.             say "error: There must also be the file CONFIG.SYS in the root!"
  849.           end
  850.         else return drive;
  851.       end
  852.     end
  853.   return boot1;
  854.  
  855. /*
  856. *******************************************************************************
  857. ** Replace old pathes                                                        **
  858. *******************************************************************************
  859. */
  860. subst_paths: procedure expose debug
  861. parse arg path_arg, old_path, new_path
  862.   path= to_os2_sep(path_arg);
  863.   old = to_os2_sep(old_path);
  864.   new = to_os2_sep(new_path);
  865.  
  866.   p = 0;
  867.   do while(1)
  868.     p = pos(to_upper(old), to_upper(path), p + 1);
  869.     if (p == 0) then
  870.       do
  871.         if (substr(path, length(path)) == ";") then return path || new || ";";
  872.         else                                        return path || ";" || new;
  873.       end
  874.     if (p <> 1) then
  875.       do
  876.         if (substr(path, p - 1, 1) <> ";") then iterate;
  877.       end
  878.     q = pos(";", path, p);
  879.     if (q == 0) then old_path = substr(path, p);
  880.     else             old_path = substr(path, p, q - p);
  881.     if (to_upper(old_path) <> to_upper(old)) then iterate;
  882.     if (q == 0) then return substr(path, 1, p-1) || new;
  883.     else             return substr(path, 1, p-1) || new || substr(path, q);
  884.   end
  885.  
  886. /*
  887. *******************************************************************************
  888. ** Utilities                                                                 **
  889. *******************************************************************************
  890. */
  891. to_upper: procedure
  892. parse arg string
  893.   return translate(string, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz");
  894.  
  895. to_lower: procedure
  896. parse arg string
  897.   return translate(string, "abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
  898.  
  899. to_unix_sep: procedure
  900. parse arg string
  901.   return translate(string, "/", "\");
  902.  
  903. to_os2_sep: procedure
  904. parse arg string
  905.   return translate(string, "\", "/");
  906.