Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!mnetor!uunet!seismo!husc6!think!ames!ucbcad!ucbvax!NMFECC.ARPA!TOLLIVER%ORN.MFENET
From: TOLLIVER%ORN.MFENET@NMFECC.ARPA
Newsgroups: comp.os.vms
Subject: RE: A TPU question (MATCH)
Message-ID: <870720080533.044@nmfecc.arpa>
Date: Mon, 20-Jul-87 11:05:33 EDT
Article-I.D.: nmfecc.870720080533.044
Posted: Mon Jul 20 11:05:33 1987
Date-Received: Wed, 22-Jul-87 04:07:58 EDT
Sender: daemon@ucbvax.BERKELEY.EDU
Distribution: world
Organization: The ARPA Internet
Lines: 70

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.