/* Mode=Run */ /* *********************************************************************** 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. 250899 Added error msg to file checks. 110999 Converted to use locale. Some error messages, before reading the locale, will still be in English. 190999 Added support for subdirectories in "Data/". 220500 End of season didn't quite work for the new directories as reported by Kevin Lambert - thanks mate - bug fixed. ************************************************************************** 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' 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. = '???' subdir = '##NONE' if pos("/",league_stuff) > 0 then parse var league_stuff subdir "/" . league_file = "Data/" || league_stuff if open(datafile,"Data/Football.locale",'r') then do line = readln(datafile) locdir = strip(line) close(datafile) end else do say say "ERROR : (EndOfSeason)" say say "Cannot read 'Data/Football.locale' for the locale settings." exit end locdir = locdir"User/EndOfSeason.data" if open(datafile,"ENV:FootballRXPath",'r') then do line = readln(datafile) rxdir = strip(line) close(datafile) end else rxdir = "SYS:Rexxc/" if exists(locdir) > 0 then do address command rxdir'rx 'locdir VarCount = getclip('VarCount') do i = 1 to VarCount interpret getclip('var.'i) end end else do say say "ERROR : (EndOfSeason)" say say "Cannot find '"locdir"' to read locale settings." exit end if exists(league_file || input_file) = 0 then do say say eos_error say say eos_t1"'"league_file || input_file"'." exit end if exists(league_file || input2_file) = 0 then do say say eos_error say say eos_t1"'"league_file || input2_file"'." exit end 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 eos_error say say eos_t2"'"league_file || input_file"'." exit end stored_divs.1 = league_file do i=2 to ndivs if exists("Data/"word(divs,i-1)||input_file) = 0 then stored_divs.i = "Data/"subdir"/"word(divs,i-1) else 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 eos_t7" '"access"' "eos_t11 say eos_t12 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 " "eos_t13 say " "eos_t14 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 eos_error say say eos_t2"'"stored_divs.i || input_file"'." exit end if pos(subdir,stored_divs.i) > 0 then parse var stored_divs.i "Data/" . "/" name . else parse var stored_divs.i . "/" name . if pos("/",name) > 0 then do parse var name . "/" name2 name = name2 end 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 eos_error say say eos_t2"'RAM:"name".final_table'." exit end say " "left(eos_t7,10," ")": "title titles.i = title say defcnt = defcnt + 1 if i=1 then do say " "left(eos_t8,10," ")": "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 " "left(eos_t9,10," ")": "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 div1.b ~= "" then do if b = start then do say " "left(eos_t10,10," ")": "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 end say say end say " ---------------------" /* swap/delete teams between divisions, write new files */ do i=1 to ndivs if pos(subdir,stored_divs.i) > 0 then parse var stored_divs.i "Data/" . "/" name . else parse var stored_divs.i . "/" name . if pos("/",name) > 0 then do parse var name . "/" name2 name = name2 end /* 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 eos_error say say eos_t2"'RAM:"name".final_table'." 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 eos_error say say eos_t2"'RAM:"word(defs.a,1)".teams'"eos_t4 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 eos_error say say eos_t2"'RAM:"word(defs.a,1)".teams'"eos_t4 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 . */ name = stored_divs.i if open(datafile2,name"_NewData"input_file,'w') then do if open(datafile,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 eos_error say say eos_t2"'"name||input_file"'"eos_t3 exit end if pos(subdir,stored_divs.i) > 0 then parse var stored_divs.i "Data/" . "/" name . else parse var stored_divs.i . "/" name . if pos("/",name) > 0 then do parse var name . "/" name2 name = name2 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 eos_error say say eos_t2"'RAM:"name".teams'"eos_t3 exit end close(datafile2) end else do say say eos_error say say eos_t2"'"name"_NewData"input_file"'"eos_t4 exit end end /* display message */ say say say " "eos_t15 say " "eos_t16 say " "eos_t17 say do i=1 to ndivs parse var stored_divs.i "Data/" name . say " '"name"_NewData"input_file"'" end say say " "eos_t18 say " "eos_t19 say " "eos_t20 say " "eos_t21 say " "eos_t22 say say " "eos_t23 say " "eos_t24 say say " ---------------------" /* display final league tables */ say say say " "eos_t25 say " "eos_t26 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 " "left(eos_t7,9," ")": "titles.i say " "uline say say eos_t27 say "-----------------------------------------------------------------------------------------" a = 1 /* parse var stored_divs.i . "/" name . */ if pos(subdir,stored_divs.i) > 0 then parse var stored_divs.i "Data/" . "/" name . else parse var stored_divs.i . "/" name . if pos("/",name) > 0 then do parse var name . "/" name2 name = name2 end 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 eos_error say say eos_t2"'RAM:"name".final_table'"eos_t3 exit end say say end say " ---------------------" say /* erase all temporary files */ do i=1 to ndivs /* parse var stored_divs.i . "/" name . */ if pos(subdir,stored_divs.i) > 0 then parse var stored_divs.i "Data/" . "/" name . else parse var stored_divs.i . "/" name . if pos("/",name) > 0 then do parse var name . "/" name2 name = name2 end filen = "RAM:"||name||".final_table" address command 'delete >NIL: 'filen filen = "RAM:"||name||".teams" address command 'delete >NIL: 'filen end exit /* Procedure --------------------------------------------------------- */ create_table : parse arg league_table2 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 league_table = league_table2 if exists(league_table || input3_file) = 0 then do say say eos_error say say eos_t2"'"league_table||input3_file"' "eos_t5 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 eos_error say say eos_t2"'"league_table || input_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 eos_error say say eos_t2"'"league_table || input3_file"'"eos_t3 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 ik=1 to tcount if home_team = teams.ik then do m_ply.ik = m_ply.ik + 1 m_gof.ik = m_gof.ik + goals_for m_goa.ik = m_goa.ik + goals_aga if goals_for = goals_aga then do m_drw.ik = m_drw.ik + 1 m_pts.ik = m_pts.ik + ptsdrw end if goals_for < goals_aga then do m_lost.ik= m_lost.ik + 1 m_pts.ik = m_pts.ik + ptslse end if goals_for > goals_aga then do m_won.ik = m_won.ik + 1 m_pts.ik = m_pts.ik + ptswin end m_pts.ik = m_pts.ik + (goals_for * ptsgls) end end do ik=1 to tcount if away_team = teams.ik then do m_ply.ik = m_ply.ik + 1 m_gof.ik = m_gof.ik + goals_aga m_goa.ik = m_goa.ik + goals_for if goals_for = goals_aga then do m_drw.ik = m_drw.ik + 1 m_pts.ik = m_pts.ik + ptsdrw end if goals_for < goals_aga then do m_won.ik = m_won.ik + 1 m_pts.ik = m_pts.ik + ptswin end if goals_for > goals_aga then do m_lost.ik= m_lost.ik + 1 m_pts.ik = m_pts.ik + ptslse end m_pts.ik = m_pts.ik + (goals_aga * ptsgls) end end end end end close(datafile) end else do say say eos_error say say eos_t2"'"league_table || input2_file"'." exit end if open(outfile,output_file,"w") then do do ik=1 to tcount line = teams.ik line = insert(" ",line,length(line)+1,30-length(line)) mp = right(m_ply.ik,3) mw = right(m_won.ik,3) md = right(m_drw.ik,3) ml = right(m_lost.ik,3) mgf = right(m_gof.ik,5) mga = right(m_goa.ik,5) mpts = right(m_pts.ik,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 eos_error say say eos_t6" '"output_file"'." exit end address command 'Exec/footsort ' if open(datafile2,output_file,'r') then do do ik=1 to tcount line = readln(datafile2) teams.ik = line teams2.ik = line end close(datafile2) end else do say say eos_error say say eos_t2"'"output_file"'"eos_t3 exit end ctr = 0 do while swapctr > 0 swapctr=9 do ik=1 to tcount-1 /* was 64,4 and 77,4 */ swapdone=0 j = i + 1 if strip(substr(teams.ik,64,7)) = strip(substr(teams.j,64,7)) then do goaldiffa = strip(substr(teams.ik,77,5)) goaldiffb = strip(substr(teams.j,77,5)) if goaldiffa < goaldiffb then do teams.ik = teams2.j teams.j = teams2.ik teams2.ik= teams.ik 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 if pos(subdir,league_table) > 0 then parse var league_table "Data/" . "/" name . else parse var league_table . "/" name . if pos("/",name) > 0 then do parse var name . "/" name2 name = name2 end /* parse var league_table . "/" name . */ if open(datafile2,"RAM:"||name||".final_table",'w') then do do ik=1 to tcount if strip(substr(teams.ik,76,5)) = 0 then teams.ik=overlay("",teams.ik,76,5," ") writeln(datafile2,teams.ik) end close(datafile2) end else do say say eos_error say say eos_t2"'RAM:"name".final_table'"eos_t4 exit end return /*******************************************************************************/