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

  1. /* ***********************************************************************
  2.  
  3.    WRITE MATCH PROGRAM FOR FOOTBALL REXX SUITE
  4.   ---------------------------------------------
  5.                    Copyright  Mark Naughton 1997
  6.  
  7.  
  8. Version    Date     History
  9. --------------------------------------------------------------------------
  10.  
  11.  1.0       080597   Created. Designed to be called from Gameplay to write
  12.                     the score directly to the Schedule file, giving an
  13.                     error if the match has been played, leaving Gameplay
  14.                     to update the Learn file.
  15.            100597   Changed command for deleting the Game.Stored file. Had
  16.                     to set 'sdcount' to 1 as lines were being missed in the
  17.                     recreation as the first was being stored at 0 instead
  18.                     of 1 which was where the loop started. Had to amend
  19.                     the loop which wrote it back as it added one extra
  20.                     line which wasn't required. Swapped parameters in the
  21.                     'pos' statement when checking the matches as it was
  22.                     always overwriting matches that had been played.
  23.            100697   Changed position that the away team is picked from the
  24.                     argument to 1 from 2. Was giving invalid values.
  25.                     Changed method again, a draw meant that the positions
  26.                     picked up were one out as it went for the 1st occurrence.
  27.  1.1       240499   Jan Andersen reported a problem with teams with numerics
  28.                     in their name and that the schedule was not being updated.
  29.                     Reworked the code for updating the schedule - much better!
  30.  
  31.  
  32. **************************************************************************
  33.  
  34. Procedure
  35. ---------
  36.  
  37. 1. Split argument into league-name and match.
  38. 2. Check schedule file exists. If file-indicator exists then erase it.
  39. 3. Read Schedule file into an array.
  40. 4. Using the teams in the array, split into teams and use this as a match
  41.    against the teams from the game. When found, overwrite the scores.
  42. 5. If a match has been played and updated, then rewrite the Schedule file
  43.    back. Then write the file-indicator to tell Gameplay that a match has
  44.    been stored. Then exit.
  45.  
  46. ************************************************************************** */
  47. PARSE ARG league_file
  48.  
  49. version      = 1
  50. input_file   = '.sf'
  51. output_file  = 'RAM:Game.stored'
  52. separator    = '*'
  53. sdlines.     = '???'
  54. sdcount      = 1
  55. not_played   = '__   __'
  56. league_file  = "Data/"league_file
  57.  
  58. parse var league_file league " " match
  59.  
  60. if exists(league || input_file) = 0  then exit
  61. if exists(output_file) > 0 then
  62.    address command 'delete >NIL: 'output_file
  63.  
  64. if open(datafile3,league || input_file,'r') then do
  65.    do while ~eof(datafile3)
  66.       line = readln(datafile3)
  67.       sdlines.sdcount = strip(line)
  68.       sdcount         = sdcount + 1
  69.    end
  70.    close(datafile3)
  71. end
  72. else do
  73.    say
  74.    say "ERROR :    (WriteMatch)"
  75.    say
  76.    say "Cannot open '"league || input_file"' for reading."
  77.    exit
  78. end
  79.  
  80. marker = 0
  81. do i=1 to sdcount
  82.    team1 = strip(substr(sdlines.i,1,30))
  83.    team2 = strip(substr(sdlines.i,41,30))
  84.    if find(match,team1) = 1 & find(match,team2) > 1 then do
  85.       if pos(not_played,sdlines.i) > 0 then do
  86.          tt = strip(delstr(match,1,length(team1)))
  87.          sdlines.i = overlay(right(word(tt,1),2),sdlines.i,32)
  88.          sdlines.i = overlay(right(word(tt,2),2),sdlines.i,37)
  89.          marker = 1
  90.          leave
  91.       end
  92.       else
  93.          marker = 0
  94.    end
  95. end
  96.  
  97.  
  98. if marker = 1 then do
  99.    if open(datafile3,league || input_file,'w') then do
  100.       do i=1 to sdcount-1
  101.          if i < sdcount-1 then
  102.             writeln(datafile3,sdlines.i)
  103.          else
  104.             writech(datafile3,sdlines.i)
  105.       end
  106.       close(datafile3)
  107.       if open(datafile1,output_file,'w') then do
  108.          writeln(datafile1,"Game stored in '"league||input_file"'.")
  109.          close(datafile1)
  110.       end
  111.       else do
  112.          say
  113.          say "ERROR :    (WriteMatch)"
  114.          say
  115.          say "Match has been stored but the indicator file could not be"
  116.          say "created."
  117.          exit
  118.       end
  119.    end
  120.    else do
  121.       say
  122.       say "ERROR :    (WriteMatch)"
  123.       say
  124.       say "Cannot open '"league || input_file"' for writing."
  125.    end
  126. end
  127.  
  128. exit
  129.  
  130. /* *********************************************************************** */