convert ASCII TABs to ASCII SPACEs

Converted all ASCII tabs to ASCII spaces using a 8 character
tab stop, for all files, except for all Makefiles (plus rpm.mk).
The `git diff -w` reports no changes.
This commit is contained in:
Landon Curt Noll
2024-07-11 22:03:52 -07:00
parent fe9cefe6ef
commit db77e29a23
631 changed files with 90607 additions and 90600 deletions

View File

@@ -10,18 +10,18 @@ resource files are shipped with calc to provide you with examples.
By default, the custom builtin returns an error. Calc have been
built with:
ALLOW_CUSTOM= -DCUSTOM
ALLOW_CUSTOM= -DCUSTOM
in the top level Makefile (this is the shipped default) and calc
must be invoked with a -C argument:
calc -C
calc -C
when it is run.
To disable custom even if -C is given, calc must be built with:
ALLOW_CUSTOM="-UCUSTOM"
ALLOW_CUSTOM="-UCUSTOM"
See the ../cal/README or "help resource" for information about
calc resource standards and guidelines.
@@ -53,7 +53,7 @@ pzasusb8.cal
##
## 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
## 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
@@ -61,8 +61,8 @@ pzasusb8.cal
## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
##
## Under source code control: 1997/03/08 20:51:32
## File existed as early as: 1997
## Under source code control: 1997/03/08 20:51:32
## File existed as early as: 1997
##
## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/

View File

