[latexila/wip/build-tools-revamp] PostProcessor and PostProcessorAllOutput (not finished)



commit 38933cf8b922e14772e38d3477f9433135e138ed
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Fri May 23 12:25:30 2014 +0200

    PostProcessor and PostProcessorAllOutput (not finished)
    
    The post processors work on a GInputStream obtained by the GSubprocess.
    The GInputStream is read asynchronously.
    
    Before, the Vala code worked on the full command output, as one big
    string. This big string was split into lines, and then processed.
    
    One exception: the latexmk post-processor worked on the full output with
    a big regex, without splitting the output into lines (splitting the
    lines was delegated to the all-output and latex post-processors, called
    by the latexmk post-processor after extracting the relevant contents
    from the big string).
    
    Next steps:
    - write the latex post-processor (the Vala code works already line by
    line, so working on the stream will use the same algorithm). One
    difference though: the latex post-processor should read the log file,
    not the command output.
    
    - write the latexmk post-processor. Working on the stream (line by line)
    will be more complicated, the big regex cannot be reused (unless the
    command output is constructed to obtain one big string, but I don't want
    this solution, it uses more memory and is thus most probably slower).
    
    - write unit tests!

 src/liblatexila/latexila-build-job.c               |   18 +++++++++--
 .../latexila-post-processor-all-output.c           |   32 +++++---------------
 src/liblatexila/latexila-post-processor.c          |   14 ++++-----
 src/liblatexila/latexila-post-processor.h          |   15 ++++-----
 4 files changed, 36 insertions(+), 43 deletions(-)
---
diff --git a/src/liblatexila/latexila-build-job.c b/src/liblatexila/latexila-build-job.c
index bd35801..651e5b1 100644
--- a/src/liblatexila/latexila-build-job.c
+++ b/src/liblatexila/latexila-build-job.c
@@ -461,9 +461,16 @@ launch_subprocess (LatexilaBuildJob *build_job)
   gchar **argv;
   GError *error = NULL;
 
-  /* No output for the moment */
-  launcher = g_subprocess_launcher_new (G_SUBPROCESS_FLAGS_STDOUT_SILENCE |
-                                        G_SUBPROCESS_FLAGS_STDERR_SILENCE);
+  if (build_job->priv->post_processor_type == LATEXILA_POST_PROCESSOR_TYPE_NO_OUTPUT)
+    {
+      launcher = g_subprocess_launcher_new (G_SUBPROCESS_FLAGS_STDOUT_SILENCE |
+                                            G_SUBPROCESS_FLAGS_STDERR_SILENCE);
+    }
+  else
+    {
+      launcher = g_subprocess_launcher_new (G_SUBPROCESS_FLAGS_STDOUT_PIPE |
+                                            G_SUBPROCESS_FLAGS_STDERR_MERGE);
+    }
 
   parent_dir = g_file_get_parent (build_job->priv->file);
   working_directory = g_file_get_path (parent_dir);
@@ -485,6 +492,11 @@ launch_subprocess (LatexilaBuildJob *build_job)
       return;
     }
 
+  if (build_job->priv->post_processor_type != LATEXILA_POST_PROCESSOR_TYPE_NO_OUTPUT)
+    {
+      g_subprocess_get_stdout_pipe (subprocess);
+    }
+
   g_subprocess_wait_async (subprocess,
                            g_task_get_cancellable (build_job->priv->task),
                            (GAsyncReadyCallback) subprocess_wait_cb,
diff --git a/src/liblatexila/latexila-post-processor-all-output.c 
b/src/liblatexila/latexila-post-processor-all-output.c
index f4bf671..8f09358 100644
--- a/src/liblatexila/latexila-post-processor-all-output.c
+++ b/src/liblatexila/latexila-post-processor-all-output.c
@@ -21,25 +21,18 @@
 
 struct _LatexilaPostProcessorAllOutputPrivate
 {
-  GSList *messages;
+  gint something;
 };
 
 G_DEFINE_TYPE_WITH_PRIVATE (LatexilaPostProcessorAllOutput, latexila_post_processor_all_output, 
LATEXILA_TYPE_POST_PROCESSOR)
 
 static void
 latexila_post_processor_all_output_process (LatexilaPostProcessor *post_processor,
-                                            const gchar           *output)
+                                            GInputStream          *stream)
 {
+  /*
   LatexilaPostProcessorAllOutput *pp = LATEXILA_POST_PROCESSOR_ALL_OUTPUT (post_processor);
-  gchar **lines;
-  gchar **l;
-
-  lines = g_strsplit (output, "\n", 0);
-
-  for (l = lines; l != NULL && *l != NULL; l++)
-    {
-      pp->priv->messages = g_slist_prepend (pp->priv->messages, *l);
-    }
+  */
 
   /* Generally a single \n is present at the end of the output, so an empty line
    * is added to the list. But we don't want to display it.
@@ -61,30 +54,21 @@ latexila_post_processor_all_output_process (LatexilaPostProcessor *post_processo
         }
     }
 #endif
-
-  pp->priv->messages = g_slist_reverse (pp->priv->messages);
-
-  /* Do not use g_strfreev() because the strings are reused in the list. */
-  g_free (lines);
 }
 
