+}
+
+int main(int argc, char **argv)
+{
+#ifdef X11
+ char *s, *temp;
+ unsigned int x;
+#endif
+
+ argc_copy = argc;
+ argv_copy = argv;
+ g_signal_pending = 0;
+ max_user_text = MAX_USER_TEXT_DEFAULT;
+ current_config = 0;
+ memset(&info, 0, sizeof(info));
+ memset(template, 0, sizeof(template));
+ clear_net_stats();
+
+#ifdef TCP_PORT_MONITOR
+ /* set default connection limit */
+ tcp_portmon_set_max_connections(0);
+#endif
+
+ /* handle command line parameters that don't change configs */
+#ifdef X11
+ if (((s = getenv("LC_ALL")) && *s) || ((s = getenv("LC_CTYPE")) && *s)
+ || ((s = getenv("LANG")) && *s)) {
+ temp = (char *) malloc((strlen(s) + 1) * sizeof(char));
+ if (temp == NULL) {
+ ERR("malloc failed");
+ }
+ for (x = 0; x < strlen(s); x++) {
+ temp[x] = tolower(s[x]);
+ }
+ temp[x] = 0;
+ if (strstr(temp, "utf-8") || strstr(temp, "utf8")) {
+ utf8_mode = 1;
+ }
+
+ free(temp);
+ }
+ if (!setlocale(LC_CTYPE, "")) {
+ ERR("Can't set the specified locale!\nCheck LANG, LC_CTYPE, LC_ALL.");
+ }
+#endif /* X11 */
+ while (1) {
+ int c = getopt_long(argc, argv, getopt_string, longopts, NULL);
+
+ if (c == -1) {
+ break;
+ }
+
+ switch (c) {
+ case 'v':
+ case 'V':
+ print_version();
+ case 'c':
+ if (current_config) {
+ free(current_config);
+ }
+ current_config = strndup(optarg, max_user_text);
+ break;
+ case 'q':
+ freopen("/dev/null", "w", stderr);
+ break;
+ case 'h':
+ print_help(argv[0]);
+ return 0;
+#ifdef CONFIG_OUTPUT
+ case 'C':
+ print_defconfig();
+ return 0;
+#endif
+#ifdef X11
+ case 'w':
+ window.window = strtol(optarg, 0, 0);
+ break;
+#endif /* X11 */
+
+ case '?':
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ /* check if specified config file is valid */
+ if (current_config) {
+ struct stat sb;
+ if (stat(current_config, &sb) ||
+ (!S_ISREG(sb.st_mode) && !S_ISLNK(sb.st_mode))) {
+ ERR("invalid configuration file '%s'\n", current_config);
+ free(current_config);
+ current_config = 0;
+ }
+ }
+
+ /* load current_config, CONFIG_FILE or SYSTEM_CONFIG_FILE */
+
+ if (!current_config) {
+ /* load default config file */
+ char buf[DEFAULT_TEXT_BUFFER_SIZE];
+ FILE *fp;
+
+ /* Try to use personal config file first */
+ to_real_path(buf, CONFIG_FILE);
+ if (buf[0] && (fp = fopen(buf, "r"))) {
+ current_config = strndup(buf, max_user_text);
+ fclose(fp);
+ }
+
+ /* Try to use system config file if personal config not readable */
+ if (!current_config && (fp = fopen(SYSTEM_CONFIG_FILE, "r"))) {
+ current_config = strndup(SYSTEM_CONFIG_FILE, max_user_text);
+ fclose(fp);
+ }
+
+ /* No readable config found */
+ if (!current_config) {
+#ifdef CONFIG_OUTPUT
+ current_config = strdup("==builtin==");
+ ERR("no readable personal or system-wide config file found,"
+ " using builtin default");
+#else
+ CRIT_ERR(NULL, NULL, "no readable personal or system-wide config file found");
+#endif /* ! CONF_OUTPUT */
+ }
+ }
+
+#if defined(WEATHER) && defined(XOAP)
+ /* Load xoap keys, if existing */
+ load_xoap_keys();
+#endif /* WEATHER && XOAP */
+
+#ifdef HAVE_SYS_INOTIFY_H
+ inotify_fd = inotify_init();
+#endif /* HAVE_SYS_INOTIFY_H */
+
+ initialisation(argc, argv);
+