home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume11 / watcher / part01 / save_key.c < prev    next >
C/C++ Source or Header  |  1987-09-27  |  1KB  |  66 lines

  1. /*
  2.    save_key: save the key for this line in the history file so that
  3.    we can use it next run.
  4.  
  5.    Assume that the keyory file is opened and that the pipeline has
  6.    already been placed in the file.  We place the data in the file in
  7.    the following format:
  8.  
  9.     pipeline
  10.         key_value
  11.             name value
  12.                 .
  13.                 .
  14.                 .
  15.             .
  16.             .
  17.             .
  18.     pipeline
  19.        .
  20.        .
  21.        .
  22.    
  23.  
  24.    Side effect: return the actual key value for other parts of the
  25.    program to use.
  26.  
  27.    Kenneth Ingham
  28.  
  29.    Copyright (C) 1987 The University of New Mexico
  30. */
  31.  
  32. #include "defs.h"
  33.  
  34. save_key(cmd, line, key_val)
  35. struct cmd_st *cmd;
  36. char *line, *key_val;
  37. {
  38.     extern int vflag;
  39.     extern FILE *hf; /* assumed to be already open */
  40.  
  41.     if (cmd->key.col_fmt == NULL) { /* no key; no reason to save. */
  42.         if (vflag) 
  43.             printf("%s has no key field.\n",cmd->pipeline);
  44.         return;
  45.     }
  46.  
  47.     switch (cmd->out_type) {
  48.         case RELATIVE:
  49.             (void) get_rel_field(line, cmd->key.rel_fmt->field,
  50.                 key_val);
  51.             break;
  52.         case COLUMN:
  53.             (void) get_col_field(line, cmd->key.col_fmt->start,
  54.                 cmd->key.col_fmt->end, key_val);
  55.             break;
  56.     }
  57.             
  58.     if (!key_val[0]) {
  59.         if (vflag)
  60.             printf("the key field for %s is empty\n",cmd->pipeline);
  61.         return;
  62.     }
  63.     
  64.     fprintf(hf, "\t%s\n",key_val);
  65. }
  66.