home *** CD-ROM | disk | FTP | other *** search
- /*
- Structure definitions, included files needed and useful constants for
- Watcher.
-
- Kenneth Ingham
-
- Copyright (C) 1987 The University of New Mexico
- */
-
- #include <stdio.h>
- #include <ctype.h>
-
- #ifdef BSD
- #include <strings.h>
- #else
- #include <string.h>
- #endif
-
- #include <signal.h>
- #include "y.tab.h"
-
- #define False 0
- #define True 1
- #define NAME "watcher"
- #define MAX_STR 256
- #define DEF_CONTROL "watcherfile"
- #define DEF_CONTROL2 "Watcherfile"
- #define DEF_HISTFILE "watcher.history"
- #define MAX_NAME 16
- #define MAX_VEC 100
-
- #define INT 1
- #define FLOAT 2
- #define PERCENT 3
- #define ABSOLUTE 4
- #define MAX_MIN 5
- #define RELATIVE 6
- #define COLUMN 7
- #define NUM 8 /* really needs to be replaced by int or float */
- #define KEY 9
-
- /*
- below lie the structure definitions for all of the linked lists used
- in watcher. Make piece with your god before venturing onward
- */
-
- /*
- what a column output fromat entry looks like:
- */
- struct col_out_st {
- char *name; /* name of output field */
- int start; /* where it starts... */
- int end; /* ... and ends */
- int type; /* what type of data to find there */
- struct col_out_st *next; /* and the next in the list is... */
- };
-
- /*
- and a relative output format...
- */
- struct rel_out_st {
- char *name; /* name of output field */
- int field; /* Which field to look in for it */
- int type; /* what type of data to find there */
- struct rel_out_st *next; /* and the next in the list */
- };
-
- /*
- types of change formats; all joined in a union later.
- */
- struct max_min_st {
- float max; /* max allowable value... */
- float min; /* ...and the min */
- };
-
- union fmt_u {
- float percent; /* percent change */
- float abs_amount; /* absolute change */
- struct max_min_st max_min; /* max and min */
- char *str_value; /* what the string should be */
- };
-
- /*
- the actual structure describing how things are allowed to change.
- */
- struct change_fmt_st {
- char *name; /* name of the field this pertains to */
- int type; /* what type of change */
- union fmt_u fmt; /* the format, depending on type */
- struct change_fmt_st *next; /* and of course the next in the list */
- };
-
- /*
- for the various types of output formats:
- */
- union out_fmt_u {
- struct rel_out_st *rel_fmt; /* a relative output format (fields) */
- struct col_out_st *col_fmt; /* or one that uses columns */
- };
-
- /*
- what we are all about: the command structure. Here we bring it all
- together and have something to work with (luckily the subroutines are
- also set up in a similar heirarchy and we can pass various parts of
- the linked lists to them and they don't care about the "upper" parts.
- */
- struct cmd_st {
- char *pipeline; /* the pipeline to execute */
- char *alias; /* a name to use when refering to it */
- int out_type; /* what type of output format used */
- union out_fmt_u out_fmt; /* the output format */
- union out_fmt_u key; /* what to key on for btwn run cmps */
- struct change_fmt_st *change_fmt;/*the things to watch for changes */
- struct cmd_st *next; /* and of course the next in the list */
- };
-
- /*
- now we get into the structures for the history linked list...
- */
-
- /*
- a way of storing any data type:
- */
- union all_u {
- char *strval;
- int intval;
- float floatval;
- };
-
- /*
- which is used here where we hold the value for a specified key value
- from the previous output.
- */
- struct val_st {
- char *name; /* output field name */
- int type; /* what type of data in the union */
- union all_u val; /* ... the data (wow!) */
- struct val_st *next; /* and where would we be without a next one? */
- };
-
- /*
- for each line in the output of a command, we grab the key and store
- all of the values obtained from the line. Here is how it is done.
- */
- struct key_st {
- char *key_value; /* value for the key (could you guess?) */
- struct val_st *vals; /* the various interesting parts of the line */
- struct key_st *next; /* and of course the next one */
- };
-
- /*
- inally we come to the reaon for all of the above structures. This is
- how previous commands are stored once they have been read in from the
- history file.
- */
- struct old_cmd_st {
- char *pipeline; /* the pipeline executed */
- struct key_st *keys; /* the keys and their useful parts */
- struct old_cmd_st *next; /* and the next pipeline... */
- };
-
- /*
- way of converting between type stored in struct and char for a
- person's use. This works on the cmd_st.out_type values.
- */
- #define TCHAR(i) (i==STRING ? 's' : (i == KEY ? 'k' : 'd'))
-
- char *malloc(); /* really should switch back to malloc */
- char *get_rel_field(), *get_col_field();
- double atof();
- struct old_cmd_st *find_prev_cmd();
-
- /* bezerkeley vs system v differences... */
- #ifdef SYSV
- #define index strchr
- #endif
-