Changeset 340

Show
Ignore:
Timestamp:
05/03/07 19:37:52 (2 years ago)
Author:
keinfarbton
Message:

works

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/tioport/extractmixins.rb

    r339 r340  
     1#!/usr/bin/ruby 
    12# search a tree for all .d files, scan every file for TioPortMixin comments. 
    23# if such comments are found, collect all paragraphs and write them into a mxin file. 
     
    67 
    78require 'find' 
     9require 'fileutils' 
    810 
    911if ARGV.length != 2 
     
    2628end 
    2729 
    28 COMMENT_START = /(\s*)\/\/TioPortMixin/ 
    29 COMMENT_END   = /\s*\/\/End of TioPortMixin/ 
     30#COMMENT_START = /^\(\s*\)\/\/TioPortMixin\>/ 
     31COMMENT_START = /^(\s*)\/\/TioPortMixin\b/ 
     32COMMENT_END   = /^\s*\/\/TioPortMixinEnd\b/ 
     33 
     34def 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 
     43end 
    3044 
    3145def processFile( src, mix ) 
    32     puts "#{src} -> #{mix}" 
     46    #puts "#{src} -> #{mix}" 
    3347 
    3448    indent = 0 
    3549    File.open( src, "r") do |infile| 
    36         indent = 0; 
     50        indent = ""; 
     51        content = Array.new 
     52        inmixin = false 
    3753        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; 
    3959            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 
    4175        end 
    4276    end