Add "const" specifier in prototypes
It's easier then to know when variables are read-only (and shouldn't
be freed).
--- a/mcabber/src/histolog.c Wed Jul 06 21:28:37 2005 +0100
+++ b/mcabber/src/histolog.c Wed Jul 06 22:18:05 2005 +0100
@@ -219,7 +219,7 @@
// hlog_enable()
// Enable logging to files. If root_dir is NULL, then $HOME/.mcabber is used.
// If loadfiles is TRUE, we will try to load buddies history logs from file.
-void hlog_enable(guint enable, char *root_dir, guint loadfiles)
+void hlog_enable(guint enable, const char *root_dir, guint loadfiles)
{
UseFileLogging = enable;
FileLoadLogs = loadfiles;
--- a/mcabber/src/histolog.h Wed Jul 06 21:28:37 2005 +0100
+++ b/mcabber/src/histolog.h Wed Jul 06 22:18:05 2005 +0100
@@ -5,7 +5,7 @@
#include "jabglue.h"
-void hlog_enable(guint enable, char *root_dir, guint loadfile);
+void hlog_enable(guint enable, const char *root_dir, guint loadfile);
void hlog_read_history(const char *jid, GList **p_buddyhbuf, guint width);
inline void hlog_write_message(const char *jid, time_t timestamp, int sent,
const char *msg);
--- a/mcabber/src/hooks.c Wed Jul 06 21:28:37 2005 +0100
+++ b/mcabber/src/hooks.c Wed Jul 06 22:18:05 2005 +0100
@@ -90,7 +90,7 @@
// hk_ext_cmd_init()
// Initialize external command variable.
// Can be called with parameter NULL to reset and free memory.
-void hk_ext_cmd_init(char *command)
+void hk_ext_cmd_init(const char *command)
{
if (extcommand) {
g_free(extcommand);
--- a/mcabber/src/hooks.h Wed Jul 06 21:28:37 2005 +0100
+++ b/mcabber/src/hooks.h Wed Jul 06 22:18:05 2005 +0100
@@ -12,7 +12,7 @@
inline void hk_mystatuschange(time_t timestamp,
enum imstatus old_status, enum imstatus new_status);
-void hk_ext_cmd_init(char *command);
+void hk_ext_cmd_init(const char *command);
void hk_ext_cmd(const char *jid, guchar type, guchar info, const char *data);
#endif /* __HOOKS_H__ */
--- a/mcabber/src/main.c Wed Jul 06 21:28:37 2005 +0100
+++ b/mcabber/src/main.c Wed Jul 06 22:18:05 2005 +0100
@@ -88,9 +88,9 @@
int main(int argc, char **argv)
{
char *configFile = NULL;
- char *username, *password, *resource, *servername;
+ const char *username, *password, *resource, *servername;
char *jid;
- char *optstring;
+ const char *optstring;
int optval, optval2;
int ssl;
int key;
@@ -153,10 +153,10 @@
char *p;
size_t passsize = 64;
printf("Please enter password: ");
- my_getpass(&password, &passsize);
+ my_getpass((char**)&password, &passsize);
printf("\n");
- for (p = password; *p; p++);
- for ( ; p > password ; p--)
+ for (p = (char*)password; *p; p++);
+ for ( ; p > (char*)password ; p--)
if (*p == '\n' || *p == '\r') *p = 0;
}
--- a/mcabber/src/screen.c Wed Jul 06 21:28:37 2005 +0100
+++ b/mcabber/src/screen.c Wed Jul 06 22:18:05 2005 +0100
@@ -108,7 +108,7 @@
}
}
-int FindColor(char *name)
+int FindColor(const char *name)
{
if (!strcmp(name, "default"))
return -1;
@@ -134,7 +134,7 @@
void ParseColors(void)
{
- char *colors[8] = {
+ const char *colors[8] = {
"", "",
"general",
"newmsg",
@@ -144,9 +144,9 @@
};
char *tmp = malloc(1024);
- char *color;
- char *background = settings_opt_get("color_background");
- char *backselected = settings_opt_get("color_backselected");
+ const char *color;
+ const char *background = settings_opt_get("color_background");
+ const char *backselected = settings_opt_get("color_backselected");
int i = 0;
// Default values
--- a/mcabber/src/settings.c Wed Jul 06 21:28:37 2005 +0100
+++ b/mcabber/src/settings.c Wed Jul 06 22:18:05 2005 +0100
@@ -44,7 +44,7 @@
}
// Return a pointer to the node with the requested key, or NULL if none found
-GSList *settings_find(GSList *list, gchar *key)
+GSList *settings_find(GSList *list, const gchar *key)
{
GSList *ptr;
@@ -69,7 +69,7 @@
// to NULL and return FALSE.
//
// The called should g_free() *pkey and *pval (if not NULL) after use.
-guint parse_assigment(gchar *assignment, gchar **pkey, gchar **pval)
+guint parse_assigment(gchar *assignment, const gchar **pkey, const gchar **pval)
{
char *key, *val, *t;
@@ -114,7 +114,7 @@
return TRUE;
}
-void settings_set(guint type, gchar *key, gchar *value)
+void settings_set(guint type, const gchar *key, const gchar *value)
{
GSList **plist;
GSList *sptr;
@@ -145,12 +145,12 @@
}
}
-void settings_del(guint type, gchar *key)
+void settings_del(guint type, const gchar *key)
{
settings_set(type, key, NULL);
}
-gchar *settings_get(guint type, gchar *key)
+const gchar *settings_get(guint type, const gchar *key)
{
GSList **plist;
GSList *sptr;
@@ -164,9 +164,9 @@
return setting->value;
}
-int settings_get_int(guint type, gchar *key)
+int settings_get_int(guint type, const gchar *key)
{
- gchar *setval = settings_get(type, key);
+ const gchar *setval = settings_get(type, key);
if (setval) return atoi(setval);
return 0;
--- a/mcabber/src/settings.h Wed Jul 06 21:28:37 2005 +0100
+++ b/mcabber/src/settings.h Wed Jul 06 22:18:05 2005 +0100
@@ -10,11 +10,12 @@
#define settings_opt_get(k) settings_get(SETTINGS_TYPE_OPTION, k)
#define settings_opt_get_int(k) settings_get_int(SETTINGS_TYPE_OPTION, k)
-guint parse_assigment(gchar *assignment, gchar **pkey, gchar **pval);
-void settings_set(guint type, gchar *key, gchar *value);
-void settings_del(guint type, gchar *key);
-gchar *settings_get(guint type, gchar *key);
-int settings_get_int(guint type, gchar *key);
+guint parse_assigment(gchar *assignment,
+ const gchar **pkey, const gchar **pval);
+void settings_set(guint type, const gchar *key, const gchar *value);
+void settings_del(guint type, const gchar *key);
+const gchar *settings_get(guint type, const gchar *key);
+int settings_get_int(guint type, const gchar *key);
#endif /* __SETTINGS_H__ */
--- a/mcabber/src/utils.c Wed Jul 06 21:28:37 2005 +0100
+++ b/mcabber/src/utils.c Wed Jul 06 22:18:05 2005 +0100
@@ -32,7 +32,7 @@
static int DebugEnabled;
static char *FName;
-void ut_InitDebug(unsigned int level, char *filename)
+void ut_InitDebug(unsigned int level, const char *filename)
{
FILE *fp;
--- a/mcabber/src/utils.h Wed Jul 06 21:28:37 2005 +0100
+++ b/mcabber/src/utils.h Wed Jul 06 22:18:05 2005 +0100
@@ -1,7 +1,7 @@
#ifndef __UTILS_H__
#define __UTILS_H__ 1
-void ut_InitDebug(unsigned int level, char *file);
+void ut_InitDebug(unsigned int level, const char *file);
void ut_WriteLog(const char *fmt, ...);
int to_iso8601(char *dststr, time_t timestamp);