mirror of
https://github.com/lcn2/calc.git
synced 2025-08-16 01:03:29 +03:00
Add config("fraction_space") to control spaces around printing fractions
Added config("tilde_space", boolean) to help/config, along with a few few minor text improvements. Updated cal/regress to test config("tilde_space"). Added config("fraction_space", boolean). The "fraction_space" controls whether or not a space (' ') is printed before and after fractions. By default, config("fraction_space") is false. For example, with the default, config("fraction_space", 0): ; base(1/3), ; 1/7 1/7 With config("fraction_space", 1): ; base(1/3), ; 1/7 1 / 7 NOTE: Use of config("fraction_space", 1) can break printing and scanning of fractional values via "%r". NOTE: Use of config("fraction_space", 1) can break printing and scanning of complex values via "%c". Added config("fraction_space", boolean) to help/config, along with a few few minor text improvements. Updated cal/regress to test config("tilde_space").
This commit is contained in:
21
config.c
21
config.c
@@ -132,6 +132,7 @@ NAMETYPE configs[] = {
|
||||
{"redecl_warn", CONFIG_REDECL_WARN},
|
||||
{"dupvar_warn", CONFIG_DUPVAR_WARN},
|
||||
{"hz", CONFIG_HZ},
|
||||
{"fraction_space", CONFIG_FRACTION_SPACE},
|
||||
{NULL, 0}
|
||||
};
|
||||
|
||||
@@ -199,6 +200,7 @@ CONFIG oldstd = { /* backward compatible standard configuration */
|
||||
BASEB, /* base for calculations */
|
||||
TRUE, /* warn when redeclaring */
|
||||
TRUE, /* warn when variable names collide */
|
||||
FALSE, /* print spaces around / in fractions */
|
||||
};
|
||||
CONFIG newstd = { /* new non-backward compatible configuration */
|
||||
MODE_INITIAL, /* current output mode */
|
||||
@@ -260,6 +262,7 @@ CONFIG newstd = { /* new non-backward compatible configuration */
|
||||
BASEB, /* base for calculations */
|
||||
TRUE, /* warn when redeclaring */
|
||||
TRUE, /* warn when variable names collide */
|
||||
FALSE, /* print spaces around / in fractions */
|
||||
};
|
||||
CONFIG *conf = NULL; /* loaded in at startup - current configuration */
|
||||
|
||||
@@ -1006,6 +1009,20 @@ setconfig(int type, VALUE *vp)
|
||||
not_reached();
|
||||
break;
|
||||
|
||||
case CONFIG_FRACTION_SPACE:
|
||||
if (vp->v_type == V_NUM) {
|
||||
q = vp->v_num;
|
||||
conf->fraction_space = !qiszero(q);
|
||||
} else if (vp->v_type == V_STR) {
|
||||
temp = lookup_long(truth, vp->v_str->s_str);
|
||||
if (temp < 0) {
|
||||
math_error("Illegal truth value for fraction_space");
|
||||
not_reached();
|
||||
}
|
||||
conf->fraction_space = (int)temp;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
math_error("Setting illegal config parameter");
|
||||
not_reached();
|
||||
@@ -1405,6 +1422,10 @@ config_value(CONFIG *cfg, int type, VALUE *vp)
|
||||
i = CALC_HZ;
|
||||
break;
|
||||
|
||||
case CONFIG_FRACTION_SPACE:
|
||||
i = (cfg->fraction_space ? 1 : 0);
|
||||
break;
|
||||
|
||||
default:
|
||||
math_error("Getting illegal CONFIG element");
|
||||
not_reached();
|
||||
|
Reference in New Issue
Block a user