[latexila/wip/latexila-next: 2/2] LatexilaPostProcessorLatexmk (not finished)



commit 9a66089436bb54de51747601a8b6add1637e3453
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Wed Sep 17 22:15:11 2014 +0200

    LatexilaPostProcessorLatexmk (not finished)

 docs/reference/latexila-docs.xml                  |    1 +
 docs/reference/latexila-sections.txt              |   17 ++
 src/liblatexila/Makefile.am                       |    2 +
 src/liblatexila/latexila-post-processor-latexmk.c |  213 +++++++++++++++++++++
 src/liblatexila/latexila-post-processor-latexmk.h |   57 ++++++
 src/liblatexila/latexila-types.h                  |    1 +
 6 files changed, 291 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/latexila-docs.xml b/docs/reference/latexila-docs.xml
index 0a693c3..f8e08c3 100644
--- a/docs/reference/latexila-docs.xml
+++ b/docs/reference/latexila-docs.xml
@@ -20,6 +20,7 @@
     <xi:include href="xml/post-processor.xml"/>
     <xi:include href="xml/post-processor-all-output.xml"/>
     <xi:include href="xml/post-processor-latex.xml"/>
+    <xi:include href="xml/post-processor-latexmk.xml"/>
     <xi:include href="xml/synctex.xml"/>
     <xi:include href="xml/utils.xml"/>
   </chapter>
diff --git a/docs/reference/latexila-sections.txt b/docs/reference/latexila-sections.txt
index a589d6c..6f623f5 100644
--- a/docs/reference/latexila-sections.txt
+++ b/docs/reference/latexila-sections.txt
@@ -191,6 +191,23 @@ latexila_post_processor_latex_get_type
 </SECTION>
 
 <SECTION>
+<FILE>post-processor-latexmk</FILE>
+<TITLE>LatexilaPostProcessorLatexmk</TITLE>
+LatexilaPostProcessorLatexmk
+latexila_post_processor_latexmk_new
+<SUBSECTION Standard>
+LATEXILA_IS_POST_PROCESSOR_LATEXMK
+LATEXILA_IS_POST_PROCESSOR_LATEXMK_CLASS
+LATEXILA_POST_PROCESSOR_LATEXMK
+LATEXILA_POST_PROCESSOR_LATEXMK_CLASS
+LATEXILA_POST_PROCESSOR_LATEXMK_GET_CLASS
+LATEXILA_TYPE_POST_PROCESSOR_LATEXMK
+LatexilaPostProcessorLatexmkClass
+LatexilaPostProcessorLatexmkPrivate
+latexila_post_processor_latexmk_get_type
+</SECTION>
+
+<SECTION>
 <FILE>synctex</FILE>
 <TITLE>LatexilaSynctex</TITLE>
 LatexilaSynctex
diff --git a/src/liblatexila/Makefile.am b/src/liblatexila/Makefile.am
index e2e33fa..c0998e1 100644
--- a/src/liblatexila/Makefile.am
+++ b/src/liblatexila/Makefile.am
@@ -21,6 +21,7 @@ liblatexila_headers =                         \
        latexila-post-processor.h               \
        latexila-post-processor-all-output.h    \
        latexila-post-processor-latex.h         \
+       latexila-post-processor-latexmk.h       \
        latexila-synctex.h                      \
        latexila-types.h                        \
        latexila-utils.h
@@ -35,6 +36,7 @@ liblatexila_sources =                         \
        latexila-post-processor.c               \
        latexila-post-processor-all-output.c    \
        latexila-post-processor-latex.c         \
+       latexila-post-processor-latexmk.c       \
        latexila-synctex.c                      \
        latexila-utils.c
 
