From 325c9fdc00582724345e089f7758c41428e6385d Mon Sep 17 00:00:00 2001 From: Thomas von Dein Date: Mon, 18 Feb 2019 19:22:23 +0100 Subject: [PATCH] +history --- rpnc | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/rpnc b/rpnc index 1d8ca12..0054b62 100755 --- a/rpnc +++ b/rpnc @@ -7,12 +7,12 @@ use Getopt::Long; use strict; use warnings; -my (@stack, @substack, @backup, @subbackup); +my (@stack, @substack, @backup, @subbackup, @hist); my $term = Term::ReadLine->new('rpn calc'); my $debug = 0; my $showstack = 1; my $tty = 1; -my $VERSION = '1.01'; +my $VERSION = '1.02'; my $sub = 0; my $op; @@ -64,6 +64,7 @@ my %commands = ( u => sub { undo(); dumpstack(); }, r => sub { reversestack(); }, R => sub { rotatestack(); }, + h => sub { showhist(); }, '(' => sub { $sub = 1 }, ')' => sub { $sub = 0 }, ); @@ -132,6 +133,12 @@ sub cmd { } } +sub showhist { + foreach my $entry (@hist) { + printf "History: %10s = %s\n", $entry->[0], $entry->[1]; + } +} + sub clearstack { if ($sub) { @substack = (); @@ -257,7 +264,7 @@ sub prompt { $prompt = '%'; } - return sprintf "%2d %s ", $count, $prompt; + return sprintf "%3d %s ", $count, $prompt; } sub calc { @@ -294,11 +301,14 @@ sub calc { else { push @stack, $res; $sub = 0; + if ($debug) { print "DEBUG: $code = $res\n"; } + if ($tty) { dumpstack(); + push @hist, [$res, $code]; return "=> $res\n\n"; } else { @@ -332,6 +342,7 @@ R rotate the stack ( enter collect mode ) leave collect mode u undo last operation +h show history of past operations q finish (C-d works as well) ? print help