Fix help about command-line arguments that do require a parameter.
[claws.git] / src / main.c
index eff8f86090dcec4a99436dc8b525e3038eb968fe..8e2f2948ca8643ed6f4ee8ee391176edff59d557 100644 (file)
@@ -171,7 +171,9 @@ static SnDisplay *sn_display = NULL;
 
 static gint lock_socket = -1;
 static gint lock_socket_tag = 0;
+#ifdef G_OS_UNIX
 static gchar *x_display = NULL;
+#endif
 typedef enum 
 {
        ONLINE_MODE_DONT_CHANGE,
@@ -317,10 +319,14 @@ static gboolean defer_check_all(void *data)
 {
        gboolean autochk = GPOINTER_TO_INT(data);
 
-       inc_all_account_mail(static_mainwindow, autochk, 
+       if (!sc_starting) {
+               inc_all_account_mail(static_mainwindow, autochk, FALSE,
                        prefs_common.newmail_notify_manu);
 
-       if (sc_starting) {
+       } else {
+               inc_all_account_mail(static_mainwindow, FALSE,
+                               prefs_common.chk_on_startup,
+                               prefs_common.newmail_notify_manu);
                sc_starting = FALSE;
                main_window_set_menu_sensitive(static_mainwindow);
                toolbar_main_set_sensitive(static_mainwindow);
@@ -635,6 +641,16 @@ static void sc_session_manager_connect(MainWindow *mainwin)
                                NULL, &client_id,
                                256, error_string_ret);
 
+               /* From https://www.x.org/releases/X11R7.7/doc/libSM/SMlib.txt:
+                * If SmcOpenConnection succeeds, it returns an opaque connection
+                * pointer of type SmcConn and the client_id_ret argument contains
+                * the client ID to be used for this session. The client_id_ret
+                * should be freed with a call to free when no longer needed. On
+                * failure, SmcOpenConnection returns NULL, and the reason for
+                * failure is returned in error_string_ret. */
+               if (mainwin->smc_conn != NULL)
+                       g_free(client_id);
+
                if (error_string_ret[0] || mainwin->smc_conn == NULL)
                        g_warning ("While connecting to session manager: %s.",
                                error_string_ret);
@@ -731,8 +747,8 @@ static void win32_log(const gchar *log_domain, GLogLevelFlags log_level, const g
 
 static void win32_open_log(void)
 {
-       gchar *logfile = g_strconcat(g_get_tmp_dir(), G_DIR_SEPARATOR_S, "claws-win32.log", NULL);
-       gchar *oldlogfile = g_strconcat(g_get_tmp_dir(), G_DIR_SEPARATOR_S, "claws-win32.log.bak", NULL);
+       gchar *logfile = win32_debug_log_path();
+       gchar *oldlogfile = g_strconcat(logfile, ".bak", NULL);
 
        if (is_file_exist(logfile)) {
                if (rename_force(logfile, oldlogfile) < 0)
@@ -1434,7 +1450,9 @@ int main(int argc, char *argv[])
                folder_item_update_freeze();
        }
        /* make the crash-indicator file */
-       str_write_to_file("foo", get_crashfile_name(), FALSE);
+       if (str_write_to_file("foo", get_crashfile_name(), FALSE) < 0) {
+               g_warning("Can't create the crash-indicator file.");
+       }
 
        inc_autocheck_timer_init(mainwin);
 
@@ -1675,6 +1693,7 @@ static void exit_claws(MainWindow *mainwin)
                if (prefs_common.last_opened_folder != NULL)
                        g_free(prefs_common.last_opened_folder);
                prefs_common.last_opened_folder =
+                       !prefs_common.goto_last_folder_on_startup ? NULL :
                        folder_item_get_identifier(item);
        }
 
@@ -1966,7 +1985,7 @@ static void parse_cmd_opt(int argc, char *argv[])
                                          "                         use - as file name for reading from standard input;\n"
                                          "                         content format: headers first (To: required) until an\n"
                                          "                         empty line, then mail body until end of file."));
-                       g_print("%s\n", _("  --subscribe [uri]      subscribe to the given URI if possible"));
+                       g_print("%s\n", _("  --subscribe uri        subscribe to the given URI if possible"));
                        g_print("%s\n", _("  --attach file1 [file2]...\n"
                                          "                         open composition window with specified files\n"
                                          "                         attached"));
@@ -2001,7 +2020,7 @@ static void parse_cmd_opt(int argc, char *argv[])
                        g_print("%s\n", _("  --version -v           output version information and exit"));
                        g_print("%s\n", _("  --version-full -V      output version and built-in features information and exit"));
                        g_print("%s\n", _("  --config-dir           output configuration directory"));
-                       g_print("%s\n", _("  --alternate-config-dir [dir]\n"
+                       g_print("%s\n", _("  --alternate-config-dir directory\n"
                                          "                         use specified configuration directory"));
                        g_print("%s\n", _("  --geometry -geometry WxH+X+Y\n"
                                          "                         set geometry for main window"));
@@ -2056,7 +2075,7 @@ static void parse_cmd_opt(int argc, char *argv[])
                        } else if (is_dir_exist(argv[i]) || is_file_exist(argv[i])) {
                                cmd.target = argv[i];
                        } else {
-                               g_print(_("Unknown option\n"));
+                               g_print(_("Unknown option. Try -h or --help for usage.\n"));
                                exit(1);
                        }
                }
@@ -2382,11 +2401,11 @@ static gint prohibit_duplicate_launch(void)
        } else if (cmd.send) {
                fd_write_all(uxsock, "send\n", 5);
        } else if (cmd.online_mode == ONLINE_MODE_ONLINE) {
-               fd_write(uxsock, "online\n", 6);
+               fd_write(uxsock, "online\n", 7);
        } else if (cmd.online_mode == ONLINE_MODE_OFFLINE) {
-               fd_write(uxsock, "offline\n", 7);
+               fd_write(uxsock, "offline\n", 8);
        } else if (cmd.debug) {
-               fd_write(uxsock, "debug\n", 7);
+               fd_write(uxsock, "debug\n", 6);
        } else if (cmd.status || cmd.status_full) {
                gchar buf[BUFFSIZE];
                gint i;
@@ -2409,7 +2428,10 @@ static gint prohibit_duplicate_launch(void)
                        fd_gets(uxsock, buf, sizeof(buf) - 1);
                        buf[sizeof(buf) - 1] = '\0';
                        if (!strncmp(buf, ".\n", 2)) break;
-                       claws_fputs(buf, stdout);
+                       if (claws_fputs(buf, stdout) == EOF) {
+                               g_warning("writing to stdout failed.");
+                               break;
+                       }
                }
        } else if (cmd.exit) {
                fd_write_all(uxsock, "exit\n", 5);
@@ -2420,7 +2442,10 @@ static gint prohibit_duplicate_launch(void)
                        fd_gets(uxsock, buf, sizeof(buf) - 1);
                        buf[sizeof(buf) - 1] = '\0';
                        if (!strncmp(buf, ".\n", 2)) break;
-                       claws_fputs(buf, stdout);
+                       if (claws_fputs(buf, stdout) == EOF) {
+                               g_warning("writing to stdout failed.");
+                               break;
+                       }
                }
        } else if (cmd.reset_statistics) {
                fd_write(uxsock, "reset_statistics\n", 17);
@@ -2440,16 +2465,19 @@ static gint prohibit_duplicate_launch(void)
                        fd_gets(uxsock, buf, sizeof(buf) - 1);
                        buf[sizeof(buf) - 1] = '\0';
                        if (!strncmp(buf, ".\n", 2)) break;
-                       claws_fputs(buf, stdout);
+                       if (claws_fputs(buf, stdout) == EOF) {
+                               g_warning("writing to stdout failed.");
+                               break;
+                       }
                }
        } else {
-#ifndef G_OS_WIN32
+#ifdef G_OS_UNIX
                gchar buf[BUFSIZ];
                fd_write_all(uxsock, "get_display\n", 12);
                memset(buf, 0, sizeof(buf));
                fd_gets(uxsock, buf, sizeof(buf) - 1);
                buf[sizeof(buf) - 1] = '\0';
-               if (strcmp2(buf, x_display)) {
+               if (g_strcmp0(buf, x_display)) {
                        g_print("Claws Mail is already running on display %s.\n",
                                buf);
                } else {
@@ -2535,10 +2563,12 @@ static void lock_socket_input_cb(gpointer data,
 
        if (!strncmp(buf, "popup", 5)) {
                main_window_popup(mainwin);
+#ifdef G_OS_UNIX
        } else if (!strncmp(buf, "get_display", 11)) {
                fd_write_all(sock, x_display, strlen(x_display));
+#endif
        } else if (!strncmp(buf, "receive_all", 11)) {
-               inc_all_account_mail(mainwin, FALSE,
+               inc_all_account_mail(mainwin, FALSE, FALSE,
                                     prefs_common.newmail_notify_manu);
        } else if (!strncmp(buf, "receive", 7)) {
                inc_mail(mainwin, prefs_common.newmail_notify_manu);
@@ -2556,7 +2586,7 @@ static void lock_socket_input_cb(gpointer data,
                while (fd_gets(sock, buf, sizeof(buf) - 1) > 0) {
                        buf[sizeof(buf) - 1] = '\0';
                        strretchomp(buf);
-                       if (!strcmp2(buf, "."))
+                       if (!g_strcmp0(buf, "."))
                                break;
 
                        ainfo = g_new0(AttachInfo, 1);