From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=BAYES_00,INVALID_DATE autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,447a948bb64464c3 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1994-10-15 06:38:39 PST Newsgroups: comp.lang.ada Path: bga.com!news.sprintlink.net!howland.reston.ans.net!pipex!uunet!telesoft!kst From: kst@alsys.com (Keith Thompson @pulsar) Subject: Re: I have a question... Message-ID: Sender: news@alsys.com (USENET News Admin @flash) Organization: Alsys Group, San Diego, CA, USA References: <1994Oct07.034523.161470@zeus.aix.calpoly.edu> Date: Sat, 15 Oct 1994 11:28:41 GMT Date: 1994-10-15T11:28:41+00:00 List-Id: In 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)