@ecmaos-apps/cmatrix-src 0.0.0-stage → 2.0.0-ecmaos.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -2
- package/build/build.sh +62 -0
- package/package.json +40 -4
- package/share/licenses/cmatrix/COPYING +674 -0
- package/share/licenses/cmatrix/SOURCE +27 -0
- package/sources/cmatrix-2.0.tar.gz +0 -0
- package/sources/ncurses-6.5.tar.gz +0 -0
- package/toolchain/emscripten-version +1 -0
- package/toolchain/rust-wali-version +3 -0
- package/toolchain/wali/asyncify-reach.mjs +107 -0
- package/toolchain/wali/asyncify.sh +57 -0
- package/toolchain/wali/build-sysroot.sh +158 -0
- package/toolchain/wali/patches/compiler-rt/0001-wasm-compare-result.patch +18 -0
- package/toolchain/wali/patches/musl/0001-environment-through-imports.patch +143 -0
- package/toolchain/wali/patches/musl/0002-setjmp-with-wasm-exceptions.patch +133 -0
- package/toolchain/wali/patches/musl/0003-unknown-syscall-is-enosys.patch +31 -0
- package/toolchain/wali/patches/musl/0004-return-from-main-is-exit.patch +53 -0
- package/toolchain/wali/patches/musl/0005-posix-spawn-through-the-host.patch +278 -0
- package/toolchain/wali/patches/musl/0006-detached-thread-frees-its-stack.patch +34 -0
- package/toolchain/wali/patches/musl/0007-wordexp-without-fork.patch +62 -0
- package/toolchain/wali/patches/musl/0008-progname-from-argv.patch +34 -0
- package/toolchain/wali/patches/musl/0009-no-basename-in-string-h.patch +15 -0
- package/toolchain/wali/patches/musl/0010-ssize-max-is-pointer-sized.patch +15 -0
- package/toolchain/wali/patches/musl/0011-startup-without-malloc.patch +85 -0
- package/toolchain/wali/patches/musl/0012-floatscan-fixes-from-musl.patch +39 -0
- package/toolchain/wali/patches/musl/0013-strptime-from-musl-with-glibc-s-and-z.patch +169 -0
- package/toolchain/wali/patches/musl/0014-wordexp-fixes-from-musl.patch +43 -0
- package/toolchain/wali/patches/musl/0015-long-double-is-ieee-quad.patch +202 -0
- package/toolchain/wali/patches/musl/0016-wordexp-nocmd-and-undef.patch +285 -0
- package/toolchain/wali/rust.sh +116 -0
- package/toolchain/wali/signal-checks.mjs +373 -0
- package/toolchain/wali-version +13 -0
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
strptime as musl has it since 1.2.5 (fced99e9: %F, %g, %G, %s, %u, %V, %z and %Z, which the next POSIX issue adopts;
|
|
2
|
+
0572555d: %Z reads tzname[] under the timezone lock, and not at all before tzset), and, beyond it, %s and %z as glibc
|
|
3
|
+
and the BSDs take them: %s sets the time to the local time of those seconds since the Epoch, where musl only parses
|
|
4
|
+
them, and %z takes Z, +hh and +hh:mm besides +hhmm.
|
|
5
|
+
|
|
6
|
+
diff --git i/src/time/__tz.c w/src/time/__tz.c
|
|
7
|
+
index c34b3eb..cf45b92 100644
|
|
8
|
+
--- i/src/time/__tz.c
|
|
9
|
+
+++ w/src/time/__tz.c
|
|
10
|
+
@@ -437,3 +437,22 @@ const char *__tm_to_tzname(const struct tm *tm)
|
|
11
|
+
UNLOCK(lock);
|
|
12
|
+
return p;
|
|
13
|
+
}
|
|
14
|
+
+
|
|
15
|
+
+int __tzname_to_isdst(const char *restrict *s)
|
|
16
|
+
+{
|
|
17
|
+
+ size_t len;
|
|
18
|
+
+ int isdst = -1;
|
|
19
|
+
+ LOCK(lock);
|
|
20
|
+
+ if (tzname[0] && !strncmp(*s, tzname[0], len = strlen(tzname[0]))) {
|
|
21
|
+
+ isdst = 0;
|
|
22
|
+
+ *s += len;
|
|
23
|
+
+ } else if (tzname[1] && !strncmp(*s, tzname[1], len=strlen(tzname[1]))) {
|
|
24
|
+
+ isdst = 1;
|
|
25
|
+
+ *s += len;
|
|
26
|
+
+ } else {
|
|
27
|
+
+ /* FIXME: is this supposed to be an error? */
|
|
28
|
+
+ while (isalpha(**s)) ++*s;
|
|
29
|
+
+ }
|
|
30
|
+
+ UNLOCK(lock);
|
|
31
|
+
+ return isdst;
|
|
32
|
+
+}
|
|
33
|
+
diff --git i/src/time/strptime.c w/src/time/strptime.c
|
|
34
|
+
index c54a0d8..07b3e8b 100644
|
|
35
|
+
--- i/src/time/strptime.c
|
|
36
|
+
+++ w/src/time/strptime.c
|
|
37
|
+
@@ -5,6 +5,8 @@
|
|
38
|
+
#include <stddef.h>
|
|
39
|
+
#include <string.h>
|
|
40
|
+
#include <strings.h>
|
|
41
|
+
+#include <limits.h>
|
|
42
|
+
+#include "time_impl.h"
|
|
43
|
+
|
|
44
|
+
char *strptime(const char *restrict s, const char *restrict f, struct tm *restrict tm)
|
|
45
|
+
{
|
|
46
|
+
@@ -59,6 +61,22 @@ char *strptime(const char *restrict s, const char *restrict f, struct tm *restri
|
|
47
|
+
s = strptime(s, "%m/%d/%y", tm);
|
|
48
|
+
if (!s) return 0;
|
|
49
|
+
break;
|
|
50
|
+
+ case 'F':
|
|
51
|
+
+ /* Use temp buffer to implement the odd requirement
|
|
52
|
+
+ * that entire field be width-limited but the year
|
|
53
|
+
+ * subfield not itself be limited. */
|
|
54
|
+
+ i = 0;
|
|
55
|
+
+ char tmp[20];
|
|
56
|
+
+ if (*s == '-' || *s == '+') tmp[i++] = *s++;
|
|
57
|
+
+ while (*s=='0' && isdigit(s[1])) s++;
|
|
58
|
+
+ for (; *s && i<(size_t)w && i+1<sizeof tmp; i++) {
|
|
59
|
+
+ tmp[i] = *s++;
|
|
60
|
+
+ }
|
|
61
|
+
+ tmp[i] = 0;
|
|
62
|
+
+ char *p = strptime(tmp, "%12Y-%m-%d", tm);
|
|
63
|
+
+ if (!p) return 0;
|
|
64
|
+
+ s -= tmp+i-p;
|
|
65
|
+
+ break;
|
|
66
|
+
case 'H':
|
|
67
|
+
dest = &tm->tm_hour;
|
|
68
|
+
min = 0;
|
|
69
|
+
@@ -114,6 +132,23 @@ char *strptime(const char *restrict s, const char *restrict f, struct tm *restri
|
|
70
|
+
s = strptime(s, "%H:%M", tm);
|
|
71
|
+
if (!s) return 0;
|
|
72
|
+
break;
|
|
73
|
+
+ case 's':
|
|
74
|
+
+ /* ecmaOS: the time is the local time of those
|
|
75
|
+
+ * seconds since the Epoch, as glibc and the BSDs
|
|
76
|
+
+ * have it, where musl only parses them. */
|
|
77
|
+
+ {
|
|
78
|
+
+ long long secs = 0;
|
|
79
|
+
+ neg = *s == '-';
|
|
80
|
+
+ if (neg) s++;
|
|
81
|
+
+ if (!isdigit(*s)) return 0;
|
|
82
|
+
+ for (; isdigit(*s); s++) {
|
|
83
|
+
+ if (secs > (LLONG_MAX - (*s-'0')) / 10) return 0;
|
|
84
|
+
+ secs = secs * 10 + (*s-'0');
|
|
85
|
+
+ }
|
|
86
|
+
+ time_t t = neg ? -secs : secs;
|
|
87
|
+
+ if (t != (neg ? -secs : secs) || !localtime_r(&t, tm)) return 0;
|
|
88
|
+
+ }
|
|
89
|
+
+ break;
|
|
90
|
+
case 'S':
|
|
91
|
+
dest = &tm->tm_sec;
|
|
92
|
+
min = 0;
|
|
93
|
+
@@ -125,11 +160,30 @@ char *strptime(const char *restrict s, const char *restrict f, struct tm *restri
|
|
94
|
+
break;
|
|
95
|
+
case 'U':
|
|
96
|
+
case 'W':
|
|
97
|
+
- /* Throw away result, for now. (FIXME?) */
|
|
98
|
+
+ /* Throw away result of %U, %V, %W, %g, and %G. Effect
|
|
99
|
+
+ * is unspecified and there is no clear right choice. */
|
|
100
|
+
dest = &dummy;
|
|
101
|
+
min = 0;
|
|
102
|
+
range = 54;
|
|
103
|
+
goto numeric_range;
|
|
104
|
+
+ case 'V':
|
|
105
|
+
+ dest = &dummy;
|
|
106
|
+
+ min = 1;
|
|
107
|
+
+ range = 53;
|
|
108
|
+
+ goto numeric_range;
|
|
109
|
+
+ case 'g':
|
|
110
|
+
+ dest = &dummy;
|
|
111
|
+
+ w = 2;
|
|
112
|
+
+ goto numeric_digits;
|
|
113
|
+
+ case 'G':
|
|
114
|
+
+ dest = &dummy;
|
|
115
|
+
+ if (w<0) w=4;
|
|
116
|
+
+ goto numeric_digits;
|
|
117
|
+
+ case 'u':
|
|
118
|
+
+ dest = &tm->tm_wday;
|
|
119
|
+
+ min = 1;
|
|
120
|
+
+ range = 7;
|
|
121
|
+
+ goto numeric_range;
|
|
122
|
+
case 'w':
|
|
123
|
+
dest = &tm->tm_wday;
|
|
124
|
+
min = 0;
|
|
125
|
+
@@ -154,6 +208,32 @@ char *strptime(const char *restrict s, const char *restrict f, struct tm *restri
|
|
126
|
+
adj = 1900;
|
|
127
|
+
want_century = 0;
|
|
128
|
+
goto numeric_digits;
|
|
129
|
+
+ case 'z':
|
|
130
|
+
+ /* ecmaOS: Z, +hh and +hh:mm too, as glibc takes
|
|
131
|
+
+ * them, where musl takes only +hhmm. */
|
|
132
|
+
+ if (*s == 'Z') {
|
|
133
|
+
+ tm->__tm_gmtoff = 0;
|
|
134
|
+
+ s++;
|
|
135
|
+
+ break;
|
|
136
|
+
+ }
|
|
137
|
+
+ if (*s == '+') neg = 0;
|
|
138
|
+
+ else if (*s == '-') neg = 1;
|
|
139
|
+
+ else return 0;
|
|
140
|
+
+ if (!isdigit(s[1]) || !isdigit(s[2])) return 0;
|
|
141
|
+
+ tm->__tm_gmtoff = (s[1]-'0')*36000+(s[2]-'0')*3600;
|
|
142
|
+
+ s += 3;
|
|
143
|
+
+ if (*s == ':' && isdigit(s[1]) && isdigit(s[2])) s++;
|
|
144
|
+
+ if (isdigit(s[0]) && isdigit(s[1])) {
|
|
145
|
+
+ if (s[0] > '5') return 0;
|
|
146
|
+
+ tm->__tm_gmtoff += (s[0]-'0')*600 + (s[1]-'0')*60;
|
|
147
|
+
+ s += 2;
|
|
148
|
+
+ }
|
|
149
|
+
+ if (neg) tm->__tm_gmtoff = -tm->__tm_gmtoff;
|
|
150
|
+
+ break;
|
|
151
|
+
+ case 'Z':
|
|
152
|
+
+ i = __tzname_to_isdst(&s);
|
|
153
|
+
+ if (i>=0) tm->tm_isdst = i;
|
|
154
|
+
+ break;
|
|
155
|
+
case '%':
|
|
156
|
+
if (*s++ != '%') return 0;
|
|
157
|
+
break;
|
|
158
|
+
diff --git i/src/time/time_impl.h w/src/time/time_impl.h
|
|
159
|
+
index f26d800..ffe5050 100644
|
|
160
|
+
--- i/src/time/time_impl.h
|
|
161
|
+
+++ w/src/time/time_impl.h
|
|
162
|
+
@@ -5,6 +5,7 @@ hidden int __month_to_secs(int, int);
|
|
163
|
+
hidden long long __year_to_secs(long long, int *);
|
|
164
|
+
hidden long long __tm_to_secs(const struct tm *);
|
|
165
|
+
hidden const char *__tm_to_tzname(const struct tm *);
|
|
166
|
+
+hidden int __tzname_to_isdst(const char *restrict *);
|
|
167
|
+
hidden int __secs_to_tm(long long, struct tm *);
|
|
168
|
+
hidden void __secs_to_zone(long long, int, int *, long *, long *, const char **);
|
|
169
|
+
hidden const char *__strftime_fmt_1(char (*)[100], size_t *, int, const struct tm *, locale_t, int);
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
wordexp as musl has it since 1.2.5, on 0007's posix_spawn: the shell's stderr is /dev/null through a file action
|
|
2
|
+
(235f7289), where `2>/dev/null` went in as $2, so expanding $2, $* or $@ gave it as a word; the eval clears the
|
|
3
|
+
positional parameters first (331cf270), so $1 and $# say there are none; and a word is freed when the vector cannot
|
|
4
|
+
grow for it (38e04447).
|
|
5
|
+
|
|
6
|
+
diff --git i/src/misc/wordexp.c w/src/misc/wordexp.c
|
|
7
|
+
index 8eb2f68..2864ea4 100644
|
|
8
|
+
--- i/src/misc/wordexp.c
|
|
9
|
+
+++ w/src/misc/wordexp.c
|
|
10
|
+
@@ -32,7 +32,6 @@ static int do_wordexp(const char *s, wordexp_t *we, int flags)
|
|
11
|
+
int sq=0, dq=0;
|
|
12
|
+
size_t np=0;
|
|
13
|
+
char *w, **tmp;
|
|
14
|
+
- char *redir = (flags & WRDE_SHOWERR) ? "" : "2>/dev/null";
|
|
15
|
+
int err = 0;
|
|
16
|
+
FILE *f;
|
|
17
|
+
size_t wc = 0;
|
|
18
|
+
@@ -107,9 +106,11 @@ static int do_wordexp(const char *s, wordexp_t *we, int flags)
|
|
19
|
+
goto nospace;
|
|
20
|
+
}
|
|
21
|
+
posix_spawn_file_actions_adddup2(&fa, p[1], 1);
|
|
22
|
+
+ if (!(flags & WRDE_SHOWERR))
|
|
23
|
+
+ posix_spawn_file_actions_addopen(&fa, 2, "/dev/null", O_WRONLY, 0);
|
|
24
|
+
int spawned = posix_spawn(&pid, "/bin/sh", &fa, 0, (char *[]){ "sh", "-c",
|
|
25
|
+
- "eval \"printf %s\\\\\\\\0 x $1 $2\"",
|
|
26
|
+
- "sh", (char *)s, (char *)redir, 0 }, __environ);
|
|
27
|
+
+ "eval \"set --;printf %s\\\\\\\\0 x $1\"",
|
|
28
|
+
+ "sh", (char *)s, 0 }, __environ);
|
|
29
|
+
posix_spawn_file_actions_destroy(&fa);
|
|
30
|
+
if (spawned) {
|
|
31
|
+
close(p[0]);
|
|
32
|
+
@@ -139,7 +140,10 @@ static int do_wordexp(const char *s, wordexp_t *we, int flags)
|
|
33
|
+
if (i+1 >= l) {
|
|
34
|
+
l += l/2+10;
|
|
35
|
+
tmp = realloc(wv, l*sizeof(char *));
|
|
36
|
+
- if (!tmp) break;
|
|
37
|
+
+ if (!tmp) {
|
|
38
|
+
+ free(w);
|
|
39
|
+
+ break;
|
|
40
|
+
+ }
|
|
41
|
+
wv = tmp;
|
|
42
|
+
}
|
|
43
|
+
wv[i++] = w;
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
long double is clang's on this target, IEEE quad (113-bit mantissa, as on aarch64 and riscv64): bits/float.h said
|
|
2
|
+
x86-64's 80-bit format, so libm's long double functions (fabsl, frexpl, sqrtl, ...) took its bytes as that layout,
|
|
3
|
+
and WALI turned printf's and scanf's long double off (strtold and %Lf ended the program with SIGABRT). float.h is
|
|
4
|
+
aarch64's now. printf and scanf still work in double, as WALI had them, since long double arithmetic is software here
|
|
5
|
+
(printing and parsing doubles in it took two and a half times as long); a second build of each in long double
|
|
6
|
+
(floatscan_ld.c, vfprintf_ld.c, vfwprintf_ld.c) takes strtold, wcstold, scanf's %Lf and a format with an L in it.
|
|
7
|
+
|
|
8
|
+
diff --git i/arch/wasm32/bits/float.h w/arch/wasm32/bits/float.h
|
|
9
|
+
index 04aaae7..4b81bff 100644
|
|
10
|
+
--- i/arch/wasm32/bits/float.h
|
|
11
|
+
+++ w/arch/wasm32/bits/float.h
|
|
12
|
+
@@ -1,20 +1,18 @@
|
|
13
|
+
-/* X86-64 uses 80-bit long double, aarch64 uses 128-bit long double
|
|
14
|
+
-* For now, long double is disabled in WALI as non-standard
|
|
15
|
+
-* This is the x86-64 float bits */
|
|
16
|
+
-
|
|
17
|
+
+/* ecmaOS: clang's long double on this target is IEEE quad (__LDBL_MANT_DIG__ 113), as aarch64's is, and these
|
|
18
|
+
+ * are aarch64's values; WALI had x86-64's 80-bit ones here, which made libm read a long double as the 80-bit format */
|
|
19
|
+
#define FLT_EVAL_METHOD 0
|
|
20
|
+
|
|
21
|
+
-#define LDBL_TRUE_MIN 3.6451995318824746025e-4951L
|
|
22
|
+
-#define LDBL_MIN 3.3621031431120935063e-4932L
|
|
23
|
+
-#define LDBL_MAX 1.1897314953572317650e+4932L
|
|
24
|
+
-#define LDBL_EPSILON 1.0842021724855044340e-19L
|
|
25
|
+
+#define LDBL_TRUE_MIN 6.47517511943802511092443895822764655e-4966L
|
|
26
|
+
+#define LDBL_MIN 3.36210314311209350626267781732175260e-4932L
|
|
27
|
+
+#define LDBL_MAX 1.18973149535723176508575932662800702e+4932L
|
|
28
|
+
+#define LDBL_EPSILON 1.92592994438723585305597794258492732e-34L
|
|
29
|
+
|
|
30
|
+
-#define LDBL_MANT_DIG 64
|
|
31
|
+
+#define LDBL_MANT_DIG 113
|
|
32
|
+
#define LDBL_MIN_EXP (-16381)
|
|
33
|
+
#define LDBL_MAX_EXP 16384
|
|
34
|
+
|
|
35
|
+
-#define LDBL_DIG 18
|
|
36
|
+
+#define LDBL_DIG 33
|
|
37
|
+
#define LDBL_MIN_10_EXP (-4931)
|
|
38
|
+
#define LDBL_MAX_10_EXP 4932
|
|
39
|
+
|
|
40
|
+
-#define DECIMAL_DIG 21
|
|
41
|
+
+#define DECIMAL_DIG 36
|
|
42
|
+
diff --git i/src/internal/floatscan.h w/src/internal/floatscan.h
|
|
43
|
+
index 312da0a..164a40c 100644
|
|
44
|
+
--- i/src/internal/floatscan.h
|
|
45
|
+
+++ w/src/internal/floatscan.h
|
|
46
|
+
@@ -5,5 +5,6 @@
|
|
47
|
+
#include <private/printscan.h>
|
|
48
|
+
|
|
49
|
+
hidden long_double_pr_t __floatscan(FILE *, int, int);
|
|
50
|
+
+hidden long double __floatscan_ld(FILE *, int, int);
|
|
51
|
+
|
|
52
|
+
#endif
|
|
53
|
+
diff --git i/src/internal/floatscan_ld.c w/src/internal/floatscan_ld.c
|
|
54
|
+
new file mode 100644
|
|
55
|
+
index 0000000..b9ee72a
|
|
56
|
+
--- /dev/null
|
|
57
|
+
+++ w/src/internal/floatscan_ld.c
|
|
58
|
+
@@ -0,0 +1,5 @@
|
|
59
|
+
+/* ecmaOS: floatscan in long double, for strtold, wcstold and scanf's %Lf; __floatscan works in double (see
|
|
60
|
+
+ * private/printscan.h), as long double arithmetic is software here */
|
|
61
|
+
+#define __wali_printscan_enable_long_double
|
|
62
|
+
+#define __floatscan __floatscan_ld
|
|
63
|
+
+#include "floatscan.c"
|
|
64
|
+
diff --git i/src/stdio/vfprintf.c w/src/stdio/vfprintf.c
|
|
65
|
+
index 2685b80..f70f1c5 100644
|
|
66
|
+
--- i/src/stdio/vfprintf.c
|
|
67
|
+
+++ w/src/stdio/vfprintf.c
|
|
68
|
+
@@ -659,8 +659,17 @@ overflow:
|
|
69
|
+
return -1;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
+#if !defined(__wali_printscan_enable_long_double)
|
|
73
|
+
+hidden int __vfprintf_ld(FILE *restrict, const char *restrict, va_list);
|
|
74
|
+
+#endif
|
|
75
|
+
+
|
|
76
|
+
int vfprintf(FILE *restrict f, const char *restrict fmt, va_list ap)
|
|
77
|
+
{
|
|
78
|
+
+#if !defined(__wali_printscan_enable_long_double)
|
|
79
|
+
+ /* ecmaOS: this one formats in double; a format that may hold a long double goes to the one built in
|
|
80
|
+
+ * long double (vfprintf_ld.c) */
|
|
81
|
+
+ if (strchr(fmt, 'L')) return __vfprintf_ld(f, fmt, ap);
|
|
82
|
+
+#endif
|
|
83
|
+
va_list ap2;
|
|
84
|
+
int nl_type[NL_ARGMAX+1] = {0};
|
|
85
|
+
union arg nl_arg[NL_ARGMAX+1];
|
|
86
|
+
diff --git i/src/stdio/vfprintf_ld.c w/src/stdio/vfprintf_ld.c
|
|
87
|
+
new file mode 100644
|
|
88
|
+
index 0000000..4d8e3b9
|
|
89
|
+
--- /dev/null
|
|
90
|
+
+++ w/src/stdio/vfprintf_ld.c
|
|
91
|
+
@@ -0,0 +1,5 @@
|
|
92
|
+
+/* ecmaOS: vfprintf in long double, which vfprintf hands a format with an L to; vfprintf works in double (see
|
|
93
|
+
+ * private/printscan.h), as long double arithmetic is software here */
|
|
94
|
+
+#define __wali_printscan_enable_long_double
|
|
95
|
+
+#define vfprintf __vfprintf_ld
|
|
96
|
+
+#include "vfprintf.c"
|
|
97
|
+
diff --git i/src/stdio/vfscanf.c w/src/stdio/vfscanf.c
|
|
98
|
+
index 3bd92ad..4789e3d 100644
|
|
99
|
+
--- i/src/stdio/vfscanf.c
|
|
100
|
+
+++ w/src/stdio/vfscanf.c
|
|
101
|
+
@@ -302,6 +302,13 @@ int vfscanf(FILE *restrict f, const char *restrict fmt, va_list ap)
|
|
102
|
+
case 'e': case 'E':
|
|
103
|
+
case 'f': case 'F':
|
|
104
|
+
case 'g': case 'G':
|
|
105
|
+
+ /* ecmaOS: %Lf is scanned in long double, the others in double */
|
|
106
|
+
+ if (size == SIZE_L) {
|
|
107
|
+
+ long double z = __floatscan_ld(f, size, 0);
|
|
108
|
+
+ if (!shcnt(f)) goto match_fail;
|
|
109
|
+
+ if (dest) *(long double *)dest = z;
|
|
110
|
+
+ break;
|
|
111
|
+
+ }
|
|
112
|
+
y = __floatscan(f, size, 0);
|
|
113
|
+
if (!shcnt(f)) goto match_fail;
|
|
114
|
+
if (dest) switch (size) {
|
|
115
|
+
diff --git i/src/stdio/vfwprintf.c w/src/stdio/vfwprintf.c
|
|
116
|
+
index 872fdf6..dd23db6 100644
|
|
117
|
+
--- i/src/stdio/vfwprintf.c
|
|
118
|
+
+++ w/src/stdio/vfwprintf.c
|
|
119
|
+
@@ -370,8 +370,16 @@ overflow:
|
|
120
|
+
return -1;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
+#if !defined(__wali_printscan_enable_long_double)
|
|
124
|
+
+hidden int __vfwprintf_ld(FILE *restrict, const wchar_t *restrict, va_list);
|
|
125
|
+
+#endif
|
|
126
|
+
+
|
|
127
|
+
int vfwprintf(FILE *restrict f, const wchar_t *restrict fmt, va_list ap)
|
|
128
|
+
{
|
|
129
|
+
+#if !defined(__wali_printscan_enable_long_double)
|
|
130
|
+
+ /* ecmaOS: as vfprintf, a format that may hold a long double goes to vfwprintf_ld.c's */
|
|
131
|
+
+ if (wcschr(fmt, L'L')) return __vfwprintf_ld(f, fmt, ap);
|
|
132
|
+
+#endif
|
|
133
|
+
va_list ap2;
|
|
134
|
+
int nl_type[NL_ARGMAX] = {0};
|
|
135
|
+
union arg nl_arg[NL_ARGMAX];
|
|
136
|
+
diff --git i/src/stdio/vfwprintf_ld.c w/src/stdio/vfwprintf_ld.c
|
|
137
|
+
new file mode 100644
|
|
138
|
+
index 0000000..d06b549
|
|
139
|
+
--- /dev/null
|
|
140
|
+
+++ w/src/stdio/vfwprintf_ld.c
|
|
141
|
+
@@ -0,0 +1,4 @@
|
|
142
|
+
+/* ecmaOS: vfwprintf in long double, which vfwprintf hands a format with an L to (see vfprintf_ld.c) */
|
|
143
|
+
+#define __wali_printscan_enable_long_double
|
|
144
|
+
+#define vfwprintf __vfwprintf_ld
|
|
145
|
+
+#include "vfwprintf.c"
|
|
146
|
+
diff --git i/src/stdlib/strtod.c w/src/stdlib/strtod.c
|
|
147
|
+
index 1045779..5d2b79d 100644
|
|
148
|
+
--- i/src/stdlib/strtod.c
|
|
149
|
+
+++ w/src/stdlib/strtod.c
|
|
150
|
+
@@ -26,9 +26,12 @@ double strtod(const char *restrict s, char **restrict p)
|
|
151
|
+
|
|
152
|
+
long double strtold(const char *restrict s, char **restrict p)
|
|
153
|
+
{
|
|
154
|
+
-#if !defined(__wali_printscan_enable_long_double)
|
|
155
|
+
- long_double_not_supported();
|
|
156
|
+
-#else
|
|
157
|
+
- return strtox(s, p, 2);
|
|
158
|
+
-#endif
|
|
159
|
+
+ /* ecmaOS: strtox's floatscan works in double; this one in long double */
|
|
160
|
+
+ FILE f;
|
|
161
|
+
+ sh_fromstring(&f, s);
|
|
162
|
+
+ shlim(&f, 0);
|
|
163
|
+
+ long double y = __floatscan_ld(&f, 2, 1);
|
|
164
|
+
+ off_t cnt = shcnt(&f);
|
|
165
|
+
+ if (p) *p = cnt ? (char *)s + cnt : (char *)s;
|
|
166
|
+
+ return y;
|
|
167
|
+
}
|
|
168
|
+
diff --git i/src/stdlib/wcstod.c w/src/stdlib/wcstod.c
|
|
169
|
+
index cbcbbc8..498395a 100644
|
|
170
|
+
--- i/src/stdlib/wcstod.c
|
|
171
|
+
+++ w/src/stdlib/wcstod.c
|
|
172
|
+
@@ -27,7 +27,9 @@ static size_t do_read(FILE *f, unsigned char *buf, size_t len)
|
|
173
|
+
return 0;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
-static long_double_pr_t wcstox(const wchar_t *s, wchar_t **p, int prec)
|
|
177
|
+
+/* ecmaOS: __floatscan works in double, __floatscan_ld in long double, for wcstold */
|
|
178
|
+
+#define wcstox(s, p, prec) ((long_double_pr_t)wcstox_with(s, p, prec, 0))
|
|
179
|
+
+static long double wcstox_with(const wchar_t *s, wchar_t **p, int prec, int ld)
|
|
180
|
+
{
|
|
181
|
+
wchar_t *t = (wchar_t *)s;
|
|
182
|
+
unsigned char buf[64];
|
|
183
|
+
@@ -40,7 +42,7 @@ static long_double_pr_t wcstox(const wchar_t *s, wchar_t **p, int prec)
|
|
184
|
+
while (iswspace(*t)) t++;
|
|
185
|
+
f.cookie = (void *)t;
|
|
186
|
+
shlim(&f, 0);
|
|
187
|
+
- long_double_pr_t y = __floatscan(&f, prec, 1);
|
|
188
|
+
+ long double y = ld ? __floatscan_ld(&f, prec, 1) : __floatscan(&f, prec, 1);
|
|
189
|
+
if (p) {
|
|
190
|
+
size_t cnt = shcnt(&f);
|
|
191
|
+
*p = cnt ? t + cnt : (wchar_t *)s;
|
|
192
|
+
@@ -60,9 +62,5 @@ double wcstod(const wchar_t *restrict s, wchar_t **restrict p)
|
|
193
|
+
|
|
194
|
+
long double wcstold(const wchar_t *restrict s, wchar_t **restrict p)
|
|
195
|
+
{
|
|
196
|
+
-#if !defined(__wali_printscan_enable_long_double)
|
|
197
|
+
- long_double_not_supported();
|
|
198
|
+
-#else
|
|
199
|
+
- return wcstox(s, p, 2);
|
|
200
|
+
-#endif
|
|
201
|
+
+ return wcstox_with(s, p, 2, 1);
|
|
202
|
+
}
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
wordexp's WRDE_NOCMD check reads the words as the shell will (musl's scans for characters, so it took a { or } in
|
|
2
|
+
${x-{}, a ( in $((...)) or a quoted one for an operator, and missed a command substitution in $(( ) ...)): quotes,
|
|
3
|
+
${...} words, quoted as the expansion is except a pattern's, $((...)), $'...', comments and line continuations.
|
|
4
|
+
WRDE_UNDEF is set -u, and the shell parses the words before it expands them, writing a marker in between, so a
|
|
5
|
+
syntax error (no marker) is told from an expansion that failed (no words after it), WRDE_BADVAL with WRDE_UNDEF.
|
|
6
|
+
|
|
7
|
+
diff --git i/src/misc/wordexp.c w/src/misc/wordexp.c
|
|
8
|
+
index 2864ea4..4637b45 100644
|
|
9
|
+
--- i/src/misc/wordexp.c
|
|
10
|
+
+++ w/src/misc/wordexp.c
|
|
11
|
+
@@ -10,6 +10,7 @@
|
|
12
|
+
#include <errno.h>
|
|
13
|
+
#include <spawn.h>
|
|
14
|
+
#include <fcntl.h>
|
|
15
|
+
+#include <ctype.h>
|
|
16
|
+
#include "pthread_impl.h"
|
|
17
|
+
|
|
18
|
+
extern char **__environ;
|
|
19
|
+
@@ -26,11 +27,179 @@ static char *getword(FILE *f)
|
|
20
|
+
return getdelim(&s, (size_t [1]){0}, 0, f) < 0 ? 0 : s;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
+/* ecmaOS: WRDE_NOCMD's check reads the words as the shell will: quotes, ${...} words (whose quoting follows the
|
|
24
|
+
+ * expansion's, except a pattern's, read unquoted), $((...)) (a command substitution after all when its parentheses
|
|
25
|
+
+ * close as `) ...`), $'...', comments and line continuations. A command substitution is WRDE_CMDSUB, an unquoted
|
|
26
|
+
+ * operator character WRDE_BADCHAR, and what never closes WRDE_SYNTAX. */
|
|
27
|
+
+enum { TOP, DQ, BRACE, BRACE_DQ, ARITH };
|
|
28
|
+
+
|
|
29
|
+
+static const char *nocmd_dollar(const char *s, int ctx, int *err);
|
|
30
|
+
+
|
|
31
|
+
+static const char *nocmd_squote(const char *s, int *err)
|
|
32
|
+
+{
|
|
33
|
+
+ const char *end = strchr(s+1, '\'');
|
|
34
|
+
+ if (!end) *err = WRDE_SYNTAX;
|
|
35
|
+
+ return end ? end+1 : 0;
|
|
36
|
+
+}
|
|
37
|
+
+
|
|
38
|
+
+static const char *nocmd_dquote(const char *s, int *err)
|
|
39
|
+
+{
|
|
40
|
+
+ for (s++; *s != '"'; ) switch (*s) {
|
|
41
|
+
+ case 0:
|
|
42
|
+
+ *err = WRDE_SYNTAX;
|
|
43
|
+
+ return 0;
|
|
44
|
+
+ case '\\':
|
|
45
|
+
+ if (!s[1]) return *err = WRDE_SYNTAX, (char *)0;
|
|
46
|
+
+ s += 2;
|
|
47
|
+
+ break;
|
|
48
|
+
+ case '`':
|
|
49
|
+
+ return *err = WRDE_CMDSUB, (char *)0;
|
|
50
|
+
+ case '$':
|
|
51
|
+
+ if (!(s = nocmd_dollar(s, DQ, err))) return 0;
|
|
52
|
+
+ break;
|
|
53
|
+
+ default:
|
|
54
|
+
+ s++;
|
|
55
|
+
+ }
|
|
56
|
+
+ return s+1;
|
|
57
|
+
+}
|
|
58
|
+
+
|
|
59
|
+
+static const char *nocmd_brace(const char *s, int dq, int *err)
|
|
60
|
+
+{
|
|
61
|
+
+ /* the word of ${name#word} and ${name%word} is a pattern, read unquoted inside double quotes too */
|
|
62
|
+
+ const char *p = s + (*s == '#' && s[1] != '}');
|
|
63
|
+
+ if (isalpha(*p) || *p == '_') while (isalnum(*p) || *p == '_') p++;
|
|
64
|
+
+ else if (isdigit(*p)) while (isdigit(*p)) p++;
|
|
65
|
+
+ else if (*p && strchr("@*#?-$!", *p)) p++;
|
|
66
|
+
+ if (*p == '#' || *p == '%') dq = 0;
|
|
67
|
+
+
|
|
68
|
+
+ while (*s != '}') switch (*s) {
|
|
69
|
+
+ case 0:
|
|
70
|
+
+ return *err = WRDE_SYNTAX, (char *)0;
|
|
71
|
+
+ case '\\':
|
|
72
|
+
+ if (!s[1]) return *err = WRDE_SYNTAX, (char *)0;
|
|
73
|
+
+ s += 2;
|
|
74
|
+
+ break;
|
|
75
|
+
+ case '\'':
|
|
76
|
+
+ if (dq) { s++; break; }
|
|
77
|
+
+ if (!(s = nocmd_squote(s, err))) return 0;
|
|
78
|
+
+ break;
|
|
79
|
+
+ case '"':
|
|
80
|
+
+ if (!(s = nocmd_dquote(s, err))) return 0;
|
|
81
|
+
+ break;
|
|
82
|
+
+ case '`':
|
|
83
|
+
+ return *err = WRDE_CMDSUB, (char *)0;
|
|
84
|
+
+ case '$':
|
|
85
|
+
+ if (!(s = nocmd_dollar(s, dq ? BRACE_DQ : BRACE, err))) return 0;
|
|
86
|
+
+ break;
|
|
87
|
+
+ default:
|
|
88
|
+
+ s++;
|
|
89
|
+
+ }
|
|
90
|
+
+ return s+1;
|
|
91
|
+
+}
|
|
92
|
+
+
|
|
93
|
+
+static const char *nocmd_arith(const char *s, int *err)
|
|
94
|
+
+{
|
|
95
|
+
+ size_t depth = 0;
|
|
96
|
+
+ for (;;) switch (*s) {
|
|
97
|
+
+ case 0:
|
|
98
|
+
+ case '#':
|
|
99
|
+
+ case '"':
|
|
100
|
+
+ case '\'':
|
|
101
|
+
+ case '\\':
|
|
102
|
+
+ return *err = WRDE_SYNTAX, (char *)0;
|
|
103
|
+
+ case '(':
|
|
104
|
+
+ depth++;
|
|
105
|
+
+ s++;
|
|
106
|
+
+ break;
|
|
107
|
+
+ case ')':
|
|
108
|
+
+ if (depth) { depth--; s++; break; }
|
|
109
|
+
+ if (s[1] == ')') return s+2;
|
|
110
|
+
+ /* $( (...) ...): a command substitution beginning with a subshell */
|
|
111
|
+
+ return *err = WRDE_CMDSUB, (char *)0;
|
|
112
|
+
+ case '`':
|
|
113
|
+
+ return *err = WRDE_CMDSUB, (char *)0;
|
|
114
|
+
+ case '{':
|
|
115
|
+
+ case '}':
|
|
116
|
+
+ return *err = WRDE_BADCHAR, (char *)0;
|
|
117
|
+
+ case '$':
|
|
118
|
+
+ if (!(s = nocmd_dollar(s, ARITH, err))) return 0;
|
|
119
|
+
+ break;
|
|
120
|
+
+ default:
|
|
121
|
+
+ s++;
|
|
122
|
+
+ }
|
|
123
|
+
+}
|
|
124
|
+
+
|
|
125
|
+
+static const char *nocmd_dollar(const char *s, int ctx, int *err)
|
|
126
|
+
+{
|
|
127
|
+
+ switch (s[1]) {
|
|
128
|
+
+ case '(':
|
|
129
|
+
+ if (s[2] == '(') return nocmd_arith(s+3, err);
|
|
130
|
+
+ return *err = WRDE_CMDSUB, (char *)0;
|
|
131
|
+
+ case '{':
|
|
132
|
+
+ return nocmd_brace(s+2, ctx == DQ || ctx == BRACE_DQ, err);
|
|
133
|
+
+ case '\'':
|
|
134
|
+
+ /* $'...' quotes at the top; in double quotes it is a dollar sign; in ${...} and $((...)) shells differ */
|
|
135
|
+
+ if (ctx == DQ) return s+1;
|
|
136
|
+
+ if (ctx != TOP) return *err = WRDE_SYNTAX, (char *)0;
|
|
137
|
+
+ for (s += 2; *s != '\''; s++) {
|
|
138
|
+
+ if (!*s || (*s == '\\' && !*++s)) return *err = WRDE_SYNTAX, (char *)0;
|
|
139
|
+
+ }
|
|
140
|
+
+ return s+1;
|
|
141
|
+
+ }
|
|
142
|
+
+ return s+1;
|
|
143
|
+
+}
|
|
144
|
+
+
|
|
145
|
+
+static int nocmd(const char *s)
|
|
146
|
+
+{
|
|
147
|
+
+ int err = 0, start = 1;
|
|
148
|
+
+ while (*s) {
|
|
149
|
+
+ if (*s == '\\' && s[1] == '\n') { s += 2; continue; }
|
|
150
|
+
+ if (*s == '#' && start) {
|
|
151
|
+
+ while (*s && *s != '\n') s++;
|
|
152
|
+
+ continue;
|
|
153
|
+
+ }
|
|
154
|
+
+ start = 0;
|
|
155
|
+
+ switch (*s) {
|
|
156
|
+
+ case ' ':
|
|
157
|
+
+ case '\t':
|
|
158
|
+
+ start = 1;
|
|
159
|
+
+ s++;
|
|
160
|
+
+ break;
|
|
161
|
+
+ case '\\':
|
|
162
|
+
+ s += 1 + !!s[1];
|
|
163
|
+
+ break;
|
|
164
|
+
+ case '\'':
|
|
165
|
+
+ if (!(s = nocmd_squote(s, &err))) return err;
|
|
166
|
+
+ break;
|
|
167
|
+
+ case '"':
|
|
168
|
+
+ if (!(s = nocmd_dquote(s, &err))) return err;
|
|
169
|
+
+ break;
|
|
170
|
+
+ case '$':
|
|
171
|
+
+ if (!(s = nocmd_dollar(s, TOP, &err))) return err;
|
|
172
|
+
+ break;
|
|
173
|
+
+ case '`':
|
|
174
|
+
+ return WRDE_CMDSUB;
|
|
175
|
+
+ case '\n':
|
|
176
|
+
+ case '|':
|
|
177
|
+
+ case '&':
|
|
178
|
+
+ case ';':
|
|
179
|
+
+ case '<':
|
|
180
|
+
+ case '>':
|
|
181
|
+
+ case '(':
|
|
182
|
+
+ case ')':
|
|
183
|
+
+ case '{':
|
|
184
|
+
+ case '}':
|
|
185
|
+
+ return WRDE_BADCHAR;
|
|
186
|
+
+ default:
|
|
187
|
+
+ s++;
|
|
188
|
+
+ }
|
|
189
|
+
+ }
|
|
190
|
+
+ return 0;
|
|
191
|
+
+}
|
|
192
|
+
+
|
|
193
|
+
static int do_wordexp(const char *s, wordexp_t *we, int flags)
|
|
194
|
+
{
|
|
195
|
+
size_t i, l;
|
|
196
|
+
- int sq=0, dq=0;
|
|
197
|
+
- size_t np=0;
|
|
198
|
+
char *w, **tmp;
|
|
199
|
+
int err = 0;
|
|
200
|
+
FILE *f;
|
|
201
|
+
@@ -41,46 +210,9 @@ static int do_wordexp(const char *s, wordexp_t *we, int flags)
|
|
202
|
+
|
|
203
|
+
if (flags & WRDE_REUSE) wordfree(we);
|
|
204
|
+
|
|
205
|
+
- if (flags & WRDE_NOCMD) for (i=0; s[i]; i++) switch (s[i]) {
|
|
206
|
+
- case '\\':
|
|
207
|
+
- if (!sq && !s[++i]) return WRDE_SYNTAX;
|
|
208
|
+
- break;
|
|
209
|
+
- case '\'':
|
|
210
|
+
- if (!dq) sq^=1;
|
|
211
|
+
- break;
|
|
212
|
+
- case '"':
|
|
213
|
+
- if (!sq) dq^=1;
|
|
214
|
+
- break;
|
|
215
|
+
- case '(':
|
|
216
|
+
- if (np) {
|
|
217
|
+
- np++;
|
|
218
|
+
- break;
|
|
219
|
+
- }
|
|
220
|
+
- case ')':
|
|
221
|
+
- if (np) {
|
|
222
|
+
- np--;
|
|
223
|
+
- break;
|
|
224
|
+
- }
|
|
225
|
+
- case '\n':
|
|
226
|
+
- case '|':
|
|
227
|
+
- case '&':
|
|
228
|
+
- case ';':
|
|
229
|
+
- case '<':
|
|
230
|
+
- case '>':
|
|
231
|
+
- case '{':
|
|
232
|
+
- case '}':
|
|
233
|
+
- if (!(sq|dq|np)) return WRDE_BADCHAR;
|
|
234
|
+
- break;
|
|
235
|
+
- case '$':
|
|
236
|
+
- if (sq) break;
|
|
237
|
+
- if (s[i+1]=='(' && s[i+2]=='(') {
|
|
238
|
+
- i += 2;
|
|
239
|
+
- np += 2;
|
|
240
|
+
- break;
|
|
241
|
+
- } else if (s[i+1] != '(') break;
|
|
242
|
+
- case '`':
|
|
243
|
+
- if (sq) break;
|
|
244
|
+
- return WRDE_CMDSUB;
|
|
245
|
+
+ if (flags & WRDE_NOCMD) {
|
|
246
|
+
+ err = nocmd(s);
|
|
247
|
+
+ if (err) return err;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
if (flags & WRDE_APPEND) {
|
|
251
|
+
@@ -108,8 +240,13 @@ static int do_wordexp(const char *s, wordexp_t *we, int flags)
|
|
252
|
+
posix_spawn_file_actions_adddup2(&fa, p[1], 1);
|
|
253
|
+
if (!(flags & WRDE_SHOWERR))
|
|
254
|
+
posix_spawn_file_actions_addopen(&fa, 2, "/dev/null", O_WRONLY, 0);
|
|
255
|
+
+ /* ecmaOS: the words are parsed first, in a branch never taken, and a marker written once they parse, so a
|
|
256
|
+
+ * syntax error (no marker) is told from a failed expansion (no words after it), which with WRDE_UNDEF is set -u's
|
|
257
|
+
+ * WRDE_BADVAL */
|
|
258
|
+
int spawned = posix_spawn(&pid, "/bin/sh", &fa, 0, (char *[]){ "sh", "-c",
|
|
259
|
+
- "eval \"set --;printf %s\\\\\\\\0 x $1\"",
|
|
260
|
+
+ (flags & WRDE_UNDEF)
|
|
261
|
+
+ ? "eval \"if false; then : $1\nfi\" || exit; printf %s\\\\0 p; set -u; eval \"set --;printf %s\\\\\\\\0 x $1\""
|
|
262
|
+
+ : "eval \"if false; then : $1\nfi\" || exit; printf %s\\\\0 p; eval \"set --;printf %s\\\\\\\\0 x $1\"",
|
|
263
|
+
"sh", (char *)s, 0 }, __environ);
|
|
264
|
+
posix_spawn_file_actions_destroy(&fa);
|
|
265
|
+
if (spawned) {
|
|
266
|
+
@@ -129,11 +266,14 @@ static int do_wordexp(const char *s, wordexp_t *we, int flags)
|
|
267
|
+
|
|
268
|
+
l = wv ? i+1 : 0;
|
|
269
|
+
|
|
270
|
+
- free(getword(f));
|
|
271
|
+
- if (feof(f)) {
|
|
272
|
+
- fclose(f);
|
|
273
|
+
- reap(pid);
|
|
274
|
+
- return WRDE_SYNTAX;
|
|
275
|
+
+ /* the words parsed: "p"; they expanded: "x" */
|
|
276
|
+
+ for (int marker = 0; marker < 2; marker++) {
|
|
277
|
+
+ free(getword(f));
|
|
278
|
+
+ if (feof(f)) {
|
|
279
|
+
+ fclose(f);
|
|
280
|
+
+ reap(pid);
|
|
281
|
+
+ return marker && (flags & WRDE_UNDEF) ? WRDE_BADVAL : WRDE_SYNTAX;
|
|
282
|
+
+ }
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
while ((w = getword(f))) {
|