def gen(prod_list = nil)
def mixGen(prod_list)
return prod_list, @prod_hash.dup if prod_list.length == 1
mixedList = []
prod_hashMixed = @prod_hash.dup
0.upto(prod_list.length-2) {|i|
if !mixedList.include?(prod_list.at(i))
(i+1).upto(prod_list.length-1) {|j|
if !mixedList.include?(prod_list.at(j))
if prod_hashMixed[prod_list.at(i)].o_file ==
@prod_hash[prod_list.at(j)].o_file
mixedList.push(prod_list.at(j))
prod_hashMixed[prod_list.at(i)].sub_list +=
@prod_hash[prod_list.at(j)].sub_list
prod_hashMixed.delete(prod_list.at(j))
end
end
}
end
}
return prod_list-mixedList, prod_hashMixed
end
def replace(source_str, replace_list)
delta_length = 0
result_str = source_str.dup
replace_list.each { |rep|
str1 = result_str[0, rep[0] + delta_length]
str2 = result_str[rep[0] + delta_length, rep[1] - rep[0] +1]
str3 = result_str[rep[1] + 1 + delta_length, result_str.length - 1]
str2 =~ @sub_hash[rep[2]].reg_exp.zoom_list.last
str = ''
eval("str = " + '"' + @sub_hash[rep[2]].text + '"')
result_str = str1 + str + str3
delta_length = result_str.length - source_str.length
}
return result_str
end
def mix_subs(sub_list, i_file)
result = []
sub_list.each { |s|
if /local/ =~ @sub_hash[s].scope then
if /before/ =~ @sub_hash[s].scope then
element = @sub_hash[s].match_hash[i_file][0].dup
element[1] = element[0] - 1
element << s
result << element
elsif /after/ =~ @sub_hash[s].scope then
element = @sub_hash[s].match_hash[i_file][0].dup
element[0] = element[1] + 1
element << s
result << element
else
element = @sub_hash[s].match_hash[i_file][0].dup
element << s
result << element
end
else
if /before/ =~ @sub_hash[s].scope then
@sub_hash[s].match_hash[i_file].each { |m|
element = m.dup
element[1] = element[0] - 1
element << s
result << element
}
elsif /after/ =~ @sub_hash[s].scope then
@sub_hash[s].match_hash[i_file].each { |m|
element = m.dup
element[0] = element[1] + 1
element << s
result << element
}
else
@sub_hash[s].match_hash[i_file].each { |m|
element = m.dup
element << s
result << element
}
end
end
}
result.sort! { |e1, e2|
if e1[0] == e2[0] then
e1[1] <=> e2[1]
else
e1[0] <=> e2[0]
end
}
return result
end
@sub_hash = {} unless @sub_hash
@prod_hash = {} unless @prod_hash
prod_list = @prod_hash.keys if !prod_list or prod_list == 'all'
eval Error.arg_class(['prod_list', 'Array'])
eval Error.without_declaration('prod')
eval Error.collision('gen')
prod_listM, prod_hashM = mixGen(prod_list)
prod_listM.each { |p|
File.open(prod_hashM[p].i_file) {|f|
exemplar_code = f.read
prod_hashM[p].sub_list.each {|s|
if !@sub_hash[s].match_hash[prod_hashM[p].i_file] then
@sub_hash[s].match_hash[prod_hashM[p].i_file] = @sub_hash[s].get_match_pos(exemplar_code, @sub_hash[s].reg_exp, @sub_hash[s].scope)
end
}
exemplar_code = replace( exemplar_code, mix_subs(prod_hashM[p].sub_list, prod_hashM[p].i_file) )
o_dir = File.dirname(prod_hashM[p].o_file)
begin
Dir.mkdir(o_dir) unless FileTest.exist?(o_dir)
rescue
if !FileTest.exist?(o_dir) then
operating_system_command = "`mkdir #{o_dir.gsub(/\\/, '\\\\\\')}`"
eval operating_system_command
end
end
File.open(prod_hashM[p].o_file, "w+") {|o_file|
o_file.write(exemplar_code)
}
}
}
end