[comp.sys.mac.programmer] MPW cmd language

tom@unicads.UUCP (Tom Gerardy) (06/22/89)

I am trying to put up ctags and a vi/tags like facility in MPW (actually
it is already working.)  The output of the tag tool is a string of MPW
commands to open the file and find the search string.  Is there a way
to feed this directly to the shell?  I tried using command substitution
on the whole line, but MPW seems to have already decided that there is
only one command and trys to open all the other words on the line!
Currently I am having to write the output to a file and execute it as
a script.  This seems to slow things down considerably since both "open"
and "find" are builtins.

I _have_ RTFM a considerable amount although I only upgraded to 3.0 very
recently so I might concievably have missed _something_ :-)  The short
part of the manual that describes what order the shell expands things in
is slightly ambiguous.  It describes tokenization as happening after
command substitution with a note about ';' and such characters at that
point.  However, it seems as if the ';'s have already been processed before
command substitutuion.  Are they really snarfed as part of the control
structures step?

Any help or suggestions would be appreciated greatly.  BTW I will try to
figure out how to ship this stuff to mac sources/binaries after I've played
just a little more to get the bugs out... I assume there would be some
interest?

	-tom-

-- 
   - Tom Gerardy             UUCP: ...!sun!sunpeaks!unicads!tom
     UNICAD, Inc.              or: ...!ncar!{sunpeaks|boulder}!unicads!tom
     1695 38th Street
     Boulder, Colo.  80301         (303) 443-6961

rmh@apple.com (Rick Holzgrafe) (06/23/89)

In article <495@unicads.UUCP> tom@unicads.UUCP (Tom Gerardy) writes:
> I am trying to put up ctags and a vi/tags like facility in MPW (actually
> it is already working.) 

