home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #3 / amigamamagazinepolishissue1998.iso / szachy / gnu / gnuchessfix / chess.convert < prev    next >
Text File  |  1995-02-11  |  3KB  |  125 lines

  1. /* chess.convert */
  2.  
  3.  
  4. /**********************/
  5. /*  Initializations   */
  6. /**********************/
  7.  
  8. /*  constants  */
  9.  
  10.    true  = 1
  11.    false = 0
  12.  
  13. /**********************/
  14. /*        Main        */
  15. /**********************/
  16.  
  17. /* trace ?r */
  18.  
  19. call setup_list_of_files_in_ram()
  20. FILE = 'FILE'
  21. call open(FILE,'ram:current_files','r')
  22. do while ~EOF(FILE)
  23.   white_king_moved = false
  24.   black_king_moved = false
  25.   line = readln(FILE)
  26.   if (left(line,3) = "CLp") then do
  27.     game = word(line,1)
  28.     call convert_and_store_current_game(game)
  29.     call delete_current_file('chess_directory:'game)
  30.   end
  31. end
  32. call close(FILE)
  33. exit
  34.  
  35.  
  36.  
  37. /**********************/
  38. /*      Functions     */
  39. /**********************/
  40.  
  41.  
  42.  
  43. setup_list_of_files_in_ram:
  44. address command "list sub "CLp" >ram:current_files chess_directory:"
  45. return
  46.  
  47.  
  48. char:
  49. string = arg(1)
  50. index  = arg(2)
  51. if index > length(string) then return 0
  52.   else return substr(string,index,1)
  53.  
  54.  
  55. convert_and_store_current_game:
  56. line_number = 0
  57. game = arg(1)
  58. game_file = 'game_file'
  59. call open(game_file,'chess_directory:'game,'r')
  60. garbage = readln(game_file)
  61. garbage = readln(game_file)
  62. new_format = 'new_format'
  63. call open(new_format,'ram:temp_file','w')
  64. call writeln(new_format," ")
  65. do while ~EOF(game_file)
  66.   /* if line_number>7 then trace ?r */
  67.   line_number = line_number + 1
  68.   line = readln(game_file)
  69.   Lcol = word(line,1)
  70.   Rcol = word(line,6)
  71.   
  72.   if (left(Lcol,2)="e1") & ~white_king_moved
  73.      then  do /****/
  74.               white_king_moved = true
  75.               select
  76.                  when (right(Lcol,2)="g1") then
  77.                     Lcol = "  O-O"
  78.                  when (right(Lcol,2)="c1") then
  79.                     Lcol = "O-O-O"
  80.                  otherwise Lcol = " "||Lcol
  81.               end /* select */
  82.            end /****/
  83.       else Lcol = " "||Lcol
  84.  
  85.   if (left(Rcol,2)="e8") & ~black_king_moved
  86.       then do /****/
  87.              black_king_moved = true
  88.              select
  89.                when (right(Rcol,2)="g8") then
  90.                      Rcol = "  O-O"
  91.                when (right(Rcol,2)="c8") then
  92.                      Rcol = "O-O-O"
  93.                otherwise Rcol = " "||Rcol
  94.              end /* select */
  95.           end /****/
  96.         else  Rcol = " "||Rcol
  97.   call writeln(new_format,padleft(line_number," ",3),
  98.                                      " "||Lcol"    "Rcol)
  99. end
  100. call close(new_format)
  101. call close(game_file)
  102. address command 'copy ' 'ram:temp_file',
  103.               'chess_directory:GNU_chess_games/'game
  104. return
  105.  
  106. delete_current_file: procedure expose true false
  107. address command
  108. 'delete' arg(1)
  109. return
  110.  
  111.  
  112. padleft:
  113. string    = arg(1)
  114. padchar   = arg(2)
  115. padlength = arg(3)
  116. len = length(string)
  117. if len<padlength then do
  118.       do i=1 to padlength-len
  119.          string = padchar||string
  120.       end
  121.   end
  122. return string
  123.  
  124.  
  125.