/* Mode=Run */
/* ***********************************************************************

   CLOSE CUP PROGRAM FOR FOOTBALL REXX SUITE
  -------------------------------------------
                   Copyright  Mark Naughton 1999


Version    Date     History
--------------------------------------------------------------------------

 1.0       210499   First release.
           250899   Added error msg to file checks.
           280899   Converted to use locale. Some error messages, before
                    reading the locale, will still be in English. Renaming
                    of history file to month name is also localed.

**************************************************************************

Procedure
---------

1. Check files.
2. Setup new filename.
3. Rename files.
4. Output message.

************************************************************************** */
PARSE ARG league_file

version      = 1
input_file   = '.cf'
input2_file  = '.scf'
input3_file  = '.cfrw'
input4_file  = '.cfh'
mnths        = 'Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec'
league_stuff = "Data/"league_file


if open(datafile,"Data/Football.locale",'r') then do
   line = readln(datafile)
   locdir = strip(line)
   close(datafile)
end
else do
   say
   say "ERROR :    (Cup_CloseCup)"
   say
   say "Cannot read 'Data/Football.locale' for the locale settings."
   exit
end

dfordir = locdir"Football.locale_data"
locdir = locdir"User/Cup_CloseCup.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 :    (Cup_CloseCup)"
   say
   say "Cannot find '"locdir"' to read locale settings."
   exit
end

if exists(dfordir) > 0 then do
  address command rxdir'rx 'dfordir
  VarCount = getclip('VarCount')
  do i = 1 to VarCount
    interpret getclip('var.'i)
  end
end
else do
   say
   say "ERROR :    (Cup_CloseCup)"
   say
   say "Cannot find '"dfordir"' to read date locale settings."
   exit
end

if exists(league_stuff||input_file) = 0 then do
   say
   say ccc_error
   say
   say fl_canfd"'"league_file || input_file"'."
   exit
end

if exists(league_stuff||input2_file) = 0 then do
   say
   say ccc_error
   say
   say fl_canfd"'"league_file || input2_file"'."
   exit
end

if exists(league_stuff||input3_file) = 0 then do
   say
   say ccc_error
   say
   say fl_canfd"'"league_file || input3_file"'."
   exit
end

if exists(league_stuff||input4_file) = 0 then do
   say
   say ccc_error
   say
   say fl_canfd"'"league_file || input4_file"'."
   exit
end

today = date()
month = strip(word(today,2))
do i=1 to 12
   if month = word(mnths,i) then do
      month = word(fl_mnths,i)
      leave
   end
end
year  = substr(word(today,3),3,2)

nleague_file = league_file"_"month||year


f1 = league_stuff||input_file" as Data/"nleague_file||input_file
address command 'c:Rename >NIL: 'f1

f1 = league_stuff||input2_file" as Data/"nleague_file||input2_file
address command 'c:Rename >NIL: 'f1

f1 = league_stuff||input3_file" as Data/"nleague_file||input3_file
address command 'c:Rename >NIL: 'f1



say
say center(ccc_two,78)
say "-------------------------------------------------------------------------------"
say
say
say ccc_three"'"league_file"'"ccc_four
say
say "                    '"nleague_file||input_file"'"
say "                    '"nleague_file||input2_file"'"
say "                    '"nleague_file||input3_file"'"
say
say

if exists(league_stuff||input4_file) > 0 then do
   say ccc_txt1"'"league_file||input4_file"'"ccc_txt2
   say
   say ccc_txt3
   say ccc_txt4
   say
   say
   say
   say ccc_txt6"'"nleague_file||input_file"'"ccc_txt7
   say
   say ccc_txt9
   say
   say ccc_txt0"'"league_file"'"ccc_txta
   say
   say
end

say
say "-------------------------------------------------------------------------------"
say

exit