From 955f2fbc90b562faab185bae43f308eb66e3458c Mon Sep 17 00:00:00 2001 From: Murilo Pereira Date: Mon, 6 Jun 2011 02:16:54 -0300 Subject: [PATCH] Name-spaced functions for frame. --- src/card.c | 12 ++++++------ src/frame.c | 14 +++++++------- src/frame.h | 10 +++++----- src/game.c | 10 +++++----- tests/frame_test.c | 32 ++++++++++++++++---------------- tests/test_helper_test.c | 12 ++++++------ 6 files changed, 45 insertions(+), 45 deletions(-) diff --git a/src/card.c b/src/card.c index ab17c05..c78d3a8 100644 --- a/src/card.c +++ b/src/card.c @@ -11,18 +11,18 @@ void card_malloc(struct card **card) { fprintf(stderr, tty_solitaire_error_message(errno, __FILE__, __LINE__)); exit(errno); } - allocate_frame(&((*card)->frame)); + frame_malloc(&((*card)->frame)); } void card_init(struct card *card) { - initialize_frame(card->frame); + frame_init(card->frame); card->value = NO_VALUE; card->suit = NO_SUIT; card->face = NO_FACE; } void card_free(struct card *card) { - free_frame(card->frame); + frame_free(card->frame); free(card); } @@ -32,7 +32,7 @@ void card_set(struct card *card, enum face face, int begin_y, int begin_x) { - set_frame(card->frame, begin_y, begin_x); + frame_set(card->frame, begin_y, begin_x); card->value = value; card->suit = suit; card->face = face; @@ -47,11 +47,11 @@ void card_cover(struct card *card) { } void card_mark(struct card *card) { - set_frame(card->frame, card->frame->begin_y + 1, card->frame->begin_x); + frame_set(card->frame, card->frame->begin_y + 1, card->frame->begin_x); } void card_unmark(struct card *card) { - set_frame(card->frame, card->frame->begin_y - 1, card->frame->begin_x); + frame_set(card->frame, card->frame->begin_y - 1, card->frame->begin_x); } struct card *card_dup(struct card *card) { diff --git a/src/frame.c b/src/frame.c index 763f2ec..643f02a 100644 --- a/src/frame.c +++ b/src/frame.c @@ -6,7 +6,7 @@ #include "frame.h" #include "common.h" -void allocate_frame(struct frame **frame) { +void frame_malloc(struct frame **frame) { if (!(*frame = malloc(sizeof(**frame)))) { fprintf(stderr, tty_solitaire_error_message(errno, __FILE__, __LINE__)); exit(errno); @@ -14,27 +14,27 @@ void allocate_frame(struct frame **frame) { (*frame)->window = newwin(FRAME_HEIGHT, FRAME_WIDTH, 0, 0); } -void initialize_frame(struct frame *frame) { +void frame_init(struct frame *frame) { frame->begin_y = 0; frame->begin_x = 0; } -void free_frame(struct frame *frame) { +void frame_free(struct frame *frame) { delwin(frame->window); free(frame); } -void set_frame(struct frame *frame, int begin_y, int begin_x) { +void frame_set(struct frame *frame, int begin_y, int begin_x) { frame->begin_y = begin_y; frame->begin_x = begin_x; mvwin(frame->window, begin_y, begin_x); } -struct frame *duplicate_frame(struct frame *frame) { +struct frame *frame_dup(struct frame *frame) { struct frame *new_frame; - allocate_frame(&new_frame); - set_frame(new_frame, frame->begin_y, frame->begin_x); + frame_malloc(&new_frame); + frame_set(new_frame, frame->begin_y, frame->begin_x); return(new_frame); } diff --git a/src/frame.h b/src/frame.h index ccb65cd..333872b 100644 --- a/src/frame.h +++ b/src/frame.h @@ -12,10 +12,10 @@ struct frame { int begin_x; }; -void allocate_frame(struct frame **); -void initialize_frame(struct frame *); -void free_frame(struct frame *); -void set_frame(struct frame *, int, int); -struct frame *duplicate_frame(struct frame *); +void frame_malloc(struct frame **); +void frame_init(struct frame *); +void frame_free(struct frame *); +void frame_set(struct frame *, int, int); +struct frame *frame_dup(struct frame *); #endif diff --git a/src/game.c b/src/game.c index 5008ead..af09df3 100644 --- a/src/game.c +++ b/src/game.c @@ -110,7 +110,7 @@ void move_card(struct stack **origin, struct stack **destination) { destination_y++; } stack_push(destination, tmp); - set_frame((*destination)->card->frame, destination_y, destination_x); + frame_set((*destination)->card->frame, destination_y, destination_x); } } @@ -184,13 +184,13 @@ void game_init() { deck_init(deck); /* Setting initial stacks' coordinates. */ - set_frame(deck->stock->card->frame, STOCK_BEGIN_Y, STOCK_BEGIN_X); - set_frame(deck->waste_pile->card->frame, WASTE_PILE_BEGIN_Y, WASTE_PILE_BEGIN_X); + frame_set(deck->stock->card->frame, STOCK_BEGIN_Y, STOCK_BEGIN_X); + frame_set(deck->waste_pile->card->frame, WASTE_PILE_BEGIN_Y, WASTE_PILE_BEGIN_X); for (int i = 0; i < FOUNDATION_STACKS_NUMBER; i++) { - set_frame(deck->foundation[i]->card->frame, FOUNDATION_BEGIN_Y, foundation_begin_x(i)); + frame_set(deck->foundation[i]->card->frame, FOUNDATION_BEGIN_Y, foundation_begin_x(i)); } for (int i = 0; i < MANEUVRE_STACKS_NUMBER; i++) { - set_frame(deck->maneuvre[i]->card->frame, MANEUVRE_BEGIN_Y, maneuvre_begin_x(i)); + frame_set(deck->maneuvre[i]->card->frame, MANEUVRE_BEGIN_Y, maneuvre_begin_x(i)); } fill_deck(deck); diff --git a/tests/frame_test.c b/tests/frame_test.c index 2ce7bce..fecae56 100644 --- a/tests/frame_test.c +++ b/tests/frame_test.c @@ -2,48 +2,48 @@ #include "test_helper.h" #include "../src/frame.h" -void test_initialize_frame() { +void test_frame_init() { struct frame *frame; - allocate_frame(&frame); - initialize_frame(frame); + frame_malloc(&frame); + frame_init(frame); assert(frame->window == NULL); assert(frame->begin_y == 0); assert(frame->begin_x == 0); - free_frame(frame); + frame_free(frame); } -void test_duplicate_frame() { +void test_frame_dup() { struct frame *frame_0, *frame_1; const int begin_y = 5, begin_x = 10; - allocate_frame(&frame_0); - set_frame(frame_0, begin_y, begin_x); - frame_1 = duplicate_frame(frame_0); + frame_malloc(&frame_0); + frame_set(frame_0, begin_y, begin_x); + frame_1 = frame_dup(frame_0); assert(frame_0 != frame_1); assert(frames_equal(frame_0, frame_1)); } -void test_set_frame() { +void test_frame_set() { struct frame *frame; int begin_y = 5; int begin_x = 10; - allocate_frame(&frame); - initialize_frame(frame); - set_frame(frame, begin_y, begin_x); + frame_malloc(&frame); + frame_init(frame); + frame_set(frame, begin_y, begin_x); assert(frame->begin_y == begin_y); assert(frame->begin_x == begin_x); - free_frame(frame); + frame_free(frame); } void test_frame() { - test_initialize_frame(); - test_duplicate_frame(); - test_set_frame(); + test_frame_init(); + test_frame_dup(); + test_frame_set(); } diff --git a/tests/test_helper_test.c b/tests/test_helper_test.c index 5167ead..a16921a 100644 --- a/tests/test_helper_test.c +++ b/tests/test_helper_test.c @@ -8,7 +8,7 @@ void test_frames_equal_with_two_nulls() { void test_frames_equal_with_one_null() { struct frame *frame; - allocate_frame(&frame); + frame_malloc(&frame); assert(!frames_equal(frame, NULL)); assert(!frames_equal(NULL, frame)); } @@ -17,10 +17,10 @@ void test_frames_equal_with_two_equivalent_frames() { struct frame *frame_0, *frame_1; const int begin_y = 5, begin_x = 10; - allocate_frame(&frame_0); - allocate_frame(&frame_1); - set_frame(frame_0, begin_y, begin_x); - set_frame(frame_1, begin_y, begin_x); + frame_malloc(&frame_0); + frame_malloc(&frame_1); + frame_set(frame_0, begin_y, begin_x); + frame_set(frame_1, begin_y, begin_x); assert(frames_equal(frame_0, frame_1)); } @@ -28,7 +28,7 @@ void test_frames_equal_with_two_equivalent_frames() { void test_frames_equal_with_two_frame_pointers_to_the_same_address() { struct frame *frame; - allocate_frame(&frame); + frame_malloc(&frame); assert(frames_equal(frame, frame)); }