Less mental retardation.
This commit is contained in:
		
							parent
							
								
									ea9ff3cfb5
								
							
						
					
					
						commit
						4802244efa
					
				
							
								
								
									
										3
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								Makefile
									
									
									
									
									
								
							@ -5,7 +5,8 @@ LDFLAGS = -lncursesw
 | 
			
		||||
EXECUTABLE = bin/ttysolitaire
 | 
			
		||||
LIB_DIR    = lib
 | 
			
		||||
SRC        = ${LIB_DIR}/ttysolitaire.c
 | 
			
		||||
LIB_OBJECTS = ${LIB_DIR}/frame.o    \
 | 
			
		||||
LIB_OBJECTS = ${LIB_DIR}/common.o   \
 | 
			
		||||
              ${LIB_DIR}/frame.o    \
 | 
			
		||||
              ${LIB_DIR}/card.o     \
 | 
			
		||||
              ${LIB_DIR}/stack.o    \
 | 
			
		||||
              ${LIB_DIR}/deck.o     \
 | 
			
		||||
 | 
			
		||||
@ -4,10 +4,11 @@
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include <errno.h>
 | 
			
		||||
#include "card.h"
 | 
			
		||||
#include "common.h"
 | 
			
		||||
 | 
			
		||||
void allocate_card(struct card **card) {
 | 
			
		||||
  if (!(*card = malloc(sizeof(**card)))) {
 | 
			
		||||
    fprintf(stderr, "%s: %s (%s:%d)\n", program_name, strerror(errno), __FILE__, __LINE__ - 1);
 | 
			
		||||
    fprintf(stderr, tty_solitaire_error_message(errno, __FILE__, __LINE__));
 | 
			
		||||
    exit(errno);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -41,8 +41,6 @@ struct card {
 | 
			
		||||
  enum face    face;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
extern const char *program_name;
 | 
			
		||||
 | 
			
		||||
void allocate_card(struct card **);
 | 
			
		||||
void initialize_card(struct card *);
 | 
			
		||||
struct card *duplicate_card(struct card *);
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										16
									
								
								lib/common.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								lib/common.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,16 @@
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <malloc.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include "common.h"
 | 
			
		||||
 | 
			
		||||
char *tty_solitaire_error_message(int errno, char *file, int line) {
 | 
			
		||||
  char *message = malloc(sizeof(ERROR_MESSAGE_BUFFER_SIZE));
 | 
			
		||||
  snprintf(message,
 | 
			
		||||
           ERROR_MESSAGE_BUFFER_SIZE,
 | 
			
		||||
           "%s: %s (%s:%d)\n",
 | 
			
		||||
           program_name,
 | 
			
		||||
           strerror(errno),
 | 
			
		||||
           file,
 | 
			
		||||
           line - 1);
 | 
			
		||||
  return(message);
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										8
									
								
								lib/common.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								lib/common.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,8 @@
 | 
			
		||||
#ifndef COMMON_H
 | 
			
		||||
#define COMMON_H
 | 
			
		||||
 | 
			
		||||
extern const char *program_name;
 | 
			
		||||
#define ERROR_MESSAGE_BUFFER_SIZE 100
 | 
			
		||||
char *tty_solitaire_error_message(int, char *, int);
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
@ -7,10 +7,11 @@
 | 
			
		||||
#include "display.h"
 | 
			
		||||
#include "game.h"
 | 
			
		||||
#include "cursor.h"
 | 
			
		||||
#include "common.h"
 | 
			
		||||
 | 
			
		||||
void allocate_cursor(struct cursor **cursor) {
 | 
			
		||||
  if (!(*cursor = malloc(sizeof(**cursor)))) {
 | 
			
		||||
    fprintf(stderr, "%s: %s (%s:%d)\n", program_name, strerror(errno), __FILE__, __LINE__ - 1);
 | 
			
		||||
    fprintf(stderr, tty_solitaire_error_message(errno, __FILE__, __LINE__));
 | 
			
		||||
    exit(errno);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -32,7 +32,6 @@ struct cursor {
 | 
			
		||||
enum movement { LEFT, DOWN, UP, RIGHT };
 | 
			
		||||
 | 
			
		||||
extern struct deck *deck;
 | 
			
		||||
extern const char *program_name;
 | 
			
		||||
 | 
			
		||||
void allocate_cursor(struct cursor **);
 | 
			
		||||
void initialize_cursor(struct cursor *);
 | 
			
		||||
 | 
			
		||||
@ -4,10 +4,11 @@
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include <errno.h>
 | 
			
		||||
#include "deck.h"
 | 
			
		||||
#include "common.h"
 | 
			
		||||
 | 
			
		||||
void allocate_deck(struct deck **deck) {
 | 
			
		||||
  if (!(*deck = malloc(sizeof(**deck)))) {
 | 
			
		||||
    fprintf(stderr, "%s: %s (%s:%d)\n", program_name, strerror(errno), __FILE__, __LINE__ - 1);
 | 
			
		||||
    fprintf(stderr, tty_solitaire_error_message(errno, __FILE__, __LINE__));
 | 
			
		||||
    exit(errno);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -21,8 +21,6 @@ struct deck {
 | 
			
		||||
  struct stack *maneuvre_6;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
extern const char *program_name;
 | 
			
		||||
 | 
			
		||||
void allocate_deck(struct deck **);
 | 
			
		||||
void initialize_deck(struct deck *);
 | 
			
		||||
void free_deck(struct deck *);
 | 
			
		||||
 | 
			
		||||
@ -6,12 +6,13 @@
 | 
			
		||||
#include <ncurses.h>
 | 
			
		||||
#include "game.h"
 | 
			
		||||
#include "display.h"
 | 
			
		||||
#include "common.h"
 | 
			
		||||
 | 
			
		||||
static char *card_suit(enum suit suit) {
 | 
			
		||||
  char *card_suit;
 | 
			
		||||
 | 
			
		||||
  if (!(card_suit = malloc(5 * sizeof(*card_suit)))) {
 | 
			
		||||
    fprintf(stderr, "%s: %s (%s:%d)\n", program_name, strerror(errno), __FILE__, __LINE__ - 1);
 | 
			
		||||
    fprintf(stderr, tty_solitaire_error_message(errno, __FILE__, __LINE__));
 | 
			
		||||
    exit(errno);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@ -30,7 +31,7 @@ static char *card_value(enum value value) {
 | 
			
		||||
  char *card_value;
 | 
			
		||||
 | 
			
		||||
  if (!(card_value = malloc(2 * sizeof(*card_value)))) {
 | 
			
		||||
    fprintf(stderr, "%s: %s (%s:%d)\n", program_name, strerror(errno), __FILE__, __LINE__ - 1);
 | 
			
		||||
    fprintf(stderr, tty_solitaire_error_message(errno, __FILE__, __LINE__));
 | 
			
		||||
    exit(errno);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -18,8 +18,6 @@
 | 
			
		||||
#define WHITE_ON_BLUE  3
 | 
			
		||||
#define WHITE_ON_GREEN 4
 | 
			
		||||
 | 
			
		||||
extern const char *program_name;
 | 
			
		||||
 | 
			
		||||
void erase_stack(struct stack *);
 | 
			
		||||
void draw_value(struct card *);
 | 
			
		||||
void draw_suit(struct card *);
 | 
			
		||||
 | 
			
		||||
@ -4,10 +4,11 @@
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include <errno.h>
 | 
			
		||||
#include "frame.h"
 | 
			
		||||
#include "common.h"
 | 
			
		||||
 | 
			
		||||
void allocate_frame(struct frame **frame) {
 | 
			
		||||
  if (!(*frame = malloc(sizeof(**frame)))) {
 | 
			
		||||
    fprintf(stderr, "%s: %s (%s:%d)\n", program_name, strerror(errno), __FILE__, __LINE__ - 1);
 | 
			
		||||
    fprintf(stderr, tty_solitaire_error_message(errno, __FILE__, __LINE__));
 | 
			
		||||
    exit(errno);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -12,8 +12,6 @@ struct frame {
 | 
			
		||||
  int    start_x;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
extern const char *program_name;
 | 
			
		||||
 | 
			
		||||
void allocate_frame(struct frame **);
 | 
			
		||||
void initialize_frame(struct frame *);
 | 
			
		||||
struct frame *duplicate_frame(struct frame *);
 | 
			
		||||
 | 
			
		||||
@ -6,6 +6,7 @@
 | 
			
		||||
#include <time.h>
 | 
			
		||||
#include "display.h"
 | 
			
		||||
#include "util.h"
 | 
			
		||||
#include "common.h"
 | 
			
		||||
#include "game.h"
 | 
			
		||||
 | 
			
		||||
bool stock_stack(struct stack *stack) {
 | 
			
		||||
@ -198,7 +199,7 @@ static void shuffle_deck(struct deck *deck) {
 | 
			
		||||
  int random;
 | 
			
		||||
 | 
			
		||||
  if (!(stack = malloc(NUMBER_OF_CARDS * sizeof(*stack)))) {
 | 
			
		||||
    fprintf(stderr, "%s: %s (%s:%d)\n", program_name, strerror(errno), __FILE__, __LINE__ - 1);
 | 
			
		||||
    fprintf(stderr, tty_solitaire_error_message(errno, __FILE__, __LINE__));
 | 
			
		||||
    exit(errno);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -30,7 +30,6 @@
 | 
			
		||||
#define MANEUVRE_5_STARTING_X   41
 | 
			
		||||
#define MANEUVRE_6_STARTING_X   49
 | 
			
		||||
 | 
			
		||||
extern const char *program_name;
 | 
			
		||||
struct deck *deck;
 | 
			
		||||
struct cursor *cursor;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -8,7 +8,7 @@
 | 
			
		||||
 | 
			
		||||
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);
 | 
			
		||||
    fprintf(stderr, tty_solitaire_error_message(errno, __FILE__, __LINE__));
 | 
			
		||||
    exit(errno);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -8,8 +8,6 @@ struct stack {
 | 
			
		||||
  struct stack *next;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
extern const char *program_name;
 | 
			
		||||
 | 
			
		||||
void allocate_stack(struct stack **);
 | 
			
		||||
void initialize_stack(struct stack *);
 | 
			
		||||
struct stack *duplicate_stack(struct stack *);
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user