Matthew Mondor's fork:
authorMatthew Mondor <mmondor@pulsar-zone.net>
Thu, 6 Apr 2023 03:32:15 +0000 (03:32 +0000)
committerMatthew Mondor <mmondor@pulsar-zone.net>
Thu, 6 Apr 2023 03:32:15 +0000 (03:32 +0000)
- Allow to build against BSD curses
- Debug function prototype issues causing bugs on x86-64
- Fix global definitions in headerfiles that should have been in the
  modules then defined extern in the headerfile as needed

14 files changed:
ChangeLog
Makefile
aliens.c
aliens.h
globals.c
globals.h
nInvaders.c
nInvaders.h
player.c
player.h
ufo.c
ufo.h
view.c
view.h

index f6ba535..a08c962 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Matthew Mondor's fork:
+- Allow to build against BSD curses
+- Debug function prototype issues causing bugs on x86-64
+- Fix global definitions in headerfiles that should have been in the
+  modules then defined extern in the headerfile as needed
+
 
 ****** Release 0.1.1 ******
 
index d815e2f..2510ecc 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,16 @@
-CC=gcc
-CFLAGS=-O3 -Wall
-LIBS=-lncurses
+#CFLAGS=-D__USE_NCURSES__ -I/usr/pkg/include -I/usr/pkg/include/ncurses
+#LDFLAGS=-L/usr/pkg/lib -Wl,-rpath,/usr/pkg/lib
+#LIBS=-lncurses
+
+CC=cc
+CFLAGS=-O2 -Wall
+LIBS=-lcurses
+
+# This was very useful to correct important bugs
+#CFLAGS+=-Werror=missing-prototypes -Werror=implicit-function-declaration \
+ -Werror=int-to-pointer-cast -Werror=pointer-to-int-cast \
+ -Werror=format-extra-args -Werror=format= -Werror=maybe-uninitialized
+
 
 CFILES=globals.c view.c aliens.c ufo.c player.c nInvaders.c
 HFILES=globals.h view.h aliens.h ufo.h player.h nInvaders.h
index fa87c5c..242ddb2 100644 (file)
--- a/aliens.c
+++ b/aliens.c
 #include "player.h"
 #include "nInvaders.h"
 
+
+Aliens aliens;
+int shipnum;   
+
+
 /**
  * initialize aliens attributes
  */
index 040d93f..592019c 100644 (file)
--- a/aliens.h
+++ b/aliens.h
@@ -38,9 +38,8 @@ struct Aliens {
        int speed;        // 0: no movement; 1: one per turn; etc.
 };
        
-Aliens aliens;
-               
-int shipnum;   
+extern Aliens aliens;
+extern int shipnum;    
 
 #define ALIENS_MAX_NUMBER_X 10
 #define ALIENS_MAX_NUMBER_Y 5  
@@ -56,23 +55,23 @@ int alienBlock[ALIENS_MAX_NUMBER_Y][ALIENS_MAX_NUMBER_X];
 int bunker[BUNKERHEIGHT][BUNKERWIDTH + 1];     
 
 
-void aliensReset();
-void bunkersReset();   
-int aliensMove();
-int aliensMissileMove();
-void render();
+void aliensReset(void);
+void bunkersReset(void);       
+int aliensMove(void);
+int aliensMissileMove(void);
+void render(void);
 int aliensHitCheck(int shotx, int shoty);
 int bunkersHitCheck(int shotx, int shoty);
 
        
 // methods that handle graphic display, from view.c
-extern void aliensDisplay(int x, int y, int wid, int hgt);
-extern void aliensClear(int x, int y, int wid, int hgt);
-extern void aliensRefresh(int level, int *pAliens);
-extern void aliensMissileDisplay(int x, int y);
-extern void aliensMissileClear(int x, int y);
-extern void bunkersClearElement(int x, int y);
-extern void bunkersClear();
-extern void bunkersRefresh();
+void aliensDisplay(int x, int y, int wid, int hgt);
+void aliensClear(int x, int y, int wid, int hgt);
+void aliensRefresh(int level, int *pAliens);
+void aliensMissileDisplay(int x, int y);
+void aliensMissileClear(int x, int y);
+void bunkersClearElement(int x, int y);
+void bunkersClear(void);
+void bunkersRefresh(void);
        
 #endif
