indexing description: "[ This class is made, to create a more proper style. ]" date: "$Date$" revision: "$Revision$" class ROOT_CLASS inherit KL_SHARED_FILE_SYSTEM export {NONE} all end EM_SHARED_FILE_LOADER export {NONE} all end create make feature {NONE} -- Initialisation make is do create log_file_path.make_from_string (file_system.current_working_directory + "/test/formatter.log") -- create log_file_path.make_from_string ("C:\eclips\workspace\em\library\formatter.log") create log_file.make_create_read_write (log_file_path) log_file.close do_directory (file_system.current_working_directory + "/test") -- do_directory ("C:\eclips\workspace\em\library") end do_directory(a_directory_name: STRING) is -- do one directory local the_dir: KL_DIRECTORY i_file, i_directory: INTEGER do create the_dir.make (a_directory_name) from i_directory := 1 until i_directory >= the_dir.directory_names.count + 1 loop if not the_dir.directory_names.item (i_directory).is_equal ("EIFGEN") and not the_dir.directory_names.item (i_directory).is_equal ("CVS") and not the_dir.directory_names.item (i_directory).is_equal ("generated_wrapper") then do_directory (a_directory_name + "/" + the_dir.directory_names.item (i_directory)) end i_directory := i_directory + 1 end io.put_string(" >> " + the_dir.name + "%N") from i_file := 1 until i_file >= the_dir.filenames.count + 1 loop checkfile(the_dir.name + "/" + the_dir.filenames.item (i_file)) i_file := i_file + 1 end end checkfile (a_file: STRING) is -- check one file local a_textfile: PLAIN_TEXT_FILE active_copy: BOOLEAN description_closed: BOOLEAN description_version : INTEGER -- 1: description: "[ ??? ]" -- 2: description: " " -- 3: description: " % % " output: STRING skip_it: BOOLEAN description_2: DS_LINKED_LIST [STRING] s: STRING first_feature_occured: BOOLEAN do create description_2.make file_loader.load_text_file_append (log_file_path) log_file := file_loader.last_text_file if file_system.has_extension (a_file, ".e") then file_loader.load_text_file_read_write (a_file) a_textfile := file_loader.last_text_file io.put_string (" -- the file: "+a_textfile.name + "%N") create output.make_empty from until a_textfile.count = 0 or else a_textfile.end_of_file loop skip_it := false a_textfile.read_line if new_line_not_accepted then from until not clean_line (a_textfile.last_string).is_equal ("") or a_textfile.end_of_file loop a_textfile.read_line end accept_new_line end if not active_copy and then description_version /= 0 and then not description_closed then if description_version = 1 then if a_textfile.last_string.has_substring ("]%"") then if check_string_is_traiding (clean_line (a_textfile.last_string), "]%"") then create s.make_from_string (clean_line (a_textfile.last_string)) s.replace_substring_all ("]%"", "") description_2.put_last (s) end description_closed := true skip_it := true else description_2.put_last (clean_line (a_textfile.last_string)) end elseif description_version = 3 then if check_string_is_traiding (clean_line (a_textfile.last_string),"%"") then if clean_line (a_textfile.last_string).index_of ('%%', 1) = 1 then create s.make_from_string (clean_line (a_textfile.last_string)) s.prune_all_leading ('%%') s.prune_all ('%"') description_2.put_last (s) end description_closed := true skip_it := true else create s.make_from_string (clean_line (a_textfile.last_string)) if check_string_is_leading (s,"%%") and check_string_is_traiding (s,"%%") then description_2.put_last (s.substring (2, s.count-1)) end end end end if not active_copy and then a_textfile.last_string.has_substring ("description") then -- DESCRIPTION FILTER from until description_version /= 0 loop if a_textfile.last_string.has_substring ("%"[") then description_version := 1 create s.make_from_string (a_textfile.last_string) s.replace_substring_all ("%"[", "") s.replace_substring_all ("description", "") s.replace_substring_all (":", "") s := clean_line (s) if s.count /= 0 then -- description_version 1 and text in same line like description tag description_2.put_last(s) end elseif a_textfile.last_string.has_substring ("%"") then if clean_line (a_textfile.last_string).substring_index ("%%", clean_line (a_textfile.last_string).count) = clean_line (a_textfile.last_string).count then description_version := 3 create s.make_from_string (clean_line (a_textfile.last_string)) s := s.substring (s.index_of ('%"', 1),s.count) s.prune_all_trailing ('%%') s.prune_all_leading ('%"') description_2.put_last (s) elseif clean_line (a_textfile.last_string).substring_index ("%"", clean_line (a_textfile.last_string).count) = clean_line (a_textfile.last_string).count then description_version := 2 create s.make_from_string (clean_line(a_textfile.last_string)) s := s.substring (s.index_of ('%"', 1),s.count) s.prune_all_trailing ('%"') s.prune_all_leading ('%"') description_2.put_last (s) description_closed := true skip_it := true else put_error (a_textfile.name, "description corrupted") end else a_textfile.readline if a_textfile.end_of_file then put_error (a_textfile.name, "description corrupted, no description") end end --io.put_string ("hi" + description_version.out + "%N") end end if not skip_it and then not active_copy and then ((description_version /= 0) implies description_closed) and then a_textfile.last_string.has_substring ("class") then -- class tag found first active_copy := true output.append (indexing_out (generated_description(a_file, description_2))) if clean_and_compare (a_textfile.last_string, "class") then a_textfile.read_line if clean_and_compare (a_textfile.last_string, "") then a_textfile.read_line if not clean_and_compare (a_textfile.last_string, "") then output.append ("class " + clean_line (a_textfile.last_string) + "%N%N") else put_error( a_textfile.name, "has no classname") end else output.append ("class " + clean_line (a_textfile.last_string) + "%N%N") end else output.append (a_textfile.last_string +"%N%N") end ignore_new_line else -- no indexing if active_copy then if is_first_and_keyword (a_textfile.last_string, "feature") then first_feature_occured := true create s.make_from_string (clean_line (a_textfile.last_string)) if not s.has_substring ("--") then output.append (s + " -- ??? NO FEATURE DESCRIPTION%N%N") log_it (a_file, "no feature description") else if s.has_substring ("-- ??? NO FEATURE") then log_it (a_file, "no feature description") end output.append (s + "%N%N") end ignore_new_line elseif not first_feature_occured and (is_first_and_keyword (a_textfile.last_string, "create") or is_first_and_keyword (a_textfile.last_string, "creation")) then if clean_and_compare (a_textfile.last_string, "create") or clean_and_compare (a_textfile.last_string, "creation") then output.append ("create%N%N%T" + next_clean_line (a_textfile) + "%N%N") else create s.make_from_string (clean_line (a_textfile.last_string)) s.replace_substring_all ("create", "") s.replace_substring_all ("creation", "") output.append ("create%N%N%T" + s + "%N%N") end ignore_new_line elseif not first_feature_occured and is_first_and_keyword (a_textfile.last_string, "inherit") then if clean_and_compare (a_textfile.last_string, "inherit") then output.append ("inherit%N%N%T" + next_clean_line (a_textfile) + "%N") else create s.make_from_string (clean_line (a_textfile.last_string)) s.replace_substring_all ("inherit", "") output.append ("inherit%N%N%T" + s + "%N") end else -- normal line create s.make_from_string (a_textfile.last_string) if s.has_substring ("end --") or s.has_substring ("end --") then s.remove_substring (s.substring_index ("--", 1),s.count) log_it (a_file, "deleted comment because of %"end --%" structure%N%T" + a_textfile.last_string) end if clean_right (s).has_substring (" ") then if s.has_substring ("-- ??? DOUBLE SPACE") then output.append (clean_right (s) + "%N") else output.append (clean_right (s) + " -- ??? DOUBLE SPACE OCCURED%N") end log_it (a_file, " double space") else if clean_and_compare (s,"") then ignore_new_line end output.append (clean_right (s) + "%N") end end end end end output.prune_all_trailing ('%N') a_textfile.close a_textfile.wipe_out a_textfile.open_write a_textfile.put_string (output) a_textfile.close end log_file.close end indexing_out (a_description: STRING): STRING is -- return indexing with a_description -- description has to be in format like: -- %T%Ttextexample%N%T%Tline2...%N do create Result.make_empty Result.append ("indexing%N") Result.append ("%N") Result.append ("%Tdescription: %"[%N") Result.append ("%N") Result.append (a_description) Result.append ("%N") Result.append ("%T]%"%N") Result.append ("%Tdate: %"$Date$%"%N") Result.append ("%Trevision: %"$Revision$%"%N") Result.append ("%N") end clean_line (a_line: STRING): STRING is -- all tabs, leading and trailing spaces will be removed do create Result.make_from_string (a_line) Result.prune_all ('%T') Result.prune_all_leading (' ') Result.prune_all_trailing (' ') end clean_right (a_line: STRING): STRING is -- clean all trailing tabs and spaces do create Result.make_from_string (a_line) from until Result.count = 0 or else not ((Result.item( Result.count ).is_equal (' ') or Result.item( Result.count ).is_equal ('%T'))) loop Result.keep_head (Result.count -1) end end clean_current_line (a_line: STRING): STRING is -- all tabs, leading and trailing spaces will be removed do a_line.prune_all ('%T') a_line.prune_all_leading (' ') a_line.prune_all_trailing (' ') end clean_and_compare (a_text_line, a_to_compare_string: STRING): BOOLEAN is -- is cleaned a_text_line equal to a_to_compare_string? do if clean_line (a_text_line).is_equal (a_to_compare_string) then Result := true else Result := false end end put_error (a_filename, a_message: STRING) is -- put errormessage do io.put_string ("%NERROR: " + a_message + ": %N --" + a_filename + "%N%N") end ignore_new_line is -- empty line will be skipped do new_line_not_accepted := true end accept_new_line is -- empty line is accepted do new_line_not_accepted := false end check_string_is_traiding (a_text, a_string: STRING): BOOLEAN is -- is a_string first in text? do if a_text.count /= 0 then if a_text.is_equal (a_string) then Result := true elseif a_text.substring_index (a_string, a_text.count-a_string.count) = a_text.count-a_string.count + 1 then Result := true else Result := false end else Result := false end end check_string_is_leading (a_text, a_string: STRING): BOOLEAN is -- is a_string first in text? do if a_text.count /= 0 then if a_text.substring_index (a_string, 1) = 1 then Result := true else Result := false end else Result := false end end generated_description (a_filename: STRING ; a_list_of_lines: DS_LINKED_LIST [STRING]) : STRING is -- generate description message from lines local stop: BOOLEAN do create Result.make_empty if not has_no_description (a_list_of_lines) then from a_list_of_lines.start until a_list_of_lines.after loop Result.append ("%T%T" + clean_line (a_list_of_lines.item_for_iteration) + "%N") a_list_of_lines.forth end from until stop loop if Result.substring_index ("%T%T%N", 1) = 1 then Result.remove_head (3) elseif Result.count > 2 and then Result.substring_index ("%T%T%N", Result.count-3) /= 0 then Result.remove_tail (3) else stop := true end end Result.prune_all_leading ('%N') Result.prune_all_trailing ('%N') Result := Result + "%N" else Result.append ("%T%T???%N") log_it (a_filename, "no description in indexing") end end has_no_description (a_list_of_lines: DS_LINKED_LIST [STRING]) :BOOLEAN is -- is the description empty? do if a_list_of_lines.count /= 0 then from a_list_of_lines.start until a_list_of_lines.after loop if (a_list_of_lines.item_for_iteration.has_substring ("Objects that ...") or a_list_of_lines.item_for_iteration.has_substring ("???")) then Result := true end a_list_of_lines.forth end else Result := true end end next_clean_line (a_textfile: PLAIN_TEXT_FILE): STRING is -- next line not "" do create Result.make_empty a_textfile.read_line from until a_textfile.end_of_file or not clean_and_compare (a_textfile.last_string, "") loop a_textfile.read_line end if a_textfile.last_string /= void then Result.append (clean_line (a_textfile.last_string)) end end is_first_and_keyword (a_text, a_keyword: STRING) : BOOLEAN is -- gets true if a_keyword is first string in a_text local s: STRING do create s.make_from_string ( clean_line (a_text)) Result := s.substring_index (a_keyword, 1) = 1 Result := Result and (s.count = a_keyword.count or else s.item(a_keyword.count+1).is_equal (' ')) end log_it (a_filename, a_text: STRING) is -- write to log file do log_file.put_string (a_filename + ": " + a_text + "%N") end log_file: PLAIN_TEXT_FILE working_path: KL_DIRECTORY new_line_not_accepted: BOOLEAN -- is a "%N" -String as next line accepptable? log_file_path : STRING end