[gegl] tools/gobj2dot.rb: catch encoding errors



commit 182f4dbad859e21453ec32091cc4b5bcd377fc84
Author: �yvind Kolås <pippin gimp org>
Date:   Thu Jan 13 01:58:50 2011 +0000

    tools/gobj2dot.rb: catch encoding errors
    
    Handle errors due to invalid utf8 gracefully. Fixes a build error originally
    spotted by Joel Parker Henderson.

 tools/gobj2dot.rb |   20 ++++++++++++--------
 1 files changed, 12 insertions(+), 8 deletions(-)
---
diff --git a/tools/gobj2dot.rb b/tools/gobj2dot.rb
index d7792a7..b99e3af 100755
--- a/tools/gobj2dot.rb
+++ b/tools/gobj2dot.rb
@@ -70,15 +70,19 @@ puts header
 Find.find( dir ) do |path| 
   Find.prune if File.basename(path) == '.git' 
   if ( ( File.extname(path) == '.c' or File.extname(path) == '.h' ) and File.file? path )
-    open( path ) do |file| 
-      content = file.read
-      if( content =~ /G_DEFINE_TYPE\s*\(\s*\w+,\s*(\w+),\s*(\w+)\s*\)/m )
-        inheritance( tocamelcase( $1 ), gegltocamelcase( $2 ) )
-      elsif( content =~ /G_DEFINE_TYPE_WITH_CODE\s*\(\s*(\w+).*G_IMPLEMENT_INTERFACE\s*\s*\(\s*(\w+)/m )
-        implementation( $1, gegltocamelcase( $2 ) )
-      elsif( content =~ /G_TYPE_INTERFACE\s*,\s*\"([^\"]+)\"/m )
-        interfacedecl( $1 )
+    begin
+      open( path ) do |file| 
+        content = file.read
+        if( content =~ /G_DEFINE_TYPE\s*\(\s*\w+,\s*(\w+),\s*(\w+)\s*\)/m )
+          inheritance( tocamelcase( $1 ), gegltocamelcase( $2 ) )
+        elsif( content =~ /G_DEFINE_TYPE_WITH_CODE\s*\(\s*(\w+).*G_IMPLEMENT_INTERFACE\s*\s*\(\s*(\w+)/m )
+          implementation( $1, gegltocamelcase( $2 ) )
+        elsif( content =~ /G_TYPE_INTERFACE\s*,\s*\"([^\"]+)\"/m )
+          interfacedecl( $1 )
+        end
       end
+    rescue
+      warn "Failed to parse #{path}, probably invalid utf8"
     end
   end
 end



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