home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
euphoria
/
install.ex
< prev
next >
Wrap
Text File
|
1994-03-10
|
13KB
|
463 lines
-----------------------------------
-- Program to Install Euphoria --
-- (see install.doc) --
-----------------------------------
include file.e
include graphics.e
constant KEYBOARD = 0, SCREEN = 1
constant SUCCESS = 1, FAILURE = 0, NO_EDIT = 2
constant TRUE = 1, FALSE = 0
constant CLEAR = 0, NO_CLEAR = 2
-------------------------------------------------
-- Subdirectory structure for Euphoria files. --
-------------------------------------------------
constant file_list = {
{"BIN",
"BIN.DOC", "SYNCOLOR.E", "LINES.BAT", "LINES.EX", "EPRINT.EX",
"EPRINT.BAT", "GREP.BAT", "GREP.EX", "GETNAMES.E", "SHROUD.EX",
"RETAB.EX", "ED.BAT", "ED.EX", "KEYWORDS.E", "SB.BAT",
"WALKDIR.EX", "FREQ.EX", "DOS4GW.EXE", "EX.EXE"},
{"DOC",
"WHAT2DO.DOC", "ED.DOC", "REFMAN.DOC", "C.DOC", "BASIC.DOC",
"REGISTER.DOC", "RELNOTES.DOC", "ORDER.FRM", "INSTALL.DOC"},
{"DEMO",
"DEMO.DOC", "PLOT3D.EX", "DICE.EX", "ANIMAL.EX", "ALLSORTS.EX",
"EXAMPLE.EX", "SB.EX", "SELECT.E", "TTT.EX", "SIMPLE.EX",
"WIRE.EX", "SANITY.EX", "MOUSE.EX", "MSET.EX", "QUEENS.EX", "BUZZ.EX",
"POLYGON.EX", "CALLMACH.EX", "MYDATA.EX"},
{"DEMO\\LEARN",
"LEARN.DOC", "LEARN.EX", "LEARN.DAT"},
{"DEMO\\LANGWAR",
"LW.DOC", "LW.SUM", "WEAPONS.E", "SCREEN.E", "COMMANDS.E", "DAMAGE.E",
"DISPLAY.E", "EMOVE.E", "ENEMY.E", "SCHED.E", "VARS.E", "SOUNDEFF.E",
"LW.EX"},
{"DEMO\\BENCH",
"BENCH.DOC", "SHELL.EX", "SHELL.BAS", "DATABASE.EX", "DATABASE.BAS",
"SIEVE.EX", "SIEVE.BAS", "SEQUENCE.EX", "SEQUENCE.BAS", "FILESORT.EX"},
{"INCLUDE",
"GRAPHICS.E", "SORT.E", "GET.E", "MOUSE.E", "FILE.E", "MACHINE.E"}
}
integer try_move
try_move = sequence(dir("c:\\dos\\move.exe")) -- DOS 6
sequence vc
vc = video_config()
integer color_monitor
color_monitor = vc[VC_COLOR]
procedure the_end()
-- exit install
puts(SCREEN, "\nPress Enter...\n")
if atom(gets(0)) then
end if
abort(1)
end procedure
procedure fore_color(integer c)
-- change foreground color
if color_monitor then
text_color(c)
end if
end procedure
procedure move(sequence source, sequence dest)
-- move one file into a directory
puts(SCREEN, " " & source & '\n')
-- MOVE (DOS 6)
if try_move then
system("move " & source & ' ' & dest & " > NUL", NO_CLEAR)
if sequence(dir(dest & "\\" & source)) then
return
else
puts(SCREEN, "OK - no MOVE command - use COPY instead ...\n")
try_move = FALSE
end if
end if
-- COPY (DOS 5 or earlier)
system("copy " & source & ' ' & dest & " > NUL", NO_CLEAR)
if sequence(dir(dest & "\\" & source)) then
system("del " & source, NO_CLEAR)
else
-- copy failed
puts(SCREEN, "Unable to copy " & source &
" to " & dest & " subdirectory\n")
if sequence(dir(source)) and
( sequence(dir("euphor12.zip")) or
sequence(dir("euph12.zip")) ) then
puts(SCREEN, "Perhaps you can try again without the .zip file\n")
end if
end if
end procedure
procedure moveall()
-- move all files into the correct subdirectories
sequence command
integer f
f = open("bin\\dos4gw.exe", "rb")
if f != -1 then
close(f)
puts(SCREEN, "Subdirectory structure has been set up\n")
return
end if
puts(SCREEN, "Creating Euphoria Subdirectories ...\n\n")
for i = 1 to length(file_list) do
command = "mkdir " & file_list[i][1]
puts(SCREEN, command & '\n')
system(command, NO_CLEAR)
for j = 2 to length(file_list[i]) do
move(file_list[i][j], file_list[i][1])
end for
end for
system("del unzip.doc", NO_CLEAR) -- not needed anymore
end procedure
function setupdir()
-- set up subdirectories
moveall()
if atom(dir("BIN\\EX.EXE")) then
puts(SCREEN, "Subdirectory set up failed - see install.doc\n")
return FAILURE
end if
return SUCCESS
end function
function upper(sequence s)
-- convert to upper case
for i = 1 to length(s) do
if s[i] >= 'a' and s[i] <= 'z' then
s[i] = s[i] - 'a' + 'A'
end if
end for
return s
end function
procedure rename_it()
puts(SCREEN,
"Please remove it or rename it before installing a new version.\n")
end procedure
function copy_to_hard_disk(integer drive)
-- copy Euphoria files to EUPHORIA directory
sequence eu_dir, rename_dir
integer rename_letter
eu_dir = drive & ":\\EUPHORIA"
if compare(upper(current_dir()), eu_dir) = 0 then
-- we're in EUPHORIA directory already - just set up subdirectories
return setupdir()
end if
if sequence(dir(eu_dir)) then
puts(SCREEN,
"An existing EUPHORIA directory was found on drive " & drive & ".\n")
if try_move then
rename_letter = 'F'
while rename_letter <= 'Z' do
rename_dir = drive & ":\\" & rename_letter & "UPHORIA"
if atom(dir(rename_dir)) then
exit
end if
rename_letter = rename_letter + 1
end while
if rename_letter <= 'Z' then
system("move " & eu_dir & ' ' & rename_dir & "> NUL", NO_CLEAR)
if sequence(dir(rename_dir)) then
puts(SCREEN,"It has been renamed as " & rename_dir & "\n\n")
else
rename_it()
return FAILURE
end if
else
rename_it()
return FAILURE
end if
else
rename_it()
return FAILURE
end if
end if
puts(SCREEN, "The EUPHORIA files will now be copied to " & eu_dir & '\n')
puts(SCREEN, " * Press Enter to start copying. [recommended action]\n")
puts(SCREEN, " * or type ! to abort.\n")
if find('!', gets(KEYBOARD)) then
puts(SCREEN, "\ninstallation aborted - try again later\n")
the_end()
end if
system("mkdir " & eu_dir, NO_CLEAR)
if atom(dir(eu_dir)) then
puts(SCREEN, "\n\nCouldn't create " & eu_dir & ".\n")
puts(SCREEN, "See install.doc\n")
return FAILURE
end if
-- copy all files to EUPHORIA directory
system("xcopy *.* " & eu_dir, CLEAR)
if atom(dir(eu_dir & "\\EX.EXE")) then
puts(SCREEN, "copy failed - see install.doc\n")
return FAILURE
end if
-- copy worked, now cd to EUPHORIA
system(drive & ':', NO_CLEAR)
system("cd " & eu_dir, NO_CLEAR)
if compare(upper(current_dir()), eu_dir) != 0 then
puts(SCREEN, "cd failed - see install.doc\n")
return FAILURE
end if
-- cd worked, now set up subdirectories
return setupdir()
end function
constant MAX_PATH = 127 - length("C:\\EUPHORIA\\BIN; ")
function edit_auto_exec(integer drive)
-- edit the autoexec.bat file
-- add to the PATH, set EUDIR
integer path_found, q, auto_exec_no, p, white, semi_pos
sequence path, auto_exec, auto_name, base_name, answer, set_line
object line
path = getenv("PATH")
if sequence(path) then
if match("EUPHORIA\\BIN", path) then
puts(SCREEN, "\nYour current PATH already has EUPHORIA\\BIN\n")
return NO_EDIT
end if
if length(path) >= MAX_PATH then
puts(SCREEN, "\nYour current PATH is too long to add EUPHORIA\\BIN\n")
puts(SCREEN, "Perhaps you can remove a directory from it.\n")
return FAILURE
end if
end if
puts(SCREEN, "\n\nEditing autoexec.bat ...\n")
base_name = ":\\autoexec.bat"
auto_name = "C" & base_name -- try C first
auto_exec_no = open(auto_name, "r")
while auto_exec_no = -1 do
puts(SCREEN, "Couldn't open " & auto_name & '\n')
puts(SCREEN, "On what drive is your autoexec.bat file?\n")
puts(SCREEN, "Type a letter: (! to abort)\n")
answer = gets(KEYBOARD)
if find('!', answer) then
puts(SCREEN, "\ninstallation aborted - see install.doc Part B\n")
the_end()
end if
auto_name = answer[1] & base_name
auto_exec_no = open(auto_name, "r")
end while
-- read in the entire autoexec.bat
auto_exec = {}
path_found = 0
while TRUE do
line = gets(auto_exec_no)
if atom(line) then
exit
end if
p = match("PATH", upper(line))
if p then
-- line contains the word "PATH" in upper or lower case
-- at position p
white = TRUE
q = p - 1
while q >= 1 do
if not find(line[q], " \t") then
-- non whitespace - only "SET" is allowed
if q >= 3 then
if compare("SET", upper(line[q-2..q])) = 0 then
q = q - 2
else
white = FALSE
exit
end if
else
white = FALSE
exit
end if
end if
q = q - 1
end while
if white and find(line[p+4], " \t=") then
-- this is a PATH line
path_found = path_found + 1
if path_found = 1 then
-- only change the first one encountered
set_line = "SET EUDIR=" & drive & ":\\EUPHORIA\n"
auto_exec = append(auto_exec, set_line)
if match(drive & ":\\EUPHORIA\\BIN", upper(line)) then
-- its already there
puts(SCREEN, "PATH already has " & drive &
":\\EUPHORIA\\BIN\n")
close(auto_exec_no)
return NO_EDIT
end if
if length(line) > MAX_PATH then
-- line is too long (MS-DOS restriction)
puts(SCREEN,
"Your PATH line is too long to add EUPHORIA\\BIN\n")
puts(SCREEN,
"Perhaps you can delete a directory from it.\n")
puts(SCREEN,
"No changes were made to your autoexec.bat file.\n")
close(auto_exec_no)
return FAILURE
end if
semi_pos = find(';', line)
if semi_pos = 0 then
semi_pos = length(line)
line = line[1..length(line)-1] & ";\n"
end if
-- add EUPHORIA\BIN to path
puts(SCREEN, "Changing this line:\n")
fore_color(2)
puts(SCREEN, line)
fore_color(7)
puts(SCREEN, "to:\n")
fore_color(2)
puts(SCREEN, line[1..semi_pos])
fore_color(4)
puts(SCREEN, drive & ":\\EUPHORIA\\BIN;")
fore_color(2)
puts(SCREEN, line[semi_pos+1..length(line)])
line = line[1..semi_pos] &
drive & ":\\EUPHORIA\\BIN;" &
line[semi_pos+1..length(line)]
fore_color(7)
puts(SCREEN, "and inserting the following line:\n")
fore_color(4)
puts(SCREEN, set_line)
fore_color(7)
end if
end if
end if
auto_exec = append(auto_exec, line)
end while
close(auto_exec_no)
if not path_found then
puts(SCREEN, "The PATH command could not be found.\n")
puts(SCREEN, "No changes were made to your autoexec.bat.\n")
return FAILURE
else
-- write out the new autoexec.bat
puts(SCREEN,
"Is it OK to make these changes to your autoexec.bat file? (y or n) \n")
puts(SCREEN, "-----> ")
answer = upper(gets(KEYBOARD))
puts(SCREEN, '\n')
if not find('Y', answer) then
return FAILURE
end if
if path_found = 2 then
puts(SCREEN, "One other \"PATH\" line was found but not changed.\n")
puts(SCREEN, "Please take a look at it.\n")
elsif path_found > 2 then
printf(SCREEN, "%d other \"PATH\" lines were found but not changed.\n",
path_found - 1)
puts(SCREEN, "Please take a look at them.\n")
end if
auto_exec_no = open(auto_name, "w")
if auto_exec_no = -1 then
puts(SCREEN, "Couldn't write out the new autoexec.bat!\n")
puts(SCREEN, "Your autoexec.bat file is read-only.\n")
return FAILURE
end if
for i = 1 to length(auto_exec) do
puts(auto_exec_no, auto_exec[i])
end for
close(auto_exec_no)
end if
return SUCCESS
end function
procedure install()
-- main routine for Euphoria installation
integer drive
integer edit_status
sequence answer
clear_screen()
fore_color(5)
puts(SCREEN, "\nEuphoria")
fore_color(7)
puts(SCREEN, " Installation Program\n\n")
if atom(dir("DOS4GW.EXE")) then
puts(SCREEN,
"All files must be together in one directory to run install.\n")
return
end if
puts(SCREEN, "On which drive do you want to put the EUPHORIA directory?\n")
puts(SCREEN, "Type the drive letter, or just hit Enter for drive C\n")
puts(SCREEN, "-----> ")
answer = upper(gets(KEYBOARD))
while answer[1] = ' ' or answer[1] = '\t' do
answer = answer[2..length(answer)]
end while
drive = answer[1]
if drive < 'A' or drive > 'Z' then
drive = 'C'
end if
puts(SCREEN, '\n')
if copy_to_hard_disk(drive) = FAILURE then
return
end if
edit_status = edit_auto_exec(drive)
if edit_status = FAILURE then
puts(SCREEN,
"To complete the install you should edit autoexec.bat manually.\n")
puts(SCREEN, "See doc\\install.doc - Manual Procedure Part B\n")
return
end if
puts(SCREEN, "\nInstall Completed.\n")
if edit_status = NO_EDIT then
puts(SCREEN,
"You might start by looking at readme.doc or doc\\what2do.doc\n")
else
puts(SCREEN, "After pressing Enter, you should exit Windows, ")
puts(SCREEN, "remove any floppy disks,\nthen press Control-Alt-Delete")
puts(SCREEN, " to reboot your machine. ")
puts(SCREEN, "This will set\nyour PATH and EUDIR variables.\n\n")
puts(SCREEN, "When the system is back up you might start\n")
puts(SCREEN, "by looking at readme.doc or doc\\what2do.doc.\n")
puts(SCREEN,
"The Euphoria editor, ed, will be available - see doc\\ed.doc.\n")
end if
puts(SCREEN, "\n\t\tEnjoy!\n")
end procedure
install()
the_end()