mirror of
https://codeberg.org/scip/rpnc.git
synced 2025-12-17 12:31:04 +01:00
additions:
toggle showstack fixed collector display better help
This commit is contained in:
63
rpnc
63
rpnc
@@ -12,7 +12,7 @@ my $term = Term::ReadLine->new('rpn calc');
|
|||||||
my $debug = 0;
|
my $debug = 0;
|
||||||
my $showstack = 1;
|
my $showstack = 1;
|
||||||
my $tty = 1;
|
my $tty = 1;
|
||||||
my $VERSION = '1.03dev';
|
my $VERSION = '1.03';
|
||||||
my $sub = 0;
|
my $sub = 0;
|
||||||
my $op;
|
my $op;
|
||||||
|
|
||||||
@@ -59,9 +59,11 @@ my %commands = (
|
|||||||
q => sub { exit; },
|
q => sub { exit; },
|
||||||
'?' => sub { help(); },
|
'?' => sub { help(); },
|
||||||
s => sub { dumpstack(); },
|
s => sub { dumpstack(); },
|
||||||
|
sa => sub { dumpstack(1); },
|
||||||
c => sub { clearstack(); },
|
c => sub { clearstack(); },
|
||||||
cx => sub { clearstack(1); dumpstack(); },
|
cx => sub { clearstack(1); dumpstack(); },
|
||||||
d => sub { $debug ^= 1; },
|
d => sub { $debug ^= 1; },
|
||||||
|
S => sub { $showstack ^= 1; },
|
||||||
u => sub { undo(); dumpstack(); },
|
u => sub { undo(); dumpstack(); },
|
||||||
rs => sub { reversestack(); },
|
rs => sub { reversestack(); },
|
||||||
Rs => sub { rotatestack(); },
|
Rs => sub { rotatestack(); },
|
||||||
@@ -238,21 +240,30 @@ sub pushstack {
|
|||||||
|
|
||||||
sub dumpstack {
|
sub dumpstack {
|
||||||
return unless $showstack;
|
return unless $showstack;
|
||||||
|
my $max = shift;
|
||||||
|
my $x = ' ';
|
||||||
my $prefix = 'stack';
|
my $prefix = 'stack';
|
||||||
my @all;
|
my @all;
|
||||||
|
|
||||||
if ($sub) {
|
if ($sub) {
|
||||||
@all = @substack;
|
@all = @substack;
|
||||||
|
$prefix = 'collectorstack';
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@all = @stack;
|
@all = @stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
my $abs = scalar @all;
|
||||||
|
if (! $max && $abs > 10) {
|
||||||
|
@all = @all[-10 .. -1];
|
||||||
|
printf "%s [..]\n", $prefix;
|
||||||
|
}
|
||||||
|
|
||||||
my $p = scalar @all;
|
my $p = scalar @all;
|
||||||
|
|
||||||
foreach my $n (@all) {
|
foreach my $n (@all) {
|
||||||
printf "%s %4d: %s\n", $prefix, $p--, $n;
|
$x = 'X' if($p == 1);
|
||||||
|
printf "%s %s %4d: %s\n", $prefix, $x, $p--, $n;
|
||||||
}
|
}
|
||||||
|
|
||||||
print "\n";
|
print "\n";
|
||||||
@@ -382,34 +393,22 @@ Commandline: rpn [-d] [<operator>]
|
|||||||
If <operator> is provided, read numbers from STDIN,
|
If <operator> is provided, read numbers from STDIN,
|
||||||
otherwise runs interactively.
|
otherwise runs interactively.
|
||||||
|
|
||||||
Available commands:
|
Configure: Available operators:
|
||||||
cx clear X (last stack element)
|
d toggle debugging (-d) ( enter collect mode
|
||||||
c clear stack
|
S toggle display of stack (-n) ) leave collect mode
|
||||||
s show the stack
|
+ add
|
||||||
d toggle debugging (current setting: $debug)
|
Stack Management: - substract
|
||||||
rs reverse the stack
|
s show the stack / divide
|
||||||
Rs rotate the stack
|
sa show the whole stack * multiply
|
||||||
( enter collect mode
|
cx clear X (last stack element) ^ expotentiate
|
||||||
) leave collect mode
|
c clear stack % percent
|
||||||
u undo last operation
|
rs reverse the stack %d percentual difference
|
||||||
h show history of past operations
|
Rs rotate the stack & bitwise AND
|
||||||
q finish (C-d works as well)
|
| bitwise OR
|
||||||
? print help
|
Various Commands x bitwise XOR
|
||||||
|
u undo last operation V pull root (2nd if stack==1)
|
||||||
Available operators:
|
h show history of past operations m median
|
||||||
+ add
|
q finish (C-d works as well) a average
|
||||||
- substract
|
? print help
|
||||||
/ divide
|
|
||||||
* multiply
|
|
||||||
^ expotentiate
|
|
||||||
% percent
|
|
||||||
%d percentual difference
|
|
||||||
& bitwise AND
|
|
||||||
| bitwise OR
|
|
||||||
x bitwise XOR
|
|
||||||
V pull root (2nd if stack==1)
|
|
||||||
m median
|
|
||||||
a average
|
|
||||||
|
|
||||||
~;
|
~;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user