[latexila/wip/latexila-next] LatexilaPostProcessorLatex (not finished)



commit 9ed859de4fe91179f038aacc77f4dbef7ac7b020
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sat Jul 12 13:40:12 2014 +0200

    LatexilaPostProcessorLatex (not finished)

 src/liblatexila/Makefile.am                     |    2 +
 src/liblatexila/latexila-build-job.c            |    1 +
 src/liblatexila/latexila-post-processor-latex.c |  137 +++++++++++++++++++++++
 src/liblatexila/latexila-post-processor-latex.h |   55 +++++++++
 src/liblatexila/latexila-post-processor.c       |   13 ++
 src/liblatexila/latexila-post-processor.h       |    8 ++
 src/liblatexila/latexila-types.h                |    1 +
 src/liblatexila/latexila.h                      |    1 +
 8 files changed, 218 insertions(+), 0 deletions(-)
---
diff --git a/src/liblatexila/Makefile.am b/src/liblatexila/Makefile.am
index 1beb3cc..e2e33fa 100644
--- a/src/liblatexila/Makefile.am
+++ b/src/liblatexila/Makefile.am
@@ -20,6 +20,7 @@ liblatexila_headers =                         \
        latexila-build-view.h                   \
        latexila-post-processor.h               \
        latexila-post-processor-all-output.h    \
+       latexila-post-processor-latex.h         \
        latexila-synctex.h                      \
        latexila-types.h                        \
        latexila-utils.h
@@ -33,6 +34,7 @@ liblatexila_sources =                         \
        latexila-build-view.c                   \
        latexila-post-processor.c               \
        latexila-post-processor-all-output.c    \
+       latexila-post-processor-latex.c         \
        latexila-synctex.c                      \
        latexila-utils.c
 