index b0ea03d..8c0204c 100644 (file)
--- a/globals.c
+++ b/globals.c
@@ -50,7 +50,7 @@ void doSleep(int microseconds)
 /**
  * show version information
  */
-void showVersion()
+void showVersion(void)
 {
        fprintf(stderr, "*** nInvaders %i.%i.%i\n", MAJOR, MINOR, RELEASE);
        fprintf(stderr, "*** (C)opyleft 2k2 by Dettus\n");
@@ -65,7 +65,7 @@ void showVersion()
 /**
  * show usage of command line parameters
  */
-void showUsage()
+void showUsage(void)
 {
 
        fprintf(stderr, "\n\nUsage: nInvaders [-l skill] [-gpl]\n");
@@ -79,7 +79,7 @@ void showUsage()
 /**
  * wait for input of return to continue
  */
-void waitForReturn()
+void waitForReturn(void)
 {
        char b[2];
        fprintf(stderr, "...Please press <Enter> to read on...");
@@ -89,7 +89,7 @@ void waitForReturn()
 /**
  * show short version of Gnu GPL
  */
-void showGplShort()
+void showGplShort(void)
 {
        fprintf(stderr,"\n");
        fprintf(stderr,"This program is free software; you can redistribute it and/or modify\n");
@@ -114,7 +114,7 @@ void showGplShort()
 /**
  * show GNU GENERAL PUBLIC LICENSE
  */
-void showGpl()
+void showGpl(void)
 {
        fprintf(stderr, "\n");
        fprintf(stderr, "                   GNU GENERAL PUBLIC LICENSE\n");
index 7eacb9a..bb20231 100644 (file)
--- a/globals.h
+++ b/globals.h
 #ifndef GLOBALS
 #define GLOBALS
 
-extern void doSleep();
+void doSleep(int);
        
-extern void showUsage();
-extern void showVersion();
-extern void showGplShort();
-extern void showGpl();
+void showUsage(void);
+void showVersion(void);
+void waitForReturn(void);
+void showGplShort(void);
+void showGpl(void);
        
 #endif
index 793139c..57a756d 100644 (file)
@@ -35,6 +35,9 @@
 int lives;
 long score;
 int status; // status handled in timer
+int weite;
+int level;
+int skill_level;
 
 #define GAME_LOOP 1
 #define GAME_NEXTLEVEL 2
@@ -49,7 +52,7 @@ int status; // status handled in timer
 /**
  * initialize level: reset attributes of most units
  */
-static void initLevel()
+static void initLevel(void)
 {
        playerReset();
        aliensReset();
@@ -122,7 +125,7 @@ static void finish(int sig)
 }
 
 
-void drawscore()
+void drawscore(void)
 {
        statusDisplay(level, score, lives);
 }
@@ -131,7 +134,7 @@ void drawscore()
 /**
  * reads input from keyboard and do action
  */
-void readInput()
+void readInput(void)
 {
        int ch;
        static int lastmove;
@@ -206,7 +209,7 @@ void readInput()
  * timer
  * this method is executed every 1 / FPS seconds  
  */
-void handleTimer()
+void handleTimer(int sig)
 {
        static int aliens_move_counter = 0; 
        static int aliens_shot_counter = 0;
@@ -310,7 +313,7 @@ void handleTimer()
 /**
  * set up timer
  */
-void setUpTimer()
+void setUpTimer(void)
 {
        struct itimerval myTimer;
        struct sigaction myAction;
@@ -320,7 +323,7 @@ void setUpTimer()
        myTimer.it_interval.tv_usec = 1000000 / FPS;
        setitimer(ITIMER_REAL, &myTimer, NULL);
        
-       myAction.sa_handler = &handleTimer;
+       myAction.sa_handler = handleTimer;
        myAction.sa_flags = SA_RESTART;
        sigaction(SIGALRM, &myAction, NULL);
 }
index 1161321..0c7f6e2 100644 (file)
@@ -41,20 +41,23 @@ int main(int argv, char **argc);    // hey! it has to start somewhere!
 extern void render(void);
        
 void game_over(int a);
-void drawscore();
+void drawscore(void);
                
 void doScoring(int alienType);
 
+void readInput(void);
+void handleTimer(int);
+void setUpTimer(void);
+
 // todo: let's try to not having to declare these "public"
-int weite;
-int level;
-int skill_level;
-       
+extern int weite;
+extern int level;
+extern int skill_level;
+
 // included from globals.h
-extern void doSleep();
-extern void showUsage();
-extern void showVersion();
-extern void showGplShort();
-extern void showGpl();
+extern void showUsage(void);
+extern void showVersion(void);
+extern void showGplShort(void);
+extern void showGpl(void);
 
 #endif
index 698d426..bc4a2dc 100644 (file)
--- a/player.c
+++ b/player.c
@@ -43,7 +43,7 @@ Player player;
 /**
  * initialize player attributes
  */
-void playerReset()
+void playerReset(void)
 {
        // if missile was fired clear that position
        if (player.missileFired == 1) { 
@@ -77,7 +77,7 @@ static void playerMove(int newPosX)
 /**
  * move player left
  */
-void playerMoveLeft()
+void playerMoveLeft(void)
 {
        // check if space between player and border of screen is big enough 
        if (player.posX > 0 + player.speed) {
@@ -93,7 +93,7 @@ void playerMoveLeft()
 /**
  * move player right
  */
-void playerMoveRight()
+void playerMoveRight(void)
 {
        // check if space between player and border of screen is big enough 
        if (player.posX < SCREENWIDTH - PLAYERWIDTH - player.speed) {
@@ -109,7 +109,7 @@ void playerMoveRight()
 /**
  * toggle turbo mode on (if key is kept pressed)
  */
-void playerTurboOn()
+void playerTurboOn(void)
 {
        player.speed = 2;
 }
@@ -118,7 +118,7 @@ void playerTurboOn()
 /**
  * toggle turbo mode off (if key is kept pressed)
  */
-void playerTurboOff()
+void playerTurboOff(void)
 {
        player.speed = 1;
 }
@@ -146,7 +146,7 @@ int playerHitCheck(int hostileShotX, int hostileShotY)
 /**
  * Launch Missile
  */
-void playerLaunchMissile()
+void playerLaunchMissile(void)
 {
        // only launch missile if no other is on its way
        if (player.missileFired == 0) {
@@ -160,7 +160,7 @@ void playerLaunchMissile()
 /**
  * Reload Missile
  */
-static void playerReloadMissile()
+static void playerReloadMissile(void)
 {
        player.missileFired = 0;        // no player missile flying
 }
@@ -170,7 +170,7 @@ static void playerReloadMissile()
  * move player missile and do alien/bunker hit testing
  * return value - 0: still some aliens left, 1: no aliens left
  */
-int playerMoveMissile()
+int playerMoveMissile(void)
 {
        int fNoAliensLeft = 0;  // return value
        int alienTypeHit = 0;
@@ -234,7 +234,7 @@ int playerMoveMissile()
 /** 
  * let player explode
  */
-void playerExplode(){
+void playerExplode(void){
        playerExplosionDisplay(player.posX, player.posY);
        playerDisplay(player.posX, player.posY);
 }
index b48701c..5088779 100644 (file)
--- a/player.h
+++ b/player.h
 #include "view.h"
 
 
-void playerReset();
+void playerReset(void);
        
-void playerMoveLeft();
-void playerMoveRight();
-void playerTurboOn();
-void playerTurboOff();
+void playerMoveLeft(void);
+void playerMoveRight(void);
+void playerTurboOn(void);
+void playerTurboOff(void);
 int playerHitCheck(int hostileShotX, int hostileShotY);
-void playerLaunchMissile();
-int playerMoveMissile();
-void playerExplode();
+void playerLaunchMissile(void);
+int playerMoveMissile(void);
+void playerExplode(void);
        
 // methods that handle graphic display, from view.c
-extern void playerInit();
+extern void playerInit(void);
 extern void playerDisplay(int x, int y);
 extern void playerClear(int x, int y);
-extern void playerMissileInit();
+extern void playerMissileInit(void);
 extern void playerMissileDisplay(int x, int y);
 extern void playerMissileClear(int x, int y);
 extern void playerExplosionDisplay(int x, int y);
diff --git a/ufo.c b/ufo.c
index 928872b..c2acc0c 100644 (file)
--- a/ufo.c
+++ b/ufo.c
@@ -28,6 +28,9 @@
 
 static int fShowUfo = 0;
 
+Ufo ufo;
+
+
 /**
  * initialize ufo attributes
  */
diff --git a/ufo.h b/ufo.h
index 60dc493..843da66 100644 (file)
--- a/ufo.h
+++ b/ufo.h
@@ -34,16 +34,16 @@ struct Ufo {
        int posY;         // vertical position of aliens
 };
        
-Ufo ufo;
+extern Ufo ufo;
 
-void ufoReset();
-int ufoShowUfo();
-void ufoMoveLeft();
+void ufoReset(void);
+int ufoShowUfo(void);
+void ufoMoveLeft(void);
 int ufoHitCheck(int shotX, int shotY);
        
 // methods that handle graphic display, from view.c
 extern void ufoDisplay(int x, int y);
-extern void ufoRefresh();
+extern void ufoRefresh(void);
 extern void ufoClear(int x, int y);
 
 #endif
diff --git a/view.c b/view.c
index aa75a6d..6196971 100644 (file)
--- a/view.c
+++ b/view.c
@@ -53,7 +53,7 @@ WINDOW *wTitleScreen;
 /**
  * initialize player sprites
  */
-static void playerInit()
+static void playerInit(void)
 {
        wPlayer = newpad(1, PLAYERWIDTH);       // new pad with appropriate size
        wclear(wPlayer);                        // clear pad
@@ -83,7 +83,7 @@ void playerClear(int x, int y)
 /**
  * initialize missile sprites
  */
-static void playerMissileInit()
+static void playerMissileInit(void)
 {
        wPlayerMissile = newpad(1, 1);          // new pad with appropriate size
        wclear(wPlayerMissile);                 // clear pad
@@ -141,7 +141,7 @@ void playerExplosionDisplay(int x, int y)
 /**
  * initialize aliens sprites
  */
-static void aliensInit()
+static void aliensInit(void)
 {
        wAliens = newpad(ALIENS_MAX_NUMBER_Y*2,ALIENS_MAX_NUMBER_X*3);
        wclear(wAliens);
@@ -169,7 +169,7 @@ void aliensClear(int x, int y, int wid, int hgt)
 /**
  * initialize missile sprites
  */
-static void aliensMissileInit()
+static void aliensMissileInit(void)
 {
        wAliensMissile = newpad(1, 1);          // new pad
        wclear(wAliensMissile);                 // clear pad
@@ -246,7 +246,7 @@ void aliensRefresh(int level, int *pAliens)
 /**
  * initialize bunkers sprites
  */
-static void bunkersInit()
+static void bunkersInit(void)
 {
        wBunkers = newpad(BUNKERHEIGHT, BUNKERWIDTH);           // new pad data
        wclear(wBunkers);
@@ -279,7 +279,7 @@ void bunkersDisplay(int *pBunker)
 /**
  * clear bunkers sprite
  */
-void bunkersClear() 
+void bunkersClear(void
 {
        copywin(wEmpty, wBattleField, 0, 0, BUNKERY, BUNKERX, BUNKERY + BUNKERHEIGHT - 1, BUNKERX + BUNKERWIDTH - 1, 0);
 }
@@ -297,7 +297,7 @@ void bunkersClearElement(int x, int y)
 /**
  * set actual sprite for ufo animation
  */
-void ufoRefresh()
+void ufoRefresh(void)
 {
        char ufo[4][6] = {"<o o>", "<oo >", "<o o>", "< oo>"};
        static int frame = 0;
@@ -313,7 +313,7 @@ void ufoRefresh()
 /**
  * initialize ufo sprite
  */
-static void ufoInit()
+static void ufoInit(void)
 {
        wUfo = newpad(1, UFOWIDTH);          // new pad with appropriate size
        wclear(wUfo);                        // clear pad
@@ -342,7 +342,7 @@ void ufoClear(int x, int y)
 /**
  * initialize gameover graphic
  */
-static void gameOverInit()
+static void gameOverInit(void)
 {
        // init game-over banner
        wGameOver = newpad(13, 31);
@@ -366,7 +366,7 @@ static void gameOverInit()
 /**
  * display game over graphic
  */ 
-void gameOverDisplay()
+void gameOverDisplay(void)
 {
        int x = (SCREENWIDTH / 2) - (31 / 2);
        int y = (SCREENHEIGHT / 2) - (13 / 2);
@@ -378,7 +378,7 @@ void gameOverDisplay()
 /**
  * initialize title screen
  */
-static void titleScreenInit()
+static void titleScreenInit(void)
 {
        wTitleScreen = newpad(SCREENHEIGHT, SCREENWIDTH);
        wclear(wTitleScreen);
@@ -388,7 +388,7 @@ static void titleScreenInit()
 /**
  * display title screen
  */
-void titleScreenDisplay()
+void titleScreenDisplay(void)
 {
        static int frame = 0;
        int x, y;
@@ -460,7 +460,7 @@ void titleScreenDisplay()
 /**
  * clear title screen
  */
-void titleScreenClear()
+void titleScreenClear(void)
 {
        battleFieldClear();
 }
@@ -469,7 +469,7 @@ void titleScreenClear()
 /**
  * initialize scores
  */
-void statusInit()
+void statusInit(void)
 {
        wStatus = newpad(1, 55);
        wclear(wStatus);
@@ -511,7 +511,7 @@ void statusDisplay(int level, int score, int lives)
 /**
  * initialize battlefield
  */
-static void battleFieldInit()
+static void battleFieldInit(void)
 {
        wEmpty = newpad(SCREENHEIGHT, SCREENWIDTH);
        wclear(wEmpty);
@@ -525,7 +525,7 @@ static void battleFieldInit()
 /**
  * clear battlefield
  */
-void battleFieldClear()
+void battleFieldClear(void)
 {
        copywin(wEmpty,wBattleField,0,0,0,0,SCREENHEIGHT-1,SCREENWIDTH-1,0);
 }
@@ -534,7 +534,7 @@ void battleFieldClear()
 /**
  * refresh screen so that modified graphic buffers get visible
  */
-void refreshScreen()
+void refreshScreen(void)
 {
        redrawwin(wBattleField); // needed to display graphics properly at startup on some terminals
        wrefresh(wBattleField);
@@ -547,6 +547,7 @@ void refreshScreen()
  */
 static void finish(int sig)
 {
+       curs_set(1);
        endwin();       // <curses.h> reset terminal into proper non-visual mode
        exit(0);
 }
@@ -555,10 +556,11 @@ static void finish(int sig)
 /**
  * initialize n_courses
  */
-void graphicEngineInit()
+void graphicEngineInit(void)
 {
        (void) signal(SIGINT, finish);  // <signal.h> on signal "SIGINT" call method "finish"
        (void) initscr();               // <curses.h> do initialization work 
+       curs_set(0);
        keypad(stdscr, TRUE);           // <curses.h> enable keypad for input
        (void) nonl();                  // <curses.h> disable translation return/ newline for detection of return key
        (void) cbreak();                // <curses.h> do not buffer typed characters, use at once
diff --git a/view.h b/view.h
index 873585a..2ee4ef7 100644 (file)
--- a/view.h
+++ b/view.h
  */
  
 
+#ifdef __USE_NCURSES__
 #include <ncurses.h>
+#else
+#include <curses.h>
+#endif
 #include <unistd.h>
 #include <signal.h>
 
 #define UFOPOSY 0
 
        
-void graphicEngineInit();
+void graphicEngineInit(void);
        
 void aliensClear(int x, int y, int wid, int hgt);
 void aliensDisplay(int x, int y, int wid, int hgt);
 void aliensMissileClear(int x, int y);
 void aliensMissileDisplay(int x, int y);
 void aliensRefresh(int level, int *pAliens);
-void battleFieldClear();
-void bunkersClear();
+void battleFieldClear(void);
+void bunkersClear(void);
 void bunkersClearElement(int x, int y);
 void bunkersDisplay(int *pBunker);
-void gameOverDisplay();
+void gameOverDisplay(void);
 void playerClear(int x, int y);
 void playerDisplay(int x, int y);
 void playerExplosionDisplay(int x, int y);
 void playerMissileClear(int x, int y);
 void playerMissileDisplay(int x, int y);
-void titleScreenClear();
-void titleScreenDisplay();
+void titleScreenClear(void);
+void titleScreenDisplay(void);
 void ufoClear(int x, int y);
 void ufoDisplay(int x, int y);
-void ufoRefresh();
+void ufoRefresh(void);
 
+void statusInit(void);
 void statusDisplay(int level, int score, int lives);   
-void refreshScreen();
+void refreshScreen(void);
 
 #endif