Mercurial > projects > dwt2
comparison packageimport.rb @ 12:bc29606a740c
Added dwt-addons in original directory structure of eclipse.org
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 14 Mar 2009 18:23:29 +0100 |
parents | |
children | a6998d2a84b3 |
comparison
equal
deleted
inserted
replaced
11:43904fec5dca | 12:bc29606a740c |
---|---|
1 require 'find' | |
2 require 'fileutils' | |
3 require 'set' | |
4 | |
5 def ProcessModule( path, modName, modList ) | |
6 puts "ProcessModule #{path}" | |
7 identifiers = Set.new | |
8 File.open(path).each_line do |s| | |
9 if s =~ /^[ \t]*\*/ then | |
10 next | |
11 end | |
12 s.split( /[^0-9A-Za-z_]/ ).each do |tok| | |
13 if tok =~ /^[_A-Z][_A-Za-z0-9]*$/ then | |
14 identifiers << tok | |
15 end | |
16 end | |
17 end | |
18 w=File.new(path+".new","w+") | |
19 File.open(path).each_line do |s| | |
20 if s =~/\/\/ packageimport$/ then | |
21 else | |
22 w.puts s | |
23 end | |
24 if s =~ /^module +((([a-zA-Z0-9_]+)\.)*)([a-zA-Z0-9_]+);/ then | |
25 packname = $1 | |
26 (modList-modName).intersection(identifiers).each do|id| | |
27 w.puts "import #{packname}#{id};" | |
28 end | |
29 end | |
30 end | |
31 end | |
32 | |
33 def ProcessDirectory( path ) | |
34 puts path | |
35 modList = Set.new | |
36 Dir.foreach(path) do |entry| | |
37 filename = File.join(path,entry) | |
38 if FileTest.file?(filename) && filename =~ /\.d$/ then | |
39 modList << entry[ 0 .. -3 ] | |
40 end | |
41 end | |
42 Dir.foreach(path) do |entry| | |
43 filename = File.join(path,entry) | |
44 if FileTest.file?(filename) && filename =~ /\.d$/ then | |
45 ProcessModule( filename, entry[ 0 .. -3 ], modList ) | |
46 end | |
47 end | |
48 end | |
49 | |
50 ARGV.each do|startpath| | |
51 puts "processing #{startpath}" | |
52 if !FileTest.directory?(startpath) then | |
53 raise "Argument is not a directory" | |
54 end | |
55 Find.find( startpath ) do |path| | |
56 if FileTest.directory?(path) then | |
57 ProcessDirectory(path) | |
58 end | |
59 end | |
60 end | |
61 |