2
2
* socket.h - this file is part of Geany, a fast and lightweight IDE
4
* Copyright 2006 Enrico Tröger <enrico.troeger@uvena.de>
4
* Copyright 2006-2007 Enrico Tröger <enrico.troeger@uvena.de>
5
* Copyright 2006-2007 Nick Treleaven <nick.treleaven@btinternet.com>
6
7
* This program is free software; you can redistribute it and/or modify
7
8
* it under the terms of the GNU General Public License as published by
17
18
* along with this program; if not, write to the Free Software
18
19
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
* $Id: socket.c 1052 2006-12-05 10:23:51Z ntrel $
21
* $Id: socket.c 1270 2007-02-12 18:42:15Z eht16 $
81
void send_open_command(gint sock, gint argc, gchar **argv)
86
g_return_if_fail(argc > 1);
87
geany_debug("using running instance of Geany");
89
if (cl_options.goto_line >= 0)
91
gchar *line = g_strdup_printf("%d\n", cl_options.goto_line);
92
socket_fd_write_all(sock, "line\n", 5);
93
socket_fd_write_all(sock, line, strlen(line));
94
socket_fd_write_all(sock, ".\n", 2);
98
socket_fd_write_all(sock, "open\n", 5);
100
for(i = 1; i < argc && argv[i] != NULL; i++)
102
filename = get_argv_filename(argv[i]);
104
if (filename != NULL &&
105
g_file_test(filename, G_FILE_TEST_IS_REGULAR | G_FILE_TEST_IS_SYMLINK))
107
socket_fd_write_all(sock, filename, strlen(filename));
108
socket_fd_write_all(sock, "\n", 1);
112
g_printerr(_("Could not find file '%s'."), filename);
113
g_printerr("\n"); // keep translation from open_cl_files() in main.c.
117
socket_fd_write_all(sock, ".\n", 2);
78
121
/* (Unix domain) socket support to replace the old FIFO code
79
122
* (taken from Sylpheed, thanks) */
80
123
gint socket_init(gint argc, gchar **argv)
118
161
// remote command mode, here we have another running instance and want to use it
124
geany_debug("using running instance of Geany");
126
socket_fd_write_all(sock, "open\n", 5);
128
for(i = 1; i < argc && argv[i] != NULL; i++)
130
filename = get_argv_filename(argv[i]);
132
if (filename != NULL)
134
socket_fd_write_all(sock, filename, strlen(filename));
135
socket_fd_write_all(sock, "\n", 1);
139
socket_fd_write_all(sock, ".\n", 2);
164
send_open_command(sock, argc, argv);
142
167
socket_fd_close(sock);
349
374
sock = accept(fd, (struct sockaddr *)&caddr, &caddr_len);
351
376
// first get the command
352
if (socket_fd_gets(sock, buf, sizeof(buf)) != -1 && strncmp(buf, "open", 4) == 0)
377
while (socket_fd_gets(sock, buf, sizeof(buf)) != -1)
354
geany_debug("remote command: open");
355
while (socket_fd_gets(sock, buf, sizeof(buf)) != -1 && *buf != '.')
379
if (strncmp(buf, "open", 4) == 0)
357
g_strstrip(buf); // remove \n char
381
while (socket_fd_gets(sock, buf, sizeof(buf)) != -1 && *buf != '.')
383
g_strstrip(buf); // remove \n char
359
if (g_file_test(buf, G_FILE_TEST_IS_REGULAR | G_FILE_TEST_IS_SYMLINK))
360
document_open_file(-1, buf, 0, FALSE, NULL, NULL);
362
geany_debug("got data from socket, but it does not look like a filename");
364
gtk_window_deiconify(GTK_WINDOW(app->window));
385
if (g_file_test(buf, G_FILE_TEST_IS_REGULAR | G_FILE_TEST_IS_SYMLINK))
386
document_open_file(-1, buf, 0, FALSE, NULL, NULL);
388
geany_debug("got data from socket, but it does not look like a filename");
390
gtk_window_deiconify(GTK_WINDOW(app->window));
365
391
#ifdef G_OS_WIN32
366
gtk_window_present(GTK_WINDOW(app->window));
392
gtk_window_present(GTK_WINDOW(app->window));
395
else if (strncmp(buf, "line", 4) == 0)
397
while (socket_fd_gets(sock, buf, sizeof(buf)) != -1 && *buf != '.')
399
g_strstrip(buf); // remove \n char
400
// on any error we get 0 which should be save enough as fallback
401
cl_options.goto_line = atoi(buf);
370
405
socket_fd_close(sock);