home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / euphoria / install.ex < prev    next >
Text File  |  1994-03-10  |  13KB  |  463 lines

  1.         -----------------------------------
  2.         --  Program to Install Euphoria  --
  3.         --  (see install.doc)            --
  4.         -----------------------------------
  5.  
  6. include file.e
  7. include graphics.e
  8.  
  9. constant KEYBOARD = 0, SCREEN = 1
  10. constant SUCCESS = 1, FAILURE = 0, NO_EDIT = 2
  11. constant TRUE = 1, FALSE = 0
  12. constant CLEAR = 0, NO_CLEAR = 2
  13.  
  14.     -------------------------------------------------
  15.     -- Subdirectory structure for Euphoria files.  --
  16.     -------------------------------------------------
  17.  
  18. constant file_list = {
  19.   {"BIN", 
  20.    "BIN.DOC", "SYNCOLOR.E", "LINES.BAT", "LINES.EX", "EPRINT.EX",   
  21.    "EPRINT.BAT", "GREP.BAT", "GREP.EX", "GETNAMES.E", "SHROUD.EX",  
  22.    "RETAB.EX", "ED.BAT", "ED.EX", "KEYWORDS.E", "SB.BAT", 
  23.    "WALKDIR.EX", "FREQ.EX", "DOS4GW.EXE", "EX.EXE"},
  24.   
  25.   {"DOC", 
  26.    "WHAT2DO.DOC", "ED.DOC", "REFMAN.DOC", "C.DOC", "BASIC.DOC", 
  27.    "REGISTER.DOC", "RELNOTES.DOC", "ORDER.FRM", "INSTALL.DOC"},
  28.  
  29.   {"DEMO",
  30.    "DEMO.DOC", "PLOT3D.EX", "DICE.EX", "ANIMAL.EX", "ALLSORTS.EX",  
  31.    "EXAMPLE.EX", "SB.EX", "SELECT.E", "TTT.EX", "SIMPLE.EX", 
  32.    "WIRE.EX", "SANITY.EX", "MOUSE.EX", "MSET.EX", "QUEENS.EX", "BUZZ.EX",
  33.    "POLYGON.EX", "CALLMACH.EX", "MYDATA.EX"},
  34.  
  35.   {"DEMO\\LEARN", 
  36.    "LEARN.DOC", "LEARN.EX", "LEARN.DAT"},
  37.  
  38.   {"DEMO\\LANGWAR", 
  39.    "LW.DOC", "LW.SUM", "WEAPONS.E", "SCREEN.E", "COMMANDS.E", "DAMAGE.E",  
  40.    "DISPLAY.E", "EMOVE.E", "ENEMY.E", "SCHED.E", "VARS.E", "SOUNDEFF.E",  
  41.    "LW.EX"},   
  42.  
  43.   {"DEMO\\BENCH", 
  44.    "BENCH.DOC", "SHELL.EX", "SHELL.BAS", "DATABASE.EX", "DATABASE.BAS", 
  45.    "SIEVE.EX", "SIEVE.BAS", "SEQUENCE.EX", "SEQUENCE.BAS", "FILESORT.EX"},   
  46.   
  47.   {"INCLUDE", 
  48.    "GRAPHICS.E", "SORT.E", "GET.E", "MOUSE.E", "FILE.E", "MACHINE.E"}  
  49. }
  50.  
  51. integer try_move
  52. try_move = sequence(dir("c:\\dos\\move.exe")) -- DOS 6
  53.  
  54. sequence vc
  55. vc = video_config()
  56.  
  57. integer color_monitor
  58. color_monitor = vc[VC_COLOR]
  59.  
  60. procedure the_end()
  61. -- exit install
  62.     puts(SCREEN, "\nPress Enter...\n")
  63.     if atom(gets(0)) then
  64.     end if
  65.     abort(1)
  66. end procedure
  67.  
  68. procedure fore_color(integer c)
  69. -- change foreground color
  70.     if color_monitor then
  71.     text_color(c)
  72.     end if
  73. end procedure
  74.  
  75. procedure move(sequence source, sequence dest)
  76. -- move one file into a directory
  77.  
  78.     puts(SCREEN, "    " & source & '\n')
  79.  
  80.     -- MOVE (DOS 6)
  81.     if try_move then
  82.     system("move " & source & ' ' & dest & " > NUL", NO_CLEAR)
  83.     if sequence(dir(dest & "\\" & source)) then
  84.         return
  85.     else
  86.         puts(SCREEN, "OK - no MOVE command - use COPY instead ...\n")
  87.         try_move = FALSE
  88.     end if
  89.     end if
  90.  
  91.     -- COPY (DOS 5 or earlier)
  92.     system("copy " & source & ' ' & dest & " > NUL", NO_CLEAR)
  93.     if sequence(dir(dest & "\\" & source)) then
  94.     system("del " & source, NO_CLEAR)
  95.     else
  96.     -- copy failed
  97.     puts(SCREEN, "Unable to copy " & source & 
  98.              " to " & dest & " subdirectory\n")
  99.     if sequence(dir(source)) and 
  100.        ( sequence(dir("euphor12.zip")) or 
  101.          sequence(dir("euph12.zip")) ) then
  102.         puts(SCREEN, "Perhaps you can try again without the .zip file\n")
  103.     end if
  104.     end if
  105. end procedure
  106.  
  107. procedure moveall()
  108. -- move all files into the correct subdirectories
  109.     sequence command
  110.     integer f
  111.  
  112.     f = open("bin\\dos4gw.exe", "rb")
  113.     if f != -1 then
  114.     close(f)
  115.     puts(SCREEN, "Subdirectory structure has been set up\n")
  116.     return
  117.     end if
  118.     puts(SCREEN, "Creating Euphoria Subdirectories ...\n\n")
  119.     for i = 1 to length(file_list) do
  120.     command = "mkdir " & file_list[i][1]
  121.     puts(SCREEN, command & '\n')
  122.     system(command, NO_CLEAR) 
  123.     for j = 2 to length(file_list[i]) do
  124.         move(file_list[i][j], file_list[i][1])
  125.     end for
  126.     end for
  127.     system("del unzip.doc", NO_CLEAR) -- not needed anymore
  128. end procedure
  129.  
  130. function setupdir()
  131. -- set up subdirectories 
  132.     moveall()
  133.     if atom(dir("BIN\\EX.EXE")) then
  134.     puts(SCREEN, "Subdirectory set up failed - see install.doc\n")
  135.     return FAILURE
  136.     end if
  137.     return SUCCESS
  138. end function
  139.  
  140. function upper(sequence s)
  141. -- convert to upper case
  142.     for i = 1 to length(s) do
  143.     if s[i] >= 'a' and s[i] <= 'z' then
  144.         s[i] = s[i] - 'a' + 'A'
  145.     end if
  146.     end for
  147.     return s
  148. end function
  149.  
  150. procedure rename_it()
  151.     puts(SCREEN, 
  152.          "Please remove it or rename it before installing a new version.\n")
  153. end procedure
  154.  
  155. function copy_to_hard_disk(integer drive)
  156. -- copy Euphoria files to EUPHORIA directory 
  157.     sequence eu_dir, rename_dir
  158.     integer rename_letter
  159.  
  160.     eu_dir = drive & ":\\EUPHORIA"
  161.  
  162.     if compare(upper(current_dir()), eu_dir) = 0 then
  163.     -- we're in EUPHORIA directory already - just set up subdirectories
  164.     return setupdir() 
  165.     end if
  166.     
  167.     if sequence(dir(eu_dir)) then
  168.     puts(SCREEN,
  169.     "An existing EUPHORIA directory was found on drive " & drive & ".\n")
  170.     if try_move then
  171.         rename_letter = 'F'
  172.         while rename_letter <= 'Z' do
  173.         rename_dir = drive & ":\\" & rename_letter & "UPHORIA"
  174.         if atom(dir(rename_dir)) then
  175.             exit
  176.         end if
  177.         rename_letter = rename_letter + 1
  178.         end while
  179.         if rename_letter <= 'Z' then
  180.         system("move " & eu_dir & ' ' & rename_dir & "> NUL", NO_CLEAR)
  181.         if sequence(dir(rename_dir)) then
  182.             puts(SCREEN,"It has been renamed as " & rename_dir & "\n\n")
  183.         else
  184.             rename_it()
  185.             return FAILURE
  186.         end if
  187.         else
  188.         rename_it()
  189.         return FAILURE
  190.         end if
  191.     else
  192.         rename_it()
  193.         return FAILURE
  194.     end if
  195.     end if
  196.     
  197.     puts(SCREEN, "The EUPHORIA files will now be copied to " & eu_dir & '\n')
  198.     puts(SCREEN, "    * Press Enter to start copying. [recommended action]\n")
  199.     puts(SCREEN, "    * or type ! to abort.\n")
  200.     
  201.     if find('!', gets(KEYBOARD)) then
  202.     puts(SCREEN, "\ninstallation aborted - try again later\n")
  203.     the_end()
  204.     end if
  205.     
  206.     system("mkdir " & eu_dir, NO_CLEAR)
  207.     if atom(dir(eu_dir)) then
  208.     puts(SCREEN, "\n\nCouldn't create " & eu_dir & ".\n")
  209.     puts(SCREEN, "See install.doc\n")
  210.     return FAILURE
  211.     end if
  212.     
  213.     -- copy all files to EUPHORIA directory
  214.     system("xcopy *.* " & eu_dir, CLEAR)
  215.     if atom(dir(eu_dir & "\\EX.EXE")) then
  216.     puts(SCREEN, "copy failed - see install.doc\n")
  217.     return FAILURE
  218.     end if
  219.     
  220.     -- copy worked, now cd to EUPHORIA
  221.     system(drive & ':', NO_CLEAR)
  222.     system("cd " & eu_dir, NO_CLEAR)
  223.     if compare(upper(current_dir()), eu_dir) != 0 then
  224.     puts(SCREEN, "cd failed - see install.doc\n")
  225.     return FAILURE
  226.     end if
  227.     
  228.     -- cd worked, now set up subdirectories
  229.     return setupdir() 
  230.  
  231. end function
  232.  
  233. constant MAX_PATH = 127 - length("C:\\EUPHORIA\\BIN; ")
  234.  
  235. function edit_auto_exec(integer drive)
  236. -- edit the autoexec.bat file
  237. -- add to the PATH, set EUDIR
  238.     integer path_found, q, auto_exec_no, p, white, semi_pos
  239.     sequence path, auto_exec, auto_name, base_name, answer, set_line
  240.     object line
  241.  
  242.     path = getenv("PATH")
  243.     if sequence(path) then
  244.     if match("EUPHORIA\\BIN", path) then
  245.         puts(SCREEN, "\nYour current PATH already has EUPHORIA\\BIN\n")
  246.         return NO_EDIT
  247.     end if
  248.     if length(path) >= MAX_PATH then
  249.         puts(SCREEN, "\nYour current PATH is too long to add EUPHORIA\\BIN\n")
  250.         puts(SCREEN, "Perhaps you can remove a directory from it.\n")
  251.         return FAILURE
  252.     end if
  253.     end if
  254.     puts(SCREEN, "\n\nEditing autoexec.bat ...\n")
  255.     base_name = ":\\autoexec.bat"
  256.     auto_name = "C" & base_name  -- try C first
  257.     auto_exec_no = open(auto_name, "r")
  258.     while auto_exec_no = -1 do
  259.     puts(SCREEN, "Couldn't open " & auto_name & '\n')
  260.     puts(SCREEN, "On what drive is your autoexec.bat file?\n")
  261.     puts(SCREEN, "Type a letter: (! to abort)\n")
  262.     answer = gets(KEYBOARD)
  263.     if find('!', answer) then
  264.         puts(SCREEN, "\ninstallation aborted - see install.doc Part B\n")
  265.         the_end()
  266.     end if
  267.     auto_name = answer[1] & base_name
  268.     auto_exec_no = open(auto_name, "r")
  269.     end while
  270.     -- read in the entire autoexec.bat
  271.     auto_exec = {}
  272.     path_found = 0
  273.     while TRUE do
  274.     line = gets(auto_exec_no)
  275.     if atom(line) then
  276.         exit
  277.     end if
  278.     p = match("PATH", upper(line))
  279.     if p then
  280.         -- line contains the word "PATH" in upper or lower case
  281.         -- at position p
  282.         white = TRUE
  283.         q = p - 1
  284.         while q >= 1 do
  285.         if not find(line[q], " \t") then
  286.             -- non whitespace - only "SET" is allowed
  287.             if q >= 3 then
  288.             if compare("SET", upper(line[q-2..q])) = 0 then
  289.                 q = q - 2
  290.             else
  291.                 white = FALSE
  292.                 exit
  293.             end if
  294.             else
  295.             white = FALSE
  296.             exit
  297.             end if
  298.         end if
  299.         q = q - 1
  300.         end while
  301.        
  302.         if white and find(line[p+4], " \t=") then
  303.         -- this is a PATH line
  304.         path_found = path_found + 1
  305.         if path_found = 1 then
  306.             -- only change the first one encountered
  307.             set_line = "SET EUDIR=" & drive & ":\\EUPHORIA\n"
  308.             auto_exec = append(auto_exec, set_line)
  309.             if match(drive & ":\\EUPHORIA\\BIN", upper(line)) then
  310.             -- its already there
  311.             puts(SCREEN, "PATH already has " & drive & 
  312.                      ":\\EUPHORIA\\BIN\n")
  313.             close(auto_exec_no)
  314.             return NO_EDIT
  315.             end if
  316.             if length(line) > MAX_PATH then
  317.             -- line is too long (MS-DOS restriction)
  318.             puts(SCREEN, 
  319.             "Your PATH line is too long to add EUPHORIA\\BIN\n")
  320.             puts(SCREEN, 
  321.             "Perhaps you can delete a directory from it.\n")
  322.             puts(SCREEN, 
  323.             "No changes were made to your autoexec.bat file.\n")
  324.             close(auto_exec_no)
  325.             return FAILURE
  326.             end if
  327.             semi_pos = find(';', line)
  328.             if semi_pos = 0 then
  329.             semi_pos = length(line)
  330.             line = line[1..length(line)-1] & ";\n"
  331.             end if
  332.             -- add EUPHORIA\BIN to path
  333.             puts(SCREEN, "Changing this line:\n")
  334.             fore_color(2)
  335.             puts(SCREEN, line)
  336.             fore_color(7)
  337.             puts(SCREEN, "to:\n")
  338.             fore_color(2)
  339.             puts(SCREEN, line[1..semi_pos])
  340.             fore_color(4)
  341.             puts(SCREEN, drive & ":\\EUPHORIA\\BIN;")
  342.             fore_color(2)
  343.             puts(SCREEN, line[semi_pos+1..length(line)])
  344.             line = line[1..semi_pos] &
  345.                drive & ":\\EUPHORIA\\BIN;" &
  346.                line[semi_pos+1..length(line)]
  347.             fore_color(7)
  348.             puts(SCREEN, "and inserting the following line:\n")
  349.             fore_color(4)
  350.             puts(SCREEN, set_line)
  351.             fore_color(7)
  352.         end if
  353.         end if
  354.     end if
  355.     auto_exec = append(auto_exec, line)
  356.     end while
  357.     close(auto_exec_no)
  358.  
  359.     if not path_found then
  360.     puts(SCREEN, "The PATH command could not be found.\n")
  361.     puts(SCREEN, "No changes were made to your autoexec.bat.\n")
  362.     return FAILURE
  363.     else
  364.     -- write out the new autoexec.bat
  365.     puts(SCREEN, 
  366.     "Is it OK to make these changes to your autoexec.bat file? (y or n) \n")
  367.     puts(SCREEN, "-----> ") 
  368.     answer = upper(gets(KEYBOARD))
  369.     puts(SCREEN, '\n')
  370.     if not find('Y', answer) then
  371.         return FAILURE
  372.     end if
  373.     if path_found = 2 then
  374.         puts(SCREEN, "One other \"PATH\" line was found but not changed.\n") 
  375.         puts(SCREEN, "Please take a look at it.\n")
  376.     elsif path_found > 2 then
  377.         printf(SCREEN, "%d other \"PATH\" lines were found but not changed.\n",
  378.         path_found - 1)
  379.         puts(SCREEN, "Please take a look at them.\n")
  380.     end if
  381.     auto_exec_no = open(auto_name, "w")
  382.     if auto_exec_no = -1 then
  383.         puts(SCREEN, "Couldn't write out the new autoexec.bat!\n")
  384.         puts(SCREEN, "Your autoexec.bat file is read-only.\n")
  385.         return FAILURE
  386.     end if
  387.     for i = 1  to length(auto_exec) do
  388.         puts(auto_exec_no, auto_exec[i])
  389.     end for
  390.     close(auto_exec_no)
  391.     end if
  392.     return SUCCESS
  393. end function
  394.  
  395. procedure install()
  396. -- main routine for Euphoria installation
  397.     integer drive
  398.     integer edit_status
  399.     sequence answer
  400.     
  401.     clear_screen()
  402.     fore_color(5)
  403.     puts(SCREEN, "\nEuphoria")
  404.     fore_color(7)
  405.     puts(SCREEN, " Installation Program\n\n")
  406.     
  407.     if atom(dir("DOS4GW.EXE")) then
  408.     puts(SCREEN, 
  409.     "All files must be together in one directory to run install.\n")
  410.     return
  411.     end if
  412.  
  413.     puts(SCREEN, "On which drive do you want to put the EUPHORIA directory?\n")
  414.     puts(SCREEN, "Type the drive letter, or just hit Enter for drive C\n")
  415.     puts(SCREEN, "-----> ")
  416.     
  417.     answer = upper(gets(KEYBOARD))
  418.     
  419.     while answer[1] = ' ' or answer[1] = '\t' do
  420.     answer = answer[2..length(answer)]
  421.     end while
  422.  
  423.     drive = answer[1]
  424.     if drive < 'A' or drive > 'Z' then
  425.     drive = 'C'
  426.     end if
  427.  
  428.     puts(SCREEN, '\n')
  429.  
  430.     if copy_to_hard_disk(drive) = FAILURE then
  431.     return
  432.     end if
  433.  
  434.     edit_status = edit_auto_exec(drive)
  435.  
  436.     if edit_status = FAILURE then
  437.     puts(SCREEN, 
  438.     "To complete the install you should edit autoexec.bat manually.\n") 
  439.     puts(SCREEN, "See doc\\install.doc - Manual Procedure Part B\n")
  440.     return
  441.     end if
  442.  
  443.     puts(SCREEN, "\nInstall Completed.\n")
  444.     if edit_status = NO_EDIT then
  445.     puts(SCREEN, 
  446.     "You might start by looking at readme.doc or doc\\what2do.doc\n")
  447.     else
  448.     puts(SCREEN, "After pressing Enter, you should exit Windows, ")
  449.     puts(SCREEN, "remove any floppy disks,\nthen press Control-Alt-Delete")
  450.     puts(SCREEN, " to reboot your machine. ")
  451.     puts(SCREEN, "This will set\nyour PATH and EUDIR variables.\n\n")
  452.     puts(SCREEN, "When the system is back up you might start\n")  
  453.     puts(SCREEN, "by looking at readme.doc or doc\\what2do.doc.\n")
  454.     puts(SCREEN, 
  455.     "The Euphoria editor, ed, will be available - see doc\\ed.doc.\n")
  456.     end if
  457.     puts(SCREEN, "\n\t\tEnjoy!\n")
  458. end procedure
  459.  
  460. install()
  461. the_end()
  462.  
  463.