home *** CD-ROM | disk | FTP | other *** search
- /* Uchess.convert */
-
-
- /**********************/
- /* Initializations */
- /**********************/
-
- /* call close("STDOUT")
- if open("STDOUT",'ram:checkfile','w') then
- say "Checkfile open......" */
-
- /* constants */
-
- true = 1
- false = 0
-
- /**********************/
- /* Main */
- /**********************/
-
- /* trace ?r */
-
- call setup_list_of_files_in_ram()
- LISTFILE = 'FILE'
- call open(LISTFILE,'ram:current_files','r')
- do while ~EOF(LISTFILE)
- white_king_moved = false
- black_king_moved = false
- line = readln(LISTFILE)
- if (left(line,1) = "$") then do
- game = word(line,1)
- call convert_and_store_current_game(game)
- call delete_current_file('chess_directory:'game)
- end
- end
- call close(FILE)
- exit
-
-
-
- /**********************/
- /* Functions */
- /**********************/
-
-
-
- setup_list_of_files_in_ram:
- address command "list sub "$" >ram:current_files chess_directory:"
- return
-
-
- char:
- string = arg(1)
- index = arg(2)
- if index > length(string) then return 0
- else return substr(string,index,1)
-
-
- convert_and_store_current_game:
- line_number = 0
- game = arg(1)
- game_file = 'game_file'
- call open(game_file,'chess_directory:'game,'r')
- new_format = 'new_format'
- call open(new_format,'ram:temp_file','w')
- call writeln(new_format," ")
- line = readln(game_file)
- do while word(line,1) ~= "move"
- line = readln(game_file)
- end
- game_over = false
- do while ~game_over
- line = readln(game_file)
- Lcol = word(line,1)
- line = readln(game_file)
- Rcol = word(line,1)
- line_number = line_number + 1
-
- if (left(Lcol,2)="e1") & ~white_king_moved
- then do /****/
- white_king_moved = true
- select
- when (right(Lcol,2)="g1") then
- Lcol = " O-O"
- when (right(Lcol,2)="c1") then
- Lcol = "O-O-O"
- otherwise Lcol = " "||Lcol
- end /* select */
- end /****/
- else Lcol = " "||Lcol
-
- if (left(Rcol,2)="e8") & ~black_king_moved
- then do /****/
- black_king_moved = true
- select
- when (right(Rcol,2)="g8") then
- Rcol = " O-O"
- when (right(Rcol,2)="c8") then
- Rcol = "O-O-O"
- otherwise Rcol = " "||Rcol
- end /* select */
- end /****/
- else Rcol = " "||Rcol
- call writeln(new_format,padleft(line_number," ",3),
- " "||Lcol" "Rcol)
- if EOF(game_file)|(Lcol=="")|(Rcol=="") then
- game_over = true
- end
- call close(new_format)
- call close(game_file)
- address command 'copy ' 'ram:temp_file',
- 'chess_directory:GNU_chess_games/'game
- return
-
-
- delete_current_file: procedure expose true false
- address command
- 'delete' arg(1)
- return
-
-
- padleft:
- string = arg(1)
- padchar = arg(2)
- padlength = arg(3)
- len = length(string)
- if len<padlength then do
- do i=1 to padlength-len
- string = padchar||string
- end
- end
- return string
-
-
-