From 38eb8c9b4720e804c477b0c5345b0beb03d088f1 Mon Sep 17 00:00:00 2001 From: Bryson Steck Date: Mon, 17 Oct 2022 15:28:28 -0600 Subject: implement timeout flag, flag checking --- listen | 44 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/listen b/listen index 11c2fc3..886dfb3 100755 --- a/listen +++ b/listen @@ -1,7 +1,5 @@ #!/usr/bin/env perl # TODO: -# implement -r flag -# implement --timeout flag in main loop # possibly create a man page # # listen: a simple configurable build system @@ -52,7 +50,7 @@ sub flags { foreach $arg (@ARGV) { # shorthand args - if ($arg =~ m/-[aosrhv]/) { + if ($arg =~ m/^-[aosrhv]+$/) { if ($arg =~ m/a/) { $ALL_FLAG = "def"; } @@ -146,6 +144,13 @@ sub flags { $ANY_FLAG = "def"; } elsif ($arg =~ m/--run/) { $RUN_FLAG = "def"; + # at this point, either it is an unknown flag or the start of the filename(s) + } elsif ($arg =~ m/^-[^aosrhv]+$/) { + print "listen: Unknown flag: $arg\n"; + exit 2; + } elsif ($arg =~ m/^--[a-z]/) { + print "listen: Unknown flag: $arg\n"; + exit 2; } else { last; } @@ -323,7 +328,13 @@ sub start { # if output differs, mark as modified foreach $modified (@modified_files) { if (@current_epoch[$counter] != @previous_epoch[$counter]) { - $modified = "yes"; + if ($TIMEOUT) { + if (!($current_epoch[$counter] - $previous_epoch[$counter] <= $TIMEOUT)) { + $modified = "yes"; + } + } else { + $modified = "yes"; + } } $counter++; } @@ -342,9 +353,17 @@ sub start { # if output differs, run command foreach (@current_epoch) { if ($current_epoch[$counter] != $previous_epoch[$counter]) { - $run = "def"; - $file_changed = $counter; - last; + if ($TIMEOUT) { + if (!($current_epoch[$counter] - $previous_epoch[$counter] <= $TIMEOUT)) { + $run = "def"; + $file_changed = $counter; + last; + } + } else { + $run = "def"; + $file_changed = $counter; + last; + } } $counter++; } @@ -352,8 +371,15 @@ sub start { # logic for singular files } else { if ($current_epoch[0] != $previous_epoch[0]) { - $run = "def"; - $file_changed = 0; + if ($TIMEOUT) { + if (!($current_epoch[0] - $previous_epoch[0] <= $TIMEOUT)) { + $run = "def"; + $file_changed = 0; + } + } else { + $run = "def"; + $file_changed = 0; + } } } -- cgit v1.2.3