diff --git a/contrib/tcsh/FAQ b/contrib/tcsh/FAQ index 92aadc726683..93773c52433a 100644 --- a/contrib/tcsh/FAQ +++ b/contrib/tcsh/FAQ @@ -1,304 +1,243 @@ + * Home + * FAQ + * Y2K + __________________________________________________________________ - [Home] FAQ +FAQ - Home | RecentChanges | Preferences - _________________________________________________________________ + For the people who do not read the manual! - This is for people who do not read the manual! + Why is the meta key broken in tcsh-5.20 and up? - So far people who don't read manuals don't read this either... I may - call it README.*PLEASE* in the future, but then the same people won't - be able to get ftp it... :-) - _________________________________________________________________ - - 1. Where can I find tcsh sources? - - See http://www.tcsh.org/MostRecentRelease for download locations. - _________________________________________________________________ - - 2. Why is the meta key broken in tcsh-5.20 and up? - - On some machines the tty is not set up to pass 8 bit characters by - default. Tcsh 5.19 used to try to determine if pass8 should be set by + On some machines the tty is not set up to pass 8 bit characters by + default. Tcsh 5.19 used to try to determine if pass8 should be set by looking at the terminal's meta key. Unfortunately there is no good way - of determining if the terminal can really pass 8 characters or not. - Consider if you are logged in through a modem line with 7 bits and - parity and your terminal has a meta key. Then tcsh 5.19 would set + of determining if the terminal can really pass 8 characters or not. + Consider if you are logged in through a modem line with 7 bits and + parity and your terminal has a meta key. Then tcsh 5.19 would set wrongly set pass8. - If you did like the previous behavior you can add in /etc/csh.login, - or in .login: - + If you did like the previous behavior you can add in /etc/csh.login, or + in .login: if ( $?tcsh && $?prompt ) then if ( "`echotc meta`" == "yes" ) then stty pass8 endif endif - If you don't have pass8, maybe one of these would work.. - + If you don't have pass8, maybe one of these would work: stty -parity -evenp -oddp cs8 -istrip (rs6000) stty -parenb -istrip cs8 - Finally, tcsh will bind all printable meta characters to the self - insert command. If you don't want that to happen (i.e. use the + Finally, tcsh will bind all printable meta characters to the self + insert command. If you don't want that to happen (i.e. use the printable meta characters for commands) setenv NOREBIND. - _________________________________________________________________ - 3. I ran 'dbxtool &' and 'shelltool &' from tcsh, and they end up in - cbreak and no echo mode? - - These programs are broken. Background jobs should not try to look at - the tty. What happens is that dbxtool looks in stderr to inherit the - tty setups, but tcsh sets up the tty in cbreak and -echo modes, so - that it can do line editing. This cannot be fixed because tcsh cannot - give away the tty. Pick one of the following as a workaround: + I ran dbxtool & and shelltool & from tcsh, and they end up in cbreak and no + echo mode? + These programs are broken. Background jobs should not try to look at + the tty. What happens is that dbxtool looks in stderr to inherit the + tty setups, but tcsh sets up the tty in cbreak and -echo modes, so that + it can do line editing. This cannot be fixed because tcsh cannot give + away the tty. Pick one of the following as a workaround: dbxtool < /dev/null >& /dev/null & /usr/etc/setsid dbxtool & - If that does not work, for dbxtool at least you can add "sh stty sane" - in your .dbxinit - _________________________________________________________________ + If that does not work, for dbxtool at least you can add sh stty sane in + your .dbxinit file. - 4. I tried to compile tcsh and it cannot find ? + I tried to compile tcsh and it cannot find ? - Your system does not support NLS. Undefine NLS in config_f.h and it + Your system does not support NLS. Undefine NLS in config_f.h and it should work fine. - _________________________________________________________________ - - 5. Where can I get csh sources? - - Csh sources are now available with the 4.4BSD networking - distributions. You don't need csh sources to compile tcsh-6.0x. - _________________________________________________________________ - - 6. I just made tcsh my login shell, and I cannot ftp any more? - - Newer versions of the ftp daemon check for the validity of the user's - shell before they allow logins. The list of valid login shells is - either hardcoded or it is usually in a file called /etc/shells. If it - is hard-coded, then you are out of luck and your best bet is to get a - newer version of ftpd. Otherwise add tcsh to the list of shells. [For - AIX this file is called /etc/security/login.cfg.] Remember that the - full path is required. If there is no /etc/shells, and you are - creating one, remember to add /bin/csh, /bin/sh, and any other valid - shells for your system, so that other people can ftp too :-) - _________________________________________________________________ - - 7. I am using SunView or OpenWindows and editing is screwed up. In - particular my arrow keys and backspace don't work right. What am I - doing wrong? - - Well, cmdtool tries to do its own command line editing and the effect - you get is one of using an editor inside an editor. Both try to - interpret the arrow key sequences and cmdtool wins since it gets them - first. The solutions are in my order of preference: - 1. Don't use suntools - 2. Use shelltool instead of cmdtool. - 3. Unset edit in tcsh. - _________________________________________________________________ + Where can I get csh sources? + + Csh sources are now available with the 4.4BSD networking distributions. + You don't need csh sources to compile tcsh-6.0x. + + I just made tcsh my login shell, and I cannot ftp any more? + + Newer versions of the ftp daemon check for the validity of the user's + shell before they allow logins. The list of valid login shells is + either hardcoded or it is usually in a file called /etc/shells. If it + is hard-coded, then you are out of luck and your best bet is to get a + newer version of ftpd. Otherwise add tcsh to the list of shells. (For + AIX this file is called /etc/security/login.cfg.) Remember that the + full path is required. If there is no /etc/shells, and you are creating + one, remember to add /bin/csh, /bin/sh, and any other valid shells for + your system, so that other people can ftp too. - 8. On a SPARCstation running Solaris 2.x and OpenWindows 3.1, inside a - cmdtool, the short-cut key sequence to clear log (i.e. Meta-e or - Diamond-e) doesn't work: it just echos 'e'; or + I am using SunView or OpenWindows and editing is screwed up. In particular my + arrow keys and backspace don't work right. What am I doing wrong? + + Well, cmdtool tries to do its own command line editing and the effect + you get is one of using an editor inside an editor. Both try to + interpret the arrow key sequences and cmdtool wins since it gets them + first. The solutions are in my order of preference: + * Don't use suntools + * Use shelltool instead of cmdtool. + * Unset edit in tcsh. + + On a SPARCstation running Solaris 2.x and OpenWindows 3.1, inside a cmdtool, + the short-cut key sequence to clear log (i.e. Meta-e or Diamond-e) doesn't + work: it just echos ‘e’; or Unset edit in tcsh. - _________________________________________________________________ - 9. On a SPARCstation running Solaris 2.x and OpenWindows 3.1, maketool - (within SPARCworks) doesn't work: it just does a `cd' to the working - directory then stops. + On a SPARCstation running Solaris 2.x and OpenWindows 3.1, maketool (within + SPARCworks) doesn't work: it just does a `cd’ to the working directory then + stops. - Unset edit in tcsh. Using shelltool instead of cmdtool does not fix + Unset edit in tcsh. Using shelltool instead of cmdtool does not fix this. - _________________________________________________________________ - 10. I rlogin to another machine, and then no matter what I tell 'stty' - I cannot get it to pass 8 bit characters? + I rlogin to another machine, and then no matter what I tell stty I cannot get + it to pass 8 bit characters? - Maybe you need to use 'rlogin -8' to tell rlogin to pass 8 bit + Maybe you need to use rlogin -8 to tell rlogin to pass 8 bit characters. - _________________________________________________________________ - 11. Where do I get the public domain directory library? + Where do I get the public domain directory library? - Anonymous ftp to prep.ai.mit.edu:/pub/gnu/dirent.tar.Z - _________________________________________________________________ + Anonymous ftp to ftp://prep.ai.mit.edu/pub/gnu/dirent.tar.Z - 12. I compiled tcsh using gcc, and when I start up it says: tcsh: - Warning no access to tty (Invalid Argument). Thus no job control in - this shell + I compiled tcsh using gcc, and when I start up it says: tcsh: Warning no + access to tty (Invalid Argument). Thus no job control in this shell - Your file is not ansi compliant. You have one of 3 + Your file is not ansi compliant. You have one of 3 choices: + * Run fixincludes from the gcc distribution. + * Add -traditional to the gcc flags. + * Compile with cc. - 1. Run fixincludes from the gcc distribution. - 2. Add -traditional to the gcc flags. - 3. Compile with cc. - _________________________________________________________________ - - 13. I compiled tcsh with the SunOS unbundled compiler and now things - get echo'ed twice. + I compiled tcsh with the SunOS unbundled compiler and now things get echoed + twice. It is a bug in the unbundled optimizer. Lower the optimization level. - _________________________________________________________________ - 14. How can I use the arrow keys with hpterm? + How can I use the arrow keys with hpterm? Hp terminals use the arrow keys internally. You can tell hpterm not to do that, by sending it the termcap sequence smkx. Since this has to be - done all the time, the easiest thing is to put it as an alias for + done all the time, the easiest thing is to put it as an alias for precmd, or inside the prompt: - if ($term == "hp") then set prompt="%{`echotc smkx`%}$prompt" endif - Note that by doing that you cannot use pgup and pgdn to scroll... Also - if you are using termcap, replace "smkx" with "ks"... - _________________________________________________________________ + Note that by doing that you cannot use pgup and pgdn to scroll… Also if + you are using termcap, replace smkx with ks. - 15. On POSIX machines ^C and ^Z will do not work when tcsh is a login - shell? + On POSIX machines ^C and ^Z do not work when tcsh is a login shell? Make sure that the interrupt character is set to ^C and suspend is set - to ^Z; 'stty -a' will show you the current stty settings; 'stty intr - ^C susp ^Z' will set them to ^C and ^Z respectively. - _________________________________________________________________ + to ^Z; stty -a will show you the current stty settings; stty intr ^C + susp ^Z will set them to ^C and ^Z respectively. - 16. I am trying to compile tcsh and I am getting compile errors that - look like: + I am trying to compile tcsh and I am getting compile errors that look like: - >sh.c:???: `STR???' undeclared, outside of functions [gcc] - >"sh.c", line ???: STR??? undefined [cc] + sh.c:???: `STR???' undeclared, outside of functions [gcc] + "sh.c", line ???: STR??? undefined [cc] - You interrupted make, while it was making the automatically generated - headers. Type 'make clean; make' - _________________________________________________________________ + You interrupted make, while it was making the automatically generated + headers. Type make clean; make - 17. On the cray, sometimes the CR/LF mapping gets screwed up. + On the cray, sometimes the CR/LF mapping gets screwed up. - You are probably logged in to the cray via telnet. Cray's telnetd - implements line mode selection the telnet client you are using does - not implement telnet line mode. This cause the Cray's telnetd to try - to use KLUDGELINEMODE. You can turn off telnet line mode from the cray - side by doing a "stty -extproc", or you can get the Cray AIC to build - a telnetd without KLUDGELINEMODE, or you can compile a new telnet - client (from the BSD net2 tape), or at least on the suns use: 'mode - character'. - _________________________________________________________________ + You are probably logged in to the cray via telnet. Cray's telnetd + implements line mode selection the telnet client you are using does not + implement telnet line mode. This cause the Cray's telnetd to try to use + KLUDGELINEMODE. You can turn off telnet line mode from the cray side by + doing a stty -extproc, or you can get the Cray AIC to build a telnetd + without KLUDGELINEMODE, or you can compile a new telnet client (from + the BSD net2 tape), or at least on the suns use: mode character. - 18. On AU/X, I made tcsh my startup shell, but the mac desktop is not - starting up (no X11 or Finder), and I only get console emulation. + On AU/X, I made tcsh my startup shell, but the mac desktop is not starting up + (no X11 or Finder), and I only get console emulation. - This is another manifestation of item 5. Just add the pathname to tcsh - in /etc/shells and everything should work fine. - _________________________________________________________________ + Add the pathname to tcsh in /etc/shells and everything should work + fine. - 19. On machines that use YP (NIS) tilde expansion might end up in - /dev/null + On machines that use YP (NIS) tilde expansion might end up in /dev/null - If this happens complain to your vendor, to get a new version of NIS. + If this happens complain to your vendor, to get a new version of NIS. You can fix that in tcsh by defining YPBUGS in config.h - _________________________________________________________________ - 20. Script on SGI 4.0.5 does not give us a tty, so we cannot have job - control. + Script on SGI 4.0.5 does not give us a tty, so we cannot have job control. Their csh does not have job control either. Try: - % script % cat > /dev/tty - _________________________________________________________________ - 21. I start tcsh and it takes a couple of minutes to get the prompt. + I start tcsh and it takes a couple of minutes to get the prompt. - You have defined REMOTEHOST and your DNS is not responding. Either + You have defined REMOTEHOST and your DNS is not responding. Either undefine REMOTEHOST and recompile or fix your DNS. - _________________________________________________________________ - - 22. If you need help generating your .cshrc file, check out: - http://www.imada.sdu.dk/~blackie/dotfile/ + If you need help generating your .cshrc file, check out: - or - http://www.dotfiles.com - _________________________________________________________________ + * https://github.com/tcsh-org/tcsh/blob/master/dot.tcshrc + * https://github.com/tcsh-org/tcsh/blob/master/dot.login - 23. On POSIX systems the kernel will send hup signals to all the - processes in the foreground process group if 'stty hupcl' is set. + On POSIX systems the kernel will send hup signals to all the processes in the + foreground process group if ‘stty hupcl’ is set. For example - ./tcsh echo $$ 591 ./tcsh kill -6 591 Will kill everything, since hup will be sent to all tcsh processes. To avoid that you can set stty -hupcl, but it is not recommended. - _________________________________________________________________ - 24. When I rsh the meta key stops working on the remote machine. + When I rsh the meta key stops working on the remote machine. - Try using rsh -8; this option is undocumented on some systems, but it - works. If that does not work, get and use ssh/sshd. You'll be better + Try using rsh -8; this option is undocumented on some systems, but it + works. If that does not work, get and use ssh/sshd. You'll be better off from a security point of view anyway. - _________________________________________________________________ - 25. Tcsh compiled under hp/ux-10.x does not pass resource limits - correctly when ran on hp/ux-11.x systems. + Tcsh compiled under hp/ux-10.x does not pass resource limits correctly when + ran on hp/ux-11.x systems. - This is a problem with lack of ABI compatibility between the two + This is a problem with lack of ABI compatibility between the two systems. The only solution is to recompile. - _________________________________________________________________ - 26. Refreshing in command line editing can appear broken on some OS's + Refreshing in command line editing can appear broken on some OS's - This is because the termcap/terminfo description lies about the - ability of the terminal to use tabs. At least on Compaq/DEC Alpha - OSF/1 3.x and 4.x systems, stty -tabs will cause problems. - _________________________________________________________________ + This is because the termcap/terminfo description lies about the ability + of the terminal to use tabs. At least on Compaq/DEC Alpha OSF/1 3.x and + 4.x systems, stty -tabs will cause problems. - 27. Where can I learn the merits of tcsh vs. bash vs. csh vs. sh etc? + Where can I learn the merits of tcsh vs. bash vs. csh vs. sh etc? - You can read the manual page section titled [NEW FEATURES] listing + You can read the manual page section titled [NEW FEATURES] listing features that tcsh adds to csh. - You can read Tom Christiansen's [Csh Programming Considered Harmful], - a document advocating that csh (and by extension, tcsh) should not be + You can read Tom Christiansen's Csh Programming Considered Harmful, a + document advocating that csh (and by extension, tcsh) should not be used for writing shell scripts. - XXX: Need to find something about [bash], but bash is sh-compatible - and has many of the same interactive features of tcsh (command - completion does not appear to be as flexible, though). - - [Curtains up: introducing the Z shell] has a pretty good rundown on - zsh. Aside from the arguments about csh being evil, tcsh appears to - compare well with zsh [zsh]. Zsh is sh and ksh compatible, with many - of the interactive features of tcsh. - _________________________________________________________________ - - 28. Why does FreeBSD's tcsh do history browsing differently than I - expect? + XXX: Need to find something about bash, but bash is sh-compatible and + has many of the same interactive features of tcsh (command completion + does not appear to be as flexible, though). - On FreeBSD, by default, the up arrow is set to - "history-search-backward", rather than the default "up-history". As a - result, if you type (part of) a word and press up arrow, you'll see - previous commands that match the prefix. Pretty useful, actually, - although it takes some getting used to. You can use bindkey to see - your settings, and to rebind up & down differently if desired. - _________________________________________________________________ + Curtains up: introducing the Z shell has a pretty good rundown on zsh. + Aside from the arguments about csh being evil, tcsh appears to compare + well with zsh. Zsh is sh and ksh compatible, with many of the + interactive features of tcsh. - Everything else is a bug :-( + Why does FreeBSD's tcsh do history browsing differently than I expect? - Christos - _________________________________________________________________ + On FreeBSD, by default, the up arrow is set to history-search-backward, + rather than the default up-history. As a result, if you type (part of) + a word and press up arrow, you'll see previous commands that match the + prefix. Pretty useful, actually, although it takes some getting used + to. You can use bindkey to see your settings, and to rebind up & down + differently if desired. + __________________________________________________________________ - Home | RecentChanges | Preferences - Edit text of this page | View other revisions - Last edited April 29, 2004 15:02 (diff) - Search: ____________________ + Page content last updated on 2019-12-31 diff --git a/contrib/tcsh/Fixes b/contrib/tcsh/Fixes index db401f23fad0..e539c8241a86 100644 --- a/contrib/tcsh/Fixes +++ b/contrib/tcsh/Fixes @@ -1,2174 +1,2197 @@ + 14. Don't crash with 'bindkey "^0" clear-screen' (Karl Jeacle) + 13. Fix $x:q:h and $x:q:t return the whole string for strings not containing / + 12. V6.22.03 - 20201118 + 11. Fix $x:q:h and $x:q:t to not crash (alzwded) with strings containing / + 10. Block SIGHUP while writing history/directory stack (Brett Frankenberger) + 9. Fixed reversed test that broke history merging (Brett Frankenberger) + 8. Prevent recursive entry for writing history (Brett Frankenberger) + 7. alxwded@github, keep track of the :g and :a modifiers per modifier they + affect. + 6. alzwded@github, fix infinite loop with :gas variable modifier + 5. PR/88: Add a Q: modifier that preserves empty arguments leaving :q + alone. + 4. V6.22.02 - 20191204 + 3. Fix version in configure.ac + 2. V6.22.01 - 20191201 + 1. undo PR/88: Preserve empty arguments in :q, since it breaks + $ set x="" + $ alias test "echo "\""$x:q"\"" is working." + $ alias test + echo " + + 6. V6.22.00 - 20191128 5. PR/113: Sobomax: avoid infinite loops for -c commands when stdout is not a tty. 4. Avoid infinite loops during history loads when merging, print a better error for errors during history load. 3. PR/88: Preserve empty arguments in :q 2. PR/94: Small apple issues (SAVESIGVEC, HOSTTYPE) 1. PR/81: Fix range matching issue where we were comparing with the range character instead of the start of range. [l-z]* would match foo + 12. V6.21.00 - 20190508 11. Abort history loading on words and lines too long https://bugzilla.redhat.com/show_bug.cgi?id=1598502 10. PR/37: Introduce GetCmdChar() to avoid open coding array access. 9. make closem() not close sockets so as not to affect nss_ldap. tcsh never creates sockets so that's ok (Miloslav Trmac) 8. PR/597: Make rmstar work with aliased rm 7. convert match() from recursive to backtracking. 6. Handle 8 bit characters in bindkey (Werner Fink) 5. Look for tgetent in libtinfo as well (Werner Fink) 4. Don't play pointer tricks that are undefined in modern c (Brooks Davis) 3. Fix out of bounds read (Brooks Davis) 2. Fix type of read in prompt confirmation (eg. rmstar) (David Kaspar) 1. PR/471: Delay arginp parsing 20. V6.20.00 - 20161124 19. Don't resize the screen if it did not change size. 18. V6.19.01 - 20161025 17. restore file description when cleaning up after eval: repeat 99 time 16. PR/572: Fix $SHLVL issue when exec'ing subshells. 15. PR/403: Fix backquote expansion for multi-byte character sets. 14. Fix drawing issu with multi-line prompt (Kensuke Iwahashi/David Kaspar) 13. always send prusage to stdout. 12. PR/526: Fix double \\ printing from previous fix in history expansion. 11. Android updates from Corinna Vinschen 10. PR/526: Quote backslashes properly so they can be preserved in `` expansions 9. Fix memory leak for paraml 8. Add notempty and ask values for the noclobber setting (Martin Tournoij) 7. more correct $wordchars for vimode (Luke Mewburn) 6. expose VImode in $vimode (Luke Mewburn) 5. display what the compiled in editor is in bindkey -d (Luke Mewburn) 4. run-fg-editor improvements and documentation (Luke Mewburn) 3. Fix parsing of 'if (cond)then' (Fridolin Pokorny) 2. PR/437: Fix handling of invalid unicode characters. 1. PR/451: Fix error messages containing %c to be always '%c' 41. V6.19.00 - 20150521 40. V6.18.05 - 20150510 39. fix reseting when interrupted inside an eval "eval sleep 10^C" (paulo.cesar.pereira.de.andrade) 38. rename handle_intr -> handle_interrupt as originally intended. 37. fix input tests that need stdin on a tty 36. V6.18.04 - 20150504 35. revert fix echo "\1", it is incorrect. 34. revert fix to PR/437, breaks short strings. 33. V6.18.03 - 20150503 32. PR/437: Nakajima Akira: Fix segmentation fault reading input files 31. PR/291: Print job status messages to stderr. 30. Fridolin Pokorny NUL in `` does not mean EOF. 29. Pavel Raiskup fix hang with: while (1) ( date & ; wait ) end 28. Add cdtohome special variable (Martin Tournoij) 27. Fix root prompt char for windows (Corinna Vinschen) 26. For "next" completion matches only consider exact matches of the previous word (Jamie Landeg-Jones) 25. Fix echo "\1" for echo_style=both where the first character was not processed properly (Gary Duzan) 24. V6.18.02 - 20140618 23. fix ls-F /non printing exit value twice. 22. rename configure.in to configure.ac, add aclocal.m4 to CVS 21. set foo="aabaabaa"; echo $foo:as/a// should produce bb 20. Add locked merge history support (Marcin Konarski) 19. Support more resource limits from various BSD's 18. Cache history count to speed up thing 17. PR/240: minix support 16. revert fix for 15. Causes extra quoting, for example (foo is a program that prints its arguments): $ ./foo 'abc' * '\a\b\c' 15. fix globbing for ``, stripping backslashes. Example: cat << _EOF > huh echo 'hello\;world' _EOF echo `./huh 0` echo `./huh $?` 14. fix for `` that causes hang. Example: cat << _EOF > huh #!/bin/sh echo "[$@]" echo "I am running" echo "I am running ($$)" >> huh.out _EOF cat << _EOF > huh.tcsh #!/bin/tcsh -f ./huh \ `#comment blah blah blah` \ parameter a \ `#comment blah blah blah` \ parameter b \ `#comment blah blah blah` \ parameter c echo ok _EOF 13. remove AsciiOnly fix now that the real issue has been fixed (Roman Kollar) 12. define utmp file for aix (Laurence Darby) 11. fix if history in loops 10. make ls-F print to stderr and set the exit code 9. make rmstar interruptible on linux 8. Get rid of pret_t and make the printf functions return the number of characters printed as the system ones do. 7. Parse a FreeBSD compat $LSCOLORS. What to do when both LSCOLORS and LS_COLORS are set. I am not documenting this until we decide. 6. V6.18.01 - 20120214 5. fix interruptible wait again 4. ignore bogus compiler overflow message 3. cleanup ifdefs in utmp code, and provide default array entries 2. Ignore #machine entries in host.defs 1. Detect missing ) in gethost.c (Corinna Vinschen) 104. V6.18.00 - 20120114 103. remove unused variables. 102. Make gethost use definitions for x __x__ and __x automatically. 101. More utmp fixes 100. V6.17.10 - 20120105 99. Add more FreeBSD/NetBSD machines 98. Add portability wrapper for gencat 97. Fix warning for write in SYSMALLOC systems. 96. V6.17.09 - 20120102 95. revert gencat handling to pre-cygwin fixes (without the env settings) 94. remove stray endutent() 93. V6.17.08 - 20111230 92. Remove - from gencat 91. Provide support for malloc_usable_size() so that linux works again without SYSMALLOC 90. Add support for FreeBSD's utmpx. 89. V6.17.07 - 20111227 88. Fix debian bug #645238: tcsh segfaults when prompt includes %j and there are more than 10 jobs. 87. PR/155: Default $anyerror to set for backward compatibility 86. PR/149: Don't print -1 in %j (Vojtech Vitek) 85. handle -- on chdir commands as the end of options processing so that they can process a directory like -x without resorting to ./-x (Andrew Stevenson) 84. Handle write(2) returning ENOENT from SoFS, thanks ++HAL (Robert Byrnes) 83. PR/38: Null check for jobs (Kurt Miller) 82. Fix spelling correction correcting ./foo -> ../foo2 (jean-luc leger) 81. PR/120: string0 in filetest does not have enough space. 80. V6.17.06 - 20110415 79. PR/110: Add $anyerror to select behavior. Default to the new one. 78. Don't try to spell commands that are correct (Rouben Rostamian) [./tcsh -f; set path=($path 2); mkdir foo2; cd foo2; touch foo; chmod +x foo; set correct=cmd; ./foo -> ../foo] 77. Don't push the syntax struct on the cleanup stack, because on foo;bar if foo fails, we will free bar prematurely (Ben Miller) 76. Avoid infinite loop while trying to print the pid of a dying process to a closed file (Bob Arendt) 75. Handle completion of ${ variables (Anthony Mallet) 74. Add --disable-nls-catalogs (Corinna Vinschen) 73. convert message catalogs to UTF-8 (Werner Fink) 72. check that the NLS path works before setting $NLSPATH. 71. use SYSMALLOC for GLIBC (Werner Fink) 70. use mallinfo for SYSMALLOC (Corinna Vinschen) 69. V6.17.05 - 20110201 68. Use mkstemp() if there for here docs (Werner Fink) 67. Fix handling of errors and exit values in builtins (Werner Fink) 66. Better pty name detection (Werner Fink) 65. Enable NLS catalogs on Cygwin (Corinna Vinschen) 64. NLSPATH handling fixes (Corinna Vinschen) 63. Avoid infrequent exit when tcsh cd's into a non-existent directory https://bugzilla.novell.com/show_bug.cgi?id=293395 (Werner Fink) 62. Don't try to spell check full path binaries that are correct because they can cause hangs when other nfs partitions are hung. (Werner Fink) 61. Avoid nested interrupts when exiting causing history writing to fail https://bugzilla.novell.com/show_bug.cgi?id=331627 (Werner Fink) 60. Instead of giving an error or ignoring lines with missing eol at eof, process them. 59. Avoid leaking fd's in mail check (Werner Fink) 58. Add cygwin_xcrypt() (Corinna Vinschen) 57. Recognize i686 (Corinna Vinschen) 56. Rename cygwin32 to cygwin and bring it up-to-date with modern cygwin settings (Corinna Vinschen) 55. Avoid double slashes in cdpath (Corinna Vinschen) 54. V6.17.04 - 20110118 53. Revert PR/110, breaks the test suite. 52. V6.17.03 - 20110117 51. PR/102: Complain on input files with missing trailing \n 50. PR/104: If atime == mtime we don't have new mail. 49. PR/113: Don't allow illegal variable names to be set. 48. PR/112: don't set $REMOTEHOST on the local machine. 47. PR/110: exit status of the pipeline should be the status of the last command. 46. Android support (Corinna Vinschen) 45. Add AUTOSET_KANJI which works around the Shift-JIS encoding that translates unshifted 7 bit ASCII (Werner Fink) 44. Handle mb{r,}towc() returning 0 by setting the return value to NUL (Jean-Luc Leger) 43. PR/109: make wait interruptible (Vojtech Vitek) 42. resource limit fixes: signed vs. unsigned, megabyte issue, doc issues (Robert Byrnes) 41. remove .bat and .cmd handling for executables on cygwin (Corinna Vinschen) 40. Don't echo history while history -L or history -M 39. Check for EOS before ** from Greg Dionne 38. Don't fork in backeval from Bryan Mason 37. Better globstar support from Greg Dionne 36. Error out when processing the last incomplete line instead of silently ignoring it (Anders Kaseorg) 35. Fix SEGV from echo `` 34. Better fixes for histchars and promptchars (nargs) 33. Fix win32 issue calling fmalloc/ffree from non-thread-safe context. (Fabio Fabbri) 32. V6.17.02 - 20100512 31. PR/79: nargs: Better handling for promptchars. 30. PR/97: Add parseoctal to retain compatibility with previous versions (Jim Zajkowski) 29. PR/84: Performance fixes for large history merges (add hashtable (Ted Anderson) 28. Revert previous #23; people should use $histlit if they want this feature. 27. Don't kill "hup" background jobs when a child of the shell exits. From Debian. 26. Ignore \r\n in the command line options for OS's that don't strip these from #!; from Debian 25. Fix enhanced missing patch (Greg Dionne) 24. Callers of rt_mbtowc don't grok -2 as a return. Return -1 for now. (Corinna Vinschen) 23. Turn HistLit on while recording history to avoid \!\! losing its \. From Debian 22. set autoexpand; set histchars="";\n crash. From Debian 21. V6.17.01 - 20100506 20. unset verbose while we are reading the history file to avoid echoing to the terminal. (Jeffrey Bastian) 19. globstar addition, Enhance addition, euid, euser, gid variables (Greg Dionne) 18. Make 'e' in vi mode work like 'b' - use wordchars (Alistair Crooks) 17. Handle UTF-16 surrogates (Corinna Vinschen) 16. Make tcsh work on systems where sizeof(wchar_t) == 2 (Corinna Vinschen) 15. Better support for Solaris >= 2.9 (Thomas Uhle) 14. Change internal expression calculations to long long so that we can deal with > 32 bit time, inodes, uids, file sizes etc. 13. Add new linux resource limits. 12. Don't print 'Exit X' when printexitvalue is set in `` expressions (Jeff Bastian) 11. Add more LS_COLORS vars (M.H. Anderson) 10. Reduce whitespace in Makefile (Don Estabrook) 9. Manual page fixes (Alan R. S. Bueno) 8. Remove history in loops bug from the documentation (Holger Weiss) 7. Add autorehash (Holger Weiss) 6. Add history.at (Ted Anderson) 5. Better NLSPATH handling (Norm Jacobs) 4. Fix hostname building from utmp (Cyrus Rahman) 3. Handle pending signals before flush so that the the history file does not get truncated. (Ted Anderson) 2. Fix AsciiOnly setting that broke 8 bit input. (Juergen Keil) 1. remember to closedir in mailchk (from Werner Fink, reported by David Binderman) 21. V6.17.00 - 20090710 20. Fix dataroot autoconf issue. 19. Fix directory stuff for unit tests. 18. Fix small bug in history in loops. 17. Provide newer config.{guess,sub} 16. Fix gcc 4 warnings. 15. Fix memory trashing bug introduced in 10. 14. V6.16.01 - 20090624 13. add missing sigemptyset in goodbye() 12. add rlimit swapsize from FreeBSD. 11. restore behavior where a[n-] never prints an error. 10. always save the whole command, not just the first 80 chars of it. 9. fix short2str/short2qstr length adjustment in wide chars (Vitezslav Crhonek) 8. set histfile=/tmp/history.temp; set savehist=(100 merge); alias precmd history -S. After that justpr is not restored and commands don't execute. (Andriy Gapon) 7. Fix "as" $ modifier from corrupting memory. set t=demfonsftraftionf; echo $t:as/f// 6. Make $% work with environment variable (Ron Johnston) 5. Dragonfly script support (Matthias Schmidt, m65) 4. Add autoexpand=onlyhistory (Don Estabrook, m66) 3. Add history in loops (Laurence Darby, m48) 2. Add missing colorls "rs" variable (Shlomi Fish, m70) 1. Fix pts detection issue (Ruslan Ermilov) 33. V6.16.00 - 20080930 32. longjmp clobbered variable fixes. 31. __GNX__ addition 30. Windows fork fixes 28. V6.15.02 - 20080830 27. Fix an eval free'ing botch (Per Hedeland) 26. /bin/echo "`" coredumped because stderror() calls longjmp corrupting the stack (Mark Davies). We should vet the code for all stderror() calls that cleanup local stack variables. 25. foo > ${undef} caused coredumps because of vfork() child corrupting the state of the parent stack. 24. $x[A-B] did not complain for A out of range. (Cai Xianchao) 23. rename setp -> tcsh_setp to avoid conflict with mach (Javier Vasquez) 22. Fix degree handling by defining __XPG4_CHAR_CLASS__ for solaris (Mike Sullivan) 21. Change 'od' to 'od -c' in tests so that they work on big endian machines. (Martin Kraemer) 20. Add environment variable COMMAND_LINE to be available in completions (Marcin Konarski) 19. V6.15.01 - 20070928 18. Evaluate expressions in the proper order (Li Zefan), controlled by compat_expr. 17. Don't need to flush() if we are silent. Prevents recursive error issue. (joshua stein) 16. Don't execute the jobcmd if the output is not a tty (Charles Ross) 15. Quote the history in the examples (Johann 'Myrkraverk' Oskarsson) 14. Mismatch clarification patch (Per Hedeland) 13. Fix 'repeat n cmd &' abort() (Mike Sullivan) 12. Fix octal parsing (Li Zefan) 11. Fix pty detection for autologout setting (Kris Kennaway, Giorgos Keramidas) 10. kill `foo` got stuck because sigchld was disabled too soon (Mark Peek) 9. Avoid null pointer dereference in proc cwd (Kurt Miller) 8. eval "foreach a b c" exits (Anthony Menasse) 7. Quoting was broken in substitutions (Joe Wells) 6. QNX patches via pkgsrc 5. cd - twice from a directory that contained a glob pattern, expands the glob twice (Mark Santcroos) 4. MidnightBsd support (Lucas Holt) 3. Fix history substitution core-dump with no history entries 2. Merge two character tables that are the same (Martin Kraemer) 1. On ancient 7 bit locales, punctuation characters are used to denote special characters such as umlaut, adiaresis, etc. These characters return true for isalpha/isalnum. Ignore them because they break parsing (Martin Kraemer) 74. V6.15.00 - 20070303 73. fix extension eating windows code (christos) 72. fix loop in %R history expansion (christos) 71. sched +X source file disables interrupts (Mike Sullivan) 70. One off copying macro buffers (Jean-Luc Leger) 69. Avoid infinite loops in :ga modifiers when the LHS is a substring of the RHS. 68. Automatically disable WIDE_STRINGS with --disable-nls (Miloslav Trmac) 67. V6.14.07 - 20060825 66. rename set to setv to avoid clashes (christos) 65. Eliminate sighold/sigrelse (christos) 64. Compilation cleanups. (Martin Kraemer) 63. Don't rebuild needlessly when generated files are unchanged (Martin Kraemer) 62. Fix confusion between Char and eChar (Martin Kraemer) 61. V6.14.06 - 20060824 60. set PROGRAM_ENVIRONMENT for OSD_POSIX (Martin Kraemer) 59. EBCDIC patch (Martin Kraemer) 58. Remove globbing support in history rearches (Ryan Barrett) 57. Highlighting patch (Ryan Barrett) 56. Mark-Cursor exchange emacs editing fix (Martin Kraemer) 55. V6.14.05 - 20060304 54. don't limit termcap strings to 1K (Alan Ferrency) 53. protect against null path. 52. Be more conservative in wide_read PR#29 51. remove HAVE_STRCOLL; not needed anymore (Miloslav Trmac) 50. remove imake support and make nls configurable by configure (Miloslav Trmac) 49. V6.14.04 - 20060214 48. Fixes build failure with !SHORT_STRINGS (Miloslav Trmac) 47. Fixes constness warnings with !SHORT_STRINGS: short2str is "strip()", which modifies its argument. Rather than verify this is safe in all callers, I have added caching_strip() to mirror the behavior of other modes. (Miloslav Trmac) 46. Fixes some constness warnings with SHORT_STRINGS; this is orthogonal to both build errors with SHORT_STRINGS in 6.14.03, and short_strings.patch. (Miloslav Trmac) 45. config-catalogs.patch: Autodetect catalog support (#14). (Miloslav Trmac) 44. auth.patch: Handle false positives in getauthid() detection, IIRC on FreeBSD. (Miloslav Trmac) 43. crypt.patch: Autodetect whether is available. (Miloslav Trmac) 42. sigint.patch: Block SIGINT while waiting on children. This is necessary, but I'll still have to look on the older releases to find out why it was not necessary before ("before" = 6.13 on Linux). (Miloslav Trmac) 41. config-package.patch: Readd package version to configure.in, the testsuite uses it. (TODO: a better integration with package.h) (Miloslav Trmac) 40. item_len.patch: Truncate item.len when truncating the string, just to be sure. (Miloslav Trmac) 39. va_list.patch: Add missing va_end(). (Miloslav Trmac) 38. Use va_copy in xvasprintf(); emulate va_copy as suggested in Autoconf manual if it is not available. (Miloslav Trmac) 37. declarations.patch: Replace some #ifdef nests by autodetecting whether the guarded declaration is necessary. I'm only guessing this is the intent of the #ifdefs, though. Declare environ unconditionally, it is a bit hard to detect and the declaration is correct for Linux, anyway. (Miloslav Trmac) 36. warning.patch: Fix a const warning. 35. More color-ls variables (Jean-Luc Leger) 34. V6.14.03 - 20060212 33. Signal related changes (Miloslav Trmac) 32. Misc cast cleanups and code clarification (Miloslav Trmac) 31. Use dynamically allocated buffers everywhere (Miloslav Trmac) 30. Fix reading of invalid byte sequences (Miloslav Trmac) 29. read should only increment count when it succeeds (Miloslav Trmac) 28. testsuiteadditions (Miloslav Trmac) 27. -n fixes (Miloslav Trmac) 26. signness warnings (Miloslav Trmac) 25. Prevent infinite recursion in catclose (Gerhard Niklasch) 24. Add Dragonfly (Joerg Sonnenberger) 23. Check for wcwidth returning a negative number (TOMITA Yoshinori) 22. recognize "li" and "co" in echotc (Martin Kraemer) [PR/7] 21. Don't use T_Cols for wrapping purposes; use TermH consistently (Martin Kraemer) [PR/8] 20. Don't display duplicate utmp records (Miloslav Trmac) [PR/17] 19. Clarify hashing and -f sections of man page (Volker Quetschke) [PR/20] 18. Dave Yearke: configure did not recognize solaris 10 [PR/18] 17. CYGWIN: Don't lowercase commands and allow foo.exe on command line. (Corinna Vinschen) [PR/19] 16. CYGWIN: cd /foo && cd .. ends up erroneously in // for systems that HAVE_SLASHSLASH [PR/21] 15. %j was broken (Peter Kruse) 14. Extend // handling in pathnames from being apollo specific to also cygwin (Corinna Vinschen) 13. Fix uppercase/lowercase transformations (Jean-Luc Leger) 12. Fix symlink expansion (revert from 6.10.00) (Jean-Luc Leger and Christos) 11. Fix literal sequence in prompt (Miloslav Trmac) 10. V6.14.02 - 20050412 9. Prototype fixes (Miloslav Trmac and Jean-Luc Leger) 8. V6.14.01 - 20050411 7. Make =- refer to $owd (H.Merijn Brand) 6. Use prototypes (almost) everywhere (Miloslav Trmac) (issue #5) 5. Fix doc path in Cygwin installation (Corinna Vinschen) 4. Fix column size calculation (Martin Kraemer) 3. Implement newline-and-hold and newline-and-down-history (Per Hedeland) 2. Messages fixes for the ja (Japanese) locale (NAKAMURA Takeshi) (issue #4) 1. Enable charset conversion in nls (Miloslav Trmac) (issue #3) 76. V6.14.00 - 20050325 75. Additional messages for the ja (Japanese) locale (NAKAMURA Takeshi) 74. V6.13.10 - 20050321 73. Implement --help (Tom Warzeka) 72. Clamp solaris autologout time 71. Add support for "limit heapsize" (Martin Kraemer) 70. Improved autoconf for utmp/utmpx (Miloslav Trmac) 69. V6.13.09 - 20050303 68. Autoconf additions (Miloslav Trmac and Jean-Luc Leger) 67. Fix erroneous sign extension when printing huge numbers (Martin Kraemer) 66. Handle delay in termcap entries (Martin Kraemer) 65. EBCDIC and BS2000 fixes (Martin Kraemer) 64. Avoid the SCCS percent-S-percent sequence differently (Kimmo Suominen) 63. Mark position update fixes (Martin Kraemer) 62. Define BSDLIMIT and BSDTIMES for Cygwin (Corinna Vinschen) 61. Fix NLSFrom prototype (Martin Kraemer) 60. V6.13.08 - 20050303 59. Add test for socklen_t in autoconf 58. Fix problems with NLSFrom prototype 57. Deal with AIX's utmpx lossage 56. V6.13.07 - 20050118 55. constifications, XXX: duplicate prototype on setpgrp(). 54. iconv fixes (Miloslav Trmac) 53. literal code cleanups (Miloslav Trmac) 52. move intptr_t definition to sh.h and include both stdint.h and inttypes.h 51. Fix dup2() issues, and introduce FSAFE as the highest file descriptor to be left untouched. This is to avoid closing hesiod/nis etc file descriptors behind their backs. I need to really fix file descriptor handling one day. 50. forward<->reverse char conversion verification (Miloslav Trmac) 49. japanese locale additions (Yoshiyuki Sakakibara) 48. wide character/utf 8 cleanups (Michael Schroeder) 47. V6.13.06 - 20050105 46. autoconf cleanup (Miloslav Trmac) 45. Fix literal refresh code (Michael Schroeder) 44. Fix history printing bug with WIDE_STRINGS 43. V6.13.05 - 20041121 42. deal with not having intptr_t 41. get rid of bool. 40. Protect HAVE_ICONV with NLS_CATALOGS 39. Deal with wchar_t being unsigned. 38. If we HAVEUTMPX redefine some utmp functions in terms of utmpx ones. 37. V6.13.04 - 20041120 36. Fix display problems with two-column characters when using WIDE_STRINGS. (Miloslav Trmac) 35. Change charset declarations for some of the translations. (Miloslav Trmac) 34. Set O_LARGEFILE properly (Miloslav Trmac) 33. Use libc functions to access utmp data (Miloslav Trmac) 32. t_pmatch() was not really case-insensitive when cs == 8 (Miloslav Trmac) 31. Fix escaping of "control" bytes 0x80..0x9F when they are actually parts of UTF-8 character representation. (Miloslav Trmac) 30. V6.13.03 - 20041120 29. More close_on_exec fixes (Miloslav Trmac) 28. SUSE dspmbyte fixes (via Harald) 27. Newline handling in command substitution controlled by csubstnonl (Miloslav Trmac) 26. Fix UNC prompt expansion (WIN32) (Yasuhiro Matsumoto) 25. Fix incorrect xprintf() usage (Miloslav Trmac) 24. Additional architectures support for $HOSTTYPE and $MACHTYPE (Miloslav Trmac) 23. Use nl_langinfo(CODESET) to determine $dspmbyte (Miloslav Trmac) 22. Complete arguments that contant a # (Steven Grady) 21. Set close-on-exec in subshells 20. Compilation fixes (Miloslav Trmac) 19. V6.13.02 - 20040804 18. de-register, de-extern, de-shadow, and const poison. 17. WIDE_STRINGS support (Miloslav Trmac) 16. warning cleanups (Miloslav Trmac) 15. nlsclose() arg passing, exp2 is now a gcc builtin (Mark Peek) 14. iconv malloc portability fix. 13. make automatic dspmbyte determination case insensitive 12. V6.13.01 - 20040724 11. bug fix in automatic dspmbyte setting (Miloslav Trmac) 10. iconv patches (Miloslav Trmac) 9. cygwin signal fixes; only init 32 signals, don't set bit flag on error; breaks SIGHUP. (Corinna Vinschen) 8. Make sure terminal size change takes effect immediately. 7. Obey $printexitvalue for builtins. 6. FreeBSD PR/66420: Allow history parsing to be special so that it can handle inline # characters (Oliver Eikemeier) 5. new termname builtin from (Andrew Stevenson) 4. if ($var =~ *[^0-9]*) echo not numeric, fix (Andrew Stevenson) 3. completion fix to avoid dup hosts from ssh_known_hosts (Eric D. Hendrickson) 2. vc++ 7.1 compilation fix (Steve Schockley) 1. UTF-8 handling for both single and double width characters, but no combining character support. (Michael Schroeder) 36. V6.13.00 - 20040519 35. V6.12.03 - 20040322 34. turn on kanji and dspmbyte by default; add check for utf8 locales, and turn parsing of that automatically based on $LANG. 33. Fix compilation issue under Windows/NT and charset incorrect patch (Yoshiyuki Sakakibara) 32. completion additions (Tom Warzeka) 31. compilation fix (Martin Kraemer) 30. V6.12.02 - 20040221 29. Glob completion listing addition (Tom Warzeka) 28. BS2000 bs2cmd builtin. (Martin Kraemer) 27. Fix interrupt resetting code when /etc startup scripts have syntax errors (Mark A. Grondona) 26. Clarification of kill-ring commands (Per Hedeland) 25. Debian completion additions (Martin Godisch) 24. Japanese character set fixes (Juehiro-san) from debian 23. NLS charset fixes; disabled since they only work with gnu gencat (Martin Godisch) 22. Fix HPUX >= 11 resource (Jack Cummings) 21. Handle breaksw that jumps out of loops. 20. Revert #16. It causes worse problems. 19. Avoid using execl() because the last NULL does not always promoted to a pointer because the function is variadic (Harti Brandt) 18. revert ignoreeof to the 6.11.00 behavior and document it (Martin Godisch) 17. do a case insensitive comparison for the multibyte vars (Martin Godisch) 16. don't sigsuspend() for an already exited job 15. glob all arguments in source (Martin Godisch) 14. various debian fixes (Martin Godisch) 13. setenv syntax check revert (Satoshi I. Nozawa) 12. EAGAIN typo (dan harkless) 11. filec compilation issue on hpux (beebe) 10. win32 compilation fixes for O_LARGEFILE (amol) 9. Don't go into an infinite loop when tcgetpgrp() returns an error. 8. Cygwin fixes (Corinna Vinschen) 7. NLS catclose() bug avoidance (KAJIMOTO Masato) 6. V6.12.01 - 20030208 5. Misc NT cleanup. No more GPL code (amol) 4. use strtol() to detect errors in builtin kill (Peter Jeremy) 3. Recognize linux systems on mips* (Maciej W. Rozycki) 2. Enable complete=igncase on unix (Stephen Krauth) 1. Eliminate maxitems (Todd Miller) 58. V6.12.00 - 20020732 57. misc cleanups. 56. V6.11.05 - 20020712 55. We should have socklen_t in the INET6 case, but we leave int otherwise. 54. Fixed for Darwin/Rhapsody (Mark Peek) 53. provide new config.sub and config.guess from ftp://ftp.gnu.org/gnu/config/ (Nelson Beebe) 52. V6.11.04 - 20020709 51. Dissallow setting of environment variables that do not contain alphanumeric names (Ton Voon) 50. Don't expand path components that don't resolve to path names (Jonathan Chen) 49. Make $ignoreeof agree with the man page (Matias Moreno Meringer) 48. Fix argument passing in tc.prompt.c expdollar (Nelson Beebe) 47. Completion fixes from FreeBSD (Mark Peek) 46. FreeBSD's sbsize limit (Mark Peek) 45. Fix repeat 3 repeat 2 echo foo 44. Fix I/O redirection in scripts (Ian D Allen) 43. Fix ` \\\n ` evaluation (Jean-Luc Leger) 42. add --version (Nelson Beebe) 41. portability fixes for sed (Nelson Beebe) 40. undef sv_handler for AIX's benefit. (Nelson Beebe) 39. Add a test for ss_family that disables IPV6 (linux/ppc, osf/1 have problems) (Nelson Beebe) 38. Disable ipv6 for Apple (Nelson Beebe) 37. Fix darwin configure entry (Nelson Beebe) 36. V6.11.03 - 20020701 35. Add Ian D. Allen's bug list. 34. If we are invoked as csh, default to bsd echo (Matej Vela) 33. Don't close file descriptors too early because setuid scripts fail. (Jill Pryse-Davies) 32. Completion updates (Tom Warzeka) 31. Fix compilation issue on SunOS4 with _POSIX_VDISABLE (Tom Warzeka) 30. ukrainian update (Olexander Kunytsa) 29. DSPMBYTE=utf8 patch (Jean-Luc Leger) 28. fix ipv4 only compilation, remove extra sigsetmask() call (Takayuki Nakao) 27. window change can cause free to be re-entered causing abort (Mark Peek) 26. vp->vec vetting, suggested by Ian Dall. 25. V6.11.02 - 20020516 24. Fix prompt bugs in $var and %c0n (TAKAI Kousuke) 23. Add Cray SV2 config (Rafal Maszkowski) 22. Add pdf manual page (Warren Ferguson) 21. Fix REMOTEHOST lossage in with AF_LOCAL sockets (Tom Mander) 20. Fix win32 break because of TIOCSTI (Amol) 19. Fix TIOCSTI for hpux 11 (Igor Schein) 18. Avoid collapsing paths that refer to non-existent components (Martin Kraemer) 17. Make -shell invocations always treated as a login shell. 16. V6.11.01 - 20020308 15. Fixes to polish nls locale (Pawe³ Niewiadomski) 14. russian locale fixes (Alexey Dokuchaev) 13. document door support (Shaen) 12. tcsh euc handling extensions (Alexey Zelkin) 11. Make sure that jobcmd does not clobber the current job (Rob McMahon) 10. Make sure that the output of verbose and echo do not end up in the command output (Victor I. Pasko) 9. Add %j in prompt [needs more work; is not right the first time after proclist changes] (Hr. Peter Kruse) 8. `` commands with embedded newlines would ignore commands following the new line (Victor I. Pasko) 7. Re-initialize nls if NLSPATH is changed (Naoki Wakamatsu) 6. Fix 64 bit compilation with linux and resource limits. 5. Avoid double globbing when ls-F needs to fork (Joe Townsend) 4. put back csh filec compatible support. 3. add support for quads in xprintf in the presence of gcc. 2. unlimit should set rlim.rlim_max to rlim.rlim_cur if max < cur. 1. Make ~user work again when the home directory is '/'. 40. V6.11.00 - 20010902 39. Completion fixes (Tom Warzeka) 38. make c_insert not static so that it can be used from win32 (amol) 37. Fix rmstar not to corrupt memory when we say no. (Mark Peek) 36. V6.10.02 - 20010806 35. polish nls locale (Pawe³ Niewiadomski)) 34. Fix a tcsetattr race running background jobs as the last line on an xterm window (Andrew Brown) 33. jobcmd alias (Greg Parker) 32. hpux11 support (Joshua Weage) 31. Fix SHORT_STRINGS compilation (Daniel Trinkle) 30. Add kill -s (Mark Peek) 29. Don't recognize all mips as dec (Bjorn Knutsson) 28. Fix GLOB_QUOTE problem (noted by Per) I introduced in 6.10.01. 27. Port to concurrent's powermaxos (Matt Majka) 26. New builtin srcfile (Amol) 25. Fix bindkey "\\" cmd (reported by Ismail H. Tuncer) 24. %0Xc was broken in the prompt if the user's home directory was '/'. (reported by Edward Glowacki) 23. V6.10.01 - 20010426 22. LARGEFILE support on Linux. 21. Add big5 multibyte support (Yen-Ming Lee) 20. Check the return value of setpriority (Dima Dorfman) 19. Avoid constructing paths with // on DomainOS (Nickolai Zeldovich) 18. Russian translation (Ilmar S. Habibulin) 17. Fix hostdefs for alpha support in FreeBSD (Andrey A. Chernov) 16. Add door support in colorls (Shaen) 15. Add BSD_STYLE_COLORLS for FreeBSD (Anand) 14. MAXHOSTNAMELEN needs to be 256 (Kris Kennaway) 13. Document stty -tabs problems on compaq (Nelson H. F. Beebe) 12. Fix broken comment, and new versions of config.guess and config.sub (H.Merijn Brand) 11. fix redrawing in the recognize case (Andrew Brown) 10. don't call qsort with 0 items. (Luke Mewburn) 9. fix echo;echo;echo; not outputing anything (Andrey A. Chernov) 8. Fix shell word parsing in dabbrev-expand (Per Hedeland) 7. hpux fixes (Chienting Lin) 6. Implement kill ring (Per Hedeland) 5. Avoid core-dumping when a very long $HOME gets passed in (Kris Kennaway) 4. Add rlimit_vmem for linux based on rlimit_as (N KomaZaki) 3. back out symlink=expand path check. 2. Add Estonian translation (Toomas Soome) 1. Accept empty $savedirs to mean infinity. 57. V6.10.00 - 20001119 56. Completion fixes (Tom Warzeka) 55. add missing linux kanji define (Tsuyoshi Kawabe) 54. More WINNT_NATIVE fixes (amol) 53. Fix compile error on winnt (Yoshiyuki Sakakibara) 52. nonstopux configure and makefile fixes (Tom Bates) 51. V6.09.04 - 20001111 50. Order of initialization for multibyte display was wrong (HyunChul Kim) 49. Follow the guideline for linux for japanese locale: http://www.linux.or.jp/JF/JFdocs/Japanese-Locale-Policy.txt (Tomohiro KUBOTA) 48. Ukrainian nls map (Olexander Kunytsa) 47. exit immeditiately if we get an error while we are setting up (Michael Shalayeff) 46. (unset path; unsetenv PATH; rehash) -> crash (Kent Vander Velden) 45. change winnt to winnt_native (Randolph Fritz) 44. Support home/end in the editor (Andrey A. Chernov) 43. Typo s/gycwin/cygwin/ in tc.os.h (Andreas Schott) 42. Alpha ev6 addition (Karen R. McArthur) 41. DSPMBYTE patch from (Issei Suzuki) 40. Security fix for here-doc tmp files (proton@ENERGYMECH.NET) 39. Fix resource limit rounding *again* (Johannes Gross) 38. Fix $ expansion in prompt (Takashi Sumiyoshi) 37. V6.09.03 - 20000715 36. cygwin port fixes (Arihiro Yoshida) 35. Add a new "catalog" variable that specifies which NLS catalog to be used (Issei Suzuki) 34. cleanup and addition of page up/down (amol) 33. fix vfork compile problem. 32. use inet_addr instead of inet_aton for portability. 31. V6.09.02 - 20000704 30. lots more completions (George Cox) 29. change FILSIZ to BUFSIZE [now that BUFSIZE >> MAXPATHLEN] and avoid a potential buffer overflow in sh.dir.c (Volker Schmidt) 28. _MINIX_VMD port (Martijn van Buul) 27. inet6 handling for remotehost and configure (Hajimu UMEMOTO) 26. aix-4 does not need gethostname (Darren Reed) 25. IBM OS/390 Unix Systems Services support (Peter Prymmer) 24. Fix prompt formatting (Andrey A. Chernov) 23. Use HostType from Imakefile correctly (Kjetil Torgrim Homme) 22. Handle long and expanded history lines better (Boleslaw Ciesielski) 21. With symlinks=expand expand valid paths only (Martin Kraemer) 20. Make one-byte charsets work with KANJI (Andrey A. Chernov) 19. NT-specific executable detection moved to NT code (amol) 18. New "complete module" (Dan Nicolaescu) 17. Correctly display scaling string in limit error messages (Nathan Ahlstrom) 16. Don't display "unset watch" message when not appropriate (kim) 15. V6.09.01 - 20000114 14. Circumvent IRIX4D ESTALE bug by exiting. 13. IRIS4D de-linting. 12. Finnish nls catalogs (Jukka A. Ukkonen) 11. Even more multibyte fixes (Taga Nayuta) 10. Patches to statically link tcsh under solaris-2.6 (John Hawkinson) 9. Manual page typos (R. Bernstein) 8. HP/UX-11 (9000/800) HP/UX-10.20 (9000/820) (Haflidi Sigtryggur Magnusson) 7. Color-ls fixes (Luis Francisco Gonzalez) 6. Don't re-use time0 to compare to stat's st_mtime, cause it could be the value returned from times(2) which is the ticks since system startup (Frank van der Linden) 5. Time percentage wrap fix (Simon Burge) 4. EUCKR support (HyunChul Kim) 3. Grammar and typo fixes for tcsh.man (Steve Kelem) 2. More multibyte fixes (Rodney Ruddock) 1. Change 6.08 -> 6.09 where I missed it; update for utlrix 4.5 (Simon Burge) 65. V6.09.00 - 19990816 64. Add csh emacs mode (Dan Harkless) 63. Make sure the the glob buffer matches the word buffer size (Brian Biswas) 62. Fix periodic to work without tperiod set (Kenny McCormack) 61. V6.08.07 - 19990813 60. Fix e_dabbrev_expand (Bjorn Knutsson) 59. Make \builtin work again (by calling the command not the builtin) 58. Add NLS_BUGS for OS's that keep file descriptors open for NLS (Ian Dowse) 57. Make NONLSREBIND work after tcsh starts up. 56. Fix AIX stupid exit bug. (Dan Harkless) 55. More irix fixes (Kaveh) 54. V6.08.06 - 19990701 53. module command completion (Dan Nicolaescu) 52. Man command completion enhancement (Tom) 51. Fixes for irix configuration (Kaveh) 50. Support \a and \e in echo command. From (Keith Thompson) 49. Alpha configure nit from Kaveh 48. V6.08.05 - 19990511 47. In some system, when a builtin fails immediately after we start tcsh and before we print any messages, NLS messages fail (some descriptor might be closed) [FreeBSD, HP/UX?]. So we force reading the NLS catalogs in errinit() (Yoshiyuki Sakakibara) 46. typos in ja/set1 and ja/set29 (Yoshiyuki Sakakibara) 45. "dspmbyte autoset trap" support to HP-UX 10.20. (Yoshiyuki Sakakibara) 44. misnumbered NLS message in tw.help.c (Yoshiyuki Sakakibara) 43. colorcat variable for NLS color messages (Yoshiyuki Sakakibara) 42. autoconf fixes from Kaveh (and if it broke, me) 41. SGI irix fixes from Glenn Coombs. 40. Don't spin writing the history file when quota is exceeded (Rob McMahon) 39. V6.08.04 - 19990419 38. complete additions (John Gotts) 37. Port to amiga with geek gadgets (Arto Huusko) 36. Ignore case in setenv for windows (amol) 35. Bug fixes for NT unc stuff (amol) 34. Hash spell check (amol) 33. V6.08.03 - 19990211 32. Helpcommand documentation (Vladimir Alexiev) 31. small Y2K fix [%y in prompt would be formatted as 10 not 00 at year 2000], and new Itoa() code (Chris Torek) 30. OpenBSD m68k patches (Paul DuBois) 29. Avoid redefinition of getpeername on Solaris-2.7 28. fix problems with savedups=erase, savehist=merge (Randy Gobbel) 27. Don't set $shell to csh, if we were invoked as tcsh (Tomas Persson) 26. added $_ 25. added postcmd 24. V6.08.02 - 19981124 23. document continue and continue_args 22. wrong test in slowexec made NT optimization a noop (Amol) 21. Rhapsody fixes + separate CFLAGS/CPPFLAGS (Wilfredo Sanchez) 20. literals in both prompt at rprompt did not work properly (Taga Nayuta) 19. multibyte deletion fixes (Yoshiyuki.Sakakibara) 18. clean up key binding stuff for NT by moving the nt dependent code to the NT source (amol) 17. dspmbyte fixes for AIX, typos in man page and nls (Yoshiyuki Sakakibara) 16. Convex fixes (Ron Echeverri) 15. V6.08.01 - 19981025 14. SX4 port; this adds many casts for machines where ptrdiff_t is 64 bits. (Andreas Schott) 13. U/Win port; does not work properly with U/Win 1.6, wait for the next version (Chris Jones) 12. Sgi does not need gethostname prototype (John Bogan) 11. Logic in sh.dir.c was wrong for NT (Amol) 10. HP_CXD_SPP stat64 fixes (Scott Garee) 9. Documentation spelling fixes (Keith Thompson) 8. Documentation fix for savedirs (Amol) 7. Siemens OSD_POSIX fixes (Martin Kraemer) 6. include for all the BSD's (Trevor Johnson) 5. Multibyte display fixes for gnu ls (Taga Nayuta) 4. Configure/Makefile hesiod and bindir fixes (Dan Winship) 3. Use winnt not win32 in tc.os.h (Amol) 2. Cygwin32 port (Raj Menon) 1. Ported Fixes (Tom) 95. V6.08.00 - 19981002 94. where builtin nt fix (Amol) 93. V6.07.13 - 19980926 96. NT multibyte fixes (Amol) 95. NeXT needs getcwd. 94. fix new bug introduced by strncpy'fication in sh.dir.c (Taga Nayuta) 93. V6.07.12 - 19980918 92. add cray in configure script (Tom) 91. nls fixes 90. Avoid buffer overflows in directory code (kim) 89. Add multibyte character display support (Yoshiyuki Sakakibara) 88. Make tcsh use getcwd instead of getwd and supply a getcwd. 87. Fix remotehost again (kim) 86. V6.07.11 - 19980913 85. Leave remotehost ip addresses alone (don't try to resolve them) (Kim) 84. Read vs. force_read fixes (Amol) 83. Make colorls if color is set before the first LS_COLORS setenv (Taga Nayuta) 82. Use _PATH_DEFPATH on BSD4_4 systems. (Jim Bernard) 81. Cursor bounds checks (Michael Schroeder) 80. Syntax error nits (Michael Schroeder) 79. configure fixes (Michael Schroeder) 78. V6.07.10 - 19980904 77. Off by one error in NO_ERRORS... 76. Japanese NLS messages (Yoshiyuki Sakakibara) 75. Add ENXIO and EBADF in the test for write failures for Irix Zombies (Ralf W. Grosse-Kunstleve) 74. Missed a test for NOSTRCOLL in glob.c (Michael Liepelt) 73. Another ABSOLUTEP change (Amol) 72. Italian NLS messages (Massimo Bertozzi) 71. WIN32 fixes for ntslowexec and color_ls literal printing in prompt (Amol) 70. a few missed WIN32 merges (Amol) 69. defined YPBUGS for sgi (Kaveh) 68. V6.07.09 - 19980707 67. Separate the nt builtins (Amol) 66. completion fixes (Tom) 65. color ls fixes (Taga Nayuta) 64. V6.07.08 - 19980629 63. add config.h.in (Kaveh) 62. win32 updates (Amol) 61. warning and portability cleanups on the new changes (Kaveh) 60. V6.07.07 - 19980628 59. Fast execute by-pass for win32 (Amol Deshpande) 58. Clean up const usage a bit, and fix gcc 2.8.1 warnings. 57. Use @bindir@ for DESTBIN in Makefile.in (Edgar Hoch) 56. Avoid overflow in time builtin computation (Nobue Adachi) 55. Color ls additions (Taga Nayuta) 54. unsigned char vs. char warning fixes (Kaveh) 53. Solaris 64 bit fixes (fix directory offset bug) (Thomas-Martin Kruel) 52. More win32 patches (Amol) 51. autoconf lossage from (Kaveh) 50. V6.07.06 - 04/08/98 49. Collation fix for globbing (Andrey A. Chernov) 48. We might have NLS_CATALOGS and not LC_MESSAGES (Andrey A. Chernov) 47. 4.4BSD header fixes (Andrey A. Chernov) 46. Signed char prompt fixes (Andrey A. Chernov) 45. Pattern match fix for directory searches (Mike Patnode) 44. Pentium DGUX fixes (Miko Nahum) 43. Spanish nls message catalogs (Luis Francisco Gonzalez) 42. Fix trailing whitespace parsing in HASHBANG code (Martin Kraemer) 41. Remove stray debuggin message from unmatched substitutions. (from Amol Deshpande) 40. Fix reversed arguments in Usagae message. (from Amol Deshpande) 39. Fix bug introduced at tcsh-7.06.03 [expdollar] that affected %.n prompt format. 38. Fix typos introduced in last batch of changes. 37. Fix interrupted script using onintr, exiting parent shell problem. 36. Cleanup prototypes. 35. V6.07.05 - 10/28/97 34. Integrate Amol Deshpande's WINNT fixes to the tcsh source. Note that this is not complete yet; we are missing the NT glue code and the message catalogs. 33. Fix ^T at the first character in the line (Chuck Silvers) 32. Eliminate xsprintf and xvsprintf 31. Qmail patch from (Matthew Zahorik) 30. Added missing linux signals (Vadim Vygonets) 29. fixed problem where complete complete 'p/*/t:*.txt/' would not honor the pattern. 28. Port to an EBCDIC machine: BS2000 by Siemens Nixdorf that has an IBM/390 compatible processor (Martin.Kraemer) 27. Detect when we have errors writing to stdout (Vadim Vygonets) 26. Ignore quotes in the comparisons for builtins, so that \builtin works (Amol Deshpande). 25. HPUX, portability fixes; make sure that we have the right config file (Jonathan Kamens) 24. Don't do lookups for x displays and figure out ttys properly (Leonard N. Zubkoff) 23. make print_by_columns print in a single column when the output is not a tty 22. use rlim_t for Solaris2 (Casper Dik) 21. V6.07.04 - 05/04/97 20. set -f -l patch (Michael Veksler) 19. SGI patches (Tomasz J. Cholewo). Also fix completion code to take into account aliases that start with a period. 18. SCO patches (Boyd Lynn Gerber) 17. Fujitsu patches (Toshiaki Nomura) 16. autoconf patches (Kaveh Ghazi) 15. BSDI patches (Paul Vixie) 14. %Q formatting character addition. 13. Fix set=#123; echo $i:s/#// (Quoting problem) 12. V6.07.03 - 02/23/97 11. Understand %$variable in the prompt. 10. Quote directory names properly in .cshdirs 9. USE_ACCESS and autoconfig patches from (Larry Schwimmer) 8. Pyramid att config file (Andrew Lister) 7. $rprompt code (Luke Mewburn) 6. Kanji patches (Huw Rogers) 5. Cray T3E port (Jorn Amundsen) 4. Avoid html redirects in tcsh.man2html (from Kimmo) 3. HP/UX 10.0 fix for filesize resource limit; don't scale by 512 anymore. 2. Workaround for TIOCSTAT for NetBSD from lukem@netbsd.org 1. Return exit status from 0..255 not -128...127, as POSIX mandates. V6.07.02, 10/27/96 58. More configure fixes from Kaveh. 57. Fix histdup=erase again: Don't renumber events, or access uninitialized storage. 56. 6.07.01 - 10/19/96 55. Fix histdup=erase, where after some repetitions, we would get negative history events (kim@gw.com) 54. NLS fixes and typo in sh.err.c (Martin.Kraemer@deejai.mch.sni.de) 53. Output history in raw format in the history file (mveksler@VNET.IBM.COM) 52. Fix possible core dump when !: in autoexpand mode (rbrown@ERA.COM) 51. 6.07.00 - 10/11/96 50. Avoid stdio.h inclusion problem in SCO (gethost.c). 49. A bit of housekeeping in host.defs 48. 6.06.04 - 10/05/96 47. Fix tellmewhat() code to return true if found. 46. Change register foo to register int foo to avoid compiler warnings. 45. Fix problem with sticky non editing mode from Casper Dik. 44. history lex fix from Martin Kraemer; history events that ended with 0 were not properly parsed. 43. SNI fixes from Martin Kraemer. 42. SGI fixes from Ralf W. Grosse-Kunstleve. 41. BSDI2.1 fixes from Paul Vixie. 40. 6.06.03 - 09/24/96 39. undef TIOCGLTC for HP/UX 10.0 from Michael Shroeder 38. Sinix fixes 37. 6.06.02 - 06/22/96 36. Added implicitcd 35. Added configure.in and Makefile.in from Kaveh. 34. unset path, unsetenv PATH, ./foo did not work. 33. Add VAR_NOGLOB, and use it to avoid globbing directory names when cd'ing into them. 32. Fix bug introduced in the new tty parsing code. 31. Avoid pushing string back to the parsing string in ${ errors. 30. Patches for the manual page from Dave. 29. 6.06.01 - 05/24/96 28. Use sysconf to get NCARGS if available Robert Daniel Kennedy 27. Grab the program name and use that instead of tcsh in error messages. 26. Fix histdup, so that it does not leave gaps in the event sequence. 25. HP/UX v10.0 fixes: Don't use bsdtty.h and avoid clobbering memory since SIGRT??? is defined as -1. 24. Avoid coredumps when $TERMCAP exceeds 1024 characters Michael Schroeder 23. Fix memory clobbering when SHORT_STRINGS is not defined. Todd J Derr 22. Only restart stopped editors. Robert Webb 21. Recognize pts sysv ptys when checking to set autologout Bob Myers 20. Magic space incomplete modified core dump fix. Chris Metcalf , Bradley White 19. Linux nls fixes Rik Faith 18. SGI RS8000, Ported notes. Ralf W. Grosse-Kunstleve 17. Greek nls messages. Aggelos P. Varvitsiotis 16. Imakefile linux and libcrypt fixes. Jonathan Kamens 15. FreeBSD fixes Jukka Ukkonen 14. Expand the environment space for path Steve Kelem 13. Don't overwrite the environment randomly Steve Kelem 12. Don't turn the editor on when we have dumb or unknown terminals. This breaks emacs when compiled with terminfo Jonathan Kamens 11. Fix F- parsing in tc.bind.c (Bob Meyers) 10. Added -T option in history to force timestamp printing. -h alone does not print timestamps anymore for compatibility with csh. 9. Typo in tc.bind.c [with -DOBSOLETE] (misplaced parenthesis) 8. Recognize convex models properly. 7. suppress the DING! option using the noding variable. 6. negative nice values did not work. 5. Harris CX/UX 7.x support. 4. ERR_DMMODE was used on the crays but not defined. I changed the error messages in tc.os.c to use ERR_STRING instead, and fixed a missing error message in the catalogs. Someone will need to retranslate #30 and #31 in set23. 3. Bug setting listflags... Workaround: set listflags=(A /bin/ls) 2. Typo in Imakefile (# comment instead of c comment) 1. Typo in ma.setp.c (missing parenthesis) V6.06.00, 05/13/95 88. Cleanup off-by-one error ed.defns.c. 87. 6.05.09 - 05/06/95 86. Small memory leak in dosetenv() 85. Make sure that the number of editing functions defined is correct and abort otherwise. 84. Completion Fixes from Tom 83. Don't add yp stuff in the tilde cache [names that start with + or -] 82. Don't let children catclose() in xexit(), because the parent will lose access to the nls catalogs. From Michael. 81. 6.05.08 - 04/29/95 80. Update to the newest csh sh.file.c 79. More completions from Tom. 78. Fix the Imakefile to use XCOMM 77. Update for AIX 3.2. 76. French catalog from J.M.Vansteene@frcl.bull.fr (fwd Michael Schmidt) 75. Nls fixes and small typos from Michael 74. PDP11 BSD type fixes. 73. More manual page fixes. 72. 6.05.07 - 04/19/95 71. More NLS catalog fixes. 70. Bruce's jumbo patch. 69. 6.05.06 - 03/15/95 68. make clean does not clobber config.h if Makefile.std is used. make veryclean does. 67. New config define NISPLUS. Reportedly fixes vanishing output of ~expansion on solaris 2.4. 66. showdots has been removed; use listflags instead. [handles -x too] 65. more nls catalog fixes. 64. set histchars=,. did not have any effect in .cshrc 63. fix "-c command" new core dump. 62. more completions from Tom 61. call catclose() before exiting, so that svr4 cleans up the symlinks before exiting. 60. Per's fix for insert-last-word 59. Per's emacs abbreviation mode. 58. Makefile fixes for catalog stuff. 57. fixed again complete-word-raw and list-word-raw 56. 6.05.05 - 03/11/95 55. Made %?str work again 54. IRIX sigalarm problem should be fixed 53. complete-word-raw and list-word-raw should work 52. nls catalogs complete reworking. 51. sh.init.c: Signal complete rewrite. 50. Signal fixes from Bruce. 49. Added promptchars, like histchars; affect %# in the prompt. The first char is for the user and the second is for root. 48. 6.05.04 - 03/03/95 47. Add NODOT config, $command [that holds the command passed with -c] $GROUP and $group 46. AFS fixes from Larry Schwimmer 45. Real NLS catalogs from Michael Schmidt 44. patch to allow ^? binding. 43. completion patch from Paul DuBois. 42. Don't spell check in here docs. 41. Incorrect normalization of usec in sh.time.c 40. directory printing and option parsing fixes [from Paul DuBois] 39. realloc_searchlen should be static to avoid conflicts with OS's that use the same malloc package. 38. LOGINFIRST now applies to /etc/csh.login 37. Fixes in bind compatibility code to bindkey. 36. 6.05.03 - 01/17/95 35. Don't print the whole watchlist on startup. One can use explicitly the log builtin for that. 34. Don't display the $watch value in the log command. 33. Don't delete the unmatched portion if we try to complete a spelling error. 32. Solaris 2.4 workaround for isprint('\t') lossage (From Casper) 31. Fixed csh bug: [Reported by Jaap] set test="one\ two\ three" echo "$test:q" 30. Fixed the lossage in setting the looking mode in tw.parse.c before calling t_search; $x/$y will not append the right suffix. 29. Another attempt at the gethost timeout code. 28. Cray dmmode and filetests -m -k [need documentation!] 27. More manual patches. 26. Don't glob the path; security problem and core-dump. [from beto] 25. Avoid waiting for jobs that failed to restart, thus hanging the shell. eg, run job in background, attach to debugger; kill it inside the debugger. Get out of the debugger and you are stuck if you fg that job. 24. 6.05.02 - 09/04/94 23. remhost code could pass the wrong length to getpeername() 22. too eager sed'ing broke convex getwarpbyvalue() to getwarpbyvarval() 21. Fixed new bindings bug. 20. Fixed bug in newgrp code; execv was called incorrectly. 19. Take into account programmable completion hints when spell checking. 18. Unconditionally change stty modes in Rawmode() 17. Change date in $version to be ISO 8601 per Keith's suggestion 16. Fixed portability problems in the new counted-strings codes (From Kaveh) 15. Fixed binding problem with the new counted-strings code [all key bindings ended up in the extended map] 14. 6.05.01 - 07/08/94 13. Changed key bindings to use counted strings instead of Null terminated strings, so that binding ^@ works. 12. Fix parsing bug, where words that contained keywords caused incorrect word breaks: switch (iftagd) case iftagd: echo It works breaksw default: echo It is broken. endsw 11. Fix sh.c for systems with no job control. [the new hup builtin sends SIGCONT]. 10. Don't add the suffix character when all completions fail, from michael 9. Added histdup=erase, that deletes the oldest duplicate instead of the newest. 8. Don't call .logout recursively if we receive more than one hup, and don't process hangups when we execute the .logout. 7. $logout was set to a static string. 6. Non printable binding listing was broken. 5. Recursive sourced scripts would get mangled up because of input buffer confusion (thanks michael) 4. M-space should not be counted as a space. Leads to infinite loop in word splitting. 3. Pyramid fixes. 2. Fixed '\' in sysv echo (from Mika) 1. Missed fix_yp_bugs() when setting REMOTEHOST (From Casper) V6.05.00, 06/19/94 113. 6.04.17 06/18/94 112. Realloc debug fix from John. 111. Completion fixes from Bruce. 110. Added -b option to bind. 109. Added tcsh.man2html from Dave. Looks great! 108. 6.04.16 06/06/94 107. Allow multi word glob in "`foo`" expressions. > if ("`ls`" == "a b c") then 106. Michaels lex() buffer patch version 2. the previous version core-dumped with > sleep | echo 105. Fix seg fault in find_cmd, when path is unset. 104. 6.04.15 05/28/94 103. the previous =~ fix, was a bit broken. 102. 6.04.14 05/25/94 101. expression parser fix for !~ and =~. if (foo =~ *) echo ok the * was taken for a multiply and parsed as 0 * 0 returning 0. and asked to match "foo" with "0" 100. Michael's lex() buffer patch. 99. Bruce's Jumbo cleanup 98. fixed Imakefile for X11R6 97. fixed argument parsing in source command. 96. added $sched to format scheduled events. 95. 6.04.13 05/07/94 94. added expand-command 93. Alpha OSF-2.0 fixes 92. 6.04.12 04/28/94 91. Ignoreeof patch from Bruce. 90. Dan's completion fix. 89. 6.04.11 04/12/94 88. Don't source .logout when killed with -HUP unless we are a login shell. [ actually $loginsh controls the behavior now ] 87. ISC-4.0 posix exec() bug workaround (from Jonathan Broome ) 86. Dan's patch for complete=enhance 85. Kaveh's patches for memset, host.defs, _{U,G}ID_T 84. 6.04.10 03/29/94 83. Pathname completion bug fixes... 82. Completion pathname(p) changes: Completion 'C' -> 'X'. Replaced 'p' with 'F' and added D,T,C. 81. Next NLS fixes (From Paul Nevai ) 80. make spelling correction obey the current histchars setting. 79. Fix rounding in limits so that 0 is a true 0. (From Ken Lalonde ) 78. 6.04.09 03/12/94 77. Alarm race with remotehost. 76. If you have in your .cshrc set savehist=(100 merge) and execute #!./tcsh exec ps you get no output; [fixed] 75. setenv SHLVL -1; tcsh = Segmentation fault [fixed] 74. 6.04.08 02/10/94 73. new machtype, ostype, vendor 72. execute .logout on hangup. 71. more man page fixes. 70. 6.04.07 02/04/94 69. Dynamic hash changes, globbing for which command from Michael. 68. INBUFSIZE fixes for history. 67. printenv returns 1 when a variable is not found, like the non builtin one 66. Add quotes to the mismatch array so that: > touch foo > mail "oo bar" does not get corrected. The right fix would be to do correct parsing and quote the space... 65. NULL terminate mismatch[] array in ed.inputl.c, since it is used in Strchr(). 64. renamed stat to filetest 63. Afs and Hesiod patches. 62. More manual page patches. 61. 6.04.06 12/19/93 60. Alarm for resolver timeouts (untested) 59. Fixes for Henry Spenser's regex in the Makefiles 58. Modifiers now work with $< and $< does not do :q by default. [incompatibility with csh] and $< can be interrupted. 57. Added $histdup. 56. source /etc/.login for Solaris 2.x 55. don't remove trailing spaces in history searches. 54. dirs -L and dirs -S spurious warning elimination. 53. man page fixes from David. 52. Kimmo's patch [makefile, gcc warning, netdb.h include] 51. 6.04.05 12/12/93 50. rewrote srcunit() to use st_save and st_restore. The code was too messy to be useful before. 49. recdirs and rechist patches again! 48. Harris hck port, and ISC imake update 47. Eliminate the x windows :display.screen before looking for the hostname in REMOTEHOST 46. Patch for CDF filetype() recognition (hpux) 45. 6.04.04 11/12/93 44. Made =x obey nonomatch. 43. Fixed rechist and recdirs not to depend on savehist and savedirs 42. Removed aliases, bind, linedit builtins [ifdef'ed out as OBSOLETE] 41. change REMHOST to REMOTEHOST for compatibility with SGI. 40. $owd was not working correctly. 39. Debugging printf elimination (from Kimmo) 38. Typos in the new hup code in sh.c (from Matt) 37. Imakefile fix for sequent (from Jaap) 36. 6.04.03, 10/30/93 35. New manual page in place. 34. Fixed Makefile sed RE to work with gnu sed. 33. Added hup builtin. 32. Added $REMHOST in config_f.h 31. Fixed random parsing bug in sh.exp.c in isa(). It checked cp[1] without checking cp[0] first... (should propagate to 4.4BSD) 30. More sh.exp.c fixes from Bruce 29. Always exit when the user types exit. cat | tcsh -f -s exit ls 28. savedirs fix and readlink() null termination fix from Peter. 27. Added -p flag (force dirs printing in all directory functions and $owd variable 26. Let $dirstack work by default without needing to be set. 25. Fixed history -h to work with other history flags. 24. Renamed ed-functions more consistently (dcs) 23. Added missing filetests (dcs) 22. Added NEWGRP define in config_f.h (dcs) 21. More fixes for non blocking io recovery from Bruce 20. 6.04.02, 10/08/93 19. changed default prompt to %# 18. New group 'g' completion. 17. removed IIASA defs. 16. fix for history -SL and dirs -SL to work when savedirs and savehist are not set. 15. fix magic-space to understand :p 14. make :u,:l work for history. 13. Fixes for non-blocking i/o recovery. trap all non blocking styles under sunos. 12. 6.04.01, 08/10/93 11. Vi mode word moves [they work like vi and don't obey wordchars anymore]. 10. New file operators and stat builtin 9. David's FIONREAD patch for SVR4 8. Bruce's ignoreeof=n patch 7. Dan's complete/correct enhancement 6. Abort corrections patch. 5. Print_by_columns, now does not use the rightmost column. 4. Renamed config/config.$i to $i to avoid once and for all filename length problems. 3. bbn butterfly config 2. Beto's proc fixes 1. Bruce's bug fix for ed.chared.c, signals V6.04.00, 07/03/93 92. Alpha prototypes, for gcc -Wall clean compile. 91. Fixed alpha hashing. Did not work for directories > 31, Thanks to Dan Mosedale for all the help! 90. Added USE(a) for unused parameters, to avoid compiler warnings. 89. 6.03.10, 06/25/93 88. Makefile and lint patches from Bruce. 87. Posixsig patch from Peter for svr4 86. 6.03.09, 06/11/93 85. signal handling broke with the last job control patch... > (does-not-compute;) would hang. 84. don't quit after the first modifier fails: > set i=aabbcc > echo $i:s/a/A/:s/b/B/ AaBbcc > echo $i:s/x/A/:s/b/B/ aabbcc 83. Imakefile fixes for sequents from Jaap. 82. Move past the bottom of input when we hit ^C, so that multi-line input commands don't get trashed. 81. Look only at the first word in ${EDITOR,VISUAL} to determine the editor name. 80. Last patch broke listmax. 79. Remove extra sandbagging in exitstat(). Not needed anymore as value() will never return NULL. 78. Save $status before calling aliasrun() otherwise: > alias precmd 'cd .' > true > echo $status 0 > false > echo $status 0 77. 6.03.08, 06/07/93 76. missing prototypes/unused variables under SYSV4. 75. savedirs should glob the filename argument. 74. 6.03.07, 06/05/93 73. Changed _Q, _Q1 macros in sh.lex.c, sh.dol.c, sh.char.? to _QF and _QB because today 4.4BSD defined _Q to be ``Phonetics'' 72. listmaxrows variable. 71. set -r would not make existing variables readonly. 70. print usernames with ~user where possible in dirs and job cwd's 69. Mika's fixes (missing args in sh.c set(), linux Makefile, SIGCHLD) 68. FIONREAD argument is int everywhere except on SunOS where it is long. Tcsh used to think that it was long, and so it broke on the alpha where sizeof(int) != sizeof(long) 67. 6.03.06 05/16/93 66. Pipeline fixes. This should get rid of the dreaded Stopped tty output message. 65. Michael's fix for history buffer cleanup: > alias foo 'echo \!:1:h' > foo a/b a > ^P [nothing happens] 64. Unsigned long rlimit type for 64 bit machines (alpha) 63. Fixed Imakefile for alpha 62. tilde expansion now obeys $nonomatch 61. readonly veriables. 'set -r x=3' will set x to a very sticky 3... 60. Fixed bug in the new tab'ed completion that interfered with old listing. 59. Fixed entry -> item in tw.parse.c 58. Added -f option to unlimit 57. Define __STDC__ in Imakefile for Irix 56. Static redeclarations in tw.parse.c 55. 6.03.05 04/26/93 54. Don't echo history expansion in loops: > alias junk 'foreach i (\!:2*) \ foreach? echo \!:1 $i; \ foreach? end' > junk a b c d echo a $i ; a b echo a $i ; a c echo a $i ; a d 53. Added complete-word-fwd and complete-word-back that scroll through the list of possible completions... Neat addition from jfink@csugrad.cs.vt.edu (Jeff "$DOTDIR" Fink) 52. Workaround hpux9.01 broken optimizer in sh.glob.c where 'ls *' breaks. 51. Michael's editor fix. With "magic margins" and 80 char width, try: > set prompt= 20aa76bac 50. Reverted fix that does not glob the expanded back-quote text again. 49. > cd /., echo $cwd /. Eliminate the . in this case... 48. Matt's optimization in glob.c [retracted] 47. Fixed bug with -S 46. Renamed Makefile Makefile.std, and fixed the readme file 45. 6.03.04 04/07/93 44. Changed -s == !-z and -S == socket 43. Fixed typo in sh.c, in phup [shpgrp != pr->pgrp] 42. Multi-line aliases are not entered into the history when executed. 41. Changed f_seek to a union to avoid gcc warnings on 4.4BSD 40. Fixed 'unset home; dirs' bug 39. fixed $HOME->$home memory problem. 38. $?0 returns false now on interactive shells for csh compatibility. 37. Default watch inteval was 10 hours not 10 minutes as advertized in the manual! 36. Fixed clobbered veriable warning from gcc-1.39 in tw.parse.c 35. Fixed typo with INVPTR in sh.lex.c 34. 6.03.03 03/04/93 33. Eliminate 'Reset tty pgrp error message'. It is normal for the walking process group stuff. Check about the killpg() above? 32. More portability for 64 bit machines. 31. Improved completion error messages. 30. Fix bug with double globbing expansion on mirrored variables: > setenv TERM '?vt100' 29. Avoid hanging when writing to pipes etc. (From Paul Close) 28. Typo in the $HOME->$home mirroring. 27. %p %P 'p'recise time formats that include seconds for prompt strings. 26. Signal list fixes from Paul Close. nsig is now a variable. 25. 6.03.02 02/12/93 24. NEC SX3 "entry" is a reserved word!, changed entry to item... [this is as bad as cray typedefining "word" to int. Next thing I know, I'll have to prefix all the variables with tcsh_!] 23. xxx 22. Protected all include files to avoid warnings from lcc. 21. Finally resolved the job control problems with linux and ISC (from Beto) 20. More HUP,XFSZ,XCPU fixes. (with Beto) 19. Dcanon would not canonicalize correctly in case where dnormalize() failed to find a directory, but the directory existed when not crossing the symbolic link. 18. sh.init.c fixes; give 65 signals for all POSIX machines. 17. AMS mail fixes and cmu wm handling. 16. Setenv would not ignore trim quoted names... > alias foo 'setenv "\!:1" bar' > setenv FOO 123 > foo FOO > printenv ... FOO=123 FOO=bar ... 15. 6.03.01 08/01/93 14. #undef SHORT_STRINGS gcc warning fixes... 13. csh bug fix in foreach [quoteing problem] > foreach i ("*") > echo $i:q > end Should print * 12. ls-F obeys showdots... 11. After scheduled commands get executed, the editor could stay disabled until the first enter. 10. sigset() bug in ed.init.c; ^C could get disabled sometimes. 9. Don't glob in dowhich(); otherwise \pat does not work if pat is aliased. 8. When completion patterns are used $ and ~ expansion did not work right. 7. Printenv builtin and long backquote expansion fix from Harald. 6. $:-1, $:-0 enhancement from Paul and Michael. 5. Lynx/OS patches 4. Apollo bugs [Setenv -> tsetenv, typedef in pid_t] 3. ^@ did not work correctly in bindkey. 2. Fix vms/posix ifdefs in tc.alloc.c 1. Elide gcc-2.3.1 warnings V6.03.00, 11/20/92 102. Solaris2 patches, renamed sunosX to sosX to fit in 14 character filenames. 101. 6.02.12 11/12/92 100. Decreased BUFSIZE to 1K... 99. Don't use sbrk() in tc.alloc.c on VMS 98. EINTR error handling from Michael 97. Overwrite mode takes effect immediately, not delayed by a command. 96. Emx fixes. 95. SIGHUP gain... 94. Coherent times()/ fixes. 93. 6.02.11 10/27/92 92. Mach setpath fixes. 91. Which now globs its arguments 90. Again POSIX SIGHUP fixes... Maybe we got it right this time... 89. Increased BUFSIZE to 4K. Smaller machines may want to decrease this. [ Now one can edit up to 4K of buffer! ]. From Harald. 88. : is now a true builtin that does nothing, instead of being treated like the last character of a label. This is so it can take args. From Harald. 87. More fixes for hpux limits from Harald. 86. Login shell if ppid == 1 and argc == 1 for VMS. 85. Typo in sh.exec.c from Harry. 84. Per's editor fixes. 83. 6.02.10 10/17/92 82. Don't free STRNULL in freelex(). Update linked list in copylex() to do the same insert as in lex(). 81. Fixed spurious tilde printing in %c prompt. 80. Fixed dumb wild free in AddXKey... (thanks Harald for the complex bindings! :-) > bindkey "\e10z" expand-line # Any editor command will do > bindkey -[cs] "\e10z" "foo" # Any string or command will do Free(%x) .... 79. coherent additions. 78. fixes for hpux8 resource limits [Thanks Harald] 77. 6.02.09 10/10/92 76. More vms cleanups. 75. Removed #include CONFIGH from sh.h. There was no way to make it work under VMS/POSIX 74. Added t completion (Gray Watson) 73. Memory leaks in sh.dir.c and sh.glob.c [thanks purify :-)] 72. IRIX 5.0 patches (from Paul Close) 71. BSD resource limits for hpux8.0 (From Andreas Stolcke) 70. NGROUPS_MAX fixes (from Matt Day) 69. 6.02.08 10/04/92 68. VMS port additions. 67. Added $%var, which == strlen(var) 66. Added ^X^I and ^X^D to override programmable listing+completion 65. Added case insensitive globbing for OS/2 64. FIOCLEX and FIONCLEX are only used if we don't have FD_CLOEXEC. 63. Added emx termio support, and emx pathsep support; emx compiles and runs: needs job-debugging and finishing touches. 62. Horrible bug with the lex linked list; from Loic Grenie, grenie@ens.fr > echo a !# echoed 'echo a echo a echo'! 61. Shell -w,-x were incompatible with the same for test [POSIX] (beto) 60. builtin newgrp did not accept the - argument. 59. FIOCLEX for the masses (POSIX FD_CLOEXEC addition) 58. Old style csh completion bug fix [not used] (beto) 57. A background process waiting for input from tty blocks when being foregrounded doesn't read its input and doesn't get and signals. It can only be killed from another session. (beto) > cat > foo #!/bin/csh -f echo ">>>>>>" set x = $< echo $x ^D > chmod +x foo > foo & > fg ^Z,^C # Nothing happens 56. history > 1000 fix (beto) 55. 6.02.07 9/18/92 54. Added e_stuff_char() to put back a character in cooked mode in the input stream... Useful for status (^T) 53. $? == $status and $# == $#argv like in the bourne shell. 52. Added $dirstack. Problems: off by one since =0 == $cwd, but $dirstack[1] == $cwd... Suggestions welcome. 51. Leading spaces would confuse the run-help function. 50. Don't expand imported environment variables: > setenv HOME \* > tcsh > echo "$home" > echo "$HOME" 49. %C0n displays the number of directories omitted as /usr/local/bin /<2>bin/ 48. Added POSIXSIGS as a configuration option. 47. Per's fixes for history format and arrow key binding. 46. Expand-variables expands array variables too 45. 6.02.06 8/14/92 44. Separated limit stuff from BSDTIMES and added BSDLIMIT 43. History searching inconsistent with HistLit: > echo foo foo > ^foo^bar bar > ec[M-p] echo foo 42. 6.02.05 8/8/92 41. sourcing a script that contains 'onintr -; onintr' would disable interrupts on the command line 40. cd ../... with symlinks=ignore would work !@#!@ 39. No more BACKPIPE for POSIX machines... 38. SUNOS NLS bug workarounds... 37. New HASHBANG define for #! emulation... even 386BSD does not have it yet... 36. Added new -b -c file operators from SGI csh. 35. 6.02.04 7/23/92 34. Walking process group fixes. 33. $0 contains now argv[0] when we are not executing a shell script. 32. New Getwd() was broken. 31. 6.02.03 7/17/92 30. We kill our last foreground process group on HUP, for POSIX systems. 29. Walking process group fix. 28. $shlvl gets reset to 1 for login shells. 27. Macros can now involve multiple commands, i.e. bindkey -s "^[OP" "ls\n^P" 26. 6.02.02 7/6/92 25. nostat accepts now a list shell patterns. 24. Avoid print_exit_value in if ( { foo } ) 23. Symbolic key names for bindkey [arrow keys]. 22. Smarter getwd() that avoids some of the NFS hangs... 21. Use memmove() where possible. 20. 6.02.01 6/16/92 19. Fix automatic correction to work with the new completion. 18. Globbing bug with brace expansion, when arguments need to be realloced... e.g. echo 134{6,7}{0,1,2,3,4,5,6,7,8,9}{0,1,2,3,4,5,6,7,8,9} 17. shift and left operators update variables correcly ('shift path' did not work) 16. apollo fixes for cd. 15. STRNULL <-> NULL bug fixes. 14. %S in xprintf for short strings. 13. history -LSc, dirs -LSc additions, builtins builtin [oxymoron] 12. history formatting string, who formatting string, prompt formatting all use tprintf() now. 11. $history accepts a second formatting argument.. 10. History timestamps preserved in .history 9. Backquotes were broken: echo hi | cat > `echo foo` 8. SGI -t operator problem. 7. Dnix fixes. 6. Fix history file writing bug when autologout. 5. Change from TCSETA to TCSETAW, since we affect the output. 4. Per's fixes for display margin bugs. 3. Linux fixes. 2. Collapse adjacent stars in glob.c to avoid exponential behavior. 1. Fixed parseescape to put ^ literally if not followed by alpha. V6.02.00, 5/15/92 94. Default echo_style was not being set correctly. 93. $< did not work correctly with NLS chars. 92. 6.01.15 (5/11/92) 91. Minor cleanups in refresh code. 90. 6.01.14 (5/8/92) 89. Print \n in the right margin always to be consistent. 88. Linux patches. 87. 6.01.13 (5/2/92) 86. Fixes in listing and completion of non-unique commands. 85. Fix =stack entries > 9... from Bill Petro 84. Fix for last character at margin. [on terminals that have am & xm move the cursor manually to the next line] 83. Fix for complete completions 82. small typo in tc.alloc.c from Mark Moraes. 81. small typo in tw.parse.c from Richard. 80. Man page fixes from Per. 79. 6.01.12 (4/24/92) [release version for 6.02] 78. Autosuffix was not getting reset all the time. 77. Don't limit completion patterns to 1K. 76. Naming changes in ed.screen.c from Justin. 75. 6.01.11 (4/10/92) 74. Fixed magic-space ! expand bug: > echo a b123 45.{6,7} > echo !:2!:3[magic-space] 73. Work-around for apollo optimizer in tc.bind.c 72. Problem with setjmp in tw.parse.c 71. symlinks=expand from Yumin. 70. tenematch() fixes from Michael; 69. 6.01.10 (4/3/92) 68. Fixed Gnmatch. 67. Removed ignore_symlinks and chase_symlinks. Replaced by symlinks variable. 66. Backquote from completion was broken for machines with no dup2() 65. No $printexitvalue for `` jobs. 64. Added ultrix stuff for PW_AUTH [from Mike Potter mpotter@lampf.lanl.gov] 63. Fixed bug in Gnmatch(), added 'N' command 'x' completion. 62. Fixed fg_proc_entry() so autologout gets disabled when a process is foregrounded. 61. 6.01.09 (3/26/92) 60. source builtin takes arguments now that are passed in the script e.g.: > ./tcsh -i a b c > cat test echo $argv > echo $argv a b c > source test 1 2 3 1 2 3 > echo $argv a b c 59. Eliminate $margin_bug, add more intelligent margin code [from Justin] 58. expand_symlinks variable Urgh... 57. SGI CONTROL() fixes... 56. new dnormalize(), expand_symlinks flag. 55. interrupting completion restores the current line. [from Marc] 54. 6.01.08 (3/20/92) 53. inputmode affects the first line too. 52. Searches in vi do not destroy the current line. 51. -drwX test enhancement. 50. Generalized completion syntax and added more completion builtins. 49. Don't print '\n' on the right margin if we can avoid it. 48. 6.01.07 (3/9/92) 47. New completion style. [[[ ]],=] 46. 6.01.06 (3/7/92) 45. complete styles are ignored after shell metachars eg. > complete mail =u > mail christos < [tab] completes filenames. 44. $echo_style is initialized to the default style of the machine. 43. SGI 4.0 CTRL() macro is busted. So we ignore it. 42. Fixed bug with the new margin code (thanks justin) 41. Fixed mirroring of variables. Now set and setenv affect HOME, TERM, PATH, SHLVL, USER and their csh counterparts. Unset affects affects only the csh copies of the variables, and unsetenv only the environment variables. 40. Fixed gcc-2.0 warnings in sh.sem.c (needed for vfork() -O2 optimization) 39. 6.01.05 (2/21/92) 38. signal masking for BSD machines was still wrong in tw.init.c 37. Added $margin_bug, and now the editor outputs on the rightmost column by default. This should fix the xterm cut-n-paste problem. 36. AU/X 2.0 and SGI compiles with POSIX as a default now. 35. sysv_echo is gone too. Now we have a variable called echo_style which can be set to "none", "bsd", "sysv", "both" that defines the builtin echo_style. The default is "bsd" for systems with SYSVREL == 0, "sysv" otherwise. This can be overriden in config.h by defining ECHO_STYLE ro be BSD_ECHO, SYSV_ECHO, BOTH_ECHO, or NONE_ECHO. 34. asynchronous notification in run-fg-editor would try to change the tty settings and print an extra prompt. > set notify > sleep 10 & > vi^Z > ^[^Z 33. alias x /bin/true x? reported .//bin/true instead of /bin/true 32. 6.01.04 (2/12/92) 31. fixed vi_substitute_line 30. binding completion addition. 29. showdots=-A addition 28. sysv_echo addition; deleted bsd_echo which is now the default. 27. dunique could crash. 26. Don't clear lines after an asynchronous notification, because it might erase the message. 25. 6.01.03 (1/29/92) 24. `` were not working correctly when tcsh is started with 0,1,2 closed. 23. Correction was picking up the wrong thing in cases like .rhosts hosts 22. Correction with names with quoted spaces was broken. 21. Added sysv_echo and bsd_echo. 20. Added and documented the complete builtin. 19. Added dunique and cd -. 18. Per's fix for alarm functions. Things would break if time went backwards. 17. Realloc bug fix (copy min of old and new size) 16. Fix for csh compatible braces. 15. Brace globbing and negation globbing for Gmatch. 14. 6.01.02 (1/16/92) 13. Completion builtin, new tw* files. 12. 6.01.01 (1/6/92) 11. Changed w_ fields in tc.who.c to who_ to avoid redefinitions in in some os's. 10. Setting savehist to an empty string makes savehist use the value in $history. 9. echotc did not use the internal termcap descriptions. 8. echotc did not work right for single argument termcap strings. 7. DGUX needs SAVESIGVEC, updated type protection, and disabled CSWTCH. 6. Changed SVID to SYSVREL, since there is no SVID == 4 (yet). 5. Typo in tc.sig.h: UNRELSIGS was not getting defined. 4. Globbing bug fix. tglob() should ignore globbing characters inside backquotes otherwise things get expanded twice: % echo 'bar?' > 'foo?' % echo `cat foo\?` echo: No match. 3. Mach setpath fix. 2. Alliant process group fix. 1. Xenix fixes for broken vi and help path with no suffixes. V6.01.00, 12/19/91 [for comp.sources.unix] 22. Restore the original prompt in automatic correction when the user asks to re-edit the command. 21. Better error for unreadable files in tw.parse.c 20. Sequent patches. 19. (V6.00.08 beta 12/14/91) 18. Filenames containing # were spelled/expanded incorrectly. 17. Stellar/stellix port. 16. Hpux 8.0 has SIGWINDOW but we cannot get the window size. Protect against window changes updating $LINES and $COLUMNS. 15. Mach setpath did not work right. 14. Mach does not need setenv in lib; in fact that does not work right. 13. shell level gets decremented when we exec. 12. restart_fg_editor picked the wrong editor if arg contained a slash. e.g vi ~/.cshrc 11. (V6.00.07 beta 12/08/91) 10. Allow use of vfork() on systems that do not have job control. 9. Avoid NUMCC from being defined twice. 8. (V6.00.06 beta 12/05/91) 7. SunOS3's FIOCLEX dups... 6. Yet another globbing bug fix from Michael (echo .[^.]) 5. Ultrix now wants __ before cpp symbols. 4. Workaround sun's header files inconsistency so tcsh can be compiled with #undef POSIX 3. Fixed limit stuff so that large values don't cause errors. 2. Fixed =1 and ~user error messages (Per) 1. (beta-5 6.00.04 == 6.00.05) $#* $#* New numbering scheme (The last 2 digits are reserved for beta releases $#* from now on. So we start at 6.00.06 which is 6.00.04 beta 6, and we are $#* going to release 6.01.00... $#* V6.00.04, (never released) 34. (beta-5 11/25/91) 33. Simplify code in BindArrowKeys() 32. Get rid of the PNULL's 31. Support for shadow password in locking code. (From Kimmo) 30. Normalize-path editor function. 29. (beta-4 11/21/91) 28. minix additions 27. bindkey fixes (-c addition, casting cleanups) 26. (beta-3 11/16/91) 25. Prompt length checking. 24. Michael's fixes for the watching code. Tcsh could core dump when using a corrupted utmp. 23. overwrite mode flag, and autologout locking code. 22. overwrite mode would still insert digits! 21. Get the value of _POSIX_VDISABLE from pathconf... 20. Hpux 8.0 fixes. Sigstack botches with shared libraries. Ansi mode static initialization of structures with prototyped function pointers gives spurious warnings... 19. Onintr in /etc rc files is disabled. 18. (beta-2 11/03/91) 17. Multi-line aliases with `` bug fix. 16. Sticky emacs overwrite mode. 15. Autolist option. 14. Fix for redirection with wildcard filanames. 13. No error correction for multi-line commands. 12. Esix-4 re-defines p_pid. Argh... 11. (beta-1 10/28/91) 10. Foreach loops were broken again. 9. SUNOS localtime() bug does not only happen on the 8th byte. [Michael] 8. sh.dir.c, memory corruption in dinit(). Thanks Michael. 7. uts broken work-around, and has a wait3() 6. SGI (-t filename) extension, returns true when filename is a tty. 5. 'default:' addition in all switch() statements. 4. oflag was not being updated correctly in Rawmode() 3. missing 'break;' in prompt code '%y'. 2. infinite loop in :a code. 1. hashstat was not reporting hits+misses V6.00.03, 10/21/91 31. watch code now accepts shell patterns. 30. new hashing code portability fixes. 29. $foo:gs/:/ / fix and 'a' modifier addition. 28. Added $! (the pid of the last background job forked) 27. exec does not kill the shell when it fails. 26. Irix4.0 decls. 25. SVR4 uthost fixes from Kimmo Suominen 24. Imake addition from marc 23. New i-search from Per. 22. ibmesa fixes 21. convex fixes. 20. t command for vi. 19. SVR4 fixes (reverse pipeline and sigaction()) from David Dawes. 18. New hashing from Marc 17. Added : to the ~name separators so ~foo:~bar works. 16. New ed.init.c. Added ed.term.c 15. Still can't get the history exactly csh-like... !-2$ was broken... 14. vi character searches. 13. -Dvar=name command line option for the apollos. 12. Prompt format changes for date/directory. 11. Vi searches. 10. Emacs i-search. [currently not bound] 9. Vi additions ([dc]-{w,$,f},Undo) 8. tcsh -n parses now builtin structures. 7. seek to the end on errors in loops. 6. echotc -s was broken 5. Better !event parsing. !foo;!bar was broken. 4. foreach loops and if statements in aliases. 3. .cshdirs would corrupt the heap if some directories were not there. 2. System V echo was broken with \ 1. Fixed echo '!-1', history would eat the quote. V6.00.02, 08/05/91 [For comp.sources.unix] 8. tcsh will always set $LOGNAME and $USER if not already set in the environment. 7. added $histfile. 6. echo `echo` * and echo ~ {} were broken 5. setty builtin addition 4. Multiple : modifiers [experimental, disabled with -DCOMPAT] 3. 7 bit fixes, and hp9000s500. 2. #undef DEBUG in tc.alloc.c, so we continue if we get a bad free() 1. getn() is now protected against NULL strings. V6.00.01, 07/16/91 17. added beepcmd, and fixed small tenematch bugs. 16. Renamed DUP2 flag to HAVEDUP2 cause AIXPS2 defines DUP2 already. 15. More ANSI fixes, and mit additions (load-average) 14. don't clear ECHOE, background programs might need it. 13. Refresh bug fix... 12. getpwent() should not be interrupted (yellow pages), cause it might leave dangling pointers, that endpwent() will trash. 11. ChangeSize is now responsible to set the screen size to something sane, but it should not affect the environment if the information it received is not valid 10. Find out if we are running under emacs using $TERM. It is more reliable. 9. tcsh was broken if SHORT_STRINGS was not defined (glob() problem) 8. If GetSize() fails it should always return reasonable screen sizes. 7. globbing should not fail if one or more patterns match. 6. increased the number of aliases in the loop detection code. 5. DGUX has size_t and pid_t defined now... 4. ESIX does not have EWOULDBLOCK or EAGAIN & POSIX... That was not handled correctly. 3. rs6000 needs BSDWAIT. 2. Hpux susp key could not be changed. 1. Apollo fixes. V6.00.00, 07/04/91 45. Fixed quoting of VSTART/VSTOP on termios 44. Memory leak every time you pipe in or out. 43. echo {foo bar.[ch]}. Did not check for end of word. 42. ANSI prototypes 41. dmove() would leave the source descriptor open when using dup2() e.g. while (1) echo foo >>! bar end runs out of file descriptors 40. recursive `` expanded via aliases would abort. 39. set home=../relative-path-name was broken. e.g. set home=../..; cd ..; 38. Incorrect error when changing to directory: e.g. mkdir not-in-cd-path; chmod -x not-in-cd-path; cd not-in-cd-path; echoed: not-in-cd-path: No such file or directory. it should have said not-in-cd-path: Permission denied. 37. if ( \! =~ [\!] ) echo ok, did not echo ok. Quoting inside [] pattern. 36. More than 127 jobs caused job # to go negative 35. unsetenv ... Added support for more than one pattern. 34. More background process status report fixes. 33. Apollo builtin support. 32. Glob fix. echo '*' * was not handled properly. 31. Glob fix. setenv FOO `sleep 1` would either cause a segmentation fault. or print ambiguous. 30. Glob fix. Quoted characters inside [] were not handled properly. 29. Removed TELL and VMUNIX defines. I think we cannot compile on V6 anyway 28. Overflow check for expansions. 27. Added matchbeep, shell pattern history searching. 26. Added code to handle /dev/std{in,out,err} 25. Fixed POSIX speed handling in raw mode. 24. Fixed a flushing bug in the filec code in sh.file.c 23. Compiled and added hp9000s700 to the list of hosts. 22. Fixed horrible bug in gmatch() switch (4) case [a-z]: echo bug; breaksw; case 4: echo ok; breaksw; endsw 21. Fixes for _SEQUENT_ ut_host. 20. FLUSHO added 19. mkdir foo\`bar; cd foo\`bar; was broken 18. EWOULDBLOCK == EAGAIN on RENO check for that too. 17. Dword() simplified and removed the gotos. 16. Hpux now compiles with POSIX. Moved the local chars modes in ed.init.c after the tty modes. 15. Process group fixes for POSIX 14. We need on the suns for FIOCLEX!!! We did not close our file descriptors before... 13. A/UX fixes. 12. History events that start with a number are not necessarily numeric: > !3d 3d: Event not fount 11. History loop detection added. > alias a \!# > b; a 10. Alias loop detection code was ineffective on eager optimizers. 9. All errors should now go through our table. Next step we should add nls error messages. 8. Unsetenv now globs its arguments! Before it did not... 7. Added tilde cache and -l flag. 6. Added autocorrect 5. Fixed for so that background jobs in scripts get process groups 4. Fixed amazing memory leak in setenv()... 3. Added short2qstr() so that we can form quoted strings to be used with glob() 2. str2short and short2str allocate space dynamically. 1. Fixed bug related to the is*() routines called with shorts. [only if NLS and SHORT_STRINGS are defined]. (The _ctype_ was getting indexed with shorts...) 0. Complete overhaul. Brought in the 4.4 csh stuff. Separated most tcsh and csh code except where I would have to add more global variables. Compiled correctly with both lint and gcc -Wall on a sparc running 4.1 V5.20.03, 03/20/91. - Never released 25. Kanji, SXA additions. 24. (exec foo) should not fail if they are suspended jobs. 23. Support kernel paging stuff on aix 370. 22. Now we handle correctly the environment variables LINES, COLUMNS, TERMCAP for window size changes... 21. Tcsh 5.18c+ had broken NULL chars on scripts. > cat > foo #!/usr/local/bin/tcsh -f echo "foo" echo "^V^@" echo "bar" ^D > chmod +x foo; foo foo 20. Posix has EAGAIN and not EWOULDBLOCK 19. Don't set ECHOK; makes kill ^U ugly. 18. $shell is SHELLPATH and not $SHELL any more. 17. Added -n flag to cd, pushd, popd and dirs. Documented -l and -v flags. 16. Documented and fixed chase_symlinks and ignore_symlinks. 15. Call endpwent() when you get interrupted... cd ~chri^C cd ~christos/ 14. Exec when you have suspended jobs asks for verification. 13. Variable length fixes: >set abcdefghijklmnopqrstuvwxyz=1 >echo $abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrs: Undefined variable Now we have better messages too... 12. Icon fixes... 11. Quote expanded glob and history chars too. 10. If someone sets SHIN to O_NDELAY we died... Now we set it back... 9. unset path; unsetenv PATH; ls-F; (poof) fixed... 8. Patches for masscomp, and ${var123} lexical analysis fix... 7. Patch for sunview bug: A partially covered suntool sends SIGWINCH every time the text is scrolled, causing annoying redraw effects. Now tcsh checks if the size really changed before doing anything. 6. Interrupt in the middle of cwdcmd, and periodic does not remove the aliases. 5. prompt2 and prompt3 fixes: Prompt2 now prints the status of the parser by default. Prompt3 can now have the standard prompt escape sequences. 4. eval file descriptor re-direction fix. >set p='w | tail +3' >eval $p (originally | tail +3 was ignored) 3. $edit != emacs anymore; it was misleading, 'set edit' enables editing 'unset edit' disables it. 2. PERROR define fix. 1. irix3.3.1 line discipline fix. V5.20.02, 12/15/90. 32. /etc/Logout added and merged with /etc/Login flag. 31. Fixed tty chars in ed.init.c. Some of them were not handled correctly. 30. Command execution does not leak memory any more, and doing ~ four times does not core-dump. 29. Fixed the notorious csh 'if(' bug (part of the convex fixes) 28. Intelligent getwd() on startup, and canonicalization. 27. Intelligent directory stack. Gets updated when $HOME changes. 26. Directory stack/save-restore additions 25. Convex Fixes. 24. Fixed onlret, and echonl getting stuck on svid. 23. Shouldn't leave tty in raw mode at auto-logout (e.g. when su'ing from a csh, this is annoying). 22. Some users had environment EMACS set to something, and with my bad fix at pl 1 found that they didn't have echo... (of course, even before my "fix", they didn't have editing...). Anyway, refined the check to be for EMACS=t, which is what emacs sets when running a subshell. 21. kill -CONT %job, would not update the status of the job, but it would just restart it. 20. Sequent fixes. 19. AIX370 signal and TCF fixes. 18. fixed ls-F -l, SIGINT problem. 17. aix on the ps2 does not have strcoll() either. 16. Bind [A - [D and OA to OD in vi mode to the arrow key functions so that they work from insert mode. 15. %~ was not working correctly for /home/news and /home/newsbin... 14. Removed Rcs Log 13. ISC unix fixes. 12. sunos3.x wants not 11. Remove precmd's, cwdcmd's and periodic cmds that had errors. 10. Compile sunos4.1 using termio. 9. Rs6000 line discipline fixes. 8. T_Tabs was wrong for termio machines. 7. Don't bind single keystroke arrow keys, when they are already bound! 6. Test for newline and tab before deciding not to send shell scripts to the bourne shell. 5. Added LITERAL prompt stuff. 4. Fixed gethostname() in sh.rest.c to return the nodename. 3. Do not quote spell checked stuff. This is not very intelligent but works better than before. 2. Fixes for relative path components. (paths that start with a .) 1. Fixed so that Rawmode() is not called when we are not editing (breaks running under emacs) V5.20.01, 11/15/90. 12. Recognize environment variables too. 11. Always start in Rawmode() 10. don't try to execute binary files using the bourne shell. 9. Vi change to end of line updates correctly now. 8. Prompt in continuation lines. 7. Prompt in if statements fix. 6. System V ^C works right now. 5. ^Z works correctly in bindings 4. Better error messages for variables. 3. dinit() now is more robust. 2. Added aux2.0 patches. 1. Fixed bug with arrow key bindings in ed.screen.c. All the keys were bound to up-history! V5.20.00, 11/10/90. 26. Fixed system V and POSIX time reporting. 25. Fixed ed.screen.c so that it does not use malloc(). 24. Fixed SIGWINCH on the iris 23. Fixed ed.screen.c, so that settc works correcly. It used to set the termcap with a string that was allocated from the stack! 22. Fixed listing of commands, where the last command was not checked. 21. Fixed which command. It did not work for \, if command was aliased. 20. Eliminated CSH4.3 define. You've had enough time to upgrade from 4.2 19. Fixed GotTermCaps to be called only once. 18. Added bindkey -r 17. Attributes were not getting reset correctly. 16. history -t does not print the time-stamp. 15. AddXkey, works now for single character xkeys. 14. filetype() knows better about symlinks. 13. ls-F works with filenames that have metachars 12. Completion/spelling works with quoted things. 11. Fixed refresh bug. Repeat by: On an intelligent terminal that has insert and delete chars (xterm) > orphan > vi orphan.c > ^P^P 10. Fixed so that if we don't have a tty on stdin editing is disabled. 9. Check for nested process forking, to avoid loops such as: > alias foo 'set bar=`foo`' > foo 8. Fix setting of AsciiOnly (Per) 7. tw.spell.c, defined F_OK for systems that don't have it. 6. ourwait.h had typo in ifdef. 5. BSD compilers need a cast to int for enums used in switches (Matthew Day) 4. Found the cause for the core-dump in long backquote expansions (Mark Davies) 3. Some externs in ed.h needed to be truly externs... reported by Mark Davies, bug appeared only on hp9000s800. 2. Changed $tcsh, and $version strings. 1. Added internal sprintf function, renamed putchar to CSHputchar, printf to CSHprintf, sprintf to CSHsprintf. V5.19.02, 10/23/90. 36. Added /etc/cshrc for the SGI irises. 35. Added expand-variables function. 34. Documented $time in tcsh.man 33. Shell variables are now 'recognized' when expanding/listing things. 32. ls-F does not eat the last slash on the / directory! 31. Strings bound to keys are printed inside double quotes. 30. History now remembers the exact line, not just an unparsed version of the tokens. 29. Renamed itoa to Itoa(), so things in libc that use itoa() don't break. 28. Ported to IBM aix/ps2. 27. Fixed eval so that it forks when the output is piped Repeat by: > who | grep $user > eval who | grep $user 26. Fixed so that 'nice ' does not nice or fork. Consider doing: nice cd /tmp && rm *.c (don't try it!!!) [what actually happens is that nice has to fork, then the child executes chdir, and the parent stays where it was] 25. Added Dan's patches (nls, builtin bindkey, fixes to the editor). 24. Added aix370, migrate, getspath, getspath, getxvers, setxvers 23. Added builtin echotc, removed sl and el. 22. Ported to 4.4 BSD. This involved changing the way lots of flags worked, cleanup of the SVID stuff, and addition of more compilation flags. Now POSIX can work whed BSD is defined... 21. Fixed so that el, sl work. Actually they are to be removed soon and be replaced with echotc. 20. Avoid the Quoted Space hack for alias when printing jobs! [aliases to the same name avoid further alias expansion, by inserting a quoted space in front of the command. In SHORT_STRINGS QUOTE is the 15th bit so print ignores it thinking it is the end of the string. So we just skip the Quoted Space....] Repeat by: > set notify > alias ls ls -F > (ls) & Prints Exit 0 ( Should print: Exit 0 ( ls -F ) 19. Fixed so that "", '', ``, all produce ': Command not found', and not the spurious messages. Repeat by: > set path = (/bin /usr/bin .... .) > "" /some/path/name/: Command not found 18. Enable the use of macros if they exist and NLS is defined. NLS code is not ready yet. 17. Fixed rmstar and continue_jobs code, so that they are not compile options, but shell variables. Now you need to 'set rmstar' to get enable rmstar. 16. Fixed SIGWINCH, SIGWINDOW, and setting of li, co, that broke suntools, and others. Repeat by: Start a shelltool of size other than 80x34 > telltc > stty -a do not report the same number of lines and columns. 15. More fixes to tw.parse.c, and tw.spell.c. 14. More fixes to sh.char.c. 13. Fixed coredump caused by ``. 12. Fixed spell-line code.. 11. Trapped SIGCHLD in sh.sem.c, while forking. Still there is a small race, but the probability of happening is smaller! 10. Fixed sh.char.c to be ISO compliant. 9. Added expand-glob 8. Fixed ourwait.h for little endians. 7. Fixed that foreach i (^D expands correctly. 6. Fixed so that listmax is ignored in ls-F. 5. Fixed spelling correction so that single letter words and words that contain globbing chars do not get spell checked. 4. Changed NeXT HOSTTYPE to next, since all HOSTTYPE's are lower case. 3. Fixed symmetry, and changed symmetry HOSTTYPE from sequent to symmetry. 2. Added boldfacing, underlining chars. 1. Added IRIX3.3.1 support. V5.19.01, 9/26/90. 7. Brought the README file up-to-date, and changed the bug report address to point to me. 6. sh.lex.c. In addla(), overflow computation was wrong. 5. Fixed SHELLPATH, to be set correctly when $SHELL is not set. 4. Fixed print statement in sh.proc.c that contained \215. 3. Fixed the Makefile and MAKEDIFFS so that a tahoe diff can be made. 2. RS6000: hacked around execv bug, and ed.init.c warning. 1. Editor should not be enabled when we don't have a tty. diff --git a/contrib/tcsh/Imakefile b/contrib/tcsh/Imakefile index be2bebe17ca9..bd1b43b1a24e 100644 --- a/contrib/tcsh/Imakefile +++ b/contrib/tcsh/Imakefile @@ -1,629 +1,631 @@ XCOMM XCOMM Imakefile for tcsh 6.12 XCOMM Marc Horowitz, MIT SIPB XCOMM #ifdef DestDir #undef DestDir #endif #ifdef ManSuffix #undef ManSuffix #endif /* All config options go in a separate file. */ #include "imake.config" #ifndef HasGcc # define HasGcc 0 #endif #ifndef HasGcc2 # define HasGcc2 0 #endif /* This is a giant conditional block. It should be set up right for platforms which are in here, but it may need to be changed for new ones. Please send in your fixes and additions! */ /**** tcsh configuration defines ****/ /* specific platforms */ #ifndef ConfigH # ifdef UltrixArchitecture # define ConfigH ultrix # endif # ifdef UxpArchitecture # define ConfigH sysv4 # endif # if defined(LinuxArchitecture) || defined(GNUArchitecture) # define ConfigH linux # endif # ifdef AlphaArchitecture # if !defined(LinuxArchitecture) && !defined(GNUArchitecture) # define ConfigH decosf1 # endif # if !HasGcc # define MyCflags -std1 -Olimit 2000 # else # define NoCombineRegs # endif # endif # if defined(VaxArchitecture) && !defined(UltrixArchitecture) # define ConfigH bsd # endif # ifdef NeXTArchitecture # define ConfigH mach # endif # if defined(SunArchitecture) # if (OSMajorVersion == 3) # define ConfigH sunos35 # else # if (OSMajorVersion == 4) # if (OSMinorVersion == 0) # define ConfigH sunos40 # else /* OSMinorVersion == 1 */ # if (OSTeenyVersion == 3) # define ConfigH sunos413 # else /* OsTeenyVersion in [0,1,2] */ # define ConfigH sunos41 # endif # endif # define NoCombineRegs # else /* OSMajorVersion == 5 */ # if (OSMinorVersion < 3) # if (OSMinorVersion < 2) # define ConfigH sol2 # else # define ConfigH sol22 # endif # else # if (OSMinorVersion < 4) # define ConfigH sol23 # else # if (OSMinorVersion < 6) # define ConfigH sol24 # else # if (OSMinorVersion < 9) # define ConfigH sol26 # else # define ConfigH sol29 # endif # endif # endif # endif # define NoCombineRegs # endif # endif # endif # ifdef HPArchitecture /* For some stupid reason makedepend on HP requires this */ DEPENDFLAGS = -o.o # if (OSMajorVersion >= 8) # define ConfigH hpux8 # else # define ConfigH hpux7 # endif # endif # ifdef CrayArchitecture # define ConfigH cray # endif # ifdef SGIArchitecture # define ConfigH irix # define UseLibBSD # if (OSMajorVersion < 5) # ifdef you_are_using_yp # define UseSunLib # endif # if !HasGCC # define MyStdc -D__STDC__ # if SGICompilerMajorVersion < 4 CCOPTIONS=-float # We don't want -cckr and -prototypes # endif # endif # endif # if (OSMajorVersion == 6) # if (OSMinorVersion >= 2) # undef UseLibBSD # define ConfigH irix62 # endif # endif # endif # ifdef IBMArchitecture # undef UseLibBSD # if (SystemV == YES) # define ConfigH aix # if OSMajorVersion < 3 # if OSMinorVersion < 2 # define UseLibBSD # endif # endif # else # define ConfigH bsd # define AOSArchitecture # endif # endif #ifdef AOSArchitecture #define MyStdc -U__STDC__ #endif # if defined(MipsBsdArchitecture) || defined(MipsSysvArchitecture) # define ConfigH mips # endif # ifdef DguxArchitecture # define ConfigH dgux # endif # ifdef ConvexArchitecture # define ConfigH convex # endif # if defined(SQNTArchitecture) || defined(SequentArchitecture) # define ConfigH sequent # endif # ifdef MacIIArchitecture # define ConfigH mac2 # endif # ifdef MinixArchitecture /* Maybe conditional on MACH? */ SYSSRCS=mi.termios.c mi.wait.h mi.varargs.h SYSOBJS=mi.termios.${SUF} EXTF=ma.setp.c vms.termcap.c # else /* Maybe conditional on MACH? */ SYSSRCS=ma.setp.c SYSOBJS=ma.setp.${SUF} EXTF=mi.termios.c mi.wait.h mi.varargs.h vms.termcap.c # endif # ifdef i386Isc # if IscVersion != 202 # define ConfigH isc # define UseLibCposix # else # define ConfigH isc202 # endif # endif /* i386Isc */ # ifdef OpenBSDArchitecture # define ConfigH bsd4.4 # endif /* OpenBsdArchitecture */ # ifdef NetBSDArchitecture # define ConfigH bsd4.4 # endif /* NetBsdArchitecture */ # ifdef FreeBSDArchitecture # define ConfigH bsd4.4 # endif /* FreeBsdArchitecture */ # ifdef MidnightBSDArchitecture # define ConfigH bsd4.4 # endif /* MidnightBsdArchitecture */ # ifdef i386SVR4Architecture # define ConfigH sysv4 # ifdef DELL # define NoCombineRegs # endif # endif #endif /* !ConfigH */ /* generic os's */ #ifndef ConfigH #if (SystemV == YES) #define ConfigH sysv3 #else /* why this as a default? Why not? */ #define ConfigH bsd #endif #endif /* !ConfigH */ /**** libraries ****/ #if (SystemV == NO) || defined(HPArchitecture) || \ defined(SQNTArchitecture) || defined(SequentArchitecture) || \ defined(MacIIArchitecture) || defined(UseLibTermcap) LIBTERMCAP = -ltermcap #else LIBTERMCAP = #endif #if defined(SQNTArchitecture) || defined(SequentArchitecture) LIBSQNT=-lsocket -linet -lnsl -lseq #endif /* This may not be good enough - I don't have access to enough systems to really test it. */ #if (SystemV == YES) || defined(UseLibCurses) && !defined(HPArchitecture) LIBCURSES = -lcurses #else LIBCURSES = #endif #if defined(UseLibNet) LIBNET = -lnet #else LIBNET = #endif #if defined(UseLibSocket) LIBSOCKET = -lsocket #else LIBSOCKET = #endif #if defined(UseLibBSD) LIBBSD = -lbsd #else LIBBSD = #endif #if (defined(SGIArchitecture) && \ (OSMajorVersion == 3) && (OSMinorVersion == 3)) || \ defined(UseLibC_S) LIBC_S = -lc_s #else LIBC_S = #endif #if defined(UseLibSun) LIBSUN = -lsun #else LIBSUN = #endif #if defined(UseLibCposix) LIBCPOSIX = -lcposix #else LIBCPOSIX = #endif #if defined(UseLibInet) LIBINET = -linet #else LIBINET = #endif #if defined(UseLibDir) LIBDIRECT = -ldir #else LIBDIRECT = #endif #if defined(UseLibX) LIBX = -lx #else LIBX = #endif #if defined(UseLibIntl) LIBINTL = -lintl #else LIBINTL = #endif #if (HasLibCrypt == YES) LIBCRYPT = -lcrypt #else LIBCRYPT = #endif #if defined(MacIIArchitecture) || defined(UseLibPosix) LIBPOSIX = -lposix #else LIBPOSIX = #endif #if defined(ATTArchitecture) || defined(UseLibDirent) LIBDIRECTENT = -ldirent #else LIBDIRECTENT = #endif /* The order here is significant. Although nothing uses all of these, some platforms which use more than one do care about the order. */ SYSLIBS = $(LIBPOSIX) $(LIBDIRECTENT) $(LIBTERMCAP) $(LIBCURSES) \ $(LIBNET) $(LIBINTL) $(LIBSOCKET) $(LIBSUN) $(LIBBSD) $(LIBCPOSIX) \ $(LIBINET) $(LIBDIRECT) $(LIBX) $(LIBC_S) $(LIBSQNT) $(LIBCRYPT) /* Past here, nothing should need to be changed to compile on a different platform, unless you have a really weird architecture. */ #ifdef MyCC CC = MyCC #else # if HasGcc # if HasGcc2 CC = gcc # else # ifdef NoCombineRegs CC = gcc -finline-functions -fstrength-reduce # else CC = gcc -fcombine-regs -finline-functions -fstrength-reduce # endif # endif # else CC = cc # endif #endif #ifdef HESIOD HESLIB = -L/usr/athena/lib -lhesiod /* it seems to me that the -I shouldn't be necessary, but there seems to be a bug in the Imake stuff, so here it is. */ HESDEF = -DHESIOD -I/usr/athena/include #else HESLIB = HESDEF = #endif #ifdef AFS #ifndef AFSDIR AFSDIR = /usr/afsws #endif #ifdef AFS33 #define AFS33LIB -laudit #else #define AFS33LIB #endif /* Auxilliary libs needed for AFS */ /* Both HPUX and Solaris need the BSD libraries. We need -lc before * the bsd library to avoid using any more of it than is necessary. */ #if defined(HPArchitecture) #define AFSAUXLIB -lc -lBSD /* This is probably a kludge, but so is imake. */ #else #if defined(SunArchitecture) && (OSMajorVersion == 5) #define AFSAUXLIB -lsocket -lnsl -lc -lucb #else #define AFSAUXLIB #endif #endif /* AFSAUXLIB */ AFSLIB = -L$(AFSDIR)/lib -L$(AFSDIR)/lib/afs -lkauth -lprot -lubik\ -lauth -lrxkad -lsys -ldes -lrx -llwp -lcom_err\ $(AFSDIR)/lib/afs/util.a AFS33LIB AFSAUXLIB AFSDEF = -DAFS -I$(AFSDIR)/include #else AFSLIB = AFSDEF = #endif /* This is encore specific, but I don't know what encore's #define is, and it shouldn't hurt to have it here, so here it is */ PARALLEL=12 # Make the multi-max run fast. #ifndef TcshTop #define TcshTop /usr/local #endif TCSHTOP = TcshTop #ifndef ManSuffix #define ManSuffix 1 #endif MANSUFFIX = ManSuffix #ifdef TcshPath PATH_TCSHELL = TcshPath TCSHPATH = -D_PATH_TCSHELL='"$(PATH_TCSHELL)"' #else TCSHPATH = #endif #ifdef DestBin TCSH_BINDIR = DestBin #else TCSH_BINDIR = $(TCSHTOP)/bin #endif #ifdef DestMan TCSH_MANDIR = DestMan #else TCSH_MANDIR = $(TCSHTOP)/man/man$(MANSUFFIX) #endif LOCALLIBS = #ifndef MyCflags #define MyCflags #endif #ifndef MyDefines #define MyDefines #endif #ifndef MyIncludes #define MyIncludes #endif #ifndef MyStdc #define MyStdc #endif #ifdef CDebugFlags CDEBUGFLAGS = CDebugFlags #else # if HasGcc2 CDEBUGFLAGS = -O2 # else CDEBUGFLAGS = -O # endif #endif #ifdef HostType HOSTTYPE=HostType HTDEF = -DHOSTTYPE='"$(HOSTTYPE)"' #else HTDEF = #endif DEFINES = $(TCSHPATH) $(HESDEF) $(AFSDEF) $(HTDEF) MyDefines MyCflags MyStdc INCLUDES = -I. MyIncludes #ifdef MyLibs LDLIBS = MyLibs #endif SUF = o VERSION = 6.12 SHSRCS= sh.c sh.dir.c sh.dol.c sh.err.c sh.exec.c \ sh.char.c sh.exp.c sh.file.c sh.func.c \ sh.glob.c sh.hist.c sh.init.c sh.lex.c \ sh.misc.c sh.parse.c sh.print.c sh.proc.c \ - sh.sem.c sh.set.c sh.time.c glob.c \ + sh.sem.c sh.set.c sh.time.c dotlock.c dotlock.h glob.c \ sh.char.h sh.dir.h sh.proc.h sh.h \ sh.decls.h glob.h ${SYSSRCS} SHOBJS= sh.${SUF} sh.dir.${SUF} sh.dol.${SUF} sh.err.${SUF} sh.exec.${SUF} \ sh.char.${SUF} sh.exp.${SUF} sh.file.${SUF} sh.func.${SUF} \ sh.glob.${SUF} sh.hist.${SUF} sh.init.${SUF} sh.lex.${SUF} \ sh.misc.${SUF} sh.parse.${SUF} sh.print.${SUF} sh.proc.${SUF} \ - sh.sem.${SUF} sh.set.${SUF} sh.time.${SUF} glob.${SUF} ${SYSOBJS} + sh.sem.${SUF} sh.set.${SUF} sh.time.${SUF} dotlock.${SUF} glob.${SUF} \ + ${SYSOBJS} TWSRCS= tw.decls.h tw.h tw.help.c tw.init.c tw.parse.c tw.spell.c \ tw.comp.c tw.color.c TWOBJS= tw.help.${SUF} tw.init.${SUF} tw.parse.${SUF} tw.spell.${SUF} \ tw.comp.${SUF} tw.color.${SUF} EDSRCS= ed.chared.c ed.decls.h ed.defns.c ed.h ed.init.c ed.inputl.c \ ed.refresh.c ed.screen.c ed.xmap.c ed.term.c ed.term.h EDOBJS= ed.chared.${SUF} ed.refresh.${SUF} ed.screen.${SUF} ed.init.${SUF} \ ed.inputl.${SUF} ed.defns.${SUF} ed.xmap.${SUF} ed.term.${SUF} TCSRCS= tc.alloc.c tc.bind.c tc.const.c tc.decls.h tc.disc.c \ - tc.func.c tc.os.c tc.os.h tc.printf.c tc.prompt.c \ - tc.sched.c tc.sig.c tc.sig.h tc.str.c sh.types.h tc.vers.c tc.wait.h \ - tc.who.c tc.h + tc.func.c tc.nls.c tc.nls.h tc.os.c tc.os.h tc.printf.c tc.prompt.c \ + tc.disc.${SUF} tc.func.${SUF} tc.nls.${SUF} tc.os.${SUF} \ + tc.printf.${SUF} tc.sched.c tc.sig.c tc.sig.h tc.str.c sh.types.h \ + tc.vers.c tc.wait.h tc.who.c tc.h TCOBJS= tc.alloc.${SUF} tc.bind.${SUF} tc.const.${SUF} tc.defs.${SUF} \ tc.disc.${SUF} tc.func.${SUF} tc.os.${SUF} tc.printf.${SUF} \ tc.prompt.${SUF} tc.sched.${SUF} tc.sig.${SUF} tc.str.${SUF} \ tc.vers.${SUF} tc.who.${SUF} MISCF = Makefile.std BUILDING Fixes MAKEDIFFS MAKESHAR NewThings README.md \ FAQ WishList config_f.h eight-bit.me glob.3 patchlevel.h pathnames.h \ tcsh.man Ported src.desc Imakefile imake.config complete.tcsh \ Makefile.vms termcap.vms snames.h host.defs gethost.c tcsh.man2html \ - Makefile.in configure.ac Makefile.win32 aclocal.m4 + Makefile.in configure.ac Makefile.win32 aclocal.m4 dot.login dot.tcshrc CONFSRCS=config/[a-z]* SRCS = $(SHSRCS) $(TWSRCS) $(EDSRCS) $(TCSRCS) OBJS = $(SHOBJS) $(TWOBJS) $(EDOBJS) $(TCOBJS) ALLSRCS= $(MISCF) $(SRCS) $(EXTF) AllTarget(tcsh) ed.defns.h: config.h ed.defns.c @rm -f $@ @echo '/* Do not edit this file, make creates it. */' > $@ @echo '#ifndef _h_ed_defns' >> $@ @echo '#define _h_ed_defns' >> $@ egrep '[FV]_' ed.defns.c | egrep '^#define' >> $@ @echo '#endif /* _h_ed_defns */' >> $@ sh.err.h: config.h sh.err.c @rm -f $@ @echo '/* Do not edit this file, make creates it. */' > $@ @echo '#ifndef _h_sh_err' >> $@ @echo '#define _h_sh_err' >> $@ egrep 'ERR_' sh.err.c | egrep '^#define' >> $@ @echo '#endif /* _h_sh_err */' >> $@ tc.const.h: config.h tc.const.c @rm -f $@ @echo '/* Do not edit this file, make creates it. */' > $@ @echo '#ifndef _h_tc_const' >> $@ @echo '#define _h_tc_const' >> $@ ${CC} -E $(INCLUDES) ${DEFINES} -D_h_tc_const tc.const.c | \ grep 'Char STR' | \ sed -e 's/Char \([a-zA-Z0-9_]*\)\[\].*/extern Char \1[];/' | \ sort >> $@ @echo '#endif /* _h_tc_const */' >> $@ config.h: config_f.h cp config/ConfigH config.h $(OBJS): sh.err.h tc.const.h ed.defns.h tar.Z: rm -f tcsh-${VERSION}.tar.Z rm -rf tcsh-${VERSION} mkdir tcsh-${VERSION} tcsh-${VERSION}/config cp ${ALLSRCS} tcsh-${VERSION} cp ${CONFSRCS} tcsh-${VERSION}/config tar cf - nls/Makefile nls/?*/set?* | (cd tcsh-${VERSION}; tar xpf -) tar cvf - tcsh-${VERSION} | compress > tcsh-${VERSION}.tar.Z rm -rf tcsh-${VERSION} tar.gz: rm -f tcsh-${VERSION}.tar.gz rm -rf tcsh-${VERSION} mkdir tcsh-${VERSION} tcsh-${VERSION}/config cp ${ALLSRCS} tcsh-${VERSION} cp ${CONFSRCS} tcsh-${VERSION}/config tar cf - nls/Makefile nls/?*/set?* | (cd tcsh-${VERSION}; tar xpf -) tar cvf - tcsh-${VERSION} | gzip > tcsh-${VERSION}.tar.gz rm -rf tcsh-${VERSION} shar: rm -f tcsh-*.shar rm -rf tcsh-${VERSION} mkdir tcsh-${VERSION} tcsh-${VERSION}/config cp ${ALLSRCS} tcsh-${VERSION} cp ${CONFSRCS} tcsh-${VERSION}/config tar cf - nls/Makefile nls/?*/set?* | (cd tcsh-${VERSION}; tar xpf -) MAKESHAR -v -n tcsh-${VERSION} tcsh-${VERSION} \ tcsh-${VERSION}/?* tcsh-${VERSION}/config/?* \ tcsh-${VERSION}/?*/set?* rm -rf tcsh-${VERSION} catalogs: @(cd nls; make catalogs) world: $(MAKE) clean ; $(MAKE) depend ; $(MAKE) tcsh ; $(MAKE) install clean:: rm -f ed.defns.h sh.err.h tc.const.h config.h tc.defs.* rm -f tcsh.*.m tcsh.*.cat depend:: config.h ed.defns.h sh.err.h tc.const.h $(SRCS) tc.defs.c tc.defs.${SUF}: tc.defs.c sh.h tc.defs.c: gethost host.defs @rm -f $@ @echo "/* Do not edit this file, make creates it */" > $@ ./gethost host.defs >> $@ ALIB=$(HESLIB) $(AFSLIB) $(SYSLIBS) AINC=ed.defns.h sh.err.h tc.const.h sh.h NormalProgramTarget(tcsh, $(OBJS), $(AINC), $(LOCALLIBS), $(ALIB)) NormalProgramTarget(gethost, gethost.${SUF}, $(AINC), $(LOCALLIBS), $(ALIB)) InstallProgram(tcsh,$(TCSH_BINDIR)) InstallManPage(tcsh,$(TCSH_MANDIR)) DependTarget() diff --git a/contrib/tcsh/Makefile.ADMIN b/contrib/tcsh/Makefile.ADMIN new file mode 100644 index 000000000000..5ad3bb8fb3c5 --- /dev/null +++ b/contrib/tcsh/Makefile.ADMIN @@ -0,0 +1,24 @@ +# +# Makefile.ADMIN +# +# Maintenance tasks +# +# You can refetch files from the website, then run "git diff" to +# sanity check any changes before committing. +# + +LYNX= lynx -dump -nolist +TRIM= expand | sed -e 's/^ *$$//' | cat -s +WEB= https://www.tcsh.org + +PAGES= FAQ + +all: ${PAGES} + +.for i in ${PAGES} +$i: force + ${LYNX} ${WEB}/${i:tl}/ | ${TRIM} > ${.TARGET} +.endfor + +.DUMMY: force +force: diff --git a/contrib/tcsh/Makefile.in b/contrib/tcsh/Makefile.in index 210b7de72dfe..c6b5f2554cc0 100644 --- a/contrib/tcsh/Makefile.in +++ b/contrib/tcsh/Makefile.in @@ -1,777 +1,782 @@ # # C Shell with process control; VM/UNIX VAX Makefile # Bill Joy UC Berkeley; Jim Kulp IIASA, Austria # # With an input editor, command completion, etc. and ported to all sorts of # things; Paul Placeway, CIS Dept., Ohio State University # SHELL=/bin/sh +ENVCMD=/usr/bin/env VERSION=@PACKAGE_VERSION@ BUILD=tcsh$(EXEEXT) VPATH=@srcdir@ srcdir=@srcdir@ ################################################################ ## CFLAGS. For various -D things, see config.h ################################################################ # # These are the default suffixes from .c to .o and -c to get there # but to use the global optimizer on the mips boxes, see below # SUF=o CF=-c CPPFLAGS=-I. -I$(srcdir) LFLAGS= # hpux lint #LFLAGS= -Zn10000 # This is set by autoconf: CFLAGS = @CFLAGS@ # debug: #CFLAGS= -g # production: #CFLAGS= -O # Broken optimizers.... #CFLAGS= #CFLAGS= -g -pg -DPROF #CFLAGS= -O -pg -DPROF # gcc 1.00-1.37 #CFLAGS= -O -finline-functions -fstrength-reduce # gcc 1.37-1.40 #CFLAGS= -O -fcombine-regs -finline-functions -fstrength-reduce # add -msoft-float for 68881 machines. # gcc 2.0 # On the sparc, don't use -O2; it breaks setjmp() and vfork() #CFLAGS= -O # gcc-2.1+ #CFLAGS= -O2 # lucid c on suns #CFLAGS= -O5 # gcc 2.1 on linux #CFLAGS= -O6 -fomit-frame-pointer # HP/UX 8.0, 9.0 #CFLAGS= +O3 -Aa # Ultrix 4.2a #CFLAGS= -O -Olimit 2000 # Intel Paragon OSF/1 with PGI compilers #CFLAGS= -O -Mnodebug -Mnoperfmon # DEC Alpha OSF/1 ## Normal Optimization #CFLAGS= -O2 -Olimit 2000 ## Full Optimization - may not work #CFLAGS= -O3 -Olimit 2000 #CF=-j #SUF=u #.SUFFIXES: .u # for silicon graphics (and other mips compilers) -- use the # global optimizer! (-O3). # On SGI 4.0+ you need to add -D__STDC__ too. #CFLAGS= -O3 ## Ultrix 4.2a #CFLAGS= -O3 -Olimit 2000 #CF=-j #SUF=u #.SUFFIXES: .u ## Ultrix and gnu-make need that # mips systems # CFLAGS= -O -systype bsd43 -Wf,-XNd5000 -Wf,-XNp6000 -Olimit 2000 # for at&t machines #CFLAGS= -O -Ksd # Stardent Titan #CFLAGS = -O -43 # Stardent Stellar or sunos4 /bin/cc or Solaris2.1 /opt/SUNWspro/bin/cc #CFLAGS = -O4 # Intergraph clipper CLIX 3.1 #CFLAGS= -w -O2 # Dnix 5.3 #CFLAGS = -O -X7 # Pyramid OS/x #CFLAGS = -OG # Multiflow (5M binary... if you choose -O5!) #CFLAGS = -O5 -sb_trace 0 # DDE Supermax Unix SYSV Rel III. # CFLAGS= -O3 # SINIX RMx00 #CFLAGS= -O# -D_POSIX_SOURCE# -kansi # Apollo's with cc [apollo builtins don't work with gcc] # and apollo should not define __STDC__ if it does not have # the standard header files. RT's (aos4.3) need that too; # you might want to skip the -O on the rt's... Not very wise. # AIX/ESA needs -D_IBMESA on command line (this may disappear by GA) #DFLAGS=-U__STDC__ #DFLAGS=-D_IBMESA # On aix2.2.1 we need more compiler space. #DFLAGS=-Nd4000 -Nn3000 # AU/X 2.0 needs a flag for POSIX (read the config file) #DFLAGS=-Zp # Tektronix 4300 running UTek 4.0 (BSD 4.2) needs: #DFLAGS = -DUTek -DBSD # VMS_POSIX needs: #DFLAGS=-D_VMS_POSIX # Multiflow and PCC compilers don't like void typedefs. # You may also need -U__STDC__ if you use pcc (i.e. ibmrt aos4.3). #DFLAGS=-DMULTIFLOW #DFLAGS=-DPCC # DELL SVR4 #DFLAGS=-DDELL #DFLAGS= #DFLAGS=-D_PATH_TCSHELL='"${DESTBIN}/tcsh"' ## The following is set by autoconf. DFLAGS = -D_PATH_TCSHELL='"${bindir}/tcsh"' @DFLAGS@ @CPPFLAGS@ ################################################################ ## LDFLAGS. Define something here if you need to ################################################################ ## This is set by autoconf: LDFLAGS= @LDFLAGS@ ## The simplest, suitable for all. #LDFLAGS= ## Stripped. Takes less space on disk. #LDFLAGS= -s ## Pure executable. Spares paging over the network for machines with ## local swap but external /usr/local/bin . #LDFLAGS= -s -n ## Without dynamic linking. (SunOS/cc) #LDFLAGS= -s -n -Bstatic ## Without dynamic linking. (SunOS/gcc) #LDFLAGS= -s -n -static ## Stripped, shared text (Unicos) #LDFLAGS= -Wl,-s,-n ## Link statically. (linux) #LDFLAGS= -s -static ## Impure executable (linux) #LDFLAGS= -s -N ################################################################ ## SBINLDFLAGS. Flags to build a tcsh suitable for installation in ## in /sbin under Solaris with gcc. See the "tcsh.sbin" ## target. ################################################################ SBINLDFLAGS=-Wl,-R/etc/lib,-I/etc/lib/ld.so.1,-ldl,-Bstatic ################################################################ ## LIBES. Pick one, or roll your own. ################################################################ ## This is set by autoconf. LIBES= @LIBS@ ## BSD style things #LIBES= -ltermcap ## SunOS, HP-UX, pyramid #LIBES= -ltermcap ## Linux #LIBES= -ltermcap ## Linux with PW_SHADOW #LIBES= -ltermcap -lshadow ## Tek XD88/10 (UTekV) with PW_SHADOW #LIBES= -ltermcap -lsec ## Motorola MPC (sysV88) with PW_SHADOW #LIBES= -ltermcap -lsec ## Mach #LIBES= -ltermcap -lcs ## DEC osf1 on the alpha #LIBES= -ltermcap -lbsd ## Intel paragon #LIBES= -ltermcap -lbsd ## Clipper intergraph #LIBES= -ltermcap -lbsd ## Sequent's Dynix #LIBES= -ltermcap -lseq ## Ultrix with Enhanced Security #LIBES= -ltermcap -lauth ## Xenix 386 style things #LIBES= -ltermcap -ldir -lx ## masscomp RTU6.0 #LIBES= -ltermcap -lndir -lsocket -ljobs ## AIX on the rt #LIBES= -lcurses ## TitanOS on the stellar #LIBES= -lcurses ## SysV4 w/o BSDTIMES or Solaris 2 #LIBES= -ltermlib -lsocket -lnsl ## SysV3 w/o networking #LIBES= -lcurses ## SysV3 with networking #LIBES= -lcurses -lnet ## SysV2 w/o networking & dirlib #LIBES= -lcurses -ldir ## SysV2 with networking & dirlib #LIBES= -lcurses -ldir -lnet ## AIX on the IBM 370 or rs6000 or ps2 #LIBES= -lcurses -lbsd ## ETA10 #LIBES= -lcurses -lbsd ## Irix3.1 on the SGI-IRIS4D #LIBES= -lcurses -lbsd ## Irix3.3 on the SGI-IRIS4D w/o yp #LIBES= -lcurses -lbsd -lc_s ## Irix3.3 on the SGI-IRIS4D with yp #LIBES= -lcurses -lsun -lbsd -lc_s ## Amdahl UTS 2.1 #LIBES= -lcurses -lsocket -lbsd ## Intel's hypercube. #LIBES= -lcurses -lsocket ## ns32000 based Opus. #LIBES= -lcurses -lsocket ## ISC 2.2 without networking #LIBES= -lcurses -lcposix ## ISC 2.2 with networking #LIBES= -lcposix -lc_s -lcurses -linet ## ISC 2.0.2 without networking #LIBES= -lcurses -lsec -lc_s ## ISC 2.0.2 with networking #LIBES= -lcurses -linet -lsec -lc_s ## SCO SysVR3.2v2.0 #LIBES= -lcurses -lintl -lcrypt ## SCO+ODT1.1 #LIBES= -lcurses -lintl -lsocket -lcrypt ## A/UX 2.0 #LIBES= -lposix -ltermcap ## A/UX 3.0 #LIBES= -lposix -ltermcap -lc_s ## att3b1 cc w/o shared lib & dirlib #LIBES= -ldirent -lcurses ## att3b1 gcc with shared lib & dirlib #LIBES= -shlib -ldirent -lcurses ## SysV4 with BSDTIMES #LIBES= -ltermlib -lsocket -lnsl -lc /usr/ucblib/libucb.a ## Stardent Vistra #LIBES= -lcurses -lnsl -lsocket -lc /usr/ucblib/libucb.a ## emx under OS/2 #LIBES= -ltermc ## Minix, VMS_POSIX #LIBES= ## Multiflow #LIBES= -ltermcap -lcrypt ## NetBSD #LIBES= -ltermcap -lcrypt ## DDE Supermax #LIBES= -lcurses ################################################################ ## EXTRAFLAGS and EXTRALIBS ################################################################ # Compiling for AFS with kerberos authentication #AFSLIBDIR = /usr/afsws/lib #AFSDEF = -DAFS -I/usr/afsws/include #AFS33LIB = -laudit # #Solaris and HPUX require the BSD libraries with AFS. #We use -lc to use only what we require. # Solaris #AFSAUXLIB = -lsocket -lnsl -lc -lucb # HPUX #AFSAUXLIB = -lc -lBSD # #AFSLIB = -L$(AFSLIBDIR) -L$(AFSLIBDIR)/afs -lkauth -lprot -lubik\ # -lauth -lrxkad -lsys -ldes -lrx -llwp -lcom_err\ # $(AFSLIBDIR)/afs/util.a $(AFS33LIB) $(AFSAUXLIB) # EXTRAFLAGS = @HESDEF@ $(AFSDEF) EXTRALIBS = @HESLIB@ $(AFSLIB) @LIBICONV@ # The difficult choice of a c-compiler... # First, you should try your own c-compiler. # Gcc -traditional is also a safe choice. # If you think that you have good include files try gcc -Wall... # If you want to take out -traditional, make sure that your sys/ioctl.h # is fixed correctly, otherwise you'll be stopped for tty input, or you # will lose the editor and job control. # This is for setting your C preprocessor value. # This is set by autoconf. CPP = @CPP@ # The -B tells gcc to use /bin/ld. This is to avoid using the gnu ld, which # on the suns does not know how to make dynamically linked binaries. # This is set by autoconf. CC = @CC@ #CC= gcc -Wall -Wmissing-prototypes -Wstrict-prototypes -Wpointer-arith -Werror -Wmissing-declarations -Wredundant-decls -Wnested-externs -Wsign-compare -Wcast-qual -Wreturn-type -Wswitch -Wshadow -Wwrite-strings -Wextra -Wcast-qual -Wwrite-strings -Wold-style-definition -Wuninitialized -Wpointer-sign # -Wconversion -Wformat=2 -ansi -pedantic #CC= gcc -Wall -pipe -B/bin/ # Generate code for Intel 486 (linux) #CC= gcc -m486 -pipe -Wall # BSDI2.1 w/ shared libraries #CC= shlicc #CC= cc #CC= occ #CC= acc #CC= pcc #CC= hc -w # For VMS/POSIX #CC= c89 # For suns, w/o gcc and SVR4 #CC= /bin/cc # FPS 500 (+FPX) with Sun C compiler #CC= /usr/lib/sun.compile/cc # Solaris 2.1 #CC= /opt/SUNWspro/bin/cc # Alliant fx2800 #CC= scc # for NEC SX-4 #CC= cc -h0,ansi,novector,float0 #CC= lcc -wa CC_FOR_GETHOST = @CC_FOR_GETHOST@ ED= ed AS= as RM= rm CXREF= /usr/ucb/cxref VGRIND= csh /usr/ucb/vgrind CTAGS= /usr/ucb/ctags #XSTR= /usr/ucb/xstr SCCS= /usr/local/sccs # Make the multi-max run fast. PARALLEL=12 # Use Sequent's parallel make #P=& P= prefix=@prefix@ exec_prefix=@exec_prefix@ bindir=@bindir@ mandir=@datarootdir@/man MANSECT=1 DESTBIN=${DESTDIR}${bindir} DESTMAN=${DESTDIR}${mandir}/man${MANSECT} # A/UX # DESTMAN=${DESTDIR}/catman/man${MANSECT} # Stardent Vistra (SysVR4) # DESTMAN=${DESTDIR}/usr/share/man/man${MANSECT} # Amiga unix (SysVR4) # DESTMAN=/usr/catman/1l EXEEXT=@EXEEXT@ FTPAREA=/usr/spool/ftp BUILD_CATALOGS = @BUILD_CATALOGS@ ASSRCS= sh.c sh.dir.c sh.dol.c sh.err.c sh.exec.c sh.char.c \ sh.exp.c sh.file.c sh.func.c sh.glob.c sh.hist.c sh.init.c \ sh.lex.c sh.misc.c sh.parse.c sh.print.c sh.proc.c sh.sem.c \ sh.set.c sh.time.c sh.char.h sh.dir.h sh.proc.h sh.h \ tw.color.c PSSRCS= sh.decls.h glob.c glob.h dotlock.c dotlock.h mi.termios.c mi.wait.h mi.varargs.h ma.setp.c \ vms.termcap.c SHSRCS= ${ASSRCS} ${PSSRCS} SHOBJS= sh.${SUF} sh.dir.${SUF} sh.dol.${SUF} sh.err.${SUF} sh.exec.${SUF} \ sh.char.${SUF} sh.exp.${SUF} sh.file.${SUF} sh.func.${SUF} \ sh.glob.${SUF} sh.hist.${SUF} sh.init.${SUF} sh.lex.${SUF} \ sh.misc.${SUF} sh.parse.${SUF} sh.print.${SUF} sh.proc.${SUF} \ sh.sem.${SUF} sh.set.${SUF} sh.time.${SUF} glob.${SUF} dotlock.${SUF} \ mi.termios.${SUF} ma.setp.${SUF} vms.termcap.${SUF} TWSRCS= tw.decls.h tw.h tw.help.c tw.init.c tw.parse.c tw.spell.c \ tw.comp.c tw.color.c TWOBJS= tw.help.${SUF} tw.init.${SUF} tw.parse.${SUF} tw.spell.${SUF} \ tw.comp.${SUF} tw.color.${SUF} EDSRCS= ed.chared.c ed.decls.h ed.defns.c ed.h ed.init.c ed.inputl.c \ ed.refresh.c ed.screen.c ed.xmap.c ed.term.c ed.term.h EDOBJS= ed.chared.${SUF} ed.refresh.${SUF} ed.screen.${SUF} ed.init.${SUF} \ ed.inputl.${SUF} ed.defns.${SUF} ed.xmap.${SUF} ed.term.${SUF} TCSRCS= tc.alloc.c tc.bind.c tc.const.c tc.decls.h tc.disc.c \ tc.func.c tc.nls.c tc.os.c tc.os.h tc.printf.c tc.prompt.c \ tc.sched.c tc.sig.c tc.sig.h tc.str.c sh.types.h tc.vers.c tc.wait.h \ tc.who.c tc.h TCOBJS= tc.alloc.${SUF} tc.bind.${SUF} tc.const.${SUF} tc.defs.${SUF} \ tc.disc.${SUF} tc.func.${SUF} tc.nls.${SUF} tc.os.${SUF} tc.printf.${SUF} \ tc.prompt.${SUF} tc.sched.${SUF} tc.sig.${SUF} tc.str.${SUF} \ tc.vers.${SUF} tc.who.${SUF} PVSRCS= Makefile.std Makefile.vms Makefile.in Makefile.win32 AVSRCS= BUILDING Fixes MAKEDIFFS MAKESHAR NewThings README.md FAQ \ WishList config_f.h eight-bit.me glob.3 patchlevel.h \ pathnames.h tcsh.man Ported src.desc Imakefile imake.config \ complete.tcsh vmsreadme.txt termcap.vms snames.h host.defs \ gethost.c tcsh.man2html configure.ac configure config.h.in \ - tests/testsuite.at aclocal.m4 + tests/testsuite.at aclocal.m4 dot.login dot.tcshrc TESTFILES= tests/aliases.at tests/arguments.at tests/commands.at \ tests/expr.at tests/lexical.at tests/mb-eucjp.at \ tests/mb-utf8.at tests/noexec.at tests/parenthesis.at tests/syntax.at \ tests/subst.at tests/variables.at tests/sh.dol.at VHSRCS=${PVSRCS} ${AVSRCS} CONFSRCS=config/* ALLSRCS= ${SHSRCS} ${TWSRCS} ${EDSRCS} ${TCSRCS} ${VHSRCS} DISTSRCS= ${PSSRCS} ${TWSRCS} ${EDSRCS} ${TCSRCS} ${AVSRCS} $(TESTFILES) OBJS= ${SHOBJS} ${TWOBJS} ${EDOBJS} ${TCOBJS} all: ${BUILD} catalogs tcsh$(EXEEXT):$(P) ${OBJS} rm -f tcsh$(EXEEXT) core ${CC} -o tcsh$(EXEEXT) ${LDFLAGS} ${CFLAGS} ${CPPFLAGS} ${OBJS} ${LIBES} ${EXTRALIBS} tcsh.sbin:$(P) ${OBJS} rm -f tcsh.sbin core ${CC} -o tcsh.sbin ${SBINLDFLAGS} ${LDFLAGS} ${CFLAGS} ${CPPFLAGS} ${OBJS} ${LIBES} ${EXTRALIBS} # Purify pure:$(P) ${OBJS} rm -f tcsh$(EXEEXT) core purify `echo ${CC} | sed -e s,-B/bin/,,` -o tcsh$(EXEEXT) ${LDFLAGS} ${CFLAGS} ${CPPFLAGS} ${OBJS} ${LIBES} ${EXTRALIBS} # OS/2 #tcsh.exe: tcsh # emxbind tcsh gethost: gethost.c sh.err.h tc.const.h sh.h rm -f gethost ${CC_FOR_GETHOST} -o gethost ${CPPFLAGS} ${CFLAGS} ${LDFLAGS} $(srcdir)/gethost.c tc.defs.c: gethost host.defs @rm -f $@.tmp @echo "/* Do not edit this file, make creates it */" > $@.tmp ./gethost $(srcdir)/host.defs >> $@.tmp @if [ -f $@ ] && cmp -s $@.tmp $@; then echo $@ unchanged.; rm -f $@.tmp; else mv -f $@.tmp $@; echo $@ recreated.; fi tcsh.ps: tcsh.man rm -f tcsh.ps -ptroff -t -man $(srcdir)/tcsh.man > tcsh.ps .c.${SUF}: ${CC} ${CF} ${CFLAGS} ${CPPFLAGS} ${DFLAGS} ${EXTRAFLAGS} $< .SUFFIXES: .s .i .c.i: ${CC} -E ${CFLAGS} ${CPPFLAGS} ${DFLAGS} ${EXTRAFLAGS} $< | cat -s > $@ .c.s: ${CC} -S ${CFLAGS} ${CPPFLAGS} ${DFLAGS} ${EXTRAFLAGS} $< # _VMS_POSIX #module addition #.c.${SUF}: # @(echo '#module '`echo $< | sed -e 's/\./_/g'`; cat $<) > $*..c # @echo ${CC} ${CF} ${CFLAGS} ${CPPFLAGS} ${DFLAGS} ${EXTRAFLAGS} $*.c # @${CC} ${CF} ${CFLAGS} ${CPPFLAGS} ${DFLAGS} ${EXTRAFLAGS} $*..c # @mv $*..o $*.o # @rm -f $*..c # Don't do any special massaging of C files for sharing of strings!! # it causes weird segmentation faults on some systems. #.c.o: # ${CPP} ${CFLAGS} ${CPPFLAGS} $*.c | ${XSTR} -c - # ${CC} ${CF} ${CFLAGS} ${CPPFLAGS} x.c # mv -f x.o $*.o # rm -f x.c #ed.init.o: ed.init.c # ${CPP} ${CFLAGS} ${CPPFLAGS} $*.c | ${XSTR} -c - # ${CC} -R ${CF} ${CFLAGS} ${CPPFLAGS} x.c # mv -f x.o $*.o # rm -f x.c #strings.o: strings # ${XSTR} # ${CC} -c -R xs.c # mv -f xs.o strings.o # rm -f xs.c ##.DEFAULT: ## ${SCCS} get $< ##.DEFAULT: ## co $< ed.defns.h: ed.defns.c @rm -f $@.tmp @echo '/* Do not edit this file, make creates it. */' > $@.tmp @echo '#ifndef _h_ed_defns' >> $@.tmp @echo '#define _h_ed_defns' >> $@.tmp grep '[FV]_' $(srcdir)/ed.defns.c | grep '^#define' >> $@.tmp @echo '#endif /* _h_ed_defns */' >> $@.tmp @if [ -f $@ ] && cmp -s $@.tmp $@; then echo $@ unchanged.; rm -f $@.tmp; else mv -f $@.tmp $@; echo $@ recreated.; fi sh.err.h: sh.err.c @rm -f $@.tmp @echo '/* Do not edit this file, make creates it. */' > $@.tmp @echo '#ifndef _h_sh_err' >> $@.tmp @echo '#define _h_sh_err' >> $@.tmp grep 'ERR_' $(srcdir)/sh.err.c | grep '^#define' >> $@.tmp @echo '#endif /* _h_sh_err */' >> $@.tmp @if [ -f $@ ] && cmp -s $@.tmp $@; then echo $@ unchanged.; rm -f $@.tmp; else mv -f $@.tmp $@; echo $@ recreated.; fi tc.const.h: tc.const.c sh.char.h config.h config_f.h sh.types.h sh.err.h @rm -f $@.tmp @echo '/* Do not edit this file, make creates it. */' > $@.tmp @echo '#ifndef _h_tc_const' >> $@.tmp @echo '#define _h_tc_const' >> $@.tmp ${CPP} $(CPPFLAGS) ${DFLAGS} ${EXTRAFLAGS} -D_h_tc_const\ $(srcdir)/tc.const.c | \ sed -n -e 's/^\(Char STR[a-zA-Z0-9_]*\) *\[ *\].*/extern \1[];/p' | \ LC_COLLATE=C sort >> $@.tmp @echo '#endif /* _h_tc_const */' >> $@.tmp @if [ -f $@ ] && cmp -s $@.tmp $@; then echo $@ unchanged.; rm -f $@.tmp; else mv -f $@.tmp $@; echo $@ recreated.; fi $(srcdir)/tests/package.m4: $(srcdir)/configure.ac { \ echo '# Signature of the current package.'; \ echo 'm4_define([AT_PACKAGE_NAME], [@PACKAGE_NAME@])'; \ echo 'm4_define([AT_PACKAGE_TARNAME], [@PACKAGE_TARNAME@])'; \ echo 'm4_define([AT_PACKAGE_VERSION], [@PACKAGE_VERSION@])'; \ echo 'm4_define([AT_PACKAGE_STRING], [@PACKAGE_STRING@])'; \ echo 'm4_define([AT_PACKAGE_BUGREPORT], [@PACKAGE_BUGREPORT@])'; \ } >$(srcdir)/tests/package.m4 $(srcdir)/tests/testsuite: $(srcdir)/tests/package.m4 $(srcdir)/tests/testsuite.at $(TESTFILES) autom4te --language=autotest -I $(srcdir)/tests \ $(srcdir)/tests/testsuite.at -o $@.tmp mv $@.tmp $@ atconfig: config.status $(SHELL) ./config.status ./atconfig csh.prof: ${OBJS} sh.prof.${SUF} mcrt0.${SUF} rm -f csh.prof ld -X mcrt0.${SUF} ${OBJS} -o csh.prof ${LIBES} -lc sh.prof.${SUF}: cp sh.c sh.prof.c ${CC} ${CF} ${CFLAGS} ${CPPFLAGS} -DPROF sh.prof.c lint: tc.const.h ed.defns.h lint ${DFLAGS} ${CPPFLAGS} ${LFLAGS} sh*.c tw*.c ed*.c tc.*.c ${LIBES} alint: tc.const.h ed.defns.h alint ${DFLAGS} ${CPPFLAGS} ${LFLAGS} sh*.c tw*.c ed*.c tc.*.c ${LIBES} print: @pr READ_ME @pr makefile makefile.* @(size -l a.out; size *.${SUF}) | pr -h SIZES @${CXREF} sh*.c | pr -h XREF @ls -l | pr @pr sh*.h [a-rt-z]*.h sh*.c alloc.c vprint: @pr -l84 READ_ME TODO @pr -l84 makefile makefile.* @(size -l a.out; size *.${SUF}) | pr -l84 -h SIZES @${CXREF} sh*.c | pr -l84 -h XREF @ls -l | pr -l84 @${CXREF} sh*.c | pr -l84 -h XREF @pr -l84 sh*.h [a-rt-z]*.h sh*.c alloc.c vgrind: @cp /dev/null index @for i in *.h; do vgrind -t -h "C Shell" $$i >/crp/bill/csh/$$i.t; done @for i in *.c; do vgrind -t -h "C Shell" $$i >/crp/bill/csh/$$i.t; done @vgrind -t -x -h Index index >/crp/bill/csh/index.t install-strip: install -strip ${DESTBIN}/tcsh$(EXEEXT) install: tcsh$(EXEEXT) install.catalogs install.man -mkdir -p ${DESTBIN} -mv -f ${DESTBIN}/tcsh$(EXEEXT) ${DESTBIN}/tcsh.old cp tcsh$(EXEEXT) ${DESTBIN}/tcsh$(EXEEXT) chmod 755 ${DESTBIN}/tcsh$(EXEEXT) install.catalogs: @test "x${BUILD_CATALOGS}" = "xyes" && (cd nls; ${MAKE} install DESTDIR=${DESTDIR}) || exit 0 install.man: tcsh.man -mkdir -p ${DESTMAN} -rm -f ${DESTMAN}/tcsh.${MANSECT} cp $(srcdir)/tcsh.man ${DESTMAN}/tcsh.${MANSECT} chmod 444 ${DESTMAN}/tcsh.${MANSECT} # Amiga Unix #install.man: tcsh.man # compress tcsh.man # cp tcsh.man.Z ${DESTMAN}/tcsh.Z # chmod 444 ${DESTMAN}/tcsh.Z # Apple A/UX #install.man: tcsh.man # -rm -f ${DESTMAN}/tcsh.${MANSECT}.Z # nroff -man tcsh.man | compress > ${DESTMAN}/tcsh.${MANSECT}.Z # chmod 444 ${DESTMAN}/tcsh.${MANSECT}.Z clean: clean.catalogs ${RM} -f a.out strings x.c xs.c tcsh$(EXEEXT) tcsh.a _MAKE_LOG gethost ${RM} -f *.${SUF} *.i *.s ${RM} -f sh.prof.c ed.defns.h tc.const.h sh.err.h tc.defs.c ${RM} -f tcsh.*.m tcsh.*.cat clean.catalogs: @test "x${BUILD_CATALOGS}" = "xyes" && (cd nls; ${MAKE} clean) || exit 0 veryclean: clean ${RM} -f Makefile config.h config_p.h ${RM} -f config.status config.cache config.log tcsh.ps ${RM} -f missing + ${RM} -f testsuite.log + ${RM} -rf testsuite.dir ${RM} -rf autom4te.cache ${RM} -f *~ #* distclean: veryclean cleandir: veryclean tags: /tmp ${CTAGS} sh*.c tar.Z: rm -f tcsh-${VERSION}.tar.Z rm -rf tcsh-${VERSION} -mkdir tcsh-${VERSION} tcsh-${VERSION}/config tcsh-${VERSION}/tests cp ${ALLSRCS} tcsh-${VERSION} cp ${CONFSRCS} tcsh-${VERSION}/config tar cf - nls/Makefile nls/?*/set?* | (cd tcsh-${VERSION}; tar xpf -) tar cvf - tcsh-${VERSION} | compress > tcsh-${VERSION}.tar.Z rm -rf tcsh-${VERSION} tar.gz: rm -f tcsh-${VERSION}.tar.gz rm -rf tcsh-${VERSION} -mkdir tcsh-${VERSION} tcsh-${VERSION}/config tcsh-${VERSION}/tests cp ${ALLSRCS} tcsh-${VERSION} cp ${CONFSRCS} tcsh-${VERSION}/config tar cf - nls/Makefile nls/?*/set?* | (cd tcsh-${VERSION}; tar xpf -) tar cvf - tcsh-${VERSION} | gzip > tcsh-${VERSION}.tar.gz rm -rf tcsh-${VERSION} shar: rm -f tcsh-*.shar rm -rf tcsh-${VERSION} -mkdir tcsh-${VERSION} tcsh-${VERSION}/config tcsh-${VERSION}/tests cp ${ALLSRCS} tcsh-${VERSION} cp ${CONFSRCS} tcsh-${VERSION}/config tar cf - nls/Makefile nls/?*/set?* | (cd tcsh-${VERSION}; tar xpf -) MAKESHAR -v -n tcsh-${VERSION} tcsh-${VERSION} \ tcsh-${VERSION}/?* tcsh-${VERSION}/config/?* \ tcsh-${VERSION}/?*/set?* rm -rf tcsh-${VERSION} catalogs: @test "x${BUILD_CATALOGS}" = "xyes" && (cd nls; ${MAKE} catalogs) || exit 0 tcsh-${VERSION}.tar.Z: rm -rf tcsh-${VERSION} rm -f tcsh-${VERSION}.tar tcsh-${VERSION}.tar.Z DIFFS.[123] -mkdir tcsh-${VERSION} tcsh-${VERSION}/tests ./MAKEDIFFS bsd mv DIFFS.1 DIFFS.2 DIFFS.3 tcsh-${VERSION} cp ${DISTSRCS} tcsh-${VERSION} -mkdir tcsh-${VERSION}/config cp ${CONFSRCS} tcsh-${VERSION}/config cp Makefile tcsh-${VERSION}/Makefile.new tar cf - nls/Makefile nls/?*/set?* | (cd tcsh-${VERSION}; tar xpf -) tar cvf - tcsh-${VERSION} | compress > tcsh-${VERSION}.tar.Z rm -rf tcsh-${VERSION} tcsh.tahoe-${VERSION}.tar.Z: rm -rf tcsh.tahoe-${VERSION} rm -f tcsh.tahoe-${VERSION}.tar tcsh.tahoe-${VERSION}.tar.Z DIFFS.[123] -mkdir tcsh.tahoe-${VERSION} ./MAKEDIFFS tahoe mv DIFFS.1 DIFFS.2 DIFFS.3 tcsh.tahoe-${VERSION} cp ${DISTSRCS} tcsh.tahoe-${VERSION} -mkdir tcsh.tahoe-${VERSION}/config cp ${CONFSRCS} tcsh.tahoe-${VERSION}/config cp Makefile tcsh.tahoe-${VERSION}/Makefile.new tar cf - nls/Makefile nls/?*/set?* | (cd tcsh-${VERSION}; tar xpf -) tar cvf - tcsh.tahoe-${VERSION} | compress > tcsh.tahoe-${VERSION}.tar.Z rm -rf tcsh.tahoe-${VERSION} tcsh.reno-${VERSION}.tar.Z: rm -rf tcsh.reno-${VERSION} rm -f tcsh.reno-${VERSION}.tar tcsh.reno-${VERSION}.tar.Z DIFFS.[123] -mkdir tcsh.reno-${VERSION} ./MAKEDIFFS reno mv DIFFS.1 DIFFS.2 DIFFS.3 tcsh.reno-${VERSION} cp ${DISTSRCS} tcsh.reno-${VERSION} -mkdir tcsh.reno-${VERSION}/config cp ${CONFSRCS} tcsh.reno-${VERSION}/config cp Makefile tcsh.reno-${VERSION}/Makefile.new tar cf - nls/Makefile nls/?*/set?* | (cd tcsh-${VERSION}; tar xpf -) tar cvf - tcsh.reno-${VERSION} | compress > tcsh.reno-${VERSION}.tar.Z rm -rf tcsh.reno-${VERSION} ftp: tcsh-${VERSION}.tar.Z tcsh.tahoe-${VERSION}.tar.Z cp tcsh-${VERSION}.tar.Z tcsh.tahoe-${VERSION}.tar.Z ${FTPAREA} cp tcsh.man ${FTPAREA} autoconfigure: $(srcdir)/configure $(srcdir)/config.h.in $(srcdir)/configure: $(srcdir)/configure.ac cd $(srcdir) && autoconf $(srcdir)/config.h.in: $(srcdir)/stamp-h.in $(srcdir)/stamp-h.in: $(srcdir)/configure.ac cd $(srcdir) && autoheader @echo timestamp > $(srcdir)/stamp-h.in -check: atconfig $(srcdir)/tests/testsuite - $(SHELL) $(srcdir)/tests/testsuite +check test: atconfig $(srcdir)/tests/testsuite + $(ENVCMD) - \ + USER="$(USER)" \ + $(SHELL) $(srcdir)/tests/testsuite # # Dependencies # config.h: config_f.h TCH=tc.h tc.const.h tc.decls.h tc.nls.h tc.os.h tc.sig.h SHH=sh.h sh.types.h sh.char.h sh.err.h sh.dir.h sh.proc.h pathnames.h \ sh.decls.h ${TCH} TWH=tw.h tw.decls.h EDH=ed.h ed.decls.h # EDH EDINC=sh.${SUF} sh.func.${SUF} sh.lex.${SUF} sh.print.${SUF} sh.proc.${SUF} \ sh.set.${SUF} tc.bind.${SUF} tc.os.${SUF} tc.prompt.${SUF} \ tc.sched.${SUF} tw.parse.${SUF} tw.color.${SUF} ${EDOBJS} ${EDINC} : ${EDH} # SHH ${OBJS}: config.h ${SHH} # TWH TWINC=ed.chared.${SUF} ed.inputl.${SUF} sh.exec.${SUF} sh.func.${SUF} \ sh.set.${SUF} tc.func.${SUF} tc.nls.${SUF} tw.color.${SUF} ${TWOBJS} ${TWINC}: ${TWH} # glob.h glob.${SUF} sh.glob.${SUF}: glob.h # dotlock.h dotlock.${SUF}: dotlock.h # ed.defns.h EDDINC=tc.bind.${SUF} tc.func.${SUF} tc.os.${SUF} ${EDOBJS} ${EDDINC}: ed.defns.h # tc.defs.o tc.defs.${SUF}: tc.defs.c sh.h diff --git a/contrib/tcsh/Makefile.std b/contrib/tcsh/Makefile.std index 3466d4ceac86..8c479fa1f213 100644 --- a/contrib/tcsh/Makefile.std +++ b/contrib/tcsh/Makefile.std @@ -1,630 +1,630 @@ # # C Shell with process control; VM/UNIX VAX Makefile # Bill Joy UC Berkeley; Jim Kulp IIASA, Austria # # With an input editor, command completion, etc. and ported to all sorts of # things; Paul Placeway, CIS Dept., Ohio State University # SHELL=/bin/sh VERSION=6.12 BUILD=tcsh srcdir=. ################################################################ ## CFLAGS. For various -D things, see config.h ################################################################ # # These are the default suffixes from .c to .o and -c to get there # but to use the global optimizer on the mips boxes, see below # SUF=o CF=-c INCLUDES=-I. -I$(srcdir) LFLAGS=$(INCLUDES) #LFLAGS=$(INCLUDES) -Zn10000 # hpux lint #CFLAGS= $(INCLUDES) -g # debug #CFLAGS= $(INCLUDES) -O # production #CFLAGS= $(INCLUDES) # Broken optimizers.... #CFLAGS= -g -pg $(INCLUDES) -DPROF #CFLAGS= -O -pg $(INCLUDES) -DPROF # gcc 1.00-1.37 #CFLAGS=-O $(INCLUDES) -finline-functions -fstrength-reduce # gcc 1.37-1.40 #CFLAGS=-O $(INCLUDES) -fcombine-regs -finline-functions -fstrength-reduce # add -msoft-float for 68881 machines. # gcc 2.0 # On the sparc, don't use -O2; it breaks setjmp() and vfork() #CFLAGS=-O $(INCLUDES) # gcc-2.1+ CFLAGS=-O2 $(INCLUDES) # lucid c on suns #CFLAGS=-O5 $(INCLUDES) # gcc 2.1 on linux #CFLAGS=-O6 -fomit-frame-pointer $(INCLUDES) # HP/UX 8.0, 9.0 #CFLAGS= $(INCLUDES) +O3 -Aa # Ultrix 4.2a #CFLAGS= $(INCLUDES) -O -Olimit 2000 # Intel Paragon OSF/1 with PGI compilers #CFLAGS=-O -Mnodebug -Mnoperfmon $(INCLUDES) # DEC Alpha OSF/1 #CFLAGS= -O2 $(INCLUDES) -Olimit 2000 ## Normal Optimization #CFLAGS= -O3 $(INCLUDES) -Olimit 2000 ## Full Optimization - may not work #CF=-j #SUF=u #.SUFFIXES: .u # for silicon graphics (and other mips compilers) -- use the # global optimizer! (-O3). # On SGI 4.0+ you need to add -D__STDC__ too. #CFLAGS= -O3 $(INCLUDES) #CFLAGS= -O3 $(INCLUDES) -Olimit 2000 ## Ultrix 4.2a #CF=-j #SUF=u #.SUFFIXES: .u ## Ultrix and gnu-make need that # mips systems # CFLAGS= $(INCLUDES) -O -systype bsd43 -Wf,-XNd5000 -Wf,-XNp6000 -Olimit 2000 # for at&t machines #CFLAGS= -O -Ksd $(INCLUDES) # Stardent Titan #CFLAGS = $(INCLUDES) -O -43 # Stardent Stellar or sunos4 /bin/cc or Solaris2.1 /opt/SUNWspro/bin/cc #CFLAGS = $(INCLUDES) -O4 # Intergraph clipper CLIX 3.1 #CFLAGS= -w -O2 $(INCLUDES) # Dnix 5.3 #CFLAGS = -O -X7 # Pyramid OS/x #CFLAGS = -OG # Multiflow (5M binary... if you choose -O5!) #CFLAGS = -O5 -sb_trace 0 # DDE Supermax Unix SYSV Rel III. # CFLAGS= -O3 # SINIX RMx00 #CFLAGS= -O # -D_POSIX_SOURCE # -kansi # Minix-VMD # CFLAGS= -O -D_ANSI_H -I /usr/include/bsdcompat $(INCLUDES) # Apollo's with cc [apollo builtins don't work with gcc] # and apollo should not define __STDC__ if it does not have # the standard header files. RT's (aos4.3) need that too; # you might want to skip the -O on the rt's... Not very wise. # AIX/ESA needs -D_IBMESA on command line (this may disappear by GA) #DFLAGS=-U__STDC__ #DFLAGS=-D_IBMESA # On aix2.2.1 we need more compiler space. #DFLAGS=-Nd4000 -Nn3000 # AU/X 2.0 needs a flag for POSIX (read the config file) #DFLAGS=-Zp # Tektronix 4300 running UTek 4.0 (BSD 4.2) needs: #DFLAGS = -DUTek -DBSD # VMS_POSIX needs: #DFLAGS=-D_VMS_POSIX # Multiflow and PCC compilers don't like void typedefs. # You may also need -U__STDC__ if you use pcc (i.e. ibmrt aos4.3). #DFLAGS=-DMULTIFLOW #DFLAGS=-DPCC # DELL SVR4 #DFLAGS=-DDELL # SCO_SV #DFLAGS=-D_SPEED_T -DSCO DFLAGS= #DFLAGS=-D_PATH_TCSHELL='"${DESTBIN}/tcsh"' ################################################################ ## LDFLAGS. Define something here if you need to ################################################################ LDFLAGS= ## The simplest, suitable for all. #LDFLAGS= -s ## Stripped. Takes less space on disk. #LDFLAGS= -s -n ## Pure executable. Spares paging over # ## the network for machines with local # ## swap but external /usr/local/bin . #LDFLAGS= -s -n -Bstatic ## Without dynamic linking. (SunOS/cc) #LDFLAGS= -s -n -static ## Without dynamic linking. (SunOS/gcc) #LDFLAGS= -Wl,-s,-n ## Stripped, shared text (Unicos) #LDFLAGS= -s -static ## Link statically. (linux) #LDFLAGS= -s -N ## Impure executable (linux) #LDFLAGS= -Bdynamic -dy ## SCO_SV ################################################################ ## LIBES. Pick one, or roll your own. ################################################################ LIBES= -ltermcap ## BSD style things #LIBES= -ltermcap ## SunOS, HP-UX, pyramid #LIBES= -ltermcap ## Linux #LIBES= -ltermcap -lshadow ## Linux with PW_SHADOW #LIBES= -ltermcap -lsec ## Tek XD88/10 (UTekV) with PW_SHADOW #LIBES= -ltermcap -lsec ## Motorola MPC (sysV88) with PW_SHADOW #LIBES= -ltermcap -lcs ## Mach #LIBES= -ltermcap -lbsd ## DEC osf1 on the alpha #LIBES= -ltermcap -lbsd ## Intel paragon #LIBES= -ltermcap -lbsd ## Clipper intergraph #LIBES= -ltermcap -lseq ## Sequent's Dynix #LIBES= -ltermcap -lauth ## Ultrix with Enhanced Security #LIBES= -ltermcap -ldir -lx ## Xenix 386 style things #LIBES= -ltermcap -lndir -lsocket -ljobs ## masscomp RTU6.0 #LIBES= -lcurses ## AIX on the rt #LIBES= -lcurses ## TitanOS on the stellar #LIBES= -ltermlib -lsocket -lnsl ## SysV4 w/o BSDTIMES or Solaris 2 #LIBES= -lcurses ## SysV3 w/o networking #LIBES= -lcurses -lnet ## SysV3 with networking #LIBES= -lcurses -ldir ## SysV2 w/o networking & dirlib #LIBES= -lcurses -ldir -lnet ## SysV2 with networking & dirlib #LIBES= -lcurses -lbsd ## AIX on the IBM 370 or rs6000 or ps2 #LIBES= -lcurses -lbsd ## ETA10 #LIBES= -lcurses -lbsd ## Irix3.1 on the SGI-IRIS4D #LIBES= -lcurses -lbsd -lc_s ## Irix3.3 on the SGI-IRIS4D w/o yp #LIBES= -lcurses -lsun -lbsd -lc_s ## Irix3.3 on the SGI-IRIS4D with yp #LIBES= -lcurses -lsocket -lbsd ## Amdahl UTS 2.1 #LIBES= -lcurses -lsocket ## Intel's hypercube. #LIBES= -lcurses -lsocket ## ns32000 based Opus. #LIBES= -lcurses -lcposix ## ISC 2.2 without networking #LIBES= -lcposix -lc_s -lcurses -linet ## ISC 2.2 with networking #LIBES= -lcurses -lsec -lc_s ## ISC 2.0.2 without networking #LIBES= -lcurses -linet -lsec -lc_s ## ISC 2.0.2 with networking #LIBES= -lcurses -lintl -lcrypt ## SCO SysVR3.2v2.0 #LIBES= -lcurses -lintl -lsocket -lcrypt ## SCO+ODT1.1 #LIBES= -lcurses -lsocket -lcrypt ## SCO_SV #LIBES= -lposix -ltermcap ## A/UX 2.0 #LIBES= -lposix -ltermcap -lc_s ## A/UX 3.0 #LIBES= -ldirent -lcurses ## att3b1 cc w/o shared lib & dirlib #LIBES= -shlib -ldirent -lcurses ## att3b1 gcc with shared lib & dirlib #LIBES= -ltermlib -lsocket -lnsl -lc /usr/ucblib/libucb.a ## SysV4 with BSDTIMES #LIBES= -lcurses -lnsl -lsocket -lc /usr/ucblib/libucb.a ## Stardent Vistra #LIBES= -ltermc ## emx under OS/2 #LIBES= ## Minix, VMS_POSIX #LIBES= -ltermcap -lcrypt ## Multiflow #LIBES= -ltermcap -lcrypt ## NetBSD #LIBES= -lcurses ## DDE Supermax ################################################################ ## EXTRAFLAGS and EXTRALIBS ################################################################ # Compiling for HESIOD #HESDEF = -DHESIOD -I/usr/athena/include #HESLIB = -L/usr/athena/lib -lhesiod # # Compiling for AFS with kerberos authentication #AFSLIBDIR = /usr/afsws/lib #AFSDEF = -DAFS -I/usr/afsws/include #AFS33LIB = -laudit # #Solaris and HPUX require the BSD libraries with AFS. #We use -lc to use only what we require. #AFSAUXLIB = -lsocket -lnsl -lc -lucb # Solaris #AFSAUXLIB = -lc -lBSD # HPUX # #AFSLIB = -L$(AFSLIBDIR) -L$(AFSLIBDIR)/afs -lkauth -lprot -lubik\ # -lauth -lrxkad -lsys -ldes -lrx -llwp -lcom_err\ # $(AFSLIBDIR)/afs/util.a $(AFS33LIB) $(AFSAUXLIB) # EXTRAFLAGS = $(HESDEF) $(AFSDEF) EXTRALIBS = $(HESLIB) $(AFSLIB) # The difficult choice of a c-compiler... # First, you should try your own c-compiler. # Gcc -traditional is also a safe choice. # If you think that you have good include files try gcc -Wall... # If you want to take out -traditional, make sure that your sys/ioctl.h # is fixed correctly, otherwise you'll be stopped for tty input, or you # will lose the editor and job control. # This is for setting your C preprocessor value. CPP = ${CC} -E # The -B tells gcc to use /bin/ld. This is to avoid using the gnu ld, which # on the suns does not know how to make dynamically linked binaries. CC= gcc -Wall -pipe -B/bin/ # -ansi -pedantic #CC= gcc -m486 -pipe -Wall # Generate code for Intel 486 (linux) #CC= shlicc # BSDI2.1 w/ shared libraries #CC= cc #CC= occ #CC= acc #CC= pcc #CC= hc -w #CC= c89 # For VMS/POSIX #CC= /bin/cc # For suns, w/o gcc and SVR4 #CC= /usr/lib/sun.compile/cc # FPS 500 (+FPX) with Sun C compiler #CC= /opt/SUNWspro/bin/cc # Solaris 2.1 #CC= scc # Alliant fx2800 #CC= lcc -wa #CC= cc -b elf -Kpic # SCO_SV ED= ed AS= as RM= rm CXREF= /usr/ucb/cxref #CXREF= /bin/cxref # SCO_SV VGRIND= csh /usr/ucb/vgrind CTAGS= /usr/ucb/ctags #CTAGS= /usr/bin/ctags # SCO_SV #XSTR= /usr/ucb/xstr #XSTR= /usr/bin/xstr # SCO_SV SCCS= /usr/local/sccs PARALLEL=12 # Make the multi-max run fast. #P=& # Use Sequent's parallel make P= DESTDIR=/usr/local #DESTDIR=/usr/contrib MANSECT=1 DESTBIN=${DESTDIR}/bin DESTMAN=${DESTDIR}/man/man${MANSECT} # DESTMAN=${DESTDIR}/catman/man${MANSECT} # A/UX # DESTMAN=${DESTDIR}/usr/share/man/man${MANSECT} # Stardent Vistra (SysVR4) # DESTMAN=/usr/catman/1l # Amiga unix (SysVR4) FTPAREA=/usr/spool/ftp ASSRCS= sh.c sh.dir.c sh.dol.c sh.err.c sh.exec.c sh.char.c \ sh.exp.c sh.file.c sh.func.c sh.glob.c sh.hist.c sh.init.c \ sh.lex.c sh.misc.c sh.parse.c sh.print.c sh.proc.c sh.sem.c \ sh.set.c sh.time.c sh.char.h sh.dir.h sh.proc.h sh.h PSSRCS= sh.decls.h glob.c glob.h dotlock.c dotlock.h mi.termios.c mi.wait.h mi.varargs.h ma.setp.c \ vms.termcap.c SHSRCS= ${ASSRCS} ${PSSRCS} SHOBJS= sh.${SUF} sh.dir.${SUF} sh.dol.${SUF} sh.err.${SUF} sh.exec.${SUF} \ sh.char.${SUF} sh.exp.${SUF} sh.file.${SUF} sh.func.${SUF} \ sh.glob.${SUF} sh.hist.${SUF} sh.init.${SUF} sh.lex.${SUF} \ sh.misc.${SUF} sh.parse.${SUF} sh.print.${SUF} sh.proc.${SUF} \ sh.sem.${SUF} sh.set.${SUF} sh.time.${SUF} glob.${SUF} dotlock.${SUF} \ mi.termios.${SUF} ma.setp.${SUF} vms.termcap.${SUF} TWSRCS= tw.decls.h tw.h tw.help.c tw.init.c tw.parse.c tw.spell.c \ tw.comp.c tw.color.c TWOBJS= tw.help.${SUF} tw.init.${SUF} tw.parse.${SUF} tw.spell.${SUF} \ tw.comp.${SUF} tw.color.${SUF} EDSRCS= ed.chared.c ed.decls.h ed.defns.c ed.h ed.init.c ed.inputl.c \ ed.refresh.c ed.screen.c ed.xmap.c ed.term.c ed.term.h EDOBJS= ed.chared.${SUF} ed.refresh.${SUF} ed.screen.${SUF} ed.init.${SUF} \ ed.inputl.${SUF} ed.defns.${SUF} ed.xmap.${SUF} ed.term.${SUF} TCSRCS= tc.alloc.c tc.bind.c tc.const.c tc.decls.h tc.disc.c \ tc.func.c tc.nls.c tc.os.c tc.os.h tc.printf.c tc.prompt.c \ tc.sched.c tc.sig.c tc.sig.h tc.str.c sh.types.h tc.vers.c tc.wait.h \ tc.who.c tc.h TCOBJS= tc.alloc.${SUF} tc.bind.${SUF} tc.const.${SUF} tc.defs.${SUF} \ tc.disc.${SUF} tc.func.${SUF} tc.nls.${SUF} tc.os.${SUF} tc.printf.${SUF} \ tc.prompt.${SUF} tc.sched.${SUF} tc.sig.${SUF} tc.str.${SUF} \ tc.vers.${SUF} tc.who.${SUF} PVSRCS= Makefile.std Makefile.vms Makefile.in Makefile.win32 AVSRCS= BUILDING Fixes MAKEDIFFS MAKESHAR NewThings README.md FAQ \ WishList config_f.h eight-bit.me glob.3 patchlevel.h \ pathnames.h tcsh.man Ported src.desc Imakefile imake.config \ complete.tcsh vmsreadme.txt termcap.vms snames.h host.defs \ gethost.c tcsh.man2html configure.ac configure config.h.in \ - aclocal.m4 + aclocal.m4 dot.login dot.tcshrc VHSRCS=${PVSRCS} ${AVSRCS} CONFSRCS=config/* ALLSRCS= ${SHSRCS} ${TWSRCS} ${EDSRCS} ${TCSRCS} ${VHSRCS} DISTSRCS= ${PSSRCS} ${TWSRCS} ${EDSRCS} ${TCSRCS} ${AVSRCS} OBJS= ${SHOBJS} ${TWOBJS} ${EDOBJS} ${TCOBJS} all: ${BUILD} tcsh:$(P) ${OBJS} rm -f tcsh core ${CC} -o tcsh ${LDFLAGS} ${CFLAGS} ${OBJS} ${LIBES} ${EXTRALIBS} # Purify pure:$(P) ${OBJS} rm -f tcsh core purify `echo ${CC} | sed -e s,-B/bin/,,` -o tcsh ${LDFLAGS} ${CFLAGS} ${OBJS} ${LIBES} ${EXTRALIBS} # OS/2 tcsh.exe: tcsh emxbind tcsh gethost: gethost.c sh.err.h tc.const.h sh.h rm -f gethost ${CC} -o gethost ${LDFLAGS} ${CFLAGS} ${DFLAGS} $(srcdir)/gethost.c ${LIBES} ${EXTRALIBS} tc.defs.c: gethost host.defs @rm -f $@ @echo "/* Do not edit this file, make creates it */" > $@ ./gethost $(srcdir)/host.defs >> $@ tcsh.ps: tcsh.man rm -f tcsh.ps -ptroff -t -man $(srcdir)/tcsh.man > tcsh.ps .c.${SUF}: ${CC} ${CF} ${CFLAGS} ${DFLAGS} ${EXTRAFLAGS} $< # _VMS_POSIX #module addition #.c.${SUF}: # @(echo '#module '`echo $< | sed -e 's/\./_/g'`; cat $<) > $*..c # @echo ${CC} ${CF} ${CFLAGS} ${DFLAGS} ${EXTRAFLAGS} $*.c # @${CC} ${CF} ${CFLAGS} ${DFLAGS} ${EXTRAFLAGS} $*..c # @mv $*..o $*.o # @rm -f $*..c # Don't do any special massaging of C files for sharing of strings!! # it causes weird segmentation faults on some systems. #.c.o: # ${CPP} ${CFLAGS} $*.c | ${XSTR} -c - # ${CC} ${CF} ${CFLAGS} x.c # mv -f x.o $*.o # rm -f x.c #ed.init.o: ed.init.c # ${CPP} ${CFLAGS} $*.c | ${XSTR} -c - # ${CC} -R ${CF} ${CF} x.c # mv -f x.o $*.o # rm -f x.c #strings.o: strings # ${XSTR} # ${CC} -c -R xs.c # mv -f xs.o strings.o # rm -f xs.c ##.DEFAULT: ## ${SCCS} get $< ##.DEFAULT: ## co $< ed.defns.h: ed.defns.c @rm -f $@ @echo '/* Do not edit this file, make creates it. */' > $@ @echo '#ifndef _h_ed_defns' >> $@ @echo '#define _h_ed_defns' >> $@ grep '[FV]_' $(srcdir)/ed.defns.c | grep '^#define' >> $@ @echo '#endif /* _h_ed_defns */' >> $@ sh.err.h: sh.err.c @rm -f $@ @echo '/* Do not edit this file, make creates it. */' > $@ @echo '#ifndef _h_sh_err' >> $@ @echo '#define _h_sh_err' >> $@ grep 'ERR_' $(srcdir)/sh.err.c | grep '^#define' >> $@ @echo '#endif /* _h_sh_err */' >> $@ tc.const.h: tc.const.c sh.char.h config.h config_f.h sh.types.h sh.err.h @rm -f $@ @echo '/* Do not edit this file, make creates it. */' > $@ @echo '#ifndef _h_tc_const' >> $@ @echo '#define _h_tc_const' >> $@ ${CPP} $(INCLUDES) ${DFLAGS} ${EXTRAFLAGS} -D_h_tc_const\ $(srcdir)/tc.const.c | grep 'Char STR' | \ sed -e 's/Char \([a-zA-Z0-9_]*\) *\[ *\].*/extern Char \1[];/' | \ LC_COLLATE=C sort >> $@ @echo '#endif /* _h_tc_const */' >> $@ csh.prof: ${OBJS} sh.prof.${SUF} mcrt0.${SUF} rm -f csh.prof ld -X mcrt0.${SUF} ${OBJS} -o csh.prof ${LIBES} -lc sh.prof.${SUF}: cp sh.c sh.prof.c ${CC} ${CF} ${CFLAGS} -DPROF sh.prof.c lint: tc.const.h ed.defns.h lint ${DFLAGS} ${LFLAGS} sh*.c tw*.c ed*.c tc.*.c ${LIBES} alint: tc.const.h ed.defns.h alint ${DFLAGS} ${LFLAGS} sh*.c tw*.c ed*.c tc.*.c ${LIBES} print: @pr READ_ME @pr makefile makefile.* @(size -l a.out; size *.${SUF}) | pr -h SIZES @${CXREF} sh*.c | pr -h XREF @ls -l | pr @pr sh*.h [a-rt-z]*.h sh*.c alloc.c vprint: @pr -l84 READ_ME TODO @pr -l84 makefile makefile.* @(size -l a.out; size *.${SUF}) | pr -l84 -h SIZES @${CXREF} sh*.c | pr -l84 -h XREF @ls -l | pr -l84 @${CXREF} sh*.c | pr -l84 -h XREF @pr -l84 sh*.h [a-rt-z]*.h sh*.c alloc.c vgrind: @cp /dev/null index @for i in *.h; do vgrind -t -h "C Shell" $$i >/crp/bill/csh/$$i.t; done @for i in *.c; do vgrind -t -h "C Shell" $$i >/crp/bill/csh/$$i.t; done @vgrind -t -x -h Index index >/crp/bill/csh/index.t install: tcsh -mv -f ${DESTBIN}/tcsh ${DESTBIN}/tcsh.old cp tcsh ${DESTBIN}/tcsh -strip ${DESTBIN}/tcsh chmod 555 ${DESTBIN}/tcsh install.man: tcsh.man -rm -f ${DESTMAN}/tcsh.${MANSECT} cp $(srcdir)/tcsh.man ${DESTMAN}/tcsh.${MANSECT} chmod 444 ${DESTMAN}/tcsh.${MANSECT} # Amiga Unix #install.man: tcsh.man # compress tcsh.man # cp tcsh.man.Z ${DESTMAN}/tcsh.Z # chmod 444 ${DESTMAN}/tcsh.Z # Apple A/UX #install.man: tcsh.man # -rm -f ${DESTMAN}/tcsh.${MANSECT}.Z # nroff -man tcsh.man | compress > ${DESTMAN}/tcsh.${MANSECT}.Z # chmod 444 ${DESTMAN}/tcsh.${MANSECT}.Z clean: ${RM} -f a.out strings x.c xs.c tcsh tcsh.a _MAKE_LOG core gethost ${RM} -f *.${SUF} sh.prof.c ed.defns.h tc.const.h sh.err.h tc.defs.c ${RM} -f tcsh.*.m tcsh.*.cat veryclean: clean ${RM} -f config.h config.status config.cache config.log Makefile tcsh.ps ${RM} -f *~ #* distclean: veryclean tags: /tmp ${CTAGS} sh*.c tar.Z: rm -f tcsh-${VERSION}.tar.Z rm -rf tcsh-${VERSION} mkdir tcsh-${VERSION} tcsh-${VERSION}/config cp ${ALLSRCS} tcsh-${VERSION} cp ${CONFSRCS} tcsh-${VERSION}/config tar cf - nls/Makefile nls/?*/set?* | (cd tcsh-${VERSION}; tar xpf -) tar cvf - tcsh-${VERSION} | compress > tcsh-${VERSION}.tar.Z rm -rf tcsh-${VERSION} tar.gz: rm -f tcsh-${VERSION}.tar.gz rm -rf tcsh-${VERSION} mkdir tcsh-${VERSION} tcsh-${VERSION}/config cp ${ALLSRCS} tcsh-${VERSION} cp ${CONFSRCS} tcsh-${VERSION}/config tar cf - nls/Makefile nls/?*/set?* | (cd tcsh-${VERSION}; tar xpf -) tar cvf - tcsh-${VERSION} | gzip > tcsh-${VERSION}.tar.gz rm -rf tcsh-${VERSION} shar: rm -f tcsh-*.shar rm -rf tcsh-${VERSION} mkdir tcsh-${VERSION} tcsh-${VERSION}/config cp ${ALLSRCS} tcsh-${VERSION} cp ${CONFSRCS} tcsh-${VERSION}/config tar cf - nls/Makefile nls/?*/set?* | (cd tcsh-${VERSION}; tar xpf -) MAKESHAR -v -n tcsh-${VERSION} tcsh-${VERSION} \ tcsh-${VERSION}/?* tcsh-${VERSION}/config/?* \ tcsh-${VERSION}/?*/set?* rm -rf tcsh-${VERSION} catalogs: @(cd nls; make catalogs) tcsh-${VERSION}.tar.Z: rm -rf tcsh-${VERSION} rm -f tcsh-${VERSION}.tar tcsh-${VERSION}.tar.Z DIFFS.[123] mkdir tcsh-${VERSION} ./MAKEDIFFS bsd mv DIFFS.1 DIFFS.2 DIFFS.3 tcsh-${VERSION} cp ${DISTSRCS} tcsh-${VERSION} mkdir tcsh-${VERSION}/config cp ${CONFSRCS} tcsh-${VERSION}/config cp Makefile tcsh-${VERSION}/Makefile.new tar cf - nls/Makefile nls/?*/set?* | (cd tcsh-${VERSION}; tar xpf -) tar cvf - tcsh-${VERSION} | compress > tcsh-${VERSION}.tar.Z rm -rf tcsh-${VERSION} tcsh.tahoe-${VERSION}.tar.Z: rm -rf tcsh.tahoe-${VERSION} rm -f tcsh.tahoe-${VERSION}.tar tcsh.tahoe-${VERSION}.tar.Z DIFFS.[123] mkdir tcsh.tahoe-${VERSION} ./MAKEDIFFS tahoe mv DIFFS.1 DIFFS.2 DIFFS.3 tcsh.tahoe-${VERSION} cp ${DISTSRCS} tcsh.tahoe-${VERSION} mkdir tcsh.tahoe-${VERSION}/config cp ${CONFSRCS} tcsh.tahoe-${VERSION}/config cp Makefile tcsh.tahoe-${VERSION}/Makefile.new tar cf - nls/Makefile nls/?*/set?* | (cd tcsh-${VERSION}; tar xpf -) tar cvf - tcsh.tahoe-${VERSION} | compress > tcsh.tahoe-${VERSION}.tar.Z rm -rf tcsh.tahoe-${VERSION} tcsh.reno-${VERSION}.tar.Z: rm -rf tcsh.reno-${VERSION} rm -f tcsh.reno-${VERSION}.tar tcsh.reno-${VERSION}.tar.Z DIFFS.[123] mkdir tcsh.reno-${VERSION} ./MAKEDIFFS reno mv DIFFS.1 DIFFS.2 DIFFS.3 tcsh.reno-${VERSION} cp ${DISTSRCS} tcsh.reno-${VERSION} mkdir tcsh.reno-${VERSION}/config cp ${CONFSRCS} tcsh.reno-${VERSION}/config cp Makefile tcsh.reno-${VERSION}/Makefile.new tar cf - nls/Makefile nls/?*/set?* | (cd tcsh-${VERSION}; tar xpf -) tar cvf - tcsh.reno-${VERSION} | compress > tcsh.reno-${VERSION}.tar.Z rm -rf tcsh.reno-${VERSION} ftp: tcsh-${VERSION}.tar.Z tcsh.tahoe-${VERSION}.tar.Z cp tcsh-${VERSION}.tar.Z tcsh.tahoe-${VERSION}.tar.Z ${FTPAREA} cp tcsh.man ${FTPAREA} autoconfigure: $(srcdir)/configure $(srcdir)/config.h.in $(srcdir)/configure: $(srcdir)/configure.ac cd $(srcdir) && autoconf $(srcdir)/config.h.in: $(srcdir)/stamp-h.in $(srcdir)/stamp-h.in: $(srcdir)/configure.ac cd $(srcdir) && autoheader @echo timestamp > $(srcdir)/stamp-h.in # # Dependencies # config.h: config_f.h TCH=tc.h tc.const.h tc.decls.h tc.nls.h tc.os.h tc.sig.h SHH=sh.h sh.types.h sh.char.h sh.err.h sh.dir.h sh.proc.h pathnames.h \ sh.decls.h ${TCH} TWH=tw.h tw.decls.h EDH=ed.h ed.decls.h # EDH EDINC=sh.${SUF} sh.func.${SUF} sh.lex.${SUF} sh.print.${SUF} sh.proc.${SUF} \ sh.set.${SUF} tc.bind.${SUF} tc.os.${SUF} tc.prompt.${SUF} \ tc.sched.${SUF} tw.parse.${SUF} tw.color.${SUF} ${EDOBJS} ${EDINC} : ${EDH} # SHH ${OBJS}: config.h ${SHH} # TWH TWINC=ed.chared.${SUF} ed.inputl.${SUF} sh.exec.${SUF} sh.func.${SUF} \ sh.set.${SUF} tc.func.${SUF} tc.nls.${SUF} tw.color.${SUF} ${TWOBJS} ${TWINC}: ${TWH} # glob.h glob.${SUF} sh.glob.${SUF}: glob.h # dotlock.h dotlock.${SUF}: dotlock.h # ed.defns.h EDDINC=tc.bind.${SUF} tc.func.${SUF} tc.os.${SUF} ${EDOBJS} ${EDDINC}: ed.defns.h # tc.defs.o tc.defs.${SUF}: tc.defs.c sh.h diff --git a/contrib/tcsh/Makefile.vms b/contrib/tcsh/Makefile.vms index bc241147e253..2e3f4adbfed4 100644 --- a/contrib/tcsh/Makefile.vms +++ b/contrib/tcsh/Makefile.vms @@ -1,592 +1,592 @@ # # C Shell with process control; VM/UNIX VAX Makefile # Bill Joy UC Berkeley; Jim Kulp IIASA, Austria # # With an input editor, command completion, etc. and ported to all sorts of # things; Paul Placeway, CIS Dept., Ohio State University # SHELL=/bin/sh VERSION=6.12 BUILD=tcsh ################################################################ ## CFLAGS. For various -D things, see config.h ################################################################ # # These are the default suffixes from .c to .o and -c to get there # but to use the global optimizer on the mips boxes, see below # SUF=o CF=-c INCLUDES=-I. -I.. LFLAGS=$(INCLUDES) #LFLAGS=$(INCLUDES) -Zn10000 # hpux lint #CFLAGS= $(INCLUDES) -g # debug #CFLAGS= $(INCLUDES) -O # production #CFLAGS= $(INCLUDES) # Broken optimizers.... #CFLAGS= -g -pg $(INCLUDES) -DPROF #CFLAGS= -O -pg $(INCLUDES) -DPROF # gcc 1.00-1.37 #CFLAGS=-O $(INCLUDES) -finline-functions -fstrength-reduce # gcc 1.37-1.40 #CFLAGS=-O $(INCLUDES) -fcombine-regs -finline-functions -fstrength-reduce # add -msoft-float for 68881 machines. # gcc 2.0 # On the sparc, don't use -O2; it breaks setjmp() and vfork() #CFLAGS=-O $(INCLUDES) # gcc-2.1+ #CFLAGS=-O2 $(INCLUDES) # lucid c on suns #CFLAGS=-O5 $(INCLUDES) # gcc 2.1 on linux #CFLAGS=-O6 -fomit-frame-pointer $(INCLUDES) # HP/UX 8.0, 9.0 #CFLAGS= $(INCLUDES) +O3 -Aa # Ultrix 4.2a #CFLAGS= $(INCLUDES) -O -Olimit 2000 # Intel Paragon OSF/1 with PGI compilers #CFLAGS=-O -Mnodebug -Mnoperfmon $(INCLUDES) # DEC Alpha OSF/1 #CFLAGS= -O2 $(INCLUDES) -Olimit 2000 ## Normal Optimization #CFLAGS= -O3 $(INCLUDES) -Olimit 2000 ## Full Optimization - may not work #CF=-j #SUF=u #.SUFFIXES: .u # for silicon graphics (and other mips compilers) -- use the # global optimizer! (-O3). # On SGI 4.0+ you need to add -D__STDC__ too. #CFLAGS= -O3 $(INCLUDES) #CFLAGS= -O3 $(INCLUDES) -Olimit 2000 ## Ultrix 4.2a #CF=-j #SUF=u #.SUFFIXES: .u ## Ultrix and gnu-make need that # mips systems # CFLAGS= $(INCLUDES) -O -systype bsd43 -Wf,-XNd5000 -Wf,-XNp6000 -Olimit 2000 # for at&t machines #CFLAGS= -O -Ksd $(INCLUDES) # Stardent Titan #CFLAGS = $(INCLUDES) -O -43 # Stardent Stellar or sunos4 /bin/cc or Solaris2.1 /opt/SUNWspro/bin/cc #CFLAGS = $(INCLUDES) -O4 # Intergraph clipper CLIX 3.1 #CFLAGS= -w -O2 $(INCLUDES) # Dnix 5.3 #CFLAGS = -O -X7 # Pyramid OS/x #CFLAGS = -OG # Multiflow (5M binary... if you choose -O5!) #CFLAGS = -O5 -sb_trace 0 # DDE Supermax Unix SYSV Rel III. # CFLAGS= -O3 # Apollo's with cc [apollo builtins don't work with gcc] # and apollo should not define __STDC__ if it does not have # the standard header files. RT's (aos4.3) need that too; # you might want to skip the -O on the rt's... Not very wise. # AIX/ESA needs -D_IBMESA on command line (this may disappear by GA) #DFLAGS=-U__STDC__ #DFLAGS=-D_IBMESA # On aix2.2.1 we need more compiler space. #DFLAGS=-Nd4000 -Nn3000 # AU/X 2.0 needs a flag for POSIX (read the config file) #DFLAGS=-Zp # Tektronix 4300 running UTek 4.0 (BSD 4.2) needs: #DFLAGS = -DUTek -DBSD # VMS_POSIX needs: #DFLAGS=-D_VMS_POSIX # Multiflow #DFLAGS=-DMULTIFLOW # DELL SVR4 #DFLAGS=-DDELL DFLAGS= #DFLAGS=-D_PATH_TCSHELL='"${DESTBIN}/tcsh"' ################################################################ ## LDFLAGS. Define something here if you need to ################################################################ LDFLAGS= ## The simplest, suitable for all. #LDFLAGS= -s ## Stripped. Takes less space on disk. #LDFLAGS= -s -n ## Pure executable. Spares paging over # ## the network for machines with local # ## swap but external /usr/local/bin . #LDFLAGS= -s -n -Bstatic ## Without dynamic links. (SunOS) #LDFLAGS= -Wl,-s,-n ## Stripped, shared text (Unicos) #LDFLAGS= -s -static ## Link statically. (linux) #LDFLAGS= -s -N ## Impure executable (linux) ################################################################ ## LIBES. Pick one, or roll your own. ################################################################ #LIBES= -ltermcap ## BSD style things #LIBES= -ltermcap ## SunOS, HP-UX, pyramid #LIBES= -ltermcap ## Linux #LIBES= -ltermcap -lshadow ## Linux with PW_SHADOW #LIBES= -ltermcap -lsec ## Tek XD88/10 (UTekV) with PW_SHADOW #LIBES= -ltermcap -lsec ## Motorola MPC (sysV88) with PW_SHADOW #LIBES= -ltermcap -lcs ## Mach #LIBES= -ltermcap -lbsd ## DEC osf1 on the alpha #LIBES= -ltermcap -lbsd ## Intel paragon #LIBES= -ltermcap -lbsd ## Clipper intergraph #LIBES= -ltermcap -lseq ## Sequent's Dynix #LIBES= -ltermcap -lauth ## Ultrix with Enhanced Security #LIBES= -ltermcap -ldir -lx ## Xenix 386 style things #LIBES= -ltermcap -lndir -lsocket -ljobs ## masscomp RTU6.0 #LIBES= -lcurses ## AIX on the rt #LIBES= -lcurses ## TitanOS on the stellar #LIBES= -ltermlib -lsocket -lnsl ## SysV4 w/o BSDTIMES or Solaris 2 #LIBES= -lcurses ## SysV3 w/o networking #LIBES= -lcurses -lnet ## SysV3 with networking #LIBES= -lcurses -ldir ## SysV2 w/o networking & dirlib #LIBES= -lcurses -ldir -lnet ## SysV2 with networking & dirlib #LIBES= -lcurses -lbsd ## AIX on the IBM 370 or rs6000 or ps2 #LIBES= -lcurses -lbsd ## ETA10 #LIBES= -lcurses -lbsd ## Irix3.1 on the SGI-IRIS4D #LIBES= -lcurses -lbsd -lc_s ## Irix3.3 on the SGI-IRIS4D w/o yp #LIBES= -lcurses -lsun -lbsd -lc_s ## Irix3.3 on the SGI-IRIS4D with yp #LIBES= -lcurses -lsocket -lbsd ## Amdahl UTS 2.1 #LIBES= -lcurses -lsocket ## Intel's hypercube. #LIBES= -lcurses -lsocket ## ns32000 based Opus. #LIBES= -lcurses -lcposix ## ISC 2.2 without networking #LIBES= -lcposix -lc_s -lcurses -linet ## ISC 2.2 with networking #LIBES= -lcurses -lsec -lc_s ## ISC 2.0.2 without networking #LIBES= -lcurses -linet -lsec -lc_s ## ISC 2.0.2 with networking #LIBES= -lcurses -lintl -lcrypt ## SCO SysVR3.2v2.0 #LIBES= -lcurses -lintl -lsocket -lcrypt ## SCO+ODT1.1 #LIBES= -lposix -ltermcap ## A/UX 2.0 #LIBES= -lposix -ltermcap -lc_s ## A/UX 3.0 #LIBES= -ldirent -lcurses ## att3b1 cc w/o shared lib & dirlib #LIBES= -shlib -ldirent -lcurses ## att3b1 gcc with shared lib & dirlib #LIBES= -ltermlib -lsocket -lnsl -lc /usr/ucblib/libucb.a ## SysV4 with BSDTIMES #LIBES= -lcurses -lnsl -lsocket -lc /usr/ucblib/libucb.a ## Stardent Vistra #LIBES= -ltermc ## emx under OS/2 LIBES= ## Minix, VMS_POSIX #LIBES= -ltermcap -lcrypt ## Multiflow #LIBES= -ltermcap -lcrypt ## NetBSD #LIBES= -lcurses ## DDE Supermax ################################################################ ## EXTRAFLAGS and EXTRALIBS ################################################################ # Compiling for HESIOD #HESDEF = -DHESIOD -I/usr/athena/include #HESLIB = -L/usr/athena/lib -lhesiod # # Compiling for AFS with kerberos authentication #AFSLIBDIR = /usr/afsws/lib #AFSDEF = -DAFS -I/usr/afsws/include #AFS33LIB = -laudit # #Solaris and HPUX require the BSD libraries with AFS. #We use -lc to use only what we require. #AFSAUXLIB = -lsocket -lnsl -lc -lucb # Solaris #AFSAUXLIB = -lc -lBSD # HPUX # #AFSLIB = -L$(AFSLIBDIR) -L$(AFSLIBDIR)/afs -lkauth -lprot -lubik\ # -lauth -lrxkad -lsys -ldes -lrx -llwp -lcom_err\ # $(AFSLIBDIR)/afs/util.a $(AFS33LIB) $(AFSAUXLIB) # EXTRAFLAGS = $(HESDEF) $(AFSDEF) EXTRALIBS = $(HESLIB) $(AFSLIB) # The difficult choice of a c-compiler... # First, you should try your own c-compiler. # Gcc -traditional is also a safe choice. # If you think that you have good include files try gcc -Wall... # If you want to take out -traditional, make sure that your sys/ioctl.h # is fixed correctly, otherwise you'll be stopped for tty input, or you # will lose the editor and job control. # The -B tells gcc to use /bin/ld. This is to avoid using the gnu ld, which # on the suns does not know how to make dynamically linked binaries. #CC= gcc -Wall -pipe -B/bin/ # -ansi -pedantic #CC= gcc -m486 -pipe -Wall # Generate code for Intel 486 (linux) #CC= cc #CC= occ #CC= acc #CC= pcc #CC= hc -w CC= c89 # For VMS/POSIX #CC= /bin/cc # For suns, w/o gcc and SVR4 #CC= /usr/lib/sun.compile/cc # FPS 500 (+FPX) with Sun C compiler #CC= /opt/SUNWspro/bin/cc # Solaris 2.1 #CC= scc # Alliant fx2800 #CC= lcc -wa ED= ed AS= as RM= rm CXREF= /usr/ucb/cxref VGRIND= csh /usr/ucb/vgrind CTAGS= /usr/ucb/ctags #XSTR= /usr/ucb/xstr SCCS= /usr/local/sccs PARALLEL=12 # Make the multi-max run fast. #P=& # Use Sequent's parallel make P= DESTDIR=/usr/local MANSECT=1 DESTBIN=${DESTDIR}/bin DESTMAN=${DESTDIR}/man/man${MANSECT} # DESTMAN=${DESTDIR}/catman/man${MANSECT} # A/UX # DESTMAN=${DESTDIR}/usr/share/man/man${MANSECT} # Stardent Vistra (SysVR4) # DESTMAN=/usr/catman/1l # Amiga unix (SysVR4) FTPAREA=/usr/spool/ftp ASSRCS= sh.c sh.dir.c sh.dol.c sh.err.c sh.exec.c sh.char.c \ sh.exp.c sh.file.c sh.func.c sh.glob.c sh.hist.c sh.init.c \ sh.lex.c sh.misc.c sh.parse.c sh.print.c sh.proc.c sh.sem.c \ sh.set.c sh.time.c sh.char.h sh.dir.h sh.proc.h sh.h PSSRCS= sh.decls.h glob.c glob.h mi.termios.c mi.wait.h mi.varargs.h ma.setp.c \ vms.termcap.c SHSRCS= ${ASSRCS} ${PSSRCS} SHOBJS= sh.${SUF} sh.dir.${SUF} sh.dol.${SUF} sh.err.${SUF} sh.exec.${SUF} \ sh.char.${SUF} sh.exp.${SUF} sh.func.${SUF} sh.glob.${SUF} \ sh.hist.${SUF} sh.init.${SUF} sh.lex.${SUF} sh.misc.${SUF} \ sh.parse.${SUF} sh.print.${SUF} sh.proc.${SUF} sh.sem.${SUF} \ sh.set.${SUF} sh.time.${SUF} glob.${SUF} mi.termios.${SUF} \ ma.setp.${SUF} vms.termcap.${SUF} TWSRCS= tw.decls.h tw.h tw.help.c tw.init.c tw.parse.c tw.spell.c \ tw.comp.c tw.color.c TWOBJS= tw.help.${SUF} tw.init.${SUF} tw.parse.${SUF} tw.spell.${SUF} \ tw.comp.${SUF} tw.color.${SUF} EDSRCS= ed.chared.c ed.decls.h ed.defns.c ed.h ed.init.c ed.inputl.c \ ed.refresh.c ed.screen.c ed.xmap.c ed.term.c ed.term.h EDOBJS= ed.chared.${SUF} ed.refresh.${SUF} ed.screen.${SUF} ed.init.${SUF} \ ed.inputl.${SUF} ed.defns.${SUF} ed.xmap.${SUF} ed.term.${SUF} TCSRCS= tc.alloc.c tc.bind.c tc.const.c tc.decls.h tc.disc.c \ tc.func.c tc.os.c tc.os.c tc.os.h tc.printf.c tc.prompt.c \ tc.sched.c tc.sig.c tc.sig.h tc.str.c sh.types.h tc.vers.c tc.wait.h \ tc.who.c tc.h TCOBJS= tc.alloc.${SUF} tc.bind.${SUF} tc.const.${SUF} tc.defs.${SUF} \ tc.disc.${SUF} tc.func.${SUF} tc.os.${SUF} tc.os.${SUF} tc.printf.${SUF} \ tc.prompt.${SUF} tc.sched.${SUF} tc.sig.${SUF} tc.str.${SUF} \ tc.vers.${SUF} tc.who.${SUF} PVSRCS= Makefile.std Makefile.vms Makefile.in Makefile.win32 AVSRCS= BUILDING Fixes MAKEDIFFS MAKESHAR NewThings README.md FAQ \ WishList config_f.h eight-bit.me glob.3 patchlevel.h \ pathnames.h tcsh.man Ported src.desc Imakefile imake.config \ complete.tcsh vmsreadme.txt termcap.vms snames.h host.defs \ - gethost.c tcsh.man2html configure.ac aclocal.m4 + gethost.c tcsh.man2html configure.ac aclocal.m4 dot.login dot.tcshrc VHSRCS=${PVSRCS} ${AVSRCS} CONFSRCS=config/* ALLSRCS= ${SHSRCS} ${TWSRCS} ${EDSRCS} ${TCSRCS} ${VHSRCS} DISTSRCS= ${PSSRCS} ${TWSRCS} ${EDSRCS} ${TCSRCS} ${AVSRCS} OBJS= ${SHOBJS} ${TWOBJS} ${EDOBJS} ${TCOBJS} all: ${BUILD} tcsh:$(P) ${OBJS} rm -f tcsh core ${CC} -o tcsh ${LDFLAGS} ${CFLAGS} ${OBJS} ${LIBES} ${EXTRALIBS} # Purify pure:$(P) ${OBJS} rm -f tcsh core purify `echo ${CC} | sed -e s,-B/bin/,,` -o tcsh ${LDFLAGS} ${CFLAGS} ${OBJS} ${LIBES} ${EXTRALIBS} # OS/2 tcsh.exe: tcsh emxbind tcsh gethost: gethost.c sh.err.h tc.const.h sh.h rm -f gethost ${CC} -o gethost ${LDFLAGS} ${CFLAGS} ${DFLAGS} gethost.c ${LIBES} ${EXTRALIBS} tc.defs.c: gethost host.defs @rm -f $@ @echo "/* Do not edit this file, make creates it */" > $@ ./gethost host.defs >> $@ tcsh.ps: tcsh.man rm -f tcsh.ps -ptroff -man tcsh.man > tcsh.ps #.c.${SUF}: # ${CC} ${CF} ${CFLAGS} ${DFLAGS} ${EXTRAFLAGS} $< # _VMS_POSIX #module addition .c.${SUF}: @(echo '\#module '`echo $< | sed -e 's/\./_/g'`; cat $<) > $*..c @echo ${CC} ${CF} ${CFLAGS} ${DFLAGS} ${EXTRAFLAGS} $*.c @${CC} ${CF} ${CFLAGS} ${DFLAGS} ${EXTRAFLAGS} $*..c @mv $*..o $*.o @rm -f $*..c # Don't do any special massaging of C files for sharing of strings!! # it causes weird segmentation faults on some systems. #.c.o: # ${CC} -E ${CFLAGS} $*.c | ${XSTR} -c - # ${CC} ${CF} ${CFLAGS} x.c # mv -f x.o $*.o # rm -f x.c #ed.init.o: ed.init.c # ${CC} -E ${CFLAGS} $*.c | ${XSTR} -c - # ${CC} -R ${CF} ${CF} x.c # mv -f x.o $*.o # rm -f x.c #strings.o: strings # ${XSTR} # ${CC} -c -R xs.c # mv -f xs.o strings.o # rm -f xs.c ##.DEFAULT: ## ${SCCS} get $< ##.DEFAULT: ## co $< ed.defns.h: ed.defns.c @rm -f $@ @echo '/* Do not edit this file, make creates it. */' > $@ @echo '\#ifndef _h_ed_defns' >> $@ @echo '\#define _h_ed_defns' >> $@ grep '[FV]_' ed.defns.c | grep '^\#define' >> $@ @echo '\#endif /* _h_ed_defns */' >> $@ sh.err.h: sh.err.c @rm -f $@ @echo '/* Do not edit this file, make creates it. */' > $@ @echo '\#ifndef _h_sh_err' >> $@ @echo '\#define _h_sh_err' >> $@ grep 'ERR_' sh.err.c | grep '^#define' >> $@ @echo '\#endif /* _h_sh_err */' >> $@ tc.const.h: tc.const.c sh.char.h config.h config_f.h sh.types.h sh.err.h @rm -f $@ @echo '/* Do not edit this file, make creates it. */' > $@ @echo '\#ifndef _h_tc_const' >> $@ @echo '\#define _h_tc_const' >> $@ ${CC} -E $(INCLUDES) ${DFLAGS} -D_h_tc_const tc.const.c | \ grep 'Char STR' | \ sed -e 's/Char \([a-zA-Z0-9_]*\) *\[ *\].*/extern Char \1[];/' | \ sort >> $@ @echo '\#endif /* _h_tc_const */' >> $@ csh.prof: ${OBJS} sh.prof.${SUF} mcrt0.${SUF} rm -f csh.prof ld -X mcrt0.${SUF} ${OBJS} -o csh.prof ${LIBES} -lc sh.prof.${SUF}: cp sh.c sh.prof.c ${CC} ${CF} ${CFLAGS} -DPROF sh.prof.c lint: tc.const.h ed.defns.h lint ${DFLAGS} ${LFLAGS} sh*.c tw*.c ed*.c tc.*.c ${LIBES} alint: tc.const.h ed.defns.h alint ${DFLAGS} ${LFLAGS} sh*.c tw*.c ed*.c tc.*.c ${LIBES} print: @pr READ_ME @pr makefile makefile.* @(size -l a.out; size *.${SUF}) | pr -h SIZES @${CXREF} sh*.c | pr -h XREF @ls -l | pr @pr sh*.h [a-rt-z]*.h sh*.c alloc.c vprint: @pr -l84 READ_ME TODO @pr -l84 makefile makefile.* @(size -l a.out; size *.${SUF}) | pr -l84 -h SIZES @${CXREF} sh*.c | pr -l84 -h XREF @ls -l | pr -l84 @${CXREF} sh*.c | pr -l84 -h XREF @pr -l84 sh*.h [a-rt-z]*.h sh*.c alloc.c vgrind: @cp /dev/null index @for i in *.h; do vgrind -t -h "C Shell" $$i >/crp/bill/csh/$$i.t; done @for i in *.c; do vgrind -t -h "C Shell" $$i >/crp/bill/csh/$$i.t; done @vgrind -t -x -h Index index >/crp/bill/csh/index.t install: tcsh -mv -f ${DESTBIN}/tcsh ${DESTBIN}/tcsh.old cp tcsh ${DESTBIN}/tcsh -strip ${DESTBIN}/tcsh chmod 555 ${DESTBIN}/tcsh install.man: tcsh.man -rm -f ${DESTMAN}/tcsh.${MANSECT} cp tcsh.man ${DESTMAN}/tcsh.${MANSECT} chmod 444 ${DESTMAN}/tcsh.${MANSECT} # Amiga Unix #install.man: tcsh.man # compress tcsh.man # cp tcsh.man.Z ${DESTMAN}/tcsh.Z # chmod 444 ${DESTMAN}/tcsh.Z # Apple A/UX #install.man: tcsh.man # -rm -f ${DESTMAN}/tcsh.${MANSECT}.Z # nroff -man tcsh.man | compress > ${DESTMAN}/tcsh.${MANSECT}.Z # chmod 444 ${DESTMAN}/tcsh.${MANSECT}.Z clean: ${RM} -f a.out strings x.c xs.c tcsh tcsh.a _MAKE_LOG core gethost ${RM} -f *.${SUF} sh.prof.c ed.defns.h tc.const.h sh.err.h tc.defs.c ${RM} -f tcsh.*.m tcsh.*.cat veryclean: clean ${RM} -f config.h ${RM} -f *~ #* tags: /tmp ${CTAGS} sh*.c tar.Z: rm -f tcsh-${VERSION}.tar.Z rm -rf tcsh-${VERSION} mkdir tcsh-${VERSION} tcsh-${VERSION}/config cp ${ALLSRCS} tcsh-${VERSION} cp ${CONFSRCS} tcsh-${VERSION}/config tar cf - nls/Makefile nls/?*/set?* | (cd tcsh-${VERSION}; tar xpf -) tar cvf - tcsh-${VERSION} | compress > tcsh-${VERSION}.tar.Z rm -rf tcsh-${VERSION} tar.gz: rm -f tcsh-${VERSION}.tar.gz rm -rf tcsh-${VERSION} mkdir tcsh-${VERSION} tcsh-${VERSION}/config cp ${ALLSRCS} tcsh-${VERSION} cp ${CONFSRCS} tcsh-${VERSION}/config tar cf - nls/Makefile nls/?*/set?* | (cd tcsh-${VERSION}; tar xpf -) tar cvf - tcsh-${VERSION} | gzip > tcsh-${VERSION}.tar.gz rm -rf tcsh-${VERSION} shar: rm -f tcsh-*.shar rm -rf tcsh-${VERSION} mkdir tcsh-${VERSION} tcsh-${VERSION}/config cp ${ALLSRCS} tcsh-${VERSION} cp ${CONFSRCS} tcsh-${VERSION}/config tar cf - nls/Makefile nls/?*/set?* | (cd tcsh-${VERSION}; tar xpf -) MAKESHAR -v -n tcsh-${VERSION} tcsh-${VERSION} \ tcsh-${VERSION}/?* tcsh-${VERSION}/config/?* \ tcsh-${VERSION}/?*/set?* rm -rf tcsh-${VERSION} catalogs: @(cd nls; make catalogs) tcsh-${VERSION}.tar.Z: rm -rf tcsh-${VERSION} rm -f tcsh-${VERSION}.tar tcsh-${VERSION}.tar.Z DIFFS.[123] mkdir tcsh-${VERSION} ./MAKEDIFFS bsd mv DIFFS.1 DIFFS.2 DIFFS.3 tcsh-${VERSION} cp ${DISTSRCS} tcsh-${VERSION} mkdir tcsh-${VERSION}/config cp ${CONFSRCS} tcsh-${VERSION}/config cp Makefile tcsh-${VERSION}/Makefile.new tar cf - nls/Makefile nls/?*/set?* | (cd tcsh-${VERSION}; tar xpf -) tar cvf - tcsh-${VERSION} | compress > tcsh-${VERSION}.tar.Z rm -rf tcsh-${VERSION} tcsh.tahoe-${VERSION}.tar.Z: rm -rf tcsh.tahoe-${VERSION} rm -f tcsh.tahoe-${VERSION}.tar tcsh.tahoe-${VERSION}.tar.Z DIFFS.[123] mkdir tcsh.tahoe-${VERSION} ./MAKEDIFFS tahoe mv DIFFS.1 DIFFS.2 DIFFS.3 tcsh.tahoe-${VERSION} cp ${DISTSRCS} tcsh.tahoe-${VERSION} mkdir tcsh.tahoe-${VERSION}/config cp ${CONFSRCS} tcsh.tahoe-${VERSION}/config cp Makefile tcsh.tahoe-${VERSION}/Makefile.new tar cf - nls/Makefile nls/?*/set?* | (cd tcsh-${VERSION}; tar xpf -) tar cvf - tcsh.tahoe-${VERSION} | compress > tcsh.tahoe-${VERSION}.tar.Z rm -rf tcsh.tahoe-${VERSION} tcsh.reno-${VERSION}.tar.Z: rm -rf tcsh.reno-${VERSION} rm -f tcsh.reno-${VERSION}.tar tcsh.reno-${VERSION}.tar.Z DIFFS.[123] mkdir tcsh.reno-${VERSION} ./MAKEDIFFS reno mv DIFFS.1 DIFFS.2 DIFFS.3 tcsh.reno-${VERSION} cp ${DISTSRCS} tcsh.reno-${VERSION} mkdir tcsh.reno-${VERSION}/config cp ${CONFSRCS} tcsh.reno-${VERSION}/config cp Makefile tcsh.reno-${VERSION}/Makefile.new tar cf - nls/Makefile nls/?*/set?* | (cd tcsh-${VERSION}; tar xpf -) tar cvf - tcsh.reno-${VERSION} | compress > tcsh.reno-${VERSION}.tar.Z rm -rf tcsh.reno-${VERSION} ftp: tcsh-${VERSION}.tar.Z tcsh.tahoe-${VERSION}.tar.Z cp tcsh-${VERSION}.tar.Z tcsh.tahoe-${VERSION}.tar.Z ${FTPAREA} cp tcsh.man ${FTPAREA} # # Dependencies # config.h: config_f.h TCH=tc.h tc.const.h tc.decls.h tc.nls.h tc.os.h tc.sig.h SHH=sh.h sh.types.h sh.char.h sh.err.h sh.dir.h sh.proc.h pathnames.h \ sh.decls.h ${TCH} TWH=tw.h tw.decls.h EDH=ed.h ed.decls.h # EDH EDINC=sh.${SUF} sh.func.${SUF} sh.lex.${SUF} sh.print.${SUF} sh.proc.${SUF} \ sh.set.${SUF} tc.bind.${SUF} tc.os.${SUF} tc.prompt.${SUF} \ tc.sched.${SUF} tw.parse.${SUF} ${EDOBJS} ${EDINC} : ${EDH} # SHH ${OBJS}: config.h ${SHH} # TWH TWINC=ed.chared.${SUF} ed.inputl.${SUF} sh.exec.${SUF} sh.func.${SUF} \ sh.set.${SUF} tc.func.${SUF} tc.nls.${SUF} ${TWOBJS} ${TWINC}: ${TWH} # glob.h glob.${SUF} sh.glob.${SUF}: glob.h # ed.defns.h EDDINC=tc.bind.${SUF} tc.func.${SUF} tc.os.${SUF} ${EDOBJS} ${EDDINC}: ed.defns.h # tc.defs.o tc.defs.${SUF}: tc.defs.c sh.h diff --git a/contrib/tcsh/README.md b/contrib/tcsh/README.md index 58a30738daa6..df6671b0316e 100644 --- a/contrib/tcsh/README.md +++ b/contrib/tcsh/README.md @@ -1,26 +1,29 @@ # TCSH *C shell with file name completion and command line editing* The Tcsh source code is available on GitHub as a read-only repo mirror at: -> http://github.com/tcsh-org/tcsh +> https://github.com/tcsh-org/tcsh Instructions for compiling Tcsh can be found in [BUILDING]. PLEASE file any bug reports, fixes, and code for new features at: > https://bugs.astron.com/ Comments, questions, etc. (even flames) are welcome via email to the tcsh mailing list: > tcsh@astron.com > https://mailman.astron.com/mailman/listinfo/tcsh [![Build Status][status]][travis] +[![Coverity Scan][badge]][coverity] [BUILDING]: BUILDING -[status]: https://travis-ci.org/tcsh-org/tcsh.svg?branch=master -[travis]: https://travis-ci.org/tcsh-org/tcsh +[badge]: https://scan.coverity.com/projects/20307/badge.svg +[coverity]: https://scan.coverity.com/projects/tcsh-org-tcsh +[status]: https://travis-ci.com/tcsh-org/tcsh.svg?branch=master +[travis]: https://travis-ci.com/tcsh-org/tcsh diff --git a/contrib/tcsh/configure b/contrib/tcsh/configure index 4e724c2bfb80..27a6bec356a0 100755 --- a/contrib/tcsh/configure +++ b/contrib/tcsh/configure @@ -1,8165 +1,8842 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69 for tcsh 6.21.00. +# Generated by GNU Autoconf 2.69 for tcsh 6.22.03. # # Report bugs to . # # # Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc. # # # This configure script is free software; the Free Software Foundation # gives unlimited permission to copy, distribute and modify it. ## -------------------- ## ## M4sh Initialization. ## ## -------------------- ## # Be more Bourne compatible DUALCASE=1; export DUALCASE # for MKS sh if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then : emulate sh NULLCMD=: # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which # is contrary to our usage. Disable this feature. alias -g '${1+"$@"}'='"$@"' setopt NO_GLOB_SUBST else case `(set -o) 2>/dev/null` in #( *posix*) : set -o posix ;; #( *) : ;; esac fi as_nl=' ' export as_nl # Printing a long string crashes Solaris 7 /usr/bin/printf. as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo # Prefer a ksh shell builtin over an external printf program on Solaris, # but without wasting forks for bash or zsh. if test -z "$BASH_VERSION$ZSH_VERSION" \ && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then as_echo='print -r --' as_echo_n='print -rn --' elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then as_echo='printf %s\n' as_echo_n='printf %s' else if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"' as_echo_n='/usr/ucb/echo -n' else as_echo_body='eval expr "X$1" : "X\\(.*\\)"' as_echo_n_body='eval arg=$1; case $arg in #( *"$as_nl"*) expr "X$arg" : "X\\(.*\\)$as_nl"; arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;; esac; expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl" ' export as_echo_n_body as_echo_n='sh -c $as_echo_n_body as_echo' fi export as_echo_body as_echo='sh -c $as_echo_body as_echo' fi # The user is always right. if test "${PATH_SEPARATOR+set}" != set; then PATH_SEPARATOR=: (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && { (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 || PATH_SEPARATOR=';' } fi # IFS # We need space, tab and new line, in precisely that order. Quoting is # there to prevent editors from complaining about space-tab. # (If _AS_PATH_WALK were called with IFS unset, it would disable word # splitting by setting IFS to empty value.) IFS=" "" $as_nl" # Find who we are. Look in the path if we contain no directory separator. as_myself= case $0 in #(( *[\\/]* ) as_myself=$0 ;; *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break done IFS=$as_save_IFS ;; esac # We did not find ourselves, most probably we were run as `sh COMMAND' # in which case we are not to be found in the path. if test "x$as_myself" = x; then as_myself=$0 fi if test ! -f "$as_myself"; then $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 exit 1 fi # Unset variables that we do not need and which cause bugs (e.g. in # pre-3.0 UWIN ksh). But do not cause bugs in bash 2.01; the "|| exit 1" # suppresses any "Segmentation fault" message there. '((' could # trigger a bug in pdksh 5.2.14. for as_var in BASH_ENV ENV MAIL MAILPATH do eval test x\${$as_var+set} = xset \ && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : done PS1='$ ' PS2='> ' PS4='+ ' # NLS nuisances. LC_ALL=C export LC_ALL LANGUAGE=C export LANGUAGE # CDPATH. (unset CDPATH) >/dev/null 2>&1 && unset CDPATH # Use a proper internal environment variable to ensure we don't fall # into an infinite loop, continuously re-executing ourselves. if test x"${_as_can_reexec}" != xno && test "x$CONFIG_SHELL" != x; then _as_can_reexec=no; export _as_can_reexec; # We cannot yet assume a decent shell, so we have to provide a # neutralization value for shells without unset; and this also # works around shells that cannot unset nonexistent variables. # Preserve -v and -x to the replacement shell. BASH_ENV=/dev/null ENV=/dev/null (unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV case $- in # (((( *v*x* | *x*v* ) as_opts=-vx ;; *v* ) as_opts=-v ;; *x* ) as_opts=-x ;; * ) as_opts= ;; esac exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} # Admittedly, this is quite paranoid, since all the known shells bail # out after a failed `exec'. $as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2 as_fn_exit 255 fi # We don't want this to propagate to other subprocesses. { _as_can_reexec=; unset _as_can_reexec;} if test "x$CONFIG_SHELL" = x; then as_bourne_compatible="if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then : emulate sh NULLCMD=: # Pre-4.2 versions of Zsh do word splitting on \${1+\"\$@\"}, which # is contrary to our usage. Disable this feature. alias -g '\${1+\"\$@\"}'='\"\$@\"' setopt NO_GLOB_SUBST else case \`(set -o) 2>/dev/null\` in #( *posix*) : set -o posix ;; #( *) : ;; esac fi " as_required="as_fn_return () { (exit \$1); } as_fn_success () { as_fn_return 0; } as_fn_failure () { as_fn_return 1; } as_fn_ret_success () { return 0; } as_fn_ret_failure () { return 1; } exitcode=0 as_fn_success || { exitcode=1; echo as_fn_success failed.; } as_fn_failure && { exitcode=1; echo as_fn_failure succeeded.; } as_fn_ret_success || { exitcode=1; echo as_fn_ret_success failed.; } as_fn_ret_failure && { exitcode=1; echo as_fn_ret_failure succeeded.; } if ( set x; as_fn_ret_success y && test x = \"\$1\" ); then : else exitcode=1; echo positional parameters were not saved. fi test x\$exitcode = x0 || exit 1 test -x / || exit 1" as_suggested=" as_lineno_1=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_1a=\$LINENO as_lineno_2=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_2a=\$LINENO eval 'test \"x\$as_lineno_1'\$as_run'\" != \"x\$as_lineno_2'\$as_run'\" && test \"x\`expr \$as_lineno_1'\$as_run' + 1\`\" = \"x\$as_lineno_2'\$as_run'\"' || exit 1 test \$(( 1 + 1 )) = 2 || exit 1" if (eval "$as_required") 2>/dev/null; then : as_have_required=yes else as_have_required=no fi if test x$as_have_required = xyes && (eval "$as_suggested") 2>/dev/null; then : else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR as_found=false for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. as_found=: case $as_dir in #( /*) for as_base in sh bash ksh sh5; do # Try only shells that exist, to save several forks. as_shell=$as_dir/$as_base if { test -f "$as_shell" || test -f "$as_shell.exe"; } && { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$as_shell"; } 2>/dev/null; then : CONFIG_SHELL=$as_shell as_have_required=yes if { $as_echo "$as_bourne_compatible""$as_suggested" | as_run=a "$as_shell"; } 2>/dev/null; then : break 2 fi fi done;; esac as_found=false done $as_found || { if { test -f "$SHELL" || test -f "$SHELL.exe"; } && { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$SHELL"; } 2>/dev/null; then : CONFIG_SHELL=$SHELL as_have_required=yes fi; } IFS=$as_save_IFS if test "x$CONFIG_SHELL" != x; then : export CONFIG_SHELL # We cannot yet assume a decent shell, so we have to provide a # neutralization value for shells without unset; and this also # works around shells that cannot unset nonexistent variables. # Preserve -v and -x to the replacement shell. BASH_ENV=/dev/null ENV=/dev/null (unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV case $- in # (((( *v*x* | *x*v* ) as_opts=-vx ;; *v* ) as_opts=-v ;; *x* ) as_opts=-x ;; * ) as_opts= ;; esac exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} # Admittedly, this is quite paranoid, since all the known shells bail # out after a failed `exec'. $as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2 exit 255 fi if test x$as_have_required = xno; then : $as_echo "$0: This script requires a shell more modern than all" $as_echo "$0: the shells that I found on your system." if test x${ZSH_VERSION+set} = xset ; then $as_echo "$0: In particular, zsh $ZSH_VERSION has bugs and should" $as_echo "$0: be upgraded to zsh 4.3.4 or later." else $as_echo "$0: Please tell bug-autoconf@gnu.org and $0: https://bugs.astron.com/ about your system, including $0: any error possibly output before this message. Then $0: install a modern shell, or manually run the script $0: under such a shell if you do have one." fi exit 1 fi fi fi SHELL=${CONFIG_SHELL-/bin/sh} export SHELL # Unset more variables known to interfere with behavior of common tools. CLICOLOR_FORCE= GREP_OPTIONS= unset CLICOLOR_FORCE GREP_OPTIONS ## --------------------- ## ## M4sh Shell Functions. ## ## --------------------- ## # as_fn_unset VAR # --------------- # Portably unset VAR. as_fn_unset () { { eval $1=; unset $1;} } as_unset=as_fn_unset # as_fn_set_status STATUS # ----------------------- # Set $? to STATUS, without forking. as_fn_set_status () { return $1 } # as_fn_set_status # as_fn_exit STATUS # ----------------- # Exit the shell with STATUS, even in a "trap 0" or "set -e" context. as_fn_exit () { set +e as_fn_set_status $1 exit $1 } # as_fn_exit # as_fn_mkdir_p # ------------- # Create "$as_dir" as a directory, including parents if necessary. as_fn_mkdir_p () { case $as_dir in #( -*) as_dir=./$as_dir;; esac test -d "$as_dir" || eval $as_mkdir_p || { as_dirs= while :; do case $as_dir in #( *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( *) as_qdir=$as_dir;; esac as_dirs="'$as_qdir' $as_dirs" as_dir=`$as_dirname -- "$as_dir" || $as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$as_dir" : 'X\(//\)[^/]' \| \ X"$as_dir" : 'X\(//\)$' \| \ X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || $as_echo X"$as_dir" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q'` test -d "$as_dir" && break done test -z "$as_dirs" || eval "mkdir $as_dirs" } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir" } # as_fn_mkdir_p # as_fn_executable_p FILE # ----------------------- # Test if FILE is an executable regular file. as_fn_executable_p () { test -f "$1" && test -x "$1" } # as_fn_executable_p # as_fn_append VAR VALUE # ---------------------- # Append the text in VALUE to the end of the definition contained in VAR. Take # advantage of any shell optimizations that allow amortized linear growth over # repeated appends, instead of the typical quadratic growth present in naive # implementations. if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then : eval 'as_fn_append () { eval $1+=\$2 }' else as_fn_append () { eval $1=\$$1\$2 } fi # as_fn_append # as_fn_arith ARG... # ------------------ # Perform arithmetic evaluation on the ARGs, and store the result in the # global $as_val. Take advantage of shells that can avoid forks. The arguments # must be portable across $(()) and expr. if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then : eval 'as_fn_arith () { as_val=$(( $* )) }' else as_fn_arith () { as_val=`expr "$@" || test $? -eq 1` } fi # as_fn_arith # as_fn_error STATUS ERROR [LINENO LOG_FD] # ---------------------------------------- # Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are # provided, also output the error to LOG_FD, referencing LINENO. Then exit the # script with STATUS, using 1 if that was 0. as_fn_error () { as_status=$1; test $as_status -eq 0 && as_status=1 if test "$4"; then as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4 fi $as_echo "$as_me: error: $2" >&2 as_fn_exit $as_status } # as_fn_error if expr a : '\(a\)' >/dev/null 2>&1 && test "X`expr 00001 : '.*\(...\)'`" = X001; then as_expr=expr else as_expr=false fi if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then as_basename=basename else as_basename=false fi if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then as_dirname=dirname else as_dirname=false fi as_me=`$as_basename -- "$0" || $as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ X"$0" : 'X\(//\)$' \| \ X"$0" : 'X\(/\)' \| . 2>/dev/null || $as_echo X/"$0" | sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/ q } /^X\/\(\/\/\)$/{ s//\1/ q } /^X\/\(\/\).*/{ s//\1/ q } s/.*/./; q'` # Avoid depending upon Character Ranges. as_cr_letters='abcdefghijklmnopqrstuvwxyz' as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' as_cr_Letters=$as_cr_letters$as_cr_LETTERS as_cr_digits='0123456789' as_cr_alnum=$as_cr_Letters$as_cr_digits as_lineno_1=$LINENO as_lineno_1a=$LINENO as_lineno_2=$LINENO as_lineno_2a=$LINENO eval 'test "x$as_lineno_1'$as_run'" != "x$as_lineno_2'$as_run'" && test "x`expr $as_lineno_1'$as_run' + 1`" = "x$as_lineno_2'$as_run'"' || { # Blame Lee E. McMahon (1931-1989) for sed's syntax. :-) sed -n ' p /[$]LINENO/= ' <$as_myself | sed ' s/[$]LINENO.*/&-/ t lineno b :lineno N :loop s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/ t loop s/-\n.*// ' >$as_me.lineno && chmod +x "$as_me.lineno" || { $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; } # If we had to re-execute with $CONFIG_SHELL, we're ensured to have # already done that, so ensure we don't try to do so again and fall # in an infinite loop. This has already happened in practice. _as_can_reexec=no; export _as_can_reexec # Don't try to exec as it changes $[0], causing all sort of problems # (the dirname of $[0] is not the place where we might find the # original and so on. Autoconf is especially sensitive to this). . "./$as_me.lineno" # Exit status is that of the last command. exit } ECHO_C= ECHO_N= ECHO_T= case `echo -n x` in #((((( -n*) case `echo 'xy\c'` in *c*) ECHO_T=' ';; # ECHO_T is single tab character. xy) ECHO_C='\c';; *) echo `echo ksh88 bug on AIX 6.1` > /dev/null ECHO_T=' ';; esac;; *) ECHO_N='-n';; esac rm -f conf$$ conf$$.exe conf$$.file if test -d conf$$.dir; then rm -f conf$$.dir/conf$$.file else rm -f conf$$.dir mkdir conf$$.dir 2>/dev/null fi if (echo >conf$$.file) 2>/dev/null; then if ln -s conf$$.file conf$$ 2>/dev/null; then as_ln_s='ln -s' # ... but there are two gotchas: # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. # In both cases, we have to default to `cp -pR'. ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || as_ln_s='cp -pR' elif ln conf$$.file conf$$ 2>/dev/null; then as_ln_s=ln else as_ln_s='cp -pR' fi else as_ln_s='cp -pR' fi rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file rmdir conf$$.dir 2>/dev/null if mkdir -p . 2>/dev/null; then as_mkdir_p='mkdir -p "$as_dir"' else test -d ./-p && rmdir ./-p as_mkdir_p=false fi as_test_x='test -x' as_executable_p=as_fn_executable_p # Sed expression to map a string onto a valid CPP name. as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" # Sed expression to map a string onto a valid variable name. as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" test -n "$DJDIR" || exec 7<&0 &1 # Name of the host. # hostname on some systems (SVR3.2, old GNU/Linux) returns a bogus exit status, # so uname gets run too. ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q` # # Initializations. # ac_default_prefix=/usr/local ac_clean_files= ac_config_libobj_dir=. LIBOBJS= cross_compiling=no subdirs= MFLAGS= MAKEFLAGS= # Identity of this package. PACKAGE_NAME='tcsh' PACKAGE_TARNAME='tcsh' -PACKAGE_VERSION='6.21.00' -PACKAGE_STRING='tcsh 6.21.00' +PACKAGE_VERSION='6.22.03' +PACKAGE_STRING='tcsh 6.22.03' PACKAGE_BUGREPORT='https://bugs.astron.com/' PACKAGE_URL='' ac_unique_file="tc.vers.c" # Factoring default headers for most tests. ac_includes_default="\ #include #ifdef HAVE_SYS_TYPES_H # include #endif #ifdef HAVE_SYS_STAT_H # include #endif #ifdef STDC_HEADERS # include # include #else # ifdef HAVE_STDLIB_H # include # endif #endif #ifdef HAVE_STRING_H # if !defined STDC_HEADERS && defined HAVE_MEMORY_H # include # endif # include #endif #ifdef HAVE_STRINGS_H # include #endif #ifdef HAVE_INTTYPES_H # include #endif #ifdef HAVE_STDINT_H # include #endif #ifdef HAVE_UNISTD_H # include #endif" ac_subst_vars='LTLIBOBJS LIBOBJS BUILD_CATALOGS HESLIB HESDEF DFLAGS -LTLIBICONV -LIBICONV CC_FOR_GETHOST GENCAT +LTLIBICONV +LIBICONV EGREP GREP CPP OBJEXT EXEEXT ac_ct_CC CPPFLAGS LDFLAGS CFLAGS CC host_os host_vendor host_cpu host build_os build_vendor build_cpu build INSTALL_DATA INSTALL_SCRIPT INSTALL_PROGRAM target_alias host_alias build_alias LIBS ECHO_T ECHO_N ECHO_C DEFS mandir localedir libdir psdir pdfdir dvidir htmldir infodir docdir oldincludedir includedir localstatedir sharedstatedir sysconfdir datadir datarootdir libexecdir sbindir bindir program_transform_name prefix exec_prefix PACKAGE_URL PACKAGE_BUGREPORT PACKAGE_STRING PACKAGE_VERSION PACKAGE_TARNAME PACKAGE_NAME PATH_SEPARATOR SHELL' ac_subst_files='' ac_user_opts=' enable_option_checking with_gnu_ld enable_rpath with_libiconv_prefix enable_nls enable_nls_catalogs with_hesiod ' ac_precious_vars='build_alias host_alias target_alias CC CFLAGS LDFLAGS LIBS CPPFLAGS CPP' # Initialize some variables set by options. ac_init_help= ac_init_version=false ac_unrecognized_opts= ac_unrecognized_sep= # The variables have the same names as the options, with # dashes changed to underlines. cache_file=/dev/null exec_prefix=NONE no_create= no_recursion= prefix=NONE program_prefix=NONE program_suffix=NONE program_transform_name=s,x,x, silent= site= srcdir= verbose= x_includes=NONE x_libraries=NONE # Installation directory options. # These are left unexpanded so users can "make install exec_prefix=/foo" # and all the variables that are supposed to be based on exec_prefix # by default will actually change. # Use braces instead of parens because sh, perl, etc. also accept them. # (The list follows the same order as the GNU Coding Standards.) bindir='${exec_prefix}/bin' sbindir='${exec_prefix}/sbin' libexecdir='${exec_prefix}/libexec' datarootdir='${prefix}/share' datadir='${datarootdir}' sysconfdir='${prefix}/etc' sharedstatedir='${prefix}/com' localstatedir='${prefix}/var' includedir='${prefix}/include' oldincludedir='/usr/include' docdir='${datarootdir}/doc/${PACKAGE_TARNAME}' infodir='${datarootdir}/info' htmldir='${docdir}' dvidir='${docdir}' pdfdir='${docdir}' psdir='${docdir}' libdir='${exec_prefix}/lib' localedir='${datarootdir}/locale' mandir='${datarootdir}/man' ac_prev= ac_dashdash= for ac_option do # If the previous option needs an argument, assign it. if test -n "$ac_prev"; then eval $ac_prev=\$ac_option ac_prev= continue fi case $ac_option in *=?*) ac_optarg=`expr "X$ac_option" : '[^=]*=\(.*\)'` ;; *=) ac_optarg= ;; *) ac_optarg=yes ;; esac # Accept the important Cygnus configure options, so we can diagnose typos. case $ac_dashdash$ac_option in --) ac_dashdash=yes ;; -bindir | --bindir | --bindi | --bind | --bin | --bi) ac_prev=bindir ;; -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*) bindir=$ac_optarg ;; -build | --build | --buil | --bui | --bu) ac_prev=build_alias ;; -build=* | --build=* | --buil=* | --bui=* | --bu=*) build_alias=$ac_optarg ;; -cache-file | --cache-file | --cache-fil | --cache-fi \ | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c) ac_prev=cache_file ;; -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \ | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*) cache_file=$ac_optarg ;; --config-cache | -C) cache_file=config.cache ;; -datadir | --datadir | --datadi | --datad) ac_prev=datadir ;; -datadir=* | --datadir=* | --datadi=* | --datad=*) datadir=$ac_optarg ;; -datarootdir | --datarootdir | --datarootdi | --datarootd | --dataroot \ | --dataroo | --dataro | --datar) ac_prev=datarootdir ;; -datarootdir=* | --datarootdir=* | --datarootdi=* | --datarootd=* \ | --dataroot=* | --dataroo=* | --dataro=* | --datar=*) datarootdir=$ac_optarg ;; -disable-* | --disable-*) ac_useropt=`expr "x$ac_option" : 'x-*disable-\(.*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid feature name: $ac_useropt" ac_useropt_orig=$ac_useropt ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "enable_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--disable-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval enable_$ac_useropt=no ;; -docdir | --docdir | --docdi | --doc | --do) ac_prev=docdir ;; -docdir=* | --docdir=* | --docdi=* | --doc=* | --do=*) docdir=$ac_optarg ;; -dvidir | --dvidir | --dvidi | --dvid | --dvi | --dv) ac_prev=dvidir ;; -dvidir=* | --dvidir=* | --dvidi=* | --dvid=* | --dvi=* | --dv=*) dvidir=$ac_optarg ;; -enable-* | --enable-*) ac_useropt=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid feature name: $ac_useropt" ac_useropt_orig=$ac_useropt ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "enable_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--enable-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval enable_$ac_useropt=\$ac_optarg ;; -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \ | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \ | --exec | --exe | --ex) ac_prev=exec_prefix ;; -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \ | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \ | --exec=* | --exe=* | --ex=*) exec_prefix=$ac_optarg ;; -gas | --gas | --ga | --g) # Obsolete; use --with-gas. with_gas=yes ;; -help | --help | --hel | --he | -h) ac_init_help=long ;; -help=r* | --help=r* | --hel=r* | --he=r* | -hr*) ac_init_help=recursive ;; -help=s* | --help=s* | --hel=s* | --he=s* | -hs*) ac_init_help=short ;; -host | --host | --hos | --ho) ac_prev=host_alias ;; -host=* | --host=* | --hos=* | --ho=*) host_alias=$ac_optarg ;; -htmldir | --htmldir | --htmldi | --htmld | --html | --htm | --ht) ac_prev=htmldir ;; -htmldir=* | --htmldir=* | --htmldi=* | --htmld=* | --html=* | --htm=* \ | --ht=*) htmldir=$ac_optarg ;; -includedir | --includedir | --includedi | --included | --include \ | --includ | --inclu | --incl | --inc) ac_prev=includedir ;; -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \ | --includ=* | --inclu=* | --incl=* | --inc=*) includedir=$ac_optarg ;; -infodir | --infodir | --infodi | --infod | --info | --inf) ac_prev=infodir ;; -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*) infodir=$ac_optarg ;; -libdir | --libdir | --libdi | --libd) ac_prev=libdir ;; -libdir=* | --libdir=* | --libdi=* | --libd=*) libdir=$ac_optarg ;; -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \ | --libexe | --libex | --libe) ac_prev=libexecdir ;; -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \ | --libexe=* | --libex=* | --libe=*) libexecdir=$ac_optarg ;; -localedir | --localedir | --localedi | --localed | --locale) ac_prev=localedir ;; -localedir=* | --localedir=* | --localedi=* | --localed=* | --locale=*) localedir=$ac_optarg ;; -localstatedir | --localstatedir | --localstatedi | --localstated \ | --localstate | --localstat | --localsta | --localst | --locals) ac_prev=localstatedir ;; -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \ | --localstate=* | --localstat=* | --localsta=* | --localst=* | --locals=*) localstatedir=$ac_optarg ;; -mandir | --mandir | --mandi | --mand | --man | --ma | --m) ac_prev=mandir ;; -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*) mandir=$ac_optarg ;; -nfp | --nfp | --nf) # Obsolete; use --without-fp. with_fp=no ;; -no-create | --no-create | --no-creat | --no-crea | --no-cre \ | --no-cr | --no-c | -n) no_create=yes ;; -no-recursion | --no-recursion | --no-recursio | --no-recursi \ | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r) no_recursion=yes ;; -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \ | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \ | --oldin | --oldi | --old | --ol | --o) ac_prev=oldincludedir ;; -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \ | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \ | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*) oldincludedir=$ac_optarg ;; -prefix | --prefix | --prefi | --pref | --pre | --pr | --p) ac_prev=prefix ;; -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*) prefix=$ac_optarg ;; -program-prefix | --program-prefix | --program-prefi | --program-pref \ | --program-pre | --program-pr | --program-p) ac_prev=program_prefix ;; -program-prefix=* | --program-prefix=* | --program-prefi=* \ | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*) program_prefix=$ac_optarg ;; -program-suffix | --program-suffix | --program-suffi | --program-suff \ | --program-suf | --program-su | --program-s) ac_prev=program_suffix ;; -program-suffix=* | --program-suffix=* | --program-suffi=* \ | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*) program_suffix=$ac_optarg ;; -program-transform-name | --program-transform-name \ | --program-transform-nam | --program-transform-na \ | --program-transform-n | --program-transform- \ | --program-transform | --program-transfor \ | --program-transfo | --program-transf \ | --program-trans | --program-tran \ | --progr-tra | --program-tr | --program-t) ac_prev=program_transform_name ;; -program-transform-name=* | --program-transform-name=* \ | --program-transform-nam=* | --program-transform-na=* \ | --program-transform-n=* | --program-transform-=* \ | --program-transform=* | --program-transfor=* \ | --program-transfo=* | --program-transf=* \ | --program-trans=* | --program-tran=* \ | --progr-tra=* | --program-tr=* | --program-t=*) program_transform_name=$ac_optarg ;; -pdfdir | --pdfdir | --pdfdi | --pdfd | --pdf | --pd) ac_prev=pdfdir ;; -pdfdir=* | --pdfdir=* | --pdfdi=* | --pdfd=* | --pdf=* | --pd=*) pdfdir=$ac_optarg ;; -psdir | --psdir | --psdi | --psd | --ps) ac_prev=psdir ;; -psdir=* | --psdir=* | --psdi=* | --psd=* | --ps=*) psdir=$ac_optarg ;; -q | -quiet | --quiet | --quie | --qui | --qu | --q \ | -silent | --silent | --silen | --sile | --sil) silent=yes ;; -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) ac_prev=sbindir ;; -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ | --sbi=* | --sb=*) sbindir=$ac_optarg ;; -sharedstatedir | --sharedstatedir | --sharedstatedi \ | --sharedstated | --sharedstate | --sharedstat | --sharedsta \ | --sharedst | --shareds | --shared | --share | --shar \ | --sha | --sh) ac_prev=sharedstatedir ;; -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \ | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \ | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \ | --sha=* | --sh=*) sharedstatedir=$ac_optarg ;; -site | --site | --sit) ac_prev=site ;; -site=* | --site=* | --sit=*) site=$ac_optarg ;; -srcdir | --srcdir | --srcdi | --srcd | --src | --sr) ac_prev=srcdir ;; -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*) srcdir=$ac_optarg ;; -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \ | --syscon | --sysco | --sysc | --sys | --sy) ac_prev=sysconfdir ;; -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \ | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*) sysconfdir=$ac_optarg ;; -target | --target | --targe | --targ | --tar | --ta | --t) ac_prev=target_alias ;; -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*) target_alias=$ac_optarg ;; -v | -verbose | --verbose | --verbos | --verbo | --verb) verbose=yes ;; -version | --version | --versio | --versi | --vers | -V) ac_init_version=: ;; -with-* | --with-*) ac_useropt=`expr "x$ac_option" : 'x-*with-\([^=]*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid package name: $ac_useropt" ac_useropt_orig=$ac_useropt ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "with_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--with-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval with_$ac_useropt=\$ac_optarg ;; -without-* | --without-*) ac_useropt=`expr "x$ac_option" : 'x-*without-\(.*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid package name: $ac_useropt" ac_useropt_orig=$ac_useropt ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "with_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--without-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval with_$ac_useropt=no ;; --x) # Obsolete; use --with-x. with_x=yes ;; -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \ | --x-incl | --x-inc | --x-in | --x-i) ac_prev=x_includes ;; -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \ | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*) x_includes=$ac_optarg ;; -x-libraries | --x-libraries | --x-librarie | --x-librari \ | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l) ac_prev=x_libraries ;; -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \ | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*) x_libraries=$ac_optarg ;; -*) as_fn_error $? "unrecognized option: \`$ac_option' Try \`$0 --help' for more information" ;; *=*) ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='` # Reject names that are not valid shell variable names. case $ac_envvar in #( '' | [0-9]* | *[!_$as_cr_alnum]* ) as_fn_error $? "invalid variable name: \`$ac_envvar'" ;; esac eval $ac_envvar=\$ac_optarg export $ac_envvar ;; *) # FIXME: should be removed in autoconf 3.0. $as_echo "$as_me: WARNING: you should use --build, --host, --target" >&2 expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null && $as_echo "$as_me: WARNING: invalid host type: $ac_option" >&2 : "${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}" ;; esac done if test -n "$ac_prev"; then ac_option=--`echo $ac_prev | sed 's/_/-/g'` as_fn_error $? "missing argument to $ac_option" fi if test -n "$ac_unrecognized_opts"; then case $enable_option_checking in no) ;; fatal) as_fn_error $? "unrecognized options: $ac_unrecognized_opts" ;; *) $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2 ;; esac fi # Check all directory arguments for consistency. for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ datadir sysconfdir sharedstatedir localstatedir includedir \ oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ libdir localedir mandir do eval ac_val=\$$ac_var # Remove trailing slashes. case $ac_val in */ ) ac_val=`expr "X$ac_val" : 'X\(.*[^/]\)' \| "X$ac_val" : 'X\(.*\)'` eval $ac_var=\$ac_val;; esac # Be sure to have absolute directory names. case $ac_val in [\\/$]* | ?:[\\/]* ) continue;; NONE | '' ) case $ac_var in *prefix ) continue;; esac;; esac as_fn_error $? "expected an absolute directory name for --$ac_var: $ac_val" done # There might be people who depend on the old broken behavior: `$host' # used to hold the argument of --host etc. # FIXME: To remove some day. build=$build_alias host=$host_alias target=$target_alias # FIXME: To remove some day. if test "x$host_alias" != x; then if test "x$build_alias" = x; then cross_compiling=maybe elif test "x$build_alias" != "x$host_alias"; then cross_compiling=yes fi fi ac_tool_prefix= test -n "$host_alias" && ac_tool_prefix=$host_alias- test "$silent" = yes && exec 6>/dev/null ac_pwd=`pwd` && test -n "$ac_pwd" && ac_ls_di=`ls -di .` && ac_pwd_ls_di=`cd "$ac_pwd" && ls -di .` || as_fn_error $? "working directory cannot be determined" test "X$ac_ls_di" = "X$ac_pwd_ls_di" || as_fn_error $? "pwd does not report name of working directory" # Find the source files, if location was not specified. if test -z "$srcdir"; then ac_srcdir_defaulted=yes # Try the directory containing this script, then the parent directory. ac_confdir=`$as_dirname -- "$as_myself" || $as_expr X"$as_myself" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$as_myself" : 'X\(//\)[^/]' \| \ X"$as_myself" : 'X\(//\)$' \| \ X"$as_myself" : 'X\(/\)' \| . 2>/dev/null || $as_echo X"$as_myself" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q'` srcdir=$ac_confdir if test ! -r "$srcdir/$ac_unique_file"; then srcdir=.. fi else ac_srcdir_defaulted=no fi if test ! -r "$srcdir/$ac_unique_file"; then test "$ac_srcdir_defaulted" = yes && srcdir="$ac_confdir or .." as_fn_error $? "cannot find sources ($ac_unique_file) in $srcdir" fi ac_msg="sources are in $srcdir, but \`cd $srcdir' does not work" ac_abs_confdir=`( cd "$srcdir" && test -r "./$ac_unique_file" || as_fn_error $? "$ac_msg" pwd)` # When building in place, set srcdir=. if test "$ac_abs_confdir" = "$ac_pwd"; then srcdir=. fi # Remove unnecessary trailing slashes from srcdir. # Double slashes in file names in object file debugging info # mess up M-x gdb in Emacs. case $srcdir in */) srcdir=`expr "X$srcdir" : 'X\(.*[^/]\)' \| "X$srcdir" : 'X\(.*\)'`;; esac for ac_var in $ac_precious_vars; do eval ac_env_${ac_var}_set=\${${ac_var}+set} eval ac_env_${ac_var}_value=\$${ac_var} eval ac_cv_env_${ac_var}_set=\${${ac_var}+set} eval ac_cv_env_${ac_var}_value=\$${ac_var} done # # Report the --help message. # if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures tcsh 6.21.00 to adapt to many kinds of systems. +\`configure' configures tcsh 6.22.03 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... To assign environment variables (e.g., CC, CFLAGS...), specify them as VAR=VALUE. See below for descriptions of some of the useful variables. Defaults for the options are specified in brackets. Configuration: -h, --help display this help and exit --help=short display options specific to this package --help=recursive display the short help of all the included packages -V, --version display version information and exit -q, --quiet, --silent do not print \`checking ...' messages --cache-file=FILE cache test results in FILE [disabled] -C, --config-cache alias for \`--cache-file=config.cache' -n, --no-create do not create output files --srcdir=DIR find the sources in DIR [configure dir or \`..'] Installation directories: --prefix=PREFIX install architecture-independent files in PREFIX [$ac_default_prefix] --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX [PREFIX] By default, \`make install' will install all the files in \`$ac_default_prefix/bin', \`$ac_default_prefix/lib' etc. You can specify an installation prefix other than \`$ac_default_prefix' using \`--prefix', for instance \`--prefix=\$HOME'. For better control, use the options below. Fine tuning of the installation directories: --bindir=DIR user executables [EPREFIX/bin] --sbindir=DIR system admin executables [EPREFIX/sbin] --libexecdir=DIR program executables [EPREFIX/libexec] --sysconfdir=DIR read-only single-machine data [PREFIX/etc] --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] --localstatedir=DIR modifiable single-machine data [PREFIX/var] --libdir=DIR object code libraries [EPREFIX/lib] --includedir=DIR C header files [PREFIX/include] --oldincludedir=DIR C header files for non-gcc [/usr/include] --datarootdir=DIR read-only arch.-independent data root [PREFIX/share] --datadir=DIR read-only architecture-independent data [DATAROOTDIR] --infodir=DIR info documentation [DATAROOTDIR/info] --localedir=DIR locale-dependent data [DATAROOTDIR/locale] --mandir=DIR man documentation [DATAROOTDIR/man] --docdir=DIR documentation root [DATAROOTDIR/doc/tcsh] --htmldir=DIR html documentation [DOCDIR] --dvidir=DIR dvi documentation [DOCDIR] --pdfdir=DIR pdf documentation [DOCDIR] --psdir=DIR ps documentation [DOCDIR] _ACEOF cat <<\_ACEOF System types: --build=BUILD configure for building on BUILD [guessed] --host=HOST cross-compile to build programs to run on HOST [BUILD] _ACEOF fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of tcsh 6.21.00:";; + short | recursive ) echo "Configuration of tcsh 6.22.03:";; esac cat <<\_ACEOF Optional Features: --disable-option-checking ignore unrecognized --enable/--with options --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) --enable-FEATURE[=ARG] include FEATURE [ARG=yes] --disable-rpath do not hardcode runtime library paths --disable-nls Disable NLS support --disable-nls-catalogs Disable NLS catalog support Optional Packages: --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) --with-gnu-ld assume the C compiler uses GNU ld [default=no] --with-libiconv-prefix[=DIR] search for libiconv in DIR/include and DIR/lib --without-libiconv-prefix don't search for libiconv in includedir and libdir --with-hesiod=PREFIX Use Hesiod lookup for ~ expansion Some influential environment variables: CC C compiler command CFLAGS C compiler flags LDFLAGS linker flags, e.g. -L if you have libraries in a nonstandard directory LIBS libraries to pass to the linker, e.g. -l CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I if you have headers in a nonstandard directory CPP C preprocessor Use these variables to override the choices made by `configure' or to help it to find libraries and programs with nonstandard names/locations. Report bugs to . _ACEOF ac_status=$? fi if test "$ac_init_help" = "recursive"; then # If there are subdirs, report their specific --help. for ac_dir in : $ac_subdirs_all; do test "x$ac_dir" = x: && continue test -d "$ac_dir" || { cd "$srcdir" && ac_pwd=`pwd` && srcdir=. && test -d "$ac_dir"; } || continue ac_builddir=. case "$ac_dir" in .) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; *) ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'` # A ".." for each directory in $ac_dir_suffix. ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'` case $ac_top_builddir_sub in "") ac_top_builddir_sub=. ac_top_build_prefix= ;; *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; esac ;; esac ac_abs_top_builddir=$ac_pwd ac_abs_builddir=$ac_pwd$ac_dir_suffix # for backward compatibility: ac_top_builddir=$ac_top_build_prefix case $srcdir in .) # We are building in place. ac_srcdir=. ac_top_srcdir=$ac_top_builddir_sub ac_abs_top_srcdir=$ac_pwd ;; [\\/]* | ?:[\\/]* ) # Absolute name. ac_srcdir=$srcdir$ac_dir_suffix; ac_top_srcdir=$srcdir ac_abs_top_srcdir=$srcdir ;; *) # Relative name. ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix ac_top_srcdir=$ac_top_build_prefix$srcdir ac_abs_top_srcdir=$ac_pwd/$srcdir ;; esac ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix cd "$ac_dir" || { ac_status=$?; continue; } # Check for guested configure. if test -f "$ac_srcdir/configure.gnu"; then echo && $SHELL "$ac_srcdir/configure.gnu" --help=recursive elif test -f "$ac_srcdir/configure"; then echo && $SHELL "$ac_srcdir/configure" --help=recursive else $as_echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2 fi || ac_status=$? cd "$ac_pwd" || { ac_status=$?; break; } done fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -tcsh configure 6.21.00 +tcsh configure 6.22.03 generated by GNU Autoconf 2.69 Copyright (C) 2012 Free Software Foundation, Inc. This configure script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it. _ACEOF exit fi ## ------------------------ ## ## Autoconf initialization. ## ## ------------------------ ## # ac_fn_c_try_compile LINENO # -------------------------- # Try to compile conftest.$ac_ext, and return whether this succeeded. ac_fn_c_try_compile () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack rm -f conftest.$ac_objext if { { ac_try="$ac_compile" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_compile") 2>conftest.err ac_status=$? if test -s conftest.err; then grep -v '^ *+' conftest.err >conftest.er1 cat conftest.er1 >&5 mv -f conftest.er1 conftest.err fi $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && { test -z "$ac_c_werror_flag" || test ! -s conftest.err } && test -s conftest.$ac_objext; then : ac_retval=0 else $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 ac_retval=1 fi eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno as_fn_set_status $ac_retval } # ac_fn_c_try_compile # ac_fn_c_try_cpp LINENO # ---------------------- # Try to preprocess conftest.$ac_ext, and return whether this succeeded. ac_fn_c_try_cpp () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack if { { ac_try="$ac_cpp conftest.$ac_ext" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_cpp conftest.$ac_ext") 2>conftest.err ac_status=$? if test -s conftest.err; then grep -v '^ *+' conftest.err >conftest.er1 cat conftest.er1 >&5 mv -f conftest.er1 conftest.err fi $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } > conftest.i && { test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || test ! -s conftest.err }; then : ac_retval=0 else $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 ac_retval=1 fi eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno as_fn_set_status $ac_retval } # ac_fn_c_try_cpp # ac_fn_c_try_link LINENO # ----------------------- # Try to link conftest.$ac_ext, and return whether this succeeded. ac_fn_c_try_link () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack rm -f conftest.$ac_objext conftest$ac_exeext if { { ac_try="$ac_link" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_link") 2>conftest.err ac_status=$? if test -s conftest.err; then grep -v '^ *+' conftest.err >conftest.er1 cat conftest.er1 >&5 mv -f conftest.er1 conftest.err fi $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && { test -z "$ac_c_werror_flag" || test ! -s conftest.err } && test -s conftest$ac_exeext && { test "$cross_compiling" = yes || test -x conftest$ac_exeext }; then : ac_retval=0 else $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 ac_retval=1 fi # Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information # created by the PGI compiler (conftest_ipa8_conftest.oo), as it would # interfere with the next link command; also delete a directory that is # left behind by Apple's compiler. We do this before executing the actions. rm -rf conftest.dSYM conftest_ipa8_conftest.oo eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno as_fn_set_status $ac_retval } # ac_fn_c_try_link # ac_fn_c_try_run LINENO # ---------------------- # Try to link conftest.$ac_ext, and return whether this succeeded. Assumes # that executables *can* be run. ac_fn_c_try_run () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack if { { ac_try="$ac_link" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_link") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && { ac_try='./conftest$ac_exeext' { { case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_try") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; }; then : ac_retval=0 else $as_echo "$as_me: program exited with status $ac_status" >&5 $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 ac_retval=$ac_status fi rm -rf conftest.dSYM conftest_ipa8_conftest.oo eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno as_fn_set_status $ac_retval } # ac_fn_c_try_run # ac_fn_c_check_header_mongrel LINENO HEADER VAR INCLUDES # ------------------------------------------------------- # Tests whether HEADER exists, giving a warning if it cannot be compiled using # the include files in INCLUDES and setting the cache variable VAR # accordingly. ac_fn_c_check_header_mongrel () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack if eval \${$3+:} false; then : { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 $as_echo_n "checking for $2... " >&6; } if eval \${$3+:} false; then : $as_echo_n "(cached) " >&6 fi eval ac_res=\$$3 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 $as_echo "$ac_res" >&6; } else # Is the header compilable? { $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 usability" >&5 $as_echo_n "checking $2 usability... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 #include <$2> _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_header_compiler=yes else ac_header_compiler=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_compiler" >&5 $as_echo "$ac_header_compiler" >&6; } # Is the header present? { $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 presence" >&5 $as_echo_n "checking $2 presence... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include <$2> _ACEOF if ac_fn_c_try_cpp "$LINENO"; then : ac_header_preproc=yes else ac_header_preproc=no fi rm -f conftest.err conftest.i conftest.$ac_ext { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_preproc" >&5 $as_echo "$ac_header_preproc" >&6; } # So? What about this header? case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in #(( yes:no: ) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&5 $as_echo "$as_me: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5 $as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;} ;; no:yes:* ) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: present but cannot be compiled" >&5 $as_echo "$as_me: WARNING: $2: present but cannot be compiled" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: check for missing prerequisite headers?" >&5 $as_echo "$as_me: WARNING: $2: check for missing prerequisite headers?" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: see the Autoconf documentation" >&5 $as_echo "$as_me: WARNING: $2: see the Autoconf documentation" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: section \"Present But Cannot Be Compiled\"" >&5 $as_echo "$as_me: WARNING: $2: section \"Present But Cannot Be Compiled\"" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5 $as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;} ( $as_echo "## --------------------------------------- ## ## Report this to https://bugs.astron.com/ ## ## --------------------------------------- ##" ) | sed "s/^/$as_me: WARNING: /" >&2 ;; esac { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 $as_echo_n "checking for $2... " >&6; } if eval \${$3+:} false; then : $as_echo_n "(cached) " >&6 else eval "$3=\$ac_header_compiler" fi eval ac_res=\$$3 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 $as_echo "$ac_res" >&6; } fi eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_c_check_header_mongrel # ac_fn_c_check_header_compile LINENO HEADER VAR INCLUDES # ------------------------------------------------------- # Tests whether HEADER exists and can be compiled using the include files in # INCLUDES, setting the cache variable VAR accordingly. ac_fn_c_check_header_compile () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 $as_echo_n "checking for $2... " >&6; } if eval \${$3+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 #include <$2> _ACEOF if ac_fn_c_try_compile "$LINENO"; then : eval "$3=yes" else eval "$3=no" fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi eval ac_res=\$$3 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 $as_echo "$ac_res" >&6; } eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_c_check_header_compile # ac_fn_c_compute_int LINENO EXPR VAR INCLUDES # -------------------------------------------- # Tries to find the compile-time value of EXPR in a program that includes # INCLUDES, setting VAR accordingly. Returns whether the value could be # computed ac_fn_c_compute_int () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack if test "$cross_compiling" = yes; then # Depending upon the size, compute the lo and hi bounds. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 int main () { static int test_array [1 - 2 * !(($2) >= 0)]; test_array [0] = 0; return test_array [0]; ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_lo=0 ac_mid=0 while :; do cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 int main () { static int test_array [1 - 2 * !(($2) <= $ac_mid)]; test_array [0] = 0; return test_array [0]; ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_hi=$ac_mid; break else as_fn_arith $ac_mid + 1 && ac_lo=$as_val if test $ac_lo -le $ac_mid; then ac_lo= ac_hi= break fi as_fn_arith 2 '*' $ac_mid + 1 && ac_mid=$as_val fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext done else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 int main () { static int test_array [1 - 2 * !(($2) < 0)]; test_array [0] = 0; return test_array [0]; ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_hi=-1 ac_mid=-1 while :; do cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 int main () { static int test_array [1 - 2 * !(($2) >= $ac_mid)]; test_array [0] = 0; return test_array [0]; ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_lo=$ac_mid; break else as_fn_arith '(' $ac_mid ')' - 1 && ac_hi=$as_val if test $ac_mid -le $ac_hi; then ac_lo= ac_hi= break fi as_fn_arith 2 '*' $ac_mid && ac_mid=$as_val fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext done else ac_lo= ac_hi= fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext # Binary search between lo and hi bounds. while test "x$ac_lo" != "x$ac_hi"; do as_fn_arith '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo && ac_mid=$as_val cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 int main () { static int test_array [1 - 2 * !(($2) <= $ac_mid)]; test_array [0] = 0; return test_array [0]; ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_hi=$ac_mid else as_fn_arith '(' $ac_mid ')' + 1 && ac_lo=$as_val fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext done case $ac_lo in #(( ?*) eval "$3=\$ac_lo"; ac_retval=0 ;; '') ac_retval=1 ;; esac else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 static long int longval () { return $2; } static unsigned long int ulongval () { return $2; } #include #include int main () { FILE *f = fopen ("conftest.val", "w"); if (! f) return 1; if (($2) < 0) { long int i = longval (); if (i != ($2)) return 1; fprintf (f, "%ld", i); } else { unsigned long int i = ulongval (); if (i != ($2)) return 1; fprintf (f, "%lu", i); } /* Do not output a trailing newline, as this causes \r\n confusion on some platforms. */ return ferror (f) || fclose (f) != 0; ; return 0; } _ACEOF if ac_fn_c_try_run "$LINENO"; then : echo >>conftest.val; read $3 &5 $as_echo_n "checking for $2... " >&6; } if eval \${$3+:} false; then : $as_echo_n "(cached) " >&6 else eval "$3=no" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 int main () { if (sizeof ($2)) return 0; ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 int main () { if (sizeof (($2))) return 0; ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : else eval "$3=yes" fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi eval ac_res=\$$3 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 $as_echo "$ac_res" >&6; } eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_c_check_type # ac_fn_c_find_uintX_t LINENO BITS VAR # ------------------------------------ # Finds an unsigned integer type with width BITS, setting cache variable VAR # accordingly. ac_fn_c_find_uintX_t () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack { $as_echo "$as_me:${as_lineno-$LINENO}: checking for uint$2_t" >&5 $as_echo_n "checking for uint$2_t... " >&6; } if eval \${$3+:} false; then : $as_echo_n "(cached) " >&6 else eval "$3=no" # Order is important - never check a type that is potentially smaller # than half of the expected target width. for ac_type in uint$2_t 'unsigned int' 'unsigned long int' \ 'unsigned long long int' 'unsigned short int' 'unsigned char'; do cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $ac_includes_default int main () { static int test_array [1 - 2 * !((($ac_type) -1 >> ($2 / 2 - 1)) >> ($2 / 2 - 1) == 3)]; test_array [0] = 0; return test_array [0]; ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : case $ac_type in #( uint$2_t) : eval "$3=yes" ;; #( *) : eval "$3=\$ac_type" ;; esac fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext if eval test \"x\$"$3"\" = x"no"; then : else break fi done fi eval ac_res=\$$3 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 $as_echo "$ac_res" >&6; } eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_c_find_uintX_t # ac_fn_c_check_member LINENO AGGR MEMBER VAR INCLUDES # ---------------------------------------------------- # Tries to find if the field MEMBER exists in type AGGR, after including # INCLUDES, setting cache variable VAR accordingly. ac_fn_c_check_member () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2.$3" >&5 $as_echo_n "checking for $2.$3... " >&6; } if eval \${$4+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $5 int main () { static $2 ac_aggr; if (ac_aggr.$3) return 0; ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : eval "$4=yes" else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $5 int main () { static $2 ac_aggr; if (sizeof ac_aggr.$3) return 0; ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : eval "$4=yes" else eval "$4=no" fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi eval ac_res=\$$4 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 $as_echo "$ac_res" >&6; } eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_c_check_member # ac_fn_c_check_decl LINENO SYMBOL VAR INCLUDES # --------------------------------------------- # Tests whether SYMBOL is declared in INCLUDES, setting cache variable VAR # accordingly. ac_fn_c_check_decl () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack as_decl_name=`echo $2|sed 's/ *(.*//'` as_decl_use=`echo $2|sed -e 's/(/((/' -e 's/)/) 0&/' -e 's/,/) 0& (/g'` { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $as_decl_name is declared" >&5 $as_echo_n "checking whether $as_decl_name is declared... " >&6; } if eval \${$3+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 int main () { #ifndef $as_decl_name #ifdef __cplusplus (void) $as_decl_use; #else (void) $as_decl_name; #endif #endif ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : eval "$3=yes" else eval "$3=no" fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi eval ac_res=\$$3 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 $as_echo "$ac_res" >&6; } eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_c_check_decl # ac_fn_c_check_func LINENO FUNC VAR # ---------------------------------- # Tests whether FUNC exists, setting the cache variable VAR accordingly ac_fn_c_check_func () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 $as_echo_n "checking for $2... " >&6; } if eval \${$3+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Define $2 to an innocuous variant, in case declares $2. For example, HP-UX 11i declares gettimeofday. */ #define $2 innocuous_$2 /* System header to define __stub macros and hopefully few prototypes, which can conflict with char $2 (); below. Prefer to if __STDC__ is defined, since exists even on freestanding compilers. */ #ifdef __STDC__ # include #else # include #endif #undef $2 /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. */ #ifdef __cplusplus extern "C" #endif char $2 (); /* The GNU C library defines this for functions which it implements to always fail with ENOSYS. Some functions are actually named something starting with __ and the normal name is an alias. */ #if defined __stub_$2 || defined __stub___$2 choke me #endif int main () { return $2 (); ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : eval "$3=yes" else eval "$3=no" fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext fi eval ac_res=\$$3 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 $as_echo "$ac_res" >&6; } eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_c_check_func cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by tcsh $as_me 6.21.00, which was +It was created by tcsh $as_me 6.22.03, which was generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ _ACEOF exec 5>>config.log { cat <<_ASUNAME ## --------- ## ## Platform. ## ## --------- ## hostname = `(hostname || uname -n) 2>/dev/null | sed 1q` uname -m = `(uname -m) 2>/dev/null || echo unknown` uname -r = `(uname -r) 2>/dev/null || echo unknown` uname -s = `(uname -s) 2>/dev/null || echo unknown` uname -v = `(uname -v) 2>/dev/null || echo unknown` /usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown` /bin/uname -X = `(/bin/uname -X) 2>/dev/null || echo unknown` /bin/arch = `(/bin/arch) 2>/dev/null || echo unknown` /usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null || echo unknown` /usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown` /usr/bin/hostinfo = `(/usr/bin/hostinfo) 2>/dev/null || echo unknown` /bin/machine = `(/bin/machine) 2>/dev/null || echo unknown` /usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null || echo unknown` /bin/universe = `(/bin/universe) 2>/dev/null || echo unknown` _ASUNAME as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. $as_echo "PATH: $as_dir" done IFS=$as_save_IFS } >&5 cat >&5 <<_ACEOF ## ----------- ## ## Core tests. ## ## ----------- ## _ACEOF # Keep a trace of the command line. # Strip out --no-create and --no-recursion so they do not pile up. # Strip out --silent because we don't want to record it for future runs. # Also quote any args containing shell meta-characters. # Make two passes to allow for proper duplicate-argument suppression. ac_configure_args= ac_configure_args0= ac_configure_args1= ac_must_keep_next=false for ac_pass in 1 2 do for ac_arg do case $ac_arg in -no-create | --no-c* | -n | -no-recursion | --no-r*) continue ;; -q | -quiet | --quiet | --quie | --qui | --qu | --q \ | -silent | --silent | --silen | --sile | --sil) continue ;; *\'*) ac_arg=`$as_echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; esac case $ac_pass in 1) as_fn_append ac_configure_args0 " '$ac_arg'" ;; 2) as_fn_append ac_configure_args1 " '$ac_arg'" if test $ac_must_keep_next = true; then ac_must_keep_next=false # Got value, back to normal. else case $ac_arg in *=* | --config-cache | -C | -disable-* | --disable-* \ | -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \ | -q | -quiet | --q* | -silent | --sil* | -v | -verb* \ | -with-* | --with-* | -without-* | --without-* | --x) case "$ac_configure_args0 " in "$ac_configure_args1"*" '$ac_arg' "* ) continue ;; esac ;; -* ) ac_must_keep_next=true ;; esac fi as_fn_append ac_configure_args " '$ac_arg'" ;; esac done done { ac_configure_args0=; unset ac_configure_args0;} { ac_configure_args1=; unset ac_configure_args1;} # When interrupted or exit'd, cleanup temporary files, and complete # config.log. We remove comments because anyway the quotes in there # would cause problems or look ugly. # WARNING: Use '\'' to represent an apostrophe within the trap. # WARNING: Do not start the trap code with a newline, due to a FreeBSD 4.0 bug. trap 'exit_status=$? # Save into config.log some information that might help in debugging. { echo $as_echo "## ---------------- ## ## Cache variables. ## ## ---------------- ##" echo # The following way of writing the cache mishandles newlines in values, ( for ac_var in `(set) 2>&1 | sed -n '\''s/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'\''`; do eval ac_val=\$$ac_var case $ac_val in #( *${as_nl}*) case $ac_var in #( *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 $as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; esac case $ac_var in #( _ | IFS | as_nl) ;; #( BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #( *) { eval $ac_var=; unset $ac_var;} ;; esac ;; esac done (set) 2>&1 | case $as_nl`(ac_space='\'' '\''; set) 2>&1` in #( *${as_nl}ac_space=\ *) sed -n \ "s/'\''/'\''\\\\'\'''\''/g; s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\''\\2'\''/p" ;; #( *) sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" ;; esac | sort ) echo $as_echo "## ----------------- ## ## Output variables. ## ## ----------------- ##" echo for ac_var in $ac_subst_vars do eval ac_val=\$$ac_var case $ac_val in *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; esac $as_echo "$ac_var='\''$ac_val'\''" done | sort echo if test -n "$ac_subst_files"; then $as_echo "## ------------------- ## ## File substitutions. ## ## ------------------- ##" echo for ac_var in $ac_subst_files do eval ac_val=\$$ac_var case $ac_val in *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; esac $as_echo "$ac_var='\''$ac_val'\''" done | sort echo fi if test -s confdefs.h; then $as_echo "## ----------- ## ## confdefs.h. ## ## ----------- ##" echo cat confdefs.h echo fi test "$ac_signal" != 0 && $as_echo "$as_me: caught signal $ac_signal" $as_echo "$as_me: exit $exit_status" } >&5 rm -f core *.core core.conftest.* && rm -f -r conftest* confdefs* conf$$* $ac_clean_files && exit $exit_status ' 0 for ac_signal in 1 2 13 15; do trap 'ac_signal='$ac_signal'; as_fn_exit 1' $ac_signal done ac_signal=0 # confdefs.h avoids OS command line length limits that DEFS can exceed. rm -f -r conftest* confdefs.h $as_echo "/* confdefs.h */" > confdefs.h # Predefined preprocessor variables. cat >>confdefs.h <<_ACEOF #define PACKAGE_NAME "$PACKAGE_NAME" _ACEOF cat >>confdefs.h <<_ACEOF #define PACKAGE_TARNAME "$PACKAGE_TARNAME" _ACEOF cat >>confdefs.h <<_ACEOF #define PACKAGE_VERSION "$PACKAGE_VERSION" _ACEOF cat >>confdefs.h <<_ACEOF #define PACKAGE_STRING "$PACKAGE_STRING" _ACEOF cat >>confdefs.h <<_ACEOF #define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT" _ACEOF cat >>confdefs.h <<_ACEOF #define PACKAGE_URL "$PACKAGE_URL" _ACEOF # Let the site file select an alternate cache file if it wants to. # Prefer an explicitly selected file to automatically selected ones. ac_site_file1=NONE ac_site_file2=NONE if test -n "$CONFIG_SITE"; then # We do not want a PATH search for config.site. case $CONFIG_SITE in #(( -*) ac_site_file1=./$CONFIG_SITE;; */*) ac_site_file1=$CONFIG_SITE;; *) ac_site_file1=./$CONFIG_SITE;; esac elif test "x$prefix" != xNONE; then ac_site_file1=$prefix/share/config.site ac_site_file2=$prefix/etc/config.site else ac_site_file1=$ac_default_prefix/share/config.site ac_site_file2=$ac_default_prefix/etc/config.site fi for ac_site_file in "$ac_site_file1" "$ac_site_file2" do test "x$ac_site_file" = xNONE && continue if test /dev/null != "$ac_site_file" && test -r "$ac_site_file"; then { $as_echo "$as_me:${as_lineno-$LINENO}: loading site script $ac_site_file" >&5 $as_echo "$as_me: loading site script $ac_site_file" >&6;} sed 's/^/| /' "$ac_site_file" >&5 . "$ac_site_file" \ || { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "failed to load site script $ac_site_file See \`config.log' for more details" "$LINENO" 5; } fi done if test -r "$cache_file"; then # Some versions of bash will fail to source /dev/null (special files # actually), so we avoid doing that. DJGPP emulates it as a regular file. if test /dev/null != "$cache_file" && test -f "$cache_file"; then { $as_echo "$as_me:${as_lineno-$LINENO}: loading cache $cache_file" >&5 $as_echo "$as_me: loading cache $cache_file" >&6;} case $cache_file in [\\/]* | ?:[\\/]* ) . "$cache_file";; *) . "./$cache_file";; esac fi else { $as_echo "$as_me:${as_lineno-$LINENO}: creating cache $cache_file" >&5 $as_echo "$as_me: creating cache $cache_file" >&6;} >$cache_file fi # Check that the precious variables saved in the cache have kept the same # value. ac_cache_corrupted=false for ac_var in $ac_precious_vars; do eval ac_old_set=\$ac_cv_env_${ac_var}_set eval ac_new_set=\$ac_env_${ac_var}_set eval ac_old_val=\$ac_cv_env_${ac_var}_value eval ac_new_val=\$ac_env_${ac_var}_value case $ac_old_set,$ac_new_set in set,) { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5 $as_echo "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;} ac_cache_corrupted=: ;; ,set) { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was not set in the previous run" >&5 $as_echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;} ac_cache_corrupted=: ;; ,);; *) if test "x$ac_old_val" != "x$ac_new_val"; then # differences in whitespace do not lead to failure. ac_old_val_w=`echo x $ac_old_val` ac_new_val_w=`echo x $ac_new_val` if test "$ac_old_val_w" != "$ac_new_val_w"; then { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' has changed since the previous run:" >&5 $as_echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;} ac_cache_corrupted=: else { $as_echo "$as_me:${as_lineno-$LINENO}: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&5 $as_echo "$as_me: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&2;} eval $ac_var=\$ac_old_val fi { $as_echo "$as_me:${as_lineno-$LINENO}: former value: \`$ac_old_val'" >&5 $as_echo "$as_me: former value: \`$ac_old_val'" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: current value: \`$ac_new_val'" >&5 $as_echo "$as_me: current value: \`$ac_new_val'" >&2;} fi;; esac # Pass precious variables to config.status. if test "$ac_new_set" = set; then case $ac_new_val in *\'*) ac_arg=$ac_var=`$as_echo "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;; *) ac_arg=$ac_var=$ac_new_val ;; esac case " $ac_configure_args " in *" '$ac_arg' "*) ;; # Avoid dups. Use of quotes ensures accuracy. *) as_fn_append ac_configure_args " '$ac_arg'" ;; esac fi done if $ac_cache_corrupted; then { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: error: changes in the environment can compromise the build" >&5 $as_echo "$as_me: error: changes in the environment can compromise the build" >&2;} as_fn_error $? "run \`make distclean' and/or \`rm $cache_file' and start over" "$LINENO" 5 fi ## -------------------- ## ## Main body of script. ## ## -------------------- ## ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu ac_config_headers="$ac_config_headers config.h" ac_config_commands="$ac_config_commands ./atconfig" ac_aux_dir= for ac_dir in "$srcdir" "$srcdir/.." "$srcdir/../.."; do if test -f "$ac_dir/install-sh"; then ac_aux_dir=$ac_dir ac_install_sh="$ac_aux_dir/install-sh -c" break elif test -f "$ac_dir/install.sh"; then ac_aux_dir=$ac_dir ac_install_sh="$ac_aux_dir/install.sh -c" break elif test -f "$ac_dir/shtool"; then ac_aux_dir=$ac_dir ac_install_sh="$ac_aux_dir/shtool install -c" break fi done if test -z "$ac_aux_dir"; then as_fn_error $? "cannot find install-sh, install.sh, or shtool in \"$srcdir\" \"$srcdir/..\" \"$srcdir/../..\"" "$LINENO" 5 fi # These three variables are undocumented and unsupported, # and are intended to be withdrawn in a future Autoconf release. # They can cause serious problems if a builder's source tree is in a directory # whose full name contains unusual characters. ac_config_guess="$SHELL $ac_aux_dir/config.guess" # Please don't use this var. ac_config_sub="$SHELL $ac_aux_dir/config.sub" # Please don't use this var. ac_configure="$SHELL $ac_aux_dir/configure" # Please don't use this var. # Find a good install program. We prefer a C program (faster), # so one script is as good as another. But avoid the broken or # incompatible versions: # SysV /etc/install, /usr/sbin/install # SunOS /usr/etc/install # IRIX /sbin/install # AIX /bin/install # AmigaOS /C/install, which installs bootblocks on floppy discs # AIX 4 /usr/bin/installbsd, which doesn't work without a -g flag # AFS /usr/afsws/bin/install, which mishandles nonexistent args # SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff" # OS/2's system install, which has a completely different semantic # ./install, which can be erroneously created by make from ./install.sh. # Reject install programs that cannot install multiple files. { $as_echo "$as_me:${as_lineno-$LINENO}: checking for a BSD-compatible install" >&5 $as_echo_n "checking for a BSD-compatible install... " >&6; } if test -z "$INSTALL"; then if ${ac_cv_path_install+:} false; then : $as_echo_n "(cached) " >&6 else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. # Account for people who put trailing slashes in PATH elements. case $as_dir/ in #(( ./ | .// | /[cC]/* | \ /etc/* | /usr/sbin/* | /usr/etc/* | /sbin/* | /usr/afsws/bin/* | \ ?:[\\/]os2[\\/]install[\\/]* | ?:[\\/]OS2[\\/]INSTALL[\\/]* | \ /usr/ucb/* ) ;; *) # OSF1 and SCO ODT 3.0 have their own names for install. # Don't use installbsd from OSF since it installs stuff as root # by default. for ac_prog in ginstall scoinst install; do for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_prog$ac_exec_ext"; then if test $ac_prog = install && grep dspmsg "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then # AIX install. It has an incompatible calling convention. : elif test $ac_prog = install && grep pwplus "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then # program-specific install script used by HP pwplus--don't use. : else rm -rf conftest.one conftest.two conftest.dir echo one > conftest.one echo two > conftest.two mkdir conftest.dir if "$as_dir/$ac_prog$ac_exec_ext" -c conftest.one conftest.two "`pwd`/conftest.dir" && test -s conftest.one && test -s conftest.two && test -s conftest.dir/conftest.one && test -s conftest.dir/conftest.two then ac_cv_path_install="$as_dir/$ac_prog$ac_exec_ext -c" break 3 fi fi fi done done ;; esac done IFS=$as_save_IFS rm -rf conftest.one conftest.two conftest.dir fi if test "${ac_cv_path_install+set}" = set; then INSTALL=$ac_cv_path_install else # As a last resort, use the slow shell script. Don't cache a # value for INSTALL within a source directory, because that will # break other packages using the cache if that directory is # removed, or if the value is a relative name. INSTALL=$ac_install_sh fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $INSTALL" >&5 $as_echo "$INSTALL" >&6; } # Use test -z because SunOS4 sh mishandles braces in ${var-val}. # It thinks the first close brace ends the variable substitution. test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}' test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL}' test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644' # Make sure we can run config.sub. $SHELL "$ac_aux_dir/config.sub" sun4 >/dev/null 2>&1 || as_fn_error $? "cannot run $SHELL $ac_aux_dir/config.sub" "$LINENO" 5 { $as_echo "$as_me:${as_lineno-$LINENO}: checking build system type" >&5 $as_echo_n "checking build system type... " >&6; } if ${ac_cv_build+:} false; then : $as_echo_n "(cached) " >&6 else ac_build_alias=$build_alias test "x$ac_build_alias" = x && ac_build_alias=`$SHELL "$ac_aux_dir/config.guess"` test "x$ac_build_alias" = x && as_fn_error $? "cannot guess build type; you must specify one" "$LINENO" 5 ac_cv_build=`$SHELL "$ac_aux_dir/config.sub" $ac_build_alias` || as_fn_error $? "$SHELL $ac_aux_dir/config.sub $ac_build_alias failed" "$LINENO" 5 fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_build" >&5 $as_echo "$ac_cv_build" >&6; } case $ac_cv_build in *-*-*) ;; *) as_fn_error $? "invalid value of canonical build" "$LINENO" 5;; esac build=$ac_cv_build ac_save_IFS=$IFS; IFS='-' set x $ac_cv_build shift build_cpu=$1 build_vendor=$2 shift; shift # Remember, the first character of IFS is used to create $*, # except with old shells: build_os=$* IFS=$ac_save_IFS case $build_os in *\ *) build_os=`echo "$build_os" | sed 's/ /-/g'`;; esac { $as_echo "$as_me:${as_lineno-$LINENO}: checking host system type" >&5 $as_echo_n "checking host system type... " >&6; } if ${ac_cv_host+:} false; then : $as_echo_n "(cached) " >&6 else if test "x$host_alias" = x; then ac_cv_host=$ac_cv_build else ac_cv_host=`$SHELL "$ac_aux_dir/config.sub" $host_alias` || as_fn_error $? "$SHELL $ac_aux_dir/config.sub $host_alias failed" "$LINENO" 5 fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_host" >&5 $as_echo "$ac_cv_host" >&6; } case $ac_cv_host in *-*-*) ;; *) as_fn_error $? "invalid value of canonical host" "$LINENO" 5;; esac host=$ac_cv_host ac_save_IFS=$IFS; IFS='-' set x $ac_cv_host shift host_cpu=$1 host_vendor=$2 shift; shift # Remember, the first character of IFS is used to create $*, # except with old shells: host_os=$* IFS=$ac_save_IFS case $host_os in *\ *) host_os=`echo "$host_os" | sed 's/ /-/g'`;; esac -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking cached host tuple" >&5 -$as_echo_n "checking cached host tuple... " >&6; } -if { test x"${ac_cv_host_system_type+set}" = x"set" && - test x"$ac_cv_host_system_type" != x"$host"; }; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: different" >&5 -$as_echo "different" >&6; } - as_fn_error $? "remove config.cache and re-run configure" "$LINENO" 5 + + if test "X$prefix" = "XNONE"; then + acl_final_prefix="$ac_default_prefix" + else + acl_final_prefix="$prefix" + fi + if test "X$exec_prefix" = "XNONE"; then + acl_final_exec_prefix='${prefix}' + else + acl_final_exec_prefix="$exec_prefix" + fi + acl_save_prefix="$prefix" + prefix="$acl_final_prefix" + eval acl_final_exec_prefix=\"$acl_final_exec_prefix\" + prefix="$acl_save_prefix" + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args. +set dummy ${ac_tool_prefix}gcc; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_CC+:} false; then : + $as_echo_n "(cached) " >&6 else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: ok" >&5 -$as_echo "ok" >&6; } -fi -ac_cv_host_system_type="$host" + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_CC="${ac_tool_prefix}gcc" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +$as_echo "$CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi -case "${host}" in +fi +if test -z "$ac_cv_prog_CC"; then + ac_ct_CC=$CC + # Extract the first word of "gcc", so it can be a program name with args. +set dummy gcc; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_CC+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_CC"; then + ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_CC="gcc" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS - ## Alpha (DEC) machines. - alpha*-dec-osf* ) - tcsh_config_file=decosf1 - ;; +fi +fi +ac_ct_CC=$ac_cv_prog_ac_ct_CC +if test -n "$ac_ct_CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 +$as_echo "$ac_ct_CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi - ## Ultrix - *-dec-ultrix* ) - tcsh_config_file=ultrix - ;; + if test "x$ac_ct_CC" = x; then + CC="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + CC=$ac_ct_CC + fi +else + CC="$ac_cv_prog_CC" +fi - ## DGUX - *-dg-dguxR4* ) - tcsh_config_file=dgux5.4 - ;; - m88k-dg-dgux5.4R* ) - tcsh_config_file=dgux5.4 - ;; +if test -z "$CC"; then + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args. +set dummy ${ac_tool_prefix}cc; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_CC+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_CC="${ac_tool_prefix}cc" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS - ## HP/UX - *-hp-hpux7* ) - tcsh_config_file=hpux7 - ;; - *-hp-hpux[89]* ) - tcsh_config_file=hpux8 - ;; - *-hp-hpux1[0-9]* ) - tcsh_config_file=hpux11 - ;; +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +$as_echo "$CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi - ## IBM AIX systems - *-ibm-aix*) - tcsh_config_file=aix - ;; - ## SX-4 - sx4-nec-*) - CC='cc -h0,ansi,novector,float0' - LDFLAGS='-Gsmall' - tcsh_config_file=superux8 - ;; + fi +fi +if test -z "$CC"; then + # Extract the first word of "cc", so it can be a program name with args. +set dummy cc; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_CC+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else + ac_prog_rejected=no +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then + ac_prog_rejected=yes + continue + fi + ac_cv_prog_CC="cc" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS - ## IBM OS/390 systems - *-ibm-os390*) - CC='c89' - tcsh_config_file=os390 - ;; +if test $ac_prog_rejected = yes; then + # We found a bogon in the path, so make sure we never use it. + set dummy $ac_cv_prog_CC + shift + if test $# != 0; then + # We chose a different compiler from the bogus one. + # However, it has the same basename, so the bogon will be chosen + # first if we set CC to just the basename; use the full file name. + shift + ac_cv_prog_CC="$as_dir/$ac_word${1+' '}$@" + fi +fi +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +$as_echo "$CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi - ## Android - *-*-android*) - tcsh_config_file=android - ;; - ## Linux - *-*-linux* | *-*-gnu* | *-*-k*bsd*-gnu) - tcsh_config_file=linux - ;; - - ## Motorola systems - m68k-motorola-sysv* ) - tcsh_config_file=sysV68 - ;; - m88k-motorola-sysv3* ) - tcsh_config_file=sysV88 - ;; - - ## Minix systems - *-*-minix*) - tcsh_config_file=minix - ;; - - ## NetBSD systems - *-*-netbsd*) - tcsh_config_file=bsd4.4 - ;; - - ## FreeBSD systems - *-*-freebsd*) - tcsh_config_file=bsd4.4 - ;; - - ## MidnightBSD systems - *-*-midnightbsd*) - tcsh_config_file=bsd4.4 - ;; - - ## DragonFlyBSD systems - *-*-dragonfly*) - tcsh_config_file=bsd4.4 - ;; - - ## MirBSD systems - *-*-mirbsd*) - tcsh_config_file=bsd4.4 - ;; - - ## OpenBSD systems - *-*-openbsd*) - tcsh_config_file=bsd4.4 - ;; - - ## BSDI systems - *-*-bsdi*) - tcsh_config_file=bsd4.4 - ;; - - ## Mac OS X Server - *-*-rhapsody* ) - tcsh_config_file=bsd4.4 - ;; - - ## Mac OS X Server - *-*-darwin* ) - tcsh_config_file=bsd4.4 - ;; - - ## DragonFly systems - *-*-dragonfly*) - tcsh_config_file=bsd4.4 - ;; - - ## Silicon Graphics machines - *-sgi-iri* ) - tcsh_config_file=irix - case "${host_os}" in - irix[34]*) # Irix-3.x - Irix 4.x - NON_GNU_DFLAGS='-D__STDC__' - LIBS='-lsun -lbsd -lc_s' - ;; - irix5* | irix6.[01]*) # Irix 5.x, Irix 6.0 - 6.1 - LIBS='-lbsd' - ;; - irix6.[2-9]*) # Irix 6.2 and later - tcsh_config_file=irix62 - ;; - esac - ;; - - ## Suns - *-sun-sunos3* ) - tcsh_config_file=sunos35 - ;; - *-sun-sunos4.0* ) - tcsh_config_file=sunos40 - ;; - *-sun-sunos4.1.[12]* ) - tcsh_config_file=sunos41 - ;; - *-sun-sunos4.1.[3456]* ) - tcsh_config_file=sunos413 - ;; - *-*-solaris2.[01] ) # Should handle sparc or x86 - tcsh_config_file=sol2 - ;; - *-sun-solaris2.2 ) # Sparc only release - tcsh_config_file=sol22 - ;; - *-sun-solaris2.3 ) # Sparc only release - tcsh_config_file=sol23 - ;; - *-*-solaris2.[45] ) # Should handle sparc, x86 and powerpc - tcsh_config_file=sol24 - ;; - *-*-solaris2.[678] ) # Should handle sparc, x86 and powerpc - tcsh_config_file=sol26 - ;; - *-*-solaris2.* ) # Should handle sparc, x86 and powerpc - tcsh_config_file=sol29 - ;; - - ## Dell SVR4 - *-dell-sysv4* ) - tcsh_config_file=sysv4 - DFLAGS="$DFLAGS -DDELL" - ;; - - ## SVR4 (Generic and otherwise) - *-*-sysv4* ) - tcsh_config_file=sysv4 - ;; - - ## Tektronix systems - m68k-tektronix-bsd* ) - tcsh_config_file=bsd - NON_GNU_DFLAGS='-DBSD -DUTek' - ;; - m88k-tektronix-sysv3* ) - tcsh_config_file=tekXD88 - ;; - - ## SCO - *-sco3.2v5*) - tcsh_config_file=sco32v5 - ;; - *-sco3.2v4*) - tcsh_config_file=sco32v4 - ;; - *-sco3.2v2*) - tcsh_config_file=sco32v2 - ;; - - ## Siemens BS2000 Mainframe - bs2000-siemens-*) - tcsh_config_file=bs2000 - ;; - - ## Convex - *-convex*) - tcsh_config_file=convex - ;; - - ## Cray - *-cray-unicos*) - tcsh_config_file=cray - ;; - - ## Red Hat Cygwin - *-cygwin) - tcsh_config_file=cygwin - ;; - - ## mips-compaq-nonstopux - *-*-nonstopux) - tcsh_config_file=sysv4 - ;; - - ## Apollo Domain/OS - *-apollo-*) - tcsh_config_file=apollo - ;; - - ## QNX6 - *-qnx6*) - tcsh_config_file=qnx6 - ;; - - * ) - as_fn_error $? "Tcsh can't guess the configuration file name -for \`${host}' systems. -Check tcsh's \`Ported' file for manual configuration instructions." "$LINENO" 5 - ;; - -esac - -echo "Tcsh will use configuration file \`$tcsh_config_file'." -cp ${srcdir}/config/${tcsh_config_file} config_p.h - - -ac_ext=c -ac_cpp='$CPP $CPPFLAGS' -ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' -ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' -ac_compiler_gnu=$ac_cv_c_compiler_gnu -if test -n "$ac_tool_prefix"; then - # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args. -set dummy ${ac_tool_prefix}gcc; ac_word=$2 +fi +if test -z "$CC"; then + if test -n "$ac_tool_prefix"; then + for ac_prog in cl.exe + do + # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. +set dummy $ac_tool_prefix$ac_prog; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_CC+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then - ac_cv_prog_CC="${ac_tool_prefix}gcc" + ac_cv_prog_CC="$ac_tool_prefix$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi CC=$ac_cv_prog_CC if test -n "$CC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 $as_echo "$CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi + test -n "$CC" && break + done fi -if test -z "$ac_cv_prog_CC"; then +if test -z "$CC"; then ac_ct_CC=$CC - # Extract the first word of "gcc", so it can be a program name with args. -set dummy gcc; ac_word=$2 + for ac_prog in cl.exe +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_ac_ct_CC+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$ac_ct_CC"; then ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then - ac_cv_prog_ac_ct_CC="gcc" + ac_cv_prog_ac_ct_CC="$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi ac_ct_CC=$ac_cv_prog_ac_ct_CC if test -n "$ac_ct_CC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 $as_echo "$ac_ct_CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi - if test "x$ac_ct_CC" = x; then - CC="" - else - case $cross_compiling:$ac_tool_warned in -yes:) -{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 -$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} -ac_tool_warned=yes ;; -esac - CC=$ac_ct_CC - fi -else - CC="$ac_cv_prog_CC" -fi - -if test -z "$CC"; then - if test -n "$ac_tool_prefix"; then - # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args. -set dummy ${ac_tool_prefix}cc; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_CC+:} false; then : - $as_echo_n "(cached) " >&6 -else - if test -n "$CC"; then - ac_cv_prog_CC="$CC" # Let the user override the test. -else -as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then - ac_cv_prog_CC="${ac_tool_prefix}cc" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 - break 2 - fi -done - done -IFS=$as_save_IFS - -fi -fi -CC=$ac_cv_prog_CC -if test -n "$CC"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 -$as_echo "$CC" >&6; } -else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } -fi - - - fi -fi -if test -z "$CC"; then - # Extract the first word of "cc", so it can be a program name with args. -set dummy cc; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_CC+:} false; then : - $as_echo_n "(cached) " >&6 -else - if test -n "$CC"; then - ac_cv_prog_CC="$CC" # Let the user override the test. -else - ac_prog_rejected=no -as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then - if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then - ac_prog_rejected=yes - continue - fi - ac_cv_prog_CC="cc" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 - break 2 - fi -done - done -IFS=$as_save_IFS - -if test $ac_prog_rejected = yes; then - # We found a bogon in the path, so make sure we never use it. - set dummy $ac_cv_prog_CC - shift - if test $# != 0; then - # We chose a different compiler from the bogus one. - # However, it has the same basename, so the bogon will be chosen - # first if we set CC to just the basename; use the full file name. - shift - ac_cv_prog_CC="$as_dir/$ac_word${1+' '}$@" - fi -fi -fi -fi -CC=$ac_cv_prog_CC -if test -n "$CC"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 -$as_echo "$CC" >&6; } -else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } -fi - - -fi -if test -z "$CC"; then - if test -n "$ac_tool_prefix"; then - for ac_prog in cl.exe - do - # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. -set dummy $ac_tool_prefix$ac_prog; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_CC+:} false; then : - $as_echo_n "(cached) " >&6 -else - if test -n "$CC"; then - ac_cv_prog_CC="$CC" # Let the user override the test. -else -as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then - ac_cv_prog_CC="$ac_tool_prefix$ac_prog" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 - break 2 - fi -done - done -IFS=$as_save_IFS - -fi -fi -CC=$ac_cv_prog_CC -if test -n "$CC"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 -$as_echo "$CC" >&6; } -else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } -fi - - - test -n "$CC" && break - done -fi -if test -z "$CC"; then - ac_ct_CC=$CC - for ac_prog in cl.exe -do - # Extract the first word of "$ac_prog", so it can be a program name with args. -set dummy $ac_prog; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_ac_ct_CC+:} false; then : - $as_echo_n "(cached) " >&6 -else - if test -n "$ac_ct_CC"; then - ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. -else -as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then - ac_cv_prog_ac_ct_CC="$ac_prog" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 - break 2 - fi -done - done -IFS=$as_save_IFS - -fi -fi -ac_ct_CC=$ac_cv_prog_ac_ct_CC -if test -n "$ac_ct_CC"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 -$as_echo "$ac_ct_CC" >&6; } -else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } -fi - - - test -n "$ac_ct_CC" && break -done - + + test -n "$ac_ct_CC" && break +done + if test "x$ac_ct_CC" = x; then CC="" else case $cross_compiling:$ac_tool_warned in yes:) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac CC=$ac_ct_CC fi fi fi test -z "$CC" && { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "no acceptable C compiler found in \$PATH See \`config.log' for more details" "$LINENO" 5; } # Provide some information about the compiler. $as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5 set X $ac_compile ac_compiler=$2 for ac_option in --version -v -V -qversion; do { { ac_try="$ac_compiler $ac_option >&5" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_compiler $ac_option >&5") 2>conftest.err ac_status=$? if test -s conftest.err; then sed '10a\ ... rest of stderr output deleted ... 10q' conftest.err >conftest.er1 cat conftest.er1 >&5 fi rm -f conftest.er1 conftest.err $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } done cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF ac_clean_files_save=$ac_clean_files ac_clean_files="$ac_clean_files a.out a.out.dSYM a.exe b.out" # Try to create an executable without -o first, disregard a.out. # It will help us diagnose broken compilers, and finding out an intuition # of exeext. { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the C compiler works" >&5 $as_echo_n "checking whether the C compiler works... " >&6; } ac_link_default=`$as_echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'` # The possible output files: ac_files="a.out conftest.exe conftest a.exe a_out.exe b.out conftest.*" ac_rmfiles= for ac_file in $ac_files do case $ac_file in *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; * ) ac_rmfiles="$ac_rmfiles $ac_file";; esac done rm -f $ac_rmfiles if { { ac_try="$ac_link_default" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_link_default") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then : # Autoconf-2.13 could set the ac_cv_exeext variable to `no'. # So ignore a value of `no', otherwise this would lead to `EXEEXT = no' # in a Makefile. We should not override ac_cv_exeext if it was cached, # so that the user can short-circuit this test for compilers unknown to # Autoconf. for ac_file in $ac_files '' do test -f "$ac_file" || continue case $ac_file in *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; [ab].out ) # We found the default executable, but exeext='' is most # certainly right. break;; *.* ) if test "${ac_cv_exeext+set}" = set && test "$ac_cv_exeext" != no; then :; else ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` fi # We set ac_cv_exeext here because the later test for it is not # safe: cross compilers may not add the suffix if given an `-o' # argument, so we may need to know it at that point already. # Even if this section looks crufty: it has the advantage of # actually working. break;; * ) break;; esac done test "$ac_cv_exeext" = no && ac_cv_exeext= else ac_file='' fi if test -z "$ac_file"; then : { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error 77 "C compiler cannot create executables See \`config.log' for more details" "$LINENO" 5; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler default output file name" >&5 $as_echo_n "checking for C compiler default output file name... " >&6; } { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_file" >&5 $as_echo "$ac_file" >&6; } ac_exeext=$ac_cv_exeext rm -f -r a.out a.out.dSYM a.exe conftest$ac_cv_exeext b.out ac_clean_files=$ac_clean_files_save { $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of executables" >&5 $as_echo_n "checking for suffix of executables... " >&6; } if { { ac_try="$ac_link" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_link") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then : # If both `conftest.exe' and `conftest' are `present' (well, observable) # catch `conftest.exe'. For instance with Cygwin, `ls conftest' will # work properly (i.e., refer to `conftest.exe'), while it won't with # `rm'. for ac_file in conftest.exe conftest conftest.*; do test -f "$ac_file" || continue case $ac_file in *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` break;; * ) break;; esac done else { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "cannot compute suffix of executables: cannot compile and link See \`config.log' for more details" "$LINENO" 5; } fi rm -f conftest conftest$ac_cv_exeext { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_exeext" >&5 $as_echo "$ac_cv_exeext" >&6; } rm -f conftest.$ac_ext EXEEXT=$ac_cv_exeext ac_exeext=$EXEEXT cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include int main () { FILE *f = fopen ("conftest.out", "w"); return ferror (f) || fclose (f) != 0; ; return 0; } _ACEOF ac_clean_files="$ac_clean_files conftest.out" # Check that the compiler produces executables we can run. If not, either # the compiler is broken, or we cross compile. { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are cross compiling" >&5 $as_echo_n "checking whether we are cross compiling... " >&6; } if test "$cross_compiling" != yes; then { { ac_try="$ac_link" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_link") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } if { ac_try='./conftest$ac_cv_exeext' { { case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_try") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; }; then cross_compiling=no else if test "$cross_compiling" = maybe; then cross_compiling=yes else { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "cannot run C compiled programs. If you meant to cross compile, use \`--host'. See \`config.log' for more details" "$LINENO" 5; } fi fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $cross_compiling" >&5 $as_echo "$cross_compiling" >&6; } rm -f conftest.$ac_ext conftest$ac_cv_exeext conftest.out ac_clean_files=$ac_clean_files_save { $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of object files" >&5 $as_echo_n "checking for suffix of object files... " >&6; } if ${ac_cv_objext+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF rm -f conftest.o conftest.obj if { { ac_try="$ac_compile" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_compile") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then : for ac_file in conftest.o conftest.obj conftest.*; do test -f "$ac_file" || continue; case $ac_file in *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM ) ;; *) ac_cv_objext=`expr "$ac_file" : '.*\.\(.*\)'` break;; esac done else $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "cannot compute suffix of object files: cannot compile See \`config.log' for more details" "$LINENO" 5; } fi rm -f conftest.$ac_cv_objext conftest.$ac_ext fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_objext" >&5 $as_echo "$ac_cv_objext" >&6; } OBJEXT=$ac_cv_objext ac_objext=$OBJEXT { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C compiler" >&5 $as_echo_n "checking whether we are using the GNU C compiler... " >&6; } if ${ac_cv_c_compiler_gnu+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { #ifndef __GNUC__ choke me #endif ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_compiler_gnu=yes else ac_compiler_gnu=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext ac_cv_c_compiler_gnu=$ac_compiler_gnu fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu" >&5 $as_echo "$ac_cv_c_compiler_gnu" >&6; } if test $ac_compiler_gnu = yes; then GCC=yes else GCC= fi ac_test_CFLAGS=${CFLAGS+set} ac_save_CFLAGS=$CFLAGS { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5 $as_echo_n "checking whether $CC accepts -g... " >&6; } if ${ac_cv_prog_cc_g+:} false; then : $as_echo_n "(cached) " >&6 else ac_save_c_werror_flag=$ac_c_werror_flag ac_c_werror_flag=yes ac_cv_prog_cc_g=no CFLAGS="-g" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_prog_cc_g=yes else CFLAGS="" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : else ac_c_werror_flag=$ac_save_c_werror_flag CFLAGS="-g" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_prog_cc_g=yes fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext ac_c_werror_flag=$ac_save_c_werror_flag fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g" >&5 $as_echo "$ac_cv_prog_cc_g" >&6; } if test "$ac_test_CFLAGS" = set; then CFLAGS=$ac_save_CFLAGS elif test $ac_cv_prog_cc_g = yes; then if test "$GCC" = yes; then CFLAGS="-g -O2" else CFLAGS="-g" fi else if test "$GCC" = yes; then CFLAGS="-O2" else CFLAGS= fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CC option to accept ISO C89" >&5 $as_echo_n "checking for $CC option to accept ISO C89... " >&6; } if ${ac_cv_prog_cc_c89+:} false; then : $as_echo_n "(cached) " >&6 else ac_cv_prog_cc_c89=no ac_save_CC=$CC cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include struct stat; /* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ struct buf { int x; }; FILE * (*rcsopen) (struct buf *, struct stat *, int); static char *e (p, i) char **p; int i; { return p[i]; } static char *f (char * (*g) (char **, int), char **p, ...) { char *s; va_list v; va_start (v,p); s = g (p, va_arg (v,int)); va_end (v); return s; } /* OSF 4.0 Compaq cc is some sort of almost-ANSI by default. It has function prototypes and stuff, but not '\xHH' hex character constants. These don't provoke an error unfortunately, instead are silently treated as 'x'. The following induces an error, until -std is added to get proper ANSI mode. Curiously '\x00'!='x' always comes out true, for an array size at least. It's necessary to write '\x00'==0 to get something that's true only with -std. */ int osf4_cc_array ['\x00' == 0 ? 1 : -1]; /* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters inside strings and character constants. */ #define FOO(x) 'x' int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1]; int test (int i, double x); struct s1 {int (*f) (int a);}; struct s2 {int (*f) (double a);}; int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int); int argc; char **argv; int main () { return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]; ; return 0; } _ACEOF for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std \ -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" do CC="$ac_save_CC $ac_arg" if ac_fn_c_try_compile "$LINENO"; then : ac_cv_prog_cc_c89=$ac_arg fi rm -f core conftest.err conftest.$ac_objext test "x$ac_cv_prog_cc_c89" != "xno" && break done rm -f conftest.$ac_ext CC=$ac_save_CC fi # AC_CACHE_VAL case "x$ac_cv_prog_cc_c89" in x) { $as_echo "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 $as_echo "none needed" >&6; } ;; xno) { $as_echo "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 $as_echo "unsupported" >&6; } ;; *) CC="$CC $ac_cv_prog_cc_c89" { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89" >&5 $as_echo "$ac_cv_prog_cc_c89" >&6; } ;; esac if test "x$ac_cv_prog_cc_c89" != xno; then : fi ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu -ac_ext=c -ac_cpp='$CPP $CPPFLAGS' -ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' -ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' -ac_compiler_gnu=$ac_cv_c_compiler_gnu -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to run the C preprocessor" >&5 -$as_echo_n "checking how to run the C preprocessor... " >&6; } -# On Suns, sometimes $CPP names a directory. -if test -n "$CPP" && test -d "$CPP"; then - CPP= -fi -if test -z "$CPP"; then - if ${ac_cv_prog_CPP+:} false; then : - $as_echo_n "(cached) " >&6 -else - # Double quotes because CPP needs to be expanded - for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp" - do - ac_preproc_ok=false -for ac_c_preproc_warn_flag in '' yes -do - # Use a header file that comes with gcc, so configuring glibc - # with a fresh cross-compiler works. - # Prefer to if __STDC__ is defined, since - # exists even on freestanding compilers. - # On the NeXT, cc -E runs the code through the compiler's parser, - # not just through cpp. "Syntax error" is here to catch this case. - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#ifdef __STDC__ -# include -#else -# include -#endif - Syntax error -_ACEOF -if ac_fn_c_try_cpp "$LINENO"; then : -else - # Broken: fails on valid input. -continue -fi -rm -f conftest.err conftest.i conftest.$ac_ext - # OK, works on sane cases. Now check whether nonexistent headers - # can be detected and how. - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#include -_ACEOF -if ac_fn_c_try_cpp "$LINENO"; then : - # Broken: success on invalid input. -continue +# Check whether --with-gnu-ld was given. +if test "${with_gnu_ld+set}" = set; then : + withval=$with_gnu_ld; test "$withval" = no || with_gnu_ld=yes else - # Passes both tests. -ac_preproc_ok=: -break + with_gnu_ld=no fi -rm -f conftest.err conftest.i conftest.$ac_ext -done -# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. -rm -f conftest.i conftest.err conftest.$ac_ext -if $ac_preproc_ok; then : - break +# Prepare PATH_SEPARATOR. +# The user is always right. +if test "${PATH_SEPARATOR+set}" != set; then + # Determine PATH_SEPARATOR by trying to find /bin/sh in a PATH which + # contains only /bin. Note that ksh looks also at the FPATH variable, + # so we have to set that as well for the test. + PATH_SEPARATOR=: + (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 \ + && { (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 \ + || PATH_SEPARATOR=';' + } fi - done - ac_cv_prog_CPP=$CPP - -fi - CPP=$ac_cv_prog_CPP -else - ac_cv_prog_CPP=$CPP -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $CPP" >&5 +ac_prog=ld +if test "$GCC" = yes; then + # Check if gcc -print-prog-name=ld gives a path. + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ld used by $CC" >&5 +$as_echo_n "checking for ld used by $CC... " >&6; } + case $host in + *-*-mingw*) + # gcc leaves a trailing carriage return which upsets mingw + ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;; + *) + ac_prog=`($CC -print-prog-name=ld) 2>&5` ;; + esac + case $ac_prog in + # Accept absolute paths. + [\\/]* | ?:[\\/]*) + re_direlt='/[^/][^/]*/\.\./' + # Canonicalize the pathname of ld + ac_prog=`echo "$ac_prog"| sed 's%\\\\%/%g'` + while echo "$ac_prog" | grep "$re_direlt" > /dev/null 2>&1; do + ac_prog=`echo $ac_prog| sed "s%$re_direlt%/%"` + done + test -z "$LD" && LD="$ac_prog" + ;; + "") + # If it fails, then pretend we aren't using GCC. + ac_prog=ld + ;; + *) + # If it is relative, then search for the first ld in PATH. + with_gnu_ld=unknown + ;; + esac +elif test "$with_gnu_ld" = yes; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GNU ld" >&5 +$as_echo_n "checking for GNU ld... " >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for non-GNU ld" >&5 +$as_echo_n "checking for non-GNU ld... " >&6; } +fi +if ${acl_cv_path_LD+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -z "$LD"; then + acl_save_ifs="$IFS"; IFS=$PATH_SEPARATOR + for ac_dir in $PATH; do + IFS="$acl_save_ifs" + test -z "$ac_dir" && ac_dir=. + if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then + acl_cv_path_LD="$ac_dir/$ac_prog" + # Check to see if the program is GNU ld. I'd rather use --version, + # but apparently some variants of GNU ld only accept -v. + # Break only if it was the GNU/non-GNU ld that we prefer. + case `"$acl_cv_path_LD" -v 2>&1 &5 +$as_echo "$LD" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi +test -z "$LD" && as_fn_error $? "no acceptable ld found in \$PATH" "$LINENO" 5 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if the linker ($LD) is GNU ld" >&5 +$as_echo_n "checking if the linker ($LD) is GNU ld... " >&6; } +if ${acl_cv_prog_gnu_ld+:} false; then : + $as_echo_n "(cached) " >&6 +else + # I'd rather use --version here, but apparently some GNU lds only accept -v. +case `$LD -v 2>&1 &5 +$as_echo "$acl_cv_prog_gnu_ld" >&6; } +with_gnu_ld=$acl_cv_prog_gnu_ld + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for shared library run path origin" >&5 +$as_echo_n "checking for shared library run path origin... " >&6; } +if ${acl_cv_rpath+:} false; then : + $as_echo_n "(cached) " >&6 +else + + CC="$CC" GCC="$GCC" LDFLAGS="$LDFLAGS" LD="$LD" with_gnu_ld="$with_gnu_ld" \ + ${CONFIG_SHELL-/bin/sh} "$ac_aux_dir/config.rpath" "$host" > conftest.sh + . ./conftest.sh + rm -f ./conftest.sh + acl_cv_rpath=done + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $acl_cv_rpath" >&5 +$as_echo "$acl_cv_rpath" >&6; } + wl="$acl_cv_wl" + acl_libext="$acl_cv_libext" + acl_shlibext="$acl_cv_shlibext" + acl_libname_spec="$acl_cv_libname_spec" + acl_library_names_spec="$acl_cv_library_names_spec" + acl_hardcode_libdir_flag_spec="$acl_cv_hardcode_libdir_flag_spec" + acl_hardcode_libdir_separator="$acl_cv_hardcode_libdir_separator" + acl_hardcode_direct="$acl_cv_hardcode_direct" + acl_hardcode_minus_L="$acl_cv_hardcode_minus_L" + # Check whether --enable-rpath was given. +if test "${enable_rpath+set}" = set; then : + enableval=$enable_rpath; : +else + enable_rpath=yes +fi + + + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to run the C preprocessor" >&5 +$as_echo_n "checking how to run the C preprocessor... " >&6; } +# On Suns, sometimes $CPP names a directory. +if test -n "$CPP" && test -d "$CPP"; then + CPP= +fi +if test -z "$CPP"; then + if ${ac_cv_prog_CPP+:} false; then : + $as_echo_n "(cached) " >&6 +else + # Double quotes because CPP needs to be expanded + for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp" + do + ac_preproc_ok=false +for ac_c_preproc_warn_flag in '' yes +do + # Use a header file that comes with gcc, so configuring glibc + # with a fresh cross-compiler works. + # Prefer to if __STDC__ is defined, since + # exists even on freestanding compilers. + # On the NeXT, cc -E runs the code through the compiler's parser, + # not just through cpp. "Syntax error" is here to catch this case. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#ifdef __STDC__ +# include +#else +# include +#endif + Syntax error +_ACEOF +if ac_fn_c_try_cpp "$LINENO"; then : + +else + # Broken: fails on valid input. +continue +fi +rm -f conftest.err conftest.i conftest.$ac_ext + + # OK, works on sane cases. Now check whether nonexistent headers + # can be detected and how. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +_ACEOF +if ac_fn_c_try_cpp "$LINENO"; then : + # Broken: success on invalid input. +continue +else + # Passes both tests. +ac_preproc_ok=: +break +fi +rm -f conftest.err conftest.i conftest.$ac_ext + +done +# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. +rm -f conftest.i conftest.err conftest.$ac_ext +if $ac_preproc_ok; then : + break +fi + + done + ac_cv_prog_CPP=$CPP + +fi + CPP=$ac_cv_prog_CPP +else + ac_cv_prog_CPP=$CPP +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $CPP" >&5 $as_echo "$CPP" >&6; } ac_preproc_ok=false for ac_c_preproc_warn_flag in '' yes do # Use a header file that comes with gcc, so configuring glibc # with a fresh cross-compiler works. # Prefer to if __STDC__ is defined, since # exists even on freestanding compilers. # On the NeXT, cc -E runs the code through the compiler's parser, # not just through cpp. "Syntax error" is here to catch this case. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #ifdef __STDC__ # include #else # include #endif Syntax error _ACEOF if ac_fn_c_try_cpp "$LINENO"; then : else # Broken: fails on valid input. continue fi rm -f conftest.err conftest.i conftest.$ac_ext # OK, works on sane cases. Now check whether nonexistent headers # can be detected and how. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include _ACEOF if ac_fn_c_try_cpp "$LINENO"; then : # Broken: success on invalid input. continue else # Passes both tests. ac_preproc_ok=: break fi rm -f conftest.err conftest.i conftest.$ac_ext done # Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. rm -f conftest.i conftest.err conftest.$ac_ext if $ac_preproc_ok; then : else { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "C preprocessor \"$CPP\" fails sanity check See \`config.log' for more details" "$LINENO" 5; } fi ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for grep that handles long lines and -e" >&5 $as_echo_n "checking for grep that handles long lines and -e... " >&6; } if ${ac_cv_path_GREP+:} false; then : $as_echo_n "(cached) " >&6 else if test -z "$GREP"; then ac_path_GREP_found=false # Loop through the user's path and test for each of PROGNAME-LIST as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_prog in grep ggrep; do for ac_exec_ext in '' $ac_executable_extensions; do ac_path_GREP="$as_dir/$ac_prog$ac_exec_ext" as_fn_executable_p "$ac_path_GREP" || continue # Check for GNU ac_path_GREP and select it if it is found. # Check for GNU $ac_path_GREP case `"$ac_path_GREP" --version 2>&1` in *GNU*) ac_cv_path_GREP="$ac_path_GREP" ac_path_GREP_found=:;; *) ac_count=0 $as_echo_n 0123456789 >"conftest.in" while : do cat "conftest.in" "conftest.in" >"conftest.tmp" mv "conftest.tmp" "conftest.in" cp "conftest.in" "conftest.nl" $as_echo 'GREP' >> "conftest.nl" "$ac_path_GREP" -e 'GREP$' -e '-(cannot match)-' < "conftest.nl" >"conftest.out" 2>/dev/null || break diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break as_fn_arith $ac_count + 1 && ac_count=$as_val if test $ac_count -gt ${ac_path_GREP_max-0}; then # Best one so far, save it but keep looking for a better one ac_cv_path_GREP="$ac_path_GREP" ac_path_GREP_max=$ac_count fi # 10*(2^10) chars as input seems more than enough test $ac_count -gt 10 && break done rm -f conftest.in conftest.tmp conftest.nl conftest.out;; esac $ac_path_GREP_found && break 3 done done done IFS=$as_save_IFS if test -z "$ac_cv_path_GREP"; then as_fn_error $? "no acceptable grep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5 fi else ac_cv_path_GREP=$GREP fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_GREP" >&5 $as_echo "$ac_cv_path_GREP" >&6; } GREP="$ac_cv_path_GREP" { $as_echo "$as_me:${as_lineno-$LINENO}: checking for egrep" >&5 $as_echo_n "checking for egrep... " >&6; } if ${ac_cv_path_EGREP+:} false; then : $as_echo_n "(cached) " >&6 else if echo a | $GREP -E '(a|b)' >/dev/null 2>&1 then ac_cv_path_EGREP="$GREP -E" else if test -z "$EGREP"; then ac_path_EGREP_found=false # Loop through the user's path and test for each of PROGNAME-LIST as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_prog in egrep; do for ac_exec_ext in '' $ac_executable_extensions; do ac_path_EGREP="$as_dir/$ac_prog$ac_exec_ext" as_fn_executable_p "$ac_path_EGREP" || continue # Check for GNU ac_path_EGREP and select it if it is found. # Check for GNU $ac_path_EGREP case `"$ac_path_EGREP" --version 2>&1` in *GNU*) ac_cv_path_EGREP="$ac_path_EGREP" ac_path_EGREP_found=:;; *) ac_count=0 $as_echo_n 0123456789 >"conftest.in" while : do cat "conftest.in" "conftest.in" >"conftest.tmp" mv "conftest.tmp" "conftest.in" cp "conftest.in" "conftest.nl" $as_echo 'EGREP' >> "conftest.nl" "$ac_path_EGREP" 'EGREP$' < "conftest.nl" >"conftest.out" 2>/dev/null || break diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break as_fn_arith $ac_count + 1 && ac_count=$as_val if test $ac_count -gt ${ac_path_EGREP_max-0}; then # Best one so far, save it but keep looking for a better one ac_cv_path_EGREP="$ac_path_EGREP" ac_path_EGREP_max=$ac_count fi # 10*(2^10) chars as input seems more than enough test $ac_count -gt 10 && break done rm -f conftest.in conftest.tmp conftest.nl conftest.out;; esac $ac_path_EGREP_found && break 3 done done done IFS=$as_save_IFS if test -z "$ac_cv_path_EGREP"; then as_fn_error $? "no acceptable egrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5 fi else ac_cv_path_EGREP=$EGREP fi fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_EGREP" >&5 $as_echo "$ac_cv_path_EGREP" >&6; } EGREP="$ac_cv_path_EGREP" -if test $ac_cv_c_compiler_gnu = yes; then - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC needs -traditional" >&5 -$as_echo_n "checking whether $CC needs -traditional... " >&6; } -if ${ac_cv_prog_gcc_traditional+:} false; then : + + + acl_libdirstem=lib + acl_libdirstem2= + case "$host_os" in + solaris*) + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for 64-bit host" >&5 +$as_echo_n "checking for 64-bit host... " >&6; } +if ${gl_cv_solaris_64bit+:} false; then : $as_echo_n "(cached) " >&6 else - ac_pattern="Autoconf.*'x'" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ -#include -Autoconf TIOCGETP -_ACEOF -if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | - $EGREP "$ac_pattern" >/dev/null 2>&1; then : - ac_cv_prog_gcc_traditional=yes -else - ac_cv_prog_gcc_traditional=no -fi -rm -f conftest* +#ifdef _LP64 +sixtyfour bits +#endif - if test $ac_cv_prog_gcc_traditional = no; then - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#include -Autoconf TCGETA _ACEOF if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | - $EGREP "$ac_pattern" >/dev/null 2>&1; then : - ac_cv_prog_gcc_traditional=yes + $EGREP "sixtyfour bits" >/dev/null 2>&1; then : + gl_cv_solaris_64bit=yes +else + gl_cv_solaris_64bit=no fi rm -f conftest* - fi -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_gcc_traditional" >&5 -$as_echo "$ac_cv_prog_gcc_traditional" >&6; } - if test $ac_cv_prog_gcc_traditional = yes; then - CC="$CC -traditional" - fi -fi - -# Extract the first word of "gencat", so it can be a program name with args. -set dummy gencat; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_path_GENCAT+:} false; then : - $as_echo_n "(cached) " >&6 -else - case $GENCAT in - [\\/]* | ?:[\\/]*) - ac_cv_path_GENCAT="$GENCAT" # Let the user override the test with a path. - ;; - *) - as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then - ac_cv_path_GENCAT="$as_dir/$ac_word$ac_exec_ext" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 - break 2 - fi -done - done -IFS=$as_save_IFS - - ;; -esac -fi -GENCAT=$ac_cv_path_GENCAT -if test -n "$GENCAT"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $GENCAT" >&5 -$as_echo "$GENCAT" >&6; } -else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_cv_solaris_64bit" >&5 +$as_echo "$gl_cv_solaris_64bit" >&6; } + if test $gl_cv_solaris_64bit = yes; then + acl_libdirstem=lib/64 + case "$host_cpu" in + sparc*) acl_libdirstem2=lib/sparcv9 ;; + i*86 | x86_64) acl_libdirstem2=lib/amd64 ;; + esac + fi + ;; + *) + searchpath=`(LC_ALL=C $CC -print-search-dirs) 2>/dev/null | sed -n -e 's,^libraries: ,,p' | sed -e 's,^=,,'` + if test -n "$searchpath"; then + acl_save_IFS="${IFS= }"; IFS=":" + for searchdir in $searchpath; do + if test -d "$searchdir"; then + case "$searchdir" in + */lib64/ | */lib64 ) acl_libdirstem=lib64 ;; + */../ | */.. ) + # Better ignore directories of this form. They are misleading. + ;; + *) searchdir=`cd "$searchdir" && pwd` + case "$searchdir" in + */lib64 ) acl_libdirstem=lib64 ;; + esac ;; + esac + fi + done + IFS="$acl_save_IFS" + fi + ;; + esac + test -n "$acl_libdirstem2" || acl_libdirstem2="$acl_libdirstem" -if test "x${cross_compiling}" = xyes ; then - CC_FOR_GETHOST="cc" -else - CC_FOR_GETHOST="\$(CC)" -fi -if test "x$GCC" != xyes ; then - DFLAGS="$DFLAGS $NON_GNU_DFLAGS" - CFLAGS="$CFLAGS $NON_GNU_CFLAGS" -fi -case "${host}" in - *-*-android*) - CFLAGS="${CFLAGS} -fPIE" - LDFLAGS="${LDFLAGS} -pie" - ;; -esac -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing crypt" >&5 -$as_echo_n "checking for library containing crypt... " >&6; } -if ${ac_cv_search_crypt+:} false; then : - $as_echo_n "(cached) " >&6 -else - ac_func_search_save_LIBS=$LIBS -cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char crypt (); -int -main () -{ -return crypt (); - ; - return 0; -} -_ACEOF -for ac_lib in '' crypt; do - if test -z "$ac_lib"; then - ac_res="none required" - else - ac_res=-l$ac_lib - LIBS="-l$ac_lib $ac_func_search_save_LIBS" - fi - if ac_fn_c_try_link "$LINENO"; then : - ac_cv_search_crypt=$ac_res -fi -rm -f core conftest.err conftest.$ac_objext \ - conftest$ac_exeext - if ${ac_cv_search_crypt+:} false; then : - break -fi -done -if ${ac_cv_search_crypt+:} false; then : -else - ac_cv_search_crypt=no -fi -rm conftest.$ac_ext -LIBS=$ac_func_search_save_LIBS -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_crypt" >&5 -$as_echo "$ac_cv_search_crypt" >&6; } -ac_res=$ac_cv_search_crypt -if test "$ac_res" != no; then : - test "$ac_res" = "none required" || LIBS="$ac_res $LIBS" -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing getspnam" >&5 -$as_echo_n "checking for library containing getspnam... " >&6; } -if ${ac_cv_search_getspnam+:} false; then : - $as_echo_n "(cached) " >&6 -else - ac_func_search_save_LIBS=$LIBS -cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char getspnam (); -int -main () -{ -return getspnam (); - ; - return 0; -} -_ACEOF -for ac_lib in '' sec; do - if test -z "$ac_lib"; then - ac_res="none required" - else - ac_res=-l$ac_lib - LIBS="-l$ac_lib $ac_func_search_save_LIBS" - fi - if ac_fn_c_try_link "$LINENO"; then : - ac_cv_search_getspnam=$ac_res -fi -rm -f core conftest.err conftest.$ac_objext \ - conftest$ac_exeext - if ${ac_cv_search_getspnam+:} false; then : - break -fi -done -if ${ac_cv_search_getspnam+:} false; then : + use_additional=yes -else - ac_cv_search_getspnam=no -fi -rm conftest.$ac_ext -LIBS=$ac_func_search_save_LIBS -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_getspnam" >&5 -$as_echo "$ac_cv_search_getspnam" >&6; } -ac_res=$ac_cv_search_getspnam -if test "$ac_res" != no; then : - test "$ac_res" = "none required" || LIBS="$ac_res $LIBS" + acl_save_prefix="$prefix" + prefix="$acl_final_prefix" + acl_save_exec_prefix="$exec_prefix" + exec_prefix="$acl_final_exec_prefix" -fi + eval additional_includedir=\"$includedir\" + eval additional_libdir=\"$libdir\" -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing tgetent" >&5 -$as_echo_n "checking for library containing tgetent... " >&6; } -if ${ac_cv_search_tgetent+:} false; then : - $as_echo_n "(cached) " >&6 -else - ac_func_search_save_LIBS=$LIBS -cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ + exec_prefix="$acl_save_exec_prefix" + prefix="$acl_save_prefix" -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char tgetent (); -int -main () -{ -return tgetent (); - ; - return 0; -} -_ACEOF -for ac_lib in '' termlib tinfo termcap curses ncurses; do - if test -z "$ac_lib"; then - ac_res="none required" - else - ac_res=-l$ac_lib - LIBS="-l$ac_lib $ac_func_search_save_LIBS" - fi - if ac_fn_c_try_link "$LINENO"; then : - ac_cv_search_tgetent=$ac_res -fi -rm -f core conftest.err conftest.$ac_objext \ - conftest$ac_exeext - if ${ac_cv_search_tgetent+:} false; then : - break -fi -done -if ${ac_cv_search_tgetent+:} false; then : -else - ac_cv_search_tgetent=no -fi -rm conftest.$ac_ext -LIBS=$ac_func_search_save_LIBS -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_tgetent" >&5 -$as_echo "$ac_cv_search_tgetent" >&6; } -ac_res=$ac_cv_search_tgetent -if test "$ac_res" != no; then : - test "$ac_res" = "none required" || LIBS="$ac_res $LIBS" +# Check whether --with-libiconv-prefix was given. +if test "${with_libiconv_prefix+set}" = set; then : + withval=$with_libiconv_prefix; + if test "X$withval" = "Xno"; then + use_additional=no + else + if test "X$withval" = "X"; then -else - - as_fn_error $? "unable to find the tgetent() function" "$LINENO" 5 - -fi - -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing gethostbyname" >&5 -$as_echo_n "checking for library containing gethostbyname... " >&6; } -if ${ac_cv_search_gethostbyname+:} false; then : - $as_echo_n "(cached) " >&6 -else - ac_func_search_save_LIBS=$LIBS -cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char gethostbyname (); -int -main () -{ -return gethostbyname (); - ; - return 0; -} -_ACEOF -for ac_lib in '' nsl; do - if test -z "$ac_lib"; then - ac_res="none required" - else - ac_res=-l$ac_lib - LIBS="-l$ac_lib $ac_func_search_save_LIBS" - fi - if ac_fn_c_try_link "$LINENO"; then : - ac_cv_search_gethostbyname=$ac_res -fi -rm -f core conftest.err conftest.$ac_objext \ - conftest$ac_exeext - if ${ac_cv_search_gethostbyname+:} false; then : - break -fi -done -if ${ac_cv_search_gethostbyname+:} false; then : - -else - ac_cv_search_gethostbyname=no -fi -rm conftest.$ac_ext -LIBS=$ac_func_search_save_LIBS -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_gethostbyname" >&5 -$as_echo "$ac_cv_search_gethostbyname" >&6; } -ac_res=$ac_cv_search_gethostbyname -if test "$ac_res" != no; then : - test "$ac_res" = "none required" || LIBS="$ac_res $LIBS" - -fi - -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing connect" >&5 -$as_echo_n "checking for library containing connect... " >&6; } -if ${ac_cv_search_connect+:} false; then : - $as_echo_n "(cached) " >&6 -else - ac_func_search_save_LIBS=$LIBS -cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char connect (); -int -main () -{ -return connect (); - ; - return 0; -} -_ACEOF -for ac_lib in '' socket; do - if test -z "$ac_lib"; then - ac_res="none required" - else - ac_res=-l$ac_lib - LIBS="-l$ac_lib $ac_func_search_save_LIBS" - fi - if ac_fn_c_try_link "$LINENO"; then : - ac_cv_search_connect=$ac_res -fi -rm -f core conftest.err conftest.$ac_objext \ - conftest$ac_exeext - if ${ac_cv_search_connect+:} false; then : - break -fi -done -if ${ac_cv_search_connect+:} false; then : - -else - ac_cv_search_connect=no -fi -rm conftest.$ac_ext -LIBS=$ac_func_search_save_LIBS -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_connect" >&5 -$as_echo "$ac_cv_search_connect" >&6; } -ac_res=$ac_cv_search_connect -if test "$ac_res" != no; then : - test "$ac_res" = "none required" || LIBS="$ac_res $LIBS" - -fi - -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing catgets" >&5 -$as_echo_n "checking for library containing catgets... " >&6; } -if ${ac_cv_search_catgets+:} false; then : - $as_echo_n "(cached) " >&6 -else - ac_func_search_save_LIBS=$LIBS -cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char catgets (); -int -main () -{ -return catgets (); - ; - return 0; -} -_ACEOF -for ac_lib in '' catgets; do - if test -z "$ac_lib"; then - ac_res="none required" - else - ac_res=-l$ac_lib - LIBS="-l$ac_lib $ac_func_search_save_LIBS" - fi - if ac_fn_c_try_link "$LINENO"; then : - ac_cv_search_catgets=$ac_res -fi -rm -f core conftest.err conftest.$ac_objext \ - conftest$ac_exeext - if ${ac_cv_search_catgets+:} false; then : - break -fi -done -if ${ac_cv_search_catgets+:} false; then : - -else - ac_cv_search_catgets=no -fi -rm conftest.$ac_ext -LIBS=$ac_func_search_save_LIBS -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_catgets" >&5 -$as_echo "$ac_cv_search_catgets" >&6; } -ac_res=$ac_cv_search_catgets -if test "$ac_res" != no; then : - test "$ac_res" = "none required" || LIBS="$ac_res $LIBS" - -fi - - - if test "X$prefix" = "XNONE"; then - acl_final_prefix="$ac_default_prefix" - else - acl_final_prefix="$prefix" - fi - if test "X$exec_prefix" = "XNONE"; then - acl_final_exec_prefix='${prefix}' - else - acl_final_exec_prefix="$exec_prefix" - fi acl_save_prefix="$prefix" prefix="$acl_final_prefix" - eval acl_final_exec_prefix=\"$acl_final_exec_prefix\" - prefix="$acl_save_prefix" + acl_save_exec_prefix="$exec_prefix" + exec_prefix="$acl_final_exec_prefix" + eval additional_includedir=\"$includedir\" + eval additional_libdir=\"$libdir\" + exec_prefix="$acl_save_exec_prefix" + prefix="$acl_save_prefix" -# Check whether --with-gnu-ld was given. -if test "${with_gnu_ld+set}" = set; then : - withval=$with_gnu_ld; test "$withval" = no || with_gnu_ld=yes -else - with_gnu_ld=no -fi - -# Prepare PATH_SEPARATOR. -# The user is always right. -if test "${PATH_SEPARATOR+set}" != set; then - # Determine PATH_SEPARATOR by trying to find /bin/sh in a PATH which - # contains only /bin. Note that ksh looks also at the FPATH variable, - # so we have to set that as well for the test. - PATH_SEPARATOR=: - (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 \ - && { (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 \ - || PATH_SEPARATOR=';' - } -fi - -ac_prog=ld -if test "$GCC" = yes; then - # Check if gcc -print-prog-name=ld gives a path. - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ld used by $CC" >&5 -$as_echo_n "checking for ld used by $CC... " >&6; } - case $host in - *-*-mingw*) - # gcc leaves a trailing carriage return which upsets mingw - ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;; - *) - ac_prog=`($CC -print-prog-name=ld) 2>&5` ;; - esac - case $ac_prog in - # Accept absolute paths. - [\\/]* | ?:[\\/]*) - re_direlt='/[^/][^/]*/\.\./' - # Canonicalize the pathname of ld - ac_prog=`echo "$ac_prog"| sed 's%\\\\%/%g'` - while echo "$ac_prog" | grep "$re_direlt" > /dev/null 2>&1; do - ac_prog=`echo $ac_prog| sed "s%$re_direlt%/%"` - done - test -z "$LD" && LD="$ac_prog" - ;; - "") - # If it fails, then pretend we aren't using GCC. - ac_prog=ld - ;; - *) - # If it is relative, then search for the first ld in PATH. - with_gnu_ld=unknown - ;; - esac -elif test "$with_gnu_ld" = yes; then - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GNU ld" >&5 -$as_echo_n "checking for GNU ld... " >&6; } -else - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for non-GNU ld" >&5 -$as_echo_n "checking for non-GNU ld... " >&6; } -fi -if ${acl_cv_path_LD+:} false; then : - $as_echo_n "(cached) " >&6 -else - if test -z "$LD"; then - acl_save_ifs="$IFS"; IFS=$PATH_SEPARATOR - for ac_dir in $PATH; do - IFS="$acl_save_ifs" - test -z "$ac_dir" && ac_dir=. - if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then - acl_cv_path_LD="$ac_dir/$ac_prog" - # Check to see if the program is GNU ld. I'd rather use --version, - # but apparently some variants of GNU ld only accept -v. - # Break only if it was the GNU/non-GNU ld that we prefer. - case `"$acl_cv_path_LD" -v 2>&1 &5 -$as_echo "$LD" >&6; } -else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } -fi -test -z "$LD" && as_fn_error $? "no acceptable ld found in \$PATH" "$LINENO" 5 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if the linker ($LD) is GNU ld" >&5 -$as_echo_n "checking if the linker ($LD) is GNU ld... " >&6; } -if ${acl_cv_prog_gnu_ld+:} false; then : - $as_echo_n "(cached) " >&6 -else - # I'd rather use --version here, but apparently some GNU lds only accept -v. -case `$LD -v 2>&1 &5 -$as_echo "$acl_cv_prog_gnu_ld" >&6; } -with_gnu_ld=$acl_cv_prog_gnu_ld - - - - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for shared library run path origin" >&5 -$as_echo_n "checking for shared library run path origin... " >&6; } -if ${acl_cv_rpath+:} false; then : - $as_echo_n "(cached) " >&6 -else - - CC="$CC" GCC="$GCC" LDFLAGS="$LDFLAGS" LD="$LD" with_gnu_ld="$with_gnu_ld" \ - ${CONFIG_SHELL-/bin/sh} "$ac_aux_dir/config.rpath" "$host" > conftest.sh - . ./conftest.sh - rm -f ./conftest.sh - acl_cv_rpath=done - -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $acl_cv_rpath" >&5 -$as_echo "$acl_cv_rpath" >&6; } - wl="$acl_cv_wl" - acl_libext="$acl_cv_libext" - acl_shlibext="$acl_cv_shlibext" - acl_libname_spec="$acl_cv_libname_spec" - acl_library_names_spec="$acl_cv_library_names_spec" - acl_hardcode_libdir_flag_spec="$acl_cv_hardcode_libdir_flag_spec" - acl_hardcode_libdir_separator="$acl_cv_hardcode_libdir_separator" - acl_hardcode_direct="$acl_cv_hardcode_direct" - acl_hardcode_minus_L="$acl_cv_hardcode_minus_L" - # Check whether --enable-rpath was given. -if test "${enable_rpath+set}" = set; then : - enableval=$enable_rpath; : -else - enable_rpath=yes -fi - - - - - acl_libdirstem=lib - acl_libdirstem2= - case "$host_os" in - solaris*) - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for 64-bit host" >&5 -$as_echo_n "checking for 64-bit host... " >&6; } -if ${gl_cv_solaris_64bit+:} false; then : - $as_echo_n "(cached) " >&6 -else - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -#ifdef _LP64 -sixtyfour bits -#endif - -_ACEOF -if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | - $EGREP "sixtyfour bits" >/dev/null 2>&1; then : - gl_cv_solaris_64bit=yes -else - gl_cv_solaris_64bit=no -fi -rm -f conftest* - - -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_cv_solaris_64bit" >&5 -$as_echo "$gl_cv_solaris_64bit" >&6; } - if test $gl_cv_solaris_64bit = yes; then - acl_libdirstem=lib/64 - case "$host_cpu" in - sparc*) acl_libdirstem2=lib/sparcv9 ;; - i*86 | x86_64) acl_libdirstem2=lib/amd64 ;; - esac - fi - ;; - *) - searchpath=`(LC_ALL=C $CC -print-search-dirs) 2>/dev/null | sed -n -e 's,^libraries: ,,p' | sed -e 's,^=,,'` - if test -n "$searchpath"; then - acl_save_IFS="${IFS= }"; IFS=":" - for searchdir in $searchpath; do - if test -d "$searchdir"; then - case "$searchdir" in - */lib64/ | */lib64 ) acl_libdirstem=lib64 ;; - */../ | */.. ) - # Better ignore directories of this form. They are misleading. - ;; - *) searchdir=`cd "$searchdir" && pwd` - case "$searchdir" in - */lib64 ) acl_libdirstem=lib64 ;; - esac ;; - esac - fi - done - IFS="$acl_save_IFS" - fi - ;; - esac - test -n "$acl_libdirstem2" || acl_libdirstem2="$acl_libdirstem" - - - - - - - - - - - - - use_additional=yes - - acl_save_prefix="$prefix" - prefix="$acl_final_prefix" - acl_save_exec_prefix="$exec_prefix" - exec_prefix="$acl_final_exec_prefix" - - eval additional_includedir=\"$includedir\" - eval additional_libdir=\"$libdir\" - - exec_prefix="$acl_save_exec_prefix" - prefix="$acl_save_prefix" - - -# Check whether --with-libiconv-prefix was given. -if test "${with_libiconv_prefix+set}" = set; then : - withval=$with_libiconv_prefix; - if test "X$withval" = "Xno"; then - use_additional=no - else - if test "X$withval" = "X"; then - - acl_save_prefix="$prefix" - prefix="$acl_final_prefix" - acl_save_exec_prefix="$exec_prefix" - exec_prefix="$acl_final_exec_prefix" - - eval additional_includedir=\"$includedir\" - eval additional_libdir=\"$libdir\" - - exec_prefix="$acl_save_exec_prefix" - prefix="$acl_save_prefix" - - else - additional_includedir="$withval/include" - additional_libdir="$withval/$acl_libdirstem" - if test "$acl_libdirstem2" != "$acl_libdirstem" \ - && ! test -d "$withval/$acl_libdirstem"; then - additional_libdir="$withval/$acl_libdirstem2" - fi - fi - fi + else + additional_includedir="$withval/include" + additional_libdir="$withval/$acl_libdirstem" + if test "$acl_libdirstem2" != "$acl_libdirstem" \ + && ! test -d "$withval/$acl_libdirstem"; then + additional_libdir="$withval/$acl_libdirstem2" + fi + fi + fi fi LIBICONV= LTLIBICONV= INCICONV= LIBICONV_PREFIX= HAVE_LIBICONV= rpathdirs= ltrpathdirs= names_already_handled= names_next_round='iconv ' while test -n "$names_next_round"; do names_this_round="$names_next_round" names_next_round= for name in $names_this_round; do already_handled= for n in $names_already_handled; do if test "$n" = "$name"; then already_handled=yes break fi done if test -z "$already_handled"; then names_already_handled="$names_already_handled $name" uppername=`echo "$name" | sed -e 'y|abcdefghijklmnopqrstuvwxyz./+-|ABCDEFGHIJKLMNOPQRSTUVWXYZ____|'` eval value=\"\$HAVE_LIB$uppername\" if test -n "$value"; then if test "$value" = yes; then eval value=\"\$LIB$uppername\" test -z "$value" || LIBICONV="${LIBICONV}${LIBICONV:+ }$value" eval value=\"\$LTLIB$uppername\" test -z "$value" || LTLIBICONV="${LTLIBICONV}${LTLIBICONV:+ }$value" else : fi else found_dir= found_la= found_so= found_a= eval libname=\"$acl_libname_spec\" # typically: libname=lib$name if test -n "$acl_shlibext"; then shrext=".$acl_shlibext" # typically: shrext=.so else shrext= fi if test $use_additional = yes; then dir="$additional_libdir" if test -n "$acl_shlibext"; then if test -f "$dir/$libname$shrext"; then found_dir="$dir" found_so="$dir/$libname$shrext" else if test "$acl_library_names_spec" = '$libname$shrext$versuffix'; then ver=`(cd "$dir" && \ for f in "$libname$shrext".*; do echo "$f"; done \ | sed -e "s,^$libname$shrext\\\\.,," \ | sort -t '.' -n -r -k1,1 -k2,2 -k3,3 -k4,4 -k5,5 \ | sed 1q ) 2>/dev/null` if test -n "$ver" && test -f "$dir/$libname$shrext.$ver"; then found_dir="$dir" found_so="$dir/$libname$shrext.$ver" fi else eval library_names=\"$acl_library_names_spec\" for f in $library_names; do if test -f "$dir/$f"; then found_dir="$dir" found_so="$dir/$f" break fi done fi fi fi if test "X$found_dir" = "X"; then if test -f "$dir/$libname.$acl_libext"; then found_dir="$dir" found_a="$dir/$libname.$acl_libext" fi fi if test "X$found_dir" != "X"; then if test -f "$dir/$libname.la"; then found_la="$dir/$libname.la" fi fi fi if test "X$found_dir" = "X"; then for x in $LDFLAGS $LTLIBICONV; do acl_save_prefix="$prefix" prefix="$acl_final_prefix" acl_save_exec_prefix="$exec_prefix" exec_prefix="$acl_final_exec_prefix" eval x=\"$x\" exec_prefix="$acl_save_exec_prefix" prefix="$acl_save_prefix" case "$x" in -L*) dir=`echo "X$x" | sed -e 's/^X-L//'` if test -n "$acl_shlibext"; then if test -f "$dir/$libname$shrext"; then found_dir="$dir" found_so="$dir/$libname$shrext" else if test "$acl_library_names_spec" = '$libname$shrext$versuffix'; then ver=`(cd "$dir" && \ for f in "$libname$shrext".*; do echo "$f"; done \ | sed -e "s,^$libname$shrext\\\\.,," \ | sort -t '.' -n -r -k1,1 -k2,2 -k3,3 -k4,4 -k5,5 \ | sed 1q ) 2>/dev/null` if test -n "$ver" && test -f "$dir/$libname$shrext.$ver"; then found_dir="$dir" found_so="$dir/$libname$shrext.$ver" fi else eval library_names=\"$acl_library_names_spec\" for f in $library_names; do if test -f "$dir/$f"; then found_dir="$dir" found_so="$dir/$f" break fi done fi fi fi if test "X$found_dir" = "X"; then if test -f "$dir/$libname.$acl_libext"; then found_dir="$dir" found_a="$dir/$libname.$acl_libext" fi fi if test "X$found_dir" != "X"; then if test -f "$dir/$libname.la"; then found_la="$dir/$libname.la" fi fi ;; esac if test "X$found_dir" != "X"; then break fi done fi if test "X$found_dir" != "X"; then LTLIBICONV="${LTLIBICONV}${LTLIBICONV:+ }-L$found_dir -l$name" if test "X$found_so" != "X"; then if test "$enable_rpath" = no \ || test "X$found_dir" = "X/usr/$acl_libdirstem" \ || test "X$found_dir" = "X/usr/$acl_libdirstem2"; then LIBICONV="${LIBICONV}${LIBICONV:+ }$found_so" else haveit= for x in $ltrpathdirs; do if test "X$x" = "X$found_dir"; then haveit=yes break fi done if test -z "$haveit"; then ltrpathdirs="$ltrpathdirs $found_dir" fi if test "$acl_hardcode_direct" = yes; then LIBICONV="${LIBICONV}${LIBICONV:+ }$found_so" else if test -n "$acl_hardcode_libdir_flag_spec" && test "$acl_hardcode_minus_L" = no; then LIBICONV="${LIBICONV}${LIBICONV:+ }$found_so" haveit= for x in $rpathdirs; do if test "X$x" = "X$found_dir"; then haveit=yes break fi done if test -z "$haveit"; then rpathdirs="$rpathdirs $found_dir" fi else haveit= for x in $LDFLAGS $LIBICONV; do acl_save_prefix="$prefix" prefix="$acl_final_prefix" acl_save_exec_prefix="$exec_prefix" exec_prefix="$acl_final_exec_prefix" eval x=\"$x\" exec_prefix="$acl_save_exec_prefix" prefix="$acl_save_prefix" if test "X$x" = "X-L$found_dir"; then haveit=yes break fi done if test -z "$haveit"; then LIBICONV="${LIBICONV}${LIBICONV:+ }-L$found_dir" fi if test "$acl_hardcode_minus_L" != no; then LIBICONV="${LIBICONV}${LIBICONV:+ }$found_so" else LIBICONV="${LIBICONV}${LIBICONV:+ }-l$name" fi fi fi fi else if test "X$found_a" != "X"; then LIBICONV="${LIBICONV}${LIBICONV:+ }$found_a" else LIBICONV="${LIBICONV}${LIBICONV:+ }-L$found_dir -l$name" fi fi additional_includedir= case "$found_dir" in */$acl_libdirstem | */$acl_libdirstem/) basedir=`echo "X$found_dir" | sed -e 's,^X,,' -e "s,/$acl_libdirstem/"'*$,,'` if test "$name" = 'iconv'; then LIBICONV_PREFIX="$basedir" fi additional_includedir="$basedir/include" ;; */$acl_libdirstem2 | */$acl_libdirstem2/) basedir=`echo "X$found_dir" | sed -e 's,^X,,' -e "s,/$acl_libdirstem2/"'*$,,'` if test "$name" = 'iconv'; then LIBICONV_PREFIX="$basedir" fi additional_includedir="$basedir/include" ;; esac if test "X$additional_includedir" != "X"; then if test "X$additional_includedir" != "X/usr/include"; then haveit= if test "X$additional_includedir" = "X/usr/local/include"; then if test -n "$GCC"; then case $host_os in linux* | gnu* | k*bsd*-gnu) haveit=yes;; esac fi fi if test -z "$haveit"; then for x in $CPPFLAGS $INCICONV; do acl_save_prefix="$prefix" prefix="$acl_final_prefix" acl_save_exec_prefix="$exec_prefix" exec_prefix="$acl_final_exec_prefix" eval x=\"$x\" exec_prefix="$acl_save_exec_prefix" prefix="$acl_save_prefix" if test "X$x" = "X-I$additional_includedir"; then haveit=yes break fi done if test -z "$haveit"; then if test -d "$additional_includedir"; then INCICONV="${INCICONV}${INCICONV:+ }-I$additional_includedir" fi fi fi fi fi if test -n "$found_la"; then save_libdir="$libdir" case "$found_la" in */* | *\\*) . "$found_la" ;; *) . "./$found_la" ;; esac libdir="$save_libdir" for dep in $dependency_libs; do case "$dep" in -L*) additional_libdir=`echo "X$dep" | sed -e 's/^X-L//'` if test "X$additional_libdir" != "X/usr/$acl_libdirstem" \ && test "X$additional_libdir" != "X/usr/$acl_libdirstem2"; then haveit= if test "X$additional_libdir" = "X/usr/local/$acl_libdirstem" \ || test "X$additional_libdir" = "X/usr/local/$acl_libdirstem2"; then if test -n "$GCC"; then case $host_os in linux* | gnu* | k*bsd*-gnu) haveit=yes;; esac fi fi if test -z "$haveit"; then haveit= for x in $LDFLAGS $LIBICONV; do acl_save_prefix="$prefix" prefix="$acl_final_prefix" acl_save_exec_prefix="$exec_prefix" exec_prefix="$acl_final_exec_prefix" eval x=\"$x\" exec_prefix="$acl_save_exec_prefix" prefix="$acl_save_prefix" if test "X$x" = "X-L$additional_libdir"; then haveit=yes break fi done if test -z "$haveit"; then if test -d "$additional_libdir"; then LIBICONV="${LIBICONV}${LIBICONV:+ }-L$additional_libdir" fi fi haveit= for x in $LDFLAGS $LTLIBICONV; do - acl_save_prefix="$prefix" - prefix="$acl_final_prefix" - acl_save_exec_prefix="$exec_prefix" - exec_prefix="$acl_final_exec_prefix" - eval x=\"$x\" - exec_prefix="$acl_save_exec_prefix" - prefix="$acl_save_prefix" + acl_save_prefix="$prefix" + prefix="$acl_final_prefix" + acl_save_exec_prefix="$exec_prefix" + exec_prefix="$acl_final_exec_prefix" + eval x=\"$x\" + exec_prefix="$acl_save_exec_prefix" + prefix="$acl_save_prefix" + + if test "X$x" = "X-L$additional_libdir"; then + haveit=yes + break + fi + done + if test -z "$haveit"; then + if test -d "$additional_libdir"; then + LTLIBICONV="${LTLIBICONV}${LTLIBICONV:+ }-L$additional_libdir" + fi + fi + fi + fi + ;; + -R*) + dir=`echo "X$dep" | sed -e 's/^X-R//'` + if test "$enable_rpath" != no; then + haveit= + for x in $rpathdirs; do + if test "X$x" = "X$dir"; then + haveit=yes + break + fi + done + if test -z "$haveit"; then + rpathdirs="$rpathdirs $dir" + fi + haveit= + for x in $ltrpathdirs; do + if test "X$x" = "X$dir"; then + haveit=yes + break + fi + done + if test -z "$haveit"; then + ltrpathdirs="$ltrpathdirs $dir" + fi + fi + ;; + -l*) + names_next_round="$names_next_round "`echo "X$dep" | sed -e 's/^X-l//'` + ;; + *.la) + names_next_round="$names_next_round "`echo "X$dep" | sed -e 's,^X.*/,,' -e 's,^lib,,' -e 's,\.la$,,'` + ;; + *) + LIBICONV="${LIBICONV}${LIBICONV:+ }$dep" + LTLIBICONV="${LTLIBICONV}${LTLIBICONV:+ }$dep" + ;; + esac + done + fi + else + LIBICONV="${LIBICONV}${LIBICONV:+ }-l$name" + LTLIBICONV="${LTLIBICONV}${LTLIBICONV:+ }-l$name" + fi + fi + fi + done + done + if test "X$rpathdirs" != "X"; then + if test -n "$acl_hardcode_libdir_separator"; then + alldirs= + for found_dir in $rpathdirs; do + alldirs="${alldirs}${alldirs:+$acl_hardcode_libdir_separator}$found_dir" + done + acl_save_libdir="$libdir" + libdir="$alldirs" + eval flag=\"$acl_hardcode_libdir_flag_spec\" + libdir="$acl_save_libdir" + LIBICONV="${LIBICONV}${LIBICONV:+ }$flag" + else + for found_dir in $rpathdirs; do + acl_save_libdir="$libdir" + libdir="$found_dir" + eval flag=\"$acl_hardcode_libdir_flag_spec\" + libdir="$acl_save_libdir" + LIBICONV="${LIBICONV}${LIBICONV:+ }$flag" + done + fi + fi + if test "X$ltrpathdirs" != "X"; then + for found_dir in $ltrpathdirs; do + LTLIBICONV="${LTLIBICONV}${LTLIBICONV:+ }-R$found_dir" + done + fi + + + + + + + + + + + + + am_save_CPPFLAGS="$CPPFLAGS" + + for element in $INCICONV; do + haveit= + for x in $CPPFLAGS; do + + acl_save_prefix="$prefix" + prefix="$acl_final_prefix" + acl_save_exec_prefix="$exec_prefix" + exec_prefix="$acl_final_exec_prefix" + eval x=\"$x\" + exec_prefix="$acl_save_exec_prefix" + prefix="$acl_save_prefix" + + if test "X$x" = "X$element"; then + haveit=yes + break + fi + done + if test -z "$haveit"; then + CPPFLAGS="${CPPFLAGS}${CPPFLAGS:+ }$element" + fi + done + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for iconv" >&5 +$as_echo_n "checking for iconv... " >&6; } +if ${am_cv_func_iconv+:} false; then : + $as_echo_n "(cached) " >&6 +else + + am_cv_func_iconv="no, consider installing GNU libiconv" + am_cv_lib_iconv=no + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +#include +#include + +int +main () +{ +iconv_t cd = iconv_open("",""); + iconv(cd,NULL,NULL,NULL,NULL); + iconv_close(cd); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + am_cv_func_iconv=yes +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + if test "$am_cv_func_iconv" != yes; then + am_save_LIBS="$LIBS" + LIBS="$LIBS $LIBICONV" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +#include +#include + +int +main () +{ +iconv_t cd = iconv_open("",""); + iconv(cd,NULL,NULL,NULL,NULL); + iconv_close(cd); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + am_cv_lib_iconv=yes + am_cv_func_iconv=yes +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + LIBS="$am_save_LIBS" + fi + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_func_iconv" >&5 +$as_echo "$am_cv_func_iconv" >&6; } + if test "$am_cv_func_iconv" = yes; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for working iconv" >&5 +$as_echo_n "checking for working iconv... " >&6; } +if ${am_cv_func_iconv_works+:} false; then : + $as_echo_n "(cached) " >&6 +else + + am_save_LIBS="$LIBS" + if test $am_cv_lib_iconv = yes; then + LIBS="$LIBS $LIBICONV" + fi + am_cv_func_iconv_works=no + for ac_iconv_const in '' 'const'; do + if test "$cross_compiling" = yes; then : + case "$host_os" in + aix* | hpux*) am_cv_func_iconv_works="guessing no" ;; + *) am_cv_func_iconv_works="guessing yes" ;; + esac +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +#include +#include + +#ifndef ICONV_CONST +# define ICONV_CONST $ac_iconv_const +#endif + +int +main () +{ +int result = 0; + /* Test against AIX 5.1 bug: Failures are not distinguishable from successful + returns. */ + { + iconv_t cd_utf8_to_88591 = iconv_open ("ISO8859-1", "UTF-8"); + if (cd_utf8_to_88591 != (iconv_t)(-1)) + { + static ICONV_CONST char input[] = "\342\202\254"; /* EURO SIGN */ + char buf[10]; + ICONV_CONST char *inptr = input; + size_t inbytesleft = strlen (input); + char *outptr = buf; + size_t outbytesleft = sizeof (buf); + size_t res = iconv (cd_utf8_to_88591, + &inptr, &inbytesleft, + &outptr, &outbytesleft); + if (res == 0) + result |= 1; + iconv_close (cd_utf8_to_88591); + } + } + /* Test against Solaris 10 bug: Failures are not distinguishable from + successful returns. */ + { + iconv_t cd_ascii_to_88591 = iconv_open ("ISO8859-1", "646"); + if (cd_ascii_to_88591 != (iconv_t)(-1)) + { + static ICONV_CONST char input[] = "\263"; + char buf[10]; + ICONV_CONST char *inptr = input; + size_t inbytesleft = strlen (input); + char *outptr = buf; + size_t outbytesleft = sizeof (buf); + size_t res = iconv (cd_ascii_to_88591, + &inptr, &inbytesleft, + &outptr, &outbytesleft); + if (res == 0) + result |= 2; + iconv_close (cd_ascii_to_88591); + } + } + /* Test against AIX 6.1..7.1 bug: Buffer overrun. */ + { + iconv_t cd_88591_to_utf8 = iconv_open ("UTF-8", "ISO-8859-1"); + if (cd_88591_to_utf8 != (iconv_t)(-1)) + { + static ICONV_CONST char input[] = "\304"; + static char buf[2] = { (char)0xDE, (char)0xAD }; + ICONV_CONST char *inptr = input; + size_t inbytesleft = 1; + char *outptr = buf; + size_t outbytesleft = 1; + size_t res = iconv (cd_88591_to_utf8, + &inptr, &inbytesleft, + &outptr, &outbytesleft); + if (res != (size_t)(-1) || outptr - buf > 1 || buf[1] != (char)0xAD) + result |= 4; + iconv_close (cd_88591_to_utf8); + } + } +#if 0 /* This bug could be worked around by the caller. */ + /* Test against HP-UX 11.11 bug: Positive return value instead of 0. */ + { + iconv_t cd_88591_to_utf8 = iconv_open ("utf8", "iso88591"); + if (cd_88591_to_utf8 != (iconv_t)(-1)) + { + static ICONV_CONST char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; + char buf[50]; + ICONV_CONST char *inptr = input; + size_t inbytesleft = strlen (input); + char *outptr = buf; + size_t outbytesleft = sizeof (buf); + size_t res = iconv (cd_88591_to_utf8, + &inptr, &inbytesleft, + &outptr, &outbytesleft); + if ((int)res > 0) + result |= 8; + iconv_close (cd_88591_to_utf8); + } + } +#endif + /* Test against HP-UX 11.11 bug: No converter from EUC-JP to UTF-8 is + provided. */ + if (/* Try standardized names. */ + iconv_open ("UTF-8", "EUC-JP") == (iconv_t)(-1) + /* Try IRIX, OSF/1 names. */ + && iconv_open ("UTF-8", "eucJP") == (iconv_t)(-1) + /* Try AIX names. */ + && iconv_open ("UTF-8", "IBM-eucJP") == (iconv_t)(-1) + /* Try HP-UX names. */ + && iconv_open ("utf8", "eucJP") == (iconv_t)(-1)) + result |= 16; + return result; + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_run "$LINENO"; then : + am_cv_func_iconv_works=yes +fi +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ + conftest.$ac_objext conftest.beam conftest.$ac_ext +fi + + test "$am_cv_func_iconv_works" = no || break + done + LIBS="$am_save_LIBS" + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_func_iconv_works" >&5 +$as_echo "$am_cv_func_iconv_works" >&6; } + case "$am_cv_func_iconv_works" in + *no) am_func_iconv=no am_cv_lib_iconv=no ;; + *) am_func_iconv=yes ;; + esac + else + am_func_iconv=no am_cv_lib_iconv=no + fi + if test "$am_func_iconv" = yes; then + +$as_echo "#define HAVE_ICONV 1" >>confdefs.h + + fi + if test "$am_cv_lib_iconv" = yes; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking how to link with libiconv" >&5 +$as_echo_n "checking how to link with libiconv... " >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LIBICONV" >&5 +$as_echo "$LIBICONV" >&6; } + else + CPPFLAGS="$am_save_CPPFLAGS" + LIBICONV= + LTLIBICONV= + fi + + + + if test "$am_cv_func_iconv" = yes; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for iconv declaration" >&5 +$as_echo_n "checking for iconv declaration... " >&6; } + if ${am_cv_proto_iconv+:} false; then : + $as_echo_n "(cached) " >&6 +else + + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +#include +#include +extern +#ifdef __cplusplus +"C" +#endif +#if defined(__STDC__) || defined(_MSC_VER) || defined(__cplusplus) +size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft); +#else +size_t iconv(); +#endif + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + am_cv_proto_iconv_arg1="" +else + am_cv_proto_iconv_arg1="const" +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + am_cv_proto_iconv="extern size_t iconv (iconv_t cd, $am_cv_proto_iconv_arg1 char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);" +fi + + am_cv_proto_iconv=`echo "$am_cv_proto_iconv" | tr -s ' ' | sed -e 's/( /(/'` + { $as_echo "$as_me:${as_lineno-$LINENO}: result: + $am_cv_proto_iconv" >&5 +$as_echo " + $am_cv_proto_iconv" >&6; } + +cat >>confdefs.h <<_ACEOF +#define ICONV_CONST $am_cv_proto_iconv_arg1 +_ACEOF + + + fi + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking cached host tuple" >&5 +$as_echo_n "checking cached host tuple... " >&6; } +if { test x"${ac_cv_host_system_type+set}" = x"set" && + test x"$ac_cv_host_system_type" != x"$host"; }; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: different" >&5 +$as_echo "different" >&6; } + as_fn_error $? "remove config.cache and re-run configure" "$LINENO" 5 +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: ok" >&5 +$as_echo "ok" >&6; } +fi +ac_cv_host_system_type="$host" + + + +case "${host}" in + + ## Alpha (DEC) machines. + alpha*-dec-osf* ) + tcsh_config_file=decosf1 + ;; + + ## Ultrix + *-dec-ultrix* ) + tcsh_config_file=ultrix + ;; + + ## DGUX + *-dg-dguxR4* ) + tcsh_config_file=dgux5.4 + ;; + m88k-dg-dgux5.4R* ) + tcsh_config_file=dgux5.4 + ;; + + ## HP/UX + *-hp-hpux7* ) + tcsh_config_file=hpux7 + ;; + *-hp-hpux[89]* ) + tcsh_config_file=hpux8 + ;; + *-hp-hpux1[0-9]* ) + tcsh_config_file=hpux11 + ;; + + ## IBM AIX systems + *-ibm-aix*) + tcsh_config_file=aix + ;; + + ## SX-4 + sx4-nec-*) + CC='cc -h0,ansi,novector,float0' + LDFLAGS='-Gsmall' + tcsh_config_file=superux8 + ;; + + ## IBM OS/390 systems + *-ibm-os390*) + CC='c89' + tcsh_config_file=os390 + ;; + + ## Android + *-*-android*) + tcsh_config_file=android + ;; + + ## Linux + *-*-linux* | *-*-gnu* | *-*-k*bsd*-gnu) + tcsh_config_file=linux + ;; + + ## Motorola systems + m68k-motorola-sysv* ) + tcsh_config_file=sysV68 + ;; + m88k-motorola-sysv3* ) + tcsh_config_file=sysV88 + ;; + + ## Minix systems + *-*-minix*) + tcsh_config_file=minix + ;; + + ## NetBSD systems + *-*-netbsd*) + tcsh_config_file=bsd4.4 + ;; + + ## FreeBSD systems + *-*-freebsd*) + tcsh_config_file=bsd4.4 + ;; + + ## MidnightBSD systems + *-*-midnightbsd*) + tcsh_config_file=bsd4.4 + ;; + + ## DragonFlyBSD systems + *-*-dragonfly*) + tcsh_config_file=bsd4.4 + ;; + + ## MirBSD systems + *-*-mirbsd*) + tcsh_config_file=bsd4.4 + ;; + + ## OpenBSD systems + *-*-openbsd*) + tcsh_config_file=bsd4.4 + ;; + + ## BSDI systems + *-*-bsdi*) + tcsh_config_file=bsd4.4 + ;; + + ## Mac OS X Server + *-*-rhapsody* ) + tcsh_config_file=bsd4.4 + ;; + + ## Mac OS X Server + *-*-darwin* ) + tcsh_config_file=bsd4.4 + ;; + + ## DragonFly systems + *-*-dragonfly*) + tcsh_config_file=bsd4.4 + ;; + + ## Silicon Graphics machines + *-sgi-iri* ) + tcsh_config_file=irix + case "${host_os}" in + irix[34]*) # Irix-3.x - Irix 4.x + NON_GNU_DFLAGS='-D__STDC__' + LIBS='-lsun -lbsd -lc_s' + ;; + irix5* | irix6.[01]*) # Irix 5.x, Irix 6.0 - 6.1 + LIBS='-lbsd' + ;; + irix6.[2-9]*) # Irix 6.2 and later + tcsh_config_file=irix62 + ;; + esac + ;; + + ## Suns + *-sun-sunos3* ) + tcsh_config_file=sunos35 + ;; + *-sun-sunos4.0* ) + tcsh_config_file=sunos40 + ;; + *-sun-sunos4.1.[12]* ) + tcsh_config_file=sunos41 + ;; + *-sun-sunos4.1.[3456]* ) + tcsh_config_file=sunos413 + ;; + *-*-solaris2.[01] ) # Should handle sparc or x86 + tcsh_config_file=sol2 + ;; + *-sun-solaris2.2 ) # Sparc only release + tcsh_config_file=sol22 + ;; + *-sun-solaris2.3 ) # Sparc only release + tcsh_config_file=sol23 + ;; + *-*-solaris2.[45] ) # Should handle sparc, x86 and powerpc + tcsh_config_file=sol24 + ;; + *-*-solaris2.[678] ) # Should handle sparc, x86 and powerpc + tcsh_config_file=sol26 + ;; + *-*-solaris2.* ) # Should handle sparc, x86 and powerpc + tcsh_config_file=sol29 + ;; + + ## Dell SVR4 + *-dell-sysv4* ) + tcsh_config_file=sysv4 + DFLAGS="$DFLAGS -DDELL" + ;; + + ## SVR4 (Generic and otherwise) + *-*-sysv4* ) + tcsh_config_file=sysv4 + ;; + + ## Tektronix systems + m68k-tektronix-bsd* ) + tcsh_config_file=bsd + NON_GNU_DFLAGS='-DBSD -DUTek' + ;; + m88k-tektronix-sysv3* ) + tcsh_config_file=tekXD88 + ;; + + ## SCO + *-sco3.2v5*) + tcsh_config_file=sco32v5 + ;; + *-sco3.2v4*) + tcsh_config_file=sco32v4 + ;; + *-sco3.2v2*) + tcsh_config_file=sco32v2 + ;; + + ## Siemens BS2000 Mainframe + bs2000-siemens-*) + tcsh_config_file=bs2000 + ;; + + ## Convex + *-convex*) + tcsh_config_file=convex + ;; + + ## Cray + *-cray-unicos*) + tcsh_config_file=cray + ;; + + ## Red Hat Cygwin + *-cygwin) + tcsh_config_file=cygwin + ;; + + ## mips-compaq-nonstopux + *-*-nonstopux) + tcsh_config_file=sysv4 + ;; + + ## Apollo Domain/OS + *-apollo-*) + tcsh_config_file=apollo + ;; + + ## QNX6 + *-qnx6*) + tcsh_config_file=qnx6 + ;; + + * ) + as_fn_error $? "Tcsh can't guess the configuration file name +for \`${host}' systems. +Check tcsh's \`Ported' file for manual configuration instructions." "$LINENO" 5 + ;; + +esac + +echo "Tcsh will use configuration file \`$tcsh_config_file'." +cp ${srcdir}/config/${tcsh_config_file} config_p.h + + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args. +set dummy ${ac_tool_prefix}gcc; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_CC+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_CC="${ac_tool_prefix}gcc" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +$as_echo "$CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_CC"; then + ac_ct_CC=$CC + # Extract the first word of "gcc", so it can be a program name with args. +set dummy gcc; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_CC+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_CC"; then + ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_CC="gcc" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_CC=$ac_cv_prog_ac_ct_CC +if test -n "$ac_ct_CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 +$as_echo "$ac_ct_CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_CC" = x; then + CC="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + CC=$ac_ct_CC + fi +else + CC="$ac_cv_prog_CC" +fi + +if test -z "$CC"; then + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args. +set dummy ${ac_tool_prefix}cc; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_CC+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_CC="${ac_tool_prefix}cc" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +$as_echo "$CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + fi +fi +if test -z "$CC"; then + # Extract the first word of "cc", so it can be a program name with args. +set dummy cc; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_CC+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else + ac_prog_rejected=no +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then + ac_prog_rejected=yes + continue + fi + ac_cv_prog_CC="cc" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +if test $ac_prog_rejected = yes; then + # We found a bogon in the path, so make sure we never use it. + set dummy $ac_cv_prog_CC + shift + if test $# != 0; then + # We chose a different compiler from the bogus one. + # However, it has the same basename, so the bogon will be chosen + # first if we set CC to just the basename; use the full file name. + shift + ac_cv_prog_CC="$as_dir/$ac_word${1+' '}$@" + fi +fi +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +$as_echo "$CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$CC"; then + if test -n "$ac_tool_prefix"; then + for ac_prog in cl.exe + do + # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. +set dummy $ac_tool_prefix$ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_CC+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_CC="$ac_tool_prefix$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +$as_echo "$CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$CC" && break + done +fi +if test -z "$CC"; then + ac_ct_CC=$CC + for ac_prog in cl.exe +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_CC+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_CC"; then + ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_CC="$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_CC=$ac_cv_prog_ac_ct_CC +if test -n "$ac_ct_CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 +$as_echo "$ac_ct_CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$ac_ct_CC" && break +done + + if test "x$ac_ct_CC" = x; then + CC="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + CC=$ac_ct_CC + fi +fi + +fi + + +test -z "$CC" && { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "no acceptable C compiler found in \$PATH +See \`config.log' for more details" "$LINENO" 5; } + +# Provide some information about the compiler. +$as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5 +set X $ac_compile +ac_compiler=$2 +for ac_option in --version -v -V -qversion; do + { { ac_try="$ac_compiler $ac_option >&5" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_compiler $ac_option >&5") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + sed '10a\ +... rest of stderr output deleted ... + 10q' conftest.err >conftest.er1 + cat conftest.er1 >&5 + fi + rm -f conftest.er1 conftest.err + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } +done + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C compiler" >&5 +$as_echo_n "checking whether we are using the GNU C compiler... " >&6; } +if ${ac_cv_c_compiler_gnu+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ +#ifndef __GNUC__ + choke me +#endif + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_compiler_gnu=yes +else + ac_compiler_gnu=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +ac_cv_c_compiler_gnu=$ac_compiler_gnu + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu" >&5 +$as_echo "$ac_cv_c_compiler_gnu" >&6; } +if test $ac_compiler_gnu = yes; then + GCC=yes +else + GCC= +fi +ac_test_CFLAGS=${CFLAGS+set} +ac_save_CFLAGS=$CFLAGS +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5 +$as_echo_n "checking whether $CC accepts -g... " >&6; } +if ${ac_cv_prog_cc_g+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_save_c_werror_flag=$ac_c_werror_flag + ac_c_werror_flag=yes + ac_cv_prog_cc_g=no + CFLAGS="-g" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_prog_cc_g=yes +else + CFLAGS="" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + +else + ac_c_werror_flag=$ac_save_c_werror_flag + CFLAGS="-g" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_prog_cc_g=yes +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + ac_c_werror_flag=$ac_save_c_werror_flag +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g" >&5 +$as_echo "$ac_cv_prog_cc_g" >&6; } +if test "$ac_test_CFLAGS" = set; then + CFLAGS=$ac_save_CFLAGS +elif test $ac_cv_prog_cc_g = yes; then + if test "$GCC" = yes; then + CFLAGS="-g -O2" + else + CFLAGS="-g" + fi +else + if test "$GCC" = yes; then + CFLAGS="-O2" + else + CFLAGS= + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CC option to accept ISO C89" >&5 +$as_echo_n "checking for $CC option to accept ISO C89... " >&6; } +if ${ac_cv_prog_cc_c89+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_cv_prog_cc_c89=no +ac_save_CC=$CC +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +#include +struct stat; +/* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ +struct buf { int x; }; +FILE * (*rcsopen) (struct buf *, struct stat *, int); +static char *e (p, i) + char **p; + int i; +{ + return p[i]; +} +static char *f (char * (*g) (char **, int), char **p, ...) +{ + char *s; + va_list v; + va_start (v,p); + s = g (p, va_arg (v,int)); + va_end (v); + return s; +} + +/* OSF 4.0 Compaq cc is some sort of almost-ANSI by default. It has + function prototypes and stuff, but not '\xHH' hex character constants. + These don't provoke an error unfortunately, instead are silently treated + as 'x'. The following induces an error, until -std is added to get + proper ANSI mode. Curiously '\x00'!='x' always comes out true, for an + array size at least. It's necessary to write '\x00'==0 to get something + that's true only with -std. */ +int osf4_cc_array ['\x00' == 0 ? 1 : -1]; + +/* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters + inside strings and character constants. */ +#define FOO(x) 'x' +int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1]; + +int test (int i, double x); +struct s1 {int (*f) (int a);}; +struct s2 {int (*f) (double a);}; +int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int); +int argc; +char **argv; +int +main () +{ +return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]; + ; + return 0; +} +_ACEOF +for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std \ + -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" +do + CC="$ac_save_CC $ac_arg" + if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_prog_cc_c89=$ac_arg +fi +rm -f core conftest.err conftest.$ac_objext + test "x$ac_cv_prog_cc_c89" != "xno" && break +done +rm -f conftest.$ac_ext +CC=$ac_save_CC + +fi +# AC_CACHE_VAL +case "x$ac_cv_prog_cc_c89" in + x) + { $as_echo "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 +$as_echo "none needed" >&6; } ;; + xno) + { $as_echo "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 +$as_echo "unsupported" >&6; } ;; + *) + CC="$CC $ac_cv_prog_cc_c89" + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89" >&5 +$as_echo "$ac_cv_prog_cc_c89" >&6; } ;; +esac +if test "x$ac_cv_prog_cc_c89" != xno; then : + +fi + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to run the C preprocessor" >&5 +$as_echo_n "checking how to run the C preprocessor... " >&6; } +# On Suns, sometimes $CPP names a directory. +if test -n "$CPP" && test -d "$CPP"; then + CPP= +fi +if test -z "$CPP"; then + if ${ac_cv_prog_CPP+:} false; then : + $as_echo_n "(cached) " >&6 +else + # Double quotes because CPP needs to be expanded + for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp" + do + ac_preproc_ok=false +for ac_c_preproc_warn_flag in '' yes +do + # Use a header file that comes with gcc, so configuring glibc + # with a fresh cross-compiler works. + # Prefer to if __STDC__ is defined, since + # exists even on freestanding compilers. + # On the NeXT, cc -E runs the code through the compiler's parser, + # not just through cpp. "Syntax error" is here to catch this case. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#ifdef __STDC__ +# include +#else +# include +#endif + Syntax error +_ACEOF +if ac_fn_c_try_cpp "$LINENO"; then : + +else + # Broken: fails on valid input. +continue +fi +rm -f conftest.err conftest.i conftest.$ac_ext + + # OK, works on sane cases. Now check whether nonexistent headers + # can be detected and how. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +_ACEOF +if ac_fn_c_try_cpp "$LINENO"; then : + # Broken: success on invalid input. +continue +else + # Passes both tests. +ac_preproc_ok=: +break +fi +rm -f conftest.err conftest.i conftest.$ac_ext + +done +# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. +rm -f conftest.i conftest.err conftest.$ac_ext +if $ac_preproc_ok; then : + break +fi - if test "X$x" = "X-L$additional_libdir"; then - haveit=yes - break - fi - done - if test -z "$haveit"; then - if test -d "$additional_libdir"; then - LTLIBICONV="${LTLIBICONV}${LTLIBICONV:+ }-L$additional_libdir" - fi - fi - fi - fi - ;; - -R*) - dir=`echo "X$dep" | sed -e 's/^X-R//'` - if test "$enable_rpath" != no; then - haveit= - for x in $rpathdirs; do - if test "X$x" = "X$dir"; then - haveit=yes - break - fi - done - if test -z "$haveit"; then - rpathdirs="$rpathdirs $dir" - fi - haveit= - for x in $ltrpathdirs; do - if test "X$x" = "X$dir"; then - haveit=yes - break - fi - done - if test -z "$haveit"; then - ltrpathdirs="$ltrpathdirs $dir" - fi - fi - ;; - -l*) - names_next_round="$names_next_round "`echo "X$dep" | sed -e 's/^X-l//'` - ;; - *.la) - names_next_round="$names_next_round "`echo "X$dep" | sed -e 's,^X.*/,,' -e 's,^lib,,' -e 's,\.la$,,'` - ;; - *) - LIBICONV="${LIBICONV}${LIBICONV:+ }$dep" - LTLIBICONV="${LTLIBICONV}${LTLIBICONV:+ }$dep" - ;; - esac - done - fi - else - LIBICONV="${LIBICONV}${LIBICONV:+ }-l$name" - LTLIBICONV="${LTLIBICONV}${LTLIBICONV:+ }-l$name" - fi - fi - fi - done - done - if test "X$rpathdirs" != "X"; then - if test -n "$acl_hardcode_libdir_separator"; then - alldirs= - for found_dir in $rpathdirs; do - alldirs="${alldirs}${alldirs:+$acl_hardcode_libdir_separator}$found_dir" - done - acl_save_libdir="$libdir" - libdir="$alldirs" - eval flag=\"$acl_hardcode_libdir_flag_spec\" - libdir="$acl_save_libdir" - LIBICONV="${LIBICONV}${LIBICONV:+ }$flag" - else - for found_dir in $rpathdirs; do - acl_save_libdir="$libdir" - libdir="$found_dir" - eval flag=\"$acl_hardcode_libdir_flag_spec\" - libdir="$acl_save_libdir" - LIBICONV="${LIBICONV}${LIBICONV:+ }$flag" - done - fi - fi - if test "X$ltrpathdirs" != "X"; then - for found_dir in $ltrpathdirs; do - LTLIBICONV="${LTLIBICONV}${LTLIBICONV:+ }-R$found_dir" done - fi + ac_cv_prog_CPP=$CPP + +fi + CPP=$ac_cv_prog_CPP +else + ac_cv_prog_CPP=$CPP +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $CPP" >&5 +$as_echo "$CPP" >&6; } +ac_preproc_ok=false +for ac_c_preproc_warn_flag in '' yes +do + # Use a header file that comes with gcc, so configuring glibc + # with a fresh cross-compiler works. + # Prefer to if __STDC__ is defined, since + # exists even on freestanding compilers. + # On the NeXT, cc -E runs the code through the compiler's parser, + # not just through cpp. "Syntax error" is here to catch this case. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#ifdef __STDC__ +# include +#else +# include +#endif + Syntax error +_ACEOF +if ac_fn_c_try_cpp "$LINENO"; then : + +else + # Broken: fails on valid input. +continue +fi +rm -f conftest.err conftest.i conftest.$ac_ext + # OK, works on sane cases. Now check whether nonexistent headers + # can be detected and how. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +_ACEOF +if ac_fn_c_try_cpp "$LINENO"; then : + # Broken: success on invalid input. +continue +else + # Passes both tests. +ac_preproc_ok=: +break +fi +rm -f conftest.err conftest.i conftest.$ac_ext +done +# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. +rm -f conftest.i conftest.err conftest.$ac_ext +if $ac_preproc_ok; then : +else + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "C preprocessor \"$CPP\" fails sanity check +See \`config.log' for more details" "$LINENO" 5; } +fi +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu +if test $ac_cv_c_compiler_gnu = yes; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC needs -traditional" >&5 +$as_echo_n "checking whether $CC needs -traditional... " >&6; } +if ${ac_cv_prog_gcc_traditional+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_pattern="Autoconf.*'x'" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +Autoconf TIOCGETP +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "$ac_pattern" >/dev/null 2>&1; then : + ac_cv_prog_gcc_traditional=yes +else + ac_cv_prog_gcc_traditional=no +fi +rm -f conftest* + if test $ac_cv_prog_gcc_traditional = no; then + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +Autoconf TCGETA +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "$ac_pattern" >/dev/null 2>&1; then : + ac_cv_prog_gcc_traditional=yes +fi +rm -f conftest* + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_gcc_traditional" >&5 +$as_echo "$ac_cv_prog_gcc_traditional" >&6; } + if test $ac_cv_prog_gcc_traditional = yes; then + CC="$CC -traditional" + fi +fi +# Extract the first word of "gencat", so it can be a program name with args. +set dummy gencat; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_GENCAT+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $GENCAT in + [\\/]* | ?:[\\/]*) + ac_cv_path_GENCAT="$GENCAT" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_GENCAT="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + ;; +esac +fi +GENCAT=$ac_cv_path_GENCAT +if test -n "$GENCAT"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $GENCAT" >&5 +$as_echo "$GENCAT" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi - am_save_CPPFLAGS="$CPPFLAGS" - for element in $INCICONV; do - haveit= - for x in $CPPFLAGS; do - acl_save_prefix="$prefix" - prefix="$acl_final_prefix" - acl_save_exec_prefix="$exec_prefix" - exec_prefix="$acl_final_exec_prefix" - eval x=\"$x\" - exec_prefix="$acl_save_exec_prefix" - prefix="$acl_save_prefix" +if test "x${cross_compiling}" = xyes ; then + CC_FOR_GETHOST="cc" +else + CC_FOR_GETHOST="\$(CC)" +fi - if test "X$x" = "X$element"; then - haveit=yes - break - fi - done - if test -z "$haveit"; then - CPPFLAGS="${CPPFLAGS}${CPPFLAGS:+ }$element" - fi - done +if test "x$GCC" != xyes ; then + DFLAGS="$DFLAGS $NON_GNU_DFLAGS" + CFLAGS="$CFLAGS $NON_GNU_CFLAGS" +fi + +case "${host}" in + *-*-android*) + CFLAGS="${CFLAGS} -fPIE" + LDFLAGS="${LDFLAGS} -pie" + ;; +esac - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for iconv" >&5 -$as_echo_n "checking for iconv... " >&6; } -if ${am_cv_func_iconv+:} false; then : +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing crypt" >&5 +$as_echo_n "checking for library containing crypt... " >&6; } +if ${ac_cv_search_crypt+:} false; then : $as_echo_n "(cached) " >&6 else - - am_cv_func_iconv="no, consider installing GNU libiconv" - am_cv_lib_iconv=no - cat confdefs.h - <<_ACEOF >conftest.$ac_ext + ac_func_search_save_LIBS=$LIBS +cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ -#include -#include - +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char crypt (); int main () { -iconv_t cd = iconv_open("",""); - iconv(cd,NULL,NULL,NULL,NULL); - iconv_close(cd); +return crypt (); ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : - am_cv_func_iconv=yes +for ac_lib in '' crypt; do + if test -z "$ac_lib"; then + ac_res="none required" + else + ac_res=-l$ac_lib + LIBS="-l$ac_lib $ac_func_search_save_LIBS" + fi + if ac_fn_c_try_link "$LINENO"; then : + ac_cv_search_crypt=$ac_res fi rm -f core conftest.err conftest.$ac_objext \ - conftest$ac_exeext conftest.$ac_ext - if test "$am_cv_func_iconv" != yes; then - am_save_LIBS="$LIBS" - LIBS="$LIBS $LIBICONV" - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ + conftest$ac_exeext + if ${ac_cv_search_crypt+:} false; then : + break +fi +done +if ${ac_cv_search_crypt+:} false; then : -#include -#include +else + ac_cv_search_crypt=no +fi +rm conftest.$ac_ext +LIBS=$ac_func_search_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_crypt" >&5 +$as_echo "$ac_cv_search_crypt" >&6; } +ac_res=$ac_cv_search_crypt +if test "$ac_res" != no; then : + test "$ac_res" = "none required" || LIBS="$ac_res $LIBS" + +fi + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing getspnam" >&5 +$as_echo_n "checking for library containing getspnam... " >&6; } +if ${ac_cv_search_getspnam+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_func_search_save_LIBS=$LIBS +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char getspnam (); int main () { -iconv_t cd = iconv_open("",""); - iconv(cd,NULL,NULL,NULL,NULL); - iconv_close(cd); +return getspnam (); ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : - am_cv_lib_iconv=yes - am_cv_func_iconv=yes +for ac_lib in '' sec; do + if test -z "$ac_lib"; then + ac_res="none required" + else + ac_res=-l$ac_lib + LIBS="-l$ac_lib $ac_func_search_save_LIBS" + fi + if ac_fn_c_try_link "$LINENO"; then : + ac_cv_search_getspnam=$ac_res fi rm -f core conftest.err conftest.$ac_objext \ - conftest$ac_exeext conftest.$ac_ext - LIBS="$am_save_LIBS" - fi - + conftest$ac_exeext + if ${ac_cv_search_getspnam+:} false; then : + break fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_func_iconv" >&5 -$as_echo "$am_cv_func_iconv" >&6; } - if test "$am_cv_func_iconv" = yes; then - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for working iconv" >&5 -$as_echo_n "checking for working iconv... " >&6; } -if ${am_cv_func_iconv_works+:} false; then : - $as_echo_n "(cached) " >&6 -else +done +if ${ac_cv_search_getspnam+:} false; then : - am_save_LIBS="$LIBS" - if test $am_cv_lib_iconv = yes; then - LIBS="$LIBS $LIBICONV" - fi - am_cv_func_iconv_works=no - for ac_iconv_const in '' 'const'; do - if test "$cross_compiling" = yes; then : - case "$host_os" in - aix* | hpux*) am_cv_func_iconv_works="guessing no" ;; - *) am_cv_func_iconv_works="guessing yes" ;; - esac else - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -#include -#include - -#ifndef ICONV_CONST -# define ICONV_CONST $ac_iconv_const -#endif - -int -main () -{ -int result = 0; - /* Test against AIX 5.1 bug: Failures are not distinguishable from successful - returns. */ - { - iconv_t cd_utf8_to_88591 = iconv_open ("ISO8859-1", "UTF-8"); - if (cd_utf8_to_88591 != (iconv_t)(-1)) - { - static ICONV_CONST char input[] = "\342\202\254"; /* EURO SIGN */ - char buf[10]; - ICONV_CONST char *inptr = input; - size_t inbytesleft = strlen (input); - char *outptr = buf; - size_t outbytesleft = sizeof (buf); - size_t res = iconv (cd_utf8_to_88591, - &inptr, &inbytesleft, - &outptr, &outbytesleft); - if (res == 0) - result |= 1; - iconv_close (cd_utf8_to_88591); - } - } - /* Test against Solaris 10 bug: Failures are not distinguishable from - successful returns. */ - { - iconv_t cd_ascii_to_88591 = iconv_open ("ISO8859-1", "646"); - if (cd_ascii_to_88591 != (iconv_t)(-1)) - { - static ICONV_CONST char input[] = "\263"; - char buf[10]; - ICONV_CONST char *inptr = input; - size_t inbytesleft = strlen (input); - char *outptr = buf; - size_t outbytesleft = sizeof (buf); - size_t res = iconv (cd_ascii_to_88591, - &inptr, &inbytesleft, - &outptr, &outbytesleft); - if (res == 0) - result |= 2; - iconv_close (cd_ascii_to_88591); - } - } - /* Test against AIX 6.1..7.1 bug: Buffer overrun. */ - { - iconv_t cd_88591_to_utf8 = iconv_open ("UTF-8", "ISO-8859-1"); - if (cd_88591_to_utf8 != (iconv_t)(-1)) - { - static ICONV_CONST char input[] = "\304"; - static char buf[2] = { (char)0xDE, (char)0xAD }; - ICONV_CONST char *inptr = input; - size_t inbytesleft = 1; - char *outptr = buf; - size_t outbytesleft = 1; - size_t res = iconv (cd_88591_to_utf8, - &inptr, &inbytesleft, - &outptr, &outbytesleft); - if (res != (size_t)(-1) || outptr - buf > 1 || buf[1] != (char)0xAD) - result |= 4; - iconv_close (cd_88591_to_utf8); - } - } -#if 0 /* This bug could be worked around by the caller. */ - /* Test against HP-UX 11.11 bug: Positive return value instead of 0. */ - { - iconv_t cd_88591_to_utf8 = iconv_open ("utf8", "iso88591"); - if (cd_88591_to_utf8 != (iconv_t)(-1)) - { - static ICONV_CONST char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; - char buf[50]; - ICONV_CONST char *inptr = input; - size_t inbytesleft = strlen (input); - char *outptr = buf; - size_t outbytesleft = sizeof (buf); - size_t res = iconv (cd_88591_to_utf8, - &inptr, &inbytesleft, - &outptr, &outbytesleft); - if ((int)res > 0) - result |= 8; - iconv_close (cd_88591_to_utf8); - } - } -#endif - /* Test against HP-UX 11.11 bug: No converter from EUC-JP to UTF-8 is - provided. */ - if (/* Try standardized names. */ - iconv_open ("UTF-8", "EUC-JP") == (iconv_t)(-1) - /* Try IRIX, OSF/1 names. */ - && iconv_open ("UTF-8", "eucJP") == (iconv_t)(-1) - /* Try AIX names. */ - && iconv_open ("UTF-8", "IBM-eucJP") == (iconv_t)(-1) - /* Try HP-UX names. */ - && iconv_open ("utf8", "eucJP") == (iconv_t)(-1)) - result |= 16; - return result; + ac_cv_search_getspnam=no +fi +rm conftest.$ac_ext +LIBS=$ac_func_search_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_getspnam" >&5 +$as_echo "$ac_cv_search_getspnam" >&6; } +ac_res=$ac_cv_search_getspnam +if test "$ac_res" != no; then : + test "$ac_res" = "none required" || LIBS="$ac_res $LIBS" + +fi + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing tgetent" >&5 +$as_echo_n "checking for library containing tgetent... " >&6; } +if ${ac_cv_search_tgetent+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_func_search_save_LIBS=$LIBS +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char tgetent (); +int +main () +{ +return tgetent (); ; return 0; } _ACEOF -if ac_fn_c_try_run "$LINENO"; then : - am_cv_func_iconv_works=yes +for ac_lib in '' termlib tinfo termcap curses ncurses; do + if test -z "$ac_lib"; then + ac_res="none required" + else + ac_res=-l$ac_lib + LIBS="-l$ac_lib $ac_func_search_save_LIBS" + fi + if ac_fn_c_try_link "$LINENO"; then : + ac_cv_search_tgetent=$ac_res fi -rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ - conftest.$ac_objext conftest.beam conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext + if ${ac_cv_search_tgetent+:} false; then : + break +fi +done +if ${ac_cv_search_tgetent+:} false; then : + +else + ac_cv_search_tgetent=no fi +rm conftest.$ac_ext +LIBS=$ac_func_search_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_tgetent" >&5 +$as_echo "$ac_cv_search_tgetent" >&6; } +ac_res=$ac_cv_search_tgetent +if test "$ac_res" != no; then : + test "$ac_res" = "none required" || LIBS="$ac_res $LIBS" - test "$am_cv_func_iconv_works" = no || break - done - LIBS="$am_save_LIBS" +else + + as_fn_error $? "unable to find the tgetent() function" "$LINENO" 5 fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_func_iconv_works" >&5 -$as_echo "$am_cv_func_iconv_works" >&6; } - case "$am_cv_func_iconv_works" in - *no) am_func_iconv=no am_cv_lib_iconv=no ;; - *) am_func_iconv=yes ;; - esac - else - am_func_iconv=no am_cv_lib_iconv=no - fi - if test "$am_func_iconv" = yes; then -$as_echo "#define HAVE_ICONV 1" >>confdefs.h +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing gethostbyname" >&5 +$as_echo_n "checking for library containing gethostbyname... " >&6; } +if ${ac_cv_search_gethostbyname+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_func_search_save_LIBS=$LIBS +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ - fi - if test "$am_cv_lib_iconv" = yes; then - { $as_echo "$as_me:${as_lineno-$LINENO}: checking how to link with libiconv" >&5 -$as_echo_n "checking how to link with libiconv... " >&6; } - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LIBICONV" >&5 -$as_echo "$LIBICONV" >&6; } +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char gethostbyname (); +int +main () +{ +return gethostbyname (); + ; + return 0; +} +_ACEOF +for ac_lib in '' nsl; do + if test -z "$ac_lib"; then + ac_res="none required" else - CPPFLAGS="$am_save_CPPFLAGS" - LIBICONV= - LTLIBICONV= + ac_res=-l$ac_lib + LIBS="-l$ac_lib $ac_func_search_save_LIBS" fi + if ac_fn_c_try_link "$LINENO"; then : + ac_cv_search_gethostbyname=$ac_res +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext + if ${ac_cv_search_gethostbyname+:} false; then : + break +fi +done +if ${ac_cv_search_gethostbyname+:} false; then : +else + ac_cv_search_gethostbyname=no +fi +rm conftest.$ac_ext +LIBS=$ac_func_search_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_gethostbyname" >&5 +$as_echo "$ac_cv_search_gethostbyname" >&6; } +ac_res=$ac_cv_search_gethostbyname +if test "$ac_res" != no; then : + test "$ac_res" = "none required" || LIBS="$ac_res $LIBS" +fi - if test "$am_cv_func_iconv" = yes; then - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for iconv declaration" >&5 -$as_echo_n "checking for iconv declaration... " >&6; } - if ${am_cv_proto_iconv+:} false; then : +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing connect" >&5 +$as_echo_n "checking for library containing connect... " >&6; } +if ${ac_cv_search_connect+:} false; then : $as_echo_n "(cached) " >&6 else - - cat confdefs.h - <<_ACEOF >conftest.$ac_ext + ac_func_search_save_LIBS=$LIBS +cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ -#include -#include -extern +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ #ifdef __cplusplus -"C" -#endif -#if defined(__STDC__) || defined(_MSC_VER) || defined(__cplusplus) -size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft); -#else -size_t iconv(); +extern "C" #endif - +char connect (); int main () { - +return connect (); ; return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - am_cv_proto_iconv_arg1="" +for ac_lib in '' socket; do + if test -z "$ac_lib"; then + ac_res="none required" + else + ac_res=-l$ac_lib + LIBS="-l$ac_lib $ac_func_search_save_LIBS" + fi + if ac_fn_c_try_link "$LINENO"; then : + ac_cv_search_connect=$ac_res +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext + if ${ac_cv_search_connect+:} false; then : + break +fi +done +if ${ac_cv_search_connect+:} false; then : + else - am_cv_proto_iconv_arg1="const" + ac_cv_search_connect=no fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - am_cv_proto_iconv="extern size_t iconv (iconv_t cd, $am_cv_proto_iconv_arg1 char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);" +rm conftest.$ac_ext +LIBS=$ac_func_search_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_connect" >&5 +$as_echo "$ac_cv_search_connect" >&6; } +ac_res=$ac_cv_search_connect +if test "$ac_res" != no; then : + test "$ac_res" = "none required" || LIBS="$ac_res $LIBS" + fi - am_cv_proto_iconv=`echo "$am_cv_proto_iconv" | tr -s ' ' | sed -e 's/( /(/'` - { $as_echo "$as_me:${as_lineno-$LINENO}: result: - $am_cv_proto_iconv" >&5 -$as_echo " - $am_cv_proto_iconv" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing catgets" >&5 +$as_echo_n "checking for library containing catgets... " >&6; } +if ${ac_cv_search_catgets+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_func_search_save_LIBS=$LIBS +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ -cat >>confdefs.h <<_ACEOF -#define ICONV_CONST $am_cv_proto_iconv_arg1 +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char catgets (); +int +main () +{ +return catgets (); + ; + return 0; +} _ACEOF +for ac_lib in '' catgets; do + if test -z "$ac_lib"; then + ac_res="none required" + else + ac_res=-l$ac_lib + LIBS="-l$ac_lib $ac_func_search_save_LIBS" + fi + if ac_fn_c_try_link "$LINENO"; then : + ac_cv_search_catgets=$ac_res +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext + if ${ac_cv_search_catgets+:} false; then : + break +fi +done +if ${ac_cv_search_catgets+:} false; then : +else + ac_cv_search_catgets=no +fi +rm conftest.$ac_ext +LIBS=$ac_func_search_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_catgets" >&5 +$as_echo "$ac_cv_search_catgets" >&6; } +ac_res=$ac_cv_search_catgets +if test "$ac_res" != no; then : + test "$ac_res" = "none required" || LIBS="$ac_res $LIBS" - fi +fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5 $as_echo_n "checking for ANSI C header files... " >&6; } if ${ac_cv_header_stdc+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include #include #include int main () { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_header_stdc=yes else ac_cv_header_stdc=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext if test $ac_cv_header_stdc = yes; then # SunOS 4.x string.h does not declare mem*, contrary to ANSI. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include _ACEOF if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | $EGREP "memchr" >/dev/null 2>&1; then : else ac_cv_header_stdc=no fi rm -f conftest* fi if test $ac_cv_header_stdc = yes; then # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include _ACEOF if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | $EGREP "free" >/dev/null 2>&1; then : else ac_cv_header_stdc=no fi rm -f conftest* fi if test $ac_cv_header_stdc = yes; then # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi. if test "$cross_compiling" = yes; then : : else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include #if ((' ' & 0x0FF) == 0x020) # define ISLOWER(c) ('a' <= (c) && (c) <= 'z') # define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c)) #else # define ISLOWER(c) \ (('a' <= (c) && (c) <= 'i') \ || ('j' <= (c) && (c) <= 'r') \ || ('s' <= (c) && (c) <= 'z')) # define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c)) #endif #define XOR(e, f) (((e) && !(f)) || (!(e) && (f))) int main () { int i; for (i = 0; i < 256; i++) if (XOR (islower (i), ISLOWER (i)) || toupper (i) != TOUPPER (i)) return 2; return 0; } _ACEOF if ac_fn_c_try_run "$LINENO"; then : else ac_cv_header_stdc=no fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ conftest.$ac_objext conftest.beam conftest.$ac_ext fi fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_stdc" >&5 $as_echo "$ac_cv_header_stdc" >&6; } if test $ac_cv_header_stdc = yes; then $as_echo "#define STDC_HEADERS 1" >>confdefs.h fi # On IRIX 5.3, sys/types and inttypes.h are conflicting. for ac_header in sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \ inttypes.h stdint.h unistd.h do : as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` ac_fn_c_check_header_compile "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default " if eval test \"x\$"$as_ac_Header"\" = x"yes"; then : cat >>confdefs.h <<_ACEOF #define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 _ACEOF fi done for ac_header in auth.h crypt.h features.h inttypes.h paths.h shadow.h stdint.h utmp.h utmpx.h do : as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default" if eval test \"x\$"$as_ac_Header"\" = x"yes"; then : cat >>confdefs.h <<_ACEOF #define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 _ACEOF fi done for ac_header in wchar.h do : ac_fn_c_check_header_mongrel "$LINENO" "wchar.h" "ac_cv_header_wchar_h" "$ac_includes_default" if test "x$ac_cv_header_wchar_h" = xyes; then : cat >>confdefs.h <<_ACEOF #define HAVE_WCHAR_H 1 _ACEOF # The cast to long int works around a bug in the HP C Compiler # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. # This bug is HP SR number 8606223364. { $as_echo "$as_me:${as_lineno-$LINENO}: checking size of wchar_t" >&5 $as_echo_n "checking size of wchar_t... " >&6; } if ${ac_cv_sizeof_wchar_t+:} false; then : $as_echo_n "(cached) " >&6 else if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (wchar_t))" "ac_cv_sizeof_wchar_t" "#include #include "; then : else if test "$ac_cv_type_wchar_t" = yes; then { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error 77 "cannot compute sizeof (wchar_t) See \`config.log' for more details" "$LINENO" 5; } else ac_cv_sizeof_wchar_t=0 fi fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sizeof_wchar_t" >&5 $as_echo "$ac_cv_sizeof_wchar_t" >&6; } cat >>confdefs.h <<_ACEOF #define SIZEOF_WCHAR_T $ac_cv_sizeof_wchar_t _ACEOF for ac_header in wctype.h do : ac_fn_c_check_header_mongrel "$LINENO" "wctype.h" "ac_cv_header_wctype_h" "$ac_includes_default" if test "x$ac_cv_header_wctype_h" = xyes; then : cat >>confdefs.h <<_ACEOF #define HAVE_WCTYPE_H 1 _ACEOF fi done fi done ac_header_dirent=no for ac_hdr in dirent.h sys/ndir.h sys/dir.h ndir.h; do as_ac_Header=`$as_echo "ac_cv_header_dirent_$ac_hdr" | $as_tr_sh` { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_hdr that defines DIR" >&5 $as_echo_n "checking for $ac_hdr that defines DIR... " >&6; } if eval \${$as_ac_Header+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include <$ac_hdr> int main () { if ((DIR *) 0) return 0; ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : eval "$as_ac_Header=yes" else eval "$as_ac_Header=no" fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi eval ac_res=\$$as_ac_Header { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 $as_echo "$ac_res" >&6; } if eval test \"x\$"$as_ac_Header"\" = x"yes"; then : cat >>confdefs.h <<_ACEOF #define `$as_echo "HAVE_$ac_hdr" | $as_tr_cpp` 1 _ACEOF ac_header_dirent=$ac_hdr; break fi done # Two versions of opendir et al. are in -ldir and -lx on SCO Xenix. if test $ac_header_dirent = dirent.h; then { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing opendir" >&5 $as_echo_n "checking for library containing opendir... " >&6; } if ${ac_cv_search_opendir+:} false; then : $as_echo_n "(cached) " >&6 else ac_func_search_save_LIBS=$LIBS cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. */ #ifdef __cplusplus extern "C" #endif char opendir (); int main () { return opendir (); ; return 0; } _ACEOF for ac_lib in '' dir; do if test -z "$ac_lib"; then ac_res="none required" else ac_res=-l$ac_lib LIBS="-l$ac_lib $ac_func_search_save_LIBS" fi if ac_fn_c_try_link "$LINENO"; then : ac_cv_search_opendir=$ac_res fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext if ${ac_cv_search_opendir+:} false; then : break fi done if ${ac_cv_search_opendir+:} false; then : else ac_cv_search_opendir=no fi rm conftest.$ac_ext LIBS=$ac_func_search_save_LIBS fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_opendir" >&5 $as_echo "$ac_cv_search_opendir" >&6; } ac_res=$ac_cv_search_opendir if test "$ac_res" != no; then : test "$ac_res" = "none required" || LIBS="$ac_res $LIBS" fi else { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing opendir" >&5 $as_echo_n "checking for library containing opendir... " >&6; } if ${ac_cv_search_opendir+:} false; then : $as_echo_n "(cached) " >&6 else ac_func_search_save_LIBS=$LIBS cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. */ #ifdef __cplusplus extern "C" #endif char opendir (); int main () { return opendir (); ; return 0; } _ACEOF for ac_lib in '' x; do if test -z "$ac_lib"; then ac_res="none required" else ac_res=-l$ac_lib LIBS="-l$ac_lib $ac_func_search_save_LIBS" fi if ac_fn_c_try_link "$LINENO"; then : ac_cv_search_opendir=$ac_res fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext if ${ac_cv_search_opendir+:} false; then : break fi done if ${ac_cv_search_opendir+:} false; then : else ac_cv_search_opendir=no fi rm conftest.$ac_ext LIBS=$ac_func_search_save_LIBS fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_opendir" >&5 $as_echo "$ac_cv_search_opendir" >&6; } ac_res=$ac_cv_search_opendir if test "$ac_res" != no; then : test "$ac_res" = "none required" || LIBS="$ac_res $LIBS" fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether stat file-mode macros are broken" >&5 $as_echo_n "checking whether stat file-mode macros are broken... " >&6; } if ${ac_cv_header_stat_broken+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include #if defined S_ISBLK && defined S_IFDIR extern char c1[S_ISBLK (S_IFDIR) ? -1 : 1]; #endif #if defined S_ISBLK && defined S_IFCHR extern char c2[S_ISBLK (S_IFCHR) ? -1 : 1]; #endif #if defined S_ISLNK && defined S_IFREG extern char c3[S_ISLNK (S_IFREG) ? -1 : 1]; #endif #if defined S_ISSOCK && defined S_IFREG extern char c4[S_ISSOCK (S_IFREG) ? -1 : 1]; #endif _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_header_stat_broken=no else ac_cv_header_stat_broken=yes fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_stat_broken" >&5 $as_echo "$ac_cv_header_stat_broken" >&6; } if test $ac_cv_header_stat_broken = yes; then $as_echo "#define STAT_MACROS_BROKEN 1" >>confdefs.h fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5 $as_echo_n "checking for ANSI C header files... " >&6; } if ${ac_cv_header_stdc+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include #include #include int main () { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_header_stdc=yes else ac_cv_header_stdc=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext if test $ac_cv_header_stdc = yes; then # SunOS 4.x string.h does not declare mem*, contrary to ANSI. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include _ACEOF if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | $EGREP "memchr" >/dev/null 2>&1; then : else ac_cv_header_stdc=no fi rm -f conftest* fi if test $ac_cv_header_stdc = yes; then # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include _ACEOF if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | $EGREP "free" >/dev/null 2>&1; then : else ac_cv_header_stdc=no fi rm -f conftest* fi if test $ac_cv_header_stdc = yes; then # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi. if test "$cross_compiling" = yes; then : : else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include #if ((' ' & 0x0FF) == 0x020) # define ISLOWER(c) ('a' <= (c) && (c) <= 'z') # define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c)) #else # define ISLOWER(c) \ (('a' <= (c) && (c) <= 'i') \ || ('j' <= (c) && (c) <= 'r') \ || ('s' <= (c) && (c) <= 'z')) # define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c)) #endif #define XOR(e, f) (((e) && !(f)) || (!(e) && (f))) int main () { int i; for (i = 0; i < 256; i++) if (XOR (islower (i), ISLOWER (i)) || toupper (i) != TOUPPER (i)) return 2; return 0; } _ACEOF if ac_fn_c_try_run "$LINENO"; then : else ac_cv_header_stdc=no fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ conftest.$ac_objext conftest.beam conftest.$ac_ext fi fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_stdc" >&5 $as_echo "$ac_cv_header_stdc" >&6; } if test $ac_cv_header_stdc = yes; then $as_echo "#define STDC_HEADERS 1" >>confdefs.h fi ac_fn_c_check_type "$LINENO" "long long" "ac_cv_type_long_long" "$ac_includes_default" if test "x$ac_cv_type_long_long" = xyes; then : cat >>confdefs.h <<_ACEOF #define HAVE_LONG_LONG 1 _ACEOF fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for uid_t in sys/types.h" >&5 $as_echo_n "checking for uid_t in sys/types.h... " >&6; } if ${ac_cv_type_uid_t+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include _ACEOF if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | $EGREP "uid_t" >/dev/null 2>&1; then : ac_cv_type_uid_t=yes else ac_cv_type_uid_t=no fi rm -f conftest* fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_type_uid_t" >&5 $as_echo "$ac_cv_type_uid_t" >&6; } if test $ac_cv_type_uid_t = no; then $as_echo "#define uid_t int" >>confdefs.h $as_echo "#define gid_t int" >>confdefs.h fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking type of array argument to getgroups" >&5 $as_echo_n "checking type of array argument to getgroups... " >&6; } if ${ac_cv_type_getgroups+:} false; then : $as_echo_n "(cached) " >&6 else if test "$cross_compiling" = yes; then : ac_cv_type_getgroups=cross else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Thanks to Mike Rendell for this test. */ $ac_includes_default #define NGID 256 #undef MAX #define MAX(x, y) ((x) > (y) ? (x) : (y)) int main () { gid_t gidset[NGID]; int i, n; union { gid_t gval; long int lval; } val; val.lval = -1; for (i = 0; i < NGID; i++) gidset[i] = val.gval; n = getgroups (sizeof (gidset) / MAX (sizeof (int), sizeof (gid_t)) - 1, gidset); /* Exit non-zero if getgroups seems to require an array of ints. This happens when gid_t is short int but getgroups modifies an array of ints. */ return n > 0 && gidset[n] != val.gval; } _ACEOF if ac_fn_c_try_run "$LINENO"; then : ac_cv_type_getgroups=gid_t else ac_cv_type_getgroups=int fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ conftest.$ac_objext conftest.beam conftest.$ac_ext fi if test $ac_cv_type_getgroups = cross; then cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include _ACEOF if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | $EGREP "getgroups.*int.*gid_t" >/dev/null 2>&1; then : ac_cv_type_getgroups=gid_t else ac_cv_type_getgroups=int fi rm -f conftest* fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_type_getgroups" >&5 $as_echo "$ac_cv_type_getgroups" >&6; } cat >>confdefs.h <<_ACEOF #define GETGROUPS_T $ac_cv_type_getgroups _ACEOF ac_fn_c_check_type "$LINENO" "mode_t" "ac_cv_type_mode_t" "$ac_includes_default" if test "x$ac_cv_type_mode_t" = xyes; then : else cat >>confdefs.h <<_ACEOF #define mode_t int _ACEOF fi ac_fn_c_check_type "$LINENO" "size_t" "ac_cv_type_size_t" "$ac_includes_default" if test "x$ac_cv_type_size_t" = xyes; then : else cat >>confdefs.h <<_ACEOF #define size_t unsigned int _ACEOF fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for uid_t in sys/types.h" >&5 $as_echo_n "checking for uid_t in sys/types.h... " >&6; } if ${ac_cv_type_uid_t+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include _ACEOF if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | $EGREP "uid_t" >/dev/null 2>&1; then : ac_cv_type_uid_t=yes else ac_cv_type_uid_t=no fi rm -f conftest* fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_type_uid_t" >&5 $as_echo "$ac_cv_type_uid_t" >&6; } if test $ac_cv_type_uid_t = no; then $as_echo "#define uid_t int" >>confdefs.h $as_echo "#define gid_t int" >>confdefs.h fi ac_fn_c_find_uintX_t "$LINENO" "32" "ac_cv_c_uint32_t" case $ac_cv_c_uint32_t in #( no|yes) ;; #( *) $as_echo "#define _UINT32_T 1" >>confdefs.h cat >>confdefs.h <<_ACEOF #define uint32_t $ac_cv_c_uint32_t _ACEOF ;; esac ac_fn_c_check_type "$LINENO" "ssize_t" "ac_cv_type_ssize_t" " #include " if test "x$ac_cv_type_ssize_t" = xyes; then : else $as_echo "#define ssize_t int" >>confdefs.h fi ac_fn_c_check_type "$LINENO" "socklen_t" "ac_cv_type_socklen_t" " #include #include " if test "x$ac_cv_type_socklen_t" = xyes; then : else $as_echo "#define socklen_t int" >>confdefs.h fi ac_fn_c_check_member "$LINENO" "struct dirent" "d_ino" "ac_cv_member_struct_dirent_d_ino" "#ifdef HAVE_DIRENT_H # include #else # ifdef HAVE_NDIR_H # include # else # include # endif # define dirent direct #endif " if test "x$ac_cv_member_struct_dirent_d_ino" = xyes; then : cat >>confdefs.h <<_ACEOF #define HAVE_STRUCT_DIRENT_D_INO 1 _ACEOF fi ac_fn_c_check_member "$LINENO" "struct utmp" "ut_host" "ac_cv_member_struct_utmp_ut_host" "#include #ifdef HAVE_UTMPX_H #include #define utmp utmpx #elif defined HAVE_UTMP_H #include #endif " if test "x$ac_cv_member_struct_utmp_ut_host" = xyes; then : cat >>confdefs.h <<_ACEOF #define HAVE_STRUCT_UTMP_UT_HOST 1 _ACEOF fi ac_fn_c_check_member "$LINENO" "struct utmp" "ut_user" "ac_cv_member_struct_utmp_ut_user" "#include #ifdef HAVE_UTMPX_H #include #define utmp utmpx #elif defined HAVE_UTMP_H #include #endif " if test "x$ac_cv_member_struct_utmp_ut_user" = xyes; then : cat >>confdefs.h <<_ACEOF #define HAVE_STRUCT_UTMP_UT_USER 1 _ACEOF fi ac_fn_c_check_member "$LINENO" "struct utmp" "ut_tv" "ac_cv_member_struct_utmp_ut_tv" "#include #ifdef HAVE_UTMPX_H #include #define utmp utmpx #elif defined HAVE_UTMP_H #include #endif " if test "x$ac_cv_member_struct_utmp_ut_tv" = xyes; then : cat >>confdefs.h <<_ACEOF #define HAVE_STRUCT_UTMP_UT_TV 1 _ACEOF fi ac_fn_c_check_member "$LINENO" "struct utmp" "ut_xtime" "ac_cv_member_struct_utmp_ut_xtime" "#include #ifdef HAVE_UTMPX_H #include #define utmp utmpx #elif defined HAVE_UTMP_H #include #endif " if test "x$ac_cv_member_struct_utmp_ut_xtime" = xyes; then : cat >>confdefs.h <<_ACEOF #define HAVE_STRUCT_UTMP_UT_XTIME 1 _ACEOF fi ac_fn_c_check_member "$LINENO" "struct utmpx" "ut_host" "ac_cv_member_struct_utmpx_ut_host" "#include #ifdef HAVE_UTMPX_H #include #define utmp utmpx #elif defined HAVE_UTMP_H #include #endif " if test "x$ac_cv_member_struct_utmpx_ut_host" = xyes; then : cat >>confdefs.h <<_ACEOF #define HAVE_STRUCT_UTMPX_UT_HOST 1 _ACEOF fi ac_fn_c_check_member "$LINENO" "struct utmpx" "ut_user" "ac_cv_member_struct_utmpx_ut_user" "#include #ifdef HAVE_UTMPX_H #include #define utmp utmpx #elif defined HAVE_UTMP_H #include #endif " if test "x$ac_cv_member_struct_utmpx_ut_user" = xyes; then : cat >>confdefs.h <<_ACEOF #define HAVE_STRUCT_UTMPX_UT_USER 1 _ACEOF fi ac_fn_c_check_member "$LINENO" "struct utmpx" "ut_tv" "ac_cv_member_struct_utmpx_ut_tv" "#include #ifdef HAVE_UTMPX_H #include #define utmp utmpx #elif defined HAVE_UTMP_H #include #endif " if test "x$ac_cv_member_struct_utmpx_ut_tv" = xyes; then : cat >>confdefs.h <<_ACEOF #define HAVE_STRUCT_UTMPX_UT_TV 1 _ACEOF fi ac_fn_c_check_member "$LINENO" "struct utmpx" "ut_xtime" "ac_cv_member_struct_utmpx_ut_xtime" "#include #ifdef HAVE_UTMPX_H #include #define utmp utmpx #elif defined HAVE_UTMP_H #include #endif " if test "x$ac_cv_member_struct_utmpx_ut_xtime" = xyes; then : cat >>confdefs.h <<_ACEOF #define HAVE_STRUCT_UTMPX_UT_XTIME 1 _ACEOF fi ac_fn_c_check_member "$LINENO" "struct sockaddr_storage" "ss_family" "ac_cv_member_struct_sockaddr_storage_ss_family" "#include #include " if test "x$ac_cv_member_struct_sockaddr_storage_ss_family" = xyes; then : cat >>confdefs.h <<_ACEOF #define HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY 1 _ACEOF fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for an ANSI C-conforming const" >&5 $as_echo_n "checking for an ANSI C-conforming const... " >&6; } if ${ac_cv_c_const+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { #ifndef __cplusplus /* Ultrix mips cc rejects this sort of thing. */ typedef int charset[2]; const charset cs = { 0, 0 }; /* SunOS 4.1.1 cc rejects this. */ char const *const *pcpcc; char **ppc; /* NEC SVR4.0.2 mips cc rejects this. */ struct point {int x, y;}; static struct point const zero = {0,0}; /* AIX XL C 1.02.0.0 rejects this. It does not let you subtract one const X* pointer from another in an arm of an if-expression whose if-part is not a constant expression */ const char *g = "string"; pcpcc = &g + (g ? g-g : 0); /* HPUX 7.0 cc rejects these. */ ++pcpcc; ppc = (char**) pcpcc; pcpcc = (char const *const *) ppc; { /* SCO 3.2v4 cc rejects this sort of thing. */ char tx; char *t = &tx; char const *s = 0 ? (char *) 0 : (char const *) 0; *t++ = 0; if (s) return 0; } { /* Someone thinks the Sun supposedly-ANSI compiler will reject this. */ int x[] = {25, 17}; const int *foo = &x[0]; ++foo; } { /* Sun SC1.0 ANSI compiler rejects this -- but not the above. */ typedef const int *iptr; iptr p = 0; ++p; } { /* AIX XL C 1.02.0.0 rejects this sort of thing, saying "k.c", line 2.27: 1506-025 (S) Operand must be a modifiable lvalue. */ struct s { int j; const int *ap[3]; } bx; struct s *b = &bx; b->j = 5; } { /* ULTRIX-32 V3.1 (Rev 9) vcc rejects this */ const int foo = 10; if (!foo) return 0; } return !cs[0] && !zero.x; #endif ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_c_const=yes else ac_cv_c_const=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_const" >&5 $as_echo "$ac_cv_c_const" >&6; } if test $ac_cv_c_const = no; then $as_echo "#define const /**/" >>confdefs.h fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for working volatile" >&5 $as_echo_n "checking for working volatile... " >&6; } if ${ac_cv_c_volatile+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { volatile int x; int * volatile y = (int *) 0; return !x && !y; ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_c_volatile=yes else ac_cv_c_volatile=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_volatile" >&5 $as_echo "$ac_cv_c_volatile" >&6; } if test $ac_cv_c_volatile = no; then $as_echo "#define volatile /**/" >>confdefs.h fi ac_fn_c_check_decl "$LINENO" "crypt" "ac_cv_have_decl_crypt" "#include \"config_p.h\" $ac_includes_default #ifdef HAVE_CRYPT_H #include #endif " if test "x$ac_cv_have_decl_crypt" = xyes; then : ac_have_decl=1 else ac_have_decl=0 fi cat >>confdefs.h <<_ACEOF #define HAVE_DECL_CRYPT $ac_have_decl _ACEOF ac_fn_c_check_decl "$LINENO" "environ" "ac_cv_have_decl_environ" "#include \"config_p.h\" $ac_includes_default #ifdef HAVE_CRYPT_H #include #endif " if test "x$ac_cv_have_decl_environ" = xyes; then : ac_have_decl=1 else ac_have_decl=0 fi cat >>confdefs.h <<_ACEOF #define HAVE_DECL_ENVIRON $ac_have_decl _ACEOF ac_fn_c_check_decl "$LINENO" "gethostname" "ac_cv_have_decl_gethostname" "#include \"config_p.h\" $ac_includes_default #ifdef HAVE_CRYPT_H #include #endif " if test "x$ac_cv_have_decl_gethostname" = xyes; then : ac_have_decl=1 else ac_have_decl=0 fi cat >>confdefs.h <<_ACEOF #define HAVE_DECL_GETHOSTNAME $ac_have_decl _ACEOF ac_fn_c_check_decl "$LINENO" "getpgrp" "ac_cv_have_decl_getpgrp" "#include \"config_p.h\" $ac_includes_default #ifdef HAVE_CRYPT_H #include #endif " if test "x$ac_cv_have_decl_getpgrp" = xyes; then : ac_have_decl=1 else ac_have_decl=0 fi cat >>confdefs.h <<_ACEOF #define HAVE_DECL_GETPGRP $ac_have_decl _ACEOF ac_fn_c_check_func "$LINENO" "setlocale" "ac_cv_func_setlocale" if test "x$ac_cv_func_setlocale" = xyes; then : have_setlocale=yes else have_setlocale=no fi ac_fn_c_check_func "$LINENO" "catgets" "ac_cv_func_catgets" if test "x$ac_cv_func_catgets" = xyes; then : have_catgets=yes else have_catgets=no fi for ac_func in dup2 getauthid getcwd gethostname getpwent getutent getutxent mallinfo mblen memmove memset mkstemp nice nl_langinfo sbrk setpgid setpriority strerror strstr sysconf wcwidth do : as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" if eval test \"x\$"$as_ac_var"\" = x"yes"; then : cat >>confdefs.h <<_ACEOF #define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 _ACEOF fi done { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether getpgrp requires zero arguments" >&5 $as_echo_n "checking whether getpgrp requires zero arguments... " >&6; } if ${ac_cv_func_getpgrp_void+:} false; then : $as_echo_n "(cached) " >&6 else # Use it with a single arg. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $ac_includes_default int main () { getpgrp (0); ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_func_getpgrp_void=no else ac_cv_func_getpgrp_void=yes fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_getpgrp_void" >&5 $as_echo "$ac_cv_func_getpgrp_void" >&6; } if test $ac_cv_func_getpgrp_void = yes; then $as_echo "#define GETPGRP_VOID 1" >>confdefs.h fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether mbrtowc and mbstate_t are properly declared" >&5 $as_echo_n "checking whether mbrtowc and mbstate_t are properly declared... " >&6; } if ${ac_cv_func_mbrtowc+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include int main () { wchar_t wc; char const s[] = ""; size_t n = 1; mbstate_t state; return ! (sizeof state && (mbrtowc) (&wc, s, n, &state)); ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : ac_cv_func_mbrtowc=yes else ac_cv_func_mbrtowc=no fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_mbrtowc" >&5 $as_echo "$ac_cv_func_mbrtowc" >&6; } if test $ac_cv_func_mbrtowc = yes; then $as_echo "#define HAVE_MBRTOWC 1" >>confdefs.h fi if test "x${cross_compiling}" != xyes ; then { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether setpgrp takes no argument" >&5 $as_echo_n "checking whether setpgrp takes no argument... " >&6; } if ${ac_cv_func_setpgrp_void+:} false; then : $as_echo_n "(cached) " >&6 else if test "$cross_compiling" = yes; then : as_fn_error $? "cannot check setpgrp when cross compiling" "$LINENO" 5 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $ac_includes_default int main () { /* If this system has a BSD-style setpgrp which takes arguments, setpgrp(1, 1) will fail with ESRCH and return -1, in that case exit successfully. */ return setpgrp (1,1) != -1; ; return 0; } _ACEOF if ac_fn_c_try_run "$LINENO"; then : ac_cv_func_setpgrp_void=no else ac_cv_func_setpgrp_void=yes fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ conftest.$ac_objext conftest.beam conftest.$ac_ext fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_setpgrp_void" >&5 $as_echo "$ac_cv_func_setpgrp_void" >&6; } if test $ac_cv_func_setpgrp_void = yes; then $as_echo "#define SETPGRP_VOID 1" >>confdefs.h fi else ac_cv_func_setpgrp_void=yes fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for working strcoll" >&5 $as_echo_n "checking for working strcoll... " >&6; } if ${ac_cv_func_strcoll_works+:} false; then : $as_echo_n "(cached) " >&6 else if test "$cross_compiling" = yes; then : ac_cv_func_strcoll_works=no else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $ac_includes_default int main () { return (strcoll ("abc", "def") >= 0 || strcoll ("ABC", "DEF") >= 0 || strcoll ("123", "456") >= 0) ; return 0; } _ACEOF if ac_fn_c_try_run "$LINENO"; then : ac_cv_func_strcoll_works=yes else ac_cv_func_strcoll_works=no fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ conftest.$ac_objext conftest.beam conftest.$ac_ext fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_strcoll_works" >&5 $as_echo "$ac_cv_func_strcoll_works" >&6; } if test $ac_cv_func_strcoll_works = yes; then $as_echo "#define HAVE_STRCOLL 1" >>confdefs.h fi if test "$have_setlocale" != no; then # Check whether --enable-nls was given. if test "${enable_nls+set}" = set; then : enableval=$enable_nls; else enable_nls=yes fi if test "x$enable_nls" != xno; then $as_echo "#define NLS 1" >>confdefs.h fi fi if test "x$enable_nls" != xno -a "$have_catgets" != no -a -n "$GENCAT" ; then # Check whether --enable-nls-catalogs was given. if test "${enable_nls_catalogs+set}" = set; then : enableval=$enable_nls_catalogs; else enable_nls_catalogs=yes fi if test "x$enable_nls_catalogs" != xno; then BUILD_CATALOGS="yes" $as_echo "#define NLS_CATALOGS 1" >>confdefs.h fi fi # Check whether --with-hesiod was given. if test "${with_hesiod+set}" = set; then : withval=$with_hesiod; hesiod="$withval" else hesiod=no fi if test "$hesiod" != no; then HESLIB="-lhesiod" ac_fn_c_check_func "$LINENO" "res_send" "ac_cv_func_res_send" if test "x$ac_cv_func_res_send" = xyes; then : : else { $as_echo "$as_me:${as_lineno-$LINENO}: checking for res_send in -lresolv" >&5 $as_echo_n "checking for res_send in -lresolv... " >&6; } if ${ac_cv_lib_resolv_res_send+:} false; then : $as_echo_n "(cached) " >&6 else ac_check_lib_save_LIBS=$LIBS LIBS="-lresolv $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. */ #ifdef __cplusplus extern "C" #endif char res_send (); int main () { return res_send (); ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : ac_cv_lib_resolv_res_send=yes else ac_cv_lib_resolv_res_send=no fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_resolv_res_send" >&5 $as_echo "$ac_cv_lib_resolv_res_send" >&6; } if test "x$ac_cv_lib_resolv_res_send" = xyes; then : HESLIB="$HESLIB -lresolv" fi fi HESDEF=-DHESIOD if test "$hesiod" != yes; then HESDEF="$HESDEF -I$hesiod/include" HESLIB="-L$hesiod/lib $HESLIB" fi fi ac_config_files="$ac_config_files Makefile nls/Makefile" cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure # tests run on this system so they can be shared between configure # scripts and configure runs, see configure's option --config-cache. # It is not useful on other systems. If it contains results you don't # want to keep, you may remove or edit it. # # config.status only pays attention to the cache file if you give it # the --recheck option to rerun configure. # # `ac_cv_env_foo' variables (set or unset) will be overridden when # loading this file, other *unset* `ac_cv_foo' will be assigned the # following values. _ACEOF # The following way of writing the cache mishandles newlines in values, # but we know of no workaround that is simple, portable, and efficient. # So, we kill variables containing newlines. # Ultrix sh set writes to stderr and can't be redirected directly, # and sets the high bit in the cache file unless we assign to the vars. ( for ac_var in `(set) 2>&1 | sed -n 's/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'`; do eval ac_val=\$$ac_var case $ac_val in #( *${as_nl}*) case $ac_var in #( *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 $as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; esac case $ac_var in #( _ | IFS | as_nl) ;; #( BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #( *) { eval $ac_var=; unset $ac_var;} ;; esac ;; esac done (set) 2>&1 | case $as_nl`(ac_space=' '; set) 2>&1` in #( *${as_nl}ac_space=\ *) # `set' does not quote correctly, so add quotes: double-quote # substitution turns \\\\ into \\, and sed turns \\ into \. sed -n \ "s/'/'\\\\''/g; s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p" ;; #( *) # `set' quotes correctly as required by POSIX, so do not add quotes. sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" ;; esac | sort ) | sed ' /^ac_cv_env_/b end t clear :clear s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/ t end s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/ :end' >>confcache if diff "$cache_file" confcache >/dev/null 2>&1; then :; else if test -w "$cache_file"; then if test "x$cache_file" != "x/dev/null"; then { $as_echo "$as_me:${as_lineno-$LINENO}: updating cache $cache_file" >&5 $as_echo "$as_me: updating cache $cache_file" >&6;} if test ! -f "$cache_file" || test -h "$cache_file"; then cat confcache >"$cache_file" else case $cache_file in #( */* | ?:*) mv -f confcache "$cache_file"$$ && mv -f "$cache_file"$$ "$cache_file" ;; #( *) mv -f confcache "$cache_file" ;; esac fi fi else { $as_echo "$as_me:${as_lineno-$LINENO}: not updating unwritable cache $cache_file" >&5 $as_echo "$as_me: not updating unwritable cache $cache_file" >&6;} fi fi rm -f confcache test "x$prefix" = xNONE && prefix=$ac_default_prefix # Let make expand exec_prefix. test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' DEFS=-DHAVE_CONFIG_H ac_libobjs= ac_ltlibobjs= U= for ac_i in : $LIBOBJS; do test "x$ac_i" = x: && continue # 1. Remove the extension, and $U if already installed. ac_script='s/\$U\././;s/\.o$//;s/\.obj$//' ac_i=`$as_echo "$ac_i" | sed "$ac_script"` # 2. Prepend LIBOBJDIR. When used with automake>=1.10 LIBOBJDIR # will be set to the directory where LIBOBJS objects are built. as_fn_append ac_libobjs " \${LIBOBJDIR}$ac_i\$U.$ac_objext" as_fn_append ac_ltlibobjs " \${LIBOBJDIR}$ac_i"'$U.lo' done LIBOBJS=$ac_libobjs LTLIBOBJS=$ac_ltlibobjs : "${CONFIG_STATUS=./config.status}" ac_write_fail=0 ac_clean_files_save=$ac_clean_files ac_clean_files="$ac_clean_files $CONFIG_STATUS" { $as_echo "$as_me:${as_lineno-$LINENO}: creating $CONFIG_STATUS" >&5 $as_echo "$as_me: creating $CONFIG_STATUS" >&6;} as_write_fail=0 cat >$CONFIG_STATUS <<_ASEOF || as_write_fail=1 #! $SHELL # Generated by $as_me. # Run this file to recreate the current configuration. # Compiler output produced by configure, useful for debugging # configure, is in config.log if it exists. debug=false ac_cs_recheck=false ac_cs_silent=false SHELL=\${CONFIG_SHELL-$SHELL} export SHELL _ASEOF cat >>$CONFIG_STATUS <<\_ASEOF || as_write_fail=1 ## -------------------- ## ## M4sh Initialization. ## ## -------------------- ## # Be more Bourne compatible DUALCASE=1; export DUALCASE # for MKS sh if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then : emulate sh NULLCMD=: # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which # is contrary to our usage. Disable this feature. alias -g '${1+"$@"}'='"$@"' setopt NO_GLOB_SUBST else case `(set -o) 2>/dev/null` in #( *posix*) : set -o posix ;; #( *) : ;; esac fi as_nl=' ' export as_nl # Printing a long string crashes Solaris 7 /usr/bin/printf. as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo # Prefer a ksh shell builtin over an external printf program on Solaris, # but without wasting forks for bash or zsh. if test -z "$BASH_VERSION$ZSH_VERSION" \ && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then as_echo='print -r --' as_echo_n='print -rn --' elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then as_echo='printf %s\n' as_echo_n='printf %s' else if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"' as_echo_n='/usr/ucb/echo -n' else as_echo_body='eval expr "X$1" : "X\\(.*\\)"' as_echo_n_body='eval arg=$1; case $arg in #( *"$as_nl"*) expr "X$arg" : "X\\(.*\\)$as_nl"; arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;; esac; expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl" ' export as_echo_n_body as_echo_n='sh -c $as_echo_n_body as_echo' fi export as_echo_body as_echo='sh -c $as_echo_body as_echo' fi # The user is always right. if test "${PATH_SEPARATOR+set}" != set; then PATH_SEPARATOR=: (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && { (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 || PATH_SEPARATOR=';' } fi # IFS # We need space, tab and new line, in precisely that order. Quoting is # there to prevent editors from complaining about space-tab. # (If _AS_PATH_WALK were called with IFS unset, it would disable word # splitting by setting IFS to empty value.) IFS=" "" $as_nl" # Find who we are. Look in the path if we contain no directory separator. as_myself= case $0 in #(( *[\\/]* ) as_myself=$0 ;; *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break done IFS=$as_save_IFS ;; esac # We did not find ourselves, most probably we were run as `sh COMMAND' # in which case we are not to be found in the path. if test "x$as_myself" = x; then as_myself=$0 fi if test ! -f "$as_myself"; then $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 exit 1 fi # Unset variables that we do not need and which cause bugs (e.g. in # pre-3.0 UWIN ksh). But do not cause bugs in bash 2.01; the "|| exit 1" # suppresses any "Segmentation fault" message there. '((' could # trigger a bug in pdksh 5.2.14. for as_var in BASH_ENV ENV MAIL MAILPATH do eval test x\${$as_var+set} = xset \ && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : done PS1='$ ' PS2='> ' PS4='+ ' # NLS nuisances. LC_ALL=C export LC_ALL LANGUAGE=C export LANGUAGE # CDPATH. (unset CDPATH) >/dev/null 2>&1 && unset CDPATH # as_fn_error STATUS ERROR [LINENO LOG_FD] # ---------------------------------------- # Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are # provided, also output the error to LOG_FD, referencing LINENO. Then exit the # script with STATUS, using 1 if that was 0. as_fn_error () { as_status=$1; test $as_status -eq 0 && as_status=1 if test "$4"; then as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4 fi $as_echo "$as_me: error: $2" >&2 as_fn_exit $as_status } # as_fn_error # as_fn_set_status STATUS # ----------------------- # Set $? to STATUS, without forking. as_fn_set_status () { return $1 } # as_fn_set_status # as_fn_exit STATUS # ----------------- # Exit the shell with STATUS, even in a "trap 0" or "set -e" context. as_fn_exit () { set +e as_fn_set_status $1 exit $1 } # as_fn_exit # as_fn_unset VAR # --------------- # Portably unset VAR. as_fn_unset () { { eval $1=; unset $1;} } as_unset=as_fn_unset # as_fn_append VAR VALUE # ---------------------- # Append the text in VALUE to the end of the definition contained in VAR. Take # advantage of any shell optimizations that allow amortized linear growth over # repeated appends, instead of the typical quadratic growth present in naive # implementations. if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then : eval 'as_fn_append () { eval $1+=\$2 }' else as_fn_append () { eval $1=\$$1\$2 } fi # as_fn_append # as_fn_arith ARG... # ------------------ # Perform arithmetic evaluation on the ARGs, and store the result in the # global $as_val. Take advantage of shells that can avoid forks. The arguments # must be portable across $(()) and expr. if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then : eval 'as_fn_arith () { as_val=$(( $* )) }' else as_fn_arith () { as_val=`expr "$@" || test $? -eq 1` } fi # as_fn_arith if expr a : '\(a\)' >/dev/null 2>&1 && test "X`expr 00001 : '.*\(...\)'`" = X001; then as_expr=expr else as_expr=false fi if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then as_basename=basename else as_basename=false fi if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then as_dirname=dirname else as_dirname=false fi as_me=`$as_basename -- "$0" || $as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ X"$0" : 'X\(//\)$' \| \ X"$0" : 'X\(/\)' \| . 2>/dev/null || $as_echo X/"$0" | sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/ q } /^X\/\(\/\/\)$/{ s//\1/ q } /^X\/\(\/\).*/{ s//\1/ q } s/.*/./; q'` # Avoid depending upon Character Ranges. as_cr_letters='abcdefghijklmnopqrstuvwxyz' as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' as_cr_Letters=$as_cr_letters$as_cr_LETTERS as_cr_digits='0123456789' as_cr_alnum=$as_cr_Letters$as_cr_digits ECHO_C= ECHO_N= ECHO_T= case `echo -n x` in #((((( -n*) case `echo 'xy\c'` in *c*) ECHO_T=' ';; # ECHO_T is single tab character. xy) ECHO_C='\c';; *) echo `echo ksh88 bug on AIX 6.1` > /dev/null ECHO_T=' ';; esac;; *) ECHO_N='-n';; esac rm -f conf$$ conf$$.exe conf$$.file if test -d conf$$.dir; then rm -f conf$$.dir/conf$$.file else rm -f conf$$.dir mkdir conf$$.dir 2>/dev/null fi if (echo >conf$$.file) 2>/dev/null; then if ln -s conf$$.file conf$$ 2>/dev/null; then as_ln_s='ln -s' # ... but there are two gotchas: # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. # In both cases, we have to default to `cp -pR'. ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || as_ln_s='cp -pR' elif ln conf$$.file conf$$ 2>/dev/null; then as_ln_s=ln else as_ln_s='cp -pR' fi else as_ln_s='cp -pR' fi rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file rmdir conf$$.dir 2>/dev/null # as_fn_mkdir_p # ------------- # Create "$as_dir" as a directory, including parents if necessary. as_fn_mkdir_p () { case $as_dir in #( -*) as_dir=./$as_dir;; esac test -d "$as_dir" || eval $as_mkdir_p || { as_dirs= while :; do case $as_dir in #( *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( *) as_qdir=$as_dir;; esac as_dirs="'$as_qdir' $as_dirs" as_dir=`$as_dirname -- "$as_dir" || $as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$as_dir" : 'X\(//\)[^/]' \| \ X"$as_dir" : 'X\(//\)$' \| \ X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || $as_echo X"$as_dir" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q'` test -d "$as_dir" && break done test -z "$as_dirs" || eval "mkdir $as_dirs" } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir" } # as_fn_mkdir_p if mkdir -p . 2>/dev/null; then as_mkdir_p='mkdir -p "$as_dir"' else test -d ./-p && rmdir ./-p as_mkdir_p=false fi # as_fn_executable_p FILE # ----------------------- # Test if FILE is an executable regular file. as_fn_executable_p () { test -f "$1" && test -x "$1" } # as_fn_executable_p as_test_x='test -x' as_executable_p=as_fn_executable_p # Sed expression to map a string onto a valid CPP name. as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" # Sed expression to map a string onto a valid variable name. as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" exec 6>&1 ## ----------------------------------- ## ## Main body of $CONFIG_STATUS script. ## ## ----------------------------------- ## _ASEOF test $as_write_fail = 0 && chmod +x $CONFIG_STATUS || ac_write_fail=1 cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # Save the log message, to keep $0 and so on meaningful, and to # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by tcsh $as_me 6.21.00, which was +This file was extended by tcsh $as_me 6.22.03, which was generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES CONFIG_HEADERS = $CONFIG_HEADERS CONFIG_LINKS = $CONFIG_LINKS CONFIG_COMMANDS = $CONFIG_COMMANDS $ $0 $@ on `(hostname || uname -n) 2>/dev/null | sed 1q` " _ACEOF case $ac_config_files in *" "*) set x $ac_config_files; shift; ac_config_files=$*;; esac case $ac_config_headers in *" "*) set x $ac_config_headers; shift; ac_config_headers=$*;; esac cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 # Files that config.status was made for. config_files="$ac_config_files" config_headers="$ac_config_headers" config_commands="$ac_config_commands" _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 ac_cs_usage="\ \`$as_me' instantiates files and other configuration actions from templates according to the current configuration. Unless the files and actions are specified as TAGs, all are instantiated by default. Usage: $0 [OPTION]... [TAG]... -h, --help print this help, then exit -V, --version print version number and configuration settings, then exit --config print configuration, then exit -q, --quiet, --silent do not print progress messages -d, --debug don't remove temporary files --recheck update $as_me by reconfiguring in the same conditions --file=FILE[:TEMPLATE] instantiate the configuration file FILE --header=FILE[:TEMPLATE] instantiate the configuration header FILE Configuration files: $config_files Configuration headers: $config_headers Configuration commands: $config_commands Report bugs to ." _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -tcsh config.status 6.21.00 +tcsh config.status 6.22.03 configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" Copyright (C) 2012 Free Software Foundation, Inc. This config.status script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it." ac_pwd='$ac_pwd' srcdir='$srcdir' INSTALL='$INSTALL' test -n "\$AWK" || AWK=awk _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # The default lists apply if the user does not specify any file. ac_need_defaults=: while test $# != 0 do case $1 in --*=?*) ac_option=`expr "X$1" : 'X\([^=]*\)='` ac_optarg=`expr "X$1" : 'X[^=]*=\(.*\)'` ac_shift=: ;; --*=) ac_option=`expr "X$1" : 'X\([^=]*\)='` ac_optarg= ac_shift=: ;; *) ac_option=$1 ac_optarg=$2 ac_shift=shift ;; esac case $ac_option in # Handling of the options. -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r) ac_cs_recheck=: ;; --version | --versio | --versi | --vers | --ver | --ve | --v | -V ) $as_echo "$ac_cs_version"; exit ;; --config | --confi | --conf | --con | --co | --c ) $as_echo "$ac_cs_config"; exit ;; --debug | --debu | --deb | --de | --d | -d ) debug=: ;; --file | --fil | --fi | --f ) $ac_shift case $ac_optarg in *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;; '') as_fn_error $? "missing file argument" ;; esac as_fn_append CONFIG_FILES " '$ac_optarg'" ac_need_defaults=false;; --header | --heade | --head | --hea ) $ac_shift case $ac_optarg in *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;; esac as_fn_append CONFIG_HEADERS " '$ac_optarg'" ac_need_defaults=false;; --he | --h) # Conflict between --help and --header as_fn_error $? "ambiguous option: \`$1' Try \`$0 --help' for more information.";; --help | --hel | -h ) $as_echo "$ac_cs_usage"; exit ;; -q | -quiet | --quiet | --quie | --qui | --qu | --q \ | -silent | --silent | --silen | --sile | --sil | --si | --s) ac_cs_silent=: ;; # This is an error. -*) as_fn_error $? "unrecognized option: \`$1' Try \`$0 --help' for more information." ;; *) as_fn_append ac_config_targets " $1" ac_need_defaults=false ;; esac shift done ac_configure_extra_args= if $ac_cs_silent; then exec 6>/dev/null ac_configure_extra_args="$ac_configure_extra_args --silent" fi _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 if \$ac_cs_recheck; then set X $SHELL '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion shift \$as_echo "running CONFIG_SHELL=$SHELL \$*" >&6 CONFIG_SHELL='$SHELL' export CONFIG_SHELL exec "\$@" fi _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 exec 5>>config.log { echo sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX ## Running $as_me. ## _ASBOX $as_echo "$ac_log" } >&5 _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 # # INIT-COMMANDS # _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # Handling of arguments. for ac_config_target in $ac_config_targets do case $ac_config_target in "config.h") CONFIG_HEADERS="$CONFIG_HEADERS config.h" ;; "./atconfig") CONFIG_COMMANDS="$CONFIG_COMMANDS ./atconfig" ;; "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;; "nls/Makefile") CONFIG_FILES="$CONFIG_FILES nls/Makefile" ;; *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;; esac done # If the user did not use the arguments to specify the items to instantiate, # then the envvar interface is used. Set only those that are not. # We use the long form for the default assignment because of an extremely # bizarre bug on SunOS 4.1.3. if $ac_need_defaults; then test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files test "${CONFIG_HEADERS+set}" = set || CONFIG_HEADERS=$config_headers test "${CONFIG_COMMANDS+set}" = set || CONFIG_COMMANDS=$config_commands fi # Have a temporary directory for convenience. Make it in the build tree # simply because there is no reason against having it here, and in addition, # creating and moving files from /tmp can sometimes cause problems. # Hook for its removal unless debugging. # Note that there is a small window in which the directory will not be cleaned: # after its creation but before its name has been assigned to `$tmp'. $debug || { tmp= ac_tmp= trap 'exit_status=$? : "${ac_tmp:=$tmp}" { test ! -d "$ac_tmp" || rm -fr "$ac_tmp"; } && exit $exit_status ' 0 trap 'as_fn_exit 1' 1 2 13 15 } # Create a (secure) tmp directory for tmp files. { tmp=`(umask 077 && mktemp -d "./confXXXXXX") 2>/dev/null` && test -d "$tmp" } || { tmp=./conf$$-$RANDOM (umask 077 && mkdir "$tmp") } || as_fn_error $? "cannot create a temporary directory in ." "$LINENO" 5 ac_tmp=$tmp # Set up the scripts for CONFIG_FILES section. # No need to generate them if there are no CONFIG_FILES. # This happens for instance with `./config.status config.h'. if test -n "$CONFIG_FILES"; then ac_cr=`echo X | tr X '\015'` # On cygwin, bash can eat \r inside `` if the user requested igncr. # But we know of no other shell where ac_cr would be empty at this # point, so we can use a bashism as a fallback. if test "x$ac_cr" = x; then eval ac_cr=\$\'\\r\' fi ac_cs_awk_cr=`$AWK 'BEGIN { print "a\rb" }' /dev/null` if test "$ac_cs_awk_cr" = "a${ac_cr}b"; then ac_cs_awk_cr='\\r' else ac_cs_awk_cr=$ac_cr fi echo 'BEGIN {' >"$ac_tmp/subs1.awk" && _ACEOF { echo "cat >conf$$subs.awk <<_ACEOF" && echo "$ac_subst_vars" | sed 's/.*/&!$&$ac_delim/' && echo "_ACEOF" } >conf$$subs.sh || as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5 ac_delim_num=`echo "$ac_subst_vars" | grep -c '^'` ac_delim='%!_!# ' for ac_last_try in false false false false false :; do . ./conf$$subs.sh || as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5 ac_delim_n=`sed -n "s/.*$ac_delim\$/X/p" conf$$subs.awk | grep -c X` if test $ac_delim_n = $ac_delim_num; then break elif $ac_last_try; then as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5 else ac_delim="$ac_delim!$ac_delim _$ac_delim!! " fi done rm -f conf$$subs.sh cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 cat >>"\$ac_tmp/subs1.awk" <<\\_ACAWK && _ACEOF sed -n ' h s/^/S["/; s/!.*/"]=/ p g s/^[^!]*!// :repl t repl s/'"$ac_delim"'$// t delim :nl h s/\(.\{148\}\)..*/\1/ t more1 s/["\\]/\\&/g; s/^/"/; s/$/\\n"\\/ p n b repl :more1 s/["\\]/\\&/g; s/^/"/; s/$/"\\/ p g s/.\{148\}// t nl :delim h s/\(.\{148\}\)..*/\1/ t more2 s/["\\]/\\&/g; s/^/"/; s/$/"/ p b :more2 s/["\\]/\\&/g; s/^/"/; s/$/"\\/ p g s/.\{148\}// t delim ' >$CONFIG_STATUS || ac_write_fail=1 rm -f conf$$subs.awk cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 _ACAWK cat >>"\$ac_tmp/subs1.awk" <<_ACAWK && for (key in S) S_is_set[key] = 1 FS = "" } { line = $ 0 nfields = split(line, field, "@") substed = 0 len = length(field[1]) for (i = 2; i < nfields; i++) { key = field[i] keylen = length(key) if (S_is_set[key]) { value = S[key] line = substr(line, 1, len) "" value "" substr(line, len + keylen + 3) len += length(value) + length(field[++i]) substed = 1 } else len += 1 + keylen } print line } _ACAWK _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 if sed "s/$ac_cr//" < /dev/null > /dev/null 2>&1; then sed "s/$ac_cr\$//; s/$ac_cr/$ac_cs_awk_cr/g" else cat fi < "$ac_tmp/subs1.awk" > "$ac_tmp/subs.awk" \ || as_fn_error $? "could not setup config files machinery" "$LINENO" 5 _ACEOF # VPATH may cause trouble with some makes, so we remove sole $(srcdir), # ${srcdir} and @srcdir@ entries from VPATH if srcdir is ".", strip leading and # trailing colons and then remove the whole line if VPATH becomes empty # (actually we leave an empty line to preserve line numbers). if test "x$srcdir" = x.; then ac_vpsub='/^[ ]*VPATH[ ]*=[ ]*/{ h s/// s/^/:/ s/[ ]*$/:/ s/:\$(srcdir):/:/g s/:\${srcdir}:/:/g s/:@srcdir@:/:/g s/^:*// s/:*$// x s/\(=[ ]*\).*/\1/ G s/\n// s/^[^=]*=[ ]*$// }' fi cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 fi # test -n "$CONFIG_FILES" # Set up the scripts for CONFIG_HEADERS section. # No need to generate them if there are no CONFIG_HEADERS. # This happens for instance with `./config.status Makefile'. if test -n "$CONFIG_HEADERS"; then cat >"$ac_tmp/defines.awk" <<\_ACAWK || BEGIN { _ACEOF # Transform confdefs.h into an awk script `defines.awk', embedded as # here-document in config.status, that substitutes the proper values into # config.h.in to produce config.h. # Create a delimiter string that does not exist in confdefs.h, to ease # handling of long lines. ac_delim='%!_!# ' for ac_last_try in false false :; do ac_tt=`sed -n "/$ac_delim/p" confdefs.h` if test -z "$ac_tt"; then break elif $ac_last_try; then as_fn_error $? "could not make $CONFIG_HEADERS" "$LINENO" 5 else ac_delim="$ac_delim!$ac_delim _$ac_delim!! " fi done # For the awk script, D is an array of macro values keyed by name, # likewise P contains macro parameters if any. Preserve backslash # newline sequences. ac_word_re=[_$as_cr_Letters][_$as_cr_alnum]* sed -n ' s/.\{148\}/&'"$ac_delim"'/g t rset :rset s/^[ ]*#[ ]*define[ ][ ]*/ / t def d :def s/\\$// t bsnl s/["\\]/\\&/g s/^ \('"$ac_word_re"'\)\(([^()]*)\)[ ]*\(.*\)/P["\1"]="\2"\ D["\1"]=" \3"/p s/^ \('"$ac_word_re"'\)[ ]*\(.*\)/D["\1"]=" \2"/p d :bsnl s/["\\]/\\&/g s/^ \('"$ac_word_re"'\)\(([^()]*)\)[ ]*\(.*\)/P["\1"]="\2"\ D["\1"]=" \3\\\\\\n"\\/p t cont s/^ \('"$ac_word_re"'\)[ ]*\(.*\)/D["\1"]=" \2\\\\\\n"\\/p t cont d :cont n s/.\{148\}/&'"$ac_delim"'/g t clear :clear s/\\$// t bsnlc s/["\\]/\\&/g; s/^/"/; s/$/"/p d :bsnlc s/["\\]/\\&/g; s/^/"/; s/$/\\\\\\n"\\/p b cont ' >$CONFIG_STATUS || ac_write_fail=1 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 for (key in D) D_is_set[key] = 1 FS = "" } /^[\t ]*#[\t ]*(define|undef)[\t ]+$ac_word_re([\t (]|\$)/ { line = \$ 0 split(line, arg, " ") if (arg[1] == "#") { defundef = arg[2] mac1 = arg[3] } else { defundef = substr(arg[1], 2) mac1 = arg[2] } split(mac1, mac2, "(") #) macro = mac2[1] prefix = substr(line, 1, index(line, defundef) - 1) if (D_is_set[macro]) { # Preserve the white space surrounding the "#". print prefix "define", macro P[macro] D[macro] next } else { # Replace #undef with comments. This is necessary, for example, # in the case of _POSIX_SOURCE, which is predefined and required # on some systems where configure will not decide to define it. if (defundef == "undef") { print "/*", prefix defundef, macro, "*/" next } } } { print } _ACAWK _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 as_fn_error $? "could not setup config headers machinery" "$LINENO" 5 fi # test -n "$CONFIG_HEADERS" eval set X " :F $CONFIG_FILES :H $CONFIG_HEADERS :C $CONFIG_COMMANDS" shift for ac_tag do case $ac_tag in :[FHLC]) ac_mode=$ac_tag; continue;; esac case $ac_mode$ac_tag in :[FHL]*:*);; :L* | :C*:*) as_fn_error $? "invalid tag \`$ac_tag'" "$LINENO" 5;; :[FH]-) ac_tag=-:-;; :[FH]*) ac_tag=$ac_tag:$ac_tag.in;; esac ac_save_IFS=$IFS IFS=: set x $ac_tag IFS=$ac_save_IFS shift ac_file=$1 shift case $ac_mode in :L) ac_source=$1;; :[FH]) ac_file_inputs= for ac_f do case $ac_f in -) ac_f="$ac_tmp/stdin";; *) # Look for the file first in the build tree, then in the source tree # (if the path is not absolute). The absolute path cannot be DOS-style, # because $ac_f cannot contain `:'. test -f "$ac_f" || case $ac_f in [\\/$]*) false;; *) test -f "$srcdir/$ac_f" && ac_f="$srcdir/$ac_f";; esac || as_fn_error 1 "cannot find input file: \`$ac_f'" "$LINENO" 5;; esac case $ac_f in *\'*) ac_f=`$as_echo "$ac_f" | sed "s/'/'\\\\\\\\''/g"`;; esac as_fn_append ac_file_inputs " '$ac_f'" done # Let's still pretend it is `configure' which instantiates (i.e., don't # use $as_me), people would be surprised to read: # /* config.h. Generated by config.status. */ configure_input='Generated from '` $as_echo "$*" | sed 's|^[^:]*/||;s|:[^:]*/|, |g' `' by configure.' if test x"$ac_file" != x-; then configure_input="$ac_file. $configure_input" { $as_echo "$as_me:${as_lineno-$LINENO}: creating $ac_file" >&5 $as_echo "$as_me: creating $ac_file" >&6;} fi # Neutralize special characters interpreted by sed in replacement strings. case $configure_input in #( *\&* | *\|* | *\\* ) ac_sed_conf_input=`$as_echo "$configure_input" | sed 's/[\\\\&|]/\\\\&/g'`;; #( *) ac_sed_conf_input=$configure_input;; esac case $ac_tag in *:-:* | *:-) cat >"$ac_tmp/stdin" \ || as_fn_error $? "could not create $ac_file" "$LINENO" 5 ;; esac ;; esac ac_dir=`$as_dirname -- "$ac_file" || $as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$ac_file" : 'X\(//\)[^/]' \| \ X"$ac_file" : 'X\(//\)$' \| \ X"$ac_file" : 'X\(/\)' \| . 2>/dev/null || $as_echo X"$ac_file" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q'` as_dir="$ac_dir"; as_fn_mkdir_p ac_builddir=. case "$ac_dir" in .) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; *) ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'` # A ".." for each directory in $ac_dir_suffix. ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'` case $ac_top_builddir_sub in "") ac_top_builddir_sub=. ac_top_build_prefix= ;; *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; esac ;; esac ac_abs_top_builddir=$ac_pwd ac_abs_builddir=$ac_pwd$ac_dir_suffix # for backward compatibility: ac_top_builddir=$ac_top_build_prefix case $srcdir in .) # We are building in place. ac_srcdir=. ac_top_srcdir=$ac_top_builddir_sub ac_abs_top_srcdir=$ac_pwd ;; [\\/]* | ?:[\\/]* ) # Absolute name. ac_srcdir=$srcdir$ac_dir_suffix; ac_top_srcdir=$srcdir ac_abs_top_srcdir=$srcdir ;; *) # Relative name. ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix ac_top_srcdir=$ac_top_build_prefix$srcdir ac_abs_top_srcdir=$ac_pwd/$srcdir ;; esac ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix case $ac_mode in :F) # # CONFIG_FILE # case $INSTALL in [\\/$]* | ?:[\\/]* ) ac_INSTALL=$INSTALL ;; *) ac_INSTALL=$ac_top_build_prefix$INSTALL ;; esac _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # If the template does not know about datarootdir, expand it. # FIXME: This hack should be removed a few years after 2.60. ac_datarootdir_hack=; ac_datarootdir_seen= ac_sed_dataroot=' /datarootdir/ { p q } /@datadir@/p /@docdir@/p /@infodir@/p /@localedir@/p /@mandir@/p' case `eval "sed -n \"\$ac_sed_dataroot\" $ac_file_inputs"` in *datarootdir*) ac_datarootdir_seen=yes;; *@datadir@*|*@docdir@*|*@infodir@*|*@localedir@*|*@mandir@*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&5 $as_echo "$as_me: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&2;} _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_datarootdir_hack=' s&@datadir@&$datadir&g s&@docdir@&$docdir&g s&@infodir@&$infodir&g s&@localedir@&$localedir&g s&@mandir@&$mandir&g s&\\\${datarootdir}&$datarootdir&g' ;; esac _ACEOF # Neutralize VPATH when `$srcdir' = `.'. # Shell code in configure.ac might set extrasub. # FIXME: do we really want to maintain this feature? cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_sed_extra="$ac_vpsub $extrasub _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 :t /@[a-zA-Z_][a-zA-Z_0-9]*@/!b s|@configure_input@|$ac_sed_conf_input|;t t s&@top_builddir@&$ac_top_builddir_sub&;t t s&@top_build_prefix@&$ac_top_build_prefix&;t t s&@srcdir@&$ac_srcdir&;t t s&@abs_srcdir@&$ac_abs_srcdir&;t t s&@top_srcdir@&$ac_top_srcdir&;t t s&@abs_top_srcdir@&$ac_abs_top_srcdir&;t t s&@builddir@&$ac_builddir&;t t s&@abs_builddir@&$ac_abs_builddir&;t t s&@abs_top_builddir@&$ac_abs_top_builddir&;t t s&@INSTALL@&$ac_INSTALL&;t t $ac_datarootdir_hack " eval sed \"\$ac_sed_extra\" "$ac_file_inputs" | $AWK -f "$ac_tmp/subs.awk" \ >$ac_tmp/out || as_fn_error $? "could not create $ac_file" "$LINENO" 5 test -z "$ac_datarootdir_hack$ac_datarootdir_seen" && { ac_out=`sed -n '/\${datarootdir}/p' "$ac_tmp/out"`; test -n "$ac_out"; } && { ac_out=`sed -n '/^[ ]*datarootdir[ ]*:*=/p' \ "$ac_tmp/out"`; test -z "$ac_out"; } && { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file contains a reference to the variable \`datarootdir' which seems to be undefined. Please make sure it is defined" >&5 $as_echo "$as_me: WARNING: $ac_file contains a reference to the variable \`datarootdir' which seems to be undefined. Please make sure it is defined" >&2;} rm -f "$ac_tmp/stdin" case $ac_file in -) cat "$ac_tmp/out" && rm -f "$ac_tmp/out";; *) rm -f "$ac_file" && mv "$ac_tmp/out" "$ac_file";; esac \ || as_fn_error $? "could not create $ac_file" "$LINENO" 5 ;; :H) # # CONFIG_HEADER # if test x"$ac_file" != x-; then { $as_echo "/* $configure_input */" \ && eval '$AWK -f "$ac_tmp/defines.awk"' "$ac_file_inputs" } >"$ac_tmp/config.h" \ || as_fn_error $? "could not create $ac_file" "$LINENO" 5 if diff "$ac_file" "$ac_tmp/config.h" >/dev/null 2>&1; then { $as_echo "$as_me:${as_lineno-$LINENO}: $ac_file is unchanged" >&5 $as_echo "$as_me: $ac_file is unchanged" >&6;} else rm -f "$ac_file" mv "$ac_tmp/config.h" "$ac_file" \ || as_fn_error $? "could not create $ac_file" "$LINENO" 5 fi else $as_echo "/* $configure_input */" \ && eval '$AWK -f "$ac_tmp/defines.awk"' "$ac_file_inputs" \ || as_fn_error $? "could not create -" "$LINENO" 5 fi ;; :C) { $as_echo "$as_me:${as_lineno-$LINENO}: executing $ac_file commands" >&5 $as_echo "$as_me: executing $ac_file commands" >&6;} ;; esac case $ac_file$ac_mode in "./atconfig":C) cat >./atconfig </dev/null $SHELL $CONFIG_STATUS $ac_config_status_args || ac_cs_success=false exec 5>>config.log # Use ||, not &&, to avoid exiting from the if with $? = 1, which # would make configure fail if this is the last instruction. $ac_cs_success || as_fn_exit 1 fi if test -n "$ac_unrecognized_opts" && test "$enable_option_checking" != no; then { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: unrecognized options: $ac_unrecognized_opts" >&5 $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;} fi diff --git a/contrib/tcsh/dot.login b/contrib/tcsh/dot.login new file mode 100644 index 000000000000..18d6f9c9d4d3 --- /dev/null +++ b/contrib/tcsh/dot.login @@ -0,0 +1,12 @@ +# +# ~/.login - Setup user login shell environment +# +# See also tcsh(1), environ(7). +# + +setenv EDITOR vi +setenv PAGER less + +# umask 077 + +# set path=( ~/.local/bin $path:q ) diff --git a/contrib/tcsh/dot.tcshrc b/contrib/tcsh/dot.tcshrc new file mode 100644 index 000000000000..a155ed56a932 --- /dev/null +++ b/contrib/tcsh/dot.tcshrc @@ -0,0 +1,110 @@ +# +# ~/.tcshrc - Setup user shell environment +# +# See also tcsh(1), environ(7). +# + +unalias * + +alias h 'history \!* 20' +alias j 'jobs -l' +alias ll 'ls -lAF' +alias md mkdir +alias rd rmdir + +# +# The following commands are only for interactive shells. +# + +if ( $?prompt ) then + set \ + autocorrect \ + autoexpand \ + autolist=ambiguous \ + correct=cmd \ + ellipsis \ + filec \ + history=1000 \ + killdup=erase \ + listjobs=long \ + listlinks \ + listmax=100 \ + nobeep \ + prompt='%N@%m:%B%c02%b%# ' \ + rmstar \ + savehist=(1000 merge) \ + + unset promptchars + + if ( $?tcsh ) then + bindkey -e + + bindkey " " magic-space + bindkey ^W backward-delete-word + bindkey ^Z run-fg-editor + bindkey ^[^W kill-region + + # + # Setup $hosts from ~/.hosts, ~/.rhosts, ~/.ssh/known_hosts + # + + if ( ! $?hosts ) then + set hosts=() + foreach f ( ~/.{,r,ssh/known_}hosts ) + if ( -r "$f" ) then + set hosts=( \ + $hosts \ + `sed \ + -e 's/#.*//' \ + -e '/^|/d' \ + -e '/^[+-]@/d' \ + -e 's/^[+-]//' \ + -e 's/[[:space:]].*$//' \ + -e 's/,/\n/g' \ + "$f" \ + | sed \ + -e 's/:[[:digit:]]*$//' \ + -e 's/^\[\([^]]*\)\]$/\1/' \ + -e '/^[.:[:xdigit:][:space:]]*$/d' \ + ` \ + ) + endif + end + unset f + endif + + uncomplete * + + # + # Copy from complete.tcsh + # + if ( -r ~/.complete ) source ~/.complete + + uncomplete rcp rsh + endif + + # + # Set status to ^G in order to keep using ^T for transpose-char. + # + + switch ( "$OSTYPE" ) + case bsd44: + case darwin: + case FreeBSD: + case NetBSD: + stty status ^G + if ( $?tcsh ) bindkey ^G stuff-char + breaksw + endsw + + # + # We don't want to create a root-owned files in our home. + # + + if ( $uid == 0 ) then + unset savehist + setenv LESSHISTFILE - + setenv VIMINIT ':set viminfo=' + endif + +endif diff --git a/contrib/tcsh/ed.chared.c b/contrib/tcsh/ed.chared.c index 0301e8fa043d..2b4a63c8ca6e 100644 --- a/contrib/tcsh/ed.chared.c +++ b/contrib/tcsh/ed.chared.c @@ -1,3893 +1,3893 @@ /* * ed.chared.c: Character editing functions. */ /*- * Copyright (c) 1980, 1991 The Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ /* Bjorn Knutsson @ Thu Jun 24 19:02:17 1999 e_dabbrev_expand() did not do proper completion if quoted spaces were present in the string being completed. Exemple: # echo hello\ world hello world # echo h # echo hello\ Correct behavior is: # echo h # echo hello\ world The same problem occured if spaces were present in a string withing quotation marks. Example: # echo "hello world" hello world # echo "h # echo "hello The former problem could be solved with minor modifications of c_preword() and c_endword(). The latter, however, required a significant rewrite of c_preword(), since quoted strings must be parsed from start to end to determine if a given character is inside or outside the quotation marks. Compare the following two strings: # echo \"" 'foo \' bar\" " 'foo \' bar\ # echo '\"" 'foo \' bar\" \"" foo ' bar" The only difference between the two echo lines is in the first character after the echo command. The result is either one or three arguments. */ #include "sh.h" #include "ed.h" #include "tw.h" #include "ed.defns.h" /* #define SDEBUG */ #define TCSHOP_NOP 0x00 #define TCSHOP_DELETE 0x01 #define TCSHOP_INSERT 0x02 #define TCSHOP_CHANGE 0x04 #define CHAR_FWD 0 #define CHAR_BACK 1 /* * vi word treatment * from: Gert-Jan Vons */ #define C_CLASS_WHITE 1 #define C_CLASS_WORD 2 #define C_CLASS_OTHER 3 static Char *InsertPos = InputBuf; /* Where insertion starts */ static Char *ActionPos = 0; /* Where action begins */ static int ActionFlag = TCSHOP_NOP; /* What delayed action to take */ /* * Word search state */ static int searchdir = F_UP_SEARCH_HIST; /* Direction of last search */ static struct Strbuf patbuf; /* = Strbuf_INIT; Search target */ /* * Char search state */ static int srch_dir = CHAR_FWD; /* Direction of last search */ static Char srch_char = 0; /* Search target */ /* all routines that start with c_ are private to this set of routines */ static void c_alternativ_key_map (int); void c_insert (int); void c_delafter (int); void c_delbefore (int); static int c_to_class (Char); static Char *c_prev_word (Char *, Char *, int); static Char *c_next_word (Char *, Char *, int); static Char *c_number (Char *, int *, int); static Char *c_expand (Char *); static int c_excl (Char *); static int c_substitute (void); static void c_delfini (void); static int c_hmatch (Char *); static void c_hsetpat (void); #ifdef COMMENT static void c_get_word (Char **, Char **); #endif static Char *c_preword (Char *, Char *, int, Char *); static Char *c_nexword (Char *, Char *, int); static Char *c_endword (Char *, Char *, int, Char *); static Char *c_eword (Char *, Char *, int); static void c_push_kill (Char *, Char *); static void c_save_inputbuf (void); static CCRETVAL c_search_line (Char *, int); static CCRETVAL v_repeat_srch (int); static CCRETVAL e_inc_search (int); #ifdef notyet static CCRETVAL e_insert_str (Char *); #endif static CCRETVAL v_search (int); static CCRETVAL v_csearch_fwd (Char, int, int); static CCRETVAL v_action (int); static CCRETVAL v_csearch_back (Char, int, int); static void c_alternativ_key_map(int state) { switch (state) { case 0: CurrentKeyMap = CcKeyMap; break; case 1: CurrentKeyMap = CcAltMap; break; default: return; } AltKeyMap = (Char) state; } void c_insert(int num) { Char *cp; if (LastChar + num >= InputLim) return; /* can't go past end of buffer */ if (Cursor < LastChar) { /* if I must move chars */ for (cp = LastChar; cp >= Cursor; cp--) cp[num] = *cp; if (Mark && Mark > Cursor) Mark += num; } LastChar += num; } void c_delafter(int num) { Char *cp, *kp = NULL; if (num > LastChar - Cursor) num = (int) (LastChar - Cursor); /* bounds check */ if (num > 0) { /* if I can delete anything */ if (VImode) { kp = UndoBuf; /* Set Up for VI undo command */ UndoAction = TCSHOP_INSERT; UndoSize = num; UndoPtr = Cursor; for (cp = Cursor; cp <= LastChar; cp++) { *kp++ = *cp; /* Save deleted chars into undobuf */ *cp = cp[num]; } } else for (cp = Cursor; cp + num <= LastChar; cp++) *cp = cp[num]; LastChar -= num; /* Mark was within the range of the deleted word? */ if (Mark && Mark > Cursor && Mark <= Cursor+num) Mark = Cursor; /* Mark after the deleted word? */ else if (Mark && Mark > Cursor) Mark -= num; } #ifdef notdef else { /* * XXX: We don't want to do that. In emacs mode overwrite should be * sticky. I am not sure how that affects vi mode */ inputmode = MODE_INSERT; } #endif /* notdef */ } void c_delbefore(int num) /* delete before dot, with bounds checking */ { Char *cp, *kp = NULL; if (num > Cursor - InputBuf) num = (int) (Cursor - InputBuf); /* bounds check */ if (num > 0) { /* if I can delete anything */ if (VImode) { kp = UndoBuf; /* Set Up for VI undo command */ UndoAction = TCSHOP_INSERT; UndoSize = num; UndoPtr = Cursor - num; for (cp = Cursor - num; cp <= LastChar; cp++) { *kp++ = *cp; *cp = cp[num]; } } else for (cp = Cursor - num; cp + num <= LastChar; cp++) *cp = cp[num]; LastChar -= num; Cursor -= num; /* Mark was within the range of the deleted word? */ if (Mark && Mark > Cursor && Mark <= Cursor+num) Mark = Cursor; /* Mark after the deleted word? */ else if (Mark && Mark > Cursor) Mark -= num; } } static Char * c_preword(Char *p, Char *low, int n, Char *delim) { while (n--) { Char *prev = low; Char *new; while (prev < p) { /* Skip initial non-word chars */ - if (!Strchr(delim, *prev) || *(prev-1) == (Char)'\\') + if (!Strchr(delim, *prev) || (prev > low && prev[-1] == (Char)'\\')) break; prev++; } new = prev; while (new < p) { prev = new; new = c_endword(prev-1, p, 1, delim); /* Skip to next non-word char */ new++; /* Step away from end of word */ while (new <= p) { /* Skip trailing non-word chars */ - if (!Strchr(delim, *new) || *(new-1) == (Char)'\\') + if (!Strchr(delim, *new) || new > prev && new[-1] == (Char)'\\') break; new++; } } p = prev; /* Set to previous word start */ } if (p < low) p = low; return (p); } /* * c_to_class() returns the class of the given character. * * This is used to make the c_prev_word(), c_next_word() and c_eword() functions * work like vi's, which classify characters. A word is a sequence of * characters belonging to the same class, classes being defined as * follows: * * 1/ whitespace * 2/ alphanumeric chars, + underscore * 3/ others */ static int c_to_class(Char ch) { if (Isspace(ch)) return C_CLASS_WHITE; if (isword(ch)) return C_CLASS_WORD; return C_CLASS_OTHER; } static Char * c_prev_word(Char *p, Char *low, int n) { p--; if (!VImode) { while (n--) { while ((p >= low) && !isword(*p)) p--; while ((p >= low) && isword(*p)) p--; } /* cp now points to one character before the word */ p++; if (p < low) p = low; /* cp now points where we want it */ return(p); } while (n--) { int c_class; if (p < low) break; /* scan until beginning of current word (may be all whitespace!) */ c_class = c_to_class(*p); while ((p >= low) && c_class == c_to_class(*p)) p--; /* if this was a non_whitespace word, we're ready */ if (c_class != C_CLASS_WHITE) continue; /* otherwise, move back to beginning of the word just found */ c_class = c_to_class(*p); while ((p >= low) && c_class == c_to_class(*p)) p--; } p++; /* correct overshoot */ return (p); } static Char * c_next_word(Char *p, Char *high, int n) { if (!VImode) { while (n--) { while ((p < high) && !isword(*p)) p++; while ((p < high) && isword(*p)) p++; } if (p > high) p = high; /* p now points where we want it */ return(p); } while (n--) { int c_class; if (p >= high) break; /* scan until end of current word (may be all whitespace!) */ c_class = c_to_class(*p); while ((p < high) && c_class == c_to_class(*p)) p++; /* if this was all whitespace, we're ready */ if (c_class == C_CLASS_WHITE) continue; /* if we've found white-space at the end of the word, skip it */ while ((p < high) && c_to_class(*p) == C_CLASS_WHITE) p++; } p--; /* correct overshoot */ return (p); } static Char * c_nexword(Char *p, Char *high, int n) { while (n--) { while ((p < high) && !Isspace(*p)) p++; while ((p < high) && Isspace(*p)) p++; } if (p > high) p = high; /* p now points where we want it */ return(p); } /* * Expand-History (originally "Magic-Space") code added by * Ray Moody * this is a neat, but odd, addition. */ /* * c_number: Ignore character p points to, return number appearing after that. * A '$' by itself means a big number; "$-" is for negative; '^' means 1. * Return p pointing to last char used. */ /* * dval is the number to subtract from for things like $-3 */ static Char * c_number(Char *p, int *num, int dval) { int i; int sign = 1; if (*++p == '^') { *num = 1; return(p); } if (*p == '$') { if (*++p != '-') { *num = INT_MAX; /* Handle $ */ return(--p); } sign = -1; /* Handle $- */ ++p; } for (i = 0; *p >= '0' && *p <= '9'; i = 10 * i + *p++ - '0') continue; *num = (sign < 0 ? dval - i : i); return(--p); } /* * excl_expand: There is an excl to be expanded to p -- do the right thing * with it and return a version of p advanced over the expanded stuff. Also, * update tsh_cur and related things as appropriate... */ static Char * c_expand(Char *p) { Char *q; struct Hist *h = Histlist.Hnext; struct wordent *l; int i, from, to, dval; int all_dig; int been_once = 0; Char *op = p; Char *buf; size_t buf_len; Char *modbuf; buf = NULL; if (!h) goto excl_err; excl_sw: switch (*(q = p + 1)) { case '^': buf = expand_lex(&h->Hlex, 1, 1); break; case '$': if ((l = (h->Hlex).prev) != 0) buf = expand_lex(l->prev->prev, 0, 0); break; case '*': buf = expand_lex(&h->Hlex, 1, INT_MAX); break; default: if (been_once) { /* unknown argument */ /* assume it's a modifier, e.g. !foo:h, and get whole cmd */ buf = expand_lex(&h->Hlex, 0, INT_MAX); q -= 2; break; } been_once = 1; if (*q == ':') /* short form: !:arg */ --q; if (HIST != '\0' && *q != HIST) { /* * Search for a space, tab, or colon. See if we have a number (as * in !1234:xyz). Remember the number. */ for (i = 0, all_dig = 1; *q != ' ' && *q != '\t' && *q != ':' && q < Cursor; q++) { /* * PWP: !-4 is a valid history argument too, therefore the test * is if not a digit, or not a - as the first character. */ if ((*q < '0' || *q > '9') && (*q != '-' || q != p + 1)) all_dig = 0; else if (*q == '-') all_dig = 2;/* we are sneeky about this */ else i = 10 * i + *q - '0'; } --q; /* * If we have a number, search for event i. Otherwise, search for * a named event (as in !foo). (In this case, I is the length of * the named event). */ if (all_dig) { if (all_dig == 2) i = -i; /* make it negitive */ if (i < 0) /* if !-4 (for example) */ i = eventno + 1 + i; /* remember: i is < 0 */ for (; h; h = h->Hnext) { if (h->Hnum == i) break; } } else { for (i = (int) (q - p); h; h = h->Hnext) { if ((l = &h->Hlex) != 0) { if (!Strncmp(p + 1, l->next->word, (size_t) i)) break; } } } } if (!h) goto excl_err; if (q[1] == ':' || q[1] == '-' || q[1] == '*' || q[1] == '$' || q[1] == '^') { /* get some args */ p = q[1] == ':' ? ++q : q; /* * Go handle !foo:* */ if ((q[1] < '0' || q[1] > '9') && q[1] != '-' && q[1] != '$' && q[1] != '^') goto excl_sw; /* * Go handle !foo:$ */ if (q[1] == '$' && (q[2] != '-' || q[3] < '0' || q[3] > '9')) goto excl_sw; /* * Count up the number of words in this event. Store it in dval. * Dval will be fed to number. */ dval = 0; if ((l = h->Hlex.prev) != 0) { for (l = l->prev; l != h->Hlex.next; l = l->prev, dval++) continue; } if (!dval) goto excl_err; if (q[1] == '-') from = 0; else q = c_number(q, &from, dval); if (q[1] == '-') { ++q; if ((q[1] < '0' || q[1] > '9') && q[1] != '$') to = dval - 1; else q = c_number(q, &to, dval); } else if (q[1] == '*') { ++q; to = INT_MAX; } else { to = from; } if (from < 0 || to < from) goto excl_err; buf = expand_lex(&h->Hlex, from, to); } else /* get whole cmd */ buf = expand_lex(&h->Hlex, 0, INT_MAX); break; } if (buf == NULL) buf = SAVE(""); /* * Apply modifiers, if any. */ if (q[1] == ':') { modbuf = buf; while (q[1] == ':' && modbuf != NULL) { switch (q[2]) { case 'r': case 'e': case 'h': case 't': case 'q': case 'x': case 'u': case 'l': if ((modbuf = domod(buf, (int) q[2])) != NULL) { xfree(buf); buf = modbuf; } ++q; break; case 'a': case 'g': /* Not implemented; this needs to be done before expanding * lex. We don't have the words available to us anymore. */ ++q; break; case 'p': /* Ok */ ++q; break; case '\0': break; default: ++q; break; } if (q[1]) ++q; } } buf_len = Strlen(buf); /* * Now replace the text from op to q inclusive with the text from buf. */ q++; /* * Now replace text non-inclusively like a real CS major! */ if (LastChar + buf_len - (q - op) >= InputLim) goto excl_err; (void) memmove(op + buf_len, q, (LastChar - q) * sizeof(Char)); LastChar += buf_len - (q - op); Cursor += buf_len - (q - op); (void) memcpy(op, buf, buf_len * sizeof(Char)); *LastChar = '\0'; xfree(buf); return op + buf_len; excl_err: xfree(buf); SoundBeep(); return(op + 1); } /* * c_excl: An excl has been found at point p -- back up and find some white * space (or the beginning of the buffer) and properly expand all the excl's * from there up to the current cursor position. We also avoid (trying to) * expanding '>!' * Returns number of expansions attempted (doesn't matter whether they succeeded * or not). */ static int c_excl(Char *p) { int i; Char *q; int nr_exp; /* * if />[SPC TAB]*![SPC TAB]/, back up p to just after the >. otherwise, * back p up to just before the current word. */ if ((p[1] == ' ' || p[1] == '\t') && (p[-1] == ' ' || p[-1] == '\t' || p[-1] == '>')) { for (q = p - 1; q > InputBuf && (*q == ' ' || *q == '\t'); --q) continue; if (*q == '>') ++p; } else { while (*p != ' ' && *p != '\t' && p > InputBuf) --p; } /* * Forever: Look for history char. (Stop looking when we find the cursor.) * Count backslashes. If odd, skip history char. Expand if even number of * backslashes. */ nr_exp = 0; for (;;) { if (HIST != '\0') while (*p != HIST && p < Cursor) ++p; for (i = 1; (p - i) >= InputBuf && p[-i] == '\\'; i++) continue; if (i % 2 == 0) ++p; if (p >= Cursor) /* all done */ return nr_exp; if (i % 2 == 1) { p = c_expand(p); ++nr_exp; } } } static int c_substitute(void) { Char *p; int nr_exp; /* * Start p out one character before the cursor. Move it backwards looking * for white space, the beginning of the line, or a history character. */ for (p = Cursor - 1; p > InputBuf && *p != ' ' && *p != '\t' && *p && *p != HIST; --p) continue; /* * If we found a history character, go expand it. */ if (p >= InputBuf && HIST != '\0' && *p == HIST) nr_exp = c_excl(p); else nr_exp = 0; Refresh(); return nr_exp; } static void c_delfini(void) /* Finish up delete action */ { int Size; if (ActionFlag & TCSHOP_INSERT) c_alternativ_key_map(0); ActionFlag = TCSHOP_NOP; if (ActionPos == 0) return; UndoAction = TCSHOP_INSERT; if (Cursor > ActionPos) { Size = (int) (Cursor-ActionPos); c_delbefore(Size); RefCursor(); } else if (Cursor < ActionPos) { Size = (int)(ActionPos-Cursor); c_delafter(Size); } else { Size = 1; c_delafter(Size); } UndoPtr = Cursor; UndoSize = Size; } static Char * c_endword(Char *p, Char *high, int n, Char *delim) { Char inquote = 0; p++; while (n--) { while (p < high) { /* Skip non-word chars */ - if (!Strchr(delim, *p) || *(p-1) == (Char)'\\') + if (!Strchr(delim, *p) || p[-1] == (Char)'\\') break; p++; } while (p < high) { /* Skip string */ if ((*p == (Char)'\'' || *p == (Char)'"')) { /* Quotation marks? */ - if (inquote || *(p-1) != (Char)'\\') { /* Should it be honored? */ + if (inquote || p[-1] != (Char)'\\') { /* Should it be honored? */ if (inquote == 0) inquote = *p; else if (inquote == *p) inquote = 0; } } /* Break if unquoted non-word char */ - if (!inquote && Strchr(delim, *p) && *(p-1) != (Char)'\\') + if (!inquote && Strchr(delim, *p) && p[-1] != (Char)'\\') break; p++; } } p--; return(p); } static Char * c_eword(Char *p, Char *high, int n) { p++; while (n--) { int c_class; if (p >= high) break; /* scan until end of current word (may be all whitespace!) */ c_class = c_to_class(*p); while ((p < high) && c_class == c_to_class(*p)) p++; /* if this was a non_whitespace word, we're ready */ if (c_class != C_CLASS_WHITE) continue; /* otherwise, move to the end of the word just found */ c_class = c_to_class(*p); while ((p < high) && c_class == c_to_class(*p)) p++; } p--; return(p); } /* Set the max length of the kill ring */ void SetKillRing(int max) { CStr *new; int count, i, j; if (max < 1) max = 1; /* no ring, but always one buffer */ if (max == KillRingMax) return; new = xcalloc(max, sizeof(CStr)); if (KillRing != NULL) { if (KillRingLen != 0) { if (max >= KillRingLen) { count = KillRingLen; j = KillPos; } else { count = max; j = (KillPos - count + KillRingLen) % KillRingLen; } for (i = 0; i < KillRingLen; i++) { if (i < count) /* copy latest */ new[i] = KillRing[j]; else /* free the others */ xfree(KillRing[j].buf); j = (j + 1) % KillRingLen; } KillRingLen = count; KillPos = count % max; YankPos = count - 1; } xfree(KillRing); } KillRing = new; KillRingMax = max; } /* Push string from start upto (but not including) end onto kill ring */ static void c_push_kill(Char *start, Char *end) { CStr save, *pos; Char *dp, *cp, *kp; int len = end - start, i, j, k; /* Check for duplicates? */ if (KillRingLen > 0 && (dp = varval(STRkilldup)) != STRNULL) { YankPos = (KillPos - 1 + KillRingLen) % KillRingLen; if (eq(dp, STRerase)) { /* erase earlier one (actually move up) */ j = YankPos; for (i = 0; i < KillRingLen; i++) { if (Strncmp(KillRing[j].buf, start, (size_t) len) == 0 && KillRing[j].buf[len] == '\0') { save = KillRing[j]; for ( ; i > 0; i--) { k = j; j = (j + 1) % KillRingLen; KillRing[k] = KillRing[j]; } KillRing[j] = save; return; } j = (j - 1 + KillRingLen) % KillRingLen; } } else if (eq(dp, STRall)) { /* skip if any earlier */ for (i = 0; i < KillRingLen; i++) if (Strncmp(KillRing[i].buf, start, (size_t) len) == 0 && KillRing[i].buf[len] == '\0') return; } else if (eq(dp, STRprev)) { /* skip if immediately previous */ j = YankPos; if (Strncmp(KillRing[j].buf, start, (size_t) len) == 0 && KillRing[j].buf[len] == '\0') return; } } /* No duplicate, go ahead and push */ len++; /* need space for '\0' */ YankPos = KillPos; if (KillRingLen < KillRingMax) KillRingLen++; pos = &KillRing[KillPos]; KillPos = (KillPos + 1) % KillRingMax; if (pos->len < len) { pos->buf = xrealloc(pos->buf, len * sizeof(Char)); pos->len = len; } cp = start; kp = pos->buf; while (cp < end) *kp++ = *cp++; *kp = '\0'; } /* Save InputBuf etc in SavedBuf etc for restore after cmd exec */ static void c_save_inputbuf(void) { SavedBuf.len = 0; Strbuf_append(&SavedBuf, InputBuf); Strbuf_terminate(&SavedBuf); LastSaved = LastChar - InputBuf; CursSaved = Cursor - InputBuf; HistSaved = Hist_num; RestoreSaved = 1; } CCRETVAL GetHistLine(void) { struct Hist *hp; int h; if (Hist_num == 0) { /* if really the current line */ if (HistBuf.s != NULL) copyn(InputBuf, HistBuf.s, INBUFSIZE);/*FIXBUF*/ else *InputBuf = '\0'; LastChar = InputBuf + HistBuf.len; #ifdef KSHVI if (VImode) Cursor = InputBuf; else #endif /* KSHVI */ Cursor = LastChar; return(CC_REFRESH); } hp = Histlist.Hnext; if (hp == NULL) return(CC_ERROR); for (h = 1; h < Hist_num; h++) { if ((hp->Hnext) == NULL) { Hist_num = h; return(CC_ERROR); } hp = hp->Hnext; } if (HistLit && hp->histline) { copyn(InputBuf, hp->histline, INBUFSIZE);/*FIXBUF*/ CurrentHistLit = 1; } else { Char *p; p = sprlex(&hp->Hlex); copyn(InputBuf, p, sizeof(InputBuf) / sizeof(Char));/*FIXBUF*/ xfree(p); CurrentHistLit = 0; } LastChar = Strend(InputBuf); if (LastChar > InputBuf) { if (LastChar[-1] == '\n') LastChar--; #if 0 if (LastChar[-1] == ' ') LastChar--; #endif if (LastChar < InputBuf) LastChar = InputBuf; } #ifdef KSHVI if (VImode) Cursor = InputBuf; else #endif /* KSHVI */ Cursor = LastChar; return(CC_REFRESH); } static CCRETVAL c_search_line(Char *pattern, int dir) { Char *cp; size_t len; len = Strlen(pattern); if (dir == F_UP_SEARCH_HIST) { for (cp = Cursor; cp >= InputBuf; cp--) if (Strncmp(cp, pattern, len) == 0 || Gmatch(cp, pattern)) { Cursor = cp; return(CC_NORM); } return(CC_ERROR); } else { for (cp = Cursor; *cp != '\0' && cp < InputLim; cp++) if (Strncmp(cp, pattern, len) == 0 || Gmatch(cp, pattern)) { Cursor = cp; return(CC_NORM); } return(CC_ERROR); } } static CCRETVAL e_inc_search(int dir) { static const Char STRfwd[] = { 'f', 'w', 'd', '\0' }, STRbck[] = { 'b', 'c', 'k', '\0' }; static Char pchar = ':'; /* ':' = normal, '?' = failed */ static Char endcmd[2]; const Char *cp; Char ch, *oldCursor = Cursor, oldpchar = pchar; CCRETVAL ret = CC_NORM; int oldHist_num = Hist_num, oldpatlen = patbuf.len, newdir = dir, done, redo; if (LastChar + sizeof(STRfwd)/sizeof(Char) + 2 + patbuf.len >= InputLim) return(CC_ERROR); for (;;) { if (patbuf.len == 0) { /* first round */ pchar = ':'; Strbuf_append1(&patbuf, '*'); } done = redo = 0; *LastChar++ = '\n'; for (cp = newdir == F_UP_SEARCH_HIST ? STRbck : STRfwd; *cp; *LastChar++ = *cp++) continue; *LastChar++ = pchar; for (cp = &patbuf.s[1]; cp < &patbuf.s[patbuf.len]; *LastChar++ = *cp++) continue; *LastChar = '\0'; if (adrof(STRhighlight) && pchar == ':') { /* if the no-glob-search patch is applied, remove the - 1 below */ IncMatchLen = patbuf.len - 1; ClearLines(); ClearDisp(); } Refresh(); if (GetNextChar(&ch) != 1) return(e_send_eof(0)); switch (GetCmdChar(ch)) { case F_INSERT: case F_DIGIT: case F_MAGIC_SPACE: if (LastChar + 1 >= InputLim) /*FIXBUF*/ SoundBeep(); else { Strbuf_append1(&patbuf, ch); *LastChar++ = ch; *LastChar = '\0'; Refresh(); } break; case F_INC_FWD: newdir = F_DOWN_SEARCH_HIST; redo++; break; case F_INC_BACK: newdir = F_UP_SEARCH_HIST; redo++; break; case F_DELPREV: if (patbuf.len > 1) done++; else SoundBeep(); break; default: switch (ASC(ch)) { case 0007: /* ^G: Abort */ ret = CC_ERROR; done++; break; case 0027: /* ^W: Append word */ /* No can do if globbing characters in pattern */ for (cp = &patbuf.s[1]; ; cp++) if (cp >= &patbuf.s[patbuf.len]) { Cursor += patbuf.len - 1; cp = c_next_word(Cursor, LastChar, 1); while (Cursor < cp && *Cursor != '\n') { if (LastChar + 1 >= InputLim) {/*FIXBUF*/ SoundBeep(); break; } Strbuf_append1(&patbuf, *Cursor); *LastChar++ = *Cursor++; } Cursor = oldCursor; *LastChar = '\0'; Refresh(); break; } else if (isglob(*cp)) { SoundBeep(); break; } break; default: /* Terminate and execute cmd */ endcmd[0] = ch; PushMacro(endcmd); /*FALLTHROUGH*/ case 0033: /* ESC: Terminate */ ret = CC_REFRESH; done++; break; } break; } while (LastChar > InputBuf && *LastChar != '\n') *LastChar-- = '\0'; *LastChar = '\0'; if (!done) { /* Can't search if unmatched '[' */ for (cp = &patbuf.s[patbuf.len - 1], ch = ']'; cp > patbuf.s; cp--) if (*cp == '[' || *cp == ']') { ch = *cp; break; } if (patbuf.len > 1 && ch != '[') { if (redo && newdir == dir) { if (pchar == '?') { /* wrap around */ Hist_num = newdir == F_UP_SEARCH_HIST ? 0 : INT_MAX; if (GetHistLine() == CC_ERROR) /* Hist_num was fixed by first call */ (void) GetHistLine(); Cursor = newdir == F_UP_SEARCH_HIST ? LastChar : InputBuf; } else Cursor += newdir == F_UP_SEARCH_HIST ? -1 : 1; } Strbuf_append1(&patbuf, '*'); Strbuf_terminate(&patbuf); if (Cursor < InputBuf || Cursor > LastChar || (ret = c_search_line(&patbuf.s[1], newdir)) == CC_ERROR) { LastCmd = (KEYCMD) newdir; /* avoid c_hsetpat */ ret = newdir == F_UP_SEARCH_HIST ? e_up_search_hist(0) : e_down_search_hist(0); if (ret != CC_ERROR) { Cursor = newdir == F_UP_SEARCH_HIST ? LastChar : InputBuf; (void) c_search_line(&patbuf.s[1], newdir); } } patbuf.s[--patbuf.len] = '\0'; if (ret == CC_ERROR) { SoundBeep(); if (Hist_num != oldHist_num) { Hist_num = oldHist_num; if (GetHistLine() == CC_ERROR) return(CC_ERROR); } Cursor = oldCursor; pchar = '?'; } else { pchar = ':'; } } ret = e_inc_search(newdir); if (ret == CC_ERROR && pchar == '?' && oldpchar == ':') { /* break abort of failed search at last non-failed */ ret = CC_NORM; } } if (ret == CC_NORM || (ret == CC_ERROR && oldpatlen == 0)) { /* restore on normal return or error exit */ pchar = oldpchar; patbuf.len = oldpatlen; if (Hist_num != oldHist_num) { Hist_num = oldHist_num; if (GetHistLine() == CC_ERROR) return(CC_ERROR); } Cursor = oldCursor; if (ret == CC_ERROR) Refresh(); } if (done || ret != CC_NORM) return(ret); } } static CCRETVAL v_search(int dir) { struct Strbuf tmpbuf = Strbuf_INIT; Char ch; Char *oldbuf; Char *oldlc, *oldc; cleanup_push(&tmpbuf, Strbuf_cleanup); oldbuf = Strsave(InputBuf); cleanup_push(oldbuf, xfree); oldlc = LastChar; oldc = Cursor; Strbuf_append1(&tmpbuf, '*'); InputBuf[0] = '\0'; LastChar = InputBuf; Cursor = InputBuf; searchdir = dir; c_insert(2); /* prompt + '\n' */ *Cursor++ = '\n'; *Cursor++ = dir == F_UP_SEARCH_HIST ? '?' : '/'; Refresh(); for (ch = 0;ch == 0;) { if (GetNextChar(&ch) != 1) { cleanup_until(&tmpbuf); return(e_send_eof(0)); } switch (ASC(ch)) { case 0010: /* Delete and backspace */ case 0177: if (tmpbuf.len > 1) { *Cursor-- = '\0'; LastChar = Cursor; tmpbuf.len--; } else { copyn(InputBuf, oldbuf, INBUFSIZE);/*FIXBUF*/ LastChar = oldlc; Cursor = oldc; cleanup_until(&tmpbuf); return(CC_REFRESH); } Refresh(); ch = 0; break; case 0033: /* ESC */ #ifdef IS_ASCII case '\r': /* Newline */ case '\n': #else case '\012': /* ASCII Line feed */ case '\015': /* ASCII (or EBCDIC) Return */ #endif break; default: Strbuf_append1(&tmpbuf, ch); *Cursor++ = ch; LastChar = Cursor; Refresh(); ch = 0; break; } } cleanup_until(oldbuf); if (tmpbuf.len == 1) { /* * Use the old pattern, but wild-card it. */ if (patbuf.len == 0) { InputBuf[0] = '\0'; LastChar = InputBuf; Cursor = InputBuf; Refresh(); cleanup_until(&tmpbuf); return(CC_ERROR); } if (patbuf.s[0] != '*') { oldbuf = Strsave(patbuf.s); patbuf.len = 0; Strbuf_append1(&patbuf, '*'); Strbuf_append(&patbuf, oldbuf); xfree(oldbuf); Strbuf_append1(&patbuf, '*'); Strbuf_terminate(&patbuf); } } else { Strbuf_append1(&tmpbuf, '*'); Strbuf_terminate(&tmpbuf); patbuf.len = 0; Strbuf_append(&patbuf, tmpbuf.s); Strbuf_terminate(&patbuf); } cleanup_until(&tmpbuf); LastCmd = (KEYCMD) dir; /* avoid c_hsetpat */ Cursor = LastChar = InputBuf; if ((dir == F_UP_SEARCH_HIST ? e_up_search_hist(0) : e_down_search_hist(0)) == CC_ERROR) { Refresh(); return(CC_ERROR); } else { if (ASC(ch) == 0033) { Refresh(); *LastChar++ = '\n'; *LastChar = '\0'; PastBottom(); return(CC_NEWLINE); } else return(CC_REFRESH); } } /* * semi-PUBLIC routines. Any routine that is of type CCRETVAL is an * entry point, called from the CcKeyMap indirected into the * CcFuncTbl array. */ /*ARGSUSED*/ CCRETVAL v_cmd_mode(Char c) { USE(c); InsertPos = 0; ActionFlag = TCSHOP_NOP; /* [Esc] cancels pending action */ ActionPos = 0; DoingArg = 0; if (UndoPtr > Cursor) UndoSize = (int)(UndoPtr - Cursor); else UndoSize = (int)(Cursor - UndoPtr); inputmode = MODE_INSERT; c_alternativ_key_map(1); #ifdef notdef /* * We don't want to move the cursor, because all the editing * commands don't include the character under the cursor. */ if (Cursor > InputBuf) Cursor--; #endif RefCursor(); return(CC_NORM); } /*ARGSUSED*/ CCRETVAL e_unassigned(Char c) { /* bound to keys that arn't really assigned */ USE(c); SoundBeep(); flush(); return(CC_NORM); } #ifdef notyet static CCRETVAL e_insert_str(Char *c) { int i, n; n = Strlen(c); if (LastChar + Argument * n >= InputLim) return(CC_ERROR); /* end of buffer space */ if (inputmode != MODE_INSERT) { c_delafter(Argument * Strlen(c)); } c_insert(Argument * n); while (Argument--) { for (i = 0; i < n; i++) *Cursor++ = c[i]; } Refresh(); return(CC_NORM); } #endif CCRETVAL e_insert(Char c) { #ifndef SHORT_STRINGS c &= ASCII; /* no meta chars ever */ #endif if (!c) return(CC_ERROR); /* no NULs in the input ever!! */ if (LastChar + Argument >= InputLim) return(CC_ERROR); /* end of buffer space */ if (Argument == 1) { /* How was this optimized ???? */ if (inputmode != MODE_INSERT) { UndoBuf[UndoSize++] = *Cursor; UndoBuf[UndoSize] = '\0'; c_delafter(1); /* Do NOT use the saving ONE */ } c_insert(1); *Cursor++ = (Char) c; DoingArg = 0; /* just in case */ RefPlusOne(1); /* fast refresh for one char. */ } else { if (inputmode != MODE_INSERT) { int i; - for(i = 0; i < Argument; i++) - UndoBuf[UndoSize++] = *(Cursor + i); + for (i = 0; i < Argument; i++) + UndoBuf[UndoSize++] = Cursor[i]; UndoBuf[UndoSize] = '\0'; c_delafter(Argument); /* Do NOT use the saving ONE */ } c_insert(Argument); while (Argument--) *Cursor++ = (Char) c; Refresh(); } if (inputmode == MODE_REPLACE_1) (void) v_cmd_mode(0); return(CC_NORM); } int InsertStr(Char *s) /* insert ASCIZ s at cursor (for complete) */ { int len; if ((len = (int) Strlen(s)) <= 0) return -1; if (LastChar + len >= InputLim) return -1; /* end of buffer space */ c_insert(len); while (len--) *Cursor++ = *s++; return 0; } void DeleteBack(int n) /* delete the n characters before . */ { if (n <= 0) return; if (Cursor >= &InputBuf[n]) { c_delbefore(n); /* delete before dot */ } } CCRETVAL e_digit(Char c) /* gray magic here */ { if (!Isdigit(c)) return(CC_ERROR); /* no NULs in the input ever!! */ if (DoingArg) { /* if doing an arg, add this in... */ if (LastCmd == F_ARGFOUR) /* if last command was ^U */ Argument = c - '0'; else { if (Argument > 1000000) return CC_ERROR; Argument = (Argument * 10) + (c - '0'); } return(CC_ARGHACK); } else { if (LastChar + 1 >= InputLim) return CC_ERROR; /* end of buffer space */ if (inputmode != MODE_INSERT) { UndoBuf[UndoSize++] = *Cursor; UndoBuf[UndoSize] = '\0'; c_delafter(1); /* Do NOT use the saving ONE */ } c_insert(1); *Cursor++ = (Char) c; DoingArg = 0; /* just in case */ RefPlusOne(1); /* fast refresh for one char. */ } return(CC_NORM); } CCRETVAL e_argdigit(Char c) /* for ESC-n */ { #ifdef IS_ASCII c &= ASCII; #else c = CTL_ESC(ASC(c) & ASCII); /* stripping for EBCDIC done the ASCII way */ #endif if (!Isdigit(c)) return(CC_ERROR); /* no NULs in the input ever!! */ if (DoingArg) { /* if doing an arg, add this in... */ if (Argument > 1000000) return CC_ERROR; Argument = (Argument * 10) + (c - '0'); } else { /* else starting an argument */ Argument = c - '0'; DoingArg = 1; } return(CC_ARGHACK); } CCRETVAL v_zero(Char c) /* command mode 0 for vi */ { if (DoingArg) { /* if doing an arg, add this in... */ if (Argument > 1000000) return CC_ERROR; Argument = (Argument * 10) + (c - '0'); return(CC_ARGHACK); } else { /* else starting an argument */ Cursor = InputBuf; if (ActionFlag & TCSHOP_DELETE) { c_delfini(); return(CC_REFRESH); } RefCursor(); /* move the cursor */ return(CC_NORM); } } /*ARGSUSED*/ CCRETVAL e_newline(Char c) { /* always ignore argument */ USE(c); if (adrof(STRhighlight) && MarkIsSet) { MarkIsSet = 0; ClearLines(); ClearDisp(); Refresh(); } MarkIsSet = 0; /* PastBottom(); NOW done in ed.inputl.c */ *LastChar++ = '\n'; /* for the benefit of CSH */ *LastChar = '\0'; /* just in case */ if (VImode) InsertPos = InputBuf; /* Reset editing position */ return(CC_NEWLINE); } /*ARGSUSED*/ CCRETVAL e_newline_hold(Char c) { USE(c); c_save_inputbuf(); HistSaved = 0; *LastChar++ = '\n'; /* for the benefit of CSH */ *LastChar = '\0'; /* just in case */ return(CC_NEWLINE); } /*ARGSUSED*/ CCRETVAL e_newline_down_hist(Char c) { USE(c); if (Hist_num > 1) { HistSaved = Hist_num; } *LastChar++ = '\n'; /* for the benefit of CSH */ *LastChar = '\0'; /* just in case */ return(CC_NEWLINE); } /*ARGSUSED*/ CCRETVAL e_send_eof(Char c) { /* for when ^D is ONLY send-eof */ USE(c); PastBottom(); *LastChar = '\0'; /* just in case */ return(CC_EOF); } /*ARGSUSED*/ CCRETVAL e_complete(Char c) { USE(c); *LastChar = '\0'; /* just in case */ return(CC_COMPLETE); } /*ARGSUSED*/ CCRETVAL e_complete_back(Char c) { USE(c); *LastChar = '\0'; /* just in case */ return(CC_COMPLETE_BACK); } /*ARGSUSED*/ CCRETVAL e_complete_fwd(Char c) { USE(c); *LastChar = '\0'; /* just in case */ return(CC_COMPLETE_FWD); } /*ARGSUSED*/ CCRETVAL e_complete_all(Char c) { USE(c); *LastChar = '\0'; /* just in case */ return(CC_COMPLETE_ALL); } /*ARGSUSED*/ CCRETVAL v_cm_complete(Char c) { USE(c); if (Cursor < LastChar) Cursor++; *LastChar = '\0'; /* just in case */ return(CC_COMPLETE); } /*ARGSUSED*/ CCRETVAL e_toggle_hist(Char c) { struct Hist *hp; int h; USE(c); *LastChar = '\0'; /* just in case */ if (Hist_num <= 0) { return CC_ERROR; } hp = Histlist.Hnext; if (hp == NULL) { /* this is only if no history */ return(CC_ERROR); } for (h = 1; h < Hist_num; h++) hp = hp->Hnext; if (!CurrentHistLit) { if (hp->histline) { copyn(InputBuf, hp->histline, INBUFSIZE);/*FIXBUF*/ CurrentHistLit = 1; } else { return CC_ERROR; } } else { Char *p; p = sprlex(&hp->Hlex); copyn(InputBuf, p, sizeof(InputBuf) / sizeof(Char));/*FIXBUF*/ xfree(p); CurrentHistLit = 0; } LastChar = Strend(InputBuf); if (LastChar > InputBuf) { if (LastChar[-1] == '\n') LastChar--; if (LastChar[-1] == ' ') LastChar--; if (LastChar < InputBuf) LastChar = InputBuf; } #ifdef KSHVI if (VImode) Cursor = InputBuf; else #endif /* KSHVI */ Cursor = LastChar; return(CC_REFRESH); } /*ARGSUSED*/ CCRETVAL e_up_hist(Char c) { Char beep = 0; USE(c); UndoAction = TCSHOP_NOP; *LastChar = '\0'; /* just in case */ if (Hist_num == 0) { /* save the current buffer away */ HistBuf.len = 0; Strbuf_append(&HistBuf, InputBuf); Strbuf_terminate(&HistBuf); } Hist_num += Argument; if (GetHistLine() == CC_ERROR) { beep = 1; (void) GetHistLine(); /* Hist_num was fixed by first call */ } Refresh(); if (beep) return(CC_ERROR); else return(CC_NORM); /* was CC_UP_HIST */ } /*ARGSUSED*/ CCRETVAL e_down_hist(Char c) { USE(c); UndoAction = TCSHOP_NOP; *LastChar = '\0'; /* just in case */ Hist_num -= Argument; if (Hist_num < 0) { Hist_num = 0; return(CC_ERROR); /* make it beep */ } return(GetHistLine()); } /* * c_hmatch() return True if the pattern matches the prefix */ static int c_hmatch(Char *str) { if (Strncmp(patbuf.s, str, patbuf.len) == 0) return 1; return Gmatch(str, patbuf.s); } /* * c_hsetpat(): Set the history seatch pattern */ static void c_hsetpat(void) { if (LastCmd != F_UP_SEARCH_HIST && LastCmd != F_DOWN_SEARCH_HIST) { patbuf.len = 0; Strbuf_appendn(&patbuf, InputBuf, Cursor - InputBuf); Strbuf_terminate(&patbuf); } #ifdef SDEBUG xprintf("\nHist_num = %d\n", Hist_num); xprintf("patlen = %d\n", (int)patbuf.len); xprintf("patbuf = \"%S\"\n", patbuf.s); xprintf("Cursor %d LastChar %d\n", Cursor - InputBuf, LastChar - InputBuf); #endif } /*ARGSUSED*/ CCRETVAL e_up_search_hist(Char c) { struct Hist *hp; int h; int found = 0; USE(c); ActionFlag = TCSHOP_NOP; UndoAction = TCSHOP_NOP; *LastChar = '\0'; /* just in case */ if (Hist_num < 0) { #ifdef DEBUG_EDIT xprintf("%s: e_up_search_hist(): Hist_num < 0; resetting.\n", progname); #endif Hist_num = 0; return(CC_ERROR); } if (Hist_num == 0) { HistBuf.len = 0; Strbuf_append(&HistBuf, InputBuf); Strbuf_terminate(&HistBuf); } hp = Histlist.Hnext; if (hp == NULL) return(CC_ERROR); c_hsetpat(); /* Set search pattern !! */ for (h = 1; h <= Hist_num; h++) hp = hp->Hnext; while (hp != NULL) { Char *hl; int matched; if (hp->histline == NULL) hp->histline = sprlex(&hp->Hlex); if (HistLit) hl = hp->histline; else { hl = sprlex(&hp->Hlex); cleanup_push(hl, xfree); } #ifdef SDEBUG xprintf("Comparing with \"%S\"\n", hl); #endif matched = (Strncmp(hl, InputBuf, (size_t) (LastChar - InputBuf)) || hl[LastChar-InputBuf]) && c_hmatch(hl); if (!HistLit) cleanup_until(hl); if (matched) { found++; break; } h++; hp = hp->Hnext; } if (!found) { #ifdef SDEBUG xprintf("not found\n"); #endif return(CC_ERROR); } Hist_num = h; return(GetHistLine()); } /*ARGSUSED*/ CCRETVAL e_down_search_hist(Char c) { struct Hist *hp; int h; int found = 0; USE(c); ActionFlag = TCSHOP_NOP; UndoAction = TCSHOP_NOP; *LastChar = '\0'; /* just in case */ if (Hist_num == 0) return(CC_ERROR); hp = Histlist.Hnext; if (hp == 0) return(CC_ERROR); c_hsetpat(); /* Set search pattern !! */ for (h = 1; h < Hist_num && hp; h++) { Char *hl; if (hp->histline == NULL) hp->histline = sprlex(&hp->Hlex); if (HistLit) hl = hp->histline; else { hl = sprlex(&hp->Hlex); cleanup_push(hl, xfree); } #ifdef SDEBUG xprintf("Comparing with \"%S\"\n", hl); #endif if ((Strncmp(hl, InputBuf, (size_t) (LastChar - InputBuf)) || hl[LastChar-InputBuf]) && c_hmatch(hl)) found = h; if (!HistLit) cleanup_until(hl); hp = hp->Hnext; } if (!found) { /* is it the current history number? */ if (!c_hmatch(HistBuf.s)) { #ifdef SDEBUG xprintf("not found\n"); #endif return(CC_ERROR); } } Hist_num = found; return(GetHistLine()); } /*ARGSUSED*/ CCRETVAL e_helpme(Char c) { USE(c); PastBottom(); *LastChar = '\0'; /* just in case */ return(CC_HELPME); } /*ARGSUSED*/ CCRETVAL e_correct(Char c) { USE(c); *LastChar = '\0'; /* just in case */ return(CC_CORRECT); } /*ARGSUSED*/ CCRETVAL e_correctl(Char c) { USE(c); *LastChar = '\0'; /* just in case */ return(CC_CORRECT_L); } /*ARGSUSED*/ CCRETVAL e_run_fg_editor(Char c) { struct process *pp; USE(c); if ((pp = find_stop_ed()) != NULL) { /* save our editor state so we can restore it */ c_save_inputbuf(); Hist_num = 0; /* for the history commands */ /* put the tty in a sane mode */ PastBottom(); (void) Cookedmode(); /* make sure the tty is set up correctly */ /* do it! */ fg_proc_entry(pp); (void) Rawmode(); /* go on */ Refresh(); RestoreSaved = 0; HistSaved = 0; } return(CC_NORM); } /*ARGSUSED*/ CCRETVAL e_list_choices(Char c) { USE(c); PastBottom(); *LastChar = '\0'; /* just in case */ return(CC_LIST_CHOICES); } /*ARGSUSED*/ CCRETVAL e_list_all(Char c) { USE(c); PastBottom(); *LastChar = '\0'; /* just in case */ return(CC_LIST_ALL); } /*ARGSUSED*/ CCRETVAL e_list_glob(Char c) { USE(c); PastBottom(); *LastChar = '\0'; /* just in case */ return(CC_LIST_GLOB); } /*ARGSUSED*/ CCRETVAL e_expand_glob(Char c) { USE(c); *LastChar = '\0'; /* just in case */ return(CC_EXPAND_GLOB); } /*ARGSUSED*/ CCRETVAL e_normalize_path(Char c) { USE(c); *LastChar = '\0'; /* just in case */ return(CC_NORMALIZE_PATH); } /*ARGSUSED*/ CCRETVAL e_normalize_command(Char c) { USE(c); *LastChar = '\0'; /* just in case */ return(CC_NORMALIZE_COMMAND); } /*ARGSUSED*/ CCRETVAL e_expand_vars(Char c) { USE(c); *LastChar = '\0'; /* just in case */ return(CC_EXPAND_VARS); } /*ARGSUSED*/ CCRETVAL e_which(Char c) { /* do a fast command line which(1) */ USE(c); c_save_inputbuf(); Hist_num = 0; /* for the history commands */ PastBottom(); *LastChar = '\0'; /* just in case */ return(CC_WHICH); } /*ARGSUSED*/ CCRETVAL e_last_item(Char c) { /* insert the last element of the prev. cmd */ struct Hist *hp; struct wordent *wp, *firstp; int i; Char *expanded; USE(c); if (Argument <= 0) return(CC_ERROR); hp = Histlist.Hnext; if (hp == NULL) { /* this is only if no history */ return(CC_ERROR); } wp = (hp->Hlex).prev; if (wp->prev == (struct wordent *) NULL) return(CC_ERROR); /* an empty history entry */ firstp = (hp->Hlex).next; /* back up arg words in lex */ for (i = 0; i < Argument && wp != firstp; i++) { wp = wp->prev; } expanded = expand_lex(wp->prev, 0, i - 1); if (InsertStr(expanded)) { xfree(expanded); return(CC_ERROR); } xfree(expanded); return(CC_REFRESH); } /*ARGSUSED*/ CCRETVAL e_dabbrev_expand(Char c) { /* expand to preceding word matching prefix */ Char *cp, *ncp, *bp; struct Hist *hp; int arg = 0, i; size_t len = 0; int found = 0; Char *hbuf; static int oldevent, hist, word; static Char *start, *oldcursor; USE(c); if (Argument <= 0) return(CC_ERROR); cp = c_preword(Cursor, InputBuf, 1, STRshwordsep); if (cp == Cursor || Isspace(*cp)) return(CC_ERROR); hbuf = NULL; hp = Histlist.Hnext; bp = InputBuf; if (Argument == 1 && eventno == oldevent && cp == start && Cursor == oldcursor && patbuf.len > 0 && Strncmp(patbuf.s, cp, patbuf.len) == 0){ /* continue previous search - go to last match (hist/word) */ if (hist != 0) { /* need to move up history */ for (i = 1; i < hist && hp != NULL; i++) hp = hp->Hnext; if (hp == NULL) /* "can't happen" */ goto err_hbuf; hbuf = expand_lex(&hp->Hlex, 0, INT_MAX); cp = Strend(hbuf); bp = hbuf; hp = hp->Hnext; } cp = c_preword(cp, bp, word, STRshwordsep); } else { /* starting new search */ oldevent = eventno; start = cp; patbuf.len = 0; Strbuf_appendn(&patbuf, cp, Cursor - cp); hist = 0; word = 0; } while (!found) { ncp = c_preword(cp, bp, 1, STRshwordsep); if (ncp == cp || Isspace(*ncp)) { /* beginning of line */ hist++; word = 0; if (hp == NULL) goto err_hbuf; hbuf = expand_lex(&hp->Hlex, 0, INT_MAX); cp = Strend(hbuf); bp = hbuf; hp = hp->Hnext; continue; } else { word++; len = c_endword(ncp-1, cp, 1, STRshwordsep) - ncp + 1; cp = ncp; } if (len > patbuf.len && Strncmp(cp, patbuf.s, patbuf.len) == 0) { /* We don't fully check distinct matches as Gnuemacs does: */ if (Argument > 1) { /* just count matches */ if (++arg >= Argument) found++; } else { /* match if distinct from previous */ if (len != (size_t)(Cursor - start) || Strncmp(cp, start, len) != 0) found++; } } } if (LastChar + len - (Cursor - start) >= InputLim) goto err_hbuf; /* no room */ DeleteBack(Cursor - start); c_insert(len); while (len--) *Cursor++ = *cp++; oldcursor = Cursor; xfree(hbuf); return(CC_REFRESH); err_hbuf: xfree(hbuf); return CC_ERROR; } /*ARGSUSED*/ CCRETVAL e_yank_kill(Char c) { /* almost like GnuEmacs */ int len; Char *kp, *cp; USE(c); if (KillRingLen == 0) /* nothing killed */ return(CC_ERROR); len = Strlen(KillRing[YankPos].buf); if (LastChar + len >= InputLim) return(CC_ERROR); /* end of buffer space */ /* else */ cp = Cursor; /* for speed */ c_insert(len); /* open the space, */ for (kp = KillRing[YankPos].buf; *kp; kp++) /* copy the chars */ *cp++ = *kp; if (Argument == 1) { /* if no arg */ Mark = Cursor; /* mark at beginning, cursor at end */ Cursor = cp; } else { Mark = cp; /* else cursor at beginning, mark at end */ } if (adrof(STRhighlight) && MarkIsSet) { ClearLines(); ClearDisp(); } MarkIsSet = 0; return(CC_REFRESH); } /*ARGSUSED*/ CCRETVAL e_yank_pop(Char c) { /* almost like GnuEmacs */ int m_bef_c, del_len, ins_len; Char *kp, *cp; USE(c); #if 0 /* XXX This "should" be here, but doesn't work, since LastCmd gets set on CC_ERROR and CC_ARGHACK, which it shouldn't(?). (But what about F_ARGFOUR?) I.e. if you hit M-y twice the second one will "succeed" even if the first one wasn't preceded by a yank, and giving an argument is impossible. Now we "succeed" regardless of previous command, which is wrong too of course. */ if (LastCmd != F_YANK_KILL && LastCmd != F_YANK_POP) return(CC_ERROR); #endif if (KillRingLen == 0) /* nothing killed */ return(CC_ERROR); YankPos -= Argument; while (YankPos < 0) YankPos += KillRingLen; YankPos %= KillRingLen; if (Cursor > Mark) { del_len = Cursor - Mark; m_bef_c = 1; } else { del_len = Mark - Cursor; m_bef_c = 0; } ins_len = Strlen(KillRing[YankPos].buf); if (LastChar + ins_len - del_len >= InputLim) return(CC_ERROR); /* end of buffer space */ if (m_bef_c) { c_delbefore(del_len); } else { c_delafter(del_len); } cp = Cursor; /* for speed */ c_insert(ins_len); /* open the space, */ for (kp = KillRing[YankPos].buf; *kp; kp++) /* copy the chars */ *cp++ = *kp; if (m_bef_c) { Mark = Cursor; /* mark at beginning, cursor at end */ Cursor = cp; } else { Mark = cp; /* else cursor at beginning, mark at end */ } if (adrof(STRhighlight) && MarkIsSet) { ClearLines(); ClearDisp(); } MarkIsSet = 0; return(CC_REFRESH); } /*ARGSUSED*/ CCRETVAL v_delprev(Char c) /* Backspace key in insert mode */ { int rc; USE(c); rc = CC_ERROR; if (InsertPos != 0) { if (Argument <= Cursor - InsertPos) { c_delbefore(Argument); /* delete before */ rc = CC_REFRESH; } } return(rc); } /* v_delprev */ /*ARGSUSED*/ CCRETVAL e_delprev(Char c) { USE(c); if (Cursor > InputBuf) { c_delbefore(Argument); /* delete before dot */ return(CC_REFRESH); } else { return(CC_ERROR); } } /*ARGSUSED*/ CCRETVAL e_delwordprev(Char c) { Char *cp; USE(c); if (Cursor == InputBuf) return(CC_ERROR); /* else */ cp = c_prev_word(Cursor, InputBuf, Argument); c_push_kill(cp, Cursor); /* save the text */ c_delbefore((int)(Cursor - cp)); /* delete before dot */ return(CC_REFRESH); } /* DCS , 9 Oct 93 * * Changed the names of some of the ^D family of editor functions to * correspond to what they actually do and created new e_delnext_list * for completeness. * * Old names: New names: * * delete-char delete-char-or-eof * F_DELNEXT F_DELNEXT_EOF * e_delnext e_delnext_eof * edelnxt edelnxteof * delete-char-or-eof delete-char * F_DELNEXT_EOF F_DELNEXT * e_delnext_eof e_delnext * edelnxteof edelnxt * delete-char-or-list delete-char-or-list-or-eof * F_LIST_DELNEXT F_DELNEXT_LIST_EOF * e_list_delnext e_delnext_list_eof * edellsteof * (no old equivalent) delete-char-or-list * F_DELNEXT_LIST * e_delnext_list * e_delnxtlst */ /* added by mtk@ari.ncl.omron.co.jp (920818) */ /* rename e_delnext() -> e_delnext_eof() */ /*ARGSUSED*/ CCRETVAL e_delnext(Char c) { USE(c); if (Cursor == LastChar) {/* if I'm at the end */ if (!VImode) { return(CC_ERROR); } else { if (Cursor != InputBuf) Cursor--; else return(CC_ERROR); } } c_delafter(Argument); /* delete after dot */ if (Cursor > LastChar) Cursor = LastChar; /* bounds check */ return(CC_REFRESH); } /*ARGSUSED*/ CCRETVAL e_delnext_eof(Char c) { USE(c); if (Cursor == LastChar) {/* if I'm at the end */ if (!VImode) { if (Cursor == InputBuf) { /* if I'm also at the beginning */ so_write(STReof, 4);/* then do a EOF */ flush(); return(CC_EOF); } else return(CC_ERROR); } else { if (Cursor != InputBuf) Cursor--; else return(CC_ERROR); } } c_delafter(Argument); /* delete after dot */ if (Cursor > LastChar) Cursor = LastChar; /* bounds check */ return(CC_REFRESH); } /*ARGSUSED*/ CCRETVAL e_delnext_list(Char c) { USE(c); if (Cursor == LastChar) { /* if I'm at the end */ PastBottom(); *LastChar = '\0'; /* just in case */ return(CC_LIST_CHOICES); } else { c_delafter(Argument); /* delete after dot */ if (Cursor > LastChar) Cursor = LastChar; /* bounds check */ return(CC_REFRESH); } } /*ARGSUSED*/ CCRETVAL e_delnext_list_eof(Char c) { USE(c); if (Cursor == LastChar) { /* if I'm at the end */ if (Cursor == InputBuf) { /* if I'm also at the beginning */ so_write(STReof, 4);/* then do a EOF */ flush(); return(CC_EOF); } else { PastBottom(); *LastChar = '\0'; /* just in case */ return(CC_LIST_CHOICES); } } else { c_delafter(Argument); /* delete after dot */ if (Cursor > LastChar) Cursor = LastChar; /* bounds check */ return(CC_REFRESH); } } /*ARGSUSED*/ CCRETVAL e_list_eof(Char c) { CCRETVAL rv; USE(c); if (Cursor == LastChar && Cursor == InputBuf) { so_write(STReof, 4); /* then do a EOF */ flush(); rv = CC_EOF; } else { PastBottom(); *LastChar = '\0'; /* just in case */ rv = CC_LIST_CHOICES; } return rv; } /*ARGSUSED*/ CCRETVAL e_delwordnext(Char c) { Char *cp; USE(c); if (Cursor == LastChar) return(CC_ERROR); /* else */ cp = c_next_word(Cursor, LastChar, Argument); c_push_kill(Cursor, cp); /* save the text */ c_delafter((int)(cp - Cursor)); /* delete after dot */ if (Cursor > LastChar) Cursor = LastChar; /* bounds check */ return(CC_REFRESH); } /*ARGSUSED*/ CCRETVAL e_toend(Char c) { USE(c); Cursor = LastChar; if (VImode) if (ActionFlag & TCSHOP_DELETE) { c_delfini(); return(CC_REFRESH); } RefCursor(); /* move the cursor */ return(CC_NORM); } /*ARGSUSED*/ CCRETVAL e_tobeg(Char c) { USE(c); Cursor = InputBuf; if (VImode) { while (Isspace(*Cursor)) /* We want FIRST non space character */ Cursor++; if (ActionFlag & TCSHOP_DELETE) { c_delfini(); return(CC_REFRESH); } } RefCursor(); /* move the cursor */ return(CC_NORM); } /*ARGSUSED*/ CCRETVAL e_killend(Char c) { USE(c); c_push_kill(Cursor, LastChar); /* copy it */ LastChar = Cursor; /* zap! -- delete to end */ if (Mark > Cursor) Mark = Cursor; MarkIsSet = 0; return(CC_REFRESH); } /*ARGSUSED*/ CCRETVAL e_killbeg(Char c) { USE(c); c_push_kill(InputBuf, Cursor); /* copy it */ c_delbefore((int)(Cursor - InputBuf)); if (Mark && Mark > Cursor) Mark -= Cursor-InputBuf; return(CC_REFRESH); } /*ARGSUSED*/ CCRETVAL e_killall(Char c) { USE(c); c_push_kill(InputBuf, LastChar); /* copy it */ Cursor = Mark = LastChar = InputBuf; /* zap! -- delete all of it */ MarkIsSet = 0; return(CC_REFRESH); } /*ARGSUSED*/ CCRETVAL e_killregion(Char c) { USE(c); if (!Mark) return(CC_ERROR); if (Mark > Cursor) { c_push_kill(Cursor, Mark); /* copy it */ c_delafter((int)(Mark - Cursor)); /* delete it - UNUSED BY VI mode */ Mark = Cursor; } else { /* mark is before cursor */ c_push_kill(Mark, Cursor); /* copy it */ c_delbefore((int)(Cursor - Mark)); } if (adrof(STRhighlight) && MarkIsSet) { ClearLines(); ClearDisp(); } MarkIsSet = 0; return(CC_REFRESH); } /*ARGSUSED*/ CCRETVAL e_copyregion(Char c) { USE(c); if (!Mark) return(CC_ERROR); if (Mark > Cursor) { c_push_kill(Cursor, Mark); /* copy it */ } else { /* mark is before cursor */ c_push_kill(Mark, Cursor); /* copy it */ } return(CC_NORM); /* don't even need to Refresh() */ } /*ARGSUSED*/ CCRETVAL e_charswitch(Char cc) { Char c; USE(cc); /* do nothing if we are at beginning of line or have only one char */ if (Cursor == &InputBuf[0] || LastChar == &InputBuf[1]) { return(CC_ERROR); } if (Cursor < LastChar) { Cursor++; } c = Cursor[-2]; Cursor[-2] = Cursor[-1]; Cursor[-1] = c; return(CC_REFRESH); } /*ARGSUSED*/ CCRETVAL e_gcharswitch(Char cc) { /* gosmacs style ^T */ Char c; USE(cc); if (Cursor > &InputBuf[1]) {/* must have at least two chars entered */ c = Cursor[-2]; Cursor[-2] = Cursor[-1]; Cursor[-1] = c; return(CC_REFRESH); } else { return(CC_ERROR); } } /*ARGSUSED*/ CCRETVAL e_charback(Char c) { USE(c); if (Cursor > InputBuf) { if (Argument > Cursor - InputBuf) Cursor = InputBuf; else Cursor -= Argument; if (VImode) if (ActionFlag & TCSHOP_DELETE) { c_delfini(); return(CC_REFRESH); } RefCursor(); return(CC_NORM); } else { return(CC_ERROR); } } /*ARGSUSED*/ CCRETVAL v_wordback(Char c) { USE(c); if (Cursor == InputBuf) return(CC_ERROR); /* else */ Cursor = c_preword(Cursor, InputBuf, Argument, STRshwspace); /* bounds check */ if (ActionFlag & TCSHOP_DELETE) { c_delfini(); return(CC_REFRESH); } RefCursor(); return(CC_NORM); } /*ARGSUSED*/ CCRETVAL e_wordback(Char c) { USE(c); if (Cursor == InputBuf) return(CC_ERROR); /* else */ Cursor = c_prev_word(Cursor, InputBuf, Argument); /* bounds check */ if (VImode) if (ActionFlag & TCSHOP_DELETE) { c_delfini(); return(CC_REFRESH); } RefCursor(); return(CC_NORM); } /*ARGSUSED*/ CCRETVAL e_charfwd(Char c) { USE(c); if (Cursor < LastChar) { Cursor += Argument; if (Cursor > LastChar) Cursor = LastChar; if (VImode) if (ActionFlag & TCSHOP_DELETE) { c_delfini(); return(CC_REFRESH); } RefCursor(); return(CC_NORM); } else { return(CC_ERROR); } } /*ARGSUSED*/ CCRETVAL e_wordfwd(Char c) { USE(c); if (Cursor == LastChar) return(CC_ERROR); /* else */ Cursor = c_next_word(Cursor, LastChar, Argument); if (VImode) if (ActionFlag & TCSHOP_DELETE) { c_delfini(); return(CC_REFRESH); } RefCursor(); return(CC_NORM); } /*ARGSUSED*/ CCRETVAL v_wordfwd(Char c) { USE(c); if (Cursor == LastChar) return(CC_ERROR); /* else */ Cursor = c_nexword(Cursor, LastChar, Argument); if (VImode) if (ActionFlag & TCSHOP_DELETE) { c_delfini(); return(CC_REFRESH); } RefCursor(); return(CC_NORM); } /*ARGSUSED*/ CCRETVAL v_wordbegnext(Char c) { USE(c); if (Cursor == LastChar) return(CC_ERROR); /* else */ Cursor = c_next_word(Cursor, LastChar, Argument); if (Cursor < LastChar) Cursor++; if (VImode) if (ActionFlag & TCSHOP_DELETE) { c_delfini(); return(CC_REFRESH); } RefCursor(); return(CC_NORM); } /*ARGSUSED*/ static CCRETVAL v_repeat_srch(int c) { CCRETVAL rv = CC_ERROR; #ifdef SDEBUG xprintf("dir %d patlen %d patbuf %S\n", c, (int)patbuf.len, patbuf.s); #endif LastCmd = (KEYCMD) c; /* Hack to stop c_hsetpat */ LastChar = InputBuf; switch (c) { case F_DOWN_SEARCH_HIST: rv = e_down_search_hist(0); break; case F_UP_SEARCH_HIST: rv = e_up_search_hist(0); break; default: break; } return rv; } static CCRETVAL v_csearch_back(Char ch, int count, int tflag) { Char *cp; cp = Cursor; while (count--) { if (*cp == ch) cp--; while (cp > InputBuf && *cp != ch) cp--; } if (cp < InputBuf || (cp == InputBuf && *cp != ch)) return(CC_ERROR); if (*cp == ch && tflag) cp++; Cursor = cp; if (ActionFlag & TCSHOP_DELETE) { Cursor++; c_delfini(); return(CC_REFRESH); } RefCursor(); return(CC_NORM); } static CCRETVAL v_csearch_fwd(Char ch, int count, int tflag) { Char *cp; cp = Cursor; while (count--) { - if(*cp == ch) + if (*cp == ch) cp++; while (cp < LastChar && *cp != ch) cp++; } if (cp >= LastChar) return(CC_ERROR); if (*cp == ch && tflag) cp--; Cursor = cp; if (ActionFlag & TCSHOP_DELETE) { Cursor++; c_delfini(); return(CC_REFRESH); } RefCursor(); return(CC_NORM); } /*ARGSUSED*/ static CCRETVAL v_action(int c) { Char *cp, *kp; if (ActionFlag == TCSHOP_DELETE) { ActionFlag = TCSHOP_NOP; ActionPos = 0; UndoSize = 0; kp = UndoBuf; for (cp = InputBuf; cp < LastChar; cp++) { *kp++ = *cp; UndoSize++; } UndoAction = TCSHOP_INSERT; UndoPtr = InputBuf; LastChar = InputBuf; Cursor = InputBuf; if (c & TCSHOP_INSERT) c_alternativ_key_map(0); return(CC_REFRESH); } #ifdef notdef else if (ActionFlag == TCSHOP_NOP) { #endif ActionPos = Cursor; ActionFlag = c; return(CC_ARGHACK); /* Do NOT clear out argument */ #ifdef notdef } else { ActionFlag = 0; ActionPos = 0; return(CC_ERROR); } #endif } #ifdef COMMENT /* by: Brian Allison */ static void c_get_word(Char **begin, Char **end) { Char *cp; cp = &Cursor[0]; while (Argument--) { while ((cp <= LastChar) && (isword(*cp))) cp++; *end = --cp; while ((cp >= InputBuf) && (isword(*cp))) cp--; *begin = ++cp; } } #endif /* COMMENT */ /*ARGSUSED*/ CCRETVAL e_uppercase(Char c) { Char *cp, *end; USE(c); end = c_next_word(Cursor, LastChar, Argument); for (cp = Cursor; cp < end; cp++) /* PWP: was cp=begin */ if (Islower(*cp)) *cp = Toupper(*cp); Cursor = end; if (Cursor > LastChar) Cursor = LastChar; return(CC_REFRESH); } /*ARGSUSED*/ CCRETVAL e_capitalcase(Char c) { Char *cp, *end; USE(c); end = c_next_word(Cursor, LastChar, Argument); cp = Cursor; for (; cp < end; cp++) { if (Isalpha(*cp)) { if (Islower(*cp)) *cp = Toupper(*cp); cp++; break; } } for (; cp < end; cp++) if (Isupper(*cp)) *cp = Tolower(*cp); Cursor = end; if (Cursor > LastChar) Cursor = LastChar; return(CC_REFRESH); } /*ARGSUSED*/ CCRETVAL e_lowercase(Char c) { Char *cp, *end; USE(c); end = c_next_word(Cursor, LastChar, Argument); for (cp = Cursor; cp < end; cp++) if (Isupper(*cp)) *cp = Tolower(*cp); Cursor = end; if (Cursor > LastChar) Cursor = LastChar; return(CC_REFRESH); } /*ARGSUSED*/ CCRETVAL e_set_mark(Char c) { USE(c); if (adrof(STRhighlight) && MarkIsSet && Mark != Cursor) { ClearLines(); ClearDisp(); Refresh(); } Mark = Cursor; MarkIsSet = 1; return(CC_NORM); } /*ARGSUSED*/ CCRETVAL e_exchange_mark(Char c) { Char *cp; USE(c); cp = Cursor; Cursor = Mark; Mark = cp; RefCursor(); return(CC_NORM); } /*ARGSUSED*/ CCRETVAL e_argfour(Char c) { /* multiply current argument by 4 */ USE(c); if (Argument > 1000000) return CC_ERROR; DoingArg = 1; Argument *= 4; return(CC_ARGHACK); } static void quote_mode_cleanup(void *unused) { USE(unused); QuoteModeOff(); } /*ARGSUSED*/ CCRETVAL e_quote(Char c) { Char ch; int num; USE(c); QuoteModeOn(); cleanup_push(&c, quote_mode_cleanup); /* Using &c just as a mark */ num = GetNextChar(&ch); cleanup_until(&c); if (num == 1) return e_insert(ch); else return e_send_eof(0); } /*ARGSUSED*/ CCRETVAL e_metanext(Char c) { USE(c); MetaNext = 1; return(CC_ARGHACK); /* preserve argument */ } #ifdef notdef /*ARGSUSED*/ CCRETVAL e_extendnext(Char c) { CurrentKeyMap = CcAltMap; return(CC_ARGHACK); /* preserve argument */ } #endif /*ARGSUSED*/ CCRETVAL v_insbeg(Char c) { /* move to beginning of line and start vi * insert mode */ USE(c); Cursor = InputBuf; InsertPos = Cursor; UndoPtr = Cursor; UndoAction = TCSHOP_DELETE; RefCursor(); /* move the cursor */ c_alternativ_key_map(0); return(CC_NORM); } /*ARGSUSED*/ CCRETVAL v_replone(Char c) { /* vi mode overwrite one character */ USE(c); c_alternativ_key_map(0); inputmode = MODE_REPLACE_1; UndoAction = TCSHOP_CHANGE; /* Set Up for VI undo command */ UndoPtr = Cursor; UndoSize = 0; return(CC_NORM); } /*ARGSUSED*/ CCRETVAL v_replmode(Char c) { /* vi mode start overwriting */ USE(c); c_alternativ_key_map(0); inputmode = MODE_REPLACE; UndoAction = TCSHOP_CHANGE; /* Set Up for VI undo command */ UndoPtr = Cursor; UndoSize = 0; return(CC_NORM); } /*ARGSUSED*/ CCRETVAL v_substchar(Char c) { /* vi mode substitute for one char */ USE(c); c_delafter(Argument); c_alternativ_key_map(0); return(CC_REFRESH); } /*ARGSUSED*/ CCRETVAL v_substline(Char c) { /* vi mode replace whole line */ USE(c); (void) e_killall(0); c_alternativ_key_map(0); return(CC_REFRESH); } /*ARGSUSED*/ CCRETVAL v_chgtoend(Char c) { /* vi mode change to end of line */ USE(c); (void) e_killend(0); c_alternativ_key_map(0); return(CC_REFRESH); } /*ARGSUSED*/ CCRETVAL v_insert(Char c) { /* vi mode start inserting */ USE(c); c_alternativ_key_map(0); InsertPos = Cursor; UndoPtr = Cursor; UndoAction = TCSHOP_DELETE; return(CC_NORM); } /*ARGSUSED*/ CCRETVAL v_add(Char c) { /* vi mode start adding */ USE(c); c_alternativ_key_map(0); if (Cursor < LastChar) { Cursor++; if (Cursor > LastChar) Cursor = LastChar; RefCursor(); } InsertPos = Cursor; UndoPtr = Cursor; UndoAction = TCSHOP_DELETE; return(CC_NORM); } /*ARGSUSED*/ CCRETVAL v_addend(Char c) { /* vi mode to add at end of line */ USE(c); c_alternativ_key_map(0); Cursor = LastChar; InsertPos = LastChar; /* Mark where insertion begins */ UndoPtr = LastChar; UndoAction = TCSHOP_DELETE; RefCursor(); return(CC_NORM); } /*ARGSUSED*/ CCRETVAL v_change_case(Char cc) { Char c; USE(cc); if (Cursor < LastChar) { #ifndef WINNT_NATIVE c = *Cursor; #else c = CHAR & *Cursor; #endif /* WINNT_NATIVE */ if (Isupper(c)) *Cursor++ = Tolower(c); else if (Islower(c)) *Cursor++ = Toupper(c); else Cursor++; RefPlusOne(1); /* fast refresh for one char */ return(CC_NORM); } return(CC_ERROR); } /*ARGSUSED*/ CCRETVAL e_expand(Char c) { Char *p; USE(c); for (p = InputBuf; Isspace(*p); p++) continue; if (p == LastChar) return(CC_ERROR); justpr++; Expand++; return(e_newline(0)); } /*ARGSUSED*/ CCRETVAL e_startover(Char c) { /* erase all of current line, start again */ USE(c); ResetInLine(0); /* reset the input pointers */ return(CC_REFRESH); } /*ARGSUSED*/ CCRETVAL e_redisp(Char c) { USE(c); ClearLines(); ClearDisp(); return(CC_REFRESH); } /*ARGSUSED*/ CCRETVAL e_cleardisp(Char c) { USE(c); ClearScreen(); /* clear the whole real screen */ ClearDisp(); /* reset everything */ return(CC_REFRESH); } /*ARGSUSED*/ CCRETVAL e_tty_int(Char c) { USE(c); #if defined(_MINIX) || defined(WINNT_NATIVE) /* SAK PATCH: erase all of current line, start again */ ResetInLine(0); /* reset the input pointers */ xputchar('\n'); ClearDisp(); return (CC_REFRESH); #else /* !_MINIX && !WINNT_NATIVE */ /* do no editing */ return (CC_NORM); #endif /* _MINIX || WINNT_NATIVE */ } /* * From: ghazi@cesl.rutgers.edu (Kaveh R. Ghazi) * Function to send a character back to the input stream in cooked * mode. Only works if we have TIOCSTI */ /*ARGSUSED*/ CCRETVAL e_stuff_char(Char c) { #ifdef TIOCSTI int was_raw = Tty_raw_mode; char buf[MB_LEN_MAX]; size_t i, len; if (was_raw) (void) Cookedmode(); (void) xwrite(SHIN, "\n", 1); len = one_wctomb(buf, c); for (i = 0; i < len; i++) (void) ioctl(SHIN, TIOCSTI, (ioctl_t) &buf[i]); if (was_raw) (void) Rawmode(); return(e_redisp(c)); #else /* !TIOCSTI */ return(CC_ERROR); #endif /* !TIOCSTI */ } /*ARGSUSED*/ CCRETVAL e_insovr(Char c) { USE(c); inputmode = (inputmode == MODE_INSERT ? MODE_REPLACE : MODE_INSERT); return(CC_NORM); } /*ARGSUSED*/ CCRETVAL e_tty_dsusp(Char c) { USE(c); /* do no editing */ return(CC_NORM); } /*ARGSUSED*/ CCRETVAL e_tty_flusho(Char c) { USE(c); /* do no editing */ return(CC_NORM); } /*ARGSUSED*/ CCRETVAL e_tty_quit(Char c) { USE(c); /* do no editing */ return(CC_NORM); } /*ARGSUSED*/ CCRETVAL e_tty_tsusp(Char c) { USE(c); /* do no editing */ return(CC_NORM); } /*ARGSUSED*/ CCRETVAL e_tty_stopo(Char c) { USE(c); /* do no editing */ return(CC_NORM); } /* returns the number of (attempted) expansions */ int ExpandHistory(void) { *LastChar = '\0'; /* just in case */ return c_substitute(); } /*ARGSUSED*/ CCRETVAL e_expand_history(Char c) { USE(c); (void)ExpandHistory(); return(CC_NORM); } /*ARGSUSED*/ CCRETVAL e_magic_space(Char c) { USE(c); *LastChar = '\0'; /* just in case */ (void)c_substitute(); return(e_insert(' ')); } /*ARGSUSED*/ CCRETVAL e_inc_fwd(Char c) { CCRETVAL ret; USE(c); patbuf.len = 0; MarkIsSet = 0; ret = e_inc_search(F_DOWN_SEARCH_HIST); if (adrof(STRhighlight) && IncMatchLen) { IncMatchLen = 0; ClearLines(); ClearDisp(); Refresh(); } IncMatchLen = 0; return ret; } /*ARGSUSED*/ CCRETVAL e_inc_back(Char c) { CCRETVAL ret; USE(c); patbuf.len = 0; MarkIsSet = 0; ret = e_inc_search(F_UP_SEARCH_HIST); if (adrof(STRhighlight) && IncMatchLen) { IncMatchLen = 0; ClearLines(); ClearDisp(); Refresh(); } IncMatchLen = 0; return ret; } /*ARGSUSED*/ CCRETVAL e_copyprev(Char c) { Char *cp, *oldc, *dp; USE(c); if (Cursor == InputBuf) return(CC_ERROR); /* else */ oldc = Cursor; /* does a bounds check */ cp = c_prev_word(Cursor, InputBuf, Argument); c_insert((int)(oldc - cp)); for (dp = oldc; cp < oldc && dp < LastChar; cp++) *dp++ = *cp; Cursor = dp; /* put cursor at end */ return(CC_REFRESH); } /*ARGSUSED*/ CCRETVAL e_tty_starto(Char c) { USE(c); /* do no editing */ return(CC_NORM); } /*ARGSUSED*/ CCRETVAL e_load_average(Char c) { USE(c); PastBottom(); #ifdef TIOCSTAT /* * Here we pass &c to the ioctl because some os's (NetBSD) expect it * there even if they don't use it. (lukem@netbsd.org) */ if (ioctl(SHIN, TIOCSTAT, (ioctl_t) &c) < 0) #endif xprintf("%s", CGETS(5, 1, "Load average unavailable\n")); return(CC_REFRESH); } /*ARGSUSED*/ CCRETVAL v_chgmeta(Char c) { USE(c); /* * Delete with insert == change: first we delete and then we leave in * insert mode. */ return(v_action(TCSHOP_DELETE|TCSHOP_INSERT)); } /*ARGSUSED*/ CCRETVAL v_delmeta(Char c) { USE(c); return(v_action(TCSHOP_DELETE)); } /*ARGSUSED*/ CCRETVAL v_endword(Char c) { USE(c); if (Cursor == LastChar) return(CC_ERROR); /* else */ Cursor = c_endword(Cursor, LastChar, Argument, STRshwspace); if (ActionFlag & TCSHOP_DELETE) { Cursor++; c_delfini(); return(CC_REFRESH); } RefCursor(); return(CC_NORM); } /*ARGSUSED*/ CCRETVAL v_eword(Char c) { USE(c); if (Cursor == LastChar) return(CC_ERROR); /* else */ Cursor = c_eword(Cursor, LastChar, Argument); if (ActionFlag & TCSHOP_DELETE) { Cursor++; c_delfini(); return(CC_REFRESH); } RefCursor(); return(CC_NORM); } /*ARGSUSED*/ CCRETVAL v_char_fwd(Char c) { Char ch; USE(c); if (GetNextChar(&ch) != 1) return e_send_eof(0); srch_dir = CHAR_FWD; srch_char = ch; return v_csearch_fwd(ch, Argument, 0); } /*ARGSUSED*/ CCRETVAL v_char_back(Char c) { Char ch; USE(c); if (GetNextChar(&ch) != 1) return e_send_eof(0); srch_dir = CHAR_BACK; srch_char = ch; return v_csearch_back(ch, Argument, 0); } /*ARGSUSED*/ CCRETVAL v_charto_fwd(Char c) { Char ch; USE(c); if (GetNextChar(&ch) != 1) return e_send_eof(0); return v_csearch_fwd(ch, Argument, 1); } /*ARGSUSED*/ CCRETVAL v_charto_back(Char c) { Char ch; USE(c); if (GetNextChar(&ch) != 1) return e_send_eof(0); return v_csearch_back(ch, Argument, 1); } /*ARGSUSED*/ CCRETVAL v_rchar_fwd(Char c) { USE(c); if (srch_char == 0) return CC_ERROR; return srch_dir == CHAR_FWD ? v_csearch_fwd(srch_char, Argument, 0) : v_csearch_back(srch_char, Argument, 0); } /*ARGSUSED*/ CCRETVAL v_rchar_back(Char c) { USE(c); if (srch_char == 0) return CC_ERROR; return srch_dir == CHAR_BACK ? v_csearch_fwd(srch_char, Argument, 0) : v_csearch_back(srch_char, Argument, 0); } /*ARGSUSED*/ CCRETVAL v_undo(Char c) { int loop; Char *kp, *cp; Char temp; int size; USE(c); switch (UndoAction) { case TCSHOP_DELETE|TCSHOP_INSERT: case TCSHOP_DELETE: if (UndoSize == 0) return(CC_NORM); cp = UndoPtr; kp = UndoBuf; for (loop=0; loop < UndoSize; loop++) /* copy the chars */ *kp++ = *cp++; /* into UndoBuf */ for (cp = UndoPtr; cp <= LastChar; cp++) *cp = cp[UndoSize]; LastChar -= UndoSize; Cursor = UndoPtr; UndoAction = TCSHOP_INSERT; break; case TCSHOP_INSERT: if (UndoSize == 0) return(CC_NORM); cp = UndoPtr; Cursor = UndoPtr; kp = UndoBuf; c_insert(UndoSize); /* open the space, */ for (loop = 0; loop < UndoSize; loop++) /* copy the chars */ *cp++ = *kp++; UndoAction = TCSHOP_DELETE; break; case TCSHOP_CHANGE: if (UndoSize == 0) return(CC_NORM); cp = UndoPtr; Cursor = UndoPtr; kp = UndoBuf; size = (int)(Cursor-LastChar); /* NOT NSL independant */ if (size < UndoSize) size = UndoSize; - for(loop = 0; loop < size; loop++) { + for (loop = 0; loop < size; loop++) { temp = *kp; *kp++ = *cp; *cp++ = temp; } break; default: return(CC_ERROR); } return(CC_REFRESH); } /*ARGSUSED*/ CCRETVAL v_ush_meta(Char c) { USE(c); return v_search(F_UP_SEARCH_HIST); } /*ARGSUSED*/ CCRETVAL v_dsh_meta(Char c) { USE(c); return v_search(F_DOWN_SEARCH_HIST); } /*ARGSUSED*/ CCRETVAL v_rsrch_fwd(Char c) { USE(c); if (patbuf.len == 0) return(CC_ERROR); return(v_repeat_srch(searchdir)); } /*ARGSUSED*/ CCRETVAL v_rsrch_back(Char c) { USE(c); if (patbuf.len == 0) return(CC_ERROR); return(v_repeat_srch(searchdir == F_UP_SEARCH_HIST ? F_DOWN_SEARCH_HIST : F_UP_SEARCH_HIST)); } #ifndef WINNT_NATIVE /* Since ed.defns.h is generated from ed.defns.c, these empty functions will keep the F_NUM_FNS consistent */ CCRETVAL e_copy_to_clipboard(Char c) { USE(c); return CC_ERROR; } CCRETVAL e_paste_from_clipboard(Char c) { USE(c); return (CC_ERROR); } CCRETVAL e_dosify_next(Char c) { USE(c); return (CC_ERROR); } CCRETVAL e_dosify_prev(Char c) { USE(c); return (CC_ERROR); } CCRETVAL e_page_up(Char c) { USE(c); return (CC_ERROR); } CCRETVAL e_page_down(Char c) { USE(c); return (CC_ERROR); } #endif /* !WINNT_NATIVE */ #ifdef notdef void MoveCursor(int n) /* move cursor + right - left char */ { Cursor = Cursor + n; if (Cursor < InputBuf) Cursor = InputBuf; if (Cursor > LastChar) Cursor = LastChar; return; } Char * GetCursor(void) { return(Cursor); } int PutCursor(Char *p) { if (p < InputBuf || p > LastChar) return 1; /* Error */ Cursor = p; return 0; } #endif diff --git a/contrib/tcsh/ed.inputl.c b/contrib/tcsh/ed.inputl.c index bd8cf7815f4b..8d4c341631b0 100644 --- a/contrib/tcsh/ed.inputl.c +++ b/contrib/tcsh/ed.inputl.c @@ -1,955 +1,955 @@ /* * ed.inputl.c: Input line handling. */ /*- * Copyright (c) 1980, 1991 The Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include "sh.h" #include "ed.h" #include "ed.defns.h" /* for the function names */ #include "tw.h" /* for twenex stuff */ #define OKCMD INT_MAX /* ed.inputl -- routines to get a single line from the input. */ extern int MapsAreInited; /* mismatched first character */ static Char mismatch[] = { '\\', '-', '%', '\0' }; /* don't Strchr() for '\0', obey current history character settings */ #define MISMATCH(c) ((c) == '\0' || (c) == HIST || (c) == HISTSUB || \ Strchr(mismatch, (c))) static int Repair (void); static int GetNextCommand (KEYCMD *, Char *); static int SpellLine (int); static int CompleteLine (void); static void RunCommand (Char *); static void doeval1 (Char **); static int rotate = 0; static int Repair(void) { if (NeedsRedraw) { ClearLines(); ClearDisp(); NeedsRedraw = 0; } Refresh(); Argument = 1; DoingArg = 0; curchoice = -1; return (int) (LastChar - InputBuf); } /* CCRETVAL */ int Inputl(void) { CCRETVAL retval; KEYCMD cmdnum = 0; unsigned char tch; /* the place where read() goes */ Char ch; int num; /* how many chars we have read at NL */ int expnum; struct varent *crct = inheredoc ? NULL : adrof(STRcorrect); struct varent *autol = adrof(STRautolist); struct varent *matchbeep = adrof(STRmatchbeep); struct varent *imode = adrof(STRinputmode); Char *SaveChar, *CorrChar; int matchval; /* from tenematch() */ int nr_history_exp; /* number of (attempted) history expansions */ COMMAND fn; int curlen = 0; int newlen; int idx; Char *autoexpand; if (!MapsAreInited) /* double extra just in case */ ed_InitMaps(); ClearDisp(); /* reset the display stuff */ ResetInLine(0); /* reset the input pointers */ if (GettingInput) MacroLvl = -1; /* editor was interrupted during input */ if (imode && imode->vec != NULL) { if (!Strcmp(*(imode->vec), STRinsert)) inputmode = MODE_INSERT; else if (!Strcmp(*(imode->vec), STRoverwrite)) inputmode = MODE_REPLACE; } #if defined(FIONREAD) && !defined(OREO) if (!Tty_raw_mode && MacroLvl < 0) { # ifdef SUNOS4 long chrs = 0; # else /* !SUNOS4 */ /* * *Everyone* else has an int, but SunOS wants long! * This breaks where int != long (alpha) */ int chrs = 0; # endif /* SUNOS4 */ (void) ioctl(SHIN, FIONREAD, (ioctl_t) & chrs); if (chrs == 0) { if (Rawmode() < 0) return 0; } } #endif /* FIONREAD && !OREO */ GettingInput = 1; NeedsRedraw = 0; tellwhat = 0; if (RestoreSaved) { copyn(InputBuf, SavedBuf.s, INBUFSIZE);/*FIXBUF*/ LastChar = InputBuf + LastSaved; Cursor = InputBuf + CursSaved; Hist_num = HistSaved; HistSaved = 0; RestoreSaved = 0; } if (HistSaved) { Hist_num = HistSaved; GetHistLine(); HistSaved = 0; } if (Expand) { (void) e_up_hist(0); Expand = 0; } Refresh(); /* print the prompt */ for (num = OKCMD; num == OKCMD;) { /* while still editing this line */ #ifdef DEBUG_EDIT if (Cursor > LastChar) xprintf("Cursor > LastChar\r\n"); if (Cursor < InputBuf) xprintf("Cursor < InputBuf\r\n"); if (Cursor > InputLim) xprintf("Cursor > InputLim\r\n"); if (LastChar > InputLim) xprintf("LastChar > InputLim\r\n"); if (InputLim != &InputBuf[INBUFSIZE - 2])/*FIXBUF*/ xprintf("InputLim != &InputBuf[INBUFSIZE-2]\r\n"); if ((!DoingArg) && (Argument != 1)) xprintf("(!DoingArg) && (Argument != 1)\r\n"); if (CcKeyMap[0] == 0) xprintf("CcKeyMap[0] == 0 (maybe not inited)\r\n"); #endif /* if EOF or error */ if ((num = GetNextCommand(&cmdnum, &ch)) != OKCMD) { break; } if (cmdnum >= NumFuns) {/* BUG CHECK command */ #ifdef DEBUG_EDIT xprintf(CGETS(6, 1, "ERROR: illegal command from key 0%o\r\n"), ch); #endif continue; /* try again */ } /* now do the real command */ retval = (*CcFuncTbl[cmdnum]) (ch); /* save the last command here */ LastCmd = cmdnum; /* make sure fn is initialized */ fn = (retval == CC_COMPLETE_ALL) ? LIST_ALL : LIST; /* use any return value */ switch (retval) { case CC_REFRESH: Refresh(); /*FALLTHROUGH*/ case CC_NORM: /* normal char */ Argument = 1; DoingArg = 0; /*FALLTHROUGH*/ case CC_ARGHACK: /* Suggested by Rich Salz */ /* */ curchoice = -1; curlen = (int) (LastChar - InputBuf); break; /* keep going... */ case CC_EOF: /* end of file typed */ curchoice = -1; curlen = (int) (LastChar - InputBuf); num = 0; break; case CC_WHICH: /* tell what this command does */ tellwhat = 1; *LastChar++ = '\n'; /* for the benifit of CSH */ num = (int) (LastChar - InputBuf); /* number characters read */ break; case CC_NEWLINE: /* normal end of line */ curlen = 0; curchoice = -1; matchval = 1; if (crct && crct->vec != NULL && (!Strcmp(*(crct->vec), STRcmd) || !Strcmp(*(crct->vec), STRall))) { Char *Origin; PastBottom(); Origin = Strsave(InputBuf); cleanup_push(Origin, xfree); SaveChar = LastChar; if (SpellLine(!Strcmp(*(crct->vec), STRcmd)) == 1) { Char *Change; PastBottom(); Change = Strsave(InputBuf); cleanup_push(Change, xfree); *Strchr(Change, '\n') = '\0'; CorrChar = LastChar; /* Save the corrected end */ LastChar = InputBuf; /* Null the current line */ SoundBeep(); printprompt(2, short2str(Change)); cleanup_until(Change); Refresh(); if (xread(SHIN, &tch, 1) < 0) { #ifdef convex /* * need to print error message in case file * is migrated */ if (errno) stderror(ERR_SYSTEM, progname, strerror(errno)); #else cleanup_until(Origin); break; #endif } ch = tch; if (ch == 'y' || ch == ' ') { LastChar = CorrChar; /* Restore the corrected end */ xprintf("%s", CGETS(6, 2, "yes\n")); } else { Strcpy(InputBuf, Origin); LastChar = SaveChar; if (ch == 'e') { xprintf("%s", CGETS(6, 3, "edit\n")); *LastChar-- = '\0'; Cursor = LastChar; printprompt(3, NULL); ClearLines(); ClearDisp(); Refresh(); cleanup_until(Origin); break; } else if (ch == 'a') { xprintf("%s", CGETS(6, 4, "abort\n")); LastChar = InputBuf; /* Null the current line */ Cursor = LastChar; printprompt(0, NULL); Refresh(); cleanup_until(Origin); break; } xprintf("%s", CGETS(6, 5, "no\n")); } flush(); } cleanup_until(Origin); } else if (crct && crct->vec != NULL && !Strcmp(*(crct->vec), STRcomplete)) { if (LastChar > InputBuf && LastChar[-1] == '\n') { LastChar[-1] = '\0'; LastChar--; Cursor = LastChar; } match_unique_match = 1; /* match unique matches */ matchval = CompleteLine(); match_unique_match = 0; curlen = (int) (LastChar - InputBuf); if (matchval != 1) { PastBottom(); } if (matchval == 0) { xprintf("%s", CGETS(6, 6, "No matching command\n")); } else if (matchval == 2) { xprintf("%s", CGETS(6, 7, "Ambiguous command\n")); } if (NeedsRedraw) { ClearLines(); ClearDisp(); NeedsRedraw = 0; } Refresh(); Argument = 1; DoingArg = 0; if (matchval == 1) { PastBottom(); *LastChar++ = '\n'; *LastChar = '\0'; } curlen = (int) (LastChar - InputBuf); } else PastBottom(); if (matchval == 1) { tellwhat = 0; /* just in case */ Hist_num = 0; /* for the history commands */ /* return the number of chars read */ num = (int) (LastChar - InputBuf); /* * For continuation lines, we set the prompt to prompt 2 */ printprompt(1, NULL); } break; case CC_CORRECT: if (tenematch(InputBuf, Cursor - InputBuf, SPELL) < 0) SoundBeep(); /* Beep = No match/ambiguous */ curlen = Repair(); break; case CC_CORRECT_L: if (SpellLine(FALSE) < 0) SoundBeep(); /* Beep = No match/ambiguous */ curlen = Repair(); break; case CC_COMPLETE: case CC_COMPLETE_ALL: case CC_COMPLETE_FWD: case CC_COMPLETE_BACK: switch (retval) { case CC_COMPLETE: fn = RECOGNIZE; curlen = (int) (LastChar - InputBuf); curchoice = -1; rotate = 0; break; case CC_COMPLETE_ALL: fn = RECOGNIZE_ALL; curlen = (int) (LastChar - InputBuf); curchoice = -1; rotate = 0; break; case CC_COMPLETE_FWD: fn = RECOGNIZE_SCROLL; curchoice++; rotate = 1; break; case CC_COMPLETE_BACK: fn = RECOGNIZE_SCROLL; curchoice--; rotate = 1; break; default: abort(); } if (InputBuf[curlen] && rotate) { newlen = (int) (LastChar - InputBuf); for (idx = (int) (Cursor - InputBuf); idx <= newlen; idx++) InputBuf[idx - newlen + curlen] = InputBuf[idx]; LastChar = InputBuf + curlen; Cursor = Cursor - newlen + curlen; } curlen = (int) (LastChar - InputBuf); nr_history_exp = 0; autoexpand = varval(STRautoexpand); if (autoexpand != STRNULL) nr_history_exp += ExpandHistory(); /* try normal expansion only if no history references were found */ if (nr_history_exp == 0 || Strcmp(autoexpand, STRonlyhistory) != 0) { /* * Modified by Martin Boyer (gamin@ireq-robot.hydro.qc.ca): * A separate variable now controls beeping after * completion, independently of autolisting. */ expnum = (int) (Cursor - InputBuf); switch (matchval = tenematch(InputBuf, Cursor-InputBuf, fn)){ case 1: if (non_unique_match && matchbeep && matchbeep->vec != NULL && (Strcmp(*(matchbeep->vec), STRnotunique) == 0)) SoundBeep(); break; case 0: if (matchbeep && matchbeep->vec != NULL) { if (Strcmp(*(matchbeep->vec), STRnomatch) == 0 || Strcmp(*(matchbeep->vec), STRambiguous) == 0 || Strcmp(*(matchbeep->vec), STRnotunique) == 0) SoundBeep(); } else SoundBeep(); break; default: if (matchval < 0) { /* Error from tenematch */ curchoice = -1; SoundBeep(); break; } if (matchbeep && matchbeep->vec != NULL) { if ((Strcmp(*(matchbeep->vec), STRambiguous) == 0 || Strcmp(*(matchbeep->vec), STRnotunique) == 0)) SoundBeep(); } else SoundBeep(); /* * Addition by David C Lawrence : If an * attempted completion is ambiguous, list the choices. * (PWP: this is the best feature addition to tcsh I have * seen in many months.) */ if (autol && autol->vec != NULL && (Strcmp(*(autol->vec), STRambiguous) != 0 || expnum == Cursor - InputBuf)) { if (adrof(STRhighlight) && MarkIsSet) { /* clear highlighting before showing completions */ MarkIsSet = 0; ClearLines(); ClearDisp(); Refresh(); MarkIsSet = 1; } PastBottom(); fn = (retval == CC_COMPLETE_ALL) ? LIST_ALL : LIST; (void) tenematch(InputBuf, Cursor-InputBuf, fn); } break; } } if (NeedsRedraw) { PastBottom(); ClearLines(); ClearDisp(); NeedsRedraw = 0; } Refresh(); Argument = 1; DoingArg = 0; break; case CC_LIST_CHOICES: case CC_LIST_ALL: if (InputBuf[curlen] && rotate) { newlen = (int) (LastChar - InputBuf); for (idx = (int) (Cursor - InputBuf); idx <= newlen; idx++) InputBuf[idx - newlen + curlen] = InputBuf[idx]; LastChar = InputBuf + curlen; Cursor = Cursor - newlen + curlen; } curlen = (int) (LastChar - InputBuf); if (curchoice >= 0) curchoice--; fn = (retval == CC_LIST_ALL) ? LIST_ALL : LIST; /* should catch ^C here... */ if (tenematch(InputBuf, Cursor - InputBuf, fn) < 0) SoundBeep(); Refresh(); Argument = 1; DoingArg = 0; break; case CC_LIST_GLOB: if (tenematch(InputBuf, Cursor - InputBuf, GLOB) < 0) SoundBeep(); curlen = Repair(); break; case CC_EXPAND_GLOB: if (tenematch(InputBuf, Cursor - InputBuf, GLOB_EXPAND) <= 0) SoundBeep(); /* Beep = No match */ curlen = Repair(); break; case CC_NORMALIZE_PATH: if (tenematch(InputBuf, Cursor - InputBuf, PATH_NORMALIZE) <= 0) SoundBeep(); /* Beep = No match */ curlen = Repair(); break; case CC_EXPAND_VARS: if (tenematch(InputBuf, Cursor - InputBuf, VARS_EXPAND) <= 0) SoundBeep(); /* Beep = No match */ curlen = Repair(); break; case CC_NORMALIZE_COMMAND: if (tenematch(InputBuf, Cursor - InputBuf, COMMAND_NORMALIZE) <= 0) SoundBeep(); /* Beep = No match */ curlen = Repair(); break; case CC_HELPME: xputchar('\n'); /* should catch ^C here... */ (void) tenematch(InputBuf, LastChar - InputBuf, PRINT_HELP); Refresh(); Argument = 1; DoingArg = 0; curchoice = -1; curlen = (int) (LastChar - InputBuf); break; case CC_FATAL: /* fatal error, reset to known state */ #ifdef DEBUG_EDIT xprintf(CGETS(7, 8, "*** editor fatal ERROR ***\r\n\n")); #endif /* DEBUG_EDIT */ /* put (real) cursor in a known place */ ClearDisp(); /* reset the display stuff */ ResetInLine(1); /* reset the input pointers */ Refresh(); /* print the prompt again */ Argument = 1; DoingArg = 0; curchoice = -1; curlen = (int) (LastChar - InputBuf); break; case CC_ERROR: default: /* functions we don't know about */ if (adrof(STRhighlight)) { ClearLines(); ClearDisp(); Refresh(); } DoingArg = 0; Argument = 1; SoundBeep(); flush(); curchoice = -1; curlen = (int) (LastChar - InputBuf); break; } } (void) Cookedmode(); /* make sure the tty is set up correctly */ GettingInput = 0; flush(); /* flush any buffered output */ return num; } void PushMacro(Char *str) { if (str != NULL && MacroLvl + 1 < MAXMACROLEVELS) { MacroLvl++; KeyMacro[MacroLvl] = str; } else { SoundBeep(); flush(); } } struct eval1_state { Char **evalvec, *evalp; }; static void eval1_cleanup(void *xstate) { struct eval1_state *state; state = xstate; evalvec = state->evalvec; evalp = state->evalp; doneinp = 0; } /* * Like eval, only using the current file descriptors */ static void doeval1(Char **v) { struct eval1_state state; Char **gv; int gflag; gflag = tglob(v); if (gflag) { gv = v = globall(v, gflag); if (v == 0) stderror(ERR_NOMATCH); v = copyblk(v); } else { gv = NULL; v = copyblk(v); trim(v); } if (gv) cleanup_push(gv, blk_cleanup); state.evalvec = evalvec; state.evalp = evalp; evalvec = v; evalp = 0; cleanup_push(&state, eval1_cleanup); process(0); cleanup_until(&state); if (gv) cleanup_until(gv); } static void RunCommand(Char *str) { Char *cmd[2]; xputchar('\n'); /* Start on a clean line */ cmd[0] = str; cmd[1] = NULL; (void) Cookedmode(); GettingInput = 0; doeval1(cmd); (void) Rawmode(); GettingInput = 1; ClearLines(); ClearDisp(); NeedsRedraw = 0; Refresh(); } int GetCmdChar(Char ch) { #ifndef WINNT_NATIVE // We use more than 256 for various extended keys wint_t c = ch & CHAR; #else wint_t c = ch; #endif return c < NT_NUM_KEYS ? CurrentKeyMap[c] : F_INSERT; } static int GetNextCommand(KEYCMD *cmdnum, Char *ch) { KEYCMD cmd = 0; int num; while (cmd == 0 || cmd == F_XKEY) { if ((num = GetNextChar(ch)) != 1) { /* if EOF or error */ return num; } #ifdef KANJI if ( #ifdef DSPMBYTE _enable_mbdisp && #else MB_LEN_MAX == 1 && #endif !adrof(STRnokanji) && (*ch & META)) { MetaNext = 0; cmd = F_INSERT; break; } else #endif /* KANJI */ if (MetaNext) { MetaNext = 0; *ch |= META; } cmd = GetCmdChar(*ch); if (cmd == F_XKEY) { XmapVal val; CStr cstr; cstr.buf = ch; cstr.len = 1; switch (GetXkey(&cstr, &val)) { case XK_CMD: cmd = val.cmd; break; case XK_STR: PushMacro(val.str.buf); break; case XK_EXE: RunCommand(val.str.buf); break; default: abort(); break; } } if (!AltKeyMap) CurrentKeyMap = CcKeyMap; } *cmdnum = cmd; return OKCMD; } static Char ungetchar; static int haveungetchar; void UngetNextChar(Char cp) { ungetchar = cp; haveungetchar = 1; } int GetNextChar(Char *cp) { int num_read; int tried = 0; char cbuf[MB_LEN_MAX]; size_t cbp; if (haveungetchar) { haveungetchar = 0; *cp = ungetchar; return 1; } for (;;) { if (MacroLvl < 0) { if (!Load_input_line()) break; } if (*KeyMacro[MacroLvl] == 0) { MacroLvl--; continue; } *cp = *KeyMacro[MacroLvl]++ & CHAR; if (*KeyMacro[MacroLvl] == 0) { /* Needed for QuoteMode On */ MacroLvl--; } return (1); } if (Rawmode() < 0) /* make sure the tty is set up correctly */ return 0; /* oops: SHIN was closed */ #ifdef WINNT_NATIVE __nt_want_vcode = 1; #endif /* WINNT_NATIVE */ #ifdef SIG_WINDOW if (windowchg) (void) check_window_size(0); /* for window systems */ #endif /* SIG_WINDOW */ cbp = 0; for (;;) { while ((num_read = xread(SHIN, cbuf + cbp, 1)) == -1) { if (!tried && fixio(SHIN, errno) != -1) tried = 1; else { # ifdef convex /* need to print error message in case the file is migrated */ stderror(ERR_SYSTEM, progname, strerror(errno)); # endif /* convex */ # ifdef WINNT_NATIVE __nt_want_vcode = 0; # endif /* WINNT_NATIVE */ *cp = '\0'; /* Loses possible partial character */ return -1; } } if (cbp == 0 /* && *cbuf < NT_NUM_KEYS */ && CurrentKeyMap[(unsigned char)*cbuf] == F_XKEY) { *cp = (unsigned char)*cbuf; } else { cbp++; if (normal_mbtowc(cp, cbuf, cbp) == -1) { reset_mbtowc(); if (cbp < MB_CUR_MAX) continue; /* Maybe a partial character */ /* And drop the following bytes, if any */ *cp = (unsigned char)*cbuf | INVALID_BYTE; } } break; } #ifdef WINNT_NATIVE /* This is the part that doesn't work with WIDE_STRINGS */ if (__nt_want_vcode == 2) *cp = __nt_vcode; __nt_want_vcode = 0; #endif /* WINNT_NATIVE */ return num_read; } /* * SpellLine - do spelling correction on the entire command line * (which may have trailing newline). * If cmdonly is set, only check spelling of command words. * Return value: * -1: Something was incorrectible, and nothing was corrected * 0: Everything was correct * 1: Something was corrected */ static int SpellLine(int cmdonly) { int endflag, matchval; Char *argptr, *OldCursor, *OldLastChar; OldLastChar = LastChar; OldCursor = Cursor; argptr = InputBuf; endflag = 1; matchval = 0; do { while (ismetahash(*argptr) || iscmdmeta(*argptr)) argptr++; for (Cursor = argptr; *Cursor != '\0' && ((Cursor != argptr && Cursor[-1] == '\\') || (!ismetahash(*Cursor) && !iscmdmeta(*Cursor))); Cursor++) continue; if (*Cursor == '\0') { Cursor = LastChar; if (LastChar[-1] == '\n') Cursor--; endflag = 0; } if (!MISMATCH(*argptr) && (!cmdonly || starting_a_command(argptr, InputBuf))) { #ifdef WINNT_NATIVE /* * This hack avoids correcting drive letter changes */ - if((Cursor - InputBuf) != 2 || (char)InputBuf[1] != ':') + if ((Cursor - InputBuf) != 2 || (char)InputBuf[1] != ':') #endif /* WINNT_NATIVE */ { #ifdef HASH_SPELL_CHECK Char save; size_t len = Cursor - InputBuf; save = InputBuf[len]; InputBuf[len] = '\0'; if (find_cmd(InputBuf, 0) != 0) { InputBuf[len] = save; argptr = Cursor; continue; } InputBuf[len] = save; #endif /* HASH_SPELL_CHECK */ switch (tenematch(InputBuf, Cursor - InputBuf, SPELL)) { case 1: /* corrected */ matchval = 1; break; case -1: /* couldn't be corrected */ if (!matchval) matchval = -1; break; default: /* was correct */ break; } } if (LastChar != OldLastChar) { if (argptr < OldCursor) OldCursor += (LastChar - OldLastChar); OldLastChar = LastChar; } } argptr = Cursor; } while (endflag); Cursor = OldCursor; return matchval; } /* * CompleteLine - do command completion on the entire command line * (which may have trailing newline). * Return value: * 0: No command matched or failure * 1: One command matched * 2: Several commands matched */ static int CompleteLine(void) { int endflag, tmatch; Char *argptr, *OldCursor, *OldLastChar; OldLastChar = LastChar; OldCursor = Cursor; argptr = InputBuf; endflag = 1; do { while (ismetahash(*argptr) || iscmdmeta(*argptr)) argptr++; for (Cursor = argptr; *Cursor != '\0' && ((Cursor != argptr && Cursor[-1] == '\\') || (!ismetahash(*Cursor) && !iscmdmeta(*Cursor))); Cursor++) continue; if (*Cursor == '\0') { Cursor = LastChar; if (LastChar[-1] == '\n') Cursor--; endflag = 0; } if (!MISMATCH(*argptr) && starting_a_command(argptr, InputBuf)) { tmatch = tenematch(InputBuf, Cursor - InputBuf, RECOGNIZE); if (tmatch <= 0) { return 0; } else if (tmatch > 1) { return 2; } if (LastChar != OldLastChar) { if (argptr < OldCursor) OldCursor += (LastChar - OldLastChar); OldLastChar = LastChar; } } argptr = Cursor; } while (endflag); Cursor = OldCursor; return 1; } diff --git a/contrib/tcsh/ed.screen.c b/contrib/tcsh/ed.screen.c index 8d240c886a10..e8b351fe800d 100644 --- a/contrib/tcsh/ed.screen.c +++ b/contrib/tcsh/ed.screen.c @@ -1,1649 +1,1649 @@ /* * ed.screen.c: Editor/termcap-curses interface */ /*- * Copyright (c) 1980, 1991 The Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include "sh.h" #include "ed.h" #include "tc.h" #include "ed.defns.h" /* #define DEBUG_LITERAL */ /* * IMPORTANT NOTE: these routines are allowed to look at the current screen * and the current possition assuming that it is correct. If this is not * true, then the update will be WRONG! This is (should be) a valid * assumption... */ #define TC_BUFSIZE 2048 #define GoodStr(a) (tstr[a].str != NULL && tstr[a].str[0] != '\0') #define Str(a) tstr[a].str #define Val(a) tval[a].val static const struct { const char *b_name; speed_t b_rate; } baud_rate[] = { #ifdef B0 { "0", B0 }, #endif #ifdef B50 { "50", B50 }, #endif #ifdef B75 { "75", B75 }, #endif #ifdef B110 { "110", B110 }, #endif #ifdef B134 { "134", B134 }, #endif #ifdef B150 { "150", B150 }, #endif #ifdef B200 { "200", B200 }, #endif #ifdef B300 { "300", B300 }, #endif #ifdef B600 { "600", B600 }, #endif #ifdef B900 { "900", B900 }, #endif #ifdef B1200 { "1200", B1200 }, #endif #ifdef B1800 { "1800", B1800 }, #endif #ifdef B2400 { "2400", B2400 }, #endif #ifdef B3600 { "3600", B3600 }, #endif #ifdef B4800 { "4800", B4800 }, #endif #ifdef B7200 { "7200", B7200 }, #endif #ifdef B9600 { "9600", B9600 }, #endif #ifdef EXTA { "19200", EXTA }, #endif #ifdef B19200 { "19200", B19200 }, #endif #ifdef EXTB { "38400", EXTB }, #endif #ifdef B38400 { "38400", B38400 }, #endif { NULL, 0 } }; #define T_at7 0 #define T_al 1 #define T_bl 2 #define T_cd 3 #define T_ce 4 #define T_ch 5 #define T_cl 6 #define T_dc 7 #define T_dl 8 #define T_dm 9 #define T_ed 10 #define T_ei 11 #define T_fs 12 #define T_ho 13 #define T_ic 14 #define T_im 15 #define T_ip 16 #define T_kd 17 #define T_kh 18 #define T_kl 19 #define T_kr 20 #define T_ku 21 #define T_md 22 #define T_me 23 #define T_mr 24 #define T_nd 25 #define T_se 26 #define T_so 27 #define T_ts 28 #define T_up 29 #define T_us 30 #define T_ue 31 #define T_vb 32 #define T_DC 33 #define T_DO 34 #define T_IC 35 #define T_LE 36 #define T_RI 37 #define T_UP 38 #define T_str 39 static struct termcapstr { const char *name; const char *long_name; char *str; } tstr[T_str + 1]; #define T_am 0 #define T_pt 1 #define T_li 2 #define T_co 3 #define T_km 4 #define T_xn 5 #define T_val 6 static struct termcapval { const char *name; const char *long_name; int val; } tval[T_val + 1]; void terminit(void) { #ifdef NLS_CATALOGS int i; for (i = 0; i < T_str + 1; i++) xfree((ptr_t)(intptr_t)tstr[i].long_name); for (i = 0; i < T_val + 1; i++) xfree((ptr_t)(intptr_t)tval[i].long_name); #endif tstr[T_al].name = "al"; tstr[T_al].long_name = CSAVS(4, 1, "add new blank line"); tstr[T_bl].name = "bl"; tstr[T_bl].long_name = CSAVS(4, 2, "audible bell"); tstr[T_cd].name = "cd"; tstr[T_cd].long_name = CSAVS(4, 3, "clear to bottom"); tstr[T_ce].name = "ce"; tstr[T_ce].long_name = CSAVS(4, 4, "clear to end of line"); tstr[T_ch].name = "ch"; tstr[T_ch].long_name = CSAVS(4, 5, "cursor to horiz pos"); tstr[T_cl].name = "cl"; tstr[T_cl].long_name = CSAVS(4, 6, "clear screen"); tstr[T_dc].name = "dc"; tstr[T_dc].long_name = CSAVS(4, 7, "delete a character"); tstr[T_dl].name = "dl"; tstr[T_dl].long_name = CSAVS(4, 8, "delete a line"); tstr[T_dm].name = "dm"; tstr[T_dm].long_name = CSAVS(4, 9, "start delete mode"); tstr[T_ed].name = "ed"; tstr[T_ed].long_name = CSAVS(4, 10, "end delete mode"); tstr[T_ei].name = "ei"; tstr[T_ei].long_name = CSAVS(4, 11, "end insert mode"); tstr[T_fs].name = "fs"; tstr[T_fs].long_name = CSAVS(4, 12, "cursor from status line"); tstr[T_ho].name = "ho"; tstr[T_ho].long_name = CSAVS(4, 13, "home cursor"); tstr[T_ic].name = "ic"; tstr[T_ic].long_name = CSAVS(4, 14, "insert character"); tstr[T_im].name = "im"; tstr[T_im].long_name = CSAVS(4, 15, "start insert mode"); tstr[T_ip].name = "ip"; tstr[T_ip].long_name = CSAVS(4, 16, "insert padding"); tstr[T_kd].name = "kd"; tstr[T_kd].long_name = CSAVS(4, 17, "sends cursor down"); tstr[T_kl].name = "kl"; tstr[T_kl].long_name = CSAVS(4, 18, "sends cursor left"); tstr[T_kr].name = "kr"; tstr[T_kr].long_name = CSAVS(4, 19, "sends cursor right"); tstr[T_ku].name = "ku"; tstr[T_ku].long_name = CSAVS(4, 20, "sends cursor up"); tstr[T_md].name = "md"; tstr[T_md].long_name = CSAVS(4, 21, "begin bold"); tstr[T_me].name = "me"; tstr[T_me].long_name = CSAVS(4, 22, "end attributes"); tstr[T_nd].name = "nd"; tstr[T_nd].long_name = CSAVS(4, 23, "non destructive space"); tstr[T_se].name = "se"; tstr[T_se].long_name = CSAVS(4, 24, "end standout"); tstr[T_so].name = "so"; tstr[T_so].long_name = CSAVS(4, 25, "begin standout"); tstr[T_ts].name = "ts"; tstr[T_ts].long_name = CSAVS(4, 26, "cursor to status line"); tstr[T_up].name = "up"; tstr[T_up].long_name = CSAVS(4, 27, "cursor up one"); tstr[T_us].name = "us"; tstr[T_us].long_name = CSAVS(4, 28, "begin underline"); tstr[T_ue].name = "ue"; tstr[T_ue].long_name = CSAVS(4, 29, "end underline"); tstr[T_vb].name = "vb"; tstr[T_vb].long_name = CSAVS(4, 30, "visible bell"); tstr[T_DC].name = "DC"; tstr[T_DC].long_name = CSAVS(4, 31, "delete multiple chars"); tstr[T_DO].name = "DO"; tstr[T_DO].long_name = CSAVS(4, 32, "cursor down multiple"); tstr[T_IC].name = "IC"; tstr[T_IC].long_name = CSAVS(4, 33, "insert multiple chars"); tstr[T_LE].name = "LE"; tstr[T_LE].long_name = CSAVS(4, 34, "cursor left multiple"); tstr[T_RI].name = "RI"; tstr[T_RI].long_name = CSAVS(4, 35, "cursor right multiple"); tstr[T_UP].name = "UP"; tstr[T_UP].long_name = CSAVS(4, 36, "cursor up multiple"); tstr[T_kh].name = "kh"; tstr[T_kh].long_name = CSAVS(4, 43, "send cursor home"); tstr[T_at7].name = "@7"; tstr[T_at7].long_name = CSAVS(4, 44, "send cursor end"); tstr[T_mr].name = "mr"; tstr[T_mr].long_name = CSAVS(4, 45, "begin reverse video"); tstr[T_str].name = NULL; tstr[T_str].long_name = NULL; tval[T_am].name = "am"; tval[T_am].long_name = CSAVS(4, 37, "Has automatic margins"); tval[T_pt].name = "pt"; tval[T_pt].long_name = CSAVS(4, 38, "Can use physical tabs"); tval[T_li].name = "li"; tval[T_li].long_name = CSAVS(4, 39, "Number of lines"); tval[T_co].name = "co"; tval[T_co].long_name = CSAVS(4, 40, "Number of columns"); tval[T_km].name = "km"; tval[T_km].long_name = CSAVS(4, 41, "Has meta key"); tval[T_xn].name = "xn"; tval[T_xn].long_name = CSAVS(4, 42, "Newline ignored at right margin"); tval[T_val].name = NULL; tval[T_val].long_name = NULL; } /* * A very useful table from justin@crim.ca (Justin Bur) :-) * (Modified by per@erix.ericsson.se (Per Hedeland) * - first (and second:-) case fixed) * * Description Termcap variables tcsh behavior * am xn UseRightmost SendCRLF * -------------- ------- ------- ------------ ------------ * Automargins yes no yes no * Magic Margins yes yes yes no * No Wrap no -- yes yes */ static int me_all = 0; /* does two or more of the attributes use me */ static void ReBufferDisplay (void); static void TCset (struct termcapstr *, const char *); static void TCset(struct termcapstr *t, const char *cap) { if (cap == NULL || *cap == '\0') { xfree(t->str); t->str = NULL; } else { size_t size; size = strlen(cap) + 1; t->str = xrealloc(t->str, size); memcpy(t->str, cap, size); } } /*ARGSUSED*/ void TellTC(void) { struct termcapstr *t; char *first, *s; xprintf("%s", CGETS(7, 1, "\n\tTcsh thinks your terminal has the\n")); xprintf("%s", CGETS(7, 2, "\tfollowing characteristics:\n\n")); xprintf(CGETS(7, 3, "\tIt has %d columns and %d lines\n"), Val(T_co), Val(T_li)); s = strsave(T_HasMeta ? CGETS(7, 5, "a") : CGETS(7, 6, "no")); cleanup_push(s, xfree); first = s; xprintf(CGETS(7, 4, "\tIt has %s meta key\n"), s); s = strsave(T_Tabs ? "" : CGETS(7, 8, " not")); cleanup_push(s, xfree); xprintf(CGETS(7, 7, "\tIt can%s use tabs\n"), s); s = strsave((T_Margin&MARGIN_AUTO) ? CGETS(7, 10, "has") : CGETS(7, 11, "does not have")); cleanup_push(s, xfree); xprintf(CGETS(7, 9, "\tIt %s automatic margins\n"), s); if (T_Margin & MARGIN_AUTO) { s = strsave((T_Margin & MARGIN_MAGIC) ? CGETS(7, 10, "has") : CGETS(7, 11, "does not have")); cleanup_push(s, xfree); xprintf(CGETS(7, 12, "\tIt %s magic margins\n"), s); } for (t = tstr; t->name != NULL; t++) { s = strsave(t->str && *t->str ? t->str : CGETS(7, 13, "(empty)")); cleanup_push(s, xfree); xprintf("\t%36s (%s) == %s\n", t->long_name, t->name, s); cleanup_until(s); } xputchar('\n'); cleanup_until(first); } static void ReBufferDisplay(void) { int i; Char **b; b = Display; Display = NULL; blkfree(b); b = Vdisplay; Vdisplay = NULL; blkfree(b); TermH = Val(T_co); TermV = (INBUFSIZE * 4) / TermH + 1;/*FIXBUF*/ b = xmalloc(sizeof(*b) * (TermV + 1)); for (i = 0; i < TermV; i++) b[i] = xmalloc(sizeof(*b[i]) * (TermH + 1)); b[TermV] = NULL; Display = b; b = xmalloc(sizeof(*b) * (TermV + 1)); for (i = 0; i < TermV; i++) b[i] = xmalloc(sizeof(*b[i]) * (TermH + 1)); b[TermV] = NULL; Vdisplay = b; } void SetTC(char *what, char *how) { struct termcapstr *ts; struct termcapval *tv; /* * Do the strings first */ setname("settc"); for (ts = tstr; ts->name != NULL; ts++) if (strcmp(ts->name, what) == 0) break; if (ts->name != NULL) { TCset(ts, how); /* * Reset variables */ if (GoodStr(T_me) && GoodStr(T_ue)) me_all = (strcmp(Str(T_me), Str(T_ue)) == 0); else me_all = 0; if (GoodStr(T_me) && GoodStr(T_se)) me_all |= (strcmp(Str(T_me), Str(T_se)) == 0); T_CanCEOL = GoodStr(T_ce); T_CanDel = GoodStr(T_dc) || GoodStr(T_DC); T_CanIns = GoodStr(T_im) || GoodStr(T_ic) || GoodStr(T_IC); T_CanUP = GoodStr(T_up) || GoodStr(T_UP); return; } /* * Do the numeric ones second */ for (tv = tval; tv->name != NULL; tv++) if (strcmp(tv->name, what) == 0) break; if (tv->name != NULL) { if (tv == &tval[T_pt] || tv == &tval[T_km] || tv == &tval[T_am] || tv == &tval[T_xn]) { if (strcmp(how, "yes") == 0) tv->val = 1; else if (strcmp(how, "no") == 0) tv->val = 0; else { stderror(ERR_SETTCUS, tv->name); return; } T_Tabs = Val(T_pt); T_HasMeta = Val(T_km); T_Margin = Val(T_am) ? MARGIN_AUTO : 0; T_Margin |= Val(T_xn) ? MARGIN_MAGIC : 0; if (tv == &tval[T_am] || tv == &tval[T_xn]) ChangeSize(Val(T_li), Val(T_co)); return; } else { tv->val = atoi(how); T_Cols = (Char) Val(T_co); T_Lines = (Char) Val(T_li); if (tv == &tval[T_co] || tv == &tval[T_li]) ChangeSize(Val(T_li), Val(T_co)); return; } } stderror(ERR_NAME | ERR_TCCAP, what); return; } /* * Print the termcap string out with variable substitution */ void EchoTC(Char **v) { char *cap, *scap, *cv; int arg_need, arg_cols, arg_rows; int verbose = 0, silent = 0; char *area; static const char fmts[] = "%s\n", fmtd[] = "%d\n"; struct termcapstr *t; char buf[TC_BUFSIZE]; Char **globbed; area = buf; setname("echotc"); v = glob_all_or_error(v); globbed = v; cleanup_push(globbed, blk_cleanup); if (!*v || *v[0] == '\0') goto end; if (v[0][0] == '-') { switch (v[0][1]) { case 'v': verbose = 1; break; case 's': silent = 1; break; default: stderror(ERR_NAME | ERR_TCUSAGE); break; } v++; } if (!*v || *v[0] == '\0') goto end; cv = strsave(short2str(*v)); cleanup_push(cv, xfree); if (strcmp(cv, "tabs") == 0) { xprintf(fmts, T_Tabs ? CGETS(7, 14, "yes") : CGETS(7, 15, "no")); goto end_flush; } else if (strcmp(cv, "meta") == 0) { xprintf(fmts, Val(T_km) ? CGETS(7, 14, "yes") : CGETS(7, 15, "no")); goto end_flush; } else if (strcmp(cv, "xn") == 0) { xprintf(fmts, T_Margin & MARGIN_MAGIC ? CGETS(7, 14, "yes") : CGETS(7, 15, "no")); goto end_flush; } else if (strcmp(cv, "am") == 0) { xprintf(fmts, T_Margin & MARGIN_AUTO ? CGETS(7, 14, "yes") : CGETS(7, 15, "no")); goto end_flush; } else if (strcmp(cv, "baud") == 0) { int i; for (i = 0; baud_rate[i].b_name != NULL; i++) if (T_Speed == baud_rate[i].b_rate) { xprintf(fmts, baud_rate[i].b_name); goto end_flush; } xprintf(fmtd, 0); goto end_flush; } else if (strcmp(cv, "rows") == 0 || strcmp(cv, "lines") == 0 || strcmp(cv, "li") == 0) { xprintf(fmtd, Val(T_li)); goto end_flush; } else if (strcmp(cv, "cols") == 0 || strcmp(cv, "co") == 0) { xprintf(fmtd, Val(T_co)); goto end_flush; } /* * Try to use our local definition first */ scap = NULL; for (t = tstr; t->name != NULL; t++) if (strcmp(t->name, cv) == 0) { scap = t->str; break; } if (t->name == NULL) scap = tgetstr(cv, &area); if (!scap || scap[0] == '\0') { if (tgetflag(cv)) { xprintf("%s", CGETS(7, 14, "yes\n")); goto end; } if (silent) goto end; else stderror(ERR_NAME | ERR_TCCAP, cv); } /* * Count home many values we need for this capability. */ for (cap = scap, arg_need = 0; *cap; cap++) if (*cap == '%') switch (*++cap) { case 'd': case '2': case '3': case '.': case '+': arg_need++; break; case '%': case '>': case 'i': case 'r': case 'n': case 'B': case 'D': break; default: /* * hpux has lot's of them... */ if (verbose) stderror(ERR_NAME | ERR_TCPARM, *cap); /* This is bad, but I won't complain */ break; } switch (arg_need) { case 0: v++; if (*v && *v[0]) { if (silent) goto end; else stderror(ERR_NAME | ERR_TCARGS, cv, arg_need); } (void) tputs(scap, 1, PUTRAW); break; case 1: v++; if (!*v || *v[0] == '\0') stderror(ERR_NAME | ERR_TCNARGS, cv, 1); arg_cols = 0; arg_rows = atoi(short2str(*v)); v++; if (*v && *v[0]) { if (silent) goto end; else stderror(ERR_NAME | ERR_TCARGS, cv, arg_need); } (void) tputs(tgoto(scap, arg_cols, arg_rows), 1, PUTRAW); break; default: /* This is wrong, but I will ignore it... */ if (verbose) stderror(ERR_NAME | ERR_TCARGS, cv, arg_need); /*FALLTHROUGH*/ case 2: v++; if (!*v || *v[0] == '\0') { if (silent) goto end; else stderror(ERR_NAME | ERR_TCNARGS, cv, 2); } arg_cols = atoi(short2str(*v)); v++; if (!*v || *v[0] == '\0') { if (silent) goto end; else stderror(ERR_NAME | ERR_TCNARGS, cv, 2); } arg_rows = atoi(short2str(*v)); v++; if (*v && *v[0]) { if (silent) goto end; else stderror(ERR_NAME | ERR_TCARGS, cv, arg_need); } (void) tputs(tgoto(scap, arg_cols, arg_rows), arg_rows, PUTRAW); break; } end_flush: flush(); end: cleanup_until(globbed); } int GotTermCaps = 0; static struct { Char *name; int key; XmapVal fun; int type; } arrow[] = { #define A_K_DN 0 { STRdown, T_kd, { 0 }, 0 }, #define A_K_UP 1 { STRup, T_ku, { 0 }, 0 }, #define A_K_LT 2 { STRleft, T_kl, { 0 }, 0 }, #define A_K_RT 3 { STRright, T_kr, { 0 }, 0 }, #define A_K_HO 4 { STRhome, T_kh, { 0 }, 0 }, #define A_K_EN 5 { STRend, T_at7, { 0 }, 0} }; #define A_K_NKEYS 6 void ResetArrowKeys(void) { arrow[A_K_DN].fun.cmd = F_DOWN_HIST; arrow[A_K_DN].type = XK_CMD; arrow[A_K_UP].fun.cmd = F_UP_HIST; arrow[A_K_UP].type = XK_CMD; arrow[A_K_LT].fun.cmd = F_CHARBACK; arrow[A_K_LT].type = XK_CMD; arrow[A_K_RT].fun.cmd = F_CHARFWD; arrow[A_K_RT].type = XK_CMD; arrow[A_K_HO].fun.cmd = F_TOBEG; arrow[A_K_HO].type = XK_CMD; arrow[A_K_EN].fun.cmd = F_TOEND; arrow[A_K_EN].type = XK_CMD; } void DefaultArrowKeys(void) { static Char strA[] = {033, '[', 'A', '\0'}; static Char strB[] = {033, '[', 'B', '\0'}; static Char strC[] = {033, '[', 'C', '\0'}; static Char strD[] = {033, '[', 'D', '\0'}; static Char strH[] = {033, '[', 'H', '\0'}; static Char strF[] = {033, '[', 'F', '\0'}; static Char stOA[] = {033, 'O', 'A', '\0'}; static Char stOB[] = {033, 'O', 'B', '\0'}; static Char stOC[] = {033, 'O', 'C', '\0'}; static Char stOD[] = {033, 'O', 'D', '\0'}; static Char stOH[] = {033, 'O', 'H', '\0'}; static Char stOF[] = {033, 'O', 'F', '\0'}; CStr cs; #ifndef IS_ASCII if (strA[0] == 033) { strA[0] = CTL_ESC('\033'); strB[0] = CTL_ESC('\033'); strC[0] = CTL_ESC('\033'); strD[0] = CTL_ESC('\033'); strH[0] = CTL_ESC('\033'); strF[0] = CTL_ESC('\033'); stOA[0] = CTL_ESC('\033'); stOB[0] = CTL_ESC('\033'); stOC[0] = CTL_ESC('\033'); stOD[0] = CTL_ESC('\033'); stOH[0] = CTL_ESC('\033'); stOF[0] = CTL_ESC('\033'); } #endif cs.len = 3; cs.buf = strA; AddXkey(&cs, &arrow[A_K_UP].fun, arrow[A_K_UP].type); cs.buf = strB; AddXkey(&cs, &arrow[A_K_DN].fun, arrow[A_K_DN].type); cs.buf = strC; AddXkey(&cs, &arrow[A_K_RT].fun, arrow[A_K_RT].type); cs.buf = strD; AddXkey(&cs, &arrow[A_K_LT].fun, arrow[A_K_LT].type); cs.buf = strH; AddXkey(&cs, &arrow[A_K_HO].fun, arrow[A_K_HO].type); cs.buf = strF; AddXkey(&cs, &arrow[A_K_EN].fun, arrow[A_K_EN].type); cs.buf = stOA; AddXkey(&cs, &arrow[A_K_UP].fun, arrow[A_K_UP].type); cs.buf = stOB; AddXkey(&cs, &arrow[A_K_DN].fun, arrow[A_K_DN].type); cs.buf = stOC; AddXkey(&cs, &arrow[A_K_RT].fun, arrow[A_K_RT].type); cs.buf = stOD; AddXkey(&cs, &arrow[A_K_LT].fun, arrow[A_K_LT].type); cs.buf = stOH; AddXkey(&cs, &arrow[A_K_HO].fun, arrow[A_K_HO].type); cs.buf = stOF; AddXkey(&cs, &arrow[A_K_EN].fun, arrow[A_K_EN].type); if (VImode) { cs.len = 2; cs.buf = &strA[1]; AddXkey(&cs, &arrow[A_K_UP].fun, arrow[A_K_UP].type); cs.buf = &strB[1]; AddXkey(&cs, &arrow[A_K_DN].fun, arrow[A_K_DN].type); cs.buf = &strC[1]; AddXkey(&cs, &arrow[A_K_RT].fun, arrow[A_K_RT].type); cs.buf = &strD[1]; AddXkey(&cs, &arrow[A_K_LT].fun, arrow[A_K_LT].type); cs.buf = &strH[1]; AddXkey(&cs, &arrow[A_K_HO].fun, arrow[A_K_HO].type); cs.buf = &strF[1]; AddXkey(&cs, &arrow[A_K_EN].fun, arrow[A_K_EN].type); cs.buf = &stOA[1]; AddXkey(&cs, &arrow[A_K_UP].fun, arrow[A_K_UP].type); cs.buf = &stOB[1]; AddXkey(&cs, &arrow[A_K_DN].fun, arrow[A_K_DN].type); cs.buf = &stOC[1]; AddXkey(&cs, &arrow[A_K_RT].fun, arrow[A_K_RT].type); cs.buf = &stOD[1]; AddXkey(&cs, &arrow[A_K_LT].fun, arrow[A_K_LT].type); cs.buf = &stOH[1]; AddXkey(&cs, &arrow[A_K_HO].fun, arrow[A_K_HO].type); cs.buf = &stOF[1]; AddXkey(&cs, &arrow[A_K_EN].fun, arrow[A_K_EN].type); } } int SetArrowKeys(const CStr *name, XmapVal *fun, int type) { int i; for (i = 0; i < A_K_NKEYS; i++) if (Strcmp(name->buf, arrow[i].name) == 0) { arrow[i].fun = *fun; arrow[i].type = type; return 0; } return -1; } int IsArrowKey(Char *name) { int i; for (i = 0; i < A_K_NKEYS; i++) if (Strcmp(name, arrow[i].name) == 0) return 1; return 0; } int ClearArrowKeys(const CStr *name) { int i; for (i = 0; i < A_K_NKEYS; i++) if (Strcmp(name->buf, arrow[i].name) == 0) { arrow[i].type = XK_NOD; return 0; } return -1; } void PrintArrowKeys(const CStr *name) { int i; for (i = 0; i < A_K_NKEYS; i++) if (name->len == 0 || Strcmp(name->buf, arrow[i].name) == 0) if (arrow[i].type != XK_NOD) printOne(arrow[i].name, &arrow[i].fun, arrow[i].type); } void BindArrowKeys(void) { KEYCMD *map, *dmap; int i, j; char *p; CStr cs; if (!GotTermCaps) return; map = VImode ? CcAltMap : CcKeyMap; dmap = VImode ? CcViCmdMap : CcEmacsMap; DefaultArrowKeys(); for (i = 0; i < A_K_NKEYS; i++) { p = tstr[arrow[i].key].str; if (p && *p) { j = (unsigned char) *p; cs.buf = str2short(p); cs.len = Strlen(cs.buf); /* * Assign the arrow keys only if: * * 1. They are multi-character arrow keys and the user * has not re-assigned the leading character, or * has re-assigned the leading character to be F_XKEY * 2. They are single arrow keys pointing to an unassigned key. */ if (arrow[i].type == XK_NOD) { ClearXkey(map, &cs); } else { if (p[1] && (dmap[j] == map[j] || map[j] == F_XKEY)) { AddXkey(&cs, &arrow[i].fun, arrow[i].type); map[j] = F_XKEY; } else if (map[j] == F_UNASSIGNED) { ClearXkey(map, &cs); if (arrow[i].type == XK_CMD) map[j] = arrow[i].fun.cmd; else AddXkey(&cs, &arrow[i].fun, arrow[i].type); } } } } } static Char cur_atr = 0; /* current attributes */ void SetAttributes(Char atr) { atr &= ATTRIBUTES; if (atr != cur_atr) { if (me_all && GoodStr(T_me)) { if (((cur_atr & BOLD) && !(atr & BOLD)) || ((cur_atr & UNDER) && !(atr & UNDER)) || ((cur_atr & STANDOUT) && !(atr & STANDOUT))) { (void) tputs(Str(T_me), 1, PUTPURE); cur_atr = 0; } } if ((atr & BOLD) != (cur_atr & BOLD)) { if (atr & BOLD) { if (GoodStr(T_md) && GoodStr(T_me)) { (void) tputs(Str(T_md), 1, PUTPURE); cur_atr |= BOLD; } } else { if (GoodStr(T_md) && GoodStr(T_me)) { (void) tputs(Str(T_me), 1, PUTPURE); if ((cur_atr & STANDOUT) && GoodStr(T_se)) { (void) tputs(Str(T_se), 1, PUTPURE); cur_atr &= ~STANDOUT; } if ((cur_atr & UNDER) && GoodStr(T_ue)) { (void) tputs(Str(T_ue), 1, PUTPURE); cur_atr &= ~UNDER; } cur_atr &= ~BOLD; } } } if ((atr & STANDOUT) != (cur_atr & STANDOUT)) { if (atr & STANDOUT) { if (GoodStr(T_so) && GoodStr(T_se)) { (void) tputs(Str(T_so), 1, PUTPURE); cur_atr |= STANDOUT; } } else { if (GoodStr(T_se)) { (void) tputs(Str(T_se), 1, PUTPURE); cur_atr &= ~STANDOUT; } } } if ((atr & UNDER) != (cur_atr & UNDER)) { if (atr & UNDER) { if (GoodStr(T_us) && GoodStr(T_ue)) { (void) tputs(Str(T_us), 1, PUTPURE); cur_atr |= UNDER; } } else { if (GoodStr(T_ue)) { (void) tputs(Str(T_ue), 1, PUTPURE); cur_atr &= ~UNDER; } } } } } int highlighting = 0; void StartHighlight(void) { (void) tputs(Str(T_mr), 1, PUTPURE); highlighting = 1; } void StopHighlight(void) { (void) tputs(Str(T_me), 1, PUTPURE); highlighting = 0; } /* PWP 6-27-88 -- if the tty driver thinks that we can tab, we ask termcap */ int CanWeTab(void) { return (Val(T_pt)); } /* move to line (first line == 0) as efficiently as possible; */ void MoveToLine(int where) { int del; if (where == CursorV) return; if (where > TermV) { #ifdef DEBUG_SCREEN xprintf("MoveToLine: where is ridiculous: %d\r\n", where); flush(); #endif /* DEBUG_SCREEN */ return; } del = where - CursorV; if (del > 0) { while (del > 0) { if ((T_Margin & MARGIN_AUTO) && Display[CursorV][0] != '\0') { size_t h; for (h = TermH - 1; h > 0 && Display[CursorV][h] == CHAR_DBWIDTH; h--) ; /* move without newline */ MoveToChar(h); so_write(&Display[CursorV][CursorH], TermH - CursorH); /* updates CursorH/V*/ del--; } else { if ((del > 1) && GoodStr(T_DO)) { (void) tputs(tgoto(Str(T_DO), del, del), del, PUTPURE); del = 0; } else { for ( ; del > 0; del--) (void) putraw('\n'); CursorH = 0; /* because the \n will become \r\n */ } } } } else { /* del < 0 */ if (GoodStr(T_UP) && (-del > 1 || !GoodStr(T_up))) (void) tputs(tgoto(Str(T_UP), -del, -del), -del, PUTPURE); else { int i; if (GoodStr(T_up)) for (i = 0; i < -del; i++) (void) tputs(Str(T_up), 1, PUTPURE); } } CursorV = where; /* now where is here */ } void MoveToChar(int where) /* move to character position (where) */ { /* as efficiently as possible */ int del; mc_again: if (where == CursorH) return; if (where >= TermH) { #ifdef DEBUG_SCREEN xprintf("MoveToChar: where is riduculous: %d\r\n", where); flush(); #endif /* DEBUG_SCREEN */ return; } if (!where) { /* if where is first column */ (void) putraw('\r'); /* do a CR */ CursorH = 0; return; } del = where - CursorH; if ((del < -4 || del > 4) && GoodStr(T_ch)) /* go there directly */ (void) tputs(tgoto(Str(T_ch), where, where), where, PUTPURE); else { int i; if (del > 0) { /* moving forward */ if ((del > 4) && GoodStr(T_RI)) (void) tputs(tgoto(Str(T_RI), del, del), del, PUTPURE); else { /* if I can do tabs, use them */ if (T_Tabs) { if ((CursorH & 0370) != (where & ~0x7) && Display[CursorV][where & ~0x7] != CHAR_DBWIDTH) { /* if not within tab stop */ for (i = (CursorH & 0370); i < (where & ~0x7); i += 8) (void) putraw('\t'); /* then tab over */ CursorH = where & ~0x7; /* Note: considering that we often want to go to TermH - 1 for the wrapping, it would be nice to optimize this case by tabbing to the last column - but this doesn't work for all terminals! */ } } /* it's usually cheaper to just write the chars, so we do. */ /* NOTE THAT so_write() WILL CHANGE CursorH!!! */ so_write(&Display[CursorV][CursorH], where - CursorH); } } else { /* del < 0 := moving backward */ if ((-del > 4) && GoodStr(T_LE)) (void) tputs(tgoto(Str(T_LE), -del, -del), -del, PUTPURE); else { /* can't go directly there */ /* if the "cost" is greater than the "cost" from col 0 */ if (T_Tabs ? (-del > ((where >> 3) + (where & 07))) : (-del > where)) { (void) putraw('\r'); /* do a CR */ CursorH = 0; goto mc_again; /* and try again */ } for (i = 0; i < -del; i++) (void) putraw('\b'); } } } CursorH = where; /* now where is here */ } void so_write(Char *cp, int n) { int cur_pos, prompt_len = 0, region_start = 0, region_end = 0; if (n <= 0) return; /* catch bugs */ if (n > TermH) { #ifdef DEBUG_SCREEN xprintf("so_write: n is riduculous: %d\r\n", n); flush(); #endif /* DEBUG_SCREEN */ return; } if (adrof(STRhighlight)) { /* find length of prompt */ Char *promptc; for (promptc = Prompt; *promptc; promptc++); prompt_len = promptc - Prompt; /* find region start and end points */ if (IncMatchLen) { region_start = (Cursor - InputBuf) + prompt_len; region_end = region_start + IncMatchLen; } else if (MarkIsSet) { region_start = (min(Cursor, Mark) - InputBuf) + prompt_len; region_end = (max(Cursor, Mark) - InputBuf) + prompt_len; } } do { if (adrof(STRhighlight)) { cur_pos = CursorV * TermH + CursorH; if (!highlighting && cur_pos >= region_start && cur_pos < region_end) StartHighlight(); else if (highlighting && cur_pos >= region_end) StopHighlight(); /* don't highlight over the cursor. the highlighting's reverse * video would cancel it out. :P */ if (highlighting && cur_pos == (Cursor - InputBuf) + prompt_len) StopHighlight(); } if (*cp != CHAR_DBWIDTH) { if (*cp & LITERAL) { Char *d; #ifdef DEBUG_LITERAL xprintf("so: litnum %d\r\n", (int)(*cp & ~LITERAL)); #endif /* DEBUG_LITERAL */ for (d = litptr + (*cp & ~LITERAL) * LIT_FACTOR; *d; d++) (void) putwraw(*d); } else (void) putwraw(*cp); } cp++; CursorH++; } while (--n); if (adrof(STRhighlight) && highlighting) StopHighlight(); if (CursorH >= TermH) { /* wrap? */ if (T_Margin & MARGIN_AUTO) { /* yes */ CursorH = 0; CursorV++; if (T_Margin & MARGIN_MAGIC) { /* force the wrap to avoid the "magic" situation */ Char xc; if ((xc = Display[CursorV][CursorH]) != '\0') { so_write(&xc, 1); - while(Display[CursorV][CursorH] == CHAR_DBWIDTH) + while (Display[CursorV][CursorH] == CHAR_DBWIDTH) CursorH++; } else { (void) putraw(' '); CursorH = 1; } } } else /* no wrap, but cursor stays on screen */ CursorH = TermH - 1; } } void DeleteChars(int num) /* deletes characters */ { if (num <= 0) return; if (!T_CanDel) { #ifdef DEBUG_EDIT xprintf(CGETS(7, 16, "ERROR: cannot delete\r\n")); #endif /* DEBUG_EDIT */ flush(); return; } if (num > TermH) { #ifdef DEBUG_SCREEN xprintf(CGETS(7, 17, "DeleteChars: num is riduculous: %d\r\n"), num); flush(); #endif /* DEBUG_SCREEN */ return; } if (GoodStr(T_DC)) /* if I have multiple delete */ if ((num > 1) || !GoodStr(T_dc)) { /* if dc would be more expen. */ (void) tputs(tgoto(Str(T_DC), num, num), num, PUTPURE); return; } if (GoodStr(T_dm)) /* if I have delete mode */ (void) tputs(Str(T_dm), 1, PUTPURE); if (GoodStr(T_dc)) /* else do one at a time */ while (num--) (void) tputs(Str(T_dc), 1, PUTPURE); if (GoodStr(T_ed)) /* if I have delete mode */ (void) tputs(Str(T_ed), 1, PUTPURE); } /* Puts terminal in insert character mode, or inserts num characters in the line */ void Insert_write(Char *cp, int num) { if (num <= 0) return; if (!T_CanIns) { #ifdef DEBUG_EDIT xprintf(CGETS(7, 18, "ERROR: cannot insert\r\n")); #endif /* DEBUG_EDIT */ flush(); return; } if (num > TermH) { #ifdef DEBUG_SCREEN xprintf(CGETS(7, 19, "StartInsert: num is riduculous: %d\r\n"), num); flush(); #endif /* DEBUG_SCREEN */ return; } if (GoodStr(T_IC)) /* if I have multiple insert */ if ((num > 1) || !GoodStr(T_ic)) { /* if ic would be more expen. */ (void) tputs(tgoto(Str(T_IC), num, num), num, PUTPURE); so_write(cp, num); /* this updates CursorH/V */ return; } if (GoodStr(T_im) && GoodStr(T_ei)) { /* if I have insert mode */ (void) tputs(Str(T_im), 1, PUTPURE); so_write(cp, num); /* this updates CursorH/V */ if (GoodStr(T_ip)) /* have to make num chars insert */ (void) tputs(Str(T_ip), 1, PUTPURE); (void) tputs(Str(T_ei), 1, PUTPURE); return; } do { if (GoodStr(T_ic)) /* have to make num chars insert */ (void) tputs(Str(T_ic), 1, PUTPURE); /* insert a char */ so_write(cp++, 1); /* this updates CursorH/V */ if (GoodStr(T_ip)) /* have to make num chars insert */ (void) tputs(Str(T_ip), 1, PUTPURE);/* pad the inserted char */ } while (--num); } /* clear to end of line. There are num characters to clear */ void ClearEOL(int num) { int i; if (num <= 0) return; if (T_CanCEOL && GoodStr(T_ce)) (void) tputs(Str(T_ce), 1, PUTPURE); else { for (i = 0; i < num; i++) (void) putraw(' '); CursorH += num; /* have written num spaces */ } } void ClearScreen(void) { /* clear the whole screen and home */ if (GoodStr(T_cl)) /* send the clear screen code */ (void) tputs(Str(T_cl), Val(T_li), PUTPURE); else if (GoodStr(T_ho) && GoodStr(T_cd)) { (void) tputs(Str(T_ho), Val(T_li), PUTPURE); /* home */ /* clear to bottom of screen */ (void) tputs(Str(T_cd), Val(T_li), PUTPURE); } else { (void) putraw('\r'); (void) putraw('\n'); } } void SoundBeep(void) { /* produce a sound */ beep_cmd (); if (adrof(STRnobeep)) return; if (GoodStr(T_vb) && adrof(STRvisiblebell)) (void) tputs(Str(T_vb), 1, PUTPURE); /* visible bell */ else if (GoodStr(T_bl)) /* what termcap says we should use */ (void) tputs(Str(T_bl), 1, PUTPURE); else (void) putraw(CTL_ESC('\007')); /* an ASCII bell; ^G */ } void ClearToBottom(void) { /* clear to the bottom of the screen */ if (GoodStr(T_cd)) (void) tputs(Str(T_cd), Val(T_li), PUTPURE); else if (GoodStr(T_ce)) (void) tputs(Str(T_ce), Val(T_li), PUTPURE); } void GetTermCaps(void) { /* read in the needed terminal capabilites */ int i; const char *ptr; char buf[TC_BUFSIZE]; static char bp[TC_BUFSIZE]; char *area; struct termcapstr *t; #ifdef SIG_WINDOW sigset_t oset, set; int lins, cols; /* don't want to confuse things here */ sigemptyset(&set); sigaddset(&set, SIG_WINDOW); (void)sigprocmask(SIG_BLOCK, &set, &oset); cleanup_push(&oset, sigprocmask_cleanup); #endif /* SIG_WINDOW */ area = buf; GotTermCaps = 1; setname("gettermcaps"); ptr = getenv("TERM"); #ifdef apollo /* * If we are on a pad, we pretend that we are dumb. Otherwise the termcap * library will put us in a weird screen mode, thinking that we are going * to use curses */ if (isapad()) ptr = "dumb"; #endif /* apollo */ if (!ptr || !ptr[0] || !strcmp(ptr, "wm") || !strcmp(ptr,"dmx")) ptr = "dumb"; setzero(bp, TC_BUFSIZE); i = tgetent(bp, ptr); if (i <= 0) { if (i == -1) { #if (SYSVREL == 0) || defined(IRIS3D) xprintf(CGETS(7, 20, "%s: The terminal database could not be opened.\n"), progname); } else if (i == 0) { #endif /* SYSVREL */ xprintf(CGETS(7, 21, "%s: No entry for terminal type \"%s\"\n"), progname, getenv("TERM")); } xprintf(CGETS(7, 22, "%s: using dumb terminal settings.\n"), progname); Val(T_co) = 80; /* do a dumb terminal */ Val(T_pt) = Val(T_km) = Val(T_li) = 0; for (t = tstr; t->name != NULL; t++) TCset(t, NULL); } else { /* Can we tab */ Val(T_pt) = tgetflag("pt") && !tgetflag("xt"); /* do we have a meta? */ Val(T_km) = (tgetflag("km") || tgetflag("MT")); Val(T_am) = tgetflag("am"); Val(T_xn) = tgetflag("xn"); Val(T_co) = tgetnum("co"); Val(T_li) = tgetnum("li"); for (t = tstr; t->name != NULL; t++) TCset(t, tgetstr(t->name, &area)); } if (Val(T_co) < 2) Val(T_co) = 80; /* just in case */ if (Val(T_li) < 1) Val(T_li) = 24; T_Cols = (Char) Val(T_co); T_Lines = (Char) Val(T_li); if (T_Tabs) T_Tabs = Val(T_pt); T_HasMeta = Val(T_km); T_Margin = Val(T_am) ? MARGIN_AUTO : 0; T_Margin |= Val(T_xn) ? MARGIN_MAGIC : 0; T_CanCEOL = GoodStr(T_ce); T_CanDel = GoodStr(T_dc) || GoodStr(T_DC); T_CanIns = GoodStr(T_im) || GoodStr(T_ic) || GoodStr(T_IC); T_CanUP = GoodStr(T_up) || GoodStr(T_UP); if (GoodStr(T_me) && GoodStr(T_ue)) me_all = (strcmp(Str(T_me), Str(T_ue)) == 0); else me_all = 0; if (GoodStr(T_me) && GoodStr(T_se)) me_all |= (strcmp(Str(T_me), Str(T_se)) == 0); #ifdef DEBUG_SCREEN if (!T_CanUP) { xprintf(CGETS(7, 23, "%s: WARNING: Your terminal cannot move up.\n", progname)); xprintf(CGETS(7, 24, "Editing may be odd for long lines.\n")); } if (!T_CanCEOL) xprintf(CGETS(7, 25, "no clear EOL capability.\n")); if (!T_CanDel) xprintf(CGETS(7, 26, "no delete char capability.\n")); if (!T_CanIns) xprintf(CGETS(7, 27, "no insert char capability.\n")); #endif /* DEBUG_SCREEN */ #ifdef SIG_WINDOW (void) GetSize(&lins, &cols); /* get the correct window size */ ChangeSize(lins, cols); cleanup_until(&oset); /* can change it again */ #else /* SIG_WINDOW */ ChangeSize(Val(T_li), Val(T_co)); #endif /* SIG_WINDOW */ BindArrowKeys(); } #ifdef SIG_WINDOW /* GetSize(): * Return the new window size in lines and cols, and * true if the size was changed. This can fail if SHIN * is not a tty, but it will work in most cases. */ int GetSize(int *lins, int *cols) { *cols = Val(T_co); *lins = Val(T_li); #ifdef TIOCGWINSZ # define KNOWsize # ifndef lint { struct winsize ws; /* from 4.3 */ if (ioctl(SHIN, TIOCGWINSZ, (ioctl_t) &ws) != -1) { if (ws.ws_col) *cols = ws.ws_col; if (ws.ws_row) *lins = ws.ws_row; } } # endif /* !lint */ #else /* TIOCGWINSZ */ # ifdef TIOCGSIZE # define KNOWsize { struct ttysize ts; /* from Sun */ if (ioctl(SHIN, TIOCGSIZE, (ioctl_t) &ts) != -1) { if (ts.ts_cols) *cols = ts.ts_cols; if (ts.ts_lines) *lins = ts.ts_lines; } } # endif /* TIOCGSIZE */ #endif /* TIOCGWINSZ */ return (Val(T_co) != *cols || Val(T_li) != *lins); } #endif /* SIG_WINDOW */ #ifdef KNOWsize static int UpdateVal(const Char *tag, int value, Char *termcap, Char *backup) { Char *ptr, *p; if ((ptr = Strstr(termcap, tag)) == NULL) { (void)Strcpy(backup, termcap); return 0; } else { size_t len = (ptr - termcap) + Strlen(tag); (void)Strncpy(backup, termcap, len); backup[len] = '\0'; p = Itoa(value, 0, 0); (void) Strcat(backup + len, p); xfree(p); ptr = Strchr(ptr, ':'); if (ptr) (void) Strcat(backup, ptr); return 1; } } #endif void ChangeSize(int lins, int cols) { /* * Just in case */ Val(T_co) = (cols < 2) ? 80 : cols; Val(T_li) = (lins < 1) ? 24 : lins; #ifdef KNOWsize /* * We want to affect the environment only when we have a valid * setup, not when we get bad settings. Consider the following scenario: * We just logged in, and we have not initialized the editor yet. * We reset termcap with tset, and not $TERMCAP has the right * terminal size. But since the editor is not initialized yet, and * the kernel's notion of the terminal size might be wrong we arrive * here with lines = columns = 0. If we reset the environment we lose * our only chance to get the window size right. */ if (Val(T_co) == cols && Val(T_li) == lins) { Char *p; char *tptr; if (getenv("COLUMNS")) { p = Itoa(Val(T_co), 0, 0); cleanup_push(p, xfree); tsetenv(STRCOLUMNS, p); cleanup_until(p); } if (getenv("LINES")) { p = Itoa(Val(T_li), 0, 0); cleanup_push(p, xfree); tsetenv(STRLINES, p); cleanup_until(p); } if ((tptr = getenv("TERMCAP")) != NULL) { /* Leave 64 characters slop in case we enlarge the termcap string */ Char termcap[TC_BUFSIZE+64], backup[TC_BUFSIZE+64], *ptr; int changed; ptr = str2short(tptr); (void) Strncpy(termcap, ptr, TC_BUFSIZE); termcap[TC_BUFSIZE-1] = '\0'; changed = UpdateVal(STRco, Val(T_co), termcap, backup); changed |= UpdateVal(STRli, Val(T_li), termcap, backup); if (changed) { /* * Chop the termcap string at TC_BUFSIZE-1 characters to avoid * core-dumps in the termcap routines */ termcap[TC_BUFSIZE - 1] = '\0'; tsetenv(STRTERMCAP, termcap); } } } #endif /* KNOWsize */ ReBufferDisplay(); /* re-make display buffers */ ClearDisp(); } diff --git a/contrib/tcsh/ed.xmap.c b/contrib/tcsh/ed.xmap.c index d76ba46dc9f9..6473519726dd 100644 --- a/contrib/tcsh/ed.xmap.c +++ b/contrib/tcsh/ed.xmap.c @@ -1,758 +1,758 @@ /* * ed.xmap.c: This module contains the procedures for maintaining * the extended-key map. * * An extended-key (Xkey) is a sequence of keystrokes * introduced with an sequence introducer and consisting * of an arbitrary number of characters. This module maintains * a map (the Xmap) to convert these extended-key sequences * into input strings (XK_STR), editor functions (XK_CMD), or * unix commands (XK_EXE). It contains the * following externally visible functions. * * int GetXkey(ch,val); * CStr *ch; * XmapVal *val; * * Looks up *ch in map and then reads characters until a * complete match is found or a mismatch occurs. Returns the * type of the match found (XK_STR, XK_CMD, or XK_EXE). * Returns NULL in val.str and XK_STR for no match. * The last character read is returned in *ch. * * void AddXkey(Xkey, val, ntype); * CStr *Xkey; * XmapVal *val; * int ntype; * * Adds Xkey to the Xmap and associates the value in val with it. * If Xkey is already is in Xmap, the new code is applied to the * existing Xkey. Ntype specifies if code is a command, an * out string or a unix command. * * int DeleteXkey(Xkey); * CStr *Xkey; * * Delete the Xkey and all longer Xkeys staring with Xkey, if * they exists. * * Warning: * If Xkey is a substring of some other Xkeys, then the longer * Xkeys are lost!! That is, if the Xkeys "abcd" and "abcef" * are in Xmap, adding the key "abc" will cause the first two * definitions to be lost. * * void ResetXmap(); * * Removes all entries from Xmap and resets the defaults. * * void PrintXkey(Xkey); * CStr *Xkey; * * Prints all extended keys prefixed by Xkey and their associated * commands. * * Restrictions: * ------------- * 1) It is not possible to have one Xkey that is a * substring of another. */ /*- * Copyright (c) 1980, 1991 The Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include "sh.h" #include "ed.h" #include "ed.defns.h" #ifndef NULL #define NULL 0 #endif /* Internal Data types and declarations */ /* The Nodes of the Xmap. The Xmap is a linked list of these node * elements */ typedef struct Xmapnode { Char ch; /* single character of Xkey */ int type; XmapVal val; /* command code or pointer to string, if this * is a leaf */ struct Xmapnode *next; /* ptr to next char of this Xkey */ struct Xmapnode *sibling; /* ptr to another Xkey with same prefix */ } XmapNode; static XmapNode *Xmap = NULL; /* the current Xmap */ /* Some declarations of procedures */ static int TraverseMap (XmapNode *, CStr *, XmapVal *); static int TryNode (XmapNode *, CStr *, XmapVal *, int); static XmapNode *GetFreeNode (CStr *); static void PutFreeNode (XmapNode *); static int TryDeleteNode (XmapNode **, CStr *); static int Lookup (struct Strbuf *, const CStr *, const XmapNode *); static void Enumerate (struct Strbuf *, const XmapNode *); static void unparsech (struct Strbuf *, Char); XmapVal * XmapCmd(int cmd) { static XmapVal xm; xm.cmd = (KEYCMD) cmd; return &xm; } XmapVal * XmapStr(CStr *str) { static XmapVal xm; xm.str.len = str->len; xm.str.buf = str->buf; return &xm; } /* ResetXmap(): * Takes all nodes on Xmap and puts them on free list. Then * initializes Xmap with arrow keys */ void ResetXmap(void) { PutFreeNode(Xmap); Xmap = NULL; DefaultArrowKeys(); return; } /* GetXkey(): * Calls the recursive function with entry point Xmap */ int GetXkey(CStr *ch, XmapVal *val) { return (TraverseMap(Xmap, ch, val)); } /* TraverseMap(): * recursively traverses node in tree until match or mismatch is * found. May read in more characters. */ static int TraverseMap(XmapNode *ptr, CStr *ch, XmapVal *val) { Char tch; if (ptr->ch == *(ch->buf)) { /* match found */ if (ptr->next) { /* Xkey not complete so get next char */ if (GetNextChar(&tch) != 1) { /* if EOF or error */ val->cmd = F_SEND_EOF; return XK_CMD;/* PWP: Pretend we just read an end-of-file */ } *(ch->buf) = tch; return (TraverseMap(ptr->next, ch, val)); } else { *val = ptr->val; if (ptr->type != XK_CMD) *(ch->buf) = '\0'; return ptr->type; } } else { /* no match found here */ if (ptr->sibling) { /* try next sibling */ return (TraverseMap(ptr->sibling, ch, val)); } else { /* no next sibling -- mismatch */ val->str.buf = NULL; val->str.len = 0; return XK_STR; } } } void AddXkey(const CStr *Xkey, XmapVal *val, int ntype) { CStr cs; cs.buf = Xkey->buf; cs.len = Xkey->len; if (Xkey->len == 0) { xprintf("%s", CGETS(9, 1, "AddXkey: Null extended-key not allowed.\n")); return; } if (ntype == XK_CMD && val->cmd == F_XKEY) { xprintf("%s", CGETS(9, 2, "AddXkey: sequence-lead-in command not allowed\n")); return; } if (Xmap == NULL) /* tree is initially empty. Set up new node to match Xkey[0] */ Xmap = GetFreeNode(&cs); /* it is properly initialized */ /* Now recurse through Xmap */ (void) TryNode(Xmap, &cs, val, ntype); return; } static int TryNode(XmapNode *ptr, CStr *str, XmapVal *val, int ntype) { /* * Find a node that matches *string or allocate a new one */ if (ptr->ch != *(str->buf)) { XmapNode *xm; for (xm = ptr; xm->sibling != NULL; xm = xm->sibling) if (xm->sibling->ch == *(str->buf)) break; if (xm->sibling == NULL) xm->sibling = GetFreeNode(str); /* setup new node */ ptr = xm->sibling; } str->buf++; str->len--; if (str->len == 0) { size_t len; /* we're there */ if (ptr->next != NULL) { PutFreeNode(ptr->next); /* lose longer Xkeys with this prefix */ ptr->next = NULL; } switch (ptr->type) { case XK_STR: case XK_EXE: xfree(ptr->val.str.buf); ptr->val.str.len = 0; break; case XK_NOD: case XK_CMD: break; default: abort(); break; } switch (ptr->type = ntype) { case XK_CMD: ptr->val = *val; break; case XK_STR: case XK_EXE: ptr->val.str.len = val->str.len; len = (val->str.len + 1) * sizeof(*ptr->val.str.buf); ptr->val.str.buf = xmalloc(len); (void) memcpy(ptr->val.str.buf, val->str.buf, len); break; default: abort(); break; } } else { /* still more chars to go */ if (ptr->next == NULL) ptr->next = GetFreeNode(str); /* setup new node */ (void) TryNode(ptr->next, str, val, ntype); } return (0); } void ClearXkey(KEYCMD *map, const CStr *in) { unsigned char c = (unsigned char) *(in->buf); if ((map[c] == F_XKEY) && ((map == CcKeyMap && CcAltMap[c] != F_XKEY) || (map == CcAltMap && CcKeyMap[c] != F_XKEY))) (void) DeleteXkey(in); } int DeleteXkey(const CStr *Xkey) { CStr s; s = *Xkey; if (s.len == 0) { xprintf("%s", CGETS(9, 3, "DeleteXkey: Null extended-key not allowed.\n")); return (-1); } if (Xmap == NULL) return (0); (void) TryDeleteNode(&Xmap, &s); return (0); } /* Destroys str */ static int TryDeleteNode(XmapNode **inptr, CStr *str) { XmapNode *ptr; ptr = *inptr; /* * Find a node that matches *string or allocate a new one */ if (ptr->ch != *(str->buf)) { XmapNode *xm; for (xm = ptr; xm->sibling != NULL; xm = xm->sibling) if (xm->sibling->ch == *(str->buf)) break; if (xm->sibling == NULL) return (0); inptr = &xm->sibling; ptr = xm->sibling; } str->buf++; str->len--; if (str->len == 0) { /* we're there */ *inptr = ptr->sibling; ptr->sibling = NULL; PutFreeNode(ptr); return (1); } else if (ptr->next != NULL && TryDeleteNode(&ptr->next, str) == 1) { if (ptr->next != NULL) return (0); *inptr = ptr->sibling; ptr->sibling = NULL; PutFreeNode(ptr); return (1); } else { return (0); } } /* PutFreeNode(): * Puts a tree of nodes onto free list using free(3). */ static void PutFreeNode(XmapNode *ptr) { if (ptr == NULL) return; if (ptr->next != NULL) { PutFreeNode(ptr->next); ptr->next = NULL; } PutFreeNode(ptr->sibling); switch (ptr->type) { case XK_CMD: case XK_NOD: break; case XK_EXE: case XK_STR: xfree(ptr->val.str.buf); break; default: abort(); break; } xfree(ptr); } /* GetFreeNode(): * Returns pointer to an XmapNode for ch. */ static XmapNode * GetFreeNode(CStr *ch) { XmapNode *ptr; ptr = xmalloc(sizeof(XmapNode)); ptr->ch = ch->buf[0]; ptr->type = XK_NOD; ptr->val.str.buf = NULL; ptr->val.str.len = 0; ptr->next = NULL; ptr->sibling = NULL; return (ptr); } /* PrintXKey(): * Print the binding associated with Xkey key. * Print entire Xmap if null */ void PrintXkey(const CStr *key) { struct Strbuf buf = Strbuf_INIT; CStr cs; if (key) { cs.buf = key->buf; cs.len = key->len; } else { cs.buf = STRNULL; cs.len = 0; } /* do nothing if Xmap is empty and null key specified */ if (Xmap == NULL && cs.len == 0) return; Strbuf_append1(&buf, '"'); cleanup_push(&buf, Strbuf_cleanup); if (Lookup(&buf, &cs, Xmap) <= -1) /* key is not bound */ xprintf(CGETS(9, 4, "Unbound extended key \"%S\"\n"), cs.buf); cleanup_until(&buf); } /* Lookup(): * look for the string starting at node ptr. * Print if last node */ static int Lookup(struct Strbuf *buf, const CStr *str, const XmapNode *ptr) { if (ptr == NULL) return (-1); /* cannot have null ptr */ if (str->len == 0) { /* no more chars in string. Enumerate from here. */ Enumerate(buf, ptr); return (0); } else { /* If match put this char into buf. Recurse */ if (ptr->ch == *(str->buf)) { /* match found */ unparsech(buf, ptr->ch); if (ptr->next != NULL) { /* not yet at leaf */ CStr tstr; tstr.buf = str->buf + 1; tstr.len = str->len - 1; return (Lookup(buf, &tstr, ptr->next)); } else { /* next node is null so key should be complete */ if (str->len == 1) { Strbuf_append1(buf, '"'); Strbuf_terminate(buf); printOne(buf->s, &ptr->val, ptr->type); return (0); } else return (-1);/* mismatch -- string still has chars */ } } else { /* no match found try sibling */ if (ptr->sibling) return (Lookup(buf, str, ptr->sibling)); else return (-1); } } } static void Enumerate(struct Strbuf *buf, const XmapNode *ptr) { size_t old_len; if (ptr == NULL) { #ifdef DEBUG_EDIT xprintf(CGETS(9, 6, "Enumerate: BUG!! Null ptr passed\n!")); #endif return; } old_len = buf->len; unparsech(buf, ptr->ch); /* put this char at end of string */ if (ptr->next == NULL) { /* print this Xkey and function */ Strbuf_append1(buf, '"'); Strbuf_terminate(buf); printOne(buf->s, &ptr->val, ptr->type); } else Enumerate(buf, ptr->next); /* go to sibling if there is one */ if (ptr->sibling) { buf->len = old_len; Enumerate(buf, ptr->sibling); } } /* PrintOne(): * Print the specified key and its associated * function specified by val */ void printOne(const Char *key, const XmapVal *val, int ntype) { struct KeyFuncs *fp; static const char *fmt = "%s\n"; xprintf("%-15S-> ", key); if (val != NULL) switch (ntype) { case XK_STR: case XK_EXE: { unsigned char *p; p = unparsestring(&val->str, ntype == XK_STR ? STRQQ : STRBB); cleanup_push(p, xfree); xprintf(fmt, p); cleanup_until(p); break; } case XK_CMD: for (fp = FuncNames; fp->name; fp++) if (val->cmd == fp->func) xprintf(fmt, fp->name); break; default: abort(); break; } else xprintf(fmt, CGETS(9, 7, "no input")); } static void unparsech(struct Strbuf *buf, Char ch) { if (ch == 0) { Strbuf_append1(buf, '^'); Strbuf_append1(buf, '@'); } else if (Iscntrl(ch)) { Strbuf_append1(buf, '^'); if (ch == CTL_ESC('\177')) Strbuf_append1(buf, '?'); else #ifdef IS_ASCII Strbuf_append1(buf, ch | 0100); #else Strbuf_append1(buf, _toebcdic[_toascii[ch]|0100]); #endif } else if (ch == '^') { Strbuf_append1(buf, '\\'); Strbuf_append1(buf, '^'); } else if (ch == '\\') { Strbuf_append1(buf, '\\'); Strbuf_append1(buf, '\\'); } else if (ch == ' ' || (Isprint(ch) && !Isspace(ch))) { Strbuf_append1(buf, ch); } else { Strbuf_append1(buf, '\\'); Strbuf_append1(buf, ((ch >> 6) & 7) + '0'); Strbuf_append1(buf, ((ch >> 3) & 7) + '0'); Strbuf_append1(buf, (ch & 7) + '0'); } } eChar parseescape(const Char **ptr) { const Char *p; Char c; p = *ptr; if ((p[1] & CHAR) == 0) { xprintf(CGETS(9, 8, "Something must follow: %c\n"), (char)*p); return CHAR_ERR; } if ((*p & CHAR) == '\\') { p++; switch (*p & CHAR) { case 'a': c = CTL_ESC('\007'); /* Bell */ break; case 'b': c = CTL_ESC('\010'); /* Backspace */ break; case 'e': c = CTL_ESC('\033'); /* Escape */ break; case 'f': c = CTL_ESC('\014'); /* Form Feed */ break; case 'n': c = CTL_ESC('\012'); /* New Line */ break; case 'r': c = CTL_ESC('\015'); /* Carriage Return */ break; case 't': c = CTL_ESC('\011'); /* Horizontal Tab */ break; case 'v': c = CTL_ESC('\013'); /* Vertical Tab */ break; case '\\': c = '\\'; break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': { int cnt, val; Char ch; for (cnt = 0, val = 0; cnt < 3; cnt++) { ch = *p++ & CHAR; if (ch < '0' || ch > '7') { p--; break; } val = (val << 3) | (ch - '0'); } if ((val & ~0xff) != 0) { xprintf("%s", CGETS(9, 9, "Octal constant does not fit in a char.\n")); return 0; } #ifndef IS_ASCII if (CTL_ESC(val) != val && adrof(STRwarnebcdic)) xprintf(/*CGETS(9, 9, no NLS-String yet!*/ "Warning: Octal constant \\%3.3o is interpreted as EBCDIC value.\n", val/*)*/); #endif c = (Char) val; --p; } break; default: c = *p; break; } } else if ((*p & CHAR) == '^' && (Isalpha(p[1] & CHAR) || strchr("@^_?\\|[{]}", p[1] & CHAR))) { p++; #ifdef IS_ASCII c = ((*p & CHAR) == '?') ? CTL_ESC('\177') : ((*p & CHAR) & 0237); #else c = ((*p & CHAR) == '?') ? CTL_ESC('\177') : _toebcdic[_toascii[*p & CHAR] & 0237]; if (adrof(STRwarnebcdic)) xprintf(/*CGETS(9, 9, no NLS-String yet!*/ "Warning: Control character ^%c may be interpreted differently in EBCDIC.\n", *p & CHAR /*)*/); #endif } else - c = *p; + c = *p & CHAR; *ptr = p; return (c); } unsigned char * unparsestring(const CStr *str, const Char *sep) { unsigned char *buf, *b; Char p; int l; /* Worst-case is "\uuu" or result of wctomb() for each char from str */ buf = xmalloc((str->len + 1) * max(4, MB_LEN_MAX)); b = buf; if (sep[0]) #ifndef WINNT_NATIVE *b++ = sep[0]; #else /* WINNT_NATIVE */ *b++ = CHAR & sep[0]; #endif /* !WINNT_NATIVE */ for (l = 0; l < str->len; l++) { p = str->buf[l]; if (Iscntrl(p)) { *b++ = '^'; if (p == CTL_ESC('\177')) *b++ = '?'; else #ifdef IS_ASCII *b++ = (unsigned char) (p | 0100); #else *b++ = _toebcdic[_toascii[p]|0100]; #endif } else if (p == '^' || p == '\\') { *b++ = '\\'; *b++ = (unsigned char) p; } else if (p == ' ' || (Isprint(p) && !Isspace(p))) b += one_wctomb((char *)b, p); else { *b++ = '\\'; *b++ = ((p >> 6) & 7) + '0'; *b++ = ((p >> 3) & 7) + '0'; *b++ = (p & 7) + '0'; } } if (sep[0] && sep[1]) #ifndef WINNT_NATIVE *b++ = sep[1]; #else /* WINNT_NATIVE */ *b++ = CHAR & sep[1]; #endif /* !WINNT_NATIVE */ *b++ = 0; return buf; /* should check for overflow */ } diff --git a/contrib/tcsh/host.defs b/contrib/tcsh/host.defs index 40572cc24271..6e03537fa612 100644 --- a/contrib/tcsh/host.defs +++ b/contrib/tcsh/host.defs @@ -1,1281 +1,1281 @@ newcode : /* * host.defs: Hosttype/Machtype etc. */ /*- * Copyright (c) 1980, 1991 The Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include "sh.h" endcode : macro : M_mips64el : (defined(mips64) && defined(MIPSEL)) macro : M_mips64eb : (defined(mips64) && defined(MIPSEB)) macro : M_mipsel : (!defined(M_mips64el) && defined(mips) && defined(MIPSEL)) macro : M_mipseb : (!defined(M_mips64eb) && defined(mips) && defined(MIPSEB)) macro : M_amd64: (defined(amd64) || defined(x86_64)) macro : M_i386 : defined(i386) macro : M_i486 : defined(i486) macro : M_i586 : defined(i586) macro : M_i686 : defined(i686) macro : M_intel : (defined(M_i386) || defined(M_i486) || defined(M_i586)) newdef : defined(ns32000) newcode : static char * isamultimax(int flag) { if (access("/Umax.image", F_OK) == 0) return "multimax"; else return flag ? "mach" : "ns32000"; } endcode : enddef : newdef : defined(cray) newcode : /* * On crays, find the current machine type via the target() syscall * We need ctype.h to convert the name returned to lower case */ # include # include # include /* From: hpa@hook.eecs.nwu.edu (H. Peter Anvin) */ static char * getcray(void) { # ifdef MC_GET_SYSTEM /* If we have target() */ struct target data; if (target(MC_GET_SYSTEM, &data) != -1) { static char hosttype_buf[sizeof(data.mc_pmt)+1]; unsigned char *p = (unsigned char *) &(data.mc_pmt); char *q = hosttype_buf; int n; /* * Copy to buffer and convert to lower case * String may not be null-terminated, so keep a counter */ for (n = 0; *p && n < sizeof(data.mc_pmt); n++) *q++ = tolower(p[n]); *q = '\0'; /* replace dashes with underscores if present */ while ((q = strchr(hosttype_buf, '-')) != NULL) *q = '_'; return hosttype_buf; /* Return in static buffer */ } else # endif /* MC_GET_SYSTEM */ return "cray"; /* target() failed */ } endcode : enddef : newdef : defined(convex) newcode : /* * On convex, find the current machine type via the getsysinfo() syscall */ #include /* From: fox@convex.com (David DeSimone) */ static char * getconvex(void) { struct system_information sysinfo; static char result[8]; if (getsysinfo(SYSINFO_SIZE, &sysinfo) == -1) return "convex"; switch(sysinfo.cpu_type) { #ifdef SI_CPUTYPE_C1 case SI_CPUTYPE_C1: return "c1"; #endif #ifdef SI_CPUTYPE_C2 case SI_CPUTYPE_C2: return "c2"; #endif #ifdef SI_CPUTYPE_C2MP case SI_CPUTYPE_C2MP: (void) strcpy(result, "c2X0"); result[2] = sysinfo.cpu_count + '0'; return result; #endif #ifdef SI_CPUTYPE_C34 case SI_CPUTYPE_C34: (void) strcpy(result, "c34X0"); result[3] = sysinfo.cpu_count + '0'; return result; #endif #ifdef SI_CPUTYPE_C38 case SI_CPUTYPE_C38: (void) strcpy(result, "c38X0"); result[3] = sysinfo.cpu_count + '0'; return result; #endif #ifdef SI_CPUTYPE_C46 case SI_CPUTYPE_C46: (void) strcpy(result, "c46X0"); result[3] = sysinfo.cpu_count + '0'; return result; #endif default: return "convex"; } } endcode : enddef : newdef : defined(linux) || defined(CYGWIN) || defined(GNU) || defined(GLIBC) newcode : # include "tw.h" #include static char mach[256]; static char host[256]; static char ostype[32]; static void populate(void) { struct utsname uts; int e = uname(&uts); const char *p = short2str(tgetenv(STROSTYPE)); if (p == NULL) { #if defined(__ANDROID__) p = "android"; #elif defined(__CYGWIN__) p = "cygwin"; #else p = "linux"; #endif } xsnprintf(ostype, sizeof(ostype), "%s", p); xsnprintf(mach, sizeof(mach), "%s", e != -1 ? uts.machine : "unknown"); xsnprintf(host, sizeof(host), "%s-%s", e != -1 ? uts.machine : "unknown", ostype); } static char * getmach(void) { if (!mach[0]) populate(); return mach; } static char * gethost(void) { if (!host[0]) populate(); return host; } static char * getostype(void) { if (!ostype[0]) populate(); return ostype; } endcode : enddef : newcode : void getmachine(void) { const char *hosttype; const char *ostype; const char *vendor; const char *machtype; endcode : newdef : defined(HOSTTYPE) hosttype: : HOSTTYPE enddef : newdef : defined(PARAGON) comment : Intel Paragon running OSF/1 vendor : : "intel" hosttype: : "paragon" ostype : : "osf1" machtype: defined(M_i386) : "i386" enddef : newdef : defined(AMIX) comment : Amiga running Amix 2.02 vendor : : "commodore" hosttype: : "amiga" ostype : : "Amix" machtype: : "m68k" enddef : newdef : defined(accel) comment : celerity Accel vendor : : "celerity" hosttype: : "celerityACCEL" ostype : : "unix" machtype: : "accel" enddef : newdef : defined(_VMS_POSIX) comment : digital vax or alpha running vms posix vendor : : "dec" hosttype: : "VMS-POSIX" ostype : : "vms" machtype: defined(alpha) : "alpha" machtype: defined(vax) : "vax" enddef : newdef : defined(hp_osf) comment : Hewlett Packard running OSF/1 vendor : : "hp" hosttype: defined(pa_risc) : "hp9000s700-osf1" hosttype: : "hp-osf1" ostype : : "osf1" machtype: defined(pa_risc) : "pa_risc" enddef : newdef : defined(hp9000) comment : Hewlett Packard running MORE/bsd vendor : : "hp" hosttype: defined(hp300) : "hp300" hosttype: defined(hp800) : "hp800" hosttype: : "hp9000" ostype : defined(BSD4_4) : "bsd44" ostype : : "mtXinu" machtype: defined(hp300) : "m68k" machtype: defined(hp800) : "pa_risc" enddef : newdef : defined(hpux) comment : Hewlett Packard running HP/UX vendor : : "hp" hosttype: defined(hp9000s800) : "hp9000s800" hosttype: defined(hp9000s700) : "hp9000s700" hosttype: defined(hp9000s500) : "hp9000s500" hosttype: defined(hp9000s300) : "hp9000s300" hosttype: : "hp" ostype : : "hpux" machtype: defined(hp9000s800) : "pa_risc" machtype: defined(hp9000s700) : "pa_risc" machtype: defined(hp9000s500) : "m68k" machtype: defined(hp9000s300) : "m68k" enddef : newdef : defined(apollo) comment : Hewlett Packard apollo running Domain/OS vendor : : "hp" hosttype: : "apollo" ostype : : "DomainOS" machtype: : "m68k" enddef : newdef : defined(sun) comment : Sun Microsystems series 2 workstation (68010 based) comment : Sun Microsystems series 3 workstation (68020 based) comment : Sun Microsystems 386i workstation (386 based) comment : Sun Microsystems series 4 workstation (SPARC based) vendor : : "sun" hosttype: defined(M_i386) && !defined(SVR4) : "sun386i" hosttype: defined(M_i386) && defined(SVR4) : "i86pc" hosttype: defined(M_amd64) : "i86pc" hosttype: defined(mc68010) : "sun2" hosttype: defined(mc68020) : "sun3" hosttype: defined(sparc) : "sun4" hosttype: : "sun" ostype : defined(SUNOS3) : "sunos3" ostype : defined(SUNOS4) : "sunos4" ostype : defined(SOLARIS2) : "solaris" machtype: defined(mc68010) : "m68k" machtype: defined(mc68020) : "m68k" machtype: defined(sparcv9) : "sparcv9" machtype: defined(sparc) : "sparc" machtype: defined(M_i386) : "i386" machtype: defined(M_amd64) : "amd64" enddef : newdef : defined(pyr) comment : Pyramid Technology vendor : : "pyramid" hosttype: : "pyramid" machtype: : "pyramid" enddef : newdef : defined(hcx) || defined(_CX_UX) comment : Harris Tahoe running CX/UX vendor : : "harris" hosttype: : "hcx" ostype : : "hcx" machtype: : "tahoe" enddef : newdef : defined(tahoe) comment : Harris Tahoe vendor : : "harris" hosttype: : "tahoe" machtype: : "tahoe" enddef : newdef : defined(ibm032) comment : RT running IBM AOS4.3 or MACH vendor : : "ibm" hosttype: : "rt" ostype : defined(MACH) : "mach" ostype : : "aos" machtype: : "ibm032" enddef : newdef : defined(aiws) comment : RT running IBM aix2.x vendor : : "ibm" hosttype: : "rtpc" ostype : : "aix" machtype: : "ibm032" enddef : newdef : defined(_AIX370) comment : IBM/370 running aix vendor : : "ibm" hosttype: : "aix370" ostype : : "aix" machtype: : "ibm370" enddef : newdef : defined(_IBMESA) comment : IBM/ESA running aix vendor : : "ibm" hosttype: : "aixESA" ostype : : "aix" machtype: : "esa" enddef : newdef : defined(_IBMR2) comment : IBM/RS6000 running aix vendor : : "ibm" hosttype: : "rs6000" ostype : : "aix" machtype: : "rs6000" enddef : newdef : defined(_AIXPS2) comment : IBM/PS2 running aix vendor : : "ibm" hosttype: : "ps2" ostype : : "aix" machtype: : "i386" enddef : newdef : defined(OREO) comment : Macintosh running AU/X vendor : : "apple" hosttype: : "mac2" ostype : : "aux" machtype: defined(mc68020) : "m68k" enddef : newdef : defined(u3b20d) comment : AT&T 3B/20 series running SVR2/3 vendor : : "att" hosttype: : "att3b20" machtype: : "u3b20" enddef : newdef : defined(u3b15) comment : AT&T 3B/15 series running SVR2/3 vendor : : "att" hosttype: : "att3b15" machtype: : "u3b15" enddef : newdef : defined(u3b5) comment : AT&T 3B/5 series running SVR2/3 vendor : : "att" hosttype: : "att3b5" machtype: : "u3b5" enddef : newdef : defined(u3b2) comment : AT&T 3B/2 series running SVR2/3 vendor : : "att" hosttype: : "att3b2" machtype: : "u3b2" enddef : newdef : defined(UNIXPC) comment : AT&T UnixPC att3b1/att7300 vendor : : "att" hosttype: : "unixpc" machtype: defined(u3b1) : "u3b1" machtype: defined(att7300) : "att7300" enddef : newdef : defined(_MINIX) comment : Andy Tanenbaum's minix vendor : defined(M_i386) : "intel" hosttype: defined(M_i386) : "minix386" hosttype: : "minix" ostype : : "minix" machtype: defined(M_i386) : "i386" enddef : newdef : defined(gnu_hurd) comment : GNU/HURD vendor : defined(M_intel) : "intel" hosttype: defined(M_i686) : "i686" hosttype: defined(M_i586) : "i586" hosttype: defined(M_i486) : "i486" hosttype: defined(M_i386) : "i386" ostype : : "gnu" machtype: defined(M_i686) : "i686-pc-gnu" machtype: defined(M_i586) : "i586-pc-gnu" machtype: defined(M_i486) : "i486-pc-gnu" machtype: defined(M_i386) : "i386-pc-gnu" enddef : newdef : defined(linux) || defined(GNU) || defined(GLIBC) comment : Linus Torvalds's linux vendor : defined(M_intel) : "intel" hosttype: : gethost() ostype : : getostype() machtype: : getmach() vendor : defined(ANDROID) : "linux" vendor : defined(alpha) : "dec" vendor : defined(PPC) : "apple" enddef : newdef : defined(EMX) comment : OS/2 EMX [unix emulation under OS/2] vendor : defined(M_intel) : "intel" hosttype: defined(M_i386) : "i386-emx" ostype : : "os2" machtype: defined(M_i386) : "i386" enddef : newdef : defined(NetBSD) comment : NetBSD vendor : defined(algor) : "algoritmics" vendor : defined(arm32) || defined(arm) : "acorn" vendor : defined(alpha) : "digital" vendor : defined(amiga) : "commodore" vendor : defined(atari) : "atari" vendor : defined(hp300) : "hp" vendor : defined(M_intel) : "intel" vendor : defined(m68k) : "motorola" vendor : defined(mac68k) : "apple" vendor : defined(pc532) : "national-semi" vendor : defined(pmax) : "dec" vendor : defined(powerpc) : "motorola" vendor : defined(mips) : "mips" vendor : defined(sparc) : "sun" vendor : defined(sparc64) : "sun" vendor : defined(sun3) : "sun" vendor : defined(vax) : "digital" vendor : defined(M_amd64) : "amd" hosttype: : "NetBSD" ostype : : "NetBSD" machtype: defined(alpha) : "alpha" machtype: defined(algor) : "algor" machtype: defined(arm32) || defined(APCS_32) : "arm32" machtype: defined(arm26) || defined(APCS_26) : "arm26" machtype: defined(arm) : "arm" machtype: defined(sparc) : "sparc" machtype: defined(sparc64) : "sparc64" machtype: defined(mc68020) : "m68k" machtype: defined(M_i386) : "i386" machtype: defined(M_mipsel) : "mipsel" machtype: defined(M_mipseb) : "mipseb" machtype: defined(mips) : "mips" machtype: defined(pc532) : "pc532" machtype: defined(powerpc) : "powerpc" machtype: defined(vax) : "vax" machtype: defined(M_amd64) : "x86_64" enddef : newdef : defined(OpenBSD) comment : OpenBSD vendor : defined(alpha) : "digital" vendor : defined(M_amd64) : "amd" vendor : defined(arm) : "arm" vendor : defined(hppa) || defined(hppa64) : "hp" vendor : defined(M_intel) : "intel" vendor : defined(m68k) : "motorola" vendor : defined(m88k) : "motorola" vendor : defined(mips) && defined(sgi) : "sgi" vendor : defined(powerpc) : "motorola" vendor : defined(sh) : "io-data" vendor : defined(sparc) || defined(sparc64) : "sun" vendor : defined(vax) : "digital" hosttype: : "OpenBSD" ostype : : "OpenBSD" machtype: defined(alpha) : "alpha" machtype: defined(M_amd64) : "amd64" machtype: defined(arm) : "arm" machtype: defined(hppa) : "hppa" machtype: defined(hppa64) : "hppa64" machtype: defined(M_i386) : "i386" machtype: defined(m68k) : "m68k" machtype: defined(m88k) : "m88k" machtype: defined(mips) : "mips" machtype: defined(sh) : "sh" machtype: defined(sparc64) : "sparc64" machtype: defined(sparc) : "sparc" machtype: defined(powerpc) : "powerpc" machtype: defined(vax) : "vax" enddef : newdef : defined(FreeBSD) comment : FreeBSD vendor : defined(alpha) : "digital" vendor : defined(arm32) || defined(arm) : "acorn" vendor : defined(M_intel) : "intel" vendor : defined(ia64) : "intel" vendor : defined(mips) : "mips" vendor : defined(powerpc) : "motorola" vendor : defined(sparc) : "sun" vendor : defined(sparc64) : "sun" vendor : defined(M_amd64) : "amd" hosttype: : "FreeBSD" ostype : : "FreeBSD" machtype: defined(alpha) : "alpha" machtype: defined(arm32) || defined(APCS_32) : "arm32" machtype: defined(arm) : "arm" machtype: defined(ia64) : "ia64" machtype: defined(M_i386) : "i386" machtype: defined(mips) : "mips" machtype: defined(powerpc) : "powerpc" machtype: defined(sparc) : "sparc" machtype: defined(sparc64) : "sparc64" machtype: defined(M_amd64) : "x86_64" enddef : newdef : defined(MidnightBSD) comment : MidnightBSD vendor : defined(M_intel) : "intel" hosttype: : "MidnightBSD" ostype : : "MidnightBSD" machtype: defined(M_i386) : "i386" enddef : newdef : defined(__386BSD__) comment : Bill Jolitz's 386BSD vendor : defined(M_intel) : "intel" hosttype: : "386BSD" ostype : : "386BSD" machtype: : "i386" enddef : newdef : defined(bsdi) comment : BSDI's unix vendor : defined(M_intel) : "intel" vendor : defined(sparc) : "sun" vendor : defined(powerpc) : "motorola" hosttype: defined(M_intel) : "bsd386" hosttype: defined(sparc) : "bsd-sparc" hosttype: defined(powerpc) : "bsd-powerpc" ostype : : "bsdi" machtype: defined(M_i386) : "i386" machtype: defined(sparc) : "sparc" machtype: defined(powerpc) : "powerpc" enddef : newdef : defined(COHERENT) comment : COHERENT's unix vendor : defined(_I386) : "intel" hosttype: : "coh386" hosttype: : "coherent" ostype : : "coherent" machtype: defined(_I386) : "i386" enddef : newdef : defined(concurrent) comment : Concurrent PowerHawk vendor : : "concurrent" hosttype: : "powerhawk" ostype : : "powermax_os" machtype: : "powerhawk" enddef : newdef : defined(SCO) comment : SCO UNIX System V/386 Release 3.2 vendor : : "sco" hosttype: : "sco386" ostype : : "sco_unix" machtype: : "i386" enddef : newdef : defined(M_XENIX) && !defined(M_UNIX) comment : SCO XENIX vendor : : "sco" hosttype: : "sco_xenix" ostype : : "sco_xenix" machtype: defined(M_I386) : "i386" machtype: defined(M_I286) : "i286" enddef : newdef : defined(ISC) || defined(ISC202) comment : Interactive Unix vendor : : "isc" hosttype: : "isc386" ostype : defined(POSIX) : "POSIX" ostype : : "SVR3" machtype: defined(M_i386) : "i386" enddef : newdef : defined(INTEL) comment : Intel Unix vendor : : "intel" hosttype: : "intel386" ostype : : "intel_unix" machtype: defined(M_i386) : "i386" enddef : newdef : defined(MACH) comment : cmu's mach vendor : : "cmu" hosttype: defined(M_i386) : "i386-mach" ostype : : "mach" machtype: defined(M_i386) : "i386" enddef : newdef : defined(alliant) comment : Alliants FSX vendor : : "alliant" hosttype: defined(mc68000) : "alliant-fx80" hosttype: defined(i860) : "alliant-fx2800" hosttype: : "alliant" ostype : : "fsx" machtype: defined(mc68000) : "mc68000" machtype: defined(i860) : "i860" enddef : newdef : defined(_FTX) comment : Stratus Computer, Inc FTX2 (i860 based) comment : Stratus Computer, Inc FTX3 (HPPA based) vendor : : "stratus" hosttype: defined(i860) && defined(_FTX) : "atlantic" hosttype: defined(hppa) && defined(_FTX) : "continuum" ostype : defined(i860) && defined(_FTX) : "ftx2" ostype : defined(hppa) && defined(_FTX) : "ftx3" machtype: defined(i860) : "i860" machtype: defined(hppa) : "hppa" enddef : newdef : defined(sequent) || defined(_SEQUENT_) comment : Sequent Balance (32000 based) comment : Sequent Symmetry running DYNIX/ptx (386/486 based) comment : Sequent Symmetry running DYNIX 3 (386/486 based) vendor : : "sequent" hosttype: defined(M_i386) && defined(sequent) : "symmetry" hosttype: defined(M_i386) : "ptx" hosttype: : "balance" ostype : defined(M_i386) && !defined(sequent) : "ptx" ostype : : "dynix3" machtype: defined(M_i386) : "i386" machtype: defined(ns32000) : "ns32000" enddef : newdef : defined(ns32000) comment : Encore Computer Corp. Multimax (32000 based) vendor : : "encore" hosttype: defined(CMUCS) : "multimax" hosttype: : isamultimax(0) ostype : defined(CMUCS) : "mach" ostype : : isamultimax(1) machtype: : "ns32000" enddef : newdef : defined(iconuxv) comment : Icon 88k running Unix vendor : : "icon" hosttype: : "icon" ostype : : "iconuxv" machtype: defined(m88k) : "m88k" enddef : newdef : defined(_CRAY) && defined(_CRAYCOM) comment : Cray Computer Corp. running CSOS vendor : : "ccc" hosttype: defined(_CRAY2) : "cray" hosttype: defined(_CRAY3) : "cray" hosttype: defined(_CRAY4) : "cray" ostype : : "CSOS" machtype: defined(_CRAY2) : "cray2" machtype: defined(_CRAY3) : "cray3" machtype: defined(_CRAY4) : "cray4" enddef : newdef : defined(cray) && !defined(_CRAYMPP) comment : Cray Research Inc. PVP running UNICOS vendor : : "cri" hosttype: : getcray() ostype : : "unicos" machtype: : getcray() enddef : newdef : defined(cray) && defined(_CRAYT3D) comment : Cray Research Inc. running UNICOS MAX vendor : : "cri" hosttype: : getcray() ostype : : "unicosmax" machtype: : getcray() enddef : newdef : defined(cray) && defined(_CRAYT3E) comment : Cray Research Inc. running UNICOS/mk vendor : : "cri" hosttype: : getcray() ostype : : "unicosmk" machtype: : getcray() enddef : newdef : defined(convex) comment : Convex vendor : : "convex" hosttype: : "convex" ostype : : "convexos" machtype: : getconvex() enddef : newdef : defined(butterfly) comment : BBN Butterfly 1000 vendor : : "bbn" hosttype: : "butterfly" machtype: defined(mc68020) : "m68k" enddef : newdef : defined(NeXT) comment : NeXTStep vendor : : "next" hosttype: defined(mc68020) : "next" hosttype: defined(M_i386) : "intel-pc" hosttype: defined(hppa) : "hp" hosttype: defined(sparc) : "sun" ostype : : "nextstep" machtype: defined(mc68020) : "m68k" machtype: defined(M_i386) : "i386" machtype: defined(hppa) : "hppa" machtype: defined(sparc) : "sparc" enddef : -newdef : defined(APPLE) && defined(MACH) +newdef : defined(APPLE) comment : OS X vendor : : "apple" hosttype: defined(i386) : "intel-mac" hosttype: defined(ppc) : "powermac" hosttype: defined(M_amd64) : "intel-mac" ostype : : "darwin" machtype: defined(i386) : "i386" machtype: defined(M_amd64) : "x86_64" machtype: defined(ppc) : "powerpc" enddef : newdef : defined(sony_news) comment : Sony NEWS 800 or 1700 workstation vendor : : "sony" hosttype: defined(mips) : "news_mips" hosttype: defined(mc68020) : "news_m68k" ostype : : "News" machtype: defined(mc68020) : "m68k" machtype: defined(M_mipsel) : "mipsel" machtype: defined(M_mipseb) : "mipseb" enddef : newdef : defined(sgi) comment : Silicon Graphics vendor : : "sgi" hosttype: defined(M_mipsel) : "iris4d" hosttype: defined(M_mipseb) : "iris4d" hosttype: defined(mc68000) : "iris3d" ostype : : "irix" machtype: defined(M_mipsel) : "mipsel" machtype: defined(M_mipseb) : "mipseb" machtype: defined(mc68000) : "mc68000" enddef : newdef : defined(ultrix) comment : Digital's Ultrix vendor : : "dec" hosttype: defined(M_mipsel) : "decstation" hosttype: defined(M_mipseb) : "decmips" hosttype: defined(vax) : "vax" ostype : : "ultrix" machtype: defined(M_mipsel) : "mipsel" machtype: defined(M_mipseb) : "mipseb" machtype: defined(vax) : "vax" enddef : newdef : defined(MIPS) comment : Mips OS vendor : : "mips" hosttype: defined(M_mipsel) : "mips" hosttype: defined(M_mipseb) : "mips" ostype : : "mips" machtype: defined(M_mipsel) : "mipsel" machtype: defined(M_mipseb) : "mipseb" enddef : newdef : defined(DECOSF1) comment : Digital's alpha running osf1 vendor : : "dec" ostype : : "osf1" hosttype: defined(alpha) : "alpha" machtype: defined(alpha) : "alpha" enddef : newdef : defined(Lynx) comment : Lynx OS 2.1 vendor : : "Lynx" hosttype: defined(M_mipsel) : "lynxos-mips" hosttype: defined(M_mipseb) : "lynxos-mips" hosttype: defined(M_i386) : "lynxos-i386" hosttype: defined(i860) : "lynxos-i860" hosttype: defined(m68k) : "lynxos-m68k" hosttype: defined(m88k) : "lynxos-m88k" hosttype: defined(sparc) : "lynxos-sparc" hosttype: : "lynxos-unknown" ostype : : "LynxOS" machtype: defined(M_mipsel) : "mipsel" machtype: defined(M_mipseb) : "mipseb" machtype: defined(M_i386) : "i386" machtype: defined(i860) : "i860" machtype: defined(m68k) : "m68k" machtype: defined(m88k) : "m88k" machtype: defined(sparc) : "sparc" enddef : newdef : defined(masscomp) comment : Masscomp vendor : : "masscomp" hosttype: : "masscomp" ostype : : "masscomp" enddef : newdef : defined(MACHTEN) comment : Machintosh vendor : : "Tenon" hosttype: : "Macintosh" ostype : : "MachTen" machtype: : "Macintosh" enddef : newdef : defined(GOULD_NP1) comment : Gould vendor : : "gould" hosttype: : "gould_np1" machtype: : "gould" enddef : newdef : defined(MULTIFLOW) comment : Multiflow running 4.3BSD vendor : : "multiflow" hosttype: : "multiflow" machtype: : "multiflow" ostype : : "bsd43" enddef : newdef : defined(SXA) comment : PFU/Fujitsu A-xx computer vendor : : "sxa" hosttype: : "pfa50" ostype : defined(_BSDX_) : "e60-bsdx" ostype : : "e60" machtype: : "pfa50" enddef : newdef : defined(titan) comment : (St)Ardent Titan vendor : : "ardent" hosttype: : "titan" enddef : newdef : defined(stellar) comment : Stellar vendor : : "stellar" hosttype: : "stellar" ostype : : "stellix" enddef : newdef : defined(atari) comment : Atari TT running SVR4. This machine was never comment : commercially available. vendor : : "atari" hosttype: : "atari" ostype : : "asv" enddef : newdef : defined(OPUS) comment : ??? vendor : : "opus" hosttype: : "opus" enddef : newdef : defined(eta10) comment : ETA running SVR3 vendor : : "eta" hosttype: : "eta10" enddef : newdef : defined(hk68) comment : Heurikon HK68 running Uniplus+ 5.0 vendor : : "heurikon" hosttype: : "hk68" ostype : : "uniplus" enddef : newdef : defined(NDIX) comment : Norsk Data ND 500/5000 running Ndix vendor : : "norsk" hosttype: : "nd500" ostype : : "ndix" enddef : newdef : defined(AMIGA) comment : Amiga running AmigaOS+GG vendor : : "commodore" hosttype: : "amiga" ostype : : "AmigaOS" machtype: : "m68k" enddef : newdef : defined(uts) comment : Amdahl running uts 2.1 vendor : : "amdahl" hosttype: : "amdahl" ostype : : "uts" machtype: : "amdahl" enddef : newdef : defined(UTek) comment : Tektronix 4300 running UTek (BSD 4.2 / 68020 based) vendor : : "tektronix" hosttype: : "tek4300" enddef : newdef : defined(UTekV) comment : Tektronix XD88/10 running UTekV 3.2e (SVR3/88100 based) vendor : : "tektronix" hosttype: : "tekXD88" enddef : newdef : defined(DGUX) comment : Data-General AViiON running DGUX hosttype: : "aviion" ostype : : "dgux" vendor : : "dg" machtype: defined(m88k) : "m88k" machtype: defined(i386) : "pentium" enddef : newdef : defined(sysV68) comment : Motorola MPC running System V/68 R32V2 (SVR3/68020 based) vendor : : "motorola" hosttype: : "sysV68" machtype: : "m68k" enddef : newdef : defined(supermax) comment : DDE Supermax running System V/68 R3 (SVR3/68020 based) vendor : : "supermax" hosttype: : "supermax" machtype: : "m68k" enddef : newdef : defined(sysV88) comment : Motorola MPC running System V/88 R32V2 (SVR3/88100 based) vendor : : "motorola" hosttype: : "sysV88" machtype: : "m88k" enddef : newdef : defined(clipper) comment : Clipper Chipset (Intergraph) vendor : : "intergraph" hosttype: : "clipper" machtype: : "clipper" enddef : newdef : defined(QNX) ostype : : "qnx" enddef : newdef : (defined(SNI) || defined(sinix)) && !defined(_OSD_POSIX) comment : Fujitsu Siemens Computers (former "Siemens Nixdorf Informationssysteme"): SINIX aka. ReliantUNIX, a SVR4 derivative vendor : : "fsc" hosttype: defined(M_intel) : "wx200i" hosttype: defined(MIPSEB) : "rm400" ostype : defined(sinix) : "sinix" machtype: defined(M_i586) : "i586" machtype: defined(M_i486) : "i486" machtype: defined(M_i386) : "i386" machtype: defined(M_mipsel) : "mipsel" machtype: defined(M_mipseb) : "mipseb" machtype: : "mips" enddef : newdef : defined(_OSD_POSIX) comment : Fujitsu Siemens Computers (former "Siemens Nixdorf Informationssysteme"): BS2000 POSIX (mainframe, EBCDIC) vendor : : "fsc" hosttype: : "bs2000" ostype : : "osdposix" machtype: #machine(7500) : "s390" machtype: #machine(mips) : "mips" machtype: #machine(sparc) : "sparc" machtype: : "bs2000" enddef : newdef : defined(MVS) comment : ibm uss s/390 (mainframe, EBCDIC) vendor : : "ibm" hosttype: : "s390" ostype : : "os390" machtype: : "s390" enddef : newdef : defined(_SX) comment : NEC Corporation (SX-4) vendor : : "nec" ostype : : "superux" hosttype: : "sx4" machtype: : "sx4" enddef : newdef : !defined(SOLARIS2) && (SYSVREL == 4) comment : Unix System V Release 4.0 vendor : defined(DELL) : "dell" hosttype: defined(M_i386) : "i386" ostype : : "svr4" machtype: defined(M_i386) : "i386" enddef : newdef : defined(uxp) || defined(uxps) comment : FUJITSU DS/90 7000 vendor : : "fujitsu" hosttype: : "ds90" ostype : : "sysv4" machtype: : "sparc" enddef : newdef : defined(CYGWIN) comment : Cygwin vendor : defined(M_intel) : "intel" hosttype: : gethost() ostype : : getostype() machtype: : getmach() enddef : newdef : defined(_UWIN) comment : AT&T Research Unix for Windows vendor : : "att" hosttype: : "win32.i386" machtype: : "i386" enddef : newdef : defined(mc68000) || defined(mc68k32) || defined(m68k) || defined(mc68010) || defined(mc68020) hosttype: : "m68k" vendor : defined(m68k) : "motorola" machtype: : "m68k" enddef : newdef : defined(m88k) hosttype: : "m88k" machtype: : "m88k" enddef : newdef : defined(M_intel) hosttype: defined(M_i586) : "i586" hosttype: defined(M_i486) : "i486" hosttype: defined(M_i386) : "i386" vendor : : "intel" machtype: defined(M_i586) : "i586" machtype: defined(M_i486) : "i486" machtype: defined(M_i386) : "i386" enddef : newdef : defined(sparc) hosttype: : "sparc" machtype: : "sparc" enddef : newdef : defined(i860) hosttype: : "i860" machtype: : "i860" enddef : newdef : defined(osf1) ostype : : "osf1" enddef : newdef : SYSVREL == 0 ostype : defined(BSD4_4) : "bsd44" ostype : defined(BSD) : "bsd" ostype : defined(POSIX) : "posix" enddef : newdef : SYSVREL == 1 ostype : : "svr1" enddef : newdef : SYSVREL == 2 ostype : : "svr2" enddef : newdef : SYSVREL == 3 ostype : : "svr3" enddef : newdef : SYSVREL == 4 ostype : : "svr4" enddef : newcode : #ifndef _hosttype_ hosttype = "unknown"; #endif #ifndef _ostype_ ostype = "unknown"; #endif #ifndef _vendor_ vendor = "unknown"; #endif #ifndef _machtype_ machtype = "unknown"; #endif tsetenv(STRHOSTTYPE, str2short(hosttype)); tsetenv(STRVENDOR, str2short(vendor)); tsetenv(STROSTYPE, str2short(ostype)); tsetenv(STRMACHTYPE, str2short(machtype)); } /* end setmachine */ endcode : diff --git a/contrib/tcsh/patchlevel.h b/contrib/tcsh/patchlevel.h index adcc1027a0d5..3c71e48b78f3 100644 --- a/contrib/tcsh/patchlevel.h +++ b/contrib/tcsh/patchlevel.h @@ -1,13 +1,13 @@ /* * patchlevel.h: Our life story. */ #ifndef _h_patchlevel #define _h_patchlevel #define ORIGIN "Astron" #define REV 6 -#define VERS 21 -#define PATCHLEVEL 00 -#define DATE "2019-05-08" +#define VERS 22 +#define PATCHLEVEL 03 +#define DATE "2020-11-18" #endif /* _h_patchlevel */ diff --git a/contrib/tcsh/sh.c b/contrib/tcsh/sh.c index dd871727d2aa..d888e8e91d21 100644 --- a/contrib/tcsh/sh.c +++ b/contrib/tcsh/sh.c @@ -1,2549 +1,2562 @@ /* * sh.c: Main shell routines */ /*- * Copyright (c) 1980, 1991 The Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #define EXTERN /* Intern */ #include "sh.h" #ifndef lint char copyright[] = "@(#) Copyright (c) 1991 The Regents of the University of California.\n\ All rights reserved.\n"; #endif /* not lint */ #include "tc.h" #include "ed.h" #include "tw.h" extern int MapsAreInited; extern int NLSMapsAreInited; /* * C Shell * * Bill Joy, UC Berkeley, California, USA * October 1978, May 1980 * * Jim Kulp, IIASA, Laxenburg, Austria * April 1980 * * Filename recognition added: * Ken Greer, Ind. Consultant, Palo Alto CA * October 1983. * * Karl Kleinpaste, Computer Consoles, Inc. * Added precmd, periodic/tperiod, prompt changes, * directory stack hack, and login watch. * Sometime March 1983 - Feb 1984. * * Added scheduled commands, including the "sched" command, * plus the call to sched_run near the precmd et al * routines. * Upgraded scheduled events for running events while * sitting idle at command input. * * Paul Placeway, Ohio State * added stuff for running with twenex/inputl 9 Oct 1984. * * ported to Apple Unix (TM) (OREO) 26 -- 29 Jun 1987 */ jmp_buf_t reslab IZERO_STRUCT; struct wordent paraml IZERO_STRUCT; static const char tcshstr[] = "tcsh"; struct sigaction parintr; /* Parents interrupt catch */ struct sigaction parterm; /* Parents terminate catch */ #ifdef TESLA int do_logout = 0; #endif /* TESLA */ int use_fork = 0; /* use fork() instead of vfork()? */ /* * Magic pointer values. Used to specify other invalid conditions aside * from null. */ static Char INVCHAR; Char *INVPTR = &INVCHAR; Char **INVPPTR = &INVPTR; static int fast = 0; static int mflag = 0; static int prompt = 1; int enterhist = 0; int tellwhat = 0; time_t t_period; Char *ffile = NULL; int dolzero = 0; int insource = 0; int exitset = 0; static time_t chktim; /* Time mail last checked */ char *progname; int tcsh; /* * This preserves the input state of the shell. It is used by * st_save and st_restore to manupulate shell state. */ struct saved_state { int insource; int OLDSTD; int SHIN; int SHOUT; int SHDIAG; int intty; struct whyle *whyles; Char *gointr; Char *arginp; Char *evalp; Char **evalvec; Char *alvecp; Char **alvec; int onelflg; int enterhist; Char **argv; Char **av; Char HIST; int cantell; struct Bin B; int justpr; }; static int srccat (Char *, Char *); #ifndef WINNT_NATIVE static int srcfile (const char *, int, int, Char **); #else int srcfile (const char *, int, int, Char **); #endif /*WINNT_NATIVE*/ static void srcunit (int, int, int, Char **); static void mailchk (void); #ifndef _PATH_DEFPATH static Char **defaultpath (void); #endif static void record (void); static void st_save (struct saved_state *, int, int, Char **, Char **); static void st_restore (void *); int main (int, char **); #ifndef LOCALEDIR #define LOCALEDIR "/usr/share/locale" #endif #ifdef NLS_CATALOGS static void add_localedir_to_nlspath(const char *path) { static const char msgs_LOC[] = "/%L/LC_MESSAGES/%N.cat"; static const char msgs_lang[] = "/%l/LC_MESSAGES/%N.cat"; char *old; char *new, *new_p; size_t len; int add_LOC = 1; int add_lang = 1; char trypath[MAXPATHLEN]; struct stat st; if (path == NULL) return; - (void) xsnprintf(trypath, sizeof(trypath), "%s/en/LC_MESSAGES/tcsh.cat", + (void) xsnprintf(trypath, sizeof(trypath), "%s/C/LC_MESSAGES/tcsh.cat", path); if (stat(trypath, &st) == -1) return; if ((old = getenv("NLSPATH")) != NULL) len = strlen(old) + 1; /* don't forget the colon. */ else len = 0; len += 2 * strlen(path) + sizeof(msgs_LOC) + sizeof(msgs_lang); /* includes the extra colon */ new = new_p = xcalloc(len, 1); if (old != NULL) { size_t pathlen = strlen(path); char *old_p; (void) xsnprintf(new_p, len, "%s", old); new_p += strlen(new_p); len -= new_p - new; /* Check if the paths we try to add are already present in NLSPATH. If so, note it by setting the appropriate flag to 0. */ for (old_p = old; old_p; old_p = strchr(old_p, ':'), old_p = old_p ? old_p + 1 : NULL) { if (strncmp(old_p, path, pathlen) != 0) continue; if (strncmp(old_p + pathlen, msgs_LOC, sizeof(msgs_LOC) - 1) == 0) add_LOC = 0; else if (strncmp(old_p + pathlen, msgs_lang, sizeof(msgs_lang) - 1) == 0) add_lang = 0; } } /* Add the message catalog paths not already present to NLSPATH. */ if (add_LOC || add_lang) (void) xsnprintf(new_p, len, "%s%s%s%s%s%s", old ? ":" : "", add_LOC ? path : "", add_LOC ? msgs_LOC : "", add_LOC && add_lang ? ":" : "", add_lang ? path : "", add_lang ? msgs_lang : ""); tsetenv(STRNLSPATH, str2short(new)); free(new); } #endif int main(int argc, char **argv) { int batch = 0; volatile int nexececho = 0; int nofile = 0; volatile int nverbose = 0; volatile int rdirs = 0; volatile int exitcode = 0; int quitit = 0; Char *cp; #ifdef AUTOLOGOUT Char *cp2; #endif char *tcp, *ttyn; int f, reenter; char **tempv; static const char *targinp = NULL; int osetintr; struct sigaction oparintr; #ifdef WINNT_NATIVE nt_init(); #endif /* WINNT_NATIVE */ (void)memset(&reslab, 0, sizeof(reslab)); #if defined(NLS_CATALOGS) && defined(LC_MESSAGES) (void) setlocale(LC_MESSAGES, ""); #endif /* NLS_CATALOGS && LC_MESSAGES */ #ifdef NLS # ifdef LC_CTYPE (void) setlocale(LC_CTYPE, ""); /* for iscntrl */ # endif /* LC_CTYPE */ #endif /* NLS */ STR_environ = blk2short(environ); environ = short2blk(STR_environ); /* So that we can free it */ #ifdef NLS_CATALOGS add_localedir_to_nlspath(LOCALEDIR); #endif nlsinit(); initlex(¶ml); #ifdef MALLOC_TRACE mal_setstatsfile(fdopen(dmove(xopen("/tmp/tcsh.trace", O_WRONLY|O_CREAT|O_LARGEFILE, 0666), 25), "w")); mal_trace(1); #endif /* MALLOC_TRACE */ #if !(defined(BSDTIMES) || defined(_SEQUENT_)) && defined(POSIX) # ifdef _SC_CLK_TCK clk_tck = (clock_t) sysconf(_SC_CLK_TCK); # else /* ! _SC_CLK_TCK */ # ifdef CLK_TCK clk_tck = CLK_TCK; # else /* !CLK_TCK */ clk_tck = HZ; # endif /* CLK_TCK */ # endif /* _SC_CLK_TCK */ #endif /* !BSDTIMES && POSIX */ settimes(); /* Immed. estab. timing base */ #ifdef TESLA do_logout = 0; #endif /* TESLA */ /* * Make sure we have 0, 1, 2 open * Otherwise `` jobs will not work... (From knaff@poly.polytechnique.fr) */ { do if ((f = xopen(_PATH_DEVNULL, O_RDONLY|O_LARGEFILE)) == -1 && (f = xopen("/", O_RDONLY|O_LARGEFILE)) == -1) exit(1); while (f < 3); xclose(f); } osinit(); /* Os dependent initialization */ { char *t; t = strrchr(argv[0], '/'); #ifdef WINNT_NATIVE { char *s = strrchr(argv[0], '\\'); if (s) t = s; } #endif /* WINNT_NATIVE */ t = t ? t + 1 : argv[0]; if (*t == '-') t++; progname = strsave((t && *t) ? t : tcshstr); /* never want a null */ tcsh = strncmp(progname, tcshstr, sizeof(tcshstr) - 1) == 0; } /* * Initialize non constant strings */ #ifdef _PATH_BSHELL STR_BSHELL = SAVE(_PATH_BSHELL); #endif #ifdef _PATH_TCSHELL STR_SHELLPATH = SAVE(_PATH_TCSHELL); #else # ifdef _PATH_CSHELL STR_SHELLPATH = SAVE(_PATH_CSHELL); # endif #endif STR_WORD_CHARS = SAVE(WORD_CHARS); STR_WORD_CHARS_VI = SAVE(WORD_CHARS_VI); HIST = '!'; HISTSUB = '^'; PRCH = tcsh ? '>' : '%'; /* to replace %# in $prompt for normal users */ PRCHROOT = '#'; /* likewise for root */ word_chars = STR_WORD_CHARS; bslash_quote = 0; /* PWP: do tcsh-style backslash quoting? */ anyerror = 1; /* for compatibility */ setcopy(STRanyerror, STRNULL, VAR_READWRITE); /* Default history size to 100 */ setcopy(STRhistory, str2short("100"), VAR_READWRITE); sethistory(100); tempv = argv; ffile = SAVE(tempv[0]); dolzero = 0; if (eq(ffile, STRaout)) /* A.out's are quittable */ quitit = 1; uid = getuid(); gid = getgid(); euid = geteuid(); egid = getegid(); /* * We are a login shell if: 1. we were invoked as - with * optional arguments 2. or we were invoked only with the -l flag */ loginsh = (**tempv == '-') || (argc == 2 && tempv[1][0] == '-' && tempv[1][1] == 'l' && tempv[1][2] == '\0'); #ifdef _VMS_POSIX /* No better way to find if we are a login shell */ if (!loginsh) { loginsh = (argc == 1 && getppid() == 1); **tempv = '-'; /* Avoid giving VMS an acidic stomach */ } #endif /* _VMS_POSIX */ if (loginsh && **tempv != '-') { char *argv0; /* * Mangle the argv space */ tempv[1][0] = '\0'; tempv[1][1] = '\0'; tempv[1] = NULL; argv0 = strspl("-", *tempv); *tempv = argv0; argc--; } if (loginsh) { (void) time(&chktim); setNS(STRloginsh); } NoNLSRebind = getenv("NOREBIND") != NULL; #ifdef NLS # ifdef SETLOCALEBUG dont_free = 1; # endif /* SETLOCALEBUG */ (void) setlocale(LC_ALL, ""); # ifdef LC_COLLATE (void) setlocale(LC_COLLATE, ""); # endif # ifdef SETLOCALEBUG dont_free = 0; # endif /* SETLOCALEBUG */ # ifdef STRCOLLBUG fix_strcoll_bug(); # endif /* STRCOLLBUG */ /* * On solaris ISO8859-1 contains no printable characters in the upper half * so we need to test only for MB_CUR_MAX == 1, otherwise for multi-byte * locales we are always AsciiOnly == 0. */ if (MB_CUR_MAX == 1) { int k; for (k = 0200; k <= 0377 && !isprint(CTL_ESC(k)); k++) continue; AsciiOnly = k > 0377; } else AsciiOnly = 0; #else AsciiOnly = getenv("LANG") == NULL && getenv("LC_CTYPE") == NULL; #endif /* NLS */ if (MapsAreInited && !NLSMapsAreInited) ed_InitNLSMaps(); ResetArrowKeys(); /* * Initialize for periodic command intervals. Also, initialize the dummy * tty list for login-watch. */ (void) time(&t_period); #ifndef HAVENOUTMP initwatch(); #endif /* !HAVENOUTMP */ #if defined(alliant) /* * From: Jim Pace * tcsh does not work properly on the alliants through an rlogin session. * The shell generally hangs. Also, reference to the controlling terminal * does not work ( ie: echo foo > /dev/tty ). * * A security feature was added to rlogind affecting FX/80's Concentrix * from revision 5.5.xx upwards (through 5.7 where this fix was implemented) * This security change also affects the FX/2800 series. * The security change to rlogind requires the process group of an rlogin * session become disassociated with the tty in rlogind. * * The changes needed are: * 1. set the process group * 2. reenable the control terminal */ if (loginsh && isatty(SHIN)) { ttyn = ttyname(SHIN); xclose(SHIN); SHIN = xopen(ttyn, O_RDWR|O_LARGEFILE); shpgrp = getpid(); (void) ioctl (SHIN, TIOCSPGRP, (ioctl_t) &shpgrp); (void) setpgid(0, shpgrp); } #endif /* alliant */ /* * Move the descriptors to safe places. The variable didfds is 0 while we * have only FSH* to work with. When didfds is true, we have 0,1,2 and * prefer to use these. */ initdesc(); cdtohome = 1; setv(STRcdtohome, SAVE(""), VAR_READWRITE); /* * Get and set the tty now */ if ((ttyn = ttyname(SHIN)) != NULL) { /* * Could use rindex to get rid of other possible path components, but * hpux preserves the subdirectory /pty/ when storing the tty name in * utmp, so we keep it too. */ if (strncmp(ttyn, "/dev/", 5) == 0) setv(STRtty, cp = SAVE(ttyn + 5), VAR_READWRITE); else setv(STRtty, cp = SAVE(ttyn), VAR_READWRITE); } else setv(STRtty, cp = SAVE(""), VAR_READWRITE); /* * Initialize the shell variables. ARGV and PROMPT are initialized later. * STATUS is also munged in several places. CHILD is munged when * forking/waiting */ /* * 7-10-87 Paul Placeway autologout should be set ONLY on login shells and * on shells running as root. Out of these, autologout should NOT be set * for any psudo-terminals (this catches most window systems) and not for * any terminal running X windows. * * At Ohio State, we have had problems with a user having his X session * drop out from under him (on a Sun) because the shell in his master * xterm timed out and exited. * * Really, this should be done with a program external to the shell, that * watches for no activity (and NO running programs, such as dump) on a * terminal for a long peroid of time, and then SIGHUPS the shell on that * terminal. * * bugfix by Rich Salz : For root rsh things * allways first check to see if loginsh or really root, then do things * with ttyname() * * Also by Jean-Francois Lamy : check the * value of cp before using it! ("root can rsh too") * * PWP: keep the nested ifs; the order of the tests matters and a good * (smart) C compiler might re-arange things wrong. */ #ifdef AUTOLOGOUT # ifdef convex if (uid == 0) /* root always has a 15 minute autologout */ setcopy(STRautologout, STRrootdefautologout, VAR_READWRITE); else if (loginsh) /* users get autologout set to 0 */ setcopy(STRautologout, STR0, VAR_READWRITE); # else /* convex */ if (loginsh || (uid == 0)) { if (*cp) { /* only for login shells or root and we must have a tty */ if (((cp2 = Strrchr(cp, (Char) '/')) != NULL) && (Strncmp(cp, STRptssl, 3) != 0)) { cp2 = cp2 + 1; } else cp2 = cp; if (!(((Strncmp(cp2, STRtty, 3) == 0) && Isalpha(cp2[3])) || Strstr(cp, STRptssl) != NULL)) { if (getenv("DISPLAY") == NULL) { /* NOT on X window shells */ setcopy(STRautologout, STRdefautologout, VAR_READWRITE); } } } } # endif /* convex */ #endif /* AUTOLOGOUT */ sigset_interrupting(SIGALRM, queue_alrmcatch); setcopy(STRstatus, STR0, VAR_READWRITE); /* * get and set machine specific environment variables */ getmachine(); /* * Publish the selected echo style */ #if ECHO_STYLE != BSD_ECHO if (tcsh) { # if ECHO_STYLE == NONE_ECHO setcopy(STRecho_style, STRnone, VAR_READWRITE); # endif /* ECHO_STYLE == NONE_ECHO */ # if ECHO_STYLE == SYSV_ECHO setcopy(STRecho_style, STRsysv, VAR_READWRITE); # endif /* ECHO_STYLE == SYSV_ECHO */ # if ECHO_STYLE == BOTH_ECHO setcopy(STRecho_style, STRboth, VAR_READWRITE); # endif /* ECHO_STYLE == BOTH_ECHO */ } else #endif /* ECHO_STYLE != BSD_ECHO */ setcopy(STRecho_style, STRbsd, VAR_READWRITE); /* * increment the shell level. */ shlvl(1); #ifdef __ANDROID__ /* On Android, $HOME either isn't set or set to /data, a R/O location. Check for the environment variable EXTERNAL_STORAGE, which contains the mount point of the external storage (SD card, mostly). If EXTERNAL_STORAGE isn't set fall back to "/sdcard". Eventually override $HOME so the environment is on the same page. */ if (((tcp = getenv("HOME")) != NULL && strcmp (tcp, "/data") != 0) || (tcp = getenv("EXTERNAL_STORAGE")) != NULL) { cp = quote(SAVE(tcp)); } else cp = quote(SAVE("/sdcard")); tsetenv(STRKHOME, cp); #else if ((tcp = getenv("HOME")) != NULL) cp = quote(SAVE(tcp)); else cp = NULL; #endif if (cp == NULL) fast = 1; /* No home -> can't read scripts */ else setv(STRhome, cp, VAR_READWRITE); dinit(cp); /* dinit thinks that HOME == cwd in a login * shell */ /* * Grab other useful things from the environment. Should we grab * everything?? */ { char *cln, *cus, *cgr; struct passwd *pw; struct group *gr; #ifdef apollo int oid = getoid(); setv(STRoid, Itoa(oid, 0, 0), VAR_READWRITE); #endif /* apollo */ setv(STReuid, Itoa(euid, 0, 0), VAR_READWRITE); if ((pw = xgetpwuid(euid)) == NULL) setcopy(STReuser, STRunknown, VAR_READWRITE); else setcopy(STReuser, str2short(pw->pw_name), VAR_READWRITE); setv(STRuid, Itoa(uid, 0, 0), VAR_READWRITE); setv(STRgid, Itoa(gid, 0, 0), VAR_READWRITE); cln = getenv("LOGNAME"); cus = getenv("USER"); if (cus != NULL) setv(STRuser, quote(SAVE(cus)), VAR_READWRITE); else if (cln != NULL) setv(STRuser, quote(SAVE(cln)), VAR_READWRITE); else if ((pw = xgetpwuid(uid)) == NULL) setcopy(STRuser, STRunknown, VAR_READWRITE); else setcopy(STRuser, str2short(pw->pw_name), VAR_READWRITE); if (cln == NULL) tsetenv(STRLOGNAME, varval(STRuser)); if (cus == NULL) tsetenv(STRKUSER, varval(STRuser)); cgr = getenv("GROUP"); if (cgr != NULL) setv(STRgroup, quote(SAVE(cgr)), VAR_READWRITE); else if ((gr = xgetgrgid(gid)) == NULL) setcopy(STRgroup, STRunknown, VAR_READWRITE); else setcopy(STRgroup, str2short(gr->gr_name), VAR_READWRITE); if (cgr == NULL) tsetenv(STRKGROUP, varval(STRgroup)); } /* * HOST may be wrong, since rexd transports the entire environment on sun * 3.x Just set it again */ { char cbuff[MAXHOSTNAMELEN]; if (gethostname(cbuff, sizeof(cbuff)) >= 0) { cbuff[sizeof(cbuff) - 1] = '\0'; /* just in case */ tsetenv(STRHOST, str2short(cbuff)); } else tsetenv(STRHOST, STRunknown); } #ifdef REMOTEHOST /* * Try to determine the remote host we were logged in from. */ remotehost(); #endif /* REMOTEHOST */ #ifdef apollo if ((tcp = getenv("SYSTYPE")) == NULL) tcp = "bsd4.3"; tsetenv(STRSYSTYPE, quote(str2short(tcp))); #endif /* apollo */ /* * set editing on by default, unless running under Emacs as an inferior * shell. * We try to do this intelligently. If $TERM is available, then it * should determine if we should edit or not. $TERM is preserved * across rlogin sessions, so we will not get confused if we rlogin * under an emacs shell. Another advantage is that if we run an * xterm under an emacs shell, then the $TERM will be set to * xterm, so we are going to want to edit. Unfortunately emacs * does not restore all the tty modes, so xterm is not very well * set up. But this is not the shell's fault. * Also don't edit if $TERM == wm, for when we're running under an ATK app. * Finally, emacs compiled under terminfo, sets the terminal to dumb, * so disable editing for that too. * * Unfortunately, in some cases the initial $TERM setting is "unknown", * "dumb", or "network" which is then changed in the user's startup files. * We fix this by setting noediting here if $TERM is unknown/dumb and * if noediting is set, we switch on editing if $TERM is changed. */ if ((tcp = getenv("TERM")) != NULL) { setv(STRterm, quote(SAVE(tcp)), VAR_READWRITE); noediting = strcmp(tcp, "unknown") == 0 || strcmp(tcp, "dumb") == 0 || strcmp(tcp, "network") == 0; editing = strcmp(tcp, "emacs") != 0 && strcmp(tcp, "wm") != 0 && !noediting; } else { noediting = 0; editing = ((tcp = getenv("EMACS")) == NULL || strcmp(tcp, "t") != 0); } /* * The 'edit' variable is either set or unset. It doesn't * need a value. Making it 'emacs' might be confusing. */ if (editing) setNS(STRedit); /* * still more mutability: make the complete routine automatically add the * suffix of file names... */ setNS(STRaddsuffix); /* * Compatibility with tcsh >= 6.12 by default */ setNS(STRcsubstnonl); /* * Random default kill ring size */ setcopy(STRkillring, str2short("30"), VAR_READWRITE); /* * Re-initialize path if set in environment */ if ((tcp = getenv("PATH")) == NULL) #ifdef _PATH_DEFPATH importpath(str2short(_PATH_DEFPATH)); #else /* !_PATH_DEFPATH */ setq(STRpath, defaultpath(), &shvhed, VAR_READWRITE); #endif /* _PATH_DEFPATH */ else /* Importpath() allocates memory for the path, and the * returned pointer from SAVE() was discarded, so * this was a memory leak.. (sg) * * importpath(SAVE(tcp)); */ importpath(str2short(tcp)); { /* If the SHELL environment variable ends with "tcsh", set * STRshell to the same path. This is to facilitate using * the executable in environments where the compiled-in * default isn't appropriate (sg). */ size_t sh_len = 0; if ((tcp = getenv("SHELL")) != NULL) { sh_len = strlen(tcp); if ((sh_len >= 5 && strcmp(tcp + (sh_len - 5), "/tcsh") == 0) || (!tcsh && sh_len >= 4 && strcmp(tcp + (sh_len - 4), "/csh") == 0)) setv(STRshell, quote(SAVE(tcp)), VAR_READWRITE); else sh_len = 0; } if (sh_len == 0) setcopy(STRshell, STR_SHELLPATH, VAR_READWRITE); } #ifdef _OSD_POSIX /* BS2000 needs this variable set to "SHELL" */ if ((tcp = getenv("PROGRAM_ENVIRONMENT")) == NULL) tcp = "SHELL"; tsetenv(STRPROGRAM_ENVIRONMENT, quote(str2short(tcp))); #endif /* _OSD_POSIX */ #ifdef COLOR_LS_F if ((tcp = getenv("LS_COLORS")) != NULL) parseLS_COLORS(str2short(tcp)); if ((tcp = getenv("LSCOLORS")) != NULL) parseLSCOLORS(str2short(tcp)); #endif /* COLOR_LS_F */ mainpid = getpid(); doldol = putn((tcsh_number_t)mainpid); /* For $$ */ #ifdef WINNT_NATIVE { char *tmp; Char *tmp2; if ((tmp = getenv("TMP")) != NULL) { tmp = xasprintf("%s/%s", tmp, "sh"); tmp2 = SAVE(tmp); xfree(tmp); } else { tmp2 = SAVE(""); } shtemp = Strspl(tmp2, doldol); /* For << */ xfree(tmp2); } #else /* !WINNT_NATIVE */ #ifdef HAVE_MKSTEMP { const char *tmpdir = getenv ("TMPDIR"); if (!tmpdir) tmpdir = "/tmp"; shtemp = Strspl(SAVE(tmpdir), SAVE("/sh" TMP_TEMPLATE)); /* For << */ } #else /* !HAVE_MKSTEMP */ shtemp = Strspl(STRtmpsh, doldol); /* For << */ #endif /* HAVE_MKSTEMP */ #endif /* WINNT_NATIVE */ /* * Record the interrupt states from the parent process. If the parent is * non-interruptible our hand must be forced or we (and our children) won't * be either. Our children inherit termination from our parent. We catch it * only if we are the login shell. */ sigaction(SIGINT, NULL, &parintr); sigaction(SIGTERM, NULL, &parterm); #ifdef TCF /* Enable process migration on ourselves and our progeny */ (void) signal(SIGMIGRATE, SIG_DFL); #endif /* TCF */ /* * dspkanji/dspmbyte autosetting */ /* PATCH IDEA FROM Issei.Suzuki VERY THANKS */ #if defined(DSPMBYTE) #if defined(NLS) && defined(LC_CTYPE) if (((tcp = setlocale(LC_CTYPE, NULL)) != NULL || (tcp = getenv("LANG")) != NULL) && !adrof(CHECK_MBYTEVAR)) #else if ((tcp = getenv("LANG")) != NULL && !adrof(CHECK_MBYTEVAR)) #endif { autoset_dspmbyte(str2short(tcp)); } #if defined(WINNT_NATIVE) else if (!adrof(CHECK_MBYTEVAR)) nt_autoset_dspmbyte(); #endif /* WINNT_NATIVE */ #endif #if defined(AUTOSET_KANJI) # if defined(NLS) && defined(LC_CTYPE) if (setlocale(LC_CTYPE, NULL) != NULL || getenv("LANG") != NULL) # else if (getenv("LANG") != NULL) # endif autoset_kanji(); #endif /* AUTOSET_KANJI */ fix_version(); /* publish the shell version */ if (argc > 1 && strcmp(argv[1], "--version") == 0) { xprintf("%S\n", varval(STRversion)); xexit(0); } if (argc > 1 && strcmp(argv[1], "--help") == 0) { xprintf("%S\n\n", varval(STRversion)); xprintf("%s", CGETS(11, 8, HELP_STRING)); xexit(0); } /* * Process the arguments. * * Note that processing of -v/-x is actually delayed till after script * processing. * * We set the first character of our name to be '-' if we are a shell * running interruptible commands. Many programs which examine ps'es * use this to filter such shells out. */ argc--, tempv++; while (argc > 0 && (tcp = tempv[0])[0] == '-' && *++tcp != '\0' && !batch) { do switch (*tcp++) { case 0: /* - Interruptible, no prompt */ prompt = 0; setintr = 1; nofile = 1; break; case 'b': /* -b Next arg is input file */ batch = 1; break; case 'c': /* -c Command input from arg */ if (argc == 1) xexit(0); argc--, tempv++; #ifdef M_XENIX /* Xenix Vi bug: it relies on a 7 bit environment (/bin/sh), so it pass ascii arguments with the 8th bit set */ if (!strcmp(argv[0], "sh")) { char *p; for (p = tempv[0]; *p; ++p) *p &= ASCII; } #endif targinp = tempv[0]; prompt = 0; nofile = 1; break; case 'd': /* -d Load directory stack from file */ rdirs = 1; break; #ifdef apollo case 'D': /* -D Define environment variable */ { Char *dp; cp = str2short(tcp); if (dp = Strchr(cp, '=')) { *dp++ = '\0'; tsetenv(cp, dp); } else tsetenv(cp, STRNULL); } *tcp = '\0'; /* done with this argument */ break; #endif /* apollo */ case 'e': /* -e Exit on any error */ exiterr = 1; break; case 'f': /* -f Fast start */ fast = 1; break; case 'i': /* -i Interactive, even if !intty */ intact = 1; nofile = 1; break; case 'm': /* -m read .cshrc (from su) */ mflag = 1; break; case 'n': /* -n Don't execute */ noexec = 1; break; case 'q': /* -q (Undoc'd) ... die on quit */ quitit = 1; break; case 's': /* -s Read from std input */ nofile = 1; break; case 't': /* -t Read one line from input */ onelflg = 2; prompt = 0; nofile = 1; break; case 'v': /* -v Echo hist expanded input */ nverbose = 1; /* ... later */ break; case 'x': /* -x Echo just before execution */ nexececho = 1; /* ... later */ break; case 'V': /* -V Echo hist expanded input */ setNS(STRverbose); /* NOW! */ break; case 'X': /* -X Echo just before execution */ setNS(STRecho); /* NOW! */ break; case 'F': /* * This will cause children to be created using fork instead of * vfork. */ use_fork = 1; break; case ' ': case '\t': case '\r': case '\n': /* * for O/S's that don't do the argument parsing right in * "#!/foo -f " scripts */ break; default: /* Unknown command option */ exiterr = 1; stderror(ERR_TCSHUSAGE, tcp-1, progname); break; } while (*tcp); tempv++, argc--; } if (quitit) /* With all due haste, for debugging */ (void) signal(SIGQUIT, SIG_DFL); /* * Unless prevented by -, -c, -i, -s, or -t, if there are remaining * arguments the first of them is the name of a shell file from which to * read commands. */ if (nofile == 0 && argc > 0) { nofile = xopen(tempv[0], O_RDONLY|O_LARGEFILE); if (nofile < 0) { child = 1; /* So this ... */ /* ... doesn't return */ stderror(ERR_SYSTEM, tempv[0], strerror(errno)); } xfree(ffile); dolzero = 1; ffile = SAVE(tempv[0]); /* * Replace FSHIN. Handle /dev/std{in,out,err} specially * since once they are closed we cannot open them again. * In that case we use our own saved descriptors */ if ((SHIN = dmove(nofile, FSHIN)) < 0) switch(nofile) { case 0: SHIN = FSHIN; break; case 1: SHIN = FSHOUT; break; case 2: SHIN = FSHDIAG; break; default: stderror(ERR_SYSTEM, tempv[0], strerror(errno)); break; } (void) close_on_exec(SHIN, 1); prompt = 0; /* argc not used any more */ tempv++; } /* * Call to closem() used to be part of initdesc(). Now called below where * the script name argument has become stdin. Kernel may have used a file * descriptor to hold the name of the script (setuid case) and this name * mustn't be lost by closing the fd too soon. */ closem(); /* * Consider input a tty if it really is or we are interactive. but not for * editing (christos) */ if (!(intty = isatty(SHIN))) { if (adrof(STRedit)) unsetv(STRedit); editing = 0; } intty |= intact; #ifndef convex if (intty || (intact && isatty(SHOUT))) { if (!batch && (uid != euid || gid != egid)) { errno = EACCES; child = 1; /* So this ... */ /* ... doesn't return */ stderror(ERR_SYSTEM, progname, strerror(errno)); } } #endif /* convex */ isoutatty = isatty(SHOUT); isdiagatty = isatty(SHDIAG); /* * Decide whether we should play with signals or not. If we are explicitly * told (via -i, or -) or we are a login shell (arg0 starts with -) or the * input and output are both the ttys("csh", or "csh/dev/ttyx") * Note that in only the login shell is it likely that parent may have set * signals to be ignored */ if (loginsh || intact || (intty && isatty(SHOUT))) setintr = 1; settell(); /* * Save the remaining arguments in argv. */ setq(STRargv, blk2short(tempv), &shvhed, VAR_READWRITE); /* * Set up the prompt. */ if (prompt) { setcopy(STRprompt, STRdefprompt, VAR_READWRITE); /* that's a meta-questionmark */ setcopy(STRprompt2, STRmquestion, VAR_READWRITE); setcopy(STRprompt3, STRKCORRECT, VAR_READWRITE); } /* * If we are an interactive shell, then start fiddling with the signals; * this is a tricky game. */ shpgrp = mygetpgrp(); opgrp = tpgrp = -1; if (setintr) { struct sigaction osig; **argv = '-'; if (!quitit) /* Wary! */ (void) signal(SIGQUIT, SIG_IGN); pintr_disabled = 1; sigset_interrupting(SIGINT, queue_pintr); (void) signal(SIGTERM, SIG_IGN); /* * No reason I can see not to save history on all these events.. * Most usual occurrence is in a window system, where we're not a login * shell, but might as well be... (sg) * But there might be races when lots of shells exit together... * [this is also incompatible]. * We have to be mre careful here. If the parent wants to * ignore the signals then we leave them untouched... * We also only setup the handlers for shells that are trully * interactive. */ sigaction(SIGHUP, NULL, &osig); if (loginsh || osig.sa_handler != SIG_IGN) /* exit processing on HUP */ sigset_interrupting(SIGHUP, queue_phup); #ifdef SIGXCPU sigaction(SIGXCPU, NULL, &osig); if (loginsh || osig.sa_handler != SIG_IGN) /* exit processing on XCPU */ sigset_interrupting(SIGXCPU, queue_phup); #endif #ifdef SIGXFSZ sigaction(SIGXFSZ, NULL, &osig); if (loginsh || osig.sa_handler != SIG_IGN) /* exit processing on XFSZ */ sigset_interrupting(SIGXFSZ, queue_phup); #endif if (quitit == 0 && targinp == 0) { #ifdef SIGTSTP (void) signal(SIGTSTP, SIG_IGN); #endif #ifdef SIGTTIN (void) signal(SIGTTIN, SIG_IGN); #endif #ifdef SIGTTOU (void) signal(SIGTTOU, SIG_IGN); #endif /* * Wait till in foreground, in case someone stupidly runs csh & * dont want to try to grab away the tty. */ if (isatty(FSHDIAG)) f = FSHDIAG; else if (isatty(FSHOUT)) f = FSHOUT; else if (isatty(OLDSTD)) f = OLDSTD; else f = -1; #ifdef NeXT /* NeXT 2.0 /usr/etc/rlogind, does not set our process group! */ if (f != -1 && shpgrp == 0) { shpgrp = getpid(); (void) setpgid(0, shpgrp); (void) tcsetpgrp(f, shpgrp); } #endif /* NeXT */ #ifdef BSDJOBS /* if we have tty job control */ if (f != -1 && grabpgrp(f, shpgrp) != -1) { /* * Thanks to Matt Day for the POSIX references, and to * Paul Close for the SGI clarification. */ if (setdisc(f) != -1) { opgrp = shpgrp; shpgrp = getpid(); tpgrp = shpgrp; if (tcsetpgrp(f, shpgrp) == -1) { /* * On hpux 7.03 this fails with EPERM. This happens on * the 800 when opgrp != shpgrp at this point. (we were * forked from a non job control shell) * POSIX 7.2.4, says we failed because the process * group specified did not belong to a process * in the same session with the tty. So we set our * process group and try again. */ if (setpgid(0, shpgrp) == -1) { xprintf("setpgid:"); goto notty; } if (tcsetpgrp(f, shpgrp) == -1) { xprintf("tcsetpgrp:"); goto notty; } } /* * We check the process group now. If it is the same, then * we don't need to set it again. On hpux 7.0 on the 300's * if we set it again it fails with EPERM. This is the * correct behavior according to POSIX 4.3.3 if the process * was a session leader . */ else if (shpgrp != mygetpgrp()) { - if(setpgid(0, shpgrp) == -1) { + if (setpgid(0, shpgrp) == -1) { xprintf("setpgid:"); goto notty; } } #ifdef IRIS4D /* * But on irix 3.3 we need to set it again, even if it is * the same. We do that to tell the system that we * need BSD process group compatibility. */ else (void) setpgid(0, shpgrp); #endif (void) close_on_exec(dcopy(f, FSHTTY), 1); } else tpgrp = -1; } if (tpgrp == -1) { notty: xprintf(CGETS(11, 1, "Warning: no access to tty (%s).\n"), strerror(errno)); xprintf("%s", CGETS(11, 2, "Thus no job control in this shell.\n")); /* * Fix from:Sakari Jalovaara if we don't * have access to tty, disable editing too */ if (adrof(STRedit)) unsetv(STRedit); editing = 0; } #else /* BSDJOBS */ /* don't have job control, so frotz it */ tpgrp = -1; #endif /* BSDJOBS */ } } if (setintr == 0 && parintr.sa_handler == SIG_DFL) setintr = 1; /* * SVR4 doesn't send a SIGCHLD when a child is stopped or continued if the * handler is installed with signal(2) or sigset(2). sigaction(2) must * be used instead. * * David Dawes (dawes@physics.su.oz.au) Sept 1991 */ sigset_interrupting(SIGCHLD, queue_pchild); if (intty && !targinp) (void) ed_Setup(editing);/* Get the tty state, and set defaults */ /* Only alter the tty state if editing */ /* * Set an exit here in case of an interrupt or error reading the shell * start-up scripts. */ osetintr = setintr; oparintr = parintr; (void)cleanup_push_mark(); /* There is no outer handler */ if (setexit() != 0) /* PWP */ reenter = 1; else reenter = 0; exitset++; haderr = 0; /* In case second time through */ if (!fast && reenter == 0) { /* Will have varval(STRhome) here because set fast if don't */ { pintr_disabled++; cleanup_push(&pintr_disabled, disabled_cleanup); setintr = 0;/*FIXRESET:cleanup*/ /* onintr in /etc/ files has no effect */ parintr.sa_handler = SIG_IGN;/*FIXRESET: cleanup*/ #ifdef LOGINFIRST #ifdef _PATH_DOTLOGIN if (loginsh) (void) srcfile(_PATH_DOTLOGIN, 0, 0, NULL); #endif #endif #ifdef _PATH_DOTCSHRC (void) srcfile(_PATH_DOTCSHRC, 0, 0, NULL); #endif if (!targinp && !onelflg && !havhash) dohash(NULL,NULL); #ifndef LOGINFIRST #ifdef _PATH_DOTLOGIN if (loginsh) (void) srcfile(_PATH_DOTLOGIN, 0, 0, NULL); #endif #endif cleanup_until(&pintr_disabled); setintr = osetintr; parintr = oparintr; } #ifdef LOGINFIRST if (loginsh) (void) srccat(varval(STRhome), STRsldotlogin); #endif /* upward compat. */ if (!srccat(varval(STRhome), STRsldottcshrc)) (void) srccat(varval(STRhome), STRsldotcshrc); if (!targinp && !onelflg && !havhash) dohash(NULL,NULL); /* * Source history before .login so that it is available in .login */ loadhist(NULL, 0); #ifndef LOGINFIRST if (loginsh) (void) srccat(varval(STRhome), STRsldotlogin); #endif if (loginsh || rdirs) loaddirs(NULL); } /* Reset interrupt flag */ setintr = osetintr; parintr = oparintr; exitset--; /* Initing AFTER .cshrc is the Right Way */ if (intty && !targinp) { /* PWP setup stuff */ ed_Init(); /* init the new line editor */ #ifdef SIG_WINDOW check_window_size(1); /* mung environment */ #endif /* SIG_WINDOW */ } /* * Now are ready for the -v and -x flags */ if (nverbose) setNS(STRverbose); if (nexececho) setNS(STRecho); if (targinp) { /* If this -c command caused an error before, skip processing */ if (reenter && arginp) { exitcode = 1; goto done; } arginp = SAVE(targinp); /* * we put the command into a variable */ if (arginp != NULL) setv(STRcommand, quote(Strsave(arginp)), VAR_READWRITE); /* * * Give an error on -c arguments that end in * backslash to * ensure that you don't make * nonportable csh scripts. */ { int count; cp = Strend(arginp); count = 0; while (cp > arginp && *--cp == '\\') ++count; if ((count & 1) != 0) { exiterr = 1; stderror(ERR_ARGC); } } } /* * All the rest of the world is inside this call. The argument to process * indicates whether it should catch "error unwinds". Thus if we are a * interactive shell our call here will never return by being blown past on * an error. */ process(setintr); done: /* * Mop-up. */ /* Take care of these (especially HUP) here instead of inside flush. */ handle_pending_signals(); if (intty) { if (loginsh) { xprintf("logout\n"); xclose(SHIN); child = 1; #ifdef TESLA do_logout = 1; #endif /* TESLA */ goodbye(NULL, NULL); } else { xprintf("exit\n"); } } record(); exitstat(); return exitcode; } void untty(void) { #ifdef BSDJOBS if (tpgrp > 0 && opgrp != shpgrp) { (void) setpgid(0, opgrp); (void) tcsetpgrp(FSHTTY, opgrp); (void) resetdisc(FSHTTY); } #endif /* BSDJOBS */ } void importpath(Char *cp) { size_t i = 0; Char *dp; Char **pv; int c; for (dp = cp; *dp; dp++) if (*dp == PATHSEP) i++; /* * i+2 where i is the number of colons in the path. There are i+1 * directories in the path plus we need room for a zero terminator. */ pv = xcalloc(i + 2, sizeof(Char *)); dp = cp; i = 0; if (*dp) for (;;) { if ((c = *dp) == PATHSEP || c == 0) { *dp = 0; pv[i++] = Strsave(*cp ? cp : STRdot); if (c) { cp = dp + 1; *dp = PATHSEP; } else break; } #ifdef WINNT_NATIVE else if (*dp == '\\') *dp = '/'; #endif /* WINNT_NATIVE */ dp++; } pv[i] = 0; cleanup_push(pv, blk_cleanup); setq(STRpath, pv, &shvhed, VAR_READWRITE); cleanup_ignore(pv); cleanup_until(pv); } /* * Source to the file which is the catenation of the argument names. */ static int srccat(Char *cp, Char *dp) { if (cp[0] == '/' && cp[1] == '\0') return srcfile(short2str(dp), (mflag ? 0 : 1), 0, NULL); else { Char *ep; char *ptr; int rv; #ifdef WINNT_NATIVE ep = Strend(cp); if (ep != cp && ep[-1] == '/' && dp[0] == '/') /* silly win95 */ dp++; #endif /* WINNT_NATIVE */ ep = Strspl(cp, dp); cleanup_push(ep, xfree); ptr = short2str(ep); rv = srcfile(ptr, (mflag ? 0 : 1), 0, NULL); cleanup_until(ep); return rv; } } /* * Source to a file putting the file descriptor in a safe place (> 2). */ #ifndef WINNT_NATIVE static int #else int #endif /*WINNT_NATIVE*/ srcfile(const char *f, int onlyown, int flag, Char **av) { int unit; if ((unit = xopen(f, O_RDONLY|O_LARGEFILE)) == -1) return 0; cleanup_push(&unit, open_cleanup); unit = dmove(unit, -1); cleanup_ignore(&unit); cleanup_until(&unit); (void) close_on_exec(unit, 1); srcunit(unit, onlyown, flag, av); return 1; } /* * Save the shell state, and establish new argument vector, and new input * fd. */ static void st_save(struct saved_state *st, int unit, int hflg, Char **al, Char **av) { st->insource = insource; st->SHIN = SHIN; /* Want to preserve the meaning of "source file >output". * Save old descriptors, move new 0,1,2 to safe places and assign * them to SH* and let process() redo 0,1,2 from them. * * The macro returns true if d1 and d2 are good and they point to * different things. If you don't avoid saving duplicate * descriptors, you really limit the depth of "source" recursion * you can do because of all the open file descriptors. -IAN! */ #define NEED_SAVE_FD(d1,d2) \ (fstat(d1, &s1) != -1 && fstat(d2, &s2) != -1 \ && (s1.st_ino != s2.st_ino || s1.st_dev != s2.st_dev) ) st->OLDSTD = st->SHOUT = st->SHDIAG = -1;/* test later to restore these */ if (didfds) { struct stat s1, s2; if (NEED_SAVE_FD(0,OLDSTD)) { st->OLDSTD = OLDSTD; OLDSTD = dmove(0, -1); (void)close_on_exec(OLDSTD, 1); } if (NEED_SAVE_FD(1,SHOUT)) { st->SHOUT = SHOUT; SHOUT = dmove(1, -1); (void)close_on_exec(SHOUT, 1); } if (NEED_SAVE_FD(2,SHDIAG)) { st->SHDIAG = SHDIAG; SHDIAG = dmove(2, -1); (void)close_on_exec(SHDIAG, 1); } donefds(); } st->intty = intty; st->whyles = whyles; st->gointr = gointr; st->arginp = arginp; st->evalp = evalp; st->evalvec = evalvec; st->alvecp = alvecp; st->alvec = alvec; st->onelflg = onelflg; st->enterhist = enterhist; st->justpr = justpr; if (hflg) st->HIST = HIST; else st->HIST = '\0'; st->cantell = cantell; cpybin(st->B, B); /* * we can now pass arguments to source. * For compatibility we do that only if arguments were really * passed, otherwise we keep the old, global $argv like before. */ if (av != NULL && *av != NULL) { struct varent *vp; if ((vp = adrof(STRargv)) != NULL && vp->vec != NULL) st->argv = saveblk(vp->vec); else st->argv = NULL; setq(STRargv, saveblk(av), &shvhed, VAR_READWRITE); } else st->argv = NULL; st->av = av; SHIN = unit; /* Do this first */ /* Establish new input arena */ { fbuf = NULL; fseekp = feobp = fblocks = 0; settell(); } arginp = 0; onelflg = 0; intty = isatty(SHIN); whyles = 0; gointr = 0; evalvec = 0; evalp = 0; alvec = al; alvecp = 0; enterhist = hflg; if (enterhist) HIST = '\0'; insource = 1; } /* * Restore the shell to a saved state */ static void st_restore(void *xst) { struct saved_state *st; st = xst; if (st->SHIN == -1) return; /* Reset input arena */ { int i; Char** nfbuf = fbuf; int nfblocks = fblocks; fblocks = 0; fbuf = NULL; for (i = 0; i < nfblocks; i++) xfree(nfbuf[i]); xfree(nfbuf); } cpybin(B, st->B); xclose(SHIN); insource = st->insource; SHIN = st->SHIN; if (st->OLDSTD != -1) xclose(OLDSTD), OLDSTD = st->OLDSTD; if (st->SHOUT != -1) xclose(SHOUT), SHOUT = st->SHOUT; if (st->SHDIAG != -1) xclose(SHDIAG), SHDIAG = st->SHDIAG; arginp = st->arginp; onelflg = st->onelflg; evalp = st->evalp; evalvec = st->evalvec; alvecp = st->alvecp; alvec = st->alvec; intty = st->intty; whyles = st->whyles; gointr = st->gointr; if (st->HIST != '\0') HIST = st->HIST; enterhist = st->enterhist; cantell = st->cantell; justpr = st->justpr; if (st->argv != NULL) setq(STRargv, st->argv, &shvhed, VAR_READWRITE); else if (st->av != NULL && *st->av != NULL && adrof(STRargv) != NULL) unsetv(STRargv); } /* * Source to a unit. If onlyown it must be our file or our group or * we don't chance it. This occurs on ".cshrc"s and the like. */ static void srcunit(int unit, int onlyown, int hflg, Char **av) { struct saved_state st; st.SHIN = -1; /* st_restore checks this */ if (unit < 0) return; if (onlyown) { struct stat stb; if (fstat(unit, &stb) < 0) { xclose(unit); return; } } /* Does nothing before st_save() because st.SHIN == -1 */ cleanup_push(&st, st_restore); if (setintr) { pintr_disabled++; cleanup_push(&pintr_disabled, disabled_cleanup); } /* Save the current state and move us to a new state */ st_save(&st, unit, hflg, NULL, av); /* * Now if we are allowing commands to be interrupted, we let ourselves be * interrupted. */ if (setintr) { cleanup_until(&pintr_disabled); pintr_disabled++; cleanup_push(&pintr_disabled, disabled_cleanup); } process(0); /* 0 -> blow away on errors */ /* Restore the old state */ cleanup_until(&st); } /*ARGSUSED*/ void goodbye(Char **v, struct command *c) { USE(v); USE(c); record(); if (loginsh) { size_t omark; sigset_t set; sigemptyset(&set); signal(SIGQUIT, SIG_IGN); sigaddset(&set, SIGQUIT); sigprocmask(SIG_UNBLOCK, &set, NULL); signal(SIGINT, SIG_IGN); sigaddset(&set, SIGINT); signal(SIGTERM, SIG_IGN); sigaddset(&set, SIGTERM); signal(SIGHUP, SIG_IGN); sigaddset(&set, SIGHUP); sigprocmask(SIG_UNBLOCK, &set, NULL); phup_disabled = 1; setintr = 0; /* No interrupts after "logout" */ /* Trap errors inside .logout */ omark = cleanup_push_mark(); if (setexit() == 0) { if (!(adrof(STRlogout))) setcopy(STRlogout, STRnormal, VAR_READWRITE); #ifdef _PATH_DOTLOGOUT (void) srcfile(_PATH_DOTLOGOUT, 0, 0, NULL); #endif if (adrof(STRhome)) (void) srccat(varval(STRhome), STRsldtlogout); #ifdef TESLA do_logout = 1; #endif /* TESLA */ } cleanup_pop_mark(omark); } exitstat(); } void exitstat(void) { #ifdef PROF _mcleanup(); #endif /* * Note that if STATUS is corrupted (i.e. getn bombs) then error will exit * directly because we poke child here. Otherwise we might continue * unwarrantedly (sic). */ child = 1; xexit(getn(varval(STRstatus))); } /* * in the event of a HUP we want to save the history */ void phup(void) { + static int again = 0; + if (again++) + return; + if (loginsh) { setcopy(STRlogout, STRhangup, VAR_READWRITE); #ifdef _PATH_DOTLOGOUT (void) srcfile(_PATH_DOTLOGOUT, 0, 0, NULL); #endif if (adrof(STRhome)) (void) srccat(varval(STRhome), STRsldtlogout); } record(); #ifdef POSIXJOBS /* * We kill the last foreground process group. It then becomes * responsible to propagate the SIGHUP to its progeny. */ { struct process *pp, *np; for (pp = proclist.p_next; pp; pp = pp->p_next) { np = pp; /* * Find if this job is in the foreground. It could be that * the process leader has exited and the foreground flag * is cleared for it. */ do /* * If a process is in the foreground we try to kill * it's process group. If we succeed, then the * whole job is gone. Otherwise we keep going... * But avoid sending HUP to the shell again. */ if (((np->p_flags & PFOREGND) != 0) && np->p_jobid != shpgrp) { np->p_flags &= ~PHUP; if (killpg(np->p_jobid, SIGHUP) != -1) { /* In case the job was suspended... */ #ifdef SIGCONT (void) killpg(np->p_jobid, SIGCONT); #endif break; } } while ((np = np->p_friends) != pp); } } #endif /* POSIXJOBS */ xexit(SIGHUP); } static Char *jobargv[2] = {STRjobs, 0}; /* * Catch an interrupt, e.g. during lexical input. * If we are an interactive shell, we reset the interrupt catch * immediately. In any case we drain the shell output, * and finally go through the normal error mechanism, which * gets a chance to make the shell go away. */ int just_signaled; /* bugfix by Michael Bloom (mg@ttidca.TTI.COM) */ void pintr(void) { just_signaled = 1; pintr1(1); } void pintr1(int wantnl) { if (setintr) { if (pjobs) { pjobs = 0; xputchar('\n'); dojobs(jobargv, NULL); stderror(ERR_NAME | ERR_INTR); } } /* MH - handle interrupted completions specially */ { if (InsideCompletion) stderror(ERR_SILENT); } /* JV - Make sure we shut off inputl */ { (void) Cookedmode(); GettingInput = 0; if (evalvec) doneinp = 1; } drainoline(); #ifdef HAVE_GETPWENT (void) endpwent(); #endif /* * If we have an active "onintr" then we search for the label. Note that if * one does "onintr -" then we shan't be interruptible so we needn't worry * about that here. */ if (gointr) { gotolab(gointr); reset(); } else if (intty && wantnl) { if (editing) { /* * If we are editing a multi-line input command, and move to * the beginning of the line, we don't want to trash it when * we hit ^C */ PastBottom(); ClearLines(); ClearDisp(); } else { /* xputchar('\n'); *//* Some like this, others don't */ (void) putraw('\r'); (void) putraw('\n'); } } stderror(ERR_SILENT); } /* * Process is the main driving routine for the shell. * It runs all command processing, except for those within { ... } * in expressions (which is run by a routine evalav in sh.exp.c which * is a stripped down process), and `...` evaluation which is run * also by a subset of this code in sh.glob.c in the routine backeval. * * The code here is a little strange because part of it is interruptible * and hence freeing of structures appears to occur when none is necessary * if this is ignored. * * Note that if catch is not set then we will unwind on any error. * If an end-of-file occurs, we return. */ void process(int catch) { jmp_buf_t osetexit; /* PWP: This might get nuked by longjmp so don't make it a register var */ size_t omark; volatile int didexitset = 0; getexit(osetexit); omark = cleanup_push_mark(); for (;;) { struct command *t; int hadhist, old_pintr_disabled; (void)setexit(); if (didexitset == 0) { exitset++; didexitset++; } pendjob(); justpr = enterhist; /* execute if not entering history */ if (haderr) { if (!catch) { /* unwind */ doneinp = 0; cleanup_pop_mark(omark); resexit(osetexit); reset(); } haderr = 0; /* * Every error is eventually caught here or the shell dies. It is * at this point that we clean up any left-over open files, by * closing all but a fixed number of pre-defined files. Thus * routines don't have to worry about leaving files open due to * deeper errors... they will get closed here. */ closem(); continue; } if (doneinp) { doneinp = 0; break; } if (chkstop) chkstop--; if (neednote) pnote(); if (intty && prompt && evalvec == 0) { just_signaled = 0; mailchk(); /* * Watch for logins/logouts. Next is scheduled commands stored * previously using "sched." Then execute periodic commands. * Following that, the prompt precmd is run. */ #ifndef HAVENOUTMP watch_login(0); #endif /* !HAVENOUTMP */ sched_run(); period_cmd(); precmd(); /* * If we are at the end of the input buffer then we are going to * read fresh stuff. Otherwise, we are rereading input and don't * need or want to prompt. */ if (fseekp == feobp && aret == TCSH_F_SEEK) printprompt(0, NULL); flush(); setalarm(1); } if (seterr) { xfree(seterr); seterr = NULL; } /* * Interruptible during interactive reads */ if (setintr) pintr_push_enable(&old_pintr_disabled); freelex(¶ml); hadhist = lex(¶ml); if (setintr) cleanup_until(&old_pintr_disabled); cleanup_push(¶ml, lex_cleanup); /* * Echo not only on VERBOSE, but also with history expansion. If there * is a lexical error then we forego history echo. * Do not echo if we're only entering history (source -h). */ if ((hadhist && !seterr && intty && !tellwhat && !Expand && !whyles) || (!enterhist && adrof(STRverbose))) { int odidfds = didfds; haderr = 1; didfds = 0; prlex(¶ml); flush(); haderr = 0; didfds = odidfds; } (void) alarm(0); /* Autologout OFF */ alrmcatch_disabled = 1; /* * Save input text on the history list if reading in old history, or it * is from the terminal at the top level and not in a loop. * * PWP: entry of items in the history list while in a while loop is done * elsewhere... */ if (enterhist || (catch && intty && !whyles && !tellwhat && !arun)) savehist(¶ml, enterhist > 1); if (Expand && seterr) Expand = 0; /* * Print lexical error messages, except when sourcing history lists. */ if (!enterhist && seterr) stderror(ERR_OLD); /* * If had a history command :p modifier then this is as far as we * should go */ if (justpr) goto cmd_done; /* * If had a tellwhat from twenex() then do */ if (tellwhat) { (void) tellmewhat(¶ml, NULL); goto cmd_done; } alias(¶ml); #ifdef BSDJOBS /* * If we are interactive, try to continue jobs that we have stopped */ if (prompt) continue_jobs(¶ml); #endif /* BSDJOBS */ /* * Check to see if the user typed "rm * .o" or something */ if (prompt) rmstar(¶ml); /* * Parse the words of the input into a parse tree. */ t = syntax(paraml.next, ¶ml, 0); /* * We cannot cleanup push here, because cd /blah; echo foo * would rewind t on the chdir error, and free the rest of the command */ if (seterr) { freesyn(t); stderror(ERR_OLD); } postcmd(); /* * Execute the parse tree From: Michael Schroeder * was execute(t, tpgrp); */ execute(t, (tpgrp > 0 ? tpgrp : -1), NULL, NULL, TRUE); freesyn(t); /* * Made it! */ #ifdef SIG_WINDOW if (windowchg || (catch && intty && !whyles && !tellwhat)) { (void) check_window_size(0); /* for window systems */ } #endif /* SIG_WINDOW */ setcopy(STR_, InputBuf, VAR_READWRITE | VAR_NOGLOB); cmd_done: if (cleanup_reset()) cleanup_until(¶ml); else haderr = 1; } cleanup_pop_mark(omark); resexit(osetexit); exitset--; handle_pending_signals(); } /*ARGSUSED*/ void dosource(Char **t, struct command *c) { Char *f; int hflg = 0; char *file; USE(c); t++; if (*t && eq(*t, STRmh)) { if (*++t == NULL) stderror(ERR_NAME | ERR_HFLAG); hflg++; } else if (*t && eq(*t, STRmm)) { if (*++t == NULL) stderror(ERR_NAME | ERR_MFLAG); hflg = 2; } f = globone(*t++, G_ERROR); file = strsave(short2str(f)); cleanup_push(file, xfree); xfree(f); t = glob_all_or_error(t); cleanup_push(t, blk_cleanup); if ((!srcfile(file, 0, hflg, t)) && (!hflg) && (!bequiet)) stderror(ERR_SYSTEM, file, strerror(errno)); cleanup_until(file); } /* * Check for mail. * If we are a login shell, then we don't want to tell * about any mail file unless its been modified * after the time we started. * This prevents us from telling the user things he already * knows, since the login program insists on saying * "You have mail." */ /* * The AMS version. * This version checks if the file is a directory, and if so, * tells you the number of files in it, otherwise do the old thang. * The magic "+1" in the time calculation is to compensate for * an AFS bug where directory mtimes are set to 1 second in * the future. */ static void mailchk(void) { struct varent *v; Char **vp; time_t t; int intvl, cnt; struct stat stb; int new; v = adrof(STRmail); if (v == NULL || v->vec == NULL) return; (void) time(&t); vp = v->vec; cnt = blklen(vp); intvl = (cnt && number(*vp)) ? (--cnt, getn(*vp++)) : MAILINTVL; if (intvl < 1) intvl = 1; if (chktim + intvl > t) return; for (; *vp; vp++) { char *filename = short2str(*vp); char *mboxdir = filename; if (stat(filename, &stb) < 0) continue; #if defined(BSDTIMES) || defined(_SEQUENT_) new = stb.st_mtime > time0.tv_sec; #else new = stb.st_mtime > seconds0; #endif if (S_ISDIR(stb.st_mode)) { DIR *mailbox; int mailcount = 0; char *tempfilename; struct stat stc; tempfilename = xasprintf("%s/new", filename); if (stat(tempfilename, &stc) != -1 && S_ISDIR(stc.st_mode)) { /* * "filename/new" exists and is a directory; you are * using Qmail. */ stb = stc; #if defined(BSDTIMES) || defined(_SEQUENT_) new = stb.st_mtime > time0.tv_sec; #else new = stb.st_mtime > seconds0; #endif mboxdir = tempfilename; } if (stb.st_mtime <= chktim + 1 || (loginsh && !new)) { xfree(tempfilename); continue; } mailbox = opendir(mboxdir); xfree(tempfilename); if (mailbox == NULL) continue; /* skip . and .. */ if (!readdir(mailbox) || !readdir(mailbox)) { (void)closedir(mailbox); continue; } while (readdir(mailbox)) mailcount++; (void)closedir(mailbox); if (mailcount == 0) continue; if (cnt == 1) xprintf(CGETS(11, 3, "You have %d mail messages.\n"), mailcount); else xprintf(CGETS(11, 4, "You have %d mail messages in %s.\n"), mailcount, filename); } else { char *type; if (stb.st_size == 0 || stb.st_atime >= stb.st_mtime || (stb.st_atime <= chktim && stb.st_mtime <= chktim) || (loginsh && !new)) continue; type = strsave(new ? CGETS(11, 6, "new ") : ""); cleanup_push(type, xfree); if (cnt == 1) xprintf(CGETS(11, 5, "You have %smail.\n"), type); else xprintf(CGETS(11, 7, "You have %smail in %s.\n"), type, filename); cleanup_until(type); } } chktim = t; } /* * Extract a home directory from the password file * The argument points to a buffer where the name of the * user whose home directory is sought is currently. * We return home directory of the user, or NULL. */ Char * gethdir(const Char *home) { Char *h; /* * Is it us? */ if (*home == '\0') { if ((h = varval(STRhome)) != STRNULL) return Strsave(h); else return NULL; } /* * Look in the cache */ if ((h = gettilde(home)) == NULL) return NULL; else return Strsave(h); } /* * Move the initial descriptors to their eventual * resting places, closing all other units. */ void initdesc(void) { #ifdef NLS_BUGS #ifdef NLS_CATALOGS nlsclose(); #endif /* NLS_CATALOGS */ #endif /* NLS_BUGS */ didfds = 0; /* 0, 1, 2 aren't set up */ (void) close_on_exec(SHIN = dcopy(0, FSHIN), 1); (void) close_on_exec(SHOUT = dcopy(1, FSHOUT), 1); (void) close_on_exec(SHDIAG = dcopy(2, FSHDIAG), 1); (void) close_on_exec(OLDSTD = dcopy(SHIN, FOLDSTD), 1); #ifndef CLOSE_ON_EXEC didcch = 0; /* Havent closed for child */ #endif /* CLOSE_ON_EXEC */ if (SHDIAG >= 0) isdiagatty = isatty(SHDIAG); else isdiagatty = 0; if (SHDIAG >= 0) isoutatty = isatty(SHOUT); else isoutatty = 0; #ifdef NLS_BUGS #ifdef NLS_CATALOGS nlsinit(); #endif /* NLS_CATALOGS */ #endif /* NLS_BUGS */ } void #ifdef PROF done(int i) #else xexit(int i) #endif { #ifdef TESLA if (loginsh && do_logout) { /* this is to send hangup signal to the develcon */ /* we toggle DTR. clear dtr - sleep 1 - set dtr */ /* ioctl will return ENOTTY for pty's but we ignore it */ /* exitstat will run after disconnect */ /* we sleep for 2 seconds to let things happen in */ /* .logout and rechist() */ #ifdef TIOCCDTR (void) sleep(2); (void) ioctl(FSHTTY, TIOCCDTR, NULL); (void) sleep(1); (void) ioctl(FSHTTY, TIOCSDTR, NULL); #endif /* TIOCCDTR */ } #endif /* TESLA */ { struct process *pp, *np; pid_t mypid = getpid(); /* Kill all processes marked for hup'ing */ for (pp = proclist.p_next; pp; pp = pp->p_next) { np = pp; do if ((np->p_flags & PHUP) && np->p_jobid != shpgrp && np->p_parentid == mypid) { if (killpg(np->p_jobid, SIGHUP) != -1) { /* In case the job was suspended... */ #ifdef SIGCONT (void) killpg(np->p_jobid, SIGCONT); #endif break; } } while ((np = np->p_friends) != pp); } } untty(); #ifdef NLS_CATALOGS /* * We need to call catclose, because SVR4 leaves symlinks behind otherwise * in the catalog directories. We cannot close on a vforked() child, * because messages will stop working on the parent too. */ if (child == 0) nlsclose(); #endif /* NLS_CATALOGS */ #ifdef WINNT_NATIVE nt_cleanup(); #endif /* WINNT_NATIVE */ _exit(i); } #ifndef _PATH_DEFPATH static Char ** defaultpath(void) { char *ptr; Char **blk, **blkp; struct stat stb; blkp = blk = xmalloc(sizeof(Char *) * 10); #ifndef NODOT # ifndef DOTLAST *blkp++ = Strsave(STRdot); # endif #endif #define DIRAPPEND(a) \ if (stat(ptr = a, &stb) == 0 && S_ISDIR(stb.st_mode)) \ *blkp++ = SAVE(ptr) #ifdef _PATH_LOCAL DIRAPPEND(_PATH_LOCAL); #endif #ifdef _PATH_USRUCB DIRAPPEND(_PATH_USRUCB); #endif #ifdef _PATH_USRBSD DIRAPPEND(_PATH_USRBSD); #endif #ifdef _PATH_BIN DIRAPPEND(_PATH_BIN); #endif #ifdef _PATH_USRBIN DIRAPPEND(_PATH_USRBIN); #endif #undef DIRAPPEND #ifndef NODOT # ifdef DOTLAST *blkp++ = Strsave(STRdot); # endif #endif *blkp = NULL; return (blk); } #endif static void record(void) { + static int again = 0; + int ophup_disabled; + + if (again++) + return; + + ophup_disabled = phup_disabled; + phup_disabled = 1; if (!fast) { recdirs(NULL, adrof(STRsavedirs) != NULL); rechist(NULL, adrof(STRsavehist) != NULL); } displayHistStats("Exiting"); /* no-op unless DEBUG_HIST */ + phup_disabled = ophup_disabled; } /* * Grab the tty repeatedly, and give up if we are not in the correct * tty process group. */ int grabpgrp(int fd, pid_t desired) { struct sigaction old; pid_t pgrp; size_t i; for (i = 0; i < 100; i++) { if ((pgrp = tcgetpgrp(fd)) == -1) return -1; if (pgrp == desired) return 0; (void)sigaction(SIGTTIN, NULL, &old); (void)signal(SIGTTIN, SIG_DFL); (void)kill(0, SIGTTIN); (void)sigaction(SIGTTIN, &old, NULL); } errno = EPERM; return -1; } diff --git a/contrib/tcsh/sh.dir.c b/contrib/tcsh/sh.dir.c index 4d6a1de25ab3..f57e9950af36 100644 --- a/contrib/tcsh/sh.dir.c +++ b/contrib/tcsh/sh.dir.c @@ -1,1416 +1,1423 @@ /* * sh.dir.c: Directory manipulation functions */ /*- * Copyright (c) 1980, 1991 The Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include "sh.h" #include "ed.h" /* * C Shell - directory management */ static Char *agetcwd (void); static void dstart (const char *); static struct directory *dfind (Char *); static Char *dfollow (Char *, int); static void printdirs (int); static Char *dgoto (Char *); static void dnewcwd (struct directory *, int); static void dset (Char *); static void dextract (struct directory *); static int skipargs (Char ***, const char *, const char *); static void dgetstack (void); +static Char *dcanon_internal(Char *, Char *); static struct directory dhead INIT_ZERO_STRUCT; /* "head" of loop */ static int printd; /* force name to be printed */ int bequiet = 0; /* do not print dir stack -strike */ static Char * agetcwd(void) { char *buf; Char *cwd; size_t len; len = MAXPATHLEN; buf = xmalloc(len); while (getcwd(buf, len) == NULL) { int err; err = errno; if (err != ERANGE) { xfree(buf); errno = err; return NULL; } len *= 2; buf = xrealloc(buf, len); } if (*buf == '\0') { xfree(buf); return NULL; } cwd = SAVE(buf); xfree(buf); return cwd; } static void dstart(const char *from) { xprintf(CGETS(12, 1, "%s: Trying to start from \"%s\"\n"), progname, from); } /* * dinit - initialize current working directory */ void dinit(Char *hp) { Char *cp, *tcp; struct directory *dp; /* Don't believe the login shell home, because it may be a symlink */ tcp = agetcwd(); if (tcp == NULL) { xprintf("%s: %s\n", progname, strerror(errno)); if (hp && *hp) { char *xcp = short2str(hp); dstart(xcp); if (chdir(xcp) == -1) cp = NULL; else cp = Strsave(hp); } else cp = NULL; if (cp == NULL) { dstart("/"); if (chdir("/") == -1) /* I am not even try to print an error message! */ xexit(1); cp = SAVE("/"); } } else { #ifdef S_IFLNK struct stat swd, shp; int swd_ok; swd_ok = stat(short2str(tcp), &swd) == 0; /* * See if $HOME is the working directory we got and use that */ if (swd_ok && hp && *hp && stat(short2str(hp), &shp) != -1 && DEV_DEV_COMPARE(swd.st_dev, shp.st_dev) && swd.st_ino == shp.st_ino) cp = Strsave(hp); else { char *cwd; /* * use PWD if we have it (for subshells) */ if (swd_ok && (cwd = getenv("PWD")) != NULL) { if (stat(cwd, &shp) != -1 && DEV_DEV_COMPARE(swd.st_dev, shp.st_dev) && swd.st_ino == shp.st_ino) { tcp = SAVE(cwd); cleanup_push(tcp, xfree); } } - cleanup_push(tcp, xfree); cp = dcanon(tcp, STRNULL); - cleanup_ignore(tcp); - cleanup_until(tcp); } #else /* S_IFLNK */ - cleanup_push(tcp, xfree); cp = dcanon(tcp, STRNULL); - cleanup_ignore(tcp); - cleanup_until(tcp); #endif /* S_IFLNK */ } dp = xcalloc(sizeof(struct directory), 1); dp->di_name = cp; dp->di_count = 0; dhead.di_next = dhead.di_prev = dp; dp->di_next = dp->di_prev = &dhead; printd = 0; dnewcwd(dp, 0); setcopy(STRdirstack, dp->di_name, VAR_READWRITE|VAR_NOGLOB); } static void dset(Char *dp) { /* * Don't call set() directly cause if the directory contains ` or * other junk characters glob will fail. */ setcopy(STRowd, varval(STRcwd), VAR_READWRITE|VAR_NOGLOB); setcopy(STRcwd, dp, VAR_READWRITE|VAR_NOGLOB); tsetenv(STRPWD, dp); } #define DIR_PRINT 0x01 /* -p */ #define DIR_LONG 0x02 /* -l */ #define DIR_VERT 0x04 /* -v */ #define DIR_LINE 0x08 /* -n */ #define DIR_SAVE 0x10 /* -S */ #define DIR_LOAD 0x20 /* -L */ #define DIR_CLEAR 0x40 /* -c */ #define DIR_OLD 0x80 /* - */ static int skipargs(Char ***v, const char *dstr, const char *str) { Char **n = *v, *s; int dflag = 0, loop = 1; for (n++; loop && *n != NULL && (*n)[0] == '-'; n++) if (*(s = &((*n)[1])) == '\0') /* test for bare "-" argument */ dflag |= DIR_OLD; else if ((*n)[1] == '-' && (*n)[2] == '\0') { /* test for -- */ n++; break; } else { char *p; while (*s != '\0') /* examine flags */ { if ((p = strchr(dstr, *s++)) != NULL) dflag |= (1 << (p - dstr)); else stderror(ERR_DIRUS, short2str(**v), dstr, str); } } if (*n && (dflag & DIR_OLD)) stderror(ERR_DIRUS, short2str(**v), dstr, str); *v = n; /* make -l, -v, and -n imply -p */ if (dflag & (DIR_LONG|DIR_VERT|DIR_LINE)) dflag |= DIR_PRINT; return dflag; } /* * dodirs - list all directories in directory loop */ /*ARGSUSED*/ void dodirs(Char **v, struct command *c) { static const char flags[] = "plvnSLc"; int dflag = skipargs(&v, flags, ""); USE(c); if ((dflag & DIR_CLEAR) != 0) { struct directory *dp, *fdp; for (dp = dcwd->di_next; dp != dcwd; ) { fdp = dp; dp = dp->di_next; if (fdp != &dhead) dfree(fdp); } dhead.di_next = dhead.di_prev = dp; dp->di_next = dp->di_prev = &dhead; } if ((dflag & DIR_LOAD) != 0) loaddirs(*v); else if ((dflag & DIR_SAVE) != 0) recdirs(*v, 1); if (*v && (dflag & (DIR_SAVE|DIR_LOAD))) v++; if (*v != NULL || (dflag & DIR_OLD)) stderror(ERR_DIRUS, "dirs", flags, ""); if ((dflag & (DIR_CLEAR|DIR_LOAD|DIR_SAVE)) == 0 || (dflag & DIR_PRINT)) printdirs(dflag); } static void printdirs(int dflag) { struct directory *dp; Char *s, *user; int idx, len, cur; dp = dcwd; idx = 0; cur = 0; do { if (dp == &dhead) continue; if (dflag & DIR_VERT) { xprintf("%d\t", idx++); cur = 0; } s = dp->di_name; user = NULL; if (!(dflag & DIR_LONG) && (user = getusername(&s)) != NULL) len = (int) (Strlen(user) + Strlen(s) + 2); else len = (int) (Strlen(s) + 1); cur += len; if ((dflag & DIR_LINE) && cur >= TermH - 1 && len < TermH) { xputchar('\n'); cur = len; } if (user) xprintf("~%S", user); xprintf("%-S%c", s, (dflag & DIR_VERT) ? '\n' : ' '); } while ((dp = dp->di_prev) != dcwd); if (!(dflag & DIR_VERT)) xputchar('\n'); } void dtildepr(Char *dir) { Char* user; if ((user = getusername(&dir)) != NULL) xprintf("~%-S%S", user, dir); else xprintf("%S", dir); } void dtilde(void) { struct directory *d = dcwd; do { if (d == &dhead) continue; - d->di_name = dcanon(d->di_name, STRNULL); + d->di_name = dcanon_internal(d->di_name, STRNULL); } while ((d = d->di_prev) != dcwd); dset(dcwd->di_name); } /* dnormalize(): * The path will be normalized if it * 1) is "..", * 2) or starts with "../", * 3) or ends with "/..", * 4) or contains the string "/../", * then it will be normalized, unless those strings are quoted. * Otherwise, a copy is made and sent back. */ Char * dnormalize(const Char *cp, int expnd) { /* return true if dp is of the form "../xxx" or "/../xxx" */ #define IS_DOTDOT(sp, p) (ISDOTDOT(p) && ((p) == (sp) || *((p) - 1) == '/')) #define IS_DOT(sp, p) (ISDOT(p) && ((p) == (sp) || *((p) - 1) == '/')) #ifdef S_IFLNK if (expnd) { struct Strbuf buf = Strbuf_INIT; int dotdot = 0; Char *dp, *cwd; const Char *start = cp; # ifdef HAVE_SLASHSLASH int slashslash; # endif /* HAVE_SLASHSLASH */ /* * count the number of "../xxx" or "xxx/../xxx" in the path */ for ( ; *cp && *(cp + 1); cp++) if (IS_DOTDOT(start, cp)) dotdot++; /* * if none, we are done. */ if (dotdot == 0) return (Strsave(start)); # ifdef notdef struct stat sb; /* * We disable this test because: * cd /tmp; mkdir dir1 dir2; cd dir2; ln -s /tmp/dir1; cd dir1; * echo ../../dir1 does not expand. We had enabled this before * because it was bothering people with expansions in compilation * lines like -I../../foo. Maybe we need some kind of finer grain * control? * * If the path doesn't exist, we are done too. */ if (lstat(short2str(start), &sb) != 0 && errno == ENOENT) return (Strsave(start)); # endif cwd = xmalloc((Strlen(dcwd->di_name) + 3) * sizeof(Char)); (void) Strcpy(cwd, dcwd->di_name); /* * If the path starts with a slash, we are not relative to * the current working directory. */ if (ABSOLUTEP(start)) *cwd = '\0'; # ifdef HAVE_SLASHSLASH slashslash = cwd[0] == '/' && cwd[1] == '/'; # endif /* HAVE_SLASHSLASH */ /* * Ignore . and count ..'s */ cp = start; do { dotdot = 0; buf.len = 0; while (*cp) if (IS_DOT(start, cp)) { if (*++cp) cp++; } else if (IS_DOTDOT(start, cp)) { if (buf.len != 0) break; /* finish analyzing .././../xxx/[..] */ dotdot++; cp += 2; if (*cp) cp++; } else Strbuf_append1(&buf, *cp++); Strbuf_terminate(&buf); while (dotdot > 0) if ((dp = Strrchr(cwd, '/')) != NULL) { # ifdef HAVE_SLASHSLASH if (dp == &cwd[1]) slashslash = 1; # endif /* HAVE_SLASHSLASH */ *dp = '\0'; dotdot--; } else break; if (!*cwd) { /* too many ..'s, starts with "/" */ cwd[0] = '/'; # ifdef HAVE_SLASHSLASH /* * Only append another slash, if already the former cwd * was in a double-slash path. */ cwd[1] = slashslash ? '/' : '\0'; cwd[2] = '\0'; # else /* !HAVE_SLASHSLASH */ cwd[1] = '\0'; # endif /* HAVE_SLASHSLASH */ } # ifdef HAVE_SLASHSLASH else if (slashslash && cwd[1] == '\0') { cwd[1] = '/'; cwd[2] = '\0'; } # endif /* HAVE_SLASHSLASH */ if (buf.len != 0) { size_t i; i = Strlen(cwd); if (TRM(cwd[i - 1]) != '/') { cwd[i++] = '/'; cwd[i] = '\0'; } dp = Strspl(cwd, TRM(buf.s[0]) == '/' ? &buf.s[1] : buf.s); xfree(cwd); cwd = dp; i = Strlen(cwd) - 1; if (TRM(cwd[i]) == '/') cwd[i] = '\0'; } /* Reduction of ".." following the stuff we collected in buf * only makes sense if the directory item in buf really exists. * Avoid reduction of "-I../.." (typical compiler call) to "" * or "/usr/nonexistant/../bin" to "/usr/bin": */ if (cwd[0]) { struct stat exists; if (0 != stat(short2str(cwd), &exists)) { xfree(buf.s); xfree(cwd); return Strsave(start); } } } while (*cp != '\0'); xfree(buf.s); return cwd; } #endif /* S_IFLNK */ return Strsave(cp); } /* * dochngd - implement chdir command. */ /*ARGSUSED*/ void dochngd(Char **v, struct command *c) { Char *cp; struct directory *dp; int dflag = skipargs(&v, "plvn", "[-|]"); USE(c); printd = 0; cp = (dflag & DIR_OLD) ? varval(STRowd) : *v; if (cp == NULL) { if (!cdtohome) stderror(ERR_NAME | ERR_TOOFEW); else if ((cp = varval(STRhome)) == STRNULL || *cp == 0) stderror(ERR_NAME | ERR_NOHOMEDIR); if (chdir(short2str(cp)) < 0) stderror(ERR_NAME | ERR_CANTCHANGE); cp = Strsave(cp); } else if ((dflag & DIR_OLD) == 0 && v[1] != NULL) { stderror(ERR_NAME | ERR_TOOMANY); /* NOTREACHED */ return; } else if ((dp = dfind(cp)) != 0) { char *tmp; printd = 1; if (chdir(tmp = short2str(dp->di_name)) < 0) stderror(ERR_SYSTEM, tmp, strerror(errno)); dcwd->di_prev->di_next = dcwd->di_next; dcwd->di_next->di_prev = dcwd->di_prev; dfree(dcwd); dnewcwd(dp, dflag); return; } else if ((cp = dfollow(cp, dflag & DIR_OLD)) == NULL) return; dp = xcalloc(sizeof(struct directory), 1); dp->di_name = cp; dp->di_count = 0; dp->di_next = dcwd->di_next; dp->di_prev = dcwd->di_prev; dp->di_prev->di_next = dp; dp->di_next->di_prev = dp; dfree(dcwd); dnewcwd(dp, dflag); } static Char * dgoto(Char *cp) { Char *dp, *ret; if (!ABSOLUTEP(cp)) { Char *p, *q; size_t cwdlen; cwdlen = Strlen(dcwd->di_name); if (cwdlen == 1) /* root */ cwdlen = 0; dp = xmalloc((cwdlen + Strlen(cp) + 2) * sizeof(Char)); for (p = dp, q = dcwd->di_name; (*p++ = *q++) != '\0';) continue; if (cwdlen) p[-1] = '/'; else p--; /* don't add a / after root */ Strcpy(p, cp); xfree(cp); cp = dp; dp += cwdlen; } else dp = cp; #if defined(WINNT_NATIVE) return agetcwd(); #elif defined(__CYGWIN__) if (ABSOLUTEP(cp) && cp[1] == ':') { /* Only DOS paths are treated that way */ return agetcwd(); } else { - cleanup_push(cp, xfree); ret = dcanon(cp, dp); - cleanup_ignore(cp); - cleanup_until(cp); } #else /* !WINNT_NATIVE */ - cleanup_push(cp, xfree); ret = dcanon(cp, dp); - cleanup_ignore(cp); - cleanup_until(cp); #endif /* WINNT_NATIVE */ return ret; } /* * dfollow - change to arg directory; fall back on cdpath if not valid */ static Char * dfollow(Char *cp, int old) { Char *dp; struct varent *c; int serrno; cp = old ? Strsave(cp) : globone(cp, G_ERROR); cleanup_push(cp, xfree); #ifdef apollo if (Strchr(cp, '`')) { char *dptr; if (chdir(dptr = short2str(cp)) < 0) stderror(ERR_SYSTEM, dptr, strerror(errno)); dp = agetcwd(); cleanup_push(dp, xfree); if (dp != NULL) { cleanup_until(cp); return dgoto(dp); } else stderror(ERR_SYSTEM, dptr, strerror(errno)); } #endif /* apollo */ /* * if we are ignoring symlinks, try to fix relatives now. * if we are expading symlinks, it should be done by now. */ dp = dnormalize(cp, symlinks == SYM_IGNORE); if (chdir(short2str(dp)) >= 0) { cleanup_until(cp); return dgoto(dp); } else { xfree(dp); if (chdir(short2str(cp)) >= 0) { cleanup_ignore(cp); cleanup_until(cp); return dgoto(cp); } else if (errno != ENOENT && errno != ENOTDIR) { int err; err = errno; stderror(ERR_SYSTEM, short2str(cp), strerror(err)); } serrno = errno; } if (cp[0] != '/' && !prefix(STRdotsl, cp) && !prefix(STRdotdotsl, cp) && (c = adrof(STRcdpath)) && c->vec != NULL) { struct Strbuf buf = Strbuf_INIT; Char **cdp; for (cdp = c->vec; *cdp; cdp++) { size_t len = Strlen(*cdp); buf.len = 0; if (len > 0) { Strbuf_append(&buf, *cdp); if ((*cdp)[len - 1] != '/') Strbuf_append1(&buf, '/'); } Strbuf_append(&buf, cp); Strbuf_terminate(&buf); /* * We always want to fix the directory here * If we are normalizing symlinks */ dp = dnormalize(buf.s, symlinks == SYM_IGNORE || symlinks == SYM_EXPAND); if (chdir(short2str(dp)) >= 0) { printd = 1; xfree(buf.s); cleanup_until(cp); return dgoto(dp); } else if (chdir(short2str(cp)) >= 0) { printd = 1; xfree(dp); xfree(buf.s); cleanup_ignore(cp); cleanup_until(cp); return dgoto(cp); } xfree(dp); } xfree(buf.s); } dp = varval(cp); if ((dp[0] == '/' || dp[0] == '.') && chdir(short2str(dp)) >= 0) { cleanup_until(cp); cp = Strsave(dp); printd = 1; return dgoto(cp); } /* * on login source of ~/.cshdirs, errors are eaten. the dir stack is all * directories we could get to. */ if (!bequiet) stderror(ERR_SYSTEM, short2str(cp), strerror(serrno)); cleanup_until(cp); return (NULL); } /* * dopushd - push new directory onto directory stack. * with no arguments exchange top and second. * with numeric argument (+n) bring it to top. */ /*ARGSUSED*/ void dopushd(Char **v, struct command *c) { struct directory *dp; Char *cp; int dflag = skipargs(&v, "plvn", " [-||+]"); USE(c); printd = 1; cp = (dflag & DIR_OLD) ? varval(STRowd) : *v; if (cp == NULL) { if (adrof(STRpushdtohome)) { if ((cp = varval(STRhome)) == STRNULL || *cp == 0) stderror(ERR_NAME | ERR_NOHOMEDIR); if (chdir(short2str(cp)) < 0) stderror(ERR_NAME | ERR_CANTCHANGE); if ((cp = dfollow(cp, dflag & DIR_OLD)) == NULL) return; dp = xcalloc(sizeof(struct directory), 1); dp->di_name = cp; dp->di_count = 0; dp->di_prev = dcwd; dp->di_next = dcwd->di_next; dcwd->di_next = dp; dp->di_next->di_prev = dp; } else { char *tmp; if ((dp = dcwd->di_prev) == &dhead) dp = dhead.di_prev; if (dp == dcwd) stderror(ERR_NAME | ERR_NODIR); if (chdir(tmp = short2str(dp->di_name)) < 0) stderror(ERR_SYSTEM, tmp, strerror(errno)); dp->di_prev->di_next = dp->di_next; dp->di_next->di_prev = dp->di_prev; dp->di_next = dcwd->di_next; dp->di_prev = dcwd; dcwd->di_next->di_prev = dp; dcwd->di_next = dp; } } else if ((dflag & DIR_OLD) == 0 && v[1] != NULL) { stderror(ERR_NAME | ERR_TOOMANY); /* NOTREACHED */ return; } else if ((dp = dfind(cp)) != NULL) { char *tmp; if (chdir(tmp = short2str(dp->di_name)) < 0) stderror(ERR_SYSTEM, tmp, strerror(errno)); /* * kfk - 10 Feb 1984 - added new "extraction style" pushd +n */ if (adrof(STRdextract)) dextract(dp); } else { Char *ccp; if ((ccp = dfollow(cp, dflag & DIR_OLD)) == NULL) return; dp = xcalloc(sizeof(struct directory), 1); dp->di_name = ccp; dp->di_count = 0; dp->di_prev = dcwd; dp->di_next = dcwd->di_next; dcwd->di_next = dp; dp->di_next->di_prev = dp; } dnewcwd(dp, dflag); } /* * dfind - find a directory if specified by numeric (+n) argument */ static struct directory * dfind(Char *cp) { struct directory *dp; int i; Char *ep; if (*cp++ != '+') return (0); for (ep = cp; Isdigit(*ep); ep++) continue; if (*ep) return (0); i = getn(cp); if (i <= 0) return (0); for (dp = dcwd; i != 0; i--) { if ((dp = dp->di_prev) == &dhead) dp = dp->di_prev; if (dp == dcwd) stderror(ERR_NAME | ERR_DEEP); } return (dp); } /* * dopopd - pop a directory out of the directory stack * with a numeric argument just discard it. */ /*ARGSUSED*/ void dopopd(Char **v, struct command *c) { Char *cp; struct directory *dp, *p = NULL; int dflag = skipargs(&v, "plvn", " [-|+]"); USE(c); printd = 1; cp = (dflag & DIR_OLD) ? varval(STRowd) : *v; if (cp == NULL) dp = dcwd; else if ((dflag & DIR_OLD) == 0 && v[1] != NULL) { stderror(ERR_NAME | ERR_TOOMANY); /* NOTREACHED */ return; } else if ((dp = dfind(cp)) == 0) stderror(ERR_NAME | ERR_BADDIR); if (dp->di_prev == &dhead && dp->di_next == &dhead) stderror(ERR_NAME | ERR_EMPTY); if (dp == dcwd) { char *tmp; if ((p = dp->di_prev) == &dhead) p = dhead.di_prev; if (chdir(tmp = short2str(p->di_name)) < 0) stderror(ERR_SYSTEM, tmp, strerror(errno)); } dp->di_prev->di_next = dp->di_next; dp->di_next->di_prev = dp->di_prev; dfree(dp); if (dp == dcwd) { dnewcwd(p, dflag); } else { printdirs(dflag); } } /* * dfree - free the directory (or keep it if it still has ref count) */ void dfree(struct directory *dp) { if (dp->di_count != 0) { dp->di_next = dp->di_prev = 0; } else { xfree(dp->di_name); xfree(dp); } } /* - * dcanon - canonicalize the pathname, removing excess ./ and ../ etc. + * dcanon - a safe version of dcanon_internal that arranges for cleanup + */ +Char * +dcanon(Char *cp, Char *p) +{ + cleanup_push(cp, xfree); + p = dcanon_internal(cp, p); + // coverity[use_after_free] we use the pointer as a marker + cleanup_ignore(cp); + cleanup_until(cp); + return p; +} + +/* + * dcanon_internal - canonicalize the pathname, removing excess ./ and ../ etc. * we are of course assuming that the file system is standardly * constructed (always have ..'s, directories have links) */ -Char * -dcanon(Char *cp, Char *p) +static Char * +dcanon_internal(Char *cp, Char *p) { Char *sp; Char *p1, *p2; /* general purpose */ int slash; #ifdef HAVE_SLASHSLASH int slashslash; #endif /* HAVE_SLASHSLASH */ size_t clen; #ifdef S_IFLNK /* if we have symlinks */ Char *mlink, *newcp; char *tlink; size_t cc; #endif /* S_IFLNK */ clen = Strlen(cp); /* * christos: if the path given does not start with a slash prepend cwd. If * cwd does not start with a slash or the result would be too long try to * correct it. */ if (!ABSOLUTEP(cp)) { Char *tmpdir; size_t len; p1 = varval(STRcwd); if (p1 == STRNULL || !ABSOLUTEP(p1)) { Char *new_cwd = agetcwd(); if (new_cwd == NULL) { xprintf("%s: %s\n", progname, strerror(errno)); setcopy(STRcwd, str2short("/"), VAR_READWRITE|VAR_NOGLOB); } else setv(STRcwd, new_cwd, VAR_READWRITE|VAR_NOGLOB); p1 = varval(STRcwd); } len = Strlen(p1); tmpdir = xmalloc((len + clen + 2) * sizeof (*tmpdir)); (void) Strcpy(tmpdir, p1); (void) Strcat(tmpdir, STRslash); (void) Strcat(tmpdir, cp); xfree(cp); cp = p = tmpdir; } #ifdef HAVE_SLASHSLASH slashslash = (cp[0] == '/' && cp[1] == '/'); #endif /* HAVE_SLASHSLASH */ while (*p) { /* for each component */ sp = p; /* save slash address */ while (*++p == '/') /* flush extra slashes */ continue; if (p != ++sp) for (p1 = sp, p2 = p; (*p1++ = *p2++) != '\0';) continue; p = sp; /* save start of component */ slash = 0; if (*p) while (*++p) /* find next slash or end of path */ if (*p == '/') { slash = 1; *p = 0; break; } #ifdef HAVE_SLASHSLASH if (&cp[1] == sp && sp[0] == '.' && sp[1] == '.' && sp[2] == '\0') slashslash = 1; #endif /* HAVE_SLASHSLASH */ if (*sp == '\0') { /* if component is null */ if (--sp == cp) /* if path is one char (i.e. /) */ break; else *sp = '\0'; } else if (sp[0] == '.' && sp[1] == 0) { if (slash) { for (p1 = sp, p2 = p + 1; (*p1++ = *p2++) != '\0';) continue; p = --sp; } else if (--sp != cp) *sp = '\0'; else sp[1] = '\0'; } else if (sp[0] == '.' && sp[1] == '.' && sp[2] == 0) { /* * We have something like "yyy/xxx/..", where "yyy" can be null or * a path starting at /, and "xxx" is a single component. Before * compressing "xxx/..", we want to expand "yyy/xxx", if it is a * symbolic link. */ *--sp = 0; /* form the pathname for readlink */ #ifdef S_IFLNK /* if we have symlinks */ if (sp != cp && /* symlinks != SYM_IGNORE && */ (tlink = areadlink(short2str(cp))) != NULL) { mlink = str2short(tlink); xfree(tlink); if (slash) *p = '/'; /* * Point p to the '/' in "/..", and restore the '/'. */ *(p = sp) = '/'; if (*mlink != '/') { /* * Relative path, expand it between the "yyy/" and the * "/..". First, back sp up to the character past "yyy/". */ while (*--sp != '/') continue; sp++; *sp = 0; /* * New length is "yyy/" + mlink + "/.." and rest */ p1 = newcp = xmalloc(((sp - cp) + Strlen(mlink) + Strlen(p) + 1) * sizeof(Char)); /* * Copy new path into newcp */ for (p2 = cp; (*p1++ = *p2++) != '\0';) continue; for (p1--, p2 = mlink; (*p1++ = *p2++) != '\0';) continue; for (p1--, p2 = p; (*p1++ = *p2++) != '\0';) continue; /* * Restart canonicalization at expanded "/xxx". */ p = sp - cp - 1 + newcp; } else { newcp = Strspl(mlink, p); /* * Restart canonicalization at beginning */ p = newcp; } xfree(cp); cp = newcp; #ifdef HAVE_SLASHSLASH slashslash = (cp[0] == '/' && cp[1] == '/'); #endif /* HAVE_SLASHSLASH */ continue; /* canonicalize the link */ } #endif /* S_IFLNK */ *sp = '/'; if (sp != cp) while (*--sp != '/') continue; if (slash) { for (p1 = sp + 1, p2 = p + 1; (*p1++ = *p2++) != '\0';) continue; p = sp; } else if (cp == sp) *++sp = '\0'; else *sp = '\0'; } else { /* normal dir name (not . or .. or nothing) */ #ifdef S_IFLNK /* if we have symlinks */ if (sp != cp && symlinks == SYM_CHASE && (tlink = areadlink(short2str(cp))) != NULL) { mlink = str2short(tlink); xfree(tlink); /* * restore the '/'. */ if (slash) *p = '/'; /* * point sp to p (rather than backing up). */ sp = p; if (*mlink != '/') { /* * Relative path, expand it between the "yyy/" and the * remainder. First, back sp up to the character past * "yyy/". */ while (*--sp != '/') continue; sp++; *sp = 0; /* * New length is "yyy/" + mlink + "/.." and rest */ p1 = newcp = xmalloc(((sp - cp) + Strlen(mlink) + Strlen(p) + 1) * sizeof(Char)); /* * Copy new path into newcp */ for (p2 = cp; (*p1++ = *p2++) != '\0';) continue; for (p1--, p2 = mlink; (*p1++ = *p2++) != '\0';) continue; for (p1--, p2 = p; (*p1++ = *p2++) != '\0';) continue; /* * Restart canonicalization at expanded "/xxx". */ p = sp - cp - 1 + newcp; } else { newcp = Strspl(mlink, p); /* * Restart canonicalization at beginning */ p = newcp; } xfree(cp); cp = newcp; #ifdef HAVE_SLASHSLASH slashslash = (cp[0] == '/' && cp[1] == '/'); #endif /* HAVE_SLASHSLASH */ continue; /* canonicalize the mlink */ } #endif /* S_IFLNK */ if (slash) *p = '/'; } } /* * fix home... */ #ifdef S_IFLNK p1 = varval(STRhome); cc = Strlen(p1); /* * See if we're not in a subdir of STRhome */ if (p1 && *p1 == '/' && (Strncmp(p1, cp, cc) != 0 || (cp[cc] != '/' && cp[cc] != '\0'))) { static ino_t home_ino = (ino_t) -1; static dev_t home_dev = (dev_t) -1; static Char *home_ptr = NULL; struct stat statbuf; int found; Char *copy; /* * Get dev and ino of STRhome */ if (home_ptr != p1 && stat(short2str(p1), &statbuf) != -1) { home_dev = statbuf.st_dev; home_ino = statbuf.st_ino; home_ptr = p1; } /* * Start comparing dev & ino backwards */ p2 = copy = Strsave(cp); found = 0; while (*p2 && stat(short2str(p2), &statbuf) != -1) { if (DEV_DEV_COMPARE(statbuf.st_dev, home_dev) && statbuf.st_ino == home_ino) { found = 1; break; } if ((sp = Strrchr(p2, '/')) != NULL) *sp = '\0'; } /* * See if we found it */ if (*p2 && found) { /* * Use STRhome to make '~' work */ newcp = Strspl(p1, cp + Strlen(p2)); xfree(cp); cp = newcp; } xfree(copy); } #endif /* S_IFLNK */ #ifdef HAVE_SLASHSLASH if (slashslash) { if (cp[1] != '/') { p = xmalloc((Strlen(cp) + 2) * sizeof(Char)); *p = '/'; (void) Strcpy(&p[1], cp); xfree(cp); cp = p; } } if (cp[1] == '/' && cp[2] == '/') { for (p1 = &cp[1], p2 = &cp[2]; (*p1++ = *p2++) != '\0';) continue; } #endif /* HAVE_SLASHSLASH */ return cp; } /* * dnewcwd - make a new directory in the loop the current one */ static void dnewcwd(struct directory *dp, int dflag) { int print; if (adrof(STRdunique)) { struct directory *dn; for (dn = dhead.di_prev; dn != &dhead; dn = dn->di_prev) if (dn != dp && Strcmp(dn->di_name, dp->di_name) == 0) { dn->di_next->di_prev = dn->di_prev; dn->di_prev->di_next = dn->di_next; dfree(dn); break; } } dcwd = dp; dset(dcwd->di_name); dgetstack(); print = printd; /* if printd is set, print dirstack... */ if (adrof(STRpushdsilent)) /* but pushdsilent overrides printd... */ print = 0; if (dflag & DIR_PRINT) /* but DIR_PRINT overrides pushdsilent... */ print = 1; if (bequiet) /* and bequiet overrides everything */ print = 0; if (print) printdirs(dflag); cwd_cmd(); /* PWP: run the defined cwd command */ } void dsetstack(void) { Char **cp; struct varent *vp; struct directory *dn, *dp; if ((vp = adrof(STRdirstack)) == NULL || vp->vec == NULL) return; /* Free the whole stack */ while ((dn = dhead.di_prev) != &dhead) { dn->di_next->di_prev = dn->di_prev; dn->di_prev->di_next = dn->di_next; if (dn != dcwd) dfree(dn); } /* thread the current working directory */ dhead.di_prev = dhead.di_next = dcwd; dcwd->di_next = dcwd->di_prev = &dhead; /* put back the stack */ for (cp = vp->vec; cp && *cp && **cp; cp++) { dp = xcalloc(sizeof(struct directory), 1); dp->di_name = Strsave(*cp); dp->di_count = 0; dp->di_prev = dcwd; dp->di_next = dcwd->di_next; dcwd->di_next = dp; dp->di_next->di_prev = dp; } dgetstack(); /* Make $dirstack reflect the current state */ } static void dgetstack(void) { int i = 0; Char **dblk, **dbp; struct directory *dn; if (adrof(STRdirstack) == NULL) return; for (dn = dhead.di_prev; dn != &dhead; dn = dn->di_prev, i++) continue; dbp = dblk = xmalloc((i + 1) * sizeof(Char *)); for (dn = dhead.di_prev; dn != &dhead; dn = dn->di_prev, dbp++) *dbp = Strsave(dn->di_name); *dbp = NULL; cleanup_push(dblk, blk_cleanup); setq(STRdirstack, dblk, &shvhed, VAR_READWRITE); cleanup_ignore(dblk); cleanup_until(dblk); } /* * getstakd - added by kfk 17 Jan 1984 * Support routine for the stack hack. Finds nth directory in * the directory stack, or finds last directory in stack. */ const Char * getstakd(int cnt) { struct directory *dp; dp = dcwd; if (cnt < 0) { /* < 0 ==> last dir requested. */ dp = dp->di_next; if (dp == &dhead) dp = dp->di_next; } else { while (cnt-- > 0) { dp = dp->di_prev; if (dp == &dhead) dp = dp->di_prev; if (dp == dcwd) return NULL; } } return dp->di_name; } /* * Karl Kleinpaste - 10 Feb 1984 * Added dextract(), which is used in pushd +n. * Instead of just rotating the entire stack around, dextract() * lets the user have the nth dir extracted from its current * position, and pushes it onto the top. */ static void dextract(struct directory *dp) { if (dp == dcwd) return; dp->di_next->di_prev = dp->di_prev; dp->di_prev->di_next = dp->di_next; dp->di_next = dcwd->di_next; dp->di_prev = dcwd; dp->di_next->di_prev = dp; dcwd->di_next = dp; } static void bequiet_cleanup(void *dummy) { USE(dummy); bequiet = 0; } void loaddirs(Char *fname) { static Char *loaddirs_cmd[] = { STRsource, NULL, NULL }; bequiet = 1; cleanup_push(&bequiet, bequiet_cleanup); if (fname) loaddirs_cmd[1] = fname; else if ((fname = varval(STRdirsfile)) != STRNULL) loaddirs_cmd[1] = fname; else loaddirs_cmd[1] = STRtildotdirs; dosource(loaddirs_cmd, NULL); cleanup_until(&bequiet); } /* * create a file called ~/.cshdirs which has a sequence * of pushd commands which will restore the dir stack to * its state before exit/logout. remember that the order * is reversed in the file because we are pushing. * -strike */ void recdirs(Char *fname, int def) { - int fp, ftmp, oldidfds; + int fp, ftmp, oldidfds, ophup_disabled; int cdflag = 0; struct directory *dp; unsigned int num; Char *snum; struct Strbuf qname = Strbuf_INIT; if (fname == NULL && !def) return; + ophup_disabled = phup_disabled; + phup_disabled = 1; if (fname == NULL) { if ((fname = varval(STRdirsfile)) == STRNULL) fname = Strspl(varval(STRhome), &STRtildotdirs[1]); else fname = Strsave(fname); } else fname = globone(fname, G_ERROR); cleanup_push(fname, xfree); if ((fp = xcreat(short2str(fname), 0600)) == -1) { cleanup_until(fname); + phup_disabled = ophup_disabled; return; } if ((snum = varval(STRsavedirs)) == STRNULL || snum[0] == '\0') num = (unsigned int) ~0; else num = (unsigned int) atoi(short2str(snum)); oldidfds = didfds; didfds = 0; ftmp = SHOUT; SHOUT = fp; cleanup_push(&qname, Strbuf_cleanup); dp = dcwd->di_next; do { if (dp == &dhead) continue; if (cdflag == 0) { cdflag = 1; xprintf("cd %S\n", quote_meta(&qname, dp->di_name)); } else xprintf("pushd %S\n", quote_meta(&qname, dp->di_name)); if (num-- == 0) break; } while ((dp = dp->di_next) != dcwd->di_next); xclose(fp); SHOUT = ftmp; didfds = oldidfds; cleanup_until(fname); + phup_disabled = ophup_disabled; } diff --git a/contrib/tcsh/sh.dol.c b/contrib/tcsh/sh.dol.c index 8009d772b2df..28e8639be8b9 100644 --- a/contrib/tcsh/sh.dol.c +++ b/contrib/tcsh/sh.dol.c @@ -1,1120 +1,1148 @@ /* * sh.dol.c: Variable substitutions */ /*- * Copyright (c) 1980, 1991 The Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include "sh.h" /* * C shell */ /* * These routines perform variable substitution and quoting via ' and ". * To this point these constructs have been preserved in the divided * input words. Here we expand variables and turn quoting via ' and " into * QUOTE bits on characters (which prevent further interpretation). * If the `:q' modifier was applied during history expansion, then * some QUOTEing may have occurred already, so we dont "trim()" here. */ static eChar Dpeekc; /* Peek for DgetC */ static eChar Dpeekrd; /* Peek for Dreadc */ static Char *Dcp, *const *Dvp; /* Input vector for Dreadc */ #define DEOF CHAR_ERR #define unDgetC(c) Dpeekc = c #define QUOTES (_QF|_QB|_ESC) /* \ ' " ` */ /* * The following variables give the information about the current * $ expansion, recording the current word position, the remaining * words within this expansion, the count of remaining words, and the * information about any : modifier which is being applied. */ static Char *dolp; /* Remaining chars from this word */ static Char **dolnxt; /* Further words */ static int dolcnt; /* Count of further words */ static struct Strbuf dolmod; /* = Strbuf_INIT; : modifier characters */ -static int dolmcnt; /* :gx -> INT_MAX, else 1 */ -static int dol_flag_a; /* :ax -> 1, else 0 */ + +static int ndolflags; /* keep track of mod counts for each modifier */ +static int *dolmcnts; /* :gx -> INT_MAX, else 1 */ +static int *dolaflags; /* :ax -> 1, else 0 */ static Char **Dfix2 (Char *const *); static int Dpack (struct Strbuf *); static int Dword (struct blk_buf *); static void dolerror (Char *); static eChar DgetC (int); static void Dgetdol (void); static void fixDolMod (void); static void setDolp (Char *); static void unDredc (eChar); static eChar Dredc (void); static void Dtestq (Char); /* * Fix up the $ expansions and quotations in the * argument list to command t. */ void Dfix(struct command *t) { Char **pp; Char *p; if (noexec) return; /* Note that t_dcom isn't trimmed thus !...:q's aren't lost */ for (pp = t->t_dcom; (p = *pp++) != NULL;) { for (; *p; p++) { if (cmap(*p, _DOL | QUOTES)) { /* $, \, ', ", ` */ Char **expanded; expanded = Dfix2(t->t_dcom); /* found one */ blkfree(t->t_dcom); t->t_dcom = expanded; return; } } } } /* * $ substitute one word, for i/o redirection */ Char * Dfix1(Char *cp) { Char *Dv[2], **expanded; if (noexec) return (0); Dv[0] = cp; Dv[1] = NULL; expanded = Dfix2(Dv); if (expanded[0] == NULL || expanded[1] != NULL) { blkfree(expanded); setname(short2str(cp)); stderror(ERR_NAME | ERR_AMBIG); } cp = Strsave(expanded[0]); blkfree(expanded); return (cp); } /* * Subroutine to do actual fixing after state initialization. */ static Char ** Dfix2(Char *const *v) { struct blk_buf *bb = bb_alloc(); Char **vec; Dvp = v; Dcp = STRNULL; /* Setup input vector for Dreadc */ unDgetC(0); unDredc(0); /* Clear out any old peeks (at error) */ dolp = 0; dolcnt = 0; /* Clear out residual $ expands (...) */ cleanup_push(bb, bb_free); while (Dword(bb)) continue; cleanup_ignore(bb); cleanup_until(bb); vec = bb_finish(bb); xfree(bb); return vec; } /* * Pack up more characters in this word */ static int Dpack(struct Strbuf *wbuf) { eChar c; for (;;) { c = DgetC(DODOL); if (c == '\\') { c = DgetC(0); if (c == DEOF) { unDredc(c); return 1; } if (c == '\n') c = ' '; else c |= QUOTE; } if (c == DEOF) { unDredc(c); return 1; } if (cmap(c, _SP | _NL | _QF | _QB)) { /* sp \t\n'"` */ unDgetC(c); if (cmap(c, QUOTES)) return 0; return 1; } Strbuf_append1(wbuf, (Char) c); } } /* * Get a word. This routine is analogous to the routine * word() in sh.lex.c for the main lexical input. One difference * here is that we don't get a newline to terminate our expansion. * Rather, DgetC will return a DEOF when we hit the end-of-input. */ static int Dword(struct blk_buf *bb) { eChar c, c1; struct Strbuf *wbuf = Strbuf_alloc(); int dolflg; int sofar = 0; Char *str; cleanup_push(wbuf, Strbuf_free); for (;;) { c = DgetC(DODOL); switch (c) { case DEOF: if (sofar == 0) { cleanup_until(wbuf); return (0); } /* finish this word and catch the code above the next time */ unDredc(c); /*FALLTHROUGH*/ case '\n': goto end; case ' ': case '\t': continue; case '`': /* We preserve ` quotations which are done yet later */ Strbuf_append1(wbuf, (Char) c); /*FALLTHROUGH*/ case '\'': case '"': /* * Note that DgetC never returns a QUOTES character from an * expansion, so only true input quotes will get us here or out. */ c1 = c; dolflg = c1 == '"' ? DODOL : 0; for (;;) { c = DgetC(dolflg); if (c == c1) break; if (c == '\n' || c == DEOF) { cleanup_until(bb); stderror(ERR_UNMATCHED, (int)c1); } if ((c & (QUOTE | TRIM)) == ('\n' | QUOTE)) { if (wbuf->len != 0 && (wbuf->s[wbuf->len - 1] & TRIM) == '\\') wbuf->len--; } switch (c1) { case '"': /* * Leave any `s alone for later. Other chars are all * quoted, thus `...` can tell it was within "...". */ Strbuf_append1(wbuf, c == '`' ? '`' : c | QUOTE); break; case '\'': /* Prevent all further interpretation */ Strbuf_append1(wbuf, c | QUOTE); break; case '`': /* Leave all text alone for later */ Strbuf_append1(wbuf, (Char) c); break; default: break; } } if (c1 == '`') Strbuf_append1(wbuf, '`'); sofar = 1; if (Dpack(wbuf) != 0) goto end; continue; case '\\': c = DgetC(0); /* No $ subst! */ if (c == '\n' || c == DEOF) continue; c |= QUOTE; break; default: break; } unDgetC(c); sofar = 1; if (Dpack(wbuf) != 0) goto end; } end: cleanup_ignore(wbuf); cleanup_until(wbuf); str = Strbuf_finish(wbuf); bb_append(bb, str); xfree(wbuf); return 1; } /* * Get a character, performing $ substitution unless flag is 0. * Any QUOTES character which is returned from a $ expansion is * QUOTEd so that it will not be recognized above. */ static eChar DgetC(int flag) { eChar c; top: if ((c = Dpeekc) != 0) { Dpeekc = 0; return (c); } if (lap < labuf.len) { c = labuf.s[lap++] & (QUOTE | TRIM); quotspec: if (cmap(c, QUOTES)) return (c | QUOTE); return (c); } if (dolp) { if ((c = *dolp++ & (QUOTE | TRIM)) != 0) goto quotspec; if (dolcnt > 0) { setDolp(*dolnxt++); --dolcnt; return (' '); } dolp = 0; } if (dolcnt > 0) { setDolp(*dolnxt++); --dolcnt; goto top; } c = Dredc(); if (c == '$' && flag) { Dgetdol(); goto top; } return (c); } static Char *nulvec[] = { NULL }; static struct varent nulargv = {nulvec, STRargv, VAR_READWRITE, { NULL, NULL, NULL }, 0 }; static void dolerror(Char *s) { setname(short2str(s)); stderror(ERR_NAME | ERR_RANGE); } /* * Handle the multitudinous $ expansion forms. * Ugh. */ static void Dgetdol(void) { Char *np; struct varent *vp = NULL; struct Strbuf *name = Strbuf_alloc(); eChar c, sc; int subscr = 0, lwb = 1, upb = 0; int dimen = 0, bitset = 0, length = 0; static Char *dolbang = NULL; cleanup_push(name, Strbuf_free); - dolmod.len = dolmcnt = dol_flag_a = 0; + dolmod.len = ndolflags = 0; c = sc = DgetC(0); if (c == DEOF) { stderror(ERR_SYNTAX); return; } if (c == '{') c = DgetC(0); /* sc is { to take } later */ if ((c & TRIM) == '#') dimen++, c = DgetC(0); /* $# takes dimension */ else if (c == '?') bitset++, c = DgetC(0); /* $? tests existence */ else if (c == '%') length++, c = DgetC(0); /* $% returns length in chars */ switch (c) { case '!': if (dimen || bitset || length) stderror(ERR_SYNTAX); if (backpid != 0) { xfree(dolbang); setDolp(dolbang = putn((tcsh_number_t)backpid)); } cleanup_until(name); goto eatbrac; case '$': if (dimen || bitset || length) stderror(ERR_SYNTAX); setDolp(doldol); cleanup_until(name); goto eatbrac; case '<'|QUOTE: { static struct Strbuf wbuf; /* = Strbuf_INIT; */ if (bitset) stderror(ERR_NOTALLOWED, "$?<"); if (dimen) stderror(ERR_NOTALLOWED, "$#<"); if (length) stderror(ERR_NOTALLOWED, "$%<"); wbuf.len = 0; { char cbuf[MB_LEN_MAX]; size_t cbp = 0; int old_pintr_disabled; for (;;) { int len; ssize_t res; Char wc; pintr_push_enable(&old_pintr_disabled); res = force_read(OLDSTD, cbuf + cbp, 1); cleanup_until(&old_pintr_disabled); if (res != 1) break; cbp++; len = normal_mbtowc(&wc, cbuf, cbp); if (len == -1) { reset_mbtowc(); if (cbp < MB_LEN_MAX) continue; /* Maybe a partial character */ wc = (unsigned char)*cbuf | INVALID_BYTE; } if (len <= 0) len = 1; if (cbp != (size_t)len) memmove(cbuf, cbuf + len, cbp - len); cbp -= len; if (wc == '\n') break; Strbuf_append1(&wbuf, wc); } while (cbp != 0) { int len; Char wc; len = normal_mbtowc(&wc, cbuf, cbp); if (len == -1) { reset_mbtowc(); wc = (unsigned char)*cbuf | INVALID_BYTE; } if (len <= 0) len = 1; if (cbp != (size_t)len) memmove(cbuf, cbuf + len, cbp - len); cbp -= len; if (wc == '\n') break; Strbuf_append1(&wbuf, wc); } Strbuf_terminate(&wbuf); } fixDolMod(); setDolp(wbuf.s); /* Kept allocated until next $< expansion */ cleanup_until(name); goto eatbrac; } case '*': Strbuf_append(name, STRargv); Strbuf_terminate(name); vp = adrof(STRargv); subscr = -1; /* Prevent eating [...] */ break; case DEOF: case '\n': np = dimen ? STRargv : (bitset ? STRstatus : NULL); if (np) { bitset = 0; Strbuf_append(name, np); Strbuf_terminate(name); vp = adrof(np); subscr = -1; /* Prevent eating [...] */ unDredc(c); break; } else stderror(ERR_SYNTAX); /*NOTREACHED*/ default: if (Isdigit(c)) { if (dimen) stderror(ERR_NOTALLOWED, "$#"); subscr = 0; do { subscr = subscr * 10 + c - '0'; c = DgetC(0); } while (c != DEOF && Isdigit(c)); unDredc(c); if (subscr < 0) stderror(ERR_RANGE); if (subscr == 0) { if (bitset) { dolp = dolzero ? STR1 : STR0; cleanup_until(name); goto eatbrac; } if (ffile == 0) stderror(ERR_DOLZERO); if (length) { length = Strlen(ffile); addla(putn((tcsh_number_t)length)); } else { fixDolMod(); setDolp(ffile); } cleanup_until(name); goto eatbrac; } #if 0 if (bitset) stderror(ERR_NOTALLOWED, "$?"); if (length) stderror(ERR_NOTALLOWED, "$%"); #endif vp = adrof(STRargv); if (vp == 0) { vp = &nulargv; cleanup_until(name); goto eatmod; } break; } if (c == DEOF || !alnum(c)) { np = dimen ? STRargv : (bitset ? STRstatus : NULL); if (np) { bitset = 0; Strbuf_append(name, np); Strbuf_terminate(name); vp = adrof(np); subscr = -1; /* Prevent eating [...] */ unDredc(c); break; } else stderror(ERR_VARALNUM); } for (;;) { Strbuf_append1(name, (Char) c); c = DgetC(0); if (c == DEOF || !alnum(c)) break; } Strbuf_terminate(name); unDredc(c); vp = adrof(name->s); } if (bitset) { dolp = (vp || getenv(short2str(name->s))) ? STR1 : STR0; cleanup_until(name); goto eatbrac; } if (vp == NULL || vp->vec == NULL) { np = str2short(getenv(short2str(name->s))); if (np) { static Char *env_val; /* = NULL; */ cleanup_until(name); fixDolMod(); if (length) { addla(putn((tcsh_number_t)Strlen(np))); } else { xfree(env_val); env_val = Strsave(np); setDolp(env_val); } goto eatbrac; } udvar(name->s); /* NOTREACHED */ } cleanup_until(name); c = DgetC(0); upb = blklen(vp->vec); if (dimen == 0 && subscr == 0 && c == '[') { name = Strbuf_alloc(); cleanup_push(name, Strbuf_free); np = name->s; for (;;) { c = DgetC(DODOL); /* Allow $ expand within [ ] */ if (c == ']') break; if (c == '\n' || c == DEOF) stderror(ERR_INCBR); Strbuf_append1(name, (Char) c); } Strbuf_terminate(name); np = name->s; if (dolp || dolcnt) /* $ exp must end before ] */ stderror(ERR_EXPORD); if (!*np) stderror(ERR_SYNTAX); if (Isdigit(*np)) { int i; for (i = 0; Isdigit(*np); i = i * 10 + *np++ - '0') continue; if (i < 0 || (i > upb && !any("-*", *np))) { cleanup_until(name); dolerror(vp->v_name); return; } lwb = i; if (!*np) upb = lwb, np = STRstar; } if (*np == '*') np++; else if (*np != '-') stderror(ERR_MISSING, '-'); else { int i = upb; np++; if (Isdigit(*np)) { i = 0; while (Isdigit(*np)) i = i * 10 + *np++ - '0'; if (i < 0 || i > upb) { cleanup_until(name); dolerror(vp->v_name); return; } } if (i < lwb) upb = lwb - 1; else upb = i; } if (lwb == 0) { if (upb != 0) { cleanup_until(name); dolerror(vp->v_name); return; } upb = -1; } if (*np) stderror(ERR_SYNTAX); cleanup_until(name); } else { if (subscr > 0) { if (subscr > upb) lwb = 1, upb = 0; else lwb = upb = subscr; } unDredc(c); } if (dimen) { /* this is a kludge. It prevents Dgetdol() from */ /* pushing erroneous ${# values into the labuf. */ if (sc == '{') { c = Dredc(); if (c != '}') stderror(ERR_MISSING, '}'); unDredc(c); } addla(putn((tcsh_number_t)(upb - lwb + 1))); } else if (length) { int i; for (i = lwb - 1, length = 0; i < upb; i++) length += Strlen(vp->vec[i]); #ifdef notdef /* We don't want that, since we can always compute it by adding $#xxx */ length += i - 1; /* Add the number of spaces in */ #endif addla(putn((tcsh_number_t)length)); } else { eatmod: fixDolMod(); dolnxt = &vp->vec[lwb - 1]; dolcnt = upb - lwb + 1; } eatbrac: if (sc == '{') { c = Dredc(); if (c != '}') stderror(ERR_MISSING, '}'); } } static void fixDolMod(void) { eChar c; c = DgetC(0); if (c == ':') { + ndolflags = 0; do { - c = DgetC(0), dolmcnt = 1, dol_flag_a = 0; + ++ndolflags; + dolmcnts = xrealloc(dolmcnts, ndolflags * sizeof(int)); + dolaflags = xrealloc(dolaflags, ndolflags * sizeof(int)); + c = DgetC(0), dolmcnts[ndolflags - 1] = 1, dolaflags[ndolflags - 1] = 0; if (c == 'g' || c == 'a') { - if (c == 'g') - dolmcnt = INT_MAX; - else - dol_flag_a = 1; + if (c == 'g') { + dolmcnts[ndolflags - 1] = INT_MAX; + } else { + dolaflags[ndolflags - 1] = 1; + } c = DgetC(0); } - if ((c == 'g' && dolmcnt != INT_MAX) || - (c == 'a' && dol_flag_a == 0)) { - if (c == 'g') - dolmcnt = INT_MAX; - else - dol_flag_a = 1; + if ((c == 'g' && dolmcnts[ndolflags - 1] != INT_MAX) || + (c == 'a' && dolaflags[ndolflags - 1] == 0)) { + if (c == 'g') { + dolmcnts[ndolflags - 1] = INT_MAX; + } else { + dolaflags[ndolflags - 1] = 1; + } c = DgetC(0); } if (c == 's') { /* [eichin:19910926.0755EST] */ int delimcnt = 2; eChar delim = DgetC(0); Strbuf_append1(&dolmod, (Char) c); Strbuf_append1(&dolmod, (Char) delim); if (delim == DEOF || !delim || letter(delim) || Isdigit(delim) || any(" \t\n", delim)) { seterror(ERR_BADSUBST); break; } while ((c = DgetC(0)) != DEOF) { Strbuf_append1(&dolmod, (Char) c); - if(c == delim) delimcnt--; - if(!delimcnt) break; + if (c == delim) delimcnt--; + if (!delimcnt) break; } - if(delimcnt) { + if (delimcnt) { seterror(ERR_BADSUBST); break; } continue; } - if (!any("luhtrqxes", c)) + if (!any(TCSH_MODIFIERS, c)) stderror(ERR_BADMOD, (int)c); Strbuf_append1(&dolmod, (Char) c); - if (c == 'q') - dolmcnt = INT_MAX; + if (c == 'q') { + dolmcnts[ndolflags - 1] = INT_MAX; + } } while ((c = DgetC(0)) == ':'); unDredc(c); } else unDredc(c); } +static int +all_dolmcnts_are_0() +{ + int i = 0; + for (; i < ndolflags; ++i) { + if (dolmcnts[i] != 0) + return 0; + } + return 1; +} + static void setDolp(Char *cp) { Char *dp; size_t i; + int nthMod = 0; - if (dolmod.len == 0 || dolmcnt == 0) { + if (dolmod.len == 0 || all_dolmcnts_are_0()) { dolp = cp; return; } cp = Strsave(cp); for (i = 0; i < dolmod.len; i++) { int didmod = 0; /* handle s// [eichin:19910926.0510EST] */ - if(dolmod.s[i] == 's') { + if (dolmod.s[i] == 's') { Char delim; Char *lhsub, *rhsub, *np; size_t lhlen = 0, rhlen = 0; + /* keep track of where the last :a match hit */ + ptrdiff_t last_match = 0; delim = dolmod.s[++i]; if (!delim || letter(delim) || Isdigit(delim) || any(" \t\n", delim)) { seterror(ERR_BADSUBST); break; } lhsub = &dolmod.s[++i]; - while(dolmod.s[i] != delim && dolmod.s[++i]) { + while (dolmod.s[i] != delim && dolmod.s[++i]) { lhlen++; } dolmod.s[i] = 0; rhsub = &dolmod.s[++i]; - while(dolmod.s[i] != delim && dolmod.s[++i]) { + while (dolmod.s[i] != delim && dolmod.s[++i]) { rhlen++; } dolmod.s[i] = 0; strip(lhsub); strip(rhsub); - strip(cp); - dp = cp; - do { - dp = Strstr(dp, lhsub); - if (dp) { - ptrdiff_t diff = dp - cp; - size_t len = (Strlen(cp) + 1 - lhlen + rhlen); - np = xmalloc(len * sizeof(Char)); - (void) Strncpy(np, cp, diff); - (void) Strcpy(np + diff, rhsub); - (void) Strcpy(np + diff + rhlen, dp + lhlen); - - xfree(cp); - dp = cp = np; - cp[--len] = '\0'; - didmod = 1; - if (diff >= (ssize_t)len) - break; - } else { - /* should this do a seterror? */ - break; - } - } - while (dol_flag_a != 0); + if (dolmcnts[nthMod] != 0) { + strip(cp); + dp = cp; + do { + dp = Strstr(dp + last_match, lhsub); + if (dp) { + ptrdiff_t diff = dp - cp; + size_t len = (Strlen(cp) + 1 - lhlen + rhlen); + np = xmalloc(len * sizeof(Char)); + (void) Strncpy(np, cp, diff); + (void) Strcpy(np + diff, rhsub); + (void) Strcpy(np + diff + rhlen, dp + lhlen); + last_match = diff + rhlen; + + xfree(cp); + dp = cp = np; + cp[--len] = '\0'; + didmod = 1; + if (diff >= (ssize_t)len) + break; + } else { + /* should this do a seterror? */ + break; + } + } + while (dolaflags[nthMod] != 0); + } /* * restore dolmod for additional words */ dolmod.s[i] = rhsub[-1] = (Char) delim; - } else { + } else if (dolmcnts[nthMod] != 0) { do { if ((dp = domod(cp, dolmod.s[i])) != NULL) { didmod = 1; if (Strcmp(cp, dp) == 0) { xfree(cp); cp = dp; break; } else { xfree(cp); cp = dp; } } else break; } - while (dol_flag_a != 0); + while (dolaflags[nthMod] != 0); } - if (didmod && dolmcnt != INT_MAX) - dolmcnt--; + if (didmod && dolmcnts[nthMod] != INT_MAX) + dolmcnts[nthMod]--; #ifdef notdef else break; #endif + + ++nthMod; } addla(cp); dolp = STRNULL; if (seterr) stderror(ERR_OLD); } static void unDredc(eChar c) { Dpeekrd = c; } static eChar Dredc(void) { eChar c; if ((c = Dpeekrd) != 0) { Dpeekrd = 0; return (c); } if (Dcp && (c = *Dcp++)) return (c & (QUOTE | TRIM)); if (*Dvp == 0) { Dcp = 0; return (DEOF); } Dcp = *Dvp++; return (' '); } static int gflag; static void Dtestq(Char c) { if (cmap(c, QUOTES)) gflag = 1; } static void inheredoc_cleanup(void *dummy) { USE(dummy); inheredoc = 0; } Char * randsuf(void) { #ifndef WINNT_NATIVE struct timeval tv; (void) gettimeofday(&tv, NULL); return putn((((tcsh_number_t)tv.tv_sec) ^ ((tcsh_number_t)tv.tv_usec) ^ ((tcsh_number_t)getpid())) & 0x00ffffff); #else return putn(getpid()); #endif } /* * Form a shell temporary file (in unit 0) from the words * of the shell input up to EOF or a line the same as "term". * Unit 0 should have been closed before this call. */ void heredoc(Char *term) { eChar c; Char *Dv[2]; struct Strbuf lbuf = Strbuf_INIT, mbuf = Strbuf_INIT; Char obuf[BUFSIZE + 1]; #define OBUF_END (obuf + sizeof(obuf) / sizeof (*obuf) - 1) Char *lbp, *obp, *mbp; Char **vp; int quoted; #ifdef HAVE_MKSTEMP char *tmp = short2str(shtemp); char *dot = strrchr(tmp, '.'); if (!dot) stderror(ERR_NAME | ERR_NOMATCH); strcpy(dot, TMP_TEMPLATE); xclose(0); if (mkstemp(tmp) == -1) stderror(ERR_SYSTEM, tmp, strerror(errno)); #else /* !HAVE_MKSTEMP */ char *tmp; # ifndef WINNT_NATIVE again: # endif /* WINNT_NATIVE */ tmp = short2str(shtemp); # if O_CREAT == 0 if (xcreat(tmp, 0600) < 0) stderror(ERR_SYSTEM, tmp, strerror(errno)); # endif xclose(0); if (xopen(tmp, O_RDWR|O_CREAT|O_EXCL|O_TEMPORARY|O_LARGEFILE, 0600) == -1) { int oerrno = errno; # ifndef WINNT_NATIVE if (errno == EEXIST) { if (unlink(tmp) == -1) { xfree(shtemp); mbp = randsuf(); shtemp = Strspl(STRtmpsh, mbp); xfree(mbp); } goto again; } # endif /* WINNT_NATIVE */ (void) unlink(tmp); errno = oerrno; stderror(ERR_SYSTEM, tmp, strerror(errno)); } #endif /* HAVE_MKSTEMP */ (void) unlink(tmp); /* 0 0 inode! */ Dv[0] = term; Dv[1] = NULL; gflag = 0; trim(Dv); rscan(Dv, Dtestq); quoted = gflag; obp = obuf; obuf[BUFSIZE] = 0; inheredoc = 1; cleanup_push(&inheredoc, inheredoc_cleanup); #ifdef WINNT_NATIVE __dup_stdin = 1; #endif /* WINNT_NATIVE */ cleanup_push(&lbuf, Strbuf_cleanup); cleanup_push(&mbuf, Strbuf_cleanup); for (;;) { Char **words; /* * Read up a line */ lbuf.len = 0; for (;;) { c = readc(1); /* 1 -> Want EOF returns */ if (c == CHAR_ERR || c == '\n') break; if ((c &= TRIM) != 0) Strbuf_append1(&lbuf, (Char) c); } Strbuf_terminate(&lbuf); /* Catch EOF in the middle of a line. */ if (c == CHAR_ERR && lbuf.len != 0) c = '\n'; /* * Check for EOF or compare to terminator -- before expansion */ if (c == CHAR_ERR || eq(lbuf.s, term)) break; /* * If term was quoted or -n just pass it on */ if (quoted || noexec) { Strbuf_append1(&lbuf, '\n'); Strbuf_terminate(&lbuf); for (lbp = lbuf.s; (c = *lbp++) != 0;) { *obp++ = (Char) c; if (obp == OBUF_END) { tmp = short2str(obuf); (void) xwrite(0, tmp, strlen (tmp)); obp = obuf; } } continue; } /* * Term wasn't quoted so variable and then command expand the input * line */ Dcp = lbuf.s; Dvp = Dv + 1; mbuf.len = 0; for (;;) { c = DgetC(DODOL); if (c == DEOF) break; if ((c &= TRIM) == 0) continue; /* \ quotes \ $ ` here */ if (c == '\\') { c = DgetC(0); if (!any("$\\`", c)) unDgetC(c | QUOTE), c = '\\'; else c |= QUOTE; } Strbuf_append1(&mbuf, (Char) c); } Strbuf_terminate(&mbuf); /* * If any ` in line do command substitution */ mbp = mbuf.s; if (Strchr(mbp, '`') != NULL) { /* * 1 arg to dobackp causes substitution to be literal. Words are * broken only at newlines so that all blanks and tabs are * preserved. Blank lines (null words) are not discarded. */ words = dobackp(mbp, 1); } else /* Setup trivial vector similar to return of dobackp */ Dv[0] = mbp, Dv[1] = NULL, words = Dv; /* * Resurrect the words from the command substitution each separated by * a newline. Note that the last newline of a command substitution * will have been discarded, but we put a newline after the last word * because this represents the newline after the last input line! */ for (vp= words; *vp; vp++) { for (mbp = *vp; *mbp; mbp++) { *obp++ = *mbp & TRIM; if (obp == OBUF_END) { tmp = short2str(obuf); (void) xwrite(0, tmp, strlen (tmp)); obp = obuf; } } *obp++ = '\n'; if (obp == OBUF_END) { tmp = short2str(obuf); (void) xwrite(0, tmp, strlen (tmp)); obp = obuf; } } if (words != Dv) blkfree(words); } *obp = 0; tmp = short2str(obuf); (void) xwrite(0, tmp, strlen (tmp)); (void) lseek(0, (off_t) 0, L_SET); cleanup_until(&inheredoc); } diff --git a/contrib/tcsh/sh.exp.c b/contrib/tcsh/sh.exp.c index 9d85e0bd159c..f9e92c515382 100644 --- a/contrib/tcsh/sh.exp.c +++ b/contrib/tcsh/sh.exp.c @@ -1,1053 +1,1053 @@ /* * sh.exp.c: Expression evaluations */ /*- * Copyright (c) 1980, 1991 The Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include "sh.h" #include "tw.h" /* * C shell */ #define TEXP_IGNORE 1 /* in ignore, it means to ignore value, just parse */ #define TEXP_NOGLOB 2 /* in ignore, it means not to globone */ #define ADDOP 1 #define MULOP 2 #define EQOP 4 #define RELOP 8 #define RESTOP 16 #define ANYOP 31 #define EQEQ 1 #define GTR 2 #define LSS 4 #define NOTEQ 6 #define EQMATCH 7 #define NOTEQMATCH 8 static int sh_access (const Char *, int); static tcsh_number_t exp1 (Char ***, int); static tcsh_number_t exp2x (Char ***, int); static tcsh_number_t exp2a (Char ***, int); static tcsh_number_t exp2b (Char ***, int); static tcsh_number_t exp2c (Char ***, int); static Char *exp3 (Char ***, int); static Char *exp3a (Char ***, int); static Char *exp4 (Char ***, int); static Char *exp5 (Char ***, int); static Char *exp6 (Char ***, int); static void evalav (Char **); static int isa (Char *, int); static tcsh_number_t egetn (const Char *); #ifdef EDEBUG static void etracc (const char *, const Char *, Char ***); static void etraci (const char *, tcsh_number_t, Char ***); #else /* !EDEBUG */ #define etracc(A, B, C) ((void)0) #define etraci(A, B, C) ((void)0) #endif /* !EDEBUG */ /* * shell access function according to POSIX and non POSIX * From Beto Appleton (beto@aixwiz.aix.ibm.com) */ static int sh_access(const Char *fname, int mode) { #if defined(POSIX) && !defined(USE_ACCESS) struct stat statb; #endif /* POSIX */ char *name = short2str(fname); if (*name == '\0') return 1; #if !defined(POSIX) || defined(USE_ACCESS) return access(name, mode); #else /* POSIX */ /* * POSIX 1003.2-d11.2 * -r file True if file exists and is readable. * -w file True if file exists and is writable. * True shall indicate only that the write flag is on. * The file shall not be writable on a read-only file * system even if this test indicates true. * -x file True if file exists and is executable. * True shall indicate only that the execute flag is on. * If file is a directory, true indicates that the file * can be searched. */ if (mode != W_OK && mode != X_OK) return access(name, mode); if (stat(name, &statb) == -1) return 1; if (access(name, mode) == 0) { #ifdef S_ISDIR if (S_ISDIR(statb.st_mode) && mode == X_OK) return 0; #endif /* S_ISDIR */ /* root needs permission for someone */ switch (mode) { case W_OK: mode = S_IWUSR | S_IWGRP | S_IWOTH; break; case X_OK: mode = S_IXUSR | S_IXGRP | S_IXOTH; break; default: abort(); break; } } else if (euid == statb.st_uid) mode <<= 6; else if (egid == statb.st_gid) mode <<= 3; # ifdef NGROUPS_MAX else { /* you can be in several groups */ long n; GETGROUPS_T *groups; /* * Try these things to find a positive maximum groups value: * 1) sysconf(_SC_NGROUPS_MAX) * 2) NGROUPS_MAX * 3) getgroups(0, unused) * Then allocate and scan the groups array if one of these worked. */ # if defined (HAVE_SYSCONF) && defined (_SC_NGROUPS_MAX) if ((n = sysconf(_SC_NGROUPS_MAX)) == -1) # endif /* _SC_NGROUPS_MAX */ n = NGROUPS_MAX; if (n <= 0) n = getgroups(0, (GETGROUPS_T *) NULL); if (n > 0) { groups = xmalloc(n * sizeof(*groups)); n = getgroups((int) n, groups); while (--n >= 0) if (groups[n] == statb.st_gid) { mode <<= 3; break; } xfree(groups); } } # endif /* NGROUPS_MAX */ if (statb.st_mode & mode) return 0; else return 1; #endif /* !POSIX */ } tcsh_number_t expr(Char ***vp) { return (exp0(vp, 0)); } tcsh_number_t exp0(Char ***vp, int ignore) { tcsh_number_t p1 = exp1(vp, ignore); etraci("exp0 p1", p1, vp); while (**vp && eq(**vp, STRor2)) { int p2; (*vp)++; p2 = compat_expr ? exp0(vp, (ignore & TEXP_IGNORE) || p1) : exp1(vp, (ignore & TEXP_IGNORE) || p1); if (compat_expr || !(ignore & TEXP_IGNORE)) p1 = (p1 || p2); etraci("exp0 p1", p1, vp); if (compat_expr) break; } return (p1); } static tcsh_number_t exp1(Char ***vp, int ignore) { tcsh_number_t p1 = exp2x(vp, ignore); etraci("exp1 p1", p1, vp); while (**vp && eq(**vp, STRand2)) { tcsh_number_t p2; (*vp)++; p2 = compat_expr ? exp1(vp, (ignore & TEXP_IGNORE) || !p1) : exp2x(vp, (ignore & TEXP_IGNORE) || !p1); etraci("exp1 p2", p2, vp); if (compat_expr || !(ignore & TEXP_IGNORE)) p1 = (p1 && p2); etraci("exp1 p1", p1, vp); if (compat_expr) break; } return (p1); } static tcsh_number_t exp2x(Char ***vp, int ignore) { tcsh_number_t p1 = exp2a(vp, ignore); etraci("exp2x p1", p1, vp); while (**vp && eq(**vp, STRor)) { tcsh_number_t p2; (*vp)++; p2 = compat_expr ? exp2x(vp, ignore) : exp2a(vp, ignore); etraci("exp2x p2", p2, vp); if (compat_expr || !(ignore & TEXP_IGNORE)) p1 = (p1 | p2); etraci("exp2x p1", p1, vp); if (compat_expr) break; } return (p1); } static tcsh_number_t exp2a(Char ***vp, int ignore) { tcsh_number_t p1 = exp2b(vp, ignore); etraci("exp2a p1", p1, vp); while (**vp && eq(**vp, STRcaret)) { tcsh_number_t p2; (*vp)++; p2 = compat_expr ? exp2a(vp, ignore) : exp2b(vp, ignore); etraci("exp2a p2", p2, vp); if (compat_expr || !(ignore & TEXP_IGNORE)) p1 = (p1 ^ p2); etraci("exp2a p1", p1, vp); if (compat_expr) break; } return (p1); } static tcsh_number_t exp2b(Char ***vp, int ignore) { tcsh_number_t p1 = exp2c(vp, ignore); etraci("exp2b p1", p1, vp); while (**vp && eq(**vp, STRand)) { tcsh_number_t p2; (*vp)++; p2 = compat_expr ? exp2b(vp, ignore) : exp2c(vp, ignore); etraci("exp2b p2", p2, vp); if (compat_expr || !(ignore & TEXP_IGNORE)) p1 = (p1 & p2); etraci("exp2b p1", p1, vp); if (compat_expr) break; } return (p1); } static tcsh_number_t exp2c(Char ***vp, int ignore) { Char *p1 = exp3(vp, ignore); Char *p2; tcsh_number_t i; cleanup_push(p1, xfree); etracc("exp2c p1", p1, vp); if ((i = isa(**vp, EQOP)) != 0) { (*vp)++; if (i == EQMATCH || i == NOTEQMATCH) ignore |= TEXP_NOGLOB; p2 = exp3(vp, ignore); cleanup_push(p2, xfree); etracc("exp2c p2", p2, vp); if (!(ignore & TEXP_IGNORE)) switch ((int)i) { case EQEQ: i = eq(p1, p2); break; case NOTEQ: i = !eq(p1, p2); break; case EQMATCH: i = Gmatch(p1, p2); break; case NOTEQMATCH: i = !Gmatch(p1, p2); break; } cleanup_until(p1); return (i); } i = egetn(p1); cleanup_until(p1); return (i); } static Char * exp3(Char ***vp, int ignore) { Char *p1, *p2; tcsh_number_t i; p1 = exp3a(vp, ignore); etracc("exp3 p1", p1, vp); while ((i = isa(**vp, RELOP)) != 0) { (*vp)++; if (**vp && eq(**vp, STRequal)) i |= 1, (*vp)++; cleanup_push(p1, xfree); p2 = compat_expr ? exp3(vp, ignore) : exp3a(vp, ignore); cleanup_push(p2, xfree); etracc("exp3 p2", p2, vp); if (!(ignore & TEXP_IGNORE)) switch ((int)i) { case GTR: i = egetn(p1) > egetn(p2); break; case GTR | 1: i = egetn(p1) >= egetn(p2); break; case LSS: i = egetn(p1) < egetn(p2); break; case LSS | 1: i = egetn(p1) <= egetn(p2); break; } cleanup_until(p1); p1 = putn(i); etracc("exp3 p1", p1, vp); if (compat_expr) break; } return (p1); } static Char * exp3a(Char ***vp, int ignore) { Char *p1, *p2; const Char *op; tcsh_number_t i; p1 = exp4(vp, ignore); etracc("exp3a p1", p1, vp); op = **vp; if (op && any("<>", op[0]) && op[0] == op[1]) { (*vp)++; cleanup_push(p1, xfree); p2 = compat_expr ? exp3a(vp, ignore) : exp4(vp, ignore); cleanup_push(p2, xfree); etracc("exp3a p2", p2, vp); if (op[0] == '<') i = egetn(p1) << egetn(p2); else i = egetn(p1) >> egetn(p2); cleanup_until(p1); p1 = putn(i); etracc("exp3a p1", p1, vp); } return (p1); } static Char * exp4(Char ***vp, int ignore) { Char *p1, *p2; tcsh_number_t i = 0; p1 = exp5(vp, ignore); etracc("exp4 p1", p1, vp); while (isa(**vp, ADDOP)) { const Char *op = *(*vp)++; cleanup_push(p1, xfree); p2 = compat_expr ? exp4(vp, ignore) : exp5(vp, ignore); cleanup_push(p2, xfree); etracc("exp4 p2", p2, vp); if (!(ignore & TEXP_IGNORE)) switch (op[0]) { case '+': i = egetn(p1) + egetn(p2); break; case '-': i = egetn(p1) - egetn(p2); break; } cleanup_until(p1); p1 = putn(i); etracc("exp4 p1", p1, vp); if (compat_expr) break; } return (p1); } static Char * exp5(Char ***vp, int ignore) { Char *p1, *p2; tcsh_number_t i = 0; p1 = exp6(vp, ignore); etracc("exp5 p1", p1, vp); while (isa(**vp, MULOP)) { const Char *op = *(*vp)++; if ((ignore & TEXP_NOGLOB) != 0) { /* * We are just trying to get the right side of * a =~ or !~ operator */ xfree(p1); return Strsave(op); } cleanup_push(p1, xfree); p2 = compat_expr ? exp5(vp, ignore) : exp6(vp, ignore); cleanup_push(p2, xfree); etracc("exp5 p2", p2, vp); if (!(ignore & TEXP_IGNORE)) switch (op[0]) { case '*': i = egetn(p1) * egetn(p2); break; case '/': i = egetn(p2); if (i == 0) stderror(ERR_DIV0); i = egetn(p1) / i; break; case '%': i = egetn(p2); if (i == 0) stderror(ERR_MOD0); i = egetn(p1) % i; break; } cleanup_until(p1); p1 = putn(i); etracc("exp5 p1", p1, vp); if (compat_expr) break; } return (p1); } static Char * exp6(Char ***vp, int ignore) { tcsh_number_t ccode; tcsh_number_t i = 0; Char *cp; if (**vp == 0) stderror(ERR_NAME | ERR_EXPRESSION); if (eq(**vp, STRbang)) { (*vp)++; cp = exp6(vp, ignore); cleanup_push(cp, xfree); etracc("exp6 ! cp", cp, vp); i = egetn(cp); cleanup_until(cp); return (putn(!i)); } if (eq(**vp, STRtilde)) { (*vp)++; cp = exp6(vp, ignore); cleanup_push(cp, xfree); etracc("exp6 ~ cp", cp, vp); i = egetn(cp); cleanup_until(cp); return (putn(~i)); } if (eq(**vp, STRLparen)) { (*vp)++; ccode = exp0(vp, ignore); etraci("exp6 () ccode", ccode, vp); if (**vp == 0 || ***vp != ')') stderror(ERR_NAME | ERR_EXPRESSION); (*vp)++; return (putn(ccode)); } if (eq(**vp, STRLbrace)) { Char **v; struct command faket; Char *fakecom[2]; faket.t_dtyp = NODE_COMMAND; faket.t_dflg = F_BACKQ; faket.t_dcar = faket.t_dcdr = faket.t_dspr = NULL; faket.t_dcom = fakecom; fakecom[0] = STRfakecom; fakecom[1] = NULL; (*vp)++; v = *vp; for (;;) { if (!**vp) stderror(ERR_NAME | ERR_MISSING, '}'); if (eq(*(*vp)++, STRRbrace)) break; } if (ignore & TEXP_IGNORE) return (Strsave(STRNULL)); psavejob(); cleanup_push(&faket, psavejob_cleanup); /* faket is only a marker */ if (pfork(&faket, -1) == 0) { *--(*vp) = 0; evalav(v); exitstat(); } pwait(); cleanup_until(&faket); etraci("exp6 {} status", egetn(varval(STRstatus)), vp); return (putn(egetn(varval(STRstatus)) == 0)); } if (isa(**vp, ANYOP)) return (Strsave(STRNULL)); cp = *(*vp)++; #ifdef convex # define FILETESTS "erwxfdzoplstSXLbcugkmKR" #else # define FILETESTS "erwxfdzoplstSXLbcugkmK" #endif /* convex */ #define FILEVALS "ZAMCDIUGNFPL" if (*cp == '-' && (any(FILETESTS, cp[1]) || any(FILEVALS, cp[1]))) return(filetest(cp, vp, ignore)); etracc("exp6 default", cp, vp); return (ignore & TEXP_NOGLOB ? Strsave(cp) : globone(cp, G_APPEND)); } /* * Extended file tests * From: John Rowe */ Char * filetest(Char *cp, Char ***vp, int ignore) { #ifdef convex struct cvxstat stb, *st = NULL; # define TCSH_STAT stat64 #else # define TCSH_STAT stat struct stat stb, *st = NULL; #endif /* convex */ #ifdef S_IFLNK # ifdef convex struct cvxstat lstb, *lst = NULL; # define TCSH_LSTAT lstat64 # else # define TCSH_LSTAT lstat struct stat lstb, *lst = NULL; # endif /* convex */ char *filnam; #endif /* S_IFLNK */ tcsh_number_t i = 0; unsigned pmask = 0xffff; int altout = 0; Char *ft = cp, *dp, *ep, *strdev, *strino, *strF, *str, valtest = '\0', *errval = STR0; char *string, string0[22 + MB_LEN_MAX + 1]; /* space for 64 bit octal */ time_t footime; struct passwd *pw; struct group *gr; - while(any(FILETESTS, *++ft)) + while (any(FILETESTS, *++ft)) continue; if (!*ft && *(ft - 1) == 'L') --ft; if (any(FILEVALS, *ft)) { valtest = *ft++; /* * Value tests return '-1' on failure as 0 is * a legitimate value for many of them. * 'F' returns ':' for compatibility. */ errval = valtest == 'F' ? STRcolon : STRminus1; if (valtest == 'P' && *ft >= '0' && *ft <= '7') { pmask = (char) *ft - '0'; while ( *++ft >= '0' && *ft <= '7' ) pmask = 8 * pmask + ((char) *ft - '0'); } if (Strcmp(ft, STRcolon) == 0 && any("AMCUGP", valtest)) { altout = 1; ++ft; } } if (*ft || ft == cp + 1) stderror(ERR_NAME | ERR_FILEINQ); /* * Detect missing file names by checking for operator in the file name * position. However, if an operator name appears there, we must make * sure that there's no file by that name (e.g., "/") before announcing * an error. Even this check isn't quite right, since it doesn't take * globbing into account. */ if (isa(**vp, ANYOP) && TCSH_STAT(short2str(**vp), &stb)) stderror(ERR_NAME | ERR_FILENAME); dp = *(*vp)++; if (ignore & TEXP_IGNORE) return (Strsave(STRNULL)); ep = globone(dp, G_APPEND); cleanup_push(ep, xfree); ft = &cp[1]; do switch (*ft) { case 'r': i = !sh_access(ep, R_OK); break; case 'w': i = !sh_access(ep, W_OK); break; case 'x': i = !sh_access(ep, X_OK); break; case 'X': /* tcsh extension, name is an executable in the path * or a tcsh builtin command */ i = find_cmd(ep, 0); break; case 't': /* SGI extension, true when file is a tty */ i = isatty(atoi(short2str(ep))); break; default: #ifdef S_IFLNK if (tolower(*ft) == 'l') { /* * avoid convex compiler bug. */ if (!lst) { lst = &lstb; if (TCSH_LSTAT(short2str(ep), lst) == -1) { cleanup_until(ep); return (Strsave(errval)); } } if (*ft == 'L') st = lst; } else #endif /* S_IFLNK */ /* * avoid convex compiler bug. */ if (!st) { st = &stb; if (TCSH_STAT(short2str(ep), st) == -1) { cleanup_until(ep); return (Strsave(errval)); } } switch (*ft) { case 'f': #ifdef S_ISREG i = S_ISREG(st->st_mode); #else /* !S_ISREG */ i = 0; #endif /* S_ISREG */ break; case 'd': #ifdef S_ISDIR i = S_ISDIR(st->st_mode); #else /* !S_ISDIR */ i = 0; #endif /* S_ISDIR */ break; case 'p': #ifdef S_ISFIFO i = S_ISFIFO(st->st_mode); #else /* !S_ISFIFO */ i = 0; #endif /* S_ISFIFO */ break; case 'm' : #ifdef S_ISOFL i = S_ISOFL(st->st_dm_mode); #else /* !S_ISOFL */ i = 0; #endif /* S_ISOFL */ break ; case 'K' : #ifdef S_ISOFL i = stb.st_dm_key; #else /* !S_ISOFL */ i = 0; #endif /* S_ISOFL */ break ; case 'l': #ifdef S_ISLNK i = S_ISLNK(lst->st_mode); #else /* !S_ISLNK */ i = 0; #endif /* S_ISLNK */ break; case 'S': # ifdef S_ISSOCK i = S_ISSOCK(st->st_mode); # else /* !S_ISSOCK */ i = 0; # endif /* S_ISSOCK */ break; case 'b': #ifdef S_ISBLK i = S_ISBLK(st->st_mode); #else /* !S_ISBLK */ i = 0; #endif /* S_ISBLK */ break; case 'c': #ifdef S_ISCHR i = S_ISCHR(st->st_mode); #else /* !S_ISCHR */ i = 0; #endif /* S_ISCHR */ break; case 'u': i = (S_ISUID & st->st_mode) != 0; break; case 'g': i = (S_ISGID & st->st_mode) != 0; break; case 'k': i = (S_ISVTX & st->st_mode) != 0; break; case 'z': i = st->st_size == 0; break; #ifdef convex case 'R': i = (stb.st_dmonflags & IMIGRATED) == IMIGRATED; break; #endif /* convex */ case 's': i = stb.st_size != 0; break; case 'e': i = 1; break; case 'o': i = st->st_uid == uid; break; /* * Value operators are a tcsh extension. */ case 'D': i = (tcsh_number_t) st->st_dev; break; case 'I': i = (tcsh_number_t) st->st_ino; break; case 'F': strdev = putn( (int) st->st_dev); strino = putn( (int) st->st_ino); strF = xmalloc((2 + Strlen(strdev) + Strlen(strino)) * sizeof(Char)); (void) Strcat(Strcat(Strcpy(strF, strdev), STRcolon), strino); xfree(strdev); xfree(strino); cleanup_until(ep); return(strF); case 'L': if ( *(ft + 1) ) { i = 1; break; } #ifdef S_ISLNK filnam = short2str(ep); string = areadlink(filnam); strF = string == NULL ? errval : str2short(string); xfree(string); cleanup_until(ep); return(Strsave(strF)); #else /* !S_ISLNK */ i = 0; break; #endif /* S_ISLNK */ case 'N': i = (tcsh_number_t) st->st_nlink; break; case 'P': string = string0 + 1; (void) xsnprintf(string, sizeof(string0) - 1, "%o", pmask & (unsigned int) ((S_IRWXU|S_IRWXG|S_IRWXO|S_ISUID|S_ISGID) & st->st_mode)); if (altout && *string != '0') *--string = '0'; cleanup_until(ep); return(Strsave(str2short(string))); case 'U': if (altout && (pw = xgetpwuid(st->st_uid))) { cleanup_until(ep); return(Strsave(str2short(pw->pw_name))); } i = (tcsh_number_t) st->st_uid; break; case 'G': if (altout && (gr = xgetgrgid(st->st_gid))) { cleanup_until(ep); return(Strsave(str2short(gr->gr_name))); } i = (tcsh_number_t) st->st_gid; break; case 'Z': i = (tcsh_number_t) st->st_size; break; case 'A': case 'M': case 'C': footime = *ft == 'A' ? st->st_atime : *ft == 'M' ? st->st_mtime : st->st_ctime; if (altout) { strF = str2short(ctime(&footime)); if ((str = Strchr(strF, '\n')) != NULL) *str = (Char) '\0'; cleanup_until(ep); return(Strsave(strF)); } i = (tcsh_number_t) footime; break; } } while (*++ft && i); etraci("exp6 -? i", i, vp); cleanup_until(ep); return (putn(i)); } static void evalav(Char **v) { struct wordent paraml1; struct wordent *hp = ¶ml1; struct command *t; struct wordent *wdp = hp; setcopy(STRstatus, STR0, VAR_READWRITE); initlex(hp); while (*v) { struct wordent *new = xcalloc(1, sizeof *wdp); new->prev = wdp; new->next = hp; wdp->next = new; wdp = new; wdp->word = Strsave(*v++); } hp->prev = wdp; cleanup_push(¶ml1, lex_cleanup); alias(¶ml1); t = syntax(paraml1.next, ¶ml1, 0); cleanup_push(t, syntax_cleanup); if (seterr) stderror(ERR_OLD); execute(t, -1, NULL, NULL, TRUE); cleanup_until(¶ml1); } static int isa(Char *cp, int what) { if (cp == 0) return ((what & RESTOP) != 0); if (*cp == '\0') return 0; if (cp[1] == 0) { if (what & ADDOP && (*cp == '+' || *cp == '-')) return (1); if (what & MULOP && (*cp == '*' || *cp == '/' || *cp == '%')) return (1); if (what & RESTOP && (*cp == '(' || *cp == ')' || *cp == '!' || *cp == '~' || *cp == '^' || *cp == '"')) return (1); } else if (cp[2] == 0) { if (what & RESTOP) { if (cp[0] == '|' && cp[1] == '&') return (1); if (cp[0] == '<' && cp[1] == '<') return (1); if (cp[0] == '>' && cp[1] == '>') return (1); } if (what & EQOP) { if (cp[0] == '=') { if (cp[1] == '=') return (EQEQ); if (cp[1] == '~') return (EQMATCH); } else if (cp[0] == '!') { if (cp[1] == '=') return (NOTEQ); if (cp[1] == '~') return (NOTEQMATCH); } } } if (what & RELOP) { if (*cp == '<') return (LSS); if (*cp == '>') return (GTR); } return (0); } static tcsh_number_t egetn(const Char *cp) { if (*cp && *cp != '-' && !Isdigit(*cp)) stderror(ERR_NAME | ERR_EXPRESSION); return (getn(cp)); } /* Phew! */ #ifdef EDEBUG static void etraci(const char *str, tcsh_number_t i, Char ***vp) { #ifdef HAVE_LONG_LONG xprintf("%s=%lld\t", str, i); #else xprintf("%s=%ld\t", str, i); #endif blkpr(*vp); xputchar('\n'); } static void etracc(const char *str, const Char *cp, Char ***vp) { xprintf("%s=%S\t", str, cp); blkpr(*vp); xputchar('\n'); } #endif /* EDEBUG */ diff --git a/contrib/tcsh/sh.func.c b/contrib/tcsh/sh.func.c index 05f3f20df3bf..c978ffe844fe 100644 --- a/contrib/tcsh/sh.func.c +++ b/contrib/tcsh/sh.func.c @@ -1,2747 +1,2746 @@ /* * sh.func.c: csh builtin functions */ /*- * Copyright (c) 1980, 1991 The Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include "sh.h" #include "ed.h" #include "tw.h" #include "tc.h" #ifdef WINNT_NATIVE #include "nt.const.h" #endif /* WINNT_NATIVE */ #if defined (NLS_CATALOGS) && defined(HAVE_ICONV) static iconv_t catgets_iconv; /* Or (iconv_t)-1 */ #endif /* * C shell */ extern int MapsAreInited; extern int NLSMapsAreInited; extern int GotTermCaps; static int zlast = -1; static void islogin (void); static void preread (void); static void doagain (void); static const char *isrchx (int); static void search (int, int, Char *); static int getword (struct Strbuf *); static struct wordent *histgetword (struct wordent *); static void toend (void); static void xecho (int, Char **); static int islocale_var (Char *); static void wpfree (struct whyle *); const struct biltins * isbfunc(struct command *t) { Char *cp = t->t_dcom[0]; const struct biltins *bp, *bp1, *bp2; static struct biltins label = {"", dozip, 0, 0}; static struct biltins foregnd = {"%job", dofg1, 0, 0}; static struct biltins backgnd = {"%job &", dobg1, 0, 0}; /* * We never match a builtin that has quoted the first * character; this has been the traditional way to escape * builtin commands. */ if (*cp & QUOTE) return NULL; if (*cp != ':' && lastchr(cp) == ':') { label.bname = short2str(cp); return (&label); } if (*cp == '%') { if (t->t_dflg & F_AMPERSAND) { t->t_dflg &= ~F_AMPERSAND; backgnd.bname = short2str(cp); return (&backgnd); } foregnd.bname = short2str(cp); return (&foregnd); } #ifdef WARP /* * This is a perhaps kludgy way to determine if the warp builtin is to be * acknowledged or not. If checkwarp() fails, then we are to assume that * the warp command is invalid, and carry on as we would handle any other * non-builtin command. -- JDK 2/4/88 */ if (eq(STRwarp, cp) && !checkwarp()) { return (0); /* this builtin disabled */ } #endif /* WARP */ /* * Binary search Bp1 is the beginning of the current search range. Bp2 is * one past the end. */ for (bp1 = bfunc, bp2 = bfunc + nbfunc; bp1 < bp2;) { int i; bp = bp1 + ((bp2 - bp1) >> 1); if ((i = ((char) *cp) - *bp->bname) == 0 && (i = StrQcmp(cp, str2short(bp->bname))) == 0) return bp; if (i < 0) bp2 = bp; else bp1 = bp + 1; } #ifdef WINNT_NATIVE return nt_check_additional_builtins(cp); #endif /*WINNT_NATIVE*/ return (0); } void func(struct command *t, const struct biltins *bp) { int i; xechoit(t->t_dcom); setname(bp->bname); i = blklen(t->t_dcom) - 1; if (i < bp->minargs) stderror(ERR_NAME | ERR_TOOFEW); if (i > bp->maxargs) stderror(ERR_NAME | ERR_TOOMANY); (*bp->bfunct) (t->t_dcom, t); } /*ARGSUSED*/ void doonintr(Char **v, struct command *c) { Char *cp; Char *vv = v[1]; USE(c); if (parintr.sa_handler == SIG_IGN) return; if (setintr && intty) stderror(ERR_NAME | ERR_TERMINAL); cp = gointr; gointr = 0; xfree(cp); if (vv == 0) { if (setintr) sigset_interrupting(SIGINT, queue_pintr); else (void) signal(SIGINT, SIG_DFL); gointr = 0; } else if (eq((vv = strip(vv)), STRminus)) { (void) signal(SIGINT, SIG_IGN); gointr = Strsave(STRminus); } else { gointr = Strsave(vv); sigset_interrupting(SIGINT, queue_pintr); } } /*ARGSUSED*/ void donohup(Char **v, struct command *c) { USE(c); USE(v); if (intty) stderror(ERR_NAME | ERR_TERMINAL); if (setintr == 0) { (void) signal(SIGHUP, SIG_IGN); phup_disabled = 1; #ifdef CC submit(getpid()); #endif /* CC */ } } /*ARGSUSED*/ void dohup(Char **v, struct command *c) { USE(c); USE(v); if (intty) stderror(ERR_NAME | ERR_TERMINAL); if (setintr == 0) sigset_interrupting(SIGHUP, SIG_DFL); } /*ARGSUSED*/ void dozip(Char **v, struct command *c) { USE(c); USE(v); } /*ARGSUSED*/ void dofiletest(Char **v, struct command *c) { Char **globbed, **fileptr, *ftest, *res; USE(c); if (*(ftest = *++v) != '-') stderror(ERR_NAME | ERR_FILEINQ); ++v; v = glob_all_or_error(v); globbed = v; cleanup_push(globbed, blk_cleanup); while (*(fileptr = v++) != NULL) { res = filetest(ftest, &fileptr, 0); cleanup_push(res, xfree); xprintf("%S", res); cleanup_until(res); if (*v) xprintf(" "); } xprintf("\n"); cleanup_until(globbed); } void prvars(void) { plist(&shvhed, VAR_ALL); } /*ARGSUSED*/ void doalias(Char **v, struct command *c) { struct varent *vp; Char *p; USE(c); v++; p = *v++; if (p == 0) plist(&aliases, VAR_ALL); else if (*v == 0) { vp = adrof1(strip(p), &aliases); if (vp && vp->vec) blkpr(vp->vec), xputchar('\n'); } else { if (eq(p, STRalias) || eq(p, STRunalias)) { setname(short2str(p)); stderror(ERR_NAME | ERR_DANGER); } set1(strip(p), saveblk(v), &aliases, VAR_READWRITE); tw_cmd_free(); } } /*ARGSUSED*/ void unalias(Char **v, struct command *c) { USE(c); unset1(v, &aliases); tw_cmd_free(); } /*ARGSUSED*/ void dologout(Char **v, struct command *c) { USE(c); USE(v); islogin(); goodbye(NULL, NULL); } /*ARGSUSED*/ void dologin(Char **v, struct command *c) { #ifdef WINNT_NATIVE USE(c); USE(v); #else /* !WINNT_NATIVE */ char **p = short2blk(v); USE(c); cleanup_push((Char **)p, blk_cleanup); islogin(); rechist(NULL, adrof(STRsavehist) != NULL); sigaction(SIGTERM, &parterm, NULL); (void) execv(_PATH_BIN_LOGIN, p); (void) execv(_PATH_USRBIN_LOGIN, p); cleanup_until((Char **)p); untty(); xexit(1); #endif /* !WINNT_NATIVE */ } #ifdef NEWGRP /*ARGSUSED*/ void donewgrp(Char **v, struct command *c) { char **p; if (chkstop == 0 && setintr) panystop(0); sigaction(SIGTERM, &parterm, NULL); p = short2blk(v); /* * From Beto Appleton (beto@aixwiz.austin.ibm.com) * Newgrp can take 2 arguments... */ (void) execv(_PATH_BIN_NEWGRP, p); (void) execv(_PATH_USRBIN_NEWGRP, p); blkfree((Char **) p); untty(); xexit(1); } #endif /* NEWGRP */ static void islogin(void) { if (chkstop == 0 && setintr) panystop(0); if (loginsh) return; stderror(ERR_NOTLOGIN); } void doif(Char **v, struct command *kp) { int i; Char **vv; v++; i = noexec ? 1 : expr(&v); vv = v; if (*vv == NULL) stderror(ERR_NAME | ERR_EMPTYIF); if (eq(*vv, STRthen)) { if (*++vv) stderror(ERR_NAME | ERR_IMPRTHEN); setname(short2str(STRthen)); /* * If expression was zero, then scan to else , otherwise just fall into * following code. */ if (!i) search(TC_IF, 0, NULL); return; } /* * Simple command attached to this if. Left shift the node in this tree, * munging it so we can reexecute it. */ if (i) { lshift(kp->t_dcom, vv - kp->t_dcom); reexecute(kp); donefds(); } } /* * Reexecute a command, being careful not * to redo i/o redirection, which is already set up. */ void reexecute(struct command *kp) { kp->t_dflg &= F_SAVE; kp->t_dflg |= F_REPEAT; /* * If tty is still ours to arbitrate, arbitrate it; otherwise dont even set * pgrp's as the jobs would then have no way to get the tty (we can't give * it to them, and our parent wouldn't know their pgrp, etc. */ execute(kp, (tpgrp > 0 ? tpgrp : -1), NULL, NULL, TRUE); } /*ARGSUSED*/ void doelse (Char **v, struct command *c) { USE(c); USE(v); if (!noexec) search(TC_ELSE, 0, NULL); } /*ARGSUSED*/ void dogoto(Char **v, struct command *c) { Char *lp; USE(c); lp = globone(v[1], G_ERROR); cleanup_push(lp, xfree); if (!noexec) gotolab(lp); cleanup_until(lp); } void gotolab(Char *lab) { struct whyle *wp; /* * While we still can, locate any unknown ends of existing loops. This * obscure code is the WORST result of the fact that we don't really parse. */ zlast = TC_GOTO; for (wp = whyles; wp; wp = wp->w_next) if (wp->w_end.type == TCSH_F_SEEK && wp->w_end.f_seek == 0) { search(TC_BREAK, 0, NULL); btell(&wp->w_end); } else { bseek(&wp->w_end); } search(TC_GOTO, 0, lab); /* * Eliminate loops which were exited. */ wfree(); } /*ARGSUSED*/ void doswitch(Char **v, struct command *c) { Char *cp, *lp; USE(c); v++; if (!*v || *(*v++) != '(') stderror(ERR_SYNTAX); cp = **v == ')' ? STRNULL : *v++; if (*(*v++) != ')') v--; if (*v) stderror(ERR_SYNTAX); lp = globone(cp, G_ERROR); cleanup_push(lp, xfree); if (!noexec) search(TC_SWITCH, 0, lp); cleanup_until(lp); } /*ARGSUSED*/ void dobreak(Char **v, struct command *c) { USE(v); USE(c); if (whyles == NULL) stderror(ERR_NAME | ERR_NOTWHILE); if (!noexec) toend(); } /*ARGSUSED*/ void doexit(Char **v, struct command *c) { USE(c); if (chkstop == 0 && (intty || intact) && evalvec == 0) panystop(0); /* * Don't DEMAND parentheses here either. */ v++; if (*v) { setv(STRstatus, putn(expr(&v)), VAR_READWRITE); if (*v) stderror(ERR_NAME | ERR_EXPRESSION); } btoeof(); #if 0 if (intty) #endif /* Always close, why only on ttys? */ xclose(SHIN); } /*ARGSUSED*/ void doforeach(Char **v, struct command *c) { Char *cp, *sp; struct whyle *nwp; int gflag; USE(c); v++; cp = sp = strip(*v); if (!letter(*cp)) stderror(ERR_NAME | ERR_VARBEGIN); do { cp++; } while (alnum(*cp)); if (*cp != '\0') stderror(ERR_NAME | ERR_VARALNUM); cp = *v++; if (v[0][0] != '(' || v[blklen(v) - 1][0] != ')') stderror(ERR_NAME | ERR_NOPAREN); v++; gflag = tglob(v); if (gflag) { v = globall(v, gflag); if (v == 0 && !noexec) stderror(ERR_NAME | ERR_NOMATCH); } else { v = saveblk(v); trim(v); } nwp = xcalloc(1, sizeof *nwp); nwp->w_fe = nwp->w_fe0 = v; btell(&nwp->w_start); nwp->w_fename = Strsave(cp); nwp->w_next = whyles; nwp->w_end.type = TCSH_F_SEEK; whyles = nwp; /* * Pre-read the loop so as to be more comprehensible to a terminal user. */ zlast = TC_FOREACH; if (intty) preread(); if (!noexec) doagain(); } /*ARGSUSED*/ void dowhile(Char **v, struct command *c) { int status; int again = whyles != 0 && SEEKEQ(&whyles->w_start, &lineloc) && whyles->w_fename == 0; USE(c); v++; /* * Implement prereading here also, taking care not to evaluate the * expression before the loop has been read up from a terminal. */ if (noexec) status = 0; else if (intty && !again) status = !exp0(&v, 1); else status = !expr(&v); if (*v && !noexec) stderror(ERR_NAME | ERR_EXPRESSION); if (!again) { struct whyle *nwp = xcalloc(1, sizeof(*nwp)); nwp->w_start = lineloc; nwp->w_end.type = TCSH_F_SEEK; nwp->w_end.f_seek = 0; nwp->w_end.a_seek = 0; nwp->w_next = whyles; whyles = nwp; zlast = TC_WHILE; if (intty) { /* * The tty preread */ preread(); doagain(); return; } } if (status) /* We ain't gonna loop no more, no more! */ toend(); } static void preread(void) { int old_pintr_disabled; whyles->w_end.type = TCSH_I_SEEK; if (setintr) pintr_push_enable(&old_pintr_disabled); search(TC_BREAK, 0, NULL); /* read the expression in */ if (setintr) cleanup_until(&old_pintr_disabled); btell(&whyles->w_end); } /*ARGSUSED*/ void doend(Char **v, struct command *c) { USE(v); USE(c); if (!whyles) stderror(ERR_NAME | ERR_NOTWHILE); btell(&whyles->w_end); if (!noexec) doagain(); } /*ARGSUSED*/ void docontin(Char **v, struct command *c) { USE(v); USE(c); if (!whyles) stderror(ERR_NAME | ERR_NOTWHILE); if (!noexec) doagain(); } static void doagain(void) { /* Repeating a while is simple */ if (whyles->w_fename == 0) { bseek(&whyles->w_start); return; } /* * The foreach variable list actually has a spurious word ")" at the end of * the w_fe list. Thus we are at the of the list if one word beyond this * is 0. */ if (!whyles->w_fe[1]) { dobreak(NULL, NULL); return; } setv(whyles->w_fename, quote(Strsave(*whyles->w_fe++)), VAR_READWRITE); bseek(&whyles->w_start); } void dorepeat(Char **v, struct command *kp) { int i = 1; do { i *= getn(v[1]); lshift(v, 2); } while (v[0] != NULL && Strcmp(v[0], STRrepeat) == 0); if (noexec) i = 1; if (setintr) { pintr_disabled++; cleanup_push(&pintr_disabled, disabled_cleanup); } while (i > 0) { if (setintr && pintr_disabled == 1) { cleanup_until(&pintr_disabled); pintr_disabled++; cleanup_push(&pintr_disabled, disabled_cleanup); } reexecute(kp); --i; } if (setintr && pintr_disabled == 1) cleanup_until(&pintr_disabled); donefds(); } /*ARGSUSED*/ void doswbrk(Char **v, struct command *c) { USE(v); USE(c); if (!noexec) search(TC_BRKSW, 0, NULL); } int srchx(Char *cp) { struct srch *sp, *sp1, *sp2; int i; /* * Ignore keywords inside heredocs */ if (inheredoc) return -1; /* * Binary search Sp1 is the beginning of the current search range. Sp2 is * one past the end. */ for (sp1 = srchn, sp2 = srchn + nsrchn; sp1 < sp2;) { sp = sp1 + ((sp2 - sp1) >> 1); if ((i = *cp - *sp->s_name) == 0 && (i = Strcmp(cp, str2short(sp->s_name))) == 0) return sp->s_value; if (i < 0) sp2 = sp; else sp1 = sp + 1; } return (-1); } static const char * isrchx(int n) { struct srch *sp, *sp2; for (sp = srchn, sp2 = srchn + nsrchn; sp < sp2; sp++) if (sp->s_value == n) return (sp->s_name); return (""); } static int Stype; static Char *Sgoal; static void search(int type, int level, Char *goal) { struct Strbuf word = Strbuf_INIT; Char *cp; struct whyle *wp; int wlevel = 0; struct wordent *histent = NULL, *ohistent = NULL; Stype = type; Sgoal = goal; if (type == TC_GOTO) { struct Ain a; a.type = TCSH_F_SEEK; a.f_seek = 0; a.a_seek = 0; bseek(&a); } cleanup_push(&word, Strbuf_cleanup); do { if (intty) { histent = xmalloc(sizeof(*histent)); ohistent = xmalloc(sizeof(*histent)); ohistent->word = STRNULL; ohistent->next = histent; histent->prev = ohistent; } if (intty && fseekp == feobp && aret == TCSH_F_SEEK) printprompt(1, isrchx(type == TC_BREAK ? zlast : type)); /* xprintf("? "), flush(); */ (void) getword(&word); Strbuf_terminate(&word); if (intty && Strlen(word.s) > 0) { histent->word = Strsave(word.s); histent->next = xmalloc(sizeof(*histent)); histent->next->prev = histent; histent = histent->next; } switch (srchx(word.s)) { case TC_ELSE: if (level == 0 && type == TC_IF) goto end; break; case TC_IF: while (getword(&word)) { if (intty) { histent->word = Strsave(word.s); histent->next = xmalloc(sizeof(*histent)); histent->next->prev = histent; histent = histent->next; } continue; } if ((type == TC_IF || type == TC_ELSE) && eq(word.s, STRthen)) level++; break; case TC_ENDIF: if (type == TC_IF || type == TC_ELSE) level--; break; case TC_FOREACH: case TC_WHILE: wlevel++; if (type == TC_BREAK) level++; break; case TC_END: if (type == TC_BRKSW) { if (wlevel == 0) { wp = whyles; if (wp) { whyles = wp->w_next; wpfree(wp); } } } if (type == TC_BREAK) level--; wlevel--; break; case TC_SWITCH: if (type == TC_SWITCH || type == TC_BRKSW) level++; break; case TC_ENDSW: if (type == TC_SWITCH || type == TC_BRKSW) level--; break; case TC_LABEL: if (type == TC_GOTO && getword(&word) && eq(word.s, goal)) level = -1; break; default: if (type != TC_GOTO && (type != TC_SWITCH || level != 0)) break; if (word.len == 0 || word.s[word.len - 1] != ':') break; word.s[--word.len] = 0; if ((type == TC_GOTO && eq(word.s, goal)) || (type == TC_SWITCH && eq(word.s, STRdefault))) level = -1; break; case TC_CASE: if (type != TC_SWITCH || level != 0) break; (void) getword(&word); if (word.len != 0 && word.s[word.len - 1] == ':') word.s[--word.len] = 0; cp = strip(Dfix1(word.s)); cleanup_push(cp, xfree); if (Gmatch(goal, cp)) level = -1; cleanup_until(cp); break; case TC_DEFAULT: if (type == TC_SWITCH && level == 0) level = -1; break; } if (intty) { ohistent->prev = histgetword(histent); ohistent->prev->next = ohistent; savehist(ohistent, 0); freelex(ohistent); xfree(ohistent); } else (void) getword(NULL); } while (level >= 0); end: cleanup_until(&word); } static struct wordent * histgetword(struct wordent *histent) { int first; eChar c, d; int e; struct Strbuf *tmp; tmp = xmalloc(sizeof(*tmp)); tmp->size = 0; tmp->s = NULL; c = readc(1); d = 0; e = 0; for (;;) { tmp->len = 0; Strbuf_terminate (tmp); while (c == ' ' || c == '\t') c = readc(1); if (c == '#') do c = readc(1); while (c != CHAR_ERR && c != '\n'); if (c == CHAR_ERR) goto past; if (c == '\n') goto nl; unreadc(c); first = 1; do { e = (c == '\\'); c = readc(1); if (c == '\\' && !e) { if ((c = readc(1)) == '\n') { e = 1; c = ' '; } else { unreadc(c); c = '\\'; } } if ((c == '\'' || c == '"') && !e) { if (d == 0) d = c; else if (d == c) d = 0; } if (c == CHAR_ERR) goto past; Strbuf_append1(tmp, (Char) c); if (!first && !d && c == '(' && !e) { break; } first = 0; } while (d || e || (c != ' ' && c != '\t' && c != '\n')); tmp->len--; if (tmp->len) { Strbuf_terminate(tmp); histent->word = Strsave(tmp->s); histent->next = xmalloc(sizeof (*histent)); histent->next->prev = histent; histent = histent->next; } if (c == '\n') { nl: tmp->len = 0; Strbuf_append1(tmp, (Char) c); Strbuf_terminate(tmp); histent->word = Strsave(tmp->s); return histent; } } past: switch (Stype) { case TC_IF: stderror(ERR_NAME | ERR_NOTFOUND, "then/endif"); break; case TC_ELSE: stderror(ERR_NAME | ERR_NOTFOUND, "endif"); break; case TC_BRKSW: case TC_SWITCH: stderror(ERR_NAME | ERR_NOTFOUND, "endsw"); break; case TC_BREAK: stderror(ERR_NAME | ERR_NOTFOUND, "end"); break; case TC_GOTO: setname(short2str(Sgoal)); stderror(ERR_NAME | ERR_NOTFOUND, "label"); break; default: break; } /* NOTREACHED */ return NULL; } static int getword(struct Strbuf *wp) { int found = 0, first; eChar c, d; if (wp) wp->len = 0; c = readc(1); d = 0; do { while (c == ' ' || c == '\t') c = readc(1); if (c == '#') do c = readc(1); while (c != CHAR_ERR && c != '\n'); if (c == CHAR_ERR) goto past; if (c == '\n') { if (wp) break; return (0); } unreadc(c); found = 1; first = 1; do { c = readc(1); if (c == '\\' && (c = readc(1)) == '\n') c = ' '; if (c == '\'' || c == '"') { if (d == 0) d = c; else if (d == c) d = 0; } if (c == CHAR_ERR) goto past; if (wp) Strbuf_append1(wp, (Char) c); if (!d && c == ')') { if (!first && wp) { goto past_word_end; } else { if (wp) { wp->len = 1; Strbuf_terminate(wp); } return found; } } if (!first && !d && c == '(') { if (wp) goto past_word_end; else break; } first = 0; } while ((d || (c != ' ' && c != '\t')) && c != '\n'); } while (wp == 0); past_word_end: unreadc(c); if (found) { wp->len--; Strbuf_terminate(wp); } return (found); past: switch (Stype) { case TC_IF: stderror(ERR_NAME | ERR_NOTFOUND, "then/endif"); break; case TC_ELSE: stderror(ERR_NAME | ERR_NOTFOUND, "endif"); break; case TC_BRKSW: case TC_SWITCH: stderror(ERR_NAME | ERR_NOTFOUND, "endsw"); break; case TC_BREAK: stderror(ERR_NAME | ERR_NOTFOUND, "end"); break; case TC_GOTO: setname(short2str(Sgoal)); stderror(ERR_NAME | ERR_NOTFOUND, "label"); break; default: break; } /* NOTREACHED */ return (0); } static void toend(void) { if (whyles->w_end.type == TCSH_F_SEEK && whyles->w_end.f_seek == 0) { search(TC_BREAK, 0, NULL); btell(&whyles->w_end); whyles->w_end.f_seek--; } else { bseek(&whyles->w_end); } wfree(); } static void wpfree(struct whyle *wp) { if (wp->w_fe0) blkfree(wp->w_fe0); xfree(wp->w_fename); xfree(wp); } void wfree(void) { struct Ain o; struct whyle *nwp; #ifdef lint nwp = NULL; /* sun lint is dumb! */ #endif #ifdef FDEBUG static const char foo[] = "IAFE"; #endif /* FDEBUG */ btell(&o); #ifdef FDEBUG xprintf("o->type %c o->a_seek %d o->f_seek %d\n", foo[o.type + 1], o.a_seek, o.f_seek); #endif /* FDEBUG */ for (; whyles; whyles = nwp) { struct whyle *wp = whyles; nwp = wp->w_next; #ifdef FDEBUG xprintf("start->type %c start->a_seek %d start->f_seek %d\n", foo[wp->w_start.type+1], wp->w_start.a_seek, wp->w_start.f_seek); xprintf("end->type %c end->a_seek %d end->f_seek %d\n", foo[wp->w_end.type + 1], wp->w_end.a_seek, wp->w_end.f_seek); #endif /* FDEBUG */ /* * XXX: We free loops that have different seek types. */ if (wp->w_end.type != TCSH_I_SEEK && wp->w_start.type == wp->w_end.type && wp->w_start.type == o.type) { if (wp->w_end.type == TCSH_F_SEEK) { if (o.f_seek >= wp->w_start.f_seek && (wp->w_end.f_seek == 0 || o.f_seek < wp->w_end.f_seek)) break; } else { if (o.a_seek >= wp->w_start.a_seek && (wp->w_end.a_seek == 0 || o.a_seek < wp->w_end.a_seek)) break; } } wpfree(wp); } } /*ARGSUSED*/ void doecho(Char **v, struct command *c) { USE(c); xecho(' ', v); } /*ARGSUSED*/ void doglob(Char **v, struct command *c) { USE(c); xecho(0, v); flush(); } static void xecho(int sep, Char **v) { Char *cp, **globbed = NULL; int nonl = 0; int echo_style = ECHO_STYLE; struct varent *vp; if ((vp = adrof(STRecho_style)) != NULL && vp->vec != NULL && vp->vec[0] != NULL) { if (Strcmp(vp->vec[0], STRbsd) == 0) echo_style = BSD_ECHO; else if (Strcmp(vp->vec[0], STRsysv) == 0) echo_style = SYSV_ECHO; else if (Strcmp(vp->vec[0], STRboth) == 0) echo_style = BOTH_ECHO; else if (Strcmp(vp->vec[0], STRnone) == 0) echo_style = NONE_ECHO; } v++; if (*v == 0) goto done; if (setintr) { int old_pintr_disabled; pintr_push_enable(&old_pintr_disabled); v = glob_all_or_error(v); cleanup_until(&old_pintr_disabled); } else { v = glob_all_or_error(v); } globbed = v; if (globbed != NULL) cleanup_push(globbed, blk_cleanup); if ((echo_style & BSD_ECHO) != 0 && sep == ' ' && *v && eq(*v, STRmn)) nonl++, v++; while ((cp = *v++) != 0) { Char c; if (setintr) { int old_pintr_disabled; pintr_push_enable(&old_pintr_disabled); cleanup_until(&old_pintr_disabled); } while ((c = *cp++) != 0) { if ((echo_style & SYSV_ECHO) != 0 && c == '\\') { switch (c = *cp++) { case 'a': c = '\a'; break; case 'b': c = '\b'; break; case 'c': nonl = 1; goto done; case 'e': #if 0 /* Windows does not understand \e */ c = '\e'; #else c = CTL_ESC('\033'); #endif break; case 'f': c = '\f'; break; case 'n': c = '\n'; break; case 'r': c = '\r'; break; case 't': c = '\t'; break; case 'v': c = '\v'; break; case '\\': c = '\\'; break; case '0': c = 0; if (*cp >= '0' && *cp < '8') c = c * 8 + *cp++ - '0'; if (*cp >= '0' && *cp < '8') c = c * 8 + *cp++ - '0'; if (*cp >= '0' && *cp < '8') c = c * 8 + *cp++ - '0'; break; case '\0': c = '\\'; cp--; break; default: xputchar('\\' | QUOTE); break; } } xputwchar(c | QUOTE); } if (*v) xputchar(sep | QUOTE); } done: if (sep && nonl == 0) xputchar('\n'); else flush(); if (globbed != NULL) cleanup_until(globbed); } /* check whether an environment variable should invoke 'set_locale()' */ static int islocale_var(Char *var) { static Char *locale_vars[] = { STRLANG, STRLC_ALL, STRLC_CTYPE, STRLC_NUMERIC, STRLC_TIME, STRLC_COLLATE, STRLC_MESSAGES, STRLC_MONETARY, 0 }; Char **v; for (v = locale_vars; *v; ++v) if (eq(var, *v)) return 1; return 0; } static void xlate_cr_cleanup(void *dummy) { USE(dummy); xlate_cr = 0; } /*ARGSUSED*/ void doprintenv(Char **v, struct command *c) { Char *e; USE(c); v++; if (*v == 0) { Char **ep; xlate_cr = 1; cleanup_push(&xlate_cr, xlate_cr_cleanup); for (ep = STR_environ; *ep; ep++) { if (setintr) { int old_pintr_disabled; pintr_push_enable(&old_pintr_disabled); cleanup_until(&old_pintr_disabled); } xprintf("%S\n", *ep); } cleanup_until(&xlate_cr); } else if ((e = tgetenv(*v)) != NULL) { int old_output_raw; old_output_raw = output_raw; output_raw = 1; cleanup_push(&old_output_raw, output_raw_restore); xprintf("%S\n", e); cleanup_until(&old_output_raw); } else setcopy(STRstatus, STR1, VAR_READWRITE); } /* from "Karl Berry." -- for NeXT things (and anything else with a modern compiler) */ /*ARGSUSED*/ void dosetenv(Char **v, struct command *c) { Char *vp, *lp; USE(c); if (*++v == 0) { doprintenv(--v, 0); return; } vp = *v++; lp = vp; if (!letter(*lp)) stderror(ERR_NAME | ERR_VARBEGIN); do { lp++; } while (alnum(*lp) || *lp == '.'); if (*lp != '\0') stderror(ERR_NAME | ERR_VARALNUM); if ((lp = *v++) == 0) lp = STRNULL; lp = globone(lp, G_APPEND); cleanup_push(lp, xfree); tsetenv(vp, lp); if (eq(vp, STRKPATH)) { importpath(lp); dohash(NULL, NULL); cleanup_until(lp); return; } #ifdef apollo if (eq(vp, STRSYSTYPE)) { dohash(NULL, NULL); cleanup_until(lp); return; } #endif /* apollo */ /* dspkanji/dspmbyte autosetting */ /* PATCH IDEA FROM Issei.Suzuki VERY THANKS */ #if defined(DSPMBYTE) - if(eq(vp, STRLANG) && !adrof(CHECK_MBYTEVAR)) { + if (eq(vp, STRLANG) && !adrof(CHECK_MBYTEVAR)) { autoset_dspmbyte(lp); } #endif if (islocale_var(vp)) { #ifdef NLS int k; # ifdef SETLOCALEBUG dont_free = 1; # endif /* SETLOCALEBUG */ (void) setlocale(LC_ALL, ""); # ifdef LC_COLLATE (void) setlocale(LC_COLLATE, ""); # endif # ifdef LC_CTYPE (void) setlocale(LC_CTYPE, ""); /* for iscntrl */ # endif /* LC_CTYPE */ # if defined(AUTOSET_KANJI) autoset_kanji(); # endif /* AUTOSET_KANJI */ # ifdef NLS_CATALOGS # ifdef LC_MESSAGES (void) setlocale(LC_MESSAGES, ""); # endif /* LC_MESSAGES */ nlsclose(); nlsinit(); # endif /* NLS_CATALOGS */ # ifdef SETLOCALEBUG dont_free = 0; # endif /* SETLOCALEBUG */ # ifdef STRCOLLBUG fix_strcoll_bug(); # endif /* STRCOLLBUG */ tw_cmd_free(); /* since the collation sequence has changed */ for (k = 0200; k <= 0377 && !Isprint(CTL_ESC(k)); k++) continue; AsciiOnly = MB_CUR_MAX == 1 && k > 0377; #else /* !NLS */ AsciiOnly = 0; #endif /* NLS */ NLSMapsAreInited = 0; ed_Init(); if (MapsAreInited && !NLSMapsAreInited) ed_InitNLSMaps(); cleanup_until(lp); return; } #ifdef NLS_CATALOGS if (eq(vp, STRNLSPATH)) { nlsclose(); nlsinit(); } #endif if (eq(vp, STRNOREBIND)) { NoNLSRebind = 1; MapsAreInited = 0; NLSMapsAreInited = 0; ed_InitMaps(); cleanup_until(lp); return; } #ifdef WINNT_NATIVE if (eq(vp, STRtcshlang)) { nlsinit(); cleanup_until(lp); return; } #endif /* WINNT_NATIVE */ if (eq(vp, STRKTERM)) { char *t; setv(STRterm, quote(lp), VAR_READWRITE); /* lp memory used here */ cleanup_ignore(lp); cleanup_until(lp); t = short2str(lp); if (noediting && strcmp(t, "unknown") != 0 && strcmp(t,"dumb") != 0) { editing = 1; noediting = 0; setNS(STRedit); } GotTermCaps = 0; ed_Init(); return; } if (eq(vp, STRKHOME)) { Char *canon; /* * convert to canonical pathname (possibly resolving symlinks) */ - canon = dcanon(lp, lp); cleanup_ignore(lp); - cleanup_until(lp); + canon = dcanon(lp, lp); cleanup_push(canon, xfree); setv(STRhome, quote(canon), VAR_READWRITE); /* lp memory used here */ cleanup_ignore(canon); cleanup_until(canon); /* fix directory stack for new tilde home */ dtilde(); return; } if (eq(vp, STRKSHLVL)) { setv(STRshlvl, quote(lp), VAR_READWRITE); /* lp memory used here */ cleanup_ignore(lp); cleanup_until(lp); return; } if (eq(vp, STRKUSER)) { setv(STRuser, quote(lp), VAR_READWRITE); /* lp memory used here */ cleanup_ignore(lp); cleanup_until(lp); return; } if (eq(vp, STRKGROUP)) { setv(STRgroup, quote(lp), VAR_READWRITE); /* lp memory used here */ cleanup_ignore(lp); cleanup_until(lp); return; } #ifdef COLOR_LS_F if (eq(vp, STRLS_COLORS)) { parseLS_COLORS(lp); cleanup_until(lp); return; } if (eq(vp, STRLSCOLORS)) { parseLSCOLORS(lp); cleanup_until(lp); return; } #endif /* COLOR_LS_F */ #ifdef SIG_WINDOW /* * Load/Update $LINES $COLUMNS */ if ((eq(lp, STRNULL) && (eq(vp, STRLINES) || eq(vp, STRCOLUMNS))) || eq(vp, STRTERMCAP)) { cleanup_until(lp); check_window_size(1); return; } /* * Change the size to the one directed by $LINES and $COLUMNS */ if (eq(vp, STRLINES) || eq(vp, STRCOLUMNS)) { #if 0 GotTermCaps = 0; #endif cleanup_until(lp); ed_Init(); return; } #endif /* SIG_WINDOW */ cleanup_until(lp); } /*ARGSUSED*/ void dounsetenv(Char **v, struct command *c) { Char **ep, *p, *n, *name; int i, maxi; USE(c); /* * Find the longest environment variable */ for (maxi = 0, ep = STR_environ; *ep; ep++) { for (i = 0, p = *ep; *p && *p != '='; p++, i++) continue; if (i > maxi) maxi = i; } name = xmalloc((maxi + 1) * sizeof(Char)); cleanup_push(name, xfree); while (++v && *v) for (maxi = 1; maxi;) for (maxi = 0, ep = STR_environ; *ep; ep++) { for (n = name, p = *ep; *p && *p != '='; *n++ = *p++) continue; *n = '\0'; if (!Gmatch(name, *v)) continue; maxi = 1; /* Unset the name. This wasn't being done until * later but most of the stuff following won't * work (particularly the setlocale() and getenv() * stuff) as intended until the name is actually * removed. (sg) */ Unsetenv(name); if (eq(name, STRNOREBIND)) { NoNLSRebind = 0; MapsAreInited = 0; NLSMapsAreInited = 0; ed_InitMaps(); } #ifdef apollo else if (eq(name, STRSYSTYPE)) dohash(NULL, NULL); #endif /* apollo */ else if (islocale_var(name)) { #ifdef NLS int k; # ifdef SETLOCALEBUG dont_free = 1; # endif /* SETLOCALEBUG */ (void) setlocale(LC_ALL, ""); # ifdef LC_COLLATE (void) setlocale(LC_COLLATE, ""); # endif # ifdef LC_CTYPE (void) setlocale(LC_CTYPE, ""); /* for iscntrl */ # endif /* LC_CTYPE */ # ifdef NLS_CATALOGS # ifdef LC_MESSAGES (void) setlocale(LC_MESSAGES, ""); # endif /* LC_MESSAGES */ nlsclose(); nlsinit(); # endif /* NLS_CATALOGS */ # ifdef SETLOCALEBUG dont_free = 0; # endif /* SETLOCALEBUG */ # ifdef STRCOLLBUG fix_strcoll_bug(); # endif /* STRCOLLBUG */ tw_cmd_free();/* since the collation sequence has changed */ for (k = 0200; k <= 0377 && !Isprint(CTL_ESC(k)); k++) continue; AsciiOnly = MB_CUR_MAX == 1 && k > 0377; #else /* !NLS */ AsciiOnly = getenv("LANG") == NULL && getenv("LC_CTYPE") == NULL; #endif /* NLS */ NLSMapsAreInited = 0; ed_Init(); if (MapsAreInited && !NLSMapsAreInited) ed_InitNLSMaps(); } #ifdef WINNT_NATIVE else if (eq(name,(STRtcshlang))) { nls_dll_unload(); nlsinit(); } #endif /* WINNT_NATIVE */ #ifdef COLOR_LS_F else if (eq(name, STRLS_COLORS)) parseLS_COLORS(n); else if (eq(name, STRLSCOLORS)) parseLSCOLORS(n); #endif /* COLOR_LS_F */ #ifdef NLS_CATALOGS else if (eq(name, STRNLSPATH)) { nlsclose(); nlsinit(); } #endif /* * start again cause the environment changes */ break; } cleanup_until(name); } void tsetenv(const Char *name, const Char *val) { #ifdef SETENV_IN_LIB /* * XXX: This does not work right, since tcsh cannot track changes to * the environment this way. (the builtin setenv without arguments does * not print the right stuff neither does unsetenv). This was for Mach, * it is not needed anymore. */ #undef setenv char *cname; if (name == NULL) return; cname = strsave(short2str(name)); setenv(cname, short2str(val), 1); xfree(cname); #else /* !SETENV_IN_LIB */ Char **ep = STR_environ; const Char *ccp; Char *cp, *dp; Char *blk[2]; Char **oep = ep; #ifdef WINNT_NATIVE nt_set_env(name,val); #endif /* WINNT_NATIVE */ for (; *ep; ep++) { #ifdef WINNT_NATIVE for (ccp = name, dp = *ep; *ccp && Tolower(*ccp & TRIM) == Tolower(*dp); ccp++, dp++) #else for (ccp = name, dp = *ep; *ccp && (*ccp & TRIM) == *dp; ccp++, dp++) #endif /* WINNT_NATIVE */ continue; if (*ccp != 0 || *dp != '=') continue; cp = Strspl(STRequal, val); xfree(*ep); *ep = strip(Strspl(name, cp)); xfree(cp); blkfree((Char **) environ); environ = short2blk(STR_environ); return; } cp = Strspl(name, STRequal); blk[0] = strip(Strspl(cp, val)); xfree(cp); blk[1] = 0; STR_environ = blkspl(STR_environ, blk); blkfree((Char **) environ); environ = short2blk(STR_environ); xfree(oep); #endif /* SETENV_IN_LIB */ } void Unsetenv(Char *name) { Char **ep = STR_environ; Char *cp, *dp; Char **oep = ep; #ifdef WINNT_NATIVE nt_set_env(name,NULL); #endif /*WINNT_NATIVE */ for (; *ep; ep++) { for (cp = name, dp = *ep; *cp && *cp == *dp; cp++, dp++) continue; if (*cp != 0 || *dp != '=') continue; cp = *ep; *ep = 0; STR_environ = blkspl(STR_environ, ep + 1); blkfree((Char **) environ); environ = short2blk(STR_environ); *ep = cp; xfree(cp); xfree(oep); return; } } /*ARGSUSED*/ void doumask(Char **v, struct command *c) { Char *cp = v[1]; int i; USE(c); if (cp == 0) { i = (int)umask(0); (void) umask(i); xprintf("%o\n", i); return; } i = 0; while (Isdigit(*cp) && *cp != '8' && *cp != '9') i = i * 8 + *cp++ - '0'; if (*cp || i < 0 || i > 0777) stderror(ERR_NAME | ERR_MASK); (void) umask(i); } #ifndef HAVENOLIMIT # ifndef BSDLIMIT typedef long RLIM_TYPE; # ifdef _OSD_POSIX /* BS2000 */ # include # endif # ifndef RLIM_INFINITY # if !defined(_MINIX) && !defined(__clipper__) && !defined(_CRAY) extern RLIM_TYPE ulimit(); # endif /* ! _MINIX && !__clipper__ */ # define RLIM_INFINITY 0x003fffff # define RLIMIT_FSIZE 1 # endif /* RLIM_INFINITY */ # ifdef aiws # define toset(a) (((a) == 3) ? 1004 : (a) + 1) # define RLIMIT_DATA 3 # define RLIMIT_STACK 1005 # else /* aiws */ # define toset(a) ((a) + 1) # endif /* aiws */ # else /* BSDLIMIT */ # if (defined(BSD4_4) || defined(__linux__) || defined(__GNU__) || defined(__GLIBC__) || (HPUXVERSION >= 1100)) && !defined(__386BSD__) typedef rlim_t RLIM_TYPE; # else # if defined(SOLARIS2) || (defined(sgi) && SYSVREL > 3) typedef rlim_t RLIM_TYPE; # else # if defined(_SX) typedef long long RLIM_TYPE; # else /* !_SX */ typedef unsigned long RLIM_TYPE; # endif /* _SX */ # endif /* SOLARIS2 || (sgi && SYSVREL > 3) */ # endif /* BSD4_4 && !__386BSD__ */ # endif /* BSDLIMIT */ # if (HPUXVERSION > 700) && (HPUXVERSION < 1100) && defined(BSDLIMIT) /* Yes hpux8.0 has limits but does not make them public */ /* Yes, we could have defined _KERNEL, and -I/etc/conf/h, but is that better? */ # ifndef RLIMIT_CPU # define RLIMIT_CPU 0 # define RLIMIT_FSIZE 1 # define RLIMIT_DATA 2 # define RLIMIT_STACK 3 # define RLIMIT_CORE 4 # define RLIMIT_RSS 5 # define RLIMIT_NOFILE 6 # endif /* RLIMIT_CPU */ # ifndef RLIM_INFINITY # define RLIM_INFINITY 0x7fffffff # endif /* RLIM_INFINITY */ /* * old versions of HP/UX counted limits in 512 bytes */ # ifndef SIGRTMIN # define FILESIZE512 # endif /* SIGRTMIN */ # endif /* (HPUXVERSION > 700) && (HPUXVERSION < 1100) && BSDLIMIT */ # if SYSVREL > 3 && defined(BSDLIMIT) && !defined(_SX) /* In order to use rusage, we included "/usr/ucbinclude/sys/resource.h" in */ /* sh.h. However, some SVR4 limits are defined in . Rather */ /* than include both and get warnings, we define the extra SVR4 limits here. */ /* XXX: I don't understand if RLIMIT_AS is defined, why don't we define */ /* RLIMIT_VMEM based on it? */ # ifndef RLIMIT_VMEM # define RLIMIT_VMEM 6 # endif # ifndef RLIMIT_AS # define RLIMIT_AS RLIMIT_VMEM # endif # endif /* SYSVREL > 3 && BSDLIMIT */ # if (defined(__linux__) || defined(__GNU__) || defined(__GLIBC__)) # if defined(RLIMIT_AS) && !defined(RLIMIT_VMEM) # define RLIMIT_VMEM RLIMIT_AS # endif /* * Oh well, has it, but does not * Linux headers: When the left hand does not know what the right hand does. */ # if defined(RLIMIT_RTPRIO) && !defined(RLIMIT_RTTIME) # define RLIMIT_RTTIME (RLIMIT_RTPRIO + 1) # endif # endif struct limits limits[] = { # ifdef RLIMIT_CPU { RLIMIT_CPU, "cputime", 1, "seconds" }, # endif /* RLIMIT_CPU */ # ifdef RLIMIT_FSIZE # ifndef aiws { RLIMIT_FSIZE, "filesize", 1024, "kbytes" }, # else { RLIMIT_FSIZE, "filesize", 512, "blocks" }, # endif /* aiws */ # endif /* RLIMIT_FSIZE */ # ifdef RLIMIT_DATA { RLIMIT_DATA, "datasize", 1024, "kbytes" }, # endif /* RLIMIT_DATA */ # ifdef RLIMIT_STACK # ifndef aiws { RLIMIT_STACK, "stacksize", 1024, "kbytes" }, # else { RLIMIT_STACK, "stacksize", 1024 * 1024, "kbytes"}, # endif /* aiws */ # endif /* RLIMIT_STACK */ # ifdef RLIMIT_CORE { RLIMIT_CORE, "coredumpsize", 1024, "kbytes" }, # endif /* RLIMIT_CORE */ # ifdef RLIMIT_RSS { RLIMIT_RSS, "memoryuse", 1024, "kbytes" }, # endif /* RLIMIT_RSS */ # ifdef RLIMIT_UMEM { RLIMIT_UMEM, "memoryuse", 1024, "kbytes" }, # endif /* RLIMIT_UMEM */ # ifdef RLIMIT_VMEM { RLIMIT_VMEM, "vmemoryuse", 1024, "kbytes" }, # endif /* RLIMIT_VMEM */ # if defined(RLIMIT_HEAP) /* found on BS2000/OSD systems */ { RLIMIT_HEAP, "heapsize", 1024, "kbytes" }, # endif /* RLIMIT_HEAP */ # ifdef RLIMIT_NOFILE { RLIMIT_NOFILE, "descriptors", 1, "" }, # endif /* RLIMIT_NOFILE */ # ifdef RLIMIT_NPTS { RLIMIT_NPTS, "pseudoterminals", 1, "" }, # endif /* RLIMIT_NPTS */ # ifdef RLIMIT_KQUEUES { RLIMIT_KQUEUES, "kqueues", 1, "" }, # endif /* RLIMIT_KQUEUES */ # ifdef RLIMIT_CONCUR { RLIMIT_CONCUR, "concurrency", 1, "thread(s)" }, # endif /* RLIMIT_CONCUR */ # ifdef RLIMIT_MEMLOCK { RLIMIT_MEMLOCK, "memorylocked", 1024, "kbytes" }, # endif /* RLIMIT_MEMLOCK */ # ifdef RLIMIT_NPROC { RLIMIT_NPROC, "maxproc", 1, "" }, # endif /* RLIMIT_NPROC */ # ifdef RLIMIT_NTHR { RLIMIT_NTHR, "maxthread", 1, "" }, # endif /* RLIMIT_NTHR */ # if defined(RLIMIT_OFILE) && !defined(RLIMIT_NOFILE) { RLIMIT_OFILE, "openfiles", 1, "" }, # endif /* RLIMIT_OFILE && !defined(RLIMIT_NOFILE) */ # ifdef RLIMIT_SBSIZE { RLIMIT_SBSIZE, "sbsize", 1, "" }, # endif /* RLIMIT_SBSIZE */ # ifdef RLIMIT_SWAP { RLIMIT_SWAP, "swapsize", 1024, "kbytes" }, # endif /* RLIMIT_SWAP */ # ifdef RLIMIT_LOCKS { RLIMIT_LOCKS, "maxlocks", 1, "" }, # endif /* RLIMIT_LOCKS */ # ifdef RLIMIT_POSIXLOCKS { RLIMIT_POSIXLOCKS,"posixlocks", 1, "" }, # endif /* RLIMIT_POSIXLOCKS */ # ifdef RLIMIT_SIGPENDING { RLIMIT_SIGPENDING,"maxsignal", 1, "" }, # endif /* RLIMIT_SIGPENDING */ # ifdef RLIMIT_MSGQUEUE { RLIMIT_MSGQUEUE, "maxmessage", 1, "" }, # endif /* RLIMIT_MSGQUEUE */ # ifdef RLIMIT_NICE { RLIMIT_NICE, "maxnice", 1, "" }, # endif /* RLIMIT_NICE */ # ifdef RLIMIT_RTPRIO { RLIMIT_RTPRIO, "maxrtprio", 1, "" }, # endif /* RLIMIT_RTPRIO */ # ifdef RLIMIT_RTTIME { RLIMIT_RTTIME, "maxrttime", 1, "usec" }, # endif /* RLIMIT_RTTIME */ { -1, NULL, 0, NULL } }; static struct limits *findlim (Char *); static RLIM_TYPE getval (struct limits *, Char **); static int strtail (Char *, const char *); static void limtail (Char *, const char *); static void limtail2 (Char *, const char *, const char *); static void plim (struct limits *, int); static int setlim (struct limits *, int, RLIM_TYPE); #ifdef convex static RLIM_TYPE restrict_limit(double value) { /* * is f too large to cope with? return the maximum or minimum int */ if (value > (double) INT_MAX) return (RLIM_TYPE) INT_MAX; else if (value < (double) INT_MIN) return (RLIM_TYPE) INT_MIN; else return (RLIM_TYPE) value; } #else /* !convex */ # define restrict_limit(x) ((RLIM_TYPE) (x)) #endif /* convex */ static struct limits * findlim(Char *cp) { struct limits *lp, *res; res = NULL; for (lp = limits; lp->limconst >= 0; lp++) if (prefix(cp, str2short(lp->limname))) { if (res) stderror(ERR_NAME | ERR_AMBIG); res = lp; } if (res) return (res); stderror(ERR_NAME | ERR_LIMIT); /* NOTREACHED */ return (0); } /*ARGSUSED*/ void dolimit(Char **v, struct command *c) { struct limits *lp; RLIM_TYPE limit; int hard = 0; USE(c); v++; if (*v && eq(*v, STRmh)) { hard = 1; v++; } if (*v == 0) { for (lp = limits; lp->limconst >= 0; lp++) plim(lp, hard); return; } lp = findlim(v[0]); if (v[1] == 0) { plim(lp, hard); return; } limit = getval(lp, v + 1); if (setlim(lp, hard, limit) < 0) stderror(ERR_SILENT); } static RLIM_TYPE getval(struct limits *lp, Char **v) { float f; Char *cp = *v++; f = atof(short2str(cp)); # ifdef convex /* * is f too large to cope with. limit f to minint, maxint - X-6768 by * strike */ if ((f < (double) INT_MIN) || (f > (double) INT_MAX)) { stderror(ERR_NAME | ERR_TOOLARGE); } # endif /* convex */ while (Isdigit(*cp) || *cp == '.' || *cp == 'e' || *cp == 'E') cp++; if (*cp == 0) { if (*v == 0) return restrict_limit((f * lp->limdiv) + 0.5); cp = *v; } switch (*cp) { # ifdef RLIMIT_CPU case ':': if (lp->limconst != RLIMIT_CPU) goto badscal; return f == 0.0 ? (RLIM_TYPE) 0 : restrict_limit((f * 60.0 + atof(short2str(cp + 1)))); case 'h': if (lp->limconst != RLIMIT_CPU) goto badscal; limtail(cp, "hours"); f *= 3600.0; break; # endif /* RLIMIT_CPU */ case 'm': # ifdef RLIMIT_CPU if (lp->limconst == RLIMIT_CPU) { limtail(cp, "minutes"); f *= 60.0; break; } # endif /* RLIMIT_CPU */ limtail2(cp, "megabytes", "mbytes"); f *= 1024.0 * 1024.0; break; # ifdef RLIMIT_CPU case 's': if (lp->limconst != RLIMIT_CPU) goto badscal; limtail(cp, "seconds"); break; # endif /* RLIMIT_CPU */ case 'G': *cp = 'g'; /*FALLTHROUGH*/ case 'g': # ifdef RLIMIT_CPU if (lp->limconst == RLIMIT_CPU) goto badscal; # endif /* RLIMIT_CPU */ limtail2(cp, "gigabytes", "gbytes"); f *= 1024.0 * 1024.0 * 1024.0; break; case 'M': # ifdef RLIMIT_CPU if (lp->limconst == RLIMIT_CPU) goto badscal; # endif /* RLIMIT_CPU */ *cp = 'm'; limtail2(cp, "megabytes", "mbytes"); f *= 1024.0 * 1024.0; break; case 'k': # ifdef RLIMIT_CPU if (lp->limconst == RLIMIT_CPU) goto badscal; # endif /* RLIMIT_CPU */ limtail2(cp, "kilobytes", "kbytes"); f *= 1024.0; break; case 'b': # ifdef RLIMIT_CPU if (lp->limconst == RLIMIT_CPU) goto badscal; # endif /* RLIMIT_CPU */ limtail(cp, "blocks"); f *= 512.0; break; case 'u': limtail(cp, "unlimited"); return ((RLIM_TYPE) RLIM_INFINITY); default: # ifdef RLIMIT_CPU badscal: # endif /* RLIMIT_CPU */ stderror(ERR_NAME | ERR_SCALEF); } # ifdef convex return f == 0.0 ? (RLIM_TYPE) 0 : restrict_limit((f + 0.5)); # else f += 0.5; if (f > (float) ((RLIM_TYPE) RLIM_INFINITY)) return ((RLIM_TYPE) RLIM_INFINITY); else return ((RLIM_TYPE) f); # endif /* convex */ } static int strtail(Char *cp, const char *str) { while (*cp && *cp == (Char)*str) cp++, str++; return (*cp != '\0'); } static void limtail(Char *cp, const char *str) { if (strtail(cp, str)) stderror(ERR_BADSCALE, str); } static void limtail2(Char *cp, const char *str1, const char *str2) { if (strtail(cp, str1) && strtail(cp, str2)) stderror(ERR_BADSCALE, str1); } /*ARGSUSED*/ static void plim(struct limits *lp, int hard) { # ifdef BSDLIMIT struct rlimit rlim; # endif /* BSDLIMIT */ RLIM_TYPE limit; int xdiv = lp->limdiv; xprintf("%-13.13s", lp->limname); # ifndef BSDLIMIT limit = ulimit(lp->limconst, 0); # ifdef aiws if (lp->limconst == RLIMIT_DATA) limit -= 0x20000000; # endif /* aiws */ # else /* BSDLIMIT */ (void) getrlimit(lp->limconst, &rlim); limit = hard ? rlim.rlim_max : rlim.rlim_cur; # endif /* BSDLIMIT */ # if !defined(BSDLIMIT) || defined(FILESIZE512) /* * Christos: filesize comes in 512 blocks. we divide by 2 to get 1024 * blocks. Note we cannot pre-multiply cause we might overflow (A/UX) */ if (lp->limconst == RLIMIT_FSIZE) { if (limit >= (RLIM_INFINITY / 512)) limit = RLIM_INFINITY; else xdiv = (xdiv == 1024 ? 2 : 1); } # endif /* !BSDLIMIT || FILESIZE512 */ if (limit == RLIM_INFINITY) xprintf("unlimited"); else # if defined(RLIMIT_CPU) && defined(_OSD_POSIX) if (lp->limconst == RLIMIT_CPU && (unsigned long)limit >= 0x7ffffffdUL) xprintf("unlimited"); else # endif # ifdef RLIMIT_CPU if (lp->limconst == RLIMIT_CPU) psecs(limit); else # endif /* RLIMIT_CPU */ xprintf("%ld %s", (long) (limit / xdiv), lp->limscale); xputchar('\n'); } /*ARGSUSED*/ void dounlimit(Char **v, struct command *c) { struct limits *lp; int lerr = 0; int hard = 0; int force = 0; USE(c); while (*++v && **v == '-') { Char *vp = *v; while (*++vp) switch (*vp) { case 'f': force = 1; break; case 'h': hard = 1; break; default: stderror(ERR_ULIMUS); break; } } if (*v == 0) { for (lp = limits; lp->limconst >= 0; lp++) if (setlim(lp, hard, (RLIM_TYPE) RLIM_INFINITY) < 0) lerr++; if (!force && lerr) stderror(ERR_SILENT); return; } while (*v) { lp = findlim(*v++); if (setlim(lp, hard, (RLIM_TYPE) RLIM_INFINITY) < 0 && !force) stderror(ERR_SILENT); } } static int setlim(struct limits *lp, int hard, RLIM_TYPE limit) { # ifdef BSDLIMIT struct rlimit rlim; (void) getrlimit(lp->limconst, &rlim); # ifdef FILESIZE512 /* Even though hpux has setrlimit(), it expects fsize in 512 byte blocks */ if (limit != RLIM_INFINITY && lp->limconst == RLIMIT_FSIZE) limit /= 512; # endif /* FILESIZE512 */ if (hard) rlim.rlim_max = limit; else if (limit == RLIM_INFINITY && euid != 0) rlim.rlim_cur = rlim.rlim_max; else rlim.rlim_cur = limit; if (rlim.rlim_cur > rlim.rlim_max) rlim.rlim_max = rlim.rlim_cur; if (setrlimit(lp->limconst, &rlim) < 0) { # else /* BSDLIMIT */ if (limit != RLIM_INFINITY && lp->limconst == RLIMIT_FSIZE) limit /= 512; # ifdef aiws if (lp->limconst == RLIMIT_DATA) limit += 0x20000000; # endif /* aiws */ if (ulimit(toset(lp->limconst), limit) < 0) { # endif /* BSDLIMIT */ int err; char *op, *type; err = errno; op = strsave(limit == RLIM_INFINITY ? CGETS(15, 2, "remove") : CGETS(15, 3, "set")); cleanup_push(op, xfree); type = strsave(hard ? CGETS(15, 4, " hard") : ""); cleanup_push(type, xfree); xprintf(CGETS(15, 1, "%s: %s: Can't %s%s limit (%s)\n"), bname, lp->limname, op, type, strerror(err)); cleanup_until(op); return (-1); } return (0); } #endif /* !HAVENOLIMIT */ /*ARGSUSED*/ void dosuspend(Char **v, struct command *c) { #ifdef BSDJOBS struct sigaction old; #endif /* BSDJOBS */ USE(c); USE(v); if (loginsh) stderror(ERR_SUSPLOG); untty(); #ifdef BSDJOBS sigaction(SIGTSTP, NULL, &old); signal(SIGTSTP, SIG_DFL); (void) kill(0, SIGTSTP); /* the shell stops here */ sigaction(SIGTSTP, &old, NULL); #else /* !BSDJOBS */ stderror(ERR_JOBCONTROL); #endif /* BSDJOBS */ #ifdef BSDJOBS if (tpgrp != -1) { if (grabpgrp(FSHTTY, opgrp) == -1) stderror(ERR_SYSTEM, "tcgetpgrp", strerror(errno)); (void) setpgid(0, shpgrp); (void) tcsetpgrp(FSHTTY, shpgrp); } #endif /* BSDJOBS */ (void) setdisc(FSHTTY); } /* This is the dreaded EVAL built-in. * If you don't fiddle with file descriptors, and reset didfds, * this command will either ignore redirection inside or outside * its arguments, e.g. eval "date >x" vs. eval "date" >x * The stuff here seems to work, but I did it by trial and error rather * than really knowing what was going on. If tpgrp is zero, we are * probably a background eval, e.g. "eval date &", and we want to * make sure that any processes we start stay in our pgrp. * This is also the case for "time eval date" -- stay in same pgrp. * Otherwise, under stty tostop, processes will stop in the wrong * pgrp, with no way for the shell to get them going again. -IAN! */ struct doeval_state { Char **evalvec, *evalp; int didfds; #ifndef CLOSE_ON_EXEC int didcch; #endif int saveIN, saveOUT, saveDIAG; int SHIN, SHOUT, SHDIAG; }; static void doeval_cleanup(void *xstate) { struct doeval_state *state; state = xstate; evalvec = state->evalvec; evalp = state->evalp; doneinp = 0; #ifndef CLOSE_ON_EXEC didcch = state->didcch; #endif /* CLOSE_ON_EXEC */ didfds = state->didfds; if (state->saveIN != SHIN) xclose(SHIN); if (state->saveOUT != SHOUT) xclose(SHOUT); if (state->saveDIAG != SHDIAG) xclose(SHDIAG); close_on_exec(SHIN = dmove(state->saveIN, state->SHIN), 1); close_on_exec(SHOUT = dmove(state->saveOUT, state->SHOUT), 1); close_on_exec(SHDIAG = dmove(state->saveDIAG, state->SHDIAG), 1); if (didfds) { close_on_exec(dcopy(SHIN, 0), 1); close_on_exec(dcopy(SHOUT, 1), 1); close_on_exec(dcopy(SHDIAG, 2), 1); } } static Char **Ggv; /*ARGSUSED*/ void doeval(Char **v, struct command *c) { struct doeval_state state; int gflag, my_reenter; Char **gv; jmp_buf_t osetexit; USE(c); v++; if (*v == 0) return; gflag = tglob(v); if (gflag) { gv = v = globall(v, gflag); if (v == 0) stderror(ERR_NOMATCH); cleanup_push(gv, blk_cleanup); v = copyblk(v); } else { gv = NULL; v = copyblk(v); trim(v); } Ggv = gv; state.evalvec = evalvec; state.evalp = evalp; state.didfds = didfds; #ifndef CLOSE_ON_EXEC state.didcch = didcch; #endif /* CLOSE_ON_EXEC */ state.SHIN = SHIN; state.SHOUT = SHOUT; state.SHDIAG = SHDIAG; (void)close_on_exec(state.saveIN = dcopy(SHIN, -1), 1); (void)close_on_exec(state.saveOUT = dcopy(SHOUT, -1), 1); (void)close_on_exec(state.saveDIAG = dcopy(SHDIAG, -1), 1); cleanup_push(&state, doeval_cleanup); getexit(osetexit); /* PWP: setjmp/longjmp bugfix for optimizing compilers */ #ifdef cray my_reenter = 1; /* assume non-zero return val */ if (setexit() == 0) { my_reenter = 0; /* Oh well, we were wrong */ #else /* !cray */ if ((my_reenter = setexit()) == 0) { #endif /* cray */ evalvec = v; evalp = 0; (void)close_on_exec(SHIN = dcopy(0, -1), 1); (void)close_on_exec(SHOUT = dcopy(1, -1), 1); (void)close_on_exec(SHDIAG = dcopy(2, -1), 1); #ifndef CLOSE_ON_EXEC didcch = 0; #endif /* CLOSE_ON_EXEC */ didfds = 0; gv = Ggv; process(0); Ggv = gv; } if (my_reenter == 0) { cleanup_until(&state); if (Ggv) cleanup_until(Ggv); } resexit(osetexit); if (my_reenter) stderror(ERR_SILENT); } /*************************************************************************/ /* print list of builtin commands */ static void lbuffed_cleanup (void *dummy) { USE(dummy); lbuffed = 1; } /*ARGSUSED*/ void dobuiltins(Char **v, struct command *c) { /* would use print_by_column() in tw.parse.c but that assumes * we have an array of Char * to pass.. (sg) */ const struct biltins *b; int row, col, columns, rows; unsigned int w, maxwidth; USE(c); USE(v); lbuffed = 0; /* turn off line buffering */ cleanup_push(&lbuffed, lbuffed_cleanup); /* find widest string */ for (maxwidth = 0, b = bfunc; b < &bfunc[nbfunc]; ++b) maxwidth = max(maxwidth, strlen(b->bname)); ++maxwidth; /* for space */ columns = (TermH + 1) / maxwidth; /* PWP: terminal size change */ if (!columns) columns = 1; rows = (nbfunc + (columns - 1)) / columns; for (b = bfunc, row = 0; row < rows; row++) { for (col = 0; col < columns; col++) { if (b < &bfunc[nbfunc]) { w = strlen(b->bname); xprintf("%s", b->bname); if (col < (columns - 1)) /* Not last column? */ for (; w < maxwidth; w++) xputchar(' '); ++b; } } if (row < (rows - 1)) { if (Tty_raw_mode) xputchar('\r'); xputchar('\n'); } } #ifdef WINNT_NATIVE nt_print_builtins(maxwidth); #else if (Tty_raw_mode) xputchar('\r'); xputchar('\n'); #endif /* WINNT_NATIVE */ cleanup_until(&lbuffed); /* turn back on line buffering */ flush(); } #ifdef NLS_CATALOGS char * xcatgets(nl_catd ctd, int set_id, int msg_id, const char *s) { char *res; errno = 0; while ((res = catgets(ctd, set_id, msg_id, s)) == s && errno == EINTR) { handle_pending_signals(); errno = 0; } return res; } # if defined(HAVE_ICONV) && defined(HAVE_NL_LANGINFO) char * iconv_catgets(nl_catd ctd, int set_id, int msg_id, const char *s) { static char *buf = NULL; static size_t buf_size = 0; char *orig, *dest, *p; ICONV_CONST char *src; size_t src_size, dest_size; orig = xcatgets(ctd, set_id, msg_id, s); if (catgets_iconv == (iconv_t)-1 || orig == s) return orig; src = orig; src_size = strlen(src) + 1; if (buf == NULL && (buf = xmalloc(buf_size = src_size + 32)) == NULL) return orig; dest = buf; while (src_size != 0) { dest_size = buf + buf_size - dest; if (iconv(catgets_iconv, &src, &src_size, &dest, &dest_size) == (size_t)-1) { switch (errno) { case E2BIG: if ((p = xrealloc(buf, buf_size * 2)) == NULL) return orig; buf_size *= 2; dest = p + (dest - buf); buf = p; break; case EILSEQ: case EINVAL: default: return orig; } } } return buf; } # endif /* HAVE_ICONV && HAVE_NL_LANGINFO */ #endif /* NLS_CATALOGS */ void nlsinit(void) { #ifdef NLS_CATALOGS static const char default_catalog[] = "tcsh"; char *catalog = (char *)(intptr_t)default_catalog; if (adrof(STRcatalog) != NULL) catalog = xasprintf("tcsh.%s", short2str(varval(STRcatalog))); #ifdef NL_CAT_LOCALE /* POSIX-compliant. */ /* * Check if LC_MESSAGES is set in the environment and use it, if so. * If not, fall back to the setting of LANG. */ catd = catopen(catalog, tgetenv(STRLC_MESSAGES) ? NL_CAT_LOCALE : 0); #else /* pre-POSIX */ # ifndef MCLoadBySet # define MCLoadBySet 0 # endif catd = catopen(catalog, MCLoadBySet); #endif if (catalog != default_catalog) xfree(catalog); #if defined(HAVE_ICONV) && defined(HAVE_NL_LANGINFO) /* xcatgets (), not CGETS, the charset name should be in ASCII anyway. */ catgets_iconv = iconv_open (nl_langinfo (CODESET), xcatgets(catd, 255, 1, "UTF-8")); #endif /* HAVE_ICONV && HAVE_NL_LANGINFO */ #endif /* NLS_CATALOGS */ #ifdef WINNT_NATIVE nls_dll_init(); #endif /* WINNT_NATIVE */ errinit(); /* init the errorlist in correct locale */ mesginit(); /* init the messages for signals */ dateinit(); /* init the messages for dates */ editinit(); /* init the editor messages */ terminit(); /* init the termcap messages */ } void nlsclose(void) { #ifdef NLS_CATALOGS #if defined(HAVE_ICONV) && defined(HAVE_NL_LANGINFO) if (catgets_iconv != (iconv_t)-1) { iconv_close(catgets_iconv); catgets_iconv = (iconv_t)-1; } #endif /* HAVE_ICONV && HAVE_NL_LANGINFO */ if (catd != (nl_catd)-1) { /* * catclose can call other functions which can call longjmp * making us re-enter this code. Prevent infinite recursion * by resetting catd. Problem reported and solved by: * Gerhard Niklasch */ nl_catd oldcatd = catd; catd = (nl_catd)-1; while (catclose(oldcatd) == -1 && errno == EINTR) handle_pending_signals(); } #endif /* NLS_CATALOGS */ } int getYN(const char *prompt) { int doit; char c; xprintf("%s", prompt); flush(); (void) force_read(SHIN, &c, sizeof(c)); /* * Perhaps we should use the yesexpr from the * actual locale */ doit = (strchr(CGETS(22, 14, "Yy"), c) != NULL); while (c != '\n' && force_read(SHIN, &c, sizeof(c)) == sizeof(c)) continue; return doit; } diff --git a/contrib/tcsh/sh.glob.c b/contrib/tcsh/sh.glob.c index d19de2483b64..a57404013f88 100644 --- a/contrib/tcsh/sh.glob.c +++ b/contrib/tcsh/sh.glob.c @@ -1,1015 +1,1022 @@ /* * sh.glob.c: Regular expression expansion */ /*- * Copyright (c) 1980, 1991 The Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include "sh.h" #include "tc.h" #include "tw.h" #include "glob.h" /* * Values for gflag */ #define G_NONE 0 /* No globbing needed */ #define G_GLOB 1 /* string contains *?[] characters */ #define G_CSH 2 /* string contains ~`{ characters */ #define GLOBSPACE 100 /* Alloc increment */ #define LBRC '{' #define RBRC '}' #define LBRK '[' #define RBRK ']' #define EOS '\0' /* * globbing is now done in two stages. In the first pass we expand * csh globbing idioms ~`{ and then we proceed doing the normal * globbing if needed ?*[ * * Csh type globbing is handled in globexpand() and the rest is * handled in glob() which is part of the 4.4BSD libc. * */ static Char *globtilde (Char *); static Char *handleone (Char *, Char **, int); static Char **libglob (Char **); static Char **globexpand (Char **, int); static int globbrace (const Char *, Char ***); static void expbrace (Char ***, Char ***, int); static void pword (struct blk_buf *, struct Strbuf *); static void backeval (struct blk_buf *, struct Strbuf *, Char *, int); static Char * globtilde(Char *s) { Char *name, *u, *home, *res; u = s; + + if (s[1] == '~') + return Strsave(s); + for (s++; *s && *s != '/' && *s != ':'; s++) continue; + name = Strnsave(u + 1, s - (u + 1)); cleanup_push(name, xfree); home = gethdir(name); if (home == NULL) { if (adrof(STRnonomatch)) { cleanup_until(name); return u; } if (*name) stderror(ERR_UNKUSER, short2str(name)); else stderror(ERR_NOHOME); } cleanup_until(name); if (home[0] == '/' && home[1] == '\0' && s[0] == '/') res = Strsave(s); else res = Strspl(home, s); xfree(home); xfree(u); return res; } /* Returns a newly allocated string, old or NULL */ Char * globequal(Char *old) { int dig; const Char *dir; Char *b; /* * kfk - 17 Jan 1984 - stack hack allows user to get at arbitrary dir names * in stack. PWP: let =foobar pass through (for X windows) */ if (old[1] == '-' && (old[2] == '\0' || old[2] == '/')) { /* =- */ const Char *olddir = varval (STRowd); if (olddir && *olddir && !dcwd->di_next->di_name && !dcwd->di_prev->di_name) return Strspl(olddir, &old[2]); dig = -1; b = &old[2]; } else if (Isdigit(old[1])) { /* = */ dig = old[1] - '0'; for (b = &old[2]; Isdigit(*b); b++) dig = dig * 10 + (*b - '0'); if (*b != '\0' && *b != '/') /* =foobar */ return old; } else /* =foobar */ return old; dir = getstakd(dig); if (dir == NULL) return NULL; return Strspl(dir, b); } static int globbrace(const Char *s, Char ***bl) { struct Strbuf gbuf = Strbuf_INIT; struct blk_buf bb = BLK_BUF_INIT; int i; const Char *p, *pm, *pe, *pl; size_t prefix_len; /* copy part up to the brace */ for (p = s; *p != LBRC; p++) ; prefix_len = p - s; /* check for balanced braces */ for (i = 0, pe = ++p; *pe; pe++) if (*pe == LBRK) { /* Ignore everything between [] */ for (++pe; *pe != RBRK && *pe != EOS; pe++) continue; if (*pe == EOS) return (-RBRK); } else if (*pe == LBRC) i++; else if (*pe == RBRC) { if (i == 0) break; i--; } if (i != 0 || *pe == '\0') return (-RBRC); Strbuf_appendn(&gbuf, s, prefix_len); for (i = 0, pl = pm = p; pm <= pe; pm++) switch (*pm) { case LBRK: for (++pm; *pm != RBRK && *pm != EOS; pm++) continue; if (*pm == EOS) { bb_cleanup(&bb); xfree(gbuf.s); return (-RBRK); } break; case LBRC: i++; break; case RBRC: if (i) { i--; break; } /* FALLTHROUGH */ case ',': if (i && *pm == ',') break; else { gbuf.len = prefix_len; Strbuf_appendn(&gbuf, pl, pm - pl); Strbuf_append(&gbuf, pe + 1); Strbuf_terminate(&gbuf); bb_append(&bb, Strsave(gbuf.s)); pl = pm + 1; } break; default: break; } *bl = bb_finish(&bb); xfree(gbuf.s); return bb.len; } static void expbrace(Char ***nvp, Char ***elp, int size) { Char **vl, **el, **nv, *s; vl = nv = *nvp; if (elp != NULL) el = *elp; else el = vl + blklen(vl); for (s = *vl; s; s = *++vl) { Char **vp, **bp; /* leave {} untouched for find */ if (s[0] == '{' && (s[1] == '\0' || (s[1] == '}' && s[2] == '\0'))) continue; if (Strchr(s, '{') != NULL) { Char **bl = NULL; int len; if ((len = globbrace(s, &bl)) < 0) stderror(ERR_MISSING, -len); xfree(s); if (len == 1) { *vl-- = *bl; xfree(bl); continue; } if (&el[len] >= &nv[size]) { size_t l, e; l = &el[len] - &nv[size]; size += GLOBSPACE > l ? GLOBSPACE : l; l = vl - nv; e = el - nv; nv = xrealloc(nv, size * sizeof(Char *)); *nvp = nv; /* To keep cleanups working */ vl = nv + l; el = nv + e; } /* nv vl el bl * | | | | * -.--..-- x-- * | len * vp */ vp = vl--; *vp = *bl; len--; for (bp = el; bp != vp; bp--) bp[len] = *bp; el += len; /* nv vl el bl * | | | | * -.-x --- -- * |len * vp */ vp++; for (bp = bl + 1; *bp; *vp++ = *bp++) continue; xfree(bl); } } if (elp != NULL) *elp = el; } static Char ** globexpand(Char **v, int noglob) { Char *s; Char ***fnv, **vl, **el; int size = GLOBSPACE; fnv = xmalloc(sizeof(Char ***)); *fnv = vl = xmalloc(sizeof(Char *) * size); *vl = NULL; cleanup_push(fnv, blk_indirect_cleanup); /* * Step 1: expand backquotes. */ while ((s = *v++) != NULL) { if (Strchr(s, '`')) { int i; Char **expanded; expanded = dobackp(s, 0); for (i = 0; expanded[i] != NULL; i++) { *vl++ = expanded[i]; if (vl == &(*fnv)[size]) { size += GLOBSPACE; *fnv = xrealloc(*fnv, size * sizeof(Char *)); vl = &(*fnv)[size - GLOBSPACE]; } } xfree(expanded); } else { *vl++ = Strsave(s); if (vl == &(*fnv)[size]) { size += GLOBSPACE; *fnv = xrealloc(*fnv, size * sizeof(Char *)); vl = &(*fnv)[size - GLOBSPACE]; } } *vl = NULL; } if (noglob) goto done; /* * Step 2: expand braces */ el = vl; expbrace(fnv, &el, size); /* * Step 3: expand ~ = */ vl = *fnv; for (s = *vl; s; s = *++vl) switch (*s) { Char *ns; case '~': *vl = globtilde(s); break; case '=': if ((ns = globequal(s)) == NULL) { if (!adrof(STRnonomatch)) stderror(ERR_DEEP); /* Error */ } if (ns && ns != s) { /* Expansion succeeded */ xfree(s); *vl = ns; } break; default: break; } vl = *fnv; /* * Step 4: expand .. if the variable symlinks==expand is set */ if (symlinks == SYM_EXPAND) { for (s = *vl; s; s = *++vl) { *vl = dnormalize(s, 1); xfree(s); } } done: cleanup_ignore(fnv); cleanup_until(fnv); vl = *fnv; xfree(fnv); return vl; } static Char * handleone(Char *str, Char **vl, int action) { size_t chars; Char **t, *p, *strp; switch (action) { case G_ERROR: setname(short2str(str)); blkfree(vl); stderror(ERR_NAME | ERR_AMBIG); break; case G_APPEND: chars = 0; for (t = vl; (p = *t++) != NULL; chars++) chars += Strlen(p); str = xmalloc(chars * sizeof(Char)); for (t = vl, strp = str; (p = *t++) != NULL; chars++) { while (*p) *strp++ = *p++ & TRIM; *strp++ = ' '; } *--strp = '\0'; blkfree(vl); break; case G_IGNORE: str = Strsave(strip(*vl)); blkfree(vl); break; default: break; } return (str); } static Char ** libglob(Char **vl) { int gflgs = GLOB_QUOTE | GLOB_NOMAGIC | GLOB_ALTNOT; glob_t globv; char *ptr; int nonomatch = adrof(STRnonomatch) != 0, magic = 0, match = 0; if (adrof(STRglobdot)) gflgs |= GLOB_DOT; if (adrof(STRglobstar)) gflgs |= GLOB_STAR; if (!vl || !vl[0]) return(vl); globv.gl_offs = 0; globv.gl_pathv = 0; globv.gl_pathc = 0; if (nonomatch) gflgs |= GLOB_NOCHECK; do { ptr = short2qstr(*vl); switch (glob(ptr, gflgs, 0, &globv)) { case GLOB_ABEND: globfree(&globv); setname(ptr); stderror(ERR_NAME | ERR_GLOB); /* NOTREACHED */ case GLOB_NOSPACE: globfree(&globv); stderror(ERR_NOMEM); /* NOTREACHED */ default: break; } if (globv.gl_flags & GLOB_MAGCHAR) { match |= (globv.gl_matchc != 0); magic = 1; } gflgs |= GLOB_APPEND; } while (*++vl); vl = (globv.gl_pathc == 0 || (magic && !match && !nonomatch)) ? NULL : blk2short(globv.gl_pathv); globfree(&globv); return (vl); } Char * globone(Char *str, int action) { Char *v[2], **vl, **vo; int gflg, noglob; noglob = adrof(STRnoglob) != 0; v[0] = str; v[1] = 0; gflg = tglob(v); if (gflg == G_NONE) return (strip(Strsave(str))); if (gflg & G_CSH) { /* * Expand back-quote, tilde and brace */ vo = globexpand(v, noglob); if (noglob || (gflg & G_GLOB) == 0) { vl = vo; goto result; } cleanup_push(vo, blk_cleanup); } else if (noglob || (gflg & G_GLOB) == 0) return (strip(Strsave(str))); else vo = v; vl = libglob(vo); if (gflg & G_CSH) { if (vl != vo) cleanup_until(vo); else cleanup_ignore(vo); } if (vl == NULL) { setname(short2str(str)); stderror(ERR_NAME | ERR_NOMATCH); } result: if (vl && vl[0] == NULL) { - xfree(vl); + if (vl != v) + xfree(vl); return (Strsave(STRNULL)); } if (vl && vl[1]) return (handleone(str, vl, action)); else { str = strip(*vl); - xfree(vl); + if (vl != v) + xfree(vl); return (str); } } Char ** globall(Char **v, int gflg) { Char **vl, **vo; int noglob; if (!v || !v[0]) return saveblk(v); noglob = adrof(STRnoglob) != 0; if (gflg & G_CSH) /* * Expand back-quote, tilde and brace */ vl = vo = globexpand(v, noglob); else vl = vo = saveblk(v); if (!noglob && (gflg & G_GLOB)) { cleanup_push(vo, blk_cleanup); vl = libglob(vo); if (vl == vo) cleanup_ignore(vo); cleanup_until(vo); } else trim(vl); return vl; } Char ** glob_all_or_error(Char **v) { int gflag; gflag = tglob(v); if (gflag) { v = globall(v, gflag); if (v == NULL) stderror(ERR_NAME | ERR_NOMATCH); } else { v = saveblk(v); trim(v); } return v; } void rscan(Char **t, void (*f) (Char)) { Char *p; while ((p = *t++) != NULL) while (*p) (*f) (*p++); } void trim(Char **t) { Char *p; while ((p = *t++) != NULL) while (*p) { #if INVALID_BYTE != 0 if ((*p & INVALID_BYTE) != INVALID_BYTE) /* *p < INVALID_BYTE */ #endif *p &= TRIM; p++; } } int tglob(Char **t) { int gflag; const Char *p; gflag = 0; while ((p = *t++) != NULL) { if (*p == '~' || *p == '=') gflag |= G_CSH; else if (*p == '{' && (p[1] == '\0' || (p[1] == '}' && p[2] == '\0'))) continue; while (*p != '\0') { if (*p == '`') { gflag |= G_CSH; #ifdef notdef /* * We do want to expand echo `echo '*'`, so we don't\ * use this piece of code anymore. */ p++; while (*p && *p != '`') if (*p++ == '\\') { if (*p) /* Quoted chars */ p++; else break; } if (!*p) /* The matching ` */ break; #endif } else if (*p == '{') gflag |= G_CSH; else if (isglob(*p)) gflag |= G_GLOB; else if (symlinks == SYM_EXPAND && p[1] && ISDOTDOT(p) && (p == *(t-1) || *(p-1) == '/') ) gflag |= G_CSH; p++; } } return gflag; } /* * Command substitute cp. If literal, then this is a substitution from a * << redirection, and so we should not crunch blanks and tabs, separating * words only at newlines. */ Char ** dobackp(Char *cp, int literal) { struct Strbuf word = Strbuf_INIT; struct blk_buf bb = BLK_BUF_INIT; Char *lp, *rp, *ep; cleanup_push(&bb, bb_cleanup); cleanup_push(&word, Strbuf_cleanup); for (;;) { for (lp = cp; *lp != '\0' && *lp != '`'; lp++) ; Strbuf_appendn(&word, cp, lp - cp); if (*lp == 0) break; lp++; for (rp = lp; *rp && *rp != '`'; rp++) if (*rp == '\\') { rp++; if (!*rp) goto oops; } if (!*rp) { oops: cleanup_until(&bb); stderror(ERR_UNMATCHED, '`'); } ep = Strnsave(lp, rp - lp); cleanup_push(ep, xfree); backeval(&bb, &word, ep, literal); cleanup_until(ep); cp = rp + 1; } if (word.len != 0) pword(&bb, &word); cleanup_ignore(&bb); cleanup_until(&bb); return bb_finish(&bb); } static void backeval(struct blk_buf *bb, struct Strbuf *word, Char *cp, int literal) { ssize_t icnt; Char c, *ip; struct command faket; int hadnl; int pvec[2], quoted; Char *fakecom[2], ibuf[BUFSIZE]; hadnl = 0; icnt = 0; if (!literal) { for (ip = cp; (*ip & QUOTE) != 0; ip++) continue; quoted = *ip == '\0'; } else quoted = literal; faket.t_dtyp = NODE_COMMAND; faket.t_dflg = F_BACKQ; faket.t_dlef = 0; faket.t_drit = 0; faket.t_dspr = 0; faket.t_dcom = fakecom; fakecom[0] = STRfakecom1; fakecom[1] = 0; /* * We do the psave job to temporarily change the current job so that the * following fork is considered a separate job. This is so that when * backquotes are used in a builtin function that calls glob the "current * job" is not corrupted. We only need one level of pushed jobs as long as * we are sure to fork here. */ psavejob(); cleanup_push(&faket, psavejob_cleanup); /* faket is only a marker */ /* * It would be nicer if we could integrate this redirection more with the * routines in sh.sem.c by doing a fake execute on a builtin function that * was piped out. */ mypipe(pvec); cleanup_push(&pvec[0], open_cleanup); cleanup_push(&pvec[1], open_cleanup); if (pfork(&faket, -1) == 0) { jmp_buf_t osetexit; struct command *t; size_t omark; xclose(pvec[0]); (void) dmove(pvec[1], 1); (void) dmove(SHDIAG, 2); initdesc(); closem(); arginp = cp; for (arginp = cp; *cp; cp++) { *cp &= TRIM; if (is_set(STRcsubstnonl) && (*cp == '\n' || *cp == '\r')) *cp = ' '; } /* * In the child ``forget'' everything about current aliases or * eval vectors. */ alvec = NULL; evalvec = NULL; alvecp = NULL; evalp = NULL; omark = cleanup_push_mark(); getexit(osetexit); for (;;) { struct wordent paraml1; initlex(¶ml1); (void) setexit(); justpr = 0; if (haderr) { /* unwind */ doneinp = 0; cleanup_pop_mark(omark); resexit(osetexit); reset(); } if (seterr) { xfree(seterr); seterr = NULL; } freelex(¶ml1); (void) lex(¶ml1); cleanup_push(¶ml1, lex_cleanup); if (seterr) stderror(ERR_OLD); alias(¶ml1); t = syntax(paraml1.next, ¶ml1, 0); cleanup_push(t, syntax_cleanup); /* The F_BACKQ flag must set so the job output is correct if * printexitvalue is set. If it's not set, the job output * will have "Exit N" appended where N is the exit status. */ if (t) t->t_dflg = F_BACKQ|F_NOFORK; if (seterr) stderror(ERR_OLD); #ifdef SIGTSTP signal(SIGTSTP, SIG_IGN); #endif #ifdef SIGTTIN signal(SIGTTIN, SIG_IGN); #endif #ifdef SIGTTOU signal(SIGTTOU, SIG_IGN); #endif execute(t, -1, NULL, NULL, TRUE); cleanup_until(¶ml1); } } cleanup_until(&pvec[1]); c = 0; ip = NULL; do { ssize_t cnt = 0; for (;;) { if (icnt == 0) { ip = ibuf; icnt = wide_read(pvec[0], ibuf, BUFSIZE, 0); if (icnt <= 0) goto eof; } if (hadnl) break; --icnt; c = (*ip++ & TRIM); if (c == 0) break; #if defined(WINNT_NATIVE) || defined(__CYGWIN__) if (c == '\r') c = ' '; #endif /* WINNT_NATIVE || __CYGWIN__ */ if (c == '\n') { /* * Continue around the loop one more time, so that we can eat * the last newline without terminating this word. */ hadnl = 1; continue; } if (!quoted && (c == ' ' || c == '\t')) break; cnt++; if (c == '\\' || quoted) c |= QUOTE; Strbuf_append1(word, c); } /* * Unless at end-of-file, we will form a new word here if there were * characters in the word, or in any case when we take text literally. * If we didn't make empty words here when literal was set then we * would lose blank lines. */ if (c != 0 && (cnt || literal)) pword(bb, word); hadnl = 0; } while (c > 0); eof: cleanup_until(&pvec[0]); pwait(); cleanup_until(&faket); /* psavejob_cleanup(); */ } static void pword(struct blk_buf *bb, struct Strbuf *word) { Char *s; s = Strbuf_finish(word); bb_append(bb, s); *word = Strbuf_init; } int Gmatch(const Char *string, const Char *pattern) { return Gnmatch(string, pattern, NULL); } int Gnmatch(const Char *string, const Char *pattern, const Char **endstr) { Char ***fblk, **p; const Char *tstring = string; int gpol = 1, gres = 0; if (*pattern == '^') { gpol = 0; pattern++; } fblk = xmalloc(sizeof(Char ***)); *fblk = xmalloc(GLOBSPACE * sizeof(Char *)); (*fblk)[0] = Strsave(pattern); (*fblk)[1] = NULL; cleanup_push(fblk, blk_indirect_cleanup); expbrace(fblk, NULL, GLOBSPACE); if (endstr == NULL) /* Exact matches only */ for (p = *fblk; *p; p++) gres |= t_pmatch(string, *p, &tstring, 1) == 2 ? 1 : 0; else { const Char *end; /* partial matches */ end = Strend(string); for (p = *fblk; *p; p++) if (t_pmatch(string, *p, &tstring, 1) != 0) { gres |= 1; if (end > tstring) end = tstring; } *endstr = end; } cleanup_until(fblk); return(gres == gpol); } /* t_pmatch(): * Return 2 on exact match, * Return 1 on substring match. * Return 0 on no match. * *estr will point to the end of the longest exact or substring match. */ int t_pmatch(const Char *string, const Char *pattern, const Char **estr, int cs) { Char stringc, patternc, rangec; int match, negate_range; const Char *pestr, *nstring; for (nstring = string;; string = nstring) { stringc = *nstring++ & TRIM; patternc = *pattern++ & TRIM; switch (patternc) { case '\0': *estr = string; return (stringc == '\0' ? 2 : 1); case '?': if (stringc == 0) return (0); break; case '*': if (!*pattern) { *estr = Strend(string); return (2); } pestr = NULL; for (;;) { switch(t_pmatch(string, pattern, estr, cs)) { case 0: break; case 1: pestr = *estr;/*FIXME: does not guarantee longest match */ break; case 2: return 2; default: abort(); /* Cannot happen */ } stringc = *string++ & TRIM; if (!stringc) break; } if (pestr) { *estr = pestr; return 1; } else return 0; case '[': match = 0; if ((negate_range = (*pattern == '^')) != 0) pattern++; while ((rangec = *pattern++ & TRIM) != '\0') { if (rangec == ']') break; if (match) continue; if (*pattern == '-' && pattern[1] != ']') { Char rangec2; pattern++; rangec2 = *pattern++ & TRIM; match = (globcharcoll(stringc, rangec2, 0) <= 0 && globcharcoll(rangec, stringc, 0) <= 0); } else match = (stringc == rangec); } if (rangec == '\0') stderror(ERR_NAME | ERR_MISSING, ']'); if ((!match) && (stringc == '\0')) return (0); if (match == negate_range) return (0); break; default: if (cs ? patternc != stringc : Tolower(patternc) != Tolower(stringc)) return (0); break; } } } diff --git a/contrib/tcsh/sh.h b/contrib/tcsh/sh.h index 0bada305756b..94f4af236671 100644 --- a/contrib/tcsh/sh.h +++ b/contrib/tcsh/sh.h @@ -1,1301 +1,1299 @@ /* * sh.h: Catch it all globals and includes file! */ /*- * Copyright (c) 1980, 1991 The Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #ifndef _h_sh #define _h_sh #include "config.h" #include #include #ifdef HAVE_ICONV # include #endif #ifdef HAVE_STDINT_H # include #endif #ifdef HAVE_INTTYPES_H # include #endif #if !defined(HAVE_STDINT_H) && !defined(HAVE_INTTYPES_H) && !defined(WINNT_NATIVE) typedef unsigned long intptr_t; #endif #ifndef EXTERN # define EXTERN extern #else /* !EXTERN */ # ifdef WINNT_NATIVE # define IZERO = 0 # define IZERO_STRUCT = {0} # endif /* WINNT_NATIVE */ #endif /* EXTERN */ #ifndef IZERO # define IZERO #endif /* IZERO */ #ifndef IZERO_STRUCT # define IZERO_STRUCT #endif /* IZERO_STRUCT */ #ifndef WINNT_NATIVE # define INIT_ZERO # define INIT_ZERO_STRUCT # define force_read xread #endif /*!WINNT_NATIVE */ #if defined(KANJI) && defined(WIDE_STRINGS) && defined(HAVE_NL_LANGINFO) && defined(CODESET) #define AUTOSET_KANJI #endif /* * Sanity */ #if defined(_POSIX_SOURCE) && !defined(POSIX) # define POSIX #endif #if defined(POSIXJOBS) && !defined(BSDJOBS) # define BSDJOBS #endif #define TMP_TEMPLATE ".XXXXXX" #ifdef SHORT_STRINGS # ifdef WIDE_STRINGS #include # ifdef UTF16_STRINGS typedef wint_t Char; # else typedef wchar_t Char; #endif typedef unsigned long uChar; typedef wint_t eChar; /* Can contain any Char value or CHAR_ERR */ #define CHAR_ERR WEOF /* Pretty please, use bit 31... */ #define normal_mbtowc(PWC, S, N) rt_mbtowc(PWC, S, N) #define reset_mbtowc() TCSH_IGNORE(mbtowc(NULL, NULL, 0)) # else typedef short Char; typedef unsigned short uChar; typedef int eChar; #define CHAR_ERR (-1) #define normal_mbtowc(PWC, S, N) ((void)(N), *(PWC) = (unsigned char)*(S), 1) #define reset_mbtowc() ((void)0) # endif # define SAVE(a) (Strsave(str2short(a))) #else typedef char Char; typedef unsigned char uChar; typedef int eChar; #define CHAR_ERR (-1) #define normal_mbtowc(PWC, S, N) ((void)(N), *(PWC) = (unsigned char)*(S), 1) #define reset_mbtowc() ((void)0) # define SAVE(a) (strsave(a)) #endif #if !defined(__inline) && !defined(__GNUC__) && !defined(_MSC_VER) #define __inline #endif #ifdef _MSC_VER #define TCSH_PTRDIFF_T_FMT "I" #else #define TCSH_PTRDIFF_T_FMT "t" #endif /* Elide unused argument warnings */ #define USE(a) (void) (a) #define TCSH_IGNORE(a) tcsh_ignore((intptr_t)a) static __inline void tcsh_ignore(intptr_t a) { USE(a); } /* * Return true if the path is absolute */ #if defined(WINNT_NATIVE) # define ABSOLUTEP(p) ((p)[0] == '/' || \ (Isalpha((p)[0]) && (p)[1] == ':')) #elif defined(__CYGWIN__) # define ABSOLUTEP(p) ((p)[0] == '/' || \ (Isalpha((p)[0]) && (p)[1] == ':' && \ ((p)[2] == '\0' || (p)[2] == '/'))) #else /* !WINNT_NATIVE && !__CYGWIN__ */ # define ABSOLUTEP(p) (*(p) == '/') #endif /* WINNT_NATIVE || __CYGWIN__ */ /* * Fundamental definitions which may vary from system to system. * * BUFSIZE The i/o buffering size; also limits word size * MAILINTVL How often to mailcheck; more often is more expensive */ #ifdef BUFSIZE # if BUFSIZE < 4096 # undef BUFSIZE # define BUFSIZE 4096 /* buffer size should be no less than this */ # endif #else # define BUFSIZE 4096 #endif /* BUFSIZE */ #define FORKSLEEP 10 /* delay loop on non-interactive fork failure */ #define MAILINTVL 600 /* 10 minutes */ #ifndef INBUFSIZE # define INBUFSIZE 2*BUFSIZE /* Num input characters on the command line */ #endif /* INBUFSIZE */ /* * What our builtin echo looks like */ #define NONE_ECHO 0 #define BSD_ECHO 1 #define SYSV_ECHO 2 #define BOTH_ECHO (BSD_ECHO|SYSV_ECHO) #ifndef ECHO_STYLE # if SYSVREL > 0 # define ECHO_STYLE SYSV_ECHO # else /* SYSVREL == 0 */ # define ECHO_STYLE BSD_ECHO # endif /* SYSVREL */ #endif /* ECHO_STYLE */ /* values for noclobber */ #define NOCLOBBER_DEFAULT 1 #define NOCLOBBER_NOTEMPTY 2 #define NOCLOBBER_ASK 4 /* * The shell moves std in/out/diag and the old std input away from units * 0, 1, and 2 so that it is easy to set up these standards for invoked * commands. */ #define FSAFE 5 /* We keep the first 5 descriptors untouched */ #define FSHTTY 15 /* /dev/tty when manip pgrps */ #define FSHIN 16 /* Preferred desc for shell input */ #define FSHOUT 17 /* ... shell output */ #define FSHDIAG 18 /* ... shell diagnostics */ #define FOLDSTD 19 /* ... old std input */ #ifdef PROF #define xexit(n) done(n) #endif #ifdef cray # define word word_t /* sys/types.h defines word.. bad move! */ #endif #include #ifdef cray # undef word #endif /* * Path separator in environment variables */ #ifndef PATHSEP # if defined(__EMX__) || defined(WINNT_NATIVE) # define PATHSEP ';' # else /* unix */ # define PATHSEP ':' # endif /* __EMX__ || WINNT_NATIVE */ #endif /* !PATHSEP */ #if defined(__HP_CXD_SPP) && !defined(__hpux) # include # define stat stat64 # define fstat fstat64 # define lstat lstat64 #endif /* __HP_CXD_SPP && !__hpux */ #ifdef HAVE_LONG_LONG typedef long long tcsh_number_t; #else typedef long tcsh_number_t; #endif /* * This macro compares the st_dev field of struct stat. On aix on ibmESA * st_dev is a structure, so comparison does not work. */ #ifndef DEV_DEV_COMPARE # define DEV_DEV_COMPARE(x,y) ((x) == (y)) #endif /* DEV_DEV_COMPARE */ #ifdef _SEQUENT_ # include #endif /* _SEQUENT_ */ #if (defined(POSIX) || SYSVREL > 0) && !defined(WINNT_NATIVE) # include #endif /* (POSIX || SYSVREL > 0) && !WINNT_NATIVE */ #ifdef NLS # include #endif /* NLS */ #if !defined(_MINIX) && !defined(_VMS_POSIX) && !defined(WINNT_NATIVE) && !defined(__MVS__) # include #endif /* !_MINIX && !_VMS_POSIX && !WINNT_NATIVE && !__MVS__ */ #include #if defined(BSDTIMES) || defined(BSDLIMIT) # include # if SYSVREL>3 && !defined(SCO) && !defined(sgi) && !defined(SNI) && !defined(sun) && !(defined(__alpha) && defined(__osf__)) && !defined(_SX) && !defined(__MVS__) # include "/usr/ucbinclude/sys/resource.h" # else # ifdef convex # define sysrusage cvxrusage # include # else # define sysrusage rusage # include # endif /* convex */ # endif /* SYSVREL>3 */ #endif /* BSDTIMES */ #ifndef WINNT_NATIVE # ifndef POSIX # ifdef TERMIO # include # else /* SGTTY */ # include # endif /* TERMIO */ # else /* POSIX */ # ifndef _UWIN # include # else # include # endif /* _UWIN */ # if SYSVREL > 3 || defined(__linux__) # undef TIOCGLTC /* we don't need those, since POSIX has them */ # undef TIOCSLTC # undef CSWTCH # define CSWTCH _POSIX_VDISABLE /* So job control works */ # endif /* SYSVREL > 3 */ # endif /* POSIX */ #endif /* WINNT_NATIVE */ #ifdef sonyrisc # include #endif /* sonyrisc */ #if defined(POSIX) && !defined(WINNT_NATIVE) # include /* * the gcc+protoize version of * redefines malloc(), so we define the following * to avoid it. */ # if defined(SYSMALLOC) || defined(__linux__) || defined(__GNU__) || defined(__GLIBC__) || defined(sgi) || defined(_OSD_POSIX) # define NO_FIX_MALLOC # include # else /* glibc */ # define _GNU_STDLIB_H # define malloc __malloc # define free __free # define calloc __calloc # define realloc __realloc # include # undef malloc # undef free # undef calloc # undef realloc # endif /* glibc || sgi */ #endif /* POSIX && !WINNT_NATIVE */ #include #if SYSVREL > 0 || defined(_IBMR2) || defined(_MINIX) || defined(__linux__) || defined(__GNU__) || defined(__GLIBC__) # if !defined(pyr) && !defined(stellar) # include # ifdef _MINIX # define HZ CLOCKS_PER_SEC # endif /* _MINIX */ # endif /* !pyr && !stellar */ #endif /* SYSVREL > 0 || _IBMR2 */ /* In the following ifdef the DECOSF1 has been commented so that later * versions of DECOSF1 will get TIOCGWINSZ. This might break older versions... */ #if !((defined(SUNOS4) || defined(_MINIX) /* || defined(DECOSF1) */) && defined(TERMIO)) # if !defined(_VMS_POSIX) && !defined(WINNT_NATIVE) # include # if SYSVREL > 3 || defined(__linux__) # undef TIOCGLTC /* we don't need those, since POSIX has them */ # undef TIOCSLTC # undef CSWTCH # define CSWTCH _POSIX_VDISABLE /* So job control works */ # endif /* SYSVREL > 3 */ # endif #endif #if (defined(__DGUX__) && defined(POSIX)) || defined(DGUX) #undef CSWTCH #define CSWTCH _POSIX_VDISABLE #endif #if (!defined(FIOCLEX) && defined(SUNOS4)) || ((SYSVREL == 4) && !defined(_SEQUENT_) && !defined(SCO) && !defined(_SX)) && !defined(__MVS__) # include #endif /* (!FIOCLEX && SUNOS4) || (SYSVREL == 4 && !_SEQUENT_ && !SCO && !_SX ) */ #if !defined(_MINIX) && !defined(supermax) && !defined(WINNT_NATIVE) && !defined(IRIS4D) # include #endif /* !_MINIX && !supermax && !WINNT_NATIVE && !defined(IRIS4D) */ #if !defined(O_RDONLY) || !defined(O_NDELAY) # include #endif #include #include #include #ifdef HAVE_DIRENT_H # include #else # ifdef HAVE_NDIR_H # include # else # include # endif # define dirent direct #endif /* HAVE_DIRENT_H */ #ifndef HAVE_STRUCT_DIRENT_D_INO # define d_ino d_fileno #endif #if defined(hpux) || defined(sgi) || defined(OREO) # include /* So the fgetpwent() prototypes work */ #endif /* hpux || sgi || OREO */ #ifndef WINNT_NATIVE #include #include #endif /* WINNT_NATIVE */ #ifdef HAVE_SHADOW_H # include #endif /* HAVE_SHADOW_H */ #ifdef HAVE_AUTH_H # include #endif /* HAVE_AUTH_H */ #if defined(BSD) && !defined(POSIX) # include # define strchr(a, b) index(a, b) # define strrchr(a, b) rindex(a, b) #else # include #endif /* BSD */ /* * IRIX-5.0 has , but most system include files do not * include it yet, so we include it here */ #if defined(sgi) && SYSVREL > 3 # include #endif /* sgi && SYSVREL > 3 */ #ifdef REMOTEHOST # ifdef ISC # undef MAXHOSTNAMELEN /* Busted headers? */ # endif # include # include # include # if (defined(_SS_SIZE) || defined(_SS_MAXSIZE)) && defined(HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY) # if !defined(__APPLE__) /* Damnit, where is getnameinfo() folks? */ # if !defined(sgi) # define INET6 # endif /* sgi */ # endif /* __APPLE__ */ # endif # include /* For struct iovec */ #endif /* REMOTEHOST */ #ifdef PURIFY /* exit normally, allowing purify to trace leaks */ # define _exit exit #endif /* !PURIFY */ /* * ASCII vs. EBCDIC */ #if 'Z' - 'A' == 25 # ifndef IS_ASCII # define IS_ASCII # endif #endif #include "sh.types.h" #if !HAVE_DECL_GETPGRP # ifndef GETPGRP_VOID extern pid_t getpgrp (int); # else extern pid_t getpgrp (void); # endif #endif #ifndef lint typedef ptr_t memalign_t; #else typedef union { char am_char, *am_char_p; short am_short, *am_short_p; int am_int, *am_int_p; long am_long, *am_long_p; float am_float, *am_float_p; double am_double, *am_double_p; } *memalign_t; # define malloc lint_malloc # define free lint_free # define realloc lint_realloc # define calloc lint_calloc #endif #ifdef SYSMALLOC # define xmalloc(i) smalloc(i) # define xrealloc(p, i) srealloc(p, i) # define xcalloc(n, s) scalloc(n, s) # define xfree sfree #else # define xmalloc(i) malloc(i) # define xrealloc(p, i) realloc(p, i) # define xcalloc(n, s) calloc(n, s) # define xfree free #endif /* SYSMALLOC */ #include "sh.char.h" #include "sh.err.h" #include "sh.dir.h" #include "sh.proc.h" #include "pathnames.h" /* * C shell * * Bill Joy, UC Berkeley * October, 1978; May 1980 * * Jim Kulp, IIASA, Laxenburg Austria * April, 1980 */ #ifdef HESIOD # include #endif /* HESIOD */ #ifdef REMOTEHOST # include #endif /* REMOTEHOST */ #ifndef MAXHOSTNAMELEN # ifdef HOST_NAME_MAX # define MAXHOSTNAMELEN (HOST_NAME_MAX + 1) # elif defined(SCO) && (SYSVREL > 3) # include # else # define MAXHOSTNAMELEN 256 # endif #endif /* MAXHOSTNAMELEN */ #define eq(a, b) (Strcmp(a, b) == 0) /* globone() flags */ #define G_ERROR 0 /* default action: error if multiple words */ #define G_IGNORE 1 /* ignore the rest of the words */ #define G_APPEND 2 /* make a sentence by cat'ing the words */ /* * Global flags */ EXTERN int chkstop IZERO; /* Warned of stopped jobs... allow exit */ #if (defined(FIOCLEX) && defined(FIONCLEX)) || defined(F_SETFD) # define CLOSE_ON_EXEC #else EXTERN int didcch IZERO; /* Have closed unused fd's for child */ #endif /* (FIOCLEX && FIONCLEX) || F_SETFD */ EXTERN int didfds IZERO; /* Have setup i/o fd's for child */ EXTERN int doneinp IZERO; /* EOF indicator after reset from readc */ EXTERN int exiterr IZERO; /* Exit if error or non-zero exit status */ EXTERN int child IZERO; /* Child shell ... errors cause exit */ EXTERN int haderr IZERO; /* Reset was because of an error */ EXTERN int intty IZERO; /* Input is a tty */ EXTERN int intact IZERO; /* We are interactive... therefore prompt */ EXTERN int justpr IZERO; /* Just print because of :p hist mod */ EXTERN int loginsh IZERO; /* We are a loginsh -> .login/.logout */ EXTERN int neednote IZERO; /* Need to pnotify() */ EXTERN int noexec IZERO; /* Don't execute, just syntax check */ EXTERN int pjobs IZERO; /* want to print jobs if interrupted */ EXTERN int setintr IZERO; /* Set interrupts on/off -> Wait intr... */ EXTERN int handle_interrupt IZERO;/* Are we currently handling an interrupt? */ EXTERN int havhash IZERO; /* path hashing is available */ EXTERN int editing IZERO; /* doing filename expansion and line editing */ EXTERN int noediting IZERO; /* initial $term defaulted to noedit */ EXTERN int bslash_quote IZERO;/* PWP: tcsh-style quoting? (in sh.c) */ EXTERN int anyerror IZERO; /* propagate errors from pipelines/backq */ EXTERN int compat_expr IZERO;/* csh-style expressions? */ EXTERN int isoutatty IZERO; /* is SHOUT a tty */ EXTERN int isdiagatty IZERO;/* is SHDIAG a tty */ EXTERN int is1atty IZERO; /* is file descriptor 1 a tty (didfds mode) */ EXTERN int is2atty IZERO; /* is file descriptor 2 a tty (didfds mode) */ EXTERN int arun IZERO; /* Currently running multi-line-aliases */ EXTERN int implicit_cd IZERO;/* implicit cd enabled?(1=enabled,2=verbose) */ EXTERN int cdtohome IZERO; /* cd without args goes home */ EXTERN int inheredoc IZERO; /* Currently parsing a heredoc */ EXTERN int no_clobber IZERO; /* no clobber enabled? 1=yes 2=notempty, 4=ask*/ /* We received a window change event */ EXTERN volatile sig_atomic_t windowchg IZERO; #if defined(KANJI) && defined(SHORT_STRINGS) && defined(DSPMBYTE) EXTERN int dspmbyte_ls; #endif /* * Global i/o info */ EXTERN Char *arginp IZERO; /* Argument input for sh -c and internal `xx` */ EXTERN int onelflg IZERO; /* 2 -> need line for -t, 1 -> exit on read */ extern Char *ffile; /* Name of shell file for $0 */ extern int dolzero; /* if $?0 should return true... */ extern char *seterr; /* Error message from scanner/parser */ #ifndef errno extern int errno; /* Error from C library routines */ #endif extern int exitset; /* Temp name for << shell files in /tmp, for xfree() */ EXTERN Char *shtemp IZERO; #ifdef BSDTIMES EXTERN struct timeval time0; /* Time at which the shell started */ EXTERN struct sysrusage ru0; #else # ifdef _SEQUENT_ EXTERN timeval_t time0; /* time at which shell started */ EXTERN struct process_stats ru0; # else /* _SEQUENT_ */ # ifndef POSIX EXTERN time_t time0; /* time at which shell started */ # else /* POSIX */ EXTERN clock_t time0; /* time at which shell started */ EXTERN clock_t clk_tck; # endif /* POSIX */ EXTERN struct tms shtimes; /* shell and child times for process timing */ # endif /* _SEQUENT_ */ EXTERN time_t seconds0; #endif /* BSDTIMES */ #ifndef HZ # define HZ 100 /* for division into seconds */ #endif /* * Miscellany */ EXTERN pid_t mainpid; /* pid of the main shell ($$) */ EXTERN Char *doldol; /* Character pid for $$ */ EXTERN pid_t backpid; /* pid of the last background job */ /* * Ideally these should be uid_t, gid_t, pid_t. I cannot do that right now * cause pid's could be unsigned and that would break our -1 flag, and * uid_t and gid_t are not defined in all the systems so I would have to * make special cases for them. In the future... */ EXTERN uid_t uid, euid; /* Invokers real and effective */ EXTERN gid_t gid, egid; /* User and group ids */ EXTERN pid_t opgrp, /* Initial pgrp and tty pgrp */ shpgrp, /* Pgrp of shell */ tpgrp; /* Terminal process group */ /* If tpgrp is -1, leave tty alone! */ EXTERN Char *Prompt; /* The actual printed prompt or NULL */ EXTERN Char *RPrompt; /* Right-hand side prompt or NULL */ /* * To be able to redirect i/o for builtins easily, the shell moves the i/o * descriptors it uses away from 0,1,2. * Ideally these should be in units which are closed across exec's * (this saves work) but for version 6, this is not usually possible. * The desired initial values for these descriptors are defined in * sh.local.h. */ EXTERN int SHIN IZERO; /* Current shell input (script) */ EXTERN int SHOUT IZERO; /* Shell output */ EXTERN int SHDIAG IZERO; /* Diagnostic output... shell errs go here */ EXTERN int OLDSTD IZERO; /* Old standard input (def for cmds) */ #if (SYSVREL == 4 && defined(_UTS)) || defined(__linux__) /* * From: fadden@uts.amdahl.com (Andy McFadden) * we need sigsetjmp for UTS4, but not UTS2.1 */ # define SIGSETJMP #endif /* * Error control * * Errors in scanning and parsing set up an error message to be printed * at the end and complete. Other errors always cause a reset. * Because of source commands and .cshrc we need nested error catches. */ #ifdef SIGSETJMP typedef struct { const char *f; size_t l; sigjmp_buf j; } jmp_buf_t; # define tcsh_setjmp() sigsetjmp(reslab.j, 1) # define tcsh_longjmp() siglongjmp(reslab.j, 1) -# define setexit() (reslab.f = __func__, \ - reslab.l = __LINE__, \ - sigsetjmp(reslab.j, 1)) -# define _reset() siglongjmp(reslab.j, 1) #else typedef struct { const char *f; size_t l; jmp_buf j; } jmp_buf_t; # define tcsh_setjmp() setjmp(reslab.j) # define tcsh_longjmp() longjmp(reslab.j, 1) #endif #define setexit() (reslab.f = __func__, \ reslab.l = __LINE__, \ tcsh_setjmp()) #ifdef SETJMP_DEBUG # define _reset() xprintf("reset %s %zu\n", reslab.f, reslab.l), \ flush(), tcsh_longjmp() #else # define _reset() tcsh_longjmp() #endif #define getexit(a) (void) ((a) = reslab) #define resexit(a) (void) (reslab = (a)) #define cpybin(a, b) (void) ((a) = (b)) extern jmp_buf_t reslab; EXTERN Char *gointr; /* Label for an onintr transfer */ extern struct sigaction parintr; /* Parents interrupt catch */ extern struct sigaction parterm; /* Parents terminate catch */ /* * Lexical definitions. * * All lexical space is allocated dynamically. * The eighth/sixteenth bit of characters is used to prevent recognition, * and eventually stripped. */ #define META 0200 #define ASCII 0177 #ifdef WIDE_STRINGS /* Implies SHORT_STRINGS */ /* 31st char bit used for 'ing (not 32nd, we want all values nonnegative) */ /* * Notice * * By fix for handling unicode name file, 32nd bit is used. * We need use '&' instead of '> or <' when comparing with INVALID_BYTE etc.. * Cast to uChar is not recommended, * becase Char is 4bytes but uChar is 8bytes on I32LP64. */ # define QUOTE 0x80000000 # define TRIM 0x7FFFFFFF /* Mask to strip quote bit */ # define UNDER 0x08000000 /* Underline flag */ # define BOLD 0x04000000 /* Bold flag */ # define STANDOUT 0x02000000 /* Standout flag */ # define LITERAL 0x01000000 /* Literal character flag */ # define ATTRIBUTES 0x0F000000 /* The bits used for attributes */ # define INVALID_BYTE 0xF0000000 /* Invalid character on input */ # ifdef SOLARIS2 # define CHAR 0x30FFFFFF /* Mask to mask out the character */ # else # define CHAR 0x00FFFFFF /* Mask to mask out the character */ # endif #elif defined (SHORT_STRINGS) # define QUOTE ((Char) 0100000)/* 16nth char bit used for 'ing */ # define TRIM 0073777 /* Mask to strip quote/lit bit */ # define UNDER 0040000 /* Underline flag */ # define BOLD 0020000 /* Bold flag */ # define STANDOUT 0010000 /* Standout flag */ # define LITERAL 0004000 /* Literal character flag */ # define ATTRIBUTES 0074000 /* The bits used for attributes */ # define INVALID_BYTE 0 # define CHAR 0000377 /* Mask to mask out the character */ #else # define QUOTE ((Char) 0200) /* Eighth char bit used for 'ing */ # define TRIM 0177 /* Mask to strip quote bit */ # define UNDER 0000000 /* No extra bits to do both */ # define BOLD 0000000 /* Bold flag */ # define STANDOUT META /* Standout flag */ # define LITERAL 0000000 /* Literal character flag */ # define ATTRIBUTES 0200 /* The bits used for attributes */ # define INVALID_BYTE 0 # define CHAR 0000177 /* Mask to mask out the character */ #endif #define CHAR_DBWIDTH (LITERAL|(LITERAL-1)) # define MAX_UTF32 0x7FFFFFFF /* max UTF32 is U+7FFFFFFF */ EXTERN int AsciiOnly; /* If set only 7 bits expected in characters */ /* * Each level of input has a buffered input structure. * There are one or more blocks of buffered input for each level, * exactly one if the input is seekable and tell is available. * In other cases, the shell buffers enough blocks to keep all loops * in the buffer. * * If (WIDE_STRINGS && cantell), fbobp is always a byte offset, but * (fseekp - fbobp) and (feobp - fbobp) are character offsets (usable for * fbuf indexing). * * If (!cantell), all offsets are character offsets; if (!WIDE_STRINGS), there * is no difference between byte and character offsets. */ EXTERN struct Bin { off_t Bfseekp; /* Seek pointer, generally != lseek() value */ off_t Bfbobp; /* Seekp of beginning of buffers */ off_t Bfeobp; /* Seekp of end of buffers */ int Bfblocks; /* Number of buffer blocks */ Char **Bfbuf; /* The array of buffer blocks */ #ifdef WIDE_STRINGS /* Number of bytes in each character if (cantell) */ unsigned char Bfclens[BUFSIZE + 1]; #endif } B; /* * This structure allows us to seek inside aliases */ struct Ain { int type; #define TCSH_I_SEEK 0 /* Invalid seek */ #define TCSH_A_SEEK 1 /* Alias seek */ #define TCSH_F_SEEK 2 /* File seek */ #define TCSH_E_SEEK 3 /* Eval seek */ union { off_t _f_seek; /* A byte offset if (cantell) */ Char* _c_seek; } fc; #define f_seek fc._f_seek #define c_seek fc._c_seek Char **a_seek; } ; extern int aret; /* Type of last char returned */ #define SEEKEQ(a, b) ((a)->type == (b)->type && \ (a)->f_seek == (b)->f_seek && \ (a)->a_seek == (b)->a_seek) #define fseekp B.Bfseekp #define fbobp B.Bfbobp #define feobp B.Bfeobp #define fblocks B.Bfblocks #define fbuf B.Bfbuf #define fclens B.Bfclens /* * The shell finds commands in loops by reseeking the input * For whiles, in particular, it reseeks to the beginning of the * line the while was on; hence the while placement restrictions. */ EXTERN struct Ain lineloc; EXTERN int cantell; /* Is current source tellable ? */ /* * Input lines are parsed into doubly linked circular * lists of words of the following form. */ struct wordent { Char *word; struct wordent *prev; struct wordent *next; }; /* * During word building, both in the initial lexical phase and * when expanding $ variable substitutions, expansion by `!' and `$' * must be inhibited when reading ahead in routines which are themselves * processing `!' and `$' expansion or after characters such as `\' or in * quotations. The following flags are passed to the getC routines * telling them which of these substitutions are appropriate for the * next character to be returned. */ #define DODOL 1 #define DOEXCL 2 #define DOALL DODOL|DOEXCL /* * Labuf implements a general buffer for lookahead during lexical operations. * Text which is to be placed in the input stream can be stuck here. * We stick parsed ahead $ constructs during initial input, * process id's from `$$', and modified variable values (from qualifiers * during expansion in sh.dol.c) here. */ extern struct Strbuf labuf; EXTERN size_t lap; /* N/A if == labuf.len, index into labuf.s otherwise */ /* * Parser structure * * Each command is parsed to a tree of command structures and * flags are set bottom up during this process, to be propagated down * as needed during the semantics/exeuction pass (sh.sem.c). */ struct command { unsigned char t_dtyp; /* Type of node */ #define NODE_COMMAND 1 /* t_dcom t_drit */ #define NODE_PAREN 2 /* ( t_dspr ) t_drit */ #define NODE_PIPE 3 /* t_dlef | t_drit */ #define NODE_LIST 4 /* t_dlef ; t_drit */ #define NODE_OR 5 /* t_dlef || t_drit */ #define NODE_AND 6 /* t_dlef && t_drit */ unsigned char t_nice; /* Nice value */ #ifdef apollo unsigned char t_systype; /* System environment */ #endif unsigned long t_dflg; /* Flags, e.g. F_AMPERSAND|... */ /* save these when re-doing */ #ifndef apollo #define F_SAVE (F_NICE|F_TIME|F_NOHUP|F_HUP) #else #define F_SAVE (F_NICE|F_TIME|F_NOHUP||F_HUP|F_VER) #endif #define F_AMPERSAND (1<<0) /* executes in background */ #define F_APPEND (1<<1) /* output is redirected >> */ #define F_PIPEIN (1<<2) /* input is a pipe */ #define F_PIPEOUT (1<<3) /* output is a pipe */ #define F_NOFORK (1<<4) /* don't fork, last ()ized cmd */ #define F_NOINTERRUPT (1<<5) /* should be immune from intr's */ /* spare */ #define F_STDERR (1<<7) /* redirect unit 2 with unit 1 */ #define F_OVERWRITE (1<<8) /* output was ! */ #define F_READ (1<<9) /* input redirection is << */ #define F_REPEAT (1<<10) /* reexec aft if, repeat,... */ #define F_NICE (1<<11) /* t_nice is meaningful */ #define F_NOHUP (1<<12) /* nohup this command */ #define F_TIME (1<<13) /* time this command */ #define F_BACKQ (1<<14) /* command is in `` */ #define F_HUP (1<<15) /* hup this command */ #ifdef apollo #define F_VER (1<<16) /* execute command under SYSTYPE */ #endif union { Char *T_dlef; /* Input redirect word */ struct command *T_dcar; /* Left part of list/pipe */ } L; union { Char *T_drit; /* Output redirect word */ struct command *T_dcdr; /* Right part of list/pipe */ } R; #define t_dlef L.T_dlef #define t_dcar L.T_dcar #define t_drit R.T_drit #define t_dcdr R.T_dcdr Char **t_dcom; /* Command/argument vector */ struct command *t_dspr; /* Pointer to ()'d subtree */ }; /* * The keywords for the parser */ #define TC_BREAK 0 #define TC_BRKSW 1 #define TC_CASE 2 #define TC_DEFAULT 3 #define TC_ELSE 4 #define TC_END 5 #define TC_ENDIF 6 #define TC_ENDSW 7 #define TC_EXIT 8 #define TC_FOREACH 9 #define TC_GOTO 10 #define TC_IF 11 #define TC_LABEL 12 #define TC_LET 13 #define TC_SET 14 #define TC_SWITCH 15 #define TC_TEST 16 #define TC_THEN 17 #define TC_WHILE 18 /* * These are declared here because they want to be * initialized in sh.init.c (to allow them to be made readonly) */ #if defined(hpux) && defined(__STDC__) && !defined(__GNUC__) /* Avoid hpux ansi mode spurious warnings */ typedef void (*bfunc_t) (); #else typedef void (*bfunc_t) (Char **, struct command *); #endif /* hpux && __STDC__ && !__GNUC__ */ extern const struct biltins { const char *bname; bfunc_t bfunct; int minargs, maxargs; } bfunc[]; extern int nbfunc; #ifdef WINNT_NATIVE extern struct biltins nt_bfunc[]; extern int nt_nbfunc; #endif /* WINNT_NATIVE*/ extern int bequiet; extern struct srch { const char *s_name; int s_value; } srchn[]; extern int nsrchn; /* * Structure defining the existing while/foreach loops at this * source level. Loops are implemented by seeking back in the * input. For foreach (fe), the word list is attached here. */ EXTERN struct whyle { struct Ain w_start; /* Point to restart loop */ struct Ain w_end; /* End of loop (0 if unknown) */ Char **w_fe, **w_fe0; /* Current/initial wordlist for fe */ Char *w_fename; /* Name for fe */ struct whyle *w_next; /* Next (more outer) loop */ } *whyles; /* * Variable structure * * Aliases and variables are stored in AVL balanced binary trees. */ EXTERN struct varent { Char **vec; /* Array of words which is the value */ Char *v_name; /* Name of variable/alias */ int v_flags; /* Flags */ #define VAR_ALL -1 #define VAR_READONLY 1 #define VAR_READWRITE 2 #define VAR_NOGLOB 4 #define VAR_FIRST 32 #define VAR_LAST 64 struct varent *v_link[3]; /* The links, see below */ int v_bal; /* Balance factor */ } shvhed IZERO_STRUCT, aliases IZERO_STRUCT; #define v_left v_link[0] #define v_right v_link[1] #define v_parent v_link[2] #define adrof(v) adrof1(v, &shvhed) #define varval(v) value1(v, &shvhed) /* * The following are for interfacing redo substitution in * aliases to the lexical routines. */ EXTERN struct wordent *alhistp IZERO_STRUCT;/* Argument list (first) */ EXTERN struct wordent *alhistt IZERO_STRUCT;/* Node after last in arg list */ EXTERN Char **alvec IZERO_STRUCT, *alvecp IZERO_STRUCT;/* The (remnants of) alias vector */ /* * Filename/command name expansion variables */ #ifndef MAXPATHLEN # ifdef PATH_MAX # define MAXPATHLEN PATH_MAX # else # define MAXPATHLEN 2048 # endif #endif /* MAXPATHLEN */ #ifndef HAVENOLIMIT /* * resource limits */ extern struct limits { int limconst; const char *limname; int limdiv; const char *limscale; } limits[]; #endif /* !HAVENOLIMIT */ /* * History list * * Each history list entry contains an embedded wordlist * from the scanner, a number for the event, and a reference count * to aid in discarding old entries. * * Essentially "invisible" entries are put on the history list * when history substitution includes modifiers, and thrown away * at the next discarding since their event numbers are very negative. */ EXTERN struct Hist { struct wordent Hlex; int Hnum; /* eventno when inserted into history list */ int Href; time_t Htime; Char *histline; struct Hist *Hnext, *Hprev; /* doubly linked list */ unsigned Hhash; /* hash value of command line */ } Histlist IZERO_STRUCT; extern struct wordent paraml; /* Current lexical word list */ EXTERN int eventno; /* Next events number */ EXTERN int lastev; /* Last event reference (default) */ EXTERN Char HIST; /* history invocation character */ EXTERN Char HISTSUB; /* auto-substitute character */ EXTERN Char PRCH; /* Prompt symbol for regular users */ EXTERN Char PRCHROOT; /* Prompt symbol for root */ /* * For operating systems with single case filenames (OS/2) */ #ifdef CASE_INSENSITIVE # ifdef WIDE_STRINGS # define samecase(x) (towlower(x)) # else # define samecase(x) (isupper((unsigned char)(x)) ? \ tolower((unsigned char)(x)) : (x)) # endif #else # define samecase(x) (x) #endif /* CASE_INSENSITIVE */ /* * strings.h: */ #ifndef SHORT_STRINGS #define Strchr(a, b) strchr(a, b) #define Strrchr(a, b) strrchr(a, b) #define Strcat(a, b) strcat(a, b) #define Strncat(a, b, c) strncat(a, b, c) #define Strcpy(a, b) strcpy(a, b) #define Strncpy(a, b, c) strncpy(a, b, c) #define Strlen(a) strlen(a) #define Strcmp(a, b) strcmp(a, b) #define Strncmp(a, b, c) strncmp(a, b, c) #define Strcasecmp(a, b) strcasecmp(a, b) #define Strspl(a, b) strspl(a, b) #define Strnsave(a, b) strnsave(a, b) #define Strsave(a) strsave(a) #define Strend(a) strend(a) #define Strstr(a, b) strstr(a, b) #define str2short(a) (a) #define blk2short(a) saveblk(a) #define short2blk(a) saveblk(a) #define short2str(a) caching_strip(a) #else #if defined(WIDE_STRINGS) && !defined(UTF16_STRINGS) #define Strchr(a, b) wcschr(a, b) #define Strrchr(a, b) wcsrchr(a, b) #define Strcat(a, b) wcscat(a, b) #define Strncat(a, b, c) wcsncat(a, b, c) #define Strcpy(a, b) wcscpy(a, b) #define Strncpy(a, b, c) wcsncpy(a, b, c) #define Strlen(a) wcslen(a) #define Strcmp(a, b) wcscmp(a, b) #define Strncmp(a, b, c) wcsncmp(a, b, c) #else #define Strchr(a, b) s_strchr(a, b) #define Strrchr(a, b) s_strrchr(a, b) #define Strcat(a, b) s_strcat(a, b) #define Strncat(a, b, c) s_strncat(a, b, c) #define Strcpy(a, b) s_strcpy(a, b) #define Strncpy(a, b, c) s_strncpy(a, b, c) #define Strlen(a) s_strlen(a) #define Strcmp(a, b) s_strcmp(a, b) #define Strncmp(a, b, c) s_strncmp(a, b, c) #endif #define Strcasecmp(a, b) s_strcasecmp(a, b) #define Strspl(a, b) s_strspl(a, b) #define Strnsave(a, b) s_strnsave(a, b) #define Strsave(a) s_strsave(a) #define Strend(a) s_strend(a) #define Strstr(a, b) s_strstr(a, b) #endif +#define TCSH_MODIFIERS "ehlqrstuxQ" + /* * setname is a macro to save space (see sh.err.c) */ EXTERN const char *bname; #define setname(a) (bname = (a)) #ifdef VFORK EXTERN Char *Vsav; EXTERN Char *Vdp; EXTERN Char *Vexpath; EXTERN char **Vt; #endif /* VFORK */ EXTERN Char **evalvec; EXTERN Char *evalp; extern struct mesg { const char *iname; /* name from /usr/include */ const char *pname; /* print name */ } mesg[]; /* word_chars is set by default to WORD_CHARS (or WORD_CHARS_VI) but can be overridden by the wordchars variable--if unset, reverts to WORD_CHARS (or WORD_CHARS_VI) */ EXTERN Char *word_chars; #define WORD_CHARS "*?_-.[]~=" /* default chars besides alnums in words */ #define WORD_CHARS_VI "_" /* default chars besides alnums in words */ EXTERN Char *STR_SHELLPATH; #ifdef _PATH_BSHELL EXTERN Char *STR_BSHELL; #endif EXTERN Char *STR_WORD_CHARS; EXTERN Char *STR_WORD_CHARS_VI; EXTERN Char **STR_environ IZERO; extern int dont_free; /* Tell free that we are in danger if we free */ extern Char *INVPTR; extern Char **INVPPTR; extern char *progname; extern int tcsh; extern int xlate_cr; extern int output_raw; extern int lbuffed; extern time_t Htime; extern int numeof; extern int insource; extern char linbuf[]; extern char *linp; extern int nsig; #ifdef VFORK extern int use_fork; #endif extern int tellwhat; extern int NoNLSRebind; #if !HAVE_DECL_ENVIRON extern char **environ; #endif #include "tc.h" #ifndef WINNT_NATIVE # ifdef NLS_CATALOGS # ifdef HAVE_FEATURES_H # include # endif # ifdef HAVE_NL_LANGINFO # include # endif # ifdef __uxps__ # define gettxt gettxt_ds # endif # include # ifdef __uxps__ # undef gettxt # endif EXTERN nl_catd catd; # if defined(HAVE_ICONV) && defined(HAVE_NL_LANGINFO) # define CGETS(b, c, d) iconv_catgets(catd, b, c, d) # else # define CGETS(b, c, d) xcatgets(catd, b, c, d) # endif # define CSAVS(b, c, d) strsave(CGETS(b, c, d)) # else # define CGETS(b, c, d) d # define CSAVS(b, c, d) d # endif #else /* WINNT_NATIVE */ # define CGETS(b, c, d) nt_cgets( b, c, d) # define CSAVS(b, c, d) strsave(CGETS(b, c, d)) #endif /* WINNT_NATIVE */ #if defined(FILEC) extern int filec; #endif /* FILEC */ #include "sh.decls.h" /* * Since on some machines characters are unsigned, and the signed * keyword is not universally implemented, we treat all characters * as unsigned and sign extend them where we need. */ #define SIGN_EXTEND_CHAR(a) (((a) & 0x80) ? ((a) | ~0x7f) : (a)) /* * explanation for use by the "--help" option */ #define HELP_STRING "\ -b file batch mode, read and execute commands from `file' \n\ -c command run `command' from next argument \n\ -d load directory stack from `~/.cshdirs' \n\ -Dname[=value] define environment variable `name' to `value' (DomainOS only) \n\ -e exit on any error \n\ -f start faster by ignoring the start-up file \n\ -F use fork() instead of vfork() when spawning (ConvexOS only) \n\ -i interactive, even when input is not from a terminal \n\ -l act as a login shell, must be the only option specified \n\ -m load the start-up file, whether or not owned by effective user \n\ -n file no execute mode, just check syntax of the following `file' \n\ -q accept SIGQUIT for running under a debugger \n\ -s read commands from standard input \n\ -t read one line from standard input \n\ -v echo commands after history substitution \n\ -V like -v but including commands read from the start-up file \n\ -x echo commands immediately before execution \n\ -X like -x but including commands read from the start-up file \n\ --help print this message and exit \n\ --version print the version shell variable and exit \n\ \nSee the tcsh(1) manual page for detailed information.\n" #include "tc.nls.h" #endif /* _h_sh */ diff --git a/contrib/tcsh/sh.hist.c b/contrib/tcsh/sh.hist.c index 5be5c4fbde53..d061f40d8c0e 100644 --- a/contrib/tcsh/sh.hist.c +++ b/contrib/tcsh/sh.hist.c @@ -1,1367 +1,1373 @@ /* * sh.hist.c: Shell history expansions and substitutions */ /*- * Copyright (c) 1980, 1991 The Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include "sh.h" #include /* for rename(2), grr. */ #include #include "tc.h" #include "dotlock.h" extern int histvalid; extern struct Strbuf histline; Char HistLit = 0; static int heq (const struct wordent *, const struct wordent *); static void hfree (struct Hist *); #define HIST_ONLY 0x01 #define HIST_SAVE 0x02 #define HIST_LOAD 0x04 #define HIST_REV 0x08 #define HIST_CLEAR 0x10 #define HIST_MERGE 0x20 #define HIST_TIME 0x40 /* * C shell */ /* Static functions don't show up in gprof summaries. So eliminate "static" * modifier from some frequently called functions. */ #ifdef PROF #define PG_STATIC #else #define PG_STATIC static #endif /* #define DEBUG_HIST 1 */ static const int fastMergeErase = 1; static unsigned histCount = 0; /* number elements on history list */ static int histlen = 0; static struct Hist *histTail = NULL; /* last element on history list */ static struct Hist *histMerg = NULL; /* last element merged by Htime */ static void insertHistHashTable(struct Hist *, unsigned); /* Insert new element (hp) in history list after specified predecessor (pp). */ static void hinsert(struct Hist *hp, struct Hist *pp) { struct Hist *fp = pp->Hnext; /* following element, if any */ hp->Hnext = fp, hp->Hprev = pp; pp->Hnext = hp; if (fp) fp->Hprev = hp; else histTail = hp; /* meaning hp->Hnext == NULL */ histCount++; } /* Remove the entry from the history list. */ static void hremove(struct Hist *hp) { struct Hist *pp = hp->Hprev; assert(pp); /* elements always have a previous */ pp->Hnext = hp->Hnext; if (hp->Hnext) hp->Hnext->Hprev = pp; else histTail = pp; /* we must have been last */ if (hp == histMerg) /* deleting this hint from list */ histMerg = NULL; assert(histCount > 0); histCount--; } /* Prune length of history list to specified size by history variable. */ PG_STATIC void discardExcess(int hlen) { struct Hist *hp, *np; if (histTail == NULL) { assert(histCount == 0); return; /* no entries on history list */ } /* Prune dummy entries from the front, then old entries from the back. If * the list is still too long scan the whole list as before. But only do a * full scan if the list is more than 6% (1/16th) too long. */ while (histCount > (unsigned)hlen && (np = Histlist.Hnext)) { if (eventno - np->Href >= hlen || hlen == 0) hremove(np), hfree(np); else break; } while (histCount > (unsigned)hlen && (np = histTail) != &Histlist) { if (eventno - np->Href >= hlen || hlen == 0) hremove(np), hfree(np); else break; } if (histCount - (hlen >> 4) <= (unsigned)hlen) return; /* don't bother doing the full scan */ for (hp = &Histlist; histCount > (unsigned)hlen && (np = hp->Hnext) != NULL;) if (eventno - np->Href >= hlen || hlen == 0) hremove(np), hfree(np); else hp = np; } /* Add the command "sp" to the history list. */ void savehist( struct wordent *sp, int mflg) /* true if -m (merge) specified */ { /* throw away null lines */ if (sp && sp->next->word[0] == '\n') return; if (sp) (void) enthist(++eventno, sp, 1, mflg, histlen); discardExcess(histlen); } #define USE_JENKINS_HASH 1 /* #define USE_ONE_AT_A_TIME 1 */ #undef PRIME_LENGTH /* no need for good HTL */ #ifdef USE_JENKINS_HASH #define hashFcnName "lookup3" /* From: lookup3.c, by Bob Jenkins, May 2006, Public Domain. "... You can use this free for any purpose. It's in the public domain. It has no warranty." http://burtleburtle.net/bob/hash/index.html */ #define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k)))) #define mix(a,b,c) \ { \ a -= c; a ^= rot(c, 4); c += b; \ b -= a; b ^= rot(a, 6); a += c; \ c -= b; c ^= rot(b, 8); b += a; \ a -= c; a ^= rot(c,16); c += b; \ b -= a; b ^= rot(a,19); a += c; \ c -= b; c ^= rot(b, 4); b += a; \ } #define final(a,b,c) \ { \ c ^= b; c -= rot(b,14); \ a ^= c; a -= rot(c,11); \ b ^= a; b -= rot(a,25); \ c ^= b; c -= rot(b,16); \ a ^= c; a -= rot(c, 4); \ b ^= a; b -= rot(a,14); \ c ^= b; c -= rot(b,24); \ } struct hashValue /* State used to hash a wordend word list. */ { uint32_t a, b, c; }; /* Set up the internal state */ static void initializeHash(struct hashValue *h) { h->a = h->b = h->c = 0xdeadbeef; } /* This does a partial hash of the Chars in a single word. For efficiency we * include 3 versions of the code to pack Chars into 32-bit words for the * mixing function. */ static void addWordToHash(struct hashValue *h, const Char *word) { uint32_t a = h->a, b = h->b, c = h->c; #ifdef SHORT_STRINGS #ifdef WIDE_STRINGS assert(sizeof(Char) >= 4); while (1) { unsigned k; if ((k = (uChar)*word++) == 0) break; a += k; if ((k = (uChar)*word++) == 0) break; b += k; if ((k = (uChar)*word++) == 0) break; c += k; mix(a, b, c); } #else assert(sizeof(Char) == 2); while (1) { unsigned k; if ((k = (uChar)*word++) == 0) break; a += k; if ((k = (uChar)*word++) == 0) break; a += k << 16; if ((k = (uChar)*word++) == 0) break; b += k; if ((k = (uChar)*word++) == 0) break; b += k << 16; if ((k = (uChar)*word++) == 0) break; c += k; if ((k = (uChar)*word++) == 0) break; c += k << 16; mix(a, b, c); } #endif #else assert(sizeof(Char) == 1); while (1) { unsigned k; if ((k = *word++) == 0) break; a += k; if ((k = *word++) == 0) break; a += k << 8; if ((k = *word++) == 0) break; a += k << 16; if ((k = *word++) == 0) break; a += k << 24; if ((k = *word++) == 0) break; b += k; if ((k = *word++) == 0) break; b += k << 8; if ((k = *word++) == 0) break; b += k << 16; if ((k = *word++) == 0) break; b += k << 24; if ((k = *word++) == 0) break; c += k; if ((k = *word++) == 0) break; c += k << 8; if ((k = *word++) == 0) break; c += k << 16; if ((k = *word++) == 0) break; c += k << 24; mix(a, b, c); } #endif h->a = a, h->b = b, h->c = c; } static void addCharToHash(struct hashValue *h, Char ch) { /* The compiler (gcc -O2) seems to do a good job optimizing this without * explicitly extracting into local variables. */ h->a += (uChar)ch; mix(h->a, h->b, h->c); } static uint32_t finalizeHash(struct hashValue *h) { uint32_t a = h->a, b = h->b, c = h->c; final(a, b, c); return c; } #elif USE_ONE_AT_A_TIME #define hashFcnName "one-at-a-time" /* This one is also from Bob Jenkins, but is slower but simpler than lookup3. "... The code given here are all public domain." http://burtleburtle.net/bob/hash/doobs.html */ #if 0 ub4 one_at_a_time(char *key, ub4 len) { ub4 hash, i; for (hash=0, i=0; i> 6); } hash += (hash << 3); hash ^= (hash >> 11); hash += (hash << 15); return (hash & mask); } #endif struct hashValue { uint32_t h; }; static void initializeHash(struct hashValue *h) { h->h = 0; } static void addWordToHash(struct hashValue *h, const Char *word) { unsigned k; uint32_t hash = h->h; while (k = (uChar)*word++) hash += k, hash += hash << 10, hash ^= hash >> 6; h->h = hash; } static void addCharToHash(struct hashValue *h, Char c) { Char b[2] = { c, 0 }; addWordToHash(h, b); } static uint32_t finalizeHash(struct hashValue *h) { unsigned hash = h->h; hash += (hash << 3); hash ^= (hash >> 11); hash += (hash << 15); return hash; } #else #define hashFcnName "add-mul" /* Simple multipy and add hash. */ #define PRIME_LENGTH 1 /* need "good" HTL */ struct hashValue { uint32_t h; }; static void initializeHash(struct hashValue *h) { h->h = 0xe13e2345; } static void addWordToHash(struct hashValue *h, const Char *word) { unsigned k; uint32_t hash = h->h; while (k = (uChar)*word++) hash = hash * 0x9e4167b9 + k; h->h = hash; } static void addCharToHash(struct hashValue *h, Char c) { h->h = h->h * 0x9e4167b9 + (uChar)c; } static uint32_t finalizeHash(struct hashValue *h) { return h->h; } #endif static unsigned hashhist(struct wordent *h0) { struct hashValue s; struct wordent *firstWord = h0->next; struct wordent *h = firstWord; unsigned hash = 0; initializeHash(&s); for (; h != h0; h = h->next) { if (h->word[0] == '\n') break; /* don't hash newline */ if (h != firstWord) addCharToHash(&s, ' '); /* space between words */ addWordToHash(&s, h->word); } hash = finalizeHash(&s); /* Zero means no hash value, so never return zero as a hash value. */ return hash ? hash : 0x7fffffff; /* prime! */ } #if 0 unsigned hashStr(Char *str) { struct hashValue s; initializeHash(&s); addWordToHash(&s, str); return finalizeHash(&s); } #endif #ifdef PRIME_LENGTH /* need good HTL */ #define hash2tableIndex(hash, len) ((hash) % len) #else #define hash2tableIndex(hash, len) ((hash) & (len-1)) #endif /* This code can be enabled to test the above hash functions for speed and * collision avoidance. The testing is enabled by "occasional" calls to * displayHistStats(), see which. */ #ifdef DEBUG_HIST #ifdef BSDTIMES static double doTiming(int start) { static struct timeval beginTime; if (start) { gettimeofday(&beginTime, NULL); return 0.0; } else { struct timeval now; gettimeofday(&now, NULL); return (now.tv_sec-beginTime.tv_sec) + (now.tv_usec-beginTime.tv_usec)/1e6; } } #else static double doTiming(int start) { USE(start); return 0.0; } #endif static void generateHashes(int nChars, unsigned nWords, unsigned samples, unsigned *hashes, unsigned length) { if (nChars < 1) return; nWords = (nWords < 1) ? 1 : (nWords > 4) ? 4 : nWords; Char *number = xmalloc((nChars+nWords)*sizeof(Char)); struct wordent word[4]; struct wordent base = { NULL, &word[0], &word[0] }; word[0].word = number, word[0].next = &base, word[0].prev = &base; unsigned w = 0; /* word number */ /* Generate multiple words of length 2, 3, 5, then all the rest. */ unsigned wBoundaries[4] = { 2-1, 2+3-1, 2+3+5-1, 0 }; /* Ensure the last word has at least 4 Chars in it. */ while (nWords >= 2 && nChars < (wBoundaries[nWords-2]+1) + 4) nWords--; wBoundaries[nWords-1] = 0xffffffff; /* don't end word past this point */ unsigned i; for (i = 0; i 10) break; } } if (i >= samples) sec = doTiming(0); else samples = i; /* number we actually did */ if (sec > 0.01) { xprintf("Hash %d (%d Char %u words) with %s: %d nsec/hash, %d mcps\n", samples, nChars, w+1, hashFcnName, (int)((sec/samples)*1e9), (int)((double)samples*nChars/sec/1e6)); } } #endif /* DEBUG_HIST */ #ifdef DEBUG_HIST static void testHash(void) { static const Char STRtestHashTimings[] = { 't','e','s','t','H','a','s','h','T','i','m','i','n','g','s', 0 }; struct varent *vp = adrof(STRtestHashTimings); if (vp && vp->vec) { unsigned hashes[4]; /* dummy place to put hashes */ Char **vals = vp->vec; while (*vals) { int length = getn(*vals); unsigned words = (length < 5) ? 1 : (length < 25) ? 2 : (length < 75) ? 3 : 4; if (length > 0) generateHashes(length, words, 0, hashes, 4); vals++; } } unsigned length = 1024; #ifdef PRIME_LENGTH /* need good HTL */ length = 1021; #endif unsigned *hashes = xmalloc(length*sizeof(unsigned)); memset(hashes, 0, length*sizeof(unsigned)); /* Compute collision statistics for half full hashes modulo "length". */ generateHashes(4, 1, length/2, hashes, length); /* Evaluate collisions by comparing occupancy rates (mean value 0.5). * One bin for each number of hits. */ unsigned bins[155]; memset(bins, 0, sizeof(bins)); unsigned highest = 0; unsigned i; for (i = 0; i= sizeof(bins)/sizeof(bins[0])) /* clip */ hits = highest = sizeof(bins)/sizeof(bins[0]) - 1; if (hits > highest) highest = hits; bins[hits]++; } xprintf("Occupancy of %d buckets by %d hashes %d Chars %d word with %s\n", length, length/2, 4, 1, hashFcnName); for (i = 0; i <= highest; i++) { xprintf(" %d buckets (%d%%) with %d hits\n", bins[i], bins[i]*100/length, i); } /* Count run lengths to evaluate linear rehashing effectiveness. Estimate * a little corrupted by edge effects. */ memset(bins, 0, sizeof(bins)); highest = 0; for (i = 0; hashes[i] == 0; i++); /* find first occupied bucket */ unsigned run = 0; unsigned rehashed = 0; for (; i 0) hits = 1 && rehashed--; else if (hits > 1) rehashed += hits-1; if (hits) run++; else { /* a real free slot, count it */ if (run >= sizeof(bins)/sizeof(bins[0])) /* clip */ run = highest = sizeof(bins)/sizeof(bins[0]) - 1; if (run > highest) highest = run; bins[run]++; run = 0; } } /* Ignore the partial run at end as we ignored the beginning. */ double merit = 0.0, entries = 0; for (i = 0; i <= highest; i++) { entries += bins[i]*i; /* total hashed objects */ merit += bins[i]*i*i; } xprintf("Rehash collision figure of merit %u (ideal=100), run lengths:\n", (int)(100.0*merit/entries)); for (i = 0; i <= highest; i++) { if (bins[i] != 0) xprintf(" %d runs of length %d buckets\n", bins[i], i); } xfree(hashes); } #endif /* DEBUG_HIST */ /* Compares two word lists for equality. */ static int heq(const struct wordent *a0, const struct wordent *b0) { const struct wordent *a = a0->next, *b = b0->next; for (;;) { if (Strcmp(a->word, b->word) != 0) return 0; a = a->next; b = b->next; if (a == a0) return (b == b0) ? 1 : 0; if (b == b0) return 0; } } /* Renumber entries following p, which we will be deleting. */ PG_STATIC void renumberHist(struct Hist *p) { int n = p->Href; while ((p = p->Hnext)) p->Href = n--; } /* The hash table is implemented as an array of pointers to Hist entries. Each * entry is located in the table using hash2tableIndex() and checking the * following entries in case of a collision (linear rehash). Free entries in * the table are zero (0, NULL, emptyHTE). Deleted entries that cannot yet be * freed are set to one (deletedHTE). The Hist.Hhash member is non-zero iff * the entry is in the hash table. When the hash table get too full, it is * reallocated to be approximately twice the history length (see * getHashTableSize). */ static struct Hist **histHashTable = NULL; static unsigned histHashTableLength = 0; /* number of Hist pointers in table */ static struct Hist * const emptyHTE = NULL; static struct Hist * const deletedHTE = (struct Hist *)1; static struct { unsigned insertCount; unsigned removeCount; unsigned rehashes; int deleted; } hashStats; #ifdef DEBUG_HIST void checkHistHashTable(int print) { unsigned occupied = 0; unsigned deleted = 0; unsigned i; for (i = 0; i= hashStats.removeCount); checkHistHashTable(1); memset(&hashStats, 0, sizeof(hashStats)); if (!doneTest) { testHash(); doneTest = 1; } } #else void displayHistStats(const char *reason) { USE(reason); } #endif static void discardHistHashTable(void) { if (histHashTable == NULL) return; displayHistStats("Discarding"); xfree(histHashTable); histHashTable = NULL; } /* Computes a new hash table size, when the current one is too small. */ static unsigned getHashTableSize(int hlen) { unsigned target = hlen * 2; unsigned e = 5; unsigned size; while ((size = 1< (int)histCount ? hlen : (int)histCount); histHashTable = xmalloc(histHashTableLength * sizeof(struct Hist *)); memset(histHashTable, 0, histHashTableLength * sizeof(struct Hist *)); assert(histHashTable[0] == emptyHTE); /* Now insert all the entries on the history list into the hash table. */ { struct Hist *hp; for (hp = &Histlist; (hp = hp->Hnext) != NULL;) { unsigned lpHash = hashhist(&hp->Hlex); assert(!hp->Hhash || hp->Hhash == lpHash); hp->Hhash = 0; /* force insert to new hash table */ insertHistHashTable(hp, lpHash); } } } /* Insert np into the hash table. We assume that np is already on the * Histlist. The specified hashval matches the new Hist entry but has not yet * been assigned to Hhash (or the element is already on the hash table). */ static void insertHistHashTable(struct Hist *np, unsigned hashval) { unsigned rehashes = 0; unsigned hi = 0; if (!histHashTable) return; if (np->Hhash != 0) { /* already in hash table */ assert(hashval == np->Hhash); return; } assert(np != deletedHTE); /* Find a free (empty or deleted) slot, using linear rehash. */ assert(histHashTable); for (rehashes = 0; ((hi = hash2tableIndex(hashval + rehashes, histHashTableLength)), histHashTable[hi] != emptyHTE && histHashTable[hi] != deletedHTE); rehashes++) { assert(np != histHashTable[hi]); if (rehashes >= histHashTableLength / 10) { /* Hash table is full, so grow it. We assume the create function * will roughly double the size we give it. Create initializes the * new table with everything on the Histlist, so we are done when * it returns. */ #ifdef DEBUG_HIST xprintf("Growing history hash table from %d ...", histHashTableLength); flush(); #endif discardHistHashTable(); createHistHashTable(histHashTableLength); #ifdef DEBUG_HIST xprintf("to %d.\n", histHashTableLength); #endif return; } } /* Might be sensible to grow hash table if rehashes is "too big" here. */ if (histHashTable[hi] == deletedHTE) hashStats.deleted--; histHashTable[hi] = np; np->Hhash = hashval; hashStats.insertCount++; hashStats.rehashes += rehashes; } /* Remove the 'np' entry from the hash table. */ static void removeHistHashTable(struct Hist *np) { unsigned hi = np->Hhash; if (!histHashTable || !hi) return; /* no hash table or not on it */ /* find desired entry */ while ((hi = hash2tableIndex(hi, histHashTableLength)), histHashTable[hi] != emptyHTE) { if (np == histHashTable[hi]) { unsigned i; unsigned deletes = 0; histHashTable[hi] = deletedHTE; /* dummy, but non-zero entry */ /* now peek ahead to see if the dummies are really necessary. */ i = 1; while (histHashTable[hash2tableIndex(hi+i, histHashTableLength)] == deletedHTE) i++; if (histHashTable[hash2tableIndex(hi+i, histHashTableLength)] == emptyHTE) { /* dummies are no longer necessary placeholders. */ deletes = i; while (i-- > 0) { histHashTable[hash2tableIndex(hi+i, histHashTableLength)] = emptyHTE; } } hashStats.deleted += 1 - deletes; /* delta deleted entries */ hashStats.removeCount++; return; } hi++; /* linear rehash */ } assert(!"Hist entry not found in hash table"); } /* Search the history hash table for a command matching lp, using hashval as * its hash value. */ static struct Hist * findHistHashTable(struct wordent *lp, unsigned hashval) { unsigned deleted = 0; /* number of deleted entries skipped */ unsigned hi = hashval; struct Hist *hp; if (!histHashTable) return NULL; while ((hi = hash2tableIndex(hi, histHashTableLength)), (hp = histHashTable[hi]) != emptyHTE) { if (hp == deletedHTE) deleted++; else if (hp->Hhash == hashval && heq(lp, &(hp->Hlex))) return hp; if (deleted > (histHashTableLength>>4)) { /* lots of deletes, so we need a sparser table. */ discardHistHashTable(); createHistHashTable(histHashTableLength); return findHistHashTable(lp, hashval); } hi++; /* linear rehash */ } return NULL; } /* When merge semantics are in use, find the approximate predecessor for the * new entry, so that the Htime entries are decreasing. Return the entry just * before the first entry with equal times, so the caller can check for * duplicates. When pTime is not NULL, use it as a starting point for search, * otherwise search from beginning (largest time value) of history list. */ PG_STATIC struct Hist * mergeInsertionPoint( struct Hist *np, /* new entry to be inserted */ struct Hist *pTime) /* hint about where to insert */ { struct Hist *pp, *p; if (histTail && histTail->Htime >= np->Htime) pTime = histTail; /* new entry goes at the end */ if (histMerg && histMerg != &Histlist && histMerg != Histlist.Hnext) { /* Check above and below previous insertion point, in case we're adding * sequential times in the middle of the list (e.g. history -M). */ if (histMerg->Htime >= np->Htime) pTime = histMerg; else if (histMerg->Hprev->Htime >= np->Htime) pTime = histMerg->Hprev; } if (pTime) { /* With hint, search up the list until Htime is greater. We skip past * the equal ones, too, so our caller can elide duplicates. */ pp = pTime; while (pp != &Histlist && pp->Htime <= np->Htime) pp = pp->Hprev; } else pp = &Histlist; /* Search down the list while current entry's time is too large. */ while ((p = pp->Hnext) && (p->Htime > np->Htime)) pp = p; /* advance insertion point */ /* Remember recent position as hint for next time */ histMerg = pp; return pp; } /* Bubble Hnum & Href in new entry down to pp through earlier part of list. */ PG_STATIC void bubbleHnumHrefDown(struct Hist *np, struct Hist *pp) { struct Hist *p; for (p = Histlist.Hnext; p != pp->Hnext; p = p->Hnext) { /* swap Hnum & Href values of p and np. */ int n = p->Hnum, r = p->Href; p->Hnum = np->Hnum; p->Href = np->Href; np->Hnum = n; np->Href = r; } } /* Enter new command into the history list according to current settings. */ struct Hist * enthist( int event, /* newly incremented global eventno */ struct wordent *lp, int docopy, int mflg, /* true if merge requested */ int hlen) /* -1 if unknown */ { struct Hist *p = NULL, *pp = &Histlist, *pTime = NULL; struct Hist *np; const Char *dp; unsigned lpHash = 0; /* non-zero if hashing entries */ if ((dp = varval(STRhistdup)) != STRNULL) { if (eq(dp, STRerase)) { /* masaoki@akebono.tky.hp.com (Kobayashi Masaoki) */ createHistHashTable(hlen); lpHash = hashhist(lp); assert(lpHash != 0); p = findHistHashTable(lp, lpHash); if (p) { if (Htime != 0 && p->Htime > Htime) Htime = p->Htime; /* If we are merging, and the old entry is at the place we want * to insert the new entry, then remember the place. */ if (mflg && Htime != 0 && p->Hprev->Htime >= Htime) pTime = p->Hprev; if (!fastMergeErase) renumberHist(p); /* Reset Href of subsequent entries */ hremove(p); hfree(p); p = NULL; /* so new entry is allocated below */ } } else if (eq(dp, STRall)) { createHistHashTable(hlen); lpHash = hashhist(lp); assert(lpHash != 0); p = findHistHashTable(lp, lpHash); if (p) /* p!=NULL, only update this entry's Htime below */ eventno--; /* not adding a new event */ } else if (eq(dp, STRprev)) { if (pp->Hnext && heq(lp, &(pp->Hnext->Hlex))) { p = pp->Hnext; eventno--; } } } np = p ? p : xmalloc(sizeof(*np)); /* Pick up timestamp set by lex() in Htime if reading saved history */ if (Htime != 0) { np->Htime = Htime; Htime = 0; } else (void) time(&(np->Htime)); if (p == np) return np; /* reused existing entry */ /* Initialize the new entry. */ np->Hnum = np->Href = event; if (docopy) { copylex(&np->Hlex, lp); if (histvalid) np->histline = Strsave(histline.s); else np->histline = NULL; } else { np->Hlex.next = lp->next; lp->next->prev = &np->Hlex; np->Hlex.prev = lp->prev; lp->prev->next = &np->Hlex; np->histline = NULL; } np->Hhash = 0; /* The head of history list is the default insertion point. If merging, advance insertion point, in pp, according to Htime. */ /* XXX -- In histdup=all, Htime values can be non-monotonic. */ if (mflg) { /* merge according to np->Htime */ pp = mergeInsertionPoint(np, pTime); for (p = pp->Hnext; p && p->Htime == np->Htime; pp = p, p = p->Hnext) { if (heq(&p->Hlex, &np->Hlex)) { eventno--; /* duplicate, so don't add new event */ hfree(np); return (p); } } /* pp is now the last entry with time >= to np. */ if (!fastMergeErase) { /* renumber at end of loadhist */ /* Before inserting np after pp, bubble its Hnum & Href values down * through the earlier part of list. */ bubbleHnumHrefDown(np, pp); } } else pp = &Histlist; /* insert at beginning of history */ hinsert(np, pp); if (lpHash && hlen != 0) /* erase & all modes use hash table */ insertHistHashTable(np, lpHash); else discardHistHashTable(); return (np); } static void hfree(struct Hist *hp) { assert(hp != histMerg); if (hp->Hhash) removeHistHashTable(hp); freelex(&hp->Hlex); if (hp->histline) xfree(hp->histline); xfree(hp); } PG_STATIC void phist(struct Hist *hp, int hflg) { if (hp->Href < 0) return; if (hflg & HIST_ONLY) { int old_output_raw; /* * Control characters have to be written as is (output_raw). * This way one can preserve special characters (like tab) in * the history file. * From: mveksler@vnet.ibm.com (Veksler Michael) */ old_output_raw = output_raw; output_raw = 1; cleanup_push(&old_output_raw, output_raw_restore); if (hflg & HIST_TIME) /* * Make file entry with history time in format: * "+NNNNNNNNNN" (10 digits, left padded with ascii '0') */ xprintf("#+%010lu\n", (unsigned long)hp->Htime); if (HistLit && hp->histline) xprintf("%S\n", hp->histline); else prlex(&hp->Hlex); cleanup_until(&old_output_raw); } else { Char *cp = str2short("%h\t%T\t%R\n"); Char *p; struct varent *vp = adrof(STRhistory); if (vp && vp->vec != NULL && vp->vec[0] && vp->vec[1]) cp = vp->vec[1]; p = tprintf(FMT_HISTORY, cp, NULL, hp->Htime, hp); cleanup_push(p, xfree); for (cp = p; *cp;) xputwchar(*cp++); cleanup_until(p); } } PG_STATIC void dophist(int n, int hflg) { struct Hist *hp; if (setintr) { int old_pintr_disabled; pintr_push_enable(&old_pintr_disabled); cleanup_until(&old_pintr_disabled); } if ((hflg & HIST_REV) == 0) { /* Since the history list is stored most recent first, non-reversing * print needs to print (backwards) up the list. */ if ((unsigned)n >= histCount) hp = histTail; else { for (hp = Histlist.Hnext; --n > 0 && hp->Hnext != NULL; hp = hp->Hnext) ; } if (hp == NULL) return; /* nothing to print */ for (; hp != &Histlist; hp = hp->Hprev) phist(hp, hflg); } else { for (hp = Histlist.Hnext; n-- > 0 && hp != NULL; hp = hp->Hnext) phist(hp, hflg); } } /*ARGSUSED*/ void dohist(Char **vp, struct command *c) { int n, hflg = 0; USE(c); if (getn(varval(STRhistory)) == 0) return; while (*++vp && **vp == '-') { Char *vp2 = *vp; while (*++vp2) switch (*vp2) { case 'c': hflg |= HIST_CLEAR; break; case 'h': hflg |= HIST_ONLY; break; case 'r': hflg |= HIST_REV; break; case 'S': hflg |= HIST_SAVE; break; case 'L': hflg |= HIST_LOAD; break; case 'M': hflg |= HIST_MERGE; break; case 'T': hflg |= HIST_TIME; break; default: stderror(ERR_HISTUS, "chrSLMT"); break; } } if (hflg & HIST_CLEAR) { struct Hist *np, *hp; for (hp = &Histlist; (np = hp->Hnext) != NULL;) hremove(np), hfree(np); } if (hflg & (HIST_LOAD | HIST_MERGE)) loadhist(*vp, (hflg & HIST_MERGE) ? 1 : 0); else if (hflg & HIST_SAVE) rechist(*vp, 1); else { if (*vp) n = getn(*vp); else { n = getn(varval(STRhistory)); } dophist(n, hflg); } } char * fmthist(int fmt, ptr_t ptr) { struct Hist *hp = ptr; char *buf; switch (fmt) { case 'h': return xasprintf("%6d", hp->Hnum); case 'R': if (HistLit && hp->histline) return xasprintf("%S", hp->histline); else { Char *istr, *ip; char *p; istr = sprlex(&hp->Hlex); buf = xmalloc(Strlen(istr) * MB_LEN_MAX + 1); for (p = buf, ip = istr; *ip != '\0'; ip++) p += one_wctomb(p, *ip); *p = '\0'; xfree(istr); return buf; } default: buf = xmalloc(1); buf[0] = '\0'; return buf; } } static void dotlock_cleanup(void* lockpath) { dot_unlock((char*)lockpath); } /* Save history before exiting the shell. */ void rechist(Char *fname, int ref) { Char *snum, *rs; - int fp, ftmp, oldidfds; + int fp, ftmp, oldidfds, ophup_disabled; struct varent *shist; char path[MAXPATHLEN]; struct stat st; static Char *dumphist[] = {STRhistory, STRmhT, 0, 0}; if (fname == NULL && !ref) return; + + ophup_disabled = phup_disabled; + phup_disabled = 1; + /* * If $savehist is just set, we use the value of $history * else we use the value in $savehist */ if (((snum = varval(STRsavehist)) == STRNULL) && ((snum = varval(STRhistory)) == STRNULL)) snum = STRmaxint; if (fname == NULL) { if ((fname = varval(STRhistfile)) == STRNULL) fname = Strspl(varval(STRhome), &STRtildothist[1]); else fname = Strsave(fname); } else fname = globone(fname, G_ERROR); cleanup_push(fname, xfree); /* * The 'savehist merge' feature is intended for an environment * with numerous shells being in simultaneous use. Imagine * any kind of window system. All these shells 'share' the same * ~/.history file for recording their command line history. * We try to handle the case of multiple shells trying to merge * histories at the same time, by creating semi-unique filenames * and saving the history there first and then trying to rename * them in the proper history file. * * Users that like to nuke their environment require here an atomic * loadhist-creat-dohist(dumphist)-close sequence which is given * by optional lock parameter to savehist. * * jw. */ /* * We need the didfds stuff before loadhist otherwise * exec in a script will fail to print if merge is set. * From: mveksler@iil.intel.com (Veksler Michael) */ oldidfds = didfds; didfds = 0; if ((shist = adrof(STRsavehist)) != NULL && shist->vec != NULL) { size_t i; int merge = 0, lock = 0; for (i = 1; shist->vec[i]; i++) { if (eq(shist->vec[i], STRmerge)) merge++; if (eq(shist->vec[i], STRlock)) lock++; } if (merge) { jmp_buf_t osetexit; if (lock) { #ifndef WINNT_NATIVE char *lockpath = strsave(short2str(fname)); cleanup_push(lockpath, xfree); /* Poll in 100 miliseconds interval to obtain the lock. */ if ((dot_lock(lockpath, 100) == 0)) cleanup_push(lockpath, dotlock_cleanup); #endif } getexit(osetexit); - if (setexit()) + if (setexit() == 0) loadhist(fname, 1); resexit(osetexit); } } rs = randsuf(); xsnprintf(path, sizeof(path), "%S.%S", fname, rs); xfree(rs); fp = xcreat(path, 0600); if (fp == -1) { didfds = oldidfds; cleanup_until(fname); + phup_disabled = ophup_disabled; return; } /* Try to preserve ownership and permissions of the original history file */ #ifndef WINNT_NATIVE if (stat(short2str(fname), &st) != -1) { TCSH_IGNORE(fchown(fp, st.st_uid, st.st_gid)); TCSH_IGNORE(fchmod(fp, st.st_mode)); } #else UNREFERENCED_PARAMETER(st); #endif ftmp = SHOUT; SHOUT = fp; dumphist[2] = snum; dohist(dumphist, NULL); xclose(fp); SHOUT = ftmp; didfds = oldidfds; #ifndef WINNT_NATIVE (void)rename(path, short2str(fname)); #else (void)ReplaceFile( short2str(fname),path,NULL,0,NULL,NULL); #endif cleanup_until(fname); + phup_disabled = ophup_disabled; } /* This is the entry point for loading history data from a file. */ void loadhist(Char *fname, int mflg) { static Char *loadhist_cmd[] = {STRsource, NULL, NULL, NULL}; loadhist_cmd[1] = mflg ? STRmm : STRmh; if (fname != NULL) loadhist_cmd[2] = fname; else if ((fname = varval(STRhistfile)) != STRNULL) loadhist_cmd[2] = fname; else loadhist_cmd[2] = STRtildothist; dosource(loadhist_cmd, NULL); /* During history merging (enthist sees mflg set), we disable management of * Hnum and Href (because fastMergeErase is true). So now reset all the * values based on the final ordering of the history list. */ if (mflg) { int n = eventno; struct Hist *hp = &Histlist; while ((hp = hp->Hnext)) hp->Hnum = hp->Href = n--; } } void sethistory(int n) { histlen = n; discardExcess(histlen); } diff --git a/contrib/tcsh/sh.lex.c b/contrib/tcsh/sh.lex.c index 2893768e9584..46cc96d0937c 100644 --- a/contrib/tcsh/sh.lex.c +++ b/contrib/tcsh/sh.lex.c @@ -1,1857 +1,1862 @@ /* * sh.lex.c: Lexical analysis into tokens */ /*- * Copyright (c) 1980, 1991 The Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include "sh.h" #include "ed.h" #include /* #define DEBUG_INP */ /* #define DEBUG_SEEK */ /* * C shell */ #define FLAG_G 1 #define FLAG_A 2 /* * These lexical routines read input and form lists of words. * There is some involved processing here, because of the complications * of input buffering, and especially because of history substitution. */ static Char *word (int); static eChar getC1 (int); static void getdol (void); static void getexcl (Char); static struct Hist *findev (Char *, int); static void setexclp (Char *); static eChar bgetc (void); static void balloc (int); static void bfree (void); static struct wordent *gethent (Char); static int matchs (const Char *, const Char *); static int getsel (int *, int *, int); static struct wordent *getsub (struct wordent *); static Char *subword (Char *, Char, int *, size_t *); static struct wordent *dosub (Char, struct wordent *, int); /* * Peekc is a peek character for getC, peekread for readc. * There is a subtlety here in many places... history routines * will read ahead and then insert stuff into the input stream. * If they push back a character then they must push it behind * the text substituted by the history substitution. On the other * hand in several places we need 2 peek characters. To make this * all work, the history routines read with getC, and make use both * of ungetC and unreadc. The key observation is that the state * of getC at the call of a history reference is such that calls * to getC from the history routines will always yield calls of * readc, unless this peeking is involved. That is to say that during * getexcl the variables lap, exclp, and exclnxt are all zero. * * Getdol invokes history substitution, hence the extra peek, peekd, * which it can ungetD to be before history substitutions. */ static Char peekc = 0, peekd = 0; static Char peekread = 0; /* (Tail of) current word from ! subst */ static Char *exclp = NULL; /* The rest of the ! subst words */ static struct wordent *exclnxt = NULL; /* Count of remaining words in ! subst */ static int exclc = 0; /* "Globp" for alias resubstitution */ int aret = TCSH_F_SEEK; /* * Labuf implements a general buffer for lookahead during lexical operations. * Text which is to be placed in the input stream can be stuck here. * We stick parsed ahead $ constructs during initial input, * process id's from `$$', and modified variable values (from qualifiers * during expansion in sh.dol.c) here. */ struct Strbuf labuf; /* = Strbuf_INIT; */ /* * Lex returns to its caller not only a wordlist (as a "var" parameter) * but also whether a history substitution occurred. This is used in * the main (process) routine to determine whether to echo, and also * when called by the alias routine to determine whether to keep the * argument list. */ static int hadhist = 0; /* * Avoid alias expansion recursion via \!# */ int hleft; struct Strbuf histline; /* = Strbuf_INIT; last line input */ int histvalid = 0; /* is histline valid */ static Char getCtmp; #define getC(f) (((getCtmp = peekc) != '\0') ? (peekc = 0, (eChar)getCtmp) : getC1(f)) #define ungetC(c) peekc = (Char) c #define ungetD(c) peekd = (Char) c /* Use Htime to store timestamps picked up from history file for enthist() * if reading saved history (sg) */ time_t Htime = (time_t)0; static time_t a2time_t (Char *); /* * special parsing rules apply for source -h */ extern int enterhist; extern int postcmd_active; int lex(struct wordent *hp) { struct wordent *wdp; eChar c; int parsehtime = enterhist; int toolong = 0; histvalid = 0; histline.len = 0; if (!postcmd_active) btell(&lineloc); hp->next = hp->prev = hp; hp->word = STRNULL; hadhist = 0; do c = readc(0); while (c == ' ' || c == '\t'); if (c == (eChar)HISTSUB && intty) /* ^lef^rit from tty is short !:s^lef^rit */ getexcl(c); else unreadc(c); cleanup_push(hp, lex_cleanup); wdp = hp; /* * The following loop is written so that the links needed by freelex will * be ready and rarin to go even if it is interrupted. */ do { struct wordent *new; new = xmalloc(sizeof(*new)); new->word = NULL; new->prev = wdp; new->next = hp; wdp->next = new; hp->prev = new; wdp = new; wdp->word = word(parsehtime); parsehtime = 0; - if (enterhist && toolong++ > 10 * 1024) + if (enterhist && toolong++ > 10 * 1024) { stderror(ERR_LTOOLONG); + } } while (wdp->word[0] != '\n'); cleanup_ignore(hp); cleanup_until(hp); Strbuf_terminate(&histline); if (histline.len != 0 && histline.s[histline.len - 1] == '\n') histline.s[histline.len - 1] = '\0'; histvalid = 1; return (hadhist); } static time_t a2time_t(Char *wordx) { /* Attempt to distinguish timestamps from other possible entries. * Format: "+NNNNNNNNNN" (10 digits, left padded with ascii '0') */ time_t ret; Char *s; int ct; if (!wordx || *(s = wordx) != '+') return (time_t)0; for (++s, ret = 0, ct = 0; *s; ++s, ++ct) { if (!isdigit((unsigned char)*s)) return (time_t)0; ret = ret * 10 + (time_t)((unsigned char)*s - '0'); } if (ct != 10) return (time_t)0; return ret; } void prlex(struct wordent *sp0) { struct wordent *sp = sp0->next; for (;;) { xprintf("%S", sp->word); sp = sp->next; if (sp == sp0) break; if (sp->word[0] != '\n') xputchar(' '); } } void copylex(struct wordent *hp, struct wordent *fp) { struct wordent *wdp; wdp = hp; fp = fp->next; do { struct wordent *new; new = xmalloc(sizeof(*new)); new->word = NULL; new->prev = wdp; new->next = hp; wdp->next = new; hp->prev = new; wdp = new; wdp->word = Strsave(fp->word); fp = fp->next; } while (wdp->word[0] != '\n'); } void initlex(struct wordent *vp) { vp->word = STRNULL; vp->prev = vp; vp->next = vp; } void freelex(struct wordent *vp) { struct wordent *fp; while (vp->next != vp) { fp = vp->next; vp->next = fp->next; xfree(fp->word); xfree(fp); } vp->prev = vp; } void lex_cleanup(void *xvp) { struct wordent *vp; vp = xvp; freelex(vp); } static Char * word(int parsehtime) { eChar c, c1; struct Strbuf wbuf = Strbuf_INIT; Char hbuf[12]; int h; int dolflg; int toolong = 0; cleanup_push(&wbuf, Strbuf_cleanup); loop: - if (enterhist && toolong++ > 256 * 1024) - seterror(ERR_WTOOLONG); + if (enterhist && toolong++ > 256 * 1024) { + stderror(ERR_WTOOLONG); + } while ((c = getC(DOALL)) == ' ' || c == '\t') continue; if (cmap(c, _META | _ESC)) switch (c) { case '&': case '|': case '<': case '>': Strbuf_append1(&wbuf, c); c1 = getC(DOALL); if (c1 == c) Strbuf_append1(&wbuf, c1); else ungetC(c1); goto ret; case '#': if (intty || (enterhist && !parsehtime)) break; c = 0; h = 0; do { c1 = c; c = getC(0); if (h < 11 && parsehtime) hbuf[h++] = c; } while (c != '\n'); if (parsehtime) { hbuf[11] = '\0'; Htime = a2time_t(hbuf); } if (c1 == '\\') goto loop; /*FALLTHROUGH*/ case ';': case '(': case ')': case '\n': Strbuf_append1(&wbuf, c); goto ret; case '\\': c = getC(0); if (c == '\n') { if (onelflg == 1) onelflg = 2; goto loop; } if (c != (eChar)HIST) Strbuf_append1(&wbuf, '\\'); c |= QUOTE; default: break; } c1 = 0; dolflg = DOALL; for (;;) { - if (enterhist && toolong++ > 256 * 1024) - seterror(ERR_WTOOLONG); + if (enterhist && toolong++ > 256 * 1024) { + stderror(ERR_WTOOLONG); + } if (c1) { if (c == c1) { c1 = 0; dolflg = DOALL; } else if (c == '\\') { c = getC(0); /* * PWP: this is dumb, but how all of the other shells work. If \ quotes * a character OUTSIDE of a set of ''s, why shouldn't it quote EVERY * following character INSIDE a set of ''s. * * Actually, all I really want to be able to say is 'foo\'bar' --> foo'bar */ if (c == (eChar)HIST) c |= QUOTE; else { if (bslash_quote && ((c == '\'') || (c == '"') || (c == '\\') || (c == '$'))) { c |= QUOTE; } else { if (c == '\n') /* * if (c1 == '`') c = ' '; else */ c |= QUOTE; ungetC(c); c = '\\' | QUOTE; } } } else if (c == '\n') { seterror(ERR_UNMATCHED, c1); ungetC(c); break; } } else if (cmap(c, _META | _QF | _QB | _ESC)) { if (c == '\\') { c = getC(0); if (c == '\n') { if (onelflg == 1) onelflg = 2; break; } if (c != (eChar)HIST) Strbuf_append1(&wbuf, '\\'); c |= QUOTE; } else if (cmap(c, _QF | _QB)) { /* '"` */ c1 = c; dolflg = c == '"' ? DOALL : DOEXCL; } else if (c != '#' || (!intty && !enterhist)) { ungetC(c); break; } } Strbuf_append1(&wbuf, c); c = getC(dolflg); } ret: cleanup_ignore(&wbuf); cleanup_until(&wbuf); return Strbuf_finish(&wbuf); } static eChar getC1(int flag) { eChar c; for (;;) { if ((c = peekc) != 0) { peekc = 0; return (c); } if (lap < labuf.len) { c = labuf.s[lap++]; if (cmap(c, _META | _QF | _QB)) c |= QUOTE; return (c); } if ((c = peekd) != 0) { peekd = 0; return (c); } if (exclp) { if ((c = *exclp++) != 0) return (c); if (exclnxt && --exclc >= 0) { exclnxt = exclnxt->next; setexclp(exclnxt->word); return (' '); } exclp = 0; exclnxt = 0; /* this will throw away the dummy history entries */ savehist(NULL, 0); } if (exclnxt) { exclnxt = exclnxt->next; if (--exclc < 0) exclnxt = 0; else setexclp(exclnxt->word); continue; } c = readc(1); /* Catch EOF in the middle of a line. (An EOF at the beginning of * a line would have been processed by the readc(0) in lex().) */ if (c == CHAR_ERR) c = '\n'; if (c == '$' && (flag & DODOL)) { getdol(); continue; } if (c == (eChar)HIST && (flag & DOEXCL)) { getexcl(0); continue; } break; } return (c); } static void getdol(void) { struct Strbuf name = Strbuf_INIT; eChar c; eChar sc; int special = 0; c = sc = getC(DOEXCL); if (any("\t \n", c)) { ungetD(c); ungetC('$' | QUOTE); return; } cleanup_push(&name, Strbuf_cleanup); Strbuf_append1(&name, '$'); if (c == '{') Strbuf_append1(&name, c), c = getC(DOEXCL); if (c == '#' || c == '?' || c == '%') special++, Strbuf_append1(&name, c), c = getC(DOEXCL); Strbuf_append1(&name, c); switch (c) { case '<': case '$': case '!': if (special) seterror(ERR_SPDOLLT); goto end; case '\n': ungetD(c); name.len--; if (!special) seterror(ERR_NEWLINE); goto end; case '*': if (special) seterror(ERR_SPSTAR); goto end; default: if (Isdigit(c)) { #ifdef notdef /* let $?0 pass for now */ if (special) { seterror(ERR_DIGIT); goto end; } #endif while ((c = getC(DOEXCL)) != 0) { if (!Isdigit(c)) break; Strbuf_append1(&name, c); } } else if (letter(c)) { while ((c = getC(DOEXCL)) != 0) { /* Bugfix for ${v123x} from Chris Torek, DAS DEC-90. */ if (!letter(c) && !Isdigit(c)) break; Strbuf_append1(&name, c); } } else { if (!special) seterror(ERR_VARILL); else { ungetD(c); name.len--; } goto end; } break; } if (c == '[') { Strbuf_append1(&name, c); do { /* * Michael Greim: Allow $ expansion to take place in selector * expressions. (limits the number of characters returned) */ c = getC(DOEXCL | DODOL); if (c == '\n') { ungetD(c); name.len--; seterror(ERR_NLINDEX); goto end; } Strbuf_append1(&name, c); } while (c != ']'); c = getC(DOEXCL); } if (c == ':') { /* * if the :g modifier is followed by a newline, then error right away! * -strike */ int gmodflag = 0, amodflag = 0; do { - Strbuf_append1(&name, c), c = getC(DOEXCL); + Strbuf_append1(&name, c), c = getC(DOEXCL), gmodflag = 0, amodflag = 0; if (c == 'g' || c == 'a') { if (c == 'g') gmodflag++; else amodflag++; Strbuf_append1(&name, c); c = getC(DOEXCL); } if ((c == 'g' && !gmodflag) || (c == 'a' && !amodflag)) { if (c == 'g') gmodflag++; else amodflag++; Strbuf_append1(&name, c); c = getC(DOEXCL); } Strbuf_append1(&name, c); /* scan s// [eichin:19910926.0512EST] */ if (c == 's') { int delimcnt = 2; eChar delim = getC(0); Strbuf_append1(&name, delim); if (!delim || letter(delim) || Isdigit(delim) || any(" \t\n", delim)) { seterror(ERR_BADSUBST); break; } while ((c = getC(0)) != CHAR_ERR) { Strbuf_append1(&name, c); - if(c == delim) delimcnt--; - if(!delimcnt) break; + if (c == delim) delimcnt--; + if (!delimcnt) break; } - if(delimcnt) { + if (delimcnt) { seterror(ERR_BADSUBST); break; } c = 's'; } - if (!any("htrqxesul", c)) { + if (!any(TCSH_MODIFIERS, c)) { if ((amodflag || gmodflag) && c == '\n') stderror(ERR_VARSYN); /* strike */ seterror(ERR_BADMOD, c); goto end; } } while ((c = getC(DOEXCL)) == ':'); ungetD(c); } else ungetD(c); if (sc == '{') { c = getC(DOEXCL); if (c != '}') { ungetD(c); seterror(ERR_MISSING, '}'); goto end; } Strbuf_append1(&name, c); } end: cleanup_ignore(&name); cleanup_until(&name); addla(Strbuf_finish(&name)); } /* xfree()'s its argument */ void addla(Char *cp) { static struct Strbuf buf; /* = Strbuf_INIT; */ buf.len = 0; Strbuf_appendn(&buf, labuf.s + lap, labuf.len - lap); labuf.len = 0; Strbuf_append(&labuf, cp); Strbuf_terminate(&labuf); Strbuf_appendn(&labuf, buf.s, buf.len); xfree(cp); lap = 0; } /* left-hand side of last :s or search string of last ?event? */ static struct Strbuf lhsb; /* = Strbuf_INIT; */ static struct Strbuf slhs; /* = Strbuf_INIT; left-hand side of last :s */ static struct Strbuf rhsb; /* = Strbuf_INIT; right-hand side of last :s */ static int quesarg; static void getexcl(Char sc) { struct wordent *hp, *ip; int left, right, dol; eChar c; if (sc == 0) { c = getC(0); if (c == '{') sc = (Char) c; else ungetC(c); } quesarg = -1; lastev = eventno; hp = gethent(sc); if (hp == 0) return; hadhist = 1; dol = 0; if (hp == alhistp) for (ip = hp->next->next; ip != alhistt; ip = ip->next) dol++; else for (ip = hp->next->next; ip != hp->prev; ip = ip->next) dol++; left = 0, right = dol; if (sc == HISTSUB && HISTSUB != '\0') { ungetC('s'), unreadc(HISTSUB), c = ':'; goto subst; } c = getC(0); if (!any(":^$*-%", c)) goto subst; left = right = -1; if (c == ':') { c = getC(0); unreadc(c); if (letter(c) || c == '&') { c = ':'; left = 0, right = dol; goto subst; } } else ungetC(c); if (!getsel(&left, &right, dol)) return; c = getC(0); if (c == '*') ungetC(c), c = '-'; if (c == '-') { if (!getsel(&left, &right, dol)) return; c = getC(0); } subst: exclc = right - left + 1; while (--left >= 0) hp = hp->next; if ((sc == HISTSUB && HISTSUB != '\0') || c == ':') { do { hp = getsub(hp); c = getC(0); } while (c == ':'); } unreadc(c); if (sc == '{') { c = getC(0); if (c != '}') seterror(ERR_BADBANG); } exclnxt = hp; } static struct wordent * getsub(struct wordent *en) { eChar delim; eChar c; eChar sc; int global; do { exclnxt = 0; global = 0; sc = c = getC(0); while (c == 'g' || c == 'a') { global |= (c == 'g') ? FLAG_G : FLAG_A; sc = c = getC(0); } switch (c) { case 'p': justpr++; return (en); case 'x': case 'q': global |= FLAG_G; /*FALLTHROUGH*/ case 'h': case 'r': case 't': case 'e': case 'u': case 'l': break; case '&': if (slhs.len == 0) { seterror(ERR_NOSUBST); return (en); } lhsb.len = 0; Strbuf_append(&lhsb, slhs.s); Strbuf_terminate(&lhsb); break; #ifdef notdef case '~': if (lhsb.len == 0) goto badlhs; break; #endif case 's': delim = getC(0); if (letter(delim) || Isdigit(delim) || any(" \t\n", delim)) { unreadc(delim); lhsb.len = 0; seterror(ERR_BADSUBST); return (en); } Strbuf_terminate(&lhsb); lhsb.len = 0; for (;;) { c = getC(0); if (c == '\n') { unreadc(c); break; } if (c == delim) break; if (c == '\\') { c = getC(0); if (c != delim && c != '\\') Strbuf_append1(&lhsb, '\\'); } Strbuf_append1(&lhsb, c); } if (lhsb.len != 0) Strbuf_terminate(&lhsb); else if (lhsb.s[0] == 0) { seterror(ERR_LHS); return (en); } else lhsb.len = Strlen(lhsb.s); /* lhsb.s wasn't changed */ rhsb.len = 0; for (;;) { c = getC(0); if (c == '\n') { unreadc(c); break; } if (c == delim) break; if (c == '\\') { c = getC(0); if (c != delim /* && c != '~' */ ) Strbuf_append1(&rhsb, '\\'); } Strbuf_append1(&rhsb, c); } Strbuf_terminate(&rhsb); break; default: if (c == '\n') unreadc(c); seterror(ERR_BADBANGMOD, (int)c); return (en); } slhs.len = 0; if (lhsb.s != NULL && lhsb.len != 0) Strbuf_append(&slhs, lhsb.s); Strbuf_terminate(&slhs); if (exclc) en = dosub(sc, en, global); } while ((c = getC(0)) == ':'); unreadc(c); return (en); } /* * * From Beto Appleton (beto@aixwiz.austin.ibm.com) * * when using history substitution, and the variable * 'history' is set to a value higher than 1000, * the shell might either freeze (hang) or core-dump. * We raise the limit to 50000000 */ #define HIST_PURGE -50000000 static struct wordent * dosub(Char sc, struct wordent *en, int global) { struct wordent lexi; int didsub = 0, didone = 0; struct wordent *hp = &lexi; struct wordent *wdp; int i = exclc; struct Hist *hst; wdp = hp; while (--i >= 0) { struct wordent *new = xcalloc(1, sizeof *wdp); new->word = 0; new->prev = wdp; new->next = hp; wdp->next = new; wdp = new; en = en->next; if (en->word) { Char *tword, *otword; if ((global & FLAG_G) || didsub == 0) { size_t pos; pos = 0; tword = subword(en->word, sc, &didone, &pos); if (didone) didsub = 1; if (global & FLAG_A) { while (didone && tword != STRNULL) { otword = tword; tword = subword(otword, sc, &didone, &pos); if (Strcmp(tword, otword) == 0) { xfree(otword); break; } else xfree(otword); } } } else tword = Strsave(en->word); wdp->word = tword; } } if (didsub == 0) seterror(ERR_MODFAIL); hp->prev = wdp; /* * ANSI mode HP/UX compiler chokes on * return &enthist(HIST_PURGE, &lexi, 0)->Hlex; */ hst = enthist(HIST_PURGE, &lexi, 0, 0, -1); return &(hst->Hlex); } /* Return a newly allocated result of one modification of CP using the operation TYPE. Set ADID to 1 if a modification was performed. If TYPE == 's', perform substitutions only from *START_POS on and set *START_POS to the position of next substitution attempt. */ static Char * subword(Char *cp, Char type, int *adid, size_t *start_pos) { Char *wp; const Char *mp, *np; switch (type) { case 'r': case 'e': case 'h': case 't': case 'q': case 'x': case 'u': case 'l': wp = domod(cp, type); if (wp == 0) { *adid = 0; return (Strsave(cp)); } *adid = 1; return (wp); default: for (mp = cp + *start_pos; *mp; mp++) { if (matchs(mp, lhsb.s)) { struct Strbuf wbuf = Strbuf_INIT; Strbuf_appendn(&wbuf, cp, mp - cp); for (np = rhsb.s; *np; np++) switch (*np) { case '\\': if (np[1] == '&') np++; /* fall into ... */ default: Strbuf_append1(&wbuf, *np); continue; case '&': Strbuf_append(&wbuf, lhsb.s); continue; } *start_pos = wbuf.len; Strbuf_append(&wbuf, mp + lhsb.len); *adid = 1; return Strbuf_finish(&wbuf); } } *adid = 0; return (Strsave(cp)); } } Char * domod(Char *cp, Char type) { Char *wp, *xp; int c; switch (type) { - + case 'Q': + if (*cp == '\0') + return Strsave(STRQNULL); + /*FALLTHROUGH*/ case 'q': case 'x': - if (*cp == '\0') - return Strsave(STRQNULL); wp = Strsave(cp); for (xp = wp; (c = *xp) != 0; xp++) - if ((c != ' ' && c != '\t') || type == 'q') + if ((c != ' ' && c != '\t') || type == 'q' || type == 'Q') *xp |= QUOTE; return (wp); case 'l': wp = NLSChangeCase(cp, 1); return wp ? wp : Strsave(cp); case 'u': wp = NLSChangeCase(cp, 0); return wp ? wp : Strsave(cp); case 'h': case 't': - if (!any(short2str(cp), '/')) - return (type == 't' ? Strsave(cp) : 0); wp = Strrchr(cp, '/'); - if (type == 'h') - xp = Strnsave(cp, wp - cp); - else + if (wp == NULL) + return NULL; + if (type == 't') xp = Strsave(wp + 1); + else + xp = Strnsave(cp, wp - cp); return (xp); case 'e': case 'r': wp = Strend(cp); for (wp--; wp >= cp && *wp != '/'; wp--) if (*wp == '.') { if (type == 'e') xp = Strsave(wp + 1); else xp = Strnsave(cp, wp - cp); return (xp); } return (Strsave(type == 'e' ? STRNULL : cp)); + default: break; } return (0); } static int matchs(const Char *str, const Char *pat) { while (*str && *pat && *str == *pat) str++, pat++; return (*pat == 0); } static int getsel(int *al, int *ar, int dol) { eChar c = getC(0); int i; int first = *al < 0; switch (c) { case '%': if (quesarg == -1) { seterror(ERR_BADBANGARG); return (0); } if (*al < 0) *al = quesarg; *ar = quesarg; break; case '-': if (*al < 0) { *al = 0; *ar = dol - 1; unreadc(c); } return (1); case '^': if (*al < 0) *al = 1; *ar = 1; break; case '$': if (*al < 0) *al = dol; *ar = dol; break; case '*': if (*al < 0) *al = 1; *ar = dol; if (*ar < *al) { *ar = 0; *al = 1; return (1); } break; default: if (Isdigit(c)) { i = 0; while (Isdigit(c)) { i = i * 10 + c - '0'; c = getC(0); } if (i < 0) i = dol + 1; if (*al < 0) *al = i; *ar = i; } else if (*al < 0) *al = 0, *ar = dol; else *ar = dol - 1; unreadc(c); break; } if (first) { c = getC(0); unreadc(c); if (any("-$*", c)) return (1); } if (*al > *ar || *ar > dol) { seterror(ERR_BADBANGARG); return (0); } return (1); } static struct wordent * gethent(Char sc) { struct Hist *hp; Char *np; eChar c; int event; int back = 0; c = (sc == HISTSUB && HISTSUB != '\0') ? (eChar)HIST : getC(0); if (c == (eChar)HIST) { if (alhistp) return (alhistp); event = eventno; } else switch (c) { case ':': case '^': case '$': case '*': case '%': ungetC(c); if (lastev == eventno && alhistp) return (alhistp); event = lastev; break; case '#': /* !# is command being typed in (mrh) */ if (--hleft == 0) { seterror(ERR_HISTLOOP); return (0); } else return (¶ml); /* NOTREACHED */ case '-': back = 1; c = getC(0); /* FALLSTHROUGH */ default: if (any("(=~", c)) { unreadc(c); ungetC(HIST); return (0); } Strbuf_terminate(&lhsb); lhsb.len = 0; event = 0; while (!cmap(c, _ESC | _META | _QF | _QB) && !any("^*-%${}:#", c)) { if (event != -1 && Isdigit(c)) event = event * 10 + c - '0'; else event = -1; Strbuf_append1(&lhsb, c); c = getC(0); } unreadc(c); if (lhsb.len == 0) { lhsb.len = Strlen(lhsb.s); /* lhsb.s wasn't changed */ ungetC(HIST); return (0); } Strbuf_terminate(&lhsb); if (event != -1) { /* * History had only digits */ if (back) event = eventno + (alhistp == 0) - event; break; } if (back) { Strbuf_append1(&lhsb, '\0'); /* Allocate space */ Strbuf_terminate(&lhsb); memmove(lhsb.s + 1, lhsb.s, (lhsb.len - 1) * sizeof (*lhsb.s)); lhsb.s[0] = '-'; } hp = findev(lhsb.s, 0); if (hp) lastev = hp->Hnum; return (&hp->Hlex); case '?': Strbuf_terminate(&lhsb); lhsb.len = 0; for (;;) { c = getC(0); if (c == '\n') { unreadc(c); break; } if (c == '?') break; Strbuf_append1(&lhsb, c); } if (lhsb.len == 0) { lhsb.len = Strlen(lhsb.s); /* lhsb.s wasn't changed */ if (lhsb.len == 0) { seterror(ERR_NOSEARCH); return (0); } } else Strbuf_terminate(&lhsb); hp = findev(lhsb.s, 1); if (hp) lastev = hp->Hnum; return (&hp->Hlex); } for (hp = Histlist.Hnext; hp; hp = hp->Hnext) if (hp->Hnum == event) { hp->Href = eventno; lastev = hp->Hnum; return (&hp->Hlex); } np = putn((tcsh_number_t)event); seterror(ERR_NOEVENT, short2str(np)); xfree(np); return (0); } static struct Hist * findev(Char *cp, int anyarg) { struct Hist *hp; for (hp = Histlist.Hnext; hp; hp = hp->Hnext) { Char *dp; Char *p, *q; struct wordent *lp = hp->Hlex.next; int argno = 0; /* * The entries added by alias substitution don't have a newline but do * have a negative event number. Savehist() trims off these entries, * but it happens before alias expansion, too early to delete those * from the previous command. */ if (hp->Hnum < 0) continue; if (lp->word[0] == '\n') continue; if (!anyarg) { p = cp; q = lp->word; do if (!*p) return (hp); while (*p++ == *q++); continue; } do { for (dp = lp->word; *dp; dp++) { p = cp; q = dp; do if (!*p) { quesarg = argno; return (hp); } while (*p++ == *q++); } lp = lp->next; argno++; } while (lp->word[0] != '\n'); } seterror(ERR_NOEVENT, short2str(cp)); return (0); } static void setexclp(Char *cp) { if (cp && cp[0] == '\n') return; exclp = cp; } void unreadc(Char c) { peekread = (Char) c; } eChar readc(int wanteof) { eChar c; static int sincereal; /* Number of real EOFs we've seen */ #ifdef DEBUG_INP xprintf("readc\n"); #endif if ((c = peekread) != 0) { peekread = 0; return (c); } top: aret = TCSH_F_SEEK; if (alvecp) { arun = 1; #ifdef DEBUG_INP xprintf("alvecp %c\n", *alvecp & 0xff); #endif aret = TCSH_A_SEEK; if ((c = *alvecp++) != 0) return (c); if (alvec && *alvec) { alvecp = *alvec++; return (' '); } else { alvecp = NULL; aret = TCSH_F_SEEK; return('\n'); } } if (alvec) { arun = 1; if ((alvecp = *alvec) != 0) { alvec++; goto top; } /* Infinite source! */ return ('\n'); } arun = 0; if (evalp) { aret = TCSH_E_SEEK; if ((c = *evalp++) != 0) return (c); if (evalvec && *evalvec) { evalp = *evalvec++; return (' '); } aret = TCSH_F_SEEK; evalp = 0; } if (evalvec) { if (evalvec == INVPPTR) { doneinp = 1; reset(); } if ((evalp = *evalvec) != 0) { evalvec++; goto top; } evalvec = INVPPTR; return ('\n'); } do { if (arginp == INVPTR || onelflg == 1) { if (wanteof) return CHAR_ERR; exitstat(); } if (arginp) { if ((c = *arginp++) == 0) { arginp = INVPTR; return ('\n'); } return (c); } #ifdef BSDJOBS reread: #endif /* BSDJOBS */ c = bgetc(); if (c == CHAR_ERR) { #ifndef WINNT_NATIVE # ifndef POSIX # ifdef TERMIO struct termio tty; # else /* SGTTYB */ struct sgttyb tty; # endif /* TERMIO */ # else /* POSIX */ struct termios tty; # endif /* POSIX */ #endif /* !WINNT_NATIVE */ if (wanteof) return CHAR_ERR; /* was isatty but raw with ignoreeof yields problems */ #ifndef WINNT_NATIVE # ifndef POSIX # ifdef TERMIO if (ioctl(SHIN, TCGETA, (ioctl_t) & tty) == 0 && (tty.c_lflag & ICANON)) # else /* GSTTYB */ if (ioctl(SHIN, TIOCGETP, (ioctl_t) & tty) == 0 && (tty.sg_flags & RAW) == 0) # endif /* TERMIO */ # else /* POSIX */ if (tcgetattr(SHIN, &tty) == 0 && (tty.c_lflag & ICANON)) # endif /* POSIX */ #else /* WINNT_NATIVE */ if (isatty(SHIN)) #endif /* !WINNT_NATIVE */ { #ifdef BSDJOBS pid_t ctpgrp; #endif /* BSDJOBS */ if (numeof != 0 && ++sincereal >= numeof) /* Too many EOFs? Bye! */ goto oops; #ifdef BSDJOBS if (tpgrp != -1 && (ctpgrp = tcgetpgrp(FSHTTY)) != -1 && tpgrp != ctpgrp) { (void) tcsetpgrp(FSHTTY, tpgrp); # ifdef _SEQUENT_ if (ctpgrp) # endif /* _SEQUENT */ (void) killpg(ctpgrp, SIGHUP); # ifdef notdef /* * With the walking process group fix, this message * is now obsolete. As the foreground process group * changes, the shell needs to adjust. Well too bad. */ xprintf(CGETS(16, 1, "Reset tty pgrp from %d to %d\n"), (int)ctpgrp, (int)tpgrp); # endif /* notdef */ goto reread; } #endif /* BSDJOBS */ /* What follows is complicated EOF handling -- sterling@netcom.com */ /* First, we check to see if we have ignoreeof set */ if (adrof(STRignoreeof)) { /* If so, we check for any stopped jobs only on the first EOF */ if ((sincereal == 1) && (chkstop == 0)) { panystop(1); } } else { /* If we don't have ignoreeof set, always check for stopped jobs */ if (chkstop == 0) { panystop(1); } } /* At this point, if there were stopped jobs, we would have already * called reset(). If we got this far, assume we can print an * exit/logout message if we ignoreeof, or just exit. */ if (adrof(STRignoreeof)) { /* If so, tell the user to use exit or logout */ if (loginsh) { xprintf("%s", CGETS(16, 2, "\nUse \"logout\" to logout.\n")); } else { xprintf(CGETS(16, 3, "\nUse \"exit\" to leave %s.\n"), progname); } reset(); } else { /* If we don't have ignoreeof set, just fall through */ ; /* EMPTY */ } } oops: doneinp = 1; reset(); } sincereal = 0; if (c == '\n' && onelflg) onelflg--; } while (c == 0); Strbuf_append1(&histline, c); return (c); } static void balloc(int buf) { Char **nfbuf; while (buf >= fblocks) { nfbuf = xcalloc(fblocks + 2, sizeof(Char **)); if (fbuf) { (void) blkcpy(nfbuf, fbuf); xfree(fbuf); } fbuf = nfbuf; fbuf[fblocks] = xcalloc(BUFSIZE, sizeof(Char)); fblocks++; } } ssize_t wide_read(int fildes, Char *buf, size_t nchars, int use_fclens) { char cbuf[BUFSIZE + 1]; ssize_t res, r = 0; size_t partial; int err; if (nchars == 0) return 0; assert (nchars <= sizeof(cbuf) / sizeof(*cbuf)); USE(use_fclens); res = 0; partial = 0; do { size_t i; size_t len = nchars > partial ? nchars - partial : 1; if (partial + len >= sizeof(cbuf) / sizeof(*cbuf)) break; r = xread(fildes, cbuf + partial, len); if (partial == 0 && r <= 0) break; partial += r; i = 0; while (i < partial && nchars != 0) { int tlen; tlen = normal_mbtowc(buf + res, cbuf + i, partial - i); if (tlen == -1) { reset_mbtowc(); if ((partial - i) < MB_LEN_MAX && r > 0) /* Maybe a partial character and there is still a chance to read more */ break; buf[res] = (unsigned char)cbuf[i] | INVALID_BYTE; } if (tlen <= 0) tlen = 1; #ifdef WIDE_STRINGS if (use_fclens) fclens[res] = tlen; #endif i += tlen; res++; nchars--; } if (i != partial) memmove(cbuf, cbuf + i, partial - i); partial -= i; } while (partial != 0 && nchars > 0); /* Throwing away possible partial multibyte characters on error if the stream is not seekable */ err = errno; lseek(fildes, -(off_t)partial, L_INCR); errno = err; return res != 0 ? res : r; } static eChar bgetc(void) { Char ch; int c, off, buf; int numleft = 0, roomleft; if (cantell) { if (fseekp < fbobp || fseekp > feobp) { fbobp = feobp = fseekp; (void) lseek(SHIN, fseekp, L_SET); } if (fseekp == feobp) { #ifdef WIDE_STRINGS off_t bytes; size_t i; bytes = fbobp; for (i = 0; i < (size_t)(feobp - fbobp); i++) bytes += fclens[i]; fseekp = feobp = bytes; #endif fbobp = feobp; c = wide_read(SHIN, fbuf[0], BUFSIZE, 1); #ifdef convex if (c < 0) stderror(ERR_SYSTEM, progname, strerror(errno)); #endif /* convex */ if (c <= 0) return CHAR_ERR; feobp += c; } #if !defined(WINNT_NATIVE) && !defined(__CYGWIN__) ch = fbuf[0][fseekp - fbobp]; fseekp++; #else do { ch = fbuf[0][fseekp - fbobp]; fseekp++; - } while(ch == '\r'); + } while (ch == '\r'); #endif /* !WINNT_NATIVE && !__CYGWIN__ */ return (ch); } while (fseekp >= feobp) { if ((editing #if defined(FILEC) && defined(TIOCSTI) || filec #endif /* FILEC && TIOCSTI */ ) && intty) { /* then use twenex routine */ fseekp = feobp; /* where else? */ #if defined(FILEC) && defined(TIOCSTI) if (!editing) c = numleft = tenex(InputBuf, BUFSIZE); else #endif /* FILEC && TIOCSTI */ c = numleft = Inputl(); /* PWP: get a line */ while (numleft > 0) { off = (int) feobp % BUFSIZE; buf = (int) feobp / BUFSIZE; balloc(buf); roomleft = BUFSIZE - off; if (roomleft > numleft) roomleft = numleft; (void) memcpy(fbuf[buf] + off, InputBuf + c - numleft, roomleft * sizeof(Char)); numleft -= roomleft; feobp += roomleft; } } else { off = (int) feobp % BUFSIZE; buf = (int) feobp / BUFSIZE; balloc(buf); roomleft = BUFSIZE - off; c = wide_read(SHIN, fbuf[buf] + off, roomleft, 0); if (c > 0) feobp += c; } if (c == 0 || (c < 0 && fixio(SHIN, errno) == -1)) return CHAR_ERR; } #ifdef SIG_WINDOW if (windowchg) (void) check_window_size(0); /* for window systems */ #endif /* SIG_WINDOW */ #if !defined(WINNT_NATIVE) && !defined(__CYGWIN__) ch = fbuf[(int) fseekp / BUFSIZE][(int) fseekp % BUFSIZE]; fseekp++; #else do { ch = fbuf[(int) fseekp / BUFSIZE][(int) fseekp % BUFSIZE]; fseekp++; - } while(ch == '\r'); + } while (ch == '\r'); #endif /* !WINNT_NATIVE && !__CYGWIN__ */ return (ch); } static void bfree(void) { int sb, i; if (cantell) return; if (whyles) return; sb = (int) (fseekp - 1) / BUFSIZE; if (sb > 0) { for (i = 0; i < sb; i++) xfree(fbuf[i]); (void) blkcpy(fbuf, &fbuf[sb]); fseekp -= BUFSIZE * sb; feobp -= BUFSIZE * sb; fblocks -= sb; } } void bseek(struct Ain *l) { switch (aret = l->type) { case TCSH_E_SEEK: evalvec = l->a_seek; evalp = l->c_seek; #ifdef DEBUG_SEEK xprintf(CGETS(16, 4, "seek to eval %x %x\n"), evalvec, evalp); #endif return; case TCSH_A_SEEK: alvec = l->a_seek; alvecp = l->c_seek; #ifdef DEBUG_SEEK xprintf(CGETS(16, 5, "seek to alias %x %x\n"), alvec, alvecp); #endif return; case TCSH_F_SEEK: #ifdef DEBUG_SEEK xprintf(CGETS(16, 6, "seek to file %x\n"), fseekp); #endif fseekp = l->f_seek; #ifdef WIDE_STRINGS if (cantell) { if (fseekp >= fbobp && feobp >= fbobp) { size_t i; off_t o; o = fbobp; for (i = 0; i < (size_t)(feobp - fbobp); i++) { if (fseekp == o) { fseekp = fbobp + i; return; } o += fclens[i]; } if (fseekp == o) { fseekp = feobp; return; } } fbobp = feobp = fseekp + 1; /* To force lseek() */ } #endif return; default: xprintf(CGETS(16, 7, "Bad seek type %d\n"), aret); abort(); } } /* any similarity to bell telephone is purely accidental */ void btell(struct Ain *l) { switch (l->type = aret) { case TCSH_E_SEEK: l->a_seek = evalvec; l->c_seek = evalp; #ifdef DEBUG_SEEK xprintf(CGETS(16, 8, "tell eval %x %x\n"), evalvec, evalp); #endif return; case TCSH_A_SEEK: l->a_seek = alvec; l->c_seek = alvecp; #ifdef DEBUG_SEEK xprintf(CGETS(16, 9, "tell alias %x %x\n"), alvec, alvecp); #endif return; case TCSH_F_SEEK: #ifdef WIDE_STRINGS if (cantell && fseekp >= fbobp && fseekp <= feobp) { size_t i; l->f_seek = fbobp; for (i = 0; i < (size_t)(fseekp - fbobp); i++) l->f_seek += fclens[i]; } else #endif /*SUPPRESS 112*/ l->f_seek = fseekp; l->a_seek = NULL; #ifdef DEBUG_SEEK xprintf(CGETS(16, 10, "tell file %x\n"), fseekp); #endif return; default: xprintf(CGETS(16, 7, "Bad seek type %d\n"), aret); abort(); } } void btoeof(void) { (void) lseek(SHIN, (off_t) 0, L_XTND); aret = TCSH_F_SEEK; fseekp = feobp; alvec = NULL; alvecp = NULL; evalvec = NULL; evalp = NULL; wfree(); bfree(); } void settell(void) { off_t x; cantell = 0; if (arginp || onelflg || intty) return; if ((x = lseek(SHIN, (off_t) 0, L_INCR)) == -1) return; fbuf = xcalloc(2, sizeof(Char **)); fblocks = 1; fbuf[0] = xcalloc(BUFSIZE, sizeof(Char)); fseekp = fbobp = feobp = x; cantell = 1; } diff --git a/contrib/tcsh/sh.misc.c b/contrib/tcsh/sh.misc.c index 96c783b56408..bf6bcc994099 100644 --- a/contrib/tcsh/sh.misc.c +++ b/contrib/tcsh/sh.misc.c @@ -1,704 +1,723 @@ /* * sh.misc.c: Miscelaneous functions */ /*- * Copyright (c) 1980, 1991 The Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include "sh.h" static int renum (int, int); static Char **blkend (Char **); static Char **blkcat (Char **, Char **); static int xdup2 (int, int); /* * C Shell */ int any(const char *s, Char c) { if (!s) return (0); /* Check for nil pointer */ while (*s) if ((Char)*s++ == c) return (1); return (0); } void setzero(void *p, size_t size) { memset(p, 0, size); } #ifndef SHORT_STRINGS char * strnsave(const char *s, size_t len) { char *r; r = xmalloc(len + 1); memcpy(r, s, len); r[len] = '\0'; return r; } #endif char * strsave(const char *s) { char *r; size_t size; if (s == NULL) s = ""; size = strlen(s) + 1; r = xmalloc(size); memcpy(r, s, size); return (r); } static Char ** blkend(Char **up) { while (*up) up++; return (up); } void blkpr(Char *const *av) { for (; *av; av++) { xprintf("%S", *av); if (av[1]) xprintf(" "); } } Char * blkexpand(Char *const *av) { struct Strbuf buf = Strbuf_INIT; for (; *av; av++) { Strbuf_append(&buf, *av); if (av[1]) Strbuf_append1(&buf, ' '); } return Strbuf_finish(&buf); } int blklen(Char **av) { int i = 0; while (*av++) i++; return (i); } Char ** blkcpy(Char **oav, Char **bv) { Char **av = oav; while ((*av++ = *bv++) != NULL) continue; return (oav); } static Char ** blkcat(Char **up, Char **vp) { (void) blkcpy(blkend(up), vp); return (up); } void blkfree(Char **av0) { Char **av = av0; if (!av0) return; for (; *av; av++) xfree(*av); xfree(av0); } void blk_cleanup(void *ptr) { blkfree(ptr); } void blk_indirect_cleanup(void *xptr) { Char ***ptr; ptr = xptr; blkfree(*ptr); xfree(ptr); } Char ** saveblk(Char **v) { Char **newv, **onewv; if (v == NULL) return NULL; onewv = newv = xcalloc(blklen(v) + 1, sizeof(Char **)); while (*v) *newv++ = Strsave(*v++); return (onewv); } #ifndef HAVE_STRSTR char * strstr(const char *s, const char *t) { do { const char *ss = s; const char *tt = t; do if (*tt == '\0') return (s); while (*ss++ == *tt++); } while (*s++ != '\0'); return (NULL); } #endif /* !HAVE_STRSTR */ char * strspl(const char *cp, const char *dp) { char *ep; size_t cl, dl; if (!cp) cp = ""; if (!dp) dp = ""; cl = strlen(cp); dl = strlen(dp); ep = xmalloc((cl + dl + 1) * sizeof(char)); memcpy(ep, cp, cl); memcpy(ep + cl, dp, dl + 1); return (ep); } Char ** blkspl(Char **up, Char **vp) { Char **wp = xcalloc(blklen(up) + blklen(vp) + 1, sizeof(Char **)); (void) blkcpy(wp, up); return (blkcat(wp, vp)); } Char lastchr(Char *cp) { if (!cp) return (0); if (!*cp) return (0); while (cp[1]) cp++; return (*cp); } /* * This routine is called after an error to close up * any units which may have been left open accidentally. */ void closem(void) { int f, num_files; #ifdef S_ISSOCK struct stat st; #endif /*S_ISSOCK*/ #ifdef NLS_BUGS #ifdef NLS_CATALOGS nlsclose(); #endif /* NLS_CATALOGS */ #endif /* NLS_BUGS */ #ifdef YPBUGS /* suggested by Justin Bur; thanks to Karl Kleinpaste */ fix_yp_bugs(); #endif /* YPBUGS */ num_files = NOFILE; for (f = 0; f < num_files; f++) if (f != SHIN && f != SHOUT && f != SHDIAG && f != OLDSTD && f != FSHTTY #ifdef MALLOC_TRACE && f != 25 #endif /* MALLOC_TRACE */ #ifdef S_ISSOCK /* NSS modules (e.g. Linux nss_ldap) might keep sockets open. * If we close such a socket, both the NSS module and tcsh think * they "own" the descriptor. * * Not closing sockets does not make the cleanup use of closem() * less reliable because tcsh never creates sockets. */ && fstat(f, &st) == 0 && !S_ISSOCK(st.st_mode) #endif ) { xclose(f); #ifdef NISPLUS - if(f < 3) + if (f < 3) (void) xopen(_PATH_DEVNULL, O_RDONLY|O_LARGEFILE); #endif /* NISPLUS */ } #ifdef NLS_BUGS #ifdef NLS_CATALOGS nlsinit(); #endif /* NLS_CATALOGS */ #endif /* NLS_BUGS */ } #ifndef CLOSE_ON_EXEC /* * Close files before executing a file. * We could be MUCH more intelligent, since (on a version 7 system) * we need only close files here during a source, the other * shell fd's being in units 16-19 which are closed automatically! */ void closech(void) { int f, num_files; if (didcch) return; didcch = 1; SHIN = 0; SHOUT = 1; SHDIAG = 2; OLDSTD = 0; isoutatty = isatty(SHOUT); isdiagatty = isatty(SHDIAG); num_files = NOFILE; for (f = 3; f < num_files; f++) xclose(f); } #endif /* CLOSE_ON_EXEC */ void donefds(void) { xclose(0); xclose(1); xclose(2); didfds = 0; #ifdef NISPLUS { int fd = xopen(_PATH_DEVNULL, O_RDONLY|O_LARGEFILE); (void)dcopy(fd, 1); (void)dcopy(fd, 2); (void)dmove(fd, 0); } #endif /*NISPLUS*/ } /* * Move descriptor i to j. * If j is -1 then we just want to get i to a safe place, * i.e. to a unit > FSAFE. This also happens in dcopy. */ int dmove(int i, int j) { if (i == j || i < 0) return (i); #ifdef HAVE_DUP2 if (j >= 0) { (void) xdup2(i, j); if (j != i) xclose(i); return (j); } #endif j = dcopy(i, j); if (j != i) xclose(i); return (j); } int dcopy(int i, int j) { if (i == j || i < 0 || (j < 0 && i > FSAFE)) return (i); if (j >= 0) { #ifdef HAVE_DUP2 (void) xdup2(i, j); return (j); #else xclose(j); #endif } return (renum(i, j)); } static int renum(int i, int j) { int k = dup(i); if (k < 0) return (-1); if (j == -1 && k > FSAFE) return (k); if (k != j) { j = renum(k, j); xclose(k); return (j); } return (k); } /* * Left shift a command argument list, discarding * the first c arguments. Used in "shift" commands * as well as by commands like "repeat". */ void lshift(Char **v, int c) { Char **u; for (u = v; *u && --c >= 0; u++) xfree(*u); (void) blkcpy(v, u); } int number(Char *cp) { if (!cp) return (0); if (*cp == '-') { cp++; if (!Isdigit(*cp)) return (0); cp++; } while (*cp && Isdigit(*cp)) cp++; return (*cp == 0); } Char ** copyblk(Char **v) { Char **nv = xcalloc(blklen(v) + 1, sizeof(Char **)); return (blkcpy(nv, v)); } char * strend(const char *cp) { if (!cp) return ((char *)(intptr_t)cp); while (*cp) cp++; return ((char *)(intptr_t)cp); } Char * strip(Char *cp) { Char *dp = cp; if (!cp) return (cp); while (*dp != '\0') { #if INVALID_BYTE != 0 if ((*dp & INVALID_BYTE) != INVALID_BYTE) /* *dp < INVALID_BYTE */ #endif *dp &= TRIM; dp++; } return (cp); } Char * quote(Char *cp) { Char *dp = cp; if (!cp) return (cp); while (*dp != '\0') { #ifdef WIDE_STRINGS if ((*dp & 0xffffff80) == 0) /* *dp < 0x80 */ #elif defined SHORT_STRINGS if ((*dp & 0xff80) == 0) /* *dp < 0x80 */ #else if ((*dp & 0x80) == 0) /* *dp < 0x80 */ #endif *dp |= QUOTE; dp++; } return (cp); } const Char * quote_meta(struct Strbuf *buf, const Char *s) { buf->len = 0; while (*s != '\0') { if (cmap(*s, _META | _DOL | _QF | _QB | _ESC | _GLOB)) Strbuf_append1(buf, '\\'); Strbuf_append1(buf, *s++); } Strbuf_terminate(buf); return buf->s; } void udvar(Char *name) { setname(short2str(name)); stderror(ERR_NAME | ERR_UNDVAR); } int prefix(const Char *sub, const Char *str) { for (;;) { if (*sub == 0) return (1); if (*str == 0) return (0); if ((*sub++ & TRIM) != (*str++ & TRIM)) return (0); } } #ifndef WINNT_NATIVE char * areadlink(const char *path) { char *buf; size_t size; ssize_t res; +#ifdef __IBMC__ + /* + * Prevent infinite recursion. Someone should tell me how to expand + * these... + */ + size_t i; + static const char *vars[] = { + "/$VERSION", + "/$SYSNAME", + "/$SYSSYMR", + "/$SYSSYMA", + }; + for (i = 0; i < sizeof(vars) / sizeof(vars[0]); i++) { + if (strcmp(vars[i], path) == 0) { + return NULL; + } + } +#endif + size = MAXPATHLEN + 1; buf = xmalloc(size); while ((size_t)(res = readlink(path, buf, size)) == size) { size *= 2; buf = xrealloc(buf, size); } if (res == -1) { int err; err = errno; xfree(buf); errno = err; return NULL; } buf[res] = '\0'; return xrealloc(buf, res + 1); } #endif /*!WINNT_NATIVE*/ void xclose(int fildes) { if (fildes < 0) return; while (close(fildes) == -1 && errno == EINTR) if (handle_pending_signals()) break; } void xclosedir(DIR *dirp) { while (closedir(dirp) == -1 && errno == EINTR) if (handle_pending_signals()) break; } int xcreat(const char *path, mode_t mode) { int res; while ((res = creat(path, mode)) == -1 && errno == EINTR) if (handle_pending_signals()) break; return res; } #ifdef HAVE_DUP2 static int xdup2(int fildes, int fildes2) { int res; while ((res = dup2(fildes, fildes2)) == -1 && errno == EINTR) if (handle_pending_signals()) break; return res; } #endif struct group * xgetgrgid(gid_t xgid) { struct group *res; errno = 0; while ((res = getgrgid(xgid)) == NULL && errno == EINTR) { if (handle_pending_signals()) break; errno = 0; } return res; } struct passwd * xgetpwnam(const char *name) { struct passwd *res; errno = 0; while ((res = getpwnam(name)) == NULL && errno == EINTR) { if (handle_pending_signals()) break; errno = 0; } return res; } struct passwd * xgetpwuid(uid_t xuid) { struct passwd *res; errno = 0; while ((res = getpwuid(xuid)) == NULL && errno == EINTR) { if (handle_pending_signals()) break; errno = 0; } return res; } int xopen(const char *path, int oflag, ...) { int res; if ((oflag & O_CREAT) == 0) { while ((res = open(path, oflag)) == -1 && errno == EINTR) if (handle_pending_signals()) break; } else { va_list ap; mode_t mode; va_start(ap, oflag); /* "int" should actually be "mode_t after default argument promotions". "int" is the best guess we have, "mode_t" used to be "unsigned short", which we obviously can't use. */ mode = va_arg(ap, int); va_end(ap); while ((res = open(path, oflag, mode)) == -1 && errno == EINTR) if (handle_pending_signals()) break; } return res; } ssize_t xread(int fildes, void *buf, size_t nbyte) { ssize_t res = -1; /* This is where we will be blocked most of the time, so handle signals that didn't interrupt any system call. */ do if (handle_pending_signals()) break; while ((res = read(fildes, buf, nbyte)) == -1 && errno == EINTR); return res; } #ifdef POSIX int xtcsetattr(int fildes, int optional_actions, const struct termios *termios_p) { int res; while ((res = tcsetattr(fildes, optional_actions, termios_p)) == -1 && errno == EINTR) if (handle_pending_signals()) break; return res; } #endif ssize_t xwrite(int fildes, const void *buf, size_t nbyte) { ssize_t res = -1; /* This is where we will be blocked most of the time, so handle signals that didn't interrupt any system call. */ do if (handle_pending_signals()) break; while ((res = write(fildes, buf, nbyte)) == -1 && errno == EINTR); return res; } diff --git a/contrib/tcsh/sh.set.c b/contrib/tcsh/sh.set.c index f15e41fcedaf..e51fdae11cc1 100644 --- a/contrib/tcsh/sh.set.c +++ b/contrib/tcsh/sh.set.c @@ -1,1356 +1,1352 @@ /* * sh.set.c: Setting and Clearing of variables */ /*- * Copyright (c) 1980, 1991 The Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include "sh.h" #include "ed.h" #include "tw.h" #ifdef HAVE_NL_LANGINFO #include #endif extern int GotTermCaps; int numeof = 0; static void update_vars (Char *); static Char *getinx (Char *, int *); static void asx (Char *, int, Char *); static struct varent *getvx (Char *, int); static Char *xset (Char *, Char ***); static Char *operate (int, Char *, Char *); static void putn1 (tcsh_number_t); static struct varent *madrof (Char *, struct varent *); static void unsetv1 (struct varent *); static void exportpath (Char **); static void balance (struct varent *, int, int); static int set_noclobber (Char **); /* * C Shell */ static void update_vars(Char *vp) { if (eq(vp, STRpath)) { struct varent *p = adrof(STRpath); if (p == NULL) stderror(ERR_NAME | ERR_UNDVAR); else { exportpath(p->vec); dohash(NULL, NULL); } } else if (eq(vp, STRnoclobber)) { struct varent *p = adrof(STRnoclobber); if (p == NULL) stderror(ERR_NAME | ERR_UNDVAR); else no_clobber = set_noclobber(p->vec); } else if (eq(vp, STRhistchars)) { Char *pn = varval(vp); HIST = *pn++; if (HIST) HISTSUB = *pn; else HISTSUB = HIST; } else if (eq(vp, STRpromptchars)) { Char *pn = varval(vp); PRCH = *pn++; if (PRCH) PRCHROOT = *pn; else PRCHROOT = PRCH; } else if (eq(vp, STRhistlit)) { HistLit = 1; } else if (eq(vp, STRuser)) { tsetenv(STRKUSER, varval(vp)); tsetenv(STRLOGNAME, varval(vp)); } else if (eq(vp, STRgroup)) { tsetenv(STRKGROUP, varval(vp)); } else if (eq(vp, STRwordchars)) { word_chars = varval(vp); } else if (eq(vp, STRloginsh)) { loginsh = 1; } else if (eq(vp, STRanyerror)) { anyerror = 1; } else if (eq(vp, STRsymlinks)) { Char *pn = varval(vp); if (eq(pn, STRignore)) symlinks = SYM_IGNORE; else if (eq(pn, STRexpand)) symlinks = SYM_EXPAND; else if (eq(pn, STRchase)) symlinks = SYM_CHASE; else symlinks = 0; } else if (eq(vp, STRterm)) { Char *cp = varval(vp); tsetenv(STRKTERM, cp); #ifdef DOESNT_WORK_RIGHT cp = getenv("TERMCAP"); if (cp && (*cp != '/')) /* if TERMCAP and not a path */ Unsetenv(STRTERMCAP); #endif /* DOESNT_WORK_RIGHT */ GotTermCaps = 0; if (noediting && Strcmp(cp, STRnetwork) != 0 && Strcmp(cp, STRunknown) != 0 && Strcmp(cp, STRdumb) != 0) { editing = 1; noediting = 0; setNS(STRedit); } ed_Init(); /* reset the editor */ } else if (eq(vp, STRhome)) { Char *cp, *canon; cp = Strsave(varval(vp)); /* get the old value back */ - cleanup_push(cp, xfree); - /* * convert to cononical pathname (possibly resolving symlinks) */ canon = dcanon(cp, cp); - cleanup_ignore(cp); - cleanup_until(cp); cleanup_push(canon, xfree); setcopy(vp, canon, VAR_READWRITE); /* have to save the new val */ /* and now mirror home with HOME */ tsetenv(STRKHOME, canon); /* fix directory stack for new tilde home */ dtilde(); cleanup_until(canon); } else if (eq(vp, STRedit)) { editing = 1; noediting = 0; /* PWP: add more stuff in here later */ } else if (eq(vp, STRvimode)) { VImode = 1; update_wordchars(); } else if (eq(vp, STRshlvl)) { tsetenv(STRKSHLVL, varval(vp)); } else if (eq(vp, STRignoreeof)) { Char *cp; numeof = 0; for ((cp = varval(STRignoreeof)); cp && *cp; cp++) { if (!Isdigit(*cp)) { numeof = 0; break; } numeof = numeof * 10 + *cp - '0'; } if (numeof <= 0) numeof = 26; /* Sanity check */ } else if (eq(vp, STRbackslash_quote)) { bslash_quote = 1; } else if (eq(vp, STRcompat_expr)) { compat_expr = 1; } else if (eq(vp, STRdirstack)) { dsetstack(); } else if (eq(vp, STRrecognize_only_executables)) { tw_cmd_free(); } else if (eq(vp, STRkillring)) { SetKillRing((int)getn(varval(vp))); } else if (eq(vp, STRhistory)) { sethistory((int)getn(varval(vp))); } #ifndef HAVENOUTMP else if (eq(vp, STRwatch)) { resetwatch(); } #endif /* HAVENOUTMP */ else if (eq(vp, STRimplicitcd)) { implicit_cd = ((eq(varval(vp), STRverbose)) ? 2 : 1); } else if (eq(vp, STRcdtohome)) { cdtohome = 1; } #ifdef COLOR_LS_F else if (eq(vp, STRcolor)) { set_color_context(); } #endif /* COLOR_LS_F */ #if defined(KANJI) && defined(SHORT_STRINGS) && defined(DSPMBYTE) - else if(eq(vp, CHECK_MBYTEVAR) || eq(vp, STRnokanji)) { + else if (eq(vp, CHECK_MBYTEVAR) || eq(vp, STRnokanji)) { update_dspmbyte_vars(); } #endif #ifdef NLS_CATALOGS else if (eq(vp, STRcatalog)) { nlsclose(); nlsinit(); } #if defined(FILEC) && defined(TIOCSTI) else if (eq(vp, STRfilec)) filec = 1; #endif #endif /* NLS_CATALOGS */ } /*ARGSUSED*/ void doset(Char **v, struct command *c) { Char *p; Char *vp; Char **vecp; int hadsub; int subscr; int flags = VAR_READWRITE; int first_match = 0; int last_match = 0; int changed = 0; USE(c); v++; do { changed = 0; /* * Readonly addition From: Tim P. Starrin */ if (*v && eq(*v, STRmr)) { flags = VAR_READONLY; v++; changed = 1; } if (*v && eq(*v, STRmf) && !last_match) { first_match = 1; v++; changed = 1; } if (*v && eq(*v, STRml) && !first_match) { last_match = 1; v++; changed = 1; } - } while(changed); + } while (changed); p = *v++; if (p == 0) { plist(&shvhed, flags); return; } do { hadsub = 0; vp = p; if (!letter(*p)) stderror(ERR_NAME | ERR_VARBEGIN); do { p++; } while (alnum(*p)); if (*p == '[') { hadsub++; p = getinx(p, &subscr); } if (*p != '\0' && *p != '=') stderror(ERR_NAME | ERR_VARALNUM); if (*p == '=') { *p++ = '\0'; if (*p == '\0' && *v != NULL && **v == '(') p = *v++; } else if (*v && eq(*v, STRequal)) { if (*++v != NULL) p = *v++; } if (eq(p, STRLparen)) { Char **e = v; if (hadsub) stderror(ERR_NAME | ERR_SYNTAX); for (;;) { if (!*e) stderror(ERR_NAME | ERR_MISSING, ')'); if (**e == ')') break; e++; } p = *e; *e = 0; vecp = saveblk(v); if (first_match) flags |= VAR_FIRST; else if (last_match) flags |= VAR_LAST; set1(vp, vecp, &shvhed, flags); *e = p; v = e + 1; } else if (hadsub) { Char *copy; copy = Strsave(p); cleanup_push(copy, xfree); asx(vp, subscr, copy); cleanup_ignore(copy); cleanup_until(copy); } else setv(vp, Strsave(p), flags); update_vars(vp); } while ((p = *v++) != NULL); } static Char * getinx(Char *cp, int *ip) { *ip = 0; *cp++ = 0; while (*cp && Isdigit(*cp)) *ip = *ip * 10 + *cp++ - '0'; if (*cp++ != ']') stderror(ERR_NAME | ERR_SUBSCRIPT); return (cp); } static void asx(Char *vp, int subscr, Char *p) { struct varent *v = getvx(vp, subscr); Char *prev; if (v->v_flags & VAR_READONLY) stderror(ERR_READONLY|ERR_NAME, v->v_name); prev = v->vec[subscr - 1]; cleanup_push(prev, xfree); v->vec[subscr - 1] = globone(p, G_APPEND); cleanup_until(prev); } static struct varent * getvx(Char *vp, int subscr) { struct varent *v = adrof(vp); if (v == 0) udvar(vp); if (subscr < 1 || subscr > blklen(v->vec)) stderror(ERR_NAME | ERR_RANGE); return (v); } /*ARGSUSED*/ void dolet(Char **v, struct command *dummy) { Char *p; Char *vp, c, op; int hadsub; int subscr; USE(dummy); v++; p = *v++; if (p == 0) { prvars(); return; } do { hadsub = 0; vp = p; if (letter(*p)) for (; alnum(*p); p++) continue; if (vp == p || !letter(*vp)) stderror(ERR_NAME | ERR_VARBEGIN); if (*p == '[') { hadsub++; p = getinx(p, &subscr); } if (*p == 0 && *v) p = *v++; if ((op = *p) != 0) *p++ = 0; else stderror(ERR_NAME | ERR_ASSIGN); /* * if there is no expression after the '=' then print a "Syntax Error" * message - strike */ if (*p == '\0' && *v == NULL) stderror(ERR_NAME | ERR_ASSIGN); vp = Strsave(vp); cleanup_push(vp, xfree); if (op == '=') { c = '='; p = xset(p, &v); } else { c = *p++; if (any("+-", c)) { if (c != op || *p) stderror(ERR_NAME | ERR_UNKNOWNOP); p = Strsave(STR1); } else { if (any("<>", op)) { if (c != op) stderror(ERR_NAME | ERR_UNKNOWNOP); stderror(ERR_NAME | ERR_SYNTAX); } if (c != '=') stderror(ERR_NAME | ERR_UNKNOWNOP); p = xset(p, &v); } } cleanup_push(p, xfree); if (op == '=') { if (hadsub) asx(vp, subscr, p); else setv(vp, p, VAR_READWRITE); cleanup_ignore(p); } else if (hadsub) { struct varent *gv = getvx(vp, subscr); Char *val; val = operate(op, gv->vec[subscr - 1], p); cleanup_push(val, xfree); asx(vp, subscr, val); cleanup_ignore(val); cleanup_until(val); } else { Char *val; val = operate(op, varval(vp), p); cleanup_push(val, xfree); setv(vp, val, VAR_READWRITE); cleanup_ignore(val); cleanup_until(val); } update_vars(vp); cleanup_until(vp); } while ((p = *v++) != NULL); } static Char * xset(Char *cp, Char ***vp) { Char *dp; if (*cp) { dp = Strsave(cp); --(*vp); xfree(** vp); **vp = dp; } return (putn(expr(vp))); } static Char * operate(int op, Char *vp, Char *p) { Char opr[2]; Char *vec[5]; Char **v = vec; Char **vecp = v; tcsh_number_t i; if (op != '=') { if (*vp) *v++ = vp; opr[0] = op; opr[1] = 0; *v++ = opr; if (op == '<' || op == '>') *v++ = opr; } *v++ = p; *v++ = 0; i = expr(&vecp); if (*vecp) stderror(ERR_NAME | ERR_EXPRESSION); return (putn(i)); } static Char *putp; Char * putn(tcsh_number_t n) { Char nbuf[1024]; /* Enough even for octal */ putp = nbuf; if (n < 0) { n = -n; *putp++ = '-'; } putn1(n); *putp = 0; return (Strsave(nbuf)); } static void putn1(tcsh_number_t n) { if (n > 9) putn1(n / 10); *putp++ = (Char)(n % 10 + '0'); } tcsh_number_t getn(const Char *cp) { tcsh_number_t n; int sign; int base; if (!cp) /* PWP: extra error checking */ stderror(ERR_NAME | ERR_BADNUM); sign = 0; if (cp[0] == '+' && cp[1]) cp++; if (*cp == '-') { sign++; cp++; if (!Isdigit(*cp)) stderror(ERR_NAME | ERR_BADNUM); } if (cp[0] == '0' && cp[1] && is_set(STRparseoctal)) base = 8; else base = 10; n = 0; while (Isdigit(*cp)) { if (base == 8 && *cp >= '8') stderror(ERR_NAME | ERR_BADNUM); n = n * base + *cp++ - '0'; } if (*cp) stderror(ERR_NAME | ERR_BADNUM); return (sign ? -n : n); } Char * value1(Char *var, struct varent *head) { struct varent *vp; if (!var || !head) /* PWP: extra error checking */ return (STRNULL); vp = adrof1(var, head); return ((vp == NULL || vp->vec == NULL || vp->vec[0] == NULL) ? STRNULL : vp->vec[0]); } static struct varent * madrof(Char *pat, struct varent *vp) { struct varent *vp1; for (vp = vp->v_left; vp; vp = vp->v_right) { if (vp->v_left && (vp1 = madrof(pat, vp)) != NULL) return vp1; if (Gmatch(vp->v_name, pat)) return vp; } return vp; } struct varent * adrof1(const Char *name, struct varent *v) { int cmp; v = v->v_left; while (v && ((cmp = *name - *v->v_name) != 0 || (cmp = Strcmp(name, v->v_name)) != 0)) if (cmp < 0) v = v->v_left; else v = v->v_right; return v; } void setcopy(const Char *var, const Char *val, int flags) { Char *copy; copy = Strsave(val); cleanup_push(copy, xfree); setv(var, copy, flags); cleanup_ignore(copy); cleanup_until(copy); } /* * The caller is responsible for putting value in a safe place */ void setv(const Char *var, Char *val, int flags) { Char **vec = xmalloc(2 * sizeof(Char **)); vec[0] = val; vec[1] = 0; set1(var, vec, &shvhed, flags); } void set1(const Char *var, Char **vec, struct varent *head, int flags) { Char **oldv = vec; if ((flags & VAR_NOGLOB) == 0) { int gflag; gflag = tglob(oldv); if (gflag) { vec = globall(oldv, gflag); - if (vec == 0) { + if (vec == NULL) { blkfree(oldv); stderror(ERR_NAME | ERR_NOMATCH); } blkfree(oldv); } } /* * Uniqueness addition from: Michael Veksler */ if ( flags & (VAR_FIRST | VAR_LAST) ) { /* * Code for -f (VAR_FIRST) and -l (VAR_LAST) options. * Method: * Delete all duplicate words leaving "holes" in the word array (vec). * Then remove the "holes", keeping the order of the words unchanged. */ - if (vec && vec[0] && vec[1]) { /* more than one word ? */ + if (vec[0] && vec[1]) { /* more than one word ? */ int i, j; int num_items; for (num_items = 0; vec[num_items]; num_items++) continue; if (flags & VAR_FIRST) { /* delete duplications, keeping first occurance */ for (i = 1; i < num_items; i++) for (j = 0; j < i; j++) /* If have earlier identical item, remove i'th item */ if (vec[i] && vec[j] && Strcmp(vec[j], vec[i]) == 0) { xfree(vec[i]); vec[i] = NULL; break; } } else if (flags & VAR_LAST) { /* delete duplications, keeping last occurance */ for (i = 0; i < num_items - 1; i++) for (j = i + 1; j < num_items; j++) /* If have later identical item, remove i'th item */ if (vec[i] && vec[j] && Strcmp(vec[j], vec[i]) == 0) { /* remove identical item (the first) */ xfree(vec[i]); vec[i] = NULL; } } /* Compress items - remove empty items */ for (j = i = 0; i < num_items; i++) if (vec[i]) vec[j++] = vec[i]; /* NULL-fy remaining items */ for (; j < num_items; j++) vec[j] = NULL; } /* don't let the attribute propagate */ flags &= ~(VAR_FIRST|VAR_LAST); } setq(var, vec, head, flags); } void setq(const Char *name, Char **vec, struct varent *p, int flags) { struct varent *c; int f; f = 0; /* tree hangs off the header's left link */ while ((c = p->v_link[f]) != 0) { if ((f = *name - *c->v_name) == 0 && (f = Strcmp(name, c->v_name)) == 0) { if (c->v_flags & VAR_READONLY) stderror(ERR_READONLY|ERR_NAME, c->v_name); blkfree(c->vec); c->v_flags = flags; trim(c->vec = vec); return; } p = c; f = f > 0; } p->v_link[f] = c = xmalloc(sizeof(struct varent)); c->v_name = Strsave(name); c->v_flags = flags; c->v_bal = 0; c->v_left = c->v_right = 0; c->v_parent = p; balance(p, f, 0); trim(c->vec = vec); } /*ARGSUSED*/ void unset(Char **v, struct command *c) { int did_roe, did_edit; USE(c); did_roe = adrof(STRrecognize_only_executables) != NULL; did_edit = adrof(STRedit) != NULL; unset1(v, &shvhed); #if defined(FILEC) && defined(TIOCSTI) if (adrof(STRfilec) == 0) filec = 0; #endif /* FILEC && TIOCSTI */ if (adrof(STRhistchars) == 0) { HIST = '!'; HISTSUB = '^'; } if (adrof(STRignoreeof) == 0) numeof = 0; if (adrof(STRpromptchars) == 0) { PRCH = tcsh ? '>' : '%'; PRCHROOT = '#'; } if (adrof(STRnoclobber) == 0) no_clobber = 0; if (adrof(STRhistlit) == 0) HistLit = 0; if (adrof(STRloginsh) == 0) loginsh = 0; if (adrof(STRanyerror) == 0) anyerror = 0; if (adrof(STRwordchars) == 0) word_chars = STR_WORD_CHARS; if (adrof(STRedit) == 0) editing = 0; if (adrof(STRbackslash_quote) == 0) bslash_quote = 0; if (adrof(STRcompat_expr) == 0) compat_expr = 0; if (adrof(STRsymlinks) == 0) symlinks = 0; if (adrof(STRimplicitcd) == 0) implicit_cd = 0; if (adrof(STRcdtohome) == 0) cdtohome = 0; if (adrof(STRkillring) == 0) SetKillRing(0); if (did_edit && noediting && adrof(STRedit) == 0) noediting = 0; if (adrof(STRvimode) == 0) VImode = 0; if (did_roe && adrof(STRrecognize_only_executables) == 0) tw_cmd_free(); if (adrof(STRhistory) == 0) sethistory(0); #ifdef COLOR_LS_F if (adrof(STRcolor) == 0) set_color_context(); #endif /* COLOR_LS_F */ #if defined(KANJI) && defined(SHORT_STRINGS) && defined(DSPMBYTE) update_dspmbyte_vars(); #endif update_wordchars(); #ifdef NLS_CATALOGS nlsclose(); nlsinit(); #endif /* NLS_CATALOGS */ } void unset1(Char *v[], struct varent *head) { struct varent *vp; int cnt; while (*++v) { cnt = 0; while ((vp = madrof(*v, head)) != NULL) if (vp->v_flags & VAR_READONLY) stderror(ERR_READONLY|ERR_NAME, vp->v_name); else unsetv1(vp), cnt++; if (cnt == 0) setname(short2str(*v)); } } void unsetv(Char *var) { struct varent *vp; if ((vp = adrof1(var, &shvhed)) == 0) udvar(var); unsetv1(vp); } static void unsetv1(struct varent *p) { struct varent *c, *pp; int f; /* * Free associated memory first to avoid complications. */ blkfree(p->vec); xfree(p->v_name); /* * If p is missing one child, then we can move the other into where p is. * Otherwise, we find the predecessor of p, which is guaranteed to have no * right child, copy it into p, and move it's left child into it. */ if (p->v_right == 0) c = p->v_left; else if (p->v_left == 0) c = p->v_right; else { for (c = p->v_left; c->v_right; c = c->v_right) continue; p->v_name = c->v_name; p->v_flags = c->v_flags; p->vec = c->vec; p = c; c = p->v_left; } /* * Move c into where p is. */ pp = p->v_parent; f = pp->v_right == p; if ((pp->v_link[f] = c) != 0) c->v_parent = pp; /* * Free the deleted node, and rebalance. */ xfree(p); balance(pp, f, 1); } /* Set variable name to NULL. */ void setNS(const Char *varName) { setcopy(varName, STRNULL, VAR_READWRITE); } /*ARGSUSED*/ void shift(Char **v, struct command *c) { struct varent *argv; Char *name; USE(c); v++; name = *v; if (name == 0) name = STRargv; else (void) strip(name); argv = adrof(name); if (argv == NULL || argv->vec == NULL) udvar(name); if (argv->vec[0] == 0) stderror(ERR_NAME | ERR_NOMORE); lshift(argv->vec, 1); update_vars(name); } static void exportpath(Char **val) { struct Strbuf buf = Strbuf_INIT; Char *exppath; if (val) while (*val) { Strbuf_append(&buf, *val++); if (*val == 0 || eq(*val, STRRparen)) break; Strbuf_append1(&buf, PATHSEP); } exppath = Strbuf_finish(&buf); cleanup_push(exppath, xfree); tsetenv(STRKPATH, exppath); cleanup_until(exppath); } static int set_noclobber(Char **val) { Char *option; int nc = NOCLOBBER_DEFAULT; if (val == NULL) return nc; while (*val) { if (*val == 0 || eq(*val, STRRparen)) return nc; option = *val++; if (eq(option, STRnotempty)) nc |= NOCLOBBER_NOTEMPTY; else if (eq(option, STRask)) nc |= NOCLOBBER_ASK; } return nc; } #ifndef lint /* * Lint thinks these have null effect */ /* macros to do single rotations on node p */ # define rright(p) (\ t = (p)->v_left,\ (t)->v_parent = (p)->v_parent,\ (((p)->v_left = t->v_right) != NULL) ?\ (t->v_right->v_parent = (p)) : 0,\ (t->v_right = (p))->v_parent = t,\ (p) = t) # define rleft(p) (\ t = (p)->v_right,\ ((t)->v_parent = (p)->v_parent,\ ((p)->v_right = t->v_left) != NULL) ? \ (t->v_left->v_parent = (p)) : 0,\ (t->v_left = (p))->v_parent = t,\ (p) = t) #else static struct varent * rleft(struct varent *p) { return (p); } static struct varent * rright(struct varent *p) { return (p); } #endif /* ! lint */ /* * Rebalance a tree, starting at p and up. * F == 0 means we've come from p's left child. * D == 1 means we've just done a delete, otherwise an insert. */ static void balance(struct varent *p, int f, int d) { struct varent *pp; #ifndef lint struct varent *t; /* used by the rotate macros */ #endif /* !lint */ int ff; #ifdef lint ff = 0; /* Sun's lint is dumb! */ #endif /* * Ok, from here on, p is the node we're operating on; pp is it's parent; f * is the branch of p from which we have come; ff is the branch of pp which * is p. */ for (; (pp = p->v_parent) != 0; p = pp, f = ff) { ff = pp->v_right == p; if (f ^ d) { /* right heavy */ switch (p->v_bal) { case -1: /* was left heavy */ p->v_bal = 0; break; case 0: /* was balanced */ p->v_bal = 1; break; case 1: /* was already right heavy */ switch (p->v_right->v_bal) { case 1: /* single rotate */ pp->v_link[ff] = rleft(p); p->v_left->v_bal = 0; p->v_bal = 0; break; case 0: /* single rotate */ pp->v_link[ff] = rleft(p); p->v_left->v_bal = 1; p->v_bal = -1; break; case -1: /* double rotate */ (void) rright(p->v_right); pp->v_link[ff] = rleft(p); p->v_left->v_bal = p->v_bal < 1 ? 0 : -1; p->v_right->v_bal = p->v_bal > -1 ? 0 : 1; p->v_bal = 0; break; default: break; } break; default: break; } } else { /* left heavy */ switch (p->v_bal) { case 1: /* was right heavy */ p->v_bal = 0; break; case 0: /* was balanced */ p->v_bal = -1; break; case -1: /* was already left heavy */ switch (p->v_left->v_bal) { case -1: /* single rotate */ pp->v_link[ff] = rright(p); p->v_right->v_bal = 0; p->v_bal = 0; break; case 0: /* single rotate */ pp->v_link[ff] = rright(p); p->v_right->v_bal = -1; p->v_bal = 1; break; case 1: /* double rotate */ (void) rleft(p->v_left); pp->v_link[ff] = rright(p); p->v_left->v_bal = p->v_bal < 1 ? 0 : -1; p->v_right->v_bal = p->v_bal > -1 ? 0 : 1; p->v_bal = 0; break; default: break; } break; default: break; } } /* * If from insert, then we terminate when p is balanced. If from * delete, then we terminate when p is unbalanced. */ if ((p->v_bal == 0) ^ d) break; } } void plist(struct varent *p, int what) { struct varent *c; int len; for (;;) { while (p->v_left) p = p->v_left; x: if (p->v_parent == 0) /* is it the header? */ break; if ((p->v_flags & what) != 0) { if (setintr) { int old_pintr_disabled; pintr_push_enable(&old_pintr_disabled); cleanup_until(&old_pintr_disabled); } len = blklen(p->vec); xprintf("%S\t", p->v_name); if (len != 1) xputchar('('); blkpr(p->vec); if (len != 1) xputchar(')'); xputchar('\n'); } if (p->v_right) { p = p->v_right; continue; } do { c = p; p = p->v_parent; } while (p->v_right == c); goto x; } } #if defined(KANJI) # if defined(SHORT_STRINGS) && defined(DSPMBYTE) extern int dspmbyte_ls; void update_dspmbyte_vars(void) { int lp, iskcode; Char *dstr1; struct varent *vp; /* if variable "nokanji" is set, multi-byte display is disabled */ if ((vp = adrof(CHECK_MBYTEVAR)) && !adrof(STRnokanji)) { _enable_mbdisp = 1; dstr1 = vp->vec[0]; - if(eq (dstr1, STRsjis)) + if (eq (dstr1, STRsjis)) iskcode = 1; else if (eq(dstr1, STReuc)) iskcode = 2; else if (eq(dstr1, STRbig5)) iskcode = 3; else if (eq(dstr1, STRutf8)) iskcode = 4; else if ((dstr1[0] - '0') >= 0 && (dstr1[0] - '0') <= 3) { iskcode = 0; } else { xprintf(CGETS(18, 2, "Warning: unknown multibyte display; using default(euc(JP))\n")); iskcode = 2; } if (dstr1 && vp->vec[1] && eq(vp->vec[1], STRls)) dspmbyte_ls = 1; else dspmbyte_ls = 0; for (lp = 0; lp < 256 && iskcode > 0; lp++) { switch (iskcode) { case 1: /* Shift-JIS */ _cmap[lp] = _cmap_mbyte[lp]; _mbmap[lp] = _mbmap_sjis[lp]; break; case 2: /* 2 ... euc */ _cmap[lp] = _cmap_mbyte[lp]; _mbmap[lp] = _mbmap_euc[lp]; break; case 3: /* 3 ... big5 */ _cmap[lp] = _cmap_mbyte[lp]; _mbmap[lp] = _mbmap_big5[lp]; break; case 4: /* 4 ... utf8 */ _cmap[lp] = _cmap_mbyte[lp]; _mbmap[lp] = _mbmap_utf8[lp]; break; default: xprintf(CGETS(18, 3, "Warning: unknown multibyte code %d; multibyte disabled\n"), iskcode); _cmap[lp] = _cmap_c[lp]; _mbmap[lp] = 0; /* Default map all 0 */ _enable_mbdisp = 0; break; } } if (iskcode == 0) { /* check original table */ if (Strlen(dstr1) != 256) { xprintf(CGETS(18, 4, "Warning: Invalid multibyte table length (%d); multibyte disabled\n"), Strlen(dstr1)); _enable_mbdisp = 0; } for (lp = 0; lp < 256 && _enable_mbdisp == 1; lp++) { if (!((dstr1[lp] - '0') >= 0 && (dstr1[lp] - '0') <= 3)) { xprintf(CGETS(18, 4, "Warning: bad multibyte code at offset +%d; multibyte diabled\n"), lp); _enable_mbdisp = 0; break; } } /* set original table */ for (lp = 0; lp < 256; lp++) { if (_enable_mbdisp == 1) { _cmap[lp] = _cmap_mbyte[lp]; _mbmap[lp] = (unsigned short) ((dstr1[lp] - '0') & 0x0f); } else { _cmap[lp] = _cmap_c[lp]; _mbmap[lp] = 0; /* Default map all 0 */ } } } } else { for (lp = 0; lp < 256; lp++) { _cmap[lp] = _cmap_c[lp]; _mbmap[lp] = 0; /* Default map all 0 */ } _enable_mbdisp = 0; dspmbyte_ls = 0; } #ifdef MBYTEDEBUG /* Sorry, use for beta testing */ { Char mbmapstr[300]; for (lp = 0; lp < 256; lp++) mbmapstr[lp] = _mbmap[lp] + '0'; mbmapstr[lp] = 0; setcopy(STRmbytemap, mbmapstr, VAR_READWRITE); } #endif /* MBYTEMAP */ } /* dspkanji/dspmbyte autosetting */ /* PATCH IDEA FROM Issei.Suzuki VERY THANKS */ void autoset_dspmbyte(const Char *pcp) { int i; static const struct dspm_autoset_Table { Char *n; Char *v; } dspmt[] = { { STRLANGEUCJP, STReuc }, { STRLANGEUCKR, STReuc }, { STRLANGEUCZH, STReuc }, { STRLANGEUCJPB, STReuc }, { STRLANGEUCKRB, STReuc }, { STRLANGEUCZHB, STReuc }, #ifdef __linux__ { STRLANGEUCJPC, STReuc }, #endif { STRLANGSJIS, STRsjis }, { STRLANGSJISB, STRsjis }, { STRLANGBIG5, STRbig5 }, { STRstarutfstar8, STRutf8 }, { NULL, NULL } }; #if defined(HAVE_NL_LANGINFO) && defined(CODESET) static const struct dspm_autoset_Table dspmc[] = { { STRstarutfstar8, STRutf8 }, { STReuc, STReuc }, { STRGB2312, STReuc }, { STRLANGBIG5, STRbig5 }, { NULL, NULL } }; Char *codeset; codeset = str2short(nl_langinfo(CODESET)); if (*codeset != '\0') { for (i = 0; dspmc[i].n; i++) { const Char *estr; if (dspmc[i].n[0] && t_pmatch(pcp, dspmc[i].n, &estr, 0) > 0) { setcopy(CHECK_MBYTEVAR, dspmc[i].v, VAR_READWRITE); update_dspmbyte_vars(); return; } } } #endif if (*pcp == '\0') return; for (i = 0; dspmt[i].n; i++) { const Char *estr; if (dspmt[i].n[0] && t_pmatch(pcp, dspmt[i].n, &estr, 0) > 0) { setcopy(CHECK_MBYTEVAR, dspmt[i].v, VAR_READWRITE); update_dspmbyte_vars(); break; } } } # elif defined(AUTOSET_KANJI) void autoset_kanji(void) { char *codeset = nl_langinfo(CODESET); if (*codeset == '\0') { if (adrof(STRnokanji) == NULL) setNS(STRnokanji); return; } if (strcasestr(codeset, "SHIFT_JIS") == (char*)0) { if (adrof(STRnokanji) == NULL) setNS(STRnokanji); return; } if (adrof(STRnokanji) != NULL) unsetv(STRnokanji); } #endif #endif void update_wordchars(void) { if ((word_chars == STR_WORD_CHARS) || (word_chars == STR_WORD_CHARS_VI)) { word_chars = (VImode ? STR_WORD_CHARS_VI : STR_WORD_CHARS); } } diff --git a/contrib/tcsh/tc.alloc.c b/contrib/tcsh/tc.alloc.c index 8914ba575d0c..cbe218f4c086 100644 --- a/contrib/tcsh/tc.alloc.c +++ b/contrib/tcsh/tc.alloc.c @@ -1,657 +1,667 @@ /* * tc.alloc.c (Caltech) 2/21/82 * Chris Kingsley, kingsley@cit-20. * * This is a very fast storage allocator. It allocates blocks of a small * number of different sizes, and keeps free lists of each size. Blocks that * don't exactly fit are passed up to the next larger size. In this * implementation, the available sizes are 2^n-4 (or 2^n-12) bytes long. * This is designed for use in a program that uses vast quantities of memory, * but bombs when it runs out. */ /*- * Copyright (c) 1980, 1991 The Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include "sh.h" #ifdef HAVE_MALLINFO #include #endif #if defined(HAVE_SBRK) && !defined(__APPLE__) #define USE_SBRK #endif #define RCHECK #define DEBUG static char *memtop = NULL; /* PWP: top of current memory */ static char *membot = NULL; /* PWP: bottom of allocatable memory */ int dont_free = 0; #ifdef WINNT_NATIVE # define malloc fmalloc # define free ffree # define calloc fcalloc # define realloc frealloc #endif /* WINNT_NATIVE */ #if !defined(DEBUG) || defined(SYSMALLOC) static void out_of_memory (void) { static const char msg[] = "Out of memory\n"; TCSH_IGNORE(write(didfds ? 2 : SHDIAG, msg, strlen(msg))); _exit(1); } #endif #ifndef SYSMALLOC #ifdef SX extern void* sbrk(); #endif /* * Lots of os routines are busted and try to free invalid pointers. * Although our free routine is smart enough and it will pick bad * pointers most of the time, in cases where we know we are going to get * a bad pointer, we'd rather leak. */ #ifndef NULL #define NULL 0 #endif typedef unsigned char U_char; /* we don't really have signed chars */ typedef unsigned int U_int; typedef unsigned short U_short; typedef unsigned long U_long; /* * The overhead on a block is at least 4 bytes. When free, this space * contains a pointer to the next free block, and the bottom two bits must * be zero. When in use, the first byte is set to MAGIC, and the second * byte is the size index. The remaining bytes are for alignment. * If range checking is enabled and the size of the block fits * in two bytes, then the top two bytes hold the size of the requested block * plus the range checking words, and the header word MINUS ONE. */ #define MEMALIGN(a) (((a) + ROUNDUP) & ~ROUNDUP) union overhead { union overhead *ov_next; /* when free */ struct { U_char ovu_magic; /* magic number */ U_char ovu_index; /* bucket # */ #ifdef RCHECK U_short ovu_size; /* actual block size */ U_int ovu_rmagic; /* range magic number */ #endif } ovu; #define ov_magic ovu.ovu_magic #define ov_index ovu.ovu_index #define ov_size ovu.ovu_size #define ov_rmagic ovu.ovu_rmagic }; #define MAGIC 0xfd /* magic # on accounting info */ #define RMAGIC 0x55555555 /* magic # on range info */ #ifdef RCHECK #define RSLOP sizeof (U_int) #else #define RSLOP 0 #endif #ifdef _LP64 #define ROUNDUP 15 #else #define ROUNDUP 7 #endif /* * nextf[i] is the pointer to the next free block of size 2^(i+3). The * smallest allocatable block is 8 bytes. The overhead information * precedes the data area returned to the user. */ #define NBUCKETS ((sizeof(long) << 3) - 3) static union overhead *nextf[NBUCKETS] IZERO_STRUCT; /* * nmalloc[i] is the difference between the number of mallocs and frees * for a given block size. */ static U_int nmalloc[NBUCKETS] IZERO_STRUCT; #ifndef lint static int findbucket (union overhead *, int); static void morecore (int); #endif #ifdef DEBUG # define CHECK(a, str, p) \ if (a) { \ xprintf(str, p); \ xprintf(" (memtop = %p membot = %p)\n", memtop, membot); \ abort(); \ } #else # define CHECK(a, str, p) \ if (a) { \ xprintf(str, p); \ xprintf(" (memtop = %p membot = %p)\n", memtop, membot); \ return; \ } #endif memalign_t malloc(size_t nbytes) { #ifndef lint union overhead *p; int bucket = 0; unsigned shiftr; /* * Convert amount of memory requested into closest block size stored in * hash buckets which satisfies request. Account for space used per block * for accounting. */ #ifdef SUNOS4 /* * SunOS localtime() overwrites the 9th byte on an 8 byte malloc().... * so we get one more... * From Michael Schroeder: This is not true. It depends on the * timezone string. In Europe it can overwrite the 13th byte on a * 12 byte malloc. * So we punt and we always allocate an extra byte. */ nbytes++; #endif nbytes = MEMALIGN(MEMALIGN(sizeof(union overhead)) + nbytes + RSLOP); shiftr = (nbytes - 1) >> 2; /* apart from this loop, this is O(1) */ while ((shiftr >>= 1) != 0) bucket++; /* * If nothing in hash bucket right now, request more memory from the * system. */ if (nextf[bucket] == NULL) morecore(bucket); if ((p = nextf[bucket]) == NULL) { child++; #ifndef DEBUG out_of_memory(); #else showall(NULL, NULL); xprintf(CGETS(19, 1, "nbytes=%zu: Out of memory\n"), nbytes); abort(); #endif /* fool lint */ return ((memalign_t) 0); } /* remove from linked list */ nextf[bucket] = nextf[bucket]->ov_next; p->ov_magic = MAGIC; p->ov_index = bucket; nmalloc[bucket]++; #ifdef RCHECK /* * Record allocated size of block and bound space with magic numbers. */ p->ov_size = (p->ov_index <= 13) ? (U_short)nbytes - 1 : 0; p->ov_rmagic = RMAGIC; *((U_int *) (((caddr_t) p) + nbytes - RSLOP)) = RMAGIC; #endif return ((memalign_t) (((caddr_t) p) + MEMALIGN(sizeof(union overhead)))); #else if (nbytes) return ((memalign_t) 0); else return ((memalign_t) 0); #endif /* !lint */ } #ifndef lint /* * Allocate more memory to the indicated bucket. */ static void morecore(int bucket) { union overhead *op; int rnu; /* 2^rnu bytes will be requested */ int nblks; /* become nblks blocks of the desired size */ int siz; if (nextf[bucket]) return; /* * Insure memory is allocated on a page boundary. Should make getpageize * call? */ op = (union overhead *) sbrk(0); memtop = (char *) op; if (membot == NULL) membot = memtop; if ((long) op & 0x3ff) { memtop = sbrk((int) (1024 - ((long) op & 0x3ff))); memtop += (long) (1024 - ((long) op & 0x3ff)); } /* take 2k unless the block is bigger than that */ rnu = (bucket <= 8) ? 11 : bucket + 3; nblks = 1 << (rnu - (bucket + 3)); /* how many blocks to get */ memtop = sbrk(1 << rnu); /* PWP */ op = (union overhead *) memtop; /* no more room! */ if ((long) op == -1) return; memtop += (long) (1 << rnu); /* * Round up to minimum allocation size boundary and deduct from block count * to reflect. */ if (((U_long) op) & ROUNDUP) { op = (union overhead *) (((U_long) op + (ROUNDUP + 1)) & ~ROUNDUP); nblks--; } /* * Add new memory allocated to that on free list for this hash bucket. */ nextf[bucket] = op; siz = 1 << (bucket + 3); while (--nblks > 0) { op->ov_next = (union overhead *) (((caddr_t) op) + siz); op = (union overhead *) (((caddr_t) op) + siz); } op->ov_next = NULL; } #endif void free(ptr_t cp) { #ifndef lint int size; union overhead *op; /* * the don't free flag is there so that we avoid os bugs in routines * that free invalid pointers! */ if (cp == NULL || dont_free) return; CHECK(!memtop || !membot, CGETS(19, 2, "free(%p) called before any allocations."), cp); CHECK(cp > (ptr_t) memtop, CGETS(19, 3, "free(%p) above top of memory."), cp); CHECK(cp < (ptr_t) membot, CGETS(19, 4, "free(%p) below bottom of memory."), cp); op = (union overhead *) (((caddr_t) cp) - MEMALIGN(sizeof(union overhead))); CHECK(op->ov_magic != MAGIC, CGETS(19, 5, "free(%p) bad block."), cp); #ifdef RCHECK if (op->ov_index <= 13) CHECK(*(U_int *) ((caddr_t) op + op->ov_size + 1 - RSLOP) != RMAGIC, CGETS(19, 6, "free(%p) bad range check."), cp); #endif CHECK(op->ov_index >= NBUCKETS, CGETS(19, 7, "free(%p) bad block index."), cp); size = op->ov_index; op->ov_next = nextf[size]; nextf[size] = op; nmalloc[size]--; #else if (cp == NULL) return; #endif } memalign_t calloc(size_t i, size_t j) { #ifndef lint char *cp; volatile size_t k; i *= j; cp = xmalloc(i); /* Stop gcc 5.x from optimizing malloc+memset = calloc */ k = i; memset(cp, 0, k); return ((memalign_t) cp); #else if (i && j) return ((memalign_t) 0); else return ((memalign_t) 0); #endif } /* * When a program attempts "storage compaction" as mentioned in the * old malloc man page, it realloc's an already freed block. Usually * this is the last block it freed; occasionally it might be farther * back. We have to search all the free lists for the block in order * to determine its bucket: 1st we make one pass thru the lists * checking only the first block in each; if that fails we search * ``realloc_srchlen'' blocks in each list for a match (the variable * is extern so the caller can modify it). If that fails we just copy * however many bytes was given to realloc() and hope it's not huge. */ #ifndef lint /* 4 should be plenty, -1 =>'s whole list */ static int realloc_srchlen = 4; #endif /* lint */ memalign_t realloc(ptr_t cp, size_t nbytes) { #ifndef lint U_int onb; union overhead *op; ptr_t res; int i; int was_alloced = 0; if (cp == NULL) return (malloc(nbytes)); op = (union overhead *) (((caddr_t) cp) - MEMALIGN(sizeof(union overhead))); if (op->ov_magic == MAGIC) { was_alloced++; i = op->ov_index; } else /* * Already free, doing "compaction". * * Search for the old block of memory on the free list. First, check the * most common case (last element free'd), then (this failing) the last * ``realloc_srchlen'' items free'd. If all lookups fail, then assume * the size of the memory block being realloc'd is the smallest * possible. */ if ((i = findbucket(op, 1)) < 0 && (i = findbucket(op, realloc_srchlen)) < 0) i = 0; onb = MEMALIGN(nbytes + MEMALIGN(sizeof(union overhead)) + RSLOP); /* avoid the copy if same size block */ if (was_alloced && (onb <= (U_int) (1 << (i + 3))) && (onb > (U_int) (1 << (i + 2)))) { #ifdef RCHECK /* JMR: formerly this wasn't updated ! */ nbytes = MEMALIGN(MEMALIGN(sizeof(union overhead))+nbytes+RSLOP); *((U_int *) (((caddr_t) op) + nbytes - RSLOP)) = RMAGIC; op->ov_rmagic = RMAGIC; op->ov_size = (op->ov_index <= 13) ? (U_short)nbytes - 1 : 0; #endif return ((memalign_t) cp); } if ((res = malloc(nbytes)) == NULL) return ((memalign_t) NULL); if (cp != res) { /* common optimization */ /* * christos: this used to copy nbytes! It should copy the * smaller of the old and new size */ onb = (1 << (i + 3)) - MEMALIGN(sizeof(union overhead)) - RSLOP; (void) memmove(res, cp, onb < nbytes ? onb : nbytes); } if (was_alloced) free(cp); return ((memalign_t) res); #else if (cp && nbytes) return ((memalign_t) 0); else return ((memalign_t) 0); #endif /* !lint */ } /* * On linux, _nss_nis_setnetgrent() calls this function to determine * the usable size of the pointer passed, but this is not a portable * API, so we cannot use our malloc replacement without providing one. * Thanks a lot glibc! */ #ifdef __linux__ #define M_U_S_CONST #else #define M_U_S_CONST #endif size_t malloc_usable_size(M_U_S_CONST void *); size_t malloc_usable_size(M_U_S_CONST void *ptr) { const union overhead *op = (const union overhead *) (((const char *) ptr) - MEMALIGN(sizeof(*op))); if (op->ov_magic == MAGIC) return 1 << (op->ov_index + 3); else return 0; } #ifndef lint /* * Search ``srchlen'' elements of each free list for a block whose * header starts at ``freep''. If srchlen is -1 search the whole list. * Return bucket number, or -1 if not found. */ static int findbucket(union overhead *freep, int srchlen) { union overhead *p; size_t i; int j; for (i = 0; i < NBUCKETS; i++) { j = 0; for (p = nextf[i]; p && j != srchlen; p = p->ov_next) { if (p == freep) return (i); j++; } } return (-1); } #endif #else /* SYSMALLOC */ /** ** ``Protected versions'' of malloc, realloc, calloc, and free ** ** On many systems: ** ** 1. malloc(0) is bad ** 2. free(0) is bad ** 3. realloc(0, n) is bad ** 4. realloc(n, 0) is bad ** ** Also we call our error routine if we run out of memory. **/ memalign_t smalloc(size_t n) { ptr_t ptr; n = n ? n : 1; #ifdef USE_SBRK if (membot == NULL) membot = sbrk(0); #endif /* USE_SBRK */ if ((ptr = malloc(n)) == NULL) out_of_memory(); #ifndef USE_SBRK if (memtop < ((char *) ptr) + n) memtop = ((char *) ptr) + n; if (membot == NULL) membot = ptr; #endif /* !USE_SBRK */ return ((memalign_t) ptr); } memalign_t srealloc(ptr_t p, size_t n) { ptr_t ptr; n = n ? n : 1; #ifdef USE_SBRK if (membot == NULL) membot = sbrk(0); #endif /* USE_SBRK */ if ((ptr = (p ? realloc(p, n) : malloc(n))) == NULL) out_of_memory(); #ifndef USE_SBRK if (memtop < ((char *) ptr) + n) memtop = ((char *) ptr) + n; if (membot == NULL) membot = ptr; #endif /* !USE_SBRK */ return ((memalign_t) ptr); } memalign_t scalloc(size_t s, size_t n) { ptr_t ptr; n *= s; n = n ? n : 1; #ifdef USE_SBRK if (membot == NULL) membot = sbrk(0); #endif /* USE_SBRK */ if ((ptr = malloc(n)) == NULL) out_of_memory(); memset (ptr, 0, n); #ifndef USE_SBRK if (memtop < ((char *) ptr) + n) memtop = ((char *) ptr) + n; if (membot == NULL) membot = ptr; #endif /* !USE_SBRK */ return ((memalign_t) ptr); } void sfree(ptr_t p) { if (p && !dont_free) free(p); } #endif /* SYSMALLOC */ /* * mstats - print out statistics about malloc * * Prints two lines of numbers, one showing the length of the free list * for each size category, the second showing the number of mallocs - * frees for each size category. */ /*ARGSUSED*/ void showall(Char **v, struct command *c) { #ifndef SYSMALLOC size_t i, j; union overhead *p; int totfree = 0, totused = 0; xprintf(CGETS(19, 8, "%s current memory allocation:\nfree:\t"), progname); for (i = 0; i < NBUCKETS; i++) { for (j = 0, p = nextf[i]; p; p = p->ov_next, j++) continue; xprintf(" %4zd", j); totfree += j * (1 << (i + 3)); } xprintf("\n%s:\t", CGETS(19, 9, "used")); for (i = 0; i < NBUCKETS; i++) { xprintf(" %4d", nmalloc[i]); totused += nmalloc[i] * (1 << (i + 3)); } xprintf(CGETS(19, 10, "\n\tTotal in use: %d, total free: %d\n"), totused, totfree); xprintf(CGETS(19, 11, "\tAllocated memory from 0x%lx to 0x%lx. Real top at 0x%lx\n"), (unsigned long) membot, (unsigned long) memtop, (unsigned long) sbrk(0)); #else /* SYSMALLOC */ #ifndef HAVE_MALLINFO #ifdef USE_SBRK memtop = sbrk(0); #endif /* USE_SBRK */ xprintf(CGETS(19, 12, "Allocated memory from 0x%lx to 0x%lx (%ld).\n"), (unsigned long) membot, (unsigned long) memtop, (unsigned long) (memtop - membot)); #else /* HAVE_MALLINFO */ struct mallinfo mi; mi = mallinfo(); xprintf(CGETS(19, 13, "%s current memory allocation:\n"), progname); xprintf(CGETS(19, 14, "Total space allocated from system: %d\n"), mi.arena); xprintf(CGETS(19, 15, "Number of non-inuse chunks: %d\n"), mi.ordblks); xprintf(CGETS(19, 16, "Number of mmapped regions: %d\n"), mi.hblks); xprintf(CGETS(19, 17, "Total space in mmapped regions: %d\n"), mi.hblkhd); xprintf(CGETS(19, 18, "Total allocated space: %d\n"), mi.uordblks); xprintf(CGETS(19, 19, "Total non-inuse space: %d\n"), mi.fordblks); xprintf(CGETS(19, 20, "Top-most, releasable space: %d\n"), mi.keepcost); #endif /* HAVE_MALLINFO */ #endif /* SYSMALLOC */ USE(c); USE(v); } + +#ifndef SYSMALLOC +/* jemalloc defines these */ +void _malloc_prefork(void); +void _malloc_postfork(void); +void _malloc_postfork_child(void); +void _malloc_prefork(void) {} +void _malloc_postfork(void) {} +void _malloc_postfork_child(void) {} +#endif diff --git a/contrib/tcsh/tc.disc.c b/contrib/tcsh/tc.disc.c index dd47da56acb0..d18277506965 100644 --- a/contrib/tcsh/tc.disc.c +++ b/contrib/tcsh/tc.disc.c @@ -1,192 +1,196 @@ /* * tc.disc.c: Functions to set/clear line disciplines * */ /*- * Copyright (c) 1980, 1991 The Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include "sh.h" #ifdef OREO #include #endif /* OREO */ #include "ed.h" static int add_discipline = 0; /* Did we add a line discipline */ #if defined(IRIS4D) || defined(OREO) || defined(sonyrisc) || defined(__ANDROID__) # define HAVE_DISC # ifndef POSIX static struct termio otermiob; # else static struct termios otermiob; # endif /* POSIX */ #endif /* IRIS4D || OREO */ #ifdef _IBMR2 # define HAVE_DISC char strPOSIX[] = "posix"; #endif /* _IBMR2 */ +#ifdef __IBMC__ +# define HAVE_DISC /* Z/OS TIOCGETD returns no such device */ +#endif /* __IBMC__ */ + #if !defined(HAVE_DISC) && defined(TIOCGETD) && defined(NTTYDISC) static int oldisc; #endif /* !HAVE_DISC && TIOCGETD && NTTYDISC */ int /*ARGSUSED*/ setdisc(int f) { #ifdef IRIS4D # ifndef POSIX struct termio termiob; # else struct termios termiob; # endif if (ioctl(f, TCGETA, (ioctl_t) & termiob) == 0) { otermiob = termiob; #if (SYSVREL < 4) || !defined(IRIS4D) if (termiob.c_line != NTTYDISC || termiob.c_cc[VSWTCH] == 0) { /*}*/ termiob.c_line = NTTYDISC; #else if (termiob.c_cc[VSWTCH] == 0) { #endif termiob.c_cc[VSWTCH] = CSWTCH; if (ioctl(f, TCSETA, (ioctl_t) & termiob) != 0) return (-1); } } else return (-1); add_discipline = 1; return (0); #endif /* IRIS4D */ #ifdef OREO # ifndef POSIX struct termio termiob; # else struct termios termiob; # endif struct ltchars ltcbuf; if (ioctl(f, TCGETA, (ioctl_t) & termiob) == 0) { int comp = getcompat(COMPAT_BSDTTY); otermiob = termiob; if ((comp & COMPAT_BSDTTY) != COMPAT_BSDTTY) { (void) setcompat(comp | COMPAT_BSDTTY); if (ioctl(f, TIOCGLTC, (ioctl_t) & ltcbuf) != 0) xprintf(CGETS(21, 1, "Couldn't get local chars.\n")); else { ltcbuf.t_suspc = CTL_ESC('\032'); /* ^Z */ ltcbuf.t_dsuspc = CTL_ESC('\031'); /* ^Y */ ltcbuf.t_rprntc = CTL_ESC('\022'); /* ^R */ ltcbuf.t_flushc = CTL_ESC('\017'); /* ^O */ ltcbuf.t_werasc = CTL_ESC('\027'); /* ^W */ ltcbuf.t_lnextc = CTL_ESC('\026'); /* ^V */ if (ioctl(f, TIOCSLTC, (ioctl_t) & ltcbuf) != 0) xprintf(CGETS(21, 2, "Couldn't set local chars.\n")); } termiob.c_cc[VSWTCH] = '\0'; if (ioctl(f, TCSETAF, (ioctl_t) & termiob) != 0) return (-1); } } else return (-1); add_discipline = 1; return (0); #endif /* OREO */ #ifdef _IBMR2 union txname tx; tx.tx_which = 0; if (ioctl(f, TXGETLD, (ioctl_t) & tx) == 0) { if (strcmp(tx.tx_name, strPOSIX) != 0) if (ioctl(f, TXADDCD, (ioctl_t) strPOSIX) == 0) { add_discipline = 1; return (0); } return (0); } else return (-1); #endif /* _IBMR2 */ #ifndef HAVE_DISC # if defined(TIOCGETD) && defined(NTTYDISC) if (ioctl(f, TIOCGETD, (ioctl_t) & oldisc) == 0) { if (oldisc != NTTYDISC) { int ldisc = NTTYDISC; if (ioctl(f, TIOCSETD, (ioctl_t) & ldisc) != 0) return (-1); add_discipline = 1; } else oldisc = -1; return (0); } else return (-1); # else USE(f); return (0); # endif /* TIOCGETD && NTTYDISC */ #endif /* !HAVE_DISC */ } /* end setdisc */ int /*ARGSUSED*/ resetdisc(int f) { if (add_discipline) { add_discipline = 0; #if defined(OREO) || defined(IRIS4D) return (ioctl(f, TCSETAF, (ioctl_t) & otermiob)); #endif /* OREO || IRIS4D */ #ifdef _IBMR2 return (ioctl(f, TXDELCD, (ioctl_t) strPOSIX)); #endif /* _IBMR2 */ #ifndef HAVE_DISC # if defined(TIOCSETD) && defined(NTTYDISC) return (ioctl(f, TIOCSETD, (ioctl_t) & oldisc)); # endif /* TIOCSETD && NTTYDISC */ #endif /* !HAVE_DISC */ } USE(f); return (0); } /* end resetdisc */ diff --git a/contrib/tcsh/tc.os.c b/contrib/tcsh/tc.os.c index 3a3bb22d9230..3ec512245603 100644 --- a/contrib/tcsh/tc.os.c +++ b/contrib/tcsh/tc.os.c @@ -1,1599 +1,1599 @@ /* * tc.os.c: OS Dependent builtin functions */ /*- * Copyright (c) 1980, 1991 The Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include "sh.h" #include "tw.h" #include "ed.h" #include "ed.defns.h" /* for the function names */ #include "sh.decls.h" #ifdef _UWIN #define TIOCGPGRP TIOCGETPGRP #define TIOCSPGRP TIOCSETPGRP #endif /*** *** MACH ***/ #ifdef MACH /* dosetpath -- setpath built-in command * ********************************************************************** * HISTORY * 08-May-88 Richard Draves (rpd) at Carnegie-Mellon University * Major changes to remove artificial limits on sizes and numbers * of paths. * ********************************************************************** */ #ifdef MACH static Char STRCPATH[] = {'C', 'P', 'A', 'T', 'H', '\0'}; static Char STRLPATH[] = {'L', 'P', 'A', 'T', 'H', '\0'}; static Char STRMPATH[] = {'M', 'P', 'A', 'T', 'H', '\0'}; # if EPATH static Char STREPATH[] = {'E', 'P', 'A', 'T', 'H', '\0'}; # endif #endif /* MACH */ static Char *syspaths[] = {STRKPATH, STRCPATH, STRLPATH, STRMPATH, #if EPATH STREPATH, #endif 0}; #define LOCALSYSPATH "/usr/local" /*ARGSUSED*/ void dosetpath(Char **arglist, struct command *c) { extern char *getenv(); Char **pathvars, **cmdargs; char **spaths, **cpaths, **cmds; char *tcp; unsigned int npaths, ncmds; int i, sysflag; pintr_disabled++; cleanup_push(&pintr_disabled, disabled_cleanup); /* * setpath(3) uses stdio and we want 0, 1, 2 to work... */ if (!didfds) { (void) dcopy(SHIN, 0); (void) dcopy(SHOUT, 1); (void) dcopy(SHDIAG, 2); didfds = 1; } for (i = 1; arglist[i] && (arglist[i][0] != '-'); i++); npaths = i - 1; cmdargs = &arglist[i]; for (; arglist[i]; i++); ncmds = i - npaths - 1; if (npaths) { sysflag = 0; pathvars = &arglist[1]; } else { sysflag = 1; npaths = (sizeof syspaths / sizeof *syspaths) - 1; pathvars = syspaths; } /* note that npaths != 0 */ spaths = xmalloc(npaths * sizeof *spaths); setzero(spaths, npaths * sizeof *spaths); cpaths = xmalloc((npaths + 1) * sizeof *cpaths); setzero(cpaths, (npaths + 1) * sizeof *cpaths); cmds = xmalloc((ncmds + 1) * sizeof *cmds); setzero(cmds, (ncmds + 1) * sizeof *cmds); for (i = 0; i < npaths; i++) { char *val = getenv(short2str(pathvars[i])); if (val == NULL) val = ""; spaths[i] = xmalloc((Strlen(pathvars[i]) + strlen(val) + 2) * sizeof **spaths); (void) strcpy(spaths[i], short2str(pathvars[i])); (void) strcat(spaths[i], "="); (void) strcat(spaths[i], val); cpaths[i] = spaths[i]; } for (i = 0; i < ncmds; i++) { Char *val = globone(cmdargs[i], G_ERROR);/*FIXRESET*/ if (val == NULL) goto abortpath; cmds[i] = strsave(short2str(val)); } if (setpath(cpaths, cmds, LOCALSYSPATH, sysflag, 1) < 0) { abortpath: if (spaths) { for (i = 0; i < npaths; i++) xfree(spaths[i]); xfree(spaths); } xfree(cpaths); if (cmds) { for (i = 0; i < ncmds; i++) xfree(cmds[i]); xfree(cmds); } cleanup_until(&pintr_disabled); donefds(); return; } for (i = 0; i < npaths; i++) { Char *val, *name; name = str2short(cpaths[i]); for (val = str2short(cpaths[i]); val && *val && *val != '='; val++); if (val && *val == '=') { *val++ = '\0'; tsetenv(name, val);/*FIXRESET*/ if (Strcmp(name, STRKPATH) == 0) { importpath(val);/*FIXRESET*/ if (havhash) dohash(NULL, NULL);/*FIXRESET*/ } *--val = '='; } } cleanup_until(&pintr_disabled); donefds(); } #endif /* MACH */ /*** *** AIX ***/ #ifdef TCF /* ARGSUSED */ void dogetxvers(Char **v, struct command *c) { char xvers[MAXPATHLEN]; if (getxvers(xvers, MAXPATHLEN) == -1) stderror(ERR_SYSTEM, "getxvers", strerror(errno)); xprintf("%s\n", xvers); flush(); } /*ARGSUSED*/ void dosetxvers(Char **v, struct command *c) { char *xvers; ++v; if (!*v || *v[0] == '\0') xvers = ""; else xvers = short2str(*v); if (setxvers(xvers) == -1) stderror(ERR_SYSTEM, "setxvers", strerror(errno)); } #include #ifdef _AIXPS2 # define XC_PDP11 0x01 # define XC_23 0x02 # define XC_Z8K 0x03 # define XC_8086 0x04 # define XC_68K 0x05 # define XC_Z80 0x06 # define XC_VAX 0x07 # define XC_16032 0x08 # define XC_286 0x09 # define XC_386 0x0a # define XC_S370 0x0b #else # include #endif /* _AIXPS2 */ static struct xc_cpu_t { short xc_id; char *xc_name; } xcpu[] = { { XC_PDP11, "pdp11" }, { XC_23, "i370" }, { XC_Z8K, "z8000" }, { XC_8086, "i86" }, { XC_68K, "mc68000" }, { XC_Z80, "x80" }, { XC_VAX, "vax" }, { XC_16032, "ns16032" }, { XC_286, "i286" }, { XC_386, "i386" }, { XC_S370, "xa370" }, { 0, NULL } }; /* * our local hack table, stolen from x.out.h */ static char * getxcode(short xcid) { int i; for (i = 0; xcpu[i].xc_name != NULL; i++) if (xcpu[i].xc_id == xcid) return (xcpu[i].xc_name); return (NULL); } static short getxid(char *xcname) { int i; for (i = 0; xcpu[i].xc_name != NULL; i++) if (strcmp(xcpu[i].xc_name, xcname) == 0) return (xcpu[i].xc_id); return ((short) -1); } /*ARGSUSED*/ void dogetspath(Char **v, struct command *c) { int i, j; sitepath_t p[MAXSITE]; struct sf *st; static char *local = "LOCAL "; if ((j = getspath(p, MAXSITE)) == -1) stderror(ERR_SYSTEM, "getspath", strerror(errno)); for (i = 0; i < j && (p[i] & SPATH_CPU) != NOSITE; i++) { if (p[i] & SPATH_CPU) { if ((p[i] & SPATH_MASK) == NULLSITE) xprintf(local); else if ((st = sfxcode((short) (p[i] & SPATH_MASK))) != NULL) xprintf("%s ", st->sf_ctype); else { char *xc = getxcode(p[i] & SPATH_MASK); if (xc != NULL) xprintf("%s ", xc); else xprintf("*cpu %d* ", (int) (p[i] & SPATH_MASK)); /* * BUG in the aix code... needs that cause if * sfxcode fails once it fails for ever */ endsf(); } } else { if (p[i] == NULLSITE) xprintf(local); else if ((st = sfnum(p[i])) != NULL) xprintf("%s ", st->sf_sname); else xprintf("*site %d* ", (int) (p[i] & SPATH_MASK)); } } xputchar('\n'); flush(); } /*ARGSUSED*/ void dosetspath(Char **v, struct command *c) { int i; short j; char *s; sitepath_t p[MAXSITE]; struct sf *st; /* * sfname() on AIX G9.9 at least, mallocs too pointers p, q * then does the equivalent of while (*p++ == *q++) continue; * and then tries to free(p,q) them! Congrats to the wizard who * wrote that one. I bet he tested it really well too. * Sooo, we set dont_free :-) */ dont_free = 1; for (i = 0, v++; *v && *v[0] != '\0'; v++, i++) { s = short2str(*v); if (isdigit(*s)) p[i] = atoi(s); else if (strcmp(s, "LOCAL") == 0) p[i] = NULLSITE; else if ((st = sfctype(s)) != NULL) p[i] = SPATH_CPU | st->sf_ccode; else if ((j = getxid(s)) != -1) p[i] = SPATH_CPU | j; else if ((st = sfname(s)) != NULL) p[i] = st->sf_id; else { setname(s); stderror(ERR_NAME | ERR_STRING, CGETS(23, 1, "Bad cpu/site name")); } if (i == MAXSITE - 1) stderror(ERR_NAME | ERR_STRING, CGETS(23, 2, "Site path too long")); } if (setspath(p, i) == -1) stderror(ERR_SYSTEM, "setspath", strerror(errno)); dont_free = 0; } /* sitename(): * Return the site name where the process is running */ char * sitename(pid_t pid) { siteno_t ss; struct sf *st; if ((ss = site(pid)) == -1 || (st = sfnum(ss)) == NULL) return CGETS(23, 3, "unknown"); else return st->sf_sname; } static int migratepid(pit_t pid, siteno_t new_site) { struct sf *st; int need_local; need_local = (pid == 0) || (pid == getpid()); if (kill3(pid, SIGMIGRATE, new_site) < 0) { xprintf("%d: %s\n", pid, strerror(errno)); return (-1); } if (need_local) { if ((new_site = site(0)) == -1) { xprintf(CGETS(23, 4, "site: %s\n"), strerror(errno)); return (-1); } if ((st = sfnum(new_site)) == NULL) { xprintf(CGETS(23, 5, "%d: Site not found\n"), new_site); return (-1); } if (setlocal(st->sf_local, strlen(st->sf_local)) == -1) { xprintf(CGETS(23, 6, "setlocal: %s: %s\n"), st->sf_local, strerror(errno)); return (-1); } } return (0); } /*ARGSUSED*/ void domigrate(Char **v, struct command *c) { struct sf *st; char *s; Char *cp; struct process *pp; int err1 = 0; int pid = 0; siteno_t new_site = 0; pchild_disabled++; cleanup_push(&pchild_disabled, disabled_cleanup); if (setintr) { pintr_disabled++; cleanup_push(&pintr_disabled, disabled_cleanup); } ++v; if (*v[0] == '-') { /* * Do the -site. */ s = short2str(&v[0][1]); /* * see comment in setspath() */ dont_free = 1; if ((st = sfname(s)) == NULL) { dont_free = 0; setname(s); stderror(ERR_NAME | ERR_STRING, CGETS(23, 7, "Site not found")); } dont_free = 0; new_site = st->sf_id; ++v; } if (!*v || *v[0] == '\0') { if (migratepid(0, new_site) == -1) err1++; } else { Char **globbed; v = glob_all_or_error(v); globbed = v; cleanup_push(globbed, blk_cleanup); while (v && (cp = *v)) { if (*cp == '%') { pp = pfind(cp); if (kill3(- pp->p_jobid, SIGMIGRATE, new_site) < 0) { xprintf("%S: %s\n", cp, strerror(errno)); err1++; } } else if (!(Isdigit(*cp) || *cp == '-')) stderror(ERR_NAME | ERR_JOBARGS); else { pid = atoi(short2str(cp)); if (migratepid(pid, new_site) == -1) err1++; } v++; } cleanup_until(globbed); } done: cleanup_until(&pchild_disabled); if (err1) stderror(ERR_SILENT); } #endif /* TCF */ /*** *** CRAY ddmode (Martin Ouwehand EPFL-SIC/SE) ***/ #if defined(_CRAY) && !defined(_CRAYMPP) void dodmmode(Char **v, struct command *c) { Char *cp = v[1]; USE(c); if ( !cp ) { int mode; mode = dmmode(0); dmmode(mode); xprintf("%d\n",mode); } else { if (cp[1] != '\0') stderror(ERR_NAME | ERR_STRING, CGETS(23, 30, "Too many arguments")); else switch(*cp) { case '0': dmmode(0); break; case '1': dmmode(1); break; default: stderror(ERR_NAME | ERR_STRING, CGETS(23, 31, "Invalid argument")); } } } #endif /* _CRAY && !_CRAYMPP */ /*** *** CONVEX Warps. ***/ #ifdef WARP /* * handle the funky warping of symlinks */ #include #include static jmp_buf sigsys_buf; static void catch_sigsys(void) { sigset_t set; sigemptyset(&set, SIGSYS); (void)sigprocmask(SIG_UNBLOCK, &set, NULL); longjmp(sigsys_buf, 1); } /*ARGSUSED*/ void dowarp(Char **v, struct command *c) { int warp, oldwarp; struct warpent *we; volatile struct sigaction old_sigsys_handler; char *newwarp; if (setjmp(sigsys_buf)) { sigaction(SIGSYS, &old_sigsys_handler, NULL); stderror(ERR_NAME | ERR_STRING, CGETS(23, 8, "You're trapped in a universe you never made")); return; } sigaction(SIGSYS, NULL, &old_sigsys_handler); signal(SIGSYS, catch_sigsys); warp = getwarp(); v++; if (*v == 0) { /* display warp value */ if (warp < 0) stderror(ERR_NAME | ERR_STRING, CGETS(23, 9, "Getwarp failed")); we = getwarpbyvalue(warp); if (we) printf("%s\n", we->w_name); else printf("%d\n", warp); } else { /* set warp value */ oldwarp = warp; newwarp = short2str(*v); if (Isdigit(*v[0])) warp = atoi(newwarp); else { we = getwarpbyname(newwarp); if (we) warp = we->w_value; else warp = -1; } if ((warp < 0) || (warp >= WARP_MAXLINK)) stderror(ERR_NAME | ERR_STRING, CGETS(23, 10, "Invalid warp")); if ((setwarp(warp) < 0) || (getwarp() != warp)) { (void) setwarp(oldwarp); stderror(ERR_NAME | ERR_STRING, CGETS(23, 11, "Setwarp failed")); } } sigaction(SIGSYS, &old_sigsys_handler, NULL); } #endif /* WARP */ /*** *** Masscomp or HCX ***/ /* Added, DAS DEC-90. */ #if defined(masscomp) || defined(_CX_UX) static void setuniverse_cleanup(void *xbuf) { char *buf; buf = xbuf; setuniverse(buf); } /*ARGSUSED*/ void douniverse(Char **v, struct command *c) { Char *cp = v[1]; Char *cp2; /* dunno how many elements v comes in with */ char ubuf[100]; if (cp == 0) { (void) getuniverse(ubuf); xprintf("%s\n", ubuf); } else { cp2 = v[2]; if (cp2 == 0) { if (*cp == '\0' || setuniverse(short2str(cp)) != 0) stderror(ERR_NAME | ERR_STRING, CGETS(23, 12, "Illegal universe")); } else { (void) getuniverse(ubuf); if (*cp == '\0' || setuniverse(short2str(cp)) != 0) stderror(ERR_NAME | ERR_STRING, CGETS(23, 12, "Illegal universe")); cleanup_push(ubuf, setuniverse_cleanup); if (setintr) { pintr_disabled++; cleanup_push(&pintr_disabled, disabled_cleanup); } lshift(v, 2); if (setintr) cleanup_until(&pintr_disabled); reexecute(c); cleanup_until(ubuf); } } } #endif /* masscomp || _CX_UX */ /*** *** BS2000/OSD POSIX (Fujitsu Siemens Computers) ***/ #if defined(_OSD_POSIX) static int bs2upcase(char *str) { enum { outside = ' ', singlequote='\'', doublequote='"'} string = outside; char *white; for (white = str + strlen(str) - 1; isspace(*white) && white > str; --white) *white = '\0'; for (; *str != '\0'; ++str) { if (string == outside) { *str = toupper (*str); } if (*str == '\'') { if (string == outside) string = singlequote; else if (string != doublequote) string = outside; } else if (*str == '"') { if (string == outside) string = doublequote; else if (string != singlequote) string = outside; } } if (string != outside) { stderror(ERR_NAME | ERR_UNMATCHED, (Char) string); return 1; } return 0; } static int bs2cmdlist(char *str) { char *str_beg = NULL; int ret = 0; enum { outside = ' ', singlequote='\'', doublequote='"'} string = outside; while (*str != '\0') { while (isspace(*str)) ++str; if (*str == '\0') break; str_beg = str; for (; *str != '\0'; ++str) { if (string == outside && *str == ';') /* End of command */ { *str++ = '\0'; break; /* continue with next command */ } if (*str == '\'') { if (string == outside) string = singlequote; else if (string != doublequote) string = outside; } else if (*str == '"') { if (string == outside) string = doublequote; else if (string != singlequote) string = outside; } } if (strlen(str_beg) != 0) { ret = bs2system(str_beg); flush(); if (ret != 0 /*&& !option.err_ignore*/) break; /* do not continue after errors */ } } if (string != outside) { stderror(ERR_NAME | ERR_UNMATCHED, (Char) string); return -1; } return ret; } /*ARGSUSED*/ void dobs2cmd(Char **v, struct command *c) { Char *cp, **globbed; int i = 0, len = 0; char *cmd = NULL; int pvec[2]; struct command faket; Char *fakecom[2]; char tibuf[BUFSIZE]; int icnt, old_pintr_disabled; static const Char STRbs2cmd[] = { 'b','s','2','c','m','d','\0' }; v++; if (setintr) pintr_push_enable(&old_pintr_disabled); v = glob_all_or_error(v); if (setintr) cleanup_until(&old_pintr_disabled); globbed = v; cleanup_push(globbed, blk_cleanup); /* First round: count the string lengths */ for (i=0; v[i]; ++i) { len += Strlen(v[i]) + (v[i+1] != NULL); } cmd = xmalloc(len+1); /* 1 for the final '\0' *//* FIXME: memory leak? */ /* 2nd round: fill cmd buffer */ i = 0; while ((cp = *v++) != 0) { int c; while (c = *cp++) cmd[i++] = (char)c; if (*v) cmd[i++] = ' '; } cmd[i] = '\0'; /* Make upper case */ bs2upcase(cmd); faket.t_dtyp = NODE_COMMAND; faket.t_dflg = F_BACKQ|F_STDERR; faket.t_dlef = 0; faket.t_drit = 0; faket.t_dspr = 0; faket.t_dcom = fakecom; fakecom[0] = (Char *)STRbs2cmd; fakecom[1] = 0; mypipe(pvec); cleanup_push(&pvec[0], open_cleanup); cleanup_push(&pvec[1], open_cleanup); if (pfork(&faket, -1) == 0) { sigset_t set; /* child */ xclose(pvec[0]); (void) dmove(pvec[1], 1); (void) dmove(SHDIAG, 2); initdesc(); sigemptyset(&set); sigaddset(&set, SIGINT); (void)sigprocmask(SIG_UNBLOCK, &set, NULL); #ifdef SIGTSTP signal(SIGTSTP, SIG_IGN); #endif #ifdef SIGTTIN signal(SIGTTIN, SIG_IGN); #endif #ifdef SIGTTOU signal(SIGTTOU, SIG_IGN); #endif xexit(bs2cmdlist(cmd)); } cleanup_until(&pvec[1]); - for(;;) { + for (;;) { int old_pintr_disabled; if (setintr) pintr_push_enable(&old_pintr_disabled); icnt = xread(pvec[0], tibuf, sizeof(tibuf)); if (setintr) cleanup_until(&old_pintr_disabled); if (icnt <= 0) break; for (i = 0; i < icnt; i++) xputchar((unsigned char) tibuf[i]); } cleanup_until(&pvec[0]); pwait(); flush(); cleanup_until(globbed); } #endif /* _OSD_POSIX */ #if defined(_CX_UX) static void setuniverse_cleanup(void *xbuf) { char *buf; buf = xbuf; setuniverse(buf); } /*ARGSUSED*/ void doatt(Char **v, struct command *c) { Char *cp = v[1]; char ubuf[100]; if (cp == 0) (void) setuniverse("att"); else { (void) getuniverse(ubuf); (void) setuniverse("att"); cleanup_push(ubuf, setuniverse_cleanup); if (setintr) { pintr_disabled++; cleanup_push(&pintr_disabled, disabled_cleanup); } lshift(v, 1); if (setintr) cleanup_until(&pintr_disabled); reexecute(c); cleanup_until(ubuf); } } /*ARGSUSED*/ void doucb(Char **v, struct command *c) { Char *cp = v[1]; char ubuf[100]; if (cp == 0) (void) setuniverse("ucb"); else { (void) getuniverse(ubuf); (void) setuniverse("ucb"); cleanup_push(ubuf, setuniverse_cleanup); if (setintr) { pintr_disabled++; cleanup_push(&pintr_disabled, disabled_cleanup); } lshift(v, 1); if (setintr) cleanup_until(&pintr_disabled); reexecute(c); cleanup_until(ubuf); } } #endif /* _CX_UX */ #ifdef _SEQUENT_ /* * Compute the difference in process stats. */ void pr_stat_sub(struct process_stats *p2, struct process_stats *p1, struct process_stats *pr) { pr->ps_utime.tv_sec = p2->ps_utime.tv_sec - p1->ps_utime.tv_sec; pr->ps_utime.tv_usec = p2->ps_utime.tv_usec - p1->ps_utime.tv_usec; if (pr->ps_utime.tv_usec < 0) { pr->ps_utime.tv_sec -= 1; pr->ps_utime.tv_usec += 1000000; } pr->ps_stime.tv_sec = p2->ps_stime.tv_sec - p1->ps_stime.tv_sec; pr->ps_stime.tv_usec = p2->ps_stime.tv_usec - p1->ps_stime.tv_usec; if (pr->ps_stime.tv_usec < 0) { pr->ps_stime.tv_sec -= 1; pr->ps_stime.tv_usec += 1000000; } pr->ps_maxrss = p2->ps_maxrss - p1->ps_maxrss; pr->ps_pagein = p2->ps_pagein - p1->ps_pagein; pr->ps_reclaim = p2->ps_reclaim - p1->ps_reclaim; pr->ps_zerofill = p2->ps_zerofill - p1->ps_zerofill; pr->ps_pffincr = p2->ps_pffincr - p1->ps_pffincr; pr->ps_pffdecr = p2->ps_pffdecr - p1->ps_pffdecr; pr->ps_swap = p2->ps_swap - p1->ps_swap; pr->ps_syscall = p2->ps_syscall - p1->ps_syscall; pr->ps_volcsw = p2->ps_volcsw - p1->ps_volcsw; pr->ps_involcsw = p2->ps_involcsw - p1->ps_involcsw; pr->ps_signal = p2->ps_signal - p1->ps_signal; pr->ps_lread = p2->ps_lread - p1->ps_lread; pr->ps_lwrite = p2->ps_lwrite - p1->ps_lwrite; pr->ps_bread = p2->ps_bread - p1->ps_bread; pr->ps_bwrite = p2->ps_bwrite - p1->ps_bwrite; pr->ps_phread = p2->ps_phread - p1->ps_phread; pr->ps_phwrite = p2->ps_phwrite - p1->ps_phwrite; } #endif /* _SEQUENT_ */ #ifndef HAVE_MEMSET /* This is a replacement for a missing memset function */ void *xmemset(void *loc, int value, size_t len) { char *ptr = loc; while (len--) *ptr++ = value; return loc; } #endif /* !HAVE_MEMSET */ #ifndef HAVE_MEMMOVE /* memmove(): * This is the ANSI form of bcopy() with the arguments backwards... * Unlike memcpy(), it handles overlaps between source and * destination memory */ void * xmemmove(void *vdst, const void *vsrc, size_t len) { const char *src = vsrc; char *dst = vdst; if (src == dst) return vdst; if (src > dst) { while (len--) *dst++ = *src++; } else { src += len; dst += len; while (len--) *--dst = *--src; } return vdst; } #endif /* HAVE_MEMMOVE */ #ifndef WINNT_NATIVE #ifdef NEEDtcgetpgrp pid_t xtcgetpgrp(int fd) { int pgrp; /* ioctl will handle setting errno correctly. */ if (ioctl(fd, TIOCGPGRP, (ioctl_t) & pgrp) < 0) return (-1); return (pgrp); } /* * XXX: tcsetpgrp is not a macro any more cause on some systems, * pid_t is a short, but the ioctl() takes a pointer to int (pyr) * Thanks to Simon Day (simon@pharaoh.cyborg.bt.co.uk) for pointing * this out. */ int xtcsetpgrp(int fd, int pgrp) { return ioctl(fd, TIOCSPGRP, (ioctl_t) &pgrp); } #endif /* NEEDtcgetpgrp */ #endif /* WINNT_NATIVE */ #ifdef YPBUGS void fix_yp_bugs(void) { char *mydomain; extern int yp_get_default_domain (char **); /* * PWP: The previous version assumed that yp domain was the same as the * internet name domain. This isn't allways true. (Thanks to Mat Landau * for the original version of this.) */ if (yp_get_default_domain(&mydomain) == 0) { /* if we got a name */ extern void yp_unbind (const char *); yp_unbind(mydomain); } } #endif /* YPBUGS */ #ifdef STRCOLLBUG void fix_strcoll_bug(void) { #if defined(NLS) && defined(HAVE_STRCOLL) /* * SunOS4 checks the file descriptor from openlocale() for <= 0 * instead of == -1. Someone should tell sun that file descriptor 0 * is valid! Our portable hack: open one so we call it with 0 used... * We have to call this routine every time the locale changes... * * Of course it also tries to free the constant locale "C" it initially * had allocated, with the sequence * > setenv LANG "fr" * > ls^D * > unsetenv LANG * But we are smarter than that and just print a warning message. */ int fd = -1; static char *root = "/"; if (!didfds) fd = xopen(root, O_RDONLY|O_LARGEFILE); (void) strcoll(root, root); if (fd != -1) xclose(fd); #endif } #endif /* STRCOLLBUG */ #ifdef OREO #include #endif /* OREO */ void osinit(void) { #ifdef OREO set42sig(); setcompat(getcompat() & ~COMPAT_EXEC); signal(SIGIO, SIG_IGN); /* ignore SIGIO */ #endif /* OREO */ #ifdef aiws { struct sigstack inst; inst.ss_sp = xmalloc(4192) + 4192; inst.ss_onstack = 0; sigstack(&inst, NULL); } #endif /* aiws */ #ifdef apollo (void) isapad(); #endif #ifdef _SX /* * kill(SIGCONT) problems, don't know what this syscall does * [schott@rzg.mpg.de] */ syscall(151, getpid(), getpid()); #endif /* _SX */ } #ifndef HAVE_STRERROR extern int sys_nerr; extern char *sys_errlist[]; char * xstrerror(int i) { if (i >= 0 && i < sys_nerr) { return sys_errlist[i]; } else { static char *errbuf; /* = NULL; */ xfree(errbuf); errbuf = xasprintf(CGETS(23, 13, "Unknown Error: %d"), i); return errbuf; } } #endif /* !HAVE_STRERROR */ #ifndef HAVE_GETHOSTNAME # if !defined(_MINIX) && !defined(__EMX__) && !defined(WINNT_NATIVE) # include # endif /* !_MINIX && !__EMX__ && !WINNT_NATIVE */ int xgethostname(char *name, int namlen) { # if !defined(_MINIX) && !defined(__EMX__) && !defined(WINNT_NATIVE) int i, retval; struct utsname uts; retval = uname(&uts); # ifdef DEBUG xprintf(CGETS(23, 14, "sysname: %s\n"), uts.sysname); xprintf(CGETS(23, 15, "nodename: %s\n"), uts.nodename); xprintf(CGETS(23, 16, "release: %s\n"), uts.release); xprintf(CGETS(23, 17, "version: %s\n"), uts.version); xprintf(CGETS(23, 18, "machine: %s\n"), uts.machine); # endif /* DEBUG */ i = strlen(uts.nodename) + 1; (void) strncpy(name, uts.nodename, i < namlen ? i : namlen); return retval; # else /* !_MINIX && !__EMX__ */ if (namlen > 0) { # ifdef __EMX__ (void) strncpy(name, "OS/2", namlen); # else /* _MINIX */ (void) strncpy(name, "minix", namlen); # endif /* __EMX__ */ name[namlen-1] = '\0'; } return(0); #endif /* _MINIX && !__EMX__ */ } /* end xgethostname */ #endif /* !HAVE_GETHOSTNAME */ #ifndef HAVE_NICE # if defined(_MINIX) && defined(NICE) # undef _POSIX_SOURCE /* redefined in */ # undef _MINIX /* redefined in */ # undef HZ /* redefined in */ # include # endif /* _MINIX && NICE */ int xnice(int incr) { #if defined(_MINIX) && defined(NICE) return callm1(MM, NICE, incr, 0, 0, NIL_PTR, NIL_PTR, NIL_PTR); #else return /* incr ? 0 : */ 0; #endif /* _MINIX && NICE */ } /* end xnice */ #endif /* !HAVE_NICE */ #ifndef HAVE_GETCWD static char *strnrcpy (char *, char *, size_t); /* xgetcwd(): * Return the pathname of the current directory, or return * an error message in pathname. */ # ifdef hp9000s500 /* * From: Bernd Mohr * I also ported the tcsh to the HP9000 Series 500. This computer * is a little bit different than the other HP 9000 computer. It has * a HP Chip instead of a Motorola CPU and it is no "real" UNIX. It runs * HP-UX which is emulated in top of a HP operating system. So, the last * supported version of HP-UX is 5.2 on the HP9000s500. This has two * consequences: it supports no job control and it has a filesystem * without "." and ".." !!! */ char * xgetcwd(char *pathname, size_t pathlen) { char pathbuf[MAXPATHLEN]; /* temporary pathname buffer */ char *pnptr = &pathbuf[(sizeof pathbuf)-1]; /* pathname pointer */ dev_t rdev; /* root device number */ DIR *dirp = NULL; /* directory stream */ ino_t rino; /* root inode number */ off_t rsize; /* root size */ struct direct *dir; /* directory entry struct */ struct stat d, dd; /* file status struct */ int serrno; *pnptr = '\0'; (void) stat("/.", &d); rdev = d.st_dev; rino = d.st_ino; rsize = d.st_size; for (;;) { if (stat(".", &d) == -1) { (void) xsnprintf(pathname, pathlen, CGETS(23, 24, "getcwd: Cannot stat \".\" (%s)"), strerror(errno)); goto fail; } if (d.st_ino == rino && d.st_dev == rdev && d.st_size == rsize) break; /* reached root directory */ if ((dirp = opendir("..")) == NULL) { (void) xsnprintf(pathname, pathlen, CGETS(23, 19, "getcwd: Cannot open \"..\" (%s)"), strerror(errno)); goto fail; } if (chdir("..") == -1) { (void) xsnprintf(pathname, pathlen, CGETS(23, 20, "getcwd: Cannot chdir to \"..\" (%s)"), strerror(errno)); goto fail; } do { if ((dir = readdir(dirp)) == NULL) { (void) xsnprintf(pathname, pathlen, CGETS(23, 21, "getcwd: Read error in \"..\" (%s)"), strerror(errno)); goto fail; } if (stat(dir->d_name, &dd) == -1) { (void) xsnprintf(pathname, pathlen, CGETS(23, 25, "getcwd: Cannot stat directory \"%s\" (%s)"), dir->d_name, strerror(errno)); goto fail; } } while (dd.st_ino != d.st_ino || dd.st_dev != d.st_dev || dd.st_size != d.st_size); closedir(dirp); dirp = NULL; pnptr = strnrcpy(dirp->d_name, pnptr, pnptr - pathbuf); pnptr = strnrcpy("/", pnptr, pnptr - pathbuf); } if (*pnptr == '\0') /* current dir == root dir */ (void) strncpy(pathname, "/", pathlen); else { (void) strncpy(pathname, pnptr, pathlen); pathname[pathlen - 1] = '\0'; if (chdir(pnptr) == -1) { (void) xsnprintf(pathname, MAXPATHLEN, CGETS(23, 22, "getcwd: Cannot change back to \".\" (%s)"), strerror(errno)); return NULL; } } return pathname; fail: serrno = errno; (void) chdir(strnrcpy(".", pnptr, pnptr - pathbuf)); errno = serrno; return NULL; } # else /* ! hp9000s500 */ char * xgetcwd(char *pathname, size_t pathlen) { DIR *dp; struct dirent *d; struct stat st_root, st_cur, st_next, st_dotdot; char pathbuf[MAXPATHLEN], nextpathbuf[MAXPATHLEN * 2]; char *pathptr, *nextpathptr, *cur_name_add; int save_errno = 0; /* find the inode of root */ if (stat("/", &st_root) == -1) { (void) xsnprintf(pathname, pathlen, CGETS(23, 23, "getcwd: Cannot stat \"/\" (%s)"), strerror(errno)); return NULL; } pathbuf[MAXPATHLEN - 1] = '\0'; pathptr = &pathbuf[MAXPATHLEN - 1]; nextpathbuf[MAXPATHLEN - 1] = '\0'; cur_name_add = nextpathptr = &nextpathbuf[MAXPATHLEN - 1]; /* find the inode of the current directory */ if (lstat(".", &st_cur) == -1) { (void) xsnprintf(pathname, pathlen, CGETS(23, 24, "getcwd: Cannot stat \".\" (%s)"), strerror(errno)); return NULL; } nextpathptr = strnrcpy(nextpathptr, "../", nextpathptr - nextpathbuf); /* Descend to root */ for (;;) { /* look if we found root yet */ if (st_cur.st_ino == st_root.st_ino && DEV_DEV_COMPARE(st_cur.st_dev, st_root.st_dev)) { (void) strncpy(pathname, *pathptr != '/' ? "/" : pathptr, pathlen); pathname[pathlen - 1] = '\0'; return pathname; } /* open the parent directory */ if (stat(nextpathptr, &st_dotdot) == -1) { (void) xsnprintf(pathname, pathlen, CGETS(23, 25, "getcwd: Cannot stat directory \"%s\" (%s)"), nextpathptr, strerror(errno)); return NULL; } if ((dp = opendir(nextpathptr)) == NULL) { (void) xsnprintf(pathname, pathlen, CGETS(23, 26, "getcwd: Cannot open directory \"%s\" (%s)"), nextpathptr, strerror(errno)); return NULL; } /* look in the parent for the entry with the same inode */ if (DEV_DEV_COMPARE(st_dotdot.st_dev, st_cur.st_dev)) { /* Parent has same device. No need to stat every member */ for (d = readdir(dp); d != NULL; d = readdir(dp)) { #ifdef __clipper__ if (((unsigned long)d->d_ino & 0xffff) == st_cur.st_ino) break; #else if (d->d_ino == st_cur.st_ino) break; #endif } } else { /* * Parent has a different device. This is a mount point so we * need to stat every member */ for (d = readdir(dp); d != NULL; d = readdir(dp)) { if (ISDOT(d->d_name) || ISDOTDOT(d->d_name)) continue; (void)strncpy(cur_name_add, d->d_name, (size_t) (&nextpathbuf[sizeof(nextpathbuf) - 1] - cur_name_add)); if (lstat(nextpathptr, &st_next) == -1) { /* * We might not be able to stat() some path components * if we are using afs, but this is not an error as * long as we find the one we need; we also save the * first error to report it if we don't finally succeed. */ if (save_errno == 0) save_errno = errno; continue; } /* check if we found it yet */ if (st_next.st_ino == st_cur.st_ino && DEV_DEV_COMPARE(st_next.st_dev, st_cur.st_dev)) break; } } if (d == NULL) { (void) xsnprintf(pathname, pathlen, CGETS(23, 27, "getcwd: Cannot find \".\" in \"..\" (%s)"), strerror(save_errno ? save_errno : ENOENT)); closedir(dp); return NULL; } else save_errno = 0; st_cur = st_dotdot; pathptr = strnrcpy(pathptr, d->d_name, pathptr - pathbuf); pathptr = strnrcpy(pathptr, "/", pathptr - pathbuf); nextpathptr = strnrcpy(nextpathptr, "../", nextpathptr - nextpathbuf); *cur_name_add = '\0'; closedir(dp); } } /* end getcwd */ # endif /* hp9000s500 */ /* strnrcpy(): * Like strncpy, going backwards and returning the new pointer */ static char * strnrcpy(char *ptr, char *str, size_t siz) { int len = strlen(str); if (siz == 0) return ptr; while (len && siz--) *--ptr = str[--len]; return (ptr); } /* end strnrcpy */ #endif /* !HAVE_GETCWD */ #ifdef apollo /*** *** Domain/OS ***/ #include #include #include static char * apperr(status_$t *st) { static char *buf; /* = NULL */ short e_subl, e_modl, e_codel; error_$string_t e_sub, e_mod, e_code; error_$get_text(*st, e_sub, &e_subl, e_mod, &e_modl, e_code, &e_codel); e_sub[e_subl] = '\0'; e_code[e_codel] = '\0'; e_mod[e_modl] = '\0'; xfree(buf); buf = xasprintf("%s (%s/%s)", e_code, e_sub, e_mod); return(buf); } static int llib(Char *s) { short len = Strlen(s); status_$t st; char *t; loader_$inlib(t = short2str(s), len, &st); if (st.all != status_$ok) stderror(ERR_SYSTEM, t, apperr(&st)); } /*ARGSUSED*/ void doinlib(Char **v, struct command *c) { Char **globbed; setname(short2str(*v++)); v = glob_all_or_error(v); globbed = v; cleanup_push(globbed, blk_cleanup); while (v && *v) llib(*v++); cleanup_until(globbed); } int getv(Char *v) { if (eq(v, STRbsd43)) return(1); else if (eq(v, STRsys53)) return(0); else stderror(ERR_NAME | ERR_SYSTEM, short2str(v), CGETS(23, 28, "Invalid system type")); /*NOTREACHED*/ return(0); } /*ARGSUSED*/ void dover(Char **v, struct command *c) { Char *p; setname(short2str(*v++)); if (!*v) { if (!(p = tgetenv(STRSYSTYPE))) stderror(ERR_NAME | ERR_STRING, CGETS(23, 29, "System type is not set")); xprintf("%S\n", p); } else { tsetenv(STRSYSTYPE, getv(*v) ? STRbsd43 : STRsys53); dohash(NULL, NULL); } } /* * Many thanks to rees@citi.umich.edu (Jim Rees) and * mathys@ssdt-tempe.sps.mot.com (Yves Mathys) * For figuring out how to do this... I could have never done * it without their help. */ typedef short enum { name_$wdir_type, name_$ndir_type, name_$node_dir_type, } name_$dir_type_t; /*ARGSUSED*/ void dorootnode(Char **v, struct command *c) { name_$dir_type_t dirtype = name_$node_dir_type; uid_$t uid; status_$t st; char *name; short namelen; setname(short2str(*v++)); name = short2str(*v); namelen = strlen(name); name_$resolve(name, &namelen, &uid, &st); if (st.all != status_$ok) stderror(ERR_SYSTEM, name, apperr(&st)); namelen = 0; name_$set_diru(&uid, "", &namelen, &dirtype, &st); if (st.all != status_$ok) stderror(ERR_SYSTEM, name, apperr(&st)); dohash(NULL, NULL); } int isapad(void) { static int res = -1; static status_$t st; if (res == -1) { int strm; if (isatty(0)) strm = 0; if (isatty(1)) strm = 1; if (isatty(2)) strm = 2; else { res = 0; st.all = status_$ok; return(res); } res = stream_$isavt(&strm, &st); res = res ? 1 : 0; } else { if (st.all != status_$ok) stderror(ERR_SYSTEM, "stream_$isavt", apperr(&st)); } return(res); } #endif #if defined(__CYGWIN__) && !defined(NO_CRYPT) #undef CHAR /* Collides with Win32 API */ #define WIN32_LEAN_AND_MEAN #include #include char * cygwin_xcrypt(struct passwd *pw, const char *password, const char *expected_pwd) { static char invalid_password[] = "\377"; HANDLE token = cygwin_logon_user(pw, password); if (token == INVALID_HANDLE_VALUE) return invalid_password; CloseHandle(token); return (char *) expected_pwd; } #endif /* __CYGWIN__ && !NO_CRYPT */ diff --git a/contrib/tcsh/tc.prompt.c b/contrib/tcsh/tc.prompt.c index 7f728710d148..f06b9596c138 100644 --- a/contrib/tcsh/tc.prompt.c +++ b/contrib/tcsh/tc.prompt.c @@ -1,668 +1,668 @@ /* * tc.prompt.c: Prompt printing stuff */ /*- * Copyright (c) 1980, 1991 The Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include "sh.h" #include "ed.h" #include "tw.h" /* * kfk 21oct1983 -- add @ (time) and / ($cwd) in prompt. * PWP 4/27/87 -- rearange for tcsh. * mrdch@com.tau.edu.il 6/26/89 - added ~, T and .# - rearanged to switch() * instead of if/elseif * Luke Mewburn, * 6-Sep-91 changed date format * 16-Feb-94 rewrote directory prompt code, added $ellipsis * 29-Dec-96 added rprompt support */ static const char *month_list[12]; static const char *day_list[7]; void dateinit(void) { #ifdef notyet int i; setlocale(LC_TIME, ""); for (i = 0; i < 12; i++) xfree((ptr_t) month_list[i]); month_list[0] = strsave(_time_info->abbrev_month[0]); month_list[1] = strsave(_time_info->abbrev_month[1]); month_list[2] = strsave(_time_info->abbrev_month[2]); month_list[3] = strsave(_time_info->abbrev_month[3]); month_list[4] = strsave(_time_info->abbrev_month[4]); month_list[5] = strsave(_time_info->abbrev_month[5]); month_list[6] = strsave(_time_info->abbrev_month[6]); month_list[7] = strsave(_time_info->abbrev_month[7]); month_list[8] = strsave(_time_info->abbrev_month[8]); month_list[9] = strsave(_time_info->abbrev_month[9]); month_list[10] = strsave(_time_info->abbrev_month[10]); month_list[11] = strsave(_time_info->abbrev_month[11]); for (i = 0; i < 7; i++) xfree((ptr_t) day_list[i]); day_list[0] = strsave(_time_info->abbrev_wkday[0]); day_list[1] = strsave(_time_info->abbrev_wkday[1]); day_list[2] = strsave(_time_info->abbrev_wkday[2]); day_list[3] = strsave(_time_info->abbrev_wkday[3]); day_list[4] = strsave(_time_info->abbrev_wkday[4]); day_list[5] = strsave(_time_info->abbrev_wkday[5]); day_list[6] = strsave(_time_info->abbrev_wkday[6]); #else month_list[0] = "Jan"; month_list[1] = "Feb"; month_list[2] = "Mar"; month_list[3] = "Apr"; month_list[4] = "May"; month_list[5] = "Jun"; month_list[6] = "Jul"; month_list[7] = "Aug"; month_list[8] = "Sep"; month_list[9] = "Oct"; month_list[10] = "Nov"; month_list[11] = "Dec"; day_list[0] = "Sun"; day_list[1] = "Mon"; day_list[2] = "Tue"; day_list[3] = "Wed"; day_list[4] = "Thu"; day_list[5] = "Fri"; day_list[6] = "Sat"; #endif } void printprompt(int promptno, const char *str) { static const Char *ocp = NULL; static const char *ostr = NULL; time_t lclock = time(NULL); const Char *cp; switch (promptno) { default: case 0: cp = varval(STRprompt); break; case 1: cp = varval(STRprompt2); break; case 2: cp = varval(STRprompt3); break; case 3: if (ocp != NULL) { cp = ocp; str = ostr; } else cp = varval(STRprompt); break; } if (promptno < 2) { ocp = cp; ostr = str; } xfree(Prompt); Prompt = NULL; Prompt = tprintf(FMT_PROMPT, cp, str, lclock, NULL); if (!editing) { for (cp = Prompt; *cp ; ) (void) putwraw(*cp++); SetAttributes(0); flush(); } xfree(RPrompt); RPrompt = NULL; if (promptno == 0) { /* determine rprompt if using main prompt */ cp = varval(STRrprompt); RPrompt = tprintf(FMT_PROMPT, cp, NULL, lclock, NULL); /* if not editing, put rprompt after prompt */ if (!editing && RPrompt[0] != '\0') { for (cp = RPrompt; *cp ; ) (void) putwraw(*cp++); SetAttributes(0); putraw(' '); flush(); } } } static void tprintf_append_mbs(struct Strbuf *buf, const char *mbs, Char attributes) { while (*mbs != 0) { Char wc; mbs += one_mbtowc(&wc, mbs, MB_LEN_MAX); Strbuf_append1(buf, wc | attributes); } } Char * tprintf(int what, const Char *fmt, const char *str, time_t tim, ptr_t info) { struct Strbuf buf = Strbuf_INIT; Char *z, *q; Char attributes = 0; static int print_prompt_did_ding = 0; char *cz; Char *p; const Char *cp = fmt; Char Scp; struct tm *t = localtime(&tim); /* prompt stuff */ static Char *olduser = NULL; int updirs; size_t pdirs; cleanup_push(&buf, Strbuf_cleanup); for (; *cp; cp++) { if ((*cp == '%') && ! (cp[1] == '\0')) { cp++; switch (*cp) { case 'R': if (what == FMT_HISTORY) { cz = fmthist('R', info); tprintf_append_mbs(&buf, cz, attributes); xfree(cz); } else { if (str != NULL) tprintf_append_mbs(&buf, str, attributes); } break; case '#': #ifdef __CYGWIN__ /* Check for being member of the Administrators group */ { gid_t grps[NGROUPS_MAX]; int grp, gcnt; gcnt = getgroups(NGROUPS_MAX, grps); # define DOMAIN_GROUP_RID_ADMINS 544 for (grp = 0; grp < gcnt; ++grp) if (grps[grp] == DOMAIN_GROUP_RID_ADMINS) break; Scp = (grp < gcnt) ? PRCHROOT : PRCH; } #else Scp = (uid == 0 || euid == 0) ? PRCHROOT : PRCH; #endif if (Scp != '\0') Strbuf_append1(&buf, attributes | Scp); break; case '!': case 'h': switch (what) { case FMT_HISTORY: cz = fmthist('h', info); break; case FMT_SCHED: cz = xasprintf("%d", *(int *)info); break; default: cz = xasprintf("%d", eventno + 1); break; } tprintf_append_mbs(&buf, cz, attributes); xfree(cz); break; case 'T': /* 24 hour format */ case '@': case 't': /* 12 hour am/pm format */ case 'p': /* With seconds */ case 'P': { char ampm = 'a'; int hr = t->tm_hour; /* addition by Hans J. Albertsson */ /* and another adapted from Justin Bur */ if (adrof(STRampm) || (*cp != 'T' && *cp != 'P')) { if (hr >= 12) { if (hr > 12) hr -= 12; ampm = 'p'; } else if (hr == 0) hr = 12; } /* else do a 24 hour clock */ /* "DING!" stuff by Hans also */ if (t->tm_min || print_prompt_did_ding || what != FMT_PROMPT || adrof(STRnoding)) { if (t->tm_min) print_prompt_did_ding = 0; /* * Pad hour to 2 characters if padhour is set, * by ADAM David Alan Martin */ p = Itoa(hr, adrof(STRpadhour) ? 2 : 0, attributes); Strbuf_append(&buf, p); xfree(p); Strbuf_append1(&buf, attributes | ':'); p = Itoa(t->tm_min, 2, attributes); Strbuf_append(&buf, p); xfree(p); if (*cp == 'p' || *cp == 'P') { Strbuf_append1(&buf, attributes | ':'); p = Itoa(t->tm_sec, 2, attributes); Strbuf_append(&buf, p); xfree(p); } if (adrof(STRampm) || (*cp != 'T' && *cp != 'P')) { Strbuf_append1(&buf, attributes | ampm); Strbuf_append1(&buf, attributes | 'm'); } } else { /* we need to ding */ size_t i; for (i = 0; STRDING[i] != 0; i++) Strbuf_append1(&buf, attributes | STRDING[i]); print_prompt_did_ding = 1; } } break; case 'M': #ifndef HAVENOUTMP if (what == FMT_WHO) cz = who_info(info, 'M'); else #endif /* HAVENOUTMP */ cz = getenv("HOST"); /* * Bug pointed out by Laurent Dami : don't * derefrence that NULL (if HOST is not set)... */ if (cz != NULL) tprintf_append_mbs(&buf, cz, attributes); if (what == FMT_WHO) xfree(cz); break; case 'm': { char *scz = NULL; #ifndef HAVENOUTMP if (what == FMT_WHO) scz = cz = who_info(info, 'm'); else #endif /* HAVENOUTMP */ cz = getenv("HOST"); if (cz != NULL) while (*cz != 0 && (what == FMT_WHO || *cz != '.')) { Char wc; cz += one_mbtowc(&wc, cz, MB_LEN_MAX); Strbuf_append1(&buf, wc | attributes); } if (scz) xfree(scz); break; } /* lukem: new directory prompt code */ case '~': case '/': case '.': case 'c': case 'C': Scp = *cp; if (Scp == 'c') /* store format type (c == .) */ Scp = '.'; if ((z = varval(STRcwd)) == STRNULL) break; /* no cwd, so don't do anything */ /* show ~ whenever possible - a la dirs */ if (Scp == '~' || Scp == '.' ) { static Char *olddir = NULL; if (tlength == 0 || olddir != z) { olddir = z; /* have we changed dir? */ olduser = getusername(&olddir); } if (olduser) z = olddir; } updirs = pdirs = 0; /* option to determine fixed # of dirs from path */ if (Scp == '.' || Scp == 'C') { int skip; #ifdef WINNT_NATIVE Char *oldz = z; if (z[1] == ':') { Strbuf_append1(&buf, attributes | *z++); Strbuf_append1(&buf, attributes | *z++); } if (*z == '/' && z[1] == '/') { Strbuf_append1(&buf, attributes | *z++); Strbuf_append1(&buf, attributes | *z++); do { Strbuf_append1(&buf, attributes | *z++); - } while(*z != '/'); + } while (*z != '/'); } #endif /* WINNT_NATIVE */ q = z; while (*z) /* calc # of /'s */ if (*z++ == '/') updirs++; #ifdef WINNT_NATIVE /* * for format type c, prompt will be following... * c:/path => c:/path * c:/path/to => c:to * //machine/share => //machine/share * //machine/share/folder => //machine:folder */ if (oldz[0] == '/' && oldz[1] == '/' && updirs > 1) Strbuf_append1(&buf, attributes | ':'); #endif /* WINNT_NATIVE */ if ((Scp == 'C' && *q != '/')) updirs++; if (cp[1] == '0') { /* print or ... */ pdirs = 1; cp++; } if (cp[1] >= '1' && cp[1] <= '9') { /* calc # to skip */ skip = cp[1] - '0'; cp++; } else skip = 1; updirs -= skip; while (skip-- > 0) { while ((z > q) && (*z != '/')) z--; /* back up */ if (skip && z > q) z--; } if (*z == '/' && z != q) z++; } /* . || C */ /* print ~[user] */ if ((olduser) && ((Scp == '~') || (Scp == '.' && (pdirs || (!pdirs && updirs <= 0))) )) { Strbuf_append1(&buf, attributes | '~'); for (q = olduser; *q; q++) Strbuf_append1(&buf, attributes | *q); } /* RWM - tell you how many dirs we've ignored */ /* and add '/' at front of this */ if (updirs > 0 && pdirs) { if (adrof(STRellipsis)) { Strbuf_append1(&buf, attributes | '.'); Strbuf_append1(&buf, attributes | '.'); Strbuf_append1(&buf, attributes | '.'); } else { Strbuf_append1(&buf, attributes | '/'); Strbuf_append1(&buf, attributes | '<'); if (updirs > 9) { Strbuf_append1(&buf, attributes | '9'); Strbuf_append1(&buf, attributes | '+'); } else Strbuf_append1(&buf, attributes | ('0' + updirs)); Strbuf_append1(&buf, attributes | '>'); } } while (*z) Strbuf_append1(&buf, attributes | *z++); break; /* lukem: end of new directory prompt code */ case 'n': #ifndef HAVENOUTMP if (what == FMT_WHO) { cz = who_info(info, 'n'); tprintf_append_mbs(&buf, cz, attributes); xfree(cz); } else #endif /* HAVENOUTMP */ { if ((z = varval(STRuser)) != STRNULL) while (*z) Strbuf_append1(&buf, attributes | *z++); } break; case 'N': if ((z = varval(STReuser)) != STRNULL) while (*z) Strbuf_append1(&buf, attributes | *z++); break; case 'l': #ifndef HAVENOUTMP if (what == FMT_WHO) { cz = who_info(info, 'l'); tprintf_append_mbs(&buf, cz, attributes); xfree(cz); } else #endif /* HAVENOUTMP */ { if ((z = varval(STRtty)) != STRNULL) while (*z) Strbuf_append1(&buf, attributes | *z++); } break; case 'd': tprintf_append_mbs(&buf, day_list[t->tm_wday], attributes); break; case 'D': p = Itoa(t->tm_mday, 2, attributes); Strbuf_append(&buf, p); xfree(p); break; case 'w': tprintf_append_mbs(&buf, month_list[t->tm_mon], attributes); break; case 'W': p = Itoa(t->tm_mon + 1, 2, attributes); Strbuf_append(&buf, p); xfree(p); break; case 'y': p = Itoa(t->tm_year % 100, 2, attributes); Strbuf_append(&buf, p); xfree(p); break; case 'Y': p = Itoa(t->tm_year + 1900, 4, attributes); Strbuf_append(&buf, p); xfree(p); break; case 'S': /* start standout */ attributes |= STANDOUT; break; case 'B': /* start bold */ attributes |= BOLD; break; case 'U': /* start underline */ attributes |= UNDER; break; case 's': /* end standout */ attributes &= ~STANDOUT; break; case 'b': /* end bold */ attributes &= ~BOLD; break; case 'u': /* end underline */ attributes &= ~UNDER; break; case 'L': ClearToBottom(); break; case 'j': { int njobs = -1; struct process *pp; for (pp = proclist.p_next; pp; pp = pp->p_next) njobs++; if (njobs == -1) njobs++; p = Itoa(njobs, 1, attributes); Strbuf_append(&buf, p); xfree(p); break; } case '?': if ((z = varval(STRstatus)) != STRNULL) while (*z) Strbuf_append1(&buf, attributes | *z++); break; case '$': expdollar(&buf, &cp, attributes); /* cp should point the last char of current % sequence */ cp--; break; case '%': Strbuf_append1(&buf, attributes | '%'); break; case '{': /* literal characters start */ #if LITERAL == 0 /* * No literal capability, so skip all chars in the literal * string */ while (*cp != '\0' && (cp[-1] != '%' || *cp != '}')) cp++; #endif /* LITERAL == 0 */ attributes |= LITERAL; break; case '}': /* literal characters end */ attributes &= ~LITERAL; break; default: #ifndef HAVENOUTMP if (*cp == 'a' && what == FMT_WHO) { cz = who_info(info, 'a'); tprintf_append_mbs(&buf, cz, attributes); xfree(cz); } else #endif /* HAVENOUTMP */ { Strbuf_append1(&buf, attributes | '%'); Strbuf_append1(&buf, attributes | *cp); } break; } } else if (*cp == '\\' || *cp == '^') Strbuf_append1(&buf, attributes | parseescape(&cp)); else if (*cp == HIST) { /* EGS: handle '!'s in prompts */ if (what == FMT_HISTORY) cz = fmthist('h', info); else cz = xasprintf("%d", eventno + 1); tprintf_append_mbs(&buf, cz, attributes); xfree(cz); } else Strbuf_append1(&buf, attributes | *cp); /* normal character */ } cleanup_ignore(&buf); cleanup_until(&buf); return Strbuf_finish(&buf); } int expdollar(struct Strbuf *buf, const Char **srcp, Char attr) { struct varent *vp; const Char *src = *srcp; Char *var, *val; size_t i; int curly = 0; /* found a variable, expand it */ var = xmalloc((Strlen(src) + 1) * sizeof (*var)); for (i = 0; ; i++) { var[i] = *++src & TRIM; if (i == 0 && var[i] == '{') { curly = 1; var[i] = *++src & TRIM; } if (!alnum(var[i]) && var[i] != '_') { var[i] = '\0'; break; } } if (curly && (*src & TRIM) == '}') src++; vp = adrof(var); if (vp && vp->vec) { for (i = 0; vp->vec[i] != NULL; i++) { for (val = vp->vec[i]; *val; val++) if (*val != '\n' && *val != '\r') Strbuf_append1(buf, *val | attr); if (vp->vec[i+1]) Strbuf_append1(buf, ' ' | attr); } } else { val = (!vp) ? tgetenv(var) : NULL; if (val) { for (; *val; val++) if (*val != '\n' && *val != '\r') Strbuf_append1(buf, *val | attr); } else { *srcp = src; xfree(var); return 0; } } *srcp = src; xfree(var); return 1; } diff --git a/contrib/tcsh/tcsh.man b/contrib/tcsh/tcsh.man index 3d06e5541e00..b01d07e0881a 100644 --- a/contrib/tcsh/tcsh.man +++ b/contrib/tcsh/tcsh.man @@ -1,5517 +1,5534 @@ .\" .\" Copyright (c) 1980, 1990, 1993 .\" The Regents of the University of California. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" Style notes for the tcsh man page: .\" .\" - Tags in lists are bold, except in the FILES section where they are .\" italic. .\" .\" - References are bold for section headings and environment and shell .\" variables and italic for commands (externals, builtins, aliases, and .\" editor commands) and arguments to commands. .\" .\" - Be careful with the .B and .I macros: they handle only a limited number .\" of words. Work around this with \fB and \fI, but only if absolutely .\" necessary, because tcsh.man2html uses .B/.I to find name anchors. .\" .\" - Indent in multiples of 4, usually 8. .\" .\" - Use `', not '' or "", except of course in shell syntax examples. .\" '' at the beginning of a line will vanish! .\" .\" - Use \` for literal back-quote (`). .\" .\" - Use \e for literal backslash (\). .\" .\" - Use \-, not -. .\" .\" - Include the tilde when naming dot files. `~/.login', not `.login'. .\" .\" - Refer to external commands in man page format, e.g., `csh(1)'. However, .\" tcsh is `tcsh', not `tcsh(1)', because this is the tcsh man page (and .\" see the next note anyway). .\" .\" - Say `the shell', not `tcsh', unless distinguishing between tcsh and csh. .\" .\" - Say `shell variable'/`environment variable' instead of `variable' .\" and `builtin command'/`editor command' instead of `builtin' or `command' .\" unless the distinction is absolutely clear from context. .\" .\" - Use the simple present tense. `The shell uses', not `The shell will use'. .\" .\" - IMPORTANT: Cross-reference as much as possible. Commands, variables, .\" etc. in the reference section should be mentioned in the appropriate .\" descriptive section, or at least in the reference-section description .\" of another command (or whatever) which is mentioned in a description .\" section. Remember to note OS-specific things in "OS variant support", .\" new features in NEW FEATURES and referenced external commands in SEE .\" ALSO. .\" .\" - tcsh.man2html depends heavily on the specific nroff commands used in the .\" man page when the script was written. Please stick closely to the style .\" used here if you can. In particular, please don't use nroff commands .\" which aren't already used herein. .\" -.TH TCSH 1 "8 May 2019" "Astron 6.21.00" +.TH TCSH 1 "11 Nov 2020" "Astron 6.22.03" .SH NAME tcsh \- C shell with file name completion and command line editing .SH SYNOPSIS .B tcsh \fR[\fB\-bcdefFimnqstvVxX\fR] [\fB\-Dname\fR[\fB=value\fR]] [arg ...] .br .B tcsh \-l .SH DESCRIPTION \fItcsh\fR is an enhanced but completely compatible version of the Berkeley UNIX C shell, \fIcsh\fR(1). It is a command language interpreter usable both as an interactive login shell and a shell script command processor. It includes a command-line editor (see \fBThe command-line editor\fR), programmable word completion (see \fBCompletion and listing\fR), spelling correction (see \fBSpelling correction\fR), a history mechanism (see \fBHistory substitution\fR), job control (see \fBJobs\fR) and a C-like syntax. The \fBNEW FEATURES\fR section describes major enhancements of \fItcsh\fR over \fIcsh\fR(1). Throughout this manual, features of \fItcsh\fR not found in most \fIcsh\fR(1) implementations (specifically, the 4.4BSD \fIcsh\fR) are labeled with `(+)', and features which are present in \fIcsh\fR(1) but not usually documented are labeled with `(u)'. .SS "Argument list processing" If the first argument (argument 0) to the shell is `\-' then it is a login shell. A login shell can be also specified by invoking the shell with the \fB\-l\fR flag as the only argument. .PP The rest of the flag arguments are interpreted as follows: .TP 4 .B \-b Forces a ``break'' from option processing, causing any further shell arguments to be treated as non-option arguments. The remaining arguments will not be interpreted as shell options. This may be used to pass options to a shell script without confusion or possible subterfuge. The shell will not run a set-user ID script without this option. .TP 4 .B \-c Commands are read from the following argument (which must be present, and must be a single argument), stored in the \fBcommand\fR shell variable for reference, and executed. Any remaining arguments are placed in the \fBargv\fR shell variable. .TP 4 .B \-d The shell loads the directory stack from \fI~/.cshdirs\fR as described under \fBStartup and shutdown\fR, whether or not it is a login shell. (+) .TP 4 .B \-D\fIname\fR[=\fIvalue\fR] Sets the environment variable \fIname\fR to \fIvalue\fR. (Domain/OS only) (+) .TP 4 .B \-e The shell exits if any invoked command terminates abnormally or yields a non-zero exit status. .TP 4 .B \-f The shell does not load any resource or startup files, or perform any command hashing, and thus starts faster. .TP 4 .B \-F The shell uses \fIfork\fR(2) instead of \fIvfork\fR(2) to spawn processes. (+) .TP 4 .B \-i The shell is interactive and prompts for its top-level input, even if it appears to not be a terminal. Shells are interactive without this option if their inputs and outputs are terminals. .TP 4 .B \-l The shell is a login shell. Applicable only if \fB\-l\fR is the only flag specified. .TP 4 .B \-m The shell loads \fI~/.tcshrc\fR even if it does not belong to the effective user. Newer versions of \fIsu\fR(1) can pass \fB\-m\fR to the shell. (+) .TP 4 .B \-n The shell parses commands but does not execute them. This aids in debugging shell scripts. .TP 4 .B \-q The shell accepts SIGQUIT (see \fBSignal handling\fR) and behaves when it is used under a debugger. Job control is disabled. (u) .TP 4 .B \-s Command input is taken from the standard input. .TP 4 .B \-t The shell reads and executes a single line of input. A `\e' may be used to escape the newline at the end of this line and continue onto another line. .TP 4 .B \-v Sets the \fBverbose\fR shell variable, so that command input is echoed after history substitution. .TP 4 .B \-x Sets the \fBecho\fR shell variable, so that commands are echoed immediately before execution. .TP 4 .B \-V Sets the \fBverbose\fR shell variable even before executing \fI~/.tcshrc\fR. .TP 4 .B \-X Is to \fB\-x\fR as \fB\-V\fR is to \fB\-v\fR. .TP 4 .B \-\-help Print a help message on the standard output and exit. (+) .TP 4 .B \-\-version Print the version/platform/compilation options on the standard output and exit. This information is also contained in the \fBversion\fR shell variable. (+) .PP After processing of flag arguments, if arguments remain but none of the \fB\-c\fR, \fB\-i\fR, \fB\-s\fR, or \fB\-t\fR options were given, the first argument is taken as the name of a file of commands, or ``script'', to be executed. The shell opens this file and saves its name for possible resubstitution by `$0'. Because many systems use either the standard version 6 or version 7 shells whose shell scripts are not compatible with this shell, the shell uses such a `standard' shell to execute a script whose first character is not a `#', i.e., that does not start with a comment. .PP Remaining arguments are placed in the \fBargv\fR shell variable. .SS "Startup and shutdown" A login shell begins by executing commands from the system files \fI/etc/csh.cshrc\fR and \fI/etc/csh.login\fR. It then executes commands from files in the user's \fBhome\fR directory: first \fI~/.tcshrc\fR (+) or, if \fI~/.tcshrc\fR is not found, \fI~/.cshrc\fR, then the contents of \fI~/.history\fR (or the value of the \fBhistfile\fR shell variable) are loaded into memory, then \fI~/.login\fR, and finally \fI~/.cshdirs\fR (or the value of the \fBdirsfile\fR shell variable) (+). The shell may read \fI/etc/csh.login\fR before instead of after \fI/etc/csh.cshrc\fR, and \fI~/.login\fR before instead of after \fI~/.tcshrc\fR or \fI~/.cshrc\fR and \fI~/.history\fR, if so compiled; see the \fBversion\fR shell variable. (+) .PP Non-login shells read only \fI/etc/csh.cshrc\fR and \fI~/.tcshrc\fR or \fI~/.cshrc\fR on startup. .PP For examples of startup files, please consult \fIhttp://tcshrc.sourceforge.net\fR. .PP Commands like \fIstty\fR(1) and \fItset\fR(1), which need be run only once per login, usually go in one's \fI~/.login\fR file. Users who need to use the same set of files with both \fIcsh\fR(1) and \fItcsh\fR can have only a \fI~/.cshrc\fR which checks for the existence of the \fBtcsh\fR shell variable (q.v.) before using \fItcsh\fR-specific commands, or can have both a \fI~/.cshrc\fR and a \fI~/.tcshrc\fR which \fIsource\fRs (see the builtin command) \fI~/.cshrc\fR. The rest of this manual uses `\fI~/.tcshrc\fR' to mean `\fI~/.tcshrc\fR or, if \fI~/.tcshrc\fR is not found, \fI~/.cshrc\fR'. .PP In the normal case, the shell begins reading commands from the terminal, prompting with `> '. (Processing of arguments and the use of the shell to process files containing command scripts are described later.) The shell repeatedly reads a line of command input, breaks it into words, places it on the command history list, parses it and executes each command in the line. .PP One can log out by typing `^D' on an empty line, `logout' or `login' or via the shell's autologout mechanism (see the \fBautologout\fR shell variable). When a login shell terminates it sets the \fBlogout\fR shell variable to `normal' or `automatic' as appropriate, then executes commands from the files \fI/etc/csh.logout\fR and \fI~/.logout\fR. The shell may drop DTR on logout if so compiled; see the \fBversion\fR shell variable. .PP The names of the system login and logout files vary from system to system for compatibility with different \fIcsh\fR(1) variants; see \fBFILES\fR. .SS Editing We first describe \fBThe command-line editor\fR. The \fBCompletion and listing\fR and \fBSpelling correction\fR sections describe two sets of functionality that are implemented as editor commands but which deserve their own treatment. Finally, \fBEditor commands\fR lists and describes the editor commands specific to the shell and their default bindings. .SS "The command-line editor (+)" Command-line input can be edited using key sequences much like those used in \fIemacs\fR(1) or \fIvi\fR(1). The editor is active only when the \fBedit\fR shell variable is set, which it is by default in interactive shells. The \fIbindkey\fR builtin can display and change key bindings. \fIemacs\fR(1)\-style key bindings are used by default (unless the shell was compiled otherwise; see the \fBversion\fR shell variable), but \fIbindkey\fR can change the key bindings to \fIvi\fR(1)\-style bindings en masse. .PP The shell always binds the arrow keys (as defined in the \fBTERMCAP\fR environment variable) to .PP .PD 0 .RS +4 .TP 8 down \fIdown-history\fR .TP 8 up \fIup-history\fR .TP 8 left \fIbackward-char\fR .TP 8 right \fIforward-char\fR .PD .RE .PP unless doing so would alter another single-character binding. One can set the arrow key escape sequences to the empty string with \fIsettc\fR to prevent these bindings. The ANSI/VT100 sequences for arrow keys are always bound. .PP Other key bindings are, for the most part, what \fIemacs\fR(1) and \fIvi\fR(1) users would expect and can easily be displayed by \fIbindkey\fR, so there is no need to list them here. Likewise, \fIbindkey\fR can list the editor commands with a short description of each. Certain key bindings have different behavior depending if \fIemacs\fR(1) or \fIvi\fR(1) style bindings are being used; see \fBvimode\fR for more information. .PP Note that editor commands do not have the same notion of a ``word'' as does the shell. The editor delimits words with any non-alphanumeric characters not in the shell variable \fBwordchars\fR, while the shell recognizes only whitespace and some of the characters with special meanings to it, listed under \fBLexical structure\fR. .SS "Completion and listing (+)" The shell is often able to complete words when given a unique abbreviation. Type part of a word (for example `ls /usr/lost') and hit the tab key to run the \fIcomplete-word\fR editor command. The shell completes the filename `/usr/lost' to `/usr/lost+found/', replacing the incomplete word with the complete word in the input buffer. (Note the terminal `/'; completion adds a `/' to the end of completed directories and a space to the end of other completed words, to speed typing and provide a visual indicator of successful completion. The \fBaddsuffix\fR shell variable can be unset to prevent this.) If no match is found (perhaps `/usr/lost+found' doesn't exist), the terminal bell rings. If the word is already complete (perhaps there is a `/usr/lost' on your system, or perhaps you were thinking too far ahead and typed the whole thing) a `/' or space is added to the end if it isn't already there. .PP Completion works anywhere in the line, not at just the end; completed text pushes the rest of the line to the right. Completion in the middle of a word often results in leftover characters to the right of the cursor that need to be deleted. .PP Commands and variables can be completed in much the same way. For example, typing `em[tab]' would complete `em' to `emacs' if \fIemacs\fR were the only command on your system beginning with `em'. Completion can find a command in any directory in \fBpath\fR or if given a full pathname. Typing `echo $ar[tab]' would complete `$ar' to `$argv' if no other variable began with `ar'. .PP The shell parses the input buffer to determine whether the word you want to complete should be completed as a filename, command or variable. The first word in the buffer and the first word following `;', `|', `|&', `&&' or `||' is considered to be a command. A word beginning with `$' is considered to be a variable. Anything else is a filename. An empty line is `completed' as a filename. .PP You can list the possible completions of a word at any time by typing `^D' to run the \fIdelete-char-or-list-or-eof\fR editor command. The shell lists the possible completions using the \fIls\-F\fR builtin (q.v.) and reprints the prompt and unfinished command line, for example: .IP "" 4 > ls /usr/l[^D] .br lbin/ lib/ local/ lost+found/ .br > ls /usr/l .PP If the \fBautolist\fR shell variable is set, the shell lists the remaining choices (if any) whenever completion fails: .IP "" 4 > set autolist .br > nm /usr/lib/libt[tab] .br libtermcap.a@ libtermlib.a@ .br > nm /usr/lib/libterm .PP If \fBautolist\fR is set to `ambiguous', choices are listed only when completion fails and adds no new characters to the word being completed. .PP A filename to be completed can contain variables, your own or others' home directories abbreviated with `~' (see \fBFilename substitution\fR) and directory stack entries abbreviated with `=' (see \fBDirectory stack substitution\fR). For example, .IP "" 4 > ls ~k[^D] .br kahn kas kellogg .br > ls ~ke[tab] .br > ls ~kellogg/ .PP or .IP "" 4 > set local = /usr/local .br > ls $lo[tab] .br > ls $local/[^D] .br bin/ etc/ lib/ man/ src/ .br > ls $local/ .PP Note that variables can also be expanded explicitly with the \fIexpand-variables\fR editor command. .PP \fIdelete-char-or-list-or-eof\fR lists at only the end of the line; in the middle of a line it deletes the character under the cursor and on an empty line it logs one out or, if \fBignoreeof\fR is set, does nothing. `M-^D', bound to the editor command \fIlist-choices\fR, lists completion possibilities anywhere on a line, and \fIlist-choices\fR (or any one of the related editor commands that do or don't delete, list and/or log out, listed under \fIdelete-char-or-list-or-eof\fR) can be bound to `^D' with the \fIbindkey\fR builtin command if so desired. .PP The \fIcomplete-word-fwd\fR and \fIcomplete-word-back\fR editor commands (not bound to any keys by default) can be used to cycle up and down through the list of possible completions, replacing the current word with the next or previous word in the list. .PP The shell variable \fBfignore\fR can be set to a list of suffixes to be ignored by completion. Consider the following: .IP "" 4 > ls .br Makefile condiments.h~ main.o side.c .br README main.c meal side.o .br condiments.h main.c~ .br > set fignore = (.o \e~) .br > emacs ma[^D] .br main.c main.c~ main.o .br > emacs ma[tab] .br > emacs main.c .PP `main.c~' and `main.o' are ignored by completion (but not listing), because they end in suffixes in \fBfignore\fR. Note that a `\e' was needed in front of `~' to prevent it from being expanded to \fBhome\fR as described under \fBFilename substitution\fR. \fBfignore\fR is ignored if only one completion is possible. .PP If the \fBcomplete\fR shell variable is set to `enhance', completion 1) ignores case and 2) considers periods, hyphens and underscores (`.', `\-' and `_') to be word separators and hyphens and underscores to be equivalent. If you had the following files .IP "" 4 comp.lang.c comp.lang.perl comp.std.c++ .br comp.lang.c++ comp.std.c .PP and typed `mail \-f c.l.c[tab]', it would be completed to `mail \-f comp.lang.c', and ^D would list `comp.lang.c' and `comp.lang.c++'. `mail \-f c..c++[^D]' would list `comp.lang.c++' and `comp.std.c++'. Typing `rm a\-\-file[^D]' in the following directory .IP "" 4 A_silly_file a-hyphenated-file another_silly_file .PP would list all three files, because case is ignored and hyphens and underscores are equivalent. Periods, however, are not equivalent to hyphens or underscores. .PP If the \fBcomplete\fR shell variable is set to `Enhance', completion ignores case and differences between a hyphen and an underscore word separator only when the user types a lowercase character or a hyphen. Entering an uppercase character or an underscore will not match the corresponding lowercase character or hyphen word separator. Typing `rm a\-\-file[^D]' in the directory of the previous example would still list all three files, but typing `rm A\-\-file' would match only `A_silly_file' and typing `rm a__file[^D]' would match just `A_silly_file' and `another_silly_file' because the user explicitly used an uppercase or an underscore character. .PP Completion and listing are affected by several other shell variables: \fBrecexact\fR can be set to complete on the shortest possible unique match, even if more typing might result in a longer match: .IP "" 4 > ls .br fodder foo food foonly .br > set recexact .br > rm fo[tab] .PP just beeps, because `fo' could expand to `fod' or `foo', but if we type another `o', .IP "" 4 > rm foo[tab] .br > rm foo .PP the completion completes on `foo', even though `food' and `foonly' also match. \fBautoexpand\fR can be set to run the \fIexpand-history\fR editor command before each completion attempt, \fBautocorrect\fR can be set to spelling-correct the word to be completed (see \fBSpelling correction\fR) before each completion attempt and \fBcorrect\fR can be set to complete commands automatically after one hits `return'. \fBmatchbeep\fR can be set to make completion beep or not beep in a variety of situations, and \fBnobeep\fR can be set to never beep at all. \fBnostat\fR can be set to a list of directories and/or patterns that match directories to prevent the completion mechanism from \fIstat\fR(2)ing those directories. \fBlistmax\fR and \fBlistmaxrows\fR can be set to limit the number of items and rows (respectively) that are listed without asking first. \fBrecognize_only_executables\fR can be set to make the shell list only executables when listing commands, but it is quite slow. .PP Finally, the \fIcomplete\fR builtin command can be used to tell the shell how to complete words other than filenames, commands and variables. Completion and listing do not work on glob-patterns (see \fBFilename substitution\fR), but the \fIlist-glob\fR and \fIexpand-glob\fR editor commands perform equivalent functions for glob-patterns. .SS "Spelling correction (+)" The shell can sometimes correct the spelling of filenames, commands and variable names as well as completing and listing them. .PP Individual words can be spelling-corrected with the \fIspell-word\fR editor command (usually bound to M-s and M-S) and the entire input buffer with \fIspell-line\fR (usually bound to M-$). The \fBcorrect\fR shell variable can be set to `cmd' to correct the command name or `all' to correct the entire line each time return is typed, and \fBautocorrect\fR can be set to correct the word to be completed before each completion attempt. .PP When spelling correction is invoked in any of these ways and the shell thinks that any part of the command line is misspelled, it prompts with the corrected line: .IP "" 4 > set correct = cmd .br > lz /usr/bin .br CORRECT>ls /usr/bin (y|n|e|a)? .PP One can answer `y' or space to execute the corrected line, `e' to leave the uncorrected command in the input buffer, `a' to abort the command as if `^C' had been hit, and anything else to execute the original line unchanged. .PP Spelling correction recognizes user-defined completions (see the \fIcomplete\fR builtin command). If an input word in a position for which a completion is defined resembles a word in the completion list, spelling correction registers a misspelling and suggests the latter word as a correction. However, if the input word does not match any of the possible completions for that position, spelling correction does not register a misspelling. .PP Like completion, spelling correction works anywhere in the line, pushing the rest of the line to the right and possibly leaving extra characters to the right of the cursor. .SS "Editor commands (+)" `bindkey' lists key bindings and `bindkey \-l' lists and briefly describes editor commands. Only new or especially interesting editor commands are described here. See \fIemacs\fR(1) and \fIvi\fR(1) for descriptions of each editor's key bindings. .PP The character or characters to which each command is bound by default is given in parentheses. `^\fIcharacter\fR' means a control character and `M-\fIcharacter\fR' a meta character, typed as escape-\fIcharacter\fR on terminals without a meta key. Case counts, but commands that are bound to letters by default are bound to both lower- and uppercase letters for convenience. .TP 8 .B backward-char \fR(^B, left) Move back a character. Cursor behavior modified by \fBvimode\fR. .TP 8 .B backward-delete-word \fR(M-^H, M-^?) Cut from beginning of current word to cursor \- saved in cut buffer. Word boundary behavior modified by \fBvimode\fR. .TP 8 .B backward-word \fR(M-b, M-B) Move to beginning of current word. Word boundary and cursor behavior modified by \fBvimode\fR. .TP 8 .B beginning-of-line \fR(^A, home) Move to beginning of line. Cursor behavior modified by \fBvimode\fR. .TP 8 .B capitalize-word \fR(M-c, M-C) Capitalize the characters from cursor to end of current word. Word boundary behavior modified by \fBvimode\fR. .TP 8 .B complete-word \fR(tab) Completes a word as described under \fBCompletion and listing\fR. .TP 8 .B complete-word-back \fR(not bound) Like \fIcomplete-word-fwd\fR, but steps up from the end of the list. .TP 8 .B complete-word-fwd \fR(not bound) Replaces the current word with the first word in the list of possible completions. May be repeated to step down through the list. At the end of the list, beeps and reverts to the incomplete word. .TP 8 .B complete-word-raw \fR(^X-tab) Like \fIcomplete-word\fR, but ignores user-defined completions. .TP 8 .B copy-prev-word \fR(M-^_) Copies the previous word in the current line into the input buffer. See also \fIinsert-last-word\fR. Word boundary behavior modified by \fBvimode\fR. .TP 8 .B dabbrev-expand \fR(M-/) Expands the current word to the most recent preceding one for which the current is a leading substring, wrapping around the history list (once) if necessary. Repeating \fIdabbrev-expand\fR without any intervening typing changes to the next previous word etc., skipping identical matches much like \fIhistory-search-backward\fR does. .TP 8 .B delete-char \fR(not bound) Deletes the character under the cursor. See also \fIdelete-char-or-list-or-eof\fR. Cursor behavior modified by \fBvimode\fR. .TP 8 .B delete-char-or-eof \fR(not bound) Does \fIdelete-char\fR if there is a character under the cursor or \fIend-of-file\fR on an empty line. See also \fIdelete-char-or-list-or-eof\fR. Cursor behavior modified by \fBvimode\fR. .TP 8 .B delete-char-or-list \fR(not bound) Does \fIdelete-char\fR if there is a character under the cursor or \fIlist-choices\fR at the end of the line. See also \fIdelete-char-or-list-or-eof\fR. .TP 8 .B delete-char-or-list-or-eof \fR(^D) Does \fIdelete-char\fR if there is a character under the cursor, \fIlist-choices\fR at the end of the line or \fIend-of-file\fR on an empty line. See also those three commands, each of which does only a single action, and \fIdelete-char-or-eof\fR, \fIdelete-char-or-list\fR and \fIlist-or-eof\fR, each of which does a different two out of the three. .TP 8 .B delete-word \fR(M-d, M-D) Cut from cursor to end of current word \- save in cut buffer. Word boundary behavior modified by \fBvimode\fR. .TP 8 .B down-history \fR(down-arrow, ^N) Like \fIup-history\fR, but steps down, stopping at the original input line. .TP 8 .B downcase-word \fR(M-l, M-L) Lowercase the characters from cursor to end of current word. Word boundary behavior modified by \fBvimode\fR. .TP 8 .B end-of-file \fR(not bound) Signals an end of file, causing the shell to exit unless the \fBignoreeof\fR shell variable (q.v.) is set to prevent this. See also \fIdelete-char-or-list-or-eof\fR. .TP 8 .B end-of-line \fR(^E, end) Move cursor to end of line. Cursor behavior modified by \fBvimode\fR. .TP 8 .B expand-history \fR(M-space) Expands history substitutions in the current word. See \fBHistory substitution\fR. See also \fImagic-space\fR, \fItoggle-literal-history\fR and the \fBautoexpand\fR shell variable. .TP 8 .B expand-glob \fR(^X-*) Expands the glob-pattern to the left of the cursor. See \fBFilename substitution\fR. .TP 8 .B expand-line \fR(not bound) Like \fIexpand-history\fR, but expands history substitutions in each word in the input buffer. .TP 8 .B expand-variables \fR(^X-$) Expands the variable to the left of the cursor. See \fBVariable substitution\fR. .TP 8 .B forward-char \fR(^F, right) Move forward one character. Cursor behavior modified by \fBvimode\fR. .TP 8 .B forward-word \fR(M-f, M-F) Move forward to end of current word. Word boundary and cursor behavior modified by \fBvimode\fR. .TP 8 .B history-search-backward \fR(M-p, M-P) Searches backwards through the history list for a command beginning with the current contents of the input buffer up to the cursor and copies it into the input buffer. The search string may be a glob-pattern (see \fBFilename substitution\fR) containing `*', `?', `[]' or `{}'. \fIup-history\fR and \fIdown-history\fR will proceed from the appropriate point in the history list. Emacs mode only. See also \fIhistory-search-forward\fR and \fIi-search-back\fR. .TP 8 .B history-search-forward \fR(M-n, M-N) Like \fIhistory-search-backward\fR, but searches forward. .TP 8 .B i-search-back \fR(not bound) Searches backward like \fIhistory-search-backward\fR, copies the first match into the input buffer with the cursor positioned at the end of the pattern, and prompts with `bck: ' and the first match. Additional characters may be typed to extend the search, \fIi-search-back\fR may be typed to continue searching with the same pattern, wrapping around the history list if necessary, (\fIi-search-back\fR must be bound to a single character for this to work) or one of the following special characters may be typed: .PP .RS +8 .RS +4 .PD 0 .TP 8 ^W Appends the rest of the word under the cursor to the search pattern. .TP 8 delete (or any character bound to \fIbackward-delete-char\fR) Undoes the effect of the last character typed and deletes a character from the search pattern if appropriate. .TP 8 ^G If the previous search was successful, aborts the entire search. If not, goes back to the last successful search. .TP 8 escape Ends the search, leaving the current line in the input buffer. .RE .PD .PP Any other character not bound to \fIself-insert-command\fR terminates the search, leaving the current line in the input buffer, and is then interpreted as normal input. In particular, a carriage return causes the current line to be executed. See also \fIi-search-fwd\fR and \fIhistory-search-backward\fR. Word boundary behavior modified by \fBvimode\fR. .RE .TP 8 .B i-search-fwd \fR(not bound) Like \fIi-search-back\fR, but searches forward. Word boundary behavior modified by \fBvimode\fR. .TP 8 .B insert-last-word \fR(M-_) Inserts the last word of the previous input line (`!$') into the input buffer. See also \fIcopy-prev-word\fR. .TP 8 .B list-choices \fR(M-^D) Lists completion possibilities as described under \fBCompletion and listing\fR. See also \fIdelete-char-or-list-or-eof\fR and \fIlist-choices-raw\fR. .TP 8 .B list-choices-raw \fR(^X-^D) Like \fIlist-choices\fR, but ignores user-defined completions. .TP 8 .B list-glob \fR(^X-g, ^X-G) Lists (via the \fIls\-F\fR builtin) matches to the glob-pattern (see \fBFilename substitution\fR) to the left of the cursor. .TP 8 .B list-or-eof \fR(not bound) Does \fIlist-choices\fR or \fIend-of-file\fR on an empty line. See also \fIdelete-char-or-list-or-eof\fR. .TP 8 .B magic-space \fR(not bound) Expands history substitutions in the current line, like \fIexpand-history\fR, and inserts a space. \fImagic-space\fR is designed to be bound to the space bar, but is not bound by default. .TP 8 .B normalize-command \fR(^X-?) Searches for the current word in PATH and, if it is found, replaces it with the full path to the executable. Special characters are quoted. Aliases are expanded and quoted but commands within aliases are not. This command is useful with commands that take commands as arguments, e.g., `dbx' and `sh \-x'. .TP 8 .B normalize-path \fR(^X-n, ^X-N) Expands the current word as described under the `expand' setting of the \fBsymlinks\fR shell variable. .TP 8 .B overwrite-mode \fR(unbound) Toggles between input and overwrite modes. .TP 8 .B run-fg-editor \fR(M-^Z) Saves the current input line and looks for a stopped job where the file name portion of its first word is found in the \fBeditors\fR shell variable. If \fBeditors\fR is not set, then the file name portion of the \fBEDITOR\fR environment variable (`ed' if unset) and the \fBVISUAL\fR environment variable (`vi' if unset) will be used. If such a job is found, it is restarted as if `fg %\fIjob\fR' had been typed. This is used to toggle back and forth between an editor and the shell easily. Some people bind this command to `^Z' so they can do this even more easily. .TP .B run-help \fR(M-h, M-H) Searches for documentation on the current command, using the same notion of `current command' as the completion routines, and prints it. There is no way to use a pager; \fIrun-help\fR is designed for short help files. If the special alias \fBhelpcommand\fR is defined, it is run with the command name as a sole argument. Else, documentation should be in a file named \fIcommand\fR.help, \fIcommand\fR.1, \fIcommand\fR.6, \fIcommand\fR.8 or \fIcommand\fR, which should be in one of the directories listed in the \fBHPATH\fR environment variable. If there is more than one help file only the first is printed. .TP 8 .B self-insert-command \fR(text characters) In insert mode (the default), inserts the typed character into the input line after the character under the cursor. In overwrite mode, replaces the character under the cursor with the typed character. The input mode is normally preserved between lines, but the \fBinputmode\fR shell variable can be set to `insert' or `overwrite' to put the editor in that mode at the beginning of each line. See also \fIoverwrite-mode\fR. .TP 8 .B sequence-lead-in \fR(arrow prefix, meta prefix, ^X) Indicates that the following characters are part of a multi-key sequence. Binding a command to a multi-key sequence really creates two bindings: the first character to \fIsequence-lead-in\fR and the whole sequence to the command. All sequences beginning with a character bound to \fIsequence-lead-in\fR are effectively bound to \fIundefined-key\fR unless bound to another command. .TP 8 .B spell-line \fR(M-$) Attempts to correct the spelling of each word in the input buffer, like \fIspell-word\fR, but ignores words whose first character is one of `\-', `!', `^' or `%', or which contain `\e', `*' or `?', to avoid problems with switches, substitutions and the like. See \fBSpelling correction\fR. .TP 8 .B spell-word \fR(M-s, M-S) Attempts to correct the spelling of the current word as described under \fBSpelling correction\fR. Checks each component of a word which appears to be a pathname. .TP 8 .B toggle-literal-history \fR(M-r, M-R) Expands or `unexpands' history substitutions in the input buffer. See also \fIexpand-history\fR and the \fBautoexpand\fR shell variable. .TP 8 .B undefined-key \fR(any unbound key) Beeps. .TP 8 .B up-history \fR(up-arrow, ^P) Copies the previous entry in the history list into the input buffer. If \fBhistlit\fR is set, uses the literal form of the entry. May be repeated to step up through the history list, stopping at the top. .TP 8 .B upcase-word \fR(M-u, M-U) Uppercase the characters from cursor to end of current word. Word boundary behavior modified by \fBvimode\fR. .TP 8 .B vi-beginning-of-next-word \fR(not bound) Vi goto the beginning of next word. Word boundary and cursor behavior modified by \fBvimode\fR. .TP 8 .B vi-eword \fR(not bound) Vi move to the end of the current word. Word boundary behavior modified by \fBvimode\fR. .TP 8 .B vi-search-back \fR(?) Prompts with `?' for a search string (which may be a glob-pattern, as with \fIhistory-search-backward\fR), searches for it and copies it into the input buffer. The bell rings if no match is found. Hitting return ends the search and leaves the last match in the input buffer. Hitting escape ends the search and executes the match. \fIvi\fR mode only. .TP 8 .B vi-search-fwd \fR(/) Like \fIvi-search-back\fR, but searches forward. .TP 8 .B which-command \fR(M-?) Does a \fIwhich\fR (see the description of the builtin command) on the first word of the input buffer. .TP 8 .B yank-pop \fR(M-y) When executed immediately after a \fIyank\fR or another \fIyank-pop\fR, replaces the yanked string with the next previous string from the killring. This also has the effect of rotating the killring, such that this string will be considered the most recently killed by a later \fIyank\fR command. Repeating \fIyank-pop\fR will cycle through the killring any number of times. .SS "Lexical structure" The shell splits input lines into words at blanks and tabs. The special characters `&', `|', `;', `<', `>', `(', and `)' and the doubled characters `&&', `||', `<<' and `>>' are always separate words, whether or not they are surrounded by whitespace. .PP When the shell's input is not a terminal, the character `#' is taken to begin a comment. Each `#' and the rest of the input line on which it appears is discarded before further parsing. .PP A special character (including a blank or tab) may be prevented from having its special meaning, and possibly made part of another word, by preceding it with a backslash (`\e') or enclosing it in single (`''), double (`"') or backward (`\`') quotes. When not otherwise quoted a newline preceded by a `\e' is equivalent to a blank, but inside quotes this sequence results in a newline. .PP Furthermore, all \fBSubstitutions\fR (see below) except \fBHistory substitution\fR can be prevented by enclosing the strings (or parts of strings) in which they appear with single quotes or by quoting the crucial character(s) (e.g., `$' or `\`' for \fBVariable substitution\fR or \fBCommand substitution\fR respectively) with `\e'. (\fBAlias substitution\fR is no exception: quoting in any way any character of a word for which an \fIalias\fR has been defined prevents substitution of the alias. The usual way of quoting an alias is to precede it with a backslash.) \fBHistory substitution\fR is prevented by backslashes but not by single quotes. Strings quoted with double or backward quotes undergo \fBVariable substitution\fR and \fBCommand substitution\fR, but other substitutions are prevented. .PP Text inside single or double quotes becomes a single word (or part of one). Metacharacters in these strings, including blanks and tabs, do not form separate words. Only in one special case (see \fBCommand substitution\fR below) can a double-quoted string yield parts of more than one word; single-quoted strings never do. Backward quotes are special: they signal \fBCommand substitution\fR (q.v.), which may result in more than one word. .PP Quoting complex strings, particularly strings which themselves contain quoting characters, can be confusing. Remember that quotes need not be used as they are in human writing! It may be easier to quote not an entire string, but only those parts of the string which need quoting, using different types of quoting to do so if appropriate. .PP The \fBbackslash_quote\fR shell variable (q.v.) can be set to make backslashes always quote `\e', `'', and `"'. (+) This may make complex quoting tasks easier, but it can cause syntax errors in \fIcsh\fR(1) scripts. .SS Substitutions We now describe the various transformations the shell performs on the input in the order in which they occur. We note in passing the data structures involved and the commands and variables which affect them. Remember that substitutions can be prevented by quoting as described under \fBLexical structure\fR. .SS "History substitution" Each command, or ``event'', input from the terminal is saved in the history list. The previous command is always saved, and the \fBhistory\fR shell variable can be set to a number to save that many commands. The \fBhistdup\fR shell variable can be set to not save duplicate events or consecutive duplicate events. .PP Saved commands are numbered sequentially from 1 and stamped with the time. It is not usually necessary to use event numbers, but the current event number can be made part of the prompt by placing an `!' in the \fBprompt\fR shell variable. .PP +By default history entries are displayed by printing each parsed token +separated by space; thus the redirection operator `>&!' will be displayed as +`> & !'. +.PP The shell actually saves history in expanded and literal (unexpanded) forms. If the \fBhistlit\fR shell variable is set, commands that display and store history use the literal form. .PP The \fIhistory\fR builtin command can print, store in a file, restore and clear the history list at any time, and the \fBsavehist\fR and \fBhistfile\fR shell variables can be set to store the history list automatically on logout and restore it on login. .PP History substitutions introduce words from the history list into the input stream, making it easy to repeat commands, repeat arguments of a previous command in the current command, or fix spelling mistakes in the previous command with little typing and a high degree of confidence. .PP History substitutions begin with the character `!'. They may begin anywhere in the input stream, but they do not nest. The `!' may be preceded by a `\e' to prevent its special meaning; for convenience, a `!' is passed unchanged when it is followed by a blank, tab, newline, `=' or `('. History substitutions also occur when an input line begins with `^'. This special abbreviation will be described later. The characters used to signal history substitution (`!' and `^') can be changed by setting the \fBhistchars\fR shell variable. Any input line which contains a history substitution is printed before it is executed. .PP A history substitution may have an ``event specification'', which indicates the event from which words are to be taken, a ``word designator'', which selects particular words from the chosen event, and/or a ``modifier'', which manipulates the selected words. .PP An event specification can be .PP .PD 0 .RS +4 .TP 8 .I n A number, referring to a particular event .TP 8 \-\fIn\fR An offset, referring to the event \fIn\fR before the current event .TP 8 # The current event. This should be used carefully in \fIcsh\fR(1), where there is no check for recursion. \fItcsh\fR allows 10 levels of recursion. (+) .TP 8 ! The previous event (equivalent to `\-1') .TP 8 .I s The most recent event whose first word begins with the string \fIs\fR .TP 8 ?\fIs\fR? The most recent event which contains the string \fIs\fR. The second `?' can be omitted if it is immediately followed by a newline. .RE .PD .PP For example, consider this bit of someone's history list: .IP "" 4 \ 9 8:30 nroff \-man wumpus.man .br 10 8:31 cp wumpus.man wumpus.man.old .br 11 8:36 vi wumpus.man .br 12 8:37 diff wumpus.man.old wumpus.man .PP The commands are shown with their event numbers and time stamps. The current event, which we haven't typed in yet, is event 13. `!11' and `!\-2' refer to event 11. `!!' refers to the previous event, 12. `!!' can be abbreviated `!' if it is followed by `:' (`:' is described below). `!n' refers to event 9, which begins with `n'. `!?old?' also refers to event 12, which contains `old'. Without word designators or modifiers history references simply expand to the entire event, so we might type `!cp' to redo the copy command or `!!|more' if the `diff' output scrolled off the top of the screen. .PP History references may be insulated from the surrounding text with braces if necessary. For example, `!vdoc' would look for a command beginning with `vdoc', and, in this example, not find one, but `!{v}doc' would expand unambiguously to `vi wumpus.mandoc'. Even in braces, history substitutions do not nest. .PP (+) While \fIcsh\fR(1) expands, for example, `!3d' to event 3 with the letter `d' appended to it, \fItcsh\fR expands it to the last event beginning with `3d'; only completely numeric arguments are treated as event numbers. This makes it possible to recall events beginning with numbers. To expand `!3d' as in \fIcsh\fR(1) say `!{3}d'. .PP To select words from an event we can follow the event specification by a `:' and a designator for the desired words. The words of an input line are numbered from 0, the first (usually command) word being 0, the second word (first argument) being 1, etc. The basic word designators are: .PP .PD 0 .RS +4 .TP 8 0 The first (command) word .TP 8 .I n The \fIn\fRth argument .TP 8 ^ The first argument, equivalent to `1' .TP 8 $ The last argument .TP 8 % The word matched by an ?\fIs\fR? search .TP 8 .I x\-y A range of words .TP 8 .I \-y Equivalent to \fI`0\-y'\fR .TP 8 * Equivalent to `^\-$', but returns nothing if the event contains only 1 word .TP 8 .I x* Equivalent to \fI`x\-$'\fR .TP 8 .I x\- Equivalent to \fI`x*'\fR, but omitting the last word (`$') .PD .RE .PP Selected words are inserted into the command line separated by single blanks. For example, the `diff' command in the previous example might have been typed as `diff !!:1.old !!:1' (using `:1' to select the first argument from the previous event) or `diff !\-2:2 !\-2:1' to select and swap the arguments from the `cp' command. If we didn't care about the order of the `diff' we might have said `diff !\-2:1\-2' or simply `diff !\-2:*'. The `cp' command might have been written `cp wumpus.man !#:1.old', using `#' to refer to the current event. `!n:\- hurkle.man' would reuse the first two words from the `nroff' command to say `nroff \-man hurkle.man'. .PP The `:' separating the event specification from the word designator can be omitted if the argument selector begins with a `^', `$', `*', `%' or `\-'. For example, our `diff' command might have been `diff !!^.old !!^' or, equivalently, `diff !!$.old !!$'. However, if `!!' is abbreviated `!', an argument selector beginning with `\-' will be interpreted as an event specification. .PP A history reference may have a word designator but no event specification. It then references the previous command. Continuing our `diff' example, we could have said simply `diff !^.old !^' or, to get the arguments in the opposite order, just `diff !*'. .PP The word or words in a history reference can be edited, or ``modified'', by following it with one or more modifiers, each preceded by a `:': .PP .PD 0 .RS +4 .TP 8 h Remove a trailing pathname component, leaving the head. .TP 8 t Remove all leading pathname components, leaving the tail. .TP 8 r Remove a filename extension `.xxx', leaving the root name. .TP 8 e Remove all but the extension. .TP 8 u Uppercase the first lowercase letter. .TP 8 l Lowercase the first uppercase letter. .TP 8 s\fI/l/r/\fR Substitute \fIl\fR for \fIr\fR. \fIl\fR is simply a string like \fIr\fR, not a regular expression as in the eponymous \fIed\fR(1) command. Any character may be used as the delimiter in place of `/'; a `\e' can be used to quote the delimiter inside \fIl\fR and \fIr\fR. The character `&' in the \fIr\fR is replaced by \fIl\fR; `\e' also quotes `&'. If \fIl\fR is empty (``''), the \fIl\fR from a previous substitution or the \fIs\fR from a previous search or event number in event specification is used. The trailing delimiter may be omitted if it is immediately followed by a newline. .TP 8 & Repeat the previous substitution. .TP 8 g Apply the following modifier once to each word. .TP 8 a (+) Apply the following modifier as many times as possible to a single word. `a' and `g' can be used together to apply a modifier globally. With the `s' modifier, only the patterns contained in the original word are substituted, not patterns that contain any substitution result. .TP 8 p Print the new command line but do not execute it. .TP 8 q Quote the substituted words, preventing further substitutions. .TP 8 +Q +Same as q +but in addition preserve empty variables as a string containing a NUL. +This is useful to preserve positional arguments for example: +.IP "" 12 +> set args=('arg 1' '' 'arg 3') +.br +> tcsh -f -c 'echo ${#argv}' $args:gQ +.br +3 +.br +.TP 8 x Like q, but break into words at blanks, tabs and newlines. .PD .RE .PP Modifiers are applied to only the first modifiable word (unless `g' is used). It is an error for no word to be modifiable. .PP For example, the `diff' command might have been written as `diff wumpus.man.old !#^:r', using `:r' to remove `.old' from the first argument on the same line (`!#^'). We could say `echo hello out there', then `echo !*:u' to capitalize `hello', `echo !*:au' to say it out loud, or `echo !*:agu' to really shout. We might follow `mail \-s "I forgot my password" rot' with `!:s/rot/root' to correct the spelling of `root' (but see \fBSpelling correction\fR for a different approach). .PP There is a special abbreviation for substitutions. `^', when it is the first character on an input line, is equivalent to `!:s^'. Thus we might have said `^rot^root' to make the spelling correction in the previous example. This is the only history substitution which does not explicitly begin with `!'. .PP (+) In \fIcsh\fR as such, only one modifier may be applied to each history or variable expansion. In \fItcsh\fR, more than one may be used, for example .IP "" 4 % mv wumpus.man /usr/man/man1/wumpus.1 .br % man !$:t:r .br man wumpus .PP In \fIcsh\fR, the result would be `wumpus.1:r'. A substitution followed by a colon may need to be insulated from it with braces: .IP "" 4 > mv a.out /usr/games/wumpus .br > setenv PATH !$:h:$PATH .br Bad ! modifier: $. .br > setenv PATH !{\-2$:h}:$PATH .br setenv PATH /usr/games:/bin:/usr/bin:. .PP The first attempt would succeed in \fIcsh\fR but fails in \fItcsh\fR, because \fItcsh\fR expects another modifier after the second colon rather than `$'. .PP Finally, history can be accessed through the editor as well as through the substitutions just described. The \fIup-\fR and \fIdown-history\fR, \fIhistory-search-backward\fR and \fI-forward\fR, \fIi-search-back\fR and \fI-fwd\fR, \fIvi-search-back\fR and \fI-fwd\fR, \fIcopy-prev-word\fR and \fIinsert-last-word\fR editor commands search for events in the history list and copy them into the input buffer. The \fItoggle-literal-history\fR editor command switches between the expanded and literal forms of history lines in the input buffer. \fIexpand-history\fR and \fIexpand-line\fR expand history substitutions in the current word and in the entire input buffer respectively. .SS "Alias substitution" The shell maintains a list of aliases which can be set, unset and printed by the \fIalias\fR and \fIunalias\fR commands. After a command line is parsed into simple commands (see \fBCommands\fR) the first word of each command, left-to-right, is checked to see if it has an alias. If so, the first word is replaced by the alias. If the alias contains a history reference, it undergoes \fBHistory substitution\fR (q.v.) as though the original command were the previous input line. If the alias does not contain a history reference, the argument list is left untouched. .PP Thus if the alias for `ls' were `ls \-l' the command `ls /usr' would become `ls \-l /usr', the argument list here being undisturbed. If the alias for `lookup' were `grep !^ /etc/passwd' then `lookup bill' would become `grep bill /etc/passwd'. Aliases can be used to introduce parser metasyntax. For example, `alias print 'pr \e!* | lpr'' defines a ``command'' (`print') which \fIpr\fR(1)s its arguments to the line printer. .PP Alias substitution is repeated until the first word of the command has no alias. If an alias substitution does not change the first word (as in the previous example) it is flagged to prevent a loop. Other loops are detected and cause an error. .PP Some aliases are referred to by the shell; see \fBSpecial aliases\fR. .SS "Variable substitution" The shell maintains a list of variables, each of which has as value a list of zero or more words. The values of shell variables can be displayed and changed with the \fIset\fR and \fIunset\fR commands. The system maintains its own list of ``environment'' variables. These can be displayed and changed with \fIprintenv\fR, \fIsetenv\fR and \fIunsetenv\fR. .PP (+) Variables may be made read-only with `set \-r' (q.v.). Read-only variables may not be modified or unset; attempting to do so will cause an error. Once made read-only, a variable cannot be made writable, so `set \-r' should be used with caution. Environment variables cannot be made read-only. .PP Some variables are set by the shell or referred to by it. For instance, the \fBargv\fR variable is an image of the shell's argument list, and words of this variable's value are referred to in special ways. Some of the variables referred to by the shell are toggles; the shell does not care what their value is, only whether they are set or not. For instance, the \fBverbose\fR variable is a toggle which causes command input to be echoed. The \fB\-v\fR command line option sets this variable. \fBSpecial shell variables\fR lists all variables which are referred to by the shell. .PP Other operations treat variables numerically. The `@' command permits numeric calculations to be performed and the result assigned to a variable. Variable values are, however, always represented as (zero or more) strings. For the purposes of numeric operations, the null string is considered to be zero, and the second and subsequent words of multi-word values are ignored. .PP After the input line is aliased and parsed, and before each command is executed, variable substitution is performed keyed by `$' characters. This expansion can be prevented by preceding the `$' with a `\e' except within `"'s where it \fIalways\fR occurs, and within `''s where it \fInever\fR occurs. Strings quoted by `\`' are interpreted later (see \fBCommand substitution\fR below) so `$' substitution does not occur there until later, if at all. A `$' is passed unchanged if followed by a blank, tab, or end-of-line. .PP Input/output redirections are recognized before variable expansion, and are variable expanded separately. Otherwise, the command name and entire argument list are expanded together. It is thus possible for the first (command) word (to this point) to generate more than one word, the first of which becomes the command name, and the rest of which become arguments. .PP Unless enclosed in `"' or given the `:q' modifier the results of variable substitution may eventually be command and filename substituted. Within `"', a variable whose value consists of multiple words expands to a (portion of a) single word, with the words of the variable's value separated by blanks. When the `:q' modifier is applied to a substitution the variable will expand to multiple words with each word separated by a blank and quoted to prevent later command or filename substitution. .PP The following metasequences are provided for introducing variable values into the shell input. Except as noted, it is an error to reference a variable which is not set. .PP .PD 0 $\fIname\fR .TP 8 ${\fIname\fR} Substitutes the words of the value of variable \fIname\fR, each separated by a blank. Braces insulate \fIname\fR from following characters which would otherwise be part of it. Shell variables have names consisting of letters and digits starting with a letter. The underscore character is considered a letter. If \fIname\fR is not a shell variable, but is set in the environment, then that value is returned (but some of the other forms given below are not available in this case). .PP $\fIname\fR[\fIselector\fR] .TP 8 ${\fIname\fR[\fIselector\fR]} Substitutes only the selected words from the value of \fIname\fR. The \fIselector\fR is subjected to `$' substitution and may consist of a single number or two numbers separated by a `\-'. The first word of a variable's value is numbered `1'. If the first number of a range is omitted it defaults to `1'. If the last member of a range is omitted it defaults to `$#\fIname\fR'. The \fIselector\fR `*' selects all words. It is not an error for a range to be empty if the second argument is omitted or in range. .TP 8 $0 Substitutes the name of the file from which command input is being read. An error occurs if the name is not known. .PP $\fInumber\fR .TP 8 ${\fInumber\fR} Equivalent to `$argv[\fInumber\fR]'. .TP 8 $* Equivalent to `$argv', which is equivalent to `$argv[*]'. .PD .PP The `:' modifiers described under \fBHistory substitution\fR, except for `:p', can be applied to the substitutions above. More than one may be used. (+) Braces may be needed to insulate a variable substitution from a literal colon just as with \fBHistory substitution\fR (q.v.); any modifiers must appear within the braces. .PP The following substitutions can not be modified with `:' modifiers. .PP .PD 0 $?\fIname\fR .TP 8 ${?\fIname\fR} Substitutes the string `1' if \fIname\fR is set, `0' if it is not. .TP 8 $?0 Substitutes `1' if the current input filename is known, `0' if it is not. Always `0' in interactive shells. .PP $#\fIname\fR .TP 8 ${#\fIname\fR} Substitutes the number of words in \fIname\fR. .TP 8 $# Equivalent to `$#argv'. (+) .PP $%\fIname\fR .TP 8 ${%\fIname\fR} Substitutes the number of characters in \fIname\fR. (+) .PP $%\fInumber\fR .TP 8 ${%\fInumber\fR} Substitutes the number of characters in $argv[\fInumber\fR]. (+) .TP 8 $? Equivalent to `$status'. (+) .TP 8 $$ Substitutes the (decimal) process number of the (parent) shell. .TP 8 $! Substitutes the (decimal) process number of the last background process started by this shell. (+) .TP 8 $_ Substitutes the command line of the last command executed. (+) .TP 8 $< Substitutes a line from the standard input, with no further interpretation thereafter. It can be used to read from the keyboard in a shell script. (+) While \fIcsh\fR always quotes $<, as if it were equivalent to `$<:q', \fItcsh\fR does not. Furthermore, when \fItcsh\fR is waiting for a line to be typed the user may type an interrupt to interrupt the sequence into which the line is to be substituted, but \fIcsh\fR does not allow this. .PD .PP The editor command \fIexpand-variables\fR, normally bound to `^X-$', can be used to interactively expand individual variables. .SS "Command, filename and directory stack substitution" The remaining substitutions are applied selectively to the arguments of builtin commands. This means that portions of expressions which are not evaluated are not subjected to these expansions. For commands which are not internal to the shell, the command name is substituted separately from the argument list. This occurs very late, after input-output redirection is performed, and in a child of the main shell. .SS "Command substitution" Command substitution is indicated by a command enclosed in `\`'. The output from such a command is broken into separate words at blanks, tabs and newlines, and null words are discarded. The output is variable and command substituted and put in place of the original string. .PP Command substitutions inside double quotes (`"') retain blanks and tabs; only newlines force new words. The single final newline does not force a new word in any case. It is thus possible for a command substitution to yield only part of a word, even if the command outputs a complete line. .PP By default, the shell since version 6.12 replaces all newline and carriage return characters in the command by spaces. If this is switched off by unsetting \fBcsubstnonl\fR, newlines separate commands as usual. .SS "Filename substitution" If a word contains any of the characters `*', `?', `[' or `{' or begins with the character `~' it is a candidate for filename substitution, also known as ``globbing''. This word is then regarded as a pattern (``glob-pattern''), and replaced with an alphabetically sorted list of file names which match the pattern. .PP In matching filenames, the character `.' at the beginning of a filename or immediately following a `/', as well as the character `/' must be matched explicitly (unless either .B globdot or .B globstar or both are set(+)). The character `*' matches any string of characters, including the null string. The character `?' matches any single character. The sequence `[...]' matches any one of the characters enclosed. Within `[...]', a pair of characters separated by `\-' matches any character lexically between the two. .PP (+) Some glob-patterns can be negated: The sequence `[^...]' matches any single character \fInot\fR specified by the characters and/or ranges of characters in the braces. .PP An entire glob-pattern can also be negated with `^': .IP "" 4 > echo * .br bang crash crunch ouch .br > echo ^cr* .br bang ouch .PP Glob-patterns which do not use `?', `*', or `[]' or which use `{}' or `~' (below) are not negated correctly. .PP The metanotation `a{b,c,d}e' is a shorthand for `abe ace ade'. Left-to-right order is preserved: `/usr/source/s1/{oldls,ls}.c' expands to `/usr/source/s1/oldls.c /usr/source/s1/ls.c'. The results of matches are sorted separately at a low level to preserve this order: `../{memo,*box}' might expand to `../memo ../box ../mbox'. (Note that `memo' was not sorted with the results of matching `*box'.) It is not an error when this construct expands to files which do not exist, but it is possible to get an error from a command to which the expanded list is passed. This construct may be nested. As a special case the words `{', `}' and `{}' are passed undisturbed. .PP The character `~' at the beginning of a filename refers to home directories. Standing alone, i.e., `~', it expands to the invoker's home directory as reflected in the value of the \fBhome\fR shell variable. When followed by a name consisting of letters, digits and `\-' characters the shell searches for a user with that name and substitutes their home directory; thus `~ken' might expand to `/usr/ken' and `~ken/chmach' to `/usr/ken/chmach'. If the character `~' is followed by a character other than a letter or `/' or appears elsewhere than at the beginning of a word, it is left undisturbed. A command like `setenv MANPATH /usr/man:/usr/local/man:~/lib/man' does not, therefore, do home directory substitution as one might hope. .PP It is an error for a glob-pattern containing `*', `?', `[' or `~', with or without `^', not to match any files. However, only one pattern in a list of glob-patterns must match a file (so that, e.g., `rm *.a *.c *.o' would fail only if there were no files in the current directory ending in `.a', `.c', or `.o'), and if the \fBnonomatch\fR shell variable is set a pattern (or list of patterns) which matches nothing is left unchanged rather than causing an error. .PP The \fBglobstar\fR shell variable can be set to allow `**' or `***' as a file glob pattern that matches any string of characters including `/', recursively traversing any existing sub-directories. For example, `ls **.c' will list all the .c files in the current directory tree. If used by itself, it will match zero or more sub-directories (e.g. `ls /usr/include/**/time.h' will list any file named `time.h' in the /usr/include directory tree; `ls /usr/include/**time.h' will match any file in the /usr/include directory tree ending in `time.h'; and `ls /usr/include/**time**.h' will match any .h file with `time' either in a subdirectory name or in the filename itself). To prevent problems with recursion, the `**' glob-pattern will not descend into a symbolic link containing a directory. To override this, use `***' (+) .PP The \fBnoglob\fR shell variable can be set to prevent filename substitution, and the \fIexpand-glob\fR editor command, normally bound to `^X-*', can be used to interactively expand individual filename substitutions. .SS "Directory stack substitution (+)" The directory stack is a list of directories, numbered from zero, used by the \fIpushd\fR, \fIpopd\fR and \fIdirs\fR builtin commands (q.v.). \fIdirs\fR can print, store in a file, restore and clear the directory stack at any time, and the \fBsavedirs\fR and \fBdirsfile\fR shell variables can be set to store the directory stack automatically on logout and restore it on login. The \fBdirstack\fR shell variable can be examined to see the directory stack and set to put arbitrary directories into the directory stack. .PP The character `=' followed by one or more digits expands to an entry in the directory stack. The special case `=\-' expands to the last directory in the stack. For example, .IP "" 4 > dirs \-v .br 0 /usr/bin .br 1 /usr/spool/uucp .br 2 /usr/accts/sys .br > echo =1 .br /usr/spool/uucp .br > echo =0/calendar .br /usr/bin/calendar .br > echo =\- .br /usr/accts/sys .PP The \fBnoglob\fR and \fBnonomatch\fR shell variables and the \fIexpand-glob\fR editor command apply to directory stack as well as filename substitutions. .SS "Other substitutions (+)" There are several more transformations involving filenames, not strictly related to the above but mentioned here for completeness. \fIAny\fR filename may be expanded to a full path when the \fBsymlinks\fR variable (q.v.) is set to `expand'. Quoting prevents this expansion, and the \fInormalize-path\fR editor command does it on demand. The \fInormalize-command\fR editor command expands commands in PATH into full paths on demand. Finally, \fIcd\fR and \fIpushd\fR interpret `\-' as the old working directory (equivalent to the shell variable \fBowd\fR). This is not a substitution at all, but an abbreviation recognized by only those commands. Nonetheless, it too can be prevented by quoting. .SS Commands The next three sections describe how the shell executes commands and deals with their input and output. .SS Simple commands, pipelines and sequences A simple command is a sequence of words, the first of which specifies the command to be executed. A series of simple commands joined by `|' characters forms a pipeline. The output of each command in a pipeline is connected to the input of the next. .PP Simple commands and pipelines may be joined into sequences with `;', and will be executed sequentially. Commands and pipelines can also be joined into sequences with `||' or `&&', indicating, as in the C language, that the second is to be executed only if the first fails or succeeds respectively. .PP A simple command, pipeline or sequence may be placed in parentheses, `()', to form a simple command, which may in turn be a component of a pipeline or sequence. A command, pipeline or sequence can be executed without waiting for it to terminate by following it with an `&'. .SS "Builtin and non-builtin command execution" Builtin commands are executed within the shell. If any component of a pipeline except the last is a builtin command, the pipeline is executed in a subshell. .PP Parenthesized commands are always executed in a subshell. .IP "" 4 (cd; pwd); pwd .PP thus prints the \fBhome\fR directory, leaving you where you were (printing this after the home directory), while .IP "" 4 cd; pwd .PP leaves you in the \fBhome\fR directory. Parenthesized commands are most often used to prevent \fIcd\fR from affecting the current shell. .PP When a command to be executed is found not to be a builtin command the shell attempts to execute the command via \fIexecve\fR(2). Each word in the variable \fBpath\fR names a directory in which the shell will look for the command. If the shell is not given a \fB\-f\fR option, the shell hashes the names in these directories into an internal table so that it will try an \fIexecve\fR(2) in only a directory where there is a possibility that the command resides there. This greatly speeds command location when a large number of directories are present in the search path. This hashing mechanism is not used: .TP 4 .B 1. If hashing is turned explicitly off via \fIunhash\fR. .TP 4 .B 2. If the shell was given a \fB\-f\fR argument. .TP 4 .B 3. For each directory component of \fBpath\fR which does not begin with a `/'. .TP 4 .B 4. If the command contains a `/'. .PP In the above four cases the shell concatenates each component of the path vector with the given command name to form a path name of a file which it then attempts to execute it. If execution is successful, the search stops. .PP If the file has execute permissions but is not an executable to the system (i.e., it is neither an executable binary nor a script that specifies its interpreter), then it is assumed to be a file containing shell commands and a new shell is spawned to read it. The \fIshell\fR special alias may be set to specify an interpreter other than the shell itself. .PP On systems which do not understand the `#!' script interpreter convention the shell may be compiled to emulate it; see the \fBversion\fR shell variable. If so, the shell checks the first line of the file to see if it is of the form `#!\fIinterpreter\fR \fIarg\fR ...'. If it is, the shell starts \fIinterpreter\fR with the given \fIarg\fRs and feeds the file to it on standard input. .SS Input/output The standard input and standard output of a command may be redirected with the following syntax: .PP .PD 0 .TP 8 < \fIname Open file \fIname\fR (which is first variable, command and filename expanded) as the standard input. .TP 8 << \fIword Read the shell input up to a line which is identical to \fIword\fR. \fIword\fR is not subjected to variable, filename or command substitution, and each input line is compared to \fIword\fR before any substitutions are done on this input line. Unless a quoting `\e', `"', `' or `\`' appears in \fIword\fR variable and command substitution is performed on the intervening lines, allowing `\e' to quote `$', `\e' and `\`'. Commands which are substituted have all blanks, tabs, and newlines preserved, except for the final newline which is dropped. The resultant text is placed in an anonymous temporary file which is given to the command as standard input. .PP > \fIname .br >! \fIname .br >& \fIname .TP 8 >&! \fIname The file \fIname\fR is used as standard output. If the file does not exist then it is created; if the file exists, it is truncated, its previous contents being lost. .RS +8 .PD .PP If the shell variable \fBnoclobber\fR is set, then the file must not exist or be a character special file (e.g., a terminal or `/dev/null') or an error results. This helps prevent accidental destruction of files. In this case the `!' forms can be used to suppress this check. If \fBnotempty\fR is given in \fBnoclobber\fR, `>' is allowed on empty files; if \fBask\fR is set, an interacive confirmation is presented, rather than an error. .PP The forms involving `&' route the diagnostic output into the specified file as well as the standard output. \fIname\fR is expanded in the same way as `<' input filenames are. .PD 0 .RE .PP >> \fIname .br >>& \fIname .br >>! \fIname .TP 8 >>&! \fIname Like `>', but appends output to the end of \fIname\fR. If the shell variable \fBnoclobber\fR is set, then it is an error for the file \fInot\fR to exist, unless one of the `!' forms is given. .PD .PP A command receives the environment in which the shell was invoked as modified by the input-output parameters and the presence of the command in a pipeline. Thus, unlike some previous shells, commands run from a file of shell commands have no access to the text of the commands by default; rather they receive the original standard input of the shell. The `<<' mechanism should be used to present inline data. This permits shell command scripts to function as components of pipelines and allows the shell to block read its input. Note that the default standard input for a command run detached is \fInot\fR the empty file \fI/dev/null\fR, but the original standard input of the shell. If this is a terminal and if the process attempts to read from the terminal, then the process will block and the user will be notified (see \fBJobs\fR). .PP Diagnostic output may be directed through a pipe with the standard output. Simply use the form `|&' rather than just `|'. .PP The shell cannot presently redirect diagnostic output without also redirecting standard output, but `(\fIcommand\fR > \fIoutput-file\fR) >& \fIerror-file\fR' is often an acceptable workaround. Either \fIoutput-file\fR or \fIerror-file\fR may be `/dev/tty' to send output to the terminal. .SS Features Having described how the shell accepts, parses and executes command lines, we now turn to a variety of its useful features. .SS "Control flow" The shell contains a number of commands which can be used to regulate the flow of control in command files (shell scripts) and (in limited but useful ways) from terminal input. These commands all operate by forcing the shell to reread or skip in its input and, due to the implementation, restrict the placement of some of the commands. .PP The \fIforeach\fR, \fIswitch\fR, and \fIwhile\fR statements, as well as the \fIif-then-else\fR form of the \fIif\fR statement, require that the major keywords appear in a single simple command on an input line as shown below. .PP If the shell's input is not seekable, the shell buffers up input whenever a loop is being read and performs seeks in this internal buffer to accomplish the rereading implied by the loop. (To the extent that this allows, backward \fIgoto\fRs will succeed on non-seekable inputs.) .SS Expressions The \fIif\fR, \fIwhile\fR and \fIexit\fR builtin commands use expressions with a common syntax. The expressions can include any of the operators described in the next three sections. Note that the \fI@\fR builtin command (q.v.) has its own separate syntax. .SS "Logical, arithmetical and comparison operators" These operators are similar to those of C and have the same precedence. They include .IP "" 4 || && | ^ & == != =~ !~ <= >= .br < > << >> + \- * / % ! ~ ( ) .PP Here the precedence increases to the right, `==' `!=' `=~' and `!~', `<=' `>=' `<' and `>', `<<' and `>>', `+' and `\-', `*' `/' and `%' being, in groups, at the same level. The `==' `!=' `=~' and `!~' operators compare their arguments as strings; all others operate on numbers. The operators `=~' and `!~' are like `!=' and `==' except that the right hand side is a glob-pattern (see \fBFilename substitution\fR) against which the left hand operand is matched. This reduces the need for use of the \fIswitch\fR builtin command in shell scripts when all that is really needed is pattern matching. .PP Null or missing arguments are considered `0'. The results of all expressions are strings, which represent decimal numbers. It is important to note that no two components of an expression can appear in the same word; except when adjacent to components of expressions which are syntactically significant to the parser (`&' `|' `<' `>' `(' `)') they should be surrounded by spaces. .SS "Command exit status" Commands can be executed in expressions and their exit status returned by enclosing them in braces (`{}'). Remember that the braces should be separated from the words of the command by spaces. Command executions succeed, returning true, i.e., `1', if the command exits with status 0, otherwise they fail, returning false, i.e., `0'. If more detailed status information is required then the command should be executed outside of an expression and the \fBstatus\fR shell variable examined. .SS "File inquiry operators" Some of these operators perform true/false tests on files and related objects. They are of the form \fB\-\fIop file\fR, where \fIop\fR is one of .PP .PD 0 .RS +4 .TP 4 .B r Read access .TP 4 .B w Write access .TP 4 .B x Execute access .TP 4 .B X Executable in the path or shell builtin, e.g., `\-X ls' and `\-X ls\-F' are generally true, but `\-X /bin/ls' is not (+) .TP 4 .B e Existence .TP 4 .B o Ownership .TP 4 .B z Zero size .TP 4 .B s Non-zero size (+) .TP 4 .B f Plain file .TP 4 .B d Directory .TP 4 .B l Symbolic link (+) * .TP 4 .B b Block special file (+) .TP 4 .B c Character special file (+) .TP 4 .B p Named pipe (fifo) (+) * .TP 4 .B S Socket special file (+) * .TP 4 .B u Set-user-ID bit is set (+) .TP 4 .B g Set-group-ID bit is set (+) .TP 4 .B k Sticky bit is set (+) .TP 4 .B t \fIfile\fR (which must be a digit) is an open file descriptor for a terminal device (+) .TP 4 .B R Has been migrated (Convex only) (+) .TP 4 .B L Applies subsequent operators in a multiple-operator test to a symbolic link rather than to the file to which the link points (+) * .RE .PD .PP \fIfile\fR is command and filename expanded and then tested to see if it has the specified relationship to the real user. If \fIfile\fR does not exist or is inaccessible or, for the operators indicated by `*', if the specified file type does not exist on the current system, then all inquiries return false, i.e., `0'. .PP These operators may be combined for conciseness: `\-\fIxy file\fR' is equivalent to `\-\fIx file\fR && \-\fIy file\fR'. (+) For example, `\-fx' is true (returns `1') for plain executable files, but not for directories. .PP \fBL\fR may be used in a multiple-operator test to apply subsequent operators to a symbolic link rather than to the file to which the link points. For example, `\-lLo' is true for links owned by the invoking user. \fBLr\fR, \fBLw\fR and \fBLx\fR are always true for links and false for non-links. \fBL\fR has a different meaning when it is the last operator in a multiple-operator test; see below. .PP It is possible but not useful, and sometimes misleading, to combine operators which expect \fIfile\fR to be a file with operators which do not (e.g., \fBX\fR and \fBt\fR). Following \fBL\fR with a non-file operator can lead to particularly strange results. .PP Other operators return other information, i.e., not just `0' or `1'. (+) They have the same format as before; \fIop\fR may be one of .PP .PD 0 .RS +4 .TP 8 .B A Last file access time, as the number of seconds since the epoch .TP 8 .B A: Like \fBA\fR, but in timestamp format, e.g., `Fri May 14 16:36:10 1993' .TP 8 .B M Last file modification time .TP 8 .B M: Like \fBM\fR, but in timestamp format .TP 8 .B C Last inode modification time .TP 8 .B C: Like \fBC\fR, but in timestamp format .TP 8 .B D Device number .TP 8 .B I Inode number .TP 8 .B F Composite \fBf\fRile identifier, in the form \fIdevice\fR:\fIinode\fR .TP 8 .B L The name of the file pointed to by a symbolic link .TP 8 .B N Number of (hard) links .TP 8 .B P Permissions, in octal, without leading zero .TP 8 .B P: Like \fBP\fR, with leading zero .TP 8 .B P\fImode Equivalent to `\-P \fIfile\fR & \fImode\fR', e.g., `\-P22 \fIfile\fR' returns `22' if \fIfile\fR is writable by group and other, `20' if by group only, and `0' if by neither .TP 8 .B P\fImode\fB: Like \fBP\fImode\fR, with leading zero .TP 8 .B U Numeric userid .TP 8 .B U: Username, or the numeric userid if the username is unknown .TP 8 .B G Numeric groupid .TP 8 .B G: Groupname, or the numeric groupid if the groupname is unknown .TP 8 .B Z Size, in bytes .RE .PD .PP Only one of these operators may appear in a multiple-operator test, and it must be the last. Note that \fBL\fR has a different meaning at the end of and elsewhere in a multiple-operator test. Because `0' is a valid return value for many of these operators, they do not return `0' when they fail: most return `\-1', and \fBF\fR returns `:'. .PP If the shell is compiled with POSIX defined (see the \fBversion\fR shell variable), the result of a file inquiry is based on the permission bits of the file and not on the result of the \fIaccess\fR(2) system call. For example, if one tests a file with \fB\-w\fR whose permissions would ordinarily allow writing but which is on a file system mounted read-only, the test will succeed in a POSIX shell but fail in a non-POSIX shell. .PP File inquiry operators can also be evaluated with the \fIfiletest\fR builtin command (q.v.) (+). .SS Jobs The shell associates a \fIjob\fR with each pipeline. It keeps a table of current jobs, printed by the \fIjobs\fR command, and assigns them small integer numbers. When a job is started asynchronously with `&', the shell prints a line which looks like .IP "" 4 [1] 1234 .PP indicating that the job which was started asynchronously was job number 1 and had one (top-level) process, whose process id was 1234. .PP If you are running a job and wish to do something else you may hit the suspend key (usually `^Z'), which sends a STOP signal to the current job. The shell will then normally indicate that the job has been `Suspended' and print another prompt. If the \fBlistjobs\fR shell variable is set, all jobs will be listed like the \fIjobs\fR builtin command; if it is set to `long' the listing will be in long format, like `jobs \-l'. You can then manipulate the state of the suspended job. You can put it in the ``background'' with the \fIbg\fR command or run some other commands and eventually bring the job back into the ``foreground'' with \fIfg\fR. (See also the \fIrun-fg-editor\fR editor command.) A `^Z' takes effect immediately and is like an interrupt in that pending output and unread input are discarded when it is typed. The \fIwait\fR builtin command causes the shell to wait for all background jobs to complete. .PP The `^]' key sends a delayed suspend signal, which does not generate a STOP signal until a program attempts to \fIread\fR(2) it, to the current job. This can usefully be typed ahead when you have prepared some commands for a job which you wish to stop after it has read them. The `^Y' key performs this function in \fIcsh\fR(1); in \fItcsh\fR, `^Y' is an editing command. (+) .PP A job being run in the background stops if it tries to read from the terminal. Background jobs are normally allowed to produce output, but this can be disabled by giving the command `stty tostop'. If you set this tty option, then background jobs will stop when they try to produce output like they do when they try to read input. .PP There are several ways to refer to jobs in the shell. The character `%' introduces a job name. If you wish to refer to job number 1, you can name it as `%1'. Just naming a job brings it to the foreground; thus `%1' is a synonym for `fg %1', bringing job 1 back into the foreground. Similarly, saying `%1 &' resumes job 1 in the background, just like `bg %1'. A job can also be named by an unambiguous prefix of the string typed in to start it: `%ex' would normally restart a suspended \fIex\fR(1) job, if there were only one suspended job whose name began with the string `ex'. It is also possible to say `%?\fIstring\fR' to specify a job whose text contains \fIstring\fR, if there is only one such job. .PP The shell maintains a notion of the current and previous jobs. In output pertaining to jobs, the current job is marked with a `+' and the previous job with a `\-'. The abbreviations `%+', `%', and (by analogy with the syntax of the \fIhistory\fR mechanism) `%%' all refer to the current job, and `%\-' refers to the previous job. .PP The job control mechanism requires that the \fIstty\fR(1) option `new' be set on some systems. It is an artifact from a `new' implementation of the tty driver which allows generation of interrupt characters from the keyboard to tell jobs to stop. See \fIstty\fR(1) and the \fIsetty\fR builtin command for details on setting options in the new tty driver. .SS "Status reporting" The shell learns immediately whenever a process changes state. It normally informs you whenever a job becomes blocked so that no further progress is possible, but only right before it prints a prompt. This is done so that it does not otherwise disturb your work. If, however, you set the shell variable \fBnotify\fR, the shell will notify you immediately of changes of status in background jobs. There is also a shell command \fInotify\fR which marks a single process so that its status changes will be immediately reported. By default \fInotify\fR marks the current process; simply say `notify' after starting a background job to mark it. .PP When you try to leave the shell while jobs are stopped, you will be warned that `There are suspended jobs.' You may use the \fIjobs\fR command to see what they are. If you do this or immediately try to exit again, the shell will not warn you a second time, and the suspended jobs will be terminated. .SS "Automatic, periodic and timed events (+)" There are various ways to run commands and take other actions automatically at various times in the ``life cycle'' of the shell. They are summarized here, and described in detail under the appropriate \fBBuiltin commands\fR, \fBSpecial shell variables\fR and \fBSpecial aliases\fR. .PP The \fIsched\fR builtin command puts commands in a scheduled-event list, to be executed by the shell at a given time. .PP The \fIbeepcmd\fR, \fIcwdcmd\fR, \fIperiodic\fR, \fIprecmd\fR, \fIpostcmd\fR, and \fIjobcmd\fR \fBSpecial aliases\fR can be set, respectively, to execute commands when the shell wants to ring the bell, when the working directory changes, every \fBtperiod\fR minutes, before each prompt, before each command gets executed, after each command gets executed, and when a job is started or is brought into the foreground. .PP The \fBautologout\fR shell variable can be set to log out or lock the shell after a given number of minutes of inactivity. .PP The \fBmail\fR shell variable can be set to check for new mail periodically. .PP The \fBprintexitvalue\fR shell variable can be set to print the exit status of commands which exit with a status other than zero. .PP The \fBrmstar\fR shell variable can be set to ask the user, when `rm *' is typed, if that is really what was meant. .PP The \fBtime\fR shell variable can be set to execute the \fItime\fR builtin command after the completion of any process that takes more than a given number of CPU seconds. .PP The \fBwatch\fR and \fBwho\fR shell variables can be set to report when selected users log in or out, and the \fIlog\fR builtin command reports on those users at any time. .SS "Native Language System support (+)" The shell is eight bit clean (if so compiled; see the \fBversion\fR shell variable) and thus supports character sets needing this capability. NLS support differs depending on whether or not the shell was compiled to use the system's NLS (again, see \fBversion\fR). In either case, 7-bit ASCII is the default character code (e.g., the classification of which characters are printable) and sorting, and changing the \fBLANG\fR or \fBLC_CTYPE\fR environment variables causes a check for possible changes in these respects. .PP When using the system's NLS, the \fIsetlocale\fR(3) function is called to determine appropriate character code/classification and sorting (e.g., a 'en_CA.UTF-8' would yield "UTF-8" as a character code). This function typically examines the \fBLANG\fR and \fBLC_CTYPE\fR environment variables; refer to the system documentation for further details. When not using the system's NLS, the shell simulates it by assuming that the ISO 8859-1 character set is used whenever either of the \fBLANG\fR and \fBLC_CTYPE\fR variables are set, regardless of their values. Sorting is not affected for the simulated NLS. .PP In addition, with both real and simulated NLS, all printable characters in the range \e200\-\e377, i.e., those that have M-\fIchar\fR bindings, are automatically rebound to \fIself-insert-command\fR. The corresponding binding for the escape-\fIchar\fR sequence, if any, is left alone. These characters are not rebound if the \fBNOREBIND\fR environment variable is set. This may be useful for the simulated NLS or a primitive real NLS which assumes full ISO 8859-1. Otherwise, all M-\fIchar\fR bindings in the range \e240\-\e377 are effectively undone. Explicitly rebinding the relevant keys with \fIbindkey\fR is of course still possible. .PP Unknown characters (i.e., those that are neither printable nor control characters) are printed in the format \ennn. If the tty is not in 8 bit mode, other 8 bit characters are printed by converting them to ASCII and using standout mode. The shell never changes the 7/8 bit mode of the tty and tracks user-initiated changes of 7/8 bit mode. NLS users (or, for that matter, those who want to use a meta key) may need to explicitly set the tty in 8 bit mode through the appropriate \fIstty\fR(1) command in, e.g., the \fI~/.login\fR file. .SS "OS variant support (+)" A number of new builtin commands are provided to support features in particular operating systems. All are described in detail in the \fBBuiltin commands\fR section. .PP On systems that support TCF (aix-ibm370, aix-ps2), \fIgetspath\fR and \fIsetspath\fR get and set the system execution path, \fIgetxvers\fR and \fIsetxvers\fR get and set the experimental version prefix and \fImigrate\fR migrates processes between sites. The \fIjobs\fR builtin prints the site on which each job is executing. .PP Under BS2000, \fIbs2cmd\fR executes commands of the underlying BS2000/OSD operating system. .PP Under Domain/OS, \fIinlib\fR adds shared libraries to the current environment, \fIrootnode\fR changes the rootnode and \fIver\fR changes the systype. .PP Under Mach, \fIsetpath\fR is equivalent to Mach's \fIsetpath\fR(1). .PP Under Masscomp/RTU and Harris CX/UX, \fIuniverse\fR sets the universe. .PP Under Harris CX/UX, \fIucb\fR or \fIatt\fR runs a command under the specified universe. .PP Under Convex/OS, \fIwarp\fR prints or sets the universe. .PP The \fBVENDOR\fR, \fBOSTYPE\fR and \fBMACHTYPE\fR environment variables indicate respectively the vendor, operating system and machine type (microprocessor class or machine model) of the system on which the shell thinks it is running. These are particularly useful when sharing one's home directory between several types of machines; one can, for example, .IP "" 4 set path = (~/bin.$MACHTYPE /usr/ucb /bin /usr/bin .) .PP in one's \fI~/.login\fR and put executables compiled for each machine in the appropriate directory. .PP The \fBversion\fR shell variable indicates what options were chosen when the shell was compiled. .PP Note also the \fInewgrp\fR builtin, the \fBafsuser\fR and \fBecho_style\fR shell variables and the system-dependent locations of the shell's input files (see \fBFILES\fR). .SS "Signal handling" Login shells ignore interrupts when reading the file \fI~/.logout\fR. The shell ignores quit signals unless started with \fB\-q\fR. Login shells catch the terminate signal, but non-login shells inherit the terminate behavior from their parents. Other signals have the values which the shell inherited from its parent. .PP In shell scripts, the shell's handling of interrupt and terminate signals can be controlled with \fIonintr\fR, and its handling of hangups can be controlled with \fIhup\fR and \fInohup\fR. .PP The shell exits on a hangup (see also the \fBlogout\fR shell variable). By default, the shell's children do too, but the shell does not send them a hangup when it exits. \fIhup\fR arranges for the shell to send a hangup to a child when it exits, and \fInohup\fR sets a child to ignore hangups. .SS "Terminal management (+)" The shell uses three different sets of terminal (``tty'') modes: `edit', used when editing, `quote', used when quoting literal characters, and `execute', used when executing commands. The shell holds some settings in each mode constant, so commands which leave the tty in a confused state do not interfere with the shell. The shell also matches changes in the speed and padding of the tty. The list of tty modes that are kept constant can be examined and modified with the \fIsetty\fR builtin. Note that although the editor uses CBREAK mode (or its equivalent), it takes typed-ahead characters anyway. .PP The \fIechotc\fR, \fIsettc\fR and \fItelltc\fR commands can be used to manipulate and debug terminal capabilities from the command line. .PP On systems that support SIGWINCH or SIGWINDOW, the shell adapts to window resizing automatically and adjusts the environment variables \fBLINES\fR and \fBCOLUMNS\fR if set. If the environment variable \fBTERMCAP\fR contains li# and co# fields, the shell adjusts them to reflect the new window size. .SH REFERENCE The next sections of this manual describe all of the available \fBBuiltin commands\fR, \fBSpecial aliases\fR and \fBSpecial shell variables\fR. .SS "Builtin commands" .TP 8 .B %\fIjob A synonym for the \fIfg\fR builtin command. .TP 8 .B %\fIjob \fB& A synonym for the \fIbg\fR builtin command. .TP 8 .B : Does nothing, successfully. .PP .B @ .br .B @ \fIname\fB = \fIexpr .br .B @ \fIname\fR[\fIindex\fR]\fB = \fIexpr .br .B @ \fIname\fB++\fR|\fB-- .PD 0 .TP 8 .B @ \fIname\fR[\fIindex\fR]\fB++\fR|\fB-- The first form prints the values of all shell variables. .PD .RS +8 .PP The second form assigns the value of \fIexpr\fR to \fIname\fR. The third form assigns the value of \fIexpr\fR to the \fIindex\fR'th component of \fIname\fR; both \fIname\fR and its \fIindex\fR'th component must already exist. .PP \fIexpr\fR may contain the operators `*', `+', etc., as in C. If \fIexpr\fR contains `<', `>', `&' or `' then at least that part of \fIexpr\fR must be placed within `()'. Note that the syntax of \fIexpr\fR has nothing to do with that described under \fBExpressions\fR. .PP The fourth and fifth forms increment (`++') or decrement (`\-\-') \fIname\fR or its \fIindex\fR'th component. .PP The space between `@' and \fIname\fR is required. The spaces between \fIname\fR and `=' and between `=' and \fIexpr\fR are optional. Components of \fIexpr\fR must be separated by spaces. .RE .PD .TP 8 .B alias \fR[\fIname \fR[\fIwordlist\fR]] Without arguments, prints all aliases. With \fIname\fR, prints the alias for name. With \fIname\fR and \fIwordlist\fR, assigns \fIwordlist\fR as the alias of \fIname\fR. \fIwordlist\fR is command and filename substituted. \fIname\fR may not be `alias' or `unalias'. See also the \fIunalias\fR builtin command. .TP 8 .B alloc Shows the amount of dynamic memory acquired, broken down into used and free memory. With an argument shows the number of free and used blocks in each size category. The categories start at size 8 and double at each step. This command's output may vary across system types, because systems other than the VAX may use a different memory allocator. .TP 8 .B bg \fR[\fB%\fIjob\fR ...] Puts the specified jobs (or, without arguments, the current job) into the background, continuing each if it is stopped. \fIjob\fR may be a number, a string, `', `%', `+' or `\-' as described under \fBJobs\fR. .PP .B bindkey \fR[\fB\-l\fR|\fB\-d\fR|\fB\-e\fR|\fB\-v\fR|\fB\-u\fR] (+) .br \fBbindkey \fR[\fB\-a\fR] [\fB\-b\fR] [\fB\-k\fR] [\fB\-r\fR] [\fB\-\-\fR] \fIkey \fR(+) .PD 0 .TP 8 \fBbindkey \fR[\fB\-a\fR] [\fB\-b\fR] [\fB\-k\fR] [\fB\-c\fR|\fB\-s\fR] [\fB\-\-\fR] \fIkey command \fR(+) .\" .B macro can't take too many words, so I used \fB in the previous tags Without options, the first form lists all bound keys and the editor command to which each is bound, the second form lists the editor command to which \fIkey\fR is bound and the third form binds the editor command \fIcommand\fR to \fIkey\fR. Options include: .PD .PP .PD 0 .RS +8 .TP 4 .B \-l Lists all editor commands and a short description of each. .TP 4 .B \-d Binds all keys to the standard bindings for the default editor, as per \fB-e\fR and \fB-v\fR below. .TP 4 .B \-e Binds all keys to \fIemacs\fR(1)\-style bindings. Unsets \fBvimode\fR. .TP 4 .B \-v Binds all keys to \fIvi\fR(1)\-style bindings. Sets \fBvimode\fR. .TP 4 .B \-a Lists or changes key-bindings in the alternative key map. This is the key map used in \fBvimode\fR command mode. .TP 4 .B \-b \fIkey\fR is interpreted as a control character written ^\fIcharacter\fR (e.g., `^A') or C-\fIcharacter\fR (e.g., `C-A'), a meta character written M-\fIcharacter\fR (e.g., `M-A'), a function key written F-\fIstring\fR (e.g., `F-string'), or an extended prefix key written X-\fIcharacter\fR (e.g., `X-A'). .TP 4 .B \-k \fIkey\fR is interpreted as a symbolic arrow key name, which may be one of `down', `up', `left' or `right'. .TP 4 .B \-r Removes \fIkey\fR's binding. Be careful: `bindkey \-r' does \fInot\fR bind \fIkey\fR to \fIself-insert-command\fR (q.v.), it unbinds \fIkey\fR completely. .TP 4 .B \-c \fIcommand\fR is interpreted as a builtin or external command instead of an editor command. .TP 4 .B \-s \fIcommand\fR is taken as a literal string and treated as terminal input when \fIkey\fR is typed. Bound keys in \fIcommand\fR are themselves reinterpreted, and this continues for ten levels of interpretation. .TP 4 .B \-\- Forces a break from option processing, so the next word is taken as \fIkey\fR even if it begins with '\-'. .TP 4 .B \-u \fR(or any invalid option) Prints a usage message. .PD .PP \fIkey\fR may be a single character or a string. If a command is bound to a string, the first character of the string is bound to \fIsequence-lead-in\fR and the entire string is bound to the command. .PP Control characters in \fIkey\fR can be literal (they can be typed by preceding them with the editor command \fIquoted-insert\fR, normally bound to `^V') or written caret-character style, e.g., `^A'. Delete is written `^?' (caret-question mark). \fIkey\fR and \fIcommand\fR can contain backslashed escape sequences (in the style of System V \fIecho\fR(1)) as follows: .RS +4 .TP 8 .PD 0 .B \ea Bell .TP 8 .B \eb Backspace .TP 8 .B \ee Escape .TP 8 .B \ef Form feed .TP 8 .B \en Newline .TP 8 .B \er Carriage return .TP 8 .B \et Horizontal tab .TP 8 .B \ev Vertical tab .TP 8 .B \e\fInnn The ASCII character corresponding to the octal number \fInnn\fR .PD .RE .PP `\e' nullifies the special meaning of the following character, if it has any, notably `\e' and `^'. .RE .TP 8 .B bs2cmd \fIbs2000-command\fR (+) Passes \fIbs2000-command\fR to the BS2000 command interpreter for execution. Only non-interactive commands can be executed, and it is not possible to execute any command that would overlay the image of the current process, like /EXECUTE or /CALL-PROCEDURE. (BS2000 only) .TP 8 .B break Causes execution to resume after the \fIend\fR of the nearest enclosing \fIforeach\fR or \fIwhile\fR. The remaining commands on the current line are executed. Multi-level breaks are thus possible by writing them all on one line. .TP 8 .B breaksw Causes a break from a \fIswitch\fR, resuming after the \fIendsw\fR. .TP 8 .B builtins \fR(+) Prints the names of all builtin commands. .TP 8 .B bye \fR(+) A synonym for the \fIlogout\fR builtin command. Available only if the shell was so compiled; see the \fBversion\fR shell variable. .TP 8 .B case \fIlabel\fB: A label in a \fIswitch\fR statement as discussed below. .TP 8 .B cd \fR[\fB\-p\fR] [\fB\-l\fR] [\fB\-n\fR|\fB\-v\fR] [\I--\fR] [\fIname\fR] If a directory \fIname\fR is given, changes the shell's working directory to \fIname\fR. If not, changes to \fBhome\fR, unless the \fBcdtohome\fR variable is not set, in which case a \fIname\fR is required. If \fIname\fR is `\-' it is interpreted as the previous working directory (see \fBOther substitutions\fR). (+) If \fIname\fR is not a subdirectory of the current directory (and does not begin with `/', `./' or `../'), each component of the variable \fBcdpath\fR is checked to see if it has a subdirectory \fIname\fR. Finally, if all else fails but \fIname\fR is a shell variable whose value begins with `/' or '.', then this is tried to see if it is a directory, and the \fB\-p\fR option is implied. .RS +8 .PP With \fB\-p\fR, prints the final directory stack, just like \fIdirs\fR. The \fB\-l\fR, \fB\-n\fR and \fB\-v\fR flags have the same effect on \fIcd\fR as on \fIdirs\fR, and they imply \fB\-p\fR. (+) Using \fB\-\-\fR forces a break from option processing so the next word is taken as the directory \fIname\fR even if it begins with '\-'. (+) .PP See also the \fBimplicitcd\fR and \fBcdtohome\fR shell variables. .RE .TP 8 .B chdir A synonym for the \fIcd\fR builtin command. .TP 8 .B complete \fR[\fIcommand\fR [\fIword\fB/\fIpattern\fB/\fIlist\fR[\fB:\fIselect\fR]\fB/\fR[[\fIsuffix\fR]\fB/\fR] ...]] (+) Without arguments, lists all completions. With \fIcommand\fR, lists completions for \fIcommand\fR. With \fIcommand\fR and \fIword\fR etc., defines completions. .RS +8 .PP \fIcommand\fR may be a full command name or a glob-pattern (see \fBFilename substitution\fR). It can begin with `\-' to indicate that completion should be used only when \fIcommand\fR is ambiguous. .PP \fIword\fR specifies which word relative to the current word is to be completed, and may be one of the following: .PP .PD 0 .RS +4 .TP 4 .B c Current-word completion. \fIpattern\fR is a glob-pattern which must match the beginning of the current word on the command line. \fIpattern\fR is ignored when completing the current word. .TP 4 .B C Like \fBc\fR, but includes \fIpattern\fR when completing the current word. .TP 4 .B n Next-word completion. \fIpattern\fR is a glob-pattern which must match the beginning of the previous word on the command line. .TP 4 .B N Like \fBn\fR, but must match the beginning of the word two before the current word. .TP 4 .B p Position-dependent completion. \fIpattern\fR is a numeric range, with the same syntax used to index shell variables, which must include the current word. .PD .RE .PP \fIlist\fR, the list of possible completions, may be one of the following: .PP .PD 0 .RS +4 .TP 8 .B a Aliases .TP 8 .B b Bindings (editor commands) .TP 8 .B c Commands (builtin or external commands) .TP 8 .B C External commands which begin with the supplied path prefix .TP 8 .B d Directories .TP 8 .B D Directories which begin with the supplied path prefix .TP 8 .B e Environment variables .TP 8 .B f Filenames .TP 8 .B F Filenames which begin with the supplied path prefix .TP 8 .B g Groupnames .TP 8 .B j Jobs .TP 8 .B l Limits .TP 8 .B n Nothing .TP 8 .B s Shell variables .TP 8 .B S Signals .TP 8 .B t Plain (``text'') files .TP 8 .B T Plain (``text'') files which begin with the supplied path prefix .TP 8 .B v Any variables .TP 8 .B u Usernames .TP 8 .B x Like \fBn\fR, but prints \fIselect\fR when \fIlist-choices\fR is used. .TP 8 .B X Completions .TP 8 $\fIvar\fR Words from the variable \fIvar\fR .TP 8 (...) Words from the given list .TP 8 \`...\` Words from the output of command .PD .RE .PP \fIselect\fR is an optional glob-pattern. If given, words from only \fIlist\fR that match \fIselect\fR are considered and the \fBfignore\fR shell variable is ignored. The last three types of completion may not have a \fIselect\fR pattern, and \fBx\fR uses \fIselect\fR as an explanatory message when the \fIlist-choices\fR editor command is used. .PP \fIsuffix\fR is a single character to be appended to a successful completion. If null, no character is appended. If omitted (in which case the fourth delimiter can also be omitted), a slash is appended to directories and a space to other words. .PP \fIcommand\fR invoked from \`...\` version has additional environment variable set, the variable name is \%\fBCOMMAND_LINE\fR\% and contains (as its name indicates) contents of the current (already typed in) command line. One can examine and use contents of the \%\fBCOMMAND_LINE\fR\% variable in her custom script to build more sophisticated completions (see completion for svn(1) included in this package). .PP Now for some examples. Some commands take only directories as arguments, so there's no point completing plain files. .IP "" 4 > complete cd 'p/1/d/' .PP completes only the first word following `cd' (`p/1') with a directory. \fBp\fR-type completion can also be used to narrow down command completion: .IP "" 4 > co[^D] .br complete compress .br > complete \-co* 'p/0/(compress)/' .br > co[^D] .br > compress .PP This completion completes commands (words in position 0, `p/0') which begin with `co' (thus matching `co*') to `compress' (the only word in the list). The leading `\-' indicates that this completion is to be used with only ambiguous commands. .IP "" 4 > complete find 'n/\-user/u/' .PP is an example of \fBn\fR-type completion. Any word following `find' and immediately following `\-user' is completed from the list of users. .IP "" 4 > complete cc 'c/\-I/d/' .PP demonstrates \fBc\fR-type completion. Any word following `cc' and beginning with `\-I' is completed as a directory. `\-I' is not taken as part of the directory because we used lowercase \fBc\fR. .PP Different \fIlist\fRs are useful with different commands. .IP "" 4 > complete alias 'p/1/a/' .br > complete man 'p/*/c/' .br > complete set 'p/1/s/' .br > complete true 'p/1/x:Truth has no options./' .PP These complete words following `alias' with aliases, `man' with commands, and `set' with shell variables. `true' doesn't have any options, so \fBx\fR does nothing when completion is attempted and prints `Truth has no options.' when completion choices are listed. .PP Note that the \fIman\fR example, and several other examples below, could just as well have used 'c/*' or 'n/*' as 'p/*'. .PP Words can be completed from a variable evaluated at completion time, .IP "" 4 > complete ftp 'p/1/$hostnames/' .br > set hostnames = (rtfm.mit.edu tesla.ee.cornell.edu) .br > ftp [^D] .br rtfm.mit.edu tesla.ee.cornell.edu .br > ftp [^C] .br > set hostnames = (rtfm.mit.edu tesla.ee.cornell.edu uunet.uu.net) .br > ftp [^D] .br rtfm.mit.edu tesla.ee.cornell.edu uunet.uu.net .PP or from a command run at completion time: .IP "" 4 > complete kill 'p/*/\`ps | awk \e{print\e \e$1\e}\`/' .br > kill \-9 [^D] .br 23113 23377 23380 23406 23429 23529 23530 PID .PP Note that the \fIcomplete\fR command does not itself quote its arguments, so the braces, space and `$' in `{print $1}' must be quoted explicitly. .PP One command can have multiple completions: .IP "" 4 > complete dbx 'p/2/(core)/' 'p/*/c/' .PP completes the second argument to `dbx' with the word `core' and all other arguments with commands. Note that the positional completion is specified before the next-word completion. Because completions are evaluated from left to right, if the next-word completion were specified first it would always match and the positional completion would never be executed. This is a common mistake when defining a completion. .PP The \fIselect\fR pattern is useful when a command takes files with only particular forms as arguments. For example, .IP "" 4 > complete cc 'p/*/f:*.[cao]/' .PP completes `cc' arguments to files ending in only `.c', `.a', or `.o'. \fIselect\fR can also exclude files, using negation of a glob-pattern as described under \fBFilename substitution\fR. One might use .IP "" 4 > complete rm 'p/*/f:^*.{c,h,cc,C,tex,1,man,l,y}/' .PP to exclude precious source code from `rm' completion. Of course, one could still type excluded names manually or override the completion mechanism using the \fIcomplete-word-raw\fR or \fIlist-choices-raw\fR editor commands (q.v.). .PP The `C', `D', `F' and `T' \fIlist\fRs are like `c', `d', `f' and `t' respectively, but they use the \fIselect\fR argument in a different way: to restrict completion to files beginning with a particular path prefix. For example, the Elm mail program uses `=' as an abbreviation for one's mail directory. One might use .IP "" 4 > complete elm c@=@F:$HOME/Mail/@ .PP to complete `elm \-f =' as if it were `elm \-f ~/Mail/'. Note that we used `@' instead of `/' to avoid confusion with the \fIselect\fR argument, and we used `$HOME' instead of `~' because home directory substitution works at only the beginning of a word. .PP \fIsuffix\fR is used to add a nonstandard suffix (not space or `/' for directories) to completed words. .IP "" 4 > complete finger 'c/*@/$hostnames/' 'p/1/u/@' .PP completes arguments to `finger' from the list of users, appends an `@', and then completes after the `@' from the `hostnames' variable. Note again the order in which the completions are specified. .PP Finally, here's a complex example for inspiration: .IP "" 4 > complete find \e .br \&'n/\-name/f/' 'n/\-newer/f/' 'n/\-{,n}cpio/f/' \e .br \&\'n/\-exec/c/' 'n/\-ok/c/' 'n/\-user/u/' \e .br \&'n/\-group/g/' 'n/\-fstype/(nfs 4.2)/' \e .br \&'n/\-type/(b c d f l p s)/' \e .br \'c/\-/(name newer cpio ncpio exec ok user \e .br group fstype type atime ctime depth inum \e .br ls mtime nogroup nouser perm print prune \e .br size xdev)/' \e .br \&'p/*/d/' .PP This completes words following `\-name', `\-newer', `\-cpio' or `ncpio' (note the pattern which matches both) to files, words following `\-exec' or `\-ok' to commands, words following `user' and `group' to users and groups respectively and words following `\-fstype' or `\-type' to members of the given lists. It also completes the switches themselves from the given list (note the use of \fBc\fR-type completion) and completes anything not otherwise completed to a directory. Whew. .PP Remember that programmed completions are ignored if the word being completed is a tilde substitution (beginning with `~') or a variable (beginning with `$'). See also the \fIuncomplete\fR builtin command. .RE .TP 8 .B continue Continues execution of the nearest enclosing \fIwhile\fR or \fIforeach\fR. The rest of the commands on the current line are executed. .TP 8 .B default: Labels the default case in a \fIswitch\fR statement. It should come after all \fIcase\fR labels. .PP .B dirs \fR[\fB\-l\fR] [\fB\-n\fR|\fB\-v\fR] .br .B dirs \-S\fR|\fB\-L \fR[\fIfilename\fR] (+) .PD 0 .TP 8 .B dirs \-c \fR(+) The first form prints the directory stack. The top of the stack is at the left and the first directory in the stack is the current directory. With \fB\-l\fR, `~' or `~\fIname\fP' in the output is expanded explicitly to \fBhome\fR or the pathname of the home directory for user \fIname\fP. (+) With \fB\-n\fR, entries are wrapped before they reach the edge of the screen. (+) With \fB\-v\fR, entries are printed one per line, preceded by their stack positions. (+) If more than one of \fB\-n\fR or \fB\-v\fR is given, \fB\-v\fR takes precedence. \fB\-p\fR is accepted but does nothing. .PD .RS +8 .PP With \fB\-S\fR, the second form saves the directory stack to \fIfilename\fR as a series of \fIcd\fR and \fIpushd\fR commands. With \fB\-L\fR, the shell sources \fIfilename\fR, which is presumably a directory stack file saved by the \fB\-S\fR option or the \fBsavedirs\fR mechanism. In either case, \fBdirsfile\fR is used if \fIfilename\fR is not given and \fI~/.cshdirs\fR is used if \fBdirsfile\fR is unset. .PP Note that login shells do the equivalent of `dirs \-L' on startup and, if \fBsavedirs\fR is set, `dirs \-S' before exiting. Because only \fI~/.tcshrc\fR is normally sourced before \fI~/.cshdirs\fR, \fBdirsfile\fR should be set in \fI~/.tcshrc\fR rather than \fI~/.login\fR. .PP The last form clears the directory stack. .RE .TP 8 .B echo \fR[\fB\-n\fR] \fIword\fR ... Writes each \fIword\fR to the shell's standard output, separated by spaces and terminated with a newline. The \fBecho_style\fR shell variable may be set to emulate (or not) the flags and escape sequences of the BSD and/or System V versions of \fIecho\fR; see \fIecho\fR(1). .TP 8 .B echotc \fR[\fB\-sv\fR] \fIarg\fR ... (+) Exercises the terminal capabilities (see \fItermcap\fR(5)) in \fIargs\fR. For example, 'echotc home' sends the cursor to the home position, \&'echotc cm 3 10' sends it to column 3 and row 10, and \&'echotc ts 0; echo "This is a test."; echotc fs' prints "This is a test." in the status line. .RS +8 .PP If \fIarg\fR is 'baud', 'cols', 'lines', 'meta' or 'tabs', prints the value of that capability ("yes" or "no" indicating that the terminal does or does not have that capability). One might use this to make the output from a shell script less verbose on slow terminals, or limit command output to the number of lines on the screen: .IP "" 4 > set history=\`echotc lines\` .br > @ history\-\- .PP Termcap strings may contain wildcards which will not echo correctly. One should use double quotes when setting a shell variable to a terminal capability string, as in the following example that places the date in the status line: .IP "" 4 > set tosl="\`echotc ts 0\`" .br > set frsl="\`echotc fs\`" .br > echo \-n "$tosl";date; echo \-n "$frsl" .PP With \fB\-s\fR, nonexistent capabilities return the empty string rather than causing an error. With \fB\-v\fR, messages are verbose. .RE .PP .B else .br .B end .br .B endif .PD 0 .TP 8 .B endsw See the description of the \fIforeach\fR, \fIif\fR, \fIswitch\fR, and \fIwhile\fR statements below. .PD .TP 8 .B eval \fIarg\fR ... Treats the arguments as input to the shell and executes the resulting command(s) in the context of the current shell. This is usually used to execute commands generated as the result of command or variable substitution, because parsing occurs before these substitutions. See \fItset\fR(1) for a sample use of \fIeval\fR. .TP 8 .B exec \fIcommand\fR Executes the specified command in place of the current shell. .TP 8 .B exit \fR[\fIexpr\fR] The shell exits either with the value of the specified \fIexpr\fR (an expression, as described under \fBExpressions\fR) or, without \fIexpr\fR, with the value 0. .TP 8 .B fg \fR[\fB%\fIjob\fR ...] Brings the specified jobs (or, without arguments, the current job) into the foreground, continuing each if it is stopped. \fIjob\fR may be a number, a string, `', `%', `+' or `\-' as described under \fBJobs\fR. See also the \fIrun-fg-editor\fR editor command. .TP 8 .B filetest \-\fIop file\fR ... (+) Applies \fIop\fR (which is a file inquiry operator as described under \fBFile inquiry operators\fR) to each \fIfile\fR and returns the results as a space-separated list. .PP .B foreach \fIname \fB(\fIwordlist\fB) .br \&... .PD 0 .TP 8 .B end Successively sets the variable \fIname\fR to each member of \fIwordlist\fR and executes the sequence of commands between this command and the matching \fIend\fR. (Both \fIforeach\fR and \fIend\fR must appear alone on separate lines.) The builtin command \fIcontinue\fR may be used to continue the loop prematurely and the builtin command \fIbreak\fR to terminate it prematurely. When this command is read from the terminal, the loop is read once prompting with `foreach? ' (or \fBprompt2\fR) before any statements in the loop are executed. If you make a mistake typing in a loop at the terminal you can rub it out. .PD .TP 8 .B getspath \fR(+) Prints the system execution path. (TCF only) .TP 8 .B getxvers \fR(+) Prints the experimental version prefix. (TCF only) .TP 8 .B glob \fIwordlist Like \fIecho\fR, but the `-n' parameter is not recognized and words are delimited by null characters in the output. Useful for programs which wish to use the shell to filename expand a list of words. .TP 8 .B goto \fIword \fIword\fR is filename and command-substituted to yield a string of the form `label'. The shell rewinds its input as much as possible, searches for a line of the form `label:', possibly preceded by blanks or tabs, and continues execution after that line. .TP 8 .B hashstat Prints a statistics line indicating how effective the internal hash table has been at locating commands (and avoiding \fIexec\fR's). An \fIexec\fR is attempted for each component of the \fBpath\fR where the hash function indicates a possible hit, and in each component which does not begin with a `/'. .IP On machines without \fIvfork\fR(2), prints only the number and size of hash buckets. .PP .B history \fR[\fB\-hTr\fR] [\fIn\fR] .br .B history \-S\fR|\fB\-L|\fB\-M \fR[\fIfilename\fR] (+) .PD 0 .TP 8 .B history \-c \fR(+) The first form prints the history event list. If \fIn\fR is given only the \fIn\fR most recent events are printed or saved. With \fB\-h\fR, the history list is printed without leading numbers. If \fB-T\fR is specified, timestamps are printed also in comment form. (This can be used to produce files suitable for loading with 'history \-L' or 'source \-h'.) With \fB\-r\fR, the order of printing is most recent first rather than oldest first. .PD .RS +8 .PP With \fB\-S\fR, the second form saves the history list to \fIfilename\fR. If the first word of the \fBsavehist\fR shell variable is set to a number, at most that many lines are saved. If the second word of \fBsavehist\fR is set to `merge', the history list is merged with the existing history file instead of replacing it (if there is one) and sorted by time stamp. (+) Merging is intended for an environment like the X Window System with several shells in simultaneous use. If the second word of \fBsavehist\fR is `merge' and the third word is set to `lock', the history file update will be serialized with other shell sessions that would possibly like to merge history at exactly the same time. .PP With \fB\-L\fR, the shell appends \fIfilename\fR, which is presumably a history list saved by the \fB\-S\fR option or the \fBsavehist\fR mechanism, to the history list. \fB\-M\fR is like \fB\-L\fR, but the contents of \fIfilename\fR are merged into the history list and sorted by timestamp. In either case, \fBhistfile\fR is used if \fIfilename\fR is not given and \fI~/.history\fR is used if \fBhistfile\fR is unset. `history \-L' is exactly like 'source \-h' except that it does not require a filename. .PP Note that login shells do the equivalent of `history \-L' on startup and, if \fBsavehist\fR is set, `history \-S' before exiting. Because only \fI~/.tcshrc\fR is normally sourced before \fI~/.history\fR, \fBhistfile\fR should be set in \fI~/.tcshrc\fR rather than \fI~/.login\fR. .PP If \fBhistlit\fR is set, the first and second forms print and save the literal (unexpanded) form of the history list. .PP The last form clears the history list. .RE .TP 8 .B hup \fR[\fIcommand\fR] \fR(+) With \fIcommand\fR, runs \fIcommand\fR such that it will exit on a hangup signal and arranges for the shell to send it a hangup signal when the shell exits. Note that commands may set their own response to hangups, overriding \fIhup\fR. Without an argument, causes the non-interactive shell only to exit on a hangup for the remainder of the script. See also \fBSignal handling\fR and the \fInohup\fR builtin command. .TP 8 .B if (\fIexpr\fB) \fIcommand If \fIexpr\fR (an expression, as described under \fBExpressions\fR) evaluates true, then \fIcommand\fR is executed. Variable substitution on \fIcommand\fR happens early, at the same time it does for the rest of the \fIif\fR command. \fIcommand\fR must be a simple command, not an alias, a pipeline, a command list or a parenthesized command list, but it may have arguments. Input/output redirection occurs even if \fIexpr\fR is false and \fIcommand\fR is thus \fInot\fR executed; this is a bug. .PP .B if (\fIexpr\fB) then .br \&... .br .B else if (\fIexpr2\fB) then .br \&... .br .B else .br \&... .PD 0 .TP 8 .B endif If the specified \fIexpr\fR is true then the commands to the first \fIelse\fR are executed; otherwise if \fIexpr2\fR is true then the commands to the second \fIelse\fR are executed, etc. Any number of \fIelse-if\fR pairs are possible; only one \fIendif\fR is needed. The \fIelse\fR part is likewise optional. (The words \fIelse\fR and \fIendif\fR must appear at the beginning of input lines; the \fIif\fR must appear alone on its input line or after an \fIelse\fR.) .PD .TP 8 .B inlib \fIshared-library\fR ... (+) Adds each \fIshared-library\fR to the current environment. There is no way to remove a shared library. (Domain/OS only) .TP 8 .B jobs \fR[\fB\-l\fR] Lists the active jobs. With \fB\-l\fR, lists process IDs in addition to the normal information. On TCF systems, prints the site on which each job is executing. .PP .PD 0 .TP 8 .B kill \fR[\fB\-s \fIsignal\fR] \fB%\fIjob\fR|\fIpid\fR ... .PD 0 .TP 8 .B kill \-l The first and second forms sends the specified \fIsignal\fR (or, if none is given, the TERM (terminate) signal) to the specified jobs or processes. \fIjob\fR may be a number, a string, `', `%', `+' or `\-' as described under \fBJobs\fR. Signals are either given by number or by name (as given in \fI/usr/include/signal.h\fR, stripped of the prefix `SIG'). There is no default \fIjob\fR; saying just `kill' does not send a signal to the current job. If the signal being sent is TERM (terminate) or HUP (hangup), then the job or process is sent a CONT (continue) signal as well. The third form lists the signal names. .PD .TP 8 .B limit \fR[\fB\-h\fR] [\fIresource\fR [\fImaximum-use\fR]] Limits the consumption by the current process and each process it creates to not individually exceed \fImaximum-use\fR on the specified \fIresource\fR. If no \fImaximum-use\fR is given, then the current limit is printed; if no \fIresource\fR is given, then all limitations are given. If the \fB\-h\fR flag is given, the hard limits are used instead of the current limits. The hard limits impose a ceiling on the values of the current limits. Only the super-user may raise the hard limits, but a user may lower or raise the current limits within the legal range. .RS +8 .PP Controllable resources currently include (if supported by the OS): .TP \fIcputime\fR the maximum number of cpu-seconds to be used by each process .TP \fIfilesize\fR the largest single file which can be created .TP \fIdatasize\fR the maximum growth of the data+stack region via sbrk(2) beyond the end of the program text .TP \fIstacksize\fR the maximum size of the automatically-extended stack region .TP \fIcoredumpsize\fR the size of the largest core dump that will be created .TP \fImemoryuse\fR the maximum amount of physical memory a process may have allocated to it at a given time .TP \fIvmemoryuse\fR the maximum amount of virtual memory a process may have allocated to it at a given time (address space) .TP \fIvmemoryuse\fR the maximum amount of virtual memory a process may have allocated to it at a given time .TP \fIheapsize\fR the maximum amount of memory a process may allocate per \fIbrk()\fR system call .TP \fIdescriptors\fR or \fIopenfiles\fR the maximum number of open files for this process .TP \fIpseudoterminals\fR the maximum number of pseudo-terminals for this user .TP \fIkqueues\fR the maximum number of kqueues allocated for this process .TP \fIconcurrency\fR the maximum number of threads for this process .TP \fImemorylocked\fR the maximum size which a process may lock into memory using mlock(2) .TP \fImaxproc\fR the maximum number of simultaneous processes for this user id .TP \fImaxthread\fR the maximum number of simultaneous threads (lightweight processes) for this user id .TP \fIthreads\fR the maximum number of threads for this process .TP \fIsbsize\fR the maximum size of socket buffer usage for this user .TP \fIswapsize\fR the maximum amount of swap space reserved or used for this user .TP \fImaxlocks\fR the maximum number of locks for this user .TP \fIposixlocks\fR the maximum number of POSIX advisory locks for this user .TP \fImaxsignal\fR the maximum number of pending signals for this user .TP \fImaxmessage\fR the maximum number of bytes in POSIX mqueues for this user .TP \fImaxnice\fR the maximum nice priority the user is allowed to raise mapped from [19...-20] to [0...39] for this user .TP \fImaxrtprio\fR the maximum realtime priority for this user \fImaxrttime\fR the timeout for RT tasks in microseconds for this user. .PP \fImaximum-use\fR may be given as a (floating point or integer) number followed by a scale factor. For all limits other than \fIcputime\fR the default scale is `k' or `kilobytes' (1024 bytes); a scale factor of `m' or `megabytes' or `g' or `gigabytes' may also be used. For \fIcputime\fR the default scaling is `seconds', while `m' for minutes or `h' for hours, or a time of the form `mm:ss' giving minutes and seconds may be used. .PP If \fImaximum-use\fR is `unlimited', then the limitation on the specified \fIresource\fR is removed (this is equivalent to the \fIunlimit\fR builtin command). .PP For both \fIresource\fR names and scale factors, unambiguous prefixes of the names suffice. .RE .TP 8 .B log \fR(+) Prints the \fBwatch\fR shell variable and reports on each user indicated in \fBwatch\fR who is logged in, regardless of when they last logged in. See also \fIwatchlog\fR. .TP 8 .B login Terminates a login shell, replacing it with an instance of \fI/bin/login\fR. This is one way to log off, included for compatibility with \fIsh\fR(1). .TP 8 .B logout Terminates a login shell. Especially useful if \fBignoreeof\fR is set. .TP 8 .B ls\-F \fR[\-\fIswitch\fR ...] [\fIfile\fR ...] (+) Lists files like `ls \-F', but much faster. It identifies each type of special file in the listing with a special character: .PP .RS +8 .PD 0 .TP 4 / Directory .TP 4 * Executable .TP 4 # Block device .TP 4 % Character device .TP 4 | Named pipe (systems with named pipes only) .TP 4 = Socket (systems with sockets only) .TP 4 @ Symbolic link (systems with symbolic links only) .TP 4 + Hidden directory (AIX only) or context dependent (HP/UX only) .TP 4 : Network special (HP/UX only) .PD .PP If the \fBlistlinks\fR shell variable is set, symbolic links are identified in more detail (on only systems that have them, of course): .PP .PD 0 .TP 4 @ Symbolic link to a non-directory .TP 4 > Symbolic link to a directory .TP 4 & Symbolic link to nowhere .PD .PP \fBlistlinks\fR also slows down \fIls\-F\fR and causes partitions holding files pointed to by symbolic links to be mounted. .PP If the \fBlistflags\fR shell variable is set to `x', `a' or `A', or any combination thereof (e.g., `xA'), they are used as flags to \fIls\-F\fR, making it act like `ls \-xF', `ls \-Fa', `ls \-FA' or a combination (e.g., `ls \-FxA'). On machines where `ls \-C' is not the default, \fIls\-F\fR acts like `ls \-CF', unless \fBlistflags\fR contains an `x', in which case it acts like `ls \-xF'. \fIls\-F\fR passes its arguments to \fIls\fR(1) if it is given any switches, so `alias ls ls\-F' generally does the right thing. .PP The \fBls\-F\fR builtin can list files using different colors depending on the filetype or extension. See the \fBcolor\fR shell variable and the \fBLS_COLORS\fR environment variable. .RE .PP .B migrate \fR[\fB\-\fIsite\fR] \fIpid\fR|\fB%\fIjobid\fR ... (+) .PD 0 .TP 8 .B migrate \-\fIsite\fR (+) The first form migrates the process or job to the site specified or the default site determined by the system path. The second form is equivalent to `migrate \-\fIsite\fR $$': it migrates the current process to the specified site. Migrating the shell itself can cause unexpected behavior, because the shell does not like to lose its tty. (TCF only) .PD .TP 8 .B newgrp \fR[\fB\-\fR] \fI[group]\fR (+) Equivalent to `exec newgrp'; see \fInewgrp\fR(1). Available only if the shell was so compiled; see the \fBversion\fR shell variable. .TP 8 .B nice \fR[\fB+\fInumber\fR] [\fIcommand\fR] Sets the scheduling priority for the shell to \fInumber\fR, or, without \fInumber\fR, to 4. With \fIcommand\fR, runs \fIcommand\fR at the appropriate priority. The greater the \fInumber\fR, the less cpu the process gets. The super-user may specify negative priority by using `nice \-number ...'. Command is always executed in a sub-shell, and the restrictions placed on commands in simple \fIif\fR statements apply. .TP 8 .B nohup \fR[\fIcommand\fR] With \fIcommand\fR, runs \fIcommand\fR such that it will ignore hangup signals. Note that commands may set their own response to hangups, overriding \fInohup\fR. Without an argument, causes the non-interactive shell only to ignore hangups for the remainder of the script. See also \fBSignal handling\fR and the \fIhup\fR builtin command. .TP 8 .B notify \fR[\fB%\fIjob\fR ...] Causes the shell to notify the user asynchronously when the status of any of the specified jobs (or, without %\fIjob\fR, the current job) changes, instead of waiting until the next prompt as is usual. \fIjob\fR may be a number, a string, `', `%', `+' or `\-' as described under \fBJobs\fR. See also the \fBnotify\fR shell variable. .TP 8 .B onintr \fR[\fB\-\fR|\fIlabel\fR] Controls the action of the shell on interrupts. Without arguments, restores the default action of the shell on interrupts, which is to terminate shell scripts or to return to the terminal command input level. With `\-', causes all interrupts to be ignored. With \fIlabel\fR, causes the shell to execute a `goto \fIlabel\fR' when an interrupt is received or a child process terminates because it was interrupted. .IP "" 8 \fIonintr\fR is ignored if the shell is running detached and in system startup files (see \fBFILES\fR), where interrupts are disabled anyway. .TP 8 .B popd \fR[\fB\-p\fR] [\fB\-l\fR] [\fB\-n\fR|\fB\-v\fR] \fR[\fB+\fIn\fR] Without arguments, pops the directory stack and returns to the new top directory. With a number `+\fIn\fR', discards the \fIn\fR'th entry in the stack. .IP "" 8 Finally, all forms of \fIpopd\fR print the final directory stack, just like \fIdirs\fR. The \fBpushdsilent\fR shell variable can be set to prevent this and the \fB\-p\fR flag can be given to override \fBpushdsilent\fR. The \fB\-l\fR, \fB\-n\fR and \fB\-v\fR flags have the same effect on \fIpopd\fR as on \fIdirs\fR. (+) .TP 8 .B printenv \fR[\fIname\fR] (+) Prints the names and values of all environment variables or, with \fIname\fR, the value of the environment variable \fIname\fR. .TP 8 .B pushd \fR[\fB\-p\fR] [\fB\-l\fR] [\fB\-n\fR|\fB\-v\fR] [\fIname\fR|\fB+\fIn\fR] Without arguments, exchanges the top two elements of the directory stack. If \fBpushdtohome\fR is set, \fIpushd\fR without arguments does `pushd ~', like \fIcd\fR. (+) With \fIname\fR, pushes the current working directory onto the directory stack and changes to \fIname\fR. If \fIname\fR is `\-' it is interpreted as the previous working directory (see \fBFilename substitution\fR). (+) If \fBdunique\fR is set, \fIpushd\fR removes any instances of \fIname\fR from the stack before pushing it onto the stack. (+) With a number `+\fIn\fR', rotates the \fIn\fRth element of the directory stack around to be the top element and changes to it. If \fBdextract\fR is set, however, `pushd +\fIn\fR' extracts the \fIn\fRth directory, pushes it onto the top of the stack and changes to it. (+) .IP "" 8 Finally, all forms of \fIpushd\fR print the final directory stack, just like \fIdirs\fR. The \fBpushdsilent\fR shell variable can be set to prevent this and the \fB\-p\fR flag can be given to override \fBpushdsilent\fR. The \fB\-l\fR, \fB\-n\fR and \fB\-v\fR flags have the same effect on \fIpushd\fR as on \fIdirs\fR. (+) .TP 8 .B rehash Causes the internal hash table of the contents of the directories in the \fBpath\fR variable to be recomputed. This is needed if the \fBautorehash\fR shell variable is not set and new commands are added to directories in \fBpath\fR while you are logged in. With \fBautorehash\fR, a new command will be found automatically, except in the special case where another command of the same name which is located in a different directory already exists in the hash table. Also flushes the cache of home directories built by tilde expansion. .TP 8 .B repeat \fIcount command The specified \fIcommand\fR, which is subject to the same restrictions as the \fIcommand\fR in the one line \fIif\fR statement above, is executed \fIcount\fR times. I/O redirections occur exactly once, even if \fIcount\fR is 0. .TP 8 .B rootnode //\fInodename \fR(+) Changes the rootnode to //\fInodename\fR, so that `/' will be interpreted as `//\fInodename\fR'. (Domain/OS only) .PP .B sched \fR(+) .br .B sched \fR[\fB+\fR]\fIhh:mm command\fR \fR(+) .PD 0 .TP 8 .B sched \-\fIn\fR (+) The first form prints the scheduled-event list. The \fBsched\fR shell variable may be set to define the format in which the scheduled-event list is printed. The second form adds \fIcommand\fR to the scheduled-event list. For example, .PD .RS +8 .IP "" 4 > sched 11:00 echo It\e's eleven o\e'clock. .PP causes the shell to echo `It's eleven o'clock.' at 11 AM. The time may be in 12-hour AM/PM format .IP "" 4 .\" TODO > sched 5pm set prompt='[%h] It\e's after 5; go home: >' .PP or may be relative to the current time: .IP "" 4 > sched +2:15 /usr/lib/uucp/uucico \-r1 \-sother .PP A relative time specification may not use AM/PM format. The third form removes item \fIn\fR from the event list: .IP "" 4 > sched .br 1 Wed Apr 4 15:42 /usr/lib/uucp/uucico \-r1 \-sother .br 2 Wed Apr 4 17:00 set prompt=[%h] It's after 5; go home: > .br > sched \-2 .br > sched .br 1 Wed Apr 4 15:42 /usr/lib/uucp/uucico \-r1 \-sother .PP A command in the scheduled-event list is executed just before the first prompt is printed after the time when the command is scheduled. It is possible to miss the exact time when the command is to be run, but an overdue command will execute at the next prompt. A command which comes due while the shell is waiting for user input is executed immediately. However, normal operation of an already-running command will not be interrupted so that a scheduled-event list element may be run. .PP This mechanism is similar to, but not the same as, the \fIat\fR(1) command on some Unix systems. Its major disadvantage is that it may not run a command at exactly the specified time. Its major advantage is that because \fIsched\fR runs directly from the shell, it has access to shell variables and other structures. This provides a mechanism for changing one's working environment based on the time of day. .RE .PP .B set .br .B set \fIname\fR ... .br .B set \fIname\fR\fB=\fIword\fR ... .br .B set [\-r] [\-f|\-l] \fIname\fR\fB=(\fIwordlist\fB)\fR ... (+) .br .B set \fIname[index]\fR\fB=\fIword\fR ... .br .B set \-r \fR(+) .br .B set \-r \fIname\fR ... (+) .PD 0 .TP 8 .B set \-r \fIname\fR\fB=\fIword\fR ... (+) The first form of the command prints the value of all shell variables. Variables which contain more than a single word print as a parenthesized word list. The second form sets \fIname\fR to the null string. The third form sets \fIname\fR to the single \fIword\fR. The fourth form sets \fIname\fR to the list of words in \fIwordlist\fR. In all cases the value is command and filename expanded. If \fB\-r\fR is specified, the value is set read-only. If \fB\-f\fR or \fB\-l\fR are specified, set only unique words keeping their order. \fB\-f\fR prefers the first occurrence of a word, and \fB\-l\fR the last. The fifth form sets the \fIindex\fR'th component of \fIname\fR to \fIword\fR; this component must already exist. The sixth form lists only the names of all shell variables that are read-only. The seventh form makes \fIname\fR read-only, whether or not it has a value. The eighth form is the same as the third form, but make \fIname\fR read-only at the same time. .PD .IP "" 8 These arguments can be repeated to set and/or make read-only multiple variables in a single set command. Note, however, that variable expansion happens for all arguments before any setting occurs. Note also that `=' can be adjacent to both \fIname\fR and \fIword\fR or separated from both by whitespace, but cannot be adjacent to only one or the other. See also the \fIunset\fR builtin command. .TP 8 .B setenv \fR[\fIname \fR[\fIvalue\fR]] Without arguments, prints the names and values of all environment variables. Given \fIname\fR, sets the environment variable \fIname\fR to \fIvalue\fR or, without \fIvalue\fR, to the null string. .TP 8 .B setpath \fIpath \fR(+) Equivalent to \fIsetpath\fR(1). (Mach only) .TP 8 .B setspath\fR LOCAL|\fIsite\fR|\fIcpu\fR ... (+) Sets the system execution path. (TCF only) .TP 8 .B settc \fIcap value \fR(+) Tells the shell to believe that the terminal capability \fIcap\fR (as defined in \fItermcap\fR(5)) has the value \fIvalue\fR. No sanity checking is done. Concept terminal users may have to `settc xn no' to get proper wrapping at the rightmost column. .TP 8 .B setty \fR[\fB\-d\fR|\fB\-q\fR|\fB\-x\fR] [\fB\-a\fR] [[\fB+\fR|\fB\-\fR]\fImode\fR] (+) Controls which tty modes (see \fBTerminal management\fR) the shell does not allow to change. \fB\-d\fR, \fB\-q\fR or \fB\-x\fR tells \fIsetty\fR to act on the `edit', `quote' or `execute' set of tty modes respectively; without \fB\-d\fR, \fB\-q\fR or \fB\-x\fR, `execute' is used. .IP "" 8 Without other arguments, \fIsetty\fR lists the modes in the chosen set which are fixed on (`+mode') or off (`\-mode'). The available modes, and thus the display, vary from system to system. With \fB\-a\fR, lists all tty modes in the chosen set whether or not they are fixed. With \fB+\fImode\fR, \fB\-\fImode\fR or \fImode\fR, fixes \fImode\fR on or off or removes control from \fImode\fR in the chosen set. For example, `setty +echok echoe' fixes `echok' mode on and allows commands to turn `echoe' mode on or off, both when the shell is executing commands. .TP 8 .B setxvers\fR [\fIstring\fR] (+) Set the experimental version prefix to \fIstring\fR, or removes it if \fIstring\fR is omitted. (TCF only) .TP 8 .B shift \fR[\fIvariable\fR] Without arguments, discards \fBargv\fR[1] and shifts the members of \fBargv\fR to the left. It is an error for \fBargv\fR not to be set or to have less than one word as value. With \fIvariable\fR, performs the same function on \fIvariable\fR. .TP 8 .B source \fR[\fB\-h\fR] \fIname\fR [\fIargs\fR ...] The shell reads and executes commands from \fIname\fR. The commands are not placed on the history list. If any \fIargs\fR are given, they are placed in \fBargv\fR. (+) \fIsource\fR commands may be nested; if they are nested too deeply the shell may run out of file descriptors. An error in a \fIsource\fR at any level terminates all nested \fIsource\fR commands. With \fB\-h\fR, commands are placed on the history list instead of being executed, much like `history \-L'. .TP 8 .B stop \fB%\fIjob\fR|\fIpid\fR ... Stops the specified jobs or processes which are executing in the background. \fIjob\fR may be a number, a string, `', `%', `+' or `\-' as described under \fBJobs\fR. There is no default \fIjob\fR; saying just `stop' does not stop the current job. .TP 8 .B suspend Causes the shell to stop in its tracks, much as if it had been sent a stop signal with \fB^Z\fR. This is most often used to stop shells started by \fIsu\fR(1). .PP .B switch (\fIstring\fB) .br .B case \fIstr1\fB: .PD 0 .IP "" 4 \&... .br .B breaksw .PP \&... .PP .B default: .IP "" 4 \&... .br .B breaksw .TP 8 .B endsw Each case label is successively matched, against the specified \fIstring\fR which is first command and filename expanded. The file metacharacters `*', `?' and `[...]' may be used in the case labels, which are variable expanded. If none of the labels match before a `default' label is found, then the execution begins after the default label. Each case label and the default label must appear at the beginning of a line. The command \fIbreaksw\fR causes execution to continue after the \fIendsw\fR. Otherwise control may fall through case labels and default labels as in C. If no label matches and there is no default, execution continues after the \fIendsw\fR. .PD .TP 8 .B telltc \fR(+) Lists the values of all terminal capabilities (see \fItermcap\fR(5)). .TP 8 .B termname \fR[\fIterminal type\fR] \fR(+) Tests if \fIterminal type\fR (or the current value of \fBTERM\fR if no \fIterminal type\fR is given) has an entry in the hosts termcap(5) or terminfo(5) database. Prints the terminal type to stdout and returns 0 if an entry is present otherwise returns 1. .TP 8 .B time \fR[\fIcommand\fR] Executes \fIcommand\fR (which must be a simple command, not an alias, a pipeline, a command list or a parenthesized command list) and prints a time summary as described under the \fBtime\fR variable. If necessary, an extra shell is created to print the time statistic when the command completes. Without \fIcommand\fR, prints a time summary for the current shell and its children. .TP 8 .B umask \fR[\fIvalue\fR] Sets the file creation mask to \fIvalue\fR, which is given in octal. Common values for the mask are 002, giving all access to the group and read and execute access to others, and 022, giving read and execute access to the group and others. Without \fIvalue\fR, prints the current file creation mask. .TP 8 .B unalias \fIpattern\fR .br Removes all aliases whose names match \fIpattern\fR. `unalias *' thus removes all aliases. It is not an error for nothing to be \fIunalias\fRed. .TP 8 .B uncomplete \fIpattern\fR (+) Removes all completions whose names match \fIpattern\fR. `uncomplete *' thus removes all completions. It is not an error for nothing to be \fIuncomplete\fRd. .TP 8 .B unhash Disables use of the internal hash table to speed location of executed programs. .TP 8 .B universe \fIuniverse\fR (+) Sets the universe to \fIuniverse\fR. (Masscomp/RTU only) .TP 8 .B unlimit \fR[\fB\-hf\fR] [\fIresource\fR] Removes the limitation on \fIresource\fR or, if no \fIresource\fR is specified, all \fIresource\fR limitations. With \fB\-h\fR, the corresponding hard limits are removed. Only the super-user may do this. Note that \fBunlimit\fR may not exit successful, since most systems do not allow \fIdescriptors\fR to be unlimited. With \fB\-f\fR errors are ignored. .TP 8 .B unset \fIpattern Removes all variables whose names match \fIpattern\fR, unless they are read-only. `unset *' thus removes all variables unless they are read-only; this is a bad idea. It is not an error for nothing to be \fIunset\fR. .TP 8 .B unsetenv \fIpattern Removes all environment variables whose names match \fIpattern\fR. `unsetenv *' thus removes all environment variables; this is a bad idea. It is not an error for nothing to be \fIunsetenv\fRed. .TP 8 .B ver \fR[\fIsystype\fR [\fIcommand\fR]] (+) Without arguments, prints \fBSYSTYPE\fR. With \fIsystype\fR, sets \fBSYSTYPE\fR to \fIsystype\fR. With \fIsystype\fR and \fIcommand\fR, executes \fIcommand\fR under \fIsystype\fR. \fIsystype\fR may be `bsd4.3' or `sys5.3'. (Domain/OS only) .TP 8 .B wait The shell waits for all background jobs. If the shell is interactive, an interrupt will disrupt the wait and cause the shell to print the names and job numbers of all outstanding jobs. .TP 8 .B warp \fIuniverse\fR (+) Sets the universe to \fIuniverse\fR. (Convex/OS only) .TP 8 .B watchlog \fR(+) An alternate name for the \fIlog\fR builtin command (q.v.). Available only if the shell was so compiled; see the \fBversion\fR shell variable. .TP 8 .B where \fIcommand\fR (+) Reports all known instances of \fIcommand\fR, including aliases, builtins and executables in \fBpath\fR. .TP 8 .B which\fR \fIcommand\fR (+) Displays the command that will be executed by the shell after substitutions, \fBpath\fR searching, etc. The builtin command is just like \fIwhich\fR(1), but it correctly reports \fItcsh\fR aliases and builtins and is 10 to 100 times faster. See also the \fIwhich-command\fR editor command. .PP .B while (\fIexpr\fB)\fR .br \&... .PD 0 .TP 8 .B end Executes the commands between the \fIwhile\fR and the matching \fIend\fR while \fIexpr\fR (an expression, as described under \fBExpressions\fR) evaluates non-zero. \fIwhile\fR and \fIend\fR must appear alone on their input lines. \fIbreak\fR and \fIcontinue\fR may be used to terminate or continue the loop prematurely. If the input is a terminal, the user is prompted the first time through the loop as with \fIforeach\fR. .PD .SS "Special aliases (+)" If set, each of these aliases executes automatically at the indicated time. They are all initially undefined. .TP 8 .B beepcmd Runs when the shell wants to ring the terminal bell. .TP 8 .B cwdcmd Runs after every change of working directory. For example, if the user is working on an X window system using \fIxterm\fR(1) and a re-parenting window manager that supports title bars such as \fItwm\fR(1) and does .RS +8 .IP "" 4 > alias cwdcmd 'echo \-n "^[]2;${HOST}:$cwd ^G"' .PP then the shell will change the title of the running \fIxterm\fR(1) to be the name of the host, a colon, and the full current working directory. A fancier way to do that is .IP "" 4 > alias cwdcmd 'echo \-n "^[]2;${HOST}:$cwd^G^[]1;${HOST}^G"' .PP This will put the hostname and working directory on the title bar but only the hostname in the icon manager menu. .PP Note that putting a \fIcd\fR, \fIpushd\fR or \fIpopd\fR in \fIcwdcmd\fR may cause an infinite loop. It is the author's opinion that anyone doing so will get what they deserve. .RE .TP 8 .B jobcmd Runs before each command gets executed, or when the command changes state. This is similar to \fIpostcmd\fR, but it does not print builtins. .RS +8 .IP "" 4 > alias jobcmd 'echo \-n "^[]2\e;\e!#:q^G"' .PP then executing \fIvi foo.c\fR will put the command string in the xterm title bar. .RE .TP 8 .B helpcommand Invoked by the \fBrun-help\fR editor command. The command name for which help is sought is passed as sole argument. For example, if one does .RS +8 .IP "" 4 > alias helpcommand '\e!:1 --help' .PP then the help display of the command itself will be invoked, using the GNU help calling convention. Currently there is no easy way to account for various calling conventions (e.g., the customary Unix `-h'), except by using a table of many commands. .RE .TP 8 .B periodic Runs every \fBtperiod\fR minutes. This provides a convenient means for checking on common but infrequent changes such as new mail. For example, if one does .RS +8 .IP "" 4 > set tperiod = 30 .br > alias periodic checknews .PP then the \fIchecknews\fR(1) program runs every 30 minutes. If \fIperiodic\fR is set but \fBtperiod\fR is unset or set to 0, \fIperiodic\fR behaves like \fIprecmd\fR. .RE .TP 8 .B precmd Runs just before each prompt is printed. For example, if one does .RS +8 .IP "" 4 > alias precmd date .PP then \fIdate\fR(1) runs just before the shell prompts for each command. There are no limits on what \fIprecmd\fR can be set to do, but discretion should be used. .RE .TP 8 .B postcmd Runs before each command gets executed. .RS +8 .IP "" 4 > alias postcmd 'echo \-n "^[]2\e;\e!#:q^G"' .PP then executing \fIvi foo.c\fR will put the command string in the xterm title bar. .RE .TP 8 .B shell Specifies the interpreter for executable scripts which do not themselves specify an interpreter. The first word should be a full path name to the desired interpreter (e.g., `/bin/csh' or `/usr/local/bin/tcsh'). .SS "Special shell variables" The variables described in this section have special meaning to the shell. .PP The shell sets \fBaddsuffix\fR, \fBargv\fR, \fBautologout\fR, \fBcsubstnonl\fR, \fBcommand\fR, \fBecho_style\fR, \fBedit\fR, \fBgid\fR, \fBgroup\fR, \fBhome\fR, \fBloginsh\fR, \fBoid\fR, \fBpath\fR, \fBprompt\fR, \fBprompt2\fR, \fBprompt3\fR, \fBshell\fR, \fBshlvl\fR, \fBtcsh\fR, \fBterm\fR, \fBtty\fR, \fBuid\fR, \fBuser\fR and \fBversion\fR at startup; they do not change thereafter unless changed by the user. The shell updates \fBcwd\fR, \fBdirstack\fR, \fBowd\fR and \fBstatus\fR when necessary, and sets \fBlogout\fR on logout. .PP The shell synchronizes \fBgroup\fR, \fBhome\fR, \fBpath\fR, \fBshlvl\fR, \fBterm\fR and \fBuser\fR with the environment variables of the same names: whenever the environment variable changes the shell changes the corresponding shell variable to match (unless the shell variable is read-only) and vice versa. Note that although \fBcwd\fR and \fBPWD\fR have identical meanings, they are not synchronized in this manner, and that the shell automatically converts between the different formats of \fBpath\fR and \fBPATH\fR. .TP 8 .B addsuffix \fR(+) If set, filename completion adds `/' to the end of directories and a space to the end of normal files when they are matched exactly. Set by default. .TP 8 .B afsuser \fR(+) If set, \fBautologout\fR's autolock feature uses its value instead of the local username for kerberos authentication. .TP 8 .B ampm \fR(+) If set, all times are shown in 12-hour AM/PM format. .TP 8 .B anyerror \fR(+) This variable selects what is propagated to the value of the \fBstatus\fR variable. For more information see the description of the \fBstatus\fR variable below. .TP 8 .B argv The arguments to the shell. Positional parameters are taken from \fBargv\fR, i.e., `$1' is replaced by `$argv[1]', etc. Set by default, but usually empty in interactive shells. .TP 8 .B autocorrect \fR(+) If set, the \fIspell-word\fR editor command is invoked automatically before each completion attempt. .TP 8 .B autoexpand \fR(+) If set, the \fIexpand-history\fR editor command is invoked automatically before each completion attempt. If this is set to \fIonlyhistory\fR, then only history will be expanded and a second completion will expand filenames. .TP 8 .B autolist \fR(+) If set, possibilities are listed after an ambiguous completion. If set to `ambiguous', possibilities are listed only when no new characters are added by completion. .TP 8 .B autologout \fR(+) The first word is the number of minutes of inactivity before automatic logout. The optional second word is the number of minutes of inactivity before automatic locking. When the shell automatically logs out, it prints `auto-logout', sets the variable \fBlogout\fR to `automatic' and exits. When the shell automatically locks, the user is required to enter his password to continue working. Five incorrect attempts result in automatic logout. Set to `60' (automatic logout after 60 minutes, and no locking) by default in login and superuser shells, but not if the shell thinks it is running under a window system (i.e., the \fBDISPLAY\fR environment variable is set), the tty is a pseudo-tty (pty) or the shell was not so compiled (see the \fBversion\fR shell variable). +Unset or set to `0' to disable automatic logout. See also the \fBafsuser\fR and \fBlogout\fR shell variables. .TP 8 .B autorehash \fR(+) If set, the internal hash table of the contents of the directories in the \fBpath\fR variable will be recomputed if a command is not found in the hash table. In addition, the list of available commands will be rebuilt for each command completion or spelling correction attempt if set to `complete' or `correct' respectively; if set to `always', this will be done for both cases. .TP 8 .B backslash_quote \fR(+) .\" TODO If set, backslashes (`\e') always quote `\e', `'', and `"'. This may make complex quoting tasks easier, but it can cause syntax errors in \fIcsh\fR(1) scripts. .TP 8 .B catalog The file name of the message catalog. If set, tcsh use `tcsh.${catalog}' as a message catalog instead of default `tcsh'. .TP 8 .B cdpath A list of directories in which \fIcd\fR should search for subdirectories if they aren't found in the current directory. .TP 8 .B cdtohome \fR(+) If not set, \fIcd\fR requires a directory \fIname\fR, and will not go to the \fBhome\fR directory if it's omitted. This is set by default. .TP 8 .B color If set, it enables color display for the builtin \fBls\-F\fR and it passes \fB\-\-color=auto\fR to \fBls\fR. Alternatively, it can be set to only \fBls\-F\fR or only \fBls\fR to enable color to only one command. Setting it to nothing is equivalent to setting it to \fB(ls\-F ls)\fR. .TP 8 .B colorcat If set, it enables color escape sequence for NLS message files. And display colorful NLS messages. .TP 8 .B command \fR(+) If set, the command which was passed to the shell with the \fB-c\fR flag (q.v.). .TP 8 .B compat_expr \fR(+) If set, the shell will evaluate expressions right to left, like the original \fIcsh\fR. .TP 8 .B complete \fR(+) If set to `igncase', the completion becomes case insensitive. If set to `enhance', completion ignores case and considers hyphens and underscores to be equivalent; it will also treat periods, hyphens and underscores (`.', `\-' and `_') as word separators. If set to `Enhance', completion matches uppercase and underscore characters explicitly and matches lowercase and hyphens in a case-insensitive manner; it will treat periods, hyphens and underscores as word separators. .TP 8 .B continue \fR(+) If set to a list of commands, the shell will continue the listed commands, instead of starting a new one. .TP 8 .B continue_args \fR(+) Same as continue, but the shell will execute: .RS +8 .IP "" 4 echo \`pwd\` $argv > ~/._pause; % .RE .TP 8 .B correct \fR(+) If set to `cmd', commands are automatically spelling-corrected. If set to `complete', commands are automatically completed. If set to `all', the entire command line is corrected. .TP 8 .B csubstnonl \fR(+) If set, newlines and carriage returns in command substitution are replaced by spaces. Set by default. .TP 8 .B cwd The full pathname of the current directory. See also the \fBdirstack\fR and \fBowd\fR shell variables. .TP 8 .B dextract \fR(+) If set, `pushd +\fIn\fR' extracts the \fIn\fRth directory from the directory stack rather than rotating it to the top. .TP 8 .B dirsfile \fR(+) The default location in which `dirs \-S' and `dirs \-L' look for a history file. If unset, \fI~/.cshdirs\fR is used. Because only \fI~/.tcshrc\fR is normally sourced before \fI~/.cshdirs\fR, \fBdirsfile\fR should be set in \fI~/.tcshrc\fR rather than \fI~/.login\fR. .TP 8 .B dirstack \fR(+) An array of all the directories on the directory stack. `$dirstack[1]' is the current working directory, `$dirstack[2]' the first directory on the stack, etc. Note that the current working directory is `$dirstack[1]' but `=0' in directory stack substitutions, etc. One can change the stack arbitrarily by setting \fBdirstack\fR, but the first element (the current working directory) is always correct. See also the \fBcwd\fR and \fBowd\fR shell variables. .TP 8 .B dspmbyte \fR(+) Has an effect iff 'dspm' is listed as part of the \fBversion\fR shell variable. If set to `euc', it enables display and editing EUC-kanji(Japanese) code. If set to `sjis', it enables display and editing Shift-JIS(Japanese) code. If set to `big5', it enables display and editing Big5(Chinese) code. If set to `utf8', it enables display and editing Utf8(Unicode) code. If set to the following format, it enables display and editing of original multi-byte code format: .RS +8 .IP "" 4 > set dspmbyte = 0000....(256 bytes)....0000 .PP The table requires \fBjust\fR 256 bytes. Each character of 256 characters corresponds (from left to right) to the ASCII codes 0x00, 0x01, ... 0xff. Each character .\" (position in this table?) is set to number 0,1,2 and 3. Each number has the following meaning: .br 0 ... not used for multi-byte characters. .br 1 ... used for the first byte of a multi-byte character. .br 2 ... used for the second byte of a multi-byte character. .br 3 ... used for both the first byte and second byte of a multi-byte character. .\" SHK: I tried my best to get the following to be grammatically correct. .\" However, I still don't understand what's going on here. In the .\" following example, there are three bytes, but the text seems to refer to .\" each nybble as a character. What's going on here? It this 3-byte code .\" in the table? The text above seems to imply that there are 256 .\" characters/bytes in the table. If I get some more info on this (perhaps .\" a complete example), I could fix the text to be grammatically correct. .\" (steve.kelem@xilinx.com 1999/09/13) .PP Example: .br If set to `001322', the first character (means 0x00 of the ASCII code) and second character (means 0x01 of ASCII code) are set to `0'. Then, it is not used for multi-byte characters. The 3rd character (0x02) is set to '1', indicating that it is used for the first byte of a multi-byte character. The 4th character(0x03) is set '3'. It is used for both the first byte and the second byte of a multi-byte character. The 5th and 6th characters (0x04,0x05) are set to '2', indicating that they are used for the second byte of a multi-byte character. .PP The GNU fileutils version of ls cannot display multi-byte filenames without the -N ( --literal ) option. If you are using this version, set the second word of dspmbyte to "ls". If not, for example, "ls-F -l" cannot display multi-byte filenames. .PP Note: .br This variable can only be used if KANJI and DSPMBYTE has been defined at compile time. .RE .TP 8 .B dunique \fR(+) If set, \fIpushd\fR removes any instances of \fIname\fR from the stack before pushing it onto the stack. .TP 8 .B echo If set, each command with its arguments is echoed just before it is executed. For non-builtin commands all expansions occur before echoing. Builtin commands are echoed before command and filename substitution, because these substitutions are then done selectively. Set by the \fB\-x\fR command line option. .TP 8 .B echo_style \fR(+) The style of the \fIecho\fR builtin. May be set to .PP .RS +8 .PD 0 .TP 8 bsd Don't echo a newline if the first argument is `\-n'; the default for \fIcsh\fR. .TP 8 sysv Recognize backslashed escape sequences in echo strings. .TP 8 both Recognize both the `\-n' flag and backslashed escape sequences; the default for \fItcsh\fR. .TP 8 none Recognize neither. .PD .PP Set by default to the local system default. The BSD and System V options are described in the \fIecho\fR(1) man pages on the appropriate systems. .RE .TP 8 .B edit \fR(+) If set, the command-line editor is used. Set by default in interactive shells. .TP 8 .B editors \fR(+) A list of command names for the \fIrun-fg-editor\fR editor command to match. If not set, the \fBEDITOR\fR (`ed' if unset) and \fBVISUAL\fR (`vi' if unset) environment variables will be used instead. .TP 8 .B ellipsis \fR(+) If set, the `%c'/`%.' and `%C' prompt sequences (see the \fBprompt\fR shell variable) indicate skipped directories with an ellipsis (`...') instead of `/'. .TP 8 .B euid \fR(+) The user's effective user ID. .TP 8 .B euser \fR(+) The first matching passwd entry name corresponding to the effective user ID. .TP 8 .B fignore \fR(+) Lists file name suffixes to be ignored by completion. .TP 8 .B filec In \fItcsh\fR, completion is always used and this variable is ignored by default. If .B edit is unset, then the traditional \fIcsh\fR completion is used. If set in \fIcsh\fR, filename completion is used. .TP 8 .B gid \fR(+) The user's real group ID. .TP 8 .B globdot \fR(+) If set, wild-card glob patterns will match files and directories beginning with `.' except for `.' and `..' .TP 8 .B globstar \fR(+) If set, the `**' and `***' file glob patterns will match any string of characters including `/' traversing any existing sub-directories. (e.g. `ls **.c' will list all the .c files in the current directory tree). If used by itself, it will match zero or more sub-directories (e.g. `ls /usr/include/**/time.h' will list any file named `time.h' in the /usr/include directory tree; whereas `ls /usr/include/**time.h' will match any file in the /usr/include directory tree ending in `time.h'). To prevent problems with recursion, the `**' glob-pattern will not descend into a symbolic link containing a directory. To override this, use `***' .TP 8 .B group \fR(+) The user's group name. .TP 8 .B highlight If set, the incremental search match (in \fIi-search-back\fR and \fIi-search-fwd\fR) and the region between the mark and the cursor are highlighted in reverse video. .IP "" 8 Highlighting requires more frequent terminal writes, which introduces extra overhead. If you care about terminal performance, you may want to leave this unset. .TP 8 .B histchars A string value determining the characters used in \fBHistory substitution\fR (q.v.). The first character of its value is used as the history substitution character, replacing the default character `!'. The second character of its value replaces the character `^' in quick substitutions. .TP 8 .B histdup \fR(+) Controls handling of duplicate entries in the history list. If set to `all' only unique history events are entered in the history list. If set to `prev' and the last history event is the same as the current command, then the current command is not entered in the history. If set to `erase' and the same event is found in the history list, that old event gets erased and the current one gets inserted. Note that the `prev' and `all' options renumber history events so there are no gaps. .TP 8 .B histfile \fR(+) The default location in which `history \-S' and `history \-L' look for a history file. If unset, \fI~/.history\fR is used. \fBhistfile\fR is useful when sharing the same home directory between different machines, or when saving separate histories on different terminals. Because only \fI~/.tcshrc\fR is normally sourced before \fI~/.history\fR, \fBhistfile\fR should be set in \fI~/.tcshrc\fR rather than \fI~/.login\fR. .TP 8 .B histlit \fR(+) If set, builtin and editor commands and the \fBsavehist\fR mechanism use the literal (unexpanded) form of lines in the history list. See also the \fItoggle-literal-history\fR editor command. .TP 8 .B history The first word indicates the number of history events to save. The optional second word (+) indicates the format in which history is printed; if not given, `%h\et%T\et%R\en' is used. The format sequences are described below under \fBprompt\fR; note the variable meaning of `%R'. Set to `100' by default. .TP 8 .B home Initialized to the home directory of the invoker. The filename expansion of `\fI~\fR' refers to this variable. .TP 8 .B ignoreeof If set to the empty string or `0' and the input device is a terminal, the \fIend-of-file\fR command (usually generated by the user by typing `^D' on an empty line) causes the shell to print `Use "exit" to leave tcsh.' instead of exiting. This prevents the shell from accidentally being killed. Historically this setting exited after 26 successive EOF's to avoid infinite loops. If set to a number \fIn\fR, the shell ignores \fIn - 1\fR consecutive \fIend-of-file\fRs and exits on the \fIn\fRth. (+) If unset, `1' is used, i.e., the shell exits on a single `^D'. .TP 8 .B implicitcd \fR(+) If set, the shell treats a directory name typed as a command as though it were a request to change to that directory. If set to \fIverbose\fR, the change of directory is echoed to the standard output. This behavior is inhibited in non-interactive shell scripts, or for command strings with more than one word. Changing directory takes precedence over executing a like-named command, but it is done after alias substitutions. Tilde and variable expansions work as expected. .TP 8 .B inputmode \fR(+) If set to `insert' or `overwrite', puts the editor into that input mode at the beginning of each line. .TP 8 .B killdup \fR(+) Controls handling of duplicate entries in the kill ring. If set to `all' only unique strings are entered in the kill ring. If set to `prev' and the last killed string is the same as the current killed string, then the current string is not entered in the ring. If set to `erase' and the same string is found in the kill ring, the old string is erased and the current one is inserted. .TP 8 .B killring \fR(+) Indicates the number of killed strings to keep in memory. Set to `30' by default. If unset or set to less than `2', the shell will only keep the most recently killed string. Strings are put in the killring by the editor commands that delete (kill) strings of text, e.g. \fIbackward-delete-word\fR, \fIkill-line\fR, etc, as well as the \fIcopy-region-as-kill\fR command. The \fIyank\fR editor command will yank the most recently killed string into the command-line, while \fIyank-pop\fR (see \fBEditor commands\fR) can be used to yank earlier killed strings. .TP 8 .B listflags \fR(+) If set to `x', `a' or `A', or any combination thereof (e.g., `xA'), they are used as flags to \fIls\-F\fR, making it act like `ls \-xF', `ls \-Fa', `ls \-FA' or a combination (e.g., `ls \-FxA'): `a' shows all files (even if they start with a `.'), `A' shows all files but `.' and `..', and `x' sorts across instead of down. If the second word of \fBlistflags\fR is set, it is used as the path to `ls(1)'. .TP 8 .B listjobs \fR(+) If set, all jobs are listed when a job is suspended. If set to `long', the listing is in long format. .TP 8 .B listlinks \fR(+) If set, the \fIls\-F\fR builtin command shows the type of file to which each symbolic link points. .TP 8 .B listmax \fR(+) The maximum number of items which the \fIlist-choices\fR editor command will list without asking first. .TP 8 .B listmaxrows \fR(+) The maximum number of rows of items which the \fIlist-choices\fR editor command will list without asking first. .TP 8 .B loginsh \fR(+) Set by the shell if it is a login shell. Setting or unsetting it within a shell has no effect. See also \fBshlvl\fR. .TP 8 .B logout \fR(+) Set by the shell to `normal' before a normal logout, `automatic' before an automatic logout, and `hangup' if the shell was killed by a hangup signal (see \fBSignal handling\fR). See also the \fBautologout\fR shell variable. .TP 8 .B mail A list of files and directories to check for incoming mail, optionally preceded by a numeric word. Before each prompt, if 10 minutes have passed since the last check, the shell checks each file and says `You have new mail.' (or, if \fBmail\fR contains multiple files, `You have new mail in \fIname\fR.') if the filesize is greater than zero in size and has a modification time greater than its access time. .PP .RS +8 .PD .PP If you are in a login shell, then no mail file is reported unless it has been modified after the time the shell has started up, to prevent redundant notifications. Most login programs will tell you whether or not you have mail when you log in. .PP If a file specified in \fBmail\fR is a directory, the shell will count each file within that directory as a separate message, and will report `You have \fIn\fR mails.' or `You have \fIn\fR mails in \fIname\fR.' as appropriate. This functionality is provided primarily for those systems which store mail in this manner, such as the Andrew Mail System. .PP If the first word of \fBmail\fR is numeric it is taken as a different mail checking interval, in seconds. .PP Under very rare circumstances, the shell may report `You have mail.' instead of `You have new mail.' .RE .TP 8 .B matchbeep \fR(+) If set to `never', completion never beeps. If set to `nomatch', it beeps only when there is no match. If set to `ambiguous', it beeps when there are multiple matches. If set to `notunique', it beeps when there is one exact and other longer matches. If unset, `ambiguous' is used. .TP 8 .B nobeep \fR(+) If set, beeping is completely disabled. See also \fBvisiblebell\fR. .TP 8 .B noclobber If set, restrictions are placed on output redirection to insure that files are not accidentally destroyed and that `>>' redirections refer to existing files, as described in the \fBInput/output\fR section. .TP 8 .B noding If set, disable the printing of `DING!' in the \fBprompt\fR time specifiers at the change of hour. .TP 8 .B noglob If set, \fBFilename substitution\fR and \fBDirectory stack substitution\fR (q.v.) are inhibited. This is most useful in shell scripts which do not deal with filenames, or after a list of filenames has been obtained and further expansions are not desirable. .TP 8 .B nokanji \fR(+) If set and the shell supports Kanji (see the \fBversion\fR shell variable), it is disabled so that the meta key can be used. .TP 8 .B nonomatch If set, a \fBFilename substitution\fR or \fBDirectory stack substitution\fR (q.v.) which does not match any existing files is left untouched rather than causing an error. It is still an error for the substitution to be malformed, e.g., `echo [' still gives an error. .TP 8 .B nostat \fR(+) A list of directories (or glob-patterns which match directories; see \fBFilename substitution\fR) that should not be \fIstat\fR(2)ed during a completion operation. This is usually used to exclude directories which take too much time to \fIstat\fR(2), for example \fI/afs\fR. .TP 8 .B notify If set, the shell announces job completions asynchronously. The default is to present job completions just before printing a prompt. .TP 8 .B oid \fR(+) The user's real organization ID. (Domain/OS only) .TP 8 .B owd \fR(+) The old working directory, equivalent to the `\-' used by \fIcd\fR and \fIpushd\fR. See also the \fBcwd\fR and \fBdirstack\fR shell variables. .TP 8 .B padhour If set, enable the printing of padding '0' for hours, in 24 and 12 hour formats. E.G.: 07:45:42 vs. 7:45:42. .TP 8 .B parseoctal To retain compatibily with older versions numeric variables starting with 0 are not interpreted as octal. Setting this variable enables proper octal parsing. .TP 8 .B path A list of directories in which to look for executable commands. A null word specifies the current directory. If there is no \fBpath\fR variable then only full path names will execute. \fBpath\fR is set by the shell at startup from the \fBPATH\fR environment variable or, if \fBPATH\fR does not exist, to a system-dependent default something like `(/usr/local/bin /usr/bsd /bin /usr/bin .)'. The shell may put `.' first or last in \fBpath\fR or omit it entirely depending on how it was compiled; see the \fBversion\fR shell variable. A shell which is given neither the \fB\-c\fR nor the \fB\-t\fR option hashes the contents of the directories in \fBpath\fR after reading \fI~/.tcshrc\fR and each time \fBpath\fR is reset. If one adds a new command to a directory in \fBpath\fR while the shell is active, one may need to do a \fIrehash\fR for the shell to find it. .TP 8 .B printexitvalue \fR(+) If set and an interactive program exits with a non-zero status, the shell prints `Exit \fBstatus\fR'. .TP 8 .B prompt The string which is printed before reading each command from the terminal. \fBprompt\fR may include any of the following formatting sequences (+), which are replaced by the given information: .PP .RS +8 .PD 0 .TP 4 %/ The current working directory. .TP 4 %~ The current working directory, but with one's home directory represented by `~' and other users' home directories represented by `~user' as per \fBFilename substitution\fR. `~user' substitution happens only if the shell has already used `~\fIuser\fR' in a pathname in the current session. .TP 4 %c[[0]\fIn\fR], %.[[0]\fIn\fR] The trailing component of the current working directory, or \fIn\fR trailing components if a digit \fIn\fR is given. If \fIn\fR begins with `0', the number of skipped components precede the trailing component(s) in the format `/<\fIskipped\fR>trailing'. If the \fBellipsis\fR shell variable is set, skipped components are represented by an ellipsis so the whole becomes `...trailing'. `~' substitution is done as in `%~' above, but the `~' component is ignored when counting trailing components. .TP 4 %C Like %c, but without `~' substitution. .TP 4 %h, %!, ! The current history event number. .TP 4 %M The full hostname. .TP 4 %m The hostname up to the first `.'. .TP 4 %S (%s) Start (stop) standout mode. .TP 4 %B (%b) Start (stop) boldfacing mode. .TP 4 %U (%u) Start (stop) underline mode. .TP 4 %t, %@ The time of day in 12-hour AM/PM format. .TP 4 %T Like `%t', but in 24-hour format (but see the \fBampm\fR shell variable). .TP 4 %p The `precise' time of day in 12-hour AM/PM format, with seconds. .TP 4 %P Like `%p', but in 24-hour format (but see the \fBampm\fR shell variable). .TP 4 \e\fIc\fR \fIc\fR is parsed as in \fIbindkey\fR. .TP 4 ^\fIc\fR \fIc\fR is parsed as in \fIbindkey\fR. .TP 4 %% A single `%'. .TP 4 %n The user name. .TP 4 %N The effective user name. .TP 4 %j The number of jobs. .TP 4 %d The weekday in `Day' format. .TP 4 %D The day in `dd' format. .TP 4 %w The month in `Mon' format. .TP 4 %W The month in `mm' format. .TP 4 %y The year in `yy' format. .TP 4 %Y The year in `yyyy' format. .TP 4 %l The shell's tty. .TP 4 %L Clears from the end of the prompt to end of the display or the end of the line. .TP 4 %$ Expands the shell or environment variable name immediately after the `$'. .TP 4 %# `>' (or the first character of the \fBpromptchars\fR shell variable) for normal users, `#' (or the second character of \fBpromptchars\fR) for the superuser. .TP 4 %{\fIstring\fR%} Includes \fIstring\fR as a literal escape sequence. It should be used only to change terminal attributes and should not move the cursor location. This cannot be the last sequence in \fBprompt\fR. .TP 4 %? The return code of the command executed just before the prompt. .TP 4 %R In \fBprompt2\fR, the status of the parser. In \fBprompt3\fR, the corrected string. In \fBhistory\fR, the history string. .PD .PP `%B', `%S', `%U' and `%{\fIstring\fR%}' are available in only eight-bit-clean shells; see the \fBversion\fR shell variable. .PP The bold, standout and underline sequences are often used to distinguish a superuser shell. For example, .IP "" 4 > set prompt = "%m [%h] %B[%@]%b [%/] you rang? " .br tut [37] \fB[2:54pm]\fR [/usr/accts/sys] you rang? _ .PP If `%t', `%@', `%T', `%p', or `%P' is used, and \fBnoding\fR is not set, then print `DING!' on the change of hour (i.e, `:00' minutes) instead of the actual time. .PP Set by default to `%# ' in interactive shells. .RE .TP 8 .B prompt2 \fR(+) The string with which to prompt in \fIwhile\fR and \fIforeach\fR loops and after lines ending in `\e'. The same format sequences may be used as in \fBprompt\fR (q.v.); note the variable meaning of `%R'. Set by default to `%R? ' in interactive shells. .TP 8 .B prompt3 \fR(+) The string with which to prompt when confirming automatic spelling correction. The same format sequences may be used as in \fBprompt\fR (q.v.); note the variable meaning of `%R'. Set by default to `CORRECT>%R (y|n|e|a)? ' in interactive shells. .TP 8 .B promptchars \fR(+) If set (to a two-character string), the `%#' formatting sequence in the \fBprompt\fR shell variable is replaced with the first character for normal users and the second character for the superuser. .TP 8 .B pushdtohome \fR(+) If set, \fIpushd\fR without arguments does `pushd ~', like \fIcd\fR. .TP 8 .B pushdsilent \fR(+) If set, \fIpushd\fR and \fIpopd\fR do not print the directory stack. .TP 8 .B recexact \fR(+) If set, completion completes on an exact match even if a longer match is possible. .TP 8 .B recognize_only_executables \fR(+) If set, command listing displays only files in the path that are executable. Slow. .TP 8 .B rmstar \fR(+) If set, the user is prompted before `rm *' is executed. .TP 8 .B rprompt \fR(+) The string to print on the right-hand side of the screen (after the command input) when the prompt is being displayed on the left. It recognizes the same formatting characters as \fBprompt\fR. It will automatically disappear and reappear as necessary, to ensure that command input isn't obscured, and will appear only if the prompt, command input, and itself will fit together on the first line. If \fBedit\fR isn't set, then \fBrprompt\fR will be printed after the prompt and before the command input. .TP 8 .B savedirs \fR(+) If set, the shell does `dirs \-S' before exiting. If the first word is set to a number, at most that many directory stack entries are saved. .TP 8 .B savehist If set, the shell does `history \-S' before exiting. If the first word is set to a number, at most that many lines are saved. (The number should be less than or equal to the number \fBhistory\fR entries; if it is set to greater than the number of \fBhistory\fR settings, only \fBhistory\fR entries will be saved) If the second word is set to `merge', the history list is merged with the existing history file instead of replacing it (if there is one) and sorted by time stamp and the most recent events are retained. If the second word of \fBsavehist\fR is `merge' and the third word is set to `lock', the history file update will be serialized with other shell sessions that would possibly like to merge history at exactly the same time. (+) .TP 8 .B sched \fR(+) The format in which the \fIsched\fR builtin command prints scheduled events; if not given, `%h\et%T\et%R\en' is used. The format sequences are described above under \fBprompt\fR; note the variable meaning of `%R'. .TP 8 .B shell The file in which the shell resides. This is used in forking shells to interpret files which have execute bits set, but which are not executable by the system. (See the description of \fBBuiltin and non-builtin command execution\fR.) Initialized to the (system-dependent) home of the shell. .TP 8 .B shlvl \fR(+) The number of nested shells. Reset to 1 in login shells. See also \fBloginsh\fR. .TP 8 .B status The exit status from the last command or backquote expansion, or any command in a pipeline is propagated to \fBstatus\fR. (This is also the default \fBcsh\fR behavior.) This default does not match what POSIX mandates (to return the status of the last command only). To match the POSIX behavior, you need to unset \fBanyerror\fR. .RS +8 .PP If the \fBanyerror\fR variable is unset, the exit status of a pipeline is determined only from the last command in the pipeline, and the exit status of a backquote expansion is \fInot\fR propagated to \fBstatus\fR. .PP If a command terminated abnormally, then 0200 is added to the status. Builtin commands which fail return exit status `1', all other builtin commands return status `0'. .RE .TP 8 .B symlinks \fR(+) Can be set to several different values to control symbolic link (`symlink') resolution: .RS +8 .PP If set to `chase', whenever the current directory changes to a directory containing a symbolic link, it is expanded to the real name of the directory to which the link points. This does not work for the user's home directory; this is a bug. .PP If set to `ignore', the shell tries to construct a current directory relative to the current directory before the link was crossed. This means that \fIcd\fRing through a symbolic link and then `cd ..'ing returns one to the original directory. This affects only builtin commands and filename completion. .PP If set to `expand', the shell tries to fix symbolic links by actually expanding arguments which look like path names. This affects any command, not just builtins. Unfortunately, this does not work for hard-to-recognize filenames, such as those embedded in command options. Expansion may be prevented by quoting. While this setting is usually the most convenient, it is sometimes misleading and sometimes confusing when it fails to recognize an argument which should be expanded. A compromise is to use `ignore' and use the editor command \fInormalize-path\fR (bound by default to ^X-n) when necessary. .PP Some examples are in order. First, let's set up some play directories: .IP "" 4 > cd /tmp .br > mkdir from from/src to .br > ln \-s from/src to/dst .PP Here's the behavior with \fBsymlinks\fR unset, .IP "" 4 > cd /tmp/to/dst; echo $cwd .br /tmp/to/dst .br > cd ..; echo $cwd .br /tmp/from .PP here's the behavior with \fBsymlinks\fR set to `chase', .IP "" 4 > cd /tmp/to/dst; echo $cwd .br /tmp/from/src .br > cd ..; echo $cwd .br /tmp/from .PP here's the behavior with \fBsymlinks\fR set to `ignore', .IP "" 4 > cd /tmp/to/dst; echo $cwd .br /tmp/to/dst .br > cd ..; echo $cwd .br /tmp/to .PP and here's the behavior with \fBsymlinks\fR set to `expand'. .IP "" 4 > cd /tmp/to/dst; echo $cwd .br /tmp/to/dst .br > cd ..; echo $cwd .br /tmp/to .br > cd /tmp/to/dst; echo $cwd .br /tmp/to/dst .br > cd ".."; echo $cwd .br /tmp/from .br > /bin/echo .. .br /tmp/to .br > /bin/echo ".." .br \&.. .PP Note that `expand' expansion 1) works just like `ignore' for builtins like \fIcd\fR, 2) is prevented by quoting, and 3) happens before filenames are passed to non-builtin commands. .RE .TP 8 .B tcsh \fR(+) The version number of the shell in the format `R.VV.PP', where `R' is the major release number, `VV' the current version and `PP' the patchlevel. .TP 8 .B term The terminal type. Usually set in \fI~/.login\fR as described under \fBStartup and shutdown\fR. .TP 8 .B time If set to a number, then the \fItime\fR builtin (q.v.) executes automatically after each command which takes more than that many CPU seconds. If there is a second word, it is used as a format string for the output of the \fItime\fR builtin. (u) The following sequences may be used in the format string: .PP .RS +8 .PD 0 .TP 4 %U The time the process spent in user mode in cpu seconds. .TP 4 %S The time the process spent in kernel mode in cpu seconds. .TP 4 %E The elapsed (wall clock) time in seconds. .TP 4 %P The CPU percentage computed as (%U + %S) / %E. .TP 4 %W Number of times the process was swapped. .TP 4 %X The average amount in (shared) text space used in Kbytes. .TP 4 %D The average amount in (unshared) data/stack space used in Kbytes. .TP 4 %K The total space used (%X + %D) in Kbytes. .TP 4 %M The maximum memory the process had in use at any time in Kbytes. .TP 4 %F The number of major page faults (page needed to be brought from disk). .TP 4 %R The number of minor page faults. .TP 4 %I The number of input operations. .TP 4 %O The number of output operations. .TP 4 %r The number of socket messages received. .TP 4 %s The number of socket messages sent. .TP 4 %k The number of signals received. .TP 4 %w The number of voluntary context switches (waits). .TP 4 %c The number of involuntary context switches. .PD .PP Only the first four sequences are supported on systems without BSD resource limit functions. The default time format is `%Uu %Ss %E %P %X+%Dk %I+%Oio %Fpf+%Ww' for systems that support resource usage reporting and `%Uu %Ss %E %P' for systems that do not. .PP Under Sequent's DYNIX/ptx, %X, %D, %K, %r and %s are not available, but the following additional sequences are: .PP .PD 0 .TP 4 %Y The number of system calls performed. .TP 4 %Z The number of pages which are zero-filled on demand. .TP 4 %i The number of times a process's resident set size was increased by the kernel. .TP 4 %d The number of times a process's resident set size was decreased by the kernel. .TP 4 %l The number of read system calls performed. .TP 4 %m The number of write system calls performed. .TP 4 %p The number of reads from raw disk devices. .TP 4 %q The number of writes to raw disk devices. .PD .PP and the default time format is `%Uu %Ss %E %P %I+%Oio %Fpf+%Ww'. Note that the CPU percentage can be higher than 100% on multi-processors. .RE .TP 8 .B tperiod \fR(+) The period, in minutes, between executions of the \fIperiodic\fR special alias. .TP 8 .B tty \fR(+) The name of the tty, or empty if not attached to one. .TP 8 .B uid \fR(+) The user's real user ID. .TP 8 .B user The user's login name. .TP 8 .B verbose If set, causes the words of each command to be printed, after history substitution (if any). Set by the \fB\-v\fR command line option. .TP 8 .B version \fR(+) The version ID stamp. It contains the shell's version number (see \fBtcsh\fR), origin, release date, vendor, operating system and machine (see \fBVENDOR\fR, \fBOSTYPE\fR and \fBMACHTYPE\fR) and a comma-separated list of options which were set at compile time. Options which are set by default in the distribution are noted. .PP .RS +8 .PD 0 .TP 6 8b The shell is eight bit clean; default .TP 6 7b The shell is not eight bit clean .TP 6 wide The shell is multibyte encoding clean (like UTF-8) .TP 6 nls The system's NLS is used; default for systems with NLS .TP 6 lf Login shells execute \fI/etc/csh.login\fR before instead of after \fI/etc/csh.cshrc\fR and \fI~/.login\fR before instead of after \fI~/.tcshrc\fR and \fI~/.history\fR. .TP 6 dl `.' is put last in \fBpath\fR for security; default .TP 6 nd `.' is omitted from \fBpath\fR for security .TP 6 vi \fIvi\fR(1)\-style editing is the default rather than \fIemacs\fR(1)\-style .TP 6 dtr Login shells drop DTR when exiting .TP 6 bye \fIbye\fR is a synonym for \fIlogout\fR and \fIlog\fR is an alternate name for \fIwatchlog\fR .TP 6 al \fBautologout\fR is enabled; default .TP 6 kan Kanji is used if appropriate according to locale settings, unless the \fBnokanji\fR shell variable is set .TP 6 sm The system's \fImalloc\fR(3) is used .TP 6 hb The `#! ' convention is emulated when executing shell scripts .TP 6 ng The \fInewgrp\fR builtin is available .TP 6 rh The shell attempts to set the \fBREMOTEHOST\fR environment variable .TP 6 afs The shell verifies your password with the kerberos server if local authentication fails. The \fBafsuser\fR shell variable or the \fBAFSUSER\fR environment variable override your local username if set. .PD .PP An administrator may enter additional strings to indicate differences in the local version. .RE .TP 8 .B vimode \fR(+) .RS +8 If unset, various key bindings change behavior to be more \fBemacs\fR(1)\-style: word boundaries are determined by \fBwordchars\fR versus other characters. .PP If set, various key bindings change behavior to be more \fBvi\fR(1)\-style: word boundaries are determined by \fBwordchars\fR versus whitespace versus other characters; cursor behavior depends upon current vi mode (command, delete, insert, replace). .PP This variable is unset by \fIbindkey\fR \fB-e\fR and set by \fIbindkey\fR \fB-v\fR. .B vimode may be explicitly set or unset by the user after those \fIbindkey\fR operations if required. .RE .TP 8 .B visiblebell \fR(+) If set, a screen flash is used rather than the audible bell. See also \fBnobeep\fR. .TP 8 .B watch \fR(+) A list of user/terminal pairs to watch for logins and logouts. If either the user is `any' all terminals are watched for the given user and vice versa. Setting \fBwatch\fR to `(any any)' watches all users and terminals. For example, .RS +8 .IP "" 4 set watch = (george ttyd1 any console $user any) .PP reports activity of the user `george' on ttyd1, any user on the console, and oneself (or a trespasser) on any terminal. .PP Logins and logouts are checked every 10 minutes by default, but the first word of \fBwatch\fR can be set to a number to check every so many minutes. For example, .IP "" 4 set watch = (1 any any) .PP reports any login/logout once every minute. For the impatient, the \fIlog\fR builtin command triggers a \fBwatch\fR report at any time. All current logins are reported (as with the \fIlog\fR builtin) when \fBwatch\fR is first set. .PP The \fBwho\fR shell variable controls the format of \fBwatch\fR reports. .RE .TP 8 .B who \fR(+) The format string for \fBwatch\fR messages. The following sequences are replaced by the given information: .PP .RS +8 .PD 0 .TP 4 %n The name of the user who logged in/out. .TP 4 %a The observed action, i.e., `logged on', `logged off' or `replaced \fIolduser\fR on'. .TP 4 %l The terminal (tty) on which the user logged in/out. .TP 4 %M The full hostname of the remote host, or `local' if the login/logout was from the local host. .TP 4 %m The hostname of the remote host up to the first `.'. The full name is printed if it is an IP address or an X Window System display. .PD .PP %M and %m are available on only systems that store the remote hostname in \fI/etc/utmp\fR. If unset, `%n has %a %l from %m.' is used, or `%n has %a %l.' on systems which don't store the remote hostname. .RE .TP 8 .B wordchars \fR(+) A list of non-alphanumeric characters to be considered part of a word by the \fIforward-word\fR, \fIbackward-word\fR etc., editor commands. If unset, the default value is determined based on the state of \fBvimode\fR: if \fBvimode\fR is unset, `*?_\-.[]~=' is used as the default; if \fBvimode\fR is set, `_' is used as the default. .SH ENVIRONMENT .TP 8 .B AFSUSER \fR(+) Equivalent to the \fBafsuser\fR shell variable. .TP 8 .B COLUMNS The number of columns in the terminal. See \fBTerminal management\fR. .TP 8 .B DISPLAY Used by X Window System (see \fIX\fR(1)). If set, the shell does not set \fBautologout\fR (q.v.). .TP 8 .B EDITOR The pathname to a default editor. Used by the \fIrun-fg-editor\fR editor command if the the \fBeditors\fR shell variable is unset. See also the \fBVISUAL\fR environment variable. .TP 8 .B GROUP \fR(+) Equivalent to the \fBgroup\fR shell variable. .TP 8 .B HOME Equivalent to the \fBhome\fR shell variable. .TP 8 .B HOST \fR(+) Initialized to the name of the machine on which the shell is running, as determined by the \fIgethostname\fR(2) system call. .TP 8 .B HOSTTYPE \fR(+) Initialized to the type of machine on which the shell is running, as determined at compile time. This variable is obsolete and will be removed in a future version. .TP 8 .B HPATH \fR(+) A colon-separated list of directories in which the \fIrun-help\fR editor command looks for command documentation. .TP 8 .B LANG Gives the preferred character environment. See \fBNative Language System support\fR. .TP 8 .B LC_CTYPE If set, only ctype character handling is changed. See \fBNative Language System support\fR. .TP 8 .B LINES The number of lines in the terminal. See \fBTerminal management\fR. .TP 8 .B LS_COLORS The format of this variable is reminiscent of the \fBtermcap(5)\fR file format; a colon-separated list of expressions of the form "\fIxx=string\fR", where "\fIxx\fR" is a two-character variable name. The variables with their associated defaults are: .PP .RS +8 .RS +4 .PD 0 .TP 12 no 0 Normal (non-filename) text .TP 12 fi 0 Regular file .TP 12 di 01;34 Directory .TP 12 ln 01;36 Symbolic link .TP 12 pi 33 Named pipe (FIFO) .TP 12 so 01;35 Socket .TP 12 do 01;35 Door .TP 12 bd 01;33 Block device .TP 12 cd 01;32 Character device .TP 12 ex 01;32 Executable file .TP 12 mi (none) Missing file (defaults to fi) .TP 12 or (none) Orphaned symbolic link (defaults to ln) .TP 12 lc ^[[ Left code .TP 12 rc m Right code .TP 12 ec (none) End code (replaces lc+no+rc) .PD .RE .PP You need to include only the variables you want to change from the default. .PP File names can also be colorized based on filename extension. This is specified in the \fBLS_COLORS\fR variable using the syntax \fB"*ext=string"\fR. For example, using ISO 6429 codes, to color all C\-language source files blue you would specify \fB"*.c=34"\fR. This would color all files ending in \fB.c\fR in blue (34) color. .PP Control characters can be written either in C\-style\-escaped notation, or in stty\-like ^\-notation. The C\-style notation adds \fB^[\fR for Escape, \fB\_\fR for a normal space character, and \fB?\fR for Delete. In addition, the \fB^[\fR escape character can be used to override the default interpretation of \fB^[\fR, \fB^\fR, \fB:\fR and \fB=\fR. .PP Each file will be written as \fB\fR \fB\fR \fB\fR \fB\fR \fB\fR. If the \fB\fR code is undefined, the sequence \fB\fR \fB \fB\fR will be used instead. This is generally more convenient to use, but less general. The left, right and end codes are provided so you don't have to type common parts over and over again and to support weird terminals; you will generally not need to change them at all unless your terminal does not use ISO 6429 color sequences but a different system. .PP If your terminal does use ISO 6429 color codes, you can compose the type codes (i.e., all except the \fBlc\fR, \fBrc\fR, and \fBec\fR codes) from numerical commands separated by semicolons. The most common commands are: .PP .RS +8 .PD 0 .TP 4 0 to restore default color .TP 4 1 for brighter colors .TP 4 4 for underlined text .TP 4 5 for flashing text .TP 4 30 for black foreground .TP 4 31 for red foreground .TP 4 32 for green foreground .TP 4 33 for yellow (or brown) foreground .TP 4 34 for blue foreground .TP 4 35 for purple foreground .TP 4 36 for cyan foreground .TP 4 37 for white (or gray) foreground .TP 4 40 for black background .TP 4 41 for red background .TP 4 42 for green background .TP 4 43 for yellow (or brown) background .TP 4 44 for blue background .TP 4 45 for purple background .TP 4 46 for cyan background .TP 4 47 for white (or gray) background .PD .RE .PP Not all commands will work on all systems or display devices. .PP A few terminal programs do not recognize the default end code properly. If all text gets colorized after you do a directory listing, try changing the \fBno\fR and \fBfi\fR codes from 0 to the numerical codes for your standard fore- and background colors. .RE .TP 8 .B MACHTYPE \fR(+) The machine type (microprocessor class or machine model), as determined at compile time. .TP 8 .B NOREBIND \fR(+) If set, printable characters are not rebound to \fIself-insert-command\fR. See \fBNative Language System support\fR. .TP 8 .B OSTYPE \fR(+) The operating system, as determined at compile time. .TP 8 .B PATH A colon-separated list of directories in which to look for executables. Equivalent to the \fBpath\fR shell variable, but in a different format. .TP 8 .B PWD \fR(+) Equivalent to the \fBcwd\fR shell variable, but not synchronized to it; updated only after an actual directory change. .TP 8 .B REMOTEHOST \fR(+) The host from which the user has logged in remotely, if this is the case and the shell is able to determine it. Set only if the shell was so compiled; see the \fBversion\fR shell variable. .TP 8 .B SHLVL \fR(+) Equivalent to the \fBshlvl\fR shell variable. .TP 8 .B SYSTYPE \fR(+) The current system type. (Domain/OS only) .TP 8 .B TERM Equivalent to the \fBterm\fR shell variable. .TP 8 .B TERMCAP The terminal capability string. See \fBTerminal management\fR. .TP 8 .B USER Equivalent to the \fBuser\fR shell variable. .TP 8 .B VENDOR \fR(+) The vendor, as determined at compile time. .TP 8 .B VISUAL The pathname to a default full-screen editor. Used by the \fIrun-fg-editor\fR editor command if the the \fBeditors\fR shell variable is unset. See also the \fBEDITOR\fR environment variable. .SH FILES .PD 0 .TP 16 .I /etc/csh.cshrc Read first by every shell. ConvexOS, Stellix and Intel use \fI/etc/cshrc\fR and NeXTs use \fI/etc/cshrc.std\fR. A/UX, AMIX, Cray and IRIX have no equivalent in \fIcsh\fR(1), but read this file in \fItcsh\fR anyway. Solaris 2.x does not have it either, but \fItcsh\fR reads \fI/etc/.cshrc\fR. (+) .TP 16 .I /etc/csh.login Read by login shells after \fI/etc/csh.cshrc\fR. ConvexOS, Stellix and Intel use \fI/etc/login\fR, NeXTs use \fI/etc/login.std\fR, Solaris 2.x uses \fI/etc/.login\fR and A/UX, AMIX, Cray and IRIX use \fI/etc/cshrc\fR. .TP 16 .I ~/.tcshrc \fR(+) Read by every shell after \fI/etc/csh.cshrc\fR or its equivalent. .TP 16 .I ~/.cshrc Read by every shell, if \fI~/.tcshrc\fR doesn't exist, after \fI/etc/csh.cshrc\fR or its equivalent. This manual uses `\fI~/.tcshrc\fR' to mean `\fI~/.tcshrc\fR or, if \fI~/.tcshrc\fR is not found, \fI~/.cshrc\fR'. .TP 16 .I ~/.history Read by login shells after \fI~/.tcshrc\fR if \fBsavehist\fR is set, but see also \fBhistfile\fR. .TP 16 .I ~/.login Read by login shells after \fI~/.tcshrc\fR or \fI~/.history\fR. The shell may be compiled to read \fI~/.login\fR before instead of after \fI~/.tcshrc\fR and \fI~/.history\fR; see the \fBversion\fR shell variable. .TP 16 .I ~/.cshdirs \fR(+) Read by login shells after \fI~/.login\fR if \fBsavedirs\fR is set, but see also \fBdirsfile\fR. .TP 16 .I /etc/csh.logout Read by login shells at logout. ConvexOS, Stellix and Intel use \fI/etc/logout\fR and NeXTs use \fI/etc/logout.std\fR. A/UX, AMIX, Cray and IRIX have no equivalent in \fIcsh\fR(1), but read this file in \fItcsh\fR anyway. Solaris 2.x does not have it either, but \fItcsh\fR reads \fI/etc/.logout\fR. (+) .TP 16 .I ~/.logout Read by login shells at logout after \fI/etc/csh.logout\fR or its equivalent. .TP 16 .I /bin/sh Used to interpret shell scripts not starting with a `#'. .TP 16 .I /tmp/sh* Temporary file for `<<'. .TP 16 .I /etc/passwd Source of home directories for `~name' substitutions. .PD .PP The order in which startup files are read may differ if the shell was so compiled; see \fBStartup and shutdown\fR and the \fBversion\fR shell variable. .SH "NEW FEATURES (+)" This manual describes \fItcsh\fR as a single entity, but experienced \fIcsh\fR(1) users will want to pay special attention to \fItcsh\fR's new features. .PP A command-line editor, which supports \fIemacs\fR(1)\-style or \fIvi\fR(1)\-style key bindings. See \fBThe command-line editor\fR and \fBEditor commands\fR. .PP Programmable, interactive word completion and listing. See \fBCompletion and listing\fR and the \fIcomplete\fR and \fIuncomplete\fR builtin commands. .PP \fBSpelling correction\fR (q.v.) of filenames, commands and variables. .PP \fBEditor commands\fR (q.v.) which perform other useful functions in the middle of typed commands, including documentation lookup (\fIrun-help\fR), quick editor restarting (\fIrun-fg-editor\fR) and command resolution (\fIwhich-command\fR). .PP An enhanced history mechanism. Events in the history list are time-stamped. See also the \fIhistory\fR command and its associated shell variables, the previously undocumented `#' event specifier and new modifiers under \fBHistory substitution\fR, the \fI*-history\fR, \fIhistory-search-*\fR, \fIi-search-*\fR, \fIvi-search-*\fR and \fItoggle-literal-history\fR editor commands and the \fBhistlit\fR shell variable. .PP Enhanced directory parsing and directory stack handling. See the \fIcd\fR, \fIpushd\fR, \fIpopd\fR and \fIdirs\fR commands and their associated shell variables, the description of \fBDirectory stack substitution\fR, the \fBdirstack\fR, \fBowd\fR and \fBsymlinks\fR shell variables and the \fInormalize-command\fR and \fInormalize-path\fR editor commands. .PP Negation in glob-patterns. See \fBFilename substitution\fR. .PP New \fBFile inquiry operators\fR (q.v.) and a \fIfiletest\fR builtin which uses them. .PP A variety of \fBAutomatic, periodic and timed events\fR (q.v.) including scheduled events, special aliases, automatic logout and terminal locking, command timing and watching for logins and logouts. .PP Support for the Native Language System (see \fBNative Language System support\fR), OS variant features (see \fBOS variant support\fR and the \fBecho_style\fR shell variable) and system-dependent file locations (see \fBFILES\fR). .PP Extensive terminal-management capabilities. See \fBTerminal management\fR. .PP New builtin commands including \fIbuiltins\fR, \fIhup\fR, \fIls\-F\fR, \fInewgrp\fR, \fIprintenv\fR, \fIwhich\fR and \fIwhere\fR (q.v.). .PP New variables that make useful information easily available to the shell. See the \fBgid\fR, \fBloginsh\fR, \fBoid\fR, \fBshlvl\fR, \fBtcsh\fR, \fBtty\fR, \fBuid\fR and \fBversion\fR shell variables and the \fBHOST\fR, \fBREMOTEHOST\fR, \fBVENDOR\fR, \fBOSTYPE\fR and \fBMACHTYPE\fR environment variables. .PP A new syntax for including useful information in the prompt string (see \fBprompt\fR), and special prompts for loops and spelling correction (see \fBprompt2\fR and \fBprompt3\fR). .PP Read-only variables. See \fBVariable substitution\fR. .SH BUGS When a suspended command is restarted, the shell prints the directory it started in if this is different from the current directory. This can be misleading (i.e., wrong) as the job may have changed directories internally. .PP Shell builtin functions are not stoppable/restartable. Command sequences of the form `a ; b ; c' are also not handled gracefully when stopping is attempted. If you suspend `b', the shell will then immediately execute `c'. This is especially noticeable if this expansion results from an \fIalias\fR. It suffices to place the sequence of commands in ()'s to force it to a subshell, i.e., `( a ; b ; c )'. .PP Control over tty output after processes are started is primitive; perhaps this will inspire someone to work on a good virtual terminal interface. In a virtual terminal interface much more interesting things could be done with output control. .PP Alias substitution is most often used to clumsily simulate shell procedures; shell procedures should be provided rather than aliases. .PP Control structures should be parsed rather than being recognized as built-in commands. This would allow control commands to be placed anywhere, to be combined with `|', and to be used with `&' and `;' metasyntax. .PP \fIforeach\fR doesn't ignore here documents when looking for its \fIend\fR. .PP It should be possible to use the `:' modifiers on the output of command substitutions. .PP The screen update for lines longer than the screen width is very poor if the terminal cannot move the cursor up (i.e., terminal type `dumb'). .PP \fBHPATH\fR and \fBNOREBIND\fR don't need to be environment variables. .PP Glob-patterns which do not use `?', `*' or `[]' or which use `{}' or `~' are not negated correctly. .PP The single-command form of \fIif\fR does output redirection even if the expression is false and the command is not executed. .PP \fIls\-F\fR includes file identification characters when sorting filenames and does not handle control characters in filenames well. It cannot be interrupted. .PP Command substitution supports multiple commands and conditions, but not cycles or backward \fIgoto\fRs. .PP Report bugs at https://bugs.astron.com/, preferably with fixes. If you want to help maintain and test tcsh, add yourself to the mailing list in https://mailman.astron.com/. .SH THE T IN TCSH In 1964, DEC produced the PDP-6. The PDP-10 was a later re-implementation. It was re-christened the DECsystem-10 in 1970 or so when DEC brought out the second model, the KI10. .PP TENEX was created at Bolt, Beranek & Newman (a Cambridge, Massachusetts think tank) in 1972 as an experiment in demand-paged virtual memory operating systems. They built a new pager for the DEC PDP-10 and created the OS to go with it. It was extremely successful in academia. .PP In 1975, DEC brought out a new model of the PDP-10, the KL10; they intended to have only a version of TENEX, which they had licensed from BBN, for the new box. They called their version TOPS-20 (their capitalization is trademarked). A lot of TOPS-10 users (`The OPerating System for PDP-10') objected; thus DEC found themselves supporting two incompatible systems on the same hardware--but then there were 6 on the PDP-11! .PP TENEX, and TOPS-20 to version 3, had command completion via a user-code-level subroutine library called ULTCMD. With version 3, DEC moved all that capability and more into the monitor (`kernel' for you Unix types), accessed by the COMND% JSYS (`Jump to SYStem' instruction, the supervisor call mechanism [are my IBM roots also showing?]). .PP The creator of tcsh was impressed by this feature and several others of TENEX and TOPS-20, and created a version of csh which mimicked them. .SH LIMITATIONS The system limits argument lists to ARG_MAX characters. .PP The number of arguments to a command which involves filename expansion is limited to 1/6th the number of characters allowed in an argument list. .PP Command substitutions may substitute no more characters than are allowed in an argument list. .PP To detect looping, the shell restricts the number of \fIalias\fR substitutions on a single line to 20. .SH "SEE ALSO" csh(1), emacs(1), ls(1), newgrp(1), sh(1), setpath(1), stty(1), su(1), tset(1), vi(1), x(1), access(2), execve(2), fork(2), killpg(2), pipe(2), setrlimit(2), sigvec(2), stat(2), umask(2), vfork(2), wait(2), malloc(3), setlocale(3), tty(4), a.out(5), termcap(5), environ(7), termio(7), Introduction to the C Shell .SH VERSION -This manual documents tcsh 6.21.00 (Astron) 2019-05-08. +This manual documents tcsh 6.22.03 (Astron) 2020-11-18. .SH AUTHORS .PD 0 .TP 2 William Joy Original author of \fIcsh\fR(1) .TP 2 J.E. Kulp, IIASA, Laxenburg, Austria Job control and directory stack features .TP 2 Ken Greer, HP Labs, 1981 File name completion .TP 2 Mike Ellis, Fairchild, 1983 Command name recognition/completion .TP 2 Paul Placeway, Ohio State CIS Dept., 1983-1993 Command line editor, prompt routines, new glob syntax and numerous fixes and speedups .TP 2 Karl Kleinpaste, CCI 1983-4 Special aliases, directory stack extraction stuff, login/logout watch, scheduled events, and the idea of the new prompt format .TP 2 Rayan Zachariassen, University of Toronto, 1984 \fIls\-F\fR and \fIwhich\fR builtins and numerous bug fixes, modifications and speedups .TP 2 Chris Kingsley, Caltech Fast storage allocator routines .TP 2 Chris Grevstad, TRW, 1987 Incorporated 4.3BSD \fIcsh\fR into \fItcsh\fR .TP 2 Christos S. Zoulas, Cornell U. EE Dept., 1987-94 Ports to HPUX, SVR2 and SVR3, a SysV version of getwd.c, SHORT_STRINGS support and a new version of sh.glob.c .TP 2 James J Dempsey, BBN, and Paul Placeway, OSU, 1988 A/UX port .TP 2 Daniel Long, NNSC, 1988 \fBwordchars\fR .TP 2 Patrick Wolfe, Kuck and Associates, Inc., 1988 \fIvi\fR mode cleanup .TP 2 David C Lawrence, Rensselaer Polytechnic Institute, 1989 \fBautolist\fR and ambiguous completion listing .TP 2 Alec Wolman, DEC, 1989 Newlines in the prompt .TP 2 Matt Landau, BBN, 1989 \fI~/.tcshrc\fR .TP 2 Ray Moody, Purdue Physics, 1989 Magic space bar history expansion .TP 2 Mordechai ????, Intel, 1989 printprompt() fixes and additions .TP 2 Kazuhiro Honda, Dept. of Computer Science, Keio University, 1989 Automatic spelling correction and \fBprompt3\fR .TP 2 Per Hedeland, Ellemtel, Sweden, 1990- Various bugfixes, improvements and manual updates .TP 2 Hans J. Albertsson (Sun Sweden) \fBampm\fR, \fIsettc\fR and \fItelltc\fR .TP 2 Michael Bloom Interrupt handling fixes .TP 2 Michael Fine, Digital Equipment Corp Extended key support .TP 2 Eric Schnoebelen, Convex, 1990 Convex support, lots of \fIcsh\fR bug fixes, save and restore of directory stack .TP 2 Ron Flax, Apple, 1990 A/UX 2.0 (re)port .TP 2 Dan Oscarsson, LTH Sweden, 1990 NLS support and simulated NLS support for non NLS sites, fixes .TP 2 Johan Widen, SICS Sweden, 1990 \fBshlvl\fR, Mach support, \fIcorrect-line\fR, 8-bit printing .TP 2 Matt Day, Sanyo Icon, 1990 POSIX termio support, SysV limit fixes .TP 2 Jaap Vermeulen, Sequent, 1990-91 Vi mode fixes, expand-line, window change fixes, Symmetry port .TP 2 Martin Boyer, Institut de recherche d'Hydro-Quebec, 1991 \fBautolist\fR beeping options, modified the history search to search for the whole string from the beginning of the line to the cursor. .TP 2 Scott Krotz, Motorola, 1991 Minix port .TP 2 David Dawes, Sydney U. Australia, Physics Dept., 1991 SVR4 job control fixes .TP 2 Jose Sousa, Interactive Systems Corp., 1991 Extended \fIvi\fR fixes and \fIvi\fR delete command .TP 2 Marc Horowitz, MIT, 1991 ANSIfication fixes, new exec hashing code, imake fixes, \fIwhere\fR .TP 2 Bruce Sterling Woodcock, sterling@netcom.com, 1991-1995 ETA and Pyramid port, Makefile and lint fixes, \fBignoreeof\fR=n addition, and various other portability changes and bug fixes .TP 2 Jeff Fink, 1992 \fIcomplete-word-fwd\fR and \fIcomplete-word-back\fR .TP 2 Harry C. Pulley, 1992 Coherent port .TP 2 Andy Phillips, Mullard Space Science Lab U.K., 1992 VMS-POSIX port .TP 2 Beto Appleton, IBM Corp., 1992 Walking process group fixes, \fIcsh\fR bug fixes, POSIX file tests, POSIX SIGHUP .TP 2 Scott Bolte, Cray Computer Corp., 1992 CSOS port .TP 2 Kaveh R. Ghazi, Rutgers University, 1992 Tek, m88k, Titan and Masscomp ports and fixes. Added autoconf support. .TP 2 Mark Linderman, Cornell University, 1992 OS/2 port .TP 2 Mika Liljeberg, liljeber@kruuna.Helsinki.FI, 1992 Linux port .TP 2 Tim P. Starrin, NASA Langley Research Center Operations, 1993 Read-only variables .TP 2 Dave Schweisguth, Yale University, 1993-4 New man page and tcsh.man2html .TP 2 Larry Schwimmer, Stanford University, 1993 AFS and HESIOD patches .TP 2 Luke Mewburn, RMIT University, 1994-6 Enhanced directory printing in prompt, added \fBellipsis\fR and \fBrprompt\fR. .TP 2 Edward Hutchins, Silicon Graphics Inc., 1996 Added implicit cd. .TP 2 Martin Kraemer, 1997 Ported to Siemens Nixdorf EBCDIC machine .TP 2 Amol Deshpande, Microsoft, 1997 Ported to WIN32 (Windows/95 and Windows/NT); wrote all the missing library and message catalog code to interface to Windows. .TP 2 Taga Nayuta, 1998 Color ls additions. .PD .PP .SH "THANKS TO" Bryan Dunlap, Clayton Elwell, Karl Kleinpaste, Bob Manson, Steve Romig, Diana Smetters, Bob Sutterfield, Mark Verber, Elizabeth Zwicky and all the other people at Ohio State for suggestions and encouragement .PP All the people on the net, for putting up with, reporting bugs in, and suggesting new additions to each and every version .PP Richard M. Alderson III, for writing the `T in tcsh' section diff --git a/contrib/tcsh/tcsh.man.new b/contrib/tcsh/tcsh.man.new index cb82955db317..dae20d6745db 100644 --- a/contrib/tcsh/tcsh.man.new +++ b/contrib/tcsh/tcsh.man.new @@ -1,9733 +1,9745 @@ .\" .\" Copyright (c) 1980, 1990, 1993 .\" The Regents of the University of California. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS `AS IS' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LESS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" - Indent in multiples of 4, usually 8. .\" .\" - Use \` for literal back-quote (`). .\" .\" - Use \e for literal backslash (\). .\" .\" - Use \-, not -. .\" .\" - Include the tilde when naming dot files. .Pa ~/.login , not .Pa .login .\" .\" - Refer to external commands in man page format, e.g., .Xr csh 1 .\" However, tcsh is .Nm , because this is the tcsh man page (and .\" see the next note anyway). .\" .\" - Say .Sq the shell , not .Sq tcsh , .\" unless distinguishing between tcsh and csh. .\" .\" - Say .Sq shell variable / .Sq environment variable instead of .\" .Sq variable and .Sq builtin command / .Sq editor command instead of .\" .Sq builtin or .Sq command .\" unless the distinction is absolutely clear from context. .\" .\" - Use the simple present tense. .\" .Sq The shell uses , not .Sq The shell will use .\" .\" - IMPORTANT: Cross-reference as much as possible. Commands, variables, .\" etc. in the reference section should be mentioned in the appropriate .\" descriptive section, or at least in the reference-section description .\" of another command (or whatever) which is mentioned in a description .\" section. Remember to note OS-specific things in "OS variant support", .\" new features in NEW FEATURES and referenced external commands in SEE .\" ALSO. .\" .\" - tcsh.man2html depends heavily on the specific nroff commands used in the .\" man page when the script was written. Please stick closely to the style .\" used here if you can. In particular, please don't use nroff commands .\" which aren't already used herein. .\" -.Dd May 8, 2019 +.Dd Noverber 18, 2020 .Dt TCSH 1 -.Os Astron 6.21.00 +.Os Astron 6.22.02 .Sh NAME .Nm tcsh .Nd C shell with file name completion and command line editing .Sh SYNOPSIS .Nm .Op Fl bcdefFimnqstvVxX .Op Fl Dname Ns Op =value .Op Ar arg ... .Nm .Fl l .Ek .Sh DESCRIPTION .Nm is an enhanced but completely compatible version of the Berkeley UNIX C shell, .Xr csh 1 . It is a command language interpreter usable both as an interactive login shell and a shell script command processor. It includes a command-line editor (see .Sx The command-line editor ) programmable word completion (see .Sx Completion and listing ) spelling correction (see .Sx Spelling correction ) , a history mechanism (see .Sx History substitution ) , job control (see .Sx Jobs ) and a C-like syntax. The .Sx NEW FEATURES section describes major enhancements of .Nm over .Xr csh 1 . Throughout this manual, features of .Nm not found in most .Xr csh 1 implementations (specifically, the 4.4BSD one) are labeled with .Sq (+) , and features which are present in .Xr csh 1 but not usually documented are labeled with .Sq (u) . .Bl -tag .Ss Argument list processing If the first argument (argument 0) to the shell is .Sq \- then it is a login shell. A login shell can be also specified by invoking the shell with the .Fl l flag as the only argument. .Pp The rest of the flag arguments are interpreted as follows: .Bl -tag -width indent .It Fl b Forces a .Dq break from option processing, causing any further shell arguments to be treated as non-option arguments. The remaining arguments will not be interpreted as shell options. This may be used to pass options to a shell script without confusion or possible subterfuge. The shell will not run a set-user ID script without this option. .It Fl c Commands are read from the following argument (which must be present, and must be a single argument), stored in the .Va command shell variable for reference, and executed. Any remaining arguments are placed in the .Va argv shell variable. .It Fl d The shell loads the directory stack from .Pa ~/.cshdirs as described under .Sx Startup and shutdown , whether or not it is a login shell. (+) .It Fl Dname Ns Op =value Sets the environment variable .Va name .Dv value . (Domain/OS only) (+) .It Fl e The shell exits if any invoked command terminates abnormally or yields a non-zero exit status. .It Fl f The shell does not load any resource or startup files, or perform any command hashing, and thus starts faster. .It Fl F The shell uses .Xr fork 2 instead of .Xr vfork 2 to spawn processes. (+) .It Fl i The shell is interactive and prompts for its top-level input, even if it appears to not be a terminal. Shells are interactive without this option if their inputs and outputs are terminals. .It Fl l The shell is a login shell. Applicable only if .Fl l is the only flag specified. .It Fl m The shell loads .Pa ~/.tcshrc even if it does not belong to the effective user. Newer versions of .Xr su 1 can pass .Fl m to the shell. (+) .It Fl n The shell parses commands but does not execute them. This aids in debugging shell scripts. .It Fl q The shell accepts SIGQUIT (see .Sx Signal handling ) and behaves when it is used under a debugger. Job control is disabled. (u) .It Fl s Command input is taken from the standard input. .It Fl t The shell reads and executes a single line of input. A .Sq \e may be used to escape the newline at the end of this line and continue onto another line. .It Fl v Sets the .Va verbose shell variable, so that command input is echoed after history substitution. .It Fl x Sets the .Va echo shell variable, so that commands are echoed immediately before execution. .It Fl V Sets the .Va verbose shell variable even before executing .Pa ~/.tcshrc . .It Fl X Is to .Fl x as .Fl V is to .Fl v . .TP 4 .It Fl \-help Print a help message on the standard output and exit. (+) .It Fl \-version Print the version/platform/compilation options on the standard output and exit. This information is also contained in the .Va version shell variable. (+) .El .Pp After processing of flag arguments, if arguments remain but none of the .Fl c , .Fl i , .Fl s , or .Fl t options were given, the first argument is taken as the name of a file of commands, or .Dq script , to be executed. The shell opens this file and saves its name for possible resubstitution by .Sq $0 . Because many systems use either the standard version 6 or version 7 shells whose shell scripts are not compatible with this shell, the shell uses such a .Sq standard shell to execute a script whose first character is not a .Sq # , i.e., that does not start with a comment. .Pp Remaining arguments are placed in the .Va argv shell variable. .Ss Startup and shutdown A login shell begins by executing commands from the system files .Pa /etc/csh.cshrc and .Pa /etc/csh.login . It then executes commands from files in the user's .Pa home directory: first .Pa ~/.tcshrc (+) or, if .Pa ~/.tcshrc is not found, .Pa ~/.cshrc , then .Pa ~/.history (or the value of the .Va histfile shell variable), then .Pa ~/.login , and finally .Pa ~/.cshdirs (or the value of the .Va dirsfile shell variable) (+). The shell may read .Pa /etc/csh.login before instead of after .Pa /etc/csh.cshrc , and .Pa ~/.login before instead of after .Pa ~/.tcshrc or .Pa ~/.cshrc and .Pa ~/.history , if so compiled; see the .Va version shell variable. (+) .Pp Non-login shells read only .Pa /etc/csh.cshrc and .Pa ~/.tcshrc or .Pa ~/.cshrc on startup. .Pp For examples of startup files, please consult: .Lk http://tcshrc.sourceforge.net .Pp Commands like .Xr stty 1 and .Xr tset 1 , which need be run only once per login, usually go in one's .Pa ~/.login file. Users who need to use the same set of files with both .Xr csh 1 and .Nm can have only a .Pa ~/.cshrc which checks for the existence of the .Va tcsh shell variable (q.v.) before using .Nm \- specific commands, or can have both a .Pa ~/.cshrc and a .Pa ~/.tcshrc which .Ic sources (see the builtin command) .Pa ~/.cshrc . The rest of this manual uses .Pa ~/.tcshrc to mean .Pa ~/.tcshrc or, if .Pa ~/.tcshrc is not found, .Pa ~/.cshrc . .Pp In the normal case, the shell begins reading commands from the terminal, prompting with .Sq >\~ . (Processing of arguments and the use of the shell to process files containing command scripts are described later.) The shell repeatedly reads a line of command input, breaks it into words, places it on the command history list, parses it and executes each command in the line. .Pp One can log out by typing .Sq ^D on an empty line, .Sq logout or .Sq login or via the shell's autologout mechanism (see the .Va autologout shell variable). When a login shell terminates it sets the .Va logout shell variable to .Sq normal or .Sq automatic as appropriate, then executes commands from the files .Pa /etc/csh.logout and .Pa ~/.logout . The shell may drop DTR on logout if so compiled; see the .Va version shell variable. .Pp The names of the system login and logout files vary from system to system for compatibility with different .Xr csh 1 variants; see .Sx FILES . .Ss Editing We first describe .Sx The command-line editor The .Sx Completion and listing and .Sx Spelling correction sections describe two sets of functionality that are implemented as editor commands but which deserve their own treatment. Finally, .Sx Editor commands lists and describes the editor commands specific to the shell and their default bindings. .Ss The command-line editor (+) Command-line input can be edited using key sequences much like those used in .Xr emacs 1 or .Xr vi 1 . The editor is active only when the .Va edit shell variable is set, which it is by default in interactive shells. The .Ic bindkey builtin can display and change key bindings. .Xr emacs 1 style key bindings are used by default (unless the shell was compiled otherwise; see the .Va version shell variable), but .Ic bindkey can change the key bindings to .Xr vi 1 style bindings en masse. .Pp The shell always binds the arrow keys (as defined in the .Va TERMCAP environment variable) to: .Pp .Bl -tag -width right -compact -offset indent .It down .Ic down-history .It up .Ic up-history .It left .Ic backward-char .It right .Ic forward-char .El .Pp unless doing so would alter another single-character binding. One can set the arrow key escape sequences to the empty string with .Va settc to prevent these bindings. The ANSI/VT100 sequences for arrow keys are always bound. .Pp Other key bindings are, for the most part, what .Xr emacs 1 and .Xr vi 1 users would expect and can easily be displayed by .Ic bindkey , so there is no need to list them here. Likewise, .Ic bindkey can list the editor commands with a short description of each. Certain key bindings have different behavior depending if .Xr emacs 1 or .Xr vi 1 style bindings are being used; see .Va vimode for more information. .Pp Note that editor commands do not have the same notion of a .Dq word as does the shell. The editor delimits words with any non-alphanumeric characters not in the shell variable .Va wordchars , while the shell recognizes only whitespace and some of the characters with special meanings to it, listed under .Sx Lexical structure . .Ss Completion and listing (+) The shell is often able to complete words when given a unique abbreviation. Type part of a word (for example .Ic ls .Pa /usr/lost ) and hit the tab key to run the .Ic complete-word editor command. The shell completes the filename .Pa /usr/lost to .Pa /usr/lost+found/ , replacing the incomplete word with the complete word in the input buffer. (Note the terminal .Sq / ; completion adds a .Sq / to the end of completed directories and a space to the end of other completed words, to speed typing and provide a visual indicator of successful completion. The .Va addsuffix shell variable can be unset to prevent this.) If no match is found (perhaps .Pa /usr/lost+found doesn't exist), the terminal bell rings. If the word is already complete (perhaps there is a .Pa /usr/lost on your system, or perhaps you were thinking too far ahead and typed the whole thing) a .Sq / or space is added to the end if it isn't already there. .Pp Completion works anywhere in the line, not at just the end; completed text pushes the rest of the line to the right. Completion in the middle of a word often results in leftover characters to the right of the cursor that need to be deleted. .Pp Commands and variables can be completed in much the same way. For example, typing .Sq em[tab] would complete .Sq em to .Sq emacs if .Pa emacs were the only command on your system beginning with .Sq em . Completion can find a command in any directory in .Pa path or if given a full pathname. Typing .Sq echo $ar[tab] would complete .Sq $ar to .Sq $argv if no other variable began with .Sq ar . .Pp The shell parses the input buffer to determine whether the word you want to complete should be completed as a filename, command or variable. The first word in the buffer and the first word following .Sq \&; , .Sq | , .Sq |& , .Sq && or .Sq || is considered to be a command. A word beginning with .Sq $ is considered to be a variable. Anything else is a filename. An empty line is .Sq completed as a filename. .Pp You can list the possible completions of a word at any time by typing .Sq ^D to run the .Ic delete-char-or-list-or-eof editor command. The shell lists the possible completions using the .Ic ls\-F builtin (q.v.) and reprints the prompt and unfinished command line, for example: .Bd -literal -offset indent > ls /usr/l[^D] lbin/ lib/ local/ lost+found/ > ls /usr/l .Ed .Pp If the .Va autolist shell variable is set, the shell lists the remaining choices (if any) whenever completion fails: .Bd -literal -offset indent > set autolist > nm /usr/lib/libt[tab] libtermcap.a@ libtermlib.a@ > nm /usr/lib/libterm .Ed .Pp If .Va autolist shell variable is set to .Sq ambiguous , choices are listed only when completion fails and adds no new characters to the word being completed. .Pp A filename to be completed can contain variables, your own or others' home directories abbreviated with .Sq ~ (see .Sx Filename substitution ) and directory stack entries abbreviated with .Sq = (see .Sx Directory stack substitution ) . For example, .Bd -literal -offset indent > ls ~k[^D] kahn kas kellogg > ls ~ke[tab] > ls ~kellogg/ .Ed or .Bd -literal -offset indent > set local = /usr/local > ls $lo[tab] > ls $local/[^D] bin/ etc/ lib/ man/ src/ > ls $local/ .Ed .Pp Note that variables can also be expanded explicitly with the .Ic expand-variables editor command. .Pp .Ic delete-char-or-list-or-eof lists at only the end of the line; in the middle of a line it deletes the character under the cursor and on an empty line it logs one out or, if then .Va ignoreeof variable is set, does nothing. .Sq M-^D , bound to the editor command .Ic list-choices , lists completion possibilities anywhere on a line, and .Ic list-choices (or any one of the related editor commands that do or don't delete, list and/or log out, listed under .Ic delete-char-or-list-or-eof ) can be bound to .Sq ^D with the .Ic bindkey builtin command if so desired. .Pp The .Ic complete-word-fwd and .Ic complete-word-back editor commands (not bound to any keys by default) can be used to cycle up and down through the list of possible completions, replacing the current word with the next or previous word in the list. .Pp The shell variable .Va fignore can be set to a list of suffixes to be ignored by completion. Consider the following: .Bd -literal -offset indent > ls Makefile condiments.h~ main.o side.c README main.c meal side.o condiments.h main.c~ > set fignore = (.o \e~) > emacs ma[^D] main.c main.c~ main.o > emacs ma[tab] > emacs main.c .Ed .Pp .Sq main.c~ and .Sq main.o are ignored by completion (but not listing), because they end in suffixes in .Va fignore . Note that a .Sq \e was needed in front of .Sq ~ to prevent it from being expanded to .Va home as described under .Sx Filename substitution . .Va fignore is ignored if only one completion is possible. .Pp If the .Va complete shell variable is set to .Sq enhance , completion 1) ignores case and 2) considers periods, hyphens and underscores .Sq ( \&. , .Sq \&- and .Sq _ ) to be word separators and hyphens and underscores to be equivalent. If you had the following files .Bd -literal -offset indent comp.lang.c comp.lang.perl comp.std.c++ comp.lang.c++ comp.std.c .Ed .Pp and typed .Sq mail \-f c.l.c[tab] , it would be completed to .Sq mail \-f comp.lang.c , and .Sq ^D would list .Sq comp.lang.c and .Sq comp.lang.c++ . .Sq mail \-f c..c++[^D] would list .Sq comp.lang.c++ and .Sq comp.std.c++ . Typing .Sq rm a\-\-file[^D] in the following directory .Bd -literal -offset indent A_silly_file a-hyphenated-file another_silly_file .Ed .Pp would list all three files, because case is ignored and hyphens and underscores are equivalent. Periods, however, are not equivalent to hyphens or underscores. .Pp If the .Va complete shell variable is set to .Sq Enhance , completion ignores case and differences between a hyphen and an underscore word separator only when the user types a lowercase character or a hyphen. Entering an uppercase character or an underscore will not match the corresponding lowercase character or hyphen word separator. Typing .Sq rm a\-\-file[^D] in the directory of the previous example would still list all three files, but typing .Sq rm A\-\-file would match only .Sq A_silly_file and typing .Sq rm a__file[^D] would match just .Sq A_silly_file and .Sq another_silly_file because the user explicitly used an uppercase or an underscore character. .Pp Completion and listing are affected by several other shell variables: .Va recexact can be set to complete on the shortest possible unique match, even if more typing might result in a longer match: .Bd -literal -offset indent > ls fodder foo food foonly > set recexact > rm fo[tab] .Ed .Pp just beeps, because .Sq fo could expand to .Sq fod or .Sq foo , but if we type another .Sq o , .Bd -literal -offset indent > rm foo[tab] > rm foo .Ed .Pp the completion completes on .Sq foo , even though .Sq food and .Sq foonly also match. .Va autoexpand can be set to run the .Ic expand-history editor command before each completion attempt, .Va autocorrect can be set to spelling-correct the word to be completed (see .Sx Spelling correction ) before each completion attempt and .Va correct can be set to complete commands automatically after one hits .Sq return . .Va matchbeep can be set to make completion beep or not beep in a variety of situations, and .Va nobeep can be set to never beep at all. .Va nostat can be set to a list of directories and/or patterns that match directories to prevent the completion mechanism from .Xr stat 2 ing those directories. .Va listmax and .Va listmaxrows can be set to limit the number of items and rows (respectively) that are listed without asking first. .Va recognize_only_executables can be set to make the shell list only executables when listing commands, but it is quite slow. .Pp Finally, the .Ic complete builtin command can be used to tell the shell how to complete words other than filenames, commands and variables. Completion and listing do not work on glob-patterns (see .Sx Filename substitution ) , but the .Ic list-glob and .Ic expand-glob editor commands perform equivalent functions for glob-patterns. .Ss Spelling correction (+) The shell can sometimes correct the spelling of filenames, commands and variable names as well as completing and listing them. .Pp Individual words can be spelling-corrected with the .Ic spell-word editor command (usually bound to M-s and M-S) and the entire input buffer with .Ic spell-line (usually bound to M-$). The .Va correct shell variable can be set to .Dv cmd to correct the command name or .Dv all to correct the entire line each time return is typed, and .Va autocorrect can be set to correct the word to be completed before each completion attempt. .Pp When spelling correction is invoked in any of these ways and the shell thinks that any part of the command line is misspelled, it prompts with the corrected line: .Bd -literal -offset indent > set correct = cmd > lz /usr/bin CORRECT>ls /usr/bin (y|n|e|a)? .Ed .Pp One can answer .Sq y or space to execute the corrected line, .Sq e to leave the uncorrected command in the input buffer, .Sq a to abort the command as if .Sq ^C had been hit, and anything else to execute the original line unchanged. .Pp Spelling correction recognizes user-defined completions (see the .Ic complete builtin command). If an input word in a position for which a completion is defined resembles a word in the completion list, spelling correction registers a misspelling and suggests the latter word as a correction. However, if the input word does not match any of the possible completions for that position, spelling correction does not register a misspelling. .Pp Like completion, spelling correction works anywhere in the line, pushing the rest of the line to the right and possibly leaving extra characters to the right of the cursor. .Ss Editor commands (+) .Ic bindkey lists key bindings and .Ic bindkey \-l lists and briefly describes editor commands. Only new or especially interesting editor commands are described here. See .Xr emacs 1 and .Xr vi 1 for descriptions of each editor's key bindings. .Pp The character or characters to which each command is bound by default is given in parentheses. .Sq ^character means a control character and .Sq M-character a meta character, typed as .Sq escape-character on terminals without a meta key. Case counts, but commands that are bound to letters by default are bound to both lower- and uppercase letters for convenience. .Bl -tag -width indent .It Ic backward-char Ar (^B, left) Move back a character. Cursor behavior modified by .Va vimode .It Ic backward-delete-word Ar (M-^H, M-^?) Cut from beginning of current word to cursor \- saved in cut buffer. Word boundary behavior modified by .Va vimode .It Ic backward-word Ar (M-b, M-B) Move to beginning of current word. Word boundary and cursor behavior modified by .Va vimode .It Ic beginning-of-line Ar (^A, home) Move to beginning of line. Cursor behavior modified by .Va vimode .It Ic capitalize-word Ar (M-c, M-C) Capitalize the characters from cursor to end of current word. Word boundary behavior modified by .Va vimode .It Ic complete-word Ar (tab) Completes a word as described under .Sx Completion and listing .It Ic complete-word-back Ar (not bound) Like .Ic complete-word-fwd , but steps up from the end of the list. .It Ic complete-word-fwd Ar (not bound) Replaces the current word with the first word in the list of possible completions. May be repeated to step down through the list. At the end of the list, beeps and reverts to the incomplete word. .It Ic complete-word-raw Ar (^X-tab) Like .Ic complete-word , but ignores user-defined completions. .It Ic copy-prev-word Ar (M-^_) Copies the previous word in the current line into the input buffer. See also .Ic insert-last-word Word boundary behavior modified by .Va vimode .It Ic dabbrev-expand Ar (M-/) Expands the current word to the most recent preceding one for which the current is a leading substring, wrapping around the history list (once) if necessary. Repeating .Ic dabbrev-expand without any intervening typing changes to the next previous word etc., skipping identical matches much like .Ic history-search-backward does. .It Ic delete-char Ar (not bound) Deletes the character under the cursor. See also .Ic delete-char-or-list-or-eof Cursor behavior modified by .Va vimode .It Ic delete-char-or-eof Ar (not bound) Does .Ic delete-char if there is a character under the cursor or .Ic end-of-file on an empty line. See also .Ic delete-char-or-list-or-eof Cursor behavior modified by .Va vimode .It Ic delete-char-or-list Ar (not bound) Does .Ic delete-char if there is a character under the cursor or .Ic list-choices at the end of the line. See also .Ic delete-char-or-list-or-eof .It Ic delete-char-or-list-or-eof Ar (^D) Does .Ic delete-char if there is a character under the cursor, .Ic list-choices at the end of the line or .Ic end-of-file on an empty line. See also those three commands, each of which does only a single action, and .Ic delete-char-or-eof , .Ic delete-char-or-list and .Ic list-or-eof , each of which does a different two out of the three. .It Ic delete-word Ar (M-d, M-D) Cut from cursor to end of current word \- save in cut buffer. Word boundary behavior modified by .Va vimode .It Ic down-history Ar (down-arrow, ^N) Like .Ic up-history , but steps down, stopping at the original input line. .It Ic downcase-word Ar (M-l, M-L) Lowercase the characters from cursor to end of current word. Word boundary behavior modified by .Va vimode .It Ic end-of-file Ar (not bound) Signals an end of file, causing the shell to exit unless the .Va ignoreeof shell variable (q.v.) is set to prevent this. See also .Ic delete-char-or-list-or-eof .It Ic end-of-line Ar (^E, end) Move cursor to end of line. Cursor behavior modified by .Va vimode .It Ic expand-history Ar (M-space) Expands history substitutions in the current word. See .Sx History substitution See also .Ic magic-space , .Ic toggle-literal-history and the .Va autoexpand shell variable. .It Ic expand-glob Ar (^X-*) Expands the glob-pattern to the left of the cursor. See .Sx Filename substitution .It Ic expand-line Ar (not bound) Like .Ic expand-history , but expands history substitutions in each word in the input buffer. .It Ic expand-variables Ar (^X-$) Expands the variable to the left of the cursor. See .Sx Variable substitution .It Ic forward-char Ar (^F, right) Move forward one character. Cursor behavior modified by .Va vimode .It Ic forward-word Ar (M-f, M-F) Move forward to end of current word. Word boundary and cursor behavior modified by .Va vimode .It Ic history-search-backward Ar (M-p, M-P) Searches backwards through the history list for a command beginning with the current contents of the input buffer up to the cursor and copies it into the input buffer. The search string may be a glob-pattern (see .Sx Filename substitution ) containing .Sq * , .Sq \&? , .Sq [] or .Sq {} .Ic up-history and .Ic down-history will proceed from the appropriate point in the history list. Emacs mode only. See also .Ic history-search-forward and .Ic i-search-back .It Ic history-search-forward Ar (M-n, M-N) Like .Ic history-search-backward , but searches forward. .It Ic i-search-back Ar (not bound) Searches backward like .Ic history-search-backward , copies the first match into the input buffer with the cursor positioned at the end of the pattern, and prompts with .Sq bck: and the first match. Additional characters may be typed to extend the search, .Ic i-search-back may be typed to continue searching with the same pattern, wrapping around the history list if necessary, .Ic ( i-search-back must be bound to a single character for this to work) or one of the following special characters may be typed: .Pp .Bl -tag -width indent -compact .It ^W Appends the rest of the word under the cursor to the search pattern. .It delete (or any character bound to .Ic backward-delete-char ) Undoes the effect of the last character typed and deletes a character from the search pattern if appropriate. .It ^G If the previous search was successful, aborts the entire search. If not, goes back to the last successful search. .It escape Ends the search, leaving the current line in the input buffer. .El .Pp Any other character not bound to .Ic self-insert-command terminates the search, leaving the current line in the input buffer, and is then interpreted as normal input. In particular, a carriage return causes the current line to be executed. See also .Ic i-search-fwd and .Ic history-search-backward Word boundary behavior modified by .Va vimode .It Ic i-search-fwd Ar (not bound) Like .Ic i-search-back , but searches forward. Word boundary behavior modified by .Va vimode .It Ic insert-last-word Ar (M-_) Inserts the last word of the previous input line .Sq ( \&!$ ) into the input buffer. See also .Ic copy-prev-word .It Ic list-choices Ar (M-^D) Lists completion possibilities as described under .Sx Completion and listing See also .Ic delete-char-or-list-or-eof and .Ic list-choices-raw .It Ic list-choices-raw Ar (^X-^D) Like .Ic list-choices , but ignores user-defined completions. .It Ic list-glob Ar (^X-g, ^X-G) Lists (via the .Ic ls\-F builtin) matches to the glob-pattern (see .Sx Filename substitution ) to the left of the cursor. .It Ic list-or-eof Ar (not bound) Does .Ic list-choices or .Ic end-of-file on an empty line. See also .Ic delete-char-or-list-or-eof .It Ic magic-space Ar (not bound) Expands history substitutions in the current line, like .Ic expand-history , and inserts a space. .Ic magic-space is designed to be bound to the space bar, but is not bound by default. .It Ic normalize-command Ar (^X-?) Searches for the current word in PATH and, if it is found, replaces it with the full path to the executable. Special characters are quoted. Aliases are expanded and quoted but commands within aliases are not. This command is useful with commands that take commands as arguments, e.g., .Sq dbx and .Sq sh \-x .It Ic normalize-path Ar (^X-n, ^X-N) Expands the current word as described under the .Sq expand setting of the .Va symlinks shell variable. .It Ic overwrite-mode Ar (unbound) Toggles between input and overwrite modes. .It Ic run-fg-editor Ar (M-^Z) Saves the current input line and looks for a stopped job where the file name portion of its first word is found in the .Va editors shell variable. If .Va editors is not set, then the file name portion of the .Va EDITOR environment variable .Sq ( ed if unset) and the .Va VISUAL environment variable Sq ( vi if unset) will be used. If such a job is found, it is restarted as if .Sq fg % .Ic job had been typed. This is used to toggle back and forth between an editor and the shell easily. Some people bind this command to .Sq ^Z so they can do this even more easily. .It Ic run-help Ar (M-h, M-H) Searches for documentation on the current command, using the same notion of .Sq current command as the completion routines, and prints it. There is no way to use a pager; .Ic run-help is designed for short help files. If the special alias .Va helpcommand is defined, it is run with the command name as a sole argument. Else, documentation should be in a file named .Sq command.help , .Sq command.1 , .Sq command.6 , .Sq command.8 , or .Sq command , which should be in one of the directories listed in the .Va HPATH environment variable. If there is more than one help file only the first is printed. .It Ic self-insert-command Ar (text characters) In insert mode (the default), inserts the typed character into the input line after the character under the cursor. In overwrite mode, replaces the character under the cursor with the typed character. The input mode is normally preserved between lines, but the .Va inputmode shell variable can be set to .Dv insert or .Dv overwrite to put the editor in that mode at the beginning of each line. See also .Ic overwrite-mode .It Ic sequence-lead-in Ar (arrow prefix, meta prefix, ^X) Indicates that the following characters are part of a multi-key sequence. Binding a command to a multi-key sequence really creates two bindings: the first character to .Ic sequence-lead-in and the whole sequence to the command. All sequences beginning with a character bound to .Ic sequence-lead-in are effectively bound to .Ic undefined-key unless bound to another command. .It Ic spell-line Ar (M-$) Attempts to correct the spelling of each word in the input buffer, like .Ic spell-word , but ignores words whose first character is one of .Sq \- , .Sq \ ! , .Sq ^ or .Sq % , or which contain .Sq \e , .Sq * or .Sq \&? , to avoid problems with switches, substitutions and the like. See .Sx Spelling correction .It Ic spell-word Ar (M-s, M-S) Attempts to correct the spelling of the current word as described under .Sx Spelling correction Checks each component of a word which appears to be a pathname. .It Ic toggle-literal-history Ar (M-r, M-R) Expands or .Sq unexpands history substitutions in the input buffer. See also .Ic expand-history and the .Va autoexpand shell variable. .It Ic undefined-key Ar (any unbound key) Beeps. .It Ic up-history Ar (up-arrow, ^P) Copies the previous entry in the history list into the input buffer. If .Va histlit is set, uses the literal form of the entry. May be repeated to step up through the history list, stopping at the top. .It Ic upcase-word Ar (M-u, M-U) Uppercase the characters from cursor to end of current word. Word boundary behavior modified by .Va vimode .It Ic vi-beginning-of-next-word Ar (not bound) Vi goto the beginning of next word. Word boundary and cursor behavior modified by .Va vimode .It Ic vi-eword Ar (not bound) Vi move to the end of the current word. Word boundary behavior modified by .Va vimode .It Ic vi-search-back Ar (?) Prompts with .Sq \&? for a search string (which may be a glob-pattern, as with .Ic history-search-backward ), searches for it and copies it into the input buffer. The bell rings if no match is found. Hitting return ends the search and leaves the last match in the input buffer. Hitting escape ends the search and executes the match. .Ic vi mode only. .It Ic vi-search-fwd Ar (/) Like .Ic vi-search-back , but searches forward. .It Ic which-command Ar (M-?) Does a .Ic which (see the description of the builtin command) on the first word of the input buffer. .It Ic yank-pop Ar (M-y) When executed immediately after a .Ic yank or another .Ic yank-pop , replaces the yanked string with the next previous string from the killring. This also has the effect of rotating the killring, such that this string will be considered the most recently killed by a later .Ic yank command. Repeating .Ic yank-pop will cycle through the killring any number of times. .El .Ss Lexical structure The shell splits input lines into words at blanks and tabs. The special characters .Sq \&& , .Sq | , .Sq \&; , .Sq < , .Sq > , .Sq \&( , and .Sq \&) and the doubled characters .Sq && , .Sq || , .Sq << and .Sq >> are always separate words, whether or not they are surrounded by whitespace. .Pp When the shell's input is not a terminal, the character .Sq # is taken to begin a comment. Each .Sq # and the rest of the input line on which it appears is discarded before further parsing. .Pp A special character (including a blank or tab) may be prevented from having its special meaning, and possibly made part of another word, by preceding it with a backslash .Sq ( \e ) or enclosing it in single .Sq ( \&' ) , , double .Sq ( \&" ) or backward .Sq ( \&` ) quotes. When not otherwise quoted a newline preceded by a .Sq \e is equivalent to a blank, but inside quotes this sequence results in a newline. .Pp Furthermore, all .Sx Substitutions (see below) except .Sx History substitution can be prevented by enclosing the strings (or parts of strings) in which they appear with single quotes or by quoting the crucial character(s) (e.g., .Sq $ or .Sq \&` for .Sx Variable substitution or .Sx Command substitution respectively) with .Sq \e .Sx ( Alias substitution is no exception: quoting in any way any character of a word for which an .Va alias has been defined prevents substitution of the alias. The usual way of quoting an alias is to precede it with a backslash.) .Sx History substitution is prevented by backslashes but not by single quotes. Strings quoted with double or backward quotes undergo .Sx Variable substitution and .Sx Command substitution , but other substitutions are prevented. .Pp Text inside single or double quotes becomes a single word (or part of one). Metacharacters in these strings, including blanks and tabs, do not form separate words. Only in one special case (see .Sx Command substitution below) can a double-quoted string yield parts of more than one word; single-quoted strings never do. Backward quotes are special: they signal .Sx Command substitution (q.v.), which may result in more than one word. .Pp Quoting complex strings, particularly strings which themselves contain quoting characters, can be confusing. Remember that quotes need not be used as they are in human writing! It may be easier to quote not an entire string, but only those parts of the string which need quoting, using different types of quoting to do so if appropriate. .Pp The .Va backslash_quote shell variable (q.v.) can be set to make backslashes always quote .Sq \e , .Sq \&' , and .Sq \&" (+) This may make complex quoting tasks easier, but it can cause syntax errors in .Xr csh 1 scripts. .Ss Substitutions We now describe the various transformations the shell performs on the input in the order in which they occur. We note in passing the data structures involved and the commands and variables which affect them. Remember that substitutions can be prevented by quoting as described under .Sx Lexical structure . .Ss History substitution Each command, or .Sq event , input from the terminal is saved in the history list. The previous command is always saved, and the .Va history shell variable can be set to a number to save that many commands. The .Va histdup shell variable can be set to not save duplicate events or consecutive duplicate events. .Pp Saved commands are numbered sequentially from 1 and stamped with the time. It is not usually necessary to use event numbers, but the current event number can be made part of the prompt by placing an .Sq \&! in the .Va prompt shell variable. .Pp +By default history entries are displayed by printing each parsed token +separated by space; thus the redirection operator +.Sq >\&&\&! +will be displayed as +.Sq >\0\&&\0\&! . The shell actually saves history in expanded and literal (unexpanded) forms. If the .Va histlit shell variable is set, commands that display and store history use the literal form. .Pp The .Va history builtin command can print, store in a file, restore and clear the history list at any time, and the .Va savehist and .Va histfile shell variables can be set to store the history list automatically on logout and restore it on login. .Pp History substitutions introduce words from the history list into the input stream, making it easy to repeat commands, repeat arguments of a previous command in the current command, or fix spelling mistakes in the previous command with little typing and a high degree of confidence. .Pp History substitutions begin with the character .Sq \&! They may begin anywhere in the input stream, but they do not nest. The .Sq \&! may be preceded by a .Sq \e to prevent its special meaning; for convenience, a .Sq \&! is passed unchanged when it is followed by a blank, tab, newline, .Sq = or .Sq \&( History substitutions also occur when an input line begins with .Sq ^ This special abbreviation will be described later. The characters used to signal history substitution .Sq ( \&! and .Sq ^ ) can be changed by setting the .Va histchars shell variable. Any input line which contains a history substitution is printed before it is executed. .Pp A history substitution may have an .Sq event specification , which indicates the event from which words are to be taken, a .Sq word designator , which selects particular words from the chosen event, and/or a .Sq modifier , which manipulates the selected words. .Pp An event specification can be .Pp .Bl -tag -width XXXX -offset indent -compact .It Ar n A number, referring to a particular event .It Ar \-n An offset, referring to the event .Ar n before the current event .It Ar # The current event. This should be used carefully in .Xr csh 1 , where there is no check for recursion. .Nm allows 10 levels of recursion. (+) .It Ar \&! The previous event (equivalent to .Sq \-1 ) .It Ar s The most recent event whose first word begins with the string .Va s .It Ar ?s? The most recent event which contains the string .Va s The second .Sq \&? can be omitted if it is immediately followed by a newline. .El .Pp For example, consider this bit of someone's history list: .Bd -literal -offset indent 9 8:30 nroff \-man wumpus.man 10 8:31 cp wumpus.man wumpus.man.old 11 8:36 vi wumpus.man 12 8:37 diff wumpus.man.old wumpus.man .Ed .Pp The commands are shown with their event numbers and time stamps. The current event, which we haven't typed in yet, is event 13. .Sq !11 and .Sq !\-2 refer to event 11. .Sq \&!! refers to the previous event, 12. .Sq \&!! can be abbreviated .Sq \&! if it is followed by .Sq \&: .Sq ( \&: is described below). .Sq !n refers to event 9, which begins with .Sq n .Sq !?old? also refers to event 12, which contains .Sq old Without word designators or modifiers history references simply expand to the entire event, so we might type .Sq !cp to redo the copy command or .Sq !!|more if the .Sq diff output scrolled off the top of the screen. .Pp History references may be insulated from the surrounding text with braces if necessary. For example, .Sq !vdoc would look for a command beginning with .Sq vdoc , and, in this example, not find one, but .Sq !{v}doc would expand unambiguously to .Sq vi wumpus.mandoc Even in braces, history substitutions do not nest. .Pp (+) While .Xr csh 1 expands, for example, .Sq !3d to event 3 with the letter .Sq d appended to it, .Nm expands it to the last event beginning with .Sq 3d ; only completely numeric arguments are treated as event numbers. This makes it possible to recall events beginning with numbers. To expand .Sq !3d as in .Xr csh 1 say .Sq !{3}d .Pp To select words from an event we can follow the event specification by a .Sq \&: and a designator for the desired words. The words of an input line are numbered from 0, the first (usually command) word being 0, the second word (first argument) being 1, etc. The basic word designators are: .Pp .Bl -tag -width XXXX -offset indent -compact .It Ar 0 The first (command) word .It Ar n The .Va n th argument .It Ar ^ The first argument, equivalent to .Sq 1 .It Ar $ The last argument .It Ar % The word matched by an ? .Va s ? search .It Ar x\-y A range of words .It Ar \-y Equivalent to .Sq 0\-y .It Ar * Equivalent to .Sq ^\-$ , but returns nothing if the event contains only 1 word .It Ar x* Equivalent to .Sq x\-$ .It Ar x\- Equivalent to .Sq x* , but omitting the last word .Sq ( $ ) .El .Pp Selected words are inserted into the command line separated by single blanks. For example, the .Sq diff command in the previous example might have been typed as .Sq diff !!:1.old !!:1 (using .Sq \&:1 to select the first argument from the previous event) or .Sq diff !\-2:2 !\-2:1 to select and swap the arguments from the .Sq cp command. If we didn't care about the order of the `diff' we might have said .Sq diff !\-2:1\-2 or simply .Sq diff !\-2:* The .Sq cp command might have been written .Sq cp wumpus.man !#:1.old , using .Sq # to refer to the current event. `!n:\- hurkle.man' would reuse the first two words from the .Sq nroff command to say .Sq nroff \-man hurkle.man .Pp The .Sq \&: separating the event specification from the word designator can be omitted if the argument selector begins with a .Sq ^ , .Sq $ , .Sq * , .Sq % or .Sq \&- For example, our .Sq diff command might have been .Sq diff !!^.old !!^ or, equivalently, .Sq diff !!$.old !!$ However, if .Sq \&!! is abbreviated .Sq \&! , an argument selector beginning with .Sq \- will be interpreted as an event specification. .Pp A history reference may have a word designator but no event specification. It then references the previous command. Continuing our .Sq diff example, we could have said simply `diff !^.old !^' or, to get the arguments in the opposite order, just .Sq diff !* .Pp The word or words in a history reference can be edited, or .Sq `modified ', by following it with one or more modifiers, each preceded by a .Sq \&: : .Pp .Bl -tag -width XXXXXX -offset indent -compact .It Ar h Remove a trailing pathname component, leaving the head. .It Ar t Remove all leading pathname components, leaving the tail. .It Ar r Remove a filename extension .Sq .xxx , leaving the root name. .It Ar e Remove all but the extension. .It Ar u Uppercase the first lowercase letter. .It Ar l Lowercase the first uppercase letter. .It Ar s/l/r/ Substitute .Ar l for .Ar r .Ar l is simply a string like .Ar r , not a regular expression as in the eponymous .Xr ed 1 command. Any character may be used as the delimiter in place of .Sq / ; a .Sq \e can be used to quote the delimiter inside .Va l and .Va r The character .Sq & in the .Va r is replaced by .Va l ; .Sq \e also quotes .Sq & If .Va l is empty ( .Dq \& ) , the .Va l from a previous substitution or the .Va s from a previous search or event number in event specification is used. The trailing delimiter may be omitted if it is immediately followed by a newline. .It Ar \&& Repeat the previous substitution. .It Ar g Apply the following modifier once to each word. .It Ar a (+) Apply the following modifier as many times as possible to a single word. .Sq a and .Sq g can be used together to apply a modifier globally. With the .Sq s modifier, only the patterns contained in the original word are substituted, not patterns that contain any substitution result. .It Ar p Print the new command line but do not execute it. .It Ar q Quote the substituted words, preventing further substitutions. +.It Ar Q +Same as +.Ar q +but in addition preserve empty variables as a string containing a NUL. +This is useful to preserve positional arguments for example: +.Bd -literal -offset indent -compact +> set args=('arg 1' '' 'arg 3') +> tcsh -f -c 'echo ${#argv}' $args:gQ +3 +.Ed .It Ar x Like .Ar q , but break into words at blanks, tabs and newlines. .El .Pp Modifiers are applied to only the first modifiable word (unless .Sq g is used). It is an error for no word to be modifiable. .Pp For example, the .Sq diff command might have been written as `diff wumpus.man.old !#^:r', using .Sq \&:r to remove .Sq .old from the first argument on the same line (`!#^'). We could say .Sq echo hello out there , then .Sq echo !*:u to capitalize `hello', .Sq echo !*:au to say it out loud, or .Sq echo !*:agu to really shout. We might follow .Sq mail \-s "I forgot my password" rot with .Sq !:s/rot/root to correct the spelling of .Sq root (but see .Sx Spelling correction for a different approach). .Pp There is a special abbreviation for substitutions. .Sq ^ , when it is the first character on an input line, is equivalent to .Sq !:s^ Thus we might have said .Sq ^rot^root to make the spelling correction in the previous example. This is the only history substitution which does not explicitly begin with .Sq \&! .Pp (+) In .Xr csh 1 as such, only one modifier may be applied to each history or variable expansion. In .Nm , more than one may be used, for example .Bd -literal -offset indent % mv wumpus.man /usr/man/man1/wumpus.1 % man !$:t:r man wumpus .Ed .Pp In .Xr csh 1 , the result would be .Sq wumpus.1:r A substitution followed by a colon may need to be insulated from it with braces: .Bd -literal -offset indent > mv a.out /usr/games/wumpus > setenv PATH !$:h:$PATH Bad ! modifier: $. > setenv PATH !{\-2$:h}:$PATH setenv PATH /usr/games:/bin:/usr/bin:. .Ed .Pp The first attempt would succeed in .Xr csh 1 but fails in .Nm , because .Nm expects another modifier after the second colon rather than .Sq $ .Pp Finally, history can be accessed through the editor as well as through the substitutions just described. The .Ic up- and .Ic down-history , .Ic history-search-backward and .Va -forward , .Ic i-search-back and .Ic -fwd , .Ic vi-search-back and .Ic -fwd , .Ic copy-prev-word and .Ic insert-last-word editor commands search for events in the history list and copy them into the input buffer. The .Ic toggle-literal-history editor command switches between the expanded and literal forms of history lines in the input buffer. .Ic expand-history and .Ic expand-line expand history substitutions in the current word and in the entire input buffer respectively. .Ss Alias substitution The shell maintains a list of aliases which can be set, unset and printed by the .Ic alias and .Ic unalias commands. After a command line is parsed into simple commands (see .Sx Commands ) the first word of each command, left-to-right, is checked to see if it has an alias. If so, the first word is replaced by the alias. If the alias contains a history reference, it undergoes .Va History substitution (q.v.) as though the original command were the previous input line. If the alias does not contain a history reference, the argument list is left untouched. .Pp Thus if the alias for .Sq ls were .Sq ls \-l the command .Sq ls /usr would become `ls \-l /usr', the argument list here being undisturbed. If the alias for .Sq lookup were .Sq grep !/etc/passwd then .Sq lookup bill would become `grep bill /etc/passwd'. Aliases can be used to introduce parser metasyntax. For example, .Sq alias print pr \e!* | lpr'' defines a .Sq `command ' (`print') which .Va pr (1)s its arguments to the line printer. .Pp Alias substitution is repeated until the first word of the command has no alias. If an alias substitution does not change the first word (as in the previous example) it is flagged to prevent a loop. Other loops are detected and cause an error. .Pp Some aliases are referred to by the shell; see .Va Special aliases .Ss Variable substitution The shell maintains a list of variables, each of which has as value a list of zero or more words. The values of shell variables can be displayed and changed with the .Va set and .Va unset commands. The system maintains its own list of .Sq `environment ' variables. These can be displayed and changed with .Va printenv , .Va setenv and .Va unsetenv .Pp (+) Variables may be made read-only with .Sq set \-r (q.v.). Read-only variables may not be modified or unset; attempting to do so will cause an error. Once made read-only, a variable cannot be made writable, so .Sq set \-r should be used with caution. Environment variables cannot be made read-only. .Pp Some variables are set by the shell or referred to by it. For instance, the .Va argv variable is an image of the shell's argument list, and words of this variable's value are referred to in special ways. Some of the variables referred to by the shell are toggles; the shell does not care what their value is, only whether they are set or not. For instance, the .Va verbose variable is a toggle which causes command input to be echoed. The .Fl v\fR command line option sets this variable. .Va Special shell variables lists all variables which are referred to by the shell. .Pp Other operations treat variables numerically. The .Sq @ command permits numeric calculations to be performed and the result assigned to a variable. Variable values are, however, always represented as (zero or more) strings. For the purposes of numeric operations, the null string is considered to be zero, and the second and subsequent words of multi-word values are ignored. .Pp After the input line is aliased and parsed, and before each command is executed, variable substitution is performed keyed by .Sq $ characters. This expansion can be prevented by preceding the .Sq $ with a .Sq \e except within .Sq " s where it .Va always occurs, and within .Sq 's where it .Va never occurs. Strings quoted by .Sq \` are interpreted later (see .Sx Command substitution below) so .Sq $ substitution does not occur there until later, if at all. A .Sq $ is passed unchanged if followed by a blank, tab, or end-of-line. .Pp Input/output redirections are recognized before variable expansion, and are variable expanded separately. Otherwise, the command name and entire argument list are expanded together. It is thus possible for the first (command) word (to this point) to generate more than one word, the first of which becomes the command name, and the rest of which become arguments. .Pp Unless enclosed in .Sq " or given the .Sq \&:q modifier the results of variable substitution may eventually be command and filename substituted. Within .Sq " , a variable whose value consists of multiple words expands to a (portion of a) single word, with the words of the variable's value separated by blanks. When the .Sq \&:q modifier is applied to a substitution the variable will expand to multiple words with each word separated by a blank and quoted to prevent later command or filename substitution. .Pp The following metasequences are provided for introducing variable values into the shell input. Except as noted, it is an error to reference a variable which is not set. .Pp .Bl -tag -width XXXXXXXXXX -offset indent -compact .PD 0 .It Ar $name .It Ar ${name} Substitutes the words of the value of variable .Va name , each separated by a blank. Braces insulate .Va name from following characters which would otherwise be part of it. Shell variables have names consisting of letters and digits starting with a letter. The underscore character is considered a letter. If .Va name is not a shell variable, but is set in the environment, then that value is returned (but some of the other forms given below are not available in this case). .It Ar $name[selector] .It Ar ${name[selector]} Substitutes only the selected words from the value of .Va name The .Va selector is subjected to .Sq $ substitution and may consist of a single number or two numbers separated by a .Sq \&- The first word of a variable's value is numbered .Sq 1 If the first number of a range is omitted it defaults to .Sq 1 If the last member of a range is omitted it defaults to .Sq $# .Va name The .Va selector .Sq * selects all words. It is not an error for a range to be empty if the second argument is omitted or in range. .It Ar $0 Substitutes the name of the file from which command input is being read. An error occurs if the name is not known. .It Ar $number .It Ar ${number} Equivalent to .Sq $argv[number] .It Ar $* Equivalent to .Sq $argv , which is equivalent to .Sq $argv[*] .El .Pp The .Sq \&: modifiers described under .Sx History substitution , except for .Sq \&:p , can be applied to the substitutions above. More than one may be used. (+) Braces may be needed to insulate a variable substitution from a literal colon just as with .Sx History substitution (q.v.); any modifiers must appear within the braces. .Pp The following substitutions can not be modified with .Sq \&: modifiers. .Pp .Bl -tag -width XXXXXXXXXX -offset indent -compact .It Ar $?name .It Ar ${?name} Substitutes the string .Sq 1 if .Va name is set, .Sq 0 if it is not. .It Ar $?0 Substitutes .Sq 1 if the current input filename is known, .Sq 0 if it is not. Always .Sq 0 in interactive shells. .It Ar $#name .It Ar ${#name} Substitutes the number of words in .Va name .It Ar $# Equivalent to .Sq $#argv (+) .It Ar $%name .It Ar ${%name} Substitutes the number of characters in .Va name (+) .Pp .It Ar $%number .It Ar ${%number} Substitutes the number of characters in .Va $argv[number] . (+) .It Ar $? Equivalent to .Sq $status (+) .It Ar $$ Substitutes the (decimal) process number of the (parent) shell. .It Ar $! Substitutes the (decimal) process number of the last background process started by this shell. (+) .It Ar $_ Substitutes the command line of the last command executed. (+) .It Ar $< Substitutes a line from the standard input, with no further interpretation thereafter. It can be used to read from the keyboard in a shell script. (+) While .Xr csh 1 always quotes $<, as if it were equivalent to .Sq $<:q , .Nm does not. Furthermore, when .Nm is waiting for a line to be typed the user may type an interrupt to interrupt the sequence into which the line is to be substituted, but .Xr csh 1 does not allow this. .El .Pp The editor command .Va expand-variables , normally bound to .Sq ^X-$ , can be used to interactively expand individual variables. .Ss "Command, filename and directory stack substitution" The remaining substitutions are applied selectively to the arguments of builtin commands. This means that portions of expressions which are not evaluated are not subjected to these expansions. For commands which are not internal to the shell, the command name is substituted separately from the argument list. This occurs very late, after input-output redirection is performed, andk in a child of the main shell. .Ss "Command substitution" Command substitution is indicated by a command enclosed in .Sq \&` The output from such a command is broken into separate words at blanks, tabs and newlines, and null words are discarded. The output is variable and command substituted and put in place of the original string. .Pp Command substitutions inside double quotes .Sq ( \&" ) retain blanks and tabs; only newlines force new words. The single final newline does not force a new word in any case. It is thus possible for a command substitution to yield only part of a word, even if the command outputs a complete line. .Pp By default, the shell since version 6.12 replaces all newline and carriage return characters in the command by spaces. If this is switched off by unsetting .Va csubstnonl , newlines separate commands as usual. .Ss "Filename substitution" If a word contains any of the characters .Sq * , .Sq \&? , .Sq \&[ or .Sq { or begins with the character .Sq ~ it is a candidate for filename substitution, also known as .Dq globbing . This word is then regarded as a pattern .Dq ( glob-pattern ) , and replaced with an alphabetically sorted list of file names which match the pattern. .Pp In matching filenames, the character .Sq . at the beginning of a filename or immediately following a .Sq / , as well as the character .Sq / must be matched explicitly (unless either .Va globdot or .Va globstar or both are set(+)). The character .Sq * matches any string of characters, including the null string. The character .Sq \&? matches any single character. The sequence .Sq [...] matches any one of the characters enclosed. Within .Sq [...] , a pair of characters separated by .Sq \&- matches any character lexically between the two. .Pp (+) Some glob-patterns can be negated: The sequence .Sq [^...] matches any single character .Va not specified by the characters and/or ranges of characters in the braces. .Pp An entire glob-pattern can also be negated with .Sq ^ : .Bd -literal -offset indent > echo * bang crash crunch ouch > echo ^cr* bang ouch .Ed .Pp Glob-patterns which do not use .Sq \&? , .Sq * , or .Sq [] or which use .Sq {} or .Sq ~ (below) are not negated correctly. .Pp The metanotation .Sq a{b,c,d}e is a shorthand for .Sq abe ace ade Left-to-right order is preserved: .Sq /usr/source/s1/{oldls,ls}.c expands to .Sq /usr/source/s1/oldls.c /usr/source/s1/ls.c The results of matches are sorted separately at a low level to preserve this order: .Sq ../{memo,*box} might expand to .Sq ../memo ../box ../mbox (Note that .Sq memo was not sorted with the results of matching .Sq *box . ) It is not an error when this construct expands to files which do not exist, but it is possible to get an error from a command to which the expanded list is passed. This construct may be nested. As a special case the words .Sq { , .Sq } and .Sq {} are passed undisturbed. .Pp The character .Sq ~ at the beginning of a filename refers to home directories. Standing alone, i.e., .Sq ~ , it expands to the invoker's home directory as reflected in the value of the .Va home shell variable. When followed by a name consisting of letters, digits and .Sq \&- characters the shell searches for a user with that name and substitutes their home directory; thus .Sq ~ken might expand to .Sq /usr/ken and .Sq ~ken/chmach to .Sq /usr/ken/chmach If the character .Sq ~ is followed by a character other than a letter or .Sq / or appears elsewhere than at the beginning of a word, it is left undisturbed. A command like .Sq setenv MANPATH /usr/man:/usr/local/man:~/lib/man does not, therefore, do home directory substitution as one might hope. .Pp It is an error for a glob-pattern containing .Sq * , .Sq \&? , .Sq \&[ or .Sq ~ , with or without .Sq ^ , not to match any files. However, only one pattern in a list of glob-patterns must match a file (so that, e.g., .Sq rm *.a *.c *.o would fail only if there were no files in the current directory ending in .Sq .a , .Sq .c , or .Sq .o ) , and if the .Va nonomatch shell variable is set a pattern (or list of patterns) which matches nothing is left unchanged rather than causing an error. .Pp The .Va globstar shell variable can be set to allow .Sq ** or .Sq *** as a file glob pattern that matches any string of characters including .Sq / , recursively traversing any existing sub-directories. For example, .Sq ls **.c will list all the .c files in the current directory tree. If used by itself, it will match zero or more sub-directories (e.g. .Sq ls /usr/include/**/time.h will list any file named .Sq time.h in the /usr/include directory tree; .Sq ls /usr/include/**time.h will match any file in the /usr/include directory tree ending in .Sq time.h ; and .Sq ls /usr/include/**time**.h will match any .h file with .Sq time either in a subdirectory name or in the filename itself). To prevent problems with recursion, the .Sq ** glob-pattern will not descend into a symbolic link containing a directory. To override this, use .Sq *** (+) .Pp The .Va noglob shell variable can be set to prevent filename substitution, and the .Va expand-glob editor command, normally bound to .Sq ^X-* , can be used to interactively expand individual filename substitutions. .Ss "Directory stack substitution (+)" The directory stack is a list of directories, numbered from zero, used by the .Va pushd , .Va popd and .Va dirs builtin commands (q.v.). .Va dirs can print, store in a file, restore and clear the directory stack at any time, and the .Va savedirs and .Va dirsfile shell variables can be set to store the directory stack automatically on logout and restore it on login. The .Va dirstack shell variable can be examined to see the directory stack and set to put arbitrary directories into the directory stack. .Pp The character .Sq = followed by one or more digits expands to an entry in the directory stack. The special case .Sq =- expands to the last directory in the stack. For example, .Bd -literal -offset indent > dirs \&-v 0 /usr/bin 1 /usr/spool/uucp 2 /usr/accts/sys > echo =1 /usr/spool/uucp > echo =0/calendar /usr/bin/calendar > echo =\- /usr/accts/sys .Ed .Pp The .Va noglob and .Va nonomatch shell variables and the .Va expand-glob editor command apply to directory stack as well as filename substitutions. .Ss "Other substitutions (+)" There are several more transformations involving filenames, not strictly related to the above but mentioned here for completeness. .Va Any filename may be expanded to a full path when the .Va symlinks variable (q.v.) is set to .Sq expand Quoting prevents this expansion, and the .Va normalize-path editor command does it on demand. The .Va normalize-command editor command expands commands in PATH into full paths on demand. Finally, .Va cd and .Va pushd interpret .Sq \&- as the old working directory (equivalent to the shell variable .Va owd ) . This is not a substitution at all, but an abbreviation recognized by only those commands. Nonetheless, it too can be prevented by quoting. .Ss "Commands" The next three sections describe how the shell executes commands and deals with their input and output. .Ss "Simple commands, pipelines and sequences" A simple command is a sequence of words, the first of which specifies the command to be executed. A series of simple commands joined by .Sq | characters forms a pipeline. The output of each command in a pipeline is connected to the input of the next. .Pp Simple commands and pipelines may be joined into sequences with .Sq ; , and will be executed sequentially. Commands and pipelines can also be joined into sequences with .Sq || or .Sq && , indicating, as in the C language, that the second is to be executed only if the first fails or succeeds respectively. .Pp A simple command, pipeline or sequence may be placed in parentheses, .Sq () , to form a simple command, which may in turn be a component of a pipeline or sequence. A command, pipeline or sequence can be executed without waiting for it to terminate by following it with an .Sq \&& . .Ss "Builtin and non-builtin command execution" Builtin commands are executed within the shell. If any component of a pipeline except the last is a builtin command, the pipeline is executed in a subshell. .Pp Parenthesized commands are always executed in a subshell. .Bd -literal -offset indent (cd; pwd); pwd .Ed .Pp thus prints the .Va home directory, leaving you where you were (printing this after the home directory), while .Bd -literal -offset indent cd; pwd .Ed .Pp leaves you in the .Va home directory. Parenthesized commands are most often used to prevent .Va cd from affecting the current shell. .Pp When a command to be executed is found not to be a builtin command the shell attempts to execute the command via .Xr execve 2 . Each word in the variable .Va path names a directory in which the shell will look for the command. If the shell is not given a .Fl f option, the shell hashes the names in these directories into an internal table so that it will try an .Xr execve 2 in only a directory where there is a possibility that the command resides there. This greatly speeds command location when a large number of directories are present in the search path. This hashing mechanism is not used: .TP 4 .Bl -enum -width indent .It If hashing is turned explicitly off via .Va unhash .It If the shell was given a .Fl f Ar argument .It For each directory component of .Va path which does not begin with a .Sq / .It If the command contains a .Sq / .El .Pp In the above four cases the shell concatenates each component of the path vector with the given command name to form a path name of a file which it then attempts to execute it. If execution is successful, the search stops. .Pp If the file has execute permissions but is not an executable to the system (i.e., it is neither an executable binary nor a script that specifies its interpreter), then it is assumed to be a file containing shell commands and a new shell is spawned to read it. The .Va shell special alias may be set to specify an interpreter other than the shell itself. .Pp On systems which do not understand the .Sq #! script interpreter convention the shell may be compiled to emulate it; see the .Va version shell variable. If so, the shell checks the first line of the file to see if it is of the form .Sq #!interpreter arg ... If it is, the shell starts .Va interpreter with the given .Va arg s and feeds the file to it on standard input. .Ss "Input/output" The standard input and standard output of a command may be redirected with the following syntax: .Pp .Bl -tag -width XXXXXXXXX -offset indent -compact .It Ar < name Open file .Va name (which is first variable, command and filename expanded) as the standard input. .It Ar << word Read the shell input up to a line which is identical to .Va word . .Va word is not subjected to variable, filename or command substitution, and each input line is compared to .Va word before any substitutions are done on this input line. Unless a quoting .Sq \e , .Sq \&" , .Sq \&' or .Sq \&` appears in .Va word variable and command substitution is performed on the intervening lines, allowing .Sq \e to quote .Sq $ , .Sq \e and .Sq \&` . Commands which are substituted have all blanks, tabs, and newlines preserved, except for the final newline which is dropped. The resultant text is placed in an anonymous temporary file which is given to the command as standard input. .Pp .It Ar > name .It Ar >! name .It Ar >& name .It Ar >&! name The file .Va name is used as standard output. If the file does not exist then it is created; if the file exists, it is truncated, its previous contents being lost. .Pp If the shell variable .Va noclobber is set, then the file must not exist or be a character special file (e.g., a terminal or .Sq /dev/null ) or an error results. This helps prevent accidental destruction of files. In this case the .Sq \&! forms can be used to suppress this check. If .Va notempty is given in .Va noclobber , .Sq > is allowed on empty files; if .Va ask is set, an interacive confirmation is presented, rather than an error. .Pp The forms involving .Sq \&& route the diagnostic output into the specified file as well as the standard output. .Va name is expanded in the same way as .Sq < input filenames are. .Pp .It Ar >> name .It Ar >>& name .It Ar >>! name .It Ar >>&! name Like .Sq > , but appends output to the end of .Va name If the shell variable .Va noclobber is set, then it is an error for the file .Va not to exist, unless one of the .Sq \&! forms is given. .El .Pp A command receives the environment in which the shell was invoked as modified by the input-output parameters and the presence of the command in a pipeline. Thus, unlike some previous shells, commands run from a file of shell commands have no access to the text of the commands by default; rather they receive the original standard input of the shell. The .Sq << mechanism should be used to present inline data. This permits shell command scripts to function as components of pipelines and allows the shell to block read its input. Note that the default standard input for a command run detached is .Va not the empty file .Va /dev/null , but the original standard input of the shell. If this is a terminal and if the process attempts to read from the terminal, then the process will block and the user will be notified (see .Sx Jobs ) . .Pp Diagnostic output may be directed through a pipe with the standard output. Simply use the form .Sq |& rather than just .Sq | . .Pp The shell cannot presently redirect diagnostic output without also redirecting standard output, but .Sq \&( command > output-file ) >& error-file is often an acceptable workaround. Either .Va output-file or .Va error-file may be .Sq /dev/tty to send output to the terminal. .Ss "Features" Having described how the shell accepts, parses and executes command lines, we now turn to a variety of its useful features. .Ss "Control flow" The shell contains a number of commands which can be used to regulate the flow of control in command files (shell scripts) and (in limited but useful ways) from terminal input. These commands all operate by forcing the shell to reread or skip in its input and, due to the implementation, restrict the placement of some of the commands. .Pp The .Va foreach , .Va switch , and .Va while statements, as well as the .Va if-then-else form of the .Va if statement, require that the major keywords appear in a single simple command on an input line as shown below. .Pp If the shell's input is not seekable, the shell buffers up input whenever a loop is being read and performs seeks in this internal buffer to accomplish the rereading implied by the loop. (To the extent that this allows, backward .Va goto s will succeed on non-seekable inputs.) .Ss "Expressions" The .Va if , .Va while and .Va exit builtin commands use expressions with a common syntax. The expressions can include any of the operators described in the next three sections. Note that the .Va @ builtin command (q.v.) has its own separate syntax. .Ss "Logical, arithmetical and comparison operators" These operators are similar to those of C and have the same precedence. They include .IP "" 4 .Bl -tag -width XXXXXX -offset indent -compact .It || && | & == != =~ !~ <= >= .It < > << >> + \- * / % ! ~ ( ) .El .Pp Here the precedence increases to the right, .Sq == .Sq \&!= .Sq =~ and .Sq \&!~ , .Sq <= .Sq >= .Sq < and .Sq > , .Sq << .Sq >> , .Sq + and .Sq \&- , .Sq * .Sq / and .Sq % being, in groups, at the same level. The .Sq == .Sq \&!= .Sq =~ and .Sq \&!~ operators compare their arguments as strings; all others operate on numbers. The operators .Sq =~ and .Sq \&!~ are like .Sq \&!= and .Sq == except that the right hand side is a glob-pattern (see .Sx Filename substitution ) against which the left hand operand is matched. This reduces the need for use of the .Va switch builtin command in shell scripts when all that is really needed is pattern matching. .Pp Null or missing arguments are considered .Sq 0 The results of all expressions are strings, which represent decimal numbers. It is important to note that no two components of an expression can appear in the same word; except when adjacent to components of expressions which are syntactically significant to the parser .Sq ( \&& .Sq | .Sq < .Sq > .Sq \&( .Sq \&) ) they should be surrounded by spaces. .Ss "Command exit status" Commands can be executed in expressions and their exit status returned by enclosing them in braces .Sq ( {} ) . Remember that the braces should be separated from the words of the command by spaces. Command executions succeed, returning true, i.e., .Sq 1 , if the command exits with status 0, otherwise they fail, returning false, i.e., .Sq 0 . If more detailed status information is required then the command should be executed outside of an expression and the .Va status shell variable examined. .Ss "File inquiry operators" Some of these operators perform true/false tests on files and related objects. They are of the form .Fl .Va op file , where .Va op is one of .Bl -tag -width XXX -offset indent -compact .It Ar r Read access .It Ar w Write access .It Ar x Execute access .It Ar X Executable in the path or shell builtin, e.g., .Sq \&-X ls and .Sq \&-X ls\&-F are generally true, but .Sq \&-X /bin/ls is not (+) .It Ar e Existence .It Ar o Ownership .It Ar z Zero size .It Ar s Non-zero size (+) .It Ar f Plain file .It Ar d Directory .It Ar l Symbolic link (+) * .It Ar b Block special file (+) .It Ar c Character special file (+) .It Ar p Named pipe (fifo) (+) * .It Ar S Socket special file (+) * .It Ar u Set-user-ID bit is set (+) .It Ar g Set-group-ID bit is set (+) .It Ar k Sticky bit is set (+) .It Ar t file (which must be a digit) is an open file descriptor for a terminal device (+) .It Ar R Has been migrated (Convex only) (+) .It Ar L Applies subsequent operators in a multiple-operator test to a symbolic link rather than to the file to which the link points (+) * .El .Pp .Va file is command and filename expanded and then tested to see if it has the specified relationship to the real user. If .Va file does not exist or is inaccessible or, for the operators indicated by .Sq * , if the specified file type does not exist on the current system, then all inquiries return false, i.e., .Sq 0 . .Pp These operators may be combined for conciseness: .Sq \&- .Va xy file is equivalent to .Sq \&-x file && \&-y file . (+) For example, .Sq \&-fx is true (returns .Sq 1 ) for plain executable files, but not for directories. .Pp .Va L may be used in a multiple-operator test to apply subsequent operators to a symbolic link rather than to the file to which the link points. For example, .Sq \&-lLo is true for links owned by the invoking user. .Va Lr , .Va Lw and .Va Lx are always true for links and false for non-links. .Va L has a different meaning when it is the last operator in a multiple-operator test; see below. .Pp It is possible but not useful, and sometimes misleading, to combine operators which expect .Va file to be a file with operators which do not (e.g., .Va X and .Va t ) . Following .Va L with a non-file operator can lead to particularly strange results. .Pp Other operators return other information, i.e., not just .Sq 0 or .Sq 1 (+) They have the same format as before; .Va op may be one of .Pp .Bl -tag -width XXX -offset indent -compact .It Ar A Last file access time, as the number of seconds since the epoch .It Ar A: Like .Va Ar A , but in timestamp format, e.g., .Sq Fri May 14 16:36:10 1993 .It Ar M Last file modification time .It Ar M: Like .Va M , but in timestamp format .It Ar C Last inode modification time .It Ar C: Like .Va C , but in timestamp format .It Ar D Device number .It Ar I Inode number .It Ar F Composite .Va f ile identifier, in the form .Va device : .Va inode .It Ar L The name of the file pointed to by a symbolic link .It Ar N Number of (hard) links .It Ar P Permissions, in octal, without leading zero .It Ar P: Like .Va P , with leading zero .It Ar P Equivalent to .Sq \-P .Va file & .Va mode , e.g., .Sq \-P22 .Va file returns `22' if .Va file is writable by group and other, .Sq 20 if by group only, and .Sq 0 if by neither .It Ar P: Like .Ar BP .Va mode , with leading zero .It Ar U Numeric userid .It Ar U: Username, or the numeric userid if the username is unknown .It Ar G Numeric groupid .It Ar G: Groupname, or the numeric groupid if the groupname is unknown .It Ar Z Size, in bytes .El .Pp Only one of these operators may appear in a multiple-operator test, and it must be the last. Note that .Va L has a different meaning at the end of and elsewhere in a multiple-operator test. Because .Sq 0 is a valid return value for many of these operators, they do not return .Sq 0 when they fail: most return .Sq \&-1 , and .Va F returns .Sq \&: .Pp If the shell is compiled with POSIX defined (see the .Va version shell variable), the result of a file inquiry is based on the permission bits of the file and not on the result of the .Va access (2) system call. For example, if one tests a file with .Fl w\fR whose permissions would ordinarily allow writing but which is on a file system mounted read-only, the test will succeed in a POSIX shell but fail in a non-POSIX shell. .Pp File inquiry operators can also be evaluated with the .Va filetest builtin command (q.v.) (+). .Ss Jobs The shell associates a .Va job with each pipeline. It keeps a table of current jobs, printed by the .Va jobs command, and assigns them small integer numbers. When a job is started asynchronously with .Sq & , the shell prints a line which looks like .IP "" 4 [1] 1234 .Pp indicating that the job which was started asynchronously was job number 1 and had one (top-level) process, whose process id was 1234. .Pp If you are running a job and wish to do something else you may hit the suspend key (usually .Sq ^Z ) , which sends a STOP signal to the current job. The shell will then normally indicate that the job has been .Sq Suspended and print another prompt. If the .Va listjobs shell variable is set, all jobs will be listed like the .Va jobs builtin command; if it is set to .Sq long the listing will be in long format, like .Sq jobs \&-l You can then manipulate the state of the suspended job. You can put it in the .Dq background with the .Va bg command or run some other commands and eventually bring the job back into the .Sq foreground ' with .Va fg (See also the .Va run-fg-editor editor command.) A .Sq ^Z takes effect immediately and is like an interrupt in that pending output and unread input are discarded when it is typed. The .Va wait builtin command causes the shell to wait for all background jobs to complete. .Pp The .Sq ^] key sends a delayed suspend signal, which does not generate a STOP signal until a program attempts to .Va read (2) it, to the current job. This can usefully be typed ahead when you have prepared some commands for a job which you wish to stop after it has read them. The .Sq ^Y key performs this function in .Xr csh 1 ; in .Nm , `^Y' is an editing command. (+) .Pp A job being run in the background stops if it tries to read from the terminal. Background jobs are normally allowed to produce output, but this can be disabled by giving the command .Sq stty tostop If you set this tty option, then background jobs will stop when they try to produce output like they do when they try to read input. .Pp There are several ways to refer to jobs in the shell. The character .Sq % introduces a job name. If you wish to refer to job number 1, you can name it as .Sq %1 Just naming a job brings it to the foreground; thus .Sq %1 is a synonym for .Sq fg %1 , bringing job 1 back into the foreground. Similarly, saying .Sq %1 & resumes job 1 in the background, just like .Sq bg %1 A job can also be named by an unambiguous prefix of the string typed in to start it: .Sq %ex would normally restart a suspended -.Va ex -(1) job, if there were only one suspended +.Xr ex 1 +job, if there were only one suspended job whose name began with the string -.Sq ex +.Sq ex . It is also possible to say -`%? -.Va string -' to specify a job whose text contains -.Va string -, if there -is only one such job. +.Va %?string +to specify a job whose text contains +.Va string , +if there is only one such job. .Pp The shell maintains a notion of the current and previous jobs. In output pertaining to jobs, the current job is marked with a .Sq + and the previous job with a .Sq \- The abbreviations .Sq %+ , .Sq % , and (by analogy with the syntax of the .Va history mechanism) .Sq %% all refer to the current job, and .Sq %\- refers to the previous job. .Pp The job control mechanism requires that the .Va stty (1) option .Sq new be set on some systems. It is an artifact from a .Sq new implementation of the tty driver which allows generation of interrupt characters from the keyboard to tell jobs to stop. See .Va stty (1) and the .Va setty builtin command for details on setting options in the new tty driver. .Ss "Status reporting" The shell learns immediately whenever a process changes state. It normally informs you whenever a job becomes blocked so that no further progress is possible, but only right before it prints a prompt. This is done so that it does not otherwise disturb your work. If, however, you set the shell variable .Va notify , the shell will notify you immediately of changes of status in background jobs. There is also a shell command .Va notify which marks a single process so that its status changes will be immediately reported. By default .Va notify marks the current process; simply say .Sq notify after starting a background job to mark it. .Pp When you try to leave the shell while jobs are stopped, you will be warned that .Sq There are suspended jobs. You may use the .Va jobs command to see what they are. If you do this or immediately try to exit again, the shell will not warn you a second time, and the suspended jobs will be terminated. .Ss "Automatic, periodic and timed events (+)" There are various ways to run commands and take other actions automatically at various times in the .Sq `life cycle ' of the shell. They are summarized here, and described in detail under the appropriate .Va Builtin commands , .Va Special shell variables and .Va Special aliases .Pp The .Va sched builtin command puts commands in a scheduled-event list, to be executed by the shell at a given time. .Pp The .Va beepcmd , .Va cwdcmd , .Va periodic , .Va precmd , .Va postcmd , and .Va jobcmd .Va Special aliases can be set, respectively, to execute commands when the shell wants to ring the bell, when the working directory changes, every .Va tperiod minutes, before each prompt, before each command gets executed, after each command gets executed, and when a job is started or is brought into the foreground. .Pp The .Va autologout shell variable can be set to log out or lock the shell after a given number of minutes of inactivity. .Pp The .Va mail shell variable can be set to check for new mail periodically. .Pp The .Va printexitvalue shell variable can be set to print the exit status of commands which exit with a status other than zero. .Pp The .Va rmstar shell variable can be set to ask the user, when .Sq rm * is typed, if that is really what was meant. .Pp The .Va time shell variable can be set to execute the .Va time builtin command after the completion of any process that takes more than a given number of CPU seconds. .Pp The .Va watch and .Va who shell variables can be set to report when selected users log in or out, and the .Va log builtin command reports on those users at any time. .Ss "Native Language System support (+)" The shell is eight bit clean (if so compiled; see the .Va version shell variable) and thus supports character sets needing this capability. NLS support differs depending on whether or not the shell was compiled to use the system's NLS (again, see .Va version ). In either case, 7-bit ASCII is the default character code (e.g., the classification of which characters are printable) and sorting, and changing the .Va LANG or .Va LC_CTYPE environment variables causes a check for possible changes in these respects. .Pp When using the system's NLS, the .Va setlocale (3) function is called to determine appropriate character code/classification and sorting (e.g., a 'en_CA.UTF-8' would yield "UTF-8" as a character code). This function typically examines the .Va LANG and .Va LC_CTYPE environment variables; refer to the system documentation for further details. When not using the system's NLS, the shell simulates it by assuming that the ISO 8859-1 character set is used whenever either of the .Va LANG and .Va LC_CTYPE variables are set, regardless of their values. Sorting is not affected for the simulated NLS. .Pp In addition, with both real and simulated NLS, all printable characters in the range \e200\-\e377, i.e., those that have M- .Va char bindings, are automatically rebound to .Va self-insert-command The corresponding binding for the escape- .Va char sequence, if any, is left alone. These characters are not rebound if the .Va NOREBIND environment variable is set. This may be useful for the simulated NLS or a primitive real NLS which assumes full ISO 8859-1. Otherwise, all M- .Va char bindings in the range \e240\-\e377 are effectively undone. Explicitly rebinding the relevant keys with .Va bindkey is of course still possible. .Pp Unknown characters (i.e., those that are neither printable nor control characters) are printed in the format \ennn. If the tty is not in 8 bit mode, other 8 bit characters are printed by converting them to ASCII and using standout mode. The shell never changes the 7/8 bit mode of the tty and tracks user-initiated changes of 7/8 bit mode. NLS users (or, for that matter, those who want to use a meta key) may need to explicitly set the tty in 8 bit mode through the appropriate .Va stty (1) command in, e.g., the .Va ~/.login file. .Ss "OS variant support (+)" A number of new builtin commands are provided to support features in particular operating systems. All are described in detail in the .Va Builtin commands section. .Pp On systems that support TCF (aix-ibm370, aix-ps2), .Va getspath and .Va setspath get and set the system execution path, .Va getxvers and .Va setxvers get and set the experimental version prefix and .Va migrate migrates processes between sites. The .Va jobs builtin prints the site on which each job is executing. .Pp Under BS2000, .Va bs2cmd executes commands of the underlying BS2000/OSD operating system. .Pp Under Domain/OS, .Va inlib adds shared libraries to the current environment, .Va rootnode changes the rootnode and .Va ver changes the systype. .Pp Under Mach, .Va setpath is equivalent to Mach's .Va setpath (1). .Pp Under Masscomp/RTU and Harris CX/UX, .Va universe sets the universe. .Pp Under Harris CX/UX, .Va ucb or .Va att runs a command under the specified universe. .Pp Under Convex/OS, .Va warp prints or sets the universe. .Pp The .Va VENDOR , .Va OSTYPE and .Va MACHTYPE environment variables indicate respectively the vendor, operating system and machine type (microprocessor class or machine model) of the system on which the shell thinks it is running. These are particularly useful when sharing one's home directory between several types of machines; one can, for example, .IP "" 4 set path = (~/bin.$MACHTYPE /usr/ucb /bin /usr/bin .) .Pp in one's .Va ~/.login and put executables compiled for each machine in the appropriate directory. .Pp The .Va version shell variable indicates what options were chosen when the shell was compiled. .Pp Note also the .Va newgrp builtin, the .Va afsuser and .Va echo_style shell variables and the system-dependent locations of the shell's input files (see .Va FILES ). .Ss "Signal handling" Login shells ignore interrupts when reading the file .Va ~/.logout The shell ignores quit signals unless started with .Fl q\fR. Login shells catch the terminate signal, but non-login shells inherit the terminate behavior from their parents. Other signals have the values which the shell inherited from its parent. .Pp In shell scripts, the shell's handling of interrupt and terminate signals can be controlled with .Va onintr , and its handling of hangups can be controlled with .Va hup and .Va nohup .Pp The shell exits on a hangup (see also the .Va logout shell variable). By default, the shell's children do too, but the shell does not send them a hangup when it exits. .Va hup arranges for the shell to send a hangup to a child when it exits, and .Va nohup sets a child to ignore hangups. .Ss "Terminal management (+)" The shell uses three different sets of terminal ( .Dq tty ) modes: `edit', used when editing, .Sq quote , used when quoting literal characters, and .Sq execute , used when executing commands. The shell holds some settings in each mode constant, so commands which leave the tty in a confused state do not interfere with the shell. The shell also matches changes in the speed and padding of the tty. The list of tty modes that are kept constant can be examined and modified with the .Va setty builtin. Note that although the editor uses CBREAK mode (or its equivalent), it takes typed-ahead characters anyway. .Pp The .Va echotc , .Va settc and .Va telltc commands can be used to manipulate and debug terminal capabilities from the command line. .Pp On systems that support SIGWINCH or SIGWINDOW, the shell adapts to window resizing automatically and adjusts the environment variables .Va LINES and .Va COLUMNS if set. If the environment variable .Va TERMCAP contains li# and co# fields, the shell adjusts them to reflect the new window size. .Sh REFERENCE The next sections of this manual describe all of the available .Va Builtin commands , .Va Special aliases and .Va Special shell variables .Ss "Builtin commands" .Bl -tag -width XXXXXXX -offset indent .It Ar %job A synonym for the .Va fg builtin command. .It Ar %job \&& A synonym for the .Va bg builtin command. .It Ar \&: Does nothing, successfully. .Pp .It Ar @ .It Ar @ name = expr .It Ar @ name[index] = expr .It Ar @ name++|-- .It Ar @name[index]++|-- The first form prints the values of all shell variables. .Pp The second form assigns the value of .Va expr to .Va name The third form assigns the value of .Va expr to the .Va index 'th component of .Va name ; both .Va name and its .Va index 'th component must already exist. .Pp .Va expr may contain the operators .Sq * , .Sq + , etc., as in C. If .Va expr contains .Sq < , .Sq > , .Sq & or .Sq then at least that part of .Va expr must be placed within .Sq () Note that the syntax of .Va expr has nothing to do with that described under .Va Expressions .Pp The fourth and fifth forms increment ( .Sq ++ ) or decrement .Sq ( -- ) .Va name or its .Va index 'th component. .Pp The space between .Sq @ and .Va name is required. The spaces between .Va name and .Sq = and between .Sq = and .Va expr are optional. Components of .Va expr must be separated by spaces. -.It Ar alias[name[wordlist]] +.It Ar alias [name [wordlist]] Without arguments, prints all aliases. With .Va name , prints the alias for name. With .Va name and .Va wordlist , assigns .Va wordlist as the alias of .Va name .Va wordlist is command and filename substituted. .Va name may not be .Sq alias or .Sq unalias See also the .Va unalias builtin command. .It Ar alloc Shows the amount of dynamic memory acquired, broken down into used and free memory. With an argument shows the number of free and used blocks in each size category. The categories start at size 8 and double at each step. -This -command's output may vary across system types, because systems other than the VAX -may use a different memory allocator. -.TP 8 -.It Ar bg[%job...] +This command's output may vary across system types, because systems other +than the VAX may use a different memory allocator. +.It Ar bg [%job...] Puts the specified jobs (or, without arguments, the current job) into the background, continuing each if it is stopped. .Va job may be a number, a string, -.Sq -, -.Sq % -, -.Sq + +.Sq \&, , +.Sq % , +.Sq + , or -.Sq \- +.Sq \&- as described under -.Va Jobs -.Pp +.Va Jobs . .It Ar bindkey Oo Fl l Ns | Ns Fl d Ns | Ns Fl e Ns | Ns Fl v Ns | Ns Fl u Oc (+) .It Ar bindkey Oo Fl a Oc Oo Fl b Oc Oo Fl k Oc Oo Fl r Oc Oo Fl Fl Oc Ar key (+) .It Ar bindkey Oo Fl a Oc Oo Fl b Oc Oo Fl k Oc Oo Fl c Ns | Ns Fl s Oc Oo Fl Fl Oc Ar key command (+) .\" .It Ar macro can't take too many words, so I used \fB in the previous tags Without options, the first form lists all bound keys and the editor command to which each is bound, the second form lists the editor command to which .Va key is bound and the third form binds the editor command .Va command to .Va key Options include: .Pp .Bl -tag -width XXX -compact .It Fl l Lists all editor commands and a short description of each. .It Fl d Binds all keys to the standard bindings for the default editor, as per .Va -e and .Va -v below. .It Fl e Binds all keys to .Va emacs (1)\-style bindings. Unsets .Va vimode .It Fl v Binds all keys to .Va vi (1)\-style bindings. Sets .Va vimode .It Fl a Lists or changes key-bindings in the alternative key map. This is the key map used in .Va vimode command mode. .It Fl b .Va key is interpreted as a control character written ^ .Va character (e.g., .Sq ^A ) or C- .Va character (e.g., .Sq C-A ), a meta character written M- .Va character (e.g., .Sq M-A ), a function key written F- .Va string (e.g., .Sq F-string ), or an extended prefix key written X- .Va character (e.g., .Sq X-A ). .It Fl k .Va key is interpreted as a symbolic arrow key name, which may be one of `down', .Sq up , .Sq left or .Sq right .It Fl r Removes .Va key 's binding. Be careful: .Sq bindkey \-r does .Va not bind .Va key to .Va self-insert-command (q.v.), it unbinds .Va key completely. .It Fl c .Va command is interpreted as a builtin or external command instead of an editor command. .It Fl s .Va command is taken as a literal string and treated as terminal input when .Va key is typed. Bound keys in .Va command are themselves reinterpreted, and this continues for ten levels of interpretation. .It Fl \&- Forces a break from option processing, so the next word is taken as .Va key even if it begins with '\&-'. .It Fl u (or any invalid option) Prints a usage message. .El .Pp .Va key may be a single character or a string. If a command is bound to a string, the first character of the string is bound to .Va sequence-lead-in and the entire string is bound to the command. .Pp Control characters in .Va key can be literal (they can be typed by preceding them with the editor command .Va quoted-insert , normally bound to .Sq ^V ) or written caret-character style, e.g., .Sq ^A Delete is written .Sq ^? (caret-question mark). .Va key and .Va command can contain backslashed escape sequences (in the style of System V .Va echo (1)) as follows: .Pp .Bl -tag -width XXXX -compact -offset indent .It \ea Bell .It \eb Backspace .It \ee Escape .It \ef Form feed .It \en Newline .It \er Carriage return .It \et Horizontal tab .It \ev Vertical tab .It \e\fInnn The ASCII character corresponding to the octal number .Va nnn .El .Pp `\e' nullifies the special meaning of the following character, if it has any, notably .Sq \e and .Sq ^ .It bs2cmd Va bs2000-command (+) Passes .Va bs2000-command to the BS2000 command interpreter for execution. Only non-interactive commands can be executed, and it is not possible to execute any command that would overlay the image of the current process, like /EXECUTE or /CALL-PROCEDURE. (BS2000 only) .It break Causes execution to resume after the .Va end of the nearest enclosing .Va foreach or .Va while The remaining commands on the current line are executed. Multi-level breaks are thus possible by writing them all on one line. .It breaksw Causes a break from a .Va switch , resuming after the .Va endsw .It builtins \fR(+) Prints the names of all builtin commands. .It bye \fR(+) A synonym for the .Va logout builtin command. Available only if the shell was so compiled; see the .Va version shell variable. .It case \fIlabel\fB: A label in a .Va switch statement as discussed below. .It cd \fR[ .Fl p\fR] [ .Fl l\fR] [ .Fl n\fR| .Fl v\fR] [\I--\fR] [ .Va name ] If a directory .Va name is given, changes the shell's working directory to .Va name If not, changes to .Va home , unless the .Va cdtohome variable is not set, in which case a .Va name is required. If .Va name is .Sq \- it is interpreted as the previous working directory (see .Va Other substitutions ). (+) If .Va name is not a subdirectory of the current directory (and does not begin with .Sq / , .Sq ./ or .Sq ../ ), each component of the variable .Va cdpath is checked to see if it has a subdirectory .Va name Finally, if all else fails but .Va name is a shell variable whose value begins with .Sq / or '.', then this is tried to see if it is a directory, and the .Fl p\fR option is implied. .RS +8 .Pp With .Fl p\fR, prints the final directory stack, just like .Va dirs The .Fl l\fR, .Fl n\fR and .Fl v\fR flags have the same effect on .Va cd as on .Va dirs , and they imply .Fl p\fR. (+) Using .Fl \-\fR forces a break from option processing so the next word is taken as the directory .Va name even if it begins with '\-'. (+) .Pp See also the .Va implicitcd and .Va cdtohome shell variables. .RE .It chdir A synonym for the .Va cd builtin command. .It complete \fR[ .Va command [\fIword\fB/\fIpattern\fB/ .Va list [\fB: .Va select ] .Va / [[ .Va suffix ] .Va / ] ...]] (+) Without arguments, lists all completions. With .Va command , lists completions for .Va command With .Va command and .Va word etc., defines completions. .RS +8 .Pp .Va command may be a full command name or a glob-pattern (see .Va Filename substitution ). It can begin with .Sq \- to indicate that completion should be used only when .Va command is ambiguous. .Pp .Va word specifies which word relative to the current word is to be completed, and may be one of the following: .Pp .PD 0 .RS +4 .TP 4 .It c Current-word completion. .Va pattern is a glob-pattern which must match the beginning of the current word on the command line. .Va pattern is ignored when completing the current word. .TP 4 .It C Like .Va c , but includes .Va pattern when completing the current word. .TP 4 .It n Next-word completion. .Va pattern is a glob-pattern which must match the beginning of the previous word on the command line. .TP 4 .It N Like .Va n , but must match the beginning of the word two before the current word. .TP 4 .It p Position-dependent completion. .Va pattern is a numeric range, with the same syntax used to index shell variables, which must include the current word. .PD .RE .Pp .Va list , the list of possible completions, may be one of the following: .Pp .Bl -tag .It a Aliases .It b Bindings (editor commands) .It c Commands (builtin or external commands) .It C External commands which begin with the supplied path prefix .It d Directories .It D Directories which begin with the supplied path prefix .It e Environment variables .It f Filenames .It F Filenames which begin with the supplied path prefix .It g Groupnames .It j Jobs .It l Limits .It n Nothing .It s Shell variables .It S Signals .It t Plain ( .Dq text ) files .It T Plain ( .Dq text ) files which begin with the supplied path prefix .It v Any variables .It u Usernames .It x Like .Va n , but prints .Va select when .Va list-choices is used. .It X Completions $ .Va var Words from the variable .Va var (...) Words from the given list \`...\` Words from the output of command .El .Pp .Va select is an optional glob-pattern. If given, words from only .Va list that match .Va select are considered and the .Va fignore shell variable is ignored. The last three types of completion may not have a .Va select pattern, and .Va x uses .Va select as an explanatory message when the .Va list-choices editor command is used. .Pp .Va suffix is a single character to be appended to a successful completion. If null, no character is appended. If omitted (in which case the fourth delimiter can also be omitted), a slash is appended to directories and a space to other words. .Pp .Va command invoked from \`...\` version has additional environment variable set, the variable name is \% .Va COMMAND_LINE \% and contains (as its name indicates) contents of the current (already typed in) command line. One can examine and use contents of the \% .Va COMMAND_LINE \% variable in her custom script to build more sophisticated completions (see completion for svn(1) included in this package). .Pp Now for some examples. Some commands take only directories as arguments, so there's no point completing plain files. .IP "" 4 > complete cd 'p/1/d/' .Pp completes only the first word following .Sq cd (`p/1') with a directory. .Va p -type completion can also be used to narrow down command completion: .IP "" 4 > co[^D] .br complete compress .br > complete \-co* 'p/0/(compress)/' .br > co[^D] .br > compress .Pp This completion completes commands (words in position 0, .Sq p/0 ) which begin with .Sq co (thus matching .Sq co* ) to .Sq compress (the only word in the list). The leading .Sq \- indicates that this completion is to be used with only ambiguous commands. .IP "" 4 > complete find 'n/\-user/u/' .Pp is an example of .Va n -type completion. Any word following .Sq find and immediately following .Sq \-user is completed from the list of users. .IP "" 4 > complete cc 'c/\-I/d/' .Pp demonstrates .Va c -type completion. Any word following .Sq cc and beginning with .Sq \-I is completed as a directory. `\-I' is not taken as part of the directory because we used lowercase .Va c .Pp Different .Va list s are useful with different commands. .IP "" 4 > complete alias 'p/1/a/' .br > complete man 'p/*/c/' .br > complete set 'p/1/s/' .br > complete true 'p/1/x:Truth has no options./' .Pp These complete words following .Sq alias with aliases, .Sq man with commands, and .Sq set with shell variables. `true' doesn't have any options, so .Va x does nothing when completion is attempted and prints .Sq Truth has no options. when completion choices are listed. .Pp Note that the .Va man example, and several other examples below, could just as well have used 'c/*' or 'n/*' as 'p/*'. .Pp Words can be completed from a variable evaluated at completion time, .IP "" 4 > complete ftp 'p/1/$hostnames/' .br > set hostnames = (rtfm.mit.edu tesla.ee.cornell.edu) .br > ftp [^D] .br rtfm.mit.edu tesla.ee.cornell.edu .br > ftp [^C] .br > set hostnames = (rtfm.mit.edu tesla.ee.cornell.edu uunet.uu.net) .br > ftp [^D] .br rtfm.mit.edu tesla.ee.cornell.edu uunet.uu.net .Pp or from a command run at completion time: .IP "" 4 > complete kill 'p/*/\`ps | awk \e{print\e \e$1\e}\`/' .br > kill \-9 [^D] .br 23113 23377 23380 23406 23429 23529 23530 PID .Pp Note that the .Va complete command does not itself quote its arguments, so the braces, space and .Sq $ in .Sq {print $1} must be quoted explicitly. .Pp One command can have multiple completions: .IP "" 4 > complete dbx 'p/2/(core)/' 'p/*/c/' .Pp completes the second argument to .Sq dbx with the word .Sq core and all other arguments with commands. Note that the positional completion is specified before the next-word completion. Because completions are evaluated from left to right, if the next-word completion were specified first it would always match and the positional completion would never be executed. This is a common mistake when defining a completion. .Pp The .Va select pattern is useful when a command takes files with only particular forms as arguments. For example, .IP "" 4 > complete cc 'p/*/f:*.[cao]/' .Pp completes .Sq cc arguments to files ending in only .Sq .c , .Sq .a , or .Sq .o .Va select can also exclude files, using negation of a glob-pattern as described under .Va Filename substitution One might use .IP "" 4 > complete rm 'p/*/f:^*.{c,h,cc,C,tex,1,man,l,y}/' .Pp to exclude precious source code from .Sq rm completion. Of course, one could still type excluded names manually or override the completion mechanism using the .Va complete-word-raw or .Va list-choices-raw editor commands (q.v.). .Pp The .Sq C , .Sq D , .Sq F and .Sq T .Va list s are like .Sq c , .Sq d , .Sq f and .Sq t respectively, but they use the .Va select argument in a different way: to restrict completion to files beginning with a particular path prefix. For example, the Elm mail program uses .Sq = as an abbreviation for one's mail directory. One might use .IP "" 4 > complete elm c@=@F:$HOME/Mail/@ .Pp to complete .Sq elm \-f = as if it were .Sq elm \-f ~/Mail/ Note that we used .Sq @ instead of .Sq / to avoid confusion with the .Va select argument, and we used `$HOME' instead of .Sq ~ because home directory substitution works at only the beginning of a word. .Pp .Va suffix is used to add a nonstandard suffix (not space or .Sq / for directories) to completed words. .IP "" 4 > complete finger 'c/*@/$hostnames/' 'p/1/u/@' .Pp completes arguments to .Sq finger from the list of users, appends an .Sq @ , and then completes after the .Sq @ from the .Sq hostnames variable. Note again the order in which the completions are specified. .Pp Finally, here's a complex example for inspiration: .IP "" 4 > complete find \e .br \&'n/\-name/f/' 'n/\-newer/f/' 'n/\-{,n}cpio/f/' \e .br \&\'n/\-exec/c/' 'n/\-ok/c/' 'n/\-user/u/' \e .br \&'n/\-group/g/' 'n/\-fstype/(nfs 4.2)/' \e .br \&'n/\-type/(b c d f l p s)/' \e .br \'c/\-/(name newer cpio ncpio exec ok user \e .br group fstype type atime ctime depth inum \e .br ls mtime nogroup nouser perm print prune \e .br size xdev)/' \e .br \&'p/*/d/' .Pp This completes words following .Sq \-name , .Sq \-newer , .Sq \-cpio or .Sq ncpio (note the pattern which matches both) to files, words following .Sq \-exec or .Sq \-ok to commands, words following .Sq user and .Sq group to users and groups respectively and words following .Sq \-fstype or .Sq \-type to members of the given lists. It also completes the switches themselves from the given list (note the use of .Va c -type completion) and completes anything not otherwise completed to a directory. Whew. .Pp Remember that programmed completions are ignored if the word being completed is a tilde substitution (beginning with .Sq ~ ) or a variable (beginning with .Sq $ ). See also the .Va uncomplete builtin command. .RE .TP 8 .B continue Continues execution of the nearest enclosing .Va while or .Va foreach The rest of the commands on the current line are executed. .TP 8 .B default: Labels the default case in a .Va switch statement. It should come after all .Va case labels. .Pp .B dirs \fR[ .Fl l\fR] [ .Fl n\fR| .Fl v\fR] .br .B dirs \-S\fR| .Fl L \fR[ .Va filename ] (+) .PD 0 .TP 8 .B dirs \-c \fR(+) The first form prints the directory stack. The top of the stack is at the left and the first directory in the stack is the current directory. With .Fl l\fR, .Sq ~ or .Sq ~\fIname\fP in the output is expanded explicitly to .Va home or the pathname of the home directory for user \fIname\fP. (+) With .Fl n\fR, entries are wrapped before they reach the edge of the screen. (+) With .Fl v\fR, entries are printed one per line, preceded by their stack positions. (+) If more than one of .Fl n\fR or .Fl v\fR is given, .Fl v\fR takes precedence. .Fl p\fR is accepted but does nothing. .PD .RS +8 .Pp With .Fl S\fR, the second form saves the directory stack to .Va filename as a series of .Va cd and .Va pushd commands. With .Fl L\fR, the shell sources .Va filename , which is presumably a directory stack file saved by the .Fl S\fR option or the .Va savedirs mechanism. In either case, .Va dirsfile is used if .Va filename is not given and .Va ~/.cshdirs is used if .Va dirsfile is unset. .Pp Note that login shells do the equivalent of .Sq dirs \-L on startup and, if .Va savedirs is set, .Sq dirs \-S before exiting. Because only .Va ~/.tcshrc is normally sourced before .Va ~/.cshdirs , .Va dirsfile should be set in .Va ~/.tcshrc rather than .Va ~/.login .Pp The last form clears the directory stack. .RE .TP 8 .B echo \fR[ .Fl n\fR] .Va word ... Writes each .Va word to the shell's standard output, separated by spaces and terminated with a newline. The .Va echo_style shell variable may be set to emulate (or not) the flags and escape sequences of the BSD and/or System V versions of .Va echo ; see .Va echo (1). .TP 8 .B echotc \fR[ .Fl sv\fR] .Va arg ... (+) Exercises the terminal capabilities (see .Va termcap (5)) in .Va args For example, 'echotc home' sends the cursor to the home position, \&'echotc cm 3 10' sends it to column 3 and row 10, and \&'echotc ts 0; echo "This is a test."; echotc fs' prints "This is a test." in the status line. .RS +8 .Pp If .Va arg is 'baud', 'cols', 'lines', 'meta' or 'tabs', prints the value of that capability ("yes" or "no" indicating that the terminal does or does not have that capability). One might use this to make the output from a shell script less verbose on slow terminals, or limit command output to the number of lines on the screen: .IP "" 4 > set history=\`echotc lines\` .br > @ history\-\- .Pp Termcap strings may contain wildcards which will not echo correctly. One should use double quotes when setting a shell variable to a terminal capability string, as in the following example that places the date in the status line: .IP "" 4 > set tosl="\`echotc ts 0\`" .br > set frsl="\`echotc fs\`" .br > echo \-n "$tosl";date; echo \-n "$frsl" .Pp With .Fl s\fR, nonexistent capabilities return the empty string rather than causing an error. With .Fl v\fR, messages are verbose. .RE .Pp .B else .br .B end .br .B endif .PD 0 .TP 8 .B endsw See the description of the .Va foreach , .Va if , .Va switch , and .Va while statements below. .PD .TP 8 .B eval .Va arg ... Treats the arguments as input to the shell and executes the resulting command(s) in the context of the current shell. This is usually used to execute commands generated as the result of command or variable substitution, because parsing occurs before these substitutions. See .Va tset (1) for a sample use of .Va eval .TP 8 .B exec .Va command Executes the specified command in place of the current shell. .TP 8 .B exit \fR[ .Va expr ] The shell exits either with the value of the specified .Va expr (an expression, as described under .Va Expressions ) or, without .Va expr , with the value 0. .TP 8 .B fg \fR[\fB% .Va job ...] Brings the specified jobs (or, without arguments, the current job) into the foreground, continuing each if it is stopped. .Va job may be a number, a string, .Sq , .Sq % , .Sq + or .Sq \- as described under .Va Jobs See also the .Va run-fg-editor editor command. .TP 8 .B filetest \- .Va op file ... (+) Applies .Va op (which is a file inquiry operator as described under .Va File inquiry operators ) to each .Va file and returns the results as a space-separated list. .Pp .B foreach \fIname \fB(\fIwordlist\fB) .br \&... .PD 0 .TP 8 .B end Successively sets the variable .Va name to each member of .Va wordlist and executes the sequence of commands between this command and the matching .Va end (Both .Va foreach and .Va end must appear alone on separate lines.) The builtin command .Va continue may be used to continue the loop prematurely and the builtin command .Va break to terminate it prematurely. When this command is read from the terminal, the loop is read once prompting with .Sq foreach? (or .Va prompt2 ) before any statements in the loop are executed. If you make a mistake typing in a loop at the terminal you can rub it out. .PD .TP 8 .B getspath \fR(+) Prints the system execution path. (TCF only) .TP 8 .B getxvers \fR(+) Prints the experimental version prefix. (TCF only) .TP 8 .B glob \fIwordlist Like .Va echo , but the .Sq -n parameter is not recognized and words are delimited by null characters in the output. Useful for programs which wish to use the shell to filename expand a list of words. .TP 8 .B goto \fIword .Va word is filename and command-substituted to yield a string of the form .Sq label The shell rewinds its input as much as possible, searches for a line of the form .Sq label: , possibly preceded by blanks or tabs, and continues execution after that line. .TP 8 .B hashstat Prints a statistics line indicating how effective the internal hash table has been at locating commands (and avoiding .Va exec 's). An .Va exec is attempted for each component of the .Va path where the hash function indicates a possible hit, and in each component which does not begin with a .Sq / .IP On machines without .Va vfork (2), prints only the number and size of hash buckets. .Pp .B history \fR[ .Fl hTr\fR] [ .Va n ] .br .B history \-S\fR| .Fl L| .Fl M \fR[ .Va filename ] (+) .PD 0 .TP 8 .B history \-c \fR(+) The first form prints the history event list. If .Va n is given only the .Va n most recent events are printed or saved. With .Fl h\fR, the history list is printed without leading numbers. If .Va -T is specified, timestamps are printed also in comment form. (This can be used to produce files suitable for loading with 'history \-L' or 'source \-h'.) With .Fl r\fR, the order of printing is most recent first rather than oldest first. .PD .RS +8 .Pp With .Fl S\fR, the second form saves the history list to .Va filename If the first word of the .Va savehist shell variable is set to a number, at most that many lines are saved. If the second word of .Va savehist is set to .Sq merge , the history list is merged with the existing history file instead of replacing it (if there is one) and sorted by time stamp. (+) Merging is intended for an environment like the X Window System with several shells in simultaneous use. If the second word of .Va savehist is .Sq merge and the third word is set to .Sq lock , the history file update will be serialized with other shell sessions that would possibly like to merge history at exactly the same time. .Pp With .Fl L\fR, the shell appends .Va filename , which is presumably a history list saved by the .Fl S\fR option or the .Va savehist mechanism, to the history list. .Fl M\fR is like .Fl L\fR, but the contents of .Va filename are merged into the history list and sorted by timestamp. In either case, .Va histfile is used if .Va filename is not given and .Va ~/.history is used if .Va histfile is unset. `history \-L' is exactly like 'source \-h' except that it does not require a filename. .Pp Note that login shells do the equivalent of .Sq history \-L on startup and, if .Va savehist is set, .Sq history \-S before exiting. Because only .Va ~/.tcshrc is normally sourced before .Va ~/.history , .Va histfile should be set in .Va ~/.tcshrc rather than .Va ~/.login .Pp If .Va histlit is set, the first and second forms print and save the literal (unexpanded) form of the history list. .Pp The last form clears the history list. .RE .TP 8 .B hup \fR[ .Va command ] \fR(+) With .Va command , runs .Va command such that it will exit on a hangup signal and arranges for the shell to send it a hangup signal when the shell exits. Note that commands may set their own response to hangups, overriding .Va hup Without an argument, causes the non-interactive shell only to exit on a hangup for the remainder of the script. See also .Va Signal handling and the .Va nohup builtin command. .TP 8 .B if (\fIexpr\fB) \fIcommand If .Va expr (an expression, as described under .Va Expressions ) evaluates true, then .Va command is executed. Variable substitution on .Va command happens early, at the same time it does for the rest of the .Va if command. .Va command must be a simple command, not an alias, a pipeline, a command list or a parenthesized command list, but it may have arguments. Input/output redirection occurs even if .Va expr is false and .Va command is thus .Va not executed; this is a bug. .Pp .B if (\fIexpr\fB) then .br \&... .br .B else if (\fIexpr2\fB) then .br \&... .br .B else .br \&... .PD 0 .TP 8 .B endif If the specified .Va expr is true then the commands to the first .Va else are executed; otherwise if .Va expr2 is true then the commands to the second .Va else are executed, etc. Any number of .Va else-if pairs are possible; only one .Va endif is needed. The .Va else part is likewise optional. (The words .Va else and .Va endif must appear at the beginning of input lines; the .Va if must appear alone on its input line or after an .Va else .) .PD .TP 8 .B inlib .Va shared-library ... (+) Adds each .Va shared-library to the current environment. There is no way to remove a shared library. (Domain/OS only) .TP 8 .B jobs \fR[ .Fl l\fR] Lists the active jobs. With .Fl l\fR, lists process IDs in addition to the normal information. On TCF systems, prints the site on which each job is executing. .Pp .PD 0 .TP 8 .B kill \fR[ .Fl s .Va signal ] \fB% .Va job | .Va pid ... .PD 0 .TP 8 .B kill \-l The first and second forms sends the specified .Va signal (or, if none is given, the TERM (terminate) signal) to the specified jobs or processes. .Va job may be a number, a string, .Sq , .Sq % , .Sq + or .Sq \- as described under .Va Jobs Signals are either given by number or by name (as given in .Va /usr/include/signal.h , stripped of the prefix .Sq SIG ). There is no default .Va job ; saying just .Sq kill does not send a signal to the current job. If the signal being sent is TERM (terminate) or HUP (hangup), then the job or process is sent a CONT (continue) signal as well. The third form lists the signal names. .PD .TP 8 .B limit \fR[ .Fl h\fR] [ .Va resource [ .Va maximum-use ]] Limits the consumption by the current process and each process it creates to not individually exceed .Va maximum-use on the specified .Va resource If no .Va maximum-use is given, then the current limit is printed; if no .Va resource is given, then all limitations are given. If the .Fl h\fR flag is given, the hard limits are used instead of the current limits. The hard limits impose a ceiling on the values of the current limits. Only the super-user may raise the hard limits, but a user may lower or raise the current limits within the legal range. .Pp Controllable resources currently include (if supported by the OS): .Bl -tag -width pseudoterminals -compact -offset indent .It Va cputime the maximum number of cpu-seconds to be used by each process .It Va filesize the largest single file which can be created .It Va datasize the maximum growth of the data+stack region via sbrk(2) beyond the end of the program text .It Va stacksize the maximum size of the automatically-extended stack region .It Va coredumpsize the size of the largest core dump that will be created .It Va memoryuse the maximum amount of physical memory a process may have allocated to it at a given time .It Va vmemoryuse the maximum amount of virtual memory a process may have allocated to it at a given time (address space) .It Va vmemoryuse the maximum amount of virtual memory a process may have allocated to it at a given time .It Va heapsize the maximum amount of memory a process may allocate per .Xr brk 2 system call .It Va descriptors or .It Va openfiles the maximum number of open files for this process .It Va pseudoterminals the maximum number of pseudo-terminals for this user .It Va kqueues the maximum number of kqueues allocated for this process .It Va concurrency the maximum number of threads for this process .It Va memorylocked the maximum size which a process may lock into memory using mlock(2) .It Va maxproc the maximum number of simultaneous processes for this user id .It Va maxthread the maximum number of simultaneous threads (lightweight processes) for this user id .It Va threads the maximum number of threads for this process .It Va sbsize the maximum size of socket buffer usage for this user .It Va swapsize the maximum amount of swap space reserved or used for this user .It Va maxlocks the maximum number of locks for this user .It Va posixlocks the maximum number of POSIX advisory locks for this user .It Va maxsignal the maximum number of pending signals for this user .It Va maxmessage the maximum number of bytes in POSIX mqueues for this user .It Va maxnice the maximum nice priority the user is allowed to raise mapped from [19...-20] to [0...39] for this user .It Va maxrtprio the maximum realtime priority for this user .It Va maxrttime the timeout for RT tasks in microseconds for this user. .El .Pp .Va maximum-use may be given as a (floating point or integer) number followed by a scale factor. For all limits other than .Va cputime the default scale is .Sq k or .Sq kilobytes (1024 bytes); a scale factor of .Sq m or .Sq megabytes or .Sq g or .Sq gigabytes may also be used. For .Va cputime the default scaling is .Sq seconds , while .Sq m for minutes or .Sq h for hours, or a time of the form .Sq mm:ss giving minutes and seconds may be used. .Pp If .Va maximum-use is .Sq unlimited , then the limitation on the specified .Va resource is removed (this is equivalent to the .Va unlimit builtin command). .Pp For both .Va resource names and scale factors, unambiguous prefixes of the names suffice. .RE .TP 8 .B log \fR(+) Prints the .Va watch shell variable and reports on each user indicated in .Va watch who is logged in, regardless of when they last logged in. See also .Va watchlog .TP 8 .B login Terminates a login shell, replacing it with an instance of .Va /bin/login . This is one way to log off, included for compatibility with .Xr sh 1 . .TP 8 .B logout Terminates a login shell. Especially useful if .Va ignoreeof is set. .TP 8 .B ls\-F \fR[\- .Va switch ...] [ .Va file ...] (+) Lists files like .Sq ls \-F , but much faster. It identifies each type of special file in the listing with a special character: .Bl -tag -width x -offset indent -compact .It Dv / Directory .It Dv * Executable .It Dv # Block device .It Dv % Character device .It Dv | Named pipe (systems with named pipes only) .It Dv = Socket (systems with sockets only) .It Dv @ Symbolic link (systems with symbolic links only) .It Dv + Hidden directory (AIX only) or context dependent (HP/UX only) .It Dv : Network special (HP/UX only) .El .Pp If the .Va listlinks shell variable is set, symbolic links are identified in more detail (on only systems that have them, of course): .Pp .PD 0 .TP 4 @ Symbolic link to a non-directory .TP 4 > Symbolic link to a directory .TP 4 & Symbolic link to nowhere .PD .Pp .Va listlinks also slows down \fIls\-F\fR and causes partitions holding files pointed to by symbolic links to be mounted. .Pp If the .Va listflags shell variable is set to .Sq x , .Sq a or .Sq A , or any combination thereof (e.g., .Sq xA ), they are used as flags to \fIls\-F\fR, making it act like .Sq ls \-xF , .Sq ls \-Fa , .Sq ls \-FA or a combination (e.g., .Sq ls \-FxA ). On machines where .Sq ls \-C is not the default, \fIls\-F\fR acts like .Sq ls \-CF , unless .Va listflags contains an .Sq x , in which case it acts like .Sq ls \-xF \fIls\-F\fR passes its arguments to .Va ls (1) if it is given any switches, so .Sq alias ls ls\-F generally does the right thing. .Pp The \fBls\-F\fR builtin can list files using different colors depending on the filetype or extension. See the .Va color shell variable and the .Va LS_COLORS environment variable. .RE .Pp .B migrate \fR[ .Fl .Va site ] .Va pid |\fB% .Va jobid ... (+) .PD 0 .TP 8 .B migrate \- .Va site (+) The first form migrates the process or job to the site specified or the default site determined by the system path. The second form is equivalent to .Sq migrate \- .Va site $$ : it migrates the current process to the specified site. Migrating the shell itself can cause unexpected behavior, because the shell does not like to lose its tty. (TCF only) .PD .TP 8 .B newgrp \fR[ .Fl \fR] .Va [group] (+) Equivalent to .Sq exec newgrp ; see .Va newgrp (1). Available only if the shell was so compiled; see the .Va version shell variable. .TP 8 .B nice \fR[\fB+ .Va number ] [ .Va command ] Sets the scheduling priority for the shell to .Va number , or, without .Va number , to 4. With .Va command , runs .Va command at the appropriate priority. The greater the .Va number , the less cpu the process gets. The super-user may specify negative priority by using .Sq nice \-number ... Command is always executed in a sub-shell, and the restrictions placed on commands in simple .Va if statements apply. .TP 8 .B nohup \fR[ .Va command ] With .Va command , runs .Va command such that it will ignore hangup signals. Note that commands may set their own response to hangups, overriding .Va nohup Without an argument, causes the non-interactive shell only to ignore hangups for the remainder of the script. See also .Va Signal handling and the .Va hup builtin command. .TP 8 .B notify \fR[\fB% .Va job ...] Causes the shell to notify the user asynchronously when the status of any of the specified jobs (or, without % .Va job , the current job) changes, instead of waiting until the next prompt as is usual. .Va job may be a number, a string, .Sq , .Sq % , .Sq + or .Sq \- as described under .Va Jobs See also the .Va notify shell variable. .TP 8 .B onintr \fR[ .Fl \fR| .Va label ] Controls the action of the shell on interrupts. Without arguments, restores the default action of the shell on interrupts, which is to terminate shell scripts or to return to the terminal command input level. With .Sq \- , causes all interrupts to be ignored. With .Va label , causes the shell to execute a .Sq goto .Va label when an interrupt is received or a child process terminates because it was interrupted. .IP "" 8 .Va onintr is ignored if the shell is running detached and in system startup files (see .Va FILES ), where interrupts are disabled anyway. .TP 8 .B popd \fR[ .Fl p\fR] [ .Fl l\fR] [ .Fl n\fR| .Fl v\fR] \fR[\fB+ .Va n ] Without arguments, pops the directory stack and returns to the new top directory. With a number .Sq + .Va n , discards the .Va n 'th entry in the stack. .IP "" 8 Finally, all forms of .Va popd print the final directory stack, just like .Va dirs The .Va pushdsilent shell variable can be set to prevent this and the .Fl p\fR flag can be given to override .Va pushdsilent The .Fl l\fR, .Fl n\fR and .Fl v\fR flags have the same effect on .Va popd as on .Va dirs (+) .TP 8 .B printenv \fR[ .Va name ] (+) Prints the names and values of all environment variables or, with .Va name , the value of the environment variable .Va name .TP 8 .B pushd \fR[ .Fl p\fR] [ .Fl l\fR] [ .Fl n\fR| .Fl v\fR] [ .Va name |\fB+ .Va n ] Without arguments, exchanges the top two elements of the directory stack. If .Va pushdtohome is set, .Va pushd without arguments does .Sq pushd ~ , like .Va cd (+) With .Va name , pushes the current working directory onto the directory stack and changes to .Va name If .Va name is .Sq \- it is interpreted as the previous working directory (see .Va Filename substitution ). (+) If .Va dunique is set, .Va pushd removes any instances of .Va name from the stack before pushing it onto the stack. (+) With a number .Sq + .Va n , rotates the .Va n th element of the directory stack around to be the top element and changes to it. If .Va dextract is set, however, .Sq pushd + .Va n extracts the .Va n th directory, pushes it onto the top of the stack and changes to it. (+) .IP "" 8 Finally, all forms of .Va pushd print the final directory stack, just like .Va dirs The .Va pushdsilent shell variable can be set to prevent this and the .Fl p\fR flag can be given to override .Va pushdsilent The .Fl l\fR, .Fl n\fR and .Fl v\fR flags have the same effect on .Va pushd as on .Va dirs (+) .TP 8 .B rehash Causes the internal hash table of the contents of the directories in the .Va path variable to be recomputed. This is needed if the .Va autorehash shell variable is not set and new commands are added to directories in .Va path while you are logged in. With .Va autorehash , a new command will be found automatically, except in the special case where another command of the same name which is located in a different directory already exists in the hash table. Also flushes the cache of home directories built by tilde expansion. .TP 8 .B repeat \fIcount command The specified .Va command , which is subject to the same restrictions as the .Va command in the one line .Va if statement above, is executed .Va count times. I/O redirections occur exactly once, even if .Va count is 0. .TP 8 .B rootnode // .Va nodename (+) Changes the rootnode to // .Va nodename , so that .Sq / will be interpreted as .Sq // .Va nodename (Domain/OS only) .Pp .B sched \fR(+) .br .B sched \fR[ .Va + ] .Va hh:mm command \fR(+) .PD 0 .TP 8 .B sched \- .Va n (+) The first form prints the scheduled-event list. The .Va sched shell variable may be set to define the format in which the scheduled-event list is printed. The second form adds .Va command to the scheduled-event list. For example, .PD .RS +8 .IP "" 4 > sched 11:00 echo It\e's eleven o\e'clock. .Pp causes the shell to echo .Sq It's eleven o'clock . at 11 AM. The time may be in 12-hour AM/PM format .IP "" 4 .\" TODO > sched 5pm set prompt='[%h] It\e's after 5; go home: >' .Pp or may be relative to the current time: .IP "" 4 > sched +2:15 /usr/lib/uucp/uucico \-r1 \-sother .Pp A relative time specification may not use AM/PM format. The third form removes item .Va n from the event list: .Bd -literal -offset indent > sched 1 Wed Apr 4 15:42 /usr/lib/uucp/uucico \-r1 \-sother 2 Wed Apr 4 17:00 set prompt=[%h] It's after 5; go home: > > sched \-2 > sched 1 Wed Apr 4 15:42 /usr/lib/uucp/uucico \-r1 \-sother .Ed .Pp A command in the scheduled-event list is executed just before the first prompt is printed after the time when the command is scheduled. It is possible to miss the exact time when the command is to be run, but an overdue command will execute at the next prompt. A command which comes due while the shell is waiting for user input is executed immediately. However, normal operation of an already-running command will not be interrupted so that a scheduled-event list element may be run. .Pp This mechanism is similar to, but not the same as, the .Va at (1) command on some Unix systems. Its major disadvantage is that it may not run a command at exactly the specified time. Its major advantage is that because .Va sched runs directly from the shell, it has access to shell variables and other structures. This provides a mechanism for changing one's working environment based on the time of day. .RE .Pp .B set .br .B set .Va name ... .br .B set .Va name \fB= .Va word ... .br .B set [\-r] [\-f|\-l] .Va name \fB=(\fIwordlist .Va ) ... (+) .br .B set .Va name[index] \fB= .Va word ... .br .B set \-r \fR(+) .br .B set \-r .Va name ... (+) .PD 0 .TP 8 .B set \-r .Va name \fB= .Va word ... (+) The first form of the command prints the value of all shell variables. Variables which contain more than a single word print as a parenthesized word list. The second form sets .Va name to the null string. The third form sets .Va name to the single .Va word The fourth form sets .Va name to the list of words in .Va wordlist In all cases the value is command and filename expanded. If .Fl r\fR is specified, the value is set read-only. If .Fl f\fR or .Fl l\fR are specified, set only unique words keeping their order. .Fl f\fR prefers the first occurrence of a word, and .Fl l\fR the last. The fifth form sets the .Va index 'th component of .Va name to .Va word ; this component must already exist. The sixth form lists only the names of all shell variables that are read-only. The seventh form makes .Va name read-only, whether or not it has a value. The eighth form is the same as the third form, but make .Va name read-only at the same time. .PD .IP "" 8 These arguments can be repeated to set and/or make read-only multiple variables in a single set command. Note, however, that variable expansion happens for all arguments before any setting occurs. Note also that .Sq = can be adjacent to both .Va name and .Va word or separated from both by whitespace, but cannot be adjacent to only one or the other. See also the .Va unset builtin command. .TP 8 .B setenv \fR[ .Va name [ .Va value ]] Without arguments, prints the names and values of all environment variables. Given .Va name , sets the environment variable .Va name to .Va value or, without .Va value , to the null string. .TP 8 .B setpath .Va path (+) Equivalent to .Va setpath (1). (Mach only) .TP 8 .B setspath\fR LOCAL| .Va site | .Va cpu ... (+) Sets the system execution path. (TCF only) .TP 8 .B settc .Va cap value (+) Tells the shell to believe that the terminal capability .Va cap (as defined in .Va termcap (5)) has the value .Va value No sanity checking is done. Concept terminal users may have to .Sq settc xn no to get proper wrapping at the rightmost column. .TP 8 .B setty \fR[ .Fl d\fR| .Fl q\fR| .Fl x\fR] [ .Fl a\fR] [[ .Va + | .Fl \fR] .Va mode ] (+) Controls which tty modes (see .Va Terminal management ) the shell does not allow to change. .Fl d\fR, .Fl q\fR or .Fl x\fR tells .Va setty to act on the .Sq edit , .Sq quote or .Sq execute set of tty modes respectively; without .Fl d\fR, .Fl q\fR or .Fl x\fR, .Sq execute is used. .IP "" 8 Without other arguments, .Va setty lists the modes in the chosen set which are fixed on (`+mode') or off (`\-mode'). The available modes, and thus the display, vary from system to system. With .Fl a\fR, lists all tty modes in the chosen set whether or not they are fixed. With \fB+ .Va mode , .Fl .Va mode or .Va mode , fixes .Va mode on or off or removes control from .Va mode in the chosen set. For example, .Sq setty +echok echoe fixes .Sq echok mode on and allows commands to turn .Sq echoe mode on or off, both when the shell is executing commands. .TP 8 .B setxvers\fR [ .Va string ] (+) Set the experimental version prefix to .Va string , or removes it if .Va string is omitted. (TCF only) .TP 8 .B shift \fR[ .Va variable ] Without arguments, discards .Va argv [1] and shifts the members of .Va argv to the left. It is an error for .Va argv not to be set or to have less than one word as value. With .Va variable , performs the same function on .Va variable .TP 8 .B source \fR[ .Fl h\fR] .Va name [ .Va args ...] The shell reads and executes commands from .Va name The commands are not placed on the history list. If any .Va args are given, they are placed in .Va argv (+) .Va source commands may be nested; if they are nested too deeply the shell may run out of file descriptors. An error in a .Va source at any level terminates all nested .Va source commands. With .Fl h\fR, commands are placed on the history list instead of being executed, much like .Sq history \-L .TP 8 .B stop \fB% .Va job | .Va pid ... Stops the specified jobs or processes which are executing in the background. .Va job may be a number, a string, .Sq , .Sq % , .Sq + or .Sq \- as described under .Va Jobs There is no default .Va job ; saying just .Sq stop does not stop the current job. .TP 8 .B suspend Causes the shell to stop in its tracks, much as if it had been sent a stop signal with .Va ^Z This is most often used to stop shells started by .Va su (1). .Pp .B switch (\fIstring\fB) .br .B case \fIstr1\fB: .PD 0 .IP "" 4 \&... .br .B breaksw .Pp \&... .Pp .B default: .IP "" 4 \&... .br .B breaksw .TP 8 .B endsw Each case label is successively matched, against the specified .Va string which is first command and filename expanded. The file metacharacters .Sq * , .Sq \&? and .Sq [...] may be used in the case labels, which are variable expanded. If none of the labels match before a .Sq default label is found, then the execution begins after the default label. Each case label and the default label must appear at the beginning of a line. The command .Va breaksw causes execution to continue after the .Va endsw Otherwise control may fall through case labels and default labels as in C. If no label matches and there is no default, execution continues after the .Va endsw .PD .TP 8 .B telltc \fR(+) Lists the values of all terminal capabilities (see .Va termcap (5)). .TP 8 .B termname \fR[ .Va terminal type ] \fR(+) Tests if .Va terminal type (or the current value of .Va TERM if no .Va terminal type is given) has an entry in the hosts termcap(5) or terminfo(5) database. Prints the terminal type to stdout and returns 0 if an entry is present otherwise returns 1. .TP 8 .B time \fR[ .Va command ] Executes .Va command (which must be a simple command, not an alias, a pipeline, a command list or a parenthesized command list) and prints a time summary as described under the .Va time variable. If necessary, an extra shell is created to print the time statistic when the command completes. Without .Va command , prints a time summary for the current shell and its children. .TP 8 .B umask \fR[ .Va value ] Sets the file creation mask to .Va value , which is given in octal. Common values for the mask are 002, giving all access to the group and read and execute access to others, and 022, giving read and execute access to the group and others. Without .Va value , prints the current file creation mask. .TP 8 .B unalias .Va pattern .br Removes all aliases whose names match .Va pattern `unalias *' thus removes all aliases. It is not an error for nothing to be .Va unalias ed. .TP 8 .B uncomplete .Va pattern (+) Removes all completions whose names match .Va pattern `uncomplete *' thus removes all completions. It is not an error for nothing to be .Va uncomplete d. .TP 8 .B unhash Disables use of the internal hash table to speed location of executed programs. .TP 8 .B universe .Va universe (+) Sets the universe to .Va universe (Masscomp/RTU only) .TP 8 .B unlimit \fR[ .Fl hf\fR] [ .Va resource ] Removes the limitation on .Va resource or, if no .Va resource is specified, all .Va resource limitations. With .Fl h\fR, the corresponding hard limits are removed. Only the super-user may do this. Note that .Va unlimit may not exit successful, since most systems do not allow .Va descriptors to be unlimited. With .Fl f\fR errors are ignored. .TP 8 .B unset \fIpattern Removes all variables whose names match .Va pattern , unless they are read-only. `unset *' thus removes all variables unless they are read-only; this is a bad idea. It is not an error for nothing to be .Va unset .TP 8 .B unsetenv \fIpattern Removes all environment variables whose names match .Va pattern `unsetenv *' thus removes all environment variables; this is a bad idea. It is not an error for nothing to be .Va unsetenv ed. .TP 8 .B ver \fR[ .Va systype [ .Va command ]] (+) Without arguments, prints .Va SYSTYPE With .Va systype , sets .Va SYSTYPE to .Va systype With .Va systype and .Va command , executes .Va command under .Va systype .Va systype may be .Sq bsd4.3 or .Sq sys5.3 (Domain/OS only) .TP 8 .B wait The shell waits for all background jobs. If the shell is interactive, an interrupt will disrupt the wait and cause the shell to print the names and job numbers of all outstanding jobs. .TP 8 .B warp .Va universe (+) Sets the universe to .Va universe (Convex/OS only) .TP 8 .B watchlog \fR(+) An alternate name for the .Va log builtin command (q.v.). Available only if the shell was so compiled; see the .Va version shell variable. .TP 8 .B where .Va command (+) Reports all known instances of .Va command , including aliases, builtins and executables in .Va path .TP 8 .B which\fR .Va command (+) Displays the command that will be executed by the shell after substitutions, .Va path searching, etc. The builtin command is just like .Va which (1), but it correctly reports .Nm aliases and builtins and is 10 to 100 times faster. See also the .Va which-command editor command. .Pp .B while (\fIexpr .Va ) .br \&... .PD 0 .TP 8 .B end Executes the commands between the .Va while and the matching .Va end while .Va expr (an expression, as described under .Va Expressions ) evaluates non-zero. .Va while and .Va end must appear alone on their input lines. .Va break and .Va continue may be used to terminate or continue the loop prematurely. If the input is a terminal, the user is prompted the first time through the loop as with .Va foreach .PD .Ss "Special aliases (+)" If set, each of these aliases executes automatically at the indicated time. They are all initially undefined. .TP 8 .B beepcmd Runs when the shell wants to ring the terminal bell. .TP 8 .B cwdcmd Runs after every change of working directory. For example, if the user is working on an X window system using .Va xterm (1) and a re-parenting window manager that supports title bars such as .Va twm (1) and does .RS +8 .IP "" 4 > alias cwdcmd 'echo \-n "^[]2;${HOST}:$cwd ^G"' .Pp then the shell will change the title of the running .Va xterm (1) to be the name of the host, a colon, and the full current working directory. A fancier way to do that is .IP "" 4 > alias cwdcmd 'echo \-n "^[]2;${HOST}:$cwd^G^[]1;${HOST}^G"' .Pp This will put the hostname and working directory on the title bar but only the hostname in the icon manager menu. .Pp Note that putting a .Va cd , .Va pushd or .Va popd in .Va cwdcmd may cause an infinite loop. It is the author's opinion that anyone doing so will get what they deserve. .RE .TP 8 .B jobcmd Runs before each command gets executed, or when the command changes state. This is similar to .Va postcmd , but it does not print builtins. .RS +8 .IP "" 4 > alias jobcmd 'echo \-n "^[]2\e;\e!#:q^G"' .Pp then executing .Va vi foo.c will put the command string in the xterm title bar. .RE .TP 8 .B helpcommand Invoked by the .Va run-help editor command. The command name for which help is sought is passed as sole argument. For example, if one does .RS +8 .IP "" 4 > alias helpcommand '\e!:1 --help' .Pp then the help display of the command itself will be invoked, using the GNU help calling convention. Currently there is no easy way to account for various calling conventions (e.g., the customary Unix .Sq -h ), except by using a table of many commands. .RE .TP 8 .B periodic Runs every .Va tperiod minutes. This provides a convenient means for checking on common but infrequent changes such as new mail. For example, if one does .RS +8 .IP "" 4 > set tperiod = 30 .br > alias periodic checknews .Pp then the .Va checknews (1) program runs every 30 minutes. If .Va periodic is set but .Va tperiod is unset or set to 0, .Va periodic behaves like .Va precmd .RE .TP 8 .B precmd Runs just before each prompt is printed. For example, if one does .RS +8 .IP "" 4 > alias precmd date .Pp then .Va date (1) runs just before the shell prompts for each command. There are no limits on what .Va precmd can be set to do, but discretion should be used. .RE .TP 8 .B postcmd Runs before each command gets executed. .RS +8 .IP "" 4 > alias postcmd 'echo \-n "^[]2\e;\e!#:q^G"' .Pp then executing .Va vi foo.c will put the command string in the xterm title bar. .RE .TP 8 .B shell Specifies the interpreter for executable scripts which do not themselves specify an interpreter. The first word should be a full path name to the desired interpreter (e.g., .Sq /bin/csh or .Sq /usr/local/bin/tcsh ). .Ss "Special shell variables" The variables described in this section have special meaning to the shell. .Pp The shell sets .Va addsuffix , .Va argv , .Va autologout , .Va csubstnonl , .Va command , .Va echo_style , .Va edit , .Va gid , .Va group , .Va home , .Va loginsh , .Va oid , .Va path , .Va prompt , .Va prompt2 , .Va prompt3 , .Va shell , .Va shlvl , .Va tcsh , .Va term , .Va tty , .Va uid , .Va user and .Va version at startup; they do not change thereafter unless changed by the user. The shell updates .Va cwd , .Va dirstack , .Va owd and .Va status when necessary, and sets .Va logout on logout. .Pp The shell synchronizes .Va group , .Va home , .Va path , .Va shlvl , .Va term and .Va user with the environment variables of the same names: whenever the environment variable changes the shell changes the corresponding shell variable to match (unless the shell variable is read-only) and vice versa. Note that although .Va cwd and .Va PWD have identical meanings, they are not synchronized in this manner, and that the shell automatically converts between the different formats of .Va path and .Va PATH .TP 8 .B addsuffix \fR(+) If set, filename completion adds .Sq / to the end of directories and a space to the end of normal files when they are matched exactly. Set by default. .TP 8 .B afsuser \fR(+) If set, .Va autologout 's autolock feature uses its value instead of the local username for kerberos authentication. .TP 8 .B ampm \fR(+) If set, all times are shown in 12-hour AM/PM format. .TP 8 .B anyerror \fR(+) This variable selects what is propagated to the value of the .Va status variable. For more information see the description of the .Va status variable below. .TP 8 .B argv The arguments to the shell. Positional parameters are taken from .Va argv , i.e., .Sq $1 is replaced by .Sq $argv[1] , etc. Set by default, but usually empty in interactive shells. .TP 8 .B autocorrect \fR(+) If set, the .Va spell-word editor command is invoked automatically before each completion attempt. .TP 8 .B autoexpand \fR(+) If set, the .Va expand-history editor command is invoked automatically before each completion attempt. If this is set to .Va onlyhistory , then only history will be expanded and a second completion will expand filenames. .TP 8 .B autolist \fR(+) If set, possibilities are listed after an ambiguous completion. If set to .Sq ambiguous , possibilities are listed only when no new characters are added by completion. .TP 8 .B autologout \fR(+) The first word is the number of minutes of inactivity before automatic logout. The optional second word is the number of minutes of inactivity before automatic locking. When the shell automatically logs out, it prints .Sq auto-logout , sets the variable .Va logout to .Sq automatic and exits. When the shell automatically locks, the user is required to enter his password to continue working. Five incorrect attempts result in automatic logout. Set to .Sq 60 (automatic logout after 60 minutes, and no locking) by default in login and superuser shells, but not if the shell thinks it is running under a window system (i.e., the .Va DISPLAY environment variable is set), the tty is a pseudo-tty (pty) or the shell was not so compiled (see the .Va version shell variable). +Unset +.Va autologout or set it to +.Dv 0 +to disable automatic logout. See also the .Va afsuser and .Va logout shell variables. .TP 8 .B autorehash \fR(+) If set, the internal hash table of the contents of the directories in the .Va path variable will be recomputed if a command is not found in the hash table. In addition, the list of available commands will be rebuilt for each command completion or spelling correction attempt if set to .Sq complete or `correct' respectively; if set to .Sq always , this will be done for both cases. .TP 8 .B backslash_quote \fR(+) .\" TODO If set, backslashes (`\e') always quote .Sq \e , .Sq \&' , and .Sq \&" This may make complex quoting tasks easier, but it can cause syntax errors in .Xr csh 1 scripts. .TP 8 .B catalog The file name of the message catalog. If set, tcsh use .Sq tcsh.${catalog} as a message catalog instead of default .Sq tcsh .TP 8 .B cdpath A list of directories in which .Va cd should search for subdirectories if they aren't found in the current directory. .TP 8 .B cdtohome \fR(+) If not set, .Va cd requires a directory .Va name , and will not go to the .Va home directory if it's omitted. This is set by default. .TP 8 .B color If set, it enables color display for the builtin \fBls\-F\fR and it passes .Fl \-color=auto\fR to .Va ls Alternatively, it can be set to only \fBls\-F\fR or only .Va ls to enable color to only one command. Setting it to nothing is equivalent to setting it to \fB(ls\-F ls)\fR. .TP 8 .B colorcat If set, it enables color escape sequence for NLS message files. And display colorful NLS messages. .TP 8 .B command \fR(+) If set, the command which was passed to the shell with the .Va -c flag (q.v.). .TP 8 .B compat_expr \fR(+) If set, the shell will evaluate expressions right to left, like the original .Xr csh 1 .TP 8 .B complete \fR(+) If set to .Sq igncase , the completion becomes case insensitive. If set to .Sq enhance , completion ignores case and considers hyphens and underscores to be equivalent; it will also treat periods, hyphens and underscores (`.', .Sq \- and .Sq _ ) as word separators. If set to .Sq Enhance , completion matches uppercase and underscore characters explicitly and matches lowercase and hyphens in a case-insensitive manner; it will treat periods, hyphens and underscores as word separators. .TP 8 .B continue \fR(+) If set to a list of commands, the shell will continue the listed commands, instead of starting a new one. .TP 8 .B continue_args \fR(+) Same as continue, but the shell will execute: .RS +8 .IP "" 4 echo \`pwd\` $argv > ~/._pause; % .RE .TP 8 .B correct \fR(+) If set to .Sq cmd , commands are automatically spelling-corrected. If set to .Sq complete , commands are automatically completed. If set to .Sq all , the entire command line is corrected. .TP 8 .B csubstnonl \fR(+) If set, newlines and carriage returns in command substitution are replaced by spaces. Set by default. .TP 8 .B cwd The full pathname of the current directory. See also the .Va dirstack and .Va owd shell variables. .TP 8 .B dextract \fR(+) If set, .Sq pushd + .Va n extracts the .Va n th directory from the directory stack rather than rotating it to the top. .TP 8 .B dirsfile \fR(+) The default location in which .Sq dirs \-S and .Sq dirs \-L look for a history file. If unset, .Va ~/.cshdirs is used. Because only .Va ~/.tcshrc is normally sourced before .Va ~/.cshdirs , .Va dirsfile should be set in .Va ~/.tcshrc rather than .Va ~/.login .TP 8 .B dirstack \fR(+) An array of all the directories on the directory stack. `$dirstack[1]' is the current working directory, .Sq $dirstack[2] the first directory on the stack, etc. Note that the current working directory is .Sq $dirstack[1] but .Sq =0 in directory stack substitutions, etc. One can change the stack arbitrarily by setting .Va dirstack , but the first element (the current working directory) is always correct. See also the .Va cwd and .Va owd shell variables. .TP 8 .B dspmbyte \fR(+) Has an effect iff 'dspm' is listed as part of the .Va version shell variable. If set to .Sq euc , it enables display and editing EUC-kanji(Japanese) code. If set to .Sq sjis , it enables display and editing Shift-JIS(Japanese) code. If set to .Sq big5 , it enables display and editing Big5(Chinese) code. If set to .Sq utf8 , it enables display and editing Utf8(Unicode) code. If set to the following format, it enables display and editing of original multi-byte code format: .RS +8 .IP "" 4 > set dspmbyte = 0000....(256 bytes)....0000 .Pp The table requires .Va just 256 bytes. Each character of 256 characters corresponds (from left to right) to the ASCII codes 0x00, 0x01, ... 0xff. Each character .\" (position in this table?) is set to number 0,1,2 and 3. Each number has the following meaning: .br 0 ... not used for multi-byte characters. .br 1 ... used for the first byte of a multi-byte character. .br 2 ... used for the second byte of a multi-byte character. .br 3 ... used for both the first byte and second byte of a multi-byte character. .\" SHK: I tried my best to get the following to be grammatically correct. .\" However, I still don't understand what's going on here. In the .\" following example, there are three bytes, but the text seems to refer to .\" each nybble as a character. What's going on here? It this 3-byte code .\" in the table? The text above seems to imply that there are 256 .\" characters/bytes in the table. If I get some more info on this (perhaps .\" a complete example), I could fix the text to be grammatically correct. .\" (steve.kelem@xilinx.com 1999/09/13) .Pp Example: .br If set to .Sq 001322 , the first character (means 0x00 of the ASCII code) and second character (means 0x01 of ASCII code) are set to .Sq 0 Then, it is not used for multi-byte characters. The 3rd character (0x02) is set to '1', indicating that it is used for the first byte of a multi-byte character. The 4th character(0x03) is set '3'. It is used for both the first byte and the second byte of a multi-byte character. The 5th and 6th characters (0x04,0x05) are set to '2', indicating that they are used for the second byte of a multi-byte character. .Pp The GNU fileutils version of ls cannot display multi-byte filenames without the -N ( --literal ) option. If you are using this version, set the second word of dspmbyte to "ls". If not, for example, "ls-F -l" cannot display multi-byte filenames. .Pp Note: .br This variable can only be used if KANJI and DSPMBYTE has been defined at compile time. .RE .TP 8 .B dunique \fR(+) If set, .Va pushd removes any instances of .Va name from the stack before pushing it onto the stack. .TP 8 .B echo If set, each command with its arguments is echoed just before it is executed. For non-builtin commands all expansions occur before echoing. Builtin commands are echoed before command and filename substitution, because these substitutions are then done selectively. Set by the .Fl x\fR command line option. .TP 8 .B echo_style \fR(+) The style of the .Va echo builtin. May be set to .Pp .RS +8 .PD 0 .TP 8 bsd Don't echo a newline if the first argument is .Sq \-n ; the default for .Xr csh 1 .TP 8 sysv Recognize backslashed escape sequences in echo strings. .TP 8 both Recognize both the .Sq \-n flag and backslashed escape sequences; the default for .Nm .TP 8 none Recognize neither. .PD .Pp Set by default to the local system default. The BSD and System V options are described in the .Va echo (1) man pages on the appropriate systems. .RE .TP 8 .B edit \fR(+) If set, the command-line editor is used. Set by default in interactive shells. .TP 8 .B editors \fR(+) A list of command names for the .Va run-fg-editor editor command to match. If not set, the .Va EDITOR (`ed' if unset) and .Va VISUAL (`vi' if unset) environment variables will be used instead. .TP 8 .B ellipsis \fR(+) If set, the .Sq %c /`%.' and .Sq %C prompt sequences (see the .Va prompt shell variable) indicate skipped directories with an ellipsis (`...') instead of .Sq / .TP 8 .B euid \fR(+) The user's effective user ID. .TP 8 .B euser \fR(+) The first matching passwd entry name corresponding to the effective user ID. .TP 8 .B fignore \fR(+) Lists file name suffixes to be ignored by completion. .TP 8 .B filec In .Nm , completion is always used and this variable is ignored by default. If .B edit is unset, then the traditional .Xr csh 1 completion is used. If set in .Xr csh 1 , filename completion is used. .TP 8 .B gid \fR(+) The user's real group ID. .TP 8 .B globdot \fR(+) If set, wild-card glob patterns will match files and directories beginning with .Sq . except for .Sq . and .Sq .. .TP 8 .B globstar \fR(+) If set, the .Sq ** and .Sq *** file glob patterns will match any string of characters including .Sq / traversing any existing sub-directories. (e.g. `ls **.c' will list all the .c files in the current directory tree). If used by itself, it will match zero or more sub-directories (e.g. .Sq ls /usr/include/**/time.h will list any file named .Sq time.h in the /usr/include directory tree; whereas .Sq ls /usr/include/**time.h will match any file in the /usr/include directory tree ending in .Sq time.h ). To prevent problems with recursion, the .Sq ** glob-pattern will not descend into a symbolic link containing a directory. To override this, use .Sq *** .TP 8 .B group \fR(+) The user's group name. .TP 8 .B highlight If set, the incremental search match (in .Va i-search-back and .Va i-search-fwd ) and the region between the mark and the cursor are highlighted in reverse video. .IP "" 8 Highlighting requires more frequent terminal writes, which introduces extra overhead. If you care about terminal performance, you may want to leave this unset. .TP 8 .B histchars A string value determining the characters used in \fBHistory substitution\fR (q.v.). The first character of its value is used as the history substitution character, replacing the default character `!'. The second character of its value replaces the character .Sq ^ in quick substitutions. .TP 8 .B histdup \fR(+) Controls handling of duplicate entries in the history list. If set to `all' only unique history events are entered in the history list. If set to .Sq prev and the last history event is the same as the current command, then the current command is not entered in the history. If set to .Sq erase and the same event is found in the history list, that old event gets erased and the current one gets inserted. Note that the `prev' and .Sq all options renumber history events so there are no gaps. .TP 8 .B histfile \fR(+) The default location in which .Sq history \-S and .Sq history \-L look for a history file. If unset, .Va ~/.history is used. .Va histfile is useful when sharing the same home directory between different machines, or when saving separate histories on different terminals. Because only .Va ~/.tcshrc is normally sourced before .Va ~/.history , .Va histfile should be set in .Va ~/.tcshrc rather than .Va ~/.login .TP 8 .B histlit \fR(+) If set, builtin and editor commands and the .Va savehist mechanism use the literal (unexpanded) form of lines in the history list. See also the .Va toggle-literal-history editor command. .TP 8 .B history The first word indicates the number of history events to save. The optional second word (+) indicates the format in which history is printed; if not given, .Sq %h\et%T\et%R\en is used. The format sequences are described below under .Va prompt ; note the variable meaning of `%R'. Set to .Sq 100 by default. .TP 8 .B home Initialized to the home directory of the invoker. The filename expansion of .Sq .Va ~ refers to this variable. .TP 8 .B ignoreeof If set to the empty string or .Sq 0 and the input device is a terminal, the .Va end-of-file command (usually generated by the user by typing `^D' on an empty line) causes the shell to print `Use "exit" to leave tcsh.' instead of exiting. This prevents the shell from accidentally being killed. Historically this setting exited after 26 successive EOF's to avoid infinite loops. If set to a number .Va n , the shell ignores .Va n - 1 consecutive .Va end-of-file s and exits on the .Va n th. (+) If unset, .Sq 1 is used, i.e., the shell exits on a single .Sq ^D .TP 8 .B implicitcd \fR(+) If set, the shell treats a directory name typed as a command as though it were a request to change to that directory. If set to .Va verbose , the change of directory is echoed to the standard output. This behavior is inhibited in non-interactive shell scripts, or for command strings with more than one word. Changing directory takes precedence over executing a like-named command, but it is done after alias substitutions. Tilde and variable expansions work as expected. .TP 8 .B inputmode \fR(+) If set to .Sq insert or .Sq overwrite , puts the editor into that input mode at the beginning of each line. .TP 8 .B killdup \fR(+) Controls handling of duplicate entries in the kill ring. If set to `all' only unique strings are entered in the kill ring. If set to `prev' and the last killed string is the same as the current killed string, then the current string is not entered in the ring. If set to .Sq erase and the same string is found in the kill ring, the old string is erased and the current one is inserted. .TP 8 .B killring \fR(+) Indicates the number of killed strings to keep in memory. Set to .Sq 30 by default. If unset or set to less than .Sq 2 , the shell will only keep the most recently killed string. Strings are put in the killring by the editor commands that delete (kill) strings of text, e.g. .Va backward-delete-word , .Va kill-line , etc, as well as the .Va copy-region-as-kill command. The .Va yank editor command will yank the most recently killed string into the command-line, while .Va yank-pop (see .Va Editor commands ) can be used to yank earlier killed strings. .TP 8 .B listflags \fR(+) If set to .Sq x , .Sq a or .Sq A , or any combination thereof (e.g., .Sq xA ), they are used as flags to \fIls\-F\fR, making it act like .Sq ls \-xF , `ls \-Fa', .Sq ls \-FA or a combination (e.g., .Sq ls \-FxA ): .Sq a shows all files (even if they start with a .Sq . ), .Sq A shows all files but .Sq . and `..', and .Sq x sorts across instead of down. If the second word of .Va listflags is set, it is used as the path to .Sq ls(1) .TP 8 .B listjobs \fR(+) If set, all jobs are listed when a job is suspended. If set to .Sq long , the listing is in long format. .TP 8 .B listlinks \fR(+) If set, the \fIls\-F\fR builtin command shows the type of file to which each symbolic link points. .TP 8 .B listmax \fR(+) The maximum number of items which the .Va list-choices editor command will list without asking first. .TP 8 .B listmaxrows \fR(+) The maximum number of rows of items which the .Va list-choices editor command will list without asking first. .TP 8 .B loginsh \fR(+) Set by the shell if it is a login shell. Setting or unsetting it within a shell has no effect. See also .Va shlvl .TP 8 .B logout \fR(+) Set by the shell to .Sq normal before a normal logout, .Sq automatic before an automatic logout, and .Sq hangup if the shell was killed by a hangup signal (see .Va Signal handling ). See also the .Va autologout shell variable. .TP 8 .B mail A list of files and directories to check for incoming mail, optionally preceded by a numeric word. Before each prompt, if 10 minutes have passed since the last check, the shell checks each file and says `You have new mail.' (or, if .Va mail contains multiple files, `You have new mail in .Va name .') if the filesize is greater than zero in size and has a modification time greater than its access time. .Pp .RS +8 .PD .Pp If you are in a login shell, then no mail file is reported unless it has been modified after the time the shell has started up, to prevent redundant notifications. Most login programs will tell you whether or not you have mail when you log in. .Pp If a file specified in .Va mail is a directory, the shell will count each file within that directory as a separate message, and will report `You have .Va n mails.' or .Sq You have .Va n mails in .Va name as appropriate. This functionality is provided primarily for those systems which store mail in this manner, such as the Andrew Mail System. .Pp If the first word of .Va mail is numeric it is taken as a different mail checking interval, in seconds. .Pp Under very rare circumstances, the shell may report .Sq You have mail. instead of .Sq You have new mail. .RE .TP 8 .B matchbeep \fR(+) If set to .Sq never , completion never beeps. If set to .Sq nomatch , it beeps only when there is no match. If set to .Sq ambiguous , it beeps when there are multiple matches. If set to .Sq notunique , it beeps when there is one exact and other longer matches. If unset, .Sq ambiguous is used. .TP 8 .B nobeep \fR(+) If set, beeping is completely disabled. See also .Va visiblebell .TP 8 .B noclobber If set, restrictions are placed on output redirection to insure that files are not accidentally destroyed and that .Sq >> redirections refer to existing files, as described in the .Va Input/output section. .TP 8 .B noding If set, disable the printing of .Sq DING! in the .Va prompt time specifiers at the change of hour. .TP 8 .B noglob If set, .Va Filename substitution and .Va Directory stack substitution (q.v.) are inhibited. This is most useful in shell scripts which do not deal with filenames, or after a list of filenames has been obtained and further expansions are not desirable. .TP 8 .B nokanji \fR(+) If set and the shell supports Kanji (see the .Va version shell variable), it is disabled so that the meta key can be used. .TP 8 .B nonomatch If set, a .Va Filename substitution or .Va Directory stack substitution (q.v.) which does not match any existing files is left untouched rather than causing an error. It is still an error for the substitution to be malformed, e.g., .Sq echo [ still gives an error. .TP 8 .B nostat \fR(+) A list of directories (or glob-patterns which match directories; see .Va Filename substitution ) that should not be .Va stat (2)ed during a completion operation. This is usually used to exclude directories which take too much time to .Va stat (2), for example .Va /afs .TP 8 .B notify If set, the shell announces job completions asynchronously. The default is to present job completions just before printing a prompt. .TP 8 .B oid \fR(+) The user's real organization ID. (Domain/OS only) .TP 8 .B owd \fR(+) The old working directory, equivalent to the .Sq \- used by .Va cd and .Va pushd See also the .Va cwd and .Va dirstack shell variables. .TP 8 .B padhour If set, enable the printing of padding '0' for hours, in 24 and 12 hour formats. E.G.: 07:45:42 vs. 7:45:42. .TP 8 .B parseoctal To retain compatibily with older versions numeric variables starting with 0 are not interpreted as octal. Setting this variable enables proper octal parsing. .TP 8 .B path A list of directories in which to look for executable commands. A null word specifies the current directory. If there is no .Va path variable then only full path names will execute. .Va path is set by the shell at startup from the .Va PATH environment variable or, if .Va PATH does not exist, to a system-dependent default something like .Sq (/usr/local/bin /usr/bsd /bin /usr/bin .) The shell may put .Sq . first or last in .Va path or omit it entirely depending on how it was compiled; see the .Va version shell variable. A shell which is given neither the .Fl c\fR nor the .Fl t\fR option hashes the contents of the directories in .Va path after reading .Va ~/.tcshrc and each time .Va path is reset. If one adds a new command to a directory in .Va path while the shell is active, one may need to do a .Va rehash for the shell to find it. .TP 8 .B printexitvalue \fR(+) If set and an interactive program exits with a non-zero status, the shell prints .Sq Exit .Va status .TP 8 .B prompt The string which is printed before reading each command from the terminal. .Va prompt may include any of the following formatting sequences (+), which are replaced by the given information: .Pp .RS +8 .PD 0 .TP 4 %/ The current working directory. .TP 4 %~ The current working directory, but with one's home directory represented by .Sq ~ and other users' home directories represented by `~user' as per .Va Filename substitution `~user' substitution happens only if the shell has already used .Sq ~ .Va user in a pathname in the current session. .TP 4 %c[[0] .Va n ], %.[[0] .Va n ] The trailing component of the current working directory, or .Va n trailing components if a digit .Va n is given. If .Va n begins with .Sq 0 , the number of skipped components precede the trailing component(s) in the format .Sq /< .Va skipped >trailing If the .Va ellipsis shell variable is set, skipped components are represented by an ellipsis so the whole becomes .Sq ...trailing `~' substitution is done as in .Sq %~ above, but the .Sq ~ component is ignored when counting trailing components. .TP 4 %C Like %c, but without .Sq ~ substitution. .TP 4 %h, %!, ! The current history event number. .TP 4 %M The full hostname. .TP 4 %m The hostname up to the first .Sq . .TP 4 %S (%s) Start (stop) standout mode. .TP 4 %B (%b) Start (stop) boldfacing mode. .TP 4 %U (%u) Start (stop) underline mode. .TP 4 %t, %@ The time of day in 12-hour AM/PM format. .TP 4 %T Like .Sq %t , but in 24-hour format (but see the .Va ampm shell variable). .TP 4 %p The .Sq precise time of day in 12-hour AM/PM format, with seconds. .TP 4 %P Like .Sq %p , but in 24-hour format (but see the .Va ampm shell variable). .TP 4 \e .Va c .Va c is parsed as in .Va bindkey .TP 4 ^ .Va c .Va c is parsed as in .Va bindkey .TP 4 %% A single .Sq % .TP 4 %n The user name. .TP 4 %N The effective user name. .TP 4 %j The number of jobs. .TP 4 %d The weekday in .Sq Day format. .TP 4 %D The day in .Sq dd format. .TP 4 %w The month in .Sq Mon format. .TP 4 %W The month in .Sq mm format. .TP 4 %y The year in .Sq yy format. .TP 4 %Y The year in .Sq yyyy format. .TP 4 %l The shell's tty. .TP 4 %L Clears from the end of the prompt to end of the display or the end of the line. .TP 4 %$ Expands the shell or environment variable name immediately after the .Sq $ .TP 4 %# `>' (or the first character of the .Va promptchars shell variable) for normal users, .Sq # (or the second character of .Va promptchars ) for the superuser. .TP 4 %{ .Va string %} Includes .Va string as a literal escape sequence. It should be used only to change terminal attributes and should not move the cursor location. This cannot be the last sequence in .Va prompt .TP 4 %? The return code of the command executed just before the prompt. .TP 4 %R In .Va prompt2 , the status of the parser. In .Va prompt3 , the corrected string. In .Va history , the history string. .PD .Pp `%B', .Sq %S , .Sq %U and .Sq %{ .Va string %} are available in only eight-bit-clean shells; see the .Va version shell variable. .Pp The bold, standout and underline sequences are often used to distinguish a superuser shell. For example, .IP "" 4 > set prompt = "%m [%h] %B[%@]%b [%/] you rang? " .br tut [37] .Va [2:54pm] [/usr/accts/sys] you rang? _ .Pp If .Sq %t , .Sq %@ , .Sq %T , .Sq %p , or .Sq %P is used, and .Va noding is not set, then print .Sq DING! on the change of hour (i.e, .Sq \&:00 minutes) instead of the actual time. .Pp Set by default to .Sq %# in interactive shells. .RE .TP 8 .B prompt2 \fR(+) The string with which to prompt in .Va while and .Va foreach loops and after lines ending in .Sq \e The same format sequences may be used as in .Va prompt (q.v.); note the variable meaning of .Sq %R Set by default to .Sq %R? in interactive shells. .TP 8 .B prompt3 \fR(+) The string with which to prompt when confirming automatic spelling correction. The same format sequences may be used as in .Va prompt (q.v.); note the variable meaning of .Sq %R Set by default to .Sq CORRECT>%R (y|n|e|a)? in interactive shells. .TP 8 .B promptchars \fR(+) If set (to a two-character string), the .Sq %# formatting sequence in the .Va prompt shell variable is replaced with the first character for normal users and the second character for the superuser. .TP 8 .B pushdtohome \fR(+) If set, .Va pushd without arguments does .Sq pushd ~ , like .Va cd .TP 8 .B pushdsilent \fR(+) If set, .Va pushd and .Va popd do not print the directory stack. .TP 8 .B recexact \fR(+) If set, completion completes on an exact match even if a longer match is possible. .TP 8 .B recognize_only_executables \fR(+) If set, command listing displays only files in the path that are executable. Slow. .TP 8 .B rmstar \fR(+) If set, the user is prompted before .Sq rm * is executed. .TP 8 .B rprompt \fR(+) The string to print on the right-hand side of the screen (after the command input) when the prompt is being displayed on the left. It recognizes the same formatting characters as .Va prompt It will automatically disappear and reappear as necessary, to ensure that command input isn't obscured, and will appear only if the prompt, command input, and itself will fit together on the first line. If .Va edit isn't set, then .Va rprompt will be printed after the prompt and before the command input. .TP 8 .B savedirs \fR(+) If set, the shell does .Sq dirs \-S before exiting. If the first word is set to a number, at most that many directory stack entries are saved. .TP 8 .B savehist If set, the shell does .Sq history \-S before exiting. If the first word is set to a number, at most that many lines are saved. (The number should be less than or equal to the number .Va history entries; if it is set to greater than the number of .Va history settings, only .Va history entries will be saved) If the second word is set to .Sq merge , the history list is merged with the existing history file instead of replacing it (if there is one) and sorted by time stamp and the most recent events are retained. If the second word of .Va savehist is .Sq merge and the third word is set to `lock', the history file update will be serialized with other shell sessions that would possibly like to merge history at exactly the same time. (+) .TP 8 .B sched \fR(+) The format in which the .Va sched builtin command prints scheduled events; if not given, .Sq %h\et%T\et%R\en is used. The format sequences are described above under .Va prompt ; note the variable meaning of .Sq %R .TP 8 .B shell The file in which the shell resides. This is used in forking shells to interpret files which have execute bits set, but which are not executable by the system. (See the description of .Va Builtin and non-builtin command execution .) Initialized to the (system-dependent) home of the shell. .TP 8 .B shlvl \fR(+) The number of nested shells. Reset to 1 in login shells. See also .Va loginsh .TP 8 .B status The exit status from the last command or backquote expansion, or any command in a pipeline is propagated to .Va status (This is also the default .Xr csh 1 behavior.) This default does not match what POSIX mandates (to return the status of the last command only). To match the POSIX behavior, you need to unset .Va anyerror .RS +8 .Pp If the .Va anyerror variable is unset, the exit status of a pipeline is determined only from the last command in the pipeline, and the exit status of a backquote expansion is .Va not propagated to .Va status .Pp If a command terminated abnormally, then 0200 is added to the status. Builtin commands which fail return exit status .Sq 1 , all other builtin commands return status .Sq 0 .RE .TP 8 .B symlinks \fR(+) Can be set to several different values to control symbolic link (`symlink') resolution: .RS +8 .Pp If set to .Sq chase , whenever the current directory changes to a directory containing a symbolic link, it is expanded to the real name of the directory to which the link points. This does not work for the user's home directory; this is a bug. .Pp If set to .Sq ignore , the shell tries to construct a current directory relative to the current directory before the link was crossed. This means that .Va cd ing through a symbolic link and then .Sq cd .. ing returns one to the original directory. This affects only builtin commands and filename completion. .Pp If set to .Sq expand , the shell tries to fix symbolic links by actually expanding arguments which look like path names. This affects any command, not just builtins. Unfortunately, this does not work for hard-to-recognize filenames, such as those embedded in command options. Expansion may be prevented by quoting. While this setting is usually the most convenient, it is sometimes misleading and sometimes confusing when it fails to recognize an argument which should be expanded. A compromise is to use .Sq ignore and use the editor command .Va normalize-path (bound by default to ^X-n) when necessary. .Pp Some examples are in order. First, let's set up some play directories: .IP "" 4 > cd /tmp .br > mkdir from from/src to .br > ln \-s from/src to/dst .Pp Here's the behavior with .Va symlinks unset, .IP "" 4 > cd /tmp/to/dst; echo $cwd .br /tmp/to/dst .br > cd ..; echo $cwd .br /tmp/from .Pp here's the behavior with .Va symlinks set to .Sq chase , .IP "" 4 > cd /tmp/to/dst; echo $cwd .br /tmp/from/src .br > cd ..; echo $cwd .br /tmp/from .Pp here's the behavior with .Va symlinks set to .Sq ignore , .IP "" 4 > cd /tmp/to/dst; echo $cwd .br /tmp/to/dst .br > cd ..; echo $cwd .br /tmp/to .Pp and here's the behavior with .Va symlinks set to .Sq expand .IP "" 4 > cd /tmp/to/dst; echo $cwd .br /tmp/to/dst .br > cd ..; echo $cwd .br /tmp/to .br > cd /tmp/to/dst; echo $cwd .br /tmp/to/dst .br > cd ".."; echo $cwd .br /tmp/from .br > /bin/echo .. .br /tmp/to .br > /bin/echo ".." .br \&.. .Pp Note that .Sq expand expansion 1) works just like .Sq ignore for builtins like .Va cd , 2) is prevented by quoting, and 3) happens before filenames are passed to non-builtin commands. .RE .TP 8 .B tcsh \fR(+) The version number of the shell in the format .Sq R.VV.Pp , where .Sq R is the major release number, .Sq VV the current version and .Sq PP the patchlevel. .TP 8 .B term The terminal type. Usually set in .Va ~/.login as described under .Va Startup and shutdown .TP 8 .B time If set to a number, then the .Va time builtin (q.v.) executes automatically after each command which takes more than that many CPU seconds. If there is a second word, it is used as a format string for the output of the .Va time builtin. (u) The following sequences may be used in the format string: .Pp .RS +8 .PD 0 .TP 4 %U The time the process spent in user mode in cpu seconds. .TP 4 %S The time the process spent in kernel mode in cpu seconds. .TP 4 %E The elapsed (wall clock) time in seconds. .TP 4 %P The CPU percentage computed as (%U + %S) / %E. .TP 4 %W Number of times the process was swapped. .TP 4 %X The average amount in (shared) text space used in Kbytes. .TP 4 %D The average amount in (unshared) data/stack space used in Kbytes. .TP 4 %K The total space used (%X + %D) in Kbytes. .TP 4 %M The maximum memory the process had in use at any time in Kbytes. .TP 4 %F The number of major page faults (page needed to be brought from disk). .TP 4 %R The number of minor page faults. .TP 4 %I The number of input operations. .TP 4 %O The number of output operations. .TP 4 %r The number of socket messages received. .TP 4 %s The number of socket messages sent. .TP 4 %k The number of signals received. .TP 4 %w The number of voluntary context switches (waits). .TP 4 %c The number of involuntary context switches. .PD .Pp Only the first four sequences are supported on systems without BSD resource limit functions. The default time format is .Sq %Uu %Ss %E %P %X+%Dk %I+%Oio %Fpf+%Ww for systems that support resource usage reporting and .Sq %Uu %Ss %E %P for systems that do not. .Pp Under Sequent's DYNIX/ptx, %X, %D, %K, %r and %s are not available, but the following additional sequences are: .Pp .PD 0 .TP 4 %Y The number of system calls performed. .TP 4 %Z The number of pages which are zero-filled on demand. .TP 4 %i The number of times a process's resident set size was increased by the kernel. .TP 4 %d The number of times a process's resident set size was decreased by the kernel. .TP 4 %l The number of read system calls performed. .TP 4 %m The number of write system calls performed. .TP 4 %p The number of reads from raw disk devices. .TP 4 %q The number of writes to raw disk devices. .PD .Pp and the default time format is .Sq %Uu %Ss %E %P %I+%Oio %Fpf+%Ww Note that the CPU percentage can be higher than 100% on multi-processors. .RE .TP 8 .B tperiod \fR(+) The period, in minutes, between executions of the .Va periodic special alias. .TP 8 .B tty \fR(+) The name of the tty, or empty if not attached to one. .TP 8 .B uid \fR(+) The user's real user ID. .TP 8 .B user The user's login name. .TP 8 .B verbose If set, causes the words of each command to be printed, after history substitution (if any). Set by the .Fl v\fR command line option. .TP 8 .B version \fR(+) The version ID stamp. It contains the shell's version number (see .Va tcsh ), origin, release date, vendor, operating system and machine (see .Va VENDOR , .Va OSTYPE and .Va MACHTYPE ) and a comma-separated list of options which were set at compile time. Options which are set by default in the distribution are noted. .Pp .RS +8 .PD 0 .TP 6 8b The shell is eight bit clean; default .TP 6 7b The shell is not eight bit clean .TP 6 wide The shell is multibyte encoding clean (like UTF-8) .TP 6 nls The system's NLS is used; default for systems with NLS .TP 6 lf Login shells execute .Va /etc/csh.login before instead of after .Va /etc/csh.cshrc and .Va ~/.login before instead of after .Va ~/.tcshrc and .Va ~/.history .TP 6 dl `.' is put last in .Va path for security; default .TP 6 nd `.' is omitted from .Va path for security .TP 6 vi .Va vi (1)\-style editing is the default rather than .Va emacs (1)\-style .TP 6 dtr Login shells drop DTR when exiting .TP 6 bye .Va bye is a synonym for .Va logout and .Va log is an alternate name for .Va watchlog .TP 6 al .Va autologout is enabled; default .TP 6 kan Kanji is used if appropriate according to locale settings, unless the .Va nokanji shell variable is set .TP 6 sm The system's .Va malloc (3) is used .TP 6 hb The .Sq #! convention is emulated when executing shell scripts .TP 6 ng The .Va newgrp builtin is available .TP 6 rh The shell attempts to set the .Va REMOTEHOST environment variable .TP 6 afs The shell verifies your password with the kerberos server if local authentication fails. The .Va afsuser shell variable or the .Va AFSUSER environment variable override your local username if set. .PD .Pp An administrator may enter additional strings to indicate differences in the local version. .RE .TP 8 .B vimode \fR(+) .RS +8 If unset, various key bindings change behavior to be more .Va emacs (1)\-style: word boundaries are determined by .Va wordchars versus other characters. .Pp If set, various key bindings change behavior to be more .Va vi (1)\-style: word boundaries are determined by .Va wordchars versus whitespace versus other characters; cursor behavior depends upon current vi mode (command, delete, insert, replace). .Pp This variable is unset by .Va bindkey .Va -e and set by .Va bindkey .Va -v .B vimode may be explicitly set or unset by the user after those .Va bindkey operations if required. .RE .TP 8 .B visiblebell \fR(+) If set, a screen flash is used rather than the audible bell. See also .Va nobeep .TP 8 .B watch \fR(+) A list of user/terminal pairs to watch for logins and logouts. If either the user is .Sq any all terminals are watched for the given user and vice versa. Setting .Va watch to .Sq (any any) watches all users and terminals. For example, .RS +8 .IP "" 4 set watch = (george ttyd1 any console $user any) .Pp reports activity of the user .Sq george on ttyd1, any user on the console, and oneself (or a trespasser) on any terminal. .Pp Logins and logouts are checked every 10 minutes by default, but the first word of .Va watch can be set to a number to check every so many minutes. For example, .IP "" 4 set watch = (1 any any) .Pp reports any login/logout once every minute. For the impatient, the .Va log builtin command triggers a .Va watch report at any time. All current logins are reported (as with the .Va log builtin) when .Va watch is first set. .Pp The .Va who shell variable controls the format of .Va watch reports. .RE .TP 8 .B who \fR(+) The format string for .Va watch messages. The following sequences are replaced by the given information: .Pp .RS +8 .PD 0 .TP 4 %n The name of the user who logged in/out. .TP 4 %a The observed action, i.e., .Sq logged on , .Sq logged off or .Sq replaced .Va olduser on .TP 4 %l The terminal (tty) on which the user logged in/out. .TP 4 %M The full hostname of the remote host, or .Sq local if the login/logout was from the local host. .TP 4 %m The hostname of the remote host up to the first .Sq . The full name is printed if it is an IP address or an X Window System display. .PD .Pp %M and %m are available on only systems that store the remote hostname in .Va /etc/utmp If unset, .Sq %n has %a %l from %m. is used, or .Sq %n has %a %l. on systems which don't store the remote hostname. .RE .TP 8 .B wordchars \fR(+) A list of non-alphanumeric characters to be considered part of a word by the .Va forward-word , .Va backward-word etc., editor commands. If unset, the default value is determined based on the state of .Va vimode : if .Va vimode is unset, .Sq *?_\-.[]~= is used as the default; if .Va vimode is set, .Sq _ is used as the default. .Sh ENVIRONMENT .TP 8 .B AFSUSER \fR(+) Equivalent to the .Va afsuser shell variable. .TP 8 .B COLUMNS The number of columns in the terminal. See .Va Terminal management .TP 8 .B DISPLAY Used by X Window System (see .Va X (1)). If set, the shell does not set .Va autologout (q.v.). .TP 8 .B EDITOR The pathname to a default editor. Used by the .Va run-fg-editor editor command if the the .Va editors shell variable is unset. See also the .Va VISUAL environment variable. .TP 8 .B GROUP \fR(+) Equivalent to the .Va group shell variable. .TP 8 .B HOME Equivalent to the .Va home shell variable. .TP 8 .B HOST \fR(+) Initialized to the name of the machine on which the shell is running, as determined by the .Va gethostname (2) system call. .TP 8 .B HOSTTYPE \fR(+) Initialized to the type of machine on which the shell is running, as determined at compile time. This variable is obsolete and will be removed in a future version. .TP 8 .B HPATH \fR(+) A colon-separated list of directories in which the .Va run-help editor command looks for command documentation. .TP 8 .B LANG Gives the preferred character environment. See .Va Native Language System support .TP 8 .B LC_CTYPE If set, only ctype character handling is changed. See .Va Native Language System support .TP 8 .B LINES The number of lines in the terminal. See .Va Terminal management .TP 8 .B LS_COLORS The format of this variable is reminiscent of the .Va termcap(5) file format; a colon-separated list of expressions of the form " .Va xx=string ", where " .Va xx " is a two-character variable name. The variables with their associated defaults are: .Pp .RS +8 .RS +4 .PD 0 .TP 12 no 0 Normal (non-filename) text .TP 12 fi 0 Regular file .TP 12 di 01;34 Directory .TP 12 ln 01;36 Symbolic link .TP 12 pi 33 Named pipe (FIFO) .TP 12 so 01;35 Socket .TP 12 do 01;35 Door .TP 12 bd 01;33 Block device .TP 12 cd 01;32 Character device .TP 12 ex 01;32 Executable file .TP 12 mi (none) Missing file (defaults to fi) .TP 12 or (none) Orphaned symbolic link (defaults to ln) .TP 12 lc ^[[ Left code .TP 12 rc m Right code .TP 12 ec (none) End code (replaces lc+no+rc) .PD .RE .Pp You need to include only the variables you want to change from the default. .Pp File names can also be colorized based on filename extension. This is specified in the .Va LS_COLORS variable using the syntax .Va "*ext=string" For example, using ISO 6429 codes, to color all C\-language source files blue you would specify .Va "*.c=34" This would color all files ending in .Va .c in blue (34) color. .Pp Control characters can be written either in C\-style\-escaped notation, or in stty\-like ^\-notation. The C\-style notation adds .Va ^[ for Escape, \fB\_\fR for a normal space character, and .Va ? for Delete. In addition, the .Va ^[ escape character can be used to override the default interpretation of .Va ^[ , .Va ^ , .Va : and .Va = .Pp Each file will be written as .Va .Va .Va .Va .Va If the .Va code is undefined, the sequence .Va \fB .Va will be used instead. This is generally more convenient to use, but less general. The left, right and end codes are provided so you don't have to type common parts over and over again and to support weird terminals; you will generally not need to change them at all unless your terminal does not use ISO 6429 color sequences but a different system. .Pp If your terminal does use ISO 6429 color codes, you can compose the type codes (i.e., all except the .Va lc , .Va rc , and .Va ec codes) from numerical commands separated by semicolons. The most common commands are: .Pp .RS +8 .PD 0 .TP 4 0 to restore default color .TP 4 1 for brighter colors .TP 4 4 for underlined text .TP 4 5 for flashing text .TP 4 30 for black foreground .TP 4 31 for red foreground .TP 4 32 for green foreground .TP 4 33 for yellow (or brown) foreground .TP 4 34 for blue foreground .TP 4 35 for purple foreground .TP 4 36 for cyan foreground .TP 4 37 for white (or gray) foreground .TP 4 40 for black background .TP 4 41 for red background .TP 4 42 for green background .TP 4 43 for yellow (or brown) background .TP 4 44 for blue background .TP 4 45 for purple background .TP 4 46 for cyan background .TP 4 47 for white (or gray) background .PD .RE .Pp Not all commands will work on all systems or display devices. .Pp A few terminal programs do not recognize the default end code properly. If all text gets colorized after you do a directory listing, try changing the .Va no and .Va fi codes from 0 to the numerical codes for your standard fore- and background colors. .RE .TP 8 .B MACHTYPE \fR(+) The machine type (microprocessor class or machine model), as determined at compile time. .TP 8 .B NOREBIND \fR(+) If set, printable characters are not rebound to .Va self-insert-command See .Va Native Language System support .TP 8 .B OSTYPE \fR(+) The operating system, as determined at compile time. .TP 8 .B PATH A colon-separated list of directories in which to look for executables. Equivalent to the .Va path shell variable, but in a different format. .TP 8 .B PWD \fR(+) Equivalent to the .Va cwd shell variable, but not synchronized to it; updated only after an actual directory change. .TP 8 .B REMOTEHOST \fR(+) The host from which the user has logged in remotely, if this is the case and the shell is able to determine it. Set only if the shell was so compiled; see the .Va version shell variable. .TP 8 .B SHLVL \fR(+) Equivalent to the .Va shlvl shell variable. .TP 8 .B SYSTYPE \fR(+) The current system type. (Domain/OS only) .TP 8 .B TERM Equivalent to the .Va term shell variable. .TP 8 .B TERMCAP The terminal capability string. See .Va Terminal management .TP 8 .B USER Equivalent to the .Va user shell variable. .TP 8 .B VENDOR \fR(+) The vendor, as determined at compile time. .TP 8 .B VISUAL The pathname to a default full-screen editor. Used by the .Va run-fg-editor editor command if the the .Va editors shell variable is unset. See also the .Va EDITOR environment variable. .Sh FILES .PD 0 .TP 16 .I /etc/csh.cshrc Read first by every shell. ConvexOS, Stellix and Intel use .Va /etc/cshrc and NeXTs use .Va /etc/cshrc.std A/UX, AMIX, Cray and IRIX have no equivalent in .Xr csh 1 , but read this file in .Nm anyway. Solaris 2.x does not have it either, but .Nm reads .Va /etc/.cshrc (+) .TP 16 .I /etc/csh.login Read by login shells after .Va /etc/csh.cshrc ConvexOS, Stellix and Intel use .Va /etc/login , NeXTs use .Va /etc/login.std , Solaris 2.x uses .Va /etc/.login and A/UX, AMIX, Cray and IRIX use .Va /etc/cshrc .TP 16 .I ~/.tcshrc \fR(+) Read by every shell after .Va /etc/csh.cshrc or its equivalent. .TP 16 .I ~/.cshrc Read by every shell, if .Va ~/.tcshrc doesn't exist, after .Va /etc/csh.cshrc or its equivalent. This manual uses .Sq .Va ~/.tcshrc to mean ` .Va ~/.tcshrc or, if .Va ~/.tcshrc is not found, .Va ~/.cshrc '. .TP 16 .I ~/.history Read by login shells after .Va ~/.tcshrc if .Va savehist is set, but see also .Va histfile .TP 16 .I ~/.login Read by login shells after .Va ~/.tcshrc or .Va ~/.history The shell may be compiled to read .Va ~/.login before instead of after .Va ~/.tcshrc and .Va ~/.history ; see the .Va version shell variable. .TP 16 .I ~/.cshdirs \fR(+) Read by login shells after .Va ~/.login if .Va savedirs is set, but see also .Va dirsfile .TP 16 .I /etc/csh.logout Read by login shells at logout. ConvexOS, Stellix and Intel use .Va /etc/logout and NeXTs use .Va /etc/logout.std A/UX, AMIX, Cray and IRIX have no equivalent in .Xr csh 1 , but read this file in .Nm anyway. Solaris 2.x does not have it either, but .Nm reads .Va /etc/.logout (+) .TP 16 .I ~/.logout Read by login shells at logout after .Va /etc/csh.logout or its equivalent. .TP 16 .I /bin/sh Used to interpret shell scripts not starting with a .Sq # .TP 16 .I /tmp/sh* Temporary file for .Sq << .TP 16 .I /etc/passwd Source of home directories for .Sq ~name substitutions. .PD .Pp The order in which startup files are read may differ if the shell was so compiled; see .Va Startup and shutdown and the .Va version shell variable. .Sh "NEW FEATURES (+)" This manual describes .Nm as a single entity, but experienced .Xr csh 1 users will want to pay special attention to .Nm 's new features. .Pp A command-line editor, which supports .Va emacs (1)\-style or .Va vi (1)\-style key bindings. See .Va The command-line editor and .Va Editor commands .Pp Programmable, interactive word completion and listing. See .Sx Completion and listing and the .Va complete and .Va uncomplete builtin commands. .Pp .Va Spelling correction (q.v.) of filenames, commands and variables. .Pp .Va Editor commands (q.v.) which perform other useful functions in the middle of typed commands, including documentation lookup .Va ( run-help ), quick editor restarting .Va ( run-fg-editor ) and command resolution .Va ( which-command ). .Pp An enhanced history mechanism. Events in the history list are time-stamped. See also the .Va history command and its associated shell variables, the previously undocumented .Sq # event specifier and new modifiers under .Va History substitution , the .Va *-history , .Va history-search-* , .Va i-search-* , .Va vi-search-* and .Va toggle-literal-history editor commands and the .Va histlit shell variable. .Pp Enhanced directory parsing and directory stack handling. See the .Va cd , .Va pushd , .Va popd and .Va dirs commands and their associated shell variables, the description of .Va Directory stack substitution , the .Va dirstack , .Va owd and .Va symlinks shell variables and the .Va normalize-command and .Va normalize-path editor commands. .Pp Negation in glob-patterns. See .Va Filename substitution .Pp New .Va File inquiry operators (q.v.) and a .Va filetest builtin which uses them. .Pp A variety of .Va Automatic, periodic and timed events (q.v.) including scheduled events, special aliases, automatic logout and terminal locking, command timing and watching for logins and logouts. .Pp Support for the Native Language System (see .Va Native Language System support ), OS variant features (see .Va OS variant support and the .Va echo_style shell variable) and system-dependent file locations (see .Va FILES ). .Pp Extensive terminal-management capabilities. See .Va Terminal management .Pp New builtin commands including .Va builtins , .Va hup , \fIls\-F\fR, .Va newgrp , .Va printenv , .Va which and .Va where (q.v.). .Pp New variables that make useful information easily available to the shell. See the .Va gid , .Va loginsh , .Va oid , .Va shlvl , .Va tcsh , .Va tty , .Va uid and .Va version shell variables and the .Va HOST , .Va REMOTEHOST , .Va VENDOR , .Va OSTYPE and .Va MACHTYPE environment variables. .Pp A new syntax for including useful information in the prompt string (see .Va prompt ), and special prompts for loops and spelling correction (see .Va prompt2 and .Va prompt3 ). .Pp Read-only variables. See .Va Variable substitution .Sh BUGS When a suspended command is restarted, the shell prints the directory it started in if this is different from the current directory. This can be misleading (i.e., wrong) as the job may have changed directories internally. .Pp Shell builtin functions are not stoppable/restartable. Command sequences of the form .Sq a ; b ; c are also not handled gracefully when stopping is attempted. If you suspend .Sq b , the shell will then immediately execute `c'. This is especially noticeable if this expansion results from an .Va alias It suffices to place the sequence of commands in ()'s to force it to a subshell, i.e., .Sq ( a ; b ; c ) .Pp Control over tty output after processes are started is primitive; perhaps this will inspire someone to work on a good virtual terminal interface. In a virtual terminal interface much more interesting things could be done with output control. .Pp Alias substitution is most often used to clumsily simulate shell procedures; shell procedures should be provided rather than aliases. .Pp Control structures should be parsed rather than being recognized as built-in commands. This would allow control commands to be placed anywhere, to be combined with .Sq | , and to be used with .Sq & and .Sq ; metasyntax. .Pp .Va foreach doesn't ignore here documents when looking for its .Va end .Pp It should be possible to use the .Sq \&: modifiers on the output of command substitutions. .Pp The screen update for lines longer than the screen width is very poor if the terminal cannot move the cursor up (i.e., terminal type .Sq dumb ). .Pp .Va HPATH and .Va NOREBIND don't need to be environment variables. .Pp Glob-patterns which do not use .Sq \&? , .Sq * or .Sq [] or which use .Sq {} or .Sq ~ are not negated correctly. .Pp The single-command form of .Va if does output redirection even if the expression is false and the command is not executed. .Pp \fIls\-F\fR includes file identification characters when sorting filenames and does not handle control characters in filenames well. It cannot be interrupted. .Pp Command substitution supports multiple commands and conditions, but not cycles or backward .Va goto s. .Pp Report bugs at https://bugs.astron.com/, preferably with fixes. If you want to help maintain and test tcsh, add yourself to the mailing list in https://mailman.astron.com/. .Sq subscribe tcsh on a line by itself in the body. .Sh THE T IN TCSH In 1964, DEC produced the PDP-6. The PDP-10 was a later re-implementation. It was re-christened the DECsystem-10 in 1970 or so when DEC brought out the second model, the KI10. .Pp TENEX was created at Bolt, Beranek & Newman (a Cambridge, Massachusetts think tank) in 1972 as an experiment in demand-paged virtual memory operating systems. They built a new pager for the DEC PDP-10 and created the OS to go with it. It was extremely successful in academia. .Pp In 1975, DEC brought out a new model of the PDP-10, the KL10; they intended to have only a version of TENEX, which they had licensed from BBN, for the new box. They called their version TOPS-20 (their capitalization is trademarked). A lot of TOPS-10 users (`The OPerating System for PDP-10') objected; thus DEC found themselves supporting two incompatible systems on the same hardware--but then there were 6 on the PDP-11! .Pp TENEX, and TOPS-20 to version 3, had command completion via a user-code-level subroutine library called ULTCMD. With version 3, DEC moved all that capability and more into the monitor (`kernel' for you Unix types), accessed by the COMND% JSYS (`Jump to SYStem' instruction, the supervisor call mechanism [are my IBM roots also showing?]). .Pp The creator of tcsh was impressed by this feature and several others of TENEX and TOPS-20, and created a version of csh which mimicked them. .Sh LIMITATIONS The system limits argument lists to ARG_MAX characters. .Pp The number of arguments to a command which involves filename expansion is limited to 1/6th the number of characters allowed in an argument list. .Pp Command substitutions may substitute no more characters than are allowed in an argument list. .Pp To detect looping, the shell restricts the number of .Va alias substitutions on a single line to 20. .Sh "SEE ALSO" csh(1), emacs(1), ls(1), newgrp(1), sh(1), setpath(1), stty(1), su(1), tset(1), vi(1), x(1), access(2), execve(2), fork(2), killpg(2), pipe(2), setrlimit(2), sigvec(2), stat(2), umask(2), vfork(2), wait(2), malloc(3), setlocale(3), tty(4), a.out(5), termcap(5), environ(7), termio(7), Introduction to the C Shell .Sh VERSION -This manual documents tcsh 6.21.00 (Astron) 2019-05-08. +This manual documents tcsh 6.22.03 (Astron) 2020-11-18. .Sh AUTHORS .PD 0 .TP 2 William Joy Original author of .Xr csh 1 .TP 2 J.E. Kulp, IIASA, Laxenburg, Austria Job control and directory stack features .TP 2 Ken Greer, HP Labs, 1981 File name completion .TP 2 Mike Ellis, Fairchild, 1983 Command name recognition/completion .TP 2 Paul Placeway, Ohio State CIS Dept., 1983-1993 Command line editor, prompt routines, new glob syntax and numerous fixes and speedups .TP 2 Karl Kleinpaste, CCI 1983-4 Special aliases, directory stack extraction stuff, login/logout watch, scheduled events, and the idea of the new prompt format .TP 2 Rayan Zachariassen, University of Toronto, 1984 \fIls\-F\fR and .Va which builtins and numerous bug fixes, modifications and speedups .TP 2 Chris Kingsley, Caltech Fast storage allocator routines .TP 2 Chris Grevstad, TRW, 1987 Incorporated 4.3BSD .Xr csh 1 into .Nm .TP 2 Christos S. Zoulas, Cornell U. EE Dept., 1987-94 Ports to HPUX, SVR2 and SVR3, a SysV version of getwd.c, SHORT_STRINGS support and a new version of sh.glob.c .TP 2 James J Dempsey, BBN, and Paul Placeway, OSU, 1988 A/UX port .TP 2 Daniel Long, NNSC, 1988 .Va wordchars .TP 2 Patrick Wolfe, Kuck and Associates, Inc., 1988 .Va vi mode cleanup .TP 2 David C Lawrence, Rensselaer Polytechnic Institute, 1989 .Va autolist and ambiguous completion listing .TP 2 Alec Wolman, DEC, 1989 Newlines in the prompt .TP 2 Matt Landau, BBN, 1989 .Va ~/.tcshrc .TP 2 Ray Moody, Purdue Physics, 1989 Magic space bar history expansion .TP 2 Mordechai ????, Intel, 1989 printprompt() fixes and additions .TP 2 Kazuhiro Honda, Dept. of Computer Science, Keio University, 1989 Automatic spelling correction and .Va prompt3 .TP 2 Per Hedeland, Ellemtel, Sweden, 1990- Various bugfixes, improvements and manual updates .TP 2 Hans J. Albertsson (Sun Sweden) .Va ampm , .Va settc and .Va telltc .TP 2 Michael Bloom Interrupt handling fixes .TP 2 Michael Fine, Digital Equipment Corp Extended key support .TP 2 Eric Schnoebelen, Convex, 1990 Convex support, lots of .Xr csh 1 bug fixes, save and restore of directory stack .TP 2 Ron Flax, Apple, 1990 A/UX 2.0 (re)port .TP 2 Dan Oscarsson, LTH Sweden, 1990 NLS support and simulated NLS support for non NLS sites, fixes .TP 2 Johan Widen, SICS Sweden, 1990 .Va shlvl , Mach support, .Va correct-line , 8-bit printing .TP 2 Matt Day, Sanyo Icon, 1990 POSIX termio support, SysV limit fixes .TP 2 Jaap Vermeulen, Sequent, 1990-91 Vi mode fixes, expand-line, window change fixes, Symmetry port .TP 2 Martin Boyer, Institut de recherche d'Hydro-Quebec, 1991 .Va autolist beeping options, modified the history search to search for the whole string from the beginning of the line to the cursor. .TP 2 Scott Krotz, Motorola, 1991 Minix port .TP 2 David Dawes, Sydney U. Australia, Physics Dept., 1991 SVR4 job control fixes .TP 2 Jose Sousa, Interactive Systems Corp., 1991 Extended .Va vi fixes and .Va vi delete command .TP 2 Marc Horowitz, MIT, 1991 ANSIfication fixes, new exec hashing code, imake fixes, .Va where .TP 2 Bruce Sterling Woodcock, sterling@netcom.com, 1991-1995 ETA and Pyramid port, Makefile and lint fixes, .Va ignoreeof =n addition, and various other portability changes and bug fixes .TP 2 Jeff Fink, 1992 .Va complete-word-fwd and .Va complete-word-back .TP 2 Harry C. Pulley, 1992 Coherent port .TP 2 Andy Phillips, Mullard Space Science Lab U.K., 1992 VMS-POSIX port .TP 2 Beto Appleton, IBM Corp., 1992 Walking process group fixes, .Xr csh 1 bug fixes, POSIX file tests, POSIX SIGHUP .TP 2 Scott Bolte, Cray Computer Corp., 1992 CSOS port .TP 2 Kaveh R. Ghazi, Rutgers University, 1992 Tek, m88k, Titan and Masscomp ports and fixes. Added autoconf support. .TP 2 Mark Linderman, Cornell University, 1992 OS/2 port .TP 2 Mika Liljeberg, liljeber@kruuna.Helsinki.FI, 1992 Linux port .TP 2 Tim P. Starrin, NASA Langley Research Center Operations, 1993 Read-only variables .TP 2 Dave Schweisguth, Yale University, 1993-4 New man page and tcsh.man2html .TP 2 Larry Schwimmer, Stanford University, 1993 AFS and HESIOD patches .TP 2 Luke Mewburn, RMIT University, 1994-6 Enhanced directory printing in prompt, added .Va ellipsis and .Va rprompt .TP 2 Edward Hutchins, Silicon Graphics Inc., 1996 Added implicit cd. .TP 2 Martin Kraemer, 1997 Ported to Siemens Nixdorf EBCDIC machine .TP 2 Amol Deshpande, Microsoft, 1997 Ported to WIN32 (Windows/95 and Windows/NT); wrote all the missing library and message catalog code to interface to Windows. .TP 2 Taga Nayuta, 1998 Color ls additions. .PD .Pp .Sh "THANKS TO" Bryan Dunlap, Clayton Elwell, Karl Kleinpaste, Bob Manson, Steve Romig, Diana Smetters, Bob Sutterfield, Mark Verber, Elizabeth Zwicky and all the other people at Ohio State for suggestions and encouragement .Pp All the people on the net, for putting up with, reporting bugs in, and suggesting new additions to each and every version .Pp Richard M. Alderson III, for writing the .Sq T in tcsh section diff --git a/contrib/tcsh/tw.parse.c b/contrib/tcsh/tw.parse.c index 4b492e20a408..ed019db5bd35 100644 --- a/contrib/tcsh/tw.parse.c +++ b/contrib/tcsh/tw.parse.c @@ -1,2375 +1,2375 @@ /* * tw.parse.c: Everyone has taken a shot in this futile effort to * lexically analyze a csh line... Well we cannot good * a job as good as sh.lex.c; but we try. Amazing that * it works considering how many hands have touched this code */ /*- * Copyright (c) 1980, 1991 The Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include "sh.h" #include "tw.h" #include "ed.h" #include "tc.h" #include #ifdef WINNT_NATIVE #include "nt.const.h" #endif /* WINNT_NATIVE */ #define EVEN(x) (((x) & 1) != 1) #define DOT_NONE 0 /* Don't display dot files */ #define DOT_NOT 1 /* Don't display dot or dot-dot */ #define DOT_ALL 2 /* Display all dot files */ /* TW_NONE, TW_COMMAND, TW_VARIABLE, TW_LOGNAME, */ /* TW_FILE, TW_DIRECTORY, TW_VARLIST, TW_USER, */ /* TW_COMPLETION, TW_ALIAS, TW_SHELLVAR, TW_ENVVAR, */ /* TW_BINDING, TW_WORDLIST, TW_LIMIT, TW_SIGNAL */ /* TW_JOB, TW_EXPLAIN, TW_TEXT, TW_GRPNAME */ static void (*const tw_start_entry[]) (DIR *, const Char *) = { tw_file_start, tw_cmd_start, tw_var_start, tw_logname_start, tw_file_start, tw_file_start, tw_vl_start, tw_logname_start, tw_complete_start, tw_alias_start, tw_var_start, tw_var_start, tw_bind_start, tw_wl_start, tw_limit_start, tw_sig_start, tw_job_start, tw_file_start, tw_file_start, tw_grpname_start }; static int (*const tw_next_entry[]) (struct Strbuf *, struct Strbuf *, int *) = { tw_file_next, tw_cmd_next, tw_var_next, tw_logname_next, tw_file_next, tw_file_next, tw_var_next, tw_logname_next, tw_var_next, tw_var_next, tw_shvar_next, tw_envvar_next, tw_bind_next, tw_wl_next, tw_limit_next, tw_sig_next, tw_job_next, tw_file_next, tw_file_next, tw_grpname_next }; static void (*const tw_end_entry[]) (void) = { tw_dir_end, tw_dir_end, tw_dir_end, tw_logname_end, tw_dir_end, tw_dir_end, tw_dir_end, tw_logname_end, tw_dir_end, tw_dir_end, tw_dir_end, tw_dir_end, tw_dir_end, tw_dir_end, tw_dir_end, tw_dir_end, tw_dir_end, tw_dir_end, tw_dir_end, tw_grpname_end }; /* #define TDEBUG */ /* Set to TRUE if recexact is set and an exact match is found * along with other, longer, matches. */ int curchoice = -1; int match_unique_match = FALSE; int non_unique_match = FALSE; static int SearchNoDirErr = 0; /* t_search returns -2 if dir is unreadable */ /* state so if a completion is interrupted, the input line doesn't get nuked */ int InsideCompletion = 0; /* do the expand or list on the command line -- SHOULD BE REPLACED */ static void extract_dir_and_name (const Char *, struct Strbuf *, Char **); static int insert_meta (const Char *, const Char *, const Char *, int); static int tilde (struct Strbuf *, Char *); static int expand_dir (const Char *, struct Strbuf *, DIR **, COMMAND); static int nostat (Char *); static Char filetype (Char *, Char *); static int t_glob (Char ***, int); static int c_glob (Char ***); static int is_prefix (Char *, Char *); static int is_prefixmatch (Char *, Char *, int); static int is_suffix (Char *, Char *); static int recognize (struct Strbuf *, const Char *, size_t, int, int, int); static int ignored (Char *); static int isadirectory (const Char *, const Char *); static int tw_collect_items (COMMAND, int, struct Strbuf *, struct Strbuf *, Char *, const Char *, int); static int tw_collect (COMMAND, int, struct Strbuf *, struct Strbuf *, Char *, Char *, int, DIR *); static Char tw_suffix (int, struct Strbuf *,const Char *, Char *); static void tw_fixword (int, struct Strbuf *, Char *, Char *); static void tw_list_items (int, int, int); static void add_scroll_tab (Char *); static void choose_scroll_tab (struct Strbuf *, int); static void free_scroll_tab (void); static int find_rows (Char *[], int, int); #ifdef notdef /* * If we find a set command, then we break a=b to a= and word becomes * b else, we don't break a=b. [don't use that; splits words badly and * messes up tw_complete()] */ #define isaset(c, w) ((w)[-1] == '=' && \ ((c)[0] == 's' && (c)[1] == 'e' && (c)[2] == 't' && \ ((c[3] == ' ' || (c)[3] == '\t')))) #endif /* TRUE if character must be quoted */ #define tricky(w) (cmap(w, _META | _DOL | _QF | _QB | _ESC | _GLOB) && w != '#') /* TRUE if double quotes don't protect character */ #define tricky_dq(w) (cmap(w, _DOL | _QB)) /* tenematch(): * Return: * > 1: No. of items found * = 1: Exactly one match / spelling corrected * = 0: No match / spelling was correct * < 0: Error (incl spelling correction impossible) */ int tenematch(Char *inputline, int num_read, COMMAND command) { struct Strbuf qline = Strbuf_INIT; Char qu = 0, *pat = STRNULL; size_t wp, word, wordp, cmd_start, oword = 0, ocmd_start = 0; Char *str_end, *cp; Char *word_start; Char *oword_start = NULL; eChar suf = 0; int looking; /* what we are looking for */ int search_ret; /* what search returned for debugging */ int backq = 0; str_end = &inputline[num_read]; cleanup_push(&qline, Strbuf_cleanup); word_start = inputline; word = cmd_start = 0; for (cp = inputline; cp < str_end; cp++) { if (!cmap(qu, _ESC)) { if (cmap(*cp, _QF|_ESC)) { if (qu == 0 || qu == *cp) { qu ^= *cp; continue; } } if (qu != '\'' && cmap(*cp, _QB)) { if ((backq ^= 1) != 0) { ocmd_start = cmd_start; oword_start = word_start; oword = word; word_start = cp + 1; word = cmd_start = qline.len + 1; } else { cmd_start = ocmd_start; word_start = oword_start; word = oword; } Strbuf_append1(&qline, *cp); continue; } } if (iscmdmeta(*cp)) cmd_start = qline.len + 1; /* Don't quote '/' to make the recognize stuff work easily */ /* Don't quote '$' in double quotes */ if (cmap(*cp, _ESC) && cp < str_end - 1 && cp[1] == HIST && HIST != '\0') Strbuf_append1(&qline, *++cp | QUOTE); else if (qu && (tricky(*cp) || *cp == '~') && !(qu == '\"' && tricky_dq(*cp))) Strbuf_append1(&qline, *cp | QUOTE); else Strbuf_append1(&qline, *cp); if (ismetahash(qline.s[qline.len - 1]) /* || isaset(qline.s + cmd_start, qline.s + qline.len) */) word = qline.len, word_start = cp + 1; if (cmap(qu, _ESC)) qu = 0; } Strbuf_terminate(&qline); wp = qline.len; /* * SPECIAL HARDCODED COMPLETIONS: * first word of command -> TW_COMMAND * everything else -> TW_ZERO * */ looking = starting_a_command(qline.s + word - 1, qline.s) ? TW_COMMAND : TW_ZERO; wordp = word; #ifdef TDEBUG { const Char *p; xprintf(CGETS(30, 1, "starting_a_command %d\n"), looking); xprintf("\ncmd_start:%S:\n", qline.s + cmd_start); xprintf("qline:%S:\n", qline.s); xprintf("qline:"); for (p = qline.s; *p; p++) xprintf("%c", *p & QUOTE ? '-' : ' '); xprintf(":\n"); xprintf("word:%S:\n", qline.s + word); xprintf("word:"); for (p = qline.s + word; *p; p++) xprintf("%c", *p & QUOTE ? '-' : ' '); xprintf(":\n"); } #endif if ((looking == TW_COMMAND || looking == TW_ZERO) && (command == RECOGNIZE || command == LIST || command == SPELL || command == RECOGNIZE_SCROLL)) { Char *p; #ifdef TDEBUG xprintf(CGETS(30, 2, "complete %d "), looking); #endif p = qline.s + wordp; looking = tw_complete(qline.s + cmd_start, &p, &pat, looking, &suf); wordp = p - qline.s; #ifdef TDEBUG xprintf(CGETS(30, 3, "complete %d %S\n"), looking, pat); #endif } switch (command) { Char *bptr; Char *items[2], **ptr; int i, count; case RECOGNIZE: case RECOGNIZE_SCROLL: case RECOGNIZE_ALL: { struct Strbuf wordbuf = Strbuf_INIT; Char *slshp; if (adrof(STRautocorrect)) { if ((slshp = Strrchr(qline.s + wordp, '/')) != NULL && slshp[1] != '\0') { SearchNoDirErr = 1; for (bptr = qline.s + wordp; bptr < slshp; bptr++) { /* * do not try to correct spelling of words containing * globbing characters */ if (isglob(*bptr)) { SearchNoDirErr = 0; break; } } } } else slshp = STRNULL; Strbuf_append(&wordbuf, qline.s + wordp); Strbuf_terminate(&wordbuf); cleanup_push(&wordbuf, Strbuf_cleanup); search_ret = t_search(&wordbuf, command, looking, 1, pat, suf); qline.len = wordp; Strbuf_append(&qline, wordbuf.s); Strbuf_terminate(&qline); cleanup_until(&wordbuf); SearchNoDirErr = 0; if (search_ret == -2) { Char *rword; rword = Strsave(slshp); cleanup_push(rword, xfree); if (slshp != STRNULL) *slshp = '\0'; wordbuf = Strbuf_init; Strbuf_append(&wordbuf, qline.s + wordp); Strbuf_terminate(&wordbuf); cleanup_push(&wordbuf, Strbuf_cleanup); search_ret = spell_me(&wordbuf, looking, pat, suf); if (search_ret == 1) { Strbuf_append(&wordbuf, rword); Strbuf_terminate(&wordbuf); wp = wordp + wordbuf.len; search_ret = t_search(&wordbuf, command, looking, 1, pat, suf); } qline.len = wordp; Strbuf_append(&qline, wordbuf.s); Strbuf_terminate(&qline); cleanup_until(rword); } if (qline.s[wp] != '\0' && insert_meta(word_start, str_end, qline.s + word, !qu) < 0) goto err; /* error inserting */ break; } case SPELL: { struct Strbuf wordbuf = Strbuf_INIT; for (bptr = word_start; bptr < str_end; bptr++) { /* * do not try to correct spelling of words containing globbing * characters */ if (isglob(*bptr)) { search_ret = 0; goto end; } } Strbuf_append(&wordbuf, qline.s + wordp); Strbuf_terminate(&wordbuf); cleanup_push(&wordbuf, Strbuf_cleanup); /* * Don't try to spell things that we know they are correct. * Trying to spell can hang when we have NFS mounted hung * volumes. */ if ((looking == TW_COMMAND) && Strchr(wordbuf.s, '/') != NULL) { if (executable(NULL, wordbuf.s, 0)) { cleanup_until(&wordbuf); search_ret = 0; goto end; } } search_ret = spell_me(&wordbuf, looking, pat, suf); qline.len = wordp; Strbuf_append(&qline, wordbuf.s); Strbuf_terminate(&qline); cleanup_until(&wordbuf); if (search_ret == 1) { if (insert_meta(word_start, str_end, qline.s + word, !qu) < 0) goto err; /* error inserting */ } break; } case PRINT_HELP: do_help(qline.s + cmd_start); search_ret = 1; break; case GLOB: case GLOB_EXPAND: items[0] = Strsave(qline.s + wordp); items[1] = NULL; cleanup_push(items[0], xfree); ptr = items; count = (looking == TW_COMMAND && Strchr(qline.s + wordp, '/') == 0) ? c_glob(&ptr) : t_glob(&ptr, looking == TW_COMMAND); cleanup_until(items[0]); if (ptr != items) cleanup_push(ptr, blk_cleanup); if (count > 0) { if (command == GLOB) print_by_column(STRNULL, ptr, count, 0); else { DeleteBack(str_end - word_start);/* get rid of old word */ for (i = 0; i < count; i++) if (ptr[i] && *ptr[i]) { (void) quote(ptr[i]); if (insert_meta(0, 0, ptr[i], 0) < 0 || InsertStr(STRspace) < 0) { if (ptr != items) cleanup_until(ptr); goto err; /* error inserting */ } } } } if (ptr != items) cleanup_until(ptr); search_ret = count; break; case VARS_EXPAND: bptr = dollar(qline.s + word); if (bptr != NULL) { if (insert_meta(word_start, str_end, bptr, !qu) < 0) { xfree(bptr); goto err; /* error inserting */ } xfree(bptr); search_ret = 1; break; } search_ret = 0; break; case PATH_NORMALIZE: if ((bptr = dnormalize(qline.s + wordp, symlinks == SYM_IGNORE || symlinks == SYM_EXPAND)) != NULL) { if (insert_meta(word_start, str_end, bptr, !qu) < 0) { xfree(bptr); goto err; /* error inserting */ } xfree(bptr); search_ret = 1; break; } search_ret = 0; break; case COMMAND_NORMALIZE: { Char *p; int found; found = cmd_expand(qline.s + wordp, &p); if (!found) { xfree(p); search_ret = 0; break; } if (insert_meta(word_start, str_end, p, !qu) < 0) { xfree(p); goto err; /* error inserting */ } xfree(p); search_ret = 1; break; } case LIST: case LIST_ALL: { struct Strbuf wordbuf = Strbuf_INIT; Strbuf_append(&wordbuf, qline.s + wordp); Strbuf_terminate(&wordbuf); cleanup_push(&wordbuf, Strbuf_cleanup); search_ret = t_search(&wordbuf, LIST, looking, 1, pat, suf); qline.len = wordp; Strbuf_append(&qline, wordbuf.s); Strbuf_terminate(&qline); cleanup_until(&wordbuf); break; } default: xprintf(CGETS(30, 4, "%s: Internal match error.\n"), progname); search_ret = 1; } end: cleanup_until(&qline); return search_ret; err: cleanup_until(&qline); return -1; } /* end tenematch */ /* t_glob(): * Return a list of files that match the pattern */ static int t_glob(Char ***v, int cmd) { jmp_buf_t osetexit; int gflag; if (**v == 0) return (0); gflag = tglob(*v); if (gflag) { size_t omark; getexit(osetexit); /* make sure to come back here */ omark = cleanup_push_mark(); if (setexit() == 0) *v = globall(*v, gflag); cleanup_pop_mark(omark); resexit(osetexit); if (haderr) { haderr = 0; NeedsRedraw = 1; return (-1); } if (*v == 0) return (0); } else return (0); if (cmd) { Char **av = *v, *p; int fwd, i; for (i = 0, fwd = 0; av[i] != NULL; i++) if (!executable(NULL, av[i], 0)) { fwd++; p = av[i]; av[i] = NULL; xfree(p); } else if (fwd) av[i - fwd] = av[i]; if (fwd) av[i - fwd] = av[i]; } return blklen(*v); } /* end t_glob */ /* c_glob(): * Return a list of commands that match the pattern */ static int c_glob(Char ***v) { struct blk_buf av = BLK_BUF_INIT; struct Strbuf cmd = Strbuf_INIT, dir = Strbuf_INIT; Char *pat = **v; int flag; if (pat == NULL) return (0); cleanup_push(&av, bb_cleanup); cleanup_push(&cmd, Strbuf_cleanup); cleanup_push(&dir, Strbuf_cleanup); tw_cmd_start(NULL, NULL); while (cmd.len = 0, tw_cmd_next(&cmd, &dir, &flag) != 0) { Strbuf_terminate(&cmd); if (Gmatch(cmd.s, pat)) bb_append(&av, Strsave(cmd.s)); } tw_dir_end(); *v = bb_finish(&av); cleanup_ignore(&av); cleanup_until(&av); return av.len; } /* end c_glob */ /* insert_meta(): * change the word before the cursor. * cp must point to the start of the unquoted word. * cpend to the end of it. * word is the text that has to be substituted. * strategy: * try to keep all the quote characters of the user's input. * change quote type only if necessary. */ static int insert_meta(const Char *cp, const Char *cpend, const Char *word, int closequotes) { struct Strbuf buffer = Strbuf_INIT; Char *bptr; const Char *wptr; int in_sync = (cp != NULL); Char qu = 0; int ndel = (int) (cp ? cpend - cp : 0); Char w, wq; int res; for (wptr = word;;) { if (cp >= cpend) in_sync = 0; if (in_sync && !cmap(qu, _ESC) && cmap(*cp, _QF|_ESC)) if (qu == 0 || qu == *cp) { qu ^= *cp; Strbuf_append1(&buffer, *cp++); continue; } w = *wptr; if (w == 0) break; wq = w & QUOTE; #if INVALID_BYTE != 0 /* add checking INVALID_BYTE for FIX UTF32 */ if ((w & INVALID_BYTE) != INVALID_BYTE) /* w < INVALID_BYTE */ #endif w &= ~QUOTE; if (cmap(w, _ESC | _QF)) wq = QUOTE; /* quotes are always quoted */ if (!wq && qu && tricky(w) && !(qu == '\"' && tricky_dq(w))) { /* We have to unquote the character */ in_sync = 0; if (cmap(qu, _ESC)) buffer.s[buffer.len - 1] = w; else { Strbuf_append1(&buffer, qu); Strbuf_append1(&buffer, w); if (wptr[1] == 0) qu = 0; else Strbuf_append1(&buffer, qu); } } else if (qu && w == qu) { in_sync = 0; if (buffer.len != 0 && buffer.s[buffer.len - 1] == qu) { /* User misunderstanding :) */ buffer.s[buffer.len - 1] = '\\'; Strbuf_append1(&buffer, w); qu = 0; } else { Strbuf_append1(&buffer, qu); Strbuf_append1(&buffer, '\\'); Strbuf_append1(&buffer, w); Strbuf_append1(&buffer, qu); } } else if (wq && qu == '\"' && tricky_dq(w)) { in_sync = 0; Strbuf_append1(&buffer, qu); Strbuf_append1(&buffer, '\\'); Strbuf_append1(&buffer, w); Strbuf_append1(&buffer, qu); } else if (wq && ((!qu && (tricky(w) || (w == HISTSUB && HISTSUB != '\0' && buffer.len == 0))) || (!cmap(qu, _ESC) && w == HIST && HIST != '\0'))) { in_sync = 0; Strbuf_append1(&buffer, '\\'); Strbuf_append1(&buffer, w); } else { if (in_sync && *cp++ != w) in_sync = 0; Strbuf_append1(&buffer, w); } wptr++; if (cmap(qu, _ESC)) qu = 0; } if (closequotes && qu && !cmap(qu, _ESC)) Strbuf_append1(&buffer, w); bptr = Strbuf_finish(&buffer); if (ndel) DeleteBack(ndel); res = InsertStr(bptr); xfree(bptr); return res; } /* end insert_meta */ /* is_prefix(): * return true if check matches initial chars in template * This differs from PWB imatch in that if check is null * it matches anything */ static int is_prefix(Char *check, Char *template) { for (; *check; check++, template++) if ((*check & TRIM) != (*template & TRIM)) return (FALSE); return (TRUE); } /* end is_prefix */ /* is_prefixmatch(): * return true if check matches initial chars in template * This differs from PWB imatch in that if check is null * it matches anything * and matches on shortening of commands */ static int is_prefixmatch(Char *check, Char *template, int enhanced) { Char MCH1, MCH2, LCH1, LCH2; for (; *check; check++, template++) { if ((*check & TRIM) != (*template & TRIM)) { MCH1 = (*check & TRIM); MCH2 = (*template & TRIM); LCH1 = Isupper(MCH1) ? Tolower(MCH1) : enhanced == 2 && MCH1 == '_' ? '-' : MCH1; LCH2 = Isupper(MCH2) ? Tolower(MCH2) : enhanced == 2 && MCH2 == '_' ? '-' : MCH2; if (MCH1 != MCH2 && MCH1 != LCH2 && (LCH1 != MCH2 || enhanced == 2)) { if (enhanced && ((*check & TRIM) == '-' || (*check & TRIM) == '.' || (*check & TRIM) == '_')) { MCH1 = MCH2 = (*check & TRIM); if (MCH1 == '_' && enhanced != 2) { MCH2 = '-'; } else if (MCH1 == '-') { MCH2 = '_'; } for (; *template && (*template & TRIM) != MCH1 && (*template & TRIM) != MCH2; template++) continue; if (!*template) { return (FALSE); } } else { return (FALSE); } } } } return (TRUE); } /* end is_prefixmatch */ /* is_suffix(): * Return true if the chars in template appear at the * end of check, I.e., are it's suffix. */ static int is_suffix(Char *check, Char *template) { Char *t, *c; t = Strend(template); c = Strend(check); for (;;) { if (t == template) return 1; if (c == check || (*--t & TRIM) != (*--c & TRIM)) return 0; } } /* end is_suffix */ /* ignored(): * Return true if this is an ignored item */ static int ignored(Char *item) { struct varent *vp; Char **cp; if ((vp = adrof(STRfignore)) == NULL || (cp = vp->vec) == NULL) return (FALSE); for (; *cp != NULL; cp++) if (is_suffix(item, *cp)) return (TRUE); return (FALSE); } /* end ignored */ /* starting_a_command(): * return true if the command starting at wordstart is a command */ int starting_a_command(Char *wordstart, Char *inputline) { Char *ptr, *ncmdstart; int count, bsl; static Char cmdstart[] = {'`', ';', '&', '(', '|', '\0'}, cmdalive[] = {' ', '\t', '\'', '"', '<', '>', '\0'}; /* * Find if the number of backquotes is odd or even. */ for (ptr = wordstart, count = 0; ptr >= inputline; count += (*ptr-- == '`')) continue; /* * if the number of backquotes is even don't include the backquote char in * the list of command starting delimiters [if it is zero, then it does not * matter] */ ncmdstart = cmdstart + EVEN(count); /* * look for the characters previous to this word if we find a command * starting delimiter we break. if we find whitespace and another previous * word then we are not a command * * count is our state machine: 0 looking for anything 1 found white-space * looking for non-ws */ for (count = 0; wordstart >= inputline; wordstart--) { if (*wordstart == '\0') continue; if (Strchr(ncmdstart, *wordstart)) { for (ptr = wordstart, bsl = 0; *(--ptr) == '\\'; bsl++); if (bsl & 1) { wordstart--; continue; } else break; } /* * found white space */ if ((ptr = Strchr(cmdalive, *wordstart)) != NULL) count = 1; if (count == 1 && !ptr) return (FALSE); } if (wordstart > inputline) switch (*wordstart) { case '&': /* Look for >& */ while (wordstart > inputline && (*--wordstart == ' ' || *wordstart == '\t')) continue; if (*wordstart == '>') return (FALSE); break; case '(': /* check for foreach, if etc. */ while (wordstart > inputline && (*--wordstart == ' ' || *wordstart == '\t')) continue; if (!iscmdmeta(*wordstart) && (*wordstart != ' ' && *wordstart != '\t')) return (FALSE); break; default: break; } return (TRUE); } /* end starting_a_command */ /* recognize(): * Object: extend what user typed up to an ambiguity. * Algorithm: * On first match, copy full item (assume it'll be the only match) * On subsequent matches, shorten exp_name to the first * character mismatch between exp_name and item. * If we shorten it back to the prefix length, stop searching. */ static int recognize(struct Strbuf *exp_name, const Char *item, size_t name_length, int numitems, int enhanced, int igncase) { Char MCH1, MCH2, LCH1, LCH2; Char *x; const Char *ent; size_t len = 0; if (numitems == 1) { /* 1st match */ exp_name->len = 0; Strbuf_append(exp_name, item); Strbuf_terminate(exp_name); return (0); } if (!enhanced && !igncase) { for (x = exp_name->s, ent = item; *x && (*x & TRIM) == (*ent & TRIM); x++, ent++) len++; } else { for (x = exp_name->s, ent = item; *x; x++, ent++) { MCH1 = *x & TRIM; MCH2 = *ent & TRIM; LCH1 = Isupper(MCH1) ? Tolower(MCH1) : MCH1; LCH2 = Isupper(MCH2) ? Tolower(MCH2) : MCH2; if (MCH1 != MCH2) { if (LCH1 == MCH2 || (MCH1 == '_' && MCH2 == '-')) *x = *ent; else if (LCH1 != LCH2) break; } len++; } } *x = '\0'; /* Shorten at 1st char diff */ exp_name->len = x - exp_name->s; if (!(match_unique_match || is_set(STRrecexact) || (enhanced && *ent)) && len == name_length) /* Ambiguous to prefix? */ return (-1); /* So stop now and save time */ return (0); } /* end recognize */ /* tw_collect_items(): * Collect items that match target. * SPELL command: * Returns the spelling distance of the closest match. * else * Returns the number of items found. * If none found, but some ignored items were found, * It returns the -number of ignored items. */ static int tw_collect_items(COMMAND command, int looking, struct Strbuf *exp_dir, struct Strbuf *exp_name, Char *target, const Char *pat, int flags) { int done = FALSE; /* Search is done */ int showdots; /* Style to show dot files */ int nignored = 0; /* Number of fignored items */ int numitems = 0; /* Number of matched items */ size_t name_length = Strlen(target); /* Length of prefix (file name) */ int exec_check = flags & TW_EXEC_CHK;/* need to check executability */ int dir_check = flags & TW_DIR_CHK; /* Need to check for directories */ int text_check = flags & TW_TEXT_CHK;/* Need to check for non-directories */ int dir_ok = flags & TW_DIR_OK; /* Ignore directories? */ int gpat = flags & TW_PAT_OK; /* Match against a pattern */ int ignoring = flags & TW_IGN_OK; /* Use fignore? */ int d = 4, nd; /* Spelling distance */ Char **cp; Char *ptr; struct varent *vp; struct Strbuf buf = Strbuf_INIT, item = Strbuf_INIT; int enhanced = 0; int cnt = 0; int igncase = 0; flags = 0; showdots = DOT_NONE; if ((ptr = varval(STRlistflags)) != STRNULL) while (*ptr) switch (*ptr++) { case 'a': showdots = DOT_ALL; break; case 'A': showdots = DOT_NOT; break; default: break; } if (looking == TW_COMMAND && (vp = adrof(STRautorehash)) != NULL && vp->vec != NULL) for (cp = vp->vec; *cp; cp++) if (Strcmp(*cp, STRalways) == 0 || (Strcmp(*cp, STRcorrect) == 0 && command == SPELL) || (Strcmp(*cp, STRcomplete) == 0 && command != SPELL)) { tw_cmd_free(); tw_cmd_start(NULL, NULL); break; } cleanup_push(&item, Strbuf_cleanup); cleanup_push(&buf, Strbuf_cleanup); while (!done && (item.len = 0, tw_next_entry[looking](&item, exp_dir, &flags) != 0)) { Strbuf_terminate(&item); #ifdef TDEBUG xprintf("item = %S\n", item.s); #endif switch (looking) { case TW_FILE: case TW_DIRECTORY: case TW_TEXT: /* * Don't match . files on null prefix match */ if (showdots == DOT_NOT && (ISDOT(item.s) || ISDOTDOT(item.s))) done = TRUE; if (name_length == 0 && item.s[0] == '.' && showdots == DOT_NONE) done = TRUE; break; case TW_COMMAND: #if defined(_UWIN) || defined(__CYGWIN__) /* * Turn foo.{exe,com,bat,cmd} into foo since UWIN's readdir returns * the file with the .exe, .com, .bat, .cmd extension * * Same for Cygwin, but only for .exe and .com extension. */ { #ifdef __CYGWIN__ static const char *rext[] = { ".exe", ".com" }; #else static const char *rext[] = { ".exe", ".bat", ".com", ".cmd" }; #endif size_t exti = Strlen(item.s); if (exti > 4) { char *ext = short2str(&item.s[exti -= 4]); size_t i; for (i = 0; i < sizeof(rext) / sizeof(rext[0]); i++) if (strcasecmp(ext, rext[i]) == 0) { item.len = exti; Strbuf_terminate(&item); break; } } } #endif /* _UWIN || __CYGWIN__ */ exec_check = flags & TW_EXEC_CHK; dir_ok = flags & TW_DIR_OK; break; default: break; } if (done) { done = FALSE; continue; } switch (command) { case SPELL: /* correct the spelling of the last bit */ if (name_length == 0) {/* zero-length word can't be misspelled */ exp_name->len = 0; /* (not trying is important for ~) */ Strbuf_terminate(exp_name); d = 0; done = TRUE; break; } if (gpat && !Gmatch(item.s, pat)) break; /* * Swapped the order of the spdist() arguments as suggested * by eeide@asylum.cs.utah.edu (Eric Eide) */ nd = spdist(target, item.s); /* test the item against original */ if (nd <= d && nd != 4) { if (!(exec_check && !executable(exp_dir->s, item.s, dir_ok))) { exp_name->len = 0; Strbuf_append(exp_name, item.s); Strbuf_terminate(exp_name); d = nd; if (d == 0) /* if found it exactly */ done = TRUE; } } else if (nd == 4) { if (spdir(exp_name, exp_dir->s, item.s, target)) { if (exec_check && !executable(exp_dir->s, exp_name->s, dir_ok)) break; #ifdef notdef /* * We don't want to stop immediately, because * we might find an exact/better match later. */ d = 0; done = TRUE; #endif d = 3; } } break; case LIST: case RECOGNIZE: case RECOGNIZE_ALL: case RECOGNIZE_SCROLL: if ((vp = adrof(STRcomplete)) != NULL && vp->vec != NULL) for (cp = vp->vec; *cp; cp++) { if (Strcmp(*cp, STREnhance) == 0) enhanced = 2; else if (Strcmp(*cp, STRigncase) == 0) igncase = 1; else if (Strcmp(*cp, STRenhance) == 0) enhanced = 1; } if (enhanced || igncase) { if (!is_prefixmatch(target, item.s, enhanced)) break; } else { if (!is_prefix(target, item.s)) break; } if (exec_check && !executable(exp_dir->s, item.s, dir_ok)) break; if (dir_check && !isadirectory(exp_dir->s, item.s)) break; if (text_check && isadirectory(exp_dir->s, item.s)) break; /* * Only pattern match directories if we're checking * for directories. */ if (gpat && !Gmatch(item.s, pat) && (dir_check || !isadirectory(exp_dir->s, item.s))) break; /* * Remove duplicates in command listing and completion * AFEB added code for TW_LOGNAME and TW_USER cases */ if (looking == TW_COMMAND || looking == TW_LOGNAME || looking == TW_USER || command == LIST) { buf.len = 0; Strbuf_append(&buf, item.s); switch (looking) { case TW_COMMAND: if (!(dir_ok && exec_check)) break; if (filetype(exp_dir->s, item.s) == '/') Strbuf_append1(&buf, '/'); break; case TW_FILE: case TW_DIRECTORY: Strbuf_append1(&buf, filetype(exp_dir->s, item.s)); break; default: break; } Strbuf_terminate(&buf); if ((looking == TW_COMMAND || looking == TW_USER || looking == TW_LOGNAME) && tw_item_find(buf.s)) break; else { /* maximum length 1 (NULL) + 1 (~ or $) + 1 (filetype) */ tw_item_add(&buf); if (command == LIST) numitems++; } } if (command == RECOGNIZE || command == RECOGNIZE_ALL || command == RECOGNIZE_SCROLL) { if (ignoring && ignored(item.s)) { nignored++; break; } else if (command == RECOGNIZE_SCROLL) { add_scroll_tab(item.s); cnt++; } if (match_unique_match || is_set(STRrecexact)) { if (StrQcmp(target, item.s) == 0) { /* EXACT match */ exp_name->len = 0; Strbuf_append(exp_name, item.s); Strbuf_terminate(exp_name); numitems = 1; /* fake into expanding */ non_unique_match = TRUE; done = TRUE; break; } } if (recognize(exp_name, item.s, name_length, ++numitems, enhanced, igncase)) if (command != RECOGNIZE_SCROLL) done = TRUE; if (enhanced && exp_name->len < name_length) { exp_name->len = 0; Strbuf_append(exp_name, target); Strbuf_terminate(exp_name); } } break; default: break; } #ifdef TDEBUG xprintf("done item = %S\n", item.s); #endif } cleanup_until(&item); if (command == RECOGNIZE_SCROLL) { if ((cnt <= curchoice) || (curchoice == -1)) { curchoice = -1; nignored = 0; numitems = 0; } else if (numitems > 1) { if (curchoice < -1) curchoice = cnt - 1; choose_scroll_tab(exp_name, cnt); numitems = 1; } } free_scroll_tab(); if (command == SPELL) return d; else { if (ignoring && numitems == 0 && nignored > 0) return -nignored; else return numitems; } } /* tw_suffix(): * Find and return the appropriate suffix character */ /*ARGSUSED*/ static Char tw_suffix(int looking, struct Strbuf *word, const Char *exp_dir, Char *exp_name) { Char *ptr; Char *dol; struct varent *vp; (void) strip(exp_name); switch (looking) { case TW_LOGNAME: return '/'; case TW_VARIABLE: /* * Don't consider array variables or empty variables */ if ((vp = adrof(exp_name)) != NULL && vp->vec != NULL) { if ((ptr = vp->vec[0]) == NULL || *ptr == '\0' || vp->vec[1] != NULL) return ' '; } else if ((ptr = tgetenv(exp_name)) == NULL || *ptr == '\0') return ' '; if ((dol = Strrchr(word->s, '$')) != 0 && dol[1] == '{' && Strchr(dol, '}') == NULL) return '}'; return isadirectory(exp_dir, ptr) ? '/' : ' '; case TW_DIRECTORY: return '/'; case TW_COMMAND: case TW_FILE: return isadirectory(exp_dir, exp_name) ? '/' : ' '; case TW_ALIAS: case TW_VARLIST: case TW_WORDLIST: case TW_SHELLVAR: case TW_ENVVAR: case TW_USER: case TW_BINDING: case TW_LIMIT: case TW_SIGNAL: case TW_JOB: case TW_COMPLETION: case TW_TEXT: case TW_GRPNAME: return ' '; default: return '\0'; } } /* end tw_suffix */ /* tw_fixword(): * Repair a word after a spalling or a recognizwe */ static void tw_fixword(int looking, struct Strbuf *word, Char *dir, Char *exp_name) { Char *ptr; switch (looking) { case TW_LOGNAME: word->len = 0; Strbuf_append1(word, '~'); break; case TW_VARIABLE: if ((ptr = Strrchr(word->s, '$')) != NULL) { if (ptr[1] == '{') ptr++; word->len = ptr + 1 - word->s; /* Delete after the dollar */ } else word->len = 0; break; case TW_DIRECTORY: case TW_FILE: case TW_TEXT: word->len = 0; Strbuf_append(word, dir); /* put back dir part */ break; default: word->len = 0; break; } (void) quote(exp_name); Strbuf_append(word, exp_name); /* add extended name */ Strbuf_terminate(word); } /* end tw_fixword */ /* tw_collect(): * Collect items. Return -1 in case we were interrupted or * the return value of tw_collect * This is really a wrapper for tw_collect_items, serving two * purposes: * 1. Handles interrupt cleanups. * 2. Retries if we had no matches, but there were ignored matches */ static int tw_collect(COMMAND command, int looking, struct Strbuf *exp_dir, struct Strbuf *exp_name, Char *target, Char *pat, int flags, DIR *dir_fd) { volatile int ni; jmp_buf_t osetexit; #ifdef TDEBUG xprintf("target = %S\n", target); #endif ni = 0; getexit(osetexit); for (;;) { volatile size_t omark; (*tw_start_entry[looking])(dir_fd, pat); InsideCompletion = 1; if (setexit()) { cleanup_pop_mark(omark); resexit(osetexit); /* interrupted, clean up */ haderr = 0; ni = -1; /* flag error */ break; } omark = cleanup_push_mark(); ni = tw_collect_items(command, looking, exp_dir, exp_name, target, pat, ni >= 0 ? flags : flags & ~TW_IGN_OK); cleanup_pop_mark(omark); resexit(osetexit); if (ni >= 0) break; } InsideCompletion = 0; #if defined(SOLARIS2) && defined(i386) && !defined(__GNUC__) /* Compiler bug? (from PWP) */ if ((looking == TW_LOGNAME) || (looking == TW_USER)) tw_logname_end(); else if (looking == TW_GRPNAME) tw_grpname_end(); else tw_dir_end(); #else /* !(SOLARIS2 && i386 && !__GNUC__) */ (*tw_end_entry[looking])(); #endif /* !(SOLARIS2 && i386 && !__GNUC__) */ return(ni); } /* end tw_collect */ /* tw_list_items(): * List the items that were found * * NOTE instead of looking at numerical vars listmax and listmaxrows * we can look at numerical var listmax, and have a string value * listmaxtype (or similar) than can have values 'items' and 'rows' * (by default interpreted as 'items', for backwards compatibility) */ static void tw_list_items(int looking, int numitems, int list_max) { Char *ptr; int max_items = 0; int max_rows = 0; if (numitems == 0) return; if ((ptr = varval(STRlistmax)) != STRNULL) { while (*ptr) { if (!Isdigit(*ptr)) { max_items = 0; break; } max_items = max_items * 10 + *ptr++ - '0'; } if ((max_items > 0) && (numitems > max_items) && list_max) max_items = numitems; else max_items = 0; } if (max_items == 0 && (ptr = varval(STRlistmaxrows)) != STRNULL) { int rows; while (*ptr) { if (!Isdigit(*ptr)) { max_rows = 0; break; } max_rows = max_rows * 10 + *ptr++ - '0'; } if (max_rows != 0 && looking != TW_JOB) rows = find_rows(tw_item_get(), numitems, TRUE); else rows = numitems; /* underestimate for lines wider than the termH */ if ((max_rows > 0) && (rows > max_rows) && list_max) max_rows = rows; else max_rows = 0; } if (max_items || max_rows) { char tc, *sname; const char *name; int maxs; if (max_items) { name = CGETS(30, 5, "items"); maxs = max_items; } else { name = CGETS(30, 6, "rows"); maxs = max_rows; } sname = strsave(name); cleanup_push(sname, xfree); xprintf(CGETS(30, 7, "There are %d %s, list them anyway? [n/y] "), maxs, sname); cleanup_until(sname); flush(); /* We should be in Rawmode here, so no \n to catch */ (void) xread(SHIN, &tc, 1); xprintf("%c\r\n", tc); /* echo the char, do a newline */ /* * Perhaps we should use the yesexpr from the * actual locale */ if (strchr(CGETS(30, 13, "Yy"), tc) == NULL) return; } if (looking != TW_SIGNAL) qsort(tw_item_get(), numitems, sizeof(Char *), fcompare); if (looking != TW_JOB) print_by_column(STRNULL, tw_item_get(), numitems, TRUE); else { /* * print one item on every line because jobs can have spaces * and it is confusing. */ int i; Char **w = tw_item_get(); for (i = 0; i < numitems; i++) { xprintf("%S", w[i]); if (Tty_raw_mode) xputchar('\r'); xputchar('\n'); } } } /* end tw_list_items */ /* t_search(): * Perform a RECOGNIZE, LIST or SPELL command on string "word". * * Return value: * >= 0: SPELL command: "distance" (see spdist()) * other: No. of items found * < 0: Error (message or beep is output) */ /*ARGSUSED*/ int t_search(struct Strbuf *word, COMMAND command, int looking, int list_max, Char *pat, eChar suf) { int numitems, /* Number of items matched */ flags = 0, /* search flags */ gpat = pat[0] != '\0', /* Glob pattern search */ res; /* Return value */ struct Strbuf exp_dir = Strbuf_INIT;/* dir after ~ expansion */ struct Strbuf dir = Strbuf_INIT; /* /x/y/z/ part in /x/y/z/f */ struct Strbuf exp_name = Strbuf_INIT;/* the recognized (extended) */ Char *name, /* f part in /d/d/d/f name */ *target; /* Target to expand/correct/list */ DIR *dir_fd = NULL; /* * bugfix by Marty Grossman (grossman@CC5.BBN.COM): directory listing can * dump core when interrupted */ tw_item_free(); non_unique_match = FALSE; /* See the recexact code below */ extract_dir_and_name(word->s, &dir, &name); cleanup_push(&dir, Strbuf_cleanup); cleanup_push(&name, xfree_indirect); /* * SPECIAL HARDCODED COMPLETIONS: * foo$variable -> TW_VARIABLE * ~user -> TW_LOGNAME * */ if ((*word->s == '~') && (Strchr(word->s, '/') == NULL)) { looking = TW_LOGNAME; target = name; gpat = 0; /* Override pattern mechanism */ } else if ((target = Strrchr(name, '$')) != 0 && (target[1] != '{' || Strchr(target, '}') == NULL) && (Strchr(name, '/') == NULL)) { target++; if (target[0] == '{') target++; looking = TW_VARIABLE; gpat = 0; /* Override pattern mechanism */ } else target = name; /* * Try to figure out what we should be looking for */ if (looking & TW_PATH) { gpat = 0; /* pattern holds the pathname to be used */ Strbuf_append(&exp_dir, pat); if (exp_dir.len != 0 && exp_dir.s[exp_dir.len - 1] != '/') Strbuf_append1(&exp_dir, '/'); Strbuf_append(&exp_dir, dir.s); } Strbuf_terminate(&exp_dir); cleanup_push(&exp_dir, Strbuf_cleanup); switch (looking & ~TW_PATH) { case TW_NONE: res = -1; goto err_dir; case TW_ZERO: looking = TW_FILE; break; case TW_COMMAND: if (Strchr(word->s, '/') || (looking & TW_PATH)) { looking = TW_FILE; flags |= TW_EXEC_CHK; flags |= TW_DIR_OK; } #ifdef notdef /* PWP: don't even bother when doing ALL of the commands */ if (looking == TW_COMMAND && word->len == 0) { res = -1; goto err_dir; } #endif break; case TW_VARLIST: case TW_WORDLIST: gpat = 0; /* pattern holds the name of the variable */ break; case TW_EXPLAIN: if (command == LIST && pat != NULL) { xprintf("%S", pat); if (Tty_raw_mode) xputchar('\r'); xputchar('\n'); } res = 2; goto err_dir; default: break; } /* * let fignore work only when we are not using a pattern */ flags |= (gpat == 0) ? TW_IGN_OK : TW_PAT_OK; #ifdef TDEBUG xprintf(CGETS(30, 8, "looking = %d\n"), looking); #endif switch (looking) { Char *user_name; case TW_ALIAS: case TW_SHELLVAR: case TW_ENVVAR: case TW_BINDING: case TW_LIMIT: case TW_SIGNAL: case TW_JOB: case TW_COMPLETION: case TW_GRPNAME: break; case TW_VARIABLE: if ((res = expand_dir(dir.s, &exp_dir, &dir_fd, command)) != 0) goto err_dir; break; case TW_DIRECTORY: flags |= TW_DIR_CHK; #ifdef notyet /* * This is supposed to expand the directory stack. * Problems: * 1. Slow * 2. directories with the same name */ flags |= TW_DIR_OK; #endif #ifdef notyet /* * Supposed to do delayed expansion, but it is inconsistent * from a user-interface point of view, since it does not * immediately obey addsuffix */ if ((res = expand_dir(dir.s, &exp_dir, &dir_fd, command)) != 0) goto err_dir; if (isadirectory(exp_dir.s, name)) { if (exp_dir.len != 0 || name[0] != '\0') { Strbuf_append(&dir, name); if (dir.s[dir.len - 1] != '/') Strbuf_append1(&dir, '/'); Strbuf_terminate(&dir); if ((res = expand_dir(dir.s, &exp_dir, &dir_fd, command)) != 0) goto err_dir; if (word->len != 0 && word->s[word->len - 1] != '/') { Strbuf_append1(word, '/'); Strbuf_terminate(word); } name[0] = '\0'; } } #endif if ((res = expand_dir(dir.s, &exp_dir, &dir_fd, command)) != 0) goto err_dir; break; case TW_TEXT: flags |= TW_TEXT_CHK; /*FALLTHROUGH*/ case TW_FILE: if ((res = expand_dir(dir.s, &exp_dir, &dir_fd, command)) != 0) goto err_dir; break; case TW_PATH | TW_TEXT: case TW_PATH | TW_FILE: case TW_PATH | TW_DIRECTORY: case TW_PATH | TW_COMMAND: if ((dir_fd = opendir(short2str(exp_dir.s))) == NULL) { if (command == RECOGNIZE) xprintf("\n"); xprintf("%S: %s", exp_dir.s, strerror(errno)); if (command != RECOGNIZE) xprintf("\n"); NeedsRedraw = 1; res = -1; goto err_dir; } if (exp_dir.len != 0 && exp_dir.s[exp_dir.len - 1] != '/') { Strbuf_append1(&exp_dir, '/'); Strbuf_terminate(&exp_dir); } looking &= ~TW_PATH; switch (looking) { case TW_TEXT: flags |= TW_TEXT_CHK; break; case TW_FILE: break; case TW_DIRECTORY: flags |= TW_DIR_CHK; break; case TW_COMMAND: xfree(name); target = name = Strsave(word->s); /* so it can match things */ break; default: abort(); /* Cannot happen */ break; } break; case TW_LOGNAME: user_name = word->s + 1; goto do_user; /*FALLTHROUGH*/ case TW_USER: user_name = word->s; do_user: /* * Check if the spelling was already correct * From: Rob McMahon */ if (command == SPELL && xgetpwnam(short2str(user_name)) != NULL) { #ifdef YPBUGS fix_yp_bugs(); #endif /* YPBUGS */ res = 0; goto err_dir; } xfree(name); target = name = Strsave(user_name); break; case TW_COMMAND: case TW_VARLIST: case TW_WORDLIST: target = name = Strsave(word->s); /* so it can match things */ break; default: xprintf(CGETS(30, 9, "\n%s internal error: I don't know what I'm looking for!\n"), progname); NeedsRedraw = 1; res = -1; goto err_dir; } cleanup_push(&exp_name, Strbuf_cleanup); numitems = tw_collect(command, looking, &exp_dir, &exp_name, target, pat, flags, dir_fd); if (numitems == -1) goto end; switch (command) { case RECOGNIZE: case RECOGNIZE_ALL: case RECOGNIZE_SCROLL: if (numitems <= 0) break; Strbuf_terminate(&exp_name); tw_fixword(looking, word, dir.s, exp_name.s); if (!match_unique_match && is_set(STRaddsuffix) && numitems == 1) { switch (suf) { case 0: /* Automatic suffix */ Strbuf_append1(word, tw_suffix(looking, word, exp_dir.s, exp_name.s)); break; case CHAR_ERR: /* No suffix */ break; default: /* completion specified suffix */ Strbuf_append1(word, suf); break; } Strbuf_terminate(word); } break; case LIST: tw_list_items(looking, numitems, list_max); tw_item_free(); break; case SPELL: Strbuf_terminate(&exp_name); tw_fixword(looking, word, dir.s, exp_name.s); break; default: xprintf("Bad tw_command\n"); numitems = 0; } end: res = numitems; err_dir: cleanup_until(&dir); return res; } /* end t_search */ /* extract_dir_and_name(): * parse full path in file into 2 parts: directory and file names * Should leave final slash (/) at end of dir. */ static void extract_dir_and_name(const Char *path, struct Strbuf *dir, Char **name) { Char *p; p = Strrchr(path, '/'); #ifdef WINNT_NATIVE if (p == NULL) p = Strrchr(path, ':'); #endif /* WINNT_NATIVE */ if (p == NULL) *name = Strsave(path); else { p++; *name = Strsave(p); Strbuf_appendn(dir, path, p - path); } Strbuf_terminate(dir); } /* end extract_dir_and_name */ /* dollar(): * expand "/$old1/$old2/old3/" * to "/value_of_old1/value_of_old2/old3/" */ Char * dollar(const Char *old) { struct Strbuf buf = Strbuf_INIT; while (*old) { if (*old != '$') Strbuf_append1(&buf, *old++); else { if (expdollar(&buf, &old, QUOTE) == 0) { xfree(buf.s); return NULL; } } } return Strbuf_finish(&buf); } /* end dollar */ /* tilde(): * expand ~person/foo to home_directory_of_person/foo * or = to */ static int tilde(struct Strbuf *new, Char *old) { Char *o, *p; new->len = 0; switch (old[0]) { case '~': { Char *name, *home; old++; for (o = old; *o && *o != '/'; o++) continue; name = Strnsave(old, o - old); home = gethdir(name); xfree(name); if (home == NULL) goto err; Strbuf_append(new, home); xfree(home); /* If the home directory expands to "/", we do * not want to create "//" by appending a slash from o. */ if (new->s[0] == '/' && new->len == 1 && *o == '/') ++o; Strbuf_append(new, o); break; } case '=': if ((p = globequal(old)) == NULL) goto err; if (p != old) { Strbuf_append(new, p); xfree(p); break; } /*FALLTHROUGH*/ default: Strbuf_append(new, old); break; } Strbuf_terminate(new); return 0; err: Strbuf_terminate(new); return -1; } /* end tilde */ /* expand_dir(): * Open the directory given, expanding ~user and $var * Optionally normalize the path given */ static int expand_dir(const Char *dir, struct Strbuf *edir, DIR **dfd, COMMAND cmd) { Char *nd = NULL; Char *tdir; tdir = dollar(dir); cleanup_push(tdir, xfree); if (tdir == NULL || (tilde(edir, tdir) != 0) || !(nd = dnormalize(edir->len ? edir->s : STRdot, symlinks == SYM_IGNORE || symlinks == SYM_EXPAND)) || ((*dfd = opendir(short2str(nd))) == NULL)) { xfree(nd); if (cmd == SPELL || SearchNoDirErr) { cleanup_until(tdir); return (-2); } /* * From: Amos Shapira * Print a better message when completion fails */ xprintf("\n%S %s\n", edir->len ? edir->s : (tdir ? tdir : dir), (errno == ENOTDIR ? CGETS(30, 10, "not a directory") : (errno == ENOENT ? CGETS(30, 11, "not found") : CGETS(30, 12, "unreadable")))); NeedsRedraw = 1; cleanup_until(tdir); return (-1); } cleanup_until(tdir); if (nd) { if (*dir != '\0') { int slash; /* * Copy and append a / if there was one */ slash = edir->len != 0 && edir->s[edir->len - 1] == '/'; edir->len = 0; Strbuf_append(edir, nd); if (slash != 0 && edir->s[edir->len - 1] != '/') Strbuf_append1(edir, '/'); Strbuf_terminate(edir); } xfree(nd); } return 0; } /* end expand_dir */ /* nostat(): * Returns true if the directory should not be stat'd, * false otherwise. * This way, things won't grind to a halt when you complete in /afs * or very large directories. */ static int nostat(Char *dir) { struct varent *vp; Char **cp; if ((vp = adrof(STRnostat)) == NULL || (cp = vp->vec) == NULL) return FALSE; for (; *cp != NULL; cp++) { if (Strcmp(*cp, STRstar) == 0) return TRUE; if (Gmatch(dir, *cp)) return TRUE; } return FALSE; } /* end nostat */ /* filetype(): * Return a character that signifies a filetype * symbology from 4.3 ls command. */ static Char filetype(Char *dir, Char *file) { if (dir) { Char *path; char *ptr; struct stat statb; if (nostat(dir)) return(' '); path = Strspl(dir, file); ptr = short2str(path); xfree(path); if (lstat(ptr, &statb) != -1) { #ifdef S_ISLNK if (S_ISLNK(statb.st_mode)) { /* Symbolic link */ if (adrof(STRlistlinks)) { if (stat(ptr, &statb) == -1) return ('&'); else if (S_ISDIR(statb.st_mode)) return ('>'); else return ('@'); } else return ('@'); } #endif #ifdef S_ISSOCK if (S_ISSOCK(statb.st_mode)) /* Socket */ return ('='); #endif #ifdef S_ISFIFO if (S_ISFIFO(statb.st_mode)) /* Named Pipe */ return ('|'); #endif #ifdef S_ISHIDDEN if (S_ISHIDDEN(statb.st_mode)) /* Hidden Directory [aix] */ return ('+'); #endif #ifdef S_ISCDF { struct stat hpstatb; char *p2; p2 = strspl(ptr, "+"); /* Must append a '+' and re-stat(). */ if ((stat(p2, &hpstatb) != -1) && S_ISCDF(hpstatb.st_mode)) { xfree(p2); return ('+'); /* Context Dependent Files [hpux] */ } xfree(p2); } #endif #ifdef S_ISNWK if (S_ISNWK(statb.st_mode)) /* Network Special [hpux] */ return (':'); #endif #ifdef S_ISCHR if (S_ISCHR(statb.st_mode)) /* char device */ return ('%'); #endif #ifdef S_ISBLK if (S_ISBLK(statb.st_mode)) /* block device */ return ('#'); #endif #ifdef S_ISDIR if (S_ISDIR(statb.st_mode)) /* normal Directory */ return ('/'); #endif if (statb.st_mode & (S_IXUSR|S_IXGRP|S_IXOTH)) return ('*'); } } return (' '); } /* end filetype */ /* isadirectory(): * Return trus if the file is a directory */ static int isadirectory(const Char *dir, const Char *file) /* return 1 if dir/file is a directory */ /* uses stat rather than lstat to get dest. */ { if (dir) { Char *path; char *cpath; struct stat statb; path = Strspl(dir, file); cpath = short2str(path); xfree(path); if (stat(cpath, &statb) >= 0) { /* resolve through symlink */ #ifdef S_ISSOCK if (S_ISSOCK(statb.st_mode)) /* Socket */ return 0; #endif #ifdef S_ISFIFO if (S_ISFIFO(statb.st_mode)) /* Named Pipe */ return 0; #endif if (S_ISDIR(statb.st_mode)) /* normal Directory */ return 1; } } return 0; } /* end isadirectory */ /* find_rows(): * Return how many rows needed to print sorted down columns */ static int find_rows(Char *items[], int count, int no_file_suffix) { int i, columns, rows; unsigned int maxwidth = 0; for (i = 0; i < count; i++) /* find widest string */ maxwidth = max(maxwidth, (unsigned int) Strlen(items[i])); maxwidth += no_file_suffix ? 1 : 2; /* for the file tag and space */ columns = (TermH + 1) / maxwidth; /* PWP: terminal size change */ if (!columns) columns = 1; rows = (count + (columns - 1)) / columns; return rows; } /* end rows_needed_by_print_by_column */ /* print_by_column(): * Print sorted down columns or across columns when the first * word of $listflags shell variable contains 'x'. * */ void print_by_column(Char *dir, Char *items[], int count, int no_file_suffix) { int i, r, c, columns, rows; size_t w; unsigned int wx, maxwidth = 0; Char *val; int across; lbuffed = 0; /* turn off line buffering */ across = ((val = varval(STRlistflags)) != STRNULL) && (Strchr(val, 'x') != NULL); for (i = 0; i < count; i++) { /* find widest string */ maxwidth = max(maxwidth, (unsigned int) NLSStringWidth(items[i])); } maxwidth += no_file_suffix ? 1 : 2; /* for the file tag and space */ columns = TermH / maxwidth; /* PWP: terminal size change */ if (!columns || !isatty(didfds ? 1 : SHOUT)) columns = 1; rows = (count + (columns - 1)) / columns; i = -1; for (r = 0; r < rows; r++) { for (c = 0; c < columns; c++) { i = across ? (i + 1) : (c * rows + r); if (i < count) { wx = 0; w = Strlen(items[i]); #ifdef COLOR_LS_F if (no_file_suffix) { /* Print the command name */ Char f = items[i][w - 1]; items[i][w - 1] = 0; print_with_color(items[i], w - 1, f); items[i][w - 1] = f; } else { /* Print filename followed by '/' or '*' or ' ' */ print_with_color(items[i], w, filetype(dir, items[i])); wx++; } #else /* ifndef COLOR_LS_F */ if (no_file_suffix) { /* Print the command name */ xprintf("%S", items[i]); } else { /* Print filename followed by '/' or '*' or ' ' */ xprintf("%-S%c", items[i], filetype(dir, items[i])); wx++; } #endif /* COLOR_LS_F */ if (c < (columns - 1)) { /* Not last column? */ w = NLSStringWidth(items[i]) + wx; for (; w < maxwidth; w++) xputchar(' '); } } else if (across) break; } if (Tty_raw_mode) xputchar('\r'); xputchar('\n'); } lbuffed = 1; /* turn back on line buffering */ flush(); } /* end print_by_column */ /* StrQcmp(): * Compare strings ignoring the quoting chars */ int StrQcmp(const Char *str1, const Char *str2) { for (; *str1 && samecase(*str1 & TRIM) == samecase(*str2 & TRIM); str1++, str2++) continue; /* * The following case analysis is necessary so that characters which look * negative collate low against normal characters but high against the * end-of-string NUL. */ if (*str1 == '\0' && *str2 == '\0') return (0); else if (*str1 == '\0') return (-1); else if (*str2 == '\0') return (1); else return ((*str1 & TRIM) - (*str2 & TRIM)); } /* end StrQcmp */ /* fcompare(): * Comparison routine for qsort, (Char **, Char **) */ int fcompare(const void *xfile1, const void *xfile2) { const Char *const *file1 = xfile1, *const *file2 = xfile2; return collate(*file1, *file2); } /* end fcompare */ /* catn(): * Concatenate src onto tail of des. * Des is a string whose maximum length is count. * Always null terminate. */ void catn(Char *des, const Char *src, int count) { while (*des && --count > 0) des++; while (--count > 0) if ((*des++ = *src++) == 0) return; *des = '\0'; } /* end catn */ /* copyn(): * like strncpy but always leave room for trailing \0 * and always null terminate. */ void copyn(Char *des, const Char *src, size_t count) { while (--count != 0) if ((*des++ = *src++) == 0) return; *des = '\0'; } /* end copyn */ /* tgetenv(): * like it's normal string counter-part */ Char * tgetenv(Char *str) { Char **var; size_t len; int res; len = Strlen(str); /* Search the STR_environ for the entry matching str. */ for (var = STR_environ; var != NULL && *var != NULL; var++) if (Strlen(*var) >= len && (*var)[len] == '=') { /* Temporarily terminate the string so we can copy the variable name. */ (*var)[len] = '\0'; res = StrQcmp(*var, str); /* Restore the '=' and return a pointer to the value of the environment variable. */ (*var)[len] = '='; if (res == 0) return (&((*var)[len + 1])); } return (NULL); } /* end tgetenv */ struct scroll_tab_list *scroll_tab = 0; static void add_scroll_tab(Char *item) { struct scroll_tab_list *new_scroll; new_scroll = xmalloc(sizeof(struct scroll_tab_list)); new_scroll->element = Strsave(item); new_scroll->next = scroll_tab; scroll_tab = new_scroll; } static void choose_scroll_tab(struct Strbuf *exp_name, int cnt) { struct scroll_tab_list *loop; int tmp = cnt; Char **ptr; ptr = xmalloc(sizeof(Char *) * cnt); cleanup_push(ptr, xfree); - for(loop = scroll_tab; loop && (tmp >= 0); loop = loop->next) + for (loop = scroll_tab; loop && (tmp >= 0); loop = loop->next) ptr[--tmp] = loop->element; qsort(ptr, cnt, sizeof(Char *), fcompare); exp_name->len = 0; Strbuf_append(exp_name, ptr[curchoice]); Strbuf_terminate(exp_name); cleanup_until(ptr); } static void free_scroll_tab(void) { struct scroll_tab_list *loop; - while(scroll_tab) { + while (scroll_tab) { loop = scroll_tab; scroll_tab = scroll_tab->next; xfree(loop->element); xfree(loop); } }