diff options
Diffstat (limited to 'apps/plugins/chessbox/chessbox_pgn.c')
-rw-r--r-- | apps/plugins/chessbox/chessbox_pgn.c | 29 |
1 files changed, 7 insertions, 22 deletions
diff --git a/apps/plugins/chessbox/chessbox_pgn.c b/apps/plugins/chessbox/chessbox_pgn.c index 8c92573b75..a8be179fac 100644 --- a/apps/plugins/chessbox/chessbox_pgn.c +++ b/apps/plugins/chessbox/chessbox_pgn.c | |||
@@ -26,8 +26,6 @@ | |||
26 | #define LOG_FILE PLUGIN_GAMES_DIR "/chessbox.log" | 26 | #define LOG_FILE PLUGIN_GAMES_DIR "/chessbox.log" |
27 | int loghandler; | 27 | int loghandler; |
28 | 28 | ||
29 | const struct plugin_api* rb; | ||
30 | |||
31 | short kn_offs[8][2] = {{2,1},{2,-1},{-2,1},{-2,-1},{1,2},{1,-2},{-1,2},{-1,-2}}; | 29 | short kn_offs[8][2] = {{2,1},{2,-1},{-2,1},{-2,-1},{1,2},{1,-2},{-1,2},{-1,-2}}; |
32 | short rk_offs[4][2] = {{1,0},{-1,0},{0,1},{0,-1}}; | 30 | short rk_offs[4][2] = {{1,0},{-1,0},{0,1},{0,-1}}; |
33 | short bp_offs[4][2] = {{1,1},{-1,1},{1,-1},{-1,-1}}; | 31 | short bp_offs[4][2] = {{1,1},{-1,1},{1,-1},{-1,-1}}; |
@@ -559,7 +557,7 @@ void write_pgn_token(int fhandler, char *buffer, size_t *line_length){ | |||
559 | } | 557 | } |
560 | 558 | ||
561 | /* ---- api functions ---- */ | 559 | /* ---- api functions ---- */ |
562 | struct pgn_game_node* pgn_list_games(const struct plugin_api* api,const char* filename){ | 560 | struct pgn_game_node* pgn_list_games(const char* filename){ |
563 | int fhandler; | 561 | int fhandler; |
564 | char line_buffer[128]; | 562 | char line_buffer[128]; |
565 | struct pgn_game_node size_node, *first_game = NULL; | 563 | struct pgn_game_node size_node, *first_game = NULL; |
@@ -567,7 +565,6 @@ struct pgn_game_node* pgn_list_games(const struct plugin_api* api,const char* fi | |||
567 | unsigned short game_count = 1; | 565 | unsigned short game_count = 1; |
568 | int line_count = 0; | 566 | int line_count = 0; |
569 | bool header_start = true, game_start = false; | 567 | bool header_start = true, game_start = false; |
570 | rb = api; | ||
571 | 568 | ||
572 | if ( (fhandler = rb->open(filename, O_RDONLY)) == 0 ) return NULL; | 569 | if ( (fhandler = rb->open(filename, O_RDONLY)) == 0 ) return NULL; |
573 | 570 | ||
@@ -617,16 +614,13 @@ struct pgn_game_node* pgn_list_games(const struct plugin_api* api,const char* fi | |||
617 | return first_game; | 614 | return first_game; |
618 | } | 615 | } |
619 | 616 | ||
620 | struct pgn_game_node* pgn_show_game_list(const struct plugin_api* api, | 617 | struct pgn_game_node* pgn_show_game_list(struct pgn_game_node* first_game){ |
621 | struct pgn_game_node* first_game){ | ||
622 | int curr_selection = 0; | 618 | int curr_selection = 0; |
623 | int button; | 619 | int button; |
624 | struct gui_synclist games_list; | 620 | struct gui_synclist games_list; |
625 | int i; | 621 | int i; |
626 | struct pgn_game_node *temp_node = first_game; | 622 | struct pgn_game_node *temp_node = first_game; |
627 | 623 | ||
628 | rb=api; | ||
629 | |||
630 | for (i=0;temp_node != NULL;i++){ | 624 | for (i=0;temp_node != NULL;i++){ |
631 | temp_node = temp_node->next_node; | 625 | temp_node = temp_node->next_node; |
632 | } | 626 | } |
@@ -661,7 +655,7 @@ struct pgn_game_node* pgn_show_game_list(const struct plugin_api* api, | |||
661 | } | 655 | } |
662 | } | 656 | } |
663 | 657 | ||
664 | void pgn_parse_game(const struct plugin_api* api, const char* filename, | 658 | void pgn_parse_game(const char* filename, |
665 | struct pgn_game_node* selected_game){ | 659 | struct pgn_game_node* selected_game){ |
666 | struct pgn_ply_node size_ply, *first_ply = NULL; | 660 | struct pgn_ply_node size_ply, *first_ply = NULL; |
667 | struct pgn_ply_node *temp_ply = NULL, *curr_node = NULL; | 661 | struct pgn_ply_node *temp_ply = NULL, *curr_node = NULL; |
@@ -670,7 +664,6 @@ void pgn_parse_game(const struct plugin_api* api, const char* filename, | |||
670 | char token_buffer[10]; | 664 | char token_buffer[10]; |
671 | unsigned short pos; | 665 | unsigned short pos; |
672 | unsigned short curr_player = white; | 666 | unsigned short curr_player = white; |
673 | rb = api; | ||
674 | 667 | ||
675 | fhandler = rb->open(filename, O_RDONLY); | 668 | fhandler = rb->open(filename, O_RDONLY); |
676 | 669 | ||
@@ -731,13 +724,11 @@ void pgn_parse_game(const struct plugin_api* api, const char* filename, | |||
731 | rb->close(fhandler); | 724 | rb->close(fhandler); |
732 | } | 725 | } |
733 | 726 | ||
734 | struct pgn_game_node* pgn_init_game(const struct plugin_api* api){ | 727 | struct pgn_game_node* pgn_init_game(void){ |
735 | struct pgn_game_node game_size, *game; | 728 | struct pgn_game_node game_size, *game; |
736 | struct pgn_ply_node ply_size, *ply; | 729 | struct pgn_ply_node ply_size, *ply; |
737 | struct tm *current_time; | 730 | struct tm *current_time; |
738 | 731 | ||
739 | rb = api; | ||
740 | |||
741 | if (bufptr == NULL){ | 732 | if (bufptr == NULL){ |
742 | pl_malloc_init(); | 733 | pl_malloc_init(); |
743 | } | 734 | } |
@@ -769,12 +760,10 @@ struct pgn_game_node* pgn_init_game(const struct plugin_api* api){ | |||
769 | return game; | 760 | return game; |
770 | } | 761 | } |
771 | 762 | ||
772 | void pgn_append_ply(const struct plugin_api* api, struct pgn_game_node* game, | 763 | void pgn_append_ply(struct pgn_game_node* game, |
773 | unsigned short ply_player, char *move_buffer, bool is_mate){ | 764 | unsigned short ply_player, char *move_buffer, bool is_mate){ |
774 | struct pgn_ply_node ply_size, *ply, *temp; | 765 | struct pgn_ply_node ply_size, *ply, *temp; |
775 | 766 | ||
776 | rb = api; | ||
777 | |||
778 | ply = (struct pgn_ply_node *)pl_malloc(sizeof ply_size); | 767 | ply = (struct pgn_ply_node *)pl_malloc(sizeof ply_size); |
779 | ply->player = ply_player; | 768 | ply->player = ply_player; |
780 | ply->column_from = move_buffer[0] - 'a'; | 769 | ply->column_from = move_buffer[0] - 'a'; |
@@ -803,11 +792,9 @@ void pgn_append_ply(const struct plugin_api* api, struct pgn_game_node* game, | |||
803 | temp->prev_node = ply; | 792 | temp->prev_node = ply; |
804 | } | 793 | } |
805 | 794 | ||
806 | void pgn_set_result(const struct plugin_api* api, struct pgn_game_node* game, | 795 | void pgn_set_result(struct pgn_game_node* game, |
807 | bool is_mate){ | 796 | bool is_mate){ |
808 | 797 | ||
809 | rb = api; | ||
810 | |||
811 | struct pgn_ply_node *ply; | 798 | struct pgn_ply_node *ply; |
812 | for(ply=game->first_ply;ply->next_node != NULL;ply=ply->next_node); | 799 | for(ply=game->first_ply;ply->next_node != NULL;ply=ply->next_node); |
813 | if (is_mate){ | 800 | if (is_mate){ |
@@ -817,15 +804,13 @@ void pgn_set_result(const struct plugin_api* api, struct pgn_game_node* game, | |||
817 | } | 804 | } |
818 | } | 805 | } |
819 | 806 | ||
820 | void pgn_store_game(const struct plugin_api* api, struct pgn_game_node* game){ | 807 | void pgn_store_game(struct pgn_game_node* game){ |
821 | int fhandler; | 808 | int fhandler; |
822 | struct pgn_ply_node *ply; | 809 | struct pgn_ply_node *ply; |
823 | unsigned ply_count; | 810 | unsigned ply_count; |
824 | size_t line_length=0; | 811 | size_t line_length=0; |
825 | char buffer[10]; | 812 | char buffer[10]; |
826 | 813 | ||
827 | rb = api; | ||
828 | |||
829 | GNUChess_Initialize(); | 814 | GNUChess_Initialize(); |
830 | 815 | ||
831 | ply_count=0; | 816 | ply_count=0; |