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

  1. /* ***********************************************************************
  2.  
  3.    CUP UPDATE MATCHES PROGRAM FOR FOOTBALL REXX SUITE
  4.   ----------------------------------------------------
  5.                    Copyright  Mark Naughton 1997
  6.  
  7.  
  8. Version    Date     History
  9. --------------------------------------------------------------------------
  10.  1.0       071297   First release.
  11.            081297   Didn't write the ExtraTime and Penalties lines. While
  12.                     checking through the list from '.scf', the file is
  13.                     opened and each played match is written along with,
  14.                     if applicable, ET and Penalties lines. Added parsing
  15.                     to the matches just played to see if they fail any of
  16.                     the checks.
  17.            131297   Update didn't work. Only changed the first match. Had
  18.                     to rework the method to read the schedule first and
  19.                     then compare it with each line in matches. Now works
  20.                     properly.
  21.            141297   Added error message for Penalties.
  22.            151297   Added error message for Penalties being equal and
  23.                     tidied display.
  24.            280898   Added new error messages. Added pseudo code for
  25.                     addition of checks for Legs and Away Goals.
  26.            290898   Added code to parse 2nd leg matches.
  27.            050998   Amended code for away goals on extra time.
  28.            110998   Fixed major bug which rewrote the schedule file and
  29.                     missed several lines. When it reached the 2nd leg of
  30.                     the 2nd round, it missed the '#1st Leg' line in the
  31.                     recreation of the file. Its fixed and is trimmer than
  32.                     before.
  33.            120998   Amended match checking so if the score is level after
  34.                     extra time with goals scored then away goals count.
  35.  
  36. **************************************************************************
  37.  
  38. Procedure
  39. ---------
  40.  
  41. 1. Check files exist.
  42. 2. Read definition file and see if away goals are involved. Read in
  43.    temporary file from RAM: containing matches with scores entered from
  44.    FOOTBALL.
  45. 3. Read in '.scf' file.
  46. 4. Loop until all matches have been done; If a match hasn't been played
  47.    then overwrite it with the scores.
  48. 5. Open '.scf' file and write the newly amended data to it.
  49. 6. Exit.
  50.  
  51. ************************************************************************** */
  52. PARSE ARG league_stuff
  53.  
  54. version      = 1
  55. input_file   = 'RAM:Football.ctmpfile'
  56. input2_file  = '.scf'
  57. input3_file  = '.cf'
  58. matches.     = '???'
  59. separator    = '*'
  60. ttc          = 0
  61. not_played   = '__   __'
  62. league_file  = "Data/"league_stuff
  63. selines.     = '???'
  64. sdlines.     = '???'
  65. sdc          = 0
  66. awaygoals    = '*CUP_AWAYG='
  67.  
  68.  
  69. if exists(input_file) = 0 then exit
  70. if exists(league_file||input2_file) = 0 then exit
  71. if exists(league_file||input3_file) = 0 then exit
  72.  
  73. if open(datafile,league_file || input3_file,'r') then do
  74.    do while ~eof(datafile)
  75.       line = readln(datafile)
  76.       if pos(awaygoals,line) > 0 then awayg = delstr(line,1,11)
  77.    end
  78.    close(datafile)
  79. end
  80. else do
  81.    say
  82.    say "ERROR :    (CupUpdateMatches)"
  83.    say
  84.    say "Unable to open '"league_file || input3_file"' file."
  85.    exit
  86. end
  87.  
  88. ttc = 0
  89. if open(datafile,input_file,'r') then do
  90.    do while ~eof(datafile)
  91.       line = readln(datafile)
  92.       if line ~= '' then do
  93.          ttc = ttc + 1
  94.          matches.ttc = line
  95.       end
  96.    end
  97.    close(datafile)
  98. end
  99. else do
  100.    say
  101.    say "ERROR :    (CupUpdateMatches)"
  102.    say
  103.    say "Cannot open '"input_file"' for reading."
  104.    exit
  105. end
  106.  
  107. /* parsing matches array for errors */
  108.  
  109. errors  = ' '
  110. errct   = 0
  111. legs    = 0
  112.  
  113. do i=1 to ttc
  114.    mkr = 0
  115.    if pos("#Round=",matches.i) > 0 then do
  116.       if pos("1st Leg",matches.i) > 0 then
  117.          legs = 1
  118.       if pos("2nd Leg",matches.i) > 0 then
  119.          legs = 2
  120.    end
  121.    if pos('#',matches.i) = 0 then do
  122.       sh  = substr(matches.i,32,2)
  123.       sa  = substr(matches.i,37,2)
  124.  
  125.       if sa  = sh then mkr = 1
  126.       if sa ~= sh & legs~=2 then iterate
  127.       if sa ~=sh & legs=2 then mkr = 1
  128.       if pos(not_played,matches.i) > 0 then mkr = 3   /* was 0 - unsure why... */
  129.  
  130.    /* this is where the check for away goals and if its equal after two legs */
  131.    /* if so then extra time then penalties needs to be played. */
  132.    /* sa and sh need to be added together with the 1st leg before checking */
  133.    /* if no winner, (if away goals set), check away goals else proceed onto */
  134.    /* extra time and penalties */
  135.  
  136.       if mkr = 1 & legs = 1 then iterate
  137.       if mkr = 1 & legs = 2 then do
  138.          j = i + 1
  139.          if pos("#1st Leg",matches.j) > 0 then do
  140.             i = j
  141.             fh  = substr(matches.i,32,2)
  142.             fa  = substr(matches.i,37,2)
  143.             shs = fh + sh
  144.             sas = fa + sa
  145.  
  146.             if shs = sas then do
  147.                if pos("YES",awayg) > 0 then do
  148.                   if fh = sa then mkr = 1
  149.                   if fh ~= sa then iterate
  150.                end
  151.                else
  152.                   mkr = 1
  153.             end
  154.             if shs ~= sas then iterate
  155.             if pos(not_played,matches.i) > 0 then mkr = 3
  156.          end
  157.          else do
  158.             errct = errct + 1
  159.             errors = errors" "i" "
  160.             iterate
  161.          end
  162.       end
  163.  
  164.       if mkr = 1 then do
  165.          j = i + 1
  166.          if pos("#Score After Extra Time",matches.j) > 0 then do
  167.             i = i + 1
  168.             eh  = substr(matches.i,32,2)
  169.             ea  = substr(matches.i,37,2)
  170.             if eh = "" | ea = "" then mkr = 3
  171.             if pos(not_played,matches.i) > 0 then mkr = 3
  172.  
  173.             if mkr ~= 3 then do
  174.                if legs = 2 then do
  175.                   shs = fh + eh
  176.                   sas = fa + ea
  177.                   if shs ~= sas then iterate
  178.                   if pos("YES",awayg) > 0 then do
  179.                      if eh = sa then do
  180.                         if eh = eh & sa = ea then
  181.                            mkr = 1
  182.                         else
  183.                            iterate
  184.                      end
  185.                      if eh ~= sa then iterate
  186.                   end
  187.                   else
  188.                      mkr = 1
  189.                end
  190.                else do
  191.                   if eh =  ea then mkr = 1
  192.                   if eh ~= ea then iterate
  193.                end
  194.             end
  195.             if eh < sh | ea < sa then mkr = 3
  196.          end
  197.       end
  198.       if mkr = 3 then do
  199.          errct = errct + 1
  200.          errors = errors" "i" "
  201.          iterate
  202.       end
  203.       if mkr = 1 then do
  204.          j = i + 1
  205.          if pos("#Penalties",matches.j) > 0 then do
  206.             i = i + 1
  207.             ph  = substr(matches.i,32,2)
  208.             pa  = substr(matches.i,37,2)
  209.             if ph = "" | pa = "" then mkr = 3
  210.  
  211.             if ph =  pa then mkr = 3
  212.             if ph ~= pa then iterate
  213.             if pos(not_played,matches.i) > 0 then mkr = 3
  214.          end
  215.       end
  216.       if mkr = 3 then do
  217.          errct = errct + 1
  218.          errors = errors" "i" "
  219.          iterate
  220.       end
  221.    end
  222. end
  223.  
  224. if errct > 0 then do
  225.    say
  226.    say center("ERRORS FOUND WHILE UPDATING CUP '"league_stuff"'",78)
  227.    say "-------------------------------------------------------------------------------"
  228.    say
  229.    do j=1 to ttc
  230.       if pos("#Round",matches.j) = 0 then do
  231.          if pos(" "j" ",errors) > 0 then
  232.             say ">"left(matches.j,70)"< ERROR IN MATCH"
  233.          else
  234.             say ">"left(matches.j,70)"<"
  235.       end
  236.    end
  237.    say
  238.    say
  239.    say errct" errors found."
  240.    say
  241.    say "Rules"
  242.    say "-----"
  243.    say
  244.    say "1. A match fails the checks if the score is equal, extra time is"
  245.    say "   equal and penalties are equal."
  246.    say "2. A match fails the checks if the score is equal and penalties"
  247.    say "   are equal."
  248.    say "3. A match will fail if the score is equal and the extra time hasn't"
  249.    say "   been played when it should have been."
  250.    say "4. A match will fail if the score is equal and the penalties haven't"
  251.    say "   been played when they should have been."
  252.    say "5. A match will fail if the score is equal and the extra time is"
  253.    say "   equal but the penalties haven't been played when they should have"
  254.    say "   been."
  255.    say "6. A match will fail if the extra time scores are lower than the"
  256.    say "   full-time scores."
  257.    say "7. A match will fail if it has been played over two legs and has failed"
  258.    say "   checks (1) and (5)."
  259.    say "8. A match will fail if the away goals (if set) are equal with the match"
  260.    say "   over two legs and has failed check (7)."
  261.    say "9. A match that is 2 legs but no score can be found for the 1st leg."
  262.    say
  263.    say "All other combinations will pass. The scores have NOT been updated so"
  264.    say "they will need to be re-entered."
  265.    say
  266.    say "-------------------------------------------------------------------------------"
  267.    exit
  268. end
  269.  
  270. secount = 0
  271. if open(datafile,league_file||input2_file,'r') then do
  272.    do while ~eof(datafile)
  273.       line = readln(datafile)
  274.       secount         = secount + 1
  275.       selines.secount = line
  276.    end
  277.    close(datafile)
  278. end
  279. else do
  280.    say
  281.    say "ERROR :    (CupUpdateMatches)"
  282.    say
  283.    say "Cannot open '"league_file||input2_file"' for reading."
  284.    exit
  285. end
  286.  
  287. address command 'delete >NIL: 'input_file
  288.  
  289. et. = '???'
  290. pn. = '???'
  291. do j=1 to secount
  292.    mkr = 0
  293.    if pos(separator,selines.j) = 0 then do
  294.       shome = strip(substr(selines.j,1,30))
  295.       saway = strip(substr(selines.j,41,30))
  296.       do i=1 to ttc
  297.          home  = strip(substr(matches.i,1,30))
  298.          away  = strip(substr(matches.i,41,30))
  299.          mkr = 0
  300.  
  301.          if shome = home & saway = away then do
  302.             if pos(not_played,selines.j) > 0 then do
  303.                selines.j = matches.i
  304.                mkr = 1
  305.             end
  306.             g = i + 1
  307.             if pos("#1st Leg",matches.g) > 0 then do
  308.                a = j + 1
  309.                dif = 1
  310.             end
  311.             else do
  312.                a = j
  313.                dif = 0
  314.             end
  315.             if mkr = 1 then do
  316.                k = i + 1 + dif
  317.                if pos("#Score After Extra Time",matches.k) > 0 & pos(not_played,matches.k) = 0 then
  318.                   et.a = matches.k
  319.                k = k + 1
  320.                if pos("#Penalties",matches.k) > 0 & pos(not_played,matches.k) = 0 then
  321.                   pn.a = matches.k
  322.             end
  323.          end
  324.          if mkr = 1 then leave
  325.       end
  326.    end
  327. end
  328.  
  329. if selines.secount ~='' & selines.secount ~='*' then do
  330.    secount = secount + 1
  331.    sdlines.secount = "*"
  332. end
  333. if open(datafile,league_file||input2_file,'w') then do
  334.    do j=1 to secount
  335.       if selines.j~='' then do
  336.          writeln(datafile,selines.j)
  337.          if pos("???",et.j) = 0 & et.j ~= "" then
  338.             writeln(datafile,et.j)
  339.          if pos("???",pn.j) = 0 & pn.j ~= "" then
  340.             writeln(datafile,pn.j)
  341.       end
  342.    end
  343.    close(datafile)
  344. end
  345. else do
  346.    say
  347.    say "ERROR :    (CupUpdateMatches)"
  348.    say
  349.    say "Cannot open '"league_file || input2_file"' for writing."
  350. end
  351.  
  352. exit