home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / game / patch / gnuchessfix / uchess.convert < prev   
Encoding:
Text File  |  1995-02-11  |  2.9 KB  |  135 lines

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