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.
34 #include "globalconf.h"
35 #include "common/util.h"
39 static void sigchld(int sigint
);
44 if (signal(SIGCHLD
, sigchld
) == SIG_ERR
)
45 fatal("Can't install SIGCHLD handler");
46 while(0 < waitpid(-1, NULL
, WNOHANG
));
49 /* load command line options into luakit and return uris to load */
51 parseopts(int argc
, char *argv
[]) {
52 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
, &globalconf
.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 globalconf structs */
98 globalconf
.signals
= signal_tree_new();
99 globalconf
.windows
= g_ptr_array_new();
101 /* get XDG basedir data */
108 /* push a table of the statup uris */
110 for (gint i
= 0; (uri
= uris
[i
]); i
++) {
111 lua_pushstring(L
, uri
);
112 lua_rawseti(L
, -2, i
+ 1);
114 lua_setglobal(L
, "uris");
116 /* parse and run configuration file */
117 if(!luaH_parserc(&xdg
, globalconf
.confpath
, TRUE
))
118 fatal("couldn't find rc file");
120 if (!globalconf
.windows
->len
)
121 fatal("no windows spawned by rc file load, exiting");
123 /* we are finished with this */
130 /* create luakit directory */
131 globalconf
.base_directory
= g_build_filename(g_get_home_dir(), LUAKIT_CONFIG_DIR
, NULL
);
132 g_mkdir_with_parents(globalconf
.base_directory
, 0771);
136 main(int argc
, char *argv
[]) {
139 /* clean up any zombies */
142 gtk_init(&argc
, &argv
);
143 if (!g_thread_supported())
146 /* parse command line opts and get uris to load */
147 uris
= parseopts(argc
, argv
);
155 // vim: ft=c:et:sw=4:ts=8:sts=4:enc=utf-8:tw=80