]> www.fi.muni.cz Git - evince.git/blobdiff - backend/comics/comics-document.c
[windows] Use \r\n as delimiter to split lines on Windows
[evince.git] / backend / comics / comics-document.c
index c2c625a19942ea9443a8a958f160ec4c048c284e..b66f4ce7187d4a663610e4882ada6ca7c915c962 100644 (file)
@@ -22,7 +22,6 @@
 
 #include <unistd.h>
 #include <string.h>
-#include <sys/wait.h>
 #include <stdlib.h>
 #include <errno.h>
 
 #include <glib/gstdio.h>
 #include <gio/gio.h>
 
+#ifdef G_OS_WIN32
+# define WIFEXITED(x) ((x) != 3)
+# define WEXITSTATUS(x) (x)
+#else
+# include <sys/wait.h>
+#endif
+
 #include "comics-document.h"
 #include "ev-document-misc.h"
 #include "ev-document-thumbnails.h"
 #include "ev-file-helpers.h"
 
+#ifdef G_OS_WIN32
+/* On windows g_spawn_command_line_sync reads stdout in O_BINARY mode, not in O_TEXT mode.
+ * As a consequence, newlines are in a platform dependent representation (\r\n). This
+ * might be considered a bug in glib.
+ */
+#define EV_EOL "\r\n"
+#else
+#define EV_EOL "\n"
+#endif
+
 typedef enum
 {
        RARLABS,
@@ -180,18 +196,19 @@ comics_generate_command_lines (ComicsDocument *comics_document,
                               GError         **error)
 {
        gchar *quoted_file;
+       gchar *quoted_command;
        ComicBookDecompressType type;
        
        type = comics_document->command_usage;
        quoted_file = g_shell_quote (comics_document->archive);
-       
-       comics_document->extract_command = 
-                           g_strdup_printf (command_usage_def[type].extract, 
-                                            comics_document->selected_command);
+       quoted_command = g_shell_quote (comics_document->selected_command);
+
+       comics_document->extract_command =
+                           g_strdup_printf (command_usage_def[type].extract,
+                                            quoted_command);
        comics_document->list_command =
-                           g_strdup_printf (command_usage_def[type].list, 
-                                            comics_document->selected_command, 
-                                            quoted_file);
+                           g_strdup_printf (command_usage_def[type].list,
+                                            quoted_command, quoted_file);
        comics_document->offset = command_usage_def[type].offset;
        if (command_usage_def[type].decompress_tmp) {
                comics_document->dir = ev_mkdtemp ("evince-comics-XXXXXX", error);
@@ -202,10 +219,10 @@ comics_generate_command_lines (ComicsDocument *comics_document,
 
                comics_document->decompress_tmp =
                        g_strdup_printf (command_usage_def[type].decompress_tmp, 
-                                        comics_document->selected_command, 
-                                        quoted_file, 
+                                        quoted_command, quoted_file,
                                         comics_document->dir);
                g_free (quoted_file);
+               g_free (quoted_command);
 
                if (!comics_decompress_temp_dir (comics_document->decompress_tmp,
                    comics_document->selected_command, error))
@@ -214,6 +231,7 @@ comics_generate_command_lines (ComicsDocument *comics_document,
                        return TRUE;
        } else {
                g_free (quoted_file);
+               g_free (quoted_command);
                return TRUE;
        }
 
@@ -406,7 +424,8 @@ comics_document_load (EvDocument *document,
        }
 
        /* FIXME: is this safe against filenames containing \n in the archive ? */
-       cb_files = g_strsplit (std_out, "\n", 0);
+       cb_files = g_strsplit (std_out, EV_EOL, 0);
+
        g_free (std_out);
 
        if (!cb_files) {
@@ -496,7 +515,7 @@ comics_document_get_page_size (EvDocument *document,
        guchar buf[1024];
        gboolean success, got_size = FALSE;
        gint outpipe = -1;
-       GPid child_pid = -1;
+       GPid child_pid;
        gssize bytes;
        GdkPixbuf *pixbuf;
        gchar *filename;
@@ -571,7 +590,7 @@ comics_document_render_pixbuf (EvDocument      *document,
        guchar buf[4096];
        gboolean success;
        gint outpipe = -1;
-       GPid child_pid = -1;
+       GPid child_pid;
        gssize bytes;
        gint width, height;
        gchar *filename;