beagle r4606 - trunk/beagle/Filters
- From: dbera svn gnome org
- To: svn-commits-list gnome org
- Subject: beagle r4606 - trunk/beagle/Filters
- Date: Wed, 12 Mar 2008 23:25:08 +0000 (GMT)
Author: dbera
Date: Wed Mar 12 23:25:08 2008
New Revision: 4606
URL: http://svn.gnome.org/viewvc/beagle?rev=4606&view=rev
Log:
Revert the earlier changes to FilterTexi. I stupidly thought that TeXinfo is the format for the 'info' files. They are not.
Add a simple 'info' filter. As usual, can also extract from compressed info files.
Added:
trunk/beagle/Filters/FilterInfo.cs (contents, props changed)
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 Wed Mar 12 23:25:08 2008
@@ -28,7 +28,7 @@
using Beagle.Filters;
-// All filter types have to be listed here to be loaded.
+// All (non-abstract) filter types have to be listed here to be loaded.
[assembly: Beagle.Daemon.FilterTypes (
typeof(FilterAbiWord),
typeof(FilterApplication),
@@ -55,6 +55,7 @@
typeof(FilterGif),
typeof(FilterHtml),
typeof(FilterIgnore),
+ typeof(FilterInfo),
typeof(FilterJava),
typeof(FilterJavascript),
typeof(FilterJpeg),
Added: trunk/beagle/Filters/FilterInfo.cs
==============================================================================
--- (empty file)
+++ trunk/beagle/Filters/FilterInfo.cs Wed Mar 12 23:25:08 2008
@@ -0,0 +1,209 @@
+//
+// FilterInfo.cs
+//
+// Copyright (C) 2008 D Bera<dbera web gmail com>
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the "Software"),
+// to deal in the Software without restriction, including without limitation
+// the rights to use, copy, modify, merge, publish, distribute, sublicense,
+// and/or sell copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.IO;
+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 FilterInfo : Beagle.Daemon.Filter {
+
+ public FilterInfo ()
+ {
+ SetFileType ("documentation");
+ }
+
+ protected override void RegisterSupportedTypes ()
+ {
+ // common paths
+ AddSupportedFlavor (new FilterFlavor ("file:///usr/share/info/*", ".lzma", null, 1));
+ AddSupportedFlavor (new FilterFlavor ("file:///usr/share/info/*", ".gz", null, 1));
+ AddSupportedFlavor (new FilterFlavor ("file:///usr/share/info/*", ".bz2", null, 1));
+ AddSupportedFlavor (new FilterFlavor ("file:///usr/share/info/*", ".info", null, 1));
+ }
+
+ const char c = ''; // Info node separator
+ private bool skipping = false; // use this to skip certain nodes
+ static readonly char[] node_line_sep = new char[] {'*', ':', '.', ','};
+
+ private TextReader reader;
+
+ protected override void DoOpen (FileInfo info)
+ {
+ if (Extension == ".gz" || Extension == ".bz2" || Extension == ".lzma")
+ GetCompressedInfoReader ();
+ else
+ reader = base.TextReader;
+ }
+
+ override protected void DoPullProperties ()
+ {
+ // start reading lines till the first node is hit
+ string line;
+ while ((line = reader.ReadLine ()) != null) {
+ if (line.Length == 0)
+ continue;
+
+ if (line [0] == c) {
+ // no title node
+ skipping = ReportNewNode ();
+ return;
+ }
+
+ if (line [0] != '*')
+ continue;
+
+ string[] words = line.Split (node_line_sep, StringSplitOptions.RemoveEmptyEntries);
+ AddProperty (Beagle.Property.New ("dc:title", words [0].Trim ()));
+ skipping = true;
+ return;
+ }
+
+ if (line == null) {
+ Finished ();
+ return;
+ }
+ }
+
+ override protected void DoPull ()
+ {
+ string line;
+
+ line = reader.ReadLine ();
+ if (line == null) {
+ Finished ();
+ return;
+ }
+
+ if (line.Length == 0)
+ return;
+
+ if (skipping && line [0] != c)
+ return;
+
+ if (line [0] != c) {
+ if (! skipping && ! line.StartsWith ("*"))
+ AppendLine (line);
+ return;
+ }
+
+ skipping = ReportNewNode ();
+ }
+
+ // Returns true if the node should be skipped
+ private bool ReportNewNode ()
+ {
+ // Starting a new node
+ // Read the next line
+ string line = reader.ReadLine ();
+ if (line == null) {
+ Finished ();
+ return true;
+ }
+
+ if (line.StartsWith ("Indirect:") ||
+ line.StartsWith ("Tag Table:") ||
+ line.Contains ("Node: Index") ||
+ line.Contains ("Node: Top")) {
+ return true;
+ }
+
+ return false;
+ }
+
+ 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/FilterTexi.cs
==============================================================================
--- trunk/beagle/Filters/FilterTexi.cs (original)
+++ trunk/beagle/Filters/FilterTexi.cs Wed Mar 12 23:25:08 2008
@@ -31,13 +31,8 @@
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 {
@@ -58,10 +53,6 @@
{
// Make this a general texi filter.
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));
}
/*
@@ -72,90 +63,11 @@
{
string line;
- line = reader.ReadLine ();
- if (line == null) {
- Finished ();
- return;
- }
-
+ line = TextReader.ReadLine ();
foreach (string keyword in texiKeywords)
line = line.Replace (keyword, String.Empty);
AppendLine (line);
}
-
- 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 Wed Mar 12 23:25:08 2008
@@ -70,6 +70,7 @@
$(srcdir)/FilterHtml.cs \
$(srcdir)/FilterIgnore.cs \
$(srcdir)/FilterImage.cs \
+ $(srcdir)/FilterInfo.cs \
$(srcdir)/FilterJava.cs \
$(srcdir)/FilterJpeg.cs \
$(srcdir)/FilterJs.cs \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]