comp.lang.ada
 help / color / mirror / Atom feed
From: kst@alsys.com (Keith Thompson @pulsar)
Subject: Re: I have a question...
Date: Sat, 15 Oct 1994 11:28:41 GMT
Date: 1994-10-15T11:28:41+00:00	[thread overview]
Message-ID: <Cxpp7u.JLz@alsys.com> (raw)
In-Reply-To: Cxn2FA.MsF@alsys.com

In <some article> Norman H. Cohen (ncohen@WATSON.IBM.COM)
> Indeed.  For example, a text editor may support commands to insert a
> given file in the current editing buffer, write all or part of the
> current editing buffer to a file, or open a new buffer and read some file
> into it.  It is a real pain if the user can't use symbols like ~ in such
> commands, so the editor ought to expand the file names in such commands.

Agreed.  The usual way to do this, I think, is for the program to
scan the user's input for special characters ('~', '*', etc.), and,
if it finds any, invoke a shell and feed the string to it.  The shell
to invoke is determined by the value of the environment variable $SHELL.

I've confirmed that vi under SunOS 5.3 (Solaris 2.3) and SunOS 4.1.3
(Solaris 1.whatever) actually does this.  I have my $SHELL set to point
to tcsh (an enhanced version of csh).  When I type

    :r ~/tmp

it invokes tcsh to expand it.  If I set $SHELL to /bin/sh, the same
command yields an error message:
    
    "~/tmp" No such file or directory

since /bin/sh doesn't do ~ expansion.

This seeming inconsistency is a good thing, IMHO; each user gets the same
kind of special character handling from vi as from his or her preferred
command shell.  Invoking a shell may seem expensive, but blinding speed
doesn't matter much when you're processing text from the user's keyboard.

It would be nice to have a predefined library function that does this
kind of expansion without actually invoking a shell; it could look at
$SHELL to determine what kind of expansion to do and/or take an optional
extra argument to tell it to mimic a specified shell.  Unfortunately,
this isn't predefined in Unix.  Given the POSIX/Ada interface, there's
no reason it couldn't be written in Ada.

To summarize:

If you can get all file names from the command line (where they will
already have been expanded by the shell with no effort on your part),
do so.  For example, if I forget to provide a file name on the command
line, I don't mind begin given a usage message and told to try again;
I don't need the program to prompt me for it.  Your mileage may vary.

If you need to provide expansion, invoke the user's shell to do it.
This is appropriate for interactive commands like text editors.
Don't bother doing your own ~ and environment variable expansion;
your probability of being totally consistent with the shell is small.

-- 
Keith Thompson (The_Other_Keith)  kst@alsys.com
TeleSoft^H^H^H^H^H^H^H^H Alsys, Inc.
10251 Vista Sorrento Parkway, Suite 300, San Diego, CA, USA, 92121-2718
/user/kst/.signature: I/O error (core dumped)



  parent reply	other threads:[~1994-10-15 11:28 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1994Oct07.034523.161470@zeus.aix.calpoly.edu>
     [not found] ` <SPIEGEL.94Oct10115716@moskau.bruessel.informatik.uni-stuttgart.de>
1994-10-12 17:33   ` I have a question David Emery
1994-10-14  1:21     ` Keith Thompson @pulsar
1994-10-14 16:46       ` Andre Spiegel
1994-10-14 14:16         ` David Emery
1994-10-14 21:32           ` Norman H. Cohen
1994-10-17 10:34             ` Ada programs in a UNIX environment (was Re: I have a question...) Andre Spiegel
1994-10-15 11:28       ` Keith Thompson @pulsar [this message]
1994-10-14  7:38     ` I have a question Henri Altarac
1994-10-14 21:25     ` Kevin Cline
1994-10-13 17:13 ` James A. Krzyzanowski
1994-10-13 15:29   ` David Emery
     [not found] <1994Oct07.034523.161470@zeus.aix>
1994-10-14 11:16 ` emery
1994-10-14 16:46 ` spiegel
1994-10-15 16:52 ` ncohen
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox