Path: utzoo!attcan!uunet!husc6!mailrus!cornell!uw-beaver!teknowledge-vaxc!sri-unix!quintus!ok From: ok@quintus.uucp (Richard A. O'Keefe) Newsgroups: comp.unix.wizards Subject: Re: End-of-file character (was script > mumble) Message-ID: <523@quintus.UUCP> Date: 12 Oct 88 02:18:34 GMT References: <4975@saturn.ucsc.edu> <503@quintus.UUCP> <1503@fireball.cs.vu.nl> Sender: news@quintus.UUCP Reply-To: ok@quintus.UUCP (Richard A. O'Keefe) Organization: Quintus Computer Systems, Inc. Lines: 36 In article <1503@fireball.cs.vu.nl> maart@cs.vu.nl (Maarten Litmaath) writes: >In article <503@quintus.UUCP> ok@quintus.UUCP (Richard A. O'Keefe) writes: >\... here's some source code: >[C source deleted] > >People, what happened to good old shell script programming? Well, it's very simple. I wanted my __C__ programs to be able to remind their users what to type to get an end-of-file. So I wrote a C function. The main() in that file was enclosed in #ifdef TEST, remember! (I have received some mail pointing out problems, esp. with System V.) >BSD: >sh -c 'stty all 2> /tmp/stty.$$; set `tail -1 /tmp/stty.$$`; > shift; shift; echo $9; /bin/rm /tmp/stty.$$' It is very easy to break this (took me 2 minutes), and in any case on the system I am using I get the answer "^Z/^[", which is wrong (it should be "^Z"). >SysV: >sh -c 'stty -a | sed -e "s/.*eof = \([^;]*\).*/\1/" -e q' It is also easy to break this (took me 5 minutes; I don't know SysV well). Forking off three programs (sh, stty, rm or sed) would be a very odd thing to do in a C program when you can get the same information with a few system calls. While we're on the subject, I have read the SVID termio(ba_env) section several times, and cannot tell whether there is any general way of disabling individual elements of c_cc[] or not. Setting c_cc[VEOL] to ASCII NUL appears to disable that feature. In DYNIX V3.0.12 NFS, SunOS 3.2, and UNIX System V/386 Release 3.0, setting c_cc[VKILL] to ASCII NUL merely makes ^@ the kill character. Does anyone know which elements of c_cc[] can be suppressed and which can't?