PROCEDURE global_search_replace (str_or_pat, str2) ! This procedure performs a search through the current ! buffer and replaces a string or a pattern with a new string LOCAL src_range, replacement_count; ! Return to caller if string not found ON_ERROR msg_text := FAO ('Completed !UL replacement!%S', replacement_count); MESSAGE (msg_text); RETURN; ENDON_ERROR; replacement_count := 0; LOOP src_range := SEARCH (str_or_pat, FORWARD); ! Search returns a range if found ERASE (src_range); ! Remove first string POSITION (END_OF (src_range)); ! Move to right place COPY_TEXT (str2); ! Replace with second string replacement_count := replacement_count + 1; ENDLOOP; ENDPROCEDURE; ! global_search_replace PROCEDURE replace_spaces (find_opening, find_closing, replace_string) ! This procedure performs a search through the current ! buffer and replaces a count of spaces with actual spaces LOCAL src_range, close_range, count, number_of_spaces, space_index, text_count, replacement_count, search_pattern; ! Return to caller if string not found ON_ERROR msg_text := FAO ('Completed !UL replacement!%S', replacement_count); MESSAGE (msg_text); RETURN; ENDON_ERROR; replacement_count := 0; number_of_spaces := 0; LOOP search_pattern := find_opening + UNANCHOR + find_closing; src_range := SEARCH (search_pattern, FORWARD); ! Search returns a range if found text_count := SUBSTR (src_range, LENGTH(find_opening)+1, LENGTH(src_range) - LENGTH(find_closing)-2); ! MESSAGE(text_count); number_of_spaces := INT(text_count); ERASE (src_range); ! Remove first string POSITION (END_OF (src_range)); ! Move to right place space_index := 0; LOOP EXITIF space_index = number_of_spaces; COPY_TEXT (replace_string); space_index := space_index + 1; ENDLOOP; replacement_count := replacement_count + 1; ENDLOOP; ENDPROCEDURE; ! replace_spaces PROCEDURE replace_format_specifier (find_opening, replace_opening, find_closing, replace_closing) ! This procedure performs a search through the current ! buffer and replaces a string or a pattern with a new string LOCAL src_range, replacement_count; ! Return to caller if string not found ON_ERROR msg_text := FAO ('Completed !UL replacement!%S', replacement_count); MESSAGE (msg_text); RETURN; ENDON_ERROR; replacement_count := 0; LOOP start_range := SEARCH (find_opening, FORWARD); ERASE (start_range); ! Remove first string POSITION (END_OF (start_range)); ! Move to right place COPY_TEXT (replace_opening); ! Replace with second string end_range := SEARCH (find_closing, FORWARD); ERASE (end_range); POSITION (END_OF (end_range)); COPY_TEXT (replace_closing); replacement_count := replacement_count + 1; ENDLOOP; ENDPROCEDURE; ! replace_format_specifier ! Executable statements input_file := GET_INFO (COMMAND_LINE, "file_name"); my_output_file := GET_INFO (COMMAND_LINE, "output_file"); ! Open input file main_buffer:= CREATE_BUFFER ("main", input_file); POSITION (BEGINNING_OF (main_buffer)); MESSAGE("Replace pound sign"); other_sequence := ASCII(27) + "(<#"; global_search_replace(other_sequence, "£"); POSITION (BEGINNING_OF (main_buffer)); MESSAGE("Replace <"); other_sequence := "<"; global_search_replace(other_sequence, "<"); POSITION (BEGINNING_OF (main_buffer)); MESSAGE("Replace >"); other_sequence := ">"; global_search_replace(other_sequence, ">"); POSITION (BEGINNING_OF (main_buffer)); MESSAGE("Replace bold underline sequences"); ansi_bold_underline_open := ASCII(27) + "[1m" + ASCII(27) + "[4m"; ansi_end_formats := ASCII(27) + "[m" + ASCII(27) + "[m"; html_bold_underline_open := ""; html_bold_underline_close := ""; replace_format_specifier (ansi_bold_underline_open, html_bold_underline_open, ansi_end_formats, html_bold_underline_close); POSITION (BEGINNING_OF (main_buffer)); MESSAGE("Replace bold sequences"); ansi_bold_open := ASCII(27) + "[1m"; ansi_end_format := ASCII(27) + "[m"; html_bold_open := ""; html_bold_close := ""; replace_format_specifier (ansi_bold_open, html_bold_open, ansi_end_format, html_bold_close); POSITION (BEGINNING_OF (main_buffer)); MESSAGE("Replace underline sequences"); ansi_underline_open := ASCII(27) + "[4m"; html_underline_open := ""; html_underline_close := ""; replace_format_specifier (ansi_underline_open, html_underline_open, ansi_end_format, html_underline_close); POSITION (BEGINNING_OF (main_buffer)); MESSAGE("Replace end formats"); global_search_replace(ansi_end_format, ""); POSITION (BEGINNING_OF (main_buffer)); MESSAGE("Replace cursor moves"); ansi_cursor_forward_start := ASCII(27) + "["; ansi_cursor_forward_end := "C"; replace_spaces(ansi_cursor_forward_start, ansi_cursor_forward_end, " "); POSITION (BEGINNING_OF (main_buffer)); MESSAGE("Replace ESC-(B"); other_sequence := ASCII(27) + "(B"; global_search_replace(other_sequence, ""); POSITION (BEGINNING_OF (main_buffer)); MESSAGE("Replace footer headers"); other_sequence := ASCII(27) + "(0qqqqqqqqqq"; global_search_replace(other_sequence, "          "); POSITION (BEGINNING_OF (main_buffer)); MESSAGE("Remove CRs"); carriage_return := ASCII(13); global_search_replace(carriage_return, ""); POSITION (BEGINNING_OF (main_buffer)); MESSAGE("Replace LFs"); line_feed := ASCII(10); global_search_replace(line_feed, "
"); POSITION (BEGINNING_OF (main_buffer)); MESSAGE("Replace page breaks"); breaks := "


"; global_search_replace(breaks, "
"); POSITION (BEGINNING_OF (main_buffer)); MESSAGE("Replace HTML delimiters"); delimiter := "{|"; global_search_replace(delimiter, "<"); POSITION (BEGINNING_OF (main_buffer)); delimiter := "|}"; global_search_replace(delimiter, ">"); POSITION (BEGINNING_OF (main_buffer)); MESSAGE("Remove FFs"); char := ASCII(15); global_search_replace(char, ""); ! Write output file WRITE_FILE (main_buffer, my_output_file); QUIT;