home *** CD-ROM | disk | FTP | other *** search
- /* chess.convert */
-
-
- /**********************/
- /* Initializations */
- /**********************/
-
- /* constants */
-
- true = 1
- false = 0
-
- /**********************/
- /* Main */
- /**********************/
-
- /* trace ?r */
-
- call setup_list_of_files_in_ram()
- FILE = 'FILE'
- call open(FILE,'ram:current_files','r')
- do while ~EOF(FILE)
- white_king_moved = false
- black_king_moved = false
- line = readln(FILE)
- if (left(line,3) = "CLp") 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 "CLp" >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')
- garbage = readln(game_file)
- garbage = readln(game_file)
- new_format = 'new_format'
- call open(new_format,'ram:temp_file','w')
- call writeln(new_format," ")
- do while ~EOF(game_file)
- /* if line_number>7 then trace ?r */
- line_number = line_number + 1
- line = readln(game_file)
- Lcol = word(line,1)
- Rcol = word(line,6)
-
- 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)
- 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
-
-
-