/* 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 AMES - project Kari Laitinen File: inname_utilities.pro Version: 0.1 Status: draft Accepted: File history: 10.5.1994 v0.0 File separated from inname.pro Kari Laitinen 5.5.1995 v0.1 Last Modification Kari Laitinen ----------------------------------------------------------------------------- N O T E S ----------------------------------------------------------------------------- 5.5.95: The routine read_lines_from_currently_open_file used to convert all characters lowercase. That feature has been taken away. ----------------------------------------------------------------------------*/ :- no_style_check(single_var). :- ensure_loaded(library(caseconv)). :- ensure_loaded(library(basics)). :- ensure_loaded(library(lists)). :- multifile general_counters/2. :- dynamic general_counters/2. /*---------------------------------------------------------------------------- CHECKING ABBREVIATIONS ----------------------------------------------------------------------------*/ can_abbreviate_string0( Shorter_string, Longer_string ) :- name( Shorter_string, Shorter_list ), name( Longer_string, Longer_list ), can_abbreviate_list0( Shorter_list, Longer_list ). can_abbreviate_string1( Shorter_string, Longer_string ) :- name( Shorter_string, Shorter_list ), name( Longer_string, Longer_list ), can_abbreviate_list1( Shorter_list, Longer_list ). can_abbreviate_list1( [], _ ) :- !, fail. can_abbreviate_list1( Shorter_list, Longer_list ) :- can_abbreviate_list0( Shorter_list, Longer_list ). can_abbreviate_list0( [], _ ) :- !. can_abbreviate_list0( [First_character_of_shorter_list | Rest_of_shorter_list], [First_character_of_longer_list | Rest_of_longer_list]):- First_character_of_shorter_list =:= First_character_of_longer_list, is_subsequence_in( Rest_of_shorter_list, Rest_of_longer_list ), !. is_subsequence_in( [ First_character_of_shorter_list | Rest_of_shorter_list ], [ First_character_of_longer_list | Rest_of_longer_list ] ):- \+ shorter_list( Rest_of_longer_list, Rest_of_shorter_list ), (( First_character_of_shorter_list =:= First_character_of_longer_list, is_subsequence_in( Rest_of_shorter_list, Rest_of_longer_list )) ; ( is_subsequence_in( [ First_character_of_shorter_list | Rest_of_shorter_list], Rest_of_longer_list ) ) ). is_subsequence_in( [], _ ) :- !. /*-------------------------------------------------------------------------- MANIPULATING CHARACTER LISTS ---------------------------------------------------------------------------*/ get_rid_of_disturbing_underscores( Name_character_list, Name_without_disturbing_underscores ) :- get_rid_of_adjacent_underscores( Name_character_list, Name_without_adjacent_underscores ), ( append( [95], Name_without_preceding_underscores, Name_without_adjacent_underscores ) ; Name_without_preceding_underscores = Name_without_adjacent_underscores ), ( append( Name_without_disturbing_underscores, [95], Name_without_preceding_underscores ) ; Name_without_disturbing_underscores = Name_without_preceding_underscores ), !. get_rid_of_adjacent_spaces( Character_list, List_without_adjacent_spaces ) :- append( First_part_of_the_list, [ 32, 32 | Second_part_of_the_list ], Character_list ), append( First_part_of_the_list, [ 32 | Second_part_of_the_list ], List_containing_one_space_less ), !, get_rid_of_adjacent_spaces( List_containing_one_space_less, List_without_adjacent_spaces ), !. get_rid_of_adjacent_spaces( List_without_adjacent_spaces, List_without_adjacent_spaces ) :- !. get_rid_of_adjacent_underscores( Name_character_list, List_without_adjacent_underscores ) :- append( First_part_of_the_list, [ 95,95 | Second_part_of_the_list ], Name_character_list ), append( First_part_of_the_list, [ 95 | Second_part_of_the_list ], List_containing_one_underscore_less ), !, get_rid_of_adjacent_underscores( List_containing_one_underscore_less, List_without_adjacent_underscores ), !. get_rid_of_adjacent_underscores( List_without_adjacent_underscores, List_without_adjacent_underscores ) :- !. get_rid_of_unnecessary_spaces( Character_list, List_without_unnecessary_spaces ) :- get_rid_of_adjacent_spaces( Character_list, List_without_adjacent_spaces ), ( append( [ 32 ], List_without_spaces_in_the_beginning, List_without_adjacent_spaces ) ; List_without_spaces_in_the_beginning = List_without_adjacent_spaces ), ( append( List_without_unnecessary_spaces, [ 32 ], List_without_spaces_in_the_beginning ) ; List_without_unnecessary_spaces = List_without_spaces_in_the_beginning), !. /*-------------------------------------------------------------------------- WORD LISTS AND STRINGS ---------------------------------------------------------------------------*/ add_trailing_spaces_to_list( List, Desired_length, Resulting_list ) :- append( List, " ", List_with_one_trailing_space_more ), length( List_with_one_trailing_space_more, Current_list_length ), Current_list_length =< Desired_length, !, add_trailing_spaces_to_list( List_with_one_trailing_space_more, Desired_length, Resulting_list ), !. add_trailing_spaces_to_list( Resulting_list, _, Resulting_list ) :- !. add_trailing_spaces_to_string( String, Desired_length, Resulting_string ) :- name( String, String_as_list ), add_trailing_spaces_to_list( String_as_list, Desired_length, Resulting_list ), name( Resulting_string, Resulting_list ), !. convert_list_of_words_to_underscored_string( [ Only_one_word ], Only_one_word) :- !. convert_list_of_words_to_underscored_string( [ First_word | Rest_of_words ], Underscored_string ) :- /* In this case we should have two or more words in the list. */ convert_list_of_words_to_underscored_string( Rest_of_words, Rest_of_words_as_underscored_string ), name( First_word, First_word_as_list ), name( Rest_of_words_as_underscored_string, Rest_of_words_as_underscored_list ), append3( First_word_as_list, [95], Rest_of_words_as_underscored_list, Underscored_character_list ), name( Underscored_string, Underscored_character_list ), !. convert_list_of_words_to_underscored_string( [], '') :- !. convert_underscored_string_to_list_of_words( Underscored_string, List_of_words ) :- name( Underscored_string, List_of_characters ), /* The following call is to make this routine more reusable. */ get_rid_of_disturbing_underscores( List_of_characters, Clean_list_of_characters ), convert_underscored_character_list_to_list_of_words( Clean_list_of_characters, List_of_words ), !. convert_underscored_character_list_to_list_of_words( [], [] ) :- !. convert_underscored_character_list_to_list_of_words( List_of_characters, [ First_word | Rest_of_words ] ) :- append( First_word_characters, [ 95 | Rest_of_character_list ], List_of_characters ), name( First_word, First_word_characters ), convert_underscored_character_list_to_list_of_words( Rest_of_character_list, Rest_of_words ), !. convert_underscored_character_list_to_list_of_words( List_of_characters, [ Last_word ] ) :- name( Last_word, List_of_characters ), !. convert_list_of_strings_to_spaced_string( [ Only_one_string ], Only_one_string) :- !. convert_list_of_strings_to_spaced_string( [ First_string | Rest_of_strings ], Spaced_string ) :- /* In this case we should have two or more strings in the list. */ convert_list_of_strings_to_spaced_string( Rest_of_strings, Rest_of_strings_as_spaced_string ), name( First_string, First_string_as_list ), name( Rest_of_strings_as_spaced_string, Rest_of_strings_as_spaced_list ), append3( First_string_as_list, [ 32 ], Rest_of_strings_as_spaced_list, Spaced_character_list ), name( Spaced_string, Spaced_character_list ), !. convert_list_of_strings_to_spaced_string( [], '') :- !. convert_list_of_words_to_string( List_of_words, Resulting_string ) :- convert_list_of_words_to_list_of_characters( List_of_words, List_of_characters ), name( Resulting_string, List_of_characters ). convert_list_of_words_to_list_of_characters( [ First_word | Rest_of_words ], List_of_characters ) :- convert_list_of_words_to_list_of_characters( Rest_of_words, Rest_of_words_as_list_of_characters ), name( First_word, First_word_as_list_of_characters ), append( First_word_as_list_of_characters, Rest_of_words_as_list_of_characters, List_of_characters ), !. convert_list_of_words_to_list_of_characters( [], [] ) :- !. convert_list_of_character_lists_to_underscored_string( List_of_character_lists, Underscored_string ) :- convert_list_of_character_lists_to_underscored_character_list( List_of_character_lists, Underscored_character_list ), name( Underscored_string, Underscored_character_list ), !. convert_list_of_character_lists_to_underscored_character_list( [ First_character_list | Rest_of_character_lists ], Underscored_character_list ) :- First_character_list == [], convert_list_of_character_lists_to_underscored_character_list( Rest_of_character_lists, Underscored_character_list ). convert_list_of_character_lists_to_underscored_character_list( [ First_character_list | Rest_of_character_lists ], Underscored_character_list ) :- convert_list_of_character_lists_to_underscored_character_list( Rest_of_character_lists, Rest_of_underscored_character_list ), ( ( Rest_of_underscored_character_list == [], Underscored_character_list = First_character_list ) ; ( append( First_character_list, [95], First_character_list_and_an_underscore ), append( First_character_list_and_an_underscore, Rest_of_underscored_character_list, Underscored_character_list ) ) ). convert_list_of_character_lists_to_underscored_character_list( [], [] ). calculate_number_of_words_in_underscored_string( Underscored_string, Number_of_words ) :- name( Underscored_string, Underscored_character_list ), calculate_number_of_words_in_character_list( Underscored_character_list, Number_of_words ). calculate_number_of_words_in_character_list( Name_in_list_form, Number_of_words ) :- member( 95, Name_in_list_form ), increment_counter( number_of_underscores ), fail. calculate_number_of_words_in_character_list( Name_in_list_form, Number_of_words ) :- read_counter( number_of_underscores, Number_of_underscores ), Number_of_words is Number_of_underscores + 1, reset_counter( number_of_underscores ), !. make_character_list_lowercase( [ First_character | Rest_of_characters ], [ First_lowercased_character | Rest_of_lowercased_characters ] ) :- (( character_is_an_uppercase_letter( First_character ), First_lowercased_character is First_character + 32 ) ; ( First_lowercased_character is First_character ) ), make_character_list_lowercase( Rest_of_characters, Rest_of_lowercased_characters ), !. make_character_list_lowercase( [], [] ) :- !. make_character_lowercase( Given_character, Lowercased_character ) :- (( character_is_an_uppercase_letter( Given_character ), Lowercased_character is Given_character + 32 ) ; ( Lowercased_character is Given_character ) ). make_list_of_words_lowercase( [ First_word | Rest_of_words ], [ Lowercased_first_word | Rest_of_lowercased_words ] ) :- lower( First_word, Lowercased_first_word ), make_list_of_words_lowercase( Rest_of_words, Rest_of_lowercased_words ), !. make_list_of_words_lowercase( [], [] ) :- !. make_list_of_words_non_capitalized( [ First_word | Rest_of_words ], [ First_non_capitalized_word | Rest_of_non_capitalized_words ] ) :- ( ( upper( First_word ), First_non_capitalized_word = First_word ) ; ( lower( First_word, First_non_capitalized_word ) ) ), !, make_list_of_words_non_capitalized( Rest_of_words, Rest_of_non_capitalized_words ), !. make_list_of_words_non_capitalized( [], [] ) :- !. make_list_of_words_uppercase( [ First_word | Rest_of_words ], [ Uppercased_first_word | Rest_of_uppercased_words ] ) :- upper( First_word, Uppercased_first_word ), make_list_of_words_uppercase( Rest_of_words, Rest_of_uppercased_words ), !. make_list_of_words_uppercase( [], [] ) :- !. remove_empty_strings_from_string_list( [ First_string | Rest_of_strings ], List_of_nonempty_strings ) :- First_string == '', !, remove_empty_strings_from_string_list( Rest_of_strings, List_of_nonempty_strings ), !. remove_empty_strings_from_string_list( [ First_original_string | Rest_of_original_strings ], [ First_original_string | List_of_nonempty_strings ] ) :- !, remove_empty_strings_from_string_list( Rest_of_original_strings, List_of_nonempty_strings ), !. remove_empty_strings_from_string_list( [], [] ) :- !. replace_spaces_with_underscores_in_list( [ 32 | Rest_of_characters ], [ 95 | Rest_of_underscored_characters ] ) :- !, replace_spaces_with_underscores_in_list( Rest_of_characters, Rest_of_underscored_characters ), !. replace_spaces_with_underscores_in_list( [ Non_space_character | Rest_of_characters ], [ Non_space_character | Rest_of_underscored_characters ] ) :- !, replace_spaces_with_underscores_in_list( Rest_of_characters, Rest_of_underscored_characters ), !. replace_spaces_with_underscores_in_list( [], [] ) :- !. /*--------------------------------------------------------------------------- CHECKING CHARACTERS, CHARACTER LISTS, AND CHARACTER STRINGS ----------------------------------------------------------------------------*/ capitalized_word_string( String ) :- name( String, List ), capitalized_word( List ). capitalized_word( [ First_letter | [] ] ) :- !, fail. /* Single character words are not acceptable. */ capitalized_word( [ First_letter | Rest_of_letters ] ) :- character_is_an_uppercase_letter( First_letter ), list_contains_only_lowercase_letters( Rest_of_letters ). name_can_be_a_capitalized_name( Name_as_string ) :- name( Name_as_string, Name_character_list ), append( _, [ Some_character_of_the_name, Following_character | _ ], Name_character_list ), character_is_an_uppercase_letter( Some_character_of_the_name ), character_is_a_lowercase_letter( Following_character ), !. name_is_lowercase_with_underscores( Name_character_list ) :- list_has_at_least_one_underscore( Name_character_list ), list_contains_only_lowercase_letters_or_underscores( Name_character_list). name_is_uppercase_with_underscores( Name_character_list ) :- list_has_at_least_one_underscore( Name_character_list ), list_contains_only_uppercase_letters_or_underscores( Name_character_list). list_has_at_least_one_underscore( Character_list ) :- member( Some_character_in_the_list, Character_list ), Some_character_in_the_list = 95 . list_contains_no_underscores( List_of_characters ) :- \+ member( 95, List_of_characters ), !. list_contains_only_letters( [] ). list_contains_only_letters( [ First_character | Rest_of_characters ] ) :- ( character_is_a_lowercase_letter( First_character ) ; character_is_an_uppercase_letter( First_character ) ), list_contains_only_letters( Rest_of_characters ). list_contains_only_lowercase_letters( [] ). list_contains_only_lowercase_letters( [ First_letter | Rest_of_letters ] ) :- character_is_a_lowercase_letter( First_letter ), list_contains_only_lowercase_letters( Rest_of_letters ). list_contains_only_uppercase_letters( [] ). list_contains_only_uppercase_letters( [ First_letter | Rest_of_letters ] ) :- character_is_an_uppercase_letter( First_letter ), list_contains_only_uppercase_letters( Rest_of_letters ). list_contains_only_letters_or_underscores( [] ). list_contains_only_letters_or_underscores( [ First_letter | Rest_of_letters]):- name_starting_character( First_letter ), list_contains_only_letters_or_underscores( Rest_of_letters ). list_contains_only_lowercase_letters_or_underscores( [] ). list_contains_only_lowercase_letters_or_underscores( [ First_character | Rest_of_characters ] ):- ( character_is_a_lowercase_letter( First_character ) ; First_character = 95 ), list_contains_only_lowercase_letters_or_underscores( Rest_of_characters ). list_contains_only_uppercase_letters_or_underscores( [] ). list_contains_only_uppercase_letters_or_underscores( [ First_character | Rest_of_characters ] ):- ( character_is_an_uppercase_letter( First_character ) ; First_character = 95 ), list_contains_only_uppercase_letters_or_underscores( Rest_of_characters ). list_starts_with_a_lowercase_letter( [ First_character | Rest_of_list ] ) :- character_is_a_lowercase_letter( First_character ). list_starts_with_an_uppercase_letter( [ First_character | Rest_of_list ] ) :- character_is_an_uppercase_letter( First_character ). valid_c_name( [ First_character | Rest_of_name ] ) :- name_starting_character( First_character ), list_of_name_body_characters( Rest_of_name ). list_of_name_body_characters( [] ). list_of_name_body_characters( [ First_character | Rest_of_list ] ) :- valid_name_body_character( First_character ), list_of_name_body_characters( Rest_of_list ). name_starting_character( Character ) :- Character = 95 ; character_is_a_letter( Character ). valid_name_body_character( Character ) :- Character = 95 ; character_is_a_letter( Character ) ; character_is_a_digit( Character ). character_is_a_letter_or_number( Letter_or_number ) :- character_is_a_letter( Letter_or_number ) ; character_is_a_digit( Letter_or_number ), !. character_is_not_a_letter_or_number( Character_code ) :- ( ( Character_code < 48 ) ; ( Character_code > 57, Character_code < 65 ) ; ( Character_code > 90, Character_code < 97 ) ; ( Character_code > 122 ) ), !. character_is_a_letter( Character ) :- character_is_a_lowercase_letter( Character ) ; character_is_an_uppercase_letter( Character ). character_is_a_lowercase_letter( Character_code ) :- Character_code > 96, Character_code < 123, !. character_is_an_uppercase_letter( Character_code ) :- Character_code > 64, Character_code < 91, !. character_is_a_digit( Character_code ) :- Character_code > 47, Character_code < 58, !. character_is_a_hexadecimal_digit( Character_code ) :- (( character_is_a_digit( Character_code )) ; ( Character_code > 64, Character_code < 71 ) ; ( Character_code > 96, Character_code < 103 ) ), !. character_is_a_type_specifier_of_c_numeric_value( Character_code ) :- ( Character_code =:= 70 ; /* F */ Character_code =:= 76 ; /* L */ Character_code =:= 85 ; /* U */ Character_code =:= 102 ; /* f */ Character_code =:= 108 ; /* l */ Character_code =:= 117 ), /* u */ !. /*--------------------------------------------------------------------------- MANAGING COUNTERS ----------------------------------------------------------------------------*/ increment_counter( Counter_name ) :- retract( general_counters( Counter_name, Current_count ) ), !, New_count is Current_count + 1, asserta( general_counters( Counter_name, New_count ) ), !. increment_counter( Counter_name ) :- asserta( general_counters( Counter_name, 1 ) ), !. set_counter( Counter_name, Desired_value ) :- retract( general_counters( Counter_name, Current_count ) ), !, asserta( general_counters( Counter_name, Desired_value ) ), !. set_counter( Counter_name, Desired_value ) :- asserta( general_counters( Counter_name, Desired_value ) ), !. read_counter( Counter_name, Value_to_be_returned ) :- retract( general_counters( Counter_name, Current_count ) ), !, Value_to_be_returned = Current_count, asserta( general_counters( Counter_name, Current_count ) ), !. read_counter( Counter_name, Value_to_be_returned ) :- Value_to_be_returned is 0, !. counter_is_smaller( Counter_name, Suggested_counter_value ) :- retract( general_counters( Counter_name, Current_count ) ), !, (( Current_count < Suggested_counter_value, asserta( general_counters( Counter_name, Current_count )), ! ) ; ( asserta( general_counters( Counter_name, Current_count )), !, fail ) ). counter_is_greater( Counter_name, Suggested_counter_value ) :- retract( general_counters( Counter_name, Current_count ) ), !, (( Current_count > Suggested_counter_value, asserta( general_counters( Counter_name, Current_count )), ! ) ; ( asserta( general_counters( Counter_name, Current_count )), !, fail ) ). counter_is_smaller_or_equal( Counter_name, Suggested_counter_value ) :- retract( general_counters( Counter_name, Current_count ) ), !, (( Current_count =< Suggested_counter_value, asserta( general_counters( Counter_name, Current_count )), ! ) ; ( asserta( general_counters( Counter_name, Current_count )), !, fail ) ). counter_is_greater_or_equal( Counter_name, Suggested_counter_value ) :- retract( general_counters( Counter_name, Current_count ) ), !, (( Current_count >= Suggested_counter_value, asserta( general_counters( Counter_name, Current_count )), ! ) ; ( asserta( general_counters( Counter_name, Current_count )), !, fail ) ). counter_value_is( Counter_name, Suggested_counter_value ) :- retract( general_counters( Counter_name, Current_count ) ), !, (( Current_count =:= Suggested_counter_value, asserta( general_counters( Counter_name, Current_count )), ! ) ; ( asserta( general_counters( Counter_name, Current_count )), !, fail ) ). reset_counter( Counter_name ) :- retract( general_counters( Counter_name, Current_count ) ), !. reset_counter( Counter_name ) :- !. write_all_counters :- general_counters( Counter_name, Current_count ), write( Counter_name ), write( ' = ' ), write( Current_count ), nl, fail, !. write_all_counters :- !. write_counter( Counter_name ) :- retract( general_counters( Counter_name, Current_count ) ), !, write( Current_count ), asserta( general_counters( Counter_name, Current_count ) ), !. write_counter( Counter_name ) :- write( 'ERROR: Counter not found. ' ), !. /*--------------------------------------------------------------------------- LIST PROCESSING ----------------------------------------------------------------------------*/ append1( First_list, Second_list, Combined_list ) :- append( First_list, Second_list, Combined_list ), length( First_list, Length_of_the_first_list ), length( Second_list, Length_of_the_second_list ), Length_of_the_first_list > 0, Length_of_the_second_list > 0. append2( First_list, Second_list, Combined_list ) :- append( First_list, Second_list, Combined_list ), length( First_list, Length_of_the_first_list ), length( Second_list, Length_of_the_second_list ), Length_of_the_first_list > 1, Length_of_the_second_list > 1. append3( First_list, Second_list, Third_list, All_three_lists_combined ) :- append( First_list, Second_and_third_lists_combined, All_three_lists_combined ), append( Second_list, Third_list, Second_and_third_lists_combined ). append4( First_list, Second_list, Third_list, Fourth_list, All_four_lists_combined ) :- append( First_list, Second_to_fourth_lists_combined, All_four_lists_combined ), append3( Second_list, Third_list, Fourth_list, Second_to_fourth_lists_combined ). append5( First_list, Second_list, Third_list, Fourth_list, Fifth_list, All_five_lists_combined ) :- append( First_list, Second_to_fifth_lists_combined, All_five_lists_combined ), append4( Second_list, Third_list, Fourth_list, Fifth_list, Second_to_fifth_lists_combined ). /******* member(X,L) :- append(_,[X|_],L). delete(X,[],[]). delete(X,[X|L],M) :- !, delete(X,L,M). delete(X,[Y|L],[Y|M]) :- delete(X,L,M). reverse(L,R) :- reverse2(L,[],R). reverse2([],L,L) :- !. reverse2([X|L],R,S) :- reverse2(L,[X|R],S). ******/ first(X,[X|L]). last_element( [ Only_one_element ], Only_one_element ). last_element( [ First_element | Rest_of_list ], Last_element ) :- last_element( Rest_of_list, Last_element ). /*-------------------------------------------------------------------------- READING AND WRITING routines ---------------------------------------------------------------------------*/ user_answers_yes :- write( ' y/n ?'), read_a_line_as_list( [ First_character | _ ] ), !, ( First_character =:= 121 ; First_character =:= 89 ), !. read_a_line_as_string( String ) :- read_a_line_as_list( List ), name( String, List ), !. read_a_line_as_list( [ First_character | Rest_of_list ] ) :- \+ at_end_of_line, get0( First_character ), !, read_a_line_as_list( Rest_of_list ). read_a_line_as_list( [] ) :- get0( Line_ending_character ), !. read_one_line( The_line_as_string ) :- read_one_line_as_list( The_line_as_list ), atom_chars( The_line_as_string, The_line_as_list ), !. read_one_line_as_list( [] ) :- at_end_of_line, skip_line, !. read_one_line_as_list( [ First_character | Rest_of_characters ] ) :- get0( First_character ), !, read_one_line_as_list( Rest_of_characters ). read_lines_from_currently_open_file( [] ) :- at_end_of_file, !. read_lines_from_currently_open_file( [ First_line | Rest_of_lines ] ) :- read_one_line( First_line ), !, read_lines_from_currently_open_file( Rest_of_lines ). write_integer_right_aligned( Integer ) :- Integer > 9999, write( Integer ), !. write_integer_right_aligned( Integer ) :- Integer > 999, write( ' ' ), write( Integer ), !. write_integer_right_aligned( Integer ) :- Integer > 99, write( ' ' ), write( Integer ), !. write_integer_right_aligned( Integer ) :- Integer > 9, write( ' ' ), write( Integer ), !. write_integer_right_aligned( Integer ) :- write( ' ' ), write( Integer ), !. write_list_of_lines_in_currently_open_file( [ First_line | Rest_of_lines ] ):- write( First_line ), nl, !, write_list_of_lines_in_currently_open_file( Rest_of_lines ). write_list_of_lines_in_currently_open_file( [] ) :- !. write_name_candidate( [ First_word | Rest_of_words ] ) :- write( First_word ), (( Rest_of_words == [] ) ; ( write( '_' ), write_name_candidate( Rest_of_words ) )). write_name_candidate( [] ). /* Just to make the routine succeed always. */ write_numeric_list_and_truncate_it_if_necessary( List_of_numbers, Number_of_numbers_to_be_written ) :- length( List_of_numbers, Number_of_numbers_in_list ), Number_of_numbers_in_list > Number_of_numbers_to_be_written, append( List_to_be_written, List_to_be_discarded, List_of_numbers ), length( List_to_be_written, Length_of_list_to_be_written ), Length_of_list_to_be_written =:= Number_of_numbers_to_be_written, write( List_to_be_written ), write( ' etc.'), !. write_numeric_list_and_truncate_it_if_necessary( List_of_numbers, _ ) :- write( List_of_numbers ), !. write_with_trailing_spaces( String_to_be_written, Desired_length ) :- add_trailing_spaces_to_string( String_to_be_written, Desired_length, String_with_trailing_spaces ), write( String_with_trailing_spaces ), !. write_word_list( [ First_word | Rest_of_words ] ) :- write( First_word ), write_word_list( Rest_of_words ). write_word_list( [] ) :- nl, !.