-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathawk.sh
More file actions
executable file
·156 lines (121 loc) · 3.78 KB
/
awk.sh
File metadata and controls
executable file
·156 lines (121 loc) · 3.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/bin/sh
# help set
# -e Exit immediately if a command exits with a non-zero status.
set -e
trap '[ "$?" -eq 0 ] || echo "!!! ERROR !!!"' EXIT
curl -sL ftp://invisible-island.net/mawk/mawk-1.3.4-20150503.tgz | tar xz && cd mawk-1.3.4-20150503
for alias in 'emcc' 'emconfigure' 'emmake'; do
alias $alias="docker run --rm -v `pwd`:/home/src 42ua/emsdk $alias"
done
unset alias
PS1="(emsdk)$PS1"
sed -i --regexp-extended -e 's/^(x\s+=\s+)@EXEEXT@$/\1.js/' \
-e 's/\.\/makescan\$x\s+>\s+scancode.c$/node &/' Makefile.in
emconfigure ./configure LDFLAGS="-O2 --memory-init-file 0"
emmake make
echo 'NODEENV:'
nodeenv env --prebuilt
. env/bin/activate
sed -i -E 's/^(PROG=")(\$\{MAWK:-\.\.\/mawk\}")$/\1node \2/' test/fpe_test test/mawktest
# cat mawktest.dat | node ../mawk.js "`cat wc.awk`"
sed -i -E \
-e 's/LC_ALL=C \$PROG -f nextfile.awk full-awk.dat \$dat \| cmp -s - nextfile.out \|\| Fail/# &/' \
-e '/^#/!s/(LC_ALL=C \$PROG .*)-f (.+\.awk) ([^ |]+)/cat \3 | \1 "`cat \2`" /' \
-e '/^#/!s/(LC_ALL=C \$PROG .*)-f (.+\.awk) \|/\1 "`cat \2`" |/' \
-e '/^#/!s/(LC_ALL=C \$PROG .*) \$dat \|/cat $dat | \1 |/' \
-e '/^#/!s/(LC_ALL=C \$PROG .*) \$dat >/cat $dat | \1 >/' test/mawktest
echo 'TESTING: make check'
CHECK_STDOUT="`emmake make check`"
if [ "$CHECK_STDOUT" = '** mawk_test
mawk 1.3.4 20150503
Copyright 2008-2014,2015, Thomas E. Dickey
Copyright 1991-1996,2014, Michael D. Brennan
testing input and field splitting
... node /home/src/mawk.js does NOT supports matches with NUL bytes
input and field splitting OK
testing regular expression matching
regular expression matching OK
testing checking for write errors
checking for write errors OK
testing arrays and flow of control
array test OK
testing nextfile
nextfile test OK
testing function calls and general stress test
general stress test OK
tested node /home/src/mawk.js OK
** fpe_test
testing floating point exception handling
testing division by zero
node /home/src/mawk.js BEGIN{ print 4/0 }
inf
testing overflow
node /home/src/mawk.js BEGIN {
x = 100
do { y = x ; x *= 1000 } while ( y != x )
print "loop terminated"
}
loop terminated
testing domain error
node /home/src/mawk.js BEGIN{ print sqrt(-8) }
nan
==============================
return1 = 0
return2 = 0
return3 = 0
results consistent: ignoring floating exceptions' ] ; then
echo "OK"
else
echo ----------------------
echo "$CHECK_STDOUT"
exit 42
fi
node mawk.js -W version
echo 'a test c' | awk '{print $2}'
echo 'a test c' | node mawk.js '{print $2}'
echo 'NPM:'
npm install -g browserify
npm install shell-quote uglifyify
cat <<EOT > mawk_template.js
"use strict";
module.exports = function(input_str, args_arr) {
var Module = {}, window = {};
window.prompt = (function() {
var input = input_str;
return function() {
var value = input;
input = null;
return value;
};
})();
Module['thisProgram'] = 'mawk';
Module['arguments'] = args_arr;
Module['return'] = '';
Module['print'] = Module['printErr'] = function (text) {
Module['return'] += text + '\n';
};
/* MAWK.RAW.JS */
return Module['return'];
};
EOT
# verify conflicts
echo 'assert mawk_template.js has no conflicts:'
! grep -o -E ".{0,10}('return'|\"return\"|\.return\s|input_str|args_arr).{0,10}" mawk.js
sed -i '/\/\* MAWK.RAW.JS \*\// {
r mawk.js
d
}' mawk_template.js
cat <<EOT > main.js
"use strict";
var fn_parse_argc = require('shell-quote').parse,
mawk = require('./mawk_template');
module.exports = function(input_str, args_str) {
return mawk(input_str, fn_parse_argc(args_str));
};
EOT
echo 'BROWSERIFY:'
browserify -g [ uglifyify --ignore '**/mawk_template.js' ] \
main.js --standalone fn_mawk > ../mawk.js
echo 'assert minify skip asm.js:'
grep -E -q "^ Module\['return'\] = '';$" ../mawk.js
grep -E -q "^ Module\['thisProgram'\] = 'mawk';$" ../mawk.js