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

  1. /*
  2.    get_rel_field: we have a relative output format and want a certain
  3.    field from it.  Place the field in 'value' if it exists and return a
  4.    pointer to the string.  If there are problems place a null terminated
  5.    zero length string in 'value' and return NULL as an error condition.
  6.  
  7.    Kenneth Ingham
  8.  
  9.    Copyright (C) 1987 The University of New Mexico
  10. */
  11.  
  12. #include "defs.h"
  13.  
  14. char *
  15. get_rel_field(line, field, value)
  16. char *line, *value;
  17. int field;
  18. {
  19.     int i;
  20.     int nfields;
  21.     char *vec[MAX_VEC];
  22.  
  23.     value[0] = '\0';
  24.  
  25.     /* break up the line */
  26.     nfields = line_to_vec(line, vec, " \t");
  27.  
  28.     /* error checking */
  29.     if (nfields <= 0) {
  30.         fprintf(stderr, "'%s' didn't break up into fields.\n",line);
  31.         return NULL;
  32.     }
  33.     if (nfields < field) {
  34.         fprintf(stderr, "Warning: '%s' has only %d fields, not %d\n",
  35.             line, nfields, field);
  36.         return NULL;
  37.     }
  38.  
  39.     (void) strcpy(value, vec[field-1]);
  40.  
  41.     for (i=0; i<nfields; i++)
  42.         free(vec[i]);
  43.  
  44.     return value;
  45. }
  46.