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

  1. /*
  2.    find_prev_value: given an old command structure, look through the
  3.    prior output for the output for name of type type.  Return it in the
  4.    union pointed to by value or NULL if not found.
  5.  
  6.    Kenneth Ingham
  7.  
  8.    Copyright (C) 1987 The University of New Mexico
  9. */
  10.  
  11. #include "defs.h"
  12.  
  13. find_prev_value(cmd, field_name, key_val, value)
  14. struct old_cmd_st *cmd;
  15. char *field_name, *key_val;
  16. union all_u **value;
  17. {
  18.     struct val_st *vp;
  19.     struct key_st *kp;
  20.  
  21.     *value = NULL;
  22.  
  23.     if (cmd == NULL)
  24.         return;
  25.     if (cmd->keys == NULL)
  26.         return;
  27.  
  28.     /* find the correct keyword */
  29.     for (kp=cmd->keys; kp != NULL; kp=kp->next) {
  30.         if (strcmp(kp->key_value, key_val) == 0)
  31.             break;
  32.     }
  33.  
  34.     if (kp == NULL)
  35.         return;
  36.     if (kp->vals == NULL)
  37.         return;
  38.  
  39.     /* find the value under the keyword */
  40.     for (vp=kp->vals; vp != NULL; vp=vp->next) {
  41.         if (strcmp(vp->name, field_name) == 0) {
  42.             *value = &(vp->val);
  43.             return;
  44.         }
  45.     }
  46. }
  47.