home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume35 / zsh / part21 < prev    next >
Encoding:
Text File  |  1993-02-19  |  53.8 KB  |  2,072 lines

  1. Newsgroups: comp.sources.misc
  2. From: zsh-list@cs.uow.edu.au (The Zsh Mailing List)
  3. Subject: v35i071:  zsh - The Z Shell, version 2.3.1, Part21/22
  4. Message-ID: <1993Feb20.212933.29601@sparky.imd.sterling.com>
  5. X-Md4-Signature: 3af96160e13951c12d61a0b6f809ec60
  6. Date: Sat, 20 Feb 1993 21:29:33 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 71
  11. Archive-name: zsh/part21
  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:  NOTES func/run-help func/zed help/alias help/cd
  22. #   help/compctl help/dirs help/echo help/elif help/else help/for
  23. #   help/foreach help/function help/getopts help/if help/kill
  24. #   help/print help/select help/set help/ttyctl help/ulimit
  25. #   help/unhash help/unset help/whence help/which src/cond.c
  26. #   src/loop.c src/mem.c src/zle_move.c src/zle_utils.c
  27. # Wrapped by mattson@odin on Sat Feb  6 14:41:56 1993
  28. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  29. echo If this archive is complete, you will see the following message:
  30. echo '          "shar: End of archive 21 (of 22)."'
  31. if test -f 'NOTES' -a "${1}" != "-c" ; then 
  32.   echo shar: Will not clobber existing file \"'NOTES'\"
  33. else
  34.   echo shar: Extracting \"'NOTES'\" \(507 characters\)
  35.   sed "s/^X//" >'NOTES' <<'END_OF_FILE'
  36. XImportant notes:
  37. X
  38. X1. Stuff like "ls *.sdofij 2>/dev/null" to suppress error messages
  39. X   produced by the shell doesn't work anymore.  Filename generation is
  40. X   done BEFORE redirection.  To avoid the error message, use the
  41. X   nonomatch option, or do "( ls *.sdofij ) 2>/dev/null".
  42. X
  43. X2. History substitution is no longer done inside startup files.  If you
  44. X   have sequences like \! or !" in your startup files, they will break.
  45. X   (Especially !").  So check for those; remove the !", and change the
  46. X   \! to !.
  47. END_OF_FILE
  48.   if test 507 -ne `wc -c <'NOTES'`; then
  49.     echo shar: \"'NOTES'\" unpacked with wrong size!
  50.   fi
  51.   # end of 'NOTES'
  52. fi
  53. if test -f 'func/run-help' -a "${1}" != "-c" ; then 
  54.   echo shar: Will not clobber existing file \"'func/run-help'\"
  55. else
  56.   echo shar: Extracting \"'func/run-help'\" \(376 characters\)
  57.   sed "s/^X//" >'func/run-help' <<'END_OF_FILE'
  58. X#! /bin/zsh
  59. X# zsh script to peruse the help directory
  60. X#
  61. Xif [[ $1 = "-l" ]]; then
  62. X  if [[ ${HELPDIR:-} != "" ]]; then
  63. X    echo 'Here is a list of topics for which help is available:'
  64. X    echo ""
  65. X    ls $HELPDIR
  66. X  else
  67. X    echo 'There is no help available at this time'
  68. X  fi
  69. Xelif [[ ${HELPDIR:-} != "" && -r $HELPDIR/$1 ]]
  70. Xthen
  71. X    ${PAGER:-more} $HELPDIR/$1
  72. Xelse
  73. X    man $1
  74. Xfi
  75. END_OF_FILE
  76.   if test 376 -ne `wc -c <'func/run-help'`; then
  77.     echo shar: \"'func/run-help'\" unpacked with wrong size!
  78.   fi
  79.   chmod +x 'func/run-help'
  80.   # end of 'func/run-help'
  81. fi
  82. if test -f 'func/zed' -a "${1}" != "-c" ; then 
  83.   echo shar: Will not clobber existing file \"'func/zed'\"
  84. else
  85.   echo shar: Extracting \"'func/zed'\" \(511 characters\)
  86.   sed "s/^X//" >'func/zed' <<'END_OF_FILE'
  87. X#!/bin/zsh
  88. X# Edit small files with the command line editor.
  89. X# You can even stick bits of the history list in it.
  90. X
  91. Xlocal var
  92. X
  93. X# (Don't) catch interrupts
  94. X# trap 'bindkey "^M" accept-line ; trap - 2 3; return 0' 2 3
  95. X
  96. Xbindkey "^M" self-insert-unmeta
  97. Xbindkey "^X^W" accept-line
  98. X
  99. X[[ -z "$1" ]] && echo 'Usage: zed filename' && return 1
  100. X[[ -f $1 ]] && var="$(<$1)"
  101. Xvared var
  102. Xprint -R "$var" >! $1
  103. X
  104. Xbindkey "^M" accept-line
  105. Xbindkey "^X^W" undefined-key
  106. X
  107. X# (Don't) release interrupts
  108. X# trap - 2 3
  109. X
  110. Xreturn 0
  111. X
  112. X#End of zed
  113. END_OF_FILE
  114.   if test 511 -ne `wc -c <'func/zed'`; then
  115.     echo shar: \"'func/zed'\" unpacked with wrong size!
  116.   fi
  117.   chmod +x 'func/zed'
  118.   # end of 'func/zed'
  119. fi
  120. if test -f 'help/alias' -a "${1}" != "-c" ; then 
  121.   echo shar: Will not clobber existing file \"'help/alias'\"
  122. else
  123.   echo shar: Extracting \"'help/alias'\" \(781 characters\)
  124.   sed "s/^X//" >'help/alias' <<'END_OF_FILE'
  125. X     alias [ -g ] [ name[=value] ] ...
  126. X          With no arguments, print the list  of  aliases  in  the
  127. X          form  name=value on the standard output.  For each name
  128. X          with a corresponding value, define an alias  with  that
  129. X          value.   A trailing space in value causes the next word
  130. X          to be checked for alias substitution.  If the  -g  flag
  131. X          is  present,  define a global alias; global aliases are
  132. X          expanded even if they do not occur in command position.
  133. X          For  each  name with no value, print the value of name,
  134. X          if any.  The exit status is nonzero if a name (with  no
  135. X          value) given for which no alias has been defined.
  136. X     unalias name ...
  137. X          The alias definition, if any, for each name is removed.
  138. END_OF_FILE
  139.   if test 781 -ne `wc -c <'help/alias'`; then
  140.     echo shar: \"'help/alias'\" unpacked with wrong size!
  141.   fi
  142.   # end of 'help/alias'
  143. fi
  144. if test -f 'help/cd' -a "${1}" != "-c" ; then 
  145.   echo shar: Will not clobber existing file \"'help/cd'\"
  146. else
  147.   echo shar: Extracting \"'help/cd'\" \(934 characters\)
  148.   sed "s/^X//" >'help/cd' <<'END_OF_FILE'
  149. X     cd [ arg ]
  150. X     cd old new
  151. X     cd +-n
  152. X          Change the  current  directory.   In  the  first  form,
  153. X          change the current directory to arg, or to the value of
  154. X          HOME if arg is not specified.  If arg is -,  change  to
  155. X          the  value  of  OLDPWD,  the  previous directory.  If a
  156. X          directory named arg is not found in the current  direc-
  157. X          tory  and  arg does not begin with a slash, search each
  158. X          component of the shell parameter cdpath.  If the option
  159. X          CDABLEVARS  is  set,  and  a parameter named arg exists
  160. X          whose value begins with a slash, treat its value as the
  161. X          directory.
  162. X
  163. X          The second form of cd substitutes the  string  new  for
  164. X          the  string  old  in the name of the current directory,
  165. X          and tries to change to this new directory.
  166. X
  167. X          The third form of cd is equivalent to popd.
  168. X
  169. X     chdir
  170. X          Same as cd.
  171. END_OF_FILE
  172.   if test 934 -ne `wc -c <'help/cd'`; then
  173.     echo shar: \"'help/cd'\" unpacked with wrong size!
  174.   fi
  175.   # end of 'help/cd'
  176. fi
  177. if test -f 'help/compctl' -a "${1}" != "-c" ; then 
  178.   echo shar: Will not clobber existing file \"'help/compctl'\"
  179. else
  180.   echo shar: Extracting \"'help/compctl'\" \(906 characters\)
  181.   sed "s/^X//" >'help/compctl' <<'END_OF_FILE'
  182. X     compctl [ -cfhovbCD ] [ -k name ] [ arg ... ]
  183. X          Control the editor's completion behavior  when  one  of
  184. X          arg  is the current command.  With the -D flag, control
  185. X          default completion behavior for commands  not  assigned
  186. X          any  special behavior; with -C, control completion when
  187. X          there is no current  command.   The  remaining  options
  188. X          specify  the type of command arguments to look for dur-
  189. X          ing completion.  For example,  compctl  -hf  rlogin  is
  190. X          equivalent to hostcmds=(rlogin).
  191. X          -c   Expect command names.
  192. X          -f   Expect filenames and filesystem paths.
  193. X          -h   Expect hostnames taken from the $hosts variable.
  194. X          -o   Expect option names.
  195. X          -v   Expect variable names.
  196. X          -b   Expect key binding names.
  197. X          -k name
  198. X               Expect names taken from the elements of $name.
  199. END_OF_FILE
  200.   if test 906 -ne `wc -c <'help/compctl'`; then
  201.     echo shar: \"'help/compctl'\" unpacked with wrong size!
  202.   fi
  203.   # end of 'help/compctl'
  204. fi
  205. if test -f 'help/dirs' -a "${1}" != "-c" ; then 
  206.   echo shar: Will not clobber existing file \"'help/dirs'\"
  207. else
  208.   echo shar: Extracting \"'help/dirs'\" \(517 characters\)
  209.   sed "s/^X//" >'help/dirs' <<'END_OF_FILE'
  210. X     dirs [ -v ] [ arg ... ]
  211. X          With no arguments, print the contents of the  directory
  212. X          stack.   If  the  -v option is given, number the direc-
  213. X          tories in the stack  when  printing.   Directories  are
  214. X          added to this stack with the pushd command, and removed
  215. X          with the cd or popd commands.  If arguments are  speci-
  216. X          fied,  load  them  onto  the directory stack, replacing
  217. X          anything that was there, and push the current directory
  218. X          onto the stack.
  219. END_OF_FILE
  220.   if test 517 -ne `wc -c <'help/dirs'`; then
  221.     echo shar: \"'help/dirs'\" unpacked with wrong size!
  222.   fi
  223.   # end of 'help/dirs'
  224. fi
  225. if test -f 'help/echo' -a "${1}" != "-c" ; then 
  226.   echo shar: Will not clobber existing file \"'help/echo'\"
  227. else
  228.   echo shar: Extracting \"'help/echo'\" \(555 characters\)
  229.   sed "s/^X//" >'help/echo' <<'END_OF_FILE'
  230. X     echo [ -n ] [ arg ... ]
  231. X          Write each arg on the standard  output,  with  a  space
  232. X          separating  each  one.   If the -n flag is not present,
  233. X          print a newline at the end.  echo recognizes  the  fol-
  234. X          lowing escape sequences:
  235. X          \b   backspace
  236. X          \c   don't print an ending newline
  237. X          \e   escape
  238. X          \f   form feed
  239. X          \n   newline
  240. X          \r   carriage return
  241. X          \t   horizontal tab
  242. X          \v   vertical tab
  243. X          \\   backslash
  244. X          \xxx character code in octal
  245. END_OF_FILE
  246.   if test 555 -ne `wc -c <'help/echo'`; then
  247.     echo shar: \"'help/echo'\" unpacked with wrong size!
  248.   fi
  249.   # end of 'help/echo'
  250. fi
  251. if test -f 'help/elif' -a "${1}" != "-c" ; then 
  252.   echo shar: Will not clobber existing file \"'help/elif'\"
  253. else
  254.   echo shar: Extracting \"'help/elif'\" \(550 characters\)
  255.   sed "s/^X//" >'help/elif' <<'END_OF_FILE'
  256. X      if list
  257. X      then list
  258. X      [ elif list ; then list ] ...
  259. X      [ else list ]
  260. X      fi   The if list is executed, and, if it returns a zero
  261. X       exit  status,  the  then list is executed.  Other-
  262. X       wise, the elif list is executed and, if its  value
  263. X       is  zero, the then list is executed.  If each elif
  264. X       list returns nonzero, the else list is executed.
  265. X
  266. X      if ( list ) sublist
  267. X       A short form of if.
  268. X
  269. X      if ( list ) {
  270. X      list
  271. X      } elif ( list ) {
  272. X      list
  273. X      } ... else {
  274. X      list
  275. X      }    An alternate form of if.
  276. END_OF_FILE
  277.   if test 550 -ne `wc -c <'help/elif'`; then
  278.     echo shar: \"'help/elif'\" unpacked with wrong size!
  279.   fi
  280.   # end of 'help/elif'
  281. fi
  282. if test -f 'help/else' -a "${1}" != "-c" ; then 
  283.   echo shar: Will not clobber existing file \"'help/else'\"
  284. else
  285.   echo shar: Extracting \"'help/else'\" \(550 characters\)
  286.   sed "s/^X//" >'help/else' <<'END_OF_FILE'
  287. X      if list
  288. X      then list
  289. X      [ elif list ; then list ] ...
  290. X      [ else list ]
  291. X      fi   The if list is executed, and, if it returns a zero
  292. X       exit  status,  the  then list is executed.  Other-
  293. X       wise, the elif list is executed and, if its  value
  294. X       is  zero, the then list is executed.  If each elif
  295. X       list returns nonzero, the else list is executed.
  296. X
  297. X      if ( list ) sublist
  298. X       A short form of if.
  299. X
  300. X      if ( list ) {
  301. X      list
  302. X      } elif ( list ) {
  303. X      list
  304. X      } ... else {
  305. X      list
  306. X      }    An alternate form of if.
  307. END_OF_FILE
  308.   if test 550 -ne `wc -c <'help/else'`; then
  309.     echo shar: \"'help/else'\" unpacked with wrong size!
  310.   fi
  311.   # end of 'help/else'
  312. fi
  313. if test -f 'help/for' -a "${1}" != "-c" ; then 
  314.   echo shar: Will not clobber existing file \"'help/for'\"
  315. else
  316.   echo shar: Extracting \"'help/for'\" \(793 characters\)
  317.   sed "s/^X//" >'help/for' <<'END_OF_FILE'
  318. X      for name [ in word ... ]
  319. X      do list
  320. X      done Expand the list of words, and  set  the  parameter
  321. X       name  to each of them in turn, executing list each
  322. X       time.  If the in word is omitted,  use  the  posi-
  323. X       tional parameters instead of the words.
  324. X
  325. X      for name [ in word ... ] ; sublist
  326. X       This is a shorthand for for.  Though it may  cause
  327. X       confusion, it is included for convenience; its use
  328. X       in scripts is discouraged,  unless  sublist  is  a
  329. X       command of the form { list }.
  330. X
  331. X      foreach name ( word ... )
  332. X      list
  333. X      end  Another form of for.
  334. X
  335. X      for name in word ...
  336. X      {
  337. X      list
  338. X      }    Another form of for.
  339. X
  340. X      for name ( word ... ) {
  341. X      list
  342. X      }    Another form of for.
  343. X
  344. X      for name ( word ... ) sublist
  345. X       Another form of for.
  346. END_OF_FILE
  347.   if test 793 -ne `wc -c <'help/for'`; then
  348.     echo shar: \"'help/for'\" unpacked with wrong size!
  349.   fi
  350.   # end of 'help/for'
  351. fi
  352. if test -f 'help/foreach' -a "${1}" != "-c" ; then 
  353.   echo shar: Will not clobber existing file \"'help/foreach'\"
  354. else
  355.   echo shar: Extracting \"'help/foreach'\" \(793 characters\)
  356.   sed "s/^X//" >'help/foreach' <<'END_OF_FILE'
  357. X      for name [ in word ... ]
  358. X      do list
  359. X      done Expand the list of words, and  set  the  parameter
  360. X       name  to each of them in turn, executing list each
  361. X       time.  If the in word is omitted,  use  the  posi-
  362. X       tional parameters instead of the words.
  363. X
  364. X      for name [ in word ... ] ; sublist
  365. X       This is a shorthand for for.  Though it may  cause
  366. X       confusion, it is included for convenience; its use
  367. X       in scripts is discouraged,  unless  sublist  is  a
  368. X       command of the form { list }.
  369. X
  370. X      foreach name ( word ... )
  371. X      list
  372. X      end  Another form of for.
  373. X
  374. X      for name in word ...
  375. X      {
  376. X      list
  377. X      }    Another form of for.
  378. X
  379. X      for name ( word ... ) {
  380. X      list
  381. X      }    Another form of for.
  382. X
  383. X      for name ( word ... ) sublist
  384. X       Another form of for.
  385. END_OF_FILE
  386.   if test 793 -ne `wc -c <'help/foreach'`; then
  387.     echo shar: \"'help/foreach'\" unpacked with wrong size!
  388.   fi
  389.   # end of 'help/foreach'
  390. fi
  391. if test -f 'help/function' -a "${1}" != "-c" ; then 
  392.   echo shar: Will not clobber existing file \"'help/function'\"
  393. else
  394.   echo shar: Extracting \"'help/function'\" \(360 characters\)
  395.   sed "s/^X//" >'help/function' <<'END_OF_FILE'
  396. X      function word [ () ] ... { list }
  397. X      word ... () { list }
  398. X      word ... () sublist
  399. X       Define a function which is referenced by  any  one
  400. X       of  word.   Normally,  only  one word is provided;
  401. X       multiple words are usually only useful for setting
  402. X       traps.   The  body  of  the  function  is the list
  403. X       between the { and }.  See FUNCTIONS below.
  404. END_OF_FILE
  405.   if test 360 -ne `wc -c <'help/function'`; then
  406.     echo shar: \"'help/function'\" unpacked with wrong size!
  407.   fi
  408.   # end of 'help/function'
  409. fi
  410. if test -f 'help/getopts' -a "${1}" != "-c" ; then 
  411.   echo shar: Will not clobber existing file \"'help/getopts'\"
  412. else
  413.   echo shar: Extracting \"'help/getopts'\" \(1207 characters\)
  414.   sed "s/^X//" >'help/getopts' <<'END_OF_FILE'
  415. X     getopts optstring name [ arg ... ]
  416. X          Checks arg for legal options.  If arg is  omitted,  use
  417. X          the  positional  parameters.   A  valid option argument
  418. X          begins with a + or a -.  An argument not beginning with
  419. X          a + or a -, or the argument --, ends the options.  opt-
  420. X          string contains the letters  that  getopts  recognizes.
  421. X          If  a  letter  is  followed  by  a  `:', that option is
  422. X          expected to have  an  argument.   The  options  can  be
  423. X          separated from the argument by blanks.
  424. X
  425. X          Each time it is  invoked,  getopts  places  the  option
  426. X          letter  it finds in the shell parameter name, prepended
  427. X          with a + when arg begins with a +.  The  index  of  the
  428. X          next  arg is stored in OPTIND.  The option argument, if
  429. X          any, is stored in OPTARG.
  430. X
  431. X          A leading : in optstring causes getopts  to  store  the
  432. X          letter of the invalid option in OPTARG, and to set name
  433. X          to `?' for an unknown option and to `:' when a required
  434. X          option  is missing.  Otherwise, getopts prints an error
  435. X          message.  The exit status is nonzero when there are  no
  436. X          more options.
  437. END_OF_FILE
  438.   if test 1207 -ne `wc -c <'help/getopts'`; then
  439.     echo shar: \"'help/getopts'\" unpacked with wrong size!
  440.   fi
  441.   # end of 'help/getopts'
  442. fi
  443. if test -f 'help/if' -a "${1}" != "-c" ; then 
  444.   echo shar: Will not clobber existing file \"'help/if'\"
  445. else
  446.   echo shar: Extracting \"'help/if'\" \(550 characters\)
  447.   sed "s/^X//" >'help/if' <<'END_OF_FILE'
  448. X      if list
  449. X      then list
  450. X      [ elif list ; then list ] ...
  451. X      [ else list ]
  452. X      fi   The if list is executed, and, if it returns a zero
  453. X       exit  status,  the  then list is executed.  Other-
  454. X       wise, the elif list is executed and, if its  value
  455. X       is  zero, the then list is executed.  If each elif
  456. X       list returns nonzero, the else list is executed.
  457. X
  458. X      if ( list ) sublist
  459. X       A short form of if.
  460. X
  461. X      if ( list ) {
  462. X      list
  463. X      } elif ( list ) {
  464. X      list
  465. X      } ... else {
  466. X      list
  467. X      }    An alternate form of if.
  468. END_OF_FILE
  469.   if test 550 -ne `wc -c <'help/if'`; then
  470.     echo shar: \"'help/if'\" unpacked with wrong size!
  471.   fi
  472.   # end of 'help/if'
  473. fi
  474. if test -f 'help/kill' -a "${1}" != "-c" ; then 
  475.   echo shar: Will not clobber existing file \"'help/kill'\"
  476. else
  477.   echo shar: Extracting \"'help/kill'\" \(524 characters\)
  478.   sed "s/^X//" >'help/kill' <<'END_OF_FILE'
  479. X     kill [ -sig ] job ...
  480. X     kill -l
  481. X          Sends either SIGTERM or the  specified  signal  to  the
  482. X          given  jobs  or processes.  Signals are given by number
  483. X          or by names (with the prefix "SIG"  removed).   If  the
  484. X          signal  being  sent  is  not KILL or CONT, then the job
  485. X          will be sent a CONT signal if it is stopped.  The argu-
  486. X          ment  job can be the process id of a job not in the job
  487. X          list.  In the second form, kill -l,  the  signal  names
  488. X          are listed.
  489. END_OF_FILE
  490.   if test 524 -ne `wc -c <'help/kill'`; then
  491.     echo shar: \"'help/kill'\" unpacked with wrong size!
  492.   fi
  493.   # end of 'help/kill'
  494. fi
  495. if test -f 'help/print' -a "${1}" != "-c" ; then 
  496.   echo shar: Will not clobber existing file \"'help/print'\"
  497. else
  498.   echo shar: Extracting \"'help/print'\" \(1151 characters\)
  499.   sed "s/^X//" >'help/print' <<'END_OF_FILE'
  500. X     print [ -RnrslzpNDP ] [ -un ] [ arg ... ]
  501. X          With no flags or with flag -, the arguments are printed
  502. X          on the standard output as described by echo.
  503. X          -R, -r
  504. X               ignore the escape conventions  of  echo.   The  -R
  505. X               option  will  print  all  subsequent arguments and
  506. X               options.
  507. X          -s   place the results in the history list  instead  of
  508. X               on the standard output.
  509. X          -n   do not add a newline to the output.
  510. X          -l   print the arguments separated by newlines  instead
  511. X               of spaces.
  512. X          -N   print the arguments separated  and  terminated  by
  513. X               nulls.
  514. X          -un  print the arguments to file descriptor n.
  515. X          -p   print the arguments to the input of the coprocess.
  516. X          -z   push the arguments onto the editing buffer  stack,
  517. X               separated  by  spaces;  no  escape  sequences  are
  518. X               recognized.
  519. X          -D   treat the arguments as directory names,  replacing
  520. X               prefixes with ~ expressions, as appropriate.
  521. X          -P   recognize the same  escape  sequences  as  in  the
  522. END_OF_FILE
  523.   if test 1151 -ne `wc -c <'help/print'`; then
  524.     echo shar: \"'help/print'\" unpacked with wrong size!
  525.   fi
  526.   # end of 'help/print'
  527. fi
  528. if test -f 'help/select' -a "${1}" != "-c" ; then 
  529.   echo shar: Will not clobber existing file \"'help/select'\"
  530. else
  531.   echo shar: Extracting \"'help/select'\" \(812 characters\)
  532.   sed "s/^X//" >'help/select' <<'END_OF_FILE'
  533. X      select name [ in word ... ]
  534. X      do list
  535. X      done Print the set of words, each preceded by a number.
  536. X       If  the  in  word  is  omitted, use the positional
  537. X       parameters.  The PROMPT3 prompt is printed  and  a
  538. X       line  is  read  from standard input.  If this line
  539. X       consists of the number of one of the listed words,
  540. X       then  the  parameter  name  is  set  to  the  word
  541. X       corresponding to this number.   If  this  line  is
  542. X       empty,  the selection list is printed again.  Oth-
  543. X       erwise, the value of the parameter name is set  to
  544. X       null.  The contents of the line read from standard
  545. X       input is saved in the parameter  REPLY.   list  is
  546. X       executed  for each selection until a break or end-
  547. X       of-file is encountered.
  548. X
  549. X      select name [ in word ] ; sublist
  550. X       A short form of select.
  551. END_OF_FILE
  552.   if test 812 -ne `wc -c <'help/select'`; then
  553.     echo shar: \"'help/select'\" unpacked with wrong size!
  554.   fi
  555.   # end of 'help/select'
  556. fi
  557. if test -f 'help/set' -a "${1}" != "-c" ; then 
  558.   echo shar: Will not clobber existing file \"'help/set'\"
  559. else
  560.   echo shar: Extracting \"'help/set'\" \(745 characters\)
  561.   sed "s/^X//" >'help/set' <<'END_OF_FILE'
  562. X     set [ +-options ] [ +-o option name ] ... [ -A name ] [ arg ] ...
  563. X          Set the options for the shell and/or set the positional
  564. X          parameters, or declare an array.  For  the  meaning  of
  565. X          the  flags,  see OPTIONS above.  Flags may be specified
  566. X          by name using the -o option.  If the -A flag is  speci-
  567. X          fied,  name  is  set  to  an array containing the given
  568. X          args.  Otherwise the positional parameters are set.  If
  569. X          no  arguments  are  given, then the names and values of
  570. X          all parameters are printed on the standard output.   If
  571. X          the only argument is +, the names of all parameters are
  572. X          printed.
  573. X     unset name ...
  574. X          Each named parameter is unset.
  575. END_OF_FILE
  576.   if test 745 -ne `wc -c <'help/set'`; then
  577.     echo shar: \"'help/set'\" unpacked with wrong size!
  578.   fi
  579.   # end of 'help/set'
  580. fi
  581. if test -f 'help/ttyctl' -a "${1}" != "-c" ; then 
  582.   echo shar: Will not clobber existing file \"'help/ttyctl'\"
  583. else
  584.   echo shar: Extracting \"'help/ttyctl'\" \(437 characters\)
  585.   sed "s/^X//" >'help/ttyctl' <<'END_OF_FILE'
  586. X     ttyctl -fu
  587. X          The -f option freezes the tty,  and  -u  unfreezes  it.
  588. X          When the tty is frozen, no changes made to the tty set-
  589. X          tings by external  programs  will  be  honored  by  the
  590. X          shell;  the  shell  will  simply  reset the settings to
  591. X          their previous values as soon as  each  command  exits.
  592. X          Thus, stty and similar programs have no effect when the
  593. X          tty is frozen.
  594. END_OF_FILE
  595.   if test 437 -ne `wc -c <'help/ttyctl'`; then
  596.     echo shar: \"'help/ttyctl'\" unpacked with wrong size!
  597.   fi
  598.   # end of 'help/ttyctl'
  599. fi
  600. if test -f 'help/ulimit' -a "${1}" != "-c" ; then 
  601.   echo shar: Will not clobber existing file \"'help/ulimit'\"
  602. else
  603.   echo shar: Extracting \"'help/ulimit'\" \(890 characters\)
  604.   sed "s/^X//" >'help/ulimit' <<'END_OF_FILE'
  605. X     ulimit [ -HSacdfmnt ] [ limit ]
  606. X          Set or display a resource limit.  The  value  of  limit
  607. X          can  be  a  number  in  the unit specified below or the
  608. X          value unlimited.  The H and S flags specify whether the
  609. X          hard  limit or the soft limit for the given resource is
  610. X          set.
  611. X          -a   Lists all of the current resource limits.
  612. X          -c   The number of 512-byte blocks on the size of  core
  613. X               dumps.
  614. X          -d   The number of K-bytes on the size of the data seg-
  615. X               ment.
  616. X          -f   The number of 512-byte blocks on the size of files
  617. X               written.
  618. X          -m   The number of K-bytes  on  the  size  of  physical
  619. X               memory.
  620. X          -n   The number of file descriptors.
  621. X          -s   The number of K-bytes on the size of the stack.
  622. X          -t   The number of CPU seconds to be used.
  623. END_OF_FILE
  624.   if test 890 -ne `wc -c <'help/ulimit'`; then
  625.     echo shar: \"'help/ulimit'\" unpacked with wrong size!
  626.   fi
  627.   # end of 'help/ulimit'
  628. fi
  629. if test -f 'help/unhash' -a "${1}" != "-c" ; then 
  630.   echo shar: Will not clobber existing file \"'help/unhash'\"
  631. else
  632.   echo shar: Extracting \"'help/unhash'\" \(362 characters\)
  633.   sed "s/^X//" >'help/unhash' <<'END_OF_FILE'
  634. X     hash name path
  635. X          Puts name in the command  hash  table,  associating  it
  636. X          with  the  pathname  path.   Whenever name is used as a
  637. X          command argument, the shell will  try  to  execute  the
  638. X          file given by path.
  639. X     unhash name ...
  640. X          The entry in the command hash table, if any,  for  each
  641. X          name is removed.
  642. END_OF_FILE
  643.   if test 362 -ne `wc -c <'help/unhash'`; then
  644.     echo shar: \"'help/unhash'\" unpacked with wrong size!
  645.   fi
  646.   # end of 'help/unhash'
  647. fi
  648. if test -f 'help/unset' -a "${1}" != "-c" ; then 
  649.   echo shar: Will not clobber existing file \"'help/unset'\"
  650. else
  651.   echo shar: Extracting \"'help/unset'\" \(745 characters\)
  652.   sed "s/^X//" >'help/unset' <<'END_OF_FILE'
  653. X     set [ +-options ] [ +-o option name ] ... [ -A name ] [ arg ] ...
  654. X          Set the options for the shell and/or set the positional
  655. X          parameters, or declare an array.  For  the  meaning  of
  656. X          the  flags,  see OPTIONS above.  Flags may be specified
  657. X          by name using the -o option.  If the -A flag is  speci-
  658. X          fied,  name  is  set  to  an array containing the given
  659. X          args.  Otherwise the positional parameters are set.  If
  660. X          no  arguments  are  given, then the names and values of
  661. X          all parameters are printed on the standard output.   If
  662. X          the only argument is +, the names of all parameters are
  663. X          printed.
  664. X     unset name ...
  665. X          Each named parameter is unset.
  666. END_OF_FILE
  667.   if test 745 -ne `wc -c <'help/unset'`; then
  668.     echo shar: \"'help/unset'\" unpacked with wrong size!
  669.   fi
  670.   # end of 'help/unset'
  671. fi
  672. if test -f 'help/whence' -a "${1}" != "-c" ; then 
  673.   echo shar: Will not clobber existing file \"'help/whence'\"
  674. else
  675.   echo shar: Extracting \"'help/whence'\" \(515 characters\)
  676.   sed "s/^X//" >'help/whence' <<'END_OF_FILE'
  677. X     whence [ -acpv ] name ...
  678. X          For each name, indicate how it would be interpreted  if
  679. X          used  as  a  command name.  The -v flag produces a more
  680. X          verbose report.  The -p flag does  a  path  search  for
  681. X          name even if it is a shell function, alias, or reserved
  682. X          word.  The -c flag prints the  results  in  a  csh-like
  683. X          format.   The  -a flag does a search for all occurences
  684. X          of name throughout the command path.
  685. X
  686. X     which
  687. X          Same as whence -c.
  688. END_OF_FILE
  689.   if test 515 -ne `wc -c <'help/whence'`; then
  690.     echo shar: \"'help/whence'\" unpacked with wrong size!
  691.   fi
  692.   # end of 'help/whence'
  693. fi
  694. if test -f 'help/which' -a "${1}" != "-c" ; then 
  695.   echo shar: Will not clobber existing file \"'help/which'\"
  696. else
  697.   echo shar: Extracting \"'help/which'\" \(515 characters\)
  698.   sed "s/^X//" >'help/which' <<'END_OF_FILE'
  699. X     whence [ -acpv ] name ...
  700. X          For each name, indicate how it would be interpreted  if
  701. X          used  as  a  command name.  The -v flag produces a more
  702. X          verbose report.  The -p flag does  a  path  search  for
  703. X          name even if it is a shell function, alias, or reserved
  704. X          word.  The -c flag prints the  results  in  a  csh-like
  705. X          format.   The  -a flag does a search for all occurences
  706. X          of name throughout the command path.
  707. X
  708. X     which
  709. X          Same as whence -c.
  710. END_OF_FILE
  711.   if test 515 -ne `wc -c <'help/which'`; then
  712.     echo shar: \"'help/which'\" unpacked with wrong size!
  713.   fi
  714.   # end of 'help/which'
  715. fi
  716. if test -f 'src/cond.c' -a "${1}" != "-c" ; then 
  717.   echo shar: Will not clobber existing file \"'src/cond.c'\"
  718. else
  719.   echo shar: Extracting \"'src/cond.c'\" \(4069 characters\)
  720.   sed "s/^X//" >'src/cond.c' <<'END_OF_FILE'
  721. X/*
  722. X *
  723. X * cond.c - evaluate conditional expressions
  724. X *
  725. X * This file is part of zsh, the Z shell.
  726. X *
  727. X * This software is Copyright 1992 by Paul Falstad
  728. X *
  729. X * Permission is hereby granted to copy, reproduce, redistribute or otherwise
  730. X * use this software as long as: there is no monetary profit gained
  731. X * specifically from the use or reproduction of this software, it is not
  732. X * sold, rented, traded or otherwise marketed, and this copyright notice is
  733. X * included prominently in any copy made. 
  734. X *
  735. X * The author make no claims as to the fitness or correctness of this software
  736. X * for any use whatsoever, and it is provided as is. Any use of this software
  737. X * is at the user's own risk. 
  738. X *
  739. X */
  740. X
  741. X#include "zsh.h"
  742. X
  743. Xint evalcond(c) /**/
  744. XCond c;
  745. X{
  746. Xstruct stat *st;
  747. X
  748. X    switch (c->type)
  749. X        {
  750. X        case COND_NOT: return !evalcond(c->left);
  751. X        case COND_AND: return evalcond(c->left) && evalcond(c->right);
  752. X        case COND_OR: return evalcond(c->left) || evalcond(c->right);
  753. X        }
  754. X    singsub((char **) &c->left);
  755. X    untokenize(c->left);
  756. X    if (c->right)
  757. X        {
  758. X        singsub((char **) &c->right);
  759. X        if (c->type != COND_STREQ && c->type != COND_STRNEQ)
  760. X            untokenize(c->right);
  761. X        }
  762. X    switch (c->type)
  763. X        {
  764. X        case COND_STREQ: return matchpat(c->left,c->right);
  765. X        case COND_STRNEQ: return !matchpat(c->left,c->right);
  766. X        case COND_STRLT: return strcmp(c->left,c->right) < 0;
  767. X        case COND_STRGTR: return strcmp(c->left,c->right) > 0;
  768. X        case 'e': case 'a': return(doaccess(c->left,F_OK));
  769. X        case 'b': return(S_ISBLK(dostat(c->left)));
  770. X        case 'c': return(S_ISCHR(dostat(c->left)));
  771. X        case 'd': return(S_ISDIR(dostat(c->left)));
  772. X        case 'f': return(S_ISREG(dostat(c->left)));
  773. X        case 'g': return(!!(dostat(c->left) & S_ISGID));
  774. X        case 'k': return(!!(dostat(c->left) & S_ISVTX));
  775. X        case 'n': return(!!strlen(c->left));
  776. X        case 'o': return(optison(c->left));
  777. X        case 'p': return(S_ISFIFO(dostat(c->left)));
  778. X        case 'r': return(doaccess(c->left,R_OK));
  779. X        case 's': return((st = getstat(c->left)) && !!(st->st_size));
  780. X        case 'S': return(S_ISSOCK(dostat(c->left)));
  781. X        case 'u': return(!!(dostat(c->left) & S_ISUID));
  782. X        case 'w': return(doaccess(c->left,W_OK));
  783. X        case 'x': return(doaccess(c->left,X_OK));
  784. X        case 'z': return(!strlen(c->left));
  785. X        case 'h': case 'L': return(S_ISLNK(dolstat(c->left)));
  786. X        case 'O': return((st = getstat(c->left)) && st->st_uid == geteuid());
  787. X        case 'G': return((st = getstat(c->left)) && st->st_gid == getegid());
  788. X        case 't': return isatty(matheval(c->left));
  789. X        case COND_EQ: return matheval(c->left) == matheval(c->right);
  790. X        case COND_NE: return matheval(c->left) != matheval(c->right);
  791. X        case COND_LT: return matheval(c->left) < matheval(c->right);
  792. X        case COND_GT: return matheval(c->left) > matheval(c->right);
  793. X        case COND_LE: return matheval(c->left) <= matheval(c->right);
  794. X        case COND_GE: return matheval(c->left) >= matheval(c->right);
  795. X        case COND_NT: case COND_OT:
  796. X            {
  797. X            time_t a;
  798. X            if (!(st = getstat(c->left)))
  799. X                return 0;
  800. X            a = st->st_mtime;
  801. X            if (!(st = getstat(c->right)))
  802. X                return 0;
  803. X            return (c->type == COND_NT) ? a > st->st_mtime : a < st->st_mtime;
  804. X            }
  805. X        case COND_EF:
  806. X            {
  807. X            dev_t d;
  808. X            ino_t i;
  809. X
  810. X            if (!(st = getstat(c->left)))
  811. X                return 0;
  812. X            d = st->st_dev;
  813. X            i = st->st_ino;
  814. X            if (!(st = getstat(c->right)))
  815. X                return 0;
  816. X            return d == st->st_dev && i == st->st_ino;
  817. X            }
  818. X        default: zerr("bad cond structure",NULL,0);
  819. X        }
  820. X    return 0;
  821. X}
  822. X
  823. Xint doaccess(s,c) /**/
  824. Xchar *s;int c;
  825. X{
  826. X    return !access(s,c);
  827. X}
  828. X
  829. Xstatic struct stat st;
  830. X
  831. Xstruct stat *getstat(s) /**/
  832. Xchar *s;
  833. X{
  834. X    if (!strncmp(s,"/dev/fd/",8))
  835. X        {
  836. X        if (fstat(atoi(s+8),&st))
  837. X            return NULL;
  838. X        }
  839. X    else if (stat(s,&st))
  840. X        return NULL;
  841. X    return &st;
  842. X}
  843. X
  844. Xunsigned short dostat(s) /**/
  845. Xchar *s;
  846. X{
  847. Xstruct stat *st;
  848. X
  849. X    if (!(st = getstat(s)))
  850. X        return 0;
  851. X    return st->st_mode;
  852. X}
  853. X
  854. X/* pem@aaii.oz; needed since dostat now uses "stat" */
  855. X
  856. Xunsigned short dolstat(s) /**/
  857. Xchar *s;
  858. X{
  859. X    if (lstat(s, &st) < 0)
  860. X        return 0;
  861. X    return st.st_mode;
  862. X}
  863. X
  864. Xint optison(s) /**/
  865. Xchar *s;
  866. X{
  867. Xint i;
  868. X
  869. X    if (strlen(s) == 1)
  870. X        return opts[(int)*s];
  871. X    if ((i = optlookup(s)) != -1)
  872. X        return opts[i];
  873. X    zerr("no such option: %s",s,0);
  874. X    return 0;
  875. X}
  876. X
  877. END_OF_FILE
  878.   if test 4069 -ne `wc -c <'src/cond.c'`; then
  879.     echo shar: \"'src/cond.c'\" unpacked with wrong size!
  880.   fi
  881.   # end of 'src/cond.c'
  882. fi
  883. if test -f 'src/loop.c' -a "${1}" != "-c" ; then 
  884.   echo shar: Will not clobber existing file \"'src/loop.c'\"
  885. else
  886.   echo shar: Extracting \"'src/loop.c'\" \(4787 characters\)
  887.   sed "s/^X//" >'src/loop.c' <<'END_OF_FILE'
  888. X/*
  889. X *
  890. X * loop.c - loop execution
  891. X *
  892. X * This file is part of zsh, the Z shell.
  893. X *
  894. X * This software is Copyright 1992 by Paul Falstad
  895. X *
  896. X * Permission is hereby granted to copy, reproduce, redistribute or otherwise
  897. X * use this software as long as: there is no monetary profit gained
  898. X * specifically from the use or reproduction of this software, it is not
  899. X * sold, rented, traded or otherwise marketed, and this copyright notice is
  900. X * included prominently in any copy made. 
  901. X *
  902. X * The author make no claims as to the fitness or correctness of this software
  903. X * for any use whatsoever, and it is provided as is. Any use of this software
  904. X * is at the user's own risk. 
  905. X *
  906. X */
  907. X
  908. X#include "zsh.h"
  909. X
  910. Xint execfor(cmd) /**/
  911. XCmd cmd;
  912. X{
  913. XList list;
  914. Xstruct forcmd *node;
  915. Xchar *str;
  916. XLklist args;
  917. Xint cj = thisjob;
  918. X
  919. X    loops++;
  920. X    exiting = 0;
  921. X    node = cmd->u.forcmd;
  922. X    args = cmd->args;
  923. X    if (!node->inflag)
  924. X        {
  925. X        char **x;
  926. X
  927. X        args = newlist();
  928. X        for (x = pparams; *x; x++)
  929. X            addnode(args,ztrdup(*x));
  930. X        }
  931. X    pushheap();
  932. X    while (str = ugetnode(args))
  933. X        {
  934. X        setsparam(node->name,ztrdup(str));
  935. X        list = dupstruct(node->list);
  936. X        execlist(list);
  937. X        if (breaks)
  938. X            {
  939. X            breaks--;
  940. X            if (breaks || !contflag)
  941. X                break;
  942. X            contflag = 0;
  943. X            }
  944. X        if (errflag)
  945. X            {
  946. X            lastval = 1;
  947. X            break;
  948. X            }
  949. X        freeheap();
  950. X        }
  951. X    popheap();
  952. X    thisjob = cj;
  953. X    loops--;
  954. X    return lastval;
  955. X}
  956. X
  957. Xint execselect(cmd) /**/
  958. XCmd cmd;
  959. X{
  960. XList list;
  961. Xstruct forcmd *node;
  962. Xchar *str,*s;
  963. XLklist args;
  964. XLknode n;
  965. Xint cj = thisjob,t0;
  966. XFILE *inp;
  967. X
  968. X    node = cmd->u.forcmd;
  969. X    args = cmd->args;
  970. X    if (!node->inflag) {
  971. X        char **x;
  972. X
  973. X        args = newlist();
  974. X        for (x = pparams; *x; x++)
  975. X            addnode(args,ztrdup(*x));
  976. X    }
  977. X    if (empty(args))
  978. X        return 1;
  979. X    loops++;
  980. X    exiting = 0;
  981. X    pushheap();
  982. X    inp = fdopen(dup((SHTTY==-1)?0:SHTTY),"r");
  983. X    for (;;)
  984. X        {
  985. X        do
  986. X            {
  987. X            int pl;
  988. X            selectlist(args);
  989. X            str = putprompt(prompt3,&pl,0);
  990. X            if (full(bufstack)) str = (char *) getnode(bufstack);
  991. X            else if (interact && SHTTY != -1 && isset(USEZLE)) {
  992. X                str = (char *)zleread((unsigned char *)str,NULL,pl);
  993. X            } else {
  994. X                fprintf(stderr,"%s",str);
  995. X                fflush(stderr);
  996. X                str = fgets(zalloc(256),256,inp);
  997. X            }
  998. X            if (!str || errflag)
  999. X                {
  1000. X                fprintf(stderr,"\n");
  1001. X                fflush(stderr);
  1002. X                goto done;
  1003. X                }
  1004. X            if (s = strchr(str,'\n'))
  1005. X                *s = '\0';
  1006. X            }
  1007. X        while (!*str);
  1008. X        setsparam("REPLY",ztrdup(str));
  1009. X        t0 = atoi(str);
  1010. X        if (!t0)
  1011. X            str = "";
  1012. X        else
  1013. X            {
  1014. X            for (t0--,n = firstnode(args); n && t0; incnode(n),t0--);
  1015. X            if (n)
  1016. X                str = getdata(n);
  1017. X            else
  1018. X                str = "";
  1019. X            }
  1020. X        setsparam(node->name,ztrdup(str));
  1021. X        list = dupstruct(node->list);
  1022. X        execlist(list);
  1023. X        freeheap();
  1024. X        if (breaks)
  1025. X            {
  1026. X            breaks--;
  1027. X            if (breaks || !contflag)
  1028. X                break;
  1029. X            contflag = 0;
  1030. X            }
  1031. X        if (errflag)
  1032. X            break;
  1033. X        }
  1034. Xdone:
  1035. X    popheap();
  1036. X    fclose(inp);
  1037. X    thisjob = cj;
  1038. X    loops--;
  1039. X    return lastval;
  1040. X}
  1041. Xint execwhile(cmd) /**/
  1042. XCmd cmd;
  1043. X{
  1044. XList list;
  1045. Xstruct whilecmd *node;
  1046. Xint cj = thisjob; 
  1047. X
  1048. X    node = cmd->u.whilecmd;
  1049. X    exiting = 0;
  1050. X    pushheap();
  1051. X    loops++;
  1052. X    for(;;)
  1053. X        {
  1054. X        list = dupstruct(node->cont);
  1055. X        execlist(list);
  1056. X        if (!((lastval == 0) ^ node->cond)) {
  1057. X            if (breaks) breaks--;
  1058. X            break;
  1059. X        }
  1060. X        list = dupstruct(node->loop);
  1061. X        execlist(list);
  1062. X        if (breaks)
  1063. X            {
  1064. X            breaks--;
  1065. X            if (breaks || !contflag)
  1066. X                break;
  1067. X            contflag = 0;
  1068. X            }
  1069. X        freeheap();
  1070. X        if (errflag)
  1071. X            {
  1072. X            lastval = 1;
  1073. X            break;
  1074. X            }
  1075. X        }
  1076. X    popheap();
  1077. X    thisjob = cj;
  1078. X    loops--;
  1079. X    return lastval;
  1080. X}
  1081. Xint execrepeat(cmd) /**/
  1082. XCmd cmd;
  1083. X{
  1084. XList list;
  1085. Xint cj = thisjob,count;
  1086. X
  1087. X    exiting = 0;
  1088. X    if (empty(cmd->args) || nextnode(firstnode(cmd->args)))
  1089. X        {
  1090. X        zerr("bad argument for repeat",NULL,0);
  1091. X        return 1;
  1092. X        }
  1093. X    count = atoi(peekfirst(cmd->args));
  1094. X    pushheap();
  1095. X    loops++;
  1096. X    while (count--)
  1097. X        {
  1098. X        list = dupstruct(cmd->u.list);
  1099. X        execlist(list);
  1100. X        freeheap();
  1101. X        if (breaks)
  1102. X            {
  1103. X            breaks--;
  1104. X            if (breaks || !contflag)
  1105. X                break;
  1106. X            contflag = 0;
  1107. X            }
  1108. X        if (lastval)
  1109. X            break;
  1110. X        if (errflag)
  1111. X            {
  1112. X            lastval = 1;
  1113. X            break;
  1114. X            }
  1115. X        }
  1116. X    popheap();
  1117. X    thisjob = cj;
  1118. X    loops--;
  1119. X    return lastval;
  1120. X}
  1121. Xint execif(cmd) /**/
  1122. XCmd cmd;
  1123. X{
  1124. Xstruct ifcmd *node;
  1125. Xint cj = thisjob;
  1126. X
  1127. X    node = cmd->u.ifcmd;
  1128. X    exiting = 0;
  1129. X    while (node)
  1130. X        {
  1131. X        if (node->ifl)
  1132. X            {
  1133. X            execlist(node->ifl);
  1134. X            if (lastval)
  1135. X                {
  1136. X                node = node->next;
  1137. X                continue;
  1138. X                }
  1139. X            }
  1140. X        execlist(node->thenl);
  1141. X        break;
  1142. X        }
  1143. X    thisjob = cj;
  1144. X    return lastval;
  1145. X}
  1146. Xint execcase(cmd) /**/
  1147. XCmd cmd;
  1148. X{
  1149. Xstruct casecmd *node;
  1150. Xchar *word;
  1151. XLklist args;
  1152. Xint cj = thisjob;
  1153. X
  1154. X    node = cmd->u.casecmd;
  1155. X    args = cmd->args;
  1156. X    exiting = 0;
  1157. X    if (firstnode(args) && nextnode(firstnode(args)))
  1158. X        {
  1159. X        zerr("too many arguments to case",NULL,0);
  1160. X        return 1;
  1161. X        }
  1162. X    if (empty(args))
  1163. X        word = strdup("");
  1164. X    else
  1165. X        word = peekfirst(args);
  1166. X    while (node)
  1167. X        {
  1168. X        singsub(&(node->pat));
  1169. X        if (matchpat(word,node->pat))
  1170. X            break;
  1171. X        else
  1172. X            node = node->next;
  1173. X        }
  1174. X    if (node && node->list)
  1175. X        execlist(node->list);
  1176. X    thisjob = cj;
  1177. X    return lastval;
  1178. X}
  1179. END_OF_FILE
  1180.   if test 4787 -ne `wc -c <'src/loop.c'`; then
  1181.     echo shar: \"'src/loop.c'\" unpacked with wrong size!
  1182.   fi
  1183.   # end of 'src/loop.c'
  1184. fi
  1185. if test -f 'src/mem.c' -a "${1}" != "-c" ; then 
  1186.   echo shar: Will not clobber existing file \"'src/mem.c'\"
  1187. else
  1188.   echo shar: Extracting \"'src/mem.c'\" \(5032 characters\)
  1189.   sed "s/^X//" >'src/mem.c' <<'END_OF_FILE'
  1190. X/*
  1191. X *
  1192. X * mem.c - memory management
  1193. X *
  1194. X * This file is part of zsh, the Z shell.
  1195. X *
  1196. X * This software is Copyright 1992 by Paul Falstad
  1197. X *
  1198. X * Permission is hereby granted to copy, reproduce, redistribute or otherwise
  1199. X * use this software as long as: there is no monetary profit gained
  1200. X * specifically from the use or reproduction of this software, it is not
  1201. X * sold, rented, traded or otherwise marketed, and this copyright notice is
  1202. X * included prominently in any copy made. 
  1203. X *
  1204. X * The author make no claims as to the fitness or correctness of this software
  1205. X * for any use whatsoever, and it is provided as is. Any use of this software
  1206. X * is at the user's own risk. 
  1207. X *
  1208. X */
  1209. X/*
  1210. X
  1211. X    mem.c - memory management
  1212. X
  1213. X    This file is part of zsh, the Z shell.
  1214. X
  1215. X    zsh is free software; no one can prevent you from reading the source
  1216. X   code, or giving it to someone else.
  1217. X
  1218. X   This file is copyrighted under the GNU General Public License, which
  1219. X   can be found in the file called COPYING.
  1220. X
  1221. X   Copyright (C) 1990, 1991 Paul Falstad
  1222. X
  1223. X*/
  1224. X
  1225. X#include "zsh.h"
  1226. X#define HEAPSIZE 8192
  1227. X
  1228. X/*
  1229. X
  1230. X    There are two ways to allocate memory in zsh.  The first way is
  1231. X    to call zalloc/zcalloc, which call malloc/calloc directly.  It
  1232. X    is legal to call realloc() or free() on memory allocated this way.
  1233. X    The second way is to call halloc/hcalloc, which allocates memory
  1234. X    from one of the memory pools on the heap stack.  A pool can be
  1235. X    created by calling pushheap(), and destroyed by calling popheap().
  1236. X    To free the memory in the pool without destroying it, call
  1237. X    freeheap(); this is equivalent to { popheap(); pushheap(); }
  1238. X    Memory allocated in this way does not have to be freed explicitly;
  1239. X    it will all be freed when the pool is destroyed.  In fact,
  1240. X    attempting to free this memory may result in a core dump.
  1241. X    The pair of pointers ncalloc and alloc may point to either
  1242. X    zalloc & zcalloc or halloc & hcalloc; permalloc() sets them to the
  1243. X    former, and heapalloc() sets them to the latter. This can be useful.
  1244. X    For example, the dupstruct() routine duplicates a syntax tree,
  1245. X    allocating the new memory for the tree using alloc().  If you want
  1246. X    to duplicate a structure for a one-time use (i.e. to execute the list
  1247. X    in a for loop), call heapalloc(), then dupstruct().  If you want
  1248. X    to duplicate a structure in order to preserve it (i.e. a function
  1249. X    definition), call permalloc(), then dupstruct().
  1250. X
  1251. X*/
  1252. X
  1253. X/* initialize heap stack */
  1254. X
  1255. Xvoid meminit() /**/
  1256. X{
  1257. X    permalloc();
  1258. X    heaplist = newlist();
  1259. X    pushheap();
  1260. X}
  1261. X
  1262. X/* set default allocation to heap stack */
  1263. X
  1264. Xvoid heapalloc() /**/
  1265. X{
  1266. X    alloc = hcalloc;
  1267. X    ncalloc = halloc;
  1268. X    useheap = 1;
  1269. X}
  1270. X
  1271. Xstatic vptr (*lastcalloc) DCLPROTO((int));
  1272. Xstatic vptr (*lastncalloc) DCLPROTO((int));
  1273. Xstatic int lastuseheap;
  1274. X
  1275. X/* set default allocation to malloc() */
  1276. X
  1277. Xvoid permalloc() /**/
  1278. X{
  1279. X    lastcalloc = alloc;
  1280. X    lastncalloc = ncalloc;
  1281. X    lastuseheap = useheap;
  1282. X    alloc = zcalloc;
  1283. X    ncalloc = zalloc;
  1284. X    useheap = 0;
  1285. X}
  1286. X
  1287. X/* reset previous default allocation */
  1288. X
  1289. Xvoid lastalloc() /**/
  1290. X{
  1291. X    alloc = lastcalloc;
  1292. X    ncalloc = lastncalloc;
  1293. X    useheap = lastuseheap;
  1294. X}
  1295. X
  1296. Xstruct heap {
  1297. X    char *pool,*ptr;
  1298. X    int free;
  1299. X    struct heap *next;
  1300. X    };
  1301. X
  1302. X/* create a memory pool */
  1303. X
  1304. Xvoid pushheap() /**/
  1305. X{
  1306. XHeap h;
  1307. X
  1308. X    h = (Heap) zalloc(sizeof *h);
  1309. X    h->pool = h->ptr = zalloc(HEAPSIZE);
  1310. X    h->free = HEAPSIZE;
  1311. X    h->next = NULL;
  1312. X    permalloc();
  1313. X    pushnode(heaplist,h);
  1314. X    lastalloc();
  1315. X}
  1316. X
  1317. X/* reset a memory pool */
  1318. X
  1319. Xvoid freeheap() /**/
  1320. X{
  1321. XHeap h = (Heap) peekfirst(heaplist);
  1322. X
  1323. X    freeh(h->next);
  1324. X    h->next = NULL;
  1325. X    h->free += (h->ptr-h->pool);
  1326. X    h->ptr = h->pool;
  1327. X}
  1328. X
  1329. X/* destroy a memory pool */
  1330. X
  1331. Xvoid popheap() /**/
  1332. X{
  1333. XHeap h = (Heap) getnode(heaplist);
  1334. X
  1335. X    freeh(h);
  1336. X}
  1337. X
  1338. Xvoid freeh(h) /**/
  1339. XHeap h;
  1340. X{
  1341. X    if (h)
  1342. X        {
  1343. X        freeh(h->next);
  1344. X        free(h->pool);
  1345. X        free(h);
  1346. X        }
  1347. X}
  1348. X
  1349. X/* allocate memory from the current memory pool */
  1350. X
  1351. Xvptr halloc(size) /**/
  1352. Xint size;
  1353. X{
  1354. XHeap h = (Heap) peekfirst(heaplist),h2;
  1355. Xchar *ret;
  1356. X
  1357. X    size = (size|7)+1;
  1358. X    while (h && h->free-size < 0)
  1359. X        h = h->next;
  1360. X    if (!h) {
  1361. X        h2 = (Heap) zalloc(sizeof *h2);
  1362. X        h2->pool = h2->ptr = zalloc(h2->free = 
  1363. X            (size < HEAPSIZE) ? HEAPSIZE : (size|(HEAPSIZE-1))+1);
  1364. X        h2->next = (Heap) peekfirst(heaplist);
  1365. X        setdata(firstnode(heaplist),(vptr) h2);
  1366. X        h = h2;
  1367. X    }
  1368. X    h->free -= size;
  1369. X    ret = h->ptr;
  1370. X    h->ptr += size;
  1371. X    return ret;
  1372. X}
  1373. X
  1374. X/* allocate memory from the current memory pool and clear it */
  1375. X
  1376. Xvptr hcalloc(size) /**/
  1377. Xint size;
  1378. X{
  1379. Xvptr ptr;
  1380. X
  1381. X    ptr = halloc(size);
  1382. X    memset(ptr,0,size);
  1383. X    return ptr;
  1384. X}
  1385. X
  1386. Xvptr hrealloc(p,old,new) /**/
  1387. Xchar *p;int old;int new;
  1388. X{
  1389. Xchar *ptr;
  1390. X
  1391. X    ptr = halloc(new);
  1392. X    memcpy(ptr,p,old);
  1393. X    return ptr;
  1394. X}
  1395. X
  1396. X/* allocate permanent memory */
  1397. X
  1398. Xvptr zalloc(l) /**/
  1399. Xint l;
  1400. X{
  1401. Xvptr z;
  1402. X    if (!l) l = 1;
  1403. X    if (!(z = malloc(l)))
  1404. X        {
  1405. X        zerr("fatal error: out of memory",NULL,0);
  1406. X        exit(1);
  1407. X        }
  1408. X    return z;
  1409. X}
  1410. X
  1411. Xvptr zcalloc(size) /**/
  1412. Xint size;
  1413. X{
  1414. Xvptr ptr;
  1415. X
  1416. X    ptr = zalloc(size);
  1417. X    memset(ptr,0,size);
  1418. X    return ptr;
  1419. X}
  1420. X
  1421. Xchar *strdup(s) /**/
  1422. Xconst char *s;
  1423. X{
  1424. Xchar *t;
  1425. X
  1426. X    if (!s)
  1427. X        return NULL;
  1428. X    t = ncalloc(strlen(s)+1);
  1429. X    strcpy(t,s);
  1430. X    return t;
  1431. X}
  1432. X
  1433. Xchar *ztrdup(s) /**/
  1434. Xconst char *s;
  1435. X{
  1436. Xchar *t;
  1437. X
  1438. X    if (!s)
  1439. X        return NULL;
  1440. X    t = zalloc(strlen(s)+1);
  1441. X    strcpy(t,s);
  1442. X    return t;
  1443. X}
  1444. X
  1445. END_OF_FILE
  1446.   if test 5032 -ne `wc -c <'src/mem.c'`; then
  1447.     echo shar: \"'src/mem.c'\" unpacked with wrong size!
  1448.   fi
  1449.   # end of 'src/mem.c'
  1450. fi
  1451. if test -f 'src/zle_move.c' -a "${1}" != "-c" ; then 
  1452.   echo shar: Will not clobber existing file \"'src/zle_move.c'\"
  1453. else
  1454.   echo shar: Extracting \"'src/zle_move.c'\" \(5167 characters\)
  1455.   sed "s/^X//" >'src/zle_move.c' <<'END_OF_FILE'
  1456. X/*
  1457. X *
  1458. X * zle_move.c - editor movement
  1459. X *
  1460. X * This file is part of zsh, the Z shell.
  1461. X *
  1462. X * This software is Copyright 1992 by Paul Falstad
  1463. X *
  1464. X * Permission is hereby granted to copy, reproduce, redistribute or otherwise
  1465. X * use this software as long as: there is no monetary profit gained
  1466. X * specifically from the use or reproduction of this software, it is not
  1467. X * sold, rented, traded or otherwise marketed, and this copyright notice is
  1468. X * included prominently in any copy made. 
  1469. X *
  1470. X * The author make no claims as to the fitness or correctness of this software
  1471. X * for any use whatsoever, and it is provided as is. Any use of this software
  1472. X * is at the user's own risk. 
  1473. X *
  1474. X */
  1475. X
  1476. X#define ZLE
  1477. X#include "zsh.h"
  1478. X
  1479. Xvoid beginningofline() /**/
  1480. X{
  1481. X    if (mult < 0) { mult = -mult; endofline(); return; }
  1482. X    while (mult--) {
  1483. X        if (cs == 0)
  1484. X            return;
  1485. X        if (line[cs-1] == '\n')
  1486. X            if (!--cs)
  1487. X                return;
  1488. X        while (cs && line[cs-1] != '\n') cs--;
  1489. X    }
  1490. X}
  1491. X
  1492. Xvoid endofline() /**/
  1493. X{
  1494. X    if (mult < 0) { mult = -mult; beginningofline(); return; }
  1495. X    while (mult--) {
  1496. X        if (cs >= ll) {
  1497. X            cs = ll;
  1498. X            return;
  1499. X        }
  1500. X        if (line[cs] == '\n')
  1501. X            if (++cs == ll)
  1502. X                return;
  1503. X        while (cs != ll && line[cs] != '\n') cs++;
  1504. X    }
  1505. X}
  1506. X
  1507. Xvoid beginningoflinehist() /**/
  1508. X{
  1509. X    if (mult < 0) { mult = -mult; endoflinehist(); return; }
  1510. X    while (mult) {
  1511. X        if (cs == 0)
  1512. X            break;
  1513. X        if (line[cs-1] == '\n')
  1514. X            if (!--cs)
  1515. X                break;
  1516. X        while (cs && line[cs-1] != '\n') cs--;
  1517. X        mult--;
  1518. X    }
  1519. X    if (mult) {
  1520. X        uphistory();
  1521. X        cs = 0;
  1522. X    }
  1523. X}
  1524. X
  1525. Xvoid endoflinehist() /**/
  1526. X{
  1527. X    if (mult < 0) { mult = -mult; beginningoflinehist(); return; }
  1528. X    while (mult) {
  1529. X        if (cs >= ll) {
  1530. X            cs = ll;
  1531. X            break;
  1532. X        }
  1533. X        if (line[cs] == '\n')
  1534. X            if (++cs == ll)
  1535. X                break;
  1536. X        while (cs != ll && line[cs] != '\n') cs++;
  1537. X        mult--;
  1538. X    }
  1539. X    if (mult)
  1540. X        downhistory();
  1541. X}
  1542. X
  1543. Xvoid forwardchar() /**/
  1544. X{
  1545. X    cs += mult;
  1546. X    if (cs > ll) cs = ll;
  1547. X    if (cs <  0) cs = 0;
  1548. X}
  1549. X
  1550. Xvoid backwardchar() /**/
  1551. X{
  1552. X    cs -= mult;
  1553. X    if (cs > ll) cs = ll;
  1554. X    if (cs <  0) cs = 0;
  1555. X}
  1556. X
  1557. Xvoid setmarkcommand() /**/
  1558. X{
  1559. X    mark = cs;
  1560. X}
  1561. X
  1562. Xvoid exchangepointandmark() /**/
  1563. X{
  1564. Xint x;
  1565. X
  1566. X    x = mark;
  1567. X    mark = cs;
  1568. X    cs = x;
  1569. X    if (cs > ll)
  1570. X        cs = ll;
  1571. X}
  1572. X
  1573. Xvoid vigotocolumn() /**/
  1574. X{
  1575. Xint x,y,ocs = cs;
  1576. X
  1577. X    if (mult > 0) mult--;
  1578. X    findline(&x,&y);
  1579. X    if (mult >= 0) cs = x+mult; else cs = y+mult;
  1580. X    if (cs < x || cs > y) {
  1581. X        feep();
  1582. X        cs = ocs;
  1583. X    }
  1584. X}
  1585. X
  1586. Xvoid vimatchbracket() /**/
  1587. X{
  1588. Xint ocs = cs,dir,ct;
  1589. Xunsigned char oth,me;
  1590. X
  1591. Xotog:
  1592. X    if (cs == ll)
  1593. X        {
  1594. X        feep();
  1595. X        cs = ocs;
  1596. X        return;
  1597. X        }
  1598. X    switch(me = line[cs])
  1599. X        {
  1600. X        case '{': dir = 1; oth = '}'; break;
  1601. X        case '}': dir = -1; oth = '{'; break;
  1602. X        case '(': dir = 1; oth = ')'; break;
  1603. X        case ')': dir = -1; oth = '('; break;
  1604. X        case '[': dir = 1; oth = ']'; break;
  1605. X        case ']': dir = -1; oth = '['; break;
  1606. X        default: cs++; goto otog;
  1607. X        }
  1608. X    ct = 1;
  1609. X    while (cs >= 0 && cs < ll && ct)
  1610. X        {
  1611. X        cs += dir;
  1612. X        if (line[cs] == oth)
  1613. X            ct--;
  1614. X        else if (line[cs] == me)
  1615. X            ct++;
  1616. X        }
  1617. X    if (cs < 0 || cs >= ll)
  1618. X        {
  1619. X        feep();
  1620. X        cs = ocs;
  1621. X        }
  1622. X}
  1623. X
  1624. Xvoid viforwardchar() /**/
  1625. X{
  1626. X    if (mult < 0) { mult = -mult; vibackwardchar(); return; }
  1627. X    while (mult--) {
  1628. X        cs++;
  1629. X        if (cs >= ll || line[cs] == '\n') {
  1630. X            cs--;
  1631. X            break;
  1632. X        }
  1633. X    }
  1634. X}
  1635. X
  1636. Xvoid vibackwardchar() /**/
  1637. X{
  1638. X    if (mult < 0) { mult = -mult; viforwardchar(); return; }
  1639. X    while (mult--) {
  1640. X        cs--;
  1641. X        if (cs < 0 || line[cs] == '\n') {
  1642. X            cs++;
  1643. X            break;
  1644. X        }
  1645. X    }
  1646. X}
  1647. X
  1648. Xvoid viendofline() /**/
  1649. X{
  1650. X    cs = findeol();
  1651. X    if (!virangeflag && cs != 0 && line[cs-1] != '\n') cs--;
  1652. X}
  1653. X
  1654. Xvoid vibeginningofline() /**/
  1655. X{
  1656. X    cs = findbol();
  1657. X}
  1658. X
  1659. X
  1660. Xstatic int vfindchar,vfinddir,tailadd;
  1661. X
  1662. Xvoid vifindnextchar() /**/
  1663. X{
  1664. X    if (vfindchar = vigetkey())
  1665. X        {
  1666. X        vfinddir = 1;
  1667. X        tailadd = 0;
  1668. X        virepeatfind();
  1669. X        }
  1670. X}
  1671. X
  1672. Xvoid vifindprevchar() /**/
  1673. X{
  1674. X    if (vfindchar = vigetkey())
  1675. X        {
  1676. X        vfinddir = -1;
  1677. X        tailadd = 0;
  1678. X        virepeatfind();
  1679. X        }
  1680. X}
  1681. X
  1682. Xvoid vifindnextcharskip() /**/
  1683. X{
  1684. X    if (vfindchar = vigetkey())
  1685. X        {
  1686. X        vfinddir = 1;
  1687. X        tailadd = -1;
  1688. X        virepeatfind();
  1689. X        }
  1690. X}
  1691. X
  1692. Xvoid vifindprevcharskip() /**/
  1693. X{
  1694. X    if (vfindchar = vigetkey())
  1695. X        {
  1696. X        vfinddir = -1;
  1697. X        tailadd = 1;
  1698. X        virepeatfind();
  1699. X        }
  1700. X}
  1701. X
  1702. Xvoid virepeatfind() /**/
  1703. X{
  1704. Xint ocs = cs;
  1705. X
  1706. X    if (!vfinddir) { feep(); return; }
  1707. X    if (mult < 0) { mult = -mult; virevrepeatfind(); return; }
  1708. X    while (mult--)
  1709. X        {
  1710. X        do
  1711. X            cs += vfinddir;
  1712. X        while (cs >= 0 && cs < ll && line[cs] != vfindchar && line[cs] != '\n');
  1713. X        if (cs < 0 || cs >= ll || line[cs] == '\n')
  1714. X            {
  1715. X            feep();
  1716. X            cs = ocs;
  1717. X            return;
  1718. X            }
  1719. X        }
  1720. X    cs += tailadd;
  1721. X    if (vfinddir == 1 && virangeflag) cs++;
  1722. X}
  1723. X
  1724. Xvoid virevrepeatfind() /**/
  1725. X{
  1726. X    if (mult < 0) { mult = -mult; virepeatfind(); return; }
  1727. X    vfinddir = -vfinddir;
  1728. X    virepeatfind();
  1729. X    vfinddir = -vfinddir;
  1730. X}
  1731. X
  1732. Xvoid vifirstnonblank() /**/
  1733. X{
  1734. X    cs = findbol();
  1735. X    while (cs != ll && iblank(line[cs]))
  1736. X        cs++;
  1737. X}
  1738. X
  1739. Xvoid visetmark() /**/
  1740. X{
  1741. Xint ch;
  1742. X
  1743. X    ch = getkey(1);
  1744. X    if (ch < 'a' || ch > 'z') {
  1745. X        feep();
  1746. X        return;
  1747. X    }
  1748. X    ch -= 'a';
  1749. X    vimarkcs[ch] = cs;
  1750. X    vimarkline[ch] = histline;
  1751. X}
  1752. X
  1753. Xvoid vigotomark() /**/
  1754. X{
  1755. Xint ch;
  1756. X
  1757. X    ch = getkey(1);
  1758. X    if (ch == c) ch = 26;
  1759. X    else {
  1760. X        if (ch < 'a' || ch > 'z') {
  1761. X            feep();
  1762. X            return;
  1763. X        }
  1764. X        ch -= 'a';
  1765. X    }
  1766. X    if (!vimarkline[ch]) {
  1767. X        feep();
  1768. X        return;
  1769. X    }
  1770. X    if (curhist != vimarkline[ch]) {
  1771. X        mult = vimarkline[ch];
  1772. X        vifetchhistory();
  1773. X        if (curhist != vimarkline[ch]) return;
  1774. X    }
  1775. X    cs = vimarkcs[ch];
  1776. X}
  1777. X
  1778. Xvoid vigotomarkline() /**/
  1779. X{
  1780. X    vigotomark();
  1781. X    cs = findbol();
  1782. X}
  1783. END_OF_FILE
  1784.   if test 5167 -ne `wc -c <'src/zle_move.c'`; then
  1785.     echo shar: \"'src/zle_move.c'\" unpacked with wrong size!
  1786.   fi
  1787.   # end of 'src/zle_move.c'
  1788. fi
  1789. if test -f 'src/zle_utils.c' -a "${1}" != "-c" ; then 
  1790.   echo shar: Will not clobber existing file \"'src/zle_utils.c'\"
  1791. else
  1792.   echo shar: Extracting \"'src/zle_utils.c'\" \(4714 characters\)
  1793.   sed "s/^X//" >'src/zle_utils.c' <<'END_OF_FILE'
  1794. X/*
  1795. X *
  1796. X * zle_utils.c - miscellaneous line editor utilities
  1797. X *
  1798. X * This file is part of zsh, the Z shell.
  1799. X *
  1800. X * This software is Copyright 1992 by Paul Falstad
  1801. X *
  1802. X * Permission is hereby granted to copy, reproduce, redistribute or otherwise
  1803. X * use this software as long as: there is no monetary profit gained
  1804. X * specifically from the use or reproduction of this software, it is not
  1805. X * sold, rented, traded or otherwise marketed, and this copyright notice is
  1806. X * included prominently in any copy made. 
  1807. X *
  1808. X * The author make no claims as to the fitness or correctness of this software
  1809. X * for any use whatsoever, and it is provided as is. Any use of this software
  1810. X * is at the user's own risk. 
  1811. X *
  1812. X */
  1813. X
  1814. X#define ZLE
  1815. X#include "zsh.h"
  1816. X
  1817. X/* make sure that the line buffer has at least sz chars */
  1818. X
  1819. Xvoid sizeline(sz) /**/
  1820. Xint sz;
  1821. X{
  1822. X    while (sz > linesz)
  1823. X        line = (unsigned char *)realloc(line,(linesz *= 4)+1);
  1824. X}
  1825. X
  1826. X/* insert space for ct chars at cursor position */
  1827. X
  1828. Xvoid spaceinline(ct) /**/
  1829. Xint ct;
  1830. X{
  1831. Xint i;
  1832. X
  1833. X    while (ct+ll > linesz)
  1834. X        line = (unsigned char *)realloc(line,(linesz *= 4)+1);
  1835. X    for (i = ll; i >= cs; i--)
  1836. X        line[i+ct] = line[i];
  1837. X    ll += ct;
  1838. X    line[ll] = '\0';
  1839. X}
  1840. X
  1841. Xvoid backkill(ct,dir) /**/
  1842. Xint ct;int dir;
  1843. X{
  1844. Xint i = (cs -= ct);
  1845. X
  1846. X    cut(i,ct,dir);
  1847. X    while (line[i] = line[i+ct])
  1848. X        i++;
  1849. X    ll -= ct;
  1850. X}
  1851. X
  1852. Xvoid forekill(ct,dir) /**/
  1853. Xint ct;int dir;
  1854. X{
  1855. Xint i = cs;
  1856. X
  1857. X    cut(i,ct,dir);
  1858. X    while (line[i] = line[i+ct])
  1859. X        i++;
  1860. X    ll -= ct;
  1861. X}
  1862. X
  1863. Xvoid cut(i,ct,dir) /**/
  1864. Xint i;int ct;int dir;
  1865. X{
  1866. X    if (vibufspec) {
  1867. X        int owrite = 1;
  1868. X        if (vibufspec >= 'A' && vibufspec <= 'Z') {
  1869. X            owrite = 0; vibufspec = tolower(vibufspec);
  1870. X        }
  1871. X        vibufspec += (idigit(vibufspec)) ? - '1' +26 : - 'a';
  1872. X        if (owrite || !vibuf[vibufspec]) {
  1873. X            if (vibuf[vibufspec]) free(vibuf[vibufspec]);
  1874. X            vibuf[vibufspec] = zalloc(ct+1);
  1875. X            ztrncpy(vibuf[vibufspec],UTOSCP(line+i),ct);
  1876. X        } else {
  1877. X            int len = strlen(vibuf[vibufspec]);
  1878. X            vibuf[vibufspec] = realloc(vibuf[vibufspec],ct+len);
  1879. X            ztrncpy(vibuf[vibufspec]+len,UTOSCP(line+i),ct);
  1880. X        }
  1881. X        vibufspec = 0;
  1882. X        return;
  1883. X    }
  1884. X    if (!cutbuf)
  1885. X        cutbuf = ztrdup("");
  1886. X    else if (!(lastcmd & ZLE_KILL)) {
  1887. X        kringnum = (kringnum+1)&(KRINGCT-1);
  1888. X        if (kring[kringnum])
  1889. X            free(kring[kringnum]);
  1890. X        kring[kringnum] = cutbuf;
  1891. X        cutbuf = ztrdup("");
  1892. X    }
  1893. X    if (dir) {
  1894. X        char *s = zalloc(strlen(cutbuf)+ct+1);
  1895. X        strncpy(s,(char *) line+i,ct);
  1896. X        strcpy(s+ct,cutbuf);
  1897. X        free(cutbuf);
  1898. X        cutbuf = s;
  1899. X    } else {
  1900. X        int x;
  1901. X
  1902. X        cutbuf = realloc(cutbuf,(x = strlen(cutbuf))+ct+1);
  1903. X        ztrncpy(cutbuf+x,UTOSCP(line+i),ct);
  1904. X    }
  1905. X}
  1906. X
  1907. Xvoid backdel(ct) /**/
  1908. Xint ct;
  1909. X{
  1910. Xint i = (cs -= ct);
  1911. X
  1912. X    while (line[i] = line[i+ct])
  1913. X        i++;
  1914. X    ll -= ct;
  1915. X}
  1916. X
  1917. Xvoid foredel(ct) /**/
  1918. Xint ct;
  1919. X{
  1920. Xint i = cs;
  1921. X
  1922. X    while (line[i] = line[i+ct])
  1923. X        i++;
  1924. X    ll -= ct;
  1925. X}
  1926. X
  1927. Xvoid setline(s) /**/
  1928. Xchar *s;
  1929. X{
  1930. X    sizeline(strlen(s));
  1931. X    strcpy((char *) line,s);
  1932. X    cs = ll = strlen(s);
  1933. X    if (cs && bindtab == altbindtab) cs--;
  1934. X}
  1935. X
  1936. Xvoid sethistline(s) /**/
  1937. Xunsigned char *s;
  1938. X{
  1939. X    setline(UTOSCP(s));
  1940. X    for (s = line; *s; s++)
  1941. X        if (*s == STOUC(HISTSPACE))
  1942. X            *s = ' ';
  1943. X}
  1944. X
  1945. Xint findbol() /**/
  1946. X{
  1947. Xint x = cs;
  1948. X
  1949. X    while (x > 0 && line[x-1] != '\n') x--;
  1950. X    return x;
  1951. X}
  1952. X
  1953. Xint findeol() /**/
  1954. X{
  1955. Xint x = cs;
  1956. X
  1957. X    while (x != ll && line[x] != '\n') x++;
  1958. X    return x;
  1959. X}
  1960. X
  1961. Xvoid findline(a,b) /**/
  1962. Xint *a;int *b;
  1963. X{
  1964. X    *a = findbol();
  1965. X    *b = findeol();
  1966. X}
  1967. X
  1968. Xstatic int lastlinelen;
  1969. X
  1970. Xvoid initundo() /**/
  1971. X{
  1972. Xint t0;
  1973. X
  1974. X    for (t0 = 0; t0 != UNDOCT; t0++)
  1975. X        undos[t0].change = NULL;
  1976. X    undoct = 0;
  1977. X    lastline = zalloc(lastlinelen = (ll+1 < 32) ? 32 : ll+1);
  1978. X    strcpy((char *) lastline,(char *) line);
  1979. X    lastcs = cs;
  1980. X}
  1981. X
  1982. Xvoid addundo() /**/
  1983. X{
  1984. Xint pf,sf;
  1985. Xunsigned char *s,*s2,*t,*t2;
  1986. Xstruct undoent *ue;
  1987. X
  1988. X    for (s = line, t = lastline; *s && *s==*t; s++,t++);
  1989. X    if (!*s && !*t)
  1990. X        return;
  1991. X    pf = s-line;
  1992. X    for (s2 = (unsigned char *)line+strlen((char *) line),
  1993. X            t2 = lastline+strlen((char *) lastline);
  1994. X        s2 > s && t > t2 && s2[-1] == t2[-1]; s2--,t2--);
  1995. X    sf = strlen((char *) s2);
  1996. X    ue = undos+(undoct = (UNDOCT-1) & (undoct+1));
  1997. X    ue->pref = pf;
  1998. X    ue->suff = sf;
  1999. X    ue->len = t2-t;
  2000. X    ue->cs = lastcs;
  2001. X    strncpy(ue->change = halloc(ue->len),(char *) t,ue->len);
  2002. X    while (ll+1 > lastlinelen)
  2003. X        {
  2004. X        free(lastline);
  2005. X        lastline = zalloc(lastlinelen *= 2);
  2006. X        }
  2007. X    strcpy((char *) lastline,(char *) line);
  2008. X    lastcs = cs;
  2009. X}
  2010. X
  2011. Xvoid freeundo() /**/
  2012. X{
  2013. X    free(lastline);
  2014. X}
  2015. X
  2016. Xint hstrncmp(s,t,len) /**/
  2017. Xchar *s;char *t;int len;
  2018. X{
  2019. X    while (len && *s && (*s == *t || (*s == ' ' && *t == HISTSPACE) ||
  2020. X            (*s == HISTSPACE && *t == ' ')))
  2021. X        s++,t++,len--;
  2022. X    return len;
  2023. X}
  2024. X
  2025. Xint hstrcmp(s,t) /**/
  2026. Xchar *s;char *t;
  2027. X{
  2028. X    while (*s && (*s == *t || (*s == ' ' && *t == HISTSPACE) ||
  2029. X            (*s == HISTSPACE && *t == ' ')))
  2030. X        s++,t++;
  2031. X    return !(*s == '\0' && *t == '\0');
  2032. X}
  2033. X
  2034. Xchar *hstrnstr(s,t,len) /**/
  2035. Xchar *s;char *t;int len;
  2036. X{
  2037. X    for (; *s; s++)
  2038. X        if (!hstrncmp(t,s,len))
  2039. X            return s;
  2040. X    return NULL;
  2041. X}
  2042. X
  2043. END_OF_FILE
  2044.   if test 4714 -ne `wc -c <'src/zle_utils.c'`; then
  2045.     echo shar: \"'src/zle_utils.c'\" unpacked with wrong size!
  2046.   fi
  2047.   # end of 'src/zle_utils.c'
  2048. fi
  2049. echo shar: End of archive 21 \(of 22\).
  2050. cp /dev/null ark21isdone
  2051. MISSING=""
  2052. 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
  2053.     if test ! -f ark${I}isdone ; then
  2054.     MISSING="${MISSING} ${I}"
  2055.     fi
  2056. done
  2057. if test "${MISSING}" = "" ; then
  2058.     echo You have unpacked all 22 archives.
  2059.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2060. else
  2061.     echo You still must unpack the following archives:
  2062.     echo "        " ${MISSING}
  2063. fi
  2064. exit 0
  2065.  
  2066. exit 0 # Just in case...
  2067.