[comp.os.vms] A TPU question

u3369429@murdu.OZ (Michael Bednarek) (07/17/87)

After two days of try/error I would like to ask the net:

Using TPU (under VMS 4.5), does anybody know how to search for a TAB
within the current line?

Here is what I tried so far:

Procedure Check_Tabs
 On_Error
  Return;
 EndOn_Error
! The next 2 statements produce a syntax error. Why?
!s:=Search(ASCII(9) & Match(ASCII(13)),Forward);
!t:=ASCII(9) & Match(ASCII(13));
!s:=Search(t,Forward);
! So I had to settle for:
 TAB:=ASCII(9);
 CR:=ASCII(13);
 t:=TAB & Match(CR);
 s:=Search(t,Forward);	! Never finds it. Exit due to Error-trap.
 If s=0 then Return; Endif;
 Position(s);
EndProcedure;

I'm a bit confused by the various TPU data types. I would like to do:
s:=Search(ASCII(9) & Match(Line_End),Forward);
but Line_End returns a pattern, whereas Match requires a string.

I want to avoid to move through the whole buffer and look at every character
(Is_Tab:=Current_Character=ASCII(9);) when most of the characters are not TABs.

It seems that none of the SYS$LIBRARY:*.TPU files ever uses MATCH.
Is that significant? Is MATCH broken?

Can anyone help?

Michael Bednarek		u3369429@{murdu.oz.au | ucsvc.dn.mu.oz.au}
Institute of Applied Economic   ...{seismo.CSS.GOV | UUNET.UU.NET}!munnari!
  and Social Research (IAESR)	   {murdu.oz | ucsvc.dn.mu.oz}!u3369429
Melbourne University		mb@munnari.oz.au
Parkville 3052, Phone : +61 3 344 5744
AUSTRALIA

"POST NO BILLS."

TOLLIVER%ORN.MFENET@NMFECC.ARPA (07/20/87)

Michael Bednarek writes...

>       Using TPU (under VMS 4.5), does anybody know how to search for a TAB
>       within the current line?
>
>       ! The next 2 statements produce a syntax error. Why?
>       !s:=Search(ASCII(9) & Match(ASCII(13)),Forward);
>       !t:=ASCII(9) & Match(ASCII(13));

Don't know.  But for some reason MATCH wants a STRING or a variable representing
a string and ASCII doesn't count.  Weird...

>       ! So I had to settle for:
>        TAB:=ASCII(9);
>        CR:=ASCII(13);
>        t:=TAB & Match(CR);
>        s:=Search(t,Forward);  ! Never finds it. Exit due to Error-trap.
>        If s=0 then Return; Endif;

This won't work because it is looking for a CR (i.e., ascii(13)) character.
Normally, there aren't any such characters in VMS text files although you
press the RETURN key to end a line.  But there are what TPU calls end-of-line
conditions.  These are matched by the LINE_END built-in.

>       I'm a bit confused by the various TPU data types. I would like to do:
>       s:=Search(ASCII(9) & Match(Line_End),Forward);
>       but Line_End returns a pattern, whereas Match requires a string.

This *might* have worked--if only MATCH took patterns.  But it doesn't, as
you point out.

>       It seems that none of the SYS$LIBRARY:*.TPU files ever uses MATCH.
>       Is that significant? Is MATCH broken?

I don't think so.  See example below.  But there are known problems with
TPU's pattern matching built-ins.  They are supposed to be fixed in the
next release...

To search for some character string in the current line only, combine the
ANCHOR built-in with MATCH.  I have modified your Check_Tabs procedure
below to do this.

Procedure Check_Tabs
local saved_pos, tab, s;
On_Error
! Trap error message
EndOn_Error
saved_pos := mark (none);
position (-current_offset);
TAB := ASCII(9);
s := search (anchor & match (tab), forward);
! You may also put in an actual TAB character in quotes as the argument
! to MATCH as follows:
!s := search (anchor & match (" "), forward);
! But beware some mailers convert tabs to spaces so that may not be a REAL
! tab in the preceeding line after going through the network(s).
If s=0 then
    position (saved_pos);
    message ("No TAB found in current line.");
else
    position (end_of (s));
    message ("Positioned to beginning of first TAB found in line.");
endif;
EndProcedure;

John Tolliver   (Tolliver%orn.mfenet@nmfecc.arpa)

Now, can someone tell me how to get the latest and greatest SWING sources?
Where is comp.sources.misc?  The last time I looked where I thought it was,
SEISMO.CSS.GOV, I could find no comp.sources.misc.