Repository navigation
Commit 2172834
committed
Implement POSIX mode for the getopts built-in
When a POSIX shell script that uses getopts is passed one of the
AST self-documentation options (like --help), then the script
aborts and ksh prints a usage message generated from the options
string, which will not contain any self-documentation if it's a
POSIX script. The script is prevented from throwing an error and
showing its own usage message, which may be a lot more informative.
This is a clear incompatibility with the POSIX spec that should be
fixed in the POSIX mode.
We can't fix this purely in ksh93; the libast optget function also
needs to learn about the POSIX mode.
src/lib/libast/include/option.h,
src/lib/libast/misc/optlib.h,
src/lib/libast/misc/optget.c:
- Remove useless padding from Optstate_t; it was ostensibly for ABI
compatibility with old libast versions, but we abandoned that.
- Add a 'posix' flag to Optstate_t, so ksh93 can set opt_info.posix
to activate the POSIX mode in optget.
- optget():
- If the posix flag is set, only process short options with a
single '-' prefix, as specified by POSIX. This disables the AST
self-doc options, too.
- Let the posix flag disable special handling of '-?' as well.
src/cmd/ksh93/bltins/getopts.c:
- b_getopts(): Set the opt_info.posix flag to 1 if the 'posix'
shell option is on *and* the options string passed does not use
the extended ksh interface (as flagged by the 'extended'
variable). This way, scripts running in POSIX mode may still
optionally offer ksh-style long options and self-documentation
(for example, many of ksh's own build scripts do this).1 parent a3aae7f commit 2172834
7 files changed
Lines changed: 42 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
12 | 18 | | |
13 | 19 | | |
14 | 20 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
115 | 115 | | |
116 | 116 | | |
117 | 117 | | |
| 118 | + | |
118 | 119 | | |
119 | 120 | | |
120 | 121 | | |
121 | 122 | | |
122 | 123 | | |
123 | 124 | | |
124 | 125 | | |
| 126 | + | |
125 | 127 | | |
126 | 128 | | |
127 | 129 | | |
| |||
210 | 212 | | |
211 | 213 | | |
212 | 214 | | |
| 215 | + | |
213 | 216 | | |
214 | 217 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6852 | 6852 | | |
6853 | 6853 | | |
6854 | 6854 | | |
6855 | | - | |
| 6855 | + | |
6856 | 6856 | | |
6857 | 6857 | | |
6858 | 6858 | | |
| |||
8137 | 8137 | | |
8138 | 8138 | | |
8139 | 8139 | | |
| 8140 | + | |
| 8141 | + | |
| 8142 | + | |
| 8143 | + | |
| 8144 | + | |
8140 | 8145 | | |
8141 | 8146 | | |
8142 | 8147 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
248 | 248 | | |
249 | 249 | | |
250 | 250 | | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
251 | 259 | | |
252 | 260 | | |
253 | 261 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
50 | | - | |
51 | 49 | | |
52 | | - | |
53 | | - | |
| 50 | + | |
54 | 51 | | |
55 | 52 | | |
56 | 53 | | |
| |||
67 | 64 | | |
68 | 65 | | |
69 | 66 | | |
70 | | - | |
| 67 | + | |
71 | 68 | | |
72 | 69 | | |
73 | 70 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
323 | 323 | | |
324 | 324 | | |
325 | 325 | | |
326 | | - | |
327 | | - | |
328 | | - | |
329 | | - | |
330 | | - | |
331 | | - | |
| 326 | + | |
332 | 327 | | |
333 | 328 | | |
334 | 329 | | |
| |||
4404 | 4399 | | |
4405 | 4400 | | |
4406 | 4401 | | |
4407 | | - | |
| 4402 | + | |
| 4403 | + | |
| 4404 | + | |
| 4405 | + | |
| 4406 | + | |
| 4407 | + | |
| 4408 | + | |
| 4409 | + | |
| 4410 | + | |
| 4411 | + | |
| 4412 | + | |
| 4413 | + | |
| 4414 | + | |
| 4415 | + | |
| 4416 | + | |
4408 | 4417 | | |
4409 | 4418 | | |
4410 | 4419 | | |
| |||
4552 | 4561 | | |
4553 | 4562 | | |
4554 | 4563 | | |
4555 | | - | |
| 4564 | + | |
4556 | 4565 | | |
4557 | 4566 | | |
4558 | 4567 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
106 | | - | |
107 | 106 | | |
108 | 107 | | |
109 | 108 | | |
| |||
0 commit comments