home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / security / Watcher / defs.h < prev    next >
Encoding:
C/C++ Source or Header  |  1989-08-02  |  4.7 KB  |  198 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.  
  21. #define False        0
  22. #define True        1
  23. #define SUCCESS        0
  24. #define FAIL        1
  25. #define EMPTY        0
  26. #define MAX_STR        256
  27. #define DEF_CONTROL    "watcherfile"
  28. #define DEF_CONTROL2    "Watcherfile"
  29. #define DEF_HISTFILE    "watcher.history"
  30. #define VERSION        "Version 1.3"
  31. #define MAX_NAME    16
  32. #define MAX_VEC        100
  33. #define STACKSIZE    256
  34.  
  35. #define ANY        2
  36. #define PERCENT        3
  37. #define ABSOLUTE    4
  38. #define MAX_MIN        5
  39. #define RELATIVE    6
  40. #define COLUMN        7
  41. #define KEY        9
  42.  
  43. /* 
  44.    Below lie the structure definitions for all of the linked lists used
  45.    in watcher.
  46. */
  47.  
  48. /* we start easy.  a number is either an int or a float... */
  49. struct number {
  50.     int type;
  51.     union {
  52.         float real;
  53.         int integer;
  54.     } value;
  55. };
  56.  
  57. /*
  58.    what a column output format entry looks like:
  59. */
  60. struct col_out_st {
  61.     char *name;            /* name of output field */
  62.     int start;            /* where it starts... */
  63.     int end;            /* ... and ends */
  64.     int type;            /* what type of data to find there */
  65.     struct col_out_st *next;    /* and the next in the list is... */
  66. };
  67.  
  68. /* 
  69.    and a relative output format...
  70. */
  71. struct rel_out_st {
  72.     char *name;            /* name of output field */
  73.     int field;            /* Which field to look in for it */
  74.     int type;            /* what type of data to find there */
  75.     struct rel_out_st *next;    /* and the next in the list */
  76. };
  77.  
  78. /*
  79.    types of change formats; all joined in a union later.
  80. */
  81. struct max_min_st {
  82.     double max;            /* max allowable value... */
  83.     double min;            /* ...and the min */
  84. };
  85.  
  86. union fmt_u {
  87.     float percent;            /* percent change */
  88.     double abs_amount;        /* absolute change */
  89.     struct max_min_st max_min;    /* max and min */
  90.     char **str_value;        /* array of values for what the
  91.                        string should be; terminated
  92.                        by a NULL pointer */
  93. };
  94.  
  95. struct chg_fmt_st {
  96.     int type;
  97.     union fmt_u fmt;
  98. };
  99.  
  100. /*
  101.    the actual structure describing how things are allowed to change.
  102. */
  103. struct change_fmt_st {
  104.     char *name;            /* name of the field this pertains to */
  105.     struct chg_fmt_st fmt;        /* the format, depending on type */
  106.     struct change_fmt_st *next;    /* and of course the next in the list */
  107. };
  108.  
  109. /*
  110.    for the various types of output formats:
  111. */
  112. union out_fmt_u {
  113.     struct rel_out_st *rel_fmt;    /* a relative output format (fields) */
  114.     struct col_out_st *col_fmt;    /* or one that uses columns */
  115. };
  116.  
  117. struct out_fmt_st {
  118.     int type;
  119.     union out_fmt_u out_fmt;
  120. };
  121.  
  122. /* 
  123.    what we are all about: the command structure.  Here we bring it all
  124.    together and have something to work with (luckily the subroutines are
  125.    also set up in a similar heirarchy and we can pass various parts of
  126.    the linked lists to them and they don't care about the "upper" parts.
  127. */
  128. struct cmd_st {
  129.     char *pipeline;            /* the pipeline to execute */
  130.     char *alias;            /* a name to use when refering to it */
  131.     struct out_fmt_st *out_fmt;    /* the output format */
  132.     struct out_fmt_st *key;        /* what to key on for btwn run cmps */
  133.     struct change_fmt_st *change_fmt;/*the things to watch for changes */
  134.     struct cmd_st *next;        /* and of course the next in the list */
  135. };
  136.  
  137. /*
  138.    now we get into the structures for the history linked list...
  139. */
  140.  
  141. /*
  142.    a way of storing any data type:
  143. */
  144. union everything_u {
  145.     char *string, character;
  146.     int integer;
  147.     float real;
  148. };
  149.  
  150. struct everything {
  151.     int type;
  152.     union everything_u data;
  153. };
  154.  
  155. /*
  156.    which is used here where we hold the value for a specified key value
  157.    from the previous output.
  158. */
  159. struct val_st {
  160.     char *name;        /* output field name */
  161.     struct everything val;    /* ... the data (wow!) */
  162.     struct val_st *next;    /* and where would we be without a next one? */
  163. };
  164.  
  165. /* 
  166.    for each line in the output of a command, we grab the key and store
  167.    all of the values obtained from the line.  Here is how it is done.
  168. */
  169. struct key_st {
  170.     char *key_value;    /* value for the key (could you guess?) */
  171.     struct val_st *vals;    /* the various interesting parts of the line */
  172.     struct key_st *next;    /* and of course the next one */
  173. };
  174.  
  175. /*
  176.    finally we come to the reaon for all of the above structures.  This is
  177.    how previous commands are stored once they have been read in from the
  178.    history file.
  179. */
  180. struct old_cmd_st {
  181.     char *pipeline;            /* the pipeline executed */
  182.     struct key_st *keys;        /* the keys and their useful parts */
  183.     struct old_cmd_st *next;    /* and the next pipeline... */
  184. };
  185.  
  186. char *xmalloc(), *realloc(), *strsave(), *strnsave();
  187. char *get_rel_field(), *get_col_field();
  188. double atof();
  189. struct old_cmd_st *find_cmd_prev();
  190.  
  191. /* Berkeley vs System V differences... */
  192. #ifdef SYSV
  193. #define index    strchr
  194. #define rindex    strrchr
  195. #endif
  196.  
  197. #define allocate(size)    ((size *)xmalloc(sizeof(size)))
  198.