2 * luakit.c - luakit main functions
4 * Copyright (C) 2010 Mason Larobina <mason.larobina@gmail.com>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 * MIT/X Consortium License (applies to some functions from surf.c)
24 * (C) 2009 Enno Boland <gottox@s01.de>
26 * See COPYING.MIT for the full license.
30 #include "common/util.h"
31 #include "common/signal.h"
38 static void sigchld(int sigint
);
43 if (signal(SIGCHLD
, sigchld
) == SIG_ERR
)
44 fatal("Can't install SIGCHLD handler");
45 while(0 < waitpid(-1, NULL
, WNOHANG
));
48 /* load command line options into luakit and return uris to load */
50 parseopts(int argc
, char *argv
[]) {
51 GOptionContext
*context
;
53 gboolean
*only_version
= NULL
;
56 /* define command line options */
57 const GOptionEntry entries
[] = {
58 { "uri", 'u', 0, G_OPTION_ARG_STRING_ARRAY
, &uris
,
59 "uri(s) to load at startup", "URI" },
60 { "config", 'c', 0, G_OPTION_ARG_STRING
, &l
->confpath
,
61 "configuration file to use", "FILE" },
62 { "version", 'V', 0, G_OPTION_ARG_NONE
, &only_version
,
63 "show version", NULL
},
64 { NULL
, 0, 0, 0, NULL
, NULL
, NULL
}};
66 /* parse command line options */
67 context
= g_option_context_new("[URI...]");
68 g_option_context_add_main_entries(context
, entries
, NULL
);
69 g_option_context_add_group(context
, gtk_get_option_group(TRUE
));
70 // TODO Passing gtk options (like --sync) to luakit causes a segfault right
71 // here. I'm clueless.
72 g_option_context_parse(context
, &argc
, &argv
, NULL
);
73 g_option_context_free(context
);
75 /* print version and exit */
77 g_printf("Version: %s\n", VERSION
);
82 fatal("invalid mix of -u and default uri arguments");
91 init_lua(gchar
**uris
)
97 /* init global signals tree */
98 l
->signals
= signal_tree_new();
100 /* get XDG basedir data */
106 /* push a table of the statup uris */
108 for (gint i
= 0; (uri
= uris
[i
]); i
++) {
109 lua_pushstring(l
->L
, uri
);
110 lua_rawseti(l
->L
, -2, i
+ 1);
112 lua_setglobal(l
->L
, "uris");
114 /* parse and run configuration file */
115 if(!luaH_parserc(&xdg
, l
->confpath
, TRUE
))
116 fatal("couldn't find rc file");
118 /* we are finished with this */
123 main(int argc
, char *argv
[]) {
126 /* clean up any zombies */
129 gtk_init(&argc
, &argv
);
130 if (!g_thread_supported())
133 /* parse command line opts and get uris to load */
134 uris
= parseopts(argc
, argv
);
141 // vim: ft=c:et:sw=4:ts=8:sts=4:enc=utf-8:tw=80