-static GSList *
+static const GNode *
 latexila_post_processor_all_output_get_messages (LatexilaPostProcessor *post_processor)
 {
+  /*
   LatexilaPostProcessorAllOutput *pp = LATEXILA_POST_PROCESSOR_ALL_OUTPUT (post_processor);
+  */
 
-  return pp->priv->messages;
+  return NULL;
 }
 
 static void
 latexila_post_processor_all_output_finalize (GObject *object)
 {
-  LatexilaPostProcessorAllOutputPrivate *priv;
-
-  priv = latexila_post_processor_all_output_get_instance_private (LATEXILA_POST_PROCESSOR_ALL_OUTPUT 
(object));
-
-  g_slist_free_full (priv->messages, g_free);
-  priv->messages = NULL;
 
   G_OBJECT_CLASS (latexila_post_processor_all_output_parent_class)->finalize (object);
 }
diff --git a/src/liblatexila/latexila-post-processor.c b/src/liblatexila/latexila-post-processor.c
index 19e2b40..7ab81dd 100644
--- a/src/liblatexila/latexila-post-processor.c
+++ b/src/liblatexila/latexila-post-processor.c
@@ -152,16 +152,13 @@ latexila_post_processor_set_property (GObject      *object,
 
 static void
 latexila_post_processor_process_default (LatexilaPostProcessor *pp,
-                                         const gchar           *output)
+                                         GInputStream          *stream)
 {
-  g_return_if_fail (LATEXILA_IS_POST_PROCESSOR (pp));
 }
 
-static GSList *
+static const GNode *
 latexila_post_processor_get_messages_default (LatexilaPostProcessor *pp)
 {
-  g_return_val_if_fail (LATEXILA_IS_POST_PROCESSOR (pp), NULL);
-
   return NULL;
 }
 
@@ -211,14 +208,15 @@ latexila_post_processor_new (void)
 
 void
 latexila_post_processor_process (LatexilaPostProcessor *pp,
-                                 const gchar           *output)
+                                 GInputStream          *stream)
 {
   g_return_if_fail (LATEXILA_IS_POST_PROCESSOR (pp));
+  g_return_if_fail (G_IS_INPUT_STREAM (stream));
 
-  LATEXILA_POST_PROCESSOR_GET_CLASS (pp)->process (pp, output);
+  LATEXILA_POST_PROCESSOR_GET_CLASS (pp)->process (pp, stream);
 }
 
-GSList *
+const GNode *
 latexila_post_processor_get_messages (LatexilaPostProcessor *pp)
 {
   g_return_val_if_fail (LATEXILA_IS_POST_PROCESSOR (pp), NULL);
diff --git a/src/liblatexila/latexila-post-processor.h b/src/liblatexila/latexila-post-processor.h
index 51e5bab..0c1b9ff 100644
--- a/src/liblatexila/latexila-post-processor.h
+++ b/src/liblatexila/latexila-post-processor.h
@@ -20,8 +20,7 @@
 #ifndef __LATEXILA_POST_PROCESSOR_H__
 #define __LATEXILA_POST_PROCESSOR_H__
 
-#include <glib.h>
-#include <glib-object.h>
+#include <gio/gio.h>
 #include "latexila-types.h"
 
 G_BEGIN_DECLS
@@ -66,10 +65,10 @@ struct _LatexilaPostProcessorClass
 {
   GObjectClass parent_class;
 
-  void (* process) (LatexilaPostProcessor *post_processor,
-                    const gchar           *output);
+  void (* process) (LatexilaPostProcessor *pp,
+                    GInputStream          *stream);
 
-  GSList * (* get_messages) (LatexilaPostProcessor *post_processor);
+  const GNode * (* get_messages) (LatexilaPostProcessor *pp);
 };
 
 GType                   latexila_post_processor_get_type              (void) G_GNUC_CONST;
@@ -81,10 +80,10 @@ const gchar *           latexila_post_processor_get_name_from_type    (LatexilaP
 
 LatexilaPostProcessor * latexila_post_processor_new                   (void);
 
-void                    latexila_post_processor_process               (LatexilaPostProcessor *post_processor,
-                                                                       const gchar           *output);
+void                    latexila_post_processor_process               (LatexilaPostProcessor *pp,
+                                                                       GInputStream          *stream);
 
-GSList *                latexila_post_processor_get_messages          (LatexilaPostProcessor 
*post_processor);
+const GNode *           latexila_post_processor_get_messages          (LatexilaPostProcessor *pp);
 
 G_END_DECLS
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]