diff options
| author | Marc Vertes <mvertes@free.fr> | 2025-07-29 20:11:46 +0200 |
|---|---|---|
| committer | Marc Vertes <mvertes@free.fr> | 2025-07-29 20:11:46 +0200 |
| commit | 30a3865247db70d55eedb200a2175747f38c4143 (patch) | |
| tree | f283a6fa628e43a611d26bf9265f26612cf168e0 | |
| parent | b4eb1e9ae2fed94726699d5e0a47542dbce5fbc1 (diff) | |
fixup
| -rwxr-xr-x | ev | 9 | ||||
| -rwxr-xr-x | jp | 4 | ||||
| -rwxr-xr-x | xx | 28 |
3 files changed, 34 insertions, 7 deletions
@@ -19,8 +19,7 @@ BEGIN { function scan() { sub(/^[ \t]+/, "", line) - # print "# line: '" line "'" - if (match(line, /^[.0-9]+/)) { + if (match(line, /^[0-9]([.0-9]*(e[+-]*)*[0-9])*/)) { tok = "d" substr(line, 1, RLENGTH) } else if (match(line, /^([][}{)(,+-=?:]|[*\/รท\^])/)) { tok = substr(line, 1, RLENGTH) @@ -31,9 +30,7 @@ function scan() { } else { tok = "b" substr(line, 1, 1) } - # cnum += RLENGTH line = substr(line, RLENGTH+1) - # print "# scan: RLENGTH=" RLENGTH return RLENGTH } @@ -58,7 +55,7 @@ function parse( stack, sl, i) { # for (j = 0; j < i; j++) printf("%s ", code[j]); print "" } -# TODO: assign +# TODO: assign, if, while, function function run( c, i, l, t) { cl = length(code) ml = length(mem) @@ -81,5 +78,5 @@ function run( c, i, l, t) { i++ } print mem[ml] - for (i = ml; i in mem; i++) delete mem[i] + # for (i = ml; i in mem; i++) delete mem[i] } @@ -17,7 +17,7 @@ BEGIN { if (err = parse(v, "", line)) print "parse err: " err for (k in v) print k " " v[k] print "---" - print format(v, "", 0) + print format(v, "", 1) exit ERROR != 0 } else file = ARGV[1] delete ARGV[1] @@ -144,6 +144,7 @@ function format(values, key, indent, id, c, i, s, v, pre, post, sp) { if (i) s = s "," post s = s pre format(values, key SUBSEP i, indent ? indent+1 : 0) } + if (substr(s, length(s)-2, 1) == "[") return id substr(s, 1, length(s)-1) "]" return id s post substr(pre, 3) "]" } if (c == "o") { @@ -154,6 +155,7 @@ function format(values, key, indent, id, c, i, s, v, pre, post, sp) { v = tail(v, SUBSEP) s = s pre "\"" HEAD "\":" sp format(values, key SUBSEP i, indent ? indent+1 : 0) } + if (substr(s, length(s)-2, 1) == "{") return id substr(s, 1, length(s)-1) "}" return id s post substr(pre, 3) "}" } } @@ -0,0 +1,28 @@ +#!/bin/bash + +trap 'stty $ttysave' EXIT INT TERM +ttysave=$(stty -g) + + stty raw -echo + +while true +do + read -n1 char + echo "$char" +done | +awk ' +/q/ {exit} +{printf "[%s]", $0; fflush} +' + +exit + +awk 'BEGIN { + cmd = "dd bs=1 count=1 2>/dev/null" + for (;;) { + cmd | getline ch + close(cmd) + if (ch == "q") exit + printf("[%s]", ch) + } +}' |
