aboutsummaryrefslogtreecommitdiff
path: root/timed_getch.pl
diff options
context:
space:
mode:
authorB. Watson <yalhcru@gmail.com>2015-12-29 23:10:50 -0500
committerB. Watson <yalhcru@gmail.com>2015-12-29 23:10:50 -0500
commit2300d2813a524cbfeabac794335e7abe99263df6 (patch)
treed729ca4f99634788cbb3a2101a5b5854a4bc2d06 /timed_getch.pl
downloadtaipan-2300d2813a524cbfeabac794335e7abe99263df6.tar.gz
initial commit
Diffstat (limited to 'timed_getch.pl')
-rw-r--r--timed_getch.pl48
1 files changed, 48 insertions, 0 deletions
diff --git a/timed_getch.pl b/timed_getch.pl
new file mode 100644
index 0000000..d9f267e
--- /dev/null
+++ b/timed_getch.pl
@@ -0,0 +1,48 @@
+#!/usr/bin/perl -w
+
+# replace this:
+
+# timeout(5000);
+# getch();
+# timeout(-1);
+
+# with this:
+
+# timed_getch(83);
+
+# the 83 comes from int(5000/1000*60)
+
+# indentation levels must be preserved!
+
+while(<>) {
+ my $line = $_;
+ if(/^(\s+)timeout\s*\((\d+)/) {
+ #warn "found timeout($2) at $.\n";
+ my $indent = $1;
+ my $jiffies = int(($2 / 1000) * 60);
+
+ if($jiffies == 60) {
+ $jiffies = "TMOUT_1S";
+ } elsif($jiffies == 180) {
+ $jiffies = "TMOUT_3S";
+ } elsif($jiffies == 300) {
+ $jiffies = "TMOUT_5S";
+ } else {
+ warn "no TMOUT_* constant for $jiffies, line $.\n";
+ }
+
+ my $next = <>;
+ if($next =~ /getch\(\)/) {
+ print $indent . "timed_getch($jiffies);\n";
+ my $last = <>;
+ if($last !~ /timeout\(-1\)/) {
+ print $last;
+ }
+ } else {
+ print $line;
+ print $next;
+ }
+ } else {
+ print $line;
+ }
+}