diff --git a/BUGS b/BUGS index f07ad8e..8a6e08a 100644 --- a/BUGS +++ b/BUGS @@ -68,33 +68,14 @@ of a context diff patch). Known bugs: + The stoponerror() facility does not seem to work, or perhaps + the stoponerror help file is incorrect. The stoponerror help file + lacks examples because of this problem. + We are sure some more bugs exist. When you find them, please let us know! See the above for details on how to report and were to EMail your bug reports and hopefully patches to fix them. - * The following command: - - calc 'read ellip; efactor(13*17*19)' - - will generate the following error: - - efactor(iN,ia,B,force) defined - point_print(p) defined - point_mul(p1,p2) defined - point_square(p) defined - point_pow(p,pow) defined - A = 1 - 2 (1,1) - "point_square": line 165: Not initializing matrix, object or list - Error in commands - - This is not an error in the ellip standard calc resource files. - It is a bug inside calc. Versions going back as far as version - 2.11.4t2 in the year 2000 (and perhaps even further) all have - this bug. - - Anyone want to track down and fix this bug? - =-= mis-features in calc: @@ -129,55 +110,6 @@ mis-features in calc: Problems with old systems that have known work-a-rounds: - * The gcc as shipped with Redhat 7 perhaps other Linux distributions - has a bug causes calc to dump core on startup when calc is: - - compiled optimized (-O, -O1, -O2 or -O3) - - AND - - compiled with debugging (-g or -g3) - - AND - - when calc is compiled with readline (see USE_READLINE, - READLINE_LIB and READLINE_INCLUDE in the Makefile) - - This is known as the Redhat 7 readlne problem. - - On Redhat, the gcc -v which has this problem is: - - gcc version 2.96 20000731 (Red Hat Linux 7.1 2.96-85) - - there may be other gcc versions that also suffer this fate. - - The readlines associated with problem are: - - readline-4.1-5 - readline2.2.1-2.2.1-2 - readline-devel-4.1-5 - - One work-a-round is to compile calc WITHOUT readline. In the - Makefile be sure that: - - USE_READLINE= - READLINE_LIB= - READLINE_INCLUDE= - - i.e., these Makefile vars are empty. - - If you must use readline, then an alternate work-a-round is to - change the DEBUG Makefile variable to either: - - compile for speed: -O3 (or -O2 if you do not have -O3) - compile to debug: -g3 (or -g if you do not have -g3) - - but not both. - - See RH bug #57889 for details: - - http://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=57889 - * There is a bug in gcc-2.95 that causes calc, when compiled with -O2, to fail the regression test. The work-a-round is to compile with -O or to use gcc-2.96 or later. @@ -227,59 +159,6 @@ Problems with old systems that have known work-a-rounds: if (n < 0) n = 0; z.sign = 0; - * Solaris cc somtimes barfs while compiling zrand.c. In particular, calc - barfs on on the SVAL macro. The work-a-round is to use the Solaric cc - Makefile set sets -DFORCE_STDC. I.e,: - - CCWARN= - CCOPT= ${DEBUG} ${NO_SHARED} - CCMISC= -DFORCE_STDC - # - CFLAGS= ${CCWARN} ${CCOPT} ${CCMISC} - ICFLAGS= ${CCWARN} ${CCMISC} - # - LCFLAGS= - LDFLAGS= ${NO_SHARED} ${LD_NO_SHARED} - ILDFLAGS= - # - LCC= cc - CC= ${PURIFY} ${LCC} - - * There is a bug in some versions of the Dec/Compaq cc for the Alpha - where the following: - - #include - #define SVAL(a,b) (unsigned long)(0x ## a ## b ## ULL) - main(){SVAL(b8a8aeb0,8168eadc);} - - fails because it puts a space inside the concatenated hex. Calc - has code that is affected by this bug. This bug has been reported - to Compaq and may be fixed in the future. A work-a-round is to - compile with cc -std0 or to use a later version of their compiler. - - * On a Digital UNIX V4.0F (Rev. 1229) on a 500 Mhz 21264, make check - dies a horrible death starting in test 600 and 622 gives 100s of - messages for calc version 2.11.0t9.4 using the Dec's cc with -O2: - - 600: Beginning test_bignums - 601: muldivcheck 1 - **** abc != acb: 602: muldivcheck 2 - **** acb != bac: 602: muldivcheck 2 - ... - **** t4 != a4: 622: algcheck 1 - **** t5 != a5: 622: algcheck 1 - **** t6 != a6: 622: algcheck 1 - **** t4 != a4: 622: algcheck 1 - ... - - it finally hangs at test 2000. - - The work-a-round is to compile calc without the optimizer. If this - happens to you, try compiling without -O and without -O2. I.e., in - the Makefile, set: - - DEBUG= -g - * There are problems compiling calc on the sparcv9 under 64 bit Solaris. On that platform, gcc-2.96 is able to compile calc, but calc dumps core very early on in startup. It is said that sparcv9 @@ -295,19 +174,7 @@ Problems with old systems that have known work-a-rounds: CCWARN="-DFORCE_STDC -w" DEBUG="-fast -xarch=v9" - * Under BSDI v4, the warnings of the form: - - /usr/include/ctype.h:147: warning: `__runetype' defined but not used - /usr/include/ctype.h:161: warning: `__isctype' defined but not used - /usr/include/ctype.h:170: warning: `toupper' defined but not used - /usr/include/ctype.h:177: warning: `tolower' defined but not used - - are seen. These warnings are the result of mis-features in BSDI - include files. They do not have an impact on the operation - or performance. The work-a-round is to ignore these warnings - under BSDI. - -## Copyright (C) 1999 Landon Curt Noll +## Copyright (C) 1999-2006 Landon Curt Noll ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License @@ -323,8 +190,8 @@ Problems with old systems that have known work-a-rounds: ## 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.22 $ -## @(#) $Id: BUGS,v 29.22 2004/10/23 02:25:02 chongo Exp $ +## @(#) $Revision: 29.24 $ +## @(#) $Id: BUGS,v 29.24 2006/05/21 07:54:13 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/RCS/BUGS,v $ ## ## Under source code control: 1994/03/18 14:06:13 diff --git a/CHANGES b/CHANGES index 5963aba..65155fd 100644 --- a/CHANGES +++ b/CHANGES @@ -1,11 +1,159 @@ -The following are the changes from calc version 2.11.10.1 to date: +The following are the changes from calc version 2.12.0 to date: + + Fixed ellip.cal to deal with a calc syntax change that happened + many ages ago but was never applied to this file until now. + This bug was fixed by Ernest Bowen . + + Fixed a problem where comments using # followed by a !, newline or + another # works. This bug was fixed by Ernest Bowen . + + The show builtins display for functions with long descriptions + is now broken into multi-line descriptions. + + The str functions, such as strcpy(s1, s2), will now copy as many + characters as possible from s2 to s1, treating '\0' like any other + character until the end of s2 is reached. If s2 is shorter than s1, + a '\0' is inserted. + + The strcmp(s1, s2) builtin, for strings s1, s2: strcmp(s1, s2) == 0 now + means the same as s1 == s2. + + The str(s) builtin has been changed so that it will return only the + string formed by the characters of 's' up to the first '\0'. + + The substr(s, start, num) builtin has been changed so that '\0' characters + are treated like any other. + + Fixed a bug where strcpy("", "a") used to cause a segmentation fault. + This bug was fixed by Ernest Bowen . + + Make minor change to natnumset.cal in how the tail variable is initialized. + + Fixed bugs in the strcmp, strncmp, strcpy, and strncpy help files. + This bug was fixed by Ernest Bowen . + + Added cal/screen.cal which Defines ANSI control sequences providing + (i.e., cursor movement, changing foreground or background color, + etc.) for VT100 terminals and terminal window emulators (i.e., xterm, + Apple OS/X Terminal, etc.) that support them. For example: + + read screen + print green:"This is green. ":red:"This is red.":black + + Fixed a bug where too many open files returned E_FOPEN3. Now + a new error symbol F_MANYOPEN is used for too many open files. + + Added the builtin function fpathopen() to open a file while + searching along a path: + + ; fd2 = fpathopen("tmp/date", "r", ".:~:~sc:/tmp:/var/tmp:/var") + ; print fd2 + "/var/tmp/date" + + By default, fpathopen() searches along CALCPATH. + + Added the calcpath() builtin function to return the current value + of CALCPATH. + + Fixed prompt characters in the EXAMPLE section of help files. + + Fixed problems related to the protect function and its documentation. + This bug was reported by David Gilham . + This bug was fixed by Ernest Bowen . + + Raised the limit of exponent in exponential notation. It was set to + arbitrary 1000000 (making 1e1000001 in invalid exponential notation + value). The exponent for exponential notation is now int(MAXLONG/10). + On 32 bit machines, this means a limit of 214748364. On 64 bit + machines, this means 922337203685477580. Of course, you may not + have enough memory to hold such huge values, but if you did you can + now express such values in exponential notation. + + Added log() builtin for base 10 logarithm. + + Fixed problems where internal use of libc strcpy() might have caused + a buffer overflow. Calc now only uses libc strcpy() when the source + string is a constant. + + The calc STRING and STRINGHEAD now use the standard size_t (an unsigned + type) length. Calc mostly uses size_t in dealing with string lengths + and object sizes when possible. + + Added ${CCWERR} make variable to allow one to force compiler warnings + to be treated as errors. The ${CC} make variable now uses ${CCWERR} + however the ${LCC} (used by the Makefile test code for building hsrc + files) does not use ${CCWERR}. By default, ${CCWERR} is empty. + In development Makefiles, we set CCWERR= -Werror to force us to + address compiler warnings before the next release. + + The calc make variable, CALCPAGER, now defaults to CALCPAGER= less + because the less utility is now very common. Set CALCPAGER= more + if you do not have less. + + Calc source had two styles of switch indentation. Converted the + style where case statements were indented with respect to the switch + statement into the style where the case statements are at the same + level. When comparing with older source, one may use the -b argument + of the diff command to ignore changes in amount of white space: + + diff -b -r -u calc-2.11.11 calc-2.12.0 + + The read, write, and help commands use the value of global string + variable if the symbol name starts with a $. For example: + + global x = "lucas.cal"; + read $x; /* same as read lucas.cal or read "lucas.cal" */ + + Added dotest.cal resource. Based on a design by Ernest Bowen + , the dotest evaluates individual + lines from a file. The dotest() function takes 1 to 3 arguments: + + dotest(dotest_file [,dotest_code [,dotest_maxcond]]) + + dotest_file + + Search along CALCPATH for dotest_file, which contains lines that + should evaluate to 1. Comment lines and empty lines are ignored. + Comment lines should use ## instead of the multi like /* ... */ + because lines are evaluated one line at a time. + + dotest_code + + Assign the code number that is to be printed at the start of + each non-error line and after **** in each error line. + The default code number is 999. + + dotest_maxcond + + The maximum number of error conditions that may be detected. + An error condition is not a sign of a problem, in some cases + a line deliberately forces an error condition. A value of -1, + the default, implies a maximum of 2147483647. + + Global variables and functions must be declared ahead of time because + the dotest scope of evaluation is a line at a time. For example: + + read dotest.cal + read set8700.cal + dotest("set8700.line"); + + Updated the todo / wish list items. The top priority now is to + convert calc to GNU autoconf / configure to build the calc. + + help todo + + Added missing help file for the stoponerror() builtin. + + +The following are the changes from calc version 2.11.10.1 to 2.11.11: Fixed a bug reported by the sourceforge user: cedars where: ln(exp(6)) == 3 /* WRONG!!! */ incorrectly returned 1. This bug was fixed by Ernest Bowen - . The regression test + . The regression test was expanded to cover this issue. Added minor improvements to hash regression testing of pi(). @@ -2179,6 +2327,8 @@ The following are the changes from calc version 2.10.3t5.38 to 2.11.3t5.46: into a single section. + + The following are the changes from calc version 2.10.3t5.34 to 2.10.3t5.37: Per request from David I Bell, the README line: @@ -5812,8 +5962,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.71 $ -## @(#) $Id: CHANGES,v 29.71 2005/12/12 06:47:21 chongo Exp $ +## @(#) $Revision: 29.76 $ +## @(#) $Id: CHANGES,v 29.76 2006/05/21 07:55:17 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/RCS/CHANGES,v $ ## ## Under source code control: 1993/06/02 18:12:57 diff --git a/COPYING b/COPYING index 864ecd3..56f9e97 100644 --- a/COPYING +++ b/COPYING @@ -12,8 +12,8 @@ This file is Copyrighted Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. - # @(#) $Revision: 29.7 $ - # @(#) $Id: COPYING,v 29.7 2003/02/26 16:54:59 chongo Exp $ + # @(#) $Revision: 29.8 $ + # @(#) $Id: COPYING,v 29.8 2006/05/01 19:16:57 chongo Exp $ # @(#) $Source: /usr/local/src/cmd/calc/RCS/COPYING,v $ =-= @@ -170,7 +170,7 @@ Calc copyrights and exception files shs1.c shs1.h shs.c shs.h md5.c md5.h COPYING COPYING-LGPL - cal/qtime.cal + cal/qtime.cal cal/screen.cal The file COPYING-LGPL, which contains a copy of the version 2.1 GNU Lesser General Public License, is itself Copyrighted by the diff --git a/Makefile b/Makefile index de12146..a0180a2 100644 --- a/Makefile +++ b/Makefile @@ -10,14 +10,13 @@ # or less. It compiles with gcc -O3 -g3 as well. You can change all # this by modifying the Makefile variables below. # -# NOTE: You might want use the READLINE facility and the less pager if -# your system supports them. To do this, set: +# NOTE: You might want use the READLINE facility if your system +# has the GNU readline headers and libaraies: # # USE_READLINE= -DUSE_READLINE # READLINE_LIB= -lreadline -lhistory -lncurses -# CALCPAGER= less # -# Copyright (C) 1999-2004 Landon Curt Noll +# Copyright (C) 1999-2006 Landon Curt Noll # # Calc is open software; you can redistribute it and/or modify it under # the terms of the version 2.1 of the GNU Lesser General Public License @@ -33,8 +32,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.74 $$ -# @(#) $Id: Makefile.ship,v 29.74 2005/10/18 11:53:37 chongo Exp $ +MAKEFILE_REV= $$Revision: 29.75 $$ +# @(#) $Id: Makefile.ship,v 29.75 2006/05/19 13:54:05 chongo Exp $ # @(#) $Source: /usr/local/src/cmd/calc/RCS/Makefile.ship,v $ # # Under source code control: 1990/02/15 01:48:41 @@ -807,10 +806,10 @@ READLINE_INCLUDE= # # Select CALCPAGER= less.exe -ci for DJGPP. # -CALCPAGER= more +#CALCPAGER= more #CALCPAGER= pg #CALCPAGER= cat -#CALCPAGER= less +CALCPAGER= less #CALCPAGER= less.exe -ci # Debug/Optimize options for ${CC} and ${LCC} @@ -983,6 +982,9 @@ EXT= # # CCOPT are flags given to ${CC} for optimization # CCWARN are flags given to ${CC} for warning message control +# CCWERR are flags given to ${CC} to make warnings fatal errors +# NOTE: CCWERR is only set in development Makefiles and must +# only be used with ${CC}, not ${LCC}. # CCMISC are misc flags given to ${CC} # # CFLAGS are all flags given to ${CC} [[often includes CCOPT, CCWARN, CCMISC]] @@ -1001,6 +1003,7 @@ EXT= # Tested on Red Hat 6.0 Linux but should run on almost any Linux release. # CCWARN= -Wall -W -Wno-comment +CCWERR= CCOPT= ${DEBUG} ${NO_SHARED} CCMISC= # @@ -1011,13 +1014,14 @@ LDFLAGS= ${NO_SHARED} ${LD_NO_SHARED} ILDFLAGS= # LCC= gcc -CC= ${PURIFY} ${LCC} +CC= ${PURIFY} ${LCC} ${CCWERR} # ### # -# gcc set (some call it gcc2, some call it gcc) +# gcc set # #CCWARN= -Wall -W -Wno-comment +#CCWERR= #CCOPT= ${DEBUG} ${NO_SHARED} #CCMISC= # @@ -1028,8 +1032,7 @@ CC= ${PURIFY} ${LCC} #ILDFLAGS= # #LCC= gcc -#LCC= gcc2 -#CC= ${PURIFY} ${LCC} +#CC= ${PURIFY} ${LCC} ${CCWERR} # ### # @@ -1039,6 +1042,7 @@ CC= ${PURIFY} ${LCC} # If -O2 -g is not supported try: DEBUG= -O -g # #CCWARN= +#CCWERR= #CCOPT= ${DEBUG} ${NO_SHARED} #CCMISC= # @@ -1049,7 +1053,7 @@ CC= ${PURIFY} ${LCC} #ILDFLAGS= # #LCC= cc -#CC= ${PURIFY} ${LCC} +#CC= ${PURIFY} ${LCC} ${CCWERR} # ### # @@ -1067,6 +1071,7 @@ CC= ${PURIFY} ${LCC} # woff 1209: cancel 'controlling expression is constant' warnings # #CCWARN= -fullwarn -woff 1209 +#CCWERR= #CCOPT= ${DEBUG} ${NO_SHARED} #CCMISC= -rdata_shared # @@ -1077,7 +1082,7 @@ CC= ${PURIFY} ${LCC} #ILDFLAGS= # #LCC= cc -n32 -xansi -#CC= ${PURIFY} ${LCC} +#CC= ${PURIFY} ${LCC} ${CCWERR} # ### # @@ -1090,6 +1095,7 @@ CC= ${PURIFY} ${LCC} # If 'make check' fails use: DEBUG= -g # #CCWARN= +#CCWERR= #CCOPT= ${DEBUG} ${NO_SHARED} #CCMISC= +e # @@ -1100,7 +1106,7 @@ CC= ${PURIFY} ${LCC} #ILDFLAGS= # #LCC= cc -#CC= ${PURIFY} ${LCC} +#CC= ${PURIFY} ${LCC} ${CCWERR} # ### # @@ -1110,6 +1116,7 @@ CC= ${PURIFY} ${LCC} # If -O2 -g is not supported try: DEBUG= -O -g # #CCWARN= +#CCWERR= #CCOPT= ${DEBUG} ${NO_SHARED} #CCMISC= -qlanglvl=ansi # @@ -1120,7 +1127,7 @@ CC= ${PURIFY} ${LCC} #ILDFLAGS= # #LCC= cc -#CC= ${PURIFY} ${LCC} +#CC= ${PURIFY} ${LCC} ${CCWERR} # ### # @@ -1133,6 +1140,7 @@ CC= ${PURIFY} ${LCC} # to avoid the use of -Xc (which as a lose performance wise). # #CCWARN= +#CCWERR= #CCOPT= ${DEBUG} ${NO_SHARED} #CCMISC= -DFORCE_STDC # @@ -1143,7 +1151,7 @@ CC= ${PURIFY} ${LCC} #ILDFLAGS= # #LCC= cc -#CC= ${PURIFY} ${LCC} +#CC= ${PURIFY} ${LCC} ${CCWERR} # ### # @@ -1152,6 +1160,7 @@ CC= ${PURIFY} ${LCC} # For better performance, set the following: DEBUG= -std0 -fast -O4 -static # #CCWARN= +#CCWERR= #CCOPT= ${DEBUG} ${NO_SHARED} #CCMISC= # @@ -1162,7 +1171,7 @@ CC= ${PURIFY} ${LCC} #ILDFLAGS= # #LCC= cc -#CC= ${PURIFY} ${LCC} +#CC= ${PURIFY} ${LCC} ${CCWERR} ############################################################################## #-=-=-=-=-=-=-=-=- Be careful if you change something below -=-=-=-=-=-=-=-=-# diff --git a/addop.c b/addop.c index 8f4789d..8367b58 100644 --- a/addop.c +++ b/addop.c @@ -1,7 +1,7 @@ /* * addop - add opcodes to a function being compiled * - * Copyright (C) 1999-2004 David I. Bell and Ernest Bowen + * Copyright (C) 1999-2006 David I. Bell and Ernest Bowen * * Primary author: David I. Bell * @@ -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.5 $ - * @(#) $Id: addop.c,v 29.5 2004/02/23 14:04:01 chongo Exp $ + * @(#) $Revision: 29.8 $ + * @(#) $Id: addop.c,v 29.8 2006/05/20 08:43:55 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/RCS/addop.c,v $ * * Under source code control: 1990/02/15 01:48:10 @@ -184,7 +184,7 @@ void endfunc(void) { register FUNC *fp; /* function just finished */ - unsigned long size; /* size of just created function */ + size_t size; /* size of just created function */ unsigned long index; if (oldop != OP_RETURN) { @@ -211,7 +211,7 @@ endfunc(void) if (newname[0] != '*' && (conf->traceflags & TRACE_FNCODES)) { dumpnames = TRUE; for (size = 0; size < fp->f_opcodecount; ) { - printf("%ld: ", (long)size); + printf("%u: ", size); size += dumpop(&fp->f_opcodes[size]); } } @@ -451,124 +451,124 @@ addop(long op) * slightly optimize the code depending on the various combinations. */ switch (op) { - case OP_GETVALUE: - switch (oldop) { - case OP_NUMBER: - case OP_ZERO: - case OP_ONE: - case OP_IMAGINARY: - case OP_GETEPSILON: - case OP_SETEPSILON: - case OP_STRING: - case OP_UNDEF: - case OP_GETCONFIG: - case OP_SETCONFIG: - return; - case OP_DUPLICATE: - diff = 1; - oldop = OP_DUPVALUE; - break; - case OP_FIADDR: - diff = 1; - oldop = OP_FIVALUE; - break; - case OP_GLOBALADDR: - diff = 1 + PTR_SIZE; - oldop = OP_GLOBALVALUE; - break; - case OP_LOCALADDR: - oldop = OP_LOCALVALUE; - break; - case OP_PARAMADDR: - oldop = OP_PARAMVALUE; - break; - case OP_ELEMADDR: - oldop = OP_ELEMVALUE; - break; - default: - cut = FALSE; + case OP_GETVALUE: + switch (oldop) { + case OP_NUMBER: + case OP_ZERO: + case OP_ONE: + case OP_IMAGINARY: + case OP_GETEPSILON: + case OP_SETEPSILON: + case OP_STRING: + case OP_UNDEF: + case OP_GETCONFIG: + case OP_SETCONFIG: + return; + case OP_DUPLICATE: + diff = 1; + oldop = OP_DUPVALUE; + break; + case OP_FIADDR: + diff = 1; + oldop = OP_FIVALUE; + break; + case OP_GLOBALADDR: + diff = 1 + PTR_SIZE; + oldop = OP_GLOBALVALUE; + break; + case OP_LOCALADDR: + oldop = OP_LOCALVALUE; + break; + case OP_PARAMADDR: + oldop = OP_PARAMVALUE; + break; + case OP_ELEMADDR: + oldop = OP_ELEMVALUE; + break; + default: + cut = FALSE; - } - if (cut) { - fp->f_opcodes[count - diff] = oldop; - return; - } + } + if (cut) { + fp->f_opcodes[count - diff] = oldop; + return; + } + break; + case OP_POP: + switch (oldop) { + case OP_ASSIGN: + fp->f_opcodes[count-1] = OP_ASSIGNPOP; + oldop = OP_ASSIGNPOP; + return; + case OP_NUMBER: + case OP_IMAGINARY: + q = constvalue(fp->f_opcodes[count-1]); + qfree(q); break; - case OP_POP: - switch (oldop) { - case OP_ASSIGN: - fp->f_opcodes[count-1] = OP_ASSIGNPOP; - oldop = OP_ASSIGNPOP; - return; - case OP_NUMBER: - case OP_IMAGINARY: - q = constvalue(fp->f_opcodes[count-1]); - qfree(q); - break; - case OP_STRING: - sfree(findstring((long)fp->f_opcodes[count-1])); - break; - case OP_LOCALADDR: - case OP_PARAMADDR: - break; - case OP_GLOBALADDR: - diff = 1 + PTR_SIZE; - break; - case OP_UNDEF: - fp->f_opcodecount -= 1; - oldop = OP_NOP; - oldoldop = OP_NOP; - return; - default: - cut = FALSE; - } - if (cut) { - fp->f_opcodecount -= diff; - oldop = OP_NOP; - oldoldop = OP_NOP; - fprintf(stderr, - "Line %ld: unused value ignored\n", - linenumber()); - return; - } + case OP_STRING: + sfree(findstring((long)fp->f_opcodes[count-1])); break; - case OP_NEGATE: - if (oldop == OP_NUMBER) { - q = constvalue(fp->f_opcodes[count-1]); - fp->f_opcodes[count-1] = addqconstant(qneg(q)); - qfree(q); - return; - } + case OP_LOCALADDR: + case OP_PARAMADDR: + break; + case OP_GLOBALADDR: + diff = 1 + PTR_SIZE; + break; + case OP_UNDEF: + fp->f_opcodecount -= 1; + oldop = OP_NOP; + oldoldop = OP_NOP; + return; + default: + cut = FALSE; + } + if (cut) { + fp->f_opcodecount -= diff; + oldop = OP_NOP; + oldoldop = OP_NOP; + fprintf(stderr, + "Line %ld: unused value ignored\n", + linenumber()); + return; + } + break; + case OP_NEGATE: + if (oldop == OP_NUMBER) { + q = constvalue(fp->f_opcodes[count-1]); + fp->f_opcodes[count-1] = addqconstant(qneg(q)); + qfree(q); + return; + } } if (oldop == OP_NUMBER) { if (oldoldop == OP_NUMBER) { q1 = constvalue(fp->f_opcodes[count - 3]); q2 = constvalue(fp->f_opcodes[count - 1]); switch (op) { - case OP_DIV: - if (qiszero(q2)) { - cut = FALSE; - break; - } - q = qqdiv(q1,q2); - break; - case OP_MUL: - q = qmul(q1,q2); - break; - case OP_ADD: - q = qqadd(q1,q2); - break; - case OP_SUB: - q = qsub(q1,q2); - break; - case OP_POWER: - if (qisfrac(q2) || qisneg(q2)) - cut = FALSE; - else - q = qpowi(q1,q2); - break; - default: + case OP_DIV: + if (qiszero(q2)) { cut = FALSE; + break; + } + q = qqdiv(q1,q2); + break; + case OP_MUL: + q = qmul(q1,q2); + break; + case OP_ADD: + q = qqadd(q1,q2); + break; + case OP_SUB: + q = qsub(q1,q2); + break; + case OP_POWER: + if (qisfrac(q2) || qisneg(q2)) + cut = FALSE; + else + q = qpowi(q1,q2); + break; + default: + cut = FALSE; } if (cut) { qfree(q1); diff --git a/blkcpy.c b/blkcpy.c index df47632..c78a374 100644 --- a/blkcpy.c +++ b/blkcpy.c @@ -1,7 +1,7 @@ /* * blkcpy - general values and related routines used by the calculator * - * Copyright (C) 1999-2004 Landon Curt Noll and Ernest Bowen + * Copyright (C) 1999-2006 Landon Curt Noll and Ernest Bowen * * Primary author: Landon Curt Noll * @@ -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.5 $ - * @(#) $Id: blkcpy.c,v 29.5 2004/02/23 14:04:01 chongo Exp $ + * @(#) $Revision: 29.9 $ + * @(#) $Id: blkcpy.c,v 29.9 2006/05/20 08:43:55 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/RCS/blkcpy.c,v $ * * Under source code control: 1997/04/18 20:41:26 @@ -73,51 +73,51 @@ copystod(VALUE *svp, long ssi, long num, VALUE *dvp, long dsi) * determine/check source type */ switch(svp->v_type) { - case V_NBLOCK: - if (svp->v_nblock->subtype & V_NOCOPYFROM) - return E_COPY15; - sblk = svp->v_nblock->blk; - if (sblk->data == NULL) - return E_COPY8; - break; - case V_BLOCK: - sblk = svp->v_block; - break; - case V_STR: - case V_OCTET: - case V_NUM: - case V_FILE: - case V_MAT: - case V_LIST: - break; - default: - return E_COPY9; + case V_NBLOCK: + if (svp->v_nblock->subtype & V_NOCOPYFROM) + return E_COPY15; + sblk = svp->v_nblock->blk; + if (sblk->data == NULL) + return E_COPY8; + break; + case V_BLOCK: + sblk = svp->v_block; + break; + case V_STR: + case V_OCTET: + case V_NUM: + case V_FILE: + case V_MAT: + case V_LIST: + break; + default: + return E_COPY9; } /* * determine/check destination type */ switch(dvp->v_type) { - case V_NBLOCK: - if (dvp->v_nblock->subtype & V_NOCOPYTO) - return E_COPY16; - noreloc |=((dvp->v_nblock->subtype & V_NOREALLOC) != 0); - dblk = dvp->v_nblock->blk; - if (dblk->data == NULL) - return E_COPY10; - break; - case V_BLOCK: - noreloc = ((dvp->v_subtype & V_NOREALLOC) != 0); - dblk = dvp->v_block; - break; - case V_STR: - case V_NUM: - case V_FILE: - case V_MAT: - case V_LIST: - break; - default: - return E_COPY11; + case V_NBLOCK: + if (dvp->v_nblock->subtype & V_NOCOPYTO) + return E_COPY16; + noreloc |=((dvp->v_nblock->subtype & V_NOREALLOC) != 0); + dblk = dvp->v_nblock->blk; + if (dblk->data == NULL) + return E_COPY10; + break; + case V_BLOCK: + noreloc = ((dvp->v_subtype & V_NOREALLOC) != 0); + dblk = dvp->v_block; + break; + case V_STR: + case V_NUM: + case V_FILE: + case V_MAT: + case V_LIST: + break; + default: + return E_COPY11; } /* @@ -280,7 +280,7 @@ copymat2mat(MATRIX *smat, long ssi, long num, MATRIX *dmat, long dsi) VALUE *vp; VALUE *vq; VALUE *vtemp; - short subtype; + unsigned short subtype; if (ssi > smat->m_size) return E_COPY2; @@ -311,7 +311,7 @@ copymat2mat(MATRIX *smat, long ssi, long num, MATRIX *dmat, long dsi) subtype = vq->v_subtype; freevalue(vq); *vq = *vp; - vq->v_subtype = subtype; + vq->v_subtype |= subtype; } free(vtemp); return 0; @@ -329,7 +329,7 @@ copyblk2mat(BLOCK *blk, long ssi, long num, MATRIX *dmat, long dsi) VALUE *vq; VALUE *vtemp; long i; - short subtype; + unsigned short subtype; if (ssi > blk->datalen) return E_COPY2; @@ -363,7 +363,7 @@ copyblk2mat(BLOCK *blk, long ssi, long num, MATRIX *dmat, long dsi) subtype = vq->v_subtype; freevalue(vq); *vq = *vp; - vq->v_subtype = subtype; + vq->v_subtype |= subtype; } free(vtemp); return 0; @@ -429,6 +429,7 @@ copymat2list(MATRIX *smat, long ssi, long num, LIST *lp, long dsi) LISTELEM *ep; VALUE *vtemp; long i; + unsigned short subtype; if (ssi > smat->m_size) return E_COPY2; @@ -456,8 +457,10 @@ copymat2list(MATRIX *smat, long ssi, long num, LIST *lp, long dsi) ep = listelement(lp, (long) dsi); i = num; while (i-- > 0) { + subtype = ep->e_value.v_subtype; freevalue(&ep->e_value); ep->e_value = *vq++; + ep->e_value.v_subtype |= subtype; ep = ep->e_next; } free(vtemp); @@ -476,7 +479,7 @@ copylist2mat(LIST *lp, long ssi, long num, MATRIX *dmat, long dsi) LISTELEM *ep; VALUE *vtemp; long i; - short subtype; + unsigned short subtype; if (ssi > lp->l_count) return E_COPY2; @@ -508,7 +511,7 @@ copylist2mat(LIST *lp, long ssi, long num, MATRIX *dmat, long dsi) subtype = vq->v_subtype; freevalue(vq); *vq = *vp; - vq->v_subtype = subtype; + vq->v_subtype |= subtype; } free(vtemp); return 0; @@ -526,6 +529,7 @@ copylist2list(LIST *slp, long ssi, long num, LIST *dlp, long dsi) LISTELEM *dep; VALUE *vtemp; VALUE *vp; + unsigned short subtype; if (ssi > slp->l_count) return E_COPY2; @@ -555,8 +559,10 @@ copylist2list(LIST *slp, long ssi, long num, LIST *dlp, long dsi) vp = vtemp; i = num; while (i-- > 0) { + subtype = dep->e_value.v_subtype; freevalue(&dep->e_value); dep->e_value = *vp++; + dep->e_value.v_subtype |= subtype; dep = dep->e_next; } free(vtemp); @@ -806,13 +812,13 @@ copystr2str(STRING *sstr, long ssi, long num, STRING *dstr, long dsi) { char *c, *c1; - if (num < 0 || ssi + num > sstr->s_len) + if (num < 0 || (size_t)(ssi + num) > sstr->s_len) num = sstr->s_len - ssi; if (num <= 0) return 0; /* Nothing to be copied */ if (dsi < 0) /* default destination index */ dsi = 0; - if (dsi + num > dstr->s_len) + if ((size_t)(dsi + num) > dstr->s_len) num = dstr->s_len - dsi; c1 = sstr->s_str + ssi; c = dstr->s_str + dsi; @@ -838,7 +844,7 @@ copyblk2str(BLOCK *sblk, long ssi, long num, STRING *dstr, long dsi) return 0; /* Nothing to be copied */ if (dsi < 0) /* default destination index */ dsi = 0; - if (dsi + num > dstr->s_len) + if ((size_t)(dsi + num) > dstr->s_len) num = dstr->s_len - dsi; c1 = sblk->data + ssi; c = (USB8 *)dstr->s_str + dsi; @@ -852,18 +858,18 @@ copyblk2str(BLOCK *sblk, long ssi, long num, STRING *dstr, long dsi) int copyostr2str(char *sstr, long ssi, long num, STRING *dstr, long dsi) { - long len; + size_t len; char *c, *c1; - len = (long)strlen(sstr); + len = strlen(sstr); - if (num < 0 || ssi + num > len) + if (num < 0 || (size_t)(ssi + num) > len) num = len - ssi; if (num <= 0) /* Nothing to be copied */ return 0; if (dsi < 0) dsi = 0; /* Default destination index */ - if (dsi + num > dstr->s_len) + if ((size_t)(dsi + num) > dstr->s_len) num = dstr->s_len - dsi; c1 = sstr + ssi; c = dstr->s_str + dsi; @@ -879,16 +885,16 @@ copyostr2str(char *sstr, long ssi, long num, STRING *dstr, long dsi) int copyostr2blk(char *str,long ssi,long num,BLOCK *dblk,long dsi,BOOL noreloc) { - int len; - int newlen; - int newsize; + size_t len; + size_t newlen; + size_t newsize; USB8 *newdata; len = strlen(str) + 1; - if (ssi > len) + if (ssi > 0 && (size_t)ssi > len) return E_COPY2; - if (num < 0 || ssi + num > len) + if (num < 0 || (size_t)(ssi + num) > len) num = len - ssi; if (num <= 0) /* Nothing to be copied */ return 0; @@ -897,7 +903,7 @@ copyostr2blk(char *str,long ssi,long num,BLOCK *dblk,long dsi,BOOL noreloc) newlen = dsi + num; if (newlen <= 0) return E_COPY7; - if (newlen >= dblk->maxsize) { + if (newlen >= (size_t)dblk->maxsize) { if (noreloc) return E_COPY17; newsize = (1 + newlen/dblk->blkchunk) * dblk->blkchunk; @@ -910,7 +916,7 @@ copyostr2blk(char *str,long ssi,long num,BLOCK *dblk,long dsi,BOOL noreloc) dblk->maxsize = newsize; } memmove(dblk->data + dsi, str + ssi, num); - if (newlen > dblk->datalen) + if (newlen > (size_t)dblk->datalen) dblk->datalen = newlen; return 0; } @@ -978,8 +984,8 @@ memmove(void *s1, const void *s2, CALC_SIZE_T n) int copynum2blk(NUMBER *snum, long ssi, long num, BLOCK *dblk, long dsi, BOOL noreloc) { - long newlen; - long newsize; + size_t newlen; + size_t newsize; USB8 *newdata; #if CALC_BYTE_ORDER == BIG_ENDIAN ZVALUE *swnum; /* byte swapped numerator */ @@ -995,10 +1001,10 @@ copynum2blk(NUMBER *snum, long ssi, long num, BLOCK *dblk, long dsi, BOOL norelo return E_COPY5; if (dsi < 0) dsi = dblk->datalen; - newlen = dsi + (long)(num*sizeof(HALF)); + newlen = dsi + (num*sizeof(HALF)); if (newlen <= 0) return E_COPY7; - if (newlen >= dblk->maxsize) { + if (newlen >= (size_t)dblk->maxsize) { if (noreloc) return E_COPY17; newsize = (1 + newlen/dblk->blkchunk) * dblk->blkchunk; @@ -1017,7 +1023,7 @@ copynum2blk(NUMBER *snum, long ssi, long num, BLOCK *dblk, long dsi, BOOL norelo memmove(dblk->data+dsi, (char *)(swnum->v+ssi), num*sizeof(HALF)); zfree(*swnum); #endif - if (newlen > dblk->datalen) + if (newlen > (size_t)dblk->datalen) dblk->datalen = newlen; return 0; } @@ -1029,7 +1035,7 @@ copynum2blk(NUMBER *snum, long ssi, long num, BLOCK *dblk, long dsi, BOOL norelo int copyblk2num(BLOCK *sblk, long ssi, long num, NUMBER *dnum, long dsi, NUMBER **res) { - long newlen; + size_t newlen; NUMBER *ret; /* cloned and modified numerator */ #if CALC_BYTE_ORDER == BIG_ENDIAN HALF *swapped; /* byte swapped input data */ @@ -1048,7 +1054,7 @@ copyblk2num(BLOCK *sblk, long ssi, long num, NUMBER *dnum, long dsi, NUMBER **re return E_COPY5; if (dsi < 0) dsi = dnum->num.len; - newlen = dsi + (long)((num+sizeof(HALF)-1)/sizeof(HALF)); + newlen = dsi + ((num+sizeof(HALF)-1)/sizeof(HALF)); if (newlen <= 0) return E_COPY7; diff --git a/block.c b/block.c index 4089499..8f491c9 100644 --- a/block.c +++ b/block.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: block.c,v 29.2 2000/06/07 14:02:13 chongo Exp $ + * @(#) $Revision: 29.3 $ + * @(#) $Id: block.c,v 29.3 2006/05/01 19:16:57 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/RCS/block.c,v $ * * Under source code control: 1997/02/27 00:29:40 @@ -57,7 +57,7 @@ static void blkchk(BLOCK*); * * given: * len - initial memory length of the block - * type - BLK_TYPE_XXX + * type - BLK_TYPE_XYZ * chunk - allocation chunk size * * returns: diff --git a/cal/Makefile b/cal/Makefile index d4a353f..5ee6068 100644 --- a/cal/Makefile +++ b/cal/Makefile @@ -18,8 +18,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.16 $ -# @(#) $Id: Makefile,v 29.16 2005/12/12 06:42:30 chongo Exp $ +# @(#) $Revision: 29.18 $ +# @(#) $Id: Makefile,v 29.18 2006/05/20 19:32:40 chongo Exp $ # @(#) $Source: /usr/local/src/cmd/calc/cal/RCS/Makefile,v $ # # Under source code control: 1991/07/21 05:00:54 @@ -176,7 +176,8 @@ CALC_FILES= README bigprime.cal deg.cal ellip.cal lucas.cal lucas_chk.cal \ test3500.cal seedrandom.cal test4000.cal test4100.cal test4600.cal \ beer.cal hello.cal test5100.cal test5200.cal randombitrun.cal \ randomrun.cal repeat.cal xx_print.cal natnumset.cal qtime.cal \ - test8400.cal test8500.cal test8600.cal chi.cal intfile.cal + test8400.cal test8500.cal test8600.cal chi.cal intfile.cal screen.cal \ + dotest.cal set8700.cal set8700.line # These files are found (but not built) in the distribution # diff --git a/cal/README b/cal/README index 4985429..c1ecaa6 100644 --- a/cal/README +++ b/cal/README @@ -12,7 +12,7 @@ Normally a resource file will simply define some functions. By default, most resource files will print out a short message when they are read. For example: - > read lucas + ; read lucas lucas(h,n) defined gen_u0(h,n,v1) defined gen_v1(h,n) defined @@ -22,9 +22,9 @@ will cause calc to load and execute the 'lucas.cal' resource file. Executing the resource file will cause several functions to be defined. Executing the lucas function: - > lucas(149,60) + ; lucas(149,60) 1 - > lucas(146,61) + ; lucas(146,61) 0 shows that 149*2^60-1 is prime whereas 146*2^61-1 is not. @@ -180,6 +180,38 @@ deg.cal Calculate in degrees, minutes, and seconds. +dotest.cal + + dotest(dotest_file [,dotest_code [,dotest_maxcond]]) + + dotest_file + + Search along CALCPATH for dotest_file, which contains lines that + should evaluate to 1. Comment lines and empty lines are ignored. + Comment lines should use ## instead of the multi like /* ... */ + because lines are evaluated one line at a time. + + dotest_code + + Assign the code number that is to be printed at the start of + each non-error line and after **** in each error line. + The default code number is 999. + + dotest_maxcond + + The maximum number of error conditions that may be detected. + An error condition is not a sign of a problem, in some cases + a line deliberately forces an error condition. A value of -1, + the default, implies a maximum of 2147483647. + + Global variables and functions must be declared ahead of time because + the dotest scope of evaluation is a line at a time. For example: + + read dotest.cal + read set8700.cal + dotest("set8700.line"); + + ellip.cal efactor(iN, ia, B, force) @@ -505,6 +537,58 @@ regress.cal Errors are reported with '****' messages, or worse. :-) +screen.cal + + up + CUU /* same as up */ + down = CUD + CUD /* same as down */ + forward + CUF /* same as forward */ + back = CUB + CUB /* same as back */ + save + SCP /* same as save */ + restore + RCP /* same as restore */ + cls + home + eraseline + off + bold + faint + italic + blink + rapidblink + reverse + concealed + /* Lowercase indicates foreground, uppercase background */ + black + red + green + yellow + blue + magenta + cyan + white + Black + Red + Green + Yellow + Blue + Magenta + Cyan + White + + Define ANSI control sequences providing (i.e., cursor movement, changing + foreground or background color, etc.) for VT100 terminals and terminal + window emulators (i.e., xterm, Apple OS/X Terminal, etc.) that support them. + + For example: + + read screen + print green:"This is green. ":red:"This is red.":black + seedrandom.cal seedrandom(seed1, seed2, bitsize [,trials]) @@ -523,6 +607,24 @@ seedrandom.cal Blum primes for the modulus. +set8700.cal + + set8700_getA1() defined + set8700_getA2() defined + set8700_getvar() defined + set8700_f(set8700_x) defined + set8700_g(set8700_x) defined + + Declare globals and define functions needed by dotest() (see + dotest.cal) to evaluate set8700.line a line at a time. + + +set8700.line + + A line-by-line evaluation file for dotest() (see dotest.cal). + The set8700.cal file (and dotest.cal) should be read first. + + solve.cal solve(low, high, epsilon) @@ -833,8 +935,8 @@ xx_print.cal ## 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.10 $ -## @(#) $Id: README,v 29.10 2005/12/12 06:39:18 chongo Exp $ +## @(#) $Revision: 29.12 $ +## @(#) $Id: README,v 29.12 2006/05/21 04:41:09 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/cal/RCS/README,v $ ## ## Under source code control: 1990/02/15 01:50:32 diff --git a/cal/dotest.cal b/cal/dotest.cal new file mode 100644 index 0000000..1ce426f --- /dev/null +++ b/cal/dotest.cal @@ -0,0 +1,193 @@ +/* + * dotest - test truth statements found in line tests of dotest_testline file + * + * This file was created by Ernest Bowen + * and modified by Landon Curt Noll. + * + * This dotest_code has been placed in the public domain. Please do not + * copyright this dotest_code. + * + * ERNEST BOWEN AND LANDON CURT NOLL DISCLAIMS ALL WARRANTIES WITH REGARD TO + * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MER- + * CHANTABILITY AND FITNESS. IN NO EVENT SHALL LANDON CURT + * NOLL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF + * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * @(#) $Revision: 29.2 $ + * @(#) $Id: dotest.cal,v 29.2 2006/05/21 00:55:27 chongo Exp $ + * @(#) $Source: /usr/local/src/cmd/calc/cal/RCS/dotest.cal,v $ + * + * This file is not covered under version 2.1 of the GNU LGPL. + * + * Under source dotest_code control: 2006/03/08 05:54:09 + * File existed as early as: 2006 + */ + + +/* + * dotest - perform tests from dotest_testline file + * + * given: + * dotest_file filename containing single test lines + * dotest_code regress.cal test number to use (def: 0) + * dotest_maxcond max error conditions allowed (def: <0 ==> 2^31-1) + * + * returns: + * number of line test failures + * + * NOTE: All variables used by the dotest() function start with "dotest_". + * The dotest_file and dotest_read should not use any variable + * that starts with "dotest_". + */ +define dotest(dotest_file, dotest_code = 0, dotest_maxcond = -1) +{ + local dotest_f_file; /* open file containing test lines */ + local dotest_testline; /* test line */ + local dotest_testeval; /* eval value from dotest_testline test line */ + local dotest_tmperrcnt; /* temp error count after line test */ + local dotest_errcnt; /* total number of errors */ + local dotest_failcnt; /* number of line tests failed */ + local dotest_testnum; /* number of test lines evaluated */ + local dotest_linenum; /* test line number */ + local dotest_old_errmax; /* value of errmax() prior to calling */ + local dotest_old_errcount; /* value of errcount() prior to calling */ + + /* + * preserve calling stats + */ + dotest_old_errmax = errmax(); + dotest_old_errcount = errcount(0); + + /* + * initialize test accounting + */ + dotest_errcnt = errcount(); + dotest_failcnt = 0; + dotest_testnum = 0; + dotest_linenum = 0; + + /* + * setup error accounting for dotest + */ + if (dotest_maxcond >= 0 && dotest_maxcond < 2147483647) { + errmax(dotest_maxcond + dotest_old_errcount + 1),; + } else { + errmax(2147483647),; + } + + /* + * open the test line file + */ + printf("%d-: opening line file: %d", dotest_code, dotest_file); + dotest_f_file = fpathopen(dotest_file, "r"); + if (!isfile(dotest_f_file)) { + printf("**** Unable to file or open file \"%s\"\n", + dotest_file); + quit; + } + printf('%d: testing "%s"\n', dotest_code, dotest_file); + + /* + * perform dotest_testline test on each line of the file + */ + for (;;) { + + /* get the next test line */ + dotest_testline = fgets(dotest_f_file); + ++dotest_linenum; + if (iserror(dotest_testline)) { + quit "**** Error while reading file"; + } else if (isnull(dotest_testline)) { + /* EOF - end of test file */ + break; + } + + /* skip empty lines */ + if (dotest_testline == "\n") { + continue; + } + + /* evaluate the test line */ + dotest_testeval = eval(dotest_testline); + + /* ignore white space or comment lines */ + if (isnull(dotest_testeval)) { + continue; + } + + /* look for test line parse errors */ + if (iserror(dotest_testeval)) { + printf("**** evaluation error: "); + ++dotest_failcnt; + + /* look for test line dotest_failcnt */ + } else if (dotest_testeval != 1) { + printf("**** did not return 1: "); + ++dotest_failcnt; + } + + /* show the test line we just performed */ + printf("%d-%d: %s", dotest_code, dotest_linenum, dotest_testline); + + /* error accounting */ + dotest_tmperrcnt = errcount() - dotest_errcnt; + if (dotest_tmperrcnt > 0) { + + /* report any other errors */ + if (dotest_tmperrcnt > 1) { + printf("%d-%d: NOTE: %d error conditions(s): %s\n", + dotest_code, dotest_linenum, dotest_tmperrcnt); + } + + /* report the calc error string */ + printf("%d-%d: NOTE: last error string: %s\n", + dotest_code, dotest_linenum, strerror()); + + /* new error count level */ + dotest_errcnt = errcount(); + if (dotest_maxcond >= 0 && + dotest_old_errcount-dotest_errcnt > dotest_maxcond) { + printf("%d-%d: total error conditions: %d > %d\n", + dotest_code, dotest_linenum, + dotest_maxcond, dotest_old_errcount-dotest_errcnt); + } + } + } + + /* + * test the close of the line file + */ + printf("%d-: detected %d error condition(s), many of which may be OK\n", + dotest_code, dotest_old_errcount-dotest_errcnt); + printf("%d-: closing line file: %d\n", dotest_code, dotest_file); + fclose(dotest_f_file); + + /* + * test line file accounting + */ + if (dotest_failcnt > 0) { + printf("**** %d-: %d test failure(s) in %d line(s)\n", + dotest_code, dotest_failcnt, dotest_linenum); + } else { + printf("%d-: no failure(s) in %d line(s)\n", + dotest_code, dotest_linenum); + } + + /* + * preppare to return to the caller environment + * + * We increase the caller's error count by the number + * of line tests that failed, not the number of internal + * errors that were noted. + */ + errmax(dotest_old_errmax),; + errcount(dotest_old_errcount + dotest_failcnt),; + + /* + * All Done!!! -- Jessica Noll, Age 2 + */ + return dotest_failcnt; +} diff --git a/cal/ellip.cal b/cal/ellip.cal index e3f2d78..3484bba 100644 --- a/cal/ellip.cal +++ b/cal/ellip.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.2 $ - * @(#) $Id: ellip.cal,v 29.2 2000/06/07 14:02:25 chongo Exp $ + * @(#) $Revision: 29.3 $ + * @(#) $Id: ellip.cal,v 29.3 2006/03/07 22:16:25 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/cal/RCS/ellip.cal,v $ * * Under source code control: 1990/02/15 01:50:33 @@ -141,7 +141,7 @@ define point_mul(p1, p2) if (p2 == 1) return p1; if (p1 == p2) - return point_square(&p1); + return point_square(`p1); obj point r; m = (minv(p2.x - p1.x, N) * (p2.y - p1.y)) % N; if (m == 0) { @@ -185,9 +185,9 @@ define point_pow(p, pow) r = p; t = p; for (bit = 2; ((bit <= pow) && (f == 0)); bit <<= 1) { - t = point_square(&t); + t = point_square(`t); if (bit & pow) - r = point_mul(&t, &r); + r = point_mul(`t, `r); } return r; } diff --git a/cal/natnumset.cal b/cal/natnumset.cal index 4976902..b275e2d 100644 --- a/cal/natnumset.cal +++ b/cal/natnumset.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.2 $ - * @(#) $Id: natnumset.cal,v 29.2 2000/06/07 14:02:25 chongo Exp $ + * @(#) $Revision: 29.3 $ + * @(#) $Id: natnumset.cal,v 29.3 2006/05/01 19:19:46 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/cal/RCS/natnumset.cal,v $ * * Under source code control: 1997/09/07 23:53:51 @@ -471,7 +471,7 @@ define set_plus(a) = set_sum(a); define interval(a, b) { local i, j, s; - static tail = str("\0\1\3\7\17\37\77\177\377"); + static tail = "\0\1\3\7\17\37\77\177\377"; if (!isint(a) || !isint(b)) quit "Non-integer argument for interval"; diff --git a/cal/regress.cal b/cal/regress.cal index 30d1fc1..9210281 100644 --- a/cal/regress.cal +++ b/cal/regress.cal @@ -1,7 +1,7 @@ /* * regress - calc regression and correctness test suite * - * Copyright (C) 1999-2004 David I. Bell and Landon Curt Noll + * Copyright (C) 1999-2006 David I. Bell and Landon Curt Noll * * Calc is open software; you can redistribute it and/or modify it under * the terms of the version 2.1 of the GNU Lesser General Public License @@ -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.20 $ - * @(#) $Id: regress.cal,v 29.20 2004/10/22 23:51:26 chongo Exp $ + * @(#) $Revision: 29.25 $ + * @(#) $Id: regress.cal,v 29.25 2006/05/21 00:58:31 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/cal/RCS/regress.cal,v $ * * Under source code control: 1990/02/15 01:50:36 @@ -1310,9 +1310,14 @@ define test_functions() * verify sleep */ vrfy(sleep(1/5) == null(), '1153: sleep(1/5) == null()'); - vrfy(sleep(1) == null(), '1154: sleep(1) == null()'); + vrfy(sleep(1/100) == null(), '1154: sleep(1/100) == null()'); - print '1155: Ending test_functions'; + /* + * verify calcpath + */ + vrfy(isstr(calcpath()), '1155: isstr(calcpath())'); + + print '1156: Ending test_functions'; } print '017: parsed test_functions()'; @@ -2595,6 +2600,22 @@ define test_2600() strcat(str(tnum++), ': ln(exp(6)^15) == 90')); vrfy(ln(exp(5)^18) == 90, strcat(str(tnum++), ': ln(exp(5)^18) == 90')); + vrfy(log(1e6) == 6, + strcat(str(tnum++), ': log(1e6)) == 6')); + vrfy(log(1) == 0, + strcat(str(tnum++), ': log(1)) == 0')); + vrfy(log(100) == 2, + strcat(str(tnum++), ': log(100)) == 2')); + vrfy(log(1e66) == 66, + strcat(str(tnum++), ': log(1e66)) == 66')); + vrfy(log(1e127) == 127, + strcat(str(tnum++), ': log(1e127)) == 127')); + vrfy(round(log(17^47),10) == 57.8310993048, + strcat(str(tnum++), + ': round(log(17^47),10) == 57.8310993048')); + vrfy(round(log(127),10) == 2.103803721, + strcat(str(tnum++), + ': round(log(127),10) == 2.103803721')); epsilon(i),; print tnum++: ': epsilon(i),;'; @@ -3383,7 +3404,7 @@ print '070: parsed test_redc()'; */ define test_fileops() { - local a, b, c, f, m, n, x, y, z; + local a, b, c, f, m, n, p, r, x, y, z; local L = "Landon"; local C = "Curt"; local N = "Noll"; @@ -3485,13 +3506,21 @@ define test_fileops() vrfy(y == "Noll", '4258: y == "Noll"'); vrfy(isnull(fclose(f)), '4259: isnull(fclose(f))'); + /* + * fpathopen tests + */ + vrfy(!iserror(p=fpathopen("junk4200","r",".")), + '4260: !iserror(p=fparhopen("junk4200","r","."))'); + vrfy(!iserror(r=fpathopen("regress.cal","r")), + '4261: !iserror(r=fparhopen("regress.cal","r","."))'); + /* * cleanup */ x = rm("junk4200"); - print '4260: x = rm("junk4200")'; + print '4262: x = rm("junk4200")'; - print '4261: Ending test_fileops'; + print '4263: Ending test_fileops'; } print '071: parsed test_fileops()'; @@ -5115,7 +5144,7 @@ define test_assign(base, work) Y5800 = base+4; print base+4: ': Y5800 = base+4'; obj xy5800 A={1,2}, obj xy5800 B={3,4}; - print base+5: ': obj xy5800 A={1,2}, obj xy5000 B={3,4}'; + print base+5: ': obj xy5800 A={1,2}, obj xy5800 B={3,4}'; /* * test assignment @@ -5238,7 +5267,7 @@ define test_is() prime = 3217; print '5922: prime = 3217'; square = prime^2; - print '5923: square = prine^2'; + print '5923: square = prime^2'; string = "a string"; print '5924: string = "a string"'; com = 3+4i; @@ -6237,7 +6266,7 @@ define test_blk() /* A second named block */ B1 = blk("+++6700", 15, 10) = {1,2,3,4,5}; - print '6746: B1 = blk("+++6700", , 10);'; + print '6746: B1 = blk("+++6700", 15 , 10) = {1,2,3,4,5};'; vrfy(size(B1) == 15, '6747: size(B1) == 15'); vrfy(sizeof(B1) == 20, '6748: sizeof(B1) == 20'); vrfy(test(B1) == 1, '6749: test(B1) == 1'); @@ -7339,7 +7368,7 @@ define test_somenew() vrfy(size(char(0)) == 1, '8203: size(char(0)) == 1'); vrfy(strlen(char(0)) == 0, '8204: strlen(char(0)) == 0'); vrfy(char(0) != "", '8205: char(0) != ""'); - vrfy(strcmp(char(0),"") == 0, '8206: strcmp(char(0),"") == 0'); + vrfy(str(char(0)) == "", '8206: str(char(0)) == ""'); vrfy(str("abc") == "abc", '8207: str("abc") == "abc"'); @@ -7696,20 +7725,34 @@ print '8406: Ending test_quit'; * test_divmod - psuedo-random tests on the // and % with various rounding modes */ print; -print '8500: Starting test_divmod' +print '8500: Starting test of divmod' read -once "test8500"; -/* 85xx: Ending test_divmod is printed by test8500.cal */ +/* 85xx: Ending test of divmod is printed by test8500.cal */ /* * test_maxargs - test up to 1024 args being passed to a builtin function */ print; -print '8600: Starting test_1024args' +print '8600: Starting test of up to 1024 args' read -once "test8600"; -/* 86xx: Ending test_1024args is printed by test8600.cal */ +/* 86xx: Ending test of up to 1024 args is printed by test8600.cal */ +/* + * dotest scripts + * + * We use the dotest driver to evaluate test-97xx data files. + */ +print '8700: Starting dotest runs' +print '8701: read -once "dotest"'; +read -once "dotest"; +print '8702: read -once "set8700"'; +read -once "set8700"; +vrfy(dotest("set8700.line", 8703) == 0, + '8703: dotest("set8700.line", 8703) == 0'); +/* 87xx: Ending dotest runs is printed by set8700.test */ + /* * read various calc resource files * diff --git a/cal/screen.cal b/cal/screen.cal new file mode 100644 index 0000000..c0d3af9 --- /dev/null +++ b/cal/screen.cal @@ -0,0 +1,61 @@ +/* + * screen - ANSI control sequences + * + * This file was created by Ernest Bowen . + * + * This code has been placed in the public domain. Please do not + * copyright this code. + * + * ERNEST BOWEN DISCLAIMS ALL WARRANTIES WITH REGARD TO + * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MER- + * CHANTABILITY AND FITNESS. IN NO EVENT SHALL LANDON CURT + * NOLL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF + * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * @(#) $Revision: 29.2 $ + * @(#) $Id: screen.cal,v 29.2 2006/05/01 19:21:18 chongo Exp $ + * @(#) $Source: /usr/local/src/cmd/calc/cal/RCS/screen.cal,v $ + * + * This file is not covered under version 2.1 of the GNU LGPL. + * + * Under source code control: 2006/03/08 05:54:09 + * File existed as early as: 2006 + */ + +up = CUU ="\e[A"; +down = CUD = "\e[B}"; +forward = CUF = "\e[C"; +back = CUB = "\e[D"; +save = SCP = "\e[s"; +restore = RCP = "\e[u"; +cls = "\e[2J"; +home = "\e[F"; +eraseline = "\e[K"; +off = "\e[0m"; +bold = "\e[1m"; +faint = "\e[2m"; +italic = "\e[3m"; +blink = "\e[5m"; +rapidblink = "\e[6m"; +reverse = "\e[7m"; +concealed = "\e[8m"; +/* Lowercase indicates foreground, uppercase background" */ +black = "\e[30m"; +red = "\e[31m"; +green = "\e[32m"; +yellow = "\e[33m"; +blue = "\e[34m"; +magenta = "\e[35m"; +cyan = "\e[36m"; +white = "\e[37m"; +Black = "\e[40m"; +Red = "\e[41m"; +Green = "\e[42m"; +Yellow = "\e[43m"; +Blue = "\e[44m"; +Magenta = "\e[45m"; +Cyan = "\e[46m"; +White = "\e[47m"; diff --git a/cal/set8700.cal b/cal/set8700.cal new file mode 100644 index 0000000..4a1426a --- /dev/null +++ b/cal/set8700.cal @@ -0,0 +1,72 @@ +/* + * set8700 - environment for dotest line tests for the 8700 set of regress.cal + * + * Copyright (C) 2006 Ernest Bowen and Landon Curt Noll + * + * Calc is open software; you can redistribute it and/or modify it under + * the terms of the version 2.1 of the GNU Lesser General Public License + * as published by the Free Software Foundation. + * + * Calc is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General + * Public License for more details. + * + * A copy of version 2.1 of the GNU Lesser General Public License is + * distributed with calc under the filename COPYING-LGPL. You should have + * 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.1 $ + * @(#) $Id: set8700.cal,v 29.1 2006/05/20 19:35:33 chongo Exp $ + * @(#) $Source: /usr/local/src/cmd/calc/cal/RCS/set8700.cal,v $ + * + * Under source code control: 2006/05/20 14:10:11 + * File existed as early as: 2006 + * + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + */ + + +/* + * setup global variables for dotest() to use with set8700.set + */ + +global set8700_A; +global set8700_B; +global set8700_M; +global set8700_M1; +global set8700_M2; +global set8700_L; +global set8700_L1; +global set8700_L2; +global set8700_O; +global set8700_P; +global set8700_P1; +global set8700_P2; +global set8700_Q; +global set8700_R; +global set8700_S; +global set8700_X; +global set8700_Y; +global set8700_x; +global set8700_y; + +define set8700_getA1() = set8700_A; + +define set8700_getA2() { return set8700_A; } + +define set8700_getvar() {local a = 42; protect(a,256); return a;} + +define set8700_f(set8700_x) = set8700_x^2; + +define set8700_g(set8700_x) +{ + if (isodd(set8700_x)) protect(set8700_x, 256); + return set8700_x; +} + +obj set8700_point { + set8700_x, set8700_y, set8700_z +} diff --git a/cal/set8700.line b/cal/set8700.line new file mode 100644 index 0000000..0ec709c --- /dev/null +++ b/cal/set8700.line @@ -0,0 +1,405 @@ +## +## set8700 - dotest line tests for the 8700 set of regress.cal +## +## Copyright (C) 2006 Ernest Bowen and Landon Curt Noll +## +## Calc is open software; you can redistribute it and/or modify it under +## the terms of the version 2.1 of the GNU Lesser General Public License +## as published by the Free Software Foundation. +## +## Calc is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General +## Public License for more details. +## +## A copy of version 2.1 of the GNU Lesser General Public License is +## distributed with calc under the filename COPYING-LGPL. You should have +## 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.1 $ +## @(#) $Id: set8700.line,v 29.1 2006/05/20 19:35:33 chongo Exp $ +## @(#) $Source: /usr/local/src/cmd/calc/cal/RCS/set8700.line,v $ +## +## Under source code control: 2006/05/20 14:10:11 +## File existed as early as: 2006 +## +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + + +strcpy("", "") == "" +strcpy("", "xyz") == "" +strcpy("a", "xyz") == "x" +strcpy("ab", "xyz") == "xy" +strcpy("abc", "xyz") == "xyz" +strcpy("abcd", "xyz") == "xyz\0" ## Result will print as "xyz" +strcpy("abcde", "xyz") == "xyz\0e" +strcpy("abcdef", "xyz") == "xyz\0ef" +strcpy("abcdef", "x\0z") == "x\0z\0ef" ## Note z is copied +strcpy("abc", "") == "\0bc" + +strncpy("abcdef", "xyz", 0) == "abcdef" ## No characters copied +strncpy("abcdef", "xyz", 1) == "xbcdef" ## One character copied, no '\0' +strncpy("abcdef", "xyz", 2) == "xycdef" +strncpy("abcdef", "xyz", 3) == "xyzdef" +strncpy("abcdef", "xyz", 4) == "xyz\0ef" +strncpy("abcdef", "xyz", 5) == "xyz\0\0f" ## Two nulls as in C +strncpy("abcdef", "xyz", 6) == "xyz\0\0\0" +strncpy("abcdef", "xyz", 7) == "xyz\0\0\0" ## Size of first string unchanged +strncpy("a\0cdef", "\0yz", 4) == "\0yz\0ef" +strncpy("ab", "xyz", 3) == "xy" + +strcmp("", "") == 0 +strcmp("", "a") == -1 +strcmp("\n", "\n") == 0 +strcmp("\0", "") == 1 ## '\0' treated like other characters +strcmp("ab", "") == 1 +strcmp("ab", "a") == 1 +strcmp("ab", "ab") == 0 +strcmp("ab", "abc") == -1 +strcmp("abc", "abb") == 1 +strcmp("abc", "abc") == 0 +strcmp("abc", "abd") == -1 +strcmp("abc\0", "abc") == 1 + +strncmp("abc", "xyz", 0) == 0 +strncmp("abc", "xyz", 1) == -1 +strncmp("abc", "", 1) == 1 +strncmp("abc", "a", 1) == 0 +strncmp("", "", 2) == 0 +strncmp("a", "a", 2) == 0 +strncmp("a", "b", 2) == -1 +strncmp("ab", "ab", 2) == 0 +strncmp("ab", "ac", 2) == -1 +strncmp("\0ac", "\0b", 2) == -1 +strncmp("ab", "abc", 2) == 0 +strncmp("abc", "abd", 2) == 0 +strncmp("a", "a\0", 2) == -1 +strncmp("a", "a", 3) == 0 +strncmp("abc", "abd", 3) == -1 +strncmp("\0\0\n", "\0\0\t", 3) == 1 + +str("abc") == "abc" +str("ab\0") == "ab" +str("a\0c") == "a" +str("\0bc") == "" + +size("") == 0 +size("a") == 1 +size("\0") == 1 +size("a\0") == 2 +size("a\0b") == 3 + +strlen("\0") == 0 +strlen("a\0") == 1 +strlen("a\0b") == 1 + +0 * "abc" == "" +1 * "abc" == "abc" +2 * "abc" == "abcabc" +3 * "abc" == "abcabcabc" +1 * "" == "" +-1 * "abc" == "cba" +-2 * "abc" == "cbacba" +"abc" + "xyz" == "abcxyz" +"abc" - "xyz" == "abczyx" + + +substr("abcd",0,0) == "" +substr("abcd",0,1) == "a" +substr("abcd",0,2) == "ab" +substr("abcd",1,0) == "" +substr("abcd",1,1) == "a" +substr("abcd",1,2) == "ab" +substr("abcd",2,0) == "" +substr("abcd",2,1) == "b" +substr("abcd",2,2) == "bc"; +substr("abcd",2,3) == "bcd"; +substr("abcd",2,4) == "bcd"; +substr("abcd",2,5) == "bcd"; ## substr stops at end of string +substr("abcd",4,0) == "" +substr("abcd",4,1) == "d" +substr("abcd",4,2) == "d" +substr("abcd",4,3) == "d" +substr("abcd",5,0) == "" +substr("abcd",5,1) == "" +substr("a\0c\0",2,2) == "\0c" ## '\0' treated like other characters +substr("a\0c\0",2,3) == "\0c\0" + +#"" == 0 ## # operator counts number of bits +#"\0" == 0 +# "a" == 3 + # "ab" == 6 ## white space ignored +# "abc" == 10 +# 27 == 4 +# 0b1010111011 == 7 + +7 # 9 == 2 ## 7 # 9 = abs(7 - 9) +3/4 # 2/3 == 1/12 + +a = 5, a #= 2, a == 3 +a #= 4, a == 1 + +## Binary # operator not defined for strings + +global set8700_A; protect(set8700_A) == 0 +## Testing with one lvalue +isnull(protect(set8700_A,65)) +protect(set8700_A) == 65 +isnull(protect(set8700_A, -1)) +protect(set8700_A) == 64 +protect(set8700_A,-2), protect(set8700_A) == 64 +protect(set8700_A,5), protect(set8700_A) == 69 +protect(set8700_A,-4), protect(set8700_A) == 65 +protect(set8700_A,0), protect(set8700_A) == 0 +protect(set8700_A,1234), protect(set8700_A) == 1234 +protect(set8700_A,-1234), protect(set8700_A) == 0 +protect(set8700_A,65535), protect(set8700_A) == 65535 +protect(set8700_A,-65535), protect(set8700_A) == 0 + +## Simple assignments +set8700_A = 42, protect(set8700_A,1024), set8700_B = set8700_A, protect(set8700_B) == 1024 +set8700_A = 6 * 7, protect(set8700_A) == 1024 +set8700_A == set8700_B + +## Testing matrix protectioon +set8700_A = mat [3] = {1, 2, list(3,4)}; 1 +protect(set8700_A, 65, 1), protect(set8700_A) == 1089 +protect(set8700_A[0]) == 65 +protect(set8700_A[2]) == 65 +protect(set8700_A[2][1]) == 0 +protect(set8700_A, 65, 2), protect(set8700_A[2][1]) == 65 +protect(set8700_A,-1024), protect(set8700_A) == 65 +protect(set8700_A, -1, 1), protect(set8700_A) == 64 +protect(set8700_A[1]) == 64 +protect(set8700_A[2]) == 64 +protect(set8700_A[2][0]) == 65 +protect(set8700_A,0), protect(set8700_A) == 0 +protect(set8700_A[1]) == 64 +protect(set8700_A, 0, 2), protect(set8700_A) == 0 +protect(set8700_A[1]) == 0 +protect(set8700_A[2][1]) == 0 +protect(set8700_A,1024, 2), protect(set8700_A) == 1024 +protect(set8700_A[2]) == 1024 +protect(set8700_A[2][0], 512), protect(set8700_A[2][0]) == 1536 + +## Testing simple assignment of matrix +set8700_B = set8700_A, protect(set8700_B) == 1024 ## protect(set8700_A) copied +protect(set8700_B[2]) == 1024 ## protect(set8700_A[2]) copied +protect(set8700_B[2][0]) == 1536 ## protect(set8700_A[2][0]) copied + +## copying matrix to list +set8700_B = list(5,6,7), protect(set8700_B) == 1024 +protect(set8700_B[0]) == 0 +protect(set8700_B[2]) == 0 +protect(set8700_A,0), protect(set8700_A) == 0 +copy(set8700_A,set8700_B), set8700_B[0] == 1 && set8700_B[1] == 2 +set8700_B[2] == list(3,4) +protect(set8700_B) == 1024 ## protect(set8700_A) not copied +protect(set8700_B[0]) == 1024 ## protect(set8700_A[0]) copied +protect(set8700_B[2][0]) == 1536 ## protect(set8700_A[2][0]) copied + +## copying matrix to matrix +set8700_B = mat[3], protect(set8700_B) == 1024 +protect(set8700_B[2]) == 0 +copy(set8700_A,set8700_B), set8700_B[0] == 1 && set8700_B[1] == 2 +set8700_B[2] == list(3,4) +protect(set8700_B) == 1024 ## protect(set8700_A) not copied +protect(set8700_B[0]) == 1024 ## protect(set8700_A[0]) copied +protect(set8700_B[2][0]) == 1536 ## protect(set8700_A[2][0]) copied + +## Testing list protection +set8700_A = list(1, 2, list(3,4)), 1 +protect(set8700_A,1024, 2), protect(set8700_A) == 1024 +protect(set8700_A[2]) == 1024 +protect(set8700_A[2][0], 512), protect(set8700_A[2][0]) == 1536 + +## Simple assignment of list +set8700_B = set8700_A, protect(set8700_B) == 1024 ## protect(set8700_A) copied +protect(set8700_B[2]) == 1024 ## protect(set8700_A[2]) copied +protect(set8700_B[2][0]) == 1536 ## protect(set8700_A[2][0]) copied + +## Copying list to list +set8700_B = list(5,6,7), protect(set8700_B) == 1024 +protect(set8700_B[2]) == 0 +copy(set8700_A,set8700_B), set8700_B[0] == 1 && set8700_B[1] == 2 +set8700_B[2] == list(3,4) +protect(set8700_B) == 1024 ## protect(set8700_A) not copied +protect(set8700_B[0]) == 1024 ## protect(set8700_A[0]) copied +protect(set8700_B[2][0]) == 1536 ## protect(set8700_A[2][0]) copied + +## Copying list to matrix +set8700_B = mat[3], protect(set8700_B) == 1024 +protect(set8700_B[2]) == 0 +copy(set8700_A,set8700_B), set8700_B[0] == 1 && set8700_B[1] == 2 +set8700_B[2] == list(3,4) +protect(set8700_B) == 1024 +protect(set8700_B[0]) == 1024 ## protect(set8700_A[0]) copied +protect(set8700_B[2][0]) == 1536 ## protect(set8700_A[2][0]) copied + +## Protecting one element of a list +set8700_A = list(1,4,3,2), protect(set8700_A[1]) == 0 +protect(set8700_A[1], 1024), protect(set8700_A[1]) == 1024 + +## Testing sort +set8700_A = sort(set8700_A), set8700_A == list(1,2,3,4) +protect(set8700_A[1]) == 0 +protect(set8700_A[3]) == 1024 ## status of 4 + +## Testings reverse +set8700_A = reverse(set8700_A), set8700_A == list(4,3,2,1) +protect(set8700_A[0]) == 1024 ## status of 4 + +## Testing swap +swap(set8700_A[0], set8700_A[1]), set8700_A == list(3,4,2,1) +protect(set8700_A[0]) == 0 ## status moved +protect(set8700_A[1]) == 1024 ## 4 retains protection + +## Testing list with protected list argument +protect(set8700_A, 0), protect(set8700_A) == 0 +protect(set8700_A, 512), protect(set8700_A) == 512 +protect(set8700_A[1]) == 1024 +set8700_L = list(1,set8700_A,3), protect(set8700_L) == 0 +protect(set8700_L[0]) == 0 +protect(set8700_L[1]) == 512 ## protect(set8700_A) copied +protect(set8700_L[1][1]) == 1024 ## protect(set8700_A[1]) copied + +## Testing list with "intialization" +set8700_L = list(1,2,3), protect(set8700_L) == 0 +protect(set8700_L[0]) | protect(set8700_L[1]) | protect(set8700_L[2]) == 0 ## All zero +set8700_L = {1,set8700_A}, set8700_L[1] == set8700_A +protect(set8700_L[1]) == 512 ## protect(set8700_A) copied +protect(set8700_L[1][1]) == 1024 ## protect(set8700_A[1]) copied +set8700_L[1] = 2, protect(set8700_L[1]) == 512 ## Not changed + +## Testing matrix with "initialization" +set8700_M = mat[3] = {1,set8700_A}, protect(set8700_M) == 0 +protect(set8700_M[0]) == 0 +protect(set8700_M[1]) == 512 ## protect(set8700_A) copied +protect(set8700_M[2]) == 0 +protect(set8700_M[1][1]) == 1024 ## protect(set8700_A[1]) copied + +## Testing push, pop, append, remove +set8700_A = list(1,2), protect(set8700_A,0,1), protect(set8700_A[0]) == 0 +protect(set8700_A[0], 256), protect(set8700_A[0]) == 256 +protect(set8700_A[1]) == 0 +append(set8700_A, pop(set8700_A)), protect(set8700_A[0]) == 0 +protect(set8700_A[1]) == 256 +push(set8700_A, remove(set8700_A)), protect(set8700_A[0]) == 256 +protect(set8700_A[1]) == 0 + +## Testing operation-assignments +set8700_A = 5, protect(set8700_A,1024), protect(set8700_A) == 1024 +protect(set8700_A, 1024), set8700_A = 7, protect(set8700_A) == 1024 +protect(set8700_A,1024), set8700_A += 2, protect(set8700_A) == 1024 +protect(set8700_A,1024), set8700_A *= 2, protect(set8700_A) == 1024 +protect(set8700_A,1024), set8700_A |= 2, protect(set8700_A) == 1024 +protect(set8700_A,1024), set8700_A &= 2, protect(set8700_A) == 1024 +protect(set8700_A,1024), set8700_A ^= 2, protect(set8700_A) == 1024 + +protect(set8700_B,0), set8700_B = set8700_getA1(), protect(set8700_B) == 1024 +protect(set8700_B,0), set8700_B = set8700_getA2(), protect(set8700_B) == 1024 +set8700_B = set8700_getvar(), protect(set8700_B) == 1024 + 256 + +global set8700_x, set8700_y; set8700_x = 7, protect(set8700_x) == 0 +protect(7,2) == error(10234) +protect(set8700_x,2.5) == error(10235) +protect(set8700_x,"abc") == error(10235) +protect(set8700_x, 1e6) == error(10235) +protect(set8700_x,1), (set8700_x = 2) == error(10366) +(set8700_x = 3 + 4) == error(10366) + +protect(set8700_x,2), protect(set8700_x) == 3 +protect(set8700_x,-1), protect(set8700_x) == 2 +(set8700_x = 2) == error(10368) +(set8700_x = 3 + 4) == 7 +protect(set8700_x,2), ++set8700_x == error(10379) +set8700_x == 7 +--set8700_x == error(10382) +set8700_x == 7 +set8700_x++ == error(10385) +set8700_x == 7 +set8700_x-- == error(10388) + +global set8700_A, set8700_B; 1 +protect(set8700_A,0), protect(set8700_A,16), 1 +set8700_A = "abcdef", protect(set8700_A) == 16 ## No copy to set8700_A +protect(set8700_B,0), set8700_B = "xyz", protect(set8700_B) == 0 +copy(set8700_B, set8700_A) == error(10226) +set8700_A == "abcdef" ## set8700_A not changed +protect(set8700_A,0), copy(set8700_B,set8700_A), set8700_A == "xyzdef" +protect(set8700_B,128), protect(set8700_B) == 128 ## No copy from set8700_B +copy(set8700_B,set8700_A,,,3) == error(10225) +set8700_A == "xyzdef" +protect(set8700_B,0), copy(set8700_B,set8700_A,,,3), set8700_A == "xyzxyz" + +set8700_A = "abcdef", protect(set8700_A, 16), swap(set8700_A[0], set8700_A[5]) == error(10371) +set8700_A == "abcdef" +protect(set8700_A,0), isnull(swap(set8700_A[0], set8700_A[5])) +set8700_A == "fbcdea" +protect(set8700_A,2), ++set8700_A[0] == error(10377) +--set8700_A[1] == error(10380) +set8700_A[2]++ == error(10383) +set8700_A[3]-- == error(10386) +set8700_A == "fbcdea" +protect(set8700_A,0), ++set8700_A[0] == 'g' +--set8700_A[1] == 'a' +set8700_A[2]++ == ord('c') +set8700_A[3]-- == ord('d') +set8700_A == "gadcea" + +protect(set8700_x,0), protect(set8700_y,0), protect(set8700_x,256), protect(set8700_y,512),1 +quomod(11,4,set8700_x,set8700_y), set8700_x == 2 && set8700_y == 3 +protect(set8700_x) == 256 +protect(set8700_y) == 512 + +set8700_A = mat[3]; protect(set8700_A[0], 1024); protect(set8700_A[0]) == 1024 +set8700_x = 7, protect(set8700_x,0), protect(set8700_x, 512), 1 +set8700_A = {set8700_x,,set8700_x}, protect(set8700_A[0]) == 1536 +protect(set8700_A[1]) == 0 +protect(set8700_A[2]) == 512 +protect(set8700_A,16), protect(set8700_A) == 16 ## No copy to +set8700_A == (mat[3] = {7,0,7}) +set8700_A = {1,2,3}, errno() == 10390; +set8700_A == (mat[3] = {7,0,7}) + +protect(set8700_A,0), set8700_A = {1,2,3}, set8700_A == (mat[3] = {1,2,3}) +protect(set8700_A[1],1), protect(set8700_A[1]) == 1 +set8700_A = {4,5,6}, errno() == 10394 +set8700_A == (mat[3] = {4,2,6}) +modify(7, "set8700_f") == error(10405) +set8700_A = list(2,3,5), modify(set8700_A, 7) == error(10406) +protect(set8700_A,2), modify(set8700_A, "set8700_f") == error(10407) +protect(set8700_A,0), modify(set8700_A, "h") == error(10408) +set8700_B = 42, protect(set8700_B,0), modify(set8700_B, "set8700_f") == error(10409) +set8700_A == list(2,3,5) ## set8700_A not affected by failures +protect(set8700_A,0,1), modify(set8700_A, "set8700_f") == null() +set8700_A == list(4,9,25) +modify(set8700_A,"set8700_g") == null() +protect(set8700_A[0]) == 0 +protect(set8700_A[1]) == 256 && protect(set8700_A[2]) == 256 + +set8700_A = 0, protect(set8700_A,0), set8700_A = pop(2), set8700_A == error(10181) +set8700_A = pop(list(1,2,3)), set8700_A == error(10181) +set8700_B = set8700_A = pop(2), set8700_B == error(10181) +set8700_A = 32, protect(set8700_A,8), (set8700_A = pop(2)) == error(10370) +set8700_A == 32 +set8700_B = set8700_A = pop(2), set8700_B == error(10370) +## Testing copying of protected elements and initialization +set8700_M1 = mat[3], protect(set8700_M1,0), protect(set8700_M1[1],1), protect(set8700_M1[1]) == 1 +set8700_M2 = mat[3], protect(set8700_M2,0), protect(set8700_M2[2],4), protect(set8700_M2[2]) == 4 +set8700_L = list(set8700_M1, set8700_M2), protect(set8700_L[0][1]) == 1 && protect(set8700_L[1][2]) == 4 +set8700_L = {{1,2,3},{'a','b','c'}}, set8700_L[0] == (mat[3] = {1,0,3}) +set8700_L[1] == (mat[3] = {'a','b',0}) +set8700_M = mat[2], protect(set8700_M,0), set8700_M = {1,2,3,4}, set8700_M == (mat[2] = {1,2}) +set8700_x = 5, set8700_M = {set8700_x++, set8700_x++, set8700_x++, set8700_x++, set8700_x++}, set8700_M == (mat[2] = {5,6}) +set8700_x == 10 ## All initialization terms evaluated +set8700_S = " ", set8700_S = {'a','b','c','d'}, set8700_S == "abc" + +set8700_P = obj set8700_point = {1,2,3,4}, set8700_P.set8700_x == 1 && set8700_P.set8700_y == 2 && set8700_P.set8700_z == 3 +protect(set8700_P,16), set8700_Q = set8700_P, set8700_Q = {5,6,7}, set8700_Q == set8700_P +set8700_P == (obj set8700_point = {1,2,3}) +set8700_L = list(mat[1] = {set8700_P}), protect(set8700_L[0][0]) == 16 +set8700_L = {{{4,5,6}}}, set8700_L[0][0] == set8700_P +protect(set8700_L,0,2), set8700_L = {{{4,5,6}}}, set8700_L[0][0] == (obj set8700_point = {4,5,6}) diff --git a/calc.c b/calc.c index 03653cb..5b30a1c 100644 --- a/calc.c +++ b/calc.c @@ -1,7 +1,7 @@ /* * calc - arbitrary precision calculator * - * Copyright (C) 1999-2004 David I. Bell, Landon Curt Noll and Ernest Bowen + * Copyright (C) 1999-2006 David I. Bell, Landon Curt Noll and Ernest Bowen * * Primary author: David I. Bell * @@ -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.11 $ - * @(#) $Id: calc.c,v 29.11 2004/02/23 14:04:01 chongo Exp $ + * @(#) $Revision: 29.13 $ + * @(#) $Id: calc.c,v 29.13 2006/05/19 15:26:10 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/RCS/calc.c,v $ * * Under source code control: 1990/02/15 01:48:11 @@ -111,7 +111,7 @@ main(int argc, char **argv) BOOL done = FALSE; BOOL havearg; BOOL haveendstr; - int len; + size_t len; /* * parse args @@ -393,7 +393,7 @@ main(int argc, char **argv) } /* XXX What if *cp = '\''? */ *bp++ = '\''; - strcpy(bp, cp); + strncpy(bp, cp, len+1); bp += len; *bp++ = '\''; cp += len; @@ -452,16 +452,19 @@ main(int argc, char **argv) } while (index < maxindex) { + size_t cplen; + if (cmdlen > 0) cmdbuf[cmdlen++] = ' '; - newcmdlen = cmdlen + strlen(cp); + cplen = strlen(cp); + newcmdlen = cmdlen + cplen; if (newcmdlen > MAXCMD) { fprintf(stderr, "%s: commands too long\n", program); exit(1); } - strcpy(cmdbuf + cmdlen, cp); + strncpy(cmdbuf + cmdlen, cp, cplen+1); cmdlen = newcmdlen; index++; if (index < maxindex) @@ -579,7 +582,7 @@ main(int argc, char **argv) if (run_state == RUN_PRE_CMD_ARGS) { if (havecommands) { set_run_state(RUN_CMD_ARGS); - (void) openstring(cmdbuf, (long) strlen(cmdbuf)); + (void) openstring(cmdbuf, strlen(cmdbuf)); getcommands(FALSE); closeinput(); } diff --git a/calc.h b/calc.h index 5118536..7985f16 100644 --- a/calc.h +++ b/calc.h @@ -1,7 +1,7 @@ /* * calc - definitions for calculator program * - * Copyright (C) 1999 David I. Bell + * Copyright (C) 1999-2006 David I. Bell * * Calc is open software; you can redistribute it and/or modify it under * the terms of the version 2.1 of the GNU Lesser General Public License @@ -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.11 $ - * @(#) $Id: calc.h,v 29.11 2003/08/26 04:36:10 chongo Exp $ + * @(#) $Revision: 29.18 $ + * @(#) $Id: calc.h,v 29.18 2006/05/21 07:28:54 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/RCS/calc.h,v $ * * Under source code control: 1990/02/15 01:48:31 @@ -98,12 +98,13 @@ #define FILEID_STDIN ((FILEID) 0) #define FILEID_STDOUT ((FILEID) 1) #define FILEID_STDERR ((FILEID) 2) -#define FILEID_NONE ((FILEID) -1) +#define FILEID_NONE ((FILEID) -1) /* must be < 0 */ /* * File I/O routines. */ extern DLL FILEID openid(char *name, char *mode); +extern DLL FILEID openpathid(char *name, char *mode, char *pathlist); extern DLL FILEID indexid(long index); extern DLL BOOL validid(FILEID id); extern DLL BOOL errorid(FILEID id); @@ -148,7 +149,7 @@ extern DLL void trimconstants(void); /* * Input routines. */ -extern DLL int openstring(char *str, long num); +extern DLL int openstring(char *str, size_t num); extern DLL int openterminal(void); extern DLL int opensearchfile(char *name, char *pathlist, char *exten, int reopen_ok); extern DLL char *nextline(void); @@ -205,7 +206,7 @@ extern DLL int d_flag; /* TRUE => disable heading, resource_debug */ extern DLL int c_flag; /* TRUE => continue after error if permitted */ extern DLL int i_flag; /* TRUE => try to go interactive after error */ extern DLL int s_flag; /* TRUE => keep args as strings for argv() */ -extern DLL int stoponerror; /* >0 => stop, <0 => continue, ==0 => use -c */ +extern DLL long stoponerror; /* >0 => stop, <0 => continue, ==0 => use -c */ extern DLL BOOL abort_now; /* TRUE => try to go interactive */ extern DLL int argc_value; /* count of argv[] strings for argv() builtin */ @@ -231,7 +232,7 @@ extern DLL char *shell; /* $SHELL or default */ extern DLL char *program; /* our name (argv[0]) */ extern DLL int no_env; /* TRUE (-e) => ignore env vars on startup */ -extern DLL int errmax; /* if >= 0, error when errcount exceeds errmax */ +extern DLL long errmax; /* if >= 0, error when errcount exceeds errmax */ extern DLL int use_old_std; /* TRUE (-O) => use classic configuration */ extern DLL int allow_read; /* FALSE => dont open any files for reading */ diff --git a/calc.spec.in b/calc.spec.in index 1ab34f0..e84239b 100644 --- a/calc.spec.in +++ b/calc.spec.in @@ -18,8 +18,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.14 $ -# @(#) $Id: calc.spec.in,v 29.14 2005/12/12 06:57:27 chongo Exp $ +# @(#) $Revision: 29.15 $ +# @(#) $Id: calc.spec.in,v 29.15 2006/05/21 06:26:00 chongo Exp $ # @(#) $Source: /usr/local/src/cmd/calc/RCS/calc.spec.in,v $ # # Under source code control: 2003/02/16 20:21:39 @@ -92,6 +92,7 @@ rm -rf %{buildroot} %{_datadir}/%{name}/bindings %{_datadir}/%{name}/README %{_datadir}/%{name}/*.cal +%{_datadir}/%{name}/*.line %files devel %defattr(-, root, root) @@ -100,7 +101,10 @@ rm -rf %{buildroot} %attr(644, root, root) %{_libdir}/*.a %changelog -* Sun Dec 11 2006 Landon Curt Noll http://www.isthe.com/chongo +* Sun May 20 2006 Landon Curt Noll http://www.isthe.com/chongo +- Release of calc-2.12.0 +- Added *.line set files to the list of packaged files +* Sun Dec 11 2005 Landon Curt Noll http://www.isthe.com/chongo - Release of calc-2.11.11 - Fixed description in spec file * Wed Feb 26 2003 Landon Curt Noll http://www.isthe.com/chongo diff --git a/calcerr.tbl b/calcerr.tbl index 6ab0292..820bf2e 100644 --- a/calcerr.tbl +++ b/calcerr.tbl @@ -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: calcerr.tbl,v 29.4 2001/04/10 22:06:46 chongo Exp $ +# @(#) $Revision: 29.8 $ +# @(#) $Id: calcerr.tbl,v 29.8 2006/05/19 15:12:57 chongo Exp $ # @(#) $Source: /usr/local/src/cmd/calc/RCS/calcerr.tbl,v $ # # Under source code control: 1996/05/23 17:38:44 @@ -164,7 +164,7 @@ E_RSEARCH3 Bad third argument for rsearch E_RSEARCH4 Bad fourth argument for rsearch E_RSEARCH5 Cannot find fsize or fpos for rsearch E_RSEARCH6 File not readable for rsearch -E_FOPEN3 Too many open files +E_MANYOPEN Too many open files E_REWIND2 Attempt to rewind a file that is not open E_STRERROR1 Bad argument type for strerror E_STRERROR2 Index out of range for strerror @@ -260,14 +260,14 @@ E_COPY13 No-copy-from source variable E_COPY14 No-copy-to destination variable E_COPY15 No-copy-from source named block E_COPY16 No-copy-to destination named block -E_COPY17 No-relocation destination for copy +E_COPY17 No-relocate destination for copy E_COPYF1 File not open for copy E_COPYF2 fseek or fsize failure for copy E_COPYF3 fwrite error for copy E_COPYF4 fread error for copy E_PROTECT1 Non-variable first argument for protect -E_PROTECT2 Non-integer second argument for protect -E_PROTECT3 Out-of-range second argument for protect +E_PROTECT2 Bad second argument for protect +E_PROTECT3 Bad third argument for protect E_MATFILL3 No-copy-to destination for matfill E_MATFILL4 No-assign-from source for matfill E_MATTRACE1 Non-matrix argument for mattrace @@ -393,3 +393,55 @@ E_BERN Bad argument for bern E_EULER Bad argument for euler E_SLEEP Bad argument for sleep E_TTY calc_tty failure +E_ASSIGN1 No-copy-to destination for octet assign +E_ASSIGN2 No-copy-from source for octet assign +E_ASSIGN3 No-change destination for octet assign +E_ASSIGN4 Non-variable destination for assign +E_ASSIGN5 No-assign-to destination for assign +E_ASSIGN6 No-assign-from source for assign +E_ASSIGN7 No-change destination for assign +E_ASSIGN8 No-type-change destination for assign +E_ASSIGN9 No-error-value destination for assign +E_SWAP1 No-copy argument for octet swap +E_SWAP2 No-assign-to-or-from argument for swap +E_SWAP3 Non-variable argument for swap +E_QUOMOD1 Non-variable argument 4 or 4 for quomod +E_QUOMOD2 Non-real-number argument 1 or 2 for quomod +E_QUOMOD3 No-assign-to argument 3 or 4 for quomod +E_PREINC1 No-copy-to or no-change argument for octet preinc +E_PREINC2 Non-variable argument for preinc +E_PREINC3 No-assign-to or no-change argument for preinc +E_PREDEC1 No-copy-to or no-change argument for octet predec +E_PREDEC2 Non-variable argument for predec +E_PREDEC3 No-assign-to or no-change argument for predec +E_POSTINC1 No-copy-to or no-change argument for octet postinc +E_POSTINC2 Non-variable argument for postinc +E_POSTINC3 No-assign-to or no-change argument for postinc +E_POSTDEC1 No-copy-to or no-change argument for octet postdec +E_POSTDEC2 Non-variable argument for postdec +E_POSTDEC3 No-assign-to or no-change argument for postdec +E_INIT1 Error-type structure for initialization +E_INIT2 No-copy-to structure for initialization +E_INIT3 Too many initializer values +E_INIT4 Attempt to initialize freed named block +E_INIT5 Bad structure type for initialization +E_INIT6 No-assign-to element for initialization +E_INIT7 No-change element for initialization +E_INIT8 No-type-change element for initialization +E_INIT9 No-error-value element for initialization +E_INIT10 No-assign-or-copy-from source for initialization +E_LIST1 No-relocate for list insert +E_LIST2 No-relocate for list delete +E_LIST3 No-relocate for list push +E_LIST4 No-relocate for list append +E_LIST5 No-relocate for list pop +E_LIST6 No-relocate for list remove +E_MODIFY1 Non-variable first argument for modify +E_MODIFY2 Non-string second argument for modify +E_MODIFY3 No-change first argument for modify +E_MODIFY4 Undefined function for modify +E_MODIFY5 Unacceptable type first argument for modify +E_FPATHOPEN1 Non-string arguments for fpathopen +E_FPATHOPEN2 Unrecognized mode for fpathopen +E_LOG1 Bad epsilon argument for log +E_LOG2 Non-numeric first argument for log diff --git a/check.awk b/check.awk index 218bbda..7ab86aa 100644 --- a/check.awk +++ b/check.awk @@ -2,7 +2,7 @@ # # check - check the regression output for problems # -# Copyright (C) 1999 Landon Curt Noll +# Copyright (C) 1999-2006 Landon Curt Noll # # Calc is open software; you can redistribute it and/or modify it under # the terms of the version 2.1 of the GNU Lesser General Public License @@ -18,8 +18,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: check.awk,v 29.2 2000/06/07 14:02:13 chongo Exp $ +# @(#) $Revision: 29.3 $ +# @(#) $Id: check.awk,v 29.3 2006/05/20 19:43:39 chongo Exp $ # @(#) $Source: /usr/local/src/cmd/calc/RCS/check.awk,v $ # # Under source code control: 1996/05/25 22:07:58 @@ -64,7 +64,7 @@ NF == 0 { end_seen = 1; } -$1 ~ /^[0-9]+:/ { +$1 ~ /^[0-9]+:/ || $1 ~ /^[0-9]+-[0-9]*:/ { if (error > 0) { if (havebuf2) { print buf2; diff --git a/cmath.h b/cmath.h index 9a79589..f2446bb 100644 --- a/cmath.h +++ b/cmath.h @@ -100,6 +100,7 @@ extern COMPLEX *c_sqrt(COMPLEX *c, NUMBER *epsilon, long R); extern COMPLEX *c_root(COMPLEX *c, NUMBER *q, NUMBER *epsilon); extern COMPLEX *c_exp(COMPLEX *c, NUMBER *epsilon); extern COMPLEX *c_ln(COMPLEX *c, NUMBER *epsilon); +extern COMPLEX *c_log(COMPLEX *c, NUMBER *epsilon); extern COMPLEX *c_cos(COMPLEX *c, NUMBER *epsilon); extern COMPLEX *c_sin(COMPLEX *c, NUMBER *epsilon); extern COMPLEX *c_cosh(COMPLEX *c, NUMBER *epsilon); diff --git a/codegen.c b/codegen.c index db01a23..73f5216 100644 --- a/codegen.c +++ b/codegen.c @@ -1,7 +1,7 @@ /* * codegen - module to generate opcodes from the input tokens * - * Copyright (C) 1999-2004 David I. Bell and Ernest Bowen + * Copyright (C) 1999-2006 David I. Bell and Ernest Bowen * * Primary author: David I. Bell * @@ -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.9 $ - * @(#) $Id: codegen.c,v 29.9 2004/02/23 14:04:01 chongo Exp $ + * @(#) $Revision: 29.15 $ + * @(#) $Id: codegen.c,v 29.15 2006/05/20 09:42:57 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/RCS/codegen.c,v $ * * Under source code control: 1990/02/15 01:48:13 @@ -53,7 +53,8 @@ static BOOL rdonce; /* TRUE => do not reread this file */ FUNC *curfunc; -static int getfilename(char *name, BOOL *once); +static int getsymvalue(char *name, VALUE *v_p); +static int getfilename(char *name, size_t namelen, BOOL *once); static BOOL getid(char *buf); static void getshowstatement(void); static void getfunction(void); @@ -146,7 +147,7 @@ getcommands(BOOL toplevel) case T_HELP: for (i=1;;i++) { - switch(getfilename(name, NULL)) { + switch(getfilename(name, MAXCMD+1, NULL)) { case -1: if(i == 1) { strcpy(name, DEFAULTCALCHELP); @@ -170,10 +171,13 @@ getcommands(BOOL toplevel) break; } for (;;) { - if (getfilename(name, &rdonce)) + int open_ret; + + if (getfilename(name, MAXCMD+1, &rdonce)) break; - switch (opensearchfile(name,calcpath, - CALCEXT,rdonce)) { + open_ret = opensearchfile(name,calcpath, + CALCEXT,rdonce); + switch (open_ret) { case 0: getcommands(FALSE); closeinput(); @@ -200,7 +204,7 @@ getcommands(BOOL toplevel) "write command disallowed by -m mode\n"); break; } - if (getfilename(name, NULL)) + if (getfilename(name, MAXCMD+1, NULL)) break; if (writeglobals(name)) { scanerror(T_NULL, @@ -213,8 +217,6 @@ getcommands(BOOL toplevel) break; case T_NEWLINE: case T_SEMICOLON: - case T_POUNDBANG: - case T_POUNDCOMMENT: break; default: @@ -264,17 +266,17 @@ evaluate(BOOL nestflag) rescantoken(); while (loop) { switch (gettoken()) { - case T_SEMICOLON: - break; - case T_NEWLINE: - case T_EOF: - loop = 0; - break; + case T_SEMICOLON: + break; + case T_NEWLINE: + case T_EOF: + loop = 0; + break; - default: - rescantoken(); - getstatement(NULL_LABEL, NULL_LABEL, - NULL_LABEL, NULL_LABEL); + default: + rescantoken(); + getstatement(NULL_LABEL, NULL_LABEL, + NULL_LABEL, NULL_LABEL); } } } @@ -298,31 +300,29 @@ ungetfunction(void) for (;;) { switch (gettoken()) { - case T_COMMA: - continue; - case T_SYMBOL: - name = tokensymbol(); - type = getbuiltinfunc(name); - if (type >= 0) { - fprintf(stderr, - "Attempt to undefine builtin function \"%s\" ignored\n", - name); - continue; - } - rmuserfunc(name); - continue; - case T_MULT: - rmalluserfunc(); - continue; - case T_NEWLINE: - case T_SEMICOLON: - case T_EOF: - rescantoken(); - return; - default: - scanerror(T_SEMICOLON, - "Non-name arg for undefine"); - return; + case T_COMMA: + continue; + case T_SYMBOL: + name = tokensymbol(); + type = getbuiltinfunc(name); + if (type >= 0) { + fprintf(stderr, + "Attempt to undefine builtin function \"%s\" ignored\n", name); + continue; + } + rmuserfunc(name); + continue; + case T_MULT: + rmalluserfunc(); + continue; + case T_NEWLINE: + case T_SEMICOLON: + case T_EOF: + rescantoken(); + return; + default: + scanerror(T_SEMICOLON, "Non-name arg for undefine"); + return; } } } @@ -370,15 +370,15 @@ getfunction(void) } name = tokensymbol(); switch (symboltype(name)) { - case SYM_UNDEFINED: - case SYM_GLOBAL: - case SYM_STATIC: - index = addparam(name); - break; - default: - scanerror(T_NULL, - "Parameter \"%s\" is already defined", - name); + case SYM_UNDEFINED: + case SYM_GLOBAL: + case SYM_STATIC: + index = addparam(name); + break; + default: + scanerror(T_NULL, + "Parameter \"%s\" is already defined", + name); } type = gettoken(); if (type == T_ASSIGN) { @@ -399,18 +399,18 @@ getfunction(void) } } switch (gettoken()) { - case T_ASSIGN: - getsimplebody(); - break; - case T_LEFTBRACE: - getbody(NULL_LABEL, NULL_LABEL, NULL_LABEL, - NULL_LABEL); - break; - default: - scanerror(T_NULL, - "Left brace or equals sign " - "expected for function"); - return; + case T_ASSIGN: + getsimplebody(); + break; + case T_LEFTBRACE: + getbody(NULL_LABEL, NULL_LABEL, NULL_LABEL, + NULL_LABEL); + break; + default: + scanerror(T_NULL, + "Left brace or equals sign " + "expected for function"); + return; } endfunc(); exitfuncscope(); @@ -473,40 +473,40 @@ getdeclarations(int symtype) while (TRUE) { switch (gettoken()) { - case T_COMMA: - continue; + case T_COMMA: + continue; - case T_NEWLINE: - case T_SEMICOLON: - case T_RIGHTBRACE: - case T_EOF: - rescantoken(); - return res; + case T_NEWLINE: + case T_SEMICOLON: + case T_RIGHTBRACE: + case T_EOF: + rescantoken(); + return res; - case T_SYMBOL: - addopone(OP_DEBUG, linenumber()); - rescantoken(); - if (getsimpledeclaration(symtype)) - res = 1; - break; - - case T_MAT: - addopone(OP_DEBUG, linenumber()); - getmatdeclaration(symtype); + case T_SYMBOL: + addopone(OP_DEBUG, linenumber()); + rescantoken(); + if (getsimpledeclaration(symtype)) res = 1; - break; + break; - case T_OBJ: - addopone(OP_DEBUG, linenumber()); - getobjdeclaration(symtype); - addop(OP_POP); - res = 1; - break; + case T_MAT: + addopone(OP_DEBUG, linenumber()); + getmatdeclaration(symtype); + res = 1; + break; - default: - scanerror(T_SEMICOLON, - "Bad syntax in declaration statement"); - return res; + case T_OBJ: + addopone(OP_DEBUG, linenumber()); + getobjdeclaration(symtype); + addop(OP_POP); + res = 1; + break; + + default: + scanerror(T_SEMICOLON, + "Bad syntax in declaration statement"); + return res; } } } @@ -525,18 +525,18 @@ getsimpledeclaration(int symtype) for (;;) { switch (gettoken()) { - case T_SYMBOL: - rescantoken(); - if (getonevariable(symtype)) { - res = 1; - addop(OP_POP); - } - continue; - case T_COMMA: - continue; - default: - rescantoken(); - return res; + case T_SYMBOL: + rescantoken(); + if (getonevariable(symtype)) { + res = 1; + addop(OP_POP); + } + continue; + case T_COMMA: + continue; + default: + rescantoken(); + return res; } } } @@ -555,22 +555,22 @@ getonevariable(int symtype) int res = 0; switch(gettoken()) { - case T_SYMBOL: - name = addliteral(tokensymbol()); - res = getonevariable(symtype); - definesymbol(name, symtype); - if (res) { - usesymbol(name, 0); - addop(OP_ASSIGNBACK); - } - return res; - case T_ASSIGN: - getopassignment(); - rescantoken(); - return 1; - default: - rescantoken(); - return 0; + case T_SYMBOL: + name = addliteral(tokensymbol()); + res = getonevariable(symtype); + definesymbol(name, symtype); + if (res) { + usesymbol(name, 0); + addop(OP_ASSIGNBACK); + } + return res; + case T_ASSIGN: + getopassignment(); + rescantoken(); + return 1; + default: + rescantoken(); + return 0; } } @@ -665,17 +665,17 @@ getstatement(LABEL *contlabel, LABEL *breaklabel, LABEL *nextcaselabel, LABEL *d case T_RETURN: switch (gettoken()) { - case T_NEWLINE: - case T_SEMICOLON: - addop(OP_UNDEF); - addop(OP_RETURN); - return; - default: - rescantoken(); - (void) getexprlist(); - if (curfunc->f_name[0] == '*') - addop(OP_SAVE); - addop(OP_RETURN); + case T_NEWLINE: + case T_SEMICOLON: + addop(OP_UNDEF); + addop(OP_RETURN); + return; + default: + rescantoken(); + (void) getexprlist(); + if (curfunc->f_name[0] == '*') + addop(OP_SAVE); + addop(OP_RETURN); } break; @@ -688,49 +688,49 @@ getstatement(LABEL *contlabel, LABEL *breaklabel, LABEL *nextcaselabel, LABEL *d clearlabel(&label2); getcondition(); switch(gettoken()) { - case T_CONTINUE: - if (contlabel == NULL_LABEL) { - scanerror(T_SEMICOLON, - "CONTINUE not within FOR, " - "WHILE, or DO"); - return; - } - addoplabel(OP_JUMPNZ, contlabel); - break; - case T_BREAK: - if (breaklabel == NULL_LABEL) { - scanerror(T_SEMICOLON, - "BREAK not within FOR, " - "WHILE, or DO"); - return; - } - addoplabel(OP_JUMPNZ, breaklabel); - break; - case T_GOTO: - if (gettoken() != T_SYMBOL) { - scanerror(T_SEMICOLON, - "Missing label in goto"); - return; - } - addop(OP_JUMPNZ); - addlabel(tokensymbol()); - break; - default: - addoplabel(OP_JUMPZ, &label1); - rescantoken(); - getstatement(contlabel, breaklabel, - NULL_LABEL, NULL_LABEL); - if (gettoken() != T_ELSE) { - setlabel(&label1); - rescantoken(); - return; - } - addoplabel(OP_JUMP, &label2); - setlabel(&label1); - getstatement(contlabel, breaklabel, - NULL_LABEL, NULL_LABEL); - setlabel(&label2); + case T_CONTINUE: + if (contlabel == NULL_LABEL) { + scanerror(T_SEMICOLON, + "CONTINUE not within FOR, " + "WHILE, or DO"); return; + } + addoplabel(OP_JUMPNZ, contlabel); + break; + case T_BREAK: + if (breaklabel == NULL_LABEL) { + scanerror(T_SEMICOLON, + "BREAK not within FOR, " + "WHILE, or DO"); + return; + } + addoplabel(OP_JUMPNZ, breaklabel); + break; + case T_GOTO: + if (gettoken() != T_SYMBOL) { + scanerror(T_SEMICOLON, + "Missing label in goto"); + return; + } + addop(OP_JUMPNZ); + addlabel(tokensymbol()); + break; + default: + addoplabel(OP_JUMPZ, &label1); + rescantoken(); + getstatement(contlabel, breaklabel, + NULL_LABEL, NULL_LABEL); + if (gettoken() != T_ELSE) { + setlabel(&label1); + rescantoken(); + return; + } + addoplabel(OP_JUMP, &label2); + setlabel(&label1); + getstatement(contlabel, breaklabel, + NULL_LABEL, NULL_LABEL); + setlabel(&label2); + return; } if (gettoken() != T_SEMICOLON) /* This makes ';' optional */ rescantoken(); @@ -934,54 +934,54 @@ getstatement(LABEL *contlabel, LABEL *breaklabel, LABEL *nextcaselabel, LABEL *d printeol = TRUE; for (;;) { switch (gettoken()) { - case T_RIGHTPAREN: - case T_RIGHTBRACKET: - case T_RIGHTBRACE: - case T_NEWLINE: - case T_EOF: - rescantoken(); - /*FALLTHRU*/ - case T_SEMICOLON: - if (printeol) - addop(OP_PRINTEOL); - return; - case T_COMMA: - addop(OP_PRINTSPACE); - /*FALLTHRU*/ - case T_COLON: - printeol = FALSE; - break; - case T_STRING: - printeol = TRUE; - addopone(OP_PRINTSTRING, tokenstring()); - break; - default: - printeol = TRUE; - rescantoken(); - (void) getopassignment(); - addopone(OP_PRINT, (long) PRINT_NORMAL); + case T_RIGHTPAREN: + case T_RIGHTBRACKET: + case T_RIGHTBRACE: + case T_NEWLINE: + case T_EOF: + rescantoken(); + /*FALLTHRU*/ + case T_SEMICOLON: + if (printeol) + addop(OP_PRINTEOL); + return; + case T_COMMA: + addop(OP_PRINTSPACE); + /*FALLTHRU*/ + case T_COLON: + printeol = FALSE; + break; + case T_STRING: + printeol = TRUE; + addopone(OP_PRINTSTRING, tokenstring()); + break; + default: + printeol = TRUE; + rescantoken(); + (void) getopassignment(); + addopone(OP_PRINT, (long) PRINT_NORMAL); } } case T_QUIT: switch (gettoken()) { - case T_STRING: - addopone(OP_QUIT, tokenstring()); - break; - default: - addopone(OP_QUIT, -1); - rescantoken(); + case T_STRING: + addopone(OP_QUIT, tokenstring()); + break; + default: + addopone(OP_QUIT, -1); + rescantoken(); } break; case T_ABORT: switch (gettoken()) { - case T_STRING: - addopone(OP_ABORT, tokenstring()); - break; - default: - addopone(OP_ABORT, -1); - rescantoken(); + case T_STRING: + addopone(OP_ABORT, tokenstring()); + break; + default: + addopone(OP_ABORT, -1); + rescantoken(); } break; @@ -1017,21 +1017,21 @@ getstatement(LABEL *contlabel, LABEL *breaklabel, LABEL *nextcaselabel, LABEL *d } for (;;) { switch (gettoken()) { - case T_RIGHTBRACE: - case T_NEWLINE: - case T_EOF: - rescantoken(); - return; - case T_SEMICOLON: - return; - case T_NUMBER: - case T_IMAGINARY: - addopone(OP_NUMBER, tokennumber()); - scanerror(T_NULL, "Unexpected number"); - continue; - default: - scanerror(T_NULL, "Semicolon expected"); - return; + case T_RIGHTBRACE: + case T_NEWLINE: + case T_EOF: + rescantoken(); + return; + case T_SEMICOLON: + return; + case T_NUMBER: + case T_IMAGINARY: + addopone(OP_NUMBER, tokennumber()); + scanerror(T_NULL, "Unexpected number"); + continue; + default: + scanerror(T_NULL, "Semicolon expected"); + return; } } } @@ -1215,16 +1215,16 @@ getmatdeclaration(int symtype) { for (;;) { switch (gettoken()) { - case T_SYMBOL: - rescantoken(); - getonematrix(symtype); - addop(OP_POP); - continue; - case T_COMMA: - continue; - default: - rescantoken(); - return; + case T_SYMBOL: + rescantoken(); + getonematrix(symtype); + addop(OP_POP); + continue; + case T_COMMA: + continue; + default: + rescantoken(); + return; } } } @@ -1353,27 +1353,27 @@ creatematrix(void) } (void) getopassignment(); switch (gettoken()) { + case T_RIGHTBRACKET: + rescantoken(); + case T_COMMA: + addop(OP_ONE); + addop(OP_SUB); + addop(OP_ZERO); + break; + case T_COLON: + (void) getopassignment(); + switch(gettoken()) { case T_RIGHTBRACKET: rescantoken(); case T_COMMA: - addop(OP_ONE); - addop(OP_SUB); - addop(OP_ZERO); - break; - case T_COLON: - (void) getopassignment(); - switch(gettoken()) { - case T_RIGHTBRACKET: - rescantoken(); - case T_COMMA: - continue; - } - /*FALLTHRU*/ - default: - rescantoken(); - scanerror(T_SEMICOLON, - "Illegal matrix definition"); - return; + continue; + } + /*FALLTHRU*/ + default: + rescantoken(); + scanerror(T_SEMICOLON, + "Illegal matrix definition"); + return; } } } @@ -1400,37 +1400,37 @@ getinitlist(void) for (index = 0; ; index++) { switch(gettoken()) { - case T_COMMA: - case T_NEWLINE: - continue; - case T_RIGHTBRACE: - (void) tokenmode(oldmode); - return index; - case T_LEFTBRACE: - rescantoken(); - addop(OP_DUPLICATE); - addopone(OP_ELEMADDR, index); - (void) getinitlist(); - break; - default: - rescantoken(); - getopassignment(); + case T_COMMA: + case T_NEWLINE: + continue; + case T_RIGHTBRACE: + (void) tokenmode(oldmode); + return index; + case T_LEFTBRACE: + rescantoken(); + addop(OP_DUPLICATE); + addopone(OP_ELEMADDR, index); + (void) getinitlist(); + break; + default: + rescantoken(); + getopassignment(); } addopone(OP_ELEMINIT, index); switch (gettoken()) { - case T_COMMA: - case T_NEWLINE: - continue; + case T_COMMA: + case T_NEWLINE: + continue; - case T_RIGHTBRACE: - (void) tokenmode(oldmode); - return index; + case T_RIGHTBRACE: + (void) tokenmode(oldmode); + return index; - default: - scanerror(T_SEMICOLON, - "Bad initialization list"); - (void) tokenmode(oldmode); - return -1; + default: + scanerror(T_SEMICOLON, + "Bad initialization list"); + (void) tokenmode(oldmode); + return -1; } } } @@ -1505,24 +1505,24 @@ getopassignment(void) type = getassignment(); switch (gettoken()) { - case T_PLUSEQUALS: op = OP_ADD; break; - case T_MINUSEQUALS: op = OP_SUB; break; - case T_MULTEQUALS: op = OP_MUL; break; - case T_DIVEQUALS: op = OP_DIV; break; - case T_SLASHSLASHEQUALS: op = OP_QUO; break; - case T_MODEQUALS: op = OP_MOD; break; - case T_ANDEQUALS: op = OP_AND; break; - case T_OREQUALS: op = OP_OR; break; - case T_LSHIFTEQUALS: op = OP_LEFTSHIFT; break; - case T_RSHIFTEQUALS: op = OP_RIGHTSHIFT; break; - case T_POWEREQUALS: op = OP_POWER; break; - case T_HASHEQUALS: op = OP_HASHOP; break; - case T_TILDEEQUALS: op = OP_XOR; break; - case T_BACKSLASHEQUALS: op = OP_SETMINUS; break; + case T_PLUSEQUALS: op = OP_ADD; break; + case T_MINUSEQUALS: op = OP_SUB; break; + case T_MULTEQUALS: op = OP_MUL; break; + case T_DIVEQUALS: op = OP_DIV; break; + case T_SLASHSLASHEQUALS: op = OP_QUO; break; + case T_MODEQUALS: op = OP_MOD; break; + case T_ANDEQUALS: op = OP_AND; break; + case T_OREQUALS: op = OP_OR; break; + case T_LSHIFTEQUALS: op = OP_LEFTSHIFT; break; + case T_RSHIFTEQUALS: op = OP_RIGHTSHIFT; break; + case T_POWEREQUALS: op = OP_POWER; break; + case T_HASHEQUALS: op = OP_HASHOP; break; + case T_TILDEEQUALS: op = OP_XOR; break; + case T_BACKSLASHEQUALS: op = OP_SETMINUS; break; - default: - rescantoken(); - return type; + default: + rescantoken(); + return type; } if (isrvalue(type)) { scanerror(T_NULL, "Illegal assignment"); @@ -1546,24 +1546,24 @@ getopassignment(void) addop(op); addop(OP_ASSIGN); switch (gettoken()) { - case T_PLUSEQUALS: op = OP_ADD; break; - case T_MINUSEQUALS: op = OP_SUB; break; - case T_MULTEQUALS: op = OP_MUL; break; - case T_DIVEQUALS: op = OP_DIV; break; - case T_SLASHSLASHEQUALS: op = OP_QUO; break; - case T_MODEQUALS: op = OP_MOD; break; - case T_ANDEQUALS: op = OP_AND; break; - case T_OREQUALS: op = OP_OR; break; - case T_LSHIFTEQUALS: op = OP_LEFTSHIFT; break; - case T_RSHIFTEQUALS: op = OP_RIGHTSHIFT; break; - case T_POWEREQUALS: op = OP_POWER; break; - case T_HASHEQUALS: op = OP_HASHOP; break; - case T_TILDEEQUALS: op = OP_XOR; break; - case T_BACKSLASHEQUALS: op = OP_SETMINUS; break; + case T_PLUSEQUALS: op = OP_ADD; break; + case T_MINUSEQUALS: op = OP_SUB; break; + case T_MULTEQUALS: op = OP_MUL; break; + case T_DIVEQUALS: op = OP_DIV; break; + case T_SLASHSLASHEQUALS: op = OP_QUO; break; + case T_MODEQUALS: op = OP_MOD; break; + case T_ANDEQUALS: op = OP_AND; break; + case T_OREQUALS: op = OP_OR; break; + case T_LSHIFTEQUALS: op = OP_LEFTSHIFT; break; + case T_RSHIFTEQUALS: op = OP_RIGHTSHIFT; break; + case T_POWEREQUALS: op = OP_POWER; break; + case T_HASHEQUALS: op = OP_HASHOP; break; + case T_TILDEEQUALS: op = OP_XOR; break; + case T_BACKSLASHEQUALS: op = OP_SETMINUS; break; - default: - rescantoken(); - return EXPR_ASSIGN; + default: + rescantoken(); + return EXPR_ASSIGN; } } } @@ -1579,16 +1579,16 @@ getassignment (void) int type; /* type of expression */ switch(gettoken()) { - case T_COMMA: - case T_SEMICOLON: - case T_NEWLINE: - case T_RIGHTPAREN: - case T_RIGHTBRACKET: - case T_RIGHTBRACE: - case T_EOF: - addop(OP_UNDEF); - rescantoken(); - return EXPR_RVALUE; + case T_COMMA: + case T_SEMICOLON: + case T_NEWLINE: + case T_RIGHTPAREN: + case T_RIGHTBRACKET: + case T_RIGHTBRACE: + case T_EOF: + addop(OP_UNDEF); + rescantoken(); + return EXPR_RVALUE; } rescantoken(); @@ -1596,26 +1596,26 @@ getassignment (void) type = getaltcond(); switch (gettoken()) { - case T_NUMBER: - case T_IMAGINARY: - addopone(OP_NUMBER, tokennumber()); - type = (EXPR_RVALUE | EXPR_CONST); - /*FALLTHRU*/ - case T_STRING: - case T_SYMBOL: - case T_OLDVALUE: - case T_LEFTPAREN: - case T_PLUSPLUS: - case T_MINUSMINUS: - case T_NOT: - scanerror(T_NULL, "Missing operator"); - return type; - case T_ASSIGN: - break; + case T_NUMBER: + case T_IMAGINARY: + addopone(OP_NUMBER, tokennumber()); + type = (EXPR_RVALUE | EXPR_CONST); + /*FALLTHRU*/ + case T_STRING: + case T_SYMBOL: + case T_OLDVALUE: + case T_LEFTPAREN: + case T_PLUSPLUS: + case T_MINUSMINUS: + case T_NOT: + scanerror(T_NULL, "Missing operator"); + return type; + case T_ASSIGN: + break; - default: - rescantoken(); - return type; + default: + rescantoken(); + return type; } if (isrvalue(type)) { scanerror(T_SEMICOLON, "Illegal assignment"); @@ -1739,15 +1739,15 @@ getrelation(void) type = getsum(); switch (gettoken()) { - case T_EQ: op = OP_EQ; break; - case T_NE: op = OP_NE; break; - case T_LT: op = OP_LT; break; - case T_GT: op = OP_GT; break; - case T_LE: op = OP_LE; break; - case T_GE: op = OP_GE; break; - default: - rescantoken(); - return type; + case T_EQ: op = OP_EQ; break; + case T_NE: op = OP_NE; break; + case T_LT: op = OP_LT; break; + case T_GT: op = OP_GT; break; + case T_LE: op = OP_LE; break; + case T_GE: op = OP_GE; break; + default: + rescantoken(); + return type; } if (islvalue(type)) addop(OP_GETVALUE); @@ -1770,25 +1770,26 @@ getsum(void) type = EXPR_RVALUE; switch(gettoken()) { - case T_PLUS: - (void) getproduct(); - addop(OP_PLUS); - break; - case T_MINUS: - (void) getproduct(); - addop(OP_NEGATE); - break; - default: - rescantoken(); - type = getproduct(); + case T_PLUS: + (void) getproduct(); + addop(OP_PLUS); + break; + case T_MINUS: + (void) getproduct(); + addop(OP_NEGATE); + break; + default: + rescantoken(); + type = getproduct(); } for (;;) { switch (gettoken()) { - case T_PLUS: op = OP_ADD; break; - case T_MINUS: op = OP_SUB; break; - default: - rescantoken(); - return type; + case T_PLUS: op = OP_ADD; break; + case T_MINUS: op = OP_SUB; break; + case T_HASH: op = OP_HASHOP; break; + default: + rescantoken(); + return type; } if (islvalue(type)) addop(OP_GETVALUE); @@ -1813,13 +1814,13 @@ getproduct(void) type = getorexpr(); for (;;) { switch (gettoken()) { - case T_MULT: op = OP_MUL; break; - case T_DIV: op = OP_DIV; break; - case T_MOD: op = OP_MOD; break; - case T_SLASHSLASH: op = OP_QUO; break; - default: - rescantoken(); - return type; + case T_MULT: op = OP_MUL; break; + case T_DIV: op = OP_DIV; break; + case T_MOD: op = OP_MOD; break; + case T_SLASHSLASH: op = OP_QUO; break; + default: + rescantoken(); + return type; } if (islvalue(type)) addop(OP_GETVALUE); @@ -1867,13 +1868,12 @@ getandexpr(void) type = getshiftexpr(); for (;;) { switch (gettoken()) { - case T_AND: op = OP_AND; break; - case T_HASH: op = OP_HASHOP; break; - case T_TILDE: op = OP_XOR; break; - case T_BACKSLASH: op = OP_SETMINUS; break; - default: - rescantoken(); - return type; + case T_AND: op = OP_AND; break; + case T_TILDE: op = OP_XOR; break; + case T_BACKSLASH: op = OP_SETMINUS; break; + default: + rescantoken(); + return type; } if (islvalue(type)) addop(OP_GETVALUE); @@ -1906,13 +1906,13 @@ getshiftexpr(void) op = 0; switch (gettoken()) { - case T_PLUS: op = OP_PLUS; break; - case T_MINUS: op = OP_NEGATE; break; - case T_NOT: op = OP_NOT; break; - case T_DIV: op = OP_INVERT; break; - case T_BACKSLASH: op = OP_BACKSLASH; break; - case T_TILDE: op = OP_COMP; break; - case T_HASH: op = OP_CONTENT; break; + case T_PLUS: op = OP_PLUS; break; + case T_MINUS: op = OP_NEGATE; break; + case T_NOT: op = OP_NOT; break; + case T_DIV: op = OP_INVERT; break; + case T_BACKSLASH: op = OP_BACKSLASH; break; + case T_TILDE: op = OP_COMP; break; + case T_HASH: op = OP_CONTENT; break; } if (op) { (void) getshiftexpr(); @@ -1922,12 +1922,12 @@ getshiftexpr(void) rescantoken(); type = getreference(); switch (gettoken()) { - case T_POWER: op = OP_POWER; break; - case T_LEFTSHIFT: op = OP_LEFTSHIFT; break; - case T_RIGHTSHIFT: op = OP_RIGHTSHIFT; break; - default: - rescantoken(); - return type; + case T_POWER: op = OP_POWER; break; + case T_LEFTSHIFT: op = OP_LEFTSHIFT; break; + case T_RIGHTSHIFT: op = OP_RIGHTSHIFT; break; + default: + rescantoken(); + return type; } if (islvalue(type)) addop(OP_GETVALUE); @@ -1948,27 +1948,27 @@ getreference(void) int type; switch(gettoken()) { - case T_ANDAND: - scanerror(T_NULL, "Non-variable operand for &"); - case T_AND: - type = getreference(); - addop(OP_PTR); - type = EXPR_RVALUE; - break; - case T_MULT: - (void) getreference(); - addop(OP_DEREF); - type = 0; - break; - case T_POWER: /* '**' or '^' */ - (void) getreference(); - addop(OP_DEREF); - addop(OP_DEREF); - type = 0; - break; - default: - rescantoken(); - type = getincdecexpr(); + case T_ANDAND: + scanerror(T_NULL, "Non-variable operand for &"); + case T_AND: + type = getreference(); + addop(OP_PTR); + type = EXPR_RVALUE; + break; + case T_MULT: + (void) getreference(); + addop(OP_DEREF); + type = 0; + break; + case T_POWER: /* '**' or '^' */ + (void) getreference(); + addop(OP_DEREF); + addop(OP_DEREF); + type = 0; + break; + default: + rescantoken(); + type = getincdecexpr(); } return type; } @@ -1997,15 +1997,15 @@ getincdecexpr(void) for (;;) { tok = gettoken(); switch(tok) { - case T_PLUSPLUS: - addop(OP_PREINC); - continue; - case T_MINUSMINUS: - addop(OP_PREDEC); - continue; - default: - addop(OP_POP); - break; + case T_PLUSPLUS: + addop(OP_PREINC); + continue; + case T_MINUSMINUS: + addop(OP_PREDEC); + continue; + default: + addop(OP_POP); + break; } break; } @@ -2044,120 +2044,120 @@ getterm(void) type = 0; switch (gettoken()) { - case T_NUMBER: - addopone(OP_NUMBER, tokennumber()); - type = (EXPR_RVALUE | EXPR_CONST); - break; + case T_NUMBER: + addopone(OP_NUMBER, tokennumber()); + type = (EXPR_RVALUE | EXPR_CONST); + break; - case T_IMAGINARY: - addopone(OP_IMAGINARY, tokennumber()); - type = (EXPR_RVALUE | EXPR_CONST); - break; + case T_IMAGINARY: + addopone(OP_IMAGINARY, tokennumber()); + type = (EXPR_RVALUE | EXPR_CONST); + break; - case T_OLDVALUE: - addop(OP_OLDVALUE); - type = 0; - break; + case T_OLDVALUE: + addop(OP_OLDVALUE); + type = 0; + break; - case T_STRING: - addopone(OP_STRING, tokenstring()); - type = EXPR_RVALUE; - break; + case T_STRING: + addopone(OP_STRING, tokenstring()); + type = EXPR_RVALUE; + break; - case T_PLUSPLUS: - if (isrvalue(getterm())) - scanerror(T_NULL, "Bad ++ usage"); - writeindexop(); - addop(OP_PREINC); - type = EXPR_ASSIGN; - break; + case T_PLUSPLUS: + if (isrvalue(getterm())) + scanerror(T_NULL, "Bad ++ usage"); + writeindexop(); + addop(OP_PREINC); + type = EXPR_ASSIGN; + break; - case T_MINUSMINUS: - if (isrvalue(getterm())) - scanerror(T_NULL, "Bad -- usage"); - writeindexop(); - addop(OP_PREDEC); - type = EXPR_ASSIGN; - break; + case T_MINUSMINUS: + if (isrvalue(getterm())) + scanerror(T_NULL, "Bad -- usage"); + writeindexop(); + addop(OP_PREDEC); + type = EXPR_ASSIGN; + break; - case T_LEFTPAREN: - oldmode = tokenmode(TM_DEFAULT); - type = getexprlist(); - if (gettoken() != T_RIGHTPAREN) - scanerror(T_SEMICOLON, - "Missing right parenthesis"); - (void) tokenmode(oldmode); - break; + case T_LEFTPAREN: + oldmode = tokenmode(TM_DEFAULT); + type = getexprlist(); + if (gettoken() != T_RIGHTPAREN) + scanerror(T_SEMICOLON, + "Missing right parenthesis"); + (void) tokenmode(oldmode); + break; - case T_MAT: - getonematrix(SYM_UNDEFINED); - type = EXPR_ASSIGN; - break; + case T_MAT: + getonematrix(SYM_UNDEFINED); + type = EXPR_ASSIGN; + break; - case T_OBJ: - getobjdeclaration(SYM_UNDEFINED); - type = EXPR_ASSIGN; - break; + case T_OBJ: + getobjdeclaration(SYM_UNDEFINED); + type = EXPR_ASSIGN; + break; - case T_SYMBOL: - rescantoken(); - type = getidexpr(TRUE, 0); - break; + case T_SYMBOL: + rescantoken(); + type = getidexpr(TRUE, 0); + break; - case T_GLOBAL: - if (gettoken() != T_SYMBOL) { - scanerror(T_NULL, "Global id expected"); - break; - } - rescantoken(); - type = getidexpr(TRUE, T_GLOBAL); + case T_GLOBAL: + if (gettoken() != T_SYMBOL) { + scanerror(T_NULL, "Global id expected"); break; + } + rescantoken(); + type = getidexpr(TRUE, T_GLOBAL); + break; - case T_LOCAL: - if (gettoken() != T_SYMBOL) { - scanerror(T_NULL, "Local id expected"); - break; - } - rescantoken(); - type = getidexpr(TRUE, T_LOCAL); + case T_LOCAL: + if (gettoken() != T_SYMBOL) { + scanerror(T_NULL, "Local id expected"); break; + } + rescantoken(); + type = getidexpr(TRUE, T_LOCAL); + break; - case T_LEFTBRACKET: - scanerror(T_NULL, "Bad index usage"); + case T_LEFTBRACKET: + scanerror(T_NULL, "Bad index usage"); + break; + + case T_PERIOD: + scanerror(T_NULL, "Bad element reference"); + break; + + default: + if (iskeyword(type)) { + scanerror(T_NULL, + "Expression contains reserved keyword"); break; - - case T_PERIOD: - scanerror(T_NULL, "Bad element reference"); - break; - - default: - if (iskeyword(type)) { - scanerror(T_NULL, - "Expression contains reserved keyword"); - break; - } - rescantoken(); - scanerror(T_COMMA, "Missing expression"); + } + rescantoken(); + scanerror(T_COMMA, "Missing expression"); } if (type == 0) { for (;;) { switch (gettoken()) { - case T_LEFTBRACKET: - rescantoken(); - getmatargs(); - type = 0; - break; - case T_PERIOD: - getelement(); - type = 0; - break; - case T_LEFTPAREN: - scanerror(T_NULL, - "Function calls not allowed " - "as expressions"); - default: - rescantoken(); - return type; + case T_LEFTBRACKET: + rescantoken(); + getmatargs(); + type = 0; + break; + case T_PERIOD: + getelement(); + type = 0; + break; + case T_LEFTPAREN: + scanerror(T_NULL, + "Function calls not allowed " + "as expressions"); + default: + rescantoken(); + return type; } } } @@ -2228,6 +2228,45 @@ getidexpr(BOOL okmat, int autodef) } +/* + * getsymvalue - return the VALUE of a symbol + * + * given: + * name symbol name + * v_p pointer to value return + * + * returns: + * symbol type found: + * + * SYM_UNDEFINED no such symbol + * SYM_GLOBAL global symbol found + * + * NOTE: This is a special hack to allow some special code in getfilename() + * to get the value of a symbol. It should NOT be used in the + * general op code generation / calc code parsing case. + */ +static int +getsymvalue(char *name, VALUE *v_p) +{ + GLOBAL *g_ret; /* global return from findglobal() */ + + /* firewall */ + if (name == NULL || v_p == NULL) { + return SYM_UNDEFINED; + } + + /* look for a global */ + g_ret = findglobal(name); + if (g_ret != NULL) { + *v_p = g_ret->g_value; + return SYM_GLOBAL; + } + + /* no such symbol */ + return SYM_UNDEFINED; +} + + /* * Read in a filename for a read or write command. * Both quoted and unquoted filenames are handled here. @@ -2236,30 +2275,78 @@ getidexpr(BOOL okmat, int autodef) * * given: * name filename to read + * namelen length of filename buffer including NUL byte * once non-NULL => set to TRUE of -once read */ static int -getfilename(char *name, BOOL *once) +getfilename(char *name, size_t namelen, BOOL *once) { STRING *s; + char *symstr; /* symbol string */ + VALUE val; /* value of the symbol */ int i; (void) tokenmode(TM_NEWLINES | TM_ALLSYMS); for (i = 2; i > 0; i--) { switch (gettoken()) { - case T_STRING: - s = findstring(tokenstring()); - strcpy(name, s->s_str); - sfree(s); - break; - case T_SYMBOL: - strcpy(name, tokensymbol()); - break; - default: - rescantoken(); - return -1; + case T_STRING: + + /* use the value of the literal string */ + s = findstring(tokenstring()); + strncpy(name, s->s_str, namelen-1); + name[namelen-1] = '\0'; + sfree(s); + break; + + case T_SYMBOL: + + /* get the symbol name */ + symstr = tokensymbol(); + + /* + * special hack - symbols starting with $ are + * treated as a gloabl variable + * instead of a literal string. + */ + if (symstr[0] == '$') { + ++symstr; + if (getsymvalue(symstr, &val)) { + if (val.v_type == V_STR) { + /* use symbol VALUE string */ + symstr = val.v_str->s_str; + if (symstr == NULL) { + math_error("string value pointer is NULL!!"); + /*NOTREACHED*/ + } + } else { + math_error("a filename variable must be a string"); + /*NOTREACHED*/ + } + } else { + math_error("no such global variable"); + /*NOTREACHED*/ + } + } + + /* return symbol name or value of global var string */ + strncpy(name, symstr, namelen-1); + name[namelen-1] = '\0'; + break; + + case T_NEWLINE: + + /* found newline */ + rescantoken(); + return 1; + + default: + + /* found something unexpected */ + rescantoken(); + return -1; } + /* deal with -once */ if (i == 2 && once != NULL) { if ((*once = !strcmp(name, "-once"))) continue; @@ -2280,57 +2367,57 @@ getshowstatement(void) long arg, index; switch (gettoken()) { - case T_SYMBOL: - strncpy(name, tokensymbol(), 4); - name[4] = '\0'; - /* Yuck! */ - arg = stringindex("buil\000" - "real\000" - "func\000" - "objf\000" - "conf\000" - "objt\000" - "file\000" - "size\000" - "erro\000" - "cust\000" - "bloc\000" - "cons\000" - "glob\000" - "stat\000" - "numb\000" - "redc\000" - "stri\000" - "lite\000" - "opco\000", name); - if (arg == 19) { - if (gettoken() != T_SYMBOL) { - rescantoken(); - scanerror(T_SEMICOLON, - "Function name expected"); - return; - } - index = adduserfunc(tokensymbol()); - addopone(OP_SHOW, index + 19); + case T_SYMBOL: + strncpy(name, tokensymbol(), 4); + name[4] = '\0'; + /* Yuck! */ + arg = stringindex("buil\000" + "real\000" + "func\000" + "objf\000" + "conf\000" + "objt\000" + "file\000" + "size\000" + "erro\000" + "cust\000" + "bloc\000" + "cons\000" + "glob\000" + "stat\000" + "numb\000" + "redc\000" + "stri\000" + "lite\000" + "opco\000", name); + if (arg == 19) { + if (gettoken() != T_SYMBOL) { + rescantoken(); + scanerror(T_SEMICOLON, + "Function name expected"); return; } - if (arg > 0) - addopone(OP_SHOW, arg); - else - printf("Unknown SHOW parameter ignored\n"); - return; - default: - printf("SHOW command to be followed by at least "); - printf("four letters of one of:\n"); - printf("\tblocks, builtin, config, constants, "); - printf("custom, errors, files, functions,\n"); - printf("\tglobaltypes, objfunctions, objtypes, " - "opcodes, sizes, "); - printf("realglobals,\n"); - printf("\tstatics, numbers, redcdata, " - "strings, literals\n"); - rescantoken(); + index = adduserfunc(tokensymbol()); + addopone(OP_SHOW, index + 19); return; + } + if (arg > 0) + addopone(OP_SHOW, arg); + else + printf("Unknown SHOW parameter ignored\n"); + return; + default: + printf("SHOW command to be followed by at least "); + printf("four letters of one of:\n"); + printf("\tblocks, builtin, config, constants, "); + printf("custom, errors, files, functions,\n"); + printf("\tglobaltypes, objfunctions, objtypes, " + "opcodes, sizes, "); + printf("realglobals,\n"); + printf("\tstatics, numbers, redcdata, " + "strings, literals\n"); + rescantoken(); + return; } } @@ -2381,18 +2468,18 @@ getmatargs(void) ++dim; (void) getopassignment(); switch (gettoken()) { - case T_RIGHTBRACKET: - addoptwo(OP_INDEXADDR, (long) dim, - (long) FALSE); - return; - case T_COMMA: - break; - default: - rescantoken(); - scanerror(T_NULL, - "Missing right bracket in " - "array reference"); - return; + case T_RIGHTBRACKET: + addoptwo(OP_INDEXADDR, (long) dim, + (long) FALSE); + return; + case T_COMMA: + break; + default: + rescantoken(); + scanerror(T_NULL, + "Missing right bracket in " + "array reference"); + return; } } } @@ -2458,26 +2545,26 @@ static void definesymbol(char *name, int symtype) { switch (symboltype(name)) { - case SYM_STATIC: - if (symtype == SYM_GLOBAL || symtype == SYM_STATIC) - endscope(name, symtype == SYM_GLOBAL); - /*FALLTHRU*/ - case SYM_UNDEFINED: - case SYM_GLOBAL: - if (symtype == SYM_LOCAL) - (void) addlocal(name); - else - (void) addglobal(name, (symtype == SYM_STATIC)); - break; + case SYM_STATIC: + if (symtype == SYM_GLOBAL || symtype == SYM_STATIC) + endscope(name, symtype == SYM_GLOBAL); + /*FALLTHRU*/ + case SYM_UNDEFINED: + case SYM_GLOBAL: + if (symtype == SYM_LOCAL) + (void) addlocal(name); + else + (void) addglobal(name, (symtype == SYM_STATIC)); + break; - case SYM_LOCAL: - if (symtype == SYM_LOCAL) - return; - /*FALLTHRU*/ - case SYM_PARAM: - scanerror(T_COMMA, - "Variable \"%s\" is already defined", name); + case SYM_LOCAL: + if (symtype == SYM_LOCAL) return; + /*FALLTHRU*/ + case SYM_PARAM: + scanerror(T_COMMA, + "Variable \"%s\" is already defined", name); + return; } } @@ -2512,16 +2599,16 @@ usesymbol(char *name, int autodef) return; } switch (symboltype(name)) { - case SYM_LOCAL: - addopone(OP_LOCALADDR, (long) findlocal(name)); - return; - case SYM_PARAM: - addopone(OP_PARAMADDR, (long) findparam(name)); - return; - case SYM_GLOBAL: - case SYM_STATIC: - addopptr(OP_GLOBALADDR, (char *) findglobal(name)); - return; + case SYM_LOCAL: + addopone(OP_LOCALADDR, (long) findlocal(name)); + return; + case SYM_PARAM: + addopone(OP_PARAMADDR, (long) findparam(name)); + return; + case SYM_GLOBAL: + case SYM_STATIC: + addopptr(OP_GLOBALADDR, (char *) findglobal(name)); + return; } /* * The symbol is not yet defined. @@ -2593,18 +2680,18 @@ getcallargs(char *name) if (!strcmp(name, "quomod") && argcount > 2) writeindexop(); switch (gettoken()) { - case T_RIGHTPAREN: - if (op == OP_CALL) - builtincheck(index, argcount); - addopfunction(op, index, argcount); - return; - case T_COMMA: - break; - default: - scanerror(T_SEMICOLON, - "Missing right parenthesis " - "in function call"); - return; + case T_RIGHTPAREN: + if (op == OP_CALL) + builtincheck(index, argcount); + addopfunction(op, index, argcount); + return; + case T_COMMA: + break; + default: + scanerror(T_SEMICOLON, + "Missing right parenthesis " + "in function call"); + return; } } } @@ -2625,15 +2712,15 @@ do_changedir(void) /* determine the new directory */ s = NULL; switch (gettoken()) { - case T_STRING: - s = findstring(tokenstring()); - p = s->s_str; - break; - case T_SYMBOL: - p = tokensymbol(); - break; - default: - p = home; + case T_STRING: + s = findstring(tokenstring()); + p = s->s_str; + break; + case T_SYMBOL: + p = tokensymbol(); + break; + default: + p = home; } if (p == NULL) { diff --git a/comfunc.c b/comfunc.c index 95a866f..fcfb181 100644 --- a/comfunc.c +++ b/comfunc.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.4 $ - * @(#) $Id: comfunc.c,v 29.4 2005/10/18 10:43:49 chongo Exp $ + * @(#) $Revision: 29.6 $ + * @(#) $Id: comfunc.c,v 29.6 2006/05/20 08:43:55 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/RCS/comfunc.c,v $ * * Under source code control: 1990/02/15 01:48:13 @@ -33,6 +33,16 @@ #include "config.h" #include "cmath.h" +/* + * cache the natural logarithm of 10 + */ +static COMPLEX *cln_10 = NULL; +static NUMBER *cln_10_epsilon = NULL; +static NUMBER _q10_ = { { _tenval_, 1, 0 }, { _oneval_, 1, 0 }, 1, NULL }; +static NUMBER _q0_ = { { _zeroval_, 1, 0 }, { _oneval_, 1, 0 }, 1, NULL }; +COMPLEX _cten_ = { &_q10_, &_q0_, 1 }; + + /* * Compute the result of raising a complex number to an integer power. * @@ -69,29 +79,29 @@ c_powi(COMPLEX *c, NUMBER *q) */ if (power <= 4) { switch ((int) (power * sign)) { - case 0: - return clink(&_cone_); - case 1: - return clink(c); - case -1: - return c_inv(c); - case 2: - return c_square(c); - case -2: - tmp = c_square(c); - res = c_inv(tmp); - comfree(tmp); - return res; - case 3: - tmp = c_square(c); - res = c_mul(c, tmp); - comfree(tmp); - return res; - case 4: - tmp = c_square(c); - res = c_square(tmp); - comfree(tmp); - return res; + case 0: + return clink(&_cone_); + case 1: + return clink(c); + case -1: + return c_inv(c); + case 2: + return c_square(c); + case -2: + tmp = c_square(c); + res = c_inv(tmp); + comfree(tmp); + return res; + case 3: + tmp = c_square(c); + res = c_mul(c, tmp); + comfree(tmp); + return res; + case 4: + tmp = c_square(c); + res = c_square(tmp); + comfree(tmp); + return res; } } /* @@ -491,7 +501,7 @@ c_ln(COMPLEX *c, NUMBER *epsilon) NUMBER *a2b2, *tmp1, *tmp2, *epsilon1; if (ciszero(c)) { - math_error("Logarithm of zero"); + math_error("logarithm of zero"); /*NOTREACHED*/ } if (cisone(c)) @@ -519,6 +529,60 @@ c_ln(COMPLEX *c, NUMBER *epsilon) return r; } +/* + * Calculate base 10 logarithm by: + * + * log(c) = ln(c) / ln(10) + */ +COMPLEX * +c_log(COMPLEX *c, NUMBER *epsilon) +{ + int need_new_cln_10 = TRUE; /* FALSE => use cached cln_10 value */ + COMPLEX *ln_c; /* ln(x) */ + COMPLEX *ret; /* base 10 logarithm of x */ + + /* + * compute ln(c) first + */ + ln_c = c_ln(c, epsilon); + /* log(1) == 0 */ + if (ciszero(ln_c)) { + return ln_c; + } + + /* + * save epsilon for ln(10) if needed + */ + if (cln_10_epsilon == NULL) { + /* first time call */ + cln_10_epsilon = qcopy(epsilon); + } else if (qcmp(cln_10_epsilon, epsilon) == FALSE) { + /* replaced cacheed value with epsilon arg */ + qfree(cln_10_epsilon); + cln_10_epsilon = qcopy(epsilon); + } else if (cln_10 != NULL) { + /* the previously computed ln(2) is OK to use */ + need_new_cln_10 = FALSE; + } + + /* + * compute ln(10) if needed + */ + if (need_new_cln_10 == TRUE) { + if (cln_10 != NULL) { + comfree(cln_10); + } + cln_10 = c_ln(&_cten_, cln_10_epsilon); + } + + /* + * return ln(c) / ln(10) + */ + ret = c_div(ln_c, cln_10); + comfree(ln_c); + return ret; +} + /* * Calculate the complex cosine within the specified accuracy. diff --git a/config.c b/config.c index cb4bf2f..4b68de3 100644 --- a/config.c +++ b/config.c @@ -1,7 +1,7 @@ /* * config - configuration routines * - * Copyright (C) 1999-2004 David I. Bell and Landon Curt Noll + * Copyright (C) 1999-2006 David I. Bell and Landon Curt Noll * * Primary author: David I. Bell * @@ -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.15 $ - * @(#) $Id: config.c,v 29.15 2005/12/12 06:45:41 chongo Exp $ + * @(#) $Revision: 29.17 $ + * @(#) $Id: config.c,v 29.17 2006/05/19 15:26:10 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/RCS/config.c,v $ * * Under source code control: 1991/07/20 00:21:56 @@ -722,7 +722,7 @@ setconfig(int type, VALUE *vp) math_error("Cannot duplicate new prompt"); /*NOTREACHED*/ } - strcpy(p, vp->v_str->s_str); + strncpy(p, vp->v_str->s_str, vp->v_str->s_len + 1); free(conf->prompt1); conf->prompt1 = p; break; @@ -737,7 +737,7 @@ setconfig(int type, VALUE *vp) math_error("Cannot duplicate new more prompt"); /*NOTREACHED*/ } - strcpy(p, vp->v_str->s_str); + strncpy(p, vp->v_str->s_str, vp->v_str->s_len + 1); free(conf->prompt2); conf->prompt2 = p; break; diff --git a/custom.c b/custom.c index ea5df9f..ad28821 100644 --- a/custom.c +++ b/custom.c @@ -1,7 +1,7 @@ /* * custom - interface for custom software and hardware interfaces * - * Copyright (C) 1999 Landon Curt Noll + * Copyright (C) 1999-2006 Landon Curt Noll * * Calc is open software; you can redistribute it and/or modify it under * the terms of the version 2.1 of the GNU Lesser General Public License @@ -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: custom.c,v 29.4 2004/02/25 23:54:40 chongo Exp $ + * @(#) $Revision: 29.6 $ + * @(#) $Id: custom.c,v 29.6 2006/05/19 15:26:10 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/RCS/custom.c,v $ * * Under source code control: 1997/03/03 04:53:08 @@ -189,7 +189,7 @@ customhelp(char *name) /* * form the custom help name */ - customname = (char *)malloc(sizeof("custhelp")+strlen(name)+1); + customname = (char *)malloc(sizeof("custhelp")+1+strlen(name)+1); if (customname == NULL) { math_error("bad malloc of customname"); /*NOTREACHED*/ diff --git a/custom/c_argv.c b/custom/c_argv.c index 58a8422..2de8dae 100644 --- a/custom/c_argv.c +++ b/custom/c_argv.c @@ -1,7 +1,7 @@ /* * c_argv - a custom function display info about its args * - * Copyright (C) 1999-2004 Landon Curt Noll + * Copyright (C) 1999-2006 Landon Curt Noll * * Calc is open software; you can redistribute it and/or modify it under * the terms of the version 2.1 of the GNU Lesser General Public License @@ -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_argv.c,v 29.4 2004/02/23 14:04:01 chongo Exp $ + * @(#) $Revision: 29.6 $ + * @(#) $Id: c_argv.c,v 29.6 2006/05/19 15:26:10 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/custom/RCS/c_argv.c,v $ * * Under source code control: 1997/03/09 20:27:37 @@ -152,9 +152,9 @@ c_argv(char UNUSED *name, int count, VALUE **vals) /* getsize error */ printf("\tsize=unknown"); } - printf("\tsizeof=%ld\n", lsizeof(vals[i])); + printf("\tsizeof=%u\n", lsizeof(vals[i])); } else { - printf("\tsize=%ld\tsizeof=%ld\n", + printf("\tsize=%ld\tsizeof=%u\n", elm_count(vals[i]), lsizeof(vals[i])); } } diff --git a/file.c b/file.c index 1152afa..714811c 100644 --- a/file.c +++ b/file.c @@ -1,7 +1,7 @@ /* * file - file I/O routines callable by users * - * Copyright (C) 1999-2004 David I. Bell and Landon Curt Noll + * Copyright (C) 1999-2006 David I. Bell and Landon Curt Noll * * Primary author: David I. Bell * @@ -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.9 $ - * @(#) $Id: file.c,v 29.9 2004/02/23 14:04:01 chongo Exp $ + * @(#) $Revision: 29.14 $ + * @(#) $Id: file.c,v 29.14 2006/05/20 08:43:55 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/RCS/file.c,v $ * * Under source code control: 1991/07/20 00:21:56 @@ -68,11 +68,11 @@ extern FILE *f_open(char *name, char *mode); */ static FILEIO files[MAXFILES] = { {FILEID_STDIN, NULL, (dev_t)0, (ino_t)0, - "(stdin)", TRUE, FALSE, 'r', "r"}, + "(stdin)", TRUE, FALSE, FALSE, FALSE, 'r', "r"}, {FILEID_STDOUT, NULL, (dev_t)0, (ino_t)0, - "(stdout)", FALSE, TRUE, 'w', "w"}, + "(stdout)", FALSE, TRUE, FALSE, FALSE, 'w', "w"}, {FILEID_STDERR, NULL, (dev_t)0, (ino_t)0, - "(stderr)", FALSE, TRUE, 'w', "w"} + "(stderr)", FALSE, TRUE, FALSE, FALSE, 'w', "w"} }; @@ -188,14 +188,141 @@ file_init(void) /* - * Open the specified file name for reading or writing; mode is assumed - * to be one of "r", "w", "a", "r+", "w+", "a+". - * Returns a file id which can be used to do I/O to the file, or else - * FILEID_NONE if the open failed. + * init_fileio - initialize a FILEIO structure + * + * This function initializes a calc FILEIO structure. It will optionally + * malloc the filename string if given an non-NULL associated filename. + * It will canonicalize the file open mode string. + * + * given: + * fiop pointer to FILEIO structure to initialize + * name associated filename (NULL => caller will setup filename) + * mode open mode (one of {r,w,a}{,b}{,+}) + * sbufp pointer to stat of open file + * id calc file ID + * fp open file stream + */ +static void +init_fileio(FILEIO *fiop, char *name, char *mode, + struct stat *sbufp, FILEID id, FILE *fp) +{ + char modestr[sizeof(fiop->mode)]; /* mode [rwa]b?\+? */ + size_t namelen; /* length of name */ + + /* allocate filename if requested */ + if (name != NULL) { + namelen = strlen(name); + fiop->name = (char *)malloc(namelen + 1); + if (fiop->name == NULL) { + math_error("No memory for filename"); + /*NOTREACHED*/ + } + } + + /* initialize FILEIO structure */ + if (name != NULL) { + strncpy(fiop->name, name, namelen+1); + } + fiop->id = id; + fiop->fp = fp; + fiop->dev = sbufp->st_dev; + fiop->inode = sbufp->st_ino; + fiop->reading = FALSE; + fiop->writing = FALSE; + fiop->appending = FALSE; + fiop->binary = FALSE; + fiop->action = 0; + fiop->mode[0] = '\0'; + + /* + * 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. + */ + /* canonicalize read modes */ + if (mode[0] == 'r') { + + /* note read mode */ + strcpy(modestr, "r"); + fiop->reading = TRUE; + + /* note binary mode even though mode is not used / ignored */ + if (strchr(mode, 'b') != NULL) { + strcat(modestr, "b"); + } + + /* note if reading and writing */ + if (strchr(mode, '+') != NULL) { + fiop->writing = TRUE; + strcat(modestr, "+"); + } + + /* canonicalize write modes */ + } else if (mode[0] == 'w') { + + /* note write mode */ + strcpy(modestr, "w"); + fiop->writing = TRUE; + + /* note binary mode even though mode is not used / ignored */ + if (strchr(mode, 'b') != NULL) { + strcat(modestr, "b"); + } + + /* note if reading and writing */ + if (strchr(mode, '+') != NULL) { + fiop->reading = TRUE; + strcat(modestr, "+"); + } + + /* canonicalize append modes */ + } else if (mode[0] == 'a') { + + /* note append mode */ + strcpy(modestr, "a"); + fiop->writing = TRUE; + fiop->appending = TRUE; + + /* note binary mode even though mode is not used / ignored */ + if (strchr(mode, 'b') != NULL) { + strcat(modestr, "b"); + } + + /* note if reading and writing */ + if (strchr(mode, '+') != NULL) { + fiop->reading = TRUE; + strcat(modestr, "+"); + } + + /* canonicalize no I/O modes */ + } else { + modestr[0] = '\0'; + } + modestr[sizeof(modestr)-1] = '\0'; /* firewall */ + + /* record canonical open mode string */ + strncpy(fiop->mode, modestr, sizeof(fiop->mode)); +} + + +/* + * openid - open the specified file name for reading or writing * * given: * name file name - * mode open mode + * mode open mode (one of {r,w,a}{,b}{,+}) + * + * returns: + * >=3 FILEID which can be used to do I/O to the file + * <0 if the open failed + * + * NOTE: This function will not return 0, 1 or 2 since they are + * reserved for stdin, stdout, stderr. In fact, it must not + * return 0, 1, or 2 because it will confuse those who call + * the opensearchfiile() function */ FILEID openid(char *name, char *mode) @@ -206,9 +333,9 @@ openid(char *name, char *mode) struct stat sbuf; /* file status */ int i; + /* find the next open slot in the files array */ if (idnum >= MAXFILES) - return -E_FOPEN3; - + return -E_MANYOPEN; fiop = &files[3]; for (i = 3; i < MAXFILES; fiop++,i++) { if (fiop->name == NULL) @@ -217,8 +344,8 @@ openid(char *name, char *mode) if (i == MAXFILES) math_error("This should not happen in openid()!!!"); + /* open the file */ fp = f_open(name, mode); - if (fp == NULL) { return FILEID_NONE; } @@ -227,50 +354,88 @@ openid(char *name, char *mode) /*NOTREACHED*/ } - fiop->name = (char *)malloc(strlen(name) + 1); - if (fiop->name == NULL) { - math_error("No memory for filename"); - /*NOTREACHED*/ - } + /* get a new FILEID */ id = ++lastid; ioindex[idnum++] = i; - strcpy(fiop->name, name); - fiop->id = id; - fiop->fp = fp; - fiop->dev = sbuf.st_dev; - fiop->inode = sbuf.st_ino; - fiop->reading = TRUE; - fiop->writing = TRUE; - fiop->action = 0; + /* initialize FILEIO structure */ + init_fileio(fiop, name, mode, &sbuf, id, fp); - /* - * 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 { - 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; + /* return calc open file ID */ + return id; +} + + +/* + * openpathid - open the specified abse filename, or relative filename along a search path + * + * given: + * name file name + * mode open mode (one of {r,w,a}{,b}{,+}) + * pathlist list of colon separated paths (or NULL) + * + * returns: + * >=3 FILEID which can be used to do I/O to the file + * <0 if the open failed + * + * NOTE: This function will not return 0, 1 or 2 since they are + * reserved for stdin, stdout, stderr. In fact, it must not + * return 0, 1, or 2 because it will confuse those who call + * the opensearchfiile() function + */ +FILEID +openpathid(char *name, char *mode, char *pathlist) +{ + FILEIO *fiop; /* file structure */ + FILEID id; /* new file id */ + FILE *fp; + struct stat sbuf; /* file status */ + char *openpath; /* malloc copy of path that was opened */ + int i; + + /* find the next open slot in the files array */ + if (idnum >= MAXFILES) + return -E_MANYOPEN; + fiop = &files[3]; + for (i = 3; i < MAXFILES; fiop++,i++) { + if (fiop->name == NULL) + break; } - strcpy(fiop->mode, mode); + if (i == MAXFILES) + math_error("This should not happen in openpathid()!!!"); + + /* open a file - searching along a path */ + openpath = NULL; + fp = f_pathopen(name, mode, pathlist, &openpath); + if (fp == NULL) { + if (openpath != NULL) { + /* should not happen, but just in case */ + free(openpath); + } + return FILEID_NONE; + } + if (fstat(fileno(fp), &sbuf) < 0) { + if (openpath != NULL) { + free(openpath); + } + math_error("bad fstat"); + /*NOTREACHED*/ + } + if (openpath == NULL) { + fclose(fp); + math_error("bad openpath"); + /*NOTREACHED*/ + } + + /* get a new FILEID */ + id = ++lastid; + ioindex[idnum++] = i; + + /* initialize FILEIO structure */ + init_fileio(fiop, NULL, mode, &sbuf, id, fp); + fiop->name = openpath; /* already malloced by f_pathopen */ + + /* return calc open file ID */ return id; } @@ -279,16 +444,20 @@ openid(char *name, char *mode) * reopenid - reopen a FILEID * * given: - * id FILEID to reopen - * mode new mode to open as - * name name of new file + * id FILEID to reopen + * mode new mode to open as + * mode new mode to open as (one of "r", "w", "a", "r+", "w+", "a+") + * name name of new file + * + * returns: + * FILEID which can be used to do I/O to the file + * <0 if the open failed */ FILEID reopenid(FILEID id, char *mode, char *name) { FILEIO *fiop; /* file structure */ FILE *fp; - char *newname; struct stat sbuf; int i; @@ -299,8 +468,8 @@ reopenid(FILEID id, char *mode, char *name) /*NOTREACHED*/ } + /* reopen the file */ fiop = NULL; - for (i = 3; i < idnum; i++) { fiop = &files[ioindex[i]]; if (fiop->id == id) @@ -344,57 +513,23 @@ reopenid(FILEID id, char *mode, char *name) return FILEID_NONE; } } - if (fstat(fileno(fp), &sbuf) < 0) { math_error("bad fstat"); /*NOTREACHED*/ } - if (name) { - newname = (char *)malloc(strlen(name) + 1); - if (newname == NULL) { - math_error("No memory for filename"); - /*NOTREACHED*/ + /* initialize FILEIO structure */ + if (name == NULL) { + if (fiop->name == NULL) { + math_error("old and new reopen filenames are NULL"); } - if (fiop->name) - free(fiop->name); - strcpy(newname, name); - fiop->name = newname; + } else if (fiop->name != NULL) { + free(fiop->name); + fiop->name = NULL; } - fiop->fp = fp; - fiop->dev = sbuf.st_dev; - fiop->inode = sbuf.st_ino; - fiop->reading = TRUE; - fiop->writing = TRUE; - fiop->action = 0; + init_fileio(fiop, name, mode, &sbuf, id, fp); - /* - * 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 { - 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 calc open file ID */ return id; } @@ -810,7 +945,7 @@ idprintf(FILEID id, char *fmt, int count, VALUE **vals) VALUE *vp; char *str; int ch; - long len; + size_t len; int oldmode, newmode; long olddigits, newdigits; long width, precision; @@ -877,36 +1012,36 @@ idprintf(FILEID id, char *fmt, int count, VALUE **vals) newdigits = precision; switch (ch) { - case 's': - printstring = TRUE; - case 'c': - printchar = TRUE; - case 'd': - break; - case 'f': - newmode = MODE_REAL; - break; - case 'e': - newmode = MODE_EXP; - break; - case 'r': - newmode = MODE_FRAC; - break; - case 'o': - newmode = MODE_OCTAL; - break; - case 'x': - newmode = MODE_HEX; - break; - case 'b': - newmode = MODE_BINARY; - break; - case 0: - math_setfp(stdout); - return 0; - default: - math_chr(ch); - continue; + case 's': + printstring = TRUE; + case 'c': + printchar = TRUE; + case 'd': + break; + case 'f': + newmode = MODE_REAL; + break; + case 'e': + newmode = MODE_EXP; + break; + case 'r': + newmode = MODE_FRAC; + break; + case 'o': + newmode = MODE_OCTAL; + break; + case 'x': + newmode = MODE_HEX; + break; + case 'b': + newmode = MODE_BINARY; + break; + case 0: + math_setfp(stdout); + return 0; + default: + math_chr(ch); + continue; } if (--count < 0) { @@ -927,41 +1062,41 @@ idprintf(FILEID id, char *fmt, int count, VALUE **vals) if ((width == 0) || (vp->v_type == V_MAT) || (vp->v_type == V_LIST)) { switch(vp->v_type) { - case V_OCTET: - if (printstring) - math_str((char *)vp->v_octet); - else if (printchar) - math_chr(*vp->v_octet); - else - printvalue(vp, PRINT_NORMAL); - break; - case V_BLOCK: - if (printstring) - math_str((char *) - vp->v_block->data); - else if (printchar) - math_chr(*vp->v_block->data); - else - printvalue(vp, PRINT_NORMAL); - break; - case V_NBLOCK: - if (printstring) { - if (vp->v_nblock->blk->data != - NULL) - math_str((char *) - vp->v_nblock - ->blk->data); - } else if (printchar) { - if (vp->v_nblock->blk->data != - NULL) - math_chr(*vp->v_nblock-> - blk->data); - } else { - printvalue(vp, PRINT_NORMAL); - } - break; - default: + case V_OCTET: + if (printstring) + math_str((char *)vp->v_octet); + else if (printchar) + math_chr(*vp->v_octet); + else printvalue(vp, PRINT_NORMAL); + break; + case V_BLOCK: + if (printstring) + math_str((char *) + vp->v_block->data); + else if (printchar) + math_chr(*vp->v_block->data); + else + printvalue(vp, PRINT_NORMAL); + break; + case V_NBLOCK: + if (printstring) { + if (vp->v_nblock->blk->data != + NULL) + math_str((char *) + vp->v_nblock + ->blk->data); + } else if (printchar) { + if (vp->v_nblock->blk->data != + NULL) + math_chr(*vp->v_nblock-> + blk->data); + } else { + printvalue(vp, PRINT_NORMAL); + } + break; + default: + printvalue(vp, PRINT_NORMAL); } math_setmode(oldmode); @@ -1014,13 +1149,13 @@ idprintf(FILEID id, char *fmt, int count, VALUE **vals) if (strchr(str, '\n')) width = 0; len = strlen(str); - while (!didneg && (width > len)) { + while (!didneg && ((size_t)width > len)) { width--; math_chr(' '); } math_str(str); free(str); - while (didneg && (width > len)) { + while (didneg && ((size_t)width > len)) { width--; math_chr(' '); } @@ -1414,52 +1549,52 @@ fseekid(FILEID id, ZVALUE offset, int whence) /* seek depending on whence */ switch (whence) { - case 0: - /* construct seek position, off = offset */ - if (zisneg(offset)) - return -3; - off = z2filepos(offset); + case 0: + /* construct seek position, off = offset */ + if (zisneg(offset)) + return -3; + off = z2filepos(offset); - /* seek there */ - ret = f_seek_set(fiop->fp, &off); - break; + /* seek there */ + ret = f_seek_set(fiop->fp, &off); + break; - case 1: - /* construct seek position, off = cur+offset */ - f_tell(fiop->fp, &off); - cur = filepos2z(off); - zadd(cur, offset, &tmp); - zfree(cur); - if (zisneg(tmp)) { - zfree(tmp); - return -3; - } - off = z2filepos(tmp); + case 1: + /* construct seek position, off = cur+offset */ + f_tell(fiop->fp, &off); + cur = filepos2z(off); + zadd(cur, offset, &tmp); + zfree(cur); + if (zisneg(tmp)) { zfree(tmp); + return -3; + } + off = z2filepos(tmp); + zfree(tmp); - /* seek there */ - ret = f_seek_set(fiop->fp, &off); - break; + /* seek there */ + ret = f_seek_set(fiop->fp, &off); + break; - case 2: - /* construct seek position, off = len+offset */ - if (get_open_siz(fiop->fp, &cur) < 0) - return -4; - zadd(cur, offset, &tmp); - zfree(cur); - if (zisneg(tmp)) { - zfree(tmp); - return -3; - } - off = z2filepos(tmp); + case 2: + /* construct seek position, off = len+offset */ + if (get_open_siz(fiop->fp, &cur) < 0) + return -4; + zadd(cur, offset, &tmp); + zfree(cur); + if (zisneg(tmp)) { zfree(tmp); + return -3; + } + off = z2filepos(tmp); + zfree(tmp); - /* seek there */ - ret = f_seek_set(fiop->fp, &off); - break; + /* seek there */ + ret = f_seek_set(fiop->fp, &off); + break; - default: - return -5; + default: + return -5; } return ret; } @@ -1828,7 +1963,7 @@ showfiles(void) FILE *fp; struct stat sbuf; ino_t inodes[MAXFILES]; - long sizes[MAXFILES]; + off_t sizes[MAXFILES]; int i, j; for (i = 0; i < idnum; i++) { @@ -1840,7 +1975,7 @@ showfiles(void) sizes[i] = -1; } else { inodes[i] = sbuf.st_ino; - sizes[i] = (long) sbuf.st_size; + sizes[i] = sbuf.st_size; } } for (i = 0; i < idnum; i++) { @@ -2040,7 +2175,7 @@ fscanfile(FILE *fp, char *fmt, int count, VALUE **vals) BOOL skip; /* True if string to be skipped rather than read */ int width; VALUE *var; /* lvalue to be assigned to */ - short subtype; /* for var->v_subtype */ + unsigned short subtype; /* for var->v_subtype */ FILEPOS cur; /* current location */ if (feof(fp)) @@ -2083,75 +2218,75 @@ fscanfile(FILE *fp, char *fmt, int count, VALUE **vals) f = *fmt++; } switch (f) { - case 'c': - if (width == 0) - width = 1; - getscanfield(fp,skip,width,0,NULL,&str); - break; - case 's': - getscanwhite(fp,1,0,6,NULL); - if (feof(fp)) - return assnum; - getscanwhite(fp,skip,width,-6,&str); - break; - case '[': - f = *fmt; - comp = (f == '^'); - if (comp) - f = *++fmt; - scanptr = fmt; - if (f == '\0') - return assnum; - fmt = strchr((f == ']' ? fmt + 1 : fmt), ']'); - if (fmt == NULL) - return assnum; - scannum = fmt - scanptr; - if (comp) - scannum = -scannum; - fmt++; - getscanfield(fp,skip, - width,scannum,scanptr,&str); - break; - case 'f': - case 'e': - case 'r': - case 'i': - getscanwhite(fp,1,0,6, NULL); - if (feof(fp)) - return assnum; - if (skip) { - fskipnum(fp); - continue; - } - assnum++; - var = *vals++; - if (var->v_type != V_ADDR) - math_error("This should not happen!!"); - var = var->v_addr; - subtype = var->v_subtype; - freevalue(var); - count--; - freadsum(fp, var); - var->v_subtype = subtype; - continue; - case 'n': - assnum++; - var = *vals++; - count--; - if (var->v_type != V_ADDR) - math_error("This should not happen!!"); - var = var->v_addr; - subtype = var->v_subtype; - freevalue(var); - var->v_type = V_NUM; - var->v_num = qalloc(); - f_tell(fp, &cur); - var->v_num->num = filepos2z(cur); - var->v_subtype = subtype; - continue; - default: - fprintf(stderr, "Unsupported scan specifier"); + case 'c': + if (width == 0) + width = 1; + getscanfield(fp,skip,width,0,NULL,&str); + break; + case 's': + getscanwhite(fp,1,0,6,NULL); + if (feof(fp)) return assnum; + getscanwhite(fp,skip,width,-6,&str); + break; + case '[': + f = *fmt; + comp = (f == '^'); + if (comp) + f = *++fmt; + scanptr = fmt; + if (f == '\0') + return assnum; + fmt = strchr((f == ']' ? fmt + 1 : fmt), ']'); + if (fmt == NULL) + return assnum; + scannum = fmt - scanptr; + if (comp) + scannum = -scannum; + fmt++; + getscanfield(fp,skip, + width,scannum,scanptr,&str); + break; + case 'f': + case 'e': + case 'r': + case 'i': + getscanwhite(fp,1,0,6, NULL); + if (feof(fp)) + return assnum; + if (skip) { + fskipnum(fp); + continue; + } + assnum++; + var = *vals++; + if (var->v_type != V_ADDR) + math_error("This should not happen!!"); + var = var->v_addr; + subtype = var->v_subtype; + freevalue(var); + count--; + freadsum(fp, var); + var->v_subtype = subtype; + continue; + case 'n': + assnum++; + var = *vals++; + count--; + if (var->v_type != V_ADDR) + math_error("This should not happen!!"); + var = var->v_addr; + subtype = var->v_subtype; + freevalue(var); + var->v_type = V_NUM; + var->v_num = qalloc(); + f_tell(fp, &cur); + var->v_num->num = filepos2z(cur); + var->v_subtype = subtype; + continue; + default: + fprintf(stderr, "Unsupported scan specifier"); + return assnum; } if (!skip) { assnum++; diff --git a/file.h b/file.h index 9613cf2..3f54a5b 100644 --- a/file.h +++ b/file.h @@ -1,7 +1,7 @@ /* * file - file I/O routines callable by users * - * Copyright (C) 1999 David I. Bell and Landon Curt Noll + * Copyright (C) 1999-2006 David I. Bell and Landon Curt Noll * * Primary author: David I. Bell * @@ -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.5 $ - * @(#) $Id: file.h,v 29.5 2001/06/08 21:00:58 chongo Exp $ + * @(#) $Revision: 29.8 $ + * @(#) $Id: file.h,v 29.8 2006/05/19 15:26:10 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/RCS/file.h,v $ * * Under source code control: 1996/05/24 05:55:58 @@ -53,8 +53,10 @@ typedef struct { char *name; /* file name */ BOOL reading; /* TRUE if opened for reading */ BOOL writing; /* TRUE if opened for writing */ + BOOL appending; /* TRUE if also opened for appending */ + BOOL binary; /* TRUE if binary mode - mode ignored/unused */ char action; /* most recent use for 'r', 'w' or 0 */ - char mode[sizeof("rb+")];/* open mode */ + char mode[sizeof("rb+")+1];/* open mode */ } FILEIO; @@ -89,11 +91,12 @@ typedef struct { /* * external functions */ -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); -extern char* findfname(FILEID); +extern DLL FILEIO * findid(FILEID id, int writable); +extern DLL int fgetposid(FILEID id, FILEPOS *ptr); +extern DLL int fsetposid(FILEID id, FILEPOS *ptr); +extern DLL int get_open_siz(FILE *fp, ZVALUE *res); +extern DLL char* findfname(FILEID); +extern DLL FILE *f_pathopen(char *name, char *mode, char *pathlist, char **openpath); #endif /* !__FILE_H__ */ diff --git a/func.c b/func.c index c41a6c6..00a5ac8 100644 --- a/func.c +++ b/func.c @@ -1,7 +1,7 @@ /* * func - built-in functions implemented here * - * Copyright (C) 1999-2004 David I. Bell, Landon Curt Noll and Ernest Bowen + * Copyright (C) 1999-2006 David I. Bell, Landon Curt Noll and Ernest Bowen * * Primary author: David I. Bell * @@ -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.16 $ - * @(#) $Id: func.c,v 29.16 2005/10/18 10:43:49 chongo Exp $ + * @(#) $Revision: 29.25 $ + * @(#) $Id: func.c,v 29.25 2006/05/21 07:28:54 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/RCS/func.c,v $ * * Under source code control: 1990/02/15 01:48:15 @@ -128,8 +128,6 @@ extern int idungetc(FILEID id, int ch); extern LIST* associndices(ASSOC *ap, long index); extern LIST* matindices(MATRIX *mp, long index); -extern int stoponerror; - /* * malloced environment storage @@ -197,25 +195,25 @@ f_eval(VALUE *vp) FUNC *newfunc; VALUE result; char *str; - long num; - int temp; + size_t num; + long temp_stoponerror; /* temp value of stoponerror */ if (vp->v_type != V_STR) return error_value(E_EVAL2); str = vp->v_str->s_str; num = vp->v_str->s_len; switch (openstring(str, num)) { - case -2: - return error_value(E_EVAL3); - case -1: - return error_value(E_EVAL4); + case -2: + return error_value(E_EVAL3); + case -1: + return error_value(E_EVAL4); } oldfunc = curfunc; enterfilescope(); - temp = stoponerror; + temp_stoponerror = stoponerror; stoponerror = -1; if (evaluate(TRUE)) { - stoponerror = temp; + stoponerror = temp_stoponerror; closeinput(); exitfilescope(); freevalue(stack--); @@ -229,7 +227,7 @@ f_eval(VALUE *vp) free(newfunc); return result; } - stoponerror = temp; + stoponerror = temp_stoponerror; closeinput(); exitfilescope(); newfunc = curfunc; @@ -250,7 +248,7 @@ f_prompt(VALUE *vp) VALUE result; char *cp; char *newcp; - unsigned int len; + size_t len; /* initialize VALUE */ result.v_type = V_STR; @@ -275,7 +273,7 @@ f_prompt(VALUE *vp) math_error("Cannot allocate string"); /*NOTREACHED*/ } - strcpy(newcp, cp); + strncpy(newcp, cp, len+1); result.v_str = makestring(newcp); return result; } @@ -331,29 +329,29 @@ f_str(VALUE *vp) result.v_subtype = V_NOSUBTYPE; switch (vp->v_type) { - case V_STR: - result.v_str = stringcopy(vp->v_str); - break; - case V_NULL: - result.v_str = slink(&_nullstring_); - break; - case V_OCTET: - result.v_str = charstring(*vp->v_octet); - break; - case V_NUM: - math_divertio(); - qprintnum(vp->v_num, MODE_DEFAULT); - cp = math_getdivertedio(); - result.v_str = makestring(cp); - break; - case V_COM: - math_divertio(); - comprint(vp->v_com); - cp = math_getdivertedio(); - result.v_str = makestring(cp); - break; - default: - return error_value(E_STR); + case V_STR: + result.v_str = makenewstring(vp->v_str->s_str); + break; + case V_NULL: + result.v_str = slink(&_nullstring_); + break; + case V_OCTET: + result.v_str = charstring(*vp->v_octet); + break; + case V_NUM: + math_divertio(); + qprintnum(vp->v_num, MODE_DEFAULT); + cp = math_getdivertedio(); + result.v_str = makestring(cp); + break; + case V_COM: + math_divertio(); + comprint(vp->v_com); + cp = math_getdivertedio(); + result.v_str = makestring(cp); + break; + default: + return error_value(E_STR); } return result; } @@ -371,23 +369,23 @@ f_name(VALUE *vp) result.v_subtype = V_NOSUBTYPE; switch (vp->v_type) { - case V_NBLOCK: - result.v_type = V_STR; - result.v_str = makenewstring(vp->v_nblock->name); - return result; - case V_FILE: - name = findfname(vp->v_file); - if (name == NULL) { - result.v_type = V_NULL; - return result; - } - math_divertio(); - math_str(name); - cp = math_getdivertedio(); - break; - default: + case V_NBLOCK: + result.v_type = V_STR; + result.v_str = makenewstring(vp->v_nblock->name); + return result; + case V_FILE: + name = findfname(vp->v_file); + if (name == NULL) { result.v_type = V_NULL; return result; + } + math_divertio(); + math_str(name); + cp = math_getdivertedio(); + break; + default: + result.v_type = V_NULL; + return result; } result.v_str = makestring(cp); return result; @@ -2037,6 +2035,51 @@ f_ln(int count, VALUE **vals) } +static VALUE +f_log(int count, VALUE **vals) +{ + VALUE result; + COMPLEX ctmp, *c; + NUMBER *err; + + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; + + err = conf->epsilon; + if (count == 2) { + if (vals[1]->v_type != V_NUM) + return error_value(E_LOG1); + err = vals[1]->v_num; + } + switch (vals[0]->v_type) { + case V_NUM: + if (!qisneg(vals[0]->v_num) && !qiszero(vals[0]->v_num)) { + result.v_num = qlog(vals[0]->v_num, err); + result.v_type = V_NUM; + return result; + } + ctmp.real = vals[0]->v_num; + ctmp.imag = qlink(&_qzero_); + ctmp.links = 1; + c = c_log(&ctmp, err); + break; + case V_COM: + c = c_log(vals[0]->v_com, err); + break; + default: + return error_value(E_LOG2); + } + result.v_type = V_COM; + result.v_com = c; + if (cisreal(c)) { + result.v_num = qlink(c->real); + result.v_type = V_NUM; + comfree(c); + } + return result; +} + + static VALUE f_cos(int count, VALUE **vals) { @@ -4001,8 +4044,8 @@ f_strlen(VALUE *vp) static VALUE f_strcmp(VALUE *v1, VALUE *v2) { - unsigned char *c1, *c2; VALUE result; + FLAG flag; /* initialize VALUE */ result.v_subtype = V_NOSUBTYPE; @@ -4010,17 +4053,10 @@ f_strcmp(VALUE *v1, VALUE *v2) if (v1->v_type != V_STR || v2->v_type != V_STR) return error_value(E_STRCMP); - c1 = (unsigned char *)v1->v_str->s_str; - c2 = (unsigned char *)v2->v_str->s_str; + flag = stringrel(v1->v_str, v2->v_str); result.v_type = V_NUM; - for (; *c1 == *c2; ++c1, ++c2) { - if (*c1 == '\0') { - result.v_num = qlink(&_qzero_); - return result; - } - } - result.v_num = (*c1 > *c2) ? qlink(&_qone_) : qlink(&_qnegone_); + result.v_num = itoq((long) flag); return result; } @@ -4028,8 +4064,8 @@ f_strcmp(VALUE *v1, VALUE *v2) static VALUE f_strncmp(VALUE *v1, VALUE *v2, VALUE *v3) { - unsigned char *c1, *c2; - long i; + long n1, n2, n; + FLAG flag; VALUE result; /* initialize VALUE */ @@ -4039,18 +4075,21 @@ f_strncmp(VALUE *v1, VALUE *v2, VALUE *v3) v3->v_type != V_NUM || qisneg(v3->v_num) || qisfrac(v3->v_num) || zge31b(v3->v_num->num)) return error_value(E_STRNCMP); - i = qtoi(v3->v_num); - for (c1 = (unsigned char *)v1->v_str->s_str, - c2 = (unsigned char *)v2->v_str->s_str; - i > 0 && *c1 == *c2; ++c1, ++c2, --i) { - if (*c1 == '\0') - break; - } + n1 = v1->v_str->s_len; + n2 = v2->v_str->s_len; + n = qtoi(v3->v_num); + if (n < n1) + v1->v_str->s_len = n; + if (n < n2) + v2->v_str->s_len = n; + + flag = stringrel(v1->v_str, v2->v_str); + + v1->v_str->s_len = n1; + v2->v_str->s_len = n2; + result.v_type = V_NUM; - if (i == 0 || *c1 == *c2) - result.v_num = qlink(&_qzero_); - else - result.v_num = (*c1>*c2) ? qlink(&_qone_) : qlink(&_qnegone_); + result.v_num = itoq((long) flag); return result; } @@ -4141,7 +4180,7 @@ static VALUE f_substr(VALUE *v1, VALUE *v2, VALUE *v3) { NUMBER *q1, *q2; - long i1, i2, len; + size_t start, len; char *cp; char *ccp; VALUE result; @@ -4157,33 +4196,32 @@ f_substr(VALUE *v1, VALUE *v2, VALUE *v3) q2 = v3->v_num; if (qisfrac(q1) || qisneg(q1) || qisfrac(q2) || qisneg(q2)) return error_value(E_SUBSTR2); - i1 = qtoi(q1); - i2 = qtoi(q2); - cp = v1->v_str->s_str; - len = (long)strlen(cp); + start = qtoi(q1); + len = qtoi(q2); + if (start > 0) + start--; result.v_type = V_STR; - if (i1 > 0) - i1--; - if (i1 >= len) { /* indexing off of end */ + if (start >= v1->v_str->s_len || len == 0) { result.v_str = slink(&_nullstring_); return result; } - cp += i1; - len -= i1; - if (len > i2) - len = i2; + if (len > v1->v_str->s_len - start) + len = v1->v_str->s_len - start; + cp = v1->v_str->s_str + start; ccp = (char *) malloc(len + 1); if (ccp == NULL) { math_error("No memory for substr"); /*NOTREACHED*/ } - strncpy(ccp, cp, len); - ccp[len] = '\0'; - result.v_str = makestring(ccp); + result.v_str = stralloc(); + result.v_str->s_len = len; + result.v_str->s_str = ccp; + while (len-- > 0) + *ccp++ = *cp++; + *ccp = '\0'; return result; } - static VALUE f_char(VALUE *vp) { @@ -4245,8 +4283,9 @@ f_ord(VALUE *vp) static VALUE f_protect(int count, VALUE **vals) { - int i; - VALUE *v1, *v2; + int i, depth; + VALUE *v1, *v2, *v3; + VALUE result; BOOL have_nblock; @@ -4272,22 +4311,20 @@ f_protect(int count, VALUE **vals) v2 = vals[1]; if (v2->v_type == V_ADDR) v2 = v2->v_addr; - if (v2->v_type != V_NUM || qisfrac(v2->v_num)) + if (v2->v_type != V_NUM||qisfrac(v2->v_num)||zge16b(v2->v_num->num)) return error_value(E_PROTECT2); - if (qisneg(v2->v_num) || zge31b(v2->v_num->num)) - return error_value(E_PROTECT3); i = qtoi(v2->v_num); - if (i > MAXPROTECT) - return error_value(E_PROTECT3); - if (have_nblock) { - v1->v_nblock->subtype |= i; - return result; + depth = 0; + if (count > 2) { + v3 = vals[2]; + if (v3->v_type == V_ADDR) + v3 = v3->v_addr; + if (v3->v_type != V_NUM || qisfrac(v3->v_num) || + qisneg(v3->v_num) || zge31b(v3->v_num->num)) + return error_value(E_PROTECT3); + depth = qtoi(v3->v_num); } - if (i & V_PROTECTALL) { - protectall(v1, i); - return result; - } - v1->v_subtype |= i; + protecttodepth(v1, i, depth); return result; } @@ -4786,10 +4823,9 @@ f_listinsert(int count, VALUE **vals) v1 = *vals++; if ((v1->v_type != V_ADDR) || (v1->v_addr->v_type != V_LIST)) return error_value(E_INSERT1); - if (v1->v_addr->v_subtype & V_NOREALLOC) { - math_error("No-relocate list for insert"); - /*NOTREACHED*/ - } + if (v1->v_addr->v_subtype & V_NOREALLOC) + return error_value(E_LIST1); + v2 = *vals++; if (v2->v_type == V_ADDR) v2 = v2->v_addr; @@ -4820,10 +4856,9 @@ f_listpush(int count, VALUE **vals) v1 = *vals++; if ((v1->v_type != V_ADDR) || (v1->v_addr->v_type != V_LIST)) return error_value(E_PUSH); - if (v1->v_addr->v_subtype & V_NOREALLOC) { - math_error("No-relocate list for push"); - /*NOTREACHED*/ - } + if (v1->v_addr->v_subtype & V_NOREALLOC) + return error_value(E_LIST3); + while (--count > 0) { v2 = *vals++; if (v2->v_type == V_ADDR) @@ -4847,10 +4882,9 @@ f_listappend(int count, VALUE **vals) v1 = *vals++; if ((v1->v_type != V_ADDR) || (v1->v_addr->v_type != V_LIST)) return error_value(E_APPEND); - if (v1->v_addr->v_subtype & V_NOREALLOC) { - math_error("No-relocate list for append"); - /*NOTREACHED*/ - } + if (v1->v_addr->v_subtype & V_NOREALLOC) + return error_value(E_LIST4); + while (--count > 0) { v2 = *vals++; if (v2->v_type == V_ADDR) @@ -4872,10 +4906,9 @@ f_listdelete(VALUE *v1, VALUE *v2) if ((v1->v_type != V_ADDR) || (v1->v_addr->v_type != V_LIST)) return error_value(E_DELETE1); - if (v1->v_addr->v_subtype & V_NOREALLOC) { - math_error("No-relocate list for delete"); - /*NOTREACHED*/ - } + if (v1->v_addr->v_subtype & V_NOREALLOC) + return error_value(E_LIST2); + if (v2->v_type == V_ADDR) v2 = v2->v_addr; if ((v2->v_type != V_NUM) || qisfrac(v2->v_num)) @@ -4890,15 +4923,12 @@ f_listpop(VALUE *vp) { VALUE result; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; - if ((vp->v_type != V_ADDR) || (vp->v_addr->v_type != V_LIST)) return error_value(E_POP); - if (vp->v_addr->v_subtype & V_NOREALLOC) { - math_error("No-relocate list for pop"); - /*NOTREACHED*/ - } + + if (vp->v_addr->v_subtype & V_NOREALLOC) + return error_value(E_LIST5); + removelistfirst(vp->v_addr->v_list, &result); return result; } @@ -4909,15 +4939,12 @@ f_listremove(VALUE *vp) { VALUE result; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; - if ((vp->v_type != V_ADDR) || (vp->v_addr->v_type != V_LIST)) return error_value(E_REMOVE); - if (vp->v_addr->v_subtype & V_NOREALLOC) { - math_error("No-relocate list for remove"); - /*NOTREACHED*/ - } + + if (vp->v_addr->v_subtype & V_NOREALLOC) + return error_value(E_LIST6); + removelistlast(vp->v_addr->v_list, &result); return result; } @@ -4957,23 +4984,16 @@ f_time(void) static VALUE f_ctime(void) { - time_t systime; - char *str; VALUE res; + time_t now; /* the current time */ /* initialize VALUE */ res.v_subtype = V_NOSUBTYPE; - - str = (char *) malloc(26); - if (str == NULL) { - math_error("No memory for ctime()"); - /*NOTREACHED*/ - } - systime = time(NULL); - strcpy(str, ctime(&systime)); - str[24] = '\0'; - res.v_str = makestring(str); res.v_type = V_STR; + + /* get the time */ + now = time(NULL); + res.v_str = makenewstring(ctime(&now)); return res; } @@ -5019,6 +5039,61 @@ f_fopen(VALUE *v1, VALUE *v2) } +static VALUE +f_fpathopen(int count, VALUE **vals) +{ + VALUE result; + FILEID id; + char *mode; + + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; + + /* check for valid strongs */ + if (vals[0]->v_type != V_STR || vals[1]->v_type != V_STR) { + return error_value(E_FPATHOPEN1); + } + if (count == 3 && vals[2]->v_type != V_STR) { + return error_value(E_FPATHOPEN1); + } + + /* check for a valid mode [rwa][b+\0][b+\0] */ + mode = vals[1]->v_str->s_str; + if ((*mode != 'r') && (*mode != 'w') && (*mode != 'a')) + return error_value(E_FPATHOPEN2); + if (mode[1] != '\0') { + if (mode[1] != '+' && mode[1] != 'b') + return error_value(E_FPATHOPEN2); + if (mode[2] != '\0') { + if ((mode[2] != '+' && mode[2] != 'b') || + mode[1] == mode[2]) + return error_value(E_FPATHOPEN2); + if (mode[3] != '\0') + return error_value(E_FPATHOPEN2); + } + } + + /* try to open along a path */ + errno = 0; + if (count == 2) { + id = openpathid(vals[0]->v_str->s_str, + vals[1]->v_str->s_str, + calcpath); + } else { + id = openpathid(vals[0]->v_str->s_str, + vals[1]->v_str->s_str, + vals[2]->v_str->s_str); + } + if (id == FILEID_NONE) + return error_value(errno); + if (id < 0) + return error_value(-id); + result.v_type = V_FILE; + result.v_file = id; + return result; +} + + static VALUE f_freopen(int count, VALUE **vals) { @@ -5138,7 +5213,7 @@ f_errcount(int count, VALUE **vals) static VALUE f_errmax(int count, VALUE **vals) { - int oldmax; + long oldmax; VALUE *vp; VALUE result; @@ -5150,11 +5225,12 @@ f_errmax(int count, VALUE **vals) vp = vals[0]; if (vp->v_type != V_NUM || qisfrac(vp->v_num) || - zge31b(vp->v_num->num)) + zge31b(vp->v_num->num) || zltnegone(vp->v_num->num)) { fprintf(stderr, "Out-of-range arg for errmax ignored\n"); - else - errmax = (int) ztoi(vp->v_num->num); + } else { + errmax = ztoi(vp->v_num->num); + } } result.v_type = V_NUM; @@ -5166,7 +5242,7 @@ f_errmax(int count, VALUE **vals) static VALUE f_stoponerror(int count, VALUE **vals) { - int oldval; + long oldval; VALUE *vp; VALUE result; @@ -5178,11 +5254,12 @@ f_stoponerror(int count, VALUE **vals) vp = vals[0]; if (vp->v_type != V_NUM || qisfrac(vp->v_num) || - zge31b(vp->v_num->num)) + zge31b(vp->v_num->num) || zltnegone(vp->v_num->num)) { fprintf(stderr, "Out-of-range arg for stoponerror ignored\n"); - else - stoponerror = (int) ztoi(vp->v_num->num); + } else { + stoponerror = ztoi(vp->v_num->num); + } } result.v_type = V_NUM; @@ -6196,10 +6273,8 @@ f_reverse(VALUE *val) { VALUE res; - /* initialize VALUE */ - res.v_subtype = V_NOSUBTYPE; - res.v_type = val->v_type; + res.v_subtype = val->v_subtype; switch(val->v_type) { case V_MAT: res.v_mat = matcopy(val->v_mat); @@ -6227,10 +6302,8 @@ f_sort(VALUE *val) { VALUE res; - /* initialize VALUE */ - res.v_subtype = V_NOSUBTYPE; - res.v_type = val->v_type; + res.v_subtype = val->v_subtype; switch (val->v_type) { case V_MAT: res.v_mat = matcopy(val->v_mat); @@ -6413,31 +6486,27 @@ f_modify(VALUE *v1, VALUE *v2) long s; VALUE res; VALUE *vp; + unsigned short subtype; - /* initialize VALUE */ - res.v_subtype = V_NOSUBTYPE; - - if (v1->v_type != V_ADDR) { - math_error("Non-variable first argument for modify"); - /*NOTREACHED*/ - } + if (v1->v_type != V_ADDR) + return error_value(E_MODIFY1); v1 = v1->v_addr; if (v2->v_type == V_ADDR) v2 = v2->v_addr; - if (v2->v_type != V_STR) { - math_error("Non-string second argument for modify"); - /*NOTREACHED*/ - } + if (v2->v_type != V_STR) + return error_value(E_MODIFY2); + if (v1->v_subtype & V_NONEWVALUE) + return error_value(E_MODIFY3); fp = findfunc(adduserfunc(v2->v_str->s_str)); - if (!fp) { - math_error("Undefined function for modify"); - /*NOTREACHED*/ - } + if (!fp) + return error_value(E_MODIFY4); switch (v1->v_type) { case V_LIST: for (ep = v1->v_list->l_first; ep; ep = ep->e_next) { + subtype = ep->e_value.v_subtype; *++stack = ep->e_value; calculate(fp, 1); + stack->v_subtype |= subtype; ep->e_value = *stack--; } break; @@ -6445,16 +6514,29 @@ f_modify(VALUE *v1, VALUE *v2) vp = v1->v_mat->m_table; s = v1->v_mat->m_size; while (s-- > 0) { + subtype = vp->v_subtype; *++stack = *vp; calculate(fp, 1); + stack->v_subtype |= subtype; + *vp++ = *stack--; + } + break; + case V_OBJ: + vp = v1->v_obj->o_table; + s = v1->v_obj->o_actions->oa_count; + while (s-- > 0) { + subtype = vp->v_subtype; + *++stack = *vp; + calculate(fp, 1); + stack->v_subtype |= subtype; *vp++ = *stack--; } break; default: - math_error("Non list or matrix first argument for modify"); - /*NOTREACHED*/ + return error_value(E_MODIFY5); } res.v_type = V_NULL; + res.v_subtype = V_NOSUBTYPE; return res; } @@ -6657,13 +6739,15 @@ f_cmdbuf(void) { VALUE result; char *newcp; + size_t cmdbuf_len; /* length of cmdbuf string */ /* initialize VALUE */ result.v_type = V_STR; result.v_subtype = V_NOSUBTYPE; - newcp = (char *)malloc(strlen(cmdbuf) + 1); - strcpy(newcp, cmdbuf); + cmdbuf_len = strlen(cmdbuf); + newcp = (char *)malloc(cmdbuf_len+1); + strncpy(newcp, cmdbuf, cmdbuf_len+1); result.v_str = makestring(newcp); return result; } @@ -6738,7 +6822,7 @@ f_inputlevel (void) static VALUE -f_calclevel (void) +f_calclevel(void) { VALUE result; @@ -6751,6 +6835,20 @@ f_calclevel (void) } +static VALUE +f_calcpath(void) +{ + VALUE result; + + /* initialize VALUE */ + result.v_type = V_STR; + result.v_subtype = V_NOSUBTYPE; + + result.v_str = makenewstring(calcpath); + return result; +} + + static VALUE f_access(int count, VALUE **vals) { @@ -6758,7 +6856,8 @@ f_access(int count, VALUE **vals) int m; char *s, *fname; VALUE result; - long i; + size_t len; + int i; /* initialize VALUE */ result.v_type = V_NULL; @@ -6779,8 +6878,8 @@ f_access(int count, VALUE **vals) break; case V_STR: s = vals[1]->v_str->s_str; - i = (long)strlen(s); - while (i-- > 0) { + len = (long)strlen(s); + while (len-- > 0) { switch (*s++) { case 'r': m |= 4; break; case 'w': m |= 2; break; @@ -6855,7 +6954,8 @@ f_putenv(int count, VALUE **vals) math_error("Cannot allocate string in putenv"); /*NOTREACHED*/ } - strcpy(putenv_str, vals[0]->v_str->s_str); + strncpy(putenv_str, vals[0]->v_str->s_str, + vals[0]->v_str->s_len + 1); } /* return putenv result */ @@ -6912,7 +7012,7 @@ f_system(VALUE *vp) } #if defined(_WIN32) /* if the execute length is 0 then just return 0 */ - if (strlen(vp->v_str->s_str) == 0) { + if (vp->v_str->s_len == 0) { result.v_num = itoq((long)0); } else { result.v_num = itoq((long)system(vp->v_str->s_str)); @@ -7820,14 +7920,14 @@ f_version(void) * * For nice output, when the description of function (b_desc) * gets too long (extends into col 79) you should chop the - * line and add "\n\t\t ", thats newline, 2 tabs a 4 spaces. + * line and add "\n\t\t\t", that's newline and 3 tabs. * For example the description: * * ... very long description that goes beyond col 79 * * should be written as: * - * "... very long description that\n\t\t goes beyond col 79"}, + * "... very long description that\n\t\t\tgoes beyond col 79"}, * * fields: * b_name name of built-in function @@ -7904,16 +8004,18 @@ static CONST struct builtin builtins[] = { "round value a to b number of binary places"}, {"btrunc", 1, 2, 0, OP_NOP, f_btrunc, 0, "truncate a to b number of binary places"}, - {"calclevel", 0, 0, 0, OP_NOP, 0, f_calclevel, - "current calculation level"}, {"calc_tty", 0, 0, 0, OP_NOP, 0, f_calc_tty, "set tty for interactivity"}, + {"calclevel", 0, 0, 0, OP_NOP, 0, f_calclevel, + "current calculation level"}, + {"calcpath", 0, 0, 0, OP_NOP, 0, f_calcpath, + "current CALCPATH search path value"}, {"catalan", 1, 1, 0, OP_NOP, 0, f_catalan, "catalan number for index a"}, {"ceil", 1, 1, 0, OP_NOP, 0, f_ceil, "smallest integer greater than or equal to number"}, {"cfappr", 1, 3, 0, OP_NOP, f_cfappr, 0, - "approximate a within accuracy b using\n\t\t continued fractions"}, + "approximate a within accuracy b using\n\t\t\tcontinued fractions"}, {"cfsim", 1, 2, 0, OP_NOP, f_cfsim, 0, "simplify number using continued fractions"}, {"char", 1, 1, 0, OP_NOP, 0, f_char, @@ -8009,13 +8111,15 @@ static CONST struct builtin builtins[] = { {"fgets", 1, 1, 0, OP_NOP, 0, f_fgets, "read next line from file, newline is kept"}, {"fgetstr", 1, 1, 0, OP_NOP, 0, f_fgetstr, - "read next null-terminated string from file, null character is kept"}, + "read next null-terminated string from file, null\n\t\t\tcharacter is kept"}, {"files", 0, 1, 0, OP_NOP, 0, f_files, "return opened file or max number of opened files"}, {"floor", 1, 1, 0, OP_NOP, 0, f_floor, "greatest integer less than or equal to number"}, {"fopen", 2, 2, 0, OP_NOP, 0, f_fopen, "open file name a in mode b"}, + {"fpathopen", 2, 3, 0, OP_NOP, 0, f_fpathopen, + "open file name a in mode b, search for a along\n\t\t\tCALCPATH or path c"}, {"fprintf", 2, IN, 0, OP_NOP, 0, f_fprintf, "print formatted output to opened file"}, {"fputc", 2, 2, 0, OP_NOP, 0, f_fputc, @@ -8039,9 +8143,9 @@ static CONST struct builtin builtins[] = { {"freopen", 2, 3, 0, OP_NOP, 0, f_freopen, "reopen a file stream to a named file"}, {"fscan", 2, IN, FA, OP_NOP, 0, f_fscan, - "scan a file for assignments to one or more variables"}, + "scan a file for assignments to one or\n\t\t\tmore variables"}, {"fscanf", 2, IN, FA, OP_NOP, 0, f_fscanf, - "formatted scan of a file for assignment to one or more variables"}, + "formatted scan of a file for assignment to one\n\t\t\tor more variables"}, {"fseek", 2, 3, 0, OP_NOP, 0, f_fseek, "seek to position b (offset from c) in file a"}, {"fsize", 1, 1, 0, OP_NOP, 0, f_fsize, @@ -8059,7 +8163,7 @@ static CONST struct builtin builtins[] = { {"getenv", 1, 1, 0, OP_NOP, 0, f_getenv, "value of environment variable (or NULL)"}, {"hash", 1, IN, 0, OP_NOP, 0, f_hash, - "return non-negative hash value for one or\n\t\t more values"}, + "return non-negative hash value for one or\n\t\t\tmore values"}, {"head", 2, 2, 0, OP_NOP, 0, f_head, "return list of specified number at head of a list"}, {"highbit", 1, 1, 0, OP_HIGHBIT, 0, 0, @@ -8153,7 +8257,7 @@ static CONST struct builtin builtins[] = { {"istype", 2, 2, 0, OP_ISTYPE, 0, 0, "whether the type of a is same as the type of b"}, {"jacobi", 2, 2, 0, OP_NOP, qjacobi, 0, - "-1 => a is not quadratic residue mod b\n\t\t 1 => b is composite, or a is quad residue of b"}, + "-1 => a is not quadratic residue mod b\n\t\t\t1 => b is composite, or a is quad residue of b"}, {"join", 1, IN, 0, OP_NOP, 0, f_join, "join one or more lists into one list"}, {"lcm", 1, IN, 0, OP_NOP, f_lcm, 0, @@ -8168,6 +8272,8 @@ static CONST struct builtin builtins[] = { "create list of specified values"}, {"ln", 1, 2, 0, OP_NOP, 0, f_ln, "natural logarithm of value a within accuracy b"}, + {"log", 1, 2, 0, OP_NOP, 0, f_log, + "base 10 logarithm of value a within accuracy b"}, {"lowbit", 1, 1, 0, OP_LOWBIT, 0, 0, "low bit number in base 2 representation"}, {"ltol", 1, 2, FE, OP_NOP, f_legtoleg, 0, @@ -8227,7 +8333,7 @@ static CONST struct builtin builtins[] = { {"ord", 1, 1, 0, OP_NOP, 0, f_ord, "integer corresponding to character value"}, {"param", 1, 1, 0, OP_ARGVALUE, 0, 0, - "value of parameter n (or parameter count if n\n\t\t is zero)"}, + "value of parameter n (or parameter count if n\n\t\t\tis zero)"}, {"perm", 2, 2, 0, OP_NOP, qperm, 0, "permutation number a!/(a-b)!"}, {"prevcand", 1, 5, 0, OP_NOP, f_prevcand, 0, @@ -8247,14 +8353,14 @@ static CONST struct builtin builtins[] = { {"polar", 2, 3, 0, OP_NOP, 0, f_polar, "complex value of polar coordinate (a * exp(b*1i))"}, {"poly", 1, IN, 0, OP_NOP, 0, f_poly, - "evaluates a polynomial given its coefficients or coefficient-list"}, + "evaluates a polynomial given its coefficients\n\t\t\tor coefficient-list"}, {"pop", 1, 1, FA, OP_NOP, 0, f_listpop, "pop value from front of list"}, {"popcnt", 1, 2, 0, OP_NOP, f_popcnt, 0, "number of bits in a that match b (or 1)"}, {"power", 2, 3, 0, OP_NOP, 0, f_power, "value a raised to the power b within accuracy c"}, - {"protect", 1, 2, FA, OP_NOP, 0, f_protect, + {"protect", 1, 3, FA, OP_NOP, 0, f_protect, "read or set protection level for variable"}, {"ptest", 1, 3, 0, OP_NOP, f_primetest, 0, "probabilistic primality test"}, @@ -8269,7 +8375,7 @@ static CONST struct builtin builtins[] = { {"quo", 2, 3, 0, OP_NOP, 0, f_quo, "integer quotient of a by b, rounding type c"}, {"quomod", 4, 4, 0, OP_QUOMOD, 0, 0, - "set c and d to quotient and remainder of a\n\t\t divided by b"}, + "set c and d to quotient and remainder of a\n\t\t\tdivided by b"}, {"rand", 0, 2, 0, OP_NOP, f_rand, 0, "additive 55 random number [0,2^64), [0,a), or [a,b)"}, {"randbit", 0, 1, 0, OP_NOP, f_randbit, 0, @@ -8305,7 +8411,7 @@ static CONST struct builtin builtins[] = { {"round", 1, 3, 0, OP_NOP, 0, f_round, "round value a to b number of decimal places"}, {"rsearch", 2, 4, 0, OP_NOP, 0, f_rsearch, - "reverse search matrix or list for value b\n\t\t starting at index c"}, + "reverse search matrix or list for value b\n\t\t\tstarting at index c"}, {"runtime", 0, 0, 0, OP_NOP, f_runtime, 0, "user mode cpu time in seconds"}, {"saveval", 1, 1, 0, OP_SAVEVAL, 0, 0, @@ -8313,11 +8419,11 @@ static CONST struct builtin builtins[] = { {"scale", 2, 2, 0, OP_SCALE, 0, 0, "scale value up or down by a power of two"}, {"scan", 1, IN, FA, OP_NOP, 0, f_scan, - "scan standard input for assignment to one or more variables"}, + "scan standard input for assignment to one\n\t\t\tor more variables"}, {"scanf", 2, IN, FA, OP_NOP, 0, f_scanf, - "formatted scan of standard input for assignment to variables"}, + "formatted scan of standard input for assignment\n\t\t\tto variables"}, {"search", 2, 4, 0, OP_NOP, 0, f_search, - "search matrix or list for value b starting\n\t\t at index c"}, + "search matrix or list for value b starting\n\t\t\tat index c"}, {"sec", 1, 2, 0, OP_NOP, 0, f_sec, "sec of a within accuracy b"}, {"sech", 1, 2, 0, OP_NOP, 0, f_sech, @@ -8363,9 +8469,9 @@ static CONST struct builtin builtins[] = { {"strcat", 1,IN, 0, OP_NOP, 0, f_strcat, "concatenate strings together"}, {"strcmp", 2, 2, 0, OP_NOP, 0, f_strcmp, - "compare two null-terminated strings"}, + "compare two strings"}, {"strcpy", 2, 2, 0, OP_NOP, 0, f_strcpy, - "copy null-terminated string to string"}, + "copy string to string"}, {"strerror", 0, 1, 0, OP_NOP, 0, f_strerror, "string describing error type"}, {"strlen", 1, 1, 0, OP_NOP, 0, f_strlen, @@ -8450,10 +8556,11 @@ void showbuiltins(void) { CONST struct builtin *bp; /* current function */ + int i; printf("\nName\tArgs\tDescription\n\n"); - for (bp = builtins; bp->b_name; bp++) { - printf("%-9s ", bp->b_name); + for (bp = builtins, i = 0; bp->b_name; bp++, i++) { + printf("%-14s ", bp->b_name); if (bp->b_maxargs == IN) printf("%d+ ", bp->b_minargs); else if (bp->b_minargs == bp->b_maxargs) @@ -8461,6 +8568,11 @@ showbuiltins(void) else printf("%d-%-4d", bp->b_minargs, bp->b_maxargs); printf("%s\n", bp->b_desc); + if (i == 32) { + i = 0; + if (getchar() == 27) + break; + } } printf("\n"); } @@ -8551,6 +8663,7 @@ builtinfunc(long index, int argcount, VALUE *stck) vpp++; } result.v_type = V_NUM; + result.v_subtype = V_NOSUBTYPE; if (!(bp->b_flags & FE) && (bp->b_minargs != bp->b_maxargs)) { result.v_num = (*bp->b_numfunc)(argcount, numargs); return result; diff --git a/hash.c b/hash.c index b48f119..2869417 100644 --- a/hash.c +++ b/hash.c @@ -1,7 +1,7 @@ /* * hash - one-way hash routines * - * Copyright (C) 1999-2002 Landon Curt Noll + * Copyright (C) 1999-2006 Landon Curt Noll * * Calc is open software; you can redistribute it and/or modify it under * the terms of the version 2.1 of the GNU Lesser General Public License @@ -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: hash.c,v 29.6 2004/02/25 23:55:38 chongo Exp $ + * @(#) $Revision: 29.8 $ + * @(#) $Id: hash.c,v 29.8 2006/05/19 15:26:10 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/RCS/hash.c,v $ * * Under source code control: 1995/11/23 05:13:11 @@ -596,7 +596,7 @@ hash_complex(int type, void *c, HASH *state) HASH * hash_str(int type, char *str, HASH *state) { - USB32 len; /* string length */ + size_t len; /* string length */ /* * initialize if state is NULL diff --git a/help/Makefile b/help/Makefile index dac2eee..d7d1a4a 100644 --- a/help/Makefile +++ b/help/Makefile @@ -18,8 +18,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.25 $ -# @(#) $Id: Makefile,v 29.25 2004/07/28 12:21:05 chongo Exp $ +# @(#) $Revision: 29.28 $ +# @(#) $Id: Makefile,v 29.28 2006/05/07 12:59:51 chongo Exp $ # @(#) $Source: /usr/local/src/cmd/calc/help/RCS/Makefile,v $ # # Under source code control: 1991/07/23 06:47:57 @@ -258,32 +258,41 @@ BLT_HELP_FILES= ${BLT_HELP_FILES_3} ${BLT_HELP_FILES_5} \ # This list is prodiced by the detaillist rule when no WARNINGS are detected. # +# Please use: +# +# make detaillist +# +# to keep this list in nice sorted order and to check that these +# non-special help files are under RCS control. +# DETAIL_HELP= abs access acos acosh acot acoth acsc acsch address agd append \ appr arg argv arrow asec asech asin asinh assign atan atan2 atanh \ avg base base2 bernoulli bit blk blkcpy blkfree blocks bround btrunc \ calc_tty calclevel catalan ceil cfappr cfsim char cmdbuf cmp comb \ conj cos cosh cot coth count cp csc csch ctime delete den dereference \ - det digit digits display dp epsilon errcount errmax errno error euler \ - eval exp fact factor fclose fcnt feof ferror fflush fgetc fgetfield \ - fgetline fgets fgetstr fib files floor fopen forall fprintf fputc \ - fputs fputstr frac free freebernoulli freeeuler freeglobals freeredc \ - freestatics frem freopen fscan fscanf fseek fsize ftell gcd gcdrem \ - gd getenv hash head highbit hmean hnrmod hypot ilog ilog10 ilog2 \ - im indices inputlevel insert int inverse iroot isassoc isatty isblk \ - isconfig isdefined iserror iseven isfile ishash isident isint islist \ - ismat ismult isnull isnum isobj isobjtype isodd isprime isptr isqrt \ - isrand israndom isreal isrel issimple issq isstr istype jacobi join \ - lcm lcmfact lfactor ln lowbit ltol makelist matdim matfill matmax \ - matmin matsum mattrace mattrans max md5 memsize meq min minv mmin \ - mne mod modify name near newerror nextcand nextprime norm null \ - num oldvalue ord param perm pfact pi pix places pmod polar poly \ - pop popcnt power prevcand prevprime printf prompt protect ptest \ - push putenv quo quomod rand randbit random randombit randperm rcin \ - rcmul rcout rcpow rcsq re remove reverse rewind rm root round rsearch \ - runtime saveval scale scan scanf search sec sech seed segment select \ - sgn sha sha1 sin sinh size sizeof sleep sort sqrt srand srandom \ - ssq str strcat strerror strlen strpos strprintf strscan strscanf \ - substr sum swap system tail tan tanh test time trunc version xor + det digit digits display dp epsilon errcount errmax errno error \ + euler eval exp fact factor fclose fcnt feof ferror fflush fgetc \ + fgetfield fgetline fgets fgetstr fib files floor fopen forall \ + fpathopen fprintf fputc fputs fputstr frac free freebernoulli \ + freeeuler freeglobals freeredc freestatics frem freopen fscan \ + fscanf fseek fsize ftell gcd gcdrem gd getenv hash head highbit \ + hmean hnrmod hypot ilog ilog10 ilog2 im indices inputlevel insert \ + int inverse iroot isassoc isatty isblk isconfig isdefined iserror \ + iseven isfile ishash isident isint islist ismat ismult isnull isnum \ + isobj isobjtype isodd isprime isptr isqrt isrand israndom isreal \ + isrel issimple issq isstr istype jacobi join lcm lcmfact lfactor \ + ln log lowbit ltol makelist matdim matfill matmax matmin matsum \ + mattrace mattrans max md5 memsize meq min minv mmin mne mod modify \ + name near newerror nextcand nextprime norm null num oldvalue ord \ + param perm pfact pi pix places pmod polar poly pop popcnt power \ + prevcand prevprime printf prompt protect ptest push putenv quo \ + quomod rand randbit random randombit randperm rcin rcmul rcout \ + rcpow rcsq re remove reverse rewind rm root round rsearch runtime \ + saveval scale scan scanf search sec sech seed segment select sgn \ + sha sha1 sin sinh size sizeof sleep sort sqrt srand srandom ssq \ + str strcat strcmp strcpy strerror strlen strncmp strncpy strpos \ + strprintf strscan strscanf substr sum swap system tail tan tanh \ + test time trunc version xor # This list is of files that are clones of DETAIL_HELP files. They are # built from DETAIL_HELP files. diff --git a/help/abs b/help/abs index 5b31678..1914b38 100644 --- a/help/abs +++ b/help/abs @@ -29,10 +29,10 @@ DESCRIPTION the result will be the absolute value correct to n decimal places. EXAMPLE - > print abs(3.4), abs(-3.4) + ; print abs(3.4), abs(-3.4) 3.4 3.4 - > print abs(3+4i, 1e-5), abs(4+5i, 1e-5), abs(4+5i, 1e-10) + ; print abs(3+4i, 1e-5), abs(4+5i, 1e-5), abs(4+5i, 1e-10) 5 6.40312 6.4031242374 LIMITS @@ -60,8 +60,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: abs,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: abs,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/abs,v $ ## ## Under source code control: 1994/03/19 01:40:22 diff --git a/help/access b/help/access index 1e83158..2b99d1d 100644 --- a/help/access +++ b/help/access @@ -23,19 +23,19 @@ EXAMPLE The system error-numbers and messages may differ for different implementations - > !rm -f junk - > access("junk") + ; !rm -f junk + ; access("junk") System error 2 - > strerror(.) + ; strerror(.) "No such file or directory" - > f = fopen("junk", "w") - > access("junk") - > fputs(f, "Alpha") - > fclose(f) - > !chmod u-w junk - > access("junk", "w") + ; f = fopen("junk", "w") + ; access("junk") + ; fputs(f, "Alpha") + ; fclose(f) + ; !chmod u-w junk + ; access("junk", "w") System error 13 - > strerror(.) + ; strerror(.) "Permission denied" LIMITS @@ -64,8 +64,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: access,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: access,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/access,v $ ## ## Under source code control: 1996/04/30 03:36:20 diff --git a/help/acos b/help/acos index 1f7b364..620655a 100644 --- a/help/acos +++ b/help/acos @@ -17,7 +17,7 @@ DESCRIPTION v = acos(x) is the number in [0, pi] for which cos(v) = x. EXAMPLE - > print acos(.5, 1e-5), acos(.5, 1e-10), acos(.5, 1e-15), acos(.5, 1e-20) + ; print acos(.5, 1e-5), acos(.5, 1e-10), acos(.5, 1e-15), acos(.5, 1e-20) 1.0472 1.0471975512 1.047197551196598 1.04719755119659774615 LIMITS @@ -45,8 +45,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: acos,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: acos,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/acos,v $ ## ## Under source code control: 1994/03/19 01:40:23 diff --git a/help/acosh b/help/acosh index 87f2d29..59f4f2a 100644 --- a/help/acosh +++ b/help/acosh @@ -20,7 +20,7 @@ DESCRIPTION acosh(x) = ln(x + sqrt(x^2 - 1)) EXAMPLE - > print acosh(2, 1e-5), acosh(2, 1e-10), acosh(2, 1e-15), acosh(2, 1e-20) + ; print acosh(2, 1e-5), acosh(2, 1e-10), acosh(2, 1e-15), acosh(2, 1e-20) 1.31696 1.3169578969 1.316957896924817 1.31695789692481670862 LIMITS @@ -48,8 +48,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: acosh,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: acosh,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/acosh,v $ ## ## Under source code control: 1994/03/19 01:40:24 diff --git a/help/acot b/help/acot index 8d473fd..cac4683 100644 --- a/help/acot +++ b/help/acot @@ -17,7 +17,7 @@ DESCRIPTION v = acot(x) is the number in (0, pi) for which cot(v) = x. EXAMPLE - > print acot(2, 1e-5), acot(2, 1e-10), acot(2, 1e-15), acot(2, 1e-20) + ; print acot(2, 1e-5), acot(2, 1e-10), acot(2, 1e-15), acot(2, 1e-20) .46365 .463647609 .463647609000806 .46364760900080611621 LIMITS @@ -45,8 +45,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: acot,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: acot,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/acot,v $ ## ## Under source code control: 1995/11/13 03:49:00 diff --git a/help/acoth b/help/acoth index 11fcf02..f8c3085 100644 --- a/help/acoth +++ b/help/acoth @@ -19,7 +19,7 @@ DESCRIPTION acoth(x) = ln((x + 1)/(x - 1))/2 EXAMPLE - > print acoth(2, 1e-5), acoth(2, 1e-10), acoth(2, 1e-15), acoth(2, 1e-20) + ; print acoth(2, 1e-5), acoth(2, 1e-10), acoth(2, 1e-15), acoth(2, 1e-20) .54931 .5493061443 .549306144334055 .5493061443340548457 LIMITS @@ -47,8 +47,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: acoth,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: acoth,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/acoth,v $ ## ## Under source code control: 1995/11/13 03:49:01 diff --git a/help/acsc b/help/acsc index 04544dc..0bc82f8 100644 --- a/help/acsc +++ b/help/acsc @@ -17,7 +17,7 @@ DESCRIPTION v = acsc(x) is the number in [-pi/2, pi/2] for which csc(v) = x. EXAMPLE - > print acsc(2, 1e-5), acsc(2, 1e-10), acsc(2, 1e-15), acsc(2, 1e-20) + ; print acsc(2, 1e-5), acsc(2, 1e-10), acsc(2, 1e-15), acsc(2, 1e-20) .5236 .5235987756 .523598775598299 .52359877559829887308 LIMITS @@ -45,8 +45,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: acsc,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: acsc,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/acsc,v $ ## ## Under source code control: 1995/11/13 03:49:00 diff --git a/help/acsch b/help/acsch index 5ac4e26..4e45af4 100644 --- a/help/acsch +++ b/help/acsch @@ -20,7 +20,7 @@ DESCRIPTION EXAMPLE - > print acsch(2, 1e-5), acsch(2, 1e-10), acsch(2, 1e-15), acsch(2, 1e-20) + ; print acsch(2, 1e-5), acsch(2, 1e-10), acsch(2, 1e-15), acsch(2, 1e-20) .48121 .4812118251 .481211825059603 .4812118250596034475 LIMITS @@ -48,8 +48,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: acsch,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: acsch,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/acsch,v $ ## ## Under source code control: 1995/11/13 03:49:01 diff --git a/help/address b/help/address index bd5df81..6cc3ba2 100644 --- a/help/address +++ b/help/address @@ -134,21 +134,21 @@ DESCRIPTION EXAMPLE Addresses for particular systems may differ from those displayed here. - > mat A[3] - > B = blk() + ; mat A[3] + ; B = blk() - > print &A, &A[0], &A[1] + ; print &A, &A[0], &A[1] v-ptr: 1400470d0 v-ptr: 140044b70 v-ptr: 140044b80 - > print &B, &B[0], &B[1] + ; print &B, &B[0], &B[1] v-ptr: 140047130 o-ptr: 140044d00 o-ptr: 140044d01 - > a = A[0] = 27 - > print &*a, &*A[0]. &27 + ; a = A[0] = 27 + ; print &*a, &*A[0]. &27 n_ptr: 14003a850 n_ptr: 14003a850 n_ptr: 14003a850 - > a = A[0] = "abc" - > print &*a, &*A[0], &"abc" + ; a = A[0] = "abc" + ; print &*a, &*A[0], &"abc" s_ptr: 14004cae0 s_ptr: 14004cae0 s_ptr: 14004cae0 LIMITS @@ -176,8 +176,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.3 $ -## @(#) $Id: address,v 29.3 2002/07/10 11:47:04 chongo Exp $ +## @(#) $Revision: 29.4 $ +## @(#) $Id: address,v 29.4 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/address,v $ ## ## Under source code control: 1997/09/06 20:03:34 diff --git a/help/agd b/help/agd index ab8aa0c..411ff86 100644 --- a/help/agd +++ b/help/agd @@ -35,16 +35,16 @@ DESCRIPTION EXAMPLE - > print agd(1, 1e-5), agd(1, 1e-10), agd(1, 1e-15) + ; print agd(1, 1e-5), agd(1, 1e-10), agd(1, 1e-15) 1.22619 1.2261911709 1.226191170883517 - > print agd(2, 1e-5), agd(2, 1e-10) + ; print agd(2, 1e-5), agd(2, 1e-10) 1.52345-3.14159i 1.5234524436-3.1415926536i - > print agd(5, 1e-5), agd(5, 1e-10), agd(5, 1e-15) + ; print agd(5, 1e-5), agd(5, 1e-10), agd(5, 1e-15) -1.93237 -1.9323667197 -1.932366719745925 - > print agd(1+2i, 1e-5), agd(1+2i, 1e-10) + ; print agd(1+2i, 1e-5), agd(1+2i, 1e-10) .22751+1.42291i .2275106584+1.4229114625i LIMITS @@ -72,8 +72,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.3 $ -## @(#) $Id: agd,v 29.3 2005/10/18 10:48:29 chongo Exp $ +## @(#) $Revision: 29.4 $ +## @(#) $Id: agd,v 29.4 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/agd,v $ ## ## Under source code control: 1997/09/06 20:03:34 diff --git a/help/append b/help/append index 44b9b6d..2305802 100644 --- a/help/append +++ b/help/append @@ -19,9 +19,9 @@ DESCRIPTION append(x, y_0, y_1, ...) is equivalent to insert(x, n, y_0, y_1, ...). EXAMPLE - > x = list(2,3,4) - > append(x, 5, 6) - > print x + ; x = list(2,3,4) + ; append(x, 5, 6) + ; print x list (5 elements, 5 nonzero): [[0]] = 2 @@ -30,8 +30,8 @@ EXAMPLE [[3]] = 5 [[4]] = 6 - > append(x, pop(x), pop(x)) - > print x + ; append(x, pop(x), pop(x)) + ; print x list (5 elements, 5 nonzero): [[0]] = 4 @@ -40,8 +40,8 @@ EXAMPLE [[3]] = 2 [[4]] = 3 - > append(x, (remove(x), 7)) - > print x + ; append(x, (remove(x), 7)) + ; print x list (5 elements, 5 nonzero): [[0]] = 4 @@ -75,8 +75,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: append,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: append,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/append,v $ ## ## Under source code control: 1994/03/19 03:13:17 diff --git a/help/appr b/help/appr index 66b3a6e..9d8acd1 100644 --- a/help/appr +++ b/help/appr @@ -97,47 +97,47 @@ PROPERTIES If y is nonzero, appr(x,y,8)/y = an odd integer n only if x = n * y. EXAMPLES - > print appr(-5.44,0.1,0), appr(5.44,0.1,0), appr(5.7,1,0), appr(-5.7,1,0) + ; print appr(-5.44,0.1,0), appr(5.44,0.1,0), appr(5.7,1,0), appr(-5.7,1,0) -5.5 5.4 5 -6 - > print appr(-5.44,-.1,0), appr(5.44,-.1,0), appr(5.7,-1,0), appr(-5.7,-1,0) + ; print appr(-5.44,-.1,0), appr(5.44,-.1,0), appr(5.7,-1,0), appr(-5.7,-1,0) -5.4 5.5 6 -5 - > print appr(-5.44,0.1,3), appr(5.44,0.1,3), appr(5.7,1,3), appr(-5.7,1,3) + ; print appr(-5.44,0.1,3), appr(5.44,0.1,3), appr(5.7,1,3), appr(-5.7,1,3) -5.5 5.5 6 -6 - > print appr(-5.44,0.1,4), appr(5.44,0.1,4), appr(5.7,1,4), appr(-5.7,1,4) + ; print appr(-5.44,0.1,4), appr(5.44,0.1,4), appr(5.7,1,4), appr(-5.7,1,4) -5.5 5.4 5 -6 - > print appr(-5.44,0.1,6), appr(5.44,0.1,6), appr(5.7,1,6), appr(-5.7,1,6) + ; print appr(-5.44,0.1,6), appr(5.44,0.1,6), appr(5.7,1,6), appr(-5.7,1,6) -5.4 5.4 6 -5 - > print appr(-5.44,-.1,6), appr(5.44,-.1,6), appr(5.7,-1,6), appr(-5.7,-1,6) + ; print appr(-5.44,-.1,6), appr(5.44,-.1,6), appr(5.7,-1,6), appr(-5.7,-1,6) -5.5 5.5 6 -6 - > print appr(-5.44,0.1,9), appr(5.44,0.1,9), appr(5.7,1,9), appr(-5.7,1,9) + ; print appr(-5.44,0.1,9), appr(5.44,0.1,9), appr(5.7,1,9), appr(-5.7,1,9) -5.5 5.5 5 -5 - > print appr(-.44,0.1,11), appr(.44,0.1,11), appr(5.7,1,11), appr(-5.7,1,11) + ; print appr(-.44,0.1,11), appr(.44,0.1,11), appr(5.7,1,11), appr(-5.7,1,11) -.4 .5 5 -6 - > print appr(-.44,-.1,11),appr(.44,-.1,11),appr(5.7,-1,11),appr(-5.7,-1,11) + ; print appr(-.44,-.1,11),appr(.44,-.1,11),appr(5.7,-1,11),appr(-5.7,-1,11) -.5 .4 6 -5 - > print appr(-.44,0.1,12), appr(.44,0.1,12), appr(5.7,1,12), appr(-5.7,1,12) + ; print appr(-.44,0.1,12), appr(.44,0.1,12), appr(5.7,1,12), appr(-5.7,1,12) -.4 .5 5 -6 - > print appr(-.44,-.1,12),appr(.44,-.1,12),appr(5.7,-1,12),appr(-5.7,-1,12) + ; print appr(-.44,-.1,12),appr(.44,-.1,12),appr(5.7,-1,12),appr(-5.7,-1,12) -.5 .4 6 -5 - > print appr(-.44,0.1,15), appr(.44,0.1,15), appr(5.7,1,15), appr(-5.7,1,15) + ; print appr(-.44,0.1,15), appr(.44,0.1,15), appr(5.7,1,15), appr(-5.7,1,15) -.4 .5 5 -6 - > print appr(-.44,-.1,15),appr(.44,-.1,15),appr(5.7,-1,15),appr(-5.7,-1,15) + ; print appr(-.44,-.1,15),appr(.44,-.1,15),appr(5.7,-1,15),appr(-5.7,-1,15) -.4 .5 5 -6 - > x = sqrt(7-3i, 1e-20) - > print appr(x,1e-5,0), appr(x,1e-5,1), appr(x,1e-5,2), appr(x,1e-6,3) + ; x = sqrt(7-3i, 1e-20) + ; print appr(x,1e-5,0), appr(x,1e-5,1), appr(x,1e-5,2), appr(x,1e-6,3) 2.70331-.55488i 2.70332-.55487i 2.70331-.55487i 2.70332-.55488i LIMITS @@ -167,8 +167,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: appr,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: appr,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/appr,v $ ## ## Under source code control: 1994/09/25 17:18:21 diff --git a/help/arg b/help/arg index 14b8e16..6719a57 100644 --- a/help/arg +++ b/help/arg @@ -16,11 +16,11 @@ DESCRIPTION but usually less than 0.5 * abs(eps). EXAMPLE - > print arg(2), arg(2+3i, 1e-5), arg(2+3i, 1e-10), arg(2+3i, 1e-20) + ; print arg(2), arg(2+3i, 1e-5), arg(2+3i, 1e-10), arg(2+3i, 1e-20) 0 .98279 .9827937232 .98279372324732906799 - > pi = pi(1e-10); deg = pi/180; eps = deg/10000 - > print arg(2+3i, eps)/deg, arg(-1 +1i, eps)/deg, arg(-1 - 1i,eps)/deg + ; pi = pi(1e-10); deg = pi/180; eps = deg/10000 + ; print arg(2+3i, eps)/deg, arg(-1 +1i, eps)/deg, arg(-1 - 1i,eps)/deg 56.3099 135 -135 LIMITS @@ -48,8 +48,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: arg,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: arg,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/arg,v $ ## ## Under source code control: 1994/09/25 20:22:31 diff --git a/help/argv b/help/argv index 30dd910..8a54895 100644 --- a/help/argv +++ b/help/argv @@ -38,8 +38,8 @@ DESCRIPTION EXAMPLE $ calc -s a bb ccc - > argc = argv(); - > for (i = 0; i < argc; i++) print "argv[": i : '] = "': argv(i) : '"'; + ; argc = argv(); + ; for (i = 0; i < argc; i++) print "argv[": i : '] = "': argv(i) : '"'; argv[0] = "a" argv[1] = "bb" argv[2] = "ccc" @@ -69,8 +69,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: argv,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: argv,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/argv,v $ ## ## Under source code control: 1999/11/23 19:45:05 diff --git a/help/arrow b/help/arrow index cb798f0..268c8e9 100644 --- a/help/arrow +++ b/help/arrow @@ -23,21 +23,21 @@ DESCRIPTION Spaces or tabs on either side of -> are optional. EXAMPLES - > obj pair {one, two} - > obj pair A, B - > p = &A - > p->one = 1; p->two = 2 - > A + ; obj pair {one, two} + ; obj pair A, B + ; p = &A + ; p->one = 1; p->two = 2 + ; A obj pair {1, 2} - > A->two = &B - > p->two->one = 3; p->two->two = 4 + ; A->two = &B + ; p->two->one = 3; p->two->two = 4 - > *p->ptwo + ; *p->ptwo obj pair {3, 4} - > B = {5,6} - > *p->two + ; B = {5,6} + ; *p->two obj pair {5, 6} @@ -66,8 +66,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.3 $ -## @(#) $Id: arrow,v 29.3 2002/07/10 11:47:04 chongo Exp $ +## @(#) $Revision: 29.4 $ +## @(#) $Id: arrow,v 29.4 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/arrow,v $ ## ## Under source code control: 1997/09/06 20:03:34 diff --git a/help/asec b/help/asec index 4a4d56f..cfd9fcc 100644 --- a/help/asec +++ b/help/asec @@ -17,7 +17,7 @@ DESCRIPTION v = asec(x) is the number in [0, pi] for which sec(v) = x. EXAMPLE - > print asec(2, 1e-5), asec(2, 1e-10), asec(2, 1e-15), asec(2, 1e-20) + ; print asec(2, 1e-5), asec(2, 1e-10), asec(2, 1e-15), asec(2, 1e-20) 1.0472 1.0471975512 1.047197551196598 1.04719755119659774615 LIMITS @@ -45,8 +45,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: asec,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: asec,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/asec,v $ ## ## Under source code control: 1995/11/13 03:49:00 diff --git a/help/asech b/help/asech index 8f09388..6cdcd3d 100644 --- a/help/asech +++ b/help/asech @@ -19,7 +19,7 @@ DESCRIPTION asech(x) = ln((1 + sqrt(1 - x^2))/x) EXAMPLE - > print asech(.5,1e-5), asech(.5,1e-10), asech(.5,1e-15), asech(.5,1e-20) + ; print asech(.5,1e-5), asech(.5,1e-10), asech(.5,1e-15), asech(.5,1e-20) 1.31696 1.3169578969 1.316957896924817 1.31695789692481670862 LIMITS @@ -47,8 +47,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: asech,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: asech,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/asech,v $ ## ## Under source code control: 1995/11/13 03:49:00 diff --git a/help/asin b/help/asin index 98c01c7..c2b8371 100644 --- a/help/asin +++ b/help/asin @@ -17,7 +17,7 @@ DESCRIPTION v = asin(x) is the number in [-pi/2, pi/2] for which sin(v) = x. EXAMPLE - > print asin(.5, 1e-5), asin(.5, 1e-10), asin(.5, 1e-15), asin(.5, 1e-20) + ; print asin(.5, 1e-5), asin(.5, 1e-10), asin(.5, 1e-15), asin(.5, 1e-20) .5236 .5235987756 .523598775598299 .52359877559829887308 LIMITS @@ -45,8 +45,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.3 $ -## @(#) $Id: asin,v 29.3 2002/07/10 11:47:04 chongo Exp $ +## @(#) $Revision: 29.4 $ +## @(#) $Id: asin,v 29.4 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/asin,v $ ## ## Under source code control: 1994/03/19 01:40:24 diff --git a/help/asinh b/help/asinh index fdbfd90..6dffbae 100644 --- a/help/asinh +++ b/help/asinh @@ -19,7 +19,7 @@ DESCRIPTION asinh(x) = ln(x + sqrt(1 + x^2)) EXAMPLE - > print asinh(2, 1e-5), asinh(2, 1e-10), asinh(2, 1e-15), asinh(2, 1e-20) + ; print asinh(2, 1e-5), asinh(2, 1e-10), asinh(2, 1e-15), asinh(2, 1e-20) 1.44363 1.4436354752 1.44363547517881 1.44363547517881034249 LIMITS @@ -47,8 +47,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: asinh,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: asinh,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/asinh,v $ ## ## Under source code control: 1994/03/19 01:40:25 diff --git a/help/assign b/help/assign index 7ef4e65..fddbc15 100644 --- a/help/assign +++ b/help/assign @@ -76,32 +76,32 @@ DESCRIPTION EXAMPLE - > b = 3+1 - > a = b - > print a, b + ; b = 3+1 + ; a = b + ; print a, b 4 4 - > obj point {x,y} - > mat A[3] = {1, list(2,3), obj point = {4,5}} + ; obj point {x,y} + ; mat A[3] = {1, list(2,3), obj point = {4,5}} - > A[1][[0]] = 6; A[2].x = 7 - > print A[1] + ; A[1][[0]] = 6; A[2].x = 7 + ; print A[1] list (2 elements, 2 nonzero): [[0]] = 6 [[1]] = 3 - > print A[2] + ; print A[2] obj point {7, 5} - > A = {A[2], , {9,10}} - > print A[0] + ; A = {A[2], , {9,10}} + ; print A[0] obj point {7, 5} - > print A[2] + ; print A[2] obj point {9, 10} - > A = {, {2}} + ; A = {, {2}} print A[1] list (2 elements, 2 nonzero): @@ -133,8 +133,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: assign,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: assign,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/assign,v $ ## ## Under source code control: 1995/05/11 21:03:23 diff --git a/help/assoc b/help/assoc index 544a1eb..10ff7eb 100644 --- a/help/assoc +++ b/help/assoc @@ -60,12 +60,12 @@ DESCRIPTION and are illegal. EXAMPLE - > A = assoc(); print A + ; A = assoc(); print A assoc (0 elements): - > A["zero"] = 0; A["one"] = 1; A["two"] = 2; A["three"] = 3; - > A["smallest", "prime"] = 2; - > print A + ; A["zero"] = 0; A["one"] = 1; A["two"] = 2; A["three"] = 3; + ; A["smallest", "prime"] = 2; + ; print A assoc (5 elements); ["two"] = 2 ["three"] = 3 @@ -98,8 +98,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.3 $ -## @(#) $Id: assoc,v 29.3 2002/07/10 11:47:04 chongo Exp $ +## @(#) $Revision: 29.4 $ +## @(#) $Id: assoc,v 29.4 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/assoc,v $ ## ## Under source code control: 1994/09/25 20:22:31 diff --git a/help/atan b/help/atan index 0af6242..d9922a3 100644 --- a/help/atan +++ b/help/atan @@ -17,7 +17,7 @@ DESCRIPTION v = atan(x) is the number in (-pi/2, pi/2) for which tan(v) = x. EXAMPLE - > print atan(2, 1e-5), atan(2, 1e-10), atan(2, 1e-15), atan(2, 1e-20) + ; print atan(2, 1e-5), atan(2, 1e-10), atan(2, 1e-15), atan(2, 1e-20) 1.10715 1.1071487178 1.107148717794091 1.10714871779409050302 LIMITS @@ -45,8 +45,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.3 $ -## @(#) $Id: atan,v 29.3 2002/07/10 11:47:04 chongo Exp $ +## @(#) $Revision: 29.4 $ +## @(#) $Id: atan,v 29.4 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/atan,v $ ## ## Under source code control: 1994/03/19 01:40:25 diff --git a/help/atan2 b/help/atan2 index cb72d3b..0bd20a7 100644 --- a/help/atan2 +++ b/help/atan2 @@ -24,7 +24,7 @@ DESCRIPTION returns 0. EXAMPLE - > print atan2(0,0), atan2(1,sqrt(3)), atan2(17,53,1e-100) + ; print atan2(0,0), atan2(1,sqrt(3)), atan2(17,53,1e-100) 0 ~.52359877559829887307 ~.31038740713235146535 LIMITS @@ -52,8 +52,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: atan2,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: atan2,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/atan2,v $ ## ## Under source code control: 1994/03/19 01:40:26 diff --git a/help/atanh b/help/atanh index 4d29324..b51b117 100644 --- a/help/atanh +++ b/help/atanh @@ -19,7 +19,7 @@ DESCRIPTION atanh(x) = ln((1 + x)/(1 - x))/2 EXAMPLE - > print atanh(.5,1e-5), atanh(.5,1e-10), atanh(.5,1e-15), atanh(.5,1e-20) + ; print atanh(.5,1e-5), atanh(.5,1e-10), atanh(.5,1e-15), atanh(.5,1e-20) .54931 .5493061443 .549306144334055 .5493061443340548457 LIMITS @@ -47,8 +47,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: atanh,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: atanh,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/atanh,v $ ## ## Under source code control: 1994/03/19 01:40:27 diff --git a/help/avg b/help/avg index d4606ae..9c13749 100644 --- a/help/avg +++ b/help/avg @@ -27,12 +27,12 @@ DESCRIPTION be averaged. EXAMPLE - > print avg(1,2,3,4,5), avg(list(1,2,3,4,5)), avg(1,2,list(3,4,5)) + ; print avg(1,2,3,4,5), avg(list(1,2,3,4,5)), avg(1,2,list(3,4,5)) 3 3 3 - > mat x[2,2] = {1,2,3,4} - > mat y[2,2] = {1,2,4,8} - > avg(x,y) + ; mat x[2,2] = {1,2,3,4} + ; mat y[2,2] = {1,2,4,8} + ; avg(x,y) mat [2,2] (4 elements, 4 nonzero): [0,0] = 1 @@ -65,8 +65,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: avg,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: avg,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/avg,v $ ## ## Under source code control: 1994/09/25 20:22:31 diff --git a/help/base b/help/base index 2916298..52b8e20 100644 --- a/help/base +++ b/help/base @@ -60,13 +60,13 @@ DESCRIPTION listed in the table above. EXAMPLE - > base() + ; base() 10 - > base(8) + ; base(8) 012 - > print 10 + ; print 10 012 LIMITS @@ -97,8 +97,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.5 $ -## @(#) $Id: base,v 29.5 2002/12/29 09:17:54 chongo Exp $ +## @(#) $Revision: 29.6 $ +## @(#) $Id: base,v 29.6 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/base,v $ ## ## Under source code control: 1994/09/30 00:09:39 diff --git a/help/base2 b/help/base2 index 98eed74..889fc6b 100644 --- a/help/base2 +++ b/help/base2 @@ -68,16 +68,16 @@ DESCRIPTION listed in the table above. EXAMPLE - > base2() + ; base2() 0 - > base2(8) + ; base2(8) 0 /* 0 */ - > print 10 + ; print 10 10 /* 012 */ - > base2(16), - > 131072 + ; base2(16), + ; 131072 131072 /* 0x20000 */ - > 2345 + ; 2345 2345 /* 0x929 */ LIMITS @@ -109,8 +109,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: 1.3 $ -## @(#) $Id: base2,v 1.3 2002/12/29 09:17:54 chongo Exp $ +## @(#) $Revision: 1.4 $ +## @(#) $Id: base2,v 1.4 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/base2,v $ ## ## Under source code control: 2002/12/29 00:21:07 diff --git a/help/bernoulli b/help/bernoulli index efaf0d3..fee40cb 100644 --- a/help/bernoulli +++ b/help/bernoulli @@ -28,8 +28,8 @@ DESCRIPTION freebernoulli(). EXAMPLE - > config("mode", "frac"),; - > for (n = 0; n <= 6; n++) print bernoulli(n),; print; + ; config("mode", "frac"),; + ; for (n = 0; n <= 6; n++) print bernoulli(n),; print; 1 -1/2 1/6 0 -1/30 0 1/42 LIMITS @@ -57,8 +57,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.5 $ -## @(#) $Id: bernoulli,v 29.5 2002/07/10 11:47:04 chongo Exp $ +## @(#) $Revision: 29.6 $ +## @(#) $Id: bernoulli,v 29.6 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/bernoulli,v $ ## ## Under source code control: 2000/07/13 01:33:00 diff --git a/help/bit b/help/bit index 7d700a0..55aa57c 100644 --- a/help/bit +++ b/help/bit @@ -20,17 +20,17 @@ DESCRIPTION return 1, otherwise return 0. EXAMPLE - > print bit(9,0), bit(9,1), bit(9,2), bit(9,3) + ; print bit(9,0), bit(9,1), bit(9,2), bit(9,3) 1 0 0 1 - > print bit(9,4), bit(0,0), bit(9,-1) + ; print bit(9,4), bit(0,0), bit(9,-1) 0 0 0 - > print bit(1.25, -2), bit(1.25, -1), bit(1.25, 0) + ; print bit(1.25, -2), bit(1.25, -1), bit(1.25, 0) 1 0 1 - > p = pi() - > print bit(p, 1), bit(p, -2), bit(p, -3) + ; p = pi() + ; print bit(p, 1), bit(p, -2), bit(p, -3) 1 0 1 LIMITS @@ -58,8 +58,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: bit,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: bit,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/bit,v $ ## ## Under source code control: 1994/10/21 02:21:30 diff --git a/help/blk b/help/blk index 000f3d0..41a9329 100644 --- a/help/blk +++ b/help/blk @@ -14,7 +14,7 @@ TYPES DESCRIPTION With only integer arguments, blk(len, chunk) attempts to - allocate a block of memory consisting of N octets (unsigned 8-bit + allocate a block of memory consisting of len octets (unsigned 8-bit bytes). Allocation is always done in multiples of chunk octets, so the actual allocation size of len rounded up to the next multiple of chunk. @@ -26,7 +26,7 @@ DESCRIPTION ... , B[len-1], these all initially having zero value. The octets B[i] for i >= len always have zero value. If B[i] with - some i >= len is referenced, len is increased by 1. For example: + some i >= len is referenced, size(B) is increased to i + 1. For example: B[i] = x @@ -56,7 +56,7 @@ DESCRIPTION will append one octet to B and increment size(B). The builtin test(B) returns 1 or 0 according as at least one octet - is zero or all octets are zero. If B1 and B2 are blocks, they are + is nonzero or all octets are zero. If B1 and B2 are blocks, they are considered equal (B1 == B2) if they have the same length and the same data, i.e. B1[i] == B2[i] for 0 <= i < len. Chunksizes and maxsizes are ignored. @@ -107,7 +107,7 @@ DESCRIPTION will give a second variable B referring to the same block as A. Either A[i] = x or B[i] = x may then be used to assign a value - to an octet in the book. Its length or chunksize may be changed by + to an octet in the block. Its length or chunksize may be changed by instructions like: blk(A, len, chunk); @@ -154,55 +154,55 @@ DESCRIPTION EXAMPLE - > B = blk(15,10) + ; B = blk(15,10) - > B[7] = 0xff - > B + ; B[7] = 0xff + ; B chunksize = 10, maxsize = 20, datalen = 15 00000000000000ff00000000000000 - > B[18] = 127 - > B + ; B[18] = 127 + ; B chunksize = 10, maxsize = 20, datalen = 18 00000000000000ff0000000000000000007f - > B[20] = 2 + ; B[20] = 2 Index out of bounds for block - > print size(B), sizeof(B) + ; print size(B), sizeof(B) 18 20 - > B = blk(B, 100, 20) - > B + ; B = blk(B, 100, 20) + ; B chunksize = 20, maxsize = 120, datalen = 100 00000000000000ff0000000000000000007f000000000000000000000000... - > C = blk(B, 10} = {1,2,3} - > C + ; C = blk(B, 10} = {1,2,3} + ; C chunksize = 20, maxsize = 20, datalen = 10 01020300000000ff0000 - > A1 = blk("alpha") - > A1 + ; A1 = blk("alpha") + ; A1 block 0: alpha chunksize = 256, maxsize = 256, datalen = 0 - > A1[7] = 0xff - > A2 = A1 - > A2[17] = 127 - > A1 + ; A1[7] = 0xff + ; A2 = A1 + ; A2[17] = 127 + ; A1 block 0: alpha chunksize = 256, maxsize = 256, datalen = 18 00000000000000ff0000000000000000007f - > A1 = blk(A1, 1000) - > A1 + ; A1 = blk(A1, 1000) + ; A1 block 0: alpha chunksize = 256, maxsize = 1024, datalen = 1000 00000000000000ff0000000000000000007f000000000000000000000000... - > A1 = blk(A1, , 16) - > A1 + ; A1 = blk(A1, , 16) + ; A1 block 0: alpha chunksize = 16, maxsize = 1008, datalen = 1000 00000000000000ff0000000000000000007f000000000000000000000000... @@ -234,8 +234,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.3 $ -## @(#) $Id: blk,v 29.3 2002/07/10 11:47:04 chongo Exp $ +## @(#) $Revision: 29.4 $ +## @(#) $Id: blk,v 29.4 2006/05/07 07:16:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/blk,v $ ## ## Under source code control: 1997/04/05 13:07:13 diff --git a/help/blkcpy b/help/blkcpy index c463b71..3e52014 100644 --- a/help/blkcpy +++ b/help/blkcpy @@ -108,74 +108,74 @@ DESCRIPTION EXAMPLE - > A = blk() = {1,2,3,4} - > B = blk() - > blkcpy(B,A) - > B + ; A = blk() = {1,2,3,4} + ; B = blk() + ; blkcpy(B,A) + ; B chunksize = 256, maxsize = 256, datalen = 4 01020304 > - > blkcpy(B,A) - > B + ; blkcpy(B,A) + ; B chunksize = 256, maxsize = 256, datalen = 8 0102030401020304 - > blkcpy(B, A, 2, 10) - > B + ; blkcpy(B, A, 2, 10) + ; B chunksize = 256, maxsize = 256, datalen = 12 010203040102030400000102 - > blkcpy(B,32767) - > B + ; blkcpy(B,32767) + ; B chunksize = 256, maxsize = 256, datalen = 16 010203040102030400000102ff7f0000 - > mat M[2,2] - > blkcpy(M, A) - > M + ; mat M[2,2] + ; blkcpy(M, A) + ; M mat [2,2] (4 elements, 4 nonzero): [0,0] = 1 [0,1] = 2 [1,0] = 3 [1,1] = 4 - > blkcpy(M, A, 2, 2) - > M + ; blkcpy(M, A, 2, 2) + ; M mat [2,2] (4 elements, 4 nonzero): [0,0] = 1 [0,1] = 2 [1,0] = 1 [1,1] = 2 - > A = blk() = {1,2,3,4} - > B = blk() - > copy(A,B) - > B + ; A = blk() = {1,2,3,4} + ; B = blk() + ; copy(A,B) + ; B chunksize = 256, maxsize = 256, datalen = 4 01020304 - > copy(A,B) - > B + ; copy(A,B) + ; B chunksize = 256, maxsize = 256, datalen = 8 0102030401020304 - > copy(A,B,1,2) - > B + ; copy(A,B,1,2) + ; B chunksize = 256, maxsize = 256, datalen = 10 01020304010203040203 - > mat M[2,2] - > copy(A,M) - > M + ; mat M[2,2] + ; copy(A,M) + ; M mat [2,2] (4 elements, 4 nonzero): [0,0] = 1 [0,1] = 2 [1,0] = 3 [1,1] = 4 - > copy(A,M,2) - > M + ; copy(A,M,2) + ; M mat [2,2] (4 elements, 4 nonzero): [0,0] = 3 [0,1] = 4 [1,0] = 3 [1,1] = 4 - > copy(A,M,0,2,2) - > M + ; copy(A,M,0,2,2) + ; M mat [2,2] (4 elements, 4 nonzero): [0,0] = 3 [0,1] = 4 @@ -207,8 +207,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: blkcpy,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: blkcpy,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/blkcpy,v $ ## ## Under source code control: 1997/04/05 14:08:50 diff --git a/help/blkfree b/help/blkfree index 272b976..182671a 100644 --- a/help/blkfree +++ b/help/blkfree @@ -23,27 +23,27 @@ DESCRIPTION EXAMPLE - > B1 = blk("foo") - > B2 = blk("Second block") + ; B1 = blk("foo") + ; B2 = blk("Second block") show blocks id name ---- ----- 0 foo 1 Second block - > blkfree(B1) - > show blocks + ; blkfree(B1) + ; show blocks id name ---- ----- 1 Second block - > B1 + ; B1 block 0: foo chunksize = 256, maxsize = 0, datalen = 0 NULL - > blk(B1); B[7] = 5 - > B1 + ; blk(B1); B[7] = 5 + ; B1 block 0: foo chunksize = 256, maxsize = 256, datalen = 8 0000000000000005 @@ -73,8 +73,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: blkfree,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: blkfree,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/blkfree,v $ ## ## Under source code control: 1997/04/05 13:07:13 diff --git a/help/blocks b/help/blocks index e2a8097..0d4a5a8 100644 --- a/help/blocks +++ b/help/blocks @@ -20,17 +20,17 @@ DESCRIPTION EXAMPLE - > A = blk("alpha") - > B = blk("beta") = {1,2,3} - > blocks() + ; A = blk("alpha") + ; B = blk("beta") = {1,2,3} + ; blocks() 2 - > blocks(1) + ; blocks(1) block 1: beta chunksize = 256, maxsize = 256, datalen = 3 010203 - > blocks(2) + ; blocks(2) Error 10211 - > strerror() + ; strerror() "Non-allocated index number for blocks" LIMITS @@ -58,8 +58,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.3 $ -## @(#) $Id: blocks,v 29.3 2002/07/10 11:47:04 chongo Exp $ +## @(#) $Revision: 29.4 $ +## @(#) $Id: blocks,v 29.4 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/blocks,v $ ## ## Under source code control: 1997/04/05 13:07:13 diff --git a/help/bround b/help/bround index 588d7fd..9d510c9 100644 --- a/help/bround +++ b/help/bround @@ -66,38 +66,38 @@ DESCRIPTION variables, so their values are not changed by the call. EXAMPLES - > a = 7/32, b = -7/32 + ; a = 7/32, b = -7/32 - > print a, b + ; print a, b .21875 -.21875 - > print round(a,3,0), round(a,3,1), round(a,3,2), print round(a,3,3) + ; print round(a,3,0), round(a,3,1), round(a,3,2), print round(a,3,3) .218, .219, .218, .219 - > print round(b,3,0), round(b,3,1), round(b,3,2), print round(b,3,3) + ; print round(b,3,0), round(b,3,1), round(b,3,2), print round(b,3,3) -.219, -.218, -.218, -.219 - > print round(a,3,16), round(a,3,17), round(a,3,18), print round(a,3,19) + ; print round(a,3,16), round(a,3,17), round(a,3,18), print round(a,3,19) .2188 .2188 .2188 .2188 - > print round(a,4,16), round(a,4,17), round(a,4,18), print round(a,4,19) + ; print round(a,4,16), round(a,4,17), round(a,4,18), print round(a,4,19) .2187 .2188 .2187 .2188 - > print round(a,2,8), round(a,3,8), round(a,4,8), round(a,5,8) + ; print round(a,2,8), round(a,3,8), round(a,4,8), round(a,5,8) .22 .218 .2188 .21875 - > print round(a,2,24), round(a,3,24), round(a,4,24), round(a,5,24) + ; print round(a,2,24), round(a,3,24), round(a,4,24), round(a,5,24) .22 .219 .2188 .21875 - > c = 21875 - > print round(c,-2,0), round(c,-2,1), round(c,-3,0), round(c,-3,16) + ; c = 21875 + ; print round(c,-2,0), round(c,-2,1), round(c,-3,0), round(c,-3,16) 21800 21900 21000 22000 - > print round(c,2,32), round(c,2,33), round(c,2,56), round(c,4,56) + ; print round(c,2,32), round(c,2,33), round(c,2,56), round(c,4,56) 21000 22000 22000 21880 - > A = list(1/8, 2/8, 3/8, 4/8, 5/8, 6/8, 7/8) - > print round(A,2,24) + ; A = list(1/8, 2/8, 3/8, 4/8, 5/8, 6/8, 7/8) + ; print round(A,2,24) list(7 elements, 7 nonzero): [[0]] = .12 @@ -138,8 +138,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: bround,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: bround,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/bround,v $ ## ## Under source code control: 1994/09/30 00:22:35 diff --git a/help/btrunc b/help/btrunc index bec11cd..74584d6 100644 --- a/help/btrunc +++ b/help/btrunc @@ -22,16 +22,16 @@ DESCRIPTION int(x). EXAMPLE - > print btrunc(pi()), btrunc(pi(), 10) + ; print btrunc(pi()), btrunc(pi(), 10) 3 3.140625 - > print btrunc(3.3), btrunc(3.7), btrunc(3.3, 2), btrunc(3.7, 2) + ; print btrunc(3.3), btrunc(3.7), btrunc(3.3, 2), btrunc(3.7, 2) 3 3 3.25 3.5 - > print btrunc(-3.3), btrunc(-3.7), btrunc(-3.3, 2), btrunc(-3.7, 2) + ; print btrunc(-3.3), btrunc(-3.7), btrunc(-3.3, 2), btrunc(-3.7, 2) -3 -3 -3.25 -3.5 - > print btrunc(55.123, -4), btrunc(-55.123, -4) + ; print btrunc(55.123, -4), btrunc(-55.123, -4) 48 -48 LIMITS @@ -59,8 +59,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: btrunc,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: btrunc,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/btrunc,v $ ## ## Under source code control: 1994/09/30 00:44:27 diff --git a/help/calc_tty b/help/calc_tty index 8241c85..6d2e911 100644 --- a/help/calc_tty +++ b/help/calc_tty @@ -18,7 +18,7 @@ DESCRIPTION > !stty echo -cbreak EXAMPLE - > calc_tty(); + ; calc_tty(); LIBRARY none @@ -42,8 +42,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.1 $ -## @(#) $Id: calc_tty,v 29.1 2000/12/14 10:31:45 chongo Exp $ +## @(#) $Revision: 29.2 $ +## @(#) $Id: calc_tty,v 29.2 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/calc_tty,v $ ## ## Under source code control: 2000/12/14 01:33:00 diff --git a/help/catalan b/help/catalan index 8a2220c..e2b8103 100644 --- a/help/catalan +++ b/help/catalan @@ -25,7 +25,7 @@ DESCRIPTION from (x,y) = (0,0) to (x,y) = (n,n) for which always y <= x. EXAMPLE - > print catalan(2), catalan(3), catalan(4), catalan(20) + ; print catalan(2), catalan(3), catalan(4), catalan(20) 2 5 14 6564120420 LIMITS @@ -53,8 +53,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: catalan,v 29.2 2000/12/17 12:27:58 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: catalan,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/catalan,v $ ## ## Under source code control: 2000/12/14 01:33:00 diff --git a/help/ceil b/help/ceil index 84696d8..223071f 100644 --- a/help/ceil +++ b/help/ceil @@ -20,7 +20,7 @@ DESCRIPTION by ceil(t). EXAMPLE - > print ceil(27), ceil(1.23), ceil(-4.56), ceil(7.8 - 9.1i) + ; print ceil(27), ceil(1.23), ceil(-4.56), ceil(7.8 - 9.1i) 27 2 -4 8-9i LIMITS @@ -48,8 +48,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: ceil,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: ceil,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/ceil,v $ ## ## Under source code control: 1994/09/30 01:12:01 diff --git a/help/cfappr b/help/cfappr index 2de33c2..c0d775d 100644 --- a/help/cfappr +++ b/help/cfappr @@ -66,17 +66,17 @@ DESCRIPTION exceeding n is 1/cfappr(1/x, n, 16). EXAMPLE - > c = config("mode", "frac") - > x = 43/30; u = cfappr(x, 10, 0); v = cfappr(x, 10, 1); - > print u, v, x - u, v - x, v - u, cfappr(x, 10, 16) + ; c = config("mode", "frac") + ; x = 43/30; u = cfappr(x, 10, 0); v = cfappr(x, 10, 1); + ; print u, v, x - u, v - x, v - u, cfappr(x, 10, 16) 10/7 13/9 1/210 1/90 1/63 10/7 - > pi = pi(1e-10) - > print cfappr(pi, 100, 16), cfappr(pi, .01, 16), cfappr(pi, 1e-6, 16) + ; pi = pi(1e-10) + ; print cfappr(pi, 100, 16), cfappr(pi, .01, 16), cfappr(pi, 1e-6, 16) 311/99 22/7 355/113 - > x = 17/12; u = cfappr(x,4,0); v = cfappr(x,4,1); - > print u, v, x - u, v - x, cfappr(x,4,16) + ; x = 17/12; u = cfappr(x,4,0); v = cfappr(x,4,1); + ; print u, v, x - u, v - x, cfappr(x,4,16) 4/3 3/2 1/12 1/12 3/2 LIMITS @@ -104,8 +104,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: cfappr,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: cfappr,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/cfappr,v $ ## ## Under source code control: 1994/09/30 01:23:59 diff --git a/help/cfsim b/help/cfsim index a00298c..c5056c4 100644 --- a/help/cfsim +++ b/help/cfsim @@ -95,13 +95,13 @@ DESCRIPTION cfsim(1/x, rnd) = 1/cfsim(x, rnd). EXAMPLE - > c = config("mode", "frac"); + ; c = config("mode", "frac"); - > print cfsim(43/30, 0), cfsim(43/30, 1), cfsim(43/30, 8), cfsim(43/30,16) + ; print cfsim(43/30, 0), cfsim(43/30, 1), cfsim(43/30, 8), cfsim(43/30,16) 10/7 33/23 10/7 33/23 - > x = pi(1e-20); c = config("mode", "frac"); - > while (!isint(x)) {x = cfsim(x,8); if (den(x) < 1e6) print x,:;} + ; x = pi(1e-20); c = config("mode", "frac"); + ; while (!isint(x)) {x = cfsim(x,8); if (den(x) < 1e6) print x,:;} 1146408/364913 312689/99532 104348/33215 355/113 22/7 3 LIMITS @@ -129,8 +129,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: cfsim,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: cfsim,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/cfsim,v $ ## ## Under source code control: 1994/09/30 01:29:45 diff --git a/help/char b/help/char index b9d45b5..9a224f0 100644 --- a/help/char +++ b/help/char @@ -14,7 +14,7 @@ DESCRIPTION the same value as j. For j = 0, returns the null string "". EXAMPLE - > print char(0102), char(0x6f), char(119), char(0145), char(0x6e) + ; print char(0102), char(0x6f), char(119), char(0145), char(0x6e) B o w e n LIMITS @@ -42,8 +42,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: char,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: char,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/char,v $ ## ## Under source code control: 1994/09/30 01:45:45 diff --git a/help/cmp b/help/cmp index fff7e8e..5ed2567 100644 --- a/help/cmp +++ b/help/cmp @@ -92,16 +92,16 @@ DESCRIPTION for example, cmp(2, "2"), returns the null value. EXAMPLE - > print cmp(3,4), cmp(4,3), cmp(4,4), cmp("a","b"), cmp("abcd","abc") + ; print cmp(3,4), cmp(4,3), cmp(4,4), cmp("a","b"), cmp("abcd","abc") -1 1 0 -1 1 - > print cmp(3,4i), cmp(4,4i), cmp(5,4i), cmp(-5,4i), cmp(-4i,5), cmp(-4i,-5) + ; print cmp(3,4i), cmp(4,4i), cmp(5,4i), cmp(-5,4i), cmp(-4i,5), cmp(-4i,-5) 1-1i 1-1i 1-1i -1-1i -1-1i 1-1i - > print cmp(3i,4i), cmp(4i,4i), cmp(5i,4i), cmp(3+4i,5), cmp(3+4i,-5) + ; print cmp(3i,4i), cmp(4i,4i), cmp(5i,4i), cmp(3+4i,5), cmp(3+4i,-5) -1i 0 1i -1+1i 1+1i - > print cmp(3+4i,3+4i), cmp(3+4i,3-4i), cmp(3+4i,2+3i), cmp(3+4i,-4-5i) + ; print cmp(3+4i,3+4i), cmp(3+4i,3-4i), cmp(3+4i,2+3i), cmp(3+4i,-4-5i) 0 1i 1+1i 1+1i LIMITS @@ -130,8 +130,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: cmp,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: cmp,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/cmp,v $ ## ## Under source code control: 1994/10/20 02:52:30 diff --git a/help/comb b/help/comb index 30b624f..ddce752 100644 --- a/help/comb +++ b/help/comb @@ -21,10 +21,10 @@ DESCRIPTION may be chosen from x items ignoring the order in which they are chosen. EXAMPLE - > print comb(7,3), comb(7,4), comb(7,5), comb(3,0), comb(0,0) + ; print comb(7,3), comb(7,4), comb(7,5), comb(3,0), comb(0,0) 35 35 21 1 1 - > print comb(2^31+1,2^31-1) + ; print comb(2^31+1,2^31-1) 2305843010287435776 LIMITS @@ -54,8 +54,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: comb,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: comb,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/comb,v $ ## ## Under source code control: 1994/10/20 04:03:02 diff --git a/help/command b/help/command index 38b6e54..7dcf757 100644 --- a/help/command +++ b/help/command @@ -18,6 +18,7 @@ Command sequence ----------------- define function(params) { body } define function(params) = expression + This first form defines a full function which can consist of declarations followed by many statements which implement the function. @@ -42,16 +43,30 @@ Command sequence read calc commands ------------------ + read $var + read -once $var read filename read -once filename + This reads definitions from the specified calc resource filename. - The name can be quoted if desired. The calculator uses the - CALCPATH environment variable to search through the specified - directories for the filename, similarly to the use of the - PATH environment variable. If CALCPATH is not defined, - then a default path which is usually ":/usr/local/lib/calc" - is used. + In the 1st and 2nd forms, if var is a global variable string + value, then the value of that variable is used as a filename. + + The following is equivalent to read lucas.cal or read "lucas.cal": + + global var = "lucas.cal"; + read $var; + + In the 3rd or 4th forms, the filename argument is treated + as a literal string, not a variable. In these forms, the + name can be quoted if desired. + + The calculator uses the CALCPATH environment variable to + search through the specified directories for the filename, + similarly to the use of the PATH environment variable. + If CALCPATH is not defined, then a default path which is + usually ":/usr/local/lib/calc" is used. The ".cal" extension is defaulted for input files, so that if "filename" is not found, then "filename.cal" is then @@ -76,7 +91,9 @@ Command sequence write calc commands ------------------- + write $var write filename + This writes the values of all global variables to the specified filename, in such a way that the file can be later read in order to recreate the variable values. @@ -85,6 +102,19 @@ Command sequence matrices, lists, and objects are not saved. Function definitions are also not saved. + In the 1st form, if var is a global variable string + value, then the value of that variable is used as a filename. + + The following is equivalent to write dump.out or + write "dump.out": + + global var = "dump.out"; + write $var; + + In the 2nd form, the filename argument is treated as a literal + string, not a variable. In this form, the name can be quoted + if desired. + If the -m mode disallows opening of files for writing, this command will be disabled. @@ -95,6 +125,7 @@ Command sequence quit string exit exit string + The action of these commands depends on where they are used. At the interactive level, they will cause calc it edit. This is the normal way to leave the calculator. In any @@ -131,6 +162,7 @@ Command sequence ----- abort abort string + This command behaves like QUIT except that it will attempt to return to the interactive level if permitted, otherwise calc exit. @@ -143,6 +175,7 @@ Command sequence ------------------------ cd cd dir + Change the current directory to 'dir'. If 'dir' is ommitted, change the current directory to the home directory, if $HOME is set in the environment. @@ -151,6 +184,7 @@ Command sequence show information ---------------- show item + This command displays some information where 'item' is one of the following: @@ -185,11 +219,24 @@ Command sequence calc help --------- - help + help $var help name + This displays a help related to 'name' or general help of none is given. + In the 1st form, if var is a global variable string + value, then the value of that variable is used as a name. + + The following is equivalent to help command or help "command": + + global var = "command"; + help $var; + + In the 2nd form, the filename argument is treated as a literal + string, not a variable. In this form, the name can be quoted + if desired. + =-= @@ -323,8 +370,8 @@ Command sequence ## 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: command,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: command,v 29.3 2006/05/20 10:01:33 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/command,v $ ## ## Under source code control: 1991/07/21 04:37:17 diff --git a/help/conj b/help/conj index 5cd40cc..fc33e1f 100644 --- a/help/conj +++ b/help/conj @@ -28,7 +28,7 @@ DESCRIPTION conjugate of the corresponding component of a. EXAMPLE - > print conj(3), conj(3 + 4i) + ; print conj(3), conj(3 + 4i) 3 3-4i LIMITS @@ -56,8 +56,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: conj,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: conj,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/conj,v $ ## ## Under source code control: 1995/10/03 10:40:01 diff --git a/help/cos b/help/cos index dd5e336..f147df1 100644 --- a/help/cos +++ b/help/cos @@ -15,14 +15,14 @@ DESCRIPTION absolute value than .75 * eps. EXAMPLE - > print cos(1, 1e-5), cos(1, 1e-10), cos(1, 1e-15), cos(1, 1e-20) + ; print cos(1, 1e-5), cos(1, 1e-10), cos(1, 1e-15), cos(1, 1e-20) .5403 .5403023059 .54030230586814 .5403023058681397174 - > print cos(2 + 3i, 1e-5), cos(2 + 3i, 1e-10) + ; print cos(2 + 3i, 1e-5), cos(2 + 3i, 1e-10) -4.18963-9.10923i -4.189625691-9.1092278938i - > pi = pi(1e-20) - > print cos(pi/3, 1e-10), cos(pi/2, 1e-10), cos(pi, 1e-10) + ; pi = pi(1e-20) + ; print cos(pi/3, 1e-10), cos(pi/2, 1e-10), cos(pi, 1e-10) .5 0 -1 LIMITS @@ -51,8 +51,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.3 $ -## @(#) $Id: cos,v 29.3 2005/10/18 10:48:29 chongo Exp $ +## @(#) $Revision: 29.4 $ +## @(#) $Id: cos,v 29.4 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/cos,v $ ## ## Under source code control: 1994/03/19 01:40:27 diff --git a/help/cosh b/help/cosh index 35158ae..9394894 100644 --- a/help/cosh +++ b/help/cosh @@ -17,7 +17,7 @@ DESCRIPTION cosh(x) = (exp(x) + exp(-x))/2 EXAMPLE - > print cosh(1, 1e-5), cosh(1, 1e-10), cosh(1, 1e-15), cosh(1, 1e-20) + ; print cosh(1, 1e-5), cosh(1, 1e-10), cosh(1, 1e-15), cosh(1, 1e-20) 1.54308 1.5430806348 1.543080634815244 1.54308063481524377848 LIMITS @@ -45,8 +45,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: cosh,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: cosh,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/cosh,v $ ## ## Under source code control: 1994/03/19 01:40:28 diff --git a/help/cot b/help/cot index 5c5aad1..8ff6646 100644 --- a/help/cot +++ b/help/cot @@ -15,7 +15,7 @@ DESCRIPTION in absolute value than .75 * eps. EXAMPLE - > print cot(1, 1e-5), cot(1, 1e-10), cot(1, 1e-15), cot(1, 1e-20) + ; print cot(1, 1e-5), cot(1, 1e-10), cot(1, 1e-15), cot(1, 1e-20) .64209 .6420926159 .642092615934331 .64209261593433070301 LIMITS @@ -43,8 +43,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: cot,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: cot,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/cot,v $ ## ## Under source code control: 1995/11/13 03:49:00 diff --git a/help/coth b/help/coth index dc532e0..ea681a0 100644 --- a/help/coth +++ b/help/coth @@ -17,7 +17,7 @@ DESCRIPTION coth(x) = (exp(2*x) + 1)/(exp(2*x) - 1) EXAMPLE - > print coth(1, 1e-5), coth(1, 1e-10), coth(1, 1e-15), coth(1, 1e-20) + ; print coth(1, 1e-5), coth(1, 1e-10), coth(1, 1e-15), coth(1, 1e-20) 1.31304 1.3130352855 1.313035285499331 1.31303528549933130364 LIMITS @@ -45,8 +45,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: coth,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: coth,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/coth,v $ ## ## Under source code control: 1995/11/13 03:49:00 diff --git a/help/count b/help/count index d514299..2224e0c 100644 --- a/help/count +++ b/help/count @@ -16,9 +16,9 @@ DESCRIPTION tests as "true". EXAMPLE - > define f(a) = (a < 5) - > A = list(1,2,7,6,4,8) - > count(A, "f") + ; define f(a) = (a < 5) + ; A = list(1,2,7,6,4,8) + ; count(A, "f") 3 LIMITS @@ -46,8 +46,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: count,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: count,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/count,v $ ## ## Under source code control: 1995/07/10 02:09:31 diff --git a/help/cp b/help/cp index 9f84dc0..ca61e34 100644 --- a/help/cp +++ b/help/cp @@ -17,9 +17,9 @@ DESCRIPTION {x1 * y2 - x2 * y1, x3 * y1 - x1 * y3, x1 * y2 - x2 * y1} EXAMPLE - > mat x[3] = {2,3,4} - > mat y[3] = {3,4,5} - > print cp(x,y) + ; mat x[3] = {2,3,4} + ; mat y[3] = {3,4,5} + ; print cp(x,y) mat [3] (3 elements, 3 nonzero): [0] = -1 @@ -52,8 +52,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: cp,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: cp,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/cp,v $ ## ## Under source code control: 1995/10/05 04:52:26 diff --git a/help/csc b/help/csc index 9b31c89..04764a8 100644 --- a/help/csc +++ b/help/csc @@ -15,7 +15,7 @@ DESCRIPTION in absolute value than .75 * eps. EXAMPLE - > print csc(1, 1e-5), csc(1, 1e-10), csc(1, 1e-15), csc(1, 1e-20) + ; print csc(1, 1e-5), csc(1, 1e-10), csc(1, 1e-15), csc(1, 1e-20) 1.1884 1.1883951058 1.188395105778121 1.18839510577812121626 LIMITS @@ -43,8 +43,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: csc,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: csc,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/csc,v $ ## ## Under source code control: 1995/11/13 03:49:00 diff --git a/help/csch b/help/csch index 6aedb3f..71fb3e1 100644 --- a/help/csch +++ b/help/csch @@ -17,7 +17,7 @@ DESCRIPTION csch(x) = 2/(exp(x) - exp(-x)) EXAMPLE - > print csch(1, 1e-5), csch(1, 1e-10), csch(1, 1e-15), csch(1, 1e-20) + ; print csch(1, 1e-5), csch(1, 1e-10), csch(1, 1e-15), csch(1, 1e-20) .85092 .8509181282 .850918128239322 .85091812823932154513 LIMITS @@ -45,8 +45,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: csch,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: csch,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/csch,v $ ## ## Under source code control: 1995/11/13 03:49:00 diff --git a/help/ctime b/help/ctime index 1858fef..812abeb 100644 --- a/help/ctime +++ b/help/ctime @@ -16,7 +16,7 @@ DESCRIPTION The 25th ctime() character, '\n' is removed. EXAMPLE - > printf("The time is now %s.\n", ctime()) + ; printf("The time is now %s.\n", ctime()) The time is now Mon Apr 15 12:41:44 1996. LIMITS @@ -44,8 +44,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: ctime,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: ctime,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/ctime,v $ ## ## Under source code control: 1996/04/30 03:05:18 diff --git a/help/custom b/help/custom index b07aed0..0e6e885 100644 --- a/help/custom +++ b/help/custom @@ -70,19 +70,19 @@ DESCRIPTION EXAMPLE If calc compiled with ALLOW_CUSTOM= (custom disabled): - > print custom("sysinfo", "baseb") + ; print custom("sysinfo", "baseb") Calc was built with custom functions disabled Error 10195 If calc compiled with ALLOW_CUSTOM= -DCUSTOM and is invoked without -C: - > print custom("sysinfo", "baseb") + ; print custom("sysinfo", "baseb") Calc must be run with a -C argument to use custom function Error 10194 If calc compiled with ALLOW_CUSTOM= -DCUSTOM and is invoked with -C: - > print custom("sysinfo", "baseb") + ; print custom("sysinfo", "baseb") 32 LIMITS @@ -110,8 +110,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: custom,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: custom,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/custom,v $ ## ## Under source code control: 1997/03/09 16:33:22 diff --git a/help/define b/help/define index fcf63ce..3462d70 100644 --- a/help/define +++ b/help/define @@ -166,8 +166,8 @@ DESCRIPTION matrices or objects. EXAMPLE - > define f(a,b) = 2*a + b; - > define g(alpha, beta) + ; define f(a,b) = 2*a + b; + ; define g(alpha, beta) >> { >> local a, pi2; >> @@ -207,8 +207,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.3 $ -## @(#) $Id: define,v 29.3 2000/07/17 15:36:26 chongo Exp $ +## @(#) $Revision: 29.4 $ +## @(#) $Id: define,v 29.4 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/define,v $ ## ## diff --git a/help/delete b/help/delete index 7df8341..fe5ea0f 100644 --- a/help/delete +++ b/help/delete @@ -15,7 +15,7 @@ DESCRIPTION the value of this element. EXAMPLE - > lst = list(2,3,4,5) + ; lst = list(2,3,4,5) list (4 elements, 4 nonzero): [[0]] = 2 @@ -23,9 +23,9 @@ EXAMPLE [[2]] = 4 [[3]] = 5 - > delete(lst, 2) + ; delete(lst, 2) 4 - > print lst + ; print lst list (3 elements, 3 nonzero): [[0]] = 2 @@ -57,8 +57,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: delete,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: delete,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/delete,v $ ## ## Under source code control: 1994/03/19 03:13:18 diff --git a/help/den b/help/den index e280d3c..fbbfc0f 100644 --- a/help/den +++ b/help/den @@ -26,7 +26,7 @@ DESCRIPTION The denominator for this n/d is d. EXAMPLE - > print den(7), den(-1.25), den(121/33) + ; print den(7), den(-1.25), den(121/33) 1 4 3 LIMITS @@ -54,8 +54,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: den,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: den,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/den,v $ ## ## Under source code control: 1995/10/05 04:52:26 diff --git a/help/dereference b/help/dereference index ab2962e..5a57070 100644 --- a/help/dereference +++ b/help/dereference @@ -58,18 +58,18 @@ DESCRIPTION **c returns the lvalue a; ***c returns the value of a. EXAMPLE - > mat A[3] = {1,2,3} - > p = &A[0] - > print *p, *(p + 1), *(p + 2) + ; mat A[3] = {1,2,3} + ; p = &A[0] + ; print *p, *(p + 1), *(p + 2) 1 2 3 - > *(p + 1) = 4 - > print A[1] + ; *(p + 1) = 4 + ; print A[1] 4 - > A[0] = &a - > a = 7 - > print **p + ; A[0] = &a + ; a = 7 + ; print **p 7 LIMITS @@ -97,8 +97,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: dereference,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: dereference,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/dereference,v $ ## ## Under source code control: 1997/09/06 20:03:34 diff --git a/help/det b/help/det index f5226a9..ff73ba6 100644 --- a/help/det +++ b/help/det @@ -37,25 +37,25 @@ DESCRIPTION - (a * h - g * b) * (a * f - d * c))/a. EXAMPLE - > mat A[3,3] = {2, 3, 5, 7, 11, 13, 17, 19, 23} - > c = config("mode", "frac") - > print det(A), det(A^2), det(A^3), det(A^-1) + ; mat A[3,3] = {2, 3, 5, 7, 11, 13, 17, 19, 23} + ; c = config("mode", "frac") + ; print det(A), det(A^2), det(A^3), det(A^-1) -78 6084 -474552 -1/78 - > obj res {r} - > global md - > define res_test(a) = !ismult(a.r, md) - > define res_sub(a,b) {local obj res v = {(a.r - b.r) % md}; return v;} - > define res_mul(a,b) {local obj res v = {(a.r * b.r) % md}; return v;} - > define res_neg(a) {local obj res v = {(-a.r) % md}; return v;} - > define res(x) {local obj res v = {x % md}; return v;} - > md = 0 - > mat A[2,2] = {res(2), res(3), res(5), res(7)} - > md = 5 - > print det(A) + ; obj res {r} + ; global md + ; define res_test(a) = !ismult(a.r, md) + ; define res_sub(a,b) {local obj res v = {(a.r - b.r) % md}; return v;} + ; define res_mul(a,b) {local obj res v = {(a.r * b.r) % md}; return v;} + ; define res_neg(a) {local obj res v = {(-a.r) % md}; return v;} + ; define res(x) {local obj res v = {x % md}; return v;} + ; md = 0 + ; mat A[2,2] = {res(2), res(3), res(5), res(7)} + ; md = 5 + ; print det(A) obj res {4} - > md = 6 - > print det(A) + ; md = 6 + ; print det(A) obj res {5} Note that if A had been a 3 x 3 or larger matrix, res_div(a,b) for @@ -89,8 +89,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: det,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: det,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/det,v $ ## ## Under source code control: 1995/11/28 11:17:47 diff --git a/help/digits b/help/digits index 8350459..ffded3a 100644 --- a/help/digits +++ b/help/digits @@ -29,16 +29,16 @@ DESCRIPTION digits(-0.123) == 1 combination of all of the above EXAMPLE - > print digits(100), digits(23209), digits(2^72) + ; print digits(100), digits(23209), digits(2^72) 3 5 22 - > print digits(0), digits(1), digits(-1) + ; print digits(0), digits(1), digits(-1) 1 1 1 - > print digits(-1234), digits(12.3456), digits(107.207) + ; print digits(-1234), digits(12.3456), digits(107.207) 4 2 3 - > print digits(17^463-1, 17), digits(10000, 100), digits(21701, 2) + ; print digits(17^463-1, 17), digits(10000, 100), digits(21701, 2) 3, 15 14 LIMITS @@ -66,8 +66,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.5 $ -## @(#) $Id: digits,v 29.5 2003/01/26 19:41:35 chongo Exp $ +## @(#) $Revision: 29.6 $ +## @(#) $Id: digits,v 29.6 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/digits,v $ ## ## Under source code control: 1995/10/03 10:40:01 diff --git a/help/display b/help/display index eacd8b0..f70a6fc 100644 --- a/help/display +++ b/help/display @@ -36,13 +36,13 @@ DESCRIPTION the type of rounding to be used is controlled by config("outround"). EXAMPLE - > print display(), 2/3 + ; print display(), 2/3 20 ~0.66666666666666666667 - > print display(40), 2/3 + ; print display(40), 2/3 20 ~0.6666666666666666666666666666666666666667 - > print display(5), 2/3 + ; print display(5), 2/3 40 ~0.66667 LIMITS @@ -70,8 +70,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.1 $ -## @(#) $Id: display,v 29.1 2004/07/26 06:54:41 chongo Exp $ +## @(#) $Revision: 29.2 $ +## @(#) $Id: display,v 29.2 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/display,v $ ## ## Under source code control: 2004/07/25 23:50:40 diff --git a/help/dp b/help/dp index 71c6b0e..1a4194c 100644 --- a/help/dp +++ b/help/dp @@ -22,9 +22,9 @@ DESCRIPTION x0*y0 + x1*y1 + ... + xn*yn EXAMPLE - > mat x[3] = {2,3,4} - > mat y[1:3] = {3,4,5} - > print dp(x,y) + ; mat x[3] = {2,3,4} + ; mat y[1:3] = {3,4,5} + ; print dp(x,y) 38 LIMITS @@ -52,8 +52,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: dp,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: dp,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/dp,v $ ## ## Under source code control: 1995/10/05 04:52:26 diff --git a/help/environment b/help/environment index 8cafbd5..da7abf3 100644 --- a/help/environment +++ b/help/environment @@ -3,8 +3,9 @@ Environment variables CALCPATH A :-separated list of directories used to search for - resource filenames (*.cal files) that do not begin with - /, ./ or ~. + resource filenames (*.cal files) that do not begin with: + + / ./ ../ ~ If this variable does not exist, a compiled value is used. Typically compiled in value is: @@ -104,8 +105,8 @@ Environment variables ## 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: environment,v 29.3 2004/07/26 07:10:43 chongo Exp $ +## @(#) $Revision: 29.4 $ +## @(#) $Id: environment,v 29.4 2006/05/07 07:22:20 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/environment,v $ ## ## Under source code control: 1991/07/23 05:47:25 diff --git a/help/epsilon b/help/epsilon index 2a3c92a..216ba4f 100644 --- a/help/epsilon +++ b/help/epsilon @@ -19,9 +19,9 @@ DESCRIPTION the functions appr(x, eps, rnd), sqrt(x, eps, rnd), etc. EXAMPLE - > oldeps = epsilon(1e-6) - > print epsilon(), sqrt(2), epsilon(1e-4), sqrt(2), epsilon(oldeps) - > .000001 1.414214 .000001 1.4142 .0001 + ; oldeps = epsilon(1e-6) + ; print epsilon(), sqrt(2), epsilon(1e-4), sqrt(2), epsilon(oldeps) + ; .000001 1.414214 .000001 1.4142 .0001 LIMITS none @@ -49,8 +49,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: epsilon,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: epsilon,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/epsilon,v $ ## ## Under source code control: 1995/10/05 04:52:26 diff --git a/help/errcount b/help/errcount index 80dbd5f..883dfab 100644 --- a/help/errcount +++ b/help/errcount @@ -28,12 +28,12 @@ DESCRIPTION errcount. EXAMPLE - > errmax(10) + ; errmax(10) 0 - > errcount() + ; errcount() 0 - > a = 1/0; b = 2 + ""; c = error(27); d = newerror("a"); - > print errcount(), a, errcount(), errmax(); + ; a = 1/0; b = 2 + ""; c = error(27); d = newerror("a"); + ; print errcount(), a, errcount(), errmax(); 4 Error 10001 4 10 LIMITS @@ -43,9 +43,10 @@ LINK LIBRARY none SEE ALSO - errmax, error, strerror, iserror, errno, newerror, errorcodes + errmax, error, strerror, iserror, errno, newerror, errorcodes, + stoponerror -## Copyright (C) 1999 Landon Curt Noll +## Copyright (C) 1999-2006 Landon Curt Noll ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License @@ -61,8 +62,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: errcount,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.4 $ +## @(#) $Id: errcount,v 29.4 2006/05/21 07:31:35 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/errcount,v $ ## ## Under source code control: 1997/03/08 08:51:14 diff --git a/help/errmax b/help/errmax index f2cc184..35e0d2b 100644 --- a/help/errmax +++ b/help/errmax @@ -13,33 +13,39 @@ DESCRIPTION Without an argument, errmax() returns the current value of an internal variable errmax. Calling errmax(num) returns this value but then resets its value to num. Execution is aborted if - evaluation of an error value if this makes errcount > errmax. - An error message displays the errno for the error. + evaluation of an error value if this makes errcount > errmax + and errmax is >= 0. + + When errmax is -1, there is no limit on the number of errors. EXAMPLE - > errmax(2) + ; errmax(2) 0 - > errcount() + ; errcount() 0 - > a = 1/0; b = 2 + ""; c = error(27); d = newerror("alpha"); + ; a = 1/0; b = 2 + ""; c = error(27); d = newerror("alpha"); Error 27 caused errcount to exceed errmax - > print c, d + ## Here global variables c and d were created when compiling the line + ## but execution was aborted before the intended assignments to c and d. + + ; print c, d 0 0 - Here global variables c and d were created when compiling the line - but execution was aborted before the intended assignments to c and d. + ; errmax(-1) + 2 LIMITS - 0 <= num < 2^32 + -1 <= num <= 2147483647 LINK LIBRARY none SEE ALSO - errcount, error, strerror, iserror, errno, newerror, errorcodes + errcount, error, strerror, iserror, errno, newerror, errorcodes, + stoponerror -## Copyright (C) 1999 Landon Curt Noll +## Copyright (C) 2006 Landon Curt Noll ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License @@ -55,8 +61,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: errmax,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.6 $ +## @(#) $Id: errmax,v 29.6 2006/05/21 07:31:35 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/errmax,v $ ## ## Under source code control: 1997/03/08 08:51:14 diff --git a/help/errno b/help/errno index 0bb2254..58328c7 100644 --- a/help/errno +++ b/help/errno @@ -33,15 +33,15 @@ DESCRIPTION EXAMPLE Assuming there is no file with name "not_a_file" - > errno(0) - > errmax(errcount()+4) + ; errno(0) + ; errmax(errcount()+4) 0 - > badfile = fopen("not_a_file", "r") - > print errno(), error(), strerror() + ; badfile = fopen("not_a_file", "r") + ; print errno(), error(), strerror() 2 System error 2 No such file or directory - > a = 1/0 - > print errno(), error(), strerror() + ; a = 1/0 + ; print errno(), error(), strerror() 10001 Error 10001 Division by zero LIMITS @@ -51,9 +51,10 @@ LINK LIBRARY none SEE ALSO - errmax, errcount, error, strerror, iserror, newerror, errorcodes + errmax, errcount, error, strerror, iserror, newerror, errorcodes, + stoponerror -## Copyright (C) 1999 Landon Curt Noll +## Copyright (C) 1999-2006 Landon Curt Noll ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License @@ -69,8 +70,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: errno,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.4 $ +## @(#) $Id: errno,v 29.4 2006/05/21 07:31:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/errno,v $ ## ## Under source code control: 1994/10/27 03:05:08 diff --git a/help/error b/help/error index d3940ae..4b764ef 100644 --- a/help/error +++ b/help/error @@ -22,13 +22,13 @@ EXAMPLE Note that by default, errmax() is 0 so unless errmax() is increased you will get: - > ba = error(10009) + ; ba = error(10009) Error 10009 caused errcount to exceed errmax - > errmax(errcount()+1) + ; errmax(errcount()+1) 0 - > a = error(10009) - > a + ; a = error(10009) + ; a Error 10009 LIMITS @@ -38,9 +38,10 @@ LINK LIBRARY none SEE ALSO - errcount, errmax, errorcodes, iserror, errno, strerror, newerror + errcount, errmax, errorcodes, iserror, errno, strerror, newerror, + stoponerror -## Copyright (C) 1999 Landon Curt Noll +## Copyright (C) 1999-2006 Landon Curt Noll ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License @@ -56,8 +57,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: error,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.4 $ +## @(#) $Id: error,v 29.4 2006/05/21 07:31:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/error,v $ ## ## Under source code control: 1995/12/18 03:30:59 diff --git a/help/euler b/help/euler index 2b89414..05f6a77 100644 --- a/help/euler +++ b/help/euler @@ -25,7 +25,7 @@ DESCRIPTION euler(n) for large even n. EXAMPLE - > for (n = 0; n <= 6; n++) print euler(n),; print; + ; for (n = 0; n <= 6; n++) print euler(n),; print; 1 0 -1 0 5 0 -61 LIMITS @@ -53,8 +53,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: euler,v 29.2 2000/12/17 12:27:58 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: euler,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/euler,v $ ## ## Under source code control: 2000/12/14 01:33:00 diff --git a/help/eval b/help/eval index bc741e9..81ae7ba 100644 --- a/help/eval +++ b/help/eval @@ -30,18 +30,18 @@ DESCRIPTION the scanerror messages and returns the value error(49). EXAMPLE - > str1 = "2 + 3"; print eval(str1); + ; str1 = "2 + 3"; print eval(str1); 5 - > i = 10; str2 = "local i = 0; 7; while (i++ < 5) print i^2,:;" - > print i, eval(str2), i + ; i = 10; str2 = "local i = 0; 7; while (i++ < 5) print i^2,:;" + ; print i, eval(str2), i 10 1 4 9 16 25 7 10 (The print statements in str2 return the null value, so execution of eval(str2) ends by returning the saved value 7. The global variable i is unchanged.) - > eval("2 + "); + ; eval("2 + "); Missing expression 49 @@ -76,8 +76,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: eval,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: eval,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/eval,v $ ## ## Under source code control: 1995/12/18 03:30:59 diff --git a/help/exp b/help/exp index 2acd076..8e79429 100644 --- a/help/exp +++ b/help/exp @@ -18,16 +18,16 @@ DESCRIPTION will give many significant figures. EXAMPLE - > print exp(2, 1e-5), exp(2,1e-10), exp(2, 1e-15), exp(2, 1e-20) + ; print exp(2, 1e-5), exp(2,1e-10), exp(2, 1e-15), exp(2, 1e-20) 7.38906 7.3890560989 7.38905609893065 7.38905609893065022723 - > print exp(30, 1e5), exp(30, 1), exp(30, 1e-10) + ; print exp(30, 1e5), exp(30, 1), exp(30, 1e-10) 10686474600000 10686474581524 10686474581524.4621469905 - > print exp(-20, 1e-5), exp(-20, 1e-10), exp(-20, 1e-15), exp(-20, 1e-20) + ; print exp(-20, 1e-5), exp(-20, 1e-10), exp(-20, 1e-15), exp(-20, 1e-20) 0 .0000000021 .000000002061154 .00000000206115362244 - > print exp(1+2i, 1e-5), exp(1+2i, 1e-10) + ; print exp(1+2i, 1e-5), exp(1+2i, 1e-10) -1.1312+2.47173i -1.1312043838+2.471726672i LIMITS @@ -56,8 +56,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.3 $ -## @(#) $Id: exp,v 29.3 2005/10/18 10:48:29 chongo Exp $ +## @(#) $Revision: 29.4 $ +## @(#) $Id: exp,v 29.4 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/exp,v $ ## ## Under source code control: 1995/10/11 04:41:26 diff --git a/help/fact b/help/fact index 3dbd801..4cafb19 100644 --- a/help/fact +++ b/help/fact @@ -16,10 +16,10 @@ DESCRIPTION 0! = 1 EXAMPLE - > print fact(10), fact(5), fact(2), fact(1), fact(0) + ; print fact(10), fact(5), fact(2), fact(1), fact(0) 3628800 120 2 1 1 - > print fact(40) + ; print fact(40) 815915283247897734345611269596115894272000000000 LIMITS @@ -48,8 +48,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: fact,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: fact,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/fact,v $ ## ## Under source code control: 1994/10/20 04:03:02 diff --git a/help/factor b/help/factor index 40224ea..317bb39 100644 --- a/help/factor +++ b/help/factor @@ -25,10 +25,10 @@ DESCRIPTION factor(n, limit, err) returns the value of err. EXAMPLE - > print factor(35,4), factor(35,5), factor(35), factor(-35) + ; print factor(35,4), factor(35,5), factor(35), factor(-35) 1 5 5 -1 - > print factor(2^32 + 1), factor(2^47 - 1), factor(2^59 - 1) + ; print factor(2^32 + 1), factor(2^47 - 1), factor(2^59 - 1) 641 2351 179951 LIMITS @@ -56,8 +56,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: factor,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: factor,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/factor,v $ ## ## Under source code control: 1995/12/18 12:34:57 diff --git a/help/fclose b/help/fclose index 39b9555..d4aa83b 100644 --- a/help/fclose +++ b/help/fclose @@ -30,15 +30,15 @@ DESCRIPTION this case. EXAMPLE - > fd = fopen("/etc/motd", "r") - > if (fd) print "file is open"; + ; fd = fopen("/etc/motd", "r") + ; if (fd) print "file is open"; file is open - > err = fclose(fd); - > if (isnull(err)) print "close successful"; else errno(err); + ; err = fclose(fd); + ; if (isnull(err)) print "close successful"; else errno(err); close successful - > if (!fd) print "file is closed"; + ; if (!fd) print "file is closed"; file is closed LIMITS @@ -67,8 +67,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: fclose,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: fclose,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/fclose,v $ ## ## Under source code control: 1994/10/27 03:04:16 diff --git a/help/fcnt b/help/fcnt index 5efaee7..c561cb3 100644 --- a/help/fcnt +++ b/help/fcnt @@ -18,7 +18,7 @@ DESCRIPTION If x is zero or if y = -1, 0 or 1, fcnt(x,y) is defined to be zero. EXAMPLE - > print fcnt(7,4), fcnt(24,4), fcnt(48,4) + ; print fcnt(7,4), fcnt(24,4), fcnt(48,4) 0 1 2 LIMITS @@ -46,8 +46,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: fcnt,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: fcnt,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/fcnt,v $ ## ## Under source code control: 1995/12/18 12:03:02 diff --git a/help/feof b/help/feof index dabea7a..c53b090 100644 --- a/help/feof +++ b/help/feof @@ -18,18 +18,18 @@ DESCRIPTION positioning operations (fseek, rewind, fsetpos) and by freopen. EXAMPLE - > fd1 = fopen("/tmp/newfile", "w") - > fputs(fd1, "Chongo was here\n") - > fflush(fd1) - > fd2 = fopen("/tmp/newfile", "r") - > feof(fd2) + ; fd1 = fopen("/tmp/newfile", "w") + ; fputs(fd1, "Chongo was here\n") + ; fflush(fd1) + ; fd2 = fopen("/tmp/newfile", "r") + ; feof(fd2) 0 - > fgetline(fd2) + ; fgetline(fd2) "Chongo was here" - > feof(fd2) + ; feof(fd2) 0 - > fgetline(fd2) - > feof(fd2) + ; fgetline(fd2) + ; feof(fd2) 1 LIMITS @@ -59,8 +59,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: feof,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: feof,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/feof,v $ ## ## Under source code control: 1994/10/27 03:04:17 diff --git a/help/ferror b/help/ferror index 5e8b16a..753c44d 100644 --- a/help/ferror +++ b/help/ferror @@ -18,8 +18,8 @@ DESCRIPTION 0 is returned. EXAMPLE - > fd = fopen("/etc/motd", "r") - > ferror(fd) + ; fd = fopen("/etc/motd", "r") + ; ferror(fd) 0 LIMITS @@ -48,8 +48,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: ferror,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: ferror,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/ferror,v $ ## ## Under source code control: 1994/10/27 03:04:17 diff --git a/help/fflush b/help/fflush index d58766d..dcb7448 100644 --- a/help/fflush +++ b/help/fflush @@ -13,9 +13,9 @@ DESCRIPTION This function forces a buffered output to the file associated with fd. EXAMPLE - > fd = fopen("/tmp/file", "w") - > fputc(fd, "@"); - > fflush(fd) + ; fd = fopen("/tmp/file", "w") + ; fputc(fd, "@"); + ; fflush(fd) LIMITS fd must be associated with an open file @@ -43,8 +43,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: fflush,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: fflush,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/fflush,v $ ## ## Under source code control: 1994/10/27 03:04:17 diff --git a/help/fgetc b/help/fgetc index 0266486..ab79d71 100644 --- a/help/fgetc +++ b/help/fgetc @@ -18,10 +18,10 @@ DESCRIPTION of EOF or error, nil is returned. EXAMPLE - > fd = fopen("/tmp/newfile", "w") - > fputs(fd, "chongo was here\n") - > fd2 = fopen("/tmp/newfile", "r") - > fgetc(fd2) + ; fd = fopen("/tmp/newfile", "w") + ; fputs(fd, "chongo was here\n") + ; fd2 = fopen("/tmp/newfile", "r") + ; fgetc(fd2) "c" LIMITS @@ -50,8 +50,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: fgetc,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: fgetc,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/fgetc,v $ ## ## Under source code control: 1995/03/04 11:33:19 diff --git a/help/fgetfield b/help/fgetfield index ba0ee38..7a39b55 100644 --- a/help/fgetfield +++ b/help/fgetfield @@ -23,23 +23,23 @@ DESCRIPTION EXAMPLE - > f = fopen("/tmp/junk", "w") - > fputs(f, " Alpha Beta \n") - > freopen(f, "r") - > fgetfield(f) + ; f = fopen("/tmp/junk", "w") + ; fputs(f, " Alpha Beta \n") + ; freopen(f, "r") + ; fgetfield(f) "Alpha" - > fgetfield(f) + ; fgetfield(f) "Beta" - > fgetfield(f) + ; fgetfield(f) > - > freopen(f, "w") - > fputstr(f, " Alpha ", "Beta") - > freopen(f, "r") - > fgetfield(f) + ; freopen(f, "w") + ; fputstr(f, " Alpha ", "Beta") + ; freopen(f, "r") + ; fgetfield(f) "Alpha" - > fgetfield(f) + ; fgetfield(f) "" - > fgetfield(f) + ; fgetfield(f) "Beta" LIMITS @@ -67,8 +67,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: fgetfield,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: fgetfield,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/fgetfield,v $ ## ## Under source code control: 1996/04/30 03:05:17 diff --git a/help/fgetline b/help/fgetline index c5e0264..a546ab9 100644 --- a/help/fgetline +++ b/help/fgetline @@ -25,19 +25,19 @@ DESCRIPTION (EOF or ERROR) nil is returned. EXAMPLE - > fd = fopen("/tmp/newfile", "w") - > fputs(fd, "chongo was here\n") - > fputs(fd, "123\n") - > fd2 = fopen("/tmp/newfile", "r") - > fgets(fd2) + ; fd = fopen("/tmp/newfile", "w") + ; fputs(fd, "chongo was here\n") + ; fputs(fd, "123\n") + ; fd2 = fopen("/tmp/newfile", "r") + ; fgets(fd2) "chongo was here " - > fclose(fd2) - > fd2 = fopen("/tmp/newfile", "r") - > fgetline(fd2) + ; fclose(fd2) + ; fd2 = fopen("/tmp/newfile", "r") + ; fgetline(fd2) "chongo was here" - > eval(fgetline(fd2)) + ; eval(fgetline(fd2)) 123 LIMITS @@ -66,8 +66,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: fgetline,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: fgetline,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/fgetline,v $ ## ## Under source code control: 1995/03/04 11:33:19 diff --git a/help/fgets b/help/fgets index 28dc4e7..df8c4a7 100644 --- a/help/fgets +++ b/help/fgets @@ -17,16 +17,16 @@ DESCRIPTION If a line is read, it is returned, otherwise (EOF or ERROR) nil is returned. EXAMPLE - > fd = fopen("/tmp/newfile", "w") - > fputs(fd, "chongo was here\n") - > fd2 = fopen("/tmp/newfile", "r") - > fgets(fd2) + ; fd = fopen("/tmp/newfile", "w") + ; fputs(fd, "chongo was here\n") + ; fd2 = fopen("/tmp/newfile", "r") + ; fgets(fd2) "chongo was here " - > fclose(fd2) - > fd2 = fopen("/tmp/newfile", "r") - > fgetline(fd2) + ; fclose(fd2) + ; fd2 = fopen("/tmp/newfile", "r") + ; fgetline(fd2) "chongo was here" LIMITS @@ -55,8 +55,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: fgets,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: fgets,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/fgets,v $ ## ## Under source code control: 1995/03/04 11:33:19 diff --git a/help/fgetstr b/help/fgetstr index c1da0ce..4146542 100644 --- a/help/fgetstr +++ b/help/fgetstr @@ -25,17 +25,17 @@ DESCRIPTION entered (on many terminals this is by ctrl-@). EXAMPLE - > f = fopen("/tmp/junk", "w") - > fputstr(f, " Alpha Beta ", "", "Gamma\n\tDelta") - > freopen(f, "r") - > fgetstr(f) + ; f = fopen("/tmp/junk", "w") + ; fputstr(f, " Alpha Beta ", "", "Gamma\n\tDelta") + ; freopen(f, "r") + ; fgetstr(f) " Alpha Beta " - > fgetstr(f) + ; fgetstr(f) "" - > fgetstr(f) + ; fgetstr(f) "Gamma Delta" - > fgetstr(f) + ; fgetstr(f) > LIMITS @@ -63,8 +63,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: fgetstr,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: fgetstr,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/fgetstr,v $ ## ## Under source code control: 1996/04/30 03:05:17 diff --git a/help/fib b/help/fib index 60f634a..dba2c2f 100644 --- a/help/fib +++ b/help/fib @@ -15,7 +15,7 @@ DESCRIPTION or negative) fib(n) = fib(n-1) + fib(n-2). EXAMPLE - > print fib(-2), fib(-1), fib(0), fib(1), fib(2), fib(3), fib(4), fib(5) + ; print fib(-2), fib(-1), fib(0), fib(1), fib(2), fib(3), fib(4), fib(5) -1 1 0 1 1 2 3 5 -8 LIMITS @@ -43,8 +43,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: fib,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: fib,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/fib,v $ ## ## Under source code control: 1995/10/25 04:03:45 diff --git a/help/files b/help/files index b95ce77..00100bd 100644 --- a/help/files +++ b/help/files @@ -42,20 +42,20 @@ DESCRIPTION "A line of text in the file on descriptor 5" EXAMPLE - > fd = fopen("/etc/motd", "r") - > fd + ; fd = fopen("/etc/motd", "r") + ; fd FILE 3 "/etc/motd" (reading, pos 0) - > files(3) + ; files(3) FILE 3 "/etc/motd" (reading, pos 0) - > if (isnull(files(4))) print "not open" + ; if (isnull(files(4))) print "not open" not open - > stdin = files(0) - > stdout = files(1) - > stderr = files(2) + ; stdin = files(0) + ; stdout = files(1) + ; stderr = files(2) - > print files() + ; print files() 20 LIMITS @@ -84,8 +84,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: files,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: files,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/files,v $ ## ## Under source code control: 1995/03/04 11:33:19 diff --git a/help/floor b/help/floor index f99f26a..aeeb687 100644 --- a/help/floor +++ b/help/floor @@ -20,7 +20,7 @@ DESCRIPTION by floor(t). EXAMPLE - > print floor(27), floor(1.23), floor(-4.56), floor(7.8 - 9.1i) + ; print floor(27), floor(1.23), floor(-4.56), floor(7.8 - 9.1i) 27 1 -5 7-10i LIMITS @@ -48,8 +48,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: floor,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: floor,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/floor,v $ ## ## Under source code control: 1994/09/30 01:12:01 diff --git a/help/fopen b/help/fopen index 66cb1ad..573d6f8 100644 --- a/help/fopen +++ b/help/fopen @@ -78,20 +78,20 @@ DESCRIPTION You can the errno() builtin to determine what the errno number means. EXAMPLE - > fd = fopen("/etc/motd", "r") - > print fd + ; fd = fopen("/etc/motd", "r") + ; print fd "/etc/motd" - > fd + ; fd FILE 3 "/etc/motd" (reading, pos 0) - > outfile = fopen("~/tmp/output", "w") - > print outfile + ; outfile = fopen("~/tmp/output", "w") + ; print outfile "~/tmp/output" - > outfile + ; outfile FILE 4 "~/tmp/output" (writing, pos 0) - > badfile = fopen("not_a_file", "r") - > if (!isfile(badfile)) print "error #" : badfile : ":", errno(badfile); + ; badfile = fopen("not_a_file", "r") + ; if (!isfile(badfile)) print "error #" : badfile : ":", errno(badfile); error #2: No such file or directory LIMITS @@ -102,7 +102,8 @@ LINK LIBRARY SEE ALSO errno, fclose, feof, ferror, fflush, fgetc, fgetline, fgets, files, fopen, - fprintf, fputc, fputs, fseek, fsize, ftell, isfile, printf, prompt + fprintf, fputc, fputs, fseek, fsize, ftell, isfile, printf, prompt, + fpathopen ## Copyright (C) 1999 Landon Curt Noll ## @@ -120,8 +121,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.3 $ -## @(#) $Id: fopen,v 29.3 2001/04/10 21:46:45 chongo Exp $ +## @(#) $Revision: 29.4 $ +## @(#) $Id: fopen,v 29.4 2006/05/07 07:18:26 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/fopen,v $ ## ## Under source code control: 1994/10/27 03:04:17 diff --git a/help/forall b/help/forall index 6782b06..bc268fd 100644 --- a/help/forall +++ b/help/forall @@ -16,15 +16,15 @@ DESCRIPTION to modify(x, y) but x is not changed. EXAMPLE - > global n = 0 - > define s(a) {n += a;} - > A = list(1,2,3,4) - > forall(A, "s") - > n + ; global n = 0 + ; define s(a) {n += a;} + ; A = list(1,2,3,4) + ; forall(A, "s") + ; n 10 - > define e(a) {if (iseven(a)) print a;} - > forall(A, "e") + ; define e(a) {if (iseven(a)) print a;} + ; forall(A, "e") 2 4 @@ -53,8 +53,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: forall,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: forall,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/forall,v $ ## ## Under source code control: 1995/07/10 02:09:31 diff --git a/help/fpathopen b/help/fpathopen new file mode 100644 index 0000000..0e3ad60 --- /dev/null +++ b/help/fpathopen @@ -0,0 +1,206 @@ +NAME + fpathopen - open an absolute filename, or a relative filename along a search path + +SYNOPSIS + fpathopen(filename, mode [,searchpath]) + +TYPES + filename string + mode string + searchpath string + + return file + +DESCRIPTION + This function opens the file named filename, potentially searching + for the file along a search path given by searchpath. If searchpath + is not given, then CALCPATH search path is used. + + If the filename is absolute, or it has an implied path, then + searchpath is ignored and the filename is opened directly. + Absolute filenames, and filenames with an implied path are files + that begin with: + + / # absolute path + ./ # implied path through the current working directory + ../ # implied path through the current working directory parent + ~ # absolute path going through a home directory + + A search path is a :-separated list of directories used to search for + a filename. For example: + + fpathopen("whey", "r", ".:/tmp:/var/tmp:~chongo/pub:~/tmp"); + + will cause this function to open the first readable file it + files while searching through these paths in order: + + ./whey + /tmp/whey + /var/tmp/whey + ~chongo/pub/whey + ~/tmp/whey + + IMPORTANT NOTE: + + This function searches along a path by attempting + to open files under the given mode. If the mode allows for + writing and a file can be created, then that file is returned. + + This call open "./gleet" for writing if the current directory is + writable, even if "./gleet" did not previously exist: + + fpathopen("gleet", "r", ".:/tmp:/var/tmp:~chongo/pub:~/tmp"); + + This call will likely open (and create if needded) for appending, + the file "/tmp/log" assuming that the user is not allowed to + create files in the previous system directories: + + fpathopen("log", "a", "/:/etc:/bin:/usr/bin:/tmp"); + + The CALCPATH search path is taken from the $CALCPATH environment + variable or if no such variable exists, a compiled in default search + path is used. See "help environment" and "help calcpath" for more + information on CALCPATH. + + It should be noted that while CALCPATH is typically used to find + resource files (*.cal files), this function is not restricted those + files. Any filename may be opened. + + A file can be opened for either reading, writing, or appending. + The mode is controlled by the mode flag as follows: + + 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: + + ~/lib/gleet + + refers to the file 'gleet' under the directory lib located + in your home directory. The file name: + + ~chongo/was_here + + refers to the a file 'was_here' under the home directory of + the user 'chongo'. + + If the open is successful, a value of type 'file' will be returned. + You can use the 'isfile' function to test the return value to see + if the open succeeded. You should assign the return value of fopen + to a variable for later use. File values can be copied to more than + one variable, and using any of the variables with the same file value + will produce the same results. + + Standard input, standard output and standard error are always opened + and cannot be closed. + + The truth value of an opened file is TRUE. + + If the open is unsuccessful, the numeric value of errno is returned. + You can the errno() builtin to determine what the errno number means. + +EXAMPLE + ; fd = fpathopen("motd", "r", "/etc:.") + ; print fd + "/etc/motd" + ; fd + FILE 3 "/etc/motd" (reading, pos 0) + + ; fd2 = fpathopen("lucas.cal", "r") + ; print fd2 + "/usr/share/calc/lucas.cal" + ; fd2 + FILE 4 "/usr/share/calc/lucas.cal" (reading, pos 0) + + ; fd3 = fpathopen("randmprime.cal", "r", calcpath()) + ; print fd3 + "/usr/share/calc/randmprime.cal" + ; fd3 + FILE 5 "/usr/share/calc/randmprime.cal" (reading, pos 0) + + ; fd4 = fpathopen("output", "w", "~/tmp:/tmp:/var/tmp") + ; print fd4 + "/home/chongo/tmp/output" + ; fd4 + FILE 6 "/home/chongo/tmp/output" (writing, pos 0) + + ; !mkdir -p /tmp/log + ; !touch /tmp/log/file + ; logfile = fpathopen("log/file", "a", "/tmp:/var/tmp") + ; print logfile + "/tmp/log/file" + ; logfile + FILE 7 "/home/chongo/tmp/output" (writing, pos 0) + + ; badfile = fpathopen("no_such_file", "r") + ; if (!isfile(badfile)) print "error #" : badfile : ":", errno(badfile); + error #2: No such file or directory + +LIMITS + none + +LINK LIBRARY + none + +SEE ALSO + errno, fclose, feof, ferror, fflush, fgetc, fgetline, fgets, files, fopen, + fprintf, fputc, fputs, fseek, fsize, ftell, isfile, printf, prompt, + environment, calcpath + +## Copyright (C) 2006 Landon Curt Noll +## +## Calc is open software; you can redistribute it and/or modify it under +## the terms of the version 2.1 of the GNU Lesser General Public License +## as published by the Free Software Foundation. +## +## Calc is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General +## Public License for more details. +## +## A copy of version 2.1 of the GNU Lesser General Public License is +## distributed with calc under the filename COPYING-LGPL. You should have +## 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: fpathopen,v 29.2 2006/05/07 07:24:34 chongo Exp $ +## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/fpathopen,v $ +## +## Under source code control: 2006/05/07 23:56:04 +## File existed as early as: 2006 +## +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/fprintf b/help/fprintf index 70309de..fd827fa 100644 --- a/help/fprintf +++ b/help/fprintf @@ -16,22 +16,22 @@ DESCRIPTION the standard output by printf(fmt, x_1, x_2, ...). EXAMPLE - > fprintf(files(1), "h=%d, i=%d\n", 2, 3); + ; fprintf(files(1), "h=%d, i=%d\n", 2, 3); h=2, i=3 - > c = config("epsilon", 1e-6); c = config("display", 6); - > c = config("tilde", 1); c = config("outround", 0); - > c = config("fullzero", 0); - > fmt = "%f,%10f,%-10f,%10.4f,%.4f,%.f.\n"; - > a = sqrt(3); - > fprintf(files(2), fmt,a,a,a,a,a,a); + ; c = config("epsilon", 1e-6); c = config("display", 6); + ; c = config("tilde", 1); c = config("outround", 0); + ; c = config("fullzero", 0); + ; fmt = "%f,%10f,%-10f,%10.4f,%.4f,%.f.\n"; + ; a = sqrt(3); + ; fprintf(files(2), fmt,a,a,a,a,a,a); 1.732051, 1.732051,1.732051 , ~1.7320,~1.7320,~1. - > file = fopen("/tmp/foo", "w"); - > mat A[4] = {sqrt(2), 3/7, "undefined", null()}; - > fprintf(file, "%f%r",A,A); - > fclose(file); - > !cat /tmp/foo + ; file = fopen("/tmp/foo", "w"); + ; mat A[4] = {sqrt(2), 3/7, "undefined", null()}; + ; fprintf(file, "%f%r",A,A); + ; fclose(file); + ; !cat /tmp/foo mat [4] (4 elements, 4 nonzero): [0] = 1.4142135623730950488 @@ -70,8 +70,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: fprintf,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: fprintf,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/fprintf,v $ ## ## Under source code control: 1996/03/12 22:50:41 diff --git a/help/fputc b/help/fputc index c0e6ddd..c2a4db4 100644 --- a/help/fputc +++ b/help/fputc @@ -15,10 +15,10 @@ DESCRIPTION associated with fd. EXAMPLE - > fd = fopen("/tmp/newfile", "w") - > fputc(fd, "c") - > fd2 = fopen("/tmp/newfile", "r") - > fgetc(fd2) + ; fd = fopen("/tmp/newfile", "w") + ; fputc(fd, "c") + ; fd2 = fopen("/tmp/newfile", "r") + ; fgetc(fd2) "c" LIMITS @@ -47,8 +47,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: fputc,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: fputc,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/fputc,v $ ## ## Under source code control: 1995/03/04 11:33:20 diff --git a/help/fputs b/help/fputs index be87362..43811b4 100644 --- a/help/fputs +++ b/help/fputs @@ -15,10 +15,10 @@ DESCRIPTION associated with fd. EXAMPLE - > fd = fopen("/tmp/newfile", "w") - > fputs(fd, "chongo was here\n") - > fd2 = fopen("/tmp/newfile", "r") - > fgetline(fd2) + ; fd = fopen("/tmp/newfile", "w") + ; fputs(fd, "chongo was here\n") + ; fd2 = fopen("/tmp/newfile", "r") + ; fgetline(fd2) "chongo was here" LIMITS @@ -47,8 +47,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: fputs,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: fputs,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/fputs,v $ ## ## Under source code control: 1995/03/04 11:33:20 diff --git a/help/fputstr b/help/fputstr index 1f32fae..de15733 100644 --- a/help/fputstr +++ b/help/fputstr @@ -18,16 +18,16 @@ DESCRIPTION null characters ('\0') are written to the file stream fs. EXAMPLE - > f = fopen("/tmp/junk", "w") - > fputstr(f, "Alpha", "Beta") - > freopen(f, "r") - > fgetstr(f) + ; f = fopen("/tmp/junk", "w") + ; fputstr(f, "Alpha", "Beta") + ; freopen(f, "r") + ; fgetstr(f) "Alpha" - > fgetstr(f) + ; fgetstr(f) "Beta" - > fgetstr(f) + ; fgetstr(f) > - > fputstr(f, "Gamma") + ; fputstr(f, "Gamma") Error 72 LIMITS @@ -55,8 +55,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: fputstr,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: fputstr,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/fputstr,v $ ## ## Under source code control: 1996/04/30 03:05:18 diff --git a/help/frac b/help/frac index c423c8a..e7c5fe2 100644 --- a/help/frac +++ b/help/frac @@ -26,8 +26,8 @@ DESCRIPTION as x in which m[[i]] = frac(x[[i]]). EXAMPLE - > c = config("mode", "frac") - > print frac(3), frac(22/7), frac(27/7), frac(-3.125), frac(2.15 - 3.25i) + ; c = config("mode", "frac") + ; print frac(3), frac(22/7), frac(27/7), frac(-3.125), frac(2.15 - 3.25i) 0 1/7 6/7 -1/8 3/20-1i/4 LIMITS @@ -57,8 +57,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.3 $ -## @(#) $Id: frac,v 29.3 2005/10/18 10:48:29 chongo Exp $ +## @(#) $Revision: 29.4 $ +## @(#) $Id: frac,v 29.4 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/frac,v $ ## ## Under source code control: 1995/12/18 03:30:59 diff --git a/help/free b/help/free index ec4f572..0b61e0c 100644 --- a/help/free +++ b/help/free @@ -17,13 +17,13 @@ DESCRIPTION free(.) frees the current "old value". EXAMPLE - > a = 7 - > mat M[3] = {1, list(2,3,4), list(5,6)} - > print memsize(a), memsize(M) + ; a = 7 + ; mat M[3] = {1, list(2,3,4), list(5,6)} + ; print memsize(a), memsize(M) 80 736 - > free(a, M[1]) - > print memsize(a), memsize(M) + ; free(a, M[1]) + ; print memsize(a), memsize(M) 16 424 LIMITS @@ -51,8 +51,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: free,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: free,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/free,v $ ## ## Under source code control: 1997/09/06 20:03:35 diff --git a/help/freebernoulli b/help/freebernoulli index 92f9523..5244095 100644 --- a/help/freebernoulli +++ b/help/freebernoulli @@ -12,7 +12,7 @@ DESCRIPTION freebernoulli(). EXAMPLE - > freebernoulli(); + ; freebernoulli(); LIMITS none @@ -39,8 +39,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.3 $ -## @(#) $Id: freebernoulli,v 29.3 2004/07/26 05:54:00 chongo Exp $ +## @(#) $Revision: 29.4 $ +## @(#) $Id: freebernoulli,v 29.4 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/freebernoulli,v $ ## ## Under source code control: 2000/07/13 diff --git a/help/freeeuler b/help/freeeuler index 2426a24..9f09af8 100644 --- a/help/freeeuler +++ b/help/freeeuler @@ -12,7 +12,7 @@ DESCRIPTION freeeuler(). EXAMPLE - > freeeuler(); + ; freeeuler(); LIMITS none @@ -39,8 +39,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.1 $ -## @(#) $Id: freeeuler,v 29.1 2000/12/14 10:31:45 chongo Exp $ +## @(#) $Revision: 29.2 $ +## @(#) $Id: freeeuler,v 29.2 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/freeeuler,v $ ## ## Under source code control: 2000/12/14 01:33:00 diff --git a/help/freeglobals b/help/freeglobals index dd72960..35e00b2 100644 --- a/help/freeglobals +++ b/help/freeglobals @@ -13,9 +13,9 @@ DESCRIPTION The oldvalue (.) is not freed by this function. EXAMPLE - > global a = 1, b = list(2,3,4), c = mat[3] - > static a = 2 - > show globals + ; global a = 1, b = list(2,3,4), c = mat[3] + ; static a = 2 + ; show globals Name Level Type ---- ----- ----- @@ -25,8 +25,8 @@ EXAMPLE c 0 matrix Number: 4 - > freeglobals() - > show globals + ; freeglobals() + ; show globals Name Level Type ---- ----- ----- @@ -62,8 +62,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: freeglobals,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: freeglobals,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/freeglobals,v $ ## ## Under source code control: 1997/09/06 20:03:35 diff --git a/help/freeredc b/help/freeredc index 6187bc4..86fb2db 100644 --- a/help/freeredc +++ b/help/freeredc @@ -12,13 +12,13 @@ DESCRIPTION calls to rcin, rcout, etc. EXAMPLE - > a = rcin(10,27) - > b = rcin(10,15) - > show redc + ; a = rcin(10,27) + ; b = rcin(10,15) + ; show redc 0 1 27 1 2 15 - > freeredc() - > show redc + ; freeredc() + ; show redc > LIMITS @@ -46,8 +46,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: freeredc,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: freeredc,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/freeredc,v $ ## ## Under source code control: 1997/09/06 20:03:35 diff --git a/help/freestatics b/help/freestatics index bbba562..43a62fa 100644 --- a/help/freestatics +++ b/help/freestatics @@ -16,23 +16,23 @@ DESCRIPTION for use when these functions are being undefined or redefined.. EXAMPLE - > static a = 5 - > define f(x) = a++ * x; + ; static a = 5 + ; define f(x) = a++ * x; f() defined - > global a - > f(1) + ; global a + ; f(1) 5 - > show statics + ; show statics Name Scopes Type ---- ------ ----- a 1 0 real = 6 Number: 1 - > freestatics() - > f(1) + ; freestatics() + ; f(1) Error 10005 - > strerror(.) + ; strerror(.) "Bad arguments for *" LIMITS @@ -60,8 +60,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: freestatics,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: freestatics,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/freestatics,v $ ## ## Under source code control: 1997/09/06 20:03:35 diff --git a/help/frem b/help/frem index 219af55..b3bf70a 100644 --- a/help/frem +++ b/help/frem @@ -24,7 +24,7 @@ DESCRIPTION For all x and y, abs(x) = frem(x,y) * abs(y) ^ fcnt(x,y). EXAMPLE - > print frem(7,4), frem(24,4), frem(48,4), frem(-48,4) + ; print frem(7,4), frem(24,4), frem(48,4), frem(-48,4) 7 6 3 3 LIMITS @@ -52,8 +52,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: frem,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: frem,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/frem,v $ ## ## Under source code control: 1995/12/18 12:03:02 diff --git a/help/freopen b/help/freopen index 89442ae..91fafc1 100644 --- a/help/freopen +++ b/help/freopen @@ -2,7 +2,7 @@ NAME freopen - close (if necessary) and reopen a filestream SYNOPSIS - freopen(fs, mode) or freopen(fs, mode, filename) + freopen(fs, mode [,filename]) TYPES fs open or closed file stream @@ -22,13 +22,13 @@ DESCRIPTION EXAMPLE - > f = fopen("/tmp/junk", "w") - > fputs(f, "Leonard Euler") - > freopen(f, "r") - > fgets(f) + ; f = fopen("/tmp/junk", "w") + ; fputs(f, "Leonard Euler") + ; freopen(f, "r") + ; fgets(f) "Leonard Euler" - > !chmod u-w /tmp/junk - > freopen(f, "w") + ; !chmod u-w /tmp/junk + ; freopen(f, "w") Error 10013 LIMITS @@ -57,8 +57,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: freopen,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: freopen,v 29.3 2006/05/07 07:18:56 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/freopen,v $ ## ## Under source code control: 1996/04/30 03:05:18 diff --git a/help/fscan b/help/fscan index cda6e83..3e4aa11 100644 --- a/help/fscan +++ b/help/fscan @@ -20,13 +20,13 @@ DESCRIPTION The function returns the number of fields evaluated. EXAMPLE - > global a, b, c, d; - > f = fopen("/tmp/junk", "w+"); - > fputs(f, "\t3+4\t\ta-2i d=a^2 'word'") - > rewind(f) - > fscan(f, a, b, , c) + ; global a, b, c, d; + ; f = fopen("/tmp/junk", "w+"); + ; fputs(f, "\t3+4\t\ta-2i d=a^2 'word'") + ; rewind(f) + ; fscan(f, a, b, , c) 4 - > print a, b, c, d + ; print a, b, c, d 7 a-2i word 49 LIMITS @@ -54,8 +54,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: fscan,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: fscan,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/fscan,v $ ## ## Under source code control: 1996/04/30 03:05:18 diff --git a/help/fscanf b/help/fscanf index 9092772..391ef9d 100644 --- a/help/fscanf +++ b/help/fscanf @@ -96,28 +96,28 @@ DESCRIPTION EXAMPLE - > global a, b, c - > f = fopen("/tmp/junk", "w+") - > fputs(f, "Alpha Beta Gamma") - > rewind(f) - > fscanf(f, "Alpha Gamma") - > fgets(f) + ; global a, b, c + ; f = fopen("/tmp/junk", "w+") + ; fputs(f, "Alpha Beta Gamma") + ; rewind(f) + ; fscanf(f, "Alpha Gamma") + ; fgets(f) "Beta Gamma" - > rewind(f) - > fscanf(f, "%5c", a) + ; rewind(f) + ; fscanf(f, "%5c", a) 1 - > a + ; a "Alpha" - > fgets(f) + ; fgets(f) " Beta Gamma" - > rewind(f) - > fscanf(f, "%3c%s%[^m]", a, b, c) + ; rewind(f) + ; fscanf(f, "%3c%s%[^m]", a, b, c) 3 - > print a, b + ; print a, b Alp ha - > print c + ; print c Beta Ga - > fgets(f) + ; fgets(f) "mma" LIMITS @@ -145,8 +145,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: fscanf,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: fscanf,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/fscanf,v $ ## ## Under source code control: 1996/04/30 03:05:18 diff --git a/help/fseek b/help/fseek index 20c800e..944d6af 100644 --- a/help/fseek +++ b/help/fseek @@ -30,28 +30,28 @@ DESCRIPTION filled by null ('\0') characters. EXAMPLE - > fd = fopen("/tmp/curds", "w") - > fputs(fd, "0123456789abcdef") - > freopen(fd, "r") - > fsize(fd) + ; fd = fopen("/tmp/curds", "w") + ; fputs(fd, "0123456789abcdef") + ; freopen(fd, "r") + ; fsize(fd) 16 - > fseek(fd, 5) - > fgets(fd) + ; fseek(fd, 5) + ; fgets(fd) "56789abcdef" - > fseek(fd, 0) - > fscanf(fd, "%*5c") + ; fseek(fd, 0) + ; fscanf(fd, "%*5c") 0 - > fseek(fd, 5, 1) - > fgets(fd) + ; fseek(fd, 5, 1) + ; fgets(fd) "abcdef" - > ftell(fd) + ; ftell(fd) 16 - > fseek(fd, -5, 2) - > fgets(fd) + ; fseek(fd, -5, 2) + ; fgets(fd) "bcdef" - > fseek(fd, -2) + ; fseek(fd, -2) System error 22 - > ftell(fd) + ; ftell(fd) 16 The results for the last four lines may be different for different systems. @@ -82,8 +82,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: fseek,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: fseek,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/fseek,v $ ## ## Under source code control: 1995/03/04 11:33:20 diff --git a/help/fsize b/help/fsize index ec38643..aa6a21c 100644 --- a/help/fsize +++ b/help/fsize @@ -15,8 +15,8 @@ DESCRIPTION the file size as reported by fsize. EXAMPLE - > fd = fopen("/etc/motd", "r") - > fsize(fd) + ; fd = fopen("/etc/motd", "r") + ; fsize(fd) 784 LIMITS @@ -45,8 +45,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: fsize,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: fsize,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/fsize,v $ ## ## Under source code control: 1995/03/04 11:33:20 diff --git a/help/ftell b/help/ftell index 34039ea..d33ebb4 100644 --- a/help/ftell +++ b/help/ftell @@ -18,23 +18,23 @@ DESCRIPTION On failure, this returns an error value. EXAMPLE - > fd = fopen("/tmp/curds", "w") - > fputs(fd, "0123456789") - > ftell(fd) + ; fd = fopen("/tmp/curds", "w") + ; fputs(fd, "0123456789") + ; ftell(fd) 10 - > fputs(fd, "abcdef") - > ftell(fd) + ; fputs(fd, "abcdef") + ; ftell(fd) 16 - > fseek(fd, 20, 0) - > ftell(fd) + ; fseek(fd, 20, 0) + ; ftell(fd) 20 - > fputs(fd, "01234") - > ftell(fd) + ; fputs(fd, "01234") + ; ftell(fd) 25 - > freopen(fd, "r") - > fscanf(fd, "%*5c") + ; freopen(fd, "r") + ; fscanf(fd, "%*5c") 0 - > ftell(fd) + ; ftell(fd) 5 LIMITS @@ -62,8 +62,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: ftell,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: ftell,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/ftell,v $ ## ## Under source code control: 1995/03/04 11:33:21 diff --git a/help/gcd b/help/gcd index 20d38a0..a036a95 100644 --- a/help/gcd +++ b/help/gcd @@ -15,7 +15,7 @@ DESCRIPTION If all xi are zero, the gcd is zero. EXAMPLE - > print gcd(12, -24, 30), gcd(9/10, 11/5, 4/25), gcd(0,0,0,0,0) + ; print gcd(12, -24, 30), gcd(9/10, 11/5, 4/25), gcd(0,0,0,0,0) 6 .02 0 LIMITS @@ -43,8 +43,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: gcd,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: gcd,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/gcd,v $ ## ## Under source code control: 1995/10/05 04:52:26 diff --git a/help/gcdrem b/help/gcdrem index 413a70c..27f917d 100644 --- a/help/gcdrem +++ b/help/gcdrem @@ -38,10 +38,10 @@ PROPERTIES gcdrem(x,y) = frem(...(frem(frem(x,p_1),p_2)...,p_k) EXAMPLE - > print gcdrem(6,15), gcdrem(15,6), gcdrem(72,6), gcdrem(6,72) + ; print gcdrem(6,15), gcdrem(15,6), gcdrem(72,6), gcdrem(6,72) 2 5 1 1 - > print gcdrem(630,6), gcdrem(6,630) + ; print gcdrem(630,6), gcdrem(6,630) 35 1 LIMITS @@ -69,8 +69,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: gcdrem,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: gcdrem,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/gcdrem,v $ ## ## Under source code control: 1995/12/18 12:03:02 diff --git a/help/gd b/help/gd index 50eba28..42db5f6 100644 --- a/help/gd +++ b/help/gd @@ -35,10 +35,10 @@ DESCRIPTION gd(z) = atan(sinh(x)/cos(y)) + i * atanh(sin(y)/cosh(x)). EXAMPLE - > print gd(1, 1e-5), gd(1, 1e-10), gd(1, 1e-15) + ; print gd(1, 1e-5), gd(1, 1e-10), gd(1, 1e-15) .86577 .8657694832 .865769483239659 - > print gd(2+1i, 1e-5), gd(2+1i, 1e-10) + ; print gd(2+1i, 1e-5), gd(2+1i, 1e-10) 1.42291+.22751i 1.4229114625+.2275106584i LIMITS @@ -66,8 +66,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.3 $ -## @(#) $Id: gd,v 29.3 2005/10/18 10:48:29 chongo Exp $ +## @(#) $Revision: 29.4 $ +## @(#) $Id: gd,v 29.4 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/gd,v $ ## ## Under source code control: 1997/09/06 20:03:35 diff --git a/help/getenv b/help/getenv index 84456ae..522b285 100644 --- a/help/getenv +++ b/help/getenv @@ -14,15 +14,15 @@ DESCRIPTION the string env. If no such environment variable exists, nil is returned. EXAMPLE - > putenv("name", "value") + ; putenv("name", "value") 0 - > getenv("name") + ; getenv("name") "value" - > putenv("name=val2") + ; putenv("name=val2") 0 - > getenv("name") + ; getenv("name") "val2" - > isnull(getenv("unknown")) + ; isnull(getenv("unknown")) 1 LIMITS @@ -50,8 +50,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: getenv,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: getenv,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/getenv,v $ ## ## Under source code control: 1995/07/09 03:48:57 diff --git a/help/hash b/help/hash index eaffc9c..740206a 100644 --- a/help/hash +++ b/help/hash @@ -24,8 +24,8 @@ DESCRIPTION information about the Fowler/Noll/Vo (FNV) hash. EXAMPLE - > a = isqrt(2e1000); s = "xyz"; - > hash(a,s) + ; a = isqrt(2e1000); s = "xyz"; + ; hash(a,s) 2378490456 LIMITS @@ -53,8 +53,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.3 $ -## @(#) $Id: hash,v 29.3 2003/03/01 01:16:02 chongo Exp $ +## @(#) $Revision: 29.4 $ +## @(#) $Id: hash,v 29.4 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/hash,v $ ## ## Under source code control: 1996/03/12 23:10:01 diff --git a/help/head b/help/head index 509c51b..25a1445 100644 --- a/help/head +++ b/help/head @@ -25,14 +25,14 @@ DESCRIPTION For any integer y, x == join(head(x,y), tail(x,-y)). EXAMPLE - > A = list(2, 3, 5, 7, 11) - > head(A, 2) + ; A = list(2, 3, 5, 7, 11) + ; head(A, 2) list (2 members, 2 nonzero): [[0]] = 2 [[1]] = 3 - > head(A, -2) + ; head(A, -2) list (3 members, 3 nonzero): [[0]] = 2 @@ -64,8 +64,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: head,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: head,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/head,v $ ## ## Under source code control: 1995/07/10 02:09:30 diff --git a/help/highbit b/help/highbit index 38a00c8..305e8c3 100644 --- a/help/highbit +++ b/help/highbit @@ -16,7 +16,7 @@ DESCRIPTION representation of x then has n + 1 digits. EXAMPLE - > print highbit(2), highbit(3), highbit(4), highbit(-15), highbit(2^27) + ; print highbit(2), highbit(3), highbit(4), highbit(-15), highbit(2^27) 1 1 2 3 27 LIMITS @@ -44,8 +44,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: highbit,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: highbit,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/highbit,v $ ## ## Under source code control: 1995/10/03 10:40:02 diff --git a/help/hmean b/help/hmean index 7d6625a..7ba5207 100644 --- a/help/hmean +++ b/help/hmean @@ -24,8 +24,8 @@ DESCRIPTION EXAMPLE - > c = config("mode", "frac") - > print hmean(1), hmean(1,2), hmean(1,2,3), hmean(1,2,3,4), hmean(1,2,0,3) + ; c = config("mode", "frac") + ; print hmean(1), hmean(1,2), hmean(1,2,3), hmean(1,2,3,4), hmean(1,2,0,3) 1 4/3 18/11 48/25 0 LIMITS @@ -53,8 +53,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: hmean,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: hmean,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/hmean,v $ ## ## Under source code control: 1995/12/18 03:30:59 diff --git a/help/hnrmod b/help/hnrmod index 8d55982..4a7a516 100644 --- a/help/hnrmod +++ b/help/hnrmod @@ -28,7 +28,7 @@ DESCRIPTION is also needed. EXAMPLE - > print hnrmod(2^177-1, 1, 177, -1), hnrmod(10^40, 17, 51, 1) + ; print hnrmod(2^177-1, 1, 177, -1), hnrmod(10^40, 17, 51, 1) 0 33827019788296445 LIMITS @@ -58,8 +58,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: hnrmod,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: hnrmod,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/hnrmod,v $ ## ## Under source code control: 1997/07/02 07:10:43 diff --git a/help/hypot b/help/hypot index 4808146..8e9d9fa 100644 --- a/help/hypot +++ b/help/hypot @@ -15,7 +15,7 @@ DESCRIPTION The default value for eps is epsilon(). EXAMPLE - > print hypot(3, 4, 1e-6), hypot(2, -3, 1e-6) + ; print hypot(3, 4, 1e-6), hypot(2, -3, 1e-6) 5 3.605551 LIMITS @@ -43,8 +43,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: hypot,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: hypot,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/hypot,v $ ## ## Under source code control: 1995/10/05 04:52:26 diff --git a/help/ilog b/help/ilog index a48e946..e755a55 100644 --- a/help/ilog +++ b/help/ilog @@ -14,7 +14,7 @@ DESCRIPTION Returns the greatest integer n for which b^n <= abs(x). EXAMPLE - > print ilog(2, 3), ilog(8, 3), ilog(8.9, 3), ilog(1/8, 3) + ; print ilog(2, 3), ilog(8, 3), ilog(8.9, 3), ilog(1/8, 3) 0 1 1 -2 LIMITS @@ -43,8 +43,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: ilog,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: ilog,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/ilog,v $ ## ## Under source code control: 1995/10/25 04:03:45 diff --git a/help/ilog10 b/help/ilog10 index acfc1bc..af80461 100644 --- a/help/ilog10 +++ b/help/ilog10 @@ -13,7 +13,7 @@ DESCRIPTION Returns the greatest integer n for which 10^n <= x. EXAMPLE - > print ilog10(7), ilog10(77.7), ilog10(777), ilog10(.00777), ilog10(-1e27) + ; print ilog10(7), ilog10(77.7), ilog10(777), ilog10(.00777), ilog10(-1e27) 0 1 2 -3 27 LIMITS @@ -41,8 +41,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: ilog10,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: ilog10,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/ilog10,v $ ## ## Under source code control: 1995/10/03 10:40:02 diff --git a/help/ilog2 b/help/ilog2 index 0ecebbf..e76dc6f 100644 --- a/help/ilog2 +++ b/help/ilog2 @@ -13,7 +13,7 @@ DESCRIPTION Returns the greatest integer n for which 2^n <= abs(x). EXAMPLE - > print ilog2(1), ilog2(2), ilog2(3), ilog2(4), ilog(1/15) + ; print ilog2(1), ilog2(2), ilog2(3), ilog2(4), ilog(1/15) 0 1 1 2 -4 LIMITS @@ -41,8 +41,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: ilog2,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: ilog2,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/ilog2,v $ ## ## Under source code control: 1995/10/03 10:40:02 diff --git a/help/im b/help/im index d3dade3..435eb88 100644 --- a/help/im +++ b/help/im @@ -13,7 +13,7 @@ DESCRIPTION If x = u + v * 1i where u and v are real, im(x) returns v. EXAMPLE - > print im(2), im(2 + 3i), im(-4.25 - 7i) + ; print im(2), im(2 + 3i), im(-4.25 - 7i) 0 3 -7 LIMITS @@ -41,8 +41,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.3 $ -## @(#) $Id: im,v 29.3 2002/03/12 09:38:26 chongo Exp $ +## @(#) $Revision: 29.4 $ +## @(#) $Id: im,v 29.4 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/im,v $ ## ## Under source code control: 1995/10/05 04:52:26 diff --git a/help/insert b/help/insert index 9f2e972..848282c 100644 --- a/help/insert +++ b/help/insert @@ -20,16 +20,16 @@ DESCRIPTION after the last element x_n-1. An error occurs if y > n. EXAMPLE - > A = list(2,3,4) - > print A + ; A = list(2,3,4) + ; print A list (3 elements, 3 nonzero): [[0]] = 2 [[1]] = 3 [[2]] = 4 - > insert(A, 1, 5, 6) - > print A + ; insert(A, 1, 5, 6) + ; print A list (5 elements, 5 nonzero): [[0]] = 1 @@ -38,8 +38,8 @@ EXAMPLE [[3]] = 3 [[4]] = 4 - > insert(A, 2, remove(A)) - > print A + ; insert(A, 2, remove(A)) + ; print A list (5 elements, 5 nonzero): [[0]] = 1 @@ -74,8 +74,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: insert,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: insert,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/insert,v $ ## ## Under source code control: 1994/03/19 03:13:18 diff --git a/help/int b/help/int index 0d313a5..ff694ae 100644 --- a/help/int +++ b/help/int @@ -26,7 +26,7 @@ DESCRIPTION as x in which m[[i]] = int(x[[i]]). EXAMPLE - > print int(3), int(22/7), int(27/7), int(-3.125), int(2.15 - 3.25i) + ; print int(3), int(22/7), int(27/7), int(-3.125), int(2.15 - 3.25i) 3 3 3 -3 2-3i LIMITS @@ -56,8 +56,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.3 $ -## @(#) $Id: int,v 29.3 2005/10/18 10:48:29 chongo Exp $ +## @(#) $Revision: 29.4 $ +## @(#) $Id: int,v 29.4 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/int,v $ ## ## Under source code control: 1994/09/30 00:57:18 diff --git a/help/inverse b/help/inverse index a5aac60..ed196a0 100644 --- a/help/inverse +++ b/help/inverse @@ -24,11 +24,11 @@ DESCRIPTION n x n matrix. The inverse m will have the same index limits as x. EXAMPLE - > print inverse(5/4), inverse(-2/7), inverse(3 + 4i) + ; print inverse(5/4), inverse(-2/7), inverse(3 + 4i) .8 -3.5 .12-.16i - > mat A[2,2] = {2,3,5,7} - > print inverse(A) + ; mat A[2,2] = {2,3,5,7} + ; print inverse(A) mat [2,2] (4 elements, 4 nonzero): [0,0] = -7 @@ -63,8 +63,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.3 $ -## @(#) $Id: inverse,v 29.3 2005/10/18 10:48:29 chongo Exp $ +## @(#) $Revision: 29.4 $ +## @(#) $Id: inverse,v 29.4 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/inverse,v $ ## ## Under source code control: 1996/03/12 23:10:01 diff --git a/help/iroot b/help/iroot index 378aa9e..d0d7d8a 100644 --- a/help/iroot +++ b/help/iroot @@ -14,7 +14,7 @@ DESCRIPTION Return the greatest integer v for which v^n <= x. EXAMPLE - > print iroot(100,3), iroot(274,3), iroot(1,9), iroot(pi()^8,5) + ; print iroot(100,3), iroot(274,3), iroot(1,9), iroot(pi()^8,5) 4 6 1 6 LIMITS @@ -42,8 +42,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: iroot,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: iroot,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/iroot,v $ ## ## Under source code control: 1995/10/25 04:03:45 diff --git a/help/isassoc b/help/isassoc index 5a03f1b..bd7ddaf 100644 --- a/help/isassoc +++ b/help/isassoc @@ -14,8 +14,8 @@ DESCRIPTION an association, 0 otherwise. EXAMPLE - > a = assoc() - > print isassoc(a), isassoc(1) + ; a = assoc() + ; print isassoc(a), isassoc(1) 1 0 LIMITS @@ -47,8 +47,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: isassoc,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: isassoc,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/isassoc,v $ ## ## Under source code control: 1994/10/21 02:21:27 diff --git a/help/isatty b/help/isatty index 01a3433..6ed942e 100644 --- a/help/isatty +++ b/help/isatty @@ -14,10 +14,10 @@ DESCRIPTION EXAMPLE - > print isatty(files(0)), isatty(files(1)), isatty(files(2)) + ; print isatty(files(0)), isatty(files(1)), isatty(files(2)) 1 1 1 - > fd = fopen("/dev/null", "r") - > isatty(fd) + ; fd = fopen("/dev/null", "r") + ; isatty(fd) 0 LIMITS @@ -50,8 +50,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: isatty,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: isatty,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/isatty,v $ ## ## Under source code control: 1995/07/09 03:49:34 diff --git a/help/isblk b/help/isblk index 69976f5..6f288a6 100644 --- a/help/isblk +++ b/help/isblk @@ -19,15 +19,15 @@ DESCRIPTION has been freed. EXAMPLE - > A = blk() - > isblk(A) + ; A = blk() + ; isblk(A) 1 - > B = blk("beta") - > isblk(B) + ; B = blk("beta") + ; isblk(B) 2 - > isblk(3) + ; isblk(3) 0 LIMITS @@ -59,8 +59,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: isblk,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: isblk,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/isblk,v $ ## ## Under source code control: 1997/04/06 03:03:23 diff --git a/help/isconfig b/help/isconfig index 87a830a..18b2a30 100644 --- a/help/isconfig +++ b/help/isconfig @@ -14,8 +14,8 @@ DESCRIPTION 1 if x is a file, 0 otherwise. EXAMPLE - > a = config("all") - > print isconfig(a), isconfig(0); + ; a = config("all") + ; print isconfig(a), isconfig(0); 1 0 LIMITS @@ -47,8 +47,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: isconfig,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: isconfig,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/isconfig,v $ ## ## Under source code control: 1995/11/11 05:09:41 diff --git a/help/isdefined b/help/isdefined index 65868c9..8e61c04 100644 --- a/help/isdefined +++ b/help/isdefined @@ -14,20 +14,20 @@ DESCRIPTION 2 if str is the name of a user-defined function, 0 otherwise. EXAMPLE - > isdefined("abs") + ; isdefined("abs") 1 - > isdefined("fun") + ; isdefined("fun") 0 - > define fun() { } + ; define fun() { } fun() defined - > isdefined("fun") + ; isdefined("fun") 2 - > undefine fun - > isdefined("fun") + ; undefine fun + ; isdefined("fun") 0 LIMITS @@ -59,8 +59,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: isdefined,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: isdefined,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/isdefined,v $ ## ## Under source code control: 1997/04/05 14:10:17 diff --git a/help/iserror b/help/iserror index 9c62f19..befc85a 100644 --- a/help/iserror +++ b/help/iserror @@ -14,7 +14,7 @@ DESCRIPTION If x is an error value, iserror(x) returns its error type. EXAMPLE - > a = error(99) + ; a = error(99) print iserror(a), iserror(2 + a), iserror(2 + "a"), iserror(2 + 3) 99 99 3 0 @@ -25,13 +25,13 @@ LINK LIBRARY none SEE ALSO - error, errorcodes, + error, errorcodes, stoponerror, isassoc, isatty, isblk, isconfig, isdefined, iseven, isfile, ishash, isident, isint, islist, ismat, ismult, isnull, isnum, isobj, isobjtype, isodd, isprime, isrand, israndom, isreal, isrel, issimple, issq, isstr, istype -## Copyright (C) 1999 Landon Curt Noll +## Copyright (C) 1999-2006 Landon Curt Noll ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License @@ -47,8 +47,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: iserror,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.4 $ +## @(#) $Id: iserror,v 29.4 2006/05/21 07:31:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/iserror,v $ ## ## Under source code control: 1995/12/18 03:30:59 diff --git a/help/iseven b/help/iseven index 879720b..2202b89 100644 --- a/help/iseven +++ b/help/iseven @@ -14,10 +14,10 @@ DESCRIPTION even integer, 0 otherwise. EXAMPLE - > print iseven(2.0), iseven(1), iseven("0") + ; print iseven(2.0), iseven(1), iseven("0") 1 0 0 - > print iseven(2i), iseven(1e20), iseven(1/3) + ; print iseven(2i), iseven(1e20), iseven(1/3) 0 1 0 LIMITS @@ -48,8 +48,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: iseven,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: iseven,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/iseven,v $ ## ## Under source code control: 1994/10/21 02:21:27 diff --git a/help/isfile b/help/isfile index 0bb5340..68a3bc2 100644 --- a/help/isfile +++ b/help/isfile @@ -14,8 +14,8 @@ DESCRIPTION a file, 0 otherwise. EXAMPLE - > a = files(0) - > print isfile(a), isfile(files(1)), isfile(1) + ; a = files(0) + ; print isfile(a), isfile(files(1)), isfile(1) 1 1 0 LIMITS @@ -46,8 +46,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: isfile,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: isfile,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/isfile,v $ ## ## Under source code control: 1994/10/21 02:21:27 diff --git a/help/ishash b/help/ishash index ffd926f..388ce43 100644 --- a/help/ishash +++ b/help/ishash @@ -18,8 +18,8 @@ DESCRIPTION 3 if x is a md5 hash state. EXAMPLE - > a = shs(0), b = shs1(0), c = md5(0) - > print ishash(0), ishash(a), ishash(b), ishash(c); + ; a = shs(0), b = shs1(0), c = md5(0) + ; print ishash(0), ishash(a), ishash(b), ishash(c); 0 1 2 3 LIMITS @@ -51,8 +51,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: ishash,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: ishash,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/ishash,v $ ## ## Under source code control: 1995/11/11 05:09:41 diff --git a/help/isident b/help/isident index b4a3b3a..9ffaa19 100644 --- a/help/isident +++ b/help/isident @@ -14,8 +14,8 @@ DESCRIPTION 0 otherwise. EXAMPLE - > mat x[3,3] = {1,0,0,0,1,0,0,0,1}; - > isident(x) + ; mat x[3,3] = {1,0,0,0,1,0,0,0,1}; + ; isident(x) 1 LIMITS @@ -47,8 +47,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: isident,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: isident,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/isident,v $ ## ## Under source code control: 1995/07/09 18:25:36 diff --git a/help/isint b/help/isint index 96512cd..1b5feff 100644 --- a/help/isint +++ b/help/isint @@ -14,10 +14,10 @@ DESCRIPTION integer, 0 otherwise. EXAMPLE - > print isint(2.0), isint(1), isint("0") + ; print isint(2.0), isint(1), isint("0") 1 1 0 - > print isint(2i), isint(1e20), isint(1/3) + ; print isint(2i), isint(1e20), isint(1/3) 0 1 0 LIMITS @@ -49,8 +49,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: isint,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: isint,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/isint,v $ ## ## Under source code control: 1994/10/21 02:21:27 diff --git a/help/islist b/help/islist index e1b149f..9d3cad7 100644 --- a/help/islist +++ b/help/islist @@ -14,8 +14,8 @@ DESCRIPTION a list, 0 otherwise. EXAMPLE - > lst = list(2,3,4) - > print islist(lst), islist(1) + ; lst = list(2,3,4) + ; print islist(lst), islist(1) 1 0 LIMITS @@ -48,8 +48,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: islist,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: islist,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/islist,v $ ## ## Under source code control: 1994/03/19 03:13:19 diff --git a/help/ismat b/help/ismat index c20b180..afb14e1 100644 --- a/help/ismat +++ b/help/ismat @@ -14,8 +14,8 @@ DESCRIPTION a matrix, 0 otherwise. EXAMPLE - > mat a[2] - > print ismat(a), ismat(1) + ; mat a[2] + ; print ismat(a), ismat(1) 1 0 LIMITS @@ -47,8 +47,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: ismat,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: ismat,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/ismat,v $ ## ## Under source code control: 1994/10/21 02:21:28 diff --git a/help/ismult b/help/ismult index 55c55fe..b4130b4 100644 --- a/help/ismult +++ b/help/ismult @@ -19,10 +19,10 @@ DESCRIPTION then return 1, otherwise return 0. EXAMPLE - > print ismult(6, 2), ismult(2, 6), ismult(7.5, 2.5) + ; print ismult(6, 2), ismult(2, 6), ismult(7.5, 2.5) 1 0 1 - > print ismult(4^67, 2^59), ismult(13, 4/67), ismult(13, 7/56) + ; print ismult(4^67, 2^59), ismult(13, 4/67), ismult(13, 7/56) 1 0 1 LIMITS @@ -54,8 +54,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: ismult,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: ismult,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/ismult,v $ ## ## Under source code control: 1994/10/21 02:21:28 diff --git a/help/isnull b/help/isnull index fabb320..c989e08 100644 --- a/help/isnull +++ b/help/isnull @@ -14,8 +14,8 @@ DESCRIPTION a null value, 0 otherwise. EXAMPLE - > mat a[2] - > print isnull(a), isnull(1) + ; mat a[2] + ; print isnull(a), isnull(1) 1 0 LIMITS @@ -46,8 +46,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: isnull,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: isnull,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/isnull,v $ ## ## Under source code control: 1994/10/21 02:21:28 diff --git a/help/isnum b/help/isnum index 201d90f..4ad8bd7 100644 --- a/help/isnum +++ b/help/isnum @@ -14,10 +14,10 @@ DESCRIPTION is a a numeric value, 0 otherwise. EXAMPLE - > print isnum(2.0), isnum(1), isnum("0") + ; print isnum(2.0), isnum(1), isnum("0") 1 1 0 - > print isnum(2i), isnum(1e20), isnum(1/3) + ; print isnum(2i), isnum(1e20), isnum(1/3) 1 1 1 LIMITS @@ -48,8 +48,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: isnum,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: isnum,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/isnum,v $ ## ## Under source code control: 1994/10/21 02:21:28 diff --git a/help/isobj b/help/isobj index 2707c32..0494b55 100644 --- a/help/isobj +++ b/help/isobj @@ -14,8 +14,8 @@ DESCRIPTION an object, 0 otherwise. EXAMPLE - > obj surd {a, b} a; - > print isobj(a), isobj(1) + ; obj surd {a, b} a; + ; print isobj(a), isobj(1) 1 0 LIMITS @@ -47,8 +47,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: isobj,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: isobj,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/isobj,v $ ## ## Under source code control: 1994/10/21 02:21:29 diff --git a/help/isobjtype b/help/isobjtype index f5476db..c38862e 100644 --- a/help/isobjtype +++ b/help/isobjtype @@ -14,11 +14,11 @@ DESCRIPTION str has been defined or not defined. EXAMPLE - > isobjtype("xy") + ; isobjtype("xy") 0 - > obj xy {x, y} - > isobjtype("xy") + ; obj xy {x, y} + ; isobjtype("xy") 1 LIMITS @@ -50,8 +50,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: isobjtype,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: isobjtype,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/isobjtype,v $ ## ## Under source code control: 1997/04/05 14:10:17 diff --git a/help/isodd b/help/isodd index 91f2aed..bfa9087 100644 --- a/help/isodd +++ b/help/isodd @@ -14,10 +14,10 @@ DESCRIPTION odd integer, 0 otherwise. EXAMPLE - > print isodd(2.0), isodd(1), isodd("1") + ; print isodd(2.0), isodd(1), isodd("1") 0 1 0 - > print isodd(2i), isodd(1e20+1), isodd(1/3) + ; print isodd(2i), isodd(1e20+1), isodd(1/3) 0 1 0 LIMITS @@ -48,8 +48,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: isodd,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: isodd,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/isodd,v $ ## ## Under source code control: 1994/10/21 02:21:29 diff --git a/help/isprime b/help/isprime index 45ad241..a31ce68 100644 --- a/help/isprime +++ b/help/isprime @@ -26,16 +26,16 @@ DESCRIPTION will be returned. EXAMPLE - > print isprime(-3), isprime(1), isprime(2) + ; print isprime(-3), isprime(1), isprime(2) 0 0 1 - > print isprime(21701), isprime(1234577), isprime(1234579) + ; print isprime(21701), isprime(1234577), isprime(1234579) 1 1 0 - > print isprime(2^31-9), isprime(2^31-1), isprime(2^31+11) + ; print isprime(2^31-9), isprime(2^31-1), isprime(2^31+11) 0 1 1 - > print isprime(2^32+1, -1), isprime(3^99, 2), isprime(4^99, 2) + ; print isprime(2^32+1, -1), isprime(3^99, 2), isprime(4^99, 2) -1 2 0 LIMITS @@ -67,8 +67,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: isprime,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: isprime,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/isprime,v $ ## ## Under source code control: 1994/10/21 02:21:29 diff --git a/help/isqrt b/help/isqrt index fdcdbdf..1ed0a78 100644 --- a/help/isqrt +++ b/help/isqrt @@ -13,7 +13,7 @@ DESCRIPTION Return the greatest integer n for which n^2 <= x. EXAMPLE - > print isqrt(8.5), isqrt(200), isqrt(2e6), isqrt(2e56) + ; print isqrt(8.5), isqrt(200), isqrt(2e6), isqrt(2e56) 2 14 1414 14142135623730950488016887242 LIMITS @@ -41,8 +41,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: isqrt,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: isqrt,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/isqrt,v $ ## ## Under source code control: 1995/10/25 04:03:45 diff --git a/help/isrand b/help/isrand index 1be4e86..fb357ae 100644 --- a/help/isrand +++ b/help/isrand @@ -14,8 +14,8 @@ DESCRIPTION This function will return 1 if x is a file, 0 otherwise. EXAMPLE - > a = srand(0) - > print isrand(a), isrand(0); + ; a = srand(0) + ; print isrand(a), isrand(0); 1 0 LIMITS @@ -47,8 +47,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: isrand,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: isrand,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/isrand,v $ ## ## Under source code control: 1995/11/11 05:09:41 diff --git a/help/israndom b/help/israndom index cd64cee..c877a23 100644 --- a/help/israndom +++ b/help/israndom @@ -16,8 +16,8 @@ DESCRIPTION XXX - the interface to the Blum generator has not been not written. EXAMPLE - > a = srandom(0) - > print israndom(a), israndom(0); + ; a = srandom(0) + ; print israndom(a), israndom(0); 1 0 LIMITS @@ -49,8 +49,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: israndom,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: israndom,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/israndom,v $ ## ## Under source code control: 1995/11/11 05:09:41 diff --git a/help/isreal b/help/isreal index 6ad0905..39e1b15 100644 --- a/help/isreal +++ b/help/isreal @@ -14,10 +14,10 @@ DESCRIPTION is a real value, 0 otherwise. EXAMPLE - > print isreal(2.0), isreal(1), isreal("0") + ; print isreal(2.0), isreal(1), isreal("0") 1 1 0 - > print isreal(2i), isreal(1e20), isreal(1/3) + ; print isreal(2i), isreal(1e20), isreal(1/3) 0 1 1 LIMITS @@ -48,8 +48,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: isreal,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: isreal,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/isreal,v $ ## ## Under source code control: 1994/10/21 02:21:30 diff --git a/help/isrel b/help/isrel index e53cb6b..b7c09fb 100644 --- a/help/isrel +++ b/help/isrel @@ -15,10 +15,10 @@ DESCRIPTION return 1, otherwise return 0. EXAMPLE - > print isrel(6, 5), isrel(5, 6), isrel(-5, 6) + ; print isrel(6, 5), isrel(5, 6), isrel(-5, 6) 1 1 1 - > print isrel(6, 2), isrel(2, 6), isrel(-2, 6) + ; print isrel(6, 2), isrel(2, 6), isrel(-2, 6) 0 0 0 LIMITS @@ -50,8 +50,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: isrel,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: isrel,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/isrel,v $ ## ## Under source code control: 1994/10/21 02:21:30 diff --git a/help/issimple b/help/issimple index de3ff43..71697a2 100644 --- a/help/issimple +++ b/help/issimple @@ -15,17 +15,17 @@ DESCRIPTION complex numbers, strings and null values. EXAMPLE - > print issimple(2.0), issimple(1), issimple("0") + ; print issimple(2.0), issimple(1), issimple("0") 1 1 1 - > print issimple(2i), issimple(1e20), issimple(1/3), issimple(null()) + ; print issimple(2i), issimple(1e20), issimple(1/3), issimple(null()) 1 1 1 1 - > mat a[2] - > b = list(1,2,3) - > c = assoc() - > obj chongo {was, here} d; - > print issimple(a), issimple(b), issimple(c), issimple(d) + ; mat a[2] + ; b = list(1,2,3) + ; c = assoc() + ; obj chongo {was, here} d; + ; print issimple(a), issimple(b), issimple(c), issimple(d) 0 0 0 0 LIMITS @@ -56,8 +56,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: issimple,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: issimple,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/issimple,v $ ## ## Under source code control: 1994/10/21 02:21:30 diff --git a/help/issq b/help/issq index 37e459e..1f7383b 100644 --- a/help/issq +++ b/help/issq @@ -17,10 +17,10 @@ DESCRIPTION return 1, otherwise return 0. EXAMPLE - > print issq(25), issq(3), issq(0) + ; print issq(25), issq(3), issq(0) 1 0 1 - > print issq(4/25), issq(-4/25), issq(pi()) + ; print issq(4/25), issq(-4/25), issq(pi()) 1 0 0 LIMITS @@ -52,8 +52,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: issq,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: issq,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/issq,v $ ## ## Under source code control: 1994/10/21 02:21:31 diff --git a/help/isstr b/help/isstr index 77f95e0..09ebd23 100644 --- a/help/isstr +++ b/help/isstr @@ -14,7 +14,7 @@ DESCRIPTION a string, 0 otherwise. EXAMPLE - > print isstr("1"), isstr(1), isstr("") + ; print isstr("1"), isstr(1), isstr("") 1 0 1 LIMITS @@ -45,8 +45,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: isstr,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: isstr,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/isstr,v $ ## ## Under source code control: 1994/10/21 02:21:31 diff --git a/help/istype b/help/istype index f6a249d..bc882bc 100644 --- a/help/istype +++ b/help/istype @@ -15,17 +15,17 @@ DESCRIPTION if x and y are of the same type, 0 otherwise. EXAMPLE - > print istype(2, 3), istype(2, 3.0), istype(2, 2.3) + ; print istype(2, 3), istype(2, 3.0), istype(2, 2.3) 1 1 1 - > print istype(2, 3i), istype(2, "2"), istype(2, null()) + ; print istype(2, 3i), istype(2, "2"), istype(2, null()) 0 0 0 - > mat a[2] - > b = list(1,2,3) - > c = assoc() - > obj chongo {was, here} d; - > print istype(a,b), istype(b,c), istype(c,d) + ; mat a[2] + ; b = list(1,2,3) + ; c = assoc() + ; obj chongo {was, here} d; + ; print istype(a,b), istype(b,c), istype(c,d) 0 0 0 LIMITS @@ -56,8 +56,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: istype,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: istype,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/istype,v $ ## ## Under source code control: 1994/10/21 02:21:31 diff --git a/help/jacobi b/help/jacobi index eb35a88..cbed8ca 100644 --- a/help/jacobi +++ b/help/jacobi @@ -46,10 +46,10 @@ DESCRIPTION the value 0. EXAMPLE - > print jacobi(2,3), jacobi(2,5), jacobi(2,15) + ; print jacobi(2,3), jacobi(2,5), jacobi(2,15) -1 -1 1 - > print jacobi(80,199) + ; print jacobi(80,199) 1 LIMITS @@ -77,8 +77,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: jacobi,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: jacobi,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/jacobi,v $ ## ## Under source code control: 1995/12/18 12:34:57 diff --git a/help/join b/help/join index e103088..51b823a 100644 --- a/help/join +++ b/help/join @@ -18,9 +18,9 @@ DESCRIPTION If any argument is not a list, a null value is returned. EXAMPLE - > A = list(1, 2, 3) - > B = list(4, 5) - > join(A, B) + ; A = list(1, 2, 3) + ; B = list(4, 5) + ; join(A, B) list (5 elements, 5 nonzero): [[0]] = 1 @@ -54,8 +54,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: join,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: join,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/join,v $ ## ## Under source code control: 1995/07/09 19:41:40 diff --git a/help/lcm b/help/lcm index b7e2a7e..c7cf33e 100644 --- a/help/lcm +++ b/help/lcm @@ -17,7 +17,7 @@ DESCRIPTION the lcm is zero. EXAMPLE - > print lcm(12, -24, 30), lcm(9/10, 11/5, 4/25), lcm(2) + ; print lcm(12, -24, 30), lcm(9/10, 11/5, 4/25), lcm(2) -120 79.2 2 LIMITS @@ -45,8 +45,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: lcm,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: lcm,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/lcm,v $ ## ## Under source code control: 1995/10/05 04:52:26 diff --git a/help/lcmfact b/help/lcmfact index 0a4514f..23f5ef2 100644 --- a/help/lcmfact +++ b/help/lcmfact @@ -13,7 +13,7 @@ DESCRIPTION Returns the lcm of the integers 1, 2, ..., n. EXAMPLE - > for (i = 1; i <= 15; i++) print lcmfact(i),:; + ; for (i = 1; i <= 15; i++) print lcmfact(i),:; 1 2 6 12 60 60 420 840 2520 2520 27720 27720 360360 360360 360360 LIMITS @@ -42,8 +42,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: lcmfact,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: lcmfact,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/lcmfact,v $ ## ## Under source code control: 1995/12/18 12:34:57 diff --git a/help/lfactor b/help/lfactor index 792f462..4fd804b 100644 --- a/help/lfactor +++ b/help/lfactor @@ -17,10 +17,10 @@ DESCRIPTION If n < 0, -1 is returned. EXAMPLE - > print lfactor(35,2), lfactor(35,3), lfactor(-35, 3) + ; print lfactor(35,2), lfactor(35,3), lfactor(-35, 3) 1 5 -1 - > print lfactor(2^32+1,115), lfactor(2^32+1,116), lfactor(2^59-1,1e5) + ; print lfactor(2^32+1,115), lfactor(2^32+1,116), lfactor(2^59-1,1e5) 1 641 179951 LIMITS @@ -49,8 +49,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: lfactor,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: lfactor,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/lfactor,v $ ## ## Under source code control: 1995/12/18 12:34:57 diff --git a/help/list b/help/list index 42297bc..3e846b3 100644 --- a/help/list +++ b/help/list @@ -57,14 +57,14 @@ DESCRIPTION the list. EXAMPLE - > list(2,"three",4i) + ; list(2,"three",4i) list (3 elements, 3 nonzero): [[0]] = 2 [[1]] = "three" [[2]] = 4i - > list() + ; list() list (0 elements, 0 nonzero) LIMITS @@ -92,8 +92,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: list,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: list,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/list,v $ ## ## Under source code control: 1994/03/19 03:13:19 diff --git a/help/ln b/help/ln index 0be4f57..4bed91f 100644 --- a/help/ln +++ b/help/ln @@ -17,10 +17,10 @@ DESCRIPTION to the n-th decimal place. EXAMPLE - > print ln(10, 1e-5), ln(10, 1e-10), ln(10, 1e-15), ln(10, 1e-20) + ; print ln(10, 1e-5), ln(10, 1e-10), ln(10, 1e-15), ln(10, 1e-20) 2.30259 2.302585093 2.302585092994046 2.30258509299404568402 - > print ln(2+3i, 1e-5), ln(2+3i, 1e-10) + ; print ln(2+3i, 1e-5), ln(2+3i, 1e-10) 1.28247+.98279i 1.2824746787+.9827937232i LIMITS @@ -32,7 +32,7 @@ LINK LIBRARY COMPLEX *c_ln(COMPLEX *x, NUMBER *eps) SEE ALSO - exp, acosh, asinh, atanh + exp, acosh, asinh, atanh, log ## Copyright (C) 1999 Landon Curt Noll ## @@ -50,8 +50,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.3 $ -## @(#) $Id: ln,v 29.3 2005/10/18 10:48:29 chongo Exp $ +## @(#) $Revision: 29.5 $ +## @(#) $Id: ln,v 29.5 2006/05/07 13:05:18 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/ln,v $ ## ## Under source code control: 1995/10/11 04:41:26 diff --git a/help/log b/help/log new file mode 100644 index 0000000..9e0bb6a --- /dev/null +++ b/help/log @@ -0,0 +1,64 @@ +NAME + log - base 10 logarithm + +SYNOPSIS + log(x [,eps]) + +TYPES + x nonzero real or complex + eps nonzero real, defaults to epsilon() + + return real or complex + +DESCRIPTION + Approximate the base 10 logarithm function of x by a multiple of + epsilon, the error having absolute value less than 0.75 * eps. + If n is a positive integer, log(x, 10^-n) will usually be correct + to the n-th decimal place. + +EXAMPLE + ; print log(10), log(100), log(1e10), log(1e500) + 1 2 10 500 + + ; print log(128), log(23209), log(2^17-19) + ~2.10720996964786836649 ~4.36565642852838930424 ~5.11744696704937330414 + + ; print log(2+3i, 1e-5) + ~0.55696845725899964822+~0.42681936428109216144i + +LIMITS + x != 0 + eps > 0 + +LINK LIBRARY + NUMBER *qlog(NUMBER *x, NUMBER *eps) + COMPLEX *c_log(COMPLEX *x, NUMBER *eps) + +SEE ALSO + ln + +## Copyright (C) 2006 Landon Curt Noll +## +## Calc is open software; you can redistribute it and/or modify it under +## the terms of the version 2.1 of the GNU Lesser General Public License +## as published by the Free Software Foundation. +## +## Calc is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General +## Public License for more details. +## +## A copy of version 2.1 of the GNU Lesser General Public License is +## distributed with calc under the filename COPYING-LGPL. You should have +## 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.1 $ +## @(#) $Id: log,v 29.1 2006/05/07 12:59:00 chongo Exp $ +## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/log,v $ +## +## Under source code control: 2006/05/06 23:56:04 +## File existed as early as: 2006 +## +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/lowbit b/help/lowbit index 7914a64..caba41b 100644 --- a/help/lowbit +++ b/help/lowbit @@ -16,7 +16,7 @@ DESCRIPTION the binary representation of x then ends with n zero bits. EXAMPLE - > print lowbit(2), lowbit(3), lowbit(4), lowbit(-15), lowbit(2^27) + ; print lowbit(2), lowbit(3), lowbit(4), lowbit(-15), lowbit(2^27) 1 0 2 0 27 LIMITS @@ -44,8 +44,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: lowbit,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: lowbit,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/lowbit,v $ ## ## Under source code control: 1995/10/03 10:40:02 diff --git a/help/ltol b/help/ltol index d20e12b..d034962 100644 --- a/help/ltol +++ b/help/ltol @@ -16,7 +16,7 @@ DESCRIPTION The default value for eps is epsilon(). EXAMPLE - > print ltol(0.4, 1e-6), hypot(0.5, 1e-6) + ; print ltol(0.4, 1e-6), hypot(0.5, 1e-6) .6 .866025 LIMITS @@ -44,8 +44,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: ltol,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: ltol,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/ltol,v $ ## ## Under source code control: 1995/10/05 04:52:27 diff --git a/help/makelist b/help/makelist index 85a070a..692fbaa 100644 --- a/help/makelist +++ b/help/makelist @@ -14,8 +14,8 @@ DESCRIPTION all members of which have null value. EXAMPLE - > A = makelist(4) - > A + ; A = makelist(4) + ; A list (4 members, 4 nonzero): [[0]] = NULL @@ -48,8 +48,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: makelist,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: makelist,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/makelist,v $ ## ## Under source code control: 1995/07/10 02:09:31 diff --git a/help/matdim b/help/matdim index 137c704..df4b75d 100644 --- a/help/matdim +++ b/help/matdim @@ -13,8 +13,8 @@ DESCRIPTION Returns the number of indices required to specify elements of the matrix. EXAMPLE - > mat A[3]; mat B[2,3]; mat C[1, 2:3, 4]; mat D[2, 3, 4, 5] - > print matdim(A), matdim(B), matdim(C), matdim(D) + ; mat A[3]; mat B[2,3]; mat C[1, 2:3, 4]; mat D[2, 3, 4, 5] + ; print matdim(A), matdim(B), matdim(C), matdim(D) 1 2 3 4 LIMITS @@ -42,8 +42,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: matdim,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: matdim,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/matdim,v $ ## ## Under source code control: 1995/10/25 04:03:45 diff --git a/help/matfill b/help/matfill index 70f8008..a3e051b 100644 --- a/help/matfill +++ b/help/matfill @@ -17,13 +17,13 @@ DESCRIPTION x to the off-diagonal elements, y to the diagonal elements. EXAMPLE - > mat A[3]; matfill(A, 2); print A + ; mat A[3]; matfill(A, 2); print A mat [3] (3 elements, 3 nonzero): [0] = 2 [1] = 2 [2] = 2 - > mat B[2, 1:2]; matfill(B,3,4); print B + ; mat B[2, 1:2]; matfill(B,3,4); print B mat [2,1:2] (4 elements, 4 nonzero): [0,1] = 4 [0,2] = 3 @@ -55,8 +55,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: matfill,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: matfill,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/matfill,v $ ## ## Under source code control: 1995/10/25 04:03:45 diff --git a/help/matmax b/help/matmax index bb3ed4a..090f090 100644 --- a/help/matmax +++ b/help/matmax @@ -15,8 +15,8 @@ DESCRIPTION for the matrix m. EXAMPLE - > mat A[3]; mat B[1:3, -4:4, 5] - > print matmax(A,0), matmax(B,0), matmax(B,1), matmax(B,2) + ; mat A[3]; mat B[1:3, -4:4, 5] + ; print matmax(A,0), matmax(B,0), matmax(B,1), matmax(B,2) 2 3 4 4 LIMITS @@ -44,8 +44,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: matmax,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: matmax,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/matmax,v $ ## ## Under source code control: 1995/10/25 04:03:45 diff --git a/help/matmin b/help/matmin index ddbc4b1..a906cb5 100644 --- a/help/matmin +++ b/help/matmin @@ -15,8 +15,8 @@ DESCRIPTION for the matrix m. EXAMPLE - > mat A[3]; mat B[1:3, -4:4, 5] - > print matmin(A,0), matmin(B,0), matmin(B,1), matmin(B,2) + ; mat A[3]; mat B[1:3, -4:4, 5] + ; print matmin(A,0), matmin(B,0), matmin(B,1), matmin(B,2) 0 1 -4 0 LIMITS @@ -44,8 +44,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: matmin,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: matmin,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/matmin,v $ ## ## Under source code control: 1995/10/25 04:03:45 diff --git a/help/matsum b/help/matsum index e34bbda..06ef5a3 100644 --- a/help/matsum +++ b/help/matsum @@ -14,7 +14,7 @@ DESCRIPTION Non-numeric elements are ignored. EXAMPLE - > mat A[2,2] = {1, 2, 3, list(1,2,3)} + ; mat A[2,2] = {1, 2, 3, list(1,2,3)} print matsum(A) 6 @@ -43,8 +43,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: matsum,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: matsum,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/matsum,v $ ## ## Under source code control: 1995/10/25 04:03:46 diff --git a/help/mattrace b/help/mattrace index 4d229f9..6cf27da 100644 --- a/help/mattrace +++ b/help/mattrace @@ -17,8 +17,8 @@ DESCRIPTION m[0,0] + m{1,1] + ... + m[N-1,N-1] EXAMPLE - > mat m[2,2] = {1,2,3,4} - > print mattrace(m), mattrace(m^2) + ; mat m[2,2] = {1,2,3,4} + ; print mattrace(m), mattrace(m^2) 5 29 LIMITS @@ -46,8 +46,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: mattrace,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: mattrace,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/mattrace,v $ ## ## Under source code control: 1997/09/06 20:03:35 diff --git a/help/mattrans b/help/mattrans index 1f20e1b..834c549 100644 --- a/help/mattrans +++ b/help/mattrans @@ -13,8 +13,8 @@ DESCRIPTION Returns the matrix whose [i,j] element is the [j,1] element of m. EXAMPLE - > mat A[2, 1:3] = {1,2,3,4,5,6} - > print mattrans(A) + ; mat A[2, 1:3] = {1,2,3,4,5,6} + ; print mattrans(A) mat [1:3,2] (6 elements, 6 nonzero): [1,0] = 1 @@ -49,8 +49,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: mattrans,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: mattrans,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/mattrans,v $ ## ## Under source code control: 1995/10/25 04:03:46 diff --git a/help/max b/help/max index 43f0eb3..f7ad80e 100644 --- a/help/max +++ b/help/max @@ -40,25 +40,25 @@ DESCRIPTION other relations, it may be difficult to predict the result. EXAMPLE - > print max(2), max(5, 3, 7, 2, 9), max(3.2, -0.5, 8.7, -1.2, 2.5) + ; print max(2), max(5, 3, 7, 2, 9), max(3.2, -0.5, 8.7, -1.2, 2.5) 2 9 8.7 - > print max(list(3,5), 7, list(6, list(7,8), 2)) + ; print max(list(3,5), 7, list(6, list(7,8), 2)) 8 - > print max("one", "two", "three", "four") + ; print max("one", "two", "three", "four") two - > obj point {x, y} - > define point_rel(a,b) = sgn(a.x - b.x) - > obj point A = {1, 5} - > obj point B = {1, 4} - > obj point C = {3, 3} - > print max(A, B, C) + ; obj point {x, y} + ; define point_rel(a,b) = sgn(a.x - b.x) + ; obj point A = {1, 5} + ; obj point B = {1, 4} + ; obj point C = {3, 3} + ; print max(A, B, C) obj point {3, 3} - > define point_max(a) = a.x - > print max(A, B, C) + ; define point_max(a) = a.x + ; print max(A, B, C) 3 LIMITS @@ -86,8 +86,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: max,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: max,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/max,v $ ## ## Under source code control: 1995/10/05 04:52:27 diff --git a/help/md5 b/help/md5 index 1dabfaf..c5b33fd 100644 --- a/help/md5 +++ b/help/md5 @@ -49,35 +49,35 @@ DESCRIPTION MD5 Message-Digest Algorithm". EXAMPLE - > base(16) + ; base(16) 0xa - > md5() + ; md5() md5 hash state - > md5(md5()) + ; md5(md5()) 0xd41d8cd98f00b204e9800998ecf8427e - > md5("x", "y", "z") == md5("xyz") + ; md5("x", "y", "z") == md5("xyz") 1 - > md5("x", "y", "z") == md5("xy") + ; md5("x", "y", "z") == md5("xy") 0 - > md5(md5("this is", 7^19-8, "a composit", 3i+4.5, "hash")) + ; md5(md5("this is", 7^19-8, "a composit", 3i+4.5, "hash")) 0x5a90d942335b0dbbdce38d90e7cb6dac - > x = md5(list(1,2,3), "curds and whey", 2^21701-1, pi()) - > x + ; x = md5(list(1,2,3), "curds and whey", 2^21701-1, pi()) + ; x md5 hash state - > md5(x) + ; md5(x) 0x88790b3ea9eb0128134c103ac9b683ed - > y = md5() - > y = md5(y, list(1,2,3), "curds and whey") - > y = md5(y, 2^21701-1) - > y = md5(y, pi()) - > y + ; y = md5() + ; y = md5(y, list(1,2,3), "curds and whey") + ; y = md5(y, 2^21701-1) + ; y = md5(y, pi()) + ; y md5 hash state - > md5(y) + ; md5(y) 0x88790b3ea9eb0128134c103ac9b683ed LIMITS @@ -117,8 +117,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: md5,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: md5,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/md5,v $ ## ## Under source code control: 1997/04/06 19:45:54 diff --git a/help/memsize b/help/memsize index c302114..97a4277 100644 --- a/help/memsize +++ b/help/memsize @@ -55,30 +55,30 @@ EXAMPLES the system being used. The following were for an SGI R4k machine in 32-bit mode: - > print memsize(null()) + ; print memsize(null()) 8 - > print memsize(0), memsize(3), memsize(2^32 - 1), memsize(2^32) + ; print memsize(0), memsize(3), memsize(2^32 - 1), memsize(2^32) 68 68 68 72 - > x = sqrt(2, 1e-100); print memsize(x), memsize(num(x)), memsize(den(x)) + ; x = sqrt(2, 1e-100); print memsize(x), memsize(num(x)), memsize(den(x)) 148 108 108 - > print memsize(list()), memsize(list(1)), memsize(list(1,2)) + ; print memsize(list()), memsize(list(1)), memsize(list(1,2)) 28 104 180 - > print memsize(list()) + ; print memsize(list()) 28 - > print ,memsize(list(1)),memsize(list(1,2)),memsize(list(1,2,3)) + ; print ,memsize(list(1)),memsize(list(1,2)),memsize(list(1,2,3)) 104 180 256 - > mat A[] = {1}; mat B[] = {1,2}; mat C[] = {1,2,3}; mat D[100,100]; - > print memsize(A), memsize(B), memsize(C), memsize(D) + ; mat A[] = {1}; mat B[] = {1,2}; mat C[] = {1,2,3}; mat D[100,100]; + ; print memsize(A), memsize(B), memsize(C), memsize(D) 124 192 260 680056 - > obj point {x,y,z} - > obj point P = {1,2,3}; print memsize(P) + ; obj point {x,y,z} + ; obj point P = {1,2,3}; print memsize(P) 274 LIMITS @@ -106,8 +106,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: memsize,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: memsize,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/memsize,v $ ## ## Under source code control: 1997/03/23 20:28:02 diff --git a/help/meq b/help/meq index 0b3afe0..ef6ab7c 100644 --- a/help/meq +++ b/help/meq @@ -20,7 +20,7 @@ DESCRIPTION For any x, y, md, meq(x, y, md) = ismult(x - y, md). EXAMPLE - > print meq(5, 33, 7), meq(.05, .33, -.07), meq(5, 32, 7) + ; print meq(5, 33, 7), meq(.05, .33, -.07), meq(5, 32, 7) 1 1 0 LIMITS @@ -48,8 +48,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: meq,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: meq,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/meq,v $ ## ## Under source code control: 1995/11/09 03:27:51 diff --git a/help/min b/help/min index 4ba4571..d163cf8 100644 --- a/help/min +++ b/help/min @@ -40,25 +40,25 @@ DESCRIPTION relations, it may be difficult to predict the result. EXAMPLE - > print min(2), min(5, 3, 7, 2, 9), min(3.2, -0.5, 8.7, -1.2, 2.5) + ; print min(2), min(5, 3, 7, 2, 9), min(3.2, -0.5, 8.7, -1.2, 2.5) 2 2 -1.2 - > print min(list(3,5), 7, list(6, list(7,8), 2)) + ; print min(list(3,5), 7, list(6, list(7,8), 2)) 2 - > print min("one", "two", "three", "four") + ; print min("one", "two", "three", "four") four - > obj point {x, y} - > define point_rel(a,b) = sgn(a.x - b.x) - > obj point A = {1, 5} - > obj point B = {1, 4} - > obj point C = {3, 3} - > print min(A, B, C) + ; obj point {x, y} + ; define point_rel(a,b) = sgn(a.x - b.x) + ; obj point A = {1, 5} + ; obj point B = {1, 4} + ; obj point C = {3, 3} + ; print min(A, B, C) obj point {1, 5} - > define point_min(a) = a.x - > print min(A, B, C) + ; define point_min(a) = a.x + ; print min(A, B, C) 1 LIMITS @@ -86,8 +86,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: min,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: min,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/min,v $ ## ## Under source code control: 1995/10/05 04:52:27 diff --git a/help/minv b/help/minv index 8e1f5a7..c057c59 100644 --- a/help/minv +++ b/help/minv @@ -29,12 +29,12 @@ DESCRIPTION 21 -md/2 <= v < md/2 md/2 <= v < -md/2 EXAMPLE - > c = config("mod", 0) - > print minv(3,10), minv(-3,10), minv(3,-10), minv(-3,-10), minv(4,10) + ; c = config("mod", 0) + ; print minv(3,10), minv(-3,10), minv(3,-10), minv(-3,-10), minv(4,10) 7 3 -3 -7 0 - > c = config("mod",16) - > print minv(3,10), minv(-3,10), minv(3,-10), minv(-3,-10), minv(4,10) + ; c = config("mod",16) + ; print minv(3,10), minv(-3,10), minv(3,-10), minv(-3,-10), minv(4,10) -3 3 -3 3 0 LIMITS @@ -62,8 +62,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: minv,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: minv,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/minv,v $ ## ## Under source code control: 1995/11/09 03:27:51 diff --git a/help/mmin b/help/mmin index 6dff0e9..ed3c71c 100644 --- a/help/mmin +++ b/help/mmin @@ -21,10 +21,10 @@ DESCRIPTION all x and md, mmin(x, md) returns the same as mod(x, md, 16). EXAMPLE - > print mmin(3,6), mmin(4,6), mmin(5,6), mmin(6,6), mmin(7,6) + ; print mmin(3,6), mmin(4,6), mmin(5,6), mmin(6,6), mmin(7,6) 3 -2 -1 0 1 - > print mmin(1.25, 2.5), mmin(-1.25,2.5), mmin(1.25, -2.5) + ; print mmin(1.25, 2.5), mmin(-1.25,2.5), mmin(1.25, -2.5) 1.25 1.25 -1.25 LIMITS @@ -52,8 +52,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: mmin,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: mmin,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/mmin,v $ ## ## Under source code control: 1995/12/18 03:30:59 diff --git a/help/mod b/help/mod index f0ff7cd..a10b130 100644 --- a/help/mod +++ b/help/mod @@ -85,14 +85,14 @@ DESCRIPTION integers modulo an integer y. EXAMPLE - > print mod(11,5,0), mod(11,5,1), mod(-11,5,2), mod(-11,-5,3) + ; print mod(11,5,0), mod(11,5,1), mod(-11,5,2), mod(-11,-5,3) 1 -4 -1 4 - > print mod(12.5,5,16), mod(12.5,5,17), mod(12.5,5,24), mod(-7.5,-5,24) + ; print mod(12.5,5,16), mod(12.5,5,17), mod(12.5,5,24), mod(-7.5,-5,24) 2.5 -2.5 2.5 2.5 - > A = list(11,13,17,23,29) - > print mod(A,10,0) + ; A = list(11,13,17,23,29) + ; print mod(A,10,0) list (5 elements, 5 nonzero): [[0]] = 1 @@ -127,8 +127,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: mod,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: mod,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/mod,v $ ## ## Under source code control: 1995/09/18 02:09:31 diff --git a/help/modify b/help/modify index c07dc16..57c4f5c 100644 --- a/help/modify +++ b/help/modify @@ -2,29 +2,43 @@ NAME modify - modify a list or matrix by changing the values of its elements SYNOPSIS - modify(x, y) + modify(A, fname) TYPES - x lvalue with list or matrix value - y string + A lvalue with list, matrix or objectvalue + fname string, the name of a user-defined function - return null value + return null value if successful, otherwise an error value DESCRIPTION - For modify(x, y), y is to be the name fname of a user-defined function. - The value of each element of x is replaced by the value of the - function at that value, i.e. if fname = "f", the value of x[[i]] - is changed to f(x[[i]]). + The value of each element of A is replaced by the value at that + value of the user-defined function with name fname. Thus, + modify(A, "f") has the effect of - As the name indicates, modify(x) usually changes x values of elements - in x. To obtain a modified copy of x without changing values in x, - one may xmod = x; modify(xmod, y) or more simply (xmod = x, y). + for (i = 0; i < size(A); i++) A[[i]] = f(A[[i]]); + + An error value is returned if A is not of acceptable type, if A has + no-change protection, or if there is no user-defined function with + name fname. The assignments are executed even if the protection + status of some elements A[[i]] would normally prevent the + assignment of f(A[[i]]) to A[[i]]. The modified elements retain + whatever kinds of protection they had as well as gaining any + other kinds of protection in the values returned by the function. + + To obtain a modified copy of A without changing values in A, + one may use + + Amod = A; modify(A, fname) + + or more simply + + modify(Amod = A, fname). EXAMPLE - > define f(x) = x^2 - > A = list(2,4,6) - > modify(A, "f") - > print A + ; define f(x) = x^2 + ; A = list(2,4,6) + ; modify(A, "f") + ; print A list (3 elements, 3 nonzero): [[0]] = 4 @@ -56,8 +70,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: modify,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.4 $ +## @(#) $Id: modify,v 29.4 2006/05/19 15:12:57 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/modify,v $ ## ## Under source code control: 1995/07/10 02:09:31 diff --git a/help/name b/help/name index cf10e12..a239c5b 100644 --- a/help/name +++ b/help/name @@ -18,15 +18,15 @@ DESCRIPTION and "./foo". EXAMPLE - > A = blk("alpha"); - > name(A) + ; A = blk("alpha"); + ; name(A) "alpha" - > f = fopen("/tmp/beta", "w") - > name(f) + ; f = fopen("/tmp/beta", "w") + ; name(f) "/tmp/beta" - > names(files(0)) + ; names(files(0)) "(stdin)" LIMITS @@ -54,8 +54,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: name,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: name,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/name,v $ ## ## Under source code control: 1997/04/05 14:12:44 diff --git a/help/near b/help/near index 7ed558d..93414f7 100644 --- a/help/near +++ b/help/near @@ -18,7 +18,7 @@ DESCRIPTION 1 if abs(x - y) > abs(eps) EXAMPLE - > print near(22/7, 3.15, .01), near(22/7, 3.15, .005) + ; print near(22/7, 3.15, .01), near(22/7, 3.15, .005) -1 1 LIMITS @@ -46,8 +46,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: near,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: near,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/near,v $ ## ## Under source code control: 1995/10/25 04:03:46 diff --git a/help/newerror b/help/newerror index c3fc520..f602fcb 100644 --- a/help/newerror +++ b/help/newerror @@ -26,24 +26,24 @@ EXAMPLE Note that by default, errmax() is 0 so unless errmax() is increased you will get: - > ba = newerror("curds n' whey"); + ; ba = newerror("curds n' whey"); Error 20000 caused errcount to exceed errmax - > errmax(errcount()+5) + ; errmax(errcount()+5) 0 - > e1 = newerror("triangle side length <= 0") - > iserror(e1) + ; e1 = newerror("triangle side length <= 0") + ; iserror(e1) 20000 - > error(20000) + ; error(20000) Error 20000 - > strerror(error(20000)) + ; strerror(error(20000)) "triangle side length <= 0" - > strerror(e1); + ; strerror(e1); "triangle side length <= 0" - > strerror(error(iserror(e1))) + ; strerror(error(iserror(e1))) "triangle side length <= 0" - > define area(a,b,c) { + ; define area(a,b,c) { >> local s; >> if (!(a > 0) || !(b > 0) || !(c > 0)) return e1; >> s = (a + b + c)/2; @@ -52,12 +52,12 @@ EXAMPLE >> } "area" defined - > A = area(8,2,5); - > if (iserror(A)) print strerror(A) : ":", iserror(A); + ; A = area(8,2,5); + ; if (iserror(A)) print strerror(A) : ":", iserror(A); Non-triangle sides: 20001 - > A = area(-3,4,5) - > if (iserror(A)) print strerror(A) : ":", iserror(A); + ; A = area(-3,4,5) + ; if (iserror(A)) print strerror(A) : ":", iserror(A); triangle side length <= 0: 20000 LIMITS @@ -67,9 +67,10 @@ LINK LIBRARY none SEE ALSO - errmax, errcount, error, strerror, iserror, errno, errorcodes + errmax, errcount, error, strerror, iserror, errno, errorcodes, + stoponerror -## Copyright (C) 1999 Landon Curt Noll +## Copyright (C) 1999-2006 Landon Curt Noll ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License @@ -85,8 +86,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: newerror,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.4 $ +## @(#) $Id: newerror,v 29.4 2006/05/21 07:31:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/newerror,v $ ## ## Under source code control: 1996/04/30 03:39:56 diff --git a/help/nextcand b/help/nextcand index a8b9bde..04be839 100644 --- a/help/nextcand +++ b/help/nextcand @@ -54,16 +54,16 @@ RUNTIME to be roughly K/N^3 some constant K. EXAMPLE - > print nextcand(50), nextcand(112140,-2), nextcand(112140,-3) + ; print nextcand(50), nextcand(112140,-2), nextcand(112140,-3) 53 112141 112153 - > print nextcand(100,1,1,1,6), nextcand(100,1,1,-1,6) + ; print nextcand(100,1,1,1,6), nextcand(100,1,1,-1,6) 103 101 - > print nextcand(100,1,1,2,6), nextcand(100,1,1,303,202) + ; print nextcand(100,1,1,2,6), nextcand(100,1,1,303,202) 1 101 - > print nextcand(2e60, 1, 1, 31, 1e30) + ; print nextcand(2e60, 1, 1, 31, 1e30) 2000000000000000000000000000053000000000000000000000000000031 LIMITS @@ -92,8 +92,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: nextcand,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: nextcand,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/nextcand,v $ ## ## Under source code control: 1996/02/25 00:27:43 diff --git a/help/nextprime b/help/nextprime index 0cdc369..0b6f7a8 100644 --- a/help/nextprime +++ b/help/nextprime @@ -20,10 +20,10 @@ DESCRIPTION Other cases cause a runtime error. EXAMPLE - > print nextprime(10), nextprime(100), nextprime(1e6) + ; print nextprime(10), nextprime(100), nextprime(1e6) 11 101 1000003 - > print nextprime(3/2,-99), nextprime(2^32-1,-99), nextprime(2^32,-99) + ; print nextprime(3/2,-99), nextprime(2^32-1,-99), nextprime(2^32,-99) -99 4294967311 -99 LIMITS @@ -51,8 +51,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: nextprime,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: nextprime,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/nextprime,v $ ## ## Under source code control: 1995/12/18 12:34:57 diff --git a/help/norm b/help/norm index 6402c3d..8675375 100644 --- a/help/norm +++ b/help/norm @@ -24,7 +24,7 @@ DESCRIPTION re(x)^2 + im(x)^2. EXAMPLE - > print norm(3.4), norm(-3.4), norm(3 + 4i), norm(4 - 5i) + ; print norm(3.4), norm(-3.4), norm(3 + 4i), norm(4 - 5i) 11.56 11.56 25 41 LIMITS @@ -52,8 +52,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: norm,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: norm,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/norm,v $ ## ## Under source code control: 1995/10/25 04:03:46 diff --git a/help/null b/help/null index 5887b15..21e289a 100644 --- a/help/null +++ b/help/null @@ -43,15 +43,15 @@ DESCRIPTION without printing the current mode or changing the stored oldvalue. EXAMPLE - > L = list(-1,0,1,2); - > while (!isnull(x = pop(L)) print x,; print + ; L = list(-1,0,1,2); + ; while (!isnull(x = pop(L)) print x,; print -1 0 1 2 - > printf("%d %d %d\n", 2, , 3); + ; printf("%d %d %d\n", 2, , 3); 2 3 - > L = list(,1,,2,) - > print L + ; L = list(,1,,2,) + ; print L list (5 elements, 5 nonzero): [[0]] = NULL @@ -60,9 +60,9 @@ EXAMPLE [[3]] = 2 [[4]] = NULL - > a = 27 - > null(pi = pi(1e-1000)) - > . + ; a = 27 + ; null(pi = pi(1e-1000)) + ; . 27 LIMITS @@ -90,8 +90,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: null,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: null,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/null,v $ ## ## Under source code control: 1996/03/12 23:10:01 diff --git a/help/num b/help/num index 7ec05b2..fee01ea 100644 --- a/help/num +++ b/help/num @@ -25,7 +25,7 @@ DESCRIPTION If x = n/x, then den(x) == n. EXAMPLE - > print num(7), num(-1.25), num(121/33) + ; print num(7), num(-1.25), num(121/33) 7 -5 11 LIMITS @@ -53,8 +53,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: num,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: num,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/num,v $ ## ## Under source code control: 1995/10/05 04:52:27 diff --git a/help/oldvalue b/help/oldvalue index 4e2ef4d..5616469 100644 --- a/help/oldvalue +++ b/help/oldvalue @@ -23,25 +23,25 @@ DESCRIPTION A null value may be assigned to . by . = null() or free(.). EXAMPLE - > saveval(1); - > a = 2 - > . + ; saveval(1); + ; a = 2 + ; . 2 - > . += 3; b = . + 4 - > print ., b + ; . += 3; b = . + 4 + ; print ., b 9 9 - > . += 3; b = . + 4; null() - > print ., b + ; . += 3; b = . + 4; null() + ; print ., b 12 16 - > list(a, b, a + b) + ; list(a, b, a + b) list (3 elements, 3 nonzero): [[0]] = 2 [[1]] = 16 [[2]] = 18 - > saveval(0) - > print pop(.), .[[1]] + ; saveval(0) + ; print pop(.), .[[1]] 2 18 LIMITS @@ -69,8 +69,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: oldvalue,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: oldvalue,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/oldvalue,v $ ## ## Under source code control: 1997/09/06 20:03:35 diff --git a/help/ord b/help/ord index 8c556ba..5f1bcef 100644 --- a/help/ord +++ b/help/ord @@ -13,7 +13,7 @@ DESCRIPTION Return the integer value of the first character of a string. EXAMPLE - > print ord("DBell"), ord("chongo"), ord("/\../\"), ord("!") + ; print ord("DBell"), ord("chongo"), ord("/\../\"), ord("!") 68 99 47 33 LIMITS @@ -41,8 +41,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: ord,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: ord,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/ord,v $ ## ## Under source code control: 1994/09/30 01:45:46 diff --git a/help/param b/help/param index 43c2a00..cce8214 100644 --- a/help/param +++ b/help/param @@ -31,14 +31,14 @@ DESCRIPTION and param(param(0) is the last. EXAMPLE - > define f() { + ; define f() { >> local n, v = 0; >> for (n = 1; n <= param(0); n++) >> v += param(n)^2; >> return v; >> } - > print f(), f(1), f(1,2), f(1,2,3) + ; print f(), f(1), f(1,2), f(1,2,3) 0 1 5 14 LIMITS @@ -66,8 +66,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: param,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: param,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/param,v $ ## ## Under source code control: 1996/03/12 23:10:01 diff --git a/help/perm b/help/perm index c4295c6..dc75b71 100644 --- a/help/perm +++ b/help/perm @@ -21,10 +21,10 @@ DESCRIPTION may be chosen from x items where order in which they are chosen matters. EXAMPLE - > print perm(7,3), perm(7,4), perm(7,5), perm(3,0), perm(0,0) + ; print perm(7,3), perm(7,4), perm(7,5), perm(3,0), perm(0,0) 210 840 2520 3 0 - > print perm(2^31+1,3) + ; print perm(2^31+1,3) 9903520314283042197045510144 LIMITS @@ -53,8 +53,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: perm,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: perm,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/perm,v $ ## ## Under source code control: 1994/10/20 04:03:02 diff --git a/help/pfact b/help/pfact index 978e41a..e0b3853 100644 --- a/help/pfact +++ b/help/pfact @@ -13,7 +13,7 @@ DESCRIPTION Returns the product of primes p_i for which p_i <= n. EXAMPLE - > for (i = 0; i <= 16; i++) print pfact(i),:; + ; for (i = 0; i <= 16; i++) print pfact(i),:; 1 1 2 6 6 30 30 210 210 210 210 2310 2310 30030 30030 30030 30030 LIMITS @@ -42,8 +42,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: pfact,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: pfact,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/pfact,v $ ## ## Under source code control: 1995/12/18 12:34:57 diff --git a/help/pi b/help/pi index 0da27af..aa0cc3e 100644 --- a/help/pi +++ b/help/pi @@ -14,7 +14,7 @@ DESCRIPTION less than 0.75 eps, and in nearly all cases by less than 0.5 eps. EXAMPLE - > print pi(1e-5), pi(1e-10), pi(1e-15), pi(1e-20) + ; print pi(1e-5), pi(1e-10), pi(1e-15), pi(1e-20) 3.14159 3.1415926536 3.141592653589793 3.14159265358979323846 LIMITS @@ -42,8 +42,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: pi,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: pi,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/pi,v $ ## ## Under source code control: 1995/10/25 04:03:46 diff --git a/help/pix b/help/pix index d30e605..bd90190 100644 --- a/help/pix +++ b/help/pix @@ -18,13 +18,13 @@ DESCRIPTION (2, 3, 5, ...) less or equal to n. EXAMPLE - > for (i = 0; i <= 20; i++) print pix(i),:; + ; for (i = 0; i <= 20; i++) print pix(i),:; 0 0 1 2 2 3 3 4 4 4 4 5 5 6 6 6 6 7 7 8 8 - > print pix(100), pix(1000), pix(1e4), pix(1e5), pix(1e6) + ; print pix(100), pix(1000), pix(1e4), pix(1e5), pix(1e6) 25 168 1229 9592 78498 - > print pix(2^32 - 1, -1), pix(2^32, -1) + ; print pix(2^32 - 1, -1), pix(2^32, -1) 203280221 -1 LIMITS @@ -53,8 +53,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: pix,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: pix,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/pix,v $ ## ## Under source code control: 1995/12/18 12:34:58 diff --git a/help/places b/help/places index 7054a15..6ed0a83 100644 --- a/help/places +++ b/help/places @@ -25,10 +25,10 @@ DESCRIPTION factor of den(x) is a factor of b. EXAMPLE - > print places(3), places(0.0123), places(3.70), places(1e-10), places(3/7) + ; print places(3), places(0.0123), places(3.70), places(1e-10), places(3/7) 0 4 1 10 -1 - > print places(0.0123, 2), places(.625, 2), places(.625, 8) + ; print places(0.0123, 2), places(.625, 2), places(.625, 8) -1 3 1 LIMITS @@ -56,8 +56,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.5 $ -## @(#) $Id: places,v 29.5 2003/01/26 19:43:45 chongo Exp $ +## @(#) $Revision: 29.6 $ +## @(#) $Id: places,v 29.6 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/places,v $ ## ## Under source code control: 1995/10/03 10:40:02 diff --git a/help/pmod b/help/pmod index 968572b..74db798 100644 --- a/help/pmod +++ b/help/pmod @@ -32,12 +32,12 @@ DESCRIPTION 21 -md/2 <= v < md/2 md/2 <= v < -md/2 EXAMPLE - > c = config("mod",0) - > print pmod(2,3,10), pmod(2,5,10), pmod(2,3,-10), pod(2,5,-10) + ; c = config("mod",0) + ; print pmod(2,3,10), pmod(2,5,10), pmod(2,3,-10), pod(2,5,-10) 8 2 -2 -8 - > c = config("mod",16) - > print pmod(2,3,10), pmod(2,5,10), pmod(2,3,-10), pmod(2,5,-10) + ; c = config("mod",16) + ; print pmod(2,3,10), pmod(2,5,10), pmod(2,3,-10), pmod(2,5,-10) -2 2 -2 2 LIMITS @@ -65,8 +65,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: pmod,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: pmod,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/pmod,v $ ## ## Under source code control: 1995/11/09 03:27:51 diff --git a/help/polar b/help/polar index 36a6ac4..f62ccdc 100644 --- a/help/polar +++ b/help/polar @@ -18,11 +18,11 @@ DESCRIPTION than 0.75 * abs(eps), but usually less than 0.5 * abs(eps). EXAMPLE - > print polar(2, 0), polar(1, 2, 1e-5), polar(1, 2, 1e-10) + ; print polar(2, 0), polar(1, 2, 1e-5), polar(1, 2, 1e-10) 2 -.41615+.9093i -.4161468365+.9092974268i - > pi = pi(1e-10); eps = 1e-5 - > print polar(2, pi/4, eps), polar(2, pi/2, eps), polar(2, 3*pi/4, eps) + ; pi = pi(1e-10); eps = 1e-5 + ; print polar(2, pi/4, eps), polar(2, pi/2, eps), polar(2, 3*pi/4, eps) 1.41421+1.41421i 2i -1.414215+1.41421i LIMITS @@ -50,8 +50,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.3 $ -## @(#) $Id: polar,v 29.3 2005/10/18 10:48:29 chongo Exp $ +## @(#) $Revision: 29.4 $ +## @(#) $Id: polar,v 29.4 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/polar,v $ ## ## Under source code control: 1995/10/25 04:03:46 diff --git a/help/poly b/help/poly index ef67744..a9b67fa 100644 --- a/help/poly +++ b/help/poly @@ -110,11 +110,11 @@ DESCRIPTION poly(clist, x_0, x_1, x_2, x_3, x_4, x_5). EXAMPLE - > print poly(2, 3, 5, 7), poly(list(5, 3, 2), 7), 5 + 3 * 7 + 2 * 7^2 + ; print poly(2, 3, 5, 7), poly(list(5, 3, 2), 7), 5 + 3 * 7 + 2 * 7^2 124 124 124 - > mat A[2,2] = {1,2,3,4} - > mat I[2,2] = {1,0,0,1} + ; mat A[2,2] = {1,2,3,4} + ; mat I[2,2] = {1,0,0,1} print poly(2 * I, 3 * I, 5 * I, A) mat [2,2] (4 elements, 4 nonzero) @@ -123,8 +123,8 @@ EXAMPLE [1,0] = 39 [1,1] = 61 - > P = list(list(0,0,1), list(0,2), 3); x = 4; y = 5 - > print poly(P,x,y), poly(P, list(x,y)), y^2 + 2 * y * x + 3 * x^2 + ; P = list(list(0,0,1), list(0,2), 3); x = 4; y = 5 + ; print poly(P,x,y), poly(P, list(x,y)), y^2 + 2 * y * x + 3 * x^2 113 113 113 LIMITS @@ -152,8 +152,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: poly,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: poly,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/poly,v $ ## ## Under source code control: 1995/12/02 02:40:43 diff --git a/help/pop b/help/pop index 5270774..7a3337e 100644 --- a/help/pop +++ b/help/pop @@ -15,25 +15,25 @@ DESCRIPTION This function is equivalent to calling delete(lst, 0). EXAMPLE - > lst = list(2,"three") + ; lst = list(2,"three") list (2 elements, 2 nonzero): [[0]] = 2 [[1]] = "three" - > pop(lst) + ; pop(lst) 2 - > print lst + ; print lst list (1 elements, 1 nonzero): [[0]] = "three" - > pop(lst) + ; pop(lst) "three" - > print lst + ; print lst list (0 elements, 0 nonzero) - > pop(lst) - > print lst + ; pop(lst) + ; print lst list (0 elements, 0 nonzero) LIMITS @@ -61,8 +61,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: pop,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: pop,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/pop,v $ ## ## Under source code control: 1994/03/19 03:13:20 diff --git a/help/popcnt b/help/popcnt index b9c3b69..c26e27c 100644 --- a/help/popcnt +++ b/help/popcnt @@ -17,10 +17,10 @@ DESCRIPTION The popcnt function is equivalent to #x when x is an integer. EXAMPLE - > print popcnt(32767), popcnt(3/2), popcnt(pi(),0), popcnt(pi(),1) + ; print popcnt(32767), popcnt(3/2), popcnt(pi(),0), popcnt(pi(),1) 15 3 69 65 - > print popcnt(randombit(128), 0), popcnt(randombit(128), 1) + ; print popcnt(randombit(128), 0), popcnt(randombit(128), 1) 61 64 LIMITS @@ -48,8 +48,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: popcnt,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: popcnt,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/popcnt,v $ ## ## Under source code control: 1997/09/11 04:20:02 diff --git a/help/power b/help/power index 685d9c6..3df4c08 100644 --- a/help/power +++ b/help/power @@ -25,19 +25,19 @@ DESCRIPTION the two results being probably at most abs(eps). EXAMPLE - > print power(1.2345, 10, 1e-5), power(1.2345, 10, 1e-10) + ; print power(1.2345, 10, 1e-5), power(1.2345, 10, 1e-10) 8.22074 8.2207405646 - > print power(1+3i, 3, 1e-5), power(1 + 3i, 2+ 1i, 1e-5) + ; print power(1+3i, 3, 1e-5), power(1 + 3i, 2+ 1i, 1e-5) -26-18i -2.50593-1.39445i - > print power(1+ 1e-30, 1e30, 1e-20) + ; print power(1+ 1e-30, 1e30, 1e-20) 2.71828182845904523536 - > print power(1i, 1i, 1e-20) + ; print power(1i, 1i, 1e-20) .20787957635076190855 - > print power(exp(1, 1e-20), pi(1e-20) * 1i/2, 1e-20) + ; print power(exp(1, 1e-20), pi(1e-20) * 1i/2, 1e-20) 1i LIMITS @@ -71,8 +71,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.3 $ -## @(#) $Id: power,v 29.3 2005/10/18 10:48:29 chongo Exp $ +## @(#) $Revision: 29.4 $ +## @(#) $Id: power,v 29.4 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/power,v $ ## ## Under source code control: 1995/10/25 04:03:46 diff --git a/help/prevcand b/help/prevcand index 8c2052c..bb7fd95 100644 --- a/help/prevcand +++ b/help/prevcand @@ -56,22 +56,22 @@ RUNTIME seems to be between roughly K/N^3 some constant K. EXAMPLE - > print prevcand(50), prevcand(2), prevcand(125,-1), prevcand(125,-2) + ; print prevcand(50), prevcand(2), prevcand(125,-1), prevcand(125,-2) 47 1 113 113 - > print prevcand(100,1,1,1,6), prevcand(100,1,1,-1,6) + ; print prevcand(100,1,1,1,6), prevcand(100,1,1,-1,6) 97 89 - > print prevcand(100,1,1,2,6), prevcand(100,1,1,4,6), + ; print prevcand(100,1,1,2,6), prevcand(100,1,1,4,6), 2 0 - > print prevcand(100,1,1,53,0), prevcand(100,1,1,53,106) + ; print prevcand(100,1,1,53,0), prevcand(100,1,1,53,106) 53 53 - > print prevcand(125,1,3), prevcand(125,-1,3), prevcand(125,-2,3) + ; print prevcand(125,1,3), prevcand(125,-1,3), prevcand(125,-2,3) 113 121 113 - > print prevcand(2e60, 1, 1, 31, 1e30) + ; print prevcand(2e60, 1, 1, 31, 1e30) 1999999999999999999999999999914000000000000000000000000000031 LIMITS @@ -100,8 +100,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: prevcand,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: prevcand,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/prevcand,v $ ## ## Under source code control: 1996/02/25 00:27:43 diff --git a/help/prevprime b/help/prevprime index f9515e7..3141e42 100644 --- a/help/prevprime +++ b/help/prevprime @@ -20,13 +20,13 @@ DESCRIPTION Other cases cause a runtime error. EXAMPLE - > print prevprime(10), prevprime(100), prevprime(1e6) + ; print prevprime(10), prevprime(100), prevprime(1e6) 7 97 999983 - > print prevprime(2,-99), prevprime(2^32,-99) + ; print prevprime(2,-99), prevprime(2^32,-99) -99 -99 - > print prevprime(2) + ; print prevprime(2) pprime arg 1 is <= 2 LIMITS @@ -54,8 +54,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: prevprime,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: prevprime,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/prevprime,v $ ## ## Under source code control: 1995/12/18 12:34:58 diff --git a/help/printf b/help/printf index c638477..54665ac 100644 --- a/help/printf +++ b/help/printf @@ -89,21 +89,21 @@ DESCRIPTION configuration parameters "outround", "tilde", "fullzero", "leadzero". EXAMPLE - > c = config("epsilon", 1e-6); c = config("display", 6); - > c = config("tilde", 1); c = config("outround", 0); - > c = config("fullzero", 0); - > fmt = "%f,%10f,%-10f,%10.4f,%.4f,%.f.\n"; - > a = sqrt(3); - > printf(fmt,a,a,a,a,a,a); + ; c = config("epsilon", 1e-6); c = config("display", 6); + ; c = config("tilde", 1); c = config("outround", 0); + ; c = config("fullzero", 0); + ; fmt = "%f,%10f,%-10f,%10.4f,%.4f,%.f.\n"; + ; a = sqrt(3); + ; printf(fmt,a,a,a,a,a,a); 1.732051, 1.732051,1.732051 , ~1.7320,~1.7320,~1. - > c = config("tilde", 0); c = config("outround",24); - > c = config("fullzero", 1); - > printf(fmt,a,a,a,a,a,a); + ; c = config("tilde", 0); c = config("outround",24); + ; c = config("fullzero", 1); + ; printf(fmt,a,a,a,a,a,a); 1.732051, 1.732051,1.732051 , 1.7321,1.7321,2. - > mat A[4] = {sqrt(2), 3/7, "undefined", null()}; - > printf("%f%r",A,A); + ; mat A[4] = {sqrt(2), 3/7, "undefined", null()}; + ; printf("%f%r",A,A); mat [4] (4 elements, 4 nonzero): [0] = 1.414214 [1] = .428571 @@ -142,8 +142,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: printf,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: printf,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/printf,v $ ## ## Under source code control: 1996/03/12 22:50:41 diff --git a/help/prompt b/help/prompt index a930e14..8bdc138 100644 --- a/help/prompt +++ b/help/prompt @@ -16,12 +16,12 @@ DESCRIPTION (other than the newline) is returned as the value of prompt(). EXAMPLE - > x = prompt("? "); + ; x = prompt("? "); ? 273 - > x + ; x "273" - > for (;;) {s = prompt("? "); if (s=="end") break; print "\t":eval(s)^2;} + ; for (;;) {s = prompt("? "); if (s=="end") break; print "\t":eval(s)^2;} ? 3 9 ? 2 + 3 @@ -54,8 +54,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: prompt,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: prompt,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/prompt,v $ ## ## Under source code control: 1995/12/18 12:34:58 diff --git a/help/protect b/help/protect index 0170a6c..12382b2 100644 --- a/help/protect +++ b/help/protect @@ -1,77 +1,194 @@ NAME - protect - read or set protect status for a variable or named block + protect - read or adjust protect status for a variable or named block SYNOPSIS - protect(var [, sts]) - protect(nblk [, sts]) + protect(var [, N [, depth]) + protect(nblk [, N [, depth]]) TYPES var lvalue nblk named block - sts integer, 0 <= sts < 512 + N integer, abs(N) < 65536 + depth nonnegative integer return null value DESCRIPTION - With one argument, protect(var) or protect(nblk) returns the current - protection status for var or nblk. + The protection status of the association of an lvalue A with + its value is represented by a nonnegative integer less than 2^16. + The current value sts of this status is returned by protect(A). + Each nonzero bit of the low eight bits of sts corresponds to a + builtin kind of protection as follows: - With two arguments, protect(var, sts) or protect(nblk, sts) sets the - protection status for var or nblk to the value sts. Each nonzero bit - of sts corresponds to one kind of protection as follows: + bit value protection - sts protection + 1 no assign to A + 2 no change of A by assignment + 4 no change of type value of A + 8 no error value for A + 16 no copy to A + 32 no relocation for A or its elements + 64 no assign from A + 128 no copy from A - 1 no assign to var - 2 no change of value of var - 4 no change of type of var - 8 no error value for var - 16 no copy to var or nblk - 32 no relocation of var or nblk - 64 no assign from var - 128 no copy from var or nblk - 256 protect recursively all components of var + For example, A having protection status 65 = 1 + 64 prevents + execution of assignments of the forms A = expression and V = A + where V is an lvalue. Attempting either of these assignments + will return an error value and leave the value of A or V unchanged. + Initally, when created, any lvalue A has zero status corresponding + to "no protection". This may be restored at any time by protect(A, 0). - Here "assign" refers to use of '=' as in A = expr to assign the value + If N is positive and A does not already have the protection + corresponding to a nonzero bit of N, protect(A, N) adds that + protection to the status of A. For example, if protect(A) is 65, + protect(A, 17) will add the no-copy-to protection so that the + new protection status of A will be 81 = 1 + 16 + 64. + + Similarly, if N is negative and A has the protection corresponding + to a nonzero bit of abs(N), protect(A,N) will remove that kind of + protection. For example if protect(A) = 65, then protect(A, -17) + will remove the no-assign-to protection and the new value of + protect(A) will be 64. Note that protect(A, -65535) has the same + effect as protect(A, 0). + + For the purposes of this function, the depth of a global or local + variable is zero; if A has depth d and the value of A is a list, + matrix, object or association, its elements have depth d + 1. + For example, after + + obj point {x,y} + X = mat[3] = {1, list(2,3), mat[2] = {obj point, obj point} } + + X has depth 0; X[0], X[1] and X[2] have depth 1; X[1][0], X[1][1], + X[2][0] and X[2][1] have depth 2; X[2][0].x, X[2][0].y, X[2][1].x + and X[2][1].y have depth 3. For any lvalue A, protect(A, N, depth) + applies protect(A, N) to A and to all elements, elements of + elements, etc., up tothe stated depth. In the above example, + protect(X, 20, 2) gives no-type-change and no-copy-to protection + to 8 of the listed lvalues, but not to the components of the + objects X[2][0] and X[2][1]; With any d >= 3, protect(X, 20, d) + would give that protection the 12 listed lvalues. + + If B is a variable with positive status and assignment of B to A is + permitted, execution of the assignment A = B adds to the protections + of A all protections of B that A does not already have. Except when + the value returned is the result of the evqluation of an lvalue with + positive status, calc's builtin operators and functions return values + with zero protection status. For example, whatever the protection + statuses of X and Y, X + sqrt(Y) will have zero status, but + t ? X : Y may have nonzero status. The list, matrix, object or + association returned by the use of list, mat, obj or assoc will have + zero status, but any element specified by an lvalue will receive + its status; e.g. after L = list(X, X^2) , protect(L[0]) equals + protect(X) and both protect(L) and protect(L[1]) are zero. + + Users may define functions that return values with positive status, e.g. + + define noassigntovalue(x) {protect(x,1); return x}; + S = noassigntovalue(42); + + will result in S having the value 42 and no-assign-to protection. + By using a backquote with a variable as argument, an even simpler + function: + + define noassignto(x) = protect(x, 1); + + gives no-assign-to protection to the variable; i.e. noassignto(`A) + achieves the same as protect(A,1). + + In the brief descriptions above of builtin kinds of protectiopn, + "assign" refers to use of '=' as in A = expr to assign the value of expr to A, and in A = {..., expr, ...} to assign the value of expr - to some component of A, and to the assignments implicit in swap(A, B), - quomod(x, y, A, B), and pre or post ++ or --. + to some component of A, and to the assignments implicit in + quomod(x, y, A, B), and pre or post ++ or --. Swapping of lvalues is + prevented if either value has no-assign-to or no-assign-from + protection. (Swapping of octets is prevented if at least one of + them is in a string or block with no-copy-to or no-copy-from + protection.) - For example, if A is a global variable, then after + "Copying" refers to initialization using {...} and to the operations + copy and blkcpy as applied to strings, blocks, lists and matrices. + Although A = {..., expr, ...) assigns the value of expr to an + elment of A, it is also regarded as copying to A. Thus, initialization + of A may be prevented either by giving no-copy-to protection to A or + no-assignment=to protection to the elements of A. Assignments to and + from characters or octets in strings or blocks are also regarded as + copying to or from the string or block. For example, after + A = "abc", protect(A,16) would prevent the assignment A[0] = 'x'. + (Note that in this example, A[0] is not an lvalue in the sense + normally understood - the only values it can have are nonnegative + integers less than 256. The only kinds of protection relevant to an + octet are the no-copy-to, no-copy-from and no-change protections of + the string or block in which the octet resides.) - protect(A, 1); + The no-relocate protection applies to lists and blocks. For lists, + it refers to the operations push, pop, append, remove, insert and + delete. For example, if A = list(2,3,5,7), protect(A, 32) will + prevent any change in the content or size of the list. + No-relocation protection of a block prevents reallocation of the + memory used by a block and the freeing of a named block, For example, + if a block B has maxsize 256, then after - an error state is established if A = expr is attempted. It does - not imply constancy if, for example, the current value of A is a list - or matrix; such a value may be changed by assignments to the elements - of A, or by push or copy commands. + protect(B, 32); - If the current value of A is val, protect(A, 2) will prevent any - assignment to A other than + copy(A, B) will fail if the copying would cause size(B) to equal or + exceed 256; if B is a named block, blkfree(B) will not be permitted. - A = expr + The elements of the list returned by list(...) will initially have zero + protection status except when an argument is an lvalue with positive + status, in which case the corresponding element will receive that + status. E.g., L = list(A,B) will result in L[0] having status + protect(A) and L[1] having status protect(B). L itself will have + the status L had before the assignment. There is a similar copying + of protection status when "= { ... }" initialization is used for + matrices, lists or objects. For example, except when A or B has + no-assign-from protection, M = mat [2] = {A,B} or mat M[2] = {A,B} + will result in M[0] and M[1] having statuses protect(A) and + protect(B) respectively. (If A or B has no-assign-from protection, + mat[2] = {A,B} returns an error value.) - where expr evaluates to val. + Although M = mat[2] = {...} and mat M[2] = {...} do the same thing, + these are different from (M = mat[2]) = {...} and (mat M[3]) = {...}. + In the former pair of statements, the result of mat[2] = {...} is being + assigned to M. In the latter statments, a matrix with zero elements is + being assigned to M and then that matrix is being "reinitialized". Both + will fail if M has no-asssign-to protection, but only the latter + would be prevented by M having no-copy-to protection. - Any such protection of A is cancelled by protect(A, 0). + When the functions which mave move elements like of sort, reverse, + swap, insert, pop, remove, push and append. are evaluated, the + protection statuses move with the values, e.g. if among the values + and elements involved, there is just one with value 42, then the + lvalue to which the value 42 is moved will get the status the lvalue + with value 42 had before the evaluation of the function. This is + relevant to evaluation of expressions like A = sort(A), + append(A, pop(A)), insert(A,2,B,C). Note that when pop(A) is first + evaluated it is located on the stack calc uses for calculating + expressions rather than being the value of an lvalue. With an + explicit assignment like X = pop(A) or the implied assignment in + append(A, pop(A)), it becomes the value of an lvalue. - If A has components as in a matrix or list, components may be - protected independently from each other and from A by stateents like: + Users may use higher bits values for other kinds of protection or + simply to store information about an lvalue and its current value. + For example 1024 might be used to indicate that the lvalue is always + to have positive value. Then code for evaluating a function might + include lines like - protect(A[0], 1); - protect(A[1], 2); + if (protect(A) & 1024 && B <= 0) + return newerror("Prohibited assignment"); + A = B; - "Copy" refers to the use of copy(A, B, ...) or blkcpy(B, A, ...) to - copy A to B. For example if B is a block, then after - - protect(B, 16); - - attempts to copy to B will fail. - - The protection status of var refers to var as a variable, not to its - current value: if an operation like var = value is executed it may - change the value of var but not protect(var). + When an operation forbidden by a particular bit in the protection + status of A is attempted, an error value is created but unless this + causes errcount to exceed errmax, the only immediate evidence + for the error might be the incrementing of errcount. Sometimes the + failure causes the return of the error value; e.g. swap(A,B) if + not permitted returns an appropriate error value rather than the + null value. If the value of A is a number and A has no-type-change + protection, A = "abc" returns an error value. The error-number of + the most recent error value is returned by errno(), a string + describing it by strerror(). A named block may be referred to by using the blocks() or blk() functions, or by assigning it to a variable A and then using either @@ -81,53 +198,47 @@ DESCRIPTION named block; protect(A,16) will prevent any copying to the named block only when it is referred to by A. - The protection provided by sts = 32 prevents relocation of the memory - used by a block, the freeing of a named block, and addition or removal - of one or more elements from a list. For example, if a block B has - maxsize 256, then after - - protect(B, 32); - - copy(A, B) will fail if the copying would cause size(B) to equal or - exceed 256; if B is a named block, blkfree(B) will not be permitted. - If the current value of L is a list, protect(L, 32) prevents the - execution of push, pop, append, remove, insert, and delete with first - argument L. - - With bit 8 of sts set, as with - - protect(A, 257); - - the protection provided by the lower order bits extends to any - elements A may have, and recursively to any elements of these elements, - etc. - - All protection of A as described above is removed by - - protect(A, 0). - - EXAMPLE + > A = 27 > protect(A,1) - > protect(A) - 1 - > A = 99 - No-assign-to destination for assign - - > protect(A,2) > A = 45 - Change of value in assign not permitted - - > A = 27 - + > A + 27 + > strerror() + "No-assign-to destination for assign" + > protect(A,64) + > protect(A) + 65 + > X = A + > X + 0 + > strerror() + "No-assign-from source for assign" + > protect(A,-1) + > protect(A) + 64 > protect(A,4) - > A = 2 + 3i - Change of type in assign not permitted - - > protect(A,8) - > A = 1/0 - Error value in assign not permitted + > protect(A) + 68 + > A = "abc" + > A + 27 + > strerror() + "No-type-change destination for assign" + > B = 45 + > swap(A,B) + Error 10372 + > strerror() + "No-assign-to-or-from argument for swap" + > protect(A,-64) + > protect(A) + 4 + > swap(A,B) + > A + 45 + > B + 27 > A = mat[4] = {1,2,3,4} > B = list(5,6,7,8) @@ -137,47 +248,27 @@ EXAMPLE > strerror() "No-copy-to destination variable" - > A = blk(0,5) + > A = list(1,2,3) > protect(A,32) + < append(A,4) + Error 10402 + > strerror() + "No-relocate for list append" + + > A = blk(0,5) > copy("abc", A) > copy("de",A) - Error 10229 + Error 10229 > strerror() - "No-relocation destination variable" + "No-relocate destination variable" - > A = list(1,2,3) - > append(A, 4) - No-relocate list for push - - > protect(A, 64) - > X = A - No-assign-from source for assign - - > protect(A,128) - > copy(A,B) - Error 10225 + > A = blk("alpha") = {1,2,3,4,5} + > protect(A,0) + < protect(*A, 16) + < copy("abc", A) + Error 10228 > strerror() - "No-copy-from source variable" - - > mat A[2] = {1, list(2, mat[2])} - > protect(A,257) - > A[1][[1]][1] = 4 - No-assign-to destination for assign - > protect(A,256) - > A[1][[1]][1] = 4 - > A[1][[1]] - - mat [2] (2 elements, 1 nonzero): - [0] = 0 - [1] = 4 - - > A = blk("alpha") = {1,2,3,4} - > protect(A, 0) - > protect(*A, 16) - copy("abc", A) - Error 10228 - No-copy-to destination named block - + "No-copy-to destination named block" LIMITS none @@ -185,7 +276,7 @@ LINK LIBRARY none SEE ALSO - assign, copy, blk + assign, copy, blk, error, errno, strerror ## Copyright (C) 1999 Landon Curt Noll ## @@ -203,8 +294,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: protect,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.4 $ +## @(#) $Id: protect,v 29.4 2006/05/19 15:12:57 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/protect,v $ ## ## Under source code control: 1997/07/10 22:38:44 diff --git a/help/ptest b/help/ptest index 44412b8..44b56d3 100644 --- a/help/ptest +++ b/help/ptest @@ -82,19 +82,19 @@ RUNTIME the standard algorithms. EXAMPLE - > print ptest(103^3 * 3931, 0), ptest(4294967291,0) + ; print ptest(103^3 * 3931, 0), ptest(4294967291,0) 1 1 In the first example, the first argument > 2^32; in the second the first argument is the largest prime less than 2^32. - > print ptest(121,-1,2), ptest(121,-1,3), ptest(121,-2,2) + ; print ptest(121,-1,2), ptest(121,-1,3), ptest(121,-2,2) 0 1 0 121 is the smallest strong pseudoprime to the base 3. - > x = 151 * 751 * 28351 - > print x, ptest(x,-4,1), ptest(x,-5,1) + ; x = 151 * 751 * 28351 + ; print x, ptest(x,-4,1), ptest(x,-5,1) 3215031751 1 0 The integer x in this example is the smallest positive integer that is @@ -102,14 +102,14 @@ EXAMPLE not to base 11. The probability that ptest(x,-1,0) will return 1 is about .23. - > for (i = 0; i < 11; i++) print ptest(91,-1,0),:; print; + ; for (i = 0; i < 11; i++) print ptest(91,-1,0),:; print; 0 0 0 1 0 0 0 0 0 0 1 The results for this example depend on the state of the random number generator; the expectation is that 1 will occur twice. - > a = 24444516448431392447461 * 48889032896862784894921; - > print ptest(a,11,1), ptest(a,12,1), ptest(a,20,2), ptest(a,21,2) + ; a = 24444516448431392447461 * 48889032896862784894921; + ; print ptest(a,11,1), ptest(a,12,1), ptest(a,20,2), ptest(a,21,2) 1 0 1 0 These results show that a is a strong pseudoprime for all 11 prime @@ -144,8 +144,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: ptest,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: ptest,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/ptest,v $ ## ## Under source code control: 1996/02/25 00:27:43 diff --git a/help/push b/help/push index bfaf947..ef1eeb3 100644 --- a/help/push +++ b/help/push @@ -20,15 +20,15 @@ DESCRIPTION This function is equivalent to insert(x, 0, y_n-1, ..., y_1, y_0). EXAMPLE - > A = list(2,"three") - > print A + ; A = list(2,"three") + ; print A list (2 elements, 2 nonzero): [[0]] = 2 [[1]] = "three" - > push(A, 4i, 7^2) - > print A + ; push(A, 4i, 7^2) + ; print A list (4 elements, 4 nonzero): [[0]] = 49 @@ -36,8 +36,8 @@ EXAMPLE [[2]] = 2 [[3]] = "three" - > push (A, pop(A), pop(A)) - > print A + ; push (A, pop(A), pop(A)) + ; print A list (4 elements, 4 nonzero): [[0]] = 4i @@ -70,8 +70,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: push,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: push,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/push,v $ ## ## Under source code control: 1994/03/19 03:13:20 diff --git a/help/putenv b/help/putenv index f86461e..b1c78b4 100644 --- a/help/putenv +++ b/help/putenv @@ -27,15 +27,15 @@ DESCRIPTION EXAMPLE - > putenv("name", "value") + ; putenv("name", "value") 0 - > getenv("name") + ; getenv("name") "value" - > putenv("name=val2") + ; putenv("name=val2") 0 - > getenv("name") + ; getenv("name") "val2" - > isnull(getenv("unknown")) + ; isnull(getenv("unknown")) 1 LIMITS @@ -63,8 +63,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: putenv,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: putenv,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/putenv,v $ ## ## Under source code control: 1995/07/09 03:48:57 diff --git a/help/quomod b/help/quomod index 18f7279..de06ec1 100644 --- a/help/quomod +++ b/help/quomod @@ -22,13 +22,13 @@ DESCRIPTION XXX - need to document relationship with "quomod" config value EXAMPLE - > global u, v; - > global mat M[2]; - > print quomod(13,5,u,v), u, v, quomod(15.6,5.2,M[0],M[1]), M[0], M[1]; - > 1 2 3 0 3 0 - > A = assoc(); - > print quomod(13, 5, A[1], A[2]), A[1], A[2] - > 1 2 3 + ; global u, v; + ; global mat M[2]; + ; print quomod(13,5,u,v), u, v, quomod(15.6,5.2,M[0],M[1]), M[0], M[1]; + ; 1 2 3 0 3 0 + ; A = assoc(); + ; print quomod(13, 5, A[1], A[2]), A[1], A[2] + ; 1 2 3 XXX - need examples of how the "quomod" config file changes results @@ -57,8 +57,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: quomod,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: quomod,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/quomod,v $ ## ## Under source code control: 1995/05/07 03:17:03 diff --git a/help/rand b/help/rand index 7e0f123..615cc6f 100644 --- a/help/rand +++ b/help/rand @@ -220,13 +220,13 @@ DESCRIPTION 100 values yourself! EXAMPLE - > print srand(0), rand(), rand(), rand() + ; print srand(0), rand(), rand(), rand() RAND state 2298441576805697181 3498508396312845423 5031615567549397476 - > print rand(123), rand(123), rand(123), rand(123), rand(123), rand(123) + ; print rand(123), rand(123), rand(123), rand(123), rand(123), rand(123) 106 59 99 99 25 88 - > print rand(2,12), rand(2^50,3^50), rand(0,2), rand(-400000, 120000) + ; print rand(2,12), rand(2^50,3^50), rand(0,2), rand(-400000, 120000) 2 658186291252503497642116 1 -324097 LIMITS @@ -256,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.3 $ -## @(#) $Id: rand,v 29.3 2001/04/14 22:46:33 chongo Exp $ +## @(#) $Revision: 29.4 $ +## @(#) $Id: rand,v 29.4 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/rand,v $ ## ## Under source code control: 1996/01/01 02:16:09 diff --git a/help/randbit b/help/randbit index b739dcf..a6dfcfd 100644 --- a/help/randbit +++ b/help/randbit @@ -27,10 +27,10 @@ DESCRIPTION pseudo-random number generator. EXAMPLE - > print srand(0), randbit(20), randbit(20), randbit(20), randbit(20) + ; print srand(0), randbit(20), randbit(20), randbit(20), randbit(20) RAND state 817647 476130 944201 822573 - > print srand(0), randbit(-20), randbit(20), randbit(-20), randbit(20) + ; print srand(0), randbit(-20), randbit(20), randbit(-20), randbit(20) RAND state 20 476130 20 822573 LIMITS @@ -58,8 +58,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: randbit,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: randbit,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/randbit,v $ ## ## Under source code control: 1996/01/01 03:17:22 diff --git a/help/random b/help/random index 153fbec..5661f1c 100644 --- a/help/random +++ b/help/random @@ -136,13 +136,13 @@ DESCRIPTION EXAMPLE - > print srandom(0), random(), random(), random() + ; print srandom(0), random(), random(), random() RANDOM state 9203168135432720454 13391974640168007611 13954330032848846793 - > print random(123), random(123), random(123), random(123), random(123) + ; print random(123), random(123), random(123), random(123), random(123) 22 83 66 88 67 - > print random(2,12), random(2^50,3^50), random(0,2), random(-400000,120000) + ; print random(2,12), random(2^50,3^50), random(0,2), random(-400000,120000) 10 483381144668580304003305 0 -70235 LIMITS @@ -172,8 +172,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: random,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: random,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/random,v $ ## ## Under source code control: 1997/02/17 01:18:22 diff --git a/help/randombit b/help/randombit index baa1fc0..448e2e4 100644 --- a/help/randombit +++ b/help/randombit @@ -27,9 +27,9 @@ DESCRIPTION pseudo-random number generator. EXAMPLE - > print srandom(0), randombit(20), randombit(20), randombit(20) + ; print srandom(0), randombit(20), randombit(20), randombit(20) RANDOM state 523139 567456 693508 - > print srandom(0), randombit(-20), randombit(20), randombit(-20) + ; print srandom(0), randombit(-20), randombit(20), randombit(-20) RANDOM state 20 567456 20 LIMITS @@ -57,8 +57,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: randombit,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: randombit,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/randombit,v $ ## ## Under source code control: 1997/02/17 01:18:22 diff --git a/help/randperm b/help/randperm index de49d9d..de82cf7 100644 --- a/help/randperm +++ b/help/randperm @@ -15,8 +15,8 @@ DESCRIPTION changed. EXAMPLE - > A = list(1,2,2,3,4) - > randperm(A) + ; A = list(1,2,2,3,4) + ; randperm(A) list (5 elements, 5 nonzero): [[0]] = 4 @@ -25,7 +25,7 @@ EXAMPLE [[3]] = 3 [[4]] = 2 - > randperm(A) + ; randperm(A) list (5 elements, 5 nonzero): [[0]] = 2 @@ -59,8 +59,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: randperm,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: randperm,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/randperm,v $ ## ## Under source code control: 1995/07/10 02:09:31 diff --git a/help/rcin b/help/rcin index 53569c4..657a749 100644 --- a/help/rcin +++ b/help/rcin @@ -60,7 +60,7 @@ RUNTIME EXAMPLE Using a 64-bit machine with B = 2^32: - > for (i = 0; i < 9; i++) print rcin(x, 9),:; print; + ; for (i = 0; i < 9; i++) print rcin(x, 9),:; print; 0 4 8 3 7 2 6 1 5 LIMITS @@ -88,8 +88,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: rcin,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: rcin,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/rcin,v $ ## ## Under source code control: 1996/02/25 02:22:21 diff --git a/help/rcmul b/help/rcmul index 4f01c9c..3702dbf 100644 --- a/help/rcmul +++ b/help/rcmul @@ -49,7 +49,7 @@ RUNTIME EXAMPLE Using a 64-bit machine with B = 2^32: - > print rcin(4 * 5, 9), rcmul(rcin(4,9), rcin(5,9), 9), rcout(8, 9); + ; print rcin(4 * 5, 9), rcmul(rcin(4,9), rcin(5,9), 9), rcout(8, 9); 8 8 2 LIMITS @@ -77,8 +77,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: rcmul,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: rcmul,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/rcmul,v $ ## ## Under source code control: 1996/02/25 02:22:21 diff --git a/help/rcout b/help/rcout index 7f23f2f..21f6431 100644 --- a/help/rcout +++ b/help/rcout @@ -51,7 +51,7 @@ RUNTIME EXAMPLE Using a 64-bit machine with B = 2^32: - > for (i = 0; i < 9; i++) print rcout(i,9),:; print; + ; for (i = 0; i < 9; i++) print rcout(i,9),:; print; 0 7 5 3 1 8 6 4 2 LIMITS @@ -79,8 +79,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: rcout,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: rcout,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/rcout,v $ ## ## Under source code control: 1996/02/25 02:22:21 diff --git a/help/rcpow b/help/rcpow index 717e467..b9d2f49 100644 --- a/help/rcpow +++ b/help/rcpow @@ -58,9 +58,9 @@ RUNTIME EXAMPLE Using a 64-bit machine with B = 2^32: - > m = 1234567; - > x = 15; - > print rcout(rcpow((rcin(x,m), m - 1, m), m), pmod(x, m-1, m) + ; m = 1234567; + ; x = 15; + ; print rcout(rcpow((rcin(x,m), m - 1, m), m), pmod(x, m-1, m) 783084 783084 LIMITS @@ -88,8 +88,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: rcpow,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: rcpow,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/rcpow,v $ ## ## Under source code control: 1996/02/25 02:22:21 diff --git a/help/rcsq b/help/rcsq index 3bb9164..44488ed 100644 --- a/help/rcsq +++ b/help/rcsq @@ -51,10 +51,10 @@ RUNTIME EXAMPLE Using a 64-bit machine with B = 2^32: - > for (i = 0; i < 9; i++) print rcsq(i,9),:; print; + ; for (i = 0; i < 9; i++) print rcsq(i,9),:; print; 0 7 1 0 4 4 0 1 7 - > for (i = 0; i < 9; i++) print rcin((rcsq(i,9),:; print; + ; for (i = 0; i < 9; i++) print rcin((rcsq(i,9),:; print; 0 1 4 0 7 7 0 4 1 LIMITS @@ -82,8 +82,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: rcsq,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: rcsq,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/rcsq,v $ ## ## Under source code control: 1996/02/25 02:22:21 diff --git a/help/re b/help/re index 932b24f..5fc20c3 100644 --- a/help/re +++ b/help/re @@ -13,7 +13,7 @@ DESCRIPTION If x = u + v * 1i where u and v are real, re(x) returns u. EXAMPLE - > print re(2), re(2 + 3i), re(-4.25 - 7i) + ; print re(2), re(2 + 3i), re(-4.25 - 7i) 2 2 -4.25 LIMITS @@ -41,8 +41,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.3 $ -## @(#) $Id: re,v 29.3 2002/03/12 09:38:26 chongo Exp $ +## @(#) $Revision: 29.4 $ +## @(#) $Id: re,v 29.4 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/re,v $ ## ## Under source code control: 1995/10/05 04:52:27 diff --git a/help/remove b/help/remove index 03452a3..928d426 100644 --- a/help/remove +++ b/help/remove @@ -19,25 +19,25 @@ DESCRIPTION what it would have returned before the remove operation. EXAMPLE - > lst = list(2,"three") + ; lst = list(2,"three") list (2 elements, 2 nonzero): [[0]] = 2 [[1]] = "three" - > remove(lst) + ; remove(lst) "three" - > print lst + ; print lst list (1 elements, 1 nonzero): [[0]] = 2 - > remove(lst) + ; remove(lst) 2 - > print lst + ; print lst list (0 elements, 0 nonzero) - > remove(lst) - > print lst + ; remove(lst) + ; print lst list (0 elements, 0 nonzero) LIMITS @@ -65,8 +65,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: remove,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: remove,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/remove,v $ ## ## Under source code control: 1996/03/12 23:10:01 diff --git a/help/reverse b/help/reverse index ca76433..624662a 100644 --- a/help/reverse +++ b/help/reverse @@ -19,8 +19,8 @@ DESCRIPTION as if the matrix were a linear array. EXAMPLE - > A = list(1, 7, 2, 4, 2) - > print reverse(A) + ; A = list(1, 7, 2, 4, 2) + ; print reverse(A) list (5 elements, 5 nonzero): [[0]] = 2 @@ -29,8 +29,8 @@ EXAMPLE [[3]] = 7 [[4]] = 1 - > mat B[2,3] = {1,2,3,4,5,6} - > print reverse(B) + ; mat B[2,3] = {1,2,3,4,5,6} + ; print reverse(B) mat [2,3] (6 elements, 6 nonzero): [0,0] = 6 @@ -65,8 +65,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: reverse,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: reverse,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/reverse,v $ ## ## Under source code control: 1995/07/09 19:41:26 diff --git a/help/rewind b/help/rewind index 6f4c8a0..c6aeabd 100644 --- a/help/rewind +++ b/help/rewind @@ -15,11 +15,11 @@ DESCRIPTION this operation is applied to all user-opened files. EXAMPLE - > f = fopen("curds","r"); - > x = fgetc(f); - > rewind(f); - > y = fgetc(f); - > print x == y + ; f = fopen("curds","r"); + ; x = fgetc(f); + ; rewind(f); + ; y = fgetc(f); + ; print x == y 1 LIMITS @@ -48,8 +48,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: rewind,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: rewind,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/rewind,v $ ## ## Under source code control: 1996/04/30 03:05:18 diff --git a/help/rm b/help/rm index b86de35..605995d 100644 --- a/help/rm +++ b/help/rm @@ -14,8 +14,8 @@ DESCRIPTION removal is performed and "no such file" errors are ignored. EXAMPLE - > rm("junk") - > rm("-f", "more/junk.cal", "curds", "whey") + ; rm("junk") + ; rm("-f", "more/junk.cal", "curds", "whey") LIMITS name must be a non-zero length string @@ -42,8 +42,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: rm,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: rm,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/rm,v $ ## ## Under source code control: 1996/06/30 22:02:58 diff --git a/help/root b/help/root index 801299a..d8579da 100644 --- a/help/root +++ b/help/root @@ -28,16 +28,16 @@ DESCRIPTION obtained by using power(x, 1/n, eps). EXAMPLE - > print root(7, 4, 1e-5), root(7, 4, 1e-10), root(7, 4, 1e-15) + ; print root(7, 4, 1e-5), root(7, 4, 1e-10), root(7, 4, 1e-15) 1.62658 1.6265765617 1.626576561697786 - > print root(1+3i, 3, 1e-5), root(1 + 3i, 3, 1e-10) + ; print root(1+3i, 3, 1e-5), root(1 + 3i, 3, 1e-10) 1.34241+.59361i 1.3424077452+.5936127825i - > print root(-8, 3, 1e-5), root(-8, 34, 1e-5) + ; print root(-8, 3, 1e-5), root(-8, 34, 1e-5) -2 ~1.05853505050032399594+~.09807874962631613016i - > print root(1i, 100, 1e-20) + ; print root(1i, 100, 1e-20) .99987663248166059864+.01570731731182067575i LIMITS @@ -68,8 +68,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.3 $ -## @(#) $Id: root,v 29.3 2005/10/18 10:48:29 chongo Exp $ +## @(#) $Revision: 29.4 $ +## @(#) $Id: root,v 29.4 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/root,v $ ## ## Under source code control: 1995/10/25 04:03:46 diff --git a/help/round b/help/round index 73dd428..4ca79c1 100644 --- a/help/round +++ b/help/round @@ -66,38 +66,38 @@ DESCRIPTION variables, so their values are not changed by the call. EXAMPLES - > a = 7/32, b = -7/32 + ; a = 7/32, b = -7/32 - > print a, b + ; print a, b .21875 -.21875 - > print round(a,3,0), round(a,3,1), round(a,3,2), print round(a,3,3) + ; print round(a,3,0), round(a,3,1), round(a,3,2), print round(a,3,3) .218, .219, .218, .219 - > print round(b,3,0), round(b,3,1), round(b,3,2), print round(b,3,3) + ; print round(b,3,0), round(b,3,1), round(b,3,2), print round(b,3,3) -.219, -.218, -.218, -.219 - > print round(a,3,16), round(a,3,17), round(a,3,18), print round(a,3,19) + ; print round(a,3,16), round(a,3,17), round(a,3,18), print round(a,3,19) .2188 .2188 .2188 .2188 - > print round(a,4,16), round(a,4,17), round(a,4,18), print round(a,4,19) + ; print round(a,4,16), round(a,4,17), round(a,4,18), print round(a,4,19) .2187 .2188 .2187 .2188 - > print round(a,2,8), round(a,3,8), round(a,4,8), round(a,5,8) + ; print round(a,2,8), round(a,3,8), round(a,4,8), round(a,5,8) .22 .218 .2188 .21875 - > print round(a,2,24), round(a,3,24), round(a,4,24), round(a,5,24) + ; print round(a,2,24), round(a,3,24), round(a,4,24), round(a,5,24) .22 .219 .2188 .21875 - > c = 21875 - > print round(c,-2,0), round(c,-2,1), round(c,-3,0), round(c,-3,16) + ; c = 21875 + ; print round(c,-2,0), round(c,-2,1), round(c,-3,0), round(c,-3,16) 21800 21900 21000 22000 - > print round(c,2,32), round(c,2,33), round(c,2,56), round(c,4,56) + ; print round(c,2,32), round(c,2,33), round(c,2,56), round(c,4,56) 21000 22000 22000 21880 - > A = list(1/8, 2/8, 3/8, 4/8, 5/8, 6/8, 7/8) - > print round(A,2,24) + ; A = list(1/8, 2/8, 3/8, 4/8, 5/8, 6/8, 7/8) + ; print round(A,2,24) list(7 elements, 7 nonzero): [[0]] = .12 @@ -138,8 +138,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: round,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: round,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/round,v $ ## ## Under source code control: 1994/09/30 00:52:38 diff --git a/help/rsearch b/help/rsearch index 734f125..8c34218 100644 --- a/help/rsearch +++ b/help/rsearch @@ -72,29 +72,29 @@ Four argument case: position, according as a match is found or not found. EXAMPLE - > L = list(2,"three",4i) - > rsearch(L,"three") + ; L = list(2,"three",4i) + ; rsearch(L,"three") 1 - > rsearch(L,"threes") - > rsearch(L, 4i, 4) - > rsearch(L, 4i, 1) + ; rsearch(L,"threes") + ; rsearch(L, 4i, 4) + ; rsearch(L, 4i, 1) 2 - > f = fopen("foo", "w+") - > fputs(f, "This file has 28 characters.") - > fflush(f) - > rsearch(f, "ha") + ; f = fopen("foo", "w+") + ; fputs(f, "This file has 28 characters.") + ; fflush(f) + ; rsearch(f, "ha") 18 - > ftell(f) + ; ftell(f) 19 - > rsearch(f, "ha", 17) + ; rsearch(f, "ha", 17) 10 - > rsearch(f, "ha", 9) - > ftell(f) + ; rsearch(f, "ha", 9) + ; ftell(f) 0 - > rsearch(f, "ha") + ; rsearch(f, "ha") 18 - > rsearch(f, "ha", 5, 500) + ; rsearch(f, "ha", 5, 500) 18 LIMITS @@ -122,8 +122,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: rsearch,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: rsearch,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/rsearch,v $ ## ## Under source code control: 1994/03/19 03:13:21 diff --git a/help/runtime b/help/runtime index d66596c..230c737 100644 --- a/help/runtime +++ b/help/runtime @@ -16,9 +16,9 @@ EXAMPLE The result is a multiple of 1/CLK_TCK, where CLK_TCK is usually 60. The following is for a XXX machine. - > t = runtime(); - > pi = pi(1e-1000); - > runtime() - t; + ; t = runtime(); + ; pi = pi(1e-1000); + ; runtime() - t; .2 LIMITS @@ -46,8 +46,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: runtime,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: runtime,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/runtime,v $ ## ## Under source code control: 1996/03/12 23:10:01 diff --git a/help/saveval b/help/saveval index 4e65423..bfa23bb 100644 --- a/help/saveval +++ b/help/saveval @@ -25,16 +25,16 @@ DESCRIPTION eval(str). EXAMPLE - > saveval(1); - > a = 27; + ; saveval(1); + ; a = 27; . 27 - > saveval(0); - > a = 45 + ; saveval(0); + ; a = 45 . 27 - > saveval(1); - > a = 63 + ; saveval(1); + ; a = 63 . 63 @@ -63,8 +63,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: saveval,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: saveval,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/saveval,v $ ## ## Under source code control: 1997/09/06 20:03:35 diff --git a/help/scale b/help/scale index fc39bf3..a32d978 100644 --- a/help/scale +++ b/help/scale @@ -23,7 +23,7 @@ DESCRIPTION for which 2^n * x is an integer. EXAMPLE - > print scale(3, 2), scale(3,1), scale(3,0), scale(3,-1), scale(3,-2) + ; print scale(3, 2), scale(3,1), scale(3,0), scale(3,-1), scale(3,-2) 12 6 3 1.5 .75 LIMITS @@ -53,8 +53,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.3 $ -## @(#) $Id: scale,v 29.3 2005/10/18 10:48:29 chongo Exp $ +## @(#) $Revision: 29.4 $ +## @(#) $Id: scale,v 29.4 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/scale,v $ ## ## Under source code control: 1995/12/18 12:34:58 diff --git a/help/scan b/help/scan index a9d209f..190b0bc 100644 --- a/help/scan +++ b/help/scan @@ -18,10 +18,10 @@ DESCRIPTION of strings is less than n, the later x_i are ignored. EXAMPLE - > global a, b, c, d; - > scan(a, 0, c, d) - > 2+3 b=a^2 3+4i 3+"a" - > print a,b,c,d + ; global a, b, c, d; + ; scan(a, 0, c, d) + ; 2+3 b=a^2 3+4i 3+"a" + ; print a,b,c,d 5 25 3+4i Error 3 LIMITS @@ -49,8 +49,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: scan,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: scan,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/scan,v $ ## ## Under source code control: 1996/04/30 03:05:18 diff --git a/help/scanf b/help/scanf index ca559bb..f5f9a5a 100644 --- a/help/scanf +++ b/help/scanf @@ -15,10 +15,10 @@ DESCRIPTION For details see fscanf. EXAMPLE - > global a, b, c - > scanf("%5c", a) + ; global a, b, c + ; scanf("%5c", a) 1 - > a + ; a "Alpha" LIMITS @@ -46,8 +46,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: scanf,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: scanf,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/scanf,v $ ## ## Under source code control: 1996/04/30 03:05:18 diff --git a/help/script b/help/script index 5702e7c..1593466 100644 --- a/help/script +++ b/help/script @@ -198,7 +198,7 @@ Calc shell scripts should display the square-roots of 27 and 2+3i. The output could be piped to another command by | or directed to a file by use of - > or >>. + ; or >>. With no specified input, either sqrts1 or sqrts2 will wait without any prompt for input from the keyboard and as each line @@ -289,8 +289,8 @@ For more information use the following calc commands: ## 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: script,v 29.7 2004/10/23 00:41:11 chongo Exp $ +## @(#) $Revision: 29.8 $ +## @(#) $Id: script,v 29.8 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/script,v $ ## ## Under source code control: 1999/11/30 05:29:48 diff --git a/help/search b/help/search index e9bc26b..39c9599 100644 --- a/help/search +++ b/help/search @@ -79,38 +79,38 @@ DESCRIPTION because the specified search region has insufficient remaining characters. EXAMPLE - > L = list(2,"three",4i) - > search(L,"three") + ; L = list(2,"three",4i) + ; search(L,"three") 1 - > search(L,"threes") - > search(L, 4i, 4) - > search(L, 4i, 1) + ; search(L,"threes") + ; search(L, 4i, 4) + ; search(L, 4i, 1) 2 - > f = fopen("foo", "w+") - > fputs(f, "This file has 28 characters.") - > rewind(f) - > search(f, "ha") + ; f = fopen("foo", "w+") + ; fputs(f, "This file has 28 characters.") + ; rewind(f) + ; search(f, "ha") 10 - > ftell(f) + ; ftell(f) 12 - > search(f, "ha") + ; search(f, "ha") 18 - > search(f, "ha") - > search(f, "ha",) + ; search(f, "ha") + ; search(f, "ha",) 10 - > search(f, "ha", 12) + ; search(f, "ha", 12) 18 - > search(f, "ha", -10) + ; search(f, "ha", -10) 18 - > search(f, "ha", ,) + ; search(f, "ha", ,) 10 - > search(f, "ha", 11, 19) - > ftell(f) + ; search(f, "ha", 11, 19) + ; ftell(f) 18 - > search(f, "ha", 11, 20) + ; search(f, "ha", 11, 20) 18 - > search(f, "ha", 5, 500) + ; search(f, "ha", 5, 500) 10 LIMITS @@ -139,8 +139,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: search,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: search,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/search,v $ ## ## Under source code control: 1994/03/19 03:13:21 diff --git a/help/sec b/help/sec index 4868b1c..dd80534 100644 --- a/help/sec +++ b/help/sec @@ -15,7 +15,7 @@ DESCRIPTION in absolute value than .75 * eps. EXAMPLE - > print sec(1, 1e-5), sec(1, 1e-10), sec(1, 1e-15), sec(1, 1e-20) + ; print sec(1, 1e-5), sec(1, 1e-10), sec(1, 1e-15), sec(1, 1e-20) 1.85082 1.8508157177 1.850815717680926 1.85081571768092561791 LIMITS @@ -44,8 +44,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: sec,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: sec,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/sec,v $ ## ## Under source code control: 1995/11/13 03:49:00 diff --git a/help/sech b/help/sech index 02a3fec..d264dd3 100644 --- a/help/sech +++ b/help/sech @@ -17,7 +17,7 @@ DESCRIPTION sech(x) = 2/(exp(x) + exp(-x)) EXAMPLE - > print sech(1, 1e-5), sech(1, 1e-10), sech(1, 1e-15), sech(1, 1e-20) + ; print sech(1, 1e-5), sech(1, 1e-10), sech(1, 1e-15), sech(1, 1e-20) .64805 .6480542737 .648054273663885 .64805427366388539958 LIMITS @@ -46,8 +46,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: sech,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: sech,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/sech,v $ ## ## Under source code control: 1995/11/13 03:49:00 diff --git a/help/seed b/help/seed index 13ba79a..29a7828 100644 --- a/help/seed +++ b/help/seed @@ -36,10 +36,10 @@ DESCRIPTION as an argument to a seed function such as srand() or srandom(). EXAMPLE - > print srand(seed()) + ; print srand(seed()) RAND state - > print srandom(seed()) + ; print srandom(seed()) RAND state LIMITS @@ -67,8 +67,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.3 $ -## @(#) $Id: seed,v 29.3 2001/05/13 13:26:26 chongo Exp $ +## @(#) $Revision: 29.4 $ +## @(#) $Id: seed,v 29.4 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/seed,v $ ## ## Under source code control: 1999/10/03 10:04:29 diff --git a/help/segment b/help/segment index f3b2372..30e454b 100644 --- a/help/segment +++ b/help/segment @@ -20,15 +20,15 @@ DESCRIPTION If y < z, x == join(head(x,y), segment(x,y,z), tail(x, size(x) - z - 1)). EXAMPLE - > A = list(2, 3, 5, 7, 11) - > segment(A, 1, 3) + ; A = list(2, 3, 5, 7, 11) + ; segment(A, 1, 3) list (3 members, 3 nonzero): [[0]] = 3 [[1]] = 5 [[2]] = 7 - > segment(A, 3, 1) + ; segment(A, 3, 1) list (3 members, 3 nonzero): [[0]] = 7 @@ -61,8 +61,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: segment,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: segment,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/segment,v $ ## ## Under source code control: 1995/07/10 02:09:31 diff --git a/help/select b/help/select index 7cabb5b..50904db 100644 --- a/help/select +++ b/help/select @@ -19,9 +19,9 @@ DESCRIPTION EXAMPLE - > define f(x) = x > 5 - > A = list(2,4,6,8,2,7) - > print select(A, "f") + ; define f(x) = x > 5 + ; A = list(2,4,6,8,2,7) + ; print select(A, "f") list (3 elements, 3 nonzero): [[0]] = 6 @@ -53,8 +53,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: select,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: select,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/select,v $ ## ## Under source code control: 1995/07/10 02:09:31 diff --git a/help/sgn b/help/sgn index eb0f6b9..851eb52 100644 --- a/help/sgn +++ b/help/sgn @@ -24,10 +24,10 @@ DESCRIPTION EXAMPLE - > print sgn(27), sgn(1e-20), sgn(0), sgn(-45) + ; print sgn(27), sgn(1e-20), sgn(0), sgn(-45) 1 1 0 -1 - > print sgn(2+3i), sgn(6i), sgn(-7+4i), sgn(-6), sgn(-6-3i), sgn(-2i) + ; print sgn(2+3i), sgn(6i), sgn(-7+4i), sgn(-6), sgn(-6-3i), sgn(-2i) 1+1i 1i -1+1i -1 -1-1i -1i LIMITS @@ -55,8 +55,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: sgn,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: sgn,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/sgn,v $ ## ## Under source code control: 1995/10/25 04:03:46 diff --git a/help/sha b/help/sha index 1d2fd77..c2dcf5c 100644 --- a/help/sha +++ b/help/sha @@ -47,35 +47,35 @@ DESCRIPTION sha(sha(h,x,y)) number numeric value of the above call EXAMPLE - > base(16) + ; base(16) 0xa - > sha() + ; sha() sha hash state - > sha(sha()) + ; sha(sha()) 0xf96cea198ad1dd5617ac084a3d92c6107708c0ef - > sha("x", "y", "z") == sha("xyz") + ; sha("x", "y", "z") == sha("xyz") 1 - > sha("x", "y", "z") == sha("xy") + ; sha("x", "y", "z") == sha("xy") 0 - > sha(sha("this is", 7^19-8, "a composit", 3i+4.5, "hash")) + ; sha(sha("this is", 7^19-8, "a composit", 3i+4.5, "hash")) 0x21e42319a26787046c2b28b7ae70f1b54bf0ba2a - > x = sha(list(1,2,3), "curds and whey", 2^21701-1, pi()) - > x + ; x = sha(list(1,2,3), "curds and whey", 2^21701-1, pi()) + ; x sha hash state - > sha(x) + ; sha(x) 0xc9e155522ea4a38d85340e6f1c2e36636950ea7e - > y = sha() - > y = sha(y, list(1,2,3), "curds and whey") - > y = sha(y, 2^21701-1) - > y = sha(y, pi()) - > y + ; y = sha() + ; y = sha(y, list(1,2,3), "curds and whey") + ; y = sha(y, 2^21701-1) + ; y = sha(y, pi()) + ; y sha hash state - > sha(y) + ; sha(y) 0xc9e155522ea4a38d85340e6f1c2e36636950ea7e LIMITS @@ -115,8 +115,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: sha,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: sha,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/sha,v $ ## ## Under source code control: 1997/03/22 06:25:51 diff --git a/help/sha1 b/help/sha1 index 728449c..cec14e3 100644 --- a/help/sha1 +++ b/help/sha1 @@ -47,35 +47,35 @@ DESCRIPTION sha1(sha1(h,x,y)) number numeric value of the above call EXAMPLE - > base(16) + ; base(16) 0xa - > sha1() + ; sha1() sha1 hash state - > sha1(sha1()) + ; sha1(sha1()) 0xda39a3ee5e6b4b0d3255bfef95601890afd80709 - > sha1("x", "y", "z") == sha1("xyz") + ; sha1("x", "y", "z") == sha1("xyz") 1 - > sha1("x", "y", "z") == sha1("xy") + ; sha1("x", "y", "z") == sha1("xy") 0 - > sha1(sha1("this is", 7^19-8, "a composit", 3i+4.5, "hash")) + ; sha1(sha1("this is", 7^19-8, "a composit", 3i+4.5, "hash")) 0xc3e1b562bf45b3bcfc055ac65b5b39cdeb6a6c55 - > x = sha1(list(1,2,3), "curds and whey", 2^21701-1, pi()) - > x + ; x = sha1(list(1,2,3), "curds and whey", 2^21701-1, pi()) + ; x sha1 hash state - > sha1(x) + ; sha1(x) 0x988d2de4584b7536aa9a50a5749707a37affa1b5 - > y = sha1() - > y = sha1(y, list(1,2,3), "curds and whey") - > y = sha1(y, 2^21701-1) - > y = sha1(y, pi()) - > y + ; y = sha1() + ; y = sha1(y, list(1,2,3), "curds and whey") + ; y = sha1(y, 2^21701-1) + ; y = sha1(y, pi()) + ; y sha1 hash state - > sha1(y) + ; sha1(y) 0x988d2de4584b7536aa9a50a5749707a37affa1b5 LIMITS @@ -115,8 +115,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: sha1,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: sha1,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/sha1,v $ ## ## Under source code control: 1997/03/23 00:01:18 diff --git a/help/sin b/help/sin index 8a25ef0..44c386e 100644 --- a/help/sin +++ b/help/sin @@ -15,14 +15,14 @@ DESCRIPTION absolute value than .75 * eps. EXAMPLE - > print sin(1, 1e-5), sin(1, 1e-10), sin(1, 1e-15), sin(1, 1e-20) + ; print sin(1, 1e-5), sin(1, 1e-10), sin(1, 1e-15), sin(1, 1e-20) .84147 .8414709848 .841470984807896 .84147098480789650665 - > print sin(2 + 3i, 1e-5), sin(2 + 3i, 1e-10) + ; print sin(2 + 3i, 1e-5), sin(2 + 3i, 1e-10) 9.1545-4.16891i 9.1544991469-4.16890696i - > pi = pi(1e-20) - > print sin(pi/6, 1e-10), sin(pi/2, 1e-10), sin(pi, 1e-10) + ; pi = pi(1e-20) + ; print sin(pi/6, 1e-10), sin(pi/2, 1e-10), sin(pi, 1e-10) .5 1 0 LIMITS @@ -51,8 +51,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.3 $ -## @(#) $Id: sin,v 29.3 2005/10/18 10:48:29 chongo Exp $ +## @(#) $Revision: 29.4 $ +## @(#) $Id: sin,v 29.4 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/sin,v $ ## ## Under source code control: 1994/03/19 01:40:28 diff --git a/help/sinh b/help/sinh index 991bec8..69c2e7e 100644 --- a/help/sinh +++ b/help/sinh @@ -17,7 +17,7 @@ DESCRIPTION sinh(x) = (exp(x) - exp(-x))/2 EXAMPLE - > print sinh(1, 1e-5), sinh(1, 1e-10), sinh(1, 1e-15), sinh(1, 1e-20) + ; print sinh(1, 1e-5), sinh(1, 1e-10), sinh(1, 1e-15), sinh(1, 1e-20) 1.1752 1.1752011936 1.175201193643801 1.17520119364380145688 LIMITS @@ -46,8 +46,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: sinh,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: sinh,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/sinh,v $ ## ## Under source code control: 1994/03/19 01:40:29 diff --git a/help/size b/help/size index b954dd9..aeb7ce5 100644 --- a/help/size +++ b/help/size @@ -30,22 +30,22 @@ DESCRIPTION named block numer of octets of data it currently holds EXAMPLE - > print size(null()), size(3), size(2 - 7i), size("abc") + ; print size(null()), size(3), size(2 - 7i), size("abc") 0 1 1 1 - > mat M[2,3] - > print size(M), size(list()), size(list(2,3,4)) + ; mat M[2,3] + ; print size(M), size(list()), size(list(2,3,4)) 6 0 3 - > A = assoc() - > A[1] = 3, A[1,2] = 6, A["three"] = 5 - > print size(A) + ; A = assoc() + ; A[1] = 3, A[1,2] = 6, A["three"] = 5 + ; print size(A) 3 - > obj point {x,y} - > obj point P = {4,-5} - > define point_size(a) = abs(a.x) + abs(a.y) - > print size(P) + ; obj point {x,y} + ; obj point P = {4,-5} + ; define point_size(a) = abs(a.x) + abs(a.y) + ; print size(P) 9 LIMITS @@ -73,8 +73,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: size,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: size,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/size,v $ ## ## Under source code control: 1994/03/19 03:13:22 diff --git a/help/sizeof b/help/sizeof index be9b9bb..d206069 100644 --- a/help/sizeof +++ b/help/sizeof @@ -56,24 +56,24 @@ EXAMPLES the system being used. The following were for an SGI R4k machine in 32-bit mode: - > print sizeof(null()), sizeof(0), sizeof(3), sizeof(2^32 - 1), sizeof(2^32) + ; print sizeof(null()), sizeof(0), sizeof(3), sizeof(2^32 - 1), sizeof(2^32) 8 68 68 68 72 - > x = sqrt(2, 1e-100); print sizeof(x), sizeof(num(x)), sizeof(den(x)) + ; x = sqrt(2, 1e-100); print sizeof(x), sizeof(num(x)), sizeof(den(x)) 148 108 108 - > print sizeof(list()), sizeof(list(1)), sizeof(list(1,2)) + ; print sizeof(list()), sizeof(list(1)), sizeof(list(1,2)) 28 104 180 - > print sizeof(list()),sizeof(list(1)),sizeof(list(1,2)),sizeof(list(1,2,3)) + ; print sizeof(list()),sizeof(list(1)),sizeof(list(1,2)),sizeof(list(1,2,3)) 28 104 180 256 - > mat A[] = {1}; mat B[] = {1,2}; mat C[] = {1,2,3}; mat D[100,100]; - > print sizeof(A), sizeof(B), sizeof(C), sizeof(D) + ; mat A[] = {1}; mat B[] = {1,2}; mat C[] = {1,2,3}; mat D[100,100]; + ; print sizeof(A), sizeof(B), sizeof(C), sizeof(D) 124 192 260 680056 - > obj point {x,y,z} - > obj point P = {1,2,3}; print sizeof(P) + ; obj point {x,y,z} + ; obj point P = {1,2,3}; print sizeof(P) 274 LIMITS @@ -101,8 +101,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: sizeof,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: sizeof,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/sizeof,v $ ## ## Under source code control: 1996/05/24 02:04:04 diff --git a/help/sleep b/help/sleep index cefb3aa..ad1806d 100644 --- a/help/sleep +++ b/help/sleep @@ -33,8 +33,8 @@ DESCRIPTION > EXAMPLE - > sleep(1/3); - > sleep(20); + ; sleep(1/3); + ; sleep(20); LIBRARY none @@ -58,8 +58,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: sleep,v 29.2 2000/12/17 12:27:58 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: sleep,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/sleep,v $ ## ## Under source code control: 2000/12/14 01:33:00 diff --git a/help/sort b/help/sort index bdf1d8f..27ec5ad 100644 --- a/help/sort +++ b/help/sort @@ -207,8 +207,8 @@ DESCRIPTION 1 The order of the elements is reversed EXAMPLES - > A = list(1, 7, 2, 4, 2) - > print sort(A) + ; A = list(1, 7, 2, 4, 2) + ; print sort(A) list (5 elements, 5 nonzero): [[0]] = 1 @@ -217,8 +217,8 @@ EXAMPLES [[3]] = 4 [[4]] = 7 - > B = list("pear", 2, null(), -3, "orange", null(), "apple", 0) - > print sort(B) + ; B = list("pear", 2, null(), -3, "orange", null(), "apple", 0) + ; print sort(B) list (8 elements, 7 nonzero): [[0]] = NULL @@ -230,8 +230,8 @@ EXAMPLES [[6]] = "orange" [[7]] = "pear" - > define precedes(a,b) = (iseven(a) && isodd(b)) - > print sort(A) + ; define precedes(a,b) = (iseven(a) && isodd(b)) + ; print sort(A) list (5 elements, 5 nonzero): [[0]] = 2 @@ -265,8 +265,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: sort,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: sort,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/sort,v $ ## ## Under source code control: 1995/07/09 19:41:26 diff --git a/help/sqrt b/help/sqrt index da88732..1f395f3 100644 --- a/help/sqrt +++ b/help/sqrt @@ -105,18 +105,18 @@ DESCRIPTION EXAMPLE - > eps = 1e-4 - > print sqrt(4,eps,0), sqrt(4,eps,64), sqrt(8i,eps,0), sqrt(8i, eps, 64) + ; eps = 1e-4 + ; print sqrt(4,eps,0), sqrt(4,eps,64), sqrt(8i,eps,0), sqrt(8i, eps, 64) 2 -2 2+2i -2-2i - > print sqrt(2,eps,0), sqrt(2,eps,1), sqrt(2,eps,24) + ; print sqrt(2,eps,0), sqrt(2,eps,1), sqrt(2,eps,24) 1.4142 1.4143 1.4142 - > x = 1.2345678^2 - > print sqrt(x,eps,24), sqrt(x,eps,32), sqrt(x,eps,96) + ; x = 1.2345678^2 + ; print sqrt(x,eps,24), sqrt(x,eps,32), sqrt(x,eps,96) 1.2346 1.2345678 -1.2345678 - > print sqrt(.00005^2, eps, 24), sqrt(.00015^2, eps, 24) + ; print sqrt(.00005^2, eps, 24), sqrt(.00015^2, eps, 24) 0 .0002 LIMITS @@ -147,8 +147,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.3 $ -## @(#) $Id: sqrt,v 29.3 2005/10/18 10:48:29 chongo Exp $ +## @(#) $Revision: 29.4 $ +## @(#) $Id: sqrt,v 29.4 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/sqrt,v $ ## ## Under source code control: 1995/09/18 03:54:32 diff --git a/help/srand b/help/srand index 51341fa..1c26a4c 100644 --- a/help/srand +++ b/help/srand @@ -122,22 +122,22 @@ DESCRIPTION See the rand help file for details on the generator. EXAMPLE - > srand(0x8d2dcb2bed3212844f4ad31) + ; srand(0x8d2dcb2bed3212844f4ad31) RAND state - > state = srand(); - > print rand(123), rand(123), rand(123), rand(123), rand(123), rand(123); + ; state = srand(); + ; print rand(123), rand(123), rand(123), rand(123), rand(123), rand(123); 80 95 41 78 100 27 - > print rand(123), rand(123), rand(123), rand(123), rand(123), rand(123); + ; print rand(123), rand(123), rand(123), rand(123), rand(123), rand(123); 122 109 12 95 80 32 - > state2 = srand(state); - > print rand(123), rand(123), rand(123), rand(123), rand(123), rand(123); + ; state2 = srand(state); + ; print rand(123), rand(123), rand(123), rand(123), rand(123), rand(123); 80 95 41 78 100 27 - > print rand(123), rand(123), rand(123), rand(123), rand(123), rand(123); + ; print rand(123), rand(123), rand(123), rand(123), rand(123), rand(123); 122 109 12 95 80 32 - > state3 = srand(); - > print state3 == state2; + ; state3 = srand(); + ; print state3 == state2; 1 - > print rand(); + ; print rand(); 10710588361472584495 LIMITS @@ -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.3 $ -## @(#) $Id: srand,v 29.3 2001/04/14 22:46:33 chongo Exp $ +## @(#) $Revision: 29.4 $ +## @(#) $Id: srand,v 29.4 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/srand,v $ ## ## Under source code control: 1996/01/01 04:19:07 diff --git a/help/srandom b/help/srandom index f92c836..803da93 100644 --- a/help/srandom +++ b/help/srandom @@ -306,22 +306,22 @@ DESCRIPTION See the random help file for details on the generator. EXAMPLE - > srandom(0x8d2dcb2bed3212844f4ad31) + ; srandom(0x8d2dcb2bed3212844f4ad31) RANDOM state - > state = srandom(); - > print random(123), random(123), random(123), random(123), random(123) + ; state = srandom(); + ; print random(123), random(123), random(123), random(123), random(123) 42 58 57 82 15 - > print random(123), random(123), random(123), random(123), random(123) + ; print random(123), random(123), random(123), random(123), random(123) 90 121 109 114 80 - > state2 = srandom(state); - > print random(123), random(123), random(123), random(123), random(123) + ; state2 = srandom(state); + ; print random(123), random(123), random(123), random(123), random(123) 42 58 57 82 15 - > print random(123), random(123), random(123), random(123), random(123) + ; print random(123), random(123), random(123), random(123), random(123) 90 121 109 114 80 - > state3 = srandom(); - > print state3 == state2; + ; state3 = srandom(); + ; print state3 == state2; 1 - > print random(); + ; print random(); 2101582493746841221 LIMITS @@ -354,8 +354,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.3 $ -## @(#) $Id: srandom,v 29.3 2001/05/13 13:26:26 chongo Exp $ +## @(#) $Revision: 29.4 $ +## @(#) $Id: srandom,v 29.4 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/srandom,v $ ## ## Under source code control: 1997/02/17 01:18:22 diff --git a/help/ssq b/help/ssq index 0d10767..d668f2c 100644 --- a/help/ssq +++ b/help/ssq @@ -14,11 +14,11 @@ DESCRIPTION Returns the value of x1^2 + x2^2 + ... EXAMPLE - > print ssq(1,2,3), ssq(1+2i, 3-4i, 5 +6i) + ; print ssq(1,2,3), ssq(1+2i, 3-4i, 5 +6i) 14 -21+40i - > mat A[2,2] = {1,2,3,4}; mat B[2,2] = {5,6,7,8} - > print ssq(A, B, A + B) + ; mat A[2,2] = {1,2,3,4}; mat B[2,2] = {5,6,7,8} + ; print ssq(A, B, A + B) mat [2,2] (4 elements, 4 nonzero): [0,0] = 190 @@ -51,8 +51,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: ssq,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: ssq,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/ssq,v $ ## ## Under source code control: 1995/10/25 04:03:46 diff --git a/help/str b/help/str index d77221b..9d59397 100644 --- a/help/str +++ b/help/str @@ -21,15 +21,15 @@ DESCRIPTION this are "mode", "mode2", "display", "outround", "tilde", "leadzero", EXAMPLE - > str("") + ; str("") "" - > str(null()) + ; str(null()) "" - > print str(123), str("+"), str(4i), str("is the same as"), str(123+4i) + ; print str(123), str("+"), str(4i), str("is the same as"), str(123+4i) 123 + 4i is the same as 3+4i - > base2(16), - > print str(23209) + ; base2(16), + ; print str(23209) 23209 /* 0x5aa9 */ LIMITS @@ -63,8 +63,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.3 $ -## @(#) $Id: str,v 29.3 2002/12/29 09:19:56 chongo Exp $ +## @(#) $Revision: 29.4 $ +## @(#) $Id: str,v 29.4 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/str,v $ ## ## Under source code control: 1995/10/05 04:52:27 diff --git a/help/strcat b/help/strcat index 3e94012..af6e326 100644 --- a/help/strcat +++ b/help/strcat @@ -16,8 +16,8 @@ DESCRIPTION of the component strings. EXAMPLE - > A = "abc"; B = "XY"; C = " "; - > print strcat(A, B, C, B, A) + ; A = "abc"; B = "XY"; C = " "; + ; print strcat(A, B, C, B, A) abcXY XYabc LIMITS @@ -45,8 +45,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: strcat,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: strcat,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/strcat,v $ ## ## Under source code control: 1995/10/05 04:52:27 diff --git a/help/strcmp b/help/strcmp new file mode 100644 index 0000000..a8a52e0 --- /dev/null +++ b/help/strcmp @@ -0,0 +1,40 @@ +NAME + strcmp - compare two strings in the customary ordering of strings + +SYNOPSIS + strcmp(s1, s2) + +TYPES + s1 string + s2 string + + return integer (1, 0 or -1) + +DESCRIPTION + Let n1 = size(s1), n2 = size(s2) and m = min(n1, n2). + This function compares up to m values of consecutive characters + in the strings s1 and s2. If an inequality is encountered, the + function returns 1 or -1 according as the greater character is + in s1 or s2. If there has been no inequality, the function + returns 1, 0, or -1 according as n1 is greater than, equal to, + or less than n2. + Note that null characters within the strings are included in the + comparison. + +EXAMPLE + strcmp("ab", "abc") == -1 + strcmp("abc", "abb") == 1 + strcmp("abc", "abc") == 0 + strcmp("abc", "abd") == -1 + strcmp("abc\0", "abc") == 1 + strcmp("a\0b", "a\0c") == -1 + + +LIMITS + none + +LINK LIBRARY + FLAG stringrel(STRING *s1, STRING *s2) + +SEE ALSO + strncmp diff --git a/help/strcpy b/help/strcpy new file mode 100644 index 0000000..dfaa1ca --- /dev/null +++ b/help/strcpy @@ -0,0 +1,41 @@ +NAME + strcpy - copy head or all of a string to head or all of a string + +SYNOPSIS + strcpy(s1, s2) + +TYPES + s1 string + s2 string + + return string + +DESCRIPTION + Let n1 = size(s1), n2 = size(n2), and m = min(n1, n2). + This function replaces the first m characters of s1 by the first + m characters of s2, and if m < n1, replaces the next character of + s1 by '\0'. The size of s1 and any later characters of s1 are unchanged. + s1, with its new value, is returned. + Unlike the C Library function with the same name, this function does + not require n1 to be greater than or equal to n2, but if this is so, + normal printing of the returned value will give the same result as + normal printing of s2. + +EXAMPLE + strcpy("", "xyz") == "" + strcpy("a", "xyz") == "x" + strcpy("ab", "xyz") == "xy" + strcpy("abc", "xyz") == "xyz" + strcpy("abcd", "xyz") == "xyz\0" + strcpy("abcde", "xyz") == "xyz\0e" + strcpy("abcdef", "xyz") == "xyz\0ef" + strcpy("abc", "") == "\0bc" + +LIMITS + none + +LINK LIBRARY + STRING* stringcpy(STRING *s1, STRING *s2) + +SEE ALSO + strncpy diff --git a/help/strerror b/help/strerror index a6d299f..ec4b111 100644 --- a/help/strerror +++ b/help/strerror @@ -22,24 +22,24 @@ DESCRIPTION EXAMPLE System error messages may be different for different systems. - > errmax(errcount()+3) + ; errmax(errcount()+3) 0 - > strerror(2) + ; strerror(2) "No such file or directory" - > x = 3 * ("a" + "b") - > print strerror(x) + ; x = 3 * ("a" + "b") + ; print strerror(x) Bad arguments for + - > a = newerror("alpha") - > print strerror(a) + ; a = newerror("alpha") + ; print strerror(a) alpha - > print strerror(999) + ; print strerror(999) Error 999 - > a = 1/0 - > print strerror() + ; a = 1/0 + ; print strerror() Division by zero LIMITS @@ -49,9 +49,10 @@ LINK LIBRARY none SEE ALSO - errcount, errmax, error, iserror, errno, newerror, errorcodes + errcount, errmax, error, iserror, errno, newerror, errorcodes, + stoponerror -## Copyright (C) 1999 Landon Curt Noll +## Copyright (C) 1999-2006 Landon Curt Noll ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License @@ -67,8 +68,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: strerror,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.4 $ +## @(#) $Id: strerror,v 29.4 2006/05/21 07:31:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/strerror,v $ ## ## Under source code control: 1996/04/30 03:05:18 diff --git a/help/strlen b/help/strlen index b62abb2..82d7d41 100644 --- a/help/strlen +++ b/help/strlen @@ -13,7 +13,7 @@ DESCRIPTION strlen(x) returns the number of characters in x EXAMPLE - > print strlen(""), strlen("abc"), strlen("a b\tc\\d") + ; print strlen(""), strlen("abc"), strlen("a b\tc\\d") 0 3 7 LIMITS @@ -41,8 +41,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: strlen,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: strlen,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/strlen,v $ ## ## Under source code control: 1995/10/05 04:52:27 diff --git a/help/strncmp b/help/strncmp new file mode 100644 index 0000000..2272c7d --- /dev/null +++ b/help/strncmp @@ -0,0 +1,44 @@ +NAME + strncmp - compare two strings up to a specified number of characters + +SYNOPSIS + strncmp(s1, s2, n) + +TYPES + s1 string + s2 string + n nonnegative integer + + return integer (1, 0 or -1) + +DESCRIPTION + Let n1 = size(s1), n2 = size(s2) and m = min(n1, n2, n). + This function compares up to m values of consecutive characters + in the strings s1 and s2. If an inequality is encountered, the + function returns 1 or -1 according as the greater character is + in s1 or s2. If there has been no inequality, the function + returns 1, 0, or -1 according as min(n1, n) is greater than, equal + to, or less than min(n2, n); in particular, if n1 and n2 are + both greater than equal to n, 0 is returned. + + +EXAMPLE +strncmp("abc", "xyz", 0) == 0 +strncmp("abc", "xyz", 1) == -1 +strncmp("abc", "", 1) == 1 +strncmp("a", "b", 2) == -1 +strncmp("ab", "ac", 2) == -1 +strncmp("\0ac", "\0b", 2) == -1 +strncmp("ab", "abc", 2) == 0 +strncmp("abc", "abd", 2) == 0 + + +LIMITS + none + +LINK LIBRARY + This function uses FLAG stringrel(STRING *s1, STRING *s2), + temporarily replacing the string sizes by min(n1,n) and min(n2,n). + +SEE ALSO + strcmp diff --git a/help/strncpy b/help/strncpy new file mode 100644 index 0000000..3f3bf72 --- /dev/null +++ b/help/strncpy @@ -0,0 +1,39 @@ +NAME + strncpy - copy a number of chracters from head or all of a stringr + to head or all of a string + +SYNOPSIS + strncpy(s1, s2, n) + +TYPES + s1 string + s2 string + n nonnegative integer + + return string + +DESCRIPTION + Let n1 = size(s1), n2 = size(n2), and m = min(n1, n2, n). + This function replaces the first m characters of s1 by the first + m characters of s2, and if min(n1, n) > n2, replaces the next + min(n1,n) - n2 characters of s1 by '\0'. The size of s1 and any + later characters of s1 are unchanged. The function returns s1, with + new value. + +EXAMPLE + strncpy("abcdef", "xyz", 0) == "abcdef" + strncpy("abcdef", "xyz", 1) == "xbcdef" + strncpy("abcdef", "xyz", 2) == "xycdef" + strncpy("abcdef", "xyz", 3) == "xyzdef" + strncpy("abcdef", "xyz", 4) == "xyz\0ef" + strncpy("abcdef", "xyz", 5) == "xyz\0\0f" + strncpy("ab", "xyz", 3) == "xy" + +LIMITS + none + +LINK LIBRARY + STRING* stringncpy(STRING *s1, STRING *s2, long num) + +SEE ALSO + strcpy diff --git a/help/strpos b/help/strpos index da0e388..0dffee2 100644 --- a/help/strpos +++ b/help/strpos @@ -16,17 +16,17 @@ DESCRIPTION found at the beginning of s, 1 is returned. EXAMPLE - > strpos("abcdefg", "c") + ; strpos("abcdefg", "c") 3 - > strpos("abcdefg", "def") + ; strpos("abcdefg", "def") 4 - > strpos("abcdefg", "defg") + ; strpos("abcdefg", "defg") 4 - > strpos("abcdefg", "defgh") + ; strpos("abcdefg", "defgh") 0 - > strpos("abcdefg", "abc") + ; strpos("abcdefg", "abc") 1 - > strpos("abcdefg", "xyz") + ; strpos("abcdefg", "xyz") 0 @@ -55,8 +55,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: strpos,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: strpos,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/strpos,v $ ## ## Under source code control: 1995/07/09 03:48:57 diff --git a/help/strprintf b/help/strprintf index bececf2..1a97e5f 100644 --- a/help/strprintf +++ b/help/strprintf @@ -15,15 +15,15 @@ DESCRIPTION would be printed to standard output by printf(fmt, x_1, x_2, ...). EXAMPLE - > strprintf("h=%d, i=%d", 2, 3); + ; strprintf("h=%d, i=%d", 2, 3); "h=2, i=3" - > c = config("epsilon", 1e-6); c = config("display", 6); - > c = config("tilde", 1); c = config("outround", 0); - > c = config("fullzero", 0); - > fmt = "%f,%10f,%-10f,%10.4f,%.4f,%.f.\n"; - > a = sqrt(3); - > strprintf(fmt,a,a,a,a,a,a); + ; c = config("epsilon", 1e-6); c = config("display", 6); + ; c = config("tilde", 1); c = config("outround", 0); + ; c = config("fullzero", 0); + ; fmt = "%f,%10f,%-10f,%10.4f,%.4f,%.f.\n"; + ; a = sqrt(3); + ; strprintf(fmt,a,a,a,a,a,a); "1.732051, 1.732051,1.732051 , ~1.7320,~1.7320,~1. " @@ -52,8 +52,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: strprintf,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: strprintf,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/strprintf,v $ ## ## Under source code control: 1996/03/12 22:50:41 diff --git a/help/strscan b/help/strscan index 7555301..e6017b2 100644 --- a/help/strscan +++ b/help/strscan @@ -20,10 +20,10 @@ DESCRIPTION EXAMPLE global a,b - > strscan(" 2+3 a^2 print(b)", a, b, 0); + ; strscan(" 2+3 a^2 print(b)", a, b, 0); 25 3 - > print a,b + ; print a,b 5 25 LIMITS @@ -51,8 +51,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: strscan,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: strscan,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/strscan,v $ ## ## Under source code control: 1996/04/30 03:05:18 diff --git a/help/strscanf b/help/strscanf index 7aeb92e..53e14a4 100644 --- a/help/strscanf +++ b/help/strscanf @@ -93,17 +93,17 @@ DESCRIPTION EXAMPLE - > global a, b, c, d - > A = "abc xyz 234.6 alpha" - > strscanf(A, "%s%*[^0123456789]%f%n", a, b, c) + ; global a, b, c, d + ; A = "abc xyz 234.6 alpha" + ; strscanf(A, "%s%*[^0123456789]%f%n", a, b, c) 3 - > print a, b, c - > abc 234.6 13 + ; print a, b, c + ; abc 234.6 13 - > strscanf(A, "%*13c%s", d); + ; strscanf(A, "%*13c%s", d); 1 - > print d - > alpha + ; print d + ; alpha LIMITS none - XXX - is this correct? @@ -130,8 +130,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: strscanf,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: strscanf,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/strscanf,v $ ## ## Under source code control: 1996/04/30 03:05:18 diff --git a/help/substr b/help/substr index c577cfe..7cfa172 100644 --- a/help/substr +++ b/help/substr @@ -24,8 +24,8 @@ DESCRIPTION If pos = 0, the result is the same as for pos = 1. EXAMPLE - > A = "abcde"; - > print substr(A,0,2), substr(A,1,2), substr(A,4,1), substr(A,3,5) + ; A = "abcde"; + ; print substr(A,0,2), substr(A,1,2), substr(A,4,1), substr(A,3,5) ab ab d cde LIMITS @@ -53,8 +53,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: substr,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: substr,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/substr,v $ ## ## Under source code control: 1995/10/05 04:52:27 diff --git a/help/sum b/help/sum index 17b074a..e029f7a 100644 --- a/help/sum +++ b/help/sum @@ -31,23 +31,23 @@ DESCRIPTION the sum of the arguments. EXAMPLE - > print sum(2), sum(5, 3, 7, 2, 9), sum(3.2, -0.5, 8.7, -1.2, 2.5) + ; print sum(2), sum(5, 3, 7, 2, 9), sum(3.2, -0.5, 8.7, -1.2, 2.5) 2 26 12.7 - > print sum(list(3,5), 7, list(6, list(7,8), 2)) + ; print sum(list(3,5), 7, list(6, list(7,8), 2)) 38 - > obj point {x, y} - > define point_add(a,b) = obj point = {a.x + b.x, a.y + b.y} - > obj point A = {1, 5} - > obj point B = {1, 4} - > obj point C = {3, 3} - > print sum(A, B, C) + ; obj point {x, y} + ; define point_add(a,b) = obj point = {a.x + b.x, a.y + b.y} + ; obj point A = {1, 5} + ; obj point B = {1, 4} + ; obj point C = {3, 3} + ; print sum(A, B, C) obj point {5, 12} - > define point_sum(a) = a.x - > print sum(A, B, C) + ; define point_sum(a) = a.x + ; print sum(A, B, C) 5 LIMITS @@ -75,8 +75,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: sum,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: sum,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/sum,v $ ## ## Under source code control: 1997/03/10 03:59:59 diff --git a/help/swap b/help/swap index 3d66aba..1d58750 100644 --- a/help/swap +++ b/help/swap @@ -23,10 +23,10 @@ DESCRIPTION memory used. EXAMPLE - > x = 3/4; y = "abc"; print x, y, swap(x,y), x, y + ; x = 3/4; y = "abc"; print x, y, swap(x,y), x, y .75 abc abc .75 - > A = list(1,2,3); mat B[3] = {4,5,6}; swap(A[[1]], B[1]); print A[[1]], B[1] + ; A = list(1,2,3); mat B[3] = {4,5,6}; swap(A[[1]], B[1]); print A[[1]], B[1] 5 2 LIMITS @@ -54,8 +54,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: swap,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: swap,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/swap,v $ ## ## Under source code control: 1995/12/18 12:34:58 diff --git a/help/system b/help/system index 704d642..50aae7b 100644 --- a/help/system +++ b/help/system @@ -25,13 +25,13 @@ DESCRIPTION EXAMPLE - > system("") + ; system("") 0 - > system("true") + ; system("true") 0 - > system("exit 2") + ; system("exit 2") 512 - > system("date") + ; system("date") Sun Jul 9 03:21:48 PDT 1995 0 @@ -60,8 +60,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: system,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: system,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/system,v $ ## ## Under source code control: 1995/07/09 03:48:57 diff --git a/help/tail b/help/tail index 79afab9..3262c04 100644 --- a/help/tail +++ b/help/tail @@ -26,14 +26,14 @@ DESCRIPTION For any integer y, x == join(head(x,-y), tail(x,y)). EXAMPLE - > A = list(2, 3, 5, 7, 11) - > tail(A, 2) + ; A = list(2, 3, 5, 7, 11) + ; tail(A, 2) list (2 members, 2 nonzero): [[0]] = 7 [[1]] = 11 - > tail(A, -2) + ; tail(A, -2) list (3 members, 3 nonzero): [[0]] = 5 @@ -65,8 +65,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: tail,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: tail,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/tail,v $ ## ## Under source code control: 1995/07/10 02:09:30 diff --git a/help/tan b/help/tan index d336d5f..95976e7 100644 --- a/help/tan +++ b/help/tan @@ -15,7 +15,7 @@ DESCRIPTION in absolute value than .75 * eps. EXAMPLE - > print tan(1, 1e-5), tan(1, 1e-10), tan(1, 1e-15), tan(1, 1e-20) + ; print tan(1, 1e-5), tan(1, 1e-10), tan(1, 1e-15), tan(1, 1e-20) 1.55741 1.5574077247 1.557407724654902 1.55740772465490223051 LIMITS @@ -44,8 +44,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: tan,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: tan,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/tan,v $ ## ## Under source code control: 1994/03/19 01:40:29 diff --git a/help/tanh b/help/tanh index e483bbf..5a42ca0 100644 --- a/help/tanh +++ b/help/tanh @@ -17,7 +17,7 @@ DESCRIPTION tanh(x) = (exp(2*x) - 1)/(exp(2*x) + 1) EXAMPLE - > print tanh(1, 1e-5), tanh(1, 1e-10), tanh(1, 1e-15), tanh(1, 1e-20) + ; print tanh(1, 1e-5), tanh(1, 1e-10), tanh(1, 1e-15), tanh(1, 1e-20) .76159 .761594156 .761594155955765 .76159415595576488812 LIMITS @@ -46,8 +46,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: tanh,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: tanh,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/tanh,v $ ## ## Under source code control: 1994/03/19 01:40:30 diff --git a/help/time b/help/time index 8de24f8..b6514c9 100644 --- a/help/time +++ b/help/time @@ -14,7 +14,7 @@ DESCRIPTION Thr Jan 1 00:00:00 UTC 1970 EXAMPLE - > print time(); + ; print time(); 831081380 LIMITS @@ -42,8 +42,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: time,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: time,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/time,v $ ## ## Under source code control: 1996/05/01 16:57:20 diff --git a/help/todo b/help/todo index b665a78..d93b1b3 100644 --- a/help/todo +++ b/help/todo @@ -24,11 +24,39 @@ Calc Todo Items: Very High priority items: - * Write the help file for the display() builtin function. + * Consider using GNU autoconf / configure to build calc. - * Write the help file for the stoponerror() builtin function. + * Internationalize calc by converting calc error messages and + text strings (e.g., calc startup banner, show output, etc.) + into calls to the GNU gettext internationalization facility. + If somebody translated these strings into another language, + setting $LANG would allow calc to produce error messages + and text strings in that language. - * Update the errmax about the meaning of errmax(-1). + * Fix any 'Known bugs' as noted in the BUGS file or as + displayed by 'calc help bugs'. + +=-= + +High priority items: + + * Verify, complete or fix the 'SEE ALSO' help file sections. + + * Verify, complete or fix the 'LINK LIBRARY' help file sections. + + * Verify, complete or fix the 'LIMITS' help file sections. + + * Verify, complete or fix the 'SYNOPSIS' and 'TYPES' help file sections. + + * Perform a code coverage analysis of the 'make check' action + and improve the coverage (within reason) of the regress.cal suite. + + * Address, if possible and reasonable, any Calc Mis-features + as noted in the BUGS file or as displayed by 'calc help bugs'. + +=-= + +Medium priority items: * Review and if needed, correct/update the help topics: @@ -56,42 +84,6 @@ Very High priority items: bugs known bugs and mis-features wishlist wish list of future enhancements of calc - * Fix any 'Known bugs' as noted in the BUGS file or as - displayed by 'calc help bugs'. - - * Internationalize calc by converting calc error messages and - text strings (e.g., calc startup banner, show output, etc.) - into calls to the GNU gettext internationalization facility. - If somebody translated these strings into another language, - setting $LANG would allow calc to produce error messages - and text strings in that language. - - * Consider using GNU autoconf / configure to build the calc Makefile. - -=-= - -High priority items: - - * Verify, complete or fix the 'SEE ALSO' help file sections. - - * Verify, complete or fix the 'LINK LIBRARY' help file sections. - - * Verify, complete or fix the 'LIMITS' help file sections. - - * Verify, complete or fix the 'SYNOPSIS' and 'TYPES' help file sections. - - * Where reasonable, be sure that regress.cal tests builtin functions. - - * Perform a code coverage analysis of the 'make check' action - and improve the coverage (within reason) of the regress.cal suite. - - * Address, if possible and reasonable, any Calc Mis-features - as noted in the BUGS file or as displayed by 'calc help bugs'. - -=-= - -Medium priority items: - * Complete the use of CONST where appropriate: CONST is beginning to be used with read-only tables and some @@ -122,7 +114,7 @@ Medium priority items: * Add a builtin function to access the 64 bit FNV hash which is currently being used internally in seed.c. -## Copyright (C) 1999-2003 Landon Curt Noll +## Copyright (C) 1999-2006 Landon Curt Noll ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License @@ -138,8 +130,8 @@ Medium priority items: ## 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: todo,v 29.5 2003/02/25 20:26:17 chongo Exp $ +## @(#) $Revision: 29.8 $ +## @(#) $Id: todo,v 29.8 2006/05/21 07:50:11 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/todo,v $ ## ## Under source code control: 1999/10/20 07:42:55 diff --git a/help/trunc b/help/trunc index 055fe76..594d026 100644 --- a/help/trunc +++ b/help/trunc @@ -17,13 +17,13 @@ DESCRIPTION Truncation of a non-integer prodcues values nearer to zero. EXAMPLE - > print trunc(pi()), trunc(pi(), 5) + ; print trunc(pi()), trunc(pi(), 5) 3 3.14159 - > print trunc(3.333), trunc(3.789), trunc(3.333, 2), trunc(3.789, 2) + ; print trunc(3.333), trunc(3.789), trunc(3.333, 2), trunc(3.789, 2) 3 3 3.33 3.78 - > print trunc(-3.333), trunc(-3.789), trunc(-3.333, 2), trunc(-3.789, 2) + ; print trunc(-3.333), trunc(-3.789), trunc(-3.333, 2), trunc(-3.789, 2) -3 -3 -3.33 -3.78 LIMITS @@ -51,8 +51,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: trunc,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: trunc,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/trunc,v $ ## ## Under source code control: 1994/09/30 00:52:38 diff --git a/help/version b/help/version index eed537f..2364042 100644 --- a/help/version +++ b/help/version @@ -20,7 +20,7 @@ DESCRIPTION t is the the liternal character 't'. EXAMPLE - > version() + ; version() "2.11.5.4" LIMITS @@ -48,8 +48,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.3 $ -## @(#) $Id: version,v 29.3 2001/06/09 23:32:45 chongo Exp $ +## @(#) $Revision: 29.4 $ +## @(#) $Id: version,v 29.4 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/version,v $ ## ## Under source code control: 2001/05/28 17:38:01 diff --git a/help/xor b/help/xor index f0fd01a..fbdcf03 100644 --- a/help/xor +++ b/help/xor @@ -26,7 +26,7 @@ DESCRIPTION xor(...xor(xor(x1,x2), x3), ... xn) EXAMPLE - > print xor(2), xor(5, 3, -7, 2, 9) + ; print xor(2), xor(5, 3, -7, 2, 9) 2 10 LIMITS @@ -54,8 +54,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: xor,v 29.2 2000/06/07 14:02:33 chongo Exp $ +## @(#) $Revision: 29.3 $ +## @(#) $Id: xor,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/xor,v $ ## ## Under source code control: 1995/10/05 04:52:27 diff --git a/hist.c b/hist.c index 1b2fc97..523107f 100644 --- a/hist.c +++ b/hist.c @@ -1,7 +1,7 @@ /* * hist - interactive readline module * - * Copyright (C) 1999-2004 David I. Bell + * Copyright (C) 1999-2006 David I. Bell * * Calc is open software; you can redistribute it and/or modify it under * the terms of the version 2.1 of the GNU Lesser General Public License @@ -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: hist.c,v 29.6 2004/02/23 14:04:01 chongo Exp $ + * @(#) $Revision: 29.10 $ + * @(#) $Id: hist.c,v 29.10 2006/05/20 08:43:55 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/RCS/hist.c,v $ * * Under source code control: 1993/05/02 20:09:19 @@ -261,7 +261,7 @@ static void insert_string(char *str, int len); * zero on an end of file or error. The prompt is printed before reading * the line. */ -int +size_t hist_getline(char *prompt, char *buf, int len) { /* @@ -351,7 +351,7 @@ hist_init(char *filename) */ if (filename == NULL) filename = HIST_BINDING_FILE; - if (opensearchfile(filename, calcpath, NULL, FALSE) > 0) + if (opensearchfile(filename, calcpath, NULL, FALSE, FALSE) > 0) return HIST_NOFILE; /* @@ -763,18 +763,18 @@ static void arrow_key(void) { switch (fgetc(stdin)) { - case 'A': - backward_history(); - break; - case 'B': - forward_history(); - break; - case 'C': - forward_char(); - break; - case 'D': - backward_char(); - break; + case 'A': + backward_history(); + break; + case 'B': + forward_history(); + break; + case 'C': + forward_char(); + break; + case 'D': + backward_char(); + break; } } @@ -1445,8 +1445,8 @@ quit_calc(void) /* name of history file */ char *my_calc_history = NULL; -int -hist_getline(char *prompt, char *buf, int len) +size_t +hist_getline(char *prompt, char *buf, size_t len) { char *line; @@ -1454,13 +1454,13 @@ hist_getline(char *prompt, char *buf, int len) line = readline(prompt); if (!line) { switch (conf->ctrl_d) { - case CTRL_D_NEVER_EOF: - return 0; - case CTRL_D_VIRGIN_EOF: - case CTRL_D_EMPTY_EOF: - default: - quit_calc(); - /*NOTREACHED*/ + case CTRL_D_NEVER_EOF: + return 0; + case CTRL_D_VIRGIN_EOF: + case CTRL_D_EMPTY_EOF: + default: + quit_calc(); + /*NOTREACHED*/ } } strncpy(buf, line, len - 1); @@ -1553,20 +1553,20 @@ main(int argc, char **argv) filename = argv[1]; switch (hist_init(filename)) { - case HIST_SUCCESS: - break; - case HIST_NOFILE: - fprintf(stderr, "Binding file was not found\n"); - break; - case HIST_NOTTY: - fprintf(stderr, "Cannot set terminal parameters\n"); - break; - case HIST_INITED: - fprintf(stderr, "Hist is already inited\n"); - break; - default: - fprintf(stderr, "Unknown error from hist_init\n"); - break; + case HIST_SUCCESS: + break; + case HIST_NOFILE: + fprintf(stderr, "Binding file was not found\n"); + break; + case HIST_NOTTY: + fprintf(stderr, "Cannot set terminal parameters\n"); + break; + case HIST_INITED: + fprintf(stderr, "Hist is already inited\n"); + break; + default: + fprintf(stderr, "Unknown error from hist_init\n"); + break; } do { diff --git a/hist.h b/hist.h index 659a5ff..0c41e6f 100644 --- a/hist.h +++ b/hist.h @@ -1,7 +1,7 @@ /* * hist - definitions for command history module * - * Copyright (C) 1999 David I. Bell + * Copyright (C) 1999-2006 David I. Bell * * Calc is open software; you can redistribute it and/or modify it under * the terms of the version 2.1 of the GNU Lesser General Public License @@ -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: hist.h,v 29.4 2002/03/12 09:40:57 chongo Exp $ + * @(#) $Revision: 29.6 $ + * @(#) $Id: hist.h,v 29.6 2006/05/19 15:26:10 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/RCS/hist.h,v $ * * Under source code control: 1993/05/02 20:09:20 @@ -70,7 +70,7 @@ extern DLL int hist_init(char *filename); extern DLL void hist_term(void); -extern DLL int hist_getline(char *prompt, char *buf, int len); +extern DLL size_t hist_getline(char *prompt, char *buf, size_t len); extern DLL void hist_saveline(char *line, int len); diff --git a/input.c b/input.c index a34215d..8a78b65 100644 --- a/input.c +++ b/input.c @@ -1,7 +1,7 @@ /* * input - nested input source file reader * - * Copyright (C) 1999 David I. Bell + * Copyright (C) 1999-2006 David I. Bell * * Calc is open software; you can redistribute it and/or modify it under * the terms of the version 2.1 of the GNU Lesser General Public License @@ -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: input.c,v 29.6 2002/03/12 09:40:57 chongo Exp $ + * @(#) $Revision: 29.11 $ + * @(#) $Id: input.c,v 29.11 2006/05/19 15:26:10 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/RCS/input.c,v $ * * Under source code control: 1990/02/15 01:48:16 @@ -114,8 +114,12 @@ static char *homeexpand(char *name); /* * Open an input file by possibly searching through a path list * and also possibly applying the specified extension. For example: - * opensearchfile("barf", ".:/tmp", ".c", once) searches in order - * for the files "./barf", "./barf.c", "/tmp/barf", and "/tmp/barf.c". + * + * opensearchfile("barf", ".:/tmp", ".c", rd_once) + * + * searches in order for the files: + * + * "./barf", "./barf.c", "/tmp/barf", and "/tmp/barf.c". * * Returns -1 if we could not open a file or error. * Returns 1 if file was opened and added to/updated in the readset @@ -134,9 +138,29 @@ opensearchfile(char *name, char *pathlist, char *extension, int rd_once) char *cp; char *path; /* name being searched for */ struct stat statbuf; /* stat of the path */ - unsigned long namelen; /* length of name */ - unsigned long extlen; /* length of the extension if non-NULL or 0 */ - unsigned long pathlen; /* length of the pathlist if non-NULL or 0 */ + size_t namelen; /* length of name */ + size_t extlen; /* length of the extension if non-NULL or 0 */ + size_t pathlen; /* length of the pathlist if non-NULL or 0 */ + + /* firewall */ + if (name == NULL) { + math_error("NULL name given to opensearchfile"); + /*NOTREACHED*/ + } + + /* + * We ignore the pathlist of the file is absolute, dot-relative + * or tilde-relative or if there is no search path. + */ + if (name[0] == PATHCHAR || + name[0] == HOMECHAR || + (name[0] == DOTCHAR && name[1] == '\0') || + (name[0] == DOTCHAR && name[1] == DOTCHAR && name[2] == '\0') || + (name[0] == DOTCHAR && name[1] == PATHCHAR) || + (name[0] == DOTCHAR && name[1] == DOTCHAR && name[2] == PATHCHAR) || + pathlist == NULL) { + pathlist = ""; + } /* * allocate storage for the longest name being searched for @@ -158,11 +182,7 @@ opensearchfile(char *name, char *pathlist, char *extension, int rd_once) } else { extlen = 0; } - if (pathlist != NULL) { - pathlen = strlen(pathlist); - } else { - pathlen = 0; - } + pathlen = strlen(pathlist); path = malloc(pathlen+1 + 1 + namelen+1 + extlen+1 + 1 + 1); if (path == NULL) { math_error("Cannot allocate filename path buffer"); @@ -178,17 +198,8 @@ opensearchfile(char *name, char *pathlist, char *extension, int rd_once) } /* - * If the name is absolute, or if there is no path list, then - * make one which just searches for the name straight. Then - * search through the path list for the file, without and with - * the specified extension. + * Search through the path list for the file */ - if (name[0] == PATHCHAR || - name[0] == HOMECHAR || - (name[0] == DOTCHAR && name[1] == PATHCHAR) || - pathlist == NULL) { - pathlist = ""; - } pathlist--; do { pathlist++; @@ -197,7 +208,7 @@ opensearchfile(char *name, char *pathlist, char *extension, int rd_once) *cp++ = *pathlist++; if (cp != path) *cp++ = PATHCHAR; - strcpy(cp, name); + strncpy(cp, name, namelen+1); i = openfile(path); if ((i < 0) && (extension != NULL && extension[0] != '\0')) { @@ -244,6 +255,123 @@ opensearchfile(char *name, char *pathlist, char *extension, int rd_once) } +/* + * f_pathopen - open an absolute filename, or a relative filename along a search path + * + * Open a file by possibly searching through a path list. For example: + * + * f_pathopen("curds", ".:/tmp:~/pub", "r", NULL) + * + * searches in order for a file that it can open for reading: + * + * "./curds", "/tmp/curds", "~/pub/curds" + * + * NOTE: ~ is expanded accordingly (see homeexpand() below). + * + * However is the file is /absolue/path/name or a ./dot/relative/name, or + * a ~/home/dir/name, or a ~user/home/name, then the pathlist is ignored + * we just attempt to open name. + * + * and opens the first one that exists and allows the mode. + * + * name file name to be read + * mode fopen() mode argument (one of "r", "w", "a", "r+", "w+", "a+") + * pathlist list of colon separated paths (or NULL) + * openpath if non-NULL, and file was opened, set to malloced path used to open + * + * returns: + * open file stream, NULL ==> file was not found or error + * If file was open and openpath was non-NULL, changed to point to path used to open + */ +FILE * +f_pathopen(char *name, char *mode, char *pathlist, char **openpath) +{ + char *cp; + char *path; /* name being searched for */ + size_t namelen; /* length of name */ + size_t pathlen; /* length of the pathlist if non-NULL or 0 */ + FILE *ret; /* return open stream or NULL */ + + /* firewall */ + if (name == NULL) { + math_error("NULL name given to f_pathopen"); + /*NOTREACHED*/ + } + if (mode == NULL) { + math_error("NULL mode given to f_pathopen"); + /*NOTREACHED*/ + } + + /* + * We ignore the pathlist of the file is absolute, dot-relative + * or tilde-relative or if there is no search path. + */ + if (name[0] == PATHCHAR || + name[0] == HOMECHAR || + (name[0] == DOTCHAR && name[1] == '\0') || + (name[0] == DOTCHAR && name[1] == DOTCHAR && name[2] == '\0') || + (name[0] == DOTCHAR && name[1] == PATHCHAR) || + (name[0] == DOTCHAR && name[1] == DOTCHAR && name[2] == PATHCHAR) || + pathlist == NULL) { + pathlist = ""; + } + + /* + * allocate storage for the longest name being searched for + * + * We will allocate more than we could ever want/need. + * The longest we could ever need would be: + * + * pathlist (as a single long string) + * / + * name + * \0 + * guard byte + */ + namelen = strlen(name); + pathlen = strlen(pathlist); + path = malloc(pathlen+1 + 1 + namelen+1 + 1 + 1); + if (path == NULL) { + math_error("Cannot allocate f_pathopen buffer"); + /*NOTREACHED*/ + } + + /* + * Search through the path list for the file + */ + pathlist--; + do { + pathlist++; + cp = path; + while (*pathlist && (*pathlist != LISTCHAR)) + *cp++ = *pathlist++; + if (cp != path) + *cp++ = PATHCHAR; + strncpy(cp, name, namelen+1); + ret = f_open(path, mode); + } while ((ret == NULL) && *pathlist); + + /* if caller wants to know the path, malloc it and return it */ + if (openpath != NULL && ret != NULL) { + if (path[0] == HOMECHAR) { + *openpath = homeexpand(path); + } else { + *openpath = strdup(path); + } + if (*openpath == NULL) { + free(path); + fclose(ret); + math_error("cannot malloc return openpath buffer"); + /*NOTREACHED*/ + } + } + free(path); + + /* return open file or NULL */ + return ret; +} + + /* * Given a filename with a leading ~, expand it into a home directory for * that user. This function will malloc the space for the expanded path. @@ -276,6 +404,7 @@ homeexpand(char *name) char *fullpath; /* the malloced expanded path */ char *after; /* after the ~user or ~ */ char *username; /* extracted username */ + size_t fullpath_len; /* length of fullpath */ /* firewall */ if (name[0] != HOMECHAR) @@ -302,11 +431,12 @@ homeexpand(char *name) return NULL; } /* just malloc the home directory and return it */ - fullpath = (char *)malloc(strlen(ent->pw_dir)+1); + fullpath_len = strlen(ent->pw_dir); + fullpath = (char *)malloc(fullpath_len+1); if (fullpath == NULL) { return NULL; } - strcpy(fullpath, ent->pw_dir); + strncpy(fullpath, ent->pw_dir, fullpath_len+1); return fullpath; } username = (char *) malloc(after-name + 1 + 1); @@ -346,7 +476,7 @@ homeexpand(char *name) * * given: * name the filename to open - 7 mode the fopen mode to use + * mode fopen() mode argument (one of "r", "w", "a", "r+", "w+", "a+") */ FILE * f_open(char *name, char *mode) @@ -413,6 +543,7 @@ static int openfile(char *name) { FILE *fp; /* open file descriptor */ + size_t namelen; if (depth >= MAXDEPTH) return -2; @@ -426,11 +557,12 @@ openfile(char *name) cip->i_ttystr = NULL; cip->i_fp = fp; cip->i_line = 1; - cip->i_name = (char *)malloc(strlen(name) + 1); + namelen = strlen(name); + cip->i_name = (char *)malloc(namelen+1); if (cip->i_name == NULL) { return -1; } - strcpy(cip->i_name, name); + strncpy(cip->i_name, name, namelen+1); return 0; } @@ -454,9 +586,10 @@ curstream(void) * * given: * str string to be opened + * num lengh of string to open */ int -openstring(char *str, long num) +openstring(char *str, size_t num) { char *cp; /* copied string */ @@ -465,7 +598,8 @@ openstring(char *str, long num) cp = (char *) malloc(num + 1); if (cp == NULL) return -1; - strcpy(cp, str); + strncpy(cp, str, num); + cp[num] = '\0'; /* firewall */ cip = inputs + depth++; cip->i_state = IS_READ; cip->i_char = '\0'; @@ -778,7 +912,7 @@ runrcfiles(void) /* load file name into the path */ if (calcrc == NULL) { - strcpy(path, cp); + strncpy(path, cp, MAX_CALCRC+1); } else { strncpy(path, cp, calcrc - cp); path[calcrc - cp] = '\0'; @@ -935,6 +1069,8 @@ static int addreadset(char *name, char *path, struct stat *sbuf) { int ret; /* index to return */ + size_t name_len; /* length of read set name */ + size_t path_len; /* length of path to read set name */ /* find the inode */ ret = isinoderead(sbuf); @@ -956,11 +1092,12 @@ addreadset(char *name, char *path, struct stat *sbuf) } /* load our information into the readset entry */ - readset[ret].name = (char *)malloc(strlen(name)+1); + name_len = strlen(name); + readset[ret].name = (char *)malloc(name_len+1); if (readset[ret].name == NULL) { return -1; } - strcpy(readset[ret].name, name); + strncpy(readset[ret].name, name, name_len+1); #if defined(_WIN32) || defined(__MSDOS__) /* * For WIN32, _fullpath expands the path to a fully qualified @@ -974,11 +1111,12 @@ addreadset(char *name, char *path, struct stat *sbuf) readset[ret].path = _fullpath(fullpathname, path, _MAX_PATH); } #else /* Windoz free systems */ - readset[ret].path = (char *)malloc(strlen(path)+1); + path_len = strlen(path); + readset[ret].path = (char *)malloc(path_len+1); if (readset[ret].path == NULL) { return -1; } - strcpy(readset[ret].path, path); + strncpy(readset[ret].path, path, path_len+1); #endif /* Windoz free systems */ readset[ret].inode = *sbuf; readset[ret].active = 1; diff --git a/lib_calc.c b/lib_calc.c index e1f90de..ed8f6f7 100644 --- a/lib_calc.c +++ b/lib_calc.c @@ -1,7 +1,7 @@ /* * lib_calc - calc link library initialization and shutdown routines * - * Copyright (C) 1999 Landon Curt Noll + * Copyright (C) 1999-2006 Landon Curt Noll * * Calc is open software; you can redistribute it and/or modify it under * the terms of the version 2.1 of the GNU Lesser General Public License @@ -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.10 $ - * @(#) $Id: lib_calc.c,v 29.10 2004/07/26 06:35:32 chongo Exp $ + * @(#) $Revision: 29.14 $ + * @(#) $Id: lib_calc.c,v 29.14 2006/05/21 07:28:54 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/RCS/lib_calc.c,v $ * * Under source code control: 1996/06/17 18:06:19 @@ -147,7 +147,7 @@ char *pager = NULL; /* $PAGER or default */ char *shell = NULL; /* $SHELL or default */ int stdin_tty = FALSE; /* TRUE if stdin is a tty */ int havecommands = FALSE; /* TRUE if have one or more cmd args */ -int stoponerror = FALSE; /* >0 => stop, <0 => continue on error */ +long stoponerror = 0; /* >0 => stop, <0 => continue, ==0 => use -c */ int post_init = FALSE; /* TRUE setjmp for math_error is ready */ BOOL abort_now = FALSE; /* TRUE => go interactive now, if permitted */ @@ -155,7 +155,7 @@ int argc_value = 0; /* count of argv[] strings for argv() builtin */ char **argv_value = NULL; /* argv[] strings for argv() builtin */ int no_env = FALSE; /* TRUE (-e) => ignore env vars on startup */ -int errmax = ERRMAX; /* if >= 0, maximum value for errcount */ +long errmax = ERRMAX; /* if >= 0, maximum value for errcount */ NUMBER *epsilon_default; /* default allowed error for float calcs */ @@ -435,13 +435,15 @@ initenv(void) } #else /* Windoz free systems */ if (home == NULL || home[0] == '\0') { + size_t pw_dir_len; ent = (struct passwd *)getpwuid(geteuid()); if (ent == NULL) { /* just assume . is home if all else fails */ home = "."; } - home = (char *)malloc(strlen(ent->pw_dir)+1); - strcpy(home, ent->pw_dir); + pw_dir_len = strlen(ent->pw_dir); + home = (char *)malloc(pw_dir_len+1); + strncpy(home, ent->pw_dir, pw_dir_len+1); } #endif /* Windoz free systems */ @@ -555,6 +557,7 @@ calc_strdup(CONST char *s1) #else /* HAVE_STRDUP */ char *ret; /* return string */ + size_t s1_len; /* length of string to duplicate */ /* * firewall @@ -566,13 +569,14 @@ calc_strdup(CONST char *s1) /* * allocate duplicate storage */ - ret = (char *)malloc(sizeof(char) * (strlen(s1)+1)); + s1_len = strlen(s1); + ret = (char *)malloc(s1_len+1); /* * if we have storage, duplicate the string */ if (ret != NULL) { - strcpy(ret, s1); + strncpy(ret, s1, s1_len+1); } /* diff --git a/lib_util.c b/lib_util.c index e38aaa8..6d539df 100644 --- a/lib_util.c +++ b/lib_util.c @@ -1,7 +1,7 @@ /* * lib_util - calc library utility routines * - * Copyright (C) 1999 Landon Curt Noll + * Copyright (C) 1999-2006 Landon Curt Noll * * Calc is open software; you can redistribute it and/or modify it under * the terms of the version 2.1 of the GNU Lesser General Public License @@ -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: lib_util.c,v 29.2 2000/06/07 14:02:13 chongo Exp $ + * @(#) $Revision: 29.4 $ + * @(#) $Id: lib_util.c,v 29.4 2006/05/19 15:26:10 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/RCS/lib_util.c,v $ * * Under source code control: 1997/04/19 21:38:30 @@ -134,7 +134,7 @@ convstr2z(char *str) { HALF *v; /* storage for string as HALFs */ ZVALUE ret; /* return value */ - int len; /* length in HALFs of our string rounded up */ + size_t len; /* length in HALFs of our string rounded up */ /* * firewall @@ -192,7 +192,7 @@ convhex2z(char *hex) char *sp; /* string pointer */ ZVALUE ret; /* return value */ int len; /* length in HALFs of our string rounded up */ - int slen; /* hex string length */ + size_t slen; /* hex string length */ int i; /* diff --git a/longbits.c b/longbits.c index 2646edf..079f34e 100644 --- a/longbits.c +++ b/longbits.c @@ -1,7 +1,7 @@ /* * longbits - Determine the number if bits in a char, short, int or long * - * Copyright (C) 1999 Landon Curt Noll + * Copyright (C) 1999-2006 Landon Curt Noll * * Calc is open software; you can redistribute it and/or modify it under * the terms of the version 2.1 of the GNU Lesser General Public License @@ -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: longbits.c,v 29.3 2004/03/31 04:18:19 chongo Exp $ + * @(#) $Revision: 29.5 $ + * @(#) $Id: longbits.c,v 29.5 2006/05/19 15:26:10 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/RCS/longbits.c,v $ * * Under source code control: 1994/03/18 03:06:18 @@ -108,7 +108,7 @@ int main(int argc, char **argv) { int exitcode = 0; /* how we will exit */ - int long_bits = 0; /* bit length of a long */ + size_t long_bits = 0; /* bit length of a long */ int forced_size = 0; /* 1 => size of long was forced via arg */ char value; /* signed or maybe unsigned character */ @@ -229,10 +229,10 @@ main(int argc, char **argv) printf("typedef unsigned char USB8;\t/* XX%s/ -=*#*=-\n", "X - should be 8 unsigned bits but is not *"); if (value < 1) { - printf("typedef char SB8;\t/* XX%s/ -=*#*=-\n", + printf("typedef char SB8;\t\t/* XX%s/ -=*#*=-\n", "X - should be 8 signed bits but is not *"); } else { - printf("typedef signed char SB8;\t/* XX%s/ -=*#*=-\n", + printf("typedef signed char SB8;\t\t/* XX%s/ -=*#*=-\n", "X - should be 8 signed bits but is not *"); } exitcode = 3; @@ -240,10 +240,10 @@ main(int argc, char **argv) printf("typedef unsigned char USB8;\t/%s/\n", "* unsigned 8 bits *"); if (value < 1) { - printf("typedef char SB8;\t/%s/\n", + printf("typedef char SB8;\t\t/%s/\n", "* signed 8 bits *"); } else { - printf("typedef signed char SB8;\t/%s/\n", + printf("typedef signed char SB8;\t\t/%s/\n", "* signed 8 bits *"); } } diff --git a/matfunc.c b/matfunc.c index 71bd461..16ec4fa 100644 --- a/matfunc.c +++ b/matfunc.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.4 $ - * @(#) $Id: matfunc.c,v 29.4 2004/02/23 14:04:01 chongo Exp $ + * @(#) $Revision: 29.6 $ + * @(#) $Id: matfunc.c,v 29.6 2006/05/20 08:43:55 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/RCS/matfunc.c,v $ * * Under source code control: 1990/02/15 01:48:18 @@ -379,29 +379,29 @@ matpowi(MATRIX *m, NUMBER *q) */ if ((power <= 4) && (power >= -2)) { switch ((int) power) { - case 0: - return matident(m); - case 1: - return matcopy(m); - case -1: - return matinv(m); - case 2: - return matsquare(m); - case -2: - tmp = matinv(m); - res = matsquare(tmp); - matfree(tmp); - return res; - case 3: - tmp = matsquare(m); - res = matmul(m, tmp); - matfree(tmp); - return res; - case 4: - tmp = matsquare(m); - res = matsquare(tmp); - matfree(tmp); - return res; + case 0: + return matident(m); + case 1: + return matcopy(m); + case -1: + return matinv(m); + case 2: + return matsquare(m); + case -2: + tmp = matinv(m); + res = matsquare(tmp); + matfree(tmp); + return res; + case 3: + tmp = matsquare(m); + res = matmul(m, tmp); + matfree(tmp); + return res; + case 4: + tmp = matsquare(m); + res = matsquare(tmp); + matfree(tmp); + return res; } } if (power < 0) { @@ -1405,12 +1405,7 @@ matcopy(MATRIX *m) v2 = res->m_table; i = m->m_size; while (i-- > 0) { - if (v1->v_type == V_NUM) { - v2->v_type = V_NUM; - v2->v_num = qlink(v1->v_num); - } else { - copyvalue(v1, v2); - } + copyvalue(v1, v2); v1++; v2++; } diff --git a/obj.c b/obj.c index 4a779e9..739e2d7 100644 --- a/obj.c +++ b/obj.c @@ -1,7 +1,7 @@ /* * obj - object handling primitives * - * Copyright (C) 1999-2004 David I. Bell + * Copyright (C) 1999-2006 David I. Bell * * Calc is open software; you can redistribute it and/or modify it under * the terms of the version 2.1 of the GNU Lesser General Public License @@ -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: obj.c,v 29.4 2004/02/23 14:04:01 chongo Exp $ + * @(#) $Revision: 29.8 $ + * @(#) $Id: obj.c,v 29.8 2006/05/20 08:43:55 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/RCS/obj.c,v $ * * Under source code control: 1990/02/15 01:48:19 @@ -164,7 +164,10 @@ objcall(int action, VALUE *v1, VALUE *v2, VALUE *v3) long index; /* index of function (negative if undefined) */ VALUE val; /* return value */ VALUE tmp; /* temp value */ - char name[SYMBOLSIZE+1]; /* full name of user routine to call */ + char name[SYMBOLSIZE+1+1]; /* full name of user routine to call */ + size_t namestr_len; /* length of the namestr() return string */ + char *namestr_ret; /* namestr() return string */ + size_t opi_name_len; /* length of the oip name */ /* initialize VALUEs */ val.v_subtype = V_NOSUBTYPE; @@ -185,9 +188,21 @@ objcall(int action, VALUE *v1, VALUE *v2, VALUE *v3) } index = oap->oa_indices[action]; if (index < 0) { - strcpy(name, namestr(&objectnames, oap->oa_index)); + namestr_ret = namestr(&objectnames, oap->oa_index); + if (namestr_ret == NULL) { + math_error("namestr returned NULL!!!"); + /*NOTREACHED*/ + } + namestr_len = strlen(namestr_ret); + opi_name_len = strlen(oip->name); + if (namestr_len > (size_t)SYMBOLSIZE-1-opi_name_len) { + math_error("namestr returned a strong too long!!!"); + /*NOTREACHED*/ + } + name[0] = '\0'; + strncpy(name, namestr_ret, namestr_len+1); strcat(name, "_"); - strcat(name, oip->name); + strncat(name, oip->name, opi_name_len+1); index = adduserfunc(name); oap->oa_indices[action] = index; } @@ -196,115 +211,115 @@ objcall(int action, VALUE *v1, VALUE *v2, VALUE *v3) fp = findfunc(index); if (fp == NULL) { switch (oip->error) { - case ERR_PRINT: - objprint(v1->v_obj); - val.v_type = V_NULL; - break; - case ERR_CMP: - val.v_type = V_INT; - if (v1->v_type != v2->v_type) { - val.v_int = 1; - return val; - } - val.v_int = objcmp(v1->v_obj, v2->v_obj); - break; - case ERR_TEST: - val.v_type = V_INT; - val.v_int = objtest(v1->v_obj); - break; - case ERR_POW: - if (v2->v_type != V_NUM) { - math_error("Non-real power"); - /*NOTREACHED*/ - } - val = objpowi(v1, v2->v_num); - break; - case ERR_ONE: - val.v_type = V_NUM; - val.v_num = qlink(&_qone_); - break; - case ERR_INC: - tmp.v_type = V_NUM; - tmp.v_num = &_qone_; - val = objcall(OBJ_ADD, v1, &tmp, NULL_VALUE); - break; - case ERR_DEC: - tmp.v_type = V_NUM; - tmp.v_num = &_qone_; - val = objcall(OBJ_SUB, v1, &tmp, NULL_VALUE); - break; - case ERR_SQUARE: - val = objcall(OBJ_MUL, v1, v1, NULL_VALUE); - break; - case ERR_VALUE: - copyvalue(v1, &val); - break; - case ERR_ASSIGN: - copyvalue(v2, &tmp); - tmp.v_subtype = v1->v_subtype; - freevalue(v1); - *v1 = tmp; - val.v_type = V_NULL; - break; - default: - math_error("Function \"%s\" is undefined", namefunc(index)); + case ERR_PRINT: + objprint(v1->v_obj); + val.v_type = V_NULL; + break; + case ERR_CMP: + val.v_type = V_INT; + if (v1->v_type != v2->v_type) { + val.v_int = 1; + return val; + } + val.v_int = objcmp(v1->v_obj, v2->v_obj); + break; + case ERR_TEST: + val.v_type = V_INT; + val.v_int = objtest(v1->v_obj); + break; + case ERR_POW: + if (v2->v_type != V_NUM) { + math_error("Non-real power"); /*NOTREACHED*/ + } + val = objpowi(v1, v2->v_num); + break; + case ERR_ONE: + val.v_type = V_NUM; + val.v_num = qlink(&_qone_); + break; + case ERR_INC: + tmp.v_type = V_NUM; + tmp.v_num = &_qone_; + val = objcall(OBJ_ADD, v1, &tmp, NULL_VALUE); + break; + case ERR_DEC: + tmp.v_type = V_NUM; + tmp.v_num = &_qone_; + val = objcall(OBJ_SUB, v1, &tmp, NULL_VALUE); + break; + case ERR_SQUARE: + val = objcall(OBJ_MUL, v1, v1, NULL_VALUE); + break; + case ERR_VALUE: + copyvalue(v1, &val); + break; + case ERR_ASSIGN: + copyvalue(v2, &tmp); + tmp.v_subtype |= v1->v_subtype; + freevalue(v1); + *v1 = tmp; + val.v_type = V_NULL; + break; + default: + math_error("Function \"%s\" is undefined", namefunc(index)); + /*NOTREACHED*/ } return val; } switch (oip->args) { - case 0: - break; - case 1: - ++stack; - stack->v_addr = v1; - stack->v_type = V_ADDR; - break; - case 2: - ++stack; - stack->v_addr = v1; - stack->v_type = V_ADDR; - ++stack; - stack->v_addr = v2; - stack->v_type = V_ADDR; - break; - case 3: - ++stack; - stack->v_addr = v1; - stack->v_type = V_ADDR; - ++stack; - stack->v_addr = v2; - stack->v_type = V_ADDR; - ++stack; - stack->v_addr = v3; - stack->v_type = V_ADDR; - break; - default: - math_error("Bad number of args to calculate"); - /*NOTREACHED*/ + case 0: + break; + case 1: + ++stack; + stack->v_addr = v1; + stack->v_type = V_ADDR; + break; + case 2: + ++stack; + stack->v_addr = v1; + stack->v_type = V_ADDR; + ++stack; + stack->v_addr = v2; + stack->v_type = V_ADDR; + break; + case 3: + ++stack; + stack->v_addr = v1; + stack->v_type = V_ADDR; + ++stack; + stack->v_addr = v2; + stack->v_type = V_ADDR; + ++stack; + stack->v_addr = v3; + stack->v_type = V_ADDR; + break; + default: + math_error("Bad number of args to calculate"); + /*NOTREACHED*/ } calculate(fp, oip->args); switch (oip->retval) { - case A_VALUE: - return *stack--; - case A_UNDEF: - freevalue(stack--); - val.v_type = V_NULL; - break; - case A_INT: - if ((stack->v_type != V_NUM) || qisfrac(stack->v_num)) { - math_error("Integer return value required"); - /*NOTREACHED*/ - } - index = qtoi(stack->v_num); - qfree(stack->v_num); - stack--; - val.v_type = V_INT; - val.v_int = index; - break; - default: - math_error("Bad object return"); + case A_VALUE: + return *stack--; + case A_UNDEF: + freevalue(stack--); + val.v_type = V_NULL; + break; + case A_INT: + if ((stack->v_type != V_NUM) || qisfrac(stack->v_num)) { + math_error("Integer return value required"); /*NOTREACHED*/ + } + index = qtoi(stack->v_num); + qfree(stack->v_num); + stack--; + val.v_type = V_INT; + val.v_int = index; + break; + default: + math_error("Bad object return"); + /*NOTREACHED*/ } return val; } @@ -407,17 +422,17 @@ objpowi(VALUE *vp, NUMBER *q) */ if ((power <= 2) && (power >= -2)) { switch ((int) power) { - case 0: - return objcall(OBJ_ONE, vp, NULL_VALUE, NULL_VALUE); - case 1: - res.v_obj = objcopy(vp->v_obj); - res.v_type = V_OBJ; - res.v_subtype = V_NOSUBTYPE; - return res; - case -1: - return objcall(OBJ_INV, vp, NULL_VALUE, NULL_VALUE); - case 2: - return objcall(OBJ_SQUARE, vp, NULL_VALUE, NULL_VALUE); + case 0: + return objcall(OBJ_ONE, vp, NULL_VALUE, NULL_VALUE); + case 1: + res.v_obj = objcopy(vp->v_obj); + res.v_type = V_OBJ; + res.v_subtype = V_NOSUBTYPE; + return res; + case -1: + return objcall(OBJ_INV, vp, NULL_VALUE, NULL_VALUE); + case 2: + return objcall(OBJ_SQUARE, vp, NULL_VALUE, NULL_VALUE); } } if (power < 0) @@ -709,13 +724,7 @@ objcopy(OBJECT *op) v1 = op->o_table; v2 = np->o_table; for (i = op->o_actions->oa_count; i-- > 0; v1++, v2++) { - if (v1->v_type == V_NUM) { - v2->v_num = qlink(v1->v_num); - v2->v_type = V_NUM; - } else { - copyvalue(v1, v2); - } - v2->v_subtype = V_NOSUBTYPE; + copyvalue(v1, v2); } return np; } diff --git a/opcodes.c b/opcodes.c index 0660c06..bb4569c 100644 --- a/opcodes.c +++ b/opcodes.c @@ -1,7 +1,7 @@ /* * opcodes - opcode execution module * - * Copyright (C) 1999-2004 David I. Bell and Ernest Bowen + * Copyright (C) 1999-2006 David I. Bell and Ernest Bowen * * Primary author: David I. Bell * @@ -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: opcodes.c,v 29.6 2004/02/23 14:04:01 chongo Exp $ + * @(#) $Revision: 29.10 $ + * @(#) $Id: opcodes.c,v 29.10 2006/05/20 08:43:55 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/RCS/opcodes.c,v $ * * Under source code control: 1990/02/15 01:48:19 @@ -194,7 +194,7 @@ o_paramaddr(FUNC UNUSED *fp, int argcount, VALUE *args, long index) } stack->v_addr = args; stack->v_type = V_ADDR; - stack->v_subtype = V_NOSUBTYPE; +/* stack->v_subtype = V_NOSUBTYPE; XXX */ } @@ -409,76 +409,97 @@ o_eleminit(FUNC UNUSED *fp, long index) VALUE tmp; OCTET *ptr; BLOCK *blk; - int subtype; + unsigned short subtype; vp = &stack[-1]; if (vp->v_type == V_ADDR) vp = vp->v_addr; + if (vp->v_type < 0) { + freevalue(stack--); + error_value(E_INIT1); + return; + } + if (vp->v_subtype & V_NOCOPYTO) { + freevalue(stack--); + error_value(E_INIT2); + return; + } switch (vp->v_type) { - case V_MAT: - if ((index < 0) || (index >= vp->v_mat->m_size)) { - math_error("Too many initializer values"); - /*NOTREACHED*/ - } - - oldvp = &vp->v_mat->m_table[index]; - break; - case V_OBJ: - if (index < 0 || index >= vp->v_obj->o_actions->oa_count) { - math_error("Too many initializer values"); - /*NOTREACHED*/ - } - oldvp = &vp->v_obj->o_table[index]; - break; - case V_LIST: - oldvp = listfindex(vp->v_list, index); - if (oldvp == NULL) { - math_error("Too many initializer values"); - /*NOTREACHED*/ - } - break; - case V_STR: - if (index < 0 || index >= vp->v_str->s_len) { - math_error("Bad index for string initializing"); - /*NOTREACHED*/ - } - ptr = (OCTET *)(&vp->v_str->s_str[index]); - vp = stack; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - copy2octet(vp, ptr); + case V_MAT: + if ((index < 0) || (index >= vp->v_mat->m_size)) { freevalue(stack--); + error_value(E_INIT3); return; - case V_NBLOCK: - case V_BLOCK: - if (vp->v_type == V_NBLOCK) { - blk = vp->v_nblock->blk; - if (blk->data == NULL) { - math_error("Attempt to initialize freed block"); - /*NOTREACHED*/ - } - } - else - blk = vp->v_block; - if (index >= blk->maxsize) { - math_error("Too many initializer values"); - /*NOTREACHED*/ - } - ptr = blk->data + index; - vp = stack; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - copy2octet(vp, ptr); - if (index >= blk->datalen) - blk->datalen = index + 1; + } + oldvp = &vp->v_mat->m_table[index]; + break; + case V_OBJ: + if (index < 0 || index >= vp->v_obj->o_actions->oa_count) { freevalue(stack--); + error_value(E_INIT3); return; - default: - math_error("Bad destination type for eleminit"); - /*NOTREACHED*/ + } + oldvp = &vp->v_obj->o_table[index]; + break; + case V_LIST: + oldvp = listfindex(vp->v_list, index); + if (oldvp == NULL) { + freevalue(stack--); + error_value(E_INIT3); + return; + } + break; + case V_STR: + if (index < 0 || (size_t)index >= vp->v_str->s_len) { + freevalue(stack--); + error_value(E_INIT3); + return; + } + ptr = (OCTET *)(&vp->v_str->s_str[index]); + vp = stack; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + copy2octet(vp, ptr); + freevalue(stack--); + return; + case V_NBLOCK: + case V_BLOCK: + if (vp->v_type == V_NBLOCK) { + blk = vp->v_nblock->blk; + if (blk->data == NULL) { + freevalue(stack--); + error_value(E_INIT4); + return; + } + } + else + blk = vp->v_block; + if (index >= blk->maxsize) { + freevalue(stack--); + error_value(E_INIT3); + return; + } + ptr = blk->data + index; + vp = stack; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + copy2octet(vp, ptr); + if (index >= blk->datalen) + blk->datalen = index + 1; + freevalue(stack--); + return; + default: + freevalue(stack--); + error_value(E_INIT5); + return; } vp = stack--; subtype = oldvp->v_subtype; + if (subtype & V_NOASSIGNTO) { + freevalue(vp); + error_value(E_INIT6); + return; + } if (vp->v_type == V_ADDR) { vp = vp->v_addr; if (vp == oldvp) @@ -487,9 +508,28 @@ o_eleminit(FUNC UNUSED *fp, long index) } else tmp = *vp; + if ((subtype & V_NONEWVALUE) && comparevalue(oldvp, &tmp)) { + freevalue(&tmp); + error_value(E_INIT7); + return; + } + if ((subtype & V_NONEWTYPE) && oldvp->v_type != tmp.v_type) { + freevalue(&tmp); + error_value(E_INIT8); + return; + } + if ((subtype & V_NOERROR) && tmp.v_type < 0) { + error_value(E_INIT9); + return; + } + if (tmp.v_subtype & (V_NOASSIGNFROM | V_NOCOPYFROM)) { + freevalue(&tmp); + error_value(E_INIT10); + return; + } + tmp.v_subtype |= oldvp->v_subtype; freevalue(oldvp); *oldvp = tmp; - oldvp->v_subtype = subtype; } @@ -536,115 +576,116 @@ o_indexaddr(FUNC UNUSED *fp, long dim, long writeflag) indices[i] = vp[0]; vp++; } + switch (val->v_type) { - case V_MAT: - vp = matindex(val->v_mat, flag, dim, indices); - break; - case V_ASSOC: - vp = associndex(val->v_assoc, flag, dim, indices); - break; - case V_NBLOCK: - case V_BLOCK: - if (val->v_type == V_BLOCK) - blk = val->v_block; - else - blk = val->v_nblock->blk; - if (blk->data == NULL) { - math_error("Freed block"); - /*NOTREACHED*/ - } - - /* - * obtain single dimensional block index - */ - if (dim != 1) { - math_error("block has only one dimension"); - /*NOTREACHED*/ - } - if (indices[0].v_type != V_NUM) { - math_error("Non-numeric index for block"); - /*NOTREACHED*/ - } - if (qisfrac(indices[0].v_num)) { - math_error("Non-integral index for block"); - /*NOTREACHED*/ - } - if (zge31b(indices[0].v_num->num) || - zisneg(indices[0].v_num->num)) { - math_error("Index out of bounds for block"); - /*NOTREACHED*/ - } - index = ztoi(indices[0].v_num->num); - - if (index >= blk->maxsize) { - math_error("Index out of bounds for block"); - /*NOTREACHED*/ - } - if (index >= blk->datalen) - blk->datalen = index + 1; - ret.v_type = V_OCTET; - ret.v_subtype = V_NOSUBTYPE; - ret.v_octet = &blk->data[index]; - freevalue(stack--); - *stack = ret; - return; - case V_STR: - if (dim != 1) { - math_error("string has only one dimension"); - /*NOTREACHED*/ - } - if (indices[0].v_type != V_NUM) { - math_error("Non-numeric index for string"); - /*NOTREACHED*/ - } - if (qisfrac(indices[0].v_num)) { - math_error("Non-integral index for string"); - /*NOTREACHED*/ - } - if (zge31b(indices[0].v_num->num) || - zisneg(indices[0].v_num->num)) { - math_error("Index out of bounds for string"); - /*NOTREACHED*/ - } - index = ztoi(indices[0].v_num->num); - if (index >= val->v_str->s_len) { - math_error("Index out of bounds for string"); - /*NOTREACHED*/ - } - ret.v_type = V_OCTET; - ret.v_subtype = V_NOSUBTYPE; - ret.v_octet = (OCTET *)(val->v_str->s_str + index); - freevalue(stack--); - *stack = ret; - return; - case V_LIST: - if (dim != 1) { - math_error("list has only one dimension"); - /*NOTREACHED*/ - } - if (indices[0].v_type != V_NUM) { - math_error("Non-numeric index for list"); - /*NOTREACHED*/ - } - if (qisfrac(indices[0].v_num)) { - math_error("Non-integral index for list"); - /*NOTREACHED*/ - } - if (zge31b(indices[0].v_num->num) || - zisneg(indices[0].v_num->num)) { - math_error("Index out of bounds for list"); - /*NOTREACHED*/ - } - index = ztoi(indices[0].v_num->num); - vp = listfindex(val->v_list, index); - if (vp == NULL) { - math_error("Index out of bounds for list"); - /*NOTREACHED*/ - } - break; - default: - math_error("Illegal value for indexing"); + case V_MAT: + vp = matindex(val->v_mat, flag, dim, indices); + break; + case V_ASSOC: + vp = associndex(val->v_assoc, flag, dim, indices); + break; + case V_NBLOCK: + case V_BLOCK: + if (val->v_type == V_BLOCK) + blk = val->v_block; + else + blk = val->v_nblock->blk; + if (blk->data == NULL) { + math_error("Freed block"); /*NOTREACHED*/ + } + + /* + * obtain single dimensional block index + */ + if (dim != 1) { + math_error("block has only one dimension"); + /*NOTREACHED*/ + } + if (indices[0].v_type != V_NUM) { + math_error("Non-numeric index for block"); + /*NOTREACHED*/ + } + if (qisfrac(indices[0].v_num)) { + math_error("Non-integral index for block"); + /*NOTREACHED*/ + } + if (zge31b(indices[0].v_num->num) || + zisneg(indices[0].v_num->num)) { + math_error("Index out of bounds for block"); + /*NOTREACHED*/ + } + index = ztoi(indices[0].v_num->num); + + if (index >= blk->maxsize) { + math_error("Index out of bounds for block"); + /*NOTREACHED*/ + } + if (index >= blk->datalen) + blk->datalen = index + 1; + ret.v_type = V_OCTET; + ret.v_subtype = val->v_subtype; + ret.v_octet = &blk->data[index]; + freevalue(stack--); + *stack = ret; + return; + case V_STR: + if (dim != 1) { + math_error("string has only one dimension"); + /*NOTREACHED*/ + } + if (indices[0].v_type != V_NUM) { + math_error("Non-numeric index for string"); + /*NOTREACHED*/ + } + if (qisfrac(indices[0].v_num)) { + math_error("Non-integral index for string"); + /*NOTREACHED*/ + } + if (zge31b(indices[0].v_num->num) || + zisneg(indices[0].v_num->num)) { + math_error("Index out of bounds for string"); + /*NOTREACHED*/ + } + index = ztoi(indices[0].v_num->num); + if (index < 0 || (size_t)index >= val->v_str->s_len) { + math_error("Index out of bounds for string"); + /*NOTREACHED*/ + } + ret.v_type = V_OCTET; + ret.v_subtype = val->v_subtype; + ret.v_octet = (OCTET *)(val->v_str->s_str + index); + freevalue(stack--); + *stack = ret; + return; + case V_LIST: + if (dim != 1) { + math_error("list has only one dimension"); + /*NOTREACHED*/ + } + if (indices[0].v_type != V_NUM) { + math_error("Non-numeric index for list"); + /*NOTREACHED*/ + } + if (qisfrac(indices[0].v_num)) { + math_error("Non-integral index for list"); + /*NOTREACHED*/ + } + if (zge31b(indices[0].v_num->num) || + zisneg(indices[0].v_num->num)) { + math_error("Index out of bounds for list"); + /*NOTREACHED*/ + } + index = ztoi(indices[0].v_num->num); + vp = listfindex(val->v_list, index); + if (vp == NULL) { + math_error("Index out of bounds for list"); + /*NOTREACHED*/ + } + break; + default: + math_error("Illegal value for indexing"); + /*NOTREACHED*/ } while (dim-- > 0) freevalue(stack--); @@ -666,33 +707,33 @@ o_elemaddr(FUNC UNUSED *fp, long index) if (vp->v_type == V_ADDR) vp = stack->v_addr; switch (vp->v_type) { - case V_MAT: - mp = vp->v_mat; - if ((index < 0) || (index >= mp->m_size)) { - math_error("Non-existent element for matrix"); - /*NOTREACHED*/ - } - vp = &mp->m_table[index]; - break; - case V_OBJ: - op = vp->v_obj; - offset = objoffset(op, index); - if (offset < 0) { - math_error("Non-existent element for object"); - /*NOTREACHED*/ - } - vp = &op->o_table[offset]; - break; - case V_LIST: - vp = listfindex(vp->v_list, index); - if (vp == NULL) { - math_error("Index out of bounds for list"); - /*NOTREACHED*/ - } - break; - default: - math_error("Not initializing matrix, object or list"); + case V_MAT: + mp = vp->v_mat; + if ((index < 0) || (index >= mp->m_size)) { + math_error("Non-existent element for matrix"); /*NOTREACHED*/ + } + vp = &mp->m_table[index]; + break; + case V_OBJ: + op = vp->v_obj; + offset = objoffset(op, index); + if (offset < 0) { + math_error("Non-existent element for object"); + /*NOTREACHED*/ + } + vp = &op->o_table[offset]; + break; + case V_LIST: + vp = listfindex(vp->v_list, index); + if (vp == NULL) { + math_error("Index out of bounds for list"); + /*NOTREACHED*/ + } + break; + default: + math_error("Not initializing matrix, object or list"); + /*NOTREACHED*/ } stack->v_type = V_ADDR; stack->v_addr = vp; @@ -725,7 +766,8 @@ o_assign(void) VALUE *var; /* variable value */ VALUE *vp; VALUE tmp; - short subtype; + unsigned short subtype; + USB8 octet; /* * get what we will store into @@ -740,24 +782,39 @@ o_assign(void) */ if (var->v_type == V_OCTET) { if (var->v_subtype & V_NOCOPYTO) { - math_error("No-copy-to octet destination"); - /*NOTREACHED*/ + freevalue(stack--); + *stack = error_value(E_ASSIGN1); + return; } - copy2octet(stack, var->v_octet); + vp = stack; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + if (vp->v_subtype & V_NOCOPYFROM || vp->v_type < 0) { + freevalue(stack--); + *stack = error_value(E_ASSIGN2); + return; + } + copy2octet(vp, &octet); freevalue(stack--); + if ((var->v_subtype & V_NONEWVALUE) && *var->v_octet != octet) { + *stack = error_value(E_ASSIGN3); + return; + } + *var->v_octet = octet; return; } if (var->v_type != V_ADDR) { - math_error("Assignment into non-variable"); - /*NOTREACHED*/ + freevalue(stack--); + *stack = error_value(E_ASSIGN4); + return; } var = var->v_addr; subtype = var->v_subtype; - if (subtype & V_NOASSIGNTO) { - math_error("No-assign-to destination for assign"); - /*NOTREACHED*/ + freevalue(stack--); + *stack = error_value(E_ASSIGN5); + return; } vp = stack; @@ -782,38 +839,40 @@ o_assign(void) if (vp == var) return; if (vp->v_subtype & V_NOASSIGNFROM) { - math_error("No-assign-from source for assign"); - /*NOTREACHED*/ + *stack = error_value(E_ASSIGN6); + return; } - tmp.v_subtype = V_NOSUBTYPE; copyvalue(vp, &tmp); } else if (vp->v_type == V_OCTET) { - tmp.v_subtype = V_NOSUBTYPE; copyvalue(vp, &tmp); } else { tmp = *vp; } /* - * perform the assignment + * Check protection */ if ((subtype & V_NONEWVALUE) && comparevalue(var, &tmp)) { freevalue(&tmp); - math_error("Change of value in assign not permitted"); - /*NOTREACHED*/ + *stack = error_value(E_ASSIGN7); + return; } if ((subtype & V_NONEWTYPE) && var->v_type != tmp.v_type) { freevalue(&tmp); - math_error("Change of type in assign not permitted"); - /*NOTREACHED*/ + *stack = error_value(E_ASSIGN8); + return; } if ((subtype & V_NOERROR) && tmp.v_type < 0) { - math_error("Error value in assign not permitted"); - /*NOTREACHED*/ + *stack = error_value(E_ASSIGN9); + return; } + + /* + * perform the assignment + */ freevalue(var); *var = tmp; - var->v_subtype = subtype; + var->v_subtype |= subtype; } @@ -841,23 +900,23 @@ static void o_ptr(void) { switch (stack->v_type) { - case V_ADDR: - stack->v_type = V_VPTR; - break; - case V_OCTET: - stack->v_type = V_OPTR; - break; - case V_STR: - sfree(stack->v_str); - stack->v_type = V_SPTR; - break; - case V_NUM: - qfree(stack->v_num); - stack->v_type = V_NPTR; - break; - default: - math_error("Addressing non-addressable type"); - /*NOTREACHED*/ + case V_ADDR: + stack->v_type = V_VPTR; + break; + case V_OCTET: + stack->v_type = V_OPTR; + break; + case V_STR: + sfree(stack->v_str); + stack->v_type = V_SPTR; + break; + case V_NUM: + qfree(stack->v_num); + stack->v_type = V_NPTR; + break; + default: + math_error("Addressing non-addressable type"); + /*NOTREACHED*/ } } @@ -866,10 +925,8 @@ static void o_deref(void) { VALUE *vp; - short subtype; vp = stack; - subtype = stack->v_subtype; if (stack->v_type == V_OCTET) { stack->v_num = itoq(*vp->v_octet); @@ -903,35 +960,34 @@ o_deref(void) } vp = vp->v_addr; switch (vp->v_type) { - case V_ADDR: - case V_OCTET: - *stack = *vp; + case V_ADDR: + case V_OCTET: + *stack = *vp; + break; + case V_OPTR: + *stack = *vp; + stack->v_type = V_OCTET; + break; + case V_VPTR: + *stack = *vp; + stack->v_type = V_ADDR; + break; + case V_SPTR: + *stack = *vp; + stack->v_type = V_STR; + break; + case V_NPTR: + if (vp->v_num->links == 0) { + stack->v_type = V_NULL; break; - case V_OPTR: - *stack = *vp; - stack->v_type = V_OCTET; - break; - case V_VPTR: - *stack = *vp; - stack->v_type = V_ADDR; - break; - case V_SPTR: - *stack = *vp; - stack->v_type = V_STR; - break; - case V_NPTR: - if (vp->v_num->links == 0) { - stack->v_type = V_NULL; - break; - } - stack->v_type = V_NUM; - stack->v_num = vp->v_num; - stack->v_num->links++; - break; - default: - copyvalue(vp, stack); + } + stack->v_type = V_NUM; + stack->v_num = vp->v_num; + stack->v_num->links++; + break; + default: + copyvalue(vp, stack); } - stack->v_subtype = subtype; } @@ -941,32 +997,34 @@ o_swap(void) VALUE *v1, *v2; /* variables to be swapped */ VALUE tmp; USB8 usb; - short s1, s2; /* for subtypes */ v1 = stack--; v2 = stack; if (v1->v_type == V_OCTET && v2->v_type == V_OCTET) { - usb = *v1->v_octet; - *v1->v_octet = *v2->v_octet; - *v2->v_octet = usb; + if (v1->v_octet != v2->v_octet && + ((v1->v_subtype | v2->v_subtype) & + (V_NOCOPYTO | V_NOCOPYFROM))) { + *stack = error_value(E_SWAP1); + return; + } + usb = *v1->v_octet; + *v1->v_octet = *v2->v_octet; + *v2->v_octet = usb; } else if (v1->v_type == V_ADDR && v2->v_type == V_ADDR) { v1 = v1->v_addr; v2 = v2->v_addr; - s1 = v1->v_subtype; - s2 = v2->v_subtype; - if ((s1 | s2) & (V_NOASSIGNTO | V_NOASSIGNFROM)) { - math_error("Swap not permitted by protection levels"); - /*NOTREACHED*/ + if (v1 != v2 && ((v1->v_subtype | v2->v_subtype) & + (V_NOASSIGNTO | V_NOASSIGNFROM))) { + *stack = error_value(E_SWAP2); + return; } tmp = *v1; *v1 = *v2; *v2 = tmp; - v1->v_subtype = s1; - v2->v_subtype = s2; } else { - math_error("Swapping values of non-variables"); - /*NOTREACHED*/ + *stack = error_value(E_SWAP3); + return; } stack->v_type = V_NULL; stack->v_subtype = V_NOSUBTYPE; @@ -1196,28 +1254,35 @@ o_quomod(void) if (v2->v_type == V_ADDR) v2 = v2->v_addr; if ((v3->v_type != V_ADDR) || (v4->v_type != V_ADDR)) { - math_error("Non-variable for quomod"); - /*NOTREACHED*/ + freevalue(stack--); + freevalue(stack--); + freevalue(stack--); + freevalue(stack); + *stack = error_value(E_QUOMOD1); + return; } if ((v1->v_type != V_NUM) || (v2->v_type != V_NUM)) { - math_error("Non-reals for quomod"); - /*NOTREACHED*/ + stack -= 2; + freevalue(stack--); + freevalue(stack); + *stack = error_value(E_QUOMOD2); + return; } v3 = v3->v_addr; v4 = v4->v_addr; - valquo.v_subtype = v3->v_subtype; - valmod.v_subtype = v4->v_subtype; - if ((v3->v_subtype | v4->v_subtype) & V_NOASSIGNTO) { - math_error("No-assign-to destination for quomod"); - /*NOTREACHED*/ + stack -= 2; + freevalue(stack--); + freevalue(stack); + *stack = error_value(E_QUOMOD3); + return; } valquo.v_type = V_NUM; - valquo.v_subtype = V_NOSUBTYPE; + valquo.v_subtype = v3->v_subtype; valmod.v_type = V_NUM; - valmod.v_subtype = V_NOSUBTYPE; + valmod.v_subtype = v4->v_subtype; res = qquomod(v1->v_num, v2->v_num, &valquo.v_num, &valmod.v_num); stack -= 2; if (stack->v_type == V_NUM) @@ -1349,14 +1414,14 @@ o_plus (void) tmp.v_type = V_NULL; tmp.v_subtype = V_NOSUBTYPE; switch (vp->v_type) { - case V_OBJ: - tmp = objcall(OBJ_PLUS, vp, NULL_VALUE, NULL_VALUE); - break; - case V_LIST: - addlistitems(vp->v_list, &tmp); - break; - default: - return; + case V_OBJ: + tmp = objcall(OBJ_PLUS, vp, NULL_VALUE, NULL_VALUE); + break; + case V_LIST: + addlistitems(vp->v_list, &tmp); + break; + default: + return; } freevalue(stack); *stack = tmp; @@ -1567,12 +1632,12 @@ o_links(void) if (haveaddress) vp = vp->v_addr; switch (vp->v_type) { - case V_NUM: links = vp->v_num->links; break; - case V_COM: links = vp->v_com->links; break; - case V_STR: links = vp->v_str->s_links; break; - default: - freevalue(stack); - return; + case V_NUM: links = vp->v_num->links; break; + case V_COM: links = vp->v_com->links; break; + case V_STR: links = vp->v_str->s_links; break; + default: + freevalue(stack); + return; } if (links <= 0) { math_error("Non-positive links!!!"); @@ -1614,14 +1679,14 @@ o_bit (void) } index = qtoi(v2->v_num); switch (v1->v_type) { - case V_NUM: - r = qisset(v1->v_num, index); - break; - case V_STR: - r = stringbit(v1->v_str, index); - break; - default: - r = 2; + case V_NUM: + r = qisset(v1->v_num, index); + break; + case V_STR: + r = stringbit(v1->v_str, index); + break; + default: + r = 2; } freevalue(stack--); freevalue(stack); @@ -1647,39 +1712,39 @@ o_highbit (void) if (vp->v_type == V_ADDR) vp = vp->v_addr; switch (vp->v_type) { - case V_NUM: - if (qiszero(vp->v_num)) { - index = -1; - break; - } - if (qisfrac(vp->v_num)) { - index = -2; - break; - } - index = zhighbit(vp->v_num->num); + case V_NUM: + if (qiszero(vp->v_num)) { + index = -1; break; - case V_STR: - index = stringhighbit(vp->v_str); + } + if (qisfrac(vp->v_num)) { + index = -2; break; - case V_OCTET: - u = *vp->v_octet; - for (index = -1; u; u >>= 1, ++index); - break; - default: - index = -3; + } + index = zhighbit(vp->v_num->num); + break; + case V_STR: + index = stringhighbit(vp->v_str); + break; + case V_OCTET: + u = *vp->v_octet; + for (index = -1; u; u >>= 1, ++index); + break; + default: + index = -3; } freevalue(stack); switch (index) { - case -3: - *stack = error_value(E_HIGHBIT1); - return; - case -2: - *stack = error_value(E_HIGHBIT2); - return; - default: - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; - stack->v_num = itoq(index); + case -3: + *stack = error_value(E_HIGHBIT1); + return; + case -2: + *stack = error_value(E_HIGHBIT2); + return; + default: + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; + stack->v_num = itoq(index); } } @@ -1695,43 +1760,43 @@ o_lowbit (void) if (vp->v_type == V_ADDR) vp = vp->v_addr; switch (vp->v_type) { - case V_NUM: - if (qiszero(vp->v_num)) { - index = -1; - break; - } - if (qisfrac(vp->v_num)) { - index = -2; - break; - } - index = zlowbit(vp->v_num->num); - break; - case V_STR: - index = stringlowbit(vp->v_str); - break; - case V_OCTET: - u = *vp->v_octet; + case V_NUM: + if (qiszero(vp->v_num)) { index = -1; - if (u) do { - ++index; - u >>= 1; - } while (!(u & 1)); break; - default: - index = -3; + } + if (qisfrac(vp->v_num)) { + index = -2; + break; + } + index = zlowbit(vp->v_num->num); + break; + case V_STR: + index = stringlowbit(vp->v_str); + break; + case V_OCTET: + u = *vp->v_octet; + index = -1; + if (u) do { + ++index; + u >>= 1; + } while (!(u & 1)); + break; + default: + index = -3; } freevalue(stack); switch (index) { - case -3: - *stack = error_value(E_LOWBIT1); - return; - case -2: - *stack = error_value(E_LOWBIT2); - return; - default: - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; - stack->v_num = itoq(index); + case -3: + *stack = error_value(E_LOWBIT1); + return; + case -2: + *stack = error_value(E_LOWBIT2); + return; + default: + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; + stack->v_num = itoq(index); } } @@ -1865,20 +1930,20 @@ o_isnum(void) if (vp->v_type == V_ADDR) vp = vp->v_addr; switch (vp->v_type) { - case V_NUM: - if (stack->v_type == V_NUM) - qfree(stack->v_num); - break; - case V_COM: - if (stack->v_type == V_COM) - comfree(stack->v_com); - break; - default: - freevalue(stack); - stack->v_num = qlink(&_qzero_); - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; - return; + case V_NUM: + if (stack->v_type == V_NUM) + qfree(stack->v_num); + break; + case V_COM: + if (stack->v_type == V_COM) + comfree(stack->v_com); + break; + default: + freevalue(stack); + stack->v_num = qlink(&_qzero_); + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; + return; } stack->v_num = qlink(&_qone_); stack->v_type = V_NUM; @@ -2112,10 +2177,10 @@ o_isptr(void) vp = vp->v_addr; r = 0; switch(vp->v_type) { - case V_OPTR: r = 1; break; - case V_VPTR: r = 2; break; - case V_SPTR: r = 3; break; - case V_NPTR: r = 4; break; + case V_OPTR: r = 1; break; + case V_VPTR: r = 2; break; + case V_SPTR: r = 3; break; + case V_NPTR: r = 4; break; } freevalue(stack); stack->v_num = itoq(r); @@ -2186,11 +2251,11 @@ o_issimple(void) vp = vp->v_addr; r = 0; switch (vp->v_type) { - case V_NULL: - case V_NUM: - case V_COM: - case V_STR: - r = 1; + case V_NULL: + case V_NUM: + case V_COM: + case V_STR: + r = 1; } freevalue(stack); stack->v_num = (r ? qlink(&_qone_) : qlink(&_qzero_)); @@ -2406,40 +2471,40 @@ o_fiaddr(void) } vp = vp->v_addr; switch (vp->v_type) { - case V_OBJ: - if (index >= vp->v_obj->o_actions->oa_count) { - math_error("Index out of bounds for object"); - /*NOTREACHED*/ - } - res = vp->v_obj->o_table + index; - break; - case V_MAT: - m = vp->v_mat; - if (index >= m->m_size) { - math_error("Index out of bounds for matrix"); - /*NOTREACHED*/ - } - res = m->m_table + index; - break; - case V_LIST: - lp = vp->v_list; - res = listfindex(lp, index); - if (res == NULL) { - math_error("Index out of bounds for list"); - /*NOTREACHED*/ - } - break; - case V_ASSOC: - ap = vp->v_assoc; - res = assocfindex(ap, index); - if (res == NULL) { - math_error("Index out of bounds for association"); - /*NOTREACHED*/ - } - break; - default: - math_error("Bad variable type for fast indexing"); + case V_OBJ: + if (index >= vp->v_obj->o_actions->oa_count) { + math_error("Index out of bounds for object"); /*NOTREACHED*/ + } + res = vp->v_obj->o_table + index; + break; + case V_MAT: + m = vp->v_mat; + if (index >= m->m_size) { + math_error("Index out of bounds for matrix"); + /*NOTREACHED*/ + } + res = m->m_table + index; + break; + case V_LIST: + lp = vp->v_list; + res = listfindex(lp, index); + if (res == NULL) { + math_error("Index out of bounds for list"); + /*NOTREACHED*/ + } + break; + case V_ASSOC: + ap = vp->v_assoc; + res = assocfindex(ap, index); + if (res == NULL) { + math_error("Index out of bounds for association"); + /*NOTREACHED*/ + } + break; + default: + math_error("Bad variable type for fast indexing"); + /*NOTREACHED*/ } stack->v_addr = res; } @@ -2925,18 +2990,23 @@ o_preinc(void) VALUE *vp, tmp; if (stack->v_type == V_OCTET) { + if (stack->v_subtype & (V_NONEWVALUE | V_NOCOPYTO)) { + *stack = error_value(E_PREINC1); + return; + } stack->v_octet[0] = stack->v_octet[0] + 1; return; } if (stack->v_type != V_ADDR) { - math_error("Preincrementing non-variable"); - /*NOTREACHED*/ + freevalue(stack); + *stack = error_value(E_PREINC2); + return; } vp = stack->v_addr; - if (vp->v_subtype & V_NOASSIGNTO) { - math_error("No-assign-to variable for pre ++"); - /*NOTREACHED*/ + if (vp->v_subtype & (V_NONEWVALUE | V_NOASSIGNTO)) { + *stack = error_value(E_PREINC3); + return; } incvalue(vp, &tmp); freevalue(vp); @@ -2950,17 +3020,22 @@ o_predec(void) VALUE *vp, tmp; if (stack->v_type == V_OCTET) { + if (stack->v_subtype & (V_NONEWVALUE | V_NOCOPYTO)) { + *stack = error_value(E_PREDEC1); + return; + } --(*stack->v_octet); return; } if (stack->v_type != V_ADDR) { - math_error("Predecrementing non-variable"); - /*NOTREACHED*/ + freevalue(stack); + *stack = error_value(E_PREDEC2); + return; } vp = stack->v_addr; - if (vp->v_subtype & V_NOASSIGNTO) { - math_error("No-assign-to variable for pre --"); - /*NOTREACHED*/ + if (vp->v_subtype & (V_NONEWVALUE | V_NOASSIGNTO)) { + *stack = error_value(E_PREDEC3); + return; } decvalue(vp, &tmp); freevalue(vp); @@ -2975,6 +3050,11 @@ o_postinc(void) VALUE tmp; if (stack->v_type == V_OCTET) { + if (stack->v_subtype & (V_NONEWVALUE | V_NOCOPYTO)) { + *stack++ = error_value(E_POSTINC1); + stack->v_type = V_NULL; + return; + } stack[1] = stack[0]; stack->v_type = V_NUM; stack->v_subtype = V_NOSUBTYPE; @@ -2984,13 +3064,17 @@ o_postinc(void) return; } if (stack->v_type != V_ADDR) { - math_error("Postincrementing non-variable"); - /*NOTREACHED*/ + stack[1] = *stack; + *stack = error_value(E_POSTINC2); + stack++; + return; } vp = stack->v_addr; - if (vp->v_subtype & V_NOASSIGNTO) { - math_error("No-assign-to variable for post ++"); - /*NOTREACHED*/ + if (vp->v_subtype & V_NONEWVALUE) { + stack[1] = *stack; + *stack = error_value(E_POSTINC3); + stack++; + return; } copyvalue(vp, stack++); incvalue(vp, &tmp); @@ -3009,6 +3093,11 @@ o_postdec(void) VALUE tmp; if (stack->v_type == V_OCTET) { + if (stack->v_subtype & (V_NONEWVALUE | V_NOCOPYTO)) { + *stack++ = error_value(E_POSTDEC1); + stack->v_type = V_NULL; + return; + } stack[1] = stack[0]; stack->v_type = V_NUM; stack->v_num = itoq((long) stack->v_octet[0]); @@ -3017,13 +3106,17 @@ o_postdec(void) return; } if (stack->v_type != V_ADDR) { - math_error("Postdecrementing non-variable"); - /*NOTREACHED*/ + stack[1] = *stack; + *stack = error_value(E_POSTDEC2); + stack++; + return; } vp = stack->v_addr; - if (vp->v_subtype & V_NOASSIGNTO) { - math_error("No-assign-to variable for post --"); - /*NOTREACHED*/ + if (vp->v_subtype & (V_NONEWVALUE | V_NOASSIGNTO)) { + stack[1] = *stack; + *stack = error_value(E_POSTDEC3); + stack++; + return; } copyvalue(vp, stack++); decvalue(vp, &tmp); @@ -3442,24 +3535,24 @@ o_show(FUNC *fp, long arg) unsigned int size; switch((int) arg) { - case 1: showbuiltins(); return; - case 2: showglobals(); return; - case 3: showfunctions(); return; - case 4: showobjfuncs(); return; - case 5: config_print(conf); putchar('\n'); return; - case 6: showobjtypes(); return; - case 7: showfiles(); return; - case 8: showsizes(); return; - case 9: showerrors(); return; - case 10: showcustom(); return; - case 11: shownblocks(); return; - case 12: showconstants(); return; - case 13: showallglobals(); return; - case 14: showstatics(); return; - case 15: shownumbers(); return; - case 16: showredcdata(); return; - case 17: showstrings(); return; - case 18: showliterals(); return; + case 1: showbuiltins(); return; + case 2: showglobals(); return; + case 3: showfunctions(); return; + case 4: showobjfuncs(); return; + case 5: config_print(conf); putchar('\n'); return; + case 6: showobjtypes(); return; + case 7: showfiles(); return; + case 8: showsizes(); return; + case 9: showerrors(); return; + case 10: showcustom(); return; + case 11: shownblocks(); return; + case 12: showconstants(); return; + case 13: showallglobals(); return; + case 14: showstatics(); return; + case 15: shownumbers(); return; + case 16: showredcdata(); return; + case 17: showstrings(); return; + case 18: showliterals(); return; } fp = findfunc(arg - 19); if (fp == NULL) { @@ -3839,64 +3932,64 @@ dumpop(unsigned long *pc) else printf("OP%ld", op); switch (op) { - case OP_LOCALADDR: case OP_LOCALVALUE: - if (dumpnames) - printf(" %s\n", localname((long)*pc)); - else - printf(" %ld\n", *pc); - return 2; - case OP_GLOBALADDR: case OP_GLOBALVALUE: - sp = * (GLOBAL **) pc; - printf(" %s", sp->g_name); - if (sp->g_filescope > SCOPE_GLOBAL) - printf(" %p", (void *) &sp->g_value); - putchar('\n'); - return (1 + PTR_SIZE); - case OP_PARAMADDR: case OP_PARAMVALUE: - if (dumpnames) - printf(" %s\n", paramname((long)*pc)); - else - printf(" %ld\n", *pc); - return 2; - case OP_PRINTSTRING: case OP_STRING: - printf(" \"%s\"\n", findstring((long)(*pc))->s_str); - return 2; - case OP_QUIT: case OP_ABORT: - if ((long)(*pc) >= 0) - printf(" \"%s\"", findstring((long)(*pc))->s_str); - putchar('\n'); - return 2; - case OP_INDEXADDR: - printf(" %ld %ld\n", pc[0], pc[1]); - return 3; - case OP_PRINT: case OP_JUMPZ: case OP_JUMPNZ: case OP_JUMP: - case OP_CONDORJUMP: case OP_CONDANDJUMP: case OP_CASEJUMP: - case OP_INITSTATIC: case OP_MATCREATE: - case OP_SHOW: case OP_ELEMINIT: case OP_ELEMADDR: - case OP_ELEMVALUE: case OP_JUMPNN: + case OP_LOCALADDR: case OP_LOCALVALUE: + if (dumpnames) + printf(" %s\n", localname((long)*pc)); + else printf(" %ld\n", *pc); - return 2; - case OP_OBJCREATE: - printf(" %s\n", objtypename(*pc)); - return 2; - case OP_NUMBER: case OP_IMAGINARY: - qprintf(" %r", constvalue(*pc)); - printf("\n"); - return 2; - case OP_DEBUG: - printf(" line %ld\n", *pc); - return 2; - case OP_CALL: - printf(" %s with %ld args\n", - builtinname((long)pc[0]), (long)pc[1]); - return 3; - case OP_USERCALL: - printf(" %s with %ld args\n", - namefunc((long)pc[0]), (long)pc[1]); - return 3; - default: - printf("\n"); - return 1; + return 2; + case OP_GLOBALADDR: case OP_GLOBALVALUE: + sp = * (GLOBAL **) pc; + printf(" %s", sp->g_name); + if (sp->g_filescope > SCOPE_GLOBAL) + printf(" %p", (void *) &sp->g_value); + putchar('\n'); + return (1 + PTR_SIZE); + case OP_PARAMADDR: case OP_PARAMVALUE: + if (dumpnames) + printf(" %s\n", paramname((long)*pc)); + else + printf(" %ld\n", *pc); + return 2; + case OP_PRINTSTRING: case OP_STRING: + printf(" \"%s\"\n", findstring((long)(*pc))->s_str); + return 2; + case OP_QUIT: case OP_ABORT: + if ((long)(*pc) >= 0) + printf(" \"%s\"", findstring((long)(*pc))->s_str); + putchar('\n'); + return 2; + case OP_INDEXADDR: + printf(" %ld %ld\n", pc[0], pc[1]); + return 3; + case OP_PRINT: case OP_JUMPZ: case OP_JUMPNZ: case OP_JUMP: + case OP_CONDORJUMP: case OP_CONDANDJUMP: case OP_CASEJUMP: + case OP_INITSTATIC: case OP_MATCREATE: + case OP_SHOW: case OP_ELEMINIT: case OP_ELEMADDR: + case OP_ELEMVALUE: case OP_JUMPNN: + printf(" %ld\n", *pc); + return 2; + case OP_OBJCREATE: + printf(" %s\n", objtypename(*pc)); + return 2; + case OP_NUMBER: case OP_IMAGINARY: + qprintf(" %r", constvalue(*pc)); + printf("\n"); + return 2; + case OP_DEBUG: + printf(" line %ld\n", *pc); + return 2; + case OP_CALL: + printf(" %s with %ld args\n", + builtinname((long)pc[0]), (long)pc[1]); + return 3; + case OP_USERCALL: + printf(" %s with %ld args\n", + namefunc((long)pc[0]), (long)pc[1]); + return 3; + default: + printf("\n"); + return 1; } } @@ -3915,38 +4008,38 @@ freenumbers(FUNC *fp) opnum = fp->f_opcodes[pc++]; op = &opcodes[opnum]; switch (op->o_type) { - case OPRET: - case OPARG: - case OPNUL: - continue; - case OPONE: - switch(opnum) { - case OP_NUMBER: - case OP_IMAGINARY: - freeconstant(fp->f_opcodes[pc]); - break; - case OP_PRINTSTRING: - case OP_STRING: - case OP_QUIT: - freestringconstant( - (long)fp->f_opcodes[pc]); - } - /*FALLTHRU*/ - case OPLOC: - case OPPAR: - case OPJMP: - case OPSTI: - pc++; - continue; - case OPTWO: - pc += 2; - continue; - case OPGLB: - pc += PTR_SIZE; - continue; - default: - math_error("Unknown opcode type for freeing"); - /*NOTREACHED*/ + case OPRET: + case OPARG: + case OPNUL: + continue; + case OPONE: + switch(opnum) { + case OP_NUMBER: + case OP_IMAGINARY: + freeconstant(fp->f_opcodes[pc]); + break; + case OP_PRINTSTRING: + case OP_STRING: + case OP_QUIT: + freestringconstant( + (long)fp->f_opcodes[pc]); + } + /*FALLTHRU*/ + case OPLOC: + case OPPAR: + case OPJMP: + case OPSTI: + pc++; + continue; + case OPTWO: + pc += 2; + continue; + case OPGLB: + pc += PTR_SIZE; + continue; + default: + math_error("Unknown opcode type for freeing"); + /*NOTREACHED*/ } } if (pc != fp->f_opcodecount) { diff --git a/qfunc.c b/qfunc.c index 22ec2f3..7ac3117 100644 --- a/qfunc.c +++ b/qfunc.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: qfunc.c,v 29.7 2004/02/23 14:04:01 chongo Exp $ + * @(#) $Revision: 29.9 $ + * @(#) $Id: qfunc.c,v 29.9 2006/05/20 08:43:55 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/RCS/qfunc.c,v $ * * Under source code control: 1990/02/15 01:48:20 @@ -559,14 +559,14 @@ qilog10(NUMBER *q) tmp1 = q->num; tmp1.sign = 0; if (qisint(q)) - return zlog10(tmp1); + return zlog10(tmp1, NULL); /* * The number is not an integer. * Compute the result if the number is greater than one. */ if (zrel(tmp1, q->den) > 0) { zquo(tmp1, q->den, &tmp2, 0); - n = zlog10(tmp2); + n = zlog10(tmp2, NULL); zfree(tmp2); return n; } @@ -580,7 +580,7 @@ qilog10(NUMBER *q) zsub(q->den, _one_, &tmp2); else zquo(q->den, tmp1, &tmp2, 0); - n = -zlog10(tmp2) - 1; + n = -zlog10(tmp2, NULL) - 1; zfree(tmp2); return n; } @@ -937,20 +937,20 @@ qcomb(NUMBER *q, NUMBER *n) } if (qisint(q)) { switch (zcomb(q->num, n->num, &z)) { - case 0: - return qlink(&_qzero_); - case 1: - return qlink(&_qone_); - case -1: - return qlink(&_qnegone_); - case 2: - return qlink(q); - case -2: - return NULL; - default: - r = qalloc(); - r->num = z; - return r; + case 0: + return qlink(&_qzero_); + case 1: + return qlink(&_qone_); + case -1: + return qlink(&_qnegone_); + case 2: + return qlink(q); + case -2: + return NULL; + default: + r = qalloc(); + r->num = z; + return r; } } if (zge31b(n->num)) diff --git a/qio.c b/qio.c index 9066615..dba3b0b 100644 --- a/qio.c +++ b/qio.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: qio.c,v 29.6 2004/02/23 14:04:01 chongo Exp $ + * @(#) $Revision: 29.8 $ + * @(#) $Id: qio.c,v 29.8 2006/05/20 08:43:55 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/RCS/qio.c,v $ * * Under source code control: 1993/07/30 19:42:46 @@ -66,15 +66,15 @@ qprintf(char *fmt, ...) if (ch == '\\') { ch = *fmt++; switch (ch) { - case 'n': ch = '\n'; break; - case 'r': ch = '\r'; break; - case 't': ch = '\t'; break; - case 'f': ch = '\f'; break; - case 'v': ch = '\v'; break; - case 'b': ch = '\b'; break; - case 0: - va_end(ap); - return; + case 'n': ch = '\n'; break; + case 'r': ch = '\r'; break; + case 't': ch = '\t'; break; + case 'f': ch = '\f'; break; + case 'v': ch = '\v'; break; + case 'b': ch = '\b'; break; + case 0: + va_end(ap); + return; } PUTCHAR(ch); continue; @@ -189,69 +189,69 @@ qprintnum(NUMBER *q, int outmode) outmode2 = conf->outmode2; } switch (outmode) { - case MODE_INT: - if (conf->tilde_ok && qisfrac(q)) - PUTCHAR('~'); - qprintfd(q, 0L); - break; + case MODE_INT: + if (conf->tilde_ok && qisfrac(q)) + PUTCHAR('~'); + qprintfd(q, 0L); + break; - case MODE_REAL: - prec = qdecplaces(q); - if ((prec < 0) || (prec > conf->outdigits)) { - if (conf->tilde_ok) - PUTCHAR('~'); - } - if (conf->fullzero || (prec < 0) || - (prec > conf->outdigits)) - prec = conf->outdigits; - qprintff(q, 0L, prec); - break; + case MODE_REAL: + prec = qdecplaces(q); + if ((prec < 0) || (prec > conf->outdigits)) { + if (conf->tilde_ok) + PUTCHAR('~'); + } + if (conf->fullzero || (prec < 0) || + (prec > conf->outdigits)) + prec = conf->outdigits; + qprintff(q, 0L, prec); + break; - case MODE_FRAC: - qprintfr(q, 0L, FALSE); - break; + case MODE_FRAC: + qprintfr(q, 0L, FALSE); + break; - case MODE_EXP: - if (qiszero(q)) { - PUTCHAR('0'); - return; - } - tmpval = *q; - tmpval.num.sign = 0; - exp = qilog10(&tmpval); - if (exp == 0) { /* in range to output as real */ - qprintnum(q, MODE_REAL); - return; - } - tmpval.num = _one_; - tmpval.den = _one_; - if (exp > 0) - ztenpow(exp, &tmpval.den); - else - ztenpow(-exp, &tmpval.num); - q = qmul(q, &tmpval); - zfree(tmpval.num); - zfree(tmpval.den); + case MODE_EXP: + if (qiszero(q)) { + PUTCHAR('0'); + return; + } + tmpval = *q; + tmpval.num.sign = 0; + exp = qilog10(&tmpval); + if (exp == 0) { /* in range to output as real */ qprintnum(q, MODE_REAL); - qfree(q); - PRINTF1("e%ld", exp); - break; + return; + } + tmpval.num = _one_; + tmpval.den = _one_; + if (exp > 0) + ztenpow(exp, &tmpval.den); + else + ztenpow(-exp, &tmpval.num); + q = qmul(q, &tmpval); + zfree(tmpval.num); + zfree(tmpval.den); + qprintnum(q, MODE_REAL); + qfree(q); + PRINTF1("e%ld", exp); + break; - case MODE_HEX: - qprintfx(q, 0L); - break; + case MODE_HEX: + qprintfx(q, 0L); + break; - case MODE_OCTAL: - qprintfo(q, 0L); - break; + case MODE_OCTAL: + qprintfo(q, 0L); + break; - case MODE_BINARY: - qprintfb(q, 0L); - break; + case MODE_BINARY: + qprintfb(q, 0L); + break; - default: - math_error("Bad mode for print"); - /*NOTREACHED*/ + default: + math_error("Bad mode for print"); + /*NOTREACHED*/ } if (outmode2 != MODE2_OFF) { @@ -479,7 +479,7 @@ str2q(char *s) } while ((*t >= '0') && (*t <= '9')) { exp = (exp * 10) + *t++ - '0'; - if (exp > 1000000) { + if (exp > (MAXLONG/10L)) { math_error("Exponent too large"); /*NOTREACHED*/ } diff --git a/qmath.c b/qmath.c index 05a178c..5f22e0b 100644 --- a/qmath.c +++ b/qmath.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.5 $ - * @(#) $Id: qmath.c,v 29.5 2004/02/23 14:04:01 chongo Exp $ + * @(#) $Revision: 29.6 $ + * @(#) $Id: qmath.c,v 29.6 2006/05/20 08:43:55 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/RCS/qmath.c,v $ * * Under source code control: 1990/02/15 01:48:21 @@ -105,12 +105,12 @@ itoq(long i) if ((i >= -1) && (i <= 10)) { switch ((int) i) { - case 0: q = &_qzero_; break; - case 1: q = &_qone_; break; - case 2: q = &_qtwo_; break; - case 10: q = &_qten_; break; - case -1: q = &_qnegone_; break; - default: q = NULL; + case 0: q = &_qzero_; break; + case 1: q = &_qone_; break; + case 2: q = &_qtwo_; break; + case 10: q = &_qten_; break; + case -1: q = &_qnegone_; break; + default: q = NULL; } if (q) return qlink(q); @@ -151,11 +151,11 @@ utoq(FULL i) if (i <= 10) { switch ((int) i) { - case 0: q = &_qzero_; break; - case 1: q = &_qone_; break; - case 2: q = &_qtwo_; break; - case 10: q = &_qten_; break; - default: q = NULL; + case 0: q = &_qzero_; break; + case 1: q = &_qone_; break; + case 2: q = &_qtwo_; break; + case 10: q = &_qten_; break; + default: q = NULL; } if (q) return qlink(q); diff --git a/qmath.h b/qmath.h index fd145df..3553e8a 100644 --- a/qmath.h +++ b/qmath.h @@ -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.5 $ - * @(#) $Id: qmath.h,v 29.5 2001/06/08 21:00:58 chongo Exp $ + * @(#) $Revision: 29.6 $ + * @(#) $Id: qmath.h,v 29.6 2006/05/07 13:04:18 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/RCS/qmath.h,v $ * * Under source code control: 1993/07/30 19:42:47 @@ -187,6 +187,7 @@ extern NUMBER *qcos(NUMBER *q, NUMBER *epsilon); extern NUMBER *qsin(NUMBER *q, NUMBER *epsilon); extern NUMBER *qexp(NUMBER *q, NUMBER *epsilon); extern NUMBER *qln(NUMBER *q, NUMBER *epsilon); +extern NUMBER *qlog(NUMBER *q, NUMBER *epsilon); extern NUMBER *qtan(NUMBER *q, NUMBER *epsilon); extern NUMBER *qsec(NUMBER *q, NUMBER *epsilon); extern NUMBER *qcot(NUMBER *q, NUMBER *epsilon); @@ -269,7 +270,7 @@ extern NUMBER *swap_HALF_in_NUMBER(NUMBER *dest, NUMBER *src, BOOL all); * constants used often by the arithmetic routines */ extern NUMBER _qzero_, _qone_, _qnegone_, _qonehalf_, _qneghalf_, _qonesqbase_; -extern NUMBER _qtwo_, _qthree_, _qfour_; +extern NUMBER _qtwo_, _qthree_, _qfour_, _qten_; extern NUMBER * initnumbs[]; diff --git a/qtrans.c b/qtrans.c index eaa6c77..a1f9352 100644 --- a/qtrans.c +++ b/qtrans.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: qtrans.c,v 29.6 2004/10/23 00:58:59 chongo Exp $ + * @(#) $Revision: 29.7 $ + * @(#) $Id: qtrans.c,v 29.7 2006/05/07 13:04:18 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/RCS/qtrans.c,v $ * * Under source code control: 1990/02/15 01:48:22 @@ -41,6 +41,12 @@ HALF _qlgenum_[] = { 36744 }; HALF _qlgeden_[] = { 25469 }; NUMBER _qlge_ = { { _qlgenum_, 1, 0 }, { _qlgeden_, 1, 0 }, 1, NULL }; +/* + * cache the natural logarithm of 10 + */ +static NUMBER *ln_10 = NULL; +static NUMBER *ln_10_epsilon = NULL; + static NUMBER *pivalue[2]; static NUMBER *qexprel(NUMBER *q, long bitnum); @@ -910,7 +916,7 @@ qln(NUMBER *q, NUMBER *epsilon) BOOL neg; if (qiszero(q) || qiszero(epsilon)) { - math_error("Zero argument for qln"); + math_error("logarithm of 0"); /*NOTREACHED*/ } if (qisunit(q)) @@ -1007,6 +1013,83 @@ qln(NUMBER *q, NUMBER *epsilon) } +/* + * Calculate the base 10 logarithm + * + * log(q) = ln(q) / ln(10) + */ +NUMBER * +qlog(NUMBER *q, NUMBER *epsilon) +{ + int need_new_ln_10 = TRUE; /* FALSE => use cached ln_10 value */ + NUMBER *ln_q; /* ln(x) */ + NUMBER *ret; /* base 10 logarithm of x */ + + /* firewall */ + if (qiszero(q) || qiszero(epsilon)) { + math_error("logarithm of 0"); + /*NOTREACHED*/ + } + + /* + * shortcut for small integer powers of 10 + */ + if (qisint(q) && qispos(q) && !zge8192b(q->num) && ziseven(q->num)) { + BOOL is_10_power; /* TRUE ==> q is a power of 10 */ + long ilog_10; /* integer log base 10 */ + + /* try for a quick small power of 10 log */ + ilog_10 = zlog10(q->num, &is_10_power ); + if (is_10_power == TRUE) { + /* is small power of 10, return log */ + return itoq(ilog_10); + } + /* q is an even integer that is not a power of 10 */ + } + + /* + * compute ln(c) first + */ + ln_q = qln(q, epsilon); + /* log(1) == 0 */ + if (qiszero(ln_q)) { + return ln_q; + } + + /* + * save epsilon for ln(10) if needed + */ + if (ln_10_epsilon == NULL) { + /* first time call */ + ln_10_epsilon = qcopy(epsilon); + } else if (qcmp(ln_10_epsilon, epsilon) == FALSE) { + /* replaced cacheed value with epsilon arg */ + qfree(ln_10_epsilon); + ln_10_epsilon = qcopy(epsilon); + } else if (ln_10 != NULL) { + /* the previously computed ln(2) is OK to use */ + need_new_ln_10 = FALSE; + } + + /* + * compute ln(10) if needed + */ + if (need_new_ln_10 == TRUE) { + if (ln_10 != NULL) { + qfree(ln_10); + } + ln_10 = qln(&_qten_, ln_10_epsilon); + } + + /* + * return ln(q) / ln(10) + */ + ret = qqdiv(ln_q, ln_10); + qfree(ln_q); + return ret; +} + + /* * Calculate the result of raising one number to the power of another. * The result is calculated to the nearest or next to nearest multiple of diff --git a/quickhash.c b/quickhash.c index ae1e11b..6342004 100644 --- a/quickhash.c +++ b/quickhash.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.8 $ - * @(#) $Id: quickhash.c,v 29.8 2004/02/25 23:55:38 chongo Exp $ + * @(#) $Revision: 29.9 $ + * @(#) $Id: quickhash.c,v 29.9 2006/05/20 08:43:55 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/RCS/quickhash.c,v $ * * Under source code control: 1995/03/04 11:34:23 @@ -185,46 +185,46 @@ QCKHASH hashvalue(VALUE *vp, QCKHASH val) { switch (vp->v_type) { - case V_INT: - val += V_NUM; - return quasi_fnv(vp->v_int, val); - case V_NUM: - return fnv_qhash(vp->v_num, val); - case V_COM: - return fnv_chash(vp->v_com, val); - case V_STR: - return fnv_STRhash(vp->v_str, val); - case V_NULL: - return val; - case V_OBJ: - return objhash(vp->v_obj, val); - case V_LIST: - return listhash(vp->v_list, val); - case V_ASSOC: - return assochash(vp->v_assoc, val); - case V_MAT: - return mathash(vp->v_mat, val); - case V_FILE: - val += V_FILE; - return quasi_fnv(vp->v_file, val); - case V_RAND: - return randhash(vp->v_rand, val); - case V_RANDOM: - return randomhash(vp->v_random, val); - case V_CONFIG: - return config_hash(vp->v_config, val); - case V_HASH: - return hash_hash(vp->v_hash, val); - case V_BLOCK: - return blk_hash(vp->v_block, val); - case V_OCTET: - val += V_OCTET; - return quasi_fnv((int)*vp->v_octet, val); - case V_NBLOCK: - return blk_hash(vp->v_nblock->blk, val); - default: - math_error("Hashing unknown value"); - /*NOTREACHED*/ + case V_INT: + val += V_NUM; + return quasi_fnv(vp->v_int, val); + case V_NUM: + return fnv_qhash(vp->v_num, val); + case V_COM: + return fnv_chash(vp->v_com, val); + case V_STR: + return fnv_STRhash(vp->v_str, val); + case V_NULL: + return val; + case V_OBJ: + return objhash(vp->v_obj, val); + case V_LIST: + return listhash(vp->v_list, val); + case V_ASSOC: + return assochash(vp->v_assoc, val); + case V_MAT: + return mathash(vp->v_mat, val); + case V_FILE: + val += V_FILE; + return quasi_fnv(vp->v_file, val); + case V_RAND: + return randhash(vp->v_rand, val); + case V_RANDOM: + return randomhash(vp->v_random, val); + case V_CONFIG: + return config_hash(vp->v_config, val); + case V_HASH: + return hash_hash(vp->v_hash, val); + case V_BLOCK: + return blk_hash(vp->v_block, val); + case V_OCTET: + val += V_OCTET; + return quasi_fnv((int)*vp->v_octet, val); + case V_NBLOCK: + return blk_hash(vp->v_nblock->blk, val); + default: + math_error("Hashing unknown value"); + /*NOTREACHED*/ } return (QCKHASH)0; } diff --git a/size.c b/size.c index 2058e54..de00c2d 100644 --- a/size.c +++ b/size.c @@ -1,7 +1,7 @@ /* * size - size and sizeof functions are implemented here * - * Copyright (C) 1999 David I. Bell + * Copyright (C) 1999-2006 David I. Bell * * Calc is open software; you can redistribute it and/or modify it under * the terms of the version 2.1 of the GNU Lesser General Public License @@ -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: size.c,v 29.2 2000/06/07 14:02:13 chongo Exp $ + * @(#) $Revision: 29.4 $ + * @(#) $Id: size.c,v 29.4 2006/05/19 15:26:10 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/RCS/size.c,v $ * * Under source code control: 1997/03/10 01:56:51 @@ -37,11 +37,11 @@ /* * forward declarations */ -static long zsize(ZVALUE); -static long qsize(NUMBER*); -static long csize(COMPLEX*); -static long memzsize(ZVALUE); -static long memqsize(NUMBER*); +static size_t zsize(ZVALUE); +static size_t qsize(NUMBER*); +static size_t csize(COMPLEX*); +static size_t memzsize(ZVALUE); +static size_t memqsize(NUMBER*); /* @@ -124,14 +124,14 @@ elm_count(VALUE *vp) * returns: * value size */ -static long +static size_t zsize(ZVALUE z) { /* ignore the size of 0, 1 and -1 */ if (z.v != _zeroval_ && z.v != _oneval_ && !zisunit(z) && !ziszero(z)) { - return (long)z.len * (long)sizeof(HALF); + return z.len * sizeof(HALF); } else { - return (long)0; + return (size_t)0; } } @@ -148,7 +148,7 @@ zsize(ZVALUE z) * returns: * value size */ -static long +static size_t qsize(NUMBER *q) { /* ingore denominator parts of integers */ @@ -173,7 +173,7 @@ qsize(NUMBER *q) * returns: * value size */ -static long +static size_t csize(COMPLEX *c) { /* ingore denominator parts of integers */ @@ -194,10 +194,10 @@ csize(COMPLEX *c) * returns: * memory footprint */ -static long +static size_t memzsize(ZVALUE z) { - return (long)sizeof(ZVALUE) + ((long)z.len * (long)sizeof(HALF)); + return sizeof(ZVALUE) + (z.len * sizeof(HALF)); } @@ -210,10 +210,10 @@ memzsize(ZVALUE z) * returns: * memory footprint */ -static long +static size_t memqsize(NUMBER *q) { - return (long)sizeof(NUMBER) + memzsize(q->num) + memzsize(q->den); + return sizeof(NUMBER) + memzsize(q->num) + memzsize(q->den); } @@ -226,7 +226,7 @@ memqsize(NUMBER *q) * returns: * memory footprint */ -long +size_t lsizeof(VALUE *vp) { VALUE *p; @@ -234,7 +234,7 @@ lsizeof(VALUE *vp) OBJECTACTIONS *oap; ASSOCELEM *aep; ASSOCELEM **ept; - long s; + size_t s; long i; /* @@ -294,20 +294,20 @@ lsizeof(VALUE *vp) s = sizeof(RAND); break; case V_RANDOM: - s = (long)sizeof(RANDOM) + + s = sizeof(RANDOM) + zsize(vp->v_random->n) + zsize(vp->v_random->r); break; case V_CONFIG: - s = (long)sizeof(CONFIG) + - (long)strlen(vp->v_config->prompt1) + - (long)strlen(vp->v_config->prompt2) + 2; + s = sizeof(CONFIG) + + strlen(vp->v_config->prompt1) + + strlen(vp->v_config->prompt2) + 2; break; case V_HASH: /* ignore the unused part of the union */ - s = (long)sizeof(HASH) + + s = sizeof(HASH) + vp->v_hash->unionsize - - (long)sizeof(vp->v_hash->h_union); + sizeof(vp->v_hash->h_union); break; case V_BLOCK: s = vp->v_block->maxsize; @@ -333,10 +333,10 @@ lsizeof(VALUE *vp) * returns: * memory footprint including overhead */ -long +size_t memsize(VALUE *vp) { - long s; + size_t s; long i, j; VALUE *p; LISTELEM *ep; @@ -351,7 +351,7 @@ memsize(VALUE *vp) * This is not the number of elements, see elm_count() for that info. */ i = j = 0; - s = (long) sizeof(VALUE); + s = sizeof(VALUE); if (vp->v_type > 0) { switch(vp->v_type) { case V_INT: @@ -362,12 +362,12 @@ memsize(VALUE *vp) s = memqsize(vp->v_num); break; case V_COM: - s = (long)sizeof(COMPLEX) + + s = sizeof(COMPLEX) + memqsize(vp->v_com->real) + memqsize(vp->v_com->imag); break; case V_STR: - s = (long)sizeof(STRING) + vp->v_str->s_len + 1; + s = sizeof(STRING) + vp->v_str->s_len + 1; break; case V_MAT: s = sizeof(MATRIX); @@ -415,25 +415,25 @@ memsize(VALUE *vp) s = sizeof(RAND); break; case V_RANDOM: - s = (long)sizeof(RANDOM) + + s = sizeof(RANDOM) + memzsize(vp->v_random->n) + memzsize(vp->v_random->r); break; case V_CONFIG: - s = (long)sizeof(CONFIG) + 2 + - (long)strlen(vp->v_config->prompt1) + - (long)strlen(vp->v_config->prompt2); + s = sizeof(CONFIG) + 2 + + strlen(vp->v_config->prompt1) + + strlen(vp->v_config->prompt2); break; case V_HASH: s = sizeof(HASH); break; case V_BLOCK: - s = (long)sizeof(BLOCK) + vp->v_block->maxsize; + s = sizeof(BLOCK) + vp->v_block->maxsize; break; case V_NBLOCK: - s = (long)sizeof(NBLOCK) + (long)sizeof(BLOCK) + + s = sizeof(NBLOCK) + sizeof(BLOCK) + vp->v_nblock->blk->maxsize + - (long)strlen(vp->v_nblock->name) + 1; + strlen(vp->v_nblock->name) + 1; break; default: math_error("memsize not defined for value type"); diff --git a/string.c b/string.c index 241335c..b21dd87 100644 --- a/string.c +++ b/string.c @@ -1,7 +1,7 @@ /* * string - string list routines * - * Copyright (C) 1999-2004 David I. Bell and Ernest Bowen + * Copyright (C) 1999-2006 David I. Bell and Ernest Bowen * * Primary author: David I. Bell * @@ -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: string.c,v 29.4 2004/02/23 14:04:01 chongo Exp $ + * @(#) $Revision: 29.9 $ + * @(#) $Id: string.c,v 29.9 2006/05/20 10:13:39 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/RCS/string.c,v $ * * Under source code control: 1990/02/15 01:48:10 @@ -45,7 +45,7 @@ static char *chartable; /* single character string table */ static struct { long l_count; /* count of strings in table */ long l_maxcount; /* maximum strings storable in table */ - long l_avail; /* characters available in current string */ + size_t l_avail; /* characters available in current string */ char *l_alloc; /* next available string storage */ char **l_table; /* current string table */ } literals; @@ -89,11 +89,11 @@ addstr(STRINGHEAD *hp, char *str) char *retstr; /* returned string pointer */ char *list; /* string list */ long newsize; /* new size of string list */ - long len; /* length of current string */ + size_t len; /* length of current string */ if ((str == NULL) || (*str == '\0')) return NULL; - len = (long)strlen(str) + 1; + len = strlen(str) + 1; if (hp->h_avail <= len) { newsize = len + 2000 + hp->h_used + hp->h_avail; list = (char *)realloc(hp->h_list, newsize); @@ -151,17 +151,17 @@ int findstr(STRINGHEAD *hp, char *str) { register char *test; /* string being tested */ - long len; /* length of string being found */ - long testlen; /* length of test string */ + size_t len; /* length of string being found */ + size_t testlen; /* length of test string */ int index; /* index of string */ if ((hp->h_count <= 0) || (str == NULL)) return -1; - len = (long)strlen(str); + len = strlen(str); test = hp->h_list; index = 0; while (*test) { - testlen = (long)strlen(test); + testlen = strlen(test); if ((testlen == len) && (*test == *str) && (strcmp(test, str) == 0)) return index; test += (testlen + 1); @@ -177,7 +177,7 @@ findstr(STRINGHEAD *hp, char *str) * * given: * hp header of string storage - * n + * n string index */ char * namestr(STRINGHEAD *hp, long n) @@ -213,13 +213,13 @@ long stringindex(char *format, char *test) { long index; /* found index */ - long len; /* length of current piece of string */ - long testlen; /* length of test string */ + size_t len; /* length of current piece of string */ + size_t testlen; /* length of test string */ - testlen = (long)strlen(test); + testlen = strlen(test); index = 1; while (*format) { - len = (long)strlen(format); + len = strlen(format); if ((len == testlen) && (*format == *test) && (strcmp(format, test) == 0)) return index; @@ -241,9 +241,9 @@ addliteral(char *str) register char **table; /* table of strings */ char *newstr; /* newly allocated string */ long count; /* number of strings */ - long len; /* length of string to allocate */ + size_t len; /* length of string to allocate */ - len = (long)strlen(str); + len = strlen(str); if (len <= 1) return charstr(*str); /* @@ -320,10 +320,6 @@ stringadd(STRING *s1, STRING *s2) char *cfrom, *c; long len; - if (s1->s_len == 0) - return slink(s2); - if (s2->s_len == 0) - return slink(s1); len = s1->s_len + s2->s_len; s = stralloc(); s->s_len = len; @@ -391,7 +387,7 @@ STRING * stringmul(NUMBER *q, STRING *str) { long len; - long j; + size_t j; NUMBER *tmp1, *tmp2; char *c, *c1; STRING *s; @@ -414,12 +410,8 @@ stringmul(NUMBER *q, STRING *str) len = qtoi(tmp1); qfree(tmp1); qfree(q); - if (len == 0) { - s = stralloc(); - s->s_len = 0; - s->s_str = charstr('\0'); - return s; - } + if (len == 0) + return slink(&_nullstring_); c = (char *) malloc(len + 1); if (c == NULL) return NULL; @@ -445,7 +437,7 @@ STRING * stringand(STRING *s1, STRING *s2) { STRING *s; - long len; + size_t len; char *c1, *c2, *c; if (s1->s_len == 0 || s2->s_len == 0) @@ -543,7 +535,7 @@ STRING * stringdiff(STRING *s1, STRING *s2) { STRING *s; - long i; + size_t i; char *c2, *c; i = s1->s_len; @@ -589,15 +581,16 @@ stringsegment(STRING *s1, long n1, long n2) char *c, *c1; long len; - if ((n1 < 0 && n2 < 0) || (n1 >= s1->s_len && n2 >= s1->s_len)) + if ((n1 < 0 && n2 < 0) || + ((size_t)n1 >= s1->s_len && (size_t)n2 >= s1->s_len)) return slink(&_nullstring_); if (n1 < 0) n1 = 0; if (n2 < 0) n2 = 0; - if (n1 >= s1->s_len) + if ((size_t)n1 >= s1->s_len) n1 = s1->s_len - 1; - if (n2 >= s1->s_len) + if ((size_t)n2 >= s1->s_len) n2 = s1->s_len - 1; len = (n1 >= n2) ? n1 - n2 + 1 : n2 - n1 + 1; s = stralloc(); @@ -688,41 +681,51 @@ stringshift(STRING *s1, long n) } /* - * stringcpy copies as many characters as possible up to and including - * the first '\0' from s2 to s1 and returns s1 + * stringcpy copies as many characters as possible + * from s2 to s1 and returns s1 */ STRING * stringcpy(STRING *s1, STRING *s2) { char *c1, *c2; - long len; + size_t num; - c1 = s1->s_str; - c2 = s2->s_str; - len = s1->s_len; - while (len-- > 0 && *c2 != 0) - *c1++ = *c2++; - *c1 = '\0'; + if (s1->s_len > 0) { + c1 = s1->s_str; + c2 = s2->s_str; + num = s1->s_len; + if (num > s2->s_len) + num = s2->s_len; + while (num-- > 0) + *c1++ = *c2++; + *c1 = '\0'; + } return slink(s1); } /* - * stringncpy copies up to n characters from s2 to s1 and returns s1 + * stringncpy copies up to num characters from s2 to s1 and returns s1 + * If num > size(s2) null characters are copied until s1 is full or + * a total of num characters have been copied */ STRING * -stringncpy(STRING *s1, STRING *s2, long num) +stringncpy(STRING *s1, STRING *s2, size_t num) { char *c1, *c2; + size_t i; if (num > s1->s_len) num = s1->s_len; + i = num; + if (i > s2->s_len) + i = s2->s_len; c1 = s1->s_str; c2 = s2->s_str; - while (num-- > 0 && *c2 != 0) + while (i-- > 0) *c1++ = *c2++; - while (num-- > 0) - *c1++ = '\0'; - *c1 = '\0'; + if (num > s2->s_len) { + memset(c1, 0, num - s2->s_len); + } return slink(s1); } @@ -824,15 +827,18 @@ stringrel(STRING *s1, STRING *s2) char *c1, *c2; long i1, i2; + if (s1 == s2) + return 0; + i1 = s1->s_len; i2 = s2->s_len; - if (i1 == 0) - return (i2 > 0); if (i2 == 0) + return (i1 > 0); + if (i1 == 0) return -1; c1 = s1->s_str; c2 = s2->s_str; - while (i1 > 0 && i2 > 0 && *c1 == *c2) { + while (i1 > 1 && i2 > 1 && *c1 == *c2) { i1--; i2--; c1++; @@ -862,7 +868,7 @@ stringbit(STRING *s, long index) return -1; res = index & 7; index >>= 3; - if (index >= s->s_len) + if ((size_t)index >= s->s_len) return -1; ch = s->s_str[index]; return (ch >> res) & 1; @@ -899,7 +905,7 @@ stringsetbit(STRING *s, long index, BOOL val) return 1; bit = 1 << (index & 7); index >>= 3; - if (index >= s->s_len) + if ((size_t)index >= s->s_len) return 2; c = &s->s_str[index]; *c &= ~bit; @@ -1059,9 +1065,9 @@ STRING * makestring(char *str) { STRING *s; - long len; + size_t len; - len = (long)strlen(str); + len = strlen(str); s = stralloc(); s->s_str = str; s->s_len = len; @@ -1097,9 +1103,9 @@ makenewstring(char *str) { STRING *s; char *c; - long len; + size_t len; - len = (long)strlen(str); + len = strlen(str); if (len == 0) return slink(&_nullstring_); c = (char *) malloc(len + 1); @@ -1189,7 +1195,7 @@ initstrings(void) * When called, len is length of string including '\0' */ long -addstring(char *str, long len) +addstring(char *str, size_t len) { STRING **sp; STRING *s; @@ -1198,6 +1204,9 @@ addstring(char *str, long len) long first; /* first non-null position found */ BOOL havefirst; + if (len < 1) { + math_error("addstring length including trailing NUL < 1"); + } if (stringconstavail <= 0) { if (stringconsttable == NULL) { initstrings(); @@ -1297,16 +1306,16 @@ printechar(char *c) putchar('\\'); ech = 0; switch (ch) { - case '\n': ech = 'n'; break; - case '\r': ech = 'r'; break; - case '\t': ech = 't'; break; - case '\b': ech = 'b'; break; - case '\f': ech = 'f'; break; - case '\v': ech = 'v'; break; - case '\\': ech = '\\'; break; - case '\"': ech = '\"'; break; - case 7: ech = 'a'; break; - case 27: ech = 'e'; break; + case '\n': ech = 'n'; break; + case '\r': ech = 'r'; break; + case '\t': ech = 't'; break; + case '\b': ech = 'b'; break; + case '\f': ech = 'f'; break; + case '\v': ech = 'v'; break; + case '\\': ech = '\\'; break; + case '\"': ech = '\"'; break; + case 7: ech = 'a'; break; + case 27: ech = 'e'; break; } if (ech) { putchar(ech); @@ -1355,9 +1364,9 @@ fitstring(char *str, long len, long width) continue; n++; switch (ch) { - case '\n': case '\r': case '\t': case '\b': case '\f': - case '\v': case '\\': case '\"': case 7: case 27: - continue; + case '\n': case '\r': case '\t': case '\b': case '\f': + case '\v': case '\\': case '\"': case 7: case 27: + continue; } if (ch >= 64 || (nch >= '0' && nch <= '7')) { n += 2; @@ -1383,13 +1392,13 @@ showstrings(void) printf("Index Links Length String\n"); printf("----- ----- ------ ------\n"); sp = &_nullstring_; - printf(" 0 %5ld 0 \"\"\n", sp->s_links); + printf(" 0 %5ld 0 \"\"\n", sp->s_links); for (i = 0, k = 1, count = 1; i < blockcount; i++) { sp = firstStrs[i]; for (j = 0; j < STRALLOC; j++, k++, sp++) { if (sp->s_links > 0) { ++count; - printf("%5ld %5ld %6ld \"", + printf("%5ld %5ld %6u \"", k, sp->s_links, sp->s_len); fitstring(sp->s_str, sp->s_len, 50); printf("\"\n"); @@ -1414,7 +1423,7 @@ showliterals(void) sp = stringconsttable[i]; if (sp->s_links > 0) { ++count; - printf("%5ld %5ld %6ld \"", + printf("%5ld %5ld %6u \"", i, sp->s_links, sp->s_len); fitstring(sp->s_str, sp->s_len, 50); printf("\"\n"); diff --git a/string.h b/string.h index d0ee4a3..671daa5 100644 --- a/string.h +++ b/string.h @@ -1,7 +1,7 @@ /* * string - string list routines * - * Copyright (C) 1999 David I. Bell + * Copyright (C) 1999-2006 David I. Bell * * Calc is open software; you can redistribute it and/or modify it under * the terms of the version 2.1 of the GNU Lesser General Public License @@ -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: string.h,v 29.4 2001/06/08 21:00:58 chongo Exp $ + * @(#) $Revision: 29.6 $ + * @(#) $Id: string.h,v 29.6 2006/05/19 15:26:10 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/RCS/string.h,v $ * * Under source code control: 1990/02/15 01:48:36 @@ -41,7 +41,7 @@ struct string { char *s_str; - long s_len; + size_t s_len; long s_links; struct string *s_next; }; @@ -51,8 +51,8 @@ typedef struct string STRING; typedef struct { char *h_list; /* list of strings separated by nulls */ - long h_used; /* characters used so far */ - long h_avail; /* characters available for use */ + size_t h_used; /* characters used so far */ + size_t h_avail; /* characters available for use */ long h_count; /* number of strings */ } STRINGHEAD; @@ -65,7 +65,7 @@ extern char *charstr(int ch); extern char *addliteral(char *str); extern long stringindex(char *str1, char *str2); extern STRING *stralloc(void); -extern long addstring(char *str, long len); +extern long addstring(char *str, size_t len); extern STRING *charstring(int ch); extern STRING *makestring(char *str); extern STRING *makenewstring(char *str); diff --git a/symbol.c b/symbol.c index 8635fc2..f3bf6d2 100644 --- a/symbol.c +++ b/symbol.c @@ -1,7 +1,7 @@ /* * symbol - global and local symbol routines * - * Copyright (C) 1999 David I. Bell and Ernest Bowen + * Copyright (C) 1999-2006 David I. Bell and Ernest Bowen * * Primary author: David I. Bell * @@ -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: symbol.c,v 29.2 2000/06/07 14:02:13 chongo Exp $ + * @(#) $Revision: 29.5 $ + * @(#) $Id: symbol.c,v 29.5 2006/05/20 08:43:55 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/RCS/symbol.c,v $ * * Under source code control: 1990/02/15 01:48:23 @@ -94,7 +94,7 @@ addglobal(char *name, BOOL isstatic) { GLOBAL *sp; /* current symbol pointer */ GLOBAL **hp; /* hash table head address */ - int len; /* length of string */ + size_t len; /* length of string */ int newfilescope; /* file scope being looked for */ int newfuncscope; /* function scope being looked for */ @@ -104,7 +104,7 @@ addglobal(char *name, BOOL isstatic) newfilescope = filescope; newfuncscope = funcscope; } - len = (int)strlen(name); + len = strlen(name); if (len <= 0) return NULL; hp = &globalhash[HASHSYM(name, len)]; @@ -140,10 +140,10 @@ findglobal(char *name) { GLOBAL *sp; /* current symbol pointer */ GLOBAL *bestsp; /* found symbol with highest scope */ - long len; /* length of string */ + size_t len; /* length of string */ bestsp = NULL; - len = (long) strlen(name); + len = strlen(name); for (sp = globalhash[HASHSYM(name, len)]; sp; sp = sp->g_next) { if ((sp->g_len == len) && !strcmp(sp->g_name, name)) { if ((bestsp == NULL) || @@ -243,76 +243,76 @@ printtype(VALUE *vp) return; } switch (type) { - case V_NUM: - printf("real = "); - fitprint(vp->v_num, 32); - return; - case V_COM: - printf("complex = "); - fitprint(vp->v_com->real, 8); - if (!vp->v_com->imag->num.sign) - printf("+"); - fitprint(vp->v_com->imag, 8); - printf("i"); - return; - case V_STR: - printf("string = \""); - fitstring(vp->v_str->s_str, vp->v_str->s_len, 50); - printf("\""); - return; - case V_NULL: - s = "null"; - break; - case V_MAT: - s = "matrix"; - break; - case V_LIST: - s = "list"; - break; - case V_ASSOC: - s = "association"; - break; - case V_OBJ: - printf("%s ", objtypename( - vp->v_obj->o_actions->oa_index)); - s = "object"; - break; - case V_FILE: - s = "file id"; - break; - case V_RAND: - s = "additive 55 random state"; - break; - case V_RANDOM: - s = "Blum random state"; - break; - case V_CONFIG: - s = "config state"; - break; - case V_HASH: - s = "hash state"; - break; - case V_BLOCK: - s = "unnamed block"; - break; - case V_NBLOCK: - s = "named block"; - break; - case V_VPTR: - s = "value pointer"; - break; - case V_OPTR: - s = "octet pointer"; - break; - case V_SPTR: - s = "string pointer"; - break; - case V_NPTR: - s = "number pointer"; - break; - default: - s = "???"; - break; + case V_NUM: + printf("real = "); + fitprint(vp->v_num, 32); + return; + case V_COM: + printf("complex = "); + fitprint(vp->v_com->real, 8); + if (!vp->v_com->imag->num.sign) + printf("+"); + fitprint(vp->v_com->imag, 8); + printf("i"); + return; + case V_STR: + printf("string = \""); + fitstring(vp->v_str->s_str, vp->v_str->s_len, 50); + printf("\""); + return; + case V_NULL: + s = "null"; + break; + case V_MAT: + s = "matrix"; + break; + case V_LIST: + s = "list"; + break; + case V_ASSOC: + s = "association"; + break; + case V_OBJ: + printf("%s ", objtypename( + vp->v_obj->o_actions->oa_index)); + s = "object"; + break; + case V_FILE: + s = "file id"; + break; + case V_RAND: + s = "additive 55 random state"; + break; + case V_RANDOM: + s = "Blum random state"; + break; + case V_CONFIG: + s = "config state"; + break; + case V_HASH: + s = "hash state"; + break; + case V_BLOCK: + s = "unnamed block"; + break; + case V_NBLOCK: + s = "named block"; + break; + case V_VPTR: + s = "value pointer"; + break; + case V_OPTR: + s = "octet pointer"; + break; + case V_SPTR: + s = "string pointer"; + break; + case V_NPTR: + s = "number pointer"; + break; + default: + s = "???"; + break; } printf("%s", s); } @@ -339,12 +339,12 @@ writeglobals(char *name) for (hp = &globalhash[HASHSIZE-1]; hp >= globalhash; hp--) { for (sp = *hp; sp; sp = sp->g_next) { switch (sp->g_value.v_type) { - case V_NUM: - case V_COM: - case V_STR: - break; - default: - continue; + case V_NUM: + case V_COM: + case V_STR: + break; + default: + continue; } math_fmt("%s = ", sp->g_name); savemode = math_setmode(MODE_HEX); @@ -496,7 +496,7 @@ endscope(char *name, BOOL isglobal) GLOBAL *sp; GLOBAL *prevsp; GLOBAL **hp; - int len; + size_t len; len = strlen(name); prevsp = NULL; diff --git a/symbol.h b/symbol.h index 9b38b4f..c43ce22 100644 --- a/symbol.h +++ b/symbol.h @@ -1,7 +1,7 @@ /* * symbol - global and local symbol routines * - * Copyright (C) 1999 David I. Bell + * Copyright (C) 1999-2006 David I. Bell * * Calc is open software; you can redistribute it and/or modify it under * the terms of the version 2.1 of the GNU Lesser General Public License @@ -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: symbol.h,v 29.4 2001/06/08 21:00:58 chongo Exp $ + * @(#) $Revision: 29.6 $ + * @(#) $Id: symbol.h,v 29.6 2006/05/19 15:26:10 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/RCS/symbol.h,v $ * * Under source code control: 1990/02/15 01:48:37 @@ -54,7 +54,7 @@ typedef struct global GLOBAL; struct global { - int g_len; /* length of symbol name */ + size_t g_len; /* length of symbol name */ short g_filescope; /* file scope level of symbol (0 if global) */ short g_funcscope; /* function scope level of symbol */ char *g_name; /* global symbol name */ diff --git a/token.c b/token.c index ed5062a..4db1980 100644 --- a/token.c +++ b/token.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.4 $ - * @(#) $Id: token.c,v 29.4 2000/07/17 15:35:49 chongo Exp $ + * @(#) $Revision: 29.6 $ + * @(#) $Id: token.c,v 29.6 2006/05/20 08:43:55 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/RCS/token.c,v $ * * Under source code control: 1990/02/15 01:48:25 @@ -214,147 +214,143 @@ gettoken(void) break; case '^': switch (nextchar()) { - case '=': type = T_POWEREQUALS; break; - default: type = T_POWER; reread(); + case '=': type = T_POWEREQUALS; break; + default: type = T_POWER; reread(); } break; case '=': switch (nextchar()) { - case '=': type = T_EQ; break; - default: type = T_ASSIGN; reread(); + case '=': type = T_EQ; break; + default: type = T_ASSIGN; reread(); } break; case '+': switch (nextchar()) { - case '+': type = T_PLUSPLUS; break; - case '=': type = T_PLUSEQUALS; break; - default: type = T_PLUS; reread(); + case '+': type = T_PLUSPLUS; break; + case '=': type = T_PLUSEQUALS; break; + default: type = T_PLUS; reread(); } break; case '-': switch (nextchar()) { - case '-': type = T_MINUSMINUS; break; - case '=': type = T_MINUSEQUALS; break; - case '>': type = T_ARROW; break; - default: type = T_MINUS; reread(); + case '-': type = T_MINUSMINUS; break; + case '=': type = T_MINUSEQUALS; break; + case '>': type = T_ARROW; break; + default: type = T_MINUS; reread(); } break; case '*': switch (nextchar()) { - case '=': type = T_MULTEQUALS; break; - case '*': - switch (nextchar()) { - case '=': - type = T_POWEREQUALS; break; - default: - type = T_POWER; reread(); - } - break; - default: type = T_MULT; reread(); + case '=': type = T_MULTEQUALS; break; + case '*': + switch (nextchar()) { + case '=': + type = T_POWEREQUALS; break; + default: + type = T_POWER; reread(); + } + break; + default: type = T_MULT; reread(); } break; case '/': switch (nextchar()) { - case '/': - switch (nextchar()) { - case '=': - type = T_SLASHSLASHEQUALS; - break; - default: - reread(); - type = T_SLASHSLASH; - break; - } + case '/': + switch (nextchar()) { + case '=': + type = T_SLASHSLASHEQUALS; break; - case '=': type = T_DIVEQUALS; break; - case '*': eatcomment(); break; - default: type = T_DIV; reread(); + default: + reread(); + type = T_SLASHSLASH; + break; + } + break; + case '=': type = T_DIVEQUALS; break; + case '*': eatcomment(); break; + default: type = T_DIV; reread(); } break; case '%': switch (nextchar()) { - case '=': type = T_MODEQUALS; break; - default: type = T_MOD; reread(); + case '=': type = T_MODEQUALS; break; + default: type = T_MOD; reread(); } break; case '<': switch (nextchar()) { - case '=': type = T_LE; break; - case '<': - switch (nextchar()) { - case '=': - type = T_LSHIFTEQUALS; - break; - default: - reread(); - type = T_LEFTSHIFT; - break; - } + case '=': type = T_LE; break; + case '<': + switch (nextchar()) { + case '=': + type = T_LSHIFTEQUALS; break; - default: type = T_LT; reread(); + default: + reread(); + type = T_LEFTSHIFT; + break; + } + break; + default: type = T_LT; reread(); } break; case '>': switch (nextchar()) { - case '=': type = T_GE; break; - case '>': - switch (nextchar()) { - case '=': - type = T_RSHIFTEQUALS; - break; - default: - reread(); - type = T_RIGHTSHIFT; - break; - } + case '=': type = T_GE; break; + case '>': + switch (nextchar()) { + case '=': + type = T_RSHIFTEQUALS; break; - default: type = T_GT; reread(); + default: + reread(); + type = T_RIGHTSHIFT; + break; + } + break; + default: type = T_GT; reread(); } break; case '&': switch (nextchar()) { - case '&': type = T_ANDAND; break; - case '=': type = T_ANDEQUALS; break; - default: type = T_AND; reread(); break; + case '&': type = T_ANDAND; break; + case '=': type = T_ANDEQUALS; break; + default: type = T_AND; reread(); break; } break; case '|': switch (nextchar()) { - case '|': type = T_OROR; break; - case '=': type = T_OREQUALS; break; - default: type = T_OR; reread(); break; + case '|': type = T_OROR; break; + case '=': type = T_OREQUALS; break; + default: type = T_OR; reread(); break; } break; case '!': switch (nextchar()) { - case '=': type = T_NE; break; - default: type = T_NOT; reread(); break; + case '=': type = T_NE; break; + default: type = T_NOT; reread(); break; } break; case '#': switch(nextchar()) { - case '=': type = T_HASHEQUALS; break; - case '!': type = T_POUNDBANG; eatline(); break; - case '#': - case ' ': - case '\t': - type = T_POUNDCOMMENT; eatline(); - break; - case '\n': type = T_POUNDCOMMENT; break; - default: type = T_HASH; reread(); + case '=': type = T_HASHEQUALS; break; + case '!': + case '#': eatline(); break; + case '\n': reread(); break; + default: type = T_HASH; reread(); } break; case '~': switch (nextchar()) { - case '=': type = T_TILDEEQUALS; break; - default: type = T_TILDE; reread(); + case '=': type = T_TILDEEQUALS; break; + default: type = T_TILDE; reread(); } break; case '\\': switch (nextchar()) { - case '\n': setprompt(conf->prompt2); break; - case '=': type = T_BACKSLASHEQUALS; break; - default: type = T_BACKSLASH; reread(); + case '\n': setprompt(conf->prompt2); break; + case '=': type = T_BACKSLASHEQUALS; break; + default: type = T_BACKSLASH; reread(); } break; default: @@ -446,82 +442,82 @@ eatstring(int quotechar) while (!done && len < STRBUFSIZE) { ch = nextchar(); switch (ch) { - case '\n': - if (!newlines) + case '\n': + if (!newlines) + break; + case EOF: + reread(); + scanerror(T_NULL, + "Unterminated string constant"); + done = TRUE; + ch = '\0'; + break; + + case '\\': + ch = nextchar(); + if (isoctal(ch)) { + ch = ch - '0'; + for (i = 2; i > 0; i--) { + cch = nextchar(); + if (!isoctal(cch)) break; + ch = 8 * ch + cch - '0'; + } + ch &= 0xff; + if (i > 0) + reread(); + break; + } + switch (ch) { + case 'n': ch = '\n'; break; + case 'r': ch = '\r'; break; + case 't': ch = '\t'; break; + case 'b': ch = '\b'; break; + case 'f': ch = '\f'; break; + case 'v': ch = '\v'; break; + case 'a': ch = '\007'; break; + case 'e': ch = '\033'; break; + case '\n': + setprompt(conf->prompt2); + continue; case EOF: reread(); - scanerror(T_NULL, - "Unterminated string constant"); + continue; + case 'x': + ch = 0; + for (i = 2; i > 0; i--) { + cch = nextchar(); + if (isdigit(cch)) + ch = 16 * ch + cch - '0'; + else if (cch >= 'a' && cch <= 'f') + ch = 16 * ch + 10 + cch - 'a'; + else if (cch >= 'A' && cch <= 'F') + ch = 16 * ch + 10 + cch - 'A'; + else break; + } + if (i > 0) + reread(); + } + break; + case '"': + case '\'': + if (ch == quotechar) { + for (;;) { + ch = nextchar(); + if (ch != ' ' && ch != '\t' && + (ch != '\n' || + newlines)) + break; + } + if (ch == '"' || ch == '\'') { + quotechar = ch; + continue; + } + reread(); done = TRUE; ch = '\0'; - break; - - case '\\': - ch = nextchar(); - if (isoctal(ch)) { - ch = ch - '0'; - for (i = 2; i > 0; i--) { - cch = nextchar(); - if (!isoctal(cch)) - break; - ch = 8 * ch + cch - '0'; - } - ch &= 0xff; - if (i > 0) - reread(); - break; - } - switch (ch) { - case 'n': ch = '\n'; break; - case 'r': ch = '\r'; break; - case 't': ch = '\t'; break; - case 'b': ch = '\b'; break; - case 'f': ch = '\f'; break; - case 'v': ch = '\v'; break; - case 'a': ch = '\007'; break; - case 'e': ch = '\033'; break; - case '\n': - setprompt(conf->prompt2); - continue; - case EOF: - reread(); - continue; - case 'x': - ch = 0; - for (i = 2; i > 0; i--) { - cch = nextchar(); - if (isdigit(cch)) - ch = 16 * ch + cch - '0'; - else if (cch >= 'a' && cch <= 'f') - ch = 16 * ch + 10 + cch - 'a'; - else if (cch >= 'A' && cch <= 'F') - ch = 16 * ch + 10 + cch - 'A'; - else break; - } - if (i > 0) - reread(); - } - break; - case '"': - case '\'': - if (ch == quotechar) { - for (;;) { - ch = nextchar(); - if (ch != ' ' && ch != '\t' && - (ch != '\n' || - newlines)) - break; - } - if (ch == '"' || ch == '\'') { - quotechar = ch; - continue; - } - reread(); - done = TRUE; - ch = '\0'; - } - break; + } + break; } *cp++ = (char) ch; @@ -738,36 +734,38 @@ scanerror(int skip, char *fmt, ...) /* post-error report processing */ switch (skip) { - case T_NULL: - return; - case T_COMMA: - rescan = TRUE; - for (;;) { - switch (gettoken()) { - case T_NEWLINE: - case T_SEMICOLON: - case T_LEFTBRACE: - case T_RIGHTBRACE: - case T_EOF: - case T_COMMA: - rescan = TRUE; - return; - } + case T_NULL: + return; + case T_COMMA: + rescan = TRUE; + for (;;) { + switch (gettoken()) { + case T_NEWLINE: + case T_SEMICOLON: + case T_LEFTBRACE: + case T_RIGHTBRACE: + case T_EOF: + case T_COMMA: + rescan = TRUE; + return; } - default: - fprintf(stderr, "Unknown skip token for scanerror\n"); - /* fall into semicolon case */ - /*FALLTHRU*/ - case T_SEMICOLON: - rescan = TRUE; - for (;;) switch (gettoken()) { - case T_NEWLINE: - case T_SEMICOLON: - case T_LEFTBRACE: - case T_RIGHTBRACE: - case T_EOF: - rescan = TRUE; - return; + } + default: + fprintf(stderr, "Unknown skip token for scanerror\n"); + /* fall into semicolon case */ + /*FALLTHRU*/ + case T_SEMICOLON: + rescan = TRUE; + for (;;) { + switch (gettoken()) { + case T_NEWLINE: + case T_SEMICOLON: + case T_LEFTBRACE: + case T_RIGHTBRACE: + case T_EOF: + rescan = TRUE; + return; } + } } } diff --git a/value.c b/value.c index 5c96a23..0b0d7d5 100644 --- a/value.c +++ b/value.c @@ -1,7 +1,7 @@ /* * value - generic value manipulation routines * - * Copyright (C) 1999 David I. Bell + * Copyright (C) 1999-2006 David I. Bell * * Calc is open software; you can redistribute it and/or modify it under * the terms of the version 2.1 of the GNU Lesser General Public License @@ -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: value.c,v 29.4 2005/10/18 10:43:49 chongo Exp $ + * @(#) $Revision: 29.8 $ + * @(#) $Id: value.c,v 29.8 2006/05/20 08:43:55 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/RCS/value.c,v $ * * Under source code control: 1990/02/15 01:48:25 @@ -61,55 +61,55 @@ freevalue(VALUE *vp) if (type <= 0) return; switch (type) { - case V_ADDR: - case V_OCTET: - case V_NBLOCK: - case V_FILE: - case V_VPTR: - case V_OPTR: - case V_SPTR: - case V_NPTR: - /* nothing to free */ - break; - case V_STR: - sfree(vp->v_str); - break; - case V_NUM: - qfree(vp->v_num); - break; - case V_COM: - comfree(vp->v_com); - break; - case V_MAT: - matfree(vp->v_mat); - break; - case V_LIST: - listfree(vp->v_list); - break; - case V_ASSOC: - assocfree(vp->v_assoc); - break; - case V_OBJ: - objfree(vp->v_obj); - break; - case V_RAND: - randfree(vp->v_rand); - break; - case V_RANDOM: - randomfree(vp->v_random); - break; - case V_CONFIG: - config_free(vp->v_config); - break; - case V_HASH: - hash_free(vp->v_hash); - break; - case V_BLOCK: - blk_free(vp->v_block); - break; - default: - math_error("Freeing unknown value type"); - /*NOTREACHED*/ + case V_ADDR: + case V_OCTET: + case V_NBLOCK: + case V_FILE: + case V_VPTR: + case V_OPTR: + case V_SPTR: + case V_NPTR: + /* nothing to free */ + break; + case V_STR: + sfree(vp->v_str); + break; + case V_NUM: + qfree(vp->v_num); + break; + case V_COM: + comfree(vp->v_com); + break; + case V_MAT: + matfree(vp->v_mat); + break; + case V_LIST: + listfree(vp->v_list); + break; + case V_ASSOC: + assocfree(vp->v_assoc); + break; + case V_OBJ: + objfree(vp->v_obj); + break; + case V_RAND: + randfree(vp->v_rand); + break; + case V_RANDOM: + randomfree(vp->v_random); + break; + case V_CONFIG: + config_free(vp->v_config); + break; + case V_HASH: + hash_free(vp->v_hash); + break; + case V_BLOCK: + blk_free(vp->v_block); + break; + default: + math_error("Freeing unknown value type"); + /*NOTREACHED*/ } } @@ -118,34 +118,52 @@ freevalue(VALUE *vp) * Set protection status for a value and all of its components */ void -protectall(VALUE *vp, int sts) +protecttodepth(VALUE *vp, int sts, int depth) { VALUE *vq; int i; LISTELEM *ep; + ASSOC *ap; if (vp->v_type == V_NBLOCK) { - vp->v_nblock->subtype |= sts; + if (sts > 0) + vp->v_nblock->subtype |= sts; + else if (sts < 0) + vp->v_nblock->subtype &= ~(-sts); + else vp->v_nblock->subtype = 0; return; } - vp->v_subtype |= sts; - switch(vp->v_type) { - case V_MAT: - vq = vp->v_mat->m_table; - i = vp->v_mat->m_size; - while (i-- > 0) - protectall(vq++, sts); - break; - case V_LIST: - for (ep = vp->v_list->l_first; ep; ep = ep->e_next) - protectall(&ep->e_value, sts); - break; - case V_OBJ: - vq = vp->v_obj->o_table; - i = vp->v_obj->o_actions->oa_count; - while (i-- > 0) - protectall(vq++, sts); - break; + if (sts > 0) + vp->v_subtype |= sts; + else if (sts < 0) + vp->v_subtype &= ~(-sts); + else + vp->v_subtype = 0; + + + if (depth > 0) { + switch(vp->v_type) { + case V_MAT: + vq = vp->v_mat->m_table; + i = vp->v_mat->m_size; + while (i-- > 0) + protecttodepth(vq++, sts, depth - 1); + break; + case V_LIST: + for (ep = vp->v_list->l_first; ep; ep = ep->e_next) + protecttodepth(&ep->e_value, sts, depth - 1); + break; + case V_OBJ: + vq = vp->v_obj->o_table; + i = vp->v_obj->o_actions->oa_count; + while (i-- > 0) + protecttodepth(vq++, sts, depth - 1); + break; + case V_ASSOC: + ap = vp->v_assoc; + for (i = 0; i < ap->a_count; i++) + protecttodepth(assocfindex(ap, i), sts, depth - 1); + } } } @@ -213,12 +231,11 @@ copyvalue(VALUE *oldvp, VALUE *newvp) break; case V_OCTET: newvp->v_type = V_NUM; - newvp->v_subtype = V_NOSUBTYPE; newvp->v_num = itoq((long) *oldvp->v_octet); break; case V_NBLOCK: newvp->v_nblock = oldvp->v_nblock; - return; + break; default: math_error("Copying unknown value type"); /*NOTREACHED*/ @@ -316,34 +333,34 @@ negvalue(VALUE *vp, VALUE *vres) vres->v_type = vp->v_type; vres->v_subtype = V_NOSUBTYPE; switch (vp->v_type) { - case V_NUM: - vres->v_num = qneg(vp->v_num); - return; - case V_COM: - vres->v_com = c_neg(vp->v_com); - return; - case V_MAT: - vres->v_mat = matneg(vp->v_mat); - return; - case V_STR: - vres->v_str = stringneg(vp->v_str); - if (vres->v_str == NULL) - *vres = error_value(E_STRNEG); - return; - case V_OCTET: - vres->v_type = V_NUM; - vres->v_subtype = V_NOSUBTYPE; - vres->v_num = itoq(- (long) *vp->v_octet); - return; + case V_NUM: + vres->v_num = qneg(vp->v_num); + return; + case V_COM: + vres->v_com = c_neg(vp->v_com); + return; + case V_MAT: + vres->v_mat = matneg(vp->v_mat); + return; + case V_STR: + vres->v_str = stringneg(vp->v_str); + if (vres->v_str == NULL) + *vres = error_value(E_STRNEG); + return; + case V_OCTET: + vres->v_type = V_NUM; + vres->v_subtype = V_NOSUBTYPE; + vres->v_num = itoq(- (long) *vp->v_octet); + return; - case V_OBJ: - *vres = objcall(OBJ_NEG, vp, NULL_VALUE, NULL_VALUE); - return; - default: - if (vp->v_type <= 0) - return; - *vres = error_value(E_NEG); + case V_OBJ: + *vres = objcall(OBJ_NEG, vp, NULL_VALUE, NULL_VALUE); + return; + default: + if (vp->v_type <= 0) return; + *vres = error_value(E_NEG); + return; } } @@ -382,65 +399,65 @@ addvalue(VALUE *v1, VALUE *v2, VALUE *vres) } vres->v_type = v1->v_type; switch (TWOVAL(v1->v_type, v2->v_type)) { - case TWOVAL(V_NUM, V_NUM): - vres->v_num = qqadd(v1->v_num, v2->v_num); + case TWOVAL(V_NUM, V_NUM): + vres->v_num = qqadd(v1->v_num, v2->v_num); + return; + case TWOVAL(V_COM, V_NUM): + vres->v_com = c_addq(v1->v_com, v2->v_num); + return; + case TWOVAL(V_NUM, V_COM): + vres->v_com = c_addq(v2->v_com, v1->v_num); + vres->v_type = V_COM; + return; + case TWOVAL(V_COM, V_COM): + vres->v_com = c_add(v1->v_com, v2->v_com); + c = vres->v_com; + if (!cisreal(c)) return; - case TWOVAL(V_COM, V_NUM): - vres->v_com = c_addq(v1->v_com, v2->v_num); - return; - case TWOVAL(V_NUM, V_COM): - vres->v_com = c_addq(v2->v_com, v1->v_num); - vres->v_type = V_COM; - return; - case TWOVAL(V_COM, V_COM): - vres->v_com = c_add(v1->v_com, v2->v_com); - c = vres->v_com; - if (!cisreal(c)) + vres->v_num = qlink(c->real); + vres->v_type = V_NUM; + comfree(c); + return; + case TWOVAL(V_MAT, V_MAT): + vres->v_mat = matadd(v1->v_mat, v2->v_mat); + return; + case TWOVAL(V_STR, V_STR): + vres->v_str = stringadd(v1->v_str, v2->v_str); + if (vres->v_str == NULL) + *vres = error_value(E_STRADD); + return; + case TWOVAL(V_VPTR, V_NUM): + q = v2->v_num; + if (qisfrac(q)) { + math_error("Adding non-integer to address"); + /*NOTREACHED*/ + } + i = qtoi(q); + vres->v_addr = v1->v_addr + i; + vres->v_type = V_VPTR; + return; + case TWOVAL(V_OPTR, V_NUM): + q = v2->v_num; + if (qisfrac(q)) { + math_error("Adding non-integer to address"); + /*NOTREACHED*/ + } + i = qtoi(q); + vres->v_octet = v1->v_octet + i; + vres->v_type = V_OPTR; + return; + default: + if ((v1->v_type != V_OBJ) && (v2->v_type != V_OBJ)) { + if (v1->v_type < 0) return; - vres->v_num = qlink(c->real); - vres->v_type = V_NUM; - comfree(c); - return; - case TWOVAL(V_MAT, V_MAT): - vres->v_mat = matadd(v1->v_mat, v2->v_mat); - return; - case TWOVAL(V_STR, V_STR): - vres->v_str = stringadd(v1->v_str, v2->v_str); - if (vres->v_str == NULL) - *vres = error_value(E_STRADD); - return; - case TWOVAL(V_VPTR, V_NUM): - q = v2->v_num; - if (qisfrac(q)) { - math_error("Adding non-integer to address"); - /*NOTREACHED*/ - } - i = qtoi(q); - vres->v_addr = v1->v_addr + i; - vres->v_type = V_VPTR; - return; - case TWOVAL(V_OPTR, V_NUM): - q = v2->v_num; - if (qisfrac(q)) { - math_error("Adding non-integer to address"); - /*NOTREACHED*/ - } - i = qtoi(q); - vres->v_octet = v1->v_octet + i; - vres->v_type = V_OPTR; - return; - default: - if ((v1->v_type != V_OBJ) && (v2->v_type != V_OBJ)) { - if (v1->v_type < 0) - return; - if (v2->v_type > 0) - *vres = error_value(E_ADD); - else - vres->v_type = v2->v_type; - return; - } - *vres = objcall(OBJ_ADD, v1, v2, NULL_VALUE); + if (v2->v_type > 0) + *vres = error_value(E_ADD); + else + vres->v_type = v2->v_type; return; + } + *vres = objcall(OBJ_ADD, v1, v2, NULL_VALUE); + return; } } @@ -459,76 +476,76 @@ subvalue(VALUE *v1, VALUE *v2, VALUE *vres) vres->v_type = v1->v_type; vres->v_subtype = V_NOSUBTYPE; switch (TWOVAL(v1->v_type, v2->v_type)) { - case TWOVAL(V_NUM, V_NUM): - vres->v_num = qsub(v1->v_num, v2->v_num); + case TWOVAL(V_NUM, V_NUM): + vres->v_num = qsub(v1->v_num, v2->v_num); + return; + case TWOVAL(V_COM, V_NUM): + vres->v_com = c_subq(v1->v_com, v2->v_num); + return; + case TWOVAL(V_NUM, V_COM): + c = c_subq(v2->v_com, v1->v_num); + vres->v_type = V_COM; + vres->v_com = c_neg(c); + comfree(c); + return; + case TWOVAL(V_COM, V_COM): + vres->v_com = c_sub(v1->v_com, v2->v_com); + c = vres->v_com; + if (!cisreal(c)) return; - case TWOVAL(V_COM, V_NUM): - vres->v_com = c_subq(v1->v_com, v2->v_num); - return; - case TWOVAL(V_NUM, V_COM): - c = c_subq(v2->v_com, v1->v_num); - vres->v_type = V_COM; - vres->v_com = c_neg(c); - comfree(c); - return; - case TWOVAL(V_COM, V_COM): - vres->v_com = c_sub(v1->v_com, v2->v_com); - c = vres->v_com; - if (!cisreal(c)) + vres->v_num = qlink(c->real); + vres->v_type = V_NUM; + comfree(c); + return; + case TWOVAL(V_MAT, V_MAT): + vres->v_mat = matsub(v1->v_mat, v2->v_mat); + return; + case TWOVAL(V_STR, V_STR): + vres->v_str = stringsub(v1->v_str, v2->v_str); + if (vres->v_str == NULL) + *vres = error_value(E_STRSUB); + return; + case TWOVAL(V_VPTR, V_NUM): + q = v2->v_num; + if (qisfrac(q)) { + math_error("Subtracting non-integer from address"); + /*NOTREACHED*/ + } + i = qtoi(q); + vres->v_addr = v1->v_addr - i; + vres->v_type = V_VPTR; + return; + case TWOVAL(V_OPTR, V_NUM): + q = v2->v_num; + if (qisfrac(q)) { + math_error("Adding non-integer to address"); + /*NOTREACHED*/ + } + i = qtoi(q); + vres->v_octet = v1->v_octet - i; + vres->v_type = V_OPTR; + return; + case TWOVAL(V_VPTR, V_VPTR): + vres->v_type = V_NUM; + vres->v_num = itoq(v1->v_addr - v2->v_addr); + return; + case TWOVAL(V_OPTR, V_OPTR): + vres->v_type = V_NUM; + vres->v_num = itoq(v1->v_octet - v2->v_octet); + return; + default: + if ((v1->v_type != V_OBJ) && (v2->v_type != V_OBJ)) { + if (v1->v_type <= 0) return; - vres->v_num = qlink(c->real); - vres->v_type = V_NUM; - comfree(c); - return; - case TWOVAL(V_MAT, V_MAT): - vres->v_mat = matsub(v1->v_mat, v2->v_mat); - return; - case TWOVAL(V_STR, V_STR): - vres->v_str = stringsub(v1->v_str, v2->v_str); - if (vres->v_str == NULL) - *vres = error_value(E_STRSUB); - return; - case TWOVAL(V_VPTR, V_NUM): - q = v2->v_num; - if (qisfrac(q)) { - math_error("Subtracting non-integer from address"); - /*NOTREACHED*/ - } - i = qtoi(q); - vres->v_addr = v1->v_addr - i; - vres->v_type = V_VPTR; - return; - case TWOVAL(V_OPTR, V_NUM): - q = v2->v_num; - if (qisfrac(q)) { - math_error("Adding non-integer to address"); - /*NOTREACHED*/ - } - i = qtoi(q); - vres->v_octet = v1->v_octet - i; - vres->v_type = V_OPTR; - return; - case TWOVAL(V_VPTR, V_VPTR): - vres->v_type = V_NUM; - vres->v_num = itoq(v1->v_addr - v2->v_addr); - return; - case TWOVAL(V_OPTR, V_OPTR): - vres->v_type = V_NUM; - vres->v_num = itoq(v1->v_octet - v2->v_octet); - return; - default: - if ((v1->v_type != V_OBJ) && (v2->v_type != V_OBJ)) { - if (v1->v_type <= 0) - return; - if (v2->v_type <= 0) { - vres->v_type = v2->v_type; - return; - } - *vres = error_value(E_SUB); + if (v2->v_type <= 0) { + vres->v_type = v2->v_type; return; } - *vres = objcall(OBJ_SUB, v1, v2, NULL_VALUE); + *vres = error_value(E_SUB); return; + } + *vres = objcall(OBJ_SUB, v1, v2, NULL_VALUE); + return; } } @@ -545,55 +562,55 @@ mulvalue(VALUE *v1, VALUE *v2, VALUE *vres) vres->v_type = v1->v_type; vres->v_subtype = V_NOSUBTYPE; switch (TWOVAL(v1->v_type, v2->v_type)) { - case TWOVAL(V_NUM, V_NUM): - vres->v_num = qmul(v1->v_num, v2->v_num); - return; - case TWOVAL(V_COM, V_NUM): - vres->v_com = c_mulq(v1->v_com, v2->v_num); - break; - case TWOVAL(V_NUM, V_COM): - vres->v_com = c_mulq(v2->v_com, v1->v_num); - vres->v_type = V_COM; - break; - case TWOVAL(V_COM, V_COM): - vres->v_com = c_mul(v1->v_com, v2->v_com); - break; - case TWOVAL(V_MAT, V_MAT): - vres->v_mat = matmul(v1->v_mat, v2->v_mat); - return; - case TWOVAL(V_MAT, V_NUM): - case TWOVAL(V_MAT, V_COM): - vres->v_mat = matmulval(v1->v_mat, v2); - return; - case TWOVAL(V_NUM, V_MAT): - case TWOVAL(V_COM, V_MAT): - vres->v_mat = matmulval(v2->v_mat, v1); - vres->v_type = V_MAT; - return; - case TWOVAL(V_NUM, V_STR): - vres->v_type = V_STR; - vres->v_str = stringmul(v1->v_num, v2->v_str); - if (vres->v_str == NULL) - *vres = error_value(E_STRMUL); - return; - case TWOVAL(V_STR, V_NUM): - vres->v_str= stringmul(v2->v_num, v1->v_str); - if (vres->v_str == NULL) - *vres = error_value(E_STRMUL); - return; - default: - if ((v1->v_type != V_OBJ) && (v2->v_type != V_OBJ)) { - if (v1->v_type <= 0) - return; - if (v2->v_type <= 0) { - vres->v_type = v2->v_type; - return; - } - *vres = error_value(E_MUL); + case TWOVAL(V_NUM, V_NUM): + vres->v_num = qmul(v1->v_num, v2->v_num); + return; + case TWOVAL(V_COM, V_NUM): + vres->v_com = c_mulq(v1->v_com, v2->v_num); + break; + case TWOVAL(V_NUM, V_COM): + vres->v_com = c_mulq(v2->v_com, v1->v_num); + vres->v_type = V_COM; + break; + case TWOVAL(V_COM, V_COM): + vres->v_com = c_mul(v1->v_com, v2->v_com); + break; + case TWOVAL(V_MAT, V_MAT): + vres->v_mat = matmul(v1->v_mat, v2->v_mat); + return; + case TWOVAL(V_MAT, V_NUM): + case TWOVAL(V_MAT, V_COM): + vres->v_mat = matmulval(v1->v_mat, v2); + return; + case TWOVAL(V_NUM, V_MAT): + case TWOVAL(V_COM, V_MAT): + vres->v_mat = matmulval(v2->v_mat, v1); + vres->v_type = V_MAT; + return; + case TWOVAL(V_NUM, V_STR): + vres->v_type = V_STR; + vres->v_str = stringmul(v1->v_num, v2->v_str); + if (vres->v_str == NULL) + *vres = error_value(E_STRMUL); + return; + case TWOVAL(V_STR, V_NUM): + vres->v_str= stringmul(v2->v_num, v1->v_str); + if (vres->v_str == NULL) + *vres = error_value(E_STRMUL); + return; + default: + if ((v1->v_type != V_OBJ) && (v2->v_type != V_OBJ)) { + if (v1->v_type <= 0) + return; + if (v2->v_type <= 0) { + vres->v_type = v2->v_type; return; } - *vres = objcall(OBJ_MUL, v1, v2, NULL_VALUE); + *vres = error_value(E_MUL); return; + } + *vres = objcall(OBJ_MUL, v1, v2, NULL_VALUE); + return; } c = vres->v_com; if (cisreal(c)) { @@ -616,31 +633,31 @@ squarevalue(VALUE *vp, VALUE *vres) vres->v_type = vp->v_type; vres->v_subtype = V_NOSUBTYPE; switch (vp->v_type) { - case V_NUM: - vres->v_num = qsquare(vp->v_num); + case V_NUM: + vres->v_num = qsquare(vp->v_num); + return; + case V_COM: + vres->v_com = c_square(vp->v_com); + c = vres->v_com; + if (!cisreal(c)) return; - case V_COM: - vres->v_com = c_square(vp->v_com); - c = vres->v_com; - if (!cisreal(c)) - return; - vres->v_num = qlink(c->real); - vres->v_type = V_NUM; - comfree(c); - return; - case V_MAT: - vres->v_mat = matsquare(vp->v_mat); - return; - case V_OBJ: - *vres = objcall(OBJ_SQUARE, vp, NULL_VALUE, NULL_VALUE); - return; - default: - if (vp->v_type <= 0) { - vres->v_type = vp->v_type; - return; - } - *vres = error_value(E_SQUARE); + vres->v_num = qlink(c->real); + vres->v_type = V_NUM; + comfree(c); + return; + case V_MAT: + vres->v_mat = matsquare(vp->v_mat); + return; + case V_OBJ: + *vres = objcall(OBJ_SQUARE, vp, NULL_VALUE, NULL_VALUE); + return; + default: + if (vp->v_type <= 0) { + vres->v_type = vp->v_type; return; + } + *vres = error_value(E_SQUARE); + return; } } @@ -657,42 +674,42 @@ invertvalue(VALUE *vp, VALUE *vres) vres->v_type = vp->v_type; vres->v_subtype = V_NOSUBTYPE; switch (vp->v_type) { - case V_NUM: - if (qiszero(vp->v_num)) - *vres = error_value(E_1OVER0); - else - vres->v_num = qinv(vp->v_num); + case V_NUM: + if (qiszero(vp->v_num)) + *vres = error_value(E_1OVER0); + else + vres->v_num = qinv(vp->v_num); + return; + case V_COM: + vres->v_com = c_inv(vp->v_com); + return; + case V_MAT: + vres->v_mat = matinv(vp->v_mat); + return; + case V_OCTET: + if (*vp->v_octet == 0) { + *vres = error_value(E_1OVER0); return; - case V_COM: - vres->v_com = c_inv(vp->v_com); - return; - case V_MAT: - vres->v_mat = matinv(vp->v_mat); - return; - case V_OCTET: - if (*vp->v_octet == 0) { - *vres = error_value(E_1OVER0); - return; - } - q1 = itoq((long) *vp->v_octet); - q2 = qinv(q1); - qfree(q1); - vres->v_num = q2; + } + q1 = itoq((long) *vp->v_octet); + q2 = qinv(q1); + qfree(q1); + vres->v_num = q2; + vres->v_type = V_NUM; + return; + case V_OBJ: + *vres = objcall(OBJ_INV, vp, NULL_VALUE, NULL_VALUE); + return; + default: + if (vp->v_type == -E_1OVER0) { vres->v_type = V_NUM; + vres->v_num = qlink(&_qzero_); return; - case V_OBJ: - *vres = objcall(OBJ_INV, vp, NULL_VALUE, NULL_VALUE); - return; - default: - if (vp->v_type == -E_1OVER0) { - vres->v_type = V_NUM; - vres->v_num = qlink(&_qzero_); - return; - } - if (vp->v_type <= 0) - return; - *vres = error_value(E_INV); + } + if (vp->v_type <= 0) return; + *vres = error_value(E_INV); + return; } } @@ -716,40 +733,40 @@ andvalue(VALUE *v1, VALUE *v2, VALUE *vres) } vres->v_type = v1->v_type; switch (TWOVAL(v1->v_type, v2->v_type)) { - case TWOVAL(V_NUM, V_NUM): - vres->v_num = qand(v1->v_num, v2->v_num); - return; - case TWOVAL(V_STR, V_STR): - vres->v_str = stringand(v1->v_str, v2->v_str); - if (vres->v_str == NULL) - *vres = error_value(E_STRAND); - return; - case TWOVAL(V_OCTET, V_OCTET): - vres->v_type = V_STR; - vres->v_str = charstring(*v1->v_octet & *v2->v_octet); - return; - case TWOVAL(V_STR, V_OCTET): - vres->v_str = charstring(*v1->v_str->s_str & - *v2->v_octet); - return; - case TWOVAL(V_OCTET, V_STR): - vres->v_type = V_STR; - vres->v_str = charstring(*v1->v_octet & - *v2->v_str->s_str); - return; - default: - if ((v1->v_type != V_OBJ) && (v2->v_type != V_OBJ)) { - if (v1->v_type < 0) - return; - if (v2->v_type < 0) { - vres->v_type = v2->v_type; - return; - } - *vres = error_value(E_AND); + case TWOVAL(V_NUM, V_NUM): + vres->v_num = qand(v1->v_num, v2->v_num); + return; + case TWOVAL(V_STR, V_STR): + vres->v_str = stringand(v1->v_str, v2->v_str); + if (vres->v_str == NULL) + *vres = error_value(E_STRAND); + return; + case TWOVAL(V_OCTET, V_OCTET): + vres->v_type = V_STR; + vres->v_str = charstring(*v1->v_octet & *v2->v_octet); + return; + case TWOVAL(V_STR, V_OCTET): + vres->v_str = charstring(*v1->v_str->s_str & + *v2->v_octet); + return; + case TWOVAL(V_OCTET, V_STR): + vres->v_type = V_STR; + vres->v_str = charstring(*v1->v_octet & + *v2->v_str->s_str); + return; + default: + if ((v1->v_type != V_OBJ) && (v2->v_type != V_OBJ)) { + if (v1->v_type < 0) + return; + if (v2->v_type < 0) { + vres->v_type = v2->v_type; return; } - *vres = objcall(OBJ_AND, v1, v2, NULL_VALUE); + *vres = error_value(E_AND); return; + } + *vres = objcall(OBJ_AND, v1, v2, NULL_VALUE); + return; } } @@ -772,40 +789,40 @@ orvalue(VALUE *v1, VALUE *v2, VALUE *vres) vres->v_type = v1->v_type; vres->v_subtype = V_NOSUBTYPE; switch (TWOVAL(v1->v_type, v2->v_type)) { - case TWOVAL(V_NUM, V_NUM): - vres->v_num = qor(v1->v_num, v2->v_num); - return; - case TWOVAL(V_STR, V_STR): - vres->v_str = stringor(v1->v_str, v2->v_str); - if (vres->v_str == NULL) - *vres = error_value(E_STROR); - return; - case TWOVAL(V_OCTET, V_OCTET): - vres->v_type = V_STR; - vres->v_str = charstring(*v1->v_octet | *v2->v_octet); - return; - case TWOVAL(V_STR, V_OCTET): - vres->v_str = charstring(*v1->v_str->s_str | - *v2->v_octet); - return; - case TWOVAL(V_OCTET, V_STR): - vres->v_type = V_STR; - vres->v_str = charstring(*v1->v_octet | - *v2->v_str->s_str); - return; - default: - if ((v1->v_type != V_OBJ) && (v2->v_type != V_OBJ)) { - if (v1->v_type < 0) - return; - if (v2->v_type < 0) { - vres->v_type = v2->v_type; - return; - } - *vres = error_value(E_OR); + case TWOVAL(V_NUM, V_NUM): + vres->v_num = qor(v1->v_num, v2->v_num); + return; + case TWOVAL(V_STR, V_STR): + vres->v_str = stringor(v1->v_str, v2->v_str); + if (vres->v_str == NULL) + *vres = error_value(E_STROR); + return; + case TWOVAL(V_OCTET, V_OCTET): + vres->v_type = V_STR; + vres->v_str = charstring(*v1->v_octet | *v2->v_octet); + return; + case TWOVAL(V_STR, V_OCTET): + vres->v_str = charstring(*v1->v_str->s_str | + *v2->v_octet); + return; + case TWOVAL(V_OCTET, V_STR): + vres->v_type = V_STR; + vres->v_str = charstring(*v1->v_octet | + *v2->v_str->s_str); + return; + default: + if ((v1->v_type != V_OBJ) && (v2->v_type != V_OBJ)) { + if (v1->v_type < 0) + return; + if (v2->v_type < 0) { + vres->v_type = v2->v_type; return; } - *vres = objcall(OBJ_OR, v1, v2, NULL_VALUE); + *vres = error_value(E_OR); return; + } + *vres = objcall(OBJ_OR, v1, v2, NULL_VALUE); + return; } } @@ -821,39 +838,39 @@ xorvalue(VALUE *v1, VALUE *v2, VALUE *vres) vres->v_type = v1->v_type; vres->v_subtype = V_NOSUBTYPE; switch (TWOVAL(v1->v_type, v2->v_type)) { - case (TWOVAL(V_NUM, V_NUM)): - vres->v_num = qxor(v1->v_num, v2->v_num); - return; - case (TWOVAL(V_STR, V_STR)): - vres->v_str = stringxor(v1->v_str, v2->v_str); - if (vres->v_str == NULL) - *vres = error_value(E_STRDIFF); - return; - case (TWOVAL(V_STR, V_OCTET)): - if (v1->v_str->s_len) { - vres->v_str = stringcopy(v1->v_str); - *vres->v_str->s_str ^= *v2->v_octet; - } else { - vres->v_str = charstring(*v2->v_octet); - } - return; - case (TWOVAL(V_OCTET, V_STR)): - if (v2->v_str->s_len) { - vres->v_str = stringcopy(v2->v_str); - *vres->v_str->s_str ^= *v1->v_octet; - } else { - vres->v_str = charstring(*v1->v_octet); - } - return; - case (TWOVAL(V_OCTET, V_OCTET)): - vres->v_type = V_STR; - vres->v_str = charstring(*v1->v_octet ^ *v2->v_octet); - return; - default: - if (v1->v_type == V_OBJ || v2->v_type == V_OBJ) - *vres = objcall(OBJ_XOR, v1, v2, NULL_VALUE); - else - *vres = error_value(E_XOR); + case (TWOVAL(V_NUM, V_NUM)): + vres->v_num = qxor(v1->v_num, v2->v_num); + return; + case (TWOVAL(V_STR, V_STR)): + vres->v_str = stringxor(v1->v_str, v2->v_str); + if (vres->v_str == NULL) + *vres = error_value(E_STRDIFF); + return; + case (TWOVAL(V_STR, V_OCTET)): + if (v1->v_str->s_len) { + vres->v_str = stringcopy(v1->v_str); + *vres->v_str->s_str ^= *v2->v_octet; + } else { + vres->v_str = charstring(*v2->v_octet); + } + return; + case (TWOVAL(V_OCTET, V_STR)): + if (v2->v_str->s_len) { + vres->v_str = stringcopy(v2->v_str); + *vres->v_str->s_str ^= *v1->v_octet; + } else { + vres->v_str = charstring(*v1->v_octet); + } + return; + case (TWOVAL(V_OCTET, V_OCTET)): + vres->v_type = V_STR; + vres->v_str = charstring(*v1->v_octet ^ *v2->v_octet); + return; + default: + if (v1->v_type == V_OBJ || v2->v_type == V_OBJ) + *vres = objcall(OBJ_XOR, v1, v2, NULL_VALUE); + else + *vres = error_value(E_XOR); } } @@ -869,16 +886,16 @@ hashopvalue(VALUE *v1, VALUE *v2, VALUE *vres) vres->v_type = v1->v_type; vres->v_subtype = V_NOSUBTYPE; switch (TWOVAL(v1->v_type, v2->v_type)) { - case TWOVAL(V_NUM, V_NUM): - q = qsub(v1->v_num, v2->v_num); - vres->v_num = qqabs(q); - qfree(q); - return; - default: - if (v1->v_type == V_OBJ || v2->v_type == V_OBJ) - *vres = objcall(OBJ_HASHOP, v1, v2, NULL_VALUE); - else - *vres = error_value(E_HASHOP); + case TWOVAL(V_NUM, V_NUM): + q = qsub(v1->v_num, v2->v_num); + vres->v_num = qqabs(q); + qfree(q); + return; + default: + if (v1->v_type == V_OBJ || v2->v_type == V_OBJ) + *vres = objcall(OBJ_HASHOP, v1, v2, NULL_VALUE); + else + *vres = error_value(E_HASHOP); } } @@ -890,23 +907,23 @@ compvalue(VALUE *vp, VALUE *vres) vres->v_type = vp->v_type; vres->v_subtype = V_NOSUBTYPE; switch (vp->v_type) { - case V_NUM: - vres->v_num = qcomp(vp->v_num); - return; - case V_STR: - vres->v_str = stringcomp(vp->v_str); - if (vres->v_str == NULL) - *vres = error_value(E_STRCOMP); - return; - case V_OCTET: - vres->v_type = V_STR; - vres->v_str = charstring(~*vp->v_octet); - return; - case V_OBJ: - *vres = objcall(OBJ_COMP, vp, NULL_VALUE, NULL_VALUE); - return; - default: - *vres = error_value(E_COMP); + case V_NUM: + vres->v_num = qcomp(vp->v_num); + return; + case V_STR: + vres->v_str = stringcomp(vp->v_str); + if (vres->v_str == NULL) + *vres = error_value(E_STRCOMP); + return; + case V_OCTET: + vres->v_type = V_STR; + vres->v_str = charstring(~*vp->v_octet); + return; + case V_OBJ: + *vres = objcall(OBJ_COMP, vp, NULL_VALUE, NULL_VALUE); + return; + default: + *vres = error_value(E_COMP); } } @@ -933,32 +950,32 @@ setminusvalue(VALUE *v1, VALUE *v2, VALUE *vres) vres->v_type = v1->v_type; vres->v_subtype = V_NOSUBTYPE; switch (TWOVAL(v1->v_type, v2->v_type)) { - case TWOVAL(V_NUM, V_NUM): - vres->v_num = qandnot(v1->v_num, v2->v_num); - return; - case TWOVAL(V_STR, V_STR): - vres->v_str = stringdiff(v1->v_str, v2->v_str); - return; - case TWOVAL(V_STR, V_OCTET): - vres->v_str = charstring(*v1->v_str->s_str & - ~*v2->v_octet); - return; - case TWOVAL(V_OCTET, V_STR): - vres->v_type = V_STR; - vres->v_str = charstring(*v1->v_octet & - ~*v2->v_str->s_str); - return; - case TWOVAL(V_OCTET, V_OCTET): - vres->v_type = V_STR; - vres->v_str = charstring(*v1->v_octet & - ~*v2->v_octet); - return; - default: - if (v1->v_type == V_OBJ || v2->v_type == V_OBJ) - *vres = objcall(OBJ_SETMINUS, v1, v2, - NULL_VALUE); - else - *vres = error_value(E_SETMINUS); + case TWOVAL(V_NUM, V_NUM): + vres->v_num = qandnot(v1->v_num, v2->v_num); + return; + case TWOVAL(V_STR, V_STR): + vres->v_str = stringdiff(v1->v_str, v2->v_str); + return; + case TWOVAL(V_STR, V_OCTET): + vres->v_str = charstring(*v1->v_str->s_str & + ~*v2->v_octet); + return; + case TWOVAL(V_OCTET, V_STR): + vres->v_type = V_STR; + vres->v_str = charstring(*v1->v_octet & + ~*v2->v_str->s_str); + return; + case TWOVAL(V_OCTET, V_OCTET): + vres->v_type = V_STR; + vres->v_str = charstring(*v1->v_octet & + ~*v2->v_octet); + return; + default: + if (v1->v_type == V_OBJ || v2->v_type == V_OBJ) + *vres = objcall(OBJ_SETMINUS, v1, v2, + NULL_VALUE); + else + *vres = error_value(E_SETMINUS); } } @@ -977,23 +994,23 @@ contentvalue(VALUE *vp, VALUE *vres) vres->v_subtype = V_NOSUBTYPE; count = 0; switch (vp->v_type) { - case V_STR: - count = stringcontent(vp->v_str); - break; - case V_OCTET: - for (u = *vp->v_octet; u; u >>= 1) - count += (u & 1); - break; - case V_NUM: - count = zpopcnt(vp->v_num->num, 1); - break; - case V_OBJ: - *vres = objcall(OBJ_CONTENT, vp, NULL_VALUE, - NULL_VALUE); - return; - default: - *vres = error_value(E_CONTENT); - return; + case V_STR: + count = stringcontent(vp->v_str); + break; + case V_OCTET: + for (u = *vp->v_octet; u; u >>= 1) + count += (u & 1); + break; + case V_NUM: + count = zpopcnt(vp->v_num->num, 1); + break; + case V_OBJ: + *vres = objcall(OBJ_CONTENT, vp, NULL_VALUE, + NULL_VALUE); + return; + default: + *vres = error_value(E_CONTENT); + return; } vres->v_num = itoq(count); } @@ -1018,26 +1035,26 @@ apprvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres) e = NULL; switch(v2->v_type) { - case V_NUM: e = v2->v_num; - break; - case V_NULL: e = conf->epsilon; - break; - default: - *vres = error_value(E_APPR2); - return; + case V_NUM: e = v2->v_num; + break; + case V_NULL: e = conf->epsilon; + break; + default: + *vres = error_value(E_APPR2); + return; } switch(v3->v_type) { - case V_NUM: if (qisfrac(v3->v_num)) { - *vres = error_value(E_APPR3); - return; - } - R = qtoi(v3->v_num); - break; - case V_NULL: R = conf->appr; - break; - default: - *vres = error_value(E_APPR3); - return; + case V_NUM: if (qisfrac(v3->v_num)) { + *vres = error_value(E_APPR3); + return; + } + R = qtoi(v3->v_num); + break; + case V_NULL: R = conf->appr; + break; + default: + *vres = error_value(E_APPR3); + return; } if (qiszero(e)) { @@ -1045,34 +1062,34 @@ apprvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres) return; } switch (v1->v_type) { - case V_NUM: - vres->v_num = qmappr(v1->v_num, e, R); - return; - case V_MAT: - vres->v_mat = matappr(v1->v_mat, v2, v3); - return; - case V_LIST: - vres->v_list = listappr(v1->v_list, v2, v3); - return; - case V_COM: - q1 = qmappr(v1->v_com->real, e, R); - q2 = qmappr(v1->v_com->imag, e, R); - if (qiszero(q2)) { - vres->v_type = V_NUM; - vres->v_num = q1; - qfree(q2); - return; - } - c = comalloc(); - qfree(c->real); - qfree(c->imag); - c->real = q1; - c->imag = q2; - vres->v_com = c; - return; - default: - *vres = error_value(E_APPR); + case V_NUM: + vres->v_num = qmappr(v1->v_num, e, R); + return; + case V_MAT: + vres->v_mat = matappr(v1->v_mat, v2, v3); + return; + case V_LIST: + vres->v_list = listappr(v1->v_list, v2, v3); + return; + case V_COM: + q1 = qmappr(v1->v_com->real, e, R); + q2 = qmappr(v1->v_com->imag, e, R); + if (qiszero(q2)) { + vres->v_type = V_NUM; + vres->v_num = q1; + qfree(q2); return; + } + c = comalloc(); + qfree(c->real); + qfree(c->imag); + c->real = q1; + c->imag = q2; + vres->v_com = c; + return; + default: + *vres = error_value(E_APPR); + return; } } @@ -1104,60 +1121,60 @@ roundvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres) } places = 0; switch (v2->v_type) { - case V_NUM: - if (qisfrac(v2->v_num)) { - *vres = error_value(E_ROUND2); - return; - } - places = qtoi(v2->v_num); - break; - case V_NULL: - break; - default: + case V_NUM: + if (qisfrac(v2->v_num)) { *vres = error_value(E_ROUND2); return; + } + places = qtoi(v2->v_num); + break; + case V_NULL: + break; + default: + *vres = error_value(E_ROUND2); + return; } rnd = 0; switch (v3->v_type) { - case V_NUM: - if (qisfrac(v3->v_num)) { - *vres = error_value(E_ROUND3); - return; - } - rnd = qtoi(v3->v_num); - break; - case V_NULL: - rnd = conf->round; - break; - default: + case V_NUM: + if (qisfrac(v3->v_num)) { *vres = error_value(E_ROUND3); return; + } + rnd = qtoi(v3->v_num); + break; + case V_NULL: + rnd = conf->round; + break; + default: + *vres = error_value(E_ROUND3); + return; } switch(v1->v_type) { - case V_NUM: - vres->v_num = qround(v1->v_num, places, rnd); + case V_NUM: + vres->v_num = qround(v1->v_num, places, rnd); + return; + case V_COM: + q1 = qround(v1->v_com->real, places, rnd); + q2 = qround(v1->v_com->imag, places, rnd); + if (qiszero(q2)) { + vres->v_type = V_NUM; + vres->v_num = q1; + qfree(q2); return; - case V_COM: - q1 = qround(v1->v_com->real, places, rnd); - q2 = qround(v1->v_com->imag, places, rnd); - if (qiszero(q2)) { - vres->v_type = V_NUM; - vres->v_num = q1; - qfree(q2); - return; - } - c = comalloc(); - qfree(c->real); - qfree(c->imag); - c->real = q1; - c->imag = q2; - vres->v_com = c; - return; - default: - if (v1->v_type <= 0) - return; - *vres = error_value(E_ROUND); + } + c = comalloc(); + qfree(c->real); + qfree(c->imag); + c->real = q1; + c->imag = q2; + vres->v_com = c; + return; + default: + if (v1->v_type <= 0) return; + *vres = error_value(E_ROUND); + return; } } @@ -1190,60 +1207,60 @@ broundvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres) } places = 0; switch (v2->v_type) { - case V_NUM: - if (qisfrac(v2->v_num)) { - *vres = error_value(E_BROUND2); - return; - } - places = qtoi(v2->v_num); - break; - case V_NULL: - break; - default: + case V_NUM: + if (qisfrac(v2->v_num)) { *vres = error_value(E_BROUND2); return; + } + places = qtoi(v2->v_num); + break; + case V_NULL: + break; + default: + *vres = error_value(E_BROUND2); + return; } rnd = 0; switch (v3->v_type) { - case V_NUM: - if (qisfrac(v3->v_num)) { - *vres = error_value(E_BROUND3); - return; - } - rnd = qtoi(v3->v_num); - break; - case V_NULL: - rnd = conf->round; - break; - default: + case V_NUM: + if (qisfrac(v3->v_num)) { *vres = error_value(E_BROUND3); return; + } + rnd = qtoi(v3->v_num); + break; + case V_NULL: + rnd = conf->round; + break; + default: + *vres = error_value(E_BROUND3); + return; } switch(v1->v_type) { - case V_NUM: - vres->v_num = qbround(v1->v_num, places, rnd); + case V_NUM: + vres->v_num = qbround(v1->v_num, places, rnd); + return; + case V_COM: + q1 = qbround(v1->v_com->real, places, rnd); + q2 = qbround(v1->v_com->imag, places, rnd); + if (qiszero(q2)) { + vres->v_type = V_NUM; + vres->v_num = q1; + qfree(q2); return; - case V_COM: - q1 = qbround(v1->v_com->real, places, rnd); - q2 = qbround(v1->v_com->imag, places, rnd); - if (qiszero(q2)) { - vres->v_type = V_NUM; - vres->v_num = q1; - qfree(q2); - return; - } - c = comalloc(); - qfree(c->real); - qfree(c->imag); - c->real = q1; - c->imag = q2; - vres->v_com = c; - return; - default: - if (v1->v_type <= 0) - return; - *vres = error_value(E_BROUND); + } + c = comalloc(); + qfree(c->real); + qfree(c->imag); + c->real = q1; + c->imag = q2; + vres->v_com = c; + return; + default: + if (v1->v_type <= 0) return; + *vres = error_value(E_BROUND); + return; } } @@ -1259,36 +1276,36 @@ intvalue(VALUE *vp, VALUE *vres) vres->v_type = vp->v_type; vres->v_subtype = V_NOSUBTYPE; switch (vp->v_type) { - case V_NUM: - if (qisint(vp->v_num)) - vres->v_num = qlink(vp->v_num); - else - vres->v_num = qint(vp->v_num); + case V_NUM: + if (qisint(vp->v_num)) + vres->v_num = qlink(vp->v_num); + else + vres->v_num = qint(vp->v_num); + return; + case V_COM: + if (cisint(vp->v_com)) { + vres->v_com = clink(vp->v_com); return; - case V_COM: - if (cisint(vp->v_com)) { - vres->v_com = clink(vp->v_com); - return; - } - vres->v_com = c_int(vp->v_com); - c = vres->v_com; - if (cisreal(c)) { - vres->v_num = qlink(c->real); - vres->v_type = V_NUM; - comfree(c); - } - return; - case V_MAT: - vres->v_mat = matint(vp->v_mat); - return; - case V_OBJ: - *vres = objcall(OBJ_INT, vp, NULL_VALUE, NULL_VALUE); - return; - default: - if (vp->v_type <= 0) - return; - *vres = error_value(E_INT); + } + vres->v_com = c_int(vp->v_com); + c = vres->v_com; + if (cisreal(c)) { + vres->v_num = qlink(c->real); + vres->v_type = V_NUM; + comfree(c); + } + return; + case V_MAT: + vres->v_mat = matint(vp->v_mat); + return; + case V_OBJ: + *vres = objcall(OBJ_INT, vp, NULL_VALUE, NULL_VALUE); + return; + default: + if (vp->v_type <= 0) return; + *vres = error_value(E_INT); + return; } } @@ -1305,37 +1322,37 @@ fracvalue(VALUE *vp, VALUE *vres) vres->v_type = vp->v_type; vres->v_subtype = V_NOSUBTYPE; switch (vp->v_type) { - case V_NUM: - if (qisint(vp->v_num)) - vres->v_num = qlink(&_qzero_); - else - vres->v_num = qfrac(vp->v_num); + case V_NUM: + if (qisint(vp->v_num)) + vres->v_num = qlink(&_qzero_); + else + vres->v_num = qfrac(vp->v_num); + return; + case V_COM: + if (cisint(vp->v_com)) { + vres->v_num = clink(&_qzero_); + vres->v_type = V_NUM; return; - case V_COM: - if (cisint(vp->v_com)) { - vres->v_num = clink(&_qzero_); - vres->v_type = V_NUM; - return; - } - vres->v_com = c_frac(vp->v_com); - c = vres->v_com; - if (cisreal(c)) { - vres->v_num = qlink(c->real); - vres->v_type = V_NUM; - comfree(c); - } - return; - case V_MAT: - vres->v_mat = matfrac(vp->v_mat); - return; - case V_OBJ: - *vres = objcall(OBJ_FRAC, vp, NULL_VALUE, NULL_VALUE); - return; - default: - if (vp->v_type < 0) - return; - *vres = error_value(E_FRAC); + } + vres->v_com = c_frac(vp->v_com); + c = vres->v_com; + if (cisreal(c)) { + vres->v_num = qlink(c->real); + vres->v_type = V_NUM; + comfree(c); + } + return; + case V_MAT: + vres->v_mat = matfrac(vp->v_mat); + return; + case V_OBJ: + *vres = objcall(OBJ_FRAC, vp, NULL_VALUE, NULL_VALUE); + return; + default: + if (vp->v_type < 0) return; + *vres = error_value(E_FRAC); + return; } } @@ -1349,28 +1366,28 @@ incvalue(VALUE *vp, VALUE *vres) { vres->v_type = vp->v_type; switch (vp->v_type) { - case V_NUM: - vres->v_num = qinc(vp->v_num); - break; - case V_COM: - vres->v_com = c_addq(vp->v_com, &_qone_); - break; - case V_OBJ: - *vres = objcall(OBJ_INC, vp, NULL_VALUE, NULL_VALUE); - break; - case V_OCTET: - *vres->v_octet = *vp->v_octet + 1; - break; - case V_OPTR: - vres->v_octet = vp->v_octet + 1; - break; - case V_VPTR: - vres->v_addr = vp->v_addr + 1; - break; - default: - if (vp->v_type > 0) - *vres = error_value(E_INCV); - break; + case V_NUM: + vres->v_num = qinc(vp->v_num); + break; + case V_COM: + vres->v_com = c_addq(vp->v_com, &_qone_); + break; + case V_OBJ: + *vres = objcall(OBJ_INC, vp, NULL_VALUE, NULL_VALUE); + break; + case V_OCTET: + *vres->v_octet = *vp->v_octet + 1; + break; + case V_OPTR: + vres->v_octet = vp->v_octet + 1; + break; + case V_VPTR: + vres->v_addr = vp->v_addr + 1; + break; + default: + if (vp->v_type > 0) + *vres = error_value(E_INCV); + break; } vres->v_subtype = vp->v_subtype; } @@ -1385,28 +1402,28 @@ decvalue(VALUE *vp, VALUE *vres) { vres->v_type = vp->v_type; switch (vp->v_type) { - case V_NUM: - vres->v_num = qdec(vp->v_num); - break; - case V_COM: - vres->v_com = c_addq(vp->v_com, &_qnegone_); - break; - case V_OBJ: - *vres = objcall(OBJ_DEC, vp, NULL_VALUE, NULL_VALUE); - break; - case V_OCTET: - *vres->v_octet = *vp->v_octet - 1; - break; - case V_OPTR: - vres->v_octet = vp->v_octet - 1; - break; - case V_VPTR: - vres->v_addr = vp->v_addr - 1; - break; - default: - if (vp->v_type >= 0) - *vres = error_value(E_DECV); - break; + case V_NUM: + vres->v_num = qdec(vp->v_num); + break; + case V_COM: + vres->v_com = c_addq(vp->v_com, &_qnegone_); + break; + case V_OBJ: + *vres = objcall(OBJ_DEC, vp, NULL_VALUE, NULL_VALUE); + break; + case V_OCTET: + *vres->v_octet = *vp->v_octet - 1; + break; + case V_OPTR: + vres->v_octet = vp->v_octet - 1; + break; + case V_VPTR: + vres->v_addr = vp->v_addr - 1; + break; + default: + if (vp->v_type >= 0) + *vres = error_value(E_DECV); + break; } vres->v_subtype = vp->v_subtype; } @@ -1423,29 +1440,29 @@ conjvalue(VALUE *vp, VALUE *vres) vres->v_type = vp->v_type; vres->v_subtype = V_NOSUBTYPE; switch (vp->v_type) { - case V_NUM: - vres->v_num = qlink(vp->v_num); - return; - case V_COM: - vres->v_com = comalloc(); - qfree(vres->v_com->real); - qfree(vres->v_com->imag) - vres->v_com->real = qlink(vp->v_com->real); - vres->v_com->imag = qneg(vp->v_com->imag); - return; - case V_MAT: - vres->v_mat = matconj(vp->v_mat); - return; - case V_OBJ: - *vres = objcall(OBJ_CONJ, vp, NULL_VALUE, NULL_VALUE); - return; - default: - if (vp->v_type <= 0) { - vres->v_type = vp->v_type; - return; - } - *vres = error_value(E_CONJ); + case V_NUM: + vres->v_num = qlink(vp->v_num); + return; + case V_COM: + vres->v_com = comalloc(); + qfree(vres->v_com->real); + qfree(vres->v_com->imag) + vres->v_com->real = qlink(vp->v_com->real); + vres->v_com->imag = qneg(vp->v_com->imag); + return; + case V_MAT: + vres->v_mat = matconj(vp->v_mat); + return; + case V_OBJ: + *vres = objcall(OBJ_CONJ, vp, NULL_VALUE, NULL_VALUE); + return; + default: + if (vp->v_type <= 0) { + vres->v_type = vp->v_type; return; + } + *vres = error_value(E_CONJ); + return; } } @@ -1490,25 +1507,25 @@ sqrtvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres) R = qtoi(v3->v_num); } switch (v1->v_type) { - case V_NUM: - if (!qisneg(v1->v_num)) { - vres->v_num = qsqrt(v1->v_num, q, R); - return; - } - tmp = qneg(v1->v_num); - c = comalloc(); - qfree(c->imag); - c->imag = qsqrt(tmp, q, R); - qfree(tmp); - vres->v_com = c; - vres->v_type = V_COM; - break; - case V_COM: - vres->v_com = c_sqrt(v1->v_com, q, R); - break; - default: - *vres = error_value(E_SQRT); + case V_NUM: + if (!qisneg(v1->v_num)) { + vres->v_num = qsqrt(v1->v_num, q, R); return; + } + tmp = qneg(v1->v_num); + c = comalloc(); + qfree(c->imag); + c->imag = qsqrt(tmp, q, R); + qfree(tmp); + vres->v_com = c; + vres->v_type = V_COM; + break; + case V_COM: + vres->v_com = c_sqrt(v1->v_com, q, R); + break; + default: + *vres = error_value(E_SQRT); + return; } c = vres->v_com; if (cisreal(c)) { @@ -1556,28 +1573,28 @@ rootvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres) } q3 = v3->v_num; switch (v1->v_type) { - case V_NUM: - if (!qisneg(v1->v_num)) { - vres->v_num = qroot(v1->v_num, q2, q3); - if (vres->v_num == NULL) - *vres = error_value(E_ROOT4); - vres->v_type = V_NUM; - return; - } - ctmp.real = v1->v_num; - ctmp.imag = &_qzero_; - ctmp.links = 1; - c = c_root(&ctmp, q2, q3); - break; - case V_COM: - c = c_root(v1->v_com, q2, q3); - break; - case V_OBJ: - *vres = objcall(OBJ_ROOT, v1, v2, v3); - return; - default: - *vres = error_value(E_ROOT); + case V_NUM: + if (!qisneg(v1->v_num)) { + vres->v_num = qroot(v1->v_num, q2, q3); + if (vres->v_num == NULL) + *vres = error_value(E_ROOT4); + vres->v_type = V_NUM; return; + } + ctmp.real = v1->v_num; + ctmp.imag = &_qzero_; + ctmp.links = 1; + c = c_root(&ctmp, q2, q3); + break; + case V_COM: + c = c_root(v1->v_com, q2, q3); + break; + case V_OBJ: + *vres = objcall(OBJ_ROOT, v1, v2, v3); + return; + default: + *vres = error_value(E_ROOT); + return; } if (c == NULL) { *vres = error_value(E_ROOT4); @@ -1612,22 +1629,22 @@ absvalue(VALUE *v1, VALUE *v2, VALUE *vres) return; } switch (v1->v_type) { - case V_NUM: - if (qisneg(v1->v_num)) - q = qneg(v1->v_num); - else - q = qlink(v1->v_num); - break; - case V_COM: - if (v2->v_type != V_NUM || qiszero(v2->v_num)) { - *vres = error_value(E_ABS2); - return; - } - q = qhypot(v1->v_com->real, v1->v_com->imag, v2->v_num); - break; - default: - *vres = error_value(E_ABS); + case V_NUM: + if (qisneg(v1->v_num)) + q = qneg(v1->v_num); + else + q = qlink(v1->v_num); + break; + case V_COM: + if (v2->v_type != V_NUM || qiszero(v2->v_num)) { + *vres = error_value(E_ABS2); return; + } + q = qhypot(v1->v_com->real, v1->v_com->imag, v2->v_num); + break; + default: + *vres = error_value(E_ABS); + return; } vres->v_num = q; vres->v_type = V_NUM; @@ -1651,23 +1668,23 @@ normvalue(VALUE *vp, VALUE *vres) return; } switch (vp->v_type) { - case V_NUM: - vres->v_num = qsquare(vp->v_num); - return; - case V_COM: - q1 = qsquare(vp->v_com->real); - q2 = qsquare(vp->v_com->imag); - vres->v_num = qqadd(q1, q2); - vres->v_type = V_NUM; - qfree(q1); - qfree(q2); - return; - case V_OBJ: - *vres = objcall(OBJ_NORM, vp, NULL_VALUE, NULL_VALUE); - return; - default: - *vres = error_value(E_NORM); - return; + case V_NUM: + vres->v_num = qsquare(vp->v_num); + return; + case V_COM: + q1 = qsquare(vp->v_com->real); + q2 = qsquare(vp->v_com->imag); + vres->v_num = qqadd(q1, q2); + vres->v_type = V_NUM; + qfree(q1); + qfree(q2); + return; + case V_OBJ: + *vres = objcall(OBJ_NORM, vp, NULL_VALUE, NULL_VALUE); + return; + default: + *vres = error_value(E_NORM); + return; } } @@ -1712,59 +1729,59 @@ shiftvalue(VALUE *v1, VALUE *v2, BOOL rightshift, VALUE *vres) n = -n; vres->v_type = v1->v_type; switch (v1->v_type) { - case V_NUM: - if (qisfrac(v1->v_num)) { - *vres = error_value(E_SHIFT); - return; - } - vres->v_num = qshift(v1->v_num, n); - return; - case V_COM: - if (qisfrac(v1->v_com->real) || - qisfrac(v1->v_com->imag)) { - *vres = error_value(E_SHIFT); - return; - } - c = c_shift(v1->v_com, n); - if (!cisreal(c)) { - vres->v_com = c; - return; - } - vres->v_num = qlink(c->real); - vres->v_type = V_NUM; - comfree(c); - return; - case V_MAT: - vres->v_mat = matshift(v1->v_mat, n); - return; - case V_STR: - vres->v_str = stringshift(v1->v_str, n); - if (vres->v_str == NULL) - *vres = error_value(E_STRSHIFT); - return; - case V_OCTET: - vres->v_type = V_STR; - if (n >= 8 || n <= -8) - ch = 0; - else if (n >= 0) - ch = (unsigned int) *v1->v_octet << n; - else - ch = (unsigned int) *v1->v_octet >> -n; - vres->v_str = charstring(ch); - return; - case V_OBJ: - if (!rightshift) { - *vres = objcall(OBJ_SHIFT, v1, v2, NULL_VALUE); - return; - } - tmp.v_num = qneg(v2->v_num); - tmp.v_type = V_NUM; - *vres = objcall(OBJ_SHIFT, v1, &tmp, NULL_VALUE); - qfree(tmp.v_num); - return; - default: + case V_NUM: + if (qisfrac(v1->v_num)) { *vres = error_value(E_SHIFT); return; + } + vres->v_num = qshift(v1->v_num, n); + return; + case V_COM: + if (qisfrac(v1->v_com->real) || + qisfrac(v1->v_com->imag)) { + *vres = error_value(E_SHIFT); + return; + } + c = c_shift(v1->v_com, n); + if (!cisreal(c)) { + vres->v_com = c; + return; + } + vres->v_num = qlink(c->real); + vres->v_type = V_NUM; + comfree(c); + return; + case V_MAT: + vres->v_mat = matshift(v1->v_mat, n); + return; + case V_STR: + vres->v_str = stringshift(v1->v_str, n); + if (vres->v_str == NULL) + *vres = error_value(E_STRSHIFT); + return; + case V_OCTET: + vres->v_type = V_STR; + if (n >= 8 || n <= -8) + ch = 0; + else if (n >= 0) + ch = (unsigned int) *v1->v_octet << n; + else + ch = (unsigned int) *v1->v_octet >> -n; + vres->v_str = charstring(ch); + return; + case V_OBJ: + if (!rightshift) { + *vres = objcall(OBJ_SHIFT, v1, v2, NULL_VALUE); + return; + } + tmp.v_num = qneg(v2->v_num); + tmp.v_type = V_NUM; + *vres = objcall(OBJ_SHIFT, v1, &tmp, NULL_VALUE); + qfree(tmp.v_num); + return; + default: + *vres = error_value(E_SHIFT); + return; } } @@ -1796,21 +1813,21 @@ scalevalue(VALUE *v1, VALUE *v2, VALUE *vres) } vres->v_type = v1->v_type; switch (v1->v_type) { - case V_NUM: - vres->v_num = qscale(v1->v_num, n); - return; - case V_COM: - vres->v_com = c_scale(v1->v_com, n); - return; - case V_MAT: - vres->v_mat = matscale(v1->v_mat, n); - return; - case V_OBJ: - *vres = objcall(OBJ_SCALE, v1, v2, NULL_VALUE); - return; - default: - *vres = error_value(E_SCALE); - return; + case V_NUM: + vres->v_num = qscale(v1->v_num, n); + return; + case V_COM: + vres->v_com = c_scale(v1->v_com, n); + return; + case V_MAT: + vres->v_mat = matscale(v1->v_mat, n); + return; + case V_OBJ: + *vres = objcall(OBJ_SCALE, v1, v2, NULL_VALUE); + return; + default: + *vres = error_value(E_SCALE); + return; } } @@ -1850,30 +1867,30 @@ powivalue(VALUE *v1, VALUE *v2, VALUE *vres) return; } switch (v1->v_type) { - case V_NUM: - if (qiszero(v1->v_num)) { - if (qisneg(q)) { - *vres = error_value(E_1OVER0); - return; - } - } - vres->v_num = qpowi(v1->v_num, q); - return; - case V_COM: - vres->v_com = c_powi(v1->v_com, q); - c = vres->v_com; - if (!cisreal(c)) + case V_NUM: + if (qiszero(v1->v_num)) { + if (qisneg(q)) { + *vres = error_value(E_1OVER0); return; - vres->v_num = qlink(c->real); - vres->v_type = V_NUM; - comfree(c); - return; - case V_MAT: - vres->v_mat = matpowi(v1->v_mat, q); - return; - default: - *vres = error_value(E_POWI); + } + } + vres->v_num = qpowi(v1->v_num, q); + return; + case V_COM: + vres->v_com = c_powi(v1->v_com, q); + c = vres->v_com; + if (!cisreal(c)) return; + vres->v_num = qlink(c->real); + vres->v_type = V_NUM; + comfree(c); + return; + case V_MAT: + vres->v_mat = matpowi(v1->v_mat, q); + return; + default: + *vres = error_value(E_POWI); + return; } } @@ -1908,40 +1925,40 @@ powervalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres) } epsilon = v3->v_num; switch (TWOVAL(v1->v_type, v2->v_type)) { - case TWOVAL(V_NUM, V_NUM): - if (qisneg(v1->v_num)) { - ctmp1.real = v1->v_num; - ctmp1.imag = &_qzero_; - ctmp1.links = 1; - ctmp2.real = v2->v_num; - ctmp2.imag = &_qzero_; - ctmp2.links = 1; - c = c_power(&ctmp1, &ctmp2, epsilon); - break; - } - vres->v_num = qpower(v1->v_num, v2->v_num, epsilon); - vres->v_type = V_NUM; - if (vres->v_num == NULL) - *vres = error_value(E_POWER4); - return; - case TWOVAL(V_NUM, V_COM): + case TWOVAL(V_NUM, V_NUM): + if (qisneg(v1->v_num)) { ctmp1.real = v1->v_num; ctmp1.imag = &_qzero_; ctmp1.links = 1; - c = c_power(&ctmp1, v2->v_com, epsilon); - break; - case TWOVAL(V_COM, V_NUM): ctmp2.real = v2->v_num; ctmp2.imag = &_qzero_; ctmp2.links = 1; - c = c_power(v1->v_com, &ctmp2, epsilon); + c = c_power(&ctmp1, &ctmp2, epsilon); break; - case TWOVAL(V_COM, V_COM): - c = c_power(v1->v_com, v2->v_com, epsilon); - break; - default: - *vres = error_value(E_POWER); - return; + } + vres->v_num = qpower(v1->v_num, v2->v_num, epsilon); + vres->v_type = V_NUM; + if (vres->v_num == NULL) + *vres = error_value(E_POWER4); + return; + case TWOVAL(V_NUM, V_COM): + ctmp1.real = v1->v_num; + ctmp1.imag = &_qzero_; + ctmp1.links = 1; + c = c_power(&ctmp1, v2->v_com, epsilon); + break; + case TWOVAL(V_COM, V_NUM): + ctmp2.real = v2->v_num; + ctmp2.imag = &_qzero_; + ctmp2.links = 1; + c = c_power(v1->v_com, &ctmp2, epsilon); + break; + case TWOVAL(V_COM, V_COM): + c = c_power(v1->v_com, v2->v_com, epsilon); + break; + default: + *vres = error_value(E_POWER); + return; } /* * Here for any complex result. @@ -1990,52 +2007,52 @@ divvalue(VALUE *v1, VALUE *v2, VALUE *vres) } vres->v_type = v1->v_type; switch (TWOVAL(v1->v_type, v2->v_type)) { - case TWOVAL(V_NUM, V_NUM): - vres->v_num = qqdiv(v1->v_num, v2->v_num); + case TWOVAL(V_NUM, V_NUM): + vres->v_num = qqdiv(v1->v_num, v2->v_num); + return; + case TWOVAL(V_COM, V_NUM): + vres->v_com = c_divq(v1->v_com, v2->v_num); + return; + case TWOVAL(V_NUM, V_COM): + if (qiszero(v1->v_num)) { + vres->v_num = qlink(&_qzero_); return; - case TWOVAL(V_COM, V_NUM): - vres->v_com = c_divq(v1->v_com, v2->v_num); - return; - case TWOVAL(V_NUM, V_COM): - if (qiszero(v1->v_num)) { - vres->v_num = qlink(&_qzero_); - return; - } - ctmp.real = v1->v_num; - ctmp.imag = &_qzero_; - ctmp.links = 1; - vres->v_com = c_div(&ctmp, v2->v_com); - vres->v_type = V_COM; - return; - case TWOVAL(V_COM, V_COM): - vres->v_com = c_div(v1->v_com, v2->v_com); - c = vres->v_com; - if (cisreal(c)) { - vres->v_num = qlink(c->real); - vres->v_type = V_NUM; - comfree(c); - } - return; - case TWOVAL(V_MAT, V_NUM): - case TWOVAL(V_MAT, V_COM): - invertvalue(v2, &tmpval); - vres->v_mat = matmulval(v1->v_mat, &tmpval); - freevalue(&tmpval); - return; - case TWOVAL(V_STR, V_NUM): - q = qinv(v2->v_num); - vres->v_str = stringmul(q, v1->v_str); - qfree(q); - if (vres->v_str == NULL) - *vres = error_value(E_DIV); - return; - default: - if ((v1->v_type != V_OBJ) && (v2->v_type != V_OBJ)) { - *vres = error_value(E_DIV); - return; - } - *vres = objcall(OBJ_DIV, v1, v2, NULL_VALUE); + } + ctmp.real = v1->v_num; + ctmp.imag = &_qzero_; + ctmp.links = 1; + vres->v_com = c_div(&ctmp, v2->v_com); + vres->v_type = V_COM; + return; + case TWOVAL(V_COM, V_COM): + vres->v_com = c_div(v1->v_com, v2->v_com); + c = vres->v_com; + if (cisreal(c)) { + vres->v_num = qlink(c->real); + vres->v_type = V_NUM; + comfree(c); + } + return; + case TWOVAL(V_MAT, V_NUM): + case TWOVAL(V_MAT, V_COM): + invertvalue(v2, &tmpval); + vres->v_mat = matmulval(v1->v_mat, &tmpval); + freevalue(&tmpval); + return; + case TWOVAL(V_STR, V_NUM): + q = qinv(v2->v_num); + vres->v_str = stringmul(q, v1->v_str); + qfree(q); + if (vres->v_str == NULL) + *vres = error_value(E_DIV); + return; + default: + if ((v1->v_type != V_OBJ) && (v2->v_type != V_OBJ)) { + *vres = error_value(E_DIV); return; + } + *vres = objcall(OBJ_DIV, v1, v2, NULL_VALUE); + return; } } @@ -2078,43 +2095,43 @@ quovalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres) } rnd = 0; switch (v3->v_type) { - case V_NUM: - if (qisfrac(v3->v_num)) { - *vres = error_value(E_QUO3); - return; - } - rnd = qtoi(v3->v_num); - break; - case V_NULL: - rnd = conf->quo; - break; - default: + case V_NUM: + if (qisfrac(v3->v_num)) { *vres = error_value(E_QUO3); return; + } + rnd = qtoi(v3->v_num); + break; + case V_NULL: + rnd = conf->quo; + break; + default: + *vres = error_value(E_QUO3); + return; } switch (v1->v_type) { - case V_NUM: - vres->v_num = qquo(v1->v_num, v2->v_num, rnd); - return; - case V_COM: - q1 = qquo(v1->v_com->real, v2->v_num, rnd); - q2 = qquo(v1->v_com->imag, v2->v_num, rnd); - if (qiszero(q2)) { - qfree(q2); - vres->v_type = V_NUM; - vres->v_num = q1; - return; - } - c = comalloc(); - qfree(c->real); - qfree(c->imag); - c->real = q1; - c->imag = q2; - vres->v_com = c; - return; - default: - *vres = error_value(E_QUO); + case V_NUM: + vres->v_num = qquo(v1->v_num, v2->v_num, rnd); + return; + case V_COM: + q1 = qquo(v1->v_com->real, v2->v_num, rnd); + q2 = qquo(v1->v_com->imag, v2->v_num, rnd); + if (qiszero(q2)) { + qfree(q2); + vres->v_type = V_NUM; + vres->v_num = q1; return; + } + c = comalloc(); + qfree(c->real); + qfree(c->imag); + c->real = q1; + c->imag = q2; + vres->v_com = c; + return; + default: + *vres = error_value(E_QUO); + return; } } @@ -2157,43 +2174,43 @@ modvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres) } rnd = 0; switch (v3->v_type) { - case V_NUM: - if (qisfrac(v3->v_num)) { - *vres = error_value(E_MOD3); - return; - } - rnd = qtoi(v3->v_num); - break; - case V_NULL: - rnd = conf->mod; - break; - default: + case V_NUM: + if (qisfrac(v3->v_num)) { *vres = error_value(E_MOD3); return; + } + rnd = qtoi(v3->v_num); + break; + case V_NULL: + rnd = conf->mod; + break; + default: + *vres = error_value(E_MOD3); + return; } switch (v1->v_type) { - case V_NUM: - vres->v_num = qmod(v1->v_num, v2->v_num, rnd); - return; - case V_COM: - q1 = qmod(v1->v_com->real, v2->v_num, rnd); - q2 = qmod(v1->v_com->imag, v2->v_num, rnd); - if (qiszero(q2)) { - qfree(q2); - vres->v_type = V_NUM; - vres->v_num = q1; - return; - } - c = comalloc(); - qfree(c->real); - qfree(c->imag); - c->real = q1; - c->imag = q2; - vres->v_com = c; - return; - default: - *vres = error_value(E_MOD); + case V_NUM: + vres->v_num = qmod(v1->v_num, v2->v_num, rnd); + return; + case V_COM: + q1 = qmod(v1->v_com->real, v2->v_num, rnd); + q2 = qmod(v1->v_com->imag, v2->v_num, rnd); + if (qiszero(q2)) { + qfree(q2); + vres->v_type = V_NUM; + vres->v_num = q1; return; + } + c = comalloc(); + qfree(c->real); + qfree(c->imag); + c->real = q1; + c->imag = q2; + vres->v_com = c; + return; + default: + *vres = error_value(E_MOD); + return; } } @@ -2212,49 +2229,49 @@ testvalue(VALUE *vp) int i; switch (vp->v_type) { - case V_NUM: - return !qiszero(vp->v_num); - case V_COM: - return !ciszero(vp->v_com); - case V_STR: - return stringtest(vp->v_str); - case V_MAT: - return mattest(vp->v_mat); - case V_LIST: - for (ep = vp->v_list->l_first; ep; ep = ep->e_next) { - if (testvalue(&ep->e_value)) - return TRUE; + case V_NUM: + return !qiszero(vp->v_num); + case V_COM: + return !ciszero(vp->v_com); + case V_STR: + return stringtest(vp->v_str); + case V_MAT: + return mattest(vp->v_mat); + case V_LIST: + for (ep = vp->v_list->l_first; ep; ep = ep->e_next) { + if (testvalue(&ep->e_value)) + return TRUE; + } + return FALSE; + case V_ASSOC: + return (vp->v_assoc->a_count != 0); + case V_FILE: + return validid(vp->v_file); + case V_NULL: + break; /* hack to get gcc on SunOS to be quiet */ + case V_OBJ: + val = objcall(OBJ_TEST, vp, NULL_VALUE, NULL_VALUE); + return (val.v_int != 0); + case V_BLOCK: + for (i=0; i < vp->v_block->datalen; ++i) { + if (vp->v_block->data[i]) { + return TRUE; } + } + return FALSE; + case V_OCTET: + return (*vp->v_octet != 0); + case V_NBLOCK: + if (vp->v_nblock->blk->data == NULL) return FALSE; - case V_ASSOC: - return (vp->v_assoc->a_count != 0); - case V_FILE: - return validid(vp->v_file); - case V_NULL: - break; /* hack to get gcc on SunOS to be quiet */ - case V_OBJ: - val = objcall(OBJ_TEST, vp, NULL_VALUE, NULL_VALUE); - return (val.v_int != 0); - case V_BLOCK: - for (i=0; i < vp->v_block->datalen; ++i) { - if (vp->v_block->data[i]) { - return TRUE; - } + for (i=0; i < vp->v_nblock->blk->datalen; ++i) { + if (vp->v_nblock->blk->data[i]) { + return TRUE; } - return FALSE; - case V_OCTET: - return (*vp->v_octet != 0); - case V_NBLOCK: - if (vp->v_nblock->blk->data == NULL) - return FALSE; - for (i=0; i < vp->v_nblock->blk->datalen; ++i) { - if (vp->v_nblock->blk->data[i]) { - return TRUE; - } - } - return FALSE; - default: - return TRUE; + } + return FALSE; + default: + return TRUE; } /* hack to get gcc on SunOS to be quiet */ return FALSE; @@ -2295,58 +2312,58 @@ comparevalue(VALUE *v1, VALUE *v2) if (v1->v_type <= 0) return FALSE; switch (v1->v_type) { - case V_NUM: - r = qcmp(v1->v_num, v2->v_num); - break; - case V_COM: - r = c_cmp(v1->v_com, v2->v_com); - break; - case V_STR: - r = stringcmp(v1->v_str, v2->v_str); - break; - case V_MAT: - r = matcmp(v1->v_mat, v2->v_mat); - break; - case V_LIST: - r = listcmp(v1->v_list, v2->v_list); - break; - case V_ASSOC: - r = assoccmp(v1->v_assoc, v2->v_assoc); - break; - case V_FILE: - r = (v1->v_file != v2->v_file); - break; - case V_RAND: - r = randcmp(v1->v_rand, v2->v_rand); - break; - case V_RANDOM: - r = randomcmp(v1->v_random, v2->v_random); - break; - case V_CONFIG: - r = config_cmp(v1->v_config, v2->v_config); - break; - case V_HASH: - r = hash_cmp(v1->v_hash, v2->v_hash); - break; - case V_BLOCK: - r = blk_cmp(v1->v_block, v2->v_block); - break; - case V_OCTET: - r = (v1->v_octet != v2->v_octet); - break; - case V_NBLOCK: - return (v1->v_nblock != v2->v_nblock); - case V_VPTR: - return (v1->v_addr != v2->v_addr); - case V_OPTR: - return (v1->v_octet != v2->v_octet); - case V_SPTR: - return (v1->v_str != v2->v_str); - case V_NPTR: - return (v1->v_num != v2->v_num); - default: - math_error("Illegal values for comparevalue"); - /*NOTREACHED*/ + case V_NUM: + r = qcmp(v1->v_num, v2->v_num); + break; + case V_COM: + r = c_cmp(v1->v_com, v2->v_com); + break; + case V_STR: + r = stringcmp(v1->v_str, v2->v_str); + break; + case V_MAT: + r = matcmp(v1->v_mat, v2->v_mat); + break; + case V_LIST: + r = listcmp(v1->v_list, v2->v_list); + break; + case V_ASSOC: + r = assoccmp(v1->v_assoc, v2->v_assoc); + break; + case V_FILE: + r = (v1->v_file != v2->v_file); + break; + case V_RAND: + r = randcmp(v1->v_rand, v2->v_rand); + break; + case V_RANDOM: + r = randomcmp(v1->v_random, v2->v_random); + break; + case V_CONFIG: + r = config_cmp(v1->v_config, v2->v_config); + break; + case V_HASH: + r = hash_cmp(v1->v_hash, v2->v_hash); + break; + case V_BLOCK: + r = blk_cmp(v1->v_block, v2->v_block); + break; + case V_OCTET: + r = (v1->v_octet != v2->v_octet); + break; + case V_NBLOCK: + return (v1->v_nblock != v2->v_nblock); + case V_VPTR: + return (v1->v_addr != v2->v_addr); + case V_OPTR: + return (v1->v_octet != v2->v_octet); + case V_SPTR: + return (v1->v_str != v2->v_str); + case V_NPTR: + return (v1->v_num != v2->v_num); + default: + math_error("Illegal values for comparevalue"); + /*NOTREACHED*/ } return (r != 0); } @@ -2450,105 +2467,105 @@ relvalue(VALUE *v1, VALUE *v2, VALUE *vres) return; } switch(v1->v_type) { + case V_NUM: + switch(v2->v_type) { case V_NUM: - switch(v2->v_type) { - case V_NUM: - r = qrel(v1->v_num, v2->v_num); - break; - case V_OCTET: - q = itoq((long) *v2->v_octet); - r = qrel(v1->v_num, q); - qfree(q); - break; - case V_COM: - r = qrel(v1->v_num, v2->v_com->real); - i = qrel(&_qzero_, v2->v_com->imag); - break; - default: - return; - } - break; - case V_COM: - switch(v2->v_type) { - case V_NUM: - r = qrel(v1->v_com->real, v2->v_num); - i = qrel(v1->v_com->imag, &_qzero_); - break; - case V_COM: - r = qrel(v1->v_com->real, v2->v_com->real); - i = qrel(v1->v_com->imag, v2->v_com->imag); - break; - case V_OCTET: - q = itoq((long) *v2->v_octet); - r = qrel(v1->v_com->real, q); - qfree(q); - i = qrel(v1->v_com->imag, &_qzero_); - break; - default: - return; - } - break; - case V_STR: - switch(v2->v_type) { - case V_STR: - r = stringrel(v1->v_str, v2->v_str); - break; - case V_OCTET: - r = (unsigned char) *v1->v_str->s_str - - *v2->v_octet; - if (r == 0) { - if (v1->v_str->s_len == 0) - r = -1; - else - r = (v1->v_str->s_len > 1); - } - break; - default: - return; - } + r = qrel(v1->v_num, v2->v_num); break; case V_OCTET: - switch(v2->v_type) { - case V_NUM: - q = itoq((long) *v1->v_octet); - r = qrel(q, v2->v_num); - qfree(q); - break; - case V_COM: - q = itoq((long) *v1->v_octet); - r = qrel(q, v2->v_com->real); - qfree(q); - i = qrel(&_qzero_, v2->v_com->imag); - break; - case V_OCTET: - r = *v1->v_octet - *v2->v_octet; - break; - case V_STR: - r = *v1->v_octet - - (unsigned char) *v2->v_str->s_str; - if (r == 0) { - if (v2->v_str->s_len == 0) - r = 1; - else - r = -(v2->v_str->s_len > 1); - } - break; - default: - return; - } + q = itoq((long) *v2->v_octet); + r = qrel(v1->v_num, q); + qfree(q); break; - case V_VPTR: - if (v2->v_type != V_VPTR) - return; - r = (v1->v_addr - v2->v_addr); - break; - case V_OPTR: - if (v2->v_type != V_OPTR) - return; - r = (v1->v_octet - v2->v_octet); + case V_COM: + r = qrel(v1->v_num, v2->v_com->real); + i = qrel(&_qzero_, v2->v_com->imag); break; default: return; + } + break; + case V_COM: + switch(v2->v_type) { + case V_NUM: + r = qrel(v1->v_com->real, v2->v_num); + i = qrel(v1->v_com->imag, &_qzero_); + break; + case V_COM: + r = qrel(v1->v_com->real, v2->v_com->real); + i = qrel(v1->v_com->imag, v2->v_com->imag); + break; + case V_OCTET: + q = itoq((long) *v2->v_octet); + r = qrel(v1->v_com->real, q); + qfree(q); + i = qrel(v1->v_com->imag, &_qzero_); + break; + default: + return; + } + break; + case V_STR: + switch(v2->v_type) { + case V_STR: + r = stringrel(v1->v_str, v2->v_str); + break; + case V_OCTET: + r = (unsigned char) *v1->v_str->s_str + - *v2->v_octet; + if (r == 0) { + if (v1->v_str->s_len == 0) + r = -1; + else + r = (v1->v_str->s_len > 1); + } + break; + default: + return; + } + break; + case V_OCTET: + switch(v2->v_type) { + case V_NUM: + q = itoq((long) *v1->v_octet); + r = qrel(q, v2->v_num); + qfree(q); + break; + case V_COM: + q = itoq((long) *v1->v_octet); + r = qrel(q, v2->v_com->real); + qfree(q); + i = qrel(&_qzero_, v2->v_com->imag); + break; + case V_OCTET: + r = *v1->v_octet - *v2->v_octet; + break; + case V_STR: + r = *v1->v_octet - + (unsigned char) *v2->v_str->s_str; + if (r == 0) { + if (v2->v_str->s_len == 0) + r = 1; + else + r = -(v2->v_str->s_len > 1); + } + break; + default: + return; + } + break; + case V_VPTR: + if (v2->v_type != V_VPTR) + return; + r = (v1->v_addr - v2->v_addr); + break; + case V_OPTR: + if (v2->v_type != V_OPTR) + return; + r = (v1->v_octet - v2->v_octet); + break; + default: + return; } vres->v_type = V_NUM; *vres = signval(r); @@ -2577,32 +2594,32 @@ sgnvalue(VALUE *vp, VALUE *vres) vres->v_type = vp->v_type; switch (vp->v_type) { - case V_NUM: - vres->v_num = qsign(vp->v_num); - vres->v_subtype = vp->v_subtype; - return; - case V_COM: - c = comalloc(); - qfree(c->real); - qfree(c->imag); - c->real = qsign(vp->v_com->real); - c->imag = qsign(vp->v_com->imag); - vres->v_com = c; - vres->v_type = V_COM; - vres->v_subtype = V_NOSUBTYPE; - return; - case V_OCTET: - vres->v_type = V_NUM; - vres->v_subtype = V_NOSUBTYPE; - vres->v_num = itoq((long) (*vp->v_octet != 0)); - return; - case V_OBJ: - *vres = objcall(OBJ_SGN, vp, NULL_VALUE, NULL_VALUE); - return; - default: - if (vp->v_type > 0) - *vres = error_value(E_SGN); - return; + case V_NUM: + vres->v_num = qsign(vp->v_num); + vres->v_subtype = vp->v_subtype; + return; + case V_COM: + c = comalloc(); + qfree(c->real); + qfree(c->imag); + c->real = qsign(vp->v_com->real); + c->imag = qsign(vp->v_com->imag); + vres->v_com = c; + vres->v_type = V_COM; + vres->v_subtype = V_NOSUBTYPE; + return; + case V_OCTET: + vres->v_type = V_NUM; + vres->v_subtype = V_NOSUBTYPE; + vres->v_num = itoq((long) (*vp->v_octet != 0)); + return; + case V_OBJ: + *vres = objcall(OBJ_SGN, vp, NULL_VALUE, NULL_VALUE); + return; + default: + if (vp->v_type > 0) + *vres = error_value(E_SGN); + return; } } @@ -2648,90 +2665,90 @@ printvalue(VALUE *vp, int flags) return; } switch (type) { - case V_NUM: - qprintnum(vp->v_num, MODE_DEFAULT); - if (conf->traceflags & TRACE_LINKS) - printf("#%ld", vp->v_num->links); + case V_NUM: + qprintnum(vp->v_num, MODE_DEFAULT); + if (conf->traceflags & TRACE_LINKS) + printf("#%ld", vp->v_num->links); + break; + case V_COM: + comprint(vp->v_com); + if (conf->traceflags & TRACE_LINKS) + printf("##%ld", vp->v_com->links); + break; + case V_STR: + if (flags & PRINT_UNAMBIG) + math_chr('\"'); + math_str(vp->v_str->s_str); + if (flags & PRINT_UNAMBIG) + math_chr('\"'); + break; + case V_NULL: + if (flags & PRINT_UNAMBIG) + math_str("NULL"); + break; + case V_OBJ: + (void) objcall(OBJ_PRINT, vp, NULL_VALUE, NULL_VALUE); + break; + case V_LIST: + if (!userfunc("list_print", vp)) + listprint(vp->v_list, + ((flags & PRINT_SHORT) ? 0L : conf->maxprint)); + break; + case V_ASSOC: + assocprint(vp->v_assoc, + ((flags & PRINT_SHORT) ? 0L : conf->maxprint)); + break; + case V_MAT: + if (!userfunc("mat_print", vp)) + matprint(vp->v_mat, + ((flags & PRINT_SHORT) ? 0L : conf->maxprint)); + break; + case V_FILE: + if (!userfunc("file_print", vp)) + printid(vp->v_file, flags); + break; + case V_RAND: + randprint(vp->v_rand, flags); + break; + case V_RANDOM: + randomprint(vp->v_random, flags); + break; + case V_CONFIG: + config_print(vp->v_config); + break; + case V_HASH: + hash_print(vp->v_hash); + break; + case V_BLOCK: + if (!userfunc("blk_print", vp)) + blk_print(vp->v_block); + break; + case V_OCTET: + if (userfunc("octet_print", vp)) break; - case V_COM: - comprint(vp->v_com); - if (conf->traceflags & TRACE_LINKS) - printf("##%ld", vp->v_com->links); - break; - case V_STR: - if (flags & PRINT_UNAMBIG) - math_chr('\"'); - math_str(vp->v_str->s_str); - if (flags & PRINT_UNAMBIG) - math_chr('\"'); - break; - case V_NULL: - if (flags & PRINT_UNAMBIG) - math_str("NULL"); - break; - case V_OBJ: - (void) objcall(OBJ_PRINT, vp, NULL_VALUE, NULL_VALUE); - break; - case V_LIST: - if (!userfunc("list_print", vp)) - listprint(vp->v_list, - ((flags & PRINT_SHORT) ? 0L : conf->maxprint)); - break; - case V_ASSOC: - assocprint(vp->v_assoc, - ((flags & PRINT_SHORT) ? 0L : conf->maxprint)); - break; - case V_MAT: - if (!userfunc("mat_print", vp)) - matprint(vp->v_mat, - ((flags & PRINT_SHORT) ? 0L : conf->maxprint)); - break; - case V_FILE: - if (!userfunc("file_print", vp)) - printid(vp->v_file, flags); - break; - case V_RAND: - randprint(vp->v_rand, flags); - break; - case V_RANDOM: - randomprint(vp->v_random, flags); - break; - case V_CONFIG: - config_print(vp->v_config); - break; - case V_HASH: - hash_print(vp->v_hash); - break; - case V_BLOCK: - if (!userfunc("blk_print", vp)) - blk_print(vp->v_block); - break; - case V_OCTET: - if (userfunc("octet_print", vp)) - break; - qtemp = itoq((long) *vp->v_octet); - qprintnum(qtemp, MODE_DEFAULT); - qfree(qtemp); - break; - case V_OPTR: - printf("o-ptr: %p", vp->v_octet); - break; - case V_VPTR: - printf("v-ptr: %p", vp->v_addr); - break; - case V_SPTR: - printf("s_ptr: %p", vp->v_str); - break; - case V_NPTR: - printf("n_ptr: %p", vp->v_num); - break; - case V_NBLOCK: - if (!userfunc("nblk_print", vp)) - nblock_print(vp->v_nblock); - break; - default: - math_error("Printing unrecognized type of value"); - /*NOTREACHED*/ + qtemp = itoq((long) *vp->v_octet); + qprintnum(qtemp, MODE_DEFAULT); + qfree(qtemp); + break; + case V_OPTR: + printf("o-ptr: %p", vp->v_octet); + break; + case V_VPTR: + printf("v-ptr: %p", vp->v_addr); + break; + case V_SPTR: + printf("s_ptr: %p", vp->v_str); + break; + case V_NPTR: + printf("n_ptr: %p", vp->v_num); + break; + case V_NBLOCK: + if (!userfunc("nblk_print", vp)) + nblock_print(vp->v_nblock); + break; + default: + math_error("Printing unrecognized type of value"); + /*NOTREACHED*/ } } @@ -2748,7 +2765,7 @@ config_print(CONFIG *cfg) NAMETYPE *cp; VALUE tmp; int tab_over; /* TRUE => ok move over one tab stop */ - int i; + size_t len; /* * firewall @@ -2779,8 +2796,8 @@ config_print(CONFIG *cfg) /* print name and spaces */ printf("%s", cp->name); - i = 16 - (int)strlen(cp->name); - while (i-- > 0) + len = 16 - strlen(cp->name); + while (len-- > 0) printf(" "); /* print value */ diff --git a/value.h b/value.h index 2ea9297..5ff97da 100644 --- a/value.h +++ b/value.h @@ -1,7 +1,7 @@ /* * value - definitions of general values and related routines used by calc * - * Copyright (C) 1999 David I. Bell + * Copyright (C) 1999-2006 David I. Bell * * Calc is open software; you can redistribute it and/or modify it under * the terms of the version 2.1 of the GNU Lesser General Public License @@ -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: value.h,v 29.7 2001/06/08 21:00:58 chongo Exp $ + * @(#) $Revision: 29.10 $ + * @(#) $Id: value.h,v 29.10 2006/05/19 15:26:10 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/RCS/value.h,v $ * * Under source code control: 1993/07/30 19:42:47 @@ -88,7 +88,7 @@ typedef struct random RANDOM; */ struct value { short v_type; /* type of value */ - short v_subtype; /* other data related to some types */ + unsigned short v_subtype; /* other data related to some types */ union { /* types of values (see V_XYZ below) */ long vv_int; /* 1: small integer value */ NUMBER *vv_num; /* 2, 21: real number */ @@ -252,7 +252,7 @@ extern DLL void addlistitems(LIST *lp, VALUE *vres); extern DLL void addlistinv(LIST *lp, VALUE *vres); extern DLL void copy2octet(VALUE *, OCTET *); extern DLL int copystod(VALUE *, long, long, VALUE *, long); -extern DLL void protectall(VALUE *, int); +extern DLL void protecttodepth(VALUE *, int, int); extern DLL void set_update(int); @@ -501,8 +501,8 @@ extern DLL void config_print(CONFIG *cfg); /* the CONFIG to print */ * size, memsize and sizeof support */ extern DLL long elm_count(VALUE *vp); -extern DLL long lsizeof(VALUE *vp); -extern DLL long memsize(VALUE *vp); +extern DLL size_t lsizeof(VALUE *vp); +extern DLL size_t memsize(VALUE *vp); /* * String functions @@ -520,7 +520,7 @@ extern DLL STRING *stringshift(STRING *, long); extern DLL STRING *stringcomp(STRING *); extern DLL STRING *stringneg(STRING *); extern DLL STRING *stringcpy(STRING *, STRING *); -extern DLL STRING *stringncpy(STRING *, STRING *, long); +extern DLL STRING *stringncpy(STRING *, STRING *, size_t); extern DLL long stringcontent(STRING *s); extern DLL long stringlowbit(STRING *s); extern DLL long stringhighbit(STRING *s); diff --git a/version.c b/version.c index b04377c..74c59cf 100644 --- a/version.c +++ b/version.c @@ -1,7 +1,7 @@ /* * version - determine the version of calc * - * Copyright (C) 1999-2004 David I. Bell and Landon Curt Noll + * Copyright (C) 1999-2006 David I. Bell and Landon Curt Noll * * Primary author: David I. Bell * @@ -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.55 $ - * @(#) $Id: version.c,v 29.55 2005/12/12 06:47:21 chongo Exp $ + * @(#) $Revision: 29.57 $ + * @(#) $Id: version.c,v 29.57 2006/05/21 06:04:01 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/RCS/version.c,v $ * * Under source code control: 1990/05/22 11:00:58 @@ -46,8 +46,8 @@ static char *program; #include "have_unused.h" #define MAJOR_VER 2 /* major version */ -#define MINOR_VER 11 /* minor version */ -#define MAJOR_PATCH 11 /* patch level or 0 if no patch */ +#define MINOR_VER 12 /* minor version */ +#define MAJOR_PATCH 0 /* patch level or 0 if no patch */ #define MINOR_PATCH 0 /* test number or 0 if no minor patch */ @@ -72,7 +72,7 @@ static char *stored_version = NULL; /* version formed if != NULL */ char *Copyright = "\n" "calc - arbitrary precision calculator\n" "\n" - "@(#) Copyright (C) 2003 David I. Bell, Landon Curt Noll and Ernest Bowen\n" + "@(#) Copyright (C) 2006 David I. Bell, Landon Curt Noll and Ernest Bowen\n" "\n" "Primary author: David I. Bell\n" "\n" @@ -102,13 +102,13 @@ char *Copyright = "\n" int snprintf (char *buf, size_t UNUSED n, const char *fmt, ...) { - int retval; - va_list arg; + int retval; + va_list arg; - va_start (arg, fmt); - retval = vsprintf (buf, fmt, arg); - va_end (arg); - return retval; + va_start (arg, fmt); + retval = vsprintf (buf, fmt, arg); + va_end (arg); + return retval; } #endif @@ -141,13 +141,10 @@ version(void) snprintf(verbuf, BUFSIZ, "%d.%d.%d.%d", calc_major_ver, calc_minor_ver, calc_major_patch, calc_minor_patch); - } else if (MAJOR_PATCH > 0) { + } else { snprintf(verbuf, BUFSIZ, "%d.%d.%d", calc_major_ver, calc_minor_ver, calc_major_patch); - } else { - snprintf(verbuf, BUFSIZ, - "%d.%d", calc_major_ver, calc_minor_ver); } /* @@ -177,7 +174,6 @@ version(void) * * x.y.z.w-r * x.y.z-r - * x.y-r * * where 'r' comes from the content of the release file. */ @@ -214,11 +210,9 @@ print_rpm_version(char *release) if (MINOR_PATCH > 0) { printf("%d.%d.%d.%d-%s\n", calc_major_ver, calc_minor_ver, calc_major_patch, calc_minor_patch, buf); - } else if (MAJOR_PATCH > 0) { + } else { printf("%d.%d.%d-%s\n", calc_major_ver, calc_minor_ver, calc_major_patch, buf); - } else { - printf("%d.%d-%s\n", calc_major_ver, calc_minor_ver, buf); } return; } @@ -230,7 +224,6 @@ print_rpm_version(char *release) * This function prints the major part version string: * * x.y.z - * x.y */ void print_rpm_major(void) @@ -238,12 +231,8 @@ print_rpm_major(void) /* * form the version buffer */ - if (MAJOR_PATCH > 0) { - printf("%d.%d.%d\n", calc_major_ver, calc_minor_ver, - calc_major_patch); - } else { - printf("%d.%d\n", calc_major_ver, calc_minor_ver); - } + printf("%d.%d.%d\n", calc_major_ver, calc_minor_ver, + calc_major_patch); return; } diff --git a/win32/calcerr.c b/win32/calcerr.c index 675498e..5daec22 100644 --- a/win32/calcerr.c +++ b/win32/calcerr.c @@ -242,14 +242,14 @@ CONST char *error_table[E__COUNT+2] = { "No-copy-to destination variable", "No-copy-from source named block", "No-copy-to destination named block", - "No-relocation destination for copy", + "No-relocate destination for copy", "File not open for copy", "fseek or fsize failure for copy", "fwrite error for copy", "fread error for copy", "Non-variable first argument for protect", - "Non-integer second argument for protect", - "Out-of-range second argument for protect", + "Bad second argument for protect", + "Bad third argument for protect", "No-copy-to destination for matfill", "No-assign-from source for matfill", "Non-matrix argument for mattrace", @@ -375,5 +375,57 @@ CONST char *error_table[E__COUNT+2] = { "Bad argument for euler", "Bad argument for sleep", "calc_tty failure", + "No-copy-to destination for octet assign", + "No-copy-from source for octet assign", + "No-change destination for octet assign", + "Non-variable destination for assign", + "No-assign-to destination for assign", + "No-assign-from source for assign", + "No-change destination for assign", + "No-type-change destination for assign", + "No-error-value destination for assign", + "No-copy argument for octet swap", + "No-assign-to-or-from argument for swap", + "Non-variable argument for swap", + "Non-variable argument 4 or 4 for quomod", + "Non-real-number argument 1 or 2 for quomod", + "No-assign-to argument 3 or 4 for quomod", + "No-copy-to or no-change argument for octet preinc", + "Non-variable argument for preinc", + "No-assign-to or no-change argument for preinc", + "No-copy-to or no-change argument for octet predec", + "Non-variable argument for predec", + "No-assign-to or no-change argument for predec", + "No-copy-to or no-change argument for octet postinc", + "Non-variable argument for postinc", + "No-assign-to or no-change argument for postinc", + "No-copy-to or no-change argument for octet postdec", + "Non-variable argument for postdec", + "No-assign-to or no-change argument for postdec", + "Error-type structure for initialization", + "No-copy-to structure for initialization", + "Too many initializer values", + "Attempt to initialize freed named block", + "Bad structure type for initialization", + "No-assign-to element for initialization", + "No-change element for initialization", + "No-type-change element for initialization", + "No-error-value element for initialization", + "No-assign-or-copy-from source for initialization", + "No-relocate for list insert", + "No-relocate for list delete", + "No-relocate for list push", + "No-relocate for list append", + "No-relocate for list pop", + "No-relocate for list remove", + "Non-variable first argument for modify", + "Non-string second argument for modify", + "No-change first argument for modify", + "Undefined function for modify", + "Unacceptable type first argument for modify", + "Non-string arguments for fpathopen", + "Unrecognized mode for fpathopen", + "Bad epsilon argument for log", + "Non-numeric first argument for log", NULL }; diff --git a/win32/calcerr.h b/win32/calcerr.h index e764cbf..eb32f10 100644 --- a/win32/calcerr.h +++ b/win32/calcerr.h @@ -143,7 +143,7 @@ #define E_RSEARCH4 10130 /* Bad fourth argument for rsearch */ #define E_RSEARCH5 10131 /* Cannot find fsize or fpos for rsearch */ #define E_RSEARCH6 10132 /* File not readable for rsearch */ -#define E_FOPEN3 10133 /* Too many open files */ +#define E_MANYOPEN 10133 /* Too many open files */ #define E_REWIND2 10134 /* Attempt to rewind a file that is not open */ #define E_STRERROR1 10135 /* Bad argument type for strerror */ #define E_STRERROR2 10136 /* Index out of range for strerror */ @@ -239,14 +239,14 @@ #define E_COPY14 10226 /* No-copy-to destination variable */ #define E_COPY15 10227 /* No-copy-from source named block */ #define E_COPY16 10228 /* No-copy-to destination named block */ -#define E_COPY17 10229 /* No-relocation destination for copy */ +#define E_COPY17 10229 /* No-relocate destination for copy */ #define E_COPYF1 10230 /* File not open for copy */ #define E_COPYF2 10231 /* fseek or fsize failure for copy */ #define E_COPYF3 10232 /* fwrite error for copy */ #define E_COPYF4 10233 /* fread error for copy */ #define E_PROTECT1 10234 /* Non-variable first argument for protect */ -#define E_PROTECT2 10235 /* Non-integer second argument for protect */ -#define E_PROTECT3 10236 /* Out-of-range second argument for protect */ +#define E_PROTECT2 10235 /* Bad second argument for protect */ +#define E_PROTECT3 10236 /* Bad third argument for protect */ #define E_MATFILL3 10237 /* No-copy-to destination for matfill */ #define E_MATFILL4 10238 /* No-assign-from source for matfill */ #define E_MATTRACE1 10239 /* Non-matrix argument for mattrace */ @@ -372,9 +372,61 @@ #define E_EULER 10359 /* Bad argument for euler */ #define E_SLEEP 10360 /* Bad argument for sleep */ #define E_TTY 10361 /* calc_tty failure */ +#define E_ASSIGN1 10362 /* No-copy-to destination for octet assign */ +#define E_ASSIGN2 10363 /* No-copy-from source for octet assign */ +#define E_ASSIGN3 10364 /* No-change destination for octet assign */ +#define E_ASSIGN4 10365 /* Non-variable destination for assign */ +#define E_ASSIGN5 10366 /* No-assign-to destination for assign */ +#define E_ASSIGN6 10367 /* No-assign-from source for assign */ +#define E_ASSIGN7 10368 /* No-change destination for assign */ +#define E_ASSIGN8 10369 /* No-type-change destination for assign */ +#define E_ASSIGN9 10370 /* No-error-value destination for assign */ +#define E_SWAP1 10371 /* No-copy argument for octet swap */ +#define E_SWAP2 10372 /* No-assign-to-or-from argument for swap */ +#define E_SWAP3 10373 /* Non-variable argument for swap */ +#define E_QUOMOD1 10374 /* Non-variable argument 4 or 4 for quomod */ +#define E_QUOMOD2 10375 /* Non-real-number argument 1 or 2 for quomod */ +#define E_QUOMOD3 10376 /* No-assign-to argument 3 or 4 for quomod */ +#define E_PREINC1 10377 /* No-copy-to or no-change argument for octet preinc */ +#define E_PREINC2 10378 /* Non-variable argument for preinc */ +#define E_PREINC3 10379 /* No-assign-to or no-change argument for preinc */ +#define E_PREDEC1 10380 /* No-copy-to or no-change argument for octet predec */ +#define E_PREDEC2 10381 /* Non-variable argument for predec */ +#define E_PREDEC3 10382 /* No-assign-to or no-change argument for predec */ +#define E_POSTINC1 10383 /* No-copy-to or no-change argument for octet postinc */ +#define E_POSTINC2 10384 /* Non-variable argument for postinc */ +#define E_POSTINC3 10385 /* No-assign-to or no-change argument for postinc */ +#define E_POSTDEC1 10386 /* No-copy-to or no-change argument for octet postdec */ +#define E_POSTDEC2 10387 /* Non-variable argument for postdec */ +#define E_POSTDEC3 10388 /* No-assign-to or no-change argument for postdec */ +#define E_INIT1 10389 /* Error-type structure for initialization */ +#define E_INIT2 10390 /* No-copy-to structure for initialization */ +#define E_INIT3 10391 /* Too many initializer values */ +#define E_INIT4 10392 /* Attempt to initialize freed named block */ +#define E_INIT5 10393 /* Bad structure type for initialization */ +#define E_INIT6 10394 /* No-assign-to element for initialization */ +#define E_INIT7 10395 /* No-change element for initialization */ +#define E_INIT8 10396 /* No-type-change element for initialization */ +#define E_INIT9 10397 /* No-error-value element for initialization */ +#define E_INIT10 10398 /* No-assign-or-copy-from source for initialization */ +#define E_LIST1 10399 /* No-relocate for list insert */ +#define E_LIST2 10400 /* No-relocate for list delete */ +#define E_LIST3 10401 /* No-relocate for list push */ +#define E_LIST4 10402 /* No-relocate for list append */ +#define E_LIST5 10403 /* No-relocate for list pop */ +#define E_LIST6 10404 /* No-relocate for list remove */ +#define E_MODIFY1 10405 /* Non-variable first argument for modify */ +#define E_MODIFY2 10406 /* Non-string second argument for modify */ +#define E_MODIFY3 10407 /* No-change first argument for modify */ +#define E_MODIFY4 10408 /* Undefined function for modify */ +#define E_MODIFY5 10409 /* Unacceptable type first argument for modify */ +#define E_FPATHOPEN1 10410 /* Non-string arguments for fpathopen */ +#define E_FPATHOPEN2 10411 /* Unrecognized mode for fpathopen */ +#define E_LOG1 10412 /* Bad epsilon argument for log */ +#define E_LOG2 10413 /* Non-numeric first argument for log */ -#define E__HIGHEST 10361 /* highest calc error */ -#define E__COUNT 361 /* number of calc errors */ +#define E__HIGHEST 10413 /* highest calc error */ +#define E__COUNT 413 /* number of calc errors */ #define E_USERDEF 20000 /* base of user defined errors */ /* names of calc error values */ diff --git a/zfunc.c b/zfunc.c index 005c281..35efb01 100644 --- a/zfunc.c +++ b/zfunc.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.4 $ - * @(#) $Id: zfunc.c,v 29.4 2003/08/26 04:35:11 chongo Exp $ + * @(#) $Revision: 29.7 $ + * @(#) $Id: zfunc.c,v 29.7 2006/05/20 08:43:55 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/RCS/zfunc.c,v $ * * Under source code control: 1990/02/15 01:48:27 @@ -34,6 +34,9 @@ ZVALUE _tenpowers_[TEN_MAX+1]; /* table of 10^2^n */ +static long *power10 = NULL; +static int max_power10_exp = 0; + /* * Compute the factorial of a number. @@ -402,27 +405,27 @@ zpowi(ZVALUE z1, ZVALUE z2, ZVALUE *res) */ if (power <= 4) { switch ((int) power) { - case 1: - ans.len = z1.len; - ans.v = alloc(ans.len); - zcopyval(z1, ans); - ans.sign = (BOOL)sign; - *res = ans; - return; - case 2: - zsquare(z1, res); - return; - case 3: - zsquare(z1, &temp); - zmul(z1, temp, res); - zfree(temp); - res->sign = (BOOL)sign; - return; - case 4: - zsquare(z1, &temp); - zsquare(temp, res); - zfree(temp); - return; + case 1: + ans.len = z1.len; + ans.v = alloc(ans.len); + zcopyval(z1, ans); + ans.sign = (BOOL)sign; + *res = ans; + return; + case 2: + zsquare(z1, res); + return; + case 3: + zsquare(z1, &temp); + zmul(z1, temp, res); + zfree(temp); + res->sign = (BOOL)sign; + return; + case 4: + zsquare(z1, &temp); + zsquare(temp, res); + zfree(temp); + return; } } /* @@ -1113,7 +1116,7 @@ zlog(ZVALUE z, ZVALUE base) /* base = 10 */ if (base.len == 1 && base.v[0] == 10) - return zlog10(z); + return zlog10(z, NULL); /* * Now loop by squaring the base each time, and see whether or * not each successive square is still smaller than the number. @@ -1151,21 +1154,72 @@ zlog(ZVALUE z, ZVALUE base) /* * Return the integral log base 10 of a number. + * + * If was_10_power != NULL, then this flag is set to TRUE if the + * value was a power of 10, FALSE otherwise. */ long -zlog10(ZVALUE z) +zlog10(ZVALUE z, BOOL *was_10_power) { - register ZVALUE *zp; /* current square */ + ZVALUE *zp; /* current square */ long power; /* current power */ ZVALUE temp; /* temporary */ + ZVALUE pow10; /* power of 10 */ + FLAG rel; /* relationship */ + int i; if (ziszero(z)) { math_error("Zero argument argument for zlog10"); /*NOTREACHED*/ } + /* Ignore sign of z */ z.sign = 0; + /* preload power10 table if missing */ + if (power10 == NULL) { + long v; + + /* determine power10 table size */ + for (v=1, max_power10_exp=0; + v <= (long)(MAXLONG/10L); + v *= 10L, ++max_power10_exp) { + } + + /* create power10 table */ + power10 = malloc(sizeof(long) * (max_power10_exp+1)); + if (power10 == NULL) { + math_error("cannot malloc power10 table"); + /*NOTREACHED*/ + } + + /* load power10 table */ + for (i=0, v = 1L; i <= max_power10_exp; ++i, v *= 10L) { + power10[i] = v; + } + } + + /* assume not a power of ten unless we find out otherwise */ + if (was_10_power != NULL) { + *was_10_power = FALSE; + } + + /* quick exit for small values */ + if (! zgtmaxlong(z)) { + long value = ztolong(z); + + for (i=0; i <= max_power10_exp; ++i) { + if (value == power10[i]) { + if (was_10_power != NULL) { + *was_10_power = TRUE; + } + return i; + } else if (value < power10[i]) { + return i-1; + } + } + } + /* * Loop by squaring the base each time, and see whether or * not each successive square is still smaller than the number. @@ -1181,26 +1235,56 @@ zlog10(ZVALUE z) zsquare(*zp, zp + 1); zp++; } + /* * Now back down the squares, and multiply them together to see * exactly how many times the base can be raised by. */ - power = 0; - - for (; zp > _tenpowers_; zp--) { - if (zrel(z, *zp) >= 0) { - zquo(z, *zp, &temp, 0); - if (power) - zfree(z); - z = temp; - power++; + /* find the tenpower table entry < z */ + do { + rel = zrel(*zp, z); + if (rel == 0) { + /* quick exit - we match a tenpower entry */ + if (was_10_power != NULL) { + *was_10_power = TRUE; + } + return (1L << (zp - _tenpowers_)); + } + } while (rel > 0 && --zp >= _tenpowers_); + if (zp < _tenpowers_) { + math_error("fell off bottom of tenpower table!"); + /*NOTREACHED*/ + } + + /* the tenpower value is now our starting comparison value */ + zcopy(*zp, &pow10); + power = (1L << (zp - _tenpowers_)); + + /* try to build up a power of 10 from tenpower table entries */ + while (--zp >= _tenpowers_) { + + /* try the next lower tenpower value */ + zmul(pow10, *zp, &temp); + rel = zrel(temp, z); + if (rel == 0) { + /* exact power of 10 match */ + power += (1L << (zp - _tenpowers_)); + if (was_10_power != NULL) { + *was_10_power = TRUE; + } + return power; + + /* ignore this entry if we went too large */ + } else if (rel > 0) { + zfree(temp); + + /* otherwise increase power and keep going */ + } else { + power += (1L << (zp - _tenpowers_)); + zfree(pow10); + pow10 = temp; } - power <<= 1; } - if (zrel(z, *zp) >= 0) - power++; - if (power > 1) - zfree(z); return power; } @@ -1440,7 +1524,7 @@ zdigits(ZVALUE z1) } return count; } - return (zlog10(z1) + 1); + return (zlog10(z1, NULL) + 1); } diff --git a/zio.c b/zio.c index a45dd5c..c121666 100644 --- a/zio.c +++ b/zio.c @@ -1,7 +1,7 @@ /* * zio - scanf and printf routines for arbitrary precision integers * - * Copyright (C) 1999-2002 David I. Bell + * Copyright (C) 1999-2006 David I. Bell * * Calc is open software; you can redistribute it and/or modify it under * the terms of the version 2.1 of the GNU Lesser General Public License @@ -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: zio.c,v 29.4 2002/12/29 09:20:25 chongo Exp $ + * @(#) $Revision: 29.6 $ + * @(#) $Id: zio.c,v 29.6 2006/05/19 15:26:10 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/RCS/zio.c,v $ * * Under source code control: 1993/07/30 19:42:48 @@ -55,8 +55,8 @@ struct iostate { int outmode2; /* secondary output mode */ FILE *outfp; /* file unit for output (if any) */ char *outbuf; /* output string buffer (if any) */ - long outbufsize; /* current size of string buffer */ - long outbufused; /* space used in string buffer */ + size_t outbufsize; /* current size of string buffer */ + size_t outbufused; /* space used in string buffer */ BOOL outputisstring; /* TRUE if output is to string buffer */ }; @@ -65,8 +65,8 @@ static IOSTATE *oldiostates = NULL; /* list of saved output states */ static FILE *outfp = NULL; /* file unit for output */ static char *outbuf = NULL; /* current diverted buffer */ static BOOL outputisstring = FALSE; -static long outbufsize; -static long outbufused; +static size_t outbufsize; +static size_t outbufused; /* @@ -122,13 +122,13 @@ void math_str(char *str) { char *cp; - long len; + size_t len; if (!outputisstring) { fputs(str, outfp); return; } - len = (long)strlen(str); + len = strlen(str); if ((outbufused + len) > outbufsize) { cp = (char *)realloc(outbuf, outbufsize + len + OUTBUFSIZE + 1); if (cp == NULL) { @@ -155,12 +155,12 @@ void math_fill(char *str, long width) { if (width > 0) { - width -= strlen(str); + width -= (long)strlen(str); while (width-- > 0) PUTCHAR(' '); PUTSTR(str); } else { - width += strlen(str); + width += (long)strlen(str); PUTSTR(str); while (width++ < 0) PUTCHAR(' '); diff --git a/zmath.h b/zmath.h index 05c1346..d79c575 100644 --- a/zmath.h +++ b/zmath.h @@ -1,7 +1,7 @@ /* * zmath - declarations for extended precision integer arithmetic * - * Copyright (C) 1999,2002,2004 David I. Bell + * Copyright (C) 1999-2006 David I. Bell * * Calc is open software; you can redistribute it and/or modify it under * the terms of the version 2.1 of the GNU Lesser General Public License @@ -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.12 $ - * @(#) $Id: zmath.h,v 29.12 2004/03/31 04:58:40 chongo Exp $ + * @(#) $Revision: 29.15 $ + * @(#) $Id: zmath.h,v 29.15 2006/05/21 07:10:22 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/RCS/zmath.h,v $ * * Under source code control: 1993/07/30 19:42:48 @@ -350,7 +350,7 @@ extern DLL void zpowermod(ZVALUE z1, ZVALUE z2, ZVALUE z3, ZVALUE *res); extern DLL BOOL zmodinv(ZVALUE z1, ZVALUE z2, ZVALUE *res); extern DLL BOOL zrelprime(ZVALUE z1, ZVALUE z2); extern DLL long zlog(ZVALUE z1, ZVALUE z2); -extern DLL long zlog10(ZVALUE z); +extern DLL long zlog10(ZVALUE z, BOOL *was_10_power); extern DLL long zdivcount(ZVALUE z1, ZVALUE z2); extern DLL long zfacrem(ZVALUE z1, ZVALUE z2, ZVALUE *rem); extern DLL long zgcdrem(ZVALUE z1, ZVALUE z2, ZVALUE *res); @@ -424,14 +424,15 @@ extern DLL void zredcpower(REDC *rp, ZVALUE z1, ZVALUE z2, ZVALUE *res); /* * macro expansions to speed this thing up */ -#define ziseven(z) (!(*(z).v & 01)) -#define zisodd(z) (*(z).v & 01) +#define ziseven(z) (!(*(z).v & 0x1)) +#define zisodd(z) (*(z).v & 0x1) #define ziszero(z) ((*(z).v == 0) && ((z).len == 1)) #define zisneg(z) ((z).sign) #define zispos(z) (((z).sign == 0) && (*(z).v || ((z).len > 1))) #define zisunit(z) ((*(z).v == 1) && ((z).len == 1)) #define zisone(z) ((*(z).v == 1) && ((z).len == 1) && !(z).sign) #define zisnegone(z) ((*(z).v == 1) && ((z).len == 1) && (z).sign) +#define zltnegone(z) (zisneg(z) && (((z).len > 1) || *(z).v > 1)) #define zistwo(z) ((*(z).v == 2) && ((z).len == 1) && !(z).sign) #define zisabstwo(z) ((*(z).v == 2) && ((z).len == 1)) #define zisabsleone(z) ((*(z).v <= 1) && ((z).len == 1)) @@ -479,6 +480,13 @@ extern DLL void zredcpower(REDC *rp, ZVALUE z1, ZVALUE z2, ZVALUE *res); * zge31b(z) TRUE if abs(z) >= 2^31 * zge32b(z) TRUE if abs(z) >= 2^32 * zge64b(z) TRUE if abs(z) >= 2^64 + * zge128b(z) TRUE if abs(z) >= 2^128 + * zge256b(z) TRUE if abs(z) >= 2^256 + * zge512b(z) TRUE if abs(z) >= 2^512 + * zge1024b(z) TRUE if abs(z) >= 2^1024 + * zge2048b(z) TRUE if abs(z) >= 2^2048 + * zge4096b(z) TRUE if abs(z) >= 2^4096 + * zge8192b(z) TRUE if abs(z) >= 2^8192 */ #if BASEB == 32 @@ -487,6 +495,13 @@ extern DLL void zredcpower(REDC *rp, ZVALUE z1, ZVALUE z2, ZVALUE *res); #define zge31b(z) (!zistiny(z) || (((SHALF)(z).v[0]) < 0)) #define zge32b(z) (!zistiny(z)) #define zge64b(z) ((z).len > 2) +#define zge128b(z) ((z).len > 4) +#define zge256b(z) ((z).len > 8) +#define zge512b(z) ((z).len > 16) +#define zge1024b(z) ((z).len > 32) +#define zge2048b(z) ((z).len > 64) +#define zge4096b(z) ((z).len > 128) +#define zge8192b(z) ((z).len > 256) #else @@ -495,6 +510,13 @@ extern DLL void zredcpower(REDC *rp, ZVALUE z1, ZVALUE z2, ZVALUE *res); #define zge31b(z) (((z).len > 2) || (((z).len == 2) && (((SHALF)(z).v[1]) < 0))) #define zge32b(z) ((z).len > 2) #define zge64b(z) ((z).len > 4) +#define zge128b(z) ((z).len > 8) +#define zge256b(z) ((z).len > 16) +#define zge512b(z) ((z).len > 32) +#define zge1024b(z) ((z).len > 64) +#define zge2048b(z) ((z).len > 128) +#define zge4096b(z) ((z).len > 256) +#define zge8192b(z) ((z).len > 512) #endif diff --git a/zprime.c b/zprime.c index 29a6077..eae55aa 100644 --- a/zprime.c +++ b/zprime.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.2 $ - * @(#) $Id: zprime.c,v 29.2 2000/06/07 14:02:13 chongo Exp $ + * @(#) $Revision: 29.3 $ + * @(#) $Id: zprime.c,v 29.3 2006/05/20 08:43:55 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/RCS/zprime.c,v $ * * Under source code control: 1994/05/29 04:34:36 @@ -1002,27 +1002,27 @@ zprimetest(ZVALUE z, long count, ZVALUE skip) pr = prime; for (i = 0; i < count; i++) { switch (type) { - case 0: - zfree(zbase); - zrandrange(_two_, zm1, &zbase); + case 0: + zfree(zbase); + zrandrange(_two_, zm1, &zbase); + break; + case 1: + if (i == 0) break; - case 1: - if (i == 0) - break; - zfree(zbase); - if (*pr == 1 || (long)*pr >= limit) { - zfree(z1); - zfree(zm1); - return TRUE; - } - itoz((long) *pr++, &zbase); + zfree(zbase); + if (*pr == 1 || (long)*pr >= limit) { + zfree(z1); + zfree(zm1); + return TRUE; + } + itoz((long) *pr++, &zbase); + break; + default: + if (i == 0) break; - default: - if (i == 0) - break; - zadd(zbase, _one_, &z3); - zfree(zbase); - zbase = z3; + zadd(zbase, _one_, &z3); + zfree(zbase); + zbase = z3; } ij = 0; @@ -1107,43 +1107,43 @@ zredcprimetest(ZVALUE z, long count, ZVALUE skip) for (i = 0; i < count; i++) { switch (type) { - case 0: - do { - zfree(zbase); - zrandrange(_one_, z, &zbase); - } - while (!zcmp(zbase, rp->one) || - !zcmp(zbase, zredcm1)); - break; - case 1: - if (i == 0) { - break; - } + case 0: + do { zfree(zbase); - if (*pr == 1 || (long)*pr >= limit) { - zfree(z1); - zfree(zm1); - if (z.len < conf->redc2) { - zredcfree(rp); - zfree(zredcm1); - } - return TRUE; - } - itoz((long) *pr++, &z3); - zredcencode(rp, z3, &zbase); - zfree(z3); + zrandrange(_one_, z, &zbase); + } + while (!zcmp(zbase, rp->one) || + !zcmp(zbase, zredcm1)); + break; + case 1: + if (i == 0) { break; - default: - if (i == 0) - break; - zadd(zbase, rp->one, &z3); + } + zfree(zbase); + if (*pr == 1 || (long)*pr >= limit) { + zfree(z1); + zfree(zm1); + if (z.len < conf->redc2) { + zredcfree(rp); + zfree(zredcm1); + } + return TRUE; + } + itoz((long) *pr++, &z3); + zredcencode(rp, z3, &zbase); + zfree(z3); + break; + default: + if (i == 0) + break; + zadd(zbase, rp->one, &z3); + zfree(zbase); + zbase = z3; + if (zrel(zbase, z) >= 0) { + zsub(zbase, z, &z3); zfree(zbase); zbase = z3; - if (zrel(zbase, z) >= 0) { - zsub(zbase, z, &z3); - zfree(zbase); - zbase = z3; - } + } } ij = 0;