@@ -7,7 +7,7 @@ Step 0: Determine if is should it be done?
multi-precision calculations in a C-like environment. You should
consider implementing algorithms in the calc language as a first
choice. Sometimes an algorithm requires use of special hardware, a
non-portable OS or pre-compiled C library. In these cases a custom
non-portable OS or pre-compiled C library. In these cases a custom
interface may be needed.
The custom function interface is intended to make is easy for
@@ -18,16 +18,16 @@ Step 0: Determine if is should it be done?
So before you go to step 1, ask yourself:
+ Can I implement this as a calc resource file or calc shell script?
+ Can I implement this as a calc resource file or calc shell script?
If Yes, write the shell script or resource file and be done with it.
If No, continue to the next question ...
If Yes, write the shell script or resource file and be done with it.
If No, continue to the next question ...
+ Does it require the use of non-portable features,
OS specific support or special hardware?
+ Does it require the use of non-portable features,
OS specific support or special hardware?
If No, write it as a regular builtin function.
If Yes, continue to step 1 ...
If No, write it as a regular builtin function.
If Yes, continue to step 1 ...
Step 1: Do some background work
@@ -39,18 +39,18 @@ Step 1: Do some background work
you look at some examples of custom functions. Look at the
the following source files:
custom.c
custom.h
custom/custtbl.c
custom/c_*.[ch]
custom/*.cal
help/custom (or run: calc help custom)
custom.c
custom.h
custom/custtbl.c
custom/c_*.[ch]
custom/*.cal
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 version archive.
See the following for more details:
help/archive (or run: calc help archive)
help/archive (or run: calc help archive)
Step 2: Name your custom function
@@ -84,16 +84,16 @@ Step 3: Document your custom function
Take a look at one of the example custom help files:
custom/devnull
custom/argv
custom/help
custom/sysinfo
custom/devnull
custom/argv
custom/help
custom/sysinfo
You can save time by using one of the custom help files
as a template. Copy one of these files to your own help file:
cd custom
cp sysinfo curds
cd custom
cp sysinfo curds
and edit it accordingly.
@@ -113,24 +113,24 @@ Step 4: Write your test code
You can use one of the following as a template:
custom/argv.cal
custom/halflen.cal
custom/argv.cal
custom/halflen.cal
Copy one of these to your own file:
cd custom
cp halflen.cal curds.cal
cd custom
cp halflen.cal curds.cal
and exit it accordingly. In particular you will want to:
remove our header disclaimer (or put your own on)
remove our header disclaimer (or put your own on)
change the name from halflen() to curds()
change the name from halflen() to curds()
change the comment from 'halflen - determine the length ...' to
'curds - brief description about ...'
change the comment from 'halflen - determine the length ...' to
'curds - brief description about ...'
change other code as needed.
change other code as needed.
Step 5: Write your custom function
@@ -138,145 +138,145 @@ Step 5: Write your custom function
By convention, the files we ship that contain custom function
interface code in filenames of the form:
c_*.c
c_*.c
We suggest that you use filenames of the form:
u_*.c
u_*.c
to avoid filename conflicts.
We recommend that you use one of the c_*.c files as a template.
Copy an appropriate file to your file:
cd custom
cp c_argv.c u_curds.c
cd custom
cp c_argv.c u_curds.c
Before you edit it, you should note that there are several important
features of this file.
a) All of the code in the file is found between #if ... #endif:
a) All of the code in the file is found between #if ... #endif:
/*
* only comments and blank lines at the top
*/
/*
* only comments and blank lines at the top
*/
#if defined(CUSTOM)
#if defined(CUSTOM)
... all code, #includes, #defines etc.
... all code, #includes, #defines etc.
#endif /* CUSTOM */
#endif /* CUSTOM */
This allows this code to 'go away' when the upper Makefile
disables the custom code when CUSTOM is not defined.
This allows this code to 'go away' when the upper Makefile
disables the custom code when CUSTOM is not defined.
b) The function type must be:
b) The function type must be:
/*ARGSUSED*/
VALUE
u_curds(char *name, int count, VALUE **vals)
/*ARGSUSED*/
VALUE
u_curds(char *name, int count, VALUE **vals)
The 3 args are passed in by the custom interface
and have the following meaning:
The 3 args are passed in by the custom interface
and have the following meaning:
name The name of the custom function that
was called. In particular, this is the first
string arg that was given to the custom()
builtin. This is the equivalent of argv[0] for
main() in C programming.
name The name of the custom function that
was called. In particular, this is the first
string arg that was given to the custom()
builtin. This is the equivalent of argv[0] for
main() in C programming.
The same code can be used for multiple custom
functions by processing off of this value.
The same code can be used for multiple custom
functions by processing off of this value.
count This is the number of additional args that
was given to the custom() builtin. Note
that count does NOT include the name arg.
This is similar to argc except that count
is one less than the main() argc interface.
count This is the number of additional args that
was given to the custom() builtin. Note
that count does NOT include the name arg.
This is similar to argc except that count
is one less than the main() argc interface.
For example, a call of:
For example, a call of:
custom("curds", a, b, c)
custom("curds", a, b, c)
would cause count to be passed as 3.
would cause count to be passed as 3.
vals This is a pointer to an array of VALUEs.
This is the equivalent of argv+1 for
main() in C programming. The difference
here is that vals[0] refers to the 1st
parameter AFTER the same.
vals This is a pointer to an array of VALUEs.
This is the equivalent of argv+1 for
main() in C programming. The difference
here is that vals[0] refers to the 1st
parameter AFTER the same.
For example, a call of:
For example, a call of:
custom("curds", a, b, c)
custom("curds", a, b, c)
would cause vals to point to the following array:
would cause vals to point to the following array:
vals[0] points to a
vals[1] points to b
vals[2] points to c
vals[0] points to a
vals[1] points to b
vals[2] points to c
NOTE: If you do not use any of the 3 function parameters,
then you should declare that function parameter to be UNUSED.
For example, if the count and vals parameters were not used
in your custom function, then your declaration should be:
NOTE: If you do not use any of the 3 function parameters,
then you should declare that function parameter to be UNUSED.
For example, if the count and vals parameters were not used
in your custom function, then your declaration should be:
/*ARGSUSED*/
VALUE
u_curds(char *name, int UNUSED count, VALUE UNUSED **vals)
/*ARGSUSED*/
VALUE
u_curds(char *name, int UNUSED count, VALUE UNUSED **vals)
c) The return value is the function must be a VALUE.
c) The return value is the function must be a VALUE.
The typical way to form a VALUE to return is by declaring
the following local variable:
The typical way to form a VALUE to return is by declaring
the following local variable:
VALUE result; /* what we will return */
VALUE result; /* what we will return */
d) You will need to include:
d) You will need to include:
#if defined(CUSTOM)
#if defined(CUSTOM)
/* any #include <foobar.h> here */
/* any #include <foobar.h> here */
#include "../have_const.h"
#include "../value.h"
#include "custom.h"
#include "../have_const.h"
#include "../value.h"
#include "custom.h"
#include "../have_unused.h"
#include "../have_unused.h"
Typically these will be included just below any system
includes and just below the #if defined(CUSTOM) line.
Typically these will be included just below any system
includes and just below the #if defined(CUSTOM) line.
To better understand the VALUE type, read:
../value.h
../value.h
The VALUE is a union of major value types found inside calc.
The v_type VALUE element determines which union element is
being used. Assume that we have:
being used. Assume that we have:
VALUE *vp;
VALUE *vp;
Then the value is determined according to v_type:
vp->v_type the value is which is a type defined in
---------- ------------ ---------- ---------------
V_NULL (none) n/a n/a
V_INT vp->v_int long n/a
V_NUM vp->v_num NUMBER * ../qmath.h
V_COM vp->v_com COMPLEX * ../cmath.h
V_ADDR vp->v_addr VALUE * ../value.h
V_STR vp->v_str char * n/a
V_MAT vp->v_mat MATRIX * ../value.h
V_LIST vp->v_list LIST * ../value.h
V_ASSOC vp->v_assoc ASSOC * ../value.h
V_OBJ vp->v_obj OBJECT * ../value.h
V_FILE vp->v_file FILEID ../value.h
V_RAND vp->v_rand RAND * ../zrand.h
V_RANDOM vp->v_random RANDOM * ../zrandom.h
V_CONFIG vp->v_config CONFIG * ../config.h
V_HASH vp->v_hash HASH * ../hash.h
V_BLOCK vp->v_block BLOCK * ../block.h
vp->v_type the value is which is a type defined in
---------- ------------ ---------- ---------------
V_NULL (none) n/a n/a
V_INT vp->v_int long n/a
V_NUM vp->v_num NUMBER * ../qmath.h
V_COM vp->v_com COMPLEX * ../cmath.h
V_ADDR vp->v_addr VALUE * ../value.h
V_STR vp->v_str char * n/a
V_MAT vp->v_mat MATRIX * ../value.h
V_LIST vp->v_list LIST * ../value.h
V_ASSOC vp->v_assoc ASSOC * ../value.h
V_OBJ vp->v_obj OBJECT * ../value.h
V_FILE vp->v_file FILEID ../value.h
V_RAND vp->v_rand RAND * ../zrand.h
V_RANDOM vp->v_random RANDOM * ../zrandom.h
V_CONFIG vp->v_config CONFIG * ../config.h
V_HASH vp->v_hash HASH * ../hash.h
V_BLOCK vp->v_block BLOCK * ../block.h
The V_OCTET is under review and should not be used at this time.
@@ -285,100 +285,100 @@ Step 5: Write your custom function
you might also want to read the following to understand
some of the numerical types of ZVALUE, NUMBER and COMPLEX:
../zmath.h
../qmath.h
../cmath.h
../zmath.h
../qmath.h
../cmath.h
While we cannot go into full detail here are some cookbook
code for manipulating VALUEs. For these examples assume
that we will manipulate the return value:
VALUE result; /* what we will return */
VALUE result; /* what we will return */
To return NULL:
result.v_type = V_NULL;
return result;
result.v_type = V_NULL;
return result;
To return a long you need to convert it to a NUMBER:
long variable;
long variable;
result.v_type = V_NUM;
result.v_num = itoq(variable); /* see ../qmath.c */
return result;
result.v_type = V_NUM;
result.v_num = itoq(variable); /* see ../qmath.c */
return result;
To return a FULL you need to convert it to a NUMBER:
FULL variable;
FULL variable;
result.v_type = V_NUM;
result.v_num = utoq(variable); /* see ../qmath.c */
return result;
result.v_type = V_NUM;
result.v_num = utoq(variable); /* see ../qmath.c */
return result;
To convert a ZVALUE to a NUMBER*:
ZVALUE variable;
ZVALUE variable;
result.v_type = V_NUM;
result.v_num = qalloc(); /* see ../qmath.c */
result.v_num->num = variable;
return result;
result.v_type = V_NUM;
result.v_num = qalloc(); /* see ../qmath.c */
result.v_num->num = variable;
return result;
To convert a small NUMBER* into a long:
NUMBER *num;
long variable;
NUMBER *num;
long variable;
variable = qtoi(num);
variable = qtoi(num);
To obtain a ZVALUE from a NUMBER*, extract the numerator:
NUMBER *num;
ZVALUE z_variable;
NUMBER *num;
ZVALUE z_variable;
if (qisint(num)) {
z_variable = num->num;
}
if (qisint(num)) {
z_variable = num->num;
}
To be sure that the value will fit, use the ZVALUE test macros:
ZVALUE z_num;
long variable;
unsigned long u_variable;
FULL f_variable;
short very_tiny_variable;
ZVALUE z_num;
long variable;
unsigned long u_variable;
FULL f_variable;
short very_tiny_variable;
if (zgtmaxlong(z_num)) { /* see ../zmath.h */
variable = ztolong(z_num);
}
if (zgtmaxulong(z_num)) {
u_variable = ztoulong(z_num);
}
if (zgtmaxufull(z_num)) {
f_variable = ztofull(z_num);
}
if (zistiny(z_num)) {
very_tiny_variable = z1tol(z_num);
}
if (zgtmaxlong(z_num)) { /* see ../zmath.h */
variable = ztolong(z_num);
}
if (zgtmaxulong(z_num)) {
u_variable = ztoulong(z_num);
}
if (zgtmaxufull(z_num)) {
f_variable = ztofull(z_num);
}
if (zistiny(z_num)) {
very_tiny_variable = z1tol(z_num);
}
You can (and should) add debugging statements to your custom code
by examining bit 8 of the calc_debug config flag:
if (conf->calc_debug & CALCDBG_CUSTOM) {
fprintf(stderr, "%ssome custom debug note: msg\n",
(conf->tab_ok ? "\t" : ""),
((msg == NULL) ? "((NULL))" : msg));
}
if (conf->calc_debug & CALCDBG_CUSTOM) {
fprintf(stderr, "%ssome custom debug note: msg\n",
(conf->tab_ok ? "\t" : ""),
((msg == NULL) ? "((NULL))" : msg));
}
One is able to set bit 8 by way of the calc command line:
calc -D 128
calc -D 128
See the calc man page for details. One may also set that bit
while running calc by way of the config() builtin function:
config("calc_debug", 128);
config("calc_debug", 128);
See the help/config file for details on calc_debug.
@@ -388,81 +388,81 @@ Step 6: Register the function in the custom interface table
you need to add an entry into the CONST struct custom cust table
found in custom/custtbl.c:
/*
* custom interface table
*
* The order of the elements in struct custom are:
*
* { "xyz", "brief description of the xyz custom function",
* minimum_args, maximum_args, c_xyz },
*
* where:
*
* minimum_args an int >= 0
* maximum_args an int >= minimum_args and <= MAX_CUSTOM_ARGS
*
* Use MAX_CUSTOM_ARGS for maximum_args is the maximum number of args
* is potentially 'unlimited'.
*
* If the brief description cannot fit on the same line as the name
* without wrapping on a 80 col window, the description is probably
* too long and will not look nice in the show custom output.
*/
CONST struct custom cust[] = {
/*
* custom interface table
*
* The order of the elements in struct custom are:
*
* { "xyz", "brief description of the xyz custom function",
* minimum_args, maximum_args, c_xyz },
*
* where:
*
* minimum_args an int >= 0
* maximum_args an int >= minimum_args and <= MAX_CUSTOM_ARGS
*
* Use MAX_CUSTOM_ARGS for maximum_args is the maximum number of args
* is potentially 'unlimited'.
*
* If the brief description cannot fit on the same line as the name
* without wrapping on a 80 col window, the description is probably
* too long and will not look nice in the show custom output.
*/
CONST struct custom cust[] = {
#if defined(CUSTOM)
#if defined(CUSTOM)
/*
* add your own custom functions here
*
* We suggest that you sort the entries below by name
* so that show custom will produce a nice sorted list.
*/
/*
* add your own custom functions here
*
* We suggest that you sort the entries below by name
* so that show custom will produce a nice sorted list.
*/
{ "argv", "information about its args, returns arg count",
0, MAX_CUSTOM_ARGS, c_argv },
{ "argv", "information about its args, returns arg count",
0, MAX_CUSTOM_ARGS, c_argv },
{ "devnull", "does nothing",
0, MAX_CUSTOM_ARGS, c_devnull },
{ "devnull", "does nothing",
0, MAX_CUSTOM_ARGS, c_devnull },
{ "help", "help for custom functions",
1, 1, c_help },
{ "help", "help for custom functions",
1, 1, c_help },
{ "sysinfo", "return a calc #define value",
0, 1, c_sysinfo },
{ "sysinfo", "return a calc #define value",
0, 1, c_sysinfo },
#endif /* CUSTOM */
#endif /* CUSTOM */
/*
* This must be at the end of this table!!!
*/
{NULL, NULL,
0, 0, NULL}
};
/*
* This must be at the end of this table!!!
*/
{NULL, NULL,
0, 0, NULL}
};
The definition of struct custom may be found in custom.h.
It is important that your entry be placed inside the:
#if defined(CUSTOM) ... #endif /* CUSTOM */
#if defined(CUSTOM) ... #endif /* CUSTOM */
lines so that when the custom interface is disabled by the upper
level Makefile, one does not have unsatisfied symbols.
The brief description should be brief so that 'show custom' looks well
formatted. If the brief description cannot fit on the same line as
formatted. If the brief description cannot fit on the same line as
the name without wrapping on a 80 col window, the description is
probably too long and will not look nice in the show custom output.
The minargs places a lower bound on the number of args that
must be supplied to the interface. This does NOT count
must be supplied to the interface. This does NOT count
the name argument given to custom(). So if minargs is 2:
custom("curds") /* call blocked at high level interface */
custom("curds", a) /* call blocked at high level interface */
custom("curds", a, b) /* call passed down to "curds" interface */
custom("curds") /* call blocked at high level interface */
custom("curds", a) /* call blocked at high level interface */
custom("curds", a, b) /* call passed down to "curds" interface */
The maxargs sets a limit on the number of args that may be passed.
If minargs == maxargs, then the call requires a fixed number of
@@ -471,39 +471,39 @@ Step 6: Register the function in the custom interface table
Note that one must have:
0 <= minargs <= maxargs <= MAX_CUSTOM_ARGS
0 <= minargs <= maxargs <= MAX_CUSTOM_ARGS
To allow the curds function to take at least 2 args and up
to 5 args, one would add the following entry to cust[]:
{ "curds", "brief description about curds interface",
2, 5, u_curds },
{ "curds", "brief description about curds interface",
2, 5, u_curds },
It is recommended that the cust[] remain in alphabetical order,
so one would place it before the "devnull" and after "argv".
Last, you must forward declare the u_curds near the top of the file:
#if defined(CUSTOM)
#if defined(CUSTOM)
/*
* add your forward custom function declarations here
*
* Declare custom functions as follows:
*
* E_FUNC VALUE c_xyz(char*, int, VALUE**);
*
* We suggest that you sort the entries below by name.
*/
E_FUNC VALUE c_argv(char*, int, VALUE**);
E_FUNC VALUE c_devnull(char*, int, VALUE**);
E_FUNC VALUE c_help(char*, int, VALUE**);
E_FUNC VALUE c_sysinfo(char*, int, VALUE**);
/*
* add your forward custom function declarations here
*
* Declare custom functions as follows:
*
* E_FUNC VALUE c_xyz(char*, int, VALUE**);
*
* We suggest that you sort the entries below by name.
*/
E_FUNC VALUE c_argv(char*, int, VALUE**);
E_FUNC VALUE c_devnull(char*, int, VALUE**);
E_FUNC VALUE c_help(char*, int, VALUE**);
E_FUNC VALUE c_sysinfo(char*, int, VALUE**);
For u_curds we would add the line:
E_FUNC VALUE u_curds(char*, int, VALUE**);
E_FUNC VALUE u_curds(char*, int, VALUE**);
Step 7: Add the required information to the custom/Makefile.head
@@ -511,26 +511,26 @@ Step 7: Add the required information to the custom/Makefile.head
The calc test script, curds.cal, should be added to the
CUSTOM_CALC_FILES Makefile variable found in custom/Makefile.head:
CUSTOM_CALC_FILES= argv.cal halflen.cal curds.cal
CUSTOM_CALC_FILES= argv.cal halflen.cal curds.cal
The help file, curds, should be added to the CUSTOM_HELP
custom/Makefile.head variable:
CUSTOM_HELP= argv devnull help sysinfo curds
CUSTOM_HELP= argv devnull help sysinfo curds
If you needed to create any .h files to support u_curds.c, these
files should be added to the CUSTOM_H_SRC custom/Makefile.head variable:
CUSTOM_H_SRC= u_curds.h otherfile.h
CUSTOM_H_SRC= u_curds.h otherfile.h
Your u_curds.c file MUST be added to the CUSTOM_SRC custom/Makefile.head
variable:
CUSTOM_SRC= c_argv.c c_devnull.c c_help.c c_sysinfo.c u_curds.c
CUSTOM_SRC= c_argv.c c_devnull.c c_help.c c_sysinfo.c u_curds.c
and so must the associated .o file:
CUSTOM_OBJ= c_argv.o c_devnull.o c_help.o c_sysinfo.o u_curds.o
CUSTOM_OBJ= c_argv.o c_devnull.o c_help.o c_sysinfo.o u_curds.o
Step 8: Compile and link in your code
@@ -540,25 +540,25 @@ Step 8: Compile and link in your code
the custom Makefile) should have the following Makefile
variable defined:
ALLOW_CUSTOM= -DCUSTOM
ALLOW_CUSTOM= -DCUSTOM
It is recommended that you build your code from the top level
Makefile. It saves having to sync the other Makefile values.
To try and build the new libcustcalc.a that contains u_curds.c:
(cd ..; make custom/libcustcalc.a)
(cd ..; make custom/libcustcalc.a)
Fix any compile and syntax errors as needed. :-)
Once libcustcalc.a successfully builds, compile calc:
cd ..
make calc
cd ..
make calc
And check to be sure that the regression test suite still
works without errors:
make check
make check
Step 9: Add the Make dependency tools
@@ -567,66 +567,66 @@ Step 9: Add the Make dependency tools
the Makefile. Given the required include files, you will at least
have the following entries placed at the bottom of the Makefile:
u_curds.o: ../alloc.h
u_curds.o: ../block.h
u_curds.o: ../byteswap.h
u_curds.o: ../cmath.h
u_curds.o: ../config.h
u_curds.o: ../endian_calc.h
u_curds.o: ../errsym.h
u_curds.o: ../hash.h
u_curds.o: ../have_const.h
u_curds.o: ../have_malloc.h
u_curds.o: ../have_newstr.h
u_curds.o: ../have_stdlib.h
u_curds.o: ../have_string.h
u_curds.o: ../longbits.h
u_curds.o: ../nametype.h
u_curds.o: ../qmath.h
u_curds.o: ../shs.h
u_curds.o: ../value.h
u_curds.o: ../zmath.h
u_curds.o: u_curds.c
u_curds.o: ../custom.h
u_curds.o: ../alloc.h
u_curds.o: ../block.h
u_curds.o: ../byteswap.h
u_curds.o: ../cmath.h
u_curds.o: ../config.h
u_curds.o: ../endian_calc.h
u_curds.o: ../errsym.h
u_curds.o: ../hash.h
u_curds.o: ../have_const.h
u_curds.o: ../have_malloc.h
u_curds.o: ../have_newstr.h
u_curds.o: ../have_stdlib.h
u_curds.o: ../have_string.h
u_curds.o: ../longbits.h
u_curds.o: ../nametype.h
u_curds.o: ../qmath.h
u_curds.o: ../shs.h
u_curds.o: ../value.h
u_curds.o: ../zmath.h
u_curds.o: u_curds.c
u_curds.o: ../custom.h
If you have the makedepend tool from the X11 development environment
(by Todd Brunhoff, Tektronix, Inc. and MIT Project Athena), you can
use the following to update your dependencies:
# cd to the top level calc directory if you are not there already
# cd to the top level calc directory if you are not there already
rm -f Makefile.bak custom/Makefile.bak
make depend
rm -f Makefile.bak custom/Makefile.bak
make depend
diff -c Makefile.bak Makefile # look at the changes
diff -c custom/Makefile.bak custom/Makefile # look at the changes
diff -c Makefile.bak Makefile # look at the changes
diff -c custom/Makefile.bak custom/Makefile # look at the changes
rm -f Makefile.bak custom/Makefile.bak # cleanup
rm -f Makefile.bak custom/Makefile.bak # cleanup
Step 10: Test
Now that you have built calc with your new custom function, test it:
./calc -C # run the new calc with the -C arg
./calc -C # run the new calc with the -C arg
And then try out our test suite:
C-style arbitrary precision calculator (version 2.10.3t5.1)
[Type "exit" to exit, or "help" for help.]
C-style arbitrary precision calculator (version 2.10.3t5.1)
[Type "exit" to exit, or "help" for help.]
> read custom/curds.cal
curds(a, b, [c, d, e]) defined
> read custom/curds.cal
curds(a, b, [c, d, e]) defined
> custom("curds", 2, 3, 4)
> custom("curds", 2, 3, 4)
Step 11: Install
Once you are satisfied that everything works, install the new code:
# cd to the top level calc directory if you are not there already
# cd to the top level calc directory if you are not there already
make install
make 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.
@@ -639,7 +639,7 @@ Step 12: Contribute
Read the file:
help/contrib (or run: calc help contrib)
help/contrib (or run: calc help contrib)
and consider submitting your custom function for possible
inclusion in later versions of calc.
@@ -652,7 +652,7 @@ Step 12: Contribute
##
## 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
## 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
@@ -660,8 +660,8 @@ Step 12: Contribute
## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
##
## Under source code control: 1997/03/10 03:03:21
## File existed as early as: 1997
## Under source code control: 1997/03/10 03:03:21
## File existed as early as: 1997
##
## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/

