Declaring local functions as static.

This commit is contained in:
Murilo Pereira 2011-02-06 04:45:53 -02:00
parent 83df7ba92f
commit 8d1b2ca7b4
8 changed files with 31 additions and 44 deletions

View File

@ -7,7 +7,7 @@
#include "display.h" #include "display.h"
#include "game.h" #include "game.h"
char *card_suit(enum suit suit) { static char *card_suit(enum suit suit) {
char *card_suit; char *card_suit;
if (!(card_suit = malloc(5 * sizeof(*card_suit)))) { if (!(card_suit = malloc(5 * sizeof(*card_suit)))) {
@ -26,7 +26,7 @@ char *card_suit(enum suit suit) {
return(card_suit); return(card_suit);
} }
char *card_value(enum value value) { static char *card_value(enum value value) {
char *card_value; char *card_value;
if (!(card_value = malloc(2 * sizeof(*card_value)))) { if (!(card_value = malloc(2 * sizeof(*card_value)))) {

View File

@ -19,8 +19,6 @@
extern const char *program_name; extern const char *program_name;
char *card_suit(enum suit);
char *card_value(enum value);
void erase_stack(struct stack *); void erase_stack(struct stack *);
void draw_empty_stacks(); void draw_empty_stacks();
void draw_value(struct card *); void draw_value(struct card *);

View File

@ -10,7 +10,7 @@
#include "game.h" #include "game.h"
#include "../debug/deck_debug.h" // noob debugging #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, set_frame(deck->stock->card->frame,
STOCK_STARTING_Y, STOCK_STARTING_Y,
STOCK_STARTING_X); STOCK_STARTING_X);
@ -54,7 +54,7 @@ void set_stacks_initial_coordinates(struct deck *deck) {
return; return;
} }
void fill_deck(struct deck *deck) { static void fill_deck(struct deck *deck) {
struct card *card[NUMBER_OF_CARDS]; struct card *card[NUMBER_OF_CARDS];
for (int i = 0; i < NUMBER_OF_CARDS; i++) { for (int i = 0; i < NUMBER_OF_CARDS; i++) {
@ -120,7 +120,7 @@ void fill_deck(struct deck *deck) {
return; return;
} }
void shuffle_deck(struct deck *deck) { static void shuffle_deck(struct deck *deck) {
struct stack **stack = NULL; struct stack **stack = NULL;
struct stack tmp; struct stack tmp;
int random; int random;
@ -150,7 +150,7 @@ void shuffle_deck(struct deck *deck) {
return; return;
} }
void deal_cards(struct deck *deck) { static void deal_cards(struct deck *deck) {
move_card(&(deck->stock), &(deck->maneuvre_0)); move_card(&(deck->stock), &(deck->maneuvre_0));
expose_card(deck->maneuvre_0->card); expose_card(deck->maneuvre_0->card);
move_card(&(deck->stock), &(deck->maneuvre_1)); move_card(&(deck->stock), &(deck->maneuvre_1));

View File

@ -10,10 +10,6 @@ extern const char *program_name;
struct deck *deck; struct deck *deck;
struct cursor *cursor; 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 greet_player();
void initialize_game(); void initialize_game();
void end_game(); void end_game();

View File

@ -3,7 +3,7 @@
#include "display.h" #include "display.h"
#include "keyboard.h" #include "keyboard.h"
struct stack *cursor_stack(struct cursor *cursor) { static struct stack *cursor_stack(struct cursor *cursor) {
struct stack *cursor_stack = NULL; struct stack *cursor_stack = NULL;
if (cursor->y == CURSOR_STARTING_Y) { if (cursor->y == CURSOR_STARTING_Y) {
@ -30,15 +30,16 @@ struct stack *cursor_stack(struct cursor *cursor) {
return(cursor_stack); 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); 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 && return(cursor->x == CURSOR_INVALID_SPOT_X &&
cursor->y == CURSOR_INVALID_SPOT_Y); cursor->y == CURSOR_INVALID_SPOT_Y);
} }
void handle_stock_event() {
static void handle_stock_event() {
if (!empty(deck->stock)) { if (!empty(deck->stock)) {
/* erase the stack before emptying it */ /* erase the stack before emptying it */
if (length(deck->stock) == 1) { if (length(deck->stock) == 1) {
@ -53,7 +54,7 @@ void handle_stock_event() {
return; return;
} }
void handle_card_movement(struct cursor *cursor) { static void handle_card_movement(struct cursor *cursor) {
struct stack *origin = NULL; struct stack *origin = NULL;
struct stack *destination = NULL; struct stack *destination = NULL;
int option; int option;

View File

@ -9,11 +9,6 @@
extern struct deck *deck; extern struct deck *deck;
extern struct cursor *cursor; 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(); void handle_keyboard_event();
#endif #endif

View File

@ -6,6 +6,25 @@
#include <errno.h> #include <errno.h>
#include "stack.h" #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) { void allocate_stack(struct stack **stack) {
if (!(*stack = malloc(sizeof(**stack)))) { if (!(*stack = malloc(sizeof(**stack)))) {
fprintf(stderr, "%s: %s (%s:%d)\n", program_name, strerror(errno), __FILE__, __LINE__ - 1); 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); 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) { void move_card(struct stack **origin, struct stack **destination) {
struct stack *stack = NULL; struct stack *stack = NULL;

View File

@ -40,9 +40,6 @@ bool empty(struct stack *);
int length(struct stack *); int length(struct stack *);
void push(struct stack **, struct card *); void push(struct stack **, struct card *);
struct stack *pop(struct stack **); 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 **); void move_card(struct stack **, struct stack **);
#endif #endif