mirror of
https://github.com/lcn2/calc.git
synced 2025-08-16 01:03:29 +03:00
Release calc version 2.11.4t2
This commit is contained in:
244
config.c
244
config.c
@@ -19,8 +19,8 @@
|
||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* @(#) $Revision: 29.3 $
|
||||
* @(#) $Id: config.c,v 29.3 2000/06/07 14:02:13 chongo Exp $
|
||||
* @(#) $Revision: 29.4 $
|
||||
* @(#) $Id: config.c,v 29.4 2000/07/17 15:35:49 chongo Exp $
|
||||
* @(#) $Source: /usr/local/src/cmd/calc/RCS/config.c,v $
|
||||
*
|
||||
* Under source code control: 1991/07/20 00:21:56
|
||||
@@ -109,10 +109,10 @@ CONFIG oldstd = { /* backward compatible standard configuration */
|
||||
SQ_ALG2, /* size of number to use square alg 2 */
|
||||
POW_ALG2, /* size of modulus to use REDC for powers */
|
||||
REDC_ALG2, /* size of modulus to use REDC algorithm 2 */
|
||||
TRUE, /* ok to print a tilde on aproximations */
|
||||
TRUE, /* ok to print a tilde on approximations */
|
||||
TRUE, /* ok to print tab before numeric values */
|
||||
0, /* quomod() default rounding mode */
|
||||
2, /* quotent // default rounding mode */
|
||||
2, /* quotient // default rounding mode */
|
||||
0, /* mod % default rounding mode */
|
||||
24, /* sqrt() default rounding mode */
|
||||
24, /* appr() default rounding mode */
|
||||
@@ -149,10 +149,10 @@ CONFIG newstd = { /* new non-backward compatible configuration */
|
||||
SQ_ALG2, /* size of number to use square alg 2 */
|
||||
POW_ALG2, /* size of modulus to use REDC for powers */
|
||||
REDC_ALG2, /* size of modulus to use REDC algorithm 2 */
|
||||
TRUE, /* ok to print a tilde on aproximations */
|
||||
TRUE, /* ok to print a tilde on approximations */
|
||||
TRUE, /* ok to print tab before numeric values */
|
||||
0, /* quomod() default rounding mode */
|
||||
0, /* quotent // default rounding mode */
|
||||
0, /* quotient // default rounding mode */
|
||||
0, /* mod % default rounding mode */
|
||||
24, /* sqrt() default rounding mode */
|
||||
24, /* appr() default rounding mode */
|
||||
@@ -287,10 +287,11 @@ static NAMETYPE truth[] = {
|
||||
|
||||
|
||||
/*
|
||||
* declate static functions
|
||||
* declare static functions
|
||||
*/
|
||||
static long lookup_long(NAMETYPE *set, char *name);
|
||||
static char *lookup_name(NAMETYPE *set, long val);
|
||||
static int getlen(VALUE *vp, LEN *lp);
|
||||
|
||||
|
||||
/*
|
||||
@@ -360,6 +361,26 @@ lookup_name(NAMETYPE *set, long val)
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Check whether VALUE at vp is a LEN (32-bit signed integer) and if so,
|
||||
* copy that integer to lp.
|
||||
* Return: 1, 2, 0, or -1 XXX
|
||||
*/
|
||||
|
||||
static int
|
||||
getlen(VALUE *vp, LEN *lp)
|
||||
{
|
||||
if (vp->v_type != V_NUM || !qisint(vp->v_num))
|
||||
return 1;
|
||||
if (zge31b(vp->v_num->num))
|
||||
return 2;
|
||||
*lp = ztoi(vp->v_num->num);
|
||||
if (*lp < 0)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Set the specified configuration type to the specified value.
|
||||
* An error is generated if the type number or value is illegal.
|
||||
@@ -370,6 +391,7 @@ setconfig(int type, VALUE *vp)
|
||||
NUMBER *q;
|
||||
CONFIG *newconf; /* new configuration to set */
|
||||
long temp;
|
||||
LEN len;
|
||||
char *p;
|
||||
|
||||
switch (type) {
|
||||
@@ -414,15 +436,11 @@ setconfig(int type, VALUE *vp)
|
||||
break;
|
||||
|
||||
case CONFIG_DISPLAY:
|
||||
if (vp->v_type != V_NUM) {
|
||||
math_error("Non-numeric for display");
|
||||
if (getlen(vp, &len)) {
|
||||
math_error("Bad value for display");
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
q = vp->v_num;
|
||||
temp = qtoi(q);
|
||||
if (qisfrac(q) || qisneg(q) || !zistiny(q->num))
|
||||
temp = -1;
|
||||
math_setdigits(temp);
|
||||
math_setdigits(len);
|
||||
break;
|
||||
|
||||
case CONFIG_MODE:
|
||||
@@ -447,91 +465,51 @@ setconfig(int type, VALUE *vp)
|
||||
break;
|
||||
|
||||
case CONFIG_MAXPRINT:
|
||||
if (vp->v_type != V_NUM) {
|
||||
math_error("Non-numeric for maxprint");
|
||||
if (getlen(vp, &len)) {
|
||||
math_error("Bad value for maxprint");
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
q = vp->v_num;
|
||||
temp = qtoi(q);
|
||||
if (qisfrac(q) || qisneg(q) || !zistiny(q->num))
|
||||
temp = -1;
|
||||
if (temp < 0) {
|
||||
math_error("Maxprint value is out of range");
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
conf->maxprint = temp;
|
||||
conf->maxprint = len;
|
||||
break;
|
||||
|
||||
case CONFIG_MUL2:
|
||||
if (vp->v_type != V_NUM) {
|
||||
math_error("Non-numeric for mul2");
|
||||
if (getlen(vp, &len)) {
|
||||
math_error("Bad value for mul2");
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
q = vp->v_num;
|
||||
temp = qtoi(q);
|
||||
if (qisfrac(q) || qisneg(q))
|
||||
temp = -1;
|
||||
if (temp == 0)
|
||||
temp = MUL_ALG2;
|
||||
if (temp < 2) {
|
||||
math_error("Illegal mul2 value");
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
conf->mul2 = (int)temp;
|
||||
if (len == 0)
|
||||
len = MUL_ALG2;
|
||||
conf->mul2 = len;
|
||||
break;
|
||||
|
||||
case CONFIG_SQ2:
|
||||
if (vp->v_type != V_NUM) {
|
||||
math_error("Non-numeric for sq2");
|
||||
if (getlen(vp, &len)) {
|
||||
math_error("Bad value for sq2");
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
q = vp->v_num;
|
||||
temp = qtoi(q);
|
||||
if (qisfrac(q) || qisneg(q))
|
||||
temp = -1;
|
||||
if (temp == 0)
|
||||
temp = SQ_ALG2;
|
||||
if (temp < 2) {
|
||||
math_error("Illegal sq2 value");
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
conf->sq2 = (int)temp;
|
||||
if (len == 0)
|
||||
len = SQ_ALG2;
|
||||
conf->sq2 = len;
|
||||
break;
|
||||
|
||||
case CONFIG_POW2:
|
||||
if (vp->v_type != V_NUM) {
|
||||
math_error("Non-numeric for pow2");
|
||||
if (getlen(vp, &len)) {
|
||||
math_error("Bad value for pow2");
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
q = vp->v_num;
|
||||
temp = qtoi(q);
|
||||
if (qisfrac(q) || qisneg(q))
|
||||
temp = -1;
|
||||
if (temp == 0)
|
||||
temp = POW_ALG2;
|
||||
if (temp < 1) {
|
||||
math_error("Illegal pow2 value");
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
conf->pow2 = (int)temp;
|
||||
if (len == 0)
|
||||
len = POW_ALG2;
|
||||
conf->pow2 = len;
|
||||
break;
|
||||
|
||||
case CONFIG_REDC2:
|
||||
if (vp->v_type != V_NUM) {
|
||||
math_error("Non-numeric for redc2");
|
||||
if (getlen(vp, &len)) {
|
||||
math_error("Bad value for redc2");
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
q = vp->v_num;
|
||||
temp = qtoi(q);
|
||||
if (qisfrac(q) || qisneg(q))
|
||||
temp = -1;
|
||||
if (temp == 0)
|
||||
temp = REDC_ALG2;
|
||||
if (temp < 1) {
|
||||
math_error("Illegal redc2 value");
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
conf->redc2 = (int)temp;
|
||||
if (len == 0)
|
||||
len = REDC_ALG2;
|
||||
conf->redc2 = len;
|
||||
break;
|
||||
|
||||
case CONFIG_TILDE:
|
||||
@@ -563,129 +541,75 @@ setconfig(int type, VALUE *vp)
|
||||
break;
|
||||
|
||||
case CONFIG_QUOMOD:
|
||||
if (vp->v_type != V_NUM) {
|
||||
math_error("Non numeric for quomod");
|
||||
if (getlen(vp, &len)) {
|
||||
math_error("Illegal value for quomod");
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
q = vp->v_num;
|
||||
temp = qtoi(q);
|
||||
if (qisfrac(q) || qisneg(q) || !zistiny(q->num)) {
|
||||
math_error("Illegal quomod parameter value");
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
conf->quomod = temp;
|
||||
conf->quomod = len;
|
||||
break;
|
||||
|
||||
case CONFIG_QUO:
|
||||
if (vp->v_type != V_NUM) {
|
||||
math_error("Non numeric for quo");
|
||||
if (getlen(vp, &len)) {
|
||||
math_error("Illegal value for quo");
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
q = vp->v_num;
|
||||
temp = qtoi(q);
|
||||
if (qisfrac(q) || qisneg(q) || !zistiny(q->num)) {
|
||||
math_error("Illegal quo parameter value");
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
conf->quo = temp;
|
||||
conf->quo = len;
|
||||
break;
|
||||
|
||||
case CONFIG_MOD:
|
||||
if (vp->v_type != V_NUM) {
|
||||
math_error("Non numeric for mod");
|
||||
if (getlen(vp, &len)) {
|
||||
math_error("Illegal value for mod");
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
q = vp->v_num;
|
||||
temp = qtoi(q);
|
||||
if (qisfrac(q) || qisneg(q) || !zistiny(q->num)) {
|
||||
math_error("Illegal mod parameter value");
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
conf->mod = temp;
|
||||
conf->mod = len;
|
||||
break;
|
||||
|
||||
case CONFIG_SQRT:
|
||||
if (vp->v_type != V_NUM) {
|
||||
math_error("Non numeric for sqrt");
|
||||
if (getlen(vp, &len)) {
|
||||
math_error("Illegal value for sqrt");
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
q = vp->v_num;
|
||||
temp = qtoi(q);
|
||||
if (qisfrac(q) || qisneg(q) || !zistiny(q->num)) {
|
||||
math_error("Illegal sqrt parameter value");
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
conf->sqrt = temp;
|
||||
conf->sqrt = len;
|
||||
break;
|
||||
|
||||
case CONFIG_APPR:
|
||||
if (vp->v_type != V_NUM) {
|
||||
math_error("Non numeric for appr");
|
||||
if (getlen(vp, &len)) {
|
||||
math_error("Illegal value for appr");
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
q = vp->v_num;
|
||||
temp = qtoi(q);
|
||||
if (qisfrac(q) || qisneg(q) || !zistiny(q->num)) {
|
||||
math_error("Illegal appr parameter value");
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
conf->appr = temp;
|
||||
conf->appr = len;
|
||||
break;
|
||||
|
||||
case CONFIG_CFAPPR:
|
||||
if (vp->v_type != V_NUM) {
|
||||
math_error("Non numeric for cfappr");
|
||||
if (getlen(vp, &len)) {
|
||||
math_error("Illegal value for cfappr");
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
q = vp->v_num;
|
||||
temp = qtoi(q);
|
||||
if (qisfrac(q) || qisneg(q) || !zistiny(q->num)) {
|
||||
math_error("Illegal cfappr parameter value");
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
conf->cfappr = temp;
|
||||
conf->cfappr = len;
|
||||
break;
|
||||
|
||||
case CONFIG_CFSIM:
|
||||
if (vp->v_type != V_NUM) {
|
||||
math_error("Non numeric for cfsim");
|
||||
if (getlen(vp, &len)) {
|
||||
math_error("Illegal value for cfsim");
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
q = vp->v_num;
|
||||
temp = qtoi(q);
|
||||
if (qisfrac(q) || qisneg(q) || !zistiny(q->num)) {
|
||||
math_error("Illegal cfsim parameter value");
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
conf->cfsim = temp;
|
||||
conf->cfsim = len;
|
||||
break;
|
||||
|
||||
case CONFIG_OUTROUND:
|
||||
if (vp->v_type != V_NUM) {
|
||||
math_error("Non numeric for outround");
|
||||
if (getlen(vp, &len)) {
|
||||
math_error("Illegal value for outround");
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
q = vp->v_num;
|
||||
temp = qtoi(q);
|
||||
if (qisfrac(q) || qisneg(q) || !zistiny(q->num)) {
|
||||
math_error("Illegal output parameter value");
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
conf->outround = temp;
|
||||
conf->outround = len;
|
||||
break;
|
||||
|
||||
case CONFIG_ROUND:
|
||||
if (vp->v_type != V_NUM) {
|
||||
math_error("Non numeric for round");
|
||||
if (getlen(vp, &len)) {
|
||||
math_error("Illegal value for round");
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
q = vp->v_num;
|
||||
temp = qtoi(q);
|
||||
if (qisfrac(q) || qisneg(q) || !zistiny(q->num)) {
|
||||
math_error("Illegal output parameter value");
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
conf->round = temp;
|
||||
conf->round = len;
|
||||
break;
|
||||
|
||||
case CONFIG_LEADZERO:
|
||||
@@ -1311,12 +1235,12 @@ config_cmp(CONFIG *cfg1, CONFIG *cfg2)
|
||||
*/
|
||||
if (cfg1 == NULL || cfg1->epsilon == NULL || cfg1->prompt1 == NULL ||
|
||||
cfg1->prompt2 == NULL) {
|
||||
math_error("CONFIG #1 value is invaid");
|
||||
math_error("CONFIG #1 value is invalid");
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
if (cfg2 == NULL || cfg2->epsilon == NULL || cfg2->prompt1 == NULL ||
|
||||
cfg2->prompt2 == NULL) {
|
||||
math_error("CONFIG #2 value is invaid");
|
||||
math_error("CONFIG #2 value is invalid");
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user