[latexila] PostProcessor: process one line at a time



commit 12bd328d9947dec6ec41dff129111092a0ac4c9e
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Mon Sep 29 15:31:22 2014 +0200

    PostProcessor: process one line at a time

 .../latexila-post-processor-all-output.c           |   17 +++++------
 src/liblatexila/latexila-post-processor-latex.c    |   29 ++++++-------------
 src/liblatexila/latexila-post-processor.c          |   27 +++++++++---------
 src/liblatexila/latexila-post-processor.h          |    8 +++---
 4 files changed, 35 insertions(+), 46 deletions(-)
---
diff --git a/src/liblatexila/latexila-post-processor-all-output.c 
b/src/liblatexila/latexila-post-processor-all-output.c
index ce208b6..1a1d7cb 100644
--- a/src/liblatexila/latexila-post-processor-all-output.c
+++ b/src/liblatexila/latexila-post-processor-all-output.c
@@ -38,22 +38,21 @@ G_DEFINE_TYPE_WITH_PRIVATE (LatexilaPostProcessorAllOutput,
                             LATEXILA_TYPE_POST_PROCESSOR)
 
 static void
-latexila_post_processor_all_output_process_lines (LatexilaPostProcessor  *post_processor,
-                                                  gchar                 **lines)
+latexila_post_processor_all_output_process_line (LatexilaPostProcessor *post_processor,
+                                                 gchar                 *line)
 {
   LatexilaPostProcessorAllOutput *pp = LATEXILA_POST_PROCESSOR_ALL_OUTPUT (post_processor);
-  gint i;
 
-  for (i = 0; lines != NULL && lines[i] != NULL; i++)
+  if (line != NULL)
     {
-      LatexilaBuildMsg *msg = latexila_build_msg_new ();
-      msg->text = lines[i];
+      LatexilaBuildMsg *msg;
+
+      msg = latexila_build_msg_new ();
+      msg->text = line;
       msg->type = LATEXILA_BUILD_MSG_TYPE_INFO;
 
       g_queue_push_tail (pp->priv->messages, msg);
     }
-
-  g_free (lines);
 }
 
 static const GQueue *
@@ -82,7 +81,7 @@ latexila_post_processor_all_output_class_init (LatexilaPostProcessorAllOutputCla
 
   object_class->finalize = latexila_post_processor_all_output_finalize;
 
-  post_processor_class->process_lines = latexila_post_processor_all_output_process_lines;
+  post_processor_class->process_line = latexila_post_processor_all_output_process_line;
   post_processor_class->get_messages = latexila_post_processor_all_output_get_messages;
 }
 
diff --git a/src/liblatexila/latexila-post-processor-latex.c b/src/liblatexila/latexila-post-processor-latex.c
index 7d8194c..049c798 100644
--- a/src/liblatexila/latexila-post-processor-latex.c
+++ b/src/liblatexila/latexila-post-processor-latex.c
@@ -1313,10 +1313,13 @@ update_stack_file (LatexilaPostProcessorLatex *pp,
 }
 
 static void