diff --git a/src/liblatexila/latexila-build-job.c b/src/liblatexila/latexila-build-job.c
index 5b176b3..d32d70f 100644
--- a/src/liblatexila/latexila-build-job.c
+++ b/src/liblatexila/latexila-build-job.c
@@ -481,6 +481,7 @@ launch_subprocess (LatexilaBuildJob *build_job)
       build_job->priv->post_processor = latexila_post_processor_all_output_new ();
 
       latexila_post_processor_process_async (build_job->priv->post_processor,
+                                             build_job->priv->file,
                                              g_subprocess_get_stdout_pipe (subprocess),
                                              g_task_get_cancellable (build_job->priv->task),
                                              (GAsyncReadyCallback) post_processor_cb,
diff --git a/src/liblatexila/latexila-post-processor-latex.c b/src/liblatexila/latexila-post-processor-latex.c
new file mode 100644
index 0000000..df8da70
--- /dev/null
+++ b/src/liblatexila/latexila-post-processor-latex.c
@@ -0,0 +1,137 @@
+/*
+ * This file is part of LaTeXila.
+ *
+ * Copyright (C) 2014 - Sébastien Wilmet <swilmet gnome org>
+ *
+ * LaTeXila is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * LaTeXila is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with LaTeXila.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "latexila-post-processor-latex.h"
+#include "latexila-build-view.h"
+
+#define NO_LINE (-1)
+
+/* If a message is split into several lines, we enter in a different state to
+ * fetch the end of the message.
+ */
+typedef enum
+{
+  STATE_START,
+  STATE_BADBOX,
+  STATE_WARNING,
+  STATE_ERROR,
+  STATE_ERROR_SEARCH_LINE,
+  STATE_FILENAME,
+  STATE_FILENAME_HEURISTIC
+} State;
+
+/* File opened. They are present in a stack of opened files. It is used to know
+ * on which file an error or warning occurred.
+ */
+typedef struct
+{
+  gchar *filename;
+  guint reliable : 1;
+
+  /* Non-existent files are also pushed on the stack, because the corresponding
+   * ')' will pop it. If we don't push them, wrong files are popped.
+   * When a new message is added, the last _existing_ file is taken.
+   */
+  guint exists : 1;
+} FileOpened;
+
+struct _LatexilaPostProcessorLatexPrivate
+{
+  /* The current message. */
+  LatexilaBuildMsg *msg;
+
+  State state;
+
+  /* If a message is split into several lines, the lines are concatenated in
+   * line_buffer.
+   */
+  GString *line_buffer;
+  gint nb_lines;
+
+  /* If a filename is split into several lines. */
+  GString *filename_buffer;
+
+  /* The stack containing the files that TeX is processing. The top of the stack
+   * is the beginning of the list.
+   */
+  GSList *stack_files;
+
+  /* The directory where the document is compiled. */
+  gchar *directory_path;
+
+  /* For statistics. */
+  gint nb_badboxes;
+  gint nb_warnings;
+  gint nb_errors;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (LatexilaPostProcessorLatex,
+                            latexila_post_processor_latex,
+                            LATEXILA_TYPE_POST_PROCESSOR)
+
+static void
+latexila_post_processor_latex_process_lines (LatexilaPostProcessor  *post_processor,
+                                             gchar                 **lines)
+{
+  LatexilaPostProcessorLatex *pp = LATEXILA_POST_PROCESSOR_LATEX (post_processor);
+}
+
+static const GNode *
+latexila_post_processor_latex_get_messages (LatexilaPostProcessor *post_processor)
+{
+  LatexilaPostProcessorLatex *pp = LATEXILA_POST_PROCESSOR_LATEX (post_processor);
+
+  return NULL;
+}
+
+static void
+latexila_post_processor_latex_dispose (GObject *object)
+{
+
+  G_OBJECT_CLASS (latexila_post_processor_latex_parent_class)->dispose (object);
+}
+
+static void
+latexila_post_processor_latex_finalize (GObject *object)
+{
+
+  G_OBJECT_CLASS (latexila_post_processor_latex_parent_class)->finalize (object);
+}
+
+static void
+latexila_post_processor_latex_class_init (LatexilaPostProcessorLatexClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  LatexilaPostProcessorClass *pp_class = LATEXILA_POST_PROCESSOR_CLASS (klass);
+
+  object_class->dispose = latexila_post_processor_latex_dispose;
+  object_class->finalize = latexila_post_processor_latex_finalize;
+
+  pp_class->process_lines = latexila_post_processor_latex_process_lines;
+  pp_class->get_messages = latexila_post_processor_latex_get_messages;
+}
+
+static void
+latexila_post_processor_latex_init (LatexilaPostProcessorLatex *pp)
+{
+  pp->priv = latexila_post_processor_latex_get_instance_private (pp);
+
+  pp->priv->msg = latexila_build_msg_new ();
+  pp->priv->state = STATE_START;
+}
diff --git a/src/liblatexila/latexila-post-processor-latex.h b/src/liblatexila/latexila-post-processor-latex.h
new file mode 100644
index 0000000..bcd617a
--- /dev/null
+++ b/src/liblatexila/latexila-post-processor-latex.h
@@ -0,0 +1,55 @@
+/*
+ * This file is part of LaTeXila.
+ *
+ * Copyright (C) 2014 - Sébastien Wilmet <swilmet gnome org>
+ *
+ * LaTeXila is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * LaTeXila is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with LaTeXila.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __LATEXILA_POST_PROCESSOR_LATEX_H__
+#define __LATEXILA_POST_PROCESSOR_LATEX_H__
+
+#include <glib-object.h>
+#include "latexila-post-processor.h"
+#include "latexila-types.h"
+
+G_BEGIN_DECLS
+
+#define LATEXILA_TYPE_POST_PROCESSOR_LATEX             (latexila_post_processor_latex_get_type ())
+#define LATEXILA_POST_PROCESSOR_LATEX(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
LATEXILA_TYPE_POST_PROCESSOR_LATEX, LatexilaPostProcessorLatex))
+#define LATEXILA_POST_PROCESSOR_LATEX_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), 
LATEXILA_TYPE_POST_PROCESSOR_LATEX, LatexilaPostProcessorLatexClass))
+#define LATEXILA_IS_POST_PROCESSOR_LATEX(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
LATEXILA_TYPE_POST_PROCESSOR_LATEX))
+#define LATEXILA_IS_POST_PROCESSOR_LATEX_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), 
LATEXILA_TYPE_POST_PROCESSOR_LATEX))
+#define LATEXILA_POST_PROCESSOR_LATEX_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), 
LATEXILA_TYPE_POST_PROCESSOR_LATEX, LatexilaPostProcessorLatexClass))
+
+typedef struct _LatexilaPostProcessorLatexClass   LatexilaPostProcessorLatexClass;
+typedef struct _LatexilaPostProcessorLatexPrivate LatexilaPostProcessorLatexPrivate;
+
+struct _LatexilaPostProcessorLatex
+{
+  LatexilaPostProcessor parent;
+
+  LatexilaPostProcessorLatexPrivate *priv;
+};
+
+struct _LatexilaPostProcessorLatexClass
+{
+  LatexilaPostProcessorClass parent_class;
+};
+
+GType latexila_post_processor_latex_get_type (void) G_GNUC_CONST;
+
+G_END_DECLS
+
+#endif /* __LATEXILA_POST_PROCESSOR_LATEX_H__ */
diff --git a/src/liblatexila/latexila-post-processor.c b/src/liblatexila/latexila-post-processor.c
index 07f395c..663cbec 100644
--- a/src/liblatexila/latexila-post-processor.c
+++ b/src/liblatexila/latexila-post-processor.c
@@ -238,6 +238,13 @@ latexila_post_processor_finalize (GObject *object)
 }
 
 static void
+latexila_post_processor_init_default (LatexilaPostProcessor *pp,
+                                      GFile                 *file)
+{
+  /* Do nothing. */
+}
+
+static void
 latexila_post_processor_process_lines_default (LatexilaPostProcessor  *pp,
                                                gchar                 **lines)
 {
@@ -260,6 +267,7 @@ latexila_post_processor_class_init (LatexilaPostProcessorClass *klass)
   object_class->dispose = latexila_post_processor_dispose;
   object_class->finalize = latexila_post_processor_finalize;
 
+  klass->init = latexila_post_processor_init_default;
   klass->process_lines = latexila_post_processor_process_lines_default;
   klass->get_messages = latexila_post_processor_get_messages_default;
 
@@ -412,6 +420,7 @@ read_stream (LatexilaPostProcessor *pp)
 /**
  * latexila_post_processor_process_async:
  * @pp: a post-processor.
+ * @file: the #GFile on which the build tool is run.
  * @stream: the input stream to process.
  * @cancellable: a #GCancellable.
  * @callback: the callback to call when the operation is finished.
@@ -426,12 +435,14 @@ read_stream (LatexilaPostProcessor *pp)
  */
 void
 latexila_post_processor_process_async (LatexilaPostProcessor *pp,
+                                       GFile                 *file,
                                        GInputStream          *stream,
                                        GCancellable          *cancellable,
                                        GAsyncReadyCallback    callback,
                                        gpointer               user_data)
 {
   g_return_if_fail (LATEXILA_IS_POST_PROCESSOR (pp));
+  g_return_if_fail (G_IS_FILE (file));
   g_return_if_fail (G_IS_INPUT_STREAM (stream));
   g_return_if_fail (G_IS_CANCELLABLE (cancellable));
   g_return_if_fail (pp->priv->task == NULL);
@@ -439,6 +450,8 @@ latexila_post_processor_process_async (LatexilaPostProcessor *pp,
   pp->priv->task = g_task_new (pp, cancellable, callback, user_data);
   pp->priv->stream = g_object_ref (stream);
 
+  LATEXILA_POST_PROCESSOR_GET_CLASS (pp)->init (pp, file);
+
   if (pp->priv->line_buffer != NULL)
     {
       g_string_free (pp->priv->line_buffer, TRUE);
diff --git a/src/liblatexila/latexila-post-processor.h b/src/liblatexila/latexila-post-processor.h
index 3f244f9..72b2375 100644
--- a/src/liblatexila/latexila-post-processor.h
+++ b/src/liblatexila/latexila-post-processor.h
@@ -65,6 +65,13 @@ struct _LatexilaPostProcessorClass
 {
   GObjectClass parent_class;
 
+  /* @file is the GFile on which the build tool is run. */
+  void (* init) (LatexilaPostProcessor *pp,
+                 GFile                 *file);
+
+  /* The process_lines function takes ownership of @lines. Free with
+   * g_strfreev() if you don't reuse the contents.
+   */
   void (* process_lines) (LatexilaPostProcessor  *pp,
                           gchar                 **lines);
 
@@ -81,6 +88,7 @@ const gchar *           latexila_post_processor_get_name_from_type    (LatexilaP
 void                    latexila_build_messages_free                  (GNode *build_messages);
 
 void                    latexila_post_processor_process_async         (LatexilaPostProcessor *pp,
+                                                                       GFile                 *file,
                                                                        GInputStream          *stream,
                                                                        GCancellable          *cancellable,
                                                                        GAsyncReadyCallback    callback,
diff --git a/src/liblatexila/latexila-types.h b/src/liblatexila/latexila-types.h
index 1dd9da4..997aa99 100644
--- a/src/liblatexila/latexila-types.h
+++ b/src/liblatexila/latexila-types.h
@@ -32,6 +32,7 @@ typedef struct _LatexilaBuildToolsPersonal      LatexilaBuildToolsPersonal;
 typedef struct _LatexilaBuildView               LatexilaBuildView;
 typedef struct _LatexilaPostProcessor           LatexilaPostProcessor;
 typedef struct _LatexilaPostProcessorAllOutput  LatexilaPostProcessorAllOutput;
+typedef struct _LatexilaPostProcessorLatex      LatexilaPostProcessorLatex;
 typedef struct _LatexilaSynctex                 LatexilaSynctex;
 
 G_END_DECLS
diff --git a/src/liblatexila/latexila.h b/src/liblatexila/latexila.h
index a200ab9..34607ad 100644
--- a/src/liblatexila/latexila.h
+++ b/src/liblatexila/latexila.h
@@ -31,6 +31,7 @@
 #include "latexila-build-view.h"
 #include "latexila-post-processor.h"
 #include "latexila-post-processor-all-output.h"
+#include "latexila-post-processor-latex.h"
 #include "latexila-synctex.h"
 #include "latexila-utils.h"
 


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