order of arguments to scripts
[uzbl-00z.git] / uzblctrl.c
blob46f3a23f388d0632bfb3c433ececdaaf91a130c2
1 /* Socket code more or less completely copied from here: http://www.ecst.csuchico.edu/~beej/guide/ipc/usock.html */
3 #include <gtk/gtk.h>
4 #include <gdk/gdkx.h>
5 #include <gdk/gdkkeysyms.h>
6 #include <webkit/webkit.h>
7 #include <pthread.h>
8 #include <stdio.h>
9 #include <string.h>
10 #include <sys/stat.h>
11 #include <sys/types.h>
12 #include <unistd.h>
13 #include <stdlib.h>
14 #include <errno.h>
15 #include <string.h>
16 #include <sys/types.h>
17 #include <sys/socket.h>
18 #include <sys/un.h>
20 static gchar* sockpath;
21 static gchar* command;
23 static GOptionEntry entries[] =
25 { "socket", 's', 0, G_OPTION_ARG_STRING, &sockpath, "Socket path of the client uzbl", NULL },
26 { "command", 'c', 0, G_OPTION_ARG_STRING, &command, "The uzbl command to execute", NULL },
27 { NULL, 0, 0, 0, NULL, NULL, NULL }
30 int
31 main(int argc, char* argv[]) {
32 GError *error = NULL;
33 GOptionContext* context = g_option_context_new ("- some stuff here maybe someday");
34 g_option_context_add_main_entries (context, entries, NULL);
35 g_option_context_add_group (context, gtk_get_option_group (TRUE));
36 g_option_context_parse (context, &argc, &argv, &error);
38 int s, len;
39 struct sockaddr_un remote;
41 if ((s = socket (AF_UNIX, SOCK_STREAM, 0)) == -1) {
42 perror ("socket");
43 exit (1);
46 remote.sun_family = AF_UNIX;
47 strcpy (remote.sun_path, (char *) sockpath);
48 len = strlen (remote.sun_path) + sizeof (remote.sun_family);
50 if (connect (s, (struct sockaddr *) &remote, len) == -1) {
51 perror ("connect");
52 exit (1);
55 if (send (s, command, strlen (command), 0) == -1) {
56 perror ("send");
57 exit (1);
60 close(s);
62 return 0;
64 /* vi: set et ts=4: */