From 8d1b2ca7b47e0b121c60e8f775b08ae5ec6b114a Mon Sep 17 00:00:00 2001 From: Murilo Pereira Date: Sun, 6 Feb 2011 04:45:53 -0200 Subject: [PATCH] Declaring local functions as static. --- lib/display.c | 4 ++-- lib/display.h | 2 -- lib/game.c | 8 ++++---- lib/game.h | 4 ---- lib/keyboard.c | 11 ++++++----- lib/keyboard.h | 5 ----- lib/stack.c | 38 +++++++++++++++++++------------------- lib/stack.h | 3 --- 8 files changed, 31 insertions(+), 44 deletions(-) diff --git a/lib/display.c b/lib/display.c index aaa6e23..876998a 100644 --- a/lib/display.c +++ b/lib/display.c @@ -7,7 +7,7 @@ #include "display.h" #include "game.h" -char *card_suit(enum suit suit) { +static char *card_suit(enum suit suit) { char *card_suit; if (!(card_suit = malloc(5 * sizeof(*card_suit)))) { @@ -26,7 +26,7 @@ char *card_suit(enum suit suit) { return(card_suit); } -char *card_value(enum value value) { +static char *card_value(enum value value) { char *card_value; if (!(card_value = malloc(2 * sizeof(*card_value)))) { diff --git a/lib/display.h b/lib/display.h index 2cb826a..d36df18 100644 --- a/lib/display.h +++ b/lib/display.h @@ -19,8 +19,6 @@ extern const char *program_name; -char *card_suit(enum suit); -char *card_value(enum value); void erase_stack(struct stack *); void draw_empty_stacks(); void draw_value(struct card *); diff --git a/lib/game.c b/lib/game.c index db34c31..b73c3b0 100644 --- a/lib/game.c +++ b/lib/game.c @@ -10,7 +10,7 @@ #include "game.h" #include "../debug/deck_debug.h" // noob debugging -void set_stacks_initial_coordinates(struct deck *deck) { +static void set_stacks_initial_coordinates(struct deck *deck) { set_frame(deck->stock->card->frame, STOCK_STARTING_Y, STOCK_STARTING_X); @@ -54,7 +54,7 @@ void set_stacks_initial_coordinates(struct deck *deck) { return; } -void fill_deck(struct deck *deck) { +static void fill_deck(struct deck *deck) { struct card *card[NUMBER_OF_CARDS]; for (int i = 0; i < NUMBER_OF_CARDS; i++) { @@ -120,7 +120,7 @@ void fill_deck(struct deck *deck) { return; } -void shuffle_deck(struct deck *deck) { +static void shuffle_deck(struct deck *deck) { struct stack **stack = NULL; struct stack tmp; int random; @@ -150,7 +150,7 @@ void shuffle_deck(struct deck *deck) { return; } -void deal_cards(struct deck *deck) { +static void deal_cards(struct deck *deck) { move_card(&(deck->stock), &(deck->maneuvre_0)); expose_card(deck->maneuvre_0->card); move_card(&(deck->stock), &(deck->maneuvre_1)); diff --git a/lib/game.h b/lib/game.h index 06f7476..034f5ff 100644 --- a/lib/game.h +++ b/lib/game.h @@ -10,10 +10,6 @@ extern const char *program_name; struct deck *deck; struct cursor *cursor; -void set_stacks_initial_coordinates(struct deck *); -void fill_deck(struct deck *); -void shuffle_deck(struct deck *); -void deal_cards(struct deck *); void greet_player(); void initialize_game(); void end_game(); diff --git a/lib/keyboard.c b/lib/keyboard.c index e12820b..e8eda0d 100644 --- a/lib/keyboard.c +++ b/lib/keyboard.c @@ -3,7 +3,7 @@ #include "display.h" #include "keyboard.h" -struct stack *cursor_stack(struct cursor *cursor) { +static struct stack *cursor_stack(struct cursor *cursor) { struct stack *cursor_stack = NULL; if (cursor->y == CURSOR_STARTING_Y) { @@ -30,15 +30,16 @@ struct stack *cursor_stack(struct cursor *cursor) { return(cursor_stack); } -bool cursor_on_stack(struct cursor *cursor, struct stack *stack) { +static bool cursor_on_stack(struct cursor *cursor, struct stack *stack) { return(cursor_stack(cursor) == stack); } -bool cursor_on_invalid_spot(struct cursor *cursor) { +static bool cursor_on_invalid_spot(struct cursor *cursor) { return(cursor->x == CURSOR_INVALID_SPOT_X && cursor->y == CURSOR_INVALID_SPOT_Y); } -void handle_stock_event() { + +static void handle_stock_event() { if (!empty(deck->stock)) { /* erase the stack before emptying it */ if (length(deck->stock) == 1) { @@ -53,7 +54,7 @@ void handle_stock_event() { return; } -void handle_card_movement(struct cursor *cursor) { +static void handle_card_movement(struct cursor *cursor) { struct stack *origin = NULL; struct stack *destination = NULL; int option; diff --git a/lib/keyboard.h b/lib/keyboard.h index 96125d3..a00047e 100644 --- a/lib/keyboard.h +++ b/lib/keyboard.h @@ -9,11 +9,6 @@ extern struct deck *deck; extern struct cursor *cursor; -struct stack *cursor_stack(struct cursor *); -bool cursor_on_stack(struct cursor *, struct stack *); -bool cursor_on_invalid_spot(struct cursor *); -void handle_stock_event(); -void handle_card_movement(struct cursor *); void handle_keyboard_event(); #endif diff --git a/lib/stack.c b/lib/stack.c index a6b8ff9..36e29c1 100644 --- a/lib/stack.c +++ b/lib/stack.c @@ -6,6 +6,25 @@ #include #include "stack.h" +static bool maneuvre_stack(struct stack *stack) { + return(stack->card->frame->start_y >= MANEUVRE_STACKS_STARTING_Y); +} + +static bool waste_pile_stack(struct stack *stack) { + return((stack->card->frame->start_x == WASTE_PILE_STARTING_X) && + (stack->card->frame->start_y == WASTE_PILE_STARTING_Y)); +} + +static void refresh_card_coordinates(struct stack *origin, struct stack *destination) { + origin->card->frame->start_x = destination->card->frame->start_x; + origin->card->frame->start_y = destination->card->frame->start_y; + if (!empty(destination) && maneuvre_stack(destination)) { + origin->card->frame->start_y++; + } + + return; +} + void allocate_stack(struct stack **stack) { if (!(*stack = malloc(sizeof(**stack)))) { fprintf(stderr, "%s: %s (%s:%d)\n", program_name, strerror(errno), __FILE__, __LINE__ - 1); @@ -85,25 +104,6 @@ struct stack *pop(struct stack **stack) { return(popped_entry); } -bool maneuvre_stack(struct stack *stack) { - return(stack->card->frame->start_y >= MANEUVRE_STACKS_STARTING_Y); -} - -bool waste_pile_stack(struct stack *stack) { - return((stack->card->frame->start_x == WASTE_PILE_STARTING_X) && - (stack->card->frame->start_y == WASTE_PILE_STARTING_Y)); -} - -void refresh_card_coordinates(struct stack *origin, struct stack *destination) { - origin->card->frame->start_x = destination->card->frame->start_x; - origin->card->frame->start_y = destination->card->frame->start_y; - if (!empty(destination) && maneuvre_stack(destination)) { - origin->card->frame->start_y++; - } - - return; -} - void move_card(struct stack **origin, struct stack **destination) { struct stack *stack = NULL; diff --git a/lib/stack.h b/lib/stack.h index c79ee4d..0702e16 100644 --- a/lib/stack.h +++ b/lib/stack.h @@ -40,9 +40,6 @@ bool empty(struct stack *); int length(struct stack *); void push(struct stack **, struct card *); struct stack *pop(struct stack **); -bool maneuvre_stack(struct stack *); -bool waste_pile_stack(struct stack *); -void refresh_card_coordinates(struct stack *, struct stack *); void move_card(struct stack **, struct stack **); #endif