Fixes in 2015/burton
Format fixes (maybe typos?) in README.md. Added calc.1 which is essentially what was calc.man but so one can actually get expected formatting when using man ./calc.1. If I fixed any typos they are not fixed in calc.man. I kept the commands the same so one would have to change calc to ./prog. Formatting and maybe typos in road.to.obscurity.
This commit is contained in:
1 parent
dbc6a3b812
commit
fa31f80b39
3 files changed
+339
-175
No files matched your search
@@ -0,0 +1,130 @@
|
||||
.TH calc 1 "25 March 2023" "calc" "IOCCC 2015"
|
||||
.SH NAME
|
||||
calc \- an integer expression calculator that outputs in both hex and decimal
|
||||
.SH SYNOPSIS
|
||||
\fBcalc\fP \fI[expr]\fP
|
||||
.SH DESCRIPTION
|
||||
.BR calc
|
||||
presents a simple signed integer expression calculator.
|
||||
The result is printed on
|
||||
.BR stdout
|
||||
as both a decimal value and its hex equivalent.
|
||||
Results are presented as 32-bit values, displaying as 64-bits only if necessary.
|
||||
If the program name begins with
|
||||
.I e
|
||||
the input is also copied to
|
||||
.BR stdout .
|
||||
.BR stdin
|
||||
is read if there are no arguments.
|
||||
.PP
|
||||
Constants may be decimal, octal or hex.
|
||||
There are 26 registers, initialized to zero, named A-Z; the most recent result is always remembered in the register
|
||||
.IR .
|
||||
(dot).
|
||||
Assignments are silent; the character
|
||||
.IR $
|
||||
will print a table of the non-zero registers.
|
||||
.PP
|
||||
All input is case-insensitive.
|
||||
Semicolons and/or newlines separate statements.
|
||||
Whitespace is ignored, except newlines cannot occur within expressions.
|
||||
Comments are introduced with
|
||||
.I #
|
||||
and extend through the following newline.
|
||||
.PP
|
||||
Operator precedence is as found in Go:
|
||||
OR and XOR are treated as additive, SHIFTing and AND are multiplicative.
|
||||
This allows a more natural expression without parentheses,
|
||||
as in
|
||||
.BR a&0xff\ |\ b<<8 \c
|
||||
\&.
|
||||
.PP
|
||||
Supported operations in decreasing precedence:
|
||||
.TP
|
||||
.B ()
|
||||
forced precedence
|
||||
.TQ
|
||||
.B \- + ! ~ ?
|
||||
unary plus/minus, not, compl, byteswap
|
||||
.TQ
|
||||
.B * / % & << >> >>>
|
||||
mul, div, mod, bitand, shift: left, right, unsigned right
|
||||
.TQ
|
||||
.B + \- | ^
|
||||
add, sub, bitor, xor
|
||||
.TQ
|
||||
.B =
|
||||
assignment ([a-z] = expr)
|
||||
.SH EXAMPLES
|
||||
.PP
|
||||
Display the decimal value of 0x42:
|
||||
.sp
|
||||
.RS
|
||||
.ft B
|
||||
$ calc 0x42
|
||||
.br
|
||||
66 0x00000042
|
||||
.ft R
|
||||
.RE
|
||||
.PP
|
||||
What is the mask value for 22 bits?
|
||||
.sp
|
||||
.RS
|
||||
.ft B
|
||||
$ calc '1<<22-1'
|
||||
.br
|
||||
4194303 0x003fffff
|
||||
.ft R
|
||||
.RE
|
||||
.PP
|
||||
What is the integer value of byte-swapped 0x11223344?
|
||||
.RS
|
||||
.ft B
|
||||
$ calc ?0x11223344
|
||||
.br
|
||||
1144201745 0x44332211
|
||||
.ft R
|
||||
.RE
|
||||
.PP
|
||||
Some canned expressions:
|
||||
.RS
|
||||
.ft B
|
||||
cat <<! | ecalc
|
||||
.br
|
||||
# multiple assignments
|
||||
.br
|
||||
a=32;n=10;c=50;m=100;$
|
||||
.br
|
||||
7+7/7+7*7-7 # pedmas
|
||||
.br
|
||||
m|a-a*3 # convenient precedence
|
||||
.br
|
||||
?(1<<14|1<<9)-1<<4-1<<3
|
||||
.br
|
||||
57005<<16+48879
|
||||
.br
|
||||
-1 >> 32 # signed shift
|
||||
.br
|
||||
-1 >>> 32 # unsigned shift
|
||||
.br
|
||||
!
|
||||
.ft R
|
||||
.RE
|
||||
.SH BUGS
|
||||
An assignment with certain types of syntax error will replace the registers with a partial evaluation:
|
||||
.sp
|
||||
.RS
|
||||
.ft B
|
||||
calc 'a = 1; a; a = 3 4; a'
|
||||
.br
|
||||
1 0x00000001
|
||||
.br
|
||||
syntax error
|
||||
.br
|
||||
3 0x00000003
|
||||
.ft R
|
||||
.RE
|
||||
.PP
|
||||
Command line expressions longer than 64 characters will give a syntax error.
|
||||
.SH SEE ALSO
|
||||
\<https://golang.org/\>
|
||||
Reference in new issue
Block a user