diff --git a/src/liblatexila/latexila-post-processor-latexmk.c 
b/src/liblatexila/latexila-post-processor-latexmk.c
new file mode 100644
index 0000000..25455bf
--- /dev/null
+++ b/src/liblatexila/latexila-post-processor-latexmk.c
@@ -0,0 +1,213 @@
+/*
+ * 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/>.
+ */
+
+/**
+ * SECTION:post-processor-latexmk
+ * @title: LatexilaPostProcessorLatexmk
+ * @short_description: latexmk post-processor
+ *
+ * A post-processor used for the latexmk command. Internally, this
+ * post-processor uses other ones: #LatexilaPostProcessorLatex and
+ * #LatexilaPostProcessorAllOutput.
+ */
+
+#include "latexila-post-processor-latexmk.h"
+#include "latexila-build-view.h"
+
+typedef enum
+{
+  STATE_FETCH_JOB_TITLE
+} State;
+
+struct _LatexilaPostProcessorLatexmkPrivate
+{
+  GQueue *messages;
+
+  /* Current message. */
+  LatexilaBuildMsg *cur_msg;
+
+  State state;
+
+  /* Number of separators encountered for the current state. */
+  gint separator_count;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (LatexilaPostProcessorLatexmk,
+                            latexila_post_processor_latexmk,
+                            LATEXILA_TYPE_POST_PROCESSOR)
+
+static void
+latexila_post_processor_latexmk_start (LatexilaPostProcessor *post_processor,
+                                       GFile                 *file)
+{
+}
+
+static void
+latexila_post_processor_latexmk_end (LatexilaPostProcessor *post_processor)
+{
+}
+
+static void
+add_message (LatexilaPostProcessorLatexmk *pp)
+{
+  g_assert (pp->priv->cur_msg != NULL);
+  g_queue_push_tail (pp->priv->messages, pp->priv->cur_msg);
+
+  pp->priv->cur_msg = latexila_build_msg_new ();
+}
+
+static gboolean
+is_separator (const gchar *line)
+{
+  return g_str_has_prefix (line, "------------");
+}
+
+static void
+fetch_job_title (LatexilaPostProcessorLatexmk *pp,
+                 gchar                        *line)
+{
+  static GRegex *regex_job_title = NULL;
+  GMatchInfo *match_info;
+  LatexilaBuildMsg *cur_msg = pp->priv->cur_msg;
+  GError *error = NULL;
+
+  if (G_UNLIKELY (regex_job_title == NULL))
+    {
+      regex_job_title = g_regex_new ("Run number \\d+ of rule '(?P<rule>.*)'",
+                                     G_REGEX_OPTIMIZE,
+                                     0,
+                                     &error);
+
+      if (error != NULL)
+        {
+          g_warning ("PostProcessorLatexmk: %s", error->message);
+          g_error_free (error);
+          return;
+        }
+    }
+
+  if (pp->priv->separator_count == 0)
+    {
+      if (is_separator (line))
+        pp->priv->separator_count++;
+
+      goto end;
+    }
+
+  if (cur_msg->text != NULL && is_separator (line))
+    {
+      add_message (pp);
+      goto end;
+    }
+
+  g_regex_match (regex_job_title, line, 0, &match_info);
+
+  if (g_match_info_matches (match_info))
+    {
+      g_free (cur_msg->text);
+      cur_msg->text = line;
+      line = NULL;
+    }
+
+  g_match_info_free (match_info);
+
+end:
+  g_free (line);
+}
+
+static void
+latexila_post_processor_latexmk_process_line (LatexilaPostProcessor *post_processor,
+                                              gchar                 *line)
+{
+  LatexilaPostProcessorLatexmk *pp = LATEXILA_POST_PROCESSOR_LATEXMK (post_processor);
+
+  switch (pp->priv->state)
+    {
+    case STATE_FETCH_JOB_TITLE:
+      fetch_job_title (pp, line);
+      break;
+
+    default:
+      g_return_if_reached ();
+    }
+}
+
+static const GQueue *
+latexila_post_processor_latexmk_get_messages (LatexilaPostProcessor *post_processor)
+{
+  LatexilaPostProcessorLatexmk *pp = LATEXILA_POST_PROCESSOR_LATEXMK (post_processor);
+
+  return pp->priv->messages;
+}
+
+static void
+latexila_post_processor_latexmk_dispose (GObject *object)
+{
+
+  G_OBJECT_CLASS (latexila_post_processor_latexmk_parent_class)->dispose (object);
+}
+
+static void
+latexila_post_processor_latexmk_finalize (GObject *object)
+{
+  LatexilaPostProcessorLatexmk *pp = LATEXILA_POST_PROCESSOR_LATEXMK (object);
+
+  g_queue_free_full (pp->priv->messages, (GDestroyNotify) latexila_build_msg_free);
+
+  if (pp->priv->cur_msg != NULL)
+    latexila_build_msg_free (pp->priv->cur_msg);
+
+  G_OBJECT_CLASS (latexila_post_processor_latexmk_parent_class)->finalize (object);
+}
+
+static void
+latexila_post_processor_latexmk_class_init (LatexilaPostProcessorLatexmkClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  LatexilaPostProcessorClass *pp_class = LATEXILA_POST_PROCESSOR_CLASS (klass);
+
+  object_class->dispose = latexila_post_processor_latexmk_dispose;
+  object_class->finalize = latexila_post_processor_latexmk_finalize;
+
+  pp_class->start = latexila_post_processor_latexmk_start;
+  pp_class->end = latexila_post_processor_latexmk_end;
+  pp_class->process_line = latexila_post_processor_latexmk_process_line;
+  pp_class->get_messages = latexila_post_processor_latexmk_get_messages;
+}
+
+static void
+latexila_post_processor_latexmk_init (LatexilaPostProcessorLatexmk *pp)
+{
+  pp->priv = latexila_post_processor_latexmk_get_instance_private (pp);
+
+  pp->priv->messages = g_queue_new ();
+  pp->priv->cur_msg = latexila_build_msg_new ();
+  pp->priv->state = STATE_FETCH_JOB_TITLE;
+}
+
+/**
+ * latexila_post_processor_latexmk_new:
+ *
+ * Returns: a new #LatexilaPostProcessorLatexmk object.
+ */
+LatexilaPostProcessor *
+latexila_post_processor_latexmk_new (void)
+{
+  return g_object_new (LATEXILA_TYPE_POST_PROCESSOR_LATEXMK, NULL);
+}
diff --git a/src/liblatexila/latexila-post-processor-latexmk.h 
b/src/liblatexila/latexila-post-processor-latexmk.h
new file mode 100644
index 0000000..f30382f
--- /dev/null
+++ b/src/liblatexila/latexila-post-processor-latexmk.h
@@ -0,0 +1,57 @@
+/*
+ * 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_LATEXMK_H__
+#define __LATEXILA_POST_PROCESSOR_LATEXMK_H__
+
+#include <glib-object.h>
+#include "latexila-post-processor.h"
+#include "latexila-types.h"
+
+G_BEGIN_DECLS
+
+#define LATEXILA_TYPE_POST_PROCESSOR_LATEXMK             (latexila_post_processor_latexmk_get_type ())
+#define LATEXILA_POST_PROCESSOR_LATEXMK(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
LATEXILA_TYPE_POST_PROCESSOR_LATEXMK, LatexilaPostProcessorLatexmk))
+#define LATEXILA_POST_PROCESSOR_LATEXMK_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), 
LATEXILA_TYPE_POST_PROCESSOR_LATEXMK, LatexilaPostProcessorLatexmkClass))
+#define LATEXILA_IS_POST_PROCESSOR_LATEXMK(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
LATEXILA_TYPE_POST_PROCESSOR_LATEXMK))
+#define LATEXILA_IS_POST_PROCESSOR_LATEXMK_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), 
LATEXILA_TYPE_POST_PROCESSOR_LATEXMK))
+#define LATEXILA_POST_PROCESSOR_LATEXMK_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), 
LATEXILA_TYPE_POST_PROCESSOR_LATEXMK, LatexilaPostProcessorLatexmkClass))
+
+typedef struct _LatexilaPostProcessorLatexmkClass   LatexilaPostProcessorLatexmkClass;
+typedef struct _LatexilaPostProcessorLatexmkPrivate LatexilaPostProcessorLatexmkPrivate;
+
+struct _LatexilaPostProcessorLatexmk
+{
+  LatexilaPostProcessor parent;
+
+  LatexilaPostProcessorLatexmkPrivate *priv;
+};
+
+struct _LatexilaPostProcessorLatexmkClass
+{
+  LatexilaPostProcessorClass parent_class;
+};
+
+GType                   latexila_post_processor_latexmk_get_type  (void) G_GNUC_CONST;
+
+LatexilaPostProcessor * latexila_post_processor_latexmk_new       (void);
+
+G_END_DECLS
+
+#endif /* __LATEXILA_POST_PROCESSOR_LATEXMK_H__ */
diff --git a/src/liblatexila/latexila-types.h b/src/liblatexila/latexila-types.h
index 997aa99..6c01249 100644
--- a/src/liblatexila/latexila-types.h
+++ b/src/liblatexila/latexila-types.h
@@ -33,6 +33,7 @@ typedef struct _LatexilaBuildView               LatexilaBuildView;
 typedef struct _LatexilaPostProcessor           LatexilaPostProcessor;
 typedef struct _LatexilaPostProcessorAllOutput  LatexilaPostProcessorAllOutput;
 typedef struct _LatexilaPostProcessorLatex      LatexilaPostProcessorLatex;
+typedef struct _LatexilaPostProcessorLatexmk    LatexilaPostProcessorLatexmk;
 typedef struct _LatexilaSynctex                 LatexilaSynctex;
 
 G_END_DECLS


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