home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume11 / watcher / part02 / defs.h < prev   
Encoding:
C/C++ Source or Header  |  1987-09-27  |  4.6 KB  |  177 lines

  1. /*
  2.   Structure definitions, included files needed and useful constants for
  3.   Watcher.
  4.  
  5.   Kenneth Ingham
  6.  
  7.   Copyright (C) 1987 The University of New Mexico
  8. */
  9.  
  10. #include <stdio.h>
  11. #include <ctype.h>
  12.  
  13. #ifdef BSD
  14. #include <strings.h>
  15. #else
  16. #include <string.h>
  17. #endif
  18.  
  19. #include <signal.h>
  20. #include "y.tab.h"
  21.  
  22. #define False        0
  23. #define True        1
  24. #define NAME        "watcher"
  25. #define MAX_STR        256
  26. #define DEF_CONTROL    "watcherfile"
  27. #define DEF_CONTROL2    "Watcherfile"
  28. #define DEF_HISTFILE    "watcher.history"
  29. #define MAX_NAME    16
  30. #define MAX_VEC        100
  31.  
  32. #define INT        1
  33. #define FLOAT        2
  34. #define PERCENT        3
  35. #define ABSOLUTE    4
  36. #define MAX_MIN        5
  37. #define RELATIVE    6
  38. #define COLUMN        7
  39. #define NUM        8 /* really needs to be replaced by int or float */
  40. #define KEY        9
  41.  
  42. /* 
  43.    below lie the structure definitions for all of the linked lists used
  44.    in watcher.  Make piece with your god before venturing onward
  45. */
  46.  
  47. /*
  48.    what a column output fromat entry looks like:
  49. */
  50. struct col_out_st {
  51.     char *name;            /* name of output field */
  52.     int start;            /* where it starts... */
  53.     int end;            /* ... and ends */
  54.     int type;            /* what type of data to find there */
  55.     struct col_out_st *next;    /* and the next in the list is... */
  56. };
  57.  
  58. /* 
  59.    and a relative output format...
  60. */
  61. struct rel_out_st {
  62.     char *name;            /* name of output field */
  63.     int field;            /* Which field to look in for it */
  64.     int type;            /* what type of data to find there */
  65.     struct rel_out_st *next;    /* and the next in the list */
  66. };
  67.  
  68. /*
  69.    types of change formats; all joined in a union later.
  70. */
  71. struct max_min_st {
  72.     float max;            /* max allowable value... */
  73.     float min;            /* ...and the min */
  74. };
  75.  
  76. union fmt_u {
  77.     float percent;            /* percent change */
  78.     float abs_amount;        /* absolute change */
  79.     struct max_min_st max_min;    /* max and min */
  80.     char *str_value;        /* what the string should be */
  81. };
  82.  
  83. /*
  84.    the actual structure describing how things are allowed to change.
  85. */
  86. struct change_fmt_st {
  87.     char *name;            /* name of the field this pertains to */
  88.     int type;            /* what type of change */
  89.     union fmt_u fmt;        /* the format, depending on type */
  90.     struct change_fmt_st *next;    /* and of course the next in the list */
  91. };
  92.  
  93. /*
  94.    for the various types of output formats:
  95. */
  96. union out_fmt_u {
  97.     struct rel_out_st *rel_fmt;    /* a relative output format (fields) */
  98.     struct col_out_st *col_fmt;    /* or one that uses columns */
  99. };
  100.  
  101. /* 
  102.    what we are all about: the command structure.  Here we bring it all
  103.    together and have something to work with (luckily the subroutines are
  104.    also set up in a similar heirarchy and we can pass various parts of
  105.    the linked lists to them and they don't care about the "upper" parts.
  106. */
  107. struct cmd_st {
  108.     char *pipeline;            /* the pipeline to execute */
  109.     char *alias;            /* a name to use when refering to it */
  110.     int out_type;            /* what type of output format used */
  111.     union out_fmt_u out_fmt;    /* the output format */
  112.     union out_fmt_u key;        /* what to key on for btwn run cmps */
  113.     struct change_fmt_st *change_fmt;/*the things to watch for changes */
  114.     struct cmd_st *next;        /* and of course the next in the list */
  115. };
  116.  
  117. /*
  118.    now we get into the structures for the history linked list...
  119. */
  120.  
  121. /*
  122.    a way of storing any data type:
  123. */
  124. union all_u {
  125.     char *strval;
  126.     int intval;
  127.     float floatval;
  128. };
  129.  
  130. /*
  131.    which is used here where we hold the value for a specified key value
  132.    from the previous output.
  133. */
  134. struct val_st {
  135.     char *name;        /* output field name */
  136.     int type;        /* what type of data in the union */
  137.     union all_u val;    /* ... the data (wow!) */
  138.     struct val_st *next;    /* and where would we be without a next one? */
  139. };
  140.  
  141. /* 
  142.    for each line in the output of a command, we grab the key and store
  143.    all of the values obtained from the line.  Here is how it is done.
  144. */
  145. struct key_st {
  146.     char *key_value;    /* value for the key (could you guess?) */
  147.     struct val_st *vals;    /* the various interesting parts of the line */
  148.     struct key_st *next;    /* and of course the next one */
  149. };
  150.  
  151. /*
  152.    inally we come to the reaon for all of the above structures.  This is
  153.    how previous commands are stored once they have been read in from the
  154.    history file.
  155. */
  156. struct old_cmd_st {
  157.     char *pipeline;            /* the pipeline executed */
  158.     struct key_st *keys;        /* the keys and their useful parts */
  159.     struct old_cmd_st *next;    /* and the next pipeline... */
  160. };
  161.  
  162. /*
  163.    way of converting between type stored in struct and char for a
  164.    person's use.  This works on the cmd_st.out_type values.
  165. */
  166. #define TCHAR(i)    (i==STRING ? 's' : (i == KEY ? 'k' : 'd'))
  167.  
  168. char *malloc();        /* really should switch back to malloc */
  169. char *get_rel_field(), *get_col_field();
  170. double atof();
  171. struct old_cmd_st *find_prev_cmd();
  172.  
  173. /* bezerkeley vs system v differences... */
  174. #ifdef SYSV
  175. #define index    strchr
  176. #endif
  177.