indexing description : "System's root class" date: "$Date$" revision: "$Revision$" class ROOT_CLASS inherit ARGUMENTS create make feature -- Initialization make is -- Creation procedure. local l_file, l_file_out: PLAIN_TEXT_FILE do if argument_count = 3 then create l_file.make (argument (1)) -- open and parse translation file if l_file.exists and then l_file.is_readable then l_file.open_read build_translation_table (l_file) l_file.close -- open and replace callgrind file create l_file.make (argument (2)) create l_file_out.make (argument (3)) if l_file.exists and then l_file.is_readable and then (l_file_out.is_creatable or (l_file_out.exists and then l_file_out.is_writable)) then l_file.open_read l_file_out.open_write translate_file (l_file, l_file_out) l_file.close l_file_out.close else io.error.put_string ("Could not open valgrind files.") io.error.new_line end else io.error.put_string ("Could not open translation file: "+ argument (1)) io.error.new_line end else print_usage end end feature {NONE} -- Implementation translation_table: HASH_TABLE [STRING, STRING] -- Mapping of translation. print_usage is -- Print usage information. do io.put_string ("Usage: valgrind_converter TRANSLAT IN OUT") io.new_line io.put_string ("TRANSLAT%Tlocation of the TRANSLAT file") io.new_line io.put_string ("IN%T%Tlocation of the input valgrind file") io.new_line io.put_string ("OUT%T%Tlocation of the output valgrind file") io.new_line end build_translation_table (a_file: PLAIN_TEXT_FILE) is -- Build translation_table from a_file. require a_file_valid: a_file /= Void and then a_file.is_open_read local l_regexp: RX_PCRE_REGULAR_EXPRESSION do -- we asume, that each line has about 40 characters, therefore we assume that we have file.size/50 lines create translation_table.make (a_file.count // 40) create l_regexp.make l_regexp.compile ("(^[^\t]*)\t([^\t]*)\t([^\t]*)\t([^\t]*)") l_regexp.optimize from a_file.start until a_file.end_of_file loop a_file.read_line l_regexp.match (a_file.last_string) translation_table.force (l_regexp.captured_substring (2) + "::" + l_regexp.captured_substring (3), l_regexp.captured_substring (4)) end ensure translation_table_set: translation_table /= Void end translate_file (a_in_file, a_out_file: PLAIN_TEXT_FILE) is -- Translate a_in_file into a_out_file. require a_in_file_valid: a_in_file /= Void and then a_in_file.is_open_read a_outfile_valid: a_out_file /= Void and then a_out_file.is_open_write translation_table_set: translation_table /= Void local l_line, l_trans: STRING l_regexp: RX_PCRE_REGULAR_EXPRESSION do create l_regexp.make l_regexp.compile ("c?fn=\([0-9]*\) ([a-zA-Z0-9_-]+)") l_regexp.optimize from a_in_file.start until a_in_file.end_of_file loop a_in_file.read_line l_line := a_in_file.last_string l_regexp.match (l_line) if l_regexp.has_matched then l_trans := l_regexp.captured_substring (1) if translation_table.has_key (l_trans) then l_line.replace_substring_all (l_trans, translation_table.found_item) end end a_out_file.put_string (l_line) a_out_file.new_line end end end -- class ROOT_CLASS