home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format 126 / af126a.adf / Football.lzx / football / exec / Games.rexx < prev    next >
OS/2 REXX Batch file  |  1999-05-22  |  7KB  |  200 lines

  1. /* ***********************************************************************
  2.  
  3.    GAMES PROGRAM FOR FOOTBALL REXX SUITE
  4.   -------------------------------------------
  5.                    Copyright  Mark Naughton 1996
  6.  
  7.  
  8. Version    Date     History
  9. --------------------------------------------------------------------------
  10.  1.0       230996   First release. Finished putting in code to display
  11.                     fixtures. Started 17/09/96. Added whether its a WIN,
  12.                     a DRAW or LOST to output. Added error check in case
  13.                     the selected team was incorrect.
  14.            270996   Updated to use new filenames. Improved error messages.
  15.            300996   Tidied code slightly. Added error message.
  16.  1.1       111196   Updated to use different leagues and to become a
  17.                     component called by FOOTBALL. Changed to read info
  18.                     from '*.sflearn' as this data is in the correct order.
  19.                     Gets team name from argument.
  20.            131196   Added checks for files - if not found, exits without
  21.                     a message.
  22.            211196   Updated and tidied the display.
  23.            190497   Added title to display.
  24.  1.2       150997   Added code to handle dates/weeks from Automatic-
  25.                     Scheduling. Tidied display and added headings.
  26.            151297   Tidied display.
  27.            050599   Amended display.
  28.  
  29. **************************************************************************
  30.  
  31. Procedure
  32. ---------
  33.  
  34. 1. Check files exist. Read Teams.df datafile and store teams.
  35. 2. Search for specified team and if not found, give an error and quit.
  36. 3. Open datafile depending whether it was autoscheduled or not.
  37. 4. If "Week" or "Date" is found, grab the data and format it for later.
  38. 5. Use selected team against either HOME or AWAY team and if a match is
  39.    found then display the data.
  40. 6. When the file is finished, print the number of matches and exit...
  41.  
  42. ************************************************************************** */
  43. PARSE ARG league_stuff
  44.  
  45. version      = 1
  46. input_file   = '.df'
  47. input2_file  = '.sflearn'
  48. input3_file  = '.sf'
  49. title        = '*LEAGUE_NAME='
  50. autosched    = '*AUTOSCHD='
  51. separator    = '*'
  52. teams.       = '???'
  53. counter      = 0
  54. not_played   = '__   __'
  55.  
  56.  
  57. parse var league_stuff league_file search_team
  58. league_file = "Data/" || league_file
  59.  
  60. if exists(league_file || input_file) = 0  then exit
  61. if exists(league_file || input2_file) = 0 then exit
  62. if exists(league_file || input3_file) = 0 then exit
  63.  
  64. autos = 0
  65. if open(datafile,league_file || input_file,'r') then do
  66.    do while ~eof(datafile)
  67.       line = readln(datafile)
  68.       if pos(title,line) > 0 then
  69.          league_title = delstr(line,1,13)
  70.       if pos(autosched,line) > 0 then
  71.          autos = 1
  72.       if pos(separator,line) = 0 then do
  73.          line = strip(line)
  74.          if counter = 0 then do
  75.             teams.1 = line
  76.             counter = 1
  77.          end
  78.          else do
  79.             counter       = counter + 1
  80.             teams.counter = line
  81.          end
  82.       end
  83.    end
  84.    close(datafile)
  85.  
  86.    sel=-1
  87.    search_team = strip(search_team)
  88.    do i=1 to counter
  89.       if pos(search_team,teams.i) > 0 then
  90.          sel = i
  91.    end
  92.    if sel > 0 then do
  93.       say
  94.       say center("Display Team Results in '"league_title"'",78)
  95.       say "-------------------------------------------------------------------------------"
  96.       say
  97.       say "Games Played By: "teams.sel
  98.       say "                                    (The selected team's score is always first)"
  99.       say
  100.       matches = 0
  101.       if autos = 1 then do
  102.          file_to_open = league_file || input3_file
  103.          say "Date/Week   Where   Opponent                        Score"
  104.          say "----------------------------------------------------------------------"
  105.       end
  106.       else do
  107.          file_to_open = league_file || input2_file
  108.          say "Where   Opponent                        Score"
  109.          say "----------------------------------------------------------"
  110.       end
  111.       if open(datafile,file_to_open,'r') then do
  112.          do while ~eof(datafile)
  113.             line = readln(datafile)
  114.             if autos = 1 then do
  115.                if pos(separator,line) > 0 then do
  116.                   if pos("*Week:",line) > 0 then do
  117.                      curr = subword(line,2)
  118.                   end
  119.                   if pos("*Date:",line) > 0 then do
  120.                      year = word(line,5)
  121.                      mnth = word(line,4)
  122.                      day  = word(line,3)
  123.                      curr = right(day,2,0)||" "||substr(mnth,1,3)||" "||substr(year,3,2)
  124.                   end
  125.                end
  126.             end
  127.             else
  128.                curr = ''
  129.             if pos(separator,line) = 0 then do
  130.                if pos(not_played,line) = 0 then do
  131.                   home_team = strip(substr(line,1,30))
  132.                   goals_for = substr(line,32,2)
  133.                   goals_aga = substr(line,37,2)
  134.                   away_team = strip(substr(line,41,30))
  135.  
  136.                   strng = strip(teams.sel)
  137.                   if strng = home_team then do
  138.                      if goals_for > goals_aga then
  139.                         ttemp = 'Home Win'
  140.                      if goals_for = goals_aga then
  141.                         ttemp = 'Draw'
  142.                      if goals_for < goals_aga then
  143.                         ttemp = 'Lost'
  144.                      if autos = 1 then
  145.                         say left(curr,12)"Home    "left(away_team,30)" "goals_for" -"goals_aga" "right(ttemp,12)
  146.                      else
  147.                         say "Home    "left(away_team,30)" "goals_for" -"goals_aga" "right(ttemp,12)
  148.                      matches = matches + 1
  149.                   end
  150.                   if strng = away_team then do
  151.                      if goals_for > goals_aga then
  152.                         ttemp = 'Lost'
  153.                      if goals_for = goals_aga then
  154.                         ttemp = 'Draw'
  155.                      if goals_for < goals_aga then
  156.                         ttemp = 'Away Win'
  157.                      if autos = 1 then
  158.                         say left(curr,12)"Away    "left(home_team,30)" "goals_aga" -"goals_for" "right(ttemp,12)
  159.                      else
  160.                         say "Away    "left(home_team,30)" "goals_aga" -"goals_for" "right(ttemp,12)
  161.                      matches = matches + 1
  162.                   end
  163.                end
  164.             end
  165.          end
  166.          close(datafile)
  167.          say
  168.          if matches = 0 then
  169.             say "No matches yet played."
  170.          else
  171.             say "Number of matches played:  "matches
  172.          say
  173.          say "-------------------------------------------------------------------------------"
  174.          say
  175.       end
  176.       else do
  177.          say
  178.          say "ERROR :    (Games)"
  179.          say
  180.          say "Cannot read '"league_file || input2_file"' datafile."
  181.          exit
  182.       end
  183.    end
  184.    else do
  185.       say
  186.       say "ERROR :    (Games)"
  187.       say
  188.       say "Incorrect team. '"search_team"' cannot be found in this"
  189.       say "league."
  190.       exit
  191.    end
  192. end
  193. else do
  194.    say
  195.    say "ERROR :    (Games)"
  196.    say
  197.    say "Cannot read '"league_file || input_file"' datafile."
  198. end
  199.  
  200. exit