!******************************************************************************* ! ! WGBTPU.TPU - TPU initialization file to create extended EDT ! emulator for TPU. Some of these functions are ! borrowed from EVE, EVEPLUS, and DSIN; others are ! WGB originals. ! ! Author: Geoff Bryant 9/16/85 ! ! Created functions to do split screen editting, my own ! help key, centering of text on lines, and learn keys. ! !******************************************************************************* ! ! MODIFICATIONS: ! ! V1.700 2/01/88 Geoff Bryant 1) Fix small bug in BOX CUT/PASTE ! 2) Change center line to use screen ! width instead of buffer margins. ! For normal 80 column screen, no ! change, but for 132, you get what ! is visually expected. ! 3) Clean up some messages ! 4) Disable bells on broadcast too, until ! DEC fixes the bug. ! 5) Make two window code use screen width ! V1.601 1/29/88 Geoff Bryant Fix small problem with GOLD Y ! V1.600 1/29/88 Geoff Bryant 1) Add GOLD Y to display graphics chars ! without translation. ! 2) Add GOLD O to toggle overstrike. ! V1.500 1/29/88 Geoff Bryant 1) Add message to GOLD B to show state. ! 2) Disable bells on messages; TPU bug ! causes cursor to go out of buffer on ! display. Also causes problems with ! callable TPU on VAXstation. ! 3) Add message to GOLD X to show state. ! V1.404 9/11/86 Geoff Bryant Fix a bug in GOLD Z, and add shifting ! left and right for long messages. ! V1.403 9/10/86 Geoff Bryant Fix GOLD T. ! V1.402 9/09/86 Geoff Bryant Modify GOLD CTRL/B so that if a file ! isn't specified, the reference buffer ! from the last GOLD CTRL/B is used. ! V1.401 8/13/86 Geoff Bryant Add message buffer display. ! V1.400 8/01/86 Geoff Bryant Fix things to work with VMS 4.4. ! V1.302 6/10/86 Geoff Bryant 1) Fix infinite loop bug in GOLD J ! 2) Add back door to GOLD J for JJK ! to reset the defaults. ! V1.301 5/27/86 Geoff Bryant Make ctrl/g handle multiple postions. ! Need to use GOLD M,G instead of CTRL/G ! and GOLD CTRL/G. ! V1.300 5/27/86 Geoff Bryant 1) Add set/goto mark ! 2) Add goto line ! V1.200 5/21/86 Geoff Bryant Change the up and down arrow keys ! to handle tabs better. ! V1.110 5/16/86 Geoff Bryant Added Selected substitute ! V1.109 4/11/86 Geoff Bryant Improved HELP to use library ! V1.108 4/10/86 Geoff Bryant Added set case ! V1.107 4/10/86 Geoff Bryant 1) Made word def init. explicit ! 2) Added buffer trimming ! V1.106 4/09/86 Geoff Bryant 1) Modified control char translation ! to add single char display ! 2) Added line info command ! 3) Added tab/space conversion ! 4) Added Box CUT/PASTE ! V1.105 4/09/86 Geoff Bryant Added word definition toggle ! V1.104 1/31/86 Geoff Bryant Added ruler key ! V1.103 12/12/85 Geoff Bryant Added control char display ! V1.102 12/11/85 Geoff Bryant Made help use SYS$HELP ! V1.101 11/15/85 Geoff Bryant Set bell for mail and timer ! V1.100 9/24/85 Geoff Bryant Added window size adjusting ! V1.001 9/24/85 Geoff Bryant Fixed scrolling in split screens ! !******************************************************************************* ! ! VERSION: ! procedure wgb$version wgb$x_version := 'V1.700'; message('TPU Version V'+str(get_info(system,'version'))+'.'+ str(get_info(system,'update'))); message('Extended EDT Keypad Emulator Version ' + wgb$x_version); endprocedure ! !******************************************************************************* ! ! PROCEDURES: ! ! WGB$VERSION - Display the current version of APLTPU. ! EDT$MOTION - Improved handling of up/down arrow keys. ! WGB$DISPLAY_MESSAGE- Display the message buffer ! WGB$SET_MARK - Save the current position ! WGB$GOTO_MARK - Goto the saved position ! WGB$GOTO_LINE - Goto specified line ! WGB$JJK_SUBSTITUTE - Equivalent of line mode subs/string1/string2/select ! WGB$SET_CASE - Set case of selected case all upper/lower ! WGB$TRIM_BUFFER - Trim spaces/tabs from the end of all lines in file ! WGB$BOX_CUT - Does a CUT in box mode. ! WGB$BOX_PASTE - Box mode PASTE. ! WGB$BOX_SELECT - Box mode SELECT. ! WGB$TOGGLE_BOX... - Toggle between box/normal mode for SELECT/CUT/PASTE ! WGB$CONVERT_TABS - Convert between tabs and spaces ! WGB$WHAT_LINE - Display current line/column information ! WGB$RULER - Display a ruler in the message area ! WGB$WORD_TOGGLE - Toggle word definition EDT standard/WGB standard ! WGB$CENTER_LINE - Center current line on screen ! WGB$HELP - Gives the user some help ! WGB$START_LEARN - Start defining a key ! WGB$END_LEARN - Finish defining a key ! WGB$TWO_FILES - Two window editing with a reference file ! WGB$TWO_WINDOWS - Two window editing in the current file ! WGB$GOTO_WINDOW - Move between top/bottom window ! WGB$ADJUST_WINDOWS - Adjust the relative size of the two windows ! WGB$TRANSLATE_CON. - Translates control characters ! WGB$TOGGLE_GRAPHI. - Toggle graphic translation ! WGB$TOGGLE_OVERST. - Toggle insert/overstrike ! TPU$LOCAL_INIT - Procedure to define all of our keys and to ! - initialize variables. (Must be last) ! ! SUBROUTINES NEEDED FOR ABOVE PROCEDURES: ! ! WGB$READ_INTEGER - Get an integer from the user ! WGB$PAD_BLANK - Inserts a padding space if needed ! WGB$CURRENT_COLUMN - Convert current offset to current column ! WGB$BLANK_CHARS - Returns a string of n blanks ! WGB$REPLACE_TABS.. - Replace tabs w/ blanks and pad line ! WGB$INDENT_LINT_TO - Indent line to a specified column ! WGB$TO_COLUMN - Insert spaces from current column to specified col. ! WGB$ADD_CTRL_TEXT - Inserts text for a control character ! WGB$SEARCH_CONTROL - Searches quietly for a secified character ! WGB$DELETE_CONTROL - Replaces control Character text with the character ! WGB$DISPLAY_CHAR.. - Dispays in message area inf abot a character ! !******************************************************************************* !+ !EDT UP/DOWN cursor key motion EMULATION !- PROCEDURE edt$motion(which_way) LOCAL temp_col, last_col , new_col, eob, buf; buf := current_buffer; EOB:=end_of(buf); last_col := get_info(buf,'offset_column'); IF (last_col <> edt$x_prev_column) THEN edt$x_target_column := last_col; ENDIF; move_vertical(which_way); new_col := get_info(buf,'offset_column'); !+ ! Now get us as close to the target as possible !- IF new_col <> edt$x_target_column THEN IF new_col < edt$x_target_column THEN LOOP EXITIF mark(none) = EOB; EXITIF current_character = ''; EXITIF new_col >= edt$x_target_column; move_horizontal(1); temp_col := get_info(buf,'offset_column'); IF temp_col > edt$x_target_column THEN move_horizontal(-1); EXITIF ELSE new_col:=temp_col ENDIF; ENDLOOP; ELSE LOOP EXITIF current_offset = 0; EXITIF new_col <= edt$x_target_column; move_horizontal(-1); new_col := get_info(buf,'offset_column'); ENDLOOP; ENDIF; ENDIF; edt$x_prev_column := new_col; ENDPROCEDURE; ! ! WGB$DISPLAY_MESSAGES ! procedure wgb$display_messages local char_pos, shift_amount; shift_amount := 0; if get_info(show_msg_buffer,"type") = UNSPECIFIED then show_msg_buffer := create_buffer("MESSAGE DISPLAY"); set(eob_text,show_msg_buffer,edt$x_empty); set(no_write,show_msg_buffer); set(system,show_msg_buffer); endif; set(status_line,info_window,bold,' = Resume editing'); set(width,info_window,get_info(screen,'width')); map(info_window,show_msg_buffer); erase(show_msg_buffer); copy_text(message_buffer); position(beginning_of(current_buffer)); loop wgb$search_control(' ',char_pos); exitif char_pos = 0; position(char_pos); erase(char_pos); endloop; position(beginning_of(current_buffer)); loop wgb$search_control(' ',char_pos); exitif char_pos = 0; position(char_pos); erase(char_pos); split_line; endloop; update(info_window); loop wgb$x_learn_key := read_key; exitif wgb$x_learn_key = ret_key; if wgb$x_learn_key = up then edt$motion(-1) endif; if wgb$x_learn_key = down then edt$motion(1) endif; if wgb$x_learn_key = left then shift_amount := shift(current_window,40) endif; if wgb$x_learn_key = right then shift_amount := shift(current_window,-40) endif; update(info_window); endloop; if shift_amount <> 0 then shift(current_window,-shift_amount) endif; set(status_line,info_window,edt$x_info_stats_video, 'Press CTRL-F to remove INFO_WINDOW and resume editing'); unmap(info_window); endprocedure ! ! WGB$READ_INTEGER - Get an integer from the user ! procedure wgb$read_integer(number,default,prompt_string) local got_it,answer; got_it := 0; loop exitif got_it = 1; answer := read_line(fao("!AS : ",prompt_string,default)); edit(answer,trim); if answer = '' then number := default; got_it := 1; else number := int(answer); if (number = 0) and (answer <> '0') then message(fao('Invalid integer - !AS.',answer)); else got_it := 1; endif; endif; endloop; endprocedure ! ! WGB$SET_MARK - Mark the current position ! procedure wgb$set_mark case edt$x_repeat_count from 1 to 8 [1]: wgb$x_mark_position_1 := mark(none); [2]: wgb$x_mark_position_2 := mark(none); [3]: wgb$x_mark_position_3 := mark(none); [4]: wgb$x_mark_position_4 := mark(none); [5]: wgb$x_mark_position_5 := mark(none); [6]: wgb$x_mark_position_6 := mark(none); [7]: wgb$x_mark_position_7 := mark(none); [8]: wgb$x_mark_position_8 := mark(none); [outrange]: message('Invalid position number'); edt$x_repeat_count := 1; return; endcase; message(fao('Position !SL saved.',edt$x_repeat_count)); edt$x_repeat_count := 1; endprocedure ! ! WGB$GOTO_MARK - Goto the saved position ! procedure wgb$goto_mark local mark_pos, mark_buffer; case edt$x_repeat_count from 1 to 8 [1]: mark_pos := wgb$x_mark_position_1; [2]: mark_pos := wgb$x_mark_position_2; [3]: mark_pos := wgb$x_mark_position_3; [4]: mark_pos := wgb$x_mark_position_4; [5]: mark_pos := wgb$x_mark_position_5; [6]: mark_pos := wgb$x_mark_position_6; [7]: mark_pos := wgb$x_mark_position_7; [8]: mark_pos := wgb$x_mark_position_8; [outrange]: message('Invalid position number'); edt$x_repeat_count := 1; return; endcase; if mark_pos = 0 then message(fao('Position !SL has not been saved', edt$x_repeat_count)); edt$x_repeat_count := 1; return; endif; mark_buffer := get_info(mark_pos,"buffer"); if mark_buffer <> current_buffer then message('Must be in buffer '+ get_info(mark_buffer,"name")); edt$x_repeat_count := 1; return; endif; position(mark_pos); edt$x_repeat_count := 1; endprocedure ! ! WGB$GOTO_LINE- Goto specified line ! procedure wgb$goto_line wgb$read_integer(wgb$x_line_number,wgb$x_line_number, 'Line number'); position(beginning_of(current_buffer)); move_vertical(wgb$x_line_number-1); endprocedure ! ! WGB$JJK_SUBSTITUTE - Equivalent of line mode subs/string1/string2/select ! procedure wgb$jjk_substitute local msg_text, src_range, replacement_count; on_error msg_text := fao ('!UL replacement!%S', replacement_count) + ' of '+wgb$x_string1+' with '+wgb$x_string2; message(msg_text); edt$x_select_range := 0; return; endon_error; edt$select_range; if edt$x_select_range = 0 then message("Select not active"); return; endif; loop if wgb$x_string1 = edt$x_empty then wgb$x_string1 := read_line("Search for: "); else cmd := read_line("Search for <"+wgb$x_string1+">: "); if cmd <> edt$x_empty then wgb$x_string1 := cmd endif; endif; if wgb$x_string2 = edt$x_empty then wgb$x_string2 := read_line("Replace with: "); else cmd := read_line("Replace with <"+wgb$x_string2+">: "); if cmd <> edt$x_empty then wgb$x_string2 := cmd endif; endif; exitif (wgb$x_string1 <> wgb$x_string2); message('Search string matches replacement string'); wgb$x_string1 := edt$x_empty; wgb$x_string2 := edt$x_empty; endloop; replacement_count := 0; position(beginning_of(edt$x_select_range)); loop src_range := search(wgb$x_string1,forward); exitif (beginning_of(src_range) > end_of(edt$x_select_range)); erase(src_range); position(end_of(src_range)); copy_text(wgb$x_string2); replacement_count := replacement_count + 1; endloop; msg_text := fao ('!UL replacement!%S', replacement_count) + ' of '+wgb$x_string1+' with '+wgb$x_string2; message(msg_text); edt$x_select_range := 0; endprocedure ! ! WGB$SET_CASE - Set case of selected case all upper/lower ! procedure wgb$set_case local cmd; edt$select_range; if edt$x_select_range = 0 then message("Select not active"); return; endif; loop cmd := read_line("Upper or Lower [default = L]: "); if cmd = edt$x_empty then cmd := 'l' endif; edit(cmd,compress,lower); cmd := substr(cmd,1,1); exitif ((cmd = 'l') or (cmd = 'u')); message("Enter U or L"); endloop; if cmd = 'l' then change_case(edt$x_select_range,lower); else change_case(edt$x_select_range,upper); endif; edt$x_select_range := 0; endprocedure ! ! WGB$TRIM_BUFFER - Trim spaces/tabs from the end of all lines ! procedure wgb$trim_buffer local this_pos, trim_range, got_one; on_error if error = tpu$_strnotfound then trim_range := 0 endif; endon_error; this_pos := mark(none); loop got_one := 0; position(beginning_of(current_buffer)); loop trim_range := search(span(' ')&line_end,forward); exitif trim_range = 0; position(beginning_of(trim_range)); erase_character(length(trim_range)); got_one := 1; endloop; position(beginning_of(current_buffer)); loop trim_range := search(span(' ')&line_end,forward); exitif trim_range = 0; position(beginning_of(trim_range)); erase_character(length(trim_range)); got_one := 1; endloop; exitif got_one = 0; endloop; position(this_pos); endprocedure ! ! Subroutines for BOX CUT/SELECT/PASTE...... ! procedure wgb$pad_blank if (mark(none) = end_of(current_buffer)) then copy_text(' '); move_horizontal(-1); else if current_character = '' then copy_text(' '); move_horizontal(-1); endif; endif; endprocedure procedure wgb$current_column local i, line, col; line := current_line; if index(line,ascii(9)) = 0 then wgb$current_column := current_offset; else i := 1; col := 0; loop exitif i > current_offset; if substr(line,i,1) = ascii(9) then col := ((col + 8)/8)*8; else col := col + 1; endif; i := i + 1; endloop; wgb$current_column := col; endif; endprocedure procedure wgb$blank_chars(blank_count) local blank_chars, oldlen, blanks_so_far; if blank_count = 0 then return "" endif; blank_chars := " "; blanks_so_far := 1; loop exitif blanks_so_far >= blank_count; oldlen := length(blank_chars); blank_chars := blank_chars + blank_chars; blanks_so_far := blanks_so_far + oldlen; endloop; if blanks_so_far > blank_count then blank_chars := substr(blank_chars,1,blank_count) endif; return blank_chars; endprocedure procedure wgb$replace_tabs_with_blanks_and_pad(target_length) local i, col, cur_length, new_line, eight_blanks; if mark(none) <> end_of(current_buffer) then if index(current_line, ascii(9)) <> 0 then new_line := ''; eight_blanks := " "; i := 1; col := 0; loop exitif i > length(current_line); if substr(current_line,i,1) = ascii(9) then col := ((col + 8)/8)*8; new_line := new_line + substr(eight_blanks, 1,col-length(new_line)); else new_line := new_line + substr(current_line,i,1); col := col + 1; endif; i := i + 1; endloop; move_horizontal(-current_offset); copy_text(new_line); endif; endif; move_horizontal(-current_offset); if mark(none) = end_of(current_buffer) then cur_length := 0; else cur_length := length(current_line); endif; if cur_length < target_length then move_horizontal(cur_length); copy_text(wgb$blank_chars(target_length - cur_length)); endif; move_horizontal(-current_offset); endprocedure ! ! WGB$BOX_CUT - Does a CUT in box mode. ! procedure wgb$box_cut local saved_mode, end_select, end_column, start_column, temp, pad_chars, save_position, blank_chars, cut_text; if wgb$x_begin_select = 0 then message("Select not active"); return; endif; saved_mode := get_info(current_buffer,"mode"); set(insert,current_buffer); erase(paste_buffer); wgb$pad_blank; if (mark(none) >= wgb$x_begin_select) then end_select := mark(none); else end_select := wgb$x_begin_select; wgb$x_begin_select := mark(none); position(end_select); endif; end_column := wgb$current_column; position(wgb$x_begin_select); wgb$x_begin_select := mark(none); start_column := wgb$current_column; if start_column > end_column then temp := end_column; end_column := start_column; start_column := temp; endif; pad_chars := wgb$blank_chars(end_column - start_column + 1); move_horizontal(-current_offset); set(overstrike, current_buffer); loop exitif mark(none) > end_select; wgb$replace_tabs_with_blanks_and_pad(end_column + 1); cut_text := substr(current_line, start_column + 1, end_column - start_column + 1); move_horizontal(start_column); copy_text(pad_chars); save_position := mark(none); position(paste_buffer); copy_text(cut_text); move_horizontal(1); position(save_position); move_horizontal(-current_offset); move_vertical(1); endloop; position(wgb$x_begin_select); wgb$x_begin_select := 0; move_horizontal(-current_offset); move_horizontal(start_column); set(saved_mode,current_buffer); endprocedure ! ! WGB$BOX_PASTE - Box mode PASTE. ! procedure wgb$box_paste local save_position, start_column, paste_line, save_buffer, saved_mode; save_buffer := current_buffer; save_position := mark(none); start_column := wgb$current_column; saved_mode := get_info(current_buffer,"mode"); set(overstrike,current_buffer); position(beginning_of(paste_buffer)); if mark(none) = end_of(paste_buffer) then position(save_buffer); set(saved_mode,current_buffer); message("Paste buffer is empty"); return; endif; loop exitif mark(none) = end_of(paste_buffer); paste_line := current_line; move_vertical(1); position(save_buffer); wgb$replace_tabs_with_blanks_and_pad(start_column+1); move_horizontal(start_column); copy_text(paste_line); move_vertical(1); position(paste_buffer); endloop; position(save_position); move_horizontal(-current_offset); move_horizontal(start_column); set(saved_mode,current_buffer); endprocedure ! ! WGB$BOX_SELECT - Box mode SELECT. ! procedure wgb$box_select if wgb$x_begin_select = 0 then wgb$pad_blank; wgb$x_begin_select := mark(reverse); else message("Select already active"); endif; endprocedure ! ! WGB$TOGGLE_BOX_CUT_PASTE - Toggle between box/normal mode for ! SELECT/CUT/PASTE. ! procedure wgb$toggle_box_cut_paste edt$x_beginning_of_select := 0; edt$x_select_range := 0; wgb$x_begin_select := 0; if wgb$x_box_cut_paste = 1 then define_key("edt$select",period,"select"); define_key("edt$cut",kp6,"cut"); define_key("edt$paste",key_name(kp6,shift_key),"paste"); define_key("edt$select",E4,"select"); define_key("edt$cut",E3,"cut"); define_key("edt$paste",E2,"paste"); wgb$x_box_cut_paste := 0; message("SELECT/CUT/PASTE mode set to normal/EDT"); else define_key("wgb$box_select",period,"select"); define_key("wgb$box_cut",kp6,"cut"); define_key("wgb$box_paste",key_name(kp6,shift_key),"paste"); define_key("wgb$box_select",E4,"select"); define_key("wgb$box_cut",E3,"cut"); define_key("wgb$box_paste",E2,"paste"); wgb$x_box_cut_paste := 1; message("SELECT/CUT/PASTE mode set to BOX mode"); endif; endprocedure ! ! WGB$CONVERT_TABS - Convert between tabs and spaces ! procedure wgb$convert_tabs local cmd, cur_pos, i, t, m, n, p; edt$select_range; if edt$x_select_range = 0 then message("No Select Active"); return; endif; loop cmd := read_line("Spaces to tabs/Tabs to spaces [default = S]: "); if cmd = edt$x_empty then cmd := 's' endif; edit(cmd,compress,lower); cmd := substr(cmd,1,1); exitif ((cmd = 't') or (cmd = 's')); message("Enter S or T"); endloop; cur_pos := mark(none); position(beginning_of(edt$x_select_range)); if cmd = 's' then loop t := search(ascii(32),forward); exitif (t = 0); exitif (beginning_of(t) > end_of(edt$x_select_range)); position(beginning_of(t)); m := mark(none); p := get_info(m,"offset_column"); if ((8*(p/8)) = p) then i := 1; loop exitif (i = 8); move_horizontal(-1); exitif (current_character <> ' '); i := i + 1; endloop; if (i <> 8) then move_horizontal(1) endif; erase_character(i); copy_text(ascii(9)); else move_horizontal(1); endif; endloop; else loop t := search(ascii(9),forward); exitif (t = 0); exitif (beginning_of(t) > end_of(edt$x_select_range)); position(beginning_of(t)); erase_character(1); n := current_offset; n := n - (8 * (n / 8)); copy_text(substr(" ",1,8-n)); endloop; endif; edt$x_select_range := 0; position(cur_pos); endprocedure ! ! WGB$WHAT_LINE - Display information about the current line. ! procedure wgb$what_line local this_position, ! current position start_of_buffer, ! beginning of current buffer this_line_position, ! position at start of this_line total_lines, ! total lines in buffer high_line, ! high line limit for binary search low_line, ! low line limit for binary search this_line, ! line number of current guess percent; ! percent of way through buffer this_position := mark (none); start_of_buffer := beginning_of (current_buffer); total_lines := get_info (current_buffer, "record_count"); high_line := total_lines; if this_position = end_of (current_buffer) then low_line := total_lines; else low_line := 1; endif; loop exitif high_line - low_line <= 1; this_line := low_line + ((high_line - low_line) / 2); position (start_of_buffer); move_vertical (this_line - 1); if mark (none) > this_position then high_line := this_line; else low_line := this_line; if mark (none) = this_position then high_line := this_line; endif; endif; endloop; position (this_position); percent := (((low_line * 1000) / total_lines)+5)/10; this_line_position := wgb$current_column + 1; message (fao ("You are on line !SL out of !SL (!SL%), at column !SL.", low_line, total_lines, percent, this_line_position)); endprocedure ! ! WGB$RULER - Display a ruler in the message area ! procedure wgb$ruler message(" 1 2 3 4 5 6 7 8"); message("12345678901234567890123456789012345678901234567890123456789012345678901234567890"); endprocedure ! ! WGB$WORD_TOGGLE - Toggle between EDT default word definition ! and my word definition ! procedure wgb$word_toggle if wgb$x_current_word_definition = 1 then edt$x_word := " "; wgb$x_current_word_definition := 0; message("WORD definition set to normal/EDT"); else edt$x_word := " '!@#$%^&*()_-+=~`{[}]:;|\<,>.?"; wgb$x_current_word_definition := 1; message("WORD definition set to non-alphanumeric"); endif; endprocedure ! ! WGB$CENTER_LINE - Center current line on screen ! procedure wgb$center_line local this_position, count, left_margin, right_margin, width_of_screen, this_column; this_position := mark (none); if this_position = end_of (current_buffer) then return; endif; move_horizontal (- current_offset); loop exitif current_character = edt$x_empty; exitif index (wgb$x_whitespace, current_character) = 0; count := count + 1; move_horizontal (1); endloop; erase_character (- count); position (search (line_end, forward)); loop exitif current_offset = 0; move_horizontal (-1); exitif index (wgb$x_whitespace, current_character) = 0; erase_character (1); endloop; ! left_margin := get_info (current_buffer, "left_margin"); ! right_margin := get_info (current_buffer, "right_margin"); ! width_of_screen := get_info (screen, "width"); ! if right_margin > width_of_screen then ! right_margin := width_of_screen; ! endif; left_margin := 1; right_margin := get_info(current_window,"width"); this_column := get_info (current_buffer, "offset_column"); count := (((right_margin-left_margin)-this_column)/2)+left_margin; wgb$indent_line_to (count); position (this_position); endprocedure; ! ! Subroutines for CENTER TEXT ! procedure wgb$indent_line_to (which_column) local this_position, this_buffer; this_buffer := current_buffer; move_horizontal (- current_offset); loop exitif get_info (this_buffer, "offset_column") >= which_column; if (current_character = " ") or (current_character = ascii (9)) then move_horizontal (1); else exitif 1; endif; endloop; wgb$to_column (which_column); endprocedure; procedure wgb$to_column (which_column) local this_buffer, this_mode, distance; this_buffer := current_buffer; this_mode := get_info (this_buffer, "mode"); set (insert, this_buffer); loop distance := which_column - get_info (this_buffer, "offset_column"); exitif distance <= 0; if distance > length (wgb$x_spaces) then copy_text (wgb$x_spaces); else copy_text (substr (wgb$x_spaces, 1, distance)); endif; endloop; set (this_mode, this_buffer); endprocedure; ! ! WGB$HELP - The poor user wants to know how to use all this stuff! ! procedure wgb$help local time_string; if get_info(help_buffer,"type") = UNSPECIFIED then help_buffer := create_buffer("HELP"); set(eob_text,help_buffer,edt$x_empty); set(no_write,help_buffer); set(system,help_buffer); endif; set(status_line,info_window,bold, ' PF2 = Keypad diagram = Resume editing A = Help with APLTPU keys' ); set(width,info_window,get_info(screen,'width')); map(info_window,help_buffer); erase(help_buffer); read_file('sys$help:apltpu.hlp'); position(beginning_of(current_buffer)); update(info_window); loop wgb$x_learn_key := read_key; if wgb$x_learn_key = ctrl_f_key then unmap(info_window); return; endif; if wgb$x_learn_key = ret_key then unmap(info_window); return; endif; if wgb$x_learn_key = PF2 then edt$keypad_help; unmap(info_window); return; endif; if (wgb$x_learn_key = key_name('a')) or (wgb$x_learn_key = key_name('A')) then set(status_line,info_window,bold,edt$x_empty); help_text('apltpu','apltpu',on,help_buffer); unmap(info_window); return; endif; endloop; endprocedure ! ! WGB$START_LEARN - Begins a new key definition (learn sequence) ! procedure wgb$start_learn message ('Hit key to learn'); wgb$x_learn_key := read_key; message ('Enter the learn sequence (CTRL/R to end)'); learn_begin(exact); endprocedure ! ! WGB$END_LEARN - Ends a learn sequence and defines the key ! procedure wgb$end_learn on_error if error = tpu$_notlearning then message ("Nothing to remember"); return; else if error = tpu$_recurlearn then message("Recursive learn procedure"); return; endif; endif; endon_error; wgb$x_learn_sequence := learn_end; message ('End learn sequence'); define_key(wgb$x_learn_sequence,wgb$x_learn_key); endprocedure ! ! WGB$TWO_FILES - Two window editing with a reference file ! procedure wgb$two_files if wgb$x_number_of_windows = 1 then wgb$x_second_file := read_line("File name: "); if wgb$x_second_buffer <> "" then if wgb$x_second_file <> "" then delete(wgb$x_second_buffer); wgb$x_second_buffer := create_buffer("REFERENCE",wgb$x_second_file); endif; else if wgb$x_second_file = "" then return; endif; wgb$x_second_buffer := create_buffer("REFERENCE",wgb$x_second_file); endif; set(eob_text,wgb$x_second_buffer,"[End of REFERENCE]"); set(no_write,wgb$x_second_buffer,on); unmap(main_window); set(width,wgb$x_top_window,get_info(screen,'width')); map(wgb$x_top_window,wgb$x_second_buffer); update (wgb$x_top_window); set(width,wgb$x_bottom_window,get_info(screen,'width')); map(wgb$x_bottom_window,main_buffer); update (wgb$x_bottom_window); position (wgb$x_top_window); edt$x_section_distance := wgb$x_top_section; wgb$x_number_of_windows := 2; else wgb$x_second_file := read_line("File name: "); if wgb$x_second_file = "" then return; endif; if wgb$x_second_buffer <> "" then delete(wgb$x_second_buffer); endif; wgb$x_second_buffer := create_buffer("REFERENCE",wgb$x_second_file); set(eob_text,wgb$x_second_buffer,"[End of REFERENCE]"); set(no_write,wgb$x_second_buffer,on); set(width,wgb$x_top_window,get_info(screen,'width')); map(wgb$x_top_window,wgb$x_second_buffer); update (wgb$x_top_window); position (wgb$x_top_window); edt$x_section_distance := wgb$x_top_section; wgb$x_number_of_windows := 2; endif; endprocedure ! ! WGB$TWO_WINDOWS - Two window editing in the current file ! procedure wgb$two_windows if wgb$x_number_of_windows = 1 then unmap(main_window); set(width,wgb$x_top_window,get_info(screen,'width')); map(wgb$x_top_window,main_buffer); update (wgb$x_top_window); set(width,wgb$x_bottom_window,get_info(screen,'width')); map(wgb$x_bottom_window,main_buffer); update (wgb$x_bottom_window); edt$x_section_distance := wgb$x_bottom_section; wgb$x_number_of_windows := 2; else unmap(wgb$x_top_window); unmap(wgb$x_bottom_window); set(width,main_window,get_info(screen,'width')); map(main_window,main_buffer); update(main_window); edt$x_section_distance := wgb$x_edt_section; wgb$x_number_of_windows := 1; endif; endprocedure ! ! WGB$GOTO_WINDOW - Move between top/bottom window ! procedure wgb$goto_window (which_window) if wgb$x_number_of_windows = 2 then position(which_window); if which_window = wgb$x_top_window then edt$x_section_distance := wgb$x_top_section; else edt$x_section_distance := wgb$x_bottom_section; endif; endif; endprocedure ! ! WGB$ADJUST_WINDOWS - Adjust the relative size of the two windows ! procedure wgb$adjust_windows local asize, top_window_buffer, in_top; if wgb$x_number_of_windows = 2 then top_window_buffer := get_info(wgb$x_top_window,"buffer"); if current_window = wgb$x_top_window then in_top:=1; else in_top:=0; endif; loop asize := read_line("Enter the number of lines to adjust by: "); asize := int(asize); exitif ((wgb$x_top_size - asize) > 3) and ((wgb$x_bottom_size + asize) > 3); message("Illegal adjustment"); endloop; wgb$x_top_size := wgb$x_top_size - asize; wgb$x_bottom_size := wgb$x_bottom_size + asize; delete(wgb$x_top_window); delete(wgb$x_bottom_window); wgb$x_top_window := create_window (1,wgb$x_top_size,on); wgb$x_bottom_window := create_window (wgb$x_top_size+1, wgb$x_bottom_size,on); set(scrolling,wgb$x_top_window,on,1,1,0); set(scrolling,wgb$x_bottom_window,on,1,1,0); wgb$x_top_section := (wgb$x_top_size*3)/4; wgb$x_bottom_section := (wgb$x_bottom_size*3)/4; if in_top = wgb$x_top_window then edt$x_section_distance := wgb$x_top_section; else edt$x_section_distance := wgb$x_bottom_section; endif; map(wgb$x_top_window,top_window_buffer); map(wgb$x_bottom_window,main_buffer); if in_top then position(wgb$x_top_window); else position(wgb$x_bottom_window); endif; refresh; endif; endprocedure ! ! Subroutines for control character translation ! procedure wgb$add_ctrl_text(char) case char from '' to 'ÿ' ['']: copy_text(''); ['']: copy_text(''); ['']: copy_text(''); ['']: copy_text(''); ['']: copy_text(''); ['']: copy_text(''); ['']: copy_text(''); ['']: copy_text(''); ['']: copy_text(''); ['']: copy_text(''); ['']: copy_text(''); ['']: copy_text(''); ['']: copy_text(''); ['']: copy_text(''); ['']: copy_text(''); ['']: copy_text(''); ['']: copy_text(''); ['']: copy_text(''); ['']: copy_text(''); ['']: copy_text(''); ['']: copy_text(''); ['']: copy_text(''); ['']: copy_text(''); ['']: copy_text(''); ['']: copy_text(''); ['']: copy_text(''); ['']: copy_text(''); ['›']: copy_text(''); endcase; endprocedure procedure wgb$search_control(char,found) on_error found := 0; return; endon_error; found := search(char,forward,exact); endprocedure procedure wgb$delete_control local found,char_pos,old_message_flags; old_message_flags := get_info(system,"message_flags"); set(message_flags,0); loop found := 0; position(beginning_of(current_buffer)); wgb$search_control('',char_pos); if char_pos <> 0 then position(char_pos); erase(char_pos); copy_text(''); found := 1; endif; wgb$search_control('',char_pos); if char_pos <> 0 then position(char_pos); erase(char_pos); copy_text(''); found := 1; endif; wgb$search_control('',char_pos); if char_pos <> 0 then position(char_pos); erase(char_pos); copy_text(''); found := 1; endif; wgb$search_control('',char_pos); if char_pos <> 0 then position(char_pos); erase(char_pos); copy_text(''); found := 1; endif; wgb$search_control('',char_pos); if char_pos <> 0 then position(char_pos); erase(char_pos); copy_text(''); found := 1; endif; wgb$search_control('',char_pos); if char_pos <> 0 then position(char_pos); erase(char_pos); copy_text(''); found := 1; endif; wgb$search_control('',char_pos); if char_pos <> 0 then position(char_pos); erase(char_pos); copy_text(''); found := 1; endif; wgb$search_control('',char_pos); if char_pos <> 0 then position(char_pos); erase(char_pos); copy_text(''); found := 1; endif; wgb$search_control('',char_pos); if char_pos <> 0 then position(char_pos); erase(char_pos); copy_text(''); found := 1; endif; wgb$search_control('',char_pos); if char_pos <> 0 then position(char_pos); erase(char_pos); copy_text(''); found := 1; endif; wgb$search_control('',char_pos); if char_pos <> 0 then position(char_pos); erase(char_pos); copy_text(''); found := 1; endif; wgb$search_control('',char_pos); if char_pos <> 0 then position(char_pos); erase(char_pos); copy_text(''); found := 1; endif; wgb$search_control('',char_pos); if char_pos <> 0 then position(char_pos); erase(char_pos); copy_text(''); found := 1; endif; wgb$search_control('',char_pos); if char_pos <> 0 then position(char_pos); erase(char_pos); copy_text(''); found := 1; endif; wgb$search_control('',char_pos); if char_pos <> 0 then position(char_pos); erase(char_pos); copy_text(''); found := 1; endif; wgb$search_control('',char_pos); if char_pos <> 0 then position(char_pos); erase(char_pos); copy_text(''); found := 1; endif; wgb$search_control('',char_pos); if char_pos <> 0 then position(char_pos); erase(char_pos); copy_text(''); found := 1; endif; wgb$search_control('',char_pos); if char_pos <> 0 then position(char_pos); erase(char_pos); copy_text(''); found := 1; endif; wgb$search_control('',char_pos); if char_pos <> 0 then position(char_pos); erase(char_pos); copy_text(''); found := 1; endif; wgb$search_control('',char_pos); if char_pos <> 0 then position(char_pos); erase(char_pos); copy_text(''); found := 1; endif; wgb$search_control('',char_pos); if char_pos <> 0 then position(char_pos); erase(char_pos); copy_text(''); found := 1; endif; wgb$search_control('',char_pos); if char_pos <> 0 then position(char_pos); erase(char_pos); copy_text(''); found := 1; endif; wgb$search_control('',char_pos); if char_pos <> 0 then position(char_pos); erase(char_pos); copy_text(''); found := 1; endif; wgb$search_control('',char_pos); if char_pos <> 0 then position(char_pos); erase(char_pos); copy_text(''); found := 1; endif; wgb$search_control('',char_pos); if char_pos <> 0 then position(char_pos); erase(char_pos); copy_text(''); found := 1; endif; wgb$search_control('',char_pos); if char_pos <> 0 then position(char_pos); erase(char_pos); copy_text(''); found := 1; endif; wgb$search_control('',char_pos); if char_pos <> 0 then position(char_pos); erase(char_pos); copy_text(''); found := 1; endif; wgb$search_control('',char_pos); if char_pos <> 0 then position(char_pos); erase(char_pos); copy_text('›'); found := 1; endif; exitif (found = 0) endloop; set(message_flags,old_message_flags); endprocedure procedure wgb$display_character local i,cc,ac; if mark(none) = end_of(current_buffer) then message('At end of buffer, no current character'); return; endif; i := 0; loop; exitif i > 255; exitif current_character = ascii(i); i := i + 1; endloop; if i > 255 then i := 0 endif; if i < 32 then cc := ', ^' + ASCII(i+64); else cc := ''; endif; case current_character from '' to 'ÿ' ['']: ac := ''; ['']: ac := ''; ['']: ac := ''; ['']: ac := ''; ['']: ac := ''; ['']: ac := ''; ['']: ac := ''; ['']: ac := ''; ['']: ac := ''; ['']: ac := ''; ['']: ac := ''; ['']: ac := ''; ['']: ac := ''; ['']: ac := ''; ['']: ac := ''; ['']: ac := ''; ['']: ac := ''; ['']: ac := ''; ['']: ac := ''; ['']: ac := ''; ['']: ac := ''; ['']: ac := ''; ['']: ac := ''; ['']: ac := ''; ['']: ac := ''; ['']: ac := ''; ['']: ac := ''; ['›']: ac := ''; [INRANGE]: ac := current_character; [OUTRANGE]: ac := current_character; endcase; message(fao("Current Character is '!AS', Octal=!OB, Decimal=!-!UB, " + "Hex=!-!XB!AS", ac, i, cc ) ); endprocedure ! ! WGB$TRANSLATE_CONTROL - Translate/display control characters ! procedure wgb$translate_control local char,char_pos,cmd,ctrl_chars,disp_chars,displ_chars; on_error position(wgb$x_start_pos); return; endon_error; wgb$x_start_pos := mark (none); ctrl_chars := any('›'); loop cmd := read_line("ON/OFF/DISPLAY_ONE [default = display_one]: "); if cmd = edt$x_empty then cmd := 'display_one' endif; edit(cmd,compress,lower); exitif ((cmd = 'on') or (cmd = 'off') or (cmd = 'display_one')); message("Enter ON, OFF, or DISPLAY_ONE"); endloop; if cmd = 'on' then position(beginning_of(current_buffer)); loop char_pos := search(ctrl_chars,forward,exact); position(char_pos); char := current_character; wgb$add_ctrl_text(char); erase(char_pos); endloop; endif; if cmd = 'off' then wgb$delete_control; position(wgb$x_start_pos); endif; if cmd = 'display_one' then wgb$display_character; position(wgb$x_start_pos); endif; endprocedure ! ! WGB$TOGGLE_GRAPHICS - Toggle between normal translation of graphics characters ! and no_translate ! procedure wgb$toggle_graphics if get_info(current_window,"text") = NO_TRANSLATE then set(text,current_window,blank_tabs); message("Graphics translation set to normal/blank_tabs"); refresh; else set(text,current_window,no_translate); message("Graphics translation set to graphics/no_translate"); endif; endprocedure ! ! WGB$TOGGLE_OVERSTRIKE - Toggle between normal insert/overstrike in current ! buffer. ! procedure wgb$toggle_overstrike if get_info(current_buffer,"mode") = OVERSTRIKE then set(insert,current_buffer); message("Buffer set to insert mode"); else set(overstrike,current_buffer); message("Buffer set to overstrike mode"); endif; endprocedure ! ! TPU$LOCAL_INIT - Procedure to define all of our keys and to ! initialize variables ! procedure tpu$local_init local msize ; edt$x_target_column := 1; edt$x_prev_column := 1; wgb$x_line_number := 1; wgb$x_mark_position_1 := 0; wgb$x_mark_position_2 := 0; wgb$x_mark_position_3 := 0; wgb$x_mark_position_4 := 0; wgb$x_mark_position_5 := 0; wgb$x_mark_position_6 := 0; wgb$x_mark_position_7 := 0; wgb$x_mark_position_8 := 0; wgb$x_string1 := edt$x_empty; wgb$x_string2 := edt$x_empty; wgb$x_box_cut_paste := 0; wgb$x_edt_section := edt$x_section_distance; wgb$x_number_of_windows := 1; wgb$x_second_file := ""; wgb$x_second_buffer := ""; wgb$x_whitespace := " "; wgb$x_spaces := " "; wgb$x_current_word_definition := 1; edt$x_word := " '!@#$%^&*()_-+=~`{[}]:;|\<,>.?"; msize := get_info(main_window,"original_length"); wgb$x_top_size := msize/2; if ((msize/2)*2) = msize then wgb$x_bottom_size := msize/2; else wgb$x_bottom_size := msize/2+1; endif; wgb$x_top_window := create_window (1,wgb$x_top_size,on); wgb$x_bottom_window := create_window (wgb$x_top_size+1, wgb$x_bottom_size,on); set(scrolling,wgb$x_top_window,on,1,1,0); set(scrolling,wgb$x_bottom_window,on,1,1,0); wgb$x_top_section := (wgb$x_top_size*3)/4; wgb$x_bottom_section := (wgb$x_bottom_size*3)/4; define_key('wgb$start_learn',ctrl_k_key); define_key('wgb$end_learn',ctrl_r_key); define_key('wgb$goto_window(wgb$x_bottom_window)', key_name(down,shift_key)); define_key('wgb$goto_window(wgb$x_top_window)', key_name(up,shift_key)); define_key('wgb$adjust_windows',key_name("W",shift_key)); define_key('wgb$two_files',key_name(ctrl_b_key,shift_key)); define_key('wgb$two_windows',ctrl_b_key); define_key('wgb$center_line',key_name("C",shift_key)); define_key('wgb$translate_control',key_name("T",shift_key)); define_key('edt$command',do); define_key('wgb$help',pf2); define_key('wgb$version',key_name("V",shift_key)); define_key('wgb$ruler',key_name("R",shift_key)); define_key('wgb$word_toggle',key_name("X",shift_key)); define_key('wgb$what_line',key_name("Q",shift_key)); define_key('wgb$convert_tabs',key_name("S",shift_key)); define_key('wgb$toggle_box_cut_paste',key_name("B",shift_key)); define_key('wgb$trim_buffer',key_name("E",shift_key)); define_key('wgb$set_case',key_name("U",shift_key)); define_key('wgb$jjk_substitute',key_name("J",shift_key)); define_key('wgb$set_mark',key_name("M",shift_key)); define_key('wgb$goto_mark',key_name("G",shift_key)); define_key('wgb$goto_line',key_name("L",shift_key)); define_key('edt$motion(-1)',up); define_key('edt$motion(1)',down); define_key('wgb$display_messages',key_name("Z",shift_key)); define_key('wgb$toggle_graphics',key_name("Y",shift_key)); define_key('wgb$toggle_overstrike',key_name("O",shift_key)); !!!!! set(bell,all,on); set(timer,on," Working "); endprocedure save('sys$disk:[]apledtsecini'); quit;