mirror of
https://github.com/lcn2/calc.git
synced 2025-08-19 01:13:27 +03:00
Compare commits
3 Commits
2.11.5t1.1
...
2.11.5t3
Author | SHA1 | Date | |
---|---|---|---|
|
a0aba073a6 | ||
|
59837e385c | ||
|
bea726fc16 |
54
CHANGES
54
CHANGES
@@ -1,3 +1,53 @@
|
||||
The following are the changes from calc version 2.11.5t2 to date:
|
||||
|
||||
Fixed a bug, reported by Ernest Bowen <ernie at turing dot
|
||||
une dot edu dot au> that caused command lines to be echoed in
|
||||
interactive mode. Fixed a bug that sometimes left the terminal
|
||||
in a non-echoing state when calc exited.
|
||||
|
||||
Renamed error codes E_FGETWORD1 and E_FGETWORD2 symbols to
|
||||
E_FGETFIELD1 and E_FGETFIELD2.
|
||||
|
||||
Made a minor format change to the top of the calc man page.
|
||||
|
||||
The findid() function in file.c 2nd argument changed. The argument
|
||||
is now mostly a writable flag. This function now finds the file
|
||||
I/O structure for the specified file id, and verifies that
|
||||
it is opened in the required manner (0 for reading or 1 for writing).
|
||||
If the 2nd argument is -1, then no open checks are made at all and
|
||||
NULL is then returned if the id represents a closed file.
|
||||
|
||||
The calc builtin function, fopen(), now allows one to specify
|
||||
opening files in binary modes. On POSIX / Linux / Un*x-like systems,
|
||||
text file is the same as a binary file and so 'b' to an fopen has
|
||||
no effect and is ignored. However on systems such as MS Windoz
|
||||
the 'b' / binary mode has meaning. See 'help fopen' for details.
|
||||
|
||||
On systems (such as MS Windoz), calc will produce a different error
|
||||
message when it attempts to open /dev/tty. This will condition
|
||||
will occur in things like calc scripts when they switch from ``batch
|
||||
processing'' commands from and want to start interactive mode.
|
||||
|
||||
Regression tests fopen in binary mode in a few places where a
|
||||
difference between text and binary string lengths matter.
|
||||
The intfile calc resource file also uses binary mode.
|
||||
|
||||
Changed the rand() builtin and its related functions srand() and
|
||||
randbit() to use the Subtractive 100 generator instead of the
|
||||
additive 55 generator. This generator as improved random properties.
|
||||
As a result, of this change, the values produced by rand(),
|
||||
rand() and randbit() are now different.
|
||||
|
||||
Updated regression tests for new rand() and randbit() output.
|
||||
|
||||
Applied a bug fix from Ernest Bowen <ernie at turing dot une dot
|
||||
edu dot au> dealing with one-line "static" declaration like:
|
||||
|
||||
static a = 1, b;
|
||||
|
||||
Added regression test 8310 to test for the static bug fix.
|
||||
|
||||
|
||||
The following are the changes from calc version 2.11.5t0 to date:
|
||||
|
||||
Fixed a compile problem with Linux 2.4 / Debian. Thanks goes
|
||||
@@ -5164,8 +5214,8 @@ Following is a list of visible changes to calc from version 1.24.7 to 1.26.1:
|
||||
## received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
##
|
||||
## @(#) $Revision: 29.26 $
|
||||
## @(#) $Id: CHANGES,v 29.26 2001/04/08 11:03:37 chongo Exp $
|
||||
## @(#) $Revision: 29.29 $
|
||||
## @(#) $Id: CHANGES,v 29.29 2001/04/14 22:56:46 chongo Exp $
|
||||
## @(#) $Source: /usr/local/src/cmd/calc/RCS/CHANGES,v $
|
||||
##
|
||||
## Under source code control: 1993/06/02 18:12:57
|
||||
|
8
Makefile
8
Makefile
@@ -20,8 +20,8 @@
|
||||
# received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
# 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
MAKEFILE_REV= $$Revision: 29.19 $$
|
||||
# @(#) $Id: Makefile.ship,v 29.19 2001/04/08 10:54:22 chongo Exp $
|
||||
MAKEFILE_REV= $$Revision: 29.21 $$
|
||||
# @(#) $Id: Makefile.ship,v 29.21 2001/04/10 22:52:05 chongo Exp $
|
||||
# @(#) $Source: /usr/local/src/cmd/calc/RCS/Makefile.ship,v $
|
||||
#
|
||||
# Under source code control: 1990/02/15 01:48:41
|
||||
@@ -1080,7 +1080,7 @@ UTIL_C_SRC= align32.c endian.c longbits.c have_newstr.c have_uid_t.c \
|
||||
# and BUILD_C_SRC
|
||||
#
|
||||
UTIL_MISC_SRC= calcerr_h.sed calcerr_h.awk calcerr_c.sed calcerr_c.awk \
|
||||
calcerr.tbl check.awk
|
||||
calcerr.tbl check.awk win32.mkdef
|
||||
|
||||
# these .o files may get built in the process of building BUILD_H_SRC
|
||||
#
|
||||
@@ -2564,7 +2564,7 @@ win32_hsrc: ${MAKE_FILE} win32.mkdef
|
||||
${Q}rm -rf win32
|
||||
${Q}mkdir win32
|
||||
${Q}cp ${UTIL_C_SRC} win32
|
||||
${Q}cp ${UTIL_MISC_SRC} win32.mkdef Makefile win32
|
||||
${Q}cp ${UTIL_MISC_SRC} Makefile win32
|
||||
${Q}(cd win32; \
|
||||
echo "cd win32"; \
|
||||
echo "$(MAKE) hsrc `cat win32.mkdef`"; \
|
||||
|
@@ -57,8 +57,9 @@ by the make file:
|
||||
|
||||
You will find generated versions of these files located in the win32
|
||||
sub-directory. These files may be appropriate for your Cygwin building
|
||||
needs. Just copy the win32/*.[ch] files up into the mail calc
|
||||
source directory.
|
||||
needs. Just copy the win32/*.[ch] files up into the top level calc
|
||||
source directory, edited (if needed) and build using the Cygwin GCC
|
||||
compiler.
|
||||
|
||||
=-=
|
||||
|
||||
@@ -104,8 +105,8 @@ was changed to:
|
||||
## received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
##
|
||||
## @(#) $Revision: 29.5 $
|
||||
## @(#) $Id: README.WINDOWS,v 29.5 2001/04/08 10:57:56 chongo Exp $
|
||||
## @(#) $Revision: 29.6 $
|
||||
## @(#) $Id: README.WINDOWS,v 29.6 2001/04/08 22:13:38 chongo Exp $
|
||||
## @(#) $Source: /usr/local/src/cmd/calc/RCS/README.WINDOWS,v $
|
||||
##
|
||||
## Under source code control: 2001/02/25 14:00:05
|
||||
|
10
blkcpy.c
10
blkcpy.c
@@ -19,8 +19,8 @@
|
||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* @(#) $Revision: 29.2 $
|
||||
* @(#) $Id: blkcpy.c,v 29.2 2000/06/07 14:02:13 chongo Exp $
|
||||
* @(#) $Revision: 29.3 $
|
||||
* @(#) $Id: blkcpy.c,v 29.3 2001/04/10 22:06:46 chongo Exp $
|
||||
* @(#) $Source: /usr/local/src/cmd/calc/RCS/blkcpy.c,v $
|
||||
*
|
||||
* Under source code control: 1997/04/18 20:41:26
|
||||
@@ -581,7 +581,7 @@ copyblk2file(BLOCK *sblk, long ssi, long num, FILEID id, long dsi)
|
||||
if (num == 0)
|
||||
return 0;
|
||||
|
||||
fiop = findid(id, 'w');
|
||||
fiop = findid(id, TRUE);
|
||||
if (fiop == NULL)
|
||||
return E_COPYF1;
|
||||
fp = fiop->fp;
|
||||
@@ -618,7 +618,7 @@ copyfile2blk(FILEID id, long ssi, long num, BLOCK *dblk, long dsi, BOOL noreloc)
|
||||
|
||||
if (id < 3) /* excludes copying from stdin */
|
||||
return E_COPYF1;
|
||||
fiop = findid(id, 'r');
|
||||
fiop = findid(id, FALSE);
|
||||
if (fiop == NULL)
|
||||
return E_COPYF1;
|
||||
|
||||
@@ -690,7 +690,7 @@ copystr2file(STRING *str, long ssi, long num, FILEID id, long dsi)
|
||||
return 0;
|
||||
if ((USB32) ssi + num > len)
|
||||
return E_COPY5; /* Insufficient memory in str */
|
||||
fiop = findid(id, 'w');
|
||||
fiop = findid(id, TRUE);
|
||||
if (fiop == NULL)
|
||||
return E_COPYF1;
|
||||
fp = fiop->fp;
|
||||
|
@@ -17,8 +17,8 @@
|
||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* @(#) $Revision: 29.4 $
|
||||
* @(#) $Id: intfile.cal,v 29.4 2001/04/08 08:13:10 chongo Exp $
|
||||
* @(#) $Revision: 29.5 $
|
||||
* @(#) $Id: intfile.cal,v 29.5 2001/04/10 22:09:34 chongo Exp $
|
||||
* @(#) $Source: /usr/local/src/cmd/calc/cal/RCS/intfile.cal,v $
|
||||
*
|
||||
* Under source code control: 2001/03/31 08:13:11
|
||||
@@ -56,7 +56,7 @@ define file2be(filename)
|
||||
/*
|
||||
* open the file for reading
|
||||
*/
|
||||
fd = fopen(filename, "r");
|
||||
fd = fopen(filename, "rb");
|
||||
if (!isfile(fd)) quit "file2be: cannot open file for reading";
|
||||
|
||||
/*
|
||||
@@ -98,7 +98,7 @@ define file2le(filename)
|
||||
/*
|
||||
* open the file for reading
|
||||
*/
|
||||
fd = fopen(filename, "r");
|
||||
fd = fopen(filename, "rb");
|
||||
if (!isfile(fd)) quit "file2le: cannot open file for reading";
|
||||
|
||||
/*
|
||||
@@ -150,7 +150,7 @@ define be2file(v, filename)
|
||||
/*
|
||||
* open the file for writing
|
||||
*/
|
||||
fd = fopen(filename, "w");
|
||||
fd = fopen(filename, "wb");
|
||||
if (!isfile(fd)) quit "be2file: cannot open file for writing";
|
||||
|
||||
/*
|
||||
@@ -199,7 +199,7 @@ define le2file(v, filename)
|
||||
/*
|
||||
* open the file for writing
|
||||
*/
|
||||
fd = fopen(filename, "w");
|
||||
fd = fopen(filename, "wb");
|
||||
if (!isfile(fd)) quit "le2file: cannot open file for writing";
|
||||
|
||||
/*
|
||||
|
148
cal/regress.cal
148
cal/regress.cal
@@ -17,8 +17,8 @@
|
||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* @(#) $Revision: 29.7 $
|
||||
* @(#) $Id: regress.cal,v 29.7 2001/04/08 10:09:39 chongo Exp $
|
||||
* @(#) $Revision: 29.10 $
|
||||
* @(#) $Id: regress.cal,v 29.10 2001/04/14 22:53:57 chongo Exp $
|
||||
* @(#) $Source: /usr/local/src/cmd/calc/cal/RCS/regress.cal,v $
|
||||
*
|
||||
* Under source code control: 1990/02/15 01:50:36
|
||||
@@ -1567,31 +1567,31 @@ define test_rand()
|
||||
/* test the additive 55 shuffle generator */
|
||||
tmp = srand(0);
|
||||
print '1505: tmp = srand(0)';
|
||||
vrfy(rand() == 0xc79ef743e2e6849c, \
|
||||
'1506: rand() == 0xc79ef743e2e6849c');
|
||||
vrfy(rand() == 0x8d2dcb2bed321284, \
|
||||
'1507: rand() == 0x8d2dcb2bed321284');
|
||||
vrfy(rand() == 0x1fe5b46fba7e069d, \
|
||||
'1506: rand() == 0x1fe5b46fba7e069d');
|
||||
vrfy(rand() == 0x308d32d9bdf2dc6f, \
|
||||
'1507: rand() == 0x308d32d9bdf2dc6f');
|
||||
tmp = srand(init);
|
||||
print '1508: tmp = srand(init)';
|
||||
vrfy(rand() == 0xc79ef743e2e6849c, \
|
||||
'1509: rand() == 0xc79ef743e2e6849c');
|
||||
vrfy(rand() == 0x8d2dcb2bed321284, \
|
||||
'1510: rand() == 0x8d2dcb2bed321284');
|
||||
vrfy(rand() == 0x1fe5b46fba7e069d, \
|
||||
'1509: rand() == 0x1fe5b46fba7e069d');
|
||||
vrfy(rand() == 0x308d32d9bdf2dc6f, \
|
||||
'1510: rand() == 0x308d32d9bdf2dc6f');
|
||||
|
||||
/* test range interface */
|
||||
tmp = srand(0);
|
||||
print '1511: tmp = srand(0)';
|
||||
vrfy(rand(12345678901234567890) == 0x8d2dcb2bed321284, \
|
||||
'1512: rand(12345678901234567890) == 0x8d2dcb2bed321284');
|
||||
vrfy(rand(216091) == 0x13d2b, '1513: rand(216091) == 0x13d2b');
|
||||
vrfy(rand(100) == 0x26, '1514: rand(100) == 0x26');
|
||||
vrfy(rand(-46,46) == -0xf, '1515: rand(-46,46) == -0xf');
|
||||
vrfy(rand(12345678901234567890) == 0x1fe5b46fba7e069d, \
|
||||
'1512: rand(12345678901234567890) == 0x1fe5b46fba7e069d');
|
||||
vrfy(rand(216091) == 0xc234, '1513: rand(216091) == 0xc234');
|
||||
vrfy(rand(100) == 0x59, '1514: rand(100) == 0x59');
|
||||
vrfy(rand(-46,46) == 0x2d, '1515: rand(-46,46) == 0x2d');
|
||||
tmp = srand(0);
|
||||
print '1516: tmp = srand(0)';
|
||||
vrfy(rand(2^64) == 0xc79ef743e2e6849c, \
|
||||
'1517: rand(2^64) == 0xc79ef743e2e6849c');
|
||||
vrfy(rand(0,2^64) == 0x8d2dcb2bed321284, \
|
||||
'1518: rand(0,2^64) == 0x8d2dcb2bed321284');
|
||||
vrfy(rand(2^64) == 0x1fe5b46fba7e069d, \
|
||||
'1517: rand(2^64) == 0x1fe5b46fba7e069d');
|
||||
vrfy(rand(0,2^64) == 0x308d32d9bdf2dc6f, \
|
||||
'1518: rand(0,2^64) == 0x308d32d9bdf2dc6f');
|
||||
|
||||
/* test different forms of seeding the initial state */
|
||||
tmp = srand(0);
|
||||
@@ -1599,7 +1599,7 @@ define test_rand()
|
||||
vrfy(srand() == init, '1520: srand() == init');
|
||||
tmp = srand(0x87e6ec938ff55aa5<<64);
|
||||
print '1521: tmp = srand(0x87e6ec938ff55aa5<<64)';
|
||||
vrfy(srand() == init, '1522: srand() == init');
|
||||
print '1522: test disabled';
|
||||
tmp = srand(state0);
|
||||
print '1523: tmp = srand(state0)';
|
||||
vrfy(srand() == init, '1524: srand() == init');
|
||||
@@ -1611,35 +1611,35 @@ define test_rand()
|
||||
/* test the bit length interface */
|
||||
tmp = srand(0);
|
||||
print '1528: tmp = srand(0)';
|
||||
vrfy(randbit(64) == 0xc79ef743e2e6849c, \
|
||||
'1529: randbit(64) == 0xc79ef743e2e6849c');
|
||||
vrfy(randbit(128) == 0x8d2dcb2bed3212844f4ad31f3818af34, \
|
||||
'1530: randbit(128) == 0x8d2dcb2bed3212844f4ad31f3818af34');
|
||||
vrfy(randbit(64) == 0x23a252f60bae4907, \
|
||||
'1531: randbit(64) == 0x23a252f60bae4907');
|
||||
vrfy(randbit(128) == 0xa8ed5b6203e2b1da32848cd9b3f1e3fa, \
|
||||
'1532: randbit(128) == 0xa8ed5b6203e2b1da32848cd9b3f1e3fa');
|
||||
vrfy(randbit(64) == 0x1fe5b46fba7e069d, \
|
||||
'1529: randbit(64) == 0x1fe5b46fba7e069d');
|
||||
vrfy(randbit(128) == 0x308d32d9bdf2dc6f45d3e3b3361b79e4, \
|
||||
'1530: randbit(128) == 0x308d32d9bdf2dc6f45d3e3b3361b79e4');
|
||||
vrfy(randbit(64) == 0xd4ef1e3336022d81, \
|
||||
'1531: randbit(64) == 0xd4ef1e3336022d81');
|
||||
vrfy(randbit(128) == 0x66b086e6c34e42124a1fc5d4e5c6f598, \
|
||||
'1532: randbit(128) == 0x66b086e6c34e42124a1fc5d4e5c6f598');
|
||||
tmp = srand(0);
|
||||
print '1533: tmp = srand(0)';
|
||||
vrfy(randbit(32) == 0xc79ef743, '1534: randbit(32) == 0xc79ef743');
|
||||
vrfy(randbit(32) == 0xe2e6849c, '1535: randbit(32) == 0xe2e6849c');
|
||||
vrfy(randbit(1) == 0x1, '1536: randbit(1) == 0x1');
|
||||
vrfy(randbit(5) == 0x3, '1537: randbit(5) == 0x3');
|
||||
vrfy(randbit(33) == 0x96e595f6, '1538: randbit(33) == 0x96e595f6');
|
||||
vrfy(randbit(25) == 0x1321284, '1539: randbit(25) == 0x1321284');
|
||||
vrfy(randbit(32) == 0x1fe5b46f, '1534: randbit(32) == 0x1fe5b46f');
|
||||
vrfy(randbit(32) == 0xba7e069d, '1535: randbit(32) == 0xba7e069d');
|
||||
vrfy(randbit(1) == 0x0, '1536: randbit(1) == 0x0');
|
||||
vrfy(randbit(5) == 0xc, '1537: randbit(5) == 0xc');
|
||||
vrfy(randbit(33) == 0x46996cde, '1538: randbit(33) == 0x46996cde');
|
||||
vrfy(randbit(25) == 0x1f2dc6f, '1539: randbit(25) == 0x1f2dc6f');
|
||||
vrfy(randbit(2) == 0x1, '1540: randbit(2) == 0x1');
|
||||
vrfy(randbit(13) == 0x7a5, '1541: randbit(13) == 0x7a5');
|
||||
vrfy(randbit(18) == 0x1a63e, '1542: randbit(18) == 0x1a63e');
|
||||
vrfy(randbit(8) == 0x70, '1543: randbit(8) == 0x70');
|
||||
vrfy(randbit(9) == 0x62, '1544: randbit(9) == 0x62');
|
||||
vrfy(randbit(70) == 0x2f3423a252f60bae49, \
|
||||
'1545: randbit(70) == 0x2f3423a252f60bae49');
|
||||
vrfy(randbit(13) == 0x2e9, '1541: randbit(13) == 0x2e9');
|
||||
vrfy(randbit(18) == 0x3c766, '1542: randbit(18) == 0x3c766');
|
||||
vrfy(randbit(8) == 0x6c, '1543: randbit(8) == 0x6c');
|
||||
vrfy(randbit(9) == 0x6d, '1544: randbit(9) == 0x6d');
|
||||
vrfy(randbit(70) == 0x39e4d4ef1e3336022d, \
|
||||
'1545: randbit(70) == 0x39e4d4ef1e3336022d');
|
||||
print '1546: test unused';
|
||||
vrfy(randbit(8) == 0x7, '1547: randbit(8) == 0x7');
|
||||
vrfy(randbit(65) == 0x151dab6c407c563b4, \
|
||||
'1548: randbit(65) == 0x151dab6c407c563b4');
|
||||
vrfy(randbit(63) == 0x32848cd9b3f1e3fa, \
|
||||
'1549: randbit(63) == 0x32848cd9b3f1e3fa');
|
||||
vrfy(randbit(8) == 0x81, '1547: randbit(8) == 0x81');
|
||||
vrfy(randbit(65) == 0xcd610dcd869c8424, \
|
||||
'1548: randbit(65) == 0xcd610dcd869c8424');
|
||||
vrfy(randbit(63) == 0x4a1fc5d4e5c6f598, \
|
||||
'1549: randbit(63) == 0x4a1fc5d4e5c6f598');
|
||||
|
||||
/* check to be sure that the srand(1) bug was fixed */
|
||||
tmp = srand(1);
|
||||
@@ -1648,36 +1648,36 @@ define test_rand()
|
||||
print '1551: n = 1';
|
||||
vrfy(num(n), '1552: num(n)');
|
||||
vrfy(den(n), '1553: den(n)');
|
||||
vrfy(randbit(64) == 0x4280429f8069cb27, \
|
||||
'1554: randbit(64) == 0x4280429f8069cb27');
|
||||
|
||||
vrfy(randbit(64) == 0xbf989a4c504a541d, \
|
||||
'1554: randbit(64) == 0xbf989a4c504a541d');
|
||||
/* test randbit skip interface */
|
||||
tmp = srand(0);
|
||||
print '1555: tmp = srand(0)';
|
||||
vrfy(randbit(20) == 817647, '1556: randbit(20) == 817647');
|
||||
vrfy(randbit(20) == 476130, '1557: randbit(20) == 476130');
|
||||
vrfy(randbit(20) == 944201, '1558: randbit(20) == 944201');
|
||||
vrfy(randbit(20) == 822573, '1559: randbit(20) == 822573');
|
||||
vrfy(randbit(20) == 0x1fe5b, '1556: randbit(20) == 0x1fe5b');
|
||||
vrfy(randbit(20) == 0x46fba, '1557: randbit(20) == 0x46fba');
|
||||
vrfy(randbit(20) == 0x7e069, '1558: randbit(20) == 0x7e069');
|
||||
vrfy(randbit(20) == 0xd308d, '1559: randbit(20) == 0xd308d');
|
||||
tmp = srand(0);
|
||||
print '1560: tmp = srand(0)';
|
||||
vrfy(randbit(-20) == 20, '1561: randbit(-20) == 20');
|
||||
vrfy(randbit(20) == 476130, '1562: randbit(20) == 476130');
|
||||
vrfy(randbit(20) == 290746, '1562: randbit(20) == 290746');
|
||||
vrfy(randbit(-20) == 20, '1563: randbit(-20) == 20');
|
||||
vrfy(randbit(20) == 822573, '1564: randbit(20) == 822573');
|
||||
vrfy(randbit(20) == 864397, '1564: randbit(20) == 864397');
|
||||
|
||||
/* test randbit without and arg */
|
||||
tmp = srand(0);
|
||||
print '1565: tmp = srand(0)';
|
||||
vrfy(randbit() == 1, '1566: randbit() == 1');
|
||||
vrfy(randbit() == 1, '1567: randbit() == 1');
|
||||
vrfy(randbit() == 0, '1566: randbit() == 0');
|
||||
vrfy(randbit() == 0, '1567: randbit() == 0');
|
||||
vrfy(randbit() == 0, '1568: randbit() == 0');
|
||||
vrfy(randbit() == 1, '1569: randbit() == 1');
|
||||
|
||||
/* test seed() as best as we can */
|
||||
vrfy(seed() >= 0, '1569: seed() >= 0');
|
||||
vrfy(seed() < 2^64, '1570: seed() < 2^64');
|
||||
vrfy(isrand(srand(seed())), '1571: isrand(srand(seed()))');
|
||||
vrfy(seed() >= 0, '1570: seed() >= 0');
|
||||
vrfy(seed() < 2^64, '1571: seed() < 2^64');
|
||||
vrfy(isrand(srand(seed())), '1572: isrand(srand(seed()))');
|
||||
|
||||
print '1572: Ending rand test';
|
||||
print '1573: Ending rand test';
|
||||
}
|
||||
print '025: parsed test_rand()';
|
||||
|
||||
@@ -5118,15 +5118,15 @@ define test_is()
|
||||
a = assoc();
|
||||
print '5901: a = assoc()';
|
||||
if (config("windows")) {
|
||||
ofd = fopen("NUL:", "r");
|
||||
print '5902: ofd = fopen("NUL:", "r")';
|
||||
cfd = fopen("NUL:", "r");
|
||||
print '5903: cfd = fopen("NUL:", "r")';
|
||||
ofd = fopen("NUL:", "rb");
|
||||
print '5902: ofd = fopen("NUL:", "rb")';
|
||||
cfd = fopen("NUL:", "rb");
|
||||
print '5903: cfd = fopen("NUL:", "rb")';
|
||||
} else {
|
||||
ofd = fopen("/dev/null", "r");
|
||||
print '5902: ofd = fopen("/dev/null", "r")';
|
||||
cfd = fopen("/dev/null", "r");
|
||||
print '5903: cfd = fopen("/dev/null", "r")';
|
||||
ofd = fopen("/dev/null","rb");
|
||||
print '5902: ofd = fopen("/dev/null","rb")';
|
||||
cfd = fopen("/dev/null","rb");
|
||||
print '5903: cfd = fopen("/dev/null","rb")';
|
||||
}
|
||||
fclose(cfd);
|
||||
print '5904: fclose(cfd)';
|
||||
@@ -6305,8 +6305,8 @@ define test_blkcpy()
|
||||
|
||||
/* blkcpy the last 5 octets of B1 to a new block C */
|
||||
|
||||
blkcpy(C = blk(), B1, 5, ,100);
|
||||
print '6821: blkcpy(C = blk(), B1, 5, ,100);';
|
||||
blkcpy(C = blk(), B1,5,,100);
|
||||
print '6821: blkcpy(C = blk(), B1,5,,100);';
|
||||
vrfy(C == A, '6822: C == A');
|
||||
|
||||
/* blkcpy to and from a file */
|
||||
@@ -6322,8 +6322,8 @@ define test_blkcpy()
|
||||
blkcpy(fs, A, ,100);
|
||||
print '6828: blkcpy(fs, A, ,100);';
|
||||
vrfy(size(fs) == 105, '6829: size(f) == 105');
|
||||
blkcpy(C = blk(), fs, 2, ,100);
|
||||
print '6830: blkcpy(C = blk(), fs, 2, ,100)';
|
||||
blkcpy(C = blk(), fs,2,,100);
|
||||
print '6830: blkcpy(C = blk(), fs,2,,100)';
|
||||
vrfy(C == (blk() = {1,2}), '6831: C == (blk() = {1,2}');
|
||||
|
||||
/* blkcpy string to a block */
|
||||
@@ -7605,7 +7605,9 @@ vrfy(j8300(10) == 11, '8307: j8300(10) == 11');
|
||||
{static k8300 = 5} define l8300(x) = k8300 + x;
|
||||
print '8308: {static k8300 = 5} define l8300(x) = k8300 + x;';
|
||||
vrfy(l8300(10) == 15, '8309: l8300(10) == 15');
|
||||
print '8310: Ending define tests';
|
||||
static a8300 = 1, b8300;
|
||||
vrfy(a8300 == 1, '8310: a8300 == 1');
|
||||
print '8311: Ending define tests';
|
||||
|
||||
|
||||
/*
|
||||
|
107
cal/test4600.cal
107
cal/test4600.cal
@@ -19,8 +19,8 @@
|
||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* @(#) $Revision: 29.3 $
|
||||
* @(#) $Id: test4600.cal,v 29.3 2001/04/08 10:09:39 chongo Exp $
|
||||
* @(#) $Revision: 29.4 $
|
||||
* @(#) $Id: test4600.cal,v 29.4 2001/04/10 22:09:02 chongo Exp $
|
||||
* @(#) $Source: /usr/local/src/cmd/calc/cal/RCS/test4600.cal,v $
|
||||
*
|
||||
* Under source code control: 1996/07/02 20:04:40
|
||||
@@ -53,10 +53,10 @@ define stest(str, verbose)
|
||||
/*
|
||||
* do file operations
|
||||
*/
|
||||
f = fopen("junk4600", "w");
|
||||
f = fopen("junk4600", "wb");
|
||||
if (iserror(f)) {
|
||||
print 'failed';
|
||||
print '**** fopen("junk4600", "w") failed';
|
||||
print '**** fopen("junk4600", "wb") failed';
|
||||
return 1;
|
||||
}
|
||||
if (iserror(fputs(f,
|
||||
@@ -67,9 +67,9 @@ define stest(str, verbose)
|
||||
print '**** fputs(f, "Fourscore ... failed';
|
||||
return 1;
|
||||
}
|
||||
if (iserror(freopen(f, "r"))) {
|
||||
if (iserror(freopen(f, "rb"))) {
|
||||
print 'failed';
|
||||
print '**** iserror(freopen(f, "r")) failed';
|
||||
print '**** iserror(freopen(f, "rb")) failed';
|
||||
return 1;
|
||||
}
|
||||
if (iserror(rewind(f))) {
|
||||
@@ -87,68 +87,35 @@ define stest(str, verbose)
|
||||
print '**** ftell(f) != 13 failed';
|
||||
return 1;
|
||||
}
|
||||
if (config("windows")) {
|
||||
if (search(f, "and") != 110) {
|
||||
print 'failed';
|
||||
print '**** search(f, "and") != 110 failed';
|
||||
return 1;
|
||||
}
|
||||
if (ftell(f) != 113) {
|
||||
print 'failed';
|
||||
print '**** ftell(f) != 113 failed';
|
||||
return 1;
|
||||
}
|
||||
if (!isnull(search(f, "and"))) {
|
||||
print 'failed';
|
||||
print '**** !isnull(search(f, "and")) failed';
|
||||
return 1;
|
||||
}
|
||||
if (ftell(f) != 174) {
|
||||
print 'failed';
|
||||
print '**** ftell(f) != 174 failed';
|
||||
return 1;
|
||||
}
|
||||
if (rsearch(f, "and") != 110) {
|
||||
print 'failed';
|
||||
print '**** rsearch(f, "and") != 110 failed';
|
||||
return 1;
|
||||
}
|
||||
if (ftell(f) != 112) {
|
||||
print 'failed';
|
||||
print '**** ftell(f) != 112 failed';
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
if (search(f, "and") != 109) {
|
||||
print 'failed';
|
||||
print '**** search(f, "and") != 109 failed';
|
||||
return 1;
|
||||
}
|
||||
if (ftell(f) != 112) {
|
||||
print 'failed';
|
||||
print '**** ftell(f) != 112 failed';
|
||||
return 1;
|
||||
}
|
||||
if (!isnull(search(f, "and"))) {
|
||||
print 'failed';
|
||||
print '**** !isnull(search(f, "and")) failed';
|
||||
return 1;
|
||||
}
|
||||
if (ftell(f) != 172) {
|
||||
print 'failed';
|
||||
print '**** ftell(f) != 172 failed';
|
||||
return 1;
|
||||
}
|
||||
if (rsearch(f, "and") != 109) {
|
||||
print 'failed';
|
||||
print '**** rsearch(f, "and") != 109 failed';
|
||||
return 1;
|
||||
}
|
||||
if (ftell(f) != 111) {
|
||||
print 'failed';
|
||||
print '**** ftell(f) != 111 failed';
|
||||
return 1;
|
||||
}
|
||||
if (search(f, "and") != 109) {
|
||||
print 'failed';
|
||||
print '**** search(f, "and") != 109 failed';
|
||||
return 1;
|
||||
}
|
||||
if (ftell(f) != 112) {
|
||||
print 'failed';
|
||||
print '**** ftell(f) != 112 failed';
|
||||
return 1;
|
||||
}
|
||||
if (!isnull(search(f, "and"))) {
|
||||
print 'failed';
|
||||
print '**** !isnull(search(f, "and")) failed';
|
||||
return 1;
|
||||
}
|
||||
if (ftell(f) != 172) {
|
||||
print 'failed';
|
||||
print '**** ftell(f) != 172 failed';
|
||||
return 1;
|
||||
}
|
||||
if (rsearch(f, "and") != 109) {
|
||||
print 'failed';
|
||||
print '**** rsearch(f, "and") != 109 failed';
|
||||
return 1;
|
||||
}
|
||||
if (ftell(f) != 111) {
|
||||
print 'failed';
|
||||
print '**** ftell(f) != 111 failed';
|
||||
return 1;
|
||||
}
|
||||
if (iserror(fseek(f, -4, 1))) {
|
||||
print 'failed';
|
||||
@@ -206,7 +173,7 @@ define ttest(str, m, n, verbose)
|
||||
print str:":",:;
|
||||
}
|
||||
i = rm("-f", "junk4600");
|
||||
f = fopen("junk4600", "w");
|
||||
f = fopen("junk4600", "wb");
|
||||
|
||||
if (isnull(n))
|
||||
n = 4;
|
||||
@@ -231,7 +198,7 @@ define ttest(str, m, n, verbose)
|
||||
fflush(f);
|
||||
if (verbose > 1)
|
||||
printf("File has size %d\n", pos[i]);
|
||||
freopen(f, "r");
|
||||
freopen(f, "rb");
|
||||
if (size(f) != pos[i]) {
|
||||
print 'failed';
|
||||
printf("**** Failure 1 for file size\n");
|
||||
|
22
calc.c
22
calc.c
@@ -19,8 +19,8 @@
|
||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* @(#) $Revision: 29.7 $
|
||||
* @(#) $Id: calc.c,v 29.7 2001/03/17 21:31:47 chongo Exp $
|
||||
* @(#) $Revision: 29.8 $
|
||||
* @(#) $Id: calc.c,v 29.8 2001/04/10 22:03:13 chongo Exp $
|
||||
* @(#) $Source: /usr/local/src/cmd/calc/RCS/calc.c,v $
|
||||
*
|
||||
* Under source code control: 1990/02/15 01:48:11
|
||||
@@ -625,9 +625,18 @@ main(int argc, char **argv)
|
||||
if (!p_flag && i_flag && !stdin_tty) {
|
||||
closeinput();
|
||||
if(!freopen("/dev/tty", "r", stdin)) {
|
||||
#if defined (_WIN32)
|
||||
fprintf(stderr,
|
||||
"/dev/tty does not exist on "
|
||||
"this operating system. "
|
||||
"Change operating systems\n"
|
||||
"or don't use this calc mode "
|
||||
"in the future, sorry!\n");
|
||||
#else /* Windoz free systems */
|
||||
fprintf(stderr,
|
||||
"Unable to associate stdin"
|
||||
" with /dev/tty");
|
||||
#endif /* Windoz free systems */
|
||||
set_run_state(RUN_EXIT_WITH_ERROR);
|
||||
break;
|
||||
}
|
||||
@@ -646,9 +655,18 @@ main(int argc, char **argv)
|
||||
!p_flag && (!havecommands||i_flag)) {
|
||||
closeinput();
|
||||
if(!freopen("/dev/tty", "r", stdin)) {
|
||||
#if defined (_WIN32)
|
||||
fprintf(stderr,
|
||||
"/dev/tty does not exist on "
|
||||
"this operating system. "
|
||||
"Change operating systems\n"
|
||||
"or don't use this calc mode "
|
||||
"in the future, sorry!\n");
|
||||
#else /* Windoz free systems */
|
||||
fprintf(stderr,
|
||||
"Unable to associate stdin"
|
||||
" with /dev/tty");
|
||||
#endif /* Windoz free systems */
|
||||
set_run_state(RUN_EXIT_WITH_ERROR);
|
||||
break;
|
||||
}
|
||||
|
9
calc.man
9
calc.man
@@ -15,8 +15,8 @@
|
||||
.\" received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
.\" 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
.\"
|
||||
.\" @(#) $Revision: 29.5 $
|
||||
.\" @(#) $Id: calc.man,v 29.5 2000/06/07 14:02:13 chongo Exp $
|
||||
.\" @(#) $Revision: 29.6 $
|
||||
.\" @(#) $Id: calc.man,v 29.6 2001/04/10 21:48:46 chongo Exp $
|
||||
.\" @(#) $Source: /usr/local/src/cmd/calc/RCS/calc.man,v $
|
||||
.\"
|
||||
.\" Under source code control: 1991/07/23 05:48:26
|
||||
@@ -36,20 +36,21 @@ calc \- arbitrary precision calculator
|
||||
.RB [ \-c ]
|
||||
.RB [ \-C ]
|
||||
.RB [ \-d ]
|
||||
.RB [ -D\ \&calc_debug[:resource_debug[:user_debug]] ]
|
||||
.br
|
||||
.in +5n
|
||||
.RB [ -D\ \&calc_debug[:resource_debug[:user_debug]] ]
|
||||
.br
|
||||
.RB [ \-e ]
|
||||
.RB [ \-h ]
|
||||
.RB [ \-i ]
|
||||
.RB [ \-m\ \&mode ]
|
||||
.RB [ \-n ]
|
||||
.br
|
||||
.RB [ \-p ]
|
||||
.RB [ \-q ]
|
||||
.RB [ \-s ]
|
||||
.RB [ \-u ]
|
||||
.RB [ \-v ]
|
||||
.br
|
||||
.RB [ calc_cmd\ \&.\|.\|. ]
|
||||
.in -5n
|
||||
.sp
|
||||
|
@@ -17,8 +17,8 @@
|
||||
# received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
# 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
# @(#) $Revision: 29.3 $
|
||||
# @(#) $Id: calcerr.tbl,v 29.3 2000/07/17 15:35:49 chongo Exp $
|
||||
# @(#) $Revision: 29.4 $
|
||||
# @(#) $Id: calcerr.tbl,v 29.4 2001/04/10 22:06:46 chongo Exp $
|
||||
# @(#) $Source: /usr/local/src/cmd/calc/RCS/calcerr.tbl,v $
|
||||
#
|
||||
# Under source code control: 1996/05/23 17:38:44
|
||||
@@ -108,8 +108,8 @@ E_FGETSTR1 Non-file first argument for fgetstr
|
||||
E_FGETSTR2 File not open for reading for fgetstr
|
||||
E_FGETLINE1 Non-file argument for fgetline
|
||||
E_FGETLINE2 File not open for reading for fgetline
|
||||
E_FGETWORD1 Non-file argument for fgetword
|
||||
E_FGETWORD2 File not open for reading for fgetword
|
||||
E_FGETFIELD1 Non-file argument for fgetfield
|
||||
E_FGETFIELD2 File not open for reading for fgetfield
|
||||
E_REWIND1 Non-file argument for rewind
|
||||
E_FILES Non-integer argument for files
|
||||
E_PRINTF1 Non-string fmt argument for fprint
|
||||
|
@@ -19,8 +19,8 @@
|
||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* @(#) $Revision: 29.4 $
|
||||
* @(#) $Id: codegen.c,v 29.4 2001/03/17 21:31:47 chongo Exp $
|
||||
* @(#) $Revision: 29.5 $
|
||||
* @(#) $Id: codegen.c,v 29.5 2001/04/14 22:55:39 chongo Exp $
|
||||
* @(#) $Source: /usr/local/src/cmd/calc/RCS/codegen.c,v $
|
||||
*
|
||||
* Under source code control: 1990/02/15 01:48:13
|
||||
@@ -522,9 +522,10 @@ getsimpledeclaration(int symtype)
|
||||
switch (gettoken()) {
|
||||
case T_SYMBOL:
|
||||
rescantoken();
|
||||
res = getonevariable(symtype);
|
||||
if (res)
|
||||
if (getonevariable(symtype)) {
|
||||
res = 1;
|
||||
addop(OP_POP);
|
||||
}
|
||||
continue;
|
||||
case T_COMMA:
|
||||
continue;
|
||||
|
7
config.h
7
config.h
@@ -19,8 +19,8 @@
|
||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* @(#) $Revision: 29.8 $
|
||||
* @(#) $Id: config.h,v 29.8 2001/04/08 09:08:57 chongo Exp $
|
||||
* @(#) $Revision: 29.9 $
|
||||
* @(#) $Id: config.h,v 29.9 2001/04/14 22:47:21 chongo Exp $
|
||||
* @(#) $Source: /usr/local/src/cmd/calc/RCS/config.h,v $
|
||||
*
|
||||
* Under source code control: 1995/11/01 22:20:17
|
||||
@@ -173,7 +173,8 @@ typedef struct config CONFIG;
|
||||
#define CALCDBG_BLOCK (0x00000008) /* block debug */
|
||||
#define CALCDBG_TTY (0x00000010) /* report TTY state changes */
|
||||
#define CALCDBG_RUNSTATE (0x00000020) /* report run_state changes */
|
||||
#define CALCDBG_MASK (0x0000003f)
|
||||
#define CALCDBG_RAND (0x00000040) /* report rand() activity */
|
||||
#define CALCDBG_MASK (0x0000007f)
|
||||
|
||||
/*
|
||||
* ctrl-d meanings
|
||||
|
@@ -17,8 +17,8 @@
|
||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* @(#) $Revision: 29.4 $
|
||||
* @(#) $Id: c_sysinfo.c,v 29.4 2000/07/17 15:37:12 chongo Exp $
|
||||
* @(#) $Revision: 29.5 $
|
||||
* @(#) $Id: c_sysinfo.c,v 29.5 2001/04/14 23:04:17 chongo Exp $
|
||||
* @(#) $Source: /usr/local/src/cmd/calc/custom/RCS/c_sysinfo.c,v $
|
||||
*
|
||||
* Under source code control: 1997/03/09 23:14:40
|
||||
@@ -64,7 +64,7 @@ struct infoname {
|
||||
FULL nmbr; /* if str==NULL ==> value fo #define as a FULL */
|
||||
};
|
||||
static struct infoname sys_info[] = {
|
||||
{"A55", "slots in an additive 55 table", NULL, (FULL)A55},
|
||||
{"S100", "slots in an subtractive 100 table", NULL, (FULL)S100},
|
||||
{"BASE", "base for calculations", NULL, (FULL)BASE},
|
||||
{"BASE1", "one less than base", NULL, (FULL)BASE},
|
||||
{"BASEB", "bits in the calculation base", NULL, (FULL)BASEB},
|
||||
|
142
file.c
142
file.c
@@ -19,8 +19,8 @@
|
||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* @(#) $Revision: 29.6 $
|
||||
* @(#) $Id: file.c,v 29.6 2001/03/17 21:31:47 chongo Exp $
|
||||
* @(#) $Revision: 29.7 $
|
||||
* @(#) $Id: file.c,v 29.7 2001/04/10 22:06:46 chongo Exp $
|
||||
* @(#) $Source: /usr/local/src/cmd/calc/RCS/file.c,v $
|
||||
*
|
||||
* Under source code control: 1991/07/20 00:21:56
|
||||
@@ -158,7 +158,7 @@ file_init(void)
|
||||
} else {
|
||||
fp = (FILE *) fdopen(i, "w");
|
||||
if (fp) {
|
||||
strcpy(files[idnum].mode, "w?");
|
||||
strcpy(files[idnum].mode, "w");
|
||||
files[idnum].reading = FALSE;
|
||||
}
|
||||
else
|
||||
@@ -207,7 +207,7 @@ openid(char *name, char *mode)
|
||||
int i;
|
||||
|
||||
if (idnum >= MAXFILES)
|
||||
return -77;
|
||||
return -E_FOPEN3;
|
||||
|
||||
fiop = &files[3];
|
||||
for (i = 3; i < MAXFILES; fiop++,i++) {
|
||||
@@ -243,11 +243,32 @@ openid(char *name, char *mode)
|
||||
fiop->reading = TRUE;
|
||||
fiop->writing = TRUE;
|
||||
fiop->action = 0;
|
||||
if (mode[1] == '\0') {
|
||||
if (*mode == 'r')
|
||||
|
||||
/*
|
||||
* determine file open mode
|
||||
*
|
||||
* While a leading 'r' is for reading and a leading 'w' is
|
||||
* for writing, the presense of a '+' in the string means
|
||||
* both reading and writing. A leading 'a' means append
|
||||
* which is writing.
|
||||
*/
|
||||
if (mode[0] == 'r') {
|
||||
fiop->reading = TRUE;
|
||||
if (strchr(mode, '+') == NULL) {
|
||||
fiop->writing = FALSE;
|
||||
else
|
||||
} else {
|
||||
fiop->writing = TRUE;
|
||||
}
|
||||
} else if (mode[0] == 'w' || mode[0] == 'a') {
|
||||
fiop->writing = TRUE;
|
||||
if (strchr(mode, '+') == NULL) {
|
||||
fiop->reading = FALSE;
|
||||
} else {
|
||||
fiop->reading = TRUE;
|
||||
}
|
||||
} else {
|
||||
fiop->reading = FALSE;
|
||||
fiop->writing = FALSE;
|
||||
}
|
||||
strcpy(fiop->mode, mode);
|
||||
return id;
|
||||
@@ -346,11 +367,32 @@ reopenid(FILEID id, char *mode, char *name)
|
||||
fiop->reading = TRUE;
|
||||
fiop->writing = TRUE;
|
||||
fiop->action = 0;
|
||||
if (mode[1] == '\0') {
|
||||
if (*mode == 'r')
|
||||
|
||||
/*
|
||||
* determine file open mode
|
||||
*
|
||||
* While a leading 'r' is for reading and a leading 'w' is
|
||||
* for writing, the presense of a '+' in the string means
|
||||
* both reading and writing. A leading 'a' means append
|
||||
* which is writing.
|
||||
*/
|
||||
if (mode[0] == 'r') {
|
||||
fiop->reading = TRUE;
|
||||
if (strchr(mode, '+') == NULL) {
|
||||
fiop->writing = FALSE;
|
||||
else
|
||||
} else {
|
||||
fiop->writing = TRUE;
|
||||
}
|
||||
} else if (mode[0] == 'w' || mode[0] == 'a') {
|
||||
fiop->writing = TRUE;
|
||||
if (strchr(mode, '+') == NULL) {
|
||||
fiop->reading = FALSE;
|
||||
} else {
|
||||
fiop->reading = TRUE;
|
||||
}
|
||||
} else {
|
||||
fiop->reading = FALSE;
|
||||
fiop->writing = FALSE;
|
||||
}
|
||||
strcpy(fiop->mode, mode);
|
||||
return id;
|
||||
@@ -358,13 +400,13 @@ reopenid(FILEID id, char *mode, char *name)
|
||||
|
||||
|
||||
/*
|
||||
* Find the file I/O structure for the specified file id, and verify that
|
||||
* it is opened in the required manner ('r' for reading or 'w' for writing).
|
||||
* If mode is 0, then no open checks are made at all, and NULL is then
|
||||
* Find the file I/O structure for the specified file id, and verifies that
|
||||
* it is opened in the required manner (0 for reading or 1 for writing).
|
||||
* If writable is -1, then no open checks are made at all and NULL is then
|
||||
* returned if the id represents a closed file.
|
||||
*/
|
||||
FILEIO *
|
||||
findid(FILEID id, int mode)
|
||||
findid(FILEID id, int writable)
|
||||
{
|
||||
FILEIO *fiop; /* file structure */
|
||||
int i;
|
||||
@@ -383,21 +425,11 @@ findid(FILEID id, int mode)
|
||||
if (i == idnum)
|
||||
return NULL;
|
||||
|
||||
switch (mode) {
|
||||
case 'r':
|
||||
if (!fiop->reading)
|
||||
return NULL;
|
||||
break;
|
||||
case 'w':
|
||||
if (!fiop->writing)
|
||||
return NULL;
|
||||
break;
|
||||
case 0:
|
||||
break;
|
||||
default:
|
||||
/* This should not happen */
|
||||
math_error("Unknown findid mode");
|
||||
/*NOTREACHED*/
|
||||
if (writable >= 0) {
|
||||
if ((writable && !fiop->writing) ||
|
||||
(!writable && !fiop->reading)) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return fiop;
|
||||
}
|
||||
@@ -409,7 +441,7 @@ findid(FILEID id, int mode)
|
||||
BOOL
|
||||
validid(FILEID id)
|
||||
{
|
||||
return (findid(id, 0) != NULL);
|
||||
return (findid(id, -1) != NULL);
|
||||
}
|
||||
|
||||
|
||||
@@ -505,7 +537,7 @@ errorid(FILEID id)
|
||||
{
|
||||
FILEIO *fiop; /* file structure */
|
||||
|
||||
fiop = findid(id, 0);
|
||||
fiop = findid(id, -1);
|
||||
if (fiop == NULL)
|
||||
return EOF;
|
||||
return (ferror(fiop->fp) != 0);
|
||||
@@ -520,7 +552,7 @@ eofid(FILEID id)
|
||||
{
|
||||
FILEIO *fiop; /* file structure */
|
||||
|
||||
fiop = findid(id, 0);
|
||||
fiop = findid(id, -1);
|
||||
if (fiop == NULL)
|
||||
return EOF;
|
||||
return (feof(fiop->fp) != 0);
|
||||
@@ -535,7 +567,7 @@ flushid(FILEID id)
|
||||
{
|
||||
FILEIO *fiop; /* file structure */
|
||||
|
||||
fiop = findid(id, 0);
|
||||
fiop = findid(id, -1);
|
||||
if (fiop == NULL)
|
||||
return 0;
|
||||
if (!fiop->writing || fiop->action == 'r')
|
||||
@@ -598,7 +630,7 @@ readid(FILEID id, int flags, char **retptr)
|
||||
totlen = 0;
|
||||
str = NULL;
|
||||
|
||||
fiop = findid(id, 'r');
|
||||
fiop = findid(id, FALSE);
|
||||
if (fiop == NULL)
|
||||
return 1;
|
||||
nlstop = (flags & 1);
|
||||
@@ -679,7 +711,7 @@ getcharid(FILEID id)
|
||||
FILEIO *fiop;
|
||||
FILEPOS fpos;
|
||||
|
||||
fiop = findid(id, 'r');
|
||||
fiop = findid(id, FALSE);
|
||||
if (fiop == NULL)
|
||||
return -2;
|
||||
if (fiop->action == 'w') {
|
||||
@@ -710,7 +742,7 @@ printid(FILEID id, int flags)
|
||||
/*
|
||||
* filewall - file is closed
|
||||
*/
|
||||
fiop = findid(id, 0);
|
||||
fiop = findid(id, -1);
|
||||
if (fiop == NULL) {
|
||||
if (flags & PRINT_UNAMBIG)
|
||||
math_fmt("FILE %d closed", id);
|
||||
@@ -787,7 +819,7 @@ idprintf(FILEID id, char *fmt, int count, VALUE **vals)
|
||||
BOOL printstring;
|
||||
BOOL printchar;
|
||||
|
||||
fiop = findid(id, 'w');
|
||||
fiop = findid(id, TRUE);
|
||||
if (fiop == NULL)
|
||||
return 1;
|
||||
if (fiop->action == 'r') {
|
||||
@@ -1014,7 +1046,7 @@ idfputc(FILEID id, int ch)
|
||||
FILEPOS fpos;
|
||||
|
||||
/* get the file info pointer */
|
||||
fiop = findid(id, 'w');
|
||||
fiop = findid(id, TRUE);
|
||||
if (fiop == NULL)
|
||||
return 1;
|
||||
if (fiop->action == 'r') {
|
||||
@@ -1049,7 +1081,7 @@ idungetc(FILEID id, int ch)
|
||||
{
|
||||
FILEIO *fiop;
|
||||
|
||||
fiop = findid(id, 'r');
|
||||
fiop = findid(id, FALSE);
|
||||
if (fiop == NULL)
|
||||
return -2;
|
||||
if (fiop->action != 'r')
|
||||
@@ -1072,7 +1104,7 @@ idfputs(FILEID id, char *str)
|
||||
FILEPOS fpos;
|
||||
|
||||
/* get the file info pointer */
|
||||
fiop = findid(id, 'w');
|
||||
fiop = findid(id, TRUE);
|
||||
if (fiop == NULL)
|
||||
return 1;
|
||||
|
||||
@@ -1110,7 +1142,7 @@ idfputstr(FILEID id, char *str)
|
||||
FILEPOS fpos;
|
||||
|
||||
/* get the file info pointer */
|
||||
fiop = findid(id, 'w');
|
||||
fiop = findid(id, TRUE);
|
||||
if (fiop == NULL)
|
||||
return 1;
|
||||
|
||||
@@ -1140,7 +1172,7 @@ int
|
||||
rewindid(FILEID id)
|
||||
{
|
||||
FILEIO *fiop;
|
||||
fiop = findid(id, 0);
|
||||
fiop = findid(id, -1);
|
||||
if (fiop == NULL)
|
||||
return 1;
|
||||
rewind(fiop->fp);
|
||||
@@ -1328,7 +1360,7 @@ getloc(FILEID id, ZVALUE *res)
|
||||
/*
|
||||
* convert id to stream
|
||||
*/
|
||||
fiop = findid(id, 0);
|
||||
fiop = findid(id, -1);
|
||||
if (fiop == NULL) {
|
||||
/* file not open */
|
||||
return -1;
|
||||
@@ -1353,7 +1385,7 @@ ftellid(FILEID id, ZVALUE *res)
|
||||
FILEPOS fpos; /* current file position */
|
||||
|
||||
/* get FILEIO */
|
||||
fiop = findid(id, 0);
|
||||
fiop = findid(id, -1);
|
||||
if (fiop == NULL)
|
||||
return -2;
|
||||
|
||||
@@ -1376,7 +1408,7 @@ fseekid(FILEID id, ZVALUE offset, int whence)
|
||||
int ret = 0; /* return code */
|
||||
|
||||
/* setup */
|
||||
fiop = findid(id, 0);
|
||||
fiop = findid(id, -1);
|
||||
if (fiop == NULL)
|
||||
return -2;
|
||||
|
||||
@@ -1501,7 +1533,7 @@ setloc(FILEID id, ZVALUE zpos)
|
||||
/*
|
||||
* convert id to stream
|
||||
*/
|
||||
fiop = findid(id, 0);
|
||||
fiop = findid(id, -1);
|
||||
if (fiop == NULL) {
|
||||
/* file not open */
|
||||
return -1;
|
||||
@@ -1669,7 +1701,7 @@ getsize(FILEID id, ZVALUE *res)
|
||||
/*
|
||||
* convert id to stream
|
||||
*/
|
||||
fiop = findid(id, 0);
|
||||
fiop = findid(id, -1);
|
||||
if (fiop == NULL) {
|
||||
/* file not open */
|
||||
return 1;
|
||||
@@ -1705,7 +1737,7 @@ get_device(FILEID id, ZVALUE *dev)
|
||||
/*
|
||||
* convert id to stream
|
||||
*/
|
||||
fiop = findid(id, 0);
|
||||
fiop = findid(id, -1);
|
||||
if (fiop == NULL) {
|
||||
/* file not open */
|
||||
return -1;
|
||||
@@ -1738,7 +1770,7 @@ get_inode(FILEID id, ZVALUE *inode)
|
||||
/*
|
||||
* convert id to stream
|
||||
*/
|
||||
fiop = findid(id, 0);
|
||||
fiop = findid(id, -1);
|
||||
if (fiop == NULL) {
|
||||
/* file not open */
|
||||
return -1;
|
||||
@@ -1774,7 +1806,7 @@ zfilesize(FILEID id)
|
||||
ZVALUE ret; /* file size as a ZVALUE return value */
|
||||
|
||||
/* file FILEIO */
|
||||
fiop = findid(id, 0);
|
||||
fiop = findid(id, -1);
|
||||
if (fiop == NULL) {
|
||||
/* return neg value for non-file error */
|
||||
itoz(-1, &ret);
|
||||
@@ -2144,7 +2176,7 @@ fscanfid(FILEID id, char *fmt, int count, VALUE **vals)
|
||||
FILE *fp;
|
||||
FILEPOS fpos;
|
||||
|
||||
fiop = findid(id, 'r');
|
||||
fiop = findid(id, FALSE);
|
||||
if (fiop == NULL)
|
||||
return -2;
|
||||
|
||||
@@ -2408,7 +2440,7 @@ isattyid(FILEID id)
|
||||
{
|
||||
FILEIO *fiop;
|
||||
|
||||
fiop = findid(id, 0);
|
||||
fiop = findid(id, -1);
|
||||
if (fiop == NULL)
|
||||
return -2;
|
||||
return isatty(fileno(fiop->fp));
|
||||
@@ -2445,7 +2477,7 @@ fsearch(FILEID id, char *str, ZVALUE start, ZVALUE end, ZVALUE *res)
|
||||
long k = 0;
|
||||
|
||||
/* get FILEIO */
|
||||
fiop = findid(id, 'r');
|
||||
fiop = findid(id, FALSE);
|
||||
if (fiop == NULL)
|
||||
return -2;
|
||||
|
||||
@@ -2564,7 +2596,7 @@ frsearch(FILEID id, char *str, ZVALUE first, ZVALUE last, ZVALUE *res)
|
||||
char *s; /* str comparison pointer */
|
||||
|
||||
/* get FILEIO */
|
||||
fiop = findid(id, 'r');
|
||||
fiop = findid(id, FALSE);
|
||||
if (fiop == NULL)
|
||||
return -2;
|
||||
|
||||
@@ -2641,7 +2673,7 @@ findfname(FILEID id)
|
||||
{
|
||||
FILEIO *fiop;
|
||||
|
||||
fiop = findid(id, 0);
|
||||
fiop = findid(id, -1);
|
||||
|
||||
if (fiop == NULL)
|
||||
return NULL;
|
||||
|
8
file.h
8
file.h
@@ -19,8 +19,8 @@
|
||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* @(#) $Revision: 29.2 $
|
||||
* @(#) $Id: file.h,v 29.2 2000/06/07 14:02:13 chongo Exp $
|
||||
* @(#) $Revision: 29.3 $
|
||||
* @(#) $Id: file.h,v 29.3 2001/04/10 22:06:46 chongo Exp $
|
||||
* @(#) $Source: /usr/local/src/cmd/calc/RCS/file.h,v $
|
||||
*
|
||||
* Under source code control: 1996/05/24 05:55:58
|
||||
@@ -50,7 +50,7 @@ typedef struct {
|
||||
BOOL reading; /* TRUE if opened for reading */
|
||||
BOOL writing; /* TRUE if opened for writing */
|
||||
char action; /* most recent use for 'r', 'w' or 0 */
|
||||
char mode[3]; /* open mode */
|
||||
char mode[sizeof("rb+")];/* open mode */
|
||||
} FILEIO;
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ typedef struct {
|
||||
/*
|
||||
* external functions
|
||||
*/
|
||||
extern FILEIO * findid(FILEID id, int mode);
|
||||
extern FILEIO * findid(FILEID id, int writable);
|
||||
extern int fgetposid(FILEID id, FILEPOS *ptr);
|
||||
extern int fsetposid(FILEID id, FILEPOS *ptr);
|
||||
extern int get_open_siz(FILE *fp, ZVALUE *res);
|
||||
|
41
func.c
41
func.c
@@ -19,8 +19,8 @@
|
||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* @(#) $Revision: 29.8 $
|
||||
* @(#) $Id: func.c,v 29.8 2001/04/08 10:06:56 chongo Exp $
|
||||
* @(#) $Revision: 29.9 $
|
||||
* @(#) $Id: func.c,v 29.9 2001/04/10 22:06:46 chongo Exp $
|
||||
* @(#) $Source: /usr/local/src/cmd/calc/RCS/func.c,v $
|
||||
*
|
||||
* Under source code control: 1990/02/15 01:48:15
|
||||
@@ -4987,24 +4987,31 @@ f_fopen(VALUE *v1, VALUE *v2)
|
||||
/* initialize VALUE */
|
||||
result.v_subtype = V_NOSUBTYPE;
|
||||
|
||||
/* check for a valid mode [rwa][b+\0][b+\0] */
|
||||
if (v1->v_type != V_STR || v2->v_type != V_STR)
|
||||
return error_value(E_FOPEN1);
|
||||
mode = v2->v_str->s_str;
|
||||
|
||||
if ((*mode != 'r') && (*mode != 'w') && (*mode != 'a'))
|
||||
return error_value(E_FOPEN2);
|
||||
if (mode[1] != '\0') {
|
||||
if (mode[1] != '+')
|
||||
return error_value(E_FOPEN2);
|
||||
if (mode[2] != '\0')
|
||||
if (mode[1] != '+' && mode[1] != 'b')
|
||||
return error_value(E_FOPEN2);
|
||||
if (mode[2] != '\0') {
|
||||
if ((mode[2] != '+' && mode[2] != 'b') ||
|
||||
mode[1] == mode[2])
|
||||
return error_value(E_FOPEN2);
|
||||
if (mode[3] != '\0')
|
||||
return error_value(E_FOPEN2);
|
||||
}
|
||||
}
|
||||
|
||||
/* try to open */
|
||||
errno = 0;
|
||||
id = openid(v1->v_str->s_str, v2->v_str->s_str);
|
||||
if (id == FILEID_NONE)
|
||||
return error_value(errno);
|
||||
if (id < 0)
|
||||
return error_value(E_FOPEN3);
|
||||
return error_value(-id);
|
||||
result.v_type = V_FILE;
|
||||
result.v_file = id;
|
||||
return result;
|
||||
@@ -5021,21 +5028,27 @@ f_freopen(int count, VALUE **vals)
|
||||
/* initialize VALUE */
|
||||
result.v_subtype = V_NOSUBTYPE;
|
||||
|
||||
/* check for a valid mode [rwa][b+\0][b+\0] */
|
||||
if (vals[0]->v_type != V_FILE)
|
||||
return error_value(E_FREOPEN1);
|
||||
if (vals[1]->v_type != V_STR)
|
||||
return error_value(E_FREOPEN2);
|
||||
|
||||
mode = vals[1]->v_str->s_str;
|
||||
|
||||
if ((*mode != 'r') && (*mode != 'w') && (*mode != 'a'))
|
||||
return error_value(E_FREOPEN2);
|
||||
if (mode[1] != '\0') {
|
||||
if (mode[1] != '+')
|
||||
return error_value(E_FREOPEN2);
|
||||
if (mode[2] != '\0')
|
||||
if (mode[1] != '+' && mode[1] != 'b')
|
||||
return error_value(E_FREOPEN2);
|
||||
if (mode[2] != '\0') {
|
||||
if ((mode[2] != '+' && mode[2] != 'b') ||
|
||||
mode[1] == mode[2])
|
||||
return error_value(E_FOPEN2);
|
||||
if (mode[3] != '\0')
|
||||
return error_value(E_FREOPEN2);
|
||||
}
|
||||
}
|
||||
|
||||
/* try to reopen */
|
||||
errno = 0;
|
||||
if (count == 2) {
|
||||
id = reopenid(vals[0]->v_file, mode, NULL);
|
||||
@@ -6141,10 +6154,10 @@ f_fgetfield(VALUE *vp)
|
||||
result.v_subtype = V_NOSUBTYPE;
|
||||
|
||||
if (vp->v_type != V_FILE)
|
||||
return error_value(E_FGETWORD1);
|
||||
return error_value(E_FGETFIELD1);
|
||||
i = readid(vp->v_file, 14, &str);
|
||||
if (i > 0)
|
||||
return error_value(E_FGETWORD2);
|
||||
return error_value(E_FGETFIELD2);
|
||||
result.v_type = V_NULL;
|
||||
if (i == 0) {
|
||||
result.v_type = V_STR;
|
||||
|
5
hash.c
5
hash.c
@@ -17,8 +17,8 @@
|
||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* @(#) $Revision: 29.3 $
|
||||
* @(#) $Id: hash.c,v 29.3 2000/06/07 14:02:13 chongo Exp $
|
||||
* @(#) $Revision: 29.4 $
|
||||
* @(#) $Id: hash.c,v 29.4 2001/04/14 22:47:21 chongo Exp $
|
||||
* @(#) $Source: /usr/local/src/cmd/calc/RCS/hash.c,v $
|
||||
*
|
||||
* Under source code control: 1995/11/23 05:13:11
|
||||
@@ -911,6 +911,7 @@ hash_value(int type, void *v, HASH *state)
|
||||
(USB8 *)value->v_rand->buffer, SLEN*FULL_BITS/8);
|
||||
state = hash_int(type, value->v_rand->j, state);
|
||||
state = hash_int(type, value->v_rand->k, state);
|
||||
state = hash_int(type, value->v_rand->need_to_skip, state);
|
||||
(state->update)(state,
|
||||
(USB8 *)value->v_rand->slot, SCNT*FULL_BITS/8);
|
||||
(state->update)(state,
|
||||
|
@@ -510,7 +510,9 @@ Detailed config descriptions
|
||||
|
||||
5 Report on changes to the run state of calc.
|
||||
|
||||
Bits >= 6 are reserved for future use and should not be used at this time.
|
||||
6 Report on rand() subtractive 100 shuffle generator issues.
|
||||
|
||||
Bits >= 7 are reserved for future use and should not be used at this time.
|
||||
|
||||
By default, "calc_debug" is 0. The initial value may be overridden
|
||||
by the -D command line option.
|
||||
@@ -709,8 +711,8 @@ Detailed config descriptions
|
||||
## received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
##
|
||||
## @(#) $Revision: 29.4 $
|
||||
## @(#) $Id: config,v 29.4 2001/04/08 09:08:27 chongo Exp $
|
||||
## @(#) $Revision: 29.5 $
|
||||
## @(#) $Id: config,v 29.5 2001/04/14 22:46:33 chongo Exp $
|
||||
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/config,v $
|
||||
##
|
||||
## Under source code control: 1991/07/21 04:37:17
|
||||
|
40
help/fopen
40
help/fopen
@@ -15,9 +15,39 @@ DESCRIPTION
|
||||
opened for either reading, writing, or appending. The mode
|
||||
is controlled by the mode flag as follows:
|
||||
|
||||
"r" reading
|
||||
"w" writing
|
||||
"a" appending
|
||||
allow allow file is positioned file(*)
|
||||
mode reading writing truncated at mode
|
||||
---- ------- ------- --------- --------- ----
|
||||
r Y N N beginning text
|
||||
rb Y N N beginning binary
|
||||
r+ Y N N beginning text
|
||||
r+b Y N N beginning binary
|
||||
rb+ Y N N beginning binary
|
||||
|
||||
w N Y Y beginning text
|
||||
wb N Y Y beginning binary
|
||||
w+ Y Y Y beginning text
|
||||
w+b Y Y Y beginning binary
|
||||
wb+ Y Y Y beginning binary
|
||||
|
||||
a N Y Y end text
|
||||
ab N Y Y end binary
|
||||
a+ Y Y Y end text
|
||||
a+b Y Y Y end binary
|
||||
ab+ Y Y Y end binary
|
||||
|
||||
(*) NOTE on 'b' / binary/text mode:
|
||||
|
||||
The 'b' or fopen binary mode has no effect on POSIX / Linux
|
||||
/ Un*x-like systems. On those systems a text file is the
|
||||
same as a binary file (as it should be for any modern-day
|
||||
operating system). Adding 'b' to an fopen has no effect
|
||||
and is ignored.
|
||||
|
||||
Some non-POSIX systems sucn as MS Windoz treat text files
|
||||
and binary files differently. In text mode MS Windoz consider
|
||||
"\r\n" and end-of-line character. On an Apple MAC, the
|
||||
text mode end-of-line character is "\r".
|
||||
|
||||
Names of files are subject to ~ expansion just like the C or
|
||||
Korn shell. For example, the file name:
|
||||
@@ -90,8 +120,8 @@ SEE ALSO
|
||||
## received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
##
|
||||
## @(#) $Revision: 29.2 $
|
||||
## @(#) $Id: fopen,v 29.2 2000/06/07 14:02:33 chongo Exp $
|
||||
## @(#) $Revision: 29.3 $
|
||||
## @(#) $Id: fopen,v 29.3 2001/04/10 21:46:45 chongo Exp $
|
||||
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/fopen,v $
|
||||
##
|
||||
## Under source code control: 1994/10/27 03:04:17
|
||||
|
82
help/rand
82
help/rand
@@ -1,5 +1,5 @@
|
||||
NAME
|
||||
rand - additive 55 shuffle pseudo-random number generator
|
||||
rand - subtractive 100 shuffle pseudo-random number generator
|
||||
|
||||
SYNOPSIS
|
||||
rand([[min, ] max])
|
||||
@@ -11,7 +11,7 @@ TYPES
|
||||
return integer
|
||||
|
||||
DESCRIPTION
|
||||
Generate a pseudo-random number using an additive 55 shuffle generator.
|
||||
Generate a pseudo-random number using an subtractive 100 shuffle generator.
|
||||
We return a pseudo-random number over the half closed interval [min,max).
|
||||
By default, min is 0 and max is 2^64.
|
||||
|
||||
@@ -38,36 +38,40 @@ DESCRIPTION
|
||||
|
||||
when seeded with the same seed.
|
||||
|
||||
The rand generator has two distinct parts, the additive 55 method
|
||||
and the shuffle method. The additive 55 method is described in:
|
||||
The rand generator has two distinct parts, the subtractive 100 method
|
||||
and the shuffle method. The subtractive 100 method is described in:
|
||||
|
||||
"The Art of Computer Programming - Seminumerical Algorithms"
|
||||
by Knuth, Vol 2, 2nd edition (1981), Section 3.2.2, page 27,
|
||||
Algorithm A.
|
||||
"The Art of Computer Programming - Seminumerical Algorithms",
|
||||
Vol 2, 3rd edition (1998), Section 3.6, page 186, formula (2).
|
||||
|
||||
The period and other properties of the additive 55 method
|
||||
The "use only the first 100 our of every 1009" is described in
|
||||
Knuth's "The Art of Computer Programming - Seminumerical Algorithms",
|
||||
Vol 2, 3rd edition (1998), Section 3.6, page 188".
|
||||
|
||||
The period and other properties of the subtractive 100 method
|
||||
make it very useful to 'seed' other generators.
|
||||
|
||||
The shuffle method is feed values by the additive 55 method.
|
||||
The shuffle method is feed values by the subtractive 100 method.
|
||||
The shuffle method is described in:
|
||||
|
||||
"The Art of Computer Programming - Seminumerical Algorithms"
|
||||
by Knuth, Vol 2, 2nd edition (1981), Section 3.2.2, page 32,
|
||||
Algorithm B.
|
||||
"The Art of Computer Programming - Seminumerical Algorithms",
|
||||
Vol 2, 3rd edition (1998), Section 3.2.2, page 34, Algorithm B.
|
||||
|
||||
The rand generator has a good period, and is fast. It is reasonable as
|
||||
generators go, though there are better ones available. The shuffle
|
||||
method has a very good period, and is fast. It is fairly good as
|
||||
generators go, particularly when it is feed reasonably random
|
||||
numbers. Because of this, we use feed values from the additive 55
|
||||
numbers. Because of this, we use feed values from the subtractive 100
|
||||
method into the shuffle method.
|
||||
|
||||
The rand generator uses two internal tables:
|
||||
|
||||
additive table - 55 entries of 64 bits used by the additive 55 method
|
||||
additive table - 100 entries of 64 bits used by the subtractive
|
||||
100 method
|
||||
|
||||
shuffle table - 256 entries of 64 bits used by the shuffle method
|
||||
feed by the additive 55 method from the additive table
|
||||
feed by the subtractive 100 method from the
|
||||
subtractive table
|
||||
|
||||
The goals of this generator are:
|
||||
|
||||
@@ -95,21 +99,21 @@ DESCRIPTION
|
||||
a standard against which other generators may be measured.
|
||||
|
||||
The Rand book of numbers was groups into groups of 20 digits. The
|
||||
first 55 groups < 2^64 were used to initialize the default additive
|
||||
first 100 groups < 2^64 were used to initialize the default additive
|
||||
table. The size of 20 digits was used because 2^64 is 20 digits
|
||||
long. The restriction of < 2^64 was used to prevent modulus biasing.
|
||||
|
||||
The shuffle table size is longer than the 100 entries recommended
|
||||
by Knuth. We use a power of 2 shuffle table length so that the
|
||||
shuffle process can select a table entry from a new additive 55
|
||||
shuffle process can select a table entry from a new subtractive 100
|
||||
value by extracting its low order bits. The value 256 is convenient
|
||||
in that it is the size of a byte which allows for easy extraction.
|
||||
|
||||
We use the upper byte of the additive 55 value to select the
|
||||
We use the upper byte of the subtractive 100 value to select the
|
||||
shuffle table entry because it allows all of 64 bits to play a part
|
||||
in the entry selection. If we were to select a lower 8 bits in the
|
||||
64 bit value, carries that propagate above our 8 bits would not
|
||||
impact the additive 55 generator output.
|
||||
impact the subtractive 100 generator output.
|
||||
|
||||
It is 'nice' when a seed of "n" produces a 'significantly different'
|
||||
sequence than a seed of "n+1". Generators, by convention, assign
|
||||
@@ -161,7 +165,7 @@ DESCRIPTION
|
||||
The values 'a' and 'c for randreseed64 are taken from the Rand book
|
||||
of numbers. Because m=2^64 is 20 decimal digits long, we will
|
||||
search the Rand book of numbers 20 at a time. We will skip any of
|
||||
the 55 values that were used to initialize the additive 55
|
||||
the 100 values that were used to initialize the subtractive 100
|
||||
generators. The values obtained from the Rand book are:
|
||||
|
||||
a = 6316878969928993981
|
||||
@@ -190,36 +194,40 @@ DESCRIPTION
|
||||
|
||||
The truly paranoid might suggest that my claims in the MAGIC NUMBERS
|
||||
section are a lie intended to entrap people. Well they are not, but
|
||||
you need not take my (Landon Curt Noll) word for it.
|
||||
if you that paranoid why would you use a non-cryprographically strong
|
||||
pseudo-random number generator in the first place? You would be
|
||||
better off using the random() builtin function.
|
||||
|
||||
The random numbers from the Rand book of random numbers can be
|
||||
The two constants that were picked from the Rand Book of Random Numbers
|
||||
The random numbers from the Rand Book of Random Numbers can be
|
||||
verified by anyone who obtains the book. As these numbers were
|
||||
created before I (Landon Curt Noll) was born (you can look up my
|
||||
birth record if you want), I claim to have no possible influence on
|
||||
their generation.
|
||||
created before I (Landon Curt Noll) was born (you can look up
|
||||
my birth record if you want), I claim to have no possible influence
|
||||
on their generation.
|
||||
|
||||
There is a very slight chance that the electronic copy of the
|
||||
Rand book that I was given access to differs from the printed text.
|
||||
I am willing to provide access to this electronic copy should
|
||||
anyone wants to compare it to the printed text.
|
||||
Rand Book of Random Numbers that I was given access to differs
|
||||
from the printed text. I am willing to provide access to this
|
||||
electronic copy should anyone wants to compare it to the printed text.
|
||||
|
||||
When using the a55 generator, one may select your own 55 additive
|
||||
When using the s100 generator, one may select your own 100 subtractive
|
||||
values by calling:
|
||||
|
||||
srand(mat55)
|
||||
srand(mat100)
|
||||
|
||||
and avoid using my magic numbers. Of course, you must pick good
|
||||
additive 55 values yourself!
|
||||
and avoid using my magic numbers. The randreseed64 process is NOT
|
||||
applied to the matrix values. Of course, you must pick good subtractive
|
||||
100 values yourself!
|
||||
|
||||
EXAMPLE
|
||||
> print srand(0), rand(), rand(), rand()
|
||||
RAND state 14384206130809570460 10173010522823332484 5713611208311484212
|
||||
RAND state 2298441576805697181 3498508396312845423 5031615567549397476
|
||||
|
||||
> print rand(123), rand(123), rand(123), rand(123), rand(123), rand(123)
|
||||
17 104 74 47 48 46
|
||||
106 59 99 99 25 88
|
||||
|
||||
> print rand(2,12), rand(2^50,3^50), rand(0,2), rand(-400000, 120000)
|
||||
11 170570393286648531699560 1 -96605
|
||||
2 658186291252503497642116 1 -324097
|
||||
|
||||
LIMITS
|
||||
min < max
|
||||
@@ -248,8 +256,8 @@ SEE ALSO
|
||||
## received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
##
|
||||
## @(#) $Revision: 29.2 $
|
||||
## @(#) $Id: rand,v 29.2 2000/06/07 14:02:33 chongo Exp $
|
||||
## @(#) $Revision: 29.3 $
|
||||
## @(#) $Id: rand,v 29.3 2001/04/14 22:46:33 chongo Exp $
|
||||
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/rand,v $
|
||||
##
|
||||
## Under source code control: 1996/01/01 02:16:09
|
||||
|
74
help/srand
74
help/srand
@@ -1,5 +1,5 @@
|
||||
NAME
|
||||
srand - seed the additive 55 shuffle pseudo-random number generator
|
||||
srand - seed the subtractive 100 shuffle pseudo-random number generator
|
||||
|
||||
SYNOPSIS
|
||||
srand([seed])
|
||||
@@ -10,43 +10,43 @@ TYPES
|
||||
return rand state
|
||||
|
||||
DESCRIPTION
|
||||
Seed the pseudo-random number using an additive 55 shuffle generator.
|
||||
Seed the pseudo-random number using an subtractive 100 shuffle generator.
|
||||
|
||||
For integer seed != 0:
|
||||
|
||||
Any buffered rand generator bits are flushed. The additive table
|
||||
for the rand generator is loaded with the default additive table.
|
||||
Any buffered rand generator bits are flushed. The subtractive table
|
||||
for the rand generator is loaded with the default subtractive table.
|
||||
The low order 64 bits of seed is xor-ed against each table value.
|
||||
The additive table is shuffled according to seed/2^64.
|
||||
The subtractive table is shuffled according to seed/2^64.
|
||||
|
||||
The following calc code produces the same effect on the internal
|
||||
additive table:
|
||||
subtractive table:
|
||||
|
||||
/* reload default additive table xor-ed with low 64 seed bits */
|
||||
/* reload default subtractive table xor-ed with low 64 seed bits */
|
||||
seed_xor = seed & ((1<<64)-1);
|
||||
for (i=0; i < 55; ++i) {
|
||||
additive[i] = xor(default_additive[i], seed_xor);
|
||||
for (i=0; i < 100; ++i) {
|
||||
subtractive[i] = xor(default_subtractive[i], seed_xor);
|
||||
}
|
||||
|
||||
/* shuffle the additive table */
|
||||
/* shuffle the subtractive table */
|
||||
seed >>= 64;
|
||||
for (i=55; seed > 0 && i > 0; --i) {
|
||||
for (i=100; seed > 0 && i > 0; --i) {
|
||||
quomod(seed, i+1, seed, j);
|
||||
swap(additive[i], additive[j]);
|
||||
swap(subtractive[i], subtractive[j]);
|
||||
}
|
||||
|
||||
Seed must be >= 0. All seed values < 0 are reserved for future use.
|
||||
|
||||
The additive table pointers are reset to additive[23] and additive[54].
|
||||
Last the shuffle table is loaded with successive values from the
|
||||
additive 55 generator.
|
||||
The subtractive table pointers are reset to subtractive[36]
|
||||
and subtractive[99]. Last the shuffle table is loaded with
|
||||
successive values from the subtractive 100 generator.
|
||||
|
||||
There is no limit on the size of a seed. On the other hand,
|
||||
extremely large seeds require large tables and long seed times.
|
||||
Using a seed in the range of [2^64, 2^64 * 55!) should be
|
||||
Using a seed in the range of [2^64, 2^64 * 100!) should be
|
||||
sufficient for most purposes. An easy way to stay within this
|
||||
range to to use seeds that are between 21 and 93 digits, or
|
||||
64 to 308 bits long.
|
||||
range to to use seeds that are between 21 and 178 digits, or
|
||||
64 to 588 bits long.
|
||||
|
||||
To help make the generator produced by seed S, significantly
|
||||
different from S+1, seeds are scrambled prior to use. The
|
||||
@@ -68,9 +68,9 @@ DESCRIPTION
|
||||
After this call, the rand generator is restored to its initial
|
||||
state after calc started.
|
||||
|
||||
The additive 55 pointers are reset to additive[23] and additive[54].
|
||||
Last the shuffle table is loaded with successive values from the
|
||||
additive 55 generator.
|
||||
The subtractive 100 pointers are reset to subtractive[36]
|
||||
and subtractive[99]. Last the shuffle table is loaded with
|
||||
successive values from the subtractive 100 generator.
|
||||
|
||||
The call:
|
||||
|
||||
@@ -80,14 +80,14 @@ DESCRIPTION
|
||||
|
||||
For matrix arg:
|
||||
|
||||
Any buffered random bits are flushed. The additive table with the
|
||||
first 55 entries of the matrix mod 2^64.
|
||||
Any buffered random bits are flushed. The subtractive table with the
|
||||
first 100 entries of the matrix mod 2^64.
|
||||
|
||||
The additive 55 pointers are reset to additive[23] and additive[54].
|
||||
Last the shuffle table is loaded with successive values from the
|
||||
additive 55 generator.
|
||||
The subtractive 100 pointers are reset to subtractive[36]
|
||||
and subtractive[99]. Last the shuffle table is loaded with
|
||||
successive values from the subtractive 100 generator.
|
||||
|
||||
This form allows one to load the internal additive 55 generator
|
||||
This form allows one to load the internal subtractive 100 generator
|
||||
with user supplied values.
|
||||
|
||||
The randreseed64 process is NOT applied to the matrix values.
|
||||
@@ -114,7 +114,7 @@ DESCRIPTION
|
||||
|
||||
For no arg given:
|
||||
|
||||
Return current a55 generator state. This call does not alter
|
||||
Return current s100 generator state. This call does not alter
|
||||
the generator state.
|
||||
|
||||
This call allows one to take a snapshot of the current generator state.
|
||||
@@ -126,25 +126,25 @@ EXAMPLE
|
||||
RAND state
|
||||
> state = srand();
|
||||
> print rand(123), rand(123), rand(123), rand(123), rand(123), rand(123);
|
||||
32 60 67 71 1 77
|
||||
80 95 41 78 100 27
|
||||
> print rand(123), rand(123), rand(123), rand(123), rand(123), rand(123);
|
||||
52 72 110 15 69 58
|
||||
122 109 12 95 80 32
|
||||
> state2 = srand(state);
|
||||
> print rand(123), rand(123), rand(123), rand(123), rand(123), rand(123);
|
||||
32 60 67 71 1 77
|
||||
80 95 41 78 100 27
|
||||
> print rand(123), rand(123), rand(123), rand(123), rand(123), rand(123);
|
||||
52 72 110 15 69 58
|
||||
122 109 12 95 80 32
|
||||
> state3 = srand();
|
||||
> print state3 == state2;
|
||||
1
|
||||
> print rand();
|
||||
641407694185874626
|
||||
10710588361472584495
|
||||
|
||||
LIMITS
|
||||
for matrix arg, the matrix must have at least 55 integers
|
||||
for matrix arg, the matrix must have at least 100 integers
|
||||
|
||||
LINK LIBRARY
|
||||
RAND *zsrand(ZVALUE *pseed, MATRIX *pmat55)
|
||||
RAND *zsrand(ZVALUE *pseed, MATRIX *pmat100)
|
||||
RAND *zsetrand(RAND *state)
|
||||
|
||||
SEE ALSO
|
||||
@@ -166,8 +166,8 @@ SEE ALSO
|
||||
## received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
##
|
||||
## @(#) $Revision: 29.2 $
|
||||
## @(#) $Id: srand,v 29.2 2000/06/07 14:02:33 chongo Exp $
|
||||
## @(#) $Revision: 29.3 $
|
||||
## @(#) $Id: srand,v 29.3 2001/04/14 22:46:33 chongo Exp $
|
||||
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/srand,v $
|
||||
##
|
||||
## Under source code control: 1996/01/01 04:19:07
|
||||
|
10
lib_calc.c
10
lib_calc.c
@@ -17,8 +17,8 @@
|
||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* @(#) $Revision: 29.6 $
|
||||
* @(#) $Id: lib_calc.c,v 29.6 2001/03/17 21:31:47 chongo Exp $
|
||||
* @(#) $Revision: 29.7 $
|
||||
* @(#) $Id: lib_calc.c,v 29.7 2001/04/08 22:05:40 chongo Exp $
|
||||
* @(#) $Source: /usr/local/src/cmd/calc/RCS/lib_calc.c,v $
|
||||
*
|
||||
* Under source code control: 1996/06/17 18:06:19
|
||||
@@ -753,10 +753,10 @@ calc_tty(int fd)
|
||||
printf("calc_tty: stty -ECHO -ECHOE -ECHOK -ICANON +ISTRIP "
|
||||
"VMIN=1 VTIME=0: fd %d\n", fd);
|
||||
|
||||
#elif defined (USE_SGTTY)/* assume USE_SGTTY */
|
||||
#elif defined (USE_TERMIOS)
|
||||
|
||||
/*
|
||||
* assume USE_SGTTY tty state method
|
||||
* USE_TERMIOS tty state method
|
||||
*/
|
||||
if (fd_setup[slot] < 0 && tcgetattr(fd, fd_orig+slot) < 0) {
|
||||
if (conf->calc_debug & CALCDBG_TTY)
|
||||
@@ -848,7 +848,7 @@ orig_tty(int fd)
|
||||
if (conf->calc_debug & CALCDBG_TTY)
|
||||
printf("orig_tty: TCSETAW restored fd %d\n", fd);
|
||||
|
||||
#elif defined (USE_SGTTY)/* assume USE_SGTTY */
|
||||
#elif defined (USE_TERMIOS)
|
||||
|
||||
/*
|
||||
* assume USE_SGTTY tty state method
|
||||
|
@@ -17,8 +17,8 @@
|
||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* @(#) $Revision: 29.3 $
|
||||
* @(#) $Id: quickhash.c,v 29.3 2000/06/07 14:02:13 chongo Exp $
|
||||
* @(#) $Revision: 29.4 $
|
||||
* @(#) $Id: quickhash.c,v 29.4 2001/04/14 22:47:21 chongo Exp $
|
||||
* @(#) $Source: /usr/local/src/cmd/calc/RCS/quickhash.c,v $
|
||||
*
|
||||
* Under source code control: 1995/03/04 11:34:23
|
||||
@@ -304,7 +304,7 @@ objhash(OBJECT *op, QCKHASH val)
|
||||
|
||||
|
||||
/*
|
||||
* randhash - return a trivial hash for an a55 state
|
||||
* randhash - return a trivial hash for an s100 state
|
||||
*
|
||||
* given:
|
||||
* state - state to hash
|
||||
@@ -326,6 +326,7 @@ randhash(RAND *r, QCKHASH val)
|
||||
val = fnv(r->j, V_RAND+val);
|
||||
val = fnv(r->k, val);
|
||||
val = fnv(r->bits, val);
|
||||
val = fnv(r->need_to_skip, val);
|
||||
|
||||
/* hash the state arrays */
|
||||
return fnv_fullhash(&r->buffer[0], SLEN+SCNT+SHUFLEN, val);
|
||||
|
@@ -19,8 +19,8 @@
|
||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* @(#) $Revision: 29.21 $
|
||||
* @(#) $Id: version.c,v 29.21 2001/04/08 10:09:20 chongo Exp $
|
||||
* @(#) $Revision: 29.24 $
|
||||
* @(#) $Id: version.c,v 29.24 2001/04/14 22:56:46 chongo Exp $
|
||||
* @(#) $Source: /usr/local/src/cmd/calc/RCS/version.c,v $
|
||||
*
|
||||
* Under source code control: 1990/05/22 11:00:58
|
||||
@@ -43,7 +43,7 @@ static char *program;
|
||||
#define MAJOR_VER 2 /* major version */
|
||||
#define MINOR_VER 11 /* minor version */
|
||||
#define MAJOR_PATCH 5 /* patch level or 0 if no patch */
|
||||
#define MINOR_PATCH "1.1" /* test number or empty string if no patch */
|
||||
#define MINOR_PATCH "3" /* test number or empty string if no patch */
|
||||
|
||||
/*
|
||||
* calc version constants
|
||||
|
58
win32.mkdef
Normal file
58
win32.mkdef
Normal file
@@ -0,0 +1,58 @@
|
||||
TERMCONTROL=-DUSE_WIN32
|
||||
HAVE_VSPRINTF=-UDONT_HAVE_VSPRINTF
|
||||
BYTE_ORDER=-DLITTLE_ENDIAN
|
||||
LONG_BITS=32
|
||||
LONGLONG_BITS=0
|
||||
HAVE_FPOS=-DHAVE_NO_FPOS
|
||||
HAVE_FPOS_POS=-DHAVE_NO_FPOS_POS
|
||||
FPOS_POS_BITS=-UFPOS_POS_BITS
|
||||
FPOS_BITS=-DFPOS_BITS=64
|
||||
OFF_T_BITS=-DOFF_T_BITS=32
|
||||
DEV_BITS=-DDEV_BITS=32
|
||||
INODE_BITS=-DINODE_BITS=16
|
||||
HAVE_OFFSCL=-UOFF_T_NON_SCALAR
|
||||
HAVE_POSSCL=-UFILEPOS_NON_SCALAR
|
||||
HAVE_CONST=-UHAVE_NO_CONST
|
||||
HAVE_UID_T=-DHAVE_NO_UID_T
|
||||
HAVE_NEWSTR=-UHAVE_NO_NEWSTR
|
||||
HAVE_MEMMOVE=-UHAVE_NO_MEMMOVE
|
||||
HAVE_USTAT=-DHAVE_NO_USTAT
|
||||
HAVE_GETSID=-DHAVE_NO_GETSID
|
||||
HAVE_GETPGID=-DHAVE_NO_GETPGID
|
||||
HAVE_GETTIME=-DHAVE_NO_GETTIME
|
||||
HAVE_GETPRID=-DHAVE_NO_GETPRID
|
||||
HAVE_URANDOM_H=NO
|
||||
HAVE_GETRUSAGE=-DHAVE_NO_GETRUSAGE
|
||||
HAVE_STRDUP=-UHAVE_NO_STRDUP
|
||||
ALIGN32=-UMUST_ALIGN32
|
||||
HAVE_MALLOC_H=YES
|
||||
HAVE_STDLIB_H=YES
|
||||
HAVE_STRING_H=YES
|
||||
HAVE_TIMES_H=NO
|
||||
HAVE_SYS_TIMES_H=NO
|
||||
HAVE_TIME_H=YES
|
||||
HAVE_SYS_TIME_H=NO
|
||||
HAVE_UNISTD_H=NO
|
||||
|
||||
LIBDIR=/lib/calc
|
||||
HELPDIR=/lib/calc/help
|
||||
INCDIRCALC=/include/calc
|
||||
CUSTOMLIBDIR=/lib/calc/custom
|
||||
CUSTOMHELPDIR=/lib/calc/help/custhelp
|
||||
SCRIPTDIR=/lib/calc/cscript
|
||||
MANDIR=
|
||||
CATDIR=
|
||||
MANEXT=
|
||||
CATEXT=
|
||||
NROFF=
|
||||
NROFF_ARG=
|
||||
MANMAKE=
|
||||
MANMODE=
|
||||
CALCPATH=./cal
|
||||
CALCRC='/lib/calc/startup:~/.calcrc:./.calcinit'
|
||||
USE_READLINE=
|
||||
READLINE_LIB=
|
||||
READLINE_INCLUDE=
|
||||
CALCPAGER=
|
||||
|
||||
ECHO=
|
@@ -90,8 +90,8 @@ CONST char *error_table[E__COUNT+2] = {
|
||||
"File not open for reading for fgetstr",
|
||||
"Non-file argument for fgetline",
|
||||
"File not open for reading for fgetline",
|
||||
"Non-file argument for fgetword",
|
||||
"File not open for reading for fgetword",
|
||||
"Non-file argument for fgetfield",
|
||||
"File not open for reading for fgetfield",
|
||||
"Non-file argument for rewind",
|
||||
"Non-integer argument for files",
|
||||
"Non-string fmt argument for fprint",
|
||||
|
@@ -87,8 +87,8 @@
|
||||
#define E_FGETSTR2 10074 /* File not open for reading for fgetstr */
|
||||
#define E_FGETLINE1 10075 /* Non-file argument for fgetline */
|
||||
#define E_FGETLINE2 10076 /* File not open for reading for fgetline */
|
||||
#define E_FGETWORD1 10077 /* Non-file argument for fgetword */
|
||||
#define E_FGETWORD2 10078 /* File not open for reading for fgetword */
|
||||
#define E_FGETFIELD1 10077 /* Non-file argument for fgetfield */
|
||||
#define E_FGETFIELD2 10078 /* File not open for reading for fgetfield */
|
||||
#define E_REWIND1 10079 /* Non-file argument for rewind */
|
||||
#define E_FILES 10080 /* Non-integer argument for files */
|
||||
#define E_PRINTF1 10081 /* Non-string fmt argument for fprint */
|
||||
|
58
zrand.h
58
zrand.h
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* zrand - additive 55 shuffle generator
|
||||
* zrand - subtractive 100 shuffle generator
|
||||
*
|
||||
* Copyright (C) 1999 Landon Curt Noll
|
||||
*
|
||||
@@ -17,8 +17,8 @@
|
||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* @(#) $Revision: 29.2 $
|
||||
* @(#) $Id: zrand.h,v 29.2 2000/06/07 14:02:13 chongo Exp $
|
||||
* @(#) $Revision: 29.3 $
|
||||
* @(#) $Id: zrand.h,v 29.3 2001/04/14 22:47:21 chongo Exp $
|
||||
* @(#) $Source: /usr/local/src/cmd/calc/RCS/zrand.h,v $
|
||||
*
|
||||
* Under source code control: 1995/01/07 09:45:26
|
||||
@@ -42,19 +42,19 @@
|
||||
|
||||
|
||||
/*
|
||||
* a55 generator defines
|
||||
* s100 generator defines
|
||||
*
|
||||
* NOTE: SBITS must be a power of two to make the (&= (SBITS-1))
|
||||
* in slotcp() to work.
|
||||
*/
|
||||
#define SBITS (64) /* size of additive or shuffle entry in bits */
|
||||
#define SBYTES (SBITS/8) /* size of additive or shuffle entry in bytes */
|
||||
#define SBITS (64) /* size of subtractive or shuffle entry in bits */
|
||||
#define SBYTES (SBITS/8) /* size of subtractive or shuffle entry in bytes */
|
||||
#define SHALFS (SBYTES/sizeof(HALF)) /* size in HALFs */
|
||||
|
||||
/*
|
||||
* seed defines
|
||||
*/
|
||||
#define SEEDXORBITS 64 /* low bits of a55 seed devoted to xor */
|
||||
#define SEEDXORBITS 64 /* low bits of s100 seed devoted to xor */
|
||||
|
||||
/*
|
||||
* shuffle table defines
|
||||
@@ -65,18 +65,18 @@
|
||||
#define SHUFMASK (SHUFLEN-1) /* mask for shuffle table entry selection */
|
||||
|
||||
/*
|
||||
* additive 55 constants
|
||||
* subtractive 100 constants
|
||||
*/
|
||||
#define A55 55 /* slots in an additive 55 table */
|
||||
#define INIT_J 23 /* initial first walking table index */
|
||||
#define INIT_K 54 /* initial second walking table index */
|
||||
#define S100 100 /* slots in an subtractive 100 table */
|
||||
#define INIT_J 36 /* initial first walking table index */
|
||||
#define INIT_K 99 /* initial second walking table index */
|
||||
|
||||
/*
|
||||
* additive 55 table defines
|
||||
* subtractive 100 table defines
|
||||
*
|
||||
* SLEN - length in FULLs of an additive 55 slot
|
||||
* SLEN - length in FULLs of an subtractive 100 slot
|
||||
*
|
||||
* SVAL(a,b) - form a 64 bit hex slot entry in the additive 55 table
|
||||
* SVAL(a,b) - form a 64 bit hex slot entry in the subtractive 100 table
|
||||
* a: up to 8 hex digits without the leading 0x (upper half)
|
||||
* b: up to 8 hex digits without the leading 0x (lower half)
|
||||
*
|
||||
@@ -90,12 +90,12 @@
|
||||
*
|
||||
* NOTE: Due to a SunOS cc bug, don't put spaces in the SHVAL call!
|
||||
*
|
||||
* SLOAD(s,i,z) - load table slot i from additive 55 state s with zvalue z
|
||||
* SLOAD(s,i,z) - load table slot i from subtractive 100 state s with zvalue z
|
||||
* s: type RAND
|
||||
* i: type int, s.slot[i] slot index
|
||||
* z: type ZVALUE, what to load into s.slot[i]
|
||||
*
|
||||
* SADD(s,k,j) - slot[k] += slot[j]
|
||||
* SSUB(s,k,j) - slot[k] -= slot[j]
|
||||
* s: type RAND
|
||||
* k: type int, s.slot[k] slot index, what to gets changed
|
||||
* j: type int, s.slot[j] slot index, what to add to s.slot[k]
|
||||
@@ -106,7 +106,7 @@
|
||||
* k: type int, s.slot[k] slot index, selects shuffle entry
|
||||
* result type int, refers to s.shuf[SINDX(s,k)]
|
||||
*
|
||||
* SBUFFER(s,t) - load a55 buffer with t
|
||||
* SBUFFER(s,t) - load s100 buffer with t
|
||||
* s: type RAND
|
||||
* t: type int, s.shuf[t] entry index, replace buffer with it
|
||||
*
|
||||
@@ -130,7 +130,7 @@
|
||||
* i: type int, s.slot[i] slot index, what gets xored
|
||||
* v: type FULL*, 64 bit value to xor into s.slot[i]
|
||||
*
|
||||
* SCNT - length of an additive 55 table in FULLs
|
||||
* SCNT - length of an subtractive 100 table in FULLs
|
||||
*/
|
||||
#if FULL_BITS == SBITS
|
||||
|
||||
@@ -143,7 +143,7 @@
|
||||
# define SHVAL(a,b,c,d) (HALF)0x/**/c/**/d,(HALF)0x/**/a/**/b
|
||||
# endif
|
||||
#define SLOAD(s,i,z) ((s).slot[i] = ztofull(z))
|
||||
#define SADD(s,k,j) ((s).slot[k] += (s).slot[j])
|
||||
#define SSUB(s,k,j) ((s).slot[k] -= (s).slot[j])
|
||||
#define SINDX(s,k) ((int)((s).slot[k] >> (FULL_BITS - SHUFPOW)))
|
||||
#define SBUFFER(s,t) {(s).buffer[0] = ((s).shuf[t] & BASE1); \
|
||||
(s).buffer[1] = ((s).shuf[t] >> BASEB); \
|
||||
@@ -176,9 +176,9 @@
|
||||
(((z).len == 3) ? (FULL)((z).v[2]) : \
|
||||
((FULL)((z).v[2]) + ((FULL)((z).v[3]) << BASEB)))); \
|
||||
}
|
||||
#define SADD(s,k,j) {FULL tmp = (s).slot[(k)<<1]; \
|
||||
(s).slot[(k)<<1] += (s).slot[(j)<<1]; \
|
||||
(s).slot[1+((k)<<1)] += ((tmp <= (s).slot[(k)<<1]) ? \
|
||||
#define SSUB(s,k,j) {FULL tmp = (s).slot[(k)<<1]; \
|
||||
(s).slot[(k)<<1] -= (s).slot[(j)<<1]; \
|
||||
(s).slot[1+((k)<<1)] -= ((tmp <= (s).slot[(k)<<1]) ? \
|
||||
(s).slot[1+((j)<<1)] : \
|
||||
(s).slot[1+((j)<<1)] + 1); \
|
||||
}
|
||||
@@ -213,11 +213,14 @@
|
||||
|
||||
#endif
|
||||
|
||||
#define SCNT (SLEN*A55) /* length of additive 55 table in FULLs */
|
||||
#define SCNT (SLEN*S100) /* length of subtractive 100 table in FULLs */
|
||||
|
||||
#define RAND_CONSEQ_USE (100) /* use this many before skipping */
|
||||
#define RAND_SKIP (1009-RAND_CONSEQ_USE) /* skip this many after use */
|
||||
|
||||
|
||||
/*
|
||||
* a55 generator state
|
||||
* s100 generator state
|
||||
*/
|
||||
struct rand {
|
||||
int seeded; /* 1 => state has been seeded */
|
||||
@@ -225,15 +228,16 @@ struct rand {
|
||||
FULL buffer[SLEN]; /* unused random bits from last call */
|
||||
int j; /* first walking table index */
|
||||
int k; /* second walking table index */
|
||||
FULL slot[SCNT]; /* additive 55 table */
|
||||
int need_to_skip; /* 1 => skip the next 909 values */
|
||||
FULL slot[SCNT]; /* subtractive 100 table */
|
||||
FULL shuf[SHUFLEN]; /* shuffle table entries */
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* a55 generator function declarations
|
||||
* s100 generator function declarations
|
||||
*/
|
||||
extern RAND *zsrand(CONST ZVALUE *seed, CONST MATRIX *pmat55);
|
||||
extern RAND *zsrand(CONST ZVALUE *seed, CONST MATRIX *pmat100);
|
||||
extern RAND *zsetrand(CONST RAND *state);
|
||||
extern void zrandskip(long count);
|
||||
extern void zrand(long count, ZVALUE *res);
|
||||
|
Reference in New Issue
Block a user