home *** CD-ROM | disk | FTP | other *** search
- /*
- check_item: given a value and a change format structure, make sure
- that the value is in range.
-
- Basically, this routine is a large switch statement on the type of
- change that grabs the necessary info, and checks to see if the item
- is worth mentioning.
-
- Note that what we print out depends on whether or not something else
- has been found wrong on this line.
-
- Kenneth Ingham
-
- Copyright (C) 1987 The University of New Mexico
- */
-
- #include "defs.h"
-
- check_item(cf, value, cmd, line, prev_val)
- char *value, *cmd, *line;
- struct change_fmt_st *cf;
- union all_u *prev_val;
- {
- extern int line_ok, cmd_ok;
- double v, pct_chg, abs_chg;
- int len;
-
- v = atof(value);
- len = strlen(value);
-
- switch(cf->type) {
- case PERCENT:
- if (prev_val == NULL) /* nothing to compare with */
- return;
- if (v == 0) /* avoid divide by 0 */
- return;
- pct_chg = (v - prev_val->floatval) / v;
- if (pct_chg > cf->fmt.percent) {
- if (line_ok) {
- printf("%s had ", cmd);
- printf("%s change by more than %.2f percent.\n",
- cf->name, cf->fmt.percent*100);
- printf("%s\n",line);
- }
- else {
- printf("Also, it had ");
- printf("%s change by more than %.2f percent.\n",
- cf->name, cf->fmt.percent*100);
- }
- printf("Previous value %.2f; ",
- prev_val->floatval);
- printf("current value %.2f.\n", v);
- line_ok = False;
- }
- break;
- case ABSOLUTE:
- if (prev_val == NULL) /* nothing to compare with */
- return;
- abs_chg = v - prev_val->floatval;
- if (abs_chg > cf->fmt.abs_amount) {
- if (line_ok) {
- printf("%s had ", cmd);
- printf("%s change by more than %.2f.\n",
- cf->name, cf->fmt.abs_amount);
- printf("%s\n",line);
- }
- else {
- printf("Also, it had ");
- printf("%s change by more than %.2f.\n",
- cf->name, cf->fmt.abs_amount);
- }
- printf("Previous value %.2f; ",
- prev_val->floatval);
- printf("current value %.2f.\n", v);
- line_ok = False;
- }
- break;
- case MAX_MIN:
- if (v > cf->fmt.max_min.max || v < cf->fmt.max_min.min) {
- if (line_ok) {
- printf("%s has a ", cmd);
- printf("max/min value out of range:\n");
- printf("%s\n",line);
- }
- else {
- printf("Also, it has a ");
- printf("max/min value out of range:\n");
- }
- printf("where %s = %.2f; ", cf->name, v);
- printf("valid range %.2f to %.2f.\n",
- cf->fmt.max_min.min, cf->fmt.max_min.max);
- line_ok = False;
- }
- break;
- case STRING:
- if (strncmp(cf->fmt.str_value, value, len) != 0) {
- if (line_ok) {
- printf("%s has a string ", cmd);
- printf("value which is not valid:\n");
- printf("%s\n",line);
- }
- else {
- printf("Also, it has a string");
- printf("value which is not valid:\n");
- }
- printf("where %s = '%s'; Should be '%s'\n",
- cf->name, value, cf->fmt.str_value);
- line_ok = False;
- }
- break;
- default:
- printf("check_item: impossible condition\n");
- break;
- }
- cmd_ok = line_ok;
- }
-