home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume35 / zsh / part19 < prev    next >
Text File  |  1993-02-20  |  56KB  |  2,243 lines

  1. Newsgroups: comp.sources.misc
  2. From: zsh-list@cs.uow.edu.au (The Zsh Mailing List)
  3. Subject: v35i069:  zsh - The Z Shell, version 2.3.1, Part19/22
  4. Message-ID: <1993Feb20.212847.29442@sparky.imd.sterling.com>
  5. X-Md4-Signature: 55c2db3c0602f107f9dd822082b6c794
  6. Date: Sat, 20 Feb 1993 21:28:47 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: zsh-list@cs.uow.edu.au (The Zsh Mailing List)
  10. Posting-number: Volume 35, Issue 69
  11. Archive-name: zsh/part19
  12. Environment: UNIX
  13. Supersedes: zsh2.2: Volume 29, Issue 97-113
  14.  
  15. #! /bin/sh
  16. # This is a shell archive.  Remove anything before this line, then feed it
  17. # into a shell via "sh file" or similar.  To overwrite existing files,
  18. # type "sh file -c".
  19. # The tool that generated this appeared in the comp.sources.unix newsgroup;
  20. # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
  21. # Contents:  doc/intro.troff.02 help/setopt src/math.c src/table.c
  22. #   src/zle_hist.c
  23. # Wrapped by mattson@odin on Sat Feb  6 14:41:55 1993
  24. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  25. echo If this archive is complete, you will see the following message:
  26. echo '          "shar: End of archive 19 (of 22)."'
  27. if test -f 'doc/intro.troff.02' -a "${1}" != "-c" ; then 
  28.   echo shar: Will not clobber existing file \"'doc/intro.troff.02'\"
  29. else
  30.   echo shar: Extracting \"'doc/intro.troff.02'\" \(9993 characters\)
  31.   sed "s/^X//" >'doc/intro.troff.02' <<'END_OF_FILE'
  32. XIn general, parameters with names in all lowercase are arrays;
  33. Xassignments to them take the form:
  34. X.Ds
  35. X\fIname\fR\fC=(\fR \fIelem\fR ...\ \fC)\fR
  36. X.De
  37. XParameters with names in all uppercase are strings.  If there is
  38. Xboth an array and a string version of the same parameter, the
  39. Xstring version is a colon-separated list, like \fBPATH\fR.
  40. X.PP
  41. X\fBHISTFILE\fR is the name of the history file, where the history
  42. Xis saved when a shell exits.
  43. X.Ds
  44. X% zsh
  45. Xphoenix% HISTFILE=/tmp/history
  46. Xphoenix% SAVEHIST=20
  47. Xphoenix% echo foo
  48. Xfoo
  49. Xphoenix% date
  50. XFri May 24 05:39:35 EDT 1991
  51. Xphoenix% uptime
  52. X  5:39am  up 4 days, 20:02,  40 users,  load average: 2.30, 2.20, 2.00
  53. Xphoenix% exit
  54. X% cat /tmp/history
  55. XHISTFILE=/tmp/history
  56. XSAVEHIST=20
  57. Xecho foo
  58. Xdate
  59. Xuptime
  60. Xexit
  61. X% HISTSIZE=3
  62. X% history
  63. X   28  rm /tmp/history
  64. X   29  HISTSIZE=3
  65. X   30  history
  66. X.De
  67. X.PP
  68. XIn zsh, if you say
  69. X.Ds
  70. X% >file
  71. X.DZ
  72. Xthe command \fCcat\fR is normally assumed:
  73. X.Ds
  74. X% >file
  75. Xfoo!    
  76. X^D
  77. X% cat file
  78. Xfoo!
  79. X.DZ
  80. XThus, you can view a file simply by typing:
  81. X.Ds
  82. X% <file
  83. Xfoo!
  84. X.DZ
  85. XHowever, this is not csh or sh compatible.  To correct this,
  86. Xchange the value of the parameter \fBNULLCMD\fR,
  87. Xwhich is \fCcat\fR by default.
  88. X.Ds
  89. X% NULLCMD=:
  90. X% >file
  91. X% ls -l file
  92. X-rw-r--r--  1 pfalstad        0 May 24 05:41 file
  93. X.DZ
  94. XIf \fCNULLCMD\fR is unset, the shell reports an error if no
  95. Xcommand is specified (like csh).
  96. X.Ds
  97. X% unset NULLCMD
  98. X% >file
  99. Xzsh: redirection with no command
  100. X.De
  101. XActually, \fBREADNULLCMD\fR is used whenever you have a null command
  102. Xreading input from a single file.  Thus, you can set \fBREADNULLCMD\fP
  103. Xto \fCmore\fP or \fCless\fP rather than \fCcat\fP.  Also, if you
  104. Xset \fBNULLCMD\fR to \fC:\fP for sh compatibility, you can still read
  105. Xfiles with \fC< file\fR if you leave \fBREADNULLCMD\fP set to \fCmore\fP.
  106. X.SH
  107. XPrompting
  108. X.PP
  109. XThe default prompt for zsh is:
  110. X.Ds
  111. Xphoenix% echo $PROMPT
  112. X%m%# 
  113. X.De
  114. XThe \fC%m\fR stands for the short form of the current hostname,
  115. Xand the \fC%#\fR stands for a \fC%\fR or a \fC#\fR, depending on whether
  116. Xthe shell is running as root or not.
  117. Xzsh supports many other control sequences
  118. Xin the \fBPROMPT\fR variable.
  119. X.Ds
  120. X% PROMPT='%/> '
  121. X/u/pfalstad/etc/TeX/zsh>
  122. X
  123. X% PROMPT='%~> '   
  124. X~/etc/TeX/zsh> 
  125. X
  126. X% PROMPT='%h %~> '
  127. X6 ~/etc/TeX/zsh> 
  128. X.DZ
  129. X\fC%h\fR represents the number of current history event.
  130. X.Ds
  131. X% PROMPT='%h %~ %M> '
  132. X10 ~/etc/TeX/zsh apple-gunkies.gnu.ai.mit.edu> 
  133. X
  134. X% PROMPT='%h %~ %m> '
  135. X11 ~/etc/TeX/zsh apple-gunkies> 
  136. X
  137. X% PROMPT='%h %t> '
  138. X12 6:11am> 
  139. X
  140. X% PROMPT='%n %w tty%l>'
  141. Xpfalstad Fri 24 ttyp0>
  142. X.DZ
  143. XAlso available is the \fBRPROMPT\fR parameter.
  144. XIf this is set, the shell puts a prompt on the \fIright\fR side
  145. Xof the screen.
  146. X.Ds
  147. X% RPROMPT='%t'
  148. X%                                                      6:14am
  149. X
  150. X% RPROMPT='%~'
  151. X%                                               ~/etc/TeX/zsh
  152. X
  153. X% PROMPT='%l %T %m[%h] ' RPROMPT=' %~'
  154. Xp0 6:15 phoenix[5]                              ~/etc/TeX/zsh
  155. X.DZ
  156. XThese special escape sequences can also be used with the
  157. X\fC-P\fR option to \fCprint\fR:
  158. X.Ds
  159. X% print -P %h tty%l
  160. X15 ttyp1
  161. X.De
  162. X.PP
  163. XThe \fBPOSTEDIT\fR parameter is printed whenever the editor exits.
  164. XThis can be useful for termcap tricks.  To highlight the prompt
  165. Xand command line while leaving command output unhighlighted, try this:
  166. X.Ds
  167. X% POSTEDIT=`echotc se`
  168. X% PROMPT='%S%% '
  169. X.De
  170. X.SH
  171. XLogin/logout watching
  172. X.PP
  173. XYou can specify login or logout events to monitor
  174. Xby setting the \fBwatch\fR variable.
  175. XNormally, this is done by specifying a list of usernames.
  176. X.Ds
  177. X% watch=( pfalstad subbarao sukthnkr egsirer )
  178. X.DZ
  179. XThe \fClog\fR command reports all people logged in
  180. Xthat you are watching for.
  181. X.Ds
  182. X% log
  183. Xpfalstad has logged on p0 from mickey.
  184. Xpfalstad has logged on p5 from mickey.
  185. X% \fR...\fC
  186. Xsubbarao has logged on p8 from phoenix.
  187. X% \fR...\fC
  188. Xsubbarao has logged off p8 from phoenix.
  189. X% \fR...\fC
  190. Xsukthnkr has logged on p8 from dew.
  191. X% \fR...\fC
  192. Xsukthnkr has logged off p8 from dew.
  193. X.DZ
  194. XIf you specify hostnames with an \fC@\fR prepended,
  195. Xthe shell will watch for all users logging in from
  196. Xthe specified host.
  197. X.Ds
  198. X% watch=( @mickey @phoenix )
  199. X% log
  200. Xdjthongs has logged on q2 from phoenix.
  201. Xpfalstad has logged on p0 from mickey.
  202. Xpfalstad has logged on p5 from mickey.
  203. X.DZ
  204. XIf you give a tty name with a \fC%\fR prepended, the shell
  205. Xwill watch for all users logging in on that tty.
  206. X.Ds
  207. X% watch=( %ttyp0 %console )
  208. X% log
  209. Xroot has logged on console from .
  210. Xpfalstad has logged on p0 from mickey.
  211. X.DZ
  212. XThe format of the reports may also be changed.
  213. X.Ds
  214. X% watch=( pfalstad gettes eps djthongs jcorr bdavis )
  215. X% log
  216. Xjcorr has logged on tf from 128.112.176.3:0.
  217. Xjcorr has logged on r0 from 128.112.176.3:0.
  218. Xgettes has logged on p4 from yo:0.0.
  219. Xdjthongs has logged on pe from grumpy:0.0.
  220. Xdjthongs has logged on q2 from phoenix.
  221. Xbdavis has logged on qd from BRUNO.
  222. Xeps has logged on p3 from csx30:0.0.
  223. Xpfalstad has logged on p0 from mickey.
  224. Xpfalstad has logged on p5 from mickey.
  225. X% WATCHFMT='%n on tty%l from %M'
  226. X% log
  227. Xjcorr on ttytf from 128.112.176.3:0.
  228. Xjcorr on ttyr0 from 128.112.176.3:0.
  229. Xgettes on ttyp4 from yo:0.0
  230. Xdjthongs on ttype from grumpy:0.0
  231. Xdjthongs on ttyq2 from phoenix.Princeto
  232. Xbdavis on ttyqd from BRUNO.pppl.gov
  233. Xeps on ttyp3 from csx30:0.0
  234. Xpfalstad on ttyp0 from mickey.Princeton
  235. Xpfalstad on ttyp5 from mickey.Princeton
  236. X% WATCHFMT='%n fm %m'
  237. X% log
  238. Xjcorr fm 128.112.176.3:0
  239. Xjcorr fm 128.112.176.3:0
  240. Xgettes fm yo:0.0
  241. Xdjthongs fm grumpy:0.0
  242. Xdjthongs fm phoenix
  243. Xbdavis fm BRUNO
  244. Xeps fm csx30:0.0
  245. Xpfalstad fm mickey
  246. Xpfalstad fm mickey
  247. X% WATCHFMT='%n %a at %t %w.'
  248. X% log
  249. Xjcorr logged on at 3:15pm Mon 20.
  250. Xjcorr logged on at 3:16pm Wed 22.
  251. Xgettes logged on at 6:54pm Wed 22.
  252. Xdjthongs logged on at 7:19am Thu 23.
  253. Xdjthongs logged on at 7:20am Thu 23.
  254. Xbdavis logged on at 12:40pm Thu 23.
  255. Xeps logged on at 4:19pm Thu 23.
  256. Xpfalstad logged on at 3:39am Fri 24.
  257. Xpfalstad logged on at 3:42am Fri 24.
  258. X.DZ
  259. XIf you have a \fC.friends\fR file in your home directory,
  260. Xa convenient way to make zsh watch for all your friends
  261. Xis to do this:
  262. X.Ds
  263. X% watch=( $(< ~/.friends) )
  264. X% echo $watch
  265. Xsubbarao maruchck root sukthnkr \fR...
  266. X.De
  267. XIf watch is set to \fCall\fR, then all users logging in or out
  268. Xwill be reported.
  269. X.SH
  270. XOptions
  271. X.PP
  272. XSome options have already been mentioned; here are a few more:
  273. X.Ds
  274. X% cd /
  275. X% setopt autocd
  276. X% bin
  277. X% pwd
  278. X/bin
  279. X% ../etc
  280. X% pwd
  281. X/etc
  282. X.DZ
  283. XUsing the \fIAUTOCD\fR option, you can simply type the name
  284. Xof a directory, and it will become the current directory.
  285. X.Ds
  286. X% setopt cdablevars
  287. X% foo=/tmp
  288. X% cd foo
  289. X/tmp
  290. X.De
  291. XWith \fICDABLEVARS\fR, if the argument to \fCcd\fR is the name of a
  292. Xparameter whose value is a valid directory, it will become
  293. Xthe current directory.
  294. X.PP
  295. X\fICORRECT\fR turns on spelling correction for commands,
  296. Xand the \fICORRECTALL\fR option turns on spelling correction
  297. Xfor all arguments.
  298. X.Ds
  299. X% setopt correct
  300. X% sl
  301. Xzsh: correct `sl' to `ls' [nyae]? y
  302. X% setopt correctall
  303. X% ls x.v11r4
  304. Xzsh: correct `x.v11r4' to `X.V11R4' [nyae]? n
  305. X/usr/princton/src/x.v11r4 not found
  306. X% ls /etc/paswd
  307. Xzsh: correct to `/etc/paswd' to `/etc/passwd' [nyae]? y
  308. X/etc/passwd
  309. X.De
  310. XIf you press \fCy\fR
  311. Xwhen the shell asks you if you want to correct a word, it will
  312. Xbe corrected.  If you press \fCn\fR, it will be left alone.
  313. XPressing \fCa\fR aborts the command, and pressing \fCe\fR brings the line
  314. Xup for editing again, in case you agree the word is spelled wrong
  315. Xbut you don't like the correction.
  316. X.PP
  317. XNormally, a quoted expression may contain a newline:
  318. X.Ds
  319. X% echo '
  320. X> foo
  321. X> '
  322. X
  323. Xfoo
  324. X
  325. X%
  326. X.DZ
  327. XWith \fICSHJUNKIEQUOTES\fR set, this is illegal, as it is
  328. Xin csh.
  329. X.Ds
  330. X% setopt cshjunkiequotes
  331. X% ls 'foo
  332. Xzsh: unmatched '
  333. X.DZ
  334. X\fIGLOBDOTS\fR lets files beginning with a \fC.\fR be matched without
  335. Xexplicitly specifying the dot.
  336. X.Ds
  337. X% ls -d *x*
  338. XMailboxes
  339. X% setopt globdots
  340. X% ls -d *x*
  341. X\&.exrc         .pnewsexpert  .xserverrc
  342. X\&.mushexpert   .xinitrc      Mailboxes
  343. X.DZ
  344. X\fIHISTIGNOREDUPS\fR prevents the current line from being
  345. Xsaved in the history if it is the same as the previous one;
  346. X\fIHISTIGNORESPACE\fR prevents the current line from being
  347. Xsaved if it begins with a space.
  348. X.Ds
  349. X% PROMPT='%h> '
  350. X39> setopt histignoredups
  351. X40> echo foo
  352. Xfoo
  353. X41> echo foo
  354. Xfoo
  355. X41> echo foo
  356. Xfoo
  357. X41> echo bar
  358. Xbar
  359. X42> setopt histignorespace
  360. X43>  echo foo
  361. Xfoo
  362. X43>  echo fubar
  363. Xfubar
  364. X43>  echo fubar
  365. Xfubar
  366. X.DZ
  367. X\fIIGNOREBRACES\fR turns off csh-style brace expansion.
  368. X.Ds
  369. X% echo x{y{z,a},{b,c}d}e
  370. Xxyze xyae xbde xcde
  371. X% setopt ignorebraces
  372. X% echo x{y{z,a},{b,c}d}e
  373. Xx{y{z,a},{b,c}d}e
  374. X.DZ
  375. X\fIIGNOREEOF\fR forces the user to type \fCexit\fR or \fClogout\fR,
  376. Xinstead of just pressing \fI^D\fP.
  377. X.Ds
  378. X% setopt ignoreeof
  379. X% ^D
  380. Xzsh: use 'exit' to exit.
  381. X.DZ
  382. X\fIINTERACTIVECOMMENTS\fR turns on interactive comments;
  383. Xcomments begin with a \fC#\fR.
  384. X.Ds
  385. X% setopt interactivecomments
  386. X% date # this is a comment
  387. XFri May 24 06:54:14 EDT 1991
  388. X.DZ
  389. X\fINOCLOBBER\fR prevents you from accidentally
  390. Xoverwriting an existing file.
  391. X.Ds
  392. X% setopt noclobber
  393. X% cat /dev/null >~/.zshrc
  394. Xzsh: file exists: /u/pfalstad/.zshrc
  395. X.DZ
  396. XIf you really do want to clobber a file, you can use the
  397. X\fC>!\fR operator.
  398. XTo make things easier in this case, the \fC>\fR is stored in
  399. Xthe history list as a \fC>!\fR:
  400. X.Ds
  401. X% cat /dev/null >! ~/.zshrc
  402. X% cat /etc/motd > ~/.zshrc
  403. Xzsh: file exists: /u/pfalstad/.zshrc
  404. X% !!
  405. Xcat /etc/motd >! ~/.zshrc
  406. X% \fR...
  407. X.DZ
  408. X\fIRCQUOTES\fR lets you use a more elegant method for including
  409. Xsingle quotes in a singly quoted string:
  410. X.Ds
  411. X% echo '"don'\e''t do that."'
  412. X"don't do that."
  413. X% echo '"don''t do that."'
  414. X"dont do that."
  415. X% setopt rcquotes
  416. X% echo '"don''t do that."'
  417. X"don't do that."
  418. X.De
  419. XFinally,
  420. X\fISUNKEYBOARDHACK\fR wins the award for the strangest option.
  421. XIf a line ends with \fC`\fR, and there are an odd number of them
  422. Xon the line, the shell will ignore the trailing \fC`\fR.  This
  423. Xis provided for keyboards whose RETURN key is too small,
  424. Xand too close to the \fC`\fR key.
  425. X.Ds
  426. X% setopt sunkeyboardhack
  427. X% date`
  428. XFri May 24 06:55:38 EDT 1991
  429. X.De
  430. X.SH
  431. XClosing Comments
  432. X.PP
  433. XI would be happy to receive mail
  434. Xif anyone has any tricks or ideas to add to this document, or
  435. Xif there are some points that could be made clearer or covered
  436. Xmore thoroughly.  Please notify me of any errors in this
  437. Xdocument.
  438. END_OF_FILE
  439.   if test 9993 -ne `wc -c <'doc/intro.troff.02'`; then
  440.     echo shar: \"'doc/intro.troff.02'\" unpacked with wrong size!
  441.   fi
  442.   # end of 'doc/intro.troff.02'
  443. fi
  444. if test -f 'help/setopt' -a "${1}" != "-c" ; then 
  445.   echo shar: Will not clobber existing file \"'help/setopt'\"
  446. else
  447.   echo shar: Extracting \"'help/setopt'\" \(11726 characters\)
  448.   sed "s/^X//" >'help/setopt' <<'END_OF_FILE'
  449. X     setopt [ +-options ] [ name ... ]
  450. X          Set the options for the shell.  All  options  specified
  451. X          either  with flags or by name are set.  If no arguments
  452. X          are supplied, the names of all  options  currently  set
  453. X          are  printed.   In option names, case is insignificant,
  454. X          and all underscore characters are ignored.
  455. X     unsetopt [ +-options ] [ name ... ]
  456. X          Unset the options for the shell.  All options specified
  457. X          either with flags or by name are unset.
  458. X
  459. X     The following options may be  set  upon  invocation  of  the
  460. X     shell, or with the set or setopt builtins:
  461. X          ALLEXPORT (-a)
  462. X               All parameters subsequently defined are  automati-
  463. X               cally exported.
  464. X          AUTO_CD (-J)
  465. X               If a command is not in the hash table,  and  there
  466. X               exists  an executable directory by that name, per-
  467. X               form the cd command to that directory.
  468. X          AUTOLIST (-9)
  469. X               Automatically list choices on an ambiguous comple-
  470. X               tion.
  471. X          AUTOMENU
  472. X               Automatically use menu completion if the  TAB  key
  473. X               is pressed repeatedly.
  474. X          AUTO_PUSHD (-N)
  475. X               Make cd act like pushd.
  476. X          AUTO_RESUME (-W)
  477. X               Treat single word simple commands without redirec-
  478. X               tion  as  candidates for resumption of an existing
  479. X               job.
  480. X          BGNICE (-6)
  481. X               Run all background jobs at a lower priority.  This
  482. X               option is set by default.
  483. X          BRACECCL
  484. X               Allow brace expansions of the form {a-zA-Z}, etc.
  485. X          CDABLEVARS (-T)
  486. X               If the argument to a cd command is  not  a  direc-
  487. X               tory,  but  a  parameter  exists  by the same name
  488. X               whose value begins with a /, try to change to  the
  489. X               directory specified by the parameter's value.
  490. X          CHASELINKS (-w)
  491. X               Resolve symbolic links to their true values.
  492. X          CORRECT (-0)
  493. X               Try to correct the spelling of commands.
  494. X          CORRECT_ALL (-O)
  495. X               Try to correct the spelling of all arguments in  a
  496. X               line.
  497. X          CSH_JUNKIE_LOOPS
  498. X               Allow loop bodies to take  the  form  "list;  end"
  499. X               instead of "do list; done".
  500. X          CSH_JUNKIE_QUOTES
  501. X               Complain if a quoted expression runs off  the  end
  502. X               of  a  line;  prevent quoted expressions from con-
  503. X               taining unescaped newlines.
  504. X          CSH_NULL_GLOB
  505. X               If  a  pattern  for  filename  generation  has  no
  506. X               matches,  delete  the  pattern  from  the argument
  507. X               list; do not report an error unless all  the  pat-
  508. X               terns  in  a  command  have no matches.  Overrides
  509. X               NULLGLOB.
  510. X          ERREXIT (-e)
  511. X               If a command has a non-zero exit  status,  execute
  512. X               the ERR trap, if set, and exit.
  513. X          EXTENDED_GLOB
  514. X               Treat the # and ^ characters as part  of  patterns
  515. X               for filename generation, etc.
  516. X          GLOB_COMPLETE
  517. X               Like MENU_COMPLETE, except that the  current  word
  518. X               is  expanded  using normal shell expansion instead
  519. X               of completion.  If no matches are found,  a  *  is
  520. X               added  to  the  end  of the word, and expansion is
  521. X               attempted again.
  522. X          GLOB_DOTS (-4)
  523. X               Do not require a leading . in  a  filename  to  be
  524. X               matched explicitly.
  525. X          HASH_CMDS
  526. X               Place the location of each  command  in  the  hash
  527. X               table  the  first  time  it  is executed.  If this
  528. X               option is unset, no path hashing will be  done  at
  529. X               all.
  530. X          HASH_DIRS
  531. X               Whenever a command is executed, hash the directory
  532. X               containing  it,  as  well  as all directories that
  533. X               occur earlier in  the  path.   Has  no  effect  if
  534. X               HASH_CMDS is unset.
  535. X          HASH_LIST_ALL
  536. X               Whenever a command completion is  attempted,  make
  537. X               sure  the  entire  command  path  is hashed first.
  538. X               This makes the first completion slower.
  539. X          HIST_IGNORE_DUPS (-h)
  540. X               Do not enter command lines into the  history  list
  541. X               if they are duplicates of the previous event.
  542. X          HIST_IGNORE_SPACE (-g)
  543. X               Do not enter command lines into the  history  list
  544. X               if they begin with a blank.
  545. X          HISTLIT (-j)
  546. X               Use literal (unparsed)  versions  of  the  history
  547. X               lines in the editor.
  548. X          HIST_NO_STORE
  549. X               Remove the history (fc -l) command from  the  his-
  550. X               tory when invoked.
  551. X          HIST_VERIFY
  552. X               Whenever the user enters a line with history  sub-
  553. X               stitution,   don't   execute  the  line  directly;
  554. X               instead, perform history substitution  and  reload
  555. X               the line into the editing buffer.
  556. X          IGNORE_BRACES (-I)
  557. X               Do not perform brace expansion.
  558. X          IGNOREEOF (-7)
  559. X               Do not exit on end-of-file.  Require  the  use  of
  560. X               exit or logout instead.
  561. X          INTERACTIVE (-i)
  562. X               This is an interactive shell.
  563. X          INTERACTIVE_COMMENTS (-k)
  564. X               Allow comments even in interactive shells.
  565. X          KSH_OPTION_PRINT
  566. X               Alters the way options settings are printed.
  567. X          LIST_TYPES (-X)
  568. X               When listing files that are possible  completions,
  569. X               show the type of each file with a trailing identi-
  570. X               fying mark.
  571. X          LOGIN (-l)
  572. X               This is a login shell.
  573. X          LONG_LIST_JOBS (-R)
  574. X               List jobs in the long format by default.
  575. X          MAIL_WARNING (-U)
  576. X               Print a warning message if a mail  file  has  been
  577. X               accessed since the shell last checked.
  578. X          MARKDIRS (-8)
  579. X               Append a trailing / to all directory names result-
  580. X               ing from filename generation (globbing).
  581. X          MENU_COMPLETE (-Y)
  582. X               On an ambiguous  completion,  instead  of  listing
  583. X               possibilities,  insert the first match.  Then when
  584. X               completion is requested again,  remove  the  first
  585. X               match  and  insert  the  second  match, etc.  When
  586. X               there are no more matches, go back  to  the  first
  587. X               one  again.   reverse-menu-complete may be used to
  588. X               loop through the list in the other direction.
  589. X          MENU_COMPLETE_BEEP
  590. X               Beep on an ambiguous menu completion.
  591. X          MONITOR (-m)
  592. X               Allow job control.  Set by default in  interactive
  593. X               shells.
  594. X          NO_BAD_PATTERN (-2)
  595. X               If a pattern  for  filename  generation  is  badly
  596. X               formed,  leave  it  unchanged in the argument list
  597. X               instead of printing an error.
  598. X          NO_BANG_HIST (-K)
  599. X               Do not perform textual history  substitution.   Do
  600. X               not treat the ! character specially.
  601. X          NOBEEP (-B)
  602. X               Do not beep.
  603. X          NO_CLOBBER (-1)
  604. X               Prevents > redirection  from  truncating  existing
  605. X               files.  >! may be used to truncate a file instead.
  606. X               Also prevents >> from creating files.  >>! may  be
  607. X               used instead.
  608. X          NO_EQUALS
  609. X               Don't perform = filename substitution.
  610. X          NOEXEC (-n)
  611. X               Read commands and check them  for  syntax  errors,
  612. X               but do not execute them.
  613. X          NOGLOB (-F)
  614. X               Disable filename generation.
  615. X          NO_HIST_BEEP
  616. X               Don't beep when an attempt is  made  to  access  a
  617. X               history entry which isn't there.
  618. X          NOHUP
  619. X               Don't send the HUP signal to running jobs when the
  620. X               shell exits.
  621. X          NO_LIST_BEEP
  622. X               Don't beep on an ambiguous completion.
  623. X          NO_NOMATCH (-3)
  624. X               If  a  pattern  for  filename  generation  has  no
  625. X               matches,  leave  it unchanged in the argument list
  626. X               instead of printing an error.
  627. X          NO_PROMPT_CR (-V)
  628. X               Don't print a carriage return just before printing
  629. X               a prompt in the line editor.
  630. X          NO_RCS (-f)
  631. X               Do not source the .zshenv, .zshrc, .zlogin,  .zlo-
  632. X               gout, or .zprofile files.
  633. X          NO_SHORT_LOOPS
  634. X               Disallow the short forms of for, select,  if,  and
  635. X               function constructs.
  636. X          NOTIFY (-5)
  637. X               Report the status of background jobs  immediately,
  638. X               rather  than  waiting until just before printing a
  639. X               prompt.
  640. X          NOUNSET (-u)
  641. X               Treat unset parameters as an error when substitut-
  642. X               ing.
  643. X          NULLGLOB (-G)
  644. X               If  a  pattern  for  filename  generation  has  no
  645. X               matches, delete the pattern from the argument list
  646. X               instead  of   reporting   an   error.    Overrides
  647. X               NO_NOMATCH.
  648. X          NUMERICGLOBSORT
  649. X               If numeric filenames are  matched  by  a  filename
  650. X               generation pattern, sort the filenames numerically
  651. X               rather than lexicographically.
  652. X          OVERSTRIKE
  653. X               Start up the line editor in overstrike mode.
  654. X          PATH_DIRS (-Q)
  655. X               Perform a path search even on command  names  with
  656. X               slashes  in  them.  Thus if "/usr/local/bin" is in
  657. X               the user's path, and  he  types  "X11/xinit",  the
  658. X               command  "/usr/local/bin/X11/xinit"  will  be exe-
  659. X               cuted (assuming it exists).
  660. X          PRINT_EXIT_VALUE (-C)
  661. X               Print the exit value  of  programs  with  non-zero
  662. X               exit status.
  663. X          PUSHD_IGNORE_DUPS
  664. X               Don't push multiple copies of the  same  directory
  665. X               onto the directory stack.
  666. X          PUSHD_MINUS
  667. X               See popd below.
  668. X          PUSHD_SILENT (-E)
  669. X               Do not print the directory stack  after  pushd  or
  670. X               popd.
  671. X          PUSHD_TO_HOME (-D)
  672. X               Have pushd with no arguments act like pushd $HOME.
  673. X          RC_EXPAND_PARAM (-P)
  674. X               See Parameter Expansion.
  675. X          RC_QUOTES
  676. X               Allow the character sequence '' to signify a  sin-
  677. X               gle quote within singly quoted strings.
  678. X          RECEXACT (-S)
  679. X               In completion, recognize  exact  matches  even  if
  680. X               they are ambiguous.
  681. X          RMSTARSILENT (-H)
  682. X               Do not query the user before executing "rm  *"  or
  683. X               "rm path/*".
  684. X          SHINSTDIN (-s)
  685. X               Read commands from the standard input.
  686. X          SH_WORD_SPLIT (-y)
  687. X               See Parameter Expansion.
  688. X          SINGLE_LINE_ZLE (-M)
  689. X               Use single-line command line  editing  instead  of
  690. X               multi-line.
  691. X          SUN_KEYBOARD_HACK (-L)
  692. X               If a line ends with a backquote, and there are  an
  693. X               odd  number  of backquotes on the line, ignore the
  694. X               trailing backquote.  This is useful on  some  key-
  695. X               boards  where the return key is too small, and the
  696. X               backquote key lies annoyingly close to it.
  697. X          VERBOSE (-v)
  698. X               Print shell input lines as they are read.
  699. X          XTRACE (-x)
  700. X               Print commands and their  arguments  as  they  are
  701. X               executed.
  702. X          ZLE (-Z)
  703. X               Use the zsh line editor.
  704. END_OF_FILE
  705.   if test 11726 -ne `wc -c <'help/setopt'`; then
  706.     echo shar: \"'help/setopt'\" unpacked with wrong size!
  707.   fi
  708.   # end of 'help/setopt'
  709. fi
  710. if test -f 'src/math.c' -a "${1}" != "-c" ; then 
  711.   echo shar: Will not clobber existing file \"'src/math.c'\"
  712. else
  713.   echo shar: Extracting \"'src/math.c'\" \(10353 characters\)
  714.   sed "s/^X//" >'src/math.c' <<'END_OF_FILE'
  715. X/*
  716. X *
  717. X * math.c - mathematical expression evaluation
  718. X *
  719. X * This file is part of zsh, the Z shell.
  720. X *
  721. X * This software is Copyright 1992 by Paul Falstad
  722. X *
  723. X * Permission is hereby granted to copy, reproduce, redistribute or otherwise
  724. X * use this software as long as: there is no monetary profit gained
  725. X * specifically from the use or reproduction of this software, it is not
  726. X * sold, rented, traded or otherwise marketed, and this copyright notice is
  727. X * included prominently in any copy made. 
  728. X *
  729. X * The author make no claims as to the fitness or correctness of this software
  730. X * for any use whatsoever, and it is provided as is. Any use of this software
  731. X * is at the user's own risk. 
  732. X *
  733. X */
  734. X
  735. X#include "zsh.h"
  736. X
  737. Xstatic char *ptr;
  738. X
  739. Xtypedef int LV;
  740. X
  741. Xstatic long yyval;
  742. Xstatic LV yylval;
  743. X
  744. X/* nonzero means we are not evaluating, just parsing */
  745. X
  746. Xstatic int noeval = 0;
  747. X
  748. X/* != 0 means recognize unary plus, minus, etc. */
  749. X
  750. Xstatic int unary = 1;
  751. X
  752. Xvoid mathparse DCLPROTO((int));
  753. X
  754. X/* LR = left-to-right associativity
  755. X    RL = right-to-left associativity
  756. X    BOO = short-circuiting boolean */
  757. X
  758. X#define LR 0
  759. X#define RL 1
  760. X#define BOOL 2
  761. X
  762. X#define M_INPAR 0
  763. X#define M_OUTPAR 1
  764. X#define NOT 2
  765. X#define COMP 3
  766. X#define POSTPLUS 4
  767. X#define POSTMINUS 5
  768. X#define UPLUS 6
  769. X#define UMINUS 7
  770. X#define AND 8
  771. X#define XOR 9
  772. X#define OR 10
  773. X#define MUL 11
  774. X#define DIV 12
  775. X#define MOD 13
  776. X#define PLUS 14
  777. X#define MINUS 15
  778. X#define SHLEFT 16
  779. X#define SHRIGHT 17
  780. X#define LES 18
  781. X#define LEQ 19
  782. X#define GRE 20
  783. X#define GEQ 21
  784. X#define DEQ 22
  785. X#define NEQ 23
  786. X#define DAND 24
  787. X#define DOR 25
  788. X#define DXOR 26
  789. X#define QUEST 27
  790. X#define COLON 28
  791. X#define EQ 29
  792. X#define PLUSEQ 30
  793. X#define MINUSEQ 31
  794. X#define MULEQ 32
  795. X#define DIVEQ 33
  796. X#define MODEQ 34
  797. X#define ANDEQ 35
  798. X#define XOREQ 36
  799. X#define OREQ 37
  800. X#define SHLEFTEQ 38
  801. X#define SHRIGHTEQ 39
  802. X#define DANDEQ 40
  803. X#define DOREQ 41
  804. X#define DXOREQ 42
  805. X#define COMMA 43
  806. X#define EOI 44
  807. X#define PREPLUS 45
  808. X#define PREMINUS 46
  809. X#define NUM 47
  810. X#define ID 48
  811. X#define TOKCOUNT 49
  812. X
  813. X/* precedences */
  814. X
  815. Xstatic int prec[TOKCOUNT] = {
  816. X    1,137,2,2,2,
  817. X    2,2,2,4,5,
  818. X    6,7,7,7,8,
  819. X    8,3,3,9,9,
  820. X    9,9,10,10,11,
  821. X    12,12,13,13,14,
  822. X    14,14,14,14,14,
  823. X    14,14,14,14,14,
  824. X    14,14,14,15,200,
  825. X    2,2,0,0,
  826. X};
  827. X
  828. X#define TOPPREC 15
  829. X#define ARGPREC (15-1)
  830. X
  831. Xstatic int type[TOKCOUNT] = {
  832. X    LR,LR,RL,RL,RL,
  833. X    RL,RL,RL,LR,LR,
  834. X    LR,LR,LR,LR,LR,
  835. X    LR,LR,LR,LR,LR,
  836. X    LR,LR,LR,LR,BOOL,
  837. X    BOOL,LR,RL,RL,RL,
  838. X    RL,RL,RL,RL,RL,
  839. X    RL,RL,RL,RL,RL,
  840. X    BOOL,BOOL,RL,RL,RL,
  841. X    RL,RL,LR,LR,
  842. X};
  843. X
  844. X#define LVCOUNT 32
  845. X
  846. X/* list of lvalues (variables) */
  847. X
  848. Xstatic int lvc;
  849. Xstatic char *lvals[LVCOUNT];
  850. X
  851. Xint zzlex() /**/
  852. X{
  853. X    for(;;)
  854. X        switch (*ptr++)
  855. X            {
  856. X            case '+':
  857. X                if (*ptr == '+' && (unary || !ialnum(*ptr)))
  858. X                    {
  859. X                    ptr++;
  860. X                    return (unary) ? PREPLUS : POSTPLUS;
  861. X                    }
  862. X                if (*ptr == '=') { unary = 1; ptr++; return PLUSEQ; }
  863. X                return (unary) ? UPLUS : PLUS;
  864. X            case '-':
  865. X                if (*ptr == '-' && (unary || !ialnum(*ptr)))
  866. X                    {
  867. X                    ptr++;
  868. X                    return (unary) ? PREMINUS : POSTMINUS;
  869. X                    }
  870. X                if (*ptr == '=') { unary = 1; ptr++; return MINUSEQ; }
  871. X                return (unary) ? UMINUS : MINUS;
  872. X            case '(': unary = 1; return M_INPAR;
  873. X            case ')': return M_OUTPAR;
  874. X            case '!': if (*ptr == '=')
  875. X                        { unary = 1; ptr++; return NEQ; }
  876. X                        return NOT;
  877. X            case '~': return COMP;
  878. X            case '&': unary = 1;
  879. X                if (*ptr == '&') { if (*++ptr == '=')
  880. X                { ptr++; return DANDEQ; } return DAND; }
  881. X                else if (*ptr == '=') { ptr++; return ANDEQ; } return AND;
  882. X            case '|': unary = 1;
  883. X                if (*ptr == '|') { if (*++ptr == '=')
  884. X                { ptr++; return DOREQ; } return DOR; }
  885. X                else if (*ptr == '=') { ptr++; return OREQ; } return OR;
  886. X            case '^': unary = 1;
  887. X                if (*ptr == '^') { if (*++ptr == '=')
  888. X                { ptr++; return DXOREQ; } return DXOR; }
  889. X                else if (*ptr == '=') { ptr++; return XOREQ; } return XOR;
  890. X            case '*': unary = 1;
  891. X                if (*ptr == '=') { ptr++; return MULEQ; } return MUL;
  892. X            case '/': unary = 1;
  893. X                if (*ptr == '=') { ptr++; return DIVEQ; } return DIV;
  894. X            case '%': unary = 1;
  895. X                if (*ptr == '=') { ptr++; return MODEQ; } return MOD;
  896. X            case '<': unary = 1; if (*ptr == '<')
  897. X                { if (*++ptr == '=') { ptr++; return SHLEFTEQ; } return SHLEFT; }
  898. X                else if (*ptr == '=') { ptr++; return LEQ; } return LES;
  899. X            case '>': unary = 1; if (*ptr == '>')
  900. X                { if (*++ptr == '=') { ptr++; return SHRIGHTEQ; } return SHRIGHT; }
  901. X                else if (*ptr == '=') { ptr++; return GEQ; } return GRE;
  902. X            case '=': unary = 1; if (*ptr == '=') { ptr++; return DEQ; }
  903. X                return EQ;
  904. X            case '?': unary = 1; return QUEST;
  905. X            case ':': unary = 1; return COLON;
  906. X            case ',': unary = 1; return COMMA;
  907. X            case '\0': unary = 1; ptr--; return EOI;
  908. X            case '[': unary = 0;
  909. X                { int base = zstrtol(ptr,&ptr,10);
  910. X                    if (*ptr == ']') ptr++;
  911. X                    yyval = zstrtol(ptr,&ptr,lastbase = base);
  912. X                    return NUM; }
  913. X            case ' ': case '\t':
  914. X                break;
  915. X            default:
  916. X                if (idigit(*--ptr))
  917. X                    { unary = 0; yyval = zstrtol(ptr,&ptr,10); return NUM; }
  918. X                if (iident(*ptr) || *ptr == '$')
  919. X                    {
  920. X                    char *p,q;
  921. X
  922. X                    if (*ptr == '$')
  923. X                        ptr++;
  924. X                    p = ptr;
  925. X                    if (lvc == LVCOUNT)
  926. X                        {
  927. X                        zerr("too many identifiers (complain to author)",NULL,0);
  928. X                        return EOI;
  929. X                        }
  930. X                    unary = 0;
  931. X                    while(iident(*++ptr));
  932. X                    q = *ptr;
  933. X                    *ptr = '\0';
  934. X                    lvals[yylval = lvc++] = ztrdup(p);
  935. X                    *ptr = q;
  936. X                    return ID;
  937. X                    }
  938. X                return EOI;
  939. X            }
  940. X}
  941. X
  942. X/* the value stack */
  943. X
  944. X#define STACKSZ 100
  945. Xint mtok;            /* last token */
  946. Xint sp = -1;    /* stack pointer */
  947. Xstruct mathvalue {
  948. X    LV lval;
  949. X    long val;
  950. X    } stack[STACKSZ];
  951. X
  952. Xvoid push(val,lval)
  953. Xlong val;LV lval;
  954. X{
  955. X    if (sp == STACKSZ-1)
  956. X        zerr("stack overflow",NULL,0);
  957. X    else
  958. X        sp++;
  959. X    stack[sp].val = val;
  960. X    stack[sp].lval = lval;
  961. X}
  962. X
  963. Xlong getvar(s)
  964. XLV s;
  965. X{
  966. Xlong t;
  967. X
  968. X    if (!(t = getiparam(lvals[s])))
  969. X        return 0;
  970. X    return t;
  971. X}
  972. X
  973. Xlong setvar(s,v)
  974. XLV s;long v;
  975. X{
  976. X    if (s == -1 || s >= lvc)
  977. X        {
  978. X        zerr("lvalue required",NULL,0);
  979. X        return 0;
  980. X        }
  981. X    if (noeval)
  982. X        return v;
  983. X    setiparam(lvals[s],v);
  984. X    return v;
  985. X}
  986. X
  987. Xint notzero(a) /**/
  988. Xint a;
  989. X{
  990. X    if (a == 0)
  991. X        {
  992. X        zerr("division by zero",NULL,0);
  993. X        return 0;
  994. X        }
  995. X    return 1;
  996. X}
  997. X
  998. X#define pop2() { b = stack[sp--].val; a = stack[sp--].val; }
  999. X#define pop3() {c=stack[sp--].val;b=stack[sp--].val;a=stack[sp--].val;}
  1000. X#define nolval() {stack[sp].lval= -1;}
  1001. X#define pushv(X) { push(X,-1); }
  1002. X#define pop2lv() { pop2() lv = stack[sp+1].lval; }
  1003. X#define set(X) { push(setvar(lv,X),lv); }
  1004. X
  1005. Xvoid op(what) /**/
  1006. Xint what;
  1007. X{
  1008. Xlong a,b,c;
  1009. XLV lv;
  1010. X
  1011. X    if (sp < 0)
  1012. X        {
  1013. X        zerr("bad math expression: stack empty",NULL,0);
  1014. X        return;
  1015. X        }
  1016. X    switch(what) {
  1017. X        case NOT: stack[sp].val = !stack[sp].val; nolval(); break;
  1018. X        case COMP: stack[sp].val = ~stack[sp].val; nolval(); break;
  1019. X        case POSTPLUS: ( void ) setvar(stack[sp].lval,stack[sp].val+1); break;
  1020. X        case POSTMINUS: ( void ) setvar(stack[sp].lval,stack[sp].val-1); break;
  1021. X        case UPLUS: nolval(); break;
  1022. X        case UMINUS: stack[sp].val = -stack[sp].val; nolval(); break;
  1023. X        case AND: pop2(); pushv(a&b); break;
  1024. X        case XOR: pop2(); pushv(a^b); break;
  1025. X        case OR: pop2(); pushv(a|b); break;
  1026. X        case MUL: pop2(); pushv(a*b); break;
  1027. X        case DIV: pop2(); if (notzero(b)) pushv(a/b); break;
  1028. X        case MOD: pop2(); if (notzero(b)) pushv(a%b); break;
  1029. X        case PLUS: pop2(); pushv(a+b); break;
  1030. X        case MINUS: pop2(); pushv(a-b); break;
  1031. X        case SHLEFT: pop2(); pushv(a<<b); break;
  1032. X        case SHRIGHT: pop2(); pushv(a>>b); break;
  1033. X        case LES: pop2(); pushv((long)(a<b)); break;
  1034. X        case LEQ: pop2(); pushv((long)(a<=b)); break;
  1035. X        case GRE: pop2(); pushv((long)(a>b)); break;
  1036. X        case GEQ: pop2(); pushv((long)(a>=b)); break;
  1037. X        case DEQ: pop2(); pushv((long)(a==b)); break;
  1038. X        case NEQ: pop2(); pushv((long)(a!=b)); break;
  1039. X        case DAND: pop2(); pushv((long)(a&&b)); break;
  1040. X        case DOR: pop2(); pushv((long)(a||b)); break;
  1041. X        case DXOR: pop2(); pushv((long)((a&&!b)||(!a&&b))); break;
  1042. X        case QUEST: pop3(); pushv((a)?b:c); break;
  1043. X        case COLON: break;
  1044. X        case EQ: b = stack[sp].val; sp -= 2; lv = stack[sp+1].lval;
  1045. X            set(b); break;
  1046. X        case PLUSEQ: pop2lv(); set(a+b); break;
  1047. X        case MINUSEQ: pop2lv(); set(a-b); break;
  1048. X        case MULEQ: pop2lv(); set(a*b); break;
  1049. X        case DIVEQ: pop2lv(); if (notzero(b)) set(a/b); break;
  1050. X        case MODEQ: pop2lv(); if (notzero(b)) set(a%b); break;
  1051. X        case ANDEQ: pop2lv(); set(a&b); break;
  1052. X        case XOREQ: pop2lv(); set(a^b); break;
  1053. X        case OREQ: pop2lv(); set(a|b); break;
  1054. X        case SHLEFTEQ: pop2lv(); set(a<<b); break;
  1055. X        case SHRIGHTEQ: pop2lv(); set(a>>b); break;
  1056. X        case DANDEQ: pop2lv(); set((long)(a&&b)); break;
  1057. X        case DOREQ: pop2lv(); set((long)(a||b)); break;
  1058. X        case DXOREQ: pop2lv(); set((long)((a&&!b)||(!a&&b))); break;
  1059. X        case COMMA: b = stack[sp].val; sp -= 2; pushv(b); break;
  1060. X        case PREPLUS: stack[sp].val = setvar(stack[sp].lval,
  1061. X            stack[sp].val+1); break;
  1062. X        case PREMINUS: stack[sp].val = setvar(stack[sp].lval,
  1063. X            stack[sp].val-1); break;
  1064. X        default: zerr("out of integers",NULL,0); exit(1);
  1065. X    }
  1066. X}
  1067. X
  1068. Xvoid bop(tk) /**/
  1069. Xint tk;
  1070. X{
  1071. X    switch (tk) {
  1072. X        case DAND: case DANDEQ: if (!stack[sp].val) noeval++; break;
  1073. X        case DOR: case DOREQ: if (stack[sp].val) noeval++; break;
  1074. X        };
  1075. X}
  1076. X
  1077. Xlong mathevall(s,prek,ep) /**/
  1078. Xchar *s;int prek;char **ep;
  1079. X{
  1080. Xint t0;
  1081. X
  1082. X    lastbase = -1;
  1083. X    for (t0 = 0; t0 != LVCOUNT; t0++)
  1084. X        lvals[t0] = NULL;
  1085. X    lvc = 0;
  1086. X    ptr = s;
  1087. X    sp = -1;
  1088. X    unary = 1;
  1089. X    mathparse(prek);
  1090. X    *ep = ptr;
  1091. X    if (sp)
  1092. X        zerr("bad math expression: unbalanced stack",NULL,0);
  1093. X    for (t0 = 0; t0 != lvc; t0++)
  1094. X        free(lvals[t0]);
  1095. X    return stack[0].val;
  1096. X}
  1097. X
  1098. Xlong matheval(s) /**/
  1099. Xchar *s;
  1100. X{
  1101. Xchar *junk;
  1102. Xlong x;
  1103. X
  1104. X    if (!*s)
  1105. X        return 0;
  1106. X    x = mathevall(s,TOPPREC,&junk);
  1107. X    if (*junk)
  1108. X        zerr("bad math expression: illegal character: %c",NULL,*junk);
  1109. X    return x;
  1110. X}
  1111. X
  1112. Xlong mathevalarg(s,ss) /**/
  1113. Xchar *s;char **ss;
  1114. X{
  1115. Xlong x;
  1116. X
  1117. X    x = mathevall(s,ARGPREC,ss);
  1118. X    if (mtok == COMMA)
  1119. X        (*ss)--;
  1120. X    return x;
  1121. X}
  1122. X
  1123. X/* operator-precedence parse the string and execute */
  1124. X
  1125. Xvoid mathparse(pc) /**/
  1126. Xint pc;
  1127. X{
  1128. X    if (errflag)
  1129. X        return;
  1130. X    mtok = zzlex();
  1131. X    while (prec[mtok] <= pc)
  1132. X        {
  1133. X        if (errflag)
  1134. X            return;
  1135. X        if (mtok == NUM)
  1136. X            push(yyval,-1);
  1137. X        else if (mtok == ID)
  1138. X            push(getvar(yylval),yylval);
  1139. X        else if (mtok == M_INPAR)
  1140. X            {
  1141. X            mathparse(TOPPREC);
  1142. X            if (mtok != M_OUTPAR)
  1143. X                exit(1);
  1144. X            }
  1145. X        else if (mtok == QUEST)
  1146. X            {
  1147. X            int q = stack[sp].val;
  1148. X            if (!q) noeval++;
  1149. X            mathparse(prec[QUEST]-1);
  1150. X            if (!q) noeval--; else noeval++;
  1151. X            mathparse(prec[QUEST]);
  1152. X            if (q) noeval--;
  1153. X            op(QUEST);
  1154. X            continue;
  1155. X            }
  1156. X        else
  1157. X            {
  1158. X            int otok = mtok,onoeval = noeval;
  1159. X
  1160. X            if (type[otok] == BOOL)
  1161. X                bop(otok);
  1162. X            mathparse(prec[otok]-(type[otok] != RL));
  1163. X            noeval = onoeval;
  1164. X            op(otok);
  1165. X            continue;
  1166. X            }
  1167. X        mtok = zzlex();
  1168. X        }
  1169. X}
  1170. X
  1171. END_OF_FILE
  1172.   if test 10353 -ne `wc -c <'src/math.c'`; then
  1173.     echo shar: \"'src/math.c'\" unpacked with wrong size!
  1174.   fi
  1175.   # end of 'src/math.c'
  1176. fi
  1177. if test -f 'src/table.c' -a "${1}" != "-c" ; then 
  1178.   echo shar: Will not clobber existing file \"'src/table.c'\"
  1179. else
  1180.   echo shar: Extracting \"'src/table.c'\" \(6815 characters\)
  1181.   sed "s/^X//" >'src/table.c' <<'END_OF_FILE'
  1182. X/*
  1183. X *
  1184. X * table.c - linked lists and hash tables
  1185. X *
  1186. X * This file is part of zsh, the Z shell.
  1187. X *
  1188. X * This software is Copyright 1992 by Paul Falstad
  1189. X *
  1190. X * Permission is hereby granted to copy, reproduce, redistribute or otherwise
  1191. X * use this software as long as: there is no monetary profit gained
  1192. X * specifically from the use or reproduction of this software, it is not
  1193. X * sold, rented, traded or otherwise marketed, and this copyright notice is
  1194. X * included prominently in any copy made. 
  1195. X *
  1196. X * The author make no claims as to the fitness or correctness of this software
  1197. X * for any use whatsoever, and it is provided as is. Any use of this software
  1198. X * is at the user's own risk. 
  1199. X *
  1200. X */
  1201. X
  1202. X#define TABLE_C
  1203. X#include "zsh.h"
  1204. X
  1205. X/* get an empty linked list header */
  1206. X
  1207. XLklist newlist() /**/
  1208. X{
  1209. XLklist list;
  1210. X    list = (Lklist) alloc(sizeof *list);
  1211. X    list->first = 0;
  1212. X    list->last = (Lknode) list;
  1213. X    return list;
  1214. X}
  1215. X
  1216. X/* get an empty hash table */
  1217. X
  1218. XHashtab newhtable(size) /**/
  1219. Xint size;
  1220. X{
  1221. XHashtab ret;
  1222. X    ret = (Hashtab) zcalloc(sizeof *ret);
  1223. X    ret->hsize = size;
  1224. X    ret->nodes = (Hashnode*) zcalloc(size*sizeof(Hashnode));
  1225. X    return ret;
  1226. X}
  1227. X/* Peter Weinberger's hash function */
  1228. X
  1229. Xint hasher(s) /**/
  1230. Xchar *s;
  1231. X{
  1232. Xunsigned hash = 0,g;
  1233. X    for (; *s; s++) {
  1234. X        hash = (hash << 4) + *s;
  1235. X        if (g = hash & 0xf0000000) {
  1236. X            hash ^= g;
  1237. X            hash ^= g >> 24;
  1238. X        }
  1239. X    }
  1240. X    return hash;
  1241. X}
  1242. X
  1243. X/* add a node to a hash table */
  1244. X
  1245. Xvoid Addhnode(nam,dat,ht,freefunc,canfree) /**/
  1246. Xchar *nam;vptr dat;Hashtab ht;FFunc freefunc;int canfree;
  1247. X{
  1248. Xint hval = hasher(nam) % ht->hsize;
  1249. Xstruct hashnode **hp = ht->nodes+hval,*hn;
  1250. X    for (; *hp; hp = &(*hp)->next)
  1251. X        if (!strcmp((*hp)->nam,nam)) {
  1252. X            if ((*hp)->canfree) free((*hp)->nam);
  1253. X            hn = dat;
  1254. X            hn->next = (*hp)->next;
  1255. X            if (!freefunc) zerr("attempt to call NULL freefunc",NULL,0);
  1256. X            else freefunc(*hp);
  1257. X            *hp = hn;
  1258. X            hn->nam = nam;
  1259. X            hn->canfree = canfree;
  1260. X            return;
  1261. X        }
  1262. X    hn = (Hashnode) dat;
  1263. X    hn->nam = nam;
  1264. X    hn->canfree = canfree;
  1265. X    hn->next = ht->nodes[hval];
  1266. X    ht->nodes[hval] = hn;
  1267. X    if (++ht->ct == ht->hsize*4) expandhtab(ht);
  1268. X}
  1269. X
  1270. X/* add a node to command hash table */
  1271. X
  1272. Xvoid addhcmdnode(nam,pnam) /**/
  1273. Xchar *nam;char **pnam;
  1274. X{
  1275. Xint hval = hasher(nam) % cmdnamtab->hsize;
  1276. Xstruct hashnode *hp = cmdnamtab->nodes[hval],*hn;
  1277. XCmdnam cc;
  1278. X    for (; hp; hp = hp->next) if (!strcmp(hp->nam,nam)) return;
  1279. X    cc = (Cmdnam) zcalloc(sizeof *cc);
  1280. X    cc->type = EXCMD;
  1281. X    cc->u.nam = tricat(*pnam,"/",nam);
  1282. X    cc->pcomp = pnam;
  1283. X    hn = (Hashnode) cc;
  1284. X    hn->nam = ztrdup(nam);
  1285. X    hn->canfree = 1;
  1286. X    hn->next = cmdnamtab->nodes[hval];
  1287. X    cmdnamtab->nodes[hval] = hn;
  1288. X    if (++cmdnamtab->ct == cmdnamtab->hsize*4) expandhtab(cmdnamtab);
  1289. X}
  1290. X
  1291. X/* expand hash tables when they get too many entries */
  1292. X
  1293. Xvoid expandhtab(ht) /**/
  1294. XHashtab ht;
  1295. X{
  1296. Xstruct hashnode **arr,**ha,*hn,*hp;
  1297. Xint osize = ht->hsize,nsize = osize*8;
  1298. X
  1299. X    ht->hsize = nsize;
  1300. X    arr = ht->nodes;
  1301. X    ht->nodes = (Hashnode*) zcalloc(nsize*sizeof(struct hashnode *));
  1302. X    for (ha = arr; osize; osize--,ha++)
  1303. X        for (hn = *ha; hn; ) {
  1304. X            hp = hn->next;
  1305. X            Addhnode(hn->nam,(vptr)hn,ht,(FFunc) 0,hn->canfree);
  1306. X            hn = hp;
  1307. X        }
  1308. X    free(arr);
  1309. X}
  1310. X
  1311. X/* get an entry in a hash table */
  1312. X
  1313. Xvptr gethnode(nam,ht) /**/
  1314. Xchar *nam;Hashtab ht;
  1315. X{
  1316. Xint hval = hasher(nam) % ht->hsize;
  1317. Xstruct hashnode *hn = ht->nodes[hval];
  1318. X    for (; hn; hn = hn->next) if (!strcmp(hn->nam,nam)) return (vptr)hn;
  1319. X    return NULL;
  1320. X}
  1321. Xvoid freehtab(ht,freefunc) /**/
  1322. XHashtab ht;FFunc freefunc;
  1323. X{
  1324. Xint val;
  1325. Xstruct hashnode *hn,**hp = &ht->nodes[0],*next;
  1326. X    for (val = ht->hsize; val; val--,hp++)
  1327. X        for (hn = *hp; hn; ) {
  1328. X            next = hn->next;
  1329. X            if (hn->canfree) free(hn->nam);
  1330. X            freefunc(hn);
  1331. X            hn = next;
  1332. X        }
  1333. X    free(ht->nodes);
  1334. X    free(ht);
  1335. X}
  1336. X
  1337. X/* remove a hash table entry and return a pointer to it */
  1338. X
  1339. Xvptr remhnode(nam,ht) /**/
  1340. Xchar *nam;Hashtab ht;
  1341. X{
  1342. Xint hval = hasher(nam) % ht->hsize;
  1343. Xstruct hashnode *hn = ht->nodes[hval],*hp;
  1344. X
  1345. X    if (!hn) return NULL;
  1346. X    if (!strcmp(hn->nam,nam)) {
  1347. X        ht->nodes[hval] = hn->next;
  1348. X        if (hn->canfree) free(hn->nam);
  1349. X        ht->ct--;
  1350. X        return (vptr)hn;
  1351. X    }
  1352. X    for (hp = hn, hn = hn->next; hn; hn = (hp = hn)->next)
  1353. X        if (!strcmp(hn->nam,nam)) {
  1354. X            hp->next = hn->next;
  1355. X            if (hn->canfree) free(hn->nam);
  1356. X            ht->ct--;
  1357. X            return (vptr)hn;
  1358. X        }
  1359. X    return NULL;
  1360. X}
  1361. X
  1362. X/* insert a node in a linked list after 'llast' */
  1363. X
  1364. Xvoid insnode(list,llast,dat) /**/
  1365. XLklist list;Lknode llast;vptr dat;
  1366. X{
  1367. XLknode tmp;
  1368. X    tmp = llast->next;
  1369. X    llast->next = (Lknode) alloc(sizeof *tmp);
  1370. X    llast->next->last = llast;
  1371. X    llast->next->dat = dat;
  1372. X    llast->next->next = tmp;
  1373. X    if (tmp) tmp->last = llast->next;
  1374. X    else list->last = llast->next;
  1375. X}
  1376. X
  1377. Xvoid addnodeinorder(x,dat) /**/
  1378. XLklist x; char *dat;
  1379. X{
  1380. XLknode y, l = NULL;
  1381. Xint val = 123;
  1382. X
  1383. X    for (y = firstnode(x); y; incnode(y)) {
  1384. X        if ((val = forstrcmp((char **) &y->dat, &dat)) >= 0) break;
  1385. X        l = y;
  1386. X    }
  1387. X    if (!val) return;
  1388. X    if (l == NULL) insnode(x, (Lknode) x, dat);
  1389. X    else insnode(x, l, dat);
  1390. X}
  1391. X
  1392. X
  1393. X/* remove a node from a linked list */
  1394. X
  1395. Xvptr remnode(list,nd) /**/
  1396. XLklist list;Lknode nd;
  1397. X{
  1398. Xvptr dat;
  1399. X
  1400. X    nd->last->next = nd->next;
  1401. X    if (nd->next) nd->next->last = nd->last;
  1402. X    else list->last = nd->last;
  1403. X    dat = nd->dat;
  1404. X    free(nd);
  1405. X    return dat;
  1406. X}
  1407. X
  1408. X/* remove a node from a linked list */
  1409. X
  1410. Xvptr uremnode(list,nd) /**/
  1411. XLklist list;Lknode nd;
  1412. X{
  1413. Xvptr dat;
  1414. X
  1415. X    nd->last->next = nd->next;
  1416. X    if (nd->next) nd->next->last = nd->last;
  1417. X    else list->last = nd->last;
  1418. X    dat = nd->dat;
  1419. X    return dat;
  1420. X}
  1421. X
  1422. X/* delete a character in a string */
  1423. X
  1424. Xvoid chuck(str) /**/
  1425. Xchar *str;
  1426. X{
  1427. X    while (str[0] = str[1]) str++;
  1428. X}
  1429. X
  1430. X/* get top node in a linked list */
  1431. X
  1432. Xvptr getnode(list) /**/
  1433. XLklist list;
  1434. X{
  1435. Xvptr dat;
  1436. XLknode node = list->first;
  1437. X    if (!node)
  1438. X        return NULL;
  1439. X    dat = node->dat;
  1440. X    list->first = node->next;
  1441. X    if (node->next)
  1442. X        node->next->last = (Lknode) list;
  1443. X    else
  1444. X        list->last = (Lknode) list;
  1445. X    free(node);
  1446. X    return dat;
  1447. X}
  1448. X
  1449. X/* get top node in a linked list without freeing */
  1450. X
  1451. Xvptr ugetnode(list) /**/
  1452. XLklist list;
  1453. X{
  1454. Xvptr dat;
  1455. XLknode node = list->first;
  1456. X    if (!node)
  1457. X        return NULL;
  1458. X    dat = node->dat;
  1459. X    list->first = node->next;
  1460. X    if (node->next)
  1461. X        node->next->last = (Lknode) list;
  1462. X    else
  1463. X        list->last = (Lknode) list;
  1464. X    return dat;
  1465. X}
  1466. X
  1467. Xvoid freetable(tab,freefunc) /**/
  1468. XLklist tab;FFunc freefunc;
  1469. X{
  1470. XLknode node = tab->first,next;
  1471. X    while (node) {
  1472. X        next = node->next;
  1473. X        if (freefunc) freefunc(node->dat);
  1474. X        free(node);
  1475. X        node = next;
  1476. X    }
  1477. X    free(tab);
  1478. X}
  1479. Xchar *ztrstr(s,t) /**/
  1480. Xchar *s;char *t;
  1481. X{
  1482. Xchar *p1,*p2;
  1483. X    for (; *s; s++) {
  1484. X        for (p1 = s, p2 = t; *p2; p1++,p2++)
  1485. X            if (*p1 != *p2) break;
  1486. X        if (!*p2) return (char *) s;
  1487. X    }
  1488. X    return NULL;
  1489. X}
  1490. X
  1491. X/* insert a list in another list */
  1492. X
  1493. Xvoid inslist(l,where,x) /**/
  1494. XLklist l;Lknode where;Lklist x;
  1495. X{
  1496. XLknode nx = where->next;
  1497. X
  1498. X    if (!l->first) return;
  1499. X    where->next = l->first;
  1500. X    l->last->next = nx;
  1501. X    l->first->last = where;
  1502. X    if (nx) nx->last = l->last;
  1503. X    else x->last = l->last;
  1504. X}
  1505. X
  1506. Xint countnodes(x) /**/
  1507. XLklist x;
  1508. X{
  1509. XLknode y;
  1510. Xint ct = 0;
  1511. X
  1512. X    for (y = firstnode(x); y; incnode(y),ct++);
  1513. X    return ct;
  1514. X}
  1515. X
  1516. END_OF_FILE
  1517.   if test 6815 -ne `wc -c <'src/table.c'`; then
  1518.     echo shar: \"'src/table.c'\" unpacked with wrong size!
  1519.   fi
  1520.   # end of 'src/table.c'
  1521. fi
  1522. if test -f 'src/zle_hist.c' -a "${1}" != "-c" ; then 
  1523.   echo shar: Will not clobber existing file \"'src/zle_hist.c'\"
  1524. else
  1525.   echo shar: Extracting \"'src/zle_hist.c'\" \(11190 characters\)
  1526.   sed "s/^X//" >'src/zle_hist.c' <<'END_OF_FILE'
  1527. X/*
  1528. X *
  1529. X * zle_hist.c - history editing
  1530. X *
  1531. X * This file is part of zsh, the Z shell.
  1532. X *
  1533. X * This software is Copyright 1992 by Paul Falstad
  1534. X *
  1535. X * Permission is hereby granted to copy, reproduce, redistribute or otherwise
  1536. X * use this software as long as: there is no monetary profit gained
  1537. X * specifically from the use or reproduction of this software, it is not
  1538. X * sold, rented, traded or otherwise marketed, and this copyright notice is
  1539. X * included prominently in any copy made. 
  1540. X *
  1541. X * The author make no claims as to the fitness or correctness of this software
  1542. X * for any use whatsoever, and it is provided as is. Any use of this software
  1543. X * is at the user's own risk. 
  1544. X *
  1545. X */
  1546. X
  1547. X#define ZLE
  1548. X#include "zsh.h"
  1549. X
  1550. Xvoid toggleliteralhistory() /**/
  1551. X{
  1552. Xchar *s;
  1553. X
  1554. X    if (histline == curhist)
  1555. X        {
  1556. X        if (curhistline)
  1557. X            free(curhistline);
  1558. X        curhistline = ztrdup(UTOSCP(line));
  1559. X        }
  1560. X    lithist ^= 1;
  1561. X    if (!(s = qgetevent(histline)))
  1562. X        feep();
  1563. X    else
  1564. X        sethistline(STOUCP(s));
  1565. X}
  1566. X
  1567. Xvoid uphistory() /**/
  1568. X{
  1569. Xchar *s;
  1570. X
  1571. X    if (mult < 0) { mult = -mult; downhistory(); return; }
  1572. X    if (histline == curhist)
  1573. X        {
  1574. X        if (curhistline)
  1575. X            free(curhistline);
  1576. X        curhistline = ztrdup(UTOSCP(line));
  1577. X        }
  1578. X    histline -= mult;
  1579. X    if (!(s = qgetevent(histline)))
  1580. X        {
  1581. X        if (unset(NOHISTBEEP)) feep();
  1582. X        histline += mult;
  1583. X        }
  1584. X    else
  1585. X        sethistline(STOUCP(s));
  1586. X}
  1587. X
  1588. Xvoid uplineorhistory() /**/
  1589. X{
  1590. Xint ocs = cs;
  1591. X
  1592. X    if (mult < 0) { mult = -mult; downlineorhistory(); return; }
  1593. X    if ((lastcmd & ZLE_LINEMOVE) != ZLE_LINEMOVE)
  1594. X        lastcol = cs-findbol();
  1595. X    cs = findbol();
  1596. X    while (mult) {
  1597. X        if (!cs)
  1598. X            break;
  1599. X        cs--;
  1600. X        cs = findbol();
  1601. X        mult--;
  1602. X    }
  1603. X    if (mult) {
  1604. X        cs = ocs;
  1605. X        if (virangeflag) {
  1606. X            feep();
  1607. X            return;
  1608. X        }
  1609. X        uphistory();
  1610. X    } else {
  1611. X        int x = findeol();
  1612. X        if ((cs += lastcol) > x)
  1613. X            cs = x;
  1614. X    }
  1615. X}
  1616. X
  1617. Xvoid uplineorsearch() /**/
  1618. X{
  1619. Xint ocs = cs;
  1620. X
  1621. X    if (mult < 0) { mult = -mult; downlineorsearch(); return; }
  1622. X    if ((lastcmd & ZLE_LINEMOVE) != ZLE_LINEMOVE)
  1623. X        lastcol = cs-findbol();
  1624. X    cs = findbol();
  1625. X    while (mult) {
  1626. X        if (!cs)
  1627. X            break;
  1628. X        cs--;
  1629. X        cs = findbol();
  1630. X        mult--;
  1631. X    }
  1632. X    if (mult) {
  1633. X        cs = ocs;
  1634. X        if (virangeflag) {
  1635. X            feep();
  1636. X            return;
  1637. X        }
  1638. X        historysearchbackward();
  1639. X    } else {
  1640. X        int x = findeol();
  1641. X        if ((cs += lastcol) > x)
  1642. X            cs = x;
  1643. X    }
  1644. X}
  1645. X
  1646. Xvoid downlineorhistory() /**/
  1647. X{
  1648. Xint ocs = cs;
  1649. X
  1650. X    if (mult < 0) { mult = -mult; uplineorhistory(); return; }
  1651. X    if ((lastcmd & ZLE_LINEMOVE) != ZLE_LINEMOVE)
  1652. X        lastcol = cs-findbol();
  1653. X    while (mult) {
  1654. X        int x = findeol();
  1655. X        if (x == ll)
  1656. X            break;
  1657. X        cs = x+1;
  1658. X        mult--;
  1659. X    }
  1660. X    if (mult) {
  1661. X        cs = ocs;
  1662. X        if (virangeflag) {
  1663. X            feep();
  1664. X            return;
  1665. X        }
  1666. X        downhistory();
  1667. X    } else {
  1668. X        int x = findeol();
  1669. X        if ((cs += lastcol) > x)
  1670. X            cs = x;
  1671. X    }
  1672. X}
  1673. X
  1674. Xvoid downlineorsearch() /**/
  1675. X{
  1676. Xint ocs = cs;
  1677. X
  1678. X    if (mult < 0) { mult = -mult; uplineorsearch(); return; }
  1679. X    if ((lastcmd & ZLE_LINEMOVE) != ZLE_LINEMOVE)
  1680. X        lastcol = cs-findbol();
  1681. X    while (mult) {
  1682. X        int x = findeol();
  1683. X        if (x == ll)
  1684. X            break;
  1685. X        cs = x+1;
  1686. X        mult--;
  1687. X    }
  1688. X    if (mult) {
  1689. X        cs = ocs;
  1690. X        if (virangeflag) {
  1691. X            feep();
  1692. X            return;
  1693. X        }
  1694. X        historysearchforward();
  1695. X    } else {
  1696. X        int x = findeol();
  1697. X        if ((cs += lastcol) > x)
  1698. X            cs = x;
  1699. X    }
  1700. X}
  1701. X
  1702. Xvoid acceptlineanddownhistory() /**/
  1703. X{
  1704. Xchar *s,*t;
  1705. X
  1706. X    if (!(s = qgetevent(histline+1)))
  1707. X        {
  1708. X        feep();
  1709. X        return;
  1710. X        }
  1711. X    pushnode(bufstack,t = ztrdup(s));
  1712. X    for (; *t; t++)
  1713. X        if (*t == HISTSPACE)
  1714. X            *t = ' ';
  1715. X    done = 1;
  1716. X    stackhist = histline+1;
  1717. X}
  1718. X
  1719. Xvoid downhistory() /**/
  1720. X{
  1721. Xchar *s;
  1722. X
  1723. X    if (mult < 0) { mult = -mult; uphistory(); return; }
  1724. X    histline += mult;
  1725. X    if (!(s = qgetevent(histline)))
  1726. X        {
  1727. X        if (unset(NOHISTBEEP)) feep();
  1728. X        histline -= mult;
  1729. X        return;
  1730. X        }
  1731. X    sethistline(STOUCP(s));
  1732. X}
  1733. X
  1734. Xstatic int histpos;
  1735. X
  1736. Xvoid historysearchbackward() /**/
  1737. X{
  1738. Xint t0,ohistline = histline;
  1739. Xchar *s;
  1740. X
  1741. X    if (histline == curhist)
  1742. X        {
  1743. X        if (curhistline)
  1744. X            free(curhistline);
  1745. X        curhistline = ztrdup(UTOSCP(line));
  1746. X        }
  1747. X    if (lastcmd & ZLE_HISTSEARCH) t0 = histpos;
  1748. X    else for (t0 = 0; line[t0] && iword(line[t0]); t0++);
  1749. X    histpos = t0;
  1750. X    for (;;)
  1751. X        {
  1752. X        histline--;
  1753. X        if (!(s = qgetevent(histline)))
  1754. X            {
  1755. X            feep();
  1756. X            histline = ohistline;
  1757. X            return;
  1758. X            }
  1759. X        if (!hstrncmp(s,UTOSCP(line),t0) && hstrcmp(s,UTOSCP(line)))
  1760. X            break;
  1761. X        }
  1762. X    sethistline(STOUCP(s));
  1763. X}
  1764. X
  1765. Xvoid historysearchforward() /**/
  1766. X{
  1767. Xint t0,ohistline = histline;
  1768. Xchar *s;
  1769. X
  1770. X    if (histline == curhist)
  1771. X        {
  1772. X        if (curhistline)
  1773. X            free(curhistline);
  1774. X        curhistline = ztrdup(UTOSCP(line));
  1775. X        }
  1776. X    if (lastcmd & ZLE_HISTSEARCH) t0 = histpos;
  1777. X    else for (t0 = 0; line[t0] && iword(line[t0]); t0++);
  1778. X    histpos = t0;
  1779. X    for (;;)
  1780. X        {
  1781. X        histline++;
  1782. X        if (!(s = qgetevent(histline)))
  1783. X            {
  1784. X            feep();
  1785. X            histline = ohistline;
  1786. X            return;
  1787. X            }
  1788. X        if (!hstrncmp(s,UTOSCP(line),t0) && hstrcmp(s,UTOSCP(line)))
  1789. X            break;
  1790. X        }
  1791. X    sethistline(STOUCP(s));
  1792. X}
  1793. X
  1794. Xvoid beginningofbufferorhistory() /**/
  1795. X{
  1796. X    if (findbol())
  1797. X        cs = 0;
  1798. X    else
  1799. X        beginningofhistory();
  1800. X}
  1801. X
  1802. Xvoid beginningofhistory() /**/
  1803. X{
  1804. Xchar *s;
  1805. X
  1806. X    if (histline == curhist)
  1807. X        {
  1808. X        if (curhistline)
  1809. X            free(curhistline);
  1810. X        curhistline = ztrdup(UTOSCP(line));
  1811. X        }
  1812. X    if (!(s = qgetevent(firsthist())))
  1813. X        {
  1814. X        if (unset(NOHISTBEEP)) feep();
  1815. X        return;
  1816. X        }
  1817. X    histline = firsthist();
  1818. X    sethistline(STOUCP(s));
  1819. X}
  1820. X
  1821. Xvoid endofbufferorhistory() /**/
  1822. X{
  1823. X    if (findeol() != ll)
  1824. X        cs = ll;
  1825. X    else
  1826. X        endofhistory();
  1827. X}
  1828. X
  1829. Xvoid endofhistory() /**/
  1830. X{
  1831. X    if (histline == curhist) {
  1832. X        if (unset(NOHISTBEEP)) feep();
  1833. X    } else
  1834. X        {
  1835. X        histline = curhist;
  1836. X        sethistline(STOUCP(curhistline));
  1837. X        }
  1838. X}
  1839. X
  1840. Xvoid insertlastword() /**/
  1841. X{
  1842. Xchar *s,*t;
  1843. Xint len,z = lithist;
  1844. X
  1845. X    /* multiple calls will now search back through the history, pem */
  1846. X    static char    *lastinsert;
  1847. X    static int    lasthist, lastpos;
  1848. X    int        evhist = curhist - 1;
  1849. X
  1850. X    if (lastinsert) {
  1851. X        int len = strlen(lastinsert);
  1852. X        int pos = cs;
  1853. X        if (    lastpos <= pos &&
  1854. X            len == pos - lastpos &&
  1855. X            strncmp(lastinsert, (char *) &line[lastpos], len) == 0) {
  1856. X        evhist = --lasthist;
  1857. X        cs = lastpos;
  1858. X        foredel(pos-cs);
  1859. X        }
  1860. X        free(lastinsert);
  1861. X        lastinsert = NULL;
  1862. X    }
  1863. X    lithist = 0;
  1864. X    if (!(s = qgetevent(evhist), lithist = z, s))
  1865. X        {
  1866. X        feep();
  1867. X        return;
  1868. X        }
  1869. X    for (t = s+strlen(s); t > s; t--)
  1870. X        if (*t == HISTSPACE)
  1871. X            break;
  1872. X    if (t != s)
  1873. X        t++;
  1874. X    lasthist = evhist;
  1875. X    lastpos = cs;
  1876. X    lastinsert = ztrdup(t);
  1877. X    spaceinline(len = strlen(t));
  1878. X    strncpy((char *) line+cs,t,len);
  1879. X    cs += len;
  1880. X}
  1881. X
  1882. Xchar *qgetevent(ev) /**/
  1883. Xint ev;
  1884. X{
  1885. X    if (ev > curhist)
  1886. X        return NULL;
  1887. X    return ((ev == curhist) ? curhistline : quietgetevent(ev));
  1888. X}
  1889. X
  1890. Xvoid pushline() /**/
  1891. X{
  1892. X    if (mult < 0) return;
  1893. X    pushnode(bufstack,ztrdup(UTOSCP(line)));
  1894. X    while (--mult)
  1895. X        pushnode(bufstack,ztrdup(""));
  1896. X    stackcs = cs;
  1897. X    *line = '\0';
  1898. X    ll = cs = 0;
  1899. X}
  1900. X
  1901. Xvoid getline() /**/
  1902. X{
  1903. Xchar *s = getnode(bufstack);
  1904. X
  1905. X    if (!s)
  1906. X        feep();
  1907. X    else
  1908. X        {
  1909. X        int cc;
  1910. X
  1911. X        cc = strlen(s);
  1912. X        spaceinline(cc);
  1913. X        strncpy((char *) line+cs,s,cc);
  1914. X        cs += cc;
  1915. X        free(s);
  1916. X        }
  1917. X}
  1918. X
  1919. Xvoid historyincrementalsearchbackward() /**/
  1920. X{
  1921. X    doisearch(-1);
  1922. X}
  1923. X
  1924. Xvoid historyincrementalsearchforward() /**/
  1925. X{
  1926. X    doisearch(1);
  1927. X}
  1928. X
  1929. Xvoid doisearch(dir) /**/
  1930. Xint dir;
  1931. X{
  1932. Xchar *s,*oldl;
  1933. Xchar ibuf[256],*sbuf = ibuf+10;
  1934. Xint sbptr = 0,ch,ohl = histline,ocs = cs;
  1935. Xint nomatch,chequiv = 0;
  1936. X
  1937. X    strcpy(ibuf,"i-search: ");
  1938. X    statusline = ibuf;
  1939. X    oldl = ztrdup(UTOSCP(line));
  1940. X    if (histline == curhist)
  1941. X        {
  1942. X        if (curhistline)
  1943. X            free(curhistline);
  1944. X        curhistline = ztrdup(UTOSCP(line));
  1945. X        }
  1946. X    for (;;)
  1947. X        {
  1948. X        nomatch = 0;
  1949. X        if (sbptr > 1 || (sbptr == 1 && sbuf[0] != '^'))
  1950. X            {
  1951. X            int ohistline = histline;
  1952. X
  1953. X            for (;;)
  1954. X                {
  1955. X                char *t;
  1956. X
  1957. X                if (!(s = qgetevent(histline)))
  1958. X                    {
  1959. X                    feep();
  1960. X                    nomatch = 1;
  1961. X                    histline = ohistline;
  1962. X                    break;
  1963. X                    }
  1964. X                if ((sbuf[0] == '^') ?
  1965. X                        (t = (hstrncmp(s,sbuf+1,sbptr-1)) ? NULL : s) :
  1966. X                        (t = hstrnstr(s,sbuf,sbptr)))
  1967. X                    if (!(chequiv && !hstrcmp(UTOSCP(line),s)))
  1968. X                        {
  1969. X                        sethistline(STOUCP(s));
  1970. X                        cs = t-s+sbptr-(sbuf[0] == '^');
  1971. X                        break;
  1972. X                        }
  1973. X                histline += dir;
  1974. X                }
  1975. X            chequiv = 0;
  1976. X            }
  1977. X        refresh();
  1978. X        if ((ch = getkey(1)) == -1)
  1979. X            break;
  1980. X        if (ch == 22 || ch == 17) {
  1981. X            if ((ch = getkey(1)) == -1)
  1982. X                break;
  1983. X        } else if (ch == 24) { /* ^XS and ^XR */
  1984. X            if ((ch = getkey(1)) == -1)
  1985. X                break;
  1986. X            if (ch != 's' && ch != 'r') {
  1987. X                ungetkey(24);
  1988. X                ungetkey(ch);
  1989. X                break;
  1990. X            }
  1991. X            ungetkey(ch & 0x1f);
  1992. X            continue;
  1993. X        } else if (ch == 8 || ch == 127) {
  1994. X            if (sbptr)
  1995. X                sbuf[--sbptr] = '\0';
  1996. X            else
  1997. X                feep();
  1998. X            histline = ohl;
  1999. X            continue;
  2000. X        } else if (ch == 7 || ch == 3) {
  2001. X            setline(oldl);
  2002. X            cs = ocs;
  2003. X            histline = ohl;
  2004. X            statusline = NULL;
  2005. X            break;
  2006. X        } else if (ch == 27)
  2007. X            break;
  2008. X        else if (ch == 10 || ch == 13) {
  2009. X            ungetkey(ch);
  2010. X            break;
  2011. X        } else if (ch == 18) {
  2012. X            ohl = (histline += (dir = -1));
  2013. X            chequiv = 1;
  2014. X            continue;
  2015. X        } else if (ch == 19) {
  2016. X            ohl = (histline += (dir = 1));
  2017. X            chequiv = 1;
  2018. X            continue;
  2019. X        } else if (!(ch & 0x60)) {
  2020. X            ungetkey(ch);
  2021. X            break;
  2022. X        }
  2023. X        if (!nomatch && sbptr != 39 && !icntrl(ch)) {
  2024. X            sbuf[sbptr++] = ch;
  2025. X            sbuf[sbptr] = '\0';
  2026. X        }
  2027. X    }
  2028. X    free(oldl);
  2029. X    statusline = NULL;
  2030. X}
  2031. X
  2032. Xvoid acceptandinfernexthistory() /**/
  2033. X{
  2034. Xint t0;
  2035. Xchar *s,*t;
  2036. X
  2037. X    done = 1;
  2038. X    for (t0 = histline-2;;t0--)
  2039. X        {
  2040. X        if (!(s = qgetevent(t0)))
  2041. X            return;
  2042. X        if (!hstrncmp(s,UTOSCP(line),ll))
  2043. X            break;
  2044. X        }
  2045. X    if (!(s = qgetevent(t0+1)))
  2046. X        return;
  2047. X    pushnode(bufstack,t = ztrdup(s));
  2048. X    for (; *t; t++)
  2049. X        if (*t == HISTSPACE)
  2050. X            *t = ' ';
  2051. X    stackhist = t0+1;
  2052. X}
  2053. X
  2054. Xvoid infernexthistory() /**/
  2055. X{
  2056. Xint t0;
  2057. Xchar *s,*t;
  2058. X
  2059. X    if (!(t = qgetevent(histline-1)))
  2060. X        {
  2061. X        feep();
  2062. X        return;
  2063. X        }
  2064. X    for (t0 = histline-2;;t0--)
  2065. X        {
  2066. X        if (!(s = qgetevent(t0)))
  2067. X            {
  2068. X            feep();
  2069. X            return;
  2070. X            }
  2071. X        if (!strcmp(s,t))
  2072. X            break;
  2073. X        }
  2074. X    if (!(s = qgetevent(t0+1)))
  2075. X        {
  2076. X        feep();
  2077. X        return;
  2078. X        }
  2079. X    histline = t0+1;
  2080. X    sethistline(STOUCP(s));
  2081. X}
  2082. X
  2083. Xvoid vifetchhistory() /**/
  2084. X{
  2085. Xchar *s;
  2086. X
  2087. X    if (mult < 0) return;
  2088. X    if (histline == curhist) {
  2089. X        if (!(lastcmd & ZLE_ARG)) {
  2090. X            cs = ll;
  2091. X            cs = findbol();
  2092. X            return;
  2093. X        }
  2094. X        if (curhistline)
  2095. X            free(curhistline);
  2096. X        curhistline = ztrdup(UTOSCP(line));
  2097. X    }
  2098. X    if (!(lastcmd & ZLE_ARG)) mult = curhist;
  2099. X    if (!(s = qgetevent(mult)))
  2100. X        feep();
  2101. X    else {
  2102. X        histline = mult;
  2103. X        sethistline(STOUCP(s));
  2104. X    }
  2105. X}
  2106. X
  2107. Xint getvisrchstr() /**/
  2108. X{
  2109. Xstatic char sbuf[80];
  2110. Xint sptr = 1;
  2111. X
  2112. X    if (visrchstr)
  2113. X        {
  2114. X        free(visrchstr);
  2115. X        visrchstr = NULL;
  2116. X        }
  2117. X    statusline = sbuf;
  2118. X    sbuf[0] = c;
  2119. X    sbuf[1] = '\0';
  2120. X    while (sptr)
  2121. X        {
  2122. X        refresh();
  2123. X        c = getkey(0);
  2124. X        if (c == '\r' || c == '\n' || c == '\033')
  2125. X            {
  2126. X            visrchstr = ztrdup(sbuf+1);
  2127. X            return 1;
  2128. X            }
  2129. X        if (c == '\b' || c == 127)
  2130. X            {
  2131. X            sbuf[--sptr] = '\0';
  2132. X            continue;
  2133. X            }
  2134. X        if (sptr != 79)
  2135. X            {
  2136. X            sbuf[sptr++] = c;
  2137. X            sbuf[sptr] = '\0';
  2138. X            }
  2139. X        }
  2140. X    return 0;
  2141. X}
  2142. X
  2143. Xvoid vihistorysearchforward() /**/
  2144. X{
  2145. X    visrchsense = 1;
  2146. X    if (getvisrchstr())
  2147. X        virepeatsearch();
  2148. X}
  2149. X
  2150. Xvoid vihistorysearchbackward() /**/
  2151. X{
  2152. X    visrchsense = -1;
  2153. X    if (getvisrchstr())
  2154. X        virepeatsearch();
  2155. X}
  2156. X
  2157. Xvoid virepeatsearch() /**/
  2158. X{
  2159. Xint ohistline = histline,t0;
  2160. Xchar *s;
  2161. X
  2162. X    if (!visrchstr)
  2163. X        {
  2164. X        feep();
  2165. X        return;
  2166. X        }
  2167. X    t0 = strlen(visrchstr);
  2168. X    if (histline == curhist)
  2169. X        {
  2170. X        if (curhistline)
  2171. X            free(curhistline);
  2172. X        curhistline = ztrdup(UTOSCP(line));
  2173. X        }
  2174. X    for (;;)
  2175. X        {
  2176. X        histline += visrchsense;
  2177. X        if (!(s = qgetevent(histline)))
  2178. X            {
  2179. X            feep();
  2180. X            histline = ohistline;
  2181. X            return;
  2182. X            }
  2183. X        if (!hstrcmp(UTOSCP(line),s))
  2184. X            continue;
  2185. X        if (*visrchstr == '^')
  2186. X            {
  2187. X            if (!hstrncmp(s,visrchstr+1,t0-1))
  2188. X                break;
  2189. X            }
  2190. X        else
  2191. X            if (hstrnstr(s,visrchstr,t0))
  2192. X                break;
  2193. X        }
  2194. X    sethistline(STOUCP(s));
  2195. X}
  2196. X
  2197. Xvoid virevrepeatsearch() /**/
  2198. X{
  2199. X    visrchsense = -visrchsense;
  2200. X    virepeatsearch();
  2201. X    visrchsense = -visrchsense;
  2202. X}
  2203. X
  2204. END_OF_FILE
  2205.   if test 11190 -ne `wc -c <'src/zle_hist.c'`; then
  2206.     echo shar: \"'src/zle_hist.c'\" unpacked with wrong size!
  2207.   fi
  2208.   # end of 'src/zle_hist.c'
  2209. fi
  2210. echo shar: End of archive 19 \(of 22\).
  2211. cp /dev/null ark19isdone
  2212. MISSING=""
  2213. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 ; do
  2214.     if test ! -f ark${I}isdone ; then
  2215.     MISSING="${MISSING} ${I}"
  2216.     fi
  2217. done
  2218. if test "${MISSING}" = "" ; then
  2219.     echo You have unpacked all 22 archives.
  2220.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2221. else
  2222.     echo You still must unpack the following archives:
  2223.     echo "        " ${MISSING}
  2224. fi
  2225. exit 0
  2226.  
  2227. exit 0 # Just in case...
  2228.