[comp.os.vms] Just what you always wanted

MSIEWEKE@GTRI01.BITNET (Mike Sieweke) (02/11/88)

Hi, all you TPU/EDT emulator fans.  Haven't you always wished you could
search for control characters like in good old EDT?  Don't you wish you
could search for an end-of-line?  Well now you can (or very soon).

I have broken down and written a TPU procedure that replaces the EDT
search function (gold-pf3) and works like good old EDT.  Best of all,
you don't have to learn about TPU patterns to be ablt to use it.
It has been in testing for one whole day, so I want to test it a while
longer (say a week).

If you know of anyone who has already written such a beast, let me know
and I will try to incorporate the best of both our procedures before
posting.

Mike Sieweke <msieweke@gtri01>             BitNet
          or <msieweke@gtri01.gatech.edu>  ArpaNet
Georgia Tech Research Institute
Atlanta, Georgia

MSIEWEKE@GTRI01.BITNET (Mike Sieweke) (03/10/88)

I sent this once before, but it didn't make it to any info-vax site
to which I had access.
----------------------------Original message----------------------------
Hi all you EDT emulator fans!  Don't you wish you had a search function
like good old EDT?   Well now you do.

What follows are 3 TPU procedures that work to give you EDT-style searching.
This means you can search for control characters and end-of-lines.  To use
it, just put it in your editor initialization file.  I probably should
have used vms_shar to package it, but I can't seem to locate vms_shar just
this minute.  If anyone has problems with this posting, please send me a
note, and I will try my best to get you a good copy.

These procedures work with the EDT emulator, but they could be easily
modified to work with EVE.

Call this file EDTINI.TPU.  Then invoke it with the command:
$ edit/tpu/section=edtsecini/command=edtini

===========cut here==================
!This note and all procedures within
!Copyright 1988 (c) Michael A. Sieweke, Georgia Tech Research Institute
!All rights reserved
!
!This note and all procedures within may be copied and distributed freely
!with the restriction that no one may sell it/them.  Please give it/them
!to your friends.  If you make any modifications, I ask that you send them
!to me so I can keep track of them and eliminate duplication of effort.
!My address is at the end of this posting.
procedure mas_ord( ch )
local
  key_val;

  key_val := key_name( ch ) /256;            ! chop off lower byte
  key_val := key_val - (256*(key_val/256));  ! isolate lower byte
  mas_ord:=key_val;
endprocedure;

! This procedure will create a special window for prompting for search
! string input.  This window will overlay the prompt line(s) on the screen.
procedure mas_prompt
local prompt_line,
      prompt_length,
      curwin;
  curwin := current_window;
  prompt_line := get_info( screen, "prompt_row" );
  prompt_length := get_info( screen, "prompt_length" );
  mas_prompt_window := create_window( prompt_line, prompt_length, off );
  mas_prompt_buffer := create_buffer( "mas_prompt_buffer" );
  set( eob_text, mas_prompt_buffer, "" );
  set( no_write, mas_prompt_buffer );
  position( curwin );
endprocedure;

! This procedure will allow searching for control characters.
! It should completely emulate searching in EDT.
procedure mas_search
local count,
      cr_pos,
      curwin,
      curbuf,
      keyin,
      keyord,
      new_search_string,
      quote_pos,
      search_string;
  mas_cr := ascii(13);
  mas_cr_eof := anchor&""&(line_end|mas_cr);
  map( mas_prompt_window, mas_prompt_buffer );
  search_string := "";
  curwin := current_window;
  curbuf := current_buffer;
  position( mas_prompt_window );
  erase( mas_prompt_buffer );
  copy_text( "Search for: " );
  loop
    update( mas_prompt_window );
    keyin := read_key;
    keyord := mas_ord( keyin );
    if key_name( ascii( keyord)) = keyin then        ! standard ascii character
      search_string := search_string + ascii( keyord );
      if keyord < 32 then
        copy_text( "^" + ascii( keyord+64 ));
      else if keyord < 127 then
        copy_text( ascii( keyord ));
      else if keyord = 127 then
        if length( search_string ) > 1 then
          search_string := substr( search_string, 1, length(search_string)-1 );
          if mas_ord( substr( search_string, length(search_string), 1)) <32 then
            edt$rubout;
          endif;
          search_string := substr( search_string, 1, length(search_string)-1 );
          edt$rubout;
        else
          search_string := "";
        endif;
      endif; endif; endif;
    else                      ! any function key will break out of input
      if keyord = 27 then     ! escape looks like a function key
        search_string := search_string + ascii( 27 );
        copy_text( "^[" );
      else
        if keyin = kp5 then
          set( reverse, curbuf );
        else if keyin = kp4 then
          set( forward, curbuf );
        endif; endif;
        exitif 1;
      endif;
    endif;
  endloop;
  count := 1;
  new_search_string := "";
  loop
    cr_pos := index( search_string, ascii(13) );
    exitif cr_pos = 0;
    if count = 1 then
      loop
        quote_pos := index( search_string, '"' );
        exitif quote_pos = 0;
        new_search_string := new_search_string +
                             substr( search_string, 1, quote_pos-1 ) +
                             '"&''"''&"';
        search_string := substr( search_string, quote_pos+1, 65535 );
      endloop;
      if search_string <> "" then
        new_search_string := new_search_string + search_string;
      endif;
      search_string := new_search_string;
      cr_pos := index( search_string, ascii(13) );
      new_search_string := '""';
    endif;
    if cr_pos = 1 then
      new_search_string := new_search_string + '&' +
                           "mas_cr_eof";
    else
      new_search_string := new_search_string + '&"' +
                           substr( search_string, 1, cr_pos-1 ) + '"&' +
                           "mas_cr_eof";
    endif;
    ! 65535 is the longest possible string length
    search_string := substr( search_string, cr_pos+1, 65535 );
    count := count + 1;
  endloop;
  if (count > 1) and (search_string <> "") then
    new_search_string := new_search_string + '&"' +
                         substr( search_string, 1, 65535 ) + '"';
  endif;
  position( curwin );
  unmap( mas_prompt_window );
  if new_search_string <> "" then
    execute( "edt$x_search_string := "+ new_search_string );
  else
    if search_string = "" then
      return;
    else
      edt$x_search_string := search_string;
    endif;
  endif;
  edt$search_next;
endprocedure;

define_key( "mas_search", key_name( pf3, shift_key ));
mas_prompt;

!Mike Sieweke <msieweke@gtri01>             BitNet
!          or <msieweke@gtri01.gatech.edu>  ArpaNet
!Georgia Tech Research Institute
!Atlanta, Georgia 30332
! I can also be reached via a friend's Unix account:
! ..."akgua, allegra, amd, harpo, hplabs,
!     ihnp4, masscomp, ut-ngp, rlgvax, sb1,
!     uf-cgrl, unmvax, ut-sally"  !gatech!gitpyr!tynor