View File

@@ -5,17 +5,17 @@ SYNOPSIS
custom("argv" [, arg ...])
TYPES
arg any
arg any
return int
return int
DESCRIPTION
This custom function will, for each arg given print:
arg number
arg type
number of elements (size())
memory size (sizeof())
arg number
arg type
number of elements (size())
memory size (sizeof())
The number of args passed, not counting the initial "argv" name
arg is returned.
@@ -23,12 +23,12 @@ DESCRIPTION
EXAMPLE
> foo=5^713; bar=17; baz=list(2,3,4);
> custom("argv", foo, bar, baz, 3+4.5i, pi())
arg[0] rational_value size=1 sizeof=272
arg[1] rational_value size=1 sizeof=68
arg[2] list size=3 sizeof=256
arg[3] complex_value size=1 sizeof=140
arg[4] rational_value size=1 sizeof=84
5
arg[0] rational_value size=1 sizeof=272
arg[1] rational_value size=1 sizeof=68
arg[2] list size=3 sizeof=256
arg[3] complex_value size=1 sizeof=140
arg[4] rational_value size=1 sizeof=84
5
LIMITS
calc must be built with ALLOW_CUSTOM= -DCUSTOM
@@ -48,7 +48,7 @@ SEE ALSO
##
## 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
## 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
@@ -56,8 +56,8 @@ SEE ALSO
## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
##
## Under source code control: 1997/03/09 20:28:01
## File existed as early as: 1997
## Under source code control: 1997/03/09 20:28:01
## File existed as early as: 1997
##
## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/

View File

@@ -9,7 +9,7 @@
*
* 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
* 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
@@ -17,41 +17,41 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Under source code control: 1997/03/10 00:27:17
* File existed as early as: 1997
* Under source code control: 1997/03/10 00:27:17
* File existed as early as: 1997
*
* chongo <was here> /\oo/\ http://www.isthe.com/chongo/
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
* chongo <was here> /\oo/\ http://www.isthe.com/chongo/
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
*/
/*
* This file is part of the custom sample calc files.
*
* NOTE: You must use a calc that was compiled with ALLOW_CUSTOM= -DCUSTOM
* and run with a -C arg.
* and run with a -C arg.
*/
if (config("compile_custom") == 0) {
quit "calc compiled without -DCUSTOM";
quit "calc compiled without -DCUSTOM";
} else if (config("allow_custom") == 0) {
quit "calc was run without the -D command line option";
quit "calc was run without the -D command line option";
}
define argv_test()
{
local i; /* arg number */
local junk; /* throw away value */
local i; /* arg number */
local junk; /* throw away value */
/*
* process each arg passed to us
*/
for (i = 1; i <= param(0); ++i) {
/*
* This won't really work because all the arg numbers
* will be reported as arg[0] ... but what the heck
* this is only a demo!
*/
junk = custom("argv", param(i));
}
return i-1;
/*
* process each arg passed to us
*/
for (i = 1; i <= param(0); ++i) {
/*
* This won't really work because all the arg numbers
* will be reported as arg[0] ... but what the heck
* this is only a demo!
*/
junk = custom("argv", param(i));
}
return i-1;
}

View File

@@ -9,7 +9,7 @@
*
* 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
* 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
@@ -17,11 +17,11 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Under source code control: 1997/03/09 20:27:37
* File existed as early as: 1997
* Under source code control: 1997/03/09 20:27:37
* File existed as early as: 1997
*
* chongo <was here> /\oo/\ http://www.isthe.com/chongo/
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
* chongo <was here> /\oo/\ http://www.isthe.com/chongo/
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
*/
@@ -30,9 +30,9 @@
* so we declare a global variable whose value is based on if CUSTOM is defined.
*/
#if defined(CUSTOM)
int c_argv_allowed = 1; /* CUSTOM defined */
int c_argv_allowed = 1; /* CUSTOM defined */
#else /* CUSTOM */
int c_argv_allowed = 0; /* CUSTOM undefined */
int c_argv_allowed = 0; /* CUSTOM undefined */
#endif /* CUSTOM */
@@ -50,129 +50,129 @@ int c_argv_allowed = 0; /* CUSTOM undefined */
#include "../have_unused.h"
#include "../banned.h" /* include after system header <> includes */
#include "../banned.h" /* include after system header <> includes */
/*
* c_argv - a custom function display info about its args
*
* given:
* vals[i] and arg to display information about
* vals[i] and arg to display information about
*
* returns:
* count
* count
*/
/*ARGSUSED*/
VALUE
c_argv(char *UNUSED(name), int count, VALUE **vals)
{
VALUE result; /* what we will return */
ZVALUE zfilelen; /* length of a file as a ZVALUE */
NUMBER *filelen; /* pointer to length of a file as a NUMBER */
char *type; /* the name of the arg type */
int i;
VALUE result; /* what we will return */
ZVALUE zfilelen; /* length of a file as a ZVALUE */
NUMBER *filelen; /* pointer to length of a file as a NUMBER */
char *type; /* the name of the arg type */
int i;
/*
* print info on each arg
*/
for (i=0; i < count; ++i) {
/*
* print info on each arg
*/
for (i=0; i < count; ++i) {
/*
* print arg number with leading tab as configured
*/
printf("%sarg[%d]", (conf->tab_ok ? "\t" : ""), i);
/*
* print arg number with leading tab as configured
*/
printf("%sarg[%d]", (conf->tab_ok ? "\t" : ""), i);
/*
* print the arg type
*/
switch (vals[i]->v_type) {
case V_NULL: /* null value */
type = "null";
break;
case V_INT: /* normal integer */
type = "int";
break;
case V_NUM: /* number */
type = "rational_value";
break;
case V_COM: /* complex number */
type = "complex_value";
break;
case V_ADDR: /* address of variable value */
type = "address";
break;
case V_STR: /* address of string */
type = "string";
break;
case V_MAT: /* address of matrix structure */
type = "matrix";
break;
case V_LIST: /* address of list structure */
type = "list";
break;
case V_ASSOC: /* address of association structure */
type = "assoc";
break;
case V_OBJ: /* address of object structure */
type = "object";
break;
case V_FILE: /* opened file id */
type = "file";
break;
case V_RAND: /* subtractive 100 random state */
type = "rand_state";
break;
case V_RANDOM: /* address of Blum random state */
type = "random_state";
break;
case V_CONFIG: /* configuration state */
type = "config_state";
break;
case V_HASH: /* hash state */
type = "hash_state";
break;
case V_BLOCK: /* memory block */
type = "octet_block";
break;
case V_OCTET: /* octet (unsigned char) */
type = "octet";
break;
default:
type = "unknown";
break;
}
printf("\t%-16s", type);
/*
* print the arg type
*/
switch (vals[i]->v_type) {
case V_NULL: /* null value */
type = "null";
break;
case V_INT: /* normal integer */
type = "int";
break;
case V_NUM: /* number */
type = "rational_value";
break;
case V_COM: /* complex number */
type = "complex_value";
break;
case V_ADDR: /* address of variable value */
type = "address";
break;
case V_STR: /* address of string */
type = "string";
break;
case V_MAT: /* address of matrix structure */
type = "matrix";
break;
case V_LIST: /* address of list structure */
type = "list";
break;
case V_ASSOC: /* address of association structure */
type = "assoc";
break;
case V_OBJ: /* address of object structure */
type = "object";
break;
case V_FILE: /* opened file id */
type = "file";
break;
case V_RAND: /* subtractive 100 random state */
type = "rand_state";
break;
case V_RANDOM: /* address of Blum random state */
type = "random_state";
break;
case V_CONFIG: /* configuration state */
type = "config_state";
break;
case V_HASH: /* hash state */
type = "hash_state";
break;
case V_BLOCK: /* memory block */
type = "octet_block";
break;
case V_OCTET: /* octet (unsigned char) */
type = "octet";
break;
default:
type = "unknown";
break;
}
printf("\t%-16s", type);
/*
* print size and sizeof information
*
* We have to treat files in a special way
* because their length can be very long.
*/
if (vals[i]->v_type == V_FILE) {
/* get the file length */
if (getsize(vals[i]->v_file, &zfilelen) == 0) {
filelen = qalloc();
filelen->num = zfilelen;
qprintfd(filelen, 0L);
qfree(filelen);
} else {
/* getsize error */
printf("\tsize=unknown");
}
printf("\tsizeof=%ld\n", (long int)lsizeof(vals[i]));
} else {
printf("\tsize=%ld\tsizeof=%ld\n",
elm_count(vals[i]), (long int)lsizeof(vals[i]));
}
}
/*
* print size and sizeof information
*
* We have to treat files in a special way
* because their length can be very long.
*/
if (vals[i]->v_type == V_FILE) {
/* get the file length */
if (getsize(vals[i]->v_file, &zfilelen) == 0) {
filelen = qalloc();
filelen->num = zfilelen;
qprintfd(filelen, 0L);
qfree(filelen);
} else {
/* getsize error */
printf("\tsize=unknown");
}
printf("\tsizeof=%ld\n", (long int)lsizeof(vals[i]));
} else {
printf("\tsize=%ld\tsizeof=%ld\n",
elm_count(vals[i]), (long int)lsizeof(vals[i]));
}
}
/*
* return count
*/
result.v_type = V_NUM;
result.v_num = itoq(count);
return result;
/*
* return count
*/
result.v_type = V_NUM;
result.v_num = itoq(count);
return result;
}
#endif /* CUSTOM */

