commit ac92b49aa242a55d0e561480803ff0c44c090fad
parent a469b2a48f9c5a6b2c6f4e4e61b9cec9011fee06
Author: aabacchus <ben@bvnf.space>
Date:   Sun,  5 Jun 2022 23:41:35 +0100
compare file timestamps in uxnsolve
Diffstat:
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/uxnsolve b/uxnsolve
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/sh -e
 
 # desired behaviour
 # shellcheck disable=SC2015
@@ -18,6 +18,15 @@ esac
 debug_file="$1"
 source_file="${1%.debug}"
 
+compare_file_timestamps() {
+    case "$(ls -t "$1" "$1.debug")" in
+        "$1.debug"*) ;;
+        *) printf "\033[1;33mWARNING\033[m: source file is newer than debug info\n" >&2 ;;
+    esac
+}
+
+compare_file_timestamps "$source_file"
+
 address="$(printf "%s" "$2" | tr 'a-f' 'A-F')"
 dec_address="$(printf "16iAo%sp\n" "$address" | dc || kill 0)"
 # add 1 because the zeroth byte is on the first line
@@ -29,7 +38,7 @@ is_integer() {
 }
 
 token="$(sed -n "${dec_address}p" "$debug_file")"
-: "${token:?can\'t find integer from debug file at given byte}"
+: "${token:?cannot find integer from debug file at given byte}"
 is_integer "$token" || {
     printf "can't find an integer token number in %s for byte %X\n" "$debug_file" "$address" >&2
     exit 1
@@ -45,6 +54,7 @@ while read -r line; do
     i="$((i + $#))"
     [ "$i" -ge "$token" ] && {
         printf "line %d: %s\n" "$lineno" "$line"
+        # TODO: highlight the individual token?
         break
     }
 done < "$source_file"