external/mksh
Revisión | c9786cca2575e0a592b5da15094590f283b665ae (tree) |
---|---|
Tiempo | 2018-02-09 02:07:54 |
Autor | Elliott Hughes <enh@goog...> |
Commiter | android-build-merger |
Merge "Upgrade to mksh R56c." am: 0c3dc4139a
am: 7b388008f5
Change-Id: I662a7b4e9feb6b9b8c11e13eeeeb81f55460c725
@@ -108,7 +108,7 @@ cc_defaults { | ||
108 | 108 | "-DHAVE_SYS_ERRLIST_DECL=0", |
109 | 109 | "-DHAVE_SYS_SIGLIST_DECL=1", |
110 | 110 | "-DHAVE_PERSISTENT_HISTORY=0", |
111 | - "-DMKSH_BUILD_R=562", | |
111 | + "-DMKSH_BUILD_R=563", | |
112 | 112 | |
113 | 113 | // Additional flags |
114 | 114 | "-DMKSH_DEFAULT_PROFILEDIR=\"/system/etc\"", |
@@ -1,5 +1,5 @@ | ||
1 | 1 | #!/bin/sh |
2 | -srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.727 2017/08/29 13:38:28 tg Exp $' | |
2 | +srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.731 2018/01/13 21:38:06 tg Exp $' | |
3 | 3 | #- |
4 | 4 | # Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, |
5 | 5 | # 2011, 2012, 2013, 2014, 2015, 2016, 2017 |
@@ -796,6 +796,8 @@ Harvey) | ||
796 | 796 | add_cppflags -DMKSH_ASSUME_UTF8 |
797 | 797 | HAVE_ISSET_MKSH_ASSUME_UTF8=1 |
798 | 798 | HAVE_ISOFF_MKSH_ASSUME_UTF8=0 |
799 | + add_cppflags -DMKSH__NO_SYMLINK | |
800 | + check_categories="$check_categories nosymlink" | |
799 | 801 | add_cppflags -DMKSH_NO_CMDLINE_EDITING |
800 | 802 | add_cppflags -DMKSH__NO_SETEUGID |
801 | 803 | oswarn=' and will currently not work' |
@@ -819,6 +821,20 @@ Interix) | ||
819 | 821 | IRIX*) |
820 | 822 | : "${HAVE_SETLOCALE_CTYPE=0}" |
821 | 823 | ;; |
824 | +Jehanne) | |
825 | + add_cppflags -DMKSH_ASSUME_UTF8 | |
826 | + HAVE_ISSET_MKSH_ASSUME_UTF8=1 | |
827 | + HAVE_ISOFF_MKSH_ASSUME_UTF8=0 | |
828 | + add_cppflags -DMKSH__NO_SYMLINK | |
829 | + check_categories="$check_categories nosymlink" | |
830 | + add_cppflags -DMKSH_NO_CMDLINE_EDITING | |
831 | + add_cppflags -DMKSH_DISABLE_REVOKE_WARNING | |
832 | + add_cppflags '-D_PATH_DEFPATH=\"/cmd\"' | |
833 | + add_cppflags '-DMKSH_DEFAULT_EXECSHELL=\"/cmd/mksh\"' | |
834 | + add_cppflags '-DMKSH_DEFAULT_PROFILEDIR=\"/cfg/mksh\"' | |
835 | + add_cppflags '-DMKSH_ENVDIR=\"/env\"' | |
836 | + SRCS="$SRCS jehanne.c" | |
837 | + ;; | |
822 | 838 | Linux) |
823 | 839 | case $CC in |
824 | 840 | *tendracc*) ;; |
@@ -947,6 +963,8 @@ Plan9) | ||
947 | 963 | add_cppflags -DMKSH_ASSUME_UTF8 |
948 | 964 | HAVE_ISSET_MKSH_ASSUME_UTF8=1 |
949 | 965 | HAVE_ISOFF_MKSH_ASSUME_UTF8=0 |
966 | + add_cppflags -DMKSH__NO_SYMLINK | |
967 | + check_categories="$check_categories nosymlink" | |
950 | 968 | add_cppflags -DMKSH_NO_CMDLINE_EDITING |
951 | 969 | add_cppflags -DMKSH__NO_SETEUGID |
952 | 970 | oswarn=' and will currently not work' |
@@ -2409,7 +2427,7 @@ addsrcs '!' HAVE_STRLCPY strlcpy.c | ||
2409 | 2427 | addsrcs USE_PRINTF_BUILTIN printf.c |
2410 | 2428 | test 1 = "$USE_PRINTF_BUILTIN" && add_cppflags -DMKSH_PRINTF_BUILTIN |
2411 | 2429 | test 1 = "$HAVE_CAN_VERB" && CFLAGS="$CFLAGS -verbose" |
2412 | -add_cppflags -DMKSH_BUILD_R=562 | |
2430 | +add_cppflags -DMKSH_BUILD_R=563 | |
2413 | 2431 | |
2414 | 2432 | $e $bi$me: Finished configuration testing, now producing output.$ao |
2415 | 2433 |
@@ -2733,6 +2751,7 @@ MKSH_DISABLE_DEPRECATED disable code paths scheduled for later removal | ||
2733 | 2751 | MKSH_DISABLE_EXPERIMENTAL disable code not yet comfy for (LTS) snapshots |
2734 | 2752 | MKSH_DISABLE_TTY_WARNING shut up warning about ctty if OS cant be fixed |
2735 | 2753 | MKSH_DONT_EMIT_IDSTRING omit RCS IDs from binary |
2754 | +MKSH_EARLY_LOCALE_TRACKING track utf8-mode from POSIX locale, for SuSE | |
2736 | 2755 | MKSH_MIDNIGHTBSD01ASH_COMPAT set -o sh: additional compatibility quirk |
2737 | 2756 | MKSH_NOPROSPECTOFWORK disable jobs, co-processes, etc. (do not use) |
2738 | 2757 | MKSH_NOPWNAM skip PAM calls, for -static on glibc or Solaris |
@@ -1,4 +1,4 @@ | ||
1 | -# $MirOS: src/bin/mksh/check.t,v 1.797 2017/08/29 13:38:29 tg Exp $ | |
1 | +# $MirOS: src/bin/mksh/check.t,v 1.801 2018/01/14 01:47:33 tg Exp $ | |
2 | 2 | # -*- mode: sh -*- |
3 | 3 | #- |
4 | 4 | # Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, |
@@ -30,7 +30,7 @@ | ||
30 | 30 | # (2013/12/02 20:39:44) http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/regress/bin/ksh/?sortby=date |
31 | 31 | |
32 | 32 | expected-stdout: |
33 | - @(#)MIRBSD KSH R56 2017/08/29 | |
33 | + @(#)MIRBSD KSH R56 2018/01/14 | |
34 | 34 | description: |
35 | 35 | Check base version of full shell |
36 | 36 | stdin: |
@@ -39,7 +39,7 @@ name: KSH_VERSION | ||
39 | 39 | category: !shell:legacy-yes |
40 | 40 | --- |
41 | 41 | expected-stdout: |
42 | - @(#)LEGACY KSH R56 2017/08/29 | |
42 | + @(#)LEGACY KSH R56 2018/01/14 | |
43 | 43 | description: |
44 | 44 | Check base version of legacy shell |
45 | 45 | stdin: |
@@ -3328,7 +3328,7 @@ stdin: | ||
3328 | 3328 | echo B |
3329 | 3329 | ) & |
3330 | 3330 | ' & |
3331 | - sleep 2 | |
3331 | + sleep 5 | |
3332 | 3332 | echo Left overs: * |
3333 | 3333 | expected-stdout: |
3334 | 3334 | A |
@@ -3392,7 +3392,7 @@ stdin: | ||
3392 | 3392 | (sleep 1; foo) & |
3393 | 3393 | foo |
3394 | 3394 | ' & |
3395 | - sleep 2 | |
3395 | + sleep 5 | |
3396 | 3396 | echo Left overs: * |
3397 | 3397 | expected-stdout: |
3398 | 3398 | hi |
@@ -6702,7 +6702,7 @@ name: regression-65 | ||
6702 | 6702 | description: |
6703 | 6703 | check for a regression with sleep builtin and signal mask |
6704 | 6704 | category: !nojsig |
6705 | -time-limit: 3 | |
6705 | +time-limit: 5 | |
6706 | 6706 | stdin: |
6707 | 6707 | sleep 1 |
6708 | 6708 | echo blub |& |
@@ -9026,6 +9026,15 @@ expected-stdout: | ||
9026 | 9026 | .c:a b.c d..: |
9027 | 9027 | .d:a b.c d..: |
9028 | 9028 | --- |
9029 | +name: arrassign-eol | |
9030 | +description: | |
9031 | + Commands after array assignments are not permitted | |
9032 | +stdin: | |
9033 | + foo=(a b) env | |
9034 | +expected-exit: e != 0 | |
9035 | +expected-stderr-pattern: | |
9036 | + /syntax error: unexpected 'env'/ | |
9037 | +--- | |
9029 | 9038 | name: arrassign-fnc-none |
9030 | 9039 | description: |
9031 | 9040 | Check locality of array access inside a function |
@@ -5,7 +5,7 @@ | ||
5 | 5 | |
6 | 6 | /*- |
7 | 7 | * Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, |
8 | - * 2011, 2012, 2013, 2014, 2015, 2016, 2017 | |
8 | + * 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 | |
9 | 9 | * mirabilos <m@mirbsd.org> |
10 | 10 | * |
11 | 11 | * Provided that these terms and disclaimer and all copyright notices |
@@ -28,7 +28,7 @@ | ||
28 | 28 | |
29 | 29 | #ifndef MKSH_NO_CMDLINE_EDITING |
30 | 30 | |
31 | -__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.340 2017/08/27 23:33:50 tg Exp $"); | |
31 | +__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.342 2018/01/14 00:03:00 tg Exp $"); | |
32 | 32 | |
33 | 33 | /* |
34 | 34 | * in later versions we might use libtermcap for this, but since external |
@@ -312,12 +312,12 @@ x_glob_hlp_add_qchar(char *cp) | ||
312 | 312 | */ |
313 | 313 | switch (ord(ch)) { |
314 | 314 | case QCHAR: |
315 | - case ord('$'): | |
316 | - case ord('*'): | |
317 | - case ord('?'): | |
318 | - case ord('['): | |
319 | - case ord('\\'): | |
320 | - case ord('`'): | |
315 | + case ORD('$'): | |
316 | + case ORD('*'): | |
317 | + case ORD('?'): | |
318 | + case ORD('['): | |
319 | + case ORD('\\'): | |
320 | + case ORD('`'): | |
321 | 321 | *dp++ = QCHAR; |
322 | 322 | break; |
323 | 323 | } |
@@ -650,11 +650,11 @@ x_cf_glob(int *flagsp, const char *buf, int buflen, int pos, int *startp, | ||
650 | 650 | if (*s == '\\' && s[1]) |
651 | 651 | s++; |
652 | 652 | else if (ctype(*s, C_QUEST | C_DOLAR) || |
653 | - ord(*s) == ord('*') || ord(*s) == ord('[') || | |
653 | + ord(*s) == ORD('*') || ord(*s) == ORD('[') || | |
654 | 654 | /* ?() *() +() @() !() but two already checked */ |
655 | - (ord(s[1]) == ord('(' /*)*/) && | |
656 | - (ord(*s) == ord('+') || ord(*s) == ord('@') || | |
657 | - ord(*s) == ord('!')))) { | |
655 | + (ord(s[1]) == ORD('(' /*)*/) && | |
656 | + (ord(*s) == ORD('+') || ord(*s) == ORD('@') || | |
657 | + ord(*s) == ORD('!')))) { | |
658 | 658 | /* |
659 | 659 | * just expand based on the extglob |
660 | 660 | * or parameter |
@@ -3688,7 +3688,7 @@ vi_hook(int ch) | ||
3688 | 3688 | return (1); |
3689 | 3689 | cmdlen = 0; |
3690 | 3690 | argc1 = 0; |
3691 | - if (ctype(ch, C_DIGIT) && ord(ch) != ord('0')) { | |
3691 | + if (ctype(ch, C_DIGIT) && ord(ch) != ORD('0')) { | |
3692 | 3692 | argc1 = ksh_numdig(ch); |
3693 | 3693 | state = VARG1; |
3694 | 3694 | } else { |
@@ -3743,7 +3743,7 @@ vi_hook(int ch) | ||
3743 | 3743 | |
3744 | 3744 | case VEXTCMD: |
3745 | 3745 | argc2 = 0; |
3746 | - if (ctype(ch, C_DIGIT) && ord(ch) != ord('0')) { | |
3746 | + if (ctype(ch, C_DIGIT) && ord(ch) != ORD('0')) { | |
3747 | 3747 | argc2 = ksh_numdig(ch); |
3748 | 3748 | state = VARG2; |
3749 | 3749 | return (0); |
@@ -4128,7 +4128,7 @@ vi_cmd(int argcnt, const char *cmd) | ||
4128 | 4128 | redraw_line(true); |
4129 | 4129 | break; |
4130 | 4130 | |
4131 | - case ord('@'): | |
4131 | + case ORD('@'): | |
4132 | 4132 | { |
4133 | 4133 | static char alias[] = "_\0"; |
4134 | 4134 | struct tbl *ap; |
@@ -4169,7 +4169,7 @@ vi_cmd(int argcnt, const char *cmd) | ||
4169 | 4169 | } |
4170 | 4170 | break; |
4171 | 4171 | |
4172 | - case ord('a'): | |
4172 | + case ORD('a'): | |
4173 | 4173 | modified = 1; |
4174 | 4174 | hnum = hlast; |
4175 | 4175 | if (vs->linelen != 0) |
@@ -4177,7 +4177,7 @@ vi_cmd(int argcnt, const char *cmd) | ||
4177 | 4177 | insert = INSERT; |
4178 | 4178 | break; |
4179 | 4179 | |
4180 | - case ord('A'): | |
4180 | + case ORD('A'): | |
4181 | 4181 | modified = 1; |
4182 | 4182 | hnum = hlast; |
4183 | 4183 | del_range(0, 0); |
@@ -4185,7 +4185,7 @@ vi_cmd(int argcnt, const char *cmd) | ||
4185 | 4185 | insert = INSERT; |
4186 | 4186 | break; |
4187 | 4187 | |
4188 | - case ord('S'): | |
4188 | + case ORD('S'): | |
4189 | 4189 | vs->cursor = domovebeg(); |
4190 | 4190 | del_range(vs->cursor, vs->linelen); |
4191 | 4191 | modified = 1; |
@@ -4193,14 +4193,14 @@ vi_cmd(int argcnt, const char *cmd) | ||
4193 | 4193 | insert = INSERT; |
4194 | 4194 | break; |
4195 | 4195 | |
4196 | - case ord('Y'): | |
4196 | + case ORD('Y'): | |
4197 | 4197 | cmd = "y$"; |
4198 | 4198 | /* ahhhhhh... */ |
4199 | 4199 | |
4200 | 4200 | /* FALLTHROUGH */ |
4201 | - case ord('c'): | |
4202 | - case ord('d'): | |
4203 | - case ord('y'): | |
4201 | + case ORD('c'): | |
4202 | + case ORD('d'): | |
4203 | + case ORD('y'): | |
4204 | 4204 | if (*cmd == cmd[1]) { |
4205 | 4205 | c1 = *cmd == 'c' ? domovebeg() : 0; |
4206 | 4206 | c2 = vs->linelen; |
@@ -4239,7 +4239,7 @@ vi_cmd(int argcnt, const char *cmd) | ||
4239 | 4239 | } |
4240 | 4240 | break; |
4241 | 4241 | |
4242 | - case ord('p'): | |
4242 | + case ORD('p'): | |
4243 | 4243 | modified = 1; |
4244 | 4244 | hnum = hlast; |
4245 | 4245 | if (vs->linelen != 0) |
@@ -4253,7 +4253,7 @@ vi_cmd(int argcnt, const char *cmd) | ||
4253 | 4253 | return (-1); |
4254 | 4254 | break; |
4255 | 4255 | |
4256 | - case ord('P'): | |
4256 | + case ORD('P'): | |
4257 | 4257 | modified = 1; |
4258 | 4258 | hnum = hlast; |
4259 | 4259 | any = 0; |
@@ -4266,25 +4266,25 @@ vi_cmd(int argcnt, const char *cmd) | ||
4266 | 4266 | return (-1); |
4267 | 4267 | break; |
4268 | 4268 | |
4269 | - case ord('C'): | |
4269 | + case ORD('C'): | |
4270 | 4270 | modified = 1; |
4271 | 4271 | hnum = hlast; |
4272 | 4272 | del_range(vs->cursor, vs->linelen); |
4273 | 4273 | insert = INSERT; |
4274 | 4274 | break; |
4275 | 4275 | |
4276 | - case ord('D'): | |
4276 | + case ORD('D'): | |
4277 | 4277 | yank_range(vs->cursor, vs->linelen); |
4278 | 4278 | del_range(vs->cursor, vs->linelen); |
4279 | 4279 | if (vs->cursor != 0) |
4280 | 4280 | vs->cursor--; |
4281 | 4281 | break; |
4282 | 4282 | |
4283 | - case ord('g'): | |
4283 | + case ORD('g'): | |
4284 | 4284 | if (!argcnt) |
4285 | 4285 | argcnt = hlast; |
4286 | 4286 | /* FALLTHROUGH */ |
4287 | - case ord('G'): | |
4287 | + case ORD('G'): | |
4288 | 4288 | if (!argcnt) |
4289 | 4289 | argcnt = 1; |
4290 | 4290 | else |
@@ -4297,21 +4297,21 @@ vi_cmd(int argcnt, const char *cmd) | ||
4297 | 4297 | } |
4298 | 4298 | break; |
4299 | 4299 | |
4300 | - case ord('i'): | |
4300 | + case ORD('i'): | |
4301 | 4301 | modified = 1; |
4302 | 4302 | hnum = hlast; |
4303 | 4303 | insert = INSERT; |
4304 | 4304 | break; |
4305 | 4305 | |
4306 | - case ord('I'): | |
4306 | + case ORD('I'): | |
4307 | 4307 | modified = 1; |
4308 | 4308 | hnum = hlast; |
4309 | 4309 | vs->cursor = domovebeg(); |
4310 | 4310 | insert = INSERT; |
4311 | 4311 | break; |
4312 | 4312 | |
4313 | - case ord('j'): | |
4314 | - case ord('+'): | |
4313 | + case ORD('j'): | |
4314 | + case ORD('+'): | |
4315 | 4315 | case CTRL_N: |
4316 | 4316 | if (grabhist(modified, hnum + argcnt) < 0) |
4317 | 4317 | return (-1); |
@@ -4321,8 +4321,8 @@ vi_cmd(int argcnt, const char *cmd) | ||
4321 | 4321 | } |
4322 | 4322 | break; |
4323 | 4323 | |
4324 | - case ord('k'): | |
4325 | - case ord('-'): | |
4324 | + case ORD('k'): | |
4325 | + case ORD('-'): | |
4326 | 4326 | case CTRL_P: |
4327 | 4327 | if (grabhist(modified, hnum - argcnt) < 0) |
4328 | 4328 | return (-1); |
@@ -4332,7 +4332,7 @@ vi_cmd(int argcnt, const char *cmd) | ||
4332 | 4332 | } |
4333 | 4333 | break; |
4334 | 4334 | |
4335 | - case ord('r'): | |
4335 | + case ORD('r'): | |
4336 | 4336 | if (vs->linelen == 0) |
4337 | 4337 | return (-1); |
4338 | 4338 | modified = 1; |
@@ -4350,13 +4350,13 @@ vi_cmd(int argcnt, const char *cmd) | ||
4350 | 4350 | } |
4351 | 4351 | break; |
4352 | 4352 | |
4353 | - case ord('R'): | |
4353 | + case ORD('R'): | |
4354 | 4354 | modified = 1; |
4355 | 4355 | hnum = hlast; |
4356 | 4356 | insert = REPLACE; |
4357 | 4357 | break; |
4358 | 4358 | |
4359 | - case ord('s'): | |
4359 | + case ORD('s'): | |
4360 | 4360 | if (vs->linelen == 0) |
4361 | 4361 | return (-1); |
4362 | 4362 | modified = 1; |
@@ -4367,7 +4367,7 @@ vi_cmd(int argcnt, const char *cmd) | ||
4367 | 4367 | insert = INSERT; |
4368 | 4368 | break; |
4369 | 4369 | |
4370 | - case ord('v'): | |
4370 | + case ORD('v'): | |
4371 | 4371 | if (!argcnt) { |
4372 | 4372 | if (vs->linelen == 0) |
4373 | 4373 | return (-1); |
@@ -4390,7 +4390,7 @@ vi_cmd(int argcnt, const char *cmd) | ||
4390 | 4390 | vs->linelen = strlen(vs->cbuf); |
4391 | 4391 | return (2); |
4392 | 4392 | |
4393 | - case ord('x'): | |
4393 | + case ORD('x'): | |
4394 | 4394 | if (vs->linelen == 0) |
4395 | 4395 | return (-1); |
4396 | 4396 | modified = 1; |
@@ -4401,7 +4401,7 @@ vi_cmd(int argcnt, const char *cmd) | ||
4401 | 4401 | del_range(vs->cursor, vs->cursor + argcnt); |
4402 | 4402 | break; |
4403 | 4403 | |
4404 | - case ord('X'): | |
4404 | + case ORD('X'): | |
4405 | 4405 | if (vs->cursor > 0) { |
4406 | 4406 | modified = 1; |
4407 | 4407 | hnum = hlast; |
@@ -4414,13 +4414,13 @@ vi_cmd(int argcnt, const char *cmd) | ||
4414 | 4414 | return (-1); |
4415 | 4415 | break; |
4416 | 4416 | |
4417 | - case ord('u'): | |
4417 | + case ORD('u'): | |
4418 | 4418 | t = vs; |
4419 | 4419 | vs = undo; |
4420 | 4420 | undo = t; |
4421 | 4421 | break; |
4422 | 4422 | |
4423 | - case ord('U'): | |
4423 | + case ORD('U'): | |
4424 | 4424 | if (!modified) |
4425 | 4425 | return (-1); |
4426 | 4426 | if (grabhist(modified, ohnum) < 0) |
@@ -4429,19 +4429,19 @@ vi_cmd(int argcnt, const char *cmd) | ||
4429 | 4429 | hnum = ohnum; |
4430 | 4430 | break; |
4431 | 4431 | |
4432 | - case ord('?'): | |
4432 | + case ORD('?'): | |
4433 | 4433 | if (hnum == hlast) |
4434 | 4434 | hnum = -1; |
4435 | 4435 | /* ahhh */ |
4436 | 4436 | |
4437 | 4437 | /* FALLTHROUGH */ |
4438 | - case ord('/'): | |
4438 | + case ORD('/'): | |
4439 | 4439 | c3 = 1; |
4440 | 4440 | srchlen = 0; |
4441 | 4441 | lastsearch = *cmd; |
4442 | 4442 | /* FALLTHROUGH */ |
4443 | - case ord('n'): | |
4444 | - case ord('N'): | |
4443 | + case ORD('n'): | |
4444 | + case ORD('N'): | |
4445 | 4445 | if (lastsearch == ' ') |
4446 | 4446 | return (-1); |
4447 | 4447 | if (lastsearch == '?') |
@@ -4468,7 +4468,7 @@ vi_cmd(int argcnt, const char *cmd) | ||
4468 | 4468 | return (0); |
4469 | 4469 | } |
4470 | 4470 | break; |
4471 | - case ord('_'): | |
4471 | + case ORD('_'): | |
4472 | 4472 | { |
4473 | 4473 | bool inspace; |
4474 | 4474 | char *p, *sp; |
@@ -4520,7 +4520,7 @@ vi_cmd(int argcnt, const char *cmd) | ||
4520 | 4520 | } |
4521 | 4521 | break; |
4522 | 4522 | |
4523 | - case ord('~'): | |
4523 | + case ORD('~'): | |
4524 | 4524 | { |
4525 | 4525 | char *p; |
4526 | 4526 | int i; |
@@ -4544,7 +4544,7 @@ vi_cmd(int argcnt, const char *cmd) | ||
4544 | 4544 | break; |
4545 | 4545 | } |
4546 | 4546 | |
4547 | - case ord('#'): | |
4547 | + case ORD('#'): | |
4548 | 4548 | { |
4549 | 4549 | int ret = x_do_comment(vs->cbuf, vs->cbufsize, |
4550 | 4550 | &vs->linelen); |
@@ -4554,7 +4554,7 @@ vi_cmd(int argcnt, const char *cmd) | ||
4554 | 4554 | } |
4555 | 4555 | |
4556 | 4556 | /* AT&T ksh */ |
4557 | - case ord('='): | |
4557 | + case ORD('='): | |
4558 | 4558 | /* Nonstandard vi/ksh */ |
4559 | 4559 | case CTRL_E: |
4560 | 4560 | print_expansions(vs, 1); |
@@ -4574,7 +4574,7 @@ vi_cmd(int argcnt, const char *cmd) | ||
4574 | 4574 | return (-1); |
4575 | 4575 | /* FALLTHROUGH */ |
4576 | 4576 | /* AT&T ksh */ |
4577 | - case ord('\\'): | |
4577 | + case ORD('\\'): | |
4578 | 4578 | /* Nonstandard vi/ksh */ |
4579 | 4579 | case CTRL_F: |
4580 | 4580 | complete_word(1, argcnt); |
@@ -4582,7 +4582,7 @@ vi_cmd(int argcnt, const char *cmd) | ||
4582 | 4582 | |
4583 | 4583 | |
4584 | 4584 | /* AT&T ksh */ |
4585 | - case ord('*'): | |
4585 | + case ORD('*'): | |
4586 | 4586 | /* Nonstandard vi/ksh */ |
4587 | 4587 | case CTRL_X: |
4588 | 4588 | expand_word(1); |
@@ -4590,8 +4590,8 @@ vi_cmd(int argcnt, const char *cmd) | ||
4590 | 4590 | |
4591 | 4591 | |
4592 | 4592 | /* mksh: cursor movement */ |
4593 | - case ord('['): | |
4594 | - case ord('O'): | |
4593 | + case ORD('['): | |
4594 | + case ORD('O'): | |
4595 | 4595 | state = VPREFIX2; |
4596 | 4596 | if (vs->linelen != 0) |
4597 | 4597 | vs->cursor++; |
@@ -4611,19 +4611,19 @@ domove(int argcnt, const char *cmd, int sub) | ||
4611 | 4611 | unsigned int bcount; |
4612 | 4612 | |
4613 | 4613 | switch (ord(*cmd)) { |
4614 | - case ord('b'): | |
4614 | + case ORD('b'): | |
4615 | 4615 | if (!sub && vs->cursor == 0) |
4616 | 4616 | return (-1); |
4617 | 4617 | ncursor = backword(argcnt); |
4618 | 4618 | break; |
4619 | 4619 | |
4620 | - case ord('B'): | |
4620 | + case ORD('B'): | |
4621 | 4621 | if (!sub && vs->cursor == 0) |
4622 | 4622 | return (-1); |
4623 | 4623 | ncursor = Backword(argcnt); |
4624 | 4624 | break; |
4625 | 4625 | |
4626 | - case ord('e'): | |
4626 | + case ORD('e'): | |
4627 | 4627 | if (!sub && vs->cursor + 1 >= vs->linelen) |
4628 | 4628 | return (-1); |
4629 | 4629 | ncursor = endword(argcnt); |
@@ -4631,7 +4631,7 @@ domove(int argcnt, const char *cmd, int sub) | ||
4631 | 4631 | ncursor++; |
4632 | 4632 | break; |
4633 | 4633 | |
4634 | - case ord('E'): | |
4634 | + case ORD('E'): | |
4635 | 4635 | if (!sub && vs->cursor + 1 >= vs->linelen) |
4636 | 4636 | return (-1); |
4637 | 4637 | ncursor = Endword(argcnt); |
@@ -4639,15 +4639,15 @@ domove(int argcnt, const char *cmd, int sub) | ||
4639 | 4639 | ncursor++; |
4640 | 4640 | break; |
4641 | 4641 | |
4642 | - case ord('f'): | |
4643 | - case ord('F'): | |
4644 | - case ord('t'): | |
4645 | - case ord('T'): | |
4642 | + case ORD('f'): | |
4643 | + case ORD('F'): | |
4644 | + case ORD('t'): | |
4645 | + case ORD('T'): | |
4646 | 4646 | fsavecmd = *cmd; |
4647 | 4647 | fsavech = cmd[1]; |
4648 | 4648 | /* FALLTHROUGH */ |
4649 | - case ord(','): | |
4650 | - case ord(';'): | |
4649 | + case ORD(','): | |
4650 | + case ORD(';'): | |
4651 | 4651 | if (fsavecmd == ' ') |
4652 | 4652 | return (-1); |
4653 | 4653 | i = ksh_eq(fsavecmd, 'F', 'f'); |
@@ -4661,7 +4661,7 @@ domove(int argcnt, const char *cmd, int sub) | ||
4661 | 4661 | ncursor++; |
4662 | 4662 | break; |
4663 | 4663 | |
4664 | - case ord('h'): | |
4664 | + case ORD('h'): | |
4665 | 4665 | case CTRL_H: |
4666 | 4666 | if (!sub && vs->cursor == 0) |
4667 | 4667 | return (-1); |
@@ -4670,8 +4670,8 @@ domove(int argcnt, const char *cmd, int sub) | ||
4670 | 4670 | ncursor = 0; |
4671 | 4671 | break; |
4672 | 4672 | |
4673 | - case ord(' '): | |
4674 | - case ord('l'): | |
4673 | + case ORD(' '): | |
4674 | + case ORD('l'): | |
4675 | 4675 | if (!sub && vs->cursor + 1 >= vs->linelen) |
4676 | 4676 | return (-1); |
4677 | 4677 | if (vs->linelen != 0) { |
@@ -4681,27 +4681,27 @@ domove(int argcnt, const char *cmd, int sub) | ||
4681 | 4681 | } |
4682 | 4682 | break; |
4683 | 4683 | |
4684 | - case ord('w'): | |
4684 | + case ORD('w'): | |
4685 | 4685 | if (!sub && vs->cursor + 1 >= vs->linelen) |
4686 | 4686 | return (-1); |
4687 | 4687 | ncursor = forwword(argcnt); |
4688 | 4688 | break; |
4689 | 4689 | |
4690 | - case ord('W'): | |
4690 | + case ORD('W'): | |
4691 | 4691 | if (!sub && vs->cursor + 1 >= vs->linelen) |
4692 | 4692 | return (-1); |
4693 | 4693 | ncursor = Forwword(argcnt); |
4694 | 4694 | break; |
4695 | 4695 | |
4696 | - case ord('0'): | |
4696 | + case ORD('0'): | |
4697 | 4697 | ncursor = 0; |
4698 | 4698 | break; |
4699 | 4699 | |
4700 | - case ord('^'): | |
4700 | + case ORD('^'): | |
4701 | 4701 | ncursor = domovebeg(); |
4702 | 4702 | break; |
4703 | 4703 | |
4704 | - case ord('|'): | |
4704 | + case ORD('|'): | |
4705 | 4705 | ncursor = argcnt; |
4706 | 4706 | if (ncursor > vs->linelen) |
4707 | 4707 | ncursor = vs->linelen; |
@@ -4709,14 +4709,14 @@ domove(int argcnt, const char *cmd, int sub) | ||
4709 | 4709 | ncursor--; |
4710 | 4710 | break; |
4711 | 4711 | |
4712 | - case ord('$'): | |
4712 | + case ORD('$'): | |
4713 | 4713 | if (vs->linelen != 0) |
4714 | 4714 | ncursor = vs->linelen; |
4715 | 4715 | else |
4716 | 4716 | ncursor = 0; |
4717 | 4717 | break; |
4718 | 4718 | |
4719 | - case ord('%'): | |
4719 | + case ORD('%'): | |
4720 | 4720 | ncursor = vs->cursor; |
4721 | 4721 | while (ncursor < vs->linelen && |
4722 | 4722 | (i = bracktype(vs->cbuf[ncursor])) == 0) |
@@ -4784,22 +4784,22 @@ bracktype(int ch) | ||
4784 | 4784 | { |
4785 | 4785 | switch (ord(ch)) { |
4786 | 4786 | |
4787 | - case ord('('): | |
4787 | + case ORD('('): | |
4788 | 4788 | return (1); |
4789 | 4789 | |
4790 | - case ord('['): | |
4790 | + case ORD('['): | |
4791 | 4791 | return (2); |
4792 | 4792 | |
4793 | - case ord('{'): | |
4793 | + case ORD('{'): | |
4794 | 4794 | return (3); |
4795 | 4795 | |
4796 | - case ord(')'): | |
4796 | + case ORD(')'): | |
4797 | 4797 | return (-1); |
4798 | 4798 | |
4799 | - case ord(']'): | |
4799 | + case ORD(']'): | |
4800 | 4800 | return (-2); |
4801 | 4801 | |
4802 | - case ord('}'): | |
4802 | + case ORD('}'): | |
4803 | 4803 | return (-3); |
4804 | 4804 | |
4805 | 4805 | default: |
@@ -2,7 +2,7 @@ | ||
2 | 2 | |
3 | 3 | /*- |
4 | 4 | * Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, |
5 | - * 2011, 2012, 2013, 2014, 2015, 2016, 2017 | |
5 | + * 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 | |
6 | 6 | * mirabilos <m@mirbsd.org> |
7 | 7 | * |
8 | 8 | * Provided that these terms and disclaimer and all copyright notices |
@@ -23,7 +23,7 @@ | ||
23 | 23 | |
24 | 24 | #include "sh.h" |
25 | 25 | |
26 | -__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.215 2017/08/28 23:27:51 tg Exp $"); | |
26 | +__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.219 2018/01/14 01:29:47 tg Exp $"); | |
27 | 27 | |
28 | 28 | /* |
29 | 29 | * string expansion |
@@ -320,21 +320,21 @@ expand( | ||
320 | 320 | case COMASUB: |
321 | 321 | case COMSUB: |
322 | 322 | *dp++ = '('; |
323 | - c = ord(')'); | |
323 | + c = ORD(')'); | |
324 | 324 | break; |
325 | 325 | case FUNASUB: |
326 | 326 | case FUNSUB: |
327 | 327 | case VALSUB: |
328 | 328 | *dp++ = '{'; |
329 | 329 | *dp++ = c == VALSUB ? '|' : ' '; |
330 | - c = ord('}'); | |
330 | + c = ORD('}'); | |
331 | 331 | break; |
332 | 332 | } |
333 | 333 | while (*sp != '\0') { |
334 | 334 | Xcheck(ds, dp); |
335 | 335 | *dp++ = *sp++; |
336 | 336 | } |
337 | - if (c == ord('}')) | |
337 | + if ((unsigned int)c == ORD('}')) | |
338 | 338 | *dp++ = ';'; |
339 | 339 | *dp++ = c; |
340 | 340 | } else { |
@@ -436,11 +436,11 @@ expand( | ||
436 | 436 | if (stype) |
437 | 437 | sp += slen; |
438 | 438 | switch (stype & STYPE_SINGLE) { |
439 | - case ord('#') | STYPE_AT: | |
439 | + case ORD('#') | STYPE_AT: | |
440 | 440 | x.str = shf_smprintf("%08X", |
441 | 441 | (unsigned int)hash(str_val(st->var))); |
442 | 442 | break; |
443 | - case ord('Q') | STYPE_AT: { | |
443 | + case ORD('Q') | STYPE_AT: { | |
444 | 444 | struct shf shf; |
445 | 445 | |
446 | 446 | shf_sopen(NULL, 0, SHF_WR|SHF_DYNAMIC, &shf); |
@@ -448,7 +448,7 @@ expand( | ||
448 | 448 | x.str = shf_sclose(&shf); |
449 | 449 | break; |
450 | 450 | } |
451 | - case ord('0'): { | |
451 | + case ORD('0'): { | |
452 | 452 | char *beg, *mid, *end, *stg; |
453 | 453 | mksh_ari_t from = 0, num = -1, flen, finc = 0; |
454 | 454 |
@@ -456,13 +456,13 @@ expand( | ||
456 | 456 | mid = beg + (wdscan(sp, ADELIM) - sp); |
457 | 457 | stg = beg + (wdscan(sp, CSUBST) - sp); |
458 | 458 | mid[-2] = EOS; |
459 | - if (ord(mid[-1]) == ord(/*{*/ '}')) { | |
459 | + if (ord(mid[-1]) == ORD(/*{*/ '}')) { | |
460 | 460 | sp += mid - beg - 1; |
461 | 461 | end = NULL; |
462 | 462 | } else { |
463 | 463 | end = mid + |
464 | 464 | (wdscan(mid, ADELIM) - mid); |
465 | - if (ord(end[-1]) != ord(/*{*/ '}')) | |
465 | + if (ord(end[-1]) != ORD(/*{*/ '}')) | |
466 | 466 | /* more than max delimiters */ |
467 | 467 | goto unwind_substsyn; |
468 | 468 | end[-2] = EOS; |
@@ -495,8 +495,8 @@ expand( | ||
495 | 495 | strndupx(x.str, beg, num, ATEMP); |
496 | 496 | goto do_CSUBST; |
497 | 497 | } |
498 | - case ord('/') | STYPE_AT: | |
499 | - case ord('/'): { | |
498 | + case ORD('/') | STYPE_AT: | |
499 | + case ORD('/'): { | |
500 | 500 | char *s, *p, *d, *sbeg, *end; |
501 | 501 | char *pat = NULL, *rrep = null; |
502 | 502 | char fpat = 0, *tpat1, *tpat2; |
@@ -506,7 +506,7 @@ expand( | ||
506 | 506 | p = s + (wdscan(sp, ADELIM) - sp); |
507 | 507 | d = s + (wdscan(sp, CSUBST) - sp); |
508 | 508 | p[-2] = EOS; |
509 | - if (ord(p[-1]) == ord(/*{*/ '}')) | |
509 | + if (ord(p[-1]) == ORD(/*{*/ '}')) | |
510 | 510 | d = NULL; |
511 | 511 | else |
512 | 512 | d[-2] = EOS; |
@@ -547,11 +547,11 @@ expand( | ||
547 | 547 | } |
548 | 548 | |
549 | 549 | /* first see if we have any match at all */ |
550 | - if (ord(fpat) == ord('#')) { | |
550 | + if (ord(fpat) == ORD('#')) { | |
551 | 551 | /* anchor at the beginning */ |
552 | 552 | tpat1 = shf_smprintf("%s%c*", pat, MAGIC); |
553 | 553 | tpat2 = tpat1; |
554 | - } else if (ord(fpat) == ord('%')) { | |
554 | + } else if (ord(fpat) == ORD('%')) { | |
555 | 555 | /* anchor at the end */ |
556 | 556 | tpat1 = shf_smprintf("%c*%s", MAGIC, pat); |
557 | 557 | tpat2 = pat; |
@@ -569,7 +569,7 @@ expand( | ||
569 | 569 | goto end_repl; |
570 | 570 | end = strnul(s); |
571 | 571 | /* now anchor the beginning of the match */ |
572 | - if (ord(fpat) != ord('#')) | |
572 | + if (ord(fpat) != ORD('#')) | |
573 | 573 | while (sbeg <= end) { |
574 | 574 | if (gmatchx(sbeg, tpat2, false)) |
575 | 575 | break; |
@@ -578,11 +578,11 @@ expand( | ||
578 | 578 | } |
579 | 579 | /* now anchor the end of the match */ |
580 | 580 | p = end; |
581 | - if (ord(fpat) != ord('%')) | |
581 | + if (ord(fpat) != ORD('%')) | |
582 | 582 | while (p >= sbeg) { |
583 | 583 | bool gotmatch; |
584 | 584 | |
585 | - c = *p; | |
585 | + c = ord(*p); | |
586 | 586 | *p = '\0'; |
587 | 587 | gotmatch = tobool(gmatchx(sbeg, pat, false)); |
588 | 588 | *p = c; |
@@ -622,8 +622,8 @@ expand( | ||
622 | 622 | afree(ws, ATEMP); |
623 | 623 | goto do_CSUBST; |
624 | 624 | } |
625 | - case ord('#'): | |
626 | - case ord('%'): | |
625 | + case ORD('#'): | |
626 | + case ORD('%'): | |
627 | 627 | /* ! DOBLANK,DOBRACE */ |
628 | 628 | f = (f & DONTRUNCOMMAND) | |
629 | 629 | DOPAT | DOTILDE | |
@@ -637,10 +637,10 @@ expand( | ||
637 | 637 | */ |
638 | 638 | if (!Flag(FSH)) { |
639 | 639 | *dp++ = MAGIC; |
640 | - *dp++ = ord(0x80 | '@'); | |
640 | + *dp++ = ORD(0x80 | '@'); | |
641 | 641 | } |
642 | 642 | break; |
643 | - case ord('='): | |
643 | + case ORD('='): | |
644 | 644 | /* |
645 | 645 | * Tilde expansion for string |
646 | 646 | * variables in POSIX mode is |
@@ -664,7 +664,7 @@ expand( | ||
664 | 664 | f &= ~(DOBLANK|DOGLOB|DOBRACE); |
665 | 665 | tilde_ok = 1; |
666 | 666 | break; |
667 | - case ord('?'): | |
667 | + case ORD('?'): | |
668 | 668 | if (*sp == CSUBST) |
669 | 669 | errorf("%s: parameter null or not set", |
670 | 670 | st->var->name); |
@@ -699,8 +699,8 @@ expand( | ||
699 | 699 | if (f & DOBLANK) |
700 | 700 | doblank--; |
701 | 701 | switch (st->stype & STYPE_SINGLE) { |
702 | - case ord('#'): | |
703 | - case ord('%'): | |
702 | + case ORD('#'): | |
703 | + case ORD('%'): | |
704 | 704 | if (!Flag(FSH)) { |
705 | 705 | /* Append end-pattern */ |
706 | 706 | *dp++ = MAGIC; |
@@ -730,7 +730,7 @@ expand( | ||
730 | 730 | doblank++; |
731 | 731 | st = st->prev; |
732 | 732 | continue; |
733 | - case ord('='): | |
733 | + case ORD('='): | |
734 | 734 | /* |
735 | 735 | * Restore our position and substitute |
736 | 736 | * the value of st->var (may not be |
@@ -763,17 +763,17 @@ expand( | ||
763 | 763 | st = st->prev; |
764 | 764 | word = quote || (!*x.str && (f & DOSCALAR)) ? IFS_WORD : IFS_IWS; |
765 | 765 | continue; |
766 | - case ord('?'): | |
766 | + case ORD('?'): | |
767 | 767 | dp = Xrestpos(ds, dp, st->base); |
768 | 768 | |
769 | 769 | errorf(Tf_sD_s, st->var->name, |
770 | 770 | debunk(dp, dp, strlen(dp) + 1)); |
771 | 771 | break; |
772 | - case ord('0'): | |
773 | - case ord('/') | STYPE_AT: | |
774 | - case ord('/'): | |
775 | - case ord('#') | STYPE_AT: | |
776 | - case ord('Q') | STYPE_AT: | |
772 | + case ORD('0'): | |
773 | + case ORD('/') | STYPE_AT: | |
774 | + case ORD('/'): | |
775 | + case ORD('#') | STYPE_AT: | |
776 | + case ORD('Q') | STYPE_AT: | |
777 | 777 | dp = Xrestpos(ds, dp, st->base); |
778 | 778 | type = XSUB; |
779 | 779 | word = quote || (!*x.str && (f & DOSCALAR)) ? IFS_WORD : IFS_IWS; |
@@ -791,19 +791,19 @@ expand( | ||
791 | 791 | /* open pattern: *(foo|bar) */ |
792 | 792 | /* Next char is the type of pattern */ |
793 | 793 | make_magic = true; |
794 | - c = *sp++ | 0x80; | |
794 | + c = ord(*sp++) | 0x80U; | |
795 | 795 | break; |
796 | 796 | |
797 | 797 | case SPAT: |
798 | 798 | /* pattern separator (|) */ |
799 | 799 | make_magic = true; |
800 | - c = '|'; | |
800 | + c = ORD('|'); | |
801 | 801 | break; |
802 | 802 | |
803 | 803 | case CPAT: |
804 | 804 | /* close pattern */ |
805 | 805 | make_magic = true; |
806 | - c = /*(*/ ')'; | |
806 | + c = ORD(/*(*/ ')'); | |
807 | 807 | break; |
808 | 808 | } |
809 | 809 | break; |
@@ -824,7 +824,7 @@ expand( | ||
824 | 824 | |
825 | 825 | case XSUB: |
826 | 826 | case XSUBMID: |
827 | - if ((c = *x.str++) == 0) { | |
827 | + if ((c = ord(*x.str++)) == 0) { | |
828 | 828 | type = XBASE; |
829 | 829 | if (f & DOBLANK) |
830 | 830 | doblank--; |
@@ -837,7 +837,7 @@ expand( | ||
837 | 837 | quote = 1; |
838 | 838 | /* FALLTHROUGH */ |
839 | 839 | case XARG: |
840 | - if ((c = *x.str++) == '\0') { | |
840 | + if ((c = ord(*x.str++)) == '\0') { | |
841 | 841 | /* |
842 | 842 | * force null words to be created so |
843 | 843 | * set -- "" 2 ""; echo "$@" will do |
@@ -855,13 +855,13 @@ expand( | ||
855 | 855 | if ((f & DOHEREDOC)) { |
856 | 856 | /* pseudo-field-split reliably */ |
857 | 857 | if (c == 0) |
858 | - c = ' '; | |
858 | + c = ORD(' '); | |
859 | 859 | break; |
860 | 860 | } |
861 | 861 | if ((f & DOSCALAR)) { |
862 | 862 | /* do not field-split */ |
863 | 863 | if (x.split) { |
864 | - c = ' '; | |
864 | + c = ORD(' '); | |
865 | 865 | break; |
866 | 866 | } |
867 | 867 | if (c == 0) |
@@ -873,7 +873,7 @@ expand( | ||
873 | 873 | if (!quote && word == IFS_WS) |
874 | 874 | continue; |
875 | 875 | /* this is so we don't terminate */ |
876 | - c = ' '; | |
876 | + c = ORD(' '); | |
877 | 877 | /* now force-emit a word */ |
878 | 878 | goto emit_word; |
879 | 879 | } |
@@ -893,33 +893,33 @@ expand( | ||
893 | 893 | c = -1; |
894 | 894 | } else if (newlines) { |
895 | 895 | /* spit out saved NLs */ |
896 | - c = '\n'; | |
896 | + c = ORD('\n'); | |
897 | 897 | --newlines; |
898 | 898 | } else { |
899 | 899 | while ((c = shf_getc(x.u.shf)) == 0 || |
900 | - ctype(c, C_NL)) { | |
900 | + cinttype(c, C_NL)) { | |
901 | 901 | #ifdef MKSH_WITH_TEXTMODE |
902 | - if (c == '\r') { | |
902 | + if (c == ORD('\r')) { | |
903 | 903 | c = shf_getc(x.u.shf); |
904 | 904 | switch (c) { |
905 | - case '\n': | |
905 | + case ORD('\n'): | |
906 | 906 | break; |
907 | 907 | default: |
908 | 908 | shf_ungetc(c, x.u.shf); |
909 | 909 | /* FALLTHROUGH */ |
910 | 910 | case -1: |
911 | - c = '\r'; | |
911 | + c = ORD('\r'); | |
912 | 912 | break; |
913 | 913 | } |
914 | 914 | } |
915 | 915 | #endif |
916 | - if (c == '\n') | |
916 | + if (c == ORD('\n')) | |
917 | 917 | /* save newlines */ |
918 | 918 | newlines++; |
919 | 919 | } |
920 | 920 | if (newlines && c != -1) { |
921 | 921 | shf_ungetc(c, x.u.shf); |
922 | - c = '\n'; | |
922 | + c = ORD('\n'); | |
923 | 923 | --newlines; |
924 | 924 | } |
925 | 925 | } |
@@ -1003,10 +1003,10 @@ expand( | ||
1003 | 1003 | /* mark any special second pass chars */ |
1004 | 1004 | if (!quote) |
1005 | 1005 | switch (ord(c)) { |
1006 | - case ord('['): | |
1007 | - case ord('!'): | |
1008 | - case ord('-'): | |
1009 | - case ord(']'): | |
1006 | + case ORD('['): | |
1007 | + case ORD('!'): | |
1008 | + case ORD('-'): | |
1009 | + case ORD(']'): | |
1010 | 1010 | /* |
1011 | 1011 | * For character classes - doesn't hurt |
1012 | 1012 | * to have magic !,-,]s outside of |
@@ -1014,29 +1014,29 @@ expand( | ||
1014 | 1014 | */ |
1015 | 1015 | if (f & (DOPAT | DOGLOB)) { |
1016 | 1016 | fdo |= DOMAGIC; |
1017 | - if (c == ord('[')) | |
1017 | + if ((unsigned int)c == ORD('[')) | |
1018 | 1018 | fdo |= f & DOGLOB; |
1019 | 1019 | *dp++ = MAGIC; |
1020 | 1020 | } |
1021 | 1021 | break; |
1022 | - case ord('*'): | |
1023 | - case ord('?'): | |
1022 | + case ORD('*'): | |
1023 | + case ORD('?'): | |
1024 | 1024 | if (f & (DOPAT | DOGLOB)) { |
1025 | 1025 | fdo |= DOMAGIC | (f & DOGLOB); |
1026 | 1026 | *dp++ = MAGIC; |
1027 | 1027 | } |
1028 | 1028 | break; |
1029 | - case ord('{'): | |
1030 | - case ord('}'): | |
1031 | - case ord(','): | |
1029 | + case ORD('{'): | |
1030 | + case ORD('}'): | |
1031 | + case ORD(','): | |
1032 | 1032 | if ((f & DOBRACE) && |
1033 | - (ord(c) == ord('{' /*}*/) || | |
1033 | + (ord(c) == ORD('{' /*}*/) || | |
1034 | 1034 | (fdo & DOBRACE))) { |
1035 | 1035 | fdo |= DOBRACE|DOMAGIC; |
1036 | 1036 | *dp++ = MAGIC; |
1037 | 1037 | } |
1038 | 1038 | break; |
1039 | - case ord('='): | |
1039 | + case ORD('='): | |
1040 | 1040 | /* Note first unquoted = for ~ */ |
1041 | 1041 | if (!(f & DOTEMP) && (!Flag(FPOSIX) || |
1042 | 1042 | (f & DOASNTILDE)) && !saw_eq) { |
@@ -1044,13 +1044,13 @@ expand( | ||
1044 | 1044 | tilde_ok = 1; |
1045 | 1045 | } |
1046 | 1046 | break; |
1047 | - case ord(':'): | |
1047 | + case ORD(':'): | |
1048 | 1048 | /* : */ |
1049 | 1049 | /* Note unquoted : for ~ */ |
1050 | 1050 | if (!(f & DOTEMP) && (f & DOASNTILDE)) |
1051 | 1051 | tilde_ok = 1; |
1052 | 1052 | break; |
1053 | - case ord('~'): | |
1053 | + case ORD('~'): | |
1054 | 1054 | /* |
1055 | 1055 | * tilde_ok is reset whenever |
1056 | 1056 | * any of ' " $( $(( ${ } are seen. |
@@ -1133,7 +1133,7 @@ varsub(Expand *xp, const char *sp, const char *word, | ||
1133 | 1133 | * ${%var}, string width (-U: screen columns, +U: octets) |
1134 | 1134 | */ |
1135 | 1135 | c = ord(sp[1]); |
1136 | - if (stype == ord('%') && c == '\0') | |
1136 | + if ((unsigned int)stype == ORD('%') && c == '\0') | |
1137 | 1137 | return (-1); |
1138 | 1138 | if (ctype(stype, C_SUB2) && c != '\0') { |
1139 | 1139 | /* Can't have any modifiers for ${#...} or ${%...} */ |
@@ -1141,11 +1141,11 @@ varsub(Expand *xp, const char *sp, const char *word, | ||
1141 | 1141 | return (-1); |
1142 | 1142 | sp++; |
1143 | 1143 | /* Check for size of array */ |
1144 | - if ((p = cstrchr(sp, '[')) && (ord(p[1]) == ord('*') || | |
1145 | - ord(p[1]) == ord('@')) && ord(p[2]) == ord(']')) { | |
1144 | + if ((p = cstrchr(sp, '[')) && (ord(p[1]) == ORD('*') || | |
1145 | + ord(p[1]) == ORD('@')) && ord(p[2]) == ORD(']')) { | |
1146 | 1146 | int n = 0; |
1147 | 1147 | |
1148 | - if (stype != ord('#')) | |
1148 | + if ((unsigned int)stype != ORD('#')) | |
1149 | 1149 | return (-1); |
1150 | 1150 | vp = global(arrayname(sp)); |
1151 | 1151 | if (vp->flag & (ISSET|ARRAY)) |
@@ -1154,14 +1154,15 @@ varsub(Expand *xp, const char *sp, const char *word, | ||
1154 | 1154 | if (vp->flag & ISSET) |
1155 | 1155 | n++; |
1156 | 1156 | c = n; |
1157 | - } else if (c == ord('*') || c == ord('@')) { | |
1158 | - if (stype != ord('#')) | |
1157 | + } else if ((unsigned int)c == ORD('*') || | |
1158 | + (unsigned int)c == ORD('@')) { | |
1159 | + if ((unsigned int)stype != ORD('#')) | |
1159 | 1160 | return (-1); |
1160 | 1161 | c = e->loc->argc; |
1161 | 1162 | } else { |
1162 | 1163 | p = str_val(global(sp)); |
1163 | 1164 | zero_ok = p != null; |
1164 | - if (stype == ord('#')) | |
1165 | + if ((unsigned int)stype == ORD('#')) | |
1165 | 1166 | c = utflen(p); |
1166 | 1167 | else { |
1167 | 1168 | /* partial utf_mbswidth reimplementation */ |
@@ -1196,11 +1197,11 @@ varsub(Expand *xp, const char *sp, const char *word, | ||
1196 | 1197 | xp->str = shf_smprintf(Tf_d, c); |
1197 | 1198 | return (XSUB); |
1198 | 1199 | } |
1199 | - if (stype == ord('!') && c != '\0' && *word == CSUBST) { | |
1200 | + if ((unsigned int)stype == ORD('!') && c != '\0' && *word == CSUBST) { | |
1200 | 1201 | sp++; |
1201 | - if ((p = cstrchr(sp, '[')) && (ord(p[1]) == ord('*') || | |
1202 | - ord(p[1]) == ord('@')) && ord(p[2]) == ord(']')) { | |
1203 | - c = ord('!'); | |
1202 | + if ((p = cstrchr(sp, '[')) && (ord(p[1]) == ORD('*') || | |
1203 | + ord(p[1]) == ORD('@')) && ord(p[2]) == ORD(']')) { | |
1204 | + c = ORD('!'); | |
1204 | 1205 | stype = 0; |
1205 | 1206 | goto arraynames; |
1206 | 1207 | } |
@@ -1214,12 +1215,12 @@ varsub(Expand *xp, const char *sp, const char *word, | ||
1214 | 1215 | /* Check for qualifiers in word part */ |
1215 | 1216 | stype = 0; |
1216 | 1217 | c = word[slen + 0] == CHAR ? ord(word[slen + 1]) : 0; |
1217 | - if (c == ord(':')) { | |
1218 | + if ((unsigned int)c == ORD(':')) { | |
1218 | 1219 | slen += 2; |
1219 | 1220 | stype = STYPE_DBL; |
1220 | 1221 | c = word[slen + 0] == CHAR ? ord(word[slen + 1]) : 0; |
1221 | 1222 | } |
1222 | - if (!stype && c == ord('/')) { | |
1223 | + if (!stype && (unsigned int)c == ORD('/')) { | |
1223 | 1224 | slen += 2; |
1224 | 1225 | stype = c; |
1225 | 1226 | if (word[slen] == ADELIM && |
@@ -1227,8 +1228,9 @@ varsub(Expand *xp, const char *sp, const char *word, | ||
1227 | 1228 | slen += 2; |
1228 | 1229 | stype |= STYPE_DBL; |
1229 | 1230 | } |
1230 | - } else if (stype == STYPE_DBL && (c == ord(' ') || c == ord('0'))) { | |
1231 | - stype |= ord('0'); | |
1231 | + } else if (stype == STYPE_DBL && ((unsigned int)c == ORD(' ') || | |
1232 | + (unsigned int)c == ORD('0'))) { | |
1233 | + stype |= ORD('0'); | |
1232 | 1234 | } else if (ctype(c, C_SUB1)) { |
1233 | 1235 | slen += 2; |
1234 | 1236 | stype |= c; |
@@ -1241,13 +1243,13 @@ varsub(Expand *xp, const char *sp, const char *word, | ||
1241 | 1243 | stype |= STYPE_DBL; |
1242 | 1244 | slen += 2; |
1243 | 1245 | } |
1244 | - } else if (c == ord('@')) { | |
1246 | + } else if ((unsigned int)c == ORD('@')) { | |
1245 | 1247 | /* @x where x is command char */ |
1246 | 1248 | switch (c = ord(word[slen + 2]) == CHAR ? |
1247 | 1249 | ord(word[slen + 3]) : 0) { |
1248 | - case ord('#'): | |
1249 | - case ord('/'): | |
1250 | - case ord('Q'): | |
1250 | + case ORD('#'): | |
1251 | + case ORD('/'): | |
1252 | + case ORD('Q'): | |
1251 | 1253 | break; |
1252 | 1254 | default: |
1253 | 1255 | return (-1); |
@@ -1261,50 +1263,50 @@ varsub(Expand *xp, const char *sp, const char *word, | ||
1261 | 1263 | return (-1); |
1262 | 1264 | |
1263 | 1265 | c = ord(sp[0]); |
1264 | - if (c == ord('*') || c == ord('@')) { | |
1266 | + if ((unsigned int)c == ORD('*') || (unsigned int)c == ORD('@')) { | |
1265 | 1267 | switch (stype & STYPE_SINGLE) { |
1266 | 1268 | /* can't assign to a vector */ |
1267 | - case ord('='): | |
1269 | + case ORD('='): | |
1268 | 1270 | /* can't trim a vector (yet) */ |
1269 | - case ord('%'): | |
1270 | - case ord('#'): | |
1271 | - case ord('?'): | |
1272 | - case ord('0'): | |
1273 | - case ord('/') | STYPE_AT: | |
1274 | - case ord('/'): | |
1275 | - case ord('#') | STYPE_AT: | |
1276 | - case ord('Q') | STYPE_AT: | |
1271 | + case ORD('%'): | |
1272 | + case ORD('#'): | |
1273 | + case ORD('?'): | |
1274 | + case ORD('0'): | |
1275 | + case ORD('/') | STYPE_AT: | |
1276 | + case ORD('/'): | |
1277 | + case ORD('#') | STYPE_AT: | |
1278 | + case ORD('Q') | STYPE_AT: | |
1277 | 1279 | return (-1); |
1278 | 1280 | } |
1279 | 1281 | if (e->loc->argc == 0) { |
1280 | 1282 | xp->str = null; |
1281 | 1283 | xp->var = global(sp); |
1282 | - state = c == ord('@') ? XNULLSUB : XSUB; | |
1284 | + state = (unsigned int)c == ORD('@') ? XNULLSUB : XSUB; | |
1283 | 1285 | } else { |
1284 | 1286 | xp->u.strv = (const char **)e->loc->argv + 1; |
1285 | 1287 | xp->str = *xp->u.strv++; |
1286 | 1288 | /* $@ */ |
1287 | - xp->split = tobool(c == ord('@')); | |
1289 | + xp->split = tobool((unsigned int)c == ORD('@')); | |
1288 | 1290 | state = XARG; |
1289 | 1291 | } |
1290 | 1292 | /* POSIX 2009? */ |
1291 | 1293 | zero_ok = true; |
1292 | - } else if ((p = cstrchr(sp, '[')) && (ord(p[1]) == ord('*') || | |
1293 | - ord(p[1]) == ord('@')) && ord(p[2]) == ord(']')) { | |
1294 | + } else if ((p = cstrchr(sp, '[')) && (ord(p[1]) == ORD('*') || | |
1295 | + ord(p[1]) == ORD('@')) && ord(p[2]) == ORD(']')) { | |
1294 | 1296 | XPtrV wv; |
1295 | 1297 | |
1296 | 1298 | switch (stype & STYPE_SINGLE) { |
1297 | 1299 | /* can't assign to a vector */ |
1298 | - case ord('='): | |
1300 | + case ORD('='): | |
1299 | 1301 | /* can't trim a vector (yet) */ |
1300 | - case ord('%'): | |
1301 | - case ord('#'): | |
1302 | - case ord('?'): | |
1303 | - case ord('0'): | |
1304 | - case ord('/') | STYPE_AT: | |
1305 | - case ord('/'): | |
1306 | - case ord('#') | STYPE_AT: | |
1307 | - case ord('Q') | STYPE_AT: | |
1302 | + case ORD('%'): | |
1303 | + case ORD('#'): | |
1304 | + case ORD('?'): | |
1305 | + case ORD('0'): | |
1306 | + case ORD('/') | STYPE_AT: | |
1307 | + case ORD('/'): | |
1308 | + case ORD('#') | STYPE_AT: | |
1309 | + case ORD('Q') | STYPE_AT: | |
1308 | 1310 | return (-1); |
1309 | 1311 | } |
1310 | 1312 | c = 0; |
@@ -1314,28 +1316,28 @@ varsub(Expand *xp, const char *sp, const char *word, | ||
1314 | 1316 | for (; vp; vp = vp->u.array) { |
1315 | 1317 | if (!(vp->flag&ISSET)) |
1316 | 1318 | continue; |
1317 | - XPput(wv, c == ord('!') ? shf_smprintf(Tf_lu, | |
1318 | - arrayindex(vp)) : | |
1319 | + XPput(wv, (unsigned int)c == ORD('!') ? | |
1320 | + shf_smprintf(Tf_lu, arrayindex(vp)) : | |
1319 | 1321 | str_val(vp)); |
1320 | 1322 | } |
1321 | 1323 | if (XPsize(wv) == 0) { |
1322 | 1324 | xp->str = null; |
1323 | - state = ord(p[1]) == ord('@') ? XNULLSUB : XSUB; | |
1325 | + state = ord(p[1]) == ORD('@') ? XNULLSUB : XSUB; | |
1324 | 1326 | XPfree(wv); |
1325 | 1327 | } else { |
1326 | 1328 | XPput(wv, 0); |
1327 | 1329 | xp->u.strv = (const char **)XPptrv(wv); |
1328 | 1330 | xp->str = *xp->u.strv++; |
1329 | 1331 | /* ${foo[@]} */ |
1330 | - xp->split = tobool(ord(p[1]) == ord('@')); | |
1332 | + xp->split = tobool(ord(p[1]) == ORD('@')); | |
1331 | 1333 | state = XARG; |
1332 | 1334 | } |
1333 | 1335 | } else { |
1334 | 1336 | xp->var = global(sp); |
1335 | 1337 | xp->str = str_val(xp->var); |
1336 | 1338 | /* can't assign things like $! or $1 */ |
1337 | - if ((stype & STYPE_SINGLE) == ord('=') && !*xp->str && | |
1338 | - ctype(*sp, C_VAR1 | C_DIGIT)) | |
1339 | + if ((unsigned int)(stype & STYPE_SINGLE) == ORD('=') && | |
1340 | + !*xp->str && ctype(*sp, C_VAR1 | C_DIGIT)) | |
1339 | 1341 | return (-1); |
1340 | 1342 | state = XSUB; |
1341 | 1343 | } |
@@ -1346,13 +1348,15 @@ varsub(Expand *xp, const char *sp, const char *word, | ||
1346 | 1348 | (((stype & STYPE_DBL) ? *xp->str == '\0' : xp->str == null) && |
1347 | 1349 | (state != XARG || (ifs0 || xp->split ? |
1348 | 1350 | (xp->u.strv[0] == NULL) : !hasnonempty(xp->u.strv))) ? |
1349 | - ctype(c, C_EQUAL | C_MINUS | C_QUEST) : c == ord('+')))) || | |
1350 | - stype == (ord('0') | STYPE_DBL) || stype == (ord('#') | STYPE_AT) || | |
1351 | - stype == (ord('Q') | STYPE_AT) || (stype & STYPE_CHAR) == ord('/')) | |
1351 | + ctype(c, C_EQUAL | C_MINUS | C_QUEST) : (unsigned int)c == ORD('+')))) || | |
1352 | + (unsigned int)stype == (ORD('0') | STYPE_DBL) || | |
1353 | + (unsigned int)stype == (ORD('#') | STYPE_AT) || | |
1354 | + (unsigned int)stype == (ORD('Q') | STYPE_AT) || | |
1355 | + (unsigned int)(stype & STYPE_CHAR) == ORD('/')) | |
1352 | 1356 | /* expand word instead of variable value */ |
1353 | 1357 | state = XBASE; |
1354 | 1358 | if (Flag(FNOUNSET) && xp->str == null && !zero_ok && |
1355 | - (ctype(c, C_SUB2) || (state != XBASE && c != ord('+')))) | |
1359 | + (ctype(c, C_SUB2) || (state != XBASE && (unsigned int)c != ORD('+')))) | |
1356 | 1360 | errorf(Tf_parm, sp); |
1357 | 1361 | *stypep = stype; |
1358 | 1362 | *slenp = slen; |
@@ -1491,7 +1495,7 @@ trimsub(char *str, char *pat, int how) | ||
1491 | 1495 | char *p, c; |
1492 | 1496 | |
1493 | 1497 | switch (how & (STYPE_CHAR | STYPE_DBL)) { |
1494 | - case ord('#'): | |
1498 | + case ORD('#'): | |
1495 | 1499 | /* shortest match at beginning */ |
1496 | 1500 | for (p = str; p <= end; p += utf_ptradj(p)) { |
1497 | 1501 | c = *p; *p = '\0'; |
@@ -1503,7 +1507,7 @@ trimsub(char *str, char *pat, int how) | ||
1503 | 1507 | *p = c; |
1504 | 1508 | } |
1505 | 1509 | break; |
1506 | - case ord('#') | STYPE_DBL: | |
1510 | + case ORD('#') | STYPE_DBL: | |
1507 | 1511 | /* longest match at beginning */ |
1508 | 1512 | for (p = end; p >= str; p--) { |
1509 | 1513 | c = *p; *p = '\0'; |
@@ -1515,7 +1519,7 @@ trimsub(char *str, char *pat, int how) | ||
1515 | 1519 | *p = c; |
1516 | 1520 | } |
1517 | 1521 | break; |
1518 | - case ord('%'): | |
1522 | + case ORD('%'): | |
1519 | 1523 | /* shortest match at end */ |
1520 | 1524 | p = end; |
1521 | 1525 | while (p >= str) { |
@@ -1531,7 +1535,7 @@ trimsub(char *str, char *pat, int how) | ||
1531 | 1535 | --p; |
1532 | 1536 | } |
1533 | 1537 | break; |
1534 | - case ord('%') | STYPE_DBL: | |
1538 | + case ORD('%') | STYPE_DBL: | |
1535 | 1539 | /* longest match at end */ |
1536 | 1540 | for (p = str; p <= end; p++) |
1537 | 1541 | if (gmatchx(p, pat, false)) { |
@@ -1863,7 +1867,7 @@ alt_expand(XPtrV *wp, char *start, char *exp_start, char *end, int fdo) | ||
1863 | 1867 | char *p = exp_start; |
1864 | 1868 | |
1865 | 1869 | /* search for open brace */ |
1866 | - while ((p = strchr(p, MAGIC)) && ord(p[1]) != ord('{' /*}*/)) | |
1870 | + while ((p = strchr(p, MAGIC)) && ord(p[1]) != ORD('{' /*}*/)) | |
1867 | 1871 | p += 2; |
1868 | 1872 | brace_start = p; |
1869 | 1873 |
@@ -1874,9 +1878,9 @@ alt_expand(XPtrV *wp, char *start, char *exp_start, char *end, int fdo) | ||
1874 | 1878 | p += 2; |
1875 | 1879 | while (*p && count) { |
1876 | 1880 | if (ISMAGIC(*p++)) { |
1877 | - if (ord(*p) == ord('{' /*}*/)) | |
1881 | + if (ord(*p) == ORD('{' /*}*/)) | |
1878 | 1882 | ++count; |
1879 | - else if (ord(*p) == ord(/*{*/ '}')) | |
1883 | + else if (ord(*p) == ORD(/*{*/ '}')) | |
1880 | 1884 | --count; |
1881 | 1885 | else if (*p == ',' && count == 1) |
1882 | 1886 | comma = p; |
@@ -1908,9 +1912,9 @@ alt_expand(XPtrV *wp, char *start, char *exp_start, char *end, int fdo) | ||
1908 | 1912 | count = 1; |
1909 | 1913 | for (p = brace_start + 2; p != brace_end; p++) { |
1910 | 1914 | if (ISMAGIC(*p)) { |
1911 | - if (ord(*++p) == ord('{' /*}*/)) | |
1915 | + if (ord(*++p) == ORD('{' /*}*/)) | |
1912 | 1916 | ++count; |
1913 | - else if ((ord(*p) == ord(/*{*/ '}') && --count == 0) || | |
1917 | + else if ((ord(*p) == ORD(/*{*/ '}') && --count == 0) || | |
1914 | 1918 | (*p == ',' && count == 1)) { |
1915 | 1919 | char *news; |
1916 | 1920 | int l1, l2, l3; |
@@ -23,7 +23,7 @@ | ||
23 | 23 | |
24 | 24 | #include "sh.h" |
25 | 25 | |
26 | -__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.199 2017/08/07 21:16:31 tg Exp $"); | |
26 | +__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.201 2017/10/11 21:09:24 tg Exp $"); | |
27 | 27 | |
28 | 28 | #ifndef MKSH_DEFAULT_EXECSHELL |
29 | 29 | #define MKSH_DEFAULT_EXECSHELL MKSH_UNIXROOT "/bin/sh" |
@@ -953,8 +953,12 @@ scriptexec(struct op *tp, const char **ap) | ||
953 | 953 | } |
954 | 954 | #ifdef __OS2__ |
955 | 955 | /* |
956 | - * Search shell/interpreter name without directory in PATH | |
957 | - * if specified path does not exist | |
956 | + * On OS/2, the directory structure differs from normal | |
957 | + * Unix, which can make many scripts whose shebang | |
958 | + * hardcodes the path to an interpreter fail (and there | |
959 | + * might be no /usr/bin/env); for user convenience, if | |
960 | + * the specified interpreter is not usable, do a PATH | |
961 | + * search to find it. | |
958 | 962 | */ |
959 | 963 | if (mksh_vdirsep(sh) && !search_path(sh, path, X_OK, NULL)) { |
960 | 964 | cp = search_path(_getname(sh), path, X_OK, NULL); |
@@ -1168,11 +1172,7 @@ findcom(const char *name, int flags) | ||
1168 | 1172 | char *fpath; |
1169 | 1173 | union mksh_cchack npath; |
1170 | 1174 | |
1171 | - if (mksh_vdirsep(name) | |
1172 | -#ifdef MKSH_DOSPATH | |
1173 | - && (strcmp(name, T_builtin) != 0) | |
1174 | -#endif | |
1175 | - ) { | |
1175 | + if (mksh_vdirsep(name)) { | |
1176 | 1176 | insert = 0; |
1177 | 1177 | /* prevent FPATH search below */ |
1178 | 1178 | flags &= ~FC_FUNC; |
@@ -2,7 +2,7 @@ | ||
2 | 2 | |
3 | 3 | /*- |
4 | 4 | * Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, |
5 | - * 2011, 2012, 2013, 2014, 2016, 2017 | |
5 | + * 2011, 2012, 2013, 2014, 2016, 2017, 2018 | |
6 | 6 | * mirabilos <m@mirbsd.org> |
7 | 7 | * |
8 | 8 | * Provided that these terms and disclaimer and all copyright notices |
@@ -23,7 +23,7 @@ | ||
23 | 23 | |
24 | 24 | #include "sh.h" |
25 | 25 | |
26 | -__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.100 2017/08/07 21:38:55 tg Exp $"); | |
26 | +__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.103 2018/01/14 01:29:47 tg Exp $"); | |
27 | 27 | |
28 | 28 | #define EXPRTOK_DEFNS |
29 | 29 | #include "exprtok.h" |
@@ -558,9 +558,11 @@ exprtoken(Expr_state *es) | ||
558 | 558 | |
559 | 559 | /* skip whitespace */ |
560 | 560 | skip_spaces: |
561 | - while (ctype(ord((c = *cp)), C_SPACE)) | |
562 | - ++cp; | |
563 | - if (es->tokp == es->expression && c == ord('#')) { | |
561 | + --cp; | |
562 | + do { | |
563 | + c = ord(*++cp); | |
564 | + } while (ctype(c, C_SPACE)); | |
565 | + if (es->tokp == es->expression && (unsigned int)c == ORD('#')) { | |
564 | 566 | /* expression begins with # */ |
565 | 567 | /* switch to unsigned */ |
566 | 568 | es->natural = true; |
@@ -575,7 +577,7 @@ exprtoken(Expr_state *es) | ||
575 | 577 | do { |
576 | 578 | c = ord(*++cp); |
577 | 579 | } while (ctype(c, C_ALNUX)); |
578 | - if (c == ord('[')) { | |
580 | + if ((unsigned int)c == ORD('[')) { | |
579 | 581 | size_t len; |
580 | 582 | |
581 | 583 | len = array_ref_len(cp); |
@@ -884,7 +886,7 @@ static int mb_ucsbsearch(const struct mb_ucsrange arr[], size_t elems, | ||
884 | 886 | |
885 | 887 | /* |
886 | 888 | * Generated from the Unicode Character Database, Version 10.0.0, by |
887 | - * MirOS: contrib/code/Snippets/eawparse,v 1.10 2017/07/12 22:47:26 tg Exp $ | |
889 | + * MirOS: contrib/code/Snippets/eawparse,v 1.12 2017/09/06 16:05:45 tg Exp $ | |
888 | 890 | */ |
889 | 891 | |
890 | 892 | static const struct mb_ucsrange mb_ucs_combining[] = { |
@@ -895,16 +897,14 @@ static const struct mb_ucsrange mb_ucs_combining[] = { | ||
895 | 897 | { 0x05C1, 0x05C2 }, |
896 | 898 | { 0x05C4, 0x05C5 }, |
897 | 899 | { 0x05C7, 0x05C7 }, |
898 | - { 0x0600, 0x0605 }, | |
899 | 900 | { 0x0610, 0x061A }, |
900 | 901 | { 0x061C, 0x061C }, |
901 | 902 | { 0x064B, 0x065F }, |
902 | 903 | { 0x0670, 0x0670 }, |
903 | - { 0x06D6, 0x06DD }, | |
904 | + { 0x06D6, 0x06DC }, | |
904 | 905 | { 0x06DF, 0x06E4 }, |
905 | 906 | { 0x06E7, 0x06E8 }, |
906 | 907 | { 0x06EA, 0x06ED }, |
907 | - { 0x070F, 0x070F }, | |
908 | 908 | { 0x0711, 0x0711 }, |
909 | 909 | { 0x0730, 0x074A }, |
910 | 910 | { 0x07A6, 0x07B0 }, |
@@ -914,7 +914,8 @@ static const struct mb_ucsrange mb_ucs_combining[] = { | ||
914 | 914 | { 0x0825, 0x0827 }, |
915 | 915 | { 0x0829, 0x082D }, |
916 | 916 | { 0x0859, 0x085B }, |
917 | - { 0x08D4, 0x0902 }, | |
917 | + { 0x08D4, 0x08E1 }, | |
918 | + { 0x08E3, 0x0902 }, | |
918 | 919 | { 0x093A, 0x093A }, |
919 | 920 | { 0x093C, 0x093C }, |
920 | 921 | { 0x0941, 0x0948 }, |
@@ -38,7 +38,7 @@ | ||
38 | 38 | #endif |
39 | 39 | #endif |
40 | 40 | |
41 | -__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.350 2017/05/05 22:53:28 tg Exp $"); | |
41 | +__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.353 2018/01/14 01:26:49 tg Exp $"); | |
42 | 42 | |
43 | 43 | #if HAVE_KILLPG |
44 | 44 | /* |
@@ -594,7 +594,7 @@ c_print(const char **wp) | ||
594 | 594 | static int |
595 | 595 | s_get(void) |
596 | 596 | { |
597 | - return (*s_ptr++); | |
597 | + return (ord(*s_ptr++)); | |
598 | 598 | } |
599 | 599 | |
600 | 600 | static void |
@@ -751,9 +751,9 @@ do_whence(const char **wp, int fcflags, bool vflag, bool iscommand) | ||
751 | 751 | bool |
752 | 752 | valid_alias_name(const char *cp) |
753 | 753 | { |
754 | - if (ord(*cp) == ord('-')) | |
754 | + if (ord(*cp) == ORD('-')) | |
755 | 755 | return (false); |
756 | - if (ord(cp[0]) == ord('[') && ord(cp[1]) == ord('[') && !cp[2]) | |
756 | + if (ord(cp[0]) == ORD('[') && ord(cp[1]) == ORD('[') && !cp[2]) | |
757 | 757 | return (false); |
758 | 758 | while (*cp) |
759 | 759 | if (ctype(*cp, C_ALIAS)) |
@@ -2304,9 +2304,9 @@ c_unset(const char **wp) | ||
2304 | 2304 | size_t n; |
2305 | 2305 | |
2306 | 2306 | n = strlen(id); |
2307 | - if (n > 3 && ord(id[n - 3]) == ord('[') && | |
2308 | - ord(id[n - 2]) == ord('*') && | |
2309 | - ord(id[n - 1]) == ord(']')) { | |
2307 | + if (n > 3 && ord(id[n - 3]) == ORD('[') && | |
2308 | + ord(id[n - 2]) == ORD('*') && | |
2309 | + ord(id[n - 1]) == ORD(']')) { | |
2310 | 2310 | strndupx(cp, id, n - 3, ATEMP); |
2311 | 2311 | id = cp; |
2312 | 2312 | optc = 3; |
@@ -3539,7 +3539,7 @@ c_cat(const char **wp) | ||
3539 | 3539 | continue; |
3540 | 3540 | } |
3541 | 3541 | if (errno == EPIPE) { |
3542 | - /* fake receiving signel */ | |
3542 | + /* fake receiving signal */ | |
3543 | 3543 | rv = ksh_sigmask(SIGPIPE); |
3544 | 3544 | } else { |
3545 | 3545 | /* an error occured during writing */ |
@@ -2,7 +2,7 @@ | ||
2 | 2 | |
3 | 3 | /*- |
4 | 4 | * Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2011, |
5 | - * 2012, 2013, 2014, 2015, 2016 | |
5 | + * 2012, 2013, 2014, 2015, 2016, 2018 | |
6 | 6 | * mirabilos <m@mirbsd.org> |
7 | 7 | * |
8 | 8 | * Provided that these terms and disclaimer and all copyright notices |
@@ -23,7 +23,7 @@ | ||
23 | 23 | |
24 | 24 | #include "sh.h" |
25 | 25 | |
26 | -__RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.124 2017/08/08 14:30:10 tg Exp $"); | |
26 | +__RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.125 2018/01/05 20:08:34 tg Exp $"); | |
27 | 27 | |
28 | 28 | #if HAVE_KILLPG |
29 | 29 | #define mksh_killpg killpg |
@@ -1545,7 +1545,9 @@ j_print(Job *j, int how, struct shf *shf) | ||
1545 | 1545 | Proc *p; |
1546 | 1546 | int state; |
1547 | 1547 | int status; |
1548 | +#ifdef WCOREDUMP | |
1548 | 1549 | bool coredumped; |
1550 | +#endif | |
1549 | 1551 | char jobchar = ' '; |
1550 | 1552 | char buf[64]; |
1551 | 1553 | const char *filler; |
@@ -1569,7 +1571,9 @@ j_print(Job *j, int how, struct shf *shf) | ||
1569 | 1571 | jobchar = '-'; |
1570 | 1572 | |
1571 | 1573 | for (p = j->proc_list; p != NULL;) { |
1574 | +#ifdef WCOREDUMP | |
1572 | 1575 | coredumped = false; |
1576 | +#endif | |
1573 | 1577 | switch (p->state) { |
1574 | 1578 | case PRUNNING: |
1575 | 1579 | memcpy(buf, "Running", 8); |
@@ -1603,7 +1607,10 @@ j_print(Job *j, int how, struct shf *shf) | ||
1603 | 1607 | * kludge for not reporting 'normal termination |
1604 | 1608 | * signals' (i.e. SIGINT, SIGPIPE) |
1605 | 1609 | */ |
1606 | - if (how == JP_SHORT && !coredumped && | |
1610 | + if (how == JP_SHORT && | |
1611 | +#ifdef WCOREDUMP | |
1612 | + !coredumped && | |
1613 | +#endif | |
1607 | 1614 | (termsig == SIGINT || termsig == SIGPIPE)) { |
1608 | 1615 | buf[0] = '\0'; |
1609 | 1616 | } else |
@@ -1629,14 +1636,22 @@ j_print(Job *j, int how, struct shf *shf) | ||
1629 | 1636 | if (how == JP_SHORT) { |
1630 | 1637 | if (buf[0]) { |
1631 | 1638 | output = 1; |
1639 | +#ifdef WCOREDUMP | |
1632 | 1640 | shf_fprintf(shf, "%s%s ", |
1633 | 1641 | buf, coredumped ? " (core dumped)" : null); |
1642 | +#else | |
1643 | + shf_puts(buf, shf); | |
1644 | + shf_putchar(' ', shf); | |
1645 | +#endif | |
1634 | 1646 | } |
1635 | 1647 | } else { |
1636 | 1648 | output = 1; |
1637 | 1649 | shf_fprintf(shf, "%-20s %s%s%s", buf, p->command, |
1638 | 1650 | p->next ? "|" : null, |
1639 | - coredumped ? " (core dumped)" : null); | |
1651 | +#ifdef WCOREDUMP | |
1652 | + coredumped ? " (core dumped)" : | |
1653 | +#endif | |
1654 | + null); | |
1640 | 1655 | } |
1641 | 1656 | |
1642 | 1657 | state = p->state; |
@@ -2,7 +2,7 @@ | ||
2 | 2 | |
3 | 3 | /*- |
4 | 4 | * Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, |
5 | - * 2011, 2012, 2013, 2014, 2015, 2016, 2017 | |
5 | + * 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 | |
6 | 6 | * mirabilos <m@mirbsd.org> |
7 | 7 | * |
8 | 8 | * Provided that these terms and disclaimer and all copyright notices |
@@ -23,7 +23,7 @@ | ||
23 | 23 | |
24 | 24 | #include "sh.h" |
25 | 25 | |
26 | -__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.239 2017/05/05 22:53:29 tg Exp $"); | |
26 | +__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.247 2018/01/14 01:44:01 tg Exp $"); | |
27 | 27 | |
28 | 28 | /* |
29 | 29 | * states while lexing word |
@@ -127,11 +127,11 @@ static int ignore_backslash_newline; | ||
127 | 127 | static int |
128 | 128 | getsc_i(void) |
129 | 129 | { |
130 | - o_getsc_r(o_getsc()); | |
130 | + o_getsc_r((unsigned int)(unsigned char)o_getsc()); | |
131 | 131 | } |
132 | 132 | |
133 | 133 | #if defined(MKSH_SMALL) && !defined(MKSH_SMALL_BUT_FAST) |
134 | -#define getsc() ord(getsc_i()) | |
134 | +#define getsc() getsc_i() | |
135 | 135 | #else |
136 | 136 | static int getsc_r(int); |
137 | 137 |
@@ -141,7 +141,7 @@ getsc_r(int c) | ||
141 | 141 | o_getsc_r(c); |
142 | 142 | } |
143 | 143 | |
144 | -#define getsc() ord(getsc_r(o_getsc())) | |
144 | +#define getsc() getsc_r((unsigned int)(unsigned char)o_getsc()) | |
145 | 145 | #endif |
146 | 146 | |
147 | 147 | #define STATE_BSIZE 8 |
@@ -220,12 +220,14 @@ yylex(int cf) | ||
220 | 220 | } else { |
221 | 221 | /* normal lexing */ |
222 | 222 | state = (cf & HEREDELIM) ? SHEREDELIM : SBASE; |
223 | - while (ctype((c = getsc()), C_BLANK)) | |
224 | - ; | |
223 | + do { | |
224 | + c = getsc(); | |
225 | + } while (ctype(c, C_BLANK)); | |
225 | 226 | if (c == '#') { |
226 | 227 | ignore_backslash_newline++; |
227 | - while (!ctype((c = getsc()), C_NUL | C_LF)) | |
228 | - ; | |
228 | + do { | |
229 | + c = getsc(); | |
230 | + } while (!ctype(c, C_NUL | C_LF)); | |
229 | 231 | ignore_backslash_newline--; |
230 | 232 | } |
231 | 233 | ungetsc(c); |
@@ -245,30 +247,32 @@ yylex(int cf) | ||
245 | 247 | while (!((c = getsc()) == 0 || |
246 | 248 | ((state == SBASE || state == SHEREDELIM) && ctype(c, C_LEX1)))) { |
247 | 249 | if (state == SBASE && |
248 | - subshell_nesting_type == ord(/*{*/ '}') && | |
249 | - c == ord(/*{*/ '}')) | |
250 | + subshell_nesting_type == ORD(/*{*/ '}') && | |
251 | + (unsigned int)c == ORD(/*{*/ '}')) | |
250 | 252 | /* possibly end ${ :;} */ |
251 | 253 | break; |
252 | 254 | Xcheck(ws, wp); |
253 | 255 | switch (state) { |
254 | 256 | case SADELIM: |
255 | - if (c == ord('(')) | |
257 | + if ((unsigned int)c == ORD('(')) | |
256 | 258 | statep->nparen++; |
257 | - else if (c == ord(')')) | |
259 | + else if ((unsigned int)c == ORD(')')) | |
258 | 260 | statep->nparen--; |
259 | - else if (statep->nparen == 0 && (c == ord(/*{*/ '}') || | |
261 | + else if (statep->nparen == 0 && | |
262 | + ((unsigned int)c == ORD(/*{*/ '}') || | |
260 | 263 | c == (int)statep->ls_adelim.delimiter)) { |
261 | 264 | *wp++ = ADELIM; |
262 | 265 | *wp++ = c; |
263 | - if (c == ord(/*{*/ '}') || --statep->ls_adelim.num == 0) | |
266 | + if ((unsigned int)c == ORD(/*{*/ '}') || | |
267 | + --statep->ls_adelim.num == 0) | |
264 | 268 | POP_STATE(); |
265 | - if (c == ord(/*{*/ '}')) | |
269 | + if ((unsigned int)c == ORD(/*{*/ '}')) | |
266 | 270 | POP_STATE(); |
267 | 271 | break; |
268 | 272 | } |
269 | 273 | /* FALLTHROUGH */ |
270 | 274 | case SBASE: |
271 | - if (c == ord('[') && (cf & CMDASN)) { | |
275 | + if ((unsigned int)c == ORD('[') && (cf & CMDASN)) { | |
272 | 276 | /* temporary */ |
273 | 277 | *wp = EOS; |
274 | 278 | if (is_wdvarname(Xstring(ws, wp), false)) { |
@@ -284,15 +288,6 @@ yylex(int cf) | ||
284 | 288 | } |
285 | 289 | afree(tmp, ATEMP); |
286 | 290 | break; |
287 | - } else { | |
288 | - Source *s; | |
289 | - | |
290 | - s = pushs(SREREAD, | |
291 | - source->areap); | |
292 | - s->start = s->str = | |
293 | - s->u.freeme = tmp; | |
294 | - s->next = source; | |
295 | - source = s; | |
296 | 291 | } |
297 | 292 | } |
298 | 293 | *wp++ = CHAR; |
@@ -303,7 +298,7 @@ yylex(int cf) | ||
303 | 298 | Sbase1: /* includes *(...|...) pattern (*+?@!) */ |
304 | 299 | if (ctype(c, C_PATMO)) { |
305 | 300 | c2 = getsc(); |
306 | - if (c2 == ord('(' /*)*/)) { | |
301 | + if ((unsigned int)c2 == ORD('(' /*)*/)) { | |
307 | 302 | *wp++ = OPAT; |
308 | 303 | *wp++ = c; |
309 | 304 | PUSH_STATE(SPATTERN); |
@@ -314,7 +309,7 @@ yylex(int cf) | ||
314 | 309 | /* FALLTHROUGH */ |
315 | 310 | Sbase2: /* doesn't include *(...|...) pattern (*+?@!) */ |
316 | 311 | switch (c) { |
317 | - case ord('\\'): | |
312 | + case ORD('\\'): | |
318 | 313 | getsc_qchar: |
319 | 314 | if ((c = getsc())) { |
320 | 315 | /* trailing \ is lost */ |
@@ -322,7 +317,7 @@ yylex(int cf) | ||
322 | 317 | *wp++ = c; |
323 | 318 | } |
324 | 319 | break; |
325 | - case ord('\''): | |
320 | + case ORD('\''): | |
326 | 321 | open_ssquote_unless_heredoc: |
327 | 322 | if ((cf & HEREDOC)) |
328 | 323 | goto store_char; |
@@ -330,12 +325,12 @@ yylex(int cf) | ||
330 | 325 | ignore_backslash_newline++; |
331 | 326 | PUSH_STATE(SSQUOTE); |
332 | 327 | break; |
333 | - case ord('"'): | |
328 | + case ORD('"'): | |
334 | 329 | open_sdquote: |
335 | 330 | *wp++ = OQUOTE; |
336 | 331 | PUSH_STATE(SDQUOTE); |
337 | 332 | break; |
338 | - case ord('$'): | |
333 | + case ORD('$'): | |
339 | 334 | /* |
340 | 335 | * processing of dollar sign belongs into |
341 | 336 | * Subst, except for those which can open |
@@ -344,9 +339,9 @@ yylex(int cf) | ||
344 | 339 | subst_dollar_ex: |
345 | 340 | c = getsc(); |
346 | 341 | switch (c) { |
347 | - case ord('"'): | |
342 | + case ORD('"'): | |
348 | 343 | goto open_sdquote; |
349 | - case ord('\''): | |
344 | + case ORD('\''): | |
350 | 345 | goto open_sequote; |
351 | 346 | default: |
352 | 347 | goto SubstS; |
@@ -358,16 +353,16 @@ yylex(int cf) | ||
358 | 353 | |
359 | 354 | Subst: |
360 | 355 | switch (c) { |
361 | - case ord('\\'): | |
356 | + case ORD('\\'): | |
362 | 357 | c = getsc(); |
363 | 358 | switch (c) { |
364 | - case ord('"'): | |
359 | + case ORD('"'): | |
365 | 360 | if ((cf & HEREDOC)) |
366 | 361 | goto heredocquote; |
367 | 362 | /* FALLTHROUGH */ |
368 | - case ord('\\'): | |
369 | - case ord('$'): | |
370 | - case ord('`'): | |
363 | + case ORD('\\'): | |
364 | + case ORD('$'): | |
365 | + case ORD('`'): | |
371 | 366 | store_qchar: |
372 | 367 | *wp++ = QCHAR; |
373 | 368 | *wp++ = c; |
@@ -385,12 +380,12 @@ yylex(int cf) | ||
385 | 380 | break; |
386 | 381 | } |
387 | 382 | break; |
388 | - case ord('$'): | |
383 | + case ORD('$'): | |
389 | 384 | c = getsc(); |
390 | 385 | SubstS: |
391 | - if (c == ord('(' /*)*/)) { | |
386 | + if ((unsigned int)c == ORD('(' /*)*/)) { | |
392 | 387 | c = getsc(); |
393 | - if (c == ord('(' /*)*/)) { | |
388 | + if ((unsigned int)c == ORD('(' /*)*/)) { | |
394 | 389 | *wp++ = EXPRSUB; |
395 | 390 | PUSH_SRETRACE(SASPAREN); |
396 | 391 | statep->nparen = 2; |
@@ -407,8 +402,8 @@ yylex(int cf) | ||
407 | 402 | memcpy(wp, sp, cz); |
408 | 403 | wp += cz; |
409 | 404 | } |
410 | - } else if (c == ord('{' /*}*/)) { | |
411 | - if ((c = getsc()) == ord('|')) { | |
405 | + } else if ((unsigned int)c == ORD('{' /*}*/)) { | |
406 | + if ((unsigned int)(c = getsc()) == ORD('|')) { | |
412 | 407 | /* |
413 | 408 | * non-subenvironment |
414 | 409 | * value substitution |
@@ -429,11 +424,11 @@ yylex(int cf) | ||
429 | 424 | wp = get_brace_var(&ws, wp); |
430 | 425 | c = getsc(); |
431 | 426 | /* allow :# and :% (ksh88 compat) */ |
432 | - if (c == ord(':')) { | |
427 | + if ((unsigned int)c == ORD(':')) { | |
433 | 428 | *wp++ = CHAR; |
434 | 429 | *wp++ = c; |
435 | 430 | c = getsc(); |
436 | - if (c == ord(':')) { | |
431 | + if ((unsigned int)c == ORD(':')) { | |
437 | 432 | *wp++ = CHAR; |
438 | 433 | *wp++ = '0'; |
439 | 434 | *wp++ = ADELIM; |
@@ -465,7 +460,7 @@ yylex(int cf) | ||
465 | 460 | parse_adelim_slash: |
466 | 461 | *wp++ = CHAR; |
467 | 462 | *wp++ = c; |
468 | - if ((c = getsc()) == ord('/')) { | |
463 | + if ((unsigned int)(c = getsc()) == ORD('/')) { | |
469 | 464 | *wp++ = c2; |
470 | 465 | *wp++ = c; |
471 | 466 | } else |
@@ -479,7 +474,7 @@ yylex(int cf) | ||
479 | 474 | } else if (c == '@') { |
480 | 475 | c2 = getsc(); |
481 | 476 | ungetsc(c2); |
482 | - if (c2 == ord('/')) { | |
477 | + if ((unsigned int)c2 == ORD('/')) { | |
483 | 478 | c2 = CHAR; |
484 | 479 | goto parse_adelim_slash; |
485 | 480 | } |
@@ -528,7 +523,7 @@ yylex(int cf) | ||
528 | 523 | ungetsc(c); |
529 | 524 | } |
530 | 525 | break; |
531 | - case ord('`'): | |
526 | + case ORD('`'): | |
532 | 527 | subst_gravis: |
533 | 528 | PUSH_STATE(SBQUOTE); |
534 | 529 | *wp++ = COMASUB; |
@@ -572,11 +567,11 @@ yylex(int cf) | ||
572 | 567 | break; |
573 | 568 | |
574 | 569 | case SEQUOTE: |
575 | - if (c == ord('\'')) { | |
570 | + if ((unsigned int)c == ORD('\'')) { | |
576 | 571 | POP_STATE(); |
577 | 572 | *wp++ = CQUOTE; |
578 | 573 | ignore_backslash_newline--; |
579 | - } else if (c == ord('\\')) { | |
574 | + } else if ((unsigned int)c == ORD('\\')) { | |
580 | 575 | if ((c2 = unbksl(true, getsc_i, ungetsc)) == -1) |
581 | 576 | c2 = getsc(); |
582 | 577 | if (c2 == 0) |
@@ -604,7 +599,7 @@ yylex(int cf) | ||
604 | 599 | break; |
605 | 600 | |
606 | 601 | case SSQUOTE: |
607 | - if (c == ord('\'')) { | |
602 | + if ((unsigned int)c == ORD('\'')) { | |
608 | 603 | POP_STATE(); |
609 | 604 | if ((cf & HEREDOC) || state == SQBRACE) |
610 | 605 | goto store_char; |
@@ -617,7 +612,7 @@ yylex(int cf) | ||
617 | 612 | break; |
618 | 613 | |
619 | 614 | case SDQUOTE: |
620 | - if (c == ord('"')) { | |
615 | + if ((unsigned int)c == ORD('"')) { | |
621 | 616 | POP_STATE(); |
622 | 617 | *wp++ = CQUOTE; |
623 | 618 | } else |
@@ -626,15 +621,15 @@ yylex(int cf) | ||
626 | 621 | |
627 | 622 | /* $(( ... )) */ |
628 | 623 | case SASPAREN: |
629 | - if (c == ord('(')) | |
624 | + if ((unsigned int)c == ORD('(')) | |
630 | 625 | statep->nparen++; |
631 | - else if (c == ord(')')) { | |
626 | + else if ((unsigned int)c == ORD(')')) { | |
632 | 627 | statep->nparen--; |
633 | 628 | if (statep->nparen == 1) { |
634 | 629 | /* end of EXPRSUB */ |
635 | 630 | POP_SRETRACE(); |
636 | 631 | |
637 | - if ((c2 = getsc()) == ord(/*(*/ ')')) { | |
632 | + if ((unsigned int)(c2 = getsc()) == ORD(/*(*/ ')')) { | |
638 | 633 | cz = strlen(sp) - 2; |
639 | 634 | XcheckN(ws, wp, cz); |
640 | 635 | memcpy(wp, sp + 1, cz); |
@@ -666,7 +661,7 @@ yylex(int cf) | ||
666 | 661 | goto Sbase2; |
667 | 662 | |
668 | 663 | case SQBRACE: |
669 | - if (c == ord('\\')) { | |
664 | + if ((unsigned int)c == ORD('\\')) { | |
670 | 665 | /* |
671 | 666 | * perform POSIX "quote removal" if the back- |
672 | 667 | * slash is "special", i.e. same cases as the |
@@ -675,26 +670,28 @@ yylex(int cf) | ||
675 | 670 | * write QCHAR+c, otherwise CHAR+\+CHAR+c are |
676 | 671 | * emitted (in heredocquote:) |
677 | 672 | */ |
678 | - if ((c = getsc()) == ord('"') || c == ord('\\') || | |
679 | - ctype(c, C_DOLAR | C_GRAVE) || c == ord(/*{*/ '}')) | |
673 | + if ((unsigned int)(c = getsc()) == ORD('"') || | |
674 | + (unsigned int)c == ORD('\\') || | |
675 | + ctype(c, C_DOLAR | C_GRAVE) || | |
676 | + (unsigned int)c == ORD(/*{*/ '}')) | |
680 | 677 | goto store_qchar; |
681 | 678 | goto heredocquote; |
682 | 679 | } |
683 | 680 | goto common_SQBRACE; |
684 | 681 | |
685 | 682 | case SBRACE: |
686 | - if (c == ord('\'')) | |
683 | + if ((unsigned int)c == ORD('\'')) | |
687 | 684 | goto open_ssquote_unless_heredoc; |
688 | - else if (c == ord('\\')) | |
685 | + else if ((unsigned int)c == ORD('\\')) | |
689 | 686 | goto getsc_qchar; |
690 | 687 | common_SQBRACE: |
691 | - if (c == ord('"')) | |
688 | + if ((unsigned int)c == ORD('"')) | |
692 | 689 | goto open_sdquote; |
693 | - else if (c == ord('$')) | |
690 | + else if ((unsigned int)c == ORD('$')) | |
694 | 691 | goto subst_dollar_ex; |
695 | - else if (c == ord('`')) | |
692 | + else if ((unsigned int)c == ORD('`')) | |
696 | 693 | goto subst_gravis; |
697 | - else if (c != ord(/*{*/ '}')) | |
694 | + else if ((unsigned int)c != ORD(/*{*/ '}')) | |
698 | 695 | goto store_char; |
699 | 696 | POP_STATE(); |
700 | 697 | *wp++ = CSUBST; |
@@ -703,16 +700,16 @@ yylex(int cf) | ||
703 | 700 | |
704 | 701 | /* Same as SBASE, except (,|,) treated specially */ |
705 | 702 | case STBRACEKORN: |
706 | - if (c == ord('|')) | |
703 | + if ((unsigned int)c == ORD('|')) | |
707 | 704 | *wp++ = SPAT; |
708 | - else if (c == ord('(')) { | |
705 | + else if ((unsigned int)c == ORD('(')) { | |
709 | 706 | *wp++ = OPAT; |
710 | 707 | /* simile for @ */ |
711 | 708 | *wp++ = ' '; |
712 | 709 | PUSH_STATE(SPATTERN); |
713 | 710 | } else /* FALLTHROUGH */ |
714 | 711 | case STBRACEBOURNE: |
715 | - if (c == ord(/*{*/ '}')) { | |
712 | + if ((unsigned int)c == ORD(/*{*/ '}')) { | |
716 | 713 | POP_STATE(); |
717 | 714 | *wp++ = CSUBST; |
718 | 715 | *wp++ = /*{*/ '}'; |
@@ -721,20 +718,20 @@ yylex(int cf) | ||
721 | 718 | break; |
722 | 719 | |
723 | 720 | case SBQUOTE: |
724 | - if (c == ord('`')) { | |
721 | + if ((unsigned int)c == ORD('`')) { | |
725 | 722 | *wp++ = 0; |
726 | 723 | POP_STATE(); |
727 | - } else if (c == ord('\\')) { | |
724 | + } else if ((unsigned int)c == ORD('\\')) { | |
728 | 725 | switch (c = getsc()) { |
729 | 726 | case 0: |
730 | 727 | /* trailing \ is lost */ |
731 | 728 | break; |
732 | - case ord('$'): | |
733 | - case ord('`'): | |
734 | - case ord('\\'): | |
729 | + case ORD('$'): | |
730 | + case ORD('`'): | |
731 | + case ORD('\\'): | |
735 | 732 | *wp++ = c; |
736 | 733 | break; |
737 | - case ord('"'): | |
734 | + case ORD('"'): | |
738 | 735 | if (statep->ls_bool) { |
739 | 736 | *wp++ = c; |
740 | 737 | break; |
@@ -755,10 +752,10 @@ yylex(int cf) | ||
755 | 752 | |
756 | 753 | /* LETEXPR: (( ... )) */ |
757 | 754 | case SLETPAREN: |
758 | - if (c == ord(/*(*/ ')')) { | |
755 | + if ((unsigned int)c == ORD(/*(*/ ')')) { | |
759 | 756 | if (statep->nparen > 0) |
760 | 757 | --statep->nparen; |
761 | - else if ((c2 = getsc()) == ord(/*(*/ ')')) { | |
758 | + else if ((unsigned int)(c2 = getsc()) == ORD(/*(*/ ')')) { | |
762 | 759 | c = 0; |
763 | 760 | *wp++ = CQUOTE; |
764 | 761 | goto Done; |
@@ -780,9 +777,9 @@ yylex(int cf) | ||
780 | 777 | s->next = source; |
781 | 778 | source = s; |
782 | 779 | ungetsc('(' /*)*/); |
783 | - return (ord('(' /*)*/)); | |
780 | + return (ORD('(' /*)*/)); | |
784 | 781 | } |
785 | - } else if (c == ord('(')) | |
782 | + } else if ((unsigned int)c == ORD('(')) | |
786 | 783 | /* |
787 | 784 | * parentheses inside quotes and |
788 | 785 | * backslashes are lost, but AT&T ksh |
@@ -798,26 +795,26 @@ yylex(int cf) | ||
798 | 795 | * $ and `...` are not to be treated specially |
799 | 796 | */ |
800 | 797 | switch (c) { |
801 | - case ord('\\'): | |
798 | + case ORD('\\'): | |
802 | 799 | if ((c = getsc())) { |
803 | 800 | /* trailing \ is lost */ |
804 | 801 | *wp++ = QCHAR; |
805 | 802 | *wp++ = c; |
806 | 803 | } |
807 | 804 | break; |
808 | - case ord('\''): | |
805 | + case ORD('\''): | |
809 | 806 | goto open_ssquote_unless_heredoc; |
810 | - case ord('$'): | |
811 | - if ((c2 = getsc()) == ord('\'')) { | |
807 | + case ORD('$'): | |
808 | + if ((unsigned int)(c2 = getsc()) == ORD('\'')) { | |
812 | 809 | open_sequote: |
813 | 810 | *wp++ = OQUOTE; |
814 | 811 | ignore_backslash_newline++; |
815 | 812 | PUSH_STATE(SEQUOTE); |
816 | 813 | statep->ls_bool = false; |
817 | 814 | break; |
818 | - } else if (c2 == ord('"')) { | |
815 | + } else if ((unsigned int)c2 == ORD('"')) { | |
819 | 816 | /* FALLTHROUGH */ |
820 | - case ord('"'): | |
817 | + case ORD('"'): | |
821 | 818 | PUSH_SRETRACE(SHEREDQUOTE); |
822 | 819 | break; |
823 | 820 | } |
@@ -831,7 +828,7 @@ yylex(int cf) | ||
831 | 828 | |
832 | 829 | /* " in << or <<- delimiter */ |
833 | 830 | case SHEREDQUOTE: |
834 | - if (c != ord('"')) | |
831 | + if ((unsigned int)c != ORD('"')) | |
835 | 832 | goto Subst; |
836 | 833 | POP_SRETRACE(); |
837 | 834 | dp = strnul(sp) - 1; |
@@ -844,10 +841,10 @@ yylex(int cf) | ||
844 | 841 | while ((c = *dp++)) { |
845 | 842 | if (c == '\\') { |
846 | 843 | switch ((c = *dp++)) { |
847 | - case ord('\\'): | |
848 | - case ord('"'): | |
849 | - case ord('$'): | |
850 | - case ord('`'): | |
844 | + case ORD('\\'): | |
845 | + case ORD('"'): | |
846 | + case ORD('$'): | |
847 | + case ORD('`'): | |
851 | 848 | break; |
852 | 849 | default: |
853 | 850 | *wp++ = CHAR; |
@@ -865,12 +862,12 @@ yylex(int cf) | ||
865 | 862 | |
866 | 863 | /* in *(...|...) pattern (*+?@!) */ |
867 | 864 | case SPATTERN: |
868 | - if (c == ord(/*(*/ ')')) { | |
865 | + if ((unsigned int)c == ORD(/*(*/ ')')) { | |
869 | 866 | *wp++ = CPAT; |
870 | 867 | POP_STATE(); |
871 | - } else if (c == ord('|')) { | |
868 | + } else if ((unsigned int)c == ORD('|')) { | |
872 | 869 | *wp++ = SPAT; |
873 | - } else if (c == ord('(')) { | |
870 | + } else if ((unsigned int)c == ORD('(')) { | |
874 | 871 | *wp++ = OPAT; |
875 | 872 | /* simile for @ */ |
876 | 873 | *wp++ = ' '; |
@@ -900,7 +897,7 @@ yylex(int cf) | ||
900 | 897 | iop->unit = c2 == 2 ? ksh_numdig(dp[1]) : c == '<' ? 0 : 1; |
901 | 898 | |
902 | 899 | if (c == '&') { |
903 | - if ((c2 = getsc()) != ord('>')) { | |
900 | + if ((unsigned int)(c2 = getsc()) != ORD('>')) { | |
904 | 901 | ungetsc(c2); |
905 | 902 | goto no_iop; |
906 | 903 | } |
@@ -911,22 +908,23 @@ yylex(int cf) | ||
911 | 908 | |
912 | 909 | c2 = getsc(); |
913 | 910 | /* <<, >>, <> are ok, >< is not */ |
914 | - if (c == c2 || (c == ord('<') && c2 == ord('>'))) { | |
911 | + if (c == c2 || ((unsigned int)c == ORD('<') && | |
912 | + (unsigned int)c2 == ORD('>'))) { | |
915 | 913 | iop->ioflag |= c == c2 ? |
916 | - (c == ord('>') ? IOCAT : IOHERE) : IORDWR; | |
914 | + ((unsigned int)c == ORD('>') ? IOCAT : IOHERE) : IORDWR; | |
917 | 915 | if (iop->ioflag == IOHERE) { |
918 | - if ((c2 = getsc()) == ord('-')) | |
916 | + if ((unsigned int)(c2 = getsc()) == ORD('-')) | |
919 | 917 | iop->ioflag |= IOSKIP; |
920 | - else if (c2 == ord('<')) | |
918 | + else if ((unsigned int)c2 == ORD('<')) | |
921 | 919 | iop->ioflag |= IOHERESTR; |
922 | 920 | else |
923 | 921 | ungetsc(c2); |
924 | 922 | } |
925 | - } else if (c2 == ord('&')) | |
926 | - iop->ioflag |= IODUP | (c == ord('<') ? IORDUP : 0); | |
923 | + } else if ((unsigned int)c2 == ORD('&')) | |
924 | + iop->ioflag |= IODUP | ((unsigned int)c == ORD('<') ? IORDUP : 0); | |
927 | 925 | else { |
928 | - iop->ioflag |= c == ord('>') ? IOWRITE : IOREAD; | |
929 | - if (c == ord('>') && c2 == ord('|')) | |
926 | + iop->ioflag |= (unsigned int)c == ORD('>') ? IOWRITE : IOREAD; | |
927 | + if ((unsigned int)c == ORD('>') && (unsigned int)c2 == ORD('|')) | |
930 | 928 | iop->ioflag |= IOCLOB; |
931 | 929 | else |
932 | 930 | ungetsc(c2); |
@@ -947,30 +945,32 @@ yylex(int cf) | ||
947 | 945 | /* free word */ |
948 | 946 | Xfree(ws, wp); |
949 | 947 | /* no word, process LEX1 character */ |
950 | - if ((c == ord('|')) || (c == ord('&')) || (c == ord(';')) || | |
951 | - (c == ord('(' /*)*/))) { | |
948 | + if (((unsigned int)c == ORD('|')) || | |
949 | + ((unsigned int)c == ORD('&')) || | |
950 | + ((unsigned int)c == ORD(';')) || | |
951 | + ((unsigned int)c == ORD('(' /*)*/))) { | |
952 | 952 | if ((c2 = getsc()) == c) |
953 | - c = (c == ord(';')) ? BREAK : | |
954 | - (c == ord('|')) ? LOGOR : | |
955 | - (c == ord('&')) ? LOGAND : | |
956 | - /* c == ord('(' )) */ MDPAREN; | |
957 | - else if (c == ord('|') && c2 == ord('&')) | |
953 | + c = ((unsigned int)c == ORD(';')) ? BREAK : | |
954 | + ((unsigned int)c == ORD('|')) ? LOGOR : | |
955 | + ((unsigned int)c == ORD('&')) ? LOGAND : | |
956 | + /* (unsigned int)c == ORD('(' )) */ MDPAREN; | |
957 | + else if ((unsigned int)c == ORD('|') && (unsigned int)c2 == ORD('&')) | |
958 | 958 | c = COPROC; |
959 | - else if (c == ord(';') && c2 == ord('|')) | |
959 | + else if ((unsigned int)c == ORD(';') && (unsigned int)c2 == ORD('|')) | |
960 | 960 | c = BRKEV; |
961 | - else if (c == ord(';') && c2 == ord('&')) | |
961 | + else if ((unsigned int)c == ORD(';') && (unsigned int)c2 == ORD('&')) | |
962 | 962 | c = BRKFT; |
963 | 963 | else |
964 | 964 | ungetsc(c2); |
965 | 965 | #ifndef MKSH_SMALL |
966 | 966 | if (c == BREAK) { |
967 | - if ((c2 = getsc()) == ord('&')) | |
967 | + if ((unsigned int)(c2 = getsc()) == ORD('&')) | |
968 | 968 | c = BRKEV; |
969 | 969 | else |
970 | 970 | ungetsc(c2); |
971 | 971 | } |
972 | 972 | #endif |
973 | - } else if (c == ord('\n')) { | |
973 | + } else if ((unsigned int)c == ORD('\n')) { | |
974 | 974 | if (cf & HEREDELIM) |
975 | 975 | ungetsc(c); |
976 | 976 | else { |
@@ -1025,7 +1025,7 @@ yylex(int cf) | ||
1025 | 1025 | |
1026 | 1026 | if ((cf & KEYWORD) && (p = ktsearch(&keywords, ident, h)) && |
1027 | 1027 | (!(cf & ESACONLY) || p->val.i == ESAC || |
1028 | - p->val.i == ord(/*{*/ '}'))) { | |
1028 | + (unsigned int)p->val.i == ORD(/*{*/ '}'))) { | |
1029 | 1029 | afree(yylval.cp, ATEMP); |
1030 | 1030 | return (p->val.i); |
1031 | 1031 | } |
@@ -1136,7 +1136,7 @@ readhere(struct ioword *iop) | ||
1136 | 1136 | if (!*eofp) { |
1137 | 1137 | /* end of here document marker, what to do? */ |
1138 | 1138 | switch (c) { |
1139 | - case ord(/*(*/ ')'): | |
1139 | + case ORD(/*(*/ ')'): | |
1140 | 1140 | if (!subshell_nesting_type) |
1141 | 1141 | /*- |
1142 | 1142 | * not allowed outside $(...) or (...) |
@@ -1151,7 +1151,7 @@ readhere(struct ioword *iop) | ||
1151 | 1151 | * Allow EOF here to commands without trailing |
1152 | 1152 | * newlines (mksh -c '...') will work as well. |
1153 | 1153 | */ |
1154 | - case ord('\n'): | |
1154 | + case ORD('\n'): | |
1155 | 1155 | /* Newline terminates here document marker */ |
1156 | 1156 | goto heredoc_found_terminator; |
1157 | 1157 | } |
@@ -1580,7 +1580,7 @@ get_brace_var(XString *wsp, char *wp) | ||
1580 | 1580 | |
1581 | 1581 | c2 = getsc(); |
1582 | 1582 | ungetsc(c2); |
1583 | - if (ord(c2) != ord(/*{*/ '}')) { | |
1583 | + if (ord(c2) != ORD(/*{*/ '}')) { | |
1584 | 1584 | ungetsc(c); |
1585 | 1585 | goto out; |
1586 | 1586 | } |
@@ -1588,22 +1588,22 @@ get_brace_var(XString *wsp, char *wp) | ||
1588 | 1588 | goto ps_common; |
1589 | 1589 | case PS_SAW_BANG: |
1590 | 1590 | switch (ord(c)) { |
1591 | - case ord('@'): | |
1592 | - case ord('#'): | |
1593 | - case ord('-'): | |
1594 | - case ord('?'): | |
1591 | + case ORD('@'): | |
1592 | + case ORD('#'): | |
1593 | + case ORD('-'): | |
1594 | + case ORD('?'): | |
1595 | 1595 | goto out; |
1596 | 1596 | } |
1597 | 1597 | goto ps_common; |
1598 | 1598 | case PS_INITIAL: |
1599 | 1599 | switch (ord(c)) { |
1600 | - case ord('%'): | |
1600 | + case ORD('%'): | |
1601 | 1601 | state = PS_SAW_PERCENT; |
1602 | 1602 | goto next; |
1603 | - case ord('#'): | |
1603 | + case ORD('#'): | |
1604 | 1604 | state = PS_SAW_HASH; |
1605 | 1605 | goto next; |
1606 | - case ord('!'): | |
1606 | + case ORD('!'): | |
1607 | 1607 | state = PS_SAW_BANG; |
1608 | 1608 | goto next; |
1609 | 1609 | } |
@@ -1621,7 +1621,7 @@ get_brace_var(XString *wsp, char *wp) | ||
1621 | 1621 | break; |
1622 | 1622 | case PS_IDENT: |
1623 | 1623 | if (!ctype(c, C_ALNUX)) { |
1624 | - if (ord(c) == ord('[')) { | |
1624 | + if (ord(c) == ORD('[')) { | |
1625 | 1625 | char *tmp, *p; |
1626 | 1626 | |
1627 | 1627 | if (!arraysub(&tmp)) |
@@ -1676,9 +1676,9 @@ arraysub(char **strp) | ||
1676 | 1676 | c = getsc(); |
1677 | 1677 | Xcheck(ws, wp); |
1678 | 1678 | *wp++ = c; |
1679 | - if (ord(c) == ord('[')) | |
1679 | + if (ord(c) == ORD('[')) | |
1680 | 1680 | depth++; |
1681 | - else if (ord(c) == ord(']')) | |
1681 | + else if (ord(c) == ORD(']')) | |
1682 | 1682 | depth--; |
1683 | 1683 | } while (depth > 0 && c && c != '\n'); |
1684 | 1684 |
@@ -5,7 +5,7 @@ | ||
5 | 5 | |
6 | 6 | /*- |
7 | 7 | * Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, |
8 | - * 2011, 2012, 2013, 2014, 2015, 2016, 2017 | |
8 | + * 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 | |
9 | 9 | * mirabilos <m@mirbsd.org> |
10 | 10 | * |
11 | 11 | * Provided that these terms and disclaimer and all copyright notices |
@@ -34,9 +34,7 @@ | ||
34 | 34 | #include <locale.h> |
35 | 35 | #endif |
36 | 36 | |
37 | -__RCSID("$MirOS: src/bin/mksh/main.c,v 1.342 2017/04/28 11:13:47 tg Exp $"); | |
38 | - | |
39 | -extern char **environ; | |
37 | +__RCSID("$MirOS: src/bin/mksh/main.c,v 1.347 2018/01/13 21:45:07 tg Exp $"); | |
40 | 38 | |
41 | 39 | #ifndef MKSHRC_PATH |
42 | 40 | #define MKSHRC_PATH "~/.mkshrc" |
@@ -52,6 +50,7 @@ void chvt_reinit(void); | ||
52 | 50 | static void reclaim(void); |
53 | 51 | static void remove_temps(struct temp *); |
54 | 52 | static mksh_uari_t rndsetup(void); |
53 | +static void init_environ(void); | |
55 | 54 | #ifdef SIGWINCH |
56 | 55 | static void x_sigwinch(int); |
57 | 56 | #endif |
@@ -242,10 +241,6 @@ main_init(int argc, const char *argv[], Source **sp, struct block **lp) | ||
242 | 241 | set_ifs(TC_IFSWS); |
243 | 242 | |
244 | 243 | #ifdef __OS2__ |
245 | - for (i = 0; i < 3; ++i) | |
246 | - if (!isatty(i)) | |
247 | - setmode(i, O_BINARY); | |
248 | - | |
249 | 244 | os2_init(&argc, &argv); |
250 | 245 | #endif |
251 | 246 |
@@ -401,14 +396,7 @@ main_init(int argc, const char *argv[], Source **sp, struct block **lp) | ||
401 | 396 | #endif |
402 | 397 | |
403 | 398 | /* import environment */ |
404 | - if (environ != NULL) { | |
405 | - wp = (const char **)environ; | |
406 | - while (*wp != NULL) { | |
407 | - rndpush(*wp); | |
408 | - typeset(*wp, IMPORT | EXPORT, 0, 0, 0); | |
409 | - ++wp; | |
410 | - } | |
411 | - } | |
399 | + init_environ(); | |
412 | 400 | |
413 | 401 | /* override default PATH regardless of environment */ |
414 | 402 | #ifdef MKSH_DEFPATH_OVERRIDE |
@@ -671,8 +659,7 @@ main_init(int argc, const char *argv[], Source **sp, struct block **lp) | ||
671 | 659 | if (Flag(FLOGIN)) |
672 | 660 | include(substitute("$HOME/.profile", 0), 0, NULL, true); |
673 | 661 | if (Flag(FTALKING)) { |
674 | - cp = substitute(substitute("${ENV:-" MKSHRC_PATH "}", | |
675 | - 0), DOTILDE); | |
662 | + cp = substitute("${ENV:-" MKSHRC_PATH "}", DOTILDE); | |
676 | 663 | if (cp[0] != '\0') |
677 | 664 | include(cp, 0, NULL, true); |
678 | 665 | } |
@@ -1987,3 +1974,111 @@ x_mkraw(int fd, mksh_ttyst *ocb, bool forread) | ||
1987 | 1974 | |
1988 | 1975 | mksh_tcset(fd, &cb); |
1989 | 1976 | } |
1977 | + | |
1978 | +#ifdef MKSH_ENVDIR | |
1979 | +static void | |
1980 | +init_environ(void) | |
1981 | +{ | |
1982 | + char *xp; | |
1983 | + ssize_t n; | |
1984 | + XString xs; | |
1985 | + struct shf *shf; | |
1986 | + DIR *dirp; | |
1987 | + struct dirent *dent; | |
1988 | + | |
1989 | + if ((dirp = opendir(MKSH_ENVDIR)) == NULL) { | |
1990 | + warningf(false, "cannot read environment from %s: %s", | |
1991 | + MKSH_ENVDIR, cstrerror(errno)); | |
1992 | + return; | |
1993 | + } | |
1994 | + XinitN(xs, 256, ATEMP); | |
1995 | + read_envfile: | |
1996 | + errno = 0; | |
1997 | + if ((dent = readdir(dirp)) != NULL) { | |
1998 | + if (skip_varname(dent->d_name, true)[0] == '\0') { | |
1999 | + xp = shf_smprintf(Tf_sSs, MKSH_ENVDIR, dent->d_name); | |
2000 | + if (!(shf = shf_open(xp, O_RDONLY, 0, 0))) { | |
2001 | + warningf(false, | |
2002 | + "cannot read environment %s from %s: %s", | |
2003 | + dent->d_name, MKSH_ENVDIR, | |
2004 | + cstrerror(errno)); | |
2005 | + goto read_envfile; | |
2006 | + } | |
2007 | + afree(xp, ATEMP); | |
2008 | + n = strlen(dent->d_name); | |
2009 | + xp = Xstring(xs, xp); | |
2010 | + XcheckN(xs, xp, n + 32); | |
2011 | + memcpy(xp, dent->d_name, n); | |
2012 | + xp += n; | |
2013 | + *xp++ = '='; | |
2014 | + while ((n = shf_read(xp, Xnleft(xs, xp), shf)) > 0) { | |
2015 | + xp += n; | |
2016 | + if (Xnleft(xs, xp) <= 0) | |
2017 | + XcheckN(xs, xp, Xlength(xs, xp)); | |
2018 | + } | |
2019 | + if (n < 0) { | |
2020 | + warningf(false, | |
2021 | + "cannot read environment %s from %s: %s", | |
2022 | + dent->d_name, MKSH_ENVDIR, | |
2023 | + cstrerror(shf_errno(shf))); | |
2024 | + } else { | |
2025 | + *xp = '\0'; | |
2026 | + xp = Xstring(xs, xp); | |
2027 | + rndpush(xp); | |
2028 | + typeset(xp, IMPORT | EXPORT, 0, 0, 0); | |
2029 | + } | |
2030 | + shf_close(shf); | |
2031 | + } | |
2032 | + goto read_envfile; | |
2033 | + } else if (errno) | |
2034 | + warningf(false, "cannot read environment from %s: %s", | |
2035 | + MKSH_ENVDIR, cstrerror(errno)); | |
2036 | + closedir(dirp); | |
2037 | + Xfree(xs, xp); | |
2038 | +} | |
2039 | +#else | |
2040 | +extern char **environ; | |
2041 | + | |
2042 | +static void | |
2043 | +init_environ(void) | |
2044 | +{ | |
2045 | + const char **wp; | |
2046 | + | |
2047 | + if (environ == NULL) | |
2048 | + return; | |
2049 | + | |
2050 | + wp = (const char **)environ; | |
2051 | + while (*wp != NULL) { | |
2052 | + rndpush(*wp); | |
2053 | + typeset(*wp, IMPORT | EXPORT, 0, 0, 0); | |
2054 | + ++wp; | |
2055 | + } | |
2056 | +} | |
2057 | +#endif | |
2058 | + | |
2059 | +#ifdef MKSH_EARLY_LOCALE_TRACKING | |
2060 | +void | |
2061 | +recheck_ctype(void) | |
2062 | +{ | |
2063 | + const char *ccp; | |
2064 | + | |
2065 | + ccp = str_val(global("LC_ALL")); | |
2066 | + if (ccp == null) | |
2067 | + ccp = str_val(global("LC_CTYPE")); | |
2068 | + if (ccp == null) | |
2069 | + ccp = str_val(global("LANG")); | |
2070 | + UTFMODE = isuc(ccp); | |
2071 | +#if HAVE_SETLOCALE_CTYPE | |
2072 | + ccp = setlocale(LC_CTYPE, ccp); | |
2073 | +#if HAVE_LANGINFO_CODESET | |
2074 | + if (!isuc(ccp)) | |
2075 | + ccp = nl_langinfo(CODESET); | |
2076 | +#endif | |
2077 | + if (isuc(ccp)) | |
2078 | + UTFMODE = 1; | |
2079 | +#endif | |
2080 | + | |
2081 | + if (Flag(FPOSIX)) | |
2082 | + warningf(true, "early locale tracking enabled UTF-8 mode while in POSIX mode, you are now noncompliant"); | |
2083 | +} | |
2084 | +#endif |
@@ -32,7 +32,7 @@ | ||
32 | 32 | #include <grp.h> |
33 | 33 | #endif |
34 | 34 | |
35 | -__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.279 2017/08/07 21:39:25 tg Exp $"); | |
35 | +__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.291 2018/01/14 00:03:03 tg Exp $"); | |
36 | 36 | |
37 | 37 | #define KSH_CHVT_FLAG |
38 | 38 | #ifdef MKSH_SMALL |
@@ -696,14 +696,14 @@ has_globbing(const char *pat) | ||
696 | 696 | if (!(c = *p++)) |
697 | 697 | return (false); |
698 | 698 | /* some specials */ |
699 | - if (ord(c) == ord('*') || ord(c) == ord('?')) { | |
699 | + if (ord(c) == ORD('*') || ord(c) == ORD('?')) { | |
700 | 700 | /* easy glob, accept */ |
701 | 701 | saw_glob = true; |
702 | - } else if (ord(c) == ord('[')) { | |
702 | + } else if (ord(c) == ORD('[')) { | |
703 | 703 | /* bracket expression; eat negation and initial ] */ |
704 | - if (ISMAGIC(p[0]) && ord(p[1]) == ord('!')) | |
704 | + if (ISMAGIC(p[0]) && ord(p[1]) == ORD('!')) | |
705 | 705 | p += 2; |
706 | - if (ISMAGIC(p[0]) && ord(p[1]) == ord(']')) | |
706 | + if (ISMAGIC(p[0]) && ord(p[1]) == ORD(']')) | |
707 | 707 | p += 2; |
708 | 708 | /* check next string part */ |
709 | 709 | s = p; |
@@ -715,27 +715,27 @@ has_globbing(const char *pat) | ||
715 | 715 | if (!(c = *s++)) |
716 | 716 | return (false); |
717 | 717 | /* terminating bracket? */ |
718 | - if (ord(c) == ord(']')) { | |
718 | + if (ord(c) == ORD(']')) { | |
719 | 719 | /* accept and continue */ |
720 | 720 | p = s; |
721 | 721 | saw_glob = true; |
722 | 722 | break; |
723 | 723 | } |
724 | 724 | /* sub-bracket expressions */ |
725 | - if (ord(c) == ord('[') && ( | |
725 | + if (ord(c) == ORD('[') && ( | |
726 | 726 | /* collating element? */ |
727 | - ord(*s) == ord('.') || | |
727 | + ord(*s) == ORD('.') || | |
728 | 728 | /* equivalence class? */ |
729 | - ord(*s) == ord('=') || | |
729 | + ord(*s) == ORD('=') || | |
730 | 730 | /* character class? */ |
731 | - ord(*s) == ord(':'))) { | |
731 | + ord(*s) == ORD(':'))) { | |
732 | 732 | /* must stop with exactly the same c */ |
733 | 733 | subc = *s++; |
734 | 734 | /* arbitrarily many chars in betwixt */ |
735 | 735 | while ((c = *s++)) |
736 | 736 | /* but only this sequence... */ |
737 | 737 | if (c == subc && ISMAGIC(*s) && |
738 | - ord(s[1]) == ord(']')) { | |
738 | + ord(s[1]) == ORD(']')) { | |
739 | 739 | /* accept, terminate */ |
740 | 740 | s += 2; |
741 | 741 | break; |
@@ -751,7 +751,7 @@ has_globbing(const char *pat) | ||
751 | 751 | /* opening pattern */ |
752 | 752 | saw_glob = true; |
753 | 753 | ++nest; |
754 | - } else if (ord(c) == ord(/*(*/ ')')) { | |
754 | + } else if (ord(c) == ORD(/*(*/ ')')) { | |
755 | 755 | /* closing pattern */ |
756 | 756 | if (nest) |
757 | 757 | --nest; |
@@ -785,24 +785,24 @@ do_gmatch(const unsigned char *s, const unsigned char *se, | ||
785 | 785 | continue; |
786 | 786 | } |
787 | 787 | switch (ord(*p++)) { |
788 | - case ord('['): | |
788 | + case ORD('['): | |
789 | 789 | /* BSD cclass extension? */ |
790 | - if (ISMAGIC(p[0]) && ord(p[1]) == ord('[') && | |
791 | - ord(p[2]) == ord(':') && | |
790 | + if (ISMAGIC(p[0]) && ord(p[1]) == ORD('[') && | |
791 | + ord(p[2]) == ORD(':') && | |
792 | 792 | ctype((pc = p[3]), C_ANGLE) && |
793 | - ord(p[4]) == ord(':') && | |
794 | - ISMAGIC(p[5]) && ord(p[6]) == ord(']') && | |
795 | - ISMAGIC(p[7]) && ord(p[8]) == ord(']')) { | |
793 | + ord(p[4]) == ORD(':') && | |
794 | + ISMAGIC(p[5]) && ord(p[6]) == ORD(']') && | |
795 | + ISMAGIC(p[7]) && ord(p[8]) == ORD(']')) { | |
796 | 796 | /* zero-length match */ |
797 | 797 | --s; |
798 | 798 | p += 9; |
799 | 799 | /* word begin? */ |
800 | - if (ord(pc) == ord('<') && | |
800 | + if (ord(pc) == ORD('<') && | |
801 | 801 | !ctype(sl, C_ALNUX) && |
802 | 802 | ctype(sc, C_ALNUX)) |
803 | 803 | break; |
804 | 804 | /* word end? */ |
805 | - if (ord(pc) == ord('>') && | |
805 | + if (ord(pc) == ORD('>') && | |
806 | 806 | ctype(sl, C_ALNUX) && |
807 | 807 | !ctype(sc, C_ALNUX)) |
808 | 808 | break; |
@@ -813,7 +813,7 @@ do_gmatch(const unsigned char *s, const unsigned char *se, | ||
813 | 813 | return (0); |
814 | 814 | break; |
815 | 815 | |
816 | - case ord('?'): | |
816 | + case ORD('?'): | |
817 | 817 | if (sc == 0) |
818 | 818 | return (0); |
819 | 819 | if (UTFMODE) { |
@@ -822,7 +822,7 @@ do_gmatch(const unsigned char *s, const unsigned char *se, | ||
822 | 822 | } |
823 | 823 | break; |
824 | 824 | |
825 | - case ord('*'): | |
825 | + case ORD('*'): | |
826 | 826 | if (p == pe) |
827 | 827 | return (1); |
828 | 828 | s--; |
@@ -838,14 +838,14 @@ do_gmatch(const unsigned char *s, const unsigned char *se, | ||
838 | 838 | */ |
839 | 839 | |
840 | 840 | /* matches one or more times */ |
841 | - case 0x80|ord('+'): | |
841 | + case ORD('+') | 0x80: | |
842 | 842 | /* matches zero or more times */ |
843 | - case 0x80|ord('*'): | |
843 | + case ORD('*') | 0x80: | |
844 | 844 | if (!(prest = pat_scan(p, pe, false))) |
845 | 845 | return (0); |
846 | 846 | s--; |
847 | 847 | /* take care of zero matches */ |
848 | - if (ord(p[-1]) == (0x80 | ord('*')) && | |
848 | + if (ord(p[-1]) == (0x80 | ORD('*')) && | |
849 | 849 | do_gmatch(s, se, prest, pe, smin)) |
850 | 850 | return (1); |
851 | 851 | for (psub = p; ; psub = pnext) { |
@@ -863,16 +863,16 @@ do_gmatch(const unsigned char *s, const unsigned char *se, | ||
863 | 863 | return (0); |
864 | 864 | |
865 | 865 | /* matches zero or once */ |
866 | - case 0x80|ord('?'): | |
866 | + case ORD('?') | 0x80: | |
867 | 867 | /* matches one of the patterns */ |
868 | - case 0x80|ord('@'): | |
868 | + case ORD('@') | 0x80: | |
869 | 869 | /* simile for @ */ |
870 | - case 0x80|ord(' '): | |
870 | + case ORD(' ') | 0x80: | |
871 | 871 | if (!(prest = pat_scan(p, pe, false))) |
872 | 872 | return (0); |
873 | 873 | s--; |
874 | 874 | /* Take care of zero matches */ |
875 | - if (ord(p[-1]) == (0x80 | ord('?')) && | |
875 | + if (ord(p[-1]) == (0x80 | ORD('?')) && | |
876 | 876 | do_gmatch(s, se, prest, pe, smin)) |
877 | 877 | return (1); |
878 | 878 | for (psub = p; ; psub = pnext) { |
@@ -889,7 +889,7 @@ do_gmatch(const unsigned char *s, const unsigned char *se, | ||
889 | 889 | return (0); |
890 | 890 | |
891 | 891 | /* matches none of the patterns */ |
892 | - case 0x80|ord('!'): | |
892 | + case ORD('!') | 0x80: | |
893 | 893 | if (!(prest = pat_scan(p, pe, false))) |
894 | 894 | return (0); |
895 | 895 | s--; |
@@ -966,12 +966,12 @@ gmatch_cclass(const unsigned char *pat, unsigned char sc) | ||
966 | 966 | char *subp; |
967 | 967 | |
968 | 968 | /* check for negation */ |
969 | - if (ISMAGIC(p[0]) && ord(p[1]) == ord('!')) { | |
969 | + if (ISMAGIC(p[0]) && ord(p[1]) == ORD('!')) { | |
970 | 970 | p += 2; |
971 | 971 | negated = true; |
972 | 972 | } |
973 | 973 | /* make initial ] non-MAGIC */ |
974 | - if (ISMAGIC(p[0]) && ord(p[1]) == ord(']')) | |
974 | + if (ISMAGIC(p[0]) && ord(p[1]) == ORD(']')) | |
975 | 975 | ++p; |
976 | 976 | /* iterate over bracket expression, debunk()ing on the fly */ |
977 | 977 | while ((c = *p++)) { |
@@ -982,18 +982,18 @@ gmatch_cclass(const unsigned char *pat, unsigned char sc) | ||
982 | 982 | if (!(c = *p++)) |
983 | 983 | break; |
984 | 984 | /* terminating bracket? */ |
985 | - if (ord(c) == ord(']')) { | |
985 | + if (ord(c) == ORD(']')) { | |
986 | 986 | /* accept and return */ |
987 | 987 | return (found != negated ? p : NULL); |
988 | 988 | } |
989 | 989 | /* sub-bracket expressions */ |
990 | - if (ord(c) == ord('[') && ( | |
990 | + if (ord(c) == ORD('[') && ( | |
991 | 991 | /* collating element? */ |
992 | - ord(*p) == ord('.') || | |
992 | + ord(*p) == ORD('.') || | |
993 | 993 | /* equivalence class? */ |
994 | - ord(*p) == ord('=') || | |
994 | + ord(*p) == ORD('=') || | |
995 | 995 | /* character class? */ |
996 | - ord(*p) == ord(':'))) { | |
996 | + ord(*p) == ORD(':'))) { | |
997 | 997 | /* must stop with exactly the same c */ |
998 | 998 | subc = *p++; |
999 | 999 | /* save away start of substring */ |
@@ -1002,7 +1002,7 @@ gmatch_cclass(const unsigned char *pat, unsigned char sc) | ||
1002 | 1002 | while ((c = *p++)) |
1003 | 1003 | /* but only this sequence... */ |
1004 | 1004 | if (c == subc && ISMAGIC(*p) && |
1005 | - ord(p[1]) == ord(']')) { | |
1005 | + ord(p[1]) == ORD(']')) { | |
1006 | 1006 | /* accept, terminate */ |
1007 | 1007 | p += 2; |
1008 | 1008 | break; |
@@ -1015,7 +1015,7 @@ gmatch_cclass(const unsigned char *pat, unsigned char sc) | ||
1015 | 1015 | debunk(subp, subp, p - s - 3 + 1); |
1016 | 1016 | cclass_common: |
1017 | 1017 | /* whither subexpression */ |
1018 | - if (ord(subc) == ord(':')) { | |
1018 | + if (ord(subc) == ORD(':')) { | |
1019 | 1019 | const struct cclass *cls = cclasses; |
1020 | 1020 | |
1021 | 1021 | /* search for name in cclass list */ |
@@ -1055,9 +1055,9 @@ gmatch_cclass(const unsigned char *pat, unsigned char sc) | ||
1055 | 1055 | } |
1056 | 1056 | } |
1057 | 1057 | /* range expression? */ |
1058 | - if (!(ISMAGIC(p[0]) && ord(p[1]) == ord('-') && | |
1058 | + if (!(ISMAGIC(p[0]) && ord(p[1]) == ORD('-') && | |
1059 | 1059 | /* not terminating bracket? */ |
1060 | - (!ISMAGIC(p[2]) || ord(p[3]) != ord(']')))) { | |
1060 | + (!ISMAGIC(p[2]) || ord(p[3]) != ORD(']')))) { | |
1061 | 1061 | /* no, check single match */ |
1062 | 1062 | if (sc == c) |
1063 | 1063 | /* note: sc is never NUL */ |
@@ -1079,13 +1079,13 @@ gmatch_cclass(const unsigned char *pat, unsigned char sc) | ||
1079 | 1079 | if (!(c = *p++)) |
1080 | 1080 | break; |
1081 | 1081 | /* sub-bracket expressions */ |
1082 | - if (ord(c) == ord('[') && ( | |
1082 | + if (ord(c) == ORD('[') && ( | |
1083 | 1083 | /* collating element? */ |
1084 | - ord(*p) == ord('.') || | |
1084 | + ord(*p) == ORD('.') || | |
1085 | 1085 | /* equivalence class? */ |
1086 | - ord(*p) == ord('=') || | |
1086 | + ord(*p) == ORD('=') || | |
1087 | 1087 | /* character class? */ |
1088 | - ord(*p) == ord(':'))) { | |
1088 | + ord(*p) == ORD(':'))) { | |
1089 | 1089 | /* must stop with exactly the same c */ |
1090 | 1090 | subc = *p++; |
1091 | 1091 | /* save away start of substring */ |
@@ -1094,7 +1094,7 @@ gmatch_cclass(const unsigned char *pat, unsigned char sc) | ||
1094 | 1094 | while ((c = *p++)) |
1095 | 1095 | /* but only this sequence... */ |
1096 | 1096 | if (c == subc && ISMAGIC(*p) && |
1097 | - ord(p[1]) == ord(']')) { | |
1097 | + ord(p[1]) == ORD(']')) { | |
1098 | 1098 | /* accept, terminate */ |
1099 | 1099 | p += 2; |
1100 | 1100 | break; |
@@ -1106,14 +1106,14 @@ gmatch_cclass(const unsigned char *pat, unsigned char sc) | ||
1106 | 1106 | strndupx(subp, s, p - s - 3, ATEMP); |
1107 | 1107 | debunk(subp, subp, p - s - 3 + 1); |
1108 | 1108 | /* whither subexpression */ |
1109 | - if (ord(subc) == ord(':')) { | |
1109 | + if (ord(subc) == ORD(':')) { | |
1110 | 1110 | /* oops, not a range */ |
1111 | 1111 | |
1112 | 1112 | /* match single previous char */ |
1113 | 1113 | if (lc && (sc == lc)) |
1114 | 1114 | found = true; |
1115 | 1115 | /* match hyphen-minus */ |
1116 | - if (ord(sc) == ord('-')) | |
1116 | + if (ord(sc) == ORD('-')) | |
1117 | 1117 | found = true; |
1118 | 1118 | /* handle cclass common part */ |
1119 | 1119 | goto cclass_common; |
@@ -1151,7 +1151,7 @@ gmatch_cclass(const unsigned char *pat, unsigned char sc) | ||
1151 | 1151 | /* otherwise, just go on with the pattern string */ |
1152 | 1152 | } |
1153 | 1153 | /* if we broke here, the bracket expression was invalid */ |
1154 | - if (ord(sc) == ord('[')) | |
1154 | + if (ord(sc) == ORD('[')) | |
1155 | 1155 | /* initial opening bracket as literal match */ |
1156 | 1156 | return (pat); |
1157 | 1157 | /* or rather no match */ |
@@ -1661,6 +1661,15 @@ do_realpath(const char *upath) | ||
1661 | 1661 | if (mksh_abspath(upath)) { |
1662 | 1662 | /* upath is an absolute pathname */ |
1663 | 1663 | strdupx(ipath, upath, ATEMP); |
1664 | +#ifdef MKSH_DOSPATH | |
1665 | + } else if (mksh_drvltr(upath)) { | |
1666 | + /* upath is a drive-relative pathname */ | |
1667 | + if (getdrvwd(&ldest, ord(*upath))) | |
1668 | + return (NULL); | |
1669 | + /* A:foo -> A:/cwd/foo; A: -> A:/cwd */ | |
1670 | + ipath = shf_smprintf(Tf_sss, ldest, | |
1671 | + upath[2] ? "/" : "", upath + 2); | |
1672 | +#endif | |
1664 | 1673 | } else { |
1665 | 1674 | /* upath is a relative pathname, prepend cwd */ |
1666 | 1675 | if ((tp = ksh_get_wd()) == NULL || !mksh_abspath(tp)) |
@@ -1695,6 +1704,7 @@ do_realpath(const char *upath) | ||
1695 | 1704 | continue; |
1696 | 1705 | else if (len == 2 && tp[1] == '.') { |
1697 | 1706 | /* strip off last pathname component */ |
1707 | + /*XXX consider a rooted pathname */ | |
1698 | 1708 | while (xp > Xstring(xs, xp)) |
1699 | 1709 | if (mksh_cdirsep(*--xp)) |
1700 | 1710 | break; |
@@ -1762,11 +1772,23 @@ do_realpath(const char *upath) | ||
1762 | 1772 | * restart if symlink target is an absolute path, |
1763 | 1773 | * otherwise continue with currently resolved prefix |
1764 | 1774 | */ |
1775 | +#ifdef MKSH_DOSPATH | |
1776 | + assemble_symlink: | |
1777 | +#endif | |
1765 | 1778 | /* append rest of current input path to link target */ |
1766 | 1779 | tp = shf_smprintf(Tf_sss, ldest, *ip ? "/" : "", ip); |
1767 | 1780 | afree(ipath, ATEMP); |
1768 | 1781 | ip = ipath = tp; |
1769 | - if (!mksh_abspath(ldest)) { | |
1782 | + if (!mksh_abspath(ipath)) { | |
1783 | +#ifdef MKSH_DOSPATH | |
1784 | + /* symlink target might be drive-relative */ | |
1785 | + if (mksh_drvltr(ipath)) { | |
1786 | + if (getdrvwd(&ldest, ord(*ipath))) | |
1787 | + goto notfound; | |
1788 | + ip += 2; | |
1789 | + goto assemble_symlink; | |
1790 | + } | |
1791 | +#endif | |
1770 | 1792 | /* symlink target is a relative path */ |
1771 | 1793 | xp = Xrestpos(xs, xp, pos); |
1772 | 1794 | } else |
@@ -1775,7 +1797,7 @@ do_realpath(const char *upath) | ||
1775 | 1797 | /* symlink target is an absolute path */ |
1776 | 1798 | xp = Xstring(xs, xp); |
1777 | 1799 | beginning_of_a_pathname: |
1778 | - /* assert: mksh_cdirsep((ip == ipath)[0]) */ | |
1800 | + /* assert: mksh_abspath(ip == ipath) */ | |
1779 | 1801 | /* assert: xp == xs.beg => start of path */ |
1780 | 1802 | |
1781 | 1803 | /* exactly two leading slashes? (SUSv4 3.266) */ |
@@ -1783,6 +1805,14 @@ do_realpath(const char *upath) | ||
1783 | 1805 | /* keep them, e.g. for UNC pathnames */ |
1784 | 1806 | Xput(xs, xp, '/'); |
1785 | 1807 | } |
1808 | +#ifdef MKSH_DOSPATH | |
1809 | + /* drive letter? */ | |
1810 | + if (mksh_drvltr(ip)) { | |
1811 | + /* keep it */ | |
1812 | + Xput(xs, xp, *ip++); | |
1813 | + Xput(xs, xp, *ip++); | |
1814 | + } | |
1815 | +#endif | |
1786 | 1816 | } |
1787 | 1817 | } |
1788 | 1818 | /* otherwise (no symlink) merely go on */ |
@@ -1932,6 +1962,15 @@ make_path(const char *cwd, const char *file, | ||
1932 | 1962 | * .. .. |
1933 | 1963 | * ./foo foo |
1934 | 1964 | * foo/../../../bar ../../bar |
1965 | + * C:/foo/../.. C:/ | |
1966 | + * C:. C: | |
1967 | + * C:.. C:.. | |
1968 | + * C:foo/../../blah C:../blah | |
1969 | + * | |
1970 | + * XXX consider a rooted pathname: we cannot really 'cd ..' for | |
1971 | + * pathnames like: '/', 'c:/', '//foo', '//foo/', '/@unixroot/' | |
1972 | + * (no effect), 'c:', 'c:.' (effect is retaining the '../') but | |
1973 | + * we need to honour this throughout the shell | |
1935 | 1974 | */ |
1936 | 1975 | void |
1937 | 1976 | simplify_path(char *p) |
@@ -1939,6 +1978,17 @@ simplify_path(char *p) | ||
1939 | 1978 | char *dp, *ip, *sp, *tp; |
1940 | 1979 | size_t len; |
1941 | 1980 | bool needslash; |
1981 | +#ifdef MKSH_DOSPATH | |
1982 | + bool needdot = true; | |
1983 | + | |
1984 | + /* keep drive letter */ | |
1985 | + if (mksh_drvltr(p)) { | |
1986 | + p += 2; | |
1987 | + needdot = false; | |
1988 | + } | |
1989 | +#else | |
1990 | +#define needdot true | |
1991 | +#endif | |
1942 | 1992 | |
1943 | 1993 | switch (*p) { |
1944 | 1994 | case 0: |
@@ -1977,7 +2027,7 @@ simplify_path(char *p) | ||
1977 | 2027 | /* just continue with the next one */ |
1978 | 2028 | continue; |
1979 | 2029 | else if (len == 2 && tp[1] == '.') { |
1980 | - /* parent level, but how? */ | |
2030 | + /* parent level, but how? (see above) */ | |
1981 | 2031 | if (mksh_abspath(p)) |
1982 | 2032 | /* absolute path, only one way */ |
1983 | 2033 | goto strip_last_component; |
@@ -2016,10 +2066,15 @@ simplify_path(char *p) | ||
2016 | 2066 | needslash = true; |
2017 | 2067 | /* try next component */ |
2018 | 2068 | } |
2019 | - if (dp == p) | |
2020 | - /* empty path -> dot */ | |
2021 | - *dp++ = needslash ? '/' : '.'; | |
2069 | + if (dp == p) { | |
2070 | + /* empty path -> dot (or slash, when absolute) */ | |
2071 | + if (needslash) | |
2072 | + *dp++ = '/'; | |
2073 | + else if (needdot) | |
2074 | + *dp++ = '.'; | |
2075 | + } | |
2022 | 2076 | *dp = '\0'; |
2077 | +#undef needdot | |
2023 | 2078 | } |
2024 | 2079 | |
2025 | 2080 | void |
@@ -2133,6 +2188,18 @@ c_cd(const char **wp) | ||
2133 | 2188 | return (2); |
2134 | 2189 | } |
2135 | 2190 | |
2191 | +#ifdef MKSH_DOSPATH | |
2192 | + tryp = NULL; | |
2193 | + if (mksh_drvltr(dir) && !mksh_cdirsep(dir[2]) && | |
2194 | + !getdrvwd(&tryp, ord(*dir))) { | |
2195 | + dir = shf_smprintf(Tf_sss, tryp, | |
2196 | + dir[2] ? "/" : "", dir + 2); | |
2197 | + afree(tryp, ATEMP); | |
2198 | + afree(allocd, ATEMP); | |
2199 | + allocd = dir; | |
2200 | + } | |
2201 | +#endif | |
2202 | + | |
2136 | 2203 | #ifdef MKSH__NO_PATH_MAX |
2137 | 2204 | /* only a first guess; make_path will enlarge xs if necessary */ |
2138 | 2205 | XinitN(xs, 1024, ATEMP); |
@@ -1,5 +1,5 @@ | ||
1 | 1 | /*- |
2 | - * Copyright (c) 2015 | |
2 | + * Copyright (c) 2015, 2017 | |
3 | 3 | * KO Myung-Hun <komh@chollian.net> |
4 | 4 | * Copyright (c) 2017 |
5 | 5 | * mirabilos <m@mirbsd.org> |
@@ -26,18 +26,18 @@ | ||
26 | 26 | #include "sh.h" |
27 | 27 | |
28 | 28 | #include <klibc/startup.h> |
29 | +#include <errno.h> | |
29 | 30 | #include <io.h> |
30 | 31 | #include <unistd.h> |
31 | 32 | #include <process.h> |
32 | 33 | |
33 | -__RCSID("$MirOS: src/bin/mksh/os2.c,v 1.2 2017/04/29 22:04:29 tg Exp $"); | |
34 | +__RCSID("$MirOS: src/bin/mksh/os2.c,v 1.8 2017/12/22 16:41:42 tg Exp $"); | |
34 | 35 | |
35 | 36 | static char *remove_trailing_dots(char *); |
36 | 37 | static int access_stat_ex(int (*)(), const char *, void *); |
37 | 38 | static int test_exec_exist(const char *, char *); |
38 | 39 | static void response(int *, const char ***); |
39 | 40 | static char *make_response_file(char * const *); |
40 | -static void env_slashify(void); | |
41 | 41 | static void add_temp(const char *); |
42 | 42 | static void cleanup_temps(void); |
43 | 43 | static void cleanup(void); |
@@ -169,44 +169,12 @@ init_extlibpath(void) | ||
169 | 169 | } |
170 | 170 | } |
171 | 171 | |
172 | -/* | |
173 | - * Convert backslashes of environmental variables to forward slahes. | |
174 | - * A backslash may be used as an escaped character when doing 'echo'. | |
175 | - * This leads to an unexpected behavior. | |
176 | - */ | |
177 | -static void | |
178 | -env_slashify(void) | |
179 | -{ | |
180 | - /* | |
181 | - * PATH and TMPDIR are used by OS/2 as well. That is, they may | |
182 | - * have backslashes as a directory separator. | |
183 | - * BEGINLIBPATH and ENDLIBPATH are special variables on OS/2. | |
184 | - */ | |
185 | - const char *var_list[] = { | |
186 | - "PATH", | |
187 | - "TMPDIR", | |
188 | - "BEGINLIBPATH", | |
189 | - "ENDLIBPATH", | |
190 | - NULL | |
191 | - }; | |
192 | - const char **var; | |
193 | - char *value; | |
194 | - | |
195 | - for (var = var_list; *var; var++) { | |
196 | - value = getenv(*var); | |
197 | - | |
198 | - if (value) | |
199 | - _fnslashify(value); | |
200 | - } | |
201 | -} | |
202 | - | |
203 | 172 | void |
204 | 173 | os2_init(int *argcp, const char ***argvp) |
205 | 174 | { |
206 | 175 | response(argcp, argvp); |
207 | 176 | |
208 | 177 | init_extlibpath(); |
209 | - env_slashify(); | |
210 | 178 | |
211 | 179 | if (!isatty(STDIN_FILENO)) |
212 | 180 | setmode(STDIN_FILENO, O_BINARY); |
@@ -361,49 +329,30 @@ real_exec_name(const char *name) | ||
361 | 329 | return (real_name); |
362 | 330 | } |
363 | 331 | |
364 | -/* OS/2 can process a command line up to 32 KiB */ | |
365 | -#define MAX_CMD_LINE_LEN 32768 | |
366 | - | |
367 | 332 | /* make a response file to pass a very long command line */ |
368 | 333 | static char * |
369 | 334 | make_response_file(char * const *argv) |
370 | 335 | { |
371 | 336 | char rsp_name_arg[] = "@mksh-rsp-XXXXXX"; |
372 | 337 | char *rsp_name = &rsp_name_arg[1]; |
373 | - int arg_len = 0; | |
374 | 338 | int i; |
339 | + int fd; | |
340 | + char *result; | |
375 | 341 | |
376 | - for (i = 0; argv[i]; i++) | |
377 | - arg_len += strlen(argv[i]) + 1; | |
378 | - | |
379 | - /* | |
380 | - * If a length of command line is longer than MAX_CMD_LINE_LEN, then | |
381 | - * use a response file. OS/2 cannot process a command line longer | |
382 | - * than 32K. Of course, a response file cannot be recognised by a | |
383 | - * normal OS/2 program, that is, neither non-EMX or non-kLIBC. But | |
384 | - * it cannot accept a command line longer than 32K in itself. So | |
385 | - * using a response file in this case, is an acceptable solution. | |
386 | - */ | |
387 | - if (arg_len > MAX_CMD_LINE_LEN) { | |
388 | - int fd; | |
389 | - char *result; | |
390 | - | |
391 | - if ((fd = mkstemp(rsp_name)) == -1) | |
392 | - return (NULL); | |
393 | - | |
394 | - /* write all the arguments except a 0th program name */ | |
395 | - for (i = 1; argv[i]; i++) { | |
396 | - write(fd, argv[i], strlen(argv[i])); | |
397 | - write(fd, "\n", 1); | |
398 | - } | |
342 | + if ((fd = mkstemp(rsp_name)) == -1) | |
343 | + return (NULL); | |
399 | 344 | |
400 | - close(fd); | |
401 | - add_temp(rsp_name); | |
402 | - strdupx(result, rsp_name_arg, ATEMP); | |
403 | - return (result); | |
345 | + /* write all the arguments except a 0th program name */ | |
346 | + for (i = 1; argv[i]; i++) { | |
347 | + write(fd, argv[i], strlen(argv[i])); | |
348 | + write(fd, "\n", 1); | |
404 | 349 | } |
405 | 350 | |
406 | - return (NULL); | |
351 | + close(fd); | |
352 | + add_temp(rsp_name); | |
353 | + strdupx(result, rsp_name_arg, ATEMP); | |
354 | + | |
355 | + return (result); | |
407 | 356 | } |
408 | 357 | |
409 | 358 | /* alias of execve() */ |
@@ -416,12 +365,12 @@ execve(const char *name, char * const *argv, char * const *envp) | ||
416 | 365 | const char *exec_name; |
417 | 366 | FILE *fp; |
418 | 367 | char sign[2]; |
419 | - char *rsp_argv[3]; | |
420 | - char *rsp_name_arg; | |
421 | 368 | int pid; |
422 | 369 | int status; |
423 | 370 | int fd; |
424 | 371 | int rc; |
372 | + int saved_mode; | |
373 | + int saved_errno; | |
425 | 374 | |
426 | 375 | /* |
427 | 376 | * #! /bin/sh : append .exe |
@@ -461,23 +410,41 @@ execve(const char *name, char * const *argv, char * const *envp) | ||
461 | 410 | if (errno == ENOEXEC) |
462 | 411 | return (-1); |
463 | 412 | |
464 | - rsp_name_arg = make_response_file(argv); | |
413 | + /* | |
414 | + * Normal OS/2 programs expect that standard IOs, especially stdin, | |
415 | + * are opened in text mode at the startup. By the way, on OS/2 kLIBC | |
416 | + * child processes inherit a translation mode of a parent process. | |
417 | + * As a result, if stdin is set to binary mode in a parent process, | |
418 | + * stdin of child processes is opened in binary mode as well at the | |
419 | + * startup. In this case, some programs such as sed suffer from CR. | |
420 | + */ | |
421 | + saved_mode = setmode(STDIN_FILENO, O_TEXT); | |
465 | 422 | |
466 | - if (rsp_name_arg) { | |
467 | - rsp_argv[0] = argv[0]; | |
468 | - rsp_argv[1] = rsp_name_arg; | |
469 | - rsp_argv[2] = NULL; | |
423 | + pid = spawnve(P_NOWAIT, exec_name, argv, envp); | |
424 | + saved_errno = errno; | |
470 | 425 | |
471 | - argv = rsp_argv; | |
472 | - } | |
426 | + /* arguments too long? */ | |
427 | + if (pid == -1 && saved_errno == EINVAL) { | |
428 | + /* retry with a response file */ | |
429 | + char *rsp_name_arg = make_response_file(argv); | |
473 | 430 | |
474 | - pid = spawnve(P_NOWAIT, exec_name, argv, envp); | |
431 | + if (rsp_name_arg) { | |
432 | + char *rsp_argv[3] = { argv[0], rsp_name_arg, NULL }; | |
433 | + | |
434 | + pid = spawnve(P_NOWAIT, exec_name, rsp_argv, envp); | |
435 | + saved_errno = errno; | |
436 | + | |
437 | + afree(rsp_name_arg, ATEMP); | |
438 | + } | |
439 | + } | |
475 | 440 | |
476 | - afree(rsp_name_arg, ATEMP); | |
441 | + /* restore translation mode of stdin */ | |
442 | + setmode(STDIN_FILENO, saved_mode); | |
477 | 443 | |
478 | 444 | if (pid == -1) { |
479 | 445 | cleanup_temps(); |
480 | 446 | |
447 | + errno = saved_errno; | |
481 | 448 | return (-1); |
482 | 449 | } |
483 | 450 |
@@ -557,3 +524,52 @@ cleanup(void) | ||
557 | 524 | { |
558 | 525 | cleanup_temps(); |
559 | 526 | } |
527 | + | |
528 | +int | |
529 | +getdrvwd(char **cpp, unsigned int drvltr) | |
530 | +{ | |
531 | + PBYTE cp; | |
532 | + ULONG sz; | |
533 | + APIRET rc; | |
534 | + ULONG drvno; | |
535 | + | |
536 | + if (DosQuerySysInfo(QSV_MAX_PATH_LENGTH, QSV_MAX_PATH_LENGTH, | |
537 | + &sz, sizeof(sz)) != 0) { | |
538 | + errno = EDOOFUS; | |
539 | + return (-1); | |
540 | + } | |
541 | + | |
542 | + /* allocate 'X:/' plus sz plus NUL */ | |
543 | + checkoktoadd((size_t)sz, (size_t)4); | |
544 | + cp = aresize(*cpp, (size_t)sz + (size_t)4, ATEMP); | |
545 | + cp[0] = ksh_toupper(drvltr); | |
546 | + cp[1] = ':'; | |
547 | + cp[2] = '/'; | |
548 | + drvno = ksh_numuc(cp[0]) + 1; | |
549 | + /* NUL is part of space within buffer passed */ | |
550 | + ++sz; | |
551 | + if ((rc = DosQueryCurrentDir(drvno, cp + 3, &sz)) == 0) { | |
552 | + /* success! */ | |
553 | + *cpp = cp; | |
554 | + return (0); | |
555 | + } | |
556 | + afree(cp, ATEMP); | |
557 | + *cpp = NULL; | |
558 | + switch (rc) { | |
559 | + case 15: /* invalid drive */ | |
560 | + errno = ENOTBLK; | |
561 | + break; | |
562 | + case 26: /* not dos disk */ | |
563 | + errno = ENODEV; | |
564 | + break; | |
565 | + case 108: /* drive locked */ | |
566 | + errno = EDEADLK; | |
567 | + break; | |
568 | + case 111: /* buffer overflow */ | |
569 | + errno = ENAMETOOLONG; | |
570 | + break; | |
571 | + default: | |
572 | + errno = EINVAL; | |
573 | + } | |
574 | + return (-1); | |
575 | +} |
@@ -10,7 +10,7 @@ | ||
10 | 10 | |
11 | 11 | /*- |
12 | 12 | * Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, |
13 | - * 2011, 2012, 2013, 2014, 2015, 2016, 2017 | |
13 | + * 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 | |
14 | 14 | * mirabilos <m@mirbsd.org> |
15 | 15 | * |
16 | 16 | * Provided that these terms and disclaimer and all copyright notices |
@@ -182,9 +182,9 @@ | ||
182 | 182 | #endif |
183 | 183 | |
184 | 184 | #ifdef EXTERN |
185 | -__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.841 2017/08/29 13:38:31 tg Exp $"); | |
185 | +__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.858 2018/01/14 01:47:36 tg Exp $"); | |
186 | 186 | #endif |
187 | -#define MKSH_VERSION "R56 2017/08/29" | |
187 | +#define MKSH_VERSION "R56 2018/01/14" | |
188 | 188 | |
189 | 189 | /* arithmetic types: C implementation */ |
190 | 190 | #if !HAVE_CAN_INTTYPES |
@@ -556,7 +556,7 @@ extern int __cdecl setegid(gid_t); | ||
556 | 556 | * low-bit7 at least on cp1047 so YMMV |
557 | 557 | */ |
558 | 558 | #define MAGIC KSH_BEL /* prefix for *?[!{,} during expand */ |
559 | -#define ISMAGIC(c) (ord(c) == ord(MAGIC)) | |
559 | +#define ISMAGIC(c) (ord(c) == ORD(MAGIC)) | |
560 | 560 | |
561 | 561 | EXTERN const char *safe_prompt; /* safe prompt if PS1 substitution fails */ |
562 | 562 |
@@ -643,7 +643,7 @@ char *ucstrstr(char *, const char *); | ||
643 | 643 | #endif |
644 | 644 | #endif |
645 | 645 | |
646 | -#if (!defined(MKSH_BUILDMAKEFILE4BSD) && !defined(MKSH_BUILDSH)) || (MKSH_BUILD_R != 562) | |
646 | +#if (!defined(MKSH_BUILDMAKEFILE4BSD) && !defined(MKSH_BUILDSH)) || (MKSH_BUILD_R != 563) | |
647 | 647 | #error Must run Build.sh to compile this. |
648 | 648 | extern void thiswillneverbedefinedIhope(void); |
649 | 649 | int |
@@ -804,7 +804,7 @@ struct sretrace_info; | ||
804 | 804 | struct yyrecursive_state; |
805 | 805 | |
806 | 806 | EXTERN struct sretrace_info *retrace_info; |
807 | -EXTERN int subshell_nesting_type; | |
807 | +EXTERN unsigned int subshell_nesting_type; | |
808 | 808 | |
809 | 809 | extern struct env { |
810 | 810 | ALLOC_ITEM alloc_INT; /* internal, do not touch */ |
@@ -1469,7 +1469,26 @@ EXTERN char ifs0; | ||
1469 | 1469 | #define C_UNDER CiUNDER /* _ underscore */ |
1470 | 1470 | |
1471 | 1471 | /* identity transform of octet */ |
1472 | -#define ord(c) ((unsigned int)(unsigned char)(c)) | |
1472 | +#if defined(DEBUG) && defined(__GNUC__) && !defined(__ICC) && \ | |
1473 | + !defined(__INTEL_COMPILER) && !defined(__SUNPRO_C) | |
1474 | +extern unsigned int eek_ord; | |
1475 | +#define ORD(c) ((size_t)(c) > 0xFF ? eek_ord : \ | |
1476 | + ((unsigned int)(unsigned char)(c))) | |
1477 | +#define ord(c) __builtin_choose_expr( \ | |
1478 | + __builtin_types_compatible_p(__typeof__(c), char) || \ | |
1479 | + __builtin_types_compatible_p(__typeof__(c), unsigned char), \ | |
1480 | + ((unsigned int)(unsigned char)(c)), ({ \ | |
1481 | + size_t ord_c = (c); \ | |
1482 | + \ | |
1483 | + if (ord_c > (size_t)0xFFU) \ | |
1484 | + internal_errorf("%s:%d:ord(%zX)", \ | |
1485 | + __FILE__, __LINE__, ord_c); \ | |
1486 | + ((unsigned int)(unsigned char)(ord_c)); \ | |
1487 | +})) | |
1488 | +#else | |
1489 | +#define ord(c) ((unsigned int)(unsigned char)(c)) | |
1490 | +#define ORD(c) ord(c) /* may evaluate arguments twice */ | |
1491 | +#endif | |
1473 | 1492 | #if defined(MKSH_EBCDIC) || defined(MKSH_FAUX_EBCDIC) |
1474 | 1493 | EXTERN unsigned short ebcdic_map[256]; |
1475 | 1494 | EXTERN unsigned char ebcdic_rtt_toascii[256]; |
@@ -1492,20 +1511,22 @@ extern void ebcdic_init(void); | ||
1492 | 1511 | #ifdef MKSH_EBCDIC |
1493 | 1512 | #define ksh_isctrl(c) (ord(c) < 0x40 || ord(c) == 0xFF) |
1494 | 1513 | #else |
1495 | -#define ksh_isctrl(c) ((ord(c) & 0x7F) < 0x20 || (c) == 0x7F) | |
1514 | +#define ksh_isctrl(c) ((ord(c) & 0x7F) < 0x20 || ord(c) == 0x7F) | |
1496 | 1515 | #endif |
1497 | 1516 | /* new fast character classes */ |
1498 | 1517 | #define ctype(c,t) tobool(ksh_ctypes[ord(c)] & (t)) |
1518 | +#define cinttype(c,t) ((c) >= 0 && (c) <= 0xFF ? \ | |
1519 | + tobool(ksh_ctypes[(unsigned char)(c)] & (t)) : false) | |
1499 | 1520 | /* helper functions */ |
1500 | 1521 | #define ksh_isdash(s) tobool(ord((s)[0]) == '-' && ord((s)[1]) == '\0') |
1501 | 1522 | /* invariant distance even in EBCDIC */ |
1502 | 1523 | #define ksh_tolower(c) (ctype(c, C_UPPER) ? (c) - 'A' + 'a' : (c)) |
1503 | 1524 | #define ksh_toupper(c) (ctype(c, C_LOWER) ? (c) - 'a' + 'A' : (c)) |
1504 | 1525 | /* strictly speaking rtt2asc() here, but this works even in EBCDIC */ |
1505 | -#define ksh_numdig(c) (ord(c) - ord('0')) | |
1526 | +#define ksh_numdig(c) (ord(c) - ORD('0')) | |
1506 | 1527 | #define ksh_numuc(c) (rtt2asc(c) - rtt2asc('A')) |
1507 | 1528 | #define ksh_numlc(c) (rtt2asc(c) - rtt2asc('a')) |
1508 | -#define ksh_toctrl(c) asc2rtt(ord(c) == ord('?') ? 0x7F : rtt2asc(c) & 0x9F) | |
1529 | +#define ksh_toctrl(c) asc2rtt(ord(c) == ORD('?') ? 0x7F : rtt2asc(c) & 0x9F) | |
1509 | 1530 | #define ksh_unctrl(c) asc2rtt(rtt2asc(c) ^ 0x40U) |
1510 | 1531 | |
1511 | 1532 | /* Argument parsing for built-in commands and getopts command */ |
@@ -1599,7 +1620,7 @@ EXTERN mksh_ari_t x_lins E_INIT(24); | ||
1599 | 1620 | #define shf_fileno(shf) ((shf)->fd) |
1600 | 1621 | #define shf_setfileno(shf,nfd) ((shf)->fd = (nfd)) |
1601 | 1622 | #define shf_getc_i(shf) ((shf)->rnleft > 0 ? \ |
1602 | - (shf)->rnleft--, *(shf)->rp++ : \ | |
1623 | + (shf)->rnleft--, (int)ord(*(shf)->rp++) : \ | |
1603 | 1624 | shf_getchar(shf)) |
1604 | 1625 | #define shf_putc_i(c, shf) ((shf)->wnleft == 0 ? \ |
1605 | 1626 | shf_putchar((uint8_t)(c), (shf)) : \ |
@@ -2500,6 +2521,7 @@ void shprintf(const char *, ...) | ||
2500 | 2521 | MKSH_A_FORMAT(__printf__, 1, 2); |
2501 | 2522 | int can_seek(int); |
2502 | 2523 | void initio(void); |
2524 | +void recheck_ctype(void); | |
2503 | 2525 | int ksh_dup2(int, int, bool); |
2504 | 2526 | short savefd(int); |
2505 | 2527 | void restfd(int, int); |
@@ -2734,27 +2756,32 @@ extern int tty_init_fd(void); /* initialise tty_fd, tty_devtty */ | ||
2734 | 2756 | #endif |
2735 | 2757 | |
2736 | 2758 | #ifdef MKSH_DOSPATH |
2759 | +#define mksh_drvltr(s) __extension__({ \ | |
2760 | + const char *mksh_drvltr_s = (s); \ | |
2761 | + (ctype(mksh_drvltr_s[0], C_ALPHA) && mksh_drvltr_s[1] == ':'); \ | |
2762 | +}) | |
2737 | 2763 | #define mksh_abspath(s) __extension__({ \ |
2738 | 2764 | const char *mksh_abspath_s = (s); \ |
2739 | 2765 | (mksh_cdirsep(mksh_abspath_s[0]) || \ |
2740 | - (ctype(mksh_abspath_s[0], C_ALPHA) && \ | |
2741 | - mksh_abspath_s[1] == ':')); \ | |
2766 | + (mksh_drvltr(mksh_abspath_s) && \ | |
2767 | + mksh_cdirsep(mksh_abspath_s[2]))); \ | |
2742 | 2768 | }) |
2743 | 2769 | #define mksh_cdirsep(c) __extension__({ \ |
2744 | 2770 | char mksh_cdirsep_c = (c); \ |
2745 | 2771 | (mksh_cdirsep_c == '/' || mksh_cdirsep_c == '\\'); \ |
2746 | 2772 | }) |
2747 | -#define mksh_sdirsep(s) __extension__({ \ | |
2748 | - const char *mksh_sdirsep_s = (s); \ | |
2749 | - ((char *)((ctype(mksh_sdirsep_s[0], C_ALPHA) && \ | |
2750 | - mksh_sdirsep_s[1] == ':' && \ | |
2751 | - !mksh_cdirsep(mksh_sdirsep_s[2])) ? \ | |
2752 | - (mksh_sdirsep_s + 1) : strpbrk(mksh_sdirsep_s, "/\\"))); \ | |
2773 | +#define mksh_sdirsep(s) strpbrk((s), "/\\") | |
2774 | +#define mksh_vdirsep(s) __extension__({ \ | |
2775 | + const char *mksh_vdirsep_s = (s); \ | |
2776 | + (((mksh_drvltr(mksh_vdirsep_s) && \ | |
2777 | + !mksh_cdirsep(mksh_vdirsep_s[2])) ? (!0) : \ | |
2778 | + (mksh_sdirsep(mksh_vdirsep_s) != NULL)) && \ | |
2779 | + (strcmp(mksh_vdirsep_s, T_builtin) != 0)); \ | |
2753 | 2780 | }) |
2754 | -#define mksh_vdirsep(s) (mksh_sdirsep((s)) != NULL) | |
2781 | +int getdrvwd(char **, unsigned int); | |
2755 | 2782 | #else |
2756 | -#define mksh_abspath(s) (ord((s)[0]) == ord('/')) | |
2757 | -#define mksh_cdirsep(c) (ord(c) == ord('/')) | |
2783 | +#define mksh_abspath(s) (ord((s)[0]) == ORD('/')) | |
2784 | +#define mksh_cdirsep(c) (ord(c) == ORD('/')) | |
2758 | 2785 | #define mksh_sdirsep(s) strchr((s), '/') |
2759 | 2786 | #define mksh_vdirsep(s) vstrchr((s), '/') |
2760 | 2787 | #endif |
@@ -2,7 +2,7 @@ | ||
2 | 2 | |
3 | 3 | /*- |
4 | 4 | * Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2011, |
5 | - * 2012, 2013, 2015, 2016, 2017 | |
5 | + * 2012, 2013, 2015, 2016, 2017, 2018 | |
6 | 6 | * mirabilos <m@mirbsd.org> |
7 | 7 | * Copyright (c) 2015 |
8 | 8 | * Daniel Richard G. <skunk@iSKUNK.ORG> |
@@ -27,7 +27,7 @@ | ||
27 | 27 | |
28 | 28 | #include "sh.h" |
29 | 29 | |
30 | -__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.95 2017/05/05 22:45:58 tg Exp $"); | |
30 | +__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.97 2018/01/14 01:28:16 tg Exp $"); | |
31 | 31 | |
32 | 32 | /* flags to shf_emptybuf() */ |
33 | 33 | #define EB_READSW 0x01 /* about to switch to reading */ |
@@ -554,7 +554,7 @@ shf_getchar(struct shf *shf) | ||
554 | 554 | if (shf->rnleft == 0 && (shf_fillbuf(shf) == -1 || shf->rnleft == 0)) |
555 | 555 | return (-1); |
556 | 556 | --shf->rnleft; |
557 | - return (*shf->rp++); | |
557 | + return (ord(*shf->rp++)); | |
558 | 558 | } |
559 | 559 | |
560 | 560 | /* |
@@ -1253,7 +1253,7 @@ set_ifs(const char *s) | ||
1253 | 1253 | * Not only do they require all 8 bits instead of 7, if chars are |
1254 | 1254 | * signed, they will have negative integer values! Something like |
1255 | 1255 | * (c - 'A') could actually become (c + 63)! Use the ord() macro to |
1256 | - * ensure you're getting a value in [0, 255]. | |
1256 | + * ensure you're getting a value in [0, 255] (ORD for constants). | |
1257 | 1257 | * 4. '\n' is actually NL (0x15, U+0085) instead of LF (0x25, U+000A). |
1258 | 1258 | * EBCDIC has a proper newline character instead of "emulating" one |
1259 | 1259 | * with line feeds, although this is mapped to LF for our purposes. |
@@ -2,7 +2,8 @@ | ||
2 | 2 | |
3 | 3 | /*- |
4 | 4 | * Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, |
5 | - * 2011, 2012, 2013, 2014, 2015, 2016, 2017 | |
5 | + * 2011, 2012, 2013, 2014, 2015, 2016, 2017, | |
6 | + * 2018 | |
6 | 7 | * mirabilos <m@mirbsd.org> |
7 | 8 | * |
8 | 9 | * Provided that these terms and disclaimer and all copyright notices |
@@ -23,7 +24,7 @@ | ||
23 | 24 | |
24 | 25 | #include "sh.h" |
25 | 26 | |
26 | -__RCSID("$MirOS: src/bin/mksh/syn.c,v 1.124 2017/05/05 22:53:31 tg Exp $"); | |
27 | +__RCSID("$MirOS: src/bin/mksh/syn.c,v 1.127 2018/01/14 00:22:30 tg Exp $"); | |
27 | 28 | |
28 | 29 | struct nesting_state { |
29 | 30 | int start_token; /* token than began nesting (eg, FOR) */ |
@@ -35,7 +36,7 @@ struct yyrecursive_state { | ||
35 | 36 | struct yyrecursive_state *next; |
36 | 37 | struct ioword **old_herep; |
37 | 38 | int old_symbol; |
38 | - int old_nesting_type; | |
39 | + unsigned int old_nesting_type; | |
39 | 40 | bool old_reject; |
40 | 41 | }; |
41 | 42 |
@@ -75,7 +76,10 @@ static int symbol; /* yylex value */ | ||
75 | 76 | #define ACCEPT (reject = false) |
76 | 77 | #define token(cf) ((reject) ? (ACCEPT, symbol) : (symbol = yylex(cf))) |
77 | 78 | #define tpeek(cf) ((reject) ? (symbol) : (REJECT, symbol = yylex(cf))) |
78 | -#define musthave(c,cf) do { if (token(cf) != (c)) syntaxerr(NULL); } while (/* CONSTCOND */ 0) | |
79 | +#define musthave(c,cf) do { \ | |
80 | + if ((unsigned int)token(cf) != (unsigned int)(c)) \ | |
81 | + syntaxerr(NULL); \ | |
82 | +} while (/* CONSTCOND */ 0) | |
79 | 83 | |
80 | 84 | static const char Tcbrace[] = "}"; |
81 | 85 | static const char Tesac[] = "esac"; |
@@ -91,7 +95,7 @@ yyparse(bool doalias) | ||
91 | 95 | c = tpeek(0); |
92 | 96 | if (c == 0 && !outtree) |
93 | 97 | outtree = newtp(TEOF); |
94 | - else if (!ctype(c, C_LF | C_NUL)) | |
98 | + else if (!cinttype(c, C_LF | C_NUL)) | |
95 | 99 | syntaxerr(NULL); |
96 | 100 | } |
97 | 101 |
@@ -330,7 +334,7 @@ get_command(int cf, int sALIAS) | ||
330 | 334 | XPput(args, yylval.cp); |
331 | 335 | break; |
332 | 336 | |
333 | - case ord('(' /*)*/): | |
337 | + case ORD('(' /*)*/): | |
334 | 338 | if (XPsize(args) == 0 && XPsize(vars) == 1 && |
335 | 339 | is_wdvarassign(yylval.cp)) { |
336 | 340 | char *tcp; |
@@ -386,18 +390,18 @@ get_command(int cf, int sALIAS) | ||
386 | 390 | Leave: |
387 | 391 | break; |
388 | 392 | |
389 | - case ord('(' /*)*/): { | |
390 | - int subshell_nesting_type_saved; | |
393 | + case ORD('(' /*)*/): { | |
394 | + unsigned int subshell_nesting_type_saved; | |
391 | 395 | Subshell: |
392 | 396 | subshell_nesting_type_saved = subshell_nesting_type; |
393 | - subshell_nesting_type = ord(')'); | |
394 | - t = nested(TPAREN, ord('('), ord(')'), sALIAS); | |
397 | + subshell_nesting_type = ORD(')'); | |
398 | + t = nested(TPAREN, ORD('('), ORD(')'), sALIAS); | |
395 | 399 | subshell_nesting_type = subshell_nesting_type_saved; |
396 | 400 | break; |
397 | 401 | } |
398 | 402 | |
399 | - case ord('{' /*}*/): | |
400 | - t = nested(TBRACE, ord('{'), ord('}'), sALIAS); | |
403 | + case ORD('{' /*}*/): | |
404 | + t = nested(TBRACE, ORD('{'), ORD('}'), sALIAS); | |
401 | 405 | break; |
402 | 406 | |
403 | 407 | case MDPAREN: |
@@ -407,8 +411,8 @@ get_command(int cf, int sALIAS) | ||
407 | 411 | switch (token(LETEXPR)) { |
408 | 412 | case LWORD: |
409 | 413 | break; |
410 | - case ord('(' /*)*/): | |
411 | - c = ord('('); | |
414 | + case ORD('(' /*)*/): | |
415 | + c = ORD('('); | |
412 | 416 | goto Subshell; |
413 | 417 | default: |
414 | 418 | syntaxerr(NULL); |
@@ -554,8 +558,8 @@ dogroup(int sALIAS) | ||
554 | 558 | */ |
555 | 559 | if (c == DO) |
556 | 560 | c = DONE; |
557 | - else if (c == ord('{')) | |
558 | - c = ord('}'); | |
561 | + else if ((unsigned int)c == ORD('{')) | |
562 | + c = ORD('}'); | |
559 | 563 | else |
560 | 564 | syntaxerr(NULL); |
561 | 565 | list = c_list(sALIAS, true); |
@@ -610,8 +614,8 @@ caselist(int sALIAS) | ||
610 | 614 | /* A {...} can be used instead of in...esac for case statements */ |
611 | 615 | if (c == IN) |
612 | 616 | c = ESAC; |
613 | - else if (c == ord('{')) | |
614 | - c = ord('}'); | |
617 | + else if ((unsigned int)c == ORD('{')) | |
618 | + c = ORD('}'); | |
615 | 619 | else |
616 | 620 | syntaxerr(NULL); |
617 | 621 | t = tl = NULL; |
@@ -636,18 +640,17 @@ casepart(int endtok, int sALIAS) | ||
636 | 640 | XPinit(ptns, 16); |
637 | 641 | t = newtp(TPAT); |
638 | 642 | /* no ALIAS here */ |
639 | - if (token(CONTIN | KEYWORD) != ord('(')) | |
643 | + if ((unsigned int)token(CONTIN | KEYWORD) != ORD('(')) | |
640 | 644 | REJECT; |
641 | 645 | do { |
642 | 646 | switch (token(0)) { |
643 | 647 | case LWORD: |
644 | 648 | break; |
645 | - case ord('}'): | |
649 | + case ORD('}'): | |
646 | 650 | case ESAC: |
647 | 651 | if (symbol != endtok) { |
648 | - strdupx(yylval.cp, | |
649 | - symbol == ord('}') ? Tcbrace : Tesac, | |
650 | - ATEMP); | |
652 | + strdupx(yylval.cp, (unsigned int)symbol == | |
653 | + ORD('}') ? Tcbrace : Tesac, ATEMP); | |
651 | 654 | break; |
652 | 655 | } |
653 | 656 | /* FALLTHROUGH */ |
@@ -659,23 +662,23 @@ casepart(int endtok, int sALIAS) | ||
659 | 662 | REJECT; |
660 | 663 | XPput(ptns, NULL); |
661 | 664 | t->vars = (char **)XPclose(ptns); |
662 | - musthave(ord(')'), 0); | |
665 | + musthave(ORD(')'), 0); | |
663 | 666 | |
664 | 667 | t->left = c_list(sALIAS, true); |
665 | 668 | |
666 | 669 | /* initialise to default for ;; or omitted */ |
667 | - t->u.charflag = ord(';'); | |
670 | + t->u.charflag = ORD(';'); | |
668 | 671 | /* SUSv4 requires the ;; except in the last casepart */ |
669 | 672 | if ((tpeek(CONTIN|KEYWORD|sALIAS)) != endtok) |
670 | 673 | switch (symbol) { |
671 | 674 | default: |
672 | 675 | syntaxerr(NULL); |
673 | 676 | case BRKEV: |
674 | - t->u.charflag = ord('|'); | |
677 | + t->u.charflag = ORD('|'); | |
675 | 678 | if (0) |
676 | 679 | /* FALLTHROUGH */ |
677 | 680 | case BRKFT: |
678 | - t->u.charflag = ord('&'); | |
681 | + t->u.charflag = ORD('&'); | |
679 | 682 | /* FALLTHROUGH */ |
680 | 683 | case BREAK: |
681 | 684 | /* initialised above, but we need to eat the token */ |
@@ -711,14 +714,14 @@ function_body(char *name, int sALIAS, | ||
711 | 714 | * only accepts an open-brace. |
712 | 715 | */ |
713 | 716 | if (ksh_func) { |
714 | - if (tpeek(CONTIN|KEYWORD|sALIAS) == ord('(' /*)*/)) { | |
717 | + if ((unsigned int)tpeek(CONTIN|KEYWORD|sALIAS) == ORD('(' /*)*/)) { | |
715 | 718 | /* function foo () { //}*/ |
716 | 719 | ACCEPT; |
717 | - musthave(ord(/*(*/ ')'), 0); | |
720 | + musthave(ORD(/*(*/ ')'), 0); | |
718 | 721 | /* degrade to POSIX function */ |
719 | 722 | ksh_func = false; |
720 | 723 | } |
721 | - musthave(ord('{' /*}*/), CONTIN|KEYWORD|sALIAS); | |
724 | + musthave(ORD('{' /*}*/), CONTIN|KEYWORD|sALIAS); | |
722 | 725 | REJECT; |
723 | 726 | } |
724 | 727 |
@@ -810,8 +813,8 @@ static const struct tokeninfo { | ||
810 | 813 | { "in", IN, true }, |
811 | 814 | { Tfunction, FUNCTION, true }, |
812 | 815 | { Ttime, TIME, true }, |
813 | - { "{", ord('{'), true }, | |
814 | - { Tcbrace, ord('}'), true }, | |
816 | + { "{", ORD('{'), true }, | |
817 | + { Tcbrace, ORD('}'), true }, | |
815 | 818 | { "!", BANG, true }, |
816 | 819 | { "[[", DBRACKET, true }, |
817 | 820 | /* Lexical tokens (0[EOF], LWORD and REDIR handled specially) */ |
@@ -823,7 +826,7 @@ static const struct tokeninfo { | ||
823 | 826 | { "((", MDPAREN, false }, |
824 | 827 | { "|&", COPROC, false }, |
825 | 828 | /* and some special cases... */ |
826 | - { "newline", ord('\n'), false }, | |
829 | + { "newline", ORD('\n'), false }, | |
827 | 830 | { NULL, 0, false } |
828 | 831 | }; |
829 | 832 |
@@ -998,9 +1001,9 @@ dbtestp_isa(Test_env *te, Test_meta meta) | ||
998 | 1001 | ret = (uqword && !strcmp(yylval.cp, |
999 | 1002 | dbtest_tokens[(int)TM_NOT])) ? TO_NONNULL : TO_NONOP; |
1000 | 1003 | else if (meta == TM_OPAREN) |
1001 | - ret = c == ord('(') /*)*/ ? TO_NONNULL : TO_NONOP; | |
1004 | + ret = (unsigned int)c == ORD('(') /*)*/ ? TO_NONNULL : TO_NONOP; | |
1002 | 1005 | else if (meta == TM_CPAREN) |
1003 | - ret = c == /*(*/ ord(')') ? TO_NONNULL : TO_NONOP; | |
1006 | + ret = (unsigned int)c == /*(*/ ORD(')') ? TO_NONNULL : TO_NONOP; | |
1004 | 1007 | else if (meta == TM_UNOP || meta == TM_BINOP) { |
1005 | 1008 | if (meta == TM_BINOP && c == REDIR && |
1006 | 1009 | (yylval.iop->ioflag == IOREAD || |
@@ -1131,14 +1134,14 @@ yyrecursive(int subtype) | ||
1131 | 1134 | struct op *t; |
1132 | 1135 | char *cp; |
1133 | 1136 | struct yyrecursive_state *ys; |
1134 | - int stok, etok; | |
1137 | + unsigned int stok, etok; | |
1135 | 1138 | |
1136 | 1139 | if (subtype != COMSUB) { |
1137 | - stok = ord('{'); | |
1138 | - etok = ord('}'); | |
1140 | + stok = ORD('{'); | |
1141 | + etok = ORD('}'); | |
1139 | 1142 | } else { |
1140 | - stok = ord('('); | |
1141 | - etok = ord(')'); | |
1143 | + stok = ORD('('); | |
1144 | + etok = ORD(')'); | |
1142 | 1145 | } |
1143 | 1146 | |
1144 | 1147 | ys = alloc(sizeof(struct yyrecursive_state), ATEMP); |
@@ -23,7 +23,7 @@ | ||
23 | 23 | |
24 | 24 | #include "sh.h" |
25 | 25 | |
26 | -__RCSID("$MirOS: src/bin/mksh/tree.c,v 1.93 2017/05/05 22:53:32 tg Exp $"); | |
26 | +__RCSID("$MirOS: src/bin/mksh/tree.c,v 1.95 2018/01/14 00:03:05 tg Exp $"); | |
27 | 27 | |
28 | 28 | #define INDENT 8 |
29 | 29 |
@@ -329,7 +329,7 @@ wdvarput(struct shf *shf, const char *wp, int quotelevel, int opmode) | ||
329 | 329 | case EOS: |
330 | 330 | return (--wp); |
331 | 331 | case ADELIM: |
332 | - if (ord(*wp) == ord(/*{*/ '}')) { | |
332 | + if (ord(*wp) == ORD(/*{*/ '}')) { | |
333 | 333 | ++wp; |
334 | 334 | goto wdvarput_csubst; |
335 | 335 | } |
@@ -342,21 +342,21 @@ wdvarput(struct shf *shf, const char *wp, int quotelevel, int opmode) | ||
342 | 342 | c = ord(*wp++); |
343 | 343 | if (opmode & WDS_TPUTS) |
344 | 344 | switch (c) { |
345 | - case ord('\n'): | |
345 | + case ORD('\n'): | |
346 | 346 | if (quotelevel == 0) { |
347 | - c = ord('\''); | |
347 | + c = ORD('\''); | |
348 | 348 | shf_putc(c, shf); |
349 | - shf_putc(ord('\n'), shf); | |
349 | + shf_putc(ORD('\n'), shf); | |
350 | 350 | } |
351 | 351 | break; |
352 | 352 | default: |
353 | 353 | if (quotelevel == 0) |
354 | 354 | /* FALLTHROUGH */ |
355 | - case ord('"'): | |
356 | - case ord('`'): | |
357 | - case ord('$'): | |
358 | - case ord('\\'): | |
359 | - shf_putc(ord('\\'), shf); | |
355 | + case ORD('"'): | |
356 | + case ORD('`'): | |
357 | + case ORD('$'): | |
358 | + case ORD('\\'): | |
359 | + shf_putc(ORD('\\'), shf); | |
360 | 360 | break; |
361 | 361 | } |
362 | 362 | shf_putc(c, shf); |
@@ -365,7 +365,7 @@ wdvarput(struct shf *shf, const char *wp, int quotelevel, int opmode) | ||
365 | 365 | case COMSUB: |
366 | 366 | shf_puts("$(", shf); |
367 | 367 | cs = ")"; |
368 | - if (ord(*wp) == ord('(' /*)*/)) | |
368 | + if (ord(*wp) == ORD('(' /*)*/)) | |
369 | 369 | shf_putc(' ', shf); |
370 | 370 | pSUB: |
371 | 371 | while ((c = *wp++) != 0) |
@@ -374,11 +374,11 @@ wdvarput(struct shf *shf, const char *wp, int quotelevel, int opmode) | ||
374 | 374 | break; |
375 | 375 | case FUNASUB: |
376 | 376 | case FUNSUB: |
377 | - c = ord(' '); | |
377 | + c = ORD(' '); | |
378 | 378 | if (0) |
379 | 379 | /* FALLTHROUGH */ |
380 | 380 | case VALSUB: |
381 | - c = ord('|'); | |
381 | + c = ORD('|'); | |
382 | 382 | shf_putc('$', shf); |
383 | 383 | shf_putc('{', shf); |
384 | 384 | shf_putc(c, shf); |
@@ -403,14 +403,14 @@ wdvarput(struct shf *shf, const char *wp, int quotelevel, int opmode) | ||
403 | 403 | break; |
404 | 404 | case OSUBST: |
405 | 405 | shf_putc('$', shf); |
406 | - if (ord(*wp++) == ord('{')) | |
406 | + if (ord(*wp++) == ORD('{')) | |
407 | 407 | shf_putc('{', shf); |
408 | 408 | while ((c = *wp++) != 0) |
409 | 409 | shf_putc(c, shf); |
410 | 410 | wp = wdvarput(shf, wp, 0, opmode); |
411 | 411 | break; |
412 | 412 | case CSUBST: |
413 | - if (ord(*wp++) == ord('}')) { | |
413 | + if (ord(*wp++) == ORD('}')) { | |
414 | 414 | wdvarput_csubst: |
415 | 415 | shf_putc('}', shf); |
416 | 416 | } |
@@ -420,11 +420,11 @@ wdvarput(struct shf *shf, const char *wp, int quotelevel, int opmode) | ||
420 | 420 | shf_putc('(', shf); |
421 | 421 | break; |
422 | 422 | case SPAT: |
423 | - c = ord('|'); | |
423 | + c = ORD('|'); | |
424 | 424 | if (0) |
425 | 425 | /* FALLTHROUGH */ |
426 | 426 | case CPAT: |
427 | - c = ord(/*(*/ ')'); | |
427 | + c = ORD(/*(*/ ')'); | |
428 | 428 | shf_putc(c, shf); |
429 | 429 | break; |
430 | 430 | } |
@@ -470,36 +470,37 @@ vfptreef(struct shf *shf, int indent, const char *fmt, va_list va) | ||
470 | 470 | while ((c = ord(*fmt++))) { |
471 | 471 | if (c == '%') { |
472 | 472 | switch ((c = ord(*fmt++))) { |
473 | - case ord('c'): | |
473 | + case ORD('c'): | |
474 | 474 | /* character (octet, probably) */ |
475 | 475 | shf_putchar(va_arg(va, int), shf); |
476 | 476 | break; |
477 | - case ord('s'): | |
477 | + case ORD('s'): | |
478 | 478 | /* string */ |
479 | 479 | shf_puts(va_arg(va, char *), shf); |
480 | 480 | break; |
481 | - case ord('S'): | |
481 | + case ORD('S'): | |
482 | 482 | /* word */ |
483 | 483 | wdvarput(shf, va_arg(va, char *), 0, WDS_TPUTS); |
484 | 484 | break; |
485 | - case ord('d'): | |
485 | + case ORD('d'): | |
486 | 486 | /* signed decimal */ |
487 | 487 | shf_fprintf(shf, Tf_d, va_arg(va, int)); |
488 | 488 | break; |
489 | - case ord('u'): | |
489 | + case ORD('u'): | |
490 | 490 | /* unsigned decimal */ |
491 | 491 | shf_fprintf(shf, "%u", va_arg(va, unsigned int)); |
492 | 492 | break; |
493 | - case ord('T'): | |
493 | + case ORD('T'): | |
494 | 494 | /* format tree */ |
495 | 495 | ptree(va_arg(va, struct op *), indent, shf); |
496 | 496 | goto dont_trash_prevent_semicolon; |
497 | - case ord(';'): | |
497 | + case ORD(';'): | |
498 | 498 | /* newline or ; */ |
499 | - case ord('N'): | |
499 | + case ORD('N'): | |
500 | 500 | /* newline or space */ |
501 | 501 | if (shf->flags & SHF_STRING) { |
502 | - if (c == ord(';') && !prevent_semicolon) | |
502 | + if ((unsigned int)c == ORD(';') && | |
503 | + !prevent_semicolon) | |
503 | 504 | shf_putc(';', shf); |
504 | 505 | shf_putc(' ', shf); |
505 | 506 | } else { |
@@ -515,7 +516,7 @@ vfptreef(struct shf *shf, int indent, const char *fmt, va_list va) | ||
515 | 516 | shf_putc(' ', shf); |
516 | 517 | } |
517 | 518 | break; |
518 | - case ord('R'): | |
519 | + case ORD('R'): | |
519 | 520 | /* I/O redirection */ |
520 | 521 | pioact(shf, va_arg(va, struct ioword *)); |
521 | 522 | break; |
@@ -613,7 +614,7 @@ wdscan(const char *wp, int c) | ||
613 | 614 | case ADELIM: |
614 | 615 | if (c == ADELIM && nest == 0) |
615 | 616 | return (wp + 1); |
616 | - if (ord(*wp) == ord(/*{*/ '}')) | |
617 | + if (ord(*wp) == ORD(/*{*/ '}')) | |
617 | 618 | goto wdscan_csubst; |
618 | 619 | /* FALLTHROUGH */ |
619 | 620 | case CHAR: |
@@ -808,7 +809,7 @@ vistree(char *dst, size_t sz, struct op *t) | ||
808 | 809 | } else if (UTFMODE && rtt2asc(c) > 0x7F) { |
809 | 810 | /* better not try to display broken multibyte chars */ |
810 | 811 | /* also go easy on the Unicode: no U+FFFD here */ |
811 | - c = ord('?'); | |
812 | + c = ORD('?'); | |
812 | 813 | } |
813 | 814 | *dst++ = c; |
814 | 815 | goto vist_loop; |
@@ -842,7 +843,7 @@ dumpwdvar_i(struct shf *shf, const char *wp, int quotelevel) | ||
842 | 843 | shf_puts("EOS", shf); |
843 | 844 | return (--wp); |
844 | 845 | case ADELIM: |
845 | - if (ord(*wp) == ord(/*{*/ '}')) { | |
846 | + if (ord(*wp) == ORD(/*{*/ '}')) { | |
846 | 847 | shf_puts(/*{*/ "]ADELIM(})", shf); |
847 | 848 | return (wp + 1); |
848 | 849 | } |
@@ -856,8 +857,8 @@ dumpwdvar_i(struct shf *shf, const char *wp, int quotelevel) | ||
856 | 857 | case QCHAR: |
857 | 858 | shf_puts("QCHAR<", shf); |
858 | 859 | c = ord(*wp++); |
859 | - if (quotelevel == 0 || c == ord('"') || | |
860 | - c == ord('\\') || ctype(c, C_DOLAR | C_GRAVE)) | |
860 | + if (quotelevel == 0 || c == ORD('"') || | |
861 | + c == ORD('\\') || ctype(c, C_DOLAR | C_GRAVE)) | |
861 | 862 | shf_putc('\\', shf); |
862 | 863 | dumpchar(shf, c); |
863 | 864 | goto closeandout; |
@@ -2,7 +2,7 @@ | ||
2 | 2 | |
3 | 3 | /*- |
4 | 4 | * Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, |
5 | - * 2011, 2012, 2013, 2014, 2015, 2016, 2017 | |
5 | + * 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 | |
6 | 6 | * mirabilos <m@mirbsd.org> |
7 | 7 | * |
8 | 8 | * Provided that these terms and disclaimer and all copyright notices |
@@ -28,7 +28,7 @@ | ||
28 | 28 | #include <sys/sysctl.h> |
29 | 29 | #endif |
30 | 30 | |
31 | -__RCSID("$MirOS: src/bin/mksh/var.c,v 1.220 2017/07/26 23:02:28 tg Exp $"); | |
31 | +__RCSID("$MirOS: src/bin/mksh/var.c,v 1.223 2018/01/13 23:55:15 tg Exp $"); | |
32 | 32 | |
33 | 33 | /*- |
34 | 34 | * Variables |
@@ -136,7 +136,7 @@ initvar(void) | ||
136 | 136 | struct tbl *tp; |
137 | 137 | |
138 | 138 | ktinit(APERM, &specials, |
139 | - /* currently 18 specials: 75% of 32 = 2^5 */ | |
139 | + /* currently 21 specials: 75% of 32 = 2^5 */ | |
140 | 140 | 5); |
141 | 141 | while (i < V_MAX - 1) { |
142 | 142 | tp = ktenter(&specials, initvar_names[i], |
@@ -204,7 +204,7 @@ array_index_calc(const char *n, bool *arrayp, uint32_t *valp) | ||
204 | 204 | } |
205 | 205 | innermost_refflag = SRF_NOP; |
206 | 206 | |
207 | - if (p != n && ord(*p) == ord('[') && (len = array_ref_len(p))) { | |
207 | + if (p != n && ord(*p) == ORD('[') && (len = array_ref_len(p))) { | |
208 | 208 | char *sub, *tmp; |
209 | 209 | mksh_ari_t rval; |
210 | 210 |
@@ -780,7 +780,7 @@ typeset(const char *var, uint32_t set, uint32_t clr, int field, int base) | ||
780 | 780 | /* no variable name given */ |
781 | 781 | return (NULL); |
782 | 782 | } |
783 | - if (ord(*val) == ord('[')) { | |
783 | + if (ord(*val) == ORD('[')) { | |
784 | 784 | if (new_refflag != SRF_NOP) |
785 | 785 | errorf(Tf_sD_s, var, |
786 | 786 | "reference variable can't be an array"); |
@@ -803,13 +803,13 @@ typeset(const char *var, uint32_t set, uint32_t clr, int field, int base) | ||
803 | 803 | } |
804 | 804 | val += len; |
805 | 805 | } |
806 | - if (ord(val[0]) == ord('=')) { | |
806 | + if (ord(val[0]) == ORD('=')) { | |
807 | 807 | strndupx(tvar, var, val - var, ATEMP); |
808 | 808 | ++val; |
809 | 809 | } else if (set & IMPORT) { |
810 | 810 | /* environment invalid variable name or no assignment */ |
811 | 811 | return (NULL); |
812 | - } else if (ord(val[0]) == ord('+') && ord(val[1]) == ord('=')) { | |
812 | + } else if (ord(val[0]) == ORD('+') && ord(val[1]) == ORD('=')) { | |
813 | 813 | strndupx(tvar, var, val - var, ATEMP); |
814 | 814 | val += 2; |
815 | 815 | vappend = true; |
@@ -822,9 +822,9 @@ typeset(const char *var, uint32_t set, uint32_t clr, int field, int base) | ||
822 | 822 | val = NULL; |
823 | 823 | /* handle foo[*] => foo (whole array) mapping for R39b */ |
824 | 824 | len = strlen(tvar); |
825 | - if (len > 3 && ord(tvar[len - 3]) == ord('[') && | |
826 | - ord(tvar[len - 2]) == ord('*') && | |
827 | - ord(tvar[len - 1]) == ord(']')) | |
825 | + if (len > 3 && ord(tvar[len - 3]) == ORD('[') && | |
826 | + ord(tvar[len - 2]) == ORD('*') && | |
827 | + ord(tvar[len - 1]) == ORD(']')) | |
828 | 828 | tvar[len - 3] = '\0'; |
829 | 829 | } |
830 | 830 |
@@ -861,7 +861,7 @@ typeset(const char *var, uint32_t set, uint32_t clr, int field, int base) | ||
861 | 861 | nameref_empty: |
862 | 862 | errorf(Tf_sD_s, var, "empty nameref target"); |
863 | 863 | } |
864 | - len = (ord(*ccp) == ord('[')) ? array_ref_len(ccp) : 0; | |
864 | + len = (ord(*ccp) == ORD('[')) ? array_ref_len(ccp) : 0; | |
865 | 865 | if (ccp[len]) { |
866 | 866 | /* |
867 | 867 | * works for cases "no array", "valid array with |
@@ -1071,7 +1071,7 @@ skip_varname(const char *s, bool aok) | ||
1071 | 1071 | do { |
1072 | 1072 | ++s; |
1073 | 1073 | } while (ctype(*s, C_ALNUX)); |
1074 | - if (aok && ord(*s) == ord('[') && (alen = array_ref_len(s))) | |
1074 | + if (aok && ord(*s) == ORD('[') && (alen = array_ref_len(s))) | |
1075 | 1075 | s += alen; |
1076 | 1076 | } |
1077 | 1077 | return (s); |
@@ -1087,7 +1087,7 @@ skip_wdvarname(const char *s, | ||
1087 | 1087 | do { |
1088 | 1088 | s += 2; |
1089 | 1089 | } while (s[0] == CHAR && ctype(s[1], C_ALNUX)); |
1090 | - if (aok && s[0] == CHAR && ord(s[1]) == ord('[')) { | |
1090 | + if (aok && s[0] == CHAR && ord(s[1]) == ORD('[')) { | |
1091 | 1091 | /* skip possible array de-reference */ |
1092 | 1092 | const char *p = s; |
1093 | 1093 | char c; |
@@ -1098,9 +1098,9 @@ skip_wdvarname(const char *s, | ||
1098 | 1098 | break; |
1099 | 1099 | c = p[1]; |
1100 | 1100 | p += 2; |
1101 | - if (ord(c) == ord('[')) | |
1101 | + if (ord(c) == ORD('[')) | |
1102 | 1102 | depth++; |
1103 | - else if (ord(c) == ord(']') && --depth == 0) { | |
1103 | + else if (ord(c) == ORD(']') && --depth == 0) { | |
1104 | 1104 | s = p; |
1105 | 1105 | break; |
1106 | 1106 | } |
@@ -1294,9 +1294,29 @@ setspec(struct tbl *vp) | ||
1294 | 1294 | { |
1295 | 1295 | mksh_ari_u num; |
1296 | 1296 | char *s; |
1297 | - int st; | |
1297 | + int st = special(vp->name); | |
1298 | 1298 | |
1299 | - switch ((st = special(vp->name))) { | |
1299 | +#ifdef MKSH_DOSPATH | |
1300 | + switch (st) { | |
1301 | + case V_PATH: | |
1302 | + case V_TMPDIR: | |
1303 | +#ifdef __OS2__ | |
1304 | + case V_BEGINLIBPATH: | |
1305 | + case V_ENDLIBPATH: | |
1306 | +#endif | |
1307 | + /* convert backslashes to slashes for convenience */ | |
1308 | + if (!(vp->flag&INTEGER)) { | |
1309 | + s = str_val(vp); | |
1310 | + do { | |
1311 | + if (*s == ORD('\\')) | |
1312 | + *s = '/'; | |
1313 | + } while (*s++); | |
1314 | + } | |
1315 | + break; | |
1316 | + } | |
1317 | +#endif | |
1318 | + | |
1319 | + switch (st) { | |
1300 | 1320 | #ifdef __OS2__ |
1301 | 1321 | case V_BEGINLIBPATH: |
1302 | 1322 | case V_ENDLIBPATH: |
@@ -1366,6 +1386,13 @@ setspec(struct tbl *vp) | ||
1366 | 1386 | } |
1367 | 1387 | vp->flag |= SPECIAL; |
1368 | 1388 | break; |
1389 | +#ifdef MKSH_EARLY_LOCALE_TRACKING | |
1390 | + case V_LANG: | |
1391 | + case V_LC_ALL: | |
1392 | + case V_LC_CTYPE: | |
1393 | + recheck_ctype(); | |
1394 | + return; | |
1395 | +#endif | |
1369 | 1396 | default: |
1370 | 1397 | /* do nothing, do not touch vp at all */ |
1371 | 1398 | return; |
@@ -1465,6 +1492,13 @@ unsetspec(struct tbl *vp) | ||
1465 | 1492 | /* AT&T ksh leaves previous value in place */ |
1466 | 1493 | unspecial(vp->name); |
1467 | 1494 | break; |
1495 | +#ifdef MKSH_EARLY_LOCALE_TRACKING | |
1496 | + case V_LANG: | |
1497 | + case V_LC_ALL: | |
1498 | + case V_LC_CTYPE: | |
1499 | + recheck_ctype(); | |
1500 | + return; | |
1501 | +#endif | |
1468 | 1502 | } |
1469 | 1503 | } |
1470 | 1504 |
@@ -1528,8 +1562,8 @@ array_ref_len(const char *cp) | ||
1528 | 1562 | char c; |
1529 | 1563 | int depth = 0; |
1530 | 1564 | |
1531 | - while ((c = *s++) && (ord(c) != ord(']') || --depth)) | |
1532 | - if (ord(c) == ord('[')) | |
1565 | + while ((c = *s++) && (ord(c) != ORD(']') || --depth)) | |
1566 | + if (ord(c) == ORD('[')) | |
1533 | 1567 | depth++; |
1534 | 1568 | if (!c) |
1535 | 1569 | return (0); |
@@ -1601,18 +1635,18 @@ set_array(const char *var, bool reset, const char **vals) | ||
1601 | 1635 | } |
1602 | 1636 | while ((ccp = vals[i])) { |
1603 | 1637 | #if 0 /* temporarily taken out due to regression */ |
1604 | - if (ord(*ccp) == ord('[')) { | |
1638 | + if (ord(*ccp) == ORD('[')) { | |
1605 | 1639 | int level = 0; |
1606 | 1640 | |
1607 | 1641 | while (*ccp) { |
1608 | - if (ord(*ccp) == ord(']') && --level == 0) | |
1642 | + if (ord(*ccp) == ORD(']') && --level == 0) | |
1609 | 1643 | break; |
1610 | - if (ord(*ccp) == ord('[')) | |
1644 | + if (ord(*ccp) == ORD('[')) | |
1611 | 1645 | ++level; |
1612 | 1646 | ++ccp; |
1613 | 1647 | } |
1614 | - if (ord(*ccp) == ord(']') && level == 0 && | |
1615 | - ord(ccp[1]) == ord('=')) { | |
1648 | + if (ord(*ccp) == ORD(']') && level == 0 && | |
1649 | + ord(ccp[1]) == ORD('=')) { | |
1616 | 1650 | strndupx(cp, vals[i] + 1, ccp - (vals[i] + 1), |
1617 | 1651 | ATEMP); |
1618 | 1652 | evaluate(substitute(cp, 0), (mksh_ari_t *)&j, |
@@ -1,5 +1,5 @@ | ||
1 | 1 | /*- |
2 | - * Copyright (c) 2009, 2011, 2012, 2016 | |
2 | + * Copyright (c) 2009, 2011, 2012, 2016, 2018 | |
3 | 3 | * mirabilos <m@mirbsd.org> |
4 | 4 | * |
5 | 5 | * Provided that these terms and disclaimer and all copyright notices |
@@ -19,7 +19,7 @@ | ||
19 | 19 | */ |
20 | 20 | |
21 | 21 | #if defined(VARSPEC_DEFNS) |
22 | -__RCSID("$MirOS: src/bin/mksh/var_spec.h,v 1.10 2016/11/11 23:31:39 tg Exp $"); | |
22 | +__RCSID("$MirOS: src/bin/mksh/var_spec.h,v 1.11 2018/01/13 21:38:10 tg Exp $"); | |
23 | 23 | #define FN(name) /* nothing */ |
24 | 24 | #elif defined(VARSPEC_ENUMS) |
25 | 25 | #define FN(name) V_##name, |
@@ -53,6 +53,11 @@ FN(HISTFILE) | ||
53 | 53 | #endif |
54 | 54 | FN(HISTSIZE) |
55 | 55 | FN(IFS) |
56 | +#ifdef MKSH_EARLY_LOCALE_TRACKING | |
57 | +FN(LANG) | |
58 | +FN(LC_ALL) | |
59 | +FN(LC_CTYPE) | |
60 | +#endif | |
56 | 61 | #ifdef __OS2__ |
57 | 62 | FN(LIBPATHSTRICT) |
58 | 63 | #endif |