View File

@@ -9,7 +9,7 @@
*
* 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
* 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
@@ -17,11 +17,11 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Under source code control: 1997/03/09 17:49:12
* File existed as early as: 1997
* Under source code control: 1997/03/09 17:49:12
* File existed as early as: 1997
*
* chongo <was here> /\oo/\ http://www.isthe.com/chongo/
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
* chongo <was here> /\oo/\ http://www.isthe.com/chongo/
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
*/
@@ -30,9 +30,9 @@
* so we declare a global variable whose value is based on if CUSTOM is defined.
*/
#if defined(CUSTOM)
int c_devnull_allowed = 1; /* CUSTOM defined */
int c_devnull_allowed = 1; /* CUSTOM defined */
#else /* CUSTOM */
int c_devnull_allowed = 0; /* CUSTOM undefined */
int c_devnull_allowed = 0; /* CUSTOM undefined */
#endif /* CUSTOM */
@@ -50,7 +50,7 @@ int c_devnull_allowed = 0; /* CUSTOM undefined */
#include "../have_unused.h"
#include "../banned.h" /* include after system header <> includes */
#include "../banned.h" /* include after system header <> includes */
/*
@@ -63,13 +63,13 @@ int c_devnull_allowed = 0; /* CUSTOM undefined */
VALUE
c_devnull(char *UNUSED(name), int UNUSED(count), VALUE **UNUSED(vals))
{
VALUE result; /* what we will return */
VALUE result; /* what we will return */
/*
* return NULL
*/
result.v_type = V_NULL;
return result;
/*
* return NULL
*/
result.v_type = V_NULL;
return result;
}
#endif /* CUSTOM */

View File

@@ -9,7 +9,7 @@
*
* 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
* 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
@@ -17,11 +17,11 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Under source code control: 1997/03/09 05:25:41
* File existed as early as: 1997
* Under source code control: 1997/03/09 05:25:41
* File existed as early as: 1997
*
* chongo <was here> /\oo/\ http://www.isthe.com/chongo/
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
* chongo <was here> /\oo/\ http://www.isthe.com/chongo/
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
*/
@@ -30,9 +30,9 @@
* so we declare a global variable whose value is based on if CUSTOM is defined.
*/
#if defined(CUSTOM)
int c_help_allowed = 1; /* CUSTOM defined */
int c_help_allowed = 1; /* CUSTOM defined */
#else /* CUSTOM */
int c_help_allowed = 0; /* CUSTOM undefined */
int c_help_allowed = 0; /* CUSTOM undefined */
#endif /* CUSTOM */
@@ -51,7 +51,7 @@ int c_help_allowed = 0; /* CUSTOM undefined */
#include "../errtbl.h"
#include "../banned.h" /* include after system header <> includes */
#include "../banned.h" /* include after system header <> includes */
/*
@@ -69,32 +69,32 @@ int c_help_allowed = 0; /* CUSTOM undefined */
* and HELPDIR file and work directly with the custom help file.
*
* given:
* vals[0] name of the custom help file to directly access
* vals[0] name of the custom help file to directly access
*/
/*ARGSUSED*/
VALUE
c_help(char *UNUSED(name), int UNUSED(count), VALUE **vals)
{
VALUE result; /* what we will return */
VALUE result; /* what we will return */
/*
* parse args
*/
if (vals[0]->v_type != V_STR) {
math_error("custom help arg 1 must be a string");
not_reached();
}
/*
* parse args
*/
if (vals[0]->v_type != V_STR) {
math_error("custom help arg 1 must be a string");
not_reached();
}
/*
* give the help
*/
customhelp((char *)vals[0]->v_str);
/*
* give the help
*/
customhelp((char *)vals[0]->v_str);
/*
* return NULL
*/
result.v_type = V_NULL;
return result;
/*
* return NULL
*/
result.v_type = V_NULL;
return result;
}
#endif /* CUSTOM */

View File

