beagle r4604 - trunk/beagle/Filters
- From: dbera svn gnome org
- To: svn-commits-list gnome org
- Subject: beagle r4604 - trunk/beagle/Filters
- Date: Mon, 10 Mar 2008 20:00:22 +0000 (GMT)
Author: dbera
Date: Mon Mar 10 20:00:22 2008
New Revision: 4604
URL: http://svn.gnome.org/viewvc/beagle?rev=4604&view=rev
Log:
Texinfo filter was included but not used. Enable it and make it work with compressed info pages. It still needs quite a bit of work though, it is really primitive.
Modified:
trunk/beagle/Filters/AssemblyInfo.cs
trunk/beagle/Filters/FilterTexi.cs
trunk/beagle/Filters/Makefile.am
Modified: trunk/beagle/Filters/AssemblyInfo.cs
==============================================================================
--- trunk/beagle/Filters/AssemblyInfo.cs (original)
+++ trunk/beagle/Filters/AssemblyInfo.cs Mon Mar 10 20:00:22 2008
@@ -92,6 +92,7 @@
typeof(FilterSpreadsheet),
typeof(FilterSvg),
typeof(FilterTeX),
+ typeof(FilterTexi),
typeof(FilterText),
typeof(FilterTiff),
typeof(FilterTotem),
Modified: trunk/beagle/Filters/FilterTexi.cs
==============================================================================
--- trunk/beagle/Filters/FilterTexi.cs (original)
+++ trunk/beagle/Filters/FilterTexi.cs Mon Mar 10 20:00:22 2008
@@ -31,6 +31,13 @@
using System.Text;
using System.Text.RegularExpressions;
+using Beagle.Util;
+using Beagle.Daemon;
+
+using ICSharpCode.SharpZipLib.GZip;
+using ICSharpCode.SharpZipLib.BZip2;
+using Decoder = SevenZip.Compression.LZMA.Decoder;
+
namespace Beagle.Filters {
public class FilterTexi : Beagle.Daemon.Filter {
@@ -44,13 +51,17 @@
public FilterTexi ()
{
// FIXME: Should this be documentation ?
- SetFileType ("document");
+ SetFileType ("documentation");
}
protected override void RegisterSupportedTypes ()
{
// Make this a general texi filter.
- AddSupportedMimeType ("text/x-texinfo");
+ AddSupportedFlavor (FilterFlavor.NewFromMimeType ("text/x-texinfo"));
+
+ // common paths
+ AddSupportedFlavor (new FilterFlavor ("file:///usr/share/info/*", ".lzma", null, 1));
+ AddSupportedFlavor (new FilterFlavor ("file:///usr/share/info/*", ".gz", null, 1));
}
/*
@@ -61,12 +72,90 @@
{
string line;
- line = TextReader.ReadLine ();
+ line = reader.ReadLine ();
+ if (line == null) {
+ Finished ();
+ return;
+ }
+
foreach (string keyword in texiKeywords)
line = line.Replace (keyword, String.Empty);
AppendLine (line);
- AppendWhiteSpace ();
+ }
+
+ private TextReader reader;
+
+ protected override void DoPullSetup ()
+ {
+ if (Extension == ".gz" || Extension == ".bz2" || Extension == ".lzma")
+ GetCompressedInfoReader ();
+ else
+ reader = base.TextReader;
+ }
+
+ private void GetCompressedInfoReader ()
+ {
+ StreamReader compressed_reader = null;
+
+ try {
+ Stream stream = null;
+ if (Extension == ".gz")
+ stream = new GZipInputStream (Stream);
+ else if (Extension == ".bz2")
+ stream = new BZip2InputStream (Stream);
+ else if (Extension == ".lzma")
+ stream = GetLzmaStream (Stream);
+
+ compressed_reader = new StreamReader (stream);
+ } catch (Exception e) {
+ Log.Error (e, "Error in opening compressed man page");
+ if (compressed_reader != null)
+ compressed_reader.Close ();
+ Error ();
+ return;
+ }
+
+ reader = compressed_reader;
+ }
+
+ protected override void DoClose ()
+ {
+ if (Extension == ".gz" || Extension == ".bz2" || Extension == ".lzma")
+ if (reader != null)
+ reader.Close ();
+ }
+
+ private Stream GetLzmaStream (Stream in_stream)
+ {
+ // From LzmaAlone.cs
+ byte[] properties = new byte [5];
+ if (in_stream.Read (properties, 0, 5) != 5)
+ throw new Exception ("input .lzma is too short");
+
+ Decoder decoder = new Decoder ();
+ decoder.SetDecoderProperties (properties);
+
+ long out_size = 0;
+ for (int i = 0; i < 8; i++)
+ {
+ int v = in_stream.ReadByte ();
+ if (v < 0)
+ throw new Exception ("LZMA: Can't Read 1");
+ out_size |= ((long)(byte)v) << (8 * i);
+ }
+ long compressed_size = in_stream.Length - in_stream.Position;
+
+ // FIXME: Man pages are small enough to use a MemoryStream to store the
+ // entire uncompressed file.
+ // Still, a proper stream based approach would be good. Unfortunately,
+ // LZMA does not provide a streaming interface. Current hacks involve
+ // a separate synchronized thread.
+ MemoryStream out_stream = new MemoryStream ((int) out_size); // outsize is long but this constructor is resizable
+ decoder.Code (in_stream, out_stream, compressed_size, out_size, null);
+ //Log.Debug ("Decoded {0} bytes to {1} bytes", compressed_size, out_size);
+ out_stream.Position = 0;
+ return out_stream;
}
}
}
Modified: trunk/beagle/Filters/Makefile.am
==============================================================================
--- trunk/beagle/Filters/Makefile.am (original)
+++ trunk/beagle/Filters/Makefile.am Mon Mar 10 20:00:22 2008
@@ -107,6 +107,7 @@
$(srcdir)/FilterSpreadsheet.cs \
$(srcdir)/FilterSvg.cs \
$(srcdir)/FilterTeX.cs \
+ $(srcdir)/FilterTexi.cs \
$(srcdir)/FilterText.cs \
$(srcdir)/FilterTiff.cs \
$(srcdir)/FilterTotem.cs \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]