mirror of
https://github.com/lcn2/calc.git
synced 2025-08-19 01:13:27 +03:00
Compare commits
7 Commits
2.11.0t8.8
...
2.11.0t9.2
Author | SHA1 | Date | |
---|---|---|---|
|
75e742c716 | ||
|
1b42111665 | ||
|
ea6b3904be | ||
|
f3fceff1b6 | ||
|
69d4a17187 | ||
|
a99a3400e7 | ||
|
9b6c308b42 |
211
BUGS
211
BUGS
@@ -68,178 +68,6 @@ importantly, fixes (in the form of a context diff patch) to:
|
||||
|
||||
Known bugs:
|
||||
|
||||
* When compiled on some Big Endian machines with BASEB forced to
|
||||
be 16 (by setting LONGLONG_BITS= 0 in the Makefile), calc fails
|
||||
a number of regression tests:
|
||||
|
||||
4230: n = ftell(f)
|
||||
4231: isnull(fputs(f,L,"\n",C,"\n",N,"\n"))
|
||||
4232: fseek(f, n)
|
||||
**** Non-true result (0): 4233: fgetstr(f) == LCN
|
||||
4234: isnull(fclose(f))
|
||||
4235: a = exp(27, 1e-1000)
|
||||
4236: b = sqrt(7 + 5i, 1e-2000)
|
||||
4252: fscanf(f, "%*[^|]%*c%n%*[^[]%*c%n", m, n) == 2
|
||||
4253: fseek(f, m)
|
||||
4254: fscanf(f, "%3c", x) == 1
|
||||
**** Non-true result (0): 4255: x == " Cu"
|
||||
4256: fseek(f, n)
|
||||
4257: fscanf(f, "%s", y) == 1
|
||||
**** Non-true result (0): 4258: y == "Noll"
|
||||
4259: isnull(fclose(f))
|
||||
4260: x = rm("junk4200")
|
||||
4261: Ending test_fileops
|
||||
4600: Beginning test_fileop
|
||||
4601: ttest(0,0): passed
|
||||
4602: stest(): failed
|
||||
**** search(f, "and") != 10 failed
|
||||
4603: ttest(1,1): failed
|
||||
**** Failure 2 for i = 0
|
||||
4604: stest(): failed
|
||||
**** search(f, "and") != 10 failed
|
||||
4605: ttest(2,2): failed
|
||||
**** Failure 2 for i = 0
|
||||
4606: stest(): failed
|
||||
**** search(f, "and") != 10 failed
|
||||
4607: ttest(3,3): failed
|
||||
**** Failure 2 for i = 0
|
||||
4608: stest(): failed
|
||||
**** search(f, "and") != 10 failed
|
||||
4609: ttest(4,4): failed
|
||||
**** Failure 2 for i = 0
|
||||
4610: stest(): failed
|
||||
**** search(f, "and") != 10 failed
|
||||
4611: ttest(5,5): failed
|
||||
**** Failure 2 for i = 0
|
||||
4612: stest(): failed
|
||||
**** search(f, "and") != 10 failed
|
||||
4613: ttest(6,6): failed
|
||||
**** Failure 2 for i = 0
|
||||
4614: stest(): failed
|
||||
**** search(f, "and") != 10 failed
|
||||
4615: ttest(7,7): failed
|
||||
**** Failure 2 for i = 0
|
||||
4616: stest(): failed
|
||||
**** search(f, "and") != 10 failed
|
||||
4617: ttest(8,8): failed
|
||||
**** Failure 2 for i = 0
|
||||
4618: stest(): failed
|
||||
**** search(f, "and") != 10 failed
|
||||
4619: ttest(9,9): failed
|
||||
**** Failure 1 for file size
|
||||
4620: stest(): failed
|
||||
**** fopen("junk4600", "w") failed
|
||||
4621: Ending test_fileop
|
||||
|
||||
4700: Beginning test_charset
|
||||
**** errcount:172 > ecnt:150
|
||||
4701: "\a" == char(7)
|
||||
4702: "\v" == char(11)
|
||||
4703: "\e" == char(27)
|
||||
5000: Beginning test_filesearch
|
||||
5001: x = rm("-f", "junk5000")
|
||||
5002: f = fopen("junk5000", "w")
|
||||
**** Unable to open "junk5000" for writing
|
||||
|
||||
5100: Beginning test_newdecl
|
||||
5101: test5100(1)
|
||||
**** errcount:173 > ecnt:172
|
||||
5102: a5100 == 0
|
||||
5103: b5100 == 2
|
||||
5104: test5100(1)
|
||||
5927: test unused
|
||||
5928: test unused
|
||||
5929: test unused
|
||||
**** errcount:180 > ecnt:177
|
||||
5930: isassoc(loc) == 0
|
||||
5931: isassoc(a) == 1
|
||||
5932: isassoc(ofd) == 0
|
||||
6079: test unused
|
||||
6080: iserror(loc) == 0
|
||||
6081: iserror(a) == 0
|
||||
**** Non-true result (0): 6082: iserror(ofd) == 0
|
||||
**** Non-true result (0): 6083: iserror(cfd) == 0
|
||||
6084: iserror(blk) == 0
|
||||
6085: iserror(nblk) == 0
|
||||
6086: iserror(cfg) == 0
|
||||
6139: test unused
|
||||
6140: isfile(loc) == 0
|
||||
6141: isfile(a) == 0
|
||||
**** Non-true result (0): 6142: isfile(ofd) == 1
|
||||
**** Non-true result (0): 6143: isfile(cfd) == 1
|
||||
6144: isfile(blk) == 0
|
||||
6145: isfile(nblk) == 0
|
||||
6146: isfile(cfg) == 0
|
||||
|
||||
6700: Beginning test_blk
|
||||
6701: A = blk(20);
|
||||
**** errcount:181 > ecnt:180
|
||||
6702: size(A) == 20
|
||||
6703: sizeof(A) == 256
|
||||
6704: B = A;
|
||||
6822: C == A
|
||||
6823: fs = fopen("junk6800", "w+");
|
||||
6824: blkcpy(fs, A);
|
||||
**** errcount:183 > ecnt:181
|
||||
**** Non-true result (0): 6825: size(f) == 5
|
||||
6826: blkcpy(B = blk(), fs);
|
||||
**** errcount:184 > ecnt:183
|
||||
**** Non-true result (0): 6827: B == A
|
||||
6828: blkcpy(fs, A, ,100);
|
||||
**** errcount:185 > ecnt:184
|
||||
**** Non-true result (0): 6829: size(f) == 105
|
||||
6830: blkcpy(C = blk(), fs, 2, ,100)
|
||||
**** errcount:186 > ecnt:185
|
||||
**** Non-true result (0): 6831: C == (blk() = {1,2}
|
||||
6832: A = blk();
|
||||
6833: blkcpy(A, "blk6800");
|
||||
6834: size(A) == 9
|
||||
6900: Beginning test_name
|
||||
6901: x = rm("-f", "junk6900")
|
||||
6902: f = fopen("junk6900", "w")
|
||||
**** errcount:189 > ecnt:186
|
||||
**** Non-true result (0): 6903: name(f) == "junk6900"
|
||||
6904: fclose(f)
|
||||
**** errcount:190 > ecnt:189
|
||||
6905: name(f) == null()
|
||||
6906: A = blk("blk6900")
|
||||
6907: name(A) == "blk6900"
|
||||
7002: B = blk();
|
||||
7003: copy("abc yz", A);
|
||||
7004: copy("defg", B);
|
||||
**** errcount:191 > ecnt:190
|
||||
7005: strprintf("%s", A) == "abc yz"
|
||||
7006: strprintf("%s", A[2]) == "c yz"
|
||||
7007: strprintf("%s", A[7]) == ""
|
||||
|
||||
9995: freeredc()
|
||||
9996: freestatics()
|
||||
**** 24 error(s) found \/++\/
|
||||
|
||||
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.
|
||||
|
||||
=-=
|
||||
|
||||
Calc Mis-features:
|
||||
|
||||
* The following shell command (written in sh,ksh,bash-like form) works:
|
||||
|
||||
calc '/*
|
||||
* comment
|
||||
*/
|
||||
print 2+3;'
|
||||
|
||||
However this (also written in sh,ksh,bash-like form) does not work:
|
||||
|
||||
echo '/*
|
||||
* comment
|
||||
*/
|
||||
print 2+3;' | calc
|
||||
|
||||
The 2nd example will result in an 'Unterminated comment' error.
|
||||
|
||||
* Calc does not support the #! exec method. For example of the
|
||||
following is placed in an executable file (assume the path to
|
||||
calc is correct) called /tmp/xyzzy:
|
||||
@@ -253,3 +81,42 @@ Calc Mis-features:
|
||||
Will result in '"tmp" is undefined' and '"xyzzy" is undefined'
|
||||
error messages because calc considers $0 as an expression to
|
||||
evaluate.
|
||||
|
||||
* The following file:
|
||||
|
||||
/* this is bugdemo.cal */
|
||||
x = eval(prompt(">>> "));
|
||||
print x;
|
||||
|
||||
when executed as:
|
||||
|
||||
calc read bugdemo.cal
|
||||
|
||||
will obtain a prompt from the terminal, print the value but leave
|
||||
the terminal in a 'bad' state, as if stty -icanon -echo -echoe
|
||||
had been executed.
|
||||
|
||||
* Dec Alpha Linux compiling with gcc-2.95.1 (or gcc-2.95.2) and
|
||||
-O2 fails the regression test with:
|
||||
|
||||
make -s check
|
||||
000: Beginning regression tests
|
||||
001: Some of these tests may take a while ...
|
||||
002: Within each section, output should be numbered sequentially
|
||||
003: parsed global definitions
|
||||
004: parsed vrfy()
|
||||
005: parsed prob(str)
|
||||
006: parsed getglobalvar()
|
||||
007: parsed test_booleans()
|
||||
008: parsed test_variables()
|
||||
make: *** [check] Segmentation fault (core dumped)
|
||||
|
||||
Other programs have reported problems when compiling -O2 with
|
||||
gcc-2.95.1 on the Alpha and Mips.
|
||||
|
||||
One work-a-round is to not compile with -O2 (perhaps just -O).
|
||||
Another work-a-round is not use gcc-2.95.1.
|
||||
|
||||
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.
|
||||
|
103
CHANGES
103
CHANGES
@@ -1,4 +1,91 @@
|
||||
Following is the change from calc version 2.11.0t8 to date:
|
||||
Following is the change from calc version 2.11.0t8.9.1 to date:
|
||||
|
||||
The config("verbose_quit") will control the printing of the message:
|
||||
|
||||
Quit or abort executed
|
||||
|
||||
when a non-interactive ABORT, QUIT or EXIT is encounted. By default,
|
||||
config("verbose_quit") is TRUE and the message is printed. If one does:
|
||||
|
||||
config("verbose_quit", 0)
|
||||
|
||||
the message is disabled.
|
||||
|
||||
Added 8400 regression test set and test8400.cal to test the new
|
||||
quit and config("verbose_quit") functionality.
|
||||
|
||||
Fixed the BigEndian BASEB==16 regression bugs by correctly swapping
|
||||
16 bit HALFs in a 64 bit value (such as a 64 bit file pointer).
|
||||
|
||||
Added calclevel() builtin to calculation level at which it is called.
|
||||
|
||||
Added help/calclevel and help/inputlevel help files.
|
||||
|
||||
Removed regression tests 951 and 5984 so that the regress test will
|
||||
run in non-interactively / without a TTY such as under Debian's
|
||||
build daemon.
|
||||
|
||||
The eval(str) builtin will return an error-value rather than cause
|
||||
an execution error str has a scan-error.
|
||||
|
||||
Declarations are permitted to end with EOF as well as a newline or ';'.
|
||||
|
||||
When prompt() occurs while reading a file, it will take input from
|
||||
the terminal rather than taking it from a file. For example:
|
||||
|
||||
/* This demonstrates the use of prompt() and some other things */
|
||||
config("verbose_quit", 0);
|
||||
define getnumber() {
|
||||
local x;
|
||||
for (;;) {
|
||||
x = eval(prompt(">>> "));
|
||||
if (isnum(x))
|
||||
return x;
|
||||
print "Not a number! Try again";
|
||||
}
|
||||
}
|
||||
print "This will display the sqrt of each number you enter";
|
||||
print "Enter quit to stop";
|
||||
for (;;) {
|
||||
print sqrt(getnumber());
|
||||
}
|
||||
print "Good bye";
|
||||
|
||||
Comments entered at input terminal level may be spread over several
|
||||
lines. For example:
|
||||
|
||||
/*
|
||||
* Assume that this calc script is called: comment.cal
|
||||
* Then these commands now work:
|
||||
* cat comment.cal | calc
|
||||
* calc < comment.cal
|
||||
*/
|
||||
print "Hello";
|
||||
|
||||
Added:
|
||||
|
||||
-D calc_debug[:lib_debug:[user_debug]]
|
||||
|
||||
to set the initial value of config("calc_debug"), config("lib_debug")
|
||||
and config("user_debug").
|
||||
|
||||
The : separated strings of -D are interpreted as signed 32 bit values.
|
||||
After an optional leading sign a leading zero indicates octal
|
||||
conversion, and a leading ``0x'' or ``0X'' hexadecimal conversion.
|
||||
Otherwise, decimal conversion is assumed.
|
||||
|
||||
Reordered the config structure moving calc_debug ahead of lib_debug.
|
||||
|
||||
Added bits 4 and 5 to config("calc_debug"):
|
||||
|
||||
4 Report on changes to the state of stdin as well as changes
|
||||
to internal variables that control the setting and restoring
|
||||
of stdin.
|
||||
|
||||
5 Report on changes to the run state of calc.
|
||||
|
||||
|
||||
Following is the change from calc version 2.11.0t8 to 2.11.0t8.9:
|
||||
|
||||
Moved 'wishlist' enhancements from the help/todo file to a new
|
||||
help/wishlist file. Ordered, by priority, help/todo items into
|
||||
@@ -132,13 +219,25 @@ Following is the change from calc version 2.11.0t8 to date:
|
||||
Fixed the help/custom_cal, help/new_custom, and help/copy files so
|
||||
that they contain the correct contents instead of the 'usage' file.
|
||||
|
||||
Fixed problem with loss of bindings when .calc -i args runs into
|
||||
Fixed problem with loss of bindings when calc -i args runs into
|
||||
an error while processing 'args' and drops into interactive mode
|
||||
without the terminal bindings being set.
|
||||
|
||||
Added patch from Ernest Bowen to extablish the abort command as
|
||||
well as to clarify the roles of quit and exit. See the help/command
|
||||
file for details.
|
||||
|
||||
Updated to some extend, the help/statement and help/command help
|
||||
files with new information about SHOW, QUIT, EXIT and ABORT.
|
||||
|
||||
Added show sizes to pzasusb8.cal.
|
||||
|
||||
Updated calc man page and help/usage file to reflect recent
|
||||
command line changes.
|
||||
|
||||
Fixed a bug, reported by Michael Somos <somos@grail.cba.csuohio.edu>,
|
||||
which prevented calc -m from being used.
|
||||
|
||||
Fixed misc compiler warnings.
|
||||
|
||||
|
||||
|
1
README
1
README
@@ -42,6 +42,7 @@ For overview of calc overview:
|
||||
> help define
|
||||
> help statement
|
||||
> help variable
|
||||
> help usage
|
||||
|
||||
For list of builtin functions:
|
||||
|
||||
|
90
calc.c
90
calc.c
@@ -40,6 +40,7 @@
|
||||
* static definitions and functions
|
||||
*/
|
||||
static char *usage = "usage: %s [-c] [-C] [-d] [-e] [-h] [-i] [-m mode]\n"
|
||||
"\t[-D calc_debug[:lib_debug:[user_debug]]]\n"
|
||||
"\t[-n] [-p] [-q] [-u] [-v] [[--] calc_cmd ...]\n";
|
||||
static void intint(int arg); /* interrupt routine */
|
||||
|
||||
@@ -55,13 +56,14 @@ main(int argc, char **argv)
|
||||
extern char *optarg; /* option argument */
|
||||
extern int optind; /* option index */
|
||||
int c; /* option */
|
||||
char *p;
|
||||
long i;
|
||||
|
||||
/*
|
||||
* parse args
|
||||
*/
|
||||
program = argv[0];
|
||||
while ((c = getopt(argc, argv, "Cehim:npquvcd")) != -1) {
|
||||
while ((c = getopt(argc, argv, "Cehim:npquvcdD:")) != -1) {
|
||||
switch (c) {
|
||||
case 'C':
|
||||
#if defined(CUSTOM)
|
||||
@@ -87,7 +89,7 @@ main(int argc, char **argv)
|
||||
i_flag = TRUE;
|
||||
break;
|
||||
case 'm':
|
||||
if (optarg[1] == '\0' || *optarg<'0' || *optarg>'7') {
|
||||
if (optarg[1] != '\0' || *optarg<'0' || *optarg>'7') {
|
||||
/*
|
||||
* we are too early in processing to
|
||||
* call libcalc_call_me_last()
|
||||
@@ -126,6 +128,26 @@ main(int argc, char **argv)
|
||||
*/
|
||||
printf("%s (version %s)\n", CALC_TITLE, version());
|
||||
exit(0);
|
||||
case 'D':
|
||||
/*
|
||||
* parse the -D optarg
|
||||
*
|
||||
* Could be calc_debug
|
||||
* or calc_debug:lib_debug
|
||||
* or calc_debug:lib_debug:user_debug
|
||||
*/
|
||||
calc_debug = optarg;
|
||||
p = strchr(optarg, ':');
|
||||
if (p != NULL) {
|
||||
*p = '\0';
|
||||
lib_debug = p+1;
|
||||
p = strchr(lib_debug, ':');
|
||||
if (p != NULL) {
|
||||
*p = '\0';
|
||||
user_debug = p+1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
/*
|
||||
* we are too early in processing to call
|
||||
@@ -185,6 +207,8 @@ main(int argc, char **argv)
|
||||
*/
|
||||
libcalc_call_me_first();
|
||||
stdin_tty = isatty(0); /* assume stdin is on fd 0 */
|
||||
if (conf->calc_debug & CALCDBG_TTY)
|
||||
printf("DEBUG: stdin_tty is %d\n", stdin_tty);
|
||||
if (want_defhelp) {
|
||||
givehelp(DEFAULTCALCHELP);
|
||||
libcalc_call_me_last();
|
||||
@@ -239,9 +263,17 @@ main(int argc, char **argv)
|
||||
*/
|
||||
if (run_state == RUN_BEGIN) {
|
||||
if (!q_flag && allow_read) {
|
||||
if (conf->calc_debug & CALCDBG_RUNSTATE)
|
||||
printf("DEBUG: run_state from %s to %s\n",
|
||||
run_state_name(run_state),
|
||||
run_state_name(RUN_RCFILES));
|
||||
run_state = RUN_RCFILES;
|
||||
runrcfiles();
|
||||
}
|
||||
if (conf->calc_debug & CALCDBG_RUNSTATE)
|
||||
printf("DEBUG: run_state from %s to %s\n",
|
||||
run_state_name(run_state),
|
||||
run_state_name(RUN_PRE_CMD_ARGS));
|
||||
run_state = RUN_PRE_CMD_ARGS;
|
||||
}
|
||||
|
||||
@@ -252,25 +284,46 @@ main(int argc, char **argv)
|
||||
if (inputlevel() == 0) {
|
||||
closeinput();
|
||||
runrcfiles();
|
||||
if (conf->calc_debug & CALCDBG_RUNSTATE)
|
||||
printf("DEBUG: run_state from %s to %s\n",
|
||||
run_state_name(run_state),
|
||||
run_state_name(RUN_PRE_CMD_ARGS));
|
||||
run_state = RUN_PRE_CMD_ARGS;
|
||||
} else {
|
||||
closeinput();
|
||||
}
|
||||
} else {
|
||||
if ((havecommands && !i_flag) || !stdin_tty)
|
||||
if ((havecommands && !i_flag) || !stdin_tty) {
|
||||
if (conf->calc_debug & CALCDBG_RUNSTATE)
|
||||
printf("DEBUG: run_state from %s to %s\n",
|
||||
run_state_name(run_state),
|
||||
run_state_name(RUN_EXIT_WITH_ERROR));
|
||||
run_state = RUN_EXIT_WITH_ERROR;
|
||||
else
|
||||
} else {
|
||||
if (conf->calc_debug & CALCDBG_RUNSTATE)
|
||||
printf("DEBUG: run_state from %s to %s\n",
|
||||
run_state_name(run_state),
|
||||
run_state_name(RUN_PRE_CMD_ARGS));
|
||||
run_state = RUN_PRE_CMD_ARGS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (run_state == RUN_PRE_CMD_ARGS) {
|
||||
if (havecommands) {
|
||||
if (conf->calc_debug & CALCDBG_RUNSTATE)
|
||||
printf("DEBUG: run_state from %s to %s\n",
|
||||
run_state_name(run_state),
|
||||
run_state_name(RUN_CMD_ARGS));
|
||||
run_state = RUN_CMD_ARGS;
|
||||
(void) openstring(cmdbuf, (long) strlen(cmdbuf));
|
||||
getcommands(FALSE);
|
||||
closeinput();
|
||||
}
|
||||
if (conf->calc_debug & CALCDBG_RUNSTATE)
|
||||
printf("DEBUG: run_state from %s to %s\n",
|
||||
run_state_name(run_state),
|
||||
run_state_name(RUN_PRE_TOP_LEVEL));
|
||||
run_state = RUN_PRE_TOP_LEVEL;
|
||||
}
|
||||
|
||||
@@ -279,19 +332,36 @@ main(int argc, char **argv)
|
||||
if ((c_flag && !stoponerror) || stoponerror < 0) {
|
||||
getcommands(FALSE);
|
||||
if (inputlevel() == 0)
|
||||
if (conf->calc_debug & CALCDBG_RUNSTATE)
|
||||
printf("DEBUG: run_state from %s to %s\n",
|
||||
run_state_name(run_state),
|
||||
run_state_name(RUN_PRE_TOP_LEVEL));
|
||||
run_state = RUN_PRE_TOP_LEVEL;
|
||||
closeinput();
|
||||
} else {
|
||||
closeinput();
|
||||
if (!stdin_tty || !i_flag || p_flag)
|
||||
if (!stdin_tty || !i_flag || p_flag) {
|
||||
if (conf->calc_debug & CALCDBG_RUNSTATE)
|
||||
printf("DEBUG: run_state from %s to %s\n",
|
||||
run_state_name(run_state),
|
||||
run_state_name(RUN_EXIT_WITH_ERROR));
|
||||
run_state = RUN_EXIT_WITH_ERROR;
|
||||
else
|
||||
} else {
|
||||
if (conf->calc_debug & CALCDBG_RUNSTATE)
|
||||
printf("DEBUG: run_state from %s to %s\n",
|
||||
run_state_name(run_state),
|
||||
run_state_name(RUN_PRE_TOP_LEVEL));
|
||||
run_state = RUN_PRE_TOP_LEVEL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (run_state == RUN_PRE_TOP_LEVEL) {
|
||||
if (stdin_tty && ((havecommands && !i_flag) || p_flag)) {
|
||||
if (conf->calc_debug & CALCDBG_RUNSTATE)
|
||||
printf("DEBUG: run_state from %s to %s\n",
|
||||
run_state_name(run_state),
|
||||
run_state_name(RUN_EXIT));
|
||||
run_state = RUN_EXIT;
|
||||
} else {
|
||||
if (stdin_tty) {
|
||||
@@ -300,6 +370,10 @@ main(int argc, char **argv)
|
||||
resetinput();
|
||||
openterminal();
|
||||
}
|
||||
if (conf->calc_debug & CALCDBG_RUNSTATE)
|
||||
printf("DEBUG: run_state from %s to %s\n",
|
||||
run_state_name(run_state),
|
||||
run_state_name(RUN_TOP_LEVEL));
|
||||
run_state = RUN_TOP_LEVEL;
|
||||
getcommands(TRUE);
|
||||
}
|
||||
@@ -315,6 +389,10 @@ main(int argc, char **argv)
|
||||
reinitialize();
|
||||
getcommands(TRUE);
|
||||
} else {
|
||||
if (conf->calc_debug & CALCDBG_RUNSTATE)
|
||||
printf("DEBUG: run_state from %s to %s\n",
|
||||
run_state_name(run_state),
|
||||
run_state_name(RUN_EXIT_WITH_ERROR));
|
||||
run_state = RUN_EXIT_WITH_ERROR;
|
||||
}
|
||||
}
|
||||
|
2
calc.h
2
calc.h
@@ -123,6 +123,7 @@ extern void resetinput(void);
|
||||
extern void setprompt(char *);
|
||||
extern BOOL inputisterminal(void);
|
||||
extern int inputlevel(void);
|
||||
extern long calclevel(void);
|
||||
extern char *inputname(void);
|
||||
extern long linenumber(void);
|
||||
extern void runrcfiles(void);
|
||||
@@ -207,6 +208,7 @@ typedef enum {
|
||||
RUN_EXIT_WITH_ERROR = 7 /* exit with error */
|
||||
} run;
|
||||
extern run run_state;
|
||||
extern char *run_state_name(run state);
|
||||
|
||||
/*
|
||||
* calc version information
|
||||
|
54
calc.man
54
calc.man
@@ -15,17 +15,19 @@ calc \- arbitrary precision calculator
|
||||
.RB [ \-c ]
|
||||
.RB [ \-C ]
|
||||
.RB [ \-d ]
|
||||
.RB [ -D\ \&calc_debug[:lib_debug:[user_debug]] ]
|
||||
.br
|
||||
.in +5n
|
||||
.RB [ \-e ]
|
||||
.RB [ \-h ]
|
||||
.RB [ \-i ]
|
||||
.RB [ \-m\ \&mode ]
|
||||
.br
|
||||
.in +5n
|
||||
.RB [ \-n ]
|
||||
.RB [ \-p ]
|
||||
.RB [ \-q ]
|
||||
.RB [ \-u ]
|
||||
.RB [ \-v ]
|
||||
.br
|
||||
.RB [ calc_cmd\ \&.\|.\|. ]
|
||||
.in -5n
|
||||
.SH DESCRIPTION
|
||||
@@ -62,6 +64,13 @@ cause
|
||||
.B calc
|
||||
to try to process each line being read
|
||||
despite the errors that it encounters.
|
||||
.sp 1
|
||||
By default, calc startup scripts ($CALCRC) are silently
|
||||
ignored if not found.
|
||||
This flag will report missing
|
||||
startup scripts unless
|
||||
.B \-d
|
||||
is also given.
|
||||
|
||||
.TP
|
||||
.B \-C
|
||||
@@ -112,6 +121,36 @@ It's nearly ten past six.
|
||||
.fi
|
||||
.in -5n
|
||||
.sp 1
|
||||
This flag disables the reporting of missing calc
|
||||
startup scripts ($CALCRC).
|
||||
|
||||
.TP
|
||||
.BR -D " calc_debug[:lib_debug:[user_debug]]"
|
||||
Force the initial value of config("calc_debug"),
|
||||
config("lib_debug") and config("user_debug").
|
||||
.sp 1
|
||||
The : separated strings are interpreted as signed 32 bit values.
|
||||
After an optional leading sign a leading zero indicates octal
|
||||
conversion, and a leading ``0x'' or ``0X'' hexadecimal
|
||||
conversion. Otherwise, decimal conversion is assumed.
|
||||
.sp 1
|
||||
By default,
|
||||
.I calc_debug
|
||||
is 0,
|
||||
.I lib_debug
|
||||
is 3 and
|
||||
.I lib_debug
|
||||
is 0.
|
||||
.sp 1
|
||||
For more information use the following
|
||||
.B calc
|
||||
command:
|
||||
.sp 1
|
||||
.in +5n
|
||||
.nf
|
||||
help config
|
||||
.fi
|
||||
.in -5n
|
||||
|
||||
.TP
|
||||
.B \-e
|
||||
@@ -173,7 +212,8 @@ This flag sets the permission mode of
|
||||
It controls the ability for
|
||||
.B calc
|
||||
to open files and execute programs.
|
||||
Mode may be a number from 0 to 7.
|
||||
.I Mode
|
||||
may be a number from 0 to 7.
|
||||
.sp 1
|
||||
The mode value is interpreted in a way similar to that
|
||||
of the
|
||||
@@ -196,8 +236,8 @@ octal mode:
|
||||
If one wished to run
|
||||
.B calc
|
||||
from a privileged user, one might want to use
|
||||
.B \-m
|
||||
0 in an effort to make
|
||||
.BR \-m " 0"
|
||||
in an effort to make
|
||||
.B calc
|
||||
somewhat more secure.
|
||||
.sp 1
|
||||
@@ -205,8 +245,8 @@ Mode bits for reading and writing apply only on an
|
||||
open.
|
||||
Files already open are not effected.
|
||||
Thus if one wanted to use the
|
||||
.B \-m
|
||||
0 in an effort to make
|
||||
.BR \-m " 0"
|
||||
in an effort to make
|
||||
.B calc
|
||||
somewhat more secure, but still wanted to read and write a specific
|
||||
file, one might want to do in
|
||||
|
@@ -409,6 +409,7 @@ getdeclarations(int symtype)
|
||||
case T_NEWLINE:
|
||||
case T_SEMICOLON:
|
||||
case T_RIGHTBRACE:
|
||||
case T_EOF:
|
||||
rescantoken();
|
||||
return;
|
||||
|
||||
|
71
config.c
71
config.c
@@ -55,6 +55,7 @@ NAMETYPE configs[] = {
|
||||
{"lib_debug", CONFIG_LIB_DEBUG},
|
||||
{"calc_debug", CONFIG_CALC_DEBUG},
|
||||
{"user_debug", CONFIG_USER_DEBUG},
|
||||
{"verbose_quit",CONFIG_VERBOSE_QUIT},
|
||||
{NULL, 0}
|
||||
};
|
||||
|
||||
@@ -93,9 +94,10 @@ CONFIG oldstd = { /* backward compatible standard configuration */
|
||||
FALSE, /* skip duplicate block output lines */
|
||||
BLK_BASE_HEX, /* block octet print base */
|
||||
BLK_FMT_HD_STYLE, /* block output format */
|
||||
3, /* calc library debug level */
|
||||
0, /* internal calc debug level */
|
||||
0 /* user defined debug level */
|
||||
3, /* calc library debug level */
|
||||
0, /* user defined debug level */
|
||||
TRUE /* print Quit or abort executed messages */
|
||||
};
|
||||
CONFIG newstd = { /* new non-backward compatible configuration */
|
||||
MODE_INITIAL, /* current output mode */
|
||||
@@ -128,9 +130,10 @@ CONFIG newstd = { /* new non-backward compatible configuration */
|
||||
FALSE, /* skip duplicate block output lines */
|
||||
BLK_BASE_HEX, /* block octet print base */
|
||||
BLK_FMT_HD_STYLE, /* block output format */
|
||||
3, /* calc library debug level */
|
||||
0, /* internal calc debug level */
|
||||
0 /* user defined debug level */
|
||||
3, /* calc library debug level */
|
||||
0, /* user defined debug level */
|
||||
TRUE /* print Quit or abort executed messages */
|
||||
};
|
||||
CONFIG *conf = NULL; /* loaded in at startup - current configuration */
|
||||
|
||||
@@ -806,20 +809,6 @@ setconfig(int type, VALUE *vp)
|
||||
conf->blkfmt = temp;
|
||||
break;
|
||||
|
||||
case CONFIG_LIB_DEBUG:
|
||||
if (vp->v_type != V_NUM) {
|
||||
math_error("Non numeric for lib_debug");
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
q = vp->v_num;
|
||||
temp = qtoi(q);
|
||||
if (qisfrac(q) || !zistiny(q->num)) {
|
||||
math_error("Illegal lib_debug parameter value");
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
conf->lib_debug = temp;
|
||||
break;
|
||||
|
||||
case CONFIG_CALC_DEBUG:
|
||||
if (vp->v_type != V_NUM) {
|
||||
math_error("Non numeric for calc_debug");
|
||||
@@ -834,6 +823,20 @@ setconfig(int type, VALUE *vp)
|
||||
conf->calc_debug = temp;
|
||||
break;
|
||||
|
||||
case CONFIG_LIB_DEBUG:
|
||||
if (vp->v_type != V_NUM) {
|
||||
math_error("Non numeric for lib_debug");
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
q = vp->v_num;
|
||||
temp = qtoi(q);
|
||||
if (qisfrac(q) || !zistiny(q->num)) {
|
||||
math_error("Illegal lib_debug parameter value");
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
conf->lib_debug = temp;
|
||||
break;
|
||||
|
||||
case CONFIG_USER_DEBUG:
|
||||
if (vp->v_type != V_NUM) {
|
||||
math_error("Non numeric for user_debug");
|
||||
@@ -848,6 +851,21 @@ setconfig(int type, VALUE *vp)
|
||||
conf->user_debug = temp;
|
||||
break;
|
||||
|
||||
case CONFIG_VERBOSE_QUIT:
|
||||
if (vp->v_type == V_NUM) {
|
||||
q = vp->v_num;
|
||||
conf->verbose_quit = !qiszero(q);
|
||||
} else if (vp->v_type == V_STR) {
|
||||
temp = truthtype(vp->v_str->s_str);
|
||||
if (temp < 0) {
|
||||
math_error("Illegal truth value"
|
||||
"for verbose_quit");
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
conf->verbose_quit = (int)temp;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
math_error("Setting illegal config parameter");
|
||||
/*NOTREACHED*/
|
||||
@@ -1107,18 +1125,22 @@ config_value(CONFIG *cfg, int type, VALUE *vp)
|
||||
i = cfg->blkfmt;
|
||||
break;
|
||||
|
||||
case CONFIG_LIB_DEBUG:
|
||||
i = cfg->lib_debug;
|
||||
break;
|
||||
|
||||
case CONFIG_CALC_DEBUG:
|
||||
i = cfg->calc_debug;
|
||||
break;
|
||||
|
||||
case CONFIG_LIB_DEBUG:
|
||||
i = cfg->lib_debug;
|
||||
break;
|
||||
|
||||
case CONFIG_USER_DEBUG:
|
||||
i = cfg->user_debug;
|
||||
break;
|
||||
|
||||
case CONFIG_VERBOSE_QUIT:
|
||||
i = cfg->verbose_quit;
|
||||
break;
|
||||
|
||||
default:
|
||||
math_error("Getting illegal CONFIG element");
|
||||
/*NOTREACHED*/
|
||||
@@ -1192,7 +1214,8 @@ config_cmp(CONFIG *cfg1, CONFIG *cfg2)
|
||||
cfg1->blkverbose != cfg2->blkverbose ||
|
||||
cfg1->blkbase != cfg2->blkbase ||
|
||||
cfg1->blkfmt != cfg2->blkfmt ||
|
||||
cfg1->lib_debug != cfg2->lib_debug ||
|
||||
cfg1->calc_debug != cfg2->calc_debug ||
|
||||
cfg1->user_debug != cfg2->user_debug;
|
||||
cfg1->lib_debug != cfg2->lib_debug ||
|
||||
cfg1->user_debug != cfg2->user_debug ||
|
||||
cfg1->verbose_quit != cfg2->verbose_quit;
|
||||
}
|
||||
|
25
config.h
25
config.h
@@ -80,6 +80,7 @@
|
||||
#define CONFIG_LIB_DEBUG 30
|
||||
#define CONFIG_CALC_DEBUG 31
|
||||
#define CONFIG_USER_DEBUG 32
|
||||
#define CONFIG_VERBOSE_QUIT 33
|
||||
|
||||
|
||||
/*
|
||||
@@ -114,8 +115,8 @@ struct config {
|
||||
LEN sq2; /* size of number to use square algorithm 2 */
|
||||
LEN pow2; /* size of modulus to use REDC for powers */
|
||||
LEN redc2; /* size of modulus to use REDC algorithm 2 */
|
||||
int tilde_ok; /* ok to print a tilde on aproximations */
|
||||
int tab_ok; /* ok to print tab before numeric values */
|
||||
BOOL tilde_ok; /* ok to print a tilde on aproximations */
|
||||
BOOL tab_ok; /* ok to print tab before numeric values */
|
||||
long quomod; /* quomod() default rounding mode */
|
||||
long quo; /* quotent // default rounding mode */
|
||||
long mod; /* mod % default rounding mode */
|
||||
@@ -125,18 +126,19 @@ struct config {
|
||||
long cfsim; /* cfsim() default rounding mode */
|
||||
long outround; /* output default rounding mode */
|
||||
long round; /* round()/bround() default rounding mode */
|
||||
int leadzero; /* ok to print leading 0 before decimal pt */
|
||||
int fullzero; /* ok to print trailing 0's */
|
||||
BOOL leadzero; /* ok to print leading 0 before decimal pt */
|
||||
BOOL fullzero; /* ok to print trailing 0's */
|
||||
long maxscancount; /* max scan errors before abort */
|
||||
char *prompt1; /* normal prompt */
|
||||
char *prompt2; /* prompt when inside multi-line input */
|
||||
int blkmaxprint; /* octets of a block to print, 0 => all */
|
||||
int blkverbose; /* TRUE => print all lines if a block */
|
||||
BOOL blkverbose; /* TRUE => print all lines if a block */
|
||||
int blkbase; /* block output base */
|
||||
int blkfmt; /* block output style */
|
||||
int lib_debug; /* library debug, see LIB_DEBUG_XXX below */
|
||||
int calc_debug; /* internal debug, see CALC_DEBUG_XXX below */
|
||||
int user_debug; /* user defined debug value: 0 default */
|
||||
long calc_debug; /* internal debug, see CALC_DEBUG_XXX below */
|
||||
long lib_debug; /* library debug, see LIB_DEBUG_XXX below */
|
||||
long user_debug; /* user defined debug value: 0 default */
|
||||
BOOL verbose_quit; /* TRUE => print Quit or abort executed msg */
|
||||
};
|
||||
typedef struct config CONFIG;
|
||||
|
||||
@@ -156,7 +158,9 @@ typedef struct config CONFIG;
|
||||
#define CALCDBG_FUNC_QUIT (0x00000002) /* active functions when quit */
|
||||
#define CALCDBG_HASH_STATE (0x00000004) /* hash state details */
|
||||
#define CALCDBG_BLOCK (0x00000008) /* block debug */
|
||||
#define CALCDBG_MASK (0x0000000f)
|
||||
#define CALCDBG_TTY (0x00000010) /* report TTY state changes */
|
||||
#define CALCDBG_RUNSTATE (0x00000020) /* report run_state changes */
|
||||
#define CALCDBG_MASK (0x0000003f)
|
||||
|
||||
|
||||
/*
|
||||
@@ -165,6 +169,9 @@ typedef struct config CONFIG;
|
||||
extern CONFIG *conf; /* current configuration */
|
||||
extern CONFIG oldstd; /* backward compatible standard configuration */
|
||||
extern CONFIG newstd; /* new non-backward compatible configuration */
|
||||
extern char *calc_debug; /* !=NULL => value of config("calc_debug") */
|
||||
extern char *lib_debug; /* !=NULL => value of config("lib_debug") */
|
||||
extern char *user_debug; /* !=NULL => value of config("user_debug") */
|
||||
|
||||
|
||||
/*
|
||||
|
@@ -1,5 +1,5 @@
|
||||
#
|
||||
# Copyright (c) 1997 Landon Curt Noll
|
||||
# Copyright (c) 1999 Landon Curt Noll
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and
|
||||
# its documentation for any purpose and without fee is hereby granted,
|
||||
@@ -44,8 +44,19 @@ calc library standards and guidelines.
|
||||
|
||||
=-=
|
||||
|
||||
argv.cal
|
||||
|
||||
argv(var, ...)
|
||||
|
||||
print information about various args
|
||||
|
||||
halflen.cal
|
||||
|
||||
halflen(num)
|
||||
|
||||
Calculate the length of a numeric value in HALF's.
|
||||
|
||||
pzasusb8.cal
|
||||
|
||||
Run custom("pzasusb8") on a standard set of data, print Endian
|
||||
related information and print value size information.
|
||||
|
@@ -38,17 +38,17 @@ Step 1: Do some background work
|
||||
you look at some examples of custom functions. Check out
|
||||
the following source files:
|
||||
|
||||
../custom.c
|
||||
custom.h
|
||||
custtbl.c
|
||||
c_*.[ch]
|
||||
../help/custom
|
||||
custom.c
|
||||
custom/custom.h
|
||||
custom/custtbl.c
|
||||
custom/c_*.[ch]
|
||||
help/custom (or run: calc help custom)
|
||||
|
||||
You would be well advised to look at a more recent calc source
|
||||
such as one available in from the calc alpha test archive.
|
||||
such as one available in from the calc version archive.
|
||||
See the following for more details:
|
||||
|
||||
../help/archive
|
||||
help/archive (or run: calc help archive)
|
||||
|
||||
|
||||
Step 2: Name your custom function
|
||||
@@ -604,3 +604,16 @@ Step 11: Install
|
||||
|
||||
Although calc does not run setuid, you may need to be root to install
|
||||
the directories into which calc installs may be write protected.
|
||||
|
||||
|
||||
Step 12: Contribute
|
||||
|
||||
Your custom function may be of interest to some people and/or
|
||||
serve as an example of what one can do with custom functions.
|
||||
|
||||
Read the file:
|
||||
|
||||
help/contrib (or run: calc help contrib)
|
||||
|
||||
and consider submitting your custom function for possible
|
||||
inclusion in later versions of calc.
|
||||
|
@@ -27,3 +27,5 @@ print "BIG_ENDIAN: ", custom("sysinfo", "BIG_ENDIAN");
|
||||
print "LITTLE_ENDIAN: ", custom("sysinfo", "LITTLE_ENDIAN");
|
||||
print "LONG_BITS: ", custom("sysinfo", "LONG_BITS");
|
||||
print "LONGLONG_BITS: ", custom("sysinfo", "LONGLONG_BITS");
|
||||
print "Calc sizes:";
|
||||
show sizes;
|
||||
|
22
func.c
22
func.c
@@ -155,6 +155,7 @@ f_eval(VALUE *vp)
|
||||
VALUE result;
|
||||
char *str;
|
||||
long num;
|
||||
int temp;
|
||||
|
||||
if (vp->v_type != V_STR)
|
||||
return error_value(E_EVAL2);
|
||||
@@ -168,7 +169,10 @@ f_eval(VALUE *vp)
|
||||
}
|
||||
oldfunc = curfunc;
|
||||
enterfilescope();
|
||||
temp = stoponerror;
|
||||
stoponerror = -1;
|
||||
if (evaluate(TRUE)) {
|
||||
stoponerror = temp;
|
||||
closeinput();
|
||||
exitfilescope();
|
||||
freevalue(stack--);
|
||||
@@ -181,6 +185,7 @@ f_eval(VALUE *vp)
|
||||
free(newfunc);
|
||||
return result;
|
||||
}
|
||||
stoponerror = temp;
|
||||
closeinput();
|
||||
exitfilescope();
|
||||
newfunc = curfunc;
|
||||
@@ -203,11 +208,11 @@ f_prompt(VALUE *vp)
|
||||
unsigned int len;
|
||||
|
||||
result.v_type = V_STR;
|
||||
if (inputisterminal()) {
|
||||
openterminal();
|
||||
printvalue(vp, PRINT_SHORT);
|
||||
math_flush();
|
||||
}
|
||||
cp = nextline();
|
||||
closeinput();
|
||||
if (cp == NULL) {
|
||||
math_error("End of file while prompting");
|
||||
/*NOTREACHED*/
|
||||
@@ -5893,6 +5898,17 @@ f_inputlevel (void)
|
||||
}
|
||||
|
||||
|
||||
static VALUE
|
||||
f_calclevel (void)
|
||||
{
|
||||
VALUE result;
|
||||
|
||||
result.v_type = V_NUM;
|
||||
result.v_num = itoq(calclevel());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
static VALUE
|
||||
f_access(int count, VALUE **vals)
|
||||
{
|
||||
@@ -6818,6 +6834,8 @@ 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"},
|
||||
{"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,
|
||||
|
@@ -105,29 +105,30 @@ BLT_HELP_FILES= ${BLT_HELP_FILES_3} ${BLT_HELP_FILES_5} \
|
||||
# This list is prodiced by the detaillist rule when no WARNINGS are detected.
|
||||
#
|
||||
DETAIL_HELP= abs access acos acosh acot acoth acsc acsch address agd append \
|
||||
appr arg arrow asec asech asin asinh assign atan atan2 atanh avg base \
|
||||
bit blk blkcpy blkfree blocks bround btrunc ceil cfappr cfsim char \
|
||||
cmdbuf cmp comb conj cos cosh cot coth count cp csc csch ctime delete \
|
||||
den dereference det digit digits dp epsilon errcount errmax errno \
|
||||
error 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 freeglobals freeredc freestatics frem \
|
||||
freopen fscan fscanf fseek fsize ftell gcd gcdrem gd getenv hash head \
|
||||
highbit hmean hnrmod hypot ilog ilog10 ilog2 im 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 sort sqrt srand \
|
||||
srandom ssq str strcat strerror strlen strpos strprintf strscan \
|
||||
strscanf substr sum swap system tail tan tanh test time trunc xor
|
||||
appr arg arrow asec asech asin asinh assign atan atan2 atanh avg \
|
||||
base bit blk blkcpy blkfree blocks bround btrunc calclevel ceil \
|
||||
cfappr cfsim char cmdbuf cmp comb conj cos cosh cot coth count cp \
|
||||
csc csch ctime delete den dereference det digit digits dp epsilon \
|
||||
errcount errmax errno error 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 freeglobals \
|
||||
freeredc freestatics frem freopen fscan fscanf fseek fsize ftell gcd \
|
||||
gcdrem gd getenv hash head highbit hmean hnrmod hypot ilog ilog10 \
|
||||
ilog2 im 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 sort sqrt srand srandom ssq str \
|
||||
strcat strerror strlen strpos strprintf strscan strscanf substr \
|
||||
sum swap system tail tan tanh test time trunc xor
|
||||
|
||||
# This list is of files that are clones of DETAIL_HELP files. They are
|
||||
# built from DETAIL_HELP files.
|
||||
@@ -416,8 +417,8 @@ bsdi: all
|
||||
detaillist:
|
||||
${Q}-(echo "xxxxx"; \
|
||||
for i in ${DETAIL_HELP}; do \
|
||||
if [ ! -f SCCS/s.$$i ]; then \
|
||||
echo "WARNING: $$i not under SCCS control" 1>&2; \
|
||||
if [ ! -f RCS/$$i,v ]; then \
|
||||
echo "WARNING: $$i not under RCS control" 1>&2; \
|
||||
else \
|
||||
echo $$i; \
|
||||
fi; \
|
||||
|
20
help/archive
20
help/archive
@@ -1,26 +1,14 @@
|
||||
Where to get the the latest versions of calc
|
||||
|
||||
Landon Noll maintains the official calc ftp archive at:
|
||||
|
||||
ftp://ftp.uu.net/pub/calc
|
||||
|
||||
Alpha test versions, complete with bugs, untested code and
|
||||
experimental features may be fetched (if you are brave) under:
|
||||
Landon Noll maintains the official calc home page at:
|
||||
|
||||
http://reality.sgi.com/chongo/tech/comp/calc/
|
||||
|
||||
One may join the calc testing group by sending a request to:
|
||||
See:
|
||||
|
||||
calc-tester-request@postofc.corp.sgi.com
|
||||
http://reality.sgi.com/chongo/tech/comp/calc/calc-download.html
|
||||
|
||||
Your message body (not the subject) should consist of:
|
||||
|
||||
subscribe calc-tester address
|
||||
end
|
||||
name your_full_name
|
||||
|
||||
where "address" is your EMail address and "your_full_name"
|
||||
is your full name.
|
||||
for information on how to obtain up a recent version of calc.
|
||||
|
||||
Landon Curt Noll
|
||||
http://reality.sgi.com/chongo
|
||||
|
35
help/calclevel
Normal file
35
help/calclevel
Normal file
@@ -0,0 +1,35 @@
|
||||
NAME
|
||||
calclevel - current calculation level
|
||||
|
||||
SYNOPSIS
|
||||
calclevel()
|
||||
|
||||
TYPES
|
||||
return nonnegative integer
|
||||
|
||||
DESCRIPTION
|
||||
This function returns the calculation level at which it is called.
|
||||
When a command is being read from a terminal or from a file,
|
||||
calc is at calculation level zero. The level is increased
|
||||
by 1 each time calculation starts of a user-defined function
|
||||
or of eval(S) for some expression S which evaluates to a string. It
|
||||
decreases to zero if an error occurs or a quit or abort statement
|
||||
is executed. Otherwise, it decreases by 1 when the calculation
|
||||
is completed. Except when an error occurs or abort is executed,
|
||||
the input level is not affected by changes in the calculation level.
|
||||
|
||||
Zero calculation level is also called top calculation level; greater
|
||||
values of calclevel() indicate calculation is occurring at greater
|
||||
depths.
|
||||
|
||||
EXAMPLE
|
||||
n/a
|
||||
|
||||
LIMITS
|
||||
none
|
||||
|
||||
LIBRARY
|
||||
none
|
||||
|
||||
SEE ALSO
|
||||
eval, read, quit, abort, inputlevel
|
74
help/config
74
help/config
@@ -40,9 +40,10 @@ Configuration parameters
|
||||
"blkverbose" TRUE=>print all lines, FALSE=>skip duplicates
|
||||
"blkbase" block output base
|
||||
"blkfmt" block output format
|
||||
"lib_debug" controls library script debug information
|
||||
"calc_debug" controls internal calc debug information
|
||||
"lib_debug" controls library script debug information
|
||||
"user_debug" for user defined debug information
|
||||
"verbose_quit" TRUE=>print message on empty quit or abort
|
||||
|
||||
|
||||
The "all" config value allows one to save/restore the configuration
|
||||
@@ -316,29 +317,6 @@ Configuration parameters
|
||||
|
||||
The default "blkfmt" is "hd".
|
||||
|
||||
The "lib_debug" parameter is intended for controlling the possible
|
||||
display of special information relating to functions, objects, and
|
||||
other structures created by instructions in calc scripts.
|
||||
Zero value of config("lib_debug") means that no such information
|
||||
is displayed. For other values, the non-zero bits which currently
|
||||
have meanings are as follows:
|
||||
|
||||
n Meaning of bit n of config("lib_debug")
|
||||
|
||||
0 When a function is defined, redefined or undefined at
|
||||
interactive level, a message saying what has been done
|
||||
is displayed.
|
||||
|
||||
1 When a function is defined, redefined or undefined during
|
||||
the reading of a file, a message saying what has been done
|
||||
is displayed.
|
||||
|
||||
The value for config("lib_debug") in both oldstd and newstd is 3,
|
||||
but if calc is invoked with the -d flag, its initial value is zero.
|
||||
Thus, if calc is started without the -d flag, until config("lib_debug")
|
||||
is changed, a message will be output when a function is defined
|
||||
either interactively or during the reading of a file.
|
||||
|
||||
The "calc_debug" is intended for controlling internal calc routines
|
||||
that test its operation, or collect or display information that
|
||||
might be useful for debug purposes. Much of the output from these
|
||||
@@ -363,7 +341,42 @@ Configuration parameters
|
||||
block is not NULL, and that its "length" is not negative.
|
||||
A failure will result in a runtime error.
|
||||
|
||||
Bits >= 4 are reserved for future use and should not be used at this time.
|
||||
4 Report on changes to the state of stdin as well as changes
|
||||
to internal variables that control the setting and restoring
|
||||
of stdin.
|
||||
|
||||
5 Report on changes to the run state of calc.
|
||||
|
||||
Bits >= 6 are reserved for future use and should not be used at this time.
|
||||
|
||||
By default, "calc_debug" is 0. The initial value may be overridden
|
||||
by the -D command line option.
|
||||
|
||||
The "lib_debug" parameter is intended for controlling the possible
|
||||
display of special information relating to functions, objects, and
|
||||
other structures created by instructions in calc scripts.
|
||||
Zero value of config("lib_debug") means that no such information
|
||||
is displayed. For other values, the non-zero bits which currently
|
||||
have meanings are as follows:
|
||||
|
||||
n Meaning of bit n of config("lib_debug")
|
||||
|
||||
0 When a function is defined, redefined or undefined at
|
||||
interactive level, a message saying what has been done
|
||||
is displayed.
|
||||
|
||||
1 When a function is defined, redefined or undefined during
|
||||
the reading of a file, a message saying what has been done
|
||||
is displayed.
|
||||
|
||||
The value for config("lib_debug") in both oldstd and newstd is 3,
|
||||
but if calc is invoked with the -d flag, its initial value is zero.
|
||||
Thus, if calc is started without the -d flag, until config("lib_debug")
|
||||
is changed, a message will be output when a function is defined
|
||||
either interactively or during the reading of a file.
|
||||
|
||||
By default, "lib_debug" is 3. The -d flag changes this default to 0.
|
||||
The initial value may be overridden by the -D command line option.
|
||||
|
||||
The "user_debug" is provided for use by users. Calc ignores this value
|
||||
other than to set it to 0 by default (for both "oldstd" and "newstd").
|
||||
@@ -375,6 +388,17 @@ Configuration parameters
|
||||
slower operation or more memory usage, and a particular value (like
|
||||
-1 or 0) corresponding to "no tests".
|
||||
|
||||
By default, "user_debug" is 0. The initial value may be overridden
|
||||
by the -D command line option.
|
||||
|
||||
The "verbose_quit" controls the print of the message:
|
||||
|
||||
Quit or abort executed
|
||||
|
||||
when a non-interactive quit or abort without an argument is encounted.
|
||||
A quit of abort without an argument does not display a message when
|
||||
invoked at the interactive level.
|
||||
|
||||
The following are synonyms for true:
|
||||
|
||||
"on" "yes" "y" "true" "t" "1" any non-zero number
|
||||
|
42
help/contrib
42
help/contrib
@@ -5,30 +5,27 @@ We welcome and encourage you to send us:
|
||||
* custom functions that you have modified or written
|
||||
* any other source code modifications
|
||||
|
||||
Prior to doing so, you should consider trying your changes on the most
|
||||
recent alpha test code. To obtain the most recent code, look under
|
||||
Prior to doing so, you should consider applying your changes to the most
|
||||
recent version of calc.
|
||||
|
||||
Landon Noll maintains the official calc home page at:
|
||||
|
||||
http://reality.sgi.com/chongo/tech/comp/calc/
|
||||
|
||||
You should also consider joining the calc testing group by sending a
|
||||
request to:
|
||||
See:
|
||||
|
||||
calc-tester-request@postofc.corp.sgi.com
|
||||
http://reality.sgi.com/chongo/tech/comp/calc/calc-download.html
|
||||
|
||||
Your message body (not the subject) should consist of:
|
||||
for information on how to obtain up a recent version of calc.
|
||||
|
||||
subscribe calc-tester address
|
||||
end
|
||||
name your_full_name
|
||||
|
||||
where "address" is your EMail address and "your_full_name"
|
||||
is your full name.
|
||||
=-=
|
||||
|
||||
In order to consider integrating your code, we need:
|
||||
|
||||
* help files (documentation)
|
||||
* CHANGES text (brief description of what it does)
|
||||
* regress.cal test (to test non-custom code)
|
||||
* the calc version you are working with (use the latest calc, see above)
|
||||
* new help files or help file patches, if applicable (documentation)
|
||||
* proposed text for the CHANGES file (brief description of what it does)
|
||||
* regress.cal test patch, if applicable
|
||||
* your source code and/or source code changes (:-))
|
||||
|
||||
The best way to send us new code, if your changes are small, is
|
||||
@@ -45,6 +42,21 @@ Thanks for considering submitting code to calc. Calc is a collective
|
||||
work by a number of people. It would not be what it is today without
|
||||
your efforts and submissions!
|
||||
|
||||
=-=
|
||||
|
||||
One may join the calc testing group by sending a request to:
|
||||
|
||||
calc-tester-request@postofc.corp.sgi.com
|
||||
|
||||
Your message body (not the subject) should consist of:
|
||||
|
||||
subscribe calc-tester address
|
||||
end
|
||||
name your_full_name
|
||||
|
||||
where "address" is your EMail address and "your_full_name"
|
||||
is your full name.
|
||||
|
||||
Landon Curt Noll
|
||||
http://reality.sgi.com/chongo
|
||||
|
||||
|
39
help/credit
39
help/credit
@@ -22,41 +22,10 @@ Credits
|
||||
|
||||
Most of this source and binary has one of the following copyrights:
|
||||
|
||||
Copyright (c) 19xx David I. Bell
|
||||
Copyright (c) 19xx David I. Bell and Landon Curt Noll
|
||||
Copyright (c) 19xx Landon Curt Noll
|
||||
Copyright (c) 19xx Ernest Bowen and Landon Curt Noll
|
||||
Copyright (c) year David I. Bell
|
||||
Copyright (c) year David I. Bell and Landon Curt Noll
|
||||
Copyright (c) year Landon Curt Noll
|
||||
Copyright (c) year Ernest Bowen and Landon Curt Noll
|
||||
|
||||
Permission is granted to use, distribute, or modify this source,
|
||||
provided that this copyright notice remains intact.
|
||||
|
||||
Send calc comments, suggestions, bug fixes, enhancements and
|
||||
interesting calc scripts that you would like you see included in
|
||||
future distributions to:
|
||||
|
||||
calc-tester@postofc.corp.sgi.com
|
||||
|
||||
Landon Noll maintains the official calc http/ftp archive at:
|
||||
|
||||
ftp://reality.sgi.com/users/chongo/src/calc
|
||||
http://reality.sgi.com/chongo/src/calc/
|
||||
|
||||
Alpha test versions, complete with bugs, untested code and
|
||||
experimental features may be fetched (if you are brave) under:
|
||||
|
||||
http://reality.sgi.com/chongo/tech/comp/calc/
|
||||
|
||||
One may join the calc testing group by sending a request to:
|
||||
|
||||
calc-tester-request@postofc.corp.sgi.com
|
||||
|
||||
Your message body (not the subject) should consist of:
|
||||
|
||||
subscribe calc-tester address
|
||||
end
|
||||
name your_full_name
|
||||
|
||||
where "address" is your EMail address and "your_full_name"
|
||||
is your full name.
|
||||
|
||||
Enjoy!
|
||||
|
36
help/inputlevel
Normal file
36
help/inputlevel
Normal file
@@ -0,0 +1,36 @@
|
||||
NAME
|
||||
inputlevel - current input level
|
||||
|
||||
SYNOPSIS
|
||||
inputlevel()
|
||||
|
||||
TYPES
|
||||
return nonnegative integer
|
||||
|
||||
DESCRIPTION
|
||||
This function returns the input level at which it is called.
|
||||
When calc starts, it is at level zero. The level is increased
|
||||
by 1 each time execution starts of a read file command or a call to
|
||||
eval(S) for some expression S which evaluates to a string. It
|
||||
decreases by 1 when a file being read reaches EOF or a string
|
||||
being eval-ed reaches '\0', or earlier if a quit statement is
|
||||
encountered at top calculation-level in the flle or string. It
|
||||
decreases to zero if an abort statement is encountered at any
|
||||
function-level in the file or string. If a quit or abort
|
||||
statement is encountered at top calculation-level at top input-level,
|
||||
calc is exited.
|
||||
|
||||
Zero input level is also called top input level; greater values
|
||||
of inputlevel() indicate reading at greater depths.
|
||||
|
||||
EXAMPLE
|
||||
n/a
|
||||
|
||||
LIMITS
|
||||
none
|
||||
|
||||
LIBRARY
|
||||
none
|
||||
|
||||
SEE ALSO
|
||||
read, eval, quit, abort, calclevel
|
@@ -71,6 +71,10 @@
|
||||
|
||||
help stdlib
|
||||
|
||||
To learn how to invoke the calc command and about calc -flags, try:
|
||||
|
||||
help usage
|
||||
|
||||
A full and extensive overview of calc may be obtained by:
|
||||
|
||||
help full
|
||||
@@ -160,5 +164,3 @@
|
||||
These can contain both functions to be defined, and expressions
|
||||
to be calculated. Global variables which are numbers can be
|
||||
saved to a file by using the 'write filename' command.
|
||||
|
||||
XXX - update this file and add in new major features
|
||||
|
30
help/todo
30
help/todo
@@ -13,14 +13,40 @@ Calc Todo Items:
|
||||
|
||||
Very High priority items:
|
||||
|
||||
* Write the help file for the inputlevel() builtin function.
|
||||
|
||||
* Write the help file for the display() builtin function.
|
||||
|
||||
* Write the help file for the stoponerror() builtin function.
|
||||
|
||||
* Update the errmax about the meaning of errmax(-1).
|
||||
|
||||
* Review and if needed, correct/update the help topics:
|
||||
|
||||
topic description
|
||||
----- -----------
|
||||
intro introduction to calc
|
||||
overview overview of calc
|
||||
assoc using associations
|
||||
command top level commands
|
||||
config configuration parameters
|
||||
define how to define functions
|
||||
environment how environment variables effect calc
|
||||
errorcodes calc generated error codes
|
||||
expression expression sequences
|
||||
file using files
|
||||
history command history
|
||||
interrupt how interrupts are handled
|
||||
list using lists
|
||||
mat using matrices
|
||||
obj user defined data types
|
||||
operator math, relational, logic and variable access ...
|
||||
statement flow control and declaration statements
|
||||
types builtin data types
|
||||
unexpected unexpected syntax/usage surprises for C ...
|
||||
variable variables and variable declarations
|
||||
libcalc using the arbitrary precision routines in ...
|
||||
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'.
|
||||
|
||||
|
27
help/usage
27
help/usage
@@ -2,8 +2,8 @@ Calc command line
|
||||
|
||||
Calc has the following command line:
|
||||
|
||||
calc [-c] [-C] [-d] [-e] [-h] [-i] [-m mode]
|
||||
[-n] [-p] [-q] [-u] [-v] [calc_cmd ...]
|
||||
calc [-c] [-C] [-d] [-D calc_debug[:lib_debug:[user_debug]]]
|
||||
[-e] [-h] [-i] [-m mode] [-n] [-p] [-q] [-u] [-v] [calc_cmd ...]
|
||||
|
||||
-c Continue reading command lines even after an execution
|
||||
error has caused the abandonment of a line.
|
||||
@@ -19,6 +19,10 @@ Calc command line
|
||||
will cause calc to try to process each line being read
|
||||
despite the errors that it encounters.
|
||||
|
||||
By default, calc startup scripts ($CALCRC) are silently
|
||||
ignored if not found. This flag will report missing
|
||||
startup scripts unless -d is also given.
|
||||
|
||||
-C Permit the execution of custom builtin functions. Without
|
||||
this flag, calling the custom() builtin function will
|
||||
simply generate an error.
|
||||
@@ -48,6 +52,25 @@ Calc command line
|
||||
|
||||
It's nearly ten past six.
|
||||
|
||||
This flag disables the reporting of missing calc
|
||||
startup scripts ($CALCRC).
|
||||
|
||||
-D calc_debug[:lib_debug:[user_debug]]
|
||||
|
||||
Force the initial value of config("calc_debug"),
|
||||
config("lib_debug") and config("user_debug").
|
||||
|
||||
The : separated strings are interpreted as signed 32 bit values.
|
||||
After an optional leading sign a leading zero indicates octal
|
||||
conversion, and a leading ``0x'' or ``0X'' hexadecimal
|
||||
conversion. Otherwise, decimal conversion is assumed.
|
||||
|
||||
By default, calc_debug is 0, lib_debug is 3 and lib_debug is 0.
|
||||
|
||||
For more information use the following calc command:
|
||||
|
||||
help config
|
||||
|
||||
-e Ignore any environment variables on startup. The
|
||||
getenv() builtin will still return values, however.
|
||||
|
||||
|
63
hist.c
63
hist.c
@@ -283,11 +283,16 @@ hist_init(char *filename)
|
||||
{
|
||||
TTYSTRUCT newtty;
|
||||
|
||||
if (inited)
|
||||
if (inited) {
|
||||
if (conf->calc_debug & CALCDBG_TTY)
|
||||
printf("DEBUG: inited already set in hist_init\n");
|
||||
return HIST_INITED;
|
||||
}
|
||||
|
||||
inited = 1;
|
||||
canedit = 0;
|
||||
if (conf->calc_debug & CALCDBG_TTY)
|
||||
printf("DEBUG: Set inited, cleared canedit in hist_init\n");
|
||||
|
||||
/*
|
||||
* open the bindings file
|
||||
@@ -309,20 +314,31 @@ hist_init(char *filename)
|
||||
closeinput();
|
||||
|
||||
#ifdef USE_SGTTY
|
||||
if (ioctl(STDIN, TIOCGETP, &oldtty) < 0)
|
||||
if (ioctl(STDIN, TIOCGETP, &oldtty) < 0) {
|
||||
if (conf->calc_debug & CALCDBG_TTY)
|
||||
printf("DEBUG: Cannot TIOCGETP stdin in hist_init\n");
|
||||
return HIST_NOTTY;
|
||||
}
|
||||
|
||||
newtty = oldtty;
|
||||
newtty.sg_flags &= ~ECHO;
|
||||
newtty.sg_flags |= CBREAK;
|
||||
|
||||
if (ioctl(STDIN, TIOCSETP, &newtty) < 0)
|
||||
if (ioctl(STDIN, TIOCSETP, &newtty) < 0) {
|
||||
if (conf->calc_debug & CALCDBG_TTY)
|
||||
printf("DEBUG: Cannot TIOCSETP stdin in hist_init\n");
|
||||
return HIST_NOTTY;
|
||||
}
|
||||
if (conf->calc_debug & CALCDBG_TTY)
|
||||
printf("DEBUG: stty -ECHO +CBREAK in hist_init\n");
|
||||
#endif
|
||||
|
||||
#ifdef USE_TERMIO
|
||||
if (ioctl(STDIN, TCGETA, &oldtty) < 0)
|
||||
if (ioctl(STDIN, TCGETA, &oldtty) < 0) {
|
||||
if (conf->calc_debug & CALCDBG_TTY)
|
||||
printf("DEBUG: Cannot TCGETA stdin in hist_init\n");
|
||||
return HIST_NOTTY;
|
||||
}
|
||||
|
||||
newtty = oldtty;
|
||||
newtty.c_lflag &= ~(ECHO | ECHOE | ECHOK);
|
||||
@@ -331,13 +347,22 @@ hist_init(char *filename)
|
||||
newtty.c_cc[VMIN] = 1;
|
||||
newtty.c_cc[VTIME] = 0;
|
||||
|
||||
if (ioctl(STDIN, TCSETAW, &newtty) < 0)
|
||||
if (ioctl(STDIN, TCSETAW, &newtty) < 0) {
|
||||
if (conf->calc_debug & CALCDBG_TTY)
|
||||
printf("DEBUG: Cannot TCSETAW stdin in hist_init\n");
|
||||
return HIST_NOTTY;
|
||||
}
|
||||
if (conf->calc_debug & CALCDBG_TTY)
|
||||
printf("DEBUG: stty -ECHO -ECHOE -ECHOK -ICANON +ISTRIP "
|
||||
"VMIN=1 VTIME=0 in hist_init\n");
|
||||
#endif
|
||||
|
||||
#ifdef USE_TERMIOS
|
||||
if (tcgetattr(STDIN, &oldtty) < 0)
|
||||
if (tcgetattr(STDIN, &oldtty) < 0) {
|
||||
if (conf->calc_debug & CALCDBG_TTY)
|
||||
printf("DEBUG: Cannot tcgetattr stdin in hist_init\n");
|
||||
return HIST_NOTTY;
|
||||
}
|
||||
|
||||
newtty = oldtty;
|
||||
newtty.c_lflag &= ~(ECHO | ECHOE | ECHOK);
|
||||
@@ -346,11 +371,19 @@ hist_init(char *filename)
|
||||
newtty.c_cc[VMIN] = 1;
|
||||
newtty.c_cc[VTIME] = 0;
|
||||
|
||||
if (tcsetattr(STDIN, TCSANOW, &newtty) < 0)
|
||||
if (tcsetattr(STDIN, TCSANOW, &newtty) < 0) {
|
||||
if (conf->calc_debug & CALCDBG_TTY)
|
||||
printf("DEBUG: Cannot tcsetattr stdin in hist_init\n");
|
||||
return HIST_NOTTY;
|
||||
}
|
||||
if (conf->calc_debug & CALCDBG_TTY)
|
||||
printf("DEBUG: stty -ECHO -ECHOE -ECHOK -ICANON +ISTRIP "
|
||||
"VMIN=1 VTIME=0 in hist_init\n");
|
||||
#endif
|
||||
|
||||
canedit = 1;
|
||||
if (conf->calc_debug & CALCDBG_TTY)
|
||||
printf("DEBUG: Set canedit in hist_init\n");
|
||||
|
||||
return HIST_SUCCESS;
|
||||
}
|
||||
@@ -363,20 +396,36 @@ void
|
||||
hist_term(void)
|
||||
{
|
||||
if (!inited || !canedit) {
|
||||
if (conf->calc_debug & CALCDBG_TTY) {
|
||||
if (!inited)
|
||||
printf("DEBUG: inited already cleared "
|
||||
"in hist_term\n");
|
||||
if (!canedit)
|
||||
printf("DEBUG: canedit already cleared "
|
||||
"in hist_term\n");
|
||||
}
|
||||
inited = 0;
|
||||
if (conf->calc_debug & CALCDBG_TTY)
|
||||
printf("DEBUG: Cleared inited in hist_term\n");
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef USE_SGTTY
|
||||
(void) ioctl(STDIN, TIOCSETP, &oldtty);
|
||||
if (conf->calc_debug & CALCDBG_TTY)
|
||||
printf("DEBUG: TIOCSETP restored stdin in hist_term\n");
|
||||
#endif
|
||||
|
||||
#ifdef USE_TERMIO
|
||||
(void) ioctl(STDIN, TCSETAW, &oldtty);
|
||||
if (conf->calc_debug & CALCDBG_TTY)
|
||||
printf("DEBUG: TCSETAW restored stdin in hist_term\n");
|
||||
#endif
|
||||
|
||||
#ifdef USE_TERMIOS
|
||||
(void) tcsetattr(STDIN, TCSANOW, &oldtty);
|
||||
if (conf->calc_debug & CALCDBG_TTY)
|
||||
printf("DEBUG: TCSANOW restored stdin in hist_term\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@@ -44,7 +44,7 @@ CALC_FILES= README bigprime.cal deg.cal ellip.cal lucas.cal lucas_chk.cal \
|
||||
test2700.cal test3100.cal test3300.cal test3400.cal prompt.cal \
|
||||
test3500.cal seedrandom.cal test4000.cal test4100.cal test4600.cal \
|
||||
beer.cal hello.cal test5100.cal test5200.cal randombitrun.cal \
|
||||
randomrun.cal xx_print.cal natnumset.cal qtime.cal
|
||||
randomrun.cal xx_print.cal natnumset.cal qtime.cal test8400.cal
|
||||
|
||||
# These files are found (but not built) in the distribution
|
||||
#
|
||||
|
@@ -17,7 +17,7 @@ For example:
|
||||
|
||||
will cause calc to load and execute the 'lucas.cal' library.
|
||||
Executing the library will cause several functions to be defined.
|
||||
Executing the lucas function
|
||||
Executing the lucas function:
|
||||
|
||||
> lucas(149,60)
|
||||
1
|
||||
|
@@ -30,6 +30,7 @@ ecnt = 0; /* clear expected errcount() value */
|
||||
initcfg = config("all", "oldstd"); /* set config to startup default */
|
||||
initcfg = config("lib_debug", 0); /* disable lib startup messages */
|
||||
initcfg = config("calc_debug", 0); /* disable internal debugging */
|
||||
initcnf = config("verbose_quit", 0); /* disable quit messages */
|
||||
initcfg = config("all"); /* save state for later use */
|
||||
|
||||
print '003: parsed global definitions';
|
||||
@@ -291,7 +292,7 @@ define test_arithmetic()
|
||||
vrfy(8/4==2, '404: 8 / 4 == 2');
|
||||
vrfy(2^3==8, '405: 2 ^ 3 == 8');
|
||||
vrfy(9-4-2==3, '406: 9-4-2 == 3');
|
||||
vrfy(9-4+2==7, '407: 9-4+2 == 6');
|
||||
vrfy(9-4+2==7, '407: 9-4+2 == 7');
|
||||
vrfy(-5+2==-3, '408: -5+2 == -3');
|
||||
vrfy(2*3+1==7, '409: 2*3+1 == 7');
|
||||
vrfy(1+2*3==7, '410: 1+2*3 == 7');
|
||||
@@ -964,7 +965,7 @@ define test_functions()
|
||||
vrfy(strpos(a, a) == 1, '948: strpos(a, a) == 1');
|
||||
vrfy(system("") == 0, '949: system("") == 0');
|
||||
vrfy(system("true") == 0, '950: system("true") == 0');
|
||||
vrfy(isatty(files(0)) == 1, '951: isatty(files(0)) == 1');
|
||||
print '951: test disabled due to stdin dependency';
|
||||
print '952: test removed';
|
||||
print '953: test removed';
|
||||
vrfy(isstr(cmdbuf()) == 1, '954: isstr(cmdbuf()) == 1');
|
||||
@@ -5106,7 +5107,7 @@ define test_is()
|
||||
vrfy(isatty(square) == 0, '5981: isatty(square) == 0');
|
||||
vrfy(isatty(string) == 0, '5982: isatty(string) == 0');
|
||||
vrfy(isatty(com) == 0, '5983: isatty(com) == 0');
|
||||
vrfy(isatty(files(0)) == 1, '5984: isatty(files(0)) == 1');
|
||||
print '5984: test disabled due to stdin dependency';
|
||||
/* if we pipe to awk (for make chk), stdout and stderr are not ttys */
|
||||
print '5985: test unused';
|
||||
print '5986: test unused';
|
||||
@@ -7120,9 +7121,11 @@ print '188: parsed test_natnumset()';
|
||||
/*
|
||||
* test_somenew - test some new features
|
||||
*/
|
||||
define func8200(x,y) {if (x>0) return calclevel()+func8200(x-1,y)-y; return 0;}
|
||||
print '189: define func8200(x,y)';
|
||||
define test_somenew()
|
||||
{
|
||||
local a, s;
|
||||
local a, s, y;
|
||||
|
||||
print '8200: Starting test_somenew';
|
||||
|
||||
@@ -7154,9 +7157,36 @@ define test_somenew()
|
||||
vrfy(hash("curds n whey") == 2376141927,
|
||||
'8219: hash("curds n whey") == 2376141927');
|
||||
|
||||
print '8220: Ending test_somenew';
|
||||
y = calclevel();
|
||||
print '8220: y = calclevel()';
|
||||
vrfy(func8200(0,y) == 0, '8221: func8200(0,y) == 0');
|
||||
vrfy(func8200(1,y) == 1, '8222: func8200(1,y) == 1');
|
||||
vrfy(func8200(10,y) == 55, '8223: func8200(10,y) == 55');
|
||||
vrfy(func8200(100,y) == 5050, '8224: func8200(100,y) == 5050');
|
||||
|
||||
vrfy(inputlevel() == 1, '8225: inputlevel() == 1');
|
||||
|
||||
print '8226: Ending test_somenew';
|
||||
}
|
||||
print '189: parsed test_somenew()';
|
||||
print '190: parsed test_somenew()';
|
||||
|
||||
|
||||
/*
|
||||
* test_quit - test the QUIT functionality
|
||||
*/
|
||||
define test_quit()
|
||||
{
|
||||
local x8400 = 23209; /* watch for lost memory */
|
||||
static s8400 = 21701; /* watch for lost memory */
|
||||
|
||||
print '8400: Starting test_quit';
|
||||
|
||||
quit;
|
||||
prob('quit did not end the test_quit() function');
|
||||
|
||||
/* 8400 serise continued after return, do not print end here */
|
||||
}
|
||||
print '191: parsed test_quit()';
|
||||
|
||||
|
||||
/*
|
||||
@@ -7442,6 +7472,17 @@ vrfy(l8300(10) == 15, '8309: l8300(10) == 15');
|
||||
print '8310: Ending define tests';
|
||||
|
||||
|
||||
/*
|
||||
* quit tests
|
||||
*/
|
||||
print;
|
||||
return test_quit();
|
||||
read -once test8400;
|
||||
print '8404: read -once test8400';
|
||||
vrfy(test8400() == 64434, '8405: test8400() == 64434');
|
||||
print '8406: Ending test_quit';
|
||||
|
||||
|
||||
/*
|
||||
* read various calc libs
|
||||
*
|
||||
@@ -7455,7 +7496,7 @@ print '8310: Ending define tests';
|
||||
* lucas_tbl.cal - duplicatres code already read by another file
|
||||
* regress.cal - this file
|
||||
* surd.cal - already read by this file
|
||||
* testXXXX.cal - already read by this file
|
||||
* test9999.cal - files of this form are already read by this file
|
||||
* xx_print.cal - prints a bunch of things when loaded
|
||||
*
|
||||
* We want to do this 2nd to last; ahead of any final cleanup and behind
|
||||
|
30
lib/test8400.cal
Normal file
30
lib/test8400.cal
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright (c) 1999 Landon Curt Noll
|
||||
* Permission is granted to use, distribute, or modify this source,
|
||||
* provided that this copyright notice remains intact.
|
||||
*
|
||||
* By: Landon Curt Noll
|
||||
* http://reality.sgi.com/chongo
|
||||
*
|
||||
* chongo <was here> /\../\
|
||||
*
|
||||
* This library is used by the 8400 series of the regress.cal test suite.
|
||||
*/
|
||||
|
||||
print "8401: in test8400.cal";
|
||||
|
||||
/*
|
||||
* test8400 - dummy function to allow a check of quit-based memory leaks
|
||||
*/
|
||||
define test8400()
|
||||
{
|
||||
local x8401 = 19937; /* watch for lost memory */
|
||||
static s8401 = 44497; /* watch for lost memory */
|
||||
|
||||
return x8401+s8401;
|
||||
}
|
||||
print "8402: parsed test8400()";
|
||||
vrfy(test8400() == 64434, '8403: test8400() == 64434');
|
||||
|
||||
quit;
|
||||
prob('quit did not end test8400.cal');
|
55
lib_calc.c
55
lib_calc.c
@@ -63,9 +63,9 @@ int new_std = FALSE; /* TRUE (-n) => use newstd configuration */
|
||||
int abortlevel; /* current level of aborts */
|
||||
BOOL inputwait; /* TRUE if in a terminal input wait */
|
||||
jmp_buf jmpbuf; /* for errors */
|
||||
run run_state = RUN_UNKNOWN; /* calc startup and run state */
|
||||
char *program = "calc"; /* our name */
|
||||
char cmdbuf[MAXCMD+1+1+1]; /* command line expression + "\n\0" + guard */
|
||||
run run_state = RUN_UNKNOWN; /* calc startup and run state */
|
||||
|
||||
|
||||
/*
|
||||
@@ -86,6 +86,7 @@ int d_flag = FALSE; /* TRUE => disable heading, lib_debug == 0 */
|
||||
int c_flag = FALSE; /* TRUE => continue on error if permitted */
|
||||
int i_flag = FALSE; /* TRUE => go interactive if permitted */
|
||||
|
||||
|
||||
/*
|
||||
* global values
|
||||
*/
|
||||
@@ -106,6 +107,10 @@ int errmax = ERRMAX; /* if >= 0, maximum value for errcount */
|
||||
|
||||
NUMBER *epsilon_default; /* default allowed error for float calcs */
|
||||
|
||||
char *calc_debug = NULL; /* !=NULL => value of config("calc_debug") */
|
||||
char *lib_debug = NULL; /* !=NULL => value of config("lib_debug") */
|
||||
char *user_debug = NULL; /* !=NULL => value of config("user_debug") */
|
||||
|
||||
|
||||
/*
|
||||
* initialization functions
|
||||
@@ -173,6 +178,19 @@ libcalc_call_me_first(void)
|
||||
conf->tab_ok = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* -D flags can change calc_debug, lib_debug of user_debug
|
||||
*/
|
||||
if (calc_debug) {
|
||||
conf->calc_debug = strtol(calc_debug, NULL, 0);
|
||||
}
|
||||
if (lib_debug) {
|
||||
conf->lib_debug = strtol(lib_debug, NULL, 0);
|
||||
}
|
||||
if (user_debug) {
|
||||
conf->user_debug = strtol(user_debug, NULL, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* initialize
|
||||
*/
|
||||
@@ -181,6 +199,11 @@ libcalc_call_me_first(void)
|
||||
/*
|
||||
* ready to rock & roll ..
|
||||
*/
|
||||
if (conf->calc_debug & CALCDBG_RUNSTATE) {
|
||||
printf("DEBUG: run_state from %s to %s\n",
|
||||
run_state_name(run_state),
|
||||
run_state_name(RUN_BEGIN));
|
||||
}
|
||||
run_state = RUN_BEGIN;
|
||||
init_done = 1;
|
||||
return;
|
||||
@@ -371,3 +394,33 @@ libcalc_call_me_last(void)
|
||||
init_done = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* run_state_name - return a constant string given a run_state
|
||||
*/
|
||||
char *
|
||||
run_state_name(run state)
|
||||
{
|
||||
switch (state) {
|
||||
case RUN_UNKNOWN:
|
||||
return "RUN_UNKNOWN";
|
||||
case RUN_BEGIN:
|
||||
return "RUN_BEGIN";
|
||||
case RUN_RCFILES:
|
||||
return "RUN_RCFILES";
|
||||
case RUN_PRE_CMD_ARGS:
|
||||
return "RUN_PRE_CMD_ARGS";
|
||||
case RUN_CMD_ARGS:
|
||||
return "RUN_CMD_ARGS";
|
||||
case RUN_PRE_TOP_LEVEL:
|
||||
return "RUN_PRE_TOP_LEVEL";
|
||||
case RUN_TOP_LEVEL:
|
||||
return "RUN_TOP_LEVEL";
|
||||
case RUN_EXIT:
|
||||
return "RUN_EXIT";
|
||||
case RUN_EXIT_WITH_ERROR:
|
||||
return "RUN_EXIT_WITH_ERROR";
|
||||
}
|
||||
return "RUN_invalid";
|
||||
}
|
||||
|
33
opcodes.c
33
opcodes.c
@@ -33,6 +33,7 @@ static BOOL saveval = TRUE; /* to enable or disable saving */
|
||||
static int calc_errno; /* most recent error-number */
|
||||
static int errcount; /* counts calls to error_value */
|
||||
static BOOL go;
|
||||
static long calc_depth;
|
||||
|
||||
/*
|
||||
* global symbols
|
||||
@@ -106,6 +107,9 @@ initstack(void)
|
||||
freevalue(stack--);
|
||||
}
|
||||
}
|
||||
/* initialize calc_depth */
|
||||
|
||||
calc_depth = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -3124,8 +3128,7 @@ o_quit(FUNC *fp, long index)
|
||||
s = findstring(index);
|
||||
cp = s->s_str;
|
||||
}
|
||||
if (inputisterminal() && (fp->f_name[0] == '*')
|
||||
&& (fp->f_name[1] == '\0')) {
|
||||
if (inputisterminal() && !strcmp(fp->f_name, "*")) {
|
||||
if (cp)
|
||||
printf("%s\n", cp);
|
||||
hist_term();
|
||||
@@ -3138,9 +3141,9 @@ o_quit(FUNC *fp, long index)
|
||||
}
|
||||
if (cp)
|
||||
printf("%s\n", cp);
|
||||
else
|
||||
else if (conf->verbose_quit)
|
||||
printf("Quit or abort executed\n");
|
||||
if (!inputisterminal() && fp->f_name[0] == '*')
|
||||
if (!inputisterminal() && !strcmp(fp->f_name, "*"))
|
||||
closeinput();
|
||||
go = FALSE;
|
||||
}
|
||||
@@ -3576,7 +3579,7 @@ calculate(FUNC *fp, int argcount)
|
||||
funcname = fp->f_name;
|
||||
funcline = 0;
|
||||
go = TRUE;
|
||||
abort_now = FALSE;
|
||||
++calc_depth;
|
||||
origargcount = argcount;
|
||||
while (argcount < fp->f_paramcount) {
|
||||
stack++;
|
||||
@@ -3692,6 +3695,7 @@ calculate(FUNC *fp, int argcount)
|
||||
}
|
||||
funcname = oldname;
|
||||
funcline = oldline;
|
||||
--calc_depth;
|
||||
return;
|
||||
|
||||
case OPSTI: /* static initialization code */
|
||||
@@ -3713,14 +3717,7 @@ calculate(FUNC *fp, int argcount)
|
||||
freevalue(stack--);
|
||||
funcname = oldname;
|
||||
funcline = oldline;
|
||||
if (abort_now && stack == stackarray) {
|
||||
if (!stdin_tty)
|
||||
run_state = RUN_EXIT;
|
||||
else if (run_state < RUN_PRE_TOP_LEVEL)
|
||||
run_state = RUN_PRE_TOP_LEVEL;
|
||||
freefunc(curfunc);
|
||||
longjmp(jmpbuf, 1);
|
||||
}
|
||||
--calc_depth;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -3857,3 +3854,13 @@ freenumbers(FUNC *fp)
|
||||
}
|
||||
trimconstants();
|
||||
}
|
||||
|
||||
|
||||
long
|
||||
calclevel(void)
|
||||
{
|
||||
return calc_depth - 1;
|
||||
}
|
||||
|
||||
|
||||
/* END CODE */
|
||||
|
@@ -404,9 +404,10 @@ config_hash(CONFIG *cfg, QCKHASH val)
|
||||
value = (((value>>5) | (value<<27)) ^ (USB32)cfg->blkverbose);
|
||||
value = (((value>>5) | (value<<27)) ^ (USB32)cfg->blkbase);
|
||||
value = (((value>>5) | (value<<27)) ^ (USB32)cfg->blkfmt);
|
||||
value = (((value>>5) | (value<<27)) ^ (USB32)cfg->lib_debug);
|
||||
value = (((value>>5) | (value<<27)) ^ (USB32)cfg->calc_debug);
|
||||
value = (((value>>5) | (value<<27)) ^ (USB32)cfg->lib_debug);
|
||||
value = (((value>>5) | (value<<27)) ^ (USB32)cfg->user_debug);
|
||||
value = (((value>>5) | (value<<27)) ^ (USB32)cfg->verbose_quit);
|
||||
|
||||
/*
|
||||
* hash the built up scalar
|
||||
|
12
token.c
12
token.c
@@ -335,22 +335,22 @@ static void
|
||||
eatcomment(void)
|
||||
{
|
||||
int ch;
|
||||
|
||||
setprompt(conf->prompt2);
|
||||
for (;;) {
|
||||
ch = nextchar();
|
||||
if (ch == '*') {
|
||||
ch = nextchar();
|
||||
if (ch == '/')
|
||||
return;
|
||||
break;
|
||||
reread();
|
||||
}
|
||||
if ((ch == EOF) || (ch == '\0') ||
|
||||
(newlines && (ch == '\n') && inputisterminal())) {
|
||||
if (ch == EOF || ch == '\0') {
|
||||
fprintf(stderr, "Unterminated comment ignored\n");
|
||||
reread();
|
||||
scanerror(T_NULL, "Unterminated comment");
|
||||
return;
|
||||
break;
|
||||
}
|
||||
}
|
||||
setprompt(conf->prompt1);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -12,7 +12,7 @@
|
||||
#define MAJOR_VER 2 /* major version */
|
||||
#define MINOR_VER 11 /* minor version */
|
||||
#define MAJOR_PATCH 0 /* patch level or 0 if no patch */
|
||||
#define MINOR_PATCH "8.8" /* test number or empty string if no patch */
|
||||
#define MINOR_PATCH "9.2" /* test number or empty string if no patch */
|
||||
|
||||
/*
|
||||
* calc version constants
|
||||
|
2
zmath.h
2
zmath.h
@@ -72,7 +72,7 @@ typedef SB16 SHALF; /* signed HALF */
|
||||
typedef USB32 FULL; /* double unit of number storage */
|
||||
typedef SB32 SFULL; /* signed FULL */
|
||||
|
||||
#define SWAP_HALF_IN_B64(dest, src) SWAP_B32_IN_B64(dest, src)
|
||||
#define SWAP_HALF_IN_B64(dest, src) SWAP_B16_IN_B64(dest, src)
|
||||
#define SWAP_HALF_IN_B32(dest, src) SWAP_B16_IN_B32(dest, src)
|
||||
#define SWAP_HALF_IN_FULL(dest, src) SWAP_B16_IN_B32(dest, src)
|
||||
#define SWAP_HALF_IN_HASH(dest, src) SWAP_B16_IN_HASH(dest, src)
|
||||
|
Reference in New Issue
Block a user