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

  1. /* ***********************************************************************
  2.  
  3.   UPDATE SETTINGS PROGRAM FOR FOOTBALL REXX SUITE
  4.   ------------------------------------------------
  5.                    Copyright  Mark Naughton 1999
  6.  
  7.  
  8. Version    Date     History
  9. --------------------------------------------------------------------------
  10.  
  11.  1.0       250499   Created as a partner to Football to update the
  12.                     settings and league name in all files.
  13.  
  14. **************************************************************************
  15.  
  16. Procedure
  17. ---------
  18.  
  19. 1. Check files exist. Get league name from '.df' file.
  20. 2. Read '.sf' file into an array. Search array for indicator for league
  21.    name. When found, check to see if the names are different - if no, then
  22.    don't update, else write the new name into the array. When finished and
  23.    updates have been made, write the new data into the old file.
  24. 3. Repeat step 2 for '.sflearn' file.
  25. 4. Repeat step 2 for '.stats' file.
  26. 5. Exit.
  27.  
  28. ************************************************************************** */
  29. PARSE ARG league_file
  30.  
  31. version      = 1
  32. league_file  = "Data/"strip(league_file)
  33. input_file   = '.df'
  34. input2_file  = '.sf'
  35. input3_file  = '.sflearn'
  36. input4_file  = '.stats'
  37. title        = '*LEAGUE_NAME='
  38. sdlines.     = '???'
  39. separator    = '*'
  40.  
  41.  
  42. if exists(league_file || input_file) = 0 then exit
  43. if exists(league_file || input2_file) = 0 then exit
  44. if exists(league_file || input3_file) = 0 then exit
  45. if exists(league_file || input4_file) = 0 then exit
  46.  
  47. if open(datafile,league_file || input_file,'r') then do
  48.    do while ~eof(datafile)
  49.       line = readln(datafile)
  50.       line = strip(line)
  51.       if pos(separator,line) > 0 then do
  52.          if pos(title,line) > 0 then do
  53.             parse var line "*LEAGUE_NAME=" league_title
  54.             league_title = strip(league_title)
  55.          end
  56.       end
  57.    end
  58.    close(datafile)
  59. end
  60. else do
  61.    say
  62.    say "ERROR :    (UpdateSettings)"
  63.    say
  64.    say "Cannot open '"league_file || input_file"' for reading."
  65.    exit
  66. end
  67.  
  68.  
  69. sdcount = 0
  70. if open(datafile,league_file||input2_file,'r') then do
  71.    do while ~eof(datafile)
  72.       line = readln(datafile)
  73.       line = strip(line)
  74.       sdcount         = sdcount + 1
  75.       sdlines.sdcount = line
  76.    end
  77.    close(datafile)
  78. end
  79. else do
  80.    say
  81.    say "ERROR :    (UpdateSettings)"
  82.    say
  83.    say "Cannot open '"league_file||input2_file"' for reading."
  84.    exit
  85. end
  86.  
  87. mkt = 0
  88. do i=1 to sdcount
  89.    if pos("**",sdlines.i) > 0 then do
  90.       parse var sdlines.i "**" ltitle
  91.       if pos(ltitle,league_title) = 0 then do
  92.          sdlines.i = "** "league_title
  93.          mkt = 1
  94.          leave
  95.       end
  96.       else do
  97.          mkt = 0
  98.          leave
  99.       end
  100.    end
  101. end
  102.  
  103. if mkt = 1 then do
  104.    if open(datafile3,league_file || input2_file,'w') then do
  105.       do j=1 to sdcount
  106.          writeln(datafile3,sdlines.j)
  107.       end
  108.       close(datafile3)
  109.    end
  110.    else do
  111.       say
  112.       say "ERROR :    (UpdateSettings)"
  113.       say
  114.       say "Cannot open '"league_file || input2_file"' for writing."
  115.       exit
  116.    end
  117. end
  118.  
  119. sdcount = 0
  120. if open(datafile,league_file||input3_file,'r') then do
  121.    do while ~eof(datafile)
  122.       line = readln(datafile)
  123.       line = strip(line)
  124.       sdcount         = sdcount + 1
  125.       sdlines.sdcount = line
  126.    end
  127.    close(datafile)
  128. end
  129. else do
  130.    say
  131.    say "ERROR :    (UpdateSettings)"
  132.    say
  133.    say "Cannot open '"league_file||input3_file"' for reading."
  134.    exit
  135. end
  136.  
  137. mkt = 0
  138. do i=1 to sdcount
  139.    if pos("**",sdlines.i) > 0 then do
  140.       parse var sdlines.i "**" ltitle
  141.       if pos(ltitle,league_title) = 0 then do
  142.          sdlines.i = "** "league_title
  143.          mkt = 1
  144.          leave
  145.       end
  146.       else do
  147.          mkt = 0
  148.          leave
  149.       end
  150.    end
  151. end
  152.  
  153. if mkt = 1 then do
  154.    if open(datafile3,league_file || input3_file,'w') then do
  155.       do j=1 to sdcount
  156.          writeln(datafile3,sdlines.j)
  157.       end
  158.       close(datafile3)
  159.    end
  160.    else do
  161.       say
  162.       say "ERROR :    (UpdateSettings)"
  163.       say
  164.       say "Cannot open '"league_file || input3_file"' for writing."
  165.       exit
  166.    end
  167. end
  168.  
  169.  
  170. sdcount = 0
  171. if open(datafile,league_file||input4_file,'r') then do
  172.    do while ~eof(datafile)
  173.       line = readln(datafile)
  174.       line = strip(line)
  175.       sdcount         = sdcount + 1
  176.       sdlines.sdcount = line
  177.    end
  178.    close(datafile)
  179. end
  180. else do
  181.    say
  182.    say "ERROR :    (UpdateSettings)"
  183.    say
  184.    say "Cannot open '"league_file||input4_file"' for re-reading."
  185.    exit
  186. end
  187.  
  188. mkt = 0
  189. do i=1 to sdcount
  190.    if pos(title,sdlines.i) > 0 then do
  191.       parse var sdlines.i "*LEAGUE_NAME=" ltitle
  192.       if pos(ltitle,league_title) = 0 then do
  193.          sdlines.i = "*LEAGUE_NAME="league_title
  194.          mkt = 1
  195.          leave
  196.       end
  197.       else do
  198.          mkt = 0
  199.          leave
  200.       end
  201.    end
  202. end
  203.  
  204. if mkt = 1 then do
  205.    if open(datafile3,league_file || input4_file,'w') then do
  206.       do j=1 to sdcount
  207.          writeln(datafile3,sdlines.j)
  208.       end
  209.       close(datafile3)
  210.    end
  211.    else do
  212.       say
  213.       say "ERROR :    (UpdateSettings)"
  214.       say
  215.       say "Cannot open '"league_file || input4_file"' for writing."
  216.       exit
  217.    end
  218. end
  219.  
  220.  
  221. exit