[CF-Devel] Patch: GTK client warning cleaning
crossfire-devel at archives.real-time.com
crossfire-devel at archives.real-time.com
Tue Jan 27 14:15:44 CST 2004
Hello.
Here's a patch to clean compilation warnings i saw under Win32.
As some may impact Linux part, i submit it here (others which are Win32 specific
i have committed straight).
Basically, most fixes are 'const' fixing. Some strings were sent as 'char*' when
'const char*' was better, stuff like that.
So some function prototypes (strdup_local, send_reply for instance) were tweaked
to use const when available.
Also some GTK calls did not (at least under Win32 & GTK2) enforce the const
specifier, so i added the correct GTK specification.
Last but not least, i changed 3 prototypes for images-related commands, to match
other commands (ok, unsigned int8 is usually equivalent to unsigned char, but
someone may try on a platform with multibyte characters...)
Nicolas 'Ryo'
-------------- next part --------------
? client.warnings.patch
? gtk/win32/GTKClient.aps
? gtk/win32/gtkclient.nsi
? gtk/win32/quantify
Index: common/commands.c
===================================================================
RCS file: /cvsroot/crossfire/client/common/commands.c,v
retrieving revision 1.19
diff -u -r1.19 commands.c
--- common/commands.c 26 Jan 2004 16:54:34 -0000 1.19
+++ common/commands.c 27 Jan 2004 20:04:41 -0000
@@ -258,7 +258,11 @@
/* Not much we can do about someone playing on an ancient server. */
if (!strcmp(param,"FALSE")) {
draw_info("Server does not support map1cmd - This server is too old to support this client!", NDI_RED);
+#ifdef WIN32
+ closesocket(csocket.fd);
+#else
close(csocket.fd);
+#endif
csocket.fd = -1;
}
} else if (!strcmp(cmd,"itemcmd")) {
@@ -610,7 +614,7 @@
* the stuff up.
*/
-void send_reply(char *text)
+void send_reply(const char *text)
{
cs_print_string(csocket.fd, "reply %s", text);
}
Index: common/image.c
===================================================================
RCS file: /cvsroot/crossfire/client/common/image.c,v
retrieving revision 1.11
diff -u -r1.11 image.c
--- common/image.c 13 Nov 2003 18:22:31 -0000 1.11
+++ common/image.c 27 Jan 2004 20:04:45 -0000
@@ -33,7 +33,10 @@
#include "config.h"
#include <stdlib.h>
#include <sys/stat.h>
-#ifndef WIN32
+#ifdef WIN32
+#include <io.h>
+#include <direct.h>
+#else
#include <unistd.h>
#endif
#include <ctype.h>
@@ -556,7 +559,7 @@
finish_face_cmd(pnum, checksum, 1, face,0);
}
-void Face2Cmd(uint8 *data, int len)
+void Face2Cmd(unsigned char *data, int len)
{
int pnum;
uint8 setnum;
@@ -579,7 +582,7 @@
finish_face_cmd(pnum, checksum, 1, face,setnum);
}
-void ImageCmd(uint8 *data, int len)
+void ImageCmd(unsigned char *data, int len)
{
int pnum,plen;
@@ -594,7 +597,7 @@
}
-void Image2Cmd(uint8 *data, int len)
+void Image2Cmd(unsigned char *data, int len)
{
int pnum,plen;
uint8 setnum;
@@ -630,12 +633,20 @@
/* Make necessary leading directories */
sprintf(filename, "%s/.crossfire/crossfire-images",getenv("HOME"));
if (access(filename, R_OK | W_OK | X_OK)== -1)
+#ifdef WIN32
+ mkdir(filename);
+#else
mkdir(filename, 0755);
+#endif
sprintf(filename, "%s/.crossfire/crossfire-images/%c%c", getenv("HOME"),
facetoname[face][0], facetoname[face][1]);
if (access(filename, R_OK | W_OK | X_OK)== -1)
+#ifdef WIN32
+ mkdir(filename);
+#else
mkdir(filename,0755);
+#endif
/* If setnum is valid, and we have faceset information for it,
* put that prefix in. This will make it easier later on to
Index: common/misc.c
===================================================================
RCS file: /cvsroot/crossfire/client/common/misc.c,v
retrieving revision 1.2
diff -u -r1.2 misc.c
--- common/misc.c 4 Nov 2001 02:53:48 -0000 1.2
+++ common/misc.c 27 Jan 2004 20:04:45 -0000
@@ -38,6 +38,10 @@
#include <sys/stat.h>
+#ifdef WIN32
+#include <direct.h>
+#endif
+
/*
* Verifies that the directory exists, creates it if necessary
@@ -55,7 +59,11 @@
while ((cp = strchr (cp + 1, (int) '/'))) {
*cp = '\0';
if (stat (buf, &statbuf) || !S_ISDIR (statbuf.st_mode)) {
+#ifdef WIN32
+ if (mkdir (buf)) {
+#else
if (mkdir (buf, 0777)) {
+#endif
perror ("Couldn't make path to file");
return -1;
}
@@ -64,7 +72,11 @@
}
/* Need to make the final component */
if (stat (buf, &statbuf) || !S_ISDIR (statbuf.st_mode)) {
+#ifdef WIN32
+ if (mkdir (buf)) {
+#else
if (mkdir (buf, 0777)) {
+#endif
perror ("Couldn't make path to file");
return -1;
}
@@ -88,7 +100,11 @@
while ((cp = strchr (cp + 1, (int) '/'))) {
*cp = '\0';
if (stat (buf, &statbuf) || !S_ISDIR (statbuf.st_mode)) {
+#ifdef WIN32
+ if (mkdir (buf)) {
+#else
if (mkdir (buf, 0777)) {
+#endif
perror ("Couldn't make path to file");
return -1;
}
@@ -102,7 +118,7 @@
* unix variants.
*/
-char *strdup_local(char *str) {
+char *strdup_local(const char *str) {
char *c=(char *)malloc(sizeof(char)*strlen(str)+1);
strcpy(c,str);
return c;
Index: common/player.c
===================================================================
RCS file: /cvsroot/crossfire/client/common/player.c,v
retrieving revision 1.9
diff -u -r1.9 player.c
--- common/player.c 10 Nov 2003 15:11:19 -0000 1.9
+++ common/player.c 27 Jan 2004 20:04:46 -0000
@@ -380,7 +380,11 @@
else if (!strcmp(cp,"clearinfo")) menu_clear();
else if (!strcmp(cp,"cwindow")) set_command_window(cpnext);
else if (!strcmp(cp,"disconnect")) {
+#ifdef WIN32
+ closesocket(csocket.fd);
+#else
close(csocket.fd);
+#endif
csocket.fd=-1;
return;
}
@@ -449,7 +453,7 @@
* the commands the server supports.
*/
-static char *commands[] = {
+static const char *commands[] = {
"save", "sound", "party", "gsay", "apply", "brace",
"cast", "disarm", "disconnect", "drop", "dropall", "examine",
"get", "help", "hiscore", "inventory", "invoke",
@@ -468,10 +472,10 @@
* command.
*/
-char * complete_command(char *command)
+const char * complete_command(const char *command)
{
int i, match=-1, len;
- char *cp;
+ const char *cp;
if (command[0] == '>') cp = command+1;
else cp = command;
Index: common/proto.h
===================================================================
RCS file: /cvsroot/crossfire/client/common/proto.h,v
retrieving revision 1.10
diff -u -r1.10 proto.h
--- common/proto.h 10 Oct 2003 06:33:47 -0000 1.10
+++ common/proto.h 27 Jan 2004 20:04:47 -0000
@@ -14,7 +14,7 @@
extern void DrawInfoCmd(char *data, int len);
extern void StatsCmd(unsigned char *data, int len);
extern void handle_query(char *data, int len);
-extern void send_reply(char *text);
+extern void send_reply(const char *text);
extern void PlayerCmd(unsigned char *data, int len);
extern void item_actions(item *op);
extern void Item1Cmd(unsigned char *data, int len);
@@ -40,9 +40,9 @@
extern void reset_image_cache_data(void);
extern void FaceCmd(unsigned char *data, int len);
extern void Face1Cmd(unsigned char *data, int len);
-extern void Face2Cmd(uint8 *data, int len);
-extern void ImageCmd(uint8 *data, int len);
-extern void Image2Cmd(uint8 *data, int len);
+extern void Face2Cmd(unsigned char *data, int len);
+extern void ImageCmd(unsigned char *data, int len);
+extern void Image2Cmd(unsigned char *data, int len);
extern void display_newpng(long face, uint8 *buf, long buflen, int setnum);
extern void get_image_info(char *data, int len);
extern void get_image_sums(uint8 *data, int len);
@@ -80,7 +80,7 @@
/* misc.c */
extern int make_path_to_dir(char *directory);
extern int make_path_to_file(char *filename);
-extern char *strdup_local(char *str);
+extern char *strdup_local(const char *str);
/* newsocket.c */
extern void LOG(int logLevel, char *format, ...);
extern void SockList_Init(SockList *sl, char *buf);
@@ -113,4 +113,4 @@
extern void CompleteCmd(unsigned char *data, int len);
extern void command_take(const char *command, char *cpnext);
extern void extended_command(const char *ocommand);
-extern char *complete_command(char *command);
+extern const char *complete_command(const char *command);
Index: gtk/gx11.c
===================================================================
RCS file: /cvsroot/crossfire/client/gtk/gx11.c,v
retrieving revision 1.41
diff -u -r1.41 gx11.c
--- gtk/gx11.c 26 Jan 2004 19:40:21 -0000 1.41
+++ gtk/gx11.c 27 Jan 2004 20:05:08 -0000
@@ -655,7 +655,8 @@
void gtk_complete_command()
{
- gchar *entry_text, *newcommand;
+ G_CONST_RETURN gchar *entry_text;
+ const char *newcommand;
entry_text = gtk_entry_get_text(GTK_ENTRY(entrytext));
newcommand = complete_command(entry_text);
@@ -1161,7 +1162,7 @@
static void enter_callback(GtkWidget *widget, GtkWidget *entry)
{
- gchar *entry_text;
+ G_CONST_RETURN gchar *entry_text;
/* Next reply will reset this as necessary */
if (!use_config[CONFIG_POPUPS])
@@ -1394,7 +1395,7 @@
static void dialog_callback(GtkWidget *dialog)
{
- gchar *dialog_text;
+ G_CONST_RETURN gchar *dialog_text;
dialog_text = gtk_entry_get_text(GTK_ENTRY(dialogtext));
#ifdef WIN32
@@ -2917,7 +2918,7 @@
void count_callback(GtkWidget *widget, GtkWidget *entry)
{
- gchar *count_text;
+ G_CONST_RETURN gchar *count_text;
count_text = gtk_entry_get_text(GTK_ENTRY(counttext));
cpl.count = atoi (count_text);
@@ -3299,7 +3300,11 @@
void disconnect(GtkWidget *widget) {
+#ifdef WIN32
+ closesocket(csocket.fd);
+#else
close(csocket.fd);
+#endif
csocket.fd = -1;
if (csocket_fd) {
gdk_input_remove(csocket_fd);
Index: gtk/keys.c
===================================================================
RCS file: /cvsroot/crossfire/client/gtk/keys.c,v
retrieving revision 1.9
diff -u -r1.9 keys.c
--- gtk/keys.c 26 Jan 2004 22:52:44 -0000 1.9
+++ gtk/keys.c 27 Jan 2004 20:05:11 -0000
@@ -111,7 +111,7 @@
* that the keyboard is in.
* This function is common to both gdk and x11 client
*/
-static void insert_key(uint32 keysym, int flags, char *command)
+static void insert_key(uint32 keysym, int flags, const char *command)
{
Key_Entry *newkey;
@@ -157,6 +157,8 @@
uint32 keysym;
int flags;
+ cp = NULL; /* Initialized because _may_ have weird cases when used non initialized else */
+
if (buf[0]=='#' || buf[0]=='\n') return;
if ((cpnext = strchr(buf,' '))==NULL) {
fprintf(stderr,"Line %d (%s) corrupted in keybinding file.\n", line,buf);
@@ -494,6 +496,9 @@
(cpl.fire_on? "Fire&": ""),
(cpl.run_on ? "Run&" : ""),
keysym==NoSymbol? "unknown": gdk_keyval_name(keysym));
+#ifdef WIN32
+ if ( ( 65513 != keysym ) && ( 65511 != keysym ) )
+#endif
draw_info(buf,NDI_BLACK);
cpl.count=0;
}
@@ -1111,9 +1116,9 @@
void bind_callback (GtkWidget *gtklist, GdkEventButton *event) {
KeySym keysym;
- gchar *entry_text;
- gchar *cpnext;
- gchar *mod="";
+ G_CONST_RETURN gchar *entry_text;
+ G_CONST_RETURN gchar *cpnext;
+ G_CONST_RETURN gchar *mod="";
char buf[MAX_BUF];
bind_flags = KEYF_MODIFIERS;
-------------- next part --------------
_______________________________________________
crossfire-devel mailing list
crossfire-devel at lists.real-time.com
https://mailman.real-time.com/mailman/listinfo/crossfire-devel
More information about the crossfire
mailing list