Maelstrom: A whole bunch of constness fixes

From 545c4dd1aac78b3ae5521d2b739d5d7e96187755 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Tue, 18 Oct 2011 21:39:12 -0400
Subject: [PATCH] A whole bunch of constness fixes

---
 Maelstrom-netd.c           |  5 +++--
 Maelstrom_Globals.h        |  4 ++--
 checksum.cpp               |  6 +++---
 controls.cpp               | 11 ++++++-----
 dialog.cpp                 |  6 +++---
 dialog.h                   | 10 +++++-----
 load.h                     |  2 +-
 maclib/Mac_FontServ.h      |  2 +-
 maclib/Mac_Resource.cpp    |  3 ++-
 maclib/Mac_Resource.h      |  2 +-
 maclib/Mac_Sound.h         |  2 +-
 maclib/Mac_Wave.h          |  2 +-
 maclib/playwave.cpp        |  2 +-
 main.cpp                   | 10 +++++-----
 myerror.cpp                |  6 +++---
 myerror.h                  |  6 +++---
 netlogic/netplay.cpp       |  6 +++---
 netlogic/netplay.h         |  2 +-
 netscore.cpp               |  4 ++--
 scores.cpp                 | 10 +++++-----
 screenlib/SDL_FrameBuf.cpp |  4 ++--
 screenlib/SDL_FrameBuf.h   |  6 +++---
 22 files changed, 57 insertions(+), 54 deletions(-)

diff --git a/Maelstrom-netd.c b/Maelstrom-netd.c
index 269a9dc2..fa4be99c 100644
--- a/Maelstrom-netd.c
+++ b/Maelstrom-netd.c
@@ -10,6 +10,7 @@
 #include <sys/time.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
+#include <arpa/inet.h>
 #include <netdb.h>
 #include <unistd.h>
 
