config.c
来自「Calc Software Package for Number Calc」· C语言 代码 · 共 1,477 行 · 第 1/3 页
C
1,477 行
/* free the current configuration */ config_free(conf); /* set the new configuration */ conf = config_copy(newconf); break; case CONFIG_TRACE: if (vp->v_type != V_NUM) { math_error("Non-numeric for trace"); /*NOTREACHED*/ } q = vp->v_num; temp = qtoi(q); if (qisfrac(q) || !zistiny(q->num) || ((unsigned long) temp > TRACE_MAX)) { math_error("Bad trace value"); /*NOTREACHED*/ } conf->traceflags = (FLAG)temp; break; case CONFIG_DISPLAY: if (getlen(vp, &len)) { math_error("Bad value for display"); /*NOTREACHED*/ } math_setdigits(len); break; case CONFIG_MODE: if (vp->v_type != V_STR) { math_error("Non-string for mode"); /*NOTREACHED*/ } temp = lookup_long(modes, vp->v_str->s_str); if (temp < 0) { math_error("Unknown mode \"%s\"", vp->v_str); /*NOTREACHED*/ } math_setmode((int) temp); break; case CONFIG_MODE2: if (vp->v_type != V_STR) { math_error("Non-string for mode"); /*NOTREACHED*/ } temp = lookup_long(modes, vp->v_str->s_str); if (temp < 0) { math_error("Unknown mode \"%s\"", vp->v_str); /*NOTREACHED*/ } math_setmode2((int) temp); break; case CONFIG_EPSILON: if (vp->v_type != V_NUM) { math_error("Non-numeric for epsilon"); /*NOTREACHED*/ } setepsilon(vp->v_num); break; case CONFIG_MAXPRINT: if (getlen(vp, &len)) { math_error("Bad value for maxprint"); /*NOTREACHED*/ } conf->maxprint = len; break; case CONFIG_MUL2: if (getlen(vp, &len) || len < 0 || len == 1) { math_error("Bad value for mul2"); /*NOTREACHED*/ } if (len == 0) len = MUL_ALG2; conf->mul2 = len; break; case CONFIG_SQ2: if (getlen(vp, &len) || len < 0 || len == 1) { math_error("Bad value for sq2"); /*NOTREACHED*/ } if (len == 0) len = SQ_ALG2; conf->sq2 = len; break; case CONFIG_POW2: if (getlen(vp, &len) || len < 0 || len == 1) { math_error("Bad value for pow2"); /*NOTREACHED*/ } if (len == 0) len = POW_ALG2; conf->pow2 = len; break; case CONFIG_REDC2: if (getlen(vp, &len) || len < 0 || len == 1) { math_error("Bad value for redc2"); /*NOTREACHED*/ } if (len == 0) len = REDC_ALG2; conf->redc2 = len; break; case CONFIG_TILDE: if (vp->v_type == V_NUM) { q = vp->v_num; conf->tilde_ok = !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 tilde"); /*NOTREACHED*/ } conf->tilde_ok = (int)temp; } break; case CONFIG_TAB: if (vp->v_type == V_NUM) { q = vp->v_num; conf->tab_ok = !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 tab"); /*NOTREACHED*/ } conf->tab_ok = (int)temp; } break; case CONFIG_QUOMOD: if (getlen(vp, &len)) { math_error("Illegal value for quomod"); /*NOTREACHED*/ } conf->quomod = len; break; case CONFIG_QUO: if (getlen(vp, &len)) { math_error("Illegal value for quo"); /*NOTREACHED*/ } conf->quo = len; break; case CONFIG_MOD: if (getlen(vp, &len)) { math_error("Illegal value for mod"); /*NOTREACHED*/ } conf->mod = len; break; case CONFIG_SQRT: if (getlen(vp, &len)) { math_error("Illegal value for sqrt"); /*NOTREACHED*/ } conf->sqrt = len; break; case CONFIG_APPR: if (getlen(vp, &len)) { math_error("Illegal value for appr"); /*NOTREACHED*/ } conf->appr = len; break; case CONFIG_CFAPPR: if (getlen(vp, &len)) { math_error("Illegal value for cfappr"); /*NOTREACHED*/ } conf->cfappr = len; break; case CONFIG_CFSIM: if (getlen(vp, &len)) { math_error("Illegal value for cfsim"); /*NOTREACHED*/ } conf->cfsim = len; break; case CONFIG_OUTROUND: if (getlen(vp, &len)) { math_error("Illegal value for outround"); /*NOTREACHED*/ } conf->outround = len; break; case CONFIG_ROUND: if (getlen(vp, &len)) { math_error("Illegal value for round"); /*NOTREACHED*/ } conf->round = len; break; case CONFIG_LEADZERO: if (vp->v_type == V_NUM) { q = vp->v_num; conf->leadzero = !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 leadzero"); /*NOTREACHED*/ } } conf->leadzero = (int)temp; } break; case CONFIG_FULLZERO: if (vp->v_type == V_NUM) { q = vp->v_num; conf->fullzero = !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 fullzero"); /*NOTREACHED*/ } } conf->fullzero = (int)temp; } break; case CONFIG_MAXSCAN: if (vp->v_type != V_NUM) { math_error("Non-numeric for maxscancount"); /*NOTREACHED*/ } q = vp->v_num; temp = qtoi(q); if (qisfrac(q) || qisneg(q) || !zistiny(q->num)) temp = -1; if (temp < 0) { math_error("Maxscan value is out of range"); /*NOTREACHED*/ } conf->maxscancount = temp; break; case CONFIG_PROMPT: if (vp->v_type != V_STR) { math_error("Non-string for prompt"); /*NOTREACHED*/ } p = (char *)malloc(vp->v_str->s_len + 1); if (p == NULL) { math_error("Cannot duplicate new prompt"); /*NOTREACHED*/ } strncpy(p, vp->v_str->s_str, vp->v_str->s_len + 1); free(conf->prompt1); conf->prompt1 = p; break; case CONFIG_MORE: if (vp->v_type != V_STR) { math_error("Non-string for more prompt"); /*NOTREACHED*/ } p = (char *)malloc(vp->v_str->s_len + 1); if (p == NULL) { math_error("Cannot duplicate new more prompt"); /*NOTREACHED*/ } strncpy(p, vp->v_str->s_str, vp->v_str->s_len + 1); free(conf->prompt2); conf->prompt2 = p; break; case CONFIG_BLKMAXPRINT: if (vp->v_type != V_NUM) { math_error("Non-numeric for blkmaxprint"); /*NOTREACHED*/ } q = vp->v_num; temp = qtoi(q); if (qisfrac(q) || qisneg(q) || !zistiny(q->num)) temp = -1; if (temp < 0) { math_error("Blkmaxprint value is out of range"); /*NOTREACHED*/ } conf->blkmaxprint = temp; break; case CONFIG_BLKVERBOSE: if (vp->v_type == V_NUM) { q = vp->v_num; conf->blkverbose = !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 blkverbose"); /*NOTREACHED*/ } conf->blkverbose = (int)temp; } break; case CONFIG_BLKBASE: if (vp->v_type != V_STR) { math_error("Non-string for blkbase"); /*NOTREACHED*/ } temp = lookup_long(blk_base, vp->v_str->s_str); if (temp < 0) { math_error("Unknown mode \"%s\" for blkbase", vp->v_str->s_str); /*NOTREACHED*/ } conf->blkbase = temp; break; case CONFIG_BLKFMT: if (vp->v_type != V_STR) { math_error("Non-string for blkfmt"); /*NOTREACHED*/ } temp = lookup_long(blk_fmt, vp->v_str->s_str); if (temp < 0) { math_error("Unknown mode \"%s\" for blkfmt", vp->v_str->s_str); /*NOTREACHED*/ } conf->blkfmt = temp; break; case CONFIG_CALC_DEBUG: if (vp->v_type != V_NUM) { math_error("Non numeric for calc_debug"); /*NOTREACHED*/ } q = vp->v_num; temp = qtoi(q); if (qisfrac(q) || !zistiny(q->num)) { math_error("Illegal calc_debug parameter value"); /*NOTREACHED*/ } conf->calc_debug = temp; break; case CONFIG_RESOURCE_DEBUG: if (vp->v_type != V_NUM) { math_error("Non numeric for resource_debug"); /*NOTREACHED*/ } q = vp->v_num; temp = qtoi(q); if (qisfrac(q) || !zistiny(q->num)) { math_error("Illegal resource_debug parameter value"); /*NOTREACHED*/ } conf->resource_debug = temp; break; case CONFIG_USER_DEBUG: if (vp->v_type != V_NUM) { math_error("Non numeric for user_debug"); /*NOTREACHED*/ } q = vp->v_num; temp = qtoi(q); if (qisfrac(q) || !zistiny(q->num)) { math_error("Illegal user_debug parameter value"); /*NOTREACHED*/ } conf->user_debug = temp; break; case CONFIG_VERBOSE_QUIT: if (vp->v_type == V_NUM) { q = vp->v_num; conf->verbose_quit = !qiszero(q); } else if (vp->v_type == V_STR) { temp = lookup_long(truth, vp->v_str->s_str); if (temp < 0) { math_error("Illegal truth value " "for verbose_quit"); /*NOTREACHED*/ } conf->verbose_quit = (int)temp; } break; case CONFIG_CTRL_D: if (vp->v_type != V_STR) { math_error("Non-string for ctrl_d"); /*NOTREACHED*/ } temp = lookup_long(ctrl_d, vp->v_str->s_str); if (temp < 0) { math_error("Unknown mode \"%s\" for ctrl_d", vp->v_str->s_str); /*NOTREACHED*/ } conf->ctrl_d = temp; break; case CONFIG_PROGRAM: math_error("The program config parameter is read-only"); /*NOTREACHED*/ case CONFIG_BASENAME: math_error("The basename config parameter is read-only"); /*NOTREACHED*/ case CONFIG_WINDOWS: math_error("The windows config parameter is read-only"); /*NOTREACHED*/ case CONFIG_CYGWIN: math_error("The cygwin config parameter is read-only"); /*NOTREACHED*/ case CONFIG_COMPILE_CUSTOM: math_error("The custom config parameter is read-only"); /*NOTREACHED*/ case CONFIG_ALLOW_CUSTOM: math_error("The allow_custom config parameter is read-only"); /*NOTREACHED*/ case CONFIG_VERSION: math_error("The version config parameter is read-only"); /*NOTREACHED*/ case CONFIG_BASEB: math_error("The baseb config parameter is read-only"); /*NOTREACHED*/ case CONFIG_REDECL_WARN: if (vp->v_type == V_NUM) { q = vp->v_num; conf->redecl_warn = !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 redecl_warn"); /*NOTREACHED*/ } conf->redecl_warn = (int)temp; } break; case CONFIG_DUPVAR_WARN: if (vp->v_type == V_NUM) { q = vp->v_num; conf->dupvar_warn = !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 dupvar_warn"); /*NOTREACHED*/ } conf->dupvar_warn = (int)temp; } break; case CONFIG_HZ: math_error("The clock tick rate config parameter is read-only"); /*NOTREACHED*/ default: math_error("Setting illegal config parameter"); /*NOTREACHED*/ }}/* * config_copy - copy the configuration from one value to another * * given:
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?