Gentoo Logo
Gentoo Spaceship




Note: Due to technical difficulties, the Archives are currently not up to date. GMANE provides an alternative service for most mailing lists.
c.f. bug 424647
List Archive: gentoo-commits
Navigation:
Lists: gentoo-commits: < Prev By Thread Next > < Prev By Date Next >
Headers:
To: gentoo-commits@g.o
From: "Jim Ramsay (lack)" <lack@g.o>
Subject: gentoo-x86 commit in rox-base/rox/files: rox-2.7-text_plain.patch digest-rox-2.7.1-r1 digest-rox-2.7.1
Date: Thu, 24 Jan 2008 20:08:12 +0000
lack        08/01/24 20:08:12

  Added:                rox-2.7-text_plain.patch digest-rox-2.7.1-r1
  Removed:              digest-rox-2.7.1
  Log:
  Added patch to fix detection of text/plain files.
  (Portage version: 2.1.4_rc14)

Revision  Changes    Path
1.1                  rox-base/rox/files/rox-2.7-text_plain.patch

file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/rox-base/rox/files/rox-2.7-text_plain.patch?rev=1.1&view=markup
plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/rox-base/rox/files/rox-2.7-text_plain.patch?rev=1.1&content-type=text/plain

Index: rox-2.7-text_plain.patch
===================================================================
commit ed0adb6e4e873eca15b4765035d3c89888c74a72
Author: Stephen Watson <stephen@...>
Date:   Mon Jan 21 23:33:13 2008 +0000

    MIME magic lookup now returns text/plain for certain unknown file types.
    Restored the code, lost in the update to the newer XDG MIME code, which checks
    unknown files to see if they are text.
    
    Modifications to the XDG code are tagged with ROX: comments.

diff --git a/ROX-Filer/src/xdgmime.c b/ROX-Filer/src/xdgmime.c
index 133282d..51d38d6 100644
--- a/ROX-Filer/src/xdgmime.c
+++ b/ROX-Filer/src/xdgmime.c
@@ -65,6 +65,7 @@ XdgMimeCache **_xdg_mime_caches = NULL;
 static int n_caches = 0;
 
 const char xdg_mime_type_unknown[] = "application/octet-stream";
+const char xdg_mime_type_unknown_text[] = "text/plain"; /* ROX: */
 
 
 enum
diff --git a/ROX-Filer/src/xdgmime.h b/ROX-Filer/src/xdgmime.h
index 82b5585..52d1524 100644
--- a/ROX-Filer/src/xdgmime.h
+++ b/ROX-Filer/src/xdgmime.h
@@ -74,7 +74,11 @@ typedef void (*XdgMimeDestroy)  (void *user_data);
 #endif
 
 extern const char xdg_mime_type_unknown[];
-#define XDG_MIME_TYPE_UNKNOWN xdg_mime_type_unknown
+#define XDG_MIME_TYPE_UNKNOWN      xdg_mime_type_unknown
+
+/* ROX: */
+extern const char xdg_mime_type_unknown_text[];
+#define XDG_MIME_TYPE_UNKNOWN_TEXT xdg_mime_type_unknown_text
 
 const char  *xdg_mime_get_mime_type_for_data       (const void *data,
 						    size_t      len);
diff --git a/ROX-Filer/src/xdgmimemagic.c b/ROX-Filer/src/xdgmimemagic.c
index 892688b..d1d04b6 100644
--- a/ROX-Filer/src/xdgmimemagic.c
+++ b/ROX-Filer/src/xdgmimemagic.c
@@ -39,6 +39,9 @@
 #include <errno.h>
 #include <limits.h>
 
+/* ROX: */
+#include <glib.h>
+
 #ifndef	FALSE
 #define	FALSE	(0)
 #endif
@@ -654,6 +657,83 @@ _xdg_mime_magic_get_buffer_extents (XdgMimeMagic *mime_magic)
   return mime_magic->max_extent;
 }
 
