home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume11 / watcher / part01 / checkline.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-09-27  |  1.9 KB  |  76 lines

  1. /*
  2.    checkline: check the input line just read in against what we expect
  3.    to find and report any problems.  Actually, most of the work is done
  4.    by check_item.  We just identify what needs to be checked.
  5.  
  6.    Kenneth Ingham
  7.  
  8.    Copyright (C) 1987 The University of New Mexico
  9. */
  10.  
  11. #include "defs.h"
  12.  
  13. checkline(cmd, line, prev_res)
  14. struct cmd_st *cmd;
  15. char *line;
  16. struct old_cmd_st *prev_res;
  17. {
  18.     extern int line_ok;
  19.     extern FILE *hf;
  20.     struct change_fmt_st *cf;
  21.     union out_fmt_u of;
  22.     union all_u *prev_value;
  23.     char value[MAX_STR];
  24.     char key_val[MAX_STR];
  25.     char *cmd_name;
  26.  
  27.     cmd_name = (cmd->alias != NULL ? cmd->alias : cmd->pipeline);
  28.         
  29.     save_key(cmd, line, key_val); /* side effect: return key value */
  30.     /* for each change format item */
  31.     line_ok = True;
  32.     for (cf=cmd->change_fmt; cf; cf=cf->next) {
  33.         /* find the output format entry for this item */
  34.         if (!find_of(cmd->out_type, cf->name, cmd->out_fmt, &of)) {
  35.             fprintf(stderr, "Warning: %s appears in change list ",
  36.                 cf->name);
  37.             fprintf(stderr, "but not in output format for %s\n",
  38.                 cmd_name);
  39.             continue;
  40.         }
  41.  
  42.         /*
  43.            find the part of the line corresponding to check.
  44.            Also find the previous results corresponding to the
  45.            key for this line (if any).
  46.         */
  47.         switch (cmd->out_type) {
  48.         case RELATIVE:
  49.             find_prev_value(prev_res, of.rel_fmt->name,
  50.                 key_val, &prev_value);
  51.             if (get_rel_field(line, of.rel_fmt->field, value) !=
  52.                 NULL)
  53.                 check_item(cf, value, cmd_name, line,
  54.                     prev_value);
  55.             break;
  56.         case COLUMN:
  57.             find_prev_value(prev_res, of.rel_fmt->name,
  58.                 key_val, &prev_value);
  59.             if (get_col_field(line, of.col_fmt->start, of.col_fmt->end, value) != NULL)
  60.                 check_item(cf, value, cmd_name, line,
  61.                     prev_value);
  62.             break;
  63.         }
  64.  
  65.         /*
  66.            save the value in the history file for future
  67.            comparisons.
  68.         */
  69.         if (cmd->key.rel_fmt != NULL)
  70.             fprintf(hf, "\t\t%s %c %s\n", cf->name, 
  71.                 TCHAR(cf->type), value);
  72.     }
  73.     if (!line_ok)
  74.         printf("---------\n");
  75. }
  76.