Skip to content

Commit

Permalink
Use gawk's gettimeofday if available #57
Browse files Browse the repository at this point in the history
  • Loading branch information
xonixx committed Sep 26, 2021
1 parent e978d86 commit 7a74bc3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Makesurefile
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@
@goal stable_version_prepared @private
{
echo '#!/bin/sh'
echo "exec awk -v \"Version=$NEXT_VERSION\" -v \"Prog=\$0\" '"
echo "command -v gawk >/dev/null && AWK='gawk -ltime -v Gawk=1' || AWK=awk"
echo "exec \$AWK -v \"Version=$NEXT_VERSION\" -v \"Prog=\$0\" '"
awk -v Q=\' '
function trim(s) { sub(/^[ \t\r\n]+/, "", s); sub(/[ \t\r\n]+$/, "", s); return s }
/^BEGIN/ { in_begin=1 }
Expand Down
2 changes: 2 additions & 0 deletions makesure.awk
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,8 @@ function topologicalSortPerform(node, result, loop, i, s) {
}

function currentTimeMillis( script, res) {
if (Gawk)
return int(gettimeofday()*1000)
res = executeGetLine("date +%s%3N")
sub(/%?3N/, "000", res) # if date doesn't support %N (macos?) just use second-precision
return +res
Expand Down
5 changes: 4 additions & 1 deletion makesure_stable
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/sh
exec awk -v "Version=0.9.10" -v "Prog=$0" '
command -v gawk >/dev/null && AWK='gawk -ltime -v Gawk=1' || AWK=awk
exec $AWK -v "Version=0.9.10" -v "Prog=$0" '
BEGIN {
Shell = "bash"
SupportedShells["bash"]
Expand Down Expand Up @@ -461,6 +462,8 @@ function topologicalSortPerform(node, result, loop, i, s) {
arrPush(result, node)
}
function currentTimeMillis( script, res) {
if (Gawk)
return int(gettimeofday()*1000)
res = executeGetLine("date +%s%3N")
sub(/%?3N/, "000", res)
return +res
Expand Down

0 comments on commit 7a74bc3

Please sign in to comment.