Merge pull request #999 from turol/const

Improve const correctness
This commit is contained in:
Mike Swanson 2018-03-16 22:00:18 -07:00 committed by GitHub
commit de175686e6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
31 changed files with 91 additions and 91 deletions

View file

@ -38,9 +38,9 @@ static int hash_table_length = -1;
// This is the algorithm used by glib
static unsigned int strhash(char *s)
static unsigned int strhash(const char *s)
{
char *p = s;
const char *p = s;
unsigned int h = *p;
if (h)
@ -52,7 +52,7 @@ static unsigned int strhash(char *s)
return h;
}
static deh_substitution_t *SubstitutionForString(char *s)
static deh_substitution_t *SubstitutionForString(const char *s)
{
int entry;
@ -165,7 +165,7 @@ static void DEH_AddToHashtable(deh_substitution_t *sub)
++hash_table_entries;
}
void DEH_AddStringReplacement(char *from_text, char *to_text)
void DEH_AddStringReplacement(const char *from_text, const char *to_text)
{
deh_substitution_t *sub;
size_t len;
@ -251,7 +251,7 @@ static format_arg_t FormatArgumentType(char c)
// Given the specified string, get the type of the first format
// string encountered.
static format_arg_t NextFormatArgument(char **str)
static format_arg_t NextFormatArgument(const char **str)
{
format_arg_t argtype;
@ -326,10 +326,10 @@ static boolean ValidArgumentReplacement(format_arg_t original,
// Return true if the specified string contains no format arguments.
static boolean ValidFormatReplacement(char *original, char *replacement)
static boolean ValidFormatReplacement(const char *original, const char *replacement)
{
char *rover1;
char *rover2;
const char *rover1;
const char *rover2;
int argtype1, argtype2;
// Check each argument in turn and compare types.

View file

@ -28,7 +28,7 @@ char *DEH_String(char *s) PRINTF_ARG_ATTR(1);
void DEH_printf(char *fmt, ...) PRINTF_ATTR(1, 2);
void DEH_fprintf(FILE *fstream, char *fmt, ...) PRINTF_ATTR(2, 3);
void DEH_snprintf(char *buffer, size_t len, char *fmt, ...) PRINTF_ATTR(3, 4);
void DEH_AddStringReplacement(char *from_text, char *to_text);
void DEH_AddStringReplacement(const char *from_text, const char *to_text);
#if 0

View file

@ -208,8 +208,8 @@ void HUlib_addLineToSText(hu_stext_t* s)
void
HUlib_addMessageToSText
( hu_stext_t* s,
char* prefix,
char* msg )
const char* prefix,
const char* msg )
{
HUlib_addLineToSText(s);
if (prefix)

View file

@ -134,8 +134,8 @@ void HUlib_addLineToSText(hu_stext_t* s);
void
HUlib_addMessageToSText
( hu_stext_t* s,
char* prefix,
char* msg );
const char* prefix,
const char* msg );
// draws stext
void HUlib_drawSText(hu_stext_t* s);

View file

@ -158,7 +158,7 @@ byte *I_ZoneBase (int *size)
return zonemem;
}
void I_PrintBanner(char *msg)
void I_PrintBanner(const char *msg)
{
int i;
int spaces = 35 - (strlen(msg) / 2);
@ -181,7 +181,7 @@ void I_PrintDivider(void)
putchar('\n');
}
void I_PrintStartupBanner(char *gamedescription)
void I_PrintStartupBanner(const char *gamedescription)
{
I_PrintDivider();
I_PrintBanner(gamedescription);
@ -261,7 +261,7 @@ void I_Quit (void)
static boolean already_quitting = false;
void I_Error (char *error, ...)
void I_Error (const char *error, ...)
{
char msgbuf[512];
va_list argptr;

View file

@ -52,7 +52,7 @@ ticcmd_t* I_BaseTiccmd (void);
// Clean exit, displays sell blurb.
void I_Quit (void);
void I_Error (char *error, ...) PRINTF_ATTR(1, 2);
void I_Error (const char *error, ...) PRINTF_ATTR(1, 2);
void I_Tactile (int on, int off, int total);
@ -72,11 +72,11 @@ void I_BindVariables(void);
// Print startup banner copyright message.
void I_PrintStartupBanner(char *gamedescription);
void I_PrintStartupBanner(const char *gamedescription);
// Print a centered text banner displaying the given string.
void I_PrintBanner(char *text);
void I_PrintBanner(const char *text);
// Print a dividing line for startup banners.

View file

@ -52,7 +52,7 @@
// Create a directory
//
void M_MakeDirectory(char *path)
void M_MakeDirectory(const char *path)
{
#ifdef _WIN32
mkdir(path);
@ -63,7 +63,7 @@ void M_MakeDirectory(char *path)
// Check if a file exists
boolean M_FileExists(char *filename)
boolean M_FileExists(const char *filename)
{
FILE *fstream;
@ -86,7 +86,7 @@ boolean M_FileExists(char *filename)
// Check if a file exists by probing for common case variation of its filename.
// Returns a newly allocated string that the caller is responsible for freeing.
char *M_FileCaseExists(char *path)
char *M_FileCaseExists(const char *path)
{
char *path_dup, *filename, *ext;
@ -178,7 +178,7 @@ long M_FileLength(FILE *handle)
// M_WriteFile
//
boolean M_WriteFile(char *name, void *source, int length)
boolean M_WriteFile(const char *name, void *source, int length)
{
FILE *handle;
int count;
@ -202,7 +202,7 @@ boolean M_WriteFile(char *name, void *source, int length)
// M_ReadFile
//
int M_ReadFile(char *name, byte **buffer)
int M_ReadFile(const char *name, byte **buffer)
{
FILE *handle;
int count, length;
@ -233,7 +233,7 @@ int M_ReadFile(char *name, byte **buffer)
//
// The returned value must be freed with Z_Free after use.
char *M_TempFile(char *s)
char *M_TempFile(const char *s)
{
char *tempdir;
@ -264,10 +264,10 @@ boolean M_StrToInt(const char *str, int *result)
|| sscanf(str, " %d", result) == 1;
}
void M_ExtractFileBase(char *path, char *dest)
void M_ExtractFileBase(const char *path, char *dest)
{
char *src;
char *filename;
const char *src;
const char *filename;
int length;
src = path + strlen(path) - 1;
@ -343,7 +343,7 @@ void M_ForceLowercase(char *text)
// Case-insensitive version of strstr()
//
char *M_StrCaseStr(char *haystack, char *needle)
const char *M_StrCaseStr(const char *haystack, const char *needle)
{
unsigned int haystack_len;
unsigned int needle_len;

View file

@ -25,18 +25,18 @@
#include "doomtype.h"
boolean M_WriteFile(char *name, void *source, int length);
int M_ReadFile(char *name, byte **buffer);
void M_MakeDirectory(char *dir);
char *M_TempFile(char *s);
boolean M_FileExists(char *file);
char *M_FileCaseExists(char *file);
boolean M_WriteFile(const char *name, void *source, int length);
int M_ReadFile(const char *name, byte **buffer);
void M_MakeDirectory(const char *dir);
char *M_TempFile(const char *s);
boolean M_FileExists(const char *file);
char *M_FileCaseExists(const char *file);
long M_FileLength(FILE *handle);
boolean M_StrToInt(const char *str, int *result);
void M_ExtractFileBase(char *path, char *dest);
void M_ExtractFileBase(const char *path, char *dest);
void M_ForceUppercase(char *text);
void M_ForceLowercase(char *text);
char *M_StrCaseStr(char *haystack, char *needle);
const char *M_StrCaseStr(const char *haystack, const char *needle);
char *M_StringDuplicate(const char *orig);
boolean M_StringCopy(char *dest, const char *src, size_t dest_size);
boolean M_StringConcat(char *dest, const char *src, size_t dest_size);

View file

@ -258,7 +258,7 @@ int W_NumLumps (void)
// Returns -1 if name not found.
//
lumpindex_t W_CheckNumForName(char* name)
lumpindex_t W_CheckNumForName(const char *name)
{
lumpindex_t i;
@ -307,7 +307,7 @@ lumpindex_t W_CheckNumForName(char* name)
// W_GetNumForName
// Calls W_CheckNumForName, but bombs out if not found.
//
lumpindex_t W_GetNumForName(char* name)
lumpindex_t W_GetNumForName(const char *name)
{
lumpindex_t i;
@ -428,7 +428,7 @@ void *W_CacheLumpNum(lumpindex_t lumpnum, int tag)
//
// W_CacheLumpName
//
void *W_CacheLumpName(char *name, int tag)
void *W_CacheLumpName(const char *name, int tag)
{
return W_CacheLumpNum(W_GetNumForName(name), tag);
}
@ -464,7 +464,7 @@ void W_ReleaseLumpNum(lumpindex_t lumpnum)
}
}
void W_ReleaseLumpName(char *name)
void W_ReleaseLumpName(const char *name)
{
W_ReleaseLumpNum(W_GetNumForName(name));
}

View file

@ -56,20 +56,20 @@ extern unsigned int numlumps;
wad_file_t *W_AddFile(char *filename);
void W_Reload(void);
lumpindex_t W_CheckNumForName(char *name);
lumpindex_t W_GetNumForName(char *name);
lumpindex_t W_CheckNumForName(const char *name);
lumpindex_t W_GetNumForName(const char *name);
int W_LumpLength(lumpindex_t lump);
void W_ReadLump(lumpindex_t lump, void *dest);
void *W_CacheLumpNum(lumpindex_t lump, int tag);
void *W_CacheLumpName(char *name, int tag);
void *W_CacheLumpName(const char *name, int tag);
void W_GenerateHashTable(void);
extern unsigned int W_LumpNameHash(const char *s);
void W_ReleaseLumpNum(lumpindex_t lump);
void W_ReleaseLumpName(char *name);
void W_ReleaseLumpName(const char *name);
#endif

View file

@ -442,7 +442,7 @@ void Z_CheckHeap (void)
// Z_ChangeTag
//
void Z_ChangeTag2(void *ptr, int tag, char *file, int line)
void Z_ChangeTag2(void *ptr, int tag, const char *file, int line)
{
memblock_t* block;

View file

@ -490,7 +490,7 @@ void Z_CheckHeap (void)
//
// Z_ChangeTag
//
void Z_ChangeTag2(void *ptr, int tag, char *file, int line)
void Z_ChangeTag2(void *ptr, int tag, const char *file, int line)
{
memblock_t* block;

View file

@ -57,7 +57,7 @@ void Z_FreeTags (int lowtag, int hightag);
void Z_DumpHeap (int lowtag, int hightag);
void Z_FileDumpHeap (FILE *f);
void Z_CheckHeap (void);
void Z_ChangeTag2 (void *ptr, int tag, char *file, int line);
void Z_ChangeTag2 (void *ptr, int tag, const char *file, int line);
void Z_ChangeUser(void *ptr, void **user);
int Z_FreeMemory (void);
unsigned int Z_ZoneSize(void);

View file

@ -93,13 +93,13 @@ txt_widget_class_t txt_button_class =
NULL,
};
void TXT_SetButtonLabel(txt_button_t *button, char *label)
void TXT_SetButtonLabel(txt_button_t *button, const char *label)
{
free(button->label);
button->label = strdup(label);
}
txt_button_t *TXT_NewButton(char *label)
txt_button_t *TXT_NewButton(const char *label)
{
txt_button_t *button;
@ -113,7 +113,7 @@ txt_button_t *TXT_NewButton(char *label)
// Button with a callback set automatically
txt_button_t *TXT_NewButton2(char *label, TxtWidgetSignalFunc func,
txt_button_t *TXT_NewButton2(const char *label, TxtWidgetSignalFunc func,
void *user_data)
{
txt_button_t *button;

View file

@ -45,7 +45,7 @@ struct txt_button_s
* @return Pointer to the new button widget.
*/
txt_button_t *TXT_NewButton(char *label);
txt_button_t *TXT_NewButton(const char *label);
/**
* Create a new button widget, binding the "pressed" signal to a
@ -57,7 +57,7 @@ txt_button_t *TXT_NewButton(char *label);
* @return Pointer to the new button widget.
*/
txt_button_t *TXT_NewButton2(char *label, TxtWidgetSignalFunc func,
txt_button_t *TXT_NewButton2(const char *label, TxtWidgetSignalFunc func,
void *user_data);
/**
@ -67,7 +67,7 @@ txt_button_t *TXT_NewButton2(char *label, TxtWidgetSignalFunc func,
* @param label The new label (UTF-8 format).
*/
void TXT_SetButtonLabel(txt_button_t *button, char *label);
void TXT_SetButtonLabel(txt_button_t *button, const char *label);
#endif /* #ifndef TXT_BUTTON_H */

View file

@ -116,7 +116,7 @@ txt_widget_class_t txt_checkbox_class =
NULL,
};
txt_checkbox_t *TXT_NewCheckBox(char *label, int *variable)
txt_checkbox_t *TXT_NewCheckBox(const char *label, int *variable)
{
txt_checkbox_t *checkbox;
@ -130,7 +130,7 @@ txt_checkbox_t *TXT_NewCheckBox(char *label, int *variable)
return checkbox;
}
txt_checkbox_t *TXT_NewInvertedCheckBox(char *label, int *variable)
txt_checkbox_t *TXT_NewInvertedCheckBox(const char *label, int *variable)
{
txt_checkbox_t *result;

View file

@ -55,7 +55,7 @@ struct txt_checkbox_s
* @return Pointer to the new checkbox.
*/
txt_checkbox_t *TXT_NewCheckBox(char *label, int *variable);
txt_checkbox_t *TXT_NewCheckBox(const char *label, int *variable);
/**
* Create a new inverted checkbox.
@ -69,7 +69,7 @@ txt_checkbox_t *TXT_NewCheckBox(char *label, int *variable);
* @return Pointer to the new checkbox.
*/
txt_checkbox_t *TXT_NewInvertedCheckBox(char *label, int *variable);
txt_checkbox_t *TXT_NewInvertedCheckBox(const char *label, int *variable);
#endif /* #ifndef TXT_CHECKBOX_H */

View file

@ -220,7 +220,7 @@ static void DrawHelpIndicator(void)
TXT_DrawString("=Help ");
}
void TXT_SetDesktopTitle(char *title)
void TXT_SetDesktopTitle(const char *title)
{
free(desktop_title);
desktop_title = strdup(title);

View file

@ -39,7 +39,7 @@ int TXT_WindowKeyPress(txt_window_t *window, int c);
* @param title The title to display (UTF-8 format).
*/
void TXT_SetDesktopTitle(char *title);
void TXT_SetDesktopTitle(const char *title);
/**
* Exit the currently-running main loop and return from the

View file

@ -517,7 +517,7 @@ int TXT_CanSelectFiles(void)
// return a pointer to a string that is a case-insensitive
// pattern representation (like [Ww][Aa][Dd])
//
static char *ExpandExtension(char *orig)
static char *ExpandExtension(const char *orig)
{
int oldlen, newlen, i;
char *c, *newext = NULL;
@ -550,7 +550,7 @@ static char *ExpandExtension(char *orig)
return newext;
}
char *TXT_SelectFile(char *window_title, char **extensions)
char *TXT_SelectFile(const char *window_title, char **extensions)
{
unsigned int i;
size_t len;

View file

@ -50,7 +50,7 @@ int TXT_CanSelectFiles(void);
* to select directories.
*/
char *TXT_SelectFile(char *prompt, char **extensions);
char *TXT_SelectFile(const char *prompt, char **extensions);
/**
* Create a new txt_fileselect_t widget.

View file

@ -113,7 +113,7 @@ txt_widget_class_t txt_label_class =
NULL,
};
void TXT_SetLabel(txt_label_t *label, char *value)
void TXT_SetLabel(txt_label_t *label, const char *value)
{
char *p;
unsigned int y;
@ -131,7 +131,7 @@ void TXT_SetLabel(txt_label_t *label, char *value)
label->h = 1;
for (p = value; *p != '\0'; ++p)
for (p = label->label; *p != '\0'; ++p)
{
if (*p == '\n')
{
@ -168,7 +168,7 @@ void TXT_SetLabel(txt_label_t *label, char *value)
}
}
txt_label_t *TXT_NewLabel(char *text)
txt_label_t *TXT_NewLabel(const char *text)
{
txt_label_t *label;

View file

@ -49,7 +49,7 @@ struct txt_label_s
* @return Pointer to the new label widget.
*/
txt_label_t *TXT_NewLabel(char *label);
txt_label_t *TXT_NewLabel(const char *label);
/**
* Set the string displayed in a label widget.
@ -58,7 +58,7 @@ txt_label_t *TXT_NewLabel(char *label);
* @param value The string to display (UTF-8 format).
*/
void TXT_SetLabel(txt_label_t *label, char *value);
void TXT_SetLabel(txt_label_t *label, const char *value);
/**
* Set the background color of a label widget.

View file

@ -180,7 +180,7 @@ void TXT_Sleep(int timeout);
void TXT_SetInputMode(txt_input_mode_t mode);
// Set the window title of the window containing the text mode screen
void TXT_SetWindowTitle(char *title);
void TXT_SetWindowTitle(const char *title);
// Safe string copy.
void TXT_StringCopy(char *dest, const char *src, size_t dest_len);

View file

@ -121,7 +121,7 @@ txt_widget_class_t txt_radiobutton_class =
NULL,
};
txt_radiobutton_t *TXT_NewRadioButton(char *label, int *variable, int value)
txt_radiobutton_t *TXT_NewRadioButton(const char *label, int *variable, int value)
{
txt_radiobutton_t *radiobutton;
@ -135,7 +135,7 @@ txt_radiobutton_t *TXT_NewRadioButton(char *label, int *variable, int value)
return radiobutton;
}
void TXT_SetRadioButtonLabel(txt_radiobutton_t *radiobutton, char *value)
void TXT_SetRadioButtonLabel(txt_radiobutton_t *radiobutton, const char *value)
{
free(radiobutton->label);
radiobutton->label = strdup(value);

View file

@ -63,7 +63,7 @@ struct txt_radiobutton_s
* @return Pointer to the new radio button widget.
*/
txt_radiobutton_t *TXT_NewRadioButton(char *label, int *variable, int value);
txt_radiobutton_t *TXT_NewRadioButton(const char *label, int *variable, int value);
/**
* Set the label on a radio button.
@ -72,7 +72,7 @@ txt_radiobutton_t *TXT_NewRadioButton(char *label, int *variable, int value);
* @param value The new label (UTF-8 format).
*/
void TXT_SetRadioButtonLabel(txt_radiobutton_t *radiobutton, char *value);
void TXT_SetRadioButtonLabel(txt_radiobutton_t *radiobutton, const char *value);
#endif /* #ifndef TXT_RADIOBUTTON_H */

View file

@ -34,7 +34,7 @@
typedef struct
{
char *name;
const char *name;
const uint8_t *data;
unsigned int w;
unsigned int h;
@ -133,7 +133,7 @@ static int Win32_UseLargeFont(void)
#endif
static const txt_font_t *FontForName(char *name)
static const txt_font_t *FontForName(const char *name)
{
int i;
const txt_font_t *fonts[] =
@ -518,7 +518,7 @@ static int TranslateScancode(SDL_Scancode scancode)
}
}
static int TranslateKeysym(SDL_Keysym *sym)
static int TranslateKeysym(const SDL_Keysym *sym)
{
int translated;
@ -558,7 +558,7 @@ static int SDLButtonToTXTButton(int button)
// Convert an SDL wheel motion to a textscreen button index.
static int SDLWheelToTXTButton(SDL_MouseWheelEvent *wheel)
static int SDLWheelToTXTButton(const SDL_MouseWheelEvent *wheel)
{
if (wheel->y <= 0)
{
@ -890,7 +890,7 @@ void TXT_SetInputMode(txt_input_mode_t mode)
input_mode = mode;
}
void TXT_SetWindowTitle(char *title)
void TXT_SetWindowTitle(const char *title)
{
SDL_SetWindowTitle(TXT_SDLWindow, title);
}

View file

@ -73,7 +73,7 @@ static void TXT_SeparatorDestructor(TXT_UNCAST_ARG(separator))
free(separator->label);
}
void TXT_SetSeparatorLabel(txt_separator_t *separator, char *label)
void TXT_SetSeparatorLabel(txt_separator_t *separator, const char *label)
{
free(separator->label);
@ -98,7 +98,7 @@ txt_widget_class_t txt_separator_class =
NULL,
};
txt_separator_t *TXT_NewSeparator(char *label)
txt_separator_t *TXT_NewSeparator(const char *label)
{
txt_separator_t *separator;

View file

@ -50,7 +50,7 @@ extern txt_widget_class_t txt_separator_class;
* @return The new separator widget.
*/
txt_separator_t *TXT_NewSeparator(char *label);
txt_separator_t *TXT_NewSeparator(const char *label);
/**
* Change the label on a separator.
@ -59,7 +59,7 @@ txt_separator_t *TXT_NewSeparator(char *label);
* @param label The new label (UTF-8 format).
*/
void TXT_SetSeparatorLabel(txt_separator_t *separator, char *label);
void TXT_SetSeparatorLabel(txt_separator_t *separator, const char *label);
#endif /* #ifndef TXT_SEPARATOR_H */

View file

@ -52,7 +52,7 @@ void TXT_SetWindowAction(txt_window_t *window,
}
}
txt_window_t *TXT_NewWindow(char *title)
txt_window_t *TXT_NewWindow(const char *title)
{
int i;
@ -508,21 +508,21 @@ void TXT_SetWindowFocus(txt_window_t *window, int focused)
TXT_SetWidgetFocus(window, focused);
}
void TXT_SetWindowHelpURL(txt_window_t *window, char *help_url)
void TXT_SetWindowHelpURL(txt_window_t *window, const char *help_url)
{
window->help_url = help_url;
}
#ifdef _WIN32
void TXT_OpenURL(char *url)
void TXT_OpenURL(const char *url)
{
ShellExecute(NULL, "open", url, NULL, NULL, SW_SHOWNORMAL);
}
#else
void TXT_OpenURL(char *url)
void TXT_OpenURL(const char *url)
{
char *cmd;
size_t cmd_len;
@ -566,7 +566,7 @@ void TXT_OpenWindowHelpURL(txt_window_t *window)
}
}
txt_window_t *TXT_MessageBox(char *title, char *message, ...)
txt_window_t *TXT_MessageBox(const char *title, const char *message, ...)
{
txt_window_t *window;
char buf[256];

View file

@ -88,7 +88,7 @@ struct txt_window_s
// URL of a webpage with help about this window. If set, a help key
// indicator is shown while this window is active.
char *help_url;
const char *help_url;
};
/**
@ -100,7 +100,7 @@ struct txt_window_s
* representing the new window.
*/
txt_window_t *TXT_NewWindow(char *title);
txt_window_t *TXT_NewWindow(const char *title);
/**
* Close a window.
@ -197,7 +197,7 @@ void TXT_SetMouseListener(txt_window_t *window,
* @return The new window.
*/
txt_window_t *TXT_MessageBox(char *title, char *message, ...);
txt_window_t *TXT_MessageBox(const char *title, const char *message, ...);
/**
* Set the help URL for the given window.
@ -207,7 +207,7 @@ txt_window_t *TXT_MessageBox(char *title, char *message, ...);
* window, or NULL to set no help for this window.
*/
void TXT_SetWindowHelpURL(txt_window_t *window, char *help_url);
void TXT_SetWindowHelpURL(txt_window_t *window, const char *help_url);
/**
* Open the help URL for the given window, if one is set.