@@ -9,7 +9,7 @@
*
* 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
* 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
@@ -17,10 +17,10 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Under source code control: 2004/07/28 22:12:25
* File existed as early as: 2004
* Under source code control: 2004/07/28 22:12:25
* File existed as early as: 2004
*
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
*/
@@ -29,9 +29,9 @@
* so we declare a global variable whose value is based on if CUSTOM is defined.
*/
#if defined(CUSTOM)
int c_pmodm127_allowed = 1; /* CUSTOM defined */
int c_pmodm127_allowed = 1; /* CUSTOM defined */
#else /* CUSTOM */
int c_pmodm127_allowed = 0; /* CUSTOM undefined */
int c_pmodm127_allowed = 0; /* CUSTOM undefined */
#endif /* CUSTOM */
@@ -48,19 +48,19 @@ int c_pmodm127_allowed = 0; /* CUSTOM undefined */
#include "../errtbl.h"
#include "../banned.h" /* include after system header <> includes */
#include "../banned.h" /* include after system header <> includes */
/* 2^255 */
STATIC HALF h255[] = {
#if BASEB == 32
(HALF)0x00000000, (HALF)0x00000000, (HALF)0x00000000, (HALF)0x00000000,
(HALF)0x00000000, (HALF)0x00000000, (HALF)0x00000000, (HALF)0x80000000
(HALF)0x00000000, (HALF)0x00000000, (HALF)0x00000000, (HALF)0x00000000,
(HALF)0x00000000, (HALF)0x00000000, (HALF)0x00000000, (HALF)0x80000000
#else /* BASEB == 32 */
(HALF)0x0000, (HALF)0x0000, (HALF)0x0000, (HALF)0x0000,
(HALF)0x0000, (HALF)0x0000, (HALF)0x0000, (HALF)0x0000,
(HALF)0x0000, (HALF)0x0000, (HALF)0x0000, (HALF)0x0000,
(HALF)0x0000, (HALF)0x0000, (HALF)0x0000, (HALF)0x8000
(HALF)0x0000, (HALF)0x0000, (HALF)0x0000, (HALF)0x0000,
(HALF)0x0000, (HALF)0x0000, (HALF)0x0000, (HALF)0x0000,
(HALF)0x0000, (HALF)0x0000, (HALF)0x0000, (HALF)0x0000,
(HALF)0x0000, (HALF)0x0000, (HALF)0x0000, (HALF)0x8000
#endif /* BASEB == 32 */
};
ZVALUE p255 = {
@@ -80,109 +80,109 @@ STATIC ZVALUE lastmodinv[1];
*
* given:
* count = 1;
* vals[0] real number; (q - potential factor)
* vals[0] real number; (q - potential factor)
*
* returns:
* result real number; (q mod 2^(2^127-1))
* result real number; (q mod 2^(2^127-1))
*/
/*ARGSUSED*/
VALUE
c_pmodm127(char *UNUSED(name), int UNUSED(count), VALUE **vals)
{
VALUE result; /* what we will return */
ZVALUE q; /* test factor */
ZVALUE temp; /* temp calculation value */
int i; /* exponent value */
VALUE result; /* what we will return */
ZVALUE q; /* test factor */
ZVALUE temp; /* temp calculation value */
int i; /* exponent value */
/*
* arg check
*/
result.v_type = V_NULL;
if (vals[0]->v_type != V_NUM) {
math_error("Non-numeric argument for pmodm127");
not_reached();
}
if (qisfrac(vals[0]->v_num)) {
math_error("Non-integer argument for pmodm127");
not_reached();
}
if (qisneg(vals[0]->v_num) || qiszero(vals[0]->v_num)) {
math_error("argument for pmodm127 <= 0");
not_reached();
}
/*
* arg check
*/
result.v_type = V_NULL;
if (vals[0]->v_type != V_NUM) {
math_error("Non-numeric argument for pmodm127");
not_reached();
}
if (qisfrac(vals[0]->v_num)) {
math_error("Non-integer argument for pmodm127");
not_reached();
}
if (qisneg(vals[0]->v_num) || qiszero(vals[0]->v_num)) {
math_error("argument for pmodm127 <= 0");
not_reached();
}
/*
* look at the numerator
*/
q = vals[0]->v_num->num;
/*
* look at the numerator
*/
q = vals[0]->v_num->num;
/*
* setup lastmod with q
*/
if (havelastmod && zcmp(q, *lastmod)) {
zfree(*lastmod);
zfree(*lastmodinv);
havelastmod = false;
}
if (!havelastmod) {
zcopy(q, lastmod);
zbitvalue(2 * q.len * BASEB, &temp);
zquo(temp, q, lastmodinv, 0);
zfree(temp);
havelastmod = true;
}
/*
* setup lastmod with q
*/
if (havelastmod && zcmp(q, *lastmod)) {
zfree(*lastmod);
zfree(*lastmodinv);
havelastmod = false;
}
if (!havelastmod) {
zcopy(q, lastmod);
zbitvalue(2 * q.len * BASEB, &temp);
zquo(temp, q, lastmodinv, 0);
zfree(temp);
havelastmod = true;
}
/*
* start with 2^255
*/
result.v_num = qalloc();
zcopy(p255, &result.v_num->num);
result.v_type = V_NUM;
/*
* start with 2^255
*/
result.v_num = qalloc();
zcopy(p255, &result.v_num->num);
result.v_type = V_NUM;
/*
* compute 2^(2^127-1) mod q by modular exponentiation
*
* We implement the following calc code in C:
*
* (* given q, our test factor, as the arg to this function *)
* result = 2^255;
* for (i=8; i < 127; ++i) {
* result %= q; (* mod *)
* result *= result; (* square *)
* result <<= 1; (* times 2 *)
* }
* result %= q; (* result is now 2^(2^127-1) % q *)
*/
for (i=8; i<127; ++i) {
/*
* compute 2^(2^127-1) mod q by modular exponentiation
*
* We implement the following calc code in C:
*
* (* given q, our test factor, as the arg to this function *)
* result = 2^255;
* for (i=8; i < 127; ++i) {
* result %= q; (* mod *)
* result *= result; (* square *)
* result <<= 1; (* times 2 *)
* }
* result %= q; (* result is now 2^(2^127-1) % q *)
*/
for (i=8; i<127; ++i) {
#if 0
/* use of zmod is a bit slower than zmod5_or_zmod */
(void) zmod(result.v_num->num, *lastmod, &temp, 0);
zfree(result.v_num->num);
result.v_num->num = temp;
/* use of zmod is a bit slower than zmod5_or_zmod */
(void) zmod(result.v_num->num, *lastmod, &temp, 0);
zfree(result.v_num->num);
result.v_num->num = temp;
#else
zmod5_or_zmod(&result.v_num->num); /* mod */
zmod5_or_zmod(&result.v_num->num); /* mod */
#endif
#if 0
/* use of zmul is slightly slower than zsquare */
zmul(result.v_num->num, result.v_num->num, &temp); /* square */
/* use of zmul is slightly slower than zsquare */
zmul(result.v_num->num, result.v_num->num, &temp); /* square */
#else
zsquare(result.v_num->num, &temp); /* square */
zsquare(result.v_num->num, &temp); /* square */
#endif
/*
* We could manually shift here, but this would o speed
* up the operation only a very tiny bit at the expense
* of a bunch of special code.
*/
zfree(result.v_num->num);
zshift(temp, 1, &result.v_num->num); /* times 2 */
zfree(temp);
}
zmod5_or_zmod(&result.v_num->num); /* result = 2^(2^127-1) % q */
/*
* We could manually shift here, but this would o speed
* up the operation only a very tiny bit at the expense
* of a bunch of special code.
*/
zfree(result.v_num->num);
zshift(temp, 1, &result.v_num->num); /* times 2 */
zfree(temp);
}
zmod5_or_zmod(&result.v_num->num); /* result = 2^(2^127-1) % q */
/*
* cleanup and return result
*/
return result;
/*
* cleanup and return result
*/
return result;
}
@@ -202,87 +202,87 @@ c_pmodm127(char *UNUSED(name), int UNUSED(count), VALUE **vals)
S_FUNC void
zmod5_or_zmod(ZVALUE *zp)
{
LEN len, modlen, j;
ZVALUE tmp1, tmp2;
ZVALUE z1, z2, z3;
HALF *a, *b;
FULL f;
HALF u;
LEN len, modlen, j;
ZVALUE tmp1, tmp2;
ZVALUE z1, z2, z3;
HALF *a, *b;
FULL f;
HALF u;
int subcount = 0;
int subcount = 0;
if (zrel(*zp, *lastmod) < 0)
return;
modlen = lastmod->len;
len = zp->len;
z1.v = zp->v + modlen - 1;
z1.len = len - modlen + 1;
z1.sign = z2.sign = z3.sign = 0;
if (z1.len > modlen + 1) {
/* in ../zmod.c we did a math_error("Bad call to zmod5!!!"); */
/* here we just call the slower zmod and return the result */
(void) zmod(*zp, *lastmod, &tmp1, 0);
/* replace zp with tmp1 mod result */
zfree(*zp);
*zp = tmp1;
return;
}
z2.v = lastmodinv->v + modlen + 1 - z1.len;
z2.len = lastmodinv->len - modlen - 1 + z1.len;
zmul(z1, z2, &tmp1);
z3.v = tmp1.v + z1.len;
z3.len = tmp1.len - z1.len;
if (z3.len > 0) {
zmul(z3, *lastmod, &tmp2);
j = modlen;
a = zp->v;
b = tmp2.v;
u = 0;
len = modlen;
while (j-- > 0) {
f = (FULL) *a - (FULL) *b++ - (FULL) u;
*a++ = (HALF) f;
u = - (HALF) (f >> BASEB);
}
if (z1.len > 1) {
len++;
if (tmp2.len > modlen)
f = (FULL) *a - (FULL) *b - (FULL) u;
else
f = (FULL) *a - (FULL) u;
*a++ = (HALF) f;
}
while (len > 0 && *--a == 0)
len--;
zp->len = len;
zfree(tmp2);
}
zfree(tmp1);
while (len > 0 && zrel(*zp, *lastmod) >= 0) {
subcount++;
if (subcount > 2) {
math_error("Too many subtractions in zmod5_or_zmod");
not_reached();
}
j = modlen;
a = zp->v;
b = lastmod->v;
u = 0;
while (j-- > 0) {
f = (FULL) *a - (FULL) *b++ - (FULL) u;
*a++ = (HALF) f;
u = - (HALF) (f >> BASEB);
}
if (len > modlen) {
f = (FULL) *a - (FULL) u;
*a++ = (HALF) f;
}
while (len > 0 && *--a == 0)
len--;
zp->len = len;
}
if (len == 0)
zp->len = 1;
if (zrel(*zp, *lastmod) < 0)
return;
modlen = lastmod->len;
len = zp->len;
z1.v = zp->v + modlen - 1;
z1.len = len - modlen + 1;
z1.sign = z2.sign = z3.sign = 0;
if (z1.len > modlen + 1) {
/* in ../zmod.c we did a math_error("Bad call to zmod5!!!"); */
/* here we just call the slower zmod and return the result */
(void) zmod(*zp, *lastmod, &tmp1, 0);
/* replace zp with tmp1 mod result */
zfree(*zp);
*zp = tmp1;
return;
}
z2.v = lastmodinv->v + modlen + 1 - z1.len;
z2.len = lastmodinv->len - modlen - 1 + z1.len;
zmul(z1, z2, &tmp1);
z3.v = tmp1.v + z1.len;
z3.len = tmp1.len - z1.len;
if (z3.len > 0) {
zmul(z3, *lastmod, &tmp2);
j = modlen;
a = zp->v;
b = tmp2.v;
u = 0;
len = modlen;
while (j-- > 0) {
f = (FULL) *a - (FULL) *b++ - (FULL) u;
*a++ = (HALF) f;
u = - (HALF) (f >> BASEB);
}
if (z1.len > 1) {
len++;
if (tmp2.len > modlen)
f = (FULL) *a - (FULL) *b - (FULL) u;
else
f = (FULL) *a - (FULL) u;
*a++ = (HALF) f;
}
while (len > 0 && *--a == 0)
len--;
zp->len = len;
zfree(tmp2);
}
zfree(tmp1);
while (len > 0 && zrel(*zp, *lastmod) >= 0) {
subcount++;
if (subcount > 2) {
math_error("Too many subtractions in zmod5_or_zmod");
not_reached();
}
j = modlen;
a = zp->v;
b = lastmod->v;
u = 0;
while (j-- > 0) {
f = (FULL) *a - (FULL) *b++ - (FULL) u;
*a++ = (HALF) f;
u = - (HALF) (f >> BASEB);
}
if (len > modlen) {
f = (FULL) *a - (FULL) u;
*a++ = (HALF) f;
}
while (len > 0 && *--a == 0)
len--;
zp->len = len;
}
if (len == 0)
zp->len = 1;
}
#endif /* CUSTOM */

View File

@@ -9,7 +9,7 @@
*
* 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
* 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
@@ -17,10 +17,10 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Under source code control: 1999/10/06 03:12:25
* File existed as early as: 1999
* Under source code control: 1999/10/06 03:12:25
* File existed as early as: 1999
*
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
*/
@@ -29,9 +29,9 @@
* so we declare a global variable whose value is based on if CUSTOM is defined.
*/
#if defined(CUSTOM)
int c_pzasusb8_allowed = 1; /* CUSTOM defined */
int c_pzasusb8_allowed = 1; /* CUSTOM defined */
#else /* CUSTOM */
int c_pzasusb8_allowed = 0; /* CUSTOM undefined */
int c_pzasusb8_allowed = 0; /* CUSTOM undefined */
#endif /* CUSTOM */
@@ -48,7 +48,7 @@ int c_pzasusb8_allowed = 0; /* CUSTOM undefined */
#include "../errtbl.h"
#include "../banned.h" /* include after system header <> includes */
#include "../banned.h" /* include after system header <> includes */
/*
@@ -56,7 +56,7 @@ int c_pzasusb8_allowed = 0; /* CUSTOM undefined */
*
* given:
* count = 1;
* vals[0] real number;
* vals[0] real number;
*
* returns:
* null
@@ -65,42 +65,42 @@ int c_pzasusb8_allowed = 0; /* CUSTOM undefined */
VALUE
c_pzasusb8(char *UNUSED(name), int UNUSED(count), VALUE **vals)
{
VALUE result; /* what we will return */
ZVALUE z; /* numerator of the value */
long half_cnt; /* number of HALFs in the numerator */
USB8 *h; /* octet pointer */
long half_len; /* length of a half in octets */
long i;
long j;
VALUE result; /* what we will return */
ZVALUE z; /* numerator of the value */
long half_cnt; /* number of HALFs in the numerator */
USB8 *h; /* octet pointer */
long half_len; /* length of a half in octets */
long i;
long j;
/*
* arg check
*/
result.v_type = V_NULL;
if (vals[0]->v_type != V_NUM) {
math_error("Non-real argument for pzasusb8");
not_reached();
}
/*
* arg check
*/
result.v_type = V_NULL;
if (vals[0]->v_type != V_NUM) {
math_error("Non-real argument for pzasusb8");
not_reached();
}
/*
* look at the numerator
*/
z = vals[0]->v_num->num;
half_len = sizeof(HALF);
half_cnt = z.len;
/*
* look at the numerator
*/
z = vals[0]->v_num->num;
half_len = sizeof(HALF);
half_cnt = z.len;
/*
* print the octets
*/
h = (USB8 *) z.v;
for (i=0; i < half_cnt; ++i) {
printf("%ld:\t", i);
for (j=0; j < half_len; ++j) {
printf("%02x", (int)(*h++));
}
putchar('\n');
}
return result;
/*
* print the octets
*/
h = (USB8 *) z.v;
for (i=0; i < half_cnt; ++i) {
printf("%ld:\t", i);
for (j=0; j < half_len; ++j) {
printf("%02x", (int)(*h++));
}
putchar('\n');
}
return result;
}
#endif /* CUSTOM */

View File

@@ -9,7 +9,7 @@
*
* 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
* 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
@@ -17,11 +17,11 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Under source code control: 2007/07/14 20:23:46
* File existed as early as: 2007
* Under source code control: 2007/07/14 20:23:46
* File existed as early as: 2007
*
* chongo <was here> /\oo/\ http://www.isthe.com/chongo/
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
* chongo <was here> /\oo/\ http://www.isthe.com/chongo/
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
*/
@@ -30,9 +30,9 @@
* so we declare a global variable whose value is based on if CUSTOM is defined.
*/
#if defined(CUSTOM)
int c_register_allowed = 1; /* CUSTOM defined */
int c_register_allowed = 1; /* CUSTOM defined */
#else /* CUSTOM */
int c_register_allowed = 0; /* CUSTOM undefined */
int c_register_allowed = 0; /* CUSTOM undefined */
#endif /* CUSTOM */
@@ -51,7 +51,7 @@ int c_register_allowed = 0; /* CUSTOM undefined */
#include "../errtbl.h"
#include "../banned.h" /* include after system header <> includes */
#include "../banned.h" /* include after system header <> includes */
/*
@@ -66,17 +66,17 @@ STATIC VALUE custom_reg[CUSTOM_REG_MAX+1];
void
init_custreg(void)
{
int i;
int i;
/*
* set the registers to zero
*/
for (i=0; i < CUSTOM_REG_MAX+1; ++i) {
custom_reg[i].v_type = V_NUM;
custom_reg[i].v_subtype = V_NOSUBTYPE;
custom_reg[i].v_num = itoq(0);
}
return;
/*
* set the registers to zero
*/
for (i=0; i < CUSTOM_REG_MAX+1; ++i) {
custom_reg[i].v_type = V_NUM;
custom_reg[i].v_subtype = V_NOSUBTYPE;
custom_reg[i].v_num = itoq(0);
}
return;
}
@@ -84,58 +84,58 @@ init_custreg(void)
* c_register - set or print a custom register value
*
* given:
* vals[i] and arg to display information about
* vals[i] and arg to display information about
*
* returns:
* count
* count
*/
/*ARGSUSED*/
VALUE
c_register(char *UNUSED(name), int count, VALUE **vals)
{
VALUE result; /* what we will return */
long reg; /* register number */
VALUE result; /* what we will return */
long reg; /* register number */
/*
* arg check
*/
result.v_type = V_NULL;
if (vals[0]->v_type != V_NUM) {
math_error("Non-numeric register number");
not_reached();
}
if (qisfrac(vals[0]->v_num)) {
math_error("Non-integer register number");
not_reached();
}
if (qisneg(vals[0]->v_num)) {
math_error("register number < 0");
not_reached();
}
if (! qistiny(vals[0]->v_num)) {
math_error("register is huge");
not_reached();
}
reg = qtoi(vals[0]->v_num);
if (reg > CUSTOM_REG_MAX) {
math_error("register is larger than CUSTOM_REG_MAX");
not_reached();
}
/*
* arg check
*/
result.v_type = V_NULL;
if (vals[0]->v_type != V_NUM) {
math_error("Non-numeric register number");
not_reached();
}
if (qisfrac(vals[0]->v_num)) {
math_error("Non-integer register number");
not_reached();
}
if (qisneg(vals[0]->v_num)) {
math_error("register number < 0");
not_reached();
}
if (! qistiny(vals[0]->v_num)) {
math_error("register is huge");
not_reached();
}
reg = qtoi(vals[0]->v_num);
if (reg > CUSTOM_REG_MAX) {
math_error("register is larger than CUSTOM_REG_MAX");
not_reached();
}
/*
* print info on each arg
*/
/* save previous value */
copyvalue(&custom_reg[reg], &result);
/* set the new value if a 2nd arg was given */
if (count == 2) {
copyvalue(vals[1], &custom_reg[reg]);
}
/*
* print info on each arg
*/
/* save previous value */
copyvalue(&custom_reg[reg], &result);
/* set the new value if a 2nd arg was given */
if (count == 2) {
copyvalue(vals[1], &custom_reg[reg]);
}
/*
* return result
*/
return result;
/*
* return result
*/
return result;
}
#endif /* CUSTOM */

