home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format 126
/
af126a.adf
/
Football.lzx
/
football
/
user
/
EndOfSeason.rexx
< prev
next >
Wrap
OS/2 REXX Batch file
|
1999-05-22
|
20KB
|
678 lines
/* ***********************************************************************
END OF SEASON PROGRAM FOR FOOTBALL REXX SUITE
-----------------------------------------------
Copyright Mark Naughton 1997
Version Date History
--------------------------------------------------------------------------
1.0 061097 First release - after about 10 days and loads of
hassle and numerous variations in the method for
swapping/deleting teams between divisions.
**************************************************************************
Procedure
---------
1. Check files exist.
2. Read number of divisions and divisions. Then store.
3. Search all leagues/divisions to see if all matches have been played,
if not, then give error and exit.
4. Create all league/division tables and save to temporary files.
5. Display the winner, teams relegated and teams promoted for each
division.
6. Loop. Read teams from division then swap/delete those teams that have
been relegated/promoted between adjoining leagues/divisions. Write to
temporary file when complete. End loop.
7. Loop. Read previous '.df' file and using data from temporary files
created in (6), create '_NewData.df' files for each league/division.
End loop.
8. Display message about '_NewData.df' files.
9. Display final league/division tables.
10.Erase temporary files. Exit.
************************************************************************** */
PARSE ARG league_stuff
version = 1
input_file = '.df'
input2_file = '.sf'
league_file = "Data/" || league_stuff
stored_divs. = '???'
league_title = '*LEAGUE_NAME='
num_divs = '*NUM_DIVISIONS='
divisions = '*DIVISIONS='
releg = '*RELEGATION='
promoted = '*PROMOTED='
not_played = '__ __'
ndivs = 1
divs = ''
promo = 0
relg = 2
separator = '*'
defcts. = '???'
titles. = '???'
names. = '???'
defs. = '???'
div1. = '???'
if exists(league_file || input_file) = 0 then exit
if exists(league_file || input2_file) = 0 then exit
if open(datafile,league_file || input_file,'r') then do
do while ~eof(datafile)
line = readln(datafile)
if pos(num_divs,line) > 0 then ndivs = delstr(line,1,15)
if pos(divisions,line) > 0 then divs = delstr(line,1,11)
end
close(datafile)
end
else do
say
say "ERROR : (EndOfSeason)"
say
say "Unable to open '"league_file || input_file"' file."
exit
end
stored_divs.1 = league_file
do i=2 to ndivs
stored_divs.i = "Data/"||word(divs,i-1)
end
access = "NONE"
do i=1 to ndivs
if open(datafile,stored_divs.i || input2_file,'r') then do
do while ~eof(datafile)
line = readln(datafile)
if pos(not_played,line) > 0 then do
access = stored_divs.i
leave
end
end
close(datafile)
end
if pos("NONE",access) = 0 then do
say "League '"access"' has not finished. Enter the scores then"
say "run this program again to close the season."
exit
end
access = "NONE"
end
/* All matches have been played in the league, so the program continues... */
/* create league tables */
do i=1 to ndivs
call create_table(stored_divs.i)
end
/* print title and winners/losers */
say
say " End Of Season"
say " ---------------"
say
say
defcnt = 0
do i=1 to ndivs
if open(datafile,stored_divs.i || input_file,'r') then do
do while ~eof(datafile)
line = readln(datafile)
if pos(league_title,line) > 0 then title = delstr(line,1,13)
if pos(releg,line) > 0 then relg = delstr(line,1,12)
if pos(promoted,line) > 0 then promo = delstr(line,1,10)
end
close(datafile)
end
else do
say
say "ERROR : (EndOfSeason)"
say
say "Unable to open '"stored_divs.i || input_file"' file."
exit
end
parse var stored_divs.i . "/" name .
a = 0
if open(datafile,"RAM:"||name||".final_table",'r') then do
do while ~eof(datafile)
line = readln(datafile)
a = a + 1
div1.a = line
end
close(datafile)
end
else do
say
say "ERROR : (EndOfSeason)"
say
say "Unable to open 'RAM:"name".final_table' file."
exit
end
say " League : "title
titles.i = title
say
defcnt = defcnt + 1
if i=1 then do
say " Winner : "substr(div1.1,1,35)
defs.defcnt = name" WINR "trim(substr(div1.1,1,35))
end
else do
do b=1 to promo
if b=1 then do
say " Promoted : "substr(div1.b,1,35)
defs.defcnt = name" PROM * "trim(substr(div1.b,1,35))
end
else do
say " "substr(div1.b,1,35)
defs.defcnt = defs.defcnt" * "trim(substr(div1.b,1,35))
end
end
end
defcnt = defcnt + 1
say
start= a - relg /* was start+1 */
do b = start to a
if b = start then do
say " Relegated : "substr(div1.b,1,35)
defs.defcnt = name" RELG * "trim(substr(div1.b,1,35))
end
else do
say " "substr(div1.b,1,35)
defs.defcnt = defs.defcnt" * "trim(substr(div1.b,1,35))
end
end
say
say
end
say " ---------------------"
/* swap/delete teams between divisions, write new files */
do i=1 to ndivs
parse var stored_divs.i . "/" name . /* read teams into memory */
n = 0
if open(datafile,"RAM:"||name||".final_table",'r') then do
do while ~eof(datafile)
line = readln(datafile)
n = n + 1
div1.n = trim(substr(line,1,35))
end
close(datafile)
end
else do
say
say "ERROR : (EndOfSeason)"
say
say "Unable to open 'RAM:"name".final_table' file."
exit
end
b = 0
do a=1 to defcnt
if pos(name,defs.a) = 0 then
iterate
if pos("RELG",defs.a) > 0 then do /* Check for relegation code */
b = a + 1
if pos("PROM",defs.b) = 0 then do
do m=1 to n
if pos(div1.m,defs.a) > 0 then /* delete relegated teams */
div1.m = "Deleted Team"
end
end
else do
do m=1 to n
if pos(div1.m,defs.a) > 0 then /* delete relegated teams... */
div1.m = "Deleted Team"
end
parse var defs.b . "* " names.1 " * " names.2 " * " names.3 " * " names.4 " * " names.5 " * " names.6 " *"
c = 1
if div1.n = '' then
n = n - 1
do while names.c ~='' /* ...then add the newly promoted ones! */
n = n + 1
div1.n = names.c
c = c + 1
end
end
if open(datafile2,"RAM:"word(defs.a,1)".teams",'w') then do
do p=1 to n
if pos("Deleted Team",div1.p) = 0 then /* create teams file in RAM: */
writeln(datafile2,div1.p)
end
close(datafile2)
end
else do
say
say "ERROR : (EndOfSeason)"
say
say "Cannot write to 'RAM:"word(defs.a,1)".teams'."
exit
end
end
else do
if pos("PROM",defs.a) > 0 then do /* Check for promotion code */
b = a - 1
if b=0 then
iterate
if pos("RELG",defs.b) = 0 then do
do m=1 to n
if pos(div1.m,defs.a) > 0 then /* delete promoted teams */
div1.m = "Deleted Team"
end
end
else do
do m=1 to n /* delete promoted teams... */
if pos(div1.m,defs.a) > 0 then
div1.m = "Deleted Team"
end
parse var defs.b . "* " names.1 " * " names.2 " * " names.3 " * " names.4 " * " names.5 " * " names.6 " *"
c = 1
if div1.n = '' then
n = n - 1
do while names.c ~='' /* ...then add the newly relegated ones! */
n = n + 1
div1.n = names.c
c = c + 1
end
end
if open(datafile2,"RAM:"word(defs.a,1)".teams",'w') then do
do p=1 to n
if pos("Deleted Team",div1.p) = 0 then
writeln(datafile2,div1.p)
end
close(datafile2) /* write teams file */
end
else do
say
say "ERROR : (EndOfSeason)"
say
say "Cannot write to 'RAM:"word(defs.a,1)".teams'."
exit
end
end
end
end
end
/* read each league and rewrite 'df' file with new teams */
do i=1 to ndivs
parse var stored_divs.i . "/" name .
if open(datafile2,"Data/"name"_NewData"input_file,'w') then do
if open(datafile,"Data/"name||input_file,'r') then do
do while ~eof(datafile)
line = readln(datafile)
if pos(separator,line) > 0 then
writeln(datafile2,line)
end
close(datafile)
end
else do
say
say "ERROR : (EndOfSeason)"
say
say "Unable to read 'Data/"name||input_file"' file."
exit
end
if open(datafile,"RAM:"name".teams",'r') then do
do while ~eof(datafile)
line = readln(datafile)
writeln(datafile2,line)
end
close(datafile)
end
else do
say
say "ERROR : (EndOfSeason)"
say
say "Unable to read 'RAM:"name".teams'."
exit
end
close(datafile2)
end
else do
say
say "ERROR : (EndOfSeason)"
say
say "Unable to write to 'Data/"name"_NewData"input_file"' file."
exit
end
end
/* display message */
say
say
say " The related Leagues/Divisions have been adjusted and"
say " promotions and relegations have been made. The new "
say " League/Divisions for next season are :"
say
do i=1 to ndivs
parse var stored_divs.i . "/" name .
say " '"name"_NewData"input_file"'"
end
say
say " These files will have to be imported into 'Create League'"
say " and then saved, ideally with a new filename. Since they contain"
say " the right teams, they might be renamed using the year/season"
say " and used as the new '.df' files. Or they can just be used to"
say " import into 'Create League' to create new files completely."
say
say " External script 'DeleteNewDataFiles' can be used to delete/cleanup"
say " these files."
say
say " ---------------------"
/* display final league tables */
say
say
say " Final League Tables"
say " ---------------------"
say
say
do i=1 to ndivs
uline = ''
do c=1 to length(titles.i)
uline = insert('-',uline,c,1)
end
uline = strip(uline)
say " League : "titles.i
say " "uline
say
say " Team Pl Won Drw Lst GoalsF GoalsA Pts GoalDiff"
say "-----------------------------------------------------------------------------------------"
a = 1
parse var stored_divs.i . "/" name .
if open(datafile,"RAM:"||name||".final_table",'r') then do
do while ~eof(datafile)
line = readln(datafile)
if line ~= '' then do
if strip(substr(line,76,5)) = 0 then line=overlay("",line,76,5," ")
if a<10 then do
if a = 1 then line = upper(line)
say " "a") "line
end
else
say a") "line
a = a + 1
end
end
close(datafile)
end
else do
say
say "ERROR : (EndOfSeason)"
say
say "Unable to open 'RAM:"name".final_table' file."
exit
end
say
say
end
say " ---------------------"
say
/* erase all temporary files */
do i=1 to ndivs
parse var stored_divs.i . "/" name .
filen = "RAM:"||name||".final_table"
address command 'delete >NIL: 'filen
filen = "RAM:"||name||".teams"
address command 'delete >NIL: 'filen
end
exit
/* Procedure --------------------------------------------------------- */
create_table : procedure
parse arg league_table
input_file = '.df'
input2_file = '.sf'
not_played = '__ __'
input3_file = '.stats'
output_file = 'Data/League.output'
points_win = '*POINTS_PER_WIN='
points_drw = '*POINTS_PER_DRW='
points_lse = '*POINTS_PER_LSE='
points_gls = '*POINTS_PER_GLS='
team = '*TEAM='
played = '*PLY='
won = '*WIN='
drawn = '*DRW='
lost = '*LST='
goalsf = '*GOF='
goalsa = '*GOA='
points = '*PTS='
separator = '*'
teams. = '???'
teams2. = '???'
m_ply. = '???'
m_win. = '???'
m_drw. = '???'
m_lost. = '???'
m_gof. = '???'
m_goa. = '???'
m_pts. = '???'
ptsgls = 0
ptswin = 2
ptsdrw = 1
ptslse = 0
if exists(league_table || input3_file) = 0 then do
say
say "ERROR : (EndOfSeason)"
say
say "Cannot find '"league_table||input3_file"' for table creation."
exit
end
tcount = 0
if open(datafile,league_table || input_file,'r') then do
do while ~eof(datafile)
line = readln(datafile)
if pos(points_win,line) > 0 then ptswin=delstr(line,1,16)
if pos(points_drw,line) > 0 then ptsdrw=delstr(line,1,16)
if pos(points_lse,line) > 0 then ptslse=delstr(line,1,16)
if pos(points_gls,line) > 0 then ptsgls=delstr(line,1,16)
if pos(separator,line) = 0 then do
line = strip(line)
tcount = tcount + 1
teams.tcount = line
end
end
close(datafile)
end
else do
say
say "ERROR : (EndOfSeason)"
say
say "Unable to open '"league_table || input_file"' file."
exit
end
team_ctr = 0
if open(datafile,league_table || input3_file,'r') then do
do while ~eof(datafile)
line = readln(datafile)
if pos(team,line) > 0 then team_ctr = team_ctr + 1
if pos(played,line) > 0 then m_ply.team_ctr = delstr(line,1,5)
if pos(won,line) > 0 then m_won.team_ctr = delstr(line,1,5)
if pos(drawn,line) > 0 then m_drw.team_ctr = delstr(line,1,5)
if pos(lost,line) > 0 then m_lost.team_ctr = delstr(line,1,5)
if pos(goalsf,line) > 0 then m_gof.team_ctr = delstr(line,1,5)
if pos(goalsa,line) > 0 then m_goa.team_ctr = delstr(line,1,5)
if pos(points,line) > 0 then m_pts.team_ctr = delstr(line,1,5)
end
close(datafile)
end
else do
say
say "ERROR : (EndOfSeason)"
say
say "Unable to open '"league_table || input3_file"'."
exit
end
if open(datafile,league_table || input2_file,'r') then do
do while ~eof(datafile)
line = readln(datafile)
if pos(separator,line) = 0 then do
if pos(not_played,line) = 0 then do
home_team = strip(substr(line,1,30))
goals_for = substr(line,32,2)
goals_aga = substr(line,37,2)
away_team = strip(substr(line,41,30))
do i=1 to tcount
if home_team = teams.i then do
m_ply.i = m_ply.i + 1
m_gof.i = m_gof.i + goals_for
m_goa.i = m_goa.i + goals_aga
if goals_for = goals_aga then do
m_drw.i = m_drw.i + 1
m_pts.i = m_pts.i + ptsdrw
end
if goals_for < goals_aga then do
m_lost.i= m_lost.i + 1
m_pts.i = m_pts.i + ptslse
end
if goals_for > goals_aga then do
m_won.i = m_won.i + 1
m_pts.i = m_pts.i + ptswin
end
m_pts.i = m_pts.i + (goals_for * ptsgls)
end
end
do i=1 to tcount
if away_team = teams.i then do
m_ply.i = m_ply.i + 1
m_gof.i = m_gof.i + goals_aga
m_goa.i = m_goa.i + goals_for
if goals_for = goals_aga then do
m_drw.i = m_drw.i + 1
m_pts.i = m_pts.i + ptsdrw
end
if goals_for < goals_aga then do
m_won.i = m_won.i + 1
m_pts.i = m_pts.i + ptswin
end
if goals_for > goals_aga then do
m_lost.i= m_lost.i + 1
m_pts.i = m_pts.i + ptslse
end
m_pts.i = m_pts.i + (goals_aga * ptsgls)
end
end
end
end
end
close(datafile)
end
else do
say
say "ERROR : (EndOfSeason)"
say
say "Unable to open '"league_table || input2_file"'."
exit
end
if open(outfile,output_file,"w") then do
do i=1 to tcount
line = teams.i
line = insert(" ",line,length(line)+1,30-length(line))
mp = right(m_ply.i,3)
mw = right(m_won.i,3)
md = right(m_drw.i,3)
ml = right(m_lost.i,3)
mgf = right(m_gof.i,5)
mga = right(m_goa.i,5)
mpts = right(m_pts.i,7)
writech(outfile,line" "mp" "mw" "md" "ml" "mgf" "mga" "mpts" ")
itemp=mgf-mga
if itemp>0 then
itemp=insert("+",itemp,0,1)
itemp=right(itemp,4)
writeln(outfile,itemp)
end
close(outfile)
end
else do
say
say "ERROR : (EndOfSeason)"
say
say "Unable to update the League. Cannot write to '"output_file"'."
exit
end
address command 'Exec/footsort '
if open(datafile2,output_file,'r') then do
do i=1 to tcount
line = readln(datafile2)
teams.i = line
teams2.i = line
end
close(datafile2)
end
else do
say
say "ERROR : (EndOfSeason)"
say
say "Cannot read '"output_file"'."
exit
end
ctr = 0
do while swapctr > 0
swapctr=9
do i=1 to tcount-1 /* was 64,4 and 77,4 */
swapdone=0
j = i + 1
if strip(substr(teams.i,64,7)) = strip(substr(teams.j,64,7)) then do
goaldiffa = strip(substr(teams.i,77,5))
goaldiffb = strip(substr(teams.j,77,5))
if goaldiffa < goaldiffb then do
teams.i = teams2.j
teams.j = teams2.i
teams2.i= teams.i
teams2.j= teams.j
swapdone= 1
ctr = ctr + 1
end
end
if swapdone = 1 then
break
end
if ctr = 0 then
swapctr = 0
else
ctr = 0
end
parse var league_table . "/" name .
if open(datafile2,"RAM:"||name||".final_table",'w') then do
do i=1 to tcount
if strip(substr(teams.i,76,5)) = 0 then teams.i=overlay("",teams.i,76,5," ")
writeln(datafile2,teams.i)
end
close(datafile2)
end
else do
say
say "ERROR : (EndOfSeason)"
say
say "Cannot write to 'RAM:"name".final_table'."
exit
end
return
/*******************************************************************************/