home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2265 < prev    next >
Encoding:
Internet Message Format  |  1990-12-28  |  50.6 KB

  1. From: netnews@netcom.UUCP (USENET Administration)
  2. Newsgroups: alt.sources
  3. Subject: Public Domain Korn Shell - Part.01 of 7
  4. Message-ID: <18606@netcom.UUCP>
  5. Date: 12 Dec 90 11:34:39 GMT
  6.  
  7. The following seven shar files are the public domain Korn Shell attributed to:
  8.  
  9.     Eric Gisin, egisin@math.UWaterloo.CA (or Waterloo.EDU)
  10.  
  11. ... however he was not reachable via email for any updates or status of
  12. this work.  So, we provide you with what we have.
  13. I don't recall how we got it originally.  We do not actually use this
  14. ksh here at NetCom, as it is incomplete (only emacs-style line editing),
  15. and we have an authentic ksh already.  However, if you don't have ksh and
  16. know emacs, this might be fun to have around.
  17.  
  18. First is the src/ReadMe file, to let you know what you're getting into,
  19. followed by the first shar.  These files may not be organized in the best
  20. possible way.  "No warrenties expressed or implied" -- use at your own risk.
  21. ------------------------------------------------------------------------------
  22. [from src/ReadMe:]
  23.  
  24.  
  25.         Public Domain KornShell
  26.  
  27.     Quick installation notes for PD KornShell
  28.  
  29. PD KornShell can be installed on
  30. 4.2+ BSD systems, System V, and POSIX-compatable systems.
  31. The makefiles all define _BSD, change this to _SYSV, or _POSIX.
  32. The makefiles also contain CC=gcc, delete this if you don't have GNU C.
  33. The ksh makefile also contains some options,
  34. including JOBS (BSD/POSIX job control) and EDIT (emacs command editing).
  35.  
  36. PD KornShell assumes you have standard C (ANSI) and POSIX header files and functions.
  37. Since you probably don't, they are provided in the "std" directory.
  38.  
  39. The Alpha test version will probably come as two tar files.
  40. std.tar contains standard C and POSIX emulation and
  41. must be extracted into a directory called std.
  42. ksh.tar contains the ksh source and should be extracted
  43. into a directory called src or ksh.
  44.  
  45. See std/ReadMe and install it. Only then can you make ksh in the "src" directory.
  46.  
  47. To clear up questions about the origin of this shell,
  48. this shell is NOT based on the "Minix shell".
  49. It is based on Charles Forsyth's public domain V7 shell,
  50. which he later contributed to Minix.
  51.  
  52. I have permission directly from Charles Forsyth to use his shell.
  53.  
  54.     Eric Gisin, egisin@math.UWaterloo.CA (or Waterloo.EDU)
  55.  
  56.     Things to do
  57. - add sxt-based job control (see Brown's contribution on the Usenix 87 tape).
  58. - add arrays and variable attributes.
  59. - add MAILPATH and CDPATH.
  60. - add vi editing mode (apparently someone has a PD version).
  61. - add new features described in Korn's book.
  62.  
  63.     Machines ported to
  64. VAX, 68000, 80386
  65.  
  66.     OS's ported to
  67. BSD 4.2, BSD 4.3 (with and without YP and NFS
  68. Sys V.3
  69. ------------------------------------------------------------------------------
  70. [end of src/ReadMe]
  71.  
  72. #!/bin/sh
  73. # This is ksh-pd, a shell archive (produced by shar 3.49)
  74. # To extract the files from this archive, save it to a file, remove
  75. # everything above the "!/bin/sh" line above, and type "sh file_name".
  76. #
  77. # made 12/12/1990 11:19 UTC by netnews@netcom
  78. # Source directory /usr/source/cmd/ksh
  79. #
  80. # existing files will NOT be overwritten unless -c is specified
  81. # This format requires very little intelligence at unshar time.
  82. # "if test", "echo", "true", and "sed" may be needed.
  83. #
  84. # This shar contains:
  85. # length  mode       name
  86. # ------ ---------- ------------------------------------------
  87. #   1599 -r--r--r-- src/ReadMe
  88. #  27500 -rw-r--r-- src/ksh.1
  89. #   1388 -rw-r--r-- src/Makefile
  90. #   6459 -rw-r--r-- src/sh.h
  91. #   3406 -rw-r--r-- src/table.h
  92. #   1991 -rw-r--r-- src/expand.h
  93. #   2669 -rw-r--r-- src/lex.h
  94. #   3598 -rw-r--r-- src/tree.h
  95. #    596 -rw-r--r-- src/tty.h
  96. #    615 -rw-r--r-- src/version.c
  97. #   7299 -rw-r--r-- src/main.c
  98. #   6290 -rw-r--r-- src/misc.c
  99. #   2734 -rw-r--r-- src/trap.c
  100. #   4501 -rw-r--r-- src/alloc.c
  101. #   3153 -rw-r--r-- src/io.c
  102. #   9196 -rw-r--r-- src/syn.c
  103. #  10858 -rw-r--r-- src/lex.c
  104. #  27910 -rw-r--r-- src/edit.c
  105. #   5293 -rw-r--r-- src/history.c
  106. #   8213 -rw-r--r-- src/tree.c
  107. #  11948 -rw-r--r-- src/exec.c
  108. #  13924 -rw-r--r-- src/jobs.c
  109. #   8915 -rw-r--r-- src/c_sh.c
  110. #   8739 -rw-r--r-- src/c_ksh.c
  111. #   6994 -rw-r--r-- src/c_test.c
  112. #   2996 -rw-r--r-- src/getopts.c
  113. #   2823 -rw-r--r-- src/ulimit.c
  114. #  10509 -rw-r--r-- src/var.c
  115. #   3724 -rw-r--r-- src/table.c
  116. #  13524 -rw-r--r-- src/eval.c
  117. #   4414 -rw-r--r-- src/expr.c
  118. #   2945 -rw-r--r-- ReadMe
  119. #   1060 -rw-r--r-- posix/Makefile
  120. #   1037 -rw-r--r-- posix/dirent.C
  121. #    880 -rw-r--r-- posix/dirent.H
  122. #     87 -rw-r--r-- posix/dirent.h
  123. #    430 -rw-r--r-- posix/fcntl.c
  124. #    435 -rw-r--r-- posix/fcntl.h
  125. #   1369 -rw-r--r-- posix/io.h
  126. #   1126 -rw-r--r-- posix/times.c
  127. #    459 -rw-r--r-- posix/unistd.c
  128. #    782 -rw-r--r-- posix/unistd.h
  129. #    274 -rw-r--r-- posix/time.h
  130. #    355 -rw-r--r-- posix/times.h
  131. #    935 -rw-r--r-- posix/wait.h
  132. #    799 -rw-r--r-- posix/fixincludes
  133. #   1592 -rw-r--r-- stdc/Makefile
  134. #   4940 -rw-r--r-- stdc/vprintf.c
  135. #    566 -rw-r--r-- stdc/stddef.h
  136. #    300 -rw-r--r-- stdc/stdio.c
  137. #   3946 -rw-r--r-- stdc/stdio.h
  138. #   2290 -rw-r--r-- stdc/stdio.h_std
  139. #   1104 -rw-r--r-- stdc/stdlib.h
  140. #   1310 -rw-r--r-- stdc/string.h
  141. #    322 -rw-r--r-- stdc/strcat.c
  142. #    795 -rw-r--r-- stdc/sprintf.c
  143. #    930 -rw-r--r-- stdc/time.h
  144. #    228 -rw-r--r-- stdc/memcpy.c
  145. #   1044 -rw-r--r-- stdc/setvbuf.c
  146. #    735 -rw-r--r-- stdc/clock.c
  147. #    369 -rw-r--r-- stdc/types.h
  148. #    845 -rw-r--r-- stdc/limits.h
  149. #    619 -rw-r--r-- stdc/stdarg.h
  150. #    357 -rw-r--r-- stdc/strcmp.s
  151. #    161 -rw-r--r-- stdc/strcpy.s
  152. #    225 -rw-r--r-- stdc/memchr.c
  153. #    358 -rw-r--r-- stdc/memcmp.c
  154. #    336 -rw-r--r-- stdc/memmove.c
  155. #    196 -rw-r--r-- stdc/memset.c
  156. #    732 -rw-r--r-- stdc/fprintf.c
  157. #   1108 -rw-r--r-- stdc/strtok.c
  158. #    423 -rw-r--r-- stdc/strchr.c
  159. #    758 -rw-r--r-- stdc/strcmp.c
  160. #    278 -rw-r--r-- stdc/strcpy.c
  161. #    467 -rw-r--r-- stdc/strcspn.c
  162. #    326 -rw-r--r-- stdc/strerror.c
  163. #    241 -rw-r--r-- stdc/strlen.c
  164. #    427 -rw-r--r-- stdc/strncat.c
  165. #    778 -rw-r--r-- stdc/strncmp.c
  166. #    410 -rw-r--r-- stdc/strncpy.c
  167. #    427 -rw-r--r-- stdc/strpbrk.c
  168. #    415 -rw-r--r-- stdc/strrchr.c
  169. #    483 -rw-r--r-- stdc/strspn.c
  170. #    595 -rw-r--r-- stdc/strstr.c
  171. #
  172. # ============= src/ReadMe ==============
  173. if test ! -d 'src'; then
  174.     echo 'x - creating directory src'
  175.     mkdir 'src'
  176. fi
  177. if test -f 'src/ReadMe' -a X"$1" != X"-c"; then
  178.     echo 'x - skipping src/ReadMe (File already exists)'
  179. else
  180. echo 'x - extracting src/ReadMe (Text)'
  181. sed 's/^X//' << 'SHAR_EOF' > 'src/ReadMe' &&
  182. X        Public Domain KornShell
  183. X
  184. X    Quick installation notes for PD KornShell
  185. X
  186. XPD KornShell can be installed on
  187. X4.2+ BSD systems, System V, and POSIX-compatable systems.
  188. XThe makefiles all define _BSD, change this to _SYSV, or _POSIX.
  189. XThe makefiles also contain CC=gcc, delete this if you don't have GNU C.
  190. XThe ksh makefile also contains some options,
  191. Xincluding JOBS (BSD/POSIX job control) and EDIT (emacs command editing).
  192. X
  193. XPD KornShell assumes you have standard C (ANSI) and POSIX header files and functions.
  194. XSince you probably don't, they are provided in the "std" directory.
  195. X
  196. XThe Alpha test version will probably come as two tar files.
  197. Xstd.tar contains standard C and POSIX emulation and
  198. Xmust be extracted into a directory called std.
  199. Xksh.tar contains the ksh source and should be extracted
  200. Xinto a directory called src or ksh.
  201. X
  202. XSee std/ReadMe and install it. Only then can you make ksh in the "src" directory.
  203. X
  204. XTo clear up questions about the origin of this shell,
  205. Xthis shell is NOT based on the "Minix shell".
  206. XIt is based on Charles Forsyth's public domain V7 shell,
  207. Xwhich he later contributed to Minix.
  208. X
  209. XI have permission directly from Charles Forsyth to use his shell.
  210. X
  211. X    Eric Gisin, egisin@math.UWaterloo.CA (or Waterloo.EDU)
  212. X
  213. X    Things to do
  214. X- add sxt-based job control (see Brown's contribution on the Usenix 87 tape).
  215. X- add arrays and variable attributes.
  216. X- add MAILPATH and CDPATH.
  217. X- add vi editing mode (apparently someone has a PD version).
  218. X- add new features described in Korn's book.
  219. X
  220. X    Machines ported to
  221. XVAX, 68000, 80386
  222. X
  223. X    OS's ported to
  224. XBSD 4.2, BSD 4.3 (with and without YP and NFS
  225. XSys V.3
  226. SHAR_EOF
  227. true || echo 'restore of src/ReadMe failed'
  228. fi
  229. # ============= src/ksh.1 ==============
  230. if test -f 'src/ksh.1' -a X"$1" != X"-c"; then
  231.     echo 'x - skipping src/ksh.1 (File already exists)'
  232. else
  233. echo 'x - extracting src/ksh.1 (Text)'
  234. sed 's/^X//' << 'SHAR_EOF' > 'src/ksh.1' &&
  235. X.\" $Header: /tmp/egisin/src/RCS/ksh.1,v 3.1 88/11/22 10:44:17 egisin Exp $
  236. X.nr OJ 1 \" Job Control
  237. X.nr OE 1 \" Command Editing
  238. X.nr OB 1 \" BSD enhanced ulimit options
  239. X.ds OK [\|
  240. X.ds CK \|]
  241. X.TH KSH 1 "January 1988"
  242. X.SH NAME
  243. Xksh \- Bourne / Korn Shell (Public Domain)
  244. X.SH SYNOPSIS
  245. X\fBksh\fP
  246. X[\fB\-st\fP] [\fB\-c\fP \fIcommand\fP]
  247. X[\fIfile\fP [\fIargument ...\fP]]
  248. X.SH INTRODUCTION
  249. XThis document only summarizes the System V, release 2 shell features.
  250. XAll of the System V features except for "restricted mode"
  251. Xand the CDPATH and MAIL* variables are implemented.
  252. XSee also the BUGS section.
  253. X.LP
  254. XFeatures of the Korn shell are described in more detail.
  255. XOnly a subset of the Korn shell features are currently implemented.
  256. X.SH DESCRIPTION
  257. X.SS Command syntax
  258. XThe ``#'' character begins a one-line comment,
  259. Xunless the ``#'' occurs inside a word.
  260. XThe tokens ``;'', ``|'', ``&'', ``;;'', ``||'', ``&&'', ``('', and ``)''
  261. Xstand by themselves.
  262. XA \fIword\fP is a sequence of any other non-whitespace characters,
  263. Xwhich may also contain quoted strings
  264. X(quote character are ``\''', ``"'', ``\`'',
  265. Xor a matching ``${ }'' or ``$( )'' pair).
  266. XA \fIname\fP is an unquoted word made up of letters, digits, or ``_''.
  267. XAny number of whitespace characters (space and tab) may separate words and tokens.
  268. X.LP
  269. XIn the following syntax, { ... }? indicates an optional thing,
  270. X{ ... }* indicates zero or more repetitions, { ... | ... } indicates alternatives.
  271. X.de S
  272. X.br
  273. X\\$1
  274. X.br
  275. X..
  276. X.IP statement:
  277. X.S "\fB(\fP list \fB)\fP"
  278. X.S "\fB{\fP list \fB;\fP \fB}\fP"
  279. X.S "\fBfor\fP name { \fBin\fP { word }* }? \fBdo\fP list \fB;\fP \fBdone\fP"
  280. X.S "{ \fBwhile\fP | \fBuntil\fP } list \fB;\fP \fBdo\fP list \fB;\fP \fBdone\fP"
  281. X.S "\fBif\fP list \fB;\fP \fBthen\fP list \fB;\fP { \fBelif\fP list \fB;\fP \fBthen\fP list \fB;\fP }* { \fBelse\fP list \fB;\fP }?\fBfi\fP"
  282. X.S "\fBcase\fP name \fBin\fP { \fB(\fP word { \fB|\fP word } \fB)\fP list \fB;;\fP }* \fBesac\fP"
  283. X.S "\fBfunction\fP name \fB{\fP list \fB;\fP \fB}\fP"
  284. X.S "name \fB() {\fP list \fB;\fP \fB}\fP"
  285. X.S "\fBtime\fP pipe"
  286. XThe opening parenthesis of the pattern is optional. 
  287. XRedirection may occur at the beginning or end of a statement.
  288. X.IP command:
  289. X.S "{ name=word }* { word }*"
  290. XRedirection may occur anywhere in a command.
  291. X.IP list:
  292. X.S "cond"
  293. X.S "cond \fB;\fP list"
  294. X.S "cond \fB&\fP list"
  295. X.IP cond:
  296. X.S "pipe"
  297. X.S "pipe \fB&&\fP cond"
  298. X.S "pipe \fB||\fP cond"
  299. X.IP pipe:
  300. X.S "statement { \fB|\fP statement }*"
  301. X.SS Alias expansion
  302. XAlias expansion occurs when the first word of a statement is a defined alias,
  303. Xexcept when that alias is already being expanded.
  304. XIt also occurs after the expansion of an alias whose definition ends with a space.
  305. X.SS Shell variables
  306. XThe following standard special variables exist:
  307. X\fB!\fP, \fB#\fP, \fB$\fP, \fB\-\fP, \fB?\fP.
  308. X.IP CDPATH
  309. XNot yet implemented.
  310. X.IP ENV
  311. XIf this variable is set at start-up
  312. X(after any profile files are executed),
  313. Xthe expanded value is used as shell start-up file.
  314. XIt typically contains function and alias definitions.
  315. X.IP FCEDIT
  316. XThe editor used by the \fIfc\fP command.
  317. X.IP IFS
  318. X\fIInternal field separator\fP,
  319. Xused during substitution and the \fIread\fP command.
  320. X.IP HOME
  321. XThe default directory for the \fIcd\fP command.
  322. X.IP "MAIL MAILCHECK MAILPATH"
  323. XNot yet implemented.
  324. X.IP PATH
  325. XThe search path for executable commands and \fB.\fP'd files.
  326. X.IP "PS1 PS2"
  327. X\fBPS1\fP is the primary prompt for interactive shells.
  328. XDollar substitution is performed, and \fB!\fP is replaced
  329. Xwith the command number (see \fIfc\fP).
  330. X.IP "PWD OLDPWD"
  331. XThe current and previous working directories.
  332. X.IP SECONDS
  333. XThe number of seconds since the shell was started.
  334. X.SS Substitution
  335. XIn addition to the System Vr2 substitutions,
  336. Xthe following are available.
  337. X.IP "$(command)"
  338. XLike `command`, but no escapes are recognized.
  339. X.IP "$(<file)"
  340. XEquivalent to $(cat file), but without forking.
  341. X.IP "${#var}"
  342. XThe length of the string value of \fIvar\fP,
  343. Xor the number of arguments if \fIvar\fP is \fB*\fP or \fB@\fP.
  344. X.IP "${var#pattern} ${var##pattern}"
  345. XIf \fIpattern\fP matches the beginning of the value of \fIvar\fP,
  346. Xthe matched text is deleted from the result of substitution.
  347. XA single \fB#\fP results in the shortest match,
  348. Xtwo \fB#\fP's results in the longest match.
  349. X.IP "${var%pattern} ${var%%pattern}"
  350. XLike \fB#\fP substition, but deleting from the end of the value.
  351. X.SS Expressions
  352. XExpressions can be used with the \fBlet\fP command,
  353. Xas numeric arguments to the \fBtest\fP command,
  354. Xand as the value of an assignment to an integer variable.
  355. X.LP
  356. XExpression may contain alpha-numeric variable identifiers and integer constants
  357. Xand may be combined with the following operators.
  358. X[list them]
  359. X.SS Command execution
  360. XAfter evaluation of keyword assignments and arguments,
  361. Xthe type of command is determined.
  362. XA command may execute a shell function, a shell built-in,
  363. Xor an executable file.
  364. X.LP
  365. XAny keyword assignments are then performed according to
  366. Xthe type of command.
  367. XIn function calls assignments are local to the function.
  368. XAssignments in built-in commands marked with a \(dg persist,
  369. Xotherwise they are temporary.
  370. XAssignments in executable commands are exported to the sub-process
  371. Xexecuting the command.
  372. X.LP
  373. XThere are several built-in commands.
  374. X.IP ":"
  375. XOnly expansion and assignment are performed.
  376. XThis is the default if a command has no arguments.
  377. X.IP ". \fIfile\fP"
  378. XExecute the commands in \fIfile\fP without forking.
  379. XThe file is searched in the directories of $PATH.
  380. XPassing arguments is not implemented.
  381. X.IP "alias [\fIname\fB=\fIvalue\fI ...]\fR"
  382. XWithout arguments, \fBalias\fP lists all aliases and their values.
  383. XFor any name without a value, its value is listed.
  384. XAny name with a value defines an alias, see "Alias Expansion" above.
  385. XKorn's tracked aliases are not implemented,
  386. Xbut System V command hashing is (see "hash").
  387. X.IP "break [\fIlevels\fP]"
  388. X.IP "builtin \fIcommand arg ...\fP"
  389. X\fICommand\fP is executed as a built-in command.
  390. X.IP "cd [\fIpath\fP]"
  391. XSet the working directory to \fIpath\fP.
  392. XIf \fIpath\fP is missing, the home directory ($HOME) is used.
  393. XIf \fIpath\fP is \fB\-\fP, the previous working directory is used.
  394. XThe PWD and OLDPWD variables are reset.
  395. XThe System V two argument form is not implemented.
  396. X.IP "continue [\fIlevels\fP]"
  397. X.IP "echo ..."
  398. X\fIEcho\fP is replaced with the alias echo='print' in the Korn shell.
  399. X.IP "eval \fIcommand ...\fP"
  400. X.IP "exec \fIcommand arg ...\fP"
  401. XThe executable command is executed without forking.
  402. XIf no arguments are given, any IO redirection is permanent.
  403. X.IP "exit [\fIstatus\fP]"
  404. X.IP "fc [\fB\-l\fP] [\fB\-n\fP] [\fIfirst\fP [\fIlast\fP]]"
  405. XA simple subset of Korn's ``fix command''.
  406. X\fIFirst\fP and \fIlast\fP select commands.
  407. XCommands can be selected by history number,
  408. Xor a string specifing the most recent command starting with that string.
  409. XThe \fB\-l\fP option lists the command on stdout,
  410. Xand \fB\-n\fP inhibits the default command numbers.
  411. XWithout \fB\-l\fP, the selected commands can be edited by
  412. Xthe \fB$FCEDIT\fP editor, then executed by the shell.
  413. X.IP "\fBfc \-s\fP [\fIold\fB=\fInew\fR] [\fIcommand\fP]"
  414. XRe-execute the selected command (the previous command by default)
  415. Xafter performing the optional substitution of \fIold\fP with \fInew\fP.
  416. XThis non-standard command is usually accessed with the predefined alias r="fc -s".
  417. X.IP "getopts"
  418. XSee the attached manual page.
  419. X.IP "hash [\fB\-r\fP] [\fIname ...\fP]"
  420. XWithout arguments, any hashed executable command pathnames are listed.
  421. XThe \fB\-r\fP flag causes all hashed commands to be removed.
  422. XEach \fIname\fP is searched as if it where a command name
  423. Xand added to the hash table if it is an executable command.
  424. X.IP "kill [\fB\-\fIsignal\fR] \fIprocess\fP ..."
  425. XSend a signal (TERM by default) to the named process.
  426. XThe signal may be specified as a number or a mnemonic from <signal.h>
  427. Xwith the SIG prefix removed.
  428. X.IP "let [\fIexpression ...\fP]"
  429. XEach expression is evaluated, see "Expressions" above.
  430. XA zero status is returned if the last expression evaluates
  431. Xto a non-zero value, otherwise a non-zero status is returned.
  432. X.IP "\fBprint\fP [\fB\-nreu\fIn\fR] [\fIargument ...\fP]"
  433. X\fBPrint\fP prints its arguments on the standard output,
  434. Xseparated by spaces, and terminated with a newline.
  435. XThe \fB\-n\fP option eliminates the newline.
  436. X.IP
  437. XBy default, certain C escapes are translated.
  438. XThese include \eb, \ef, \en, \er, \et, \ev, and \e### (# is an octal digit).
  439. X\ec is equivalent to the \fB\-n\fP option.
  440. XThis expansion may be inhibitted with the \fB\-r\fP option,
  441. Xand may be re-enabled with the addition of the \fB\-e\fP option.
  442. X.IP "read [\fB\-ru\fIn\fR] \fIname ...\fP"
  443. XThe first variable name may be of the form \fIname\fB?\fIprompt\fR.
  444. X.IP "readonly [\fIname ...\fP]"
  445. X.IP "return [\fIstatus\fP]"
  446. X.ta 5n 10n 30n
  447. X.de O
  448. X.br
  449. X\t\\$1\t\\$2\t\\$3
  450. X..
  451. X.IP "set [\fB\(+-\fP\fI[a-z]\fP] [\fB\(+-o\fP \fIkeyword\fP] ..."
  452. XSet (\fB\-\fP) or clear (\fB+\fP) a shell option:
  453. X.O \-a allexport "all new variable are created with export attribute"
  454. X.O \-e errexit "exit on non-zero status [incorrect]"
  455. X.O "" bgnice "background jobs are run with lower priority"
  456. X.if \n(OE \{
  457. X.O "" emacs "BRL emacs-like line editing"\}
  458. X.O "" ignoreeof "shell will not exit of EOF, must use \fIexit\fP"
  459. X.O \-k keyword "variable assignments are recognized anywhere in command"
  460. X.O "" markdirs "[not implemented]"
  461. X.if \n(OJ \{
  462. X.O \-m monitor "job control enabled (default for interactive shell)"\}
  463. X.O \-n noexec "compile input but do not execute (ignored if interactive)"
  464. X.O \-f noglob "don't expand filenames"
  465. X.O \-u nounset "dollar expansion of unset variables is an error"
  466. X.O \-v verbose "echo shell commands on stdout when compiling"
  467. X.O \-h trackall "add command pathnames to hash table"
  468. X.O \-x xtrace "echo simple commands while executing"
  469. X.IP "set [\fB\-\-\fP] \fIarg ...\fP"
  470. XSet shell arguments.
  471. X.IP "shift [\fInumber\fP]"
  472. X.IP "test"
  473. XSee the attached manual page.
  474. X.IP "times"
  475. X.IP "trap [\fIhandler\fP] [\fIsignal ...\fP]"
  476. X.IP "typeset [\fB\(+-irtx\fP] [\fIname\fP[\fB=\fIvalue\fR] ...]"
  477. XIf no arguments are given, lists all variables and their attributes.
  478. X.PP
  479. XIf options but no names are given, lists variables with specified
  480. Xattributes, and their values if unless ``+'' is used.
  481. X.PP
  482. XIf names are given, set the attributes of the named variables.
  483. XVariables may also be assigned a value.
  484. XIf used inside a function, the created variable are local to the function.
  485. X.PP
  486. XThe attributes are as follows.
  487. X.ta 5n 10n
  488. X\t\-i\tThe variable's value is stored as an integer.
  489. X.br
  490. X\t\-x\tThe variable is exported to the enviroment.
  491. X.br
  492. X\t\-r\tThe variable is read-only cannot be reassigned a value.
  493. X.br
  494. X\t\-t\tTrace (not implemented).
  495. X.br
  496. X\t\-f\tList functions instead of variable.
  497. X.\".IP "ulimit [\fB\-f\fP] [\fIvalue\fP]"
  498. X.ds OZ <OZ>
  499. X.IP "\fBulimit\fP \*(OK \fB\-\*(OZ\fP \*(CK \*(OK \fIn\fP \*(CK"
  500. X.RS
  501. X.TP "\w'\fB\-\-\ \ \ 'u"
  502. X.if \n(OB \{.B \-c
  503. XImpose a size limit of
  504. X.I n\^
  505. Xblocks on the size of core dumps.
  506. X.TP
  507. X.B \-d
  508. XImpose a size limit of
  509. X.I n\^
  510. Xblocks on the size of the data area.\}
  511. X.TP
  512. X.B \-f
  513. XImpose a size limit of
  514. X.I n
  515. Xblocks on files written by the shell
  516. Xand its child processes (files of any size may be read).
  517. X.if \n(OB \{.TP
  518. X.B \-m
  519. XImpose a soft limit of
  520. X.I n\^
  521. Xblocks on the size of physical memory.
  522. X.TP
  523. X.B \-t
  524. XImpose a time limit of
  525. X.I n\^
  526. Xseconds to be used by each process.\}
  527. X.PP
  528. XIf no option is given,
  529. X.B \-f
  530. Xis assumed.
  531. XIf
  532. X.I n
  533. Xis omitted, the current limit is printed.
  534. XAs far as
  535. X.B ulimit
  536. Xis concerned, a ``block'' is 512 bytes.
  537. X.PP
  538. XYou may lower your own resource limit,
  539. Xbut only a super-user (see
  540. X.IR su (1M))
  541. Xcan raise a limit.
  542. X.RE
  543. X.IP "umask [\fIvalue\fP]"
  544. X.IP "unalias \fIname ...\fP"
  545. XThe aliases for the given names are removed.
  546. X.IP "unset [\fB\-f\fP] \fIname ...\fP"
  547. X.IP "wait [\fIprocess-id\fP]"
  548. X.IP "whence [\fB\-v\fP] name ..."
  549. XFor each name, the type of command is listed.
  550. XThe \fB\-v\fP flag causes function and alias values to be listed.
  551. X.if \n(OJ \{.SS Job Control
  552. XJob control features are enabled by the
  553. X\fB\-m\fP or \fB\-o monitor\fP flags.
  554. XWhen job control is enabled,
  555. Xbackground commands and foreground commands that have been stopped
  556. X(usually by a
  557. X.SM SIGTSTP
  558. Xsignal generated by typing
  559. X.IR ^Z\^ )
  560. Xare placed into separate individual
  561. X.IR "process groups" .
  562. XThe following commands are used to manipulate these process groups:
  563. X.PP
  564. X.PD 0
  565. X.TP "\w'\fBkill\fP \*(OK \fIjob\fP \*(CK\ \ \ 'u"
  566. X\fBjobs\fP
  567. XDisplay information about the controlled jobs.
  568. XThe job number is given preceeded by a percent sign,
  569. Xfollowed by a plus sign if it is the ``current job'',
  570. Xor by a minus sign if it is the ``previous job'',
  571. Xthen the process group number for the job,
  572. Xthen the command.
  573. X.TP
  574. Xkill [\fB\-\fIsignal\fR] \fIjob\fP ...
  575. XSend a signal (TERM by default) to the named job process group.
  576. X.TP
  577. X\fBfg\fP \*(OK \fIjob\fP \*(CK
  578. XResume the stopped foreground job in the foreground.
  579. XIf the process group
  580. X.I n
  581. Xis not specified then the ``current job'' is resumed.
  582. X.TP
  583. X\fBbg\fP \*(OK \fIjob\fP \*(CK
  584. XResume the stopped foreground job in the background.
  585. XIf the process group
  586. X.I n
  587. Xis not specified then the ``current job'' is resumed.
  588. X.PD
  589. X.PP
  590. XThe \fBfg\fP, \fBbg\fP, \fBkill\fP, and \fBwait\fP commands
  591. Xmay refer to jobs with the following ``percent'' sequences.
  592. XThe percent sign is optional with the fg and bg commands.
  593. X.PP
  594. X.PD 0
  595. X.TP "\w'\fBbg\fP \*(OK \fIn\fP \*(CK\ \ \ 'u"
  596. X.BR %+ ( %\- )
  597. XIf there is a ``current job'' (``previous job''),
  598. Xthen that job is selected.
  599. X.TP
  600. X.BI % n
  601. XIf the specified job number is one of the known jobs,
  602. Xthen that job is selected.
  603. X.TP
  604. X.BI % string
  605. XIf the string matches the initial part of a job's command,
  606. Xthen that job is selected.
  607. X.TP
  608. X.BI %? string
  609. XAs above, but the string may match any portion of the command.
  610. X.PD\}
  611. X.br
  612. X.if \n(OE \{.SS "Interactive Input Line Editing"
  613. XWhen the
  614. X.B emacs
  615. Xoption is set,
  616. Xinteractive input line editing is enabled.
  617. XThis mode is slightly different from the emacs mode in AT&T's KornShell.
  618. XIn this mode various
  619. X.I "editing commands"
  620. X(typically bound to one or more control characters)
  621. Xcause immediate actions without waiting for a new-line.
  622. XSeveral
  623. X.I "editing commands"
  624. Xare bound to particular control characters
  625. Xwhen the shell is invoked;
  626. Xthese bindings can be changed using the following commands:
  627. X.br
  628. X.PP
  629. X.PD 0
  630. X.TP 2i
  631. X\fBbind\fP
  632. XThe current bindings are listed.
  633. X.TP
  634. X\fBbind\fP \*(OK \fIstring\fP \*(CK = \*(OK \fIediting-command\fP \*(CK
  635. XThe specified
  636. X.I "editing command\^"
  637. Xis bound to the given
  638. X.IR string ,
  639. Xwhich should consist of a control character
  640. X(which may be written using ``caret notation'' \fB^\fP\fIx\fP\|),
  641. Xoptionally preceded by one of the two prefix characters.
  642. XFuture input of the
  643. X.I string
  644. Xwill cause the
  645. X.I "editing command\^"
  646. Xto be immediately invoked.
  647. X.br
  648. X.TP
  649. X\fBbind -m\fP \*(OK \fIstring\fP \*(CK = \*(OK \fIsubstitute\fP \*(CK
  650. XThe specified input
  651. X.I string
  652. Xwill afterwards be immediately replaced by the given
  653. X.I substitute
  654. Xstring,
  655. Xwhich may contain
  656. X.IR "editing commands" .
  657. X.PD
  658. X.PP
  659. XThe following
  660. X.I "editing commands"
  661. Xare available;
  662. Xfirst the command name is given
  663. Xfollowed by its default binding (if any)
  664. Xusing caret notation
  665. X(note that the ASCII
  666. X.SM ESC
  667. Xcharacter is written as \s-1^[\s0\|),
  668. Xthen the editing function performed is decribed.
  669. XNote that
  670. X.I "editing command"
  671. Xnames are used only with the
  672. X.B bind
  673. Xcommand.
  674. XFurthermore,
  675. Xmany
  676. X.I "editing commands"
  677. Xare useful only on terminals with a visible cursor.
  678. XThe default bindings were chosen to resemble corresponding EMACS key bindings.
  679. X.br
  680. X.PP
  681. X.PD 0
  682. X.TP "\w'\fBdelete-word-backward\ \ ^W\fP\ \ \ 'u"
  683. X\fBabort\ \ ^G\fP
  684. XUseful as a response to a request for a
  685. X.B search-history
  686. Xpattern in order to abort the search.
  687. X.br
  688. X.TP
  689. X\fBauto-insert\fP
  690. XSimply causes the character to appear as literal input.
  691. X(Most ordinary characters are bound to this.)
  692. X.br
  693. X.TP
  694. X\fBbackward-char\ \ ^B\fP
  695. XMoves the cursor backward one character.
  696. X.br
  697. X.TP
  698. X\fBbackward-word\ \ ^[\|b\fP
  699. XMoves the cursor backward to the beginning of a word;
  700. Xwords are delimited by the current setting of \fB\s-1IFS\s0\fP.
  701. X.br
  702. X.TP
  703. X\fBbeginning-of-line\ \ ^A\fP
  704. XMoves the cursor to the beginning of the input line
  705. X(after the prompt string).
  706. X.br
  707. X.TP
  708. X\fBcomplete\ \ ^[\|^[\fP
  709. XAutomatically completes as much as is unique of the hashed command name
  710. Xor the file name containing the cursor.
  711. XIf the entire remaining command or file name is unique
  712. Xa space is printed after its completion,
  713. Xunless it is a directory name in which case
  714. X.B /
  715. Xis postpended.
  716. XIf there is no hashed command or file name with the current partial word
  717. Xas its prefix,
  718. Xa bell character is output (usually causing a ``beep'').
  719. X.br
  720. X.TP
  721. X\fBcomplete-command\ \ ^X^[\fP
  722. XAutomatically completes as much as is unique of the hashed command name
  723. Xhaving the partial word up to the cursor as its prefix,
  724. Xas in the
  725. X.B complete
  726. Xcommand described above.
  727. XOnly command and function names seen since the last
  728. X.B "hash \-r"
  729. Xcommand are available for completion;
  730. Xthe
  731. X.B "hash"
  732. Xcommand may be used to register additional names.
  733. X.br
  734. X.TP
  735. X\fBcomplete-file\ \ ^X\|^X\fP
  736. XAutomatically completes as much as is unique of the file name
  737. Xhaving the partial word up to the cursor as its prefix,
  738. Xas in the
  739. X.B complete
  740. Xcommand described above.
  741. X.br
  742. X.TP
  743. X\fBdelete-char-backward\ \ ^H\fP
  744. XDeletes the character before the cursor.
  745. X.br
  746. X.TP
  747. X\fBdelete-char-forward\ \ ^D\fP
  748. XDeletes the character after the cursor.
  749. X.br
  750. X.TP
  751. X\fBdelete-word-backward\ \ ^W\fP
  752. XDeletes characters before the cursor back to the beginning of a word.
  753. X.br
  754. X.TP
  755. X\fBdelete-word-forward\ \ ^[\|d\fP
  756. XDeletes characters after the cursor up to the end of a word.
  757. X.br
  758. X.TP
  759. X\fBdown-history\ \ ^N\fP
  760. XScrolls the history buffer forward one line (later).
  761. XEach input line originally starts just after
  762. Xthe last entry in the history buffer,
  763. Xso
  764. X.B down-history
  765. Xis not useful until either
  766. X.B search-history
  767. Xor
  768. X.B up-history
  769. Xhas been performed.
  770. X.br
  771. X.TP
  772. X\fBend-of-line\ \ ^E\fP
  773. XMoves the cursor to the end of the input line.
  774. X.br
  775. X.TP
  776. X\fBeot\ \ ^_\fP
  777. XActs as an end-of-file;
  778. Xthis is useful because edit-mode input
  779. Xdisables normal terminal input canonicalization.
  780. X.br
  781. X.TP
  782. X\fBforward-char\ \ ^F\fP
  783. XMoves the cursor forward one position.
  784. X.br
  785. X.TP
  786. X\fBforward-word\ \ ^[\|f\fP
  787. XMoves the cursor forward to the end of a word.
  788. X.br
  789. X.TP
  790. X\fBkill-line\ \ ^U\fP
  791. XDeletes the entire input line.
  792. X.br
  793. X.TP
  794. X\fBkill-to-eol\ \ ^K\fP
  795. XDeletes the input from the cursor to the end of the line.
  796. X.br
  797. X.TP
  798. X\fBlist\ \ ^[\|?\fP
  799. XPrints a sorted, columnated list of hashed command names or file names
  800. X(if any) that can complete the partial word containing the cursor.
  801. XDirectory names have
  802. X.B /
  803. Xpostpended to them,
  804. Xand executable file names are followed by
  805. X.BR \(** .
  806. X.br
  807. X.TP
  808. X\fBlist-command\ \ ^X\|?\fP
  809. XPrints a sorted, columnated list of hashed command names
  810. X(if any) that can complete the partial word containing the cursor.
  811. X.br
  812. X.TP
  813. X\fBlist-file\fP
  814. XPrints a sorted, columnated list of file names
  815. X(if any) that can complete the partial word containing the cursor.
  816. XFile type indicators are postpended as described under
  817. X.B list
  818. Xabove.
  819. X.br
  820. X.TP
  821. X\fBnewline\ \ ^J\ \fP\fIand\^\fP\fB\ ^M\fP
  822. XCauses the current input line to be processed by the shell.
  823. X(The current cursor position may be anywhere on the line.)
  824. X.br
  825. X.TP
  826. X\fBprefix-1\ \ ^[\fP
  827. XIntroduces a 2-character command sequence.
  828. X.br
  829. X.TP
  830. X\fBprefix-2\ \ ^X\fP
  831. XIntroduces a 2-character command sequence.
  832. X.br
  833. X.TP
  834. X\fBquote\ \ ^^\fP
  835. XThe following character is taken literally
  836. Xrather than as an
  837. X.IR "editing command" .
  838. X.br
  839. X.TP
  840. X\fBredraw\ \ ^L\fP
  841. XReprints the prompt string and the current input line.
  842. X.br
  843. X.TP
  844. X\fBsearch-character\ \ ^]\fP
  845. XSearch forward in the current line for the next keyboard character.
  846. X.br
  847. X.TP
  848. X\fBsearch-history\ \ ^R\fP
  849. XEnter incremental search mode.
  850. XThe internal history list is searched backwards for commands matching the input.
  851. XAn initial ``^'' in the search string anchors the search.
  852. XThe escape key will leave search mode.
  853. XOther commands will be executed after leaving search mode.
  854. XSuccessive
  855. X.B search-history
  856. Xcommands continue searching backward
  857. Xto the next previous occurrence of the pattern.
  858. XThe history buffer retains only a finite number of lines;
  859. Xthe oldest are discarded as necessary.
  860. X.br
  861. X.ie \n(OX \{.TP
  862. X\fBstuff\ \ ^T\fP\}
  863. X.el \{.TP
  864. X\fBstuff\fP\}
  865. XOn systems supporting it,
  866. Xpushes the bound character back onto the terminal input
  867. Xwhere it may receive special processing by the terminal handler.
  868. X.if \n(OX \{This is useful for the BRL
  869. X.B ^T
  870. X``mini-systat'' feature,
  871. Xfor example.\}
  872. X.br
  873. X.TP
  874. X\fBstuff-reset\fP
  875. XActs like
  876. X.BR stuff\^ ,
  877. Xthen aborts input the same as an interrupt.
  878. X.br
  879. X.ie \n(OX \{.TP
  880. X\fBtranspose-chars\fP\}
  881. X.el \{.TP
  882. X\fBtranspose-chars\ \ ^T\fP\}
  883. XExchanges the two characters on either side of the cursor.
  884. X.br
  885. X.TP
  886. X\fBup-history\ \ ^P\fP
  887. XScrolls the history buffer backward one line (earlier).
  888. X.br
  889. X.TP
  890. X\fByank\ \ ^Y\fP
  891. XInserts the most recently killed text string at the current cursor position.
  892. X.br
  893. X.TP
  894. X\fByank-pop\ \ ^[\|y\fP
  895. XImmediately after a
  896. X.BR yank ,
  897. Xreplaces the inserted text string with the
  898. Xnext previous killed text string.
  899. X.PD\}
  900. X.br
  901. X.SH FILES
  902. X~/.profile
  903. X.br
  904. X/etc/profile
  905. X.SH SEE ALSO
  906. XSh(1) on System V or Sun OS.
  907. X.LP
  908. X.I "UNIX Shell Programming,"
  909. XStephan G. Kochan,
  910. XPatrick H. Wood,
  911. XHayden.
  912. X.LP
  913. X.I "KornShell: Command and Programming Language (not yet published),"
  914. XMorris Bolsky and David Korn.
  915. X.SH AUTHORS
  916. XBased on the public domain 7th edition Bourne shell.
  917. X.LP
  918. XSystem V and Korn modifications by Eric Gisin,
  919. Xwith contributions by
  920. XRon Natalie, Arnold Robbins, Doug Gwyn, Erik Baalbergen, AT&T (getopt(3)).
  921. X.SH DIFFERENCES FROM AT&T VERSION
  922. XVi editing mode is not implemented.
  923. XThe \fBselect\fP statement is not implemented.
  924. X"\fBfc \-e \-\fP" is not implemented, use "\fBfc \-s\fP".
  925. XThe variables \fBRANDOM\fP and \fBPPID\fP are not implemented.
  926. XVariable arrays are not implemented.
  927. XVariable attributes other than integer are not implemented.
  928. XThe \fBERR\fP and \fBEXIT\fP traps are not implemented for functions.
  929. XAlias expansion is inhibited at the beginning of an alias definition
  930. Xin the AT&T version.
  931. XKorn evaluates expressions differently [elaborate].
  932. X.SH BUGS
  933. XInteractive shells will occasionally hang while waiting for a job.
  934. X.LP
  935. XThe 8th bit is stripped in emacs mode.
  936. X.LP
  937. XPlease report any other bugs by mail to egisin@Waterloo.EDU or egisin@UWaterloo.CA.
  938. X.TH TEST 1 "January 1988" "Korn shell"
  939. X.ta 30n
  940. X.de X
  941. X.br
  942. X\\$1\t\\$2
  943. X..
  944. X.SH NAME
  945. Xtest \- test condition (Korn and 8th edition)
  946. X.SH SYNOPSIS
  947. X\fBtest\fP \fIexpression\fP
  948. X.br
  949. X\fB[\fP \fIexpression\fP \fB]\fP
  950. X.SH DESCRIPTION
  951. X\fBTest\f evalutates the \fIexpression\fP and returns zero status if true,
  952. Xand non-zero status otherwise.
  953. XIt is normally used as the controlling command of the \fBif\fP and \fBwhile\fP statements.
  954. X.LP
  955. XThe following basic expressions are available.
  956. X.IP
  957. X.X "-r file" "file exists and is readable"
  958. X.X "-w file" "file exists and is writable"
  959. X.X "-x file" "file exists and is executable"
  960. X.X "-f file" "file is a regular file"
  961. X.X "-d file" "file is a directory"
  962. X.X "-c file" "file is a character special device"
  963. X.X "-b file" "file is a block special device"
  964. X.X "-p file" "file is a named pipe"
  965. X.X "-u file" "file mode has setuid bit"
  966. X.X "-g file" "file mode has setgid bit"
  967. X.X "-k file" "file mode has sticky bit"
  968. X.X "-s file" "file is not empty"
  969. X.X "-L file" "file is a symbolic link"
  970. X.X "-S file" "file is a socket"
  971. X.X "file -nt file" "first file is newer than second file"
  972. X.X "file -ot file" "first file is older than second file"
  973. X.X "file -ef file" "first file is the same file as second file"
  974. X.X "-t filedes" "file descriptor is a tty device"
  975. X.IP
  976. X.X "string" "string is not null"
  977. X.X "-z string" "string is null"
  978. X.X "-n string" "string is not null"
  979. X.X "string = string" "strings are equal"
  980. X.X "string != string" "strings are not equal"
  981. X.IP
  982. X.X "number -eq number" "numbers compare equal"
  983. X.X "number -ne number" "numbers compare not equal"
  984. X.X "number -ge number" "numbers compare greater than or equal"
  985. X.X "number -gt number" "numbers compare greater than"
  986. X.X "number -le number" "numbers compare less than or equal"
  987. X.X "number -lt number" "numbers compare less than"
  988. X.LP
  989. XThe above basic expressions may be combined with the following operators.
  990. X.IP
  991. X.X "expr -o expr" "logical or"
  992. X.X "expr -a expr" "logical and"
  993. X.X "! expr" "logical not"
  994. X.X "( expr )" "grouping"
  995. X.SH AUTHOR
  996. XErik Baalbergen. Modified by Arnold Robbins.
  997. X.rn LP P
  998. X.TH GETOPTS 1 "January 1988" "Korn shell"
  999. X.SH NAME
  1000. Xgetopts \- parse command options
  1001. X.SH SYNOPSIS
  1002. X.B getopts
  1003. Xoptstring name [arg ...]
  1004. X.SH DESCRIPTION
  1005. X.I getopts
  1006. Xis used by shell procedures
  1007. Xto parse positional parameters and to check for legal options.
  1008. XIt supports all applicable rules of the command syntax standard
  1009. X(see Rules 3-10,
  1010. X.IR intro (1)).
  1011. XIt should be used in place of the
  1012. X.IR getopt (1)
  1013. Xcommand.
  1014. X(See the
  1015. X.BR \s-1WARNING\s0 ,
  1016. Xbelow.)
  1017. X.PP
  1018. X.I optstring
  1019. Xmust contain the option letters the command using
  1020. X.I getopts
  1021. Xwill recognize;
  1022. Xif a letter is followed by a colon,
  1023. Xthe option is expected to have an argument
  1024. Xwhich should be separated from it by white space.
  1025. X.PP
  1026. XEach time it is invoked,
  1027. X.I getopts
  1028. Xwill place the next option in the shell variable
  1029. X.I name
  1030. Xand the index of the next argument to be processed in the shell variable
  1031. X.BR \s-1OPTIND\s0 .
  1032. XWhenever the shell or a shell procedure is invoked,
  1033. X.B \s-1OPTIND\s0
  1034. Xis initialized to
  1035. X.BR 1 .
  1036. X.PP
  1037. XWhen an option requires an option-argument,
  1038. X.I getopts
  1039. Xplaces it in the shell variable
  1040. X.BR \s-1OPTARG\s0 .
  1041. X.P
  1042. XIf an illegal option is encountered,
  1043. X.B ?\&
  1044. Xwill be placed in
  1045. X.IR name .
  1046. X.P
  1047. XWhen the end of the options is encountered,
  1048. X.I getopts
  1049. Xexits with a non-zero exit status.
  1050. XThe special option
  1051. X.RB `` \-\- ''
  1052. Xmay be used to delimit the end of the options.
  1053. X.P
  1054. XBy default,
  1055. X.I getopts
  1056. Xparses the positional parameters.
  1057. XIf extra arguments
  1058. X.RI ( arg
  1059. X\&...) are given on the
  1060. X.I getopts
  1061. Xcommand line,
  1062. X.I getopts
  1063. Xwill parse them instead.
  1064. X.PP
  1065. XSo all new commands will adhere to the command syntax standard described in
  1066. X.IR intro (1),
  1067. Xthey should use
  1068. X.IR getopts (1)
  1069. Xor
  1070. X.IR getopt (3C)
  1071. Xto parse positional parameters
  1072. Xand check for options that are legal for that command
  1073. X(see
  1074. X.BR \s-1WARNINGS\s0 ,
  1075. Xbelow).
  1076. X.SH EXAMPLE
  1077. XThe following fragment of a shell program
  1078. Xshows how one might process the arguments
  1079. Xfor a command that can take the options
  1080. X.B a
  1081. Xor
  1082. X.BR b ,
  1083. Xas well as the option
  1084. X.BR o ,
  1085. Xwhich requires an option-argument:
  1086. X.PP
  1087. X.RS
  1088. X.nf
  1089. X.ss 18
  1090. X.ta +.5i +1i
  1091. X\fBwhile getopts abo: c
  1092. Xdo
  1093. X    case $c in
  1094. X    a\(bvb)    FLAGS=$FLAGS$c;;
  1095. X    o)    OARG=$OPTARG;;
  1096. X    \e?)    echo $USAGE 1>&2
  1097. X        exit 2;;
  1098. X    esac
  1099. Xdone
  1100. Xshift OPTIND\-1\fP
  1101. X.fi
  1102. X.ta
  1103. X.ss 12
  1104. X.RE
  1105. X.PP
  1106. XThis code will accept any of the following as equivalent:
  1107. X.PP
  1108. X.RS
  1109. X.nf
  1110. X.ss 18
  1111. X\fBcmd \-a \-b \-o "xxx z yy" file
  1112. Xcmd \-a \-b \-o "xxx z yy" \-\- file
  1113. Xcmd \-ab \-o "xxx z yy" file
  1114. Xcmd \-ab \-o "xxx z yy" \-\- file\fP
  1115. X.fi
  1116. X.ss 12
  1117. X.RE
  1118. X.SH SEE ALSO
  1119. Xintro(1),
  1120. Xsh(1).
  1121. X.br
  1122. Xgetopt(3C)
  1123. Xin the
  1124. X.IR "Programmer's Reference Manual" .
  1125. X.br
  1126. X.IR "UNIX System V Release 3.0 Release Notes" .
  1127. X.SH WARNING
  1128. XAlthough the following command syntax rule (see
  1129. X.IR intro (1))
  1130. Xrelaxations are permitted under the current implementation,
  1131. Xthey should not be used because they may not be supported
  1132. Xin future releases of the system.
  1133. XAs in the
  1134. X.B \s-1EXAMPLE\s0
  1135. Xsection above,
  1136. X.B a
  1137. Xand
  1138. X.B b
  1139. Xare options,
  1140. Xand the option
  1141. X.B o
  1142. Xrequires an option-argument:
  1143. X.PP
  1144. X.RS
  1145. X.nf
  1146. X.ta +1i +1.5i
  1147. X\fBcmd \-aboxxx file\fP    (Rule 5 violation: options with
  1148. X    option-arguments must not be grouped with other options)
  1149. X\fBcmd \-ab \-oxxx file\fP    (Rule 6 violation: there must be
  1150. X    white space after an option that takes an option-argument)
  1151. X.fi
  1152. X.ta
  1153. X.RE
  1154. X.PP
  1155. XChanging the value of the shell variable
  1156. X.B \s-1OPTIND\s0
  1157. Xor parsing different sets of arguments
  1158. Xmay lead to unexpected results.
  1159. X.SH DIAGNOSTICS
  1160. X.I getopts
  1161. Xprints an error message on the standard error output
  1162. Xwhen it encounters an option letter not included in
  1163. X.IR optstring .
  1164. SHAR_EOF
  1165. true || echo 'restore of src/ksh.1 failed'
  1166. fi
  1167. # ============= src/Makefile ==============
  1168. if test -f 'src/Makefile' -a X"$1" != X"-c"; then
  1169.     echo 'x - skipping src/Makefile (File already exists)'
  1170. else
  1171. echo 'x - extracting src/Makefile (Text)'
  1172. sed 's/^X//' << 'SHAR_EOF' > 'src/Makefile' &&
  1173. X# PD Bourne/Korn Shell
  1174. X
  1175. X# $Header: /tmp/egisin/src/RCS/Makefile,v 3.2 88/11/06 11:34:12 egisin Exp $
  1176. X
  1177. XBIN = /u/egisin/bin
  1178. XSTD = ../std
  1179. XPRINT = lpr -p -Plp26_3018
  1180. X
  1181. X# CC = cc
  1182. XCC = gcc 
  1183. X
  1184. X# Must define one of _V7, _SYSV, _BSD, _POSIX
  1185. X# may define any of JOBS (have BSD or POSIX job control),
  1186. X# EDIT (emacs-like command editing), SILLY (see edit.c)
  1187. X
  1188. XOPTIONS = -D_BSD -DJOBS -DEDIT 
  1189. X
  1190. XCFWARN = -ansi -O -W -Wcomment # -Wreturn-type
  1191. XCFLAGS = $(CFWARN) -I$(STD)/h $(OPTIONS) $(JUNK) 
  1192. XLDFLAGS = -L$(STD) $(JUNK) 
  1193. XLDLIBS = -lstdc -lposix            # compatability libraries
  1194. X
  1195. XHDRS =    sh.h table.h expand.h lex.h tree.h tty.h
  1196. XSRCS1 =    version.c main.c misc.c trap.c alloc.c io.c \
  1197. X    syn.c lex.c edit.c history.c tree.c 
  1198. XSRCS2 =    exec.c jobs.c \
  1199. X    c_sh.c c_ksh.c c_test.c getopts.c ulimit.c \
  1200. X    var.c table.c eval.c expr.c 
  1201. XSRCS =    Makefile $(HDRS) $(SRCS1) $(SRCS2) 
  1202. X
  1203. XOBJS =    version.o main.o misc.o \
  1204. X    syn.o lex.o edit.o tree.o \
  1205. X    exec.o jobs.o trap.o \
  1206. X    c_sh.o c_ksh.o c_test.o \
  1207. X    ulimit.o getopts.o expr.o history.o \
  1208. X    var.o table.o alloc.o io.o eval.o 
  1209. X
  1210. Xksh: $(OBJS) 
  1211. X    $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LDLIBS)
  1212. X
  1213. Xinstall: ksh
  1214. X    cp ksh $(BIN)/ksh
  1215. X
  1216. Xprint: Index $(SRCS)
  1217. X    $(PRINT) Index $(HDRS)
  1218. X    $(PRINT) $(SRCS1) 
  1219. X    $(PRINT) $(SRCS2) 
  1220. X
  1221. XIndex: $(SRCS)
  1222. X    ctags -x $(SRCS) >Index
  1223. X
  1224. Xci:
  1225. X    touch version.c
  1226. X    ci -u -q $(SRCS)
  1227. X
  1228. Xfix_csh:
  1229. X    rm -f /bin/csh
  1230. X
  1231. Xtar:    ReadMe ksh.1 $(SRCS)
  1232. X    tar cf /tmp/egisin/ksh.tar ReadMe ksh.1 $(SRCS)
  1233. X
  1234. SHAR_EOF
  1235. true || echo 'restore of src/Makefile failed'
  1236. fi
  1237. # ============= src/sh.h ==============
  1238. if test -f 'src/sh.h' -a X"$1" != X"-c"; then
  1239.     echo 'x - skipping src/sh.h (File already exists)'
  1240. else
  1241. echo 'x - extracting src/sh.h (Text)'
  1242. sed 's/^X//' << 'SHAR_EOF' > 'src/sh.h' &&
  1243. X/*
  1244. X * Public Domain Bourne/Korn shell
  1245. X */
  1246. X
  1247. X/* $Header: /tmp/egisin/src/RCS/sh.h,v 3.1 88/11/03 09:13:48 egisin Exp $ */
  1248. X
  1249. X/* allow for non-Unix linkers. main.c has a "#define Extern " */
  1250. X#ifndef Extern
  1251. X#define    Extern    extern
  1252. X#endif
  1253. X
  1254. X#ifndef SHELL
  1255. X#define    SHELL    "/bin/sh"    /* shell to exec scripts */
  1256. X#endif
  1257. X
  1258. X#if __STDC__
  1259. X#define    ARGS(args)    args    /* prototype declaration */
  1260. X#define    Void    void        /* generic pointer */
  1261. X#define    Const    const        /* constant data */
  1262. X#define    Volatile volatile    /* you know */
  1263. X#else
  1264. X#define    ARGS(args)    ()    /* K&R declaration */
  1265. X#define    Void    char
  1266. X#define    Const    
  1267. X#define    Volatile 
  1268. X#endif
  1269. X
  1270. X#define    sizeofN(type, n) (sizeof(type) * (n))
  1271. X#define    BIT(i)    (1<<(i))    /* define bit in flag */
  1272. X
  1273. X#define    NUFILE    10        /* Number of user-accessible files */
  1274. X#define    FDBASE    10        /* First file usable by Shell */
  1275. X
  1276. X/* you're not going to run setuid shell scripts, are you? */
  1277. X#define    eaccess(path, mode)    access(path, mode)
  1278. X
  1279. X#define    MAGIC    (char)0x80    /* prefix for ~*?[ during expand */
  1280. X
  1281. X#define    LINE    256        /* input line size */
  1282. X#define    PATH    256        /* pathname size */
  1283. X
  1284. XExtern    int    exstat;        /* exit status */
  1285. XExtern    int    async;        /* $!, last &'d pid */
  1286. X
  1287. X/*
  1288. X * Area-based allocation built on malloc/free
  1289. X */
  1290. X
  1291. Xtypedef struct Area {
  1292. X    struct Block *free;    /* free list */
  1293. X} Area;
  1294. X
  1295. Xextern    Area    aperm;        /* permanent object space */
  1296. X#define    APERM    &aperm
  1297. X#define    ATEMP    &e.area
  1298. X
  1299. XArea   *ainit ARGS((Area *ap));        /* initialize Area */
  1300. Xvoid    afreeall ARGS((Area *ap));    /* free Area's contents */
  1301. Xvoid    ashrink ARGS((Area *ap));    /* unimplimented */
  1302. Xvoid    aerror ARGS((Area *ap, const char *msg)); /* error handler */
  1303. X
  1304. XVoid   *alloc ARGS((size_t size, Area *ap)); /* alloc object from Area */
  1305. XVoid   *aresize ARGS((Void *ptr, size_t size, Area *ap)); /* shrink object */
  1306. Xvoid    afree ARGS((Void *ptr, Area *ap)); /* free ojbect in Area */
  1307. X
  1308. X/*
  1309. X * parsing & execution environment
  1310. X */
  1311. XExtern    struct    env {
  1312. X    int    type;            /* enviroment type - see below */
  1313. X    Area    area;            /* temporary allocation area */
  1314. X    struct    block *loc;        /* local variables and functions */
  1315. X    short  *savefd;            /* original redirected fd's */
  1316. X    struct    env *oenv;        /* link to previous enviroment */
  1317. X    jmp_buf    jbuf;            /* long jump back to env creator */
  1318. X    int    interactive;        /* fd's 0,1,2 are tty */
  1319. X    struct temp *temps;        /* temp files */
  1320. X} e;
  1321. X
  1322. X#define    E_NONE    0        /* dummy enviroment */
  1323. X#define    E_PARSE    1        /* parsing command # */
  1324. X#define    E_EXEC    2        /* executing command tree */
  1325. X#define    E_LOOP    3        /* executing for/while # */
  1326. X#define    E_TCOM    5        /* executing simple command */
  1327. X#define    E_FUNC    6        /* executing function */
  1328. X#define    E_ERRH    7        /* general error handler # */
  1329. X/* # indicates env has valid jbuf */
  1330. X
  1331. X/*
  1332. X * flags
  1333. X */
  1334. X#define    FEXPORT    FLAG('a')    /* -a: allexport */
  1335. X#define    FERREXIT FLAG('e')    /* -e: errexit (quit on error) */
  1336. X#define    FBGNICE    29        /* bgnice */
  1337. X#define    FEMACS 30        /* emacs */
  1338. X#define    FIGNEOF    27        /* ignoreeof (eof does not exit) */
  1339. X#define    FHASHALL FLAG('h')    /* -h: trackall, hashall */
  1340. X#define    FTALKING FLAG('i')    /* -i: interactive (talking type wireless) */
  1341. X#define    FKEYWORD FLAG('k')    /* -k: keyword (name=value anywhere) */
  1342. X#define    FMARKDIRS 28        /* markdirs */
  1343. X#define    FMONITOR FLAG('m')    /* -m: monitor */
  1344. X#define    FNOEXEC    FLAG('n')    /* -n: noexec */
  1345. X#define    FNOGLOB    FLAG('f')    /* -f: noglob */
  1346. X#define    FPRIVILEGED FLAG('p')    /* -p: privileged */
  1347. X#define    FSTDIN    FLAG('s')    /* -s (invocation): parse stdin */
  1348. X#define    FNOUNSET FLAG('u')    /* -u: nounset (unset vars is error) */
  1349. X#define    FVERBOSE FLAG('v')    /* -v: verbose (echo input) */
  1350. X#define    FXTRACE    FLAG('x')    /* -x: (execute) xtrace */
  1351. X
  1352. X#define    FLAG(c)    (1 + c - 'a')    /* map char to flags index */
  1353. X#define    FLAGS    32
  1354. XExtern    char flag [FLAGS];
  1355. Xint    option ARGS((Const char *name));
  1356. Xchar   *getoptions ARGS((void));
  1357. Xvoid    printoptions ARGS((void));
  1358. X
  1359. Xextern    char    null [];    /* null value for variable */
  1360. X
  1361. X/*
  1362. X * other functions
  1363. X */
  1364. Xchar   *search();
  1365. Xstruct tbl *findcom();
  1366. Xchar   *strsave ARGS((char *, Area *));
  1367. Xchar   *ulton ARGS((unsigned long n, int base));
  1368. Xint    xstrcmp();
  1369. Xvoid    qsortp ARGS((void **base, size_t n, int (*compare)(void *, void *)));
  1370. Xlong    evaluate ARGS((Const char *expr));
  1371. Xvoid    resetopts();
  1372. Xvoid    histsave();
  1373. Xvoid    histlist();
  1374. X
  1375. X#if EDIT
  1376. Xvoid    x_init();
  1377. Xvoid    x_bind();
  1378. Xint    x_read();
  1379. X#endif
  1380. X
  1381. Xvoid    j_init ARGS((void));
  1382. Xvoid    j_exit ARGS((void));
  1383. Xvoid    j_notify ARGS((void));
  1384. Xvoid    j_kill ARGS((int job, int sig));
  1385. X#ifdef JOBS
  1386. Xvoid    j_change ARGS((void));
  1387. Xint    j_resume ARGS((int job, int bg));
  1388. X#endif
  1389. X
  1390. X/*
  1391. X * error handling
  1392. X */
  1393. Xvoid    leave();    /* abort shell (or fail in subshell) */
  1394. X
  1395. X/*
  1396. X * library functions
  1397. X */
  1398. Xtypedef    void (*handler_t)();    /* signal handler */
  1399. X
  1400. X/* temp/here files. the file is removed when the struct is freed */
  1401. Xstruct    temp {
  1402. X    struct    temp * next;
  1403. X    char   *name;
  1404. X};
  1405. Xstruct temp *maketemp ARGS((Area *ap));
  1406. X
  1407. X/*
  1408. X * stdio and our IO routines
  1409. X */
  1410. X
  1411. X#ifdef    BUFSIZ            /* <stdio.h> included? */
  1412. Xextern    FILE *    shf [NUFILE];    /* map shell fd to FILE */
  1413. X#endif
  1414. Xvoid    fopenshf();
  1415. Xvoid    flushshf();
  1416. X
  1417. X#undef    stdin
  1418. X#undef    stdout
  1419. X
  1420. X#define    stdin    shf[0]        /* standard input */
  1421. X#define    stdout    shf[1]        /* standard output */
  1422. X#define    shlout    shf[2]        /* shell output */
  1423. X
  1424. Xint    shellf ARGS((Const char *fmt, ...)); /* fprintf(shlout, ); */
  1425. Xint    errorf ARGS((Const char *fmt, ...)); /* fprintf(shlout, ); error(); */
  1426. X
  1427. X/*
  1428. X * IO control
  1429. X */
  1430. Xextern    int ttyfd;        /* tty fd (original fd 0) */
  1431. X
  1432. Xint    savefd ARGS((int fd));    /* save user fd */
  1433. Xvoid    restfd ARGS((int fd, int ofd));
  1434. Xvoid    openpipe ARGS((int [2]));
  1435. Xvoid    closepipe ARGS((int [2]));;
  1436. X
  1437. X/*
  1438. X * trap handlers
  1439. X */
  1440. Xtypedef struct trap {
  1441. X    int    signal;        /* signal number */
  1442. X    char   *name;        /* short name */
  1443. X    char   *mess;        /* descriptive name */
  1444. X    char   *trap;        /* trap command */
  1445. X    short    Volatile set;    /* trap pending */
  1446. X    char    ourtrap;    /* not ignored (?) */
  1447. X    char    sig_dfl;    /* originally SIG_DFL */
  1448. X} Trap;
  1449. X
  1450. X#define    SIGNALS    32
  1451. X
  1452. XExtern    int Volatile trap;    /* traps pending? */
  1453. Xextern    Trap    sigtraps[SIGNALS];
  1454. XTrap    *gettrap ARGS((char *)); /* search for struct trap by number or name */
  1455. Xvoid    trapsig ARGS((int sig)); /* trap signal handler */
  1456. X
  1457. X/*
  1458. X * fast character classes
  1459. X */
  1460. X#define    C_ALPHA    0x01        /* a-z_A-Z */
  1461. X#define    C_DIGIT    0x02        /* 0-9 */
  1462. X#define    C_LEX1    0x04        /* \0 \t\n|&;<>() */
  1463. X#define    C_VAR1    0x08        /* *@#!$-? */
  1464. X#define    C_SUBOP    0x40        /* "=-+?#%" */
  1465. X#define    C_IFS    0x80        /* $IFS */
  1466. X
  1467. Xextern    char ctypes [];
  1468. Xvoid    initctypes ARGS((void));
  1469. Xvoid    setctypes ARGS((Const char*, int type));
  1470. X
  1471. X#define    ctype(c, t)    !!(ctypes[(unsigned char)(c)]&(t))
  1472. X#define    letter(c)    ctype(c, C_ALPHA)
  1473. X#define    digit(c)    ctype(c, C_DIGIT)
  1474. X#define    letnum(c)    ctype(c, C_ALPHA|C_DIGIT)
  1475. X
  1476. SHAR_EOF
  1477. true || echo 'restore of src/sh.h failed'
  1478. fi
  1479. # ============= src/table.h ==============
  1480. if test -f 'src/table.h' -a X"$1" != X"-c"; then
  1481.     echo 'x - skipping src/table.h (File already exists)'
  1482. else
  1483. echo 'x - extracting src/table.h (Text)'
  1484. sed 's/^X//' << 'SHAR_EOF' > 'src/table.h' &&
  1485. X/* $Header: /tmp/egisin/src/RCS/table.h,v 3.1 88/11/03 09:13:56 egisin Exp $ */
  1486. X
  1487. X/*
  1488. X * generic hashed associative table for commands and variables.
  1489. X */
  1490. X
  1491. Xstruct table {
  1492. X    Area   *areap;        /* area to allocate enties */
  1493. X    short    size, free;    /* hash size (always 2^^n), free entries */
  1494. X    struct    tbl **tbls;    /* hashed table items */
  1495. X};
  1496. X
  1497. Xstruct tbl {            /* table item */
  1498. X    short    flag;        /* flags */
  1499. X    short    type;        /* command type or base, see below */
  1500. X    union {
  1501. X        char *s;    /* string */
  1502. X        long i;        /* integer */
  1503. X        int (*f)();    /* int function */
  1504. X        struct op *t;    /* "function" tree */
  1505. X    } val;            /* value */
  1506. X    char    name[4];    /* name -- variable length */
  1507. X};
  1508. X
  1509. X/* flag bits */
  1510. X#define    ALLOC    BIT(0)        /* val.s has been allocated */
  1511. X#define    DEFINED    BIT(1)        /* is defined in block */
  1512. X#define    ISSET    BIT(2)        /* has value, vp->val.[si] */
  1513. X#define    SPECIAL    BIT(3)        /* PATH, IFS, SECONDS, etc */
  1514. X#define    INTEGER    BIT(4)        /* val.i contains integer value */
  1515. X#define    RDONLY    BIT(8)        /* read-only variable */
  1516. X#define    EXPORT    BIT(9)        /* exported variable */
  1517. X#define    LOCAL    BIT(10)        /* for local typeset() */
  1518. X#define    TRACE    BIT(11)        /* trace (-t) */
  1519. X#define    FUNCT    BIT(12)        /* function */
  1520. X
  1521. X/* command types */
  1522. X#define    CNONE    0        /* undefined */
  1523. X#define    CSHELL    1        /* built-in */
  1524. X#define    CFUNC    2        /* function */
  1525. X#define    CEXEC    4        /* executable command */
  1526. X#define    CALIAS    5        /* alias */
  1527. X#define    CKEYWD    6        /* keyword */
  1528. X
  1529. Xvoid tinit ARGS((struct table *, Area *)); /* initialize table */
  1530. Xunsigned int hash();        /* name hash function */
  1531. Xstruct tbl *tsearch();        /* table lookup primative */
  1532. Xstruct tbl *tenter();        /* table lookup/enter primative */
  1533. Xvoid tdelete();            /* mark tbl entry for deletion */
  1534. Xvoid twalk();            /* initialize walk of table */
  1535. Xstruct tbl *tnext();        /* walk table returning table time */
  1536. Xstruct tbl **tsort();        /* sort table entries by name */
  1537. X
  1538. X/*
  1539. X * activation record for function blocks
  1540. X */
  1541. Xstruct block {
  1542. X    Area    area;        /* area to allocate things */
  1543. X    int    argc;        /* current $# */
  1544. X    char **    argv;        /* current $* */
  1545. X    struct    table vars;    /* local variables */
  1546. X    struct    table funs;    /* local functions */
  1547. X#if 1
  1548. X    char *    error;        /* error handler */
  1549. X    char *    exit;        /* exit handler */
  1550. X#else
  1551. X    struct    trap error, exit;
  1552. X#endif
  1553. X    struct    block *next;    /* enclosing block */
  1554. X};
  1555. X
  1556. XExtern    struct block globals;    /* global variables and functions */
  1557. XExtern    struct table commands;    /* hashed commands */
  1558. XExtern    struct table builtins;    /* built-in commands */
  1559. XExtern    struct table lexicals;    /* keywords and aliases */
  1560. XExtern    struct table homedirs;    /* homedir() cache */
  1561. X
  1562. Xstruct builtin {
  1563. X    char   *name;
  1564. X    int  (*func)();
  1565. X};
  1566. XExtern Const struct builtin shbuiltins [], kshbuiltins [];
  1567. X
  1568. X/* var spec values */
  1569. X#define    V_NONE    0
  1570. X#define    V_PATH    1
  1571. X#define    V_IFS    2
  1572. X#define    V_SECONDS 3
  1573. X#define    V_OPTIND 4
  1574. X
  1575. XExtern    Area   *lastarea;    /* area of last variable/function looked up */
  1576. XExtern    char   *path;        /* PATH value */
  1577. XExtern    char   *prompt;        /* PS1 or PS2 */
  1578. X
  1579. Xvoid    newblock();
  1580. Xvoid    popblock();
  1581. Xstruct tbl *global(/* char *s */);
  1582. Xstruct tbl *local(/* char *s */);
  1583. Xstruct tbl *typeset(/* char *var; int set, clr */);
  1584. Xstruct tbl *setvar(/* struct tbl *vdst, *vsrc */);
  1585. Xstruct tbl *strint(/* struct tbl *vdst, *vsrc */);
  1586. Xlong    intval(/* struct tbl *vp */);
  1587. Xvoid    setint(/* struct tbl *vp; long n */);
  1588. Xchar   *strval(/* struct tbl *vp */);
  1589. Xvoid    setstr(/* struct tbl *vp; char *s */);
  1590. Xvoid    unset(/* struct tbl *vp */);
  1591. Xint    import(/* char *s */);
  1592. Xchar  **makenv();
  1593. Xint    isassign(/* char *s */);
  1594. X
  1595. SHAR_EOF
  1596. true || echo 'restore of src/table.h failed'
  1597. fi
  1598. # ============= src/expand.h ==============
  1599. if test -f 'src/expand.h' -a X"$1" != X"-c"; then
  1600.     echo 'x - skipping src/expand.h (File already exists)'
  1601. else
  1602. echo 'x - extracting src/expand.h (Text)'
  1603. sed 's/^X//' << 'SHAR_EOF' > 'src/expand.h' &&
  1604. X/*
  1605. X * Expandable strings
  1606. X *
  1607. X * Usage
  1608. X *    XString xs;
  1609. X *    char *xp;
  1610. X *
  1611. X *    Xinit(xs, xp, 128);
  1612. X *    while ((c = generate()) {
  1613. X *        Xcheck(xs, xp);
  1614. X *        Xput(xs, xp, c);
  1615. X *    }
  1616. X *    return Xclose(xs, xp);
  1617. X */
  1618. X
  1619. Xtypedef struct XString {
  1620. X    char   *end, *beg;    /* end, begin of string */
  1621. X#if 1
  1622. X    char   *oth, *old;    /* togo, adjust */
  1623. X#endif
  1624. X    size_t    len;        /* length */
  1625. X} XString;
  1626. X
  1627. Xtypedef char * XStringP;
  1628. X
  1629. X/* initialize expandable string */
  1630. X#define    Xinit(xs, xp, length) { \
  1631. X            (xs).len = length; \
  1632. X            (xs).beg = alloc((xs).len + 4, ATEMP); \
  1633. X            (xs).end = (xs).beg + (xs).len; \
  1634. X            xp = (xs).beg; \
  1635. X        }
  1636. X
  1637. X/* stuff char into string */
  1638. X#define    Xput(xs, xp, c)    *xp++ = (c)
  1639. X
  1640. X/* check for overflow, expand string */
  1641. X#define    Xcheck(xs, xp) if (xp >= (xs).end) { \
  1642. X            char *old_beg = (xs).beg; \
  1643. X            (xs).len += (xs).len; \
  1644. X            (xs).beg = alloc((xs).len + 4, ATEMP); \
  1645. X            (xs).end = (xs).beg + (xs).len; \
  1646. X            memcpy((xs).beg, old_beg, (size_t)(xp - old_beg)); \
  1647. X            afree((Void*) old_beg, ATEMP); \
  1648. X            xp = (xs).beg + (xp - old_beg); \
  1649. X        }
  1650. X
  1651. X/* free string */
  1652. X#define    Xfree(xs, xp)    afree((Void*) (xs).beg, ATEMP)
  1653. X
  1654. X/* close, return string */
  1655. X#define    Xclose(xs, xp)    (char*) aresize((Void*)(xs).beg, \
  1656. X                    (size_t)(xp - (xs).beg), ATEMP)
  1657. X/* begin of string */
  1658. X#define    Xstring(xs, xp)    ((xs).beg)
  1659. X
  1660. X#define    Xsavepos(xs, xp) (xp - (xs).beg)
  1661. X#define    Xrestpos(xs, xp, n) ((xs).beg + (n))
  1662. X
  1663. X/*
  1664. X * expandable vector of generic pointers
  1665. X */
  1666. X
  1667. Xtypedef struct XPtrV {
  1668. X    Void  **cur;        /* next avail ptr */
  1669. X    Void  **beg, **end;    /* begin, end of vector */
  1670. X} XPtrV;
  1671. X
  1672. X#define    XPinit(x, n) { \
  1673. X            register Void **vp; \
  1674. X            vp = (Void**) alloc(sizeofN(Void*, n), ATEMP); \
  1675. X            (x).cur = (x).beg = vp; \
  1676. X            (x).end = vp + n; \
  1677. X            }
  1678. X
  1679. X#define    XPput(x, p) { \
  1680. X            if ((x).cur >= (x).end) \
  1681. X                xpexpand(&(x)); \
  1682. X            *(x).cur++ = (p); \
  1683. X            }
  1684. X
  1685. X#define    XPptrv(x)    ((x).beg)
  1686. X#define    XPsize(x)    ((x).cur - (x).beg)
  1687. X
  1688. X#define    XPclose(x)    (Void**) aresize((Void*)(x).beg, \
  1689. X                     sizeofN(Void*, XPsize(x)), ATEMP)
  1690. X
  1691. X#define    XPfree(x)    afree((Void*) (x).beg, ATEMP)
  1692. X
  1693. SHAR_EOF
  1694. true || echo 'restore of src/expand.h failed'
  1695. fi
  1696. true || echo 'restore of src/lex.h failed'
  1697. echo End of part 1, continue with part 2
  1698. exit 0
  1699.