View File

@@ -9,7 +9,7 @@
*
* 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
* 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
@@ -17,11 +17,11 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Under source code control: 1997/03/09 23:14:40
* File existed as early as: 1997
* Under source code control: 1997/03/09 23:14:40
* File existed as early as: 1997
*
* chongo <was here> /\oo/\ http://www.isthe.com/chongo/
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
* chongo <was here> /\oo/\ http://www.isthe.com/chongo/
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
*/
@@ -30,9 +30,9 @@
* so we declare a global variable whose value is based on if CUSTOM is defined.
*/
#if defined(CUSTOM)
int c_sysinfo_allowed = 1; /* CUSTOM defined */
int c_sysinfo_allowed = 1; /* CUSTOM defined */
#else /* CUSTOM */
int c_sysinfo_allowed = 0; /* CUSTOM undefined */
int c_sysinfo_allowed = 0; /* CUSTOM undefined */
#endif /* CUSTOM */
@@ -68,17 +68,17 @@ int c_sysinfo_allowed = 0; /* CUSTOM undefined */
#include "../errtbl.h"
#include "../banned.h" /* include after system header <> includes */
#include "../banned.h" /* include after system header <> includes */
/*
* sys_info - names and values of selected #defines
*/
struct infoname {
char *name; /* name of #define converted to all UPPER_CASE */
char *meaning; /* brief explanation of the #define */
char *str; /* non-NULL ==> value of #define is a string */
FULL nmbr; /* if str==NULL ==> value fo #define as a FULL */
char *name; /* name of #define converted to all UPPER_CASE */
char *meaning; /* brief explanation of the #define */
char *str; /* non-NULL ==> value of #define is a string */
FULL nmbr; /* if str==NULL ==> value fo #define as a FULL */
};
STATIC struct infoname sys_info[] = {
{"S100", "slots in an subtractive 100 table", NULL,
@@ -254,130 +254,130 @@ STATIC struct infoname sys_info[] = {
/*
* forward declarations
*/
S_FUNC void dump_name_meaning(void); /* custom("sysinfo", 0) */
S_FUNC void dump_name_value(void); /* custom("sysinfo", 1) */
S_FUNC void dump_mening_value(void); /* custom("sysinfo", 2) */
S_FUNC void dump_name_meaning(void); /* custom("sysinfo", 0) */
S_FUNC void dump_name_value(void); /* custom("sysinfo", 1) */
S_FUNC void dump_mening_value(void); /* custom("sysinfo", 2) */
/*
* c_sysinfo - return a calc #define value
*
* given:
* vals[0] if given, name of #define to print
* otherwise a list of #defines are printed
* vals[0] if given, name of #define to print
* otherwise a list of #defines are printed
*
* returns:
* value of #define if given (int or string)
* null if no #define arg was given
* value of #define if given (int or string)
* null if no #define arg was given
*/
/*ARGSUSED*/
VALUE
c_sysinfo(char *UNUSED(name), int count, VALUE **vals)
{
VALUE result; /* what we will return */
struct infoname *p; /* current infoname */
char *buf; /* upper case value of vals[0] */
char *q; /* to upper case converter */
char *r; /* to upper case converter */
VALUE result; /* what we will return */
struct infoname *p; /* current infoname */
char *buf; /* upper case value of vals[0] */
char *q; /* to upper case converter */
char *r; /* to upper case converter */
/*
* we will return NULL if a value was not found
*/
result.v_type = V_NULL;
result.v_subtype = V_NOSUBTYPE;
/*
* we will return NULL if a value was not found
*/
result.v_type = V_NULL;
result.v_subtype = V_NOSUBTYPE;
/*
* case 0: if no args, then dump the table with no values
*/
if (count == 0) {
/*
* case 0: if no args, then dump the table with no values
*/
if (count == 0) {
/* dump the entire table */
dump_name_meaning();
/* dump the entire table */
dump_name_meaning();
/*
* case 1: numeric arg is given
*/
} else if (vals[0]->v_type == V_NUM) {
/*
* case 1: numeric arg is given
*/
} else if (vals[0]->v_type == V_NUM) {
/* firewall - must be a tiny non-negative integer */
if (qisneg(vals[0]->v_num) ||
qisfrac(vals[0]->v_num) ||
zge31b(vals[0]->v_num->num)) {
math_error("sysinfo: arg must be string, 0, 1 or 2");
not_reached();
}
/* firewall - must be a tiny non-negative integer */
if (qisneg(vals[0]->v_num) ||
qisfrac(vals[0]->v_num) ||
zge31b(vals[0]->v_num->num)) {
math_error("sysinfo: arg must be string, 0, 1 or 2");
not_reached();
}
/*
* select action based on numeric value of arg
*/
switch (z1tol(vals[0]->v_num->num)) {
case 0: /* print all infonames and meanings */
dump_name_meaning();
break;
case 1: /* print all infonames and values */
dump_name_value();
break;
case 2: /* print all values and meanings */
dump_mening_value();
break;
default:
math_error("sysinfo: arg must be string, 0, 1 or 2");
not_reached();
}
/*
* select action based on numeric value of arg
*/
switch (z1tol(vals[0]->v_num->num)) {
case 0: /* print all infonames and meanings */
dump_name_meaning();
break;
case 1: /* print all infonames and values */
dump_name_value();
break;
case 2: /* print all values and meanings */
dump_mening_value();
break;
default:
math_error("sysinfo: arg must be string, 0, 1 or 2");
not_reached();
}
/*
* case 2: string arg is given
*
* The string is taken to be the infoname we want to print.
*/
} else if (vals[0]->v_type == V_STR) {
/*
* case 2: string arg is given
*
* The string is taken to be the infoname we want to print.
*/
} else if (vals[0]->v_type == V_STR) {
/* convert vals[0] to upper case string */
buf = (char *)malloc(strlen((char *)vals[0]->v_str->s_str)+1);
for (q = (char *)vals[0]->v_str->s_str, r = buf; *q; ++q, ++r)
{
if (isascii((int)*q) && islower((int)*q)) {
*r = *q - 'a' + 'A';
} else {
*r = *q;
}
}
*r = '\0';
/* convert vals[0] to upper case string */
buf = (char *)malloc(strlen((char *)vals[0]->v_str->s_str)+1);
for (q = (char *)vals[0]->v_str->s_str, r = buf; *q; ++q, ++r)
{
if (isascii((int)*q) && islower((int)*q)) {
*r = *q - 'a' + 'A';
} else {
*r = *q;
}
}
*r = '\0';
/* search the table for the infoname */
for (p = sys_info; p->name != NULL; ++p) {
/* search the table for the infoname */
for (p = sys_info; p->name != NULL; ++p) {
if (strcmp(p->name, buf) == 0) {
if (strcmp(p->name, buf) == 0) {
/* found the infoname */
if (p->str == NULL) {
/* return value as integer */
result.v_type = V_NUM;
result.v_num = utoq( p->nmbr);
} else {
/* return value as string */
result.v_type = V_STR;
result.v_subtype = V_NOSUBTYPE;
result.v_str = makestring(p->str);
}
/* found the infoname */
if (p->str == NULL) {
/* return value as integer */
result.v_type = V_NUM;
result.v_num = utoq( p->nmbr);
} else {
/* return value as string */
result.v_type = V_STR;
result.v_subtype = V_NOSUBTYPE;
result.v_str = makestring(p->str);
}
/* return found infotype as value */
break;
}
}
/* return found infotype as value */
break;
}
}
/*
* bad arg given
*/
} else {
math_error("sysinfo: arg must be string, 0, 1 or 2");
not_reached();
}
/*
* bad arg given
*/
} else {
math_error("sysinfo: arg must be string, 0, 1 or 2");
not_reached();
}
/*
* return what we found or didn't find
*/
return result;
/*
* return what we found or didn't find
*/
return result;
}
@@ -387,13 +387,13 @@ c_sysinfo(char *UNUSED(name), int count, VALUE **vals)
S_FUNC void
dump_name_meaning(void)
{
struct infoname *p; /* current infoname */
struct infoname *p; /* current infoname */
/* dump the entire table */
for (p = sys_info; p->name != NULL; ++p) {
printf("%s%-23s\t%s\n",
(conf->tab_ok ? "\t" : ""), p->name, p->meaning);
}
/* dump the entire table */
for (p = sys_info; p->name != NULL; ++p) {
printf("%s%-23s\t%s\n",
(conf->tab_ok ? "\t" : ""), p->name, p->meaning);
}
}
@@ -404,27 +404,27 @@ dump_name_meaning(void)
S_FUNC void
dump_name_value(void)
{
struct infoname *p; /* current infoname */
struct infoname *p; /* current infoname */
/* dump the entire table */
for (p = sys_info; p->name != NULL; ++p) {
if (p->str == NULL) {
/* dump the entire table */
for (p = sys_info; p->name != NULL; ++p) {
if (p->str == NULL) {
#if LONG_BITS == FULL_BITS || FULL_BITS == 32
printf("%s%-23s\t%-8lu\t(0x%lx)\n",
(conf->tab_ok ? "\t" : ""), p->name,
(unsigned long)p->nmbr,
(unsigned long)p->nmbr);
printf("%s%-23s\t%-8lu\t(0x%lx)\n",
(conf->tab_ok ? "\t" : ""), p->name,
(unsigned long)p->nmbr,
(unsigned long)p->nmbr);
#else
printf("%s%-23s\t%-8llu\t(0x%llx)\n",
(conf->tab_ok ? "\t" : ""), p->name,
(unsigned long long)p->nmbr,
(unsigned long long)p->nmbr);
printf("%s%-23s\t%-8llu\t(0x%llx)\n",
(conf->tab_ok ? "\t" : ""), p->name,
(unsigned long long)p->nmbr,
(unsigned long long)p->nmbr);
#endif
} else {
printf("%s%-23s\t\"%s\"\n",
(conf->tab_ok ? "\t" : ""), p->name, p->str);
}
}
} else {
printf("%s%-23s\t\"%s\"\n",
(conf->tab_ok ? "\t" : ""), p->name, p->str);
}
}
}
@@ -435,27 +435,27 @@ dump_name_value(void)
S_FUNC void
dump_mening_value(void)
{
struct infoname *p; /* current infoname */
struct infoname *p; /* current infoname */
/* dump the entire table */
for (p = sys_info; p->name != NULL; ++p) {
if (p->str == NULL) {
/* dump the entire table */
for (p = sys_info; p->name != NULL; ++p) {
if (p->str == NULL) {
#if LONG_BITS == FULL_BITS || FULL_BITS == 32
printf("%s%-36.36s\t%-8lu\t(0x%lx)\n",
(conf->tab_ok ? "\t" : ""), p->meaning,
(unsigned long)p->nmbr,
(unsigned long)p->nmbr);
printf("%s%-36.36s\t%-8lu\t(0x%lx)\n",
(conf->tab_ok ? "\t" : ""), p->meaning,
(unsigned long)p->nmbr,
(unsigned long)p->nmbr);
#else
printf("%s%-36.36s\t%-8llu\t(0x%llx)\n",
(conf->tab_ok ? "\t" : ""), p->meaning,
(unsigned long long)p->nmbr,
(unsigned long long)p->nmbr);
printf("%s%-36.36s\t%-8llu\t(0x%llx)\n",
(conf->tab_ok ? "\t" : ""), p->meaning,
(unsigned long long)p->nmbr,
(unsigned long long)p->nmbr);
#endif
} else {
printf("%s%-36.36s\t\"%s\"\n",
(conf->tab_ok ? "\t" : ""), p->meaning, p->str);
}
}
} else {
printf("%s%-36.36s\t\"%s\"\n",
(conf->tab_ok ? "\t" : ""), p->meaning, p->str);
}
}
}

View File

@@ -9,7 +9,7 @@
*
* 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
* 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
@@ -17,11 +17,11 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Under source code control: 1997/03/09 02:28:54
* File existed as early as: 1997
* Under source code control: 1997/03/09 02:28:54
* File existed as early as: 1997
*
* chongo <was here> /\oo/\ http://www.isthe.com/chongo/
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
* chongo <was here> /\oo/\ http://www.isthe.com/chongo/
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
*/
@@ -33,23 +33,23 @@
#include "../errtbl.h"
#include "../banned.h" /* include after system header <> includes */
#include "../banned.h" /* include after system header <> includes */
/*
* custom_compiled - determine if custom functions are compiled into libcustcalc
*
* returns:
s* true ==> libcustcalc was compiled with CUSTOM defined
* false ==> libcustcalc was compiled with CUSTOM undefined
s* true ==> libcustcalc was compiled with CUSTOM defined
* false ==> libcustcalc was compiled with CUSTOM undefined
*/
E_FUNC bool
custom_compiled(void)
{
#if defined(CUSTOM)
return true;
return true;
#else /* CUSTOM */
return false;
return false;
#endif /* CUSTOM */
}
@@ -67,7 +67,7 @@ custom_compiled(void)
*
* Declare custom functions as follows:
*
* E_FUNC VALUE c_xyz(char*, int, VALUE**);
* E_FUNC VALUE c_xyz(char*, int, VALUE**);
*
* We suggest that you sort the entries below by name.
*/
@@ -88,13 +88,13 @@ E_FUNC VALUE c_register(char*, int, VALUE**);
*
* The order of the elements in struct custom are:
*
* { "xyz", "brief description of the xyz custom function",
* minimum_args, maximum_args, c_xyz },
* { "xyz", "brief description of the xyz custom function",
* minimum_args, maximum_args, c_xyz },
*
* where:
*
* minimum_args an int >= 0
* maximum_args an int >= minimum_args and <= MAX_CUSTOM_ARGS
* minimum_args an int >= 0
* maximum_args an int >= minimum_args and <= MAX_CUSTOM_ARGS
*
* Use MAX_CUSTOM_ARGS for maximum_args is the maximum number of args
* is potentially 'unlimited'.
@@ -108,40 +108,40 @@ CONST struct custom cust[] = {
#if defined(CUSTOM)
/*
* add your own custom functions here
*
* We suggest that you sort the entries below by name
* so that show custom will produce a nice sorted list.
*/
/*
* add your own custom functions here
*
* We suggest that you sort the entries below by name
* so that show custom will produce a nice sorted list.
*/
{ "argv", "information about its args, returns arg count",
0, MAX_CUSTOM_ARGS, c_argv },
{ "argv", "information about its args, returns arg count",
0, MAX_CUSTOM_ARGS, c_argv },
{ "devnull", "does nothing",
0, MAX_CUSTOM_ARGS, c_devnull },
{ "devnull", "does nothing",
0, MAX_CUSTOM_ARGS, c_devnull },
{ "help", "help for custom functions",
1, 1, c_help },
{ "help", "help for custom functions",
1, 1, c_help },
{ "sysinfo", "return a calc #define value",
0, 1, c_sysinfo },
{ "sysinfo", "return a calc #define value",
0, 1, c_sysinfo },
{ "pzasusb8", "print ZVALUE as USB8",
0, 1, c_pzasusb8 },
{ "pzasusb8", "print ZVALUE as USB8",
0, 1, c_pzasusb8 },
{ "pmodm127", "calculate q mod 2^(2^127-1)",
1, 1, c_pmodm127 },
{ "pmodm127", "calculate q mod 2^(2^127-1)",
1, 1, c_pmodm127 },
{ "register", "get or set customer registers",
1, 2, c_register },
{ "register", "get or set customer registers",
1, 2, c_register },
#endif /* CUSTOM */
/*
* This must be at the end of this table!!!
*/
{NULL, NULL,
0, 0, NULL}
/*
* This must be at the end of this table!!!
*/
{NULL, NULL,
0, 0, NULL}
};

View File

@@ -5,12 +5,12 @@ SYNOPSIS
custom("devnull" [, arg ...])
TYPES
arg any
arg any
return null
return null
DESCRIPTION
This custom function does nothing. It is intended for testing
This custom function does nothing. It is intended for testing
of the general custom interface.
EXAMPLE
@@ -34,7 +34,7 @@ SEE ALSO
##
## 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
## 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
@@ -42,8 +42,8 @@ SEE ALSO
## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
##
## Under source code control: 1997/03/09 17:49:12
## File existed as early as: 1997
## Under source code control: 1997/03/09 17:49:12
## File existed as early as: 1997
##
## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/

View File

@@ -9,7 +9,7 @@
*
* 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
* 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
@@ -17,55 +17,55 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Under source code control: 1997/03/08 20:51:32
* File existed as early as: 1997
* Under source code control: 1997/03/08 20:51:32
* File existed as early as: 1997
*
* chongo <was here> /\oo/\ http://www.isthe.com/chongo/
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
* chongo <was here> /\oo/\ http://www.isthe.com/chongo/
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
*/
/*
* This file is part of the custom sample calc files.
*
* NOTE: You must use a calc that was compiled with ALLOW_CUSTOM= -DCUSTOM
* and run with a -C arg.
* and run with a -C arg.
*/
if (config("compile_custom") == 0) {
quit "calc compiled without -DCUSTOM";
quit "calc compiled without -DCUSTOM";
} else if (config("allow_custom") == 0) {
quit "calc was run without the -D command line option";
quit "calc was run without the -D command line option";
}
define halflen(num)
{
local baseb; /* bit len of a HALF */
local baseb; /* bit len of a HALF */
/*
* firewall
*/
if (!isnum(num)) {
return newerror("halflen only works on numeric values");
}
/*
* firewall
*/
if (!isnum(num)) {
return newerror("halflen only works on numeric values");
}
/*
* determine baseb
*/
baseb = custom("sysinfo","BASEB");
/*
* determine baseb
*/
baseb = custom("sysinfo","BASEB");
/*
* determine the HALF length of a numeric value
*/
if (num == 0) {
/* consider 0 to be 1 HALF long */
return 1;
} else if (isint(num)) {
return (highbit(num)+baseb-1)/baseb;
} else if (isreal(num)) {
return halflen(num(num)) + halflen(den(num));
} else if (isnum(num)) {
return halflen(re(num)) + halflen(im(num));
} else {
return newerror("halflen only works on numeric values");
}
/*
* determine the HALF length of a numeric value
*/
if (num == 0) {
/* consider 0 to be 1 HALF long */
return 1;
} else if (isint(num)) {
return (highbit(num)+baseb-1)/baseb;
} else if (isreal(num)) {
return halflen(num(num)) + halflen(den(num));
} else if (isnum(num)) {
return halflen(re(num)) + halflen(im(num));
} else {
return newerror("halflen only works on numeric values");
}
}

View File

@@ -5,9 +5,9 @@ SYNOPSIS
custom("help", name)
TYPES
name string
name string
return null
return null
DESCRIPTION
This custom function will display the help for the builtin function
@@ -35,7 +35,7 @@ SEE ALSO
##
## 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
## 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
@@ -43,8 +43,8 @@ SEE ALSO
## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
##
## Under source code control: 1997/03/09 06:03:58
## File existed as early as: 1997
## Under source code control: 1997/03/09 06:03:58
## File existed as early as: 1997
##
## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/

View File

@@ -5,40 +5,40 @@ SYNOPSIS
custom("pmodm127", q)
TYPES
q int > 0
q int > 0
return int
return int
DESCRIPTION
This custom function will return the value:
q mod 2^(2^127-1)
q mod 2^(2^127-1)
This custom function serves as a demonstration of how to write
a custom function. It performs the equivalent of:
pmod(2, 2^127-1, q)
pmod(2, 2^127-1, q)
The return value is integer in the half open range: [0, q).
SPECIAL NOTE:
Can you find a value, q, for which this custom function returns 1?
If you do, send the value of q to chongo using the Email address
found at:
Can you find a value, q, for which this custom function returns 1?
If you do, send the value of q to chongo using the Email address
found at:
http://www.isthe.com/chongo/address.html
http://www.isthe.com/chongo/address.html
EXAMPLE
> custom("pmodm127", 65537)
32769
32769
> custom("pmodm127", 2^31-1)
8
8
> custom("pmodm127", 7^51+2)
11228202966269457258557496419097462731193173
11228202966269457258557496419097462731193173
LIMITS
calc must be built with ALLOW_CUSTOM= -DCUSTOM
@@ -59,7 +59,7 @@ SEE ALSO
##
## 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
## 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
@@ -67,8 +67,8 @@ SEE ALSO
## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
##
## Under source code control: 2004/02/25 07:13:15
## File existed as early as: 2004
## Under source code control: 2004/02/25 07:13:15
## File existed as early as: 2004
##
## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/

View File

@@ -9,7 +9,7 @@
*
* 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
* 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
@@ -17,116 +17,116 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Under source code control: 2004/02/25 14:25:32
* File existed as early as: 2004
* Under source code control: 2004/02/25 14:25:32
* File existed as early as: 2004
*
* chongo <was here> /\oo/\ http://www.isthe.com/chongo/
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
* chongo <was here> /\oo/\ http://www.isthe.com/chongo/
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
*/
/*
* This file is part of the custom sample calc files.
*
* NOTE: You must use a calc that was compiled with ALLOW_CUSTOM= -DCUSTOM
* and run with a -C arg.
* and run with a -C arg.
*/
if (config("compile_custom") == 0) {
quit "calc compiled without -DCUSTOM";
quit "calc compiled without -DCUSTOM";
} else if (config("allow_custom") == 0) {
quit "calc was run without the -D command line option";
quit "calc was run without the -D command line option";
}
define pmodm127_test1(testcnt)
{
local q; /* test factor */
local m127; /* 2^127-1 */
local i;
local q; /* test factor */
local m127; /* 2^127-1 */
local i;
/*
* firewall
*/
if (!isint(testcnt) || testcnt <= 0) {
return newerror("pmodm127_test1 must have an integer count>0");
}
/*
* firewall
*/
if (!isint(testcnt) || testcnt <= 0) {
return newerror("pmodm127_test1 must have an integer count>0");
}
/*
* perform testcnt divisor tests for primes of form 2*k*(2^127-1)+1
*
* NOTE: Since this is just a test, we do not need to be optimal.
*/
m127 = 2^127 - 1;
q = 2*4949132165849*m127+1;
for (i=0; i < testcnt; ++i) {
/*
* perform testcnt divisor tests for primes of form 2*k*(2^127-1)+1
*
* NOTE: Since this is just a test, we do not need to be optimal.
*/
m127 = 2^127 - 1;
q = 2*4949132165849*m127+1;
for (i=0; i < testcnt; ++i) {
/*
* determine next prime divisor
*/
q = nextcand(q, -1, 0, 1, 2*m127);
/*
* determine next prime divisor
*/
q = nextcand(q, -1, 0, 1, 2*m127);
/* compare custom function with its pmod() equivalent */
if (config("resource_debug") & 8) {
print "testing", q;
}
if (pmod(2, m127, q) != custom("pmodm127", q)) {
print "ERROR: pmodm127 failed for ", str(q);
return newerror("pmodm127 failed for " + str(q));
}
}
/* compare custom function with its pmod() equivalent */
if (config("resource_debug") & 8) {
print "testing", q;
}
if (pmod(2, m127, q) != custom("pmodm127", q)) {
print "ERROR: pmodm127 failed for ", str(q);
return newerror("pmodm127 failed for " + str(q));
}
}
/* return success count */
if (config("resource_debug") & 8) {
print "passed", testcnt, "tests";
}
return testcnt;
/* return success count */
if (config("resource_debug") & 8) {
print "passed", testcnt, "tests";
}
return testcnt;
}
define pmodm127_test2(testcnt, seed)
{
local q; /* test factor */
local m127; /* 2^127-1 */
local i;
local q; /* test factor */
local m127; /* 2^127-1 */
local i;
/*
* firewall
*/
if (!isint(testcnt) || testcnt <= 0) {
return newerror("pmodm127_test2 must have an integer count>0");
}
if (!isint(seed)) {
return newerror("pmodm127_test2 must an integer seed");
}
/*
* firewall
*/
if (!isint(testcnt) || testcnt <= 0) {
return newerror("pmodm127_test2 must have an integer count>0");
}
if (!isint(seed)) {
return newerror("pmodm127_test2 must an integer seed");
}
/*
* perform testcnt divisor tests random integers over [1e51, 1e52)
*
* NOTE: Since this is just a test, we do not need to be optimal.
*/
m127 = 2^127 - 1;
for (i=0; i < testcnt; ++i) {
/*
* perform testcnt divisor tests random integers over [1e51, 1e52)
*
* NOTE: Since this is just a test, we do not need to be optimal.
*/
m127 = 2^127 - 1;
for (i=0; i < testcnt; ++i) {
/*
* determine next prime divisor
*/
q = rand(1e51, 1e52) | 0x1;
if (config("resource_debug") & 8) {
print "testing", q;
}
/*
* determine next prime divisor
*/
q = rand(1e51, 1e52) | 0x1;
if (config("resource_debug") & 8) {
print "testing", q;
}
/* compare custom function with its pmod() equivalent */
if (pmod(2, m127, q) != custom("pmodm127", q)) {
print "ERROR: pmodm127 failed for ", str(q);
print "ERROR: ", pmod(2,m127,q), " != ",
custom("pmodm127", q);
return newerror("pmodm127 failed for " + str(q));
}
}
/* compare custom function with its pmod() equivalent */
if (pmod(2, m127, q) != custom("pmodm127", q)) {
print "ERROR: pmodm127 failed for ", str(q);
print "ERROR: ", pmod(2,m127,q), " != ",
custom("pmodm127", q);
return newerror("pmodm127 failed for " + str(q));
}
}
/* return success count */
if (config("resource_debug") & 8) {
print "passed", testcnt, "tests";
}
return testcnt;
/* return success count */
if (config("resource_debug") & 8) {
print "passed", testcnt, "tests";
}
return testcnt;
}
if ((config("resource_debug") & 3) && !(config("resource_debug") & 8)) {

View File

@@ -5,19 +5,19 @@ SYNOPSIS
custom("pzasusb8", arg)
TYPES
arg real
arg real
return null
return null
DESCRIPTION
This custom function prints out the numerator of a real value
in octets. Each HALF value is printed in a separate line.
in octets. Each HALF value is printed in a separate line.
NOTE: The output will vary depending on the size of a HALF
and the byte order of the system. See:
and the byte order of the system. See:
custom("sysinfo", "BASEB")
custom("sysinfo", "CALC_BYTE_ORDER")
custom("sysinfo", "BASEB")
custom("sysinfo", "CALC_BYTE_ORDER")
for details.
@@ -26,15 +26,15 @@ DESCRIPTION
EXAMPLE
> custom("pzasusb8", 0x01020304050607080910111213141516);
0: 13141516
1: 09101112
2: 05060708
3: 01020304
0: 13141516
1: 09101112
2: 05060708
3: 01020304
> custom("pzasusb8", 10^25)
0: 4a000000
1: 16140148
2: 00084595
0: 4a000000
1: 16140148
2: 00084595
> printf("%x\n", 10^25);
0x84595161401484a000000
@@ -57,7 +57,7 @@ SEE ALSO
##
## 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
## 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
@@ -65,8 +65,8 @@ SEE ALSO
## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
##
## Under source code control: 1999/10/06 04:05:43
## File existed as early as: 1999
## Under source code control: 1999/10/06 04:05:43
## File existed as early as: 1999
##
## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/

View File

@@ -11,7 +11,7 @@
*
* 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
* 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
@@ -19,11 +19,11 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Under source code control: 1999/10/06 03:11:12
* File existed as early as: 1998
* Under source code control: 1999/10/06 03:11:12
* File existed as early as: 1998
*
* chongo <was here> /\oo/\ http://www.isthe.com/chongo/
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
* chongo <was here> /\oo/\ http://www.isthe.com/chongo/
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
*/
@@ -31,9 +31,9 @@
* firewall
*/
if (config("compile_custom") == 0) {
quit "calc compiled without -DCUSTOM";
quit "calc compiled without -DCUSTOM";
} else if (config("allow_custom") == 0) {
quit "calc was run without the -D command line option";
quit "calc was run without the -D command line option";
}
print "p(n) prints array in which numerator of n is stored as a";

View File

@@ -5,10 +5,10 @@ SYNOPSIS
custom("register", regnum[, value])
TYPES
regnum int
value any, &any
regnum int
value any, &any
return any
return any
DESCRIPTION
This custom function reads or sets a value of a custom register.
@@ -22,7 +22,7 @@ DESCRIPTION
There will be at least 32 registers although there could be more
added in the future. It may be determined by:
custom("sysinfo", "REGNUM_MAX")
custom("sysinfo", "REGNUM_MAX")
The custom registers are initialized to 0 by the internal
function libcalc_call_me_first() during calc startup.
@@ -32,16 +32,16 @@ DESCRIPTION
EXAMPLE
> custom("register", 3)
0
0
> custom("register", 3, 45)
0
0
> custom("register", 3)
45
45
> custom("register", 7, 2i),
> custom("register", 8, 3i),
> custom("register", 7) * custom("register", 8)
-6
-6
LIMITS
calc must be built with ALLOW_CUSTOM= -DCUSTOM
@@ -63,7 +63,7 @@ SEE ALSO
##
## 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
## 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
@@ -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.
##
## Under source code control: 2005/02/04 22:39:50
## File existed as early as: 2005
## Under source code control: 2005/02/04 22:39:50
## File existed as early as: 2005
##
## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/

View File

@@ -9,7 +9,7 @@
*
* 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
* 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
@@ -17,50 +17,50 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Under source code control: 2007/07/05 11:11:11
* File existed as early as: 2007
* Under source code control: 2007/07/05 11:11:11
* File existed as early as: 2007
*
* chongo <was here> /\oo/\ http://www.isthe.com/chongo/
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
* chongo <was here> /\oo/\ http://www.isthe.com/chongo/
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
*/
/*
* This file is part of the custom sample calc files.
*
* NOTE: You must use a calc that was compiled with ALLOW_CUSTOM= -DCUSTOM
* and run with a -C arg.
* and run with a -C arg.
*/
if (config("compile_custom") == 0) {
quit "calc compiled without -DCUSTOM";
quit "calc compiled without -DCUSTOM";
} else if (config("allow_custom") == 0) {
quit "calc was run without the -D command line option";
quit "calc was run without the -D command line option";
}
define register(num)
{
local reg_max; /* number of registers */
local reg_max; /* number of registers */
/*
* firewall
*/
if (!isnum(num)) {
return newerror("register only works on numeric values");
}
/*
* firewall
*/
if (!isnum(num)) {
return newerror("register only works on numeric values");
}
/*
* determine register count
*/
reg_max = custom("sysinfo", "REGNUM_MAX");
/*
* determine register count
*/
reg_max = custom("sysinfo", "REGNUM_MAX");
/*
* determine the HALF length of a numeric value
*/
if (num < 0) {
return newerror("register number must be >= 0");
} else if (num > reg_max) {
return newerror("register number must be < REGNUM_MAX");
} else {
return custom("register", num);
}
/*
* determine the HALF length of a numeric value
*/
if (num < 0) {
return newerror("register number must be >= 0");
} else if (num > reg_max) {
return newerror("register number must be < REGNUM_MAX");
} else {
return custom("register", num);
}
}

View File

@@ -5,9 +5,9 @@ SYNOPSIS
custom("sysinfo" [, infoname]);
TYPES
infoname string or int
infoname string or int
return int, string or null
return int, string or null
DESCRIPTION
@@ -24,13 +24,13 @@ DESCRIPTION
If infoname is a number, then it is interpreted as follows:
0 print all infonames and meanings (same as no infoname)
1 print all infonames and values
2 print all infoname meanings and values
0 print all infonames and meanings (same as no infoname)
1 print all infonames and values
2 print all infoname meanings and values
EXAMPLE
> custom("sysinfo", "baseb")
32
32
> custom("sysinfo")
... a list of infonames and meanings are printed ...
@@ -61,7 +61,7 @@ SEE ALSO
##
## 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
## 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
@@ -69,8 +69,8 @@ SEE ALSO
## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
##
## Under source code control: 1997/03/09 23:14:40
## File existed as early as: 1997
## Under source code control: 1997/03/09 23:14:40
## File existed as early as: 1997
##
## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/