From 8dede470b17e3cd4b96d658b7096f41af1c8ed98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrico=20Tr=C3=B6ger?= Date: Mon, 11 Sep 2006 07:41:37 +0000 Subject: [PATCH] Made socket code for detecting running instances working under Windows. Fixed compile warnings under Windows. git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@810 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- ChangeLog | 9 ++++++ src/dialogs.c | 5 +++- src/makefile.win32 | 2 +- src/socket.c | 75 ++++++++++++++++++++++++++-------------------- src/ui_utils.c | 6 +++- src/win32.c | 3 +- 6 files changed, 63 insertions(+), 37 deletions(-) diff --git a/ChangeLog b/ChangeLog index eadbf4a3..d3fb6d1a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2006-09-11 Enrico Tröger + + * src/socket.c: Made socket code for detecting running instances + working under Windows. + * src/win32.c, src/ui_utils.c, src/dialogs.c: + Fixed compile warnings under Windows. + * src/highlighting.c: Fixed a typo. + + 2006-09-10 Enrico Tröger * src/sci_cb.c, src/keybindings.c, src/callbacks.c: diff --git a/src/dialogs.c b/src/dialogs.c index f55dc240..6b1699f6 100644 --- a/src/dialogs.c +++ b/src/dialogs.c @@ -46,8 +46,9 @@ #include "keybindings.h" +#ifndef G_OS_WIN32 static GtkWidget *add_file_open_extra_widget(); - +#endif /* This shows the file selection dialog to open a file. */ void dialogs_show_open_file () @@ -152,6 +153,7 @@ void dialogs_show_open_file () } +#ifndef G_OS_WIN32 static GtkWidget *add_file_open_extra_widget() { GtkWidget *vbox; @@ -215,6 +217,7 @@ static GtkWidget *add_file_open_extra_widget() return vbox; } +#endif /* This shows the file selection dialog to save a file. */ diff --git a/src/makefile.win32 b/src/makefile.win32 index c1af04b4..32b9c6b6 100644 --- a/src/makefile.win32 +++ b/src/makefile.win32 @@ -71,7 +71,7 @@ binclean: $(TARGET): $(OBJS) $(RES) ../scintilla/scintilla.a ../tagmanager/tagmanager.a $(CXX) $(OBJS) $(RES) -o $(TARGET) \ ../scintilla/scintilla.a ../tagmanager/tagmanager.a $(ALL_GTK_LIBS) \ - -mwindows -limm32 -lshell32 -lole32 -luuid -lcomdlg32 -lcomctl32 -liberty + -mwindows -limm32 -lshell32 -lole32 -luuid -lcomdlg32 -lcomctl32 -liberty -lwsock32 deps.mak: $(CC) -MM $(CCFLAGS) *.c >deps.mak diff --git a/src/socket.c b/src/socket.c index 34d5d1dc..c1dc2a20 100644 --- a/src/socket.c +++ b/src/socket.c @@ -25,9 +25,14 @@ #ifdef HAVE_SOCKET -#include -#include -#include +#ifndef G_OS_WIN32 +# include +# include +# include +#else +# include +# include +#endif #include #include @@ -37,12 +42,25 @@ +#ifdef G_OS_WIN32 +#define REMOTE_CMD_PORT 49876 +#define SockDesc SOCKET +#define SOCKET_IS_VALID(s) ((s) != INVALID_SOCKET) +#else +#define SockDesc gint +#define SOCKET_IS_VALID(s) ((s) >= 0) +#define INVALID_SOCKET (-1) +#endif + + #ifdef G_OS_WIN32 static gint socket_fd_connect_inet (gushort port); static gint socket_fd_open_inet (gushort port); -#endif +static void socket_init_win32(); +#else static gint socket_fd_connect_unix (const gchar *path); static gint socket_fd_open_unix (const gchar *path); +#endif static gint socket_fd_write (gint sock, const gchar *buf, gint len); static gint socket_fd_write_all (gint sock, const gchar *buf, gint len); @@ -63,6 +81,7 @@ gint socket_init(gint argc, gchar **argv) #ifdef G_OS_WIN32 HANDLE hmutex; + socket_init_win32(); hmutex = CreateMutexA(NULL, FALSE, "Geany"); if (! hmutex) { @@ -135,7 +154,9 @@ gint socket_finalize(void) socket_info.read_ioc = NULL; } -#ifndef G_OS_WIN32 +#ifdef G_OS_WIN32 + WSACleanup(); +#else unlink(socket_info.file_name); g_free(socket_info.file_name); #endif @@ -144,19 +165,9 @@ gint socket_finalize(void) } -#ifdef G_OS_WIN32 -#define SockDesc SOCKET -#define SOCKET_IS_VALID(s) ((s) != INVALID_SOCKET) -#else -#define SockDesc gint -#define SOCKET_IS_VALID(s) ((s) >= 0) -#define INVALID_SOCKET (-1) -#endif - - +#ifdef G_OS_UNIX static gint socket_fd_connect_unix(const gchar *path) { -#ifdef G_OS_UNIX gint sock; struct sockaddr_un addr; @@ -178,15 +189,11 @@ static gint socket_fd_connect_unix(const gchar *path) } return sock; -#else - return -1; -#endif } static gint socket_fd_open_unix(const gchar *path) { -#ifdef G_OS_UNIX gint sock; struct sockaddr_un addr; gint val; @@ -226,11 +233,8 @@ static gint socket_fd_open_unix(const gchar *path) } return sock; -#else - return -1; -#endif } - +#endif static gint socket_fd_close(gint fd) { @@ -247,16 +251,12 @@ static gint socket_fd_open_inet(gushort port) { SockDesc sock; struct sockaddr_in addr; - gint val; + gchar val; sock = socket(AF_INET, SOCK_STREAM, 0); if (! SOCKET_IS_VALID(sock)) { -#ifdef G_OS_WIN32 geany_debug("fd_open_inet(): socket() failed: %ld\n", WSAGetLastError()); -#else - perror("fd_open_inet(): socket"); -#endif return -1; } @@ -299,11 +299,7 @@ static gint socket_fd_connect_inet(gushort port) sock = socket(AF_INET, SOCK_STREAM, 0); if (! SOCKET_IS_VALID(sock)) { -#ifdef G_OS_WIN32 geany_debug("fd_connect_inet(): socket() failed: %ld\n", WSAGetLastError()); -#else - perror("fd_connect_inet(): socket"); -#endif return -1; } @@ -320,6 +316,17 @@ static gint socket_fd_connect_inet(gushort port) return sock; } + + +static void socket_init_win32() +{ + WSADATA wsadata; + + if (WSAStartup(MAKEWORD(2, 2), &wsadata) != NO_ERROR) + geany_debug("WSAStartup() failed\n"); + + return; +} #endif @@ -408,7 +415,9 @@ static gint socket_fd_check_io(gint fd, GIOCondition cond) { struct timeval timeout; fd_set fds; +#ifdef G_OS_UNIX gint flags; +#endif timeout.tv_sec = 60; timeout.tv_usec = 0; diff --git a/src/ui_utils.c b/src/ui_utils.c index e686615a..7c3e5725 100644 --- a/src/ui_utils.c +++ b/src/ui_utils.c @@ -46,9 +46,10 @@ static void recent_file_activate_cb (GtkMenuItem *menuitem, gpointer user_data); +#ifndef G_OS_WIN32 static GtkWidget *create_build_menu_tex(gint idx); static GtkWidget *create_build_menu_gen(gint idx); - +#endif /* allow_override is TRUE if text can be ignored when another message has been set * that didn't use allow_override and has not timed out. */ @@ -751,6 +752,8 @@ void ui_build_show_hide(gint idx) } +#ifndef G_OS_WIN32 + #define GEANY_ADD_WIDGET_ACCEL(gkey, menuitem) \ if (keys[(gkey)]->key != 0) \ gtk_widget_add_accelerator(menuitem, "activate", accel_group, \ @@ -973,6 +976,7 @@ static GtkWidget *create_build_menu_tex(gint idx) return menu; } +#endif void ui_treeviews_show_hide(gboolean force) diff --git a/src/win32.c b/src/win32.c index 32ad39f7..991ce5bd 100644 --- a/src/win32.c +++ b/src/win32.c @@ -40,6 +40,7 @@ #include "document.h" #include "support.h" #include "utils.h" +#include "ui_utils.h" #include "sciwrappers.h" #include "dialogs.h" @@ -210,7 +211,7 @@ void win32_show_font_dialog(void) { gchar *editorfont = g_strdup_printf("%s %d", lf.lfFaceName, (cf.iPointSize / 10)); - utils_set_editor_font(editorfont); + ui_set_editor_font(editorfont); g_free(editorfont); } }