@@ -156,7 +157,7 @@ printf("Let's party!!\n");
 		for ( i=0; i<numplayers; ++i ) {
 			connection *player = &players[positions[i]];
 
-			strcpy(ptr, (char *)inet_ntoa(player->raddr.sin_addr));
+			strcpy(ptr, inet_ntoa(player->raddr.sin_addr));
 printf("Setting up player %d at host %s and port ", i+1, ptr);
 			len += strlen(ptr)+1;
 			ptr += strlen(ptr)+1;
@@ -366,7 +367,7 @@ printf("Connection received on port %d\n", i);
 			players[slot].raddr.sin_port = 
 						htons((short)ntohl(cliport));
 printf("Player %d arrived on port %d\n", player+1, slot);
-printf("  the remote address is %s:%lu\n",
+printf("  the remote address is %s:%u\n",
 	inet_ntoa(players[slot].raddr.sin_addr),
 	ntohs(players[slot].raddr.sin_port));
 		}
diff --git a/Maelstrom_Globals.h b/Maelstrom_Globals.h
index a4f3547c..4c83cdac 100644
--- a/Maelstrom_Globals.h
+++ b/Maelstrom_Globals.h
@@ -31,9 +31,9 @@ typedef Uint8 Bool;
 
 // Functions from main.cc
 extern void   PrintUsage(void);
-extern int    DrawText(int x, int y, char *text, MFont *font, Uint8 style,
+extern int    DrawText(int x, int y, const char *text, MFont *font, Uint8 style,
 						Uint8 R, Uint8 G, Uint8 B);
-extern void   Message(char *message);
+extern void   Message(const char *message);
 
 // Functions from init.cc
 extern void  SetStar(int which);
diff --git a/checksum.cpp b/checksum.cpp
index 28c109ee..420d75af 100644
--- a/checksum.cpp
+++ b/checksum.cpp
@@ -229,7 +229,7 @@ error("\n");
 }
 
 /* Call this later, when you want to see the checksum */
-char *get_checksum(unsigned char *key, int keylen)
+const char *get_checksum(unsigned char *key, int keylen)
 {
 	unsigned char csum[MD5LEN], seed;
 	int i, j;
@@ -258,10 +258,10 @@ static inline void Unused(...) { }	/* For eliminating compiler warnings */
 
 void checksum(void) { return; }
 
-char *get_checksum(unsigned char *key, int keylen)
+const char *get_checksum(unsigned char *key, int keylen)
 {
 	Unused(key); Unused(keylen);
-	static char *foo = "Checksum Not Enabled";
+	static const char *foo = "Checksum Not Enabled";
 	return(foo);
 }
 #endif /* USE_CHECKSUM */
diff --git a/controls.cpp b/controls.cpp
index 12560e38..e169abe6 100644
--- a/controls.cpp
+++ b/controls.cpp
@@ -68,10 +68,10 @@ void KeyName(SDLKey keycode, char *namebuf)
 	*namebuf = '\0';
 }
 
-static FILE *OpenData(char *mode, char **fname)
+static FILE *OpenData(const char *mode, char **fname)
 {
 	static char datafile[BUFSIZ];
-	char *home;
+	const char *home;
 	FILE *data;
 
 	if ( (home=getenv("HOME")) == NULL ) {
@@ -116,7 +116,8 @@ void LoadControls(void)
 
 void SaveControls(void)
 {
-	char  *datafile, *newmode;
+	char  *datafile;
+	const char *newmode;
 	FILE *data;
 
 	/* Don't clobber existing joystick data */
@@ -154,7 +155,7 @@ void SaveControls(void)
 
 Controls newcontrols;
 static struct {
-	char *label;
+	const char *label;
 	int  yoffset;
 	SDLKey *control;
 } checkboxes[] = {
@@ -496,7 +497,7 @@ int DropEvents(void)
 
 void ShowDawn(void)
 {
-	static char *D_text[6] = {
+	static const char *D_text[6] = {
 		"No eternal reward will forgive us",
 		"now",
 		    "for",
diff --git a/dialog.cpp b/dialog.cpp
index 7c150f9b..0178273f 100644
--- a/dialog.cpp
+++ b/dialog.cpp
@@ -15,7 +15,7 @@ Mac_Dialog::Mac_Dialog(int x, int y)
 }
 
 Mac_Button::Mac_Button(int x, int y, int width, int height,
-				char *text, MFont *font, FontServ *fontserv, 
+				const char *text, MFont *font, FontServ *fontserv, 
 				int (*callback)(void)) : Mac_Dialog(x, y)
 {
 	SDL_Surface *textb;
@@ -58,14 +58,14 @@ Mac_Button::Mac_Button(int x, int y, int width, int height,
 }
 
 Mac_DefaultButton::Mac_DefaultButton(int x, int y, int width, int height,
-				char *text, MFont *font, FontServ *fontserv, 
+				const char *text, MFont *font, FontServ *fontserv, 
 						int (*callback)(void)) : 
 	Mac_Button(x, y, width, height, text, font, fontserv, callback)
 {
 	return;
 }
 
-Mac_CheckBox::Mac_CheckBox(int *toggle, int x, int y, char *text,
+Mac_CheckBox::Mac_CheckBox(int *toggle, int x, int y, const char *text,
 			MFont *font, FontServ *fontserv) : Mac_Dialog(x, y)
 {
 	/* Create the text label */
diff --git a/dialog.h b/dialog.h
index d658d5e4..4a081ac0 100644
--- a/dialog.h
+++ b/dialog.h
@@ -88,7 +88,7 @@ class Mac_Dialog {
 	}
 
 	/* Error message */
-	virtual void SetError(char *fmt, ...) {
+	virtual void SetError(const char *fmt, ...) {
 		va_list ap;
 
 		va_start(ap, fmt);
@@ -109,7 +109,7 @@ class Mac_Button : public Mac_Dialog {
 
 public:
 	Mac_Button(int x, int y, int width, int height,
-		char *text, MFont *font, FontServ *fontserv, 
+		const char *text, MFont *font, FontServ *fontserv, 
 				int (*callback)(void));
 	virtual ~Mac_Button() {
 		SDL_FreeSurface(button);
@@ -217,7 +217,7 @@ class Mac_DefaultButton : public Mac_Button {
 
 public:
 	Mac_DefaultButton(int x, int y, int width, int height,
-				char *text, MFont *font, FontServ *fontserv, 
+				const char *text, MFont *font, FontServ *fontserv, 
 						int (*callback)(void));
 	virtual ~Mac_DefaultButton() { }
 
@@ -285,7 +285,7 @@ class Mac_DefaultButton : public Mac_Button {
 class Mac_CheckBox : public Mac_Dialog {
 
 public:
-	Mac_CheckBox(int *toggle, int x, int y, char *text,
+	Mac_CheckBox(int *toggle, int x, int y, const char *text,
 				MFont *font, FontServ *fontserv);
 	virtual ~Mac_CheckBox() {
 		if ( label ) {
@@ -395,7 +395,7 @@ class Mac_RadioList : public Mac_Dialog {
 		}
 	}
 
-	virtual void Add_Radio(int x, int y, char *text) {
+	virtual void Add_Radio(int x, int y, const char *text) {
 		struct radio *radio;
 
 		for ( radio=&radio_list; radio->next; radio=radio->next )
diff --git a/load.h b/load.h
index 3b4c0cad..d98ba213 100644
--- a/load.h
+++ b/load.h
@@ -97,7 +97,7 @@ class LibPath {
 	}
 
 	const char *Path(const char *filename) {
-		char *directory;
+		const char *directory;
 
 		directory = getenv("MAELSTROM_LIB");
 		if ( directory == NULL ) {
diff --git a/maclib/Mac_FontServ.h b/maclib/Mac_FontServ.h
index e919ccaa..85880e98 100644
--- a/maclib/Mac_FontServ.h
+++ b/maclib/Mac_FontServ.h
@@ -131,7 +131,7 @@ class FontServ {
 	int text_allocated;
 
 	/* Useful for getting error feedback */
-	void SetError(char *fmt, ...) {
+	void SetError(const char *fmt, ...) {
 		va_list ap;
 
 		va_start(ap, fmt);
diff --git a/maclib/Mac_Resource.cpp b/maclib/Mac_Resource.cpp
index 85c184fa..73cefe29 100644
--- a/maclib/Mac_Resource.cpp
+++ b/maclib/Mac_Resource.cpp
@@ -173,7 +173,8 @@ static void CheckMacBinary(FILE *resfile, Uint32 *resbase)
 }
 static FILE *Open_MacRes(char **original, Uint32 *resbase)
 {
-	char *filename, *dirname, *basename, *ptr, *newname;
+	char *filename, *basename, *ptr, *newname;
+	const char *dirname;
 	FILE *resfile=NULL;
 
 	/* Search and replace characters */
diff --git a/maclib/Mac_Resource.h b/maclib/Mac_Resource.h
index 1115b2d8..60f209cc 100644
--- a/maclib/Mac_Resource.h
+++ b/maclib/Mac_Resource.h
@@ -92,7 +92,7 @@ class Mac_Resource {
 	Uint32  base;				/* The offset of the rsrc */
 
 	/* Useful for getting error feedback */
-	void error(char *fmt, ...) {
+	void error(const char *fmt, ...) {
 		va_list ap;
 
 		va_start(ap, fmt);
diff --git a/maclib/Mac_Sound.h b/maclib/Mac_Sound.h
index ba3b36d7..cd48ddf7 100644
--- a/maclib/Mac_Sound.h
+++ b/maclib/Mac_Sound.h
@@ -195,7 +195,7 @@ printf("Freeing Wave id %hu at hash page %d/%d\n",(upper<<8)|lower,upper,lower);
 	}
 
 	/* Useful for getting error feedback */
-	void error(char *fmt, ...) {
+	void error(const char *fmt, ...) {
 		va_list ap;
 
 		va_start(ap, fmt);
diff --git a/maclib/Mac_Wave.h b/maclib/Mac_Wave.h
index 54b03a27..d2428046 100644
--- a/maclib/Mac_Wave.h
+++ b/maclib/Mac_Wave.h
@@ -104,7 +104,7 @@ class Wave {
 			Uint8 **samples, Uint32 n_samples, Uint8 s_size);
 	
 	/* Useful for getting error feedback */
-	void error(char *fmt, ...) {
+	void error(const char *fmt, ...) {
 		va_list ap;
 
 		va_start(ap, fmt);
diff --git a/maclib/playwave.cpp b/maclib/playwave.cpp
index 1e0b7903..d05d771d 100644
--- a/maclib/playwave.cpp
+++ b/maclib/playwave.cpp
@@ -156,7 +156,7 @@ int main(int argc, char *argv[])
 	signal(SIGTERM, CleanUp);
 
 	/* Show what audio format we're playing */
-	printf("Playing %#.2f seconds (%d bit %s) at %lu Hz\n", 
+	printf("Playing %#.2f seconds (%d bit %s) at %u Hz\n", 
 		(double)(wave->DataLeft()/wave->SampleSize())/wave->Frequency(),
 			wave->BitsPerSample(),
 			wave->Stereo() ? "stereo" : "mono", wave->Frequency());
diff --git a/main.cpp b/main.cpp
index 49c23cbd..966dedf3 100644
--- a/main.cpp
+++ b/main.cpp
@@ -19,7 +19,7 @@
 /* External functions used in this file */
 extern int DoInitializations(Uint32 video_flags);		/* init.cc */
 
-static char *Version =
+static const char *Version =
 "Maelstrom v1.4.3 (GPL version 3.0.6) -- 10/19/2002 by Sam Lantinga\n";
 
 // Global variables set in this file...
@@ -35,7 +35,7 @@ static ButtonList buttons;
 // Local functions in this file...
 static void DrawMainScreen(void);
 static void DrawSoundLevel(void);
-static void DrawKey(MPoint *pt, char *ch, char *str, void (*callback)(void));
+static void DrawKey(MPoint *pt, const char *ch, const char *str, void (*callback)(void));
 
 // Main Menu actions:
 static void RunDoAbout(void)
@@ -412,7 +412,7 @@ int main(int argc, char *argv[])
 }	/* -- main */
 
 
-int DrawText(int x, int y, char *text, MFont *font, Uint8 style,
+int DrawText(int x, int y, const char *text, MFont *font, Uint8 style,
 					Uint8 R, Uint8 G, Uint8 B)
 {
 	SDL_Surface *textimage;
@@ -636,7 +636,7 @@ void DrawMainScreen(void)
 /* ----------------------------------------------------------------- */
 /* -- Draw the key and its function */
 
-static void DrawKey(MPoint *pt, char *key, char *text, void (*callback)(void))
+static void DrawKey(MPoint *pt, const char *key, const char *text, void (*callback)(void))
 {
 	MFont *geneva;
 
@@ -657,7 +657,7 @@ static void DrawKey(MPoint *pt, char *key, char *text, void (*callback)(void))
 }	/* -- DrawKey */
 
 
-void Message(char *message)
+void Message(const char *message)
 {
 	static MFont *font;
 	static int xOff;
diff --git a/myerror.cpp b/myerror.cpp
index 83bf1f80..3a748a06 100644
--- a/myerror.cpp
+++ b/myerror.cpp
@@ -10,7 +10,7 @@
 #include <errno.h>
 
 
-void error(char *fmt, ...)
+void error(const char *fmt, ...)
 {
 	char mesg[BUFSIZ];
 	va_list ap;
@@ -21,7 +21,7 @@ void error(char *fmt, ...)
 	va_end(ap);
 }
 
-void mesg(char *fmt, ...)
+void mesg(const char *fmt, ...)
 {
 	char mesg[BUFSIZ];
 	va_list ap;
@@ -32,7 +32,7 @@ void mesg(char *fmt, ...)
 	va_end(ap);
 }
 
-void myperror(char *msg)
+void myperror(const char *msg)
 {
 	char buffer[BUFSIZ];
 
diff --git a/myerror.h b/myerror.h
index 0dd8d973..3cc75d9f 100644
--- a/myerror.h
+++ b/myerror.h
@@ -4,9 +4,9 @@
 
 /* Generic error message routines */
 
-extern void error(char *fmt, ...);
-extern void mesg(char *fmt, ...);
-extern void myperror(char *msg);
+extern void error(const char *fmt, ...);
+extern void mesg(const char *fmt, ...);
+extern void myperror(const char *msg);
 
 #endif /* _myerror_h */
 
diff --git a/netlogic/netplay.cpp b/netlogic/netplay.cpp
index 6c4dc1eb..fd9a7028 100644
--- a/netlogic/netplay.cpp
+++ b/netlogic/netplay.cpp
@@ -100,7 +100,7 @@ void HaltNetData(void)
 	SDLNet_Quit();
 }
 
-int AddPlayer(char *playerstr)
+int AddPlayer(const char *playerstr)
 {
 	int playernum;
 	int portnum;
@@ -471,7 +471,7 @@ static inline void MakeNewPacket(int Wave, int Lives, int Turbo,
 }
 
 /* Flash an error up on the screen and pause for 3 seconds */
-static void ErrorMessage(char *message)
+static void ErrorMessage(const char *message)
 {
 	/* Display the error message */
 	Message(message);
@@ -503,7 +503,7 @@ static int AlertServer(int *Wave, int *Lives, int *Turbo)
 	Uint32 lives, seed;
 	int waiting;
 	int status;
-	char *message = NULL;
+	const char *message = NULL;
 
 	/* Our address server connection is through TCP */
 	Message("Connecting to Address Server");
diff --git a/netlogic/netplay.h b/netlogic/netplay.h
index cc8c9cc1..30add548 100644
--- a/netlogic/netplay.h
+++ b/netlogic/netplay.h
@@ -2,7 +2,7 @@
 /* Functions in netplay.cc */
 extern int   InitNetData(void);
 extern void  HaltNetData(void);
-extern int   AddPlayer(char *playerstr);
+extern int   AddPlayer(const char *playerstr);
 extern int   SetServer(char *serverstr);
 extern int   CheckPlayers(void);
 extern void  QueueKey(unsigned char Op, unsigned char Type);
diff --git a/netscore.cpp b/netscore.cpp
index 27c27131..ce31b676 100644
--- a/netscore.cpp
+++ b/netscore.cpp
@@ -12,7 +12,7 @@
 
 #define NUM_SCORES	10		// Copied from scores.cc 
 
-static TCPsocket Goto_ScoreServer(char *server, int port);
+static TCPsocket Goto_ScoreServer(const char *server, int port);
 static void Leave_ScoreServer(TCPsocket remote);
 
 /* This function actually registers the high scores */
@@ -177,7 +177,7 @@ int NetLoadScores(void)
 	return(0);
 }
 
-static TCPsocket Goto_ScoreServer(char *server, int port)
+static TCPsocket Goto_ScoreServer(const char *server, int port)
 {
 	TCPsocket remote;
 	IPaddress remote_address;
diff --git a/scores.cpp b/scores.cpp
index 1633e8f5..ebc99624 100644
--- a/scores.cpp
+++ b/scores.cpp
@@ -185,17 +185,17 @@ static int Cancel2_callback(void) {
 
 int GetStartLevel(void)
 {
-	static char    *Ltext1 = 
+	static const char    *Ltext1 = 
 			"Enter the level to start from (1-40).  This";
-	static char    *Ltext2 = 
+	static const char    *Ltext2 = 
 			"disqualifies you from a high score...";
-	static char    *Ltext3 = "Level:";
-	static char    *Ltext4 = "Lives:";
+	static const char    *Ltext3 = "Level:";
+	static const char    *Ltext4 = "Lives:";
 	MFont *chicago;
 	Maclike_Dialog *dialog;
 	SDL_Surface *splash;
 	SDL_Surface *text1, *text2, *text3, *text4;
-	static char *turbotext = "Turbofunk On";
+	static const char *turbotext = "Turbofunk On";
 	int x, y, X, Y;
 	Mac_Button *doit;
 	Mac_Button *cancel;
diff --git a/screenlib/SDL_FrameBuf.cpp b/screenlib/SDL_FrameBuf.cpp
index 2e6ac7fb..8ea2090d 100644
--- a/screenlib/SDL_FrameBuf.cpp
+++ b/screenlib/SDL_FrameBuf.cpp
@@ -63,7 +63,7 @@ FrameBuf:: FrameBuf()
 	itail = &images;
 }
 
-static void PrintSurface(char *title, SDL_Surface *surface)
+static void PrintSurface(const char *title, SDL_Surface *surface)
 {
 #ifdef FRAMEBUF_DEBUG
 	fprintf(stderr, "%s:\n", title);
@@ -614,7 +614,7 @@ FrameBuf:: GrabArea(Uint16 x, Uint16 y, Uint16 w, Uint16 h)
 }
 
 int
-FrameBuf:: ScreenDump(char *prefix, Uint16 x, Uint16 y, Uint16 w, Uint16 h)
+FrameBuf:: ScreenDump(const char *prefix, Uint16 x, Uint16 y, Uint16 w, Uint16 h)
 {
 	SDL_Surface *dump;
 	int retval;
diff --git a/screenlib/SDL_FrameBuf.h b/screenlib/SDL_FrameBuf.h
index 1957c814..73b70a38 100644
--- a/screenlib/SDL_FrameBuf.h
+++ b/screenlib/SDL_FrameBuf.h
@@ -130,7 +130,7 @@ class FrameBuf {
 
 	/* Area copy/dump routines */
 	SDL_Surface *GrabArea(Uint16 x, Uint16 y, Uint16 w, Uint16 h);
-	int ScreenDump(char *prefix, Uint16 x, Uint16 y, Uint16 w, Uint16 h);
+	int ScreenDump(const char *prefix, Uint16 x, Uint16 y, Uint16 w, Uint16 h);
 
 	/* Cursor handling routines */
 	void ShowCursor(void) {
@@ -139,7 +139,7 @@ class FrameBuf {
 	void HideCursor(void) {
 		SDL_ShowCursor(0);
 	}
-	void SetCaption(char *caption, char *icon = NULL) {
+	void SetCaption(const char *caption, const char *icon = NULL) {
 		if ( icon == NULL ) {
 			icon = caption;
 		}
@@ -161,7 +161,7 @@ class FrameBuf {
 	int locked, faded;
 
 	/* Error message */
-	void SetError(char *fmt, ...) {
+	void SetError(const char *fmt, ...) {
 		va_list ap;
 
 		va_start(ap, fmt);