/* The following comment was added by Kari Laitinen on 15.3.2005 This is one of the Prolog programs of which an experimental software maintenance tool called InName is made. InName is a disabbreviation tool with which it is possible convert abbreviated names of C/C++ programs to more understandable, natural names. The Prolog source programs of the InName tool are now declared "Open Source" programs. People who have contributed to the original development of these programs include Kari Laitinen http://www.naturalprogramming.com Neil Rowe U.S. Naval Postgraduate School Markku Heikkila Currently works at Nokia. Jorma Taramaa Currently works at Nokia. The InName tool was developed at VTT Electronics, a division of the Technical Reseach Centre of Finland. The work was funded by VTT Electronics and the EU. It is the wish of the original developers that the above names will be mentioned if these programs are exploited in the development of other disabbreviation tools. A description about the InName tool and theoretical discussion related to it can be found at Laitinen, K., Taramaa, J., Heikkila, M., and Rowe, N. C.. Enhancing Maintainability of Source Programs through Disabbreviation. The Journal of Systems and Software, Vol. 37, No. 2, 1997, pp. 117 - 128. The text of the original file begins below. */ /*--------------------------------------------------------------------------- VTT Electronics Quintus Prolog source program Embedded Software (Version 3.1.1) AMES / InName project Markku Heikkila (MaH) File: inname_third_pass.pro Version: 0.1 Status: draft Accepted by: File history: 18.8.1994 v0.0 File created Markku Heikkila 23.8.1994 v0.1 Last modification Markku Heikkila ---------------------------------------------------------------------------*/ replace_selected_names_in_program_file( Original_file ) :- generate_backup_file( Original_file, Backup_file_name ), see( Backup_file_name ), tell( Original_file ), lines_in_file( Last_line ), handle_all_lines( 1, Last_line ), told, seen. handle_all_lines( Line_number, Last_line ) :- Line_number =< Last_line, ( findall( ( Unknown_name, Substitution_as_list_of_words ), ( name_substitution( Unknown_name, Substitution_as_list_of_words, List_of_line_numbers ), member( Line_number, List_of_line_numbers ) ), List_of_pairs_of_name_and_substitution ) ; List_of_pairs_of_name_and_substitution = [] ), get_line( Next_line ), replace_all_unknown_names_in_line( Next_line, List_of_pairs_of_name_and_substitution, Resulting_line ), put_line( Resulting_line ), Next_line_number is Line_number + 1, handle_all_lines( Next_line_number, Last_line ). handle_all_lines( _, _ ) :- !. replace_all_unknown_names_in_line( Resulting_line, [], Resulting_line ). replace_all_unknown_names_in_line( Next_line, [ ( Unknown_name, Substitution_for_unknown_name ) | Rest_of_pairs_of_name_and_substitution ], Resulting_line ) :- name( Unknown_name, Unknown_name_as_list ), !, append3( First_part, Unknown_name_as_list, Rest_part, Next_line ), ensure_that_unknown_name_is_not_part_of_another_name( Unknown_name_as_list, First_part, Rest_part ), convert_list_of_words_to_underscored_string( Substitution_for_unknown_name, Substitution_as_string ), name( Substitution_as_string, Substitution_as_list ), append3( First_part, Substitution_as_list, Rest_part, Line_with_this_unknown_name_replaced ), replace_all_unknown_names_in_line( Line_with_this_unknown_name_replaced, Rest_of_pairs_of_name_and_substitution, Resulting_line ). ensure_that_unknown_name_is_not_part_of_another_name( Unknown_name_as_list, First_part, Rest_part ) :- inname_data( list_of_illegal_characters_next_to_unknown_name( List_of_illegal_characters ) ), /* Separate bordering characters and check whether they are legal or not. */ ( append( _, [ Last_character_of_first_part ], First_part ) ; Last_character_of_first_part = [] ), !, nonmember( Last_character_of_first_part, List_of_illegal_characters ), ( append( [ First_character_of_rest_part | _ ], [], Rest_part ) ; First_character_of_rest_part = [] ), !, nonmember( First_character_of_rest_part, List_of_illegal_characters ). /* This is not used so far. This could accelerate the replacing process a bit. */ forget_unknown_name_if_all_replaced( Unknown_name, Line_number, List_of_line_numbers ) :- append( _, [ Last_line_number_in_list ], List_of_line_numbers ), Line_number > Last_line_number_in_list, retractall( name_substitution( Unknown_name, _, _ ) ), !, fail.