-process_line (LatexilaPostProcessorLatex *pp,
-              const gchar                *line)
+latexila_post_processor_latex_process_line (LatexilaPostProcessor *post_processor,
+                                            gchar                 *line)
 {
-  g_assert (line != NULL);
+  LatexilaPostProcessorLatex *pp = LATEXILA_POST_PROCESSOR_LATEX (post_processor);
+
+  if (line == NULL)
+    return;
 
   if (pp->priv->state != STATE_START)
     append_to_line_buffer (pp, line);
@@ -1325,7 +1328,7 @@ process_line (LatexilaPostProcessorLatex *pp,
     {
     case STATE_START:
       if (line[0] == '\0')
-        return;
+        break;
 
       if (!(detect_badbox (pp, line) ||
             detect_warning (pp, line) ||
@@ -1355,22 +1358,8 @@ process_line (LatexilaPostProcessorLatex *pp,
     default:
       g_return_if_reached ();
     }
-}
-
-static void
-latexila_post_processor_latex_process_lines (LatexilaPostProcessor  *post_processor,
-                                             gchar                 **lines)
-{
-  LatexilaPostProcessorLatex *pp = LATEXILA_POST_PROCESSOR_LATEX (post_processor);
-  gint i;
-
-  for (i = 0; lines != NULL && lines[i] != NULL; i++)
-    {
-      process_line (pp, lines[i]);
-      g_free (lines[i]);
-    }
 
-  g_free (lines);
+  g_free (line);
 }
 
 static const GQueue *
@@ -1414,7 +1403,7 @@ latexila_post_processor_latex_class_init (LatexilaPostProcessorLatexClass *klass
 
   pp_class->start = latexila_post_processor_latex_start;
   pp_class->end = latexila_post_processor_latex_end;
-  pp_class->process_lines = latexila_post_processor_latex_process_lines;
+  pp_class->process_line = latexila_post_processor_latex_process_line;
   pp_class->get_messages = latexila_post_processor_latex_get_messages;
 }
 
diff --git a/src/liblatexila/latexila-post-processor.c b/src/liblatexila/latexila-post-processor.c
index a270a02..f72cc9e 100644
--- a/src/liblatexila/latexila-post-processor.c
+++ b/src/liblatexila/latexila-post-processor.c
@@ -215,10 +215,10 @@ latexila_post_processor_start_default (LatexilaPostProcessor *pp,
 }
 
 static void
-latexila_post_processor_process_lines_default (LatexilaPostProcessor  *pp,
-                                               gchar                 **lines)
+latexila_post_processor_process_line_default (LatexilaPostProcessor *pp,
+                                              gchar                 *line)
 {
-  g_strfreev (lines);
+  g_free (line);
 }
 
 static void
@@ -244,7 +244,7 @@ latexila_post_processor_class_init (LatexilaPostProcessorClass *klass)
   object_class->finalize = latexila_post_processor_finalize;
 
   klass->start = latexila_post_processor_start_default;
-  klass->process_lines = latexila_post_processor_process_lines_default;
+  klass->process_line = latexila_post_processor_process_line_default;
   klass->end = latexila_post_processor_end_default;
   klass->get_messages = latexila_post_processor_get_messages_default;
 
@@ -318,13 +318,12 @@ read_stream_cb (GInputStream          *stream,
           pp->priv->line_buffer->str != NULL &&
           pp->priv->line_buffer->str[0] != '\0')
         {
-          lines = g_new (gchar *, 2);
-          lines[0] = g_string_free (pp->priv->line_buffer, FALSE);
-          lines[1] = NULL;
+          gchar *line;
 
+          line = g_string_free (pp->priv->line_buffer, FALSE);
           pp->priv->line_buffer = NULL;
 
-          LATEXILA_POST_PROCESSOR_GET_CLASS (pp)->process_lines (pp, lines);
+          LATEXILA_POST_PROCESSOR_GET_CLASS (pp)->process_line (pp, line);
         }
 
       /* finished! */
@@ -344,13 +343,14 @@ read_stream_cb (GInputStream          *stream,
       g_string_append (pp->priv->line_buffer, lines[0]);
     }
 
-  /* If a second line exists, we can call process_lines().
+  /* If a second line exists, we can call process_line().
    * The first line must be replaced by the contents of line_buffer.
    * And the last line must go to line_buffer.
    */
   if (lines[1] != NULL)
     {
       gint last_line;
+      gint i;
 
       if (pp->priv->line_buffer != NULL)
         {
@@ -365,15 +365,16 @@ read_stream_cb (GInputStream          *stream,
       g_free (lines[last_line]);
       lines[last_line] = NULL;
 
-      LATEXILA_POST_PROCESSOR_GET_CLASS (pp)->process_lines (pp, lines);
+      for (i = 0; lines[i] != NULL; i++)
+        LATEXILA_POST_PROCESSOR_GET_CLASS (pp)->process_line (pp, lines[i]);
+
+      g_free (lines);
     }
   else
     {
       /* If not already done above, put the first line to line_buffer. */
       if (pp->priv->line_buffer == NULL)
-        {
-          pp->priv->line_buffer = g_string_new (lines[0]);
-        }
+        pp->priv->line_buffer = g_string_new (lines[0]);
 
       g_strfreev (lines);
     }
diff --git a/src/liblatexila/latexila-post-processor.h b/src/liblatexila/latexila-post-processor.h
index 0df0650..e0200fb 100644
--- a/src/liblatexila/latexila-post-processor.h
+++ b/src/liblatexila/latexila-post-processor.h
@@ -71,11 +71,11 @@ struct _LatexilaPostProcessorClass
   void (* start) (LatexilaPostProcessor *pp,
                   GFile                 *file);
 
-  /* The process_lines function takes ownership of @lines. Free with
-   * g_strfreev() if you don't reuse the contents.
+  /* The process_line function takes ownership of @line. Free with
+   * g_free() if you don't reuse the content.
    */
-  void (* process_lines) (LatexilaPostProcessor  *pp,
-                          gchar                 **lines);
+  void (* process_line) (LatexilaPostProcessor *pp,
+                         gchar                 *line);
 
   /* End of processing. */
   void (* end) (LatexilaPostProcessor *pp);


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