It never rains but it pours... I and some friends also have a ctags for 
MPW, which we hope to release Real Soon Now, perhaps within a couple of 
days. It's very complete (produces roughly 7000 tags for {CIncludes}, for 
example) and very fast (about three seconds to access any tag out of that 
7000, on a Mac II) and easy to use (double-click a word, select "Find
Tag" from a menu).

But there's plenty of room for competition - we all win. Tom, send me an 
example of the output of your tag tool; I'll show you what ours is like 
and how we solved the problem.
 
==========================================================================
Rick Holzgrafe              |    {sun,voder,nsc,mtxinu,dual}!apple!rmh
Software Engineer           | AppleLink HOLZGRAFE1          rmh@apple.com
Apple Computer, Inc.        |  "All opinions expressed are mine, and do
20525 Mariani Ave. MS: 27-O |    not necessarily represent those of my
Cupertino, CA 95014         |        employer, Apple Computer Inc."

norbert@iraul1.ira.uka.de (Norbert Lindenberg) (06/27/89)

In article <495@unicads.UUCP> tom@unicads.UUCP (Tom Gerardy) writes:
>I am trying to put up ctags and a vi/tags like facility in MPW (actually
>it is already working.)  The output of the tag tool is a string of MPW
>commands to open the file and find the search string.
>...
>Currently I am having to write the output to a file and execute it as
>a script.  This seems to slow things down considerably since both "open"
>and "find" are builtins.

I developed a similar package for MPW Pascal some time ago
(LookupDeclaration, available from the info-mac archives),
and also could not find a better way. Probably there is none...

-- Norbert

rmh@apple.com (Rick Holzgrafe) (06/29/89)

In article <919@iraun1.ira.uka.de> norbert@iraul1.ira.uka.de (Norbert 
Lindenberg) writes:
> In article <495@unicads.UUCP> tom@unicads.UUCP (Tom Gerardy) writes:
> > [...]  The output of the tag tool is a string of MPW
> >commands to open the file and find the search string.
> >...
> >Currently I am having to write the output to a file and execute it as
> >a script.  This seems to slow things down considerably [...]
> 
> I [...] also could not find a better way. Probably there is none...

Here's how:

AddMenu Find "Find Tag/E" \
    'Set Exit 0; \
    alias doit "`Findtag -a >> {WorkSheet}`";  \
    (doit) > Dev:Null; \
    Set Exit 1;'

(Use option-d for backslash, and option-> for >.)

You can't simply execute `Findtag -a >> {WorkSheet}` directly, because the 
Shell will take the semicolons in the output literally, rather than as 
command separators. But it will handle them correctly when it executes the 
alias.

This method requires an extra layer of insulation on characters special to 
the shell, since escaped characters must survive both the assignment to 
the alias and the execution of the alias. E.g. To find a left-square bracket,
Find /\[/ isn't enough; you must use Find /\\\[/ so that the [ and one of
the backslashes (option-d's) survives the alias assignment.

Clear as mud? :-)


==========================================================================
Rick Holzgrafe              |    {sun,voder,nsc,mtxinu,dual}!apple!rmh
Software Engineer           | AppleLink HOLZGRAFE1          rmh@apple.com
Apple Computer, Inc.        |  "All opinions expressed are mine, and do
20525 Mariani Ave. MS: 27-O |    not necessarily represent those of my
Cupertino, CA 95014         |        employer, Apple Computer Inc."

mitch@Apple.COM (Mitchell Adler) (06/29/89)

In article <919@iraun1.ira.uka.de> norbert@ira.uka.de (Norbert Lindenberg) writes:
>In article <495@unicads.UUCP> tom@unicads.UUCP (Tom Gerardy) writes:
>>I am trying to put up ctags and a vi/tags like facility in MPW (actually
>>it is already working.)  The output of the tag tool is a string of MPW
>>commands to open the file and find the search string.
>>...
>>Currently I am having to write the output to a file and execute it as
>>a script.  This seems to slow things down considerably since both "open"
>>and "find" are builtins.
>I developed a similar package for MPW Pascal some time ago
>(LookupDeclaration, available from the info-mac archives),
>and also could not find a better way. Probably there is none...

There is a different way, but depending on the complexity of the
script producing the script to execute, it is a little messy...

The trick is to use back-quotes (`) to put your standard output on the command
line. If it happens that your output is executable, it will be executed, i.e.

`getListItem 'files -l' files; files -t TEXT`

will let you choose the command to execute on all the text files in the current
directory. Since back-quotes just put text on the command lines, that text can
be anything you want it to be, even a command (or series of commands) to
execute.

One thing to rember is that the syntax for back-quotes allows *any* script to
be executed (even looping structures, begin/ends and the like), BUT the whole
script must be on one "line", that is there must be no carriage returns between
the start and end back-quotes that aren't masked with option-d's.

Not having cirrage returns means adding semi-colons between all your commands,
more dirt, it can get really messy, but sometimes it is truly elegant.

And the final problem is that you are already inside a set of back-quotes so
if any of your commands need to use back-quotes in their command lines, you
need to escape them (with option-d).

In my experience it is valuable to use this trick whenever it will help you
avoid creating a temporary file without adding more than 20 option-d's :-).

For those real purists out there, this trick won't avoid creating a file, MPW
uses temporary files to do back-quoting, but it does put the problem of naming
and deleting the temprary file back in MPW's hands (where it should be).


Mitch Adler                      "Hamper? ... I have a Hamper?"
Apple Computer                                    - Dr. Peter Venkman

mitch@apple.com                  "Prepare for jump to...ludicrous speed!"
AppleLink: M.ADLER                                - Dark Helmet

leeke@m2.csc.ti.com (Steve Leeke) (06/30/89)

In article <495@unicads.UUCP> tom@unicads.UUCP (Tom Gerardy) writes:
>I am trying to put up ctags and a vi/tags like facility in MPW (actually
>it is already working.)  The output of the tag tool is a string of MPW
>commands to open the file and find the search string.
>...
>Currently I am having to write the output to a file and execute it as
>a script.  This seems to slow things down considerably since both "open"
>and "find" are builtins.


Tom:

I didn't see the original article and I don't know how to use UUCP
from here so I hope you read this.  I'd like to get a copy of your
scripts for C if they are available.  Eventually I'd like to
find/write scripts for C++.

Thanks,

Steve