+static gboolean _rox_buffer_looks_like_text (const void  *data,
+					    const size_t len)
+{
+  gchar *end;
+
+  if (g_utf8_validate (data, len, (const gchar**)&end))
+  {
+    /* g_utf8_validate allows control characters */
+    int i;
+    for (i = 0; i < len; i++)
+    {
+      unsigned char c = ((const guchar *) data)[i];
+      if (c < 32 && c != '\r' && c != '\n' && c != '\t')
+	return FALSE;
+    }
+    return TRUE;
+
+  } else {
+    /* Check whether the string was truncated in the middle of
+     * a valid UTF8 char, or if we really have an invalid
+     * UTF8 string
+     */
+    gint remaining_bytes = len;
+
+    remaining_bytes -= (end-((gchar*)data));
+
+    if (g_utf8_get_char_validated(end, remaining_bytes) == -2)
+      return TRUE;
+#if defined(HAVE_WCTYPE_H) && defined (HAVE_MBRTOWC)
+    else {
+      size_t wlen;
+      wchar_t wc;
+      gchar *src, *end;
+      mbstate_t state;
+
+      src = data;
+      end = data+len;
+                       
+      memset (&state, 0, sizeof (state));
+      while (src < end) {
+	/* Don't allow embedded zeros in textfiles */
+	if (*src == 0)
+	  return FALSE;
+                               
+	wlen = mbrtowc(&wc, src, end - src, &state);
+
+	if (wlen == (size_t)(-1)) {
+	  /* Illegal mb sequence */
+	  return FALSE;
+	}
+                               
+	if (wlen == (size_t)(-2)) {
+	  /* No complete mb char before end
+	   * Probably a cut off char which is ok */
+	  return TRUE;
+	}
+
+	if (wlen == 0) {
+	  /* Don't allow embedded zeros in textfiles */
+	  return FALSE;
+	}
+        
+	if (!iswspace (wc)  && !iswprint(wc)) {
+	  /* Not a printable or whitspace
+	   * Probably not a text file */
+	  return FALSE;
+	}
+	
+	src += wlen;
+      }
+      return TRUE;
+    }
+#endif /* defined(HAVE_WCTYPE_H) && defined (HAVE_MBRTOWC) */
+  }
+  return FALSE;
+}
+
 const char *
 _xdg_mime_magic_lookup_data (XdgMimeMagic *mime_magic,
 			     const void   *data,
@@ -708,6 +788,12 @@ _xdg_mime_magic_lookup_data (XdgMimeMagic *mime_magic,
 	}
     }
 
+  if (mime_type == NULL)
+    {
+      if(_rox_buffer_looks_like_text(data, len))
+	 mime_type = XDG_MIME_TYPE_UNKNOWN_TEXT;
+    }
+  
   return mime_type;
 }
 



1.1                  rox-base/rox/files/digest-rox-2.7.1-r1

file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/rox-base/rox/files/digest-rox-2.7.1-r1?rev=1.1&view=markup
plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/rox-base/rox/files/digest-rox-2.7.1-r1?rev=1.1&content-type=text/plain

Index: digest-rox-2.7.1-r1
===================================================================
MD5 6302280f57d1f02c07da5637a2609a4f rox-filer-2.7.1.tar.bz2 1835501
RMD160 f1face1871d641b7bea4b66a5de9a9a78ea7a25a rox-filer-2.7.1.tar.bz2 1835501
SHA256 3a565cc47f8ad2cba5972e2494e9f9380b7fc68a2ba0467aef6f2e1340695f92 rox-filer-2.7.1.tar.bz2 1835501



-- 
gentoo-commits@g.o mailing list


Navigation:
Lists: gentoo-commits: < Prev By Thread Next > < Prev By Date Next >
Previous by thread:
gentoo-x86 commit in rox-base/rox: ChangeLog rox-2.7.ebuild rox-2.7-r2.ebuild rox-2.7.1-r1.ebuild rox-2.7.1.ebuild
Next by thread:
gentoo-x86 commit in app-portage/herdstat: herdstat-1.1.2-r1.ebuild ChangeLog
Previous by date:
gentoo-x86 commit in rox-base/rox: ChangeLog rox-2.7.ebuild rox-2.7-r2.ebuild rox-2.7.1-r1.ebuild rox-2.7.1.ebuild
Next by date:
gentoo commit in xml/htdocs/doc/it: power-management-guide.xml


Updated Jan 04, 2012

Summary: Archive of the gentoo-commits mailing list.

Donate to support our development efforts.

Copyright 2001-2013 Gentoo Foundation, Inc. Questions, Comments? Contact us.