Subject: Quell const char conversion warnings. From: Loui Chang Date: Fri Oct 16 09:37:57 EDT 2009 const char* to char* is deprecated behaviour in gcc 4.4. diff -Naur a/include/comments.h b/include/comments.h --- a/include/comments.h 2004-09-27 05:28:10.000000000 -0400 +++ b/include/comments.h 2009-10-16 09:09:30.000000000 -0400 @@ -56,12 +56,12 @@ void clear(); // Clear the comment void move(); // Move the comment void draw(float ypos); // Draw the comment - void set(int color, char *str); // Set the comment + void set(int color, const char *str); // Set the comment void copy(COMMENT &from); // Copy the comment }; -void add_comment(int color, char *str, ...); +void add_comment(int color, const char *str, ...); void draw_comments(); void move_comments(); void clear_comments(); diff -Naur a/include/config.h b/include/config.h --- a/include/config.h 2004-09-27 05:28:10.000000000 -0400 +++ b/include/config.h 2009-10-16 09:19:40.000000000 -0400 @@ -59,14 +59,14 @@ // config file. It first checks the user's home directory, // and if that fails it uses the CONFIG_DIR defined in the // makefile. -char *get_config_location(bool write = false); +const char *get_config_location(bool write = false); // Load config from file -void load_config(char *file, CONFIG *conf); +void load_config(const char *file, CONFIG *conf); // Save config to file -void save_config(char *file, CONFIG *conf); +void save_config(const char *file, CONFIG *conf); #endif diff -Naur a/include/font.h b/include/font.h --- a/include/font.h 2004-09-27 05:28:10.000000000 -0400 +++ b/include/font.h 2009-10-16 09:11:28.000000000 -0400 @@ -68,19 +68,19 @@ // Print a string with specified font texture -void glprintf(GLuint tex, int set, float x, float y, float z, char *string, ...); +void glprintf(GLuint tex, int set, float x, float y, float z, const char *string, ...); // Print a centered string with specified font texture -void glprintf_center(GLuint tex, int set, float x, float y, float z, char *string, ...); +void glprintf_center(GLuint tex, int set, float x, float y, float z, const char *string, ...); // Return the length of a string -float glfont_length(char *string, ...); +float glfont_length(const char *string, ...); // Print numbers using the big number font -void glprint_num(float x, float y, float z, char *string); +void glprint_num(float x, float y, float z, const char *string); // Build a display list for bitmapped fonts (-> font_base) diff -Naur a/include/hiscore.h b/include/hiscore.h --- a/include/hiscore.h 2004-09-27 05:28:10.000000000 -0400 +++ b/include/hiscore.h 2009-10-16 09:26:50.000000000 -0400 @@ -55,10 +55,10 @@ void clear(); // Clear the list void sort(); // Sort the list - int add_name(char *name, int score); // Add a record + int add_name(const char *name, int score); // Add a record void draw(int place, float fade); // Draw the list - void save(char *file); // Save the list - void load(char *file); // Load the list + void save(const char *file); // Save the list + void load(const char *file); // Load the list void input_name(int place); // Input a name }; @@ -66,7 +66,7 @@ extern HISCORE_LIST hiscore_1; extern HISCORE_LIST hiscore_2; -char *get_hiscore_location(int which, bool write = false); +const char *get_hiscore_location(int which, bool write = false); #endif diff -Naur a/include/init.h b/include/init.h --- a/include/init.h 2004-09-27 05:28:10.000000000 -0400 +++ b/include/init.h 2009-10-16 09:11:43.000000000 -0400 @@ -48,7 +48,7 @@ void init_sdl_and_gl(); // Display an error message and quit -void error_msg(char *msg, ...); +void error_msg(const char *msg, ...); #endif diff -Naur a/include/mpak.h b/include/mpak.h --- a/include/mpak.h 2004-09-27 05:28:10.000000000 -0400 +++ b/include/mpak.h 2009-10-16 09:30:54.000000000 -0400 @@ -94,7 +94,7 @@ // Open a package for reading or writing. You don't need to supply // the override directory, but it's recommended for reading mode. // Returns zero on failure. - int open_mpk(int mode, char *file, char *override = NULL); + int open_mpk(int mode, const char *file, const char *override = NULL); // Close the package. This writes the file table to the end of the // package and updates the header. After closing the file, you can @@ -103,13 +103,13 @@ // Add a file to the package. // Returns zero on failure. - int add_file(char *file); + int add_file(const char *file); // Get a pointer to a certain file in the package. It first looks // from the override directory, and if the file isn't there it looks // from the package. The user MUST fclose() the pointer himself! // Returns NULL on failure. - FILE *open_file(char *file); + FILE *open_file(const char *file); // Extracts a file from the package (using open_file()) and saves it // to a file by the same name. It first looks from the override directory, @@ -117,11 +117,11 @@ // You can supply optional path prefix if you don't want to extract to the // working directory. // Returns zero on failure. - int extract_file(char *file, char *path = NULL); + int extract_file(const char *file, const char *path = NULL); // Find the index of a particular file in the package. // Returns -1 on failure. - int find_file(char *file); + int find_file(const char *file); }; diff -Naur a/include/soundmusic.h b/include/soundmusic.h --- a/include/soundmusic.h 2004-11-20 13:49:07.000000000 -0500 +++ b/include/soundmusic.h 2009-10-16 08:26:21.000000000 -0400 @@ -86,7 +86,7 @@ void init_mixer(); // Play music -void play_music(char *file); +void play_music(const char *file); // Play a sound void play_sound(int sound, bool random_freq); diff -Naur a/include/texture.h b/include/texture.h --- a/include/texture.h 2004-09-27 05:28:10.000000000 -0400 +++ b/include/texture.h 2009-10-16 09:17:49.000000000 -0400 @@ -35,10 +35,10 @@ // Load a PNG -GLuint load_png(char *file, bool alpha = false, bool repeat = false, bool mipmaps = true); +GLuint load_png(const char *file, bool alpha = false, bool repeat = false, bool mipmaps = true); // Load a JPG -GLuint load_jpg(char *file, bool alpha = false, bool repeat = false, bool mipmaps = true); +GLuint load_jpg(const char *file, bool alpha = false, bool repeat = false, bool mipmaps = true); // Load a image file using SDL_Image and @@ -47,10 +47,10 @@ // If repeat == true -> texture can be tiled // If mipmaps == true -> Mipmaps will be generated // Return texture ID -GLuint load_texture(char *file, char *type, bool alpha = false, bool repeat = false, bool mipmaps = true); +GLuint load_texture(const char *file, const char *type, bool alpha = false, bool repeat = false, bool mipmaps = true); // Same as load_texture(), but loads into the specified texture index -void load_texture_into(GLuint tex, char *file, char *img_type, bool alpha, bool repeat, bool mipmaps); +void load_texture_into(GLuint tex, const char *file, const char *img_type, bool alpha, bool repeat, bool mipmaps); // Grab texture contents from the frame buffer. // Assuming that 'tex' is a valid texture ID diff -Naur a/include/tilemap.h b/include/tilemap.h --- a/include/tilemap.h 2004-09-27 05:28:10.000000000 -0400 +++ b/include/tilemap.h 2009-10-16 08:26:42.000000000 -0400 @@ -76,8 +76,8 @@ void build_map(); void kill_map(); -void save_map(char *file); -void load_map(char *file); +void save_map(const char *file); +void load_map(const char *file); #endif diff -Naur a/src/comments.cpp b/src/comments.cpp --- a/src/comments.cpp 2004-09-27 05:28:20.000000000 -0400 +++ b/src/comments.cpp 2009-10-16 09:09:01.000000000 -0400 @@ -50,7 +50,7 @@ // Add a comment -void add_comment(int color, char *str, ...) { +void add_comment(int color, const char *str, ...) { // Format the string arguments char buf[256]; va_list args; @@ -97,7 +97,7 @@ // Set the text -void COMMENT::set(int color_, char *str) { +void COMMENT::set(int color_, const char *str) { clear(); // Set the buf diff -Naur a/src/config.cpp b/src/config.cpp --- a/src/config.cpp 2004-09-27 05:35:48.000000000 -0400 +++ b/src/config.cpp 2009-10-16 09:19:02.000000000 -0400 @@ -76,7 +76,7 @@ // config file. It first checks the user's home directory, // and if that fails it uses the CONFIG_DIR defined in the // makefile. -char *get_config_location(bool write) { +const char *get_config_location(bool write) { #ifdef LINUX // Get the path to the config file string tmp = get_tomatoes_dir() + "config.cfg"; @@ -91,7 +91,7 @@ fclose(ftest); } - return (char*)tmp.c_str(); + return (const char*)tmp.c_str(); #endif // Return the CONFIG_DIR @@ -100,7 +100,7 @@ // Load config from file -void load_config(char *file, CONFIG *conf) { +void load_config(const char *file, CONFIG *conf) { FILE *f = fopen(file, "rt"); if(!f) @@ -127,7 +127,7 @@ // Save config to file -void save_config(char *file, CONFIG *conf) { +void save_config(const char *file, CONFIG *conf) { FILE *f = fopen(file, "wt"); if(!f) diff -Naur a/src/font.cpp b/src/font.cpp --- a/src/font.cpp 2004-09-27 05:28:22.000000000 -0400 +++ b/src/font.cpp 2009-10-16 09:13:57.000000000 -0400 @@ -53,7 +53,7 @@ // Return the length of a string -float glfont_length(char *string, ...) { +float glfont_length(const char *string, ...) { // Format the string arguments char buf[1024]; @@ -71,7 +71,7 @@ // Print a string with specified font texture -void glprintf(GLuint tex, int set, float x, float y, float z, char *string, ...) { +void glprintf(GLuint tex, int set, float x, float y, float z, const char *string, ...) { // Format the string arguments char buf[1024]; @@ -97,7 +97,7 @@ // Print a centered string with specified font texture -void glprintf_center(GLuint tex, int set, float x, float y, float z, char *string, ...) { +void glprintf_center(GLuint tex, int set, float x, float y, float z, const char *string, ...) { // Format the string arguments char buf[1024]; @@ -179,7 +179,7 @@ // Print numbers using the big number font -void glprint_num(float x, float y, float z, char *string) { +void glprint_num(float x, float y, float z, const char *string) { // Print BIND_TEXTURE(font_num); diff -Naur a/src/hiscore.cpp b/src/hiscore.cpp --- a/src/hiscore.cpp 2004-11-20 13:49:07.000000000 -0500 +++ b/src/hiscore.cpp 2009-10-16 09:27:01.000000000 -0400 @@ -69,7 +69,7 @@ // hiscore file. It first checks the user's home directory, // and if that fails it uses the HISCORE_DIR defined in the // makefile. -char *get_hiscore_location(int which, bool write) { +const char *get_hiscore_location(int which, bool write) { #ifdef LINUX // Get the path to the hiscore file string tmp; @@ -401,7 +401,7 @@ // Save the list to a file -void HISCORE_LIST::save(char *file) { +void HISCORE_LIST::save(const char *file) { FILE *fout; fout = fopen(file, "wb"); if(!fout) @@ -421,7 +421,7 @@ // Load the list from a file -void HISCORE_LIST::load(char *file) { +void HISCORE_LIST::load(const char *file) { FILE *fin; fin = fopen(file, "rb"); if(!fin) { @@ -444,7 +444,7 @@ // Add a name to the list. Returns the place. -int HISCORE_LIST::add_name(char *name, int score) { +int HISCORE_LIST::add_name(const char *name, int score) { // Check if we qualify if(list[NUM_NAMES-1].score >= score) return -1; diff -Naur a/src/init.cpp b/src/init.cpp --- a/src/init.cpp 2004-11-20 13:49:07.000000000 -0500 +++ b/src/init.cpp 2009-10-16 09:14:11.000000000 -0400 @@ -58,7 +58,7 @@ // Display an error message and quit -void error_msg(char *msg, ...) { +void error_msg(const char *msg, ...) { char *buf = new char[4096]; diff -Naur a/src/menu.cpp b/src/menu.cpp --- a/src/menu.cpp 2004-11-21 05:26:40.000000000 -0500 +++ b/src/menu.cpp 2009-10-16 09:29:02.000000000 -0400 @@ -92,7 +92,7 @@ // Helper function which returns a key name in upper case -char *key_name(int key) { +const char *key_name(int key) { if(key != -1) { // Get the key name from SDL diff -Naur a/src/mpak.cpp b/src/mpak.cpp --- a/src/mpak.cpp 2004-09-27 05:28:22.000000000 -0400 +++ b/src/mpak.cpp 2009-10-16 09:31:31.000000000 -0400 @@ -102,7 +102,7 @@ // Compute the CRC for a file -UINT32 mpk_crc_file(char *file, UINT32 pos) { +UINT32 mpk_crc_file(const char *file, UINT32 pos) { // Initial CRC UINT32 crc = 0xFFFFFFFFL; @@ -172,7 +172,7 @@ // This helper function returns the filename without full path. // Pass a full path. -char *mpk_strip_path(char *path) { +char *mpk_strip_path(const char *path) { int pos = strlen(path); while(pos > 0) { @@ -218,7 +218,7 @@ // Open a package for reading or writing. You don't need to supply // the override directory, but it's recommended for reading mode. // Returns zero on failure. -int MPAK_FILE::open_mpk(int open_mode, char *file, char *override) { +int MPAK_FILE::open_mpk(int open_mode, const char *file, const char *override) { // Check if it's already open if(mode != MPAK_CLOSED) @@ -402,7 +402,7 @@ // Add a file to the package. // Returns zero on failure. -int MPAK_FILE::add_file(char *file) { +int MPAK_FILE::add_file(const char *file) { // Check that we're in write mode if(mode != MPAK_WRITE) @@ -450,7 +450,7 @@ // from the override directory, and if the file isn't there it looks // from the package. The user MUST fclose() the pointer himself! // Returns NULL on failure. -FILE *MPAK_FILE::open_file(char *file) { +FILE *MPAK_FILE::open_file(const char *file) { // Check that we're in read mode if(mode != MPAK_READ) @@ -501,7 +501,7 @@ // You can supply optional path prefix if you don't want to extract to the // working directory. // Returns zero on failure. -int MPAK_FILE::extract_file(char *file, char *path) { +int MPAK_FILE::extract_file(const char *file, const char *path) { // Retrieve the pointer from open_file() FILE *fin = open_file(file); @@ -551,7 +551,7 @@ // Find the index of a particular file in the package. // Returns -1 on failure. -int MPAK_FILE::find_file(char *file) { +int MPAK_FILE::find_file(const char *file) { // Check that we're open if(mode == MPAK_CLOSED) return -1; diff -Naur a/src/screenshot.cpp b/src/screenshot.cpp --- a/src/screenshot.cpp 2004-09-27 05:38:16.000000000 -0400 +++ b/src/screenshot.cpp 2009-10-16 08:28:22.000000000 -0400 @@ -46,11 +46,11 @@ // Save an array of pixels to a TGA file -void save_tga(char *filename, short int w, short int h, unsigned char *image_data); +void save_tga(const char *filename, short int w, short int h, unsigned char *image_data); // Check if a file exists -bool file_exists(char *file) { +bool file_exists(const char *file) { FILE *f = fopen(file, "rb"); if(!f) return false; @@ -105,7 +105,7 @@ // Save an array of pixels to a TGA file // Written using OpenGL Game Programming - book as a reference -void save_tga(char *filename, short int w, short int h, unsigned char *image_data) { +void save_tga(const char *filename, short int w, short int h, unsigned char *image_data) { unsigned char byte_skip; // Used to fill in the data fields that we don't care about short int short_skip; diff -Naur a/src/soundmusic.cpp b/src/soundmusic.cpp --- a/src/soundmusic.cpp 2004-11-21 05:18:29.000000000 -0500 +++ b/src/soundmusic.cpp 2009-10-16 08:28:34.000000000 -0400 @@ -168,7 +168,7 @@ // This helper function loads a sound and stores it to the sound array static int cur_sound = 0; -void load_sound(char *file) { +void load_sound(const char *file) { if(cur_sound > NUM_SOUNDS-1) error_msg("load_sounds():\nTrying to load too many sounds!\nNUM_SOUNDS is defined as %d.\n", NUM_SOUNDS); @@ -257,7 +257,7 @@ // Play music -void play_music(char *file) { +void play_music(const char *file) { if(!config.sound || !config.music_vol) return; diff -Naur a/src/texture.cpp b/src/texture.cpp --- a/src/texture.cpp 2004-11-20 13:49:22.000000000 -0500 +++ b/src/texture.cpp 2009-10-16 09:28:00.000000000 -0400 @@ -67,13 +67,13 @@ // Load a PNG -GLuint load_png(char *file, bool alpha, bool repeat, bool mipmaps) { +GLuint load_png(const char *file, bool alpha, bool repeat, bool mipmaps) { return load_texture(file, "PNG", alpha, repeat, mipmaps); } // Load a JPG -GLuint load_jpg(char *file, bool alpha, bool repeat, bool mipmaps) { +GLuint load_jpg(const char *file, bool alpha, bool repeat, bool mipmaps) { return load_texture(file, "JPG", alpha, repeat, mipmaps); } @@ -84,9 +84,10 @@ // If repeat == true -> texture can be tiled // If mipmaps == true -> Mipmaps will be generated // Return texture ID -GLuint load_texture(char *file, char *img_type, bool alpha, bool repeat, bool mipmaps) { +GLuint load_texture(const char *file, const char *img_type, bool alpha, bool repeat, bool mipmaps) { GLuint tex; + char itype[5]; // Load the 'file' to SDL_Surface SDL_Surface *img = NULL; @@ -98,7 +99,8 @@ SDL_RWops *rw; rw = SDL_RWFromFP(fin, 1); - img = IMG_LoadTyped_RW(rw,0, img_type); + strcpy(itype, img_type); + img = IMG_LoadTyped_RW(rw,0, itype); if(img == NULL) error_msg("Unable to load texture from %s!\n%s", file, IMG_GetError()); SDL_FreeRW(rw); @@ -187,9 +189,10 @@ // Same as load_texture(), but loads into a specified texture index -void load_texture_into(GLuint tex, char *file, char *img_type, bool alpha, bool repeat, bool mipmaps) { +void load_texture_into(GLuint tex, const char *file, const char *img_type, bool alpha, bool repeat, bool mipmaps) { // Load the 'file' to SDL_Surface SDL_Surface *img = NULL; + char itype[5]; FILE *fin = pakfile.open_file(file); if(!fin) @@ -197,7 +200,8 @@ SDL_RWops *rw; rw = SDL_RWFromFP(fin, 1); - img = IMG_LoadTyped_RW(rw,0, img_type); + strcpy(itype, img_type); + img = IMG_LoadTyped_RW(rw,0, itype); if(img == NULL) error_msg("Unable to load texture from %s!\n%s", file, IMG_GetError()); SDL_FreeRW(rw); diff -Naur a/src/tilemap.cpp b/src/tilemap.cpp --- a/src/tilemap.cpp 2004-09-27 05:28:22.000000000 -0400 +++ b/src/tilemap.cpp 2009-10-16 08:29:06.000000000 -0400 @@ -416,7 +416,7 @@ // Save the map to a file -void save_map(char *file) { +void save_map(const char *file) { #ifdef EDITOR // Open the file FILE *f = fopen(file, "wb"); @@ -466,7 +466,7 @@ // Load the map from a file -void load_map(char *file) { +void load_map(const char *file) { #ifndef EDITOR // Load the level from the pakfile FILE *f = pakfile.open_file(file);