Changeset 340
- Timestamp:
- 05/03/07 19:37:52 (2 years ago)
- Files:
-
- trunk/tioport/extractmixins.rb (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/tioport/extractmixins.rb
r339 r340 1 #!/usr/bin/ruby 1 2 # search a tree for all .d files, scan every file for TioPortMixin comments. 2 3 # if such comments are found, collect all paragraphs and write them into a mxin file. … … 6 7 7 8 require 'find' 9 require 'fileutils' 8 10 9 11 if ARGV.length != 2 … … 26 28 end 27 29 28 COMMENT_START = /(\s*)\/\/TioPortMixin/ 29 COMMENT_END = /\s*\/\/End of TioPortMixin/ 30 #COMMENT_START = /^\(\s*\)\/\/TioPortMixin\>/ 31 COMMENT_START = /^(\s*)\/\/TioPortMixin\b/ 32 COMMENT_END = /^\s*\/\/TioPortMixinEnd\b/ 33 34 def append( arr, indent, line ) 35 if line.length != 0 and line.slice( 0, indent.length ) != indent 36 raise "must match the indent of be an empty line" 37 elsif line.length == 0 38 arr << "" 39 else 40 arr << line.slice( indent.length, line.length ) 41 end 42 arr 43 end 30 44 31 45 def processFile( src, mix ) 32 puts "#{src} -> #{mix}"46 #puts "#{src} -> #{mix}" 33 47 34 48 indent = 0 35 49 File.open( src, "r") do |infile| 36 indent = 0; 50 indent = ""; 51 content = Array.new 52 inmixin = false 37 53 while (line = infile.gets) 38 if line ~= COMMENT_START 54 if line =~ COMMENT_START 55 indent = $1 56 inmixin = true; 57 elsif line =~ COMMENT_END 58 inmixin = false; 39 59 end 40 puts "#{counter}: #{line}" 60 if inmixin 61 content = append( content, indent, line ) 62 end 63 end 64 if inmixin 65 raise "mixin was not closed in #{src}" 66 end 67 if content.length > 0 68 puts "writing #{mix}" 69 FileUtils.mkdir_p( File.dirname( mix ) ) 70 File.open( mix, "w" ) do |mixfile| 71 content.each do |contentline| 72 mixfile << contentline 73 end 74 end 41